akhauriyash/Code-Regression huggingface dataset:
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list ?sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list ?sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list ?sep conv);
  arr

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

let m = scan "%d" id
let ls = scan_lines m "%d %d" Tuple2.make

let rec calc v n =
  if n = 1 then (v, 0)
  else
    let v2 = v + v in
    let (w, m) = if v2 / 10 = 1 then
        v2 mod 10 + v2 / 10, 1 + 1
      else v2, 1
    in
    let (x, o) = calc w (n/2) in
    if n mod 2 = 0 then
      (x, n/2 * m + o)
    else
      let s = v + x in
      (s mod 10 + s/10, n/2 * m + o + 1 + s/10)

let () =
  ListL.map ls ~f:(fun (v, n) -> calc v n)
  |> List.reduce (fun (v,n) (w, m) ->
      let s = v + w in
      (s mod 10 + s / 10, n + m + 1 + s/10))
  |> Tuple2.second
  |> Printf.printf "%d\n"


Measured memory_bytes: 24704
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,M=map(int,input().split())
    A=[input() for _ in range(N)]
    B=[input() for _ in range(M)]
    for i in range(N-M+1):
        for j in range(N-M+1):
            for k in range(M):
                if A[i+k][j:j+M]!=B[k]:
                    break
            else:
                print('Yes')
                exit()
    print('No')

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <stdio.h>

int main() {

	int arr[3][3]={};
	for(int i=0; i<3; i++){
		for(int j=0; j<3; j++){
			scanf("%d", &arr[i][j]);
		}
	}
	
	int n;
	scanf("%d", &n);
	int call;
	for(int k=0; k<n; k++){
		scanf("%d", &call);
		for(int i=0; i<3; i++){
			for(int j=0; j<3; j++){
			if(arr[i][j]==call){
				arr[i][j]=0;
			}
		}
			}
			
	}
	
	if(arr[0][0]==0&&arr[0][1]==0&&arr[0][2]==0 || arr[1][0]==0&&arr[1][1]==0&&arr[1][2]==0 || arr[2][0]==0&&arr[2][1]==0&&arr[2][2]==0 || arr[0][0]==0&&arr[1][0]==0&&arr[2][0]==0 || arr[0][1]==0&&arr[1][1]==0&&arr[2][1]==0 || arr[0][2]==0&&arr[1][2]==0&&arr[2][2]==0 || arr[0][0]==0&&arr[1][1]==0&&arr[2][2]==0 || arr[0][2]==0&&arr[1][1]==0&&arr[2][0]==0){
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}

    return 0;
}

Measured memory_bytes: 3116
#include <cstdio>
#include <cstdlib>
using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  scanf("%d", &N);
  int A[N + 2];
  A[0] = 0;
  A[N + 1] = 0;
  int cost[N + 1];
  int costall = 0;
  for (int i = 1; i < N + 1; i++) {
    scanf("%d", &A[i]);
    cost[i - 1] = abs(A[i] - A[i - 1]);
    // printf("%d\n", cost[i - 1]);
    costall += cost[i - 1];
  }
  cost[N] = abs(A[N + 1] - A[N]);
  costall += cost[N];
  for (int i = 1; i < N + 1; i++) {
    printf("%d\n", costall - cost[i - 1] - cost[i] + abs(A[i + 1] - A[i - 1]));
  }
  return 0;
}


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

int main(){
  int n;
  string s;
  cin >> n >> s;
  for(int i=0; i<s.size(); i++){
    int a = int(s[i]-'A');
    a += n;
    a %= 26;
    s[i] = char('A' + a);
    cout << s[i];
  }
}

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<long long, int>> a;
    for (int i = 0; i < n; i++) {
        long long e;
        cin >> e;
        a.emplace_back(e, 1);
    }
    for (int i = 0; i < m; i++) {
        int b;
        long long c;
        cin >> b >> c;
        a.emplace_back(c, b);
    }
    
    sort(a.rbegin(), a.rend());
    
    int cnt = 0;
    long long ans = 0;
    for (const auto &e : a) {
        int c;
        long long val;
        tie(val, c) = e;
        int res = min(max(0, n - cnt), c);
        ans += (long long) res * val;
        cnt += res;
    }
    cout << ans << endl;
    return 0;
}

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

#define fi first
#define se second
#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define pb push_back
#define int long long
typedef pair<int, int> ii;
const int N = 605;
const int mod = 1e9 + 7;

int n, k;
int sum[N], g[N], dp[N][N], ok[N][N];
ii eg[N];

