akhauriyash/Code-Regression huggingface dataset:
'use strict'

function Main(input) {
  const N = Number(input.split("\n")[0].split(" ")[0])
  let M = Number(input.split("\n")[0].split(" ")[1])
  const shopList = input.split("\n").slice(1).map(x => x.split(" ").map(x => Number(x))).sort((a, b) => a[0] - b[0])
  
  let ans = 0
  for (const shop of shopList) {
    if (shop[1] < M) {
      ans += shop[0] * shop[1]
      M -= shop[1]
    } else {
      ans += shop[0] * M
      break
    }
  }
  
  console.log(ans)
}

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


Measured memory_bytes: 62592
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,w,val,cst,ans=0;
    cin>>n>>w;
    vector<ll>cost(n,0);
    vector<ll>weight(n,0);

    for(ll i=0;i<n;i++)
    {
        cin>>val>>cst;
        weight[i]=val;
        cost[i]=cst;
    }
    ll i=0;
    ll dp[2][w+1];
    memset(dp,0,sizeof(dp));
    while(i<n)
    {
        ll j=0;
        if(i%2!=0)
        {
          while(j<=w)
            {
                if(weight[i]<=j)
                {
                dp[1][j]=max(dp[0][j],dp[0][j-weight[i]]+cost[i]);
                }
                else
                {
                    dp[1][j]=dp[0][j];
                }
                j++;
            }
        }
        else
        {
              while(j<=w)
            {
                if(weight[i]<=j)
                {
                dp[0][j]=max(dp[1][j],dp[1][j-weight[i]]+cost[i]);
                }
                else
                {
                    dp[0][j]=dp[1][j];
                }
                j++;
            }
        }
        
        i++;
    }

    ans=n%2==0?dp[1][w]:dp[0][w];
    cout<<ans<<endl;

    return  0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K, X;
    cin >> K >> X;
    K--;
    REP(i, X - K, X + K) {
        cout << i << " ";
    } 
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXSIZE = 1e4+7;
int num[MAXSIZE];

int n, m;
bool solve(int i, int c){
	if(c == 0) return true;
	if(i >= n) return false;
	return solve(i+1,c-num[i]) || solve(i+1,c);
}
int main(){
	while(~scanf("%d",&n)){
		int temp;
		for(int i = 0; i < n; i++){
			scanf("%d",&num[i]);
		}
		scanf("%d",&m);
		for(int i = 0; i < m; i++){
			scanf("%d",&temp);
			if(solve(0,temp)){
				printf("yes\n");
			}else printf("no\n");
		}
	}
	return 0;
}


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


