akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.math.BigInteger;

public class Main {
       public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int a = input.nextInt(); // Rows of the 1st matrix
        int b = input.nextInt(); // Columns of 1st Matrix and Rows of 2 Matrix
        int c = input.nextInt(); // Columns of 2nd matrix

        BigInteger[][] A = new BigInteger[a][b];
        BigInteger[][] B = new BigInteger[b][c];

        // Build matrix A
        for(int row = 0; row < a; row++){
            for(int col = 0; col < b; col++){
                A[row][col] = BigInteger.valueOf(input.nextInt());
            }
        }

        // Build martix B
        for(int row = 0; row < b; row++){
            for(int col = 0; col < c; col++){
                B[row][col] = BigInteger.valueOf(input.nextInt());
            }
        }

        // Multiple out
        BigInteger[][] result = new BigInteger[a][c];

        for(int row = 0; row < a; row++){
            for(int col = 0; col < c; col++){
                BigInteger temp = sum(A[row], B, col);
                result[row][col] = temp;
            }
        }
        showSheet(result); // Display the result
    }

    // Helper function that computes the value of a cell in the result matrix
    // Takes an (a x 1) vector that is a row of A and then the entire B matrix, and a colIndex that indicates where to index B
    private static BigInteger sum(BigInteger[] row, BigInteger[][] matrix, int colIndex){
        BigInteger total = BigInteger.ZERO;
        for(int i = 0; i < row.length; i++){
            total = total.add(row[i].multiply(matrix[i][colIndex]));
        }
        return total;
    }

    // Helper function that displays a 2D int array
    private static void showSheet(BigInteger[][] result){
        for(int i = 0; i < result.length; i++){
            for(int j = 0; j < result[0].length; j++){
                System.out.print(result[i][j]);
                if( j < result[0].length - 1) System.out.print(" ");
            }
            System.out.print("\n");
        }
    }
}


Measured memory_bytes: 103444
#include <iostream>
#include <cmath>
#include <unordered_set>
using namespace std;


