akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using LL = int64_t;
using ULL = uint64_t;
using P = pair<LL, LL>;
#define rep(i, n) for (LL i = 0; i < (n); ++i)
//#define DEBUG

LL f(const vector<vector<LL>> &edges, vector<bool> &visited,
     const LL pos, const LL depth, const LL n) {
  #ifdef DEBUG
  string s = "";
  rep(i, depth) {
    s += "  ";
  }
  cout << s << pos << endl;
  #endif

  if (depth == n) {
    return (LL)1;
  }

  visited.at(pos) = true;
  LL sum = (LL)0;
  for (const auto i: edges.at(pos)) {
    //cout << "* " << i << endl;
    if (!visited.at(i)) {
      sum += f(edges, visited, i, depth + 1, n);
    }
  }
  visited.at(pos) = false;
  return sum;
}

int main() {
  LL n, m;
  cin >> n >> m;

  vector<vector<LL>> edges(n, vector<LL>());

  for (LL i = 0; i < m; ++i) {
    LL a, b;
    cin >> a >> b;
    edges[a - 1].push_back(b - 1);
    edges[b - 1].push_back(a - 1);
  }

  vector<bool> visited(n, false);
  cout << f(edges, visited, 0, 1, n) << endl;
  #ifdef DEBUG
  #endif
}



Measured memory_bytes: 256
// input: alds1_10_b.in
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

#define NIL -1

struct Matrix {
  Matrix(int r, int c)
    : r(r), c(c){
  }
  int r;
  int c;
};

int costs[101][101];

void init_costs() {
  for(int i=0; i<101; i++) {
    for(int j=0; j<101; j++) {
      costs[i][j] = NIL;
    }
  }
}

int cost(vector<Matrix>& ms, int start, int end) {
  if(costs[start][end] != NIL) {
    return costs[start][end];
  }

  if(start == end) {
    costs[start][end] = 0;
    return 0;
  }

  if(end - start == 1) {
    Matrix s = ms.at(start);
    Matrix e = ms.at(end);
    int c = s.r * s.c * e.c;
    costs[start][end] = c;
    return c;
  }

  vector<int> cs;
  for(int i=start; i<end; i++) {
    int c1 = cost(ms, start, i);
    int c2 = cost(ms, i+1, end);
    int c3 = ms.at(start).r * ms.at(i).c * ms.at(end).c;
    cs.push_back(c1 + c2 + c3);
  }
  int c = *min_element(cs.begin(), cs.end());
  costs[start][end] = c;

  return c;
}

int solve(vector<Matrix>& ms) {
  return cost(ms, 0, ms.size()-1);
}

int main() {
  init_costs();

  int n;
  cin >> n;

  vector<Matrix> ms;

  for(int i=0; i<n; i++) {
    int r, c;
    cin >> r >> c;

    ms.push_back(Matrix(r, c));
  }

  cout << solve(ms) << endl;
}

Measured memory_bytes: 3196
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
typedef long long ll;

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

    priority_queue<int, vector<int>, greater<int>> A;
    for (int i = 0; i < N; i++) {
        int tmp;
        cin >> tmp;
        A.push(tmp);
    }
    map<int, int, greater<int>> C;
    for (int i = 0; i < M; i++) {
        int b, c;
        cin >> b >> c;
        C[c] += b;
    }

    for (auto c : C) {
        // cout << c.first << " " << c.second << endl;
        for (int i = 0; i < c.second; i++) {
            if (A.top() < c.first) {
                A.pop();
                A.push(c.first);
            } else {
                break;
            }
        }
    }

    ll output = 0;
    for (int i = 0; i < N; i++) {
        output += (ll)A.top();
        A.pop();
        // cout << A[i] << endl;
    }
    cout << output << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvl;
int n, m;
vector<vector<int>> p, inv;
vector<int> ans;
vector<int> dep;

