akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define MOD 10000007
#define f first
#define s second
#define es " "
#define pb push_back
#define endl "\n"
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define ll long long int
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

ll mdc(ll a, ll b){
    if(b==0){
        return a;
    }
    return mdc(b, a%b);
}

int primo(ll atual){
    if(atual==1) return 1;
    for(ll i=2; i*i<=atual; i++){
        if(atual%i==0){
            return 0;
        }
    }
    return 1;
}

int main(){
    fastio;
    ll x, y;
    cin >> x >> y;
    if(x<y){
        swap(x, y);
    }
    ll gdc=mdc(x, y);
    vector<ll> div;
    //cout << gdc << endl;
    div.pb(gdc);
    if(gdc!=1){
        div.pb(1);
    }
    for(ll i=2; i*i<gdc; i++){
        if(gdc%i==0){
            div.pb(i);
            div.pb(gdc/i);
        }
    }
    ll primos=0;
    for(ll i=0; i<div.size(); i++){
        if(primo(div[i])){
            primos++;
        }
    }
    cout << primos << endl;
    return 0;

}

Measured memory_bytes: 384
//=============================================================
// Name        : d
// Date        : Mon Jun 10 14:10:24 CST 2019
// Author      : landcold7
// Description : Actions speak louder more than words
//=============================================================
#include <bits/stdc++.h>
using namespace std;

#define x first
#define y second
#define sz(x) ((int)(x).size())
#ifndef _has_trace
#define trace(...)
#endif
typedef long long ll;

void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  ll ans = 0;
  for (int i = 0; i <= m; ++i) {
    for (int j = 0; j <= m; ++j) {
      int op = i + j;
      if (op <= m && op <= n) {
        ll tmp = 0;
        vector<int> b;
        for (int k = 0; k < i; ++k) {
          b.push_back(a[k]);
          tmp += a[k];
        }
        for (int k = n - j; k < n; ++k) {
          b.push_back(a[k]);
          tmp += a[k];
        }
        trace(b, tmp, op);
        sort(b.begin(), b.end());
        for (int k = 0; k < sz(b) && op < m; ++k) {
          if (b[k] < 0) {
            op++;
            tmp -= b[k];
          } else {
            break;
          }
        }
        ans = max(ans, tmp);
      }
    }
  }
  cout << ans << "\n";
}

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


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

typedef struct {
  int par, l_ch, r_sib, depth;
} node;

#define MAX_N 100000

node T[MAX_N];
int num;

void dfs(int u, int d) {
  T[u].depth = d;
  if(T[u].r_sib != -1) dfs(T[u].r_sib, d);
  if(T[u].l_ch != -1) dfs(T[u].l_ch, d+1);
}

int main() {
  int i, j;
  {
    for(i = 0; i < MAX_N; i++) {
      T[i] = (node){-1, -1, -1, -1};
    }
  }
  {
    scanf("%d", &num);
    for(i = 0; i < num; i++) {
      int id, k, p;
      scanf("%d %d", &id, &k);
      p = -1;
      for(j = 0; j < k; j++) {
        int e;
        scanf("%d", &e);
        if(T[id].l_ch == -1) T[id].l_ch = e;
        else T[p].r_sib = e;
        p = e;
        T[e].par = id;
      }
    }
  }
  {
    int root = -1;
    for(i = 0; i < num; i++) {
      if(T[i].par == -1) root = i;
    }


    dfs(root, 0);

    for(i = 0; i < num; i++) {
      char type[256];
      if(T[i].par == -1) strcpy(type, "root");
      else if(T[i].l_ch == -1) strcpy(type, "leaf");
      else strcpy(type, "internal node");
      printf("node %d: parent = %d, depth = %d, %s, ", i, T[i].par, T[i].depth,\
 type);
      printf("[");
      if(T[i].l_ch != -1) {
        int p = T[i].l_ch;
        printf("%d", T[i].l_ch);
        while(T[p].r_sib != -1) {
          printf(", %d", T[p].r_sib);
          p = T[p].r_sib;
        }
      }
      puts("]");
    }
  }


  return 0;
}




