akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;

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

  vector<pair<int, int>> jobs(N);
  for_each(jobs.begin(), jobs.end(),
           [](auto &v){ cin >> v.first >> v.second; });
  sort(jobs.begin(), jobs.end());

  priority_queue<int> effective_jobs;
  int next_job = 0;
  long long ans = 0;
  for(int m = 1; m <= M; m++){
    while(next_job < N && jobs[next_job].first <= m){
      effective_jobs.push(jobs[next_job].second);
      next_job++;
    }
    if(!effective_jobs.empty()){
      ans += effective_jobs.top();
      effective_jobs.pop();
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1660
#include<iostream>
#include<stdio.h>
#include<vector>
#include<cmath>
#include<queue>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#define ll long long
#define pi pair < ll,ll >
#define mp(a,b) make_pair(a,b)
#define mid (low+high)/2
#define rep(i,a,b) for(int i = a;i < b;i++)
#define N 300004
#define INF 1e9+7

using namespace std;

long long n;

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

    cin >> n;

    long long cur = 100;
    ll ans = 0;

    while(cur < n)
    {
        ans++;
        cur = cur*1.01;
    }

    cout << ans;

    return 0;
}

// 1000000000000000


Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n;
bool prime[1000005];
map<llint, llint> mp;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	for(int i = 2; i < 1000005; i++){
		if(prime[i]) continue;
		for(int j = 2*i; j < 1000005; j+=i) prime[j] = true;
	}
	
	cin >> n;
	for(int i = 2; i < 1000005; i++){
		if(prime[i]) continue;
		while(n%i == 0){
			mp[i]++;
			n /= i;
		}
	}
	if(n > 1) mp[n]++;
	
	llint ans = 0;
	for(auto it = mp.begin(); it != mp.end(); it++){
		for(int i = 1; ; i++){
			if(it->second >= i){
				ans++;
				it->second -= i;
			}
			else break;
		}
	}
	cout << ans << endl;
	
	return 0;
}

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

public class Main{
    public static void swap(int[] A, int[] B, int gap_a2b){
    	boolean swapable= false;
		Arrays.sort(A);
		Arrays.sort(B);
    	if( A.length < B.length ){
    		for(int i=0;i<A.length;i++){
    			if( Arrays.binarySearch(B, A[i]+gap_a2b/2) >= 0 ){
    				System.out.println( A[i]+" "+(A[i]+gap_a2b/2) );
    				swapable= true;
    				break;
    			}
    		}
    		if( !swapable ){ System.out.println(-1); }
    	} else{
    		for(int i=0;i<B.length;i++){
    			if( Arrays.binarySearch(A, B[i]-gap_a2b/2) >= 0 ){
    				System.out.println( (B[i]-gap_a2b/2)+" "+B[i] );
    				swapable= true;
    				break;
    			}
    		}
    		if( !swapable ){ System.out.println(-1); }
    	}
    }
    
    public static void main(String args[]) throws Exception{
        Scanner sc= new Scanner(System.in);
        int Na,Nb;
        int sum_a,sum_b;
        while( (Na= sc.nextInt())>0 && (Nb= sc.nextInt())>0 ){
        	int[] A= new int[Na];
        	int[] B= new int[Nb];
        	sum_a= sum_b= 0;
        	
        	int i;
        	for(i=0;i<Na;i++){
        		A[i]= sc.nextInt();
        		sum_a += A[i];
        	}
        	for(i=0;i<Nb;i++){
        		B[i]= sc.nextInt();
        		sum_b += B[i];
        	}
        	
        	int gap_a2b= sum_b-sum_a;
        	if( gap_a2b %2 == 0 ){
        		swap(A,B,gap_a2b);
        	} else{ System.out.println(-1); }
        }
    }
}

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

