akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <chrono>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <unordered_set>
#include <vector>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <fstream>
#include <functional>
#include <map>
#include <deque>
#include <string.h>
#include <set>

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? (-a) : (a))
#define YesNo(flag) ((flag) ? "Yes\n" : "No\n")
#define YESNO(flag) ((flag) ? "YES\n" : "NO\n")

constexpr auto NMAX = (int)2e3 + 20;
constexpr auto INF_ULL = 18446744073709551615;
constexpr auto INF_INT = 2147483647;
constexpr auto PI = 3.14159265359;
constexpr auto MOD = 1000000007;

using namespace std;

typedef unsigned long long ull;

char c;

int main()
{
	cin >> c;
	if (c >= 'A' && c <= 'Z') {
		cout << 'A';
	}
	else {
		cout << 'a';
	}
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    int n;
    cin>>n;
    int A=0;
    int T=0;
    for(int i=0;i<n;i++){
        int a,t;
        cin>>a>>t;
        if(i==0){
            A=a;
            T=t;
        }
        else{
            int e=(A-1)/a+1;
            int f=(T-1)/t+1;
            int g=max(e,f);
            A=a*g;
            T=t*g;
        }
    }
    cout<<A+T<<endl;
}


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

int main(){
  vector<vector<int>> bi(3,vector<int>(3));
  for(int i=0;i<3;i++)for(int k=0;k<3;k++)cin>>bi[i][k];
  
  int n;cin>>n;
  vector<vector<int>> an(3,vector<int>(3,0));
  for(int i=0;i<n;i++){
    int b;cin>>b;
    for(int k=0;k<3;k++)for(int j=0;j<3;j++){
      if(b==bi[k][j])an[k][j]=1;
    }
  }
  if(an[0][0]*an[0][1]*an[0][2])cout<<"Yes"<<endl;
  else if(an[1][0]*an[1][1]*an[1][2])cout<<"Yes"<<endl;
  else if(an[2][0]*an[2][1]*an[2][2])cout<<"Yes"<<endl;
  else if(an[0][0]*an[1][0]*an[2][0])cout<<"Yes"<<endl;
  else if(an[0][1]*an[1][1]*an[2][1])cout<<"Yes"<<endl;
  else if(an[0][2]*an[1][2]*an[2][2])cout<<"Yes"<<endl;
  else if(an[0][0]*an[1][1]*an[2][2])cout<<"Yes"<<endl;
  else if(an[2][0]*an[1][1]*an[0][2])cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    string S;cin >> S;int N = S.size();
    ll ans = N;
    REP(i,S.size()){
        if(S[i] != S[i+1]) ans = min(ans,max(i+1,N-1-i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
 
#define REP(i,b,n) for(int i=b;i<n;++i)
#define REPR(i,b,n) for(int i=n-1;i>=b;--i)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))
#define EACH(i, c) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define BIT(n, b) ((n>>b) & 1)
#define PI acos(-1.0)

#define INF 1<<14

using namespace std;

static const double EPS = 1e-9;
typedef pair<int, int> pii;
typedef long long ll;

int N, a, b, t;
int amat[22][22]={{0}};
int dist[22][22]={{0}};
int brg_count[22]={0, INF, 0};

void warshall_floyd(){
	
	for(int i=1; i<=N; ++i)
		for(int j=1; j<=N; ++j)
			dist[i][j] = (amat[i][j]>0?amat[i][j]:INF);
	
	for(int k=1; k<=N; ++k)
		for(int i=1; i<=N; ++i)
			for(int j=1; j<=N; ++j)
				dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
	
	return;
}

int solve(){
	
	warshall_floyd();
	
	int sum = 0;
	
	for(int i=1; i<=N; ++i){
		for(int j=i; j<=N; ++j){
			
			if( amat[i][j] && brg_count[i]>1 && brg_count[j]>1 )
				sum += 2*amat[i][j];
		}
	}
	
	int res = sum;
	
	for(int k=2; k<=N; ++k){
		if( brg_count[k] > 1 )
			res = min(res, sum - dist[1][k]);
	}
	
	return res<sum ? res : 0;
}	

int main(){
		
	while(cin >> N, N){
		
		CLR(amat);
		CLR(dist);
		CLR(brg_count);
		brg_count[1] = INF;
		
		for(int i=0; i < N-1; ++i){
			cin >> a >> b >> t;
			amat[a][b] = amat[b][a] = t;
			brg_count[a]++;
			brg_count[b]++;
		}
		
		cout << solve() << endl;
	}
	
	return 0;
}

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

int main() {
    int q, h, s, d; cin >> q >> h >> s >> d;
    int n; cin >> n;

    h = min(h, 2 * q);
    s = min(s, 2 * h);
    d = min(d, 2 * s);
    
    long long ans = 1LL * d * (n / 2) + 1LL * s * (n % 2);
    cout << ans << "\n";
}   

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <array>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>

#define INT_MAX 2000000000
#define MOD 1000000007
#define ll long long
#define rep(i,a,b) for(i = (a); i < (b); i++)
#define bitget(a,b) (((a) >> (b)) & 1)

using namespace std;



int main() {
	int i, j, k;
	int n;
	cin >> n;
	int a[200000];
	int b[200000] = {};
	rep(i, 0, n)
		cin >> a[i];
	int m = 0;
	for (i = n - 1;i > -1;i -= 2) {
		b[m] = a[i];
		m++;
	}
	for (i = n % 2;i < n;i += 2) {
		b[m] = a[i];
		m++;
	}
	rep(i, 0, n) {
		cout << b[i];
		if (i != n - 1) {
			cout << " ";
		}
	}
	cout << endl;
	return 0;
}

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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int n, x;
    cin >> n >> x;
    vint m(n);
    rep(i, n)
    {
        cin >> m[i];
    }

    int sum = 0;
    int mi = INF;
    rep(i, n)
    {
        sum += m[i];
        mi = min(mi, m[i]);
    }

    cout << n + (x - sum) / mi << endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

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

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 200000;
const int N = 100;

int A[MAX];

int main() {
	int n;cin>>n;
	rep(i,n) cin>>A[i];
	int num=0;
	rep(i,n) if(A[i]==num+1) num++;
	if(num>0) cout<<n-num<<endl;
	else cout<<-1<<endl;
}


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

int main() {
  long N;
  cin >> N;
  vector<long> X(N);
  for (long i = 0; i < N; i++) cin >> X.at(i);
  long ans = 2e18;
  for (long i = 0; i <= 100; i++) {
    long tmp = 0;
    for (long j = 0; j < N; j++) {
      tmp += (X.at(j) - i) * (X.at(j) - i);
    }
    ans = min(ans, tmp);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <utility>
#include <map>

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)
#define all(c) begin(c),end(c)
#define vmax(c) *max_element(all(c))
#define vmin(c) *min_element(all(c))
 
template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

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

template<typename T1, typename T2>
std::ostream &operator<<(std::ostream &out, const std::map<T1, T2>& map)
{
    for (typename std::map<T1, T2>::const_iterator it = map.begin();
         it != map.end();
         ++it)
    {
        out << (*it);
    }
    return out;
}

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vll;

const long long INF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9; 

// 2次元配列を作る
// vector<vi> my_vector(n, vi(m, 0));

// 多次元配列の dump
// for (auto v : my_vector) {
//     cout << v;
// }

int main(void){
    ll n, w;
    scanf("%lld", &n);
    scanf("%lld", &w);
    // printf("%lld\n", n);
    // printf("%lld\n", w);

    vector<pair<ll, ll>> items(n, make_pair(0, 0));
    REP(i, n) {
        ll item_weight, item_value;
        scanf("%lld", &item_weight);
        scanf("%lld", &item_value);
        items[i].first = item_weight;
        items[i].second = item_value;
        // cout << items[i];
    }

    // cout << endl;
    map<ll,ll> dp{
        {w, 0},
    };
    REP(i, n) {
        // cout << "==== ";
        ll weight = items[i].first;
        ll value = items[i].second;
        // cout << weight << ',' << value << endl;
        for (auto it = dp.lower_bound(weight); it != dp.end(); ++it) {

            // cout << "--" << endl;
            ll newWeight;
            ll newValue;
            newWeight = (*it).first - weight;
            newValue = (*it).second + value;

            // cout << *it << endl;
            // cout << newWeight << ',' << newValue << endl;

            if (dp.count(newWeight) > 0) {
                ll compareValue = dp[newWeight];
                dp[newWeight] = max(newValue, compareValue);
            } else {
                dp[newWeight] = newValue;
            }
        }
        // cout << dp << endl;
    }
    pair<ll,ll> max_value = *max_element(dp.begin(), dp.end(), [](const pair<ll, ll>& a, const pair<ll, ll>& b) {
        return a.second < b.second;
    });

    // cout << max_value << endl;
    printf("%lld", max_value.second);
    return 0;
}


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

long long n, k;
vector<long long> w;

int f(long long p) {
  // 荷物の数
  int count = 0;
  for (int j = 0; j < k; j++) {
    long long sum = 0;
    while (sum + w[count] <= p) {
      sum += w[count];
      count++;
      // 全部詰めたらnを返す
      if (count == n) {
        return n;
      }
    }
  }
  // 詰めた個数を返す
  return count;
}

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

  w.resize(n);  
  for (int i = 0; i < n; i++) {
    cin >> w[i];
  }

  // Pを二分探索で決める
  long long left = 0;
  long long right = 100000 * 10000;
  long long mid = 0;

  while (1 < right - left) {
    mid = (left + right) / 2;
    // midをpとすると、何個荷物が詰めるか
    int v = f(mid);
    if (n <= v) {
      // 詰めた個数がn以上の場合は、midを上限にする
      right = mid;
    } else {
      // 詰めた個数がn未満の場合は、midを下限にする
      left = mid;
    }
  }

  cout << right << endl;

  return 0;

}


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

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

const int N = (int) 1e6 + 7;
int n, sumtop;

struct T {
  int o;
  int mn;
};

bool cmp1(T a, T b) {
  return a.mn > b.mn;
}

bool cmp2(T a, T b) {
  return a.o > b.o;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  vector<T> a, b;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    int o = 0, top = 0, mn = 0;
    for (auto &ch : s) {
      if (ch == '(') {
        top++;
      } else {
        top--;
      }
      mn = min(mn, top);
      if (ch == '(') {
        o++;
      } else {
        if (o) {
          o--;
        }
      }
    }
    o = top - mn;
    if (o >= -mn) {
      a.push_back({o, mn});
    } else {
      b.push_back({o, mn});
    }
    sumtop += o + mn;
  }
  if (sumtop != 0) {
    cout << "No\n";
    return 0;
  }
  sort(a.begin(), a.end(), cmp1);
  sort(b.begin(), b.end(), cmp2);
  int cur = 0;
  for (auto &it : a) {
    if (cur + it.mn < 0) {
      cout << "No\n";
      return 0;
    }
    cur += it.o + it.mn;
  }
  for (auto &it : b) {
    if (cur + it.mn < 0) {
      cout << "No\n";
      return 0;
    }
    cur += it.o + it.mn;
  }
  cout << "Yes\n";
  return 0;
}


Measured memory_bytes: 11280
/*                             //
         frostbyte02
//                             */
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=a; i<=b; i++)
#define LLFOR(i,a,b) for (ll i=a; i<=b; i++)
#define FORD(i,a,b) for (int i=a; i>=b; i--)
#define fi first
#define se second
#define pb push_back
#define fastio {ios_base::sync_with_stdio(false); cin.tie(0);}
#define sqr(x) (x)*(x)
#define sqrmod(x) (((x)%MOD)*((x)%MOD))%MOD

using namespace std;
const int MOD = 1e9+7;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;

int main()                                
{
        fastio
        int a, b; cin >> a >> b;
        cout << max(a + a - 1, max(b + b - 1, a + b));
        return 0;  
}


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

using namespace std;

const long long M = 1e9 + 7;
int n , m , c = 0 ;
char grid[1000][1000];
int dp[1001][1001];
int visited[1001][1001];
bool ok(int i , int j){
    if(i < n && j < m && grid[i][j] != '#')return true;
    return false;
}
long long dfs(int i , int j){
    if(i == n - 1 && j == m - 1)return 1;
    if(!ok(i , j))return  0;
    if(visited[i][j] != 0)return (dp[i][j]);
    visited[i][j]=1;
    dp[i][j] += (dfs(i + 1, j) + dfs(i , j + 1))%M;
    return dp[i][j];
}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>m;
    for(int i = 0 ; i < n; ++i){
        cin>>grid[i];
    }
   cout<<dfs(0,0);
    
}

 

Measured memory_bytes: 9216
n = int(input())
list_a = list(map(int, input().split(" ")))
target = sum(list_a) / n
if target - int(target) >= 0.5:
  target = int(target) + 1
else:
  target = int(target)
cost = 0
for one_a in list_a:
  cost += (one_a - target) ** 2
print(cost)

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

int sum(int x) {
	int s = 0;
	while (x > 0) {
		s += x % 10;
		x = x / 10;
	}
	return(s);
}

int main()
{
	int N;
	cin >> N;
	if (N % sum(N) == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#define ll long long int
#define ld long double
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int a,b,c;
    cin>>a>>b>>c;
    	if(a==b && a!=c)
      cout<<"Yes";
  	else if(a==c && a!=b)
      cout<<"Yes";
  else if(b==c && a!=b)
    cout<<"Yes";
  else
    cout<<"No";
    
    
	return 0;
}	

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
    long long int x;
    cin >> x;
    long long int res=0;
    res=(x/500)*1000;
    x%=500;
    res+=(x/5)*5;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if (a > b) {
      cout << a - 1 << '\n';
    } else {
      cout << a << '\n';
    }

    return 0;
}


Measured memory_bytes: 256
import itertools

def main():
    N = int(input())
    P = tuple(map(int, input().split()))
    Q = tuple(map(int, input().split()))

    l = [i for i in range(1, N+1)]
    p = list(itertools.permutations(l, N))

    print(abs(p.index(P) - p.index(Q)))

if __name__ == '__main__':
    main()

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

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

    int d = 0;
    int xi;
    for (int i = 0; i < N; i++) {
        scanf("%d", &xi);
        d += min(xi, abs(xi - K)) * 2;
    }
    cout << d << endl;

    return 0;
}

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

