akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

using namespace std;

#include <utility>
#include <vector>
#include <queue>

typedef pair<int, int> P;
class MinCostFlow {
#define MAX_V 10001
private:
  const int INF = 1e9 + 10;
  struct Edge {
    int to, cap, cost, rev;
    Edge(int to, int cap, int cost, int rev):
      to(to), cap(cap), cost(cost), rev(rev) { }
  };
  int V;
  vector<Edge> G[MAX_V];
  int h[MAX_V];
  int dist[MAX_V];
  int prevv[MAX_V], preve[MAX_V];

public:
  MinCostFlow(int V): V(V) { }

  void AddEdge(int from, int to, int cap, int cost) {
    G[from].push_back(Edge(to, cap, cost, G[to].size()));
    G[to].push_back(Edge(from, 0, -cost, G[from].size() - 1));
  }

  int Solve(int s, int t, int f) {
    int res = 0;
    fill(h, h + V, 0);
    
    while (f > 0) {
      priority_queue<P, vector<P>, greater<P>> que;
      fill(dist, dist + V, INF);
      dist[s] = 0;
      que.push(P(0, s));
      while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (dist[v] < p.first) {
          continue;
        }
        for (int i = 0; i < G[v].size(); i++) {
          Edge &e = G[v][i];
          if (e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
            dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
            prevv[e.to] = v;
            preve[e.to] = i;
            que.push(P(dist[e.to], e.to));
          }
        }
      }
      if (dist[t] == INF) {
        return -1;
      }
      for (int v = 0; v < V; v++) {
        h[v] += dist[v];
      }
      int d = f;
      for (int v = t; v != s; v = prevv[v]) {
        d = min(d, G[prevv[v]][preve[v]].cap);
      }
      f -= d;
      res += d * h[t];
      for (int v = t; v != s; v = prevv[v]) {
        Edge &e = G[prevv[v]][preve[v]];
        e.cap -= d;
        G[v][e.rev].cap += d;
      }
    }

    return res;    
  }
};

int main() {
  int V, E, F;
  cin >> V >> E >> F;

  MinCostFlow mcf(V);

  for (int i = 0; i < E; i++) {
    int u, v, c, d;
    cin >> u >> v >> c >> d;
    mcf.AddEdge(u, v, c, d);
  }
  
  int s = 0, t = V - 1;
  int ans = mcf.Solve(s, t, F);

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

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

typedef long long ll;

const int MAX_N = 1005;
const int MOD = 1000000007;

int pot(int a, int b) {
    int w = 1;
    while(b > 0) {
        if(b % 2 == 1) {
            w = ll(w) * ll(a) % ll(MOD);
        }
        a = ll(a) * ll(a) % ll(MOD);
        b /= 2;
    }
    return w;
}

int newton[MAX_N][MAX_N], DP[MAX_N][MAX_N];
int sil[MAX_N], odw[MAX_N];

int main() {
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    
    sil[0] = 1;
    odw[0] = pot(odw[0], MOD - 2);
    for(int i = 1; i <= n; i++) {
        sil[i] = ll(i) * ll(sil[i - 1]) % ll(MOD);
        odw[i] = pot(sil[i], MOD - 2);
    }
    
    for(int i = 0; i <= n; i++) {
        for(int j = 0; j <= i; j++) {
            if(i == 0 || j == 0 || i == j) {
                newton[i][j] = 1;
            } else {
                newton[i][j] = (newton[i - 1][j] + newton[i - 1][j - 1]) % MOD;
            }
        }
    }
    
    for(int i = 0; i <= n; i++) {
        DP[0][i] = 1;
    }
    
    for(int i = 1; i <= n; i++) {
        for(int j = a; j <= b; j++) {
            DP[i][j] = DP[i][j - 1];
            int akt = 1;
            for(int k = 1; k * j <= i; k++) {
                akt = ll(akt) * ll(newton[i - (k - 1) * j][j]) % ll(MOD);
                if(c <= k && k <= d) {
                    int dod = ll(akt) * ll(odw[k]) % ll(MOD);
                    dod = ll(dod) * ll(DP[i - k * j][j - 1]) % ll(MOD);
                    DP[i][j] = (DP[i][j] + dod) % MOD;
                }
            }
        }
    }
    cout << DP[n][b];
    
    return 0;
}


Measured memory_bytes: 11420
#include<stdio.h>
#include<stdlib.h>
int n, i;
int a[100000][2];
int compare_int(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}

int main(void){
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d", &a[i][0]);
		a[i][1]=i;
	}
	qsort(a, n, sizeof(int)*2, compare_int);
	for(i=0; i<n; i++){
		printf("%d ", a[i][1]+1);
	}
	printf("\n");
}


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; i++)
#define all(a) (a).begin(), (a).end()

int N;
vector<int> a, b;