int main() {
  int N;
  cin>>N;
    if(N/100==7)
      cout<<"Yes"<<endl;
    else if(N%100/10==7)
      cout<<"Yes"<<endl;
  	else if(N%10==7)
      cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
 



Measured memory_bytes: 3600
A = gets.to_i
B = gets.to_i
C = gets.to_i
D = gets.to_i
E = gets.to_i
F = gets.to_i
min1 = [A,B,C,D].min
min2 = [E,F].min
puts (A + B + C + D + E + F - min1 - min2)


Measured memory_bytes: 6860
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld DINF = 1e12;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  char t[200010], d[200010];
  rep(i, q) cin >> t[i] >> d[i];

  auto simulate = [&](ll x) {
    int now = x;
    rep(i, q)
    {
      if (t[i] == s[now])
      {
        now += (d[i] == 'L' ? -1 : 1);
      }
      if (now < 0)
        return -1;
      if (now >= n)
        return 1;
    }
    return 0;
  };

  auto binary_search1 = [&]() {
    ll lo = -1, hi = n;
    while (hi - lo > 1)
    {
      ll mi = (lo + hi) / 2;
      if (simulate(mi) == -1)
        lo = mi;
      else
        hi = mi;
    }
    return lo;
  };

  auto binary_search2 = [&]() {
    ll lo = -1, hi = n;
    while (hi - lo > 1)
    {
      ll mi = (lo + hi) / 2;
      if (simulate(mi) <= 0)
        lo = mi;
      else
        hi = mi;
    }
    return lo;
  };
  cout << binary_search2() - binary_search1() << endl;

  return 0;
}

Measured memory_bytes: 976
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  int n;
  vector<long long> a;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long k;
    cin >> k;
    a.push_back(k);
  }
  sort(a.begin(), a.end());
  vector<long long> p(2, 0);
  int t = 0;
  long long prev = -1;
  for (int i = n-1; i >= 0; i--) {
    if (t == 2) break;
    if (prev != a[i]) {
      prev = a[i];
    } else {
      p[t] = prev;
      prev = -1;
      t++;
    }
  }
  cout << p[0] * p[1] << endl;
  return 0;
}

Measured memory_bytes: 1400
import math

n = int(raw_input())
x = map(float, raw_input().split())
y = map(float, raw_input().split())

for p in range(4):
    p = float(p)
    D = 0
    for j in range(n):
        if p == 3.0:
            D = max(D, abs(x[j] - y[j]))
        else:
            D += math.pow(abs(x[j] - y[j]), p+1)
    if p == 3.0:
        print D
    else:
        print math.pow(D, 1/(p+1))
    

Measured memory_bytes: 6620
n, a, b = map(int, input().split())

mod = 10 ** 9 + 7
#a本、b本の制限を無視すると、2^n - 1の選び方が存在する。
ans = pow(2, n, mod) - 1 

def choose(n, a):
    x, y = 1, 1
    for i in range(a):
        y = y * (i + 1) % mod
        x = x * (n - i) % mod
    return x * pow(y, mod - 2, mod) % mod 
#上記で求めた値から、a本を選んだ時とb本を選んだ時の組み合わせ数を引く
ans -= choose(n, a)
ans -= choose(n, b)