using namespace std;

int main() {
    int n,x,t;
    cin>>n>>x>>t;
    int k=0,ans=0;
    while(k<n){
        k+=x;
        ans+=t;
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3628
def binary_search(l, r, arr, val)
  if l == r then
    return l
  else
    m = (l + r)/2
    if val == arr[m] then
      return m + 1
    elsif val < arr[m] then
      return binary_search(l, m,arr, val)
    else
      return binary_search(m+1, r,arr, val)
    end
  end
end

MAX = 999999
sqrt_max = Math.sqrt(MAX).ceil

prime = [2]
arr = Array.new(MAX){nil}
i = 3
while i <= MAX
  arr[i] = i
  i += 2
end

0.upto(sqrt_max){|i|
  next unless arr[i]
  prime << arr[i]
  j = it = arr[i]
  while j <= MAX
    arr[j] = nil
    j += it*2
  end
}
prime += arr.compact!

while n = gets
  #binary search
  puts binary_search(0, prime.size, prime, n.to_i)
end

Measured memory_bytes: 16400
let cnt n =
  let rec f n' c = if n' mod 2 = 1 then c else f (n' / 2) (c + 1) in
  f n 0

let solve n =
  let rec f i ans =
    if i > n then ans
    else let tmp = Scanf.scanf "%d " cnt in f (i + 1) (min ans tmp)
  in
  f 1 max_int

let () = Scanf.scanf "%d\n" solve |> Printf.printf "%d\n"

Measured memory_bytes: 512
//BROWNIE TK

#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()
#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en
#define le length()
#define mp make_pair
#define mt make_tuple
#define F first
#define S second

#define forz(i, n) for (int i = 0; i < n; i++)
#define forzm(i, m, n) for (int i = m; i < n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rforzm(i, m, n) for (int i = n - 1; i >= m; i--)
#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define osetlli tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order
using namespace std;

/*STD fucntions*/
lli power(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        //y must be even now
        y = y >> 1; //y=y/2
        x = (x * x) % p;
    }
    return res;
}
lli gcd(lli a, lli b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
lli lcm(lli a, lli b)
{
    return a * b / gcd(a, b);
}
lli modi(lli a, lli m)
{
    // fermat little thm where m is prime
    return power(a, m - 2, m);
}
/*CODE BEGINS*/
int main()
{
    kira;
    lli n,m;
    cin>>n>>m;
    priority_queue<lli>pq;
    vector<pair<lli,lli>>v;
    lli a,b;
    forz(i,n)
    {
        cin>>a>>b;
        v.pb({a,b});
    }
    sort(all(v));
    lli in=0;
    lli ans=0;
    for(int i=1;i<=m;i++)
    {
        while(v[in].F<=i&&in<n)
        {
            pq.push(v[in].S);
            in++;
        }
        if(!pq.empty())
        {
            ans+=pq.top();
            pq.pop();
        }
    }
    cout<<ans;
    return 0;
}

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

int main(){
    ll n,m;
    cin >> n >> m;
    ll ans = 0;
    if(n==1&&m==1) ans = 1;
    else if(n==1||m==1) ans = n*m-2;
    else ans = (n-2)*(m-2);
    COUT(ans);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	int k;
	cin >> k;
	ll result = 0;
	REP(a, k) {
		REP(b, k) {
			REP(c, k) { result += gcd(a + 1, gcd(b + 1, c + 1)); }
		}
	}
	cout << result << endl;
	return 0;
}


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

main(){
  int A, B, x;
  cin >> A >> B;
  
  for(; A<=B; A++){
    if(A/10000 == A%10 && A%10000/1000 == A%100/10)
      x++;
  }
  cout << x << endl;
}

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

using namespace std;

int main()
{
	int n, m, l;
	cin >> n >> m >> l;
	vector< vector<int> > a(n, vector<int>(m, 0));
	vector< vector<int> > b(m, vector<int>(l, 0));
	vector< vector<long> > c(n, vector<long>(l, 0));
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < m; j++)
		{
			cin >> a[i][j];
		}
	}
	for (int j = 0; j < m; j++)
	{
		for (int k = 0; k < l; k++)
		{
			cin >> b[j][k];
		}
	}
	for (int i = 0; i < n; i++)
	{
		for (int k = 0; k < l; k++)
		{
			for (int j = 0; j < m; j++)
			{
				c[i][k] += a[i][j] * b[j][k];
			}
		}
	}
	for (int i = 0; i < n; i++)
	{
		for (int k = 0; k < l; k++)
		{
			cout << c[i][k];
			if (k == l - 1)
			{
				cout << endl;
			}
			else
			{
				cout << " ";
			}
		}
	}
    return 0;
}


Measured memory_bytes: 3160
A = list()
for _ in range(3):
    a1, a2, a3 = list(map(int, input().split()))
    A.append(a1)
    A.append(a2)
    A.append(a3)

N = int(input())

for _ in range(N):
    b = int(input())
    for i in range(len(A)):
        if A[i] == b:
            A[i] = 0

if sum(A[0:3]) == 0 or sum(A[3:6]) == 0 or sum(A[6:9]) == 0:
    print("Yes")
elif A[0] + A[3] + A[6] == 0 or A[1] + A[4] + A[7] == 0 or A[2] + A[5] + A[8] == 0:
    print("Yes")
elif A[0] + A[4] + A[8] == 0 or A[2] + A[4] + A[6] == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define MOD 1000000007
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

void mod( ll &n, ll m=MOD ){ n%=m,n+=m,n%=m; }

const int MAXN = 1e5+5;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

ld prob[303][303][303], ev[303][303][303];

int main() 
{
    fastio();

    int n;
    cin>>n;
    int cnt[4]={};
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        cnt[x]++;
    }
    prob[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;

                ld p_waste = (ld) ( n - (a+b+c) )/n;
                ld ev_waste = p_waste / ( 1 - p_waste ) + 1;
                ev[a][b][c] += ev_waste*prob[a][b][c];

                // push dp from dp[a][b][c]

                // remove 1 -> dp[a-1][b][c]
                if( a != 0 )
                {
                    ld p_go = (ld) a / (a+b+c);
                    prob[a-1][b][c] += prob[a][b][c]*p_go;
                    ev[a-1][b][c] += ev[a][b][c]*p_go;
                }

                // remove 2 -> dp[a+1][b-1][c]
                if( b != 0 )
                {
                    ld p_go = (ld) b / (a+b+c);
                    prob[a+1][b-1][c] += prob[a][b][c]*p_go;
                    ev[a+1][b-1][c] += ev[a][b][c]*p_go;
                }

                // remove 3 -> dp[a][b+1][c-1]
                if( c != 0 )
                {
                    ld p_go = (ld) c / (a+b+c);
                    prob[a][b+1][c-1] += prob[a][b][c]*p_go;
                    ev[a][b+1][c-1] += ev[a][b][c]*p_go;
                }
            }
        }
    }
    cout<<fixed<<setprecision(12)<<ev[0][0][0],nl;

    return 0;
}