Measured memory_bytes: 6464
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
const int MN = 100100;
bool bs[50][MN];
int main() {
	memset(bs,false,sizeof(bs));
	int n;
	cin >> n;
	queue<ii> q;
	//SUM MOD
	q.push({0,0});
	bs[0][0] = true;
	while(!q.empty()) {
		ii p = q.front();q.pop();
		int a = p.first,b = p.second;
		for(int i=0;i<=9;i++) {
			int u = a+i;
			int v = (b*10+i)%n;
			if(u >= 50) continue;
			if(bs[u][v]) continue;
			bs[u][v] = true;
			q.push({u,v});
		}
	}
	int mi = -1;
	for(int i=1;i<50;i++) {
		if(bs[i][0]) {mi = i;break;}
	}
	cout << mi << '\n';
}

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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d ;
  if (a+b > c+d){
    cout << "Left" << endl;
  }
  else if (a+b < c+d){
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
using namespace std;
int main() {
    long long N, A, B;
    cin >> N >> A >> B;
    if (N == 1 && A==B){
        cout << "1" << endl;
        return 0;
    }else if( A>B || B-A > N){
        cout << "0" << endl;
        return 0;
    }
   
    long long ans = (N-2)*(B-A)+1;
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	string s, t;
	cin >> s >> t;
	int a[26] = {}, b[26] = {};
	for (int i = 0; i < s.size(); i++) {
		a[s[i] - 'a']++;
	}
	for (int i = 0; i < t.size(); i++) {
		b[t[i] - 'a']++;
	}
	int cnt = 0;
	for (int i = 0; i < 26; i++) {
		if (a[i] > 0) {
			s[cnt] = i + 'a';
			a[i]--;
			i--;
			cnt++;
		}
	}
	cnt = 0;
	for (int i = 25; i >= 0; i--) {
		if (b[i] > 0) {
			t[cnt] = i + 'a';
			b[i]--;
			i++;
			cnt++;
		}
	}
	if (s < t) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m; i<n; i++)
#define co(n) cout << n << endl
using namespace std;
int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a==b) co(c);
  else if(b==c) co(a);
  else co(b);
  
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    char S[4];
    scanf("%s",S);
    if(S[0]==S[1]){
        if(S[2]==S[3] && S[0]!=S[2]){
            printf("Yes\n");
        }
        else
        {
            printf("No\n");
        }
        
    }
    else if(S[0]==S[2]){
        if(S[1]==S[3]&& S[0]!=S[1]){
            printf("Yes\n");
        }
        else {
            printf("No\n");
        }
    }
    else if(S[0]==S[3]){
        if(S[1]==S[2]&& S[0]!=S[1]){
              printf("Yes\n");
        }
        else {
            printf("No\n"); 
        }
    }
    else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (4) << f << endl; Prints x.xxxx


using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);  
char s[60][60],str[60][60]; 
int n,m;
int check(int a,int b){
	if(a+m-1>=n || b+m-1>=n)
		return 0;
	int i,j;
	rep(i,m){
		rep(j,m){
			if(str[i][j]!=s[i+a][j+b])
				return 0;
		}
	}
	cout<<"Yes"<<endl;
	exit(0);
}
int main(){
	std::ios::sync_with_stdio(false);
	int i,j;
	cin>>n>>m;
	rep(i,n){
		rep(j,n)
			cin>>s[i][j];
	}
	rep(i,m){
		rep(j,m)
			cin>>str[i][j];
	}
	rep(i,n){
		rep(j,n)
			check(i,j);
	}
	cout<<"No"<<endl;


}


Measured memory_bytes: 256
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back

/*
#ifdef IZI_KATKA
#define int __int64_t
#else
#define int __int64
#endif
*/

const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;

typedef long long ll;

long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}

int a[MAXN];
map <int, int> cnt;

bool cmp(pair <int, int> a, pair <int, int> b) {
	return a.S < b.S;
}

int main() {
	#ifdef IZI_KATKA
	assert(freopen("input", "r", stdin));
    assert(freopen("output", "w", stdout));
    #endif
    int n = readInt(), k = readInt();
    for (int i = 1; i <= n; i++) {
   		a[i] = readInt();
   		cnt[a[i]]++;
   	}	
	vector <pair <int, int> > v;
	for (auto i : cnt) {
		v.pb(i);
	}
	int kek = v.size();
	sort(v.begin(), v.end(), cmp);
	int ans = 0;
	for (int i = 0; i < v.size() && kek > k; i++) {
		ans += v[i].S;		
		kek--;
	}
	cout << ans;
    return 0;
}

