akhauriyash/Code-Regression huggingface dataset:
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for (int i = a; i < b; i++)
using namespace std;

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <stack>
#include <bitset>

int main() {
	int N, M;
	cin >> N >> M;

	vector<int> a(M);
	vector<int> b(M);

	rep(i, M) {
		cin >> a.at(i) >> b.at(i);
	}

	vector<int> road(N);
	rep(i, M) {
		road.at(a.at(i) - 1)++;
		road.at(b.at(i) - 1)++;
	}

	rep(i, N) {
		cout << road.at(i) << endl;
	}
}

Measured memory_bytes: 384
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
import heapq
from collections import defaultdict
from heapq import heappop, heappush
import itertools
input = sys.stdin.readline

##### リストの 二分木検索 #####
# bisect_left(lists, 3)
# bisect_right(lists, 3)

##### プライオリティキュー #####
# heapq.heapify(a) #リストaのheap化
# heapq.heappush(a,x) #heap化されたリストaに要素xを追加
# heapq.heappop(a) #heap化されたリストaから最小値を削除＆その最小値を出力

# heapq.heappush(a, -x) #最大値を取り出す時は、pushする時にマイナスにして入れよう
# heapq.heappop(a) * (-1) #取り出す時は、-1を掛けて取り出すこと

##### タプルリストのソート #####
# sorted(ans) #(a, b) -> 1st : aの昇順, 2nd : bの昇順
# sorted(SP, key=lambda x:(x[0],-x[1])) #(a, b) -> 1st : aの昇順, 2nd : bの降順
# sorted(SP, key=lambda x:(-x[0],x[1])) #(a, b) -> 1st : aの降順, 2nd : bの昇順
# sorted(SP, key=lambda x:(-x[0],-x[1])) #(a, b) -> 1st : aの降順, 2nd : bの降順

# sorted(SP, key=lambda x:(x[1])) #(a, b) -> 1st : bの昇順
# sorted(SP, key=lambda x:(-x[1])) #(a, b) -> 1st : bの降順

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))

def main():
	H,W,K = inputMap()
	S = []
	for i in range(H):
		s = input()
		s = list(s)
		s = s[:-1]
		S.append(s)

	cnt = 1
	ans = []
	cpy = 0
	for i,val in enumerate(S):
		tmp = []
		flg1 = False
		flg2 = False

		flg3 = False

		for j,vol in enumerate(val):
			if vol == "#":
				flg2 = True

				if flg1 == False:
					flg1 = True
					tmp.append(cnt)
				else:
					if flg3 == False:
						flg3 = True
						cnt += 1
						tmp.append(cnt)
					else:
						flg3 = False
						cnt += 1
						tmp.append(cnt)
			else:
				tmp.append(cnt)

		#print(flg2)
		if flg2 == False:
			if len(ans) > 0:
				ans.append(ans[-1])
			else:
				cpy += 1
		else:
			ans.append(tmp)
			#print(cpy)
			for i in range(cpy):
				#print("dddd")
				ans.append(tmp)
			cpy = 0
			cnt += 1

	for i in ans:
		print(*i)


if __name__ == "__main__":
	main()


Measured memory_bytes: 49372
H, N = map(int, input().split())
A = [0]*N
B = [0]*N
C = [0]*N
for i in range(N):
    A[i],B[i] = map(int, input().split())
    C[i] = A[i]/B[i]
inf=float("inf")
dp = [[inf for i in range(H+1)] for j in range(N+1)]
for i in range(N+1): dp[i][0]=0
for i in range(N):
    for j in range(H+1):
        dp[i+1][j] = min(dp[i][j],dp[i+1][max(j-A[i],0)]+B[i])
print(dp[N][H])

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

int main(){
    int r, c, n, i, j;
    cin >> r >> c;
    int list[101][101] = {};
    
    for(i = 0; i < r; i++){
        for(j = 0; j < c; j++){
            cin >> n;
            list[i][j] = n;
        }
    }
    
    for(j = 0; j < c; j++){
        int b = 0;
        for(i = 0; i < r; i++){
            b = b + list[i][j];
        }
        list[r][j] = b;
    }
    
    for(i = 0; i < r+1; i++){
        int s = 0 ;
        for(j = 0; j < c; j++){
            s = s + list[i][j];
        }
        list[i][c] = s;
    }
    
    for(i = 0; i < r+1; i++){
        for(j=0; j < c+1; j++){
            if(j == c) cout << list[i][j] << endl;
            else cout << list[i][j] << " ";
        }
    }
    
}


Measured memory_bytes: 3128
#include<iostream>
#include<set>
using namespace std;
struct Point{int x,y,z;};
bool operator<(Point a,Point b)
{
  return a.x!=b.x?(a.x<b.x):(a.y!=b.y?a.y<b.y:a.z<b.z);
}
int main()
{
  int n,h,a,b;
  string c;
  int i;
  while(cin>>n>>h,n|h){
    set<Point>hole;
    while(h-->0){
      cin>>c>>a>>b;
      if(c=="xy"){
	for(i=n;i>=1;i--){
	  Point p={a,b,i};
	  hole.insert(p);
	}
      }else if(c=="xz"){
	for(i=n;i>=1;i--){
	  Point p={a,i,b};
	  hole.insert(p);
	}
      }else{
	for(i=n;i>=1;i--){
	  Point p={i,a,b};
	  hole.insert(p);
	}
      }
    }
    cout<<n*n*n-hole.size()<<endl;
  }
}