bool inside(int l, int r, int p1, int p2)    {
    return ((l <= p1 && p1 <= r && l <= p2 && p2 <= r) || (!(l <= p1 && p1 <= r) && !(l <= p2 && p2 <= r)));
}
void add(int &x, int y) { x = (x + y) % mod; }
void mul(int &x, int y) { x = x * y % mod; }
void sub(int &x, int y) { x = (x % mod - y % mod); if(x < 0) x += mod; }
signed main()
{
    //freopen("test.inp", "r", stdin);
    ios_base::sync_with_stdio(false);   cin.tie(0); cout.tie(0);
    cin >> n >> k; n <<= 1;
    FOR(i, 1, k)    {
        int u, v; cin >> u >> v;
        sum[u] ++; sum[v] ++;   eg[i] = {u, v};
    }
    FOR(i, 1, n) sum[i] += sum[i - 1];
    FOR(i, 1, n) FOR(j, i, n)   {
        ok[i][j] = true; FOR(t, 1, k) if(!inside(i, j, eg[t].fi, eg[t].se))
            ok[i][j] = false;
    }
    k <<= 1;
    g[0] = 1;
    FOR(i, 2, N - 1) g[i] = g[i - 2] * (i - 1) % mod;

    for(int len = 2; len <= n; len += 2) FOR(l, 1, n) if(l + len - 1 <= n && ok[l][l + len - 1]) {
        int r = l + len - 1;
        int x = (r - l + 1) - sum[r] + sum[l - 1];
        dp[l][r] = g[x];
        FOR(mid, l + 1, r - 2) sub(dp[l][r], dp[l][mid] * g[r - mid - sum[r] + sum[mid]]);
    }
    int ans = 0;
    FOR(i, 1, n) FOR(j, i + 1, n) {
        //if((j - i + 1) % 2 == 0) cout << i << ' ' << j << ' ' << dp[i][j] << '\n';
        add(ans, dp[i][j] * g[n - k - (j - i + 1 - sum[j] + sum[i - 1])]);
    }
    cout << ans ;
}


Measured memory_bytes: 5888
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;

void solve() {
	cin >> N;
	ll res = 0;
	int a = 0, b = 0, c = 0;
	rep(i, 0, N) {
		string str; cin >> str;
		int n = sz(str);
		rep(i, 0, n - 1) {
			if(str[i] == 'A' && str[i + 1] == 'B') res++;
		}
		if(str[0] == 'B' && str[n - 1] == 'A') a++;
		else if(str[0] == 'B') b++;
		else if(str[n - 1] == 'A') c++;
	}
	debug(res, a, b, c);
	if(b || c) {
		cout << res + a + min(b, c) << "\n";
	}
	else {
		cout << res + max(a - 1, 0) << "\n";
	}
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



Measured memory_bytes: 256
package main

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

func main() {
	fsc := NewFastScanner()
	A, B := fsc.NextInt(), fsc.NextInt()
	C, D := fsc.NextInt(), fsc.NextInt()
	res := map[int]int{}
	for i := A; i < B; i++ {
		res[i]++
	}
	for i := C; i < D; i++ {
		res[i]++
	}
	result := 0
	for _, v := range res {
		if v >= 2 {
			result++
		}
	}
	fmt.Println(result)
}

//template
type FastScanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewFastScanner() *FastScanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1024)
	return &FastScanner{r: rdr}
}
func (s *FastScanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *FastScanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *FastScanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *FastScanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *FastScanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *FastScanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}

