akhauriyash/Code-Regression huggingface dataset:
h,w = map(int,input().split())
g = [[] for _ in range(0,10)]
for i in range(0,10):
    a = list(map(int,input().split()))
    for j in range(0,10):
        g[i].append((j,a[j]))

def dijkstra(s):
    d = [float("inf") for _ in range(0,10)]
    d[s] = 0
    q = []
    q.append((s,g[s]))
    while len(q) > 0:
        start,edge = q.pop(0)
        for to,cost in edge:
            if d[to] > d[start] + cost:
                d[to] = d[start] + cost
                q.append((to,g[to]))
    return d[1]

d = []
for i in range(0,10):
    d.append(dijkstra(i))
ans = 0
for i in range(0,h):
    a = list(map(int,input().split()))
    for j in range(0,w):
        if a[j] != -1:
            ans += d[a[j]]
print(ans)


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int C[3][3];
int main()
{
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> C[i][j];
    }
  }
  int a[3], b[3];
  bool ans = false;
  for (a[0] = 0; a[0] <= 100; a[0]++) {
    b[0] = C[0][0] - a[0];
    b[1] = C[0][1] - a[0];
    b[2] = C[0][2] - a[0];
    a[1] = C[1][0] - b[0];
    a[2] = C[2][0] - b[0];
    
    if (a[1]+b[1]==C[1][1]) {
      if (a[1]+b[2]==C[1][2]) {
        if (a[2]+b[1]==C[2][1]) {
          if (a[2]+b[2]==C[2][2]) {
            ans = true;
            break;
          }
        }
      }
    }
  }
  if (ans) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))

cnt = 0
for i in range(n):
    if a[i] < 0:
        cnt += 1
a2 = [ abs(i) for i in a]
if cnt%2 == 0:
    print(sum(a2))
else:
    print(sum(a2)-min(a2)*2)

Measured memory_bytes: 14284
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
x=[a[i]-b[i] for i in range(n)]
if sum(x)<0:
  print(-1)
  exit()
x.sort()
if x[0]>=0:
  print(0)
  exit()
ans=0
m=0
while x[ans]<0:
  ans+=1
m=sum(x[:ans])
x=x[ans:][::-1]
i=0
while True:
  m+=x[i]
  i+=1
  if m>0:
    break
ans+=i
print(ans)

Measured memory_bytes: 18356
#include <stdio.h>
int main(){
	int n,k,a,i,x=0;
	scanf("%d%d",&n,&k);
	for(i=0;i<k;i++){
		scanf("%d",&a);
		x+=a;
	}
	a=x/(n+1);
	if(x%(n+1)==0)--a;
	printf("%d\n",a+1);
	return 0;
}