print(ans % mod)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	void run() {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int sum = 0;
		for (int i = 0;; i++) {
			sum += i;
			if (n <= sum) {
				System.out.println(i);
				return;
			}
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n;
    cin>>n;
    ll x=100;
    ll c=0;
    while(x<n)
    {
        x+=x/100;
        c++;
    }
    cout<<c<<endl;
    
return 0;
}

Measured memory_bytes: 3668
n,m,p = map(int, input().split())
G = [[] for i in range(n)]
for i in range(m):
    a,b,c = map(int, input().split())
    a,b = a-1, b-1
    G[a].append((b, p-c))


INF = 10**18
dist = [INF] * n
dist[0] = 0
for i in range(2*n):
    for v, e in enumerate(G):
        if dist[v] == INF:
            continue
        for t, cost in e:
            if dist[v] + cost < dist[t]:
                dist[t] = dist[v] + cost
                # 頂点Nに向かう辺に負閉路があったとき
                if i >= n-1 and t == n-1:
                    print(-1)
                    exit()
print(max(0, -dist[-1]))

Measured memory_bytes: 51672
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<bitset>
using namespace std;
#define ll long long
const ll INF = 1LL << 60;

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

class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

//input
ll N,M,L;
string S;
int main() {
	int A, B;
	cin >> A >> B;
	int ans = 0;
	for (int i = 0; i < 2; i++) {
		if (A > B) {
			ans += A;
			A--;
		}
		else {
			ans += B;
			B--;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
local n = io.read("*n", "*l")
local t = {}
for i = 1, n do
  local s = io.read()
  if not t[s] then t[s] = 1 else t[s] = t[s] + 1 end
end
local max = 0
for k, v in pairs(t) do
  if max < v then
    max = v
  end
end
local r = {}
for k, v in pairs(t) do
  if v == max then
    table.insert(r, k)
  end
end
table.sort(r)
for i = 1, #r do
  print(r[i])
end


Measured memory_bytes: 18456
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];
ll x[10];
ll y[10];

int main()
{
    ll i,j,cc=0,k,l,n;
    cin>>n>>k;
    string str;cin>>str;
    vector<ll>ara(n+1);
    ara[1]=0;
    ara[0]=0;
    for(i=1;i<n;i++){
        if(str[i-1]=='A' && str[i]=='C'){
            ara[i]+=ara[i-1]+1;
        }
        else {
            ara[i]=ara[i-1];
        }
    }
    while(k--){
        ll x,y;cin>>x>>y;
        x--,y--;
        if(x==0){
            cout<<ara[y]<<endl;
        }
        else{
            cout<<ara[y]-ara[x]<<endl;
        }
    }
return 0;
}


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

int main() {
  int N;
  cin >> N;
  int A[2][N];
  for(int i=0; i<2; i++){
    for(int j=0; j<N; j++){
      cin >> A[i][j];
    }
  }

  int max = 0;
  for(int i=0; i<N; i++){
    int sum = 0;
    for(int j=0; j<N; j++){
      if(i >= j){
        sum += A[0][j];
      }
      if(i <= j){
        sum += A[1][j];
      }
    }
    max = std::max(max, sum);
  }

  cout << max << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        int innerRating = 0;
        int joinNum = 0;
        int displayRating = 0;

        Scanner scanner = new Scanner(System.in);
        String inputData = scanner.nextLine();
        scanner.close();

        String[] editData = inputData.split(" ");

        joinNum = Integer.parseInt(editData[0]);
        displayRating = Integer.parseInt(editData[1]);

        if (joinNum <= 9) {
            innerRating = displayRating + (10 - joinNum) * 100;
        } else {
            innerRating = displayRating;
        }

        System.out.println(innerRating);

    }
}

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

namespace abc163b
{
    class Program
    {
        static void Main(string[] args)
        {
            //==========================================================================================================================
            //1) input
            List<int> input = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
            List<int> a = Console.ReadLine().Split(' ').Select(int.Parse).ToList();


            //==========================================================================================================================
            //2) output
            int output = input[0]-a.Sum();

            if (output < 0)
            {
                output = -1;
            }


            Console.WriteLine(output);
        }
    }
}


Measured memory_bytes: 29120
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }



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

    vector<int> v(n);
    
    rep(i, n) cin >> v[i];
    
    /*
    sort(all(v));
    outa(v, n);
     */
    
    map<int, int> mp;
    rep(i, n) mp[v[i]]++;
    
    
    int cnt = 0;
    for (auto e : mp) cnt += e.S - 1;
    // for (auto e : mp) cout << e.F << " " << e.S << endl;
    // out(cnt);
    
    out(sz(v) - (cnt % 2 == 0 ? cnt : cnt + 1));
}




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

int main(){
  int N, M;
  int A[110];
  cin >> N >> M;
  for (int i = 0; i < N; ++i) cin >> A[i];
  sort(A, A + N, greater<int>());
  int sum = accumulate(A, A + N, 0);
  if(A[M-1] < sum/(4*M))cout << "No" <<endl;
  else if(A[M-1] == sum/(4*M) && sum%(4*M) !=0)cout << "No" << endl;
  else cout << "Yes" << endl;
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;


ll n,m;
int main(){
  cin >> n >> m;
  vector<pair<ll,ll>> vec(m);
  if(n % 2 == 1){
    rep(i,m){
      vec[i] = make_pair(i+1,n-i-1);
    }
  }else{
    t1 = (n / 2 - 1) / 2;
    rep(i,t1){
      if(i < m){
        vec[i].first = i+1;
        vec[i].second = 2 * t1 + 1 - i;
      }
    }
    REP(i,t1,m){
      vec[i].first = 2 * t1 + 2 + (i - t1);
      vec[i].second = n - (i - t1) - 1;
    }
  }
  //cout << endl;
  rep(i,m){
    cout << vec[i].first << " " << vec[i].second << endl;
  }
}

Measured memory_bytes: 4580
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };



const int MAX_PRIME = 114514;;
bool is_prime[MAX_PRIME + 1];
void sieve(int n = MAX_PRIME)
{
	fill_n(is_prime, n + 1, true);
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i * i <= n; ++i)
	{
		if (is_prime[i])
		{
			for (int j = 2 * i; j <= n; j += i)
				is_prime[j] = false;
		}
	}
}
vector<int> make_primes(int n = MAX_PRIME)
{
	vector<int> res;
	for (int i = 2; i <= n; ++i)
		if (is_prime[i])
			res.push_back(i);
	return res;
}
int main()
{
	sieve();
	vector<int> primes = make_primes();
	
	int n, p;
	while (scanf("%d%d", &n, &p), ~n)
	{
		vector<int> w;
		int t = upper_bound(all(primes), n) - primes.begin();
		for (int i = t; i < t + p; ++i)
			for (int j = i; j < t + p; ++j)
				w.push_back(primes[i] + primes[j]);
		sort(all(w));
		printf("%d\n", w[p - 1]);
	}
}

