akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")
#define deg_to_rad(deg) (((deg)/360)*2*M_PI)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(T x,T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> T modinv(T x,const T mod){return modpow(x,mod-2,mod);}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> T deg2rad(T deg) {return deg*2*M_PI/360;}
template<class T> T rad2deg(T rad) {return rad*360/(2*M_PI);}

typedef long long ll;
typedef pair<ll, ll> P;

const ll MOD=1e9+7;
const ll MAX=5e6;

int main() {
  double a,b,x;cin>>a>>b>>x;

  // 3角形
  if (a*a*b/2>=x) {
    double c = x*2/(a*b);
    printf("%.7f",rad2deg(atan2(b,c)));
  } else {
    double c = x*2/(a*a)-b;
    printf("%.7f",rad2deg(atan2(b-c,a)));
  }

  return 0;
}

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

int main() {
  int N; cin >> N;
  vector<int> C(N), S(N), F(N); for (int i = 1; i < N; i++) cin >> C[i] >> S[i] >> F[i];

  for (int i = 1; i < N; i++) {
    int x = S[i] + C[i];
    for (int j = i + 1; j < N; j++) {
      if (x <= S[j]) x = S[j];
      else if (x % F[j]) x += F[j] - x % F[j];
      x += C[j];
    }
    cout << x << endl;
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define ALL(c) (c).begin(), (c).end()
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    if (s[3] == s[2] && s[5] == s[4])
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    
    
}




Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    double c, b=0,a[500];
    int i,n;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
    scanf("%lf",&a[i]);
    b=b+1/a[i];
    }
    c=1/b;
    printf("%lf",c);
    return 0;

}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
ll n;
ll a[3],b[3];
ll dp[25000001];
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	rep(i,3)
	cin>>a[i];
	rep(i,3)
	cin>>b[i];
	
	rep(i,n+1){
		rep(j,3){
			if(i+a[j]<=n){
				dp[i+a[j]]=max(dp[i+a[j]],dp[i]+b[j]);
			}
		}
	}
	ll mx=0;
	rep(i,n+1){
		mx=max(mx,dp[i]+n-i);
	}
	zero(dp);
	rep(i,mx+1){
		rep(j,3){
			if(i+b[j]<=mx){
				dp[i+b[j]]=max(dp[i+b[j]],dp[i]+a[j]);
			}
		}
	}
	ll res=0;
	rep(i,mx+1){
		res=max(res,dp[i]+mx-i);
	}
	cout<<res;
	re 0;
}

Measured memory_bytes: 195584
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<cmath>
#include<cstdio>
#include<vector>
#include<climits>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
int read(){
	int f=1,x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return f*x;
}
#define MAXN 100000
#define INF 0x3f3f3f3f
int h[MAXN+5];
int main(){
	int n=read(),k=read(),ans=INF;
	for(int i=1;i<=n;i++)
		h[i]=read();
	sort(h+1,h+n+1);
	for(int i=k;i<=n;i++)
		ans=min(ans,h[i]-h[i-k+1]);
	printf("%d\n",ans);
	return 0;
}

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

int main(){
    //input
    int N;
    cin >> N;
    set<int> dan;
    int d,i;
    for(i=1; i<=N; i++){
        cin >> d;
        dan.insert(d);
    }

    //output
    cout << dan.size() << endl;
    system("pause");
    return 0;
}

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

const int MAXN = 2005;

int n, k, q;

int a[MAXN];
int dx[MAXN], top = 0;

void work(int L, int R)
{
	if (L > R) return;
	static int stk[MAXN];
	int stk_top = 0, len = R-L+1;
	for (int i = L; i <= R; i++) stk[++stk_top] = a[i];
	sort(stk+1, stk+stk_top+1);
	for (int i = 1; i <= len-k+1; i++)
		dx[++top] = stk[i];
}

