akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
 
import java.util.*;
public class Main {
	int T,N,D;
	public void solve(){
		T = nextInt();
		for(int i = 0;i < T;i++){
			N = nextInt();
			D = nextInt();
			
			PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
			pq.add(D);
			for(int j = 0;j < N - 1;j++){
				int d = pq.poll();
				pq.add(127);
				pq.add(d ^ 127);
			}
			int sum = 0;
			while(pq.size() > 0){
				sum += pq.poll();
			}
			
			out.println(sum);
		}
	}
 
	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}
 
	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;
 
	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}
 
	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}
 
	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}
 
	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}
 
	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}
 
	public int nextInt() {
		return Integer.parseInt(next());
	}
 
	public long nextLong() {
		return Long.parseLong(next());
	}
 
	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

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

#define rep(i,N) repv(i,0,N)
#define reps(i,N) repvs(i,0,N)
#define repv(i,a,b) for(int i=a;i<b;i++)
#define repvs(i,a,b) for(int i=a+1;i<=b;i++)
#define repr(i,N) for(int i=N-1;i>=0;i--)
#define reprs(i,N) for(int i=N;i>0;i--)

#define debug(a) if(isDebugMode) cout<<#a<<"="<<a<<","
#define debug2(a,b) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b
#define debug3(a,b,c) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c
#define debug4(a,b,c,d) if(isDebugMode) cout<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<","<<#d<<"="<<d
#define debugarr(arr,N){if(isDebugMode){ rep(i,N+1)\
	{if(arr[i]==INF)printf("INF ");\
		else cout<<arr[i]<<" ";} cout<<endl;}}
#define debugarr2(arr,N,M){if(isDebugMode) rep(i,N+1){rep(j,M+1)\
	{if(arr[i][j]==INF)printf(" INF");\
		else printf(" %3d",arr[i][j]);} cout<<endl;}}
#define pb push_back
#define pob pop_back
#define show(a) cout<<a<<endl;

auto chmax =[](int &a,int b){a=max(a,b);};
auto chmin =[](int &a,int b){a=min(a,b);};

typedef long long ll;
typedef pair<int,int> P;
const int INF=100000000;
const int dx[4]={ 0, 1, 0,-1};
const int dy[4]={ 1, 0,-1, 0};

bool isDebugMode=true;
//--------------------------------------//
int n,m,X,Y;

int main(){
	cin>>n>>m>>X>>Y;
	int ma=X;
	rep(i,n){
		int x;
		cin>>x;
		chmax(ma,x);
	}
	int mi=Y;
	rep(i,m){
		int y;
		cin>>y;
		chmin(mi,y);
	}
	repv(i,-100,101){
		if(i>ma&&i<=mi){ cout<<"No War"<<endl;return 0;}
	}
	cout<<"War"<<endl;
	return 0;
}


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

typedef long long ll;
typedef pair<ll,ll> ii;
typedef long double ld;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
const int INF=2012345678;
const ll LLINF=4012345678012345678LL;
const ll MOD=1000000007; //998244353; //
const ld PI=3.1415926535898;
const ld EPS=1e-9;
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(b==0)return a;return gcd(b,a%b);}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll expo(ll b,ll p,ll m){ll res=1; while(p){if(p&1)res=(res*b)%m; b=(b*b)%m; p>>=1;} return res;}
inline ll modinv(ll a,ll m){return expo(a,m-2,m);}

int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	printf("%d",a*b);
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const int MOD = 1e9 + 7;
int main()
{
    ll A,B,N;
    cin>>A>>B>>N;
    ll x=min(B-1,N);
    cout<<floor(A*x/B)<<endl;
}

Measured memory_bytes: 3780
#include <iostream>
#include <string>
#include <vector>
using ll=long long;
using namespace std;

long long pow(long long a,long long b,long long mod){
    if(b==0){
        return 1;
    }else{
        if(b%2==0){
            return pow(a*a%mod,b/2,mod);
        }else{
            return pow(a*a%mod,b/2,mod)*a%mod;
        }
    }

}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