//Max,Min
func IntMax(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func Int64Max(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func Float64Max(a, b float64) float64 {
	if a < b {
		return b
	}
	return a
}

func IntMin(a, b int) int {
	if a > b {
		return b
	}
	return a
}

func Int64Min(a, b int64) int64 {
	if a > b {
		return b
	}
	return a
}
func Float64Min(a, b float64) float64 {
	if a > b {
		return b
	}
	return a
}

//Gcd
func IntGcd(a, b int) int {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return IntGcd(b, a%b)
}
func Int64Gcd(a, b int64) int64 {
	if a < b {
		b, a = a, b
	}
	if b == 0 {
		return a
	}
	return Int64Gcd(b, a%b)
}

func IntAbs(a int) int {
	if a < 0 {
		a *= -1
	}
	return a
}

func Int64Abs(a int64) int64 {
	if a < 0 {
		a *= -1
	}
	return a
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0,x;
  int a[LIMIT2]={0};
  char s[LIMIT1];
  
  scanf("%lld %lld",&x,&n);
  rep(i,n){
    scanf("%lld",&m);
    a[m]=1;
  }
  for(i=x;i>=0;i--){
    if(a[i]==0 && abs(x-result)>abs(x-i)) result = i;
  }
  for(i=x+1;i<=1000;i++){
    if(a[i]==0 && abs(x-result)>abs(x-i)) result = i;
  }
  printf("%lld\n",result);
  return 0;
}

Measured memory_bytes: 3688
import sys
from math import gcd

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def debug(res):
    tot = sum(res)
    for num in res:
        if gcd(tot - num, num) == 1:
            return False
    return True


def resolve():
    n = int(input())

    if n == 3:
        res = [2, 5, 63]
    elif n == 4:
        res = [2, 5, 20, 63]
    elif n == 5:
        res = [2, 5, 20, 30, 63]
    else:
        nums = [num for num in range(2, 30001) if num % 2 == 0 or num % 3 == 0]
        res = [nums[i] for i in range(n)]
        total = sum(res)
        if total % 6 == 2:
            res.pop(res.index(8))
            for i in range(n, len(nums)):
                if nums[i] % 6 == 0:
                    res.append(nums[i])
                    break
        elif total % 6 == 3:
            res.pop(res.index(9))
            for i in range(n, len(nums)):
                if nums[i] % 6 == 0:
                    res.append(nums[i])
                    break
        elif total % 6 == 5:
            res.pop(res.index(9))
            for i in range(n, len(nums)):
                if nums[i] % 6 == 4:
                    res.append(nums[i])
                    break
    print(*res)
    # print(debug(res))


if __name__ == '__main__':
    resolve()


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

using namespace std;

int main()
{
    int k;
    cin >> k;
    vector<int> v;
    v.push_back(1);

    for (int i = 1; i < k; ++i)
    {
        if (v.size() == 1 && v[0] < 9 ||
            v.size() > 1 && (v[0] < v[1] + 1 && v[0] < 9))
        {
            ++v[0];
        }
        else
        {
            int i;
            for (i = 1; i < v.size(); ++i)
            {
                if ((i == v.size() - 1) && v[i] < 9 ||
                    (i < v.size() - 1) && (v[i] < v[i + 1] + 1 && v[i] < 9))
                {
                    ++v[i];
                    for (int j = i - 1; j >= 0; --j)
                    {
                        v[j] = v[j + 1] - 1;
                        if (v[j] < 0) v[j] = 0;
                    }
                    break;
                }
            }
            if (i == v.size())
            {
                for (int j = 0; j < v.size(); ++j) { v[j] = 0; }
                v.push_back(1);
            }
        }
    }

    long long val = 0;
    long long mult = 1;
    for (int d : v)
    {
        val += mult * d;
        mult *= 10;
    }

    cout << val << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

ll d;
vector<ll> c(26);
vector<vector<ll>> s(365, vector<ll>(26));
vector<ll> t(365);

vector<ll> calc() {
  vector<ll> nsc(26);
  vector<ll> score(d);
  vector<ll> last(26, -1);
  rep(i, d) {
    last[t[i]] = i;
    rep(j, 26) {
      if (t[i] == j) nsc[j] += s[i][j];
      else nsc[j] -= c[j]*(i-last[j]);
    }
    ll sum = 0;
    rep(j, 26) sum += nsc[j];
    score[i] = sum;
  }
  return score;
}

int main()
{
  srand((unsigned)time(NULL));

  cin>>d;
  rep(i, 26) cin>>c[i];
  rep(i, d) rep(j, 26) cin>>s[i][j];

  rep(i, d) {
    ll tmp = 0;
    ll ma = -inf;
    rep(j, 26) {
      if (s[i][j] > ma) {
        ma = s[i][j];
        tmp = j;
      } else if (s[i][j] == ma) {
        if (c[j] < c[tmp]) {
          tmp = j;
        }
      }
    }
    t[i] = tmp;
  }
  vector<ll> fsc = calc();

  {
    vector<ll> last(26, -1);
    vector<ll> nsc(26);
    rep(i, d) {
      ll idx = 0;
      ll sum = 0;
      rep(j, 26) {
        nsc[j] -= c[j]*(i-last[j]);
        sum += nsc[j];
      }
      rep(j, 26) {
        ll aa = sum + c[j]*(i-last[j]) + s[i][j];
        ll bb = sum + c[idx]*(i-last[idx]) + s[i][idx];
        if (aa > bb && aa >= fsc[i]) {
          idx = j;
        }
      }
      nsc[idx] += c[idx]*(i-last[idx]) + s[i][idx];
      last[idx] = i;
      t[i] = idx;
    }
  }
  vector<ll> ssc = calc();

  vector<vector<bool>> flg(d, vector<bool>(26, true));
  rep(i, d) {
    vector<pair<ll, ll>> p(26);
    rep(j, 26) {
      p[j] = make_pair(j, c[j]*s[i][j]);
    }
    sort(p.begin(),p.end());
    rep(j, 5) {
      flg[i][p[j].first] = false;
    }
  }

  int ti = clock();
  while (clock() - ti < 195 * CLOCKS_PER_SEC / 100) {
    ll nd = rand() % d;
    ll nx = rand() % 26;
    if (!flg[nd][nx]) continue;
    ll px = t[nd];
    t[nd] = nx;
    vector<ll> tsc = calc();
    if (ssc[d-1] < tsc[d-1]) {
      ssc = tsc;
    } else {
      t[nd] = px;
    }
  }

  rep(i, d) cout << t[i]+1 << endl;

  return 0;
}


Measured memory_bytes: 3784
#include "bits/stdc++.h"
using namespace std;
#define INF 1000000000
#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> Vl;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T>  // chmax(max, a);
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> //chmin(min,a)
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}


int main(){
    ll b,c,x,y,n,m,h,k,max=-10000000,min=1000000000,ans=0,sum=0;
    string s,t;
    cin >> n >> m;
    cout << abs(n*m - (m*2+(n-2)*2)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>

#define INF (1ll<<60)
#define MOD 1000000007
#define BOUND 27182818284

typedef long long ll;
typedef long long int lli;

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

template<class T>bool umax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool umin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

using namespace std;

// gcd
int gcd(int a, int b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}
// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);

    return result;
}

// sort big to small
// sort(A,A+N, greater<int>());

// v.front() = -BOUND;
// v.back() = BOUND;

// Iterator
// v.begin
// v.end
class Itinerary {
public:
    long long x;
    long long  y;
    long long time;

    Itinerary(long long in_time, long long in_x, long long in_y) {
        x = in_x;
        y = in_y;
        time = in_time;
    }
};

int main() {
    long long N;
    string ans = "Yes";
    cin >> N;
    vector<Itinerary> itinerary;

    itinerary.emplace_back(Itinerary(0, 0, 0));
    for (int i = 1; i < N + 1; i++) {
        long long time, x, y;
        cin >> time >> x >> y;
        itinerary.emplace_back(Itinerary(time, x, y));
    }

    for(int i=1; i<=N; i++){
        long long time_diff = itinerary[i].time-itinerary[i-1].time;
        long long distance = abs(itinerary[i].x-itinerary[i-1].x)
                       +abs(itinerary[i].y-itinerary[i-1].y);
        if(time_diff >= distance && (time_diff-distance)%2 == 0){
            ;
        }else{
            ans = "No";
        }
    }

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



Measured memory_bytes: 4724
n = int(input())
s = ['']*n
for i in range(n):
    st = list(input())
    st.sort()
    s[i] = st
s.sort()


ans = 0
cnt = 0
for i in range(1,n):
    if s[i-1] == s[i]:
        cnt += 1
    else:
        ans += cnt*(cnt+1)//2
        cnt = 0
ans += cnt*(cnt+1)//2
print(ans)

Measured memory_bytes: 26520
//package compilers;

import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int sum=in.nextInt();
		int dp[]  = new int[sum+1];
		int arr[]= new int[n];
		dp[0] = 1; // dp[i] is optimal anwser for that i
		Arrays.fill(dp,1);
		for(int i=0;i<n;i++)
			arr[i] = in.nextInt();
		
		for(int i = 1;i<=sum;i++) {
			for(int j=0;j<n;j++) {
				if(i- arr[j] >= 0 && dp[i-arr[j]]==1) {
					dp[i]=0;
					break;
				}
			}
		}
	   if(dp[sum]==0)
		   System.out.println("First");
	   else System.out.println("Second");
	}

}


Measured memory_bytes: 21972
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 200005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int n,k,a[MAXN];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    for(int i=1;i<=n;i++) a[i]-=i;
    sort(a+1,a+n+1);
    ll ans=0;
    for(int i=n/2+1;i<=n;i++) ans+=a[i]-a[n+1-i];
    printf("%lld\n",ans);
    return 0;
}



Measured memory_bytes: 1024
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    n = int(input())
    s_table = [0]*3
    ans = 0
    for i in range(n):
        s = input()
        ans += s.count('AB')
        if s[0] == 'B' and s[-1] == 'A':
            s_table[0] += 1
        elif s[0] == 'B' and s[-1] != 'A':
            s_table[1] += 1
        elif s[0] != 'B' and s[-1] == 'A':
            s_table[2] += 1
    
    if s_table[0] == 0:
        ans += min(s_table[1:])
    elif sum(s_table[1:]) > 0:
        ans += s_table[0]+min(s_table[1:])
    else:
        ans += s_table[0]-1
    print(ans)
        
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 9220
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
  int H, W, K; cin >> H >> W >> K;
  vector<string> m(H);
  for (int i = 0; i < H; i++) {
    cin >> m[i];
  }
  int cnt1 = 0;
  for (int bit1 = 0; bit1 < (1<<H); bit1++) {
    vector<int> S1;
    for (int i = 0; i < H; i++) {
      if (bit1 & (1 << i)) S1.push_back(i);
    }
    for (int bit2 = 0; bit2 < (1<<W); bit2++) {
      vector<int> S2;
      for (int j = 0; j < W; j++) {
        if (bit2 & (1 << j)) S2.push_back(j);
      }
      int cnt2 = 0;
      for (auto it1 = S1.begin(); it1 != S1.end(); it1++) {
        for (auto it2 = S2.begin(); it2 != S2.end(); it2++) {
          if (m[*it1][*it2] == '#') cnt2++;
        }
      }
      if (cnt2 == K) cnt1++;
    }
  }
  cout << cnt1 << endl;
  return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			String a = sc.nextLine();
			String b = sc.nextLine();
			String c = sc.nextLine();

			StringBuilder sba = new StringBuilder(a);
			StringBuilder sbb = new StringBuilder(b);
			StringBuilder sbc = new StringBuilder(c);

			char next = sba.charAt(0);
			sba.deleteCharAt(0);
			while (true) {
				switch (next) {
				case 'a' :
					if (sba.length() == 0) {
						System.out.println("A");
						return;
					}
					next = sba.charAt(0);
					sba.deleteCharAt(0);
					break;
				case 'b' :
					if (sbb.length() == 0) {
						System.out.println("B");
						return;
					}
					next = sbb.charAt(0);
					sbb.deleteCharAt(0);
					break;
				case 'c' :
					if (sbc.length() == 0) {
						System.out.println("C");
						return;
					}
					next = sbc.charAt(0);
					sbc.deleteCharAt(0);
					break;
				}
			}

		} finally {
			sc.close();
		}
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <algorithm>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    int n;
    cin >> n;
    vector<int> vec(n);
    rep(i,n){
        cin >> vec[i];
    }
    sort(vec.begin(),vec.end(),greater<int>());
    int ans = vec[0]/2;

    reps(i,1,n){
        ans += vec[i];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.Scanner;
import java.math.BigInteger;

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

    static class TaskD {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();
            long[] xs = new long[n];
            long[] ys = new long[m];
            for (int i = 0; i < n; i++) {
                xs[i] = in.nextLong();
            }
            for (int i = 0; i < m; i++) {
                ys[i] = in.nextLong();
            }
            long x = 0L;
            for (int k = 1; k <= n; k++) {
                x += (k - 1) * xs[k - 1] - (n - k) * xs[k - 1];
            }
            long y = 0L;
            for (int k = 1; k <= m; k++) {
                y += (k - 1) * ys[k - 1] - (m - k) * ys[k - 1];
            }
            System.out.println(new BigInteger(String.valueOf(x))
                    .multiply(new BigInteger(String.valueOf(y)))
                    .remainder(new BigInteger(String.valueOf("1000000007"))));
        }

    }
}