Measured memory_bytes: 2336
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<int,P>
#define vpp vector<PP>
#define fi first
#define se second
#define INF 1e9
#define MOD 1000000007
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define all(x) (x).begin(),(x).end()
int main(){
    int d[3][3];
    REP(i,3){
        REP(j,3){
            cin>>d[i][j];
        }
    }
    bool f=true;
    REP(i,2){
        vi a(3);
        REP(j,3){
            a[j]=d[i+1][j]-d[i][j];
        }
        REP(j,3){
            REP(k,3){
                if(a[j]!=a[k]){
                    f=false;
                }
            }
        }
    }
    REP(i,2){
        vi a(3);
        REP(j,3){
            a[j]=d[j][i+1]-d[j][i];
        }
        REP(j,3){
            REP(k,3){
                if(a[j]!=a[k]){
                    f=false;
                }
            }
        }
    }
    if(f){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

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

using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
    int d = a / b;
    int r = a%b;
    double f = (double)a / (double)b;
    cout << d << ' ' << r<<' ';
    printf("%.9f\n", f);
}


Measured memory_bytes: 3244
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    lli K = -1;
    if (N == 1) {
        cout << "Yes" << endl;
        cout << "2" << endl;
        cout << "1 1" << endl;
        cout << "1 1" << endl;
        return 0;
    }
    for (lli i = 1; i <= N; i++) {
        if (i * (i - 1) == 2 * N) {
            K = i;
            break;
        } else if (i * (i - 1) > 2 * N) {
            cout << "No" << endl;
            return 0;
        }
    }
    if (K == -1) {
        cout << "No" << endl;
        return 0;
    }
    vector<vector<int>> ans(K);
    int num = 1;
    REP(i, 0, K) {
        REP(j, 0, i) {
            ans[i].push_back(num);
            ans[j].push_back(num);
            num++;
        }
    }
    cout << "Yes" << endl;
    cout << K << endl;
    REP(i, 0, K) {
        cout << ans[i].size();
        for (auto &j : ans[i]) {
            cout << ' ' << j;
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll a, b, c;
  cin >> a >> b >> c;
  cout << min(b/a, c) << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <set>
using namespace std;
int main(void){
    int a,b,c,x,y,ans=0; cin>>a>>b>>c>>x>>y;
  	if(c*2<a+b){
      for(int i=0;i<min(x,y);i++){
        ans+=2*c;
      }
      if(max(x,y)==x){
        if(c*2<a) ans+=2*c*(x-y);
        else ans+=a*(x-y);
      }else{
        if(c*2<b) ans+=2*c*(y-x);
        else ans+=b*(y-x);
      }
    }else{
      ans=a*x+b*y;
    }
  	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue, Set}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N, M = in.next().toInt
  val graph = Array.fill[List[Int]](N+1)(Nil)

  //
  for (_ <- 1 to M) {
    val s, t = in.next().toInt
    graph(s) = t :: graph(s)
  }

  val dp = new Array[Double](N+1)
  var ans = Double.MaxValue

  for (i <- (1 to N-1).reverse)
    dp(i) = graph(i).map(e => dp(e) + 1).sum / graph(i).length

  if (dp(1) < ans) ans = dp(1)

  for (k <- 1 to N-1) {
    for (i <- (1 to k).reverse) {
      val l = graph(i).length
      val now = graph(i).map(e => dp(e) + 1)

      if (i == k && l > 1)
        dp(i) = (now.sum - now.max) / (l - 1)
      else
        dp(i) = now.sum / l
    }

    if (dp(1) < ans)
      ans = dp(1)
  }

  println(ans)
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}


Measured memory_bytes: 122204
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
int N;
vector<int> P;
int main() {
  cin >> N;
  P.resize(N);
  for (int i = 0; i < N; i++){
    cin >> P[i];
  }
  int cnt = 0;
  for (int i = 0; i < N; i++){
    if (i + 1 == P[i]){
      if (i < N - 1){
        swap(P[i], P[i + 1]);
        cnt++;
      }else{
        cnt++;
      }
    }
  }
  cout << cnt << endl;
  return 0;
}


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


def m():
    if sum(A) < sum(B):
        return -1
    f = 0
    for i in range(N):
        if B[i] > A[i]:
            f = 1
    if f == 0:
        return 0


    C = [A[i]-B[i] for i in range(N)]
    org = [A[i] - B[i] for i in range(N)]
    C.sort(reverse=True)
    org.sort(reverse=True)

    def swapsum(plus, minus):
        if abs(C[plus]) > abs(C[minus]):
            C[plus] += C[minus]
            C[minus] = 0
        else:
            C[minus] += C[plus]
            C[plus] = 0
    ans = 0
    left = 0
    right = N-1
    while C[right] < 0:
        if -C[left] == C[right]:
            swapsum(left, right)
        else:
            swapsum(left,right)
        if C[left] == 0:
            left += 1
            ans += 1
        if C[right] == 0:
            right -=1
            ans +=1
    if org[left] == C[left]:
        return ans
    else:
        return ans+1

print(m())

Measured memory_bytes: 19436
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
 
 
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;
 
using namespace std;


int main()   {
    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, 1000);   // rand_gen(rng) gets the rand no

//    auto start = chrono::steady_clock::now();

//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readll(n);
        map<ll,int> freq;
        ll sum = 0;
        forr(i,0,n) {
            readint(kk);
            freq[kk]++;
            sum += kk;
        }

        readll(q);
        forr(i,0,q) {
            readll(b); readll(c);
            sum += freq[b]*(c-b);
            cout << sum << endl;
            int temp = freq[b];
            freq[b]=0;
            freq[c] += temp;
        }

    }

//    auto end = chrono::steady_clock::now();
//    cout << chrono::duration_cast<chrono::milliseconds>(end - start).count() << endl;

    return 0;
}

