akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

def dfs(v, p, tree, ans):
    for u in tree[v]:
        if u == p:
            continue
        ans[u] += ans[v]
        dfs(u, v, tree, ans)

def main():
    N, Q = map(int, input().split())
    tree = [[] for _ in range(N)]
    for i in range(N - 1):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        tree[a].append(b)
        tree[b].append(a)
    ans = [0] * N
    for i in range(Q):
        p, x = map(int, input().split())
        p -= 1
        ans[p] += x

    dfs(0, -1, tree, ans)

    print(*ans)

main()

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

typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false);
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    ll ans = 0, t = min(x, y);
    ans += min(2 * t * c, a * t + b * t);
    x -= t, y -= t;
    ll left = 0, cost = 0;
    (x > y) ? (left = x, cost = a) : (left = y, cost = b);
    ans += min(2 * left * c, left * cost);
    cout << ans << endl;
}



Measured memory_bytes: 256
import java.util.Scanner;
import java.util.LinkedList;
import java.lang.Math;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long k = sc.nextLong();
        sc.close();
        LinkedList<Long> list = new LinkedList<Long>();//[1]
        for(long i=1;i<10;i++){
            list.add(i);
        }

        long ans=0;

        for(long i=0;i<k;i++){
            ans = list.get(0);
            list.remove(0);
            if(ans%10 != 0){
                list.add(10*ans + ans%10-1);
            }
            list.add(10*ans + ans%10);
            if(ans%10 != 9){
                list.add(10*ans + ans%10+1);
            }
        }
        System.out.println(ans);
    }
        
    public static int[] sort(int[] a){
        int x;
        for(int i=0;i<a.length;i++){
            x = a[i];
            for(int j=0;j<a.length;j++){
                if(x == Math.max(x,a[j])){
                    a[i]=a[j];
                    a[j]=x;
                    x=a[i];
                }
            }
        }
        return a;
    }
}

Measured memory_bytes: 35024
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
  int N;
  cin >> N;
  vector<int> x(N);
  vector<int> y(N);
  double dist=0;
  for(int i=0;i<N;++i){
    cin >> x.at(i) >> y.at(i);
  }

  for(int i=0;i<N;++i){
    for(int j=i;j<N;++j){
      dist+=sqrt(pow(x.at(i)-x.at(j),2)+pow(y.at(i)-y.at(j),2));
    }
  }
  
  dist=dist*2/N;

  printf("%.10f\n",dist);

  return 0;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N,M;
    cin >> N;
    map<string,int> s,t;
    REP(i,N) {
        string S; cin >> S; s[S]++;
    }
    cin >> M;
    REP(i,M) {
        string S; cin >> S; t[S]++;
    }
    int ans = 0;
    for(auto p : s) {
        if(t.count(p.first)) chmax(ans,p.second-t[p.first]);
        else chmax(ans,p.second);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3568
#-*- coding:utf-8 -*-

if __name__ == "__main__":
    N = int(input())
    A = list(map(int, input().split()))
    A.insert(0, 0)
    A.append(0)
    # 本来のコスト計算
    honrai_cost = 0
    for i in range(N+1):
        honrai_cost += abs(A[i]-A[i+1])
    # iを訪れるのをやめたときのコストを計算して出力
    for i in range(1, N+1):
        minus_cost = abs(A[i-1] - A[i]) + abs(A[i] - A[i+1])
        plus_cost  = abs(A[i-1] - A[i+1])
        print(honrai_cost - minus_cost + plus_cost)


Measured memory_bytes: 14044
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9)+7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector< pair<ll, ll> > prime_factorize(ll n) {
  vector< pair<ll, ll> > p;
  for (ll i = 2; i * i <= n; i++) {
    if ((n % i) != 0) continue;
    p.push_back(make_pair(i, 0));
    while ((n % i) == 0) {
      n /= i;
      p[i].second += 1;
    }
    p.push_back(make_pair(n, 0));
  }

  if (n != 1) p.push_back(make_pair(n, 1));
  return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a) {
	ll b = MOD, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= MOD;
	if (u < 0) { u += MOD; }
	return u;
}
// 順列
ll permutation(const ll n, const ll m) {
	ll result = 1;
	for (ll i = n; i > n - m; i--) { result = (result * i) % MOD; }
	return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x) {
	if (x == 0) return 1;
	ll res = repeat_square(n, x/2);
	res = res * res % MOD;
	if ((x % 2) == 1) res = res * n % MOD;
  return res;
}
// 組み合わせ
ll combination(const ll n, const ll a) {
	ll x = 1, y = 1;
  for(ll i = 0; i < a; i++){
    x = x * (n-i) % MOD;
    y = y * (i+1) % MOD;
  }
  return x * repeat_square(y, MOD-2) % MOD;
}

