akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			final String s = sc.next();
			
			String[] suffixs = new String[N];
			for(int i = 0; i < N; i++) {
				suffixs[i] = s.substring(i);
			}
			
			Arrays.sort(suffixs);
			
			int answer = 0;
			for(int i = 0; i < N - 1; i++) {
				final int curr = i;
				
				int lower = i + 1, upper = N;
				while(lower + 1 < upper) {
					final int middle = (lower + upper) / 2;
					
					if(suffixs[middle].startsWith(suffixs[curr])){
						lower = middle;
					}else {
						upper = middle;
					}
				}
				//System.out.println(suffixs[curr] + " " + suffixs[lower]);
				
				final int next = lower;
				
				final int curr_start_index = (N - suffixs[curr].length());
				final int next_start_index = (N - suffixs[next].length());
				final int start_index_diff = Math.abs(curr_start_index - next_start_index);
				
				//System.out.println(suffixs[curr] + " " + curr_start_index + " " + start_index_diff);
				
				int same = 0;
				while(same < suffixs[curr].length() && same < suffixs[next].length()){
					if(suffixs[curr].charAt(same) != suffixs[next].charAt(same)) { break; }
					if(same >= start_index_diff) { break; }
					
					same++;
				}
				
				answer = Math.max(same, answer);
			}
			
			System.out.println(answer);
			
			
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 56020
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
//        int K = scanner.nextInt();
        char[] wins = scanner.next().toCharArray();
        int K = wins.length;
        int cnt = 0;
        for(char c: wins) {
            if (c == 'o') {
                cnt++;
            }
        }
        if (15-K < 8-cnt) {
            out.println("NO");
        }
        else out.println("YES");
        out.flush();
    }
    
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        
        int[] readIntArray(int n) {
            int[] a = new int[n];
            for (int idx = 0; idx < n; idx++) {
                a[idx] = nextInt();
            }
            return a;
        }
    }
}


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

int sum;
int g[10][10];

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

    rep(i, h) rep(j, w) {
        char c;
        cin >> c;
        if (c == '.') continue;
        sum++;
        g[i][j]++;
    }

    int ans = 0;
    rep(bitR, 1 << h) {
        rep(bitC, 1 << w) {
            int a = 0;
            rep(i, h) rep(j, w) {
                if (bitR & (1 << i) && bitC & (1 << j) && g[i][j] == 1) a++;
            }
            if (a == k) ans++;
        }
    }

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


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

int main(){
	char str[100];
	int len, i;

	scanf("%s", str);
	len = strlen(str);

	for(i=0; i < (len-1)/2; i++){
		if(str[i] != str[len-i-1]){
			printf("No");
			return 0;
		}
	}

	for(i=0; i<(len-1)/2; i++){
		if(str[i] != str[(len-1)/2-i-1]){
			printf("No");
			return 0;
		}
	}

	for(i=(len+3)/2-1; i<len; i++){
		if(str[i] != str[(len+3)/2-i+len-2]){
			printf("No");
			return 0;
		}
	}

	printf("Yes");

	return 0;
}


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

#define COUNTOF(array) (sizeof(array) / sizeof(array[0]))    
#define OUT(P) cout << (P) << endl    
#define OUT2(P1, P2) cout << (P1) << " " << (P2) << endl    
#define PRINT_ARRAY(P) for(int i=0; i<P.size(); i++) cout << P[i] << endl;    
#define PRINT_ARRAY_INLINE(P) do { for(int i=0; i<P.size(); i++) cout << P[i] << " "; cout << endl; } while(0)    
#define PRINT_ARRAY_WITH_LABEL(L, P) do { cout << L << ": "; PRINT_ARRAY_INLINE(P); cout << endl; } while(0)    
typedef long long ll;    

int sum_digits(int num);    
template <class T>    
vector<T> copy_vector(vector<T> vec);    
int gcd(int a, int b);    
// ****** print functions ****** //
template <class T, class U>
void print_pairs(const vector<pair<T, U>> pairs);
template <class K, class V>
void print_map(const map<K, V> m);


bool find_difs(const vector<pair<int, int>> &diffs, const pair<int, int> &diff) {
    for(int i=0; i<diffs.size(); i++) {
        if((diffs[i].first == diff.first && diffs[i].second == diff.second))  {
            return true;
        }
    }
    return false;
}

int main() {    
    int n;
    cin >> n;
    vector<pair<int, int>> pts(n);
    for(int i=0; i<n; i++) {
        int x, y;
        cin >> x >> y;
        pts[i].first = x;
        pts[i].second = y;
    }

    int ans = 1;
    if(n > 1) {
        map<pair<int, int>,int> diffs;
        for(int i=0; i<n; i++) {
            for(int j=0; j<n; j++) {
                if(i != j) {
                    int difx = pts[i].first - pts[j].first;
                    int dify = pts[i].second - pts[j].second;
                    pair<int, int> diff = make_pair(difx, dify);
                    diffs[diff]++;
                }
            }
        }
        pair<pair<int, int>, int> x = *max_element(diffs.begin(), diffs.end(), 
                [](const pair<pair<int, int>, int> &pt1, const pair<pair<int, int>, int> &pt2){return pt1.second < pt2.second; });
        ans = n - x.second;
    }
    cout << ans << endl;
    return 0;    
}    