Measured memory_bytes: 649600
#include <iostream>

using namespace std;

int main(int argc, char* argv[]) {
  int N, K, X, Y;
  cin >> N >> K >> X >> Y;

  int total = 0;
  if (N > K) {
    total += K*X;
    total += (N-K)*Y;
  } else {
    total += N*X;
  }
  cout << total << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int x, y, r, ans;
	int z;
	
	cin >> x >> y;
	
	if (x >= y){
		r = x % y;
		ans = y;
		while (r != 0){
			z = y;
			y = r;
			r = z % r;
			if (r != 0){
				ans = r;
			}
		}
		cout << ans << endl;
		return 0;
	}
	else {
		r = y % x;
		ans = x;
		while (r != 0){
			z = x;
			x = r;
			r = z % r;
			if (r != 0){
				ans = r;
			}
		}
		cout << ans << endl;
		return 0;
	}
}

Measured memory_bytes: 3112
#include <stdio.h>

int main(void){
    int count[4][3][10];
    int n,i;
    scanf("%d", &n);
    for(i=0;i<4;i++){//初期化
        int j;
        for(j=0;j<3;j++){
            int k;
            for(k=0;k<10;k++){
                count[i][j][k] = 0;
            }
        }
    }
    for(i=0;i<n;i++){
        int b,f,r,v;
        scanf("%d %d %d %d",&b,&f,&r,&v);
        count[b-1][f-1][r-1] += v;
    }
    for(i=0;i<4;i++){
        int j;
        for(j=0;j<3;j++){
            int k;
            for(k=0;k<10;k++){
                printf(" %d",count[i][j][k]);
            }
            printf("\n");
        }
        if(i != 3){
            for(j=0;j<20;j++){
                printf("#");
            }
                    printf("\n");
        }

    }
    return 0;
}


