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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    ll N, K;
    cin >> N >> K;
    cout << 1 + (ll)ceil((double)(N - K) / (K - 1)) << endl;
    return 0;
}


Measured memory_bytes: 256
#ifndef DEBUG
#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (Int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP(i, n) for (Int i = 0, i##_len = (n); i <= i##_len; ++i)
#define rep3(i, l, r) for (Int i = l, i##_len = (r); i < i##_len; ++i)
#define REP3(i, l, r) for (Int i = l, i##_len = (r); i <= i##_len; ++i)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 62;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

template <class T>
inline bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <class T>
inline bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

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

    Int n, m;
    cin >> n >> m;
    vector<Int> x(m);
    rep(i, m) {
        cin >> x[i];
    }

    sort(all(x));
    vector<Int> xd(m - 1);
    rep(i, m - 1) {
        xd[i] = x[i + 1] - x[i];
    }
    sort(all(xd), greater<>());
    Int ans = 0;
    rep(i, m - 1) {
        if (i < n - 1) {
            continue;
        } else {
            ans += xd[i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4760
#include <cstdio>
#include <iostream>

using namespace std;

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

    int h = S / 3600;
    int m = S % 3600 / 60;
    int s = S % 60;

    printf("%d:%d:%d\n", h, m, s);

    return 0;
}


Measured memory_bytes: 3224
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scanf("%d %d", &n, &m)
	var homework, a int
	for i := 0; i < m; i++ {
		fmt.Scan(&a)
		homework += a
	}
	if homework > n {
		fmt.Println("-1")
	} else {
		fmt.Println(n - homework)
	}
}


Measured memory_bytes: 2448
let () =
  Scanf.scanf "%d\n" @@ fun n ->
  let lst = Array.to_list (Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun d -> d) in
  let ans = (List.length lst) = List.length (List.sort_uniq compare lst) in
  Printf.printf "%s\n" (if ans then "YES" else "NO")

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  int max = 0;
  int min = 1000000000;
  for (int i = 0; i < N; i++) {
    if (a.at(i) > max) {
      max = a.at(i);
    }
    if (a.at(i) < min) {
      min = a.at(i);
    }
  }
  int ans = max - min;
  cout << ans << endl;
}


Measured memory_bytes: 256
// -*- coding: utf-8 -*-
// @Date    : 2019-11-09 18:32:56

#include <bits/stdc++.h>
#define greeting cerr << "What's your problem?\n"

using namespace std;
typedef long long ll;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& v)
{
	for(auto i : v)
		os << i << " ";
	return os;
}

template<typename T>
ostream& operator << (ostream& os, const set<T>& v)
{
	for(auto i : v)
		os << i << " ";
	return os;
}

