akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;++i)
#define MOD (int) 1e9+7

int main(){
    int N, T;
    cin >> N >> T;
    int t[N];
    ll ans = 0;
    rep(i, N){
        cin >> t[i];
    }
    for (int i=N-1;i>=1;i--){
        t[i] -=t[i-1];
    }
    rep(i, N){
        ans += min(t[i], T);
    }
    ans += T;

    cout << ans << endl;
    // printf("%d\n", N);
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
main(){
  int i,a,b;
  char op;
  for(i=0;;i++){
    scanf("%d %c %d",&a,&op,&b);
    if(op=='?')break;
    else if(op=='+'){
      printf("%d\n",a+b);
    }
    else if(op=='-'){
      printf("%d\n",a-b);
    }
    else if(op=='*'){
      printf("%d\n",a*b);
    }
    else if(op=='/'){
      printf("%d\n",a/b);
    }
  }
  return 0;
}

Measured memory_bytes: 600
import java.util.Arrays
import java.util.Collections
import java.util.ArrayList
import java.util.ArrayDeque
import java.util.PriorityQueue

const val MOD: Long = (1e9+7).toLong()
fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun <T : Comparable<T>> Iterable<T>.argmax(): Int? = withIndex().maxBy{it.value}?.index
fun <T : Comparable<T>> Iterable<T>.argmin(): Int? = withIndex().minBy{it.value}?.index

fun main(args: Array<String>) {
    val reader = System.`in`.bufferedReader()
    val (n, m) = reader.readLine()!!.split(" ").map{it.toInt()}
    val a = reader.readLine()!!.split(" ").map{it.toLong()}
    val d = Array(m, {
        val (b, c) = reader.readLine()!!.split(" ")
        Pair(b.toInt(), c.toLong())
    })
    d.sortBy {-it.second}

    val l = ArrayList<Long>(a)

    for (e in d) {
        val (b, c) = e
        for (i in 0..Math.min(2*n-l.size, b-1)) {
            l.add(c)
        }
        if (l.size >= 2*n) {
            break
        }
    }

    l.sortBy {-it}
    println(l.take(n).sum())
}


Measured memory_bytes: 127136
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vb = vector<bool>;
using vs = vector<string>;
using vvi = vector<vi>;
using vp = vector<pii>;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define each(a, x) for (auto&& a : x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, n) for (int i = (a); i < (n); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _per(i, n) peri(i, 0, n)
#define peri(i, a, n) for (int i = (n) - 1; i >= (a); --i)
#define per(...) _overload3(__VA_ARGS__, peri, _per)(__VA_ARGS__)
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
template<typename T> inline void chmax(T& a, const T& b) {if (a < b) a = b;}
template<typename T> inline void chmin(T& a, const T& b) {if (a > b) a = b;}
template<typename T> inline void print(const T& x) {cout << x << "\n";}
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p) {is >> p.fi >> p.se; return is;}
template<typename T, typename U> ostream& operator<<(ostream& os, const pair<T, U>& p) {os << p.fi << " " << p.se; return os;}
template<typename T> istream& operator>>(istream& is, vector<T>& v) {each(in, v) is >> in; return is;}
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {rep(i, sz(v)) {os << v[i] << (i + 1 != sz(v) ? " " : "");} return os;}
struct Init {Init() {ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10);}} init;

int main() {
    int k;
    string s;
    cin >> k >> s;
    if (sz(s) <= k) print(s);
    else print(s.substr(0, k) + "...");
}

Measured memory_bytes: 3636
hp = [0, 0]
atk = [0, 0]
hp[0], atk[0], hp[1], atk[1] = [int(x) for x in input().split()]

while True:
    for i in range(2):
        if hp[0] <= 0 or hp[1] <= 0: break
        hp[1 - i] -= atk[i]
    else:
        continue
    break
if hp[0] > 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define FOR(it, c) \
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const ll MOD = 998244353;

struct FenwickTree {
  int n;
  vector<int> tree;

 public:
  FenwickTree(int n_) : n(n_), tree(n_ + 1, 0) {}
  void add(int i, int value) {
    for (; i < n; i |= i + 1) tree[i] += value;
  }
  int sum(int i) {
    int s = 0;
    for (; i >= 0; i = (i & i + 1) - 1) s += tree[i];
    return s;
  }
};

int main() {
  //
  int N;
  cin >> N;
  vector<pair<int, int>> v;
  map<int, int> zx, zy;
  rep(i, N) {
    int x, y;
    cin >> x >> y;
    v.emplace_back(x, y);
    zx[x] = 1;
    zy[y] = 1;
  }
  {
    int cnt = 0;
    FOR(it, zx) { it->second = cnt++; }
  }
  {
    int cnt = 0;
    FOR(it, zy) { it->second = cnt++; }
  }

  rep(i, N) {
    v[i].first = zx[v[i].first];
    v[i].second = zy[v[i].second];
  }
  sort(ALLOF(v));

  FenwickTree lhs(N), rhs(N);
  vector<int> v_x(N, 0), v_w(N, 0), v_z(N, 0), v_y(N, 0);

  int cnt = 0;
  rep(i, N) {
    int x = v[i].first;
    int y = v[i].second;
    v_w[i] = lhs.sum(y - 1);
    v_x[i] = cnt - v_w[i];
    lhs.add(y, 1);
    cnt++;
  }
  cnt = 0;
  for (int i = N - 1; i >= 0; i--) {
    int x = v[i].first;
    int y = v[i].second;
    v_y[i] = rhs.sum(y - 1);
    v_z[i] = cnt - v_y[i];
    rhs.add(y, 1);
    cnt++;
  }

  vector<ll> mod_pow(N + 1, 0);
  ll p = 1;
  rep(i, N + 1) {
    mod_pow[i] = p;
    p *= 2;
    p %= MOD;
  }

  ll ret = 0;
  rep(i, N) {
    rep(S, 1 << 4) {
      ll a = v_x[i];
      ll b = v_w[i];
      ll c = v_z[i];
      ll d = v_y[i];
      vector<ll> w{a, b, c, d};
      ll tmp = 1;
      rep(j, 4) {
        if ((S >> j) & 1) {
          tmp *= mod_pow[w[j]] - 1;
          tmp %= MOD;
        }
      }
      if ((((S >> 0) & 1) && ((S >> 3) & 1)) ||
          (((S >> 1) & 1) && ((S >> 2) & 1))) {
        tmp *= 2;
        tmp %= MOD;
      }
      ret += tmp;
      ret %= MOD;
    }
  }

  cout << ret << endl;

  return 0;
}

