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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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

map<lli,lli> cnt;

map<lli,lli> makePrimeList2(lli n){
    map<lli,lli> m;
    lli a = 2;
    while(n>=a*a){
        if(n%a==0){
            m[a]++;
            n /= a;
        }
        else a++;
    }
    if(n!=1)m[n]++;
    return m;
}

void func(long long N){

    REP(i,1,N+1){
        map<lli,lli> prime = makePrimeList2(i);
        for(auto e:prime){
            cnt[e.first]+=e.second;
        }
    }
    //約数が75個,-> x^2*y^24 or x^2*y^4*z^4 or x^4 or y^15 ,x^74

    lli sum = 0;
    //x^2,y^24の組み合わせ
    lli x = 0,y=0;
    for(auto e:cnt){
        if(e.second>=2)x++;
        if(e.second>=24)y++;
    }
    sum += y*(x-1);

    //x^2*y^4*z^4の組み合わせ
    x=0,y=0;
    for(auto e:cnt){
        if(e.second>=2)x++;
        if(e.second>=4)y++;
    }
    sum += y*(y-1)/2*(x-2);

    //x^4*y^14
    x=0,y=0;
    for(auto e:cnt){
        if(e.second>=4)x++;
        if(e.second>=14)y++;
    }
    sum += y*(x-1);

    x=0;
    for(auto e:cnt){
        if(e.second>=74)x++;
    }

    sum+=x;

    cout<<sum<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    func(N);
    return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
A=[int(x) for x in input().split()]
B=[]
C=[]
for i in range(N):
  if A[i]<0:
    C += [-A[i]]
  else:
    B +=[A[i]]
C=sorted(C)
b=len(B)
c=len(C)
B=[0]+B+[float('inf')]*c
C=[0]+C+[float('inf')]*b
answer=float('inf')

for i in range(K):
  answer=min(answer,2*B[i]+C[K-i],2*C[i]+B[K-i])
print(answer)

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

int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
    int n,k;
    cin>>n>>k;
    if(k!=1)cout<<n-k<<endl;
    else cout<<0<<endl;


//////////////////////////////////////////////////////
return 0;}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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

using ll = long long;
using namespace std;

const ll mod = 998244353;

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

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

ll N, S;
ll A[3010];
mint dp[3010][3010][3];

int main()
{
  scanf( "%lld%lld", &N, &S );
  
  rep( i, N )
    scanf( "%lld", A+i );

  dp[0][0][0] = 1;

  rep( i, N ) rep( j, S+1 )
  {
    dp[i+1][j][0] += dp[i][j][0];
    dp[i+1][j][1] += dp[i][j][0]+dp[i][j][1];
    dp[i+1][j][2] += dp[i][j][0]+dp[i][j][1]+dp[i][j][2];

    if( j+A[i] <= S )
    {
      dp[i+1][j+A[i]][1] += dp[i][j][0]+dp[i][j][1];
      dp[i+1][j+A[i]][2] += dp[i][j][0]+dp[i][j][1];
    }
  }

  printf( "%lld\n", dp[N][S][2].x );

  return 0;
}

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

typedef unsigned int ui;
#define rep(i,l,r) for(int i=l;i<=r;++i)
const int N=2000+5,A=4e6+5;
int cnt[A];
ui a[1<<17];int mx;
bool Count(int x)
{
	return a[x/32]&(1<<(x&31));
}
void move(int x)
{
	int u=mx/32;mx+=x;
	int du=x/32,di=x&31;
	if(!di)
	{
		for(int i=u;i>=0;--i)a[i+du]|=a[i];
		return ;
	}
	for(int i=u;i>=0;--i)
	{
		a[i+du+1]|=a[i]>>32-di;
		a[i+du]|=a[i]<<di;
	}
}

int main()
{
	//freopen("will.in","r",stdin);freopen("will.out","w",stdout);
	int n;
	cin>>n;
	int sum=0;
	rep(i,1,n)
	{
		int x;
		scanf("%d",&x);
		sum+=x;
		++cnt[x];
	}
	mx=0;a[0]=1;
	rep(i,1,sum)
	{
		while(cnt[i]>2){++cnt[i*2];cnt[i]-=2;}
		while(cnt[i]--)move(i);
	}
	int tot=0;
	rep(i,1,sum)
	if(Count(i))++tot;
	tot=(tot+1)/2;
	rep(i,1,sum)
	if(Count(i))
	{
		if(!--tot)
		{
			cout<<i;
			exit(0);
		}
	}
}


Measured memory_bytes: 16384
#include <cstdio>
#include <set>
using namespace std;

long long int cnt[10];
set<pair<int, int> > s;

int main(){
	int H, W, N, a, b, t;
	scanf("%d %d %d", &H, &W, &N);
	cnt[0] = 1LL * (H-2) * (W-2);
	while(N--){
		scanf("%d %d", &a, &b);
		s.insert({a, b});
		for(int i=max(1, a-2); i<=min(H-2, a); ++i){
			for(int j=max(1, b-2); j<=min(W-2, b); ++j){
				t = 0;
				for(int y=i; y<i+3; ++y){
					for(int x=j; x<j+3; ++x){
						if(s.count({y, x}))
							++t;
					}
				}
				++cnt[t];
				--cnt[t-1];
			}
		}
	}
	for(int i=0; i<10; ++i)
		printf("%lld\n", cnt[i]);
}