Measured memory_bytes: 0
#include<set>
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
    int n; 
    cin >> n;
    set<int> s1,s2;
    for (int i = 0; i < n; i++) {int t; cin >> t; s1.insert(t);}
    cin >> n;
    for (int i = 0; i < n; i++) {int t; cin >> t; s2.insert(t);}
    set<int> s3;
    set_intersection(s1.begin(),s1.end(),s2.begin(), s2.end(), inserter(s3, s3.begin()));
    for (auto it = s3.begin(); it !=s3.end(); it++) {
        cout << *it << endl;
    }
    return 0;
}


Measured memory_bytes: 23632
#include <iostream>
#include <algorithm>
#include <vector>
typedef long long ll;
using namespace std;
 
int main(){
  int n,m;
  cin>>n>>m;
  int ans=0;
  vector<vector<int>> swi(m);
  vector<int> p(m);
  for(int i=0;i<m;i++){
    int k;
    cin>>k;
    for(int j=0;j<k;j++){
      int s;
      cin>>s;
      swi[i].push_back(s);
    }
  }
  for(int i=0;i<m;i++) cin>>p[i];

  for(int bit=0;bit<(1<<n);bit++){//n桁以下の2進数
    vector<int> s_c(m);
    for(int j=0;j<n;j++){
      if(bit>>j&1){
        for(int i=0;i<m;i++){
          for(int k=0;k<swi[i].size();k++){
            if(swi[i][k]==j+1) s_c[i]++;
          }
        }
      }
    }
    for(int i=0;i<m;i++){
      s_c[i]%=2;
      if(s_c[i]!=p[i]) break;
      if(i==m-1){
        ans++;
      }
    }
  }
  cout<<ans<<endl;
}


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

int main () {
  int N;
  cin >> N;
  vector<int> cost(N);
  for (int i = 0; i < N; i++) cin >> cost.at(i);
  sort (cost.begin(),cost.end());
  int ans = 0;
  for (int i = 0; i < N;i++){
    if (i == N-1) ans += cost.at(i)/2;
    else ans += cost.at(i);
  }
  cout << ans << endl;
}

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

int main(){
    while(1){
        int price=0;
        cin >> price;
        if(price==0) break;
        int first=1;
        int last=1;
        int sum=1;
        
        while(1){
            if(sum<price){
                last++;
                sum+=last;
            }else if(sum>price){
                sum-=first;
                first++;
            }else{
                break;
            }
        }
        
        cout << first << " " << (last-first+1) << endl;
    }
}














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

#define ll long long int
#define vi vector<int>

