akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> anys;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(anys{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

ll INF = 1e18;
int main(){
	int N;
	cin >> N;
	vector<ll> A(N);
	for(int i=0; i<N; i++) cin >> A[i];

	vector<vector<ll>> dp(N+1, vector<ll>(6));
	dp[0][0] = -INF;
	dp[0][1] = 0;
	dp[0][2] = -INF;
	dp[0][3] = -INF;
	dp[0][4] = -INF;
	dp[0][5] = -INF;

	for(int i=1; i<=N; i++){
		if(i%2){
			dp[i][0] = max(dp[i-1][0], dp[i-1][3]);
			dp[i][1] = max(dp[i-1][1], dp[i-1][4]);
			dp[i][2] = max(dp[i-1][2], dp[i-1][5]);
			dp[i][3] = -INF;
			dp[i][4] = A[i-1] + dp[i-1][0];
			dp[i][5] = A[i-1] + dp[i-1][1];
		} else {
			dp[i][0] = max(dp[i-1][1], dp[i-1][4]);
			dp[i][1] = max(dp[i-1][2], dp[i-1][5]);
			dp[i][2] = -INF;
			dp[i][3] = A[i-1] + dp[i-1][0];
			dp[i][4] = A[i-1] + dp[i-1][1];
			dp[i][5] = A[i-1] + dp[i-1][2];
		}
		debug(i, dp[i][0], dp[i][1], dp[i][2], dp[i][3], dp[i][4], dp[i][5]);
	}

	cout << max(dp[N][1], dp[N][4]) << endl;

	return 0;
}


Measured memory_bytes: 22004
H, W = map(int, input().split())
Ch, Cw = map(int, input().split())
Dh, Dw = map(int, input().split())
S = [list(input()) for _ in range(H)]

num = 0
if S[0][0] == '#':
    S[0][0] = -1
else:
    num += 1
    S[0][0] = num

for i in range(1, H):
    if S[i][0] == '#':
        S[i][0] = -1
    elif S[i-1][0] > 0:
        S[i][0] = S[i-1][0]
    else:
        num += 1
        S[i][0] = num

for j in range(1, W):
    if S[0][j] == '#':
        S[0][j] = -1
    elif S[0][j-1] > 0:
        S[0][j] = S[0][j-1]
    else:
        num += 1
        S[0][j] = num

for i in range(1, H):
    for j in range(1, W):
        if S[i][j] == '#':
            S[i][j] = -1
        elif S[i-1][j] < 0 and S[i][j-1] < 0:
            num += 1
            S[i][j] = num
        elif S[i-1][j] < 0:
            S[i][j] = S[i][j-1]
        elif S[i][j-1] < 0:
            S[i][j] = S[i-1][j]
        else:
            S[i][j-1] = min(S[i-1][j], S[i][j-1])
            S[i-1][j] = min(S[i-1][j], S[i][j-1])
            S[i][j] = min(S[i-1][j], S[i][j-1])

G = [{} for _ in range(num)]

for i in range(H):
    for j in range(W):
        if S[i][j] == -1:
            continue

        start_i = max(0, i-2)
        start_j = max(0, j-2)
        end_i = min(H, i+3)
        end_j = min(W, j+3)
        for x in range(start_i, end_i):
            for y in range(start_j, end_j):
                if S[x][y] > 0 and S[x][y] != S[i][j]:
                    G[S[x][y]-1][S[i][j]-1] = 1
                    G[S[i][j]-1][S[x][y]-1] = 1

for i in range(H):
    for j in range(W):
        if S[i][j] == -1:
            continue

        start_i = max(0, i-2)
        start_j = max(0, j-2)
        end_i = min(H, i+3)
        end_j = min(W, j+3)
        for x in range(start_i, end_i):
            for y in range(start_j, end_j):
                if (x, y) in [(i-1, j), (i, j-1), (i+1, j), (i, j+1)]:
                    if S[x][y] > 0 and S[x][y] != S[i][j]:
                        G[S[x][y]-1][S[i][j]-1] = 0
                        G[S[i][j]-1][S[x][y]-1] = 0

from heapq import heapify, heappop, heappush
def dijkstra(s):
    dist = [float('inf')] * num
    dist[s] = 0

    heap = [(s, 0)]
    heapify(heap)
    while heap:
        v, c = heappop(heap)
        if c > dist[v]: continue
        for u, d in G[v].items():
            tmp = d + dist[v]
            if tmp < dist[u]:
                dist[u] = tmp
                heappush(heap, (u, tmp))

    return dist

start = S[Ch-1][Cw-1]-1
end = S[Dh-1][Dw-1]-1
dist = dijkstra(start)

ans = -1 if dist[end] == float('inf') else dist[end]
print(ans)

Measured memory_bytes: 187292
import itertools
import math
from functools import reduce
def gcd(numbers):
    return reduce(math.gcd, numbers)
N = int(input())
l = [i for i in range(1,N+1)]
h = itertools.combinations_with_replacement(l, 3)

result=0
for v in h:
    ans=gcd(v)
    i,j,k=zip(v)
    if (i==j)&(i==k):
        result += ans
    elif ((i==j)&(i!=k))|((i==k)&(i!=j))|((j==k)&(j!=i)):
        result += (ans*3)
    else:
        result += (ans*6)
    
print(result)

Measured memory_bytes: 9592
#[allow(unused_macros)]
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 ( 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 ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
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" ) } ; }

fn main() {
    input! {
        n: u64
    }
    println!("{}", 800*n - (n/15)*200);
}


Measured memory_bytes: 4352
#

import itertools
from collections import Counter
from collections import defaultdict
import bisect
from heapq import heappush, heappop

def main():
    N = int(input())

    edges = defaultdict(list)
    edges_l = []
    for _ in range(N-1):
        a, b = map(int, input().split())

        edges_l.append((a-1, b-1))
        edges[a-1].append(b-1)
        edges[b-1].append(a-1)

    C = list(map(int, input().split()))
    C.sort(reverse=True)
    # print(d)
    # print(C)
    used = [False] * N
    ans = [0] * N
    count = 0
    que = list()
    que.append(0)
    while que:
        index = que.pop()
        if not used[index]:
            # print('i = {}, Ci = {}'.format(i, C[i]))
            ans[index] = C[count]
            used[index] = True
            count += 1

        # print(edges[i])
        for nei in edges[index]:
            if not used[nei]:
                que.append(nei)

    val = 0
    for a, b in edges_l:
        node_val = min(ans[a], ans[b])
        val += node_val

    print(val)
    print(' '.join(map(str, ans)))


if __name__ == '__main__':
    main()


Measured memory_bytes: 53080
def main():
    one, two, three, four, five, six = map(lambda n: int(n), input().split(' '))
    d = Dice(one, two, three, four, five, six)
    s = input()
    for i in s:
        d.roll(i)
    print(d.top)

class Dice:
    def __init__(self, one, two, three, four, five, six):
        self.top = one
        self.bottom = six
        self.s = two
        self.n = five
        self.e = three
        self.w = four 
    

    def roll(self, d):
        top = self.top
        bottom = self.bottom
        s = self.s
        n = self.n
        e = self.e
        w = self.w
        if d == "S":
            self.bottom = s
            self.s = top
            self.top = n
            self.n = bottom
        elif d == "N":
            self.bottom = n
            self.s = bottom
            self.top = s
            self.n = top
        elif d == "W":
            self.bottom = w
            self.w = top
            self.top = e
            self.e = bottom
        else:
            self.bottom = e
            self.e = top
            self.top = w
            self.w = bottom
        

if __name__ == "__main__":
    main()


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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int n, k;
  cin >> n >> k;
  int ans;
  if(n%k==0) ans = 0;
  else ans = 1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

int H, W, N;
char c[1010][1010];
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
bool flag[1010][1010];

bool inrange(int i, int j) { return i >= 0 && i < H && j >= 0 && j < W; }

int bfs(int si, int sj, int gi, int gj) {
	using State = tuple<int, int, int>;
	queue<State> q;
	q.emplace(si, sj, 0);
	memset(flag, false, sizeof(flag));
	while (q.size()) {
		int ci, cj, cnt;
		tie(ci, cj, cnt) = q.front(); q.pop();
		if (!inrange(ci, cj))continue;
		if (ci == gi&&cj == gj)return cnt;
		if (flag[ci][cj])continue;
		flag[ci][cj] = true;
		if (c[ci][cj] == 'X')continue;
		rep(i, 0, 4) {
			int ni = ci + dy[i], nj = cj + dx[i];
			q.emplace(ni, nj, cnt + 1);
		}
	}
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> H >> W >> N;
	vector<tuple<int, int, int>> v;
	rep(i, 0, H)rep(j, 0, W) {
		cin >> c[i][j];
		if (c[i][j] == 'S') {
			v.emplace_back(0, i, j);
		}
		else if ('1' <= c[i][j] && c[i][j] <= '9') {
			v.emplace_back(c[i][j] - '0', i, j);
		}
	}
	sort(all(v));
	int ans = 0;
	rep(i, 0, v.size() - 1) {
		int ci, cj, ni, nj;
		tie(ignore, ci, cj) = v[i];
		tie(ignore, ni, nj) = v[i + 1];
		ans += bfs(ci, cj, ni, nj);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5080
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long
#define INF 1000000001

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  string s;cin>>s;
  int s_long=s.size();
  string ans=s[0]+to_string(s_long-2)+s[s_long-1];
  P(ans);
  return 0;
}


Measured memory_bytes: 256
// #include C/C++ {
#include <bits/stdc++.h>
// }
using namespace std;
// #typedef {
typedef long long int64;
typedef pair <int, int> PII;
typedef pair <int64, int64> PLL;
// }

// #parameter{
#ifdef _DEBUG

#define TYPE decltype
#define RF(filename) {freopen((filename), "r", stdin);}
#define WF(filename) {freopen((filename), "w", stdout);}
#define DF(filename) {freopen((filename), "w", stderr);}
#define eprintf printf

#else

#define TYPE __typeof
#define RF(filename) {;}
#define WF(filename) {;}
#define DF(filename) {;}
#define eprintf(...)
#define fprintf(...)

#endif

// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x)<<1)
#define R(x) ((x)<<1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;

#define MAX_N 200005
#define MAX_M 55
#define MOD (int)(1e9+7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }

/////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////
int main() {
	RF("input.txt");
	//  WF("output.txt");
	DF("err.txt");

	int N;
	scanf("%d", &N);

	printf("%d\n", (N - 2) * 180);
	return 0;
}

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

#define rep(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

// 事前に、X>=0,Y>=0 にしておく
// 1. X+Yが奇数 かつ Kが偶数
//    -1, どうやっても奇数番地にはたどり着けない
// 2. X+Y>K
//    n=ceil(X+Y/K)として、X+Y と nK の偶奇が異れば n++
//    余剰 nK-X-Y のために、冗長な経路を作る。
// 
//      t = (nK-X-Y)/2
//
//            +
//            |
//            | Y
//      +     |
//    t |     | t 
//      |-----|
//         X
// 
// 3. X+Y<K
// 3-1. X+Yが偶数, n=2となる
//      t = (2K-X-Y)/2
//
//            +
//            |
//            | Y
//      +     |
//    t |     | t 
//      |-----|
//         X
// 
// 3-1. X+Yが奇数（1より、Kも奇数）
//      n=3になる
//      これが難しい
//
//      2(t+p) = 3K-(X+Y), t=K-X, p=(K+X-Y)/2
//      pとtが正、かつ p,t < K となるように
//                       p
//                     +----+
//                          |
//                          | Y
//               +          |
//             t |          | t
//               |----------|
//                 X     p
// 4. X+Y==Kは自明

ll K,X,Y;
ll sign_x = 1, sign_y = 1;
bool swp = false;

void print(vector<PLL> ans) {
  cout<<ans.size()<<endl;

  rep(i,0,ans.size()){
    if (swp)
      swap(ans[i].first, ans[i].second);
    ans[i].first  *= sign_x;
    ans[i].second *= sign_y;
  }
  if (swp)
    swap(X,Y);
  if (sign_x) X*=sign_x;
  if (sign_y) Y*=sign_y;

  rep(i,0,ans.size()) cout<<ans[i].first<< " " << ans[i].second<<endl;

  assert(ans[ans.size()-1].first == X);
  assert(ans[ans.size()-1].second == Y);
  rep(i,0,ans.size()) if (i > 0) assert(abs(ans[i].first-ans[i-1].first) + abs(ans[i].second-ans[i-1].second) == K);
}

signed main() {
  cin>>K>>X>>Y;

  if (X<0) { X*=-1; sign_x = -1;}
  if (Y<0) { Y*=-1; sign_y = -1;}
  if (X<Y){
    swap(X,Y);
    swp=true;
  }

  if ((X+Y)%2==1 && K%2==0) {
    cout<<-1<<endl;
    return 0;
  }

  if (X+Y == K) {
    vector<PLL> ans;
    ans.push_back(PLL(X,Y));
    print(ans);
    return 0;
  }

  if (X+Y < K && (X+Y)%2 == 1) {
    ll p=(K+X-Y)/2;
    vector<PLL> ans;
    ans.push_back(PLL(X, -(K-X)));
    ans.push_back(PLL(X+p, Y-(K-p)));
    ans.push_back(PLL(X, Y));
    print(ans);
    return 0;
  }

  // 移動回数の決定
  ll n;
  if (X+Y < K && (X+Y)%2 == 0) {
    n = 2;
  } else {
    //ll c = (K -(X+Y % K)) %K;
    //if (c%2==0) {
    //  n = (X+Y +K-1) / K;
    //} else {
    //  n = (X+Y +K-1) / K + 1;
    //}
    n = (X+Y +K-1) / K;
    if ( (n*K)%2 != (X+Y)%2 )
      n++;
  }

  ll t = (n*K-X-Y)/2;
  vector<PLL> ans;
  for (ll i=0; i<n; i++){
    ll d = (i+1)*K;
    if (d<=t) {
      ans.push_back(PLL(0, -d));
    } else if (d<=X+t) {
      ans.push_back(PLL(d-t, -t));
    } else {
      ans.push_back(PLL(X, -t+(d-X-t)));
    }
  }
  print(ans);
  return 0;
}


Measured memory_bytes: 9452
#import <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vs = vector<string>;
#define  rep(i,n)  for(ll i = 0; i < (n); ++i)
#define  repp(i,n) for(ll i = 1; i <=(n); ++i)
#define  red(i,n)  for(ll i = (n)-1; i >= 0; --i)
#define  all(a)   begin(a),end(a)
#define  pb(a)    push_back(a)
#define  yn(a)    cout << ( (a)?"Yes\n":"No\n" )
inline ll gcd(ll a,ll b) { return b?gcd(b,a%b):a; }
ll INF = 1e9+9, LINF = 1e18;

int main(){
    ll n,ans=0; cin>>n;
    map<string,ll> a;
    string s;
    rep(i,n)cin>>s,sort(all(s)),a[s]++;
    for(auto x:a)ans+=x.second*(x.second-1)/2;
    cout<<ans<<endl;
}

Measured memory_bytes: 11136
package main

import (
	"fmt"
	"math"
)

func main() {
	var (
		n, t, a int
	)
	fmt.Scanf("%d\n%d %d\n", &n, &t, &a)
	a *= 1000
	t *= 1000
	h := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&h[i])
	}


	point := 0
	nearestDiff := math.MaxInt64
	for idx, x := range h {
		diff := a - (t - x * 6)
		if diff < 0 {
			diff = -diff
		}
		if diff < nearestDiff {
			point = idx + 1
			nearestDiff = diff
		}
	}
	fmt.Println(point)
}


Measured memory_bytes: 512
let prim a n =
  let min_costs = Array.make n max_int in
  min_costs.(0) <- 0;
  let reached_p = Array.make n false in
  let z = Array.make n (-1) in
  let rec doit () =
    let u =
      Array.fold_left (fun (i, m, u) p ->
        if not p && min_costs.(i) < m then (i + 1, min_costs.(i), i)
        else (i + 1, m, u))
        (0, max_int, (-1)) reached_p
      |> (fun (_, _, u) -> u) in
    if u = (-1) then ()
    else begin
      reached_p.(u) <- true;
      Array.iteri (fun j p ->
        if a.(u).(j) <> (-1) && not p && min_costs.(j) > a.(u).(j) then begin
          min_costs.(j) <- a.(u).(j);
          z.(j) <- u;
        end) reached_p;
      doit ()
    end in
  doit ();
  Array.fold_left (fun (i, sum) j ->
    (i + 1, if j = (-1) then sum else sum + a.(j).(i)))
    (0, 0) z
  |> snd

let () =
  let n = read_int () in
  let a = Array.make_matrix n n 0 in
  for i = 0 to n - 1 do
    for j = 0 to n - 1 do
      a.(i).(j) <- Scanf.scanf " %d" (fun x -> x);
    done
  done;
  prim a n |> Printf.printf "%d\n"

Measured memory_bytes: 4592
#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            line.pop();
            line
        }
    )
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let iter = line.split_whitespace();
            iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
        }
    )
}