int main (){
    int N;
    cin>>N;
    vector<string> City(N);
    vector<int> Score(N);
    vector<int> Num(N);
    for(int i=0; i<N; i++){
        cin>>City.at(i)>>Score.at(i);
        Num.at(i)=i;
    }
    for (int i=0; i<N;i++){
        for(int j=i+1;j< N;j++){
            if(City.at(i) > City.at(j)){
                string A=City.at(j);
                City.at(j)=City.at(i);
                City.at(i)=A;
                int B=Num.at(j);
                Num.at(j)=Num.at(i);
                Num.at(i)=B;
                int C=Score.at(j);
                Score.at(j)=Score.at(i);
                Score.at(i)=C;
            }
            if(City.at(i)==City.at(j)){
                if(Score.at(i)<Score.at(j)){
                    string A=City.at(j);
                City.at(j)=City.at(i);
                City.at(i)=A;
                int B=Num.at(j);
                Num.at(j)=Num.at(i);
                Num.at(i)=B;
                int C=Score.at(j);
                Score.at(j)=Score.at(i);
                Score.at(i)=C;
                }
            }
        }
    }
    for(int i=0;i<N;i++){
        cout<<Num.at(i)+1<<endl;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long int s[100009] = {0};
long long int f[100009] = {0};
string z;
long long int n, m, i, x;
int main()
{
    //freopen("test.inp","r",stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> m;
    long long int dem1 = 0, dem2 = 0;
    for (i = 1; i <= m; i++)
    {
        cin >> x >> z;
        if (z == "WA")
        {
            if (s[x] == 0) f[x]++;
        }
        else s[x]++;
    }
    for (i = 1; i <= n; i++)
    {
        if (s[i] != 0) dem1 ++;
        if (s[i] != 0) dem2 += f[i];
    }
    cout << dem1 << " " << dem2;
}


Measured memory_bytes: 1792
/*input
1 1 3
#
*/
#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 2;

char c[8][8];

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

  int h, w, k; cin >> h >> w >> k;
  for (int i = 0; i < h; ++i) {
    cin >> c[i];
    for (int j = 0; j < w; ++j) {
      c[i][j] = (c[i][j] == '#');
    }
  }

  int64_t ans = 0;
  for (int ki = 0; ki < (1 << h); ++ki) {
    for (int kj = 0; kj < (1 << w); ++kj) {
      int cnt = 0;
      for (int i = 0; i < h; ++i) {
        if ((1 << i) & ki) continue;
        for (int j = 0; j < w; ++j) {
          if ((1 << j) & kj) continue;
          cnt += c[i][j];
        }
      }
      ans += (cnt == k);
    }
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define all(x) (x).begin(), (x).end()
#define rsort(x) sort((x).rbegin(), (x).rend())
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n, e) for (int i = (int)(n); i >= (int)(e); --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << (x) << '\n'; return 0;}while(0)

const int MOD = 1e9+7;
const int MAXN = 5e5+3;
const int INF = 1e9;

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    //int ntest; cin >> ntest; while(ntest--)
    {
        LL x; cin >> x;
        LL years = 0, cur = 100;
        while(cur < x) {
            years++;
            cur += cur/100;
        }
        cout << years << endl;
    }

    return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define fo(i,a,b)for(int i=a,_e=b;i<=_e;++i)
#define P pair<int,int>
#define ll long long
using namespace std;
ll s,ss;
int x2,y2,x3,y3;
int main(){
	cin>>s;
	int a=sqrt(s);
	for(;(ll)a*a<s;)++a;
	x2=a;y3=a;
	for(;ss=(ll)x2*y3-s,ss>1e9;)--x2,++y3;
	y2=1;x3=(ll)x2*y3-s;
	printf("%lld %lld %lld %lld %lld %lld\n",0,0,x2,y2,x3,y3);
}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

template <typename T> T &chmin(T &a, const T &b) {return a = min(a, b);}
template <typename T> T &chmax(T &a, const T &b) {return a = max(a, b);}

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);

int table[505][505];

int main(){
  int n, m, Q;
  cin >> n >> m >> Q;
  int l, r;
  int p, q;
  REP(i, m) { cin >> l >> r; table[l-1][r-1]++; }
  REP(i, n) REP(j, n) table[i][j+1] += table[i][j];
  REP(i, n+1) REP(j, n) table[j+1][i] += table[j][i];
  REP(i, Q) { cin >> p >> q; cout << table[q-1][q-1] - (p==1?0:table[q-1][p-2]+table[p-2][q-1]-table[p-2][p-2]) << endl; }
  return 0;
}

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

int main(){
  int m, f, r;
  char grade;

  while(1){
    cin >> m >> f >> r;
    if ( m == -1 && f == -1 && r == -1 ) break;
    if ( m == -1 || f == -1 ) grade = 'F';
    else if ( m + f >= 80 ) grade = 'A';
    else if ( m + f >= 65 ) grade = 'B';
    else if ( m + f >= 50 ) grade = 'C';
    else if ( m + f >= 30 ) {
      if ( r >= 50 ) grade = 'C';
      else grade = 'D';
      }
    else grade = 'F';

    cout << grade <<endl;
  }

  return 0;
}


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

int main() {
  int N, i = 111;
  cin >> N;
  while (true) {
    int a = i - N;
    if (a >= 0) {
      cout << i << endl;
      break;
    }
    else {
      i += 111;
    }
  }
} 


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

//------------------------------------------
//------------------------------------------

int main() {

    int N;
    cin >> N;

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

    sort(A.begin(), A.end());

    LL ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i + 1; j < N; j++) {
            for (int k = j + 1; k < N; k++) {
                if(A[k] < A[i] + A[j]){
                    ans++;
                }else{
                    break;
                }
            }
        }
    }

    printf("%d", ans);

    return 0;
}





















































Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long int  ll;
typedef pair<ll, ll> P;

constexpr int MOD = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template< typename S, typename T >
inline void chmax(S &a, const T &b) { if(a < b) a = b; }
 
template< typename S, typename T >
inline void chmin(S &a, const T &b) { if(a > b) a = b; }
 

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

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

//inversemod//
ll modinv(ll a, ll m) {
	if(m==0)return (ll)1;
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll 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;
	}
}

// 
ll COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}


////////////////////////////////////////////////////////////////////

int main() {
 ios::sync_with_stdio(false);
ll n;
cin>>n;
for(int i=1;i<=10;i++){
	ll k=1000*i;
	if(n<=k){cout<<k-n<<endl;
	return 0;}
}

return 0;
}




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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define REP(i, n) for(ll i = 0LL; i < (ll)(n); i++)
#define REPR(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define FOR(i, n, m) for(ll i = (ll)n; i < (ll)(m); i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define PRINT(x) std::cout << x << endl
 
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dx[8] = {0,1,0,-1, 1, -1, 1, -1}, dy[8] = {1,0,-1,0,1,1,-1,-1};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) os << v[i] << " ";  
    return os; 
}

template <typename T1, typename T2> 
ostream& operator<<(ostream& os, const map<T1, T2>& m) 
{ 
    for (auto p : m) os << "<" << p.first << ", " << p.second << "> "; 
    return os; 
}