Measured memory_bytes: 2104
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def min(a,b)
    return a>b ? b : a
end
N=gets.to_i
INF=Float::INFINITY
dp=array(N+1,INF)
dp[0]=0
1.upto(N) do|i|
  dp[i]=min(dp[i],dp[i-1]+1)
  k=1
  while i-6**k>=0
    dp[i]=min(dp[i],dp[i-6**k]+1) 
    k+=1
  end
  k=1
  while i-9**k>=0 
    dp[i]=min(dp[i],dp[i-9**k]+1) 
    k+=1
  end
end
puts dp[N]

Measured memory_bytes: 2556
#include <bits/stdc++.h>
#define endl '\n'
#define F first
#define $ ios::sync_with_stdio(0);
#define S second
using namespace std;
using ll = long long int;
using vi = vector<int>;
using vii = vector<pair<int, int> >;
using graph = vector<vi>;
const int MAXN = 312345;
const int INF = 0x3f3f3f3f;
int n, pai[MAXN], r[MAXN];
int findS(int i) {return i == pai[i] ? i : pai[i] = findS(pai[i]); }
void join(int a, int b) {
    a = findS(a);
    b = findS(b);
    if (a == b) return;
    if (r[b] > r[a]) swap(a, b);
    pai[b] = a;
    r[a] += r[b];
    n--;
}
int main() {
    int m, k;
    scanf("%d %d", &n, &m);
    for (int i = 1; i<=n; ++i) {
        pai[i] = i;
        r[i] = i;
    }
    int u, v, w;
    while (m--) {
        scanf("%d %d %*d", &u, &v);
        join(u, v);
    }
    printf("%d\n", n);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
#define print(x) cerr << (#x) << "is "<< x << "\n"
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10;
 
int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   string s;
   cin >> s;
   int n = s.length();
   string res = "",prv="";
   prv += s[0];
   int ans = 1;
   f(i,1,n){
      res += s[i];
      if(res != prv){
         ans++;
         prv = res;
         res = "";
      }
   }
   cout << ans << '\n';
   return 0;
}