Measured memory_bytes: 92200
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8, f8

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit((numba.types.optional(i8), ) * 2, cache=True)
def seg_f(x, y):
    if x is None:
        return y
    if y is None:
        return x
    return max(x, y)


@njit((i8[:], ), cache=True)
def build(raw_data):
    N = len(raw_data)
    seg = np.empty(N + N, np.int64)
    seg[N:] = raw_data
    for i in range(N - 1, 0, -1):
        seg[i] = seg_f(seg[i << 1], seg[i << 1 | 1])
    return seg


@njit((i8[:], i8, i8), cache=True)
def set_val(seg, i, x):
    N = len(seg) // 2
    i += N
    seg[i] = x
    while i > 1:
        i >>= 1
        seg[i] = seg_f(seg[i << 1], seg[i << 1 | 1])


@njit((i8[:], i8, i8), cache=True)
def fold(seg, l, r):
    vl = vr = None
    N = len(seg) // 2
    l, r = l + N, r + N
    while l < r:
        if l & 1:
            vl = seg_f(vl, seg[l])
            l += 1
        if r & 1:
            r -= 1
            vr = seg_f(seg[r], vr)
        l, r = l >> 1, r >> 1
    return seg_f(vl, vr)


@njit((i8[:], i8, i8), cache=True)
def max_right(seg, l, x):
    """[l,r) が ok であるような最大の r を返す"""
    N = len(seg) // 2

    def is_ok(v):
        return v < x

    v = None
    i, node_l, node_w = l + N, l, 1
    while True:
        if not (i & 1):
            i >>= 1
            node_w <<= 1
            continue
        if node_l + node_w > N:
            break
        v1 = seg_f(v, seg[i])
        if is_ok(v1):
            v, i = v1, (i + 1) >> 1
            node_l, node_w = node_l + node_w, node_w << 1
        else:
            break
    # 奇数セルに居て、とりきれないことが分かっている。偶数をとっていく
    i, node_w = i << 1, node_w >> 1
    while node_w:
        if node_l + node_w > N:
            i, node_w = i << 1, node_w >> 1
            continue
        v1 = seg_f(v, seg[i])
        if is_ok(v1):
            v, i = v1, (i + 1) << 1
            node_l, node_w = node_l + node_w, node_w >> 1
        else:
            i, node_w = i << 1, node_w >> 1
    i >>= 1
    return i - N