Measured memory_bytes: 9332
n,k=map(int,input().split())
if k%2==1:
    a=n//k
    print(a**3)
else:
    k2=k//2
    a=n//k2
    if a%2==0:
        b=a//2
        print(b**3 + b**3)
    else:
        print(((a+1)//2)**3 + ((a-1)//2)**3)

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

int main() {
	int l = 0, t = 0;
	string S;
	cin >> S;
	for (int i = 0; i < 3;i++) {
		if (S.at(i) == 'A') {
			l = 1;
		}if (S.at(i) == 'B') {
			t = 1;
		}
	}

	if (l + t == 2) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		int a = sc.nextInt() + sc.nextInt() + sc.nextInt() + sc.nextInt();
		int b = sc.nextInt() + sc.nextInt() + sc.nextInt() + sc.nextInt();
		System.out.println(Math.max(a, b));
	}

}

Measured memory_bytes: 11000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
int a[1005][1005];
int main(){
    int n,a,fg=1;
    cin>>n;
    set<int>p;
    for(int i=1;i<=n;i++){
        scanf("%d",&a);
        if(p.find(a)!=p.end()) fg=0;
        p.insert(a);
    }
    if(fg==1)printf("YES");
    else printf("NO");
    return 0;
}


Measured memory_bytes: 9600
import qualified Data.IntMap as M
import Data.Maybe (fromJust)
import Data.Array.IO
import Data.List
import Control.Monad

main = do
  k <- readLn :: IO Int
  cost <- newArray (0, k-1) inf :: IO Cost
  let graph = foldl' (make k) M.empty [1..k-1]
      pq = insertPQ 0 Empty $ M.lookup 1 graph
  writeArray cost 1 0
  dijkstra graph pq cost $ pop pq
  ans <- readArray cost 0
  print $ ans + 1

type Cost = IOUArray Int Int
type Node = (Int, Int)

inf = 100

dijkstra :: GraphW -> SkewHeap (Int, Int) -> Cost -> Maybe Node -> IO Cost
dijkstra graph pq cost Nothing = return cost
dijkstra graph pq cost node = do
  let (w, v) = fromJust node
      pq' = deleteMin pq
  c <- readArray cost v
  if c /= inf
    then dijkstra graph pq' cost $ pop pq'
    else do
      writeArray cost v w
      let ne = M.lookup v graph
          pq'' = insertPQ w pq ne
      dijkstra graph pq'' cost $ pop pq''

insertPQ :: Int -> SkewHeap (Int, Int) -> Maybe Neighbor -> SkewHeap (Int, Int)
insertPQ w heap Nothing = heap
insertPQ w heap ne      =
  let neList = M.toList . fromJust $ ne
  in foldl add heap neList
  where add heap (v', w') = push (w'+w, v') heap

type EdgeW = (Int, Int, Int)
type Weight = Int
type Vertex = (Int, Weight)
type GraphW = M.IntMap Neighbor
type Neighbor = M.IntMap Weight

make :: Int -> GraphW -> Int -> GraphW
make k graph i =
  let g = makeGraphW graph (i, mod (i+1) k, 1)
  in makeGraphW g (i, mod (i*10) k, 0)

--重み付き隣接リスト
makeGraphW :: GraphW -> EdgeW -> GraphW
makeGraphW graph (x, y, w) =
  let nX = M.lookup x graph
      nY = M.lookup y graph
  in if nX == Nothing
       then M.insert x (addNeighbor (y, w) M.empty) graph
       else M.insert x (addNeighbor (y, w) $ fromJust nX) graph

addNeighbor :: Vertex -> Neighbor -> Neighbor
addNeighbor (i, weight) ne = M.insert i weight ne

data SkewHeap a = Empty | Node a (SkewHeap a) (SkewHeap a) deriving (Show, Read, Eq)

merge :: Ord a => SkewHeap a -> SkewHeap a -> SkewHeap a
merge Empty h = h
merge h Empty = h
merge h1@(Node x1 l1 r1) h2@(Node x2 l2 r2)
  | x1 <= x2  = Node x1 (merge h2 r1) l1
  | otherwise = Node x2 (merge h1 r2) l2

singleton :: Ord a => a -> SkewHeap a
singleton x = Node x Empty Empty

push :: Ord a => a -> SkewHeap a -> SkewHeap a
push x heap = merge (singleton x) heap

pop :: Ord a => SkewHeap a -> Maybe a
pop Empty = Nothing
pop (Node x l r) = Just x

deleteMin :: Ord a => SkewHeap a -> SkewHeap a
deleteMin Empty = Empty
deleteMin (Node _ l r) = merge l r


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

using namespace std;

typedef long long ll;


int main()
{
	int n, k;

	cin >> n >> k;

	vector<bool> dp(k + 1);
	vector<int> s(n);

	for(int &x : s)
		cin >> x;

	for(int i = s[0]; i <= k; i++)
	{
		for(int x : s)
		{
			if(x > i)
				break;

			dp[i] = dp[i] | !dp[i - x]; 
		}
	}		

	cout << (dp[k] ? "First" : "Second") << endl; 
}

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

cnt = [0]*5
for a in A:
    if a % 4 == 0:
        cnt[4] += 1
    elif a % 2 == 0:
        cnt[2] += 1
    else:
        cnt[1] += 1

if cnt[2] > 0:
    if cnt[4] >= cnt[1]:
        print('Yes')
    else:
        print('No')
else:
    if cnt[4] + 1 >= cnt[1]:
        print('Yes')
    else:
        print('No')

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

int p[550][550];
bool trace[550][550];
int h, w;
vector<vector<int>> op;

bool dfs(int hi, int wi) {
    if (trace[hi][wi]) {
        return false;
    }
    trace[hi][wi] = true;
    if (p[hi][wi] % 2 != 0) {
        p[hi][wi]++;
        trace[hi][wi] = false;
        return true;
    }
    int dir[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
    for (int i = 0; i < 4; ++i) {
        int hj = hi + dir[i][0];
        int wj = wi + dir[i][1];
        if (hj < 0 || hj >= h || wj < 0 || wj >= w) {
            continue;
        }
        if (dfs(hj, wj)) {
            vector<int> o = {hi, wi, hj, wj};
            op.push_back(o);
            return true;
        }
    }
    trace[hi][wi] = false;
    return false;
}

int main(void) {
    cin >> h >> w;
    for (int hi = 0; hi < h; ++hi) {
        for (int wi = 0; wi < w; ++wi) {
            int c;
            cin >> c;
            p[hi][wi] = c;
            trace[hi][wi] = false;
        }
    }
    for (int hi = 0; hi < h; ++hi) {
        for (int wi = 0; wi < w; ++wi) {
            if (p[hi][wi] % 2 != 0) {
                p[hi][wi]--;
                if (!dfs(hi, wi)) {
                    p[hi][wi]++;
                }
            }
        }
    }
    reverse(op.begin(), op.end());
    cout << op.size() << endl;
    for (auto e : op) {
        printf("%d %d %d %d\n", e[0] + 1, e[1] + 1, e[2] + 1, e[3] + 1);
    }
}


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

int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int main(int argc, char const *argv[])
{
    int n;cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;++i)cin>>v[i];
    int ans = gcd(v[0],v[1]);
    for (size_t i = 2; i < n; i++)
    {
        ans=gcd(ans,v[i]);
    }
    
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 640
#[allow(unused_macros)]
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
#[allow(unused_macros)]
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }

// ref: https://github.com/hatoo/competitive-rust-snippets/blob/master/src/misc.rs
fn adjacent4(y: usize, x: usize, sy: usize, sx: usize) -> impl Iterator<Item = (usize, usize)> {
    [(0, 1), (1, 0), (0, -1), (-1, 0)]
        .iter()
        .filter_map(move |&(dy, dx)| {
            let yi = y as isize + dy;
            let xi = x as isize + dx;
            if yi >= 0 && yi < sy as isize && xi >= 0 && xi < sx as isize {
                Some((yi as usize, xi as usize))
            } else {
                None
            }
        })
}

fn main() {
    input! {
        h: usize,
        w: usize,
        s_: [String; h],
    }
    let s: Vec<Vec<char>> = s_.iter().map(|c| c.chars().collect()).collect();

    let mut ret = 0;
    for i in 0..h {
        for j in 0..w {
            if s[i][j] == '.' {
                ret += 1;
            }
        }
    }

    let mut bfs = vec![vec![std::i32::MAX; w]; h];
    let mut que = std::collections::VecDeque::new();
    que.push_front((0, 0, 0));  // (y, x, d)
    while let Some((y, x, d)) = que.pop_back() {
        if bfs[y][x] != std::i32::MAX {
            continue;
        }
        bfs[y][x] = d;

        for (ny, nx) in adjacent4(y, x, h, w) {
            if s[ny][nx] == '#' {
                continue;
            }
            que.push_front((ny, nx, d + 1));
        }
    }

    if bfs[h-1][w-1] == std::i32::MAX {
        println!("-1");
    } else {
        ret -= bfs[h-1][w-1] + 1;
        println!("{}", ret);
    }
}


Measured memory_bytes: 2204
using System;
using System.IO;
using System.Linq;

namespace ABC107
{
    class B
    {
        static void Main(string[] args)
        {
            var HW = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var hw = Enumerable.Repeat(0, HW[0]).Select(_ => Console.ReadLine()).ToArray();

            var resH = new int[HW[0]];
            var resW = new int[HW[1]];
            var isblack = false;
            for (int h = 0; h < HW[0]; h++)
            {
                isblack = false;
                for (int w = 0; w < HW[1]; w++)
                {
                    if (hw[h][w] == '#') isblack = true;
                }
                if (!isblack) resH[h] = 1;
            }

            for (int w = 0; w < HW[1]; w++)
            {
                isblack = false;
                for (int h = 0; h < HW[0]; h++)
                {
                    if (hw[h][w] == '#') isblack = true;
                }
                if (!isblack) resW[w] = 1;
            }

            for (int h = 0; h < HW[0]; h++)
            {
                if (resH[h] == 1) continue;
                for (int w = 0; w < HW[1]; w++)
                {
                    if (resW[w] == 1) continue;
                    Console.Write(hw[h][w]);
                }
                Console.WriteLine();
            }
        }
    }
}


Measured memory_bytes: 13396
#include <stdio.h>
#include <iostream>
using namespace std;
#define MAX 100005
#define NIL -1

struct Node {
    int parent;
    int left;
    int right;
};
Node gNode[MAX];
int gDepth[MAX];
void print(int node){
    cout << "node " << node << ": ";
    cout << "parent = " << gNode[node].parent << ", ";
    cout << "depth = " << gDepth[node] << ", ";
    
    if(gNode[node].parent == NIL) cout << "root, ";
    else if(gNode[node].left == NIL)cout << "leaf, ";
    else cout << "internal node, ";
    
    cout << "[";
    
    for(int i = 0,left = gNode[node].left;left != NIL;++i,left = gNode[left].right){
        if(i) cout << ", ";
        cout << left;
    }
    cout << "]" << endl;
}
void rec(int node ,int parent){
    gDepth[node] = parent;
    if(gNode[node].right != NIL){
        // 右の兄弟に同じ深さを設定
        rec(gNode[node].right,parent);
    }
    if(gNode[node].left != NIL){
        // 最も左の子に自分の深さ+1を設定
        rec(gNode[node].left,parent + 1);
    }
}
int main(){
    int nodeNum,nodeIndex,node,left,root,n;
    cin >> n;
    // 1.初期化
    for(int i = 0;i < n;++i){
        gNode[i].parent = gNode[i].left = gNode[i].right = NIL;
    }
    // 2.nodeに代入していく
    for(int i = 0;i < n;++i){
        cin >> nodeIndex >> nodeNum;
        for(int j = 0;j < nodeNum;++j){
            cin >> node;
            // 初期値はleft
            if(j == 0){
                gNode[nodeIndex].left = node;
            }
            else{
                gNode[left].right = node;
            }
            left = node;
            gNode[node].parent = nodeIndex;
        }
    }
    
    // 3.rootを探す
    for(int i = 0;i < n;++i){
        if(gNode[i].parent == NIL){
            root = i;
        }
    }
    
    // 根からはじめて深さを代入する
    rec(root,0);
    
    // 4.nodeのindexごとに出力する
    for(int i = 0;i < n;++i){
        print(i);
    }
    return 0;
}



Measured memory_bytes: 7768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e9) + 1;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, n) for(int i = 1; i <= (int)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

  int n_ans = n * (n - 1) / 2;
  int m_ans = m * (m - 1) / 2;

  cout << n_ans + m_ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
	char date[12];
	
	scanf("%s", date);
	
	date[0] = '2';
	date[1] = '0';
	date[2] = '1';
	date[3] = '8';
	
	printf("%s\n", date);
	
	return 0;
}