int main () {
  cin >> N;
  a.resize(N), b.resize(N);

  rep(i,N) cin >> a[i];
  rep(i,N) cin >> b[i];

  const int D = 29;
  vector<vector<int>> pb(D, vector<int>(N));
  for(int d = 0; d < D; d++) {
    rep(i,N) pb[d][i] = b[i] % (1 << (d+1));
    sort(all(pb[d]));
  }

  int ans = 0;
  for(int d = 0; d < D; d++) {
    int c = 0;
    rep(i,N) {
      int ar = a[i] % (1<<(d+1));
      c += distance(lower_bound(all(pb[d]), (1<<d) - ar), lower_bound(all(pb[d]), (1<<(d+1)) - ar));
      c &= 1;
      c += distance(lower_bound(all(pb[d]), 3*(1<<d) - ar), lower_bound(all(pb[d]), (1<<(d+2)) - ar));
      c &= 1;
    }
    if(c) ans |= (1<<d);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 25344
n, t = map(int,input().split())
A = list(map(int,input().split()))

amin = A[0]
sa_max = [0, 0]
for i in range(1, n):
    if sa_max[0] < A[i]-amin:
        sa_max[0] = A[i]-amin
        sa_max[1] = 1
    elif sa_max[0] == A[i]-amin:
        sa_max[1] += 1
    amin = min(amin, A[i])
    # print(sa_max)

print(sa_max[1])

Measured memory_bytes: 63088
/*
    author: Salam_35
    Created at :

*/

#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define pb push_back
#define sc(n) scanf("%d",&n)
#define Max 100005
#define scan(n) scanf("%lld",&n)
#define pi acos(-1.0)
#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define sci(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define load(array,size)  for(ll i=0 ; i<size ; i++) cin>>array[i] ;
#define load1(array,size)  for(ll i=1 ; i<=size ; i++) cin>>array[i] ;
#define INF	1LL<<19
#define pll pair<ll,ll>
#define mst(arr,value) memset(arr,value,sizeof(arr));
#define tst() int testsalam;cin >> testsalam;while(testsalam--)
#define Mod 100000007
#define YES cout<<"Yes"<<endl;
#define NO cout<<"No"<<endl;
#define endl '\n'
//void inversemod(ll n, ll mod, ll invmod[],ll MOD){for(int i=2; i<=n; ++i) invmod[i]=MOD-MOD/i*invmod[MOD%i]%MOD;}
//void bigmod( ll a, ll b ,ll mod){ll r = 1;a = a%mod;while(b){if( b%2 ) r = (r*a)%mod;b = b/2;a = (a*a)%mod; }return (ll)r;}

typedef vector<ll>vec;
typedef pair<ll,ll> pii;
typedef map<ll,ll>mpll;
typedef set<ll>seet;

int main()
{
    string s,t;
    cin >> s >> t;
    int a=s.size();
    t=t.substr(0,a);
    if(s==t)YES
   	else NO
}


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

int main(){
    int count[5][4][11];

    // 初期化
    for(int i = 1; i < 5; i++){
        for(int j = 1; j < 4; j++){
            for(int k = 1; k < 11; k++){
                count[i][j][k] = 0;
            }
        }
    }

    // 入退出
    int b; // 棟
    int f; // 階
    int r; // 番目の部屋
    int v; // 人数

    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> b >> f >> r >> v;
        // cout << b << " " << f << " " << r << " " << v << endl;
        count[b][f][r] += v;
    }


    // 出力
    for(int i = 1; i < 5; i++){
        for(int j = 1; j < 4; j++){
            for(int k = 1; k < 11; k++){
                cout << " " << count[i][j][k];
            }
            cout << endl;
        }
        if(i != 4){
            cout << "####################" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3072
#include <algorithm>
#include <iostream>
#include <set>
#include <utility>
#include <vector>
using namespace std;

int main() {
  long long n, c, k;
  cin >> n >> c >> k;
  vector<long long> t(n);
  for (int i = 0; i < n; i++)
    cin >> t[i];
  sort(t.begin(), t.end());
  long long size = 0;
  long long ans = 0, mint;
  for (int i = 0; i < n; i++) {
    if (size == 0) {
      size++;
      mint = t[i];
    } else {
      if (t[i] - mint <= k) {
        size++;
      } else {
        ans++;
        size = 1;
        mint = t[i];
      }
    }
    if (size == c) {
      size = 0;
      ans++;
    }
  }
  if (size > 0) {
    ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int a = sc.nextInt();
            String m = sc.next();
            int b = sc.nextInt();

            if(m.equals("?")) break;
            if(m.equals("+")) System.out.println(a+b);
            if(m.equals("-")) System.out.println(a-b);
            if(m.equals("*")) System.out.println(a*b);
            if(m.equals("/")) System.out.println(a/b);
        }
    }
}


Measured memory_bytes: 26260
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
typedef long long LL;
const int N = 153;
int n, k, mod, f[N][N], g[N][N][N];
inline void qmo(int &x){x += (x >> 31) & mod;}
int main(){
	scanf("%d%d%d", &n, &k, &mod);
	if(k & 1){
		int lim = n + k >> 1; g[0][0][0] = 1;
		for(Rint i = 1;i <= lim;++ i){
			for(Rint j = 0;j <= n;++ j)
				for(Rint l = 0;l <= k + 1;++ l)
					qmo(g[i][0][0] += g[i - 1][j][l] - mod);
			if(i <= (n >> 1)){
				for(Rint j = 0;j <= n;++ j)
					for(Rint l = 0;l <= k + 1;++ l)
						qmo(g[i][j + 1][0] += g[i - 1][j][l] - mod);
			}
			if((i << 1) >= k + 1){
				for(Rint j = 0;j <= n;++ j){
					for(Rint l = 1;l <= k;++ l)
						qmo(g[i][0][l + 1] += g[i - 1][j][l] - mod);
					qmo(g[i][0][0] += g[i - 1][j][0] - mod);
				}
			}
			if(i <= (n >> 1) && (i << 1) >= k + 1){
				for(Rint j = 0;j <= n && j < k;++ j)
					for(Rint l = 0;l <= k;++ l)
						qmo(g[i][j + 1][max(j + 2, l + 1)] += g[i - 1][j][l] - mod);
			}
		}
		int ans = 0;
		for(Rint j = 0;j <= n;++ j)
			for(Rint l = 0;l <= k + 1;++ l)
				qmo(ans += g[lim][j][l] - mod);
		printf("%d\n", ans);
	} else {
		k >>= 1; f[0][0] = 1;
		int n1 = n >> 1, n2 = n - n1;
		for(Rint i = 1;i <= n2;++ i){
			for(Rint j = 0;j <= k;++ j)
				qmo(f[i][0] += f[i - 1][j] - mod);
			for(Rint j = 0;j < k;++ j)
				qmo(f[i][j + 1] += f[i - 1][j] - mod);
		}
		int ans1 = 0, ans2 = 0;
		for(Rint i = 0;i <= k;++ i) qmo(ans1 += f[n1][i] - mod);
		for(Rint i = 0;i <= k;++ i) qmo(ans2 += f[n2][i] - mod);
		printf("%d\n", (LL) ans1 * ans2 % mod);
	}
}

Measured memory_bytes: 12544
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    string N;
    cin >> N;
    char c = N.back();
    if (c == '2' or c == '4' or c == '5' or c == '7' or c == '9') {
        cout << "hon\n";
    } else if (c == '3') {
        cout << "bon\n";
    } else {
        cout << "pon\n";
    }
    
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll N;
  cin >> N;
  vector<ll> p(N);
  REP(i, N) cin >> p[i];

  vector<ll> q(N);
  REP(i, N) q[p[i]-1] = i;
  ll res = -1;
  REP(i, N){
    ll j = i;
    while(j<N-1 && q[j]<q[j+1]) j++;
    res = max(res, j-i+1);
    dump(i)
    dump(j)
    i = j;
  }
  cerr << q << endl;
  cout << N - res << endl;
  return 0;
}

Measured memory_bytes: 4992
package main

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

func main() {
  input := Input{bufio.NewReaderSize(os.Stdin,100)}
  n,k := input.NextInts()
  a := make([]int64,n)
  b := make([]int64,n+1)
  for i:=0;i<n;i++ {
    a[i] = input.NextInt()-k
    b[i+1] = b[i]+a[i]
  }
  c := compress(b)
  m := int64(0)
  bit := BinaryIndexTree{make([]int,n+1)}
  for i:=0;i<n+1;i++ {
    m += int64(bit.Sum(c[i]))
    bit.Add(c[i],1)
  }
  fmt.Print(m)
}
func compress(a []int64) []int {
  b := make([]int64,len(a))
  copy(b,a)
  sort.Sort(Int64Slice(b))
  m := map[int64]int{}
  v := 1
  for i:=0;i<len(b);i++ {
    if _,ok := m[b[i]];ok { continue }
    m[b[i]] = v
    v++
  }
  c := make([]int,len(a))
  for i:=0;i<len(a);i++ { c[i] = m[a[i]] }
  return c
}

type Int64Slice []int64
func(s Int64Slice) Len() int { return len(s) }
func(s Int64Slice) Less(i,j int) bool { return s[i] < s[j] }
func(s Int64Slice) Swap(i,j int) { s[i],s[j] = s[j],s[i] }

type BinaryIndexTree struct { bit []int }
func(b *BinaryIndexTree) Add(i,v int) {
  for x:=i;x<=len(b.bit);x+=x&-x { b.bit[x-1] += v }
}
func(b *BinaryIndexTree) Sum(i int) int {
  r := 0
  for x:=i;x>0;x-=x&-x { r += b.bit[x-1] }
  return r
}

type Input struct { reader *bufio.Reader }
func(i *Input) NextLine() string {
  var buffer []byte
  for {
    line,isPrefix,err := i.reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func(i *Input) NextInt() int64 {
  n,_ := strconv.ParseInt(i.NextLine(),10,64)
  return n
}
func(i *Input) NextInts() (int,int64) {
  s := strings.Split(i.NextLine()," ")
  n,_ := strconv.Atoi(s[0])
  k,_ := strconv.ParseInt(s[1],10,64)
  return n,k
}

Measured memory_bytes: 18432
#include <bits/stdc++.h>
#define endl        '\n'
#define pi          2*acos(0.0)
#define pb(a)       push_back(a)
#define db          double
#define ld          long double
#define ll          long long
#define ull         unsigned long long
#define mod         1000000007
#define inf         1000000000000000001
#define sqr(x)      (x) * (x)
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)   ((a/gcd(a,b)) * b)
#define debug(x) 	cerr << #x << " = " << (x) <<endl
#define all(x)      (x).begin(), (x).end()
#define unsyncIO    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)


using namespace std;

int main()
{
    //freopen("/home/taalpatar_shepai/Documents/my_codes/out.txt", "w", stdout);
    unsyncIO;
    ll n;
    cin >> n;
    string ans;
    while(n > 0) {
        n--;
        ans+=((char)('a' + n % 26));
        n /= 26;
    }
    for (ll i = ans.length() - 1; i >= 0; i--) {
        cout << ans[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3664
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int k = Integer.parseInt(in.readLine());
    String str[] = in.readLine().split(" ");
    int a = Integer.parseInt(str[0]);
    int b = Integer.parseInt(str[1]);
    int largest = (b/k) * k;
    System.out.println(a<=largest?"OK":"NG");
  }
}

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

typedef long long lli;

lli rec(int l, int r, vector<int> &A) {
  if(r-l <= 1) return 0;
  int n = A.size();
  int m = (l+r)/2;
  lli res = rec(l, m, A) + rec(m, r, A);
  queue<int> a, b;
  for(int i = l; i < m; ++i) a.push(A[i]);
  for(int i = m; i < r; ++i) b.push(A[i]);
  int k = l;
  while(a.size() && b.size()) {
    if(a.front() <= b.front()) {
      A[k++] = a.front();
      a.pop();
    } else {
      A[k++] = b.front();
      b.pop();
      res += a.size();
    }
  }
  while(a.size()) {
    A[k++] = a.front();
    a.pop();
  }
  while(b.size()) {
    A[k++] = b.front();
    b.pop();
  }
  return res;
}

int main() {
  int n;
  vector<int> A;
  cin >> n;
  A.resize(n);
  for(int i = 0; i < n; ++i) cin >> A[i];
  cout << rec(0, n, A) << endl;
  return 0;
}

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

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define mp(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    ll a[n];
    ll ans = 0;
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    int tn = n - 1;
    for (int i = n - 1; i > 0; i--) {
        if (i == n - 1) {
            tn--;
            ans += a[i];
            continue;
        }
        if (tn >= 2) {
            ans += 2 * a[i];
            tn -= 2;
        } else {
            ans += a[i];
            tn--;
        }
        if (tn == 0) break;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 5172
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int N;
  cin >>N;
  vector<string> B(N);
  rep(i,N) {
cin >>B.at(i);
  }
  
  int M;
  cin >>M;
  vector<string> R(M);
  rep(i,M) {
    cin >>R.at(i);
  }
  
  
  
  
  
  
  int plus=0;
  int minus=0;
  vector<int>vec(N);
  
  rep(i,N) {
    //Blue内部
    repl(j,0,N) {
      if(B.at(j)==B.at(i)) {
        plus++;
      }
    }
    
    //Red内部
    rep(k,M) {
if( R.at(k)==B.at(i)) {
  minus++;
}
    }
    
    vec.at(i)=plus-minus;
    plus=0;
    minus=0;
  }
  
  sort(all(vec));
  cout<< max(vec.at(N-1),0)<< endl;
  
  
  
  }

    


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

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    cout << *max_element(A.begin(), A.end()) - *min_element(A.begin(), A.end()) << endl;
}


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

int lcs(string str1,string str2,int m,int n)
{
	if(m==0||n==0)
		return 0;
	if(str1[m-1]==str2[n-1])
		return 1+lcs(str1,str2,m-1,n-1);
	else return max(lcs(str1,str2,m-1,n),lcs(str1,str2,m,n-1));
}
//dp
string lcs(string str1,string str2)
{
	int n=str1.size();
	int m=str2.size();
int dp[str1.size()+1][str2.size()+1];
for(int i=0;i<=str1.size();i++)
{
	for(int j=0;j<=str2.size();j++)
	{
		if(i==0||j==0)
			dp[i][j]=0;
		else if(str1[i-1]==str2[j-1])
			dp[i][j]=1+dp[i-1][j-1];
		else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
	}

}
//cout<<"length of LCS= "<<dp[n][m]<<endl;
string ans,rans;
int i=n,j=m;
if(dp[n][m]==0)
	return " ";
while(dp[i][j])
{
	if(str1[i-1]==str2[j-1])
		{ans+=str1[i-1];i--;j--;}
	else if(dp[i-1][j]>dp[i][j-1])
		 i--;
    else  j--;
}

for(auto i=ans.rbegin();i!=ans.rend();i++)
     rans+=(*i);
 return rans;
}

int main()
{
	string str1,str2;
	cin>>str1>>str2;
   // cout<<lcs(str1,str2,str1.size(),str2.size());
    cout<<lcs(str1,str2);

}


Measured memory_bytes: 35456
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void rd(char &c){
  int i;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
int K;
char S[100002];
int main(){
  int i;
  int res = 0;
  rd(N);
  rd(K);
  rd(S);
  for(i=(1);i<(N);i++){
    if(S[i]==S[i-1]){
      res++;
    }
  }
  res =min_L(N-1, res+2*K);
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190914-1

// --- original code ---
// int N, K;
// char S[100002];
// {
//   int res = 0;
//   rd(N,K,S);
//   rep(i,1,N) if(S[i]==S[i-1]) res++;
//   res = min(N-1, res+2K);
//   wt(res);
// }


Measured memory_bytes: 384
N, K = map(int, input().split())
ans = 0
MOD = 10**9+7
for i in range(K, N+2):
    b = N*(N+1)//2-(N-i)*(N-i+1)//2
    a = (i-1)*i//2
    ans += b-a+1
    ans %= MOD
print(ans)


Measured memory_bytes: 9148
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(n);++i)
const int INF =1001001001;
using ll=long long;
using P = pair<int,int>;
using Graph =vector<string>;
Graph field;
queue<P> q;

int main() {
  ll a,b,c,d,m;
  m=-1000000000000000000;
  cin>>a>>b>>c>>d;
  m=max(b*d,max(b*c,max(a*d,max(m,a*c))));
  cout<<m<<endl;
}


Measured memory_bytes: 3628
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var pos = new long[] { 0, 0, 0 };
            for (var i = 0; i < N; ++i)
            {
                var target = Sarray();
                var dst = Abs(target[1] - pos[1]) + Abs(target[2] - pos[2]);
                var time = target[0] - pos[0];
                if (time < dst)
                {
                    WriteLine("No");
                    return;
                }
                if ((time - dst) % 2 != 0)
                {
                    WriteLine("No");
                    return;
                }
                pos = target;
            }
            WriteLine("Yes");
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 17452
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
typedef unsigned long long llu;
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define f  first
#define s  second
#define mp make_pair
#define pb push_back
#define ep emplace_back
#define sz(a) (int) a.size()
#define FOR(x,a,b) for (int x=a;x<=b;x++)
#define FOD(x,a,b) for (int x=a;x>=b;x--)
#define REP(x,a,b) for (int x=a;x<b;x++)
#define RED(x,a,b) for (int x=a;x>b;x--)
#define EL printf("\n")
#define debug 1
ld n,a;
ld s;
int main()
{
	IO;
	cin>>n;
      if((int)n%2==0) a=(int)n/2;
      else a=((int)n+1)/2;
      cout<<setprecision(10)<<fixed<<a/n;
	return 0;
}


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

int gcd(int a,int b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}

int main()
{
    ll a,b,c,d; cin>>a>>b>>c>>d;
    ll n=b-a+1; ll lcm=(c*d)/gcd(c,d);
    ll ub=b/c+b/d-b/lcm;
    ll ua=(a-1)/c+ (a-1)/d -(a-1)/lcm;
    cout<<n-(ub-ua);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define ocut cout
#define ouct cout
#define itn int

struct Union{
  vector<ll> par;
  Union(ll a){
  par=vector<ll>(a,-1);
  }
  ll find(ll a){
    if(par[a]<0){
      return a;
    }
    else{
      return par[a]=find(par[a]);
    }
  }
  bool same(ll a,ll b){
    return (find(a)==find(b));
  }
  ll size(ll a){
    return -par[find(a)];
  }
  void unite(ll a,ll b){
    ll c=find(a),d=find(b);
    if(c==d)
      return;
    if(size(c)<size(d)){
      swap(c,d);
    }
    par[c]+=par[d];
    par[d]=c;
  }
};

int main(){
  ll n;
  cin >> n;
  char s[n+1];
  ll r[n],g[n],q=0,w=0,e=0;
  cin >> s;
  rep(i,n){
    if(s[i]=='R'){
      r[q]=i;
      q++;
    }
    if(s[i]=='G'){
      g[w]=i;
      w++;
    }
    if(s[i]=='B'){
      e++;
    }
  }
  ll ans=0;
  rep(i,q){
    rep(j,w){
      ans=ans+e;
      if(r[i]+r[i]-g[j]>-1&&r[i]+r[i]-g[j]<n&&s[r[i]+r[i]-g[j]]=='B')ans--;
      if(g[j]-r[i]+g[j]>-1&&g[j]-r[i]+g[j]<n&&s[g[j]-r[i]+g[j]]=='B')ans--;
      if((r[i]+g[j])%2==0&&s[(r[i]+g[j])/2]=='B')ans--;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3648
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;

int main(){
    int n,l,sum=0,maxl=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>l;
        sum+=l;
        maxl=max(maxl,l);
    }
    if(sum>2*maxl)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 764
n, w = map(int, input().split())

value = []
weight = []

for _ in range(n):
  vi, wi = map(int, input().split())
  value.append(vi)
  weight.append(wi)

dp = [0 for _ in range(w + 1)]

for i in range(n):
  for j in range(weight[i] ,w + 1):
    dp[j] = max(dp[j], dp[j - weight[i]] + value[i])

print(dp[w])


Measured memory_bytes: 5728
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

class UnionFind {
public:
  vector<ll> par; 
  vector<ll> siz; 

    
  UnionFind(ll sz_): par(sz_), siz(sz_, 1) {
    for (ll i = 0; i < sz_; ++i) par[i] = i; 
  }
  void init(ll sz_) {
    par.resize(sz_);
    siz.resize(sz_, 1);
    for (ll i = 0; i < sz_; ++i) par[i] = i;
  }

  ll root(ll x) { 
    while (par[x] != x) {
      x = par[x] = par[par[x]];
    }
    return x;
  }

  bool merge(ll x, ll y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (siz[x] < siz[y]) swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }

  bool issame(ll x, ll y) {
    return root(x) == root(y);
  }

  ll size(ll x) {
    return siz[root(x)];
  }
};

int main() {
  int n, k, l;
  cin >> n >> k >> l;
  UnionFind road(n), rail(n);
  rep(i, k) {
    int p, q;
    cin >> p >> q;
    road.merge(p - 1, q - 1);
  }
  rep(i, l) {
    int r, s;
    cin >> r >> s;
    rail.merge(r - 1, s - 1);
  }

  map<pair<int, int>, int> m;
  rep(i, n) m[{road.root(i), rail.root(i)}]++;
  rep(i, n) {
    if (i) cout << " ";
    cout << m[{road.root(i), rail.root(i)}];
  }
  cout << endl;







  
  return 0;
}

Measured memory_bytes: 18048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define debug(x) cerr << "[(" << __LINE__ << ") " << (#x) << "]: " << x << endl;

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

    int x;
    cin >> x;

    cout << x/500 * 1000 + (x%500)/5 * 5 << "\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
    int a, b;
    cin >> a >> b;
    int ans;

    if (a < 10 && b < 10) {
        ans = a * b;
    }
    else {
        ans = -1;
    }

    cout << ans << endl;

    return 0;
}


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

int main()
{
	string s;
	cin >> s;
	string ans;
	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0) ans += s.at(i);
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
n,m = gets.split.map(&:to_i)
dp = Array.new(n+1){[1,false]}
dp[1][1] = true
m.times do
  a,b = gets.split.map(&:to_i)
  dp[b][0] += 1
  dp[a][0] -= 1
  dp[b][1] = dp[b][1] || dp[a][1]
  dp[a][1] = false if dp[a][0] == 0
end
ans = 0
dp.each {|num,bool| ans += 1 if bool}
p ans


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

#define REP(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define FOR(i,k,n) for(ll (i) = (k); (i) < (n); ++(i))

const ll INF = 1e9;

signed main(){
    int n,m;
    cin >> n >> m;
    vector<int> a(m);
    vector<int> b(m);
    vector<int> c(m);
    REP(i,m){
        cin >> a[i] >> b[i] >> c[i];
        --a[i];--b[i];
    }
    vector<vector<P>> edges(n);
    REP(i,m){
        edges[a[i]].emplace_back(b[i], c[i]);
        edges[b[i]].emplace_back(a[i], c[i]);
    }

    auto dijk = [&](int st){
        vector<ll> range(n, INF);
        priority_queue<P, vector<P>, greater<P>> que;
        que.emplace(0, st);
        vector<int> flag(n, 0);
        range[st] = 0;

        while(!que.empty()){
            ll pos, ran;
            std::tie(ran, pos) = que.top();
            que.pop();

            if(flag[pos])continue;
            flag[pos] = 1;

            for(auto xx : edges[pos])
                if(range[xx.first] > ran + xx.second){
                    range[xx.first] = ran + xx.second;
                    que.emplace(range[xx.first], xx.first);
                }
        }
        return range;
    };

    ll ma = 0;
    vector<P> mapos;

    std::vector<std::vector<ll>> ranges(n);
    REP(i,n){
        ranges[i] = move(dijk(i));
        REP(j,n)
            if(ma <= ranges[i][j]){
                if(ma < ranges[i][j])
                    mapos.clear();
                ma = ranges[i][j];
                if(i < j)
                    mapos.emplace_back(i, j);
            }
    }
    vector<int> fl(n, false);
    REP(i,n){
        for(auto xx : mapos)
            if(ranges[i][xx.first] + ranges[i][xx.second] == ma)
                fl[i] = true;
    }


    /*
    for(auto xx : ranges){
        for(auto yy : xx)cout << yy << " ";
        cout << endl;
    }

    cout << ma << endl;
    for(auto xx : mapos)cout << xx.first << " " << xx.second << endl;
    */

    cout << count(fl.begin(), fl.end(), 0) << endl;
    REP(i,n)if(fl[i] == 0)cout << i + 1 << endl;

}



Measured memory_bytes: 48880
#include<bits/stdc++.h>
using namespace std;
#define _ ios::sync_with_stdio(false);cin.tie(0);
#define __ cout<<fixed;cout<<setprecision(10);
#define int long long

void solve() {
	int n, d;
	cin >> n >> d;
	int arr[n];
	vector<pair<int, int>> p;
	for (int i = 0 ; i < n; i++) {
		int a, b;
		cin >> a >> b;
		p.push_back(make_pair(a, b));
	}
	for (int i = 0; i < n; i++) {
		int p1, q1;
		p1 = p[i].first;
		q1 = p[i].second;
		arr[i] = (p1 * p1) + (q1 * q1);
	}
	/*for (int i = 0 ; i < n; i++) {
		cout << arr[i] << " ";
	}
	cout << "\n";*/
	int count = 0;
	for (int i = 0; i < n; i++) {
		if (arr[i] <= d * d) {
			count++;
		}
	}
	cout << count << "\n";
}

int32_t main() {
	_ __
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}

#ifndef ONLINE_JUDGE
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
#endif

	return 0;
}

Measured memory_bytes: 7924
#include <cstdint>
#include <iostream>
#include <string>

using namespace std;

int32_t main()
{
  uint32_t _;
  cin >> _;

  string str;
  cin >> str;
  int32_t x = 0;
  int32_t m = x;
  for (uint32_t i = 0; i < str.size(); i++) {
    if (str[i] == 'I') {
      x++;
    } else {
      x--;
    }
    m = max(m, x);
  }

  cout << m << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<queue>
#include<iostream>
using namespace std;
typedef long long ll;
inline ll read(){
	ll x=0,f=1;char ch=getchar();
	while(ch!='-'&&(ch>'9'||ch<'0')) ch=getchar();
	if(ch=='-') f=-1,ch=getchar();
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*f;
}

const int maxn=1e5+5;
struct edge{int v,p;}e[maxn<<1];int tot,last[maxn];
int n,m,col[maxn];
ll sum[2];bool flag;
inline void insert(int u,int v){e[++tot]=(edge){v,last[u]};last[u]=tot;}
inline void ins(int a,int b){insert(a,b);insert(b,a);}

inline void dfs(int x,int c){
	col[x]=c;
	for(int i=last[x],v;i;i=e[i].p){
		v=e[i].v;
		if(col[v]==-1) dfs(v,c^1);
		if(col[v]==col[x]) {flag=1;return;}
	}
}

int main(){
	n=read();m=read();
	memset(col,-1,sizeof(col));
	for(int i=1,a,b;i<=m;i++)
		a=read(),b=read(),ins(a,b);
	dfs(1,0);
	if(flag) cout<<(ll)n*(n-1)/2-m;
	else{
		for(int i=1;i<=n;i++)
			sum[col[i]]++;
		cout<<sum[0]*sum[1]-m<<endl;
	}
	return 0;
}

Measured memory_bytes: 2944
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import fractions
import random
from heapq import heappop,heappush
import time
import os
import sys
import datetime
from functools import lru_cache
readline=readline = sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def fac_list(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s


#@lru_cache(maxsize=None)  
def f():
    return 1
#main
L=int(input())
R=[]
print((L/3)**3)

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

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var nk = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var n = nk[0];
        var k = nk[1];
        var rsp = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var t = Console.ReadLine().Trim().Select(x => x == 'r' ? 2 : x == 's' ? 0 : 1).ToArray();

        var p = 0;
        for (int i = 0; i < k; ++i)
        {
            p += rsp[t[i]];
        }
        for (int i = k; i < t.Length; ++i)
        {
            if (t[i - k] >= rsp.Length || t[i - k] != t[i])
            {
                p += rsp[t[i]];
                continue;
            }

            if (rsp[t[i]] > rsp[t[i - k]])
            {
                p -= rsp[t[i - k]];
                p += rsp[t[i]];
            }
            else
            {
                t[i] = int.MaxValue;
            }
        }
        Console.WriteLine(p);
    }
}


Measured memory_bytes: 14944
namespace VainZero.Procon.FSharp

open System
open System.Collections.Generic

type Heap<'x> (list: ResizeArray<'x>, compare: 'x -> 'x -> int) =
  member this.Count = list.Count
 
  member this.Min =
    list.[0]
 
  member this.Enqueue(value) =
    list.Add(value)
    let rec loop i =
      if i > 0 then
        let parentIndex = (i - 1) >>> 1
        if compare list.[parentIndex] value > 0 then
          list.[i] <- list.[parentIndex]
          loop parentIndex
        else
          i
       else
        i
    let i = loop (this.Count - 1)
    list.[i] <- value
 
  member this.Dequeue() =
    let min = list.[0]
    let x = list.[this.Count - 1]
    let rec loop i =
      let l = (i <<< 1) + 1
      let r = (i <<< 1) + 2
      if l >= this.Count then
        i
      else
        // Index of the smaller child.
        let c = if r < this.Count && compare list.[r] list.[l] < 0 then r else l
        if compare list.[c] x >= 0 then
          i
        else
          list.[i] <- list.[c]
          loop c
    let i = loop 0
    list.[i] <- x
    list.RemoveAt(this.Count - 1)
    min

  member this.AsList =
    list :> IReadOnlyList<_>
 
  static member FromEnumerable(xs, compare) =
    let list = xs |> Seq.sortWith compare |> ResizeArray
    Heap(list, compare)

[<AutoOpen>]
module Operators =
  let read f = Console.ReadLine().Split([|' '|]) |> Array.map f

module Program =
  [<EntryPoint>]
  let main _ =
    let n = Console.ReadLine() |> int
    let xs = read int64

    let negativeCompare l r = - (compare l r)

    let calc () =
      let solve compare (xs: array<int64>) =
        [|
          let heap = Heap<_>.FromEnumerable(ArraySegment(xs, 0, n), compare)
          let mutable sum = heap.AsList |> Seq.sum
          yield sum
          for i in n..(2 * n - 1) do
            let x = xs.[i]
            heap.Enqueue(x)
            let y = heap.Dequeue()
            sum <- sum - y + x
            yield sum
        |]

      let positives = solve compare xs
      let negatives = solve negativeCompare (xs |> Array.rev) |> Array.rev

      seq {
        for i in 0..n ->
          positives.[i] - negatives.[i]
      } |> Seq.max

    printfn "%d" (calc ())

    0


Measured memory_bytes: 51648
#include<bits/stdc++.h>
#define For(i,a,b) for(i=(a);i<=(b);++i)
#define Forward(i,a,b) for(i=(a);i>=(b);--i)
#define Rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define Repe(i,a,b) for(register int i=(a);i>=(b);--i)
using namespace std;
template<typename T>inline void read(T &x)
{
    T s=0,f=1;char k=getchar();
    while(!isdigit(k)&&(k^'-'))k=getchar();
    if(!isdigit(k)){f=-1;k=getchar();}
    while(isdigit(k)){s=s*10+(k^48);k=getchar();}
    x=s*f;
}
const int MAXN=1e5+7;

static int n,m,a[MAXN];

static vector<int>p[MAXN];

inline void init()
{
	read(n);read(m);
	Rep(i,1,n)read(a[i]);
	static int u,v;
	Rep(i,1,m)read(u),read(v),p[u].push_back(v),p[v].push_back(u);
}

static int vis[MAXN],ans,sta1[MAXN],sta2[MAXN],tp;

void dfs(int u)
{
	vis[u]=100;sta1[++tp]=u;sta2[tp]=a[u];
	for(int v:p[u])if(!vis[v])dfs(v);
}

inline void solve()
{
	static int p1,p2;
	Rep(i,1,n)if(!vis[i])
	{
		tp=0;
		dfs(i);
		sort(sta1+1,sta1+tp+1);
		sort(sta2+1,sta2+tp+1);
		p1=p2=1;
		while(p1<=tp&&p2<=tp)
		{
			while(p1<=tp&&p2<=tp&&sta1[p1]!=sta2[p2])
			{
				while(p1<=tp&&sta1[p1]<sta2[p2])++p1;
				while(p2<=tp&&sta1[p1]>sta2[p2])++p2;
			}
			if(p1<=tp&&p2<=tp&&sta1[p1]==sta2[p2])++ans,++p1,++p2;
		}
	}
	printf("%d\n",ans);
}
int main()
{
    init();
    solve();
    return 0;
}


Measured memory_bytes: 9344
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int a=sc.nextInt();
    int b=sc.nextInt();
    int c=sc.nextInt();
    int[] l=new int[n];
    for(int i=0;i<n;i++){
      l[i]=sc.nextInt();
    }
    int all[]=new int[n];
    int min=Integer.MAX_VALUE;
    Arrays.fill(all,0);
    do{
      min=Math.min(calc2(all,a,b,c,l),min);
    }while(calc(all));
    System.out.println(min);
  }
  static int calc2(int[] all,int a,int b,int c,int[] l){
    int marge=0;
    int n[]={0,0,0,0};
    for(int i=0;i<all.length;i++){
      if(all[i]!=0&&n[all[i]]!=0){
        marge+=10;
      }
      n[all[i]]+=l[i];
    }
    if(n[1]==0||n[2]==0||n[3]==0){
      return Integer.MAX_VALUE;
    }
    return Math.abs(a-n[1])+Math.abs(b-n[2])+Math.abs(c-n[3])+marge;
  }
  static boolean calc(int[] all){
    boolean res=false;
    for(int i=0;i<all.length;i++){
      if(all[i]==3){
        all[i]=0;
      }else{
        all[i]++;
        res=true;
        break;
      }
    }
    return res;
  }
}

Measured memory_bytes: 24020
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

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; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

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

  ll a, b, c;
  cin >> a >> b >> c;
  if (c - a - b <= 0) {
    puts("No");
    return 0;
  }
  if (4 * a * b < (c - a - b) * (c - a - b)) {
    puts("Yes");
  } else {
    puts("No");
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
int N;
LL A[200001];
LL S[200001];
int main(){
	cin>>N;
	REP(i,N){
		cin>>A[i];
		if(i==0){
			S[i]=A[i];
		}else{
			S[i]=S[i-1]+A[i];
		}
	}
	int a=0;
	int c=2;
	LL ans=1e15;
	for(int i=0;i<=N-2;i++){
		while(1){
			if(abs(S[a]-(S[i]-S[a]))>abs(S[a+1]-(S[i]-S[a+1]))){
				a++;
			}else{
				break;
			}
		}
		if(i==c)c++;
		while(1){
			if(abs((S[c]-S[i])-(S[N-1]-S[c]))>abs((S[N-1]-S[c+1])-(S[c+1]-S[i]))){
				c++;
			}else{
				break;
			}
		}
		//cout<<a<<c<<endl;
		LL v[4];
		v[0]=S[a];
		v[1]=S[i]-S[a];
		v[2]=S[c]-S[i];
		v[3]=S[N-1]-S[c];
		LL mi=1e15;
		LL ma=0;
		REP(i,4){
			//cout<<"v"<<v[i]<<endl;
			mi=min(mi,v[i]);
			ma=max(ma,v[i]);
		}
		ans=min(ans,ma-mi);
	}
	cout<<ans<<endl;
	
	return(0);
}

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

int gcd(int a, int b){
    if(b == 0)
        return a;
    return gcd(b, a % b);
}


int main(){
    int N, X, ans;
    cin >> N >> X;
    vector<int> x(N);

    for(int i=0; i<N; i++){
	cin >> x[i];
	x[i] = abs(X-x[i]);
    }
    ans = x[0];
    for(int i=1; i<N; i++){
	ans = gcd(ans, x[i]);
    }

    
    cout << ans<< endl;

}




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

typedef long long ll;

int main(){
	static ll n;
	static ll a[300010];
	scanf("%lld",&n);
	for(int i=0;i<3*n;i++)scanf("%lld",&a[i]);
	
	static ll b[300010],c[300010];
	if(1){
		priority_queue<ll,vector<ll>,greater<ll>> S;
		ll sum=0;
		for(int i=0;i<n;i++){
			S.push(a[i]);
			sum+=a[i];
		}
		b[n-1]=sum;
		for(int i=n;i<2*n;i++){
			S.push(a[i]);
			sum+=a[i];
			ll x=S.top(); S.pop();
			sum-=x;
			b[i]=sum;
		}
	}
	if(1){
		priority_queue<ll> S;
		ll sum=0;
		for(int i=3*n-1;i>=2*n;i--){
			S.push(a[i]);
			sum+=a[i];
		}
		c[2*n]=sum;
		for(int i=2*n-1;i>=n;i--){
			S.push(a[i]);
			sum+=a[i];
			ll x=S.top(); S.pop();
			sum-=x;
			c[i]=sum;
		}
	}
	ll ret=b[n-1]-c[2*n];
	for(int i=n-1;i<=2*n-1;i++){
		ret=max(ret,b[i]-c[i+1]);
	}
	cout<<ret<<endl;
}

Measured memory_bytes: 7908
#include<bits/stdc++.h>
#include<time.h>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <cstdio>
#include <string>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef unsigned long long uLL;

#define ls rt<<1
#define rs rt<<1|1
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define bug printf("*********\n")
#define FIN freopen("input.txt","r",stdin);
#define FON freopen("output.txt","w+",stdout);
#define IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

#define SZ(x) ((int)(x).size())

#define readi read<int>()
#define readll read<ll>()


const ll mod=998244353;

ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

template <typename T>
inline T read() {  //ÉùÃ÷ template Àà,ÒªÇóÌá¹©ÊäÈëµÄÀàÐÍT,²¢ÒÔ´ËÀàÐÍ¶¨ÒåÄÚÁªº¯Êý read()
  T sum = 0, fl = 1;  //½« sum,fl ºÍ ch ÒÔÊäÈëµÄÀàÐÍ¶¨Òå
  int ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') fl = -1;
  for (; isdigit(ch); ch = getchar()) sum = sum * 10 + ch - '0';
  return sum * fl;
}

//head

const int N=2000+7;
bitset<N> fl[N],fr[N],a[N],tmp;


int n;
int main()
{
	IO;
	cin>>n;
	for (int i=2;i<=n;i++)
	{
		string s;
		cin>>s;
		for (int j=0;j<s.length();j++)
		{
			if (s[j]=='1') a[i][j+1]=1;
			
			a[j+1][i]=1-a[i][j+1];
			//cin>>a[i][j];
			//a[j][i]=1-a[i][j]; 
		}
	}
	
	for (int i=1;i<=n;i++) fl[i][i]=1,fr[i][i]=1; 
	for (int i=2;i<=n;i++)
	{
		for (int j=1;j<=n;j++)
		{
			if (j+i-1>n) break;
			if ((fr[j] & fl[j + i - 1 - 1] & a[j + i - 1]).count()>0)
			{
				fr[j][j + i - 1]=1;
			}
			
			if ((fr[j+1] & fl[j + i - 1 ] & a[j]).count()>0)
			{
				fl[j + i - 1][j]=1;
			}
		}
	}
	
	int ans=(fr[1] & fl[n]).count();
	
	cout<<ans<<"\n";
}

Measured memory_bytes: 1792