akhauriyash/Code-Regression huggingface dataset:
def main():
    K, N = map(int, input().split())
    AN = list(map(int, input().split()))

    max_diff = 0
    for i in range(N - 1):
        max_diff = max(max_diff, AN[i + 1] - AN[i])
    max_diff = max(max_diff, AN[0] + K - AN[-1])

    print(K - max_diff)


main()


Measured memory_bytes: 26100
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
ll fac(ll x){if(x==0) return 1;  return x*fac(x-1);}
//cout << fixed << setprecision(10);

int main(){
  ll n,t=1; cin>>n;
 vector<ll>v(n);
  rep(i,n){
  cin>>v[i];
    if(v[i]==t){
    t++;
    }
  }
  if(t==1)cout<<-1<<endl;
  else cout<<n-(t-1)<<endl;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/22  Problem: ABC 055 A / Link: http://abc055.contest.atcoder.jp/tasks/abc055_a  ----- */


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

	LL N; cin >> N;
	LL ans = 800 * N - 200 * (N / 15);
	
	
	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
// *st.find_by_order(index), 0-based
// order_of_key(e)

const int MAX = 1000000;
int block; 

struct query { 
	int L, R, index, result; 
}; 

void eval(vector<int> &a, vector<query> &q) {
	int n=a.size(), m=q.size();
	block = (int)sqrt(n); 
	sort(q.begin(), q.end(), [&](const query &x, const query &y) {
		if (x.L / block != y.L / block)
			return x.L / block < y.L / block;
		return x.R < y.R;
	});
	int currL = 0, currR = 0; 
	int curr_Diff_elements = 0; 
	int freq[MAX] = { 0 }; 
	for (int i = 0; i < m; i++) { 
		int L = q[i].L, R = q[i].R; 
		while (currL < L) { 
			freq[a[currL]]--; 
			if (freq[a[currL]] == 0)  
				curr_Diff_elements--; 
			currL++; 
		} 
		while (currL > L) { 
			freq[a[currL - 1]]++; 
			if (freq[a[currL - 1]] == 1)  
				curr_Diff_elements++; 
			currL--; 
		} 
		while (currR <= R) { 
			freq[a[currR]]++; 
			if (freq[a[currR]] == 1)  
				curr_Diff_elements++; 
			currR++; 
		} 
		while (currR > R + 1) { 
			freq[a[currR - 1]]--; 
			if (freq[a[currR - 1]] == 0)  
				curr_Diff_elements--; 
			currR--; 
		} 
		q[i].result = curr_Diff_elements; 
	} 
} 

void print(vector<query> &q) { 
	int m=q.size();
	sort(q.begin(), q.end(), [&](const query &x, const query &y) { 
		return x.index < y.index;
	}); 
	for (int i = 0; i < m; i++)
		cout<<q[i].result<<"\n";
} 

// Driver program 
int main() { 
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N,Q; cin>>N>>Q;
	vector<int> a(N);
	for (int i=0; i<N; i++)
		cin>>a[i];
	vector<query> q(Q);
	for (int i=0; i<Q; i++) {
		int l,r; cin>>l>>r; l--; r--;
		q[i]={l,r,i,0};
	}
	eval(a,q); 
	print(q); 
	return 0;
} 

Measured memory_bytes: 17400
/*
  AOJ 0587
  Title:tunnel
  @kankichi573
*/
#include <stdio.h>
// #include <stdlib.h>
// #include <string.h>
// #include <math.h>
// #include <float.h>
// #include <stdlib.h>
int n,m;
int in_,out_,sum;
main()
{
        int i,zflag,max_;

        zflag=0;
        scanf("%d %d",&n,&m);
        sum=m;
        for(i=0;i<n;i++)
        {
                scanf("%d %d",&in_,&out_);
                sum += in_;
                sum -= out_;
                if(sum < 0)
                        zflag=1;
                if(max_ <sum)
                        max_=sum;
                //printf("%d:%d (%d %d)\n",i,sum,in_,out_);
        }
        if(zflag)
                printf("0\n");
        else
                printf("%d\n",max_);

  return(0);
}

Measured memory_bytes: 596
/*
 *  JOI / Prelim 0642
 *    Sugoroku: find a maxium length of the series made only by one
 */

#include <stdio.h>

int main(void)
{
    int max = 0;
    int tmp_max = 0;
    int n;

    scanf("%d", &n);

    int i;
    for (i = 0; i < n; i++) {
        int status;
        scanf("%d", &status);
        if (status == 1) {
            tmp_max++;
        } else {
            max = max < tmp_max ? tmp_max : max;
            tmp_max = 0;
        }
    }
    max = max < tmp_max ? tmp_max : max;

    printf("%d\n", max + 1);

    return 0;
}



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

const int N = 1e5;

vector<int> xs[N+1];

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

	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
		xs[a].push_back(b);
	}

	multiset<int> ans;
	for (int i = m; i > 0; i--) {
		sort(xs[i].begin(), xs[i].end());
		int cnt = m-i+1;
		while (!xs[i].empty() && ans.size() < cnt) {
			ans.insert(xs[i].back());
			xs[i].pop_back();
		}
		while (!xs[i].empty() && !ans.empty() && xs[i].back() > *ans.begin()) {
			ans.erase(ans.begin());
			ans.insert(xs[i].back());
			xs[i].pop_back();
		}
	}
	int tot = 0;
	for (int x : ans) {
		tot += x;
	}
	cout << tot << endl;
	return 0;
}



Measured memory_bytes: 10112
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    string s;
    cin >> n >> s;
    vi se(n+1, 0), sw(n+1, 0);
    rep(i, n) {
        se[i+1] = se[i] + (s[i] == 'E');
        sw[i+1] = sw[i] + (s[i] == 'W');
    }

    int ans = 1001001001;
    rep(i, n) {
        int now = sw[i] + (se[n] - se[i+1]); 
        chmin(ans, now);
    }
    cout << ans << endl;
}

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