Measured memory_bytes: 1664
package main

import (
	"fmt"
)

func main() {
	var n, a int
	fmt.Scanf("%d", &n)

  	max := 0
	ans := 0
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a)
        if max > a {
          	ans += max - a
        }
        if max < a {
          	max = a
        }
	}
	fmt.Printf("%d\n", ans)
}


Measured memory_bytes: 6428
#include <cstdio>
using namespace std;
int main() {
    int n,k,x,y;
    scanf("%d%d%d%d",&n,&k,&x,&y);
    k--;

    int ans = 0;
    for(int i=0; i<n; i++) ans += (i<=k ? x : y);
    printf("%d\n",ans);
 
    return 0;
}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

char G[55][55];

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

inline bool inside(ll y, ll x, ll H, ll W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll h,w; cin>>h>>w;
  rep(i,h) rep(j,w) cin>>G[i][j];
  
  rep(i,h){
    rep(j,w){
      if(G[i][j]=='#'){
        bool flg=false;
        rep(k,4){
          ll y=i+dy[k], x=j+dx[k];
          if(inside(y,x,h,w) && G[y][x]=='#') flg=true;
        }
        if(!flg){
          cout<<"No"<<endl;
          return 0;
        }
      }
    }
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <map>
#include <vector>
using namespace std;
int main()
{
	int i, j, n, m , x;
	char s[1005];
	int aa[1005];
	int xx;
	scanf("%d %d %d", &n, &m, &x);
	for(i = 1 ; i <= m ;i++)
	{
		scanf("%d", &xx);
		aa[xx] = 1;
	}
	int ans1 = 0,ans2 = 0;
	for(i = 1 ; i < x ; i++)
	{
		if(aa[i] == 1)ans1++;
	}
	for(i = x + 1 ; i < n ; i++)
	{
		if(aa[i] == 1)ans2++;
	}
	printf("%d\n",min(ans1,ans2));
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	for (int i = 1; i <= 100000; i++) {
		if ((int)floor((double)i * 0.08) == a && (int)floor((double)i * 0.1) == b) {
			cout << i << '\n';
			return 0;
		}
	}
	cout << "-1\n";
}


Measured memory_bytes: 256
#include<stdio.h>

int a,b,x1[10000][10000],x2[10000][10000],x,y,n;
int i,j,k;

int main(void)
{
	scanf("%d %d",&a,&b);
	while(a!=0 && b!=0){
		scanf("%d",&n);
		for(i=0;i<=a;i++){
			for(j=0;j<=b;j++){
				x1[i][j]=x2[i][j]=0;
			}
		}
		for(k=0;k<n;k++){
			scanf("%d %d",&x,&y);
			for(i=1;i<=a;i++){
				for(j=1;j<=b;j++){
					if(i==x && j==y){
						x1[i][j]=-1;
					}
				}
			}
		}
		x2[0][1]=1;
		for(i=1;i<=a;i++){
			for(j=1;j<=b;j++){
/*				if(x1[i][j-1]>=1 && x1[i-1][j]>=1 && x1[i][j]!=-1){
					x1[i][j]=x1[i][j-1]+x1[i-1][j];
				}
				else if(x1[i][j-1]>=1 && x1[i-1][j]!=-1 && x1[i][j]!=-1){
					x1[i][j]=x1[i][j-1];
				}*/
				/*else if(x1[i-1][j]>=1 && x1[i][j-1]!=-1 && x1[i][j]!=-1){
					x1[i][j]=x1[i-1][j];
				}*/
				if (x1[i][j] == 0) 	{
					x2[i][j]=x2[i-1][j]+x2[i][j-1];
				}
 			}
		}
	/*	for(i=1;i<=a;i++){
			for(j=1;j<=b;j++){
				printf("%d ",x1[i][j]);
			}
			printf("\n");
		}*/
		printf("%d\n",x2[a][b]);
		scanf("%d %d",&a,&b);
	}
	return 0;
}

Measured memory_bytes: 4760
#include <stdio.h>
 
int main()
{
  int n,i,j,k;
  int b,f,r,v;
  int count[4][3][10];
 
  for (i=0;i<4;i++){
    for (j=0;j<3;j++){
      for (k=0;k<10;k++){
        count[i][j][k]=0;
      }
    }
  }
  scanf("%d",&n);
 
  for (i=0;i<n;i++){
    scanf("%d",&b);
    scanf("%d",&f);
    scanf("%d",&r);
    scanf("%d",&v);
    count[b-1][f-1][r-1]+=v;
  }
 
  for (i=0;i<4-1;i++){
    for (j=0;j<3;j++){
      for (k=0;k<10;k++){
        printf(" %d",count[i][j][k]);
      }
      printf("\n");
    }
    printf("####################\n");
  }
 
  for (j=0;j<3;j++){
    for (k=0;k<10;k++){
      printf(" %d",count[3][j][k]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,q,b[N],ans[N];
int flag,t[4*N],hs[N];
queue<int>qa[N],qb[N];
struct node
{
    int s,t,x;
}a[N];
bool cmp(node a,node b)
{
    return a.x<b.x;
}
void fix(int l,int r,int k,int x)
{
    if(l==r)
    {
        t[k]++;
        return;
    }
    int m=l+r>>1;
    if(x<=m) fix(l,m,k<<1,x);
    else fix(m+1,r,k<<1|1,x);
    t[k]=t[k<<1]+t[k<<1|1];
}
void del(int l,int r,int k,int x)
{
    if(l==r)
    {
        t[k]--;
        if(l==flag) flag=0;
        return;
    }
    int m=l+r>>1;
    if(x<=m) del(l,m,k<<1,x);
    else del(m+1,r,k<<1|1,x);
    t[k]=t[k<<1]+t[k<<1|1];
}
int query(int l,int r,int k)
{
    if(l==r) return hs[l];
    int m=l+r>>1;
    if(t[k<<1]) return query(l,m,k<<1);
    else if(t[k<<1|1]) return query(m+1,r,k<<1|1);
    return -1;
}
int read()
{
    char c=getchar();int x=0,f=1;
    while(c!='-'&&(c<'0'||c>'9')) c=getchar();
    if(c=='-') f=-1,c=getchar();
    while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+c-'0',c=getchar();
    return x*f;
}
int main()
{
    n=read();q=read();
    for(int i=1;i<=n;i++)
        a[i].s=read(),a[i].t=read(),a[i].x=read(),hs[i]=a[i].x;
    sort(hs+1,hs+1+n);
    sort(a+1,a+1+n,cmp);
    for(int i=1;i<=q;i++)
        b[i]=read();
    for(int i=n;i>=1;i--)
    {
        int s=a[i].s,t=a[i].t;
        int l=lower_bound(b+1,b+1+q,s-a[i].x)-b,r=lower_bound(b+1,b+1+q,t-a[i].x)-b-1;
        if(l>r) continue;
        qa[l].push(i);
        qb[r].push(i);
    }
    for(int i=1;i<=q;i++)
    {
        while(!qa[i].empty())
        {
            fix(1,n,1,qa[i].front());
            qa[i].pop();
        }
        if(!flag)
            ans[i]=query(1,n,1);
        else ans[i]=hs[flag];
        while(!qb[i].empty())
        {
            del(1,n,1,qb[i].front());
            qb[i].pop();
        }
    }
    for(int i=1;i<=q;i++)
        printf("%d\n",ans[i]);
}


Measured memory_bytes: 278656
open Scanf
open Printf

(* list->() *)
let rec print_list a_list =
  match a_list with
    [] -> ()
  | fst::[] -> printf "%d" fst;print_newline()
  | fst::rest -> printf "%d " fst;print_list rest
(* output template *)
let lt = "a < b"
let gt = "a > b"
let eq = "a == b"
(* int->int->string *)
let compare a b =
  if a > b then gt
  else if a < b then lt
  else eq
(*  *)
let () =
  print_endline @@ scanf "%d %d" compare

Measured memory_bytes: 2284
#include<bits/stdc++.h>
using namespace std;
#define nn 65536*4
#define ll long long
#define mod 998244353

ll a[nn];ll n;
ll pre1[nn];ll pre2[nn];ll bas=0;
ll smax,smin;ll s[nn];ll ans=0;ll d[nn];
ll extra[nn];ll pre3[nn];
ll gl[nn],gr[nn];
void solve()
{
	for(int i=1;i<=n;i++)
	{
		pre1[i]=pre1[i-1]+a[i];
		if(a[i]%2==0) pre1[i]--;
		
		pre2[i]=pre2[i-1]+a[i];
		if(a[i]%2==1) pre2[i]--;
		else if(a[i]==0) pre2[i]-=2;
	}
	for(int i=n;i>=1;i--)
	{
		pre3[i]=pre3[i+1]+a[i];
		if(a[i]%2==1) pre3[i]--;
		else if(a[i]==0) pre3[i]-=2;
	}
	ll now=0;//cout<<pre3[1]
	for(int i=1;i<=n;i++)
	{
		now=min(now,pre2[i]);
		gl[i]=pre2[i]-now;
	}
	now=0;
	for(int i=n;i>=1;i--)
	{
		now=min(now,pre3[i]);
		gr[i]=pre3[i]-now;
	}
//	cout<<gr[4]<<" ";
	for(int i=n;i>=1;i--) s[i]=pre1[i]+gr[i+1];
	smax=s[n];
	for(int i=n;i>=0;i--)
	{
		smax=max(smax,s[i]);
		ans=max(ans,smax-pre1[i]+gl[i]);
	}
}
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++) 
	{
		scanf("%lld",&a[i]);bas+=a[i];
	}
	solve();
	cout<<bas-ans;
	return 0;
}

Measured memory_bytes: 14080
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
	ll i,j,k,n,t;
    cin>>t>>n;
    if(t==0)
    {
    	if(n==100)
    	cout<<"101"<<endl;
    	else
    	cout<<n<<endl;
    }
    else if(t==1)
    {
    	if(n==100)
    	cout<<"10100"<<endl;
    	else
    	{
    		cout<<n;
    		cout<<"00";
    		cout<<endl;
    	}
    }
    else
    {
    	if(n==100)
    	cout<<"1010000"<<endl;
    	else
    	{
    		cout<<n;
    		cout<<"0000";
    		cout<<endl;
    	}
    }
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))

using namespace std;

int main(void)
{
	vector<vector<int>> A(3, vector<int>(3));
	rep(i, 0, 3)cin >> A[i][0] >> A[i][1] >> A[i][2];
	int N; cin >> N;
	rep(i, 0, N) {
		int b; cin >> b;
		rep(i, 0, 3) {
			rep(j, 0, 3) {
				if (A[i][j] == b)A[i][j] = -1;
			}
		}
	}

	bool flag = false;
	rep(i, 0, 3) {
		if (A[i][0] == -1 && A[i][1] == -1 && A[i][2] == -1)flag = true;
		if (A[0][i] == -1 && A[1][i] == -1 && A[2][i] == -1)flag = true;
	}
	if (A[0][0] == -1 && A[1][1] == -1 && A[2][2] == -1)flag = true;
	if (A[0][2] == -1 && A[1][1] == -1 && A[2][0] == -1)flag = true;
	cout << (flag ? "Yes" : "No") << endl;

	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] get = br.readLine().split(" ");

		List<Integer> abc = new ArrayList<Integer>();
		abc.add(Integer.parseInt(get[0]));
		abc.add(Integer.parseInt(get[1]));
		abc.add(Integer.parseInt(get[2]));
		abc.sort(null);

		int a = abc.get(0); //small
		int b = abc.get(1);
		int c = abc.get(2);

		if(a%2 == b%2){
			System.out.println(((b-a)/2) +(c-b));
			System.exit(0);
		}else{
			a++;
			c++;	//count+1
			System.out.println(((b-a)/2) +(c-b) + 1);
			System.exit(0);
		}


	}
}