int main()
{ 
  ll N;
  string X;
  cin >> N >> X;
  ll pop_cnt = 0;
  REP(i, N) {
    if (X[i] == '1') pop_cnt++;
  }
  
  vector<ll> plus_pows(N);
  plus_pows[0] = 1 % (pop_cnt + 1);
  REP(i, N-1) {
    plus_pows[i+1] = (plus_pows[i] * 2) % (pop_cnt+1);
  }
  ll plus_tmp = 0;
  REP(i, N) {
    if (X[i] == '1') {
      plus_tmp += plus_pows[N-1-i];
      plus_tmp %= (pop_cnt+1);
    }
  }
  if (pop_cnt == 0) {
    REP(i, N) {
      PRINT(1);
    }
    return 0;
  }
  if (pop_cnt == 1) {
    REP(i, N) {
      ll ans = 1;
      if (X[i] == '0') {
        unsigned long long t = plus_tmp;
        t += plus_pows[N-1-i];
        t %= (pop_cnt+1);
        while(t != 0) {
          ll pcnt = __builtin_popcountll(t);
          t %= pcnt;
          ans++;
        }
        PRINT(ans);
      } else {
        PRINT(0);
      }
    }
    return 0;
  }
  vector<ll> minus_pows(N);
  minus_pows[0] = 1;
  REP(i, N-1) {
    minus_pows[i+1] = (minus_pows[i] * 2) % (pop_cnt-1);
  }
  ll minus_tmp = 0;
  REP(i, N) {
    if (X[i] == '1') {
      minus_tmp += minus_pows[N-1-i];
      minus_tmp %= (pop_cnt-1);
    }
  }
  REP(i, N) {
    ll ans = 0;
    if (X[i] == '1') {
      ll tmp = minus_tmp;
      tmp -= minus_pows[N-1-i];
      if (tmp < 0) tmp += (pop_cnt-1);
      ans++;
      unsigned long long t = tmp;
      while(t != 0) {
        ll pcnt = __builtin_popcountll(t);
        t %= pcnt;
        ans++;
      }
    } else {
      ll tmp = plus_tmp;
      tmp += plus_pows[N-1-i];
      tmp %= (pop_cnt+1);
      ans++;
      unsigned long long t = tmp;
      while(t != 0) {
        ll pcnt = __builtin_popcountll(t);
        t %= pcnt;
        ans++;
      }
    }
    PRINT(ans);
  }
  return 0;
} 


Measured memory_bytes: 6832
#include <bits/stdc++.h>
#include <ext/rope>
#define VALHALLA cin.tie(0);ios_base::sync_with_stdio(false);cout<<fixed<<setprecision(13);
#define endl "\n"
#define pb push_back
#define all(v) v.begin(),v.end()
#define debug(x) std::cerr << #x << ": " << (x) << '\n';
#define sz(x) (int)x.size()
#define fast(map_name) map_name.reserve(1024);map_name.max_load_factor(0.25);
using namespace std;
using namespace __gnu_cxx;
typedef long long int ll;
typedef pair<int,int> ii;
typedef complex<double> point;
const double epsilon=1e-9;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mod=1e9+7;
/* VARIABLE DECLARATION START */
/*  FUCNTION TEMPLATE STARTS  HERE */

double dot(point a,point b){ return (conj(a)*b).real() ; }
double cross(point a,point b){ return (conj(a)*b).imag() ; }
double dist(point a, point b){ return abs(a-b); }
struct neal {
static uint64_t splitmix64(uint64_t x)
 {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const
 {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
}
};
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};
bool isprime(ll n) {
    if (n == 2 || n == 3) return true;
    if (n < 2 || n % 2 == 0 || n % 3 == 0) return false;
    for (ll i = 6; (i - 1) * (i - 1) <= n; i += 6) {
        if (n % (i - 1) == 0 || n % (i + 1) == 0) {
            return false;
        }
    }
    return true;
}
inline ll exp(ll a, ll b, ll mod) {
    ll n = 1;
    ll p = a;
    while (b > 0) {
        if (b % 2 == 1) {
            n *= p;
            n %= mod;
        }
        p *= p;
        p %= mod;
        b /= 2;
    }
    return n;
}

inline bool comp(double a,double b)
{
  return (fabs(a-b)<epsilon);
}
ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}


/*  FUCNTION TEMPLATE ENDS HERE */
int main()
{
   VALHALLA
   string s;cin>>s;
   int n=sz(s);
   ll sum=0;
   for(int i=1;i<(1<<(n-1));++i)
   {
     int end=n;
     int num=i;
     int it=n-1;
     while(num>0)
     {
      if(num%2)
      {
        string news=s.substr(it,end-it);
        sum+=(stoll(news));
        end=it;
      }
      num/=2;
      --it;
     }
     string news=s.substr(0,end);
     sum+=(stoll(news));
   }

   cout<<sum+stoll(s)<<endl;

}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int total, h, m, s;
    scanf("%d", &total);
    h = total / 3600;
    s = total % 3600;
    m = s / 60;
    s %= 60;
    printf("%d:%d:%d\n", h, m, s);
    return 0;
}