#define ll long long
#define pb push_back
#define debug1(x) cerr << #x << " = " << x << '\n';
#define debug2(x, y) cerr << #x << " = " << x << "   " << #y << " = " << y << "\n";
#define _ ios_base::sync_with_stdio(0);cin.tie(NULL);

void solve() {
    int n;
    cin >> n;
    set<string> s;
    for(int i = 0; i<n; i++) {
        string x;
        cin >> x;
        s.insert(x);
    }
    cout << int(s.size()) << ' ';
}

int main() {_
    int t = 1;
    //cin >> t;
    // Please remember to uncomment for taking test cases
    for(int i = 1; i<=t; i++) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 19232
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.TreeSet;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int q = Integer.parseInt(sa[1]);

		sa = br.readLine().split(" ");
		int[] pre = new int[n + 1];
		int[] last = new int[n + 1];
		for (int i = 0; i < n; i++) {
			int c = Integer.parseInt(sa[i]);
			if (last[c] > 0) {
				pre[i + 1] = last[c];
			}
			last[c] = i + 1;
		}

		TreeSet<Obj> set = new TreeSet<>((o1, o2) -> {
			if (o1.r != o2.r) {
				return o1.r - o2.r;
			}
			return o1.i - o2.i;
		});
		Obj[] arr = new Obj[q];
		for (int i = 0; i < q; i++) {
			sa = br.readLine().split(" ");
			Obj o = new Obj();
			o.i = i;
			o.l = Integer.parseInt(sa[0]);
			o.r = Integer.parseInt(sa[1]);
			set.add(o);
			arr[i] = o;
		}
		br.close();

		BIT bit = new BIT(n);
		int j = 1;
		for (Obj o : set) {
			while (j <= o.r) {
				bit.add(j, 1);
				if (pre[j] > 0) {
					bit.add(pre[j], -1);
				}
				j++;
			}
			o.ans = bit.sum(o.r) - bit.sum(o.l - 1);
		}

		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < q; i++) {
			pw.println(arr[i].ans);
		}
		pw.flush();
	}

	static class Obj {
		int i, l, r;
		long ans;
	}

	static class BIT {
		int n;
		long[] arr;

		public BIT(int n) {
			this.n = n;
			arr = new long[n + 1];
		}

		void add(int idx, long val) {
			for (int i = idx; i <= n; i += i & -i) {
				arr[i] += val;
			}
		}

		long sum(int idx) {
			long sum = 0;
			for (int i = idx; i > 0; i -= i & -i) {
				sum += arr[i];
			}
			return sum;
		}
	}
}


Measured memory_bytes: 102676
open System

// prelude
let readStr () = stdin.ReadLine()

let read f () = readStr() |> f
let reads f () = readStr().Split() |> Array.map f

let pair = function
| [|a; b|] -> (a, b)
| _ -> failwith "owatta"

let triple = function
| [|a; b; c|] -> (a, b, c)
| _ -> failwith "owatta"

let readPair f g () =
  let (a,b) = readStr().Split() |> pair
  (f a, g b)

let readTriple f g h () =
  let (a,b,c) = readStr().Split() |> triple
  (f a, g b, h c)

let inc n = n + 1
let dec n = n - 1

let inline flip f a b = f b a
let rec fix f = fun x -> (f (fix f)) x

module Option =
  let getOr defaultValue = function
  | Some x -> x
  | None -> defaultValue

module Array =
  let modify (arr: _ []) i f =
    arr.[i] <- f arr.[i]

module Array2D =
  let modify (arr: _ [,]) i j f =
    arr.[i, j] <- f arr.[i, j]

// start
let N = read int64 ()