int main()
{
	scanf("%d%d%d", &n, &k, &q);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	int ans = 1e9;
	for (int i = 1; i <= n; i++) {
		int last = 0;
		top = 0;
		for (int j = 1; j <= n; j++) {
			if (a[j] < a[i]) {
				work(last+1, j-1);
				last = j;
			}
		}
		work(last+1, n);
		sort(dx+1, dx+top+1);
		if (top >= q) ans = min(ans, dx[q]-dx[1]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

typedef struct {
    char color;
    int val;
} CARD;

#define swap(a, b)                                                             \
    {                                                                          \
        CARD t = a;                                                            \
        a = b;                                                                 \
        b = t;                                                                 \
    }

void select_sort(CARD A[], int N) {
    for (int i = 0; i < N; i++) {
        int minj = i;
        for (int j = i + 1; j < N; j++) {
            if (A[j].val < A[minj].val) {
                minj = j;
            }
        }
        if (minj != i) {
            swap(A[minj], A[i]);
        }
    }
}

void bubble_sort(CARD A[], int N) {
    for (int i = 0; i < N; i++) {
        for (int j = N - 1; j > i; j--) {
            if (A[j - 1].val > A[j].val) {
                swap(A[j - 1], A[j]);
            }
        }
    }
}

void print_array(CARD A[], int N) {
    for (int i = 0; i < N; i++) {
        printf("%c%d%c", A[i].color, A[i].val, i == N - 1 ? '\n' : ' ');
    }
}

int main() {
    int N;
    CARD A[100], B[100];
    char buf[100];
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%s", buf);
        A[i].color = buf[0];
        A[i].val = buf[1] - '0';
        B[i] = A[i];
    }
    bubble_sort(A, N);
    select_sort(B, N);
    print_array(A, N);
    printf("Stable\n");
    print_array(B, N);
    bool b = true;
    for (int i = 0; i < N; i++) {
        if (A[i].val != B[i].val || A[i].color != B[i].color) {
            b = false;
            break;
        }
    }
    if (b) {
        printf("Stable\n");
    } else {
        printf("Not stable\n");
    }
    return 0;
}



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

// begin fast read template by CYJian (source: https://www.luogu.com.cn/paste/i11c3ppx)

namespace io {
	const int __SIZE = (1 << 21) + 1;
	char ibuf[__SIZE], *iS, *iT, obuf[__SIZE], *oS = obuf, *oT = oS + __SIZE - 1, __c, qu[55]; int __f, qr, _eof;
	#define Gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush () { fwrite (obuf, 1, oS - obuf, stdout), oS = obuf; }
	inline void gc (char &x) { x = Gc(); }
	inline void pc (char x) { *oS ++ = x; if (oS == oT) flush (); }
	inline void pstr (const char *s) { int __len = strlen(s); for (__f = 0; __f < __len; ++__f) pc (s[__f]); }
	inline void gstr (char *s) { for(__c = Gc(); __c < 32 || __c > 126 || __c == ' ';)  __c = Gc();
		for(; __c > 31 && __c < 127 && __c != ' '; ++s, __c = Gc()) *s = __c; *s = 0; }
	template <class I> inline bool gi (I &x) { _eof = 0;
		for (__f = 1, __c = Gc(); (__c < '0' || __c > '9') && !_eof; __c = Gc()) { if (__c == '-') __f = -1; _eof |= __c == EOF; }
		for (x = 0; __c <= '9' && __c >= '0' && !_eof; __c = Gc()) x = x * 10 + (__c & 15), _eof |= __c == EOF; x *= __f; return !_eof; }
	template <class I> inline void print (I x) { if (!x) pc ('0'); if (x < 0) pc ('-'), x = -x;
		while (x) qu[++ qr] = x % 10 + '0',  x /= 10; while (qr) pc (qu[qr --]); }
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
} using io::pc; using io::gc; using io::pstr; using io::gstr; using io::gi; using io::print;

// end fast read template by CYJian

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair
 
using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int s, w; gi(s), gi(w);
	if(w >= s) pstr("unsafe\n");
	else pstr("safe\n");
}


Measured memory_bytes: 3612
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000007;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int N;
	cin >> N;

	vector<Int> x(N);
	for (Int i = 0; i < N; i++) {
		cin >> x[i];
	}

	vector<Int> temp(N);
	temp = x;
	sort(temp.begin(), temp.end());

	Int temp_M = temp[N / 2];

	for (Int i = 0; i < N; i++) {
		if (x[i] >= temp_M) {
			cout << temp[N / 2 - 1] << endl;
		}
		else {
			cout << temp_M << endl;
		}
	}

}

Measured memory_bytes: 5376
#include <iostream>

using namespace std;

int main(){

	int n,max=0;
	int s[101]={0};
	while(cin>>n){
		s[n]++;
	}
	for(int i=0;i<101;i++){
		if(max<s[i])
			max=s[i];
	}
	for(int i=0;i<101;i++){
		if(max==s[i])
			cout<<i<<endl;
	}
	
}

Measured memory_bytes: 1160
/*---------------Go Code GO---------------*/

#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;

template<typename T>
using Order_Set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
//(order) Set.order_of_key(); (pointer) Set.find_by_order();

#define     PI              acos(-1.0)
#define     O_O             ios_base::sync_with_stdio(false); cin.tie(NULL)
#define     precision(a)    fixed<<setprecision(a)
#define     endl            '\n'
#define     Flush           cout<<flush
#define     LLMX            0x3fffffffffffffff




int main()
{
    long long i,j,k,l,tst=0,ans=0, csno=0;
    cin>>k;
    double res = 2*k*PI;
    cout<<precision(10)<<res<<endl;

    return 0;
}


Measured memory_bytes: 3772
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
const long long INF = 1LL << 60;

