akhauriyash/Code-Regression huggingface dataset:
n, m = map(int, input().split())
A = list(map(int, input().split()))

tmp_list = []

for i in range(n):
    tmp = A[i]
    now = tmp
    while True:
        if tmp != 0:
            tmp = tmp // (2)
            tmp_list.append(now - tmp)
            now = tmp
        else:
            break

tmp_list.sort(reverse=True)
print(sum(A) - sum(tmp_list[:m])) 

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

int h, w;
string input [102];

int main (){
	cin>>h>>w;
	for (int i=1; i<=h; i++)
		cin>>input [i];
	for (int i=1; i<=w+2; i++){
		cout<<"#";
	}
	cout<<endl;
	for (int i=1; i<=h; i++){
		cout<<"#"<<input [i]<<"#"<<endl;
	}
		for (int i=1; i<=w+2; i++){
		cout<<"#";
	}
}

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

int main(){
  int K,T;
  cin>>K>>T;
  int a[T];
  for(int i=0;i<T;i++){
    cin>>a[i];
  }
  sort(a,a+T);
  int d=a[T-1];
   if(d>K-d+1){
    cout<<d-(K-d)-1<<endl;
    return 0;
  }
  cout<<0<<endl;
  return 0;
}


Measured memory_bytes: 256
import sys

def parse(inp):
    n,m = map(int,next(inp).split())
    lr =[]
    for _ in range(m):
        lr.append(list(map(int,next(inp).split())))
    
    return n,m,lr
  
def main(inp):
    n,m,lr = inp
    
    b1 = 1
    b1 = ((b1 << (lr[0][1]-lr[0][0]+1)) - 1) << lr[0][0]-1 
    
    b2 = 1
    for i in range(1,m):
        b2 = ((b2 << (lr[i][1]-lr[i][0]+1)) - 1) << lr[i][0]-1
        b1 = b1 & b2
        b2 = 1
    
    mask = (1 << n) - 1
    b1 = b1 & mask
    return bin(b1).count("1")
  
print(main(parse(sys.stdin)))

Measured memory_bytes: 27500
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws IOException{
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String input = br.readLine();
		
		boolean used[] = new boolean[26];
		
		for(int i = 0; i < input.length(); i++){
			used[input.charAt(i) - 'a'] = true;
		}
		
		int prev = 0;
		for(int i = input.length() - 1; i >= -1 ; i--){
			for(int j = prev; j < 26 ; j++){
				if(!used[j]){
					System.out.println(input+(char)(j + 'a'));
					return;
				}
			}
			
			if(input.length() == 0){
				break;
			}
			prev = input.charAt(input.length() - 1) - 'a' + 1;
			used[input.charAt(input.length() - 1) - 'a'] = false;
			
			input = input.substring(0, input.length() - 1);
		}
		
		System.out.println(-1);
	}
	
}



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

using namespace std;
typedef long long ll;

#define rep(i, n) for(int i=0; i<(n); ++i)

bool isBalancedS(const string &s) {
    int cnt = 0;
    rep(i, s.size()) {
        if(s[i] == '[') cnt++;
        if(s[i] == ']') cnt--;
        if(cnt < 0) return false;
    }
    if(cnt > 0) return false;
    return true;
}
bool isBalancedR(const string &s) {
    int cnt = 0;
    rep(i, s.size()) {
        if(s[i] == '(') cnt++;
        if(s[i] == ')') cnt--;
        if(cnt < 0) return false;
    }
    if(cnt > 0) return false;
    return true;
}

bool isBalanced(const string &s) {
    if(!isBalancedS(s)) return false;
    if(!isBalancedR(s)) return false;
    // check substring
    for(int i=0; i<s.size(); ++i) {
        if(s[i] == '(') {
            int len = 0;
            int cnt = 1;
            for(int j=i+1; j<s.size(); ++j, ++len) {
                if(s[j] == '(') cnt++;
                if(s[j] == ')') cnt--;
                if(cnt==0) break;
            }
            if(!isBalancedS(s.substr(i+1, len))) return false;
        } else if(s[i] == '[') {
            int len = 0;
            int cnt = 1;
            for(int j=i+1; j<s.size(); ++j, len++) {
                if(s[j] == '[') cnt++;
                if(s[j] == ']') cnt--;
                if(cnt==0) break;
            }
            if(!isBalancedR(s.substr(i+1, len))) return false;
        }
    }
    return true;
}

int main(void){
    string s;
    while(getline(cin, s) && s!=".") {
        if(isBalanced(s)) cout << "yes" << endl;
        else cout << "no" << endl;
    }
}