let rec primes n a =
  if N < a*a then
    if n=1L then [] else [1]
  elif n % a <> 0L then primes n (a+1L)
  else
    let rec inner n acc =
      if n%a<>0L then (n, acc)
      else inner (n/a) (acc+1)
    let (n', c) = inner n 0
    c::(primes n' (a+1L))

let rec cnt n c = if n>=c then 1+(cnt (n-c) (c+1)) else 0

primes N 2L
|> List.fold (
  fun st x -> st + (cnt x 1)
) 0
|> printfn "%d"

Measured memory_bytes: 30080
#include<bits/stdc++.h>
const int N=1e5+7;
using namespace std;
int n,m,tot,head[N],size[N];
vector<int> G[N];
inline int read(){
	int f=1,x=0;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
	return f*x;
}
inline void addedge(int u,int v){
	G[u].push_back(v);G[v].push_back(u);
}
int cnt=0;
inline int dfs(int u,int f){
	size[u]=1;int cur=0;
	for(int i=0;i<G[u].size();i++){
		int v=G[u][i];if(v==f)continue;
		cur+=dfs(v,u);size[u]+=size[v];
	}
	if(cur>=2){puts("First");exit(0);}
	if(cur)return 0;
	else return 1;
}
int main(){
	n=read();
	for(int i=1;i<n;i++){
		int u=read(),v=read();
		addedge(u,v);
	}
	int ans=dfs(1,0);int cnt=0;
	if(cnt)puts("First");
	if(ans)puts("First");else puts("Second");
}

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

double punch(double x, double y) {
	return (x + y) / 2;
}

int main() {
	int N;
	cin >> N;
	vector<double> v(N);
	for (int i = 0; i < N; ++i) cin >> v.at(i);

	sort(v.begin(), v.end());

	double sum = punch(v.at(0), v.at(1));

	if (N == 2) cout << sum << endl;
	else {
		for (int i = 2; i < N; ++i) sum = punch(sum, v.at(i));
		cout << sum << endl;
	}

}

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

using namespace std;

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

  int N, T;
  cin >> N >> T;

  vector<int> t(N+1);
  for(int i=0; i<N; i++){
	cin >> t[i];
  }
  t[N] = t[N-1] + T;

  int sum = 0;
  for(int i=0; i<N; i++){
	sum += (t[i+1] - t[i] <= T) ? t[i+1] - t[i] : T;
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int d,g;
int p[10],c[10];
int dp[10][1001];
int main(){
	string str;
	cin>>str;
	if(str[0]!='A') {
		cout<<"WA"<<endl;
		return 0;
	}
	int cnt=0;
	for(int i=2;i<str.length()-1;i++) if(str[i]=='C') cnt++;
	if(cnt!=1){
		cout<<"WA"<<endl;
		return 0;
	}
	cnt=0;
	for(int i=0;i<str.length();i++) if(str[i]>='A'&&str[i]<='Z') cnt++;
	if (cnt!=2){
		cout<<"WA"<<endl;
		return 0;
	}
	cout<<"AC"<<endl;
	return 0;
}

Measured memory_bytes: 256
import bisect

n,q = map(int,input().split())
A = list(map(int,input().split()))

dic = {}

w = [A[0]]
for i in range(1,n):
    w.append(w[-1]+A[i])
w1 = [A[0],0]
w2 = [0,A[1]]
for i in range(2,n):
    if i%2 == 0:
        w1.append(w1[-2]+A[i])
        w2.append(0)
    else:
        w2.append(w2[-2]+A[i])
        w1.append(0)

def solve(x):
    if x in dic:
        print(dic[x])
        return 
    if x >= A[-1]:
        count = max(w1[-1],w2[-1])
        dic[x] = count
        print(count)
        return
    l = 0
    r = 10**10
    while r > l+1:
        m = (r+l)//2
        li = bisect.bisect_left(A,x-m)
        ri = bisect.bisect_right(A,x+m)
        if n-ri == ri-li:
            count = w[-1]-w[ri-1]
            li -= 1
            if li>= 0:
                if li%2 == 0:
                    count += w1[li]
                else:
                    count += w2[li]
            dic[x] = count
            print(count)
            return 0
        if n-ri == ri-li+1:
            count = w[-1]-w[ri-1]
            li -= 2
            if li>= 0:
                if li%2 == 0:
                    count += w1[li]
                else:
                    count += w2[li]
            dic[x] = count
            print(count)
            return 0
        if A[ri-1] == x+m:
            ri2 = ri-1
            if n-ri2 == ri2-li:
                count = w[-1]-w[ri2-1]
                li -= 1
                if li>= 0:
                    if li%2 == 0:
                        count += w1[li]
                    else:
                        count += w2[li]
                dic[x] = count
                print(count)
                return 0
            elif n-ri2 == ri2-li+1:
                count = w[-1]-w[ri2-1]
                li -= 2
                if li>= 0:
                    if li%2 == 0:
                        count += w1[li]
                    else:
                        count += w2[li]
                dic[x] = count
                print(count)
                return 0
        if 2*ri > n+li:
            r = m
        else:
            l = m
    
    count = max(w1[-1],w2[-1])
    dic[x] = count
    print(count)
    return

for _ in range(q):
    x = int(input())
    solve(x)



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

class Stack
{

  private:
    int *stack;
    int max_size;
    int stack_pointer;

  public:
    Stack(int n = 1000)
        : stack_pointer(0),
          max_size(n)
    {
        stack = (int *)malloc(sizeof(int) * max_size);
    }

    ~Stack()
    {
        free(stack);
    }

    void push(int in)
    {
        if (stack_pointer < max_size - 1)
        {
            stack_pointer++;
            stack[stack_pointer] = in;
        }
        else
        {
            std::cout << "Stack is full\n";
        }
    }

    int pop()
    {
        if (stack_pointer != 0)
        {
            int out = stack[stack_pointer];
            stack_pointer--;
            return out;
        }
        else
        {
            std::cout << "No value in stack\n";
        }
    }

    bool isFull()
    {
        if (stack_pointer == max_size - 1)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    bool isEmpty()
    {
        if (stack_pointer == 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    void initialize()
    {
        stack_pointer = 0;
    }
    
        int num()
    {
        return stack_pointer;
    }
};

int main()
{

    Stack s;
    std::string input;

    int a, b;

    while (std::cin >> input)
    {
        if (input == "+")
        {
            b = s.pop();
            a = s.pop();
            s.push(a + b);
        }
        else if (input == "-")
        {
            b = s.pop();
            a = s.pop();
            s.push(a - b);
        }
        else if (input == "*")
        {
            b = s.pop();
            a = s.pop();
            s.push(a * b);
        }
        else
        {
            s.push(atoi(input.c_str()));
        }
    }

    
    std::cout << s.pop() << "\n";
}


Measured memory_bytes: 3152
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const range = (start: number, stop: number) =>
  [...Array(stop - start + 1)].map((_, i) => start + i);

const main = (input: string[][]) => {
  const [A, B, K] = input[0].map(Number);

  if (A + K - 1 >= B - K + 1) {
    return range(A, B).join("\n");
  }

  return [...range(A, A + K - 1), ...range(B - K + 1, B)].join("\n");
};

console.log(main(read()));


Measured memory_bytes: 29844
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;

public class Main {
  public static void main(String args[] ) throws IOException {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

      String readLine = br.readLine();
      while( readLine != null ) {
        readLine = readLine.trim();
        String[] readLineArray = readLine.split(" ");

        int h = Integer.parseInt(readLineArray[0]);
        int w = Integer.parseInt(readLineArray[1]);

        if ( h == 0 && w == 0) {
          break;
        }

        for (int i = 0 ; i < h ; i++) {
          for (int k = 0 ; k < w ; k++) {
            System.out.print("#");
          }
          System.out.print("\n");
        }
        System.out.print("\n");
        readLine = br.readLine();
      }
    br.close();
  }
}

Measured memory_bytes: 34256
#include<cstdio>
#include<iostream>
using namespace std;
const long long maxv=1e18;
const long long md=1e9+7;
struct node{
	long long x,y;
}b[105][210];
int num[210];
long long f[105];
int ttp;
int m;
int main(){
//	freopen("F.in","r",stdin);
	f[0]=1,f[1]=2;
	for(int i=2;i<=100;i++)
	{
		f[i]=f[i-1]+f[i-2];
		if(f[i]>2*maxv){
			ttp=i;
			break;
		}
	}
	b[1][1]=(node){1,2};
	b[1][2]=(node){1,3};
	num[1]=2;
	long long x,y;
	for(int i=2;i<ttp;i++){
		for(int j=1;j<=num[i-1];j++)
		{
			x=b[i-1][j].x,y=b[i-1][j].y;
			while(x+y<=f[i+1]){
				x=x+y;
				b[i][++num[i]]=(node){y,x};
			}
		}
	}
	
	int M;
	scanf("%d",&M);
	long long s,t;
	int n;
	long long ans;
	for(m=1;m<=M;m++){
		ans=0;
		scanf("%lld%lld",&s,&t);
		if(s==1&&t==1){
			printf("1 1\n");
			continue;
		}
		if(s>t) swap(s,t);
		for(int i=1;i<=ttp;i++){
			if(f[i-1]<=s&&f[i]<=t);
			else{
				n=i-1;
				break;
			}
		}
		if(n==1){
			if(s>1&&t>1){
				printf("1 4\n");
			}
			else
				printf("1 %lld\n",(s+t-1)%md);
			continue;
		}
		for(int i=1;i<=num[n-1];i++){
			x=b[n-1][i].x;
			y=b[n-1][i].y;
			if(x<=s&&y<=s)
			{
				ans=(ans+(t-x)/y)%md;
				ans=(ans+(s-x)/y)%md;
			}
		}
		printf("%d %lld\n",n,ans);
	}
	return 0;
}


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

typedef long long LL;
string s;

LL fact(int num, LL score, LL prev){
    int number = s[num] - '0';
    if(num == s.size() - 1){
       // cout << score + prev * 10 + number << endl;
        return score + prev * 10 + number;
    }
    return fact(num + 1, score + prev * 10 + number, 0)
     + fact(num + 1, score, prev * 10 + number);
}

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

    cin >> s;

    cout << fact(0, 0, 0) << endl;

	return 0;
}

Measured memory_bytes: 256
from fractions import gcd
a, b, c, d = map(int, input().split())
def quo_items(x, num1, num2):
    num1_quo = x // num1
    num2_quo = x // num2
    num12_quo = x // int((num1 / gcd(num1, num2) * num2))
    items = x - num1_quo - num2_quo + num12_quo
    return items

print(quo_items(b, c, d) - quo_items(a - 1, c, d))

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

using namespace std;
using ll = long long;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI=3.14159265358979323846;

typedef priority_queue<int, vector<int>, greater<int>> priority_queue_asc;

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

    list<int> b;
    for (int i = 0; i < N; i++) {
        int bi;
        cin >> bi;
        b.push_back(bi);
    }

    list<int> ans;

    for (int i = 0; i < N; i++) {
        list<int>::reverse_iterator itr = b.rbegin();
        for (int j = b.size(); itr != b.rend(); --j, ++itr) {
            // cout << "* " << (*itr) << endl;
            if (*itr == j) {
                break;
            }
        }
        // cout << "---" << endl;

        if (itr == b.rend()) {
            cout << -1 << endl;
            return 0;
        }

        int bj = *itr;
        b.erase((++itr).base());
        // cout << ": " << bj << endl;
        ans.push_front(bj);
    }

    for (const auto& e : ans) {
        cout << e << endl;
    }

    return 0;
}


Measured memory_bytes: 3176
n = int(input())
a = list(map(int, input().split()))
flag = 1
count = 0
while flag:
    flag = 0
    for i in range(n-1,0,-1):
        if a[i]<a[i-1]:
            a[i],a[i-1] = a[i-1],a[i]
            flag = 1
            count+=1
print(*a)
print(count)



Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    long long int R,G,B,N;
    long long int tmp=0;
    cin >> R >> B >> G >> N;
    FOR(i,0,N+1){
        FOR(j,0,N+1){
            if((N-R*i-G*j)>=0 && (N-R*i-G*j)%B==0)
                {
                tmp++;
                }
        }
    }
    cout << tmp;
    return 0;
}

Measured memory_bytes: 256
K, N = map(int, input().split())
A = list(map(int, input().split()))

import numpy as np

a = np.array(A)
D = np.diff(a)
D = np.append(D, a[0] + K - a[-1])
ind = np.argmax(D)

if N == 2:
    print(a[ind+1]-a[ind])
elif ind == len(a)-1:
    ans =  -a[0] + a[ind]
    print(ans)
else:
    ans = K - (a[ind+1]-a[ind])
    print(ans)


Measured memory_bytes: 39404
#include <bits/stdc++.h>
using namespace std;
int n,q;
int a[200010];
int main(){
	cin>>n;
	long long sum=0;
	for (int i=1;i<=n;i++){
		int x;
		cin>>x;
		a[x]++;
		sum+=x;
	}
	cin>>q;
	while (q--){
		int x,y;
		cin>>x>>y;
		sum-=1ll*x*a[x];
		sum+=1ll*a[x]*y;
		a[y]+=a[x];
		a[x]=0;
		cout<<sum<<endl;
	}
	return 0;
}



Measured memory_bytes: 4008
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVSORT(v) sort(v.rbegin(), v.rend());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int gcd(int a,int b){return b?gcd(b,a%b):a;}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

ll modpow(ll n,ll k){
  if(k == 1){
    return n;
  }else if(k == 0){
    return 1;
  }else if(k%2==0){
    ll memo = modpow(n,k/2)%MOD;
    return memo*memo%MOD;
  }else{
    return n * modpow(n,k-1)%MOD;
  }
}

vector<ll> v;
  vector<LP> sub;
void solve(){

  VSORT(v);
  int i = 0;
  while(i<v.size()){
    if(v[i]==0){
      LP p;
      p.first = v[v.size()-1];
      p.second = 0;
      sub.pb(p);
      remove(v,i);
    }else{
      i++;
    }
  }
  while(v.size()>2){
    if(v[1]<0){
      LP p;
      p.first = v[v.size()-1];
      p.second = v[1];
      sub.pb(p);
      v[v.size()-1] -= v[1];
      remove(v,1);
    }else if(v[v.size()-2]>0){
      LP p;
      p.first = v[0];
      p.second = v[v.size()-2];
      sub.pb(p);
      v[0] -= v[v.size() -2];
      remove(v,v.size()-2);
    }
  }
  LP p;
  p.first = v[v.size()-1];
  p.second = v[0];
  sub.pb(p);
  ll ans = p.first - p.second;
  cout<<ans<<endl;
  REP(j,sub.size()){
    cout<<sub[j].first<<" "<<sub[j].second<<endl;
  }

}

int main(){

  int n;cin>>n;


  ll ans;
  
  REP(i,n){
    ll t;cin>>t;
    v.pb(t);
  }

  VSORT(v);
  if(v[0]<0&&v[v.size()-1]>0){
    solve();
    return 0;
  }



  if(v[0]==v[v.size()-1]){

    if(n==2){
      cout<<0<<endl;
      cout<<v[0]<<" "<<v[0]<<endl;
      return 0;
    }else if(n==3){
      cout<<abs(v[0])<<endl;
      cout<<v[0]<<" "<<v[0]<<endl;
      if(v[0]>=0){
        cout<<v[0]<<" "<<0<<endl;
      }else{
        cout<<0<<" "<<v[0]<<endl;
      }
      return 0;
    }else{
      LP lp;
      lp.first = v[0];
      lp.second = v[0];
      sub.pb(lp);
      lp.first = 0;
      sub.pb(lp);
      remove(v,0);
      remove(v,0);
      v[0] *= -1;
      solve();
    }
  }else{
    if(v[0]>=0){
      LP lp;
      lp.first = v[0];
      lp.second = v[n-1];
      sub.pb(lp);
      v[0] = v[0] - v[n-1];
      remove(v,n-1);
      solve();
    }else{
      
      LP lp;
      lp.first = v[n-1];
      lp.second = v[0];
      sub.pb(lp);
      v[n-1] = v[n-1] - v[0];
      remove(v,0);
      solve();
    }
  }





 

  return 0;
}

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

#define fastio {\
    ios::sync_with_stdio(0);\
    cin.tie(0);\
}

#define file {\
    freopen("io\\in.txt", "r", stdin);\
    freopen("io\\out.txt", "w", stdout);\
    freopen("io\\err.txt", "w", stderr);\
}

#ifdef LOCAL
#define debug(args...) {\
    string _s(#args);\
    replace(_s.begin(), _s.end(), ',', ' ');\
    stringstream _ss(_s);\
    istream_iterator<string> _it(_ss);\
    debug1(_it, args);\
}

#pragma GCC diagnostic ignored "-Wunused-parameter"
void debug1(istream_iterator<string> it) {
    cerr << endl;
}
#pragma GCC diagnostic pop

template<class T, class... Args>
void debug1(istream_iterator<string> it, T a, Args... args) {
    cerr << '>' << *it << " = " << a << "; ";
    debug1(++it, args...);
}
#else
#define debug(args...)
#define cerr if (false) cerr
#endif

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define rep(i, n)   for (int i = 0; i < n; i++)
#define dotc()      int tcs; if (cin >> tcs) rep(tc, tcs)
#define sz(x)       (int)x.size()
#define eb          emplace_back
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define all(x)      x.begin(), x.end()
#define rall(x)     x.rbegin(), x.rend()
#define fi          first
#define se          second

const int inf(0x3fffffff);
const int mod(1000000007);
const double pi(acos(-1.0));

signed main() {
    fastio;
#ifdef LOCAL
    file;
#endif

    int n;
    cin >> n;

    ll sum = 0;
    rep(i, n + 1) {
        if (i % 3 && i % 5) sum += i;
    }

    cout << sum;

    return 0;
}


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

int main(){
    int h, w;
    while(cin >> h >> w, h+w){
        map<char, pair<int,int>> m;
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                char c; cin >> c;
                if(c == '_')    continue;
                m[c] = {i,j};
            }
        }
        string s;
        cin >> s;
        int i = 0, j = 0, ans = s.length();
        for(char c : s) ans += abs(m[c].first-i)+abs(m[c].second-j), i = m[c].first, j = m[c].second;
        cout << ans << endl;
    }
    return 0;
}


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

