akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;}return a>b; }
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;}return a<b; }
int weight[110],value[110];
int dp[110][100100];
signed main() {
  int N,W;
  cin>>N>>W;
  for(int i=0;i<N;i++) cin>>weight[i]>>value[i];
  for (int i=0;i<N;i++) {
    for (int sum=0;sum<=W;sum++) {
      if (sum>=weight[i]) {
        chmax(dp[i+1][sum], dp[i][sum-weight[i]]+value[i]); 
      }
      chmax(dp[i+1][sum], dp[i][sum]);
    }
  }
  cout << dp[N][W] << endl;
}


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

int main() {
  long N;
  cin >> N;
  vector<long> ans;


  for (long i = 1; i <= N; i++) {
    if (i % 3 == 0 && i % 5 == 0)  // iが3の倍数かつ5の倍数
      ans.push_back(0);
    else if (i % 3 == 0)  // iが3の倍数(かつ、5の倍数でない)
      ans.push_back(-1);
    else if (i % 5 == 0)  // iが5の倍数(かつ、3の倍数でない)
      ans.push_back(-1);
    else  // iが3の倍数でも5の倍数でもない
      ans.push_back(i);
  }

  long sum = 0;
  long cnt = 0;

  for (long i = 0; i <= N; i++){
    if (ans[i] == 0) {
      cnt += 1;
      if (cnt == N){
        break;
      }
    }else if(ans[i] == -1) {
      continue;
    }else {
      sum += ans[i];
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 11656
#include<iostream>
#include<algorithm> 
using namespace std;
int x[105],n;
int sum(int a)
{int s=0;
	for(int i=0;i<n;++i)
	s+=(a-x[i])*(a-x[i]);
	return s;
}
int main()
{
	cin>>n;int min=10000000;
	for(int i=0;i<n;++i)
	cin>>x[i];
	sort(x,x+n);
	for(int i=x[0];i<=x[n-1];++i)
	{int s=sum(i);
	if(s<min) min=s;	
	}
	cout<<min<<endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
  input! {
    n: usize, m: usize,
    av: [usize; m]
  };

  let sum: usize = av.into_iter().sum();
  let res = if sum > n { -1 } else { (n - sum) as isize };
  println!("{}", res);
}


Measured memory_bytes: 2232
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int main()
{
    string s;
    cin>>s;
    int year = 0,month = 0,day = 0;
    for(int i = 0;i < 4; ++i){
        year = year * 10 + (s[i]-'0');
    }
    month = (s[5] - '0') * 10 + s[6] - '0';
    day = (s[8] - '0') * 10 + s[9] - '0';
    bool vis = false;
    if(year > 2019) vis = true;
    if(year == 2019 )
    {
        if(month > 4) vis = true;
        if(month == 4)
        {
            if(day > 30) vis = true;
        }
    }
    if(vis) cout<<"TBD";
    else cout<<"Heisei";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ok() puts(ok?"Yes":"No");
template<class T> bool chmax(T &a, const T &b) { if(a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if(a > b) { a = b; return true; } return false; }
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vvi = vector<vi>;
using vii = vector<ii>;
using gt = greater<int>;
using minq = priority_queue<int, vector<int>, gt>;
using P = pair<ll,ll>;
const ll LINF = 1e18L + 1;
const int INF = 1e9 + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int N,Q;
int main() {
  cin >> N >> Q;
  string S; cin >> S;
  vi SA(N+1);
  for (int i=1; i<N; ++i) {
    if (S[i] == 'C') {
      if (S[i-1] == 'A') {
        SA[i+1]++; 
      }
    }
    SA[i+1] += SA[i];
  }
  rep(i,Q) {
    int l,r; cin >> l >> r;
    int ans = SA[r] - SA[l];
    cout << ans << endl;
  }
  // rep(i,N+1) cout << SA[i] << " ";
  return 0;
}

Measured memory_bytes: 3796
<?php 
  fscanf(STDIN,"%d %d %d",$a,$b,$k);
  $list = [];
  for($i=1; $i<=min($a,$b); $i++){
    if($a%$i == 0 && $b%$i == 0){
      $list[] = $i;
    }
  }
  rsort($list);
  echo $list[$k-1]."\n";


Measured memory_bytes: 4604
#include<iostream>
#include<algorithm>
using namespace std;
int DP[10001][101];
int main() {
	int N, W;
	cin >> N >> W;
	int  v[100], w[100];
	for (int i = 0; i < N; i++) {
		cin >> v[i] >> w[i];
	}
	for (int i = 1; i <= W; i++) {
		for (int j = 1; j <= N; j++) {
			if (i - w[j-1] < 0) {
				DP[i][j] = DP[i][j - 1];
			}
			else {
				DP[i][j] = max(DP[i][j - 1], DP[i - w[j-1]][j - 1] + v[j-1]);
			}
		}
	}
	cout << DP[W][N] << endl;
	cin >> N;
	return 0;
}


Measured memory_bytes: 7072
//K-OS WITH THE OCDE

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <iostream>
#include <numeric>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <deque>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <climits>

using namespace std;

typedef long long int ll;
typedef long double db;


#define TEST ll t; cin>>t; while(t--)
#define vell vector<ll>
#define pl pair<ll,ll>
#define all(v) v.begin(),v.end()
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define dbg(x)  cerr << #x << ": "<< x <<endl
#define dbg2(x,y) cerr<< #x <<": "<< x <<" || "<< #y << ": " << y << endl

#define endl "\n"
#define MAX 1e18
#define MIN INT_MIN
#define mod 1000000007



void solve()
{
    ll n;
    cin >> n;
    ll a[n];
    map <ll, ll> m , o;

    priority_queue <pair<ll, ll>> pq , pp;

    for (ll i = 0 ; i < n ; i++) {
        cin >> a[i];

        if (i & 1) m[a[i]]++;
        else o[a[i]]++;
    }


    ll mx = MIN , mm = MIN;
    for (auto it : m) {
        pq.push({it.ss , it.ff});
    }

    for (auto it : o) {
        pp.push({it.ss , it.ff});
    }


    if (pq.top().ss != pp.top().ss) {
        cout << n - pq.top().ff - pp.top().ff;
    }
    else {

        ll m1 = pq.top().ff;
        ll m2 = pp.top().ff;
        pq.pop();
        pp.pop();

        ll mm1 = 0 , mm2 = 0;

        if (pq.size())
            mm1 = pq.top().ff;

        if (pp.size())
            mm2 = pp.top().ff;

        cout << n - max(m1 + mm2 , m2 + mm1);
    }

}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0); cin.tie(0);
    //TEST
    solve();
}



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

int main(){
  //小数点以下12ケタを表示させるためのおまじない
  cout<<fixed<<setprecision(12);
  
  double a,b,C;
  cin>>a>>b>>C;

  double PI=acos(-1.0);

  //Cをラジアンに直す
  C=C/180.0*PI;
  
  cout<< a*b*sin(C)/2.0 <<endl;
  
  // c*c = a*a + b*b - 2*a*b*cosC
  double cc=a*a+b*b-2*a*b*cos(C);
  cout<< a+b+sqrt(cc) <<endl;
  
  cout<< b*sin(C) <<endl;
  
  return 0;  
}



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

typedef long long ll;

using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<ll> sum(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        ll p;
        cin >> p;
        sum[i] = p + 1 + sum[i - 1];
    }
    ll mx = -1e18;
    for (int i = 0; i <= n - k; i++) {
        mx = max(mx, sum[i + k] - sum[i]);
    }
    double ans = mx;
    ans /= 2;
    printf("%.10f\n", ans);
    return 0;
}


Measured memory_bytes: 1792
#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 << a*b << endl;
  else if ( (a*b) <= (c*d))
    cout << c*d << endl;
return 0;

}

Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, M;
    cin >> N >> M;
    priority_queue<int> que;
    REP(i, N) {
        int A;
        cin >> A;
        que.push(A);
    }
    REP(i, M) {
        int t = que.top(); que.pop();
        que.push(t / 2);
    }
    ll ans = 0;
    while (!que.empty()) {
        int t = que.top(); que.pop();
        ans += t;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int N; string S,T;
    cin >> N >> S >> T;
    string ans = {};
    for (int i = 0;i < N;i++){
        ans += S[i];
        ans += T[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = {}
for i in range(n):
    b[a[i]] = b[a[i]]+1 if a[i] in b else 1
b = list(b.items())
if len(b) == 1:
    print("Yes") if b[0][0] == 0 else print("No")
elif len(b) == 2:
    b.sort()
    print("Yes") if b[0][0] == 0 and b[0][1]*2 == b[1][1] else print("No")
elif len(b) == 3:
    print("Yes") if b[0][0]^b[1][0]^b[2][0] == 0 and b[0][1] == b[1][1] and b[1][1] == b[2][1] else print("No")
else:
    print("No")

Measured memory_bytes: 20544
#include <cstdio>
#include <string>
#include <iostream>

using namespace std;
#define ASCII 48

bool checkMM(int, int);

int main() {
	
	std::string str = "";
	cin >> str;

	int pal[4];

	pal[0] = str[0] - ASCII;
	pal[1] = str[1] - ASCII;
	pal[2] = str[2] - ASCII;
	pal[3] = str[3] - ASCII;

	bool first = checkMM(pal[0], pal[1]);
	bool second = checkMM(pal[2], pal[3]);

	if (first) {
		if (second) cout << "AMBIGUOUS" << endl;
		else cout << "MMYY" << endl;
	}
	else if (second) {
		cout << "YYMM" << endl;
	}
	else {
		cout << "NA" << endl;
	}

	return 0;
}

bool checkMM(int a,int b){
	switch (a) {
	case 0:
		if(b != 0)return true;
		break;
	case 1:
		if (b < 3) return true;
		break;
	default:
		return false;
	}
	return false;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
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; }

int main(){
    int x; cin >> x;
    if(x >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int n;
ll x[105],y[105],h[105];

ll calc(ll a,ll b){
    ll H=0; int j=0;
    while(H<=0){
        if(h[j]!=0){
        H = h[j]+labs(x[j]-a)+labs(y[j]-b);
        }
        j++;
    }
    rep(i,n){
        if(h[i]==0 && H-labs(x[i]-a)-labs(y[i]-b) <= 0) continue;
        if(H != h[i]+labs(x[i]-a)+labs(y[i]-b) ){
            return -1;
        }
    }
    return H;
}

int main(){
    cin >> n;
    rep(i,n){
        cin >> x[i] >> y[i] >> h[i];
    }
    ll ans = 0;
    int ansx=0,ansy=0;
    for(int a=0;a<=100;a++){
        for(int b=0;b<=100;b++){
            if(calc(a,b)>0){
                ansx=a;
                ansy=b;
                ans=calc(a,b);
            }
        }
    }
    cout << ansx <<" "<<ansy<<" "<<ans<< endl;
}




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

const ULL HS=19260817;
const int maxn=1e5;

ULL ans=0;
int du[maxn+10];
vector<int>G[maxn+10];
unordered_map<ULL,ULL>S;

ULL gao(int x){
	ULL t=0;
	for(int i=0;i<du[x];i++)t+=gao(G[x][i]);
	t=t*HS+1;
	ans+=S[t]++;
	return t;
}

int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		G[a].push_back(b);
		du[a]++;
	}
	gao(1);
	//printf("%llu\n",ans);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 19084
n,t = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)
prof = Array.new(n)
m = 0
(n-1).downto(0) do |i|
  m = [m,a[i]].max
  prof[i] = m-a[i]
end
puts prof.count(prof.max)

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

using namespace std;

int const N = 2222;

int ss[N][N], s[N][N];

int d[N], st[N];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int c = getchar();
      while (c <= 32) c = getchar();
      ss[i][j] = c;
    }
    for (int j = 0; j + 1 < m; j++) {
      s[i][j] = ss[i][j] != ss[i][j + 1];
    }
  }
  int ans = std::max(n, m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j + 1 < m; j++) {
      if (i == 0) {
        d[j] = 1;
      } else if (s[i][j] == s[i - 1][j]) {
        d[j]++;
      } else {
        d[j] = 1;
      }
    }
    d[m - 1] = -1;
    int cn = 0;
    for (int j = 0; j < m; j++) {
      while (cn > 0 && d[st[cn - 1]] >= d[j]) { 
        int last = st[--cn];
        int prev = cn == 0 ? -1 : st[cn - 1];
        ans = std::max(ans, (j - prev) * d[last]);
      }
      st[cn++] = j;
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 37120
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)
#define RFOR(i,s,n) for(int i=(int)(n)-1,i##_len=(int)(s);i>=i##_len;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define MOD 2019

typedef long long ll;
typedef unsigned long long ull;

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};
//今回の変数

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int  a, int  b) {
	return (a) > (b) ? (a) : (b);
}
ll Minl(ll a, ll b) {
	return (a)<(b) ? (a) : (b);
}
ll Maxl(ll a, ll b) {
	return (a)>(b) ? (a) : (b);
}
void hSwap(int x[], int i, int j)
{
	int temp;

	temp = x[i];
	x[i] = x[j];
	x[j] = temp;
}
void ShowData(int x[], int left, int right)
{
	int i;
	for (i = left; i <= right; i++)printf("%d  ", x[i]);
	printf("\n");
}
void QSort(int x[], int left, int right, int n) {
	int i, j;	//左端,右端
	int pivot;	//軸

	i = left;
	j = right;
	pivot = x[(left + right) / 2];

	while (1) {
		if (n > 0) {				//n>0なら昇順、n<=0なら降順
			while ((x[i] < pivot) && (i <= right))i++;	//軸値より大きい要素
			while ((pivot < x[j]) && (i <= right))j--;	//軸値より小さい要素
		}
		else {
			while ((x[i] > pivot) && (i <= right))i++;	//軸値より小さい要素
			while ((pivot > x[j]) && (i <= right))j--;	//軸値より大きい要素
		}
		if (i >= j)	break;
		hSwap(x, i, j);
		i++; j--;
	}
	//ShowData(x, left, right);

	if (left < i - 1)QSort(x, left, i - 1, n);
	if (j + 1 <  right)QSort(x, j + 1, right, n);
}