Measured memory_bytes: 720
n = int(input())
s = input()
cnt = 0
for i in range(10):
    idx1 = s.find(str(i))
    if idx1 == -1:
        pass
    elif idx1 > n-3:
        pass
    else:
        for j in range(10):
            idx2 = s.find(str(j),idx1+1)
            if idx2 == -1:
                pass
            elif idx2 > n-2:
                pass
            else:
                for k in range(10):
                    idx3 = s.find(str(k),idx2+1)
                    if idx3 == -1:
                        pass
                    else:
                        cnt += 1
#    print(i,idx1)
print(cnt)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;

pair<int,int> maja(int x) {
  if (x == 0) return pair<int,int>(0,0);
  int n = static_cast<int>(ceil((-1.0+sqrt(1.0+4.0/3.0*x))/2.0));
  int a = 3*n*(n-1), d = static_cast<int>(ceil((1.0*x-a)/n-1.0));
  int k = x - a - n * d;
  switch (d) {
  case 0: return pair<int,int>(n-k,k);
  case 1: return pair<int,int>(-k,n);
  case 2: return pair<int,int>(-n,n-k);
  case 3: return pair<int,int>(-n+k,-k);
  case 4: return pair<int,int>(k,-n);
  case 5: return pair<int,int>(n,-n+k);
  }
}

