akhauriyash/Code-Regression huggingface dataset:
#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <stack>
#include <list>
#include <math.h>
#include <map>
#include <iomanip>
#include <functional>
#include <string>
#include <algorithm>
#include <queue>
#include <set>

using namespace std;

template<class T> ostream& operator<<(ostream& os, const vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) os << *i << (i == end(v) - 1 ? "" : " "); return os;
}
template<class T> istream& operator>>(istream& is, vector<T>& v) {
	for (auto i = begin(v); i != end(v); i++) is >> *i; return is;
}


int main()
{
#if defined(_DEBUG) 
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	cout.tie(NULL);

	int n;
	cin >> n;

	vector<int> a, b;
	for (int i = 0; i < n; i++)
	{
		int tmp;
		cin >> tmp;
		a.push_back(tmp);
	}

	for (int i = 0; i < n; i++)
	{
		int tmp;
		cin >> tmp;
		b.push_back(tmp);
	}

	int ans = 0;
	for (int bit = 0; bit < 30; bit++)
	{
		vector<int> aa, bb;
		int mask = (2 << bit) - 1;
		for (int x : a)
		{
			aa.push_back(x & mask);
		}

		for (int x : b)
		{
			bb.push_back(x & mask);
		}

//		sort(aa.begin(), aa.end());
		sort(bb.begin(), bb.end());
		int bit_val = 0;
		for (int x : aa)
		{
			int maxbit = (1 << bit) & x;
			if (maxbit == 0)
			{
				int from = (1 << bit) - x;
				int to = mask - x;

				auto from_it = lower_bound(bb.begin(), bb.end(), from);
				auto to_it = upper_bound(bb.begin(), bb.end(), to);
				bit_val ^= (to_it - from_it) % 2;
			}
			else
			{
				int from = (1 << (bit + 1)) - x;
				int to = from + (1 << bit) - 1;
				auto from_it = lower_bound(bb.begin(), bb.end(), from);
				auto to_it = upper_bound(bb.begin(), bb.end(), to);
				int cnt1 = bb.size() - (to_it - from_it);
				bit_val ^= cnt1 % 2;
			}
		}
		ans |= bit_val * (1 << bit);
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 4492
#include<bits/stdc++.h>
#define ll long long
#define ljc 998244353
using namespace std;
#define gc getchar
inline ll read(){
    register ll x=0,f=1;char ch=gc();
    while (!isdigit(ch)){if (ch=='-') f=-1;ch=gc();}
    while (isdigit(ch)){x=(x<<3)+(x<<1)+ch-'0';ch=gc();}
    return (f==1)?x:-x;
}
char A[10101],B[10101];
int n,L[10101],R[10101];
int tot,B1,cac[10101];
inline int gr(int x,int y){return (x+y%n+n)%n;}
inline int gl(int x,int y){return (x-y%n+n)%n;}
inline int solve(int c){
	int COST=0,one=0,_=0x3f3f3f3f,xmi=0;
	tot=0;
	for (int i=0;i<=n;i++) cac[i]=0;
	for (int i=0;i<n;i++){
		if (A[i]=='1'){
			if (B[gr(i,c)]=='0'){
				COST++;
				cac[L[i]]=max(cac[L[i]],R[i]);	
			}else one++;
		}
	}
	if (c>0) cac[n+1]=c;
	else xmi=-c;
	COST+=B1-one;
	for (int i=n;i>=xmi;i--){
		cac[i]=max(cac[i],cac[i+1]);
		_=min(_,cac[i+1]+i);
	}
	if (c<0){
		return 2*_+COST+c;
	}else{
		return 2*_+COST-c;
	}
}
signed main(){
	scanf("%s",A);scanf("%s",B);
	n=strlen(A);
	B1=count(B,B+n,'1');
	if (!B1){
		puts(count(A,A+n,'1')?"-1":"0");
		return 0;
	}
	int _=0x3f3f3f3f;
	for (int i=0,x,y;i<n;i++){
		x=y=i;
		while (B[x]=='0') L[i]++,x=gl(x,1);
		while (B[y]=='0') R[i]++,y=gr(y,1);
	}
	for (int i=-2*n;i<=2*n;i++) 
		_=min(_,solve(i));
	cout<<_;
	return 0;
}



Measured memory_bytes: 3820
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(deprecated)]

use std::cell::{Cell, Ref, RefCell, RefMut};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;
use std::usize;

const MOD_10_9_7: u64 = 1_000_000_007;
const INF: i64 = 1_000_000_000_000;
const MIN_INF: i64 = -1_000_000_000_000;

/// FYI: https://github.com/vain0x/scan-bench
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let n = read!(usize);
    let mut f: Vec<Vec<usize>> = Vec::with_capacity(n);
    for i in 0..n {
        f.push(read![[usize]]);
    }
    let mut p: Vec<Vec<i32>> = Vec::with_capacity(n);
    for i in 0..n {
        p.push(read![[i32]]);
    }
    //    let f = read!(usize, usize, usize, usize, usize, usize, usize, usize, usize, usize; n);
    //    let p = read!(i32, i32, i32, i32, i32, i32, i32, i32, i32, i32, i32; n);

    let mut ans = -1_000_000_000;

    // bit全探索
    for o in 1..2i32.pow(10) {
        let mut c = vec![0; n]; // 商店街の店xと同時に開店している時間帯の個数
        for i in 0..10 {
            if 1 << i & o != 0 {
                // 店jがオープンしているか
                for j in 0..n {
                    if f[j][i] == 1 {
                        c[j] += 1;
                    }
                }
            }
        }
        let mut t_sum = 0;
        for i in 0..n {
            t_sum += p[i][c[i]];
        }
        if t_sum > ans {
            ans = t_sum;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<stdlib.h>
#include<limits.h>

int matrixChainOrder(int);
int min(int, int, int);

int second[101];
int m[101][101];

main(){
  int n, i;

  int min;

  scanf("%d", &n);
  
  for(i = 1; i <= n; i++){
    
    scanf("%d %d", &m[i][0], &m[i][1]);
    
  }
  
  for(i = 0; i < n; i++){

    second[i] = m[i+1][0];
 
  }
  second[n] = m[n][1];
  i = matrixChainOrder(n);
  printf("%d\n",m[1][i]);
 
 return 0;

}

int matrixChainOrder(int n){
  
  int i, l, j, k, q;
  
  for(i = 1; i <= n; i++){
    
    m[i][i] = 0;
  
  }
 
  for(l = 2; l <= n; l++){
    for(i = 1; i <= n - l + 1; i++){
      
      j = i + l - 1;
      
      m[i][j] = INT_MAX;
      
      for(k = i; k <= j-1; k++){
	
	q = m[i][k] + m[k+1][j] + second[i-1]*second[k]*second[j];
	 
	m[i][j]	= min(i, j, q);

	//	printf("%d %d %d\n",i,j,m[i][j]);

      }
    }
  }
  return j;
}

int min(int i, int j, int min){

  if(m[i][j] > min)
    return min;

  return m[i][j];
}


    

Measured memory_bytes: 636
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

def func(a,b,c):
    return (a - 2 * (a//2)) * b * c

a,b,c = map(int,input().split())
print(min(func(a,b,c),func(b,c,a),func(c,a,b)))


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    if(n%10==2)
        cout<<"hon"<<endl;
    else if(n%10==4)
        cout<<"hon"<<endl;
        else if(n%10==4)
        cout<<"hon"<<endl;
        else if(n%10==5)
        cout<<"hon"<<endl;
        else if(n%10==7)
        cout<<"hon"<<endl;
        else if(n%10==9)
        cout<<"hon"<<endl;
    else if(n%10==0)
        cout<<"pon"<<endl;
        else if(n%10==1)
        cout<<"pon"<<endl;
        else if(n%10==6)
        cout<<"pon"<<endl;
        else if(n%10==8)
        cout<<"pon"<<endl;
    else cout<<"bon"<<endl;
    return 0;
}

Measured memory_bytes: 3036
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]

L = []
for i in range(N):
  for j in range(i + 1, N):
    L.append([A[i][j], i, j])

ans = 0
for i in range(N - 1):
  for j in range(i + 1, N):
    for k in range(N):
      if i == k: continue
      if j == k: continue
      if A[i][j] > A[i][k] + A[k][j]:
        print(-1)
        exit()
      if A[i][j] == A[i][k] + A[k][j]:
        break
    else:
      ans += A[i][j]

print(ans)

Measured memory_bytes: 48348
#include<stdio.h>
int main() {
 int n, a[200000], i;
 long s = 0, e, d, d2;
 scanf("%d", &n);
 for(i=0; i<n; i++) {
  scanf("%d", a+i);
  s += a[i];
 }
 for(d=s/2, i=0, e=0; 1; i++) {
  e+=a[i];
  if(e>=d) break;
 }
 d = 2*e-s;
 d *= d<0?-1:1;
 d2 = 2*(e-a[i])-s;
 d2 *= d2<0?-1:1;
 printf("%ld", d<d2?d:d2);
}

Measured memory_bytes: 896
#include<cstdio>

int main()
{
	int n,m,c;
	scanf("%d%d%d",&n,&m,&c);
	int a[n][m],b[n],i,j;
	for(i=0;i<m;i++)
	scanf("%d",b+i);
	
	for(i=0;i<n;i++)
	{
		for(j=0;j<m;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	long long max,g=0;
	for(i=0;i<n;i++)
	{
		max=c;
		for(j=0;j<m;j++)
		{
			max+=a[i][j]*b[j];
		}
		if(max>0)
		g++;
	}
	printf("%lld",g);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;

int main(){
  string s;cin>>s;
  char pre = 'a';int ans = 0;
  rep(i,s.length()){
    if(pre != s[i]){
      ans++;
      pre = s[i];
    }
  }
  cout << ans - 1 <<endl;
}


Measured memory_bytes: 512
import math
n,m=map(int,input().split())
ans = 0
two = math.factorial(2)
if n >= 2:
    ans += math.factorial(n)//(two*math.factorial(n-2))
else:
    ans += 0
if m >= 2:
    ans += math.factorial(m)//(two*math.factorial(m-2))
else:
    ans += 0
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define MAX 100005
#define MOD 1e9
#define pb push_back
#define pairs pair<int, int>
#define vi vector<int>
#define vb vector<bool>
#define vii vector<pairs>
#define lb lower_bound
#define ub upper_bound
#define ll long long
#define endl '\n'
using namespace std;
/* ----------------------------------------------------------------------------------- */

#define FastInput ios_base::sync_with_stdio(false), cin.tie(NULL);
#define all(x) x.begin(), x.end()
#define scan(a) scanf("%d", &a)
#define print(a) printf("%d\n", a);
#define read(x) freopen(x, "r", stdin)
#define write(x) freopen(x, "w", stdout)
#define rep(i, a, n) for (int i = a; i < n; i++)
#define REP(i, a, n) for (int i = a; i <= n; i++)
#define inputArray(a,n) rep(i, 0, n) cin >> a[i];
#define copyArray(a,temp,n) rep(i, 0, n) temp[i]=a[i];
#define printArray(a,n) rep(i, 0, n) cout << a[i] << " "; cout << endl;

/* ----------------------------------------------------------------------------------- */

#define Cases  cout << "Case " << ++Case << ": ";
#define __test int tt; int Case=0; cin >> tt; while(tt--)

#define dbgA2(A, n, m) {cout<<"--> "<<#A<<" = \n";rep(i, 0, n){rep(j, 0, n){cout<<A[i][j]<<" ";}cout<<"\n";}cout<<"\n";}
#define dbgA(A, n) {cout<<" --> "<<#A<<" = (";rep(i, 0, n)cout<<A[i]<<" ";cout<<")\n";}
#define dbg(args...) {string sss(#args);sss+=',';cout<<" --> ";debugger::call(all(sss), args);cout<<"\n";}

/* ----------------------------------------------------------------------------------- */

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }

struct debugger {
    typedef string::iterator si;
    static void call(si it, si ed) {}
    template<typename T, typename ... aT>
    static void call(si it, si ed, T a, aT... rest) {
        string b;
        for(; *it!=','; ++it)
            if(*it!=' ')
                b+=*it;
        cout << b << "=" << a << " ";
        call(++it, ed, rest...);
    }
};

/* ----------------------------------------------------------------------------------- */

vi g[MAX];
vi h(MAX);
vi connect(MAX);

void solve() {
	int n, m;
	cin >> n >> m;
	int ans = 0;
	REP(i, 1, n) {
        g[i].clear();
    }
    REP(i, 1, n) {
        scan(h[i]);
    }
	REP(i, 1, m) {
		int u, v;
        scan(u);
        scan(v);
        g[u].pb(v);
        g[v].pb(u);
	}

	REP(i, 1, n) {
        bool on = 1;
        for(auto it : g[i]) {
            if(h[it] >= h[i]) {
                on = 0;
                break;
            }
        }
        if(on) {
            ans++;
        }
    }

	print(ans);

}

int main() {
    solve();

    // __test {
    //     solve();
    // }
}

Measured memory_bytes: 9440
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    string S;
    cin >> S;
    sort(ALL(S));
    if (S == "abc") {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}


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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
        a[i]--;
    }
    vector<bool> check(n,false);
    check[0] = true;
    int i = a[0];
    int cnt=1;
    bool stop = false;
    if(i==1) stop = true;
    while(!check[i]){
        check[i] = true;
        i = a[i];
        if(!stop){
            cnt++;
        }
        if(i==1) stop = true;
    }
    if(!check[1]) cout << -1 << endl;
    else cout << cnt << endl;
}


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

/*
,,,,
　　　　　　　　　　　　　　　　　　　　　　　　　　,.斗*''“i:i:{
　　　　　　　　　　　　　,.　｡. . . * : : : ''' : : : :” :”“ ''ｰ - 弋,,_
　　　　　 　 　 ,.斗*''“ : : : : : : : : : : : : : ' ' ' ' ' ' : : : : : : : : : : :”: '':* ｡ ,
　　　 ,.斗*''“ ” ＼：　　 ”・・． ' ' ' '　　　　　　　　 ' ' ' ' : : : : : : : : : : : : ”ミ*｡,,,,,,　　　　　　 　 　 　 ＿
　　く.　 ◎　 ﾞ:.ﾞ:..　ﾟ:,　:　───────────　　　--　　,,,,,,__ ' ' ' :.:.:.:.:.”≧s｡.　　＿,,,｡s*i:i:i:i:<
　　ﾏ*s｡ :,　 }　ﾟ:,　 :}　　　　　　　　　　　　　　　　　　　　　　　　　　　　”　''　-　”””：：”：：`*｡i:i:i:i:i:i:i;:’
　　　` .｡`　 ,　,ノ ／｡ ,,,_　　　　　　　　　　　　　　　　　　　　　　　　　　　　　＿＿`　　} }　　ﾉi:i:i:i:i:ﾂ
　　　　　 `　*　｡　　`*｡i:i:i::*=-　　　　　　　　　　　＿＿　　　　　　,,,....｡s*'i,:’　　　”`*｡＿,*’i:i:i:i:r’
　　　　　　　　　　　”　─ --　　　　｡｡｡｡｡　　 -　－`''''''''ヽ ─ '''”　　　｀ｰ“　　　　　　　`*｡i:i:i:i:i:i:
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　`*｡i:i:::
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　`*ﾟ:,
         fozubaoyou    no BUGs alive!
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define debug_interval ','
#define dump_interval endl
#define debug_toggle 0

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cout<<endl;}
template<class...A> inline void debug_rest() {cout<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cout<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cout<<first,debug_rest(rest...);}

int n;
ll a=1;

int main(){
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;i++){
      a*=i;
      a%=(ll)1e9+7;
    }
    dump(a);
  }

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

int main() {
  int n, w;
  cin >> n >> w;
  long long  dp[n+1][w+1];
  long long  weight[n];
  long long  value[n];
  for (int i = 0; i < n; i++){
    cin >> weight[i] >> value[i];
    dp[i][0] = 0;
  }
  for (int i = 0; i <= w; i++){
    dp[0][i] = 0;
  }
  for (int i = 0; i < n; i++){
    for (long long  j = 0; j <= w; j++){
      if (j >= weight[i]){
        dp[i+1][j] = max(dp[i][j-weight[i]] + value[i], dp[i][j]);
      }else{
        dp[i+1][j] = dp[i][j];
      }
    }
  }
  cout << dp[n][w] << endl;
}


Measured memory_bytes: 79104
import java.io.*;
import java.util.*;
class Main
{
  public static void main(String ar[])
  {
	Scanner sc=new Scanner(System.in);
    long n=sc.nextLong();
    long a=sc.nextLong();
    long b=sc.nextLong();
    long ans=a*(n/(a+b))+(long)Math.min(n%(a+b),a);
    System.out.println(ans);
  }
}
  

Measured memory_bytes: 35776
#include <bits/stdc++.h>
 
#define int long long
 
using namespace std;
 
int pw (int x) {
    int ans = 1;
    for (int i = 1; i <= x; i++) ans *= 10;
    return ans;
}
 
void solve(){
    int pos = 0;
    for (int i = 1; i <= 10; i++) {
        cout << "? " << pw(i) << endl;
        string s;
        cin >> s;
 
        if (s == "N") {
            pos = i;
            break;
        }
    }
 
    if (!pos) {
        for (int i = 0; i <= 9; i++) {
            cout << "? " << pw(i) + 1 << endl;
            string s;
            cin >> s;
 
            if (s == "Y") {
                cout << "! " << pw(i) << endl;
                return;
            }
        }
    }
 
    int l = pw(pos - 1);
    int r = pw(pos) - 1;
 
    while (l <= r) {
        int mid = (l + r) >> 1;
        cout << "? " << mid * 10 << endl;
        string s;
        cin >> s;
 
        if (s == "Y") r = mid - 1;
        else l = mid + 1;
    }
 
    cout << "!" << " " << l << endl;
    return;
}
 
signed main(){
    solve();
}

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int n, m;
ll dp[2001][2001] = {};

int main() {
  cin >> n >> m;
  int s[n], t[m];
  REP(i, n) cin >> s[i];
  REP(i, m) cin >> t[i];
  dp[0][0] = 1;
  REP1(i, n) dp[i][0] = 1;
  REP1(i, m) dp[0][i] = 1;
  REP(i, n) REP(j, m) {
    dp[i + 1][j + 1] += dp[i + 1][j] + dp[i][j + 1];
    dp[i + 1][j + 1] %= MOD;
    dp[i + 1][j + 1] += MOD - dp[i][j];
    dp[i + 1][j + 1] %= MOD;
    if (s[i] == t[j]) {
      dp[i + 1][j + 1] += dp[i][j];
      dp[i + 1][j + 1] %= MOD;
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}

Measured memory_bytes: 31488
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
C = [int(i) for i in input().split()]

m = 0
before = 0
for a in A:
    m += B[a-1]
    if before != 0:
        if before+1 == a:
            m += C[before-1]
    before = a
    #print(m)
    #print(before)

print(m)

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

using namespace std;

#define F first
#define S second
#define tm akljdf

const int MAXN = 500 + 3;

int n, ans = 1e9;
string s[MAXN];
bool mark[MAXN][MAXN], tm[MAXN][MAXN];

bool sec[MAXN];
void go(int r, int c){
	for (int j = 0; j < n; j++) sec[j] = mark[r][j];
	for (int i = 0; i < n; i++)
		mark[i][c] = sec[i];
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	bool found = 0;
	pair<int, int> p;
	for (int i = 0; i < n; i++){
		cin >> s[i];
		for (int j = 0; j < n; j++)
			if (s[i][j] == '#')
				mark[i][j] = 1, found = 1, p={i, j};
	}
	if (!found){
		cout << "-1\n";
		return 0;
	}

	for (int i = 0; i < n; i++){
		int ret = 0;
		memcpy(tm, mark, sizeof(mark));
		
		int row = -1;
		for (int j = 0; j < n; j++)
			if (mark[j][i]){
				row = j;
				break;
			}
	
		if (row == -1){
			go(p.F, i);
			ret++;
			for (int j = 0; j < n; j++)
				if (mark[j][i]){
					row = j;
					break;
				}
		}

		for (int j = 0; j < n; j++)
			if (!mark[i][j])
				ret++, go(row, j);

		for (int c = 0; c < n; c++){
			bool done = 0;
			for (int r = 0; !done && r < n; r++)
				if (!mark[r][c]) done = 1;
			if (done)
				ret++;
		}
		
		ans = min(ans, ret);
		memcpy(mark, tm, sizeof(tm));
	}

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


Measured memory_bytes: 1024
#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 INF 1e9


int main() {
    int N;
    cin >> N;
    string s;
    vector<int> S(N);
    cin >> s;
    for (int i=0; i<N; i++){
        S[i] = s[i]-'0';
    }
    

    if (N< 1){
        cout << 0 << endl;
    }
    else if (N>=1 && N<3){
        cout << 1 << endl;
    }
    else{
        int count = 0;
        for (int i=0; i<1000; i++){
            int num[3] = {(i/100)%10, (i/10)%10, i%10};
            int check = 0;
            for (int j=0; j<N; j++){
                if (S[j] == num[check]){
                    check++;
                }
                if(check == 3)break;
            }
            if(check == 3)count++;
        }
        cout << count << endl;
    }

    return 0;
}


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

int main() {
    int number = 0;
    cin >> number;
    int area = number + 1;
    vector<int64_t> lucas(area);
    for (int i = 0; i < area; ++i) {
        if (i == 0) {
            lucas.at(i) = 2;
        }
        if (i == 1) {
            lucas.at(i) = 1;
        }
        if (i >= 2) {
            lucas.at(i) = lucas.at(i-1) + lucas.at(i-2);
        }
    }
    
    cout << lucas.at(number) << endl;
}



Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
from collections import Counter

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    c = Counter(A)
    mi = min(A)+1
    m = c[mi-1] + c[mi] + c[mi+1]
    ans = m
    for i in range(mi+1, max(A)):
        m -= c[i-2]
        m += c[i+1]
        ans = max(ans, m)
    
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 14564
fun main(args: Array<String>) {
    diverta20192b()
}

fun diverta20192b() {
    val n = readLine()!!.toInt()
    val coordinates = (1..n).map { readLine()!!.split(' ').map { it.toLong() } }
        .map { Pair(it[0], it[1]) }.sortedBy { it.second }.sortedBy { it.first }

    if (n == 1) return println(1)

    val diffMap = mutableMapOf<Pair<Long, Long>, Int>()

    for (i1 in 0..coordinates.lastIndex) {
        for (i2 in i1 + 1..coordinates.lastIndex) {
            val c1 = coordinates[i1]
            val c2 = coordinates[i2]
            val diff = Pair( c1.first - c2.first, c1.second - c2.second)
            diffMap.put(diff, diffMap.getOrElse(diff, { 0 }) + 1)
        }
    }

    val answer = n - diffMap.map { it.value }.max()!!

    println(answer)
}


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

long n,m,ans=0;
vector<long> a(100),b(100);
set<long> ab;

void zts(vector<long> x,long y) {
  if(x.size()==n) {
    bool a=true;
    for(long i=0;i<n-1;i++) {
      if(!(ab.count(x[i]*100+x[i+1]))) a=false;
    }
    if(a)ans++;
    return;
  }
  for(long i=0;i<n;i++) {
    if(!((1<<i)&y)) {
      vector<long> xx=x;
      xx.push_back(i);
      zts(xx,y+(1<<i));
    }
  }
  return;
}

int main() {
  cin >> n >> m;
  for(long i=0;i<m;i++) {
    cin >> a[i] >> b[i];
    ab.insert((a[i]-1)*100+(b[i]-1));
    ab.insert((b[i]-1)*100+(a[i]-1));
  }
  zts({0},1);
  
  cout << ans << endl;
}

Measured memory_bytes: 3632
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

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

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

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

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

fn main() {
    input! {
        n: usize,
        mut v: [u64; n],
    }
    //let mut que = BinaryHeap::new();
    v.sort();
    v.reverse();

    let mut v_: Vec<f64> = vec![];
    for i in 0..n {
        v_.push(v[i] as f64);
    }

    let mut ans = 0;
    for i in 0..n - 1 {
        let acc_1 = v_.pop().unwrap() as f64;
        let acc_2 = v_.pop().unwrap() as f64;
        let acc = (acc_1 + acc_2) / 2.;
        v_.push(acc);
    }

    println!("{}", v_[0]);
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <cstring>
#include <map>
using namespace std;

#define mp make_pair
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n) REP(i,0,n)

int N, M, r, q;
bool used[10000][2000];

void solve() {
  memset(used, false, sizeof used);
  cin>>r;
  
  map<int,int> login[M];
  rep(i,r) {
    int t, n, m, s;
    cin>>t>>n>>m>>s; m--;
    if (s == 1) {
      login[m].insert(mp(n,t));
    } else {
      map<int,int>::iterator it = login[m].begin();
      while (it != login[m].end()) {
        if (it->first == n) {
          REP(j,it->second,t) used[m][j] = true;
          login[m].erase(it);
          break;
        }
        it++;
      }
    }
  }
  
  cin>>q;
  rep(i,q) {
    int ts, te, m, res = 0;
    cin>>ts>>te>>m; m--;
    REP(i,ts,te) if (used[m][i])
      res++;
    cout<<res<<endl;
  }
}

int main (int argc, char const* argv[]) {
  while (cin>>N>>M, N||M) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 20000
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
a=get_i.sort!
cnt_ps=a.count{|x| x>=0}
cnt_ng=a.count{|x| x<=0}
if cnt_ps==N
    ans=[]
    num1=a.pop
    num2=a.shift
    a.each do|a_|
        ans.push([num2,a_])
        num2-=a_
    end
    ans.push([num1,num2])
    num1-=num2
    puts num1
    ans.each do|arr|
        puts arr.join(" ")
    end
elsif cnt_ng==N
    ans=[]
    num=a.pop
    a.each do|a_|
        ans.push([num,a_])
        num-=a_
    end
    puts num
    ans.each do|arr|
        puts arr.join(" ")
    end
else
    ps=a.select{|x| x>0}
    ng=a.select{|x| x<=0}
    num1=ps.pop
    num2=ng.pop
    ans=[]
    ps.each do|n|
        ans.push([num2,n])
        num2-=n
    end
    ng.each do|n|
        ans.push([num1,n])
        num1-=n
    end
    ans.push([num1,num2])
    num1-=num2
    puts num1
    ans.each do|arr|
        puts arr.join(" ")
    end
end

Measured memory_bytes: 25636
#!/usr/bin/env python3
import sys
import math
# from decimal import *
from fractions import *


def solve(A: int, B: int, N: int):
    def kansuu(x):
        # return math.floor(A*x/B) - A * math.floor(x/B)
        left = math.floor(Fraction(A) * Fraction(x) * Fraction(1, B))
        right = Fraction(A) * math.floor(Fraction(x, B))
        return left - right

    saidaibaisuu = (N // B) * B
    if saidaibaisuu == 0:
        print(kansuu(N))
        exit()
    else:
        print(kansuu(saidaibaisuu-1))
        exit()

    return


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


if __name__ == '__main__':
    main()


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

#define INF ((1<<30)-1)
#define LLINF (1LL<<60)
#define EPS (1e-10)

int main() {
    int n;
    set<string> s;

    cin >> n;
    rep(i, n) {
        string tmp;
        cin >> tmp;
        s.insert(tmp);
    }
    cout << s.size() << endl;
}


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

int main()
{
  ll x, count;
  count = 0;
  cin >> x;

  count += x / 11;
  count *= 2;
  int a = x % 11;
  if (a > 0 && a <= 6)
  {
    count++;
  }
  else if (a > 6)
  {
    count += 2;
  }

  cout << count << endl;
}


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

const string YES = "Yes";
const string NO = "No";

void solve(long long N){
    string s = to_string(N);
    if ((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3]))
        cout << YES << '\n';
    else
        cout << NO << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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


int main() {
  int N, M;
  cin >> N >> M;
  priority_queue<ll> A;
  for (int i = 0; i < N; ++i) {
    ll ai;
    cin >> ai;
    A.push(ai);
  }
  for (int i = 0; i < M; ++i) {
    ll ai = A.top();
    A.pop();
    ai /= 2;
    A.push(ai);
  }
  ll result = 0;
  for (int i = 0; i < N; ++i) {
    result += A.top();
    A.pop();
  }
  cout << result << endl;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF=1e9;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};

int main(){
  int n;
  cin>>n;
  map<string,int> mp;
  rep(i,n){
    string s;
    cin>>s;
    mp[s]++;
  }
  int mx=0;
  for(auto x:mp) mx=max(mx,x.second);
  for(auto x:mp){
    if(x.second==mx){
      cout<<x.first<<endl;
    }
  }
}

Measured memory_bytes: 19184
#include<stdio.h>
#include<string.h>
 
typedef struct {
  char name[100];
  int t;
}Queue;
 
Queue Q[100000];
int n, head = 0, tail = 0;
 
void enqueue(Queue x){
 
  if(tail == n){
    tail = 1;
  } else {
    tail++;
  }
 
  Q[tail] = x;
}
 
Queue dequeue(){
  if(head == n){
    head = 1;
  } 
  else {
    head++;
  }
  return Q[head];
}

int main(){
  int i, q, cnt = 0, time = 0;
  Queue cell;
  
  scanf("%d %d",&n,&q);
  
  for (i = 1; i <= n; i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }
  
  while(cnt != n){
    cell = dequeue();
    if(cell.t - q <= 0){
      time += cell.t;
      cell.t = 0; 
      cnt++;
     
      printf("%s %d",cell.name ,time);
      printf("\n");    
  
    } else if (cell.t > 0){
      time += q;     
      cell.t -= q;
      enqueue(cell);
    }
    
  }
 
 return 0;

}

Measured memory_bytes: 6744
#include<bits/stdc++.h>
using namespace std;
int N,MIN=1000,MAX=-1000,ANS,COST;
int arr[101];
int main()
{
	scanf("%d",&N);
	for(int i=0;i<N;++i)
	{
		scanf("%d",&arr[i]);
		MIN=min(MIN,arr[i]);
		MAX=max(MAX,arr[i]);
	}
	ANS=2000000000;
	while(MIN<=MAX)
	{
		COST=0;
		for(int i=0;i<N;++i)
			COST+=abs(MIN-arr[i])*abs(MIN-arr[i]);
		ANS=min(ANS,COST);
		MIN++;
	}
	printf("%d\n",ANS);
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

class Dmondai
{
    static void Main()
    {
        var line = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var N = line[0];
        var K = line[1];
        var list = new List<long[]>();
        var netaAllCount = 0L;
        for (int i=0;i<N;++i)
        {
            var line1 = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray();
            list.Add(new long[2]{ line1[0],line1[1]});
        }
        list = list.OrderBy(x => x[0]).ThenByDescending(x => x[1]).ToList();
        for (int i=N-1;0<i;--i)
        {
            if (list[i][0] != list[i - 1][0])
            {
                list[i][0] = 1;
                netaAllCount++;
            }
            else list[i][0] = 0;
        }
        list[0][0] = 1;
        list = list.OrderByDescending(x => x[1]).ThenByDescending(x=>x[0]).ToList();
        var selectedList = list.Take(K).ToList();
        var selectedNeta = 0L;
        var selectedOishisa = 0L;
        var stack = new Stack<long>();
        for (int i=0;i<K;++i)
        {
            selectedNeta += selectedList[i][0];
            selectedOishisa += selectedList[i][1];
            if (selectedList[i][0] == 0) stack.Push(selectedList[i][1]);
        }
        var ans = selectedOishisa + selectedNeta * selectedNeta;
        for (int i=K;i<N;++i)
        {
            if (list[i][0] == 0) continue;
            if (/*K <= selectedNeta ||*/ stack.Count() < 1 /*|| netaAllCount <= selectedNeta*/) break;
            selectedNeta += list[i][0];
            selectedOishisa = selectedOishisa + list[i][1] - stack.Pop();
            var temp= selectedOishisa + selectedNeta * selectedNeta;
            ans = temp < ans ? ans : temp;
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 35504
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


int N;
int X[100000];
int L[100000];



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

	cin >> N;
	rep(i, N) {
		cin >> X[i] >> L[i];
	}
	vector<pair<int, int>> v;
	rep(i, N)v.emplace_back(X[i] + L[i], i);
	sort(all(v));

	int last = X[v[0].second] + L[v[0].second];
	int ans = 1;
	for (int i = 1; i < N; i++) {
		int st = X[v[i].second] - L[v[i].second];

		if (last <= st) {
			ans++;
			last = v[i].first;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2168
n = int(input())
dp = [{} for i in range(0, n + 1)]

for i in "ATGC":
    for j in "ATGC":
        for k in "ATGC":
            dp[3][i + j + k] = 1
            
del dp[3]["AGC"]
del dp[3]["ACG"]
del dp[3]["GAC"]

def add(i, k, v):
    global dp
    if k in dp[i]:
        dp[i][k] += v
    else:
        dp[i][k] = v

for i in range(4, n + 1):
    for k in dp[i - 1].keys():
        for c in "ATGC":
            l3 = k[1:] + c
            l4 = k + c
            if l3 != "AGC" and l3 != "ACG" and l3 != "GAC" and l4 != "AGGC" and l4 != "AGTC" and l4 != "ATGC":
                add(i, l3, dp[i - 1][k])

print(sum(dp[n].values()) % (10**9 + 7))

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

int main() {
  vector<int> x(5);
  rep(i,5) {
    cin>> x.at(i);
    if(x.at(i)==0) {
      cout << i+1 << endl;
      return 0;
    }
  }
}


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

int a,b;
int main(){
    cin>>a>>b;
    if(a>=13){
        cout<<b<<endl;
    }
    else if(a>=6&&a<=12){
        cout<<b/2<<endl;
    }
    else{
        cout<<0<<endl;
    }
}

Measured memory_bytes: 256
N = int(input())
L = []
K = []
S = 0
for i in range(N):
  L.append(list(map(int,input().split())))
for i in range(N):
  S += -L[i][1]
for i in range(N):
  K.append(L[i][0]+L[i][1])
K.sort()
K.reverse()
if N%2 == 0:
  for i in range(N//2):
    S += K[i*2]
else:
  for i in range(N//2+1):
    S += K[i*2]
print(S)

Measured memory_bytes: 31872
/* 
	Author: ankrypt
*/

#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<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define all(x) x.begin(), x.end() 
#define ub upper_bound
#define lb lower_bound
#define MAX_INT 1005
#define PI 3.141592653589793
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fi(a, b, c, d) for(int a = b; a < c; a += d)
#define fl(a, b, c, d) for(ll a = b; a < c; a += d)
#define fei(a, b, c, d) for(int a = b; a <= c; a += d)
#define fel(a, b, c, d) for(ll a = b; a <= c; a += d)
#define quit exit(0)
#define mem(x, a) memset(x, a, sizeof x)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pcl pair<char, ll>
#define psl pair<string, ll>


ll N, M, A, B, C;
ll arr[MAX_INT], arr1[MAX_INT], data[MAX_INT];
vector<ll> V;
unordered_map<ll, ll> mp;
set<ll> s;
string S = "";
ll cases;

int main() {
	go;
    cin >> N >> M;
    fi(i, 0, N, 1) {
    	cin >> arr[i];
    }
    sort(arr, arr + N);
    ll sum = 0;
    fi(i, 0, M, 1) {
    	sum += arr[i];
    }
    cout << sum << " \n";
	return 0;
}
/*
	Powered by Buggy Plugin
*/




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

long long c[100001];
long long cost(int arr[],int n,int k)
{
    long long mi;
    if(n==2)
        return abs(arr[2]-arr[1]);
    if(n==1)
        return 0;
    if(c[n] != -1)
        return c[n];
    mi=cost(arr,n-1,k)+abs(arr[n]-arr[n-1]);
    for(int i=2 ;i<=k && i<=n-1;i++)
    {
        if((cost(arr,n-i,k)+abs(arr[n]-arr[n-i]))<mi)
            mi=cost(arr,n-i,k)+abs(arr[n]-arr[n-i]);
    }
    c[n]=mi;
    return mi;
}
int main()
{
    long long n,ans,k;
    cin>>n>>k;
    memset(c,-1,sizeof(c));
    int arr[n+1];
    for(int i=1;i<=n;++i)
        cin>>arr[i];
    ans=cost(arr,n,k);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 10752
/*
    quid-pro-quo: LOGIC for AC
    written by: codercell07
    LANG: C++ 11
    Problem: random
*/
#include<bits/stdc++.h>
#define fastio ios::sync_with_stdio(false); cin.tie(NULL)
#define testcases freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout)
#define ui unsigned int
#define ll long long
#define pb push_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define sz(x) (int)x.size()
#define pq priority_queue /*maxim at top(max-heap)*/
#define pqmax priority_queue<int, vector<int>, greater<int>> /*minim at top(min-heap)*/
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define asc(x) sort(all(x))
#define desc(x) sort(all(x), greater<int>())
#define time_el (double)time/CLOCKS_PER_SEC
using namespace std;
const int MAX=2e6; //dummy, make sure change as per constraints
const ll M=1e9+7, inf=1e18;
const char nl='\n';
 
ll apbmc(ll a, ll b, ll c){ a%=c; ll res=1; while(b){ if(b&1) res=res*a%c; a=a*a%c; b>>=1; } return res;}
ll apb(ll x, ll y){ ll temp; if(y==0) return 1;  temp=apb(x, y/2); if(y%2==0) return temp*temp;  else return temp*temp*x;}
 
 
 
void solve(){
    //clock_t time;
    int n; cin>>n;
    for(int i=0; i<n; i++){
        cout<<"ACL";
    }
 
 
}
 
int main(){
    fastio;
    // #ifndef ONLINE_JUDGE
    //     testcases;
    // #endif // !DEBUG
    cout<<fixed<<setprecision(10);
    
    //int t; cin>>t; while(t--) solve();
    solve();
 
    return 0;
}
//points to check:
//  * check for constraints, mainly array!
//  * EDGE CASES
//  * check for integer overflow, use long long!
//  * learn, do, solve, share something, NOW!

Measured memory_bytes: 3608
// Merge Sort
#include <stdio.h>
#include <stdlib.h>
#define SENTINEL 1000000000

void merge(int *a, int left, int mid, int right);
void mergeSort(int *a, int left, int right);

int cnt = 0;

int main() {
  int i, n;
  int *a;
  int left, right, mid;

  // input the length
  scanf("%d", &n);
  // memory allocation
  a = (int *)malloc(n * sizeof(int));
  // input the number
  for(i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }

  left = 0;
  right = n;
  mid = (left + right) / 2;

  //merge sort
  mergeSort(a, left, right);

  // output
  for(i = 0; i < n; i++) {
    printf("%d", a[i]);
    if(i == n - 1) printf("\n");
    else printf(" ");
  }
  printf("%d\n", cnt);
  
  return 0;
}

void merge(int *a, int left, int mid, int right) {
  int n1, n2;
  int i, j, k;
  int *l, *r;

  n1 = mid - left;
  n2 = right - mid;
  // create array L and R
  l = (int *)malloc((n1+1)*sizeof(int));
  r = (int *)malloc((n2+1)*sizeof(int));
  for(i = 0; i < n1; i++) {
    l[i] = a[left + i];
  }
  for(i = 0; i < n2; i++) {
    r[i] = a[mid + i];
  }
  l[n1] = SENTINEL;
  r[n2] = SENTINEL;
  i = 0;
  j = 0;
  for(k = left; k < right; k++) {
    if(l[i] <= r[j]) {
      a[k] = l[i];
      i = i + 1;
    }
    else {
      a[k] = r[j];
      j = j + 1;
    }
    cnt++;
  }
}

void mergeSort(int *a, int left, int right) {
  int mid;
  
  if(left + 1 < right) {
    mid = (left + right)/2;
    mergeSort(a, left, mid);
    mergeSort(a, mid, right);
    merge(a, left, mid, right);
  }
}



Measured memory_bytes: 64484
#include <iostream>
#include <cstdlib>
#include<vector>
#include<string>
using namespace std;

int main(){
	string str;

	cin>> str;
	
	for (int i = 0; i < str.size(); i++)
	{
		if(i%2==0){
			cout<<str[i];
		}
	}
	


	return 0;
	}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)

using namespace std;


int main(void) {

	int a;
	int b;
	cin >> a >> b;
	int temp;
	double tokuhyo=0;
	vector<int> shohin;

	for (int i = 0; i < a; i++) {

		cin >> temp;
		shohin.push_back(temp);
		tokuhyo = tokuhyo + temp;
	}
	int count = 0;
	double shikii = double(tokuhyo / (4 * b));

	for (int i = 0; i < shohin.size(); i++) {
		if ((double)shohin[i] >= shikii) {
			count++;
			}

	}

	if (count >= b) {
		cout << "Yes";
	}else{
		cout << "No";
	}






}






Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

int main() {
  int N, A, B;
  while (cin >> N >> A >> B) {
    int a = 0, b = 0, c = 0;
    for (int i = 0; i < N; i++) {
      int x;
      cin >> x;
      if (x <= A) {
        ++a;
      } else if (x <= B) {
        ++b;
      } else {
        ++c;
      }
    }
    int res = min({a, b, c});
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static long Mod = (long)1e9 + 7;
        static void Main(string[] args)
        {
            SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            Out.Flush();
            Read();
        }
        static void Solve()
        {
            var N = ReadLine();
            var len = N.Length;
            var Nn = new long[len];
            for (var i = 0; i < len; ++i)
                Nn[i] = N[i] - '0';
            Array.Reverse(Nn);
            var dp = new long[len, 2];//繰り上げをしない、繰り上げをする
            dp[0, 0] = Nn[0];
            dp[0, 1] = 10 - Nn[0];
            for (var i = 1; i < len; ++i)
            {
                //繰り上げをしない場合
                dp[i, 0] = Nn[i] + dp[i - 1, 0];
                if (Nn[i] != 9) dp[i, 0] = Min(dp[i, 0], Nn[i] + 1 + dp[i - 1, 1]);
                //次の桁を繰り上げる場合
                dp[i, 1] = Min(10 - Nn[i] + dp[i - 1, 0], 9 - Nn[i] + dp[i - 1, 1]);
            }
            var ans = Min(dp[len - 1, 0], dp[len - 1, 1] + 1);
            WriteLine(ans);
        }
    }
}

Measured memory_bytes: 53668
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long K = sc.nextLong();
        long[] H = new long[(int) N];
        
        for(int i = 0; i < N; i++){
            H[i] = sc.nextLong();
        }
        Arrays.sort(H);
        long sum = 0;
        for(int i = 0; i < N - K; i++){
            sum += H[i];
        }
        System.out.println(sum);
    }
}

Measured memory_bytes: 81336