int main() {
	int n,d;
	scanf("%d%d", &n,&d);
	PRINTD((n + 2 * d) / (2*d+1));
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#define MD 150
#define P pair<int,int> // 人数, 予算*MD+ノード
using namespace std;

struct Path{
  int to,d,n;
  Path(int to=0,int d=0,int n=0):to(to),d(d),n(n){};
};


int main(){
  int N,m,l;
  int a,b,d,e;

  while( cin>>N>>m>>l && (N|m|l) ){
    vector<Path> v[110];
    for( int i=0;i<m;i++ ){
      cin>>a>>b>>d>>e;
      a--; b--;
      v[a].push_back( Path(b,d,e) );
      v[b].push_back( Path(a,d,e) );
    }
    /*
    for( int i=0;i<N;i++ ){
      for( unsigned int j=0;j<v[i].size();j++ )
	cout << " " << v[i][j].to+1;
      cout << endl;
    }
    */

    priority_queue<P,vector<P>,greater<P> > q;
    
    int dL = 110*MD+100 +100;
    int d[ dL  ]; // [ノード*MD+予算]での最小人数
    const int iniC = 100*10000 * 10;
    for( int i=0,len=dL;i<len;i++ )
      d[i] = iniC;
    
    // 人数、残り予算*MD+ノード
    q.push( P(0,l*MD+0) );
    int ans=-1;
    while( !q.empty() ){
      P p=q.top(); q.pop();
      int n=p.first; // 人数
      int l=p.second/MD; //残り予算
      int s=p.second%MD; // 現在のノード

      if( s==N-1 ){
	ans = n; break;
      }

      for( unsigned int i=0;i<v[s].size();i++ ){
	int ns=v[s][i].to;
	if( l>=v[s][i].d ){ // 護衛を雇う場合
	  int nl = l-v[s][i].d;
	  int state = nl*MD+ns;

	  if( n<d[state] )
	    q.push( P(d[state]=n,state) );
	}
	// 護衛を雇わない場合
	int nn = n + v[s][i].n;
	int state = l*MD+ns;
	if( nn< d[state] )
	  q.push( P(d[state]=nn,state) );
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1128
#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>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

int n;

ll dp[100001];

int main(){
	cin >> n;
	vector<ll> vl;
	vl.push_back(1);
	ll num = 6;
	while(num <= 100000){
		vl.push_back(num);
		num *= 6;
	}
	num = 9;
	while(num <= 100000){
		vl.push_back(num);
		num *= 9;
	}
	fill(dp,dp+100001,INF);
	dp[0] = 0;
	rep(i,vl.size()){
		rep(j,n){
			if(j+vl[i] <= n)dp[j+vl[i]] = min(dp[j]+1,dp[j+vl[i]]);
		}
	}
	cout << dp[n] << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  	int n,k;
  	cin>>n>>k;
  	vector<int> prices;
  	int price;
    while(cin>>price){
        prices.push_back(price);
    }
  	
  	sort(prices.begin(),prices.end());
  	
  	int answer=0;
  	for(int i=0;i<k;i++){
      	answer+=prices[i];
    }
  	
  	cout<<answer<<endl;
  	return 0;
  	
}

Measured memory_bytes: 3640
n = int(input())
a = []
for i in range(n):
    a.append(int(input()))
b = list(a)
a.sort(reverse=True)

max_num = max(a)
count = a.count(max_num)

for i in a:
    if i < max_num:
        max_num2 = i
        break

for i in range(n):
    if b[i] == max_num and count == 1:
        print(max_num2)
    else:
        print(max_num)

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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;

int dig(ll t){

	int digit=0;
	    while(t!=0){
	        t /= 10;
	        digit++;
	    }
	    return digit;
}

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

	int a,b,c,d;cin>>a>>b>>c>>d;


	for(int i=0; i<210; i++){
		if(i %2 ==0){
			c -=b;
		}else {
			a -=d;
		}
	if( c<=0){
		writeln("Yes");
		return 0;
	}

	if( a<=0){
		writeln("No");
	return 0;
	}
	}

}




Measured memory_bytes: 3608
use proconio::input;

fn main() {
    input! {
        n: usize,
        m: usize,
    }
    let p = 1000000007;
    let max = 510000;

    let mut com = COM::new(max, p);
    com.init();

    let v = prime_factorize(m);

    let mut ans = 1;
    for &nv in &v {
        let tmp = com.com(n - 1 + nv.1, nv.1);
        ans = ans * tmp % p;
    }

    println!("{}", ans);
}

fn prime_factorize(mut n: usize) -> Vec<(usize, usize)> {
    let mut res = vec![];
    let mut a = 2;
    while a * a <= n {
        if n % a != 0 {
            a += 1;
            continue;
        }
        let mut ex = 0;

        while n % a == 0 {
            ex += 1;
            n /= a;
        }

        res.push((a, ex));
        a += 1;
    }
    if n != 1 {
        res.push((n, 1));
    }

    res
}

struct COM {
    fac: Vec<isize>,
    finv: Vec<isize>,
    inv: Vec<isize>,
    max: usize,
    m: isize,
}

impl COM {
    fn new(max: usize, m: isize) -> Self {
        COM {
            fac: vec![0; max],
            finv: vec![0; max],
            inv: vec![0; max],
            max: max,
            m: m
        }
    }

    fn init(&mut self) {
        self.fac[0] = 1;
        self.fac[1] = 1;
        self.finv[0] = 1;
        self.finv[1] = 1;
        self.inv[0] = 0;
        self.inv[1] = 1;

        let mut i = 2;
        while i < self.max {
            self.fac[i] = self.fac[i - 1] * i as isize % self.m;
            self.inv[i] = self.m as isize - self.inv[self.m as usize % i] * (self.m / i as isize) % self.m;
            self.finv[i] = self.finv[i - 1] * self.inv[i] % self.m;
            i += 1;
        }
    }

    fn com(&self, n: usize, k: usize) -> isize {
        if n < k {
            return 0;
        }
        self.fac[n] * (self.finv[k] * self.finv[n - k] % self.m) % self.m
    }
}


Measured memory_bytes: 13940
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int m,a[10],b[10]={0,2,5,5,4,5,6,3,7,6},memo[10101];
bool done[10101];

int solve(int x){
	int i,ans;
	if(done[x]){
		return memo[x];
	}
	done[x] = true;
	if(!x){
		memo[x] = 0ll;
		return memo[x];
	}else if(x==1){
		memo[x] = -INF;
		return memo[x];
	}
	memo[x] = -INF;
	for(i=0; i<m; ++i){
		if(x<b[a[i]]){
			continue;
		}
		memo[x] = max(memo[x],solve(x-b[a[i]]));
	}
	++memo[x];
	return memo[x];
}

int main(void){
	int n,i;
	fill(done,done+10101,false);
	cin >> n >> m;
	for(i=0; i<m; ++i){
		cin >> a[i];
	}
	sort(a,a+m,greater<int>());
	while(n){
		for(i=0; i<m; ++i){
			if(n<b[a[i]]){
				continue;
			}
			if(solve(n-b[a[i]])+1 == solve(n)){
				cout << a[i];
				n -= b[a[i]];
				break;
			}
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
const long double pi = acos(-1);
const long double eps = 1e-10;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

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

    auto dp = vec<int>(n + 1, m + 1);
    FOR(i, 0, n)FOR(j, 0, m) {
        chmax(dp[i + 1][j + 1], max(dp[i + 1][j], dp[i][j + 1]));
        if (s[i] == t[j])chmax(dp[i + 1][j + 1], dp[i][j] + 1);
    }

    string ans = "";
    while (0 < n && 0 < m) {
        if (dp[n][m] == dp[n - 1][m])--n;
        else if (dp[n][m] == dp[n][m - 1])--m;
        else {
            --n, --m;
            ans += s[n];
        }
    }

    reverse(all(ans));
    cout << ans << "\n";
}


Measured memory_bytes: 35584
using System;
using System.Collections.Generic;
class Program
{

    static void Main()
    {
        string[] X = Console.ReadLine().Split(' ');
        int x = int.Parse(X[0]);

        if(x>=30)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }

    }

}



Measured memory_bytes: 27536
while True:
    n=int(input())
    if n==0:break
    s=input()
    conv=""
    for _ in range(n):
        seq=1
        pr=s[0]
        for i in range(1,len(s)):
            if pr==s[i]:seq+=1
            else:
                conv+=str(seq)+pr
                pr=s[i]
                seq=1
        conv+=str(seq)+pr
        s=conv
        conv=""
    print(s)

Measured memory_bytes: 7772
from collections import deque
import math
from functools import reduce

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n = int(input())
ans = [-1] * n
ans[0] = 0

edges = [ [] for _ in range(n)]
for i in range(n-1):
    u,v,w = get_nums_l()
    edges[u-1].append([v-1,w%2==0])
    edges[v-1].append([u-1,w%2==0])

def aaa(x):
    # xを含むエッジ

    # breakpoint()

    for edge in edges[x]:
        to = edge[0] # edgeのうちxじゃないほう
        if ans[to] != -1:
            continue
        same = edge[1]
        ans[to] = ans[x] ^ (not same)

        queue.append(to)

queue = deque()
queue.append(0)
while queue:
    aaa(queue.popleft())
for annn in ans:
    print(annn)

Measured memory_bytes: 90912
import java.util.Scanner;

public class Main {
    public  static  void main(String args[]){
        Scanner sc= new Scanner(System.in);
        int n= sc.nextInt();
        int k=sc.nextInt();
        int h []=new int[n];
        for(int j=0;j<n;j++)
            h[j]=sc.nextInt();
        int cost[]= new int [n];
        for(int i=0;i<k&&i<n;i++){
            cost[i]=Math.abs(h[i]-h[0]);
        }
        if(k<n)
            for (int i=k;i<n;i++){
            int j=1,temp,val=Integer.MAX_VALUE;
            while(j<=k){
                temp=cost[i-j]+Math.abs(h[i]-h[i-j]);
                if(temp<val){
                    val=temp;
                }
                j++;
            }
            cost[i]=val;
        }
        System.out.println(cost[n-1]);
    }
}


Measured memory_bytes: 50960
#include <stdio.h>
/*ABC 134 C*/

int main(void)
{
  int N;
  int max1=0,max2=0;
  int counter1;
  int number;

  scanf("%d", &N);
  for (size_t i = 0; i < N; i++) {
    scanf("%d", &number);
    if (number > max1) {
      max1 = number;
      counter1 = i+1;
    }else if(number > max2){
      max2 = number;
    }
  }

  for (size_t i = 0; i < N; i++) {
    if(i != counter1-1)printf("%d\n", max1);
    else printf("%d\n", max2);
  }
}


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

int main() {
    int N;
    int a, b;
    int count = 0;
    cin >> N;

    for (int i = 0; i < N; i++) {
        cin >> a >> b;
        for (int j = a; j <= b; j++) {
            ++count;
        }
    }
    cout << count << endl;
}


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

int64_t mod = 1000000007;

int main()
{
    int N, tmp;
    cin >> N;
    vector<int> list(N);
    for (int i = 0; i < N; i++)
        cin >> list[i];

    sort(list.begin(), list.end());
    cout << list[N / 2] - list[(N - 1) / 2];
}

Measured memory_bytes: 640
#include<iostream>
#include<math.h>
#include <algorithm>
using namespace std;
int a[200005];
long long ss(long long x,long long sum)
{
	long long a;
	if(x==1)
		return 1;
	else
	{
		a=ss(x/2,sum)*2+1;
		sum+=a;
	}
	return sum;
}
int main()
{
	long long n,h,k,sum=0;
	cin>>h;
	sum=ss(h,0);
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MAX 200000
#define SENTINAL 2000000000
typedef long long llong;

int L[MAX / 2+2], R[MAX / 2+2];

llong merge(int A[], int n, int left, int mid, int right)
{
	int i, j, k;
	llong cnt = 0;
	int n1 = mid - left;
	int n2 = right - mid;
	for(i=0; i<n1; i++){
		L[i] = A[left + i];
	}
	for(i=0; i<n2; i++){
		R[i] = A[mid + i];
	}
	L[n1] = R[n2] = SENTINAL;
	i =0;
	j = 0;
	for(k=left; k<right; k++){
		if(L[i] <= R[j])
		{
			A[k] = L[i++];
		}
		else
		{
			A[k] = R[j++];
			cnt += n1 - i;
		}
	}
	return cnt;
}


llong mergeSort(int A[], int n, int left, int right)
{
	int mid;
	llong v1, v2, v3;
	if(left + 1 < right)
	{
		mid = (left + right) /2;
		v1 = mergeSort(A, n, left, mid);
		v2 = mergeSort(A, n, mid, right);
		v3 = merge(A, n, left, mid, right);
		return v1 + v2 + v3;
	}
	else return 0;
}


int main (void)
{
	int A[MAX], n, i;
	
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d", &A[i]);
	}
	
	llong ans = mergeSort(A, n, 0, n);
	printf("%lld\n", ans);
	
	return 0;
}



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

using namespace std;
typedef long long ll;

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n), b(n);
    map<ll, bool> mp;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        mp[a[i]] = i % 2;
        b[i] = a[i];
    }
    sort(b.begin(), b.end());
    ll ret = 0;
    for(int i = 0; i < n; i++) {
        if(mp[b[i]] != i % 2) ret++;
    }
    cout << ret / 2 << endl;
    return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N, M;
	cin >> N >> M;
	priority_queue<int>q;
	for (int i = 0; i < N; i++){
		int a;
		cin >> a;
		q.push(a);
	}
	
	for (int i = 0; i < M; i++){
		int p = q.top();
		q.pop();
		q.push(p / 2);
	}

	long long ans = 0;
	for (int i = 0; i < N; i++){
		ans += (long long)(q.top());
		q.pop();
	}
	cout << ans << endl;
	return 0;
}

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

p = 0
ans = 0
for enemy, power in zip(A, B):
    if enemy >= p:
        enemy -= p
        ans += p
    else:
        ans += enemy
        enemy = 0
        p = 0
    if enemy <= power:
        p = power - enemy
        ans += enemy
    else:
        ans += power
        p = 0
ans += min(p, A[-1])

print(ans)


Measured memory_bytes: 82020
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
n,m = ma()
s = input()
dp = [-1]*(n+1) #dp[i]:: i番目にたどり着く最小コスト
dp[0]=0
r=0
while r<=n-1:
    l=0
    tmp=0
    while l+1<=m and r+l+1<=n:
        l+=1
        if s[r+l]=="0":
            tmp=l
            dp[r+l]=dp[r]+1
    r+=tmp
    #if r==n:break
    if tmp==0:
        print(-1)
        exit()
d = dp[-1]
rt = []
dp = dp[::-1]
r=0
while r<=n-1:
    l=0
    tmp=0
    while l+1<=m and r+l+1<=n:
        l+=1
        if dp[r+l]==d-1:
            tmp=l
    rt.append(tmp)
    d-=1
    r+=tmp
print(*reversed(rt))


Measured memory_bytes: 82688
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define FORCLS(i,a,b) for(int i = (a); i <= (b); i++)
#define REPCLS(i,n) FORCLS(i,1,n)

using Int = long;

const Int n_max = 100004;
Int n,a,b;
Int h[n_max];

bool check(Int cnt) {
    Int c = 0;
    REP(i, n) {
        Int v = h[i] - cnt*b;
        if (v <= 0) return true;;
        Int q = v / (a - b);
        Int r = v % (a - b);
        q = q + (r == 0 ? 0 : 1);
        c += q;
        if (cnt < c) return false;
    }
    return true;
}
void solve() {
    cin >> n >> a>> b;
    REP(i,n) { cin >> h[i];}
    sort(h, h + n, [](Int a, Int b) { return a > b; });
    h[n] = 0;
    
    Int l = 0;
    Int r = 1000000001;
    while (r - l > 1) {
        Int mid = (r + l) / 2;
        
        if (check(mid)) {
//            cout << mid << endl;
            r = mid;
        }
        else {
//            cout << "  " << mid << endl;
            l = mid;
        }
    }
    cout << r << endl;
}
#ifdef DEBUG
#define MAIN hoge
#else
#define MAIN main
#endif

int MAIN() {
    solve();
    
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

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

const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;

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

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

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

const int MAXN = 110000;

int memo[MAXN];

int dfs(int s){
    if(s == 0) return 0;
    if(memo[s] != -1) return memo[s];
    int res = s;
    for(int i = 1; i <= s; i*=6) res = min(res,dfs(s-i)+1);
    for(int i = 1; i <= s; i*=9) res = min(res,dfs(s-i)+1);
    return memo[s] = res;
}

int main(){
    int N;
    cin >> N;
    for(int i = 0; i < MAXN; i++) memo[i] = -1;
    cout << dfs(N) << endl;
    return 0;
}


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

#define ll long long

int main() {
    std::ios::sync_with_stdio(false);
    using namespace std;
    const ll max_cost = 50, 
             max_time = 1'000'000'000'000'000'000;
    ll n, m, s, u, v, a, b;
    cin >> n >> m >> s;
    vector< vector< tuple<ll, ll, ll> > > G(n); // dest, cost, time
    while(m--) {
        cin >> u >> v >> a >> b;
        u--; v--;
        G[u].push_back({v, a, b});
        G[v].push_back({u, a, b});
    }

    vector<ll> D(n), C(n);
    for(int i = 0; i < n; i++)
        cin >> C[i] >> D[i];

    ll max_silver_needed = n * max_cost;
    vector< vector<ll> > X(n, vector<ll>(max_silver_needed + 1, max_time));
    priority_queue< tuple<ll, ll, ll> > Q; // time, node, silver_left

    Q.push({0, 0, min(max_silver_needed, s)});
    while(Q.size()) {
        auto [time, node, silver] = Q.top(); Q.pop();
        //cout << time << " " << node << " " << silver << "\n";
        if(X[node][silver] != max_time) continue;
        X[node][silver] = -time;
        for(int i = 0; i < G[node].size(); i++) {
            auto [dest, cost, time_cost] = G[node][i];
            if(cost <= silver && X[dest][silver - cost] == max_time) {
                Q.push({time - time_cost, dest, silver - cost});
            }
        }
        if(silver < max_silver_needed) {
            Q.push({time - D[node], node, min(max_silver_needed, silver + C[node])});
        }
    }

    for(int i = 1; i < n; i++) {
        ll best = max_time;
        for(int j = 0; j < max_silver_needed + 1; j++)
            best = min(best, X[i][j]);
        cout << best << "\n";
    }
    return 0;
}


Measured memory_bytes: 10472
#include<bits/stdc++.h>
using namespace std;
long long a[1001],b[1001];
long long fj(int x){
	for(int i=2;i<=x;i++){
		while(x%i==0){
            x/=i;a[i]++;
		}
	}
	if(x!=1) a[x]++;
}

int main(){
	int n,i;
	cin>>n;
	for(int i=2;i<=n;i++){
		fj(i);
	}
	long long ans=1;
	for(i=2;i<=n;i++){
		if(a[i]!=0){
			ans*=a[i]+1;
			ans%=1000000007;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

pub trait InputValue {
    fn parse(s: &str) -> Self;
}

pub fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

pub fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

pub fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);
parse_tuple!(A, B, C, D);
parse_tuple!(A, B, C, D, E);

// ===

fn main() {
    let (h, w): (usize, usize) = read();
    let mut cost_table = vec![vec![0; 10]; 10];
    for i in 0..10 {
        let c: Vec<i32> = readnc();
        for j in 0..10 {
            cost_table[i][j] = c[j];
        }
    }

    for k in 0..10 {
        for i in 0..10 {
            for j in 0..10 {
                cost_table[i][j] = min(cost_table[i][j], cost_table[i][k] + cost_table[k][j]);
            }
        }
    }

    let mut counter = vec![0; 10];
    for _i in 0..h {
        let c: Vec<i32> = readnc();
        for j in 0..w {
            if c[j] >= 0 {
                counter[c[j] as usize] += 1;
            }
        }
    }

    let mut total_cost = 0;
    for x in 0..10 {
        total_cost += counter[x] * cost_table[x][1];
    }
    println!("{}", total_cost);
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
long long a[1005];
int main()
{
    int n;
    scanf("%d",&n);
    a[0] = 2;
    a[1] = 1;
    for(int i=2; i<=n; i++)
    {
        a[i] = a[i-1]+a[i-2];
    }
    printf("%lld\n",a[n]);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int sumL = 0;
        int maxL = 0;
        for (int i = 0; i < n; i++) {
            int l = sc.nextInt();
            sumL += l;
            if (l > maxL) {
                maxL = l;
            }
        }
        if (maxL < sumL - maxL) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=1010001000;
const ll  INF=1001000100010001000;
const int mod=(int)1e9+7;

int main(){
    string s,t;
    cin>>s>>t;
    int n=s.size();
    map<char,char>m;
    rep(i,0,n){
        m[s.at(i)]=t.at(i);       
    }
    for(char c='a'; c<='z';c++){
        for(char d='a';d<='z'; d++){
            if(!m.count(c) or !m.count(d) or c==d)continue;
            if(m[c]==m[d]){        
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    rep(i,0,n){
        s.at(i)=m[s.at(i)]; 
    }
    cout<<(s==t?"Yes":"No")<<endl; 
return 0;
}

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

int main(){

    int n, q;
    cin >> n >> q;

    vector<list<int>> ls(n);
    for(int i = 0; i < q; ++i){
        int com;
        cin >> com;
        if(com == 0){
            int t, x;
            cin >> t >> x;
            ls[t].insert(ls[t].end(), x);
        }
        else if(com == 1){
            int t;
            cin >> t;
            for(auto it = ls[t].begin(); it != ls[t].end(); ++it){
                cout << *it;
                if(it != prev(ls[t].end())){
                    cout << " ";
                }
            }
            cout << endl;
        }
        else if(com == 2){
            int s, t;
            cin >> s >> t;
            ls[t].splice(ls[t].end(), ls[s]);
            ls[s].clear();
        }
    }
    return 0;
}


Measured memory_bytes: 18724
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

const int INF = 1e9;

int a[(int)1e5];

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

	int n,m;
	cin >> n >> m;

	int tmp;
	for(int i=0;i<n;i++){
		cin >> tmp;
		a[i] = tmp % m;
	}

	map<int,long long> ma;
	int rui=0;
	ma[0]++;
	long long ans=0;
	for(int i=0;i<n;i++){
		rui += a[i] % m;
		rui %= m;
		ans += ma[rui]++;
	}

	cout << ans << "\n";
	return 0;
}

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

#define MAX 251
//#define NIL -1

int main(void){
  int i,n,left,right;
  int A[MAX];

  scanf("%d", &n);
  for(i=1; i<n+1; i++) scanf("%d", &A[i]);

  for(i=1; i<n+1; i++){
    printf("node %d: key = %d, ", i, A[i]);
    if(i/2 != 0) printf("parent key = %d, ", A[i/2]);
    if(i*2 <= n) printf("left key = %d, ", A[i*2]);
    if(i*2+1 <= n) printf("right key = %d, ", A[i*2+1]);
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
int inf = 1e9;

int main() {
  int n, m;
  cin >> n >> m;
  int dp[n][n];
  int dp0[n][n];
  fill(dp[0], dp[n], inf);
  for (int i = 0; i < n; i++) {
    dp[i][i] = 0;
  }
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    dp[a][b] = c;
    dp[b][a] = c;
  }

  copy(dp[0], dp[n], dp0[0]);

  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (dp[i][j] < dp0[i][j] && dp0[i][j] != inf) {
        ans++;
        //       cout << i << " " << j << " " << dp[i][j] << " " << dp0[i][j] <<
        //       endl;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 384
n = int(input())
l = [int(input()) for _ in range(n)]
ans = sum(l)
l.sort()
if not ans%10==0:
    print(ans)
    exit()
for i in range(len(l)):
    if not l[i]%10==0:
        print(ans-l[i])
        exit()
print(0)

Measured memory_bytes: 3060
/*Shivam Bhalla */
/* f2016941@pilani.bits-pilani.ac.in */



#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iostream>
#include <string>
#include <cmath>
#include <cassert>
#include <bits/stdc++.h>
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
long long maxv = 1e9;

int main() {
  int N;
  cin>>N;
  cout<<(3*N*N);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define mp make_pair
#define F first
#define S second
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define INF 0x3f3f3f3f
typedef long long ll;
/*while(l<=r)
{
    ll mid=(l+r)/2;
    if(check(mid)) r=mid-1;
    else l=mid+1;
}*/
ll n,k;
ll num[100000005];
map<string,string> m;
int main()
{
    m["Sunny"]="Cloudy";
    m["Cloudy"]="Rainy";
    m["Rainy"]="Sunny";
    string s;
    while(cin>>s)
    {
        cout<<m[s]<<"\n";
    }

    return 0;
}


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

int main()
{
  int n, d, x;
  cin >> n >> d >> x;
  vector<int> a(n);
  int i;
  for(i = 0; i < n; i++)
  {
    cin >> a.at(i);
  }
  for(i = 0; i < n; i++)
  {
    x += (d-1)/a.at(i) + 1;
  }
  cout << x << endl;
}

Measured memory_bytes: 256
import sys
import re
import math

# import bisect

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
# MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    a,b,c=ns()
    print(min(c, b//a))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include<algorithm>
#include <string>
#include <cmath>
#include<queue>
#define PI 3.141592653589793238
#define ll long long
using namespace std;

int main()
{
	vector<int> permi;
	int p, q, count;
	int n, tmp, np, nq;

	cin >> n;
	np = 0;
	nq = 0;
	p = 0;
	q = 0;
	count = 0;

	for (int i = 0; i < n; i++) {
		cin >> tmp;
		p = p * 10 + tmp;
	}
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		q = q * 10 + tmp;
	}
	for (int i = 0; i < n; i++) {
		permi.emplace_back(i + 1);
	}
	
	do
	{
		tmp = 0;
		count++;
		for (int i : permi) {
			tmp = tmp * 10 + i;
		}
		if (p == tmp) {
			np = count;
		}
		if (q == tmp) {
			nq = count;
		}

		if (np * nq) {
			break;
		}
	} while (next_permutation(permi.begin(), permi.end()));
	
	printf("%d", abs(np-nq));

	return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265359

int main(void)
{
	vector<int> ans(26);
	string s;

	while (getline(cin, s)) {
		rep(i, s.length()) {
			if (s.at(i) >= 'a' && s.at(i) <= 'z') {
				++ans.at(s.at(i) - 'a');
			}
			else if (s.at(i) >= 'A' && s.at(i) <= 'Z') {
				++ans.at(s.at(i) - 'A');
			}
		}
	}
	rep(i, 26)
		cout << char('a' + i) << " : " << ans.at(i) << endl;
}



Measured memory_bytes: 3152
from string import ascii_lowercase


def main():
    n = int(input())
    count = {a: 10 ** 9 + 7 for a in ascii_lowercase}
    for _ in range(n):
        s = input()
        for a in ascii_lowercase:
            count[a] = min(count[a], s.count(a))
    answer = []
    for a in ascii_lowercase:
        if 10 ** 9 + 7 > count[a]:
            for _ in range(count[a]):
                answer.append(a)
    answer.sort()
    print("".join(answer))


if __name__ == '__main__':
    main()



Measured memory_bytes: 3768
package main

import (
	"fmt"
	"math"
)

func main() {
	n := scanInt()
	for i := 0; i < n; i++ {
		cal()
	}
}

func scanInt() int {
	var n int
	fmt.Scanf("%d", &n)
	return n
}

func cal() {
	var x1, y1, x2, y2, x3, y3 float64
	fmt.Scanf("%f%f%f%f%f%f", &x1, &y1, &x2, &y2, &x3, &y3)
	a := 2 * (x1 - x2)
	b := 2 * (y1 - y2)
	c := 2 * (x1 - x3)
	d := 2 * (y1 - y3)
	e := x1*x1 - x2*x2 + y1*y1 - y2*y2
	f := x1*x1 - x3*x3 + y1*y1 - y3*y3

	px := (d*e - b*f) / (a*d - b*c)
	py := (a*f - c*e) / (a*d - b*c)

	r := math.Sqrt((x1-px)*(x1-px) + (y1-py)*(y1-py))
	fmt.Printf("%.3f %.3f %.3f\n", px, py, r)
}



Measured memory_bytes: 1124