#define locala
int main()
{
#ifdef local
	freopen("data.in", "r", stdin);
	freopen("ans.out", "w", stdout);
#endif	
	set<int> s;
	for(int i = 1; i < 10; ++i)
		for(int j = 1; j <= i; ++j)
			s.insert(i*j);
	int x;
	scanf("%d", &x);
	if(s.count(x))
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
fn in_digit(mut x: u32, a: u32, b: u32) -> bool {
    let mut sum = 0;
    while x > 0 {
        sum += x % 10;
        x /= 10;
    }
    a <= sum && sum <= b
}

fn main() {
    input!(
        n: u32,
        a: u32,
        b: u32,
    );
    println!(
        "{}",
        (1..n+1)
            .into_iter()
            .filter(|x| {
                let sum = x.to_string()
                    .chars()
                    .map(|c| (c as u8 - b'0') as u32)
                    .sum::<u32>();
                a <= sum && sum <= b
            })
            .sum::<u32>()
    )
}


Measured memory_bytes: 4352
#include <bits/stdc++.h> 
using namespace std; 
const int dx[]={1,0,-1,0,1,-1,-1,1}; 
const int dy[]={0,1,0,-1,1,1,-1,-1}; 
const int INF = 1e9; 
const long long LINF = 1e18; 
const double EPS = 1e-8; 
#define pb push_back 
#define mk make_pair 
#define fr first 
#define sc second 
#define ll long long 
#define reps(i,j,k) for(int i = (j); i < (k); ++i) 
#define rep(i,j) reps(i,0,j) 
#define all(a) (a).begin(),(a).end() 
#define MOD 1000000007 
typedef pair<int,int> Pii; 
typedef vector<int> vi; 
ll a[100100];
ll b[100100];
ll c[100100];
ll d[100100];
ll flg[100100][2];
int main(){
    int N;
    cin >> N;
    rep(i,N){
        cin >> a[i]; 
    }
    rep(i,N){
        cin >> b[i];
    }
    reverse(b,b+N);
    reps(i,1,N){
        if(a[i-1] > a[i] || b[i-1] > b[i]){
            cout << 0 << endl;
            exit(0);
        }
    }
    ll prev = -1;
    rep(i,N){
        if(a[i] != prev){
            c[i] = 1LL;
            flg[i][0] = true;
            prev = a[i];
        }
        else{
            c[i] = prev;
        }
    }
    prev = -1;
    rep(i,N){
        if(b[i] != prev){
            d[i] = 1LL;
            flg[i][1] = true;
            prev = b[i];
        }
        else{
            d[i] = prev;
        }
    }
   // rep(i,N){
     //   cout << a[i] << " ";
    //}
    //cout << endl;
    //rep(i,N){
     //    cout << b[i] << " ";
    //}
    //cout << endl;

    ll ans = 1;
    rep(i,N){
        int s = i;
        int e = N-i-1;
        if(flg[s][0] && flg[e][1]){
            //cout << "FLG1" << endl;
            if(a[s] != b[e]){
                cout << 0 << endl;
                exit(0);
            }
        }
        else if(flg[s][0]){
            //cout << "FLG2" << endl;
            if(a[s] > b[e]){
                cout << 0 << endl;
                exit(0);
            }
        }
        else if(flg[e][1]){
            //cout << "FLG3" << endl;
            if(b[e] > a[s]){
                cout << 0 << endl;
                exit(0);
            }
        }
        //cout << "PASS" << endl;
     //   cout << c[s] << " " << d[e] << endl;
        ans *= min(c[s],d[e]);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4736
a,b = map(int,input().split())
List = [int(i) for i in input().split()]
s = [0]*b
s[b-1] = abs(List[0] + a- List[b-1])
for i in range(b-1):
    s[i] = abs(List[i]-List[i+1])
print(a-max(s))

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

using namespace std;

long long a[100005];
long long tree[4*100005+4];

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

void Build(int v, int l, int r) {
	if (l>r) return;
	if (l==r) {
		tree[v] = a[l];
		return;
	}
	int m = (l+r)/2;
	Build(2*v,l,m);
	Build(2*v+1,m+1,r);
	tree[v] = gcd(tree[2*v], tree[2*v + 1]);
}

long long Find(int v, int l, int r, int cl, int cr) {
	if ((cr<l) || (r<cl))
		return 0;
	if ((cl<=l) && (r<=cr))
		return tree[v];
	int m = (l+r)/2;
	return gcd(Find(2*v,l,m,cl,cr),Find(2*v+1,m+1,r,cl,cr));
}

int main() {
	int n;
	cin>>n;
	for (int i=1; i<=n; i++)
		cin>>a[i];
	Build(1,1,n);
	/*for (int i=1; i<=8; i++)
		cout<<tree[i]<<" ";
	cout<<endl;*/
	long long res = max(Find(1,1,n,2,n), Find(1,1,n,1,n-1));
	for (int i=2; i<n; i++)
		res = max(res,gcd(Find(1,1,n,1,i-1),Find(1,1,n,i+1,n)));
	cout<<res<<endl;
}

Measured memory_bytes: 3072
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC120a
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);
            int c = int.Parse(s[2]);

            Console.WriteLine(Math.Min(b / a, c));
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <vector>
using namespace std;
vector<int> dp(8000000, -1);
int f(vector<vector<int>> &A, int y1, int x1, int y2, int x2){
	int X = (y1 * 200 + x1) * 200 + y2;
	if (dp[X] != -1){
		return dp[X];
	} else {
		int tmp = A[y1][x1] + A[y2][x2];
		if (y1 == y2 && x1 == x2){
			tmp /= 2;
		}
		int ans = 0;
		if (y1 > 0 && y2 > 0){
			ans = max(ans, f(A, y1 - 1, x1, y2 - 1, x2));
		}
		if (y1 > 0 && x2 > 0){
			ans = max(ans, f(A, y1 - 1, x1, y2, x2 - 1));
		}
		if (x1 > 0 && y2 > 0){
			ans = max(ans, f(A, y1, x1 - 1, y2 - 1, x2));
		}
		if (x1 > 0 && x2 > 0){
			ans = max(ans, f(A, y1, x1 - 1, y2, x2 - 1));
		}
		ans += tmp;
		dp[X] = ans;
		return ans;
	}
}
int main(){
	int H, W;
	cin >> H >> W;
	vector<vector<int>> A(H, vector<int>(W));
	for (int i = 0; i < H; i++){
		for (int j = 0; j < W; j++){
			cin >> A[i][j];
		}
	}
	cout << f(A, H - 1, W - 1, H - 1, W - 1) << endl;
}

Measured memory_bytes: 34604
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

signed main() {
    int n, m;
    cin >> n >> m;
    map<int, vector<int>> v;
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        v[a].push_back(b);
    }
    for (auto && x : v[1]) {
        if (v[x].empty())
            continue;
        for (auto && y : v[x]) {
            if (y == n) {
                cout << "POSSIBLE" << "\n";
                return 0;
            }
        }
    }
    cout << "IMPOSSIBLE" << "\n";
}

Measured memory_bytes: 19828
#include <stdio.h>

int main(void)
{
  //入力
  int n,x;
  scanf("%d%d",&n,&x);
  int i,l[n];
  for(i=0;i<n;i++)
    scanf("%d",&l[i]);



  //計算
  int cnt=0,dist=0;

  for (i=0; i<=n; i++) {
    if(dist<=x)
      cnt++;
    dist += l[i];
  }

  //出力
  printf("%d\n",cnt);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>

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

struct Union_Find {
	vector<int> root, rank;
	Union_Find(int n) {
		root.resize(n), rank.resize(n);
		for (int i = 0; i < n; i++)root[i] = i, rank[i] = 1;
	}

	int getroot(int n) {
		if (n == root[n])return n;
		return root[n] = getroot(root[n]);
	}

	bool issame(int a, int b) {
		int P = getroot(a), Q = getroot(b);
		return P == Q;
	}

	void unite(int a, int b) {
		int P = getroot(a), Q = getroot(b);
		if (P == Q)return;
		if (rank[P] > rank[Q]) {
			root[Q] = P;
		}
		else {
			if (rank[P] == rank[Q]) {
				rank[Q]++;
			}
			root[P] = Q;
		}
	}

};

struct Edge {
	int from, to;
	ll cost;
};

ll getcost(P a, P b) {
	return min(abs(a.first - b.first), abs(a.second - b.second));
}

int N;
P pos[100000];
TP arx[100000], ary[100000];
vector<Edge> candidate;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> pos[i].first >> pos[i].second;
		arx[i] = TP(pos[i], i);
		ary[i] = TP(P(pos[i].second, pos[i].first), i);
	}
	sort(arx, arx + N), sort(ary, ary + N);

	for (int i = 0; i < N - 1; i++) {
		Edge NewE;
		NewE.from = arx[i].second, NewE.to = arx[i + 1].second;
		NewE.cost = getcost(arx[i].first, arx[i + 1].first);
		candidate.push_back(NewE);
	}

	for (int i = 0; i < N - 1; i++) {
		Edge NewE;
		NewE.from = ary[i].second, NewE.to = ary[i + 1].second;
		NewE.cost = getcost(ary[i].first, ary[i + 1].first);
		candidate.push_back(NewE);
	}

	sort(candidate.begin(), candidate.end(), [](Edge &a, Edge &b) {
		if (a.cost < b.cost)return true;
		else return false;
	});

	Union_Find uf(N);

	ll ans = 0;
	for (int i = 0; i < candidate.size(); i++) {
		Edge now = candidate[i];
		if (!uf.issame(now.from, now.to)) {
			ans += now.cost;
			uf.unite(now.from, now.to);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 12656
# Acceptance of input
import sys

file_input = sys.stdin

V, E = map(int, file_input.readline().split())

adj = [[] for i in range(V)]

for i in range(E):
    s, t = map(int, file_input.readline().split())
    adj[s].append(t)


# Tarjan's strongly connected components algorithm
import collections

sys.setrecursionlimit(100000)

S = collections.deque()
indices = [None] * V
lowlink = [None] * V
onStack = [False] * V
index = 0
scc_id = [None] * V

def strong_connect(v):
    global index
    indices[v] = index
    lowlink[v] = index
    index += 1
    S.append(v)
    onStack[v] = True

    for w in adj[v]:
        if indices[w] == None:
            strong_connect(w)
            lowlink[v] = min(lowlink[v], lowlink[w])
        elif onStack[w]:
            lowlink[v] = min(lowlink[v], indices[w])

    if lowlink[v] == indices[v]:
        while S:
            w = S.pop()
            onStack[w] = False
            scc_id[w] = v
            if w == v:
                break

for v in range(V):
    if not indices[v]:
        strong_connect(v)


# Output
Q = file_input.readline()

for line in file_input:
    u, v = map(int, line.split())
    if scc_id[u] == scc_id[v]:
        print(1)
    else:
        print(0)

Measured memory_bytes: 19868
#include <algorithm>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
#include <cstring>
#include <tuple>
#include <bitset>
#include <unordered_map>
using namespace std;
typedef long long ll;

void print(vector<int> vi) {
    for (int i=0; i<(int)vi.size(); ++i) {
        cout << (i == 0 ? "" : " ") << vi[i];
    }
    cout << endl;
}

int main() {
    ios::sync_with_stdio(false);

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

    int ans = 0;
    for (int i=0; i<N; ++i) {
        int mini = i;
        for (int j=i; j<N; ++j) {
            if (A[mini] > A[j]) {
                mini = j;
            }
        }
        if (mini != i) {
            swap(A[mini], A[i]);
            ++ ans;
        }
    }
    print(A);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1216
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let v: Vec<usize> = s.trim().split_whitespace().map(|x| x.parse().unwrap()).collect();
    for _ in 0..v[0] {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        println!("{}\n{}", s.trim(), s.trim());
    }
}



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

int main() {
  long long x; cin >> x;
  long long ans = 0;
  ans += 2 * (x / 11);
  long long r = x % 11;
  if (r >= 1 && r <= 6) ans += 1;
  if (r >= 7 && r <= 10) ans += 2;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  string s, akb = "AKIHABARA";
  cin >> s;
  int j = 0;
  for(int i = 0; i < s.length(); ++i){
    if(akb[j] == 'A' && s[i] != 'A') ++j;
    if(s[i] == akb[j]) ++j;
    else{
      cout << "NO" << endl;
      return 0;
    }
  }
  if(j >= 8) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  cin >> s;
  cout << s.substr(0, 3) << "\n";
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int n;
cin >> n;
int c[n],v[n];
REP(i,n) cin >> v[i];
REP(i,n) cin >> c[i];
int s[n];
int ans = 0;
REP(i,n) {
  s[i] = v[i]-c[i];
  if(s[i]>0) ans+=s[i]; 
}
cout << ans << endl;
return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque
K = int(input())

es = []
for i in range(K):
    v0 = (i*10) % K
    v1 = (i+1) % K
    es.append((v0, v1))

visited = [0 for i in range(K)]
q = deque([(1,1)])
while q:
    now,cost = q.popleft()
    if now == 0:
        print(cost)
        sys.exit()
    visited[now] = 1
    v0,v1 = es[now]
    if not visited[v0]: q.appendleft((v0, cost))
    if not visited[v1]: q.append((v1, cost+1))


Measured memory_bytes: 22260
#include <bits/stdc++.h>
using namespace std;
#define fore(i, a, b) for (int i = a, to = b; i < to; i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define SZ(v) (int)v.size()
#define pb push_back
typedef long long Long;
typedef pair<int, int> Pair;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  Long n,k;cin>>n>>k;
  vector<Long> v(n);
  fore(i,0,n)cin>>v[i];
  sort(rall(v));
  Long ans = 0;
  fore(i,0,n)if(i>=k)ans+=v[i];
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 1792
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        String[] s = new String[3];
        s[0] = in.next();
        s[1] = in.next();
        s[2] = in.next();

        int x = 0;
        while (true) {
            if (s[x].length() == 0) {
                out.println(x == 0 ? "A" : x == 1 ? "B" : "C");
                return;
            }
            char c = s[x].charAt(0);
            s[x] = s[x].length() == 1 ? "" : s[x].substring(1);
            x = c == 'a' ? 0 : c == 'b' ? 1 : 2;
        }
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}

Measured memory_bytes: 21332
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>

using namespace std;

typedef long long ll;

int cnt_digits(ll N) {
    int digits = 0;

    while (N > 0) {
        N /= 10;
        digits++;
    }

    return digits;
}

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

    int ans = cnt_digits(N);

    for (ll A=1LL;A*A <= N; ++A) {
        if (N%A!= 0) continue;
        const ll B = N/A;

        const int cur = max(cnt_digits(A), cnt_digits(B));

        if (ans > cur) {
            ans = cur;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>
#include <queue>

using namespace std;


int main()
{
	int N,K;
	string  S;
	cin >> N >> K >> S;

	vector<int> Ls;
	vector<int> sum_l;

	int cnt = 1;
	sum_l.push_back(0);
	for (int ni = 1; ni < N; ni++){
		if(S[ni -1] == S[ni]){
			cnt++;
		}else{
			Ls.push_back(cnt);
			sum_l.push_back(sum_l.back() + cnt);
			cnt = 1;
		}		
	}
	Ls.push_back(cnt);
	sum_l.push_back(sum_l.back() + cnt);

	int mod = 0;
	if (S[0] == '0'){
		mod = 1;
	}

	//int len = min( (int)sum_l.size() - 1, 2 * K + 1);
	int len = 2 * K + 1;

	if (len == 1) {
		printf("%d", N);
		return 0;
	}

	int sum;
	int u_sum = 0;
	//for (int li = 0; li < sum_l.size() - len + 1; li++) {
	for (int li = 0; li < sum_l.size(); li++){
		if (li % 2 == mod && li != sum_l.size() - len) {
			sum = sum_l[min(li + len, (int)sum_l.size() - 1)] - sum_l[li];
		}
		else {
			sum = sum_l[min(li + len - 1, (int)sum_l.size() - 1)] - sum_l[li];
		}

		if (sum > u_sum) {
			u_sum = sum;
		}

	}

	int ans = u_sum;

	printf("%d", ans);

	return 0;
}


Measured memory_bytes: 1404
class Combination:
    def __init__(self, size, mod=10**9 + 7):
        self.size = size + 2
        self.mod = mod
        self.fact = [1, 1] + [0] * size
        self.factInv = [1, 1] + [0] * size
        self.inv = [0, 1] + [0] * size

        for i in range(2, self.size):
            self.fact[i] = self.fact[i - 1] * i % self.mod
            self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod
            self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod

    def npr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * self.factInv[n - r] % self.mod

    def ncr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod

    def nhr(self, n, r):  # 重複組合せ
        return self.ncr(n + r - 1, n - 1)

    def factN(self, n):
        if n < 0:
            return 0
        return self.fact[n]

N, M, K = map(int, input().split())
MOD = 10**9 + 7
comb = Combination(N * M + 100)

S = 0
for x in range(1, N):
    S += (N - x) * (M**2) * x
for y in range(1, M):
    S += (M - y) * (N**2) * y

ans = S * comb.ncr(N * M - 2, K - 2)
print(ans % MOD)


Measured memory_bytes: 28248
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        long n=Long.parseLong(br.readLine());
        StringTokenizer st=new StringTokenizer(br.readLine());
        long[] a=new long[(int)n];
        long sum=0;
        long count=0;
        for(int i=0;i<n;i++){ a[i]=Long.parseLong(st.nextToken()); sum+=a[i]; }
        if(sum%((n*(n+1))/2)!=0){
            System.out.println("NO");
            System.exit(0);
        }
        long times=sum/((n*(n+1))/2);
        for(int i=0;i<n;i++){
            count=(a[(i+1)%(int)n]-a[i]);
            if((count>times)||(times-count)%n!=0){
                System.out.println("NO");
                System.exit(0);
            }else if(count<0 && (times-count)/n>times){
                    System.out.println("NO");
                    System.exit(0);
            }
        }System.out.println("YES");
    }
}


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

int main() {
  string str;
  cin >> str;
  
  for (int i=0;i<5;i++){
  cout << str.at(i);
}
  cout <<" ";
  for (int i=6;i<13;i++){
    cout <<str.at(i);
  }
  cout <<" ";
  for (int i=14;i<19;i++){
    cout << str.at(i) ;
  }
}

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

#define N 200001

using namespace std;

const int MOD = 1e9 + 7;
int n;
int h[N];
long long a[N];
long long dp[N];
long long st[4 * N];

long long max(long long a, long long b)
{
	return (a < b) ? b : a;
}

void insert(int ind, long long val, int ss, int se, int si)
{
	if (ss > se)
		return;
	if (ss == se)
	{
		st[si] = val;
		return;
	}
	int mid = ss + (se - ss) / 2;
	if (ind <= mid)
		insert(ind, val, ss, mid, 2 * si + 1);
	else
		insert(ind, val, mid + 1, se, 2 * si + 2);
	st[si] = max(st[2 * si + 1], st[2 * si + 2]);
}

long long query(int qs, int qe, int ss, int se, int si)
{
	if (qs > se || qe < ss)
		return 0;
	if (qs <= ss && qe >= se)
		return st[si];
	int mid = (ss + se) / 2;
	return max(query(qs, qe, ss, mid, 2 * si + 1), query(qs, qe, mid + 1, se, 2 * si + 2));
}

long long solve()
{
	memset(dp, 0, sizeof(dp));
	memset(st, 0, sizeof(st));

	long long ans = 0;

	for (int i = 0; i < n; i++)
	{
		dp[h[i]] = a[i] + query(1, h[i] - 1, 1, n, 0);
		ans = max(ans, dp[h[i]]);
		insert(h[i], dp[h[i]], 1, n, 0);
	}
	return ans;
}

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> h[i];
	for (int i = 0; i < n; i++)
		cin >> a[i];
	cout << solve() << endl;
	return 0;
}


Measured memory_bytes: 10368
#include<iostream>
#include<cstdio>
#include<cstdlib> 
#include<cstring>
using namespace std;
char s[200];
int main()
{
	scanf("%s",s);
	int l=strlen(s);
	for (int i=0; i<l-8; i++) printf("%c",s[i]);
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 1000000 + 5;

int ans, a[N], b[N], rt[N * 20], ls[N * 20], rs[N * 20], sum[N * 20];
 
int n, k, tot, sz, ql, qr, x, q;
 
void Build(int& o, int l, int r){
    o = ++ tot;
    sum[o] = 0;
    if(l == r) return;
    int m = (l + r) >> 1;
    Build(ls[o], l, m);
    Build(rs[o], m + 1, r);
}
 
void update(int& o, int l, int r, int last, int p){
    o = ++ tot;
    ls[o] = ls[last];
    rs[o] = rs[last];
    sum[o] = sum[last] + 1;
    if(l == r) return;
    int m = (l + r) >> 1;
    if(p <= m)  update(ls[o], l, m, ls[last], p);
    else update(rs[o], m + 1, r, rs[last], p);
}
 
void query(int ss, int tt, int l, int r, int x, int y){
    if(x <= l && r <= y)  
	{
		ans += sum[tt] - sum[ss];
		return;
	}
    int m = (l + r) >> 1;
    if(x <= m) query(ls[ss], ls[tt], l, m, x, y);
    if (y > m) query(rs[ss], rs[tt], m + 1, r, x, y);
}
void work(){
    scanf("%d%d%d", &ql, &qr, &x);
    int l = lower_bound(b + 1, b + sz + 2, min(b[a[ql]], b[a[qr]]) - x) - b - 1;
    int r = lower_bound(b + 1, b + sz + 2, max(b[a[ql]], b[a[qr]]) + x + 1) - b;
    ans = 0;
	if (l >= 1)
		query(rt[ql - 1], rt[qr], 1, sz, 1, l);
	if (r <= sz) 
		query(rt[ql - 1], rt[qr], 1, sz, r, sz); 
    printf("%d\n", ans);
}
 
int main(){
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) scanf("%d", a + i), b[i] = a[i];
    scanf("%d", &q);
    sort(b + 1, b + n + 1);
    sz = unique(b + 1, b + n + 1) - (b + 1);
    b[sz + 1] = 1e9;
    tot = 0;
    Build(rt[0], 1, sz);
    //for(int i = 0; i <= 4 * n; i ++)printf("%d,rt =  %d,ls =  %d, rs = %d, sum = %d\n", i, rt[i], ls[i], rs[i], sum[i]);
    for(int i = 1; i <= n; i++)a[i] = lower_bound(b + 1, b + sz + 1, a[i]) - b;
    for(int i = 1; i <= n; i++)update(rt[i], 1, sz, rt[i - 1], a[i]);
    //for(int i = 0; i <= 5 * n; i++)printf("%d,rt =  %d,ls =  %d, rs = %d, sum = %d\n", i, rt[i], ls[i], rs[i], sum[i]);
    while(q--)work();
    return 0;
}


Measured memory_bytes: 27028
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <utility>
using namespace std;

typedef pair<int,int> pii;


#define M 1000000
#define INF 1000000000

#define MAX 1100

bool isnp[M + 10] = {true, true};
int hl[MAX][MAX];
pii tbl[M + 10];

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

int main(){
	for(int i = 2; i * i <= M; ++i){
		if(!isnp[i]){
			for(int j = i * i; j <= M; j += i){
				isnp[j] = true;
			}
		}
	}

	int y = MAX / 2, x = MAX / 2;
	int k = 1;
	int d = 0;
	int c = 1;
	int z = 1;
	int my = 0;
	while(k <= M){
		hl[y][x] = k;
		tbl[k] = pii(y, x);
		y += dy[d];
		x += dx[d];
		if(!--c){
			d = (d + 1) % 4;
			if(d % 2 == 0){
				++z;
			}
			c = z;
		}
		++k;
		my = max(my, y);
	}

	vector<pii> def(MAX, pii(-INF, -INF));

	int m, n;
	while(scanf("%d%d", &m, &n), m){
		y = tbl[n].first;
		x = tbl[n].second;
		
		vector<pii> v1 = def;
		if(isnp[n]){
			v1[x] = pii(0, 0);
		}
		else{
			v1[x] = pii(1, n);
		}

		pii ans = v1[x];
		while(y < my){
			vector<pii> v2 = def;
			int ny = y + 1;
			for(int x = 0; x < MAX; ++x){
				if(!hl[y][x] || hl[y][x] > m) continue;
				for(int d = -1; d <= 1; ++d){
					int nx = x + d;
					if(!hl[ny][nx] || hl[ny][nx] > m) continue;
					pii tmp = v1[x];
					if(!isnp[hl[ny][nx]]){
						tmp = pii(tmp.first + 1, hl[ny][nx]);
					}
					v2[nx] = max(v2[nx], tmp);
					ans = max(ans, v2[nx]);
				}
			}
			v1.swap(v2);
			++y;
		}

		printf("%d %d\n", ans.first, ans.second);
	}
}

Measured memory_bytes: 14512
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    ll N, K;
    cin >> N >> K;
    ll ans = pow(N / K, 3);
    if (K % 2 == 0) {
        ll d = N / K;
        if (N % K >= K / 2) d++;
        ans += pow(d, 3);
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
/*void cplc(int p0[2],int p1[2],int p2[2],int r,double s[2],double t[2]){
  int x1=p1[0]-p0[0],y1=p1[1]-p0[1],x2=p2[0]-p0[0],y2=p2[1]-p0[1];
  int a=x1*x1+y1*y1,b=x1*x2+y1*y2,c=x2*x2+y2*y2-r*r;
  double d=sqrt(b*b-a*c);
  s[0]=p0[0]+x1*((b+d)/a);
  s[1]=p0[1]+y1*((b+d)/a);
  t[0]=p0[0]+x1*((b-d)/a);
  t[1]=p0[1]+y1*((b-d)/a);
  }//*/
void ashi(int p0[2],int p1[2],int p2[2],double p3[2]){
  int x1=p1[0]-p0[0],x2=p2[0]-p0[0],y1=p1[1]-p0[1],y2=p2[1]-p0[1];
  p3[0]=1.0*(x1*x2+y1*y2)/(x1*x1+y1*y1)*x1+p0[0];
  p3[1]=1.0*(x1*x2+y1*y2)/(x1*x1+y1*y1)*y1+p0[1];
}
void cplc(int p0[2],int p1[2],int p2[2],int r,double s[2],double t[2]){
  int x1=p1[0]-p0[0],y1=p1[1]-p0[1];
  double p3[2],l;
  ashi(p0,p1,p2,p3);
  l=sqrt(r*r-(p3[0]-p2[0])*(p3[0]-p2[0])-(p3[1]-p2[1])*(p3[1]-p2[1]));
  s[0]=p3[0]+x1/hypot(x1,y1)*l;
  s[1]=p3[1]+y1/hypot(x1,y1)*l;
  t[0]=p3[0]-x1/hypot(x1,y1)*l;
  t[1]=p3[1]-y1/hypot(x1,y1)*l;
}  
int main(){
  int p[4][2],n,i,r,j=0;
  double a[2][2],e=0.000005;
  scanf("%d %d %d %d",&p[2][0],&p[2][1],&r,&n);
  while(n--){
    for(i=0;i<4;i++)scanf("%d",&p[i/2][i%2]);
    cplc(p[0],p[1],p[2],r,a[0],a[1]);
    if(fabs(a[0][0]-a[1][0])<e)j=a[0][1]+e<a[1][1]?0:1;
    else                       j=a[0][0]+e<a[1][0]?0:1;
    printf("%.9f %.9f %.9f %.9f\n",a[j][0],a[j][1],a[1-j][0],a[1-j][1]);
  }
  return 0;
}

Measured memory_bytes: 652
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

LL a[100005];
LL prefix[100005];

int main() {
    LL n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n, [](LL x, LL y) { return x > y; });
    prefix[0] = a[0];
    for (int i = 1; i < n; i++) {
        prefix[i] = prefix[i - 1] + a[i];
    }
    LL l = 0, r = 2e5 + 5;
    LL num;
    LL ans = 0;
    while (r - l > 1) {
        LL mid = (l + r) / 2;
        LL up = n - 1;
        LL count = 0;
        LL sum = 0;
        for (LL i = 0; i < n; i++) {
            while (0 <= up && !(a[i] + a[up] >= mid)) { up--; }
            if (0 > up) { break; }
            count += up + 1;
            sum += prefix[up] + (up + 1) * a[i];
        }
        // printf("mid = %lld, count = %lld, sum = %lld\n", mid, count, sum);
        if (count >= m) {
            num = count;
            ans = sum;
            l = mid;
        } else {
            r = mid;
        }
    }
    cout << ans - (num - m) * l << endl;
}


Measured memory_bytes: 5160
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
S = input().replace('?','.')
T = input()
for i in range(len(S)-len(T),-1,-1):
    if re.match(S[i:i+len(T)],T):
        S = S.replace('.','a')
        print(S[:i] + T + S[i+len(T):])
        exit()
print('UNRESTORABLE')


Measured memory_bytes: 10300
import java.util.*;
public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		long n=in.nextLong(),c=0,s=0;
		long k=in.nextLong();
		long[] arr=new long[(int)n];
		for(int i=0;i<n;i++)
		{
			arr[i]=in.nextInt();
			s=s+arr[i];
		}
		if(k>=n)
		{
			System.out.println("0");
			System.exit(0);
		}
		Arrays.sort(arr);
		long mid=n-1;
		while(c!=k)
		{
			s=s-arr[(int)mid];
			mid--;
			c++;
		}
		System.out.println(s);
	}
}