Measured memory_bytes: 26864
#include <iostream>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <queue>
#include <cstdarg>
#include <set>
#include <limits>
#include <iomanip>

using namespace std;
#define INF 2e9 + 9
#define MOD 1000000007
#define ALL(v) v.begin() , v.end()
#define Int int64_t
#define pll pair<Int,Int>
template<class T> using pql = priority_queue<T, vector<T>>;
template<class T> using pq = priority_queue<T, vector<T>, greater<T>>;
#define ll(n) Int n; cin >> n;
#define LL(...) Int __VA_ARGS___; cin >> __VA_ARGS___;
#define OUT(...) cout << __VA_ARGS___;
#define RP(n, i, s) for(Int i = s ;i < n ;i++)
#define REP(n, i) for (Int i = 0; i < n; i++)
#define REPe(n, i) for (Int i = 1; i <= n; i++)
#define RPe(n, i, s) for (Int i = s; i <= n; i++)
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;
#define upd_min(miner, updater) if (miner > updater) miner = updater;

void ansYes(bool flag) {
    if (flag) cout << "Yes" << endl; else cout << "No" << endl;
}

void ansYES(bool flag) {
    if (flag) cout << "YES" << endl; else cout << "NO" << endl;
}

struct node {
    Int to;
    Int length;
};


