akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
using namespace std;

void add(vector<int> &a, int i, int x) {
    a[i-1] += x;
}

int getSum(vector<int> &a, int s, int t) {
    int sum = 0;
    for(int i=s-1; i<=t-1; ++i) {
        sum += a[i];
    }
    return sum;
}

int main() {
    int n, q;
    cin >> n >> q;
    vector<int> a(n, 0);

    vector<int> com, x, y;
    for(int i=0; i<q; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        com.push_back(a);
        x.push_back(b);
        y.push_back(c);
    }

    for(int i=0; i<q; ++i) {
        if(com[i] == 0) {
            add(a, x[i], y[i]);
        } else if(com[i] == 1) {
            cout << getSum(a, x[i], y[i]) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 4564
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  int n;cin>>n;
  int cnt=0;
  rep(i, n){
    int a;cin>>a;
    if(i%2==0 && a&1)cnt++;
  }
  cout<<cnt<<endl;
  system("read -n 1 -s -p \"Press any key to continue...\"");
}


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

int main(void){
    long long int a,b,c,k;
    long long sum = 0;
    cin >> a >> b >> c >> k;
    if(a <= k)sum += a,k -= a;
    else sum += k,k = 0;
    if(b <= k)k -= b;
    sum -= k;
    cout << sum << endl;
}


Measured memory_bytes: 3636
// author: Saman Mahdanian
#include <bits/stdc++.h>

using namespace std;
const int N = 1e5 + 10;

int n, x[N], y[N], par[N];
vector <int> xs[N], ys[N];
set <int> st[N];

int root (int);
void merge (int, int);

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
		xs[x[i]].push_back(i);
		ys[y[i]].push_back(i);
	}

	iota (par, par + n, 0);
	for (int i = 1; i < N; i++) {
		for (int j: xs[i])
			merge(xs[i][0], j);
		for (int j: ys[i])
			merge(ys[i][0], j);
	}

	for (int i = 0; i < n; i++)
		st[root(i)].insert(i);

	long long ans = 0;
	for (int i = 0; i < n; i++) 
		if (st[i].size()) {
			set <int> cx, cy;
			for (int j: st[i]) {
				cx.insert(x[j]);
				cy.insert(y[j]);
			}
			ans += 1LL * cx.size() * cy.size();
		}
	cout << ans - n << endl;
}

int root (int v) {
	return par[v] == v? v : (par[v] = root(par[v]));
}

void merge (int v, int u) {
	par[root(v)] = root(u);
}

// SamMHD :: Jun27-2019 :: Another Day with Shayan...

Measured memory_bytes: 23296
package main

import "fmt"

func main() {
	var n int
	var s string

	fmt.Scan(&n)
	fmt.Scan(&s)

	answer := 1
	for i := 0; i < n - 1; i++ {
		if s[i] != s[i + 1] {
			answer++
		}
	}
	fmt.Println(answer)
}

Measured memory_bytes: 1280
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
# fractions.gcd() を用いること
# math.log2()はatcoderでは対応していない．留意せよ．

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def find_gcd(list_l):
    x = reduce(gcd, list_l)
    return x


def main():
    a, b, c, x, y = map(int, input().strip().split())
    t1=a*x + b*y
    t2=c * 2 * min(x, y) + (a if x > y else b)*(max(x, y) - min(x, y))
    t3=c * 2 * max(x, y)
    print(min(t1,t2,t3))

if __name__ == '__main__':
    main()


Measured memory_bytes: 61420
#include <iostream>
#include <cstring>
#include <string>    
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
string s, t;
int mps[26], mpt[26];

int main(){
	cin >> s >> t;
	
	for(ll j = 0; j < 26; j++){
		mps[j] = -1;
		mpt[j] = -1;
	}
	
	for(ll i = 0; i < s.size(); i++){
		int cs = s[i]-'a';
		int ct = t[i]-'a';
		
		if(mps[cs] < 0 && mpt[ct] < 0){
			mps[cs] = ct;
			mpt[ct] = cs;
		}
		else{
			if(mps[cs] != ct || mpt[ct] != cs){cout << "No" << endl; return 0;}
		}
	}
	
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 776
use std::cmp::max;
use proconio::{input, fastout};


#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        h: [usize; n],
        v: [(usize, usize); m],
    }
    let mut res: Vec<usize> = vec![0; n];

    for (i, j) in v.iter() {
        res[*i - 1] = max(res[*i - 1], h[*j - 1]);
        res[*j - 1] = max(res[*j - 1], h[*i - 1]);
        // println!("{:?}", res);
    }
    let mut ans: usize = 0;
    for k in 0..n {
        if h[k] > res[k] {
            ans += 1;
        }
    }
    println!("{}", ans);
}

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

using namespace std;

typedef tuple< int, int, int > Pi;

int N, M, L[200000], R[200000];
int ans = 11451419;
Pi first[200000], second[200000];

int check(int vq)
{
  vector< Pi > que2;
  int tail = 1;
  bool used[200000] = {};
  for(int i = 0; i < N; i++) {
    int l, r, idx;
    tie(l, r, idx) = first[i];
    if(tail <= l && tail < vq) {
      tail++;
      used[idx] = true;
    }
  }
  int head = M;
  int ret = 0;
  for(int i = 0; i < N; i++) {
    int l, r, idx;
    tie(r, l, idx) = second[i];
    if(used[idx]) continue;
    r *= -1;
    if(r <= head && head >= tail) {
      head--;
    } else {
      ++ret;
    }
  }
  ans = min(ans, ret);
  return (ret);
}