@njit((i8, i8[:]), cache=True)
def main(K, A):
    MAX = 300_010
    seg = np.zeros(2 * MAX, np.int64)
    for x in A:
        l, r = max(0, x - K), min(MAX, x + K + 1)
        n = fold(seg, l, r) + 1
        set_val(seg, x, n)
    return fold(seg, 0, MAX)

N, K = map(int, readline().split())
A = np.array(read().split(), np.int64)

print(main(K, A))

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

int n,m,k;
int ans;

int main(void)
{
    //input
    cin >> n >> m;
    vector< vector<int> > vec(m);

    for(int i=0; i<m; ++i){
        cin >> k;
        vec[i].resize(k);
        for(int j=0; j<k; ++j){
            cin >> vec[i][j];
            --vec[i][j];
        }
    }
    vector<int> p(m);
    for(int i=0; i<m; ++i) cin >> p[i];

    //calculate
    for(int bit=0; bit < (1<<n); ++bit){ //パターン全列挙
        bool flag = true;

        for (int i = 0; i < m; ++i) {
            int count=0;
            
            for(auto j : vec[i]){
			    if ((bit >> j) & 1) ++count; 
            }
            count %= 2;

            if(count != p[i]) flag = false;
        }
        if(flag) ans++;
    }

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

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



int main(){
    int A,B,C,X;
    cin >> A >> B >> C >> X;
    int money = 0;
    int count = 0;

    for(int i=0;i<=A;i++){
        for(int j=0;j<=B;j++){
            for(int k=0;k<=C;k++){
                money = 500*i+100*j+50*k;
                if(money == X){
                    count++;
                    continue;
                }
                if(money > X){
                    continue;
                }                 
            }
            if(100*j > X){
                continue;
            }
        }
        if(500*i > X){
            break;
        }
    }

    cout << count << endl;

}

Measured memory_bytes: 384
#include <iostream>

int main() {
    std::string s{}, p{};
    std::cin >> s >> p;
    bool can_make{false};
    const size_t sl{s.length()}, pl{p.length()};
    for(auto i=0; i<sl; i++) {
        size_t shortlen{ (sl-i)<pl ? (pl-(sl-i)) : 0 };
        if((s.substr(i,pl) + s.substr(0,shortlen))==p) {
            can_make = true;
            break;
        }
    }
    std::cout << (can_make ? "Yes" : "No") << std::endl;
}



Measured memory_bytes: 3224
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;


public class Main {
    public static void main(String[] args) {

    	try{
    		InputStreamReader isr = new InputStreamReader(System.in);
			BufferedReader br = new BufferedReader(isr);
			String buf = br.readLine();
			StringTokenizer st=new StringTokenizer(buf," ");
	    	int a = Integer.parseInt(st.nextToken());
	    	int b = Integer.parseInt(st.nextToken());

	    	if( 1<=a && a<=Math.pow(10, 9) && 1<=b && b<=Math.pow(10, 9) )
	    		System.out.print(a/b+" "+a%b);
	    		System.out.printf(" %f\n",(double)a/b);

    	} catch(IOException e) {
    		System.err.println(e);
		}
    }
}

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

int factorial(int n) {
  int sum = 1;
  for (int i = 1; i <= n; i++) {
    sum *= i;
  }
  return sum;
}

int main() {
  int N;
  scanf("%d", &N);
  vector<pair<int, int>> P(N);
  for (int i = 0; i < N; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    P.at(i) = make_pair(x, y);
  }

  vector<int> v(N);
  iota(v.begin(), v.end(), 1);

  double sum = 0;
  do {
    for (int i = 0; i < N - 1; i++) {
      sum += sqrt(pow(P.at(v.at(i) - 1).first - P.at(v.at(i + 1) - 1).first, 2) + 
                  pow(P.at(v.at(i) - 1).second - P.at(v.at(i + 1) - 1).second, 2));
    }
  } while (next_permutation(v.begin(), v.end()));

  printf("%.16f", sum / factorial(N));
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

int64_t f(int64_t n, int64_t a, int64_t b) {
    if (n == 1 && a == b) return 1;
    if (a > b) return 0;
    if (n < 2) return 0;
    return (b - a) * (n - 2) + 1;
}

int main() {
    int64_t n, a, b; std::cin >> n >> a >> b;
    std::cout << f(n, a, b) << std::endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int n,t,i;
  long ans=0;
  long timer=0;
  scanf("%d %d",&n,&t);
  long str[n];
  scanf("%ld",&str[0]);

  for(i=0;i<n-1;i++){
    scanf("%ld",&str[i]);
  	if(timer + t >str[i] ){
    	ans=ans+ (long)(str[i]- timer);
      	timer=str[i];
    }else{
      timer=str[i];
      ans+=(long)t;
    }
   
   // printf("%d   ",ans);
  }
   ans+=t;
  printf("%ld\n",ans);
return 0;
}


Measured memory_bytes: 1664
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define Rep(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SMALLPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const int inf=1000000007;
const int mod=1000000007;
void chmin(auto &a,auto b){if(b<a)a=b;}
void chmax(auto &a,auto b){if(a<b)a=b;}
int main(){
  string s;cin>>s;
  int n=s.size();
  vvi dp(n,vi(13));
  if(s[0]=='?')rep(i,10)dp[0][i]++;
  else dp[0][s[0]-'0']++;
  Rep(i,1,n){
    if(s[i]=='?'){
      rep(j,13){
        rep(k,10){
          dp[i][(j*10+k)%13]+=dp[i-1][j];
          dp[i][(j*10+k)%13]%=mod;
        }
      }
    }
    else{
      rep(j,13){
        dp[i][((s[i]-'0'+10*j))%13]+=dp[i-1][j];
        dp[i][((s[i]-'0'+10*j))%13]%=mod;
      }
    }
  }
  cout<<(dp[n-1][5])%mod<<endl;
}


Measured memory_bytes: 16768
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<i64>();
    let (a, b) = (v[0], v[1]);
    let mut n = gcd(a, b);

    let mut root_n = 1;
    while root_n * root_n <= n {
        root_n += 1;
    }
    let primes = get_primes(root_n as usize + 2);
    debug!(primes);

    let mut factors = vec![];
    for &p in primes.iter() {
        while n % p as i64 == 0 {
            factors.push(p as i64);
            n /= p as i64;
        }
    }

    if n != 1 {
        factors.push(n);
    }
    factors.push(1);
    debug!(factors);
    let s = factors.iter().collect::<HashSet<_>>();

    println!("{}", s.len());
}

fn get_primes(n: usize) -> Vec<usize> {
    let mut is_prime = vec![true; n + 1];
    let mut primes = Vec::new();
    is_prime[0] = false;
    is_prime[1] = false;

    for i in 2..n + 1 {
        if is_prime[i] {
            primes.push(i);
            let mut j = 2 * i;
            while j < n {
                is_prime[j] = false;
                j += i;
            }
        }
    }
    primes
}

fn factorize(mut num: usize, primes: &Vec<usize>) -> std::collections::HashMap<usize, usize> {
    // max_primes >= (num)^(1/2)
    let mut dict = std::collections::HashMap::new();
    for &p in primes.iter() {
        while num % p == 0 {
            *dict.entry(p).or_insert(0) += 1usize;
            num /= p;
        }
        if num == 1 {
            break;
        }
    }
    if num != 1 {
        dict.insert(num, 1);
    }
    dict
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

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

fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        return a;
    }
    gcd(b, a % b)
}


Measured memory_bytes: 6396
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
vector<string> grid;
static const int dx[4] = {0,1,0,-1};
static const int dy[4] = {1,0,-1,0,};
void um(int x, int y){
  grid[y][x] = '0';
  REP(r,4) if(y+dy[r]>=0&&y+dy[r]<12&&x+dx[r]>=0&&x+dx[r]<12&&grid[y+dy[r]][x+dx[r]]=='1'){
    um(x+dx[r], y+dy[r]);
  }
}
int main(void){
  string line;
  while(cin>>line){
    grid.clear();
    grid.push_back(line);
    REP(i,11){
      cin>>line;
      grid.push_back(line);
    }
    int ans = 0; 
    REP(y,12)REP(x,12){
        if(grid[y][x]=='1'){
          ans++;
          um(x,y);
        }
    }
    cout<<ans<<endl;
  }
  return 0;
}

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


int main(){
  int i;
  char s[100];
  int x[100];
  for(i=0;i<100;i++){
    x[i]=0;
  }
  i=0;
  while(scanf("%s",s)!=EOF){
    if(s[0]=='+'){
      x[i-2]=x[i-1]+x[i-2];
      i--;
    }else if(s[0]=='-'){
      x[i-2]=x[i-2]-x[i-1];
      i--;
    }else if(s[0]=='*'){
      x[i-2]=x[i-1]*x[i-2];
      i--;
    }else{
      x[i]=atoi(s);
      i++;
    }
  }
  printf("%d\n",x[i-1]);

  return 0;
}

Measured memory_bytes: 1812
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 

ll a[300005];

int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m,mx=0;

	cin >> n >> k;
	for(i=1;i<=n;i++)
	{
		cin >> a[i];
		mx=max(mx,a[i]);
	}

	ll lo=1,hi=mx,md,prev=-1;

	while(lo<=hi)
	{
		md=(lo+hi)/2;
		x=0;
		if(md==prev)
			break;
		prev=md;
		for(i=1;i<=n;i++)
		{
			ll cut=a[i]/md;
			if(a[i]%md)
				cut++;
			x+=cut-1;
		}
		if(x<=k)
			hi=md;
		else
			lo=md+1;
	}

	cout<<hi<<endl;
}

