akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Int32;

class Program
{
    static void Main(string[] args)
    {
        label:
        var array = new int[Parse(ReadLine())];
        var sp = ReadLine().Split();
        for (int i = 0; i < sp.Length; ++i)
        {
            array[i] = Parse(sp[i]);
        }
        int left = 0, right = 0, sum = array[0];
        long result = 1;
        while (true)
        {
            if (right < array.Length - 1)
            {
                if ((sum | array[right + 1]) == (sum + array[right + 1]))
                {
                    ++result;
                    sum |= array[++right];
                    continue;
                }
            }
            if (left < right)
            {
                result += right - left;
                sum &= ~array[left++];
                continue;
            }
            if (left < array.Length - 1)
            {
                sum = array[++left];
                ++right;
                ++result;
                continue;
            }
            break;
        }
        WriteLine(result);
    }
}


Measured memory_bytes: 28764
class Dice:
    def __init__(self, face_vals):
        self.faces = dict(zip(['top', 'front', 'right',
                               'left', 'back', 'bottom'], face_vals.split()))

    def roll(self, direction):
        if direction == 'N':
            self.faces['top'], self.faces['front'], self.faces['bottom'], \
            self.faces['back'] = self.faces['front'], self.faces['bottom'], \
            self.faces['back'], self.faces['top']
        elif direction == 'S':
            self.faces['top'], self.faces['front'], self.faces['bottom'], \
            self.faces['back'] = self.faces['back'], self.faces['top'], \
            self.faces['front'], self.faces['bottom']
        elif direction == 'E':
            self.faces['top'], self.faces['right'], self.faces['bottom'], \
            self.faces['left'] = self.faces['left'], self.faces['top'], \
            self.faces['right'], self.faces['bottom']
        else:
            self.faces['top'], self.faces['right'], self.faces['bottom'], \
            self.faces['left'] = self.faces['right'], self.faces['bottom'], \
            self.faces['left'], self.faces['top']

    def _revolve(self, direction):
        if direction == 'R':
            self.faces['front'], self.faces['left'], self.faces['back'], \
            self.faces['right'] = self.faces['right'], self.faces['front'], \
            self.faces['left'], self.faces['back']
        else:
            self.faces['front'], self.faces['left'], self.faces['back'], \
            self.faces['right'] = self.faces['left'], self.faces['back'], \
            self.faces['right'], self.faces['front']
            
    def show_right_face(self, top, front):
        if front == self.faces['back']:
            if top == self.faces['top']:
                self._revolve('R')
                self._revolve('R')
            else:
                self.roll('S')
                self.roll('S')
        elif front == self.faces['top']:
            self.roll('S')
        elif front == self.faces['right']:
            self._revolve('R')
        elif front == self.faces['left']:
            self._revolve('L')
        elif front == self.faces['bottom']:
            self.roll('N')
        if top == self.faces['bottom']:
            self.roll('E')
            self.roll('E')
        elif top == self.faces['right']:
            self.roll('W')
        elif top == self.faces['left']:
            self.roll('E')
        print(self.faces['right'])


import sys

face_vals = sys.stdin.readline()

dice = Dice(face_vals)

n = int(sys.stdin.readline())

for i in range(n):
    top, front = sys.stdin.readline().split()
    dice.show_right_face(top, front)

