akhauriyash/Code-Regression huggingface dataset:
import qualified Data.Vector.Unboxed as V
import Data.Array.IArray (listArray, accumArray, (!))
import Data.Array.MArray
import Data.Array.ST (STUArray, runSTUArray)
import Data.Array.Unboxed (UArray)
import Data.List (sortOn, sortBy, unfoldr, partition)
import Data.Char (isSpace)
import Data.Monoid (First(..))
import Control.Monad.ST (ST)
import Control.Monad.Trans.State (StateT(..))
import qualified Data.ByteString.Char8 as B

import Debug.Trace (trace)

-- utility functions

tr x = trace (show x) x

--   Input functions
readInt = B.readInt . B.dropWhile isSpace

readInts :: Int -> B.ByteString -> [Int]
readInts n = take n . unfoldr readInt

readIntsV :: Int -> B.ByteString -> V.Vector Int
readIntsV n = V.unfoldrN n readInt

readIntsA :: Int -> B.ByteString -> UArray Int Int
readIntsA n bs = runSTUArray $ do
  arr <- newArray_ (0,n-1)
  go arr 0 bs
  return arr
  where
    go :: STUArray s Int Int -> Int -> B.ByteString -> ST s ()
    go arr i bs
      | i==n = return ()
      | otherwise = do
        let Just (x,bs') = readInt bs
        writeArray arr i x
        go arr (i+1) bs'

readTsV :: Int -> B.ByteString -> V.Vector (Int,Int)
readTsV n = V.unfoldrN n $ runStateT ((,) <$> StateT readInt <*> StateT readInt)

readTs :: Int -> B.ByteString -> [(Int,Int)]
readTs n = take n . unfoldr readT where
  readT = runStateT ((,) <$> StateT readInt <*> StateT readInt)

-- main

(!*) = V.unsafeIndex

s xs n
  | n < 0 = Nothing
  | n == xs!*n = Just n
  | otherwise = s xs (n-1)

ex n bs = V.take n bs V.++ V.drop (n+1) bs

solv bs
  | V.null bs = V.empty
  | otherwise
    = case cand of
      Nothing -> V.singleton (-1)
      Just i -> V.snoc (solv $ ex i bs) (i+1)
  where
    cand = s bs (V.length bs - 1)

main = do
  n <- read <$> getLine
  bs <- V.map (subtract 1) . readIntsV n <$> B.getLine
  let ans = solv bs
  if ans !* 0 == -1 then print (-1)
  else V.forM_ ans print


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

#define rep0(i, n) for(int i=0; i<(int)(n);i++)
#define rep1(i, n) for(int i=1; i<=(int)(n);i++)
#define all(x) (x).begin(), (x).end()
#define debug(a) if(flagdebug){cout << "debug (" #a "):" << endl << (a) << endl;}

typedef uint64_t ulint;
typedef int64_t lint;
using namespace std;

lint 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;
bool flagdebug = false;

int main(){
//////////////////////////////////////////////////////
    // flagdebug = true;
    cin >> a >> b;

    if(a>b*2)
    {
        cout << a - b * 2 << endl;
    }
    else
    {
        cout << 0 << endl;
    }



    

//////////////////////////////////////////////////////
// Ctrl + Opt + N to make
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
 
public class Main {
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		int t = sc.nextInt();
		int a = sc.nextInt();
		int[] h = new int[n];
		
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}
		double near = Double.MAX_VALUE;
		int res = -1;
		
		for (int i = 0; i < n; i++) {
			double temperature = Math.abs(a*1.0 -(t*1.0 - h[i]*1.0*0.006));
			if (temperature < near) {
				near = temperature;
				res = i+1;
			}
		}
		
		System.out.println(res);
	}
  
    static class FastReader {
	    BufferedReader br;
	    StringTokenizer st;
	
	    public FastReader() {
	      br = new BufferedReader(new InputStreamReader(System.in));
	    }
	  
	    String next() { 
	      while (st == null || !st.hasMoreElements()) {
	        try {
	          st = new StringTokenizer(br.readLine());
	        } catch (IOException  e) {
	          e.printStackTrace();
	        }
	      }
	      return st.nextToken();
	    }
	
	    int nextInt() {
	      return Integer.parseInt(next());
	    }
	
	    long nextLong() {
	      return Long.parseLong(next());
	    }
	
	    double nextDouble() { 
	      return Double.parseDouble(next());
	    }
	
	    String nextLine() {
	      String str = "";
	        try{
	            str = br.readLine();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
	        return str;
	      }
	  }
}

Measured memory_bytes: 21588
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
namespace AtCoderSolve
{
    class Solve
    {
        const int mod = 1000000007;
        const int INF = 2147483647;
        const long SINF = 9223372036854775807;

        static int N, x;
        static long[] a;
        //static int[] H;
        //static string S, T;


        public static void Input()
        {
            var cin = new Scanner();
            var input = cin.SplitReader();
            N = input[0];
            x = input[1];
            a = cin.SplitReaderL();
        }

        static void Main(string[] args)
        {
            Input();
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            long ans = 0;
            if (a[0] > x)
            {
                ans += a[0] - x;
                a[0] = x;
            }

            for(var i = 1; i < N; i++)
            {
                if (a[i] + a[i - 1] > x)
                {
                    ans += a[i] + a[i - 1] - x;
                    a[i] = x - a[i - 1];
                }
            }

            Console.WriteLine(ans);

            //Console.Out.Flush();
        }

    }

    public class Scanner
    {
        public int[] SplitReader()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReaderL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }

        public int[] MultiLineReader(int N)
        {
            int[] ret = new int[N];
            for(var i = 0; i < N; i++)
            {
                ret[i] = int.Parse(Console.ReadLine());
            }

            return ret;
        }
        public long[] MultiLineReaderL(int N)
        {
            long[] ret = new long[N];
            for (var i = 0; i < N; i++)
            {
                ret[i] = long.Parse(Console.ReadLine());
            }

            return ret;
        }

    }

    public class Graph
    {
        
    }
}

    



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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    /**
     * とりあえずまずは前からやるべき。
     * aには手を加えない
     * 基本的に操作を行うたびに辞書順の最適から遠ざかっていくがz->aは行いたい。
     * 簡単にz->aの形に持っていけるような所は手を付けるべき。
     *
     * 前から見ていって、もし残り回数以内にaにできるものはそうする。
     * 出来ないものは放置して次に行く。
     * 最後まで行って操作回数が余ったら、最後の文字で使い切るまで操作する
     */

    string s; cin >> s;
    i32 k; cin >> k;

    for(i32 i = 0; i < s.size() && k > 0; ++i) {
        if(s[i] == 'a') continue;
        else if(26 - (int)(s[i]-'a') <= k) {
            k -= 26 - (int)(s[i]-'a');
            s[i] = 'a';
        }
//
//        debug(s);
//        debug(k);
    }

    i32 diff;
    if(k > 0) {
        diff = s[s.size()-1]-'a';
        diff = (diff + k) % 26;
        s[s.size()-1] = (char)('a' + diff);
    }

    cout << s << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  long long S, a, r, mod = 1000000000;
  cin >> S;
  r = (mod - S % mod) % mod;
  a = (r + S) / 1000000000;
 
  cout << "0 0 1 1000000000 " << a << ' ' << r << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    long W, H, x, y;
    scanf("%ld", &W);
    scanf("%ld", &H);
    scanf("%ld", &x);
    scanf("%ld", &y);

    double ans = (W * H) / 2.0;
    printf("%.10lf ", ans);
    if ((W % 2) == 0 && (H % 2) == 0 && x == (W / 2) && y == (H / 2))
        printf("%d", 1);
    else
        printf("%d", 0);
    return 0;
}