vector<Int> divisor(Int n) {
    vector<Int> ret;
    for (Int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    return (ret);
}

/*
vector<vector<int>> to;
vector<int> flag;
vector<int> c;


Int dfs(int from, int mae) {
    flag[from] = 1;
    Int mini = 0;
    for (auto next : to[from]) {
        if (next == mae) continue;
        if (flag[next] == 1) {
            return -1;
        } else {
            mini = min(mini, dfs(next, from));
        }
    }
    return mini;
}*/

int dx8[8] = {0, -1, -1, -1, 0, 1, 1, 1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

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

struct datas {
    Int max;
    Int size;
};

class ContainChecker {
protected:
    Int minx, miny, maxx, maxy;
public:
    ContainChecker(Int minx, Int miny, Int maxx, Int maxy) : minx(minx), miny(miny), maxx(maxx), maxy(maxy) {};

    bool in(Int x, Int y) {
        return (minx <= x && miny <= y && x <= maxx && y <= maxy);
    }
};


int main(void) {
    Int n;
    cin >> n;
    Int k , q;
    cin >> k >> q;
    vector<Int> a(n,k);
    REP(q,i){
        Int x;
        cin >> x;
        x--;
        a.at(x)++;
    }
    REP(n,i){
        a.at(i) -= q;
        ansYes(a.at(i) > 0);
    }
}




Measured memory_bytes: 1408
n=int(input())
ad=[list(map(int,input().split())) for i in range(n)]
l=0
for i in range(n):
  for j in  range(n):
    l+=((ad[i][0]-ad[j][0])**2+(ad[i][1]-ad[j][1])**2)**(1/2)

ans=l/n
print(ans)

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

int main() {
    int K;
    cin >> K;
    int ans = 0;

    rep(i,K) {
        rep(j,K) {
            rep(k,K) {
                ans += gcd(gcd(i, j), k);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main()
{
    int a,b,c,s,y,z;
    cin>>a>>b>>c;
    s=a+b;
    y=a+c;
    z=b+c;

    if(s<y && s< z)cout<<s<<endl;
    else if(y<s && y<z)cout<<y<<endl;
    else
        cout<<z<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template <class T> T min2(T a,T b){if(a<b) return a;return b;};

typedef long long ll;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

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

  long a=1;
  rep(i,n){
    a = min(a*2, a+k);
  }

  cout << a << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define fast cin.sync_with_stdio(false);
using namespace std;


int main()
{
 
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif

	int n;cin>>n;
	int arr[n];
	for (int i=0;i<n;i++)cin>>arr[i];

	int dp[n];
	dp[0]=0;
	dp[1]=abs(arr[1]-arr[0]);

	for (int i=2;i<n;i++)
	{
		dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
	}
	cout<<dp[n-1];


}

Measured memory_bytes: 1024
import java.util.Scanner;
import java.util.Arrays;

class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		int [] count = new int [101], countc = new int [101];
		int max, j = 0, x;
 		
		Scanner cin = new Scanner(System.in);
		while (cin.hasNext()) {
    	 	x = cin.nextInt();
    	 	count[x]++;
		}
    	 
   		for (j = 0; j < 101; j++) {
    		countc[j] = count[j];
   	 	}
		Arrays.sort(countc);
 		max = countc[100];
 			
	 	for (j = 0; j < 101; j++) {
   	 		if (count[j] == max) {
   	 			System.out.println(j);
   	 		}
   	 	}
	}
}

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

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


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

ll gcd_euclid(ll a, ll b){
    return b==0 ? a : gcd_euclid(b, a%b);
}


int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n, m; cin >> n >> m;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        a[i] /= 2;
    }
    
    ll lcm = a[0];
    for(int i = 1; i < n; i++){
        int gcd = gcd_euclid(lcm, a[i]);
        lcm = lcm * a[i] / gcd;
        if(lcm > m){
            cout << 0 << endl;
            return 0;
        }
    }

    for(int i = 0 ; i < n; i++){
        if((lcm/a[i])%2 == 0){
            cout << 0 << endl;
            return 0;
        }
    }

    ll ans = 1 + (m-lcm) / (lcm*2);
    cout << ans << endl;
    
    return 0;
}


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

using namespace std;

#define int long long
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
static const int INF=1010000000000000017LL;
static const double eps=1e-12;
static const double pi=3.14159265358979323846;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};
static const int ddx[8]={1,-1,0,0,1,1,-1,-1};
static const int ddy[8]={0,0,1,-1,1,-1,1,-1};

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

int N;
string S;

vector<int> ri;
int ans;

void swap(int i,int j){
    char temp=S[i];
    S[i]=S[j];
    S[j]=temp;
}

signed main(){
    cin>>N;
    cin>>S;
    for(int i=0;i<N;++i)if(S[i]=='R')ri.push_back(i);
    for(int i=0;i<N;++i){
        if(ri.size()==0)break;
        if(S[i]=='W'){
            int j=ri.back();
            if(j<i)break;
            swap(i,j);
            ans++;
            ri.pop_back();
        }
    }
    cout<<ans<<endl;
}

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


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	string S;
	cin >> S;
	int res = 0;
	for (int i = 0; i < n - 1;++i) {
		if (S[i] == S[i + 1]) {
			res++;
		}
	}
	cout << S.size() - res << endl;
	return 0;
}

Measured memory_bytes: 512
s=input()
a=[]
for i in range(0,len(s)//2*2,2):
  a.append(s[i:i+2])
a10=a.count('10')
a01=a.count('01')

if len(s)%2:
  s1=int(s[-1])
else:s1=-1

if a10>a01:
  if s1==0:
    cnt=len(a)-a10+a01+1
  else:
    cnt=len(a)-a10+a01
elif a01>a10:
  if s1==1:
    cnt=len(a)-a01+a10+1
  else:
    cnt=len(a)-a01+a10
else:
  cnt=len(a)
print(cnt)


Measured memory_bytes: 41584
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

namespace Atcoder.Abc
{
    //https://atcoder.jp/contests/abc173/tasks/abc173_b
    public class Abc173_B
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            int C0 = 0;
            int C1 = 0;
            int C2 = 0;
            int C3 = 0;

            var N = int.Parse(ReadLine());

            for (int i = 1; i <= N; i++)
            {
                var S = ReadLine().ToString();

                switch (S)
                {
                    case "AC":
                        C0 += 1;
                        break;

                    case "WA":
                        C1 += 1;
                        break;

                    case "TLE":
                        C2 += 1;
                        break;

                    case "RE":
                        C3 += 1;
                        break;
                }
            }

            WriteLine($"AC x {C0}");
            WriteLine($"WA x {C1}");
            WriteLine($"TLE x {C2}");
            WriteLine($"RE x {C3}");



            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 20724
#include <stdio.h>
#include <math.h>
#define sq(a) ((a)*(a))

double x[10], y[10];
int count = 0;
double length;

void dfs(int array[], int n, int flag){
  if(array[0] == n){
    count++;
    double newlen = 0;
    for(int i=2; i<=n; i++)
      newlen = newlen + sqrt(sq(x[array[i]]-x[array[i-1]]) + sq(y[array[i]]-y[array[i-1]]));
    length = length + newlen;
    return;
  }
  
  for(int i=1; i<=n; i++){
    if(flag & (1<<i))  continue;
    array[++array[0]] = i;
    dfs(array, n, (flag | (1<<i)));
    array[0]--;
  }
}

int main(){
  int n;  scanf("%d", &n);
  for(int i=1; i<=n; i++)  scanf("%lf %lf", &x[i], &y[i]);
  int array[12] = {0};
  dfs(array, n, 0);
  double ans = length / count;
  printf("%4.10lf\n", ans);
  return 0;
}
    


Measured memory_bytes: 128
#include <bits/stdc++.h>
//#pragma GCC optimize(2)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);	
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
double r;
int main(){
//	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> r;
	printf("%.12lf\n",2.0*pi*r);
	return 0;
}
//do smt instead of nothing! never give up!


Measured memory_bytes: 3776
#include <iostream>
#include <map>
#include <algorithm>
using namespace std;

void insert(map<size_t, size_t>& target_map, size_t const target_val) {
    if (target_map.find(target_val) == target_map.cend()) target_map[target_val] = 0;
    target_map[target_val]++;
}

void getMaxCount(map<size_t, size_t> const& target, map<size_t, size_t>::const_iterator* ret) {


    map<size_t, size_t>::const_iterator ite = target.cbegin();
    ret[0] = ite;
    ite++;
    ret[1] = ite;
    if (ret[0]->second < ret[1]->second) swap(ret[0], ret[1]);

    for (;ite != target.end(); ite++) {
        if (ret[0]->second < ite->second) {
            ret[1] = ret[0];
            ret[0] = ite; 
        } else if(ret[1]->second < ite->second) {
            ret[1] = ite;
        }
    }
}

size_t spCase(map<size_t, size_t> first, map<size_t, size_t> second) {
    map<size_t, size_t>* targets[2];
    if (first.size() == 1) {
        targets[0] = &first;
        targets[1] = &second;
    } else {
        targets[0] = &second;
        targets[1] = &first;
    } 
    targets[1]->erase(targets[0]->begin()->first);
    map<size_t, size_t>::const_iterator ites[2];
    getMaxCount(*(targets[1]), ites);
    return ites[0]->second;
}

int main() {
    size_t n;
    cin >> n;
    size_t v[n];
    map<size_t, size_t> first;
    map<size_t, size_t> second;
    for (auto i = 0; i < n; i++) {  
        size_t x;
        cin >> x;    
        if (i%2 == 0) insert(first, x);
        else insert(second, x);
    }

    size_t ans = 0;
    if (first.size() == 1 && second.size() == 1) {
        if (first.begin()->first == second.begin()->first) ans = n / 2;
        else 0;
    } else if (first.size() == 1 || second.size() == 1){
        ans = n / 2 - spCase(first, second); 
    } else {
        map<size_t, size_t>::const_iterator first_max[2];
        getMaxCount(first, first_max);

        map<size_t, size_t>::const_iterator second_max[2];
        getMaxCount(second, second_max);
        if (first_max[0]->first == second_max[0]->first) {
            if (first_max[0]->second == second_max[0]->second) {
                size_t const temp = max(first_max[1]->second, second_max[1]->second);
                ans = n - (first_max[0]->second + temp);
            } else if (first_max[0]->second < second_max[0]->second) {
                ans = n - second_max[0]->second - first_max[1]->second;
            } else {
               ans = n - first_max[0]->second - second_max[1]->second;
            }
        } else {
            ans = n - first_max[0]->second - second_max[0]->second;                
        }
    }
    cout << ans << endl;
    return 0;
}



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

int main()
{
  int a, b, s, sum = 0;
  cin >> a >> b;
  s = b - a;
  for (int i = s; i >= 1; i--)
  {
    sum += i;
  }
  cout << sum - b << endl;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define mkp make_pair
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<<endl;}}
#define print1d(mat,n){for(int i=0;i<(int)(n);i++)cout<<mat[i]<<" ";cout<<endl;}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define printpair(v) for(auto val: v){cout<<val.fi<<":"<<val.se<<", ";}cout<<endl;
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<endl;
#define init(v,x) for (auto &itr:v){itr=x;}
#define ln length()
const int mod = 998244353;
#define sz size()
const int inf = 1e18;
int n,w,warr[105],varr[105];
int dp[105][100005];
int f(int i, int cw){
    if(cw==w || i==n){
        return 0;
    }
    int ans=-inf;
    if(dp[i][cw]!=-1){
        return dp[i][cw];
    }
    if(cw+warr[i]<=w){
        ans=max(ans,f(i+1,cw+warr[i])+varr[i]);
    }
    ans=max(ans,f(i+1,cw));
    dp[i][cw]=ans;
    return ans;

}
void solve() {
    clr(dp,-1);
    cin>>n>>w;
    rep(i,0,n){
        cin>>warr[i]>>varr[i];
    }
    cout<<f(0,0)<<endl;
}

int32_t main(){
    fastIO
#ifndef ONLINE_JUDGE
    freopen(R"(C:\Users\swast\CLionProjects\untitled\input.txt)", "r", stdin);
#endif
    int t=1;
//    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 85728
const Main = input => {
  const lines = input.split('\n');
  const firstLine = lines[0];
  const secondLine = lines[1];
  const firstLineArray = firstLine.split('');
  const secondLineArray = secondLine.split('');
  const result = firstLineArray.reduce((acc,_,index) => {
    if(firstLineArray[index] == secondLineArray[index]) return acc;
    else return acc + 1;
  },0);
  console.log(result)
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 37724
import java.util.*;
import java.lang.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int g[] = new int[n];
        for(int i = 0;i<n;i++){
            int k = sc.nextInt();
            g[k-1] = i+1;
        }
        for(int i = 0;i<n;i++){
            System.out.print(g[i]+" ");
        }
        System.out.println();
        sc.close();
    }
}

Measured memory_bytes: 57568
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N; ll C;
    cin >> N >> C;
    vector<vector<ll> > vX(2, vector<ll>(N + 1));
    vector<vector<ll> > vV(2, vector<ll>(N + 1));
    for (int i = 1; i <= N; i++) { cin >> vX[0][i] >> vV[0][i]; }
    for (int i = 1; i <= N; i++) {
        vX[1][i - 1] = C - vX[0][i];
        vV[1][i - 1] = vV[0][i];
    }
    for (int i = 0; i < N; i++) {
        vV[0][i + 1] += vV[0][i];
        vV[1][N - (i + 1)] += vV[1][N - i];
    }
    vector<vector<ll> > vMax(2, vector<ll>(N + 1));
    for (int i = 1; i <= N; i++) {
        vMax[0][i] = max(vMax[0][i - 1], vV[0][i] - vX[0][i]);
        vMax[1][N - i] = max(vMax[1][N - i + 1], vV[1][N - i] - vX[1][N - i]);
    }

    ll ans = -LINF;
    for (int i = 0; i <= N; i++) {
        ans = max(ans, vV[0][i] - vX[0][i] * 2 + vMax[1][i]);
        ans = max(ans, vV[1][i] - vX[1][i] * 2 + vMax[0][i]);
    }
    cout << ans << '\n';

}

Measured memory_bytes: 5744
#include <stdio.h>

int main(){
	long x, y;
	
	while(scanf("%ld %ld", &x, &y) != EOF){
		long tmp, m, n;
		
		if(x > y){
			m = x;
			n = y;
		}else{
			m = y;
			n = x;
		}
		
		while(n != 0){
			tmp = n;
			n   = m % n;
			m   = tmp;
		}
		
		printf("%ld %ld\n", m, x / m * y);
	}

	return 0;
}

Measured memory_bytes: 596
#define _CRT_SECURE_NO_DEPRECATE
#include<bits/stdc++.h>
#define Rint register int
#define MP make_pair
#define fi first
#define se second
#define PB push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii; // 注意必要时改类型
typedef vector<int> vi;
const int N = (int)3e2 + 3;

int n, a[4];
// 发现一个3，做状态变量
// dp[a][b][c] 表示剩一个a个，剩两个b个, 剩三个c个
double dp[N][N][N];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
#ifdef _DEBUG
	int tt = clock();
	// freopen("in.txt", "r", stdin);
#endif 

	cin >> n;
	int x = 0;
	for (Rint i = 0; i < n; ++i){
		cin >> x;
		++a[x];
	}
	dp[0][0][0] = 0;
	for (int k = 0; k < N - 1; ++k) {
		for (int j = 0; j < N - 1; ++j) {
			for (int i = 0; i < N - 1; ++i) {	
				if (i || j || k) {
					int sum = i + j + k;
					double val = 1.0 * n / sum;
					if (i) val += 1.0 * dp[i - 1][j][k] * i / sum;
					if (j) val += 1.0 * dp[i + 1][j - 1][k] * j / sum;
					if (k) val += 1.0 * dp[i][j + 1][k - 1] * k / sum;
					dp[i][j][k] = val;
				}
					
			}
		}
	}
	printf("%.20lf\n", dp[a[1]][a[2]][a[3]]);



#ifdef _DEBUG
	cerr << "\nTIME = " << clock() - tt << endl;
	tt = clock();
#endif

	return 0;
}