Measured memory_bytes: 22996
package main

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

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
)

func main() {
	N := getInt()
	
	num := N / 2
	if N % 2 != 0 {
		num++
	}

	fmt.Println(num)
}

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

func getString() string {
	sc.Scan()
	return sc.Text()
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func powMod(n, p int) int {
	if p == 0 {
		return 1
	} else if p%2 == 0 {
		t := powMod(n, p/2)
		return calcMod(t * t)
	} else {
		return n * powMod(n, p-1)
	}
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray)-1])
}

func calcMod(x int) int {
	return x % mod
}


Measured memory_bytes: 640
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

m = 0
for i in range(N):
    if A[i-1] == A[i]-1 and i != 0:
        m += B[A[i]-1] + C[A[i-1]-1]
    else:
        m += B[A[i]-1]
print(m)

Measured memory_bytes: 8916
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
int gcd(int a, int b)
{
	if (a%b == 0)return b;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int n; cin >> n;
	int cnt = 0;
	for (int i = 1; i <= n; i += 2)
	{
		int d = 0;
		for (int j = 1; j <= i; ++j)
		{
			if (i%j == 0)++d;
		}
		if (d == 8)++cnt;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int main(){
    ll N,temp,maxheight=0,sum=0;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>temp;
        if(temp>=maxheight){
            maxheight=temp;
        }
        else{
            sum=sum+maxheight-temp;
        }
    }   
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>

int Partition(int*,int,int); 

main(){
  int n;
  int i,a,A[100001];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  a = Partition(A,0,n-1);

  for(i=0;i<n-1;i++){
    if(i==a)
      printf("[%d] ",A[i]);
      else printf("%d ",A[i]);
	     }
  printf("%d\n",A[n-1]);

  return 0;
}

int Partition(int *A,int p,int r){
  int i,j,x,tmp;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i=i+1;
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
    }
  }
  tmp=A[i+1];
  A[i+1]=A[r];
  A[r]=tmp;
  return i+1;
}