Measured memory_bytes: 128
N, K = map(int,input().split())
A = list(map(int,input().split()))
L = []
for i in range(N):
  for j in range(i+1,N+1):
    L.append(sum(A[i:j]))
L.sort(reverse=True)
ans = 0
remains = []
for i in range(40):
  bit = 1 << (39 - i)
  l = []
  cnt = 0
  #print(bit)
  for j in range(len(L)):
    if bit & L[j] == bit:
      cnt += 1
      l.append(L[j])
  if cnt >= K:
    ans += bit
    L = l
print(ans)

Measured memory_bytes: 24220
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;
ll gcd(ll a, ll b) {
  if (a%b==0) return(b);
        else return(gcd(b,a%b));
}

int main (void) {
  int N; std::cin >> N;

  ll ans = 1;
  for(int i=0; i<N; i++) {
    ll T; std::cin >> T;
    ans *= T/gcd(ans,T);
  }
  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#define llint long long

using namespace std;

llint Q;
llint a, b, c, d;
llint k, bd, bd2, bd3;

char get(llint x)
{
	if(x <= (k+1)*(a/k)){
		if(x % (k+1) == 0) return 'B';
		else return 'A';
	}
	else{
		x -= (k+1)*(a/k);
		if(x <= a%k) return 'A';
		else return 'B';
	}
}

char get2(llint x)
{
	if(x <= (k+1)*bd){
		if(x % (k+1) == 0) return 'B';
		else return 'A';
	}
	x -= (k+1)*bd;
	
	if(x <= bd2){
		return 'A';
	}
	x -= bd2;
	
	if(x <= bd3){
		if(x <= bd3) return 'B';
	}
	x -= bd3;
	
	if(x % (k+1) == 1) return 'A';
	else return 'B';
}

int main(void)
{
	cin >> Q;
	for(llint q = 0; q < Q; q++){
		cin >> a >> b >> c >> d;
		
		k = (a+b)/(min(a, b)+1);
		
		llint ub = a+5, lb = 0, mid;
		while(ub-lb>1){
			mid = (ub+lb)/2;
			if(k*(a-mid*k)+k >= b+1-mid) lb = mid;
			else ub = mid;
		}
		bd = lb;
		
		llint A = a - bd*k, B = b-bd;
		ub = k, lb = 0;
		while(ub-lb>1){
			mid = (ub+lb)/2;
			if(k*(A-mid)+k >= B) lb = mid;
			else ub = mid;
		}
		bd2 = lb;
		
		A -= bd2;
		bd3 = B - k*A;
		
		for(llint i = c; i <= d; i++) cout << get2(i);
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 384
import numpy as np

nums = []
sortedNums = [0,0,0,0,0]
sortedRemainders = [0,0,0,0,0]
for i in range(5):
	nums.append(int(input()))

remainders = [0,0,0,0,0]
for i in range(5):
	if nums[i] % 10 == 0:
		remainders[i] = 10
	else:
		remainders[i] = nums[i] % 10

sortedRemaindersIndex = np.ndarray.tolist(np.argsort(remainders))

for i in range(5):
	sortedNums[i] = nums[sortedRemaindersIndex[i]]

elapsedTime = 0
for i in range(4):
	if sortedNums[i+1] % 10 == 0:
		elapsedTime += sortedNums[i+1]
	else:
		elapsedTime += sortedNums[i+1] + 10 - sortedNums[i+1] % 10

elapsedTime += sortedNums[0]

print(elapsedTime)

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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int m,k;
	cin>>m>>k;
	int n=1<<m;
	if(k>=n)
		cout<<-1<<endl;
	else if(k==0){
		for(int i=0;i<n;i++)
			cout<<i<<' '<<i<<' ';
		cout<<endl;
	}
	else if(m==0||m==1){
			cout<<-1<<endl;
	}
	else{
		cout<<k<<' ';
		for(int i=0;i<n;i++)
			if(i!=k)
				cout<<i<<' ';
		cout<<k<<' ';
		for(int i=n-1;i>=0;i--)
			if(i!=k)
				cout<<i<<' ';
		cout<<endl;
	}
}


Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
#include<vector>

using namespace std;

int x, y, a, b, c;
int p[100005], q[100005], r[100005];
vector<int> s, t;

int main() {
  scanf("%d %d %d %d %d", &x, &y, &a, &b, &c);
  for (int i = 0; i < a; i++) {
    scanf("%d", &p[i]);
  }
  for (int i = 0; i < b; i++) {
    scanf("%d", &q[i]);
  }
  for (int i = 0; i < c; i++) {
    scanf("%d", &r[i]);
  }
  auto f = [] (int x, int y) {
    return x > y;
  };
  sort(p, p + a, f);
  sort(q, q + b, f);
  sort(r, r + c, f);
  for (int i = 0; i < x; i++) {
    s.push_back(p[i]);
  }
  for (int i = 0; i < y; i++) {
    s.push_back(q[i]);
  }
  sort(s.begin(), s.end(), f);
  for (int i = 0; i < c; i++) {
    if (r[i] > s.back()) {
      t.push_back(r[i]);
      s.pop_back();
    } else {
      break;
    }
  }
  long long ans = 0;
  for (auto e: s) {
    ans += e;
  }
  for (auto e: t) {
    ans += e;
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 3060
#include <stdio.h>
#include <algorithm>
#define MN 100000
int n,k,a[MN+5],ans=0x7fffffff;
int calc(int l,int r){
	if(1ll*a[l]*a[r]>=0) return std::max(std::abs(a[l]),std::abs(a[r]));
	return std::abs(a[l])+std::abs(a[r])+std::min(std::abs(a[l]),std::abs(a[r]));
}
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int l=1;l+k-1<=n;l++)
		ans=std::min(ans,calc(l,l+k-1));
	printf("%d\n",ans);
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <numeric>

int main(void) {
	int n, t;

	std::cin >> n >> t;

	int min = 1000000;

	for (size_t i = 0; i < n; i++) {
		int a, b;

		std::cin >> a >> b;
		if (b <= t) {
			if (a < min) {
				min = a;
			}
		}
	}

	if (min != 1000000) {
		std::cout << min << std::endl;
	}
	else {
		std::cout << "TLE" << std::endl;
	}
	return 0;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;

  ll dp[s.size() + 1][2][5] = {};  // 既に未満が確定か？のフラグ
  dp[0][false][0] = 1;             // 1文字目、1桁のやつと合わす

  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j <= k; j++) {
      dp[i + 1][true][j + 1] += dp[i][true][j] * 9;  // 以下+1~9
      dp[i + 1][true][j] += dp[i][true][j];          // 以下+0

      dp[i + 1][true][j + 1] += dp[i][false][j] * (max(0, s[i] - '0' - 1));  // 0以外を追加して剥がれる                            // ぴったり張り付いたまま

      if (s[i] - '0') dp[i + 1][false][j + 1] += dp[i][false][j];  // くっついたまま
      dp[i + 1][s[i] - '0' != 0][j] += dp[i][false][j];            // くっついてる所に0を追加
    }
  }

  cout << dp[s.size()][false][k] + dp[s.size()][true][k] << endl;
}


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

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> X(N);
    rep(i, N) cin >> X[i];
    int ans = 1e9;
    rep(P, 101) {
        int d = 0;
        rep(i, N) {
            d += (X[i] - P) * (X[i] - P);
        }
        ans = min(ans, d);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from heapq import heappop, heappush
import math

if __name__ == '__main__':
    V, E, r = map(int, input().split())
    edge = [[] for _ in range(V)]
    d = [math.inf] * V
    que = []
    for _ in range(E):
        s, t, c = map(int, input().split())
        edge[s].append([t, c])

    d[r] = 0
    heap = [(d[r], r)]
    while heap:
        du, u = heappop(heap)
        for t, c in edge[u]:
            if d[t] > du + c:
                d[t] = du + c
                heappush(heap, (d[t], t))

    for di in d:
        print('INF' if math.isinf(di) else di)




Measured memory_bytes: 97008
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.16f\n", a)//少数出力
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>

using ll = long long;

const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main() {

	int n;
	scanf("%d", &n);
	vector<ll> a(n);
	rep(i, n)scanf("%lld", &a[i]);
	ll ans = 0;
	rep(i, n) {
		for (int j = i + 1; j < n; ++j) {
			ans += a[i] * a[j];
		}
	}
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}


int main() {
  int N;
  cin>>N;
  vector<int>a(N);
  for(int i=0;i<N;i++){
      cin>>a[i];
  }
  int cnt=0;
  for(int i=0;i<N;i++){
      if((i+1)%2!=0&&a[i]%2!=0){
          cnt++;
      }
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 3624
n = int(input())

threeT = [
    ['a', 'a', '.'],
    ['.', '.', 'a'],
    ['.', '.', 'a']
]
fourT = [
    ['a', 'a', 'c', 'd'],
    ['b', 'b', 'c', 'd'],
    ['e', 'f', 'g', 'g'],
    ['e', 'f', 'h', 'h']
]
fiveT = [
    ['a', 'a', '.', 'c', 'd'],
    ['.', 'b', 'b', 'c', 'd'],
    ['e', '.', 'f', 'f', 'g'],
    ['e', '.', 'h', '.', 'g'],
    ['i', 'i', 'h', 'j', 'j']
]
sevenT = [
    ['a', 'a', 'b', 'b', 'c', 'c', '.'],
    ['d', 'd', 'e', 'e', '.', '.', 'f'],
    ['g', '.', '.', 'h', 'h', '.', 'f'],
    ['g', 'i', '.', '.', '.', '.', 'j'],
    ['.', 'i', '.', '.', 'k', 'k', 'j'],
    ['.', '.', 'l', '.', '.', 'm', 'n'],
    ['.', '.', 'l', '.', '.', 'm', 'n']
]

if n == 2:
    print(-1)
    exit()

if n == 7:
    for i in range(n):
        print(''.join(sevenT[i]))
    exit()

if n == 11:
    for i in range(n):
        br = ['.'] * n
        if i < 7 :
            for j in range(7):
                br[j] = sevenT[i][j]
        else:
            for j in range(4):
                br[7+j] = fourT[i-7][j]
        print(''.join(br))
    exit()

if n % 3 == 0:
    for i in range(n):
        br = ['.'] * n
        ind = i % 3
        k = i // 3
        for j in range(3):
            br[3*k+j] = threeT[ind][j]
        print(''.join(br))
    exit()
ac = n % 4
afive = ac
afour = (n - afive * 5) // 4
for i in range(n):
    br = ['.'] * n
    if i // 4 < afour:
        ind = i % 4
        k = i // 4
        for j in range(4):
            br[4*k+j] = fourT[ind][j]
    else:
        off = 4 * afour
        ind = (i-off) % 5
        k = (i-off) // 5
        for j in range(5):
            br[off+5*k+j] = fiveT[ind][j]
    print(''.join( br))






Measured memory_bytes: 42348
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
//const int INF = 1e8;
using namespace std;

int main(){
	string s;
	cin >> s;

	while(not s.empty()){
		bool f = true;
		s.pop_back();
		if(s.size() % 2) s.pop_back();
		rep(i,s.size() / 2){
			if(s[i] != s[i + s.size() / 2]){
				f = false;
			}
		}
		if(f){
			cout << s.size() << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
const int INF=1<<30;
int n, m;
int d[1001], c[1001];
int dp[1001][1001];
int main(){
  cin>>n>>m;
  for(int i=1;i<=n;i++)
    cin>>d[i];
  for(int j=1;j<=m;j++)
    cin>>c[j];
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      dp[i][j]=INF;
    }
  }
  for(int i=1;i<=n;i++){
    for(int j=i;j<=m;j++){
      if(j==1)
	dp[i][j]=c[j]*d[i];
      else
	dp[i][j]=min(dp[i-1][j-1]+c[j]*d[i],dp[i][j-1]);
    }
  }
  cout<<dp[n][m]<<endl;
}

Measured memory_bytes: 4348
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
//#define i_7 (ll)(1E9+7)
//#define i_7 998244353
//#define i_5 i_7-2

ll i_7=1E6+3;
ll i_5=i_7-2;

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
///////////////////////////



int main(){fastio
    ll a,b,m;cin>>a>>b>>m;
    ll x[a],y[b];
    rep(i,0,a-1)cin>>x[i];
    rep(i,0,b-1)cin>>y[i];
    ll ans=inf;
    while(m--){
        ll p,q,r;cin>>p>>q>>r;p--;q--;
        Min(ans,x[p]+y[q]-r);
    }
    sort(x,x+a);sort(y,y+b);
    Min(ans,x[0]+y[0]);
    cout<<ans<<endl;
    
    return 0;
}



Measured memory_bytes: 1792
n,m,k=gets.chomp.split.map(&:to_i)
x=n%10
arr=[]
4.times{|i|arr<<(x**(i+1))%10}
arr2=[]
4.times{|i|arr2<<(1+i*m)%4}
q,r=k.divmod 4
arr3=Array.new(4)
1.upto(4){|i|arr3[i-1]=((i>r)?q:q+1)}
sum=0
4.times{|i|sum+=arr3[i]*arr[arr2[i]-1]}
puts sum


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

typedef long long ll;
typedef long double ld;

int main(){
    ios_base::sync_with_stdio(false), cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int k;
    cin >> k;
    string s;
    cin >> s;
    if(s.size() <= k){
        cout << s;
        return 0;
    }
    for(int i=0; i<k; i++) cout << s[i];
    cout << "...";
    return 0;
}


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


int main(){
   int n;
   cin >> n;
   vector<int> vect(n);
   vector<int> vect2(n);

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

   vect2[0] = 0;
   vect2[1] = abs(vect[1] - vect[0]);
   for(int i = 2; i < n; i++){
      vect2[i] = min(vect2[i-1] + abs(vect[i] - vect[i-1]),vect2[i-2] + abs(vect[i] - vect[i-2]));
   }

   cout << vect2[n-1] << endl;

}

Measured memory_bytes: 1024
arr = [[], []]
arr[0][0], arr[0][1], arr[1][0], arr[1][1] = gets.chomp.split.map(&:to_i)
turn = 0
while true
    arr[1 - turn][0] -= arr[turn][1]
    break if arr[1 - turn][0] <= 0
    turn = 1 - turn
end
puts (turn == 0 ? "Yes" : "No")

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

int main() {
    int n, t, a;
    cin >> n >> t >> a;

    vector<pair<double, int> > T(n);
    for(int i=0; i<n; i++){
        int h;
        cin >> h;
        T[i].first = abs(t-h*0.006-a);
        T[i].second = i;
    }

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

    cout << T[0].second + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (ll &e : a)
        cin >> e;
    sort(a.begin(), a.end());
    ll p = 1;
    if (a[n - 1] == 0 && (k & 1))
        p = 0;
    else if (a[n - 1] <= 0 && (k & 1))
        for (ll i = n - 1; i >= n - k; i--)
            p = p * a[i] % M;
    else
    {

        ll i = 0, j = n - 1;
        if (k & 1)
        {
            p = p * a[j] % M;
            j--;
            k--;
        }
        k >>= 1;
        for (ll itr = 0; itr < k; itr++)
        {
            ll lp = a[i] * a[i + 1];
            ll rp = a[j] * a[j - 1];
            if (lp > rp)
            {
                lp %= M;
                p = p * lp % M;
                i += 2;
            }
            else
            {
                rp %= M;
                p = p * rp % M;
                j -= 2;
            }
        }
    }
    cout << (p + 99 * M) % M;
}

Measured memory_bytes: 4780
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    int k; cin>>k;
    string s; cin>>s;
    
    if(s.size()<=k){
        cout << s << ln;
    }else{
        cout << s.substr(0, k) << "..." << ln;
    }
 
   return 0;
}

Measured memory_bytes: 3656
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] arr = new int[k];
        for (int i=0; i<k; i++){
            arr[i] = sc.nextInt();
        }
        
        for (int i=0; n<999999999; i++){
            if (i != 0){
                n += 1;
            }
            int count = 0;
            for (int j=0; j<arr.length; j++){
                if (String.valueOf(n).indexOf(String.valueOf(arr[j])) == -1){
                    count++;
                }
            }
            if (count == arr.length){
                break;
            }
        }

        System.out.println(n);
    }
}

Measured memory_bytes: 57016
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt();
        int y = scanner.nextInt();
        if (x >= y) {
            System.out.println("10");
        }else{
            System.out.println("0");
        }
    }
}


