akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define revrep(i, n) for(ll i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
/*
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll max3(ll a, ll b, ll c){return max(a, max(b, c));};
ll min3(ll a, ll b, ll c){return min(a, min(b, c));};
ll max4(ll a, ll b, ll c, ll d){return max(max(a, b), min(c, d));};
ll min4(ll a, ll b, ll c, ll d){return min(min(a, b), min(c, d));};
ll max5(ll a, ll b, ll c, ll d, ll e){return max(max(a, b), max3(c, d, e));};
ll min5(ll a, ll b, ll c, ll d, ll e){return min(min(a, b), min3(c, d, e));};
*/
const ll INFL = 1LL << 60;//10^18 = 2^60
const int INF = 1 << 30;//10^9
//ll MOD = 1000000007;
ll MOD = 998244353;

vector<ll> dy = {0, 0, 1, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, -1, 0, 0, 1, -1, 1, -1, 0};


ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x;
    k /= 2;
  }
  return res;
}
ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){return x / gcd(x, y) * y;};

ll kai_mod(ll x){
  if(x == 0) return 1;
  return x * kai_mod(x-1) % MOD;
}

/*
//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}
*/

ll N, M;
vector<P> A;
set<P> tmp, par, rest;

bool solve(){
  rep(i, M) rest.insert(A[i]);
  rest.insert({INFL, N});
  sort(A.begin(), A.end());
  par.insert(A[0]);
  rest.erase(A[0]);

  rep(t, N){
    for(auto itr = par.begin(); itr != par.end(); itr++){
      P x = *itr;
      auto itr2 = rest.lower_bound({x.f, INFL});
      P y = *itr2;
      if(y.f == INFL) return 0;
      tmp.insert(y);
      rest.erase(y);
    }

    for(auto itr = tmp.begin(); itr != tmp.end(); itr++){
      par.insert(*itr);
    }
    tmp.clear();
  }
  return 1;
}

int main(){
  cin >> N;
  M = pow(2, N);
  A.resize(M);
  rep(i, M){
    cin >> A[i].f;
    A[i].f *= -1;
    A[i].s = i;
  }

  if(solve()){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 28928
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//while(N)で回すとき、Nはコピーを作っておく
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//等価なものに変換する思考
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//配列はvector<>を使う：意味わからないエラーがなくなる。
//背反な事象にちゃんとわける
//チェックリストはマップを使う
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//またはかかつか
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//数が大きい時のせぐふぉはコードテストで試してみる
//スペルミスに注意
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll M = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}


//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//nC2の計算
ll C(ll N) {
	return N * (N - 1) / 2;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1)) % M;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

//ABC158のE見る
int main() {
	ll N, K; cin >> N >> K;
	vector<ll> A(N); rep(i, N)cin >> A[i];

	vector<ll> s(N);
	for (ll i = 0; i < N; i++) {
		for (ll j = i + 1; j < N; j++) {
			if (A[i] > A[j]) s[i]++;
		}
	}

	ll ans = 0;
	rep(i, N) {
		ans += s[i];
		ans %= M;
	}
	ans *= K;
	ans %= M;

	vector<ll> rank(N);
	for (ll i = 0; i < N; i++) {
		for (ll j = 0; j < N;j++) {
			if (A[i] > A[j]) rank[i]++;
		}
	}

	ll sum = 0;
	rep(i, N) {
		sum += rank[i];
		sum %= M;
	}
	ll x = ((K*(K - 1) / 2) % M);
	sum *= x;
	sum %= M;

	cout << (ans + sum)%M << endl;
}

Measured memory_bytes: 8064
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <map>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
typedef long long ll;
typedef map<int,int> mint;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int inf=1e9+1000;
ll infi=1e18+100;

int A,B,X;
 