Measured memory_bytes: 89716
use std::io::Read;
use std::collections::HashMap;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let mut counts: HashMap<usize, usize> = HashMap::new();
    for _ in 0..n {
        let ai: usize = iterator.next().unwrap().parse().unwrap();
        *counts.entry(ai).or_insert(0) += 1;
    }

    if n % 2 == 0 {
        for i in 0..(n / 2) {
            let ai = 2 * i + 1;
            if !counts.contains_key(&ai) || *counts.get(&ai).unwrap() != 2 {
                return "0".to_string();
            }
        }
        return mod_pow(2, n / 2).to_string();
    }

    let zero = 0;
    if !counts.contains_key(&zero) || *counts.get(&zero).unwrap() != 1 {
        return "0".to_string();
    }
    for i in 0..(n / 2) {
        let ai = 2 * (i + 1);
        if !counts.contains_key(&ai) || *counts.get(&ai).unwrap() != 2 {
            return "0".to_string();
        }
    }

    return mod_pow(2, n / 2).to_string();
}

const MOD: usize = 1000000007;

fn mod_pow(a: usize, b: usize) -> usize {
    let mut result = 1;
    for _ in 0..b {
        result = result * a % MOD;
    }
    return result
}


Measured memory_bytes: 12540
from heapq import heappop, heappush
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
X = sorted([list(map(int, input().split())) for _ in range(N)], key = lambda x: x[0])