Measured memory_bytes: 5152
import java.util.Scanner;
class Main {
	int[][][] t = new int [5][5][11];
	int n = 0, b = 0, f = 0, r = 0, v = 0, i = 0, k = 0;
	public void of() {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		for(i = 1; i <= n; i++) {
			b = sc.nextInt();
			f = sc.nextInt();
			r = sc.nextInt();
			v = sc.nextInt();
					t[b][f][r] += v;
		}
		for(n = 1; n <= 4; n++) {
			for(i = 1; i < 4; i++) {
				for(k = 1; k < 11; k++) {
							System.out.printf(" %d",t[n][i][k]);
				}
				System.out.println();
			}
			if(n < 4) {
				System.out.println("####################");
			}
		}
	}
	public static void main(String[] args) {
		new Main().of();
	}
}

Measured memory_bytes: 23212
#include <bits/stdc++.h>
 
typedef long long ll;

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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;

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

const double PI=3.14159265358979323846;


void Main() {
    ll r;

    cin >> r;
    COUT(2 * PI * r);
}

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



Measured memory_bytes: 3804
/*
Author: CNYALI_LK
LANG: C++
PROG: c.cpp
Mail: cnyalilk@vip.qq.com
*/
#include<bits/stdc++.h>
#define debug(...) fprintf(stderr,__VA_ARGS__)
#define DEBUG printf("Passing [%s] in LINE %lld\n",__FUNCTION__,__LINE__)
#define Debug debug("Passing [%s] in LINE %lld\n",__FUNCTION__,__LINE__)
#define all(x) x.begin(),x.end()
#define x first
#define y second
using namespace std;
const double eps=1e-8;
const double pi=acos(-1.0);
typedef long long ll;
typedef pair<ll,ll> pii;
template<class T>ll chkmin(T &a,T b){return a>b?a=b,1:0;}
template<class T>ll chkmax(T &a,T b){return a<b?a=b,1:0;}
template<class T>T sqr(T a){return a*a;}
template<class T>T mmin(T a,T b){return a<b?a:b;}
template<class T>T mmax(T a,T b){return a>b?a:b;}
template<class T>T aabs(T a){return a<0?-a:a;}
#define min mmin
#define max mmax
#define abs aabs
ll read(){
	ll s=0,base=1;
	char c;
	while(!isdigit(c=getchar()))if(c=='-')base=-base;
	while(isdigit(c)){s=s*10+(c^48);c=getchar();}
	return s*base;
}
ll a[202424];
int main(){
#ifdef cnyali_lk
	freopen("c.in","r",stdin);
	freopen("c.out","w",stdout);
#endif
	ll n;
	n=read();
	for(ll i=1;i<=n;++i)a[i]=read()-i;
	sort(a+1,a+n+1);
	ll s=(n+1)>>1,ans=0;
	for(ll i=1;i<=n;++i)ans+=abs(a[i]-a[s]);
	printf("%lld\n",ans);
	
	return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
int main()
{
  string s;
  int K;
  cin >> s >> K;
  set<string> st;
  for (int i = 0; i < s.length(); i++)
  {
    for (int j = 1; j <= K; j++)
    {
      st.insert(s.substr(i, min(j, (int)s.length() - i)));
    }
  }
  int idx = 1;
  for (auto s : st)
  {
    if (idx == K)
    {
      cout << s << endl;
      return 0;
    }
    idx++;
  }
  return 0;
}

Measured memory_bytes: 1664
#include<iostream>

using namespace std;

int main() {
    int N, result = 0;
    char s, previous;
    bool big = false;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> s;

        if (i == 0 || s != previous) {
            ++result;
        }

        previous = s;
    }

    cout << result;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>

using namespace std;



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

	int n;
	cin >> n;

	cout << 2 * n - 1 << "\n";

	int x;
	cin >> x;

	auto min_elem = x, max_elem = x;
	int min_index = 0, max_index = 0;

	for (int i = 1; i < n; ++i) {
		cin >> x;
		min_elem = min(min_elem, x);
		max_elem = max(max_elem, x);
		if (min_elem == x) min_index = i;
		if (max_elem == x) max_index = i;
	}

	if (abs(max_elem) >= abs(min_elem)) {
		for (int i = 0; i < n; ++i)
			if (max_index != i)
				cout << max_index + 1 << " " << i + 1 << "\n";
		cout << max_index + 1 << " " << max_index + 1 << "\n";

		for (int i = 0; i < n - 1; ++i)
			cout << i + 1 << " " << i + 2 << "\n";
	}
	else {
		for (int i = 0; i < n; ++i)
			if (min_index != i)
				cout << min_index + 1 << " " << i + 1 << "\n";
		cout << min_index + 1 << " " << min_index + 1 << "\n";

		for (int i = n - 1; i > 0; --i)
			cout << i + 1 << " " << i << "\n";
	}

	//system("pause");

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
using ll = long long;
using ull = unsigned long long;

int main(void)
{
    IOS
    int n,a,b;
    cin >> n >> a >>b;

    int ans = n * a < b ? n*a : b;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N = int(input())
W = list(map(int, input().split()))
D = 9999999999999999999
for n in range(2,N) :
    S1 = sum(W[0:n])
    S2 = sum(W[n:N])
    #print(S1)
    #print(S2)
    d = abs(S1 - S2)
    if D > d :
        D = d
print(D)

Measured memory_bytes: 2940
use std::io;

fn procon_read<T: std::str::FromStr>() ->  Vec<T> {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let iter = buf.split_whitespace();
	let mut v: Vec<T> = Vec::new();
	for i in iter {
		v.push(i.parse().ok().unwrap());
	}
	v
}

fn main() {
	let v:Vec<i32> = procon_read();
	let n = v[0];
	let up4 = n/4;
	let up7 = n/7;
	let mut flag = false;
	for i in 0..(up4+1) {
		for j in 0..(up7+1) {
			if 4*i + 7*j == n {
				flag = true;
				break;
			}
		}
		if flag {
			break;
		}
	}
	if flag {
		println!("Yes");
	}else{
		println!("No");
	}
}

Measured memory_bytes: 4352