Measured memory_bytes: 2048
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>

    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    using namespace std;
    using ll = long long;


    int main(){
      int n,q;
      string s;
      cin>>n>>q>>s;
      auto cnts = vec(int,n);
      cnts[0] = 0;
      REP(i,1,n-1){
        cnts[i] = cnts[i-1];
        if(s.substr(i-1,2) == "AC")cnts[i]++;
      }

      rep(i,q){
        int a,b;
        cin>>a>>b;
        a--;b--;
        cout<<cnts[b]-cnts[a]<<endl;
      }
      
    }
      


Measured memory_bytes: 1408
n = input()
s = input()

ans = 0

for i in range(len(s) - 2):
    s1 = list(set(s[:i + 1]))
    s2 = list(set(s[i + 1:]))

    j = 0
    for x in s1:
        if x in s2:
            j += 1
    ans = max(ans, j)

print(ans)


Measured memory_bytes: 3060
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)

	A, B := 1, 1
	var x, y int
	for i := 0; i < N; i++ {
		fmt.Scan(&x, &y)
		n := max((A+x-1)/x, (B+y-1)/y)
		A, B = x*n, y*n
	}
	fmt.Println(A + B)
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}


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

int gcd(int a, int b){
    while(a != b){
        if(a > b) a = a - b; else b = b - a;
    }
    return a;
}

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

int main(){
    int h, w;
    while(true){
char torus[10][20];
        string str[2048];
        bool ok[2048];
        int num = 0;

        for(int i=0; i<2048; ++i){
            str[i] = "";
            ok[i] = true;
        }

        cin >> h >> w;
        if(h==0 && w==0) break;

        int cml = lcm(w, h);

        for(int i=0; i<h; ++i){
            for(int j=0; j<w; ++j){
                cin >> torus[i][j];
            }
        }

        //一番長い文字列をつくる

        for(int y=0; y<h; ++y){
            for(int x=0; x<w; ++x){
                for(int i=0; i<h; ++i){
                    str[num] += torus[(y+i)%h][x];
                    str[num+1] += torus[h-(y+i)%h-1][x];
                }
                num += 2;
            }
        }
        for(int y=0; y<h; ++y){
            for(int x=0; x<w; ++x){
                for(int i=0; i<w; ++i){
                    str[num] += torus[y][(x+i)%w];
                    str[num+1] += torus[y][w-(x+i)%w-1];
                }
                num += 2;
            }
        }
        for(int y=0; y<h; ++y){
            for(int x=0; x<w; ++x){
                for(int i=0; i<cml; ++i){
                    str[num] += torus[(y+i)%h][(x+i)%w];
                    str[num+1] += torus[(y+i)%h][w-(x+i)%w-1];
                    str[num+2] += torus[h-(y+i)%h-1][(x+i)%w];
                    str[num+3] += torus[h-(y+i)%h-1][w-(x+i)%w-1];
                }
                num += 4;
            }
        }


        vector<char> result;

        sort(str, str+num);

        for(int i=num-1; i>0; --i){
            int length = 0;
            vector<char> k;
            for(int j=0; j<min(str[i].length(), str[i-1].length()); ++j){
                if(str[i][j] == str[i-1][j]) k.push_back(str[i][j]); else break;
            }
            if(k.size() >= result.size()){
                result = k;
            }
        }

        if(result.size() == 1){
            cout << "0" << endl;
        }else{
            vector<char>::iterator it = result.begin();
            while( it != result.end()){
                cout << *it;
                ++it;
            }
            cout << endl;
        }
    }

    return 0;
}

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

int main() {

    int n;
    cin >> n;
    vector<int64_t> a(100001,0);
    int64_t sum = 0;
    for (int i = 0; i < n; i++) { // 1~10000の各数を数列がそれぞれいくつ含むかを調べるための配列
        int x;
        cin >> x;
        a.at(x)++; 
        sum += x; // 数列の和
    }
    
    int q;
    cin >> q;
    vector<int64_t> answer(q,0);
    for (int i = 0; i < q; i++) {
        int b, c;
        cin >> b >> c;
        sum += (c - b) * a.at(b); // 数列の和を更新
        answer.at(i) = sum;
        a.at(c) += a.at(b);
        a.at(b) = 0;
    }

    for (int64_t ans : answer) {
        cout << ans << endl;
    }
}