int main() {

    ll H, N;
    cin >> H >> N;

    ll sum = 0;
    ll a;
    for (int i = 0; i < N; i++) {
        cin >> a;
        sum += a;
    }

    if (sum >= H) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
//Ruthless Coding 
#include <bits/stdc++.h>

#define uni(x)      (x).resize(unique(all(x)) - (x).begin())
#define fprint(v)   for(auto x : v) cout << x << ' '
#define ALL(x)      (x).begin(), (x).end()
#define MP(x, y)    make_pair(x, y)
#define PII         pair<int, int>
#define SZ(x)       int((x).size())
#define PB(x)       push_back(x)
#define ll          long long
#define S           second 
#define F           first
#define nl          '\n'

using namespace std;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
mt19937_64 rnd;

const int N = 2e5 + 5;
void print(int x){
    if(x == 1) cout << "GREATER";
    else if(x == 0) cout << "EQUAL";
    else  cout << "LESS";
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    string a, b;
    cin >> a >> b;
    int na = SZ(a), nb = SZ(b);
    if(na != nb){
        if(na < nb) print(-1);
        else print(1);
    }else{        
        for(int i = 0; i < na; i++){
            if(a[i] > b[i]){
                print(1);
                return 0;
            }else if(a[i] < b[i]){
                print(-1);
                return 0;
            }
        }   
        print(0);
    }
    return 0;
}


Measured memory_bytes: 256
n=int(input())
d=[]
a=[2,3,5,7,11,13,17,23,29,31]

i=0
while(i<n):
	stri=input()
	stri=list(map(ord,stri))
	stri=list(map(lambda h: h-97,stri))
	stri.sort()
	# print(stri)
	j=0
	number=1
	leng=len(stri)
	while(j<leng):
		number*=a[j]**(stri[j])
		j+=1
	d.append(number)
	i+=1
d.sort()
# print(d)
j=0
super=0
while(j<n):
	pfinder=d[j]
	summer=0
	notFound=True
	# print("Here",j)
	while( notFound and j<n):
		if(d[j]==pfinder):
			summer+=1
			j+=1	
		else:
			notFound=False
	# print(summer)
	super+=int(summer*(summer-1)/2)

print(super)

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

typedef long long ll;
 
int main(){
  int n;
  cin >> n;
  vector<vector<int>> f(n, vector<int>(10));
  for(int i=0; i<n; i++){
    for(int j=0; j<10; j++){
      cin >> f[i][j];
    }
  }
  vector<vector<int>> p(n, vector<int>(11));
  for(int i=0; i<n; i++){
    for(int j=0; j<11; j++){
      cin >> p[i][j];
    }
  }
  int l = 1 << 10;
  int ans = -1000000009;
  for(int i=1; i<l; i++){
    int m[n]={};
    int tmp=0;
    for(int bit=0; bit<10; bit++){
      if(i&(1<<bit)){
        for(int j=0; j<n; j++){
          m[j] += f[j][bit];
        }
      }
    }
    for(int j=0; j<n; j++){
      tmp += p[j][m[j]];
    }
    
    ans = max(ans, tmp);
    
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vs vector<string>
#define pb push_back
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,s1;
    int c=0;
    cin>>s>>s1;
    for(int i=0;i<s1.length();i++)
        if(s1[i]!=s[i])
            c++;
    cout<<c;
    return 0;
}


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

int main() {
  int max, min;
  int A, X, Y;
  cin >> A;
  cin >> X;
  cin >> Y;
  if (X > Y) {
    max = Y;
  } else {
    max = X;
  }

  min = X + Y - A;
  if (min <= 0) {
    min = 0;
  }

  cout << max << " " << min << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		double A[] = new double[N];
		double sum = 0;
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextDouble();
			sum += 1 / A[i];
		}
		sum = 1 / sum;
		System.out.println(sum);
	}
}


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

using namespace std;

