akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

template<int mod> struct ModInt {
    int x;

    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    ModInt& operator+=(const ModInt& p) {
        if ((x += p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator-=(const ModInt& p) {
        if ((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }
    ModInt& operator*=(const ModInt& p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }
    ModInt& operator/=(const ModInt& p) {
        *this *= p.inverse();
        return *this;
    }

    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt& p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt& p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt& p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt& p) const { return ModInt(*this) /= p; }

    bool operator==(const ModInt& p) const { return x == p.x; }
    bool operator!=(const ModInt& p) const { return x != p.x; }

    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        return ModInt(u);
    }

    ModInt pow(int e) {
        long long a = 1, p = x;
        while (e > 0) {
            if (e % 2 == 0) { p = (p * p) % mod; e /= 2; }
            else { a = (a * p) % mod; e--; }
        }
        return ModInt(a);
    }

    friend ostream& operator<<(ostream& os, const ModInt<mod>& p) {
        return os << p.x;
    }
    friend istream& operator>>(istream& is, ModInt<mod>& a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};
using modint = ModInt<mod>;

modint dp[100010][2];
int main() {
    init();

    string l;
    cin >> l;
    dp[0][0] = 1;
    FOR(i, 0, l.length())FOR(smaller, 0, 2) {
        if (smaller) {
            dp[i + 1][smaller] += dp[i][smaller] * 3;
        }
        else {
            if (l[i] == '1') {
                dp[i + 1][1] += dp[i][smaller];
                dp[i + 1][0] += dp[i][smaller] * 2;
            }
            else {
                dp[i + 1][0] += dp[i][smaller];
            }
        }
    }
    cout << dp[l.length()][0] + dp[l.length()][1] << "\n";
}


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

int main(){
    int a,b,c,coins = 0,days = 0;
    cin >> a >> b >> c;
    while(coins < c){
        days++;
        coins += a;
        if(days % 7 == 0) coins += b;
    }
    cout << days << endl;
    return 0;
}


Measured memory_bytes: 3100
//g++  7.4.0

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007

ll solve(string a,string b)
{
    ll count = 0;
    for(ll i=0;i<a.length();++i)
    {
        if(a[i] != b[i])
            count++;
    }
    
    return(count);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string s,t; cin>>s>>t;
    ll N = s.length();
    ll M = t.length();
    ll ans = LLONG_MAX;
    for(ll i=0;i<=(N - M);++i)
    {
        string temp;
        for(ll j=i;j<(i + M);++j)
            temp += s[j];
        
        ans = min(ans,solve(temp,t));
    }
    
    cout<<ans<<endl;
}

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

#define MAX_N 44

int fib(int);

int dp[MAX_N+1];

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

  cout << fib(n) << endl;
}

int fib(int n) {
  dp[0] = 1;
  dp[1] = 1;

  if(n==0) return dp[0];
  if(n==1) return dp[1];

  for(int i=2; i<=n; ++i) {
    dp[i] = dp[i-1] + dp[i-2];
  }

  return dp[n];
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define all(n) n.begin(),n.end()
#define yn(x) cout << (x ? "Yes":"No") << endl;

int main() {
  int n,k;
  cin >> n >> k;
  vector<int>h(n);
  rep(i,n) cin >> h[i];
  int cnt = 0;
  rep(i,n){
    if(h[i]>=k) cnt++;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 640
n, k = map(int, raw_input().split())
d = {}
for i in xrange(n):
    a, b = map(int, raw_input().split())
    d[a] = d.get(a, 0) + b
i = 1
ks = sorted(d)
for e in ks:
    if i <= k < i+d[e]:
        print e
        break
    i += d[e]


Measured memory_bytes: 9276
#include<iostream>
#include<map>
using namespace std;
int h,w,sx,sy,gx,gy,n;
int dax[]={-1,-1,0,1,1,1,0,-1},day[]={0,1,1,1,0,-1,-1,-1};
int dbx[]={-2,-2,-2,-1,0,1,2,2,2,1,0,-1},dby[]={-1,0,1,2,2,2,1,0,-1,-2,-2,-2};
bool mas[10][10];
pair<int,int>data[10];
bool dfs(int x,int y,int d){
  if(d == n) return true;
  for(int i=0;i<12;i++){
    int nx=x+dbx[i],ny=y+dby[i];
    if(nx>=0&&nx<9&&ny>=0&&ny<9){
	for(int j=0;j<8;j++){
	  int sx=data[d].first+dax[j],sy=data[d].second+day[j];
	  if(sx>=0&&sx<9&&sy>=0&&sy<9){
	      if(nx==sx&&ny==sy){
		if(dfs(nx,ny,d+1)==true) return true;
	      }
	    }
	}
      }
  }
  return false;
}
int main(){
  int a,b;

  while(1){
    for(int i=0;i<10;i++) for(int j=0;j<10;j++) mas[i][j]=false;

    cin >> sy >> sx;
    if(sx==0&&sy==0)break;
    cin >> n;
    for(int i=0;i<n;i++){
      cin >> a >> b;
      data[i].second=a;
      data[i].first=b;
    }
    cout << (dfs(sx,sy,0)==true ? "OK" : "NA") << endl;
  }
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
const ull MOD = 1000000007;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
ll digitPoor(ll n)
{
    assert(INT_MAX == 2147483647);
    assert(n >= 0);

    if (n < 10)         return 1;
    if (n < 100)        return 2;
    if (n < 1000)       return 3;
    if (n < 10000)      return 4;
    if (n < 100000)     return 5;
    if (n < 1000000)    return 6;
    if (n < 10000000)   return 7;
    if (n < 100000000)  return 8;
    if (n < 1000000000) return 9;
    return 10;
}
struct p{
  ll x;
  bool b;
};
int main(){
    ll H,W;
    cin>>H>>W;
    
    vector<string> t(H+2);
    fill(ALL(t[0]),'.');
    REP1(i,H){
        t[i]='.';
        string s;
        cin>>s;
        t[i]+=s;
        t[i]+'.';
    }
    
    
    REP1(i,H){
        REP1(j,W){
            if(t[i][j]=='#'&&t[i][j-1]=='.'&&t[i][j+1]=='.'&&t[i-1][j]=='.'&&t[i+1][j]=='.'){
                cout<<"No";return 0;
            } 
            
        }
    }
    cout<<"Yes";
    
    return 0;
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3636
from collections import defaultdict
import heapq

n, m = map(int, input().split())
d = defaultdict(list)

for _ in range(n):
    a, b = map(int, input().split())
    d[a].append(-b)

hq = []
reword = 0

for i in range(1, m + 1):
    if i in d:
        for item in d[i]:
            heapq.heappush(hq, item)
    if hq:
        reword += heapq.heappop(hq)

print(-1 * reword)


Measured memory_bytes: 27676
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>

using namespace std;

int break2(int n){
    int count = 0;
    while(n%2 != 1){
        n = n/2;
        count++;
    }
    return count;
}

int main(){
    int N;
    cin >> N;
    int result_break2 = 0;
    int result = 1;
    for(int i=1; i<=N; i++){
        if(result_break2 < break2(i)){
            result_break2 = break2(i);
            result = i;
        }
    }

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int n;
	while (cin >> n&&n != 0) {
		int a=0, b=0;
		for (int i = 0; i < n; i++) {
			int c, d;
			cin >> c >> d;
			if (c > d) a += (c + d);
			else if (c < d) b += (c + d);
			else {
				a += c;
				b += c;
			}
		}
		cout << a << " " << b << endl;
	}
}

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

using namespace std;
using ll = long long;

#define gc getchar
int getint() { unsigned int c; int x = 0; while (((c = gc()) - '0') >= 10) { if (c == '-') return -getint(); if (!~c) exit(0); } do { x = (x << 3) + (x << 1) + (c - '0'); } while (((c = gc()) - '0') < 10); return x; }
int getstr(char *s) { int c, n = 0; while ((c = gc()) <= ' ') { if (!~c) exit(0); } do { s[n++] = c; } while ((c = gc()) > ' ' ); s[n] = 0; return n; }
template<class T> inline bool chmin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template<class T> inline bool chmax(T &a, T b) { return a < b ? a = b, 1 : 0; }

struct Bridge {
    static const int N = 100;
    struct edge { int to, rv; edge() {} edge(int to, int rv) : to(to), rv(rv) {}  };
    int nv, cnt;
    vector<edge> graph[N];
    int dis[N], low[N], par[N];
    void init(int v = N) {
        nv = v;
        for (v = 0; v < nv; v++) graph[v].clear();
    }
    void add_edge(int u, int v) {
        if (u == v) return;
        int tu = graph[u].size(), tv = graph[v].size();
        graph[u].push_back(edge(v, tv)), graph[v].push_back(edge(u, tu));
    }
    void proc() {
        cnt = 0;
        fill(dis, dis + nv, ~0);
        for (int u = 0; u < nv; u++) if (!~dis[u]) dfs(u, -1, -1);
    }
    void dfs(int u, int p, int pe) {
        dis[u] = low[u] = cnt++, par[u] = p;
        for (int i = 0; i < graph[u].size(); i++) {
            int v = graph[u][i].to;
            if (i == pe) continue;
            if (~dis[v]) {
                low[u] = min(low[u], dis[v]);
            } else {
                dfs(v, u, graph[u][i].rv);
                low[u] = min(low[u], low[v]);
            }
        }
    }
    bool is_bridge(int u, int v) {
        if (dis[u] > dis[v]) swap(u, v);
        return (u == par[v] and dis[v] <= low[v]);
    }
};

int n, m;

int main () {
    n = getint(), m = getint();
    Bridge brg;
    brg.init(n);
    vector<int> us, vs;
    for (auto j = 0; j < m; ++j) {
        const auto u = getint() - 1;
        const auto v = getint() - 1;
        brg.add_edge(u, v);
        us.push_back(u);
        vs.push_back(v);
    }
    brg.proc();
    int res = 0;
    for (auto j = 0; j < m; ++j) {
        if (brg.is_bridge(us[j], vs[j])) ++res;
    }
    cout << res << endl;
    return 0;
}




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

int main() {
  int a1,a2,a3;
  cin >> a1 >> a2 >> a3;
  if(a1+a2+a3>=22){
    cout << "bust" << endl;
  }else{
    cout << "win" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mkp make_pair
#define rep(i,s,f) for(i=s;i<f;i++)
#define db cout<<'h'<<'i'<<endl 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define vi vector<int>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define PI 3.14159265
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)
int arr[space];
int main()
{
    int n,i,j,t,a;
    boost;
    int m,l,r;
    cin>>n>>m;

    rep(i,0,m)
    {
        cin>>l>>r;  
        arr[l]++;
        arr[r+1]--;
    }
    int c=0;
    if(arr[1]==m) c++;
    rep(i,2,n+1)
    {
        arr[i]+=arr[i-1];
        if(arr[i]==m) c++;
    }
    cout<<c;
    return 0;
}



Measured memory_bytes: 640
#include <ext/rope>
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define ll long long
#define ull unsigned long long
typedef vector<vector<ll>> mat;

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

    string s;
    cin >> s;
    
    int dif = 0 , cnt = 0;
    for(auto i : s)
    {
        if(i == 'g') 
        {
            if(dif > 0) cnt++ , dif--;
            else dif++;
        }
        else
        {
            if(dif > 0) dif--;
            else cnt-- , dif++;
        }
    }
    cout << cnt;

    return 0;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

template<typename T>
vector<T> gen_v(size_t a) { return vector<T>(a); }
template<typename T, typename ...Ts>
auto gen_v(size_t a, Ts... ts) { return vector<decltype(gen_v<T>(ts...))>(a, gen_v<T>(ts...)); }
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K; cin >> N >> K;
	vector<int> P(N); rep(i, 0, N) {
		cin >> P[i];
	}

	set<int> st;
	rep(i, 0, K) {
		st.insert(P[i]);
	}

	int ans = 1;
	rep(i, 0, N) {
		if (i + K >= N)break;
		st.erase(P[i]);
		dump(st);
		if (P[i] < *st.begin() && *st.rbegin() < P[i + K]) {
			
		}
		else {
			ans++;
		}
		dump(ans);
		st.insert(P[i + K]);
	}

	vector<int> c(N);
	rep(i, 1, N) {
		if (P[i - 1] < P[i]) {
			c[i] += c[i - 1] + 1;
		}
	}
	dump(c);
	c.push_back(0);
	int cnt = 0;
	rep(i, 1, N + 1) {
		if (c[i - 1] > c[i] && c[i - 1] >= K - 1) {
			cnt++;
		}
	}
	ans -= max(cnt - 1, 0LL);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 15744
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << 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; }
#define int long long

void solve() {
	int n; cin >> n;
    int ok = inf, ng = 0;
    while(ok - ng > 1) {
        int mid = (ok  + ng) / 2;
        if(mid * (mid + 1) / 2 >= n) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    int i = ok;
    while(n > 0 && i > 0) {
        if(i <= n) {
            cout << i << endl;
            n -= i;
        }
        --i;
    }
    return;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 256
def sim(as, max_move = 10000)
  as.sort!
  ans = 0
  while as[-1] > 0 && ans <= max_move
    as.map!{ |a| a+1 }
    as[-1] -= N+1
    as.sort!
    #p as, ans
    ans += 1
  end
  ans <= max_move ? ans : nil
end

N,*as = `dd`.split.map &:to_i
as.map!{ |a| a - N + 1 }

if n = sim(as.clone)
  p n; exit
end

as.sort!
#p as
ms = [0] + as[1..-1].map{ |a| (a-as[0])/(N+1) + 1 }
m = ms.inject(:+)
(0...N).each{ |i| as[i] = as[i] + m - ms[i]*(N+1) }
#p as, m
as.sort!
ans = m

k = (as.min - (N+1))
as.map!{ |a| a - k }
ans += k*N

#p as, ans

p ans + sim(as)



Measured memory_bytes: 2164
#include<bits/stdc++.h>
using namespace std;
#define int long long
bool cmp(pair<int,int> x,pair<int,int> y)
{
    return x.second>y.second;
}
signed main()
{
    int n,m,i,ans=0;
    cin>>n>>m;
    int a[n];
    vector <pair<int,int>> v;
    priority_queue<int,vector<int>,greater<int>> z;
    for(i=0;i<n;i++) {
        cin >> a[i];
        z.push(a[i]);
        ans+=a[i];
    }
    for(i=0;i<m;i++)
    {
        int x,y;
        cin>>x>>y;
        pair<int,int> p;
        p.first=x;
        p.second=y;
        v.push_back(p);
    }
    sort(v.begin(),v.end(),cmp);
    for(i=0;i<m;i++)
    {
        int j;
        for(j=0;j<v[i].first;j++)
        {
            int y=z.top();
            if(y<v[i].second)
            {
                z.pop();
                z.push(v[i].second);
                ans+=(v[i].second-y);
                continue;
            }
            break;
        }
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 3956
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
#define MAX_V 400010
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}

#define INF 1e9+7
#define LLINF 1e18+7
ll MOD=1e9+7;
#define N 1055050
ll dp[50][1<<20];
vector<ll> change(int x){
    vector <ll> v;
    int count=0;
    while(x){
        count++;
        if(x%2){v.pb(count);count=0;}
        x/=2;
    }
    return v;
}
int change2(vector<ll> v){
    ll now=1;
    ll ans=0;
    for(auto e:v){
        rep(i,e)now*=2;
        ans+=now/2;
    }
    return ans;
}
bool judge[N];
ll pw[50];
main(){
    ll n=in();
    ll x[3];
    rep(i,3)x[i]=in();
    int sum=x[0]+x[1]+x[2];
    vector<pair<vector<ll>,ll>> v;
    vector<ll> vvv;
    v.pb({vvv,1ll});
    ll ans=0;
    pw[0]=1;
    rep(i,20)pw[i+1]=pw[i]*2;
    dp[0][0]=1;
    vector<ll> tmp={2,3};
    rep(i,1<<sum){
        vector<ll> s=change(i);
        int state=0;
        int now[3]={};
        rep(kk,s.size()){
            if(state==3)break;
            if(now[state]+s[kk]<x[state])now[state]+=s[kk];
            else if(now[state]+s[kk]==x[state])state++;
            else {state=-1;break;}
        }
        judge[i]=(state==3?1:0);
    }
    rep(i,n){
        rep(k,1<<sum){
            if(dp[i][k]==0)continue;
            rep2(j,1,7){
                vector<ll> s(1,j);
                ll next=(k*pw[j]+pw[j-1])%pw[sum];
                if(!judge[next])
                dp[i+1][next]=(dp[i][k]+dp[i+1][next])%MOD;
            }
            dp[i+1][0]=(dp[i+1][0]+dp[i][k]*3)%MOD;
        }
    }
    ll p=1;
    rep(i,n){
        p=p*10ll%MOD;
    }
    rep(i,1<<sum){
        p=(p-dp[n][i]+MOD)%MOD;
    }
    cout<<p<<endl;
}

Measured memory_bytes: 149888
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,ll> PPI;
typedef pair<ll,P> PIP;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
#define PQ(T) priority_queue<T,vector<T>,greater<T>>
#define PQ2(T) priority_queue<T>
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define REP(i,a,b) for(ll (i)=a;(i)<(ll)(b);++(i))
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n+1)
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) ((x)=min((x),(y)))
#define chmax(x,y) ((x)=max((x),(y)))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
#define DEBUG(x) cerr<<"line ("<<__LINE__<<")  "<<#x<<": "<<x<<endl;
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);

#define N 100010
ll l[N], r[N];
multiset<ll> ls, rs;
ll lo, ro;
ll n;

int main(){
	INIT;
	cin>>n;
	rep(i, n) cin>>l[i]>>r[i];
	ls.insert(-1e16);
	rs.insert(1e16);
	ll res = 0;
	rep(i, n){
		lo -= r[i]-l[i];
		auto itl = ls.end(); --itl;
		auto itr = rs.begin();
		if(l[i]<*itl+lo){
			ll x = *itl+lo;
			res += abs(l[i]-x);
			ls.erase(itl);
			rs.insert(x-ro);
			ls.insert(l[i]-lo);
			ls.insert(l[i]-lo);
		} else if(l[i]>*itr+ro){
			ll x = *itr+ro;
			res += abs(l[i]-x);
			rs.erase(itr);
			ls.insert(x-lo);
			rs.insert(l[i]-ro);
			rs.insert(l[i]-ro);
		} else {
			ls.insert(l[i]-lo);
			rs.insert(l[i]-ro);
		}
		ro += r[i]-l[i];
	}
	cout<<res<<endl;
	return 0;
}


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

#define int long long

signed main() {
        int n;
        cin >> n;
        vector<long long> x(n);
        for (int i = 0; i < n; i ++) cin >> x[i];
        vector<long long> d(n - 1);
        for (int i = 0; i < n - 1; i ++) d[i] = x[i + 1] - x[i];
        long long m, k;
        cin >> m >> k;
        vector<long long> a(m);
        for (int i = 0; i < m; i ++) { 
                cin >> a[i];
                a[i] --;
        }
        vector<long long> s(n - 1);
        for (int i = 0; i < n - 1; i ++) s[i] = i;
        for (int i = 0; i < m; i ++) swap(s[a[i]], s[a[i] - 1]);
        vector<vector<long long> > swp(n - 1, vector<long long> (61));
        for (int i = 0; i < n - 1; i ++) swp[s[i]][0] = i;
        for (int i = 1; i < 61; i ++) { 
                for (int j = 0; j < n - 1; j ++) { 
                        swp[j][i] = swp[swp[j][i - 1]][i - 1];
                }
        }
        //cout << "swap function" << endl;
        //for (int i = 0; i < n - 1; i ++) {
        //        cout << swp[i][0] << ' ';
        //}
        //cout << endl;
        for (int b = 0; b < 61; b ++) {
                if ((k >> b) & 1) {
                        vector<long long> next(n - 1);
                        for (int i = 0; i < n - 1; i ++) next[swp[i][b]] = d[i];
                        for (int i = 0; i < n - 1; i ++) d[i] = next[i];
                }
        }
        long long prev = x[0];
        cout << prev << endl;
        for (int i = 0; i < n - 1; i ++) { 
                prev = d[i] + prev;
                cout << prev << endl;
        }
        return 0;
}                                         


Measured memory_bytes: 55920
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=998244353;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<'\n';}}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}

int main(){
    ll n,s;cin>>n>>s;
    ll ans=0;
    vi dp(s+1);
    vi v(n);
    rep(i,n)cin>>v[i];
    rep(i,n){
        vi ndp=dp;
        if(v[i]<=s)ndp[v[i]]+=i+1;
        rep(j,s+1)if(j+v[i]<=s)ndp[j+v[i]]+=dp[j];
        dp=ndp;
        ans+=dp[s];
        ans%=mod;
        rep(j,s)dp[j]%=mod;
    }
    out(ans);
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
// #include "Template.cpp"

void solve() {
    int n; cin >> n;
    vector<int> arr(n, 0);
    for(int i = 0; i < n; i ++) cin >> arr[i];
    sort(arr.begin(), arr.end());
    int ans = 1e9;
    for(int i = arr[0]; i <= arr[n-1]; i ++) {
        int temp = 0;
        for(int j = 0; j < n; j ++) {
            temp += (arr[j] - i) * (arr[j] - i);
        }
        ans = min(temp, ans);
    }
    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while(t --) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3684
#include <iostream>
#include <bits/stdc++.h> 
using namespace std;
typedef long long int ll;
// #define MAX 10000000000000 

ll multiply(ll x, ll res[], ll res_size);
  

// void factorial(ll n,ll b) 
// { 
//     ll res[MAX]; 
  
//     // Initialize result 
//     res[0] = 1; 
//    ll res_size = 1; 
  
//     // Apply simple factorial formula n! = 1 * 2 * 3 * 4...*n 
//     for (ll x=2; x<=n; x++) 
//         res_size = multiply(x, res, res_size); 
  
//     cout << "Factorial of given number is \n"; 
//     for (ll i=res_size-1; i>=0; i--) 
//         cout <<  res[i]%b; 
// } 
  



 
ll MAX = 1e9+7;
int main() {
    ll n; 
    cin >> n;
    ll n1 = 1, n2 = 1, ans = 1;
    ll b=10;
    for(int i=0; i<n; i++) {
        n1 =n1 *b;
        n2 =n2*(b-1);
        ans =ans*( b-2);
        n1 = n1%MAX;
        n2 = n2%MAX;
        ans =ans% MAX;
    }
    n2 = n2*2;
    n2 = n2% MAX;
    cout << (n1 - n2 + ans + MAX) % MAX << endl;

  return 0;     
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

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

	ll P, Q, R;
	ll ans = 0;

	cin >> P >> Q >> R;

	ans = P + Q + R;
	ll max = P;
	if (max < Q) max = Q;
	if (max < R) max = R;

	ans -= max;

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

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
--import qualified Data.Sequence as Sequence
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
--import Data.Array
--import Data.Array.Unboxed
import Data.Array.IArray
import Data.Array.MArray
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe

-- templete
readInt = read :: String -> Int
readInteger = read :: String -> Integer
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getInteger = readLn :: IO Integer
getIntegers = map readInteger . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
binMap :: (a -> a -> b) -> [a] -> [b]
binMap f (x:xs@(y:_)) = f x y : binMap f xs
binMap _ _ = []
splitRec :: Int -> [a] -> [[a]]
splitRec _ [] = []
splitRec n xs = let (y,ys) = splitAt n xs in y : splitRec n ys
infixl 7 `divCeil`
divCeil :: Integral a => a -> a -> a
x `divCeil` y = (x+y-1) `div` y
-- templete

type Food = (String, Int, Int)
getName :: Food -> String
getName (f,_,_) = f
getWeight :: Food -> Int
getWeight (_,w,_) = w
getLimit :: Food -> Int
getLimit (_,_,s) = s

f :: (Int,Int,Int,[Food]) -> [Food] -> [(Int,[String])]
f (g, i, t, l) [] = [(g, map getName l)]
f (g, i, t, l) fs = ff [] fs
  where
    ff yys [] = []
    ff yys (x:xs) = let w = getWeight x in let limit = getLimit x in if (t<=limit) then f (g+i*w, i+1, t+w, (x:l)) (yys ++ xs) ++ ff (x:yys) xs else ff (x:yys) xs
    
calc :: [Food] -> [String]
calc fs = snd $ maximumBy (comparing fst) $ f (0,1,0,[]) fs

main = do
    n <- getInt
    when (n/=0) $ do
        fs <- map ((\[f,w,s] -> (f, readInt w, readInt s)) . words) <$> replicateM n getLine
        mapM_ putStrLn $ calc fs
        main
    



Measured memory_bytes: 185836
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 410;
ll a[maxn], dp[maxn][maxn], n;
ll pref[maxn];

ll solve(int li, int ri) {
	if(dp[li][ri] != -1) return dp[li][ri];

	if(li == ri) return dp[li][ri] = 0LL;

	dp[li][ri] = LLONG_MAX;
	for(int i=li+1;i<=ri;i++) {
		dp[li][ri] = min(dp[li][ri], solve(li, i-1) + solve(i, ri) + pref[ri] - pref[li-1]);
	}
	return dp[li][ri];
}

int main() {
	cin>>n;
	for(int i=1;i<=n;i++) {
		cin>>a[i];
		pref[i] = pref[i-1] + a[i];
	}

	memset(dp, -1, sizeof(dp));
	cout<<solve(1, n)<<"\n";
}

Measured memory_bytes: 1536
#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 ll INF = 1e18;
const int MX = 2005;

int main() {
  ll a,b,n;
  cin >> a >> b >> n;
  ll ans = min(n,b-1) * a / b;
  cout << ans << endl;
}

Measured memory_bytes: 3588
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
ld EPS = 1e-12;
int INF = numeric_limits<int>::max() / 2;
int MOD = 1e9 + 7;
#define rep(i,n) for(int i=0;i<n;i++)

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

    int H, W, h, w;
    int result;
	cin >> H >> W >> h >> w;

    result = H * W - h * W - w * H + h * w;
	
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 256
/**
* Sources: various
*/

#pragma GCC optimize("O3")
#pragma GCC target("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
template<typename T>
ostream& operator<< (ostream& out, const pair<T, T>& v) {
    out << "{" << v.first << ", " << v.second << "}";
    return out;
}

template<typename T>
ostream& operator<< (ostream& out, const vector<T>& v) {
    out << "[";
    size_t last = v.size() - 1;
    for(size_t i = 0; i < v.size(); ++i) {
        out << v[i];
        if (i != last) 
            out << ", ";
    }
    out << "]";
    return out;
}

template<typename T>
ostream& operator<< (ostream& out, const set<T>& v) {
    out << "[";
    auto pen = v.end();
    pen--;
    for (auto it = v.begin(); it != v.end(); it++){
		out << *it;
		if (it != pen){
			out << ", ";
		}
	}
	out << "]";
    return out;
}

template<typename T>
ostream& operator<< (ostream& out, const Tree<T>& v) {
    out << "[";
    auto pen = v.end();
    pen--;
    for (auto it = v.begin(); it != v.end(); it++){
		out << *it;
		if (it != pen){
			out << ", ";
		}
	}
	out << "]";
    return out;
}
int a[200000];
int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	Tree<pii> T;
	int N; cin >> N;
	int hf = N/2 - 1;
	for (int i = 0; i < N; i++){
		cin >> a[i];
		T.insert(make_pair(a[i], i));
	}
	for (int i = 0; i < N; i++){
		T.erase(T.find(make_pair(a[i], i)));
		cout << (*T.find_by_order(hf)).first << '\n';
		T.insert(make_pair(a[i], i));
	}
}


// read!read!read!read!read!read!read!
// ll vs. int!


Measured memory_bytes: 15488
fun main(args: Array<String>) {
    val s = readInputLine().toCharArray()
    val buf = mutableListOf<Int>()
    
    for (c in s) {
        when (c) {
            '0' -> buf.add(0)
            '1' -> buf.add(1)
            else -> if (buf.size > 0) buf.removeAt(buf.lastIndex)
        }
    }
    
    println(buf.joinToString(""))
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 33812
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int[] dish = new int[5];
		boolean[] t = new boolean[5];
		int max = 0;
		int min = 0;
		int time = 0;
		Scanner sc = new Scanner(System.in);
		//최대 최소 인덱스 구함
		for (int i = 0; i < dish.length; i++) {
			dish[i] = sc.nextInt();
			if(dish[i]%10==0)
				continue;
			max = dish[max]%10>dish[i]%10?max:i;
			min = dish[min]%10<dish[i]%10?min:i;
		}
		if(max == min){
			max = 0;
			min = 4;
		}
		t[max] = t[min] = true;
		
		time += (int)Math.ceil((double)dish[max]/10)*10;
		for (int i = 0; i < 5; i++) {
			if(!t[i])
				time += (int)Math.ceil((double)dish[i]/10)*10;
		}
		time += dish[min];
		
		System.out.println(time);
	}

}

Measured memory_bytes: 20948
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <bitset>

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define INF 2000000000
#define rep(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> P;
const ll MOD=1000000007;
using Graph = vector<vector<int>>;

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


ull gcd(ull a, ull b) {
    while (a % b != 0) {
        ull tmp = b;
        b = a % b;
        a = tmp;
    }
    return b;
}

ull lcm(ull a, ull b) {
    if (a == b) return b;
    ull g = gcd(a, b);
    return (a / g) * b;
}


int a[100005][3];
int dp[100005][3];
int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }
    dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];
    for (int i = 1; i < n; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (j != k) {
                    chmax(dp[i][j], dp[i - 1][k] + a[i][j]);
                }
            }
        }
    }
    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main() {

	int n, m;
	long long ans = 0;

	vector<pair<long long, long long> > pairs;

	cin >> n >> m;

	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		pairs.push_back(make_pair(a, 1));
	}

	for (int i = 0; i < m; i++) {
		long long b, c;
		cin >> b >> c;
		pairs.push_back(make_pair(c, b));
	}

	sort(pairs.begin(), pairs.end(), greater < pair<int, int>>());


	int i = 0;

	while (1) {
		if (n - pairs[i].second >= 0) {
			n = n - pairs[i].second;
			ans += pairs[i].first * pairs[i].second;
			i++;
		} else {
			ans += pairs[i].first * n;
			break;
		}
		// cout << ans << endl;
	}

	cout << ans << endl;
}


Measured memory_bytes: 6384
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N,K = inpl()

if K%2 == 1:
	print((N//K)**3)
else:
	ans = (N//K)**3
	tmp = N//K
	if N%K >= K//2:
		tmp += 1
	ans += tmp**3
	print(ans)


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

int main() {
    int house[4][3][10] = {};
    int b, f, r, v;
    int n;

    cin >> n;

    for(int i=0; i<n; i++){
        cin >> b >> f >> r >> v;
	house[b-1][f-1][r-1] += v;
    }

    for(int i=0; i<4; i++){
        for(int j=0; j<3; j++){
	    for(int k=0; k<10; k++){
	        cout << ' ' << house[i][j][k] << flush;
		if(k==9) cout << endl;
	    }
	}
	if(i!=3){
	    cout << "####################" << endl;
	}
    }
}

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

using namespace std;

static const int MAX = 36;

int main(void)
{
	int N, minj;
	bool flag = true;
	string A[MAX], B[MAX];
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> A[i];
		B[i] = A[i];
	}
	//??????????????????
	for(int i=0;flag;i++){
		flag = false;
		for(int j=N-1;j>i;j--){
			if (A[j][1] < A[j-1][1]){
				swap(A[j], A[j-1]);
				flag = true;
			}
		}
	}
	for(int i=0;i<N;i++){
		if (i > 0) cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << "Stable" << endl;
	//???????????????
	for(int i=0;i<N;i++){
		minj = i;
		for(int j=i+1;j<N;j++){
			if (B[j][1] < B[minj][1]){
				minj = j;
			}
		}
		if (minj != i) swap(B[i], B[minj]);
	}
	for(int i=0;i<N;i++){
		if (i > 0) cout << " ";
		cout << B[i];
	}
	flag = false;
	cout << endl;
	for(int i=0;i<N;i++){
		if (A[i] != B[i]){
			flag = true;
			break;
		}
	}
	if (flag){
		cout << "Not stable" << endl;
	}else{
		cout << "Stable" << endl;
	}
	return 0;
}

Measured memory_bytes: 1212
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<functional>

using ll = long long;

using namespace std;

ll mod = 1000000007;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= mod;
	if (n % 2 == 1)t *= a;
	return t % mod;
}


int main() {
	double r;
	cin >> r;
	double ans = 2 * M_PI*r;
	printf("%.12lf\n", ans);
	return 0;
}


Measured memory_bytes: 3752
/**
 * Created by hiramekun at 23:23 on 2020-03-28.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll k, n;
    cin >> k >> n;
    vl a(n);
    cin >> a;

    vl d(n);
    rep(i, n - 1) {
        d[i] = a[i + 1] - a[i];
    }
    d[n - 1] = k - a.back() + a[0];
    ll ans = accumulate(all(d), 0LL) - *max_element(all(d));
    cout << ans << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 3328
#define M(a,b)(a>b?a:b)
T[999],X[999],q,n,A,a,B,b,h,m,p;N(){if(~T[0])for(q=1;q<999;q++)if(~T[q])X[q]+=1440-M(T[q],T[0]),T[q]=-1;T[0]=-1;}main(){for(;scanf("%d",&n),n;printf("%d\n",m)){for(memset(T,0xff,3996),memset(X,0,3996),A=0;n--;){if(scanf("%d/%d%d:%d%s%d",&a,&b,&h,&m,&p,&p),A-a||B-b)N(),A=a,B=b;if(h=h*60+m,~T[p]){if(p==0){for(q=1;q<999;q++)if(~T[q])X[q]+=h-M(T[q],T[0]);}else if(~T[0])X[p]+=h-M(T[p],T[0]);T[p]=-1;}else T[p]=h;}for(N(),m=0,p=1;p<999;p++)m=M(m,X[p]);}exit(0);}

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

using namespace std;

int main(){
    string s;
    cin >>s;
    
    long long int count = 0;
    long long int total = 0;
    for(int i = 0;i<s.length();i++){
        if(s[i] == 'B'){
            count++;
        }
        else if(s[i] =='W'){
            total += count;
        }
    }
    cout << total <<"\n";
    return 0;
}


Measured memory_bytes: 640
<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
$d = trim(fgets(STDIN));
 
// ？
$ans = 0;
$ans = min([$a, $b]) + min([$c, $d]);
 
echo($ans."\n");

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int N, L;
int a[100010];

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

    rep(i, N) cin >> a[i];

    rep(i, N - 1) {
	if (a[i] + a[i + 1] >= L) {
	    puts("Possible");

	    vi ans;
	    ans.pb(i + 1);

	    for (int j = i - 1; j >= 0; --j) {
		ans.pb(j + 1);
	    }

	    for (int j = i + 1; j < N - 1; ++j) {
		ans.pb(j + 1);
	    }

	    reverse(ALL(ans));
	    assert(ans.size() == N - 1);
	    for (int p : ans) cout << p << endl;
	    return 0;
	}
    }
    puts("Impossible");

    return 0;
}

Measured memory_bytes: 1784
let n, k = Scanf.scanf " %d %d" @@ fun a b -> a, b
let f a = a * a * a
let m = 2 * n / k
let _ = Printf.printf "%d\n" @@ if k mod 2 = 1 then f @@ n / k else let e = m / 2 in f e + f (m - e)

Measured memory_bytes: 384
N, M, Q = map(int, input().split())
num = [[0]*500 for _ in range(500)]

for i in range(M):
  L,R = map(int, input().split())
  num[R-1][L-1] += 1

cum = [[0]*500 for _ in range(500)]
for r in range(500):
  cum[r][r] = num[r][r]
for r in range(1,500):
  for l in range(r-1,-1,-1):
    cum[r][l] = cum[r-1][l]+cum[r][l+1]-cum[r-1][l+1]+num[r][l]
#print(cum)
ans = []
for i in range(Q):
  P,Q = map(int, input().split())
  ans.append(cum[Q-1][P-1])
print(*ans,sep='\n')

Measured memory_bytes: 67672
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 10
#else
#define SIZE 10
#endif

int H,W,K;
string M[SIZE];

bool ok(int i, int j) {
    bitset<20> bh(i),bw(j);
    int cnt = 0;
    REP(h,H)REP(w,W) {
        if (bh[h]||bw[w]) continue;
        if (M[h][w]=='#') cnt++;
    }
    return cnt==K;
}

void solve() {
    cin>>H>>W>>K;
    REP(i,H)cin>>M[i];
    int ans = 0;
    REP(i,1LL<<H)REP(j,1LL<<W) {
        if (ok(i,j)) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3672