fn solve(k: usize, xys: Vec<(i64, i64)>) -> i64 {
    use std::cmp::{min, max};

    let xs = xys.iter().map(|&(x,y)| x).collect::<Vec<i64>>();
    let ys = xys.iter().map(|&(x,y)| y).collect::<Vec<i64>>();

    let mut min_area = std::i64::MAX;

    for &x1 in xs.iter() {
        for &x2 in xs.iter() {
            for &y1 in ys.iter() {
                for &y2 in ys.iter() {
                    let xmin = min(x1, x2);
                    let xmax = max(x1, x2);
                    let ymin = min(y1, y2);
                    let ymax = max(y1, y2);

                    let cnt = xys.iter().filter(|&&(x, y)|
                                                xmin <= x && x <= xmax &&
                                                ymin <= y && y <= ymax
                    ).count();

                    if cnt >= k {
                        let area = (xmax - xmin) * (ymax - ymin);
                        if area < min_area {
                            min_area = area;
                        }
                    }
                }
            }
        }
    }

    min_area
}

fn main() {
    let (n, k) = parse_line!(usize, usize);

    let xys = (0..n).map(|_|parse_line!(i64, i64)).collect();

    println!("{}", solve(k, xys));
}

#[test]
fn solve_test() {
    assert_eq!(solve(3, vec![(-1000000000, -1000000000),
                             (1000000000, 1000000000),
                             (-999999999, 999999999),
                             (999999999, -999999999)]), 3999999996000000001);
}


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

