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

using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    
    vector<int> a(n);
    for(int i=0;i<n;i++)
        cin>>a[i];
    
    sort(a.begin(),a.end(),greater<int>());
    double sum=accumulate(a.begin(),a.end(),0);
    
    for(int i=0;i<m;i++){
        if(a[i]< sum/4/m){
            cout<<"No"<<endl;
            goto Exit;
        }
    }
    
    cout<<"Yes"<<endl;
    
    Exit:
        ;
}

Measured memory_bytes: 3592
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

#define Min(a, b) (a < b ? a : b)

int main() {
  long n, a, b;
  scanf("%ld%ld%ld", &n ,&a, &b);
  long ans;
  ans = n/(a+b)*a;
  ans += Min(n%(a+b), a);
  printf("%ld\n", ans);
  return 0;
}


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

int func(int x){
    if (x<10) return x;
    return func(x/10)+x%10;
}
int main() {
    int N, x, MIN=1000000;
    cin >> N;
    for (int i=1; i<N; i++){
        x=func(i)+func(N-i);
        MIN=min(x, MIN);
    }
    cout << MIN << endl;
}


Measured memory_bytes: 256
N = int(input())
a = list(map(int,input().split()))

c = 0
for i in range(0, N):
  if a[i]%2 == 0:
    if a[i] % 3 == 0 or a[i] % 5 == 0:
      c += 1
  else:
    c += 1

if c == N:
  print("APPROVED")
else:
  print("DENIED")
      

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

int main()
{
  int n;
  cin >> n;
  int y;
  cin >> y;
  int i, j;
  int s = 0;
  for(i = 0; i <= n; i++)
  {
    for(j = 0; j <= n-i; j++)
    {
      if(10000*i+5000*j+1000*(n-i-j)==y)
      {
        cout << i << " " << j << " " << n-i-j << endl;
        s = 1;
        break;
      }
    }
    if(s == 1) break;
  }
  if(s == 0)
  {
    cout << "-1 -1 -1" << endl;
  }
}

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

using namespace std;

u_int seed = 3;
u_int xor_shift()
{
    seed ^= seed << 1;
    seed ^= seed >> 3;
    seed ^= seed << 10;
    return seed;
}

chrono::system_clock::time_point start_time;
int elapsed()
{
    auto cur = chrono::system_clock::now();
    return chrono::duration_cast<chrono::milliseconds>(cur - start_time).count();
}

// セグ木を使えば二分探索で一点をlog(n)で更新できる これ嘘で，後ろのスコアも変更する必要があるため
// 前からA*とかビームサーチもできそう
// とりあえず焼きなます
// 最初はCを考慮せずに焼きなます(いや，貪欲でいいだろ)
int score = 0;
int d;
vector<int> T, C;
vector<vector<int>> S, last;

// i日目をj番目に
int calc(int i, int to){
    int res = 0;
    int from = T[i];
    res -= S[i][from];
    int l = i == 0 ? -1 : last[i - 1][from];
    for (int j = i; j < d; j++){
        if (last[j][from] != i)
            break;
        res += C[from] * (j - last[j][from]);
        res -= C[from] * (j - l);
    }

    res += S[i][to];
    for (int j = i; j < d; j++){
        if (last[j][to] > i)
            break;
        res += C[to] * (j - last[j][to]);
        res -= C[to] * (j - i);
    }

    return res;
}

void change(int i, int to){
    int from = T[i];
    T[i] = to;
    int l = i == 0 ? -1 : last[i - 1][from];
    for (int j = i; j < d; j++){
        if (last[j][from] != i)
            break;
        last[j][from] = l;
    }

    for (int j = i; j < d; j++){
        if (last[j][to] > i)
            break;
        last[j][to] = i;
    }
}

int calc_overall(){
    int res = 0;
    for (int i = 0; i < d; i++){
        res += S[i][T[i]];
        for (int j = 0; j < 26; j++){
            res -= C[j] * (i - last[i][j]);
        }
    }

    return res;
}


int main(){
    cin >> d;
    start_time = chrono::system_clock::now();
    C.resize(26);
    copy_n(istream_iterator<int>(cin), 26, C.begin());
    S.assign(d, vector<int>(26));
    last.assign(d, vector<int>(26, -1));
    for (auto &s: S)
        copy_n(istream_iterator<int>(cin), 26, s.begin());

    T.resize(d);

    for (int i = 0; i < d; i++){
        // int to = max_element(S[i].begin(), S[i].end()) - S[i].begin();
        int to = xor_shift() % 26;
        T[i] = to;
        for (int j = i; j < d; j++){
            last[j][to] = i;
        }
    }

    auto ans = T;
    score = calc_overall();
    cerr << score << endl;
    int max_score = score;
    const double s_temp = 20000, e_temp = 1;
    const constexpr int L = 1e5;
    double delta = (s_temp - e_temp) / L;
    double temp = s_temp;
    const double sup = pow(2, 32) - 1;

    while (elapsed() < 1950){
        auto i = xor_shift() % d;
        auto to = xor_shift() % 26;
        if (T[i] == to)
            continue;
        auto cost = calc(i, to);
        if (cost > 0 or exp(cost / temp) > xor_shift() / sup){
            change(i, to);
            // cerr << "change: " << i << " " << to << " " << cost << " " << temp << endl;
            score += cost;
        }
        if (score > max_score){
            ans = T;
            max_score = score;
        }
        if (temp > e_temp)
            temp -= delta;
    }

    cerr << temp << endl;
    for (const auto &t: ans)
        cout << t + 1 << endl;

    cerr << max_score << endl;

}

