akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;

struct Edge {
	int from;
	int to;
	int cost;
	int time;
	int compa;
};

struct aa {
	int now;
	int time;
	int cost;
};
class Compare {
public:
	//aa?????????????????¶
	bool operator()(const aa&l, const aa&r) {
		return l.cost> r.cost;
	}
};
int main() {
	while (1) {
		
		int N, M, H, K; cin >> N >> M >> H >> K;
		if (!N)break;
		vector<vector<Edge>>edges(N);
		for (int i = 0; i < M; ++i) {
			int a, b, c, h, r; cin >> a >> b >> c >> h >> r; 
			a--; b--; r--;
			edges[a].push_back(Edge{ a, b, c,h,r });
			edges[b].push_back(Edge{ b,a, c,h,r });
		}
		int S, T; cin >> S >> T; S--; T--;
		int P; cin >> P;
		vector<int>passcost;
		vector<vector<bool>>frees(P,vector<bool>(K,false));
		for (int p = 0; p < P; ++p) {
			int l, d; cin >> l >> d;
			passcost.push_back(d);
			for (int j = 0; j < l; ++j) {
				int k; cin >> k; k--;
				frees[p][k] = true;
			}
		}
		vector<int> dp(1<<K,1e8);
		dp[0] = 0;
		for (int i = 0; i < (1 << K); ++i) {
			bitset<8>bs(i);
			for (int p = 0;p< passcost.size(); ++p) {
				bitset<8>newbs(bs);
				for (int k = 0; k < K; ++k) {
					if (frees[p][k])newbs[k] = true;
				}
				dp[newbs.to_ulong()] = min(dp[newbs.to_ulong()], dp[i] + passcost[p]);
			}
		}
		int ans = 1e8;

		for (int i = 0; i < (1 << K); ++i) {
			vector<vector<int>>memo(N, vector<int>(H + 1, 1e8));
			bitset<8>bs(i);
			vector<bool>free(K);
			int money = dp[i];
			priority_queue<aa, vector<aa>, Compare>que;
			que.push(aa{ S,0,0 });
			memo[S][0] = 0;

			while (!que.empty()) {
				aa atop(que.top());
				que.pop();
				const int nowplace = atop.now;
				const int nowtime = atop.time;
				const int nowcost = atop.cost;
				for (auto e : edges[nowplace]) {
					const  int nextplace = e.to;
				const int nextcost = bs[e.compa] ? nowcost : nowcost + e.cost;
					const int nexttime = nowtime + e.time;
					if (nexttime > H)continue;
					else if (nextcost < memo[nextplace][nexttime]) {
						memo[nextplace][nexttime] = nextcost;
						que.push(aa{ nextplace,nexttime,nextcost });
					}
				}
			}
			for (int h = 0; h <= H; ++h) {
				if (memo[T][h] < 9e7) {
					ans = min(ans, money + memo[T][h]);
				}
			}
		}
		if (ans>9e7)ans = -1;
		cout << ans<< endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 3264
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main(){
	while(1){
		int n;
		cin>>n;
		if(n==0) break;
		int m;
		cin>>m;
		vp a(m);
		for(int i=0;i<m;i++) cin>>a[i].first>>a[i].second;
		for(int i=0;i<n;i++){
			cin>>m;
			vp b(m);
			for(int j=0;j<m;j++) cin>>b[j].first>>b[j].second;
			if(a.size()!=m) continue;
			bool B=1;
			int I=-1;
			for(int j=0;j<m-1;j++){
				int x=a[j+1].first-a[j].first,y=a[j+1].second-a[j].second;
				int x_=b[j+1].first-b[j].first,y_=b[j+1].second-b[j].second;
				for(int k=0;k<4;k++){
					if(x==x_&&y==y_){
						if(I==-1) I=k;
						else if(I!=k) B=0;
						break;
					}
					swap(x,y);
					y*=-1;
					if(k==3) B=0;
				}
			}
			if(B) cout<<i+1<<endl;
			else{
			reverse(b.begin(),b.end());
			B=1;
			I=-1;
			for(int j=0;j<m-1;j++){
				int x=a[j+1].first-a[j].first,y=a[j+1].second-a[j].second;
				int x_=b[j+1].first-b[j].first,y_=b[j+1].second-b[j].second;
				for(int k=0;k<4;k++){
					if(x==x_&&y==y_){
						if(I==-1) I=k;
						else if(I!=k) B=0;
						break;
					}
					swap(x,y);
					y*=-1;
					if(k==3) B=0;
				}
			}
			if(B) cout<<i+1<<endl;
			}
		}
		cout<<"+++++"<<endl;
	}
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long

vector<vector<ll> >v;
vector<vector <ll>>dp;

bool compare(vector<ll>&a,vector<ll>&b){
ll w1 = a[0],s1=a[1],w2=b[0],s2=b[1];
return w1+s1 > w2+s2;
}
void solve(){
ll n;cin>>n;
v.resize(n,vector<ll>(3));
dp.resize(n,vector<ll>(10001));
for(ll i=0;i<n;i++){
cin>>v[i][0]>>v[i][1]>>v[i][2];
}
sort(v.begin(),v.end(),compare);
for(ll i=0;i<=v[0][1];i++){
dp[0][i]=v[0][2];
}
for(ll i=1;i<n;i++){
for(ll j=0;j<=10001;j++){
dp[i][j] = dp[i-1][j];
if(j<=v[i][1]){
dp[i][j] = max(dp[i-1][j],v[i][2]+(j+v[i][0]<=10000 ? (dp[i-1][j+v[i][0]]):0));
}
}
}
cout <<dp[n-1][0]<<"\n";

}

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

/*
    #ifndef ONLINE_JUDGE
        freopen("input.txt",  "r",  stdin);
        freopen("output.txt", "w", stdout);
    #endif
//*/

        
cout.precision(10);
int t=1;//cin>>t;
while(t--){
    solve();
}
return 0;
}

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

using namespace std;

int main()
{
    int a,b;
    while(cin>>a>>b)
    {
        if(a%3==0||b%3==0||(a+b)%3==0)
        {
            cout<<"Possible"<<endl;
        }
        else
        {
            cout<<"Impossible"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)

int main(void){
  int n,m;
  cin>>n>>m;
  vector<int> r(n,0);
  vector<int> w(n,1);
  r[0] = 1;
  int a,b;
  

  while(m--){
    cin>>a>>b;
    --a,--b;
    if(w[a]==1&&r[a]==1){
      w[a]=0;
      r[a]=0;
      r[b]=1;
      w[b]++;
    }else{
      if(r[a]==1){
        r[b]=1;
      }
      w[b]++; 
      w[a]--;
    }
    //cout<<a<<" "<<b<<endl;
    //cout<<"r";rep(i,n)cout<<r[i]<<" ";cout<<endl;
    //cout<<"w";rep(i,n)cout<<w[i]<<" ";cout<<endl;

  }
  int ret = 0;
  rep(i,n)if(r[i])ret++;
  cout<<ret<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long long dp[405][405];

int main(){
  int n;cin>>n;
  vector<long long> arr(n+1);
  for(int i=0;i<n;++i){
    cin>>arr[i];
  }
  vector<long long> sum(n);
  for(int i=0;i<n;++i){
    sum[i] = arr[i];
    if(i>0){
      sum[i] += sum[i-1];
    }
  }
  
  for(int len=2;len<=n;++len){
    for(int start=0;start+len<=n;++start){
      int l = start;
      int r = start+len-1;
      dp[start][len] = 1e18;
      long long penlty = 0;
      for(int k = l+1;k<=r;++k){
        if (l==0){
          penlty = sum[r];
        } else {
          penlty = sum[r]-sum[l-1];
        }
        dp[start][len] = min(dp[start][len],dp[l][k-l]+dp[k][r-k+1]+penlty);
      }
      
      /*
      dp[start][len] = min(	
                        arr[start] + dp[start+1][len-1]
        				,
      				    dp[start+1][len-1] + arr[start+len-1] 
      					);
      */
    }
  }
  /*
  for(int i=0;i<=n;++i){
    for(int j=0;j<=n;++j){
      cout<<dp[i][j]<<" ";
    }
    cout<<endl;
  }
  */
  cout<<dp[0][n]<<endl;
  return 0;
}


Measured memory_bytes: 1536
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE BangPatterns #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust, fromMaybe )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.IntMap.Lazy            as IML
import qualified Data.Map.Strict               as M
import           Data.Char
import qualified Data.Array.IArray as A
import qualified Data.Array.Unboxed as UA
import Data.Bits
import Control.Monad.State.Strict
import qualified Data.Array.ST as STA
import qualified Data.Array.IO as IOA
import qualified Data.Array.MArray as MA
import Control.Monad.ST
import System.IO (stdin)
import Control.Arrow
import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector.Generic as GV



readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- readInts
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- readInts
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

modN = 2019

pow :: Num a => a -> Int -> a
pow base 0 = 1
pow base 1 = base
pow base time
    | odd time = let 
        a = pow base (div time 2)
        in
        a * a * base
    | otherwise = let
        a = pow base (div time 2)
        in
        a * a

inv :: ModNum -> ModNum
inv a = pow a $ modN - 2

newtype ModNum = ModNum {getInt :: Int} deriving (Show, Eq, Ord)
instance Num ModNum where
    (+) (ModNum a) (ModNum b) = ModNum $ mod (a + b) modN
    (-) (ModNum a) (ModNum b)
            | a < b = (ModNum $ a + modN) - ModNum b
            | otherwise = ModNum $ mod (a - b) modN
    (*) (ModNum a) (ModNum b) = ModNum $ mod (a * b) modN
    abs (ModNum a)
        | a < 0 = abs . ModNum $ a + modN
        | otherwise = ModNum a
    signum (ModNum a) = ModNum $ signum a
    fromInteger i = abs . ModNum . fromIntegral $ mod i (fromIntegral modN)

mDiv :: ModNum -> ModNum -> ModNum
mDiv a b = a * inv b

chooseTwo :: Int -> Int
chooseTwo 0 = 0
chooseTwo 1 = 0
chooseTwo a = a * (a - 1) `div` 2

solve :: BC.ByteString -> Int
solve s = sum $ chooseTwo <$> intCount where
    ints = (BC.unpack . BC.reverse) s
    intList :: [ModNum]
    !intList = zipWith (\time base -> base * pow 10 time)  [0..] $ fromIntegral . digitToInt <$> ints
    sumacc = scanl' (+) 0 intList
    intCount :: [Int]
    intCount = fmap snd $ M.toList $ foldl' (\m n -> M.alter (Just . maybe 1 (+1)) n m) M.empty sumacc

main = do
    n <- BC.getLine
    print $ solve n


Measured memory_bytes: 6168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=1<<20,INF=1<<28;
ll dp[MAX];

ll rui(ll a,ll b){
    ll ans=1;
    while(b>0){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return ans;
}
ll bit[MAX+1],H;

//1-indexed

ll sum(int i){
    ll s=0;
    while(i>0){
        s+=bit[i];
        i-=i&-i;
        s%=mod;
    }
    return s;
}

//sからtの和=sum(t)-sum(s-1)

void add(int i,ll x){
    while(i<=H){
        bit[i]+=x;
        bit[i]%=mod;
        i+=i&-i;
    }
}


int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll N,D;cin>>N>>H>>D;
    H++;
    
    ll bik=1;
    ll s=0;
    for(ll i=1;i<=N;i++){
        bik*=i;
        bik%=mod;
        s+=bik;
        s%=mod;
    }
    
    dp[1]=bik*rui(s,mod-2)%mod;
    
    add(1,dp[1]);
    
    for(int i=2;i<=H;i++){
        dp[i]=(sum(i-1)-sum(i-D-1)+mod)%mod*s;
        dp[i]%=mod;
        
        add(i,dp[i]);
    }
    
    cout<<dp[H]<<endl;
}


Measured memory_bytes: 16640
#include <iostream>
using namespace std;
 
int calcDistance(int figure1,int figure2){
  if((figure1-figure2)>=0){
    return figure1-figure2;
  }
  else{
    return figure2-figure1;
  }
}

bool dicision(int distance,int k){
  if((k-distance)>=0){
    return true;
  }
  else{
    return false;
  }
}

int main() {
  // ここにプログラムを追記
  int a,b,c,d,e,k;
  cin>>a>>b>>c>>d>>e>>k;
  if( dicision(calcDistance(a,b),k) &&
      dicision(calcDistance(a,c),k) &&
      dicision(calcDistance(a,d),k) &&
      dicision(calcDistance(a,e),k) &&
      dicision(calcDistance(b,c),k) &&
     
      dicision(calcDistance(b,d),k) &&
      dicision(calcDistance(b,e),k) &&
      dicision(calcDistance(c,e),k) &&
      dicision(calcDistance(c,d),k) &&
      dicision(calcDistance(d,e),k) ){
    cout<<"Yay!"<<endl;
    }
    else{
      cout<<":("<<endl;
    }
      
  
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static Scanner sc;
	public static void main(String[] args) {
		sc=new Scanner(System.in);
		int n[]=new int[15];
		int score[][]=new int[15][1000];
		double ans[]=new double[1000];
		int i=0;
		int count=0;
		for(;;) {
			n[i]=sc.nextInt();
			if(n[i]==0) {
				break;
			}
			for(int j=0;j<n[i];j++) {
				score[i][j]=sc.nextInt();
				//System.out.print(i+" "+j+"="+score[i][j]+"\n");
			}
			i++;
			count++;
		}
		//平均の取得
		double m[]=new double[15];
		int sum=0;
		for(i=0;i<count;i++) {
			for(int j=0;j<n[i];j++) {
				sum+=score[i][j];
			}
			m[i]=(double)sum/n[i];
			//System.out.println(i+" "+m[i]);
			sum=0;
		}
		//標準偏差
		double Sum=0;
		for(i=0;i<count;i++) {
			for(int j=0;j<n[i];j++) {
				Sum+=(double)(score[i][j]-m[i])*(score[i][j]-m[i]);
				//System.out.print(i+" "+j+":"+Sum+"\n");
			}
			ans[i]=Math.sqrt((double)Sum/n[i]);
			//System.out.print(ans[i]);
			Sum=0;
		}
		for(i=0;i<count;i++) {
			System.out.printf("%.08f\n",ans[i]);
		}
	}
}



Measured memory_bytes: 33200
#include <stdio.h>

void input(int loop, int *);

int main(void) {
    int N, last_num = -1, manzoku_sum = 0;
    scanf("%d", &N);
    int A[N], B[N], C[N - 1];
    input(N, A);
    input(N, B);
    input(N - 1, C);
    for (int i = 0; i < N; i++) {
        manzoku_sum += B[A[i] - 1];
        if (last_num + 1 == A[i]) {
            manzoku_sum += C[last_num - 1];
        }
        last_num = A[i];
    }
    printf("%d\n", manzoku_sum);
    return 0;
}

void input(int loop, int *array) {
    int tmp;
    for (int i = 0; i < loop; i++) {
        scanf("%d", &tmp);
        array[i] = tmp;
    }
}


Measured memory_bytes: 128
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	
	A := ScanInt(scanner)
	B := ScanInt(scanner)
	
	ans := 0
	for i := A; i <= B; i++ {
	    x := strconv.Itoa(i)
	    var y []byte
	    for j := len(x) - 1; j >= 0; j-- {
	        y = append(y, x[j])
	    }
	    if string(y) == x {
	        ans++
	    }
	}
	fmt.Println(ans)
}

func ScanInt(scanner *bufio.Scanner) int {
	scanner.Scan()
	i, e := strconv.Atoi(scanner.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func ScanFloat64(scanner *bufio.Scanner) float64 {
	scanner.Scan()
	f, e := strconv.ParseFloat(scanner.Text(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func ScanText(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

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

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

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

Measured memory_bytes: 2048
package main

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

func getNextLine(scanner *bufio.Reader) string {
	var buffer string
	for {
		line, isPrefix, _ := scanner.ReadLine()
		buffer += string(line)
		if isPrefix == false {
			break
		}
	}
	return buffer
}

func getIntList(scanner *bufio.Reader) []int {
	list := strings.Split(getNextLine(scanner), " ")
	l := len(list)
	result := make([]int, l)
	for i := 0; i < l; i++ {
		result[i], _ = strconv.Atoi(list[i])
	}
	return result
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := bufio.NewReader(fp)

	var n, k int
	fmt.Sscan(getNextLine(scanner), &n, &k)
	dp := make([]float64, 200000+1)
	for i := 1; i <= n; i++ {
		dp[i] = 1 / float64(n)
	}
	var ans float64
	for i := 0; i < k; i++ {
		dp[i*2] += dp[i] / 2.0
	}
	for i := k; i <= 200000; i++ {
		ans += dp[i]
	}
	fmt.Println(ans)
}


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

██╗    ██╗██████╗ ██╗████████╗████████╗███████╗███╗   ██╗    ██████╗ ██╗   ██╗
██║    ██║██╔══██╗██║╚══██╔══╝╚══██╔══╝██╔════╝████╗  ██║    ██╔══██╗╚██╗ ██╔╝
██║ █╗ ██║██████╔╝██║   ██║      ██║   █████╗  ██╔██╗ ██║    ██████╔╝ ╚████╔╝
██║███╗██║██╔══██╗██║   ██║      ██║   ██╔══╝  ██║╚██╗██║    ██╔══██╗  ╚██╔╝
╚███╔███╔╝██║  ██║██║   ██║      ██║   ███████╗██║ ╚████║    ██████╔╝   ██║
 ╚══╝╚══╝ ╚═╝  ╚═╝╚═╝   ╚═╝      ╚═╝   ╚══════╝╚═╝  ╚═══╝    ╚═════╝    ╚═╝

     ███╗   ███╗   ██╗██████╗ ██████╗  █████╗ ██╗  ██╗██╗███╗   ███╗
     ████╗ ████║   ██║██╔══██╗██╔══██╗██╔══██╗██║  ██║██║████╗ ████║
     ██╔████╔██║   ██║██████╔╝██████╔╝███████║███████║██║██╔████╔██║
     ██║╚██╔╝██║   ██║██╔══██╗██╔══██╗██╔══██║██╔══██║██║██║╚██╔╝██║
     ██║ ╚═╝ ██║██╗██║██████╔╝██║  ██║██║  ██║██║  ██║██║██║ ╚═╝ ██║
     ╚═╝     ╚═╝╚═╝╚═╝╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝╚═╝     ╚═╝
*/
#define speed  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FOR(n) for(int i=0;i<n;i++)
#define For(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define E "\n"
#define all(e) e.begin(),e.end()
#define F first
#define S second
#define pi (acos(-1))
#define rad(x) ((x*pi)/(ld)(180))
#define perc(x) fixed<<setprecision(x)
/*****
#define cross(a, b) ((conj(a) * (b)).Y)
#define dot(a, b) ((conj(a) * (b)).X)
#define vec(a,b) ((b) - (a))
#define rot(p,angle) (p)*polar((double)(1),angle)
#define rot2(p,angle,a) ((p)-(a)) *(polar((ld)(1),angle)+ (a))
#define x real()
#define y imag()
*****/
typedef long long int ll; typedef unsigned long long ull; typedef long double ld;typedef complex<ld> point; typedef tuple<double,double,double> line;
ll gcd(ll x,ll y){if(!y)return x; return gcd(y,x%y);};   ll lcm(ll x,ll y){return (x*y)/__gcd(x,y);}
const int N=1e3+1;
ll dp[N][N],n,m,mod=1e9+7;
char arr[N][N];

ll solve(int i,int j)
{
    
    if(dp[i][j]!=-1)return dp[i][j];

    if(i == n or j == m)return 0;
    if(i == n-1 and j == m-1)return 1;
    if(arr[i][j]=='#')return 0;
    

    dp[i][j] = (solve(i,j+1) + solve(i+1,j) ) % mod;

    return dp[i][j];
}

int main(){ speed;
memset(dp,-1,sizeof dp);
cin>>n>>m;

for(int i=0;i<n;i++)for(int j=0;j<m;j++)cin>>arr[i][j];
//for(int i=0;i<n;i++){for(int j=0;j<m;j++)cout<<arr[i][j]<<' ';cout<<E;}
cout<<solve(0,0);

return 0;}


Measured memory_bytes: 9216
#include "bits/stdc++.h"
#define rep(i, j) for (long long i = j; i > 0; i--)
using namespace std;


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

	vector<long long> a(n + 1);
	for (long long i = 0; i < n + 1; i++)
		cin >> a[i];
	
	vector<long long> b(n);
	for (long long i = 0; i < n; i++)
		cin >> b[i];

	long long ans = 0;

	for (int i = 0; i < n; i++) {
		if (a[i] >= b[i]) {
			ans += b[i];
		}
		else {
			ans += a[i];
			b[i] -= a[i];
			if (a[i + 1] >= b[i]) {
				ans += b[i];
				a[i + 1] -= b[i];
			}
			else {
				ans += a[i + 1];
				a[i + 1] = 0;
			}
		}
	}

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

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

class weighted_unionfind {
  vector<int> par, weight, s;
  
public:
  weighted_unionfind(int n) {
    for (int i = 0; i < n; i++) {
      par.push_back(i);
      weight.push_back(0);
      s.push_back(1);
    }
  }
  
  int find(int n) {
    if (par.at(n) == n) return n;
    return find(par.at(n));
  }
  
  void merge(int m, int n, int d) {
    d += diff(m) - diff(n);
    m = find(m); n = find(n);
    if (s.at(m) < s.at(n)) {
      swap(m, n);
      d = -d;
    }
    par.at(n) = m;
    weight.at(n) = d;
    if (s.at(m) == s.at(n)) s.at(m)++;
  }
  
  int diff(int n) {
    if (par.at(n) == n) return 0;
    return weight.at(n) + diff(par.at(n));
  }
};

int main() {
  int n, m;
  cin >> n >> m;
  weighted_unionfind t(n);
  for (int i = 0; i < m; i++) {
    int l, r, d;
    cin >> l >> r >> d;
    l--; r--;
    if (t.find(l) != t.find(r)) {
      t.merge(l, r, d);
    } else {
      if (t.diff(r) - t.diff(l) != d) {
        puts("No");
        return 0;
      }
    }
  }
  puts("Yes");
}


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

int main() {
    int N,a,ret=0,j;
    cin>>N;
    for(;N>0;N--){
        cin>>a;
        if(a==2) ret++;
        else if(a%2>0){
            for(j=3;j*j<=a;j+=2) if(a%j==0) break;
            if(j*j>a) ret++;
        }
    }
    cout<<ret<<endl;
    return 0;
}


Measured memory_bytes: 3120
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	int n,k,c=0;
    cin>>n>>k;
    while(n!=0){
        c++;
        n/=k;
    }
    cout<<c;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <math.h>

using namespace std;

#define MAX_N 105

int X, N;
set<int> p;
vector<int> q;
int t;

int main() {
  cin >> X >> N;
  for (int i = 0; i < N; i++) {
    cin >> t;
    p.insert(t);
  }
  for (int i = -10; i <= 110; i++) {
    if (p.count(i) == 0) q.push_back(i);
  }

  int ans = -1;
  for (int i = 0; i < q.size(); i++) {
    if (ans < 0) {
      ans = i;
    } else if (abs(q[i] - X) < abs(q[ans] - X)) {
      ans = i;
    } else if (abs(q[i] - X) == abs(q[ans] - X)) {
      if (q[i] < q[ans]) ans = i;
    }
  }
  cout << q[ans] << endl;
}


Measured memory_bytes: 3680
#include <stdio.h>

int main(void){
	int a[4],b[4], i, j, hit, blow;
	while(scanf("%d %d %d %d %d %d %d %d",&a[0],&a[1],&a[2],&a[3],&b[0],&b[1],&b[2],&b[3])==8){
		hit=0, blow=0;
		for(i=0; i<4; i++) for(j=0; j<4; j++){
			if(a[i]==b[j]){
				if(i==j) hit++;
				else blow++;
			}
		}
		printf("%d %d\n",hit,blow);
	}
	return 0;
}

Measured memory_bytes: 0
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<string>
using namespace std;

long gcd(long x, long y) { if (x > y) { return gcd(y, x); } long r; while (y != 0) { r = x % y; x = y; y = r; }return x; }
long lcm(long x, long y) { return(x / gcd(x, y)) * y; }
void indexsort(long* first, long* last, long* func) { sort(first, last, [&](long a, long b) {return func[a] < func[b]; }); }
//--------------------

int main() {

	long N; cin >> N;
	long A[100009]; for (int i = 1; i <= N; i++) cin >> A[i];
	sort(A + 1, A + N + 1);

	long first = 0;

	for (int i = N; i >= 2; i--) if (A[i] == A[i - 1]) {

		if (first == 0) first = A[i]; else { cout << first * A[i] << endl; return 0; }

		A[i] = INT_MAX;
		A[i - 1] = INT_MAX;
	}

	cout << 0 << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;
 
 
signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
 
  string S;
  cin >> S;
  if(S == "SUN") cout << 7 << endl;
  else if(S == "SAT") cout << 1 << endl;
  else if(S == "FRI") cout << 2 << endl;
  else if(S == "THU") cout << 3 << endl;
  else if(S == "WED") cout << 4 << endl;
  else if(S == "TUE") cout << 5 << endl;
  else if(S == "MON") cout << 6 << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int X,Y;
    scanf("%d %d",&X,&Y);
    
    if(Y%2==0 && 4*X-Y >= 0 && -2*X+Y >= 0)
        printf("Yes\n");
    else
        printf("No\n");
}


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

int main() {
    int n, x; cin >> n >> x;
    vector<int> X(n);

    rep(i, n) cin >> X[i];
    int ans = 1;
    vector<int> b;
    rep(i, n) {
        b.push_back(abs(x-X[i]));
    }
    if (b.size() == 1) {
        cout << b[0] << endl;
        return 0;
    }
    for (int i = 1; i < b.size(); i++) {
        if (i == 1) {
            ans = __gcd(b[0], b[1]);
            continue;
        }
        ans = __gcd(ans, b[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1276
k, t = map(int, input().split())
A = list(map(int, input().split()))

if t == 1:
    print(k-1)
    exit()

ans = 0
before = -1
for i in range(k):
    A.sort(reverse=True)
    # print(A)
    if A[0] == before-1:
        if A[1] == 0:
            before = A[0]
            A[0] -= 1
            ans += 1
        else:
            before = A[1]
            A[1] -= 1
    else:
        before = A[0]
        A[0] -= 1
    before
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; ++i)
#define repR(i, n) for(ll i = n; i >= 0; ++i)
#define FDS(i, n) for(ll i = 0; i < n; ++i)
#define FDSR(i, n) for(ll i = n; i >= 0; ++i)
#define FOR(i, m, n) for(ll i = m; i < n; ++i)
#define FORR(i, m, n) for(ll i = m;i >= n;--i)
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define itn ll
#define ednl endl
using namespace std;
typedef long long ll;template<typename Typell>Typell G_C_D(Typell a, Typell b){if (a < 0) a = -a;if (b < 0) b = -b;while (b != 0) {a %= b;if (a == 0) return b;b %= a;}return a;}template<typename Typell>
Typell G_C_D(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = G_C_D(a, list[i]);}return a;}template<typename Typell>Typell L_C_M(Typell a, Typell b) {if( a == 0 && b == 0)return 0;return a / G_C_D(a, b) * b;}
template<typename Typell>Typell L_C_M(const std::vector<Typell> &list){Typell a = list[0];for (size_t i = 1; i < list.size(); ++i) {a = L_C_M(a, list[i]);}return a;}

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	
	int N;
	cin>>N;
	vector<int> V(N);
	vector<int> C(N);
	vector<int> sou(N);
	FDS(i,N){
		cin>>V[i];
	}
	FDS(i,N){
		cin>>C[i];
	}	
	FDS(i,N){
		sou[i]=V[i]-C[i];
	}
	int sum=0;
	FDS(i,N){
		if(sou[i]>0){
			sum+=sou[i];
		}
	}
	cout<<sum<<endl;
}

Measured memory_bytes: 256
// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
// ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
// [███████████████████].░░░░░░░░░░░░░░
// ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░

//PointBlank's code (⌐■_■)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
 
ll power(ll x, ll y); 
#define repp(I, A, B) for(int I = A; I <= B; I++)
#define rep(I, A, B) for(int I = A; I < B; I++)
#define rrep(I, B, A) for(int I = B; I >= A; I--)
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define mem(A, B) memset(A, B, sizeof(A));
#define mem0(A) memset(A, 0, sizeof(A));
#define quickio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define bitcount(n) __builtin_popcountll(n)
#define in_edges(M) repp(I, 1, M){ll A, B; cin >> A >> B; v[A].pb(B), v[B].pb(A);}
#define in_edges2(M) repp(I, 1, M){ll A, B; cin >> A >> B; v[A].pb(B);}
#define endl "\n"

const ll MOD = 1000000007;

ll ncr(ll n, ll r){
    if(n < r) return 0ll;
    ll res = 1;
    rep(i, 0, r) res *= (n - i);
    repp(i, 2, r) res /= i;
    return res;
}
 
int main() //PointBlank's code ¯\_(ツ)_/¯
{
    string s;
    cin >> s;
    int n = s.size();
    int k;
    cin >> k;
    s += '0';

    ll x = n, y = n;
    rep(i, 1, n) if(s[i] != '0'){x = i; break;}
    rep(i, x + 1, n) if(s[i] != '0'){y = i; break;}

    ll res = ncr(n, k);
    rep(i, 0, k) res *= 9;

    if(k == 1) res -= (9 - s[0] + '0');

    if(k == 2){
        if(x == n) res -= (10 - s[0] + '0')*(n-1)*9;
        else
            res -= (9 - s[x] + '0'),
            res -= (x - 1)*9,
            res -= (9 - s[0] + '0')*(n-1)*9;
    }

    if(k == 3){
        if(x == n && y == n) res -= (10 - s[0] +'0')*ncr(n-1, 2)*9*9;
        if(x < n && y == n){
            res -= (10 - s[x] + '0')*(n - x - 1)*9,
            res -= (x - 1) * (n - x) * 81,
            res -= (9 - s[0] + '0')*ncr(n-1, 2)*81;
        }
        if(x < n && y < n){
            res -= (9 - s[y] + '0'),
            res -= (y - x - 1)*9,
            res -= (9 - s[x] + '0')*(n - x - 1)*9,
            res -= (x - 1)*9*(n - x)*9,
            res -= (9 - s[0] + '0')*ncr(n-1, 2)*9*9;
        }
    }

    ll ans = 0;
    rep(i, 2, n-1) ans += (i*(i-1))/2 * 9 * 9 * 9;
	ans += max(0,(s[0]-'0'-1) * (n-1) * (n-2) / 2 * 9 * 9);
    rep(i, 1, n){
		if(s[i] != '0'){
			ans += max(0,(s[i]-'0'-1) * (n-i-1) * 9);
			ans += max(0,(n-i-1)*(n-i-2) / 2 * 9 * 9);
			for(int j=i+1;j<n;j++){
				if(s[j] != '0'){
					
					ans += s[j]-'0';
					ans += max(0,(n-j-1)*9);
					
					break;
				}
			}
			break;
		}
	}

    if(k == 3) cout << ans;
    else cout << res;
}

ll power(ll x, ll y)
{ 
    ll res = 1; x %= MOD;
    while(y > 0){if(y & 1) res = (res*x) % MOD; y = y>>1, x = (x*x) % MOD;} 
    return res; 
}

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

int main(){
  double a,b,h,m;cin>>a>>b>>h>>m;
  
  double sita=min(abs((h*30+m*0.5)-(m*6)),360-abs((h*30+m*0.5)-(m*6)));
  double ans=sqrt(a*a+b*b-2*a*b*cos(M_PI/180*sita));
  
  cout<<fixed<<setprecision(18);
  cout<<ans<<endl;
}

Measured memory_bytes: 4220
#include<iostream>
using namespace std;
int main()
{
    string a,b,c,y,x,q;
    cin>>a>>b>>c;
    if((a[0]>='a'&&a[0]<='z')&&(b[0]>='a'&&b[0]<='z')&&(c[0]>='a'&&c[0]<='z'))
    {
        y=a[0]-32;
        cout<<y;
        x=b[0]-32;
        cout<<x;
        q=c[0]-32;
        cout<<q;
    }

    return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var sc = new Scanner();
            int x = sc.NextInt();
            int y = sc.NextInt();
            int z = sc.NextInt();
            int p = sc.NextInt();
            long[] a = new long[x];
            long[] b = new long[y];
            long[] c = new long[z];
            for (int i = 0; i < x; i++) a[i] = sc.NextLong();
            for (int i = 0; i < y; i++) b[i] = sc.NextLong();
            for (int i = 0; i < z; i++) c[i] = sc.NextLong();

            Array.Sort(a); Array.Reverse(a);
            Array.Sort(b); Array.Reverse(b);
            Array.Sort(c); Array.Reverse(c);

            var list = new List<long>(3000);
            var ab = new List<long>(p);
            for (int i = 0; i < x; i++)
                for (int j = 0; j < y; j++)
                    ab.Add(a[i] + b[j]);
            ab.Sort(); ab.Reverse();

            for (int i = 0; i < z; i++)
            {
                for (int j = 0; j < ab.Count; j++)
                {
                    if (j > p) break;
                    list.Add(ab[j] + c[i]);
                }
            }

            list.Sort();
            list.Reverse();

            for (int i = 0; i < p; i++)
            {
                Console.WriteLine(list[i]);
            }
        }
    }

    class Scanner
    {
        int index = -1;
        string[] buf;

        public Scanner()
        {
        }

        public int NextInt()
        {
            CheckNext();
            return int.Parse(buf[index++]);
        }

        public long NextLong()
        {
            CheckNext();
            return long.Parse(buf[index++]);
        }

        public string NextString()
        {
            CheckNext();
            return buf[index++];
        }

        private void CheckNext()
        {
            if (index >= 0 && index < buf.Length) return;

            buf = Console.ReadLine().Split(' ');
            index = 0;
        }
    }
}


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

int main(){

    int n,d;
    cin>>n>>d;
    int ans=0;

    vector<vector<int>> x(n,vector<int>(d));

    for(int i=0;i<n;i++){
        for(int j=0;j<d;j++){
            cin>>x[i][j];
        }
    }

    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            double sum=0;
            for(int k=0;k<d;k++){
                sum+=(x[j][k]-x[i][k])*(x[j][k]-x[i][k]);
            }
            double root=sqrt(sum);
            if(root-(int)root==0) ans++;

        }
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N, A[123];

int main() {

	cin >> N;
	rep(i, N) cin >> A[i];

	bool f = true;
	rep(i, N) {
		if (A[i] % 2 == 0) {
			if (A[i] % 3 && A[i] % 5) {
				f = false;
				break;
			}
		}
	}

	if (f) cout << "APPROVED" << endl;
	else cout << "DENIED" << endl;

	return 0;
}


Measured memory_bytes: 384
N = int(input())
src = list(map(int,input().split()))

prev = -1
seq = 1
ans = 0
for a in src:
    if prev == a:
        seq += 1
    else:
        ans += seq//2
        seq = 1
    prev = a

if seq > 1:
    ans += seq//2
print(ans)

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

	private static int X(int [] a, int [] b, int C) {
		int num = 0;
		int sum = C;
		for (int i = 0; i < a.length; i++) {
			sum += a[i] * b[i];

		}
		if (sum > 0)
			num = 1;
		return num;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int C = sc.nextInt();
		
		int [] A = new int [M];
		int [] B = new int [M];
		
		for ( int j = 0; j < M; j++) {
			B[j] = sc.nextInt();
		}
		int result = 0; 
		for ( int i = 0; i < N; i++) {
			for ( int j = 0; j < M; j++) {
				A[j] = sc.nextInt();
			}
			result += X(A, B, C);
		}
		
		System.out.println(result);
	}

}


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

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

	int r[w*2];
	for (int i=0; i<w; i++) {
		for (int j=0; j<2; j++) {
			cin>>r[i+w*j];
		}
	}

	long long t = 1, a = 1, s;
	for (int i=0; i<w; i++) {
		s = max(t/r[i] + (t%r[i] == 0 ? 0:1), a/r[i+w] + (a%r[i+w] == 0 ? 0:1));
		t = r[i] * s;
		a = r[i+w] * s;
	}

	cout << t + a << endl;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <string>
#include <cstdio>
#include <iostream>
using namespace std;
int n;
int maxn;
set<string> st;
map<string,int> t;
inline int max(int a,int b){
	return a>b?a:b;
}
int main(){
	scanf("%d",&n);
	for (int i=0;i<n;i++){
		string str;
		cin>>str;
		++t[str];
		st.insert(str);
	}
	set<string>::iterator it;
	for (it=st.begin();it!=st.end();it++){
		maxn=max(maxn,t[*it]);
	}
	for (it=st.begin();it!=st.end();it++){
		if (t[*it]==maxn){
			cout<<*it<<endl;
		}
	}
	return 0;
}


Measured memory_bytes: 34560
using System;

namespace ALDS1_1_B
{
	class Program
	{
		static void Main(string[] args)
		{
			string[] vs = Console.ReadLine().Split(' ');
			long x = long.Parse(vs[0]);
			long y = long.Parse(vs[1]);

			Console.WriteLine($"{GreatestCommonDivisor(x, y)}");
		}

		static long GreatestCommonDivisor(long x, long y)
		{
			if(x < y) {
				return GreatestCommonDivisor(y, x);
			}

			while(y != 0) {
				long r = x % y;
				x = y;
				y = r; 
			}

			return x;
		}
	}
}



Measured memory_bytes: 17956
from collections import deque
import sys
input = sys.stdin.readline
import bisect as bi
from operator import mul
from functools import reduce
from math import factorial

def main():
    n = int(input())
    c = {(i,j): 0 for i in range(1,10) for j in range(1,10)}

    for i in range(1, n+1):
        s = str(i)
        if s[-1] == "0":
            continue
        h, t = map(int, (s[0], s[-1]))
        c[h, t] += 1

    print(sum(c[i,j] * c[j,i] for i in range(1,10) for j in range(1, 10)))


main()


Measured memory_bytes: 3564
S = input()
N = len(S)
if N % 2 == 0:
    S1 = "10"*round((N/2))
    S2 = '01'*round((N/2))
else:
    S1 = "10"*round((N/2))+'1'
    S2 = '01'*round((N/2))+'0'

s1 = N - sum([a==b for a, b in zip(S,S1)])
s2 = N - sum([a==b for a, b in zip(S,S2)])
print(min(s1,s2))

Measured memory_bytes: 4212
n = int(input())
t, a = map(int, input().split())
h = list(map(float, input().split()))

dt = 1000
ans = 0
for i in range(len(h)):
    tmp = float(t) - 0.006 * h[i]
    if dt > abs( a - tmp ):
        dt = abs( a - tmp )
        ans = i + 1

print(ans)


Measured memory_bytes: 9260
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long ll;
const ll INF = 1001001001001001001;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int a, b, q;
    cin >> a >> b >> q;
    vector<ll> s(a+2), t(b+2);
    // 番兵みたいな要素
    s[0] = -2 * INF, s[a + 1] = 2 * INF;
    t[0] = -2 * INF, t[b + 1] = 2 * INF;
    for(int i = 1; i <= a; ++i){
        cin >> s[i];
    }
    for(int i = 1; i <= b; ++i){
        cin >> t[i];
    }
    for(int i = 0; i < q; ++i){
        ll x;
        cin >> x;
        int s_id = lower_bound(s.begin(), s.end(), x) - s.begin();
        int t_id = lower_bound(t.begin(), t.end(), x) - t.begin();
        ll res = INF;
        ll x1 = s[s_id] - x;
        ll x2 = x - s[s_id - 1];
        ll y1 = t[t_id] - x;
        ll y2 = x - t[t_id - 1];
        cerr << x1 << " " << x2 << " " << y1 << " " << y2 << " ";
        res = min(res, max(x1, y1));
        res = min(res, max(x2, y2));
        res = min({res, 2 * x1 + y2, x1 + 2 * y2});
        res = min({res, 2 * x2 + y1, x2 + 2 * y1});
        cout << res << endl;
    }
}

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

int main(){
  int n;
  cin >> n;
  switch (n % 10){
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      cout << "hon" << endl;
      break;
    case 0:
    case 1:
    case 6:
    case 8:
      cout << "pon" << endl;
      break;
    case 3:
      cout << "bon" << endl;
      break;
  }
  return 0;
}

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

int main(void) {
  int n, a, b, sum, totalsum = 0, tmp;
  cin >> n >> a >> b;
  for (int i = 1; i <= n; i++) {
    sum = 0;
    tmp = i;
    do {
      sum += tmp%10;
    } while (tmp/=10);
    if (sum >= a && sum <= b) {
      // cout << i << endl;
      totalsum += i;
    }
  }
  cout << totalsum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stack>
using namespace std;
int main()
{
  for(;;){
    string s;
    getline(cin,s);
    if(s == ".") break;
    stack<char> q;
    bool balanced = true;
    for(int i=0; i<s.length(); i++){
      switch(s[i]){
      case '(':
      case '[':
        q.push(s[i]);
        break;
      case ')':
        if(q.empty() || q.top() != '('){
          balanced = false;
          break;
        }else{
          q.pop();
        }
        break;
      case ']':
        if(q.empty() || q.top() != '['){
          balanced = false;
          break;
        }else{
          q.pop();
        }
        break;
      }
    }
    if(balanced && q.empty()) cout << "yes" << endl;
    else cout << "no" << endl;
  }
  return 0;
}

Measured memory_bytes: 1180
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[][] A = new int[2][N];

        for (int k = 0; k < 2; k++) {
            for (int i = 0; i < N; i++) {
                A[k][i] = sc.nextInt();
            }
        }

        int sum = A[0][0];
        for (int i = 0; i < N; i++) {
            sum += A[1][i];
        }

        int max = sum;
        for (int i = 1; i < N; i++) {
            sum -= A[1][i - 1];
            sum += A[0][i];
            max = Math.max(max, sum);
        }

        System.out.println(max);
        return;
    }

}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 29)
#define MOD 1000000007
//int dx[4] = {1,0,0,-1};
//int dy[4] = {0,1,-1,0};

ll modpow(ll n,int r){
  ll res = 1;
  while(r){
    if(r & 1)res = (res*n)%MOD;
    n = n*n%MOD;
    r >>= 1;
  }
  return res;
}



ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}




int main(){
  
  string s;
  cin >> s;
  vector<ll> v;
  ll sum = 0;
  ll digit = 1;
  REPD(i,(int)s.size()){
    if(s[i] == '?')v.push_back(digit%13);
    else sum = (sum + ((s[i]-'0')*digit))%13;
    (digit *= 10)%=13;
  }
  ll dp[v.size()+1][13];
  FILL(dp,v.size()+1,0);
  dp[0][0] = 1;
  for(int i = 1;i <= v.size();i++){
    REP(j,13){
      REP(k,10){
        (dp[i][j] += dp[i-1][(130+j-k*v[i-1])%13])%=MOD;
      }
    }
  }
  int k = -1;
  REP(i,13){
    if((i+sum)%13 == 5){
      k = i;
      break;
    }
  }
  cout << dp[(int)v.size()][k] << endl;



  
  


  return 0;
}


Measured memory_bytes: 11508
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  string s;
  cin >> s;
  set<char> se;
  rep(i, s.size()){
    se.insert(s.at(i));
  }
  if(se.size() == s.size()) cout << "yes" << endl;
  else cout << "no" << endl;
  return 0;
}

Measured memory_bytes: 3584
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstdint>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <utility>
#include <limits>
#include <list>
#include <type_traits>

/* template start */

using i64=std::int_fast64_t;
using u64=std::uint_fast64_t;
 
#define rep(i, a, b) for (i64 i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  if(sizeof...(t)>0)std::cout<<" :";
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

template<typename Num>
constexpr Num mypow(Num a, u64 b,Num id=1) {
  if(b==0)return id;
  Num x = id;
  while (b > 0) {
    if(b & 1)x*=a;
    a*=a;
    b >>= 1;
  }
  return x;
}

/* template end */

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

  i64 n;
  std::cin>>n;

  std::vector<i64> order(n*n);
  for(auto&& e:order){
    std::cin>>e;
    e--;
  }

  std::vector<std::vector<i64>> cost(n,std::vector<i64>(n));
  std::vector<std::vector<i64>> empty(n,std::vector<i64>(n,1));

  rep(i,0,n){
    rep(j,0,n){
      cost[i][j]=std::min({i,n-1-i,j,n-1-j});
    }
  }

  i64 ans=0;

  auto dfs=[&](auto f,i64 x,i64 y)->void{
    i64 val=cost[x][y]+empty[x][y];
    if(x-1>=0&&chmin(cost[x-1][y],val))f(f,x-1,y);
    if(x+1<n&&chmin(cost[x+1][y],val))f(f,x+1,y);
    if(y-1>=0&&chmin(cost[x][y-1],val))f(f,x,y-1);
    if(y+1<n&&chmin(cost[x][y+1],val))f(f,x,y+1);
  };

  for(const auto& p:order){
    i64 py=p/n,px=p%n;
    ans+=cost[px][py];
    empty[px][py]=0;
    dfs(dfs,px,py);
  }

  std::cout<<ans<<"\n";
  
  return 0;
}

Measured memory_bytes: 39988
import sys
sys.setrecursionlimit(10000000)
def input():
    return sys.stdin.readline()[:-1]
from bisect import *
from collections import *
from heapq import *
import itertools
import math
INF = 10**9
MOD = 10**9+7

N, M = map(int, input().split())
es = [[] for i in range(N+1)]
for i in range(M):
    a, b = map(int, input().split())
    es[a].append(b)
ansr, ansd = -1, INF
for r in range(1, N+1):
    d = [INF] * (N+1)
    d[0] = 0
    dq = deque()
    for w in es[r]:
        dq.append(w)
        d[w] = 1
    while len(dq) > 0:
        v = dq.popleft()
        if v == r:
            break
        nd = d[v]+1
        for u in es[v]:
            if nd < d[u]:
                d[u] = nd
                dq.append(u)
    if d[r] < ansd:
        ansd = d[r]
        ansr = r
if ansr == -1:
    print(-1)
else:
    vis = [0] * (N+1)
    vis[0] = 1
    p = [-1] * (N+1)
    dq = deque()
    for v in es[ansr]:
        vis[v] = 1
        p[v] = 0
        dq.append(v)
    while len(dq) > 0:
        v = dq.popleft()
        if v == ansr:
            break
        for u in es[v]:
            if vis[u] == 0:
                vis[u] = 1
                p[u] = v
                dq.append(u)
    lst = []
    v = ansr
    while p[v] != -1:
        lst.append(v)
        v = p[v]
    print(len(lst))
    print(*lst, sep = '\n')


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

long long x;

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

	cin >> x;

	long long lo = 1, mid, hi = 1e15;
	while (lo <= hi) {
		mid = (lo+hi) / 2;
		long long R = (mid / 2 + (mid&1)) * 6 + (mid / 2) * 5;
		long long L = R - ((mid&1) ? 6 : 5) + 1;
		if (L <= x && x <= R) {
			cout << mid << '\n';
			return 0;
		}
		else if (R <= x) {
			lo = mid+1;
		}
		else {
			hi = mid-1;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define pb(x) push_back(x)
#define TEST(t) int inox,t;cin>>t; for(inox=1;inox<=t;inox++)
#define rep(i,n) for(i=0;i<n;i++)
#define repr(i,n) for(i=n-1;i>=0;i--)
using namespace std;
string s;map<ll,ll> m;
ll fun( char b, char ch, ll i,  ll n){
	ll c=0,j,sum=0;m.clear();
for(j=i-1;j>=0;j--){
				if(s[j]==b){m[i-j]++;c++;}
				if(s[j]==ch){
					if((i-j)%2==0&&m[(i-j)/2])sum+=(c-1);
					else sum+=c;
				}
			}
			return sum;
}

int main(){
	ll n,i,j,c=0,sum=0; cin>>n;
	 cin>>s;
	
	for(i=2;i<n;i++){
		if(s[i]=='R'){
			sum+=(fun('G','B',i,n)+fun('B','G',i,n));
		}
		else if(s[i]=='G'){
			sum+=(fun('R','B',i,n)+fun('B','R',i,n));
		}
		else{
			sum+=(fun('R','G',i,n)+fun('G','R',i,n));
		}
	}
	cout<<sum;
}

Measured memory_bytes: 3760