class Program
{
    static void Main(string[] args)
    {
        List<int> ABC = Console.ReadLine().Split(' ').Select(o => int.Parse(o)).ToList();
        int A = ABC[0], B = ABC[1], C = ABC[2];
        if ((A == B && A != C) ||
            (B == C && B != A) ||
            (C == A && C != B))
            Console.WriteLine("Yes");
        else
            Console.WriteLine("No");
    }
}

Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
int n, t;
long long a[1000020];
long long ans;
int main() {
	scanf("%d%d", &n, &t);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	sort(a, a + n);
	int back = a[0];
	int front = a[0] + t;
	for (int i = 0; i < n; i++) {
		if (a[i] <= front) {
			front = a[i] + t;
		} else {
			ans += front - back;
			back = a[i];
			front = a[i] + t;
		}
	}
	ans += front - back;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1792
import sys,math

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]


def main():
	n,a,b = MI()
	mod = 10 ** 9 + 7

	def f(n,r,mod):
		r = min(r,n-r)
		x = y = 1
		for i in range(r):
			x = (x*(n-i)) % mod
			y = (y*(i+1)) % mod
		return (x * pow(y, mod-2, mod)) % mod

	ans = (pow(2,n,mod) - f(n,a,mod) - f(n,b,mod) - 1)%mod
	ans += mod if ans < 0 else 0
	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}