Measured memory_bytes: 988
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let mut s = sc.chars();
    let mut ok = true;
    let n = s.len();
    for i in 0..n {
        if s[i] != s[n - 1 - i] {
            ok = false;
        }
    }

    let t = (n - 1) / 2;
    for i in 0..t {
        if s[i] != s[t - 1 - i] {
            ok = false;
        }
    }
    s.reverse();
    let t = (n - 1) / 2;
    for i in 0..t {
        if s[i] != s[t - 1 - i] {
            ok = false;
        }
    }

    if ok {
        println!("Yes");
    } else {
        println!("No");
    }
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (N, K): (usize, usize) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    };
    let S: Vec<char> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().chars().collect()
    };

    let a = (0..N)
        .filter(|&i| {
            i >= 1 && S[i - 1] == 'L' && S[i] == 'L' || i + 1 < N && S[i] == 'R' && S[i + 1] == 'R'
        })
        .count();
    let m = S
        .iter()
        .map(|&s| s.to_string())
        .collect::<String>()
        .split(S[0])
        .filter(|&s| s != "")
        .count();
    let ans = if K >= m && S[0] != S[N - 1] {
        a + 2 * m - 1
    } else {
        a + 2 * std::cmp::min(m, K)
    };

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


Measured memory_bytes: 4352
# stack
exp = [i for i in input().split()]
s = []

