akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int l = sc.nextInt();
		int m = l;
		int num = 0;
		m = m;
		while(m > 0) {
			m = m/2;
			num += 1;
		}
		int rest = l - (int)Math.pow(2, num-1);
		int a[] = new int[num];
		int i = 0;
		while(rest > 0) {
			a[i] = rest % 2;
			rest = rest/2;
			i += 1;
		}

		int road = 0;

		for(int j = 0;j<a.length;j++) {
			road += a[j];
		}
		road = road + 2*(num -1);

		System.out.println(num + " " + road);
		for(int j=0;j<num-1;j++) {
			System.out.println((j+1) + " " + (j+2) + " " + 0);
			System.out.println((j+1) + " " + (j+2) + " " + (int)Math.pow(2, j));
		}
		int rsum = 0;
		for(int j=0;j<num;j++) {
			if(a[j] == 1) {
				System.out.println((j+1) + " " + num + " " + ((int)Math.pow(2, num-1) + rsum));
				rsum += (int)Math.pow(2, j);
			}
		}

	}
}

Measured memory_bytes: 23380
#include<bits/stdc++.h>
using namespace std;
void run_case(){
    long int n;
    cin>>n;
    long long int x=0;
    for(long int i=1;i<n;i++){
        x+=n/i;
        if(n%i==0)x--;
    }
    cout<<x<<endl;


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

}



Measured memory_bytes: 3648
/*
                                               
 ____                 ______           _____   
|    |            ___|\     \      ___|\    \  
|    |           |    |\     \    |    |\    \ 
|    |           |    |/____/|    |    | |    |
|    |        ___|    \|   | |    |    |/____/|
|    |       |    \    \___|/     |    ||    ||
|    |       |    |\     \        |    ||____|/
|____|  ___  |\ ___\|_____|  ___  |____|       
|    | |   | | |    |     | |   | |    |       
|____| |___|  \|____|_____| |___| |____|       
  \(             \(    )/           \(         
   '              '    '             '      
   				template v.1.4   
                                           
*/
#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define sz(s) (int)s.size()
#define OPTIMIZE ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x) cerr << "#" << x << ": " << x << '\n';

using namespace std;

typedef long long LL;
typedef pair<int,int> ii;
typedef pair<LL,LL> pll;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<ii> vii;
typedef vector<pll> vll;

const LL MODPRIME = 1e9 + 7;
const double EPS  = 1e-12;
const LL MAXL = 4e18;
const LL MINL = -4e18;
const int MAXI = 2e9;
const int MINI = -2e9;

const int MAXN = 1e7;

LL A, B, fpb;
bitset<MAXN+3> bs;
vector<LL> primes;

void sieve(){
	bs.set();
	bs[0] = bs[1] = false;
	for (int i = 2; i <= MAXN; ++i){
		if (bs[i]){
			primes.pb(i);
			for (LL j = 1LL * i * i; j <= MAXN; j += i){
				bs[j] = false;
			}
		}
	}
}

int cPrimeFactor(LL x){
	int idx = 0;
	LL pf = primes[idx];
	int res = 0;
	while (pf * pf <= x && idx < sz(primes)){
		if (x%pf == 0){
			++res;
			while (x%pf == 0){
				x /= pf;
			}
		}
		pf = primes[idx++];
	}
	if (x != 1) ++res;
	return res;
}

int main(){
	// #ifndef ONLINE_JUDGE
	//	freopen("in.txt", "r", stdin);
	// #endif
	OPTIMIZE
	sieve();
	cin >> A >> B;
	fpb = __gcd(A, B);
	cout << cPrimeFactor(fpb) + 1 << '\n';
	return 0;
}

Measured memory_bytes: 11884
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  string s1, s2, s3; cin >> s1 >> s2 >> s3;
  cout << s1[0] << s2[1] << s3[2] << endl;
}


Measured memory_bytes: 3588
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    const char E = 'E';
    const char W = 'W';

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var s = input.ReadLine();

        int cLE = 0;
        int cLW = 0;
        int cRE = 0;
        int cRW = 0;

        for (int i=0; i<n; i++) {
            if (s[i] == E) cRE++;
            else cRW++;
        }

        int min = int.MaxValue;

        for(int i=0; i<n; i++) {
            if (s[i] == E) cRE--;
            else cRW--;

            var c = cLW + cRE;
            min = Math.Min(min, c);

            if (s[i] == E) cLE++;
            else cLW++;
        }

        return min;
    }

    static long[] ToIntArray(string strs, int n) {
        var ret = new long[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = long.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 12128
#include <algorithm>
#include <iostream> //入出力
#include <stdio.h>
#include <map>
#include <set>
#include <string>
#include <math.h> //算術演算子
#include <vector>
#include <cstdlib>
#include <queue>
#include <stack>
#include <list>
#include <iomanip> //小数点以下を表示させる(setprecision())
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //64bit型

#define debug(x) cerr << x << " " \
                      << "(L:" << __LINE__ << ")" << '\n'
#define PRINT(V)                                   \
        {                                          \
                for (int i = 0; i < V.size(); i++) \
                {                                  \
                        cout << V[i] << " ";       \
                }                                  \
                cout << endl;                      \
        }

int gcd(int a, int b)
{
        return b ? gcd(b, a % b) : a;
}

int main()
{
        //input->compute->output//
        int x, Y;
        string A;
        cin >> x>>A>>Y;

        if (A[0]=='+')
        {
                cout << x+Y << endl;
        } else{
                cout << x-Y << endl;
        }
        


        return 0;
}


Measured memory_bytes: 256
// Original: https://github.com/tanakh/competitive-rs
#[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)*}
    };
}