Measured memory_bytes: 12536
N, K = list(map(int, input().split(' ')))
odds = 0
evens = 0
for i in range(1, N+1):  # 2e5
  if i % K == 0:  # (a+b) % k == 0 and ... => (a*k + b*k) % k = 0
    odds += 1
  elif K % 2 == 0 and i % (K//2) == 0:  # (a*(K/2) + b*(K/2)) % k | a, b >= 1, 
    evens += 1
print(odds ** 3 + evens ** 3)

Measured memory_bytes: 3060
C = [[int(i) for i in input().split()] for k in range(3)]
tC = [list(k) for k in zip(*C)]
for i in range(2):
    p = [C[i][k]-C[i+1][k] for k in range(3)]
    tp = [tC[i][k]-tC[i+1][k] for k in range(3)]
    if p[0] == p[1] == p[2] and tp[0] == tp[1] == tp[2]:
        continue
    else:
        print("No")
        exit()
else:
    print("Yes")


Measured memory_bytes: 3064
A,B,K = list(map(int,input().split()))
def solve(A,B,K):
    k = 1
    for i in reversed(range(1,max(B+1,A+1))):
        if A%i == 0 and B%i == 0:
            if K == k:
                return i
            else:
                k = k + 1
print(solve(A,B,K))


Measured memory_bytes: 2940
#include <iostream>
int main(){
  int k;
  std::cin >> k;
  int r = 0;
  int tmp = 0;
  if(k % 10 == 0 or k % 10 == 2 or k % 10 == 4 or k % 10 == 5 or k % 10 == 6 or k % 10 == 8)std::cout<<"-1"<<std::endl;
  else{
    while(++r){
      tmp = (tmp * 10 + 7) % k;
      if(tmp == 0){
        std::cout << r << std::endl;
        break;
      }
    }
  }
}

Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=3e5+10;
int sz[N];
int a[N];
void initialize(int n)
{
    for(int i = 1;i<=n;i++)
    {
        a[i] = i ;
        sz[i]=1;
    }
}
int root(int i)
{
    while(a[i]!=i)
    {
        a[i]=a[a[i]]; 
        i=a[i]; 
    }
    return i;
}
void merge(int x,int y)
{
    int u=root(x);
    int v=root(y);
    if(sz[u] < sz[v])
    {
        swap(u,v);
    }
    a[v] = a[u];
    sz[u]+=sz[v];

}
int32_t main()
{
	IOS;
	int n,m;
	cin>>n>>m;
	initialize(n);
	for(int i=1;i<=m;i++)
	{
		int x,y;
		cin>>x>>y;
		if(root(x)!=root(y))
		{
			merge(x,y);
		}
	}
	int mx=0;
	for(int i=1;i<=n;i++)
	{
		mx=max(mx,sz[i]);
	}
	cout<<mx<<endl;

}

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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

ll n,m;
string s;
//Write From this Line

const int mod = 1e9+7;
int main()
{
	cin >> n ;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	int count = 1 ;
	int crash = 0;
	rep(i,n){
		if(a[i] == count){
			count ++ ;
		}else{
			crash ++ ;
		}
	}
	if(crash < n){
		cout << crash << endl;
	}else{
		cout << -1 << endl;
	}
}


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

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<=(b);i++)
#define all(a) (a).begin(),(a).end()
using namespace std;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef long long ll;

void solve() {
#ifdef _WIN32
	istream &cin = ifstream("input.txt");
#endif
	int n;
	cin >> n;
	int sum = 0, i = 1;
	while (sum < n) {
		sum += i++;
	}
	cout << --i << endl;
}




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


	solve();
#ifdef _WIN32
	system("PAUSE");
#endif
	return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  ll a,b,c;cin>>a>>b>>c;
  if(a%2==0||b%2==0||c%2==0)out(0);
  else {
    out(min({a*b,a*c,b*c}));
  }



  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 100100100100100100;//10^17
const ll MOD = 1000000007;


ll combination(ll n, ll r){
    if(n < r) return 0;
    if(r == 0||r == n) return 1;
    else if(r == 1) return n;
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}

bool checkKaibun(string str){
    string checkStr = str;
    reverse(checkStr.begin(), checkStr.end());
    if(str == checkStr) return true;
    else return false;
}

int keta(ll num){
    int digits = 0;
    while(num > 0){
        num /= 10;
        digits++;
    }
    return digits;
}


ll mpow(ll x, ll n){//繰り返し二乗法 計算量O(logN)
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans * x % MOD;
        x = x * x % MOD;
        n  = n >> 1;
    }
    return ans;
}

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



int main(){
    int S, W;
    cin >> S >> W;
    if(S <= W)cout << "unsafe" << endl;
    else cout << "safe" << endl;
}

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

using namespace std;

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

typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll MOD = 1e9+9;

mat mul(mat const& A, mat const& B) {
  mat C(A.size(), vec(B[0].size()));
  for(int i=0; i<A.size(); i++)
    for(int k=0; k<B.size(); k++)
      for(int j=0; j<B[0].size(); j++)
        C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  return C;
}

mat pow(mat A, ll n) {
  mat B(A.size(), vec(A.size()));
  for(int i=0; i<A.size(); i++) {
    B[i][i] = 1;
  }
  while(n > 0) {
    if(n & 1) B = mul(B, A);
    A = mul(A, A);
    n >>= 1;
  }
  return B;
}

int W; ll H; int N;
mat coef;
vector<pair<ll, vector<int>>> vs;
mat xsmat;

inline void make_identity_coef() {
  coef.clear(); coef.resize(W); rep(i, W) coef[i].resize(W);
  rep(i, W) rep(j, 3)
    if(i+j-1 >= 0 && i+j-1<W)
      coef[i][i+j-1] = 1;
}

inline void init_xsmat() {
  xsmat.clear();
  xsmat.resize(W);
  rep(i, xsmat.size()) xsmat[i].resize(1);
  xsmat[0][0] = 1;
}

inline void input_blocks() {
  vs.clear();
  map<ll, vector<int>> y2xs;
  rep(i, N) {
    ll x, y; scanf("%lld%lld", &x, &y); x--, y--;
    y2xs[y].push_back(x);
  }
  for(auto& e: y2xs) vs.emplace_back(e.first, e.second);
  vs.emplace_back(H - 1, vector<int>());
}