Measured memory_bytes: 4440
#include <bits/stdc++.h>
#define mk make_pair
using namespace std;
typedef long long ll;
const int N = 3e5;
const int mod = 1e9 + 7;
int n, k;
int a[N], h[N];
ll B[N];
ll ask(int x) {
	ll res = 0;
	while (x) { //cout << x << ",";
		res = max(res, B[x]);
		x -= x & -x;
	}
	return res;
}
void ins(int x, ll v) {
	while (x <= n) { //cout << x << ",";
		B[x] = max(B[x], v);
		x += x & -x;
	}
}
int main() {
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		scanf("%d", h + i);
	}
	for (int i = 1; i <= n; ++i) {
		scanf("%d", a + i);
	}
	ll ans = 0;
	for (int i = 1; i <= n; ++i) {
		ll tmp = a[i] + ask(h[i]);
		ans = max(ans, tmp);
		ins(h[i], tmp);
	}
	cout << ans;
}



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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
template<class T> bool isIn(T a,vector<T> v){ for(T x:v){ if(a==x){return true;}} return false;}
string strReplace(string s,string target, string replacement){
    if (!target.empty()) {
      std::string::size_type pos = 0;
      while ((pos = s.find(target, pos)) != std::string::npos) {
        s.replace(pos, target.length(), replacement);
        pos += replacement.length();
      }
    }
    return s;
}
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair




int main(){
    int H,W,K; cin>>H>>W>>K;
    string board[H]; CINA(board,H);
    int ans[H][W];
    int c=1;
    bool flag = false;
    // 横にスライス
    REP(i,H){
        bool change=false;
        REP(j,W){
            if(board[i][j]=='#'){
                change = true; break;
            }
        }
        if(change){
            if(!flag){
                flag = true;
            }else{
                c += 1;
            }
        }
        
        REP(j,W){
            ans[i][j] = c;
        }
    }
    // 縦にスライス
    REP(i,H){
        flag = false;
        REP(j,W){
            bool change = false;
            if(board[i][j]=='#'){
                change = true;
            }
            if(change){
                if(!flag){
                    flag = true;
                }else{
                    c += 1;
                    int orig_c = ans[i][j];
                    for(int k=0;k<H;++k){
                        for(int l=j;l<W;++l){
                            if(ans[k][l]==orig_c){
                                ans[k][l] = c;
                            }else{
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    
    REP(i,H){
        REP(j,W){
            if(j<W-1){
                cout << ans[i][j] << " ";
            }else{
                cout << ans[i][j] << "\n";
            }
        }
    }
    
    
}

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

int main() {
  int N;
  cin >> N;
  vector<int> pos(N + 1);
  rep(i, N) {
    int p;
    cin >> p;
    pos.at(p) = i + 1;
  }

  multiset<int> ms;
  rep(i, 2) {
    ms.insert(0);
    ms.insert(N + 1);
  }
  ll ans = 0;
  for (int i = N; i >= 1; i--) {
    // インデックスの順は l1 < l2 < pos.at(i) < r1 < r2 となるようにする
    ms.insert(pos.at(i));
    auto itr = ms.find(pos.at(i));
    rep(j, 2) itr--;
    ll l1 = *itr;
    itr++;
    ll l2 = *itr;
    rep(j, 2) itr++;
    ll r1 = *itr;
    itr++;
    ll r2 = *itr;

    ans += ((l2 - l1) * (r1 - pos.at(i)) + (pos.at(i) - l2) * (r2 - r1)) * i;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5376
n = int(input())
A = list(map(int,input().split()))
B = [0]*n
ans = []
cur = 0
for i in range(n,0,-1):
	# print("i",i)
	j = i
	cur = 0
	k = 1
	while j*k <= n:
		# print("j*k",j,k,cur)
		cur += B[j*k-1]
		k += 1
	if cur % 2 != A[i-1]:
		ans.append(i)
		B[i-1] = 1
	# print(B,ans)
print(len(ans))
if ans:
	print(*ans[::-1])

Measured memory_bytes: 14760
#include<iostream>
using namespace std;
int a[100000],n;
int partition(int r){
  int x=a[r],change=0,tmp;
  for(int i=0;i<r;++i){
    if(a[i]<=x){
      tmp=a[change];
      a[change++]=a[i];
      a[i]=tmp;
    }
  }
  tmp=a[change];
  a[change]=a[r];
  a[r]=tmp;
  return change;
}
int main(){
  cin>>n;
  for(int i=0;i<n;++i) cin>>a[i];
  int base=partition(n-1);
  for(int i=0;i<n;++i){
    if(i) cout<<" ";
    if(i==base) cout<<"[";
    cout<<a[i];
    if(i==base) cout<<"]";
  }
  cout<<endl;
  return 0;
}



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

int main(){
  int N;
  cin >> N;
  int num[N];
  int i, j;

  // 入力
  for(i = 0; i < N; i++){
    cin >> num[i];
  }
  // ソート
  sort(num, num + N);

  // 異値の個数をカウント
  i = 0;
  int hz, cnt, result = 0;
  while(i < N){
    hz = num[i];
    cnt = 0;
    while(i < N && num[i] == hz){
      cnt++;
      i++;
    }
    result += cnt % 2;
  }
  cout << result << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>

int first_array[20], first_array_size;

int calc(int a, int b) {
	if (b == 0) return 1;
	if (a >= first_array_size) return 0;
	int reply = calc(a + 1, b) || calc(a + 1, b - first_array[a]);
	return reply;
}

int main() {
	int i, second_array_number, second_array_size;
	scanf("%d", &first_array_size);

	for (i = 0; i < first_array_size; i++) {
		scanf("%d", &first_array[i]);
	}

	scanf("%d", &second_array_size);

	for (i = 0; i < second_array_size; i++) {
		scanf("%d", &second_array_number);
		if (calc(0, second_array_number)) printf("yes\n");
		else printf("no\n");
	}

	return 0;
}


Measured memory_bytes: 2132
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector as V
import Data.Ord

main :: IO ()
main = readLine >>= main'
    where
        main' [h, w, d] = readContents h >>= main'' . build h w d 
        main'' vs = readLn >>= readContents >>= printRes . solve vs
        printRes = mapM_ print 

build :: Int -> Int -> Int -> [[Int]] -> V.Vector Int
build h w d as = V.fromList . (0 :) . map snd . sortBy (comparing fst) . concat $ buildLoop bs
    where
        bs = sortBy cmpf . concatMap mf $ zip [1..] as
        mf (i, xs) = map (\(j, a) -> (a, (i, j))) $ zip [1..] xs
        cmpf (la, _) (ra, _) = (comparing (`mod` d)) la ra `mappend` compare la ra

        buildLoop (x@(a, _) : xs) = ss : buildLoop ts
            where
                (ss, ts) = innerLoop (a `mod` d) $ x : xs
        buildLoop _ = []

        innerLoop m (x : xs) = ((fst x, 0) : res1, rs)
            where
                (res1, rs) = loop 0 x xs
                loop pv (_, (lp, rp)) (y@(ya, (ly, ry)) : ys)
                    | ya `mod` d == m = ((ya, nv) : us, vs)
                    | otherwise = ([], y : ys)
                    where
                        nv = pv + abs (lp - ly) + abs (rp - ry) 
                        (us, vs) = loop nv y ys
                loop _ _ _ = ([], [])
        innerLoop _ _ = ([], [])


solve :: V.Vector Int -> [[Int]] -> [Int]
solve vs = map (\[l, r] -> vs V.! r - vs V.! l)

readLine :: IO [Int]
readLine = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

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

using namespace std;

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

    int n, m;

    cin >> n >> m;

    printf("%d\n", n * (n - 1) / 2 + m * (m - 1) / 2);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

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

    if(a*b<=0){
        cout << "Zero" << endl;
        return 0;
    }
    else if(a>0 && b>0){
        cout << "Positive" << endl;
        return 0;
    }
    else{
        ll temp=llabs(b-a)+1;
        if(temp%2==0) cout << "Positive" << endl;
        else cout << "Negative" << endl;
    }
    
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ll long long

using namespace std;

int main(){
  string s;cin>>s;
  int sc=0, tc=0;

  rep(i, s.size()){
    if(s[i]=='T'){
      if(sc==0)tc++;
      else sc--;
    }
    if(s[i]=='S')sc++;
  }

  cout<<sc+tc<<endl;

  return 0;
}

Measured memory_bytes: 640
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi   vector<int> 
#define   co(x)  cout << x << '\n' 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int  n, len = 0 ; 
    cin >> n ; 
    map <int,int> oc; 
    for (int i=0,c;i<n;i++) {
        cin >> c ; 
        oc[c]++ ; 
        if (!oc[c+1]) oc[c+1] = oc[c]; 
        len = max(len,oc[c]); 
    }
    cout << (n - len) << endl ; 
}

signed main()
{
    int n=1; // cin>>n; 
    while (n--) solve(); 
    return 0; 
}


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

int main() {
  string S;
  cin >> S;
  if (S == "RRR") {
    cout << 3 << endl;
  } else if (S == "SRR" || S == "RRS") {
    cout << 2 << endl;
  } else if (S == "SSS") {
    cout << 0 << endl;
  } else {
    cout << 1 << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3580
#include <stdio.h>
int main(void) {
    int n, k;
    char str[100];
    scanf("%d %d", &n, &k);
    scanf("%s", str);

    str[k - 1] = str[k - 1] - 'A' + 'a';
    printf("%s\n", str);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>

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

int selection_sort(int a[], int n)
{
	int i, j;
	int minj;
	int sw = 0;
	
	for (i = 0; i < n; i++) {
		minj = i;
		for (j = i; j < n; j++) {
			if (a[minj] > a[j]) {
				minj = j;
			}
		}
		
		if (i != minj) {
			swap(&a[i], &a[minj]);
			sw++;
		}
	}
	
	for (i = 0; i < n; i++) {
		if (i > 0)
			printf(" ");
		printf("%d", a[i]);
	}
	printf("\n");
	printf("%d\n", sw);
	
	return 0;
}

int main(int argc, char *argv[]) {
	
	int n;
	int i;
	int a[100];
	
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	
	selection_sort(a, n);
	
	return 0;
}

Measured memory_bytes: 604
#include <iostream>
using namespace std;
int main(int argc, char const *argv[])
{
    string S;
    cin >> S;
    int length = 0;
    int ans = 0;
    for(int i = 0; i < S.size(); i++) {
        if(S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
            length++;
        } else {
            ans = max(ans, length);
            length = 0;
        }
    }
    ans = max(ans, length);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int a;
string vec[100];

int main(){
    cin >> a;
    for(int k=0;k<a;k++) cin >> vec[k];
    
    for(int k=1;k<a;k++){
        if(vec[k-1].back()!=vec[k].front()){
            cout << "No" << '\n';
            return 0;
        }
    }
    for(int k=0;k<a-1;k++){
        for(int l=k+1;l<a;l++){
            if(vec[k]==vec[l]){
                cout << "No" << '\n';
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#else
#include <iostream>
#include <iomanip> 
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; } sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; } eni(!=) cerr << boolalpha << i; ris; } eni(==) ris << range(begin(i), end(i)); } sim, class b dor(pair < b, c > d) { ris << "(" << d.first << ", " << d.second << ")"; } sim dor(rge<c> d) { *this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]"; }
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}
#define fix(a) fixed << setprecision(a)
#define forn(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 all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'


void solve(){ 
  string s;
  cin >> s;
  int n = len(s);
  vector<ll> a(n+1);
  vector<ll> b(n+1);
  
  forn(i, n){
    if (s[i]=='<') a[i+1] = a[i] + 1;
  }
  reverse(all(s));
  forn(i, n){
    if (s[i]=='>') b[i+1] = b[i] + 1;
  }
  reverse(all(b));
  reverse(all(s));
  ll ans = 0;
  forn(i,n+1) {
    ans += max(a[i], b[i]);
    // cerr << max(a[i], b[i]) << ' ' << ((i < n) ? s[i] : ' ') << ' '; 
  }
  cout << ans << endl;
}

int main() {
  ios::sync_with_stdio(false);
  int t = 1;
  // cin >> t;
  forn(i, t){
    solve();
  }
}

/* 

6
1 1
7 1
2 2
6 2
1 3
7 3

0 < 2 > 1 > 0

 */

Measured memory_bytes: 8732
#include <bits/stdc++.h>
#include <string>
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define loop(i, a, n) for(ll i = (a); i < (n); i++)
#define dd(x) cout << #x << " : " << x << endl
#define sorn(i, n) char((i == n-1)?'\n':' ')
using namespace std;
using ll = int64_t;

vector<vector<int> > ps;

void dfs(int i, vector<int> num, const int n, const int m){
    if(num.size() >= n){
        ps.push_back(num);
        return;
    }

    loop(ii, i, m+1){
        if(!num.size()) {
            vector<int> tmp = num;
            tmp.push_back(ii);
            dfs(ii, tmp, n, m);
        } else {
            if(num[num.size()-1] > ii) continue;
            vector<int> tmp = num;
            tmp.push_back(ii);
            dfs(ii, tmp, n, m);
        }
    }

    return;
}

int main(){
    int n, m, q; cin >> n >> m >> q;
    int a[q], b[q], c[q], d[q];
    rep(i, q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }

    loop(i, 1, m+1){
        vector<int> tmp;
        dfs(i, tmp, n, m);
    }

    ll ans = 0;
    for(auto vec : ps){
        ll tmp = 0;
        rep(i, q){
            int tmpa = vec[a[i]-1];
            int tmpb = vec[b[i]-1];
            if(tmpb - tmpa == c[i]) tmp += d[i];
        }
        ans = max<ll>(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}

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

typedef long long ll;

const int Maxn = 100005;

ll n, m, p, v;
ll a[Maxn], sum[Maxn];
int res;

bool Less(const ll &a, const ll &b) { return a > b; }

int main()
{
    scanf("%lld %lld %lld %lld", &n, &m, &v, &p);
    for (int i = 1; i <= n; i++)
        scanf("%lld", &a[i]);
    sort(a + 1, a + n + 1, Less);
    for (int i = 1; i <= n; i++)
        sum[i] = sum[i - 1] + a[i];
    ll X = a[p];
    for (int i = 1; i <= n; i++)
        if (i <= p) res++;
        else if (a[i] + m >= X)
            if (p - 1 + n - i + 1 >= v) res++;
            else {
                ll lft = v - (p - 1 + n - i + 1);
                X = max(X, (lft * m + sum[i - 1] - sum[p - 1] + i - p - 1) / (i - p));
                if (a[i] + m >= X) res++;
            }
    printf("%d\n", res);
    return 0;
}


Measured memory_bytes: 1792
n  = int(input())
count = [0] * (n + 1)
for i in range(1,n+1):
    k = i
    while 1:
        if i == 0:
            break
        elif float(i % 2) == 0.0:
            count[k] += 1
            i = int(i / 2)
        else:
            break
print(1) if n== 1 else print(count.index(max(count)))


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

int main() {
    int W,a,b;
    int ans;
    cin >> W;
    cin >> a;
    cin >> b;
    if (a>b)
        ans=a-b-W;
    else
        ans=b-a-W;
    if (ans<0)
        ans=0;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#define rep(i,n) for(int i=0;i<(n);i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define All(x) (x).begin(),(x).end()
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

int U[2003][2003];

int main() {
  ll D;
  cin >> D;
  cout << (D==7 ? "YES" : (D==5 ? "YES" : (D==3 ? "YES" :  "NO"))) <<endl;
}

Measured memory_bytes: 256
// AOJ 0394: Pilling Blocks
// 2019.2.23 bal4u

#include <stdio.h>
#include <stdlib.h>

int main()
{
	int N, K, ans, sum, len;

	scanf("%d%d", &N, &K);
	ans = sum = K + 1;
	if (N <= sum) {
		printf("%d\n", N);
		return 0;
	}

	len = 2; while (1) {
		while (sum > len*K) len++;
		sum += len;
		if (sum > N) break;
		ans++;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int amari(int x, int y){
	int a = x % y;
	if(a < 0){
		a += y;
	}
	return a;
}

int main(){
	string S;
	int D;
	cin >> S >> D;
	int data[S.size()];
	data[0] = (S[0]-'0') % D;
	for(int i=1; i<S.size(); i++){
		data[i] = (data[i-1] + (S[i] - '0')) % D;
	}
	int dp[S.size()][D];
	for(int i=0; i<S.size(); i++){
		for(int j=0; j<D; j++){
			dp[i][j] = 0;
		}
	}
	for(int i=0; i<S[0]-'0'; i++){
		dp[0][i%D]++;
	}
	for(int i=1; i<S.size(); i++){
		for(int j=0; j<D; j++){
			for(int k=0; k<10; k++){
				dp[i][j] = (dp[i][j] + dp[i-1][amari(j-k, D)]) % mod;
			}
		}
		for(int k=0; k<S[i]-'0'; k++){
			dp[i][(data[i-1]+k)%D] = (dp[i][(data[i-1]+k)%D] + 1) % mod;
		}
	}
	if(data[S.size() - 1] == 0){
		cout << dp[S.size() - 1][0] << endl;
	}else{
		cout << amari(dp[S.size() - 1][0]-1, mod) << endl;
	}
	return 0;
}

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

int main(){
    int n;
    string str;
    cin >> n >> str;
    int r = 0;
    int b = 0;
    for(int i = 0; i < str.size(); i++){
        if(str.at(i) == 'R') {
            r++;
        } else {
            b++;
        }
    }
    if( r > b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
A, B, K = input().split(' ')
A = int(A)
B = int(B)
K = int(K)
N = []
if B-A>K:
  for i in range(A, A+K):
    print(i)
    N.append(i)
  for i in range(B-K+1, B+1):
    if not i in N:
      print(i)

else:
  for i in range(A, B+1):
    if i < A + K:
      print(i)
    elif i > B-K:
      print(i)

Measured memory_bytes: 9196
#include<iostream>
using namespace std;
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
int main(){
  long long int n,i;
  cin>>n;
  long long int s=floor(sqrt(n));
  for(i=s;i>=1;i--){
    if(n%i==0){
      cout<<i+n/i-2<<"\n";
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }

int cnt[10][10];

int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++){
    string s = to_string(i);
    cnt[s[0] - '0'][s[sz(s) - 1] - '0']++;
  }
  ll ans = 0;
  rep(i, 10) rep(j, 10) ans += cnt[i][j] * cnt[j][i];
  cout << ans << endl;
  return 0;
}

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

int main(){
    int a, b;
    cin >> a >> b;
    if(a == 1 && b != 1)cout << "Alice" << endl;
    else if(a != 1 && b == 1)cout << "Bob" << endl;
    else if(a < b)cout << "Bob" << endl;
    else if(a == b)cout << "Draw" << endl;
    else cout << "Alice" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
 
long int GCD(long int A, long int B){
  if(A < B) return GCD(B, A);
  if(B == 0) return A;
  else return GCD(B, A%B);
}  

int main() {
  long int A, B, ans;
  cin >> A >> B;
  ans = (A * B) / GCD(A, B);
  cout << ans << endl;
  return 0;
}

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

using namespace std;

#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;


int main() {
#ifdef LOCAL
  assert(freopen("a.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  string s;
  cin >> s;
  int n = s.length();

  for (int i = 0; i < n; ++i) {
      for (char c = 'a'; c <= 'z'; ++c) {
          string t = c + s + c;
          int p = 0;
          bool ok = true;
          for (int j = 0; j < n + 2; ++j)
              if (t[j] == c) {
                  if (j - p > i + 1) {
                      ok = false;
                      break;
                  }
                  p = j;
              }
          if (ok) {
              cout << i << endl;
              return 0;
          }
      }
  }

  assert(false);
}



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

int main(){
    long long n, T;
    cin >> n >> T;

    long long t[n];
    for(long long i = 0; i < n; i++){
        cin >> t[i];
    }

    long long right = 0;
    long long left = 0;
    long long sum = 0;
    for(long long i = 0; i < n; i++){
        if(t[i] < right ){
            //left = t[i-1];
            right = t[i] + T;
        }
        else{
            sum += right - left;
            left = t[i];
            right = t[i] + T;

        }
    }

    sum += right - left;

    printf("%lld\n", sum);

    return 0;

}

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

int main(void){
    long long a,b,c,k;
    scanf("%lld%lld%lld%lld",&a,&b,&c,&k);
    if (k%2==0){
        printf("%lld\n",a-b);
    } else {
        printf("%lld\n",b-a);
    }
	return 0 ;
}

Measured memory_bytes: 128
N, *A = map(int, open(0).read().split())
M = (N+1)*N//2
S = sum(A)
if S%M!=0:
  print('NO')
  exit()
cnt = S//M
for i in range(N):
  df = A[(i+1)%N]-A[i]
  if (cnt-df)%N!=0 or cnt<df:
    print('NO')
    break
else:
  print('YES')

Measured memory_bytes: 14068
N = int(input())
As = list(map(int, input().split()))

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

res = 2*10**14
for i in range(len(As)-1):
    res = min(res, abs(2 * As[i] - As[-1]))
print(res)

Measured memory_bytes: 24800
#include <iostream>
#include <vector>
#include <algorithm>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
using namespace std;

const int MOD=1e9+7;
const int N=2e5+7;
int dp[N],arr[N];


int32_t main()
{
	IOS;
	int n;
	cin>>n;
	for (int i = 1; i <= n; ++i)
	{
		cin>>arr[i];
	}
	dp[1]=0;
	dp[2]=abs(arr[2]-arr[1]);
	for (int i = 3; i <= n; ++i)
	{
		dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
	}
	cout<<dp[n];

	return 0;
}



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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  vector<char> T(Q), D(Q);
  for (int i = 0; i < Q; i++)
    cin >> T[i] >> D[i];
  int left = 0, right = N - 1;
  for (int i = Q - 1; i >= 0; i--) {
    if (D[i] == 'L') {
      if (T[i] == S[left]) left++;
      if (right < N - 1 && T[i] == S[right + 1]) right++;
    } else {
      if (T[i] == S[right]) right--;
      if (left > 0 && T[i] == S[left - 1]) left--;
    }
  }
  cout << max(right - left + 1, 0) << '\n';
  return 0;
}


Measured memory_bytes: 976
#include<bits/stdc++.h>
#define ll long long int
#define pb(x) push_back(x)
#define vvi vector<vector<int>>
#define vec vector<int>
#define un unsigned
#define dbl double
#define wking(t) cout<<"Working "<<t<<endl;
#define loop(i,s,n) for(auto i=s;i!=n;i++)
#define eps 0.000000001
using namespace std;

int f(int a[],int n,int dp[])
{
    if(n<=0) return 0;
    if(dp[n]!=-1) return dp[n];
    dp[n] = min(f(a,n-1,dp)+abs(a[n]-a[n-1]),f(a,n-2,dp)+abs(a[n]-a[n-2]));
    return dp[n];
}

int calc(int a[],int n)
{
    int dp[n+1];
    memset(dp,-1,sizeof(dp));
    dp[1] = 0;
    dp[2] = abs(a[2]-a[1]);
    dp[n] = f(a,n,dp);
    // loop(i,0,n) cout<<dp[i+1]<<" ";
    // cout<<endl;
    return dp[n];
}

int main()
{
    int n;
    cin>>n;
    int a[n+1],dp[n+1];
    a[0] = 0;
    loop(i,0,n) cin>>a[i+1];
    cout<<calc(a,n)<<endl;
    return 0;
}


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

long long int N, a;

int main(){
    scanf("%lld", &N);
    //if(N == 7)return 0&puts("114514");
    a = N / 11;
    N %= 11;
    //cout << a << " " << N << endl;
    a *= 2;
    if(N > 0)++a;
    if(N > 6)++a;
    cout << a << endl;
    return 0;
}


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

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
int main(){
  int n,m;cin>>n>>m;
  int pin[n+100]={};
  for(int i=0;i<m;i++){
    int a,b;cin>>a>>b;
    pin[a-1]++;
    pin[b-1]--;
  }
  int ans=0;
  bool flag=false;
  int now=0;
  int po=0;
  for(int i=0;i<n;i++){
    now+=pin[i];
    if(now==0&&flag){
      ans+=(i-po)*2;
   
      flag=false;
    }else if(now!=0&&!flag){
      flag=true;
      po=i;
    }
  }
  cout<<ans+n+1<<endl;
  return 0;
}



Measured memory_bytes: 3140
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}

int main() {
  int n, h, w; cin >> n >> h >> w;
  cout << (n-h+1) * (n-w+1) << endl;

  return 0;
}



///


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

const int N = 110;
int n;
int l[N * 2];
int main()
{
    cin >> n;
    for (int i = 0; i < 2 * n; i ++ ) cin >> l[i];
    sort(l, l + n * 2);

    int res = 0;
    for (int i = 0; i < 2 * n - 1; i += 2)
        res += min(l[i], l[i + 1]);

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 3604
/*author* Priyanshu Shrivastav (from IIT Palakkad) *
 * *_ __ ___  _ ______ ___  _ ____   ___  ___| |_  *
 * | '_ ` _ \| '__/ __/ _ \| '_ \ \ / / |/ __| __| *
 * | | | | | | | | (_| (_) | | | \ V /| | (__| |_  *
 * |_| |_| |_|_|(_)___\___/|_| |_|\_/ |_|\___|\__| *
When I wrote this, only God and I understood what I was doing
 ** * * * * * * * Now, only God knows * * * * * * */
#include         <bits/stdc++.h>
using namespace std;
#pragma GCC      optimize ("Ofast")
#pragma GCC      optimize ("unroll-loops")
#pragma GCC      target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define IOS      ios_base::sync_with_stdio(false); cin.tie (nullptr)
#define PREC     cout.precision (10); cout << fixed
#define bg(x)    " [ " << #x << " : " << (x) << " ] "
#define x        first
#define y        second
using ll = long long;
using ff = long double;
using pii = pair<int,int>;

#define debug(args...) { \
/* WARNING : do NOT compile this debug func calls with following flags: // \
 * // -D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC -D_FORTIFY_SOURCE=2*/ \
   string _s = #args; replace(_s.begin(), _s.end(), ',', ' ');\
   stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); \
}
void err(istream_iterator<string> it) { it->empty();
   cerr << " (Line : " << __LINE__ << ")" << '\n';
}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << fixed << setprecision(15) << " [ " <<  *it << " : " << a  << " ] "<< ' ';
	err(++it, args...);
}

const int MOD = (int)1e9 + 7;
const int K = (int)1e5 + 10, N = 103;
int n, k;
int ar[N];

int dp[K];
int seg[4 * K];

int add(int a, int b) {
   a += b;
   if (a >= MOD) a -= MOD;
   return a;
}

int sub (int a, int b) {
   a -= b;
   if (a < 0) a += MOD;
   return a;
}

void create(int l, int r, int x) {
   if (l == r) {
      seg[x] = dp[l];
      return;
   }
   int mid = (l+r)/2;
   create(l, mid, x + x + 1);
   create(mid+1, r, x + x + 2);
   seg[x] = add(seg[x + x + 1], seg[x + x + 2]);
}

int query(int l, int r, int ql, int qr, int x) {
   if (l > qr || r < ql) return 0;
   if (l >= ql && r <= qr) return seg[x];
   int mid = (l+r)/2;
   return add(query(l, mid, ql, qr, x + x + 1), query(mid+1, r, ql, qr, x + x + 2));
}

void solve() {
   for (int i = 1; i <= k; ++i) dp[i] = 0;
   dp[0] = 1;

   for (int i = 1; i <= n; ++i) {
      vector <int> cum(k + 1);
      for (int j = 0; j <= k; ++j) {
         if (j) cum[j] = add(cum[j-1], dp[j]);
         else cum[j] = dp[j];
      }
//       create(0, k, 0);
      for (int j = k; j >= 0; --j) {
         int l = max(0,j-ar[i]), r = j;
         dp[j] = cum[r];
         if (l - 1 >= 0) dp[j]  = sub(dp[j], cum[l-1]);
         // dp[j] = query(0, k, max(0,j-ar[i]), j, 0);
//          for (int x = 1; x <= min(j, ar[i]); ++x) {
//             dp[j] = add(dp[j], dp[j-x]);
//          }
      }
   }
   cout << dp[k] << '\n';
}


signed main() {
   IOS; PREC;
   cin >> n >> k;
   for (int i = 1; i <= n; ++i) cin >> ar[i];
   solve();

   return EXIT_SUCCESS;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(){
int a[5001],dp[5001],i,n,b=-100001;
while(1){
scanf("%d\n",&n);
if(n==0){
break;
}
for(i=0;i<n;i++){
scanf("%d\n",&a[i]);
}
dp[0]=a[0];
for(i=1;i<n;i++){
if(dp[i-1]+a[i]<a[i]){
dp[i]=a[i];
}
else{
dp[i]=dp[i-1]+a[i];
}
}
for(i=0;i<n;i++){
if(b<dp[i]){
b=dp[i];
}
}
printf("%d\n",b);
b=-100001;
}
return 0;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;
// const int MOD = 998244353;

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

   int k;
   cin >> k;
   vector<ll> a;
   rep(i, 1, 10) a.push_back(i);
   while (1) {
      if (k <= a.size()) {
         cout << a[k - 1] << endl;
         return 0;
      }
      k -= a.size();
      vector<ll> old;
      swap(old, a);
      for (ll x : old) {
         rep(i, -1, 2) {
            int d = x % 10 + i;
            if (d < 0 || d > 9) continue;
            ll nx = x * 10 + d;
            a.push_back(nx);
         }
      }
   }
   return 0;
}

Measured memory_bytes: 1712
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
        int max = -100;
        int min = 100;
        for(int i=0;i<N;i++){
            a[i] = sc.nextInt();
            if(max<a[i]){
                max = a[i];
            }
            if(min>a[i]){
                min = a[i];
            }
        }
        
        int result = 1000000;
        for(int i=min;i<=max;i++){
            int sum = 0;
            for(int j=0;j<N;j++){
                sum += (a[j]-i)*(a[j]-i);
            }
            if(result>sum){
                result = sum;
            }
        }

        System.out.println(result);
    }
    
    
}


Measured memory_bytes: 9932
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <fstream>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <assert.h>
using namespace std;
#define eps 0.000000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define seg_size 65536*2
#define REP(i,n) for(long long i = 0;i < n;++i)
int dp[400000] = {};
int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= 300000; ++i) {
		dp[i] = 100000;
	}
	vector<int> hoge;
	hoge.push_back(1);
	for (int i = 6; i <= 100000; i *= 6) {
		hoge.push_back(i);
	}
	for (int i = 9; i <= 100000; i *= 9) {
		hoge.push_back(i);
	}
	for (int i = 0; i <= 100000; ++i) {
		for (int q = 0; q < hoge.size(); ++q) {
			int mee = i + hoge[q];
			if (dp[mee] > dp[i] + 1) {
				dp[mee] = dp[i] + 1;
			}
		}
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 1408
# -- coding:utf-8 --

r,d,x_2000=map(int, input().split())
x_i=[0]*10

for ii in range(0,10):
    if ii == 0:
        x_i[ii] = r * x_2000 - d
    else :
        x_i[ii] = r * x_i[ii-1] - d
    print(x_i[ii])


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	long long l0 = 2;
	long long l1 = 1;
	for (int i = 2; i <= n; i++)
	{
		l0 = l0 + l1;
		swap(l0, l1);
	}
	cout << l1 << endl;
	return 0;
}


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

using namespace std;

#define INF 1010001000
#define EPS 1e-10
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef pair<int, int> i_i;
typedef long long int llong;
typedef pair<llong, llong> ll_ll;
typedef struct edge {int f, t;}Edge;


int main()
{
    int n;
    while (cin >> n, n) {
        vector<pair<double, string> > input(n);
        rep(i, n) {
            cin >> input[i].second;
            int price, a, b, c, d, e, seed, sell, num;
            cin >> price >> a >> b >> c >> d >> e >> seed
                >> sell >> num;
            double time = a + b + c + (d + e) * num;
            double income = seed * sell * num - price;
            input[i].first = -income / time;
        }
        sort(input.begin(), input.end());
        rep(i, n) {
            cout << input[i].second << endl;
        }
        cout << "#" << endl;
    }
    return 0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll/*, vl, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define rep2(i, k, n) for(ll i = ll(k); i <= ll(n); i++)
#define rep3(i, n, k) for(ll i = ll(n); i >= ll(k); i--)
#define all(v) (v).begin(), (v).end()
ll mod(ll a, ll b) {if(b == 0) return 0; return (a % b + b) % b;}
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n, k;
  cin >> n >> k;
  
  vl p(n), c(n);
  rep(i, n) {cin >> p[i]; p[i]--;}
  rep(i, n) cin >> c[i];
  
  vb checked(n, 0);
  vl loop(n), sizes, scores;
  ll cnt_loop=0;
  rep(i, n) {
    if(checked[i]) continue;

    ll num=i, cnt_size=0, cnt_score=0;
    while(!checked[num]) {
      checked[num] = 1;
      loop[num] = cnt_loop;
      num = p[num];
      cnt_size++;
      cnt_score += c[num];
    }
    sizes.push_back(cnt_size);
    scores.push_back(cnt_score);
    cnt_loop++;
  }
  
  ll max_score=-INF;
  rep(i, n) {
    ll num=i, score=0;
    rep(_, min(n, k)) {
      num = p[num];
      score += c[num];
      chmax(max_score, score);
    }
  }
  
  if(n < k) rep(i, n) {
    ll score = (k/sizes[loop[i]]-1)*scores[loop[i]];
    chmax(max_score, score);
    ll num=i;
    rep(_, k%sizes[loop[i]]+sizes[loop[i]]) {
      num = p[num];
      score += c[num];
      chmax(max_score, score);
    }
  }
  
  cout << max_score << newl;
  return 0;
}

Measured memory_bytes: 3760
#include "bits/stdc++.h"
using namespace std;
const auto start_time = std::chrono::high_resolution_clock::now();
void timecalculater(){
    #ifndef ONLINE_JUDGE
    auto end_time = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
    #endif
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif
#define fastio  cin.sync_with_stdio(0); cin.tie(0);cin.exceptions(cin.failbit);
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a,v) memset(a, v, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1e9+7;
const int N=2e5+5;
int main() {
    
    fastio;
    int T=1;
    // cin>>T;
    while(T--){
        int h,w,k;cin>>h>>w>>k;
        char a[h][w];
        rep(i,h)rep(j,w)cin>>a[i][j];
        int cnt=0;
        rep(i,h)rep(j,w){
            if(a[i][j]=='#')cnt++;
        }
        k=cnt-k;
        if(k<0){
            cout<<0;return 0;
        }
        int ans=0;
        for(int i=0;i<(1<<h);i++){
            for(int j=0;j<(1<<w);j++){
                int cnt=0;
                rep(x,h){
                    rep(y,w){
                        if((i&(1<<x))||(j&(1<<y))){
                            if(a[x][y]=='#')cnt++;
                        }
                    }
                }
                if(cnt==k)ans++;
            }
        }
        cout<<ans;
    }   
    timecalculater();
    return 0;   
} 

Measured memory_bytes: 3652