for lt in exp:
    if lt == '+':
        rhs = s.pop()
        lhs = s.pop()
        s.append(lhs + rhs)
    elif lt == '*':
        rhs = s.pop()
        lhs = s.pop()
        s.append(lhs * rhs)
    elif lt == '-':
        rhs = s.pop()
        lhs = s.pop()
        s.append(lhs - rhs)
    else:
        s.append(int(lt))
        
print(str(s[0]))

Measured memory_bytes: 7696
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin
from collections import Counter

cnt = Counter()
cond = dict()
for line in stdin:
    if line.isspace():
        break
    id = int(line.partition(',')[0])
    cnt[id] += 1
    cond[id] = False

for line in stdin:
    id = int(line.partition(',')[0])
    cnt[id] += 1
    if id in cond:
        cond[id] = True

for id, flag in sorted(cond.items()):
    if flag:
        print(id, cnt[id])

Measured memory_bytes: 4656
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
#include <random>
#include <bitset>
#include <memory>
using namespace std;
typedef long long LL;
//#define _USE_MATH_DEFINES

int main(void) {
	int n, ans = 0, ma = 0;
	string s;
	cin >> n;
	cin >> s;

	for (int i = 0; i < n; i++) {
		vector<int> a(27, 0);
		vector<int> b(27, 0);
		ans = 0;

		for (int j = 0; j < i; j++) {
			a[s[j] - 97]++;
		}
		for (int j = i; j < n; j++) {
			b[s[j] - 97]++;
		}
		for (int j = 0; j < 27; j++) {
			if (a[j] > 0 && b[j] > 0) {
				ans++;
			}
		}
		ma = max(ans, ma);
	}
	cout << ma << endl;
	return 0;
}

Measured memory_bytes: 256
# 全探索

n = gets.to_i
a = gets.chomp.split(' ').map(&:to_i)

flag = true
count = -1

while flag do
    count += 1
    for i in 0..n-1
        if a[i] % 2 != 0
            flag = false
        end
        a[i] = a[i] / 2
    end
end

p count

Measured memory_bytes: 1916