int main(){
    int n;
    cin >> n;
    for(int i=0; i<n; i++){
        unordered_set<int> hold;
        int x,max;
        bool flag=true;
        cin >> x;
        while(x>=10){
            max=0;
            for(int j=10; j<x; j*=10){
                int val = x/j * (x%j);
                if(val > max){
                    max = val;
                }
            }
            x=max;
            if(!(hold.insert(x).second)){
                flag=false;
                break;
            }
        }
        if(flag){
            cout << hold.size() << endl;
        }else{
            cout << -1 << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3076
import math

def ans(n):
  diff = abs(math.radians(6)*n[3] - (math.radians(30)*n[2] + math.radians(0.5)*n[3]))
  if diff < math.radians(180):
    print(math.sqrt(n[0]**2 + n[1]**2 -2*n[0]*n[1]*(math.cos(diff))))
  elif diff > math.radians(180): 
    print(math.sqrt(n[0]**2 + n[1]**2 -2*n[0]*n[1]*(math.cos(math.radians(360) - diff))))
  else:
    print(n[0] + n[1])

ans(list(map(int,input().split())))


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

using static Input;
using static Util;
class Program
{
    static int N, Ma, Mb;
    static int[] A, B, C;
    static void INPUT()
    {
        N = NextInt();
        Ma = NextInt();
        Mb = NextInt();
        A = new int[N];
        B = new int[N];
        C = new int[N];
        for (int i = 0; i < N; i++)
        {
            A[i] = NextInt();
            B[i] = NextInt();
            C[i] = NextInt();
        }
    }

    static void OUT()
    {
        var aaa = A.Sum();
        var bbb = B.Sum();
        var dp = new int[N + 1, aaa, bbb];
        for (int i = 0; i <= N; i++)
            for (int a = 0; a < aaa; a++)
                for (int b = 0; b < bbb; b++)
                    dp[i,a,b] = INF;
        dp[0, 0, 0] = 0;

        for (int i = 0; i < N; i++)
        {
            for (int a = 0; a < aaa; a++)
            {
                for (int b = 0; b < bbb; b++)
                {
                    dp[i + 1, a , b] = Math.Min(dp[i + 1, a, b], dp[i, a, b]);
                    if (a + A[i] < aaa && b + B[i] < bbb)
                    dp[i + 1, a + A[i], b + B[i]] = Math.Min(dp[i + 1, a + A[i], b + B[i]], dp[i, a, b] + C[i]);
                }
            }
        }

        var min = INF;
        for (int i = 1; i < 10; i++)
        {
            var a = i * Ma;
            var b = i * Mb;
            if(a < aaa && b < bbb)
            min = Math.Min(min,dp[N, a, b]);
        }
        Console.WriteLine(min == INF ? -1: min);
    }
    static void Main(string[] args)
    {
#if DEBUG  
        //TESTINPUT();
        INPUT();

#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{

}




Measured memory_bytes: 21088
/*
Author : N_o_o_B
Created : June 14 2020 17:34:31 
*/
#include <bits/stdc++.h>
using namespace std;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
*/
#define TRACE
#ifdef TRACE
#define trace(...) { cerr<<"[ "; __trace__(#__VA_ARGS__, __VA_ARGS__);}
#undef endl
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const pair<Arg1,Arg2> &x) {
    return out<<"("<<x.first<<","<<x.second<<")";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const vector<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
ostream& operator << (ostream& out, const set<Arg1> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1,typename Arg2>
ostream& operator << (ostream& out, const map<Arg1,Arg2> &a) {
    out<<"[";for(const auto &x:a)out<<x<<",";return out<<"]";
}
 
template <typename Arg1>
void __trace__(const string name, Arg1&& arg1){
    cerr << name << " : " << arg1 << " ] " << endl;
}
 
template <typename Arg1, typename... Args>
void __trace__(const string names, Arg1&& arg1, Args&&... args){
    const string name = names.substr(0,names.find(','));
    cerr<<name<<" : "<<arg1<<" | ";
    __trace__(names.substr(1+(int)name.size()), args...);
}
#else
    #define trace(args...)
#endif
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<ll,ll>> vll;
typedef vector<vl> vvl;
//typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
#define fori(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define repd(i,a,b) for(int i=a;i>=b;i--)
#define ford(i,n)  for(int i=n-1;i>=0;i--)
#define trav(x,a) for(auto& x:a)
#define all(x) x.begin(),x.end()
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define fi first
#define se second
clock_t time_p=clock();
void time_taken()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
//const ll mod=998244353;
const ll mod=1e9+7;
const ll INF=1e18;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    cout.precision(12);cout << fixed;

    int x,n;
    cin >> x >> n;
    vi a(n);
    set<int> s;
    fori(i,n) {
        cin >> a[i];
        s.insert(a[i]);
    }
    for(int i=0;i<n+10;i++){
        if(!s.count(x-i)){
            cout << x-i << endl;
            return 0;
        }
        if(!s.count(x+i)){
            cout << x+i << endl;
            return 0;
        }
    }



    time_taken();
    return 0;
}

Measured memory_bytes: 3684
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define REP(i, n) for(ll i = 1; i < (ll)(n); i++)
typedef long long ll;
const ll mod = 1e9+7;

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}

//繰り返し自乗法によるmod累乗計算
//a = 底、　n = 指数
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//nCa 
ll comb(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}


int main(){
  int n;
  cin >> n;
  vector<int> cost(n);
  rep(i,n) cin >> cost[i];
  sort(cost.begin(), cost.end());
  int ans = 0;
  rep(i, n-1){
    ans += cost[i];
  }
  ans += cost[n-1]/2;
  cout << ans << endl;
}






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

int main()
{
	char str[1300];
	
	while(fgets(str, 1300, stdin))
	{
		int sum = 0;
		if(str[0] == '0')
		{
			break;
		}
		for(int i = 0; i < strlen(str)-1; i++)
		{
			sum += str[i]-48;

				
		}
		printf("%d\n", sum);
		
	}
}


Measured memory_bytes: 2688
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int cnt = sc.nextInt();
    int sum = sc.nextInt();
    int[] moneys = {-1, -1, -1};
    
    for(int i = 0; i <= cnt; i++){
        for(int j = 0; j <= (cnt-i); j++){
            for(int k = 0; k <= (cnt-i-j); k++){
                if(i*10000 + j*5000 + k*1000 == sum &&
                    i + j + k == cnt){
                    moneys[0] = i;
                    moneys[1] = j;
                    moneys[2] = k;
                }
            }
        }
    }
    System.out.printf("%d %d %d", moneys[0], moneys[1], moneys[2]);
  }
}

Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i= (a); i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() { int N;
  cin >> N;
  vector<ll> A(N);
  ll ans = 0;
  REP(i, N) { cin >> A[i];
    while(A[i]%2==0){
      ans++;
      A[i] /= 2;
    }
   }
   cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int main()
{
	int A, B, K;

	cin >> A >> B >> K;

	repc(i, A, min(A + K - 1, B)) cout << i << endl;
	repc(i, max(A + K, B - K + 1), B) cout << i << endl;

	return 0;
}


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

int main(){
  int N;cin >> N;
  vector<ll> A(N);
  ll sum = 0;
  int count_nega=0;
  for(int i=0;i<N;i++){
    cin >> A[i];
    if(A[i]<0){
      count_nega ++;
      A[i] = -A[i];
    }
    sum += A[i];
  }
  sort(A.begin(),A.end());
  if(count_nega%2==0){
    cout << sum << endl;
  }else{
    cout << sum - 2*A[0] << endl;
  }
}

Measured memory_bytes: 1024
n,i,j,u,v=1,a[2][3];long dp[25000005];solve(){for(i=n;i;--i)dp[i]=i;for(;i<=n;++i)for(j=0;j<3;++j)a[v][j]>a[u][j]&&i>=a[u][j]&&(dp[i]=fmax(dp[i],dp[i-a[u][j]]+a[v][j]));}main(){for(scanf("%d",&n);i<2;i++)for(j=0;j<3;j++)scanf("%d",a[i]+j);solve(),n=dp[n],u=1,v=0,solve();printf("%lld\n",dp[n]);}

Measured memory_bytes: 195456
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;
const double PI=acos(-1);

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 (a>b) { a=b; return 1; } return 0; }
int dy[]={-1,1,0,0};
int dx[]={0,0,-1,1};


int main() {
    int N,M; cin >>N>>M;
    cout<<((N==M)?"Yes":"No")<<endl;

    return 0;
}


Measured memory_bytes: 256
/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+---test
6 2
---+/
/+---test
14 3
---+/
/+---test
20 4
---+/

void main(string[] args) {
  long N, D;
  readf(" %d %d ", &N, &D);
  (N*1./(2*D+1)).ceil.to!int.writeln;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lli long long int
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    lli h,a,cnt=0,i;
    cin>>h>>a;
    lli n[a];
    for(i=0;i<a;i++)
    cin>>n[i];
    for(i=0;i<a;i++)
    {
        h=h-n[i];
        cnt++;
    }
    if(h<=0)
    cout<<"Yes"<<"\n";
    else
    cout<<"No"<<"\n";
}

Measured memory_bytes: 4368
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}