Measured memory_bytes: 2140
function Main(input) {
  var s = input.replace(/\r?\n/g, "");
  var a = "abcdefghijklmnopqrstuvwxyz"
  for (var i of a) {
    if(s.indexOf(i) == -1) {
      console.log(i);
      return;
    }
  }
  console.log("None");
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
s = str(input())
while len(s) > 0:
    if s[-5:] == 'dream':
        s = s[:-5]
    elif s[-7:] == 'dreamer':
        s = s[:-7]
    elif s[-5:] == 'erase':
        s = s[:-5]
    elif s[-6:] == 'eraser':
        s = s[:-6]
    else:
        print('NO')
        break
else:
    print('YES')


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

using namespace std;

int main() {
  int n;

  cin >> n;
  int aux = n;

  if(aux & 1) {
    aux++;
  }

  while(!(aux % 2 == 0 && aux % n == 0)) {
    aux += 2;
  }

  cout << aux << endl;

  return 0;
}

Measured memory_bytes: 256
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus >= 201703L
#        pragma GCC target("avx2")
#    else
#        pragma GCC target("avx")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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 main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, a;
    cin >> n;

    int ans = 0;
    for (int i = 0; i < n; i++) {
        cin >> a;
        a--;
        ans += a;
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

const int INF = (1 << 30) - 1;
const ll INF64 = ((ll)1 << 62) - 1;
const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n;
	cin >> n;

	string ans = "";
	while (n != 0) {
		if (n % 2 != 0) {
			n--;
			ans = "1" + ans;
		} else {
			ans = "0" + ans;
		}

		n /= -2;
	}

	if (ans == "") {
		ans = "0";
	}

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


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

int main() {
    int N;
    cin >> N;
    vector<int> data(N);
    for (int i = 0; i < N; i++) {
        cin >> data.at(i);
    }
    sort(data.begin(), data.end());
    cout << data.at(N - 1) - data.at(0) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <string>
#include <vector>
#include <iomanip>
#include <sstream>
#include <utility>
#include <iterator>
#include <algorithm>
#include <functional>
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define pq priority_queue<int,vector<int>,greater<int>>
#define ll long long
//#define int long long

using namespace std;

typedef pair<int, int> pi;
int n, m, c[26];
string s;
int main() {
	cin >> s;
	rep(i, s.size()) {
		c[s[i] - 'a']++;
	}
	rep(i, 26) {
		if (c[i] == 0) {
			cout << char('a' + i) << endl;
			return 0;
		}
	}
	cout << "None" << endl;
	return 0;
}

Measured memory_bytes: 512
#pragma GCC optimize ("Ofast")
#include "bits/stdc++.h"
	
#define int long long
#define double long double 
#define PI 3.141592653589793
#define FAST ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
// Use for file I/O;
#define FIN string _fname = "paintbarn"; \
			string _is = _fname + ".in", _os = _fname + ".out"; \
			freopen(_is.c_str(), "r", stdin); \
			freopen(_os.c_str(), "w", stdout);

using namespace std;

const int INF = 4e18 + 10;
const int INF2 = 2e18 + 10;
const int INF3 = 2e10;
const int MAXN = 305;
const int LOGN = 19;
const int MOD = 1e9 + 7;
const int EPS = 1e-9;
const int MULT = 2e5;
const int MCNST = MOD * MOD * 8;

int32_t main() {
	FAST;

	int a, b, c;
	cin >> a >> b >> c;
	int c1 = 0, c2 = 0;
	while (a >= b) {
		c1++; b *= 2;
	}
	while (b >= c) {
		c2++; c *= 2;
	}
	int k;
	cin >> k;
	if (c1 + c2 <= k) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 3636
/**
 * B - Ordinary Number
 * https://atcoder.jp/contests/abc132/tasks/abc132_b
 * 
 * 方針１
 * 愚直に検査する
 * 1 < i < N の i において... 
 * p[i-1] > p[i] > p[i+1]
 * p[i+1] < p[i] < p[i-1]
 * を確認する方法.
 * 一応, O(n) で解けるはず
 **/
#include<iostream>

using namespace std;

const int MAX_N = 20;

int n;
int p[MAX_N+1];

void solve() {
    int res;
    for (int i = 1; i < n-1; i++) {
        if ((p[i-1] > p[i] && p[i] > p[i+1]) || (p[i-1] < p[i] && p[i] < p[i+1])) {
            res += 1;
        }
    }
    cout << res << endl;
}

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> p[i];
    }
    solve();
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<math.h>
using namespace std;
#define max(a,b)  (((a) > (b)) ? (a) : (b))
#define min(a,b)  (((a) < (b)) ? (a) : (b))
typedef long long ll;
int main()
{
    ll a[100001],b[100001],ans=0,n,i;
    scanf("%lld",&n);
    for(i=1; i<=n+1; i++)
    {
        scanf("%lld",&a[i]);
    }
    for(i=1; i<=n; i++)
    {
        scanf("%lld",&b[i]);
    }
    for(i=n; i>=1; i--)
    {    //printf("a[i]=%lld b[i]=%lld\n",a[i],b[i]);
        if(b[i]>=a[i+1])
        {
            b[i]-=a[i+1];
            ans+=a[i+1];
             a[i+1]=0;
            if(b[i]>=a[i])
            {
                b[i]-=a[i];
                ans+=a[i];
                a[i]=0;
            }
            else
            {

                a[i]-=b[i];
                ans+=b[i];
                b[i]=0;
            }
        }
        else
        {
            a[i+1]-=b[i];
            ans+=b[i];
             b[i]=0;
        }
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 1792
S=str(input())

cnt=0
for i in range(len(S)):
	if i%2==0:
		if S[i]=='h':
			cnt+=1
		else:
			break
	else:
		if S[i]=='i':
			cnt+=1
		else:
			break
if cnt==len(S) and len(S)%2==0:
	print('Yes')
else:
	print('No')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<double> VL;
typedef vector<string> VS;
typedef vector<PLL> VP;
typedef vector<ll> VLL;
const static int INF = 1000000000;
const static int MOD = 1000000007;
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
        ll A, B, C;
        cin >> A >> B >> C;
        ll K;
        cin >> K;
        if(A>=K){
            cout << K << endl;
        }
        else if(A<K && A+B>=K){
            cout << A << endl;
        }
        else if(A+B<K){
            cout << A+(K-A-B)*(-1) << endl;
        }

}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;

int main(){
  ll n; cin >> n;
  n--;
  string ans = "";
  ll st = 26, cnt = 1, x = n, y = n + 1, z;
  while(1){
    if(x < st){
      z = y - st / 26;
      break;
    }
    y = x;
    x -= st;
    st *= 26;
    cnt++;
  }
  for(ll i = 0; i < cnt; i++){
    char c = ('a' + (z % 26));
    string s = string() + c;
    ans.insert(0, s);
    z /= 26;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3624
A, B, C, D = map(int, input().split())

taka_life = A
taka_att = B
ao_life = C
ao_att = D

while((taka_life > 0) & (ao_life > 0)):
    ao_life -= taka_att
    taka_life -= ao_att
    
    
if(ao_life <= 0):
    print("Yes")
else:
    print("No")

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

long long a, b, c, d;

int main()
{
	cin >> a >> b >> c;

	d = c - a - b;

	if (d > 0 && d * d > 4 * a * b)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


Measured memory_bytes: 256
#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  
    typedef long double ld;
    #define pb push_back
    #define f(i,a,b) for(int i=a;i<b;i++)
    #define fd(i,a,b) for(int i=a-1;i>=b;i--)
    #define pf push_front
    #define fi first
    #define se second
    #define ps(x,y)         fixed<<setprecision(y)<<x
    #define INF 1e10
    const double pi=3.14159265358979323;
    const int mod=998244353;
    const int MAX=1000000+5;
    int p[MAX]={0};

     int gcd(int a, int b) 
    { 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
    } 
    void swap(int a,int b)
    {
      int temp=a;
      a=b;
      b=temp;
    } 
    int  binpow(int  a,int  b) 
    {
    int res = 1;
    while (b > 0) {
        if (b%2 == 1)
            res = (res * a)%mod;
        a = (a* a)% mod;
        b >>= 1;
    }
    return res;
}
    int modinv(int y)
    {
        return binpow(y,mod-2);
    }

    int fact[500000+5];
    void precal()
    {
    fact[0]=1;
    for(int i=1;i<500000+5;i++)
    {
        fact[i]=(i*fact[i-1])%mod;
    }
}
    bool isPrime(int n) 
    { 
    // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
   
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
    } 
    int mm[200000+5];
    int vis[200000+5]={0};
    signed main() {

 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  
    #ifndef ONLINE_JUDGE
      if(fopen("INPUT.txt","r"))
      {
      freopen ("INPUT.txt" , "r" , stdin);
      freopen ("OUTPUT.txt" , "w" , stdout); 
      }
    #endif  
    // -------------------------------------Code starts here--------------------------------------------------------------------- 
    int t=1; 
   // cin>>t;
    while(t--)
    {
        int n,m,k;
        cin>>n>>m>>k;
        int a[7][7];
        f(i,0,n)
        {
            f(j,0,m)
            {
                char r;
                cin>>r;
                if(r=='#')
                    a[i][j]=1;
                else
                    a[i][j]=0;
            }
        }
        int x=pow(2,n),y=pow(2,m);
        int ans=0;
        f(i,0,x)
        {
            f(j,0,y)
            {
                int cnt=0;
                f(e,0,n)
                {
                    f(r,0,m)
                    {
                        if(!(i&(1<<e) || j&(1<<r)))
                        {
                            cnt+=a[e][r];
                        }
                    }
                }
                if(cnt==k)
                    ans++;
            }
        }
        cout<<ans<<endl;
    }
}



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

int main() {
    int N;
    cin >> N;
    int A[N];
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }

    map<int, int> mp;
    for(int i = 0; i < N; i++){
        mp[A[i]]= i+1;
    }

    for(auto m: mp){
        cout << m.second << " ";
    }
    cout << endl;

    return 0;
}

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

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

    string s;
    cin >> s;
    int apos=0, zpos=0;
    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] == 'A')
        {
            apos = i;
            break;
        }
    }
    for (int i = 0; i < s.length(); i++)
    {
        int j = s.length() - 1 - i;
        if (s[j] == 'Z')
        {
            zpos = j;
            break;
        }
    }
    int ans = zpos - apos + 1;
    cout << ans << endl;
    
    
    return 0;
}

Measured memory_bytes: 720
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

def Dijkstra(num, start, vedge):
    """ vedge は DAG の 重みとして vedge[from] = (to, value)　としておくこと """
    """ DAGでない場合は vedge[from] と vedge[to] の両方を作ること """
    """ dist[i] は start から i までの最短距離 """

    dist = [float("inf") for i in range(num)]
    dist[start] = 0
    q = [[dist[start], start]]
    while q:
        du, u = heappop(q)
        for j, k in vedge[u]:
            if dist[j] > du + k:
                dist[j] = du + k
                heappush(q, [dist[j], j])
    return dist



#solve
def solve():
    n, m, s, t = LI()
    s -= 1
    t -= 1
    uva = defaultdict(list)
    uvb = defaultdict(list)
    for _ in range(m):
        u, v, a, b = LI_()
        a += 1
        b += 1
        uva[u].append((v, a))
        uva[v].append((u, a))
        uvb[u].append((v, b))
        uvb[v].append((u, b))
    dista = Dijkstra(n, s, uva)
    distb = Dijkstra(n, t, uvb)
    a = [None] * n
    for i in range(n):
        a[i] = dista[i] + distb[i]
    a = a[::-1]
    for i in range(1,n):
        a[i] = min(a[i], a[i - 1])
    a = a[::-1]
    for i in range(n):
        print(10**15-a[i])
    return


#main
if __name__ == '__main__':
    solve()


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

const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main() {
  int n, m;
  cin >> n >> m;
  if (n < m) swap(n, m);
  if (n - m > 1) {
    cout << 0 << endl;
    return 0;
  }

  mint ans = 1;
  rep(i, n) {
    ans *= (i + 1);
    if (i < m) ans *= (i + 1);
  }
  if (n == m) ans *= 2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
#include <tuple>
#include <functional>
#include <cstring>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i < n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i < n; i++)

typedef long long ll;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<std::vector<bool> > v2_bool;
typedef std::pair<ll, ll> pll;

using namespace std;

int main() 
{
    int n, x;
    cin >> n >> x;
    v_int a(n);
    v_int b(n);
    irep(i, n) {
        cin >> a[i];
        b[n-i-1] = a[i];
    }

    ll a_ans = 0;
    ll b_ans = 0;

    irep(i, n-1) {
        ll sum = a[i]+a[i+1];
        if(sum > x) { 
            a_ans += (sum - x);
            if(a[i+1] >= (sum - x)) {
                a[i+1] -= (sum - x);
            } else {
                a[i+1] = 0; 
            }
        }
    }

    irep(i, n-1) {
        ll sum = b[i]+b[i+1];
        if(sum > x) { 
            b_ans += (sum - x);
            if(b[i+1] >= (sum - x)) {
                b[i+1] -= (sum - x);
            } else {
                b[i+1] = 0; 
            }
        }
    }
    cout << min(a_ans, b_ans) << endl;
    return 0;
}


Measured memory_bytes: 1024
N = int(input()) + 2;
A = [0] + [int(i) for i in input().split()] + [0];

sum = 0;
for i in range(1, N) :
    sum += abs(A[i] - A[i - 1]);

for i in range(1, N - 1) :
    print(sum - (abs(A[i] - A[i - 1]) + abs(A[i + 1] - A[i])) + abs(A[i - 1] - A[i + 1]));


Measured memory_bytes: 14044
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

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

    double v[N];
    REP(i, N){
        cin >> v[i];
    }

    sort(v, v+N);
    double ans = 0;
    REP(i, N-1){
        v[i+1] = (v[i]+v[i+1])/2;
    }

    cout << fixed << setprecision(6) << v[N-1] << endl;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    // dp[k][i]i番目のホテルから2^k日で到達可能な最右のホテル
    vector<vector<int>> dp(20, vector<int>(n, 0));
    for(size_t i = 0; i < n; i++) {
        cin >> a[i];
    }
    int l;
    cin >> l;
    for(size_t i = 0; i < n; i++) {
        auto itr = lower_bound(all(a), a[i] + l + 1) - a.begin();
        dp[0][i] = itr - 1;
    }
    for(int k = 0; k < 19; k++) {
        for(int i = 0; i < n; i++) {
            dp[k + 1][i] = dp[k][dp[k][i]];
        }
    }
    int q;
    cin >> q;
    while(q--) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        if(x > y) {
            swap(x, y);
        }
        int day = 0;
        for(int i = 19; i >= 0; i--) {
            if(dp[i][x] < y) {
                x = dp[i][x];
                day += 1 << i;
            }
        }
        cout << day + 1 << endl;
    }
}


Measured memory_bytes: 9080
#include<stdio.h>
int main()
{
      char a,b;
    scanf("%c %c",&a,&b);
        if(a=='H'&&b=='H')
            printf("H\n");
        if(a=='H'&&b=='D')
            printf("D\n");
            if(a=='D'&&b=='H')
            printf("D\n");
            if(a=='D'&&b=='D')
            printf("H\n");
      return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include<vector>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;

int main() {
	int W, H, N;
	cin >> W >> H >> N;
	vector<int> X(N), Y(N), A(N);
	for (int i = 0; i < N; i++) {
		cin >> X[i] >> Y[i] >> A[i];
	}

	int x0, xw, y0, yh;
	x0 = 0; xw = W; y0 = 0; yh = H;
	for (int i = 0; i < N; i++) {
		if (A[i] == 1) {
			x0 = max(x0, X[i]);
		}
		else if (A[i] == 2) {
			xw = min(xw, X[i]);
		}
		else if (A[i] == 3) {
			y0 = max(y0, Y[i]);
		}
		else {
			yh = min(yh, Y[i]);
		}
	}

	if (x0 < xw && y0 < yh) {
		cout << (xw - x0) * (yh - y0);
	}
	else {
		cout << 0;
	}
	
	return 0;
}

Measured memory_bytes: 256
from functools import *
from itertools import *
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
 
M = 10**9+7
N = int(input())

@lru_cache(maxsize=None)
def mod_inv(x):
  return 1 if x == 1 else M // x * -mod_inv(M%x) % M

Weight = [0]*(N+1)
Size = [0]*(N+1)
def calc_subtree(v):
  W, S = 1, 1
  for child in Edge[v]:
    Edge[child].remove(v)
    w, s = calc_subtree(child)
    W = W * w % M
    S += s
  Weight[v] = W * S % M
  Size[v] = S
  return Weight[v], Size[v]

Ans = [0]*(N+1)
def calc_ans(v, a):
  Ans[v] = a
  for child in Edge[v]:
    n = Size[child]
    calc_ans(child, Ans[v] * n * mod_inv(N-n) % M)

Edge = [set() for i in range(N+1)]
fact = N
for i in range(1, N):
  fact = fact * i % M
  a, b = map(int, input().split())
  Edge[a].add(b)
  Edge[b].add(a)
  
calc_subtree(1)
calc_ans(1, mod_inv(Weight[1]) * fact % M)

for a in islice(Ans, 1, None):
  print(a)



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

using namespace std;


int main () {

	ios_base::sync_with_stdio(false); cin.tie(NULL);

	int n, k;
	cin >> n >> k;

	long long div1 = 0, div2 = 0;

	for (int x = 1; x <= n; ++x) {
		if (x % k == 0) ++div1;
		if (x % k == k / 2) ++div2;
	}

	long long ans = div1 * div1 * div1;

	if (k % 2 == 0) ans += div2 * div2 * div2;

	cout << ans << '\n';



	return 0;
}


Measured memory_bytes: 256
# include <stdio.h>

int main()
{
	char s1[100005],s2[100005];
	int p1[100005],p2[100005];
    int q,a,b,c,d;
    while(scanf("%s%s%d",s1+1,s2+1,&q)!=EOF)
    {
	    for(int i=1;s1[i];i++)
	        p1[i]=p1[i-1]+s1[i]-'A'+1;
	    for(int i=1;s2[i];i++)
	        p2[i]=p2[i-1]+s2[i]-'A'+1;
	    while(q--)
	    {
	        scanf("%d%d%d%d",&a,&b,&c,&d);
	        if((p1[b]-p1[a-1])%3==(p2[d]-p2[c-1])%3)
	            printf("YES\n");
	        else
	            printf("NO\n");
	    }
	}
    return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define endl '\n'
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define newline putchar('\n')
#define SZ(x) (int((x).size()))
#define leave_space putchar(' ')
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
#define repe(it, x) for (auto it = (x).begin(); it != (x).end(); ++it)
const int MAXN = 2019;
bool can[MAXN][MAXN * 5];
string s[MAXN], all, ans;
int sz[MAXN];
bitset<int(1e6) + 10> tree[64], state;
inline char query() {
	int pos = 1;
	while (pos < 32) {
		if ((state & tree[pos * 2]).none()) {
			pos = pos * 2 + 1;
		}	else pos *= 2;
	}
	return (pos - 32) + 'a';
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	int n, m;
	cin >> n >> m;
	rep (i, 1, n) {
		cin >> s[i];
	}
	can[n + 1][0] = 1;
	per (i, n, 1) {
		rep (j, 0, m) if (can[i + 1][j]) {
			can[i][j] = 1;
			if (j + SZ(s[i]) <= m) {
				can[i][j + SZ(s[i])] = 1;
			}
		}
	}
	rep (i, 1, n) {
		sz[i] = SZ(all);
		all += s[i];
	}
	sz[n + 1] = SZ(all);
	rep (i, 0, SZ(all) - 1) {
		tree[all[i] - 'a' + 32].set(i);
	}
	per (i, 31, 1) {
		tree[i] = tree[i << 1] | tree[i << 1 | 1];
	}
	state.set(0, 1);
	rep (i, 0, m - 1) {
		rep (j, 1, n) {
			if (state.test(sz[j])) state.set(sz[j + 1]);
		}
		rep (j, 1, n) {
			if (m - i - SZ(s[j]) < 0 || !can[j + 1][m - i - SZ(s[j])]) state.reset(sz[j]);
		}
		static char ch;
		ans += ch = query();
		(state &= tree[ch - 'a' + 32]) <<= 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 30348
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main{

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

		List<Integer> list = new ArrayList<Integer>();
		list.add(sc.nextInt());
		list.add(sc.nextInt());
		list.add(sc.nextInt());

		Collections.sort(list);

		System.out.println(list.get(0) + " " + list.get(1) + " " + list.get(2));

		sc.close();

	}

}


Measured memory_bytes: 26268
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
 
		if(a + b == 15) {
			System.out.println("+");
		}else if(a * b == 15) {
			System.out.println("*");
		}else {
			System.out.println("x");
		}
 
 
 
 
	}
}

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

int main() {
    int n; cin >> n;
    vector<vector<int>> g(n);
    for (int i = 0; i < n; i++) {
        int u, k; cin >> u >> k; u--;
        while (k--) {
            int v; cin >> v; v--;
            g[u].push_back(v);
        }
        sort(g[u].begin(), g[u].end());
    }
    vector<int> d(n, -1);
    d[0] = 0;
    queue<int> q; q.push(0);
    while (q.size()) {
        int v = q.front(); q.pop();
        for (auto x : g[v]) {
            if (d[x] < 0) {
                d[x] = d[v] + 1;
                q.push(x);
            }
        }
    }
	for (int i = 0; i < n; i++) cout << i + 1 << " " << d[i] << endl;
}


Measured memory_bytes: 3108
#include <iostream>
using namespace std;
#define MAX 100002
#define NIL -1

struct Node { int p, l, r, d; };

Node Tree[MAX];
int n, D[MAX];

void print(int u){
    cout << "node " << u << ": ";
    cout << "parent = " << Tree[u].p << ", ";
    cout << "depth = " << Tree[u].d << ", ";
    
    if(Tree[u].p==NIL) cout << "root, ";
    else if(Tree[u].l==NIL) cout << "leaf, ";
    else cout << "internal node, ";
    
    cout << "[";
    for(int i=0, c=Tree[u].l ; c!=NIL ; i++, c=Tree[c].r){
        if(i) cout << ", " ;
        cout << c ;
    }
    cout << "]" << endl;
    
}

void depth(int u,int d){
    Tree[u].d = d;
    if(Tree[u].r!=NIL) depth(Tree[u].r, d);
    if(Tree[u].l!=NIL) depth(Tree[u].l, d+1);
}


int main(){
    int root;
    int id,k,c,c_back;
    
    cin >> n;
    
    for(int i=0;i<n;i++){
        Tree[i].p=Tree[i].l=Tree[i].r=NIL;
    }
    
    for(int i=0;i<n;i++){
        cin >> id >> k;
        for(int j=0;j<k;j++){
            cin >> c;
            if(j==0) Tree[id].l=c;
            else Tree[c_back].r = c;
            c_back = c;
            Tree[c].p = id; 
        }
    }
    
    for(int i=0;i<n;i++){
        if(Tree[i].p==NIL) root = i;
    }
    
    depth(root,0);
    
    for(int i=0;i<n;i++) print(i);
    
    return 0;
}



Measured memory_bytes: 7732
#include "bits/stdc++.h"
using namespace std;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t = 1;
    //cin >> t;
    while(t--)
    {
        int n, m, p;
        cin>>n>>m>>p;
        if((n == m && n != p) || (n == p && n != m) || (m == p) && (m != n))
            cout << "Yes" << endl;
        else
            cout << "No" <<endl;
    }
    return 0;
}



Measured memory_bytes: 256
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():

    N,M=map(int,input().split())
    X=sorted(list(map(int,input().split())))



    l=sorted([X[i+1]-X[i] for i in range(M-1)], reverse=True)

    print(X[-1]-X[0]-sum(l[:N-1]))




resolve()

Measured memory_bytes: 59048
#include <bits/stdc++.h>
using namespace std;
constexpr double EPS = 1e-14;

struct vec2 {
    double x, y;
    vec2 operator+(const vec2 rhs) {
        return {x + rhs.x, y + rhs.y};
    }
    vec2 operator-(const vec2 rhs) {
        return {x - rhs.x, y - rhs.y};
    }
    vec2 operator*(const double k) {
        return {x * k, y * k};
    }
    vec2 operator/(const double k) {
        return {x / k, y / k};
    }
};

double dot(vec2 a, vec2 b) {
    return a.x * b.x + a.y * b.y;
};

double norm2(vec2 a) {
    return dot(a, a);
}

struct line {
    vec2 p, l;
};

line make_line(vec2 a, vec2 b) {
    return {a, b - a};
}

bool is_parallel(line a, line b) {
    return abs(a.l.x * b.l.y - a.l.y * b.l.x) < EPS;
}

void printvec2(vec2 p, int precision) {
    cout << setprecision(precision) << fixed << p.x << " " << p.y << endl;
}

vec2 intersection(line l1, line l2) {
    assert(!is_parallel(l1, l2));
    double a = l1.p.x, b = l1.p.y, c = l1.l.x, d = l1.l.y;
    double e = l2.p.x, f = l2.p.y, g = l2.l.x, h = l2.l.y;
    double k = (h * (a - e) - g * (b - f)) / (g * d - c * h);
    return {
        a + k * c,
        b + k * d
    };
}

vec2 get_normal(vec2 p) {
    return {-p.y, p.x};
}

vec2 foot(vec2 p, line l) {
    line normal = {p, get_normal(l.l)};
    return intersection(normal, l);
}

vec2 reflect(vec2 p, line l) {
    vec2 f = foot(p, l);
    return {2 * f.x - p.x, 2 * f.y - p.y};
}

double dist(vec2 p, line l) {
    return sqrt(norm2(foot(p, l) - p));
}

int main() {
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    line l = make_line({x1, y1}, {x2, y2});

    int q;
    cin >> q;
    while (q--) {
        double x, y;
        cin >> x >> y;
        printvec2(reflect({x, y}, l), 10);
    }
}



Measured memory_bytes: 3280
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    H, W = il()
    S = [iss() for _ in range(H)]

    move = [[-1, 1], [0, 1], [1, 1], [-1, 0], [1, 0], [-1, -1], [0, -1], [1, -1]]
    ret = []
    for _ in range(H):
        ret.append([0] * W)

    for h in range(H):
        for w in range(W):
            if S[h][w] == '.':
                continue
            else:
                ret[h][w] = '#'
                for mw, mh in move:
                    if w + mw >= W or h + mh >= H: continue
                    if w + mw < 0 or h + mh < 0: continue
                    if ret[h + mh][w + mw] != '#': ret[h + mh][w + mw] += 1

    for r in ret:
        print(*r, sep='')


if __name__ == '__main__':
    main()


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

int main()
 {
     int n;
     cin>>n;
     ll a[2*100000];
     for(int i=0;i<n;i++)
     {
         cin>>a[i];
     }
    sort(a,a+n);
    int l=a[n-1]; //left
    int r=l;             // right
int i=0,j=n-2;
long long int sum=0;
while(i<j){
        int li=abs(l-a[i]),ri=abs(r-a[i]);
        int lj=abs(l-a[j]),rj=abs(r-a[j]);
        if(li>ri||lj>rj){ //left side
                if(li>lj){
                        sum+=li;
                        l=a[i++];
                }else{
                        sum+=lj;
                        l=a[j--];
                }
        }else{
                if(ri>rj){
                        sum+=ri;
                        r=a[i++];
                }else{
                        sum+=rj;
                        r=a[j--];
                }
        }
}
sum+=max(abs(l-a[i]),abs(r-a[i]));
cout<<sum<<endl;

}


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

using namespace std;

//const int MOD=1e9+7;
const int MOD=998244353;

const double PI=3.14159265359;




int main(){
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    int n;
    cin>>n;
    
    int k=-1;
    for(int i=2; i<1000; i++){
        if(2*n==i*(i-1)) k=i;
    }
    if(k==-1){
        cout<<"No";
        return 0;
    }
    
    vector<vector<int>> ans(k,vector<int>(k-1,-1));
    
    int cur=1;
    for(int i=0; i<k-1; i++){
        for(int j=i; j<k-1; j++){
            ans[i][j]=cur;
            ans[j+1][i]=cur;
            cur++;
        }
    }
    
    cout<<"Yes\n"<<k<<'\n';
    for(int i=0; i<k; i++){
        cout<<k-1<<' ';
        for(int j:ans[i]){
            cout<<j<<' ';
        }
        cout<<'\n';
    }
    
    
    return 0;
}

Measured memory_bytes: 2176
# coding: utf-8
# Your code here!

n,m = [int(i) for i in input().split()]
py = [[int(i) for i in input().split()] for _ in range(m)]

spy = list(sorted(py+[[p,0] for p in range(n+1)]))

zaatu = {(p,y):i for i, (p,y) in enumerate(spy)}


for p,y in py:
    print(format(p, '06')+format(zaatu[(p,y)]-zaatu[(p,0)], '06'))


Measured memory_bytes: 73492
//Coded by Abhijay Mitra
#include <iostream>
#include <stdlib.h>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <numeric>
#include <vector>
#include <iterator> 
#include <map>
#include <set>
#include <climits>
#include <queue>
#include <cmath>
#include <stack>
#include <cctype>
#include <bitset>
// #include <bits/stdc++.h>
#define double long double
#define int long long int
#define ll int
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define bp __builtin_popcount
#define pb push_back
#define res(v) v.resize(unique(v.begin(), v.end()) - v.begin());
#define cnt_res(v) std::distance(v.begin(),std::unique(v.begin(), v.end())); 
#define timer cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using pii = std::pair<int,int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
#define mp         make_pair
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define per(i,b,a) for (int i = b; i >= a; i--)
#define all(x)     x.begin(), x.end()
using namespace std;
const int N=2e6+10;
const int inf = /*0x3f3f3f3f*/1e18+10;
// const ll M = 998244353 ; // Mulo
// const int M = 1e9+7 ; // Mulo
const double Pi = 3.14159265;
#define F first
#define S second
int n,w;
void solve(){
  cin>>n>>w;vvi v(2,vi(n+1,0));vvi dp(w+1,vi(n+1,0));
  rep(i,1,n)
    rep(j,0,1)
      cin>>v[j][i];
  //dp[i][j] is max weight taken by consider all elements from 1 to j
  //with total weight i
  int ma=0;
  rep(j,1,n)rep(i,1,w){
    if(v[0][j]>i)dp[i][j]=dp[i][j-1];
    else dp[i][j]=max(dp[i][j-1],v[1][j]+dp[i-v[0][j]][j-1]);
    ma=max(ma,dp[i][j]);
  }
  cout<<ma;
}
int32_t main()
{
  ibs;cti;
  solve()
  /*,cout<<"\n"*/;
  // cout<<"\n";
  int xx=0;
  // int t;cin>>t;while(t--){/*xx++;cout<<"Case "<<xx<<":\n"*/;solve();cout<<"\n";}
  return 0;
}

Measured memory_bytes: 83072
import java.util.Scanner;

// https://atcoder.jp/contests/abc137/tasks/abc137_b
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int x = sc.nextInt();
		sc.close();

		int min = x-k+1;
		int max = x+k-1;

		System.out.print(min + " ");

		int num = min;
		for(int i=1;num<max;i++) {
			num = num + 1;
			System.out.print(num + " ");
		}
	}

}