Measured memory_bytes: 1184
#include<stdio.h>
int main()
{
    int n,d,i,min,max;
    long long int sum = 0;
    scanf("%d",&n);

    long long int arr[n];
    for(i=0; i<n; i++)
    {
        scanf("%lld",&arr[i]);
    }
     min = max = arr[0];

    for(i=0; i<n; i++)
    {
        if(min>arr[i])
        {
            min=arr[i];
        }
        if(max<arr[i])
        {
            max=arr[i];
        }
        sum=sum+arr[i];
    }

    printf("%d %d %lld\n",min,max,sum);

    return 0;
}


Measured memory_bytes: 2100
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}


signed main(void) {
    int i,j;
    int n;
    cin >> n;
    vi x(n),y(n),h(n);
    rep(i,n) cin >> x[i] >> y[i] >> h[i];
    rep(i,n)if(h[i] >= 1){
        x.push_back(x[i]);
        y.push_back(y[i]);
        h.push_back(h[i]);
        break;
    }
    rep(px,101)rep(py,101){
        int H = h.back() + abs(px - x.back()) + abs(py - y.back());
        bool c = true;
        rep(i,n){
            int a = max(H - abs(x[i] - px) - abs(y[i] - py),0LL);
            if(h[i] != a)c = false;
        }
        if(c){
            cout << px << " " << py << " " << H << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include <stdio.h>
  
int main(){
  //入力
  int A,B,C;
  //B<AかつA,B,Cは1から20までの整数
  scanf("%d %d %d", &A,&B,&C);

  //計算
  C = C-(A-B);
  if(C<0) C=0;

  //出力
  printf("%d", C);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <iomanip>

//auto print = [](auto x){ std::cout << x; };
auto println = [](auto x){ std::cout << x << std::endl; };
auto read = [](auto &x){ std::cin >> x; };

int main ()
{
  double a, b, theta;

  std::cin >> a >> b >> theta;
  std::cout << std::setprecision(20);

  theta = theta / 180.0 * M_PI;

  auto area = 0.5 * a * b * std::sin(theta);
  auto c = std::sqrt(a*a + b*b - 2*a*b*std::cos(theta));
  auto l = a + b + c;
  auto h = b*std::sin(theta);
  println(area);
  println(l);
  println(h);
}



Measured memory_bytes: 3524
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>


using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<n;++i)
#define FOR(i, a, b) for(int i=a;i<b;++i)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=b-1;i>=a;--i)

#define all(x) begin(x),end(x)
#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

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

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


template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> p) {
    os << p.first << ":" << p.second;
    return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T1, class T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "[";
    for (auto it = mp.begin(); it != mp.end(); ++it) {
        if (it != mp.begin()) {
            os << ", ";
        }
        os << *it;
    }
    return os << "]";
}

// edit

void solve() {
    int N;
    cin >> N;

    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    sort(all(A));
    reverse(all(A));

    ll ans = 0;
    for (int i = 1; i < N; ++i) {
       ans += A[i / 2];
    }

    cout << ans << endl;
}


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
//    std::ifstream in("input.txt");
//    std::cin.rdbuf(in.rdbuf());

    solve();


    return 0;
}


Measured memory_bytes: 4432
from itertools import product

n, m = [int(i) for i in input().split()]
k = []
s = []
for _ in range(m):
    s.append([int(i) for i in input().split()])
    k.append(s[-1].pop(0))
p = [int(i) for i in input().split()]

cnt = 0
for switches in product(range(2), repeat=n):
    num_of_on_switches = [0] * m
    for i, switch in enumerate(switches):
        if switch:
            for k, ss in enumerate(s):
                if i+1 in ss:
                    num_of_on_switches[k] += 1

    for i, pp in enumerate(p):
        if num_of_on_switches[i] % 2 != pp:
            break
    else:
        cnt += 1

print(cnt)


Measured memory_bytes: 3188
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		String s = sc.next();

		int[] r = new int[n];
		int[] w = new int[n];
		int cr = 0;
		int cw = 0;
		for ( int i=0; i<n; i++ ) {
			if ( s.charAt(i)=='R' )	{
				r[cr] = i;
				cr++;
			} else {
				w[cw] = i;
				cw++;
			}
		}

		int minc = Math.min(cr, cw);
		if ( minc==0 ) {
			System.out.println(0);
			System.exit(0);
		}

		int t = 0;
		int maxr = cr-1;
		int minw = 0;

		while ( minc>0 && r[maxr]>w[minw] ) {

			t++;
			maxr--;
			minw++;
			minc--;
		}
		System.out.println(t);
	}
}