int main(){
	cin>>A>>B>>X;
	if(X>=A && X<=A+B) cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> x(m);
    for(int i=0; i<m; ++i)
        cin >> x[i];
    sort(x.begin(), x.end());
 
    vector<int> v(m-1);
    for(int i=0; i<m-1; ++i)
        v[i] = x[i+1] - x[i];
    sort(v.begin(), v.end());
 
    long long ans = 0;
    for(int i=0; i<m-n; ++i)
        ans += v[i];
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

string s[15];

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    rep(i, h) cin >> s[i];



    int ans = INF;

    for (int bits = 0; bits < (1<<(h-1)); bits++){
        vector<vector<int>> parts;
        parts.push_back({0});
        rep(i, h - 1){
            if(bits & (1<<i)) parts.push_back({i + 1});
            else parts.back().push_back(i + 1);
        }
        int val = __builtin_popcount(bits);

        int n = parts.size();
        int num[n] = {};

        rep(j, w){
            int now[n] = {};
            rep(i, n){
                for (auto tmp : parts[i]){
                    if (s[tmp][j] == '1') now[i]++;
                    if(now[i] > k){
                        val = INF;
                        j = w;
                        break;
                    }
                }
            }

            bool cut = false;
            if (val == INF) break;
            rep(i, n){
                num[i] += now[i];
                if (num[i] > k) cut = true;
            }

            if (cut){
                val++;
                rep(i, n) num[i] = 0;
                j--;
            }
        }
        ans = min(ans, val);
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		int n = sc.nextInt();
		int[] p = new int[n];
		for (int i = 0; i < n; i++	) {
			p[i] = sc.nextInt();
		}
		int ans = 0;
		for (int i = 1; i < n-1; i++) {
			if (p[i-1] == p[i+1]) {
				if (p[i-1] > p[i]) {
					ans++;
				}
			} else if (p[i-1] == p[i]) {
				if (p[i] < p[i+1]) {
					ans++;
				}
			} else if (p[i+1] == p[i]) {
				if (p[i] < p[i-1]) {
					ans++;
				}
			} else if (p[i-1] == p[i] && p[i] == p[i+1]) {
				continue;
			} else {
				int[] temp = {p[i-1],p[i],p[i+1]};
				Arrays.sort(temp);
				if (temp[1] == p[i]) {
					ans++;
				}
			}
		}
		System.out.println(ans);
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 21204
#include <iostream>
#include <string>
#include <unordered_map>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;

#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define y1 abcde
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
#define int long long

const ll inf = 2e15;
const int N = 2e3 + 15;
const int L = 15;
int n, x, a[N], ans = inf, LG[N], st[L][N];

inline void build() {
    for(int i = 2; i < N; ++i)
        LG[i] = LG[i >> 1] + 1;
    for(int i = 1; i <= n; ++i)
        st[0][i] = a[i];
    for(int j = 1; j < L; ++j)
        for(int i = 1; i <= n; ++i)
            st[j][i] = min(st[j-1][i], st[j-1][min(n, i + (1 << (j - 1)))]);
}

inline int get(int l, int r) {
    int lg = LG[r - l + 1];
    return min(st[lg][l], st[lg][r - (1 << lg) + 1]);
}

main() {
    cin >> n >> x;
    for(int i = 1; i <= n; ++i)
        cin >> a[i];
    reverse(a + 1, a + 1 + n);
    build();
    for(int shift = 0; shift < n; ++shift) {
        int cur = 0;
        for(int i = 1; i <= n; ++i) {
            int ind = i + shift;
            if(ind > n)
                cur += min(get(i, min(n, ind)), get(1, ind - n));
            else
                cur += get(i, min(n, ind));
        }
        cur += shift * x;
        ans = min(ans, cur);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
from functools import *
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline


def array(size,init=0):
    return [[init for j in range(size[1])] for i in range(size[0])]



def acinput():
    return list(map(int, input().split(" ")))


def II():
    return int(input())


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact


def permutate(x,A):
    n=len(x)
    res=[-1]*n
    for i in range(n):

        res[i]=x[A[i]]
    return res


def generate_bin(digit):
    for b in range(2**digit):
        b=bin(b)
        tmp=b[2:].zfill(digit)
        yield list(map(int,tmp))
        #b=list(map(int,list(b[2:].zfill(digit))))
        #yield b
        

def search(x, count):
    #print("top", x, count)
            

    for d in directions:
        nx = d+x
        #print(nx)
        if np.all(0 <= nx) and np.all(nx < (H, W)):
            if field[nx[0]][nx[1]] == "E":
                count += 1 
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)  
                continue
            if field[nx[0]][nx[1]] == "#":
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)    
                 
    return count

N=int(input())
A=acinput()


M=max(A)
m=[0]*(M+1)
for i in range(N):
    
    x=A[i]
    m[x]+=1
    
    k=2
    while True:
        if x*k<=M:
            m[x*k]+=1
        
            k+=1
        else:
            break


res=0
for a in A:
    if m[a]==1:
        res+=1

        
print(res)
        
        
#print(m)

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

int main(){
    int N,K;
    cin >> N >> K;
    int h[N];
    for(int i=0;i<N;i++){
        cin >> h[i];
    }
    sort(h,h+N);
    int d_min=1000000000;
    for(int i=0;i<=N-K;i++){
        int diff = h[i+K-1] - h[i];
        if (diff < d_min) d_min = diff;
    }
    cout << d_min << endl;
}

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

const int64_t mod = 1000000007;

int main() {
  int64_t n, k, ans = 0;
  cin >> n >> k;
  for (int64_t i = k; i <= n + 1; i++) {
    ans += (n + 1 - i) * i % mod;
    ans++;
    ans %= mod;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3592
n, s = map(int, input().split())
a = list(map(int, input().split()))
MOD = 998244353

dp = [0] * (3000 + 1)
dp[0] = 1
ans = 0
for i in range(n):
    for w in range(3000 + 1)[::-1]:
        # 選ぶとき
        if w - a[i] > 0:
            dp[w] += dp[w - a[i]]
        if w - a[i] == 0:
            dp[w] += dp[w - a[i]] * (i + 1)
        dp[w] %= MOD
    ans += dp[s]
    ans %= MOD
print(ans % MOD)

Measured memory_bytes: 44012
#include<stdio.h>
int main() {
	int a,n,k,i,j;
	int coin[21],x[50001]={0};
	scanf("%d%d",&n,&k);
	for(i=0;i<k;i++)scanf("%d",&coin[i]);
	for(i=0;i<=n;i++){
		for(j=0;j<k;j++){
			if(i+coin[j]<=n){
				a=x[i]+1;
				if(x[i+coin[j]]==0)x[i+coin[j]]=a;
				else if(a<x[i+coin[j]])x[i+coin[j]]=a;
			}
		}
	}
	printf("%d\n",x[n]);
	return 0;
}


Measured memory_bytes: 2136
#include <stdio.h>

int main(void)
{

    int n = 1;
    int m, f, r, a, j;
    char *b[128];
    int i = 0;

    while (n) {
        scanf("%d %d %d", &m, &f, &r);
        if(m == -1 && f == -1 && r == -1)
            break;
        a = m + f;
        if(m == -1 || f == -1)
            b[i] = "F";
        else if(a >= 80)
            b[i] = "A";
        else if(a >= 65 && a < 80)
            b[i] = "B";
        else if(a >= 50 && a < 65)
            b[i] = "C";
        else if(a >= 30 && a < 50) {
            if(r >= 50)
                b[i] = "C";
            else
                b[i] = "D";
        }
        else if(a < 30)
            b[i] = "F";
        i++;
    }

    for(j = 0; j < i; j++)
        printf("%s\n", b[j]);

    return 0;
}

Measured memory_bytes: 584
#include<list>
#include<cstdio>
#include<iostream>
#include<algorithm>


using namespace std;
int main(){
//	freopen("1 .in","r",stdin);
	list<int> l;
	list<int>::iterator it;
	it=l.end(); 
//	for(it=l.begin();it!=l.end();it++) printf("%d ",*it);cout<<"\n";
	int Q;
	scanf("%d",&Q);
//	cout<<Q;
	while(Q--){
		int q,x;
		scanf("%d",&q);
		if(q==0){
			scanf("%d",&x);
			it=l.insert(it,x);
//			for(it=l.begin();it!=l.end();it++) printf("%d ",*it);cout<<"\n";
		}
		else if(q==1){
			scanf("%d",&x);
			if(x>0) while(x--) it++;
			else{
				x=-x;
				while(x--) it--;
			}
//			for(it=l.begin();it!=l.end();it++) printf("%d ",*it);cout<<"\n";
		}
		else{
			it=l.erase(it);
//			for(it=l.begin();it!=l.end();it++) printf("%d ",*it);cout<<"\n";
		} 
	}
	for(it=l.begin();it!=l.end();it++) printf("%d\n",*it);
	return 0;
}


Measured memory_bytes: 18752
#include<iostream>
 #include<stdio.h>
 #include<cstdlib>
 #include<cstdio>
 #include<string>
 #include<math.h>
 #include<time.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<fstream> 
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 #include<deque>
 #include<functional>
 #include<utility>
 #include<list>
 #include<memory>
 
 using namespace std;
 
 int main()
 {
   long long int n;
   int arr[100000+5];
   while(cin>>n)
   {
     for(int i=0;i<n;i++) cin>>arr[i];
     sort(arr,arr+n);
     int cnt=1;
     long long square;
     for(int i=n-2;i>=0;i--)
     {
       if(arr[i]-arr[i+1]==0) cnt++;
       if(cnt==4)
       {
         square=arr[i]*arr[i];
         break;          
       }      
     } 
     cnt=1;
     int cnt2=0;
     long long int w,h;
     w=0;
     h=0;
     long long rec;
     for(int i=n-2;i>=0;i--)
     {
       if(arr[i]-arr[i+1]==0) cnt++;
       if(cnt==2) 
       {
         if(cnt2==0) w=arr[i];
         else if(cnt2==1) h=arr[i];
         i--;
         cnt=1;      
         cnt2++;       
         if(cnt2==2)  break;
       }       
       if(cnt2==2) break;
     }
     rec=w*h;
     cout<<max(square,rec)<<endl;
   }
   //while(1);
   return 0;
 }
 

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define SLAY ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PI 3.141592653589793238
#define ll long long
#define pii pair<int , int>
#define pll pair<long long , long long>
#define INPUT freopen("travel_restrictions_validation_input.txt", "r", stdin);
using namespace std;
int dx[] = { 0 , 0 , 1 , -1};
int dy[] = { 1 , -1 , 0 , 0};
int getmod(int x, int y , int mod ){return (((x - y)%mod)+mod)%mod;}
int main(){SLAY
	int _=1 , tc=1;
	// cin>>_;
	while(_--){
		ll n,c,m,ans=0;
		cin>>n>>m>>c;
		vector<ll>a(n+1);
		vector<ll>prea(n+1);
		vector<ll>b(m+1);
		vector<ll>preb(m+1);
		for(int i = 1 ; i <= n ; i ++){
			cin>>a[i];
			prea[i]+= a[i]+prea[i-1];
		}
		for(int i = 1 ; i <= m ; i ++){
			cin>>b[i];
			preb[i]+= b[i]+preb[i-1];
		}
		
		for(int i = 1 ; i <= n ; i++ ){
			ll pay = prea[i];
			if(pay>c)break;
			if(pay==c)ans=max(ans , (ll)i);
			ll rem = c-pay;
			
			int start = 0 , end = m+1 , pos=-1;
			while(start<end){
				int mid = start+(end-start)/2;
				if(preb[mid]<=rem){
					pos = mid;
					start=mid+1;
				}else{
					end = mid;
				}
			}
			ans = max(ans , (ll)i+pos);
		}
		
		for(int i = 1 ; i <= m ; i++ ){
			ll pay = preb[i];
			if(pay>c)break;
			if(pay==c)ans=max(ans , (ll)i);
			ll rem = c-pay;
			
			int start = 0 , end = n+1 , pos=-1;
			while(start<end){
				int mid = start+(end-start)/2;
				if(prea[mid]<=rem){
					pos = mid;
					start=mid+1;
				}else{
					end = mid;
				}
			}
			ans = max(ans , (ll)i+pos);
			
		}
		cout<<ans;
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 9552
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int n,m,s,t;
int d[100001][3];
const int INF=0x3f3f3f3f;
vector<int> v[100001];
void bfs(int st){
    memset(d,0x3f,sizeof(d));
    d[st][0]=0;
    queue<int> q;q.push(st*10);
    while(!q.empty()){
        int pp=q.front();q.pop();
        int pos=pp%10,tv=pp/10;
        rep(i,v[tv].size()){
            int nv=v[tv][i],np=(pos+1)%3;
            if(d[nv][np]!=INF) continue;
            d[nv][np]=d[tv][pos]+1;
            q.push(nv*10+np); 
        }
    }
}
int main(){
    cin>>n>>m;
    int ui,vi;
    rep(i,m){
        cin>>ui>>vi;
        --ui,--vi;
        v[ui].pb(vi);
    }
    cin>>s>>t;--s;--t;
    bfs(s);
    if(d[t][0]==INF) cout<<-1<<endl;
    else cout<<d[t][0]/3<<endl;
    return 0;
}


Measured memory_bytes: 7036
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> l_l;
typedef pair<int,int> i_i;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  int n,l;
  cin >> n >> l;
  vector<int> a(n);
  rep(i,n) a[i]=l+i;
  int ans=0;
  rep(i,n) ans+=a[i];
  if(a[0]>0){
    ans-=a[0];
  }
  else if(a[n-1]<0){
    ans-=a[n-1];
  }
  cout << ans << endl;
}

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

using namespace std;

long long a, v, b, w, t;

int main() {

	scanf("%lld %lld %lld %lld %lld", &a, &v, &b, &w, &t);

	long long d = llabs(a - b);

	if (v * t - w * t >= d) {
		puts("YES");
	} else {
		puts("NO");
	}

	return 0;

}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const int vx[]={1,0,-1,0}, vy[]={0,1,0,-1};
const int sqrtN = 512;
const int logN = 32;
const ll LINF=1e18;
const ld PI=abs(acos(-1));

ll li[200010], li2[200010], a[200010];

int main(){
	int n; cin >> n;
	REP(i, 0, n) cin >> a[i];
	
	stack<P> st;
	REP(i, 0, n){
		while(!st.empty() and st.top().second > a[i]){
			li2[st.top().first] = i - st.top().first;
			st.pop();
		}
		
		if(!st.empty()) li[i] = i - st.top().first;
		else li[i] = i + 1;
		st.push({i, a[i]});
	}
	
	while(!st.empty()){
		li2[st.top().first] = n - st.top().first;
		st.pop();
	}
	
	ll pos = 0;
	REP(i, 0, n) pos += a[i] * li[i] * li2[i];
	cout << pos << endl;
	return 0;
}


Measured memory_bytes: 6144
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(intl i=0;i<(intl)(n);i++)
#define Rep1(i,n) for(intl i=1;i<(intl)(n)+1;i++)
#define vec vector
#define fi first
#define se second
#define SortA(v) sort(v.begin(), v.end())
#define SortD(v) sort(v.rbegin(), v.rend())
#define All(a) (a).begin(),(a).end()
using intl = int64_t;
using vi = vec<intl>;
using vvi = vec<vi>;
vec<intl> dx = {0, 1, 0, -1, 1, 1, -1, -1};
vec<intl> dy = {1, 0, -1, 0, 1, -1, 1, -1};


int main(){
  int N;
  cin >> N;
  int ans=0;
  Rep1(i,N){
    int cnt =0;
    if (i % 2==0)continue;
    Rep1(j,i){
      if (i%j==0) cnt ++;
    }
    if (cnt ==8) ans++;
  }
  
  cout <<ans;
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define REP(i,n) for(int i=0;i<(n);++i)
#define PER(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define PII pair<int,int>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define PAIR pair<double, double>
#define ALL(x) (x).begin(),(x).end()
#define BIT(x) (1LL << (x))
#define PI acos(-1)
const LL MOD = (LL)1e9+7;
const LL INF = (LL)1e9+7;
const LL INFLL = (LL)1e18;
using namespace std;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

LL modpow(LL x, LL b){
	LL res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

LL modinv(LL x){
	return modpow(x, MOD-2);
}

int main(){
	int n;
	int k;
	int q;
	cin >> n >> k >> q;
	vector<int> point(n+1, k-q);
	REP(i, q){
		int d;
		cin >> d;
		++point[d];
	}
	REPA(i, n+1){
		cout << (point[i]>0?"Yes":"No") << endl;
	}
	return 0;

}


Measured memory_bytes: 1024
#include<stdio.h>
int ke(int a){
  int b = a % 10;
  int c = a / 10;
  return b * 10 + c;
}

int main(){
  int a,b,ans = 0;
  scanf("%d %d",&a,&b);
  for(int i = a;i <= b;i++){
    if(ke(i / 1000) == i % 100){
      ans++;
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn=1e5+9;
LL c,ans=0,n;
LL x[maxn],v[maxn];
struct node{
	LL CW,AC,CW_back,AC_back;
}f[maxn];
LL read(){
	LL x=0;bool f=0;char c=getchar();
	while (c<'0'||c>'9'){if (c=='-') f=1;c=getchar();}
	while (c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
	return f?-x:x;
}
int main(){
	n=read(),c=read();
	for (int i=1;i<=n;++i) x[i]=read(),v[i]=read();
	f[1].AC=v[1]-x[1];f[1].AC_back=f[1].AC-x[1];
	for (int i=2;i<=n;++i) f[i].AC=f[i-1].AC+v[i]-(x[i]-x[i-1]),f[i].AC_back=f[i].AC-x[i];
	for (int i=2;i<=n;++i) f[i].AC=max(f[i-1].AC,f[i].AC),f[i].AC_back=max(f[i-1].AC_back,f[i].AC_back);
	f[n].CW=v[n]-(c-x[n]);f[n].CW_back=f[n].CW-(c-x[n]);
	for (int i=n-1;i>=1;--i) f[i].CW=f[i+1].CW+v[i]-(x[i+1]-x[i]),f[i].CW_back=f[i].CW-(c-x[i]);
	for (int i=n-1;i>=1;--i) f[i].CW=max(f[i+1].CW,f[i].CW),f[i].CW_back=max(f[i+1].CW_back,f[i].CW_back);
	ans=max(ans,max(f[n].AC,f[1].CW));
	for (int i=1;i<n;++i){
		ans=max(ans,f[i].AC_back+f[i+1].CW);
		ans=max(ans,f[i].AC+f[i+1].CW_back);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll Nmax=1e9;
const ll INF=1e9;


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

  double ans=0;

  rep1(i,n){//



    int x=0;
    int temp=i;
    double p=1;

    while(temp<k){
      x++;
      temp *=2;
      p *=double(0.5);
    }
    ans+= p;

  }

  ans /=double(n);
  printf("%.10lf",ans);




}


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

using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
const ll mod = 1e9 + 7;
const int INF = 1e9;

int main() {
	cin.sync_with_stdio(false);
	int N, A;
	cin >> N >> A;
	cout << N*N - A << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
const double PI = acos(-1);
int main(){
    int a,b;cin>>a;
    int ans =a%1000;
    if(ans==0){
        cout<<0<<endl;
        return 0;
    }
    ans = 1000-ans;
    cout<<ans<<endl;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> R(n);
    for(int i = 0; i < n; i++) {
        cin >> R.at(i);
    }
    int maxv = -2000000000;
    int minv = R.at(0);
    for(int i = 1; i < n; i++) {
        maxv = max(maxv, R.at(i) - minv);
        minv = min(minv, R.at(i));
    }

    cout << maxv << endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define vi vector<int>

int main(void){
  int n,k,in,m=-1;
  cin>>n>>k;
  vi a(100);
  rep(i,k){
    cin>>in;
    a[--in]++;
    m = max(m,in);
  }
//  cout<<m+1<<endl;
  int s = m+1;
  if(a[m]>=2){
    cout<<0<<endl;
    return 0;
  }
  rep(i,100)if(i != s-1&&a[i]){
    m -= (i+1) * a[i];
//    cout<<a[i]<<" "<<i+1<<endl;
  }
  cout<<(m>=0?m:0)<<endl;
}

Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
using namespace std;

int inf = 2147483647;
int64_t inf64 = 9223372036854775807;
int MOD = 1e+7;

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

  int n, m;
  cin >> n >> m;
  vector<bool> ac(n);
  vector<int> wa(n);
  rep(i,m) {
    int p;
    string s;
    cin >> p >> s;
    p--;
    if (ac[p]) continue;
    if (s == "AC") ac[p] = true;
    else wa[p]++;
  }

  int AC = 0, WA = 0;
  rep(i,n) {
    if(ac[i]) {
      AC++;
      WA += wa[i];
    }
  }

  cout << AC << " " << WA << endl;
  return 0;
}

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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  
  string s;
  int sum = 0;
  int ans = 0;
  for(int i=1; i<=n; i++) {
    s = to_string(i);
    for(int j=0; j<s.size(); j++) {
      sum += s[j]-'0';
      if(j==s.size()-1 && a<=sum && sum<=b) ans += i;
    }
    sum = 0;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3672
from collections import deque
import numpy as np

H,W = map(int,input().split())
maze = [input() for _ in range(H)]#迷路の入力

ans = 0
for x in range(H):#すべてのマスからスタート
    for y in range(W):
        #壁からはスタートできない：スルー
        if maze[x][y] == "#":
            continue

        #初期化：0埋め、HとWの順番に注意
        distance = [[0]*W for _ in range(H)]
        #start位置
        stack = deque([[x,y]])#デキューに入れる

        while stack:#スタックが有るあいだ
            h,w = stack.popleft()#スタックの先頭を取ってくる
            for i,j in [[1,0],[-1,0],[0,1],[0,-1]]:#マスの四方
                new_h, new_w = h+i, w+j#新しいマス
                if new_h < 0 or new_w < 0 or new_h >= H or new_w >= W:
                    continue#範囲外ならスルー
                elif maze[new_h][new_w] != "#" and distance[new_h][new_w] == 0:
                    distance[new_h][new_w] = distance[h][w]+1#BFS、+1
                    stack.append([new_h, new_w])#新しいマスをスタックへ

        #start位置は0で初期化
        distance[x][y] = 0
        ans = max(ans, np.max(distance))#npは二次元のmax取れる

print(ans)

Measured memory_bytes: 14484
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define debug(x) cout << #x << " = " << (x) << endl;
#define pb push_back
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000000000
#define EPS 0.00000000001
typedef long long ll;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    //---------------------------------------------

    string s;
    cin >> s;
    int n = s.size();
    if (n == 1)
    {
        cout << 1 << endl;
    }
    else if (n == 2)
    {
        if (s[0] == s[1])
        {
            cout << 1 << endl;
        }
        else
        {
            cout << 2 << endl;
        }
    }
    else
    {
        int cnt = 0;
        for (int i = 0; i < n ; i++)
        {
            if (i >= n - 2)
            {
                if (i == n - 2)
                {
                    if (s[n - 2] == s[n - 1])
                    {
                        cnt++;
                    }
                    else
                    {
                        cnt += 2;
                    }
                }
                else
                {
                    cnt++;
                }
                break;
            }

            if (s[i] == s[i + 1])
            {
                cnt += 2;
                i += 2;
            }
            else if (s[i] != s[i + 1])
            {
                cnt++;
            }
        }
        cout << cnt << endl;
    }
}


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

int main() {
    int n;
    scanf("%d", &n);
    int p;
    int ans = 0, max = 0;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &p);
        max = std::max(max, p);
        ans += p;
    }
    printf("%d", (ans - max/2));
    return 0;
}

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

#define int long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define all(c) (c).begin(),(c).end()
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;
const ld PI = acos(-1.0);

int32_t main(){
	fast;
	int n;
	cin >> n;
	
	string s;
	cin >> s;
	
	int cur = 0 , ans= 0;
	for(auto x : s)
	{
		if(x == 'D')
			cur--;
		else
			cur++;
		ans = max(ans, cur);
	}
	cout << ans;
}



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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll a, b, c;
    cin >> a >> b >> c;
    ll sum = a + b + c;
    if (sum >= 22) {
        cout << "bust" << endl;
    } else {
        cout << "win" << endl;
    }
    return 0;
}



Measured memory_bytes: 256
n, x, y = map(int, input().split())
dists = [0 for i in range(n+1)]

for i in range(1, n+1):
  for j in range(i+1, n+1):
    dist = min(abs(j-i), 1 + abs(x-i)+abs(y-j), 1 + abs(y-i)+abs(x-j))
    dists[dist]+=1
    
for i in range(1, n):
  print(dists[i])

Measured memory_bytes: 47964
#include<stdio.h>
int main(void){
    int h,w;
    while(1){
        scanf("%d %d",&h,&w);
        if (h==0 &&w==0)break;
        for (int i = 0; i < h; i++)
        {
            for (int k = 0; k < w; k++)
            {
                printf("#");
            }
            printf("\n");
        }
        printf("\n");        
    }
    
    return 0;
}


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

int main() {
    int n;
    int64_t k;
    cin >> n >> k;
    vector<vector<int>> to(62, vector<int>(n));
    for(int i = 0; i < n; ++i) {
        cin >> to[0][i];
        to[0][i]--;
    }
    for(int x = 0; x < 61; ++x) {
        for(int i = 0; i < n; ++i) to[x + 1][i] = to[x][to[x][i]];
    }
    int now = 0;
    while(k) {
        for(int i = 0; i < 62; ++i) {
            if(k & (1LL << i)) {
                now = to[i][now];
                k ^= (1LL << i);
            }
        }
    }
    cout << now + 1 << '\n';
    return 0;
}


Measured memory_bytes: 52636
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		solver();
	}

	void solver() {
		Scanner sc = new Scanner(System.in);
		char[] c = sc.next().toCharArray();
		int[] s = new int[c.length];
		for (int i = 0; i < c.length; i++) {
			s[i] = c[i] - 'a';
		}
		int MOD = 26;
		int K = sc.nextInt();
		for (int i = 0; i < s.length; i++) {
			if (MOD - s[i] <= K && s[i] != 0) {
				K -= MOD - s[i];
				s[i] = 0;
			}
		}
		s[s.length - 1] = (s[s.length - 1] + K) % MOD;
		char[] ref = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
				't', 'u', 'v', 'w', 'x', 'y', 'z' };
		for (int i = 0; i < s.length; i++) {
			System.out.print(ref[s[i]]);
		}
		System.out.println();
	}
}


Measured memory_bytes: 24276
#include <iostream>
using namespace std;
// sum(l) -sum(r) + n を出力する

int main(){
  int n;
  cin >> n;
  int ans = 0;
  for ( int i = 0; i < n;i++){
      int r,l;
      cin >> r >> l;
      ans = ans + l -r +1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import math
while True:
	n = input()
	if n==0:break
	s = map(int,raw_input().split(" "))
	m = 0.0
	for i in range(0,n):
		m += s[i]
	a = 0.0
	for i in range(0,n):
		a += (s[i]-m/n)**2
	a = math.sqrt(a/n)
	print a

Measured memory_bytes: 4448
MOD = 2019

l, r = map(int, input().split())

ans = 2019
if l // MOD != r // MOD:
    ans = 0
else:
    lmod = l % MOD
    rmod = r % MOD
    for i in range(lmod, rmod + 1):
        for j in range(i + 1, rmod + 1):
            ans = min(ans, (i * j) % MOD)
print(ans)

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

int n;
int A[25];
int B[25];
int C[25];


int main() {
	int fll = 0;
	cin >> n;
	for (int i = 1;i <= n;i++) {
		cin >> A[i];
	}
	for (int i = 1;i <= n;i++) {
		cin >> B[i];
	}
	for (int i = 1;i <= n-1;i++) {
		cin >> C[i];
	}

	int rmd = -50;
	for (int i = 1;i <= n;i++) {
		fll += B[A[i]];
		if (A[i] == rmd + 1) { fll += C[rmd]; }
		rmd = A[i];
	}

	cout << fll << "\n";

	return 0;
}

Measured memory_bytes: 384
/*
Problem :
Algorithm :
Status :
*/
#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#define DEBUG printf("Passing Line %d in Function [%s].\n",__LINE__,__FUNCTION__);
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int INF = 0x3f3f3f3f;
const int MAXN = 6377292 + 5;
const int BASE = 3;

int n,m;
int bin[MAXN],ans[MAXN];
char s[MAXN];

namespace Trie{
    int tot = 1;
    int trie[MAXN][3],val[MAXN],tag[MAXN];

    void Build(int k,int dep,int num){
        if(dep == n){
            val[k] = num;
            return;
        }
        for(int i = 0;i < BASE;i++){
            trie[k][i] = ++tot;
            Build(trie[k][i],dep + 1,num + i * bin[dep]);
        }
    }

    void down(int k){
        if(tag[k]){
            swap(trie[k][1],trie[k][2]);
            tag[k] = 0;
            for(int i = 0;i < BASE;i++)
                tag[trie[k][i]] ^= 1;
        }
    }

    void dfs(int k,int dep,int num){
        if(dep == n){
            ans[val[k]] = num;
            return;
        }
        down(k);
        for(int i = 0;i < BASE;i++)
            dfs(trie[k][i],dep + 1,num + i * bin[dep]);
    }

    void Add(int k,int dep){
        if(dep == n)
            return;
        down(k);
        Add(trie[k][2],dep + 1);
        swap(trie[k][0],trie[k][1]);
        swap(trie[k][0],trie[k][2]);
    }
}

 int main(){
//     freopen("data.in","r",stdin);
//     freopen("data.out","w",stdout);
    scanf("%d",&n);
    scanf("%s",s + 1);
    m = strlen(s + 1);
    bin[0] = 1;
    for(int i = 1;i <= n;i++)
        bin[i] = bin[i - 1] * BASE;
    Trie::Build(1,0,0);
    for(int i = 1;i <= m;i++){
        if(s[i] == 'S')
            Trie::tag[1] ^= 1;
        else if(s[i] == 'R')
            Trie::Add(1,0);
    }
    Trie::dfs(1,0,0);
    for(int i = 0;i < bin[n];i++)
        printf("%d ",ans[i]);
    return 0;
}

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

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

ll n, q;
ll v, w;

int main(){
    cin >> n >> q;
    rep(i,q) {
        cin >> v >> w;
        if (n == 1) {
            cout << min(v, w) << endl;
            continue;
        }
        v--; w--;
        vector<int> t1, t2;
        while (v >= 0) {
            t1.push_back(v);
            if (v == 0) break;
            v = (v-1)/n;
        }
        while (w >= 0) {
            t2.push_back(w);
            if (w == 0) break;
            w = (w-1)/n;
        }
        reverse(t1.begin(), t1.end());
        reverse(t2.begin(), t2.end());
        int si = min(t1.size(), t2.size());
        int ans = 0;
        for (int j = 0; j < si; j++) {
            if (t1[j] != t2[j]) {
                break;
            }
            ans = t1[j];
        }
        cout << ans+1 << endl;
    }
}
































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

int main(void){
	string s;
	cin >> s;
	int a = stoi(s.substr(0,2));
	int b = stoi(s.substr(2,2));
	int y=0, m=0;
	if(1<=a&&a<=12){
		m=1;
	}
	if(1<=b&&b<=12){
		y=1;
	}
	if(y==1&&m==1){
		cout << "AMBIGUOUS" << endl;
		return 0;
	}
	if(y==1){
		cout << "YYMM" << endl;
		return 0;
	}
	if(m==1){
		cout << "MMYY" << endl;
		return 0;
	}
	cout << "NA" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define all(x) (x).begin(),(x).end()
typedef long long int ll;
using namespace std;
int main()
{
  int n;
  cin >> n;
  vector<int > p(n,0);
  vector<int > q(n,0);
  REP(i,n){
    cin >> p[i];
  }
  REP(i,n){
    cin >> q[i];
  }
  vector<int > a(n,0);
  REP(i,n){
    a[i] = i + 1;
  }
  int b = 0;
  int c = 0;
  int i = 0;
  bool flag = false;
  /////////////////
  do{
    i ++;
    flag = true;
    REP(j,n){
      if(a[j] != p[j]){
	flag = false;
	break;
      }
    }
    if(flag){
      b = i;
      break;
    }
  }while(next_permutation(all(a)));
  /////////////////
  REP(i,n){
    a[i] = i + 1;
  }
  i = 0;
  do{
    i ++;
    flag = true;
    REP(j,n){
      if(a[j] != q[j]){
	flag = false;
	break;
      }
    }
    if(flag){
      c = i;
      break;
    }
  }while(next_permutation(all(a)));
  cout << abs(b - c) << endl;

}


Measured memory_bytes: 256
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
//const n = +input[0];
//const a = [];
//for(let i=0;i<n;i++){
//	a.push(input[i+1].split(" ").map((x:string):number=>+x));
//}

//const [n, m] = input[0].split(" ").map((x: string): number => +x);
//const a = input[1].split(" ").map((x: string): number => +x);

function compareFunc(a, b){
    return a-b;
}

const a: number = +input[0];
const s: string = input[1];

if(a>=3200){
    console.log(s);
}else{
    console.log('red');
}

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

int main(){
  std::priority_queue<int> items;
  int N;
  
  cin >> N;
  
  for(int i = 0; i < N; i++){
    int a;
    cin >> a;
    items.push(a);
  }
  
  int sum = items.top() / 2;
  items.pop();
  while(!items.empty()){
    sum += items.top();
    items.pop();
  }
  
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    int N;  cin >> N;
    for(int i = 0 ; i <= 100000 ; i += 1000){
      if(N <= i){  cout << i - N  << endl;  return 0;  }
    }
	return 0;
}

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int A = scanner.nextInt();
	    int x = A * 800;
	    int y = A / 15 * 200;
	    System.out.println(x - y);
		
		// TODO Auto-generated method stub

	}

}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  string s;
  cin >> s;
  
  int ans = 0;
  REP(i,3){
    if(s[i] == '1'){
	  ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3608