int result = 0;

void dfs(int N, int M, int Q, vector<int> A, map<int, vector<int> > m){
	if (A.size() == N+1) {
		int temp = 0;
		rep(i, Q) {
			int a = m[i][0];
			int b = m[i][1];
			int c = m[i][2];
			int d = m[i][3];
			if ((A[b] - A[a]) == c) temp += d;
		}

		if (temp > result) result = temp;
		return;
	}
	A.push_back(A.back()); // 直前の数を push（A1 <= A2 <= A3 ... An のため）
	while(A.back() <= M) {
		dfs(N, M, Q, A, m);
		A.back()++;
	}
}

int main() {
	int N, M, Q;
	map<int, vector<int> > m;
	cin >> N >> M >> Q;

	rep(i, Q) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		m[i] = vector<int>{a,b,c,d};
	}
	
	dfs(N, M, Q, vector<int> (1, 1), m);
	cout << result << endl;
  return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long
#define double long double
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define mod 1000000007
#define ceil(a,b) (a+b-1)/b
#define endl "\n"
const int N=100005;
const int inf=1e18;
const double eps=1e-9;

#define oa(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define o1(a) cout<<" "<<#a<<" : "<<a<<"\n"
#define o2(a,b) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<"\n"
#define o3(a,b,c) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<"\n"
#define o4(a,b,c,d) cout<<" "<<#a<<" : "<<a<<" "<<#b<<" : "<<b<<" "<<#c<<" : "<<c<<" "<<#d<<" : "<<d<<"\n"

int power(int a,int b){
    int res=1;
    while(b>0){
        if(b&1){
        	res=res*a;
		}
        a=a*a;
        b>>=1;
    }
    return res;
}
int pow1(int a,int b){
    int res=1;
    while(b>0){
        if(b&1){
            res=res*a;
            res%=mod;
        }
        a=a*a;
        a%=mod;
        b>>=1;
    }
    return res;
}
signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	int h,w,m;
    cin>>h>>w>>m;
    int a[m][2];
    map<int,int,greater<int>>r,c1;
    multimap<int,int,greater<int>>c;
    set<pair<int,int>>s;
    for(int x=0;x<m;x++){
        cin>>a[x][0]>>a[x][1];
        r[a[x][0]]++,c1[a[x][1]]++;
        s.insert({a[x][0],a[x][1]});
    }
    for(auto itr2=c1.begin();itr2!=c1.end();itr2++){
        c.insert({itr2->second,itr2->first});
    }
    if(m==1){
        cout<<1;
        return 0;
    }
    // for(auto itr1=c.begin();itr1!=c.end();itr1++){
    //     cout<<"ff "<<itr1->first<<endl;
    // }
    int ans=1;
    for(auto itr=r.begin();itr!=r.end();itr++){
        bool f=0;
        int cans=itr->second;
        for(auto itr1=c.begin();itr1!=c.end();itr1++){
            // cout<<"ff "<<itr1->first<<endl;
            // if(c1>50){
            //     break;
            // }
            if(f){
                break;
            }
            if(s.find({itr->first,itr1->second})!=s.end()){
                ans=max(ans,cans+itr1->first-1);
            }else{
                f=1;
                ans=max(ans,cans+itr1->first);
            }
        }
    }
    cout<<ans;








	
return 0;
}


Measured memory_bytes: 83292
// AtCode ABC 122 A
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	H := readInt()
	W := readInt()
	h := readInt()
	w := readInt()
	all := H * W
	row := h * W
	col := w * (H - h)
	fmt.Println(all - (row + col))
}

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

func readInt() int {
	i, e := strconv.Atoi(read())
	if e != nil {
		panic(e)
	}
	return i
}


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

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

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

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

const ll INF = 1e9+10;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

class UnionFind{
private:
  vector<ll> Parent; 
 public:
  UnionFind(ll N){
    Parent = vector<ll>(N, -1);
  }
  
  ll root(ll A){
    if(Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }
  
  ll size(ll A){
    return -Parent[root(A)]; 
  }
  
  bool connect(ll A, ll B){
    A = root(A);
    B = root(B);
    if(A == B){
      return false;
    }
    if(size(A) < size(B)) swap(A, B);
    Parent[A] += Parent[B];
    Parent[B] = A;
    return true;
  }
  
  bool isSame(ll A, ll B){
    return root(A) == root(B);
  }
};

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  ll n,m; cin>>n>>m;
  UnionFind uf(n);
  rep(i,m){
    ll a,b; cin>>a>>b; a--,b--;
    uf.connect(a,b);
  }
  