Measured memory_bytes: 4824
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int a,b,c,k;
int main(void){
    cin>>a>>b>>c>>k;
    while(k--){
        if(a>=b){
            b=b*2;
        }else if(b>=c){
            c=c*2;
        }
        //cout<<a<<" "<<b<<" "<<c<<endl;
    }
    if(a<b&&b<c){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

}



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

int main(){
  vector<int> A(5);
  int k;
  for(int i=0; i<5; i++){
    cin >> A.at(i);
  }
  cin >> k;
  sort(A.begin(), A.end());
  if(k<A.at(4)-A.at(0)){
    cout << ":(" << endl;
  }
  else{
    cout << "Yay!" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

#define _GLIBCXX_DEBUG
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    string s;
    cin >> s;
    char a,b,c,d;
    a = s.at(0);
    b = s.at(1);
    c = s.at(2);
    d = s.at(3);
    if((a == b && c==d && a != c) ||
       (a == c && b==d && a != b) ||
       (a == d && b==c && a != b)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
 }


Measured memory_bytes: 256
#!python3

iim = lambda: map(int, input().rstrip().split())
from collections import deque

def resolve():
    N = int(input())
    S = tuple("abcdefghij")

    q = deque([("", 0, 0)])
    ans = []
    while q:
        #print(q)
        s1, i1, i2 = q.popleft()
        #print(s1, i1, i2)

        if i1 == N:
            ans.append(s1)
            continue
        for i in range(i2):
            q.append((s1+S[i], i1+1, i2))
        q.append((s1+S[i2], i1+1, i2+1))

    print(*ans, sep="\n")


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 23960
//#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main()
{
	int i = 0,count = 0;
	char c1[11],c2[10000];
	scanf("%s",c1);
	while (scanf("%s", c2)!=EOF)
	{
		if (!strcmp(c2, "END_OF_TEXT")) break;
		for (i = 0; i < strlen(c2); i++)
		{
			c2[i] = tolower(c2[i]);
		}
		if (strcmp(c1, c2) == 0){ count++; }
	}
	printf("%d\n",count);
	return 0;

}

Measured memory_bytes: 560
import std.stdio;

void main() {
    int n;
    readf("%d\n", &n);
    long[long] f;
    for(int x = 1; x*x <= n; x++) {
        for(int y = 1; y*y <= n; y++) {
            for(int z = 1; z*z <= n; z++) {
                long result = x*x+y*y+z*z+x*y+y*z+z*x;
                if(result in f) {
                    f[result] += 1;
                } else {
                    f[result] = 1;
                }
            }
        }
    }
    for(int i = 1; i <= n; i++) {
        if(i in f)
            f[i].writeln;
        else
            0.writeln;
    }
}


Measured memory_bytes: 6016
#include<cstdio>

int a[100000];

int abs(int x) {
	return x > 0 ? x : -x;
}

int main() {
	int n;
	scanf("%d", &n);
	for(int i=0;i<n;i++) {
		scanf("%d", &a[i]);
	}
	int sum = abs(a[0]) + abs(a[n-1]);
	for(int i=1;i<n;i++) sum += abs(a[i] - a[i-1]);
	for(int i=0;i<n;i++) {
		int x = i > 0 ? a[i-1] : 0;
		int y = a[i];
		int z = i+1 < n ? a[i+1] : 0;
		printf("%d\n", sum - abs(y-x) - abs(z-y) + abs(z-x));
	}
	return 0;
}


Measured memory_bytes: 1536
#E
#greedy 
n = input()
l = len(n)

#a is kuriagari naku, pittari na case
#b is kuriagari ari
a,b = 0,1
for v in n:
    v = int(v)
    a_next = min(a+v, b+(10-v))
    b_next = min(a+v+1, b+(10-(v+1)))
    a = a_next
    b = b_next
    
    #繰り上がりが発生する⇔引く数を+1する
    #(10-v)や(10-(v+1)) means charges
    #last keta is pittari, no amari happenes

print(a)

Measured memory_bytes: 5492
n,k = gets.split.map(&:to_i)
as = gets.split.map(&:to_i)

TEL = Array.new(n+1,0)

as.each.with_index do |to, from|
  TEL[from+1] = to
end

def detect_cycle(head)
  slow = head
  fast = head

  while true do
    slow = TEL[slow]
    fast = TEL[TEL[fast]]
    break if slow == fast
  end
  
  slow = head
  
  while slow != fast do    
    slow = TEL[slow]
    fast = TEL[fast]
  end
  slow
end

cycle_start = detect_cycle(1)

# count moves before cycle
before_cycle = 0
before_ar = []

if cycle_start != 1
  before_cycle = 1
  current = TEL[1]
  before_ar = [1,current]

  while current != cycle_start do
    current = TEL[current]
    before_cycle += 1
    before_ar.push current
  end
end

if k <= before_cycle
  puts before_ar[k]
  exit 0
end

# count of cycle
current = TEL[cycle_start]
ar = [cycle_start, current]

while current != cycle_start do
  current = TEL[current]
  ar.push current if current != cycle_start
end


i = (k-before_cycle) % ar.size
puts ar[i]



Measured memory_bytes: 30320
n = input()
i = 1
num = []
while i <= n:
    if i % 3 == 0:
        num.append(i)
        i +=1
    else:
        x = i
        while x > 0:
            if x % 10 == 3:
                num.append(i)
                break
            else:
                x /=  10                
        i += 1
print("{}".format(str(num)).replace("["," ").replace("]","").replace(",",""))

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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

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

template <typename A, typename B>
string to_string(pair<A, B> p){
    return "(" + to_string(p.fi) + ", " + to_string(p.se) + ")";
}

template <typename T>
string to_string(T v){
    string s = "{";
    bool first = true;
    for(const auto & x : v){
        if(!first) s += ", ";
        first = false;
        s += to_string(x);
    }
    return s + "}";
}

void debug_out(){ cerr << endl;}
template <typename First, typename... Next>
void debug_out(First F, Next... N){
    cerr << " " << to_string(F);
    debug_out(N...);
}

#ifdef LOCAL
    #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 1
#endif


int n;
const int N = 2e5 + 5;
ll fat[N], ifat[N];

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

ll add(ll x, ll y){
    x += y;
    if(x >= MOD) x -= MOD;
    return x;
}

ll sub(ll x, ll y){
    x -= y;
    x += MOD;
    if(x >= MOD) x -= MOD;
    return x;
}

ll mul(ll x, ll y){
    return (x % MOD * y % MOD) % MOD;
}

ll pwr(ll x, ll p){
    if(p == 0) return 1;
    if(p == 1) return x;
    if(p&1) return mul(x, pwr(x, p-1));
    ll t = pwr(x, p/2);
    return mul(t, t);
}

ll inv(ll x){
    return pwr(x, MOD-2);
}


void pre(){
    fat[0] = 1LL;
    ifat[0] = 1LL;
    for(int i = 1; i < N; i++){
        fat[i] = mul(fat[i-1], i);
        ifat[i] = inv(fat[i]);
    }
}

int st[N];
int dp[N];
vector<int> e[N];

void dfs(int u, int p=-1){
    st[u] = 1;
    dp[u] = 1;
    for(int v : e[u]){
        if(v == p) continue;
        dfs(v, u);
        st[u] += st[v];
        dp[u] = mul(dp[u], dp[v]);
        dp[u] = mul(dp[u], ifat[st[v]]);
    }
    dp[u] = mul(dp[u], fat[st[u]-1]);
}

int ans[N];
void root(int u, int p=-1){
    int old_dpp, old_dpu, old_stp, old_stu;

    if(p != -1){
        old_dpp = dp[p];
        old_dpu = dp[u];
        old_stp = st[p];
        old_stu = st[u];

        dp[p] = mul(dp[p], inv(dp[u]));
        st[p] -= st[u];
        dp[p] = mul(dp[p], fat[st[u]]);
        dp[p] = mul(dp[p], ifat[old_stp-1]);
        dp[p] = mul(dp[p], fat[st[p]-1]);

        st[u] += st[p];
        dp[u] = mul(dp[u], dp[p]);
        dp[u] = mul(dp[u], ifat[st[p]]);
        dp[u] = mul(dp[u], ifat[old_stu-1]);
        dp[u] = mul(dp[u], fat[st[u]-1]);
    }

    for(int v : e[u]){
        if(v == p) continue;
        root(v, u);
    }
    
    ans[u] = dp[u];
    if(p != -1){
        dp[p] = old_dpp;
        st[p] = old_stp;

        dp[u] = old_dpu;
        st[u] = old_stu;
    }
}

int main(){
    fcin;
    pre();
    cin >> n;
    for(int i = 0; i < n - 1; i++){
        int u, v;
        cin >> u >> v;
        e[u].pb(v);
        e[v].pb(u);
    }

    dfs(1);
    root(1);

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



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

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

    vector<int> p(N);
    int ans = 0;

    for (int i=0; i<N; i++){
        cin >> p.at(i);
    }

    sort(p.begin(),p.end());

    for (int i=0; i<K; i++){
        ans += p.at(i);
    }

    cout << ans << endl;

}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  ll n, m;
  cin >> n >> m;
  ll sum = 0;
  vector <ll> v(n);
  rep(i, n) {
    cin >> v.at(i);
    sum += v.at(i);
  }
  ll res = 0;
  ll flag;
  if (sum%(4*m)) flag = sum/(4*m) + 1;
  else flag = sum/(4*m);
  rep(i, n) {
    if (v.at(i) >= flag) res++;
  }
  if (res >= m) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3628
{-# LANGUAGE Strict #-}
import qualified Data.ByteString.Char8 as B
import           Data.List             (sort, unfoldr)


main :: IO ()
main = do
  [n, m] <- readIntsLn
  as <- readIntsLn
  putStrLn $ if solve n m as then "Yes" else "No"

solve :: Int -> Int -> [Int] -> Bool
solve _ m as = all (>= (s + (4 * m) - 1) `div` (4 * m)) (take m as')
  where as' = reverse $ sort as
        s = sum as

readIntsLn :: IO [Int]
readIntsLn = unfoldr (B.readInt . B.dropWhile (== ' ')) <$> B.getLine


Measured memory_bytes: 3776
n, k = map(int, input().split())
x = list(map(int, input().split()))
d = [0 for _ in range(n)]
S = [0 for _ in range(n)]
for i in range(1, n):
    d[i] = x[i] - x[i - 1]
    S[i] = S[i - 1] + d[i]
tmp = [0 for _ in range(n - k + 1)]
for i in range(n - k + 1):
    tmp[i] = S[i + k - 1] - S[i] + min(abs(x[i]), abs(x[i + k - 1]))
print(min(tmp))


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

int main(){
    int inputSec,hor,min,sec;
    cin >> inputSec;
    hor = inputSec / 3600;
    min = inputSec % 3600 / 60;
    sec = inputSec % 3600 % 60;
    cout << hor << ":" << min << ":" << sec << endl;
    return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N;
  int result = 10000000;
  int k;
  int flag = 0;
  cin >> N;
  vector<char> A(N);
  vector<int> B(N,0);
  vector<int> C(N+1,0);
  int red = 0;
  int white = 0;
  for(int a = 0;a < N;a++)cin >> A[a];
  for(int a = 0;a < N;a++){
    if(a >= 1)C[a+1] = C[a];
    if(A[a] == 'R'){
      red++;
      C[a+1]++;
    }
    if(A[a] == 'W')white++;
  }
  for(int a = 0;a <= N;a++){
    k = 0;
    int m = a - C[a];
    int n = red - C[a];
    k = min(m,n) + abs(m - n);
    
    
    
    
    
    result = min(result,k);
  }
  
  cout << result << endl;
}

Measured memory_bytes: 5036
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dbl;
#define sqr(int) (int * int)
#define sqr3(int) (int * int * int)
#define pi M_PI
#define nl "\n"


void solve(){
	string a;
	int sum = 0;
	getline(cin, a);
	for(int i = 0; i<a.size(); i++){
		sum += int(a[i] - 48);
	}
	if(sum % 9 == 0){
		cout << "Yes";
	}
	else{
		cout << "No";
	}

}


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




Measured memory_bytes: 3752
import scala.io.Source.stdin

object Main extends App {
  def decode(s:String) = {
    def scan(t:String,i:Int):String = {
      if(i >= s.length) t
      else {
        if(s(i) == '@') scan(t + (s(i+2).toString * s(i+1).asDigit),i+3)
        else scan(t + s(i),i+1)
      }
    }
    scan("",0)
  }

  stdin.getLines.foreach { s=> println(decode(s)) }
}

Measured memory_bytes: 43752
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<string>
#include<climits>
#include<stack>
#include<queue>
#include<unordered_map>
#include<map>
#include<set>
#include <fstream>
#include<list>

#define loopi(x,y) for(int i = x;i<(y);i++)
#define loopj(x,y) for(int j = x;j<(y);j++)
#define rloopi(x,y) for(int i = x;i>=(y);i--)
#define rloopj(x,y) for(int j = x;j>=(y);j--)


#define nl cout<<"\n";
#define ll long long int
#define mod  1000000007


using namespace std;

int main()
{

	ios :: sync_with_stdio(false);
	cin.tie(nullptr);

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

	int n, x, t;
	cin >> n >> x >> t;

	int ans = ceil(1.0 * n / x) * t;

	cout << ans;


	return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vch = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
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;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;
const db pi = acos(-1.0L);

int main(){
  ll n;
  cin >> n;
  vll cost(n), limit(n);
  rep(i, 0, n) cin >> cost.at(i) >> limit.at(i);
  vll ord(n);
	iota(ord.begin(),ord.end(),0);
	sort(ord.begin(),ord.end(),[&](int x,int y){
		return limit.at(x) < limit.at(y);
	});

  ll now = 0;
  bl check = true;
  rep(i, 0, n){
    now += cost.at(ord.at(i));
    if(limit.at(ord.at(i)) < now) check = false;
  }
  cout << (check ? "Yes" : "No") << endl;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline bool chmin(A &a,const B &b){if(a>b){a=b;return true;}else{return false;}}
template<typename A,typename B>inline bool chmax(A &a,const B &b){if(a<b){a=b;return true;}else{return false;}}

int main()
{
    ll N,M;
    cin >> N >> M;
    ll cc = M/2;
    M %= 2;
    ll ans = 0;
    if(N <= cc){
        ans += N;
        cc -= N;
    }else{
        cout << cc << endl;
        return 0;
    }
    M += cc*2;
    ans += (M/4);
    cout << ans << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <cstring>
using namespace std;
typedef long long int ll;

int n;
int p[]={5,12,17,24,31};

void solve(){
	vector<int> a(n+1);
	for(int i=0;i<n;i++){
		string s; cin >> s;
		a[i+1]=a[i]+(int)s.size();
	}
	for(int i=0;i<n;i++){
		int j=0;
		for(int k=i+1;k<=n;k++){
			if(a[k]==a[i]+p[j]){
				j++;
				if(j==5)break;
			}
		}
		if(j==5){
			printf("%d\n",i+1 );
			return;
		}
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	while(1){
		cin >> n;
		if(n==0)break;
		solve();
	}
}


Measured memory_bytes: 3292
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[int(input()) - 1])


Measured memory_bytes: 9104
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
signed main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n; cin >> n;
  vi a(n); for (int i = 0; i < n; i++) cin >> a[i];
  sort(a.begin(), a.end());
  if (a.back() - a.front() > 1) cout << "No" << "\n";
  else if (a.back() == a.front()) {
    if (a.front() == n - 1 or a.front() <= n / 2) cout << "Yes" << "\n";
    else cout << "No" << "\n";
  } else {
    int u = upper_bound(a.begin(), a.end(), a.front()) - lower_bound(a.begin(), a.end(), a.front());
    if (u <= n - 2 and u + 1 <= a.back() and a.back() <= u + (n - u) / 2) cout << "Yes" << "\n";
    else cout << "No" << "\n";
  }
  return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define endl "\n"
using namespace std;

int32_t main(){
	int n;
	cin >> n;
	set<int> ans;
	int curr = 2;
	if(n == 3){
		cout << "2 5 63" << endl;
		return 0;
	}
	n-=2;
	ans.insert(3);
	ans.insert(29997);
	while(curr < 30000 - curr && n > 1){
		n-=2;
		ans.insert(curr);
		ans.insert(30000 - curr);
		curr += 2;
	}
	curr = 9;
	while(curr < 30000 - curr && n > 1){
		n-=2;
		ans.insert(curr);
		ans.insert(30000 - curr);
		curr += 3;
		while(curr%2 == 0) curr += 3;
	}
	curr = 5;
	while(curr < 30000 - curr && n > 1){
		n-=2;
		ans.insert(curr);
		ans.insert(30000 - curr);
		curr += 5;
		while(curr%2 == 0 || curr%3 == 0) curr += 5;
	}
	if(n == 1) ans.insert(30000);
	for(int x : ans){
		if(x == *ans.begin()) cout << x;
		else cout << " " << x;
	}
	cout << endl;
}

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

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

  bool flg = false;
  for (int i=1; i<=m; i++) {
    int l = i;
    int r = n-i;
    if (n%2==0 && !flg && r-l <= n/2) flg = true;
    if (flg) r--;
    printf("%d %d\n", l, r);
  }

  return 0;
}


Measured memory_bytes: 3732
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
    int a,b,c;
    cin >> a >> b >> c;

    if(a < b){
	if(a< c && c < b)Yes;
	else No;	 
    }else{
	if(b< c && c < a)Yes;
	else No;
    }
    return  0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n, k; cin >> n >> k;
  int a = 1;
  for (int i = 0; i < n; i++) a = min(2 * a, a + k);
  cout << a << '\n';
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<cstring>
using namespace std;
int pa[111111],id[111111],cnt,rk[111111];
bool used[111111];
int n,m,x,y,z;
vector<pair<int,int> > g[1111111];
vector<int> gra[1111111];
void Init(int i)
{
	pa[i]=i;
	used[i]=0;
	id[i]=-1;	
	rk[i]=1;
}
int root(int x)
{
	if (pa[x]!=x) pa[x]=root(pa[x]);
	return pa[x];
}
void Union(int x,int y)
{
	int rx=root(x),ry=root(y);
	if (rx==ry) return;
	if (rk[rx]>rk[ry]) 
	{
		pa[ry]=rx;
		rk[rx]+=rk[ry];
	}
	else 
	{
		pa[rx]=ry;
		rk[ry]+=rk[rx];
	}
}
queue<int> q;
int dist[444444];
int main()
{
	while(scanf("%d%d",&n,&m)==2)
	{
		for (int i=1;i<=n;i++) g[i].clear();
		for (int i=1;i<=400000;i++) gra[i].clear();
		for (int i=1;i<=m;i++)
		{
			scanf("%d%d%d",&x,&y,&z);
			g[z].push_back(make_pair(x,y)); 
		}
		cnt=n;
		memset(used,0,sizeof(used));
		for (int i=1;i<=1000000;i++)
		{
			for (int j=0;j<g[i].size();j++)
			{
				Init(g[i][j].first);
				Init(g[i][j].second);
			}
			for (int j=0;j<g[i].size();j++)
			{
				Union(g[i][j].first,g[i][j].second);
			}
			for (int j=0;j<g[i].size();j++)
			{
				x=g[i][j].first;y=g[i][j].second;
				if (!used[x])
				{
					int r=root(x);
					if (!~id[r]) id[r]=++cnt;
					used[x]=1;
					gra[x].push_back(id[r]);
					gra[id[r]].push_back(x); 
				}
				if (!used[y])
				{
					int r=root(y);
					if (!~id[r]) id[r]=++cnt;
					used[y]=1;
					gra[y].push_back(id[r]);
					gra[id[r]].push_back(y);  
				}
			}
		}
		memset(dist,-1,sizeof(dist));
		q.push(1);dist[1]=0;
		while(!q.empty())
		{
			x=q.front();q.pop();
			for (int i=0;i<gra[x].size();i++)
			{
				int to=gra[x][i];
				if (!~dist[to])
				{
					dist[to]=dist[x]+1;
					q.push(to); 
				}
			}
		}
		if (!~dist[n]) printf("-1\n");
		else printf("%d\n",dist[n]/2);
	}
	return 0;
}

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

#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)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
const long long MOD = 1e9 + 7;
///////////////////////////////////////////////
// for template
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;
}
///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
int main() {
    int X,Y; cin >> X >> Y;
    FORq(i,0,100){
        FORq(j,0,100){
            if ((i + j == X) and (2 * i + 4 * j == Y)){
                puts("Yes");
                return 0;
            }
        }
    }
    puts("No");
    return 0;
}

Measured memory_bytes: 3588