int main(){
    int q;
    while(cin>>q){
        rep(i,q){
            string s,t;cin>>s>>t;
            int m = s.size(),n = t.size();
            s.insert(0,"0");
            t.insert(0,"0");
            int dp[m+1][n+1];
            rep(j,m+1)rep(k,n+1)dp[j][k] = 0;
            REP(j,1,m){
                REP(k,1,n){
                    if(s[j] == t[k]){
                        dp[j][k] = max({dp[j][k],dp[j-1][k-1]+1,dp[j-1][k],dp[j][k-1]});
                    }
                    else dp[j][k] = max({dp[j][k],dp[j-1][k],dp[j][k-1]});
                }
            }
            cout<<dp[m][n]<<endl;
        }
    }
}




Measured memory_bytes: 7072
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <string>
#include <cctype>
#include <algorithm>
#include <climits>
#include <list>

using namespace std;

int main()
{
	double x1, x2, y1, y2, d;
	cin >> x1 >> y1 >> x2 >> y2;
	d = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
	printf("%.8f\n", d);
	return 0;
}

Measured memory_bytes: 1240
#include <iostream>
#include <cstdlib>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
#include <sstream>
#include <math.h>

using namespace std;

#define ll long long int
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecchar vector<char>
#define vecstr vector<string>
#define vecbool vector<bool>
#define vec2bool vector<vector<bool>>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(ll s = a;s < b;s++)
#define forllde(s,a) for(ll s = a;s > 0;s--)

#define Pi 3.1415926535897932384626

int main() {
	ll n, ans = 0;
	string s;
	bool flag = false;

	cin >> n;

	ll buf1 = 0, buf2 = 0;

	while (n > buf1) {
		buf2++;
		buf1 += (ll)pow(26, buf2);
	}

	string tmp;

	ll before = 0;

	forll(i, 0, buf2) {
		ll buf = n - before;
		buf--;

		if (i > 0)
		{
			forll(j, 0, i)
			{
				buf /= 26;
			}
		}

		buf %= 26;

		tmp.push_back('a' + buf);

		before += (ll)pow(26, i + 1);
	}

	forll(i, 0, tmp.size())
	{
		s.push_back(tmp[(tmp.size() - 1) - i]);
	}

	cout << s;
}


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

int f[101][11];
int p[101][12];

int main() {
  int n; 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];
  int ans = -(1<<30);
  for (int i = 1; i < (1 << 10); i++) {
    int sum = 0;
    for (int j = 0; j < n; j++) {
      int cnt = 0;
      for (int k = 0; k < 10; k++) if ((i >> k & 1) && f[j][k]) cnt++;
      sum += p[j][cnt];
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll n,m;
    cin >> n >> m;
    priority_queue<ll>a;
    for(ll i=0;i<n;i++){
        ll x;
        cin >> x;
        a.push(x);
    }
    for(ll i=0;i<m;i++){
        ll x=a.top();
        a.pop();
        x/=2;
        a.push(x);
    }
    ll ans=0;
    for(ll i=0;i<n;i++){
        ll x=a.top();
        a.pop();
        ans+=x;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4316
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;

int main(){
    ll h, w, k;
    cin >> h >> w >> k;

    //dp[i][j] : 高さiで幅jに行ける本数
    ll dp[h+2][w+2] = {};
    dp[0][0] = 1;
    rep(i, h)rep(j, w){
        //
        rep(bit, (1<<(w-1))){
            //正しい線の引き方か？
            bool isok = true;
            rep(b, w){
                if(1<<b & bit && 1<<(b+1) & bit){
                    isok = false;
                    break;
                }
            }
            if(!isok)continue;

            //右方向へ移動する
            if(1<<j & bit){
                dp[i+1][j+1] += dp[i][j];
                dp[i+1][j+1] %= MOD;
            }
            //左方向へ移動する
            else if(j > 0 && 1<<(j-1) & bit){
                dp[i+1][j-1] += dp[i][j];
                dp[i+1][j-1] %= MOD;
            }
            //そのまま下へ
            else {
                dp[i+1][j] += dp[i][j];
                dp[i+1][j] %= MOD;
            }
        }
    }

    cout << dp[h][k-1] << endl;
}

Measured memory_bytes: 3516
# Template 1.0
import sys, re
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log
from heapq import heappush, heappop, heapify, nlargest, nsmallest
def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
def sortListWithIndex(listOfTuples, idx):   return (sorted(listOfTuples, key=lambda x: x[idx]))
def sortDictWithVal(passedDic):
    temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0]))
    toret = {}
    for tup in temp:
        toret[tup[0]] = tup[1]
    return toret