inline void update_n_step(ll n) {
  xsmat = mul(pow(coef, n), xsmat);
}

int main() {

  for(int tc = 1; scanf("%d%lld%d", &W,&H,&N) && (W|H|N); tc++) {
    input_blocks();
    make_identity_coef();
    init_xsmat();
    ll curr = 0;
    rep(i, vs.size()) {
      update_n_step(vs[i].first - curr);
      curr = vs[i].first;
      for(auto& x: vs[i].second) xsmat[x][0] = 0;
    }
    printf("Case %d: %lld\n", tc, xsmat[W-1][0]);
  }

  return 0;
}

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

int main( void ) {
	char str1[ 100000 ], str2[ 100000 ], fig, tmp;
	int i, n, idx1, idx2, sum;

	while ( 1 ) {
		scanf( "%d", &n );

		if ( !n )
			break;

		scanf( "%s", str1 );

		for ( i = 0; i < n; i++ ) {
			idx1 = idx2 = 0;
			while ( 1 ) {
				if ( sscanf( str1 + idx1, "%c", &fig ) == EOF )
					break;

				sum = 1;
				while ( sscanf( str1 + ++idx1, "%c", &tmp ) != EOF && fig == tmp )
					sum++;
				sprintf( str2 + idx2++, "%d%c", sum, fig );

				do {
					idx2++;
				} while ( sum /= 10 );
			}

			strcpy( str1, str2 );
		}

		printf( "%s\n", str1 );
	}

	return 0;
}

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

int main() {
  bool flag=true;
  string s;
  cin >> s;
  r(i,s.length()-1){
    if(s.at(i+1)!='9')flag=false;
  }
  if(flag)cout<< (s.length()-1)*9+(s.at(0)-'0')<<endl;
  else cout<< (s.length()-1)*9+(s.at(0)-'1')<<endl;
}

Measured memory_bytes: 384
#N=gets.to_i
#S=gets.chomp
#A=(0...N).map{gets.to_i}
#sum=A.inject(&:+)
#B=gets.split.map(&:to_i)


N,M=gets.split.map(&:to_i)
a=gets.split.map(&:to_i)
bcs=(0...M).map{gets.split.map(&:to_i)}

sa=a.sort
sbcs=bcs.sort_by{|b,c| c}

max=0
N.times do
  if sa.length>0
    va=sa[-1]
  else
    va=0
  end
  if sbcs.length>0
    vbc=sbcs[-1][1]
  else
    vbc=0
  end
  if va>vbc
    max+=va
    sa.pop
  else
    max+=vbc
    if sbcs[-1][0]==1
      sbcs.pop
    else
      sbcs[-1][0]-=1
    end
  end
end

puts max


Measured memory_bytes: 21736
import java.util.*;
import java.lang.Math;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	
      	int n = sc.nextInt();
      	int m = sc.nextInt();
      	int dif = n-m+1;
        boolean ams[][] = new boolean[n][n];
      	boolean bms[][] = new boolean[m][m];
      	boolean con;
      	boolean nex;
      	String sstack;
      
      	for(int i = 0;i < n;i++){
          sstack = sc.next();
          for(int j = 0;j < n;j++){
          	if(sstack.charAt(j) == '#') ams[i][j] = true;
            else ams[i][j] = false;
          }
        }
      	for(int i = 0;i < m;i++){
          sstack = sc.next();
          for(int j = 0;j < m;j++){
          	if(sstack.charAt(j) == '#') bms[i][j] = true;
            else bms[i][j] = false;
          }
        }
      
      	nex = true;
      	for(int i = 0;i < dif && nex;i++){
          for(int j = 0;j < dif && nex;j++){
            con = true;
            for(int k = 0;k < m && con;k++){
          	  for(int l = 0;l < m && con;l++){
                if(ams[i+k][j+l] != bms[k][l]) con = false;
              }
            }
            if(con) nex = false;
          }
        }
      	
      
      	if(nex) System.out.println("No");
      	else System.out.println("Yes");
        
	}
}


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

using namespace std;
#define ll long long int 
int main()
{
    ll a,b,c,y;
    cin>>a>>b>>c;
    
   
   
    if(c==b)
     y=floor((b-1)*a/b);
    if(c<b)
     y=floor((c)*a/b);
    if(c>b)
    {
         y=floor((b-1)*a/b);
    }
    
      cout<<y;
     
     
     return 0;   
    
}

Measured memory_bytes: 3524
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	cout<<min(b/a,c)<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <tuple>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int graph[210][210];