hq = []
ans, j = 0, 0

for i in range(1, M + 1):  # M - i 日後にするバイトを考える
    while (j < N) and (X[j][0] <= i):
        heappush(hq, -X[j][1])  # 候補の追加
        j += 1
    if len(hq):
        ans += -heappop(hq)  # 候補があるとき、候補から最大値を取り出す

print(ans)


Measured memory_bytes: 31948
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cassert>

#define pb push_back
#define mp make_pair

using namespace std;
int main() {
  int q, h, d, s;
  cin >> q >> h >>d >> s;
  q *= 4;
  h *= 2;
  int n;
  cin >> n;
  d = min(d, min(h, q));
  if (d *  2 <= s) {
    cout << 1ll * n * d;
  } else {
    cout << 1ll * n / 2 * s +1ll * (n % 2 == 1) * d;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<ll, ll>;
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; }

const ll inf = 1e18;
const ll MAXC = 2500;
using edge = pair<int, P>; // to, money, time

ll dp[55][MAXC+1]; // pos, money

int main(){
    int n,m; ll s; cin >> n >> m >> s;
    chmin(s, MAXC);
    vector<vector<edge>> g(n);
    rep(i,m){
        int u,v; ll a,b; cin >> u >> v >> a >> b;
        u--; v--;
        g[u].pb({v, {a,b}});
        g[v].pb({u, {a,b}});
    }
    vector<ll> c(n), d(n);
    rep(i,n) cin >> c[i] >> d[i];
    rep(i,n){
        rep(j,MAXC+1){
            dp[i][j] = inf;
        }
    }

    dp[0][s] = 0;
    priority_queue<pair<ll, P>, vector<pair<ll, P>>, greater<pair<ll, P>>> que;
    // time, pos, money
    que.push({0,{0,s}});

    while(!que.empty()){
        auto v = que.top(); que.pop();
        ll time = v.first;
        ll pos = v.second.first;
        ll money = v.second.second;
        if(time > dp[pos][money]) continue;

        ll next_money = min(money + c[pos], MAXC);
        ll next_time = time + d[pos];
        if(chmin(dp[pos][next_money], next_time)){
            que.push({next_time, {pos, next_money}});
        }

        for(auto e : g[pos]){
            if(money < e.second.first) continue;
            ll next_time = time + e.second.second;
            ll next_pos = e.first;
            ll next_money = money - e.second.first;
            if(chmin(dp[next_pos][next_money], next_time)){
                que.push({next_time, {next_pos, next_money}});
            }
        }
    }

    FOR(i,1,n){
        ll ans = inf;
        rep(j,MAXC+1){
            chmin(ans, dp[i][j]);
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 7416
n = int(input())
t=[0]*(n+1)
x=[0]*(n+1)
y=[0]*(n+1)
cnt = 0
for i in range(1,n+1):
  t[i],x[i],y[i] = list(map(int,input().split()))
  dt = t[i]-t[i-1]
  dr = abs(x[i]-x[i-1])+abs(y[i]-y[i-1])
  if dt%2==dr%2 and dt >= dr:
    continue
  else:
    print('No')
    cnt = 1
    break
if cnt==0:
  print('Yes')

Measured memory_bytes: 11764
#ifndef Local
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define popCnt(x) (__builtin_popcountll(x))
typedef long long Long;

const int N = 2e6 + 5;
const int MOD = round(1e9 + 7);

int acc[N];
int arr[N];

int cnt[N][2];
int pw2[N];
vector<int> occ[N];

int cntInRange(const vector<int>& occ, int l, int r) {
  auto r_it = upper_bound(occ.begin(), occ.end(), r);
  auto l_it = lower_bound(occ.begin(), occ.end(), l);
  return r_it - l_it;
}

void build() {
  pw2[0] = 1;
  for (int i = 1; i < N; ++i) {
    pw2[i] = 2LL * pw2[i - 1] % MOD;
  }
}

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  build();

  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> arr[i];
    acc[i] = acc[i - 1] ^ arr[i];
    occ[acc[i]].push_back(i);
  }

  if (acc[n] == 0) {
    for (int i = 1; i < N; ++i) {
      cnt[i][0] = 1;
    }
  }

  for (int i = n; i >= 1; --i) {
    if (i == occ[acc[i]].back()) {
      cnt[acc[i]][1] = 1;
      continue;
    }
    if (acc[i] != 0) {
      int nxt = *upper_bound(occ[acc[i]].begin(), occ[acc[i]].end(), i);
      int cnt_zeroes = cntInRange(occ[0], i, nxt - 1);
      cnt[acc[i]][0] = (cnt[acc[i]][0] + 1LL * cnt_zeroes * cnt[acc[i]][1])
        % MOD;
      cnt[acc[i]][1] = (cnt[acc[i]][1] + cnt[acc[i]][0]) % MOD;
    }
  }

  Long res = 0;
  if (acc[n] == 0) {
    res = pw2[occ[0].size() - 1];
    for (int i = 1; i < N; ++i) {
      res = (res + cnt[i][1]) % MOD;
    }
  } else {
    res = cnt[acc[n]][1];
  }

  cout << res << endl;
}


Measured memory_bytes: 87668
/**
*    created: 09.07.2020 00:41:37
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
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;}
const long double pi = acos(-1.0);
const int MAX = 1000010;
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    bint a, b;
    cin >> a >> b;
    if (a > b) cout << "GREATER" << endl;
    else if (a == b) cout << "EQUAL" << endl;
    else cout << "LESS" << endl;
    return 0;
}

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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

int main()
{
    ll N, C;
    cin >> N >> C;
    vector<ll> s(N), t(N), c(N);
    ll tMax = 0;
    REP(i, N)
    {
        cin >> s[i] >> t[i] >> c[i];
        c[i]--;
        tMax = max(tMax, t[i]);
    }
    priority_queue<double, vector<double>, greater<double>> sDQ[C], tDQ[C];
    REP(i, N)
    {
        sDQ[c[i]].push((double)s[i] - 0.5);
        tDQ[c[i]].push((double)t[i]);
    }
    vector<double> sD[C], tD[C];
    REP(i, C)
    {
        ll sizeV = sDQ[i].size();
        vector<double> sDV(sizeV), tDV(sizeV);
        for (ll j = 0; j < sizeV; ++j)
        {
            sDV[j] = sDQ[i].top();
            sDQ[i].pop();
            tDV[j] = tDQ[i].top();
            tDQ[i].pop();
        }
        sD[i] = sDV;
        tD[i] = tDV;
    }

    map<double, ll> countRecord; 
    for (ll i = 1; i <= 2 * tMax; ++i)
    {
        double now = 0.5 * i;
        countRecord[now] = 0;
        REP(i, C)
        {
            if (sD[i].size() == 0)
            {
                continue;
            }

            auto it = lower_bound(ALL(sD[i]), now);
            if (it == sD[i].end())
            {
                if (now < tD[i][tD[i].size() - 1])
                {
                    countRecord[now]++;
                }
            }
            else
            {
                int index = distance(sD[i].begin(), it);
                if (now == sD[i][index]) 
                {
                    countRecord[now]++;
                }
                else
                {
                    if (index - 1 >= 0 && now < tD[i][index - 1]) 
                    {
                        countRecord[now]++;
                    }
                }
            }
        }
    }

    ll ans = 0;
    REPV(it, countRecord)
    {
        ans = max(ans, it->second);
    }

    cout << ans << endl;
}


Measured memory_bytes: 18944
/*************************************************************************
    > File Name: A.cpp
    > Author: HandsomeHow
    > Mail: handsomehowyxh@gmail.com 
    > Created Time: 2017/7/1 20:01:08
 ************************************************************************/

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

#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp make_pair
#define cl(a) memset((a),0,sizeof(a))
#ifdef HandsomeHow
#define dbg(x) cerr << #x << " = " << x << endl
#else
#define dbg(x)
#endif
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
const int mod=1000000007;
const double pi=acos(-1.0);
inline void gn(long long&x){
    int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
    while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
ll gcd(ll a,ll b){return a? gcd(b%a,a):b;}
ll powmod(ll a,ll x,ll mod){ll t=1ll;while(x){if(x&1)t=t*a%mod;a=a*a%mod;x>>=1;}return t;}
// (づ°ω°)づe★------------------------------------------------
const int maxn = 2e5+5;
int v[maxn*5];
int main(){
#ifdef HandsomeHow
    //freopen("data.in","r",stdin);
    //freopen("data.out","w",stdout);
#endif
    int n;
    gn(n);
    int l = 2e5+5, r=l+1;
    rep(i,1,n){
        int x;gn(x);
        if(i&1) v[r++]=x;
        else v[l--]=x;
    }
    ++n;
    if(n&1) rep(i,l+1,r-1)printf("%d ",v[i]);
    else per(i,r-1,l+1)printf("%d ",v[i]);
    
    puts("");
    return 0;
}



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

public class Main {

	public void Sort(){

	}

	public void maain(){

	}

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????

		//1???????????\????????¢
	       StringBuilder buider = new StringBuilder();

	       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String n = br.readLine();
        int count = 0;
        int w = 0;

        //??\????????¢
        int[] LaunderingNum = new int[Integer.parseInt(n)];

        String[] input2 = br.readLine().split(" ");

        for(int i = 0; i < LaunderingNum.length; i++){
        	LaunderingNum[i] = Integer.parseInt(input2[i]);
        }

        //
        for(int i = 0; i < LaunderingNum.length - 1; i++){
        	
        	int minj = i;
        	
        	for(int j = i + 1; j < LaunderingNum.length; j++){
        		
        		if(LaunderingNum[j] < LaunderingNum[minj]){
        			minj = j;
        		}
        	}
        	if(minj != i){
        		
    			w = LaunderingNum[i];
    			LaunderingNum[i] = LaunderingNum[minj];
    			LaunderingNum[minj] = w;
    			count++;
        	}

        }
        //
        for(int i = 0; i < LaunderingNum.length; i++){

        	if(i == LaunderingNum.length - 1){
        		System.out.println(LaunderingNum[i]);
        	}else{
            	System.out.print(LaunderingNum[i] + " ");
        	}

        }
        System.out.println(count);
	}
}

Measured memory_bytes: 24436