int majadist(const pair<int,int> &a, const pair<int,int> &b) {
  int dx = abs(a.first - b.first);
  int dy = abs(a.second - b.second);
  int dz = abs(a.first+a.second-b.first-b.second);
  return min(dx+dy, min(dx+dz, dy+dz));
}

int main(){
  string strN;
  
  int char2num[256];
  char2num['f'] = 1;
  char2num['e'] = 2;
  char2num['d'] = 3;
  char2num['c'] = 4;
  char2num['b'] = 5;
  char2num['a'] = 6;
  int chars[] = {'f','e','d','c','b','a'};

  while(getline(cin,strN)){
    int N = atoi(strN.c_str());
    
    for(int i=0;i<N;i++){
      string routes[2];
      map<pair<int,int>,bool> visited[2][6];

      for(int person=0;person<2;person++){
	getline(cin,routes[person]);

	for(int offset=0;offset< 6;offset++){
	  for(int char_idx=0;char_idx<6;char_idx++){
	    char2num[chars[char_idx]]
	      = (char_idx + offset) % 6 + 1;	  
	  }  
	  pair<int,int> current(0,0);
	  visited[person][offset][current] = true;

	  for(int k=0;k<routes[person].size();k++){
	    current.first 
	      += maja(char2num[routes[person][k]]).first;
	    current.second 
	      += maja(char2num[routes[person][k]]).second;
	    // cout << "x: " << current.first;
	    // cout << " y: " << current.second << endl;
	    visited[person][offset][current] = true;
	  }
	}
      }
	
      string garbage;
      getline(cin,garbage);

      bool res = false;
      for(int src_offset=0;src_offset< 6;src_offset++){
	for(int dst_offset=0;dst_offset< 6;dst_offset++){
	  int offset_x
	    = visited[1][dst_offset].begin()->first.first
	    - visited[0][src_offset].begin()->first.first;
	  int offset_y
	    = visited[1][dst_offset].begin()->first.second
	    - visited[0][src_offset].begin()->first.second;

	  bool isok = true;
	  for(map<pair<int,int>,bool>::iterator it = visited[0][src_offset].begin();
	      it != visited[0][src_offset].end();
	      it++){
	    pair<int,int> moved(it->first.first+offset_x,
				it->first.second+offset_y);
	    if(visited[1][dst_offset].find(moved) == visited[1][dst_offset].end()){
	      isok = false;
	      break;
	    }
	  }
	  res |= isok;
	}
      }
      printf("%s\n",res ? "true" : "false");
    }
  }
}

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

int main(){
  string s;
  cin >> s;
  int rev = 0;
  int q;
  cin >> q;
  while (q--){
    int t;
    cin >> t;
    if (t == 1){
      rev = (rev + 1) % 2;
      continue ;
    }
    int f;
    cin >> f;
    char c;
    cin >> c;
    if (f == 1 && rev) s += c;
    else if (f == 2 && !rev) s += c;
    else s = c + s;
  }
  if (rev) reverse(s.begin(), s.end());
  cout << s << endl;
}

Measured memory_bytes: 4744
#include<map>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<stack>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,n) n = unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;
/*
struct point
{
long long dist; long long name;
bool operator<(const point& rhs) const {
return dist > rhs.dist;
}
};
*/

ll const MOD = 1000000007;
ll const MAX = 100005;
ll a[MAX];
ll mod_p(ll x, ll y) {
	return (x + y) % MOD;
}
ll mod_m(ll x, ll y) {
	return x * y%MOD;
}

long long extgcd(long long x, long long y, long long &a, long long &b) {
	if (y == 0) {
		a = 1; b = 0;
		return x;
	}
	else {
		long long q = x / y; long long r = x % y;
		long long s;
		long long d = extgcd(y, r, s, a);
		b = s - a * q;
		return d;
	}
}