Measured memory_bytes: 42060
#include <iostream>
using namespace std;
 int main(){
   int a;
   int b;
   int c;
   cin >> a >> b >> c;
   if(a + b + c > 21){
   cout << "bust" << endl;
   }
   if(a + b + c <= 21){
     cout << "win" << endl;
   }
 }

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

int     main() {
        int N;
        double S=0;
        double A;
        cin >>N;
        for (int i=1; i<=N; i++) {
                cin >>A;
                S += 1/A;
        }
        printf("%.16f", 1/S);
        cout << endl;
        return 0;
};

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (N, M) = listOfLong()
    val A = listOfLong().map { it / 2 }
    val L = A.reduce { acc, a -> lcm(acc, a) }
    if (A.any { (L / it) % 2 == 0L }) {
        println(0)
        return
    }
    var ans = M / L
    ans = (ans + 1) / 2
    println(ans)
}
fun gcd(a: Long, b: Long): Long = if (b > 0) gcd(b, a % b) else a
fun lcm(a: Long, b: Long): Long = a / gcd(a, b) * b
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfLong(delta: Long = 0L) = listOfString().map { java.lang.Long.parseLong(it) + delta }


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

namespace Programminng
{
    class AOJ_Volume0006
    {
        public static void Main(string[] args)
        {
            var input = Console.ReadLine().ToCharArray();
            Array.Reverse(input);
            Console.WriteLine(new string(input));
        }
    }
}

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

int main() {
  int a, b, c, biggest = 0;
  cin >> a >> b >> c;
  
  biggest = max(a, max(b, c));
  
  if((biggest * 3 - (a + b + c)) % 2 == 0){
    cout << (biggest * 3 - (a + b + c)) / 2 << endl;
  }
  else{
    cout << (biggest * 3 - (a + b + c)) / 2 + 2 << endl;
  }  
}


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

int main() {
  string S;
  int Q;
  cin >> S >> Q;

  int Qu;
  int F;
  string C;
  int reverseFlg = 0;
  int XOR = 0;
  for (int i=0; i<Q; i++){
    cin >> Qu;
    Qu--;
    if (!Qu){
      reverseFlg = reverseFlg ^ ++Qu;
    } else {
      cin >> F >> C;
      F--;
      XOR = F ^ reverseFlg;
      if (XOR) {
        S.insert(S.length(), C);
      } else {
        S.insert(0, C);
      }
    }
  }
  
  if (reverseFlg) {
    reverse(S.begin(), S.end());
  }
    
  cout << S << endl;
}

Measured memory_bytes: 900
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        r: i64,
        g: i64
    }
    println!("{}", g * 2 - r);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
 

int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int n;cin>>n;
  vi a(n);
  rep(i,n)cin>>a[i];
  vsort(a);
  int ans=a[a.size()-1]-a[0];
  cout(ans);
  return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    Int A, B; cin >> A >> B;
    cout << A*B/2 << endl;
}


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

using namespace std;


int main() {

	int x;
	cin >> x;

	int ans = 1;

	for (int i = 2; i <= x; i++) {

		int num = i;

		if (i * i > x) {
			break;
		}

		while (num * i <= x) {
			num *= i;
		}
		ans = max(ans, num);
	}
	cout << ans << endl;
	return 0;
}




Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int n, a[100], i;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (i = n-1; i > 0; i--) {
    printf("%d ", a[i]);
  }
  printf("%d\n", a[i]);
  return 0;
}



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

// ローリングハッシュ
struct RollingHash {
    static const int base1 = 1007, base2 = 2009;
    static const int mod1 = 1000000007, mod2 = 1000000009;
    vector<long long> hash1, hash2, power1, power2;

    // construct
    RollingHash(const string &S) {
        int n = (int)S.size();
        hash1.assign(n+1, 0);
        hash2.assign(n+1, 0);
        power1.assign(n+1, 1);
        power2.assign(n+1, 1);
        for (int i = 0; i < n; ++i) {
            hash1[i+1] = (hash1[i] * base1 + S[i]) % mod1;
            hash2[i+1] = (hash2[i] * base2 + S[i]) % mod2;
            power1[i+1] = (power1[i] * base1) % mod1;
            power2[i+1] = (power2[i] * base2) % mod2;
        }
    }
    