Measured memory_bytes: 22868
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int[] bo = new int[n];
			for (int i = 0; i < n; i++) {
				bo[i] = sc.nextInt();
			}
			Arrays.sort(bo);
			int ans = 0;
			for (int i = 0; i < n - 2; i++) {
				for (int j = i + 1; j < n - 1; j++) {
					for (int k = j + 1; k < n; k++) {
						if (bo[i] + bo[j] > bo[k]) {
							ans++;
						} else {
							break;
						}
					}
				}
			}
			System.out.print(ans);
		}
	}
}


Measured memory_bytes: 26416
#include <stdio.h>
#include <iomanip>
#include <time.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#define mod 1000000007
#define ll long long
#define pi acos(-1)
using namespace std;

int main(){
	int k;
	string s;
	cin>>k>>s;
	if(s.size()<=k) cout<<s;
	else{
		for(int i = 0; i < k; i++)
			cout<<s[i];
		
		cout<<"...";
	}	
	
	return 0;	
}



Measured memory_bytes: 3628
A=int(input())
B=int(input())

if A==1 and B==2: 
    print(3)
elif A==2 and B==1:
    print(3)
elif A==2 and B==3:
    print(1)
elif A==3 and B==2:
    print(1)
else:
    print(2)

Measured memory_bytes: 3060
#include <stdio.h>