long long mod_inverse(long long x) {
	x %= MOD;
	long long a, b;
	a = b = 0;
	if (extgcd(x, MOD, a, b) != 1) {
		return -1;
	}
	else {
		return (MOD + a % MOD) % MOD;
	}
}

ll fct;
ll fctdv[MAX];

int main() {
	ll n;
	cin >> n;
	REP(i, 1, n) {
		cin >> a[i];
	}
	fct = 1;
	REP(i, 1, n) {
		fct *= i;
		fct %= MOD;
	}
	REP(i, 1, n) {
		fctdv[i] = mod_m(fct, mod_inverse(i));
	}
	ll l, r;
	l = 2; r = n;
	ll cur = 0;
	REP(i, 1, n) {
		cur += fctdv[i];
		cur %= MOD;
	}
	ll ans = 0;
	REP(i, 1, n) {
		ans = mod_p(ans, cur*a[i] % MOD);
		cur = (cur + fctdv[l] - fctdv[r]+MOD) % MOD;
		l++; r--;
	}
	cout << ans << endl;
}



Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
    std::vector< std::pair<int, int> > cards;

    int n, m;
    std::cin >> n >> m;
    for (int i = 0; i < n; i++) {
        int tmp;
        std::cin >> tmp;
        cards.push_back(std::pair<int, int>(tmp, 1));
    }
    for (int i = 0; i < m; i++) {
        int b, c;
        std::cin >> b >> c;
        cards.push_back(std::pair<int, int>(c, b));
    }

    std::sort(cards.begin(), cards.end());
    std::reverse(cards.begin(), cards.end());

    long sum = 0;
    for (int i = 0; ; i++) {
        long number = cards[i].first;
        long quantity = cards[i].second;

        if (n <= quantity) {
            sum += n * number;
            break;
        } else {
            sum += quantity * number;
            n -= quantity;
        }
    }

    std::cout << sum << std::endl;
}

Measured memory_bytes: 2420
#14:07
s = input()
l = len(s)
cnt = 0
ans = 0
mod = 10**9 + 7
di = [1]
tri = [1]
for _ in range(l):
  di.append(di[-1] * 2 % mod)
  tri.append(tri[-1] * 3 % mod)
#print(di)
#print(tri)
for i in range(l):
  if s[i] == '1':
    cnt += 1
    ans += tri[l-1-i] * di[cnt-1]
    ans %= mod
    #print(tri[l-1-i],di[cnt-1])
ans += di[cnt]
ans %= mod
print(ans)

Measured memory_bytes: 51952
#include <iostream>
#include <string.h>

#define NUM 100000

using namespace std;

int main(void) {
	int a[200001];
	int n,x=1,flag;
	cin >> n;
	cin >> a[NUM];

	if (n%2 == 0) {
		flag = 0;
	} else {
		flag = 1;
	}
	if (flag == 0) {
		for (int i=0;i<n-1;i++) {
			if (i%2 == 0) {
				cin >> a[NUM-x];
			}  else {
				cin >> a[NUM+x];
				x++;
			}
		}
		for(int i=0;i<x*2;i++) {
			cout << a[NUM-x+i] << " ";
		}
	} else {
		for (int i=0;i<n-1;i++) {
			if (i%2 == 1) {
				cin >> a[NUM-x];
				x++;
			}  else {
				cin >> a[NUM+x];
			}
		}
		for(int i=1;i<x*2;i++) {
			cout << a[NUM-x+i] << " ";
		}
	}

	cout << endl;
}


Measured memory_bytes: 2944
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstdio>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <set>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> P;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
const int MAXN = 100000;
const int MAXE = 100000;
const int MAXV = 10000;
const int inf = 1e9;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;