Measured memory_bytes: 217472
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

type kakko struct {
	str string
	min int
	max int
}

func main() {
	N := getStdinInt()
	F := make([]kakko, 0, N)
	L := make([]kakko, 0, N)
	for i := 0; i < N; i++ {
		s := getStdin()
		min, max := minmaxKakko(s)
		if min >= 0 {
			F = append(F, kakko{s, min, max})
		} else {
			L = append(L, kakko{s, min, max})
		}
	}
	sort.Slice(F, func(i, j int) bool { return F[i].max-F[i].min < F[j].max-F[j].min })
	sort.Slice(L, func(i, j int) bool { return L[i].max > L[j].max })

	K := make([]kakko, N)
	for i := 0; i < len(F); i++ {
		K[i] = F[i]
	}
	for i := 0; i < len(L); i++ {
		K[i+len(F)] = L[i]
	}

	first := -1
	last := -1
	for i := 0; i < len(K); i++ {
		if K[i].str[0] == '(' {
			first = i
			break
		}
	}
	for i := len(K) - 1; i >= 0; i-- {
		if first != i && K[i].str[len(K[i].str)-1] == ')' {
			last = i
			break
		}
	}

	if first == -1 || last == -1 {
		fmt.Printf("No\n")
		return
	}

	stack := 0
	stack = okKakko(K[first].str, stack)
	if stack < 0 {
		fmt.Printf("No\n")
		return
	}
	for i := 0; i < len(K); i++ {
		if first == i || last == i {
			continue
		}
		stack = okKakko(K[i].str, stack)
		if stack < 0 {
			fmt.Printf("No\n")
			return
		}
	}
	stack = okKakko(K[last].str, stack)
	if stack < 0 {
		fmt.Printf("No\n")
		return
	}

	if stack == 0 {
		fmt.Printf("Yes\n")
	} else {
		fmt.Printf("No\n")
	}
}