int main(){
  ll N,K;cin>>N>>K;
  vector<ll> v(N);
  ll a=0;
  
  rep(i,N){
    cin>>v.at(i);
  }
  
  sort(v.begin(),v.end(),greater<ll>());
  if(K<N){
  Rep(i,K,N){
    a+=v.at(i);
  }
  }
  
  cout<<a<<endl;
}
  



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define P pair<ll,ll>
#define V vector<ll>

#define rep(i,n) for(ll i = 0; i < (n); i++)
#define repd(i,n) for(ll i = (n); i >= 0; i--)
#define FOR(i,t,n) for(ll i = (t); i < (n); i++)
#define FORD(i,t,n) for(ll i = (n); i >= t; i--)
#define ALL(x) x.begin(),x.end()
#define asort(x) sort(ALL(x))

int main() {
    int a;
    cin >> a;
    if(a%1000 == 0) cout << 0 << endl;
    else cout << 1000 - a % 1000 << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin >> n >> k;
  double ans=0;
  for(int i=1;i<=n;i++){
    double p = 1.0/n;
    int j=i;
    while(j<k){
      j *=2;
      p /=2;
    }
    ans +=p;
  }
  cout << fixed << setprecision(10) << ans << endl;
}


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

int main(){
  int N;
  cin >> N;
  int A[N];
  int x[N][N];
  int y[N][N];
  rep(i,N){cin >> A[i];
    rep(j,A[i]) cin >> x[i][j] >> y[i][j];
  }
  
  int ans = 0;
  //bit全探索　それぞれの人が正直者か不誠実の全パターン2^N通りについて、正直者の発言が矛盾していないか調べる
  for(int bit = 0;bit<(1<<N);bit++){
    bool ok = true;
    for(int i = 0;i < N; i++){
      if((bit&(1<<i))){ //正直者iの発言のみチェック
        //cout << bit << ":"<< i << endl;
        for(int j = 0;j < A[i];j++){ //正直者iのj番目の発言、人x[i][j]はy[i][j]であるをチェック          
         //if(((bit&(1<<(x[i][j]-1)))^y[i][j]==1)) ok = false;
         if(!(bit&(1<<(x[i][j]-1)))&&y[i][j]==1) ok = false;
         else if( bit& (1<<(x[i][j]-1)) && y[i][j]==0)ok = false; //正直者i発言が矛盾しているとき、フラグをfalseにする                      
          }
        }
      }
    if(ok) ans = max(ans,__builtin_popcount(bit));
  }
  cout << ans <<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n,h[100],c=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    
    for(int i=0;i<200;i++){
        bool f=false;
        for(int j=0;j<n;j++){
            if(h[j]>i){
                f=true;
            }else if(f){
                f=false;
                c++;
            }
        }
        if(f)c++;
    }
    cout<<c<<endl;
}


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