int main()
{
  int n, m, R;
  cin >> n >> m >> R;
  vector<int> r(R);
  for (auto &e : r)
    cin >> e;
  for (int i = 0; i < 210; ++i)
    for (int j = 0; j < 210; ++j)
      if (i != j)
        graph[i][j] = INF;
  for (int i = 0; i < m; ++i)
  {
    int a, b, c;
    cin >> a >> b >> c;
    graph[a][b] = graph[b][a] = c;
  }
  for (int k = 1; k <= n; ++k)
  {
    for (int i = 1; i <= n; ++i)
    {
      for (int j = 1; j <= n; ++j)
      {
        graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
      }
    }
  }
  int ans = INF;
  sort(r.begin(), r.end());
  do
  {
    int sum = 0;
    for (int i = 0; i < R - 1; ++i)
    {
      sum += graph[r[i]][r[i + 1]];
    }
    ans = min(ans, sum);
  } while (next_permutation(r.begin(), r.end()));

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
typedef long long ll;
int n, x;
int a[maxn];
ll ans;
int main()
{
	scanf("%d%d", &n, &x);
	for(int i = 1; i <= n; ++i) 
	{
		scanf("%d", &a[i]);
		if(a[i] > x)
		{
			ans += a[i] - x;
			a[i] = x;
		}
	}
	for(int i = 2; i <= n; ++i)
		if(a[i] + a[i - 1] > x)
		{
			int ret = a[i] + a[i - 1] - x;
			a[i] -= ret;
			ans += ret;
		}
	cout << ans << endl;
	return 0;
}
			

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


using namespace std;

#define MAXN 10010

char s[MAXN][15];
int tam[MAXN];
int n;
int qa, qb, qc;

int main() {
    scanf("%d", &n);
    int i, j, k;
    for (i=1; i<=n; i++) {
        scanf("%s", s[i]+1);
        tam[i] = strlen(s[i]+1);
    }
    int ans = 0;
    qa = 0;
    qb = 0;
    qc = 0;
    for (i=1; i<=n; i++) {
        for (j=2; j<=tam[i]; j++) {
            if (s[i][j]=='B' && s[i][j-1]=='A') {
                ans++;
            }
        }
        if (s[i][tam[i]]=='A') {
            qa++;
        }
        if (s[i][1]=='B') {
            qb++;
        }
        if (s[i][tam[i]]=='A' && s[i][1]=='B') {
            qc++;
        }
    }
    if (qa==qb && qb==qc) {
        ans += max(0, qa-1);
    }
    else {
        ans += min(qa, qb);
    }
    printf("%d\n", ans);
    return 0;
}








Measured memory_bytes: 384
from collections import Counter

N = int(input())
wsv = [list(map(int, input().split())) for _ in range(N)]
W, S, V = map(list, zip(*wsv))
 
L = sorted(range(N), key = lambda i : W[i]+S[i], reverse = True)

dp = Counter()
dp[10**9+7] = 0

for l in L:
    for k, v in dp.copy().items():
        if k >= W[l]:
            t = min(k - W[l], S[l])
            dp[t] = max(dp[t], v + V[l])
print(max(dp.values()))        


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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	for(int n,l;cin>>n>>l && n|l;){
		vs ss(n);
		rep(i,n) cin>>ss[i];
		sort(all(ss));
		string res;
		rep(i,n) res+=ss[i];
		cout<<res<<endl;
	}
}


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

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  sort(h.begin(), h.end());
  ll ans = 0;
  k = min(n,k);
  rep(i,k){
    h.pop_back();
  }
  rep(i,h.size()) ans += h[i];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
typedef unsigned int ui;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int main() {
	ll a; cin >> a;
	ll cnt = 0;
	for (cnt;; cnt++) {
		if (cnt*(cnt + (ll)1) / (ll)2>=a)break;
	}
	ll d = cnt - (cnt * (cnt + (ll)1) / (ll)2 - a);
	rep(i, d) {
		cout << ')';
	}
	cout << '(';
	rep(i, cnt - d)cout << ')';
	rep(i, cnt - (ll)1)cout << '(';
	cout << endl;
	return 0;
}


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

using namespace std;

int main(){
    int N,*A;
    cin >> N;
    A = (int *)malloc(sizeof(int)*N);
    
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    int min = 2000000000;
    int plf = -2000000000;
    for (int i = 1; i < N; i++) {
        if (min > A[i-1]) min = A[i-1];
        if(A[i] - min > plf) plf = A[i] - min;
    }
    cout << plf << endl;
    return 0;
}

Measured memory_bytes: 1960
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
vector<string> vec(3);
  for(ll i=0;i<3;i++) {
cin>>vec[i];
  }
  
  reverse(all(vec[0]));
  reverse(all(vec[1]));
  reverse(all(vec[2]));
  
  
  ll turn =0;
  for(ll i=0;i<300;i++) {
    if(vec[turn].size()==0) {
cout<<(char)('A'+turn)<<endl;
      return 0;
    }
    char k=vec[turn].back();
    vec[turn].pop_back();
   turn=k-'a';
  }
}
    
    
   
    

  


Measured memory_bytes: 3632
"""
N/x-1 - N/x >= 1のところを狙っていく
解aだとして、aまではAを+1ずつインクリメントでOK
a以降はN/aからbをデクリメント
"""
N = int(input())