int main()
{
    int A, B, C, D, E, F;
    cin>>A>>B>>C>>D>>E>>F;

    int anst = A*100;
    int anss = 0;
    for (int a=0; a*A*100<=F; a++)
    for (int b=0; a*A*100+b*B*100<=F; b++)
    for (int c=0; c*C+a*A*100+b*B*100<=F && c*C<=(a*A+b*B)*E; c++)
    {
        int d = min(((a*A+b*B)*E-c*C)/D, (F-a*A*100-b*B*100-c*C)/D);
        int t = a*A*100+b*B*100+c*C+d*D;
        int s = c*C+d*D;
        if (s*anst > anss*t)
        {
            //cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<t<<" "<<s<<endl;
            anst = t,
            anss = s;
        }
    }
    cout<<anst<<" "<<anss<<endl;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

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

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;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 SREP(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)

//printf
#define PRINTD(d) printf("%d\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9

typedef long long ll;
int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int a, int b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int main() {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if (b < c)Swap(&b, &c);
	if (a < b)Swap(&a, &b);
	int cnt = 0;
	if ((a - b) % 2 && (a - c) % 2) {
		b++;
		c++;
		cnt++;
	}
	else if ((a - b) % 2) {
		a++;
		c++;
		cnt++;
	}
	else if ((a - c) % 2) {
		a++;
		b++;
		cnt++;
	}
	cnt += (a - b) / 2 + (a - c) / 2;
	PRINTD(cnt);
}

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

#define ll long long

int main() {
	int n;
	cin >> n;
	int i, j, k;
	ll ans = 0;
	int buf1,buf2;
	vector < ll > leng(n);
	for (i = 0; i < n; i++) {
		cin >> leng[i];
	}
	sort(leng.begin(), leng.end());
	for (i = 0; i < n - 2; i++) {
		buf1 = leng[i];
		for (j = i + 1; j < n - 1; j++) {
			if (buf1 == leng[j])continue;
			else buf2 = leng[j];
			for (k = j + 1; k < n; k++) {
				if (buf2 == leng[k])continue;
				if (leng[i] + leng[j] > leng[k] && leng[j] + leng[k] > leng[i] && leng[k] + leng[i] > leng[j])ans ++ ;

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

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  char a;
  cin >> a;
  if(a>='a'&&a<='z'){
    print('a');
  }
  else{
    print('A');
  }
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);

	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	ll k;
	string s;
	cin >> k >> s;
	if (s.length() <= k)
	{
		cout << s;
	}
	else
	{
		string t = "";
		for (ll i = 0; i < k; i++)
		{
			t = t + s[i];
		}
		t = t + "...";
		cout << t;
	}
}



Measured memory_bytes: 3652
#include<iostream>
#include<vector>
using namespace std;
typedef vector<int> vc;

vc cut(vc& v,int& n){
  vc next(2*n);
  for(int i = 0 ; i < n ; i++){
    next[2*i] = v[i];
    next[2*i+1] = v[n+i];
  }
  return next;
}

vc shuffle(vc& v,int& k,int& n){
  vc next(2*n);
  for(int i = 0 ; i < k ; i++) next[2*n-k+i] = v[i];
  for(int i = k ; i < 2 * n ; i++ ) next[i-k] = v[i];
  return next;
}

int main(){
  int n, m, k;
  vc card;
  cin >> n;
  card.resize(2 * n);
  for(int i = 0 ; i < 2 * n ; i++ ) card[i] = i + 1;
  cin >> m;
  while(m--){
    cin >> k;
    card = vc(k ? shuffle(card,k,n) : cut(card,n));
  }
  for(int i = 0 ; i < 2 * n ; i++ ) cout << card[i] << endl;
}

Measured memory_bytes: 1216
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <queue>
using namespace std;

typedef pair<int, string> P;

map<string, string> change;
string input, output;

string Replace(string s, string from, string to){
  string::size_type pos = 0;
  while(pos = s.find(from, pos), pos != string::npos){
    s.replace(pos, from.size(), to);
    pos += to.size();
  }
  return s;
}

int bfs(){
  set<string> ever;
  ever.insert(input);
  P start(P(0, input));
  queue<P> que;
  que.push(start);
  while(!que.empty()){
    P tmp = que.front();
    que.pop();

    int cnt = tmp.first;
    string in = tmp.second;
    if(in == output) return cnt;
    
    for(map<string, string>::iterator it = change.begin() ; it != change.end() ; it++){
      string after = Replace(in, it->first, it->second);
      if(after.size() > output.size()) continue;
      if(ever.find(after) != ever.end()) continue;
      ever.insert(after);
      que.push(P(cnt+1, after));
    }
  }
  return -1;
}

void init(){
  change.clear();
}
      
int main(){
  int n;
  while(cin >> n, n){
    init();
    string a, b;
    for(int cs = 0 ; cs < n ; cs++){
      cin >> a >> b;
      change[a] = b;
    }
    cin >> input >> output;
    cout << bfs() << endl;
  }
  return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#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 SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#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;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


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

  int N;
  while(cin>>N,N){
	VI xs(N);
	REP(i,N){
	  char c;
	  cin >> c;
	  xs[i] = c - 'A';
	}

	VI cnt(26,0);
	REP(i,N) cnt[xs[i]]++;
	int mx = *max_element(ALL(cnt));
	int ix = -1;
	REP(i,26){
	  if(cnt[i] == mx){
		if(ix == -1) ix = i;
		else{
		  ix = -1;
		  break;
		}
	  }
	}
	if(ix < 0){
	  cout << "TIE" << endl;
	  continue;
	}
	int ans = N;
	cnt = VI(26,0);
	REP(i,N){
	  cnt[xs[i]]++;
	  bool ok = true;
	  int d = N - i - 1;
	  REP(j,26){
		if(j != ix && cnt[j]+d >= cnt[ix])
		  ok = false;
	  }
	  if(ok){
		ans = i+1;
		break;
	  }
	}

	cout << (char)('A'+ix) << " " << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 3172
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int n,k,q,t;
    cin >> n >> k >> q;
    vector<int> a;
    a.resize(n);
    for(int i=0;i<n;i++)a[i]=0;
    for(int i=0;i<q;i++){
        cin >> t;
        a[t-1]++;
    }
    for(int i=0;i<n;i++){
        if(a[i]>q-k)cout <<"Yes"<<endl;
        else cout << "No" <<endl;
    }
}

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

int bubbleSort(int A[],int N){
	int sw=0;
	bool flag=1;
	for(int i=0;flag;i++){
		flag=0;
		for(int j=N-1;j>=i+1;j--){
			if(A[j]<A[j-1]){
				swap(A[j],A[j-1]);
				flag=1;
				sw++;
			}
		}
	}
	return sw;
}
int main(){
	int A[100],N,sw;
	cin>>N;
	
	for(int i=0;i<N;i++)cin>>A[i];
	
	sw=bubbleSort(A,N);
	
	for(int i=0;i<N;i++){
		if(i)cout<<" ";
		cout<<A[i];
	}
	cout<<endl;
	cout<< sw <<endl;
	
	return 0;
}

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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define MOD_1_000_000_007 (1000000007LL)
#define LINF (1LL<<60)
#define rep(i, n)   for (long long i = 0; i <  (long long)(n); i++)
#define rep1(i, n)  for (long long i = 1; i <  (long long)(n); i++)
#define rep2(i, n)  for (long long i = 2; i <  (long long)(n); i++)
#define rep0c(i, n) for (long long i = 0; i <= (long long)(n); i++)
#define rep1c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep2c(i, n) for (long long i = 2; i <= (long long)(n); i++)
#define repc0(n, i) for (long long i = (long long)(n); i >= 0; i--)
#define repc1(n, i) for (long long i = (long long)(n); i >= 1; i--)
#define repc2(n, i) for (long long i = (long long)(n); i >= 2; i--)
#define REP(i, n, m) for (long long i = (long long)(n); i < (long long)(m); i++)

namespace solver {
  using namespace std;
  typedef long long ll;

  ll X;

  void init() {
    scanf("%lld", &X);
  }

  void solve() {
    rep(i, 500000) rep(j, 2) {
      ll b = i;
      if(j) b = -b;
      ll b5 = (ll)pow(b, 5);
      ll a = (ll)pow(X+b5, 0.2);
      ll y = (ll)pow(a, 5) - (ll)pow(b, 5);
      if(X == y) {
        cout << a << " " << b << endl;
        return;
      }
    }
  }
}

int main() {
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 4156
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}

using namespace std;
ll k (ll a){
    a--;
    ll ans =0;
    while(a != 0){
        ans += a;
        a--;
        
    }
    return ans;
}


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

    vector<ll> vec(n);
    REP(i,n){
        cin >> vec[i];
    }
    SORT(vec);
    
    REP(i,k){
        if(i >= n){
            break;
        }
        vec[n-1-i] = 0;
    }
    ll ans = 0;
    REP(i,n){
        ans += vec[i];
    }
    cout << ans <<endl;
}



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

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    int n,k;
    cin >> n >> k;
    int ans= 0;
    while (n) {
        ans += 1;
        n /= k;
    }
    
    cout << ans << "\n";
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

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

int main() {

    string S, T;
    cin >> S >> T;
    int ans = 0;
    rep(i,S.length()) {
        if (S[i] != T[i]) ans++;
    }

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

Measured memory_bytes: 3840
import java.util.*;
public class Main{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        Set<Integer> set = new HashSet<>();
        int n =sc.nextInt();
        int arr[] = new int[n];
        for(int i=0;i<n;i++){
            arr[i] = sc.nextInt();
            set.add(arr[i]);
        }
        int ans =0;
        for(int i=1;i<n;i++){
            if(arr[i] == arr[i-1]){
                ans++;
                for(int ii=1;ii<=10000;ii++) {
                    if(!set.contains(ii)) { arr[i] = ii; break; }
                }
            }
        }
        System.out.println(ans);
    }
}


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

int main(void) {
    int N, K;
    cin >> N >> K;
    int H[N];
    for(int i = 0; i < N; i++ ) {
        cin >> H[i];
    }

    if(K > N) {
        cout << 0 << endl;
        return 0;
    }

    sort(H, H + N);

    unsigned long  sum = 0;
    for(int i = 0; i < N - K; i++)  {
        sum += H[i];
    }
    
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[200010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){//線分の交差判定
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int g(int x){
	x=modpow(x,MOD-2);
	return x;
}
int w,h,ans;
vector<P>v;
signed main(){
	cin>>w>>h;
	rep(i,w){
		int a;
		cin>>a;
		v.pb({a,0});
	}
	rep(i,h){
		int b;
		cin>>b;
		v.pb({b,1});
	}
	int x=w+1,y=h+1;
	sort(all(v));
	for(P p:v){
		if(p.se==0){
			if(!x)break;
			ans+=y*p.fi,x--;
		}
		else{
			if(!y)break;
			ans+=x*p.fi,y--;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6512
#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>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    string N;
    Int K;

    Int dp[101][2][11][4][101];

    Int rec(Int n = 0, Int t = 1, Int x = 0, Int k = 0, Int d = 0) {
        if (dp[n][t][x][k][d] != -1) {
            return dp[n][t][x][k][d];
        }
        if (n == N.size()) {
            return dp[n][t][x][k][d] = k == K;
        }

        int max_x = t ? (N[n] - '0') : 9;
        Int ret = 0;
        for (int nx = 0; nx <= max_x; ++nx) {
            Int tmp = 0;
            if (nx == 0) {
                tmp = rec(n + 1, nx == max_x && t, nx, k + (nx != 0), d);
            } else {
                if (k + (nx != 0) <= K) {
                    if (d == 0) {
                        tmp = rec(n + 1, nx == max_x && t, nx, k + (nx != 0), n);
                    } else {
                        tmp = rec(n + 1, nx == max_x && t, nx, k + (nx != 0), 0);
                    }
                }
            }
            ret += tmp;
        }

        return dp[n][t][x][k][d] = ret;
    }

    void solve() {
        memset(dp, -1, sizeof(dp));
        cin >> N >> K;

        Int ans = rec();
        cout << ans << endl;

    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n,d;
  cin >> n >> d;
  d = 2*d+1;
  ll ans = n/d;
  if(n%d>0) ans++;
  cout << ans<< endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    char s[4], t[4];
    int i, n;

    scanf("%s%s",s,t);
    i=0;    n=0;
    while(s[i] != '\0'){
        if(s[i] == t[i]){
            n++;
        }
        i++;
    }
    printf("%d\n", n);
    return 0;
}

Measured memory_bytes: 1732
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

int cnt[3];
int as[3];

int main()
{
  while( true )
  {
    int a, b, c;
    scanf( "%d%d%d", &a, &b, &c );

    as[0] = a, as[1] = b, as[2] = c;

    std::sort( as, as+3 );

    if( abs(a-b) < c && c < a+b )
    {
      int py = as[2]*as[2]-as[0]*as[0]-as[1]*as[1];

      if( py == 0 )
        ++cnt[0];
      else if( py < 0 )
        ++cnt[1];
      else
        ++cnt[2];
    }
    else
    {
      printf( "%d %d %d %d\n", cnt[0]+cnt[1]+cnt[2], cnt[0], cnt[1], cnt[2] );

      return 0;
    }
  }
  
  return 0;
}


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

int main() {
    int a, b;
    cin >> a >> b;
    if (a < b) {
        cout << "a < b" << endl;
        return 0;
    }
    if (a > b) {
        cout << "a > b" << endl;
        return 0;
    }
    if (a == b) {
        cout << "a == b" << endl;
        return 0;
    }
}


Measured memory_bytes: 3096
n, m, c = map(int, input().split())
B = [int(num) for num in input().split()]
counter = 0
for _n in range(n):
  A = [int(num) for num in input().split()]
  ip = 0
  for _m in range(m):
    ip += A[_m] * B[_m]
  if ip + c > 0:
    counter += 1
print(counter)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,k;
  cin>>N;
  map<string, int> score;
  string s=" ";
  for(int i=0;i<N;i++){
    cin>>s;
    score[s]=1;
  }

  k=score.size();
  cout<<k<<endl;
  
}








Measured memory_bytes: 19192
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define DEBUG
#ifdef DEBUG
#define debug_printf printf
#else
#define debug_printf 1 ? 0 : printf
#endif

using namespace std;
typedef long long int ll;
typedef vector<ll> Vl;
typedef vector<int> Vi;
typedef pair<int, int> Pi;

#define FST first
#define SND second

#define MAX_N   (100)                  // 10^5
#define MAX_S   (100)                  // 10^5
// #define MAX_N   (1000000000)              // 10^9
// #define MAX_N   (1000000000000000000)     // 10^18
#define BASE    (1000000000 + 7)          // 10^9 + 7
#define INFI    (1000000000 + 7)          // 10^9 + 7
#define INFL    (1000000000000000000 + 7) // 10^18 + 7

int N;
ll S[MAX_N];

void solve() {
  ll sum = 0;
  for (int i = 0; i < N; i++) sum += S[i];

  ll ans = 0;
  if (sum % 10 != 0) {
    ans = sum;
  } else {
    ll mn = INFL;
    for (int i = 0; i < N; i++) {
      if (S[i] % 10 != 0) {
        mn = min(mn, S[i]);
      }
    }
    ans = max(0LL, sum - mn);
  }

  cout << ans << endl;
}

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }

  solve();

  return 0;
}


Measured memory_bytes: 256