Measured memory_bytes: 7924
#include<stdio.h>
#include<stdlib.h>
int main(){
  int unused __attribute__((unused));
  long long X,  y = 0, m = 100;
  unused = scanf("%lld", &X);

  while(m < X){
    m = m*1.01;
    y++;
  }
  printf("%lld", y);
  return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#define llint long long

using namespace std;
typedef pair<llint, llint> P;

llint parent[2005];

void init(){
	for(llint i = 0; i < 2005; i++) parent[i] = i;
}

llint root(llint i)
{
	if(parent[i] == i) return i;
	return parent[i] = root(parent[i]);
}

void unite(llint i, llint j)
{
	llint root_i = root(i), root_j = root(j);
	if(root_i == root_j) return;
	parent[root_i] = root_j;
}

bool same(llint i, llint j)
{
	return root(i) == root(j);
}

llint N, K, Q;
llint A[2005];
bool valid[2005];
vector<P> vec;
llint cnt[2005];

int main(void)
{
	cin >> N >> K >> Q;
	for(llint i = 0; i < N; i++) cin >> A[i];
	init();
	
	for(llint i = 0; i < N; i++) vec.push_back(make_pair(A[i], i));
	sort(vec.begin(), vec.end());
	
	llint ans = 2e9+7;
	for(llint i = vec.size()-1; i >= 0; i--){
		for(llint j = 0; j < N; j++){
			if(!valid[j] && vec[i].first <= A[j]){
				valid[j] = true;
				if(j < N-1 && valid[j+1]) unite(j, j+1);
				if(j > 0 && valid[j-1]) unite(j, j-1);
			}
		}
		for(llint j = 0; j < N; j++) cnt[j] = 0;
		for(llint j = 0; j < N; j++){
			if(valid[j]) cnt[root(j)]++;
		}
		
		//for(llint j = 0; j < N; j++) cout << cnt[j] << " "; cout << endl;
		
		llint done = 0, tmp = -1;
		for(llint j = i; j < vec.size(); j++){
			if(cnt[root(vec[j].second)] >= K){
				cnt[root(vec[j].second)]--;
				done++;
				tmp = vec[j].first;
			}
			if(done >= Q) break;
		}
		if(done < Q) goto ng;
		//cout << vec[i].first << " " << tmp << endl;
		ans = min(ans, tmp - vec[i].first);
		ng:;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 384
from collections import deque

N = int(input())
A = [[] for i in range(N + 1)]
for i in range(N - 1):
  u, v, w=map(int, input().split())
  A[u].append([v, w])
  A[v].append([u, w])
#print(A)

check = [-1] * (N + 1)
check[1] = 0
D = deque()
D.append(1)

while D:
  d=D.popleft()
  for a in A[d]:
    if check[a[0]]==-1:
      D.append(a[0])
      check[a[0]]=(check[d]+a[1])%2

for i in range(1,len(check)):
  print(check[i])

Measured memory_bytes: 82464
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int n,k;
ll dp[2005][2005];
ll modpow(ll x,ll n){
	ll res=1;
	while(n>0){
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
ll F[4000005],R[4000005];
void make(){
	F[0] = 1;
	for(int i=1;i<4000005;i++) F[i] = F[i-1]*i%mod;
	R[4000000] = modpow(F[4000000],mod-2);
	for(int i=4000000;i>=1;i--) R[i-1] = R[i]*1LL*i%mod;
}
ll C(int a,int b){
	return F[a]*R[b]%mod*R[a-b]%mod;
}
int main(){
	cin>>n>>k; if(k==1){puts("1");return 0;} make();
	dp[0][0] = 1;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			if(dp[i][j] == 0) continue;
			if(i!=n) dp[i+1][j] = (dp[i+1][j]+dp[i][j])%mod;
			if(i>=j+1) dp[i][j+1] = (dp[i][j+1]+dp[i][j]*C(n*k-j*(k-1)-i-1,k-2)%mod)%mod;
		}
	}
	cout<<dp[n][n]*F[n]%mod<<endl;
}

Measured memory_bytes: 94080
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

int ac_num[100001];

int main(){
  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  rep(i, 1, N){
    ac_num[i + 1] = ac_num[i] + (S[i] == 'C' && S[i - 1] == 'A' ? 1 : 0);
  }
  rep(i, Q){
    int l, r;
    cin >> l >> r;
    int ans = ac_num[r] - ac_num[l];
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>
#include<stdlib.h>

int main()
{
 int N;
 char S[10005];
 char OUT[10005];
 int num;
 int i;
 int count=0;

 scanf("%d %s",&N,&S);
 for(i=0;i<10000;i++)
 {
  if( (S[i]<'A')|(S[i]>'Z') ) break;
  num=S[i];
  num='A'+((num+26-'A'+N)%26);
  OUT[i]=num;
  count++;
 }
 for(i=0;i<count;i++) printf("%c",OUT[i]);
 printf("\n");
 return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    if(K == 0) {
        cout << N * N << endl;
        return 0;
    }
    repi2(j, K + 1, N) {
        ans += N / j * (j - K) + max(0LL, N % j - K + 1);
    }
    cout << ans << endl;
    return 0;
}


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

/* short names and const
using ll = long long;
using vll = vector<long long>;
using df = vector<vector<long long>>;
df data(n, vector<long long>(m));
const int MOD = 1e9 + 7;
const long long INF = 1e18;
*/

/* Boost!
#include <boost/algorithm/string/classification.hpp> // is_any_of
#include <boost/algorithm/string/split.hpp>
using boost::algorithm::split; // split(result, s, boost::is_any_of(","));
#include <boost/algorithm/string/join.hpp>
using boost::algorithm::join; // string s = join(arr, "");
#include <boost/algorithm/string/replace.hpp>
using boost::algorithm::replace_all; // replace_all(s, "AtCoder", "A");
#include <boost/range/algorithm.hpp> // boost::sort(arr)
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
*/

/* print(arr)
template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}
*/

/* fast cin and precise cout
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  getline(cin, s);
  cout << fixed << setprecision(15);
*/

/* sum function
int sum(vector<int> &arr) {
  int res = accumulate(arr.begin(), arr.end(), 0);
  return res;
}
*/

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  auto speak = [d](int x, int y){return abs(y - x) <= d;};
  cout << (speak(a, c) || (speak(a, b) && speak(b, c)) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
S = input().strip()
mod = 10**9+7
a = 0
ab = 0
ans = 0
q = 1
for c in S:
    if c == 'A':
        a += q
    elif c == 'B':
        ab += a
    elif c == 'C':
        ans += ab
    elif c == '?':
        a, ab, ans, q = a*3+q, ab*3+a, ans*3+ab, q*3
    a %= mod
    ab %= mod
    ans %= mod
    q %= mod
print(ans % mod)


Measured memory_bytes: 42220
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
  vector <char> v;
  char s;
  while (cin >> s) v.push_back(s);
  string a = "maerd", b = "remaerd", c = "esare", d = "resare";
  ll i = 0;
  ll tmp = 0;
  ll res = 0;
  reverse(v.begin(), v.end());
  while (i < v.size()) {
    if (v.at(i) == 'm') {
      rep(j, 5) {
        if (i+j >= v.size()) {
          res++;
          break;
        } else {
          if (v.at(i+j) == a.at(j)) tmp++;
        }
      }
      i += 5;
    } else if (v.at(i) == 'e') {
      rep(j, 5) {
        if (i+j >= v.size()) {
          res++;
          break;
        } else {
          if (v.at(i+j) == c.at(j)) tmp++;
        }
      }
      i += 5;
    } else if (v.at(i) == 'r') {
      if (i+2<v.size() && v.at(i+2)=='m') {
        rep(j, 7) {
          if (i+j >= v.size()) {
            res++;
            break;
          } else {
            if (v.at(i+j) == b.at(j)) tmp++;
          }
        }
        i += 7;
      } else if (i+2<v.size() && v.at(i+2)=='s') {
        rep(j, 6) {
          if (i+j >= v.size()) {
            res++;
            break;
          } else {
            if (v.at(i+j) == d.at(j)) tmp++;
          }
        }
        i += 6;
      } else {
        res++;
        break;
      }
    }
    if (res > 0) {
      break;
    }
  }
  if (tmp == v.size()) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 512
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>
#include<deque>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl

ll n,m,a,b,c,x,y,z,aa[200010],ab[200010],ac[1010][1010];
bool r,ra,rb,rc;
string s,sa,sb,sc;
char ca,cb,cc,cd[1010][1010];
vector<ll> va,vb,vc;

int main(){
    cin>>a>>b>>c;
    x=(a+b)*c/2;
    C x E;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void) {
	// your code goes here
    
    double x1,y1;
    double x2,y2;
    double d;
    
    scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
    d = pow((x1-x2),2)+pow((y1-y2),2);
    d = sqrt(d);
    
    printf("%f",d);
    
	return 0;
}

Measured memory_bytes: 652
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>
#include<iomanip>


using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define printfloat(x) cout << setprecision(7) << (x) << endl;

long double pi = 3.14159265359;

int n;

int main(){
    cin >> n;
    if(n%1000==0){
        cout << 0 << endl;
        return 0;
    }
    int ans = n/1000*1000 + 1000;
    if (ans - n != 1000)cout << ans - n << endl;
    else cout << 0 << endl;


return 0;
}

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

int main(){
  int a[4];
  cin>>a[0];
  a[3]=a[0]%10;
  a[0]/=10;
  a[2]=a[0]%10;
  a[0]/=10;
  a[1]=a[0]%10;
  a[0]/=10;
  for(int op1=1;op1<=2;++op1){
    for(int op2=1;op2<=2;++op2){
      for(int op3=1;op3<=2;++op3){
        if(a[0]+pow(-1,op1)*a[1]+pow(-1,op2)*a[2]+pow(-1,op3)*a[3]==7){
          cout << a[0] << (op1==1?'-':'+') << a[1] << (op2==1?'-':'+') << a[2] << (op3==1?'-':'+') << a[3] << "=7" << endl;
          return 0;
        }
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

int n, m, a;
map<int, int> edges[110];

int main() {
  while (scanf("%d %d %d", &n, &m, &a), n|m|a) {
    REP(i, 110) { edges[i].clear(); }
    REP(i, m) {
      int h, p, q;
      scanf("%d %d %d", &h, &p, &q);
      edges[p].insert(make_pair(-h, q));
      edges[q].insert(make_pair(-h, p));
    }
    int h = -1001;
    while (true) {
      if (edges[a].upper_bound(h) == edges[a].end()) { break; }
      map<int, int>::iterator it = edges[a].upper_bound(h);
      h = it->first;
      a = it->second;
    }
    printf("%d\n", a);
  }
}

Measured memory_bytes: 976
#include <stdio.h>
void swap(int *a,int *b){
   int tmp;
   tmp = *a;
   *a=*b;
   *b=tmp;
   return;
}
int main(){
  int i,n,k[10],w[10],K,W;
  K=W=0;
  for(i=0;i<10;i++){
    scanf("%d",&n);
    w[i]=n;
  }
  for(i=0;i<10;i++){
    scanf("%d",&n);
    k[i]=n;
  }
  for(i=0;i<3;i++){
    for(int j=i+1;j<10;j++) if(k[i]<k[j]) swap(&k[i],&k[j]);
  }
  for(i=0;i<3;i++){
    for(int j=i+1;j<10;j++) if(w[i]<w[j]) swap(&w[i],&w[j]);
  }
  for(i=0;i<3;i++){
    K+=k[i];W+=w[i];
  }
  printf("%d %d\n",W,K);
  return 0;
}

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

int main(){
    string s;
    int ans,a,b;
    cin >> s;
    a=100*(s.at(0)-'0')+10*(s.at(1)-'0')+(s.at(2)-'0');
    b=100*(s.at(0)-'0')+10*(s.at(0)-'0')+(s.at(0)-'0');
    ans=100*(s.at(0)-'0')+10*(s.at(0)-'0')+(s.at(0)-'0')+111;
    if(a<=b){
        cout << b << endl;
    }else{
        cout << ans << endl;
    }
}


Measured memory_bytes: 256
X,N=map(int,input().split())
L=list(map(int,input().split()))
L.append(X)
if L.count(X)==1:
  print(X)
else:
  set(L)
  for i in range(1,X+1):
    if X-i not in L:
      print(X-i)
      break
    elif X+i not in L:
      print(X+i)
      break

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

int main()
{
	// ?????°??£?¨?
	int x;
	int i = 1;

	while (1)
	{
		// ??\???
		cin >> x;

		if (x == 0)
		{
			break;
		}
		// ??????
		cout << "Case " << i << ": " << x << endl;
		i++;
	}

	return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int m = sc.nextInt();
        long[] ans = new long[n+1];
        ans[0] = 1;
        for (int i = 0; i < m; i++) {
            ans[sc.nextInt()] = -1;
        }
        if (ans[1] == -1) {
            ans[1] = 0;
        } else {
            ans[1] = 1;
        }
        for (int i = 2; i < n+1; i++) {
            if(ans[i] == -1) {
                ans[i] = 0;
            } else {
                ans[i] = (ans[i-2] + ans[i-1]) % 1000000007;
            }
        }
        System.out.println(ans[n]);
    }

}


Measured memory_bytes: 62796
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<long long> A(N+1, 0);
    for(int i=1; i<=N; i++) cin >> A[i];

    vector<long long> B(N+1, 0LL);
    for(int i=1; i<=N; i++)
        B[i] = B[i-1] + abs(A[i] - A[i-1]);

    for(int i=1; i<=N-1; i++)
        cout << B[i-1] + abs(A[i-1] - A[i+1]) + B[N] - B[i+1] + abs(A[N])<< endl;
    cout << B[N-1] + abs(A[N-1]) << endl;

    return 0;
}

Measured memory_bytes: 2816
def poison():
    sum = input()
    sum = sum.split()
    for i in range(3):
        sum[i] = int(sum[i])
        if 0 > sum[i] or sum[i] > 10 ** 9:
            return print("error")

    notPoison = sum[0] + sum[1]
    if (notPoison + 1) >= sum[2]:
        sum[1] += sum[2]
    else:
        sum[1] += notPoison + 1
    return print(sum[1])


poison()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
const string tr="abcdefghijklmnopqrstuvwxyz";
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll i = 2; i < MAX; 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;}}
long long COM(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll llpow(ll n,ll i){ll cnt=n;  for(ll j=0;j<i-1;j++){n*=cnt;}return n;}
bool ip/*is_prime*/(long long N) {if (N == 1) return false;for (long long i = 2; i * i <= N; ++i) {if (N % i == 0) return false;}return true;}
int digit(ll N) {int ans = 0;while (N) {++ans;N /= 10;}return ans;}
vector<pair<ll,ll>> pf/*prime_factorize*/(ll n){vector<pair<ll,ll>> res;for(ll a=2;a*a<=n;a++){if(n%a!=0) continue;ll ex=0;while(n%a==0){ex++;n/=a;}res.pb({a,ex});}if(n!=1) res.pb({n,1});return res;}
vector<ll> div/*divisor*/(ll n){  vector<ll> res={1};for(ll a=2;a*a<=n;a++){if(n%a!=0) continue;ll b=n/a;res.pb(b);if(b!=a) res.pb(a);}sort(all(res));return res;}

int main(){
  ll n,k;
  cin>>n>>k;
  v(ll) a(n);
  rep(i,n) cin>>a[i];
  rep(i,n-k){
    if(a[i+k]>a[i]) yn;
  }
}


Measured memory_bytes: 4824
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;

int main() {
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	if (a > w / 2 || b > h / 2) {
		cout << -1;
		return 0;
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (i % 2 == 0) {
				if (j < a)
					cout << '0';
				else
					cout << '1';
			}
			else {
				if ((i + 1) / 2 <= b) {
					if (j < a)
						cout << '1';
					else
						cout << '0';
				}
				else {
					if (j < a)
						cout << '0';
					else
						cout << '1';
				}
			}			
		}
		cout << '\n';
	}	
}


Measured memory_bytes: 1280
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    System.out.println(n*n*n);
  }
}

Measured memory_bytes: 21076
import sys
input=sys.stdin.readline
n,m=map(int,input().split())
kagi=[[]for _ in range(m)]
for _ in range(m):
    a,b=map(int,input().split())
    c=list(map(int,input().split()))
    kagi[_].append(a)
    kagi[_].append(c)

dp=[10**7 for _ in  range(2**n)]
dp[0]=0
for i in range(2**n):
    for j in range(m):
        l=kagi[j][1]
        ni=0
        for k in l:
            ni+=2**(k-1)
        dp[ni|i]=min(dp[ni|i],dp[i]+kagi[j][0])

if dp[-1]==10**7:
    print(-1)
else:
    print(dp[-1])


Measured memory_bytes: 43372
while True:
  H, W = map(int, input().split())
  if(H==0 and W==0):
    break
  for i in range(H):
    if i == 0:
      print("#"*W)
    elif i == H-1:
      print("#"*W)
    else:
      print("#"+"."*(W-2)+"#")

  print()



Measured memory_bytes: 5616
#include<iostream>
using namespace std;
int main (void){

    int n,y,m,yy,mm,a,b;

    cin >> n;

    a = n / 100;
    b = n % 100;

    if(0 < a && a < 13)
    m = 1,y = 0;
    else
    y = 1,m = 0;

    if(0 < b && b < 13 )
    mm = 1,yy = 0;
    else
    yy = 1,mm = 0;

    if(y == 1 && mm == 1)
    cout << "YYMM" << endl;
        
    else if(m == 1 && yy == 1)
    cout << "MMYY" << endl;
    
    else if(m == 1 && mm == 1)
    cout << "AMBIGUOUS" << endl;
    
    else
    cout << "NA" << endl;

    return 0;
}

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

int main(){
	string a,b,c;
	cin >> a >> b >> c;
	
	int i = 1,j = 0, k = 0;
	
	char t = a[0];
	while(i<=a.size()&&j<=b.size()&&k<=c.size()){
		if(t=='a'){
			if(i==a.size()){
				cout << "A";
				return 0;
			}
			t = a[i++];
		}
		else if(t=='b'){
			if(j==b.size()){
				cout << "B";
				return 0;
			}
			t = b[j++];
		}
		else{
			if(k==c.size()){
				cout << "C";
				return 0;
			}
			t = c[k++];
		}
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef vector<vector<int>> UnWeightedGraph;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;
template< typename G >
struct StronglyConnectedComponents {
  const G &g;
  UnWeightedGraph gg, rg;
  vector< int > comp, order, used;

  StronglyConnectedComponents(G &g) : g(g), gg(g.size()), rg(g.size()), comp(g.size(), -1), used(g.size()) {
    for(int i = 0; i < g.size(); i++) {
      for(auto e : g[i]) {
        gg[i].emplace_back((int) e);
        rg[(int) e].emplace_back(i);
      }
    }
  }

  int operator[](int k) {
    return (comp[k]);
  }

  void dfs(int idx) {
    if(used[idx]) return;
    used[idx] = true;
    for(int to : gg[idx]) dfs(to);
    order.push_back(idx);
  }

  void rdfs(int idx, int cnt) {
    if(comp[idx] != -1) return;
    comp[idx] = cnt;
    for(int to : rg[idx]) rdfs(to, cnt);
  }

  void build(UnWeightedGraph &t) {
    for(int i = 0; i < gg.size(); i++) dfs(i);
    reverse(begin(order), end(order));
    int ptr = 0;
    for(int i : order) if(comp[i] == -1) rdfs(i, ptr), ptr++;

    t.resize(ptr);
    for(int i = 0; i < g.size(); i++) {
      for(auto &to : g[i]) {
        int x = comp[i], y = comp[to];
        if(x == y) continue;
        t[x].push_back(y);
      }
    }
  }
};

vector<ll> dp[2];
vector<int> visited;
UnWeightedGraph t;
bool Root[1001];

void dfs(int now) {
    if(visited[now]) return;
    visited[now] = 1;
    sort(t[now].begin(), t[now].end());
    t[now].erase(unique(t[now].begin(), t[now].end()), t[now].end());
    dp[1][now] = 1;
    dp[0][now] = 1;
    for(auto to : t[now]) {
        Root[to] = false;
        dfs(to);
        dp[1][now] *= (dp[0][to] + dp[1][to]);
        dp[1][now] %= mod;
    }
}


int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    dp[0].resize(N);
    dp[1].resize(N);
    visited.resize(N);
    UnWeightedGraph g(N);
    for(int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[b].push_back(a);
    }
    StronglyConnectedComponents<UnWeightedGraph> SCC(g);
    SCC.build(t);
    for(int i = 0; i < t.size(); i++) {
        Root[i] = true;
    }
    for(int i = 0; i < t.size(); i++) {
        dfs(i);
    }
    ll ans = 1;
    for(int i = 0; i < t.size(); i++) {
        if(Root[i]) {
            ans *= (dp[0][i] + dp[1][i]);
            ans %= mod;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3412
#define __LOCAL_DEBUG__
#include<bits/stdc++.h>
using namespace std;
#ifdef __LOCAL_DEBUG__
# define _debug(x) { cerr << "\033[94m" << __func__ << " " << #x << ": " << (x) << "\n\033[0m"; }
#else
# define _debug(x) {((void) 0);}
#endif
#define rep(i, n) for (int i = (0); i < (n); i++)
#define repp(i, a, b) for (int i = (a); i < (b); i++)
#define CLR(x, v) memset(x, v, sizeof (x))
#define all(x) x.begin(), x.end()
#define SZ(x) (int) x.size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
using ll = signed long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int MAXN = 700;

const int N = 100005;

// #define __LOCAL_DEBUG__
char s[10];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    scanf("%s",s);
    puts(s[2] == s[3] && s[4] == s[5] ? "Yes" : "No");
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>

int main() {
	//C
	int n = 0;

	std::cin >> n;
	std::set<std::string> items;
	for (int i = 0; i < n; ++i) {
		std::string tmp;
		std::cin >> tmp;
		items.insert(tmp);
	}

	std::cout << items.size() << std::endl;

	return 0;


}

Measured memory_bytes: 19228
input_data=input().split()

P=int(input_data[0])
Q=int(input_data[1])
R=int(input_data[2])

abc = P+Q
acb = R+Q
bac = P+R
bca = Q+R
cab = R+P
cba = Q+P

answer=min(abc,acb,bac,bca,cab,cba)
print(answer)

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

int main(){
  int N;
  cin >> N;
  vector<long> A(N);
  for(int i=0; i<N; i++) cin >> A[i];
  long long money=1000;
  long long kabu=0;
  for(int i=0; i<N; i++){
    //N日目は売却
    //それ以外は、上がるなら買う、下がるなら売る
    if(i==N-1){
      money+=kabu*A[i];
      kabu=0;
    }else{
      if(A[i]<A[i+1]){
        long newkabu=money/A[i];
        money-=newkabu*A[i];
        kabu+=newkabu;
      }else if(A[i]>A[i+1]){
        money+=kabu*A[i];
        kabu=0;
      }
    }
  }
  cout << money << endl;
}

Measured memory_bytes: 3620
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
#define N 1010
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
int n,a[N][N],t,ok[N][N],q,cnt;
int c[N];
vector<int> vec[4];
int main(){
	n=read();
	q=n*n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n-1;j++){
			a[i][j]=read();
		}
	}
	for(int i=1;i<=n;i++){
		vec[0].push_back(i);
	}
	while(q){
		if(vec[t&1].empty()){
			cout<<-1<<endl;
			return 0;
		}
		for(int i=0;i<vec[t&1].size();i++){
			int p=vec[t&1][i];
			c[p]++;
			q--;
			if(c[p]==n)continue;
			int s=a[p][c[p]];
			ok[s][p]=1;
			if(ok[p][s]){
				vec[(t+1)&1].push_back(p);
				vec[(t+1)&1].push_back(s);
				ok[s][p]=0;
				ok[p][s]=0;
			}
		}
		vec[t&1].clear();
		t++;
	}
	cout<<t-1<<endl;
	return 0;
}


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

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

    int n, m;
    cin >> n >> m;
    
    vector<pair<int, int>> Ng(m);
    for(int i = 0; i < m; i++){
        cin >> Ng[i].second >> Ng[i].first;
    }

    sort(Ng.begin(), Ng.end());

    int ans = 0, right = -1;
    for(int i = 0; i < m; i++){
        if(right < Ng[i].second){
            ans++;
            right = Ng[i].first - 1;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i > 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << (c - (a - b) >= 0 ? c - (a - b) : 0) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <unordered_map>
#include <list>
#include <string>
#include <limits.h>
#include <set>
using namespace std;
#define ll long long int


int main(){
	int N;
	cin>>N;
	int i,j,k;
	vector<pair<long long int,long long int>> v(N);
	for(i=0;i<N;i++){
		long long int x,y;
		cin>>x>>y;
		v[i]=make_pair(x,y);
	}

	long long int res=0;
	res+=(v[0].first+v[0].second);
	for(i=1;i<N;i++){
		if(v[i].first<v[i-1].first||v[i].second<v[i-1].second){
			long long int a=v[i-1].first/v[i].first;
			long long int b=v[i-1].second/v[i].second;
			if(v[i-1].first%v[i].first!=0&&v[i-1].first>v[i].first) a++;
			if(v[i-1].second%v[i].second!=0&&v[i-1].second>v[i].second) b++;
			a=max(a,b);
			v[i].first*=a;
			v[i].second*=a;
		}
	}
	res=v.back().first+v.back().second;
	cout<<res<<endl;
	return 0;
}





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

int main(){
  cin >> S;
  int saisyo = 0;
  int saigo = 0;
  
  for(int i = 0; i < S.size() ; i++){
    if(S[i] == 'A'){
      saisyo = i;
      break;
    }
  }
  for(int i = 0; i < S.size() ; i++){
    if(S[i] == 'Z') saigo = i;
  }
  
  cout << saigo - saisyo + 1 << endl;
}

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

int main()
{
  string s;
  int ans = 0;

  cin >> s;
  for (int i = 0; i < s.size() / 2; i++)
  {
    if (s[i] != s[s.size() - i - 1])
      ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, S: "List[str]"):
    dic = {}
    for s in S:
        if s in dic:
            dic[s] += 1
        else:
            dic[s] = 1
    mx = max(dic.values())
    max_str = []
    for k in dic:
        if dic[k] == mx:
            max_str.append(k)
    max_str.sort()
    for s in max_str:
        print(s)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = [next(tokens) for _ in range(N)]  # type: "List[str]"
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 35232
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[n];
		boolean[] s = new boolean[n];
		for (int i = 0; i < n; i++) {
			a[i] = 0;
			s[i] = false;
		}
		for (int i = 0; i < m; i++) {
			int p = sc.nextInt()-1;
			String S = sc.next();
			if(S.equals("WA")) {
				if(!s[p]) a[p]++;
			}else {
				s[p] = true;
			}
		}
		int count = 0;
		int count2 = 0;
		for (int i = 0; i < n; i++) {
			if(s[i]) {
				count++;
				count2 += a[i];
			}
		}
		System.out.printf("%d %d",count, count2);
		sc.close();
	}
}

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

 using namespace std;
 typedef long long ll;

 int main() {
   vector<int> count(4);

   for (int i = 0; i < 6; i++) {
     int tmp;
     cin >> tmp;
     count.at(tmp - 1)++;
   }

   sort(count.begin(), count.end());

   vector<int> cor = {1, 1, 2, 2};

   if (count == cor) cout << "YES" << endl;
   else cout << "NO" << endl;
  }


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

ll dp[3030][3030];
int N; 
ll A[3030];
ll INF=LLONG_MAX/2;

ll solve(int l,int r){
  if(dp[l][r]!=INF) return dp[l][r];
  if(l==r) return (dp[l][r]=(N%2?1:-1)*A[l]);
  if(N%2!=(r-l)%2){
    ll L=solve(l+1,r)+A[l];
    ll R=solve(l,r-1)+A[r];
    return (dp[l][r]=max(L,R));
  }else{
    ll L=solve(l+1,r)-A[l];
    ll R=solve(l,r-1)-A[r];
    return (dp[l][r]=min(L,R));
  }
}

int main(){
  rep(i,3030) rep(j,3030) dp[i][j]=INF;
  cin>>N;
  rep(i,N) cin>>A[i];
  solve(0,N-1);
  cout<<dp[0][N-1]<<endl;
  return 0;
}


Measured memory_bytes: 72192
<?php

ini_set('error_reporting', E_ALL & ~E_NOTICE & ~E_WARNING);
ini_set('display_errors', 'Off');

// define('DEBUG', true);
define('DEBUG', false);

fscanf(STDIN, "%d %d %d %d %d", $N, $A, $B, $C, $D);
$diff = abs($A - $B);
$N--;

$tMIN = min($C, $D) - max($C, $D);
$tMAX = max($C, $D) - min($C, $D);

if (DEBUG) echo $tMIN . " " . $tMAX . PHP_EOL;
// exit;

for ($i = 0; $i <= $N; $i += 2) {
    // printf ("%d %d\n", $N - $i, $i);

    $a = $N - $i;
    $b = $i;
    $mmin1 = $a * $C;
    $mmax1 = $a * $D;
    $mmin2 = $b * $tMIN / 2;
    $mmax2 = $b * $tMAX / 2;
    $mminALL = $mmin1 + $mmin2;
    $mmaxALL = $mmax1 + $mmax2;

    if (DEBUG) echo $a . " " . $b . " $mminALL -- $mmaxALL | $diff \n";

    if (abs($A - $B) >=  $mminALL && abs($A - $B) <= $mmaxALL) {
        echo "YES\n";
        exit;
    }
 
}

echo "NO\n";


Measured memory_bytes: 4728
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
	int max = Math.max(Math.max(A,B),C);
	int min = Math.min(Math.min(A,B),C);
    int m = A+B+C-max-min;

    System.out.println((m-min)+(max-m));
    }
}

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

int n, a, b, c, ans = 1000000000;
int l[10];

void dfs(int m, int x, int y, int z, int mp) {
	if (m == n) {
		if (x == 0 || y == 0 || z == 0) return;
		ans = min(ans, abs(x - a) + abs(y - b) + abs(z - c) + mp - 30);
		return;
	}
	dfs(m + 1, x + l[m], y, z, mp + 10);
	dfs(m + 1, x, y + l[m], z, mp + 10);
	dfs(m + 1, x, y, z + l[m], mp + 10);
	dfs(m + 1, x, y, z, mp);
}

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

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

 
int main() {
   int n;
   cin>>n;
   int A[n],B[n],C[n-1];
   rep(i,n)cin>>A[i];
   rep(i,n)cin>>B[i];
   rep(i,n-1)cin>>C[i];

   int ans=0;
   rep(i,n)ans+=B[i];

   rep(i,n-1){
       if(A[i+1]-A[i]==1)ans+=C[A[i]-1];
   }

   cout<<ans<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        var A = cin.scanint;
        WriteLine(A[0] - A[1] + 1);
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define dofloat cout<<fixed<<setprecision(8)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define bitcount __builtin_popcount
#define all(vec) vec.begin(),vec.end()
#define rall(vec) vec.rbegin(),vec.rend()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vll;
typedef vector<pair<int,int> > vii;
typedef vector<int> vi;
typedef pair<int,int> ii;
const long long MOD=1000000007;
const long long MAX=100005;
const long double PI=3.14159265359;
const long double G=9.807;
const long long INF=1e18;
const long double EPS=1e-6;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
bool isprime(ll a){
  if(a==2)return 1;
  if(!(a&1))return 0;
  for(ll i=3;i*i<=a;i+=2)
    if(a%i==0)return 0;
  return 1;
}
ll mpow(ll base,ll exponent,ll modulus){
  if(modulus==1)return 0;
  long long result = 1;
  base=base%modulus;
  while(exponent){
    if(exponent%2 == 1)
    result=(result*base)%modulus;
    exponent=exponent>>1;
    base=(base*base)%modulus;
  }
  return result;
}
ll minv(ll a,ll mod){
  ll _gcd=gcd(a,mod);
  assert(_gcd==1);
  return mpow(a,mod-2,mod);
}


/*
ll ncr(ll N,ll K){
  if(N<K)return 0;
  if(K==0)return 1;
  if(N==0)return 0;

  ll den=1;
  for(ll i=1;i<=K;i++)den*=i;
  ll num=1;
  while(K--){
    num*=N;
    if(num%den==0){
      num/=den;
      den=1;
    }
    N--;
  }

  return num;
}
*/
ll n,m;
ll a[MAX];
int main(){FAST;
cin>>n>>m;
ll L = 1;
for(int i=1;i<=n;++i){

}
for(int i=1;i<=n;++i){
  cin>>a[i];
  ll foo = L;
  ll bar = a[i]/2;
  ll g = gcd(foo,bar);
  if(foo/g>m/bar){
    cout<<0;
    return 0;
  }
  L = foo/g*bar;
}
for(int i=1;i<=n;++i){
  if(L%a[i] == 0){
    cout<<0;
    return 0;
  }
}
cout<<(m/L+1)/2;
return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
int main() {
  int N, ac, wa, tle, re;
  cin >> N;
  ac = 0;
  wa = 0;
  tle = 0;
  re = 0;
  for (int i = 0; i < N; i++){
    string S;
    cin >> S;
    if(S == "AC") ac++;
    else if(S == "WA") wa++;
    else if(S == "TLE") tle++;
    else if(S == "RE") re++;
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1<<30;
  
int main(){
  ll n;cin>>n;
  ll ans=n;
  for(ll i=2;i<=sqrt((ll)n);i++){
    if(n%i==0){ans=min(ans, max(i, n/i));}
  }
  int t=0;
  while(ans!=0){
  	ans/=10;
    t++;
  }
  cout<<t<<endl;
}


Measured memory_bytes: 384
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

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

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

fn game(x: usize, y: usize, turn: usize, cache: &mut Vec<Vec<Vec<usize>>>) -> usize {
    if cache[turn][x][y] != 0 {
        return cache[turn][x][y];
    }

    for i in 1..x {
        if i * 2 > x {
            break;
        }
        let r = game(x - i * 2, y + i, 3 - turn, cache);
        if r == turn {
            cache[turn][x][y] = turn;
            return turn;
        }
    }

    for i in 1..y {
        if i * 2 > y {
            break;
        }
        let r = game(x + i, y - i * 2, 3 - turn, cache);
        if r == turn {
            cache[turn][x][y] = turn;
            return turn;
        }
    }


    cache[turn][x][y] = 3 - turn;
    3 - turn
}

fn main() {
    input! {
        n: usize,
        mut p: [usize; n],
    }

    let mut ans = 0;
    for i in 0..n-1 {
        if p[i] == i+1 && p[i+1] == i+2 {
            let t = p[i];
            p[i] = p[i+1];
            p[i+1] = t;
            ans +=1;
        }
    }

    for i in 0..n {
        if p[i] == i+1 {
            let n = if i == n-1 { i-1} else {i+1};
            let t = p[i];
            p[i] = p[n];
            p[n] = t;
            ans +=1;
        }
    }
    print!("{}", ans);
}


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

int main(){
  int p, q, r;
  cin >> p >> q >> r;
  cout << min(p+q,min(q+r,p+r)) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int H, W;
	cin >> H >> W;

	string board[H];
	for (int i = 0; i < H; i++)
		cin >> board[i];

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

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (board[i][j] == '#')
				continue;
			int sum = 0;
			for (int d = 0; d < 8; d++) {
				int ni = i + dx[d], nj = j + dy[d];
				if (ni < 0 or H <= ni)
					continue;
				if (nj < 0 or W <= nj)
					continue;
				if (board[ni][nj] == '#')
					sum++;
			}
			board[i][j] = char(sum + '0');
		}
	}

	for (int i = 0; i < H; i++)
		cout << board[i] << endl;

	return 0;
}


Measured memory_bytes: 256