akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
  
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const ll INF = 1e18;
const int N = 2e5 + 5;
int a[N], mx[N], mn_mod[N], mx_mod[N];
int n, m;

bool check(int x) {
    for (int i = 0, j = n; i < n; i++) {
        while (j > 0 && a[j - 1] + a[i] >= m)
            j--;
        mn_mod[i] = j;
    }

    for (int i = n - 1, j = -1; i >= 0; i--) {
        while (j + 1 < n && a[j + 1] + a[i] <= x + m)
            j++;
        mx_mod[i] = j;
    }

    for (int i = n - 1, j = -1; i >= 0; i--) {
        while (j + 1 < n && a[j + 1] + a[i] <= x)
            j++;
        mx[i] = j;
    }

    // for (int i = 0; i < n; i++) {
    //     cout << mn_mod[i] << " ";
    // }
    // cout << "\n";

    // for (int i = 0; i < n; i++) {
    //     cout << mx[i] << " ";
    // }
    // cout << "\n";




    for (int i = 0; i < n; i++) {
        mx[i] += i;
        mn_mod[i] -= n - 1 - i;
        mx_mod[i] -= n - 1 - i;
    }



    
    // cout << "\n";
    

    for (int i = 1; i < n; i++) {
        mx[i] = min(mx[i], mx[i - 1]);
    }

    for (int i = n - 2; i >= 0; i--) {
        mn_mod[i] = max(mn_mod[i], mn_mod[i + 1]);
    }

    for (int i = n - 2; i >= 0; i--) {
        mx_mod[i] = min(mx_mod[i], mx_mod[i + 1]);
    }

    // for (int i = 0; i < n; i++) {
    //     cout << mn_mod[i] << " ";
    // }
    // cout << "\n";

    for (int i = -1; i < n; i += 2) {
        // if (i == -1) {
        //     cout << mn_mod[n - 1 - (n - i - 2) / 2] << "\n";
        // }
        if ((i == -1 || mx[i / 2] >= i) &&
            (i + 1 == n || mn_mod[n - 1 - (n - i - 2) / 2] <= i + 1 && 
                mx_mod[n - 1 - (n - i - 2) / 2] >= i + 1)) {
            return true;
        }
    }

    return false;
}

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

    cin >> n >> m;

    n *= 2;

    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    sort(a, a + n);

    // cout << check(4) << "\n";
    // return 0;

    int l = -1, r = m;
    while (r - l > 1) {
        int p = (l + r) >> 1;
        if (check(p))
            r = p;
        else
            l = p;
    }

    cout << r << "\n";

    return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>

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

using namespace std;
typedef long long int ll;
const int INF = 1000000000;
const double PI = acos(-1);
const ll mod = 1000000007;

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

    ll ans = 0;
    for (int i = 1; i <= n; i++) {
        if (i % 3 == 0 || i % 5 == 0) continue;
        ans += i;
    }
    cout << ans << endl;
    return 0;
}

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

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

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

  vector<int> a(n);
  rep(i,n) cin >> a.at(i);

  ll money = 1000;
  ll motikabu = 0;
  bool flag = false; //true:売るターン

  int i=0;

  while(i<n){
    if(!flag){
     while(i+1!=n&&a.at(i)>=a.at(i+1)) i++;
     if(i<n){
       motikabu += money/a.at(i);
       money -= a.at(i)*motikabu;
       flag = true;
     }
     else{
       break;
     }
   }

   if(flag){
     while(i+1!=n&&a.at(i)<=a.at(i+1))i++;
     if(i+1!=n){
       money += a.at(i)*motikabu;
       motikabu = 0;
       flag = false;
     }
     else{
       money += motikabu*a.at(i);
       break;
     }
   }
    
    //cout << flag << " "  << money << " " << i << endl;

 }
 cout << money;  
}

Measured memory_bytes: 3440
use proconio::*;

fn main() {
    input! {
        n: usize,
        mut a: [usize; n]
    }

    a.sort();
    let maxval = a[a.len() - 1];

    let mut arr: [bool; 1000001] = [false; 1000001];
    for i in 0..n {
        let mut val = a[i];
        if i + 1 < n && a[i] == a[i + 1] {
            arr[val] = true;
        }

        val += a[i];
        while val <= maxval {
            arr[val] = true;
            val += a[i];
        }
    }

    let mut count = 0;
    for i in 0..n {
        if arr[a[i]] == false { count += 1; }
    }
    println!("{}", count);
}


Measured memory_bytes: 5948
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>
#include <set>
#include <list>
#include <cmath>
#include <map>

using namespace std;
typedef long long ll;

ll CountDigit(ll n){
	ll result = 0;
	while(n > 0){
		n /= 10;
		result++;
	}
	return result;
}