Measured memory_bytes: 4864
package main

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumInt64(a []int64) int64 {
	var ret int64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcdInt64(m, n int64) int64 {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcmInt64(m, n int64) int64 {
	return m / gcdInt64(m, n) * n
}

// sort ------------------------------------------------------------

type int64Array []int64

func (s int64Array) Len() int           { return len(s) }
func (s int64Array) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s int64Array) Less(i, j int) bool { return s[i] < s[j] }

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var n int
var h, dp []int

func dfs(i int) int {
	if dp[i] != -1 {
		return dp[i]
	}
	if i == n-1 {
		return 0
	}
	if i+2 < n {
		dp[i] = min(dfs(i+1)+abs(h[i]-h[i+1]), dfs(i+2)+abs(h[i]-h[i+2]))
	} else {
		dp[i] = dfs(i+1) + abs(h[i]-h[i+1])
	}
	return dp[i]
}

func main() {
	n = readInt()
	h = make([]int, n)
	for i := range h {
		h[i] = readInt()
	}
	dp = make([]int, n+1)
	for i := 0; i < n+1; i++ {
		dp[i] = -1
	}

	fmt.Println(dfs(0))
}


Measured memory_bytes: 10624
#define ll long long
#define pb push_back
#define mpr make_pair
#define ff first
#define ss second
#include <bits/stdc++.h>
using namespace std;

int main(int argc, char const *argv[]) {
  string s;
  int n,mx=0;
  cin>>n;
  cin>>s;
  for(int i=0;i<n-1;i++){
    vector<char>s1,s2;
    map<char,int>mp;
    for(int j=0;j<=i;j++){
      if(!mp[s[j]])mp[s[j]]=1;
    }
    for(int j=i+1;j<n;j++){
      if(mp[s[j]]==1)mp[s[j]]+=1;
    }
    int t =0;
    for(char j='a';j<='z';j++)if(mp[j]==2)t++;
    mx = max (mx,t);
  }
  cout<<mx<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <vector>
#include <string>
#include <set>
#include <utility>
using namespace std ;
using ll = long long ;
using vll = vector<ll> ;
using pll = pair<ll,ll> ;

int main(){
    string s ; cin >> s ;
    if(s=="hi"||s=="hihi"||s=="hihihi"||s=="hihihihi"||s=="hihihihihi") cout << "Yes" << endl ;
    else cout << "No" << endl ;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front
#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll x,n,q,sum=0,a,b;
    vector <ll> arr(100005);
    cin>>n;
    
    for(int i=0; i<n; i++){
        cin>>x;
        sum += x;
        arr[x]++;
    }

    cin>>q;
    while(q--){
        cin>>a>>b;
        sum -= (a*arr[a]);
        sum += (b*arr[a]);
        arr[b] += arr[a];
        arr[a] = 0;

        cout << sum << "\n";
    }
    
    return 0;
}

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

#define ll long long
#define MAX 300005
#define pp pair<ll, pair<ll, ll>>
#define pb push_back
#define mod 1000000007

using namespace std;

/*
 * author: Kruti_20
 */

ll power(ll x, ll y);
ll gcd(ll a, ll b);



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string a,b;
    cin>>a>>b;
    int ans=0;
    if(a[0]==b[0]) ans++;
    if(a[1]==b[1]) ans++;
    if(a[2]==b[2]) ans++;
    cout<<ans;
    return 0;
}

ll power(ll x, ll y) {
    ll res = 1;
    x = x % mod;
    while (y > 0) {
        if (y & 1) res = (res * x) % mod;
        y = y >> 1;
        x = (x * x) % mod;
    }
    return res;
}

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

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


int main(){
    int N, T; cin >> N >> T;
    vector<int> t(N); for(int i = 0; i < N; i++) cin >> t[i];
    ll ans = 0;
    //ll tmp = t[0] + T;

    for(int i = 1; i < N; i++){
        if(t[i-1] + T < t[i]) ans += T;
        else  ans += t[i] - t[i-1];

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

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
int main() {
  int n, b;
  set<int> a;
  cin >> n;
  rep(i,n)
  {
    cin >> b;
    if (a.find(b) != a.end()) {
      cout << "NO";
      return 0;
    }
    a.insert(b);
  }
  cout << "YES";
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
//#include<iostream>
using namespace std;
#define int long long

#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint,int> P1;
typedef pair<int,pint> P2;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007,INF=1e18;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
struct edge{
    int to,cost;
    edge(int to,int cost):to(to),cost(cost){}
};
vector <edge> tree[100010];
ll dist[100010];

int V,E,r;

void dijkstra(int s){
    priority_queue<pint,vpint,greater<pint>> que;
    fill(dist,dist+V,INF);
    dist[s]=0;
    que.push(pint(0,s));
    
    while(!que.empty()){
        pint p=que.top();
        que.pop();
        int v=p.se;
        if(dist[v]<p.fi)continue;
        rep(i,0,tree[v].size()){
            edge e=tree[v][i];
            if(dist[e.to]>dist[v]+e.cost){
                dist[e.to]=dist[v]+e.cost;
                que.push(pint(dist[e.to],e.to));
            }
        }
    }
}


signed main(){
    cin.tie(0);
	ios::sync_with_stdio(false);
    cin>>V>>E>>r;
    rep(i,0,E){
        int a,b,c;
        cin>>a>>b>>c;
        tree[a].pb(edge(b,c));
    }
    dijkstra(r);
    
    rep(i,0,V){
        if(dist[i]==INF)cout<<"INF"<<endl;
        else cout<<dist[i]<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 19536
#include<iostream>
#include<cstdlib>

using namespace std;

bool linearSearch(int key);

int *S,*T;
int n,q;

int main(){

	cin>>n;
	S = new int[n+1];
	for(int i=0;i<n;i++)
		cin>>S[i];

	cin>>q;
	T = new int[q];
	for(int i=0;i<q;i++)
		cin>>T[i];

	static int count;
	for(int i=0;i<q;i++){
		if(linearSearch(T[i])) count++;
	}

	cout<<count<<endl;

	cin.get();
	cin.get();
}

bool linearSearch(int key){
	int i = 0;
	S[n] = key;
	while(S[i]!=key){
		i++;
	}
	if(i==n) return false;
	return true;
}

Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>

#define BR "\n"
#define REP(i,n) for(int i=0;i<n;i++)

using namespace std;
int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	for(int i = 0; true; i++) {
		if (i *  a - i + 1 >= b) {
			cout << i << endl;
			return 0;
		}
	}
}

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

int main(void){
 int N;
 cin >> N ;
 int A[N];
for(int i = 0;i < N;i++){
 cin >> A[i] ;
}
 int num;
 int M = 0;
 for(int i = 0;i < N-1 ;i ++){
    for(int j = i;j < N ;j ++){
      num = fabs(A[i]-A[j]);
      if(num > M){
        M = num;
      }
    }
  }
  cout << M << endl;
}

Measured memory_bytes: 256
from collections import deque

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

for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    g[a].append(b)
    g[b].append(a)

start = -1
for v in range(n):
    if len(g[v]) == 0:
        continue
    start = v
    break

memo = [0] * n
memo[start] = 1
count = 0
q1 = deque([])
q2 = deque([])
for v in g[start]:
    if memo[v] == 1:
        continue
    count += 1
    if count > 2:
        break
    memo[v] = 1
    if count == 1:
        q1.append(v)
    elif count == 2:
        q2.append(v)

ans1 = [start]
while q1:
    node = q1.popleft()
    ans1.append(node)
    flag = 0
    for nv in g[node]:
        if memo[nv] == 1:
            continue
        memo[nv] = 1
        q1.append(nv)
        flag = 1
        break
    if flag == 0:
        break

ans2 = []
while q2:
    node = q2.popleft()
    ans2.append(node)
    flag = 0
    for nv in g[node]:
        if memo[nv] == 1:
            continue
        memo[nv] = 1
        q2.append(nv)
        flag = 1
        break
    if flag == 0:
        break

ans1 = ans1[::-1]


ans = []
for i in ans1:
    ans.append(i+1)
for i in ans2:
    ans.append(i+1)
print(len(ans))
print(*ans)


Measured memory_bytes: 30424
import sys
from collections import deque
 
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
 
N, M = lr()
graph = [[] for _ in range(N+1)]
for _ in range(M):
    a, b = lr()
    graph[a].append(b)
    graph[b].append(a)
 
def bfs():
    que = deque([1])
    dir = [None] * (N+1)    
    while que:
        cur = que.popleft()
        for n in graph[cur]:
            if dir[n] != None:
                continue
            dir[n] = str(cur)
            que.append(n)
    return dir
 
dir = bfs()
print('Yes')
print('\n'.join(dir[2:]))

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

int main(){
    int n;
    cin >> n;
    int a,b,c;
    a=n/100;
    b=(n/10)%10;
    c=n%10;
    if(a==9) cout << 1; 
    else cout << 9 ;   
    if(b==9) cout << 1;
    else cout << 9 ;
    if(c==9) cout << 1 <<endl;
    else cout << 9 << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
void chmin(long long &a, long long b) { if (a > b) a = b; }
 
int main() {
    int A, B, Q; cin >> A >> B >> Q;
    vector<long long> s(A), t(B);
    for (int i = 0; i < A; ++i) cin >> s[i];
    for (int i = 0; i < B; ++i) cin >> t[i];
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
 
    for (int _ = 0; _ < Q; ++_) {
        long long x; cin >> x;
        
        long long res = 1LL<<60;
        
        // 先に s
        int it = lower_bound(s.begin(), s.end(), x) - s.begin();
        for (int i = max(0, it-1); i < min(A, it+1); ++i) {
            long long y = s[i]; 
            int it2 = lower_bound(t.begin(), t.end(), y) - t.begin();
            for (int j = max(0, it2-2); j < min(B, it2+2); ++j) {
                chmin(res, abs(x - y) + abs(y - t[j]));
            }         
        }
 
        // 先に t
        it = lower_bound(t.begin(), t.end(), x) - t.begin();
        for (int i = max(0, it-1); i < min(B, it+1); ++i) {
            long long y = t[i]; 
            int it2 = lower_bound(s.begin(), s.end(), y) - s.begin();
            for (int j = max(0, it2-1); j < min(A, it2+1); ++j) {
                chmin(res, abs(x - y) + abs(y - s[j]));
            }         
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 2944
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")
#include <bits/stdc++.h>
using namespace std ;
#define ll long long
void FastInputOutput(){
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}

inline int D(){
    int t ;
    scanf( "%d" , &t ) ;
    return t ;
}
inline ll LLD(){
    ll t ;
    scanf( "%lld" , &t ) ;
    return t ;
}

ll power(ll x, ll p, ll m){
    ll res = 1;
    while(p){
        if(p&1)    res = (res * x)%m;
        x = (x * x)%m;
        p >>= 1;
    }
    return res;
}


const int N = 1e5 + 5;
char a[N];

int main(){
    scanf("%s", a);
    a[3] = '8';
    printf("%s", a);
    return 0;
}


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

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

    int tmp, cnt;
    int ans = n;
    for (int i = 0; i <= n; i++) {
        cnt = 0;
        tmp = i;
        while (tmp > 0) {
            cnt += tmp % 9;
            tmp /= 9;
        }
        tmp = n - i;
        while (tmp > 0) {
            cnt += tmp % 6;
            tmp /= 6;
        }
        if (ans > cnt)
            ans = cnt;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
c=list(input())
i,j=0,n-1
ans=0
while 1:
    if i>=j:
        break
    if c[i]=="W" and c[j]=="R":
        c[i]="R"
        c[j]="W"
        ans+=1
    if c[i]!="W":
        i+=1
    if c[j]!="R":
        j-=1
for i in range(n-1):
    if c[i]=="W" and c[i+1]=="R":
        c[i]="R"
        ans+=1
print(ans)

Measured memory_bytes: 10780
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n); i >= 0; i--)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define REVSORT(c) SORT(c);REVERSE(c)
#define ALL(x) (x).begin(),(x).end()
const long long MOD = 1000000007;
typedef long long ll;

int main(){
	string S, T;
	cin >> S >> T;
	int cnt = 0;
	rep(i, 3){
		if(S[i] == T[i])cnt++;
	}
	cout <<cnt << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(void){
  int x;
  scanf("%d",&x);
  int i=x;
  while(1){int flag=0;
    for(int j=2;j<sqrt(i);j++){
      if(i%j==0){
        flag=1;
        break;
      }
    }
    if(!flag)break;
    i++;
          }
    printf("%d",i);
    return 0;
  }

Measured memory_bytes: 128
// 解き直し.
// https://img.atcoder.jp/sumitrust2019/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

int main(){

    // 1. 入力情報.
    LL T1, T2, A1, A2, B1, B2;
    scanf("%lld %lld %lld %lld %lld %lld", &T1, &T2, &A1, &A2, &B1, &B2);
    
    // 2. 解説通り.
    // P = (A1 - B1) * T1, Q = (A2 - B2) * T2 と置いて場合分け.
    LL P = (A1 - B1) * T1, Q = (A2 - B2) * T2, ans = 0;
    
    // 2-1. P > 0 の 場合は, P, Q を -1倍.
    if(P > 0) P *= -1, Q *= -1;
    
    // 2-2. P + Q < 0.
    if(P + Q < 0){
        puts("0");
        return 0;
    }
    
    // 2-3. P + Q == 0.
    if(P + Q == 0){
        puts("infinity");
        return 0;
    }
    
    // 2-4. P + Q > 0.
    //  (kサイクル目)  ->     (P 進む)         ->  (Q 進む(= k + 1サイクル目))
    // k * (P + Q) > 0 -> k * (P + Q) + P < 0  -> (k + 1) * (P + Q) > 0   … 0 の 位置 を 2回通過.
    // k * (P + Q) > 0 -> k * (P + Q) + P == 0 -> (k + 1) * (P + Q) > 0   … 0 の 位置 を 1回通過.
    // k * (P + Q) > 0 -> k * (P + Q) + P > 0  -> (k + 1) * (P + Q) > 0   … 0 の 位置 を 0回通過.
    LL S = -P / (P + Q), T = -P % (P + Q);
    if(T != 0) printf("%lld\n", 2 * S + 1);
    else       printf("%lld\n", 2 * S);
    return 0;
    
}

Measured memory_bytes: 256
[A1,A2,A3]=map(int,input().split())
tasks=[A1,A2,A3]
costs=[]
def cost(start):
    for i in range(3):
        if i!=start:
            cost_1st=abs(tasks[i]-tasks[start])
            for l in range(3):
                if l != i and l != start:
                    total_cost=cost_1st+abs(tasks[i]-tasks[l])
                    costs.append(total_cost)
                else:
                    continue
        else:
            continue
for i in range(3):
    cost(i)

ans=min(costs)

print(ans)


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

using namespace std;


signed main(){
    int a, b, x;
    cin >> a >> b >> x;
    int sum = 0;
    while(x > 0){
        if(x > 500){
            sum += min(a, 2 * b);
            x -= 1000;
        }else{
            sum += min(a, b);
            x -= 500;
        }
    }
    cout << sum << endl;
}



Measured memory_bytes: 3084
// {{{ by shik
#include <bits/stdc++.h>
#include <unistd.h>
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define FOR(it,c) for ( auto it=(c).begin(); it!=(c).end(); it++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

#ifdef SHIK
template<typename T>
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }

template<typename T, typename... Args>
void _dump( const char* s, T&& head, Args&&... tail ) {
    int c=0;
    while ( *s!=',' || c!=0 ) {
        if ( *s=='(' || *s=='[' || *s=='{' ) c++;
        if ( *s==')' || *s==']' || *s=='}' ) c--;
        cerr<<*s++;
    }
    cerr<<"="<<head<<", ";
    _dump(s+1,tail...);
}

#define dump(...) do { \
    fprintf(stderr, "%s:%d - ", __PRETTY_FUNCTION__, __LINE__); \
    _dump(#__VA_ARGS__, __VA_ARGS__); \
} while (0)

template<typename Iter>
ostream& _out( ostream &s, Iter b, Iter e ) {
    s<<"[";
    for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
    s<<"]";
    return s;
}

template<typename A, typename B>
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }
template<typename T>
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
template<typename T, size_t N>
ostream& operator <<( ostream &s, const array<T,N> &c ) { return _out(s,ALL(c)); }
template<typename T>
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
template<typename A, typename B>
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }
#else
#define dump(...)
#endif

template<typename T>
void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( long long &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }

void R() {}
template<typename T, typename... U>
void R( T& head, U&... tail ) {
    _R(head);
    R(tail...);
}

template<typename T>
void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
template<typename T>
void _W( const vector<T> &x ) {
    for ( auto i=x.cbegin(); i!=x.cend(); i++ ) {
        if ( i!=x.cbegin() ) putchar(' ');
        _W(*i);
    }
}

void W() {}
template<typename T, typename... U>
void W( const T& head, const U&... tail ) {
    _W(head);
    putchar(sizeof...(tail)?' ':'\n');
    W(tail...);
}

#ifdef SHIK
#define FILEIO(...)
#else
#define FILEIO(name) do {\
    freopen(name ".in","r",stdin); \
    freopen(name ".out","w",stdout); \
} while (0)
#endif

// }}}

const int N=2e5+10;

int n,m;
pair<LL,int> v[N];
int main() {
    R(n,m);
    REP(i,n+m) {
        R(v[i].first);
        v[i].second=i<n;
    }
    sort(v,v+n+m);
    LL ans=0;
    LL c[2]={m+1,n+1};
    REP(i,n+m) {
        LL a=v[i].first;
        int b=v[i].second;
        dump(a,b);
        ans+=a*max(0LL,c[b^1]);
        c[b]--;
    }
    W(ans);
    return 0;
}


Measured memory_bytes: 3456
import * as fs from 'fs';

const readString = (() => {
  const input = fs.readFileSync(0).toString();
  const words = input.split(/[ \n]/);
  let i = 0;
  return () => words[i++] || '';
})();
const readInt = () => parseInt(readString(), 10);
const readBigInt = () => BigInt(readString());

const gcd = (a: bigint, b: bigint) => {
  const _gcd = (a: bigint, b: bigint): bigint => {
    const q = a % b;
    return q === 0n ? b : _gcd(b, q);
  };
  return a > b ? _gcd(a, b) : _gcd(b, a);
};

const MOD = 1000000007;
const MOD_BIGINT = BigInt(MOD);
class ModBigInt {
  constructor(public v: bigint) {}

  static of(n: number | bigint) {
    return new ModBigInt(ModBigInt.toBigInt(n));
  }

  static toBigInt(other: number | bigint | ModBigInt) {
    if (typeof other === 'bigint') return other;
    if (typeof other === 'number') return BigInt(other);
    return other.v;
  }

  clone = () => new ModBigInt(this.v);
  plus = (other: number | bigint | ModBigInt) => {
    this.v = (this.v + ModBigInt.toBigInt(other)) % MOD_BIGINT;
    return this;
  };
  minus = (other: number | bigint | ModBigInt) => {
    this.v = (this.v + MOD_BIGINT - ModBigInt.toBigInt(other)) % MOD_BIGINT;
    return this;
  };
  multiply = (other: number | bigint | ModBigInt) => {
    this.v = (this.v * ModBigInt.toBigInt(other)) % MOD_BIGINT;
    return this;
  };
  pow = (other: number) => {
    const v = mod(1);
    for (let i = 0; i < other; i++) v.multiply(this.v);
    return v;
  };
}

const mod = ModBigInt.of;

const abs = (a: bigint) => (a > 0n ? a : -a);

(function main() {
  const A = readInt();
  const B = readInt();
  console.log(A * B);
})();


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


int main(){
  int N;
  cin>>N;
  vector<pair<int,int>> red(N);
  for(int i=0;i<N;++i){
    cin>>red.at(i).first;
    cin>>red.at(i).second;
  }
  vector<pair<int,int>> blue(N);
  for(int i=0;i<N;++i){
    cin>>blue.at(i).first;
    cin>>blue.at(i).second;
  }

  
  sort(red.begin(),red.end());
  sort(blue.begin(),blue.end());

  vector<bool> nakayoshi(N);
  int count=0;
  
  for(int ind1=0;ind1<N;++ind1){
 
    int ind2=-1;
    int red2=-1;
    for(int i=0;i<N;++i){
      if(red.at(i).first<blue.at(ind1).first && red.at(i).second<blue.at(ind1).second && nakayoshi.at(i)==false){
        if(red2<red.at(i).second){
          ind2=i;
          red2=red.at(i).second;
        }
      }
    }

    if(ind2==-1){
    continue;
    }
    else{
      ++count;
      nakayoshi.at(ind2)=true;
    }
  }

  cout<<count<<endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

class UnionFind:
    def __init__(self, n):
        self.d = [-1]*n
    
    def find(self, x):
        if self.d[x] < 0:
            return x
        else:
            self.d[x] = self.find(self.d[x])
            return self.find(self.d[x])
    
    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x==y:
            return False
        if self.d[x] > self.d[y]:
            x, y = y, x
        self.d[x] += self.d[y]
        self.d[y] = x
        return True
    
    def same(self, x, y):
        if self.find(x)==self.find(y):
            return True
        return False
    
    def size(self, x):
        return (-1) * self.d[self.find(x)]

N, M = mi()
A = li2(M)
islands = UnionFind(N)

ans = [N*(N-1)//2] * (M+1)
for i in reversed(range(M)):
    s, t = A[i][0]-1, A[i][1]-1
    if islands.same(s, t):
        ans[i] = ans[i+1]
    else:
        ans[i] = ans[i+1] - islands.size(s) * islands.size(t)
    islands.unite(s, t)

for num in ans[1:]:
    print(num)

Measured memory_bytes: 35428
"use strict"

function Main(input) {
  input = input.split('\n');
  let N = parseInt(input.shift());
  let array = input.shift().split(' ').map(x => x-0);
  let result = 0;
  let max = 0;
  for (let i=0;i<N;i++){
    let tmp = array[i];
    if (tmp >= max) {
      max = tmp;
      result++;
    }
  }
  console.log(result);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 22964
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
 
const int N = 1e4 + 5;
int a[N] , n;
 
int main()
{
    cin >> n;
 
    memset(a , 0 , sizeof a);
 
    for(int x = 1; x <= 100; ++x)
        for(int y = 1; y <= 100; ++y)
            for(int z = 1; z <= 100; ++z) {
                long long f = x*x + y*y + z*z + x*y + x*z + y*z;
                if(f <= 10000)
                    a[f]++;
            }
 
    for(int i = 1; i <= n; ++i)
        cout << a[i] << "\n";
 
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll a, b, c, d, e, f;
    cin>>a>>b>>c>>d>>e>>f;

    ll m_water = 0;
    ll m_salt = 0;
    ld m = -1;
    for(ll i=0;i<=30;++i){
        for(ll j=0;j<=30;++j){
            ll water = a*i*100 + b*j*100;
            ll salt = 0;
            if(i + j == 0 or water > f)continue;

            for(ll k=0;k<=(f-water)/c;++k){
                for(ll l=0;l<=(f-water)/d;++l){
                    salt = c*k + d*l;
                    if(water + salt > f)continue;

                    ld sum = (ld)salt / (ld)water;
                    if(sum > (ld)e / 100)continue;
                    if(sum > m){
                        m = sum;
                        m_water = water;
                        m_salt = salt;
                    }
                }
            }
        }
    }
    cout<<m_water + m_salt<<' '<<m_salt<<endl;

    return 0;
}

Measured memory_bytes: 256
#!venv/bin/python

import math
import numpy as np
import random
import copy
import statistics 
import bisect
import heapq
from collections import defaultdict 

N,W = [int(x) for x in input().split()]
h,w = [int(x) for x in input().split()]

print (N * W - (h * W + w * N - w * h))



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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF LONG_LONG_MAX

int n,k,ans;
string s;

signed main() {
    cin >> n >> k >> s;
    rep(i,n) {
        if (i) {
            if (s[i-1] == s[i]) ans++;
        }
    }
    cout << min(ans+2*k, n-1) << endl;
}


Measured memory_bytes: 512
import math

N = int(input())
A = [int(input()) for i in range(5)]
#print(A)
I = float("INF")
c = 0
for i in reversed(range(5)):
    if I >= A[i]:
        c = i
        I = A[i]
#print(I,c)
a = math.ceil(N/I)+4
print(a)
#
#
# AAAa0A
# 0
# BBBBbb
# 00
# CCCCccc


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
 
int main(void) {
    int a, b, t;
    int cnt = 0;
    cin >> a >> b >> t;
    for(int i = a; i <= t; i = i + a){
        cnt += b;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3608
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
int main()
{
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll my=a*c;
	my=max(my,a*d);
	my=max(my,b*c);
	my=max(my,b*d);
	cout<<my<<endl;
	return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {
	static Scanner sc =  new java.util.Scanner(System.in);

	public static void main(String[] args) {
		
		
		while ( sc.hasNext() ){
		
		double a = sc.nextDouble();
		
		double a2 = a * 2 ;
		double a3 = a2 / 3 ;
		double a4 = a3 * 2 ;
		double a5 = a4 / 3 ;
		double a6 = a5 * 2 ;
		double a7 = a6 / 3 ;
		double a8 = a7 * 2 ;
		double a9 = a8 / 3 ;
		double a10 = a9 * 2 ;
		
		double s = a + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10 ;
		
		System.out.println( s );
	
		}
	}

}

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

typedef long long ll;
typedef long double ld;
const ll M=1e9+7;
const ll MAXN=1e6+7;
const ld pi=acos(-1);

#define gi(n) ll n=read()
#define endl '\n'
#define rep(i,a,b) for(ll i=a; i<b; ++i)
#define per(i,a,b) for(ll i=b-1; i>=a; --i)

typedef vector<ll> V;
typedef vector<V> VV;
typedef set<ll> S;
typedef pair<ll,ll> pl;
typedef vector<pl> Vp;

#define all(v) v.begin(),v.end()
#define pb push_back
#define fs first
#define sc second

inline ll read(){
	ll x=0,ff=1;
	char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') ff=-1;ch=getchar();}
	while(isdigit(ch)) {x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*ff;
}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll pow1(ll p,ll d, ll P){return d?(pow1(p*p%P,d>>1,P)*(d&1?p:1))%P:1;}

V prime;
bool is_composite[MAXN];
void sieve (ll n){
	std::fill (is_composite, is_composite + n, false);
	rep(i,2,n){
		if(!is_composite[i]) prime.pb(i);
		for(ll j = 0; j < prime.size() && i*prime[j] < n; ++j){
			is_composite[i*prime[j]] = true;
			if(i % prime[j] == 0) break;
		}
	}
}
ll modInverse(ll a, ll m){
	ll m0=m,y=0,x=1;
	if(m==1) return 0;
	while(a>1){
		ll q=a/m,t=m;
		m=a%m;
		a=t; 
		t=y;

		y = x-q*y; 
		x = t;
	}
	if(x<0) x += m0;
	return x; 
}

void doit(){
	gi(n);
	ll a[n],b[100007]={0},s=0;
	rep(i,0,n) a[i]=read(), s+=a[i], ++b[a[i]];
	gi(q);
	rep(i,0,q){
		gi(p); gi(q);
		s+=(q-p)*b[p];
		b[q]+=b[p];
		b[p]=0;
		cout<<s<<endl;		
	}
}
int main(){
//	for(gi(t);t--;cout<<endl)
		doit();
	return 0;
}

Measured memory_bytes: 5192
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;

void chmax(string &a,string b){
	if(a=="-")a=b;
	else if(a.size()<b.size())a=b;
	else if(a.size()==b.size()){
		if(a<b)a=b;
	}
}

int match[10]={2,5,5,4,5,6,3,7,6};
string dp[11000];

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,m; cin >> n >> m;
	vector<int> a(m);
	for(int i=0;i<m;i++){
		cin >> a[i];
	}
	for(int i=0;i<11000;i++){
		dp[i]="-";
	}
	dp[0]="";
	for(int i=0;i<n;i++){
		if(dp[i]=="-")continue;
		for(int p:a){
			chmax(dp[i+match[p-1]],dp[i]+(char)('0'+p));
		}
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 44928
n=int(input())
s=int(input())
if s==n:
  print(n+1)
  exit()
def f(x):
  m=n
  t=0
  while m:
    t+=m%x
    m//=x
  return t
for b in range(2,int(n**0.5)+2):
  if f(b)==s:
    print(b)
    exit()
for p in range(1,int(n**0.5))[::-1]:
  q=s-p
  b=(n-s)//p+1
  if 1<=p<b and 0<=q<b and (n-s)%p==0:
    b=(n-s)//p+1
    if f(b)==s:
      print(b)
      exit()
print(-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
  int N,a;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N-1);

for (int i = 0;i<N;i++){
 cin >> A.at(i) ;
}
  for(int j = 0;j<N;j++){
  cin >> B.at(j);
  }
  for (int k = 0;k<(N-1);k++){
  cin >> C.at(k);
  }
  a = 0;
  for (int l = 0;l<N;l++){
  a += B.at(l);
  }
  for (int m = 0;m<(N-1);m++){
  if(A.at(m)+1==A.at(m+1)){
  a += C.at(A.at(m)-1);
  }
  }
  cout << a << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int f[110][15],p[110][15];
int sum=-INT_MAX;
int n;
void dfs(string s){
	if(s.size()==10){
		if(s.find('1')==string::npos)return ;
		int cnt=0;
		for(int i=0;i<n;i++){
			int ans=0;
			for(int j=0;j<10;j++){
				if(f[i][j]&&s[j]=='1'){
					ans++;
				}
			}
			cnt+=p[i][ans];
		}
		sum=max(cnt,sum);
		return;
	}
	dfs(s+'0');
	dfs(s+'1');
}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++){
			cin>>f[i][j];
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<11;j++){
			cin>>p[i][j];
		}
	}
	dfs("");
	cout<<sum<<endl;
	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

void solve(){
    ll x;
    cin >> x;

    ll a=0;
    // a = x % 11 > 6 ? 2 : 1;
    if (x % 11 != 0) {
        if (x % 11 > 6) {
            a = 2;
        }else{
            a = 1;
        }
    }
    cout << 2 * (x/11) + a << endl;
    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


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

typedef long long int ll;
typedef string str;

int main ()
{
	// ios::sync_with_stdio(0);
 //    cin.tie(0);
 //    cout.tie(0);
	ll t,n,m,k,i,a,b,j;
	cin >> n >> m;
	cout << n*m << "\n";
	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
#include <climits>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

int n,m,Q;
int l[200010];
int r[200010];
int p[100010];
int q[100010];
int a[510][510]={0};
int s[510][510]={0};

int main() {
    cin >> n >> m >> Q;
    REP(i,m){
        cin >> l[i] >> r[i];
    }
    REP(i,Q){
        cin >> p[i] >> q[i];
    }
    REP(i,m){
        a[r[i]][l[i]]++;
    }
    REP(i,n){
        REP(j,n){
            s[i+1][j+1]+=s[i+1][j]+a[i+1][j+1];
        }
    }
    REP(i,Q){
        int res = 0;
        FOR(j,p[i],q[i]+1){
            res += s[j][q[i]]-s[j][p[i]-1];
        }
        put(res);
    }
    return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)


signed main(){
    int n;
    cin >> n;
    int A[n];
    REP(i,n) cin >> A[i];
    sort(A,A+n);
    int ind = -1;
    REP(i,n){
        if(A[i] >= 0){
            ind = i;
            break;
        }
    }

    if(ind == -1){
        ind = n-1;
    }
    pair<int,int> res[n];
    int ans = A[0];
    if(ind ==0) ind = 1;
    int cnt = 0;
    FOR(i,ind,n-1){
        res[cnt].fi = ans;
        res[cnt].se = A[i];
        ans = ans - A[i];
        cnt ++;
    }
    res[cnt].fi = A[n-1];
    res[cnt].se = ans;
    ans = A[n-1] - ans;
    cnt ++;
    FOR(i,1,ind){
        res[cnt].fi = ans;
        res[cnt].se = A[i];
        ans -= A[i];
        cnt ++;
    }




    cout << ans << endl;
    REP(i,n-1){
        cout << res[i].fi << " "<< res[i].se << endl;
     }

}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Weverything"
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>
#pragma clang diagnostic pop

using namespace std;

int64_t solve(int64_t n, int64_t p) {
  std::vector<std::pair<int64_t, int64_t>> primes;
  while (p % 2 == 0) {
    if (primes.empty() || primes.back().first != 2) {
      primes.emplace_back(std::make_pair(2, 1));
    } else {
      primes.back().second++;
    }
    p /= 2;
  }
  auto const nn = static_cast<int64_t>(sqrt(p * 1.0));
  for (int64_t i = 3; i <= nn && p > 1 && i <= p; i += 2) {
    while (p % i == 0) {
      if (primes.empty() || primes.back().first != i) {
        primes.emplace_back(std::make_pair(i, 1));
      } else {
        primes.back().second++;
      }
      p /= i;
    }
  }
  if (p > 1) {
    primes.emplace_back(std::make_pair(p, 1));
  }
  int64_t ret = 1;
  for (auto& prime : primes) {
    while (prime.second >= n) {
      ret *= prime.first;
      prime.second -= n;
    }
  }
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int64_t n;
  std::cin >> n;
  int64_t p;
  std::cin >> p;
  auto const res = solve(n, p);
  std::cout << res << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <queue>
using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}

ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

int main(void) {
  int n, m;
  cin>>n>>m;
  priority_queue<int> q;
  for(int i=0; i<n; i++) {
    int x;
    cin>>x;
    q.push(x);
  }
  for(int i=0; i<m; i++) {
    int x = q.top();
    q.pop();
    q.push(x/2);
  }
  ll ans = 0;
  for(int i=0; i<n; i++) {
    ans += q.top();
    q.pop();
  }
  std::cout << ans << std::endl;
  return 0;
}



Measured memory_bytes: 892
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace abc121_a
{
    public class Program
    {
        static void Main(string[] args)
        {
            string[] input1 = Console.ReadLine().Split(' ');
            int H = int.Parse(input1[0]);
            int W = int.Parse(input1[1]);

            string[] input2 = Console.ReadLine().Split(' ');
            int h = int.Parse(input2[0]);
            int w = int.Parse(input2[1]);

            Console.WriteLine(WhiteCells(H,W,h,w));
            Console.Read();
        }

        public static int WhiteCells(int H, int W, int h, int w)
        {
            return (H - h) * (W - w);
        }

    }
}


Measured memory_bytes: 13140
using System;
using System.Linq;

class Program {
    static void Main() {
        int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int a = input[0];
        int b = input[1];
        int N = int.Parse(Console.ReadLine());
        int ans = 0;
        for (int i = 0; i < N; i++) {
            input = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int s = input[0];
            int f = input[1];
            if (!(f <= a || b <= s)) {
                ans = 1;
            }
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 9660
#include <iostream>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int main() {
    int n;
    cin >> n;
    ll a[100010];
    int b[100010] = {};
    int res = 0;
    REP(i,n){
        cin >> a[i];
    }
    REP(i,n){
        if(a[i]>100000){
            res++;
        }else{
            b[a[i]]++;
        }
    }
    REP(i,100001){
        if(b[i]>i){
            res += b[i]-i;
        }else if(b[i]<i){
            res += b[i];
        }
    }
    cout << res << endl;
    return 0;
}


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

int main() {
    char s[10];
    int ans = 0;
    scanf("%s", &s);
    if (strcmp(s, "SUN") == 0) {
        ans = 7;
    }
    if (strcmp(s, "MON") == 0) {
        ans = 6;
    }
    if (strcmp(s, "TUE") == 0) {
        ans = 5;
    }
    if (strcmp(s, "WED") == 0) {
        ans = 4;
    }
    if (strcmp(s, "THU") == 0) {
        ans = 3;
    }
    if (strcmp(s, "FRI") == 0) {
        ans = 2;
    }
    if (strcmp(s, "SAT") == 0) {
        ans = 1;
    }
    printf("%d", ans);

    return 0;
}


Measured memory_bytes: 128