int main(){

  int n,ten,sum,max,min,i,j;
  while(1){
    scanf("%d",&n);
    if(n==0)break;
    for(i=0;i<n;i++){
      sum=0;
      for(j=0;j<5;j++){
	scanf("%d",&ten);
	sum += ten;
      }
      if(sum>max)max=sum;
      if(sum<min)min=sum;
    }
    printf("%d %d\n",max,min);
    max=0;
    min=500;
  }
  return 0;
}

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

int main() {
	string s;
	cin >> s;
	if(s[2]==s[3] && s[4]==s[5])
		cout << "Yes" << endl;
else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

#define int long long
#define rep(i,n) for(int i=0; i<(int)(n); i++)

const int N = (int)2e5;
int n;
int a[N];

int di(int x, int a) {
  return x / a + (x % a < 0 ? -1 : 0); 
}

int count(int x, int i) {
  int s = 0;
  if(a[i] > 0) s = upper_bound(a+i+1, a+n, di(x, a[i]))-a-i-1;
  else if(a[i] < 0) s = n-i-1 - (lower_bound(a+i+1, a+n, -di(x, -a[i]))-a-i-1);
  else if(x >= 0) s = n-i-1;
  return s;
}

int index(int x) {
  int s = 0;
  rep(i,n-1) s += count(x, i);
  return s;
}

int solve(int k) {
  int l = -(int)1e18-1, r = (int)1e18+1;
  while(r - l > 1) {
    int m = (l + r) / 2;
    if(index(m) < k) l = m;
    else r = m;
  }
  return r;
}

signed main() {
  int k;
  cin >> n >> k;
  rep(i,n) cin >> a[i];
  sort(a, a+n);
  
  cout << solve(k) << endl;
  return 0;
}

Measured memory_bytes: 5168
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef long long ll;

template <typename T> void max_self(T& a, T b){
  a = max(a,b);
}

template <typename T> void min_self(T& a, T b){
  a = min(a,b);
}

void solve(){	
  int n,m; cin>>n>>m;
  vi h(n);
  for(int i=0;i<n;i++) cin>>h[i];
  vi g[n];
  for(int i=0;i<m;i++){
    int l,r; cin>>l>>r;
    l--;r--;
    g[l].PB(r);
    g[r].PB(l);
  }
  
  int ans = 0;
  for(int i=0;i<n;i++){
    if(g[i].size() == 0) ans++;
    else{
      bool t = true;
      for(int j=0;j<g[i].size(); j++){
        if(h[i] <= h[g[i][j]]){
          t = false;
          break;
        }
      }
      if(t)
        ans++;
    }
  }
  cout<<ans<<endl;
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //int t; cin >> t;
  //while(t--) solve();
  //
  solve();
  return 0;
}


Measured memory_bytes: 8748
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2019-12-24 15:34:53
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;
template<class T> ostream& operator<<(ostream& os, vector<T>& _) { os << '{'; for (T& x : _) { os << x; if (&x != &_.back()) os << ','; } os << '}'; return os; }
template<class T, class U> ostream& operator<<(ostream& os, pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }

#ifdef LOCAL
#define debug(_) cerr << #_ << ": " << (_) << '\n'
#else
#define debug(_) 1728
#endif

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

  int64 k; cin >> k;

  int64 n = 50;

  int64 div = k / n;
  int64 mod = k % n;

  vector<int64> ans(n, n - 1);
  for (int64 i = 0; i < n; ++i) {
    ans[i] += div;
  }

  for (int64 i = 0; i < mod; ++i) {
    for (int64 j = 0; j < n; ++j) {
      if (i == j) {
        ans[j] += n;
      } else {
        ans[j] -= 1LL;
      }
    }
  }

  cout << n << '\n';
  for (int64 x : ans) {
    cout << x << " ";
  }
  cout << '\n';

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define Max 200000

int main(){
  int i, j, n, R[Max], minv, maxv;

  scanf("%d", &n);

  for(i = 0 ; i < n ; i++) scanf("%d", &R[i]);

  maxv = R[1] - R[0];
  minv = R[0];

  for(j = 1 ; j <= n - 1 ; j++){
    //if(minv > R[j]) minv = R[j];
    if(maxv < R[j] - minv) maxv = R[j] - minv;
    if(minv > R[j]) minv = R[j];
  }

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

  return 0;
}


Measured memory_bytes: 2576
import java.util.*;

public class Main {

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

        int N = scanner.nextInt();
        int T = scanner.nextInt();
        int A = scanner.nextInt();

        double MAX = Double.MAX_VALUE;

        int idx = -1;

        for(int i=0; i<N; i++){
            int tmp = scanner.nextInt();

            double temperature = (double) T - tmp * 0.006;
            double diff = Math.abs(temperature - A);

            if(diff < MAX){
                idx = i + 1;
                MAX = diff;
            }
        }

        System.out.println(idx);
    }
}