int main()
{
  cin >> N >> M;
  for(int i = 0; i < N; i++) cin >> L[i] >> R[i];
  for(int i = 0; i < N; i++) first[i] = make_tuple(L[i], -R[i], i);
  for(int i = 0; i < N; i++) second[i] = make_tuple(-R[i], L[i], i);
  sort(second, second + N);
  sort(first, first + N);


  int low = 1, high = M + 1;
  while(high - low > 1) {
    int mid = (low + high) >> 1;
    (check(mid) - check(mid - 1) > 0 ? low : high) = mid;
  }
  check(0);
  check(M + 1);
  for(int i = low - 30; i <= high + 30; i++)check(i);


  cout << ans << endl;
}


Measured memory_bytes: 6656
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		char[] taro;
		char[] hana;

		int tp = 0;
		int hp = 0;

		loop:
		for ( int i=0; i<n; i++ ) {
			taro = sc.next().toCharArray();
			hana = sc.next().toCharArray();

			int tl = taro.length;
			int hl = hana.length;
			int len = Math.min(tl, hl);

			for (int j=0; j<len; j++) {
				if ( taro[j] - hana[j] > 0 ) {
					tp += 3;
					continue loop;
				} else if ( taro[j] - hana[j] < 0 ) {
					hp += 3;
					continue loop;
				}
			}

			if ( tl == hl ) {
				tp += 1;
				hp += 1;
				continue loop;
			} else if ( tl > hl ) {
				tp += 3;
				continue loop;
			} else if ( tl < hl ) {
				hp += 3;
				continue loop;
			}
		}

		System.out.println(tp + " " + hp);
	}

}

Measured memory_bytes: 29764
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



#define SIZE 200005

char S[SIZE],T[SIZE];

int main(){

	scanf("%s",S);
	scanf("%s",T);

	int ans = 0;

	for(int i = 0; S[i] != '\0'; i++){
		if(S[i] != T[i]){

			ans++;
		}
	}

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

	return 0;
}


Measured memory_bytes: 4200
#include<bits/stdc++.h>
using namespace std;
int m,d,ans;
int main(){
	cin>>m>>d;
	for(int i=1;i<=m;i++){
		for(int j=10;j<=d;j++){
			int p=j%10,q=j/10;
			if(p>=2&&q>=2&&p*q==i){
				ans++;
//				cout<<i<<" "<<j<<endl;
			}
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(M)]
B=[None]*M
for i,b in enumerate(reversed(AB)):
    B[i]=(b[0]-1,b[1]-1)
a=[None]*M
a[-1]=N*(N-1)//2
class UnionFind:
    def __init__(self,N):
        self.Parent=[-1]*N
    def unite(self,m,n):
        rm=self.root(m)
        rn=self.root(n)
        if rm==rn:
            return False
        else:
            if self.size(rm)<self.size(rn):
                rm,rn=rn,rm
            self.Parent[rm]+=self.Parent[rn]
            self.Parent[rn]=rm
            return True
    def root(self,n):
        if self.Parent[n]<0:
            return n
        else:
            self.Parent[n]=self.root(self.Parent[n])
            return self.Parent[n]
    def size(self,n):
        return -self.Parent[self.root(n)]
    def route(self,n):
        return self.size(n)*(self.size(n)-1)//2
u=UnionFind(N)
for i,b in enumerate(B[:-1]):
    r1,r2=u.route(b[0]),u.route(b[1])
    if u.unite(b[0],b[1]):
        r3=u.route(b[0])
        a[-2-i]=a[-1-i]-(r3-r1-r2)
    else:
        a[-2-i]=a[-1-i]
for l in a:
    print(l)

Measured memory_bytes: 46852
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}

string sa;

int main(){
	int n,m;
	int i,j,k;
	int a,b,c;
	cin>>n>>m;
	cin>>sa;
	a=0;
	for(i=0;i<n-1;i++){
		if(sa[i]==sa[i+1])a++;
	}
	a+=m*2;
	cout<<min(a,n-1)<<endl;
}

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

#define int             long long
#define INF             1e18
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)

const int MOD = 1e9 + 7;

int f(int step, int a[], int n, int k)
{
    if (step == n - 1)
        return 0;
    int ans = INF;
    for (int i = 1; i <= k; i++)
    {
        if (step + i < n)
            ans = min(ans, abs(a[step] - a[step + i]) + f(step + i, a, n, k));
    }
    return ans;
}

int fdp(int a[], int n, int k)
{
    // dp[i] = min cost to get to here
    vector<int> dp(n, INF);
    dp[0] = 0;
    for (int i = 1; i < n; i++)
    {
        for (int j = 1; j <= k; j++)
            if (i >= j)
                dp[i] = min(dp[i], abs(a[i] - a[i - j]) + dp[i - j]);
    }
    return dp[n - 1]; //min cost to get to n-1th pos
}

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

    int n, k;
    cin >> n >> k;
    int a[n];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    // cout << f(0, a, n, k) << endl;
    cout << fdp(a, n, k);


    return 0;
}


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

int main(){
    int n,m;
    cin >> n >> m;
    int a[n][m],b[m],c[n];
    
    for(int i = 0;i<n;i++){
        c[i] =0;
        for(int j =0;j<m;j++){
            cin >> a[i][j];
        }
    }
    for(int i = 0;i<m;i++){
        cin >> b[i];
    }
    for(int i =0;i<n;i++){
        for(int j = 0;j<m;j++){
            c[i] += b[j]*a[i][j];
        }
        cout << c[i] << endl;
    }
    
}

Measured memory_bytes: 1196
import java.util.Scanner;

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

		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();

		int max = Math.min(A, B);
		int min = N - (A + B);

		if (min < 0) {
			min = Math.abs(min);
		} else {
			min = 0;
		}

		System.out.println(max + " " + min);

	}
}

Measured memory_bytes: 23252
#include <iostream>
#include <cmath>