def sortDictWithKey(passedDic):
    return dict(OrderedDict(sorted(passedDic.items())))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n,k =MAP()

a = LIST()

a.sort()

print(sum(a[:k]))


Measured memory_bytes: 68200
#include <stdio.h>

int main() {
  int N;
  scanf("%d", &N);

  if(N % 1000 == 0) {
    puts("0");
  } else {
    printf("%d", ((N / 1000) + 1)*1000 - N);
  }


 // 1900 , bayar 2000, balik 100
 // 2300, bayar 3000, balik 700
  return 0;
}

Measured memory_bytes: 1728
def c_splitting_pile():
    # X = sum(A)、カードの山の先頭 i 枚の総和を x とすると、
    # |y-x| = |X-2x| である。各 i(1<=i<=N-1) についてこの値を計算すればよい
    from itertools import accumulate
    N = int(input())
    A = [int(i) for i in input().split()]
    total = sum(A)
    return min([abs(total - 2 * x) for x in accumulate(A[:-1])])

print(c_splitting_pile())

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

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

using namespace std;
using ll = long long;
using P = pair<int,int>;

constexpr int MOD = 1000000007;
constexpr int INF = 1001001001;

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 (a>b) { a=b; return 1; } return 0; }

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> l(n);
    rep (i, n) cin >> l[i];
    int now = 0, ans = 0;
    while (now <= x && ans <= n) {
        ans++;
        now += l[ans-1];
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3564
import           Control.Monad
import           Data.Array
import qualified Data.ByteString.Char8 as BS
import           Data.List
import           Data.Maybe
import           Data.Ord

readInts :: IO [Int]
readInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

main = do
  [a,b] <- map read . words <$> getLine
  print $ lcm a b


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

using namespace std;

const int maxn = 20;
const int INF = 1e9 + 100;

int a[30];

int main() {
    //freopen("input", "r", stdin);
    //freopen("output", "w", stdout);

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

    int h, w;
    cin >> h >> w;
    for (int i = 0; i < h; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < w; ++j) {
            a[s[j] - 'a']++;
        }
    }
    if (h % 2 == 0 && w % 2 == 0) {
        for (int i = 0; i < 26; ++i) {
            if (a[i] % 4 != 0) {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
        return 0;
    }
    if (w % 2 != 0) {
        swap(w, h);
    }
    if (h % 2 != 0 && w % 2 == 0) {
        int cnt = 0;
        for (int i = 0; i < 26; ++i) {
            if (a[i] % 2 != 0) {
                cout << "No" << endl;
                return 0;
            }
            if (a[i] % 4 != 0) {
                cnt++;
            }
        }
        if (cnt > w / 2 || (cnt % 2) != (w / 2) % 2) {
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }
        return 0;
    }

    int cnt2 = 0, cnt1 = 0;
    for (int i = 0; i < 26; ++i) {
        if (a[i] % 2 != 0) {
            cnt1++;
        } else if (a[i] % 4 != 0) {
            cnt2++;
        }
    }
    if (cnt1 != 1) {
        cout << "No" << endl;
        return 0;
    }
    if (cnt2 > (h - 1) / 2 + (w - 1) / 2 || (cnt2 % 2) != ((h - 1) / 2 + (w - 1) / 2) % 2) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int a, b, c;
  int out;

  while (scanf("%d %d", &a, &b) != EOF) {
	out = 0;
	c = a + b;
	do {
	  c /= 10;
	  out++;
	} while (c > 0);
	
	printf("%d\n", out);
  }
  return 0;
}

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

#define FOR(x,to) for(int x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))

typedef long long ll;
const int inf = 2e9;
using namespace std;
ll MOD = 1000000007;
typedef pair<int,int> ii;
typedef struct {int a,b,c;}iii;

void mosA(vector<int> a){
	for(int i=0; i<a.size(); i++) printf("%d ",a[i]);
	printf("\n");
}
void mosP(vector<ii> a){
	for(int i=0; i<a.size(); i++) printf("%d %d\n",a[i].first,a[i].second);
	printf("\n");
}
/*
bool ord(ii a, ii b){
	return b.second<a.second;
}*/

ll ans = 0;
int k,minimo = 5005,ver,t,p,n,m,f,q,mA;
int G[28];
char S[200005];
pair<char,char> Q[200005];


bool se_cae_iz(int pos){
	char actual = S[pos];
	for(auto q:Q){
		if(q.first==actual){
			if(q.second == 'L') pos--;
			else pos++;
			if(pos<0) return true;
			if(pos>=n) return false;
			actual = S[pos];
		}
	}
	return false;
}

bool se_cae_der(int pos){
	char actual = S[pos];
	for(auto q:Q){
		if(q.first==actual){
			if(q.second == 'L') pos--;
			else pos++;
			if(pos<0) return false;
			if(pos>=n) return true;
			actual = S[pos];
		}
	}
	return false;
}


int main(){

	scanf("%d%d%s",&n,&q,S);
	FOR(k,q) scanf(" %c %c",&Q[k].first,&Q[k].second);


	int L,R;

	int r = n-1 ,l = 0,mid,u = -1;

	while(r>=l){
		mid = (l+r)/2;
		if(se_cae_iz(mid)){
			u = mid;
			l = mid + 1;
		} else r = mid-1;
	}

	L = u;
	
	r = n-1 ,l = 0,mid,u = -1;
	
	while(r>=l){
		mid = (l+r)/2;
		if(se_cae_der(mid)){
			u = mid;
			r = mid - 1;
		} else l = mid+1;
	}

	R = u;

	if(R==-1) R = n;


	//cout<<L<<" "<<R<<endl;
	cout<<R-L-1<<endl;

}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int x,y; cin >> x >> y;
    cout << x + y/2 << endl;
    return 0;
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

// {{{ BIT
struct BIT{
    vector<int> data;
    int leng;
    BIT( int n ){
        init(n);
    }
    void init(int n){
        leng = n;
        data.assign(n+1,0);
    }
    int sum(int i){
        int s = 0;
        for( ; i>0; i -= i & -i ){
            s += data[i];
        }
        return s;
    }
    void add(int i, int x){
        for( ; i<=leng ; i += i & -i ){
            data[i] += x;
        }
    }
};
// }}}

int main() {

    int N,K;
    Scd2(N,K);

    vi a(N);
    Rep(i,N){
        Scd(a[i]), a[i]-=K;
    }

    vl s(N+1);
    map<ll,ll> z;
    z[0] = 0;
    Rep(i,N) s[i+1] = s[i] + a[i], z[s[i+1]]=0;

    int cnt = 0;
    for( auto& t : z ) t.second = ++cnt;

    BIT b(N+114);

    ll ans = 0;
    Rep(i,N+1){
        ans += b.sum(z[s[i]]);
        b.add(z[s[i]],1);
    }

    printf ("%lld\n", ans );

    return 0;
}



Measured memory_bytes: 15872
#include <stdio.h>

int main(void)
{
	int can;
	
	while (scanf("%d", &can) != EOF){
		if (can % 39 == 0){
			printf("3C39\n");
		}
		else if (can % 39 < 10){
			printf("3C0%d\n", can % 39);
		}
		else {
			printf("3C%d\n", can % 39);
		}
	}
	
	return (0);
}

Measured memory_bytes: 604
import java.util.Scanner;
class Main{
  public static void main(String args[]){
    Scanner n=new Scanner(System.in);
    double num=n.nextInt();
    double a;
    if(num%2==1){
      a=(num+1)/2;
    }else{
      a=num/2;
    }
    System.out.println(a/num);
  }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string str;
  int count = 0;
  cin >> str;
  
  for(int i=0;i<3;i++){
    if(str[i]=='R'){
      count++;
      if(str[i+1]!='R'){
        break;
      }
    }
  } 
   
  cout << count << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int d,g;
    cin >> d >> g;
    int res = inf;
    vector<int> p(d),c(d);
    rep(i,d) cin >> p[i] >> c[i];
    rep(i, (1<<d)){
        int now = 0;
        int cnt = 0;
        rep(j,d){
            if((i>>j)&1) now += 100*(j+1)*p[j] + c[j], cnt += p[j]; 
        }
        if(now >= g) res = min(res,cnt);
        else{
            for(int j = d-1; j >= 0;j --){
                if((i >> j)&1) continue;
                for(int k = 0;k < p[j]-1; k++){
                    now += 100*(j+1);
                    cnt++;
                    if(now >= g) res = min(res, cnt);
                }
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
long long a[4] = {1};
char s[100005];
int main(){
	scanf("%s", s);
	for(char c:s) for(int j = 3; j >= 0; j--)
		a[j] = (a[j]*(c-'?'?1:3) + (j&&!(c-'?'&&c-'A'-j+1)?a[j-1]:0))%1000000007;
	printf("%lld\n", a[3]);
}


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

int main() {
    int n;
    cin >> n;
    vector<string> v(n);
    vector<int> mi(n), last(n);
    vector<int> mi_r(n), last_r(n); // from right
    for(int i=0; i<n; ++i) {
        cin >> v[i];
        mi[i] = (v[i][0] == '(' ? 1 : -1);
        int sum = mi[i];
        for(int j=1; j<v[i].size(); ++j) {
            sum += (v[i][j] == '(' ? 1 : -1);
            mi[i] = min(mi[i], sum);
        }
        last[i] = sum;

        mi_r[i] = v[i].back() == ')' ? 1 : -1;
        sum = mi_r[i];
        for(int j=v[i].size()-2; j>=0; --j) {
            sum += (v[i][j] == ')' ? 1 : -1);
            mi_r[i] = min(mi_r[i], sum);
        }
        last_r[i] = sum;
    }
    vector<bool> used(n);
    int now = 0;
    while(true) {
        int next = -1;
        for(int i=0; i<n; ++i) {
            if(used[i]) {
                continue;
            }
            if(now + mi[i] >= 0 && now + last[i] >= now) {
                if(next == -1 || last[i] > last[next]) {
                    next = i;
                }
            }
        }
        if(next == -1) {
            break;
        }
        used[next] = true;
        now += last[next];
    }

    int now2 = 0;
    while(true) {
        int next = -1;
        for(int i=0; i<n; ++i) {
            if(used[i]) {
                continue;
            }
            if(now2 + mi_r[i] >= 0 && now2 + last_r[i] >= now2) {
                if(next == -1 || last_r[i] > last_r[next]) {
                    next = i;
                }
            }
        }
        if(next == -1) {
            break;
        }
        used[next] = true;
        now2 += last_r[next];
    }

    if(count(used.begin(), used.end(), true) == n && now == now2) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3192
n,k = map(int,input().split())
X = list(map(int,input().split()))
Xp = [x for x in X if x>=0]
Xm = [-x for x in X if x<0]
Xm.sort()
Xp.insert(0,0)
Xm.insert(0,0)
lp = len(Xp)
lm = len(Xm)
ans = 10**9
for p in range(k+1):
    m = k-p
    if p>lp-1 or m>lm-1:continue
    ans= min(ans,2*Xm[m] +Xp[p],Xm[m] +2*Xp[p] )
print(ans)


Measured memory_bytes: 14252
import Control.Monad

main :: IO ()
main = do
  n <- readLn
  if n == 0
    then return ()
    else do
      ls <- replicateM n readLn
      putStrLn (show (bubbleSet (ls,0)))
      main

bubble :: [Int] -> [Int]
bubble [] = []
bubble (x:[]) = [x]
bubble (x:y:r)
  | x <= y = x : (bubble (y:r))
  | otherwise = y : (bubble (x:r)) 

bubbleC :: [Int] -> Int -> Int
bubbleC [] i = i
bubbleC (x:[]) i  = i
bubbleC (x:y:r) i
  | x <= y = bubbleC (y:r) i
  | otherwise = bubbleC (x:r) (i+1)

bubbleSet :: ([Int],Int) -> Int
bubbleSet ([],i) = i
bubbleSet (l,i)  = bubbleSet ((init (bubble l)),(bubbleC l i))

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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) RFOR(i, n, 0)
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const ll INF = 1e18;
const int inf = 1e8;


void solve()
{
  ll A;
  scanf("%lld",&A);
  ll B;
  scanf("%lld",&B);
  ll C;
  scanf("%lld",&C);
  if (A==B) cout << C << endl;
  else if (A==C) cout << B << endl;
  else cout << A << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FI freopen ("inp.txt", "r", stdin)
#define FO freopen ("out.txt", "w", stdout)
#define eb emplace_back
#define FOR(v) for(int i : v) {printf("%d ", i);} printf("\n");
#define what_is(x) cerr << #x << " = " << x << endl;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
/*---------------------------Codes-----------------------------*/
const int nax = 1e5 + 5;
vector<int> edges[nax];
int in_degree[nax];
bool visited[nax];
int dist[nax];

void dfs(int u) {
    assert(!visited[u]); // should be unvisited.
    visited[u] = true;
    for (int v : edges[u]) {
        dist[v] = max(dist[v], dist[u] + 1);
        --in_degree[v];
        if (in_degree[v] == 0) {
            dfs(v);
        }
    }
}

int main() {
    //FI;

    int n, m, a, b;
    scanf("%d %d", &n, &m);
    while(m--) {
        scanf("%d %d", &a, &b);
        edges[a].eb(b);
        ++in_degree[b];
    }

    for (int i = 1; i <= n; ++i) {
        if (!visited[i] && in_degree[i] == 0) {
            dfs(i);
        }
    }

    int ans = 0;
    for (int i = 1; i <= n; ++i)
        ans = max(ans, dist[i]);

    printf("%d\n", ans);

    return 0;
}


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

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

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

Int modpow(Int a, Int n, Int mod) {
    Int ret = 1;
    while (n > 0) {
        if (n & 1) {
            ret = ret * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }

    return ret;
}

vector<Int> factorials(0), invs(0);
bool is_ncr_table = false;
void calc_ncr_table(Int n, Int mod) {
    is_ncr_table = true;

    // 1! ~ n! の計算
    Int f = 1;
    factorials.push_back(f);
    for (Int i = 1; i < n + 1; i++) {
        f *= i;
        f %= mod;
        factorials.push_back(f);
    }
    // n!^-1 の計算
    Int inv = modpow(factorials[n], mod - 2, mod);
    // (n-1)!^-1 ~ 1!^-1 の計算
    invs.assign(n, 1);
    invs[n] = inv;
    for (Int i = n; i >= 1; i--) {
        inv *= i;
        inv %= mod;
        invs[i - 1] = inv;
    }
}

Int factorial(Int n, Int mod = 1) {
    Int ret = 1;
    if (mod == 1) {
        for (Int i = 1; i < n + 1; i++) {
            ret *= i;
        }

        return ret;
    } else {
        for (Int i = 1; i < n + 1; i++) {
            ret *= i;
            ret %= mod;
        }

        return ret;
    }
}

Int ncr(Int n, Int r, Int mod, bool use_table = false) {
    if (n < r) {
        return (Int)0;
    } else {
        if (use_table) {
            // modが素数の場合のみ
            if (!is_ncr_table) {
                calc_ncr_table(n, mod);
            }
            return (factorials[n] * invs[r] % mod) * invs[n - r] % mod;
        } else {
            Int x = 1;
            for (Int i = n - r + 1; i < n + 1; i++) {
                x *= i;
                x %= mod;
            }
            return x * modpow(factorial(r, mod), mod - 2, mod) % mod;
        }
    }
}

int main() {
    Int n, k;
    cin >> n >> k;

    calc_ncr_table(2010, MOD);

    vector<Int> rr(k);
    for (Int i = 0; i <= k - 1; i++) {
        rr[i] = ncr(k - 1, i, MOD, true) % MOD;
    }

    for (Int i = 1; i <= k; i++) {
        Int ans = 0;
        Int nn = n - k + 1;
        ans += ncr(nn, i, MOD, true);
        ans *= rr[i - 1] % MOD;
        ans %= MOD;
        cout << ans << endl;
    }

    return 0;
}

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

int main(){
	ll xa=1e9, S; cin>>S;
	ll yb = (S+xa-1)/xa;
	cout<<"0 0 1000000000 1 "<< xa*yb-S <<" "<< yb <<endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int calc_gcd(int, int);
int calc_lcm(int, int, int);

int main(void) {
    int a, b, gcd, lcm;

    while(scanf("%d %d", &a, &b) != EOF) {
        if(a <= b) gcd = calc_gcd(a, b);
        else       gcd = calc_gcd(b, a);
        lcm = calc_lcm(a, b, gcd);
        printf("%d %d\n", gcd, lcm);
    }

    return 0;
}

int calc_gcd(int small, int large) {
    if(large % small == 0) return small;

    int gcd = small / 2;
    while(gcd >= 1) {
        if((small % gcd == 0) && (large % gcd == 0)) break;
        gcd--;                                                                                                                                                           
    }

    return gcd;
}

int calc_lcm(int p, int q, int gcd) {
    return p / gcd * q;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N;
    cin >> N;
    vector<vector<int>> A(N, vector<int>(N, 0));
    rep(i, N) {
        rep(j, N) {
            int a;
            cin >> a;
            A[i][j] = a;
        }
    }
    ll S = 1LL << N;
    vector<vector<ll>> dp(N + 1, vector<ll>(S, 0));
    dp[0][0] = 1;
    rep(i, N) {
        rep(s, S) {
            int cnt = __builtin_popcount(s);
            if (cnt != i) continue;
            rep(j, N) {
                if (!(s & (1LL << j)) && A[i][j]) {
                    dp[i + 1][s | (1LL << j)] += dp[i][s];
                    dp[i + 1][s | (1LL << j)] %= MOD;
                }
            }
        }
    }
    cout << dp[N][S - 1] % MOD << '\n';
}

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


Measured memory_bytes: 377216
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

//int r, D, n = 0;
//int B(int x) {
//	n++;
//	cout << r * x - D << "\n";
//	if (n == 10) {
//		return 0;
//	}
//	return B(r * x - D);
//}

int main() {
	/*int A, B, ans;
	cin >> A >> B;
	if (A >= 13) {
		ans = B;
	}
	else if (A >= 6 && A <= 12) {
		ans = B / 2;
	}
	else {
		ans = 0;
	}
	cout << ans;*/


	/*int x;
	cin >> r >> D >> x;
	B(x);*/



	/*int N, M;
	cin >> N >> M;
	vector<pair<int, int>>a(M);
	rep(i, M) {
		cin >> a[i].first >> a[i].second;
	}
	ll max = 0, min = 1000000;
	rep (i, M) {
		if (a[i].first > max) {
			max = a[i].first;
		}
		if (a[i].second < min) {
			min = a[i].second;
		}
	}
	int ans;
	if (min - max < 0) {
		ans = 0;
	}
	else {
		ans = min - max + 1;
	}
	cout << ans;*/



	ll N, M;
	cin >> N >> M;
	vector<ll>A(N);
	vector<pair<ll, ll>>B(M);
	rep(i, N) {
		cin >> A[i];
	}
	
	rep(i, M) {
		cin >> B[i].second >> B[i].first;	
	}
	sort(all(A));
	sort(all(B), greater<pair<ll, ll>>());
	vector<ll>C;
	rep(i, M) {
		rep(j, B[i].second) {
			C.push_back(B[i].first);
			if (C.size() == N) {
				break;
			}
		}
		if (C.size() == N) {
			break;
		}
	}

	ll ans = 0;
	rep(i, N) {
		if (i < C.size()) {
			ans += max(A[i], C[i]);
		}
		else {
			ans += A[i];
		}
	}
	cout << ans;


	return 0;
}

Measured memory_bytes: 3704
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
void solve() {
	int N; cin >> N;
	vector<int> A(N), B(N), C(N - 1);
	int ans = 0;
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
		A[i]--;
	}
	for (int i = 0; i < N; ++i) {
		cin >> B[i];
	}
	for (int i = 0; i < N - 1; ++i) {
		cin >> C[i];
	}
	ans += B[A[0]];
	for (int i = 1; i < N; ++i) {
		ans += B[A[i]];
		if (A[i] == A[i - 1] + 1) {
			ans += C[A[i - 1]];
		}
	}
	cout << ans << endl;
	return;
}

int main() {
	solve();
  return 0;
}

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

int N;

int main()
{
    cin >> N;

    if(N == 3)
    {
        cout << 2 << endl;
        cout << 1 << " " << 3 << endl;
        cout << 2 << " " << 3 << endl;
    }
    else if(N == 4)
    {
        cout << 4 << endl;
        cout << 1 << " " << 3 << endl;
        cout << 1 << " " << 2 << endl;
        cout << 4 << " " << 2 << endl;
        cout << 4 << " " << 3 << endl;
    }

    else if(N % 2 == 0)
    {
        cout << N / 2 * 4 << endl;
        for(int i = 0; i < N / 2 - 1; i++)
        {
            cout << i + 1 << " " << i + 2 << endl;
            cout << i + 1 << " " << N - 1 - i << endl;
            cout << N - i << " " << i + 2 << endl;
            cout << N - i << " " << N - 1 - i << endl;
        }
        // N / 2 N / 2 + 1 N 1
        cout << 1 << " " << N / 2 << endl;
        cout << 1 << " " << N / 2 + 1 << endl;
        cout << N << " " << N / 2 << endl;
        cout << N << " " << N / 2 + 1 << endl;
    }

    else
    {
        cout << (N + 1) / 2 * 4 - 4 << endl;
        N--;
        for(int i = 0; i < N / 2 - 1; i++)
        {
            cout << i + 1 << " " << i + 2 << endl;
            cout << i + 1 << " " << N - 1 - i << endl;
            cout << N - i << " " << i + 2 << endl;
            cout << N - i << " " << N - 1 - i << endl;
        }
        cout << 1 << " " << N + 1 << endl;
        cout << N / 2 << " " << N + 1 << endl;
        cout << N / 2 + 1 << " " << N + 1 << endl;
        cout << N << " " << N + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
/* ex7_3
    fmuacshai */

# include<stdio.h>
# include<stdlib.h>

int main(void){
    //縦の行数をheight、横の列数をwideとする
    int height,wide,i;
    
    char **square;
    int *sensorh,*sensorw;
    //heightの入力
    scanf("%d",&height);
    //wideの入力
    scanf("%d",&wide);
    //マス目の配列をsquareとする
    square=(char**)calloc(height, sizeof(char*));
    if(square==NULL){
        printf("memory allocation error.\n");
        exit(1);
    }
    for(i=0;i<height;i++){
        square[i]=(char*)calloc(wide, sizeof(char));
        if(square[i]==NULL){
            printf("memory allocation error.\n");
            exit(1);
        }
    }
    //縦の列を残すか判別する配列をsensorh[]、
    //横の列を残すか判別する配列をsensorw[]とする
    sensorh=(int*)calloc(height, sizeof(int));
    sensorw=(int*)calloc(wide, sizeof(int));
    //squeres[height][wide]を入力
    for(int i=0;i<height;i++){
        for(int j=0;j<wide;j++){
            scanf(" %c",&square[i][j]);
        }
    }
    //sensorh[]の中身を全て0にする
    for(int i=0;i<height;i++){
        sensorh[i]=0;
    }
    //sensorw[]の中身を全て0にする
    for(int j=0;j<wide;j++){
        sensorw[j]=0;
    }
    //'#'が入力されているところに対応する行と列を把握する
    for(int i=0;i<height;i++){
        for(int j=0;j<wide;j++){
            //'#'だったら
            if(square[i][j]=='#'){
                //対応する部分の配列に1を入力
                sensorh[i]=1;
                sensorw[j]=1;
            }
        }
    }
    //対応する行列がどちらも1が入力されていたらを出力
    for(int i=0;i<height;i++){
        for(int j=0;j<wide;j++){
            //対応する行列がどちらも1が入力されていたら
            if(sensorh[i]==1 && sensorw[j]==1){
                //squeres[i][j]を出力
                printf("%c",square[i][j]);
            }
        }
        //消されなかったものがあった列は最後に改行
        if(sensorh[i]==1){
            printf("\n");
        }
    }
    return 0;
}



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

#define FOR(i, a, b) for(i = a; i < b; ++i)
#define REP(i, n) FOR(i, 0, n)
#define comp(a, b) int comp(const void *a, const void *b)
#define MOD  1000000007

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;

void TF_print(char boolean, char T[], char F[]){
    if(boolean){
        printf("%s\n", T);
    }else{
        printf("%s\n", F);
    }
}

comp(a, b){
    return *(ull*)b - *(ull*)a;
}

int main(){
    uint i, N;
    scanf("%u", &N);
    ull A[N];
    ull a = 0, b = 0;

    REP(i, N){
        scanf("%llu", &A[i]);
    }
    qsort(A, N, sizeof(ull), comp);

    REP(i, N - 1){
        if(A[i] == A[i + 1]){
            if(a == 0){
                a = A[i];
            }else{
                b = A[i];
            }
            i++;
            if(a > 0 && b > 0){
                break;
            }
        }
    }

    printf("%llu\n", a * b);
    return 0;
}

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

int main(){
  double ans=0.0;
  cout << fixed << setprecision(6);
  int n;
  cin>>n;
  vector<double> a(n);
  rep(i,n)cin>>a.at(i);
  
  rep(i,n){
      ans+=1.00000/a.at(i);
  }
  cout<<1/ans<<endl;
  
  
}

Measured memory_bytes: 384