Measured memory_bytes: 23764
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; ++i)
#define debug(s, param) std::cerr << s << param << std::endl;

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> v;
  rep (i, n) {
    int a, b;
    cin >> a >> b;
    v.emplace_back(a, b);
  }
  bool res = false;
  int seq = 0;
  for (const auto& [a, b] : v) {
    if (a == b) {
      ++seq;
    } else {
      seq = 0;
    }
    if (seq >= 3) {
      res = true;
      break;
    }
  }
  cout << (res ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
using namespace std;
typedef long long ll;

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();
		
		int taps = 1;
		int count = 0;
		while(taps<b) {
			count++;
			taps += a-1;
		}
		
		System.out.println(count);
	}

}


Measured memory_bytes: 23124
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <string>
#define ll long long
#define ull unsigned long long
#define make(type,x) type x; cin>>x
#define make2(type,x,y) type x,y; cin>>x>>y
#define fr(x,y) for(long long x=0;x<y;x++)
#define makevec(x,y,n) vector <x> y(n); for(ll i=0;i<n;i++) cin>>y[i]
#define M (ll)1000000007
#define MM (ll) 1e8
#define INF (ll) 1e18

# define IOS ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;

template <typename T>
T modpow(T base, T exp, T modulus) {
  base %= modulus;
  T result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulus;
    base = (base * base) % modulus;
    exp >>= 1;
  }
  return result;
}
bool sortbysec(const pair <ll,ll> &a,const pair <ll,ll> &b){
    return a.second<b.second;
}

