akhauriyash/Code-Regression huggingface dataset:
module MakeBinaryHeap (M : sig type t val compare : t -> t -> int end) = struct

  type t = { node : M.t array; mutable size : int }

  let make n (init : M.t) = { node = Array.make n init; size = 0 }

  let empty_p t = if t.size = 0 then true else false

  let pop t =
    let rec max_heapify i =
      let l = 2*i in
      let r = 2*i + 1 in
      let m = if l <= t.size && M.compare t.node.(l) t.node.(i) > 0 then l else i in
      let m = if r <= t.size && M.compare t.node.(r) t.node.(m) > 0 then r else m in
      if m = i then ()
      else begin
        let tmp = t.node.(i) in
        t.node.(i) <- t.node.(m);
        t.node.(m) <- tmp;
        max_heapify m
      end in
    let ret = t.node.(1) in
    t.node.(1) <- t.node.(t.size);
    t.size <- t.size - 1;
    max_heapify 1;
    ret

  let push x t =
    let parent i = int_of_float (floor (float_of_int i) /. 2.) in
    let rec doit i =
      let p = parent i in
      if i <= 1 || M.compare t.node.(p) t.node.(i) >= 0 then ()
      else begin
        let tmp = t.node.(i) in
        t.node.(i) <- t.node.(p);
        t.node.(p) <- tmp;
        doit p
      end in
    t.size <- t.size + 1;
    t.node.(t.size) <- x;
    doit t.size

end

module H = MakeBinaryHeap(struct type t = (int * int) let compare (_, x) (_, y) = y - x end)

let dijkstra g n =
  let reached_p = Array.make n false in
  let d = Array.make n max_int in
  d.(0) <- 0;
  let h = H.make 30000 (0, 0) in
  H.push (0, 0) h;
  while not (H.empty_p h) do
    let (u, x) = H.pop h in
    reached_p.(u) <- true;
    if x > d.(u) then ()
    else
      List.iter (fun (v, c) ->
        let x = d.(u) + c in
        if not reached_p.(v) && x < d.(v) then begin
          d.(v) <- x;
          H.push (v, x) h;
        end) g.(u)
  done;
  d

let rec make_pair acc = function
  | [] -> acc
  | v :: c :: tl -> make_pair ((v, c) :: acc) tl
  | _ -> assert false

let make_pair lst = make_pair [] lst

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let n = read_int () in
  let g = Array.make n [] in
  for _ = 0 to n - 1 do
    match read_line () |> split_on_char ' ' |> List.map int_of_string with
    | u :: _ :: l -> g.(u) <- make_pair l
    | _ -> assert false
  done;
  dijkstra g n |> Array.iteri (fun i e -> Printf.printf "%d %d\n" i e)

Measured memory_bytes: 29892
#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#define MAXN 200000
#define ri register int
#define MOD 1000000007
using namespace std;
static int fat[MAXN + 1], inv[MAXN + 1];
static inline int expmod(int n, int p);
static inline int C(int n, int k);
int expmod(int n, int p) {
	if(p == 0) return 1;
	int ans = expmod(n, p >> 1);
	ans = 1LL * ans * ans % MOD;
	return p & 1 ? 1LL * ans * n % MOD : ans;
}
int C(int n, int k) {
	return 1LL * fat[n] * expmod(1LL * fat[k] * fat[n - k] % MOD, MOD - 2) % MOD;
}
int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	fat[0] = 1;
	for(ri k = 1; k <= h + w; ++k)
		fat[k] = 1LL * k * fat[k - 1] % MOD;
	int paths = 0;
	for(ri k = b + 1; k <= w; ++k)
		paths = (paths + 1LL * C(h - a + k - 2, k - 1) * C(a + w - k - 1, a - 1)) % MOD;
	cout << paths << '\n';
	return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys
import numpy as np


def solve(S: str):
    if S=="SSS":
        print(0)
        return
    if S=="SSR" or S=="SRS" or S=="RSS" or S=="RSR":
        print(1)
        return
    if S=="SRR" or S=="RRS":
        print(2)
        return
    else:
        print(3)
        return

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


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

#define int long long

signed main(){
	int n,m;
	cin>>n>>m;
	int tot=0;
	int dummy;
	for(int i=0;i<m;i++){
		cin>>dummy;
		tot+=dummy;
	}
	if(n-tot<0)
		cout<<-1<<endl;
	else
		cout<<n-tot<<endl;
	return 0;
	
}

Measured memory_bytes: 3184
#include <math.h>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265358979323846264338327950L
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

int main() {
  string A, B, C;

  cin >> A >> B >> C;

  if (A[A.size() - 1] == B[0] && B[B.size() - 1] == C[0])
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	var s string
	fmt.Scanf("%s", &s)
	if s == "Sunny" {
		fmt.Printf("Cloudy")
	}
	if s == "Cloudy" {
		fmt.Printf("Rainy")
	}
	if s == "Rainy" {
		fmt.Printf("Sunny")
	}
}