int main(){
    int n,k;
    cin>>n>>k;
    k=min(k,n-1);

    ll mod=1e9+7;

    vector<ll> fact(n+1);
    vector<ll> ifact(n+1);
    fact[0]=1;
    ifact[0]=1;
    ll f=1;
    ll inv=1;
    for(int i=1;i<=n;i++){
        f*=i;
        f%=mod;
        inv*=modinv(i,mod);
        inv%=mod;
        fact[i]=f;
        ifact[i]=inv;
    }

    ll ans=0;
    ll comb1,comb2;
    for(int i=0;i<=k;i++){
        comb1=fact[n]*ifact[n-i]%mod;
        comb1=comb1*ifact[i]%mod;
        comb2=fact[n-1]*ifact[n-i-1]%mod;
        comb2=comb2*ifact[i]%mod;
        //cout<<comb1<<" "<<comb2<<endl;
        ans+=comb1*comb2%mod;
        ans%=mod;
    }

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

Measured memory_bytes: 6384
import unittest


class TestA(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think([1, 2, 3]), (3, 1, 2))

    def test_2(self):
        self.assertEqual(think([100, 100, 100]), (100, 100, 100))

    def test_3(self):
        self.assertEqual(think([41, 59, 31]), (31, 41, 59))


def solve():
    xyz = read()
    result = think(xyz)
    write(result)


def read():
    return read_int(3)


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(xyz):
    return xyz[2], xyz[0], xyz[1]


def write(result):
    print('{0:d} {1:d} {2:d}'.format(result[0], result[1], result[2]))


if __name__ == '__main__':
    # unittest.main()
    solve()

Measured memory_bytes: 49904
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jaynil
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        E1Or2 solver = new E1Or2();
        solver.solve(1, in, out);
        out.close();
    }

    static class E1Or2 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            DSet d = new DSet(n);
            for (int i = 0; i < m; i++) {
                d.union(in.nextInt(), in.nextInt());
                int temp = in.nextInt();
            }
            out.println(d.getClusters());
        }

    }

    static class DSet {
        int parent[];
        int rank[];
        int size;

        DSet(int n) {
            parent = new int[n + 1];
            rank = new int[n + 1];
            size = n;
            for (int i = 0; i <= n; i++) {
                this.parent[i] = i;
            }
        }

        public int find(int i) {
            if (parent[i] == i) return i;
            else {
                int result = find(parent[i]);
                parent[i] = result;
                return result;
            }
        }

        public int getClusters() {
            return size;
        }

        public void union(int i, int j) {
            int ipar = this.find(i);
            int jpar = this.find(j);
            if (ipar == jpar) {
                return;
            }
            int irank = this.rank[ipar];
            int jrank = this.rank[jpar];
            if (irank < jrank) {
                this.parent[ipar] = jpar;
            } else if (jrank < irank) {
                this.parent[jpar] = ipar;
            } else {
                this.parent[ipar] = jpar;
                this.rank[jpar]++;
            }
            size--;
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 46652
#include<cstdio>
#include<algorithm>
#include<cctype>
#include<cstring>
#include<iostream>
#include<vector>

using namespace std;

#define bomb exit(1)
#define INF 1061109567
#define LINF 4557430888798830399ll
#define pprint(x) print(x),putchar(' ')
#define fprint(x) print(x),putchar('\n')
#define EE(x); struct edge { int nxt,to;ll w; }e[M << 1]; int head[N],ecnt = 1;\
	void add(int u,int v,ll w = 0) { e[++ecnt].w = w,e[ecnt].to = v,e[ecnt].nxt = head[u];head[u] = ecnt; }\
	void add_edge(int u,int v,ll w = 0) { add(u,v,w),add(v,u,w * x); }
#define ll long long
int mod = 1000000007;
ll Mod(ll x) { return x >= mod ? x - mod : x; }
#define eps 0.0000000001
#define sqr(x) ((x) * (x))
#define iter iterator
#define fi first
#define se second
//#define getchar() (SS == TT && (TT = (SS = BB) + fread(BB,1,1 << 15,stdin),TT == SS) ? EOF : *SS++)
//char BB[1 << 15],*SS = BB,*TT = BB;
ll read()
{
	ll x = 0;int f = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') f = -1;
	for(;isdigit(ch);ch = getchar()) x = x * 10 + (ch ^ 48);
	return x * f;
}
void print(ll x)
{
	if(x < 0) putchar('-'),x = -x;
	if(x > 9) print(x / 10);putchar(x % 10 + '0');
}

const int N = 2000010;
ll qpow(ll a,int b)
{
	ll ans = 1;
	while(b) { if(b & 1) ans = ans * a % mod;a = a * a % mod,b >>= 1; }
	return ans;
}
ll fac[N],ifac[N];
ll C(int n,int m) { return fac[n] * ifac[m] % mod * ifac[n - m] % mod; }
ll G(int x1,int y1,int x2,int y2) { return C(abs(x2 - x1) + abs(y2 - y1),abs(x2 - x1)); }
ll X[10],Y[10],ans;
ll calc(int x1,int y1,int x2,int y2,int f1,int f2)
{
	ll res = 0;
	for(int x = X[3];x <= X[4];x++)
	{
		res = (res + G(x1,y1,x,Y[4]) * G(x,Y[4] + 1,x2,y2) % mod * (x + Y[4] + 1)) % mod;
		res = Mod(res - G(x1,y1,x,Y[3] - 1) * G(x,Y[3],x2,y2) % mod * (x + Y[3]) % mod + mod);
	}
	for(int y = Y[3];y <= Y[4];y++)
	{
		res = (res + G(x1,y1,X[4],y) * G(X[4] + 1,y,x2,y2) % mod * (X[4] + y + 1)) % mod;
		res = Mod(res - G(x1,y1,X[3] - 1,y) * G(X[3],y,x2,y2) % mod * (X[3] + y) % mod + mod);
	}return res * f1 * f2;
}
struct point { ll x,y,f; }p[20];
int main()
{
	for(int i = 1;i <= 6;i++) X[i] = read();
	for(int i = 1;i <= 6;i++) Y[i] = read();
	fac[0] = 1;for(int i = 1;i < N;i++) fac[i] = fac[i - 1] * i % mod;
	ifac[N - 1] = qpow(fac[N - 1],mod - 2);for(int i = N - 1;i;i--) ifac[i - 1] = ifac[i] * i % mod;
	
	p[1] = {X[1] - 1,Y[1] - 1,1};p[4] = {X[2],Y[2],1};
	p[2] = {X[2],Y[1] - 1,-1};p[3] = {X[1] - 1,Y[2],-1};
	
	p[5] = {X[6] + 1,Y[6] + 1,1};p[8] = {X[5],Y[5],1};
	p[6] = {X[6] + 1,Y[5],-1},p[7] = {X[5],Y[6] + 1,-1};
	
	for(int i = 1;i <= 4;i++) for(int j = 5;j <= 8;j++)
		ans = (ans + calc(p[i].x,p[i].y,p[j].x,p[j].y,p[i].f,p[j].f) + mod) % mod;
	fprint(ans);
	return 0;
}

Measured memory_bytes: 31488
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct union_find {
    size_t parent;
    size_t size;
};

void uf_init(size_t n, struct union_find *uf)
{
    for (size_t i = 0; i < n; i++) {
        uf[i].parent = i;
        uf[i].size = 1;
    }
}

size_t uf_root(size_t a, struct union_find *uf)
{
    if (uf[a].parent == a)
        return a;
    return uf[a].parent = uf_root(uf[a].parent, uf);
}

size_t uf_size(size_t a, struct union_find *uf)
{
    return uf[uf_root(a, uf)].size;
}

void uf_unite(size_t a, size_t b, struct union_find *uf)
{
    a = uf_root(a, uf);
    b = uf_root(b, uf);
    if (a == b)
        return;
    if (uf_size(a, uf) > uf_size(b, uf)) {
        size_t tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    uf[a].parent = b;
    uf[b].size += uf[a].size;
}

bool uf_same(size_t a, size_t b, struct union_find *uf)
{
    return uf_root(a, uf) == uf_root(b, uf);
}

int main(void)
{
    intmax_t N, M, K;
    intmax_t A[(int)1e5 + 1], B[(int)1e5 + 1], C[(int)1e5 + 1], D[(int)1e5 + 1];

    scanf("%jd%jd%jd", &N, &M, &K);
    for (size_t i = 0; i < M; i++) {
        scanf("%jd%jd", &A[i], &B[i]);
    }
    for (size_t i = 0; i < K; i++) {
        scanf("%jd%jd", &C[i], &D[i]);
    }

    struct union_find uf[(int)1e5 + 1];
    uf_init(N + 1, uf);

    for (size_t i = 0; i < M; i++) {
        uf_unite(A[i], B[i], uf);
    }

    size_t friend[(int)1e5 + 1] = {};
    for (size_t i = 0; i < M; i++) {
        friend[A[i]]++;
        friend[B[i]]++;
    }

    size_t blocked[(int)1e5 + 1] = {};
    for (size_t i = 0; i < K; i++) {
        if (uf_same(C[i], D[i], uf)) {
            blocked[C[i]]++;
            blocked[D[i]]++;
        }
    }

    for (size_t i = 1; i <= N; i++) {
        printf("%jd", uf_size(i, uf) - friend[i] - blocked[i] - 1);
        if (i == N) {
            printf("\n");
        } else {
            printf(" ");
        }
    }

    return 0;
}


Measured memory_bytes: 7040
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	ll ans = 0;
	if (n == 1) {
		ans += a[0] / 2;
		cout << ans << endl;
		return 0;
	}
	rep(i, n - 1) {
		ll tmp = a[i] + a[i + 1];
		ans += tmp / 2;
		if (tmp % 2 == 0) {
			a[i + 1] = 0;
		}
		else {
			a[i + 1] = (a[i + 1] ? 1 : 0);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;
const int N = 1e5+100;
int a[N],pos[N],n;
set<int> st; ll ans;
int main(){
    scanf("%d",&n); ans=0;
    for(int i=1;i<=n;++i){
        scanf("%d",&a[i]);
        pos[a[i]]=i;
    }
    st.insert(0); st.insert(n+1);
    for(int i=n;i>=1;--i){
        auto rf=st.upper_bound(pos[i]);
        auto lf=prev(rf);
        if(*lf!=0){
            auto tp=prev(lf);
            ans+=(ll)i*(*lf-*tp)*(*rf-pos[i]);
        }
        if(*rf!=n+1){
            auto tp=next(rf);
            ans+=(ll)i*(*tp-*rf)*(pos[i]-*lf);
        }
        st.insert(pos[i]);
    }
    printf("%lld\n",ans);
}

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

int main() {
    string s;
    bool b[26] = {0};
    cin >> s;
    for(int i=0; i < s.length(); i++) {
        b[s[i]-97] = true;
    }
    for(int i=0; i<26; i++) {
        if(!b[i]) {
            cout << char('a'+i) << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}

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

const int MOD=1e9+7;
long long dp[100005][13];

int main() {
  string s;
  cin>>s;
  int n=s.size();
  dp[0][0]=1;

  for(int i=0;i<n;i++){
    for(int j=0;j<13;j++){
      if(s[i]=='?'){
        for(int k=0;k<10;k++){
          (dp[i+1][(j*10+k)%13]+=dp[i][j])%=MOD;
        }
      }
      else{
        int k=s[i]-'0';
        (dp[i+1][(j*10+k)%13]+=dp[i][j])%=MOD;
      }
    }
  }

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


Measured memory_bytes: 10624
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(b/a < c){
    cout << b/a << endl;
  }
  else {
    cout << c << endl;
  }
}


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

long long solve(const vector<int> &v, int N, int K) {
  vector<vector<long long>> dp(K, vector<long long>(N, INT_MIN));
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < K; ++j) {
      long long tmp = numeric_limits<long long>::min();
      for (int k = 0; k <= j; ++k) {
        tmp = max(tmp, (i-2-j+k >= 0 ? dp[k][i-2-j+k] : 0));
      }
      dp[j][i] = tmp + v[i];
    }
  }
  long long result = numeric_limits<long long>::min();
  for (int k = 0; k < K; ++k) {
    result = max(result, dp[K-1-k][N-1-k]);
  }
  return result;
}

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

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

  cout << solve(v, N, (N & 1) ? 3 : 2) << endl;

  return 0;
}

Measured memory_bytes: 10296
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
	int i, j;
	int N;

	cin >> N;
	double *p = new double[N + 1];

	for (i = 1; i <= N; i++)
		cin >> p[i];

	double **DP = new double*[N + 1];
	for (i = 0; i <= N; i++)
		DP[i] = new double[N + 1];



	for (i = 0; i <= N; i++) {
		for (j = 0; j <= N; j++) {
			DP[i][j] = 0.0;
		}
	}

	DP[0][0] = 1.0;

	for (i = 1; i <= N; i++) {
		DP[i][0] = DP[i - 1][0] * (1.0 - p[i]);
		for (j = 1; j <= i; j++) {
			DP[i][j] = DP[i - 1][j - 1] * p[i] + DP[i - 1][j] * (1.0 - p[i]);
		}
	}
	

	double ans = 0.0;

	for (i = N; i > N / 2; i--)
		ans += DP[N][i];

	cout << fixed << setprecision(11) << ans << endl;

	for (i = 0; i <= N; i++)
		delete[] DP[i];

	delete[] DP;
	delete[] p;


	return 0;
}

Measured memory_bytes: 70656
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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 (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N; ll A[301];
//---------------------------------------------------------------------------------------------------
ll dp[51][2][2];
ll opt(ll A0, ll A1, ll other) {
	rep(d, 0, 51) rep(debt, 0, 2) rep(prof, 0, 2) dp[d][debt][prof] = infl;
	dp[0][0][0] = 0;

	rep(d, 0, 50) rep(debt, 0, 2) rep(prof, 0, 2) {
		ll a0 = ((A0 & (1LL << d)) != 0);
		ll a1 = ((A1 & (1LL << d)) != 0);
		ll b = ((other & (1LL << d)) != 0);

		int debt2 = 0, prof2 = 0;
		if (debt) a0--;
		if (a0 < 0) a0 = 1, debt2 = 1;
		if (prof) a1++;
		if (a1 == 2) a1 = 0, prof2 = 1;

		// 何もしない
		if ((a0 ^ a1) == b) chmin(dp[d + 1][debt2][prof2], dp[d][debt][prof]);

		// 1つ渡す
		a0--;
		if (a0 < 0) debt2 = 1, a0 = 1;
		a1++;
		if (a1 == 2) prof2 = 1, a1 = 0;
		if ((a0 ^ a1) == b) chmin(dp[d + 1][debt2][prof2], dp[d][debt][prof] + (1LL << d));
	}

	ll ans = dp[50][0][0];
	if (ans == infl) ans = -1;
	if (ans == A0) ans = -1;
	return ans;
}
//---------------------------------------------------------------------------------------------------
ll naive(ll A0, ll A1, ll other) {	
	rep(move, 0, A0) if ((other ^ (A0 - move) ^ (A1 + move)) == 0) return move;
	return -1;
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) cin >> A[i];

	ll other = 0;
	rep(i, 2, N) other ^= A[i];

	//cout << naive(A[0], A[1], other) << endl;
	cout << opt(A[0], A[1], other) << endl;
}







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

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 (b<a) { a=b; return 1; } return 0; }

using ll = long long;
using P = pair<int,int>;
using graph = vector<vector<char>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

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

int main() {
    int H,W;
    cin>>H>>W;
    graph g(H,vector<char>(W));
    queue<P> bfs;
    vector<vector<int>> d(H,vector<int>(W,-1));
    rep(i,H){
        rep(j,W) {
            cin>>g[i][j];
            if(g[i][j]=='#'){
                bfs.push(make_pair(i,j));
                d[i][j]=0;
            }
        }
    }
    while(!bfs.empty()){
        P p = bfs.front();
        bfs.pop();
        int x = p.first;
        int y = p.second;
        rep(i,4){
            int nx = x + dx[i];
            int ny = y + dy[i];
            if(nx<0||nx>=H||ny<0||ny>=W) continue;
            if(d[nx][ny]!=-1) continue;
            d[nx][ny] = d[x][y]+1;
            bfs.push(make_pair(nx,ny));
        }
    }
    int ans = 0;
    rep(i,H){
        rep(j,W) chmax(ans,d[i][j]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 16212
import Control.Monad
import Control.Applicative
import Data.List

toTuple :: [Int] -> (Int, Int)
toTuple [x,l] = (x+l, x-l)

solve :: [(Int,Int)] -> Int -> Int
solve [] _ = 0
solve ((l,s):xs) cur 
  | cur <= s = 1 + solve xs l
  | otherwise = solve xs cur 

main = do
  n <- readLn :: IO Int
  arms <- replicateM n (toTuple . map read . words <$> getLine) :: IO [(Int, Int)]
  print $ solve (sort arms) (negate $ 10^10)

Measured memory_bytes: 126204
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b;
    cin >> a >> b;
    if  (a < b) {
        cout << "a < b" << endl;
    }
    else if  (a > b) {
        cout << "a > b" << endl;
    }
    else if  (a == b) {
        cout << "a == b" << endl;
    }
}



Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

//const int INF = 1e8;
const int N = 105;

char c[N][N];
long long dist[4][N][N];
long long h, w, l;
long long to, loop;

struct Point{ int x, y; };
int dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

void dfs(Point p, int dir, long long dis){
    //cout << endl;
    if(dist[dir][p.y][p.x] != -1){
        //show(p.y)
        //show(p.x)
        //show(dis)
        //show(dist[p.y][p.x])
        to = dist[dir][p.y][p.x];
        loop = dis - dist[dir][p.y][p.x];
        return;
    }
    dist[dir][p.y][p.x] = dis;

    //rep(i,h){ rep(j,w){ cout << dist[dir][i][j] << ' '; } cout << endl; }

    int ny = p.y + dy[dir];
    int nx = p.x + dx[dir];
    while( (ny < 0 || ny >= h || nx < 0 || nx >= w) || c[ny][nx] == '#'){
        dir = (dir + 1) % 4;
        ny = p.y + dy[dir];
        nx = p.x + dx[dir];
    }


    dfs(Point{nx,ny}, dir, dis + 1);
}

void dfs_(Point p, int dir, long long dis){
    //show(dir) cout << p.y << ' ' << p.x << endl;
    if(dis == 0){
        char d[5] = {"ESWN"};
        cout << p.y + 1 << ' ' << p.x + 1 << ' ' << d[dir] << endl;
        return;
    }

    int ny = p.y + dy[dir];
    int nx = p.x + dx[dir];
    while( (ny < 0 || ny >= h || nx < 0 || nx >= w) || c[ny][nx] == '#'){
        dir = (dir + 1) % 4;
        ny = p.y + dy[dir];
        nx = p.x + dx[dir];
    }
    dfs_(Point{nx,ny}, dir, dis - 1);
}

int main(){
    while(cin >> h >> w >> l,h){
        memset(dist, -1, sizeof(dist));
        int dir = -1;
        Point p = Point{-1,-1};
        rep(i,h){
            rep(j,w){
                cin >> c[i][j];
                if(c[i][j] == 'N') dir = 3;
                else if(c[i][j] == 'E') dir = 0;
                else if(c[i][j] == 'S') dir = 1;
                else if(c[i][j] == 'W') dir = 2;
                if(dir != -1 && p.x == -1){
                    p = Point{j,i};
                }
            }
        }
        dfs(p,dir,0);
        //show(to)
        //show(loop)
        if(l >= to){
            l -= to;
            l %= loop;
            l += to;
        }
        dfs_(p,dir,l);
    }
}

Measured memory_bytes: 3524
N = int(input())

Restaurants = [input().split() for i in range(N)]

for ResNum in range(0, N + 1):
    if ResNum <= N - 1:
        Restaurants[ResNum][1] = int(Restaurants[ResNum][1])

    if ResNum > 0:
        Restaurants[ResNum - 1].append(ResNum)

Restaurants.sort(key=lambda x: (x[0], -x[1]))

#print(Restaurants)

for i in range(N):
    print(Restaurants[i][2])

Measured memory_bytes: 3064
n,k=map(int,input().split())
#n>=kの場合は最初のサイコロで勝ちになる可能性がある
if n>=k:
    ans=(n-k+1)/n#xはサイコロだけで勝ちになる確率
    for i in range(1,k):
        j=0
        while True:
            i*=2
            j+=1
            if i>=k:
                break
        ans+=(1/n)*(0.5)**j
else:
    ans=0
    for i in range(1,n+1):
        j=0
        while True:
            i*=2
            j+=1
            if i>=k:
                break
        ans+=(1/n)*(0.5)**j
print(ans)

Measured memory_bytes: 65164
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
//#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    double n; cin >> n;
    if(floor(floor(n/1.08) * 1.08) == n) cout << floor(n/1.08);
    else if(floor(ceil(n/1.08) * 1.08) == n) cout << ceil(n/1.08);
    else cout << ":(";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll = long long;
#define REP(i,n) for(ll i=0;i<ll(n);i++)
#define FOR(i,a,b) for(ll i=a;i<=ll(b);i++)
#define ALL(x) x.begin(),x.end()

#define INF (ll)1e9 //10^9:∞
#define LLINF (ll)1e12
#define MOD (ll)(1e9+7) //10^9+7:合同式の法
#define PI 3.141592653589
#define PB push_back
#define F first
#define S second
#define __MAGIC__ ios::sync_with_stdio(false);cin.tie(nullptr);

#define YESNO(T) if(T){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define yesno(T) if(T){cout<<"yes"<<endl;}else{cout<<"no"<<endl;}
#define YesNo(T) if(T){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}

#define Graph vector<vector<int>>
#define PII pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>
#define VPII vector<pair<int,int>>

#define DDD fixed<<setprecision(10)
#define endl "\n"

using namespace std;
/*..................DEFINE GLOBAL VARIABLES...................*/


/*.....................DEFINE FUNCTIONS ......................*/



/*.........................kemkemG0...........................*/
signed main() {
	__MAGIC__


	int N;
	cin >> N;

	vector<vector<pair<int, int>>> vp(N);  //vp[i]={(F1,S1),(F2,S2),(F3,S3)}:=人iの証言で

	REP(i, N) {
		int A;
		cin >> A;
		REP(j, A) {

			PII p;
			cin >> p.F >> p.S;

			--p.F;

			vp[i].push_back(p);
		}
	}


	int ans = 0;

	REP(bit, 1 << N) {
		vector<int> testify(N, -1); //未なら-1　正直なら1 不親切なら0

		bool ok = true;

		REP(i, N) {

			if ( (bit >> i) & 1) { //もしiの人が親切ならは
				for (auto pp : vp[i]) {

					if (testify[pp.F] == -1)testify[pp.F] = pp.S;//まだ未証言なら証言を更新
					else if (testify[pp.F] != -1 && testify[pp.F] != pp.S)ok = false; //すでに証言されてて食い違ってたらダメ

					if ( ((bit >> pp.F) & 1) != pp.S) ok = false; //今仮定してる設定と記録が食い違っててもダメ
				}
			}

		}

		if (!ok)continue;

		else ans = max(ans, __builtin_popcount(bit) );
	}

	cout << ans << endl;







	return 0;
}


Measured memory_bytes: 3640
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        String n = sc.next();
        
        String ans = "";
        
        for(int i=0;i<3;i++){
            if(n.charAt(i)=='1')
                ans+="9";
            else
                ans+="1";
        }
        
        System.out.println(ans);
    }
}
/*
119
*/

Measured memory_bytes: 22740
def main():
    from collections import deque

    H, W, K = map(int, input().split())

    move = [(1, 0), (-1, 0), (0, 1), (0, -1)]

    G = [list(input()) for _ in range(H)]
    check = [[-1] * (W) for _ in range(H)]

    que = deque()

    flag = False
    for h in range(H):
        for w in range(W):
            if G[h][w] == 'S':
                que.append((h, w))
                flag = True
                break
        if flag:
            break

    x_min = h
    x_max = h

    y_min = w
    y_max = w

    check[h][w] = 0
    while que:
        tmp = que.popleft()
        
        x = tmp[0]
        y = tmp[1]
        
        now_ = check[x][y]
        if now_ == K:
            continue

        for dx, dy in move:
            nx = x + dx
            ny = y + dy
            if not (0 <= nx < H and 0 <= ny < W):
                continue
            if G[nx][ny] == '#':
                continue
            if check[nx][ny] == -1:
                check[nx][ny] = now_ + 1
                que.append((nx, ny))
                
                x_min = min(x_min, nx)
                x_max = max(x_max, nx)

                y_min = min(y_min, ny)
                y_max = max(y_max, ny)

    ans = 10 ** 18
    ans = min(ans, (x_min + K - 1) // K + 1)
    ans = min(ans, (H - x_max - 1 + K - 1) // K + 1)
    ans = min(ans, (y_min + K - 1) // K + 1)
    ans = min(ans, (W - y_max - 1 + K - 1) // K + 1)

    print (ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 31368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define mod (ll)(1e9+7)
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<(x)<<endl
#define ps(x) cout<<(x);
#define pfix(d,x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
#define fi first
#define se second
ll a[100001],b[100001],c[100001],d,n,m,x,y,z,k,h,w,sum,mi,ma,ans,s,t,l,r,res,tmp,itr,p,q;
bool flag;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int dx8[8]={1,1,0,-1,-1,-1,0,1},dy8[8]={0,1,1,1,0,-1,-1,-1};
char cha;
string st;
typedef map<int, int> imap;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<pair<ll,ll> > VP;


int main(){
    cin>>n;
    rep(i,n)cin>>a[i];
    rep(i,n)b[i]=2*a[i];
    rep(i,n)d(b[i])
    rep(i,n){
        if(i%2==1)sum-=b[i];
        else sum+=b[i];
    }
    d(sum)
    tmp=sum/2;
    ps(tmp);
    rep(i,n-1){
        ps(" ");
        tmp=b[i]-tmp;
        ps(tmp);
    }
    p("");
    return 0;
}


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

int main() {
    int X; cin >> X;
    
    int Y = X % 100;
    int cnt = 0;
    for(int i=5; i>0; --i) {
        cnt += Y / i;
        Y %= i;
    }

    cout << (X >= 100 * cnt) << endl;
}

Measured memory_bytes: 256
def solve():

  n,m = (int(i) for i in input().split())
  ans = 0
  left = 0
  right = 10**9
  for i in range(m):
    l,r = (int(i) for i in input().split())
    left = max(left,l)
    right = min(right,r)
  if right <left :
    print(0)
  else:
   print(1+right-left)
    
solve()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
void solve()
{
int n;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++)
    cin>>arr[i];
  long long ans=0;
  int maxx=0;
  for(int i=0;i<n;i++)
  { 
    maxx=max(maxx,arr[i]);
    ans+=maxx-arr[i];
  }
  cout<<ans<<endl;
  
  
}
int main()
{
solve();
}


Measured memory_bytes: 4428
N = int(input())
L = list(map(int,input().split()))


S = [0,L[0]]
for i in range(1,N):
  temp = S[i]+L[i]
  S.append(temp)
dic ={}
for i in range(len(S)):
  if S[i] not in dic:
    dic[S[i]] = 1
  else:
    dic[S[i]] += 1
ans = 0    
for t in dic.values():
  ans += t*(t-1)//2
print(ans)

Measured memory_bytes: 41348
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main()
    {
        var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();

        if (input.Sum() >= 10)
        {
            Console.WriteLine("error");
        }
        else
        {
            Console.WriteLine(input.Sum());
        }
    }
}

Measured memory_bytes: 13268
n=int(input())
a=[0]+list(map(int,input().split()))
su=0
su+=abs(a[1])
for i in range(2,n+1):
    su+=abs(a[i]-a[i-1])
su+=abs(a[n])
a.append(0)
#print(su)
for i in range(1,n+1):
    x,y=a[i-1],a[i+1]
    if min(x,y)<=a[i] and a[i]<=max(x,y):
        print(su)
    else:
        d1=abs(a[i-1]-a[i])
        d2=abs(a[i]-a[i+1])
        print(su-2*min(d1,d2))



Measured memory_bytes: 14172
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int l[300000];
int r[300000];

int main()
{
	int N, ans = 300000;
	string S;

	cin >> N >> S;

	rep(i, N) {
		if (i == 0) l[i] = 0;
		else {
			if (S[i - 1] == 'W') l[i] = l[i - 1] + 1;
			else l[i] = l[i - 1];
		}
	}

	rrep(i, N) {
		if (i == N - 1) r[i] = 0;
		else {
			if (S[i + 1] == 'E') r[i] = r[i + 1] + 1;
			else r[i] = r[i + 1];
		}
	}

	rep(i, N) {
		ans = min(ans, l[i] + r[i]);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define ll long long int
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define INF 0x3f3f3f3f

using namespace std;
using namespace __gnu_pbds;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef tree<pair<int,int>,null_type, less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>   ordered_set;
const int N=1e6+10, mod=1e9+7;
int n,k,a[510];

bool isPoss(int m){
	vector<int> v;  int i,nn;
	for(i=0;i<n;i++){
		v.pb(a[i]%m);
	}
	sort(v.begin(),v.end());
	int pos=0,neg=0;  nn=v.size();

	for(i=0;i<nn;i++)pos+=v[i];
	for(i=nn-1;i>=0;i--){
		if( pos-v[i] >= neg+(m-v[i]) ){
			pos-=v[i];
			neg+=(m-v[i]);
			if( pos==neg &&  pos<=k) return true;
		}
	}
	
	return false;
}

int main(){
	ios_base::sync_with_stdio(0);	cin.tie(0);
	int i,sum=0;
	cin>>n>>k;
	for(i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	
	int res=1;
	for(i=1;i*i<=sum;i++){
		if(sum%i==0){
			if( isPoss(i) ){
				res=max(res,i);
			}
			if( isPoss(sum/i) ){
				res=max(res,sum/i);
			}
		}
	}
	cout<<res;
}
// check for any potential overflow before submitting



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

int n, M[MAX][MAX];
int color[MAX], d[MAX], f[MAX], tt;

void dfs_visit(int u){
    int v;
    color[u] = GRAY;
    d[u] = ++tt;
    for(v = 0; v < n; v++){
        if(M[u][v] == 0){
            continue;
        }
        if(color[v] == WHITE){
            dfs_visit(v);
        }
    }
    color[u] = BLACK;
    f[u] = ++tt;
}

void dfs(){
    int u;
    for(u = 0; u < n; u++) color[u] = WHITE;
    tt = 0;

    for(u = 0; u < n; u++){
        if(color[u] == WHITE) {
            dfs_visit(u);
        }
    }

    for(u = 0; u < n; u++){
        cout << u + 1 << " " << d[u] << " " << f[u] << endl;
    }
}


int main(){
    int i, j, u, k, v;
    cin >> n;
    for(i = 0; i < n; i++){
        cin >> u >> k;
        for(j = 0; j < k; j++){
            cin >> v;
            M[u-1][v-1] = 1; 
        }
    }

    dfs();
    return 0;

}


Measured memory_bytes: 3132
#include <iostream>
#include <cstdio>
#include <vector>

#define GET_STDIN fgets(buf, 1024, stdin)
#define FOR(i, f, n, b) for(int i = (f); i < (n); i += (b))

typedef long long ll;

using namespace std;

int main() {
  char s[1024];
  char buf[1024];

  GET_STDIN;
  sscanf(buf, "%s", s);

  string str(s);

  ll len = str.size();

  ll before = 0;
  ll sum = 0;

  FOR(i, 0, 1<<len-1, 1) {
    before = -1;
    FOR(j, 0, len-1, 1) {
      if (i & (1 << j)) {
        sum += stol(str.substr(before + 1, j - before));
        before = j;
      }
    }
    sum += stol(str.substr(before + 1, len - before));
  }

  cout << sum << endl;
}


Measured memory_bytes: 256
pub 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()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn cnt_minus(i: i64, pv: &Vec<i64>, mv: &Vec<i64>) -> u64 {
    let mut ret = 0;

    let mut k = 0;

    for j in 0..mv.len() {
        while k < pv.len() {
            if mv[j] * pv[k] <= i {
                break;
            }
            k += 1;
        }
        ret += (pv.len() - k) as u64;
    }

    ret
}

fn sub(i: i64, v: &Vec<i64>) -> u64 {
    let mut ret = 0;

    let mut k = v.len() - 1;

    for j in 0..v.len() {
        while j < k {
            if v[j] * v[k] <= i {
                break;
            }
            k -= 1;
        }
        if j == k {
            break;
        }
        ret += (k - j) as u64;
    }

    ret
}

fn cnt_plus(i: i64, pv: &Vec<i64>, mv: &Vec<i64>) -> u64 {
    let mut pv2: Vec<i64> = mv.iter().map(|x| -x).collect();
    pv2.sort();

    sub(i, pv) + sub(i, &pv2)
}

fn main() {
    let nk: Vec<u64> = read_vec();
    let n = nk[0];
    let k = nk[1];

    let a: Vec<i64> = read_vec();

    let mut mv: Vec<i64> = a.iter().filter(|x| **x < 0).cloned().collect();
    let mut pv: Vec<i64> = a.iter().filter(|x| **x > 0).cloned().collect();

    mv.sort();
    pv.sort();

    let m = a
        .iter()
        .fold(0, |sum, x| if *x < 0 { sum + 1 } else { sum });

    let z = a
        .iter()
        .fold(0, |sum, x| if *x == 0 { sum + 1 } else { sum });

    let p = a
        .iter()
        .fold(0, |sum, x| if *x > 0 { sum + 1 } else { sum });

    let mut ans = 0;

    if k <= p * m {
        //minus
        let mut left: i64 = -1000000000000000001;
        let mut right: i64 = 0;
        while left + 1 < right {
            let mid = (left + right) / 2;
            let cnt = cnt_minus(mid, &pv, &mv);
            if k <= cnt {
                right = mid;
            } else {
                left = mid;
            }
        }
        ans = right;
    } else if !(k <= p * m + p * z + m * z + z * (z - 1) / 2) {
        //plus
        let mut left: i64 = 0;
        let mut right: i64 = 1000000000000000001;
        while left + 1 < right {
            let mid = (left + right) / 2;
            let cnt = cnt_plus(mid, &pv, &mv) + p * m + p * z + m * z + z * (z - 1) / 2;
            if k <= cnt {
                right = mid;
            } else {
                left = mid;
            }
        }
        ans = right;
    }

    println!("{}", ans);
}


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

int main(){
    long long N, K, Q;
    cin >> N >> K >> Q;
    vector<long long> A(Q);
    map<long long, long long> B;
    for(long long i = 0; i < N; i++)B[i] = 0;
    for(long long i = 0; i < Q; i++){
        cin >> A[i];
        B[A[i] - 1]++;
    }
    
    for(long long i = 0; i < N; i++){
        long long  P = K - Q + B[i];
        if(P > 0)cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

Measured memory_bytes: 9088
#include<cstdio>
#include<algorithm>
#include<cctype>
using namespace std;
#define G getchar()
int read()
{
	int x=0; char ch=G;
	for (;!isdigit(ch);ch=G);
	for (;isdigit(ch);ch=G) x=(x<<3)+(x<<1)+(ch^48);
	return x;
}
#undef G

int n,m,K; char s[1000010],t[1000010];
int a[2000010],b[2000010],c[2000010],d[2000010];
struct Rec{
	int msk,pos;
}; Rec stk[2000010],bin[2000010]; int stktop,bintop;
int main()
{
	scanf("%d%d%d%s%s",&n,&m,&K,s+1,t+1);
	for (int i=1;i<=n;i++) a[n-i+1]=s[i]&1;
	for (int i=1;i<=m;i++) b[m-i+1]=t[i]&1;
	for (int i=max(n,m);i>0;i--)
		if (a[i]&&b[i]){
			bintop=0;
			int j=i+1,msk=3,tot=K-1;
			while (stktop){
				if (msk==3){  //11
					if (j+tot<stk[stktop].pos){
						j+=tot; tot=0;
						c[j]=d[j]=1; j++; msk=0;
						break;
					}
					tot-=stk[stktop].pos-j; j=stk[stktop].pos;
					if (stk[stktop].msk==1){
						bin[++bintop]=(Rec){2,stk[stktop].pos};
						msk=1; j++; stktop--;
					}
					else{
						bin[++bintop]=(Rec){1,stk[stktop].pos};
						msk=2; j++; stktop--;
					}
					continue;
				}
				if (msk==2){  //01
					if (j!=stk[stktop].pos){
						bin[++bintop]=(Rec){2,j}; j++; msk=0;
						break;
					}
					if (stk[stktop].msk==1){
						if (tot) tot--,msk=3,j++;
						else{
							c[j]=d[j]=1,msk=0,j++; break;
						}
					}
					else j++,msk=2;
					stktop--;
					continue;
				}
				if (msk==1){  //10
					if (j!=stk[stktop].pos){
						bin[++bintop]=(Rec){1,j}; j++; msk=0;
						break;
					}
					if (stk[stktop].msk==1) j++,msk=1;
					else{
						if (tot) tot--,msk=3,j++;
						else{
							c[j]=d[j]=1,msk=0;j++; break;
						}
					}
					stktop--;
					continue;
				}
//				assert(0);
			}
			if (msk==3) j+=tot,tot=0,c[j]=d[j]=1,msk=0,j++;
			else if (msk==2){
				bin[++bintop]=(Rec){2,j}; j++; msk=0;
			}
			else if (msk==1){
				bin[++bintop]=(Rec){1,j}; j++; msk=0;
			}
			for (int j=bintop;j;j--) stk[++stktop]=bin[j];
		}
		else if (a[i]) stk[++stktop]=(Rec){1,i};
		else if (b[i]) stk[++stktop]=(Rec){2,i};
	for (int i=1;i<=stktop;i++) if (stk[i].msk==1) c[stk[i].pos]=1; else d[stk[i].pos]=1;
	int topa=n+K,topb=m+K;
	while (!c[topa]) topa--; while (topa) putchar(c[topa--]^48); putchar('\n');
	while (!d[topb]) topb--; while (topb) putchar(d[topb--]^48); putchar('\n');
	return 0;
}

Measured memory_bytes: 37760
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int dataSet, x, y, w, h, catNumber;
	static int[][] point;
	public static void main(String[] args) {
		dataSet = sc.nextInt();
		for(int i = 0; i < dataSet; i++){
			read();
			System.out.println(solve());
		}
	}
	static void read(){
		x = sc.nextInt();
		y = sc.nextInt();
		w = sc.nextInt();
		h = sc.nextInt();
		catNumber = sc.nextInt();
		point = new int[2][catNumber];
		for(int i = 0; i < catNumber; i++){
			point[0][i] = sc.nextInt();
			point[1][i] = sc.nextInt();
		}
	}
	static int solve(){
		int count = 0;
		for(int i = 0; i < catNumber; i++){
			if(point[0][i] >= x && point[0][i] <= x+w && 
					point[1][i] >= y && point[1][i] <= y+h)
				count++;
		}
		return count;
	}

}

Measured memory_bytes: 12000
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

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

    
    int x[m];
    rep(i, m) cin >> x[i];
    if (n >= m){
        cout << 0 << endl;
        return 0;
    }
    sort(x, x + m);
    int dis[m-1];
    int sm = 0;
    rep(i, m - 1) {dis[i] = x[i+1] - x[i]; sm += dis[i];}
    sort(dis, dis + m - 1, greater<int>());
    rep(i, n - 1) sm -= dis[i];


    cout << sm << endl;

}


Measured memory_bytes: 1024
/* Arthor : Ender_zzm
E-mail zzm_ender_wiggin@outlook.com
Blog oi.ender-zzm.pro
*/
#include <bits/stdc++.h>
using namespace std;

template<class T>
inline void read(T &a) {
    register T x = 0, flag = 1;
    register char ch;
    while (!isdigit(ch = getchar())) if (ch == '-') flag = -1;
    while (x = x * 10 + (ch & 15), isdigit(ch = getchar()));
    a = x * flag;
}

template <class T>
inline void write(T x) {
    if (x < 0)
        putchar('-'), x = -x;
    if(x >= 10) write(x / 10); 
    putchar(x % 10 + '0');
}

template<class T> inline bool Chkmax(T& x, const T& y) { return x < y ? x = y, true : false; }
template<class T> inline bool Chkmin(T& x, const T& y) { return x > y ? x = y, true : false; }

#define For(i, a, b) for (int i = (a); i <= (b); i++) 
#define Rep(i, a, b) for (int i = (a); i >= (b); i--) 
#define For_edge(x) for (int i = head[x]; i; i = net[i])
#define mem0(a) memset(a, 0, sizeof a)

int n;
int main() {
	cin >> n;
	int x = n;
	while(x) {
		int tmp = x % 10;
		if (tmp == 7) {
			puts("Yes");
			return 0;
		}
		x /= 10;
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3636
/////////////////////////////
//* Code By: SANSKAR SETH *//
/////////////////////////////


/*----------HEADER FILES AND TEMPLATES----------*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define pob pop_back
#define pf pop_front()
#define puf push_front()
#define mp make_pair
#define loop(i,a,b) for(int i=a ; i<b ; ++i)
#define rloop(i,a,b) for(int i=a ; i>=b ; --i)
#define ip(a) int a; cin>>a
#define ip2(a,b) int a,b; cin>>a>>b
#define ip3(a,b,c) int a,b,c; cin>>a>>b>>c
#define ipv(v,n) vi v(n); loop(i,0,n) cin>>v[i]
#define pv(v) loop(i,0,v.size()) cout<<v[i]<<" "
#define ips(s) string s; cin>>s
#define F first
#define S second
#define si(x) scanf("%lld",&x)
#define ss(s) scanf("%s",s)
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define coutfl(l,p) fixed << setprecision(p) << l

typedef pair<int, int> pii;
typedef unordered_set<int> usi;
typedef set<int> si;
typedef map<int, int>   mii;
typedef map<char, int>  mci;
typedef vector<int>    vi;
typedef vector<char>   vc;
typedef vector<pii>    vpii;
typedef vector<vi>     vvi;

const int mod = 1000000007;
const int N = 5e5;

/*----------SOLUTION----------*/

void solve()
{
	ip(x);
	if (x == 1) cout << 0 << endl;
	else cout << 1 << endl;

}

/*----------MAIN FUNCTION----------*/
int32_t main()
{
	fastIO;


	/*----MAIN PART----*/

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

Measured memory_bytes: 3604