int main()
{
    int A, B;
    std::cin >> A >> B;

    for (auto i = 1; i <= 1250; i++) {
        if (static_cast<int>(i * 0.08) == A
            && static_cast<int>(i * 0.1) == B) {
            
            std::cout << i;
            return 0;
        }
    }

    std::cout << -1;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
using namespace std;

template<class Abel> struct UnionFind {
	vector<int> par;
	vector<int> rank;
	vector<Abel> diff_weight;

	UnionFind(int n = 1, Abel SUM_UNITY = 0) {
		init(n, SUM_UNITY);
	}

	void init(int n = 1, Abel SUM_UNITY = 0) {
		par.resize(n); rank.resize(n); diff_weight.resize(n);
		for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
	}

	int root(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			int r = root(par[x]);
			diff_weight[x] += diff_weight[par[x]];
			return par[x] = r;
		}
	}

	Abel weight(int x) {
		root(x);
		return diff_weight[x];
	}

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

	bool merge(int x, int y, Abel w) {
		w += weight(x); w -= weight(y);
		x = root(x); y = root(y);
		if (x == y) return false;
		if (rank[x] < rank[y]) swap(x, y), w = -w;
		if (rank[x] == rank[y]) ++rank[x];
		par[y] = x;
		diff_weight[y] = w;
		return true;
	}

	Abel diff(int x, int y) {
		return weight(y) - weight(x);
	}
};

int main() {
	int N, M;
	while (cin >> N >> M) {
		if (N == 0) break;
		UnionFind<int> uf(N);
		for (int i = 0; i < M; ++i) {
			char c; int a, b, w;
			cin >> c;
			if (c == '!') {
				cin >> a >> b >> w; --a, --b;
				uf.merge(a, b, w);
			}
			else {
				cin >> a >> b; --a, --b;
				if (!uf.issame(a, b)) puts("UNKNOWN");
				else cout << uf.diff(a, b) << endl;
			}
		}
	}
}


Measured memory_bytes: 4028
//#define MYDEBUG
#define _CRT_SECURE_NO_WARNINGS
#define TASK "c1"
#pragma comment(linker, "/STACK:67108864")
#include <cstdio>
#include <iostream>
#include <iomanip> 
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>
#include <cassert>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <random>

const int MOD = 1000000007;
const long long INF = 1000000000000000001;
const double EPS = 1e-6;
const int HASH_POW = 29;
const double PI = acos(-1.0);

using namespace std;

double workTime()
{
	return double(clock()) / CLOCKS_PER_SEC;
}

void my_return(int code)
{
#ifdef MYDEBUG
	cout << "\nTime = " << fixed << setprecision(3) << workTime() << endl;
#endif
	exit(code);
}

int n, p[100010];
long long dp[100010][2];

int main()
{
	cin.sync_with_stdio(0);
	cin.tie(0);
	mt19937 mt_rand(time(0));
#ifdef MYDEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	/*freopen(TASK".in", "rt", stdin);
	freopen(TASK".out", "wt", stdout);*/
	/*freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);*/
#endif
	
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &p[i]);

	dp[0][1] = -INF;
	for (int i = 1; i <= n; ++i)
	{
		if (p[i] % 2 == 0)
		{
			dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]) + p[i] / 2;
			if (p[i] > 0)
				dp[i][1] = dp[i - 1][1] + p[i] / 2;
			else
				dp[i][1] = -INF;
		}
		else
		{
			dp[i][0] = dp[i - 1][1] + p[i]/2 + 1;
			dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) + p[i] / 2;
		}
	}
	printf("%lld\n", max(dp[n][0], dp[n][1]));

	my_return(0);
}

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

int main(void)
{
    int N;
    cin >> N;
    vector<vector<int>> G(N, vector<int>());
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < N; j++) {
            if (s[j] == '1') {
                G[i].push_back(j);
            }
        }
    }

    int max_k = -1;
    for (int i = 0; i < N; i++) {
        queue<int> que;
        vector<int> d(N, INT_MAX);
        que.push(i);
        d[i] = 0;
        int k = -1;
        while (que.size()) {
            int p = que.front();
            que.pop();
            for (auto&& v : G[p]) {
                if (d[v] == INT_MAX) {
                    que.push(v);
                    d[v] = d[p]+1;
                    k = d[v]+1;
                } else {
                    if (d[v] != d[p]+1 && d[v] != d[p]-1) {
                        k = -1;
                        break;
                    }
                }
            }
            if (k == -1) break;
        }
        max_k = max(k, max_k);
    }
    cout << max_k << endl;
    return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <iomanip>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

pair<ll, ll> evaluate(int x, const vector<int> &a, const vector<ll> &pref) {
    int n = a.size();
    ll count = 0;
    ll sum = 0;

    fori (i, 0, n) {
        int left = i, right = n - 1;
        int wall = i - 1;
        while (left <= right) {
            int mid = (left + right) / 2;
            if (a[i] + a[mid] >= x) {
                wall = mid; 
                left = mid + 1;
            }
            else {
                right = mid - 1;
            }
        }

        if (wall >= i) {
            int size = (wall - i + 1);
            count += 2 * size - 1;
            ll rs = pref[wall] - (i == 0 ? 0 : pref[i - 1]);
            sum += 2 * ((rs - a[i]) + 1LL * a[i] * (size - 1) + a[i]) ;
        }
    }

    return make_pair(count, sum);
}

void solve() {
    int n;
    ll m;
    cin >> n >> m;

    vector<int> a(n);
    fori (i, 0, n) cin >> a[i];

    sort(begin(a), end(a), greater<int>());

    vector<ll> pref(n);
    pref[0] = a[0];
    fori (i, 1, n) pref[i] = pref[i - 1] + a[i];

    ll left = 2, right = (int) 2e5;
    int lb = -1;

    while (left <= right) {
        ll mid = (left + right) / 2;
        pair<ll, ll> p = evaluate(mid, a, pref);

        if (p.first >= m) {
            lb = mid; 
            left = mid + 1;
        }
        else {
            right = mid - 1;
        }
    }

    pair<ll, ll> p = evaluate(lb + 1, a, pref);
    ll ans = p.second + (m - p.first) * lb;

    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}