int main() {
	ll L, R;
	cin >> L >> R;

	if (L <= 2019 && 2019 <= R) {
		cout << 0 << endl;
		return 0;
	}


	ll num1 = 2020;
	int time1 = 2020;
	for (ll i = L; i <= R-1; i++) {
		int time2 = 2020;
		for (ll j = i + 1; j <= R; j++) {
			ll now = (i*j) % 2019;
			num1 = min(num1, now);
			time2--;
			if (time2 == 0) {
				break;
			}
		}
		time1--;
		if (time1 == 0) {
			break;
		}
	}
	cout << num1 << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define N 100009
#define M 20000009
using namespace std;

int n,m,cnt,trtot,rt,a[N],b[N],lf[N],rg[N],ls[M],rs[M],tg[M];
ll ans=1ll<<60,f[N];
void mdy(int &k,int x){
	if (!k) k=++trtot; tg[k]=x;
}
void pushdn(int k){
	if (tg[k]){
		mdy(ls[k],tg[k]); mdy(rs[k],tg[k]);
		tg[k]=0;
	}
}
void mdy(int &k,int l,int r,int x,int y,int z){
	if (!k) k=++trtot;
	if (x<=l && r<=y){
		mdy(k,z); return;
	}
	int mid=l+r>>1;
	pushdn(k);
	if (x<=mid) mdy(ls[k],l,mid,x,y,z);
	if (y>mid) mdy(rs[k],mid+1,r,x,y,z);
}
int qry(int k,int l,int r,int x){
	if (tg[k] || l==r) return tg[k];
	int mid=l+r>>1;
	pushdn(k);
	return x<=mid?qry(ls[k],l,mid,x):qry(rs[k],mid+1,r,x); 
}
int calc(int x,int y,int z){
	if (x<=z && z<=y) return 0;
	return (x-z+m)%m;
}
void solve(int k,int l,int r){
	if (tg[k]){
		ans=min(ans,f[tg[k]]+(tg[k]>cnt?0:calc(l,r,rg[tg[k]]))); return;
	}
	if (!k || l==r) return;
	int mid=l+r>>1;
	pushdn(k);
	solve(ls[k],l,mid); solve(rs[k],mid+1,r);
}
int main(){
	scanf("%d%d",&n,&m);
	int i,x,y; ll res=0,tx=0;
	for (i=1; i<=n; i++){
		scanf("%d%d",&x,&y); x<<=1;
		res+=x; tx+=x;
		if (y==1){
			if (x>m){
				puts("-1"); return 0;
			}
			if (!x) continue;
			a[++cnt]=tx%m; b[cnt]=x%m; tx=0;
		}
	}
	for (i=1,tx=0; i<=cnt; i++){
		lf[i]=(a[i]+tx)%m; rg[i]=(a[i]-b[i]+m+tx)%m;
		tx=(tx+a[i])%m;
	}
	mdy(rt,cnt+1);
	for (i=cnt; i; i--){
		x=qry(rt,0,m-1,rg[i]);
		f[i]=(x>cnt?0:f[x]+(rg[i]-rg[x]+m)%m);
		if (lf[i]<=rg[i]){
			if (lf[i]) mdy(rt,0,m-1,0,lf[i]-1,i);
			if (rg[i]<m-1) mdy(rt,0,m-1,rg[i]+1,m-1,i);
		} else
			mdy(rt,0,m-1,rg[i]+1,lf[i]-1,i);
	}
	solve(rt,0,m-1);
	printf("%lld\n",res+ans);
	return 0;
}


Measured memory_bytes: 40320
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define inf 1000000007

ll N,K;
vector<ll>x;

ll calc(ll left, ll right){
    if (left >= 0){
        return right;
    }
    else if(right <= 0){
        return abs(left);
    }
    else{
        return abs(right)+abs(left)+min(abs(left),abs(right));
    }
}

int main() {
    scanf("%lld%lld",&N,&K);
    rep(i,N){
        ll temp; scanf("%lld",&temp);
        x.push_back(temp);
    }
    ll ans = inf;
    rep(i,N-K+1){
        ll left = x[i];
        ll right = x[i+K-1];
        ans = min(ans,calc(left,right));
    }
    cout << ans << endl;
    
    
    return 0;
}


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

int main(){
  int A,B,C,D;
    cin >> A >> B >> C >> D;
  if(A + B > C + D){
    cout << "Left" << endl;
  }
  else if(A + B == C + D){
    cout << "Balanced" << endl;
  }
  else{
    cout << "Right" << endl;
  }
}

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

using namespace std;
using ll = long long int;
const int MOD = 1e9 + 7;

array<int, 2> solve (int a[], int l, int r, int bit)
{
	if (bit == -1) return {0, 0};
	if ((a[r] & (1 << bit)) == 0) return solve(a, l, r, bit-1);
	if (a[l] & (1 << bit))
	{
		auto rt = solve(a, l, r, bit-1);
		return {rt[0], rt[1]+(1<<bit)};
	}
	int mid = l;
	for (int i = l; i <= r; ++i)
	{
		if (((1 << bit) & a[i]) == 0)
			mid = i;
	}
	auto r1 = solve(a, l, mid, bit-1);
	auto r2 = solve(a, mid+1, r, bit-1);
	if (r1[0] < r2[0]) return {r1[0]+(1<<bit), r1[0]+(1<<bit)};
	else return {r2[0]+(1<<bit), r2[1]};
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	ll tot = 0;
	map<string, int> cost;
	for (int i = 0; i < n; ++i)
	{
		string s; cin >> s;
		int t; cin >> t;
		tot += t;
		cost[s] = tot;
	}
	string s; cin >> s;
	cout << tot - cost[s];
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = [int(i) for i in input().split() if int(i) % 2 == 0]
    if all(a % 3 == 0 or a % 5 == 0 for a in A):
        print("APPROVED")
    else:
        print("DENIED")


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

//ここから

ll n;
vector<ll>a;

template< typename T >
vector< T > convert_base(T x, T b) {
  vector< T > ret;
  T t = 1, k = abs(b);
  while(x) {
    ret.emplace_back((x * t) % k);
    if(ret.back() < 0) ret.back() += k;
    x -= ret.back() * t;
    x /= k;
    t *= b / k;
  }
  if(ret.empty()) ret.emplace_back(0);
  reverse(begin(ret), end(ret));
  return ret;
}
//桁DP
ll digit_dp(ll k){
  ll dp[45][2];//kはbitが立っているか確かめるだけ
  memset(dp,0,sizeof(dp));
  rep(i,45)dp[i][1]=-1;
  rep(i,40){
    ll bit=1LL<<(39-i);
    ll cnt=0;
    rep(j,n){
      if(bit&a[j])++cnt;
    }
    //演算を可換にする.
    if(k&bit)chmax(dp[i+1][1],dp[i][0]+cnt*bit);//Kより真に小さくなる
    if(dp[i][1]>-1)chmax(dp[i+1][1],dp[i][1]+max(n-cnt,cnt)*bit);
    if(!(k&bit))chmax(dp[i+1][0],dp[i][0]+cnt*bit);
    else chmax(dp[i+1][0],dp[i][0]+max(n-cnt,cnt)*bit);
	}
  ll ans=max(dp[40][0],dp[40][1]);
  return ans;
}


void solve(){
  ll k;
  cin>>n>>k;
  a.resize(n);
  rep(i,n)cin>>a[i];
  if(k)cout<<digit_dp(k);
  else {
    ll sum=0;
    rep(i,n)sum+=a[i];
    cout<<sum;
  }
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


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

int linearsearch(int A[], int n, int key){
    int i = 0;
    A[n] = key;
    while (A[i] != key) i++;
    return i != n;
}

int main() {
    int i, n, A[10000+1], q, key, sum = 0;

    scanf("%d", &n);
    for (i = 0; i < n; i++) scanf("%d", &A[i]);

    scanf("%d", &q);
    for (i = 0; i < q; i++){
        scanf("%d", &key);
        if (linearsearch(A, n, key)) sum++;
    }
    printf("%d\n", sum);

    return 0;

}

Measured memory_bytes: 3240
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

int main(void) {
	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> B(N);
	vector<int> C(N);


	for(int i = 0; i < N; i++) cin >> A[i];
	for(int i = 0; i < N; i++) cin >> B[i];
	for(int i = 0; i < N; i++) cin >> C[i];

	sort(A.begin(), A.end());
	sort(C.begin(), C.end());

	
	/*cout << endl;
	for(int i = 0; i < N; i++) cout << A[i] << ' ';
	cout << endl;
	for(int i = 0; i < N; i++) cout << B[i] << ' ';
	cout << endl;
	for(int i = 0; i < N; i++) cout << C[i] << ' ';
	cout << endl;*/

	long long ans = 0;
	for(int i = 0; i < N; i++) {
		int left, right;
		long long tmp;
		/*Bより小さい最大のAのindexを求める*/
		left = -1; right = N;
		while(right - left > 1) {
			int mid = (left + right) / 2;
			if(A[mid] < B[i]) left = mid;
			else right = mid;
		}
		//printf("A: left=%d, right=%d\n", left, right);
		tmp = left + 1;

		
		/*Bより大きい最小のCのindexを求める*/
		left = -1; right = N;
		while(right - left > 1) {
			int mid = (left + right) / 2;
			if(B[i] < C[mid]) right = mid;
			else left = mid;
		}
		//printf("B: left=%d, right=%d\n", left, right);
		tmp *= (long long)N - right;


		ans += tmp;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1408
N=int(input())
A1=list(map(int,input().split()))
A2=list(map(int,input().split()))
max=0
tmp=0
for i in A2:
  tmp+=i
tmp+=A1[0]
max=tmp
for i in range(N-1):
  tmp=tmp-A2[i]+A1[i+1]
  if max<tmp:max=tmp
print(max)

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

#define printl(s) cout << s << endl;
#define print(s) cout << s << endl; return 0;
#define yes cout << "Yes" << endl; return 0;
#define no cout << "No" << endl; return 0;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n)+1; ++i)
using ll = long long;

const ll modseed = pow(10,9) + 7;

template <typename T>
vector<T> getValues(ll num){
    vector<T> values(num);
    for(ll i=0;i<num;i++){
        cin >> values.at(i);
    }
    return values;
}

string S;
int A,B,C,K,N,M,X,Y,cnt;

int main(){
  cin >> N >> M;
  vector<bitset<10>> switches(M);
  rep(i,M){
    int k;
    cin >> k;
    bitset<10> s;
    rep(j,k){
      int pos;
      cin >> pos;
      pos--;
      s.set(pos);
    }
    switches.at(i) = s;
  }
  auto p = getValues<int>(M);
  
  for(int i=0;i<(1<<N);i++){
    bitset<10> s(i);
    int r = 0;
    rep(j,M){
      auto v = switches.at(j) & s;
      int num = v.count();
      if(num%2==p.at(j)){
        r++;
      }
    }
    if(r==M){
      cnt++;
    }
  }
  print(cnt);
}


Measured memory_bytes: 3632
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

static const double pi = 3.141592653589793;

class CColon {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        double A, B, H, M;
        cin >> A >> B >> H >> M;

        double a = (H * 60 + M) * 360 / (12 * 60);
        double b = 360.0f / 60 * M;
        double c = abs(a - b);

        double res = sqrt(A * A + B * B - 2 * A * B * cos(c * pi/ 180));
        fcout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    CColon solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 4244
#include<stdio.h>
#define MAX 500001
void buildMaxHeap(void);
void maxHeapify(int);
int left(int);
int right(int);
void swap(int,int);
int A[MAX],H;

int main(){
  int i;
  scanf("%d",&H);
  for(i = 1; i <= H; i++){
    scanf("%d",&A[i]);
  }
  buildMaxHeap();
  for(i = 1;i <= H; i++){
    printf(" %d",A[i]);
  }
  printf("\n");

  return 0;
}

void buildMaxHeap(){
  int i;
  for(i = H/2; i >= 1; i--){
    maxHeapify(i);
  }
}

void maxHeapify(int i){
  int l,r,largest;
  l = left(i);
  r = right(i);
  if( l <= H && A[l] > A[i]) largest = l;
  else largest = i;
  if(r <= H && A[r] > A[largest]) largest = r;

  if(largest != i){
    swap(i,largest);
    maxHeapify(largest);
  }
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i + 1;
}

void swap(int i,int largest){
  int tmp;
  tmp = A[i];
  A[i] = A[largest];
  A[largest] = tmp;
}

Measured memory_bytes: 2548
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let a = scan.read::<i64>();
    let b = scan.read::<i64>();
    println!("{}", lcm(a, b));
}

#[allow(dead_code)]
pub fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}


#[allow(dead_code)]
pub fn lcm(a: i64, b: i64) -> i64 {
    a / gcd(a, b) * b
}

// region template
#[allow(dead_code)]
fn iu(i: i64) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> i64 { i as i64 }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 4352
package main

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

func main() {
	nextReader = newScanner()
	N := nextInt()
	Ls := nextInts(N)
	sort.Ints(Ls)

	ans := 0
	for i := 0; i < N; i++ {
		for j := i + 1; j < N; j++ {
			ans += search(Ls[j+1:], Ls[i]+Ls[j])
		}
	}
	fmt.Println(ans)
}

func search(l []int, key int) int {
	left := 0
	right := len(l)
	for left < right {
		mid := (left + right) / 2
		if key <= l[mid] {
			right = mid
		} else {
			left = mid + 1
		}
	}
	return left
}

// ---------------------------------------------------------------
// I/O
// ---------------------------------------------------------------
var nextReader func() string

func newScanner() func() string {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, 1024), int(1e11))
	sc.Split(bufio.ScanWords)
	return func() string {
		sc.Scan()
		return sc.Text()
	}
}

func nextString() string { return nextReader() }

func nextInt() int { n, _ := strconv.Atoi(nextReader()); return n }

func nextInts(size int) []int {
	ns := make([]int, size)
	for i := 0; i < size; i++ {
		ns[i] = nextInt()
	}
	return ns
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> b(n);
  rep(i, n) b[i] = a[i];
  sort(b.begin(), b.end());
  rep(i, n) {
    if (a[i] == b[n - 1])
      cout << b[n - 2] << endl;
    else
      cout << b[n - 1] << endl;
  }
  return 0;
}

Measured memory_bytes: 3200
#include <iostream>
using namespace std;
int main(){
  int N;
  cin>>N;
  int a[110];
  for (int i=0; i<N; ++i) cin >> a[i];
 int num[110]={0}; 
  for (int i=0; i<N; ++i) num[a[i]]++;
  int sum;
    for (int i=0; i<101; ++i){
      if (num[i]>0){
        sum++;
      }
    }
  cout<<sum<<endl;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;
constexpr auto INF = INT_MAX >> 1;
constexpr auto LINF = 5000000000000000;
constexpr auto MOD = 1000000007;

ll gcd(ll i, ll j) { return i % j ? gcd(j, i % j) : j; }
ll lpow(int p, int q) {
    ll ans = 1;
    ll pp = p;
    while (q) {
        if (q & 1) {
            ans *= pp;
            ans %= MOD;
        }
        q /= 2;
        pp *= pp;
        pp %= MOD;
    }
    return ans;
}

int main(){

    int n;
    cin >> n;
    int zero = 0;
    map<P, int> pl, mn;
    set<P> se;
    rep(i, n) {
        ll a, b;
        cin >> a >> b;
        short int k = 0;
        if (a < 0) { a *= -1;k ^= 1; }
        if (b < 0) { b *= -1;k ^= 1; }
        if (a == 0 && b == 0) {
            zero++;
            continue;
        }
        else if (a == 0 || b == 0) {
            if (a == 0)mn[P(0, 1)]++;
            if (b == 0)pl[P(0, 1)]++;
            se.insert(P(0, 1));
        }
        else {
            ll g = gcd(a, b);
            a /= g;b /= g;
            if (k) { mn[P(a, b)]++;se.insert(P(a, b));}
            else { pl[P(b, a)]++;se.insert(P(b, a)); }
        }
    }

    if (zero == n) { cout << n << endl;return 0; }

    ll ans = 1;
    for (auto x : se) {
        int l = mn[x];
        int m = pl[x];
        ans *= (lpow(2, l) + lpow(2, m) - 1 + MOD) % MOD;
        ans %= MOD;
    }

    cout << (ans + zero - 1 + MOD) % MOD << endl;

 }

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

dp = [[0]*64 for i in range(n)]


#a,g,c =0,1,2
##末尾4文字見る必要がある。3文字ではない

def test(w,x,y,z):
    s = ((0,1,2),(1,0,2),(0,2,1))
    if (x,y,z) not in s and (w,y,z)!=(0,1,2) and (w,x,z)!=(0,1,2):##これ手でノーミスは無理なのだが、処理の実装を思いつく気がしない
        return True
    else:
        return False

for i in range(64):
    x,y,z = i>>4,(i>>2)&3,i&3
    if test(3,x,y,z):
        dp[2][i]=1

for i in range(3,n):
    for j in range(64):
        w,x,y = j>>4,(j>>2)&3,j&3
        """
        if w not in (0,1,2,3) or x not in (0,1,2,3) or y not in ( 0,1,2,3):
            print(j,w,x,y)
            exit()
        """
        for z in range(4):
            if test(w,x,y,z):
                dp[i][(x<<4)+(y<<2)+z]+=dp[i-1][j]

#for i in range(16):
#    ans+=dp[i][n-1]
ans = sum(dp[n-1])
ans%=10**9+7
print(ans)


Measured memory_bytes: 53232
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

long min(long a, long b, long c) {
    return min(a, min(b, c));
}

long max(long a, long b, long c) {
    return max(a, max(b, c));
}

int main() {
    VI v;
    REP(i,3) {
        long a;
        cin >> a;
        v.push_back(a);
    }
    long ans = 1e9;
    REP(k,51) {
        if (k < min(v[0],v[1],v[2]) || k > max(v[0],v[1],v[2])) {
            
        } else {
            long hoge = 0;
            REP(i,3) {
                if (v[i] > k) {
                    hoge += v[i] - k;
                } else {
                    if ((k - v[i]) % 2 == 0) {
                        hoge += (k - v[i]) / 2;
                    } else {
                        hoge += (k - v[i]) / 2 + 2;
                    }
                    
                }
            }
            ans = min(ans ,hoge);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
def input():
	return sys.stdin.readline().strip()

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


class Union_Find():
	def __init__(self, n):
		self.union = [i for i in range(n)]
		self.level = [0 for i in range(n)]
		self.num = n

	def root(self, i, mode=0):
		keiro = [i]
		ans = i
		while ans != self.union[ans]:
			ans = self.union[ans]
			keiro.append(ans)
		if mode == 0:
			return ans
		else:
			return ans, keiro

	def unite(self, i, j):
		root_i, list_i = self.root(i, 1)
		root_j, list_j = self.root(j, 1)
		if root_i != root_j:
			self.num -= 1
			if self.level[root_i] < self.level[root_j]:
				self.level[root_j] = max(self.level[root_i] + 1, self.level[root_j])
				for node in list_i:
					self.union[node] = root_j
			else:
				self.level[root_i] = max(self.level[root_j] + 1, self.level[root_i])
				for node in list_j:
					self.union[node] = root_i

union = Union_Find(N)

for i in range(M):
	X, Y, Z = list(map(int, input().split()))
	union.unite(X - 1, Y - 1)

print(union.num)

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

using namespace std;
int a,b,c,x,y,res;
int main(){
  cin>>a>>b>>c>>x>>y;
  res = min(a*x+b*y,min(c*2*(max(x,y)),c*2*min(x,y)+max(x-min(x,y),0)*a+max(y-min(x,y),0)*b));
  cout<<res;
  return 0;
}


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

int n;
int a[11][11];

int main() {
	for(int i=0;i<3;i++)
	for(int j=0;j<3;j++) {
		scanf("%d", &a[i][j]);
	}
	
	scanf("%d", &n);
	for(int t=0;t<n;t++) {
		int x;
		scanf("%d", &x);
		
		for(int i=0;i<3;i++)
		for(int j=0;j<3;j++)
			if(a[i][j]==x) a[i][j] = 0;
	}
	
	bool chk = false;
	for(int i=0;i<3;i++) {
		if(a[i][0]+a[i][1]+a[i][2]==0) chk = true;
		if(a[0][i]+a[1][i]+a[2][i]==0) chk = true;
	}
	if(a[0][0]+a[1][1]+a[2][2]==0) chk = true;
	if(a[0][2]+a[1][1]+a[2][0]==0) chk = true;
	
	puts(chk?"Yes":"No");
	
	return 0;
}

Measured memory_bytes: 256
package main

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

const MOD = 1000000007

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextIntSlice(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = nextInt()
	}
	return a
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

func mod(val int, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	m := nextInt()
	s := nextIntSlice(n)
	t := nextIntSlice(m)
	dp := make([][]int, n+1)
	for i := 0; i <= n; i++ {
		dp[i] = make([]int, m+1)
	}
	for i := 0; i <= m; i++ {
		dp[0][i] = 1
	}
	for i := 0; i <= n; i++ {
		dp[i][0] = 1
	}

	for i := 1; i <= n; i++ {
		for j := 1; j <= m; j++ {
			if s[i-1] == t[j-1] {
				dp[i][j] = mod(dp[i-1][j]+dp[i][j-1], MOD)
			} else {
				dp[i][j] = mod(dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1], MOD)
			}
		}
	}

	fmt.Println(dp[n][m])

}


Measured memory_bytes: 33920
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>

using namespace std;

const int MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;
#define rep(i, m, n) for(int i=m;i<n;i++)
#define rrep(i, n, m) for(int i=n;i>=m;i--)

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> V(N);
    for (int i = 0; i < N; ++i) {
        cin >> V[i];
    }

    ll ans = 0;
    for (int a = 0; a <= min(N, K); ++a) {
        for (int b = 0; b <= min(N - a, K - a); ++b) {
            vector<ll> tmp;
            ll cur = 0;
            for (int i = 0; i < a; ++i) {
                cur += V[i];
                tmp.push_back(V[i]);
            }
            for (int i = 0; i < b; ++i) {
                cur += V[N - i - 1];
                tmp.push_back(V[N - i - 1]);
            }
            sort(tmp.begin(), tmp.end());
            for (int i = 0; i < min((int)tmp.size(), K - a - b); ++i) {
                if (tmp[i] < 0) {
                    cur -= tmp[i];
                }
            }
            ans = max(ans, cur);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
def abc(d, down_text, up_text):
    d[down_text] -= 1
    d[up_text] += 1


def main():
    n, a, b, c = map(int, input().split())
    ans_list = []
    dct = {"A": a, "B": b, "C": c}

    abc_list = [input() for _ in range(n)]
    abc_list.append('AB')

    for i in range(n):
        # a_txt = input()
        l_txt = abc_list[i][0]
        r_txt = abc_list[i][1]

        if dct[l_txt] < dct[r_txt]:
            abc(dct, r_txt, l_txt)
            ans_list.append(l_txt)

        elif dct[l_txt] > dct[r_txt]:
            abc(dct, l_txt, r_txt)
            ans_list.append(r_txt)

        else:
            if dct[l_txt] == dct[r_txt] == 0:
                print('No')
                break
            else:
                if l_txt in abc_list[i + 1]:
                    abc(dct, r_txt, l_txt)
                    ans_list.append(l_txt)
                elif r_txt in abc_list[i + 1]:
                    abc(dct, l_txt, r_txt)
                    ans_list.append(r_txt)
    else:
        print('Yes')
        print(*ans_list, sep='\n')


if __name__ == "__main__":
    main()


Measured memory_bytes: 18492
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

int main() {
    int n;
    cin >> n;
    
    vector<int> v(n);
    vector<int> sum(n + 1);
    sum[0] = 0;
    for(int i = 0; i < n; i++) {
        cin >> v[i];
        sum[i + 1] = v[i] + sum[i];
    }
    
    int min = 1000000;
    for(int i = 1; i < n; i++) {
        if(min > abs(sum[n] - 2 * sum[i])) {
            min = abs(sum[n] - 2 * sum[i]);
        }
    }
    
    cout << min << endl;
    
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n; cin>>n;
	vector<int> a(n), b(n), c(n - 1);
	for(auto &x : a){
		cin>>x; x--;
	}
	for(auto &x : b){
		cin>>x;
	}
	for(auto &x : c){
		cin>>x;
	}
	ll ans = accumulate(b.begin(), b.end(), 0);
	for(int i = 0; i + 1 < n; i++){
		if(a[i] + 1 == a[i + 1])ans += c[a[i]];
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
//inline int in() { int x; scanf("%d",&x); return x;}
template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int a, b;
  cin >> a >> b;
  rrep(i,1000) {
    int za = i*8/100;
    int zb = i*10/100;
    if (za == a && zb == b) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

#[macro_use]
extern crate lazy_static;
extern crate num_bigint; // 0.2.2
extern crate num_traits; // 0.2.8
use num_bigint::BigInt;
use num_bigint::ToBigInt;
use num_traits::Pow;
use num_traits::{One, Zero};

// use proconio::derive_readable;
use proconio::fastout;
use proconio::input;
// use std::convert::TryInto;
// use ascii::Chars;
use proconio::marker::{Bytes, Chars};
use std::cmp::*;
use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::*;
use std::ops::Range;
use std::str::FromStr;
use superslice::*;

use lazy_static::lazy_static;
use std::sync::Mutex;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

lazy_static! {
    // static ref PARENTS: Mutex<Vec<usize>> = Mutex::default();
    // static ref CHILDS: Mutex<Vec<Vec<usize>>> = Mutex::default();
    static ref ADJ: Mutex<Vec<Vec<usize>>> = Mutex::default();
}

// const MOD: usize = 9997063;
// const MOD: usize = 100_000_000_ + 7;

//tenka1-2019-C
// #[fastout]
fn main() {
    input![n: usize, s: Chars];

    // let mut continuas_region = Vec::new();

    let mut b_count = vec![-1; n + 1];
    let mut w_count = vec![-1; n + 1];
    b_count[0] = 0;
    w_count[0] = 0;
    for (idx, s) in s.iter().enumerate() {
        let idx = idx + 1;
        b_count[idx] = b_count[idx - 1];
        w_count[idx] = w_count[idx - 1];
        if *s == '#' {
            b_count[idx] += 1;
        } else {
            w_count[idx] += 1;
        }
    }

    let all_w = w_count[n];
    for i in 0..n + 1 {
        w_count[i] = all_w - w_count[i];
    }

    // eprintln!("{:?}", b_count);
    // eprintln!("{:?}", w_count);

    let mut old_is_w = true;
    let mut ans = 1000000000;
    for (idx, s) in s.iter().enumerate() {
        let is_w = *s == '.';
        // if !old_is_w && is_w {
        //     eprintln!("{}, {}", idx, s);
        ans = min(ans, w_count[idx] + b_count[idx]);
        // }

        old_is_w = is_w;
    }

    ans = min(ans, w_count[n] + b_count[n]);

    // eprintln!("{:?}", adj);
    println!("{}", ans);
}

// let mut values = VALUES.lock().unwrap();
// values.extend_from_slice(&[1, 2, 3, 4]);
// assert_eq!(&*values, &[1, 2, 3, 4]);

// -100000000
//  1000000000


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

int main(){
	int n,m,l;
	cin >> n >> m >> l;
	
	long long int a[100][100], b[100][100];
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			cin >> a[i][j];
		}
	}
	for(int i=0; i<m; i++){
		for(int j=0; j<l; j++){
			cin >> b[i][j];
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<l; j++){
			long long int elem=0;
			for(int k=0; k<m; k++){
				elem += a[i][k]*b[k][j];
			}
			if(j==0) cout << elem;
			else cout << " " << elem;
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3156
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] A = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);

            int idx = Partition(A, 0, n - 1);

            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < idx; i++) sb.Append(A[i] + " ");
            sb.Append("[" + A[idx] + "]");
            for (int i = idx + 1; i < n; i++) sb.Append(" " + A[i]);
            Console.WriteLine(sb);
        }

        static int Partition(int[] A,int p,int r)
        {
            int x = A[r];
            int i = p - 1;
            int temp;

            for(int j = p; j < r; j++)
            {
                if (A[j] <= x)
                {
                    i++;

                    temp = A[i];
                    A[i] = A[j];
                    A[j] = temp;
                }
            }

            temp = A[i + 1];
            A[i + 1] = A[r];
            A[r] = temp;

            return i + 1;
        }
    }
}

Measured memory_bytes: 20056