def calc(a,b):
    N = a * b 
    n = int(N**0.5)-2
    while (n+1)**2 < N:
        n += 1
    if a == b == 1:
        return 0
    cnta = n
    cntb = n
    if a <= n:
        cnta -= 1
    if b <= n:
        cntb -= 1
    ans = cnta + cntb
    # A : 1,2,3,..,n,n+1, 大きい数
    # B : 大きい数,n+1,n,...,3,2,1
    # それぞれペアを見つけながら進んでいけばいいので基本 2*n
    # 1. Aの1~nまでにaが入っていると-1
    # 2. Bの1~nまでにbが入っていると-1
    # 3. n*n+1がabより大きいと成り立たないので-1
    if n*(n+1) >= N:
        ans -= 1
    return ans        

for i in range(N):
    a,b = map(int, input().split())
    ans = calc(a,b)
    print(ans)


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("4");
            WillReturn.Add("1 -3 1 0");
            //4
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("5");
            WillReturn.Add("3 -6 4 -5 7");
            //0
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("6");
            WillReturn.Add("-1 4 3 2 -5 4");
            //8
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] AArr = InputList[1].Split(' ').Select(X => int.Parse(X)).ToArray();

        long Cost1 = Solve(AArr, true);
        long Cost2 = Solve(AArr, false);
        Console.WriteLine(Math.Min(Cost1, Cost2));
    }

    //最初の符号を引数として、コストを求める
    static long Solve(int[] pArr, bool pIsFirstPlus)
    {
        long Cost = 0;
        long RunSum = 0;

        for (int I = 0; I <= pArr.GetUpperBound(0); I++) {
            RunSum += pArr[I];
            if (I % 2 == 0 && pIsFirstPlus
             || I % 2 == 1 && pIsFirstPlus == false) {
                if (RunSum > 0) continue;
                Cost += Math.Abs(RunSum) + 1;
                RunSum = 1;
            }
            else {
                if (RunSum < 0) continue;
                Cost += Math.Abs(RunSum) + 1;
                RunSum = -1;
            }
        }
        return Cost;
    }
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 1005;
const int MAX_S = 21234;
struct Item{
  int w, s, v;
};
Item item[MAX_N];

ll dp[MAX_N][MAX_S];

int main2() {
  int N = nextInt();
  REP(i, N) {
    int w = nextInt();
    int s = nextInt();
    int v = nextInt();
    item[i] = {w, s, v};
  }
  sort(item, item + N, [](const Item&a, const Item&b) -> bool {
    return a.w+a.s < b.w+b.s;
  });
  // REP(i, N) {
    // cout << item[i].w << " " << item[i].s << " " << item[i].v << endl;
  // }
  CLR(dp, 0);
  REP(i, N) {
    REP(w, MAX_S) chmax(dp[i+1][w], dp[i][w]);
    REP(w, item[i].s + 1) {
      chmax(dp[i+1][w + item[i].w], dp[i][w] + item[i].v);
    }
  }
  ll ans = 0;
  REP(s, MAX_S) chmax(ans, dp[N][s]);
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef string ss;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

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

int main()
{
    ll n,cnt=0,min=M,sum=0;
    cin >> n;
    vll a(n);
    rep(i,n){
        cin >> a[i];
        sum += abs(a[i]);
        if(a[i] < 0)cnt++;
        if(min > abs(a[i]))min = abs(a[i]);
    }

    cout << sum - ((cnt%2==0)?0:2*min) << endl;
    return 0;
}

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

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

string s;
string t = "keyence";

bool c1() {
  return s == t;
}

bool c2() {
  int k = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'k') {
      k = i;
      break;
    }
  }

  return s.substr(k, 7) == t;
}

bool c3() {
  return s.substr(0, 7) == t;
}

bool c4() {
  int front = 0;
  rep (i, s.size()) {
    if (i >= t.size()) break;;
    if (t[i] == s[i]) {
      front++;
    } else {
      break;
    }
  }

  int back = 0;
  string rs = s;
  reverse(all(rs));
  string rt = t;
  reverse(all(rt));
  rep (i, s.size()) {
    if (i >= t.size()) break;;
    if (rt[i] == rs[i]) {
      back++;
    } else {
      break;
    }
  }

  return front + back >= 7;
}

signed main() {
  cin >> s;

  if (c1() || c2() || c3() || c4()) {
    puts("YES");
  } else {
    puts("NO");
  }

  return 0;
}

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

int main(){
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    
    vector<vector<int>> a(2,vector<int>(n));
    rep(i,2){
        rep(j,n) cin >> a[i][j];
    }
    
    int maxv = 0;
    
    for(int k = 0; k < n; k++){
        int sum = 0;
        int i = 0;
        int j = 0;
        bool flag = true;
        while(j < n){
            sum += a[i][j];
            if(j==k and flag){
                i++;
                flag = false;
            } else {
                j++;
            }
        }
        maxv = max(maxv,sum);
    }
    cout << maxv << endl;
}


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