  ll ans=0;
  rep(i,n){
    chmax(ans, uf.size(i));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4728
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

const long long INF = 1LL << 60;

int main(void)
{

	int N, K;
	cin >> N >> K;
	vector<long long> h(N);
	for (auto &x : h){
		cin >> x;
	}

	vector<long long> dp(N, INF);
	dp[0] = 0;
	
	for (int i = 0; i < N - 1; i++){
		for (int j = 1; j <= K; j++){
			if (i + j > N - 1) break;
			dp[i + j] = min(abs(h[i] - h[i + j]) + dp[i], dp[i + j]);

		}
	}
	cout << dp[N - 1] << endl;
	return 0;
}

Measured memory_bytes: 1792
def gcd(a,b):
	while b>0:
		a,b=b,a%b
	return a

n=int(input())
a=[0]*n
for i in range(n):
	a[i]=int(input())
if n==1:
	print(a[0])
else:
	r = a[0]*a[1]//gcd(a[0],a[1])
	for i in range(2,n):
		r = r * (a[i]//gcd(r,a[i]))
	print(int(r))

Measured memory_bytes: 38384
import java.util.*;
import java.math.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long h = sc.nextLong();
    long w = sc.nextLong();

    if (h == 1 || w == 1) {
      System.out.println(1);
      return;
    }

    long n = h*w % 2;

    if (n == 0) {
      System.out.println(h*w/2);
    } else {
      System.out.println(h*w/2+n);
    }
  }
}


Measured memory_bytes: 22996
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using in6 = int64_t;
using ind = double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    int a,b;
    cin >> a >> b;
    cout << a * b << " " << (a + b) * 2 << endl;
}


Measured memory_bytes: 3088
#include <stdio.h>
#include <iostream>
#include <string>

using namespace std;

int main(){
    string a, b;
    cin >> a;
    for (int i=0; i < 3; i++){
        if (a[i] == '1') b += '9';
        else if (a[i] == '9') b += '1';
        else{
            b += a[i];
        }
    }
    cout << b << endl;
    

    return 0;
}

Measured memory_bytes: 256
package main

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

var nextString func() string

func init() {
	nextString = newReadString(os.Stdin)
}

func main() {
	h := nextInt()
	w := nextInt()
	a := make([]string, h)

	for i := 0; i < h; i++ {
		a[i] = nextString()
	}

	for i := -1; i <= h; i++ {
		fmt.Print("#")
		if 0 <= i && i < h {
			fmt.Print(a[i])
		} else {
			fmt.Print(strings.Repeat("#", w))
		}
		fmt.Println("#")
	}
}

func nextInt() (result int) {
	result, _ = strconv.Atoi(nextString())
	return
}

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() {
		}
		return r.Text()
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <string>

using namespace std;
int table[8][9] = {
	{1,1,1,0,0,0,0,0,0},
	{0,0,0,1,1,1,0,0,0},
	{0,0,0,0,0,0,1,1,1},
	{1,0,0,1,0,0,1,0,0},
	{0,1,0,0,1,0,0,1,0},
	{0,0,1,0,0,1,0,0,1},
	{1,0,0,0,1,0,0,0,1},
	{0,0,1,0,1,0,1,0,0}
};