    // get hash of S[left:right]
    inline pair<long long, long long> get(int l, int r) const {
        long long res1 = hash1[r] - hash1[l] * power1[r-l] % mod1;
        if (res1 < 0) res1 += mod1;
        long long res2 = hash2[r] - hash2[l] * power2[r-l] % mod2;
        if (res2 < 0) res2 += mod2;
        return {res1, res2};
    }
};

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int N;
    string S;
    cin >> N >> S;

    // ロリハ
    RollingHash rh(S);

    // 二分探索判定
    auto check = [&](int d) -> bool {
        for (int i = 0; i < N; ++i) {
            for (int j = i+d; j+d <= N; ++j) {
                if (S[i] != S[j]) continue;
                if (rh.get(i, i+d) == rh.get(j, j+d)) return true;
            }
        }
        return false;
    };

    // 二分探索
    int left = 0, right = N/2 + 1;
    while (right - left > 1) {
        int mid = (left + right) >> 1;
        if (check(mid)) left = mid;
        else right = mid;
    }
        
    cout << left << endl;
}


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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  string S; cin >> S;
  VI cnt(26);
  for(char c: S)
	cnt[c-'a']++;

  cout << (all_of(ALL(cnt), [](int c){return c%2==0;})? "Yes": "No") << endl;
  
  return 0;
}


Measured memory_bytes: 256
/*
g++ -std=c++11 -o2 -Wall AISing2019B1.cpp -o .\out\AISing2019B1.out
.\out\AISing2019B1.out
*/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

ll a[100005];
ll b[100005];