#[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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[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, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::BTreeMap;

fn main() {
    input!(n: usize, hs: [i64; n]);

    const INF: i64 = 1 << 30;
    let mut dp = vec![INF; n + 10];
    dp[0] = 0;
    dp[1] = (hs[0] - hs[1]).abs();
    for i in 2..n {
        let c1 = dp[i - 1] + (hs[i] - hs[i - 1]).abs();
        let c2 = dp[i - 2] + (hs[i] - hs[i - 2]).abs();
        dp[i] = min(c1, c2);
    }

    println!("{}", dp[n - 1]);
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
#define ll uint64_t
#define vi vector <int>
#define vl vector <ll>
#define dl pair <ll, ll>
#define ii pair <ll, ll>
#define vii vector <ii>
#define graph vector <vector <int> >
#define inf 1000000000

using namespace std;

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

	int n, x, t;
	cin >> n >> x >> t;
	cout << ((n + x - 1) / x) * t << "\n";
	return 0;
}

Measured memory_bytes: 3648
//https://www.codechef.com/LTIME59A/problems/GCDDIV
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, ans = 0;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        if(a[i] % 2 == 0) {
            if(a[i] % 3 != 0 && a[i] % 5 != 0)
                ans++;
        }
    }
    if(ans == 0)
        cout << "APPROVED" << endl;
    else
        cout << "DENIED" << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
cd = [list(map(int, input().split())) for _ in range(n)]

# aが大きい順に並び替え
ab = sorted(ab, reverse=True)
# dが小さい順に並び替え
cd = sorted(cd, key=lambda x: x[1])

count = 0
for a, b in ab:
    for c, d in cd:
        if a < c and b < d:
            count += 1
            cd.remove([c, d])
            break
print(count)


Measured memory_bytes: 3064
x,n = map(int,input().split())
if n == 0:
  print(x)
else:
  p = list(map(int,input().split()))

if n == 0:
  pass
elif x not in p:
  print(x)
else:
  for i in range(1,101):
    if x-i not in p:
      print(x-i)
      break
    elif x+i not in p:
      print(x+i)
      break



Measured memory_bytes: 9176
#include<iostream>
#include<cstdio>
#include<algorithm>
const int MAXN = 100010;
typedef long long ll;
using namespace std;

int T[MAXN];
int n, k;

int check(ll P)
{
	ll sum;
	int i = 0;
	for(int j = 0; j < k; j++)
	{
		sum = 0;
		while(sum + T[i] <= P)
		{
			sum += T[i];
			i++;
			if(i == n) 
				return i; 
		} 
	}
	return i;
}

int solve()
{
	int v;
	ll left = 0, right = 100000*10000, mid;
	while(left + 1 < right)									//一定要注意此处跳出循环条件 
	{
		mid = (left + right)/2;								//right一定会左移移，而left = mid时可能会陷入死循环 
		v = check(mid);
		
		if(v >= n) 
			right = mid;
		else	
			left = mid;			
	}
	return right; 
}

int main ()
{
	scanf("%d%d", &n, &k);
	for(int i = 0; i < n; i++)
	{
		scanf("%d", &T[i]);	
	}
	cout << solve() << endl;
	return 0;	
} 


Measured memory_bytes: 3640
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <cstdio>
#include <numeric>
#include <functional>
#include <cstdlib>
#include <regex>
#include <list>
#include <cstring>
#include <math.h>

int main(){
	int k, x;
	std::cin >> k >> x;
	for (int i = (k*-1);i < -1;++i) {
		std::cout << x + i + 1 <<" ";
	}
	for (int i = 0;i < k;++i) {
		std::cout << x + i<<" ";
	}
	std::cout << std::endl;
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    double r1, r2; cin >> r1 >> r2;
    cout << r1*r2/(r1+r2) << endl;
}

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

typedef long long ll;

int main(){
    string s;
    cin >> s;
    int a,z;
    for(int i = 0; i < (int)s.size(); i++)
    {
        if(s[i]=='A'){
            a=i;
            break;
        }
    }
    for(int i = (int)s.size()-1; i >= 0; i--)
    {
        if(s[i]=='Z'){
            z=i;
            break;
        }
    }
    
    cout << z-a+1 << endl;
    
    return 0;
}

Measured memory_bytes: 640
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
#define endl '\n'

int gcd(int a, int b);

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	int k;
	
	while (cin >> k)
	{
		
		long long sum = 0;
		for (int a = 1; a <= k; a++)
		{
			for (int b = 1; b <= k; b++)
			{
				for (int c = 1; c <= k; c++)
				{
					sum += gcd(a, gcd(b, c));
				}
			}
		}
		cout << sum << endl;
	}
	//system("pause");
	return 0;
}