int main(){
	string str;
	int field[9];
	int sum, lines;
	
	while(cin >> str){
		for(int i = 0; i < 9; ++i){
			switch(str[i]){
			case 'o':
				field[i] = 1; break;
			case 'x':
				field[i] = -1; break;
			default:
				field[i] = 0; break;
			}
		}
		
		lines = 0;
		for(int i = 0; i < 8; ++i){
			sum = 0;
			for(int j = 0; j < 9; ++j){
				sum += field[j] * table[i][j];
			}
			if(sum == 3 || sum == -3){
				lines += sum / 3;
			}
		}
		switch (lines){
		case 1:
			cout << "o" << endl; break;
		case -1:
			cout << "x" << endl; break;
		default:
			cout << "d" << endl; break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1172
#include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        int A,B,C,X;
        int count=0;
        cin >> A >> B >> C >> X;
        for(int a=0;a<=A;a++){
            for(int b=0;b<=B;b++){
                for(int c=0;c<=C;c++){
                    if(a*500+b*100+c*50==X)count++;
                }
            }
        }
        cout << count << "\n";
    }

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

using namespace std;

const int maxn = 100010;

int w[maxn], x[maxn];

int n, L, T;

pair<int,int> y[maxn];

int main() {
	scanf("%d%d%d", &n, &L, &T);
	for(int i = 0; i < n; ++i) {
		scanf("%d%d", &x[i], &w[i]);
		if(w[i] == 2) w[i] = -1;
	}
	int cur = 0;
	for(int i = 1; i < n; ++i) if(w[i] != w[0]) {
		if(w[i] == -1) {
			if(T * 2 >= x[i] - x[0]) {
				int del = T * 2 - (x[i] - x[0]);
				(cur += del / L + (del % L > 0)) %= n;
			}
		} else {
			if(T * 2 >= x[0] + L - x[i]) {
				int del = T * 2 - (x[0] + L - x[i]);
				(cur -= del / L + (del % L > 0)) %= n;
			}
		}
	}
	if(cur < 0) cur += n;
	for(int i = 0; i < n; ++i) {
		x[i] = (x[i] + w[i] * T) % L;
		if(x[i] < 0) x[i] += L;
		y[i] = {x[i], -w[i]};
	}
	sort(y, y + n);
	auto it = find(y, y + n, pair<int,int>(x[0], -w[0]));
	rotate(y, it, y + n);
	if(cur) rotate(y, y + (n - cur), y + n);
	for(int i = 0; i < n; ++i) {
		printf("%d\n", y[i].first);
	}
	return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
int fact(int n)
{
    if(n==0)
        return 0;
    int sum=1;
    for(int i=1; i<=n; i++)
        sum*=i;
    return sum;
}
int main(int argc,char *argv[])
{
    int n;
    cin>>n;
    int flag[9]= {0};
    int tmp;
    int a=0,b=0,cnt;
    for(int i=0; i<n; i++)
    {
        cin>>tmp;
        cnt=0;
        for(int j=1; j<tmp; j++)
        {
            if(flag[j]==0)
            {
                cnt++;
            }
        }
        a+=cnt*fact(n-i-1);
        flag[tmp]=1;
    }
    memset(flag,0,sizeof(flag));
    for(int i=0; i<n; i++)
    {
        cin>>tmp;
        cnt=0;
        for(int j=1; j<tmp; j++)
        {
            if(flag[j]==0)
            {
                cnt++;
            }
        }
        b+=cnt*fact(n-i-1);
        flag[tmp]=1;
    }
    cout<<fabs(a-b);
}


Measured memory_bytes: 256
n,m = map(int,input().split())
if(n == 1):
    ans = (m+1)%1000000007
    print(ans)
else:
    d = int(m//(n-1))
    ans = (m+1)*d - d*(d+1)//2*(n-1)
    ans *= 2
    ans += (m+1)
    ans %= 1000000007
    print(ans)

Measured memory_bytes: 7720
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i;
	cin>>n;
	int a[n],b[n],c[n];
	int ans1[n],ans2[n],ans3[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i]>>b[i]>>c[i];
	}
	ans1[0]=a[0];
	ans2[0]=b[0];
	ans3[0]=c[0];
	for(i=1;i<n;i++)
	{
		ans1[i]=max(ans2[i-1],ans3[i-1])+a[i];
		ans2[i]=max(ans1[i-1],ans3[i-1])+b[i];
		ans3[i]=max(ans1[i-1],ans2[i-1])+c[i];
	}
	cout<<max(max(ans1[n-1],ans2[n-1]),ans3[n-1])<<endl;
	return 0;
}

Measured memory_bytes: 2560
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[200005], finv[200005], inv[200005];
vector<long long>dij;
struct edge { long long to, cost; };
vector<vector<edge> >G;

long long mod_pow(long long a, long long b) {
	long long res = 1;
	while (b) {
		if (b & 1) { res = res * a%MOD; }
		a = a * a%MOD;
		b >>= 1;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}

//↑template↑

int main() {
	string h, ans = "Heisei";
	cin >> h;
	if (h > "2019/04/30") { ans = "TBD"; }
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int P = 1000000007;
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z main.cpp
//.\a.exe

int main(void){ios::sync_with_stdio(false);cin.tie(0);
////////////////////////////////////////////////////////
int n,a=1;
cin >> n;
string s;
cin >> s;

for(int i=0;i<n-1;i++){
    if(s.at(i)!=s.at(i+1)){
        a++;
    }
}
cout << a << endl;
////////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 512
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            int n = Integer.parseInt(in.next());
            String w[] = new String[n];
            for (int i = 0; i < n; i++) {
                w[i] = in.next();
            }
            int ans = 0;

            for (int i = 1; i < n; i++) {
                if (w[i - 1].charAt(w[i - 1].length() - 1) != w[i].charAt(0)) {
                    out.print("No");
                    return;
                }
                if (isExist(i, w)) {
                    out.print("No");
                    return;
                }
            }

            // 出力
            out.println("Yes");

        }

        private static boolean isExist(int n, String s[]) {
            for (int i = 0; i < n; i++) {
                if (s[i].equals(s[n])) {
                    return true;
                }
            }
            return false;
        }

    }
}



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

a = []
for i in range(n):
    a.append(int(input()))

a.sort()

i = 1
j = n - 1
ans = 0
comp = [a[0], a[0]]
for _ in range(n - 1):
    if comp[1] - a[i] >= a[j] - comp[0]:
        ans += comp[1] - a[i]
        comp[1] = a[i]
        i += 1
    else:
        ans += a[j] - comp[0]
        comp[0] = a[j]
        j -= 1
    comp.sort()
print(ans)

Measured memory_bytes: 7508
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
#define rep(i,n) for(int i=0;i<n;++i)
#define rep2(i,x,n) for(int i=x;i<n;++i)

int main()
{    
    int a,b;
    cin >> a >> b;
    
    cout << 6-a-b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main() {
  int N, A[SIZE];
  multiset<int> ss;

  scanf("%d", &N);

  for (int i=0; i<N; i++) {
    scanf("%d", A+i);
  }

  for (int i=0; i<N; i++) {
    auto it = ss.upper_bound(A[i]-1);

    if (ss.begin() == it) {
      ss.insert(A[i]);
    } else {
      it--;
      ss.erase(it);
      ss.insert(A[i]);
    }
  }

  cout << ss.size() << endl;

  return 0;
}


Measured memory_bytes: 5376
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 1000000000000000007LL;
constexpr int inf = 1000000007;

int main() {
    int n; cin >> n;
    vector<pair<int, int>> range;
    for (int i = 0; i < n; ++i) {
        int x, l; cin >> x >> l;
        range.push_back(make_pair(x + l, x - l));
    }
    sort(range.begin(), range.end());
    int ans = 1;
    int rmax = range.front().first;
    for (int i = 1; i < n; ++i) {
        if (rmax <= range[i].second) {
            ++ans;
            rmax = range[i].first;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "limits.h"
#include "bitset"
#define lp(n) for (int i = 0; i < n; i++)
#define lop(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define ll long long int
#define sp ' '
using namespace std;

string s;
ll ans;
ll cnt;

ll gcd(ll x, ll y) {
	if (y == 0) return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	ll g = gcd(x, y);
	return x / g * y;
}

int main(){
	cin >> s;
	ans = 0;
	lp(s.size()) {
		cnt = 0;
		cnt += pow(10, s.size() - i - 1);
//		cout<< pow(10, s.size() - i - 1)<<sp;
		for (int j = s.size() - i - 2; j >= 0; j--) {
//			cout<< pow(10, j)*(1 << (s.size() - 2 - j-i))<<sp;
			cnt += pow(10, j)*(1 << (s.size() - 2 - j-i));
		}
		cnt = (cnt << i)*(s[i]-'0');
//		cout <<endl<<s[i]<<sp<< cnt << endl;
		ans += cnt;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
#include<algorithm>
#include<stdio.h>
/*
*▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
*    ▀▀       ▀▀▀▀▀▀    ▀     ▀▀▀▀▀▀      ▀    ▀
*   ▀  ▀      ▀         ▀     ▀            ▀  ▀
*  ▀    ▀     ▀ ▀ ▀     ▀     ▀ ▀ ▀         ▀
* ▀ ▀▀▀▀ ▀    ▀         ▀     ▀             ▀
*▀        ▀   ▀         ▀     ▀             ▀
*▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
*/
using namespace std;
void afify()
{
	ios::sync_with_stdio(0);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
//===============================================
#define ll long long
#define ld long double
#define mk make_pair
#define loop(i,intial,n)  for(int i=(intial);i<n;i++)
#define loopn(j,n,ends) for(int j=int(n-1);j>=ends;j--)
#define loopm(name)  for(auto it : name)
#define loopm2(name)  for(auto it2 : name)
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(v) v.begin(),v.end()
#define PI (ld)(3.14159265358979323846)
//===============================================
#define SF(a) scanf("%d",&a)
#define SF2(a,b) scanf("%d %d",&a,&b)
#define SFLL(a) scanf("%lld",&a)
#define SFLL2(a,b) scanf("%lld %lld",&a,&b)
#define PF(a) printf("%d\n",a)
#define PFLL(a) printf("%lld\n",a)
//===============================================
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <vi> vvi;
typedef vector <vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<vpii> vvpii;
typedef stringstream ss;
const double EPS = 1e-4;
const ll oo = (ll) 10e4 + 7;
const ll N = 10000018;
const ll mod = 1000000007;
int dx[] = { 0, 0, -1, 1 };
int dy[] = { 1, -1, 0, 0 };
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1}; 8 direction
//freopen("largest.in", "r", stdin);
//freopen("output.txt", "w", stdout);
//ifstream ifs("input.txt");
//ofstream ofs("output.txt");



int main()
{
	afify();
	ll a;
	cin >> a;
	cout << a + (a*a) + (a*a*a) << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define maxn 150005
#define eps 1e-10
#define mp(x,y) make_pair(x,y)
#define se second
#define fi first
#define inf 50000000
using namespace std;
typedef long long int ll;
int n,m,v,p;
int a[100005];
ll sum[100005];
ll piao=0;
int main()
{
	scanf("%d%d%d%d",&n,&m,&v,&p);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)sum[i]=sum[i-1]+a[i];
	int ans=0,cnt=0;
	for(int i=1;i<=n;i++)
	{
		piao=(ll)m*v;
		int A=a[i]+m;
		int t2=upper_bound(a+1,a+n+1,A)-a-1;
		int t1=upper_bound(a+1,a+n+1,A-m)-a;
		
		cnt=n-t2;

		piao-=(ll)cnt*m+(ll)(t1-1)*m;
		if(piao<=0)
		{
			ans+=(cnt<p);
			continue;
		}
		
		
			int l=t1-1,r=t2,cnt2=l;
			while(l<=r)
			{
				int mid=(l+r)>>1;
				if((ll)A*(mid-t1+1)-(sum[mid]-sum[t1-1])+(ll)(t2-mid)*m<piao)
				{
					r=mid-1;
				}
				else cnt2=mid,l=mid+1;
			}
			cnt+=(t2-cnt2);
		
		if(cnt<p)ans++;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
typedef long long llint; 
const int Maxn = 100+10;

int n; llint W,v[Maxn],w[Maxn],F[Maxn][Maxn][Maxn*4];

void solve(){
	scanf("%d%lld",&n,&W);
	for(int i=1;i<=n;i++) scanf("%lld%lld",&w[i],&v[i]);
	for(int i=1;i<=n;i++){
		for(int j=0;j<=i;j++)
		  for(int k=0;k<=3*i;k++) F[i][j][k] = F[i-1][j][k];
		for(int j=1;j<=i;j++)
		  for(int k=w[i]-w[1];k<=3*i;k++) if((llint)j*w[1]+(llint)k <= W)
		    F[i][j][k] = max(F[i][j][k],F[i-1][j-1][k-(w[i]-w[1])]+v[i]);
	}
	llint ans = 0;
	for(int j=0;j<=n;j++)
	  for(int k=0;k<=3*n;k++) ans = max(ans,F[n][j][k]);
	printf("%lld\n",ans);
}

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

Measured memory_bytes: 37248
//yashverma

#include<bits/stdc++.h>
using namespace std;

#define rep(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define pb push_back
#define Pi 3.141592653589793
#define MOD 1000000007
// For i/o
#define sd1(a) scanf("%d",&a)
#define sd2(a,b) scanf("%d %d",&a,&b)
#define sd3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define sf scanf
#define pf printf
// For debugging
#define deb(a) printf("deb%d\n",a)

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

int main()
{
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int len = s.size();
	cout << s[0] << len-2 << s[len-1] << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
long long p = 1000000007;
long long n, k, x, ans;
long long a[2000];
int main() {
	scanf("%lld%lld", &n, &k);
	for (int i = 0; i < n; i++) {
		scanf("%lld", a + i);
	}
	for (int i = 0; i < n; i++) {
		x = 0;
		for (int j = i + 1; j < n; j++) {
			if (a[i] > a[j])x++;
		}
		ans += k * x;
		x = 0;
		for (int j = 0; j < n; j++) {
			if (a[i] > a[j])x++;
		}
		ans += x * ((k - 1) * k / 2 % p);
		ans %= p;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long
const int mod =1000000007;
const int INF = 1e18;
#define rep(i,a,n) for(int i=a;i<n;i++)
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a[6]={100,101,102,103,104,105};
    int M=0;
    for(int i=0;i<6;i++){
        for(int j=i+1;j<6;j++){
            M=max(a[i]*a[j]-a[i]-a[j],M);
        }
    }
    int n;
    cin>>n;
    if(n>M){cout<<1;return 0;}
    else{
        for(int i1=0;i1*100<=n;i1++){
            for(int i2=0;i1*100+i2*101<=n;i2++){
                for(int i3=0;i1*100+i2*101+i3*102<=n;i3++){
                    for(int i4=0;i1*100+i2*101+i3*102+i4*103<=n;i4++){
                        for(int i5=0;i1*100+i2*101+i3*102+i4*103+i5*104<=n;i5++){
                            int s=n-(i1*100+i2*101+i3*102+i4*103+i5*104);
                            if(s%105==0){cout<<1;return 0;}
                        }
                    }
                }
            }           
        }
    }
    cout<<0;return 0;
}


Measured memory_bytes: 256
//print test cases

#include<stdio.h>

int main(void)
{
    int i=0,a[10000]={0};
    
    do
    {
        scanf("%d",&a[i]);
    }
    while (a[i++]!=0);

    i=0;

    do
    {
        printf("Case %d: %d\n",i+1,a[i]);
        i++;
    }
    while(a[i]!=0);

    return 0;

}


Measured memory_bytes: 2044
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

/*

1 2 3
4 5 6
7 8 9
3
1
5
9

1 2 3
4 5 6
7 8 9
3
3
5
7


*/

fn main() {
    let A = read![[i64]; 3];
    let N = read!(usize);
    let b = read![i64; N];

    let B = b.into_iter().collect::<HashSet<_>>();

    let mut bingo = false;

    for y in 0..3 {
        bingo = bingo || (0..3).all(|x| B.contains(&A[y][x]));
    }
    for x in 0..3 {
        bingo = bingo || (0..3).all(|y| B.contains(&A[y][x]));
    }
    bingo =
        bingo || (0..3).all(|i| B.contains(&A[i][i])) || (0..3).all(|i| B.contains(&A[i][2 - i]));

    println!("{}", if bingo { "Yes" } else { "No" })
}


Measured memory_bytes: 4352
def Synthetic_Kadomatsu_dfs(l, depth, a, b, c, N, A, B, C):
    if depth == N: return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a,b,c) > 0 else float('INF')

    ret0 = Synthetic_Kadomatsu_dfs(l, depth+1, a, b, c, N, A, B, C)
    ret1 = Synthetic_Kadomatsu_dfs(l, depth + 1, a + l[depth], b, c, N, A, B, C)+10
    ret2 = Synthetic_Kadomatsu_dfs(l, depth + 1, a, b + l[depth], c, N, A, B, C)+10
    ret3 = Synthetic_Kadomatsu_dfs(l, depth + 1, a, b, c + l[depth], N, A, B, C)+10
    return min(ret0,ret1,ret2,ret3)

def Synthetic_Kadomatsu():
    N, A, B, C = map(int, input().split())
    l = [int(input()) for _ in range(N)]

    print(Synthetic_Kadomatsu_dfs(l, 0, 0, 0, 0, N, A, B, C))



if __name__ == "__main__":
    Synthetic_Kadomatsu()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
long long n,a,cnt=0;
vector<long long> v;
int main(){
	scanf("%lld",&n);
	for(int i=1;i<=3*n;i++){
		scanf("%lld",&a);
		v.push_back(-a);
	}
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();i++){
		v[i]=-v[i];
		//printf("%lld ",v[i]);
	}
	for(int i=1;i<=n;i++){
		cnt+=v[2*i-1];
	}
	printf("%lld",cnt);
}

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

#define rep(i,n) for(i=0;i<(n);i++)
#define For(i,a,b) for(i=(a);i<(b);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const double PI=acos(-1.0);

int main(){
	int i,j,k;
	int n;
	int c=0;
	int flag;
	vector<int> a;
	cin >> n;
	a.resize(n);
	rep(i,n) cin >> a[i];
	while(1){
		flag=0;
		rep(i,n){
			if(a[i]%2==1){
				flag=1;
				break;
			}
			a[i]/=2;
		}
		if(!flag) c++;
		else break;
	}

	cout << c << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void){
  int n;
  cin >> n;
  VL a(n);
  REP(i, 0, n) {
    cin >> a[i];
  }
  VL former, latter;
  for (int i = n - 1; i >= 0; i -= 2) {
    former.push_back(a[i]);
  }
  for (int i = n - 2; i >= 0; i -= 2) {
    latter.push_back(a[i]);
  }
  for (int i = latter.size() - 1; i >= 0; --i) {
    former.push_back(latter[i]);
  }
  REP(i, 0, former.size()) {
    cout << former[i] << (i == former.size() - 1 ? "\n": " ");
  }
}


Measured memory_bytes: 6256
import java.io.*;
import java.util.*;

public class Main {
    static BufferedReader in;

    public static void solve() throws IOException {
        Integer[] nm = nextArray(2);
        int n = nm[0];
        int m = nm[1];

        if(m != n){
            System.out.println("No");
        }
        else
            System.out.println("Yes");

    }

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        solve();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(in.readLine().trim());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(in.readLine().trim());
    }

    static Integer[] nextArray(int n) throws IOException {
        StringTokenizer st = new StringTokenizer(in.readLine());
        Integer[] tmp = new Integer[n];
        for (int i = 0; i < tmp.length; i++) {
            tmp[i] = Integer.parseInt(st.nextToken());
        }

        return tmp;
    }

}



Measured memory_bytes: 23380
/* When Talent doesn't work, Hard work beats Talent*/

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include"bits/stdc++.h"

using namespace std;

#define Fast_D cout<<fixed<<setprecision(13);
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define nl "\n"
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define scanstr(s) cin>>ws; getline(cin,s);

const double PI = 3.141592653589793;

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

int32_t main()
{
	FastIO;
	Fast_D;
	int T;
	T=1;
	while(T--) solve();
	return 0;
}



Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 1; i <= (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define inf 2147483647 //int値の最大値
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素
#define CST(x) cout<<fixed<<setprecision(x)//小数点以下の桁数指定
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int two(int n){
	ll ans=1;
	rep(i,n){
		ans*=2;
	}
	return ans;
}
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

    int n;
    cin>>n;
    vector<ll>l(n+6);
    rep(i,n)cin>>l.at(i);
    int sum=0;

rep(i,n){
    FOR(j,i+1,n){
        FOR(k,j+1,n){
            ll len =(l.at(i)+l.at(j))+l.at(k);
            ll ma =max(l.at(i),max(l.at(j),l.at(k)));
            ll rest =len-ma;

            if(ma<rest && l.at(i) !=l.at(j) && l.at(i) !=l.at(k) && l.at(k) !=l.at(j))sum++;
        }
    }
}
cout<<sum<<endl;
}

Measured memory_bytes: 3640
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);

  int n,y;

  cin >> n >> y;

  vec ans(3,0);

  REP(i,n + 1){
    ans[0] = i;
    REP(j,n + 1){
      ans[1] = j;
      ans[2] = n - i - j;
      if(ans[2] >= 0 && y == ans[0] * 10000 + ans[1] * 5000 + ans[2] * 1000){
        cout << ans[0] SP ans[1] SP ans[2] << endl;
        return 0;
      }
    }
  }

  cout << "-1 -1 -1" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <ctime>
#include <string>
#include <map>
#include <stack>
#include <queue>

using namespace std;

int w, h;
const int MAX = 50;
int c[MAX][MAX];


void check(int x, int y){
	c[x][y] = 0;
    for(int dx = -1; dx <= 1; dx++){
        for(int dy = -1; dy <= 1; dy++){
            if(x + dx >= 0 && x + dx < h  && y + dy >= 0 && y + dy < w && c[x + dx][y + dy] == 1){
            	check(x + dx, y + dy);
            } 
        }
    }
	
}

int main(void){

	for(int i = 0; i < MAX ; i++){
		for(int j = 0; j < MAX; j++){
			c[i][j] = 0;
		}
	}

	cin >> w >> h;
	while(w != 0 && h != 0){
		int ans = 0;
		for(int i = 0; i < h ; i++){
			for(int j = 0; j < w; j++){
				cin >> c[i][j];
			}
		}

		for(int i = 0; i < h ; i++){
			for(int j = 0; j < w; j++){
				if(c[i][j] == 1){
					check(i, j);
					ans++;
				}
			}
		}
		cout << ans << endl;

		cin >> w >> h;
	}
	
    return 0;
}

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

string s1, s2;

int main( void ) {
    
    int n;
    cin >> n >> s1 >> s2;
    
    for( int i = n; i >= 0; i -- ) {
        bool ok = true;
        
        for( int j = n - i, k = 0; j < n; j ++, k ++ )
            ok &= ( s1[j] == s2[k] );
    
        if( ok == true ) {
            cout << n * 2 - i << endl;
            break;
        }
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{ int a[10],i,j,k,t;
  for(i=0;i<10;i++)	
	scanf("%d",&a[i]);
  for(i=0;i<3;i++)
  { k=i;
  for(j=i+1;j<10;j++)
  if(a[j]>a[k])k=j;
  if(k!=i)
  {t=a[i];a[i]=a[k];a[k]=t;
  }
  }
  for(i=0;i<3;i++)
  printf("%d\n",a[i]);	
  return 0;
}

Measured memory_bytes: 600
def print_remain(sec):
    print "{:02}:{:02}:{:02}".format(sec/60**2,sec%60**2/60,sec%60)
while True:
    h,m,s=map(int,raw_input().split())
    if (h,m,s)==(-1,-1,-1):
        break
    sec=h*60**2+m*60+s
    print_remain(2*60**2-sec)
    print_remain((2*60**2-sec)*3)

Measured memory_bytes: 4228
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
using namespace std;

int main() {
	int N;
	int A[210];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		
	}
	int res = 0;
	while (true) 
	{
		bool exist_odd = false;

		for (int i = 0; i < N; i++) 
		{
			if (A[i] % 2 != 0) exist_odd = true;
		}

		if (exist_odd) break;

		for (int i = 0; i < N; i++)
		{
			A[i] /= 2;
		}
		res++;
	}
	cout << res << endl;
}

Measured memory_bytes: 256