int dfs(int i) {
  if (dep[i] >= 0)
    return dep[i];
  int par = 0;
  int now = -1;
  for (int &j : p[i]) {
    int d = dfs(j);
    if (now < d) {
      now = d;
      par = j;
    }
  }
  dep[i] = now + 1;
  ans[i] = par + 1;
  return dep[i];
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  p.resize(n);
  inv.resize(n);
  for (int i = 0; i < n + m - 1; i++) {
    int t, f;
    cin >> f >> t;
    t--;
    f--;
    inv[f].push_back(t);
    p[t].push_back(f);
  }
  ans.resize(n);
  dep.resize(n);
  int root = -1;
  for (int i = 0; i < n; i++) {
    if (p[i].size() == 0) {
      ans[i] = 0;
      dep[i] = 0;
      root = i;
    } else {
      ans[i] = -1;
      dep[i] = -1;
    }
  }

  for (int i = 0; i < n; i++)
    dfs(i);
  for (int i = 0; i < n; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 16512
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
#define sz(x) x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define V vector<int>
#define COUT(x) cout<<(x)<<endl
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int,V,greater<int>>

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

using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 50;

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int a, b, c, d; cin >> a >> b >> c >> d; a--;
	int bc = b / c; int bd = b / d; int btmp = b / (lcm(c, d));
	int ac = a / c; int ad = a / d; int atmp = a / (lcm(c, d));
	cout << (b - (bc + bd-btmp)) - (a - (ac + ad-atmp)) << endl;
	return 0;
}

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

int main() {
	
	long long int n,sum=0; cin>>n;
	int a[n+1],b[n];
	for(int i=0;i<n+1;i++) cin>>a[i];
	for(int i=0;i<n;i++) {
		cin>>b[i];
	}
	for(int i=0;i<n;i++) {
		if(a[i]>b[i]) { sum+=b[i]; }	//Remove Equal to
		else {
			b[i]-=a[i];
			sum+=a[i];
			if(a[i+1]>=b[i])  { //Remove Equal to
				a[i+1]-=b[i]; 
				sum+=b[i];
			}
			else {
				sum+=a[i+1]; 
				a[i+1]=0;
			}	
		}
	}
	cout<<sum<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define il inline
#define ll long long
const int N=1e5+5;

int n,m=1,q; ll f[N],a[N],ans[N];

il void work(ll c,ll d)
{
    int x=std::upper_bound(a+1,a+m+1,c)-a-1;
    if (!x) ans[1]+=d,ans[c+1]-=d;
    else f[x]+=c/a[x]*d,work(c%a[x],d);
}

int main()
{
    scanf("%d%d",&n,&q),a[m]=n; int i; ll x;
    for ( ; q; q--,a[++m]=x) for (scanf("%lld",&x); x<=a[m]&&m; m--);

    for (f[i=m]=1; i>1; i--) f[i-1]+=a[i]/a[i-1]*f[i],work(a[i]%a[i-1],f[i]);
    for (ans[i=1]+=f[1],ans[a[1]+1]-=f[1]; i<=n; i++) printf("%lld\n",ans[i]+=ans[i-1]);

    return 0;
}

Measured memory_bytes: 6032
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
#define int long long

signed main() {
    int a, v, b, w, t;
    cin >> a >> v >> b >> w >> t;
    if (b > a) {
        int b2 = b + w * t;
        int a2 = a + v * t;
        if (a2 >= b2) {
            cout << "YES" << endl;
        }
        else
            cout << "NO" << endl;
    }
    else if (b < a) {
        int b2 = b - w * t;
        int a2 = a - v * t;
        if (a2 <= b2) {
            cout << "YES" << endl;
        }
        else
            cout << "NO" << endl;
    }
}


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

int main(){
	int N;
	cin>>N;
	vector<string>s(N);
	vector<int>t(N);
	rep(i,N){
		cin>>s.at(i)>>t.at(i);
	}
	string X;
	cin>>X;
	int time=0;
	rep(i,N){
		if(s.at(N-1-i)==X){
			cout<<time<<endl;
			return 0;
		}
		time+=t.at(N-1-i);
	}
return 0;}

/*compile
g++ code.cpp
./a.out
run*/

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iomanip>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
template < typename T > std::string to_string( const T& n )
  {
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
  }
using namespace std;

const long long INF=9000000000000000;
int main(){
long long int n=0,m=0,k;
string s;
cin>>s;
n=s.size();
for(int i=0;i<n;i++){
  if(s[i]=='o')
  m++;
}
if((15-n)<(8-m))
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
}


Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(vec) vec.begin(), vec.end()
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y){
  return y == 0 ? x : gcd(y, x % y);
}
ll lcg(ll x, ll y){
  return x * y / gcd(x, y);
}
map<ll, ll> factor(ll n){
  map<ll, ll> ans;
  ll a = 2;
  while (n >= a * a){
    if (n % a == 0){
      ans[a]++;
      n /= a;
    }
    else a++;
  }
  ans[n]++;
  return ans;
}

int main(){
  int a, w; string s; cin >> a >> s >> w;
  char c = s[w - 1];
  rep(i, a) if (s[i] != c) s[i] = '*';
  cout << s << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

#define MAX(x,y) (x>y?x:y)
#define MIN(x,y) (x<y?x:y)
#define ABS(x) (x>0?x:-(x))
#define INF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

typedef long long int lli;

void swap(int* a, int* b)
{
    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

void ll_swap(lli* a, lli* b)
{
    lli tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
}

int gcd(int a, int b)
{
    if (a < b)
        swap(&a, &b);

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

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

long power(long x, int n) {
    long ans = 1;
    while (n > 0) {
        if ((n & 1) == 1) {
            ans = ans * x;
        }
        x = x * x;
        n >>= 1;
    }
    return ans;
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
		printf("res:%lld a:%lld\n", res,a);
	}
	return res;
}


lli comb(lli n, lli r)
{
    if (n == 0)
        return 0;

    if (r == 0 || r == n)
        return (1);
    else if (r == 1)
        return (n);
    return (comb(n - 1, r - 1) + comb(n - 1, r));
}

/*
#define MAX 100000
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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;
    }
}
// 二項係数計算
long long COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
*/

int main()
{
    int N;
    int A[100000];

    scanf("%d", &N);

    for (int i = 0; i < N; i++)
        scanf("%d", &A[i]);

    for (int i = 0; i < N-1; i++)
    {
        A[i + 1] = gcd(A[i], A[i + 1]);
    }

    printf("%d", A[N - 1]);
}



Measured memory_bytes: 640
///         Saniuzzaman Robin
///      CSE,Comilla University

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

typedef     long long int                ll;
typedef     unsigned long long int       ull;
typedef     vector< int >                vint;
typedef     vector< ll >                 vlong;
typedef     vector< vint >               vvint;
typedef     pair< int,int >              pint;
typedef     pair< ll, ll >               plong;
typedef     vector< pint >               vpi;
typedef     vector< plong >              vpli;

#define     dbl                 double
#define     pf                  printf
#define     sc                  scanf
#define     MAX                 1000007
#define     MOD                 1000000007
#define     PI                  2*acos(0.0)
#define     fast                ios_base::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define     all(a)              (a).begin(),(a).end()
#define     sz(x)               (int)x.size()
#define     pb                  push_back
#define     mp                  make_pair
#define     mem(a,b)            memset(a, b, sizeof(a) )
#define     gcd(a,b)            __gcd(a,b)
#define     lcm(a,b)            (a*(b/gcd(a,b)))
#define     ifor(x,n)           for( int i=x ; i<n ;i++)
#define     lfor(x,n)           for( long long int i=x; i<n; i++)

int main()
{

   int n,m,cnt=0;
   cin>>n>>m;
   for(int i=1;i<=n;i++)
   {
       for(int j=1;j<=m;j++)
       {
           if(j%10>=2 && j/10>=2 && (j%10)*(j/10)==i)
           {
               cnt++;
           }
       }
   }
   cout<<cnt<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main() {
    int a,b,c;
    int max,min,mid;

    scanf("%d %d %d",&a,&b,&c);

    if (a > b && a > c) {
        max = a;
        if (b > c) {
            mid = b;
            min = c;
        } else {
            mid = c;
            min = b;
        }
    } else if (b > c) {
        max = b;
        mid = c;
        min = a;
    } else {
        max = c;
        mid = b;
        min = a;
    }
    
    printf("%d %d %d\n",min,mid,max);

    return 0;
}


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

string toUpper(string s){
	target="";
	for (int i = 0; i < s.length(); ++i) {
		target+=toupper(s[i]);
	}
	return target;
}


int main() {
string s,c;
string a;
cin>>s;
s=toUpper(s);
int ans=0;
for (int i = 0; i < 1002; ++i) {
	cin>>a;
	if(a=="END_OF_TEXT"){break;}
	a=toUpper(a);
	if(a==s){ans++;}
}
cout<<ans<<endl;
}

Measured memory_bytes: 3204
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

bool palin(string s){
  string temp = s;
  reverse(all(temp));
  return s == temp;
}

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  ld n;
  cin >> n;
  ld ans = n/3;
  ans=ans*ans*ans;
  cout << fixed << setprecision(12) << ans << endl;

return 0;
}
///....


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
typedef long long int LL;
using namespace std;

// 插入此處

int main() {
    int L; cin >> L;
    if (L % 3 == 0) {
        printf("%.9lf\n", pow(L / 3, 3));
    } else {
        printf("%.9lf\n", 1. * L * L * L / 27);
    }
    return 0;
}


Measured memory_bytes: 384
import sys

input = sys.stdin.readline


def main():
    N, C, K = map(int, input().split())
    T = [0] * N
    for i in range(N):
        T[i] = int(input())

    T.sort()
    ans = 0
    s = 0  # Time when the bus comes
    m = 0  # Current numbers of passengers
    for t in T:
        if m == 0:
            s = t
            m = 1
            ans += 1
        else:
            if t <= s + K:
                m += 1
            else:
                s = t
                m = 1
                ans += 1
        if m == C:
            m = 0

    print(ans)


if __name__ == "__main__":
    main()


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

int main()
{
    int N, X, Y;
    cin >> N >> X >> Y;
    map<int, int> mp;
    for (int i = 1; i < N; i++)
    {
        mp[i] = 0;
    }

    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            if (i >= j){
                /* code */
                continue;
            } else {
                int key;
                if (i == X and Y == j) {
                    key = 1;
                } else {
                    // key = int(min(j - i, math.fabs(X - i) + math.fabs(Y - j) + 1))
                    key = min(abs(X - i) + abs(Y - j) + 1, j - i);
                }
                mp[key] += 1;
            }
        }
    }
    for (int i = 1; i < N; i++) {
        cout << mp[i] << endl;
    }
}


Measured memory_bytes: 384
#include <stdio.h>
#include <inttypes.h>

int main(void) {
	int64_t A, B, C, K;
	int64_t answer = 0;
	if (scanf("%" SCNd64 "%" SCNd64 "%" SCNd64 "%" SCNd64, &A, &B, &C, &K) != 4) return 1;
	if (A >= K) {
		answer += K;
		K = 0;
	} else {
		answer = A;
		K -= A;
	}
	if (B >= K) {
		K = 0;
	} else {
		K -= B;
	}
	if (C >= K) {
		answer -= K;
	} else {
		answer -= C;
	}
	printf("%" PRId64 "\n", answer);
	return 0;
}


Measured memory_bytes: 1732
N,A,B =map(int,input().split()) 

# import collections

# blues = 'b' * A
# reds = 'r' * B

# set_balls = blues + reds

# all_balls = set_balls * ( N // ( A + B ) + 1 )

# balls_N = all_balls[:N]

# c = collections.Counter(balls_N)
# print(c['b'])

p = N//(A+B)

if N - p*(A+B) < A:
    print(A*p + N - p*(A+B) )
else:
    print(A*p+A)

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

const int offset = 1 << 20;
int st[2 * offset];
int in[offset];

int minimum(int a, int b) {
    a += offset;
    b += offset;

    int rv = 1e9 + 7;
    while(a <= b) {
        if(a % 2 == 1) rv = min(rv, st[a++]);
        if(b % 2 == 0) rv = min(rv, st[b--]);
        a /= 2; b /= 2;
    }
    return rv;
}


void add(int k, int x) {
    k += offset;
    st[k] = x;
    for(k /= 2; k >= 1; k /= 2) {
        st[k] = min(st[k * 2], st[k * 2 + 1]);
    }
}

int main() {
    int n, k;
    scanf("%d %d", &n, &k);

    for(int i = 0; i < n; i++) {
        scanf("%d", &in[i]);
        add(i, in[i]);
    }

    int maxx = 0;
    for(int i = 1; i < n; ++i) {
        int v = minimum(0, i - 1);
        if(in[i] - v > maxx) {
           maxx = in[i] - v;
        }
    }

    int res = 0;
    unordered_set< int> st;
    st.insert(in[0]);
    for(int i = 1; i < n; ++i) {
        if(st.count(in[i] - maxx)) res++;
        st.insert(in[i]);
    }
    printf("%d\n", res);
}

Measured memory_bytes: 10916
from fractions import Fraction

n, k = [int(i) for i in input().split(" ")]
p = Fraction(0, 1)

def int_log(x, y):
    r = 0
    while x < y:
        x *= 2
        r += 1
    return r

for i in range(1, n + 1):
    if i >= k:
        p += Fraction(1, n)
    else:
        p += Fraction(1, n * 2**int_log(i, k))

print('{:.10f}'.format(float(p)))

Measured memory_bytes: 5048
#include<stdio.h>
int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    if ( a<b ){
       printf("a < b\n");
    } else if ( a>b ){
       printf("a > b\n");
    } else if ( a==b ){
       printf("a == b\n");
    }
    return 0;
}