/******************************/    
/***** DECRARED FUNCTIONS *****/    
/******************************/    

int sum_digits(int num) {    
    int rtn = 0;    
    while(num != 0) {    
        int tmp = num % 10;    
        rtn += tmp;    
        num /= 10;    
    }    
    return rtn;    
}    

// vectorのコピー    
template <class T>    
vector<T> copy_vector(vector<T> vec) {    
    vector<T> rtn;    
    rtn.reserve(vec.size());    
    copy(vec.begin(), vec.end(), back_inserter(rtn));    
    return rtn;    
}    

// ユークリウッドの互除法    
int gcd(int a, int b) {    
    if(b==0) return a;    
    else return gcd(b, a % b);    
}

template <class T, class U>
void print_pairs(const vector<pair<T, U>> &pairs) {
    for(int i=0; i<pairs.size(); i++) { 
        cout << "(" << pairs[i].first << ", " << pairs[i].second << ")" << " "; 
    } 
    cout << endl;
}

template <class K, class V>
void print_map(const map<K, V> &m) {
    for(auto it=m.cbegin(); it!=m.cend(); it++) {
        cout << it->first << ": " << it->second << endl;
    }
}


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



int32_t main(){
	
	int n;cin>>n;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int c=0;
	int mx=0;
	for(int i=1;i<n;i++){
		if(a[i]<=a[i-1]){
			c++;
			mx=max(mx,c);
		}
		else{
			c=0;
		}
	}
	cout<<mx<<endl;


	return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#include<string>
#include<cmath>

using namespace std;

#define ll long long int
#define loop(i, n) for (int i = 0; i < n; i++)
#define loops(i, s, n) for (int i = s; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define MOD 1000000007

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll k,n,s,b,a;
    cin>>k>>n;
     
    cin>>s;
    b = s;
    
    ll ans = 0;
    
    for(ll i = 1; i<n; i++){
        cin>>a;
        if(ans < a - b){
            ans = a - b;
        }
        b = a ;
    }
    if(ans < s + k - a){
        ans = s + k - a;
    }
    cout<<k - ans;
    
    
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int M = 50 + 5;
int a[M];
int main(){
	int n;
	cin>>n;
	for(int i = 0; i < n; i++){
		cin>>a[i];
	}
	sort(a,a+n);
	double ans = 1.0*a[0];
	for(int i = 1; i < n;i++){
		ans = 1.0*(ans+a[i])/2.0;
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  string s, r, c;
  cin >> s;
  for (int i = 0; i < s.length(); ++i) {
    c = s.at(i);
    if (c == "0") {
      r.insert(r.length(), "0");
    } else if (c == "1") {
      r.insert(r.length(), "1");
    } else if (c == "B") {
      if (!r.empty()) {
        r.pop_back();
      }
    }
  }
  cout << r << endl;
  return 0;
}


Measured memory_bytes: 256
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}

use std::f64::consts::PI;
fn main() {
    let v = read_vec::<f64>();
    let a = v[0];
    let b = v[1];
    let x = v[2];
    let t = x / a;

    if t >= (a * b) / 2.0 {
        let c = (2.0 * ((a * b) - t)) / a;
        let ans = (c / a).atan();
        println!("{}", ans * 360.0 / (2.0 * PI));
    } else {
        let c = t * 2.0 / b;
        let ans = (b / c).atan();
        println!("{}", ans * 360.0 / (2.0 * PI));
    }
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  vector<vector<char>> a(H, vector<char>(W));
  REP(i, H) REP(j, W) cin >> a[i][j];
  set<int> retu;
  for(int i = 0; i < H; i++) {
    bool flag = true;
    for(int j = 0; j < W; j++) {
      if(a[i][j] == '#') {
        flag = false;
        break;
      }
    }
    if(flag) { retu.insert(i); }
  }
  set<int> gyo;
  for(int j = 0; j < W; j++) {
    bool flag = true;
    for(int i = 0; i < H; i++) {
      if(a[i][j] == '#') {
        flag = false;
        break;
      }
    }
    if(flag) { gyo.insert(j); }
  }

  for(int i = 0; i < H; i++) {
    if(retu.count(i) > 0) { continue; }
    for(int j = 0; j < W; j++) {
      if(gyo.count(j) > 0) { continue; }
      cout << a[i][j];
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

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

const ll mod = 1e9 + 7;
const ll inf = 1e18;

const int N_MAX = 100010;
ll dp_A[N_MAX];
ll dp_AB[N_MAX];
ll dp_ABC[N_MAX];
ll dp_N[N_MAX];

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

    // input
    string s;
    cin >> s;

    ll L = s.size();
    dp_A[0] = 0;
    dp_AB[0] = 0;
    dp_ABC[0] = 0;
    dp_N[0] = 1;

    // i文字目を見たとき (1-indexed)
    FOR(i, 1, L+1){
        char c = s[i-1];
        if(c=='A'){
            dp_A[i] = dp_A[i-1] + dp_N[i-1]; // 文字列数分だけAが増える
            dp_AB[i] = dp_AB[i-1];
            dp_ABC[i] = dp_ABC[i-1];
            dp_N[i] = dp_N[i-1];
        }
        else if(c=='B'){
            dp_A[i] = dp_A[i-1];
            dp_AB[i] = dp_AB[i-1] + dp_A[i-1]; // １つ前のAの数だけABが増える
            dp_ABC[i] = dp_ABC[i-1];
            dp_N[i] = dp_N[i-1];
        }
        else if(c=='C'){
            dp_A[i] = dp_A[i-1];
            dp_AB[i] = dp_AB[i-1];
            dp_ABC[i] = dp_ABC[i-1] + dp_AB[i-1]; // 1つ前のABの数だけABCが増える
            dp_N[i] = dp_N[i-1];
        }
        else if(c=='?'){
            // Aの場合
            ll A_A = dp_A[i-1] + dp_N[i-1];
            ll AB_A = dp_AB[i-1];
            ll ABC_A = dp_ABC[i-1];

            // B
            ll A_B = dp_A[i-1];
            ll AB_B = dp_AB[i-1] + dp_A[i-1];
            ll ABC_B = dp_ABC[i-1];

            // C
            ll A_C = dp_A[i-1];
            ll AB_C = dp_AB[i-1];
            ll ABC_C = dp_ABC[i-1] + dp_AB[i-1];

            dp_A[i] = A_A + A_B + A_C;
            dp_AB[i] = AB_A + AB_B + AB_C;
            dp_ABC[i] = ABC_A + ABC_B + ABC_C;

            dp_N[i] = 3 * dp_N[i-1];
        }

        dp_A[i] %= mod;
        dp_AB[i] %= mod;
        dp_ABC[i] %= mod;
        dp_N[i] %= mod;

        // pn(i);
        // pn(c);
        // pn(dp_A[i]);
        // pn(dp_AB[i]);
        // pn(dp_ABC[i]);
        // pn(dp_N[i]);
        // br();
        
    }

    p(dp_ABC[L]);
    
    
    return 0;
}

Measured memory_bytes: 3664
def binary_search(A, n, key):
    start = 0
    end = n - 1
    while start + 1 < end:
        mid = (start + end) // 2
        if key > A[mid]:
            start = mid
        elif key < A[mid]:
            end = mid
        else:
            end = mid
    if A[start] == key:
        return True
    elif A[end] == key:
        return True
    else:
        return False

n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
count = 0
for i in T:
    if binary_search(S, n, i):
        count += 1


print(count)

Measured memory_bytes: 18768
from collections import deque

N = int(input())
A = [int(a) for a in input().split()]
B = deque([])
for n in range(N):
    if n % 2 == 0:
        B.append(A[n])
    else:
        B.appendleft(A[n])
if N % 2 == 0:
    print(*B)
else:
    print(*list(B)[::-1])

Measured memory_bytes: 25540
H,W = map(int,input().split())
a = []
for i in range(H):
    a.append(list(map(int,input().split())))

ans = []
for i in range(H):
    for j in range(W):
        if a[i][j] % 2 != 0:
            if j == W - 1 and i != H - 1:
                a[i][j] -= 1
                a[i+1][j] += 1
                ans.append([i+1,j+1,i+2,j+1])
            elif j != W - 1:
                a[i][j] -= 1
                a[i][j+1] += 1
                ans.append([i+1,j+1,i+1,j+2])

print(len(ans))
for i in range(len(ans)):
    print(" ".join(map(str,ans[i])))


Measured memory_bytes: 66268
{-# LANGUAGE ScopedTypeVariables #-}
import Control.Applicative
import Control.Monad
import Control.Monad.State
import Control.DeepSeq
import Data.Array
import Data.Bits
import Data.Char
import Data.Functor.Identity
import Data.List
import Data.Maybe
import Data.Ord
import Data.Tree
import Data.Tuple
import qualified System.IO
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.Sequence as Q
import qualified Data.ByteString.Char8 as B

main = do
  s <- map decode <$> getLine
  k :: Z <- readLn
  putStrLn $ map encode $ solve s k

decode c = ord c - ord 'a'
encode i = chr (ord 'a' + i)

solve [c] k = [(c + k) `mod` 26]
solve (0:cs) k = 0 : solve cs k
solve (c:cs) k =
  if c + k >= 26
  then 0 : solve cs (k - (26-c))
  else c : solve cs k

 
type Z = Int
type Q = Rational
type R = Double
type S = String

fint :: (Integral a, Num b) => a -> b
fint = fromIntegral

getInt = fst . fromJust . B.readInt <$> B.getLine
getIntPair = (\[a,b]->(a,b)) <$> getInts
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine
getStr = B.unpack <$> B.getLine

yesNo :: Bool -> String
yesNo True = "YES"
yesNo False = "NO"

printList :: (Show a) => [a] -> IO ()
printList = putStrLn . unwords . map show

readLnList :: (Read a) => IO [a]
readLnList = map read . words <$> getLine


-----  Union-find
type UnionFindT v m a = StateT (M.Map v (UnionFindVal v)) m a
newtype UnionFindVal v = UnionFindVal v

runUnionFindT :: (Monad m) => UnionFindT v m a -> m a
runUnionFindT = flip evalStateT $ M.empty

runUnionFind = runIdentity . runUnionFindT

ufFresh :: (Monad m, Ord v) => v -> UnionFindT v m ()
ufFresh v = modify $ M.insert v (UnionFindVal v)

ufClass :: (Monad m, Ord v) => v -> UnionFindT v m v
ufClass v = do
  (UnionFindVal pv) <- gets (M.! v)
  if v == pv
    then return v
    else do
      c <- ufClass pv
      modify $ M.insert v (UnionFindVal c)
      return c

ufUnify v w = do
  cv <- ufClass v
  cw <- ufClass w
  modify $ M.insert cw (UnionFindVal cv)
  return $ cv /= cw


Measured memory_bytes: 5116
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef pair<int,int> pii;
typedef vector<pii> vp;
typedef vector<int> vi;

int main(){
  int n;
  while(cin >> n,n){
    vp s(n);
    rep(i,n)cin >> s[i].first >> s[i].second;
    sort(all(s));

    vi t(n), lap(n);
    rep(i,n){
      t[i] = s[i].first;
      lap[i] = s[i].second;
    }
    vi q1,q2;
    rep(i,n)q1.push_back(i);
    
    int ans = 0;
    while(q1.size() || q2.size()){
      int nxt = 1000;
      vi goal1, goal2;
      if(q1.size())nxt = min(nxt, t[q1.front()]);
      if(q2.size())nxt = min(nxt, t[q2.front()]);
      ans += nxt;
      
      rep(i,q1.size()){
	t[q1[i]] -= nxt;
	if(i>0 && t[q1[i-1]] > t[q1[i]])t[q1[i]] = t[q1[i-1]];
      }
      rep(i,q1.size()){
	if(t[q1[i]]==0){
	  goal1.push_back(q1[i]);
	  q1.erase(q1.begin()+i--);
	}
      }

      rep(i,q2.size()){
	t[q2[i]] -= nxt;
	if(i>0 && t[q2[i-1]] > t[q2[i]])t[q2[i]] = t[q2[i-1]];
      }
      rep(i,q2.size()){
	if(t[q2[i]]==0){
	  goal2.push_back(q2[i]);
	  q2.erase(q2.begin()+i--);
	}
      }
      
      sort(all(goal1)); sort(all(goal2));
      rep(i,goal1.size()){
	q2.push_back(goal1[i]);
	t[goal1[i]] = s[goal1[i]].first;
      }
      rep(i,goal2.size()){
	if(--lap[goal2[i]]){
	  q1.push_back(goal2[i]);
	  t[goal2[i]] = s[goal2[i]].first;
	}
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
int main(){
  string a,b,c;
  char A,B,C;
  cin>>a>>b>>c;
  A=toupper(a.at(0));
  B=toupper(b.at(0));
  C=toupper(c.at(0));
  cout<<A<<B<<C<<endl;
}


Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

S = input()
N = len(S) - 1

ans = 0
for i in range(1 << N):
    exp = ""
    for j in range(len(S)):
        exp += S[j]
        if i & 1 << j > 0:
            exp += "+"
    ans += sum(map(int, exp.split("+")))
print(ans)

Measured memory_bytes: 9352
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,m;
  cin >> n >> m;
  vector<int> vec(n,0);
  for(int i=0 ;i<m*2;i++){
    int j;
    cin >> j;
    vec.at(j-1) +=1;
  }
  for(int i=0;i<n;i++){
    cout << vec.at(i) << endl;
  }
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    FASTINOUT;
    int x;
    cin>>x;
    ll ans=0;
    for (int i=1; i<=1e6; i++)
    {
        for (int j=1; i*j<x; j++)
        {
            ans++;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3644
N=int(input())
B=list(map(int,input().split()))
A=[0]*N
for i in range(len(B)):
    A[i]=B[i]
    A[i+1]=B[i]
for j in range(len(B)):
    if A[j+1]>=B[j]:
        A[j+1]=B[j]
print(sum(A))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<LL> VI;
typedef vector<VI> VVI;
typedef pair<LL, LL> PII;
typedef vector<string> VS;
inline LL toInt(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(x,c) for(auto x: (c))
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define REVERSE(c) reverse((c).begin(), (c).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define STABLE_SORT(c) stable_sort((c).begin(),(c).end())
#define STABLE_RSORT(c) stable_sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique((c).begin(), (c).end()), (c).end());
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define dump(x)  cerr << #x << " = " << (x) << endl;


int main() {
	LL N, A, B;
	cin >> N;
	cin >> A >> B;
	VI P;
	P.resize(N);
	LL X = 0, Y = 0, Z = 0;
	REP(i, N) {
		cin >> P[i];
		if (P[i] <= A) {
			X++;
		} else if (P[i] >= B + 1) {
			Z++;
		} else {
			Y++;
		}
	}

	cout << min(min(X, Y), Z) << endl;

    return 0;
}


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

#define debug(x) cout<<#x<<"="<<x<<endl
#define pii pair<int,int>
#define ll long long
#define pb push_back
#define mp make_pair

ll ans=1;
int n;
string s;
bool f;

int main(){
	int i;
	cin>>n>>s>>s;
	if (n==1){
		cout<<3;
		return 0;
	}
	if (s[0]==s[1]){
		ans*=6;
		f=false;
		i=2;
	}else{
		ans*=3;
		f=true;
		i=1;
	}
	for (i;i<n-1;i++){
		if (s[i]==s[i+1]){
			if (f){
				ans*=2;
			}else{
				ans*=3;
			}
			ans%=1000000007;
			i++;
			f=false;
		}else{
			if (f) ans*=2;
			ans%=1000000007;
			f=true;
		}
	}
	if (s[n-1]!=s[n-2]){
		if (f) ans*=2;
		ans%=1000000007;
		f=true;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#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 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int A,B,C,D;
int main(){
    bool ans = true;
    cin >>A>>B>>C>>D;
    while(A>0 && C>0){
        C = C - B;
        if(C <= 0){
            break;
        }
        A = A - D;
        if(A <= 0){
            ans = false;
            break;
        }
    }
    cout << (ans ? "Yes":"No") << endl;
}

Measured memory_bytes: 3624
N = int(input())
A = list(map(int,input().split()))
m = 1
flag = True
try:
    a = A.index(0)
    print(0)
except:

    for n in range(N):
        m *= A[n]
        if m > 10**18:
            print(-1)
            flag = False
            break

    if flag:
        print(m)


Measured memory_bytes: 21608
#include<iostream>
#include<cmath>

using namespace std;

int main(){
  int x1, y1, x2, y2;
  int x3, y3, x4, y4;
  
  cin >> x1 >> y1 >> x2 >> y2;
  
  int dx = x2 - x1, dy = y2 - y1;
  x3 = x2 - dy;
  y3 = y2 + dx;
  x4 = x1 - dy;
  y4 = y1 + dx;
  
  cout << x3 << ' ' << y3<< ' ' << x4 << ' ' << y4 << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,p,k,l,h;
    cin>>n>>m>>p>>k;
    l=n+m;
    h=p+k;
    if(h==l)
    {
        cout<<"Balanced"<<endl;
    }
    if(h>l)
    {
        cout<<"Right"<<endl;
    }

    if(h<l)
    {
        cout<<"Left"<<endl;
    }

}


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

int main()
{
	string s;
	cin >> s;
	sort(s.begin(), s.end());


	string t;
	cin >> t;
	sort(t.begin(), t.end());
	reverse(t.begin(), t.end());


	if (s < t)cout << "Yes" << endl;
	else cout << "No"<<endl;


}

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

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;


int main(){
  int a[3];
  cin >> a[0] >> a[1] >> a[2];

  sort(a,a+3);

  if((a[1] - a[0])%2 == 1)cout << a[2] - a[1] + (a[1] - a[0] + 1)/2 + 1 << endl;
  else cout << a[2] - a[1] + (a[1] - a[0])/2 << endl;


  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	int n, a, b, c, d; cin >> n;
	for (int h = 0; h < n; h++) {
		cin >> a >> b >> c >> d;
		if (c >= 5 && d >= 2) {
			cout << ((a*c) + (b*d)) * 4 / 5 << endl;
		}
		else {
			if ((a*c) + (b*d) > ((a*max(c, 5)) + (b*max(d, 2))) * 4 / 5) {
				cout << ((a*max(c, 5)) + (b*max(d, 2))) * 4 / 5 << endl;
			}
			else {
				cout << (a*c) + (b*d) << endl;
			}
		}
	}
	cin >> n;
}


Measured memory_bytes: 3120
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

typedef vector<int> vi;
typedef pair<int,int> ii;
#define sz(a) int((a).size())
#define all(c) (c).begin(), (c).end()

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

	int w, h, x, y;
	scanf("%d%d%d%d", &w, &h, &x, &y);
	double area = (double)w * h / 2.0;
	int multi = (2*x == w && 2*y == h);
	printf("%.10f %d\n", area, multi);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;

int main() {
  int c = '0';
  string s;
  cin >> s;

  int day=  (s[8]-c)*10 + (s[9]-c);
  int month = (s[5]-c)*10 + s[6]-c;
  int year = (s[0]-c) * 1000 + (s[1]-c) * 100 + (s[2]-c) * 10 + (s[3]-c);
  if (year > 2019) {
    cout << "TBD" << endl; 
    return 0;
  }
  if (month > 4){
    cout << "TBD" << endl;
    return 0;
  }
    cout << "Heisei" << endl;
    return 0;
}


Measured memory_bytes: 256
n, m, x, y = map(int, input().split())
x_city = list(map(int, input().split()))
y_city = list(map(int, input().split()))
x_city.sort()
y_city.sort()
if y_city[0] - x_city[-1] > 0 and x < y_city[0] and x_city[-1] < y:
    print('No War')
else:
    print('War')

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

int main() {
	int n;
	cin >> n;
	vector<int> a(n+1);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	vector<int> ans(n+1);
	for (int i = n; i >= 1; i--) {
		int sum = 0;
		for (int j = i+i; j <= n; j += i) {
			sum += ans[j];
		}
		sum %= 2;
		if (sum != a[i]) ans[i] = 1;
		else ans[i] = 0;
	}
	int m = 0;
	for (int i = 1; i <= n; i++) {
		if (ans[i] == 1) m++;
	}
	cout << m << endl;
	for (int i = 1; i <= n; i++) {
		if (ans[i] == 1) cout << i << endl;
	}
	return 0;
}

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

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define size_t unsigned long long
#define ll long long
#define rep(i,a) for(int i=0;i<(a);i++)
#define repr(i,a) for(int i=(int)(a)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=a;i--)
#define ALL(a) a.begin(), a.end()
using namespace std;
int si() { int x; scanf("%d", &x); return x; }
long long sl() { long long x; scanf("%lld", &x); return x; }
string ss() { string x; cin >> x; return x; }
void pi(int x) { printf("%d ", x); }
void pl(long long x) { printf("%lld ", x); }
void pd(double x) { printf("%.15f ", x); }
void ps(const string &s) { printf("%s ", s.c_str()); }
void br() { putchar('\n'); }

const int MOD = 1e9 + 7;

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

typedef pair<int, int> P;

const int N = 1e5+5;
string s;
vector<int> v[N];
int n,k;
int result;
int h;

int main () {
  cin >> n >> k;
  rep(i,n) {
    cin >> h;
    if(h >= k) result++;
  }
  cout << result << endl;
}


Measured memory_bytes: 2560
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>
#include<map>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;
const long long MOD = (long long)1e9 + 7;

int main(){
    int n;
    cin >> n;
    vector<ll> c(n), dp(n + 1);
    for(int i = 0; i < n; i++){
        cin >> c[i];
    }
    map<int, int> mp;
    dp[0] = 1;
    for(int i = 0; i < n; i++){
        dp[i + 1] = dp[i];
        if(mp.find(c[i]) != mp.end() && mp[c[i]] != i - 1){
            dp[i + 1] += dp[mp[c[i]] + 1];
            dp[i + 1] %= MOD;
        }
        mp[c[i]] = i;
    }
    cout << dp[n] << endl;
    return 0;
}


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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

vector<bool> sieve(ll N)
{
	vector<bool> isp(N+1, true);

	isp[0] = false;
	isp[1] = false;
	for (ll i = 2; i*i <= N; ++i)
	{
		if (isp[i]) for (ll j = i*i; j <= N; j+=i) isp[j] = false;
	}
	return isp;
}
int main(int argc, char **argv)
{
	ll N; cin >> N;
	vector<bool> isp = sieve(60000);

	--N;
	std::cout << 2 << " ";
	for(ll i = 1; i < 30000; ++i)
	{
		if (isp[5*i+1])
		{
			std::cout << 5*i+1;
			--N;
			if (N == 0) break;
			else
				std::cout << " ";
		}
	}
	std::cout << std::endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
using namespace std;

long long cnt[(int)(1e5 + 500)];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
                
    #ifndef _LOCAL          
    #endif // _LOCAL

    int n;
    long long ans = 0;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        ans += x;
        ++cnt[x];
    }

    int q;
    cin >> q;
    while (q--) {
        long long b, c;
        cin >> b >> c;

        ans += cnt[b] * (c - b);
        cnt[c] += cnt[b];
        cnt[b] = 0;

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

    return 0;
}

Measured memory_bytes: 4364
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define ALL(V) ((V).begin(),(V).end())
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
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 namespace std;
using Graph = vector<vector<ll>>;
ll ANS[1000000];

int main(){
  ll N,M;
  cin>>N>>M;
  
  Graph G(N);
  REP(i,M){
    ll A,B;
    cin>>A>>B;
    G[A-1].push_back(B-1);
    G[B-1].push_back(A-1);
  }
  
  vector<int> dist(N, -1); // 全頂点を「未訪問」に初期化
  queue<int> que;
  ll ANS[N];
  REP(i,N) ANS[i]=0;
  
  // 初期条件 (頂点 0 を初期ノードとする)
  dist[0]=0;
  que.push(0); // 0 を橙色頂点にする
  
  // BFS 開始 (キューが空になるまで探索を行う)
  while(!que.empty()){
    int v=que.front(); // キューから先頭頂点を取り出す
    que.pop();
    
    // v から辿れる頂点をすべて調べる
    for(int nv : G[v]){
      if(dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない
      
      // 新たな白色頂点 nv について距離情報を更新してキューに追加する
      dist[nv] = dist[v] + 1;
      if(ANS[nv]==0) ANS[nv]=v+1;
      que.push(nv);
    }
  }

  cout<<"Yes"<<endl;
  for(int v=1; v<N; ++v) cout<<ANS[v]<<endl;
}

Measured memory_bytes: 13204
import sys
n = int(input())
a = list(map(int, input().split()))
count = 0

while 1:
    ans = 0
    for i in range(n):
        if a[i] % 2 == 0:
            ans += 1
            a[i] /= 2
    if ans == n:
        count += 1
    else:
        break

print(count)

Measured memory_bytes: 38768
#include<vector>
#include <iostream>
#include <math.h>

using namespace std;

int main(){
    const long h = 1000000007;
    long x;
    cin >> x;
    long power = 1;
    //power = power % h;
    for(int i = 0; i < x; i++){
        power = power * (i+1) % h;
    }
    cout << power<< endl;
}

Measured memory_bytes: 256
// ABC 076B
//参考
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N,K;
    cin >> N >> K;
    int num = 1;
    for(int i = 1; i <= N; i++){
        int a = num * 2;
        int b = num + K;
        if(a < b) num=  a;
        else num = b;

    }
    cout << num << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};


int main(void){
    int N;
    cin >> N;
    int A[N];
    rep(i,N) cin >> A[i];
    bool ans=true;
    rep(i,N) if(A[i]%2==0) if(A[i]%3!=0 && A[i]%5!=0) ans=false;
    if(ans) cout << "APPROVED" << endl;
    else cout << "DENIED" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<queue>
using namespace std;
typedef pair<int, int>pii;
typedef pair<pii, int>pi3;
vector<pii>pat[600000];
bool flag[600000];
int dist[600000];
int main()
{
	int num, way;
	scanf("%d%d", &num, &way);
	vector<pii>zat;
	vector<pi3>zp;
	for (int i = 0; i < way; i++)
	{
		int za, zb, zc;
		scanf("%d%d%d", &za, &zb, &zc);
		za--, zb--, zc--;
		zat.push_back(make_pair(za, zc));
		zat.push_back(make_pair(zb, zc));
		zp.push_back(make_pair(make_pair(za, zb), zc));
		zp.push_back(make_pair(make_pair(zb, za), zc));
	}
	sort(zat.begin(), zat.end());
	for (int i = 0; i < zat.size(); i++)
	{
		pat[num + i].push_back(make_pair(zat[i].first, 0));
		pat[zat[i].first].push_back(make_pair(num + i, 1));
	}
	for (int i = 0; i < zp.size(); i++)
	{
		int l1 = lower_bound(zat.begin(), zat.end(), make_pair(zp[i].first.first, zp[i].second)) - zat.begin();
		int l2 = lower_bound(zat.begin(), zat.end(), make_pair(zp[i].first.second, zp[i].second)) - zat.begin();
		pat[l1 + num].push_back(make_pair(l2 + num, 0));
	}
	priority_queue<pii>que;
	que.push(make_pair(0, 0));
	fill(dist, dist + 600000, 1000000000);
	for (;;)
	{
		if (que.empty())break;
		pii z = que.top();
		que.pop();
		if (flag[z.second])continue;
		flag[z.second] = true;
		for (int i = 0; i < pat[z.second].size(); i++)
		{
			if (dist[pat[z.second][i].first]>-z.first + pat[z.second][i].second)
			{
				dist[pat[z.second][i].first] = -z.first + pat[z.second][i].second;
				que.push(make_pair(-dist[pat[z.second][i].first], pat[z.second][i].first));
			}
		}
	}
	if (flag[num - 1])printf("%d\n", dist[num - 1]);
	else printf("-1\n");
}

Measured memory_bytes: 55036
n = int(input())
L = []
ans = 0

for i in range(n):
    a = int(input())
    for j in range(a):
        x, y = map(int, input().split())
        L.append((i, x-1, y))

for i in range(1<<n):
    flg = True
    for j, x, y in L:
        if i>>j & 1 and i>>x & 1 != y:
            flg = False
            break
    if flg:
        ans = max(ans, sum(i>>j & 1 for j in range(n)))

print(ans)


Measured memory_bytes: 9140
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;
 
signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  priority_queue<pair<int, int>> ans;
  int p;
  rep(i, a){
    cin >> p;
    ans.emplace(p, 1);
  }
  rep(i, b){
    cin >> p;
    ans.emplace(p, 2);
  }
  rep(i, c){
    cin >> p;
    ans.emplace(p, 3);
  }
  lol sum = 0;
  a = b = c = 0;
  while(a + b + c < x + y){
    if(ans.top().second == 1){
      if(a < x){
	a ++;
	sum += ans.top().first;
      }
    } else if(ans.top().second == 2){
      if(b < y){
	b ++;
	sum += ans.top().first;
      }
    } else {
      c ++;
      sum += ans.top().first;
    }
    ans.pop();
  }
  cout << sum << '\n';
  return 0;
}


Measured memory_bytes: 7412
n = int(input())
a = list(map(int, input().split()))

def check_two(num):
    count = 0
    while num % 2 == 0:
        num /= 2
        count += 1
    return count

total_count = 0
for i in range(n):
    total_count += check_two(a[i])

print(total_count)

Measured memory_bytes: 4148
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

int main() {
    ll N, K;
    cin >> N >> K;

    ll divided = N / K;
    ll left = N % K;
    string digits = "";
    while (divided > 0) {
        digits.push_back('0' + left);
        left = divided % K;
        divided = divided / K;
    }
    digits.push_back('0' + left);
    reverse(digits.begin(), digits.end());

    int ans = digits.size();

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3556
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>

using namespace std;

long long int ceil(long long int a, long long int b)
{
	return (a + (b - 1)) / b;
}

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

	vector<pair<long long int, long long int > > a(N);
	for (int i = 0; i < N; i++)
	{
		cin >> a[i].first >> a[i].second;
	}

	long long int x = 1;
	long long int  y = 1;

	for (int i = 0; i < N; ++i)
	{
		long long int xm = ceil(x, a[i].first);
		long long int ym = ceil(y, a[i].second);
		long long int maxm = max(xm, ym);

		x = maxm*a[i].first;
		y = maxm*a[i].second;
	}
	long long int ans = x + y;
	std::cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
/*input
5 5
1 2
1 3
3 4
3 5
4 5
*/
#include <bits/stdc++.h>
using namespace std;

const int N = 705;
int n, m, save =  0, edge[N][N], dp[N][1405], color[N];

void dfs(int u) {
	save += color[u] ? 1 : -1;
	for(int v = 1; v <= n; ++ v) if(edge[u][v]) {
		if(color[v] != -1) {
			if(color[v] == color[u]) puts("-1"), exit(0);
			continue;
		}
		color[v] = color[u] ^ 1;
		dfs(v);
	}
}

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; ++ i) {
		int a, b; scanf("%d%d", &a, &b);
		edge[a][b] = edge[b][a] = 1;
	}

	for(int i = 1; i <= n; ++ i)
		for(int j = 1; j <= n; ++ j) if(i != j) edge[i][j] ^= 1;

	int cnt = 0; dp[0][700] = 1;
	memset(color, -1, sizeof color);
	for(int i = 1; i <= n; ++ i)  
		if(color[i] == -1) {
			color[i] = 0, save = 0, dfs(i);
			save = abs(save);

			for(int j = 0; j <= 1400; ++ j) {
				if(j >= save) dp[cnt + 1][j] |= dp[cnt][j - save];
				if(j + save <= 1400) dp[cnt + 1][j] |= dp[cnt][j + save];
			}
			++ cnt;
		}

	for(int i = 700; i <= 1400; ++ i)
		if(dp[cnt][i]) {
			int a = (n - i + 700) >> 1, b = (n + i - 700) >> 1;
			printf("%d\n", a * (a - 1) / 2 + b * (b - 1) / 2);
			// cout << i << ' ' << a << ' ' << b << endl;
			break;
		}
}

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

int main(int argc, char const *argv[])
{
	string s;
	cin>>s;
	int f=1;
	if (s[0]!='A')
	{
		f=0;
	}
	int cnt=0;
	for (int i = 2; i < s.size()-1; ++i)
	{
		if (s[i]=='C')
		{
			++cnt;
		}
	}
	if (cnt!=1)
	{
		f=0;
	}
	for (int i = 1; i < s.size(); ++i)
	{
		if (s[i]<'a'||'z'<s[i])
		{
			--cnt;
		}
	}
	if (cnt!=0)
	{
		f=0;
	}
	if (f)
	{
		cout<<"AC\n";
	}
	else
	{
		cout<<"WA\n";
	}
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
using namespace std;
#define mod 1000000007
#define maxn 100005
char s[maxn];
int num[maxn];
int all[maxn];
int main()
{
    scanf("%s",s);
    int len=strlen(s);
    for(int i=0;i<len;i++)
    {
        if(s[i]=='(')   num[i+1]=1;
        else num[i+1]=-1;
    }
    int temp=0;
    for(int i=1;i<=len;i++)
    {
        temp+=num[i];
        all[temp]++;
    }
    long long fin=0;
    temp=0;
    all[0]++;
    for(int i=1;i<=len;i++)
    {
        all[temp]--;
        fin+=all[temp];
        temp+=num[i];
    }
    printf("%lld\n",fin-1);
}

Measured memory_bytes: 1820
fun main(args:Array<String>?): Unit {
    println(solve(readLine()!!.trim()) ?: -1)
}
fun solve(state: String): String? {
    tailrec fun sub(position: Int, count: Int): String? {
        return if (position == state.length) {
            if (count >= 2) "AZ".repeat(count / 2)
            else null
        }
        else {
            if (count % 2 == 0 && state[position] == 'A') sub(position + 1, count + 1)
            else if (count % 2 == 1 && state[position] == 'Z') sub(position + 1, count + 1)
            else sub(position + 1, count)
        }
    }
    return sub(0, 0)
}


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

int main(){
	int n,m;
	int *potato;
	int count, pos;
	while(cin>>n>>m,n||m){
		potato = new int[n];
		for(int i=0;i<n;++i)potato[i]=1;
		pos = 0;
		for(int i=0;i<n;++i){
			count = 0;
			while(1){
				if(potato[pos])count++;
				if(count == m){
					potato[pos] = 0;
					break;
				}
				pos = (pos+1)%n;
			}
		}
		cout<<pos+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 1200
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int MAX = 100005;
int fac[MAX], inv[MAX], finv[MAX];

void pre(){
  inv[1]=1;
  for (int i = 2; i <MAX ; i++)
  {
    inv[i]=inv[mod%i]*(mod-mod/i)%mod;
  }
  fac[0]=finv[0]=1;
  for (int i = 1; i < MAX; ++i)
  {
    fac[i]=fac[i-1]*i%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}
int ncr(int n, int r){
  if(r<0||r>n)return 0;
  return fac[n]*finv[r]%mod*finv[n-r]%mod;
}
int n,k;
int a[101010];

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  pre();
  cin >> n >> k;
  for(int i=1;i<=n;i++){
    cin >> a[i];
  }
  sort(a+1,a+n+1);
  int ans = 0;
  for(int i=1;i<=n;i++){
    ans = (ans + ncr(i-1,k-1)*a[i]%mod + mod )%mod;
    ans = (ans - ncr(n-i,k-1)*a[i]%mod + mod )%mod;
  }
  cout << ans << endl;
  

return 0;
}
///....


Measured memory_bytes: 3456