Measured memory_bytes: 22484
//Date and time of submission: 
 
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll N=1e5+5;
ll n,m;
int main() {
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	cin>>n>>m;
	cout<<(n-1)*(m-1);
	return 0;
}


Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
			　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <memory>
#include <iomanip>

#define rep(i, n) for(Int (i) = 0; (i) < (n); ++(i))
#define debug(var) std::cout << #var << ": " << var << "\n"
using Int = int64_t;
constexpr Int INF = INT_MAX;

///aとbの最大公約数を求める関数。計算量はO(log min(a, b))
Int Gcd(Int a, Int b) {
	if (a % b == 0)return b;
	else return Gcd(b, a % b);
}

void calc() {

	Int N; std::cin >> N;
	std::vector<Int> num(N);
	rep(i, N - 1) {
		Int A; std::cin >> A;
		num[A - 1]++;
	}
	rep(i, N) {
		std::cout << num[i] << "\n";
	}

}


int main() {

	calc();

	return 0;
}

Measured memory_bytes: 4848
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

const int N = 500205;

int a[N];
int n,sum;
int cnt[10];

void add(int x){
	cnt[a[1]]--;
	a[1]+=x;
	int now=1;
	while(a[now]>9){
		cnt[a[now+1]]--;
		a[now+1]++;
		a[now]-=10;
		cnt[a[now]]++;
		now++;
	}
	cnt[a[now]]++;
	n=max(now,n);
}