func minmaxKakko(s string) (int, int) {
	stack := 0
	max := math.MinInt32
	min := math.MaxInt32
	for i := 0; i < len(s); i++ {
		if s[i] == '(' {
			stack++
			if stack > max {
				max = stack
			}
		}
		if s[i] == ')' {
			stack--
			if stack < min {
				min = stack
			}
		}
	}
	return min, max
}

func okKakko(s string, stack int) int {
	for i := 0; i < len(s); i++ {
		if s[i] == '(' {
			stack++
		}
		if s[i] == ')' {
			stack--
		}
		if stack < 0 {
			return -1
		}
	}
	return stack
}

func getStdin() string {
	sc.Scan()
	return sc.Text()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}


Measured memory_bytes: 67372
/////////////////////////   _LeMur_
#define _CRT_SECURE_NO_WARNINGS
#include <unordered_map>
#include <unordered_set>
#include <functional>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <chrono>
#include <random>
#include <bitset>
#include <cstdio>
#include <vector>
#include <string>
#include <ctime>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>

using namespace std;

const int N = 200005;
const int inf = 1000 * 1000 * 1000;
const int mod = 1000 * 1000 * 1000 + 7;
mt19937 myrand(chrono::steady_clock::now().time_since_epoch().count());

long long n, m;

int main() {
    cin >> n >> m;
    if (n == 1 || m == 1) {
        cout << 1 << endl;
        return 0;
    }
    long long x1 = n - n / 2, y1 = n / 2;
    long long x2 = m - m / 2, y2 = m / 2;
    cout << x1 * x2 + y1 * y2 << endl;
	return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include<vector>
using namespace std;
int main(){

  int N;
  cin>>N;
  vector<int>T(N);
  int allsum=0;
  for(int i=0;i<=N-1;i++){
  
    cin>>T[i];
    allsum+=T[i];
  }
  int M;
  cin>>M;
  vector<int>P(M);
  vector<int>X(M);
  for(int i=0;i<=M-1;i++){
  
    cin>>P[i]>>X[i];
  }
  for(int i=0;i<=M-1;i++){
  
    cout<<allsum-T[P[i]-1]+X[i]<<endl;
  }
  return 0;
}

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

int main(){
  int N,M;
  cin >> N >> M;
  
  vector<bool> nice(N,true); //いい展望台だとtrue
  
  vector<int> height(N); //展望台の高さ
  for(int i=0;i<N;i++){
    cin >> height.at(i);
  }
  
  int A,B;
  int sa;
  for(int i=0;i<M;i++){
    cin >> A >> B;
    sa=height.at(A-1)-height.at(B-1);
    if(sa<0){
      nice.at(A-1)=false;
    }else if(sa>0){
      nice.at(B-1)=false;
    }else{
      nice.at(A-1)=false;
      nice.at(B-1)=false;
    }
      
  }
    
    int ans=0;
    for(int i=0;i<N;i++){
      if(nice.at(i)) ans++;
    }
    cout << ans << endl;
 
  return 0;
}

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

using namespace std;

#define MAX 510
#define MAX_E 50010

int par[MAX],rnk[MAX];
void init(int N){
  for(int i = 0 ; i < N ; i++){
    par[i] = i;
    rnk[i] = 0;
  }
}

int find(int x){
  if(par[x] == x){
    return x;
  }
  return par[x] = find(par[x]);
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y){ return; }
  if(rnk[x] < rnk[y]){
      par[x] = y;
  }else{
    par[y] = x;
    if(rnk[x] == rnk[y]){
      rnk[x]++;
    }
  }
}