int main() {
  ll a,b;cin>>a>>b;
  for(int i=1;i<=a;i++){
    if(b*i%a==0){
      cout<<b*i<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3540
import itertools
import numpy as np

X = int(input())
maxs = int(X**(1/5))

l = np.arange(-126, 127)

comb = np.array(list(itertools.combinations_with_replacement(l, 2)))

sum1 = comb[:, 0]**5 - comb[:, 1]**5
sum2 = comb[:, 1]**5 - comb[:, 0]**5

if len(np.where(sum1==X)[0]) != 0:
    result1 = np.where(sum1==X)[0][0]
    print(comb[result1][0], comb[result1][1])
else:
    result2 = np.where(sum2==X)[0][0]
    print(comb[result2][1], comb[result2][0])

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

int main(){
    ll h, k,ans=0;
    cin>>h>>k;
    for(ll i=0; i<k; i++)
    {
        ll tmp;
        cin>>tmp;
        ans+=tmp;
    }
    if(ans>=h){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}



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

int main() {
  int n;
  cin >> n;
  vector<tuple<int, int, int>> vt(n);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    int c = a + b;
    vt.at(i) = make_tuple(c, a, b);
  }
  sort(rbegin(vt), rend(vt));
  ll taka = 0, aoki = 0;
  for (int i = 0; i < n; i++) {
    if (i % 2 == 0) {
      taka += get<1>(vt.at(i));
    } else {
      aoki += get<2>(vt.at(i));
    }
  }
  cout << taka - aoki << endl;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
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; }

int D;
vector<int> c(26+1);
vector<vector<int>> s;

int compute_score(vector<int> t) {
    vector<vector<int>> last(D+1,vector<int>(26+1,0));
    int ans = 0;
    for(int d = 1; d <= D; d++) {
        last[d][t[d]] = d;
        ans += s[d][t[d]];
        for(int i = 1; i <= 26; i++) {
            if(i == t[d]) continue;
            last[d][i] = last[d-1][i];
            ans -= c[i]*(d-last[d][i]);
        }
    }
    return 0;
}

vector<int> greedy() {
    vector<int> t(D+1);
    vector<vector<int>> last(D+1,vector<int>(26+1,0));
    for(int d = 1; d <= D; d++) {
        int best_i = 0;
        int best_score_diff = -(INT32_MAX>>2);
        for(int i = 1; i <= 26; i++) {
            int score_diff = s[d][i] - c[i]*(d-last[d][i]);
            if(score_diff >= best_score_diff) {
                best_i = i;
                best_score_diff = score_diff;
            }
        }
        for(int i = 1; i <= 26; i++) {
            if(i == best_i) {
                last[d][i] = d;
                t[d] = i;
            } else {
                last[d][i] = last[d-1][i];
            }
        }
    }
    return t;
}

int main(){
    ios::sync_with_stdio(false);
    cin >> D;
    s.assign(D+1,vector<int>(26+1,0));
    for(int i = 1; i <= 26; i++) cin >> c[i];
    for(int d = 1; d <= D; d++) for(int i = 1; i <= 26; i++) cin >> s[d][i];

    vector<int> t = greedy();
    for(int d = 1; d <= D; d++) cout << t[d] << endl;
}


Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct edge
{
	int u , v;
	ll w;
}E[400010];
int len , head[200010];
void add(int u , int v , ll w)
{
	E[len++] = {u , v , w};
	
}
bool cmp(edge a , edge b)
{
	return a.w < b.w;
}
int n , a , b , q;
int fa[200010];
ll d[200010];
int get(int x)
{
	return (fa[x] == x) ? x : (fa[x] = get(fa[x]));
}
ll kruskal()
{
	ll res = 0;
	int cnt = n;
	sort(E , E + len , cmp);
	for (int i = 0; i < len; i++)
	{
		int u = E[i].u , v = E[i].v;
		ll w = E[i].w;
		//cout << u << " " << v << " " << w << endl;
		u = get(u) , v = get(v);
		if (u != v)
		{
			fa[v] = u;
			res += w;
			cnt--;
		}
		if (cnt == 1)
		{
			return res;
		}
	}
	return res;
}
int main()
{
	memset(d , 0x7f , sizeof(d));
	ll c;
	scanf("%d%d" , &n , &q);
	for (int i = 0; i < n; i++)
	{
		fa[i] = i;
	}
	for (int i = 1; i <= q; i++)
	{
		scanf("%d%d%lld" , &a , &b , &c);
		add(a , b , c);
		d[a] = min(d[a] , c + 1);
		d[b] = min(d[b] , c + 2);
		//cout << a << "  " << b <<" " << d[a] << " " << d[b] << endl;
	}
	for (int i = 0; i < n; i++)
	{
		d[(i + 1) % n] = min(d[(i + 1) % n] , d[i] + 2);
	}
	for (int i = 0; i < n; i++)
	{
		d[(i + 1) % n] = min(d[(i + 1) % n] , d[i] + 2);
	}
	for (int i = 0; i < n; i++)
	{
		add(i , (i + 1) % n , d[i]);
	}
	printf("%lld\n" , kruskal());
}

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

using namespace std;

const int nax = 1e5+5;

vector<int> edges[nax];

int indegree[nax];
int dist[nax];
bool visited[nax];

void dfs(int a)
{
    visited[a] = true;
    for(int b:edges[a])
    {
        dist[b] = max(dist[b], 1+dist[a]);
        --indegree[b];
        if(!indegree[b])
        {
            dfs(b);
        }
    }
}

int main()
{
    int n, m; 
    cin>>n>>m;
    // for(int i=0; i<nax; i++) indegree[i] = 0;
    while(m--)
    {
        int x, y;
        cin>>x>>y;
        edges[x].push_back(y);
        ++indegree[y];
    }

    // for(int i=0; i<nax; i++) {visited[i]=false; dist[i]=0;}

    for(int i=1; i<=n; ++i)
    {
        if(!visited[i] && indegree[i]==0) dfs(i);
    }

    int ans=0;
    for(int i=0; i<=n; i++)
    {
        ans = max(ans, dist[i]);
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 9728
def main():
    from collections import deque
    N = int(input())
    B = deque(list(map(int, input().split())))
    result = deque([])
    for i in range(N):
        flag = False
        for j in range(len(B), 0, -1):
            b = B[j-1]
            if j == b:
                del B[j-1]
                result.append(b)
                flag = True
                break
        if not flag:
            print(-1)
            return
    for j in range(len(result)-1, -1, -1):
        print(result[j])
main()

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> P;
LL mod = 1e9+7;

int main(){
    string L;
    cin >> L;
    vector<LL>  p(L.size()+1), p3(L.size()+1);
    LL d = 1, d3 = 1;
    for(int i = 0;i <= L.size();i++){
        d %= mod;
        d3 %= mod;
        p[i] = d;
        p3[i] = d3;
        d *= 2;
        d3 *= 3;
    }
    LL ans = 0;
    LL lc = 0;
    for(int i = 0;i < L.size();i++){
        if(L[i] == '1'){
            ans += p[lc]*p3[L.size()-i-1];
            ans %= mod;
            lc++;
        }
    }
    ans += p[lc];
    ans %= mod;
    cout << ans << endl;
}

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

int main(void){
  string s;
  int i, sum = 700;

  cin >> s;

  for(i = 0; s[i] != '\0'; i ++)
    if(s[i] == 'o') sum += 100;
  
  cout << sum << endl;

  return 0;
}

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

int main()
{
  map<string, int> Map;
  string str;
  string max, freq;

  while (cin >> str){
    Map[str]++;
    if (Map[max] < Map[str]){
      max = str;
    }
    if (freq.size() < str.size()){
      freq = str;
    }
  }

  cout << max << " " << freq << '\n';

  return (0);
}

Measured memory_bytes: 1188
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto itr : x) { debug(itr); }

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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  if ((b - a) % 2 == 0) 
    cout << "Alice" << endl;
  else
    cout << "Borys" << endl;
}


Measured memory_bytes: 256
import os
import math

def main():
    lst = [0,0,0,0,0,0]
    for i in range(0, int(input())):
        temp = float(input())
        if temp < 165:
            lst[0] += 1
        elif temp < 170:
            lst[1] += 1
        elif temp < 175:
            lst[2] += 1
        elif temp < 180:
            lst[3] += 1
        elif temp < 185:
            lst[4] += 1
        else:
            lst[5] += 1
    for i in range(0,6):
        print("{}:".format(i+1), end="")
        for j in range(0,lst[i]):
            print("*", end = "")
        print()

main()

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

ll dp[101][100001] = {0};

int main(){
    int N, W, w[100], v[100];
    cin >> N >> W;
    rep(i, N) cin >> w[i] >> v[i];

    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= W; j++) {
            if (j - w[i] >= 0) { //i番目の品物を選ぶ場合
                dp[i+1][j] = max(dp[i+1][j], dp[i][j-w[i]] + v[i]);
            }

            //i番目の品物を選ばない場合
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
        }
    }

    cout << dp[N][W] << endl;

    return 0;
}

Measured memory_bytes: 78336
#include <bits/stdc++.h>
 
using namespace std;
#define int long long
#define mod 1000000007
int dp[2097152][21];
int mat[21][21];
int solve(int msk, int i, int n)
{
    if(i == n)
        return 1;
    if(dp[msk][i] != -1)
        return dp[msk][i];
    int ans = 0;
    for(int j = 0;j < n;j++)
    {
        if(mat[i][j] == 1)
        {
            if(msk&(1 << j))
                continue;
            ans = (ans + solve((msk|(1 << j)), i+1, n))%mod;
        }
    }
    return (dp[msk][i] = ans);
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int i, j;
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
            cin >> mat[i][j];
    for(i=0;i<2097152;i++)
        for(j=0;j<21;j++)
            dp[i][j] = -1;
    cout << solve(0, 0, n);
}

Measured memory_bytes: 347688
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 60;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;
  rep(i, 26) {
    rep(j, 15) {
      ll x = 4 * i + 7 * j;
      if (x == n) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
#pragma comment(linker, "/STACK:16000000")
//#define map gp_hash_table
#define PI 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
using namespace std;
namespace Geometry{
	struct point{
		double x;double y;
		void print(){
			printf("Point:x:%.8lf,y:%.8lf",x,y);
		}
	};
	struct line{
		double x;double c;
		void print(){
			printf("Line:x:%.8lf,c:%.8lf\n",x,c);
		}
	};
	line make_line(point a,point b){
		double x=(a.x-b.x)/(a.y-b.y);
		double c=a.y-(a.x)*(x);
		return (line){x,c};
	}
}
#define int long long
using namespace Geometry;
//using namespace __gnu_pbds;
const int inf=0x3f3f3f3f;
const long long inf2=0x3f3f3f3f3f3f3f3f;
const double eps=1e-6;
const int mod=1000000007;
const int MAX_N=1e6;
struct BIT{
	int bit[MAX_N+1],BITN=1e6;
	//sum a[1,i]
	void init1(){
		for(int i=0;i<MAX_N;i++)bit[i]=0;
	}
	void init(vector<int> v){
		for(int i=0;i<v.size();i++)add(i+1,v[i]);
	}
	int sum(int i){
		int s=0;
		while(i>0){
			s+=bit[i];
			i=(i)&(i-1);
		}
		return s;
	}
	//a[i]+=x
	void add(int i,int x){
		while(i<=BITN){
			bit[i]+=x;
			i+=(i)&(-i);
		}
	}
}bit;
int n;
int a[111111];
int cmp[111111];
int pre[111111];
int ll[111111],rr[111111];
int mergesort(int l,int r){
	long long sum=0;
	sum+=mergesort(l,(l+r)/2);
	sum+=mergesort((l+r)/2+1,r);
	for(int i=l;i<=(l+r)/2;i++)ll[i]=a[i];
	for(int i=(l+r)/2+1;i<=r;i++)rr[i]=a[i];
	int lpos=l,rpos=(l+r)/2+1;
	int pos=l;
	while(lpos!=(l+r)/2&&rpos!=r){
		if(ll[lpos]<rr[rpos]){
			a[pos++]=ll[lpos++];
			sum+=(l+r)/2-l+1;
		}
		else{
			a[pos++]=rr[rpos++];
		}
	}
	if(lpos!=(l+r)/2){
		while(pos!=r+1){
			a[pos++]=ll[lpos++];
		}
	}else{
		while(pos!=r+1){
			a[pos++]=rr[rpos++];
		}
	}
	return sum;
}
bool check(int x){
	bit.init1();
	int sum=0;
	memset(pre,0,sizeof(pre));
	for(int i=1;i<=n;i++)pre[i]=pre[i-1]+(a[i]>=x?1:-1);
	for(int i=0;i<=n;i++){
		sum+=bit.sum(pre[i]+5e5);
		bit.add(pre[i]+5e5,1);
	}
	return sum>=1ll*(n+1)*n/4;
}
signed main(){
	scanf("%d",&n);
	if(n==1){
		int x;
		cin>>x;
		cout<<x<<endl;
		return 0;
	}
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	int l=-1,r=2e9;
	while(r-l>1){
		int mid=l+r>>1;
		bool data=check(mid);
		if(data)l=mid;
		else r=mid;
	}
	cout<<l<<endl;
	return 0;
}

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

#define inf 0x3f3f3f3f3f3f3f3f
#define pi acos(-1)
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(),a.end()

int32_t main(){
	
	int n,W;
	scanf("%d%d",&n,&W);
	vector<pair<long long,long long>> A(n);
	for(auto &a:A) scanf("%lld%lld",&a.fi,&a.se);
	vector<long long> dp(W+1);
	for(int id = 0;id<n;id++){
		for(long long peso = W-A[id].fi;peso>=0;peso--)
			dp[peso+A[id].fi] = max(dp[peso+A[id].fi],dp[peso]+A[id].se);
	}
	long long ans =0;
	for(int i=0;i<=W;i++)
		ans = max(ans,dp[i]);
	cout << ans << '\n';
#ifdef LOCAL_DEFINE
	cerr << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}

Measured memory_bytes: 1024
# import bisect
# from collections import Counter, defaultdict, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    s = input()
    for i in range(len(s)-1):
        if s[i:i+2] == "AC":
            print('Yes')
            sys.exit()
    print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 38256
import java.util.Scanner;

public class Main 
{

	public static void main(String[] args) 
	{
		Scanner sc  = new Scanner(System.in);
		
		String s = sc.next();
		
		if(s.charAt(2) == s.charAt(3) && s.charAt(4) == s.charAt(5))
		{
			System.out.println("Yes");
		}
		else
		{
			System.out.println("No");
		}

	}

}


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

int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    bool flag = false;
    rep(i,n){
        cin >> a[i];
        if(a[i]==0) flag = true;
    }
    ll ans=1;
    rep(i,n){
        if(flag) {
            ans = 0;
            break;
        }
        if(a[i]>M/ans){
            ans = -1;
            break;
        }
        ans *= a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3996
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class AtCoderC
{
    private static int n;
    private static int m;
    private static int broken = -1;
    private static long[] patterns;
    private static long mod = 1000000007;
    static void Main()
    {
        {
            string line = Console.ReadLine();
            var words = line.Split(' ');
            n = int.Parse(words[0]);
            m = int.Parse(words[1]);
        }

        patterns = new long[n + 1];
        patterns[0] = 1;

        if (m > 0)
        {
            broken = int.Parse(Console.ReadLine());
            m--;
        }

        int index = 1;
        while (index <= n)
        {
            long pattern = 0;
            if (index == 1)
            {
                pattern = patterns[0];
            }
            else
            {
                pattern = (patterns[index - 1] + patterns[index - 2]) % mod;
            }
            if (index == broken)
            {
                pattern = 0;
                if (m > 0)
                {
                    broken = int.Parse(Console.ReadLine());
                    m--;
                }
            }
            patterns[index] = pattern;
            index++;
        }
        long answer = patterns[n];
        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 14036
let NM = readLine()!.split(separator: " ").compactMap { Int($0) }
let m = NM[1]

let ABM = (0..<m).map { _ in readLine()!.split(separator: " ").compactMap { Int($0) } }

var arrayDic = [Int: Int]()
var circle = [[Int]]()
for i in 0..<m {
    let ai = ABM[i][0]
    let bi = ABM[i][1]
    if arrayDic[ai] == nil && arrayDic[bi] == nil {
        circle.append([ai, bi])
        arrayDic[ai] = circle.count-1
        arrayDic[bi] = circle.count-1
    } else if let index = arrayDic[ai], arrayDic[bi] == nil {
        circle[index].append(bi)
        arrayDic[bi] = index
    } else if let index = arrayDic[bi], arrayDic[ai] == nil {
        circle[index].append(ai)
        arrayDic[ai] = index
    } else if let aIndex = arrayDic[ai], let bIndex = arrayDic[bi] {
        if aIndex == bIndex { continue }

        let maxIndex = circle[aIndex].count > circle[bIndex].count ? aIndex : bIndex
        let minIndex = circle[aIndex].count > circle[bIndex].count ? bIndex : aIndex

        for element in circle[minIndex] {
            arrayDic[element] = maxIndex
        }
        circle[maxIndex].append(contentsOf: circle[minIndex])
    }
}

let result = circle.reduce(0, { max($0, $1.count) })
print(result > 0 ? result : 1)


Measured memory_bytes: 43264
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pb push_back
#define INF 0x3f3f3f3f
using namespace std;
string s;
int ans;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>s;
	int l=0,r=s.size()-1;
	while (l<r)
	{
		if (s[l]!=s[r]) ++ans;
		++l,--r;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
  int N,K,count=0;
  scanf("%d%d", &N,&K);
  int h[N];
  for(int i=0; i<N; i++){
    scanf("%d", &h[i]);
    if(h[i]>=K){
      count++;
    }
  }
  printf("%d\n",count);
  
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll N=1e5+5;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n;cin>>n;
    ll a[n];for(ll i=0;i<n;i++)cin>>a[i];
    ll ans=0,prv=0;
    for(ll i=0;i<n;i++){
        ans = ans + min(prv,a[i]);
        a[i]-=min(prv,a[i]);
        ans+=a[i]/2;
        prv=a[i]%2;
    }
    cout<<ans;
}



Measured memory_bytes: 1024