int main() {
  int n;
  cin>>n;
  pair<string,int> pr[110];
  for (int i=0; i<n; i++) {
    string s; int p;
    cin>>s>>p;
    pr[i]=make_pair(s,p);
  }
  int r[110];
  for (int i=0; i<n; i++) {
    int rank=1;
    for (int j=0; j<n; j++) {
      if (pr[i].first > pr[j].first) rank++;
      else if (pr[i].first == pr[j].first) {
	if (pr[i].second < pr[j].second) rank++;
      }
    }
    r[i]=rank;
  }
  for (int i=1; i<=n; i++) {
    for (int j=0; j<n; j++) {
      if (r[j]==i) {
	cout<<j+1<<endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main() {
  long int N;
  int K, h, sum=0;
  cin >> N >> K;
  for(int i=0; i<N; i++) {
    cin >> h;
    h>=K?sum++:sum=sum;
  }
  cout << sum << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD=1e9+7;

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

  int n;
  std::vector<int> v,odd;
  for(int i=1;i*(i+1)*(i+2)/6<=6*1e6;i++){
      int tmp=i*(i+1)*(i+2)/6;
      v.push_back(tmp);
      if(tmp%2) odd.push_back(tmp);
  }
  std::vector<int> dp(1e6+1),odddp(1e6+1);
  for(int i=1;i<=1e6;i++){
      dp[i]=i;odddp[i]=i;
  }
  for(int i=1;i<=1e6;i++){
      for(int j=0;j<(int)v.size();j++){
          if(i-v[j]>=0) dp[i]=min(dp[i],dp[i-v[j]]+1);
      }
      for(int j=0;j<(int)odd.size();j++){
          if(i-odd[j]>=0) odddp[i]=min(odddp[i],odddp[i-odd[j]]+1);
      }
  }
  while(cin>>n,n){
      cout<<dp[n]<<" "<<odddp[n]<<endl;
  }
  return 0;
}

Measured memory_bytes: 10520
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> result = new List<string>();

            while (true)
            {

                string firststringorder = Console.ReadLine();

                if (firststringorder == "-") break;

                int cutnum = int.Parse(Console.ReadLine());

                for (int i = 1; i <= cutnum; i++)
                {
                    int shuffle = int.Parse(Console.ReadLine());


                    string stringchange = firststringorder.Insert(shuffle, " ");

                    string[] orderchange = stringchange.Split(' ');


                    firststringorder =  orderchange[1] + orderchange[0];
                }

                result.Add(firststringorder);


            }

            //??????
            foreach (var output in result) Console.WriteLine(output);

        }
    
    }

}

Measured memory_bytes: 8956
#include<cstdio>

int cnt[10000];
bool used[1260-540][10000];

int main(){
	for(int m;scanf("%*d%d",&m),m;){
		for(int i=0;i<m;i++)	cnt[i]=0;

		int r;	scanf("%d",&r);
		int t=0;
		for(int i=0;i<r;i++){
			int tt,st,flg;	scanf("%d%*d%d%d",&tt,&st,&flg);
			st--;
			for(;t<tt-540;t++){
				for(int j=0;j<m;j++)	used[t][j]=(cnt[j]>0);
			}
			if(flg)	cnt[st]++;
			else	cnt[st]--;
		}
		for(;t<1260-540;t++){
			for(int j=0;j<m;j++)	used[t][j]=(cnt[j]>0);
		}

		int q;	scanf("%d",&q);
		for(int i=0;i<q;i++){
			int ts,te,st;	scanf("%d%d%d",&ts,&te,&st);
			st--;
			int ans=0;
			for(int t=ts-540;t<te-540;t++)	ans+=used[t][st];
			printf("%d\n",ans);
		}
	}

	return 0;
}

Measured memory_bytes: 7828
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
	int n;
	string al("abcdefghijklmnopqrstuvwxyz");
	while(cin>>n){
		if(n==0) break;
		string s[n];
		int a[n][9];
		for(int i=0;i<n;i++){
			cin>>s[i];
			for(int j=0;j<=8;j++){
				cin>>a[i][j];
			}
		}
		double ef[n];
		for(int i=0;i<n;i++){
			double x=a[i][7]*a[i][6]*a[i][8]-a[i][0];
			double y=a[i][1]+a[i][2]+a[i][3]+(a[i][4]+a[i][5])*a[i][8];
			ef[i]=x/y;
		}
		for(int i=0;i<n;i++){
			double me=-100;
			int ms;
			for(int j=0;j<n;j++){
				if(ef[j]>me){
					me=ef[j];
					ms=j;
				}
				else if(ef[j]==me){
					for(int moji=0;moji<30;moji++){
						int m1=-1,m2=-1;
						for(int z=0;z<26;z++){
							if(s[ms][moji]==al[z]) m1=z;
							if(s[j][moji]==al[z]) m2=z;
						}
						if(m1<m2){
							break;
						}
						else if(m1>m2){
							ms=j;
							break;
						}
					}
				}
			}
			cout<<s[ms]<<endl;
			ef[ms]=-200;
		}
		cout<<"#"<<endl;
	}
    return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <vector>
#include <string>
#include <cctype>
#include<algorithm>
using namespace std;
vector<char> s;
int dp[3001][3001];


void printLcs(string x,string y,int m,int n){
     for(int i=0;i<=m;i++){
        for(int j=0;j<=n;j++){
            if(i==0||j==0){
                dp[i][j]=0;
            }
            else if(x[i-1]==y[j-1]){
                dp[i][j]=1+dp[i-1][j-1];
            }
            else{
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
     }
    //int dp[m+1][n+1];
    //vector<string> s;
       
                    //cout<<x[i-1];
                    //cout<<ch;
                    //s.push_back(x[i-1]);
                  
          int i=m;
        int j=n;
        
        while(i>0&&j>0){
               
                if(x[i-1]==y[j-1]){
                    //cout<<x[i-1];
                    //cout<<ch;
                    s.push_back(x[i-1]);
                    i--;
                    j--;

                }
                else{
                    if(dp[i][j-1]>=dp[i-1][j]){
                        j--;
                    }
                    else{
                        i--;
                    }
                }
        }
            
        
        reverse(s.begin(),s.end());
        for(auto x: s){
            cout<<x;
        }
        
    }
            
        
       // reverse(s.begin(),s.end());
        //for(auto x: s){
           // cout<<x;
        //}
        
        
    

int main() {
   string x;
   string y;
   cin>>x;
   cin>>y;
   int m=x.length();
   int n=y.length();
   printLcs(x,y,m,n);
}


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

int main(){
  int i,j,k;
  string str;

  while(cin>>str){
    for(i=0;i<str.size();i++){
      if(str[i]=='@'){
	i++;
	k=i+1;
	for(j=0;j<str[i]-'0';j++){
	  cout << str[k];
	}
	i++;
      }else{
	cout << str[i];
      }
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1172
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<set>
#include<map>
#include<vector>
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)((x).size()))
#define rep(i,j,k) for(int i=(int)j;i<=(int)k;i++)
#define per(i,j,k) for(int i=(int)j;i>=(int)k;i--)
using namespace std;
typedef long long LL;
typedef double DB;
const DB pi=acos(-1.0);
const int N=110000;
int a,b,n;
char d[N];
int main(){
	scanf("%d%d%d",&n,&a,&b);
	scanf("%s",d+1);
	int d1=0;
	int d2=0;
	rep(i,1,n){
		if(d[i]=='c'){
			puts("No");
		}
		else
		if(d[i]=='a'){
			if(d1+d2<a+b){
				puts("Yes");
				d1++;
			}
			else puts("No");
		}
		else{
			if(d1+d2<a+b&&d2<b){
				++d2;
				puts("Yes");
			}
			else puts("No");
		}
	}
	return 0;
}











Measured memory_bytes: 640
//aising2020_b.cpp
//Sat Jul 11 20:50:55 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007
#define rep(i,n) for (int i=0;i<(n);++i)

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

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

	int a[n];
	rep(i,n) cin >> a[i];

	int ans = 0;
	for (int i=0;i<n;i=i+2){
		if(a[i]&1){
			ans++;
		}
	}

	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int T;
	scanf("%d", &T);
	while(T--)
	{
		ll a, b, c, d;
		scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
		if(a < b || d < b) { puts("No"); continue;}
		if(c >= b - 1) { puts("Yes"); continue;}
		a %= b;
		if(a > c) { puts("No"); continue;}
		d %= b;
		ll g = __gcd(b, d);
		if((b - 1) / g - c / g > 0) puts("No");
		else puts("Yes");
	}
	return 0;
}
		 
		

Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e15+9
#define MOD 1000000007
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

string s;
ll ANS;

int main(){
	cin >> s;
	int ans = 0;
	int g = 0, p = 0;
	REP(i, s.size()){
		if (g == p){
			g++;
			if (s[i] == 'p')ans--;
		}
		else{
			p++;
			if (s[i] == 'g')ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cout << #x << " = " << (x) << endl; \
    }
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
#define S set<int>
#define itn int
bool dbg = false;
itn N, M, a[1010], b[1010], c[1010];
int dp[101010];
void solve() {
    FOR(bit, 1ll, (1ll << N)) {
        dp[bit] = INF;
    }
    FOR(bit, 0ll, (1ll << N)) {
        FOR(i, 0, M) {
            dp[bit | c[i]] = min(dp[bit | c[i]], dp[bit] + a[i]);
        }
    }
    if (dp[(1ll << N) - 1] == INF) {
        dp[(1ll << N) - 1] = -1;
    }
    cout << dp[(1ll << N) - 1] << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    FOR(i, 0, M) {
        cin >> a[i] >> b[i];
        FOR(j, 0, b[i]) {
            int x = 0;
            cin >> x;
            x--;
            c[i] += (1ll << x);
        }
    }

    solve();
    return 0;
}


Measured memory_bytes: 384