Measured memory_bytes: 4528
N, K = map(int, input().split())
H = list(map(int, input().split()))
MAX = 10**9
dp = [MAX]*N
dp[0] = 0
for i in range(0,N):
    for j in range(1,K+1):
        if i+j>=N:
            break
        tmp = dp[i] + abs(H[i+j]-H[i])
        dp[i+j] = min(dp[i+j], tmp)
print(dp[-1])

Measured memory_bytes: 52448
from collections import Counter


n, k, l = map(int, input().split())

def root(x):
    while p[x] >= 0:
        x = p[x]
    return x

def unite(x, y):
    x, y = root(x), root(y)
    if x == y:
        return
    if x > y:
        x, y = y, x
    p[x] += p[y]
    p[y] = x

def g(x):
    global p
    p = [-1]*n
    for _ in range(x):
        a, b = map(int, input().split())
        unite(a-1, b-1)
    return [root(i) for i in range(n)]

z = [*zip(g(k), g(l))]
count = Counter(z)
print(*[count[t] for t in z])

Measured memory_bytes: 54204
open System.Collections.Generic

let K = stdin.ReadLine() |> int64

let queue = new Queue<int64>()

[ 1L..9L ] |> List.iter queue.Enqueue

let mutable n = 0L

let rec func (k : int64) =
    n <- queue.Dequeue()
    match n % 10L with
    | 0L ->
        [ n * 10L + n % 10L
          n * 10L + n % 10L + 1L ]
    | 9L ->
        [ n * 10L + n % 10L - 1L
          n * 10L + n % 10L ]
    | _ ->
        [ n * 10L + n % 10L - 1L
          n * 10L + n % 10L
          n * 10L + n % 10L + 1L ]
    |> List.iter queue.Enqueue
    if k = K - 1L then ()
    else func (k + 1L)

func 0L
n |> printfn "%d"


Measured memory_bytes: 19924
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	if(a<b&&b<c)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}

	
	return 0;
}


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

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

	long sum = 0;

	for(int i = 1; i < N + 1; i++){
		if(i % 3 == 0 || i % 5 == 0){
			continue;
		} else {
			sum += i;
		}
	}

	cout << sum << endl;


}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int a,b=1,c,aa[110000],cnt=0,ab[110000];
string s,ss;
signed main()
{
	cin>>a;
	cin>>aa[0];
	if(aa[0]!=0){
		cout<<0;
		return 0;
	}
	for(int i=1;i<a;i++){
		cin>>aa[i];
		if(aa[i]==0){
			cout<<0;
			return 0;
		}
		ab[aa[i]]++;
	}
	for(int i=2;i<a;i++){
		rep(j,ab[i]){
			b*=ab[i-1];
			b%=998244353;
		}
	}
	cout<<b;
}

Measured memory_bytes: 1792
while(1):
    m,f,r=map(int,input().split(" "))
    if(m==-1 and f==-1 and r==-1):
        break
    total=m+f
    if(m==-1 or f==-1):
        print("F")
    elif(total>=80):
        print("A")
    elif(total>=65):
        print("B")
    elif(total>=50):
        print("C")
    elif(total>=30):
        if(r>=50):
            print("C")
        else:
            print("D")
    else:
        print("F")


Measured memory_bytes: 5596
A,B,C,X,Y=map(int,input().split())
ans=0
if 2*C<A+B:
  Z=min(X,Y)
  X-=Z
  Y-=Z
  ans+=2*C*Z
A=min(A,2*C)
B=min(B,2*C)
ans+=A*X
ans+=B*Y
print(ans)


Measured memory_bytes: 8940
mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    A = input().rstrip('\n')
    B = input().rstrip('\n')
    N = len(A)

    if A == B:
        print(0)
        exit()
    if int(B) == 0:
        print(-1)
        exit()

    def solve(A, B):
        left = [0] * N
        right = [0] * N
        for i in range(N):
            for j in range(N):
                if B[(i-j)%N] == "1":
                    left[i] = j
                    break
        for i in range(N):
            for j in range(N):
                if B[(i+j)%N] == "1":
                    right[i] = j
                    break
        ret = 10**9
        for k in range(N):
            f = 0
            i_list = []
            for i in range(N):
                if A[i] != B[(i-k)%N]:
                    f += 1
                    i_list.append(i)
            lr = [0] * N
            lmax = 0
            rmax = 0
            for i in i_list:
                if left[i] <= k:
                    continue
                lr[left[i] - k] = max(lr[left[i] - k], right[i])
                lmax = max(lmax, left[i] - k)
            ret = min(ret, f + 2 * lmax + k)
            for l in range(N-1, 0, -1):
                rmax = max(rmax, lr[l])
                ret = min(ret, f + 2 * (l - 1 + rmax) + k)
        return ret
    print(min(solve(A, B), solve(A[::-1], B[::-1])))


if __name__ == '__main__':
    main()


Measured memory_bytes: 72184
#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))


a,b=input2()


str_a=str(a)*b
str_b=str(b)*a

print(min(str_a,str_b))

Measured memory_bytes: 3060
//AtCoder Beginner Contest 075
//B - Minesweeper
//Hiia
#include <stdio.h>
#include <stdlib.h>