struct UnionFind{
    vector<int> par,rank;
    UnionFind(int n):par(n),rank(n){
        for(int i=0;i<n;++i) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x,int y){
        int rx=root(x),ry=root(y);
        if(rx==ry) return ;
        if(rank[ry]>rank[rx]) par[rx]=ry;
        else par[ry]=rx;
        if(rank[rx]==rank[ry]) rank[rx]++;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};

vector<ll> fac,inv,finv;

void initcom(){
    fac=inv=finv=vector<ll>(1e6);
    fac[0]=fac[1]=1;
    inv[1]=1;
    finv[0]=finv[1]=1;
    for(ll i=2;i<1e6;++i){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

ll com(int n,int k){
    if(n<0||k<0) return 0;
    if(n<k) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll x,ll y){
    if(y==0) return x;
    return gcd(y,x%y);
}
ll mopow(ll a,ll x,ll mod){
    ll res=1;
    while(x>0){
        if(x&1) res=res*a%mod;
        a=a*a%mod;
        x>>=1;
    }
    return res;
}
int main(){
    int n;cin>>n;
    string s;cin>>s;
    vector<int> cb(n+1,0);
    for(int i=0;i<n;++i)if(s[i]=='#') cb[i+1]++;
    for(int i=0;i<n;++i) cb[i+1]+=cb[i];
    int ans=inf;
    for(int i=0;i<=n;++i){
        ans=min(ans,cb[i]+n-i-(cb[n]-cb[i]));
    }
    cout<<ans<<endl;
    return 0;
}

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

int main()
{
	int N, M;
	cin >> N >> M;
	
	vector<vector<int>> matrix(N, vector<int>(M));
	for(auto it = matrix.begin(); it != matrix.end(); it++)
	{
		for(auto itx = it->begin(); itx != it->end(); itx++)
		{
			cin >> *itx;
		}
	}
	
	vector<int> low_v(M);
	for(auto it = low_v.begin(); it != low_v.end(); it++)
	{
		cin >> *it;
	}
	
	for(int i = 0; i < N; i++)
	{
		int ans = 0;
		for(int j = 0; j < M; j++)
		{
			ans += matrix[i][j] * low_v[j];
		}
		
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define int ll
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 100000000000000
#define pb push_back

vector<vii> vec;
vv res;
bitset<2501> vis;
int dist[2501];

void dfs(int node){
	vis[node]=1;
	for(auto it:res[node])
		if(!vis[it])
			dfs(it);
}

int32_t main(){
	boost ;
	vis=0;
	int n,m,p,a,b,c;
	cin>>n>>m>>p;
	vec.resize(n),res.resize(n);
	while(m--){
		cin>>a>>b>>c;
		a--,b--;
		vec[a].pb(ii(b,-1LL*(c-p)));
		res[b].pb(a);
	}
	dfs(n-1);
	dist[0]=0;
	for (int i = 1; i < n; ++i)
		dist[i]=INF;
	for (int j = 0; j < n-1; ++j)
		for (int i = 0; i < n; ++i){
			if(dist[i]==INF)continue;
			for(auto child:vec[i])
				if(dist[child.fi]>child.se+dist[i])
					dist[child.fi]=child.se+dist[i];
		}
	for (int i = 0; i < n; ++i){
		if(dist[i]==INF)continue;
		for(auto child:vec[i]){
			if(dist[child.fi]==INF)continue;
			if((dist[child.fi]>child.se+dist[i])&&vis[child.fi]){
				cout<<-1;return 0;
			}

		}
	}
	cout<<max(0LL,-1LL*dist[n-1]);
	return 0;
}

Measured memory_bytes: 640
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
signed main(){
  ll a,b;
  cin >> a >> b;
  cout << (a+b+1)/2<<endl;
}


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

int main (void)
{
    int cnt=0;
    char s[15];
    scanf("%s",s);
    for(int i=0;i<strlen(s);i++)
    {
        if(s[i]=='x')
        {
            cnt++;
        }
    }
    if(cnt>7)
    {
        puts("NO");
    }else{
        puts("YES");
    }
    return 0;
}


Measured memory_bytes: 1632
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <limits>
#include <ctype.h> 
#include <stdio.h> 
#include <set> 
#include <iomanip>
#include <vector>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
#define L(ID) ((ID*2)+1)
#define R(ID) ((ID*2)+2)
#define M(L,R) ((L+R)/2)
#define forr(start,end) for(int i = start; i < end; i++)
#define gap ' '


const int MAXN = 1e5;
char a[MAXN];   
int n = 0;

int factorial(){
    for(int i = n-1; i > 0; --i){
        n = n * i;
    }
    return n;
}


int main() {
    int s = 0, w = 0;
    cin >> s >> w;
    if(w >= s){
        cout << "unsafe" << endl;
    }
    else{
        cout << "safe" << endl;
    }
    

    return 0;
} 


Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
int main(){
int A,B;
  cin>>A>>B;
int count=0;
for(int i=1;i<10;i++){
	for(int j=0;j<10;j++){
    	for(int k=0;k<10;k++){
          int x= 10001*i + 1010*j +100*k;
        	if(A<=x && x<=B){
            count++; 
            }
        }
    }
}
cout<<count<<endl;
}
 

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

int a[100005],b[50005];

bool binary(int i,int j,int x)
{
    if(i > j) return 0;
    int mid = (i+j)/2;
    if(x==a[mid]) return 1;
    else if(x < a[mid]) return binary(i,mid-1,x);
    else if(x > a[mid]) return binary(mid+1,j,x);
}
int main()
{
    int n,q;
    cin>>n;
    for(int i=0;i < n;i++) cin>>a[i];
    cin>>q;
    for(int i=0;i < q;i++) cin>>b[i];
    int ans=0;
    for(int i=0;i < q;i++)
        if(binary(0,n-1,b[i]))
            ans++;
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3612
#include <iostream>

using namespace std;

template<typename T>
T extgcd(T a, T b, T& x, T& y){
    T g = a; x = 1; y = 0;
    if(b){
        g = extgcd(b, a % b, y, x);
        y -= (a / b) * x;
    }
    return g;
}

int main(){
    int a, b, x, y;
    cin >> a >> b;
    extgcd(a, b, x, y);
    cout << x << ' ' << y << '\n';
    return 0;
}

Measured memory_bytes: 1164