int main(){
//  freopen("./input/input.txt", "r", stdin);
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  ll suma = 0ll;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    suma += a[i];
  }
  ll sumb = 0ll;
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
    sumb += b[i];
  }
  if (suma < sumb) {
    cout << "-1\n";
    return 0;
  }
  ll need = 0;
  int ans = 0;
  vector <ll> tank;
  for (int i = 0; i < n; ++i) {
    ll d = a[i] - b[i];
    if (d < 0) {
      ++ans;
      need += (b[i] - a[i]);
    } else if (d > 0) {
      tank.push_back(d);
    }
  }
  sort(begin(tank), end(tank), greater<ll>());
  int i = 0;
  while (need > 0) {
    need -= tank[i];
    ++ans;
    ++i;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 2428
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define ktya(x) sort(all(x))
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 1e18
#define INFLL 1000000000000000007LL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define PI (acos(-1))
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
ll MOD = 1000000007;
// ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
ll powMod(ll x, ll k, ll m) {//x^k (mod n)
	if (k == 0)     return 1;
	if (k % 2 == 0) return powMod(x*x % m, k/2, m);
	else            return x*powMod(x, k-1, m) % m;
}
int N,K;
int cnt[114514]={0};
vi a,b,c;
int main(){
	cin>>N>>K;
	string str;
	cin>>str;
	int cnt=0;
	rep(i,N-1){
		if(str[i]!=str[i+1])cnt++;
	}
	cout<<N-max(0,(cnt-2*K))-1<<endl;
}




Measured memory_bytes: 512
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#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 _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
using ll = long long;
template <class T> using vec = vector<T>;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vvvi = vector<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval>newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!

// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  string s;
  cin >> s;
  bool dup = false;
  rep(i,3){
    if(s[i]==s[i+1]) dup = true;
  }
  if(dup) cout << "Bad" << endl;
  else cout << "Good" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define vvi vector<vi>
#define vs vector<string>
#define pb push_back
#define P pair<int,int>
#define vp vector<P>
#define PP pair<P,int>
#define vpp vector<PP>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#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 all(x) (x).begin(),(x).end()
int main(){
    int n;
    cin>>n;
    vi vec(n);
    REP(i,n){
        cin>>vec[i];
        vec[i]--;
    }
    int ans=0;
    REP(i,n){
        if(vec[vec[i]]==i)ans++;
    }
    cout<<ans/2<<endl;
    return 0;
}

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

using namespace std;
#define ll long long
#define ull unsigned long long
#define mp make_pair
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
int n;
ll f[300005], ans = 0;
const ll mod = 1e9 + 7;

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)scanf("%lld", &f[i]);
    for (int i = 0; i <= 60; i++) {
        ll x = 0, y = 0, cnt = 0;
        for (int j = 1; j <= n; j++)if (f[j] & (1ll << i))x++; else y++;
        for (int j = 1; j <= n; j++)if (f[j] & (1ll << i))cnt = (cnt + y) % mod, x--; else cnt = (cnt + x) % mod, y--;
        ans = (ans + (1ll << i) % mod * cnt % mod) % mod;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 2560
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
#define endl "\n"
//#define int long long
#define ALL(x) begin(x),end(x)
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return ((fact(i - 1)) * i) % MOD;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
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;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された
    if (n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である
    // 6の倍数前後の数を使って試し割りをする
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }
    return true;
}
int cnt;
/*signed*/int main(void) {   
    string s;
    cin >> s;
    rep(i, s.size()) {
        if (s[i] == '2') ++cnt;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3548
N = gets.chomp.split(" ").map(&:to_i)
arr = readlines.map{|n| n.chomp.to_i}

first = arr.sort{|x,y| y<=>x}[0]
second  = arr.sort{|x,y| y<=>x}[1] 
# p N,arr,first,second
arr.each do |n|
    if n != first
        puts first
    else
        puts second
    end
end

Measured memory_bytes: 24552
class mod_comb_k():
  def __init__(self, MAX_N = 10**6, mod = 10**9+7):
    self.fact = [1]
    self.fact_inv = [0] * (MAX_N + 4)
    self.mod = mod
    for i in range(MAX_N + 3):
      self.fact.append(self.fact[-1] * (i + 1) % self.mod)
    self.fact_inv[-1] = pow(self.fact[-1], self.mod - 2, self.mod)
    for i in range(MAX_N + 2, -1, -1):
      self.fact_inv[i] = self.fact_inv[i + 1] * (i + 1) % self.mod
  def comb(self, n, k):
    if n < k:return 0
    else:return self.fact[n] * self.fact_inv[k] % self.mod * self.fact_inv[n - k] % self.mod
c=mod_comb_k()
n,k=map(int,input().split())
if k>=n:print(c.comb(2*n-1,n))
else:
  ans=0
  m=10**9+7
  for i in range(k+1):
    ans+=c.comb(n-1,i)*c.comb(n,i)%m
    ans%=m
  print(ans)

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

using namespace std;

int N, M;
multiset<int> CardsInfo;

int solve(int cnt) {
	int total;
	multiset<int>::iterator curPos;

	if (cnt >= M) {
		return 0;
	}
	cnt = M - cnt;
	total = 0;
	curPos = CardsInfo.begin();
	for (int i = 0; i < cnt; ++i) {
		total += N + *curPos;
		++curPos;
	}
	return total;
}

int main() {
	int cnt, a, b, total;

	cnt = 0;
	cin >> N >> M;
	for (int i = 0; i < M; ++i) {
		cin >> a >> b;
		if (a >= N) {
			++cnt;
			continue;
		}
		CardsInfo.insert(-a);
	}
	--M;
	cout << solve(cnt) << endl;
	
	return 0;
}


Measured memory_bytes: 3108
#-- coding: utf-8 --
#スペース区切りの整数の入力
a, b = map(int, input().split())
#配列の入力
array = list(map(int, input().split()))
#配列を降順に並び替え
array.sort()
#配列をbでスライス
del array[b:]
#配列を足して出力
print(sum(array))

Measured memory_bytes: 9184
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int x = sc.nextInt();
        int y = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        int[] p = new int[a];
        int[] q = new int[b];
        int[] r = new int[c];

        for(int i=0; i<a; i++) {
            p[i] = sc.nextInt();
        }
        for(int i=0; i<b; i++) {
            q[i] = sc.nextInt();
        }
        for(int i=0; i<c; i++) {
            r[i] = sc.nextInt();
        }

        Arrays.sort(p);
        Arrays.sort(q);
        Arrays.sort(r);

        int ai = a - x;
        int bi = b - y;
        int ci = c - 1;

        while(true) {
            if(ai == a && bi == b || ci == -1) break;
            if(bi == b) {
                if(p[ai] < r[ci]) {
                    p[ai++] = r[ci--];
                    continue;
                } else {
                    break;
                }
            }
            if(ai == a) {
                if(q[bi] < r[ci]) {
                    q[bi++] = r[ci--];
                    continue;
                } else {
                    break;
                }
            }
            int da = r[ci] - p[ai];
            int db = r[ci] - q[bi];
            if(da < 0 && db < 0) break;
            if(da > db) {
                p[ai++] = r[ci--];
            } else {
                q[bi++] = r[ci--];
            }
        }



        long res = 0;
        for(int i=0; i<x; i++) {
            res += p[a-1-i];
        }
        for(int i=0; i<y; i++) {
            res += q[b-1-i];
        }
        System.out.println(res);

    }



}

Measured memory_bytes: 96664
#include<bits/stdc++.h>
using namespace std;
int a,b;
char s[12];
int main()
{
	cin>>a>>b;
	cin>>s;
	for(int i=0;i<a;i++)
	{
		if(!('0'<=s[i] && s[i]<='9')) {cout<<"No\n";return 0;}
	}
	if(s[a]!='-') {cout<<"No\n";return 0;}
	for(int i=a+1;i<=a+b;i++)
	{
		if(!('0'<=s[i] && s[i]<='9')) {cout<<"No\n";return 0;}
	}
	cout<<"Yes\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N;
  cin >> N;
  
  long long num = sqrt(N);
  long long num2;
  long long num3;
  
  for(int i = num;i > 0;--i){
    if(N % i == 0){
      num2 = N / i;
      num3 = i;
      break;
    }
  }
  
  
  cout << num2 + num3 - 2 << endl;
}