int main(){

  char a[100][100], b[100][100];
  int h, w, i, j; //height,width

  scanf("%d %d", &h, &w);
  for(i = 1; i <= h; i++) {
    for(j = 1; j <= w; j++) {
      scanf("%c", &a[i][j]);
      if(a[i][j] == '\n') {//Kore ga naito kaigyou mo hairetu toshite yomikomareru yurusann
        j--;//a[i][j] = '\0';
      }
    }
  }

  //printf("\n");
/*
  for(i = 1; i <= h; i++) {
      a[i][0]='x';
      a[i][w+1]='x';
  }
  for(j = 0; j <= w+1; j++) {
    a[0][j]='x';
    a[h+1][j]='x';
  }
*/
/*
  for(i = 0; i <= h+1; ++i) {
    for(j = 0; j <= w+1; ++j) {
      printf("%c", a[i][j]);
      if(j==w+1){
        printf("\n");
      }
    }
  }
*/

  for(i = 1; i <= h; i++) {
    for(j = 1; j <= w; j++) {
      if(a[i][j]=='.'){
            b[i][j]='0';
            if(a[i-1][j-1]=='#') b[i][j]++;
            if(a[i-1][j]=='#') b[i][j]++;
            if(a[i-1][j+1]=='#') b[i][j]++;
            if(a[i][j-1]=='#') b[i][j]++;
            if(a[i][j+1]=='#') b[i][j]++;
            if(a[i+1][j-1]=='#') b[i][j]++;
            if(a[i+1][j]=='#') b[i][j]++;
            if(a[i+1][j+1]=='#') b[i][j]++;
          }
      else{
            b[i][j]=a[i][j];
      }
    }
  }

  for(i = 1; i <= h; ++i) {
    for(j = 1; j <= w; ++j) {
      printf("%c", b[i][j]);
      if(j==w){
        printf("\n");
      }
    }
  }

  return 0;
}


Measured memory_bytes: 1672
#include<stdio.h>
int main(void)
{
	int a,b,c=0;
	char op;
	while(scanf("%d %c %d",&a,&op,&b),op!='?'){
		if(op=='+')	c=a+b;
		else if(op=='-')c=a-b;
		else if(op=='*')c=a*b;
		else if(op=='/')c=a/b;
		printf("%d\n",c);
	}
	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (auto &&i : v) scanf("%d", &i);
    sort(v.begin(),v.end(), greater<>());
    double ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i+1; j < n; ++j) {
            for (int k = 0; k < 3; ++k) {
                for (int l = k+1; l < 4; ++l) {
                    if(i != k && i != l && j != k && j != l){
                        ans = max(ans, 1.0*(v[k]+v[l])/(v[i]-v[j]));
                    }
                }
            }
        }
    }
    printf("%.10lf\n", ans);
    return 0;
}


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

int main(int argc, char const *argv[])
{
	int a, b; cin >> a >> b;
	cout << max(a - b * 2, 0) << endl;
	return 0;
}


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

int N;
int ans[510][510];

void unit(int l, int r, int d = 1)
{
    if(l + 1 == r)return;

    int mid = (l + r) / 2;

    for(int i = l; i < mid; i++)
        for(int j = mid; j < r; j++)
            ans[i][j] = d;

    unit(l, mid, d + 1);
    unit(mid, r, d + 1);
}

int main()
{
    cin >> N;

    unit(0, N);

    for(int i = 0; i < N; i++)
    {
        for(int j = i + 1; j < N; j++)
        {
            cout << ans[i][j];
            if(j != N - 1)cout << " ";
        }
        cout << endl;
    }

    return 0;
}


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

static const long N = 100;

int main(){
	long n, p[N + 1], m[N + 1][N + 1];
	cin >> n;
	for (long i = 1; i <= n; i++) cin >> p[i - 1] >> p[i];
	for (long i = 1; i <= n; i++) m[i][i] = 0;
	for (long l = 2; l <= n; l++){
		for (long i = 1; i <= n - l + 1; i++){
			long j = i + l - 1;
			m[i][j] = (1 << 21);
			for (long k = i; k <= j - 1; k++){
				m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
			}
		}
	}
	cout << m[1][n] << endl;
	return 0;
}

Measured memory_bytes: 1240
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>

#define REP(i,n) for(i=0;i<n;i++)

//prototype declaration
int iin();
long long llin();
double din();
char cin();
void stin(char *s);
void iout(int i);
void llout(long long i);
void dout(double i);
void cout(char c);
void stout(char *s);
int dfs(int v, int n, int *visited, int table[n][n]);
int gcd(int a, int b);
int lcm(int a, int b);
long long llgcd(long long a, long long b);
long long lllcm(long long a, long long b);

//main function
int main() {
    int n = iin(), i;
    if (n == 2) {
        int a = iin(), b = iin();
        iout(a > b ? a : b);
        return 0;
    }
    int a1 = iin(), a2 = iin(), a3 = iin(), hold, gcdmax;
    if (gcd(a1, a2) >= gcd(a2, a3) && gcd(a1, a2) >= gcd(a1, a3)) {
        gcdmax = gcd(a1, a2);
        hold = a3;
    } else if (gcd(a2, a3) > gcd(a1, a2) && gcd(a2, a3) > gcd(a1, a3)) {
        gcdmax = gcd(a2, a3);
        hold = a1;
    } else if (gcd(a1, a3) > gcd(a1, a2) && gcd(a1, a3) > gcd(a2, a3)) {
        gcdmax = gcd(a1, a3);
        hold = a2;
    }
    REP(i, n - 3) {
        a1 = iin();
        if (gcd > gcd(gcdmax, a1)) {
            if (gcd(gcdmax, a1) < gcd(gcdmax, hold)) {
                gcdmax = gcd(gcdmax, hold);
                hold = a1;
            } else {
                gcdmax = gcd(gcdmax, a1);
            }
        }
    }
    iout(gcdmax);
    return 0;
}