int main(){
	char ch;
	while(ch=getchar(),ch<'0'||ch>'9');
	a[n=1]=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')a[++n]=ch-'0';
	fo(i,1,n/2)swap(a[n-i+1],a[i]);
	fo(i,1,n)a[i]=a[i]*9;
	fo(i,1,n){
		a[i+1]=a[i+1]+a[i]/10;
		a[i]%=10;
	}
	while(a[n+1]){n++;a[n+1]=a[n+1]+a[n]/10;}
	fo(i,1,n)cnt[a[i]]++;
	int sum=0;
	while(n){
		if (cnt[9]==n){
			n=0;
			sum++;
		}
		else{
			int tmp=a[n];
			cnt[tmp]--;
			sum+=tmp;
			a[n]=0;
			n--;
			add(tmp);
		}
	}
	printf("%d\n",(sum-1)/9+1);
	return 0;
}

Measured memory_bytes: 2176
#include <stdio.h>

int H[500005],n;

void max(int x)
{
    int l,r,largest,d;
    l=2*x;
    r=l+1;

    if( l <= n && H[l] > H[x] ) 
        largest = l;
    else
        largest = x;
    if( r <= n && H[r] > H[largest] )
        largest = r;
   
    if( largest != x ) {
        d=H[largest];
        H[largest]=H[x];
        H[x]=d;
        max(largest);   
    }
}