Measured memory_bytes: 256
import Foundation

let input_line: String = readLine()!
//let split: [String] = input_line.components(separatedBy: "")
//let a = Int(split[0])!
//let b = Int(split[1])!
//let c = Int(split[2])!
let num = Int(input_line)!

var result = 0


for num in input_line {
    if num == "1" {
        result += 1
    }
}
 print(result)

Measured memory_bytes: 13044
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
using namespace std;

#define fi first
#define se second
typedef long long LL;
typedef long double LD;

LL N,a[100010],v[100010];
vector<int> g[100010];

bool dfs(int nod, int f){
    int i;  LL sum=0,d;

    if (g[nod].size()==1){
        v[nod]=a[nod];
        return 1;
    }

    for (i=0; i<(int)g[nod].size(); i++)
        if (g[nod][i]!=f){
            if (!dfs(g[nod][i],nod)) return 0;
            sum+=v[g[nod][i]];
        }

    d=2*a[nod]-sum;
    if (d<0) return 0;
    v[nod]=d;

    sum=0; int nxt;
    for (i=0; i<(int)g[nod].size(); i++){
        nxt=g[nod][i];
        if (nxt==f) continue;
        sum=min(2*(a[nod]-d),sum+min(a[nod]-d,v[nxt]));
    }

    if (sum<2*(a[nod]-d)) return 0;
    return 1;
}

int main(){
    cin >> N;

    int i;
    for (i=1; i<=N; i++) cin >> a[i];

    int x,y;
    for (i=1; i<N; i++){
        cin >> x >> y;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    if (N==2){
        if (a[1]==a[2]) cout << "YES\n";
        else cout << "NO\n";
        return 0;
    }

    for (i=1; i<=N; i++)
        if (g[i].size()>1){
            bool p=dfs(i,0);
            if (!p || v[i]!=0) cout << "NO\n";
            else cout << "YES\n";
            return 0;
        }

    return 0;
}





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

class Main{
  public static void main(String args[])throws IOException{
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
      String input_num = br.readLine();
      int num = Integer.parseInt(input_num);
      String input_s = br.readLine(); 
      if((num % 2) == 0){
        int half = num / 2;
        if(input_s.substring(0, half).equals(input_s.substring(half, num))){
          System.out.println("Yes");
        }else{
          System.out.println("No");
        }
      }else{
        System.out.println("No");
      }
    }
  }
}

Measured memory_bytes: 21076
#include<iostream>
#include<vector>
using namespace std;
int main(){
  int n,m;
  while(cin>>n>>m,n!=0&&m!=0){
    vector<int>ta(n);
    vector<int>ha(m);
    int sum=0;
    int sumt=0;
    for(int i=0;i<n;i++){
      cin>>ta[i];
      sum+=ta[i];
      sumt+=ta[i];
    }
    for(int i=0;i<m;i++){
      cin>>ha[i];
      sum+=ha[i];
    }
    if((sum%2)==1){
      cout<<-1<<endl;
      continue;
    }
    sum/=2;
    //cout<<sum<<" "<<sumt<<endl;
    int i,j;
    for(i=0;i<n;i++){
      bool hantei=false;
      for(j=0;j<m;j++){
	if(sum-sumt+ta[i]==ha[j]){hantei=true;break;}
      }
      if(hantei)break;
    }
    if(i==n)cout<<-1<<endl;
    else cout<<ta[i]<<" "<<ha[j]<<endl;
  }
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int ansa=1,ansb=1;
  pair<int,int> xl[n];
  rep(i,n){
    int a,b;
    cin>>a>>b;
    xl[i].fst=a+b;
    xl[i].scd=a-b;
  }
  sort(xl,xl+n);
  rep(i,n){
    //cout<<xl[i].fst<<" "<<xl[i].scd<<endl;
  }
  int now=xl[0].fst;
  rep(i,n){
    if(xl[i].scd>=now){
      now=xl[i].fst;
      ansa++;
      //cout<<xl[i].fst<<" "<<xl[i].scd<<endl;
    }
    
  }
  cout<<ansa<<endl;
  return 0;
}

Measured memory_bytes: 1792
A = [0 for i in range(2001)]
        
for i in range(1001) :
    for j in range(1001) :
        A[i + j] += 1

while True :
    try :
        n = int(input())
                
        cnt = 0
        
        if(n > 4000) :
            print(0)
            
        elif(n > 2000) :
            for i in range(n - 2000, 2001) :
                cnt += A[i] * A[n - i]
            print(cnt)
                
        else :
            for i in range(n + 1) :
                cnt += A[i] * A[n - i]
            print(cnt)
       
    except :
        break