//body function
int iin() {
    int i;
    scanf("%d", &i);
    return i;
}

long long llin() {
    long long i;
    scanf("%lld", &i);
    return i;
}

double din() {
    double i;
    scanf("%lf", &i);
    return i;
}

char cin() {
    char c;
    scanf("%c", &c);
    return c;
}

void stin(char *s) {
    scanf("%s", s);
}

void iout(int i) {
    printf("%d\n", i);
}

void llout(long long i) {
    printf("%lld\n", i);
}

void dout(double i) {
    printf("%lf\n", i);
}

void cout(char c) {
    printf("%c\n", c);
}

void stout(char *s) {
    printf("%s\n", s);
}

int dfs(int v, int n, int *visited, int table[n][n]) {
    int all_visited = 1, i;

    REP(i,n) {
        if (!visited[i]) {
            all_visited = 0;
            break;
        }
    }

    if (all_visited) {
        return 1;
    }

    int count = 0;

    REP(i,n) {
        if (!table[v][i]) continue;
        if (visited[i]) continue;

        visited[i] = 1;
        count += dfs(i, n, visited, table);
        visited[i] = 0;
    }

    return count;
}

int gcd(int a, int b) {
    int r;

    if (a < b) {
        r = a;
        a = b;
        b = r;
    }

    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

int lcm(int a, int b) {
    int r = llgcd(a, b);
    a /= r;
    return a * b;
}

long long llgcd(long long a, long long b) {
    long long r;

    if (a < b) {
        r = a;
        a = b;
        b = r;
    }

    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

long long lllcm(long long a, long long b) {
    long long r = llgcd(a, b);
    a /= r;
    return a * b;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;
typedef pair<int, int> Pr;

int N, H;
int d[100000], h[100000];

const int size = 1 << 20;
int seg_v[size * 2 - 1];
int seg_a[size * 2 - 1];
Pr rmq[size * 2 - 1];

void seg_add(int l, int r, int x, int k = 0, int a = 0, int b = size){
	if (b <= l || r <= a) return;
	if (l <= a && b <= r){
		seg_a[k] += x;
		while (k){
			k = (k - 1) / 2;
			seg_v[k] = max(
				seg_v[k * 2 + 1] + seg_a[k * 2 + 1],
				seg_v[k * 2 + 2] + seg_a[k * 2 + 2]
			);
		}
		return;
	}
	
	int m = (a + b) / 2;
	seg_add(l, r, x, k * 2 + 1, a, m);
	seg_add(l, r, x, k * 2 + 2, m, b);
}
int seg_getMax(int l, int r, int k = 0, int a = 0, int b = size){
	if (b <= l || r <= a) return -INF;
	if (l <= a && b <= r) return seg_a[k] + seg_v[k];
	int m = (a + b) / 2;
	int vl = seg_getMax(l, r, k * 2 + 1, a, m);
	int vr = seg_getMax(l, r, k * 2 + 2, m, b);
	return seg_a[k] + max(vl, vr);
}

void rmq_update(int k, int x){
	int i = k;
	k += size - 1;
	rmq[k] = Pr(x, i);
	while (k){
		k = (k - 1) / 2;
		rmq[k] = max(rmq[k * 2 + 1], rmq[k * 2 + 2]);
	}
}
Pr _rmq_getMax(int l, int r, int k = 0, int a = 0, int b = size){
	if (b <= l || r <= a) return Pr(-INF, -1);
	if (l <= a && b <= r) return rmq[k];
	int m = (a + b) / 2;
	Pr vl = _rmq_getMax(l, r, k * 2 + 1, a, m);
	Pr vr = _rmq_getMax(l, r, k * 2 + 2, m, b);
	return max(vl, vr);
}
int rmq_getMax(int l, int r){
	return _rmq_getMax(l, r).first;
}
int rmq_getMaxIdx(int l, int r){
	return _rmq_getMax(l, r).second;
}

void solve()
{
	long long int res = 0;
	
	for (int i = 0; i < N; i++){
		rmq_update(i, h[i]);
	}
	
	seg_add(0, N, H);
	
	for (int fl = 0; fl < N; fl++){
		if (seg_getMax(fl, fl + 1) > H){
			seg_add(fl, N, H - seg_getMax(fl, fl + 1));
		}
		
		seg_add(fl, N, -d[fl]);
		//printf("%dF HP=%d\n", fl, seg_getMax(fl, fl + 1));
		if (seg_getMax(fl, fl + 1) > 0) continue;
		
		while (true){
			int idx = rmq_getMaxIdx(0, fl);
			if (h[idx] > H - seg_getMax(idx, fl)){
				h[idx] = H - seg_getMax(idx, fl);
				rmq_update(idx, h[idx]);
				continue;
			}
			
			/*
			seg_add(idx, N, h[idx]);
			res++;
			if (seg_getMax(fl, fl + 1) > 0) break;
			*/
			
			int s = (H - seg_getMax(idx, fl)) / h[idx];
			int hp = seg_getMax(fl, fl + 1);
			int need = -hp + 1;
			int t = (need / h[idx]) + !!(need % h[idx]);
			int num = min(s, t);
			
			seg_add(idx, N, h[idx] * num);
			res += num;
			if (seg_getMax(fl, fl + 1) > 0) break;
		}
		
		//printf("%dF HP=%d\n", fl, seg_getMax(fl, fl + 1));
	}
	
	printf("%lld\n", res);
}

int main()
{
	scanf("%d %d", &N, &H);
	for (int i = 0; i < N - 1; i++){
		scanf("%d %d", d + i + 1, h + i);
	}
	solve();
}

Measured memory_bytes: 30636
# 初期入力
import sys
input = sys.stdin.readline
A,V = (int(i) for i in input().split())
B,W = (int(i) for i in input().split())
T = int(input())

#T秒以内に距離が０になるか
d =abs(A -B)
speed = V -W
if speed <=0:
    print("NO")
    exit()
else:
    t =d / speed

if t <=T:
    ans ="YES"
else:
    ans ="NO"
print(ans)

Measured memory_bytes: 9200
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
using namespace std;

#define max(a,b) ((a>b)?(a):(b))
#define min(a,b) ((a<b)?(a):(b))

int main(){
  int h,w;
  cin >> h >> w;
  int map[50][50];
  char c;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> c;
      if(c=='#'){
        map[i][j]=1;
      }else{
        map[i][j]=0;
      }
    }
  }
  bool okflag=false;
  int houkou[5] = {0,1,0,-1,0};
  int x,y;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(map[i][j]==1){
        okflag=false;
        for(int k=0;k<4;k++){
          x=j+houkou[k];
          y=i+houkou[k+1];
          if(0<=x&&x<w&&0<=y&&y<h){
            if(map[y][x]==1){
              okflag=true;
            }
          }
        }
        if(!okflag){
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

long long n;
long long minLength;

int main()
{
	scanf("%lld", &n);
	
	minLength = n - 1;
	
	long long curLength;
	long long d = 2;
	while ((d * d) <= n)
	{
		if (n % d == 0)
		{
			curLength = (n / d - 1) + (d - 1);
			
			if (curLength < minLength)
				minLength = curLength;
		}
		
		d++;
	}
	
	printf("%lld\n", minLength);
	
	return 0;
}


Measured memory_bytes: 128
n = int(input())
M = int(n**(0.5))
ans = [0]*(n+1)
for x in range(1,M+1):
    for y in range(1,10**2):
        for z in range(1,10**2):
            if x**2+y**2+z**2+x*y+y*z+z*x > n:
                break
            ans[x**2+y**2+z**2+x*y+y*z+z*x] += 1
        if x**2+y**2 > n:
            break
for i in range(n):
    print(ans[i+1])

Measured memory_bytes: 9624
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;

int main() {
  //
  ll n, h;
  cin >> n >> h;
  vl a(n), b(n);
  vector<pll> d;
  rep(i, n) {
    cin >> a[i] >> b[i];
    d.push_back(make_pair(a[i], 0));
    d.push_back(make_pair(b[i], 1));
  }
  sort(ALL(d));
  reverse(ALL(d));
  ll ans = 0;
  ll cur = 0;
  for (auto& d0 : d) {
    if (d0.second == 1) {
      ans++;
      cur += d0.first;
    } else {
      ll ax = (h - cur) / d0.first;
      if ((h - cur) % d0.first != 0) {
        ax++;
      }
      ans += ax;
      cur += d0.first * ax;
    }
    if (h <= cur) {
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7920
from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
import numpy as np
from collections import deque, Counter, defaultdict
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush, heapify
from bisect import bisect_left, bisect_right, bisect
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
from functools import reduce
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
MOD = 10**9+7
def lcm_base(a, b):
    return (a * b) // gcd(a, b)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def main():
  N, M = map(int,readline().split())
  A = [0]*N
  for i, x in enumerate(map(int,readline().split())):
    A[i] = -x
  heapify(A)
  for _ in range(M):
    x = heappop(A)
    x = -((-x)//2)
    heappush(A, x)
  print(-sum(A))

  
  
if __name__ == '__main__':
  main()

Measured memory_bytes: 24532
#include<stdio.h>

int n,k;
int w[100001];

int check(int p){
  int i;
  int sum=0;
  int idx = 0;
  for(i=0;i<k;i++){
    sum = 0;
    while(w[idx] + sum <= p){
      sum+=w[idx];
      idx++;
      if(idx == n) return 1;
    }
  }
  return 0;
}

int main(){
  int i;
  int left = 0, right = 100000 * 10000;
  int mid ;
  scanf("%d%d",&n,&k);
  for(i=0;i<n;i++) scanf("%d",&w[i]);
  while(right - left > 1){
    mid = (left + right) / 2;
    if(check(mid)==1) right = mid;
    else left = mid;
  }
  printf("%d\n",right);
  return 0;
}

Measured memory_bytes: 984
#include<iostream>
#include<vector>
#include<utility>
#include<string>
#include<cmath>
#include<map>
#include<algorithm>
#include<tuple>
#include<stdio.h>
int main(){
    int n;
    std::cin>>n;
    std::vector<unsigned> array(n);
    for(int i = 0;i < n;i++){
        std::cin>>array[i];
    }
    std::vector<bool> flag(1000000000,false);
    for(int i = 0;i < n;i++){
        if(flag[array[i] - 1] == true){
            puts("NO");
            return 0;
        }
        flag[array[i] - 1] = true;
    }
    puts("YES");
    return 0;
}

Measured memory_bytes: 123136
/******************************************************************************

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

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

#include <stdio.h>

int main()
{
   long long int num1,num2;
    scanf("%lld %lld",&num1,&num2);
    if((num1+num2)%2==0){
        printf("%lld",(num1+num2)/2);
    }else{
        printf("IMPOSSIBLE");
    }

    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n),b(n),c(n-1);
  rep(i,n){
    int x;
    cin >> x;
    x--;
    a[i] = x;
  }
  rep(i,n) cin >> b[i];
  rep(i,n-1) cin >> c[i];
  
  ll ans=0;
  rep(i,n) ans+= b[a[i]];
  
  rep(i,n-1){
    if(a[i+1] == a[i]+1){
      ans += c[a[i]];
    }
  }
  
  cout << ans << endl;
  
  return(0);
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  vint A(N+1);
  rep(i, N) cin >> A[i];
  A[N] = 0;
  int ans = 0;
  rep(i, N) {
    ans += A[i]/2;
    if(A[i+1] > 0) A[i+1] += A[i]%2;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
N,M,X,Y = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
max_x = max(x)
min_y = min(y)
if max_x < min_y and max_x < Y and min_y > X:
	print("No War")	
else:
	print("War")


Measured memory_bytes: 2940
#include<stdio.h>
int main(void)
{
  int w,h,c,a=1,b,d;
scanf("%d",&w);
scanf("%d",&h);
scanf("%d",&c);
while(a<=1000){
  if(w%a==0){
    if(h%a==0)
      b=a;
  }
a++; 
}
d=(w/b)*(h/b)*c;
printf("%d\n",d);
return 0;
}


Measured memory_bytes: 2112
fun main(arr:Array<String>) {
    val (x,y) = readLine()!!.split(" ").map { it.toLong() }
    val multipleGift = mutableListOf(x)
    while (multipleGift.last() * 2 <= y) {
        multipleGift.add(multipleGift.last() * 2)
    }
    println(multipleGift.size)

}


Measured memory_bytes: 38024
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define mod 1000000007
#define prec(n) fixed<<setprecision(n)
int N;
int x[10], y[10];
 
double dist(int i, int j) {
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx * dx + dy * dy, 0.5);
}
 
void solve() {
    cin >> N;
    for(int i = 1; i <= N; i++) cin >> x[i] >> y[i];
    double sum = 0.0;
    vector<int> v(N);
    for(int i = 0; i < N; i++) v[i] = i + 1;
    do {
        for(int i = 0; i < N - 1; i++) sum += dist(v[i], v[i+1]);
    } while(next_permutation(v.begin(), v.end()));
    int Factorial = 1;
    for(int i = 2; i <= N; i++) Factorial *= i;
    cout << fixed << setprecision(10) << sum / Factorial << endl;
    return;
}
 
int main() {
    solve();
    return 0;
}

Measured memory_bytes: 4272
#include<iostream>
#include<vector>

int main()
{
    int count;
    std::cin >> count;

    if( count == 1 )
    {
        std::cout<< "Yes\n";
        return 0;
    }

    std::vector< int > n( count );

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

    int max = 0;

    for( int i = 0; i < count; i++ )
    {
        if( i== 0 )
        {
            max = n[i];
        }
        else
        {
            if( max < n[i] )
            {
                max = n[i];
            }
            else if( n[i] <= max - 2 )
            {
                std::cout<< "No\n";
                return 0;
            }
        }
    }

    std::cout<< "Yes\n";
}


Measured memory_bytes: 768
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>

typedef long long ll;


using namespace std;

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

    int rl = 1; //-1:l 1:r
    string sr = s;
    string sl = "";

    for (int i = 0; i < q; i++) {
        int t;
        cin >> t;

        if (t == 1) {
            rl *= -1;
        }
        else {
            int f;
            cin >> f;
            string c;
            cin >> c;
            
            if (f == 1) {
                if (rl == 1) {
                    sl += c;
                }
                else {
                    sr += c;
                }
            }
            else {
                if (rl == 1) {
                    sr += c;
                }
                else {
                    sl += c;
                }
            }
        }
    }

    reverse(sl.begin(), sl.end());

    sl += sr;

    if (rl == -1) {
        reverse(sl.begin(), sl.end());
    }

    cout << sl;

    return 0;
}

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

int main(){
	int n;
	int money = 100000;
	cin >> n;

	for(int i=0 ; i < n ; i++) {
		money *=1.05;
		if (money % 1000 != 0)
			money = money - money % 1000 + 1000;
	}
		cout << money << "\n";

}

Measured memory_bytes: 1164
import numpy as np

S = input()
NSEW = [S.count("N"), S.count("S"), S.count("E"), S.count("W")]

if np.prod(NSEW) > 0:
    print("Yes")
    exit()
elif NSEW[0] + NSEW[1] > 0 and NSEW[0] * NSEW[1] == 0:
    print("No")
    exit()
elif NSEW[2] + NSEW[3] > 0 and NSEW[2] * NSEW[3] == 0:
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 13216
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;

    vector<int> ta(N+1);
    for(int i = 1;i<=N;i++){
       int d;
       cin>>d;
       ta.at(i)=d;
    }
    
    int ans = 0;
    for(int i = 1;i<=N;i++){
        for(int j = i+1;j<=N;j++){
            ans += ta.at(i)*ta.at(j);
        }
    }
    cout<<ans<<endl;
    
    
    // for(int x:ta){
    //     cout << x << " ";
    // }
}

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

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

int main(){

    int N;
    cin >> N;
    map<string, int> mp;
    rep(i,N){
        string s;
        cin >> s;
        mp[s]++;
    }
    int mx = 0;
    for(auto p : mp)
        mx = max(mx, p.second);
    for(auto p : mp){
        if(p.second!=mx)
            continue;
        cout << p.first << endl;
    }

    return 0;
}


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

using ll = long long;
ll n;
vector<ll> p;

int main() {
	cin >> n;
	for (ll i=2; i*i<=n; i++) {
		if (n % i == 0) {
			ll e = 0;
			while (n % i == 0) {
				e++;
				n /= i;
			}
			p.push_back(e);
		}
	}
	if (n != 1)
		p.push_back(1);
	ll ans = 0;
	for (ll x : p) {
		// cout << x << "\n";
		ll i = 1;
		while (x >= i) {
			x -= i;
			ans++;
			i++;
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3196
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main(int argc, char **argv)
{
    int h1, h2, m1, m2, K;
    cin >> h1 >> m1 >> h2 >> m2 >> K;

    int h = h2 - h1;
    int m = m2 - m1;
    if (m < 0) {
        h--;
        m += 60;
    }
    m = m + h * 60;
    cout << m - K << endl;
    return 0;
}


Measured memory_bytes: 3624