akhauriyash/Code-Regression huggingface dataset:
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns          #-}
{-# LANGUAGE CPP                   #-}
{-# LANGUAGE MagicHash             #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE RecordWildCards       #-}
{-# LANGUAGE TupleSections         #-}
{-# LANGUAGE TypeFamilies          #-}
{-# LANGUAGE UnboxedTuples         #-}

import           Control.Applicative
import           Control.DeepSeq
import           Control.Exception
import           Control.Monad
import           Control.Monad.ST
import           Control.Monad.Trans.State.Strict
import           Data.Array.Base
import           Data.Array.ST                    (STUArray, runSTUArray)
import           Data.Bits
import           Data.Bool
import qualified Data.ByteString.Char8            as B
import           Data.Char
import           Data.Coerce
import qualified Data.Foldable                    as F
import           Data.Function
import           Data.Int
import qualified Data.IntMap.Strict               as IM
import qualified Data.IntSet                      as IS
import qualified Data.List                        as L
import qualified Data.Map.Strict                  as M
import           Data.Monoid
import           Data.Ord
import qualified Data.Set                         as S
import           Data.STRef
import           Data.Tuple
import           Data.Word
import           Debug.Trace
import           GHC.Arr                          (Array, Ix (..), STArray)
import           GHC.Exts
import           System.Exit
import           System.IO
--
import           GHC.Prim

main :: IO ()
main = do
    !n <- readLn :: IO Int
    print $ solve n

lim :: Int
lim = 1000000

solve :: Int -> Int
solve n = F.foldl' (+%) 0 $ zipWith3 (\i x y -> (x -% y) *% i) is fs $ 0:fs
  where
    is = [div (n + 1) 2 .. n - 1]
    fs = map f is
    f k = fact k *% fact (k - 1) /% fact (2 * k - n)

#define MOD 1000000007

infixl 7 *%, /%
infixl 6 +%, -%

type IntMod = Int

(+%), (-%), (*%), (/%) :: IntMod -> IntMod -> IntMod
(I# x#) +% (I# y#) = I# ((x# +# y#) `remInt#` MOD#)
(I# x#) -% (I# y#) = I# ((x# -# y# +# MOD#) `remInt#` MOD#)
(I# x#) *% (I# y#) = I# ((x# *# y#) `remInt#` MOD#)
(I# x#) /% (I# y#) = go# y# MOD# 1# 0#
  where
    go# a# b# u# v#
        | isTrue# (b# ># 0#) = case a# `quotInt#` b# of
            q# -> go# b# (a# -# (q# *# b#)) v# (u# -# (q# *# v#))
        | otherwise = I# ((x# *# (u# +# MOD#)) `remInt#` MOD#)
{-# INLINE (+%) #-}
{-# INLINE (-%) #-}
{-# INLINE (*%) #-}
{-# INLINE (/%) #-}

factCache :: UArray Int Int
factCache = runSTUArray $ do
    fact <- newArray (0, lim) 1
    F.for_ [2..lim] $ \i ->
        unsafeRead fact (i - 1) >>= unsafeWrite fact i . (*% i)
    return fact

fact :: Int -> Int
fact = unsafeAt factCache



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

using namespace std;

int n, m;
int a[222222], b[222222];

bool ok(int x){
	int s = n;
	for(int i = 1; i <= m; ++i) b[i] = a[i] >= x;
	int dist = 1 << 20;
	int an = b[1];
	for(int i = 2; i <= n; ++i) if (b[i] == b[i - 1]){
		if (s - i < dist){
			dist = s - i;
			an = b[i];
		}
	}
	for(int i = n; i < m; ++i) if (b[i] == b[i + 1]){
		if (i - s < dist){
			dist = i - s;
			an = b[i];
		}
	}
	return an;
}

int main(){
//	freopen("input.inp", "r", stdin);
	scanf("%d",&n);
	m = 2 * n - 1;
	for(int i = 1; i <= m; ++i) scanf("%d",&a[i]);
	int l = 1, r = m;
	while (l <= r){
		int md = (l + r) >> 1;
		if (ok(md)) l = md + 1;
		else r = md - 1;
	}
	printf("%d",r);
	return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) ((v).begin(),(v).end())
using namespace std;

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    int c[n], a[n][m];
    int result=10000000;
    REP(i,n){
        cin >> c[i];
        REP(j,m){
            cin >> a[i][j];
        }
    }

    // 購入する参考書の組み合わせについて全探索
    for(int bit=0; bit<(1<<n); bit++){  // 1<<n は2^n
        
        // 参考書の組み合わせにおける、値段とスキル合計値を計算
        int skills_sum[15]={0};
        int price=0;
        for(int i=0; i<n; i++){
            // 購入する参考書でマスクがけ
            int mask = 1 << i;  // 1, 2, 4, ... 2の累乗を生成
            if(bit & mask){
                price += c[i];
                for(int j=0; j<m; j++){
                    skills_sum[j] += a[i][j];
                }
            }
        }
        
        bool skill = true;
        REP(i,m){
            if(skills_sum[i] < x){
                skill = false;
            }
        }
        
        if(skill){
            result = min(result, price);
        }
    }
    if(result!=10000000){
        cout << result << endl;
    }
    else{
        cout << "-1" << endl;
    }
    return 0;
}

Measured memory_bytes: 3640
C = input()

alp=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
i=0
while True:
    if alp[i]==C:
        print(alp[i+1])
        break
    else:
        i+=1

Measured memory_bytes: 38256
n = gets.to_i
x = gets.chomp.split(" ").map(&:to_i)
min = 0
for i in x.min..x.max do
    totalDistance = 0
    for j in x do
        totalDistance += ((i - j).abs) ** 2
    end
    if i == x.min
        min = totalDistance
        next
    end
    if min > totalDistance
        min = totalDistance
    end
end
puts min

Measured memory_bytes: 14212
#include<iostream>
#include<stdio.h>
#include<string.h>
#define int long long
using namespace std;
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
signed main()
{
	int n, a, b; cin >> n >> a >> b;
	a = a - b;
	int hp[100001] = { 0 }, h[100001] = { 0 };
	REP(i, n) {
		cin >> h[i];
	}
	long long count = 1, ookii = 0, ok = 1000000000, no = 0;
	while (1) {
		REP(i, 100001) { hp[i] = h[i]; }
		ookii = 0; int mae = count;
		count = (no + ok) / 2; //cout << count << endl;
		if (ok - no < 2) {
			cout << ok << endl; break;
		}
		for (int i = 0; i < n; i++)
		{
			hp[i] -= b*count;
			if (hp[i] > 0) {
				//hp[i] -= a; i--; ookii++; 
                                ookii += (hp[i] + a - 1) / a;
				if (ookii > count) {
					break;
				}
			}
//cout<<count<<" "<<i<<""<<hp[i]<<" "<<ookii<<endl;
		}
		if (ookii <= count) {
			ok = count;
		}
		else {
			no = count;
		}
	}
	return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 2000000
#define INFTY (1<<30)

int H, A[MAX+1];

void swap(int *a, int *b) {
    int t;
    t = *a;
    *a = *b;
    *b = t;
}

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

int extract() {
    int maxv;
    if ( H < 1 ) return -INFTY;
    maxv = A[1];
    A[1] = A[H--];
    maxHeapify(1);
    return maxv;
}

void increaseKey(int i, int key) {
    if(key < A[i]) return;
    A[i] = key;
    while(i > 1 && A[i / 2] < A[i]) {
        swap(&A[i], &A[i / 2]);
        i = i / 2;
    }
}

void insert(int key) {
    H++;
    A[H] = -INFTY;
    increaseKey(H, key);
}

int main() {
    int key;
    char com[10];

    while(1) {
        scanf("%s", com);
        if(com[0] == 'e' && com[1] == 'n') break;
        if(com[0] == 'i') {
            scanf("%d", &key);
            insert(key);
        }else {
            printf("%d\n", extract());
        }
    }

    return 0;
}

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

int main() {
	int X,Y;
	cin>>X>>Y;
	int sum=0;
	if(X==1 && Y==1) {cout<<1000000; return 0;}
	if(X==1) sum=300000;
	else if(X==2) sum=200000;
	else if(X==3) sum=100000;
	else  sum=0;
	
	if(Y==1) sum+=300000;
	else if(Y==2) sum+=200000;
	else if(Y==3) sum+=100000;
	else  sum+=0;
	
	cout<<sum<<endl;
		
	
}

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

#define ll long long
#define ld long double

#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define repA(i,A)   for(auto i:A)

#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define mp make_pair
#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)	A.rbegin(),A.rend()
#define ft first
#define sd second

#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V> 
#define Vpll vector<pll>

#define endl "\n"

const ll logN = 20;
const ll N = 100005;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265

const ll dx[4] = {1,0,-1,0};
const ll dy[4] = {0,1,0,-1};

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    ll A[n+1];
    rep(i,1,n+1)	cin>>A[i];
    ll cnt=0;
    rep(i,1,n+1){
    	if(A[i]!=i)	cnt++;
    }	
    if(cnt==0 || cnt==2){
    	cout<<"YES"<<endl;
    }
    else{
    	cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <vector>
#include <cmath>
#include <cstdint>
#include <string>

using namespace std;

int main() {
  while (true) {
    string line;
    getline(cin, line);
    if (line == "0") break;
    int sum = 0;
    for (char c : line) {
      int n = c - 48;
      sum += n;
    }
    cout << sum << endl;
  }
}

Measured memory_bytes: 3160
import java.io.*;
import java.util.*;
/*
 * 	Heart beats fast
 * 		Colors and promises
 * 			How to be brave
 * 				How can I love when I am afraid to fall...
 */
public class Main 
{
	static final int mod=1000000007;
	static final double eps=1e-8;
	static final long inf=100000000000000000L;
	static final boolean debug=true;
	static Reader in=new Reader();
	public static void main(String[] args) throws IOException
	{
		int n=ni();
		int d=ni(),x=ni();
		int a[]=new int[n];
		int an=0;
		for(int i=0; i<n; i++)
		{
			a[i]=ni();
			an++;
			an+=(d-1)/a[i];
		}
		pr(an+x);
		System.out.println(ans);
	}
	static StringBuilder ans=new StringBuilder();
	static long powm(long a, long b, long m)
	{
		long an=1;
		long c=a;
		while(b>0)
		{
			if(b%2==1)
				an=(an*c)%m;
			c=(c*c)%m;
			b>>=1;
		}
		return an;
	}
	static Random rn=new Random();
	static void pd(){if(debug)ans.append("hola");}
	static void pd(Object a){if(debug)ans.append(a+"\n");}
	static void pr(Object a){ans.append(a+"\n");}
	static void pr(){ans.append("\n");}
	static void p(Object a){ans.append(a);}
	static int ni(){return in.nextInt();}
	static long nl(){return in.nextLong();}
	static String ns(){return in.next();}
	static double nd(){return in.nextDouble();}
	static String pr(String a, long b)
	{
		String c="";
		while(b>0)
		{
			if(b%2==1)
				c=c.concat(a);
			a=a.concat(a);
			b>>=1;
		}
		return c;
	}
	static class Reader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public Reader() {
            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
        	return Long.parseLong(next());
        }
        public double nextDouble() {
        	return Double.parseDouble(next());
        }
    }
}

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

int main() {
    int n, f=0;
    cin>>n;
    string p=to_string(n);
    for(int i=0;i<p.size();i++)
    {
        if(p[i]=='7')
        {
            f=1;
            break;
        }
    }
    if(f==0)
    cout<<"No"<<endl;
    else
    cout<<"Yes";
	return 0;
}

Measured memory_bytes: 3660
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
/*
//#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
*/

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
/*
//#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
*/
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

#define INF INT_MAX/3
#define MAX_N 1000
#define M_INF 1000000000
int n,m,v,i;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n;
  std::vector<ll> a(n),b(n);
  rep(i,n) cin>>a[i]>>b[i];
  ll cnt = 0;
  for(int i = n-1;i >=0;i--) {
    if((a[i]+cnt) % b[i] != 0) cnt += b[i] - (a[i]+cnt)%b[i];
  }
  cout<<cnt<<endl;

}

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


Measured memory_bytes: 1792
#![allow(non_snake_case, unused_mut)]
//use petgraph::unionfind::UnionFind;
use proconio::marker::Usize1;
use proconio::{fastout, input, marker::*};
use std::collections::*;

#[fastout()]
fn main() {
    input! {
        N:usize, mut S:Chars, Q:usize,
    }
    let mut set = vec![BTreeSet::new(); 26];
    let ctoi = |c| (c as u8 - b'a') as usize;
    for i in 0..N {
        set[ctoi(S[i])].insert(i);
    }

    for _ in 0..Q {
        input! {query:i32}
        if query == 1 {
            input! {iq:Usize1,cq:char}
            let sq = S[iq];
            if sq == cq {
                continue;
            };
            set[ctoi(sq)].remove(&iq);
            set[ctoi(cq)].insert(iq);
            S[iq] = cq;
        } else {
            // queary 2の場合
            input! {lq:Usize1, rq:Usize1}
            let mut ans = 0;
            for c in b'a'..=b'z' {
                let i = (c - b'a') as usize;
                let mut p = set[i].range(lq..=rq).peekable();
                if p.peek().is_some() {
                    ans += 1;
                }
            }

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


Measured memory_bytes: 15064
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define rep(i,n) for(long long int i=0;i<(long long int)(n);i++)
int main(){
  ll a, b; cin>>a>>b;
  int s=0;
  rep(i,1300){
    if((i*8)/100 ==a && i/10==b){
      cout<< i<<endl;
      s++;
      break;
    }
  }
  
  if(s==0){
    cout<<-1<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int I=X;I<Y;I++)
#define REP(I,X,Y) for(int I=Y-1;I>=X;I--)
#define INF 1000000007
using namespace std;

int main(){
  int n,m;
  cin >> n >> m;
  int c[m];
  FOR(i,0,m)cin >> c[i];
  int DP[n+1];
  DP[0] = 0;
  FOR(i,1,n+1)DP[i] = INF;
  FOR(i,1,n+1){
    FOR(j,0,m){
      if(i - c[j] >= 0)DP[i] = min(DP[i],1+DP[i - c[j]]);
    }
  }
  cout << DP[n] << endl;
}



Measured memory_bytes: 3288
#define NDEBUG

#include <unordered_map>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <tuple>
#include <set>
#include <map>

// [0, max)
#define FOR0(var, max) for (sl (var) = 0; (var) < (max); ++(var))
// [min, max)
#define FORi(var, min, max) for (sl (var) = (min); (var) < (max); ++(var))
// [min, max)
#define FORi_INV(var, min, max) for (sl (var) = (max) - 1; (var) + 1 > (min); --(var))
#define FORITER(var, iter) for (auto (iter) = (var).begin(); (iter) != (var).end(); (iter)++)
#define FORITER_INV(var, iter) for (auto (iter) = (var).rbegin(); (iter) != (var).rend(); (iter)++)

// a < b < c
#define LTLT(a, b, c) (((a) < (b)) && ((b) < (c)))
// a <= b < c
#define LELT(a, b, c) (((a) <= (b)) && ((b) < (c)))
// a < b <= c
#define LTLE(a, b, c) (((a) < (b)) && ((b) <= (c)))
// a <= b <= c
#define LELE(a, b, c) (((a) <= (b)) && ((b) <= (c)))

#ifndef NDEBUG
#  define MASSERT(cond) m_assert(cond, __LINE__, #cond);
#else
#  define MASSERT(...)
#endif

using namespace std;

using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;

using sc = signed char;
using si = signed int;
using sl = signed long long int;

using ld = long double;

void m_assert(const bool& cond, const sl& line, const char *condstr) {
  if (!cond) {
    cerr << "Assertion Failed: " << condstr << " at line " << line << endl;
    exit(1);
  }
}

template <class T>
T powint(T x, sl y) {
  MASSERT(0 < y);
  T cur = x;
  T res = 1;
  while (y != 0) {
    if ((y & 1) == 1) {
      res = res * cur;
    }
    cur = cur * cur;
    y >>= 1;
  }
  return res;
}

template <class T>
T factorial(const T& n) {
  T res = 1;
  FOR0(i, n) {
    res *= i + 1;
  }
  return res;
}

template <class T>
T permutation(const T& n, const T& m) {
  return factorial(n) / factorial(n - m);
}

template <class T>
T combination(const T& n, const T& m) {
  T res = 1;
  FORi(i, n - m, n) {
    res *= i + 1;
  }
  FORi(i, 0, m) {
    res /= i + 1;
  }
  return res;
}

static string N;
static sl K;
static sl dp[100];

void solve(void) {
  sl M = N.size();
  sl j = 0;
  FOR0(i, M) {
    sl n = N[i] - '0';
    sl t = 0;
    if (j < K) {
      if (n != 0) {
        t += (n - 1) * combination(M - i - 1, K - j - 1) * powint(9, K - j - 1);
        t += combination(M - i - 1, K - j) * powint(9, K - j);
      }
    }
    if (i != 0) {
      t += dp[i - 1];
    }
    dp[i] = t;
    if (n != 0) {
      j++;
      if (j == K) {
        dp[i]++;
      }
    }
  }
  cout << dp[M - 1] << endl;
}

int main(void) {
  cin >> N;
  cin >> K;
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

struct edge {
  int to;
  ll cost;
  edge(int to, ll cost) : to(to), cost(cost) {}
};

class LCA {
public:
  int V, logV;
  vector<int> depth, len;
  vector<vector<int> > parent; // parent[i][v]: ノードvの(i+1)個上の親

  LCA(int V) {
    this->V = V;
    logV = 0;
    while(V > (1LL<<logV)) logV++;
    this->depth = vector<int>(V);
    this->len = vector<int>(V);
    this->parent = vector<vector<int> >(logV, vector<int>(V));
  }

  void init(int v, int par, int d, int l, vector<vector<edge>>& G) {
    depth[v] = d;       // rootからの深さ
    parent[0][v] = par; // 親
    len[v] = l;         // rootからの距離
    for(int i=0; i<(int)G[v].size(); i++) {
      int w = G[v][i].to;   // 子ノード
      int lc = G[v][i].cost; // 子ノードとの距離
      if(w == par) continue;
      init(w, v, d+1, lc + l, G);
    }
  }

  void build() {
    for(int k=0; k+1<logV; k++) {
      for(int v=0; v<V; v++) {
        if(parent[k][v] < 0) parent[k+1][v] = -1;
        else parent[k+1][v] = parent[k][parent[k][v]];
      }
    }
  }

  int query(int u, int v) {
    if(depth[u] > depth[v]) swap(u, v);
    for(int k=0; k<logV; k++) {
      if((depth[v] - depth[u]) >> k & 1)
        v = parent[k][v];
    }
    if(u == v) return u;

    for(int k=logV-1; k>=0; k--) {
      if(parent[k][u] != parent[k][v]) {
        u = parent[k][u];
        v = parent[k][v];
      }
    }
    return parent[0][u];
  }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<vector<edge>> G(N);
  map<pair<int, int>, int> mp;
  rep(i, N-1) {
    int a, b;
    cin >> a >> b; a--; b--;
    G[a].push_back({b, 1});
    G[b].push_back({a, 1});
    mp[{min(a, b), max(a, b)}] = i;
  }
  LCA lca(N);
  lca.init(0, -1, 0, 0, G);
  lca.build();
  int M;
  cin >> M;
  vector<bitset<50>> onPath(M);
  rep(i, M) {
    int u, v;
    cin >> u >> v; u--; v--;
    int z = lca.query(u, v);
    int cur = u;
    while(cur != z) {
      if(!mp.count({min(cur, lca.parent[0][cur]),
              max(cur, lca.parent[0][cur])})) {
        cout << "something wrong\n";
      }
      int e = mp[{min(cur, lca.parent[0][cur]),
                  max(cur, lca.parent[0][cur])}];
      onPath[i].set(e);
      cur = lca.parent[0][cur];
    }
    cur = v;
    while(cur != z) {
      if(!mp.count({min(cur, lca.parent[0][cur]),
              max(cur, lca.parent[0][cur])})) {
        cout << "something wrong\n";
      }
      int e = mp[{min(cur, lca.parent[0][cur]),
                  max(cur, lca.parent[0][cur])}];
      onPath[i].set(e);
      cur = lca.parent[0][cur];
    }
  }
  ll ans = 0;
  rep(i, 1<<M) {
    int n = __builtin_popcount(i);
    bitset<50> onPaths;
    rep(j, M) if((i>>j)&1) onPaths |= onPath[j];
    int m = onPaths.count();
    ans += (n%2 ? -1 : 1) * (1LL<<(N-1-m));
  }
  cout << ans << "\n";
  return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> s(n);
    int t = 0;
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        t += s[i];
    }

    if (t % 10 != 0) {
        cout << t << endl;
        return 0;
    }

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

    for (const int x : s) {
        if (x % 10 != 0) {
            cout << (t - x) << endl;
            return 0;
        }
    }

    cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int N, Q, A[100000], X, l, r, hoge;
ll sa[100001], sb[100000];

int main() {
	cin >> N >> Q;
	for (int i = 0; i != N; ++i)
		cin >> A[i];
	for (int i = 0; i != N; ++i) {
		sa[i + 1] = sa[i] + A[i];
		sb[i] = A[i];
	}
	for (int i = 2; i < N; ++i)
		sb[i] += sb[i - 2];
	l = A[0];
	r = A[N / 2];
	while (l + 1 != r) {
		int k = (l + r) / 2;
		if (k - A[0] <= A[N / 2] - k)
			l = k;
		else
			r = k;
	}
	hoge = l;
	for (int i = 0; i != Q; ++i) {
		cin >> X;
		if (X <= hoge)
			cout << sa[N] - sa[N / 2] << endl;
		else {
			l = 0;
			r = N / 2 + 1;
			while (l + 1 != r) {
				int k = (l + r) / 2;
				if (A[N - k] - X >= X - A[N - k * 2])
					l = k;
				else
					r = k;
			}
//			cout << nyan << endl;
//			cout << l << endl;
			if (A[N - l - 1] - X >= X - A[N - l * 2 - 1])
				++l;
//			cout << l << endl;
			cout << sa[N] - sa[N - l] + sb[N - 1 - l - l] << endl;
//			cout << nyan << endl;
		}
	}
	return 0;
}


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

const int MAXN = 501;

int C[MAXN], S[MAXN], F[MAXN];

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n; cin >> n;
	for (int i = 1; i < n; i++){
		cin >> C[i] >> S[i] >> F[i];
	}
	C[n] = S[n] = F[n] = 0;
	for (int i = 1; i <= n; i++){
		int time = C[i] + S[i];
		for (int j = i + 1; j < n; j++){
			if (time < S[j]){
				time = C[j] + S[j];
			}
			else{
				if (time % F[j] != 0){
					time += F[j] - (time % F[j]);
				}
				time += C[j];
			}
		}
		cout << time << endl;
	}
	return 0;
}

Measured memory_bytes: 256
use v5.18; # strict say state
use warnings;
use List::Util qw(reduce first max min sum0);

chomp (my $n = <STDIN>);
chomp (my @a = split / /, <STDIN>);
my %h;
$h{$_}++ for @a;
my @s = grep {$h{$_} >= 4} keys %h;
my @t = grep {$h{$_} >= 2} keys %h;
my $ans = 0;
if (@s > 0) {
  my $u = max(@s);
  $ans = $u * $u;
}
if (@t > 1) {
  my @v = sort {$b <=> $a} @t;
  $ans = $v[0] * $v[1] if $ans < $v[0] * $v[1];
}
say $ans;

Measured memory_bytes: 28196
def main():
  N = int(input())
  X = N // 1.08
  if (N == int(X * 1.08)):
    print(int(X))
  elif (N == int((X + 1) * 1.08)):
    print(int(X + 1))
  else:
    print(':(')



if __name__ == '__main__':
  main()


Measured memory_bytes: 3064
#include <stdio.h>
int main(void)
{
    int w, h;
    int j;
    while (1)
    {
        scanf("%d %d", &w, &h);
        if (w == 0 && h == 0)
        {
            break;
        }
        for (int i = 1; i <= w; i++)
        {
            for (j = 0; j < h; j++)
            {
                printf("#");
            }
            printf("\n");

            if (i == w)
            {
                printf("\n");
            }
        }
    }

    return 0;
}


Measured memory_bytes: 2020
H,N = map(int,input().split())
AB = [tuple(map(int,input().split())) for _ in range(N)]
INF = float("inf")
dp0 = [INF]*(H+1)
dp1 = [0]*(H+1)
dp0[0] = 0
for i in range(N):
    a,b = AB[i]
    dp1[H] = dp0[H]
    for h in range(H-1, -1, -1):
        dp1[h] = min(dp0[h], dp1[h+1])
    for h in range(H+1):
        dp1[h] = min(dp1[h], dp1[max(h-a,0)]+b)
    t = dp1
    dp1 = dp0
    dp0 = t
print(dp0[H])

Measured memory_bytes: 74888
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long int

int N, A, B;
int h[100000];

bool isOk(int a) {
    int cnt = 0;
    int diff = A - B;

    rep(i, N) {
        int leave = h[i] - a * B;
        if (leave > 0) cnt += (leave + diff - 1) / diff;
    }
    return (cnt <= a);
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> A >> B;
    rep(i, N) cin >> h[i];
    int l = 0, r = 1073741824;
    int mid = (l + r) / 2;
    while (l < r) {
        mid = (l + r ) / 2;
        if (isOk(mid)) r = mid;
        else l = mid + 1;
    }
    cout << l << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main()
{
  int a, b;
  cin >> a >> b;
  if (a + b == 15)
    cout << "+" << endl;
  else if (a * b == 15)
    cout << "*" << endl;
  else
    cout << "x" << endl;
  return 0;
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    int n;
    cin >> n;

    int l = n%10;
    if(l==0||l==1||l==6||l==8) cout << "pon" << endl;
    else if(l==3) cout << "bon" << endl;
    else cout << "hon" << endl;
    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#include<string.h>
int main()
{
    char s[10];
    scanf("%s",s);
    int i;

    if(s[0]=='S'||s[0]=='s')
        printf("Cloudy\n");
    else if(s[0]=='C'||s[1]=='c')
        printf("Rainy\n");
    else
        printf("Sunny\n");

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <cstring>
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

int main() {
    string S, T;
    int s;

    cin >> S >> T;

    s = S.size();

    if(S==T.substr(0, s)) {
        cout << "Yes" << endl;
    } else {
        cout << "No";
    }

    return 0;
    
}

Measured memory_bytes: 3600
#include<iostream>
#include<string>
#include <vector>
#include<algorithm>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define vsort(v) sort(v.begin(), v.end())
#define ll long long
const ll MOD = 1e9 + 7;

int main() {
	string s;
	cin >> s;
	int p, q;
	p = s.size() + 1;
	q = -1;
	rep(i, s.size()) {
		if (s[i] == 'A' && p > i) p = i;
		if (s[i] == 'Z' && q < i) q = i;
	}
	cout << q - p + 1 << endl;
}

Measured memory_bytes: 640
// /*
// power code taken from geeks for geeks
// */
// cout << setprecision (2) << fixed << 1.2;

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef long double ld;

#define pll pair<ll, ll>

const ll INF = 1e18 + 5;
const ll MAX_N = 410 + 5;
const ll MODD = 1e9 + 7;

ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
double max(double a,double b){return a>b?a:b;}
double min(double a,double b){return a<b?a:b;}

ll modd(ll a){if(a<0LL) return a*-1LL;return a;}
double modd(double a){if(a<0.0) return a*-1.0;return a;}

ll modulo(ll a){return (a + MODD) % MODD; }

ll power(ll k, ll p){
    if (p == 0)
        return 1LL;
 
    ll P = power(k, p/2LL);
    P = (P * P) % MODD;
 
    if (p % 2 == 1)
        P = (P * k) % MODD;
 
    return P;
}


struct p_str {
    ll a, b;
};


void solve() {
    string s, t;
    cin >> s >> t;
    
    ll n = s.length();
    ll k = t.length();

    ll ans = k;

    for(ll i = 0; i + k <= n; i++) {
        ll c = 0;
        for(ll j = 0; j < k; j++) {

            if(s[i + j] != t[j]) {
                c++;
            }
        }
        ans = min(ans, c);
    }
    cout << ans << endl;

}



int main(){

  

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




    ll t=1;


    // cin >> t;
    


    while(t--){
        solve();
    }

    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
    int n;cin>>n;
    vl c(n),d(n+1);
    map<ll,ll>b;
    d[0]=1;
    ll a=1;
    rep(i,n){
        cin>>c[i];
        b[c[i]]++;
        d[i+1]=(i+1)*d[i];
        d[i+1]%=MOD;  
    }
    rep(i,2*n-2){
        a*=2;
        a%=MOD;
    }
    sort(all(c));
    ll ans=0,cnt=0,now=c[0],cnt2=0;
    for(int i=0;i<n;++i){
        ans+=c[i]*(n+1-i)%MOD;
        ans%=MOD;
    }
    ans*=a;
    ans%=MOD;
    cout<<ans<<endl;
}


Measured memory_bytes: 18816
//I am so vegetable
//#define _LOCAL_
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define PB push_back
#define IN insert
#define ER erase
#define CT count
#define EP empty
#define _for(i,a,b) for(int i = (a);i<(b);++i)
#define _rfor(i,a,b) for(int i = (a);i>(b);--i)
#define _sfor(p,st) for(auto &p:st)
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll N = 2e5 + 5;
const int MOD = 10000;
const double eps = 1e-6;
const double pi = acos(-1);
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
ll qpow(ll x, ll y) { ll ans = 1; for (; y > 0; y >>= 1) { if (y & 1)ans *= x; x *= x; }return ans; }
ll inv(ll x, int mod = MOD) { return qpow(x, mod - 2) % mod; }

int main() {
	FIO;
	int k;cin>>k;
	ll cur;
	queue<ll>qu;
	_for(i,1,10)qu.push(i);
	_for(i,0,k){
		cur = qu.front();
		int tail = cur%10;
		qu.pop();
		if(tail>0)qu.push(10ll*cur+tail-1);
		qu.push(10ll*cur+tail);
		if(tail<9)qu.push(10ll*cur+tail+1);
	}
	cout<<cur;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cmath>
using namespace std;

int main() {
    int n;
    cin >> n;
    long ans = 0;
    for (int i = 1; i <= n; i++) {
        if (i % 3 != 0 && i % 5 != 0) {
            ans += i;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner inp = new Scanner(System.in);

        int n = inp.nextInt();;
        int x = inp.nextInt();

        while(n != 0){
            int total = 0;
            for (int i = 1; i <= n; i++) {
                for (int j = i+1; j <= n; j++) {
                    int k = x - i - j;
                    if(k > j && k <= n) {
                        total++;
                    }

                }
            }

            System.out.println(total);

            n = inp.nextInt();
            x = inp.nextInt();
        }
    }
}



Measured memory_bytes: 26408
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
typedef long long ll;


int main(){
  ll N; cin >> N;
  cout << N * (N - 1) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <queue>
#include <assert.h>
#include <cmath>
#include <deque>
#include <set>
#include <unordered_map>
#include <complex>
#include <fstream>
#include <map>
using namespace std;
using ll = long long;
using ld = long double;
const int mxn = 200100;
ld A[mxn];
ll B[mxn];

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

	int n; cin>>n;
	for(int i=0; i<n; i++) cin>>A[i];

	for(int i=0; i<n; i++) {
		B[i] = llround(A[i]*1e9);
		//cout << B[i] << '\n';
	}

	map<pair<int, int>, ll> f;

	for(int i=0; i<n; i++) {
		int cnt2 = 0; while(B[i]%2==0) B[i]/=2, cnt2++;
		int cnt5 = 0; while(B[i]%5==0) B[i]/=5, cnt5++;
		cnt2-=9; cnt5-=9;
		f[make_pair(cnt2, cnt5)]++;
	}
	ll ans = 0;
	for(auto it = f.begin(); it!=f.end(); it++) {
		for(auto it2 = it; it2!=f.end(); it2++) {
			if(it2==it) {
				if(it->first.first>=0 and it->first.second>=0) {
					ans+=(it->second-1)*it->second/2;
				}
				continue;
			}
			if(it->first.first+it2->first.first>=0 and it->first.second+it2->first.second>=0)
				ans+=1ll*it->second*it2->second;
		}
	}

	cout << ans << '\n';
	return 0;
}

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

int main() {
     ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   
        ll k;
        cin>>k;
     
        ll n =100;
        ll j =0;
        if(n>=k)
            {cout<<0;
                return 0;
            }
        while(1){
            n+=n/100;
            j++;
            if(n>=k)
                break;
        }
        cout<<j;
        
        
    
	return 0;
}

Measured memory_bytes: 3648
#include<cstdio>
#include<algorithm>
#include<cstring>
#define rep(i, s, t) for(i = s; i <= t; ++i)
#define dep(i, s, t) for(i = s; i >= t; --i)

using namespace std;

const int N = 1010;
int n, m, nn, mm, A, B;
char mp[N][N];

void paint(int t, int o, bool stop) {
	int x, y;
	x = (t-1) / mm + 1; y = (t-1) % mm + 1;
	//printf("%d %d\n", x, y);
	x = (x-1) * 2 + 1; y = (y-1) * 2 + 1;
	if(!o) {
		mp[x][y] = '<'; mp[x][y+1] = '>';
		if(stop) return;
		mp[x+1][y] = '<'; mp[x+1][y+1] = '>';
	} else {
		mp[x][y] = '^'; mp[x+1][y] = 'v';
		if(stop) return;
		mp[x][y+1] = '^'; mp[x+1][y+1] = 'v';
	}
}

void so(int e) {
	int t, f, i, j;
	nn = n>>1; mm = m>>1; f = nn * mm;
	
	t = min(f, A/2); f -= t; A -= t*2;
	for(i = 1; i <= t; ++i) paint(i, 0, 0);
	t = min(f, B/2); f -= t; B -= t*2;
	for(t += i-1; i <= t; ++i) paint(i, 1, 0);
	
	if((A || B) && (!f)) {puts("NO"); return;}
	if(A+B <= f+e) puts("YES"); else {puts("NO"); return;}
	
	if(f == 1 && A && B && e) {
		mp[n-2][m-2] = '<'; mp[n-2][m-1] = '>';
		mp[n-1][m-2] = '^'; mp[n][m-2] = 'v';
	} else {
		if(A) paint(i++, 0, 1);
		if(B) paint(i++, 1, 1);
	}
	rep(i, 1, n) {
		rep(j, 1, m) printf("%c", mp[i][j]);
		puts("");
	}
}

int main() {
	int i, j, down, right;
	scanf("%d%d%d%d", &n, &m, &A, &B);
	rep(i, 1, n) rep(j, 1, m) mp[i][j] = '.';
	if((n & 1) && (m > 1)) {
		down = min(A, m/2);
		A -= down; down <<= 1;
		rep(i, 1, down) mp[n][i] = (i&1)? '<': '>';
		if((m&1) && m>1 && m == down+1) {
			mp[n][m-2] = '.'; mp[n][m-1] = '<'; mp[n][m] = '>';
		}
	}
	if((m & 1) && (n > 1)) {
		right = min(B, n/2);
		B -= right; right <<= 1;
		rep(i, 1, right) mp[i][m] = (i&1)? '^': 'v';
	}
	
	if((n&1) && (m&1)) so(1); else so(0);
	return 0;
}

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

#define MAX_N 200005
#define MAX_M 100005

#define pb push_back
#define mp make_pair
#define all(V) (V).begin(),(V).end()
#define reset(V) (V).clear();(V).resize(0);

#define sq(x) ((x)*(x))
#define abs(x) ((x)>0?(x):(-(x)))

#define fi first
#define se second

#define LL_inf (1LL<<60)
#define full_inf 0x7fffffff
#define half_inf 0x3fffffff
#define inf 0x3fffffff

#define MOD 1000000007LL

#define cpx_mod(x) (((LD)(((LL)x.real())%MOD)),((LD)(((LL)x.imag())%MOD)))


using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL> pil;
typedef pair<LL,string> pls;
typedef complex<LD> Complex;
typedef long double LD;
LL n,ans;
LL t[MAX_N][3],V[MAX_N];
void solve(){
	LL i,x;
	for(i=1;i<=n;i++){
		t[i][0]=max({0LL,t[i-1][0],t[i-1][1]})+(V[i]%2?V[i]:V[i]-1);
		if(V[i]==0)	x=-2;
		else if(V[i]==1)	x=0;
		else	x=V[i]/2*2;
		t[i][1]=max(0LL,t[i-1][1])+x;
		t[i][2]=max({0LL,t[i-1][0],t[i-1][1],t[i-1][2]})+x;
		ans=max({ans,t[i][0],t[i][1],t[i][2]});
	}
}
int main(){
	LL i;
	scanf("%lld",&n);
	for(i=1;i<=n;i++)	scanf("%lld",&V[i]);
	solve();
	
	for(i=1;i<=n/2;i++)	swap(V[i],V[n-i+1]);
	for(i=1;i<=n;i++)	t[i][0]=t[i][1]=t[i][2]=0;
	solve();
	ans=-ans;
	for(i=1;i<=n;i++)	ans+=V[i];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 6528
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int  a,b,c,d,i,j,k,x,y,z,ans,gay;
int f[100005],h[10010][1005][2],g[10010];
int main(){
	gay=0;
	ans=0;
	scanf("%d",&a);
	for (i=1;i<=a;i++) 	{
		scanf("%d",&f[i]);
		c=f[i]%10007;
		g[c]++;
		h[c][g[c]][0]=f[i];
		h[c][g[c]][1]=i;
	}
	sort(f+1,f+a+1);
	for (i=1;i<=a;i++){
		c=f[i]%10007;
		//printf("D%d\n",g[c]);
		for (j=1;j<=g[c];j++){
			if (h[c][j][0]==f[i]){
				//printf("E%d %d\n",h[c][j][0],h[c][j][1]);
				if (abs((h[c][j][1]-i)%2)==1) ans++;
				break;
			}
		}
	}
	printf("%d\n",(ans)/2);
}

Measured memory_bytes: 77824
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define trep(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main()
{
    int cc[3][3];
    rep(i, 3)
    {
        rep(j, 3)
        {
            cin >> cc[i][j];
        }
    }
    int a, b, c;
    a = cc[0][0] + cc[1][1] + cc[2][2];
    b = cc[0][1] + cc[1][2] + cc[2][0];
    c = cc[1][0] + cc[2][1] + cc[0][2];
    if (a == b && b == c)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

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

class Main{
    public static void main(String[] args){
	BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
	String st, sx[] = {"A", "B", "AB", "O"};
	int a=0, b=0, ab=0, o=0;
	try{
	    while((st=sc.readLine())!=null){
		String[] bld = st.split(",");
		if(bld[1].equals(sx[0]))
		    a++;
		else if(bld[1].equals(sx[1]))
		    b++;
		else if(bld[1].equals(sx[2]))
		    ab++;
		else
		    o++;
	    }
	    System.out.println(a);
	    System.out.println(b);
	    System.out.println(ab);
	    System.out.println(o);
	}catch(Exception e){
	    System.out.println("Error");
	}
    }
}

Measured memory_bytes: 9184
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
using namespace std;

struct Node{
    int key;
    Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k){
    Node *y = NIL;
    Node *x = root;
    Node *z;
    z = (Node *)malloc(sizeof(Node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;

    while(x!=NIL){
        y = x;
        if(z->key < x->key){
            x = x->left;
        }
        else{
            x = x->right;
        }
    }

    z->parent = y;
    if(y==NIL){
        root = z;
    }
    else{
        if(z->key < y->key){
            y->left = z;
        }
        else{
            y->right = z;
        }
    }
}

Node *find(Node *u, int k){
    while(u!=NIL && k != u->key){
        if(k<u->key) u = u->left;
        else u = u->right;
    }
    return u;
}

Node *treeMinimum(Node *x){
    while(x->left != NIL) x = x->left;
    return x;
}


Node * treeSuccessor(Node *x){
    if(x->right != NIL) return treeMinimum(x->right);
    Node *y = x->parent;
    while(y!=NIL&& x==y->right){
        x=y;
        y=y->parent;
    }
    
    return y;
}


void treeDelete(Node *z){
    Node *y; // 削除する対象
    Node *x; // y の子

    // 削除する接点を求める
    if(z->left == NIL || z->right==NIL) y=z;
    else y = treeSuccessor(z);

    // y の子を決める
    if(y->left != NIL) x = y->left;
    else x = y->right;

    if(x!=NIL) x->parent = y->parent;

    if(y->parent == NIL){
        root = x;
    }
    else{
        if(y==y->parent->left){
            y->parent->left = x;
        }
        else{
            y->parent->right = x;
        }
    }

    if(y!=z) z->key =y->key;

    free(y);
}

void inorder(Node *u){
    if(u == NIL) return;
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
}
void preorder(Node *u){
    if(u == NIL) return;
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
}

int main(int argc, char const *argv[])
{
    int n,x;
    string com;
    scanf("%d", &n);

    for(int i=0; i<n; i++){
        cin >> com;
        if(com == "find"){
            scanf("%d", &x);
            Node *t = find(root, x);
            if(t!=NIL) printf("yes\n");
            else printf("no\n");
        }
        else if(com == "insert"){
            scanf("%d", &x);
            insert(x);
        }
        else if(com == "print"){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
        else if(com == "delete"){
            scanf("%d", &x);
            treeDelete(find(root, x));
        }
    }

    return 0;
}



Measured memory_bytes: 21900
#include <stdio.h>
int main(){
	int n;
	scanf("%d",&n);
	int sum=0,tmp,tmpn=n,num=1000000000;
	while(num>=1){
		tmp=tmpn/num;
		tmpn=tmpn%num;
		num=num/10;
		sum=sum+tmp;
		}
	if(n%sum==0){
		printf("Yes");
		}
	else if(n%sum!=0){
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 128
N=int(input())
inf=float("inf")
Graph=[[inf]*N for i in range(N)]
ans=0
for i in range(N):
  a=[int(m) for m in input().split()]
  for j in range(i+1):
    Graph[i][j]=a[j]
    Graph[j][i]=a[j]
    ans+=a[j]

for i in range(N):
  for j in range(i+1):
    for k in range(N):
      if Graph[i][j]>Graph[i][k]+Graph[k][j]:
        print(-1)
        exit()
      elif Graph[i][j]==Graph[i][k]+Graph[k][j] and i!=k and j!=k:
        ans-=Graph[i][j]
        break

print(ans)

Measured memory_bytes: 48108
N, M = map(int, input().split())
L = []
for i in range(N):
    l = list(map(int, input().split()))
    L.append(l)
L.sort()
ans = 0
nes = M
for i in range(N):
    if nes >= L[i][1]:
        ans += L[i][0] * L[i][1]
        nes -= L[i][1]
    else:
        ans += L[i][0] * nes
        break
print(ans)


Measured memory_bytes: 27760
extern crate proconio;

use proconio::*;

fn main() {
    input! {
        n: usize,
        a: [u64; n],
    }
    let ans = a.into_iter().fold(1u64, |s, a| s.saturating_mul(a));
    if ans > 10u64.pow(18) {
        println!("-1");
    } else {
        println!("{}", ans);
    }
}


Measured memory_bytes: 4392
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<string.h>
using namespace std;

int n;
struct Road{
    int e,next;
}r[210000];int R[110000],num;
int f[110000],sz[110000],d[110000],ans;

void addr(int x,int y){
    r[++num]=(Road){y,R[x]};
    R[x]=num;
}

void dfs(int u,int fa){
    f[u]=fa;d[u]=d[fa]+1;sz[u]=1;
    for(int i=R[u];i;i=r[i].next){
        int v=r[i].e;
        if(v==fa)continue;
        dfs(v,u);
        sz[u]+=sz[v];
    }
}

int main(){
    int x,y;
    scanf("%d",&n);
    for(int i=1;i<n;i++){
        scanf("%d %d",&x,&y);
        addr(x,y);addr(y,x);
    }dfs(1,0);
    int dep=d[n]-d[n]/2+1;
    int v=n;
    while(d[v]>dep)v=f[v];
    ans=sz[v];
    if(ans>=n-ans)printf("Snuke\n");
    else printf("Fennec\n");
    return 0;
}

Measured memory_bytes: 8064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
#include <map>
#include <cstdio>
#include <cmath>
#include <unordered_map>
#include <iomanip>
using namespace std;

int main(){
  int N,M,ac=0,wa=0;
  cin >> N >> M;
  int p[M];
  int check[N], ch2[N];
  for (int i = 0; i < N; i++){
    check[i] = 0;
    ch2[i] = 0;
  }
  string S[M];
  for (int i = 0; i < M; i++){
    cin >> p[i] >> S[i];
    if (S[i] == "AC"){
      check[p[i]-1] = 1;
    }
  }
  for (int i = 0; i < M; i++){
    if (S[i] == "WA" && check[p[i]-1] == 1 && ch2[p[i]-1] == 0){
      wa++;
    }
    if (check[p[i]-1] == 1 && S[i] == "AC" && ch2[p[i]-1] == 0){
      ac++;
      ch2[p[i]-1] = 1;
    }
  } 
  cout << ac << " " << wa << endl;
}

Measured memory_bytes: 6912