Measured memory_bytes: 640
#include<iostream>
using namespace std;
string s;
int l,r,lc,rc,ans;
int main(){
    cin>>s;
    if(s==string(s.size(),'x')){cout<<0<<endl;return 0;}
    for(r=s.size()-1;;lc=rc=0,l++,r--){
        while(s[l]=='x')l++,lc++;
        while(s[r]=='x')r--,rc++;
        if(s[l]!=s[r]){cout<<-1<<endl;return 0;}
        if(r<l)break;
        ans+=abs(lc-rc);
        if(l==r)break;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3704
sx, sy, tx, ty = gets.split.map(&:to_i)

dx = tx - sx
dy = ty - sy

R,L,U,D="RLUD".chars

print U*dy + R*dx + D*dy + L*dx

dx += 1
dy += 1

puts L + U*dy + R*dx  + D + R + D*dy + L*dx + U

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

const int mxN=1e5+1;
int n, dp[mxN][3], a, b, c;

int main() {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n;
    memset(dp, 0x3f, sizeof(dp));
    dp[0][0]=dp[0][1]=dp[0][2]=0;
    for (int i=1; i<=n; ++i) {
        cin >> a >> b >> c;
        dp[i][0]=max(dp[i-1][1]+b, dp[i-1][2]+c);
        dp[i][1]=max(dp[i-1][0]+a, dp[i-1][2]+c);
        dp[i][2]=max(dp[i-1][1]+b, dp[i-1][0]+a);
    }
    cout << max({dp[n][0], dp[n][1], dp[n][2]}) << '\n';
}


Measured memory_bytes: 4780
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int,int>;

ll solve() {
    ll N, M;
    cin >> N >> M;
    vector<vector<int>> g(N, vector<int>(N));
    int a, b;
    for ( int i = 0; i < M; i++ ) {
        cin >> a >> b;
        a--, b--;
        g[a][b] = 1;
        g[b][a] = 1;
    }
    vector<vector<int>> G(N);
    for ( int i = 0; i < N; i++ ) {
        for ( int j = i+1; j < N; j++ ) {
            if ( g[i][j] == 0 ) {
                G[i].push_back(j);
                G[j].push_back(i);
            }
        }
    }
    vector<pii> cnt;
    vector<int> used(N, -1);
    for ( int s = 0; s < N; s++ ) {
        vector<int> cl(N, -1); 
        if ( used[s] >= 0 ) continue;
        queue<int> q;
        q.push(s);
        cl[s] = 0;
        while ( !q.empty() ) {
            int v = q.front();
            q.pop();
            for ( int u : G[v] ) {
                if ( cl[u] >= 0 ) {
                    if ( cl[u] != 1 - cl[v] ) return -1;
                    continue;
                }
                cl[u] = 1 - cl[v];
                q.push(u);
            }
        }

        unordered_map<int, int> m;
        for ( int i = 0; i < N; i++ ) {
            if ( cl[i] >= 0 ) used[i] = 1;
            m[cl[i]]++;
        }
        cnt.push_back(pii(m[0],m[1]));
    }

    vector<vector<int>> dp(cnt.size()+1, vector<int>(N+1));
    dp[0][0] = 1;
    for ( int i = 1; i <= cnt.size(); i++ ) {
        pii x = cnt[i-1];
        for ( int j = 0; j <= N; j++ ) {
            if ( j - x.first >= 0 ) dp[i][j] = max(dp[i][j], dp[i-1][j-x.first]);
            if ( j - x.second >= 0 ) dp[i][j] = max(dp[i][j], dp[i-1][j-x.second]);
        }
    }
    int c0 = N/2;
    while ( c0 > 0 && dp[cnt.size()][c0] == 0 ) c0--;
    int c1 = (int)N - c0;
    ll ans = c0 * (c0 - 1) / 2 + c1 * (c1 - 1) / 2;
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 5120
/*================================================================
Love China, Love YALI, Love OI!
*   
*   File Name：A.cpp
*   Author：YaliKiWi
*   Date：2019年08月18日
*   Discribe：
*
================================================================*/


#include<bits/stdc++.h>
using namespace std;
#define fo(i,s,e) for(register int i=s;i<=e;i++)
#define max_(x,y) ((x)>(y)?(x):(y))
#define min_(x,y) ((x)<(y)?(x):(y))
#define dd double
#define ull unsigned long long
#define ll long long
#define maxn 100
char c[maxn];
int n;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>c;
	if(n<3200){
		cout<<"red";
		return 0;
	}
	cout<<c;
	return 0;
}

Measured memory_bytes: 256
border = [4,8,12]
ary = []
for i in 1..15 do
    ary.push([].fill(0,0,10)) 
end

n = gets.to_i

n.times{
    b, f, r, v = gets.split.map(&:to_i)
    i = 4*(b-1) + f - 1
    j = r - 1
    ary[i][j] += v
}

for i in 1..15 do
    if border.include?(i) then
        puts "#"*20
    else
        puts " " + ary[i-1].join(" ")
    end
end



Measured memory_bytes: 6884
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
const int INF=1e15;

int lcm(int x,int y){
    return (x*y)/__gcd(x,y);
}

int twod(int x){
    int ret=0;
    while(x%2==0){
        x/=2;
        ret++;
    }
  	return ret;
}

int myd(int x,int y){
  if(x%y==0) return x/y;
  else return x/y+1;
}

signed main(){
    int N,M;cin>>N>>M;
    vector<int>A(N);
    int check;
    bool ok=true;
    int d;
    REP(i,N){
        cin>>A[i];
        if(i==0){
            check=pow(2,twod(A[i]));
            d=A[i]/2;
        }
        else{
          d=lcm(d,A[i]/2);
      		if((A[i]%check)!=0||(A[i]/check)%2==0) ok=false;
        }
    }
    if(d<=M&&ok) cout<<myd(M/d,2)<<endl;
  	else cout<<0<<endl;
}

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

bool f(string s) {
    string rs = s;
    reverse(all(rs));
    return s == rs;
}

int main() {
    string S;
    cin >> S;
    bool ans  = true;
    string s2 = S.substr(0, (S.size() - 1) / 2);
    string s3 = S.substr(((S.size() + 3) / 2) - 1);
    cout << (f(S) && f(s2) && f(s3) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
const int INF=1e18;
const int MOD=1e9+7;

signed main(){
    int K;cin>>K;
    int d=49+(K/50);
    vector<int> A(50,d);
    REP(i,50){
        if(i<K%50)A[i]+=51-K%50;
        else A[i]-=K%50;
    }
    cout<<50<<endl;
    REP(i,50)cout<<A[i]<<" ";
}

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

int main() {
  int N;
  cin >> N;
  vector<string> S;
  rep(i, N) {
    string tmp;
    cin >> tmp;
    S.push_back(tmp);
  }

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

  int ans = 1;
  rep(i, N - 1){
    if(S[i] != S[i+1]) ans++;
  }

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

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a == b) cout << c << endl;
  if(b == c) cout << a << endl;
  if(c == a) cout << b << endl; 
  return 0;
}


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

fugo = [a < 0 for a in A]
seiA = [abs(a) for a in A]

ans = sum(seiA)
if sum(fugo) % 2 == 0:
    print(ans)
else:
    print(ans - 2 * min(seiA))


Measured memory_bytes: 14412
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
using namespace std;

string s;
void solve(){
  string a, b, c; cin >> a >> b >> c;
  cout << "A" << b[0] << "C" << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
def do():
    L, R = list(map(int, input().split(" ")))
    ans = 10 ** 15
    if R - L < 5000: #差が小さい場合は全探索
        for i in range(L,R + 1):
            for j in range(i+1,R + 1):
                if (i*j) % 2019 < ans:
                    ans = (i*j) % 2019
    else:#そうでなければ確実に一つ2019の倍数がある
        ans = 0
    print(ans)

if __name__ == "__main__":
    do()

Measured memory_bytes: 40048
import collections
N = int(input())
A = list(map(int,input().split()))
B = collections.Counter(A)
num = 0
for i in set(A):
    if B[i] > 1:
        num += B[i]*(B[i] - 1)//2
for i in A:
    print(num-B[i]+1)

Measured memory_bytes: 34096
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>

using namespace std;

int main()
{
   int x, a, b;
   cin >> x >> a >> b;

   if (a >= b)
      cout << "delicious" << endl;
   else if (b - a > x)
      cout << "dangerous" << endl;
   else
      cout << "safe" << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main ()
{
    int n,t,a[105],b[105],i,m=2000;
    cin >> n >> t;
    for(i=0;i<n;i++)
    {
        cin >> a[i] >> b[i];
        if(b[i]<=t)
            m=min(m,a[i]);
    }
    if(m==2000)
        cout << "TLE" ;
    else
        cout << m ;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <algorithm>
#define lson root<<1
#define rson root<<1|1
using namespace std;

int n;
int a[200010];
int sum[200010];
int b[200010];

struct node
{
    int l,r,sum;
}tr[1600080];

int push_up(int root)
{
    tr[root].sum=tr[lson].sum+tr[rson].sum;
}

int build(int root,int l,int r)
{
    if(l==r)
    {
        tr[root].sum=0;
        tr[root].l=l;
        tr[root].r=r;
        return 0;
    }
    tr[root].l=l;
    tr[root].r=r;
    int mid=(l+r)>>1;
    build(lson,l,mid);
    build(rson,mid+1,r);
    push_up(root);
}

int update(int root,int pos)
{
    if(pos==tr[root].l&&pos==tr[root].r)
    {
        tr[root].sum++;
        return 0;
    }
    int mid=(tr[root].l+tr[root].r)>>1;
    if(pos<=mid)
    {
        update(lson,pos);
    }
    else
    {
        update(rson,pos);
    }
    push_up(root);
}

int query(int root,int l,int r)
{
    if(l>r) return 0;
    if(l<=tr[root].l&&tr[root].r<=r) return tr[root].sum;
    int mid=(tr[root].l+tr[root].r)>>1;
    if(r<=mid)
    {
        return query(lson,l,r);
    }
    else
    {
        if(l>mid)
        {
            return query(rson,l,r);
        }
        else
        {
            return query(lson,l,mid)+query(rson,mid+1,r);
        }
    }
}

int check(int x)
{
    long long ans=0;
    memset(sum,0,sizeof(sum));
    for(int i=1;i<=n;i++)
    {
        sum[i]=sum[i-1]+((a[i]<=x)?1:-1);
    }
    for(int i=0;i<=n;i++)
    {
        sum[i]+=n+1;
    }
    build(1,1,200010);
    for(int i=0;i<=n;i++)
    {
        ans+=query(1,1,sum[i]-1);
        update(1,sum[i]);
    }
    return ans>=1ll*n*(n+1)/4+1;
}

int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        b[i]=a[i];
    }
    sort(b+1,b+n+1);
    int l=1,r=n,ans=0,mid=0;
    while(l<=r){
        mid=(l+r)/2;
        if(check(b[mid])){
            ans=b[mid];
            r=mid-1;
        }else{
            l=mid+1;
        }
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 10752
import java.io.*;

class Main {
	
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		while(true) {
			int width = Integer.parseInt(br.readLine());
			if(width == 0) return;
			
			int maxSize = 0;
			
			boolean[][] map = new boolean[width][width];
			
			int[] xy = new int[2];
			
			for(int y = 0; y < width; y++) {
				String str = br.readLine();
				for(int x = 0; x < width; x++) {
					if(str.charAt(x) == '*')
						map[y][x] = true;
					else {
						int nowSize = 1;
						
						sqCheck: for(int cWidth = 1; x - cWidth >= 0 && y - cWidth >= 0; cWidth++) {
							
							for(int cWidth2 = 0; cWidth2 <= cWidth; cWidth2++)
								if(map[y - cWidth + cWidth2][x - cWidth] || map[y - cWidth][x - cWidth + cWidth2])
									break sqCheck;
							
							nowSize++;
						}
						
						if(maxSize < nowSize) maxSize = nowSize;
					}
				}
			}
			System.out.println(maxSize);
		}
	}
	
	
}

Measured memory_bytes: 12000
#include <stdio.h>

main(){

  int i,j;
  int Sel[101];
  int N;
  int tmp;
  int mini;
  int count = 0;

  scanf("%d",&N);

  for(i=1; i<=N;i++){
    scanf("%d",&Sel[i]);
  }

  // selection
  for (i=1; i<=N; i++){
    mini = i;
    for (j=i; j<=N; j++){
      if(Sel[j] < Sel[mini]){
	mini = j;
      }
    }
    if(i != mini){
      
      tmp = Sel[i];
      Sel[i] = Sel[mini];
      Sel[mini] = tmp;
      count++;
      
    }

  }

  for (i=1; i<=N; i++){
    printf("%d",Sel[i]);

    if(i!=N){
      printf(" ");
    }
  }

  printf("\n%d\n",count);

return 0;

}

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

int main(){
    int r, c, x;
    cin >> r >> c;
    int sheet[r+1][c+1];

    for(int i=0; i<r; i++){
        for(int j=0; j<c; j++){
            cin >> x;
            sheet[i][j] = x;
        }
    }

    for(int i=0; i<r; i++){
        int total_r = 0;
        for(int j=0; j<c; j++){
            total_r += sheet[i][j];
        }
        sheet[i][c] = total_r;
    }

    for(int i=0; i<=c; i++){
        int total_c = 0;
        for(int j=0; j<r; j++){
            total_c += sheet[j][i];
        }
        sheet[r][i] = total_c;
    }

    for(int i=0; i<=r; i++){
        for(int j=0; j<c; j++){
            cout << sheet[i][j] << " ";

        }
        cout << sheet[i][c] << endl;
    }
    return 0;
}


Measured memory_bytes: 3116
N,K = map(int,input().split())
mod = 1000000007

ans = 0
for i in range(K,N+2):
    m = i*(i+1)//2
    m %= mod
    M = i*(N+2) - m
    M %= mod
    ans += M - m + 1
    ans %= mod
print(ans)

Measured memory_bytes: 9188
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

constexpr lint mod=1e9+7;

/* pow */
//a^b mod p
int64_t modpow(int64_t a,int64_t b,int64_t p)
{
	if(b==0)return 1;
	int64_t ret=modpow(a,b/2,p);
	ret=(ret*ret)%p;
	if(b%2==1)
		ret=(a*ret)%p;
	return ret;
}

/* combination */
// nCr mod p
int64_t comb(int64_t n,int64_t r,int64_t p)
{
	int64_t ret=1;
	for(int64_t i=0;i<r;i++)
	{
		ret*=(n-i);
		ret%=p;
	}
	for(int64_t i=2;i<=r;i++)
	{
		ret*=modpow(i,p-2,p);
		ret%=p;
	}
	return ret;
}

int main()
{
	lint X,Y;

	cin >> X >> Y;

	for(lint a=0;a<=X;a++)
	{
		if(2*(Y-2*a)!=X-a)continue;

		lint b=Y-2*a;
		cout << comb(a+b,min(a,b),mod) << endl;
		return 0;
	}

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



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

#define MAX_N 100'000

using namespace std;

int A[MAX_N]{};
bool selected[MAX_N]{};

int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  int a = 1;
  int cnt = 0;
  while (a != 2 && !selected[a - 1]) {
    selected[a - 1] = true;
    a = A[a - 1];
    ++cnt;
  }
  if (a == 2) {
    printf("%d\n", cnt);
  } else {
    printf("-1\n");
  }
}

Measured memory_bytes: 3744
#include<stdio.h>
#define H 500000

int h;

void maxHeapify(int *A,int i){
  int l=2*i,r=2*i+1,largest,c;
  if(l<=h&&A[l]>A[i]) largest=l;
  else largest=i;
  if(r<=h&&A[r]>A[largest]) largest=r;

  if(largest!=i){
    c=A[i];
    A[i]=A[largest];
    A[largest]=c;
    maxHeapify(A,largest);
  }
  
}

void buildMaxHeap(int *A){
  int i;
  for(i=h/2;i>=1;i--) maxHeapify(A,i);
}


int main(){
  int A[H],i;

  scanf("%d",&h);
  for(i=1;i<=h;i++) scanf("%d",&A[i]);

  buildMaxHeap(A);
  
  for(i=1;i<=h;i++) printf(" %d",A[i]);
  printf("\n");

  return 0;

}





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

int main(){
    string s;
    cin >> s;
    int ans = 0;
    for(int i=s.size()-1; i>0; i--){
        if(i%2 == 0 && s.substr(0, i/2) == s.substr(i/2, i/2)) ans = max(ans, i);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
R = [(-1, -1)] * N
for n in range(N):
    x, y = map(int, input().split())
    R[n] = (x, y)
B = [(-1, -1)] * N
for n in range(N):
    x, y = map(int, input().split())
    B[n] = (x, y)

B = sorted(B)
R = sorted(R, reverse=True)

ans = 0
for i, b in enumerate(B):
    tmp = []
    for j, r in enumerate(R):
        if r[0] == -1:
            continue
        if r[0] < b[0] and r[1] < b[1]:
            tmp.append((j, r))
    if tmp:
        tmp = sorted(tmp, key=lambda x: x[1][1], reverse=True)
        R[tmp[0][0]] = (-1, -1)
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#include <cstring>
#include <fstream>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LLI long long int
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POS(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
#define Pos(i) cout<<(i?"Possible":"Impossible")<<endl
#define co(i) cout<<i<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//

int main(){
    int a,b,c; cin>>a>>b>>c;
    int ans=0;
    while(true){
        if(a%2||b%2||c%2){
            break;
        }else if(a==b&&b==c){
            ans=-1;
            break;
        }else{
            int a1=(b+c)/2,b1=(c+a)/2,c1=(a+b)/2;
            a=a1,b=b1,c=c1;
            ans++;
        }
    }
    co(ans);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <limits.h>
#define MAX 101

int n,m[MAX][MAX], p[MAX], FUCK, ans=INT_MAX;

void matrixChainOrder()
{
    int na = n;
    for (int i = 1; i<=na; i++) m[i][i] = 0;
    for (int l = 2; l<=na; l++)
        for (int i = 1; i<=na-l+1; i++)
        {
            int j = i+l-1;
            m[i][j] = INT_MAX;
            for(int k = i; k<=j-1; k++)
            {
                int q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
                if(m[i][j]>=q) m[i][j]= q; 
                if(m[i][j]<ans) ans = m[i][j]; 
            }
        }
}

int main()
{
    scanf("%d", &n);    
    scanf("%d%d",&p[0], &p[1]);
    for(int i=2; i<n+1; i++)
    {
        scanf("%d%d", &FUCK, &p[i]);
    }
    matrixChainOrder();

    printf("%d\n", m[1][n]);
    return 0;
}


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

int main()
{
	int N;
	string S;
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		cin >> S;
		if(S=="Y"s)
		{
			cout << "Four\n"s;
			return 0;
		}
	}
	cout << "Three"s;
}

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

typedef long long ll;

int main () {
    // 入力
    int N,M;
    cin >> N >> M;
    vector<int> x(N);
    for (int i=0; i<N; ++i) {
	cin >> x[i];
    }
    sort(x.begin(), x.end());

//    for(auto& e : x) cout << e << " ";
//    cout << endl;

    
    vector<int> num_same(M);
    int pre = x[0], num=1;
    for(int i=1; i<=N; i++) {
	if( i == N or pre != x[i] ) {
	    num_same[pre%M] += num/2; // pairの個数
	    num = 1;
	    pre = x[i];
	}
	else if( pre == x[i] ) num++;
    }
    
    vector<int> x_mod(N);
    for(int i=0; i<N; i++) x_mod[i] = x[i]%M;
    sort(x_mod.begin(), x_mod.end());
    
//    for(auto& e : x_mod) cout << e << " ";
//    cout << endl;

//    cout << "num_same" <<endl;
//    for(int i=0; i<num_same.size(); i++) cout << num_same[i] << " ";
//    cout << endl;
    

    // mod が等しいものの個数
    vector<int> cnt(M);
    for(int i=0; i<N; i++) {
	cnt[x_mod[i]]++;
    }
    
    int ans = 0;
    ans += cnt[0]/2;
    for(int i=0; i<((M-1)/2); i++) {
	ans += min(cnt[i+1], cnt[M-1-i]);      // 足して和がMの倍数なら答えに追加
	int diff = abs(cnt[i+1] - cnt[M-1-i]); // 余った分で同じカードでペアができるなら追加
	if( cnt[i+1] > cnt[M-1-i] )
	    ans += min(diff/2, num_same[i+1]);
	if( cnt[i+1] < cnt[M-1-i] )
	    ans += min(diff/2, num_same[M-1-i]);
    }

    if( M%2 == 0 ) {
	ans += cnt[M/2]/2;
    }
    cout << ans << endl;
    
    
    
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<list>
#include<string>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<ctime>
using namespace std;

const int NIL = -1;
const int MAX = 2147483647;
const int N = 100001;
clock_t START, END;
bool debug = false;

int minv[N << 2], addv[N << 2], setv[N << 2];
int ql, qr, p, v;
int _min;

void pushdown(int o)
{
	int lc = o * 2, rc = o * 2 + 1;
	if (setv[o] >= 0) {
		setv[lc] = setv[rc] = setv[o];
		setv[o] = -1;
	}
}

void maintain(int o, int L, int R)
{
	int lc = o * 2, rc = 2 * o + 1;
	if (setv[o] >= 0) {
		minv[o] = setv[o];
	}
	else if (R > L) {
		minv[o] = min(minv[lc], minv[rc]);
	}
	//minv[o] += addv[o];
}

void query(int o, int L, int R)
{
	int M = L + (R - L) / 2;
	if (setv[o] >= 0) {
		_min = min(_min, setv[o]);
	}
	else if (ql <= L && qr >= R) {
		_min = min(_min, minv[o]);
	}
	else {
		if (ql <= M)
			query(o * 2, L, M);
		if (qr > M)
			query(o * 2 + 1, M + 1, R);
	}
}

void update(int o, int L, int R)
{
	int M = L + (R - L) / 2;
	int lc = o * 2, rc = o * 2 + 1;
	if (ql <= L && qr >= R) {
		setv[o] = v;
	}
	else {
		pushdown(o);
		if (ql <= M)
			update(lc, L, M);
		else
			maintain(lc, L, M);
		if (qr > M)
			update(rc, M + 1, R);
		else
			maintain(rc, M + 1, R);
	}
	maintain(o, L, R);
}


int main(void)
{
	if (debug) {
		START = clock();
		freopen("in5.txt", "r", stdin);
		freopen("out1.txt", "w", stdout);
	}
	int n, q, com;
	scanf("%d%d", &n, &q);
	for (int i = 0; i <= 4 * n; i++) {
		setv[i] = -1;
		minv[i] = MAX;
	}
	for (int i = 0; i < q; i++) {
		scanf("%d", &com);
		if (com) {
			scanf("%d%d", &ql, &qr);
			ql++;
			qr++;
			_min = MAX;
			query(1, 1, n);
			printf("%d\n", _min);
		}
		else {
			scanf("%d%d%d", &ql, &qr, &v);
			ql++;
			qr++;
			update(1, 1, n);
		}
	}
	if (debug) {
		END = clock();
		double endtime = (double)(END - START) / 1000;
		printf("total time = %lf s", endtime);
	}
	return 0;
}


Measured memory_bytes: 6332
//#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <string>

using namespace std;

//ifstream cin("x.in"); ofstream cout("x.out");

int n, m;

const int nmax = 800;
const int inf = 1 << 30;
const int dl[ 4 ] = {-1, 0, 0, 1};
const int dc[ 4 ] = {0, -1, 1, 0};

int viz[nmax + 1][nmax + 1];
queue <pair<int, int>> q;
string s[nmax + 1];

inline int mndst (int x, int y) {
    int dist = min(x - 1, y - 1);
    return min(dist, min(n - x, m - y));
}

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

    int x, y;
    for (int i = 1; i <= n; ++ i) {
        cin >> s[ i ];
        for (int j = 1; j <= m; ++ j) {
            if (s[ i ][j - 1] == 'S') {
                x = i, y = j;
            }
        }
        s[ i ] = "#" + s[ i ];
    }

    viz[ x ][ y ] = 1;
    q.push(make_pair(x, y));
    int ans = inf;

    while (!q.empty()) {
        pair<int, int> shp = q.front(); q.pop();

        ans = min(ans, mndst(shp.first, shp.second));
        if (viz[ shp.first ][ shp.second ] == k + 1) continue;

        for (int dir = 0; dir < 4; ++ dir) {
            int a, b;
            a = shp.first + dl[ dir ], b = shp.second + dc[ dir ];

            if (a < 1 || b < 1 || a > n || b > m) continue;
            if (viz[ a ][ b ] != 0 || s[ a ][ b ] == '#') continue;

            viz[ a ][ b ] = viz[ shp.first ][ shp.second ] + 1;
            q.push(make_pair(a, b));
        }
    }

    if (ans <= 0) ans = 0;
    else ans = (ans - 1) / k + 1;

    if (x == 1 || y == 1 || x == n || y == m) ans = -1;
    cout << ans + 1;
    return 0;
}



Measured memory_bytes: 3456
#include<stdio.h>

int main ()
{
	int n,q;
	scanf("%d %d",&n,&q);
	while(q--)
	{
		int t1,t2,i;
		scanf("%d %d",&t1,&t2);
		if(n==1)
		{
			printf("%d\n",t1>t2?t2:t1);
			continue;
		}
		while(t1!=t2)
		{
			if(t1>t2)
				t1=(t1-2)/n+1;
			else
				t2=(t2-2)/n+1;
		}
		printf("%d\n",t1);
	}
	return 0;
}

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

const int N=1500010;
int n,m,a[N];

struct SegTree
{
	int l[N],r[N],maxn[N];
	
	void build(int x,int ql,int qr)
	{
		l[x]=ql; r[x]=qr;
		if (ql==qr) return;
		int mid=(ql+qr)>>1;
		build(x*2,ql,mid); build(x*2+1,mid+1,qr);
	}
	
	int query(int x,int ql,int qr)
	{
		if (l[x]==ql && r[x]==qr)
			return maxn[x];
		int mid=(l[x]+r[x])>>1;
		if (qr<=mid) return query(x*2,ql,qr);
		if (ql>mid) return query(x*2+1,ql,qr);
		return max(query(x*2,ql,mid),query(x*2+1,mid+1,qr));
	}
	
	void update(int x,int p,int v)
	{
		if (l[x]==p && r[x]==p)
		{
			maxn[x]=max(maxn[x],v);
			return;
		}
		int mid=(l[x]+r[x])>>1;
		if (p<=mid) update(x*2,p,v);
			else update(x*2+1,p,v);
		maxn[x]=max(maxn[x*2],maxn[x*2+1]);
	}
}seg;

int main()
{
	scanf("%d%d",&n,&m);
	seg.build(1,1,300010);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]); a[i]++;
		seg.update(1,a[i],seg.query(1,max(1,a[i]-m),min(300010,a[i]+m))+1);
	}
	printf("%d\n",seg.maxn[1]);
	return 0;
}

Measured memory_bytes: 17328
a,b,c,d=map(int,input().split())
mod=998244353
dp=[[0]*(c+1) for i in range(d+1)]
dp[b][a]=1
for i in range(b,d+1):
  for j in range(a,c+1):
    if i==b and j==a:
      continue
    dp[i][j]=(dp[i-1][j]*j+dp[i][j-1]*i-dp[i-1][j-1]*(i-1)*(j-1))%mod
print(dp[-1][-1])

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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X,i) ((X>>i)&1)
#define REP(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(rall(a))
#define ina(x,n) rep(x_i,n) cin>>x[x_i]
#define outa(x,n) rep(x_i,n) cerr<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;

const int inf = (1<<28);
const ll infl = (1LL<<60);
const int mod = 1e9+7;
struct mint {
  ll x;
  mint(ll x=0) : x((x%mod+mod)%mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (t == 0) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint &operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};
const mint ONE(1);
vector<mint> fac, inv;

void init(int n) {
  fac.assign(n+1,1);
  inv.assign(n+1,1);
  for (int i = 1; i <= n; i++) {
    fac[i] = fac[i-1] * mint(i);
    inv[i] = fac[i].inv();
  }
}

mint ncr(int n, int r) {
  mint N(n);
  return fac[n] * inv[n-r] * inv[r];
}

mint nhr(int n, int r) {
  return ncr(n+r-1, r);
}

int main() {
  int n, k; cin >> n >> k;
  init(n);
  mint ans(1);
  for (int i = 1; i <= min(n-1, k); i++) {
    ans += ncr(n,i) * nhr(n-i,i);
  }
  cout << ans.x << endl;
  return 0;
}


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

const int offset=100;
bool table[210][210];
bool visited[210][210];

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

struct state{
	int x,y,t;
};

int main(void){
	int t,n;
	while(cin >> t >> n){
		if(t==0)
			break;
		rep(i,210)rep(j,210)
			table[i][j]=visited[i][j]=false;

		rep(i,n){
			int x,y;
			cin >> x >> y;
			table[x+offset][y+offset]=true;
		}
		state s;
		cin >> s.x >> s.y;
		s.t=0;
		queue<state> q;
		q.push(s);
		while(!q.empty()){
			state cur=q.front(); q.pop();
			if(visited[cur.x+offset][cur.y+offset])
				continue;
			visited[cur.x+offset][cur.y+offset]=true;
			if(cur.t>=t)
				continue;
			rep(i,6){
				state next=cur;
				next.x+=dx[i];
				next.y+=dy[i];
				next.t++;
				if(!table[next.x+offset][next.y+offset])
					q.push(next);
			}
		}
		int ans=0;
		rep(i,210)rep(j,210) ans+=visited[i][j];
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1316
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];

        for (int i = 0; i < n; i++)
            a[i] = sc.nextInt();

        int swapCount = 0;
        boolean sorted = false;
        while (!sorted) {
            sorted = true;
            for (int i = n - 1; i >= 1; i--) {
                if (a[i] < a[i - 1]) {
                    swap(a, i-1, i);
                    swapCount++;
                    sorted = false;
                }
            }
        }
        printlnArray(a);
        System.out.println(swapCount);
    }
    
    static void swap(int[] a, int i, int j) {
        int temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }
    
    private static void printlnArray(int[] a) {
        for (int i = 0; i < a.length - 1; i++) {
            System.out.print(a[i] + " ");
        }
        System.out.println(a[a.length - 1]);
    }
}


Measured memory_bytes: 26364
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		String sample = scanner.nextLine();
		String[] s = sample.split(" ");
		int a = Integer.parseInt(s[0]);
		int b = Integer.parseInt(s[1]);
		
		int max = a+b;
		if(max < (a-b)){
			max = a-b;
		}
		if(max < (a*b)){
			max = (a*b);
		}
		System.out.println(max);
	}

}


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

int main(void){
    int n;cin>>n;
    bool can =true;
    for(int i=0;i<n;i++){
        int tmp;cin>>tmp;
        if(!can)continue;
        if(tmp%2==0&&tmp%3!=0&&tmp%5!=0)can=false;
    }
    if(can)cout<<"APPROVED"<<endl;
    else cout<<"DENIED"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int N,total = 0,d1,d2;
    cin >> N;
    for(int i = 0;i < N;i++){
        cin >> d1 >> d2;
        if(d1 == d2){total++;}
        else{total = 0;}
        
        if(total >= 3){
            cout << "Yes" << endl;
            return 0;
        }
    }    
    cout << "No" << endl;
}


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

int main(){
    int n, d;
    cin >> n >> d;
    int a = 2*d + 1;
    if(n%a != 0) cout << n/a + 1 << endl;
    else cout << n/a << endl;
    return 0;
}

Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
       Scanner scn=new Scanner(System.in);
       int n=scn.nextInt();
       int[] arr=new int[n];
       for(int i=0;i<n;i++){
    	   arr[i]=scn.nextInt();
       }
       int[] dp=new int[n];
       dp[0]=0;
       for(int i=1;i<n;i++){
    	   int option1=Math.abs(arr[i]-arr[i-1])+dp[i-1];
    	   int option2;
    	   if(i==1){
    		   option2=Integer.MAX_VALUE;
    	   }
    	   else{
    	    option2=Math.abs(arr[i]-arr[i-2])+dp[i-2];
    	   }
    	   dp[i]=Math.min(option1, option2);
       }
       System.out.println(dp[n-1]);
	}

}