int gcd(int a, int b)
{
	if (a == 0)
		return b;
	return gcd(b%a, a);
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main(){
  int i,j,N,ans;
  cin>>N;
  for(i=0;i<N-1;i++){
    for(j=i+1;j<N;j++){
      if(j!=i+1)cout<<" ";
      for(ans=0;;ans++)if((i^j)&(1<<ans))break;
      cout<<ans+1;
    }
    cout<<endl;
  }
}

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

#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RS(x) rsort(x.begin(),x,end()))
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
#define pob pop_back
#define vint(v,n) vector<int> v(n); REP(i,n) scanf("%d", &v[i]);
int INF = 1e9 + 1;
int MOD = 1e9+7;
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
unsigned GetDigit(unsigned num){
    return log10(num)+1;
}

signed main(){
    int n,c=0;
    string s;
    cin >> n >> s;
for(int i=0;i<n-1;i++){
 if(s[i]=='B'&&s[i-1]=='A'&&s[i+1]=='C'){
     c++;
 }

}
cout << c;
             }

Measured memory_bytes: 256
#ABC066-B
def gusu(s):
    l = len(s)
    if l % 2 == 0:
        s_1 = s[:(l//2)]
        s_2 = s[(l//2):]
        if s_1 == s_2:
            return True
        
    return False

s = input()

for i in range(len(s),-1,-1):
    tmp = s[:]
    tmp = tmp[:i-1]
    if gusu(tmp):
        print(len(tmp))
        break

Measured memory_bytes: 3060
import std.stdio, std.algorithm, std.conv, std.array, std.string;

void main()
{
    auto nt = readln.split.map!(to!int);
    auto n = nt[0];
    auto t = nt[1];
    auto as = readln.split.to!(long[]);
 
    long max = 0;
    foreach_reverse (ref a; as) {
        auto tmp = a;
        a = max - a;
        if (tmp > max) max = tmp;
    }
 
    as.sort!"a > b";
    auto top = as[0];
    int cnt;
    foreach (a; as) {
        if (a == top)
            ++cnt;
        else
            break;
    }
    writeln(cnt);
}

Measured memory_bytes: 4532
int_a, int_b, int_k = map(int, input().split())

minset = set(range(int_a, int_a + int_k))
maxset = set(range(int_b - int_k + 1, int_b + 1))

result = list(minset | maxset)
result.sort()
for i in result:
    if int_a <= i <= int_b:
        print(i)



Measured memory_bytes: 3060
K, A, B = map(int, input().split(" "))

if B-A <= 2:
    print(K+1)
    exit()

can_change = (K - (A-1)) // 2
ans = can_change*(B-A) + A
if (K - (A-1)) % 2 == 1:
    ans += 1
print(ans)


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

#define INF INT_MAX

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;



int main(void){
 	cin.tie(0);
    ios::sync_with_stdio(false);
	
	int N,X;
	cin >> N >> X;
	vector<int> L(N);
	for(int i = 0;i < N;i++){
		cin >> L[i];
	}

	int ans = 1;
	int d = 0;
	for(int i = 0;i < N;i++){
		d += L[i];
		if(d > X)continue;
		ans++;
	}

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

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>

using namespace std;


void solve(long long N, long long K, std::vector<long long> H){
    sort(H.begin(), H.end());
    long long ans = 0;
    
    if(N<=K) cout<<"0"<<endl;
    else{
        for(int i=0;i<N-K;i++){
            ans += H[i];
        }
        cout<<ans<<endl;
    }
    return;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> H(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&H[i]);
    }
    solve(N, K, std::move(H));
    return 0;
}


Measured memory_bytes: 1920
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds; 

#define int long long
#define pb push_back
#define pf push_front
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define f first
#define s second
#define sz(x) (int)x.size()
#define endl "\n"
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout<<(x)<<endl
#define watch2(x,y) cout<<(x)<<" "<<(y)<<endl
#define watch3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;

const int INF = 9e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;

int i,n,a[N];

void solve()
{
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    int mx=a[1],ans=0;
    for(i=2;i<=n;i++)
    {
        if(mx>=a[i])
            ans+=mx-a[i];
        else
            mx=a[i];
    }
    cout<<ans;
}

signed main()
{
    fastio;
    int tt;
    //cin>>tt;
    tt=1;
    while(tt--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 5076
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	n := readInt()
	m := readInt()
	e := make([][2]int, m)
	for i := range e {
		e[i][0] = readInt() - 1
		e[i][1] = readInt() - 1
	}
	var ans int
	for i := range e {
		uf := NewUnionFind(n)
		for j := range e {
			if i == j {
				continue
			}
			uf.Union(e[j][0], e[j][1])
		}
		if uf.Size(0) != n {
			ans++
		}
	}
	println(ans)
}

// -----------------------------------------------------------------------------
type UnionFind struct {
	parent []int
	rank   []int
	size   []int
}

// Initialize UnionFind for [0 - n) elements.
// Use n+1 if you need [1 - n] elements
func NewUnionFind(n int) *UnionFind {
	u := &UnionFind{
		parent: make([]int, n),
		rank:   make([]int, n),
		size:   make([]int, n),
	}

	for i := range u.parent {
		u.parent[i] = i
		u.rank[i] = 0
		u.size[i] = 1
	}

	return u
}

func (u *UnionFind) Find(i int) int {
	if u.parent[i] == i {
		return i
	}
	p := u.Find(u.parent[i])
	u.parent[i] = p
	return p
}

func (u *UnionFind) Union(i, j int) {
	p := u.Find(i)
	q := u.Find(j)

	if p == q {
		return
	}

	if u.rank[p] < u.rank[q] {
		p, q = q, p
	}
	u.parent[p] = q
	if u.rank[p] == u.rank[q] {
		u.rank[q]++
	}
	u.size[q] += u.size[p]
}

func (u *UnionFind) Size(i int) int {
	p := u.Find(i)
	return u.size[p]
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using ll=long long;
using namespace std;
#define rep_i(i, n) for (int i = 0; i < (n); ++i)
#define rep_ll(i, n) for (long long i = 0; i < (n); ++i)
#define r_rep_i(i, start, end) for (int i = (start); i < (end); ++i)
#define r_rep_ll(i, start, end) for (long long i = (start); i < (end); ++i)
#define debug_vi(v) copy((v).begin(), (v).end(), ostream_iterator<int>(cout, " "));
#define debug_vll(v) copy((v).begin(), (v).end(), ostream_iterator<long long>(cout, " "));
#define debug_vd(v) copy((v).begin(), (v).end(), ostream_iterator<double>(cout, " "));
#define sort_v(v) sort((v).begin(), (v).end()); //昇順
#define d_sort_vi(v) sort((v).begin(), (v).end(), greater<int>()); //降
#define d_sort_vd(v) sort((v).begin(), (v).end(), greater<double>()); //昇順
#define say(t) cout << (t) << endl;
#define sum_vi(v) accumulate((v).begin(), (v).end(), 0);
#define sum_vll(v)accumulate((v).begin(), (v).end(), 0LL);

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  int n, m; cin >> n >> m;
  if(n == m){
    say("Yes");
  }else{
    say("No");
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define forn(i,a,b) for(int i =a;i<b;i++)
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(false);
using namespace std;

typedef long long int ll;
typedef vector<ll> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int modi = 1e9 + 7;
const int INF = 1e9 + 10;
const int mxn = 1<<20;
int t[2*mxn],lz[2*mxn];

void build(pair<int,int>* a, int v,int tl,int tr){
	if(tl==tr){
		t[v] = a[tl].se;
		// cout << a[tl].fi << " " << a[tl].se << " " << endl;
	}
	else{
		int tm = tl+tr>>1;
		build(a,v<<1,tl,tm);
		build(a,v<<1|1,tm+1,tr);
		t[v] = max(t[v<<1],t[v<<1|1]);
	}
}

void update(int v,int tl,int tr, int l , int r, int val){
	if(lz[v]!=0){
		t[v]+=lz[v];
		if(tl!=tr){
			lz[v<<1]+=lz[v];
			lz[v<<1|1]+=lz[v];
		}
		lz[v] = 0;
	}

	if(l>r || tl>r || tr<l) return;

	if(tl>=l && tr<=r){
		t[v]+=val;
		if(tl!=tr){
			lz[v<<1]+=val;
			lz[v<<1|1]+=val;
		}
		return;
	}

	int tm = tl+tr>>1;
	update(v<<1,tl,tm,l,r,val);
	update(v<<1|1,tm+1,tr,l,r,val);
	t[v] = max(t[v<<1],t[v<<1|1]);
}

int query(int v, int tl,int tr,int l, int r){

	if(l>r || tl>r || tr<l)
		return -INF;

	if(lz[v]!=0){
		t[v]+=lz[v];
		if(tl!=tr){
			lz[v<<1] += lz[v];
			lz[v<<1|1] += lz[v];
		}
		lz[v] = 0;
	}

	if(tl>=l && tr<=r){
		return t[v];
	}

	int tm = tl+tr>>1;
	return max(query(v<<1,tl,tm,l,r),query(v<<1|1,tm+1,tr,l,r));

}


bool cmp(pii a, pii b){
	return a.fi<b.fi || (a.fi == b.fi && a.se<b.se);
}

void solve(){
	int n,d,a;
	cin >> n >> d >> a;

	pair<int,int> mon[n],nmon[n];
	for(int i =0;i<n;i++){
		cin >> mon[i].fi >> mon[i].se;
		nmon[i].fi = -mon[i].fi;
		nmon[i].se = mon[i].se;
		// cout << nmon[i].fi << " " << nmon[i].se << endl;
	}
	sort(mon,mon+n,cmp);
	sort(nmon,nmon+n,cmp);
	build(mon,1,0,n-1);
	// for(int i = mxn;i<mxn+n;i++){
	// 	cout << t[i] << " val of tree" << endl;
	// }
	ll ans = 0;
	for(int i =0;i<n;i++){
		if(query(1,0,n-1,i,i)<=0)continue;
		int l = i;
		int r = upper_bound(mon,mon+n,mp(mon[i].fi + 2*d,INF)) - (mon);
		int del  = -a;
		int times = (query(1,0,n-1,l,l)+a-1)/a;
		// cout << i << " " << l << " " << r << endl;
		// cout << i << " " << l << " " << r  << "  " << times<< endl;

		ans+=times;
		del *=times;
		update(1,0,n-1,l,r-1,del);
	}
	memset(t,0,sizeof(t));
	memset(lz,0,sizeof(lz));
	build(nmon,1,0,n-1);
	for(int i =0;i<n;i++){
		// cout << nmon[i].fi << " " << nmon[i].se << endl;
	}
	ll newans = 0;
	for(int i =0;i<n;i++){
		if(query(1,0,n-1,i,i)<=0)continue;
		int l = i;
		int r = upper_bound(nmon,nmon+n,mp(nmon[i].fi + 2*d,INF)) - (nmon);
		int del  = -a;
		int times = (query(1,0,n-1,l,l)+a-1)/a;
		// cout << i << " " << l << " " << r  << "  " << times<< endl;
		newans+=times;
		del *=times;
		update(1,0,n-1,l,r-1,del);
	}
	ans = min(ans,newans);
	cout << ans << endl;

}

int main(){
	fast;
	// #ifndef ONLINE_JUDGE
	// 	freopen("input.txt","r",stdin);
	// 	freopen("output.txt","w",stdout);
	// #endif

	// int t;cin >> t;while(t--)
		solve();
}


Measured memory_bytes: 19712
n,m = map(int,input().split())
dp = [[10**9]*(2**n+5) for _ in range(m+1)]
dp[0][0] = 0
for i in range(m):
    a,b = map(int,input().split())
    c = list(map(int,input().split()))
    res = 0
    for x in c:
        res|=1<<(x-1)
    for j in range(2**n):
        ni = i+1
        nj = j|res
        dp[ni][j] = min(dp[ni][j],dp[i][j])
        dp[ni][nj] = min(dp[ni][nj],dp[i][j]+a)
ans = dp[m][2**n-1]
if ans == 10**9:ans = -1
print(ans)

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

int main(){
  int t;
  int weight[10];
  int point[4][13];
  int s[5],n[5];
  int kind[4][13];
  string card;
  bool flag;
  bool f = false;

  while(cin >> t){
    if(f)cout << endl;
    f = true;

    for(int i=0;i<4;i++){
      for(int j=0;j<13;j++)cin >> point[i][j];
    }
    weight[0] = 0;
    for(int i=1;i<10;i++)cin >> weight[i];
    
    while(t--){
      for(int i=0;i<4;i++){
	for(int j=0;j<13;j++)kind[i][j] = false;
      }

      for(int i=0;i<5;i++){
	cin >> card;
	if(card[0] == 'A')n[i] = 1;
	else if(card[0] == 'T')n[i] = 10;
	else if(card[0] == 'J')n[i] = 11;
	else if(card[0] == 'Q')n[i] = 12;
	else if(card[0] == 'K')n[i] = 13;
	else n[i] = card[0] - '0';

	if(card[1] == 'S')s[i] = 0;
	else if(card[1] == 'C')s[i] = 1;
	else if(card[1] == 'H')s[i] = 2;
	else if(card[1] == 'D')s[i] = 3;

	kind[s[i]][n[i]-1] = true;
      }

      int ans = 0;
      for(int i=0;i<4;i++){
	for(int j=0;j<13;j++){
	  if(kind[i][j])ans += point[i][j];
	}
      }

      flag = false;
      int c = 9;
      //loyal straight flash
      for(int i=0;i<4;i++){
	if(kind[i][0] && kind[i][9] && kind[i][10] && kind[i][11] && kind[i][12]){
	  flag = true;
	}
      }
      if(!flag){
	c--;
	//straight flash
	for(int i=0;i<4;i++){
	  for(int j=0;j<9;j++){
	    if(kind[i][j] && kind[i][j+1] && kind[i][j+2] && kind[i][j+3] && kind[i][j+4])flag = true;
	  }
	}
	if(!flag){
	  c--;
	  //four card
	  sort(n,n+5);
	  if(n[0] == n[1] && n[1] == n[2] && n[2] == n[3])flag = true;
	  if(n[1] == n[2] && n[2] == n[3] && n[3] == n[4])flag = true;
	  if(!flag){
	    c--;
	    //full house
	    if(n[0] == n[1] && n[1] == n[2] && n[3] == n[4])flag = true;
	    if(n[0] == n[1] && n[2] == n[3] && n[3] == n[4])flag = true;
	    if(!flag){
	      c--;
	      //flash
	      if(s[0] == s[1] && s[1] == s[2] && s[2] == s[3] && s[3] == s[4])flag = true;
	      if(!flag){
		c--;
		//straight
		if(n[0] == n[1]-1 && n[1] == n[2]-1 && n[2] == n[3]-1 && n[3] == n[4]-1)flag = true;
		if(n[0] == 1 && n[1] == 10 && n[2] == 11 && n[3] == 12 && n[4] == 13)flag = true;
		if(!flag){
		  c--;
		  //three card
		  if(n[0] == n[1] && n[1] == n[2])flag = true;
		  if(n[1] == n[2] && n[2] == n[3])flag = true;
		  if(n[2] == n[3] && n[3] == n[4])flag = true;
		  if(!flag){
		    c--;
		    //two pair
		    if(n[0] == n[1] && n[2] == n[3])flag = true;
		    if(n[0] == n[1] && n[3] == n[4])flag = true;
		    if(n[1] == n[2] && n[3] == n[4])flag = true;
		    if(!flag){
		      c--;
		      if(n[0] == n[1])flag = true;
		      if(n[1] == n[2])flag = true;
		      if(n[2] == n[3])flag = true;
		      if(n[3] == n[4])flag = true;
		      if(!flag)c--;
		    }
		  }
		}
	      }
	    }
	  }
	}
      }
      cout << ans * weight[c] << endl;
    }

  }
}

Measured memory_bytes: 932
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;

class Reader {
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    static void init(InputStream input) {
        reader = new BufferedReader(
                new InputStreamReader(input));
        tokenizer = new StringTokenizer("");
    }

    static String next() throws IOException {
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(
                    reader.readLine());
        }
        return tokenizer.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    static float nextFloat() throws IOException {
        return Float.parseFloat(next());
    }
}

public class Main {
    //static final int MOD=1000000007;
    public static void main(String[] args) throws IOException {
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512);
        Reader.init(System.in);
        int test = 1;
        for (int ii = 0; ii < test; ii++) {
            int k = Reader.nextInt();
            String s = Reader.next();
            if (s.length() <= k) out.write(s + "\n");
            else {
                String s1 = s.substring(0, k);
                StringBuffer str = new StringBuffer(s1);
                str.append("...");
                out.write(str.toString() + "\n");
            }
        }
        out.flush();
        out.close();
    }
}



Measured memory_bytes: 36480
//
//  InsertionSort.cpp
//  test
//
//  Created by Sajor on 2019/3/20.
//  Copyright © 2019年 Sajor. All rights reserved.
//

#include <cstdio>
#include <iostream>
using namespace std;

void print(int a[], int n){
    for(int i=0; i<n; i++){
        if (i>0) cout << " ";
        cout << a[i];
    }
    cout << endl;
}

void insertion_sort(int a[], int n){
    int v, j;
    for(int i=1; i<n; i++){
        v = a[i];
        j = i - 1;
        while(j>=0 && a[j]>v) {
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;
        print(a, n);
    }
}

int main()
{
    int N, a[105];
    cin >> N;
    for(int i=0; i<N; i++){
        cin >> a[i];
    }
    print(a, N);
    insertion_sort(a, N);
    return 0;
}



Measured memory_bytes: 3096
fun main(args: Array<String>) {
    val s = readLine()!!
    var r = ""
    for (i in s.indices) {
        when (s[i]) {
            '0', '1' -> r += s[i]
            else -> if (r.isNotEmpty()) r = r.substring(0, r.lastIndex)
        }
    }
    println(r)
}

Measured memory_bytes: 31836
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    int N;cin>>N;
    vi V(N),C(N);
    for(int i=0;i<N;i++)cin>>V[i];
    for(int i=0;i<N;i++)cin>>C[i];
    int ans=0;
    for(int i=0;i<N;i++){
        int a=V[i]-C[i];
        if(a>0)ans+=a;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3588
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<utility>

using namespace std;

typedef long long int64;

int main(void){
    int64 N,D;
    cin>>N>>D;
    if(N%(2*D+1)==0){
        cout<<N/(2*D+1)<<endl;
    }else{
        cout<<N/(2*D+1)+1<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    cout << min(k,n) * x + y * max(0, n-k);
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意

n,k = [int(i) for i in readline().split()]
a= [int(i) for i in readline().split()]

from bisect import *

a.sort()
l = bisect_left(a,k) # a[:l] のみを考える
ans = n-l

m = sum(a[:l])

#print(a[:l])
dp = [0]*(k+1)
dp[0] = 1
for ai in reversed(a[:l]):
#    print(m)
    for i in range(max(0,k-m),k):
        if dp[i]: break
    else: break
    ans += 1
    m -= ai
    for i in range(k-ai,-1,-1):
        if dp[i] == 1: dp[i+ai] = 1 
#    print(dp)

print(n-ans)    

Measured memory_bytes: 41452
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    K,=pin()
    if K==0:
        print(4)
        print(3,3,3,3)
    elif K==1:
        print(3)
        print(1,0,3)
    elif K<=50:
        print(K)
        t=[K]*K
        print(*t)
    else:
        print(50)
        s=K%50
        t=K//50
        t=[50+t-1]*50
        if s>0:
            for i in range(s):
                t=[tt-1 for tt in t]
                t[i]+=51
        print(*t)
#%%submit!
resolve()

Measured memory_bytes: 38512
#include <iostream>
#include <algorithm>
using namespace std;
int a[100];
int selectionSort(int n){
	int cnt = 0;
	for (int i = 0; i <= n - 1; ++i){
		int Minj = i;
		for (int j = i; j <= n - 1; ++j) if (a[j] < a[Minj]) Minj = j;
		if(i!=Minj) swap(a[i], a[Minj]), ++cnt;
	}
	return cnt;
}
int main(){
	int n; cin >> n; 
	for (int i = 0; i < n; ++i) cin >> a[i];
	int cnt=selectionSort(n);
	for (int i = 0; i < n; ++i){
		if (i != 0) cout << ' ';
		cout << a[i];
	}
	cout << '\n' << cnt << '\n';
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fstIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MAX 100005
#define last 1000000000005
 
int main(){
    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    
    ll dp[MAX];
    for(int i=0;i<n+2;i++) dp[i]=last;
    dp[0]=0;

    
    for(int i=0; i<n; i++){
        for(int j=1;j<=k && (i+j)<n ;j++){
         
            dp[i+j] = min(dp[i+j], dp[i]+abs(a[i]-a[i+j]));
        }
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1408
n = gets.to_i
a = 2.times.map{gets.chomp.split(" ").map(&:to_i)}
for i in 1..n-1
  a[0][i] += a[0][i-1]
  a[1][n-1-i] += a[1][n-i]
end
m = 0
for i in 0..n-1
  m = [m,a[0][i]+a[1][i]].max
end
puts m

Measured memory_bytes: 1788
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cstdio>

using namespace std;

int main(void){
  int w, n;
  int cnt = 0;
  while(cin>>w,w){
    vector<pair<int,int> > v;
    long long dp[1001][1001];
    memset(dp, 0, sizeof(dp));
  
    cin>>n;

    for(int i = 0 ; i < n ; i++){
      int s,t;
      scanf("%d,%d",&s,&t);
      v.push_back(make_pair(s,t));
    }
    for(int i = n-1 ; i >= 0 ; i --){
      for(int j = 0 ; j <= w ; j ++){
	if(j < v[i].second) dp[i][j] = dp[i+1][j];
	else dp[i][j] = max(dp[i+1][j] , dp[i+1][j -v[i].second]+v[i].first);
      }						
    }

    cout<<"Case "<<++cnt<<":"<<endl;
    cout<<dp[0][w]<<endl;
    for(int i = w ; ; i--){
      if(dp[0][i] != dp[0][w]){
	cout<<i+1<<endl;
	break;
      }
    }
  }
}

Measured memory_bytes: 9096
x,k,d = map(int,input().split())

a = abs(x)//d

if a >= k:
    print(abs(x)-k*d)
else:
    ax = abs(x)
    if a%2 == k%2:
        print(ax-a*d)
    else:
        print(abs(ax-a*d-d))

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

#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector <int> vi;
typedef vector <ll> vl;
typedef vector <ull> vu;
typedef vector <vector <int>> vvi;
typedef pair <int, int> pi;
typedef vector <pair <int, int>> vpi;

int a, b;

void read() {
  cin >> a >> b;
}

void solve() {
  int nr = b - a;
  cout << nr * (nr + 1) / 2 - b;
}

int main() {
  ios :: sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
  //cin >> t; //please do not forget to comment this if there are no queries
  while(t) {
    --t;
    read();
    solve();
  }
  return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
x = list(map(int, input().split()))
x.sort()
l = []
for i in range(m - 1):
    l.append(x[i + 1] - x[i])
l.sort(reverse=True)
print(x[-1]-x[0]-sum(l[:min(n-1, m-1)]))


Measured memory_bytes: 57512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int count =0;
		int size = sc.nextInt();//size of the array
		for(int i=0;i<size; i++) {
			int p = sc.nextInt();
			Boolean x = findPrime(p);
			//System.out.println(x);
			if(x == true) {
				count++;
			}
		}
		System.out.println(count);
		sc.close();
	}
	
	public static boolean findPrime(int B) {
		if(B==0||B==1) {
			return false;
		}
		else if(B==2||B==3||B==5||B==7) {
			return true;
		}
		for(int j=2; j<= Math.sqrt(B);j++) {
			if(B%j == 0){
				return false;
			}
		}
		return true;
	}
}



Measured memory_bytes: 41400
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair

/*int P[10010];
void init(int n){//Union-find
    for(int i=0;i<n;++i)P[i]=i;
}
int root(int a) {
    if(P[a]==a)return a;
    return (P[a]=root(P[a]));
}
bool is_same_set(int a,int b){
    return root(a) == root(b);//代表元を求める
}
void unite(int a,int b){
    P[root(a)]=root(b);
}//対set,グラフ？
//セグメント木？？
*/

double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }//内積
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }//外積
xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }//投影
//対図形

#define mod 1000000007
/*ll f[2001];
//int n,k とかしておく

ll pw(ll x, ll y){//euclidの互除法より
    ll a= 1;
    while(y){
        if(y&1){//奇数なら
            a = a*x%mod;
        }
        x = x*x%mod;
        y /= 2;
    }
    return a;
}

ll modinv(ll x){//逆元を求める
    return pw(x, mod - 2 );
}

ll comb(int n,int r){
    if(n<r){
        return 0;
    }
    return f[n] * modinv(f[r])%mod*modinv(f[n-r])%mod;
}//対combination//ただしfは用意してね
*/

//cerrはコメントアウトしなくても通る

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);
#define ADD +
#define SUBTRACT -
#define MULTIPLY *
#define DIVIDE /
#define MOD %
#define INCREMENT(x) ++x
#define DECREMENT(x) --x
#define in(a,b) cin>>a>>b;
#define out(a,b) cout<<a<<endl<<b<<endl;
#define scan(a) scanf("%d",&a);
#define print(a) printf("%d\n",a);
#define scanii(a,b) scanf("%d %d",&a,&b);
#define printii(a,b) printf("%d\n%d\n",a,b);
#define scaniii(a,b,c) scanf("%d %d %d",&a,&b,&c);
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define ll long long
#define ull unsigned long long
#define sll signed long long
#define pi acos(-1)
#define mod 1000000007
#define TRUE 1
#define FALSE 0
#define ZERO 0
#define MP make_pair
#define F first
#define S second
#define f1(i,a) for(int i=0;i<a;++i)
#define f2(i,a) for(int i=a-1;i>=0;--i)
#define en puts("");
#define elif else if
typedef ll int lli;
typedef sll int slli;
typedef ull int ulli;
const int sz=10000;
using namespace std;

int clue();
int result();
void show();
bool check();


bool cmp(pair<int,int>p,pair<int,int>q) {
    // return p.first>q.first;//descending by first
    // return p.first<q.first;//ascending by first
    // return p.second>q.second;//descending by second
    return p.second<q.second;//ascending by second
}

// bool cmp(int p,int q) {
    // return p>q;//descending
    // return p<q;//ascending
// }

int main() {

    int t;
    // cin>>t;
    t=1;
    while(t-->0) {
        clue();
    }

    return 0;
}
int clue() {

    int n;
    cin>>n;
    lli sum=0;
    for(int i=1;i<=n;++i) {
        int x=i;
        if((x%3==0)||(x%5==0)||(x%15==0)) {
            sum=sum;
        }
        else
        {
            sum+=i;
        }
        
    }

    cout<<sum<<endl;

    // (det)?cout<<"Yes"<<endl:cout<<"No"<<endl;
    
    return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <limits>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

string A, B;
int K, ans;
int to_int(char ch) { return ch - '0'; }
void dfs(int pos, int down, int cnt, string result)
{
    if(pos >= A.size())
    {
        reverse(result.begin(), result.end());
        ans = max(ans, stoi(result));
        return;
    }
    int c = to_int(A[pos]) - down - to_int(B[pos]);
    if(c >= 0)
    {
        result += to_string(c);
        dfs(pos + 1, 0, cnt, result);
    }
    else
    {
        result += to_string(c + 10);
        if(cnt > 0) dfs(pos + 1, 0, cnt - 1, result);
        dfs(pos + 1, 1, cnt, result);
    }
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ans = 0;
    cin >> A >> B >> K;
    reverse(A.begin(), A.end());
    reverse(B.begin(), B.end());
    while(A.size() != B.size()) B += '0';
    dfs(0, 0, K, "");
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3296
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<bool> vb;
#define deb(x) cout << #x": " << (x) << endl;

const int N = 1e3+5;
const lli INF = 1e18;
const lli MOD = 1e9+7;

bool mm[N];
vi primes(1,2);
ld nk[N][N];
void sieve(){
	for(int i = 4; i<N; i+=2)mm[i]=1;
	for(int i = 3; i*i<=N; i+=2)if(!mm[i])for(int j = i*i; j<N; j+=i)mm[j]=1;
	for(int i = 3; i<N; i+=2)if(!mm[i])primes.pb(i);
}

void pascal(){
	fore(i,0,N)nk[i][0]=nk[i][i]=1.0;
	fore(i,1,N)fore(j,1,i)nk[i][j]=nk[i-1][j-1]+nk[i-1][j];
}

lli gcd(lli a, lli b){return (b?gcd(b,a%b):a);}

lli lcm(lli a, lli b){
	if(a<b)swap(a,b);
	lli c = gcd(a,b);
	a/=c;
	return a*b;
}

int popcount(lli x) { return __builtin_popcountll(x); }

lli poww(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = res * a;
		a = a*a;
		b/=2;
	}
	return res;
}

lli powm(lli a, lli b){
	lli res =1;
	while(b){
		if(b&1) res = (res * a)%MOD;
		a = (a*a)%MOD;
		b/=2;
	}
	return res;
}

bool isPrime(lli x){
	if(x==1)return 0;
	for(auto i:primes){
		if(i*i>x)return 1;
		if(x%i==0)return 0;
	}
	return 1;
}

// ---- コーディングはここから！ ('-')7
const int X = 1e6+5;
int main(){_
int n,a; cin>>n;
vi v(X,0);
fore(i,0,n){cin>>a;v[a]++;}
fore(i,1,X)if(v[i])for(int j = i*2;j<X;j+=i)v[j]=0;
int r =0;
fore(i,1,X)if(v[i]==1)r++;
cout<<r<<ENDL;
}


Measured memory_bytes: 7164
#include <stdio.h>

int main(void){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if(a<b){
    if(b<c){
      printf("Yes\n");
    }else{
      printf("No\n");
    }
  }else{
    printf("No\n");
  }
  
  return 0;
}

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

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

  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }

  int cnt = 1;
  for (int i = 0; i < n; i++) {
    if (a.at(i) == cnt) {
      cnt++;
    }
  }

  if (cnt == 1) {
    cout << -1 << endl;
  }
  else {
    cout << n - (cnt - 1) << endl;
  }
}

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

using namespace std;
#define all(a)a.begin(),a.end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<int>;
using P = pair<int,int>;

int main()
{
   ll ans=0;
   ll x;cin >>x;
   ans+=(x/11)*2;
   x%=11;
   if(x>6)ans+=2;
   else if(x!=0)ans++;
   cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <utility> 
#include <tuple>
#include <iterator>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)

void solve(){
  int n;
  cin >> n;
  
  vector<tuple<string, int, int>> tuples;
  rep(i, n){
    string s;
    int p;
    cin >> s >> p;
    p = -p;
    int j= i+1;
    tuples.emplace_back(s,p,j);
  }
  
  sort(tuples.begin(), tuples.end());
  rep(i,n){
  cout << get<2>(tuples[i]) << endl;
  }
  
  

}

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


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

int main() {
  int a[3][3];
  bool check[3][3];
  for (int i = 0; i < 3; i ++) {
    for (int j = 0; j < 3; j ++) {
      cin >> a[i][j];
      check[i][j] = false;
    }
  }

  int n; cin >> n;
  int t;
  for (int b = 0; b < n; b ++) {
    cin >> t;
    for (int i = 0; i < 3; i ++) {
      for (int j = 0; j < 3; j ++) {
        if (a[i][j] == t) check[i][j] = true;
      }
    }
  }

  string ans = "No";
  for (int i = 0; i < 3; i ++) {
    if (check[i][0] && check[i][1] && check[i][2]) ans = "Yes";
    if (check[0][i] && check[1][i] && check[2][i]) ans = "Yes";
  }
  if (check[2][0] && check[1][1] && check[0][2]) ans = "Yes";
  if (check[0][0] && check[1][1] && check[2][2]) ans = "Yes";

  cout << ans << endl;
}


Measured memory_bytes: 256