bool same(int x,int y){
  return (find(x) == find(y));
}

struct Edge{ int u,v,cost; };

bool comp(const Edge &e1,const Edge &e2){
  return e1.cost < e2.cost;
}

int V,E;
Edge es[MAX_E];

bool equals(const Edge &e1,const Edge &e2){
  return (e1.u == e2.u && e1.v == e2.v);
}

vector<Edge> vec;

int kruskal(int ne){
  init(V);
  int res = 0;
  for(int i = 0 ; i < E ; i++){
    Edge e = es[i];
    if(ne != -1 && equals(e,vec[ne])){
      continue;
    }
    if(!same(e.u,e.v)){
      unite(e.u,e.v);
      res += e.cost;
    }
  }
  return res;
}

int kruskal(){
  sort(es,es+E,comp);
  init(V);
  int res = 0;
  for(int i = 0 ; i < E ; i++){
    Edge e = es[i];
    if(!same(e.u,e.v)){
      unite(e.u,e.v);
      res += e.cost;
      vec.push_back(e);
    }
  }
  return res;
}

int main(){
  int a,b,c;
  cin >> V >> E;
  for(int i = 0 ; i < E ; i++){
    cin >> a >> b >> c; a--; b--;
    es[i] = (Edge){a,b,c};
  }
  vec.clear();
  int cnt = 0, sum = 0;
  int res = kruskal();
  for(int i = 0 ; i < (int)vec.size() ; i++){
    int r = kruskal(i);
    bool check = true;
    for(int j = 0 ; j < V ; j++){
      if(!same(0,j)){
        check = false;
        break;
      }
    }
    if((check && r > res) || !check){
      cnt++;
      sum += vec[i].cost;
    }
  }
  cout << cnt << " " << sum << endl;
  return 0;
}

Measured memory_bytes: 1824
#include<bits/stdc++.h>
using namespace std;
const int mxn = 305;

double p[mxn][mxn][mxn];
double ev[mxn][mxn][mxn];
int main(){
	int n;
	cin >> n;
	map<int,int> cnt;
	for(int i =0;i<n;i++){
		int a;
		cin >> a;
		cnt[a]++;
	}

	p[cnt[1]][cnt[2]][cnt[3]] = 1;

	for(int c =n;c>=0;c--){
		for(int b= n;b>=0;b--){
			for(int a = n;a>=0;a--){

				if(a==0 && b ==0 && c ==0)
					continue;

				if(a+b+c>n)continue;

				double p_waste = 1.0*(n-(a+b+c))/n; // the probability that I cant move from the current state
				double ev_waste = p_waste/(1-p_waste)+1; // expected number of moves required to move from the current state

				ev[a][b][c]+=ev_waste*p[a][b][c]; // The number of moves till I change --> add all the move wasted then +1 since a valid transformation is chosen
				if(a!=0){
					double pa = 1.0*a/(a+b+c);
					p[a-1][b][c] += p[a][b][c]*pa;
					ev[a-1][b][c] += ev[a][b][c]*pa;
				}
				if(b!=0){
					double pb=1.0*b/(a+b+c);
					p[a+1][b-1][c] += p[a][b][c]*pb;
					ev[a+1][b-1][c] +=ev[a][b][c]*pb;
				}
				if(c!=0){
					double pc = 1.0*c/(a+b+c);
					p[a][b+1][c-1]+=p[a][b][c]*pc;
					ev[a][b+1][c-1] +=ev[a][b][c]*pc;
				}
			}
		}
	}

	cout << fixed << setprecision(12) << ev[0][0][0] << endl;
}

Measured memory_bytes: 438528
#include<iostream>

int main(){
	int t;
	std::cin>>t;
	for(int i=0;i<t;i++){
		int n,back,max_up=0,max_down=0;
		std::cin>>n>>back;
		for(int j=1;j<n;j++){
			int now;
			std::cin>>now;
			if(back<now)max_up=std::max(max_up,now-back);
			else if(back>now)max_down=std::max(max_down,back-now);
			back=now;
		}
		std::cout<<max_up<<" "<<max_down<<std::endl;
	}
	return 0;
}

Measured memory_bytes: 1160
n = int(input())
A = list(map(int, input().split()))
count = 0
flag = 1
while(flag):
    flag = 0
    for i in range(n):
        if A[i]%2 == 0:
            A[i] /= 2
        else:
            break
    else:
        flag = 1
        count += 1 

print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000



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


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

namespace AtCoder.Abc
{
    class QuestionD
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            var ab = Console.ReadLine().Split(' ').Select(q => long.Parse(q)).ToArray();

            var result = 0L;