Measured memory_bytes: 5620
import math
s = int(input())
if s < 3:
    print("0")
else:
    bar = (s // 3) - 1
    ans = 0
    for i in range(bar+1):
        if i == 0:
            ans += 1
        else:
            val = s - 3 * (i+1)
            count = math.factorial(val+i) // (math.factorial(val) * math.factorial(i))
            ans += count % (10**9+7)
    print(ans%(10**9+7))

Measured memory_bytes: 9156
#include <stdio.h>

int min(int x,int y){
	if(x>y){
		return y;
	}
	else{
		return x;
	}
}

int main(){
	int A,B,C,X,Y;
	scanf("%d%d%d%d%d",&A,&B,&C,&X,&Y);
	int output=A*X+B*Y;
	if(2*C<(A+B)){
		while(X>0&&Y>0){
			X--;
			Y--;
			output=output-A-B+2*C;	
		}
	}
	if(X==0&&2*C<B){
		while(Y>0){
			Y--;
			output=output-B+2*C;
		}
	}
	if(Y==0&&2*C<A){
		while(X>0){
			X--;
			output=output-A+2*C;
		}
	}

	printf("%d",output);
	return 0;
} 

Measured memory_bytes: 128
#pragma comment(linker, "/STACK:128777216")
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <climits>
#include <ctime>
#include <random>
using namespace std;

#define forx(_name,_from, to, value) for (int name = from; name < to; name += value)
#define rforx(_name, from, to, value) for (int name = from; name > to; name -= _value)
#define all(_STL_NAME) _STL_NAME.begin(), _STL_NAME.end()
#define rall(_STL_NAME) _STL_NAME.rbegin(), _STL_NAME.rend()
#define mp(_FIRST,_SECOND) make_pair(_FIRST,_SECOND)

typedef long long ll;
typedef unsigned long long llu;
typedef long double ld;
const ld eps = 1e-12;
mt19937 rndm;

void start() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cout.precision(20); cout.setf(ios::fixed);
	string FILENAME = "navalny";
	rndm.seed(time(0));
#ifdef _DEBUG
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#else
	//freopen((FILENAME + ".in").c_str(), "rt", stdin);
	//freopen((FILENAME + ".out").c_str(), "wt", stdout);
#endif
}

int main() {
	start();
	ll n, a, b;
	cin >> n >> a >> b;
	cout << min(n * a, b);
#ifdef _DEBUG
	cout << "\nTime: " << 1.0 * clock() / CLOCKS_PER_SEC << endl;
#endif
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    cin >> N;
    vector<ll> P(N);
    rep(i,N){
        cin >> P[i];
        P[i]--;
    }
    vector<ll> v(N);
    rep(i,N){
        v[P[i]] = i;
    }
    ll M = 0;
    ll now = -1;
    ll cnt = 0;
    rep(i,N){
        if(now < v[i]){
            cnt++;
            now = v[i];
            cmax(M,cnt);
        }else{
            cmax(M,cnt);
            cnt = 1;
            now = v[i];
        }
    }
    cout << N - M << endl;
}

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