Measured memory_bytes: 580
M=998244353
N,*A=map(int,open(0))
d=[0]*90001
d[0]=1
e=[0]*90001
e[0]=1
z=1
s=0
for a in A:
	i=s;s+=a;z=z*3%M
	while i>=0:d[i+a]+=d[i]%M;d[i]*=2;e[i+a]+=e[i]%M;i-=1
for i in range(s+1>>1,s+1):z=(z-d[i]*3)%M
print([(z+e[s//2]*3)%M,z][s%2])

Measured memory_bytes: 141900
N, k = map(int, input().split())                                                                               
s = input()

l, accum = len(s), []
i = 0
while i < l:
    ch = s[i]
    count = 0
    while i < l and s[i] == ch:
        count += 1
        i += 1
    accum.append(count)

l = len(accum)
for i in range(1, l): accum[i] += accum[i-1]

mx = accum[min(2*k - (1-int(s[0])), l-1)]
i = 1
while l > 1:
    idx = min(2*k - (1-int(s[0])) + 2*i, l-1)
    mx = max(accum[idx] - accum[2*(i-1)+int(s[0])], mx)
    if idx >= l-1: break
    i += 1
print(mx) 

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    int2(n, x);
    vi low(n), up(n), point(n);
    vp data(n);
    int score = 0;
    rep(i, n) {
        cin >> point[i] >> low[i] >> up[i];
        score += point[i] * low[i];
        data[i].fir = up[i] * (x - point[i]) + point[i] * low[i];
        data[i].sec = i;
    }
    if (!score) {
        std::cout << 0 << std::endl;
        return 0;
    }

    //cout << "score : " << score << endl;
    sort(all(data)); reverse(all(data));

    int l = 0, r = x * n;
    while (r - l > 1) {
        int mid = (r + l) / 2;
        vi used(n, 0);
        //cout << "mid : " << mid << endl;

        int p = 0, sum = 0;
        while (mid >= x) {
            sum += data[p].fir;
            used[p] = 1;
            p++; mid -= x;
        }
        //cout << sum << " : ";

        int yui = sum;
        rep(i, data.size()) {
            if (!used[i]) {
                if (mid <= point[data[i].sec]) {
                    yui = max(yui, sum + mid * low[data[i].sec]);
                } else {
                    yui = max(yui,
                            sum + point[data[i].sec] * low[data[i].sec] + 
                            (mid - point[data[i].sec]) * up[data[i].sec]);
                }
            } else if (p < data.size()) {
                int tmp = sum - data[i].fir + data[p].fir;
                //cout << " [tmp : " << tmp << "] "; 
                if (mid <= point[data[i].sec]) {
                    yui = max(yui, tmp + mid * low[data[i].sec]);
                } else {
                    yui = max(yui,
                            tmp + point[data[i].sec] * low[data[i].sec] + 
                            (mid - point[data[i].sec]) * up[data[i].sec]);
                }
            }
            //cout << yui << ", ";
        }
        //cout << endl;
        if (yui >= score) {
            r = (r + l) / 2;
        } else {
            l = (r + l) / 2;
        }
    }
    std::cout << r << std::endl;
    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;

long long gcd(long long a, long long b)
{
	long long tmp, r;
	if (a < b)
	{
		tmp = a;
		a = b;
		b = tmp;
	}
	r = a % b;
	while (r != 0)
	{
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

int main(void)

{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << ketasitei;
	
	ll a;
	cin >> a;

	ll ans = 0;

	for (int i = 1; i <= a; i++)
	{
		for (int j = 1; j <= a; j++)
		{
			for (int k = 1; k <= a; k++)
			{
				ans += gcd(gcd(i, j), k);
			}
		}
	}
    cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3688
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), k = sc.nextInt();
        long kp2 = 0;
        long kp1 = 0;
        long ans = 0L;
        for (int i = 1; i <= n; i++) {
            if (i % k == k/2) kp2++;
            if (i % k == 0) kp1++;
        }

        if(k % 2 != 0) kp2 = 0;

        System.out.println(kp1*kp1*kp1+kp2*kp2*kp2);
    }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
typedef long long ll;
#define MX 100005
#define PB push_back
ll MOD = 1e9 + 7;
using namespace std;
int dp[101][MX];
int cum[101][MX];
int main() {
	int n, k;
	cin >> n >> k;
	for (int i = 0; i <= k; ++i)
		cum[0][i] = 1;
	int a;
	int sum = 0;
	for (int i = 1; i <= n; ++i) {
		cin >> a;
		sum += a;
		for (int j = 0; j <= k; ++j) {
			if (j <= sum) {
				int b = j - a;
				if (b <= 0)
					dp[i][j] = cum[i - 1][j];
				else
					dp[i][j] = (cum[i - 1][j] - cum[i - 1][b - 1]) % MOD;
				if(dp[i][j] < 0)
					dp[i][j] += MOD;
			}
			cum[i][j] = dp[i][j];
			if (j > 0)
				cum[i][j] = (cum[i][j] % MOD + cum[i][j - 1] % MOD) % MOD;
		}
	}
	cout << dp[n][k] << endl;
}

Measured memory_bytes: 79104
// practice with Dukkha
#include <algorithm>
#include <iostream>

using namespace std;

const int MD = 1000000007;

int main() {
	string s; cin >> s;
	int n = s.length();
	long long a = 0, b = 0, c = 0, k = 1;
	for (int i = 0; i < n; i++) {
		char x = s[i];
		if (x == 'A')
			a = (a + k) % MD;
		else if (x == 'B')
			b = (b + a) % MD;
		else if (x == 'C')
			c = (c + b) % MD;
		else {
			long long a_ = (a * 3 + k) % MD;
			long long b_ = (b * 3 + a) % MD;
			long long c_ = (c * 3 + b) % MD;
			a = a_;
			b = b_;
			c = c_;
			k = k * 3 % MD;
		}
	}
	cout << c << '\n';
	return 0;
}


Measured memory_bytes: 3756
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
a = list(map(int,readline().split()))
q = int(readline())
bc = list(map(int,read().split()))

from collections import defaultdict
d = defaultdict(int)

for i in a:
    d[i] += 1

ans = []
si = sum(a)
it = iter(bc)
for b,c in zip(it,it):
    d[c] += d[b]
    si += (c*d[b]) - b*d[b]
    d[b] = 0
    ans.append(si)

print('\n'.join(map(str,ans)))

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

namespace ConsoleApp9
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = new int[3]; 
            for (int a = 0; a < 3; a++) {
                input[a] = int.Parse(Console.ReadLine());
            }
            int result = (input[0] + input[1]) * input[2]/2;
            Console.WriteLine(result);

            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
#include<cstdio>
#include<iostream>
#include<string>
#include<map>
#include<queue>
#include<set>

using namespace std;

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

int main(){
	while(1){
		int m,n;
		cin>>m>>n;
		if(m==0)break;
		
		int dp[2][111][111];
		
		rep(p,2){
			rep(i,111){
				rep(j,111){
					dp[p][i][j]=1000000000;
				}
			}
			rep(i,111)dp[p][i][i]=0;
		}
		
		rep(i,m){
			int a,b,c,t;
			cin>>a>>b>>c>>t;
			
			a--;b--;
			
			dp[0][a][b]=c;
			dp[0][b][a]=c;
			
			dp[1][a][b]=t;
			dp[1][b][a]=t;
		}
		
		rep(p,2){
			rep(k,n){
				rep(i,n){
					rep(j,n){
						dp[p][i][j] = min(dp[p][i][j],dp[p][i][k]+dp[p][k][j]);
					}
				}
			}
		}
		
		int T;
		cin>>T;
		rep(i,T){
			int a,b,c;
			cin>>a>>b>>c;
			printf("%d\n",dp[c][a-1][b-1]);
		}
	}
}

Measured memory_bytes: 968
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <algorithm>
#include <set>

using namespace std;

using ll = long long;

inline ll min(ll a, ll b) {
	return a < b ? a : b;
}

const int Max = 1e4;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> daum(n + 1);
	int x1 = 0, f = 0;
	for (int i = 1; i <= n; ++i) {
		cin >> daum[i];
		if (i & 1)
			f += daum[i];
		else
			f -= daum[i];
	}
	cout << f << ' ';
	for (int i = 2; i <= n; ++i) {
		cout << daum[i - 1] * 2 - f << ' ';
		f = daum[i - 1] * 2 - f;

	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const LL INF=1e15;
LL memo[100005];
LL datas[100005];
int N, K;
LL solve(int ix)
{
	if(ix==N) return 0;
	if(ix > N) return INF;
	if(memo[ix]!=-1) return memo[ix];
	LL ret=INF;
	for(int z=1;z<=K;z++)
	{
		ret=min(ret, abs(datas[ix]-datas[ix+z])+solve(ix+z));
	}
	return memo[ix]=ret;
}

int main()
{
	scanf("%d%d", &N, &K);
	for(int a=1;a<=N;a++)
	{
		scanf("%lld", &datas[a]);
	}
	memset(memo, -1, sizeof(memo));
	printf("%lld\n", solve(1));
	return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int MAX = 510000;
const double pi=acos(-1);

int main(){
  string s,p;
  cin >> s >> p;
  s+=s;
  rep(i,s.size()-p.size()){
    bool ok=true;
    rep(j,p.size()){
      if(s[i+j]!=p[j])ok=false;
    }
    if(ok){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  
}



Measured memory_bytes: 3200
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    ll N,A,B;cin>>N>>A>>B;
    ll ans=(N/(A+B))*A;
    N-=(N/(A+B))*(A+B);
    ans+=min(N,A);
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll,ll> pr;
typedef vector<ll> vc;
typedef unordered_map<ll,ll> umap;
#define pb emplace_back
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
const ll mod = 1e9+7;
const ll max_n = 1e3+5;

int main() {
    // your code goes here
    ll n, w[max_n], s[max_n], v[max_n];
    ll dp[max_n][30050] = {0}, ans = 0;
    pair<pr,ll> tk[max_n];
    cin >> n;
    rep(i,0,n-1){
    	cin >> w[i] >> s[i] >> v[i];
    	tk[i] = {{w[i]+s[i],w[i]},v[i]};
    }
    sort(tk,tk+n);
    rep(i,1,n){
    	w[i] = tk[i-1].first.second;
    	s[i] = tk[i-1].first.first - w[i];
    	v[i] = tk[i-1].second;
    }
    rep(i,1,n){
    	rep(j,0,20000) dp[i][j] = dp[i-1][j];
    	rep(j,0,20000){
    		if(s[i]>=j) chmax(dp[i][w[i]+j], dp[i-1][j]+v[i]);
    	}
    }
    rep(i,0,20000) chmax(ans,dp[n][i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 236288
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())
#define MATHPI acos(-1)
#define itn int
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-19;

signed main() {
    ll a, b, x;
    cin >> a >> b >> x;
    
    ll r = b/x - (a-1)/x;
	if(a == 0 && x != 1) r++;
    
    mes(r);
    
    
    
    
    
    
    
    
}

Measured memory_bytes: 3600
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, L; cin>>N>>L;
  vector<string> S(N);
  for(int i=0;i<N;++i) cin>>S[i];
  sort(S.begin(), S.end());
  string ans;
  for(int i=0;i<N;++i) ans += S[i];
  cout<<ans<<endl;
}



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

using namespace std;

using Int  = int_fast64_t;
using UInt = uint_fast64_t;

template <typename T>
using vec1 = vector<T>;

template <typename T>
T cin2var()
{
    T val;
    cin >> val;
    return val;
}

template <typename T>
vec1<T> cin2vec(size_t size)
{
    vec1<T> vec1(size);
    for (auto& v : vec1) {
        v = cin2var<T>();
    }
    return vec1;
}

void sub()
{
    const auto N(cin2var<UInt>());
    const auto S(cin2var<string>());
    for (auto c : S) {
        c += N;
        if (c > 'Z') c -= 26;
        cout << c;
    }
    cout << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    sub();
    return 0;
}

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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i=(int)(b-1);i>=(int)(a);--i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,n) for(int i=(int)(n-1);i>=0;--i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x)*(x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main() {
    int n, p;
    while (cin >> n >> p, n|p) {
        vi te(n);
        int wan = p;
        int i = 0;
        while (1) {
            if (wan > 0) {
                wan--;
                te[i]++;
                if (wan == 0 && te[i] == p) {
                    cout << i << endl;
                    break;
                }
            } else {
                wan += te[i];
                te[i] = 0;
            }
            i = (i + 1) % n;
        }
    }
}

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

int		main(void)
{
	int d, n;

	cin >> d >> n;
	if (d == 0)
	{
		if (n == 100)
			cout << n + 1 << endl;
		else
			cout << n << endl;
	}
	else if (d == 1)
	{
		if (n == 100)
			cout << n * 100 + 100 << endl;
		else
			cout << n * 100 << endl;
	}
	else
	{
		if (n == 100)
			cout << n * 10000 + 10000 << endl;
		else
			cout << n * 10000 << endl;
	}
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    int W, H, x, y, r, a;
    cin >> W >> H >> x >> y >> r;
    a = 0;
    if (x < r || y < r ) a = 1;
    else if (x > W-r || y > H-r) a = 1;
    if (a == 0) cout << "Yes" << endl;
    else if (a == 1) cout << "No" << endl;
}


Measured memory_bytes: 3116
#include <iostream>
#include <algorithm>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <string>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;

#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())

using namespace std;


string isStableSort(string bubble[],string cmpArray[],int N){
    REP(i,N){
        if(bubble[i] != cmpArray[i]){
            return "Not stable";
        }
    }
    return "Stable";
}

void bubbleSort(string array[],int N){
    for(int i = 0;i < N;i++){
        for(int j = N-1;j > i;--j){
            if(array[j][1] < array[j-1][1]){
                swap(array[j],array[j-1]);
            }
        }
    }
}

void selectionSort(string array[],int N){
    for(int i = 0; i < N; i++){
        int minj = i;
        for(int j = i;j < N; j++){
            if(array[j][1] < array[minj][1]){
                minj = j;
            }
        }
        swap(array[i],array[minj]);
    }
}
void printArray(string array[],int N){
    REP(i,N){
        if(i) cout << " ";
        cout << array[i];
    }
    cout << endl;
}



int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string selection[50];
    string bubble[50];
    string tmpSuitNum;
    cin >> N;
    REP(i,N){
        cin >> tmpSuitNum;
        bubble[i] = tmpSuitNum;
        selection[i] = tmpSuitNum;
    }

    bubbleSort(bubble,N);
    selectionSort(selection,N);

    printArray(bubble,N);
    cout << isStableSort(bubble,bubble,N) << endl;
    printArray(selection,N);
    cout << isStableSort(bubble,selection,N) << endl;

    

    return 0;
}


Measured memory_bytes: 3228
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
#define MK make_pair
const ll E=1e18+7;
const ll MOD=1000000007;

vector<vector<ll>> dp(2000,vector<ll>(2000,0));

void DP(){
    dp[0][0]=1;
    for(int i=0;i<2000;i++){
        for(int t=1;t<2000;t++){
            if(i-t>=0){
                dp[i][t]=dp[i][t-1]+dp[i-t][t];
                dp[i][t]%=MOD;
            }
            else{
                dp[i][t]=dp[i][t-1];
            }
        }
    }
}

int main(){
    ll n,k;
    cin>>n>>k;
    DP();
    if(n<k){cout<<0<<endl;}
    else{cout<<dp[n-k][k]<<endl;}
    
    
    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

pll get_rev(pll x){
    ll a = x.first;
    ll b = x.second;
    if (a < 0) return pll(b, -a);
    else return pll(-b, a);
}

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll gcd(ll x, ll y){
    if(y == 0) return x;
    return gcd(y, x % y);
}

const ll mod = (ll)(1e9 + 7);

int main(){
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }

    ll zz = 0;
    ll z_left = 0;
    ll z_right = 0;
    map<pll, ll> mp;

    for (int i = 0; i < n; ++i) {
        if (a[i] == 0 && b[i] == 0) zz++;
        else if (a[i] == 0) z_left++;
        else if (b[i] == 0) z_right++;
        else{
            ll g = gcd(abs(a[i]), abs(b[i]));
            if (b[i] > 0){
                mp[pll(a[i] / g, b[i] / g)]++;
            } else{
                mp[pll(-a[i] / g, -b[i] / g)]++;
            }
        }
    }

    ll res = modpow(2, z_left, mod) + modpow(2, z_right, mod) - 1; // 一つも取らないが重複
    res %= mod;

    set<pll> used;
    for(auto &x : mp){
        if(used.count(x.first)) continue;
        pll p = x.first;
        pll p_rev = get_rev(p);

        if(mp.count(p_rev)){
            res *= modpow(2, mp[p], mod) + modpow(2, mp[p_rev], mod) - 1;
            res %= mod;
            used.insert(p_rev);
        } else{
            res *= modpow(2, mp[p], mod);
            res %= mod;
        }
    }

    res += zz;
    res--; // 何も取らない

    res += mod;
    res %= mod;
    cout << res << endl;
}

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

int main() {
  std::string S, T; std::cin >> S >> T;
  int ans = 0;
  for (int i = 0; i < S.size(); ++i)
    if (S[i] != T[i])
      ans++;
  std::cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 3864
#include<stdio.h>
int main(){
  int n,i,j,key,k;
  int a[1000];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(j=0;j<n;j++){
    key=a[j];
    i=j-1;
    while(i>=0&&a[i]>key){
      a[i+1]=a[i];
      i=i-1;
      a[i+1]=key;
    }
    printf("%d",a[0]);
    for(k=1;k<n;k++){
      printf(" %d",a[k]);
    }
    printf("\n");
  }
  return 0;
}



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

int N, M, Q, L[200009], R[200009], X[509][509], C[509][509];

int main() {
	cin >> N >> M >> Q;
	for (int i = 1; i <= M; i++) {
		cin >> L[i] >> R[i]; X[L[i]][R[i]]++;
	}
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) C[i][j] = C[i][j - 1] + X[i][j];
	}
	for (int i = 1; i <= Q; i++) {
		int p, q; cin >> p >> q;
		int sum = 0;
		for (int j = p; j <= q; j++) sum += C[j][q] - C[j][p - 1];
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 4480
/*#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <array>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <unordered_map>
#include <unordered_set>
*/

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

#define int long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
const ll INF = LLONG_MAX - 100;
const ll mod = 1e9 + 7;
const int MAX_N = 5e5 + 5;
int dx[] = { -1LL,0,1LL,0 }, dy[] = { 0,1LL,0,-1LL };
vector<ll> prime;

ll inv[MAX_N], fac[MAX_N];

inline ll GCD(ll a, ll b) { ll c; while (b != 0) { c = a % b; a = b; b = c; }return a; }
inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
inline ll POW(ll a, ll b) { ll c = 1LL; while (b > 0) { if (b & 1LL) { c = a * c%mod; }a = a * a%mod; b >>= 1LL; }return c; }
inline void _nCr() { fac[0] = 1LL; for (int i = 1LL; i < MAX_N; i++) { fac[i] = fac[i - 1LL] * i%mod; }for (int i = 0; i < MAX_N; i++) { inv[i] = POW(fac[i], mod - 2); } }
inline ll nCr(ll n, ll r) { return (fac[n] * inv[r] % mod)*inv[n - r] % mod; }
inline void PRI(ll n) { bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) { a[i] = 1LL; }for (int i = 2; i < n + 1LL; i++) { if (a[i]) { prime.pb(i); ll b = i; while (b <= n) { a[b] = 0; b += i; } } } }

int dp[100005];
int sum[26];

signed main() {
    int n;cin >> n;
    vector<vector<int>> A(n);
    REP (i,n) {
        int m; cin >> m;
        multiset<int> se;
        REP (j,m) {
            int x; cin >> x;
            se.insert(x);
        }
        int cnt = 0;
        for (auto x = se.rbegin();x != se.rend();x++) {
            if (cnt <= i) {
                A[i].push_back((int)*x);
                cnt++;
            } else {
                break;
            }
        }
    }
    priority_queue<int, vector<int>, greater<int> >p;
    REP (i,n) {
        REP (j,A[i].size()) {
            p.push(A[i][j]);
        }
        int dis = max(0LL,(int)p.size() - (i+1));
        REP (j,dis) {
            p.pop();
        }
    }

    int ans = 0;
    while (!p.empty()) {
        ans += p.top();
        p.pop();
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 23364