struct cmp {
	bool operator() (const pair<int, int> &a, const pair<int, int> &b) const {
		int lena = a.second - a.first + 1;
		int lenb = b.second - b.first + 1;
		if (lena == lenb) return a.first < b.first;
		return lena > lenb;
	}
};


struct c_h {
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll calcpow(ll x, ll y)
{
    ll temp;
    if(y == 0)
        return 1;
    temp = calcpow(x, y / 2);
    if (y % 2 == 0)
        return temp * temp;
    else
    {
        if(y > 0)
            return x * temp * temp;
        else
            return (temp * temp) / x;
    }
}
ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);

}
ll egcd(ll a, ll b, ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1;
    ll y1;
    ll g=egcd(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}


bool isprime(ll a){
bool flag=1;
for(ll i=2;i*i<=a;i++){
    if(a%i==0) {flag=0; break;}
}
return flag;
}

ll dx8[8]={1,0,-1,0,1,-1,1,-1};
ll dy8[8]={0,1,0,-1,1,-1,-1,1};
ll dx4[4]={0,0,1,-1};
ll dy4[4]={1,-1,0,0};



int main(){
    IOS;
    ll s=0;
    ll ss=0;

    fr(i,9){
        make(ll,x);
        s+=x;
        if(i==0 || i==4 || i==8) ss+=x;
    }
    if(s%3==0 && (ss==s/3)) cout<<"Yes \n";
    else cout<<"No \n";



    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 std;
using namespace __gnu_pbds ;
#define ll long long
#define ld long double
#define rep(i,a,b) for(ll i=a;i<b;i+=1)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define sz(a) int((a).size())
#define hell (ll)1000000007
#define f first
#define s second
#define sll(x) scanf("%lld",&x)
#define si(x) scanf("%d",&x)
typedef tree< ll , null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update > ordered_set ;
ll t = 1 ;
void solve()
{
    ll a , b , c ;
    cin >> a >> b >> c ;
    cout << min( a + b , min( a + c , b+c ))  ;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    /*fact[0] = 1 ;
    rep( i , 1 , N )
        fact[i] = ( fact[i-1] * i ) % hell ;*/
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //cin>>t;
    while(t--)
        solve() ;
    return 0 ;
}


Measured memory_bytes: 256
# 設問注意。ただの数字の配列ではなく、 1,2,3,4,5,...Nと1ずつインクリメントされる配列である.

n = int(input())
ary = [int(i) for i in input().split()]
wrongCount = 0

# wrongCountの数が0か2ならYES
# 3を超えた時点でNOを出力して終了する
for i in range(n):
    if ary[i] != i + 1:
        if wrongCount == 2:
            print('NO')
            exit()
        wrongCount += 1

print('YES')


Measured memory_bytes: 2940
from itertools import permutations
from math import ceil, floor

D, G = [int(elem) for elem in input().split(' ')]
point_info_list = [[int(elem) for elem in input().split()] for _ in range(D)]
assert len(point_info_list) == D
assert len(point_info_list[0]) == 2

min_num = float('inf')
for perm in permutations(range(D)):
    current_point = 0
    current_num = 0
    for point in perm:
        if (G - current_point) - (point + 1) * 100 * point_info_list[point][0] <= 0:
            current_num += ceil((G - current_point) / ((point + 1) * 100))
            break
        elif (G - current_point) - (point + 1) * 100 * point_info_list[point][0] - point_info_list[point][1] <= 0:
            current_num += point_info_list[point][0]
            break
        else:
            current_point += (point + 1) * 100 * point_info_list[point][0] + point_info_list[point][1]
            current_num += point_info_list[point][0]
    min_num = min(current_num, min_num)

print(min_num)



Measured memory_bytes: 42472
from collections import *
from heapq import *
from itertools import *
#from fractions import gcd

from decimal import *
import copy
from bisect import *
import time
import sys
import math

input=lambda :sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))