int main(){
  	string s,t1,t2;
  	cin >> s;
  
  	rep(i,1,s.size()){
      t1="";t2="";
      if((s.size()-i) % 2 == 0){
        rep(j,0,(s.size()-i)/2){
          t1 += s[j];
          t2 += s[((s.size()-i)/2)+j];
        }
        
        if(t1 == t2){
          cout << s.size()-i << endl;
          return 0;
        }
      }
      
    }
    
  	return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    ll n, i, ans = 1;
    cin >> n;
    vll a(n);
    for(i = 0; i < n; i++)
        cin >> a[i];
    multiset <ll> ms;
    ms.insert(a[0]);
    for(i = 1; i < n; i++)
    {
        auto it = ms.lower_bound(a[i]);
        if(it == ms.begin())
            ans++;
        else
        {
            it--;
            ms.erase(it);
        }
        ms.insert(a[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5760
// g++ A.cpp -Wall -Wextra -Woverflow -Wshadow -O2
#include <iostream>
#include <algorithm>
#include <utility>
#include <map>
#include <vector>
#include <cstring>
#include <climits>
#include <queue>
#include <cmath>
#include <iomanip>
#include <set>
#include <bitset>

using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, pii> edge;

const int MAXB = 21;
int node[MAXB];

int main() {
  ios::sync_with_stdio(false);
  int L;
  cin >> L;
  L--;
  vector<edge> ans;
  int maxbit = 0;
  for (int i = 0; i < MAXB; i++) {
    if (1 << (i + 1) > L) {
      maxbit = i;
      break;
    }
  }
  int num = 2;
  if (L == (1 << (maxbit + 1)) - 1) {
    ans.push_back(edge(1 << maxbit, pii(1, 2)));
    ans.push_back(edge(0, pii(1, 2)));
    node[maxbit] = num - 1;
    num++;
  }
  for (int j = maxbit - 1; j >= 0; j--) {
    ans.push_back(edge(1 << j, pii(num - 1, num)));
    ans.push_back(edge(0, pii(num - 1, num)));
    node[j] = num - 1;
    num++;
  }
  num--;

  if (L != (1 << (maxbit + 1)) - 1) {
    int cur = 0;
    for (int i = maxbit; i >= 0; i--) {
      if (!(L & (1 << i))) continue;
      cur |= (1 << i);
      L ^= (1 << i);

      int tot = 0;
      bool done = 0;
      for (int j = 0; j <= maxbit; j++) {
        if (tot + (1 << j) > L) {
          j--;
          if (j < 0) ans.push_back(edge(cur, pii(1, num)));
          else ans.push_back(edge(cur, pii(1, node[j])));
          break;
        } else if (tot + (1 << j) == L) {
          done = 1;
          ans.push_back(edge(cur, pii(1, node[j])));
          break;
        }
        tot += (1 << j);
      }
      if (done) break;
    }
  }

  cout << num << ' ' << ans.size() << '\n';
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i].second.first << ' ' << ans[i].second.second << ' ' << ans[i].first << '\n';
  }
} 

Measured memory_bytes: 3660
n = int(input())
dp = [float('inf')]*n
amt = [1] + [6**i for i in range(1, 7)] + [9**i for i in range(1, 6)]
for a in amt:
    if a-1 < n:
        dp[a-1] = 1
for i in range(n):
    for j in amt:
        if i+j < n:
            dp[i+j] = min(dp[i+j], dp[i]+1)
print(dp[-1])


Measured memory_bytes: 47440
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <stack>
#include <string>
#include <list>
#include <set>
#include <queue>
#include <deque>
#include <math.h>
#include <string.h>
using namespace std;

typedef pair<int, int> P;
#define ll long long
#define int ll
#define INF (1LL<<60)
#define mod 1000000007


int N, K, X, Y;

signed main(){

	cin >> N >> K >> X >> Y;
	if (K<=N)
		cout << K*X + (N-K)*Y << endl;
	else
		cout << N*X << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main (void){
     
    int dice[7]={0};
    int d1,d2,d3,d4,d5,d6;
    int i;
    char d;
     
    for(i=1;i<=6;i++){
        scanf("%d",&dice[i]);
    }
    getchar();
    while(1){
         
        scanf("%c",&d);
        if(d == '\n')break;
        d1=dice[1];d2=dice[2];d3=dice[3];d4=dice[4];d5=dice[5];d6=dice[6];
        if(d=='N'){
            dice[1]=d2;dice[2]=d6;dice[6]=d5;dice[5]=d1;
        }else if(d=='E'){
            dice[1]=d4;dice[4]=d6;dice[6]=d3;dice[3]=d1;
        }else if(d=='S'){
            dice[1]=d5;dice[2]=d1;dice[6]=d2;dice[5]=d6;
        }else if(d=='W'){
            dice[1]=d3;dice[4]=d1;dice[6]=d4;dice[3]=d6;
        }
    }
     
    printf("%d\n",dice[1]);
     
return 0;
}


Measured memory_bytes: 2108
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
using namespace std;
int main()
{
	long long A;
	long long B;
	int K;
	while(scanf("%lld%lld%d",&A,&B,&K)!=EOF)
	{
		int pre=0;
		vector<int>vec(K);
		if(K<=B-A)
		{
			for(int i=A,k=1;k<=K;i++,k++)
			{
				printf("%lld\n",i);
			}
			for(int j=B-K+1,k=1;k<=K;j++,k++)
			{
				if(j>=(A+K)&&j<=B)
			    printf("%lld\n",j);	
			}
		}
		else
		{
			for(int i=A;i<=B;i++)
			printf("%lld\n",i);
		}
	}
	return 0;
} 

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int i;
  string s;
  cin>>s;
  for(i=0;i<4;i++){
    s[i]=s[i]-'0';
  }
  int a=s[0]*10+s[1],b=s[2]*10+s[3];
  
  if((a>0 and a<=12)&&(b>0 and b<=12)){
    cout<<"AMBIGUOUS";
  }
  else if(a>0 and a<=12)
    cout<<"MMYY";
  else if(b>0 and b<=12)
    cout<<"YYMM";
  else
    cout<<"NA";
  
  return 0;
}

Measured memory_bytes: 256