int main() {
  int x;
  cin >> x;
  cout << (x == 0 ? "1" : "0") << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++)
        cin>>a[i];
    int c=0;
    for(int i=0; i<n; i++){
        for(int j=i+1; j<n; j++){
            for(int k=j+1; k<n; k++){
                if(a[i]!=a[j] && a[j]!=a[k] && a[i]!=a[k]){
                    if(a[i]+a[j]>a[k] && a[i]+a[k]>a[j] && a[k]+a[j]>a[i])c++;
                }
            }
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main(int argc, char *argv[])
{
	int x,y;
	while(cin>>x>>y)
	{
		string s[105];
		for(int i=0;i<x;)
		{
			cin>>s[i];
			getchar();
			int k=0;
			for(int j=0;j<y;j++)
				if(s[i][j]=='.')
					k++;
			if(k!=y)
				i++;
			else
				x--;	
		}
		for(int j=0;j<y;j++)
		{
			int k=0;
			for(int i=0;i<x;i++)
				if(s[i][j]=='.')
					k++;
			if(k==x)
			{
				for(int i=0;i<x;i++)
					s[i][j]=' ';
			}
		}
		for(int i=0;i<x;i++)
		{
			for(int j=0;j<y;j++)
				if(s[i][j]!=' ')
					cout<<s[i][j];
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}



signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  cin>>n;
  vector<int> A(n);
  cin>>A;

  Double ave = 0;
  for(int i=0;i<n;i++) ave += A[i];
  ave /= n;
  using P = pair<Double, Int>;
  vector<P> ans(n);
  for(int i=0;i<n;i++) ans[i] = P(abs(ave - A[i]), i);
  sort(ans.begin(), ans.end());
  cout<<ans[0].second<<endl;
  
  
  return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <iomanip>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    ll N;
    cin >> N;
    auto D = InputVec(N);
    ll M;
    cin >> M;
    auto T = InputVec(M);
    map<ll,ll> count;
    for (int i = 0; i < D.size(); ++i) {
        count[D[i]]++;
    }
    for (int i = 0; i < T.size(); ++i) {
        if(count[T[i]] == 0){
            cout << "NO" << endl;
            return 0;
        }
        count[T[i]]--;
    }
    cout << "YES" << endl;

}


Measured memory_bytes: 15872
let f n = let rec f a c d m = if d > m || d * d > n then if c > 0 then (d, c) :: a else if m > 1 then (m, 1) :: a else a else if m mod d = 0 then f a (c + 1) d @@ m / d else f (if c > 0 then (d, c) :: a else a) 0 (d + 1) m in f [] 0 2 n
let rec g a b = if b = 0 then a else g b (a mod b)
let _ = Scanf.scanf "%d %d" @@ fun a b -> 1 + (List.length @@ f @@ g a b) |> Printf.printf "%d\n"

Measured memory_bytes: 2432
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <ctime>
#include <cstdlib>
#include <bitset>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
const int N = 1010 , P = 1e9 + 7;
int Pow(int x,ll t){int r=1;for(;t;t>>=1,x=1ll*x*x%P)if(t&1)r=1ll*r*x%P;return r;}
int n,m,black,lr,ud;
ll K;
char s[N][N];

int main(){
    scanf("%d%d%lld",&n,&m,&K);
    rep(i,0,n) scanf("%s",s[i]);
    rep(i,0,n) rep(j,0,m) black += s[i][j] == '#';
    rep(i,0,n) lr += s[i][0] == '#' && s[i][m-1] == '#';
    rep(i,0,m) ud += s[0][i] == '#' && s[n-1][i] == '#';
    K--;
    if(K<=0||(lr*ud>0)) printf("%d\n",1);
    else {
        int out = lr+ud , in = 0;
        if(lr) rep(i,0,n) rep(j,1,m) in += s[i][j] == '#' && s[i][j-1] == '#';
        else if(ud) rep(i,1,n) rep(j,0,m) in += s[i-1][j] == '#' && s[i][j] == '#';
        int ans = Pow(black,K) , del = ((Pow(black,K) - Pow(out,K))%P+P)%P;
        del = 1ll*del*Pow(black-out,P-2)%P*in%P;
        ans -= del;if(ans < 0) ans += P;
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 1280
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int x[]=new int[N];
		int y[]=new int[N];
		for(int i=0;i<N;i++) {
			x[i]=sc.nextInt();
			y[i]=x[i];
		}
		int sum=0;

		for(int i=0;i<N;i++) {
			if(i!=N-1) {
				if(y[i]<=x[i+1]) {
					y[i]=0;
				}
			}
			if(i!=0) {
				if(y[i]<x[i-1]) {
					y[i]=0;
				}
			}
			sum+=y[i];
		}
		Boolean j=false;
		int min=0;
		for(int i=0;i<N;i++) {
			if(y[i]!=0) {
				j=true;
			}
			if(j) {
				if(y[i]==0) {
					if(min>x[i]) {
						min=x[i];
					}
				}else {
					sum-=min;
					min=101;
				}
			}
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
int main() {
	int h, n, a, cnt=0;
	cin >> h >> n;
	for(int i =0; i< n;i++)
	{
		cin >> a;
		cnt += a;
	}
	cout << (h <= cnt? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
class String
  @@encode = {}
  @@decode = {}

  def encode
    res = split('').map{ |c| @@encode[c] }.join
    res + '0' * ((5 - res.size % 5) % 5)
  end

  def decode
    scan(/.{5}/).map{ |s| @@decode[s] }.join
  end


  @@encode[" "] = "101"
  @@encode["'"] = "000000"
  @@encode[","] = "000011"
  @@encode["-"] = "10010001"
  @@encode["."] = "010001"

  @@encode["?"] = "000001"
  @@encode["A"] = "100101"
  @@encode["B"] = "10011010"
  @@encode["C"] = "0101"
  @@encode["D"] = "0001"
  @@encode["E"] = "110"
  @@encode["F"] = "01001"
  @@encode["G"] = "10011011"

  @@encode["H"] = "010000"
  @@encode["I"] = "0111"
  @@encode["J"] = "10011000"
  @@encode["K"] = "0110"
  @@encode["L"] = "00100"
  @@encode["M"] = "10011001"
  @@encode["N"] = "10011110"

  @@encode["O"] = "00101"
  @@encode["P"] = "111"
  @@encode["Q"] = "10011111"
  @@encode["R"] = "1000"
  @@encode["S"] = "00110"
  @@encode["T"] = "00111"
  @@encode["U"] = "10011100"

  @@encode["V"] = "10011101"
  @@encode["W"] = "000010"
  @@encode["X"] = "10010010"
  @@encode["Y"] = "10010011"
  @@encode["Z"] = "10010000"

  @@decode["00000"] = "A"
  @@decode["00001"] = "B"
  @@decode["00010"] = "C"
  @@decode["00011"] = "D"
  @@decode["00100"] = "E"
  @@decode["00101"] = "F"
  @@decode["00110"] = "G"

  @@decode["00111"] = "H"
  @@decode["01000"] = "I"
  @@decode["01001"] = "J"
  @@decode["01010"] = "K"
  @@decode["01011"] = "L"
  @@decode["01100"] = "M"
  @@decode["01101"] = "N"

  @@decode["01110"] = "O"
  @@decode["01111"] = "P"
  @@decode["10000"] = "Q"
  @@decode["10001"] = "R"
  @@decode["10010"] = "S"
  @@decode["10011"] = "T"
  @@decode["10100"] = "U"

  @@decode["10101"] = "V"
  @@decode["10110"] = "W"
  @@decode["10111"] = "X"
  @@decode["11000"] = "Y"
  @@decode["11001"] = "Z"

  @@decode["11010"] = " "
  @@decode["11011"] = "."
  @@decode["11100"] = ","
  @@decode["11101"] = "-"
  @@decode["11110"] = "'"
  @@decode["11111"] = "?"
end


while line = gets
  puts line.encode.decode
end

Measured memory_bytes: 2648
import java.io.*;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int a = fs.nextInt();
        int b = fs.nextInt();
        int p = a + b;
        int mi = a - b;
        int mp = a * b;
        System.out.println( Math.max( p , Math.max( mi , mp ) ) );
    }

    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte()) {
                return buffer[ptr++];
            } else {
                return -1;
            }
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
                ptr++;
            }
            return hasNextByte();
        }

        public String next() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong() {
            if (!hasNext()) {
                throw new NoSuchElementException();
            }
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
                throw new NumberFormatException();
            }
            return (int) nl;
        }

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


Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int main(){
  ll n;
  cin >> n;
  vector<ll>place(n);
  for(int i=0; i<n; i++) cin >> place[i];
  
  ll count=0;
  for(int i=0; i<n-1; i++){
   if(place[i]==i+1 && place[i+1]==i+2){
    swap(place[i],place[i+1]);
    count++;
   }
  }
  
  for(int i=0; i<n-1; i++){
   if(place[i]==i+1){
    swap(place[i],place[i+1]);
    count++;
   }
  }
  
  if(place[n-1]==n) count++;
  
  cout << count << endl;
  
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define rrep(i, n) for(int i = (int)(n); i>=0; --i)
struct fast_ios { fast_ios(){cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast_ios_;

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

    ll y = N/K;
    //printf("y:%lld, Ky:%lld, N-Ky:%lld\n", y, (K*y), (N-K*y));

    ll a = N-K*(y+1);
    if(a<0) { a=-a; }
    ll b = N-K*y;

    if(a<b)
    {
        cout << a << endl;
    }
    else
    {
        cout << b << endl;
    }
   
    
    return 0;
}

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

#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;

int pngkt[30];
int arr[5005];
int pref[5005];
map <string,int> asd;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	pngkt[0]=1;
	for(int q=1;q<30;q++)pngkt[q]=pngkt[q-1]*2;
	
	int z;
	cin>>z;
	
	string a;
	cin>>a;
	a="a"+a;
	for(int q=1;q<=a.size();q++)arr[q]=pngkt[a[q-1]-'a'],pref[q]=pref[q-1]+arr[q];
	
	int low=0,high=z;
	int mid,ans=0;
	
	while(low<=high){
		mid=(low+high)/2;
		asd.clear();
		for(int q=z-mid+1;q>1+mid-1;q--){
			string temp="";
			for(int w=q;w<=q+mid-1;w++)temp+=a[w];
			asd[temp]++;
		}
		bool cek=false;
		for(int q=1;q<=z-mid+1;q++){
			string temp="";
			for(int w=q;w<=q+mid-1;w++)temp+=a[w];
			if(asd[temp]!=0)cek=true;
			temp="";
			for(int w=q+mid;w<=q+mid+mid-1;w++)temp+=a[w];
			asd[temp]--;
		}
		
		if(cek)ans=mid,low=mid+1;
		else high=mid-1;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 37028
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
ll lef[200000],righ[200000],a[200000];
int n;
ll gcd (ll a, ll b){
    if(a<b)swap(a,b);
    ll c = (a%b);
    while(c>0){
        a = b;
        b = c;
        c = a%b;
    }
    return b;
}
vector <ll> candidate;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    lef[1]=a[1];
    for(int i=2;i<=n;i++){
        lef[i] = gcd(a[i],lef[i-1]);
    }
    righ[n]=a[n];
    for(int i=n-1;i>=1;i--){
        righ[i] = gcd(a[i],righ[i+1]);
    }

    ll mx = -1;
    for(int i=1;i<=n;i++){
        ll g;
        if(i==1){g = righ[2];}
        else if(i==n){g=lef[n-1];}
        else {
            g = gcd(lef[i-1],righ[i+1]);
        }
        mx = max(mx,g);
    }
    cout<<mx<<endl;
}


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

#define Fi first
#define Se second
#define pb push_back
#define mp make_pair
#define rep(x, a, b) for(int x = (a); x <= (b); ++ x)
#define per(x, a, b) for(int x = (a); x >= (b); -- x)
#define rop(x, a, b) for(int x = (a); x < (b); ++ x)
#define por(x, a, b) for(int x = (a); x > (b); -- x) 

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int unt;
typedef double db;
typedef pair <int, int> pii;
typedef vector <int> vi;

const db eps  = 1e-8;
const db _PI  = 3.1415926535897932384;
const db _E   = 2.7182818284590452354;
const int inf = 0x3f3f3f3f;
const LL INF  = 0x3f3f3f3f3f3f3f3fll;

int dcmp(db x) {
	if(x > eps) return 1;
	if(x < -eps) return -1;
	return 0;
}

int dcmp(db x, db y) {
	return dcmp(x - y);
}

struct Point {
	db x, y;
	Point(db _x = 0, db _y = 0) : x(_x), y(_y) {}
	void print() { printf("%.10f %.10f", x, y); }
};
struct Line {
	Point p1, p2;
	Line() {};
	Line(Point _p1, Point _p2) : p1(_p1), p2(_p2) {};
};

typedef Point Vector;
typedef Line Segment;

Vector operator + (const Vector &a, const Vector &b) {
	return Vector(a.x + b.x, a.y + b.y);
}
Vector operator - (const Vector &a, const Vector &b) {
	return Vector(a.x - b.x, a.y - b.y);
}
Vector operator * (const Vector &a, const db &b) {
	return Vector(a.x * b, a.y * b);
}
Vector operator / (const Vector &a, const db &b) {
	return Vector(a.x / b, a.y / b);
}
db operator * (const Vector &a, const Vector &b) {
	return a.x * b.x + a.y * b.y;
}
db operator ^ (const Vector &a, const Vector &b) {
	return a.x * b.y - a.y * b.x;
}
db dis(const Point &a, const Point &b) {
	return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
db dis2(const Point &a, const Point &b) {
	return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
db dis(const Vector &a) {
	return sqrt(a.x * a.x + a.y * a.y);
}
db dis2(const Vector &a) {
	return a.x * a.x + a.y * a.y;
}
Point Projection(const Line &L, const Point &p) {
	Vector Base = L.p2 - L.p1;
	db len = Base * (p - L.p1);
	return L.p1 + Base * (len / dis2(L.p1, L.p2));
}
Point Reflection(const Line &L, const Point &p) {
	return p + (Projection(L, p) - p) * 2.0;
}

int main() {
	Point p0, p1, p2;
	scanf("%lf%lf%lf%lf", &p0.x, &p0.y, &p1.x, &p1.y);
	int q; scanf("%d", &q);
	while(q --) {
		scanf("%lf%lf", &p2.x, &p2.y);
		Vector p01 = p1 - p0, p02 = p2 - p0;
		if(dcmp(p01 ^ p02) == 1) puts("COUNTER_CLOCKWISE");
		else if(dcmp(p01 ^ p02) == -1) puts("CLOCKWISE");
		else if(dcmp(p01 * p02) == -1) puts("ONLINE_BACK");
		else if(dcmp(dis2(p01), dis2(p02)) == -1) puts("ONLINE_FRONT");
		else puts("ON_SEGMENT");
	}
	return 0;
}


Measured memory_bytes: 3252
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>//priority_queue(優先度付きキュー)：最大値の探索が早い
#include<set>
#include<stack>
#include<string>
#include<vector>

#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<tuple>
#include<utility>
#define rep0(i,n) for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define rep1(i,n) for(ll i=1; i<=n; i++)
#define rrep1(i,n) for(ll i=n; 1<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
using ll = long long;
using namespace std;
/*ビットxにi番目のフラグが立っているかどうか
if(x & (1 << i))
↑ a << b == a*pow(b,2)
/*{0, 1, ..., n-1} の部分集合の全探索
for (int bit = 0; bit < (1 << n); ++bit)
*/

int main(){
  ll n,m;  cin >> n >> m;
  priority_queue<ll> q;
  rep0(i,n){
    ll a; cin >> a;
    q.push(a);
  }

  rep0(i,m){
    ll x = q.top();  q.pop();
    q.push(x/2);
  }

  ll ans = 0;
  while(!q.empty()){
    ans += q.top();  q.pop();
  }
  cout << ans;
}


Measured memory_bytes: 1400
N = int(input())
A = set() 
cnt = 0

def count(n, Set):
    if not n in Set:
        Set.add(n)
        return 0
    else:
        return 1
for x in input().split():
    cnt += count(x, A)
if not cnt & 1:
    ans = N - cnt
else:
    ans = N - cnt - 1
print(ans)
    



Measured memory_bytes: 22772
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1LL << 60
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
long long gcd(long long a, long long b){
  if(b == 0) return a;
  return gcd(b, a%b);
}
int main(void)
{
    ll a,b,c,d;cin>>a>>b>>c>>d;
    ll lcd = c/gcd(c, d)*d;
    ll m = b/c - (a-1)/c;
    ll n = b/d - (a-1)/d;
    ll k = b/lcd - (a-1)/lcd;
    ll ans = b - a + 1 - m - n + k;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256