N,M=map(int,input().split())
A=sorted(list(map(int,input().split())),reverse=True)
a=sum(A)
Z=a/(4*M)
for m in range(M):
    if A[m]<Z:
        print("No")
        exit()
print("Yes")


Measured memory_bytes: 59884
#include <bits/stdc++.h>
#define LL long long
#define Accel ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Re(a,b) memset(a,b,sizeof a)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(X) (X).begin(), (X).end()
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
#define REP(I, N) for (int I = 0; I < (N); I++)
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define SZ(a) ((int)a.size())
using namespace std;
const int N=1e5+10;
int p[N];
int find(int x){
	if(x==p[x])return p[x];
	return p[x]=find(p[x]);
}
int n,k;
int a[N];
int main(){
	cin>>n>>k;
	FOR(i,1,n)cin>>a[i],p[i]=i;
	REP(i,k){
		int u,v;cin>>u>>v;u=find(u),v=find(v);
		p[u]=v;
	}
	int t=0;
	FOR(i,1,n){
		if(find(i)==find(a[i]))t++;
		
	}
	cout<<t<<endl;

}

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


int main() {
	string s;
  	cin>>s;
  	sort(s.begin(),s.end());
  
  	for (int i=0;i<s.size()-1;i++){
		if(s.at(i)==s.at(i+1)){
        	cout<<"no"<<endl;
          	return 0;
        }
    }
  	cout<<"yes"<<endl;
}


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

using namespace std; 

int main(){ 
  string s;
  cin>>s;
  int a=s.size();
  s=s.substr(0,a-2);
  a-=2;
  bool x=true;
  int ans=-1;
  while(x){
    for(int i=0;i<a/2;++i){
      if(s[i]!=s[i+a/2]){
        s=s.substr(0,a-2);
        a-=2;
        break;
      }
      if(i==a/2-1){
        ans=a;
        x=false;
        break;
      }
    }
    if(a==0) {
      break;
    }
  }
  cout<<ans;
}
 

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

using namespace std;

int main(void)
{
    string s, result;
    cin >> s;

    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] != 'B') result.push_back(s[i]);
        else if(result.size() != 0) result.pop_back();
    }

    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256