int main()
{ 
    int i;

    scanf("%d",&n);

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

    for(i=n/2;i>=1;i--){
        max(i);
    }

    for(i =1;i<=n;i++){
        printf(" %d",H[i]);
    }

    printf("\n");

    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>

using ll = long long;
typedef unsigned long long ull;
typedef std::pair<int, int>p;

ll min(ll a, ll b) {
	if (a >= b)return b;
	else return a;
}
ll max(ll a, ll b) {
	if (a >= b)return a;
	else return b;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const ll Z = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
bool flag = true;
bool fl = false;
bool f = false;
bool used[210];
bool graph[100][100];
bool visited[8];
int abc[26] = { 0 };
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

int main() {
	int n, a[100010], ans = 0;
	std::cin >> n;
	for (int i = 1;i <= n;i++) {
		std::cin >> a[i];
	}
	for (int i = 1;i <= n;i++) {
		if (a[i] == i)ans++, i++;
		}
	std::cout << ans << std::endl;
	}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

VI e[100000], d[100000];
int par[100000][18], depth[100000], dist[10000];

void dfs(int now, int past){
    REP(i,e[now].size()){
        int next = e[now][i];
        if (next == past) continue;
        par[next][0] = now;
        depth[next] = depth[now] + 1;
        dist[next] = dist[now] + d[now][i];
        dfs(next, now);
    }
}

int lca(int x, int y){
    if (depth[y] > depth[x]) swap(x,y);
    int d = depth[x] - depth[y];
    REP(i,18){
        if ((d>>i) & 1){
            x = par[x][i];
        }
    }
    if (x == y) return x;
    FORR(i,17,0){
        if (par[x][i] != par[y][i]){
            x = par[x][i];
            y = par[y][i];
        }
    }
    return par[x][0];
}

int main() {
    int n;
    while (cin >> n && n){
        REP(i,n){
            e[i].clear();
            d[i].clear();
        }
        VI to(n-1), length(n-1), f(n);
        REP(i,n-1){
            cin >> to[i];
            to[i]--;
        }
        REP(i,n-1) cin >> length[i];
        REP(i,n-1){
            int x = to[i], y = i + 1;
            e[x].push_back(y);
            e[y].push_back(x);
            d[x].push_back(length[i]);
            d[y].push_back(length[i]);
        }
        REP(i,n) if (e[i].size() > 1) f[i] = 1;
        int root;
        REP(i,n){
            if (f[i]){
                root = i;
                break;
            }
        }
        par[root][0] = root;
        depth[root] = 0;
        dist[root] = 0;
        dfs(root, -1);

        FOR(i,1,17){
            REP(j,n){
                par[j][i] = par[par[j][i-1]][i-1];
            }
        }

        int ans = 0;
        REP(i,n-1){
            if (f[i+1] && f[to[i]]) ans += 3 * length[i];
            else ans += length[i];
        }

        int ma = 0;
        REP(i,n) REP(j,n){
            if (!f[i] || !f[j]) continue;
            ma = max(ma, dist[i]+dist[j]-2*dist[lca(i,j)]);
        }
        ans -= ma;
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 7984
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <climits>
#include <tuple>
#include <queue>
#include <cassert>
//#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define el '\n'
 

 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	ll x, n, t;
	cin >> n>> x>>t;
	cout << t * (n / (x ) +  ((n % (x ))> 0))<<el; 

	
	
    return 0;
}

Measured memory_bytes: 3172
#include<stdio.h>
#include<stdlib.h>

int main(){
  int i = 0;
  int num = 0;
  int min = 0;
  int max = 0;
  int *data;

  while(1){
    scanf("%d",&num);
    if(num >= 2 && num <= 200000){
      break;
    }
  }

  data = (int *)malloc(sizeof(int)* num);

  for(i = 0;i < num;i++){
    while(1){
      scanf("%d",&data[i]);
      if(data[i] >= 1 && data[i] <= 1000000000){
        break;
      }
    }
  }

  min = data[0];
  max = data[1] -min;

  for(i = 1;i < num;i++){
    if(max < data[i] - min){
      max = data[i] -min;
    }
    if(min > data[i]){
      min = data[i];
    }
  }
  printf("%d",max);
  printf("\n");
  free(data);
  return 0;
}



Measured memory_bytes: 2288
#include <iostream>
//与えられた数列が何個あるか分からいときは ➡　bvectorを使う。（以下に説明あり）
#include <vector>
using namespace std;
int main(void){
     
    //数列の個数の変数 n を宣言する
    int n;
    
    //数列の個数の変数 n を入力する
    cin >> n;
    
    //vectorの宣言：vector<型名> 変数名(要素数);
    vector<int> a(n);
    
    //数列を入れるため繰り返し処理する「for文」を使用
    for(int i = 0; i < n; i++){
        cin >> a[i];
    } 
    
    //数列を表示するため繰り返し処理する「for文」を使用 ➡　初期値をいつもの逆から始める
    for(int i = n-1; i >= 0; i--){
        cout << a[i] << ((i != 0) ? " ":"\n"); //3項演算子
    }

    return 0;
}


/********************************************　vector　*****************************************************
 
 
    ●vectorとは可変長配列を用いるときにしよう
        簡単に言う　➡　配列の長さが変化するときに使用する
        
        
    ●書き方
        1. #include <vector>を書く(これ絶対に必要)
        
        2．vector<型名> 変数名(要素数);


*********************************************************************************************************/


/****************************　3項演算子（もう一つの「if文」）　*********************************************
 
 
    ●書き方：式（比較） ? 条件1 : 条件2
            式（比較）が真であれば → 条件1を実行
            式（比較）が偽であれば → 条件2を実行

        ※式tと条件の所は変更しているからね！！！

    ●例えば：a < 5 ? "aは5より大きい" : "aは5以下"
            a < 5が真であれば → aは5より大きいを実行
            a < 5が偽であれば → aは5以下を実行


    ●if文と同じプログラムを以下に書く
        if(a < 5){
            "aは5より大きい" 
        }
        else{
            "aは5以下"
        }
         
     
     
     
*********************************************************************************************************/




/****************************************復習（　for文　）***************************************************
 
 
☆繰り返し処理をしたいときは「　for文　」を使用する
 
 
    〇書き方
    for(始まりの値； 条件式；　増加 or 減少の式){
         
    }
         
     
*********************************************************************************************************/





/****************************************　コメント無し回答　***************************************************
 
#include <iostream>
#include <vector>
using namespace std;
int main(void){
     
    int n;
    cin >> n;
    
    vector<int> a(n);
    
    for(int i = 0; i < n; i++){
        cin >> a[i];
    } 
    
    for(int i = n-1; i >= 0; i--){
        cout << a[i] << ((i != 0) ? " ":"\n");
    }

    return 0;
}
     
*********************************************************************************************************/



























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

int main() {
	int n;
	int ans;
	cin>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a.begin(),a.end());
	for(int i=0;i<n;i++){
//		cout<<a[i]<<endl;
	}
	for(int i=n-1;i>=0;i=i-2){
		ans=ans+a[i];
	}
	for(int i=n-2;i>=0;i=i-2){
		ans=ans-a[i];
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1010;
const int MOD = 1e9+7;
int n,cnt = 0;
int main() {
	string s,t,u;
	int a,b;
	cin >> s >> t >> a >> b >> u;
	if(u == s)
	a--;
	if(u == t)
	b--;
	cout << a << " " << b<<endl;   
	return 0;
}

Measured memory_bytes: 256
/*
Rathin Bhargava
IIIT Bangalore

*/
#include<bits/stdc++.h>
#define mt make_tuple
#define mp make_pair
#define pu push_back
#define INF 1000000001
#define MOD 1000000007
#define EPS 1e-6
#define ll long long int
#define ld long double
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define pr(v) { for(int i=0;i<v.size();i++) { v[i]==INF? cout<<"INF " : cout<<v[i]<<" "; } cout<<endl;}
#define t1(x)                cerr<<#x<<" : "<<x<<endl
#define t2(x, y)             cerr<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl
#define t3(x, y, z)          cerr<<#x<<" : " <<x<<" "<<#y<<" : "<<y<<" "<<#z<<" : "<<z<<endl
#define t4(a,b,c,d)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<endl
#define t5(a,b,c,d,e)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<endl
#define t6(a,b,c,d,e,f)          cerr<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<" "<<#e<<" : "<<e<<" "<<#f<<" : "<<f<<endl
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define t(...) GET_MACRO(__VA_ARGS__,t6,t5, t4, t3, t2, t1)(__VA_ARGS__)
#define _ cerr<<"here"<<endl;
#define __ {ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}

using namespace std;
template<class A, class B> ostream& operator<<(ostream& out, const pair<A, B> &a){ return out<<"("<<a.first<<", "<<a.second<<")";}
template <int> ostream& operator<<(ostream& os, const vector<int>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { if(v[i]!=INF) os << v[i]; else os << "INF";if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { os << "["; for (int i = 0; i < v.size(); ++i) { os << v[i]; ;if (i != v.size() - 1) os << ", "; } os << "]\n"; return os; } 

vector< vector<int> > mat(105,vector<int>(105));


void make(int n)
{
  int k = n/2;
  mat[k+2][k+1] = mat[k+1][k+2] = 1;
  mat[k+1][k-1] = mat[k-1][k+1] = 1;
  mat[k][k+2] = mat[k+2][k] = 1;
  mat[k-1][k] = mat[k][k-1] = 1;

  int left = k-2, right = k+3;
  while(left > 0 && right <= n)
  {
    for(int i=left+1;i<right;i++) 
    {
      mat[left][i] = mat[i][left] = 1;
      mat[right][i] = mat[i][right] = 1;
    }
    left--; right++;
  }
}

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

  if(n%2==1)
  {
    n/=2;
    n*=2;
    make(n);
    for(int i=1;i<=n;i++) mat[i][n+1] = mat[n+1][i] = 1;
  }
  else make(n);

  vector<pair<int,int> > ans;
  int cnt = 0;
  for(int i=1;i<=100;i++)
  {
    for(int j=1;j<i;j++)
    {
      if(mat[i][j]) ans.pu(mp(i,j));
    }
  }

  cout << ans.size() << endl;
  for(int i=0;i<ans.size();i++) cout << ans[i].fi << " " << ans[i].se << endl;

  return 0;
}



Measured memory_bytes: 384