            if(ab[1] % ab[0] == 0) {
                result = ab[1] + ab[0];
            } else {
                result = ab[1] - ab[0];
            }

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

char s[30];
int n,vis[30];
int main() {
	scanf("%s",s);
	n=strlen(s);
	if (n!=26) {
		rep(i,0,n) vis[s[i]-'a']=1;
		printf("%s",s);
		rep(i,0,26) if (!vis[i]) { printf("%c\n",i+'a'); return 0; }
	} else {
		rep(i,0,n) vis[s[i]-'a']=1;
		per(i,0,n) {
			vis[s[i]-'a']=0;
			rep(j,s[i]-'a'+1,26) if (vis[j]==0) {
				s[i]=0;
				printf("%s",s);
				printf("%c\n",j+'a');
				return 0;
			}
		}
		puts("-1");
	}
}

Measured memory_bytes: 256
n=int(input())

t = list(map(int,input().split()))

memo = [0]*(2*10**5+1)

for i in t:
    memo[i] += 1

ans = 0

for i in memo:
    ans += i*(i-1)//2

for i in t:
    print(ans-(memo[i]*(memo[i]-1)//2)+((memo[i]-1)*(memo[i]-2)//2))
    


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

long long n, m;
const long long M = 1e9 + 7;

long long pow (long long a, long long p){
    long long c = 1, d = a;
    
    while(p){
        if(p & 1)
            c = c * d % M;
        
        d = d * d % M;
        p >>= 1;
    }
    
    return c;
}

int main() {
    cin >> n;
    
    m = (pow(10, n) - pow(9, n) * 2 + pow(8, n) + M * 2) % M;
    cout << m << endl;
}



Measured memory_bytes: 3604
#include <cstdio>
#define FOR(i, m, n) for (int i = m; i < n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define MIN(x, y) x < y ? x : y
using namespace std;

int n, t, ans=1<<30;
char s[300005];

int main() {
  scanf("%d", &n), scanf("%s", s);
	FOR(i,1,n) t += (s[i]=='E');
	REP(i,n) {
		ans = MIN(ans, t);
		t += (s[i]=='W') - (s[i+1]=='E');
	}
	printf("%d\n", ans);
	return 0;
}

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

#define cc(x) cout << (x) << endl
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); ++i)
typedef long long ll;

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

const ll inf = 1LL<<58;
const int iinf = 1<<30;

int main(){
    int a,b;
    cin >> a >> b;
    int tmp =0;
    if(a>b){
        tmp += a;
        a--;
    }else{
        tmp += b;
        b--;
    }
        if(a>b){
        tmp += a;
        a--;
    }else{
        tmp += b;
        b--;
    }
    cc(tmp);
}

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

using namespace std;

string cube;
int cnt;

void remove(){
    int prev = cnt;
    for(string::iterator itr = cube.begin(); itr < cube.end() - 1; itr++){
        if(*itr != *(itr + 1)){
            cube.erase(itr);
            cube.erase(itr);
            cnt += 2;
            break;
        }
    }
    if(cnt == prev) return;
    else remove();
}

int main(){
    cin >> cube;
    remove();
    cout << cnt << endl;
    return 0;
}

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



int main() {
  int n,m;
  cin>>n>>m;
  vector<ll> a(n);
  vector<ll> b(n);
  vector <pair<ll,ll>> q;
  rep(i,n){
    cin>>a[i]>>b[i];
    q.push_back(make_pair(a[i],b[i]));
  }
  sort(q.begin(),q.end());
  int cnt=0;
  ll ans=0;
  int now=0;
  ll price;
  while(cnt<m){
  price=q[now].first;
  ll bottle=q[now].second;
  ans+=price*bottle;
  cnt+=bottle;now++;
  }
  ll sub=cnt-m;
  ans-=sub*price;
  cout<<ans;
}


Measured memory_bytes: 3956
/*
https://atcoder.jp/contests/dp/tasks/dp_d*/
#include<bits/stdc++.h>
using namespace std;
long long dp[100005];

int main()
{
	int n,w;
    cin >> n >> w;
    int a[n],b[n];
    for(int i=0;i<n;i++)cin >> a[i] >> b[i];
    for(int i=0;i<n;i++)
    {   if(a[i]>w)continue;
        for(int j=w;j>=a[i];j--)
        {
            dp[j]=max(dp[j],b[i]+dp[j-a[i]]);
        }
    }
    cout << dp[w] << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cctype>
#include <map>

const int INT_INF = 1000000000;                 // 10^9
const long long LONG_INF = 1000000000000000000; // 10^18

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> d(n);
    for (int i = 0; i < n; i++)
    {
        cin >> d[i];
    }

    sort(d.begin(), d.end());
    int mid = d.size() / 2;
    int ans = d[mid] - d[mid - 1];

    cout << ans << endl;

    return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<string> S(N);
  for (int i = 0; i < N; i++) cin >> S.at(i);
  sort(S.begin(), S.end());
  S.push_back("");

  vector<pair<int, string>> V;
  for (int i = 1, cnt = 1; i <= N; i++) {
    if (S.at(i - 1) != S.at(i)) {
      V.push_back({-cnt, S.at(i - 1)});
      cnt = 1;
    } else cnt++;
  }
  sort(V.begin(), V.end());

  for (int i = 0; i < V.size(); i++)
    if (V.at(i).first == V.at(0).first) cout << V.at(i).second << "\n";
}

Measured memory_bytes: 18912
N = int(input())
L = list(map(int, input().split()))

M = sorted(L)
count = 0

for i in range(N-2):
  for j in range(i+1,N-1):
    for k in range(j+1,N):
      if M[i] != M[j] and M[j] != M[k]:
        if M[i] + M[j] > M[k]:
          count += 1
          
print(count)

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

int t;
string s;

vector<pair<int, vector<int>>> v;

void dfs(int i, int sum, vector<int> vv)
{
	if (sum > t) return;
	
	if (i == s.size()){
		v.push_back(make_pair(sum, vv));
		return;
	}
	
	/*
	
	if (s[i] == '0'){
		vv.push_back(0);
		dfs(i + 1, sum, vv);
		vv.pop_back();
		return;
	}
	
	*/
	
	int a = 0;
	for (int j = i; j < s.size(); j++){
		a *= 10;
		a += s[j] - '0';
		vv.push_back(a);
		dfs(j + 1, sum + a, vv);
		vv.pop_back();
	}
}

void solve()
{
	v.clear();
	dfs(0, 0, vector<int>());
	sort(begin(v), end(v));
	
	if (v.empty()){
		puts("error");
	}
	else if (v.size() >= 2 && v[v.size() - 1].first == v[v.size() - 2].first){
		puts("rejected");
	}
	else {
		printf("%d", v.back().first);
		for (int i = 0; i < v.back().second.size(); i++){
			printf(" %d", v.back().second[i]);
		}
		puts("");
	}
}

int main()
{
	while (cin >> t >> s, t){
		solve();
	}
}

Measured memory_bytes: 1228
#include <iostream>    // cin, cout
#include <string>    // string, stoi, to_string
#include <algorithm>    // sort, lower_bound, heap, min, next_permutation 
#include <functional>    // greater, less
#include <vector>    // vector
#include <stack>    // stack
#include <queue>    // queue
#include <list>    // list
#include <map>    // map
#include <set>    // set
#include <tuple>    // tuple
#include <bitset>    // bitset
#include <cstdio>  // fopen, printf, scanf, puts
#include <cmath>    // sin, exp, log, pow, sqrt
#include <iomanip>    // setfill, setbase
#include <ctime>    // clock

using namespace std;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<30));
const long long linf = (1LL<<60);

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y;
    cin >> x >> y;
    bool ok = false;
    for(int i=0; i<=x; i++)
    {
        if(2*i + 4*(x-i) == y) ok = true;
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <algorithm>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int a, b, h;

int main() {
  cin >> a >> b >> h;
  cout << (a + b) * h / 2 << endl;
  return 0;
}


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

int main() {
    int r, g, b;
    cin >> r >> g >> b;

    int num = r * 100 + g * 10 + b;
    if (num % 4 == 0) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
s = input()
rs = s[::-1]
p = 1
while True:
    if p == 0:
        print("NO")
        exit()
    elif p == 1:
        p = 0
    
    if len(rs) == 0:
        print("YES")
        exit()
    
    if rs[0:5] == "maerd":
        rs = rs[5:]
        p = 1
    elif rs[0:5] == "esare":
        rs = rs[5:]
        p = 1
    elif rs[0:7] == "remaerd":
        rs = rs[7:]
        p = 1
    elif rs[0:6] == "resare":
        rs = rs[6:]
        p = 1

Measured memory_bytes: 3316
/* ***********************************************
Author        :yang12138
Created Time  :2017年12月29日 星期五 14时45分59秒
File Name     :A.cpp
************************************************ */
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
typedef long long ll;
typedef pair<int,int>pii;
#define lson (root<<1)
#define rson (root<<1|1)



int main(){
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

	ll a,b;
	cin>>a>>b;

	int ans=0;
	while(a<=b){
		ans++;
		a<<=1;
	}
	cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define inf (1<<30)
using namespace std;
typedef long long LL;
int read()
{
    char c=getchar();int f=1,sum=0;
    while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0' && c<='9'){sum=sum*10+c-'0';c=getchar();}
    return sum*f;
}
int n,nl[6005],nr[6005],ps[6005],ans=inf,pa[2005];
char A[2005],B[6005];
vector<pair<int,int> > v;
void init()
{
	nl[0]=-inf;for(int i=1;i<=n*3;i++) nl[i]=(B[i]=='1')?i:nl[i-1];
	nr[3*n+1]=inf;for(int i=n*3;i>=1;i--) nr[i]=(B[i]=='1')?i:nr[i+1];
	for(int i=1;i<=n*3;i++) ps[i]=ps[i-1]+(B[i]=='1');
	for(int i=1;i<=n;i++) pa[i]=pa[i-1]+(A[i]=='1');
}
int getl(int x){return x-nl[x];}int getr(int x){return nr[x]-x;}
int main()
{
	scanf("%s%s",A+1,B+1);
	n=strlen(A+1);
	for(int i=n+1;i<=n*3;i++) B[i]=B[(i-1)%n+1];
	init();
	if(pa[n]>0 && ps[n]==0) return puts("-1"),0;
	for(int i=1;i<=2*n+1;i++)
	{
		int tot=0;v.clear();v.push_back(make_pair(0,0));
		for(int j=1;j<=n;j++)
		if(A[j]!=B[j+i-1])
		{
			tot++;
			int l=j+i-1,r=j+n; if(l>r) l^=r^=l^=r;
			if(ps[r]-ps[l-1]==0) v.push_back(make_pair(getl(l),getr(r)));
		}
		sort(v.begin(),v.end());
		int sz=v.size(),maxr=0,sum=inf;
		for(int j=sz-1;j>=0;j--)
		{
			if(v[j].first!=inf && maxr!=inf) sum=min(sum,(v[j].first<<1)+(maxr<<1));
			maxr=max(maxr,v[j].second);if(maxr==inf) break;
		}
		if(sum!=inf) ans=min(ans,sum+tot+abs(n+1-i));
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define maxn 100005
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
inline void read(int& x)
{	char c=getchar();x=0;int y=1;
	while(c<'0'||c>'9'){if(c=='-') y=-1;c=getchar();}
	while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	x*=y;
}
long long ans,sum[maxn];
int n,A[maxn],B[maxn],C[maxn],f[maxn];
int main()
{   read(n);
	for(int i=1;i<=n;++i) read(A[i]);
	for(int i=1;i<=n;++i) read(B[i]);
	for(int i=1;i<=n;++i) read(C[i]);
	std::sort(A+1,A+n+1);std::sort(B+1,B+n+1);std::sort(C+1,C+n+1);
	for(int i=1;i<=n;++i)
		sum[i]=sum[i-1]+lower_bound(A+1,A+n+1,B[i])-A-1;
	for(int i=1;i<=n;++i)
	{	int tmp=lower_bound(B+1,B+n+1,C[i])-B-1;
		ans+=sum[tmp];
	}
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 2176