Measured memory_bytes: 52996
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#pragma endregion

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  int a[3];
  rep(i, 3) cin >> a[i];
  sort(a, a + 3);
  int ans = 0;
  ans += (a[2] - a[1]);
  a[0] += (a[2] - a[1]);
  a[1] = a[2];
  if ((a[1] - a[0]) % 2 == 0)
  {
    ans += (a[1] - a[0]) / 2;
  }
  else
  {
    a[1]++, a[2]++;
    ans++;
    ans += (a[1] - a[0]) / 2;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define rrep(i,j,n) for(ll i = (ll)(j); i < (ll)(n); i++)
#define mrep(i,n) for (ll i = (ll)(n); i > 0; i--)
#define be(v) (v).begin(), (v).end()
#define dcout cout << fixed << setprecision(20) 
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main() {
	ll x,n;
	cin >> x >> n;
	if(n==0) {
		cout << x << endl;
		return 0;
	}
	vector<ll> p(n);
	ll ma=0;
	rep(i,n) {
		cin >> p[i];
		ma=max(ma,p[i]);
	}
	sort(be(p));
	reverse(be(p));

	ll ans = 1000;
	for(ll i=0;i<=101;i++) {
		bool ok = true;
		for(ll j=0;j<n;j++) {
			if(i==p[j]) ok = false;
		}
		if(ok) {
			if(abs(x-ans)>abs(x-i)) ans=i;
		}
	}
	cout << ans << endl;
}


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

int main() {
  int c5 = 0, c7 = 0;
  for (int i = 0; i < 3; ++i) {
    int a;
    cin >> a;
    if (a == 5) ++c5;
    if (a == 7) ++c7;
  }
  if (c5 == 2 && c7 == 1) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  return 0;
}

Measured memory_bytes: 256
S = input().strip()
n = len(S)

for i in range(int(n/2)-1):
    S = S[:-2]
    for j in range(int(len(S)/2)):
        if S[j] != S[j+int(len(S)/2)]:
            break
    else:
        print(len(S))
        quit()

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//????????????????????????????????????
#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//??£??\???????????¨???
	ll to, cost;
};
struct S {//???????????±?????\???????????°
	int from, to, cost;
};
struct H {
	int x, y;
};
ll gcm(ll i, ll j) {//?????§??¬?´???°
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(ld a, ld b, ld c, ld d) {
	return sqrt(pow(a - c, 2) + pow(b - d, 2));
}//rad?????§?¨???????2??????????????¢
 //---------------------------------------------------
 //+++++++++++++++++++++++++++++++++++++++++++++++++++
int A, B, C, n;
int a[100], b[100], c[100];
struct D {
	int a, b, c;
};
D d[1000];
signed main() {
	while (cin >> A >> B >> C>>n&&A + B + C != 0) {
		for (int i = 0; i < max(A, max(B, C)); i++)
			a[i] = 2, b[i] = 2, c[i] = 2;
		int t, y, o, p, sum = 0;
		for (int i = 0; i < n; i++) {
			cin >> t >> y >> o >> p;
			t--; y--; o--;
			y -= A, o -= (B + A);
			if (p == 1)
				a[t] = 1, b[y] = 1, c[o] = 1;
			else
				d[sum++] = D{ t,y,o };
		}
		for (int i = 0; i < sum; i++) {
			int s = 0;
			if (a[d[i].a] == 1) s++;
			if (b[d[i].b] == 1) s++;
			if (c[d[i].c] == 1) s++;
			if (s == 2) {
				if (a[d[i].a] == 2) a[d[i].a] = 0;
				if (b[d[i].b] == 2) b[d[i].b] = 0;
				if (c[d[i].c] == 2) c[d[i].c] = 0;
			}
		}
		for (int i = 0; i < A; i++)
			cout << a[i] << endl;
		for (int i = 0; i < B; i++)
			cout << b[i] << endl;
		for (int i = 0; i < C; i++)
			cout << c[i] << endl;
	}
	getchar(); getchar();
}

Measured memory_bytes: 3124
#include <iostream>
#include <string>

using namespace std;

int main(int argc, const char *argv[]) {
  string S, R;
  string RSfront, RSend;
  cin >> S;
  R = S;
  string Sfront = S.substr(0, ((S.length() - 1) / 2));
  string Send = S.substr(((S.length() + 3) / 2) - 1, ((S.length() - 1) / 2));
  RSfront = Sfront;
  RSend = Send;
  reverse(R.begin(), R.end());
  reverse(RSfront.begin(), RSfront.end());
  reverse(RSend.begin(), RSend.end());

  if(S == R && Sfront == RSfront && Send == RSend){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s; cin >> s;
    int Q; cin >> Q;
    int cnt = 0;
    deque<string>str;
    str.push_back(s);
    for(int k = 0; k < Q; ++k){
        int query;  cin >> query;
        if(query == 1){
            ++cnt;
        } else {
            int f; cin >> f;
            string s_; cin >> s_;
            if(f == 1){
                if(cnt % 2 == 0)str.push_front(s_);
                else str.push_back(s_);
            } else {
                if(cnt % 2)str.push_front(s_);
                else str.push_back(s_);
            }
        }
    }
    string ans = accumulate(str.begin(), str.end(), ""s,[](string res,string t){return res += t;});
    if(cnt % 2)reverse(ans.begin(),ans.end());
    cout << ans  << endl;
}


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

const int INF=1e9;

int main(){
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
    cin.tie(0);*/

	int n,k;cin>>n>>k;
	vector<int> a(n),dp(n,INF);
	for(int i=0;i<n;i++)cin>>a[i];
	dp[0]=0;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<=i+k;j++){
			if(j<n)dp[j]=min(dp[j],dp[i]+abs(a[i]-a[j]));
		}
	}
	cout<<dp[n-1];

    /*#ifndef ONLINE_JUDGE
    	cout << "\nTime Elapsed : " << 1.0 * clock() << " ms\n";
    #endif*/
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
typedef long long LL;
map<LL,int>m;
int main(){
    int N;
    cin>>N;
    REP(i,N){
        LL a;
        cin>>a;
        m[a]++;
    }
    int M;
    cin>>M;
    bool check=true;
    REP(i,M){
        LL a;
        cin>>a;
        if(m[a]==0){
           check=false;break;
        }else{
           m[a]--;
        }
    }
    if(check){
       cout<<"YES"<<endl;
    }else{
       cout<<"NO"<<endl;
    }
    return(0);
}

Measured memory_bytes: 12800
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
ll x, y;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> x >> y;

  ll xx = x;
  int ans = 0;
  while(xx <= y) {
    ans++;
    xx *= 2;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000007
//0=48,A=65,a=97

int main() {
    string s;cin >> s;
    int z=0,one=0;
    for(int i = 0; i < s.size(); i++) {
        if(s[i]=='0') z++;
        else one++;
    }

    cout << 2*min(z,one) << endl;

    return 0;
}

Measured memory_bytes: 3752
s = input()
l = len(s)//2
s_ = s[::-1]
s1 = s[:l]
s1_ = s1[::-1]
s2 = s[l+1:]
s2_ = s2[::-1]
 
if s == s_ and s1 == s1_ and s2 == s2_:
    print("Yes")
else:
    print("No")

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

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define MOD 1000000007
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll ans,A,B,C;

void solve(){
    if(A * B * C % 2 == 0)
        cout << 0 << endl;
    else
        cout << min({A*B, B*C, C*A}) << endl;
}

int main(){
    cin >> A >> B >> C;

    solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,a[100],ave=0,dist=10000;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i],ave+=a[i],a[i]*=n;
	for(int i=0;i<n;i++)
		dist=min(dist,abs(ave-a[i]));
	for(int i=0;i<n;i++)
		if(abs(ave-a[i])==dist)
			cout<<i<<endl,exit(0);
}


Measured memory_bytes: 256