int main()
{
	ll N;
	cin >> N;
	ll ans = 1000;
	for(ll A = 1; A <= sqrt(N) + 1; A++){
		if(N % A == 0){
			ll B = N / A;
			ll M = max(A, B);
			ans = min(ans, CountDigit(M));
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(ll)(n);i>0;i--)
#define REP(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 2e18;
const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);

typedef string::const_iterator State;
class ParseError {};

ll number(State&);
ll factor(State&);
ll term(State&);
ll expression(State&);

ll number(State &begin) {
  ll ret = 0;
  while (isdigit(*begin)) {
    ret *= 10;
    ret += *begin - '0';
    begin++;
  }
  return ret;
}

ll factor(State &begin) {
    if (*begin == '(') {
        begin++; // '('を飛ばす。
        ll ret = expression(begin);
        begin++; // ')'を飛ばす。
    } else {
        return number(begin);
    }
}

ll term(State &begin) {
  ll ret = factor(begin);
  for (;;) {
    if (*begin == '*') {
      begin++;
      ret *= factor(begin);
    }
    else if (*begin == '/') {
      begin++;
      ret /= factor(begin);
    }
    else {
      break;
    }
  }
  return ret;
}

ll expression(State &begin) {
  ll ret = term(begin);
  for (;;) {
    if (*begin == '+') {
      begin++;
      ret += term(begin);
    }
    else if (*begin == '-') {
      begin++;
      ret -= term(begin);
    }
    else {
      break;
    }
  }
  return ret;
}


int main () {
  int n;
  cin >> n;
  cin.ignore();
  while (n--) {
    string s;
    getline(cin, s);
    State begin = s.begin();
    ll ans = expression(begin);
    cout << ans << endl;
  }
  
}



Measured memory_bytes: 3148
import Data.List
import Data.Array.IArray

solve :: [Int] -> Int
solve a = dp!(n,0)
  where
    n = length a
    aa = listArray (1,n) a :: Array Int Int
    k = ((0,0),(n,1))
    dp = listArray k $ map f (range k) :: Array (Int,Int) Int
    f (0,0) = 0
    f (0,1) = minBound `div` 2
    f (i,0) = max (dp!(i-1,0) + (aa!i)) (dp!(i-1,1) - (aa!i))
    f (i,1) = max (dp!(i-1,0) - (aa!i)) (dp!(i-1,1) + (aa!i))

main :: IO ()
main = do
    _ <- getLine
    a <- map read . words <$> getLine :: IO [Int]
    print $ solve a

Measured memory_bytes: 92540
fn main() {
    let v = read_vec::<usize>();
    let a = v[0];
    let b = v[1];
    if a >= b {
        let x = vec![b; a];
        println!(
            "{}",
            x.into_iter()
                .map(|i| i.to_string())
                .collect::<Vec<String>>()
                .join("")
        );
    } else {
        let x = vec![a; b];
        println!(
            "{}",
            x.into_iter()
                .map(|i| i.to_string())
                .collect::<Vec<String>>()
                .join("")
        );
    }
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>

#define MOD 1e9+7;
#define INF 1e17+9;
#define PI acos(-1);

using namespace std;

int main(){
	int n,k;
	cin >> n >> k;
	long long ans=1;
	for(int i=0;i<n;i++){
		if(i==0){
			ans*=k;
			continue;
		}
		ans*=(k-1);
	}
	cout << ans << endl;
	return 0;
}


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

vector<int> a, b, c, d;
int N, M, Q;
int ans;

void dfs(vector<int> A){
    if(A.size() == N+1){
        int now = 0;
        for (int i = 0; i < Q; i++){
            if(A[b[i]] - A[a[i]] == c[i]){
              now += d[i];
            }
        }
        ans = max(ans, now);
        return;
    }

    A.push_back(A.back());
    while(A.back() <= M){
        dfs(A);
        A.back()++;
    }
}

int main(){
    cin >> N >> M >> Q;
    a = b = c = d = vector<int>(Q);

    for (int i = 0; i < Q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    dfs(vector<int>(1, 1));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3568
def f(n)
    n.even? ? n/2 : 3*n + 1
end
def main()
  s = gets.chomp.to_i
  a = [s]
  i = 0
  while 1 do
    result_of_f = f(a[i])
    unless a.include?(result_of_f)
      a << result_of_f
    else
      break
    end
    i += 1
  end
  puts "#{i+2}"
end
main


Measured memory_bytes: 1788
n = int(input())
h = list(map(int,input().split()))

count =0
while True:
  is_all_0 = True
  left = 0  
  for i in range(len(h)):
    if h[i]>0:
      is_all_0 = False
      left = i
      break
  
  if is_all_0:
    break
  
  right = left
  is_all_0 = True
  for j in range(left,len(h)):
    if h[j]>0:
      right=j
    else:
      break
    
  for i in range(left,right+1):
    h[i]-=1
  count+=1
print(count)  


Measured memory_bytes: 3064
#include "bits/stdc++.h"

using namespace std;

constexpr char endl('\n');


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


    string s;
    cin >> s;

    if (s.at(2) == s.at(3) && s.at(4) == s.at(5)) {
        cout << "Yes" << ::endl;
    }
    else {
        cout << "No" << ::endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <math.h>
typedef long long ll;
using namespace std;

int main()
{
	int k, x;
	cin >> k >> x;
	
	for (int i = 0; i < k - 1; i++)
	{
		cout << x - (k - 1) + i << " ";
	}
	cout << x << " ";
	for (int i = 0; i < k - 1; i++)
	{
		cout << x + 1 + i << " ";
	}
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  constexpr u64 &value() noexcept { return a; }
  constexpr const u64 &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};

using mint = modint<MOD>;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<ll> C(N);
    rep(i,N) cin >> C[i];

    sort(all(C));
    reverse(all(C));

    vector<mint> modpow(N+1,1);
    rep(i,N) modpow[i+1] = modpow[i]*2LL;
    mint ans = 0;
    for (ll i = 0; i < N; i++) {
        if (i == 0) ans += modpow[N-1]*C[i];
        else ans += modpow[i-1]*modpow[N-1-i]*(i+2LL)*C[i];
    }
    ans *= modpow[N];

    cout << ans.a << endl;
}

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

int main()
{
  int L, R, l, r, a, b, tmp, ans = 2019;
  bool memo[2019];
  for(int i = 0; i < 2019; i++)
    memo[i] = false;
  cin >> L >> R;

  l = L % 2019;
  r = R % 2019;
  a = L / 2019;
  b = R / 2019;

  if(a == b){
    for(int i = l; i < r; i++){
      for(int j = i + 1; j <= r; j++){
        tmp = (i * j) % 2019;
        if(memo[tmp] == true)
          continue;
        else{
          if(tmp < ans)
            ans = tmp;
          memo[tmp] = true;
        }
      }
    }
  }
  else
    ans = 0;

  cout << ans << endl;


}


Measured memory_bytes: 384
N,M = map(int, input().split())
n,m = max(N,M), min(N,M)
MOD = int(1e9)+7

fac_m = 1
for i in range(1,m+1):
    fac_m *= i
    fac_m %= MOD
    
if n-m>=2:
    ans = 0
elif n-m==1:
    ans = fac_m * (fac_m*n) % MOD
else: 
    ans = 2 * fac_m * fac_m % MOD

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <math.h>
#include <string>
#include <iomanip>
#include <locale>
#include <list>
#include <bitset>
#include <tuple>
using namespace std;
#define FORN(i,m,n) for(int i=(m); i<int(n); i++)
#define PRINTVEC(v) FORN(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define PRINTMAT(m) FORN(j,0,m.size()) {PRINTVEC(m[j]);}
typedef long long ll;

bool test(string s){
  int a = 0, b = s.size() - 1;
  while(a <= b && s[a] == s[b]) a++, b--;
  return a > b;
}

int main(){
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  string s; cin>>s;
  int n = s.size();
    if(test(s) && test(s.substr(0,(n-1)/2))) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(args...) do { cout << "DEBUG: " << #args << " -> "; err(args); } while (0)
#else
#define dbg(...)
#endif
void err() { cout << endl; }
template<template<typename...> class T, typename t, typename... Args>
void err(T<t> a, Args... args) { for (auto x: a) cout << x << ' '; err(args...); }
template<typename T, typename... Args>
void err(T a, Args... args) { cout << a << ' '; err(args...); }
// -----------------------------------------------------------------------------
const int N = 100000;
char s[N];

void prt(int u, int v) { printf("%d %d\n", u, v); }

int main() {
    scanf("%s", s + 1);
    int n = strlen(s + 1);
    if (s[1] == '0' || s[n] == '1') { puts("-1"); return 0; }
    FOR (i, 1, n) if (s[i] != s[n - i]) { puts("-1"); return 0; }
    int rt = 1, sz = 2;
    FOR (i, 1, n)
        if (s[i] == '1') { prt(rt, sz++); rt = sz - 1; }
        else { prt(rt, sz++); }
}

Measured memory_bytes: 1536
import sys
for i in sys.stdin:
    a, b = map(int, i.split())
    p, q = max(a, b), min(a, b)
    while True:
        if p % q == 0:
            break
        else:
            p, q = q, p % q
    print("{} {}".format(q, int(a * b / q)))


Measured memory_bytes: 5600
#include <stdio.h>

int main(void)
{
	int m, f, r;   //m:中間試験 f:期末試験 r:再試験

	while (1)
	{
		scanf("%d %d %d", &m, &f, &r);
		/*全てが-1ならプログラム終了*/
		if (m == -1 && f == -1 && r == -1)
		{
			break;
		}
		/*中間、期末いずれかを欠席したらF*/
		if (m == -1 || f == -1)
		{
			printf("F\n");
		}
		/*中間期末合計80点以上A*/
		else if (m + f >= 80)
		{
			printf("A\n");
		}
		/*中間期末合計65点以上80点未満B*/
		else if ((m + f < 80) && (m + f >= 65))
		{
			printf("B\n");
		}
		/*中間期末合計50点以上65点未満C*/
		else if ((m + f >= 50) && (m + f < 65))
		{
			printf("C\n");
		}
		/*中間期末合計30点以上50点未満D*/
		else if ((m + f >= 30) && (m + f < 50))
		{
			/*再試験が50点以上ならC*/
			if (r >= 50)
			{
				printf("C\n");
			}
			else
			{
				printf("D\n");
			}
		}
		/*中間期末合計30点未満F*/
		else if (m + f < 30)
		{
			printf("F\n");
		}
	}
	return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set> 
#include <map>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iomanip>
#define REP(i,n) for(int i=0; i<(n); ++i)
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const ll INFLL = 100100100100100100;
const int MOD = (int)1e9 + 7;
const ll MODLL = (ll)1e9 + 7;
const double EPS = 1e-9;
 
int main () {
    
    int h,w; cin >>h>>w;
    vector<vector<char> > a(h, vector<char>(w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> a[i][j];
        }
    }

    vector<vector<ll> > dp(h, vector<ll>(w, 0));
    for (int i = 0; i < h; i++) {
        if (a[i][0] == '#') {
            break;
        } 
        dp[i][0] = 1;
    }
    for (int j = 0; j < w; j++) {
        if (a[0][j] == '#') {
            break;
        } 
        dp[0][j] = 1;
    }

    for (int i = 1; i < h; i++) {
        for (int j = 1; j < w; j++) {
            if (a[i][j] == '.') {
                dp[i][j] = (dp[i-1][j] + dp[i][j-1]);
                dp[i][j] %= MODLL;
            } 
        }
    }

    cout << dp[h-1][w-1] << endl;
    
    return 0;
}

 

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

int a[maxn],tmp[maxn],s[maxn],f[maxn],c[maxn<<1],n,k;
inline int lowbit(int x){
	return x&(-x);
}
void insert(int pos){
	for(int i=pos;i<=2*n+3;i+=lowbit(i))
		c[i]++;
}
int query(int pos){
	int ret=0;
	for(int i=pos;i;i-=lowbit(i))
		ret+=c[i];
	return ret;
}
bool check(int x){
	memset(c,0,sizeof(c));
	ll cnt=0;
	for(int i=1;i<=n;i++)
		tmp[i]=a[i]<=x?1:-1;
	for(int i=1;i<=n;i++)
		s[i]=s[i-1]+tmp[i];
	insert(0 +n+3);
	for(int i=1;i<=n;i++)
		cnt+=query(s[i]-1 +n+3),insert(s[i] +n+3);
	return cnt>=1LL*n*(n+1)/2/2+1;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int l=1,r=1e9;
	while(l<r){
		int mid=l+r>>1;
		if(check(mid))
			r=mid;
		else
			l=mid+1;
	}
//	if(!check(l))
//		l--;
	printf("%d\n",l);
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
int main(void)
{
  int n, a[100002] = {}, all = 0;
  std::cin >> n;
  for(int i = 1; i <= n + 1; i++){
    if(i != n + 1) std::cin >> a[i];
    all += std::abs(a[i] - a[i - 1]);
  }
  for(int i = 1; i != n + 1; i++){
    if((a[i + 1] - a[i]) * (a[i] - a[i - 1]) >= 0) std::cout << all << std::endl;
    else std::cout << all - 2 * std::min(std::abs(a[i + 1] - a[i]), std::abs(a[i - 1] - a[i]))  << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1664
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

int main(void)
{
    int n,red = 0,blue = 0;
    string s;
    cin >> n;
    cin >> s;
    for(int i = 0;i < n;i++)
    {
        if(s[i] == 'R'){red++;}
        else{blue++;}
    }
    if(blue < red){cout << "Yes" << endl;}
    else{cout << "No" << endl;}
    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <numeric>

using namespace std;

#define int long long
typedef long double ld;
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<vi>
#define viii vector<vii>
#define vpii vector<pii>
#define vb vector<bool>
#define vbb vector<vb>
#define vs vector<string>
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define in(a, x) for (int i = x; i < (a).size(); ++i) cin >> (a)[i]
#define out(a) for (auto qwe : a) cout << qwe << " "

const int INF = 1e9;
const int INF64 = 1e18;
const int MOD = 1e9 + 7;
const int MOD9 = 1e9 + 9;
const int MOD3 = 998244353;
const int P = 37;

const int mxn = 200000;

vi f(2e5 + 2, 0);
vi bkf(2e5 + 2, 0);

int pw(int a, int n) {
    if (n == 0) return 1;

    if (n % 2 == 0) {
        int c = pw(a, n / 2);
        return (c * c) % MOD;
    } else {
        return (a * pw(a, n - 1)) % MOD;
    }
}

int cnk(int n, int k) {
    return (((f[n] * bkf[k]) % MOD) * bkf[n - k]) % MOD;
}

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

    f[0] = 1;
    bkf[0] = 1;

    for (int j = 1; j <= 200001; ++j) {
        f[j] = (f[j - 1] * j) % MOD;
        bkf[j] = pw(f[j], MOD - 2);
    }

    int h, w, n;
    cin >> h >> w >> n;

    vpii p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i].ff >> p[i].ss;
    }

    sort(all(p));
    p.pb({h, w});

    vi dp(n + 1, 0);

    for (int i = 0; i <= n; ++i) {
        int a = p[i].ff;
        int b = p[i].ss;

        dp[i] = cnk(a + b - 2, a - 1);

        for (int j = 0; j < i; ++j) {
            int x = p[j].ff;
            int y = p[j].ss;

            if (x <= a && y <= b) {
                dp[i] = (dp[i] - ((dp[j] * cnk(a + b - x - y, a - x)) % MOD) + MOD) % MOD;
            }
        }
    }

    cout << dp[n];
}

Measured memory_bytes: 3456
#include <stdio.h>

int main(){
  int n, max = -10000000, min = 100000000;
  long long int sum = 0;

  scanf("%d",&n);

  int i = 0, a;

  for(i = 0; i < n; i++){
    scanf("%d",&a);
    if(a < min){
      min = a;
    }
    if(max < a){
      max = a;
    }
    sum = sum+a;
  }

  printf("%d %d %lld\n",min ,max ,sum);
  return 0;
}

Measured memory_bytes: 600
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nw = br.readLine().split(" ");
        
        int N = Integer.parseInt(nw[0]);
        int W = Integer.parseInt(nw[1]);
        
        int[][] weight = new int[N][2];
        
        for(int i=0; i<N; i++) {
            String[] input = br.readLine().split(" ");
            weight[i][0] = Integer.parseInt(input[0]);
            weight[i][1] = Integer.parseInt(input[1]);
        }
        
        System.out.println(getMaxValue(weight, W));
    }

    private static long getMaxValue(int[][] weight, int W) {
        long[][] dp = new long[weight.length + 1][W+1];
        
        for(int i=1; i<=weight.length; i++) {
            for(int j=1; j<=W; j++) {
                dp[i][j] = dp[i-1][j];
                
                if(weight[i-1][0] <= j) {
                    dp[i][j] = Math.max(dp[i][j], weight[i-1][1] + dp[i-1][j-weight[i-1][0]]);
                }
            }
        }
        
        return dp[weight.length][W];
    }
}


Measured memory_bytes: 137856
#include<iostream>
using namespace std;
string W, s, n;
int a, i;
main() {
	cin >> W;
	while (cin >> s, s != "END_OF_TEXT") {
		n = "";
		for (i = 0; i < s.size(); ++i) {
			if ('a' <= s[i] && s[i] <= 'z') n.push_back(s[i]);
			else if ('A' <= s[i] && s[i] <= 'Z') n.push_back((char)tolower(s[i]));
		}
		a += W == n;
	}
	cout << a << endl;
}


Measured memory_bytes: 3184
#include <iostream>

using namespace std;

int main(){
    int K, X;
    cin >> K >> X;
    int l = X-(K-1);
    int r = X+(K-1);
    
    for(int i = l; i <= r; i++){
        cout << i << " ";
    }
    cout << endl;
    

    return 0;
}

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

int pow2(int k){
  	int res=1;
  	for(int i=0; i<k; i++) res*=2;
	return res;
}
int main(){
  	int N, k, min;
	cin >> N; 
	vector<int> A(N), K(N);
  	for(int i=0; i<N; i++){
      k=0;
      cin >> A[i];
      while( A[i]%pow2(k+1)==0 ){k++;}
      K[i] = k;
    }
  	min=K[0];
  	for(int k:K) if(k<min) min=k;
  
  	cout << min;
  	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
 public static void main(String args[]) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int Y = sc.nextInt();
    for(int x = n; x >= 0; x--) {
        for (int y = n - x; y >= 0; y--) {
            int z = n - x - y;
            int ans  = 10000 * x + 5000 * y + 1000 * z;
            if(Y  == ans) {
              System.out.println(String.format("%d %d %d", x, y, z));
              return;
            }
        }
    }
    System.out.println("-1 -1 -1");
 }
}

Measured memory_bytes: 23124
import java.util.Arrays;
import java.util.Scanner;

//Adaptive Time Slicing Quantization
public class Main{

	int n, M, L, INF = 1<<29;
	double res;
	double[] a;
	double[][] dp;
	
	void dfs(int k, int m, double e){
		if(m<0||res<=e)return;
		if(k==n){
			if(m==0)res = e;
			return;
		}
		if(dp[k][m]!=-1){
			res = Math.min(res, e+dp[k][m]);
			return;
		}
//		double min = INF;
		
	}
	
	double bs(double min, double max, double x){
		int l = 1, r = 1<<L;
		while(r-l>1){
			int m = (l+r)/2;
			double v = min+(m-1)*(max-min)/((1<<L)-1);
			if(v<x)l=m;
			else r=m;
		}
		double lv = min+(l-1)*(max-min)/((1<<L)-1), rv = min+(r-1)*(max-min)/((1<<L)-1);
		return Math.abs(x-lv)<Math.abs(x-rv)?lv:rv;
	}
	
	double get(int k, int m){
		if(n==k){
			return m==0?0:INF;
		}
		if(m<0)return INF;
		if(dp[k][m]!=-1)return dp[k][m];
		if(n<=k+1)return INF;
		double min = a[k], max = a[k], res = INF;
		for(int i=k+1;i<n;i++){
			min = Math.min(min, a[i]); max = Math.max(max, a[i]);
			if(n<i+1+2*(m-1))break;
//			double[] q = new double[(1<<L)+1];
//			for(int j=1;j<=1<<L;j++)q[j]=min+(j-1)*(max-min)/((1<<L)-1);
			double e = 0;
			for(int j=k;j<=i;j++){
				double s = bs(min, max, a[j]);
//				for(int Q=1;Q<=1<<L;Q++){
//					double abs = Math.abs(a[j]-(min+(Q-1)*(max-min)/((1<<L)-1)));
//					if(s<abs)break;
//					s = abs;
//				}
				e += (s-a[j])*(s-a[j]);
			}
			res = Math.min(res, e+get(i+1, m-1));
		}
		return dp[k][m] = res;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			n = sc.nextInt(); M = sc.nextInt(); L = sc.nextInt();
			if((n|M|L)==0)break;
//			long T = System.currentTimeMillis();
			a = new double[n];
			for(int i=0;i<n;i++)a[i]=sc.nextDouble();
			dp = new double[n][M+1];
			for(double[]d:dp)Arrays.fill(d, -1);
//			res = INF;
			System.out.printf("%.8f\n", get(0, M));
//			System.out.println("Time:"+(System.currentTimeMillis()-T)+" ms.");
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 14000
#include <bits/stdc++.h>
#define lint long long
using namespace std;
 
int main()
{
    lint n;
    cin >> n;
    lint ans = 1e16;
    for(lint i = 1; i*i <= n; i++){
        if(n%i) continue;
        ans = min(ans, i+n/i-2);
    }
    cout << ans << endl;
 
    return 0;
}


Measured memory_bytes: 256
#include<cctype>
#include<cstdio>
#include<cstring>
#include<iostream>
#define N 15
#define int long long

int n,m,ans;
int used[N];
int p[N],c[N];

int getint(){
	int x=0,f=0;char ch=getchar();
	while(!isdigit(ch)) f|=ch=='-',ch=getchar();
	while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}

void dfs(int now,int sum,int rem){
	if(rem>=m){
		ans=std::min(ans,sum);
		return;
	}
	for(int i=1;i<=n;i++){
		if(used[i]) continue;
		used[i]=1;
		int q=(m-rem)/(100*i);
		int aa=sum,bb=rem;
		if(q>=p[i]){
			aa+=p[i];
			bb+=p[i]*100*i+c[i];	
		} else{
			aa+=q;
			bb+=q*100*i;
		}
		dfs(i,aa,bb);
		used[i]=0;
	}
}

signed main(){
	n=getint(),m=getint();
	for(int i=1;i<=n;i++)
		p[i]=getint(),c[i]=getint();
	ans=1e9;
	dfs(1,0,0);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define si set<int>
#define stk stack<int>
#define que queue<int>
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const ll mod=1e9+7;

using namespace std;

int main(){
	string s;
	cin>>s;
	set<char> se(s.begin(), s.end());
	if(se.size()==1)
		cout<<"No"<<endl;
	else
		cout<<"Yes"<<endl;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(){

	int n, a, b, sum = 0, i, l, num, digi, lsum = 0;
	scanf("%d%d%d", &n, &a, &b);
	for(i = 1; i <= n; i++){

		l = i;
      	lsum = 0;

		while(l){
			digi = l % 10;
			lsum = lsum + digi;
			l = l/10;
		}

		if(lsum >= a && lsum <= b) sum = sum + i;

	}
	printf("\n\n%d", sum);
	return 0;

}

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

// TYPEDEF
// ----------------------------------------
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pair;
typedef vector<ll> vll;
typedef vector<vector<ll>> Graph;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> Pll;
typedef queue<ll> qll;

// REPEAT
// ----------------------------------------
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REPA(i,a) for(ll i=0;i<(ll)(a.size());i++);
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;
#define COUTA(i,a) for(ll i=0;i<(ll)(a.size());i++) {cout << (a)[i] << " ";} cout << endl;

// UTIL
// ----------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())

// DEBUG
// ----------------------------------------
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

// BIT FLAG
// ----------------------------------------
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000

// CONST
// ----------------------------------------
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI=3.14159265358979323846; // or M_PI
constexpr int MOD = 1000000007;


void Main() {
  ll n;
  cin >> n;
  string s;
  cin >> s;
  ll count = 1;
  FOR(i, 1, n - 1) {
    if (s[i] != s[i - 1]) {
      count++;
    }
  }
  COUT(count);


}


int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}

/*
10
aabbbbaaca
*/


Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b){
    return a == 0 ? b : gcd(b%a,a);
}
int main(){
    long long a,b;
    scanf("%lld%lld",&a,&b);
    printf("%lld",a*b/gcd(a,b));
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <numeric>
#include <algorithm>
using namespace std;

int dfs(int i, vector<char> const& cs, vector<int> const& coeff, vector<bool> const& leading, vector<bool>& used, int sum) {
    if(i == cs.size()) {
        return sum == 0;
    }
    char c = cs[i];
    int res = 0;
    for(int j=0; j<10; ++j) {
        if(used[j] || j == 0 && leading[c-'A']) {
            continue;
        }
        used[j] = true;
        res += dfs(i+1, cs, coeff, leading, used, sum + coeff[c-'A']*j);
        used[j] = false;
    }
    return res;
}

int main() {
    int N;
    while(cin >> N, N) {
        vector<bool> leading(26), used(10);
        vector<int> coefficient(26);
        vector <char> cs;
        for(int i=0; i<N; ++i) {
            string s;
            cin >> s;
            if(s.size() != 1) {
                leading[s[0]-'A'] = true;
            }
            reverse(s.begin(), s.end());
            for(int j=0, k=1; j<s.size(); ++j, k *= 10) {
                coefficient[s[j]-'A'] += k * (i == N - 1 ? -1 : 1);
                cs.push_back(s[j]);
            }
        }
        sort(cs.begin(), cs.end());
        cs.erase(unique(cs.begin(), cs.end()), cs.end());
        cout << dfs(0, cs, coefficient, leading, used, 0) << endl;
    }
}


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

int main(){
    int N;
    double ave;
    cin >> N;
    vector<int> v(N);
    for(int i=0;i<N;i++){
        cin >> v.at(i);
    }
    sort(v.begin(),v.end());
    ave = (double) (v.at(0)+v.at(1))/2;
    for(int i=2;i<N;i++){
        ave = (double) (ave+v.at(i))/2;
    }
    cout << ave << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> PA;
typedef priority_queue<int> PQ;
typedef vector<int> VE;
#define int long long
#define INF 1000000009
#define INFL 1000000000000000018
#define mod 1000000007
#define pb push_back
#define MAXN 100005

int h, w, a[1000][1000];
int d[3] = {0, 1, 0};
bool used[1000][1000];
int ans;
struct edge
{
    int x1;
    int y1;
    int x2;
    int y2;
};
vector<edge> G;

signed main()
{
    cin >> h >> w;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> a[i][j];
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(a[i][j] % 2 == 1){
                for(int k = 0; k < 2; k++){
                    int nx = i + d[k];
                    int ny = j + d[k + 1];
                    if(0 <= nx && nx < h && 0 <= ny && ny < w && a[i][j] % 2 == 1){
                        a[nx][ny]++;
                        a[i][j]--;
                        G.pb({i + 1, j + 1, nx + 1, ny + 1});
                        ans++;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    for(int i = 0; i < (int)G.size(); i++){
        printf("%lld %lld %lld %lld\n", G[i].x1, G[i].y1, G[i].x2, G[i].y2);
    }

    return 0;
}


Measured memory_bytes: 11632
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;

int main(void)
{
    IOS
    int n; cin >> n;
    vector<ll> v(n);
    ll mn = 1LL << 60;
    ll mx = (1LL << 60) * -1;
    int mni,mxi;

    auto ifmax = [&](int i) {
            if (mx < v[i]) {
            mx = v[i];
            mxi = i;
            }
        };
    auto ifmin = [&](int i) {
            if (mn > v[i]) {
                mn = v[i];
                mni = i;
            }
        };

    REP(i,n) {
        cin >> v[i];
        ifmax(i);
        ifmin(i);
    }

    vector<pair<int,int>> p;
    
    if (mx < 0 || (abs(mx) < abs(mn))) {
        for (auto i = n-1; i > 0 ; i--) {
            while(v[i] < v[i-1]) {
                v[i-1] += mn;
                p.emplace_back(make_pair(mni+1,i));
                ifmin(i-1);
            }
        }
    } else {
        for (auto i = 0; i < n-1 ; i++) {
            while(v[i] > v[i+1]) {
                v[i+1] += mx;
                p.emplace_back(make_pair(mxi+1,i+2));
                ifmax(i+1);
            }
        }
    }

    cout << p.size() << endl;
    for(auto x:p) {
        cout << x.first << " " << x.second << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;
const double PI=acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    ll n; cin>>n;
    vector<ll> a(n);
    rep(i,0,n) cin>>a[i];
    sort(all(a));
    set<ll> s;
    ll cnt=0;
    rep(i,0,n){
        if(i==0){
            if(a[i]==a[i+1]) cnt++;
        }
        bool ok=false;
        for(ll j=1; j*j<=a[i]; j++){
            if(a[i]%j==0){
                // debug(a[i]);
                // debug(j);
                if(s.count(j)==1 or s.count(a[i]/j)==1){
                    // debug(s.count(j));
                    // debug(s.count(a[i]/j));
                    ok=true;
                    break;
                }
            }
        }
        if(ok==false){
            if(i!=n-1 and i!=0){
                if(a[i]!=a[i-1] and a[i]==a[i+1]){
                    cnt++;
                }
            }
        }
        if(ok) cnt++;
        // debug(cnt);
        s.insert(a[i]);
    }
    cout<<n-cnt<<endl;

    
}

Measured memory_bytes: 13852
fun main(args: Array<String>) {
    val sc = java.util.Scanner(System.`in`)
    val list = sc.next().toCharArray().map(Char::toString).map(String::toInt).toMutableList()
    val a = 7 - list[0]
    sequenceOf(-1, 1).forEach { op1 ->
        sequenceOf(-1, 1).forEach { op2 ->
            sequenceOf(-1, 1).forEach { op3 ->
                if (list[1] * op1 + list[2] * op2 + list[3] * op3 == a) {
                    println("${list[0]}${if (op1 == 1) '+' else '-'}${list[1]}${if (op2 == 1) '+' else '-'}${list[2]}${if (op3 == 1) '+' else '-'}${list[3]}=7")
                    return
                }
            }
        }
    }
}


Measured memory_bytes: 35900
#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#define INC 0
#define DEC 1
#define clr(x, y) memset(x, y, sizeof x)
using namespace std;

typedef long long LL;
const int N = 2e5 + 5;

namespace Segment_Tree {
#define mid ((L + R) >> 1)
#define no ID(L, R)
#define lc ID(L, mid)
#define rc ID(mid + 1, R)
  LL key[N << 1][2], lazy[N << 1];
  
  inline void Init() {
    clr(key, 0x0f);
    clr(lazy, 0);
  }
  
  inline int ID(int L, int R) {return (L + R) | (L != R);}
  
  inline void PushDown(int L, int R) {
    if (L == R || !lazy[no]) return;
    key[lc][0] += lazy[no];
    key[rc][0] += lazy[no];
    key[lc][1] += lazy[no];
    key[rc][1] += lazy[no];
    lazy[lc] += lazy[no];
    lazy[rc] += lazy[no];
    lazy[no] = 0;
  }

  inline void PushUp(int L, int R) {
    key[no][0] = min(key[lc][0], key[rc][0]);
    key[no][1] = min(key[lc][1], key[rc][1]);
  }
  
  inline void Update(int L, int R, int x, LL val) {
    if (L == R) {
      key[no][0] = min((LL)val + L, key[no][0]);
      key[no][1] = min((LL)val - L, key[no][1]);
      return;
    }
    PushDown(L, R);
    if (x <= mid) Update(L, mid, x, val);
    else Update(mid + 1, R, x, val);
    PushUp(L, R);
  }

  inline LL Query(int L, int R, int l, int r, bool type) {
    if (L == l && R == r) return key[no][type];
    PushDown(L, R);
    if (r <= mid) return Query(L, mid, l, r, type);
    else if (l > mid) return Query(mid + 1, R, l, r, type);
    else return min(Query(L, mid, l, mid, type), Query(mid + 1, R, mid + 1, r, type));
  }

  inline LL Solve(int L, int R) {
    if (L == R) return key[L][no] - L;
    PushDown(L, R);
    return min(Solve(L, mid), Solve(mid + 1, R));
  }
#undef mid
#undef no
#undef lc
#undef rc
}
using namespace Segment_Tree;

int main() {
  int n, q, a, b, pre;
  scanf("%d%d%d%d", &n, &q, &a, &b);
  Init();
  pre = a;
  Update(1, n, b, 0LL);
  LL tmp;
  for (int i = 1, x; i <= q; i ++) {
    scanf("%d", &x);
    tmp = min(Query(1, n, x, n, INC) - x, Query(1, n, 1, x, DEC) + x);
    lazy[ID(1, n)] += abs(x - pre);
    Update(1, n, pre, tmp);
    pre = x;
  }
  printf("%lld\n", Solve(1, n));
  return 0;
}


Measured memory_bytes: 9728
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		List<Integer> b = new ArrayList<>();

		for(int i=0;i<N;i++) {
			b.add(sc.nextInt());
		}

		List<Integer> ans = listsearch(b,new ArrayList<Integer>());
		if(ans.size() == 0) {
			System.out.println(-1);
		}else {
			for(int i=ans.size()-1;i>=0;i--) {
				System.out.println(ans.get(i));
			}
		}

	}

	public static List<Integer> listsearch(List<Integer> b,List<Integer> ans) {

		if(b.size() == 0) return ans;

		List<Integer> b_temp;
		List<Integer> ans_temp;

		for(int i=b.size()-1;i>=0;i--) {
			if(b.get(i) == i+1) {
				b_temp = new ArrayList<>(b);
				ans_temp = new ArrayList<>(ans);
				b.remove(i);
				ans.add(i+1);
				List<Integer> c = listsearch(b,ans);
				if(c.size() != 0) {
					return c;
				}else {
					return new ArrayList<Integer>();
				}
			}
		}
		return new ArrayList<Integer>();
	}
}

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

int main() {
	string S;
	bool flg = true;
	int cnt = 0;
	cin >> S;

	for (int i = 0; i < (int)S.length(); i++)
	{
		if (i == 0){
			if (S[i] != 'A') {
				flg = false;
			}
		}
		else if(i>=2&&i<= (int)S.length()-2){
			if (S[i] == 'C') {
				cnt++;
			}
		}
		else if(S[i]<'a'||S[i]>'z') {
				flg = false;
		}
	}

	if (cnt != 1)
		flg = false;

	if (flg)
		cout << "AC" << endl;
	else
		cout << "WA" << endl;

	return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
c = []
while s = gets
  c.push(s.split.map(&:to_i))
end
if n == 1
  puts c[0][0]+c[1][0]
  exit
end
cnt = 0
for i in 0..n-1
  cnt += c[1][i]
end
cnt += c[0][0]
#puts cnt
max = cnt
for i in 1..n-1
  #p "#{c[0][i]} #{c[1][i-1]}"
  cnt = cnt + c[0][i] - c[1][i-1]
  if max <= cnt
    max = cnt
  end
  #puts cnt
end

puts max
  

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a,v) memset(a, v, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1e9+7;
const int N=2e5+5;
int main() {
    
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int T=1;
    // cin>>T;
    while(T--){
        int n,m;cin>>n>>m;
        vector<int> g[n+1];
        int ans[n+1];
        rep(i,m){
            int u,v;cin>>u>>v;g[u].pb(v);g[v].pb(u);
        }
        int v[n+1]={0};
        queue<pair<int,int> > q;
        q.push({1,1});
        while(!q.empty()){
            pii p=q.front();q.pop();
            v[p.fst]=1;
            ans[p.fst]=p.snd;
            for(auto j:g[p.fst]){
                if(v[j]==0){
                    q.push({j,p.fst});
                    v[j]=1;
                }
            }
        }
        cout<<"Yes"<<endl;
        repA(i,2,n){
            cout<<ans[i]<<endl;    
        }
    }   
    timecalculater();
    return 0;   
} 

Measured memory_bytes: 11040