akhauriyash/Code-Regression huggingface dataset:
void main()
{
    long n = rdElem;
    string[] s = new string[n];
    long[] t = new long[n];
    foreach (i; 0 .. n)
    {
        string[] tmp = rdRow!string;
        s[i] = tmp[0];
        t[i] = tmp[1].to!long;
    }
    string x = rdStr;

    long result = long.min;
    foreach (i; 0 .. n)
    {
        result += t[i];
        if (s[i] == x) result = 0;
    }

    result.writeln;
}

T rdElem(T = long)()
{
    //import std.stdio : readln;
    //import std.string : chomp;
    //import std.conv : to;

    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;

dchar[] rdDchar()
{
    //import std.conv : to;

    return rdStr.to!(dchar[]);
}

T[] rdRow(T = long)()
{
    //import std.stdio : readln;
    //import std.array : split;
    //import std.conv : to;

    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    //import std.range : iota;
    //import std.algorithm : map;
    //import std.array : array;

    return iota(col).map!(x => rdRow!T).array;
}

void wrMat(T = long)(T[][] mat)
{
    //import std.stdio : write, writeln;

    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

int main(){
  std::string s;
  std::cin >> s;
  if(s[0] == s[1] && s[1] == s[2] )
    std::cout << "Yes" << std::endl;
  else if(s[1] == s[2] && s[2] == s[3])
    std::cout << "Yes" << std::endl;
  else
    std::cout << "No" << std::endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
ll a,b,c;

int main() {

  cin >> a >> b >> c;

  if(a == b && b == c && a % 2 == 0) {
    cout <<"-1"<<endl;
    return 0;
  }

  ll ans = 0;

  while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
    ll s = a / 2;
    ll t = b / 2;
    ll r = c / 2;
    a = t + r;
    b = s + r;
    c = s + t;
    ans++;
  }

  cout << ans << endl;
}
  


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

int x,y,n,root[111][111],dame1[111],dame2[111];
int main(){
  while(1){
    cin >> x >> y;
    if(x == 0 && y == 0)break;
    cin >> n;
    for(int i=0;i<n;i++){
      cin >> dame1[i] >> dame2[i];
    }
    root[1][1]=1;
    root[0][0]=0;
    if(x > 0 && y > 0){
      for(int i=1;i<111;i++){
	root[0][i]=0;
	root[i][0]=0;
      }
      for(int j=1;j<111;j++){
	for(int i=1;i<111;i++){
	  if(i==1 && j==1){
	  }
	  else{
	    root[i][j]=root[i-1][j] + root[i][j-1];
	  }
	  for(int k=0;k<n;k++){
	    if(i == dame1[k] && j == dame2[k]){
	      root[i][j] = 0;
	    }
	  }
	}
      }
    }
    cout << root[x][y] << endl;
  }
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
#include<math.h>
#include<iostream>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; i++)
typedef long long ll;
int main(){
   //A
   /*
   int r;cin>>r;
   cout<<2*M_PI*r<<endl;
   */
  //B
  int n,m;
  cin>>n>>m;
  vector<int> a(m);
  int c=0;
  rep(i,0,m){ 
    cin>>a[i];
    c+=a[i];
  }
  if(c<=n) cout<<n-c<<endl;
  else cout<<-1<<endl;
}

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

int main(){
		
	int E, Y, ans;
	
	cin>>E>>Y;	
	if(E == 0){
		if(1868 <= Y && Y <= 1911) cout<<"M"<<Y - 1868 + 1<<endl;
		else if(Y <= 1925) cout<<"T"<<Y - 1912 + 1<<endl;
		else if(Y <= 1988) cout<<"S"<<Y - 1926 + 1<<endl;
		else if(Y <= 2016) cout<<"H"<<Y - 1989 + 1<<endl;
		return 0;
	}
	if(E == 1)ans = 1868 + Y - 1;	
	if(E == 2)ans = 1912 + Y - 1;
	if(E == 3)ans = 1926 + Y - 1;
	if(E == 4)ans = 1989 + Y - 1;
	
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 3100
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <unordered_set>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define fi first
#define se second

#define INF 2147483600

char c1[4010], c2[4010];

int main(){
  scanf("%s %s", c1, c2);
  string s1(c1), s2(c2);
  if(s1.size() > s2.size()) swap(s1,s2);

  for(int l = s1.size(); l>0; l--){
    set<vector<int> > st;
    vector<int> rui(26,0);
    rep(i,l-1) rui[s1[i]-'a']++;
    rep(i, s1.size()-l+1){
      rui[s1[i+l-1]-'a']++;
      vector<int> vec(rui);
      st.insert(vec);
      rui[s1[i]-'a']--;
    }
    rui = vector<int>(26,0);
    rep(i,l-1) rui[s2[i]-'a']++;
    rep(i, s2.size()-l+1){
      rui[s2[i+l-1]-'a']++;
      if(st.find(rui)!=st.end()){
        cout<<l<<endl;
        return 0;
      }
      rui[s2[i]-'a']--;
    }
  }
  cout<<0<<endl;

  return 0;
}

Measured memory_bytes: 3900
use std::io;

fn read_line()-> String {
    let mut s = String::new();
    let _ = io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
	let s = read_line().split_whitespace().map(|e|e.parse().unwrap())
	.collect::<Vec<f32>>();
	let r:f32 = (s[0] + s[1]) / 2 as f32;
	let i = r.round() as i32;
	println!("{}",i);
}


Measured memory_bytes: 4604
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
 
int main () {
    int N, K, ans;
    cin >> N >> K;
    ans = 0;
    for(;;){
      N /= K;
      ++ans;
      if (N <= 0) {
        break;
      }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

string s,t;

int main(void){
	cin >> s;
	cin >> t;
	int cnt=0;
	for(int i=0;i<s.size();i++){
		if(s[i]==t[i]){
			cnt++;
		}
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <stdio.h>

#define MAX_N 50
#define INF 1'000'000'000'000'000'000

typedef long long ll;

using namespace std;

int A[MAX_N];
int B[MAX_N];
int C[MAX_N];
int D[MAX_N];

int main() {
  int N, M;
  cin >> N >> M;
  for (int i = 0; i < N; ++i) {
    cin >> A[i] >> B[i];
  }
  for (int i = 0; i < M; ++i) {
    cin >> C[i] >> D[i];
  }
  for (int i = 0; i < N; ++i) {
    ll d = INF;
    int res = 0;
    for (int j = 0; j < M; ++j) {
      ll _d = (ll)abs(A[i] - C[j]) + (ll)abs(B[i] - D[j]);
      if (_d < d) {
        d = _d;
        res = j + 1;
      }
    }
    printf("%d\n", res);
  }
}

Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N, X, Y;
    cin >> N >> X >> Y;
    X--;
    Y--;

    int d[N][N];
    for(int i=0;i<N;i++)
        for(int j=0;j<N;j++)
            d[i][j] = d[j][i] = 500000;
    for(int i=0;i<N;i++)
        d[i][i] = 0;
    /*
    // 距離1の辺
    for(int i=0;i<N-1;i++){
        d[i][i+1] = 1;
        d[i+1][i] = 1;
    }
    */
   for(int i=0;i<N;i++){
        for(int j=i;j<N;j++){
            // A→B, A→X→Y→B
            d[i][j] = min(abs(j-i), abs(j-Y) + 1 + abs(X-i));
        }
    }
    
    int ans[N] = {};
    for(int i=0;i<N;i++){
        for(int j=i;j<N;j++){
            if(d[i][j] != 500000)
                ans[d[i][j]]++;
        }
    }

    for(int i=1;i<N;i++)
        cout << ans[i] << endl;

}

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

using namespace std;

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define FOR(i,m,n) for(int i=(m) ; i<(n) ; i++)
#define FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)
#define ALL(x) (x).begin(),(x).end()

int GCD(int a,int b){ return b ? GCD(b,a%b) : a ;}
int LCM(int a,int b){ return a*b / GCD(a,b) ;}

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1e9;

int main(){
   ull a,b,x;
   cin >> a >> b >> x;
   if(a == 0)cout << b/x+1 << endl;
   else cout << b/x+1 - ((a-1)/x+1) << endl;
   return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
  ll a;
  cin>>a;
  vector<pair<pair<string,ll>,ll>>vec(a);
  for(ll i=0;i<a;i++){
    cin>>vec.at(i).first.first;
    ll g;
    cin>>g;
    vec.at(i).first.second=100-g;
    vec.at(i).second=i;
  }
  sort(vec.begin(),vec.end());
  
  for(ll i=0;i<a;i++){
    cout<<vec.at(i).second+1<<endl;
  }
  return 0;
}

Measured memory_bytes: 3660
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

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


int main(){
	int r,d,x;

	cin >> r >> d >> x;
	for(int i=0;i<10;i++){
		x = r*x -d;
		cout << x << endl;
	}
	

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  int A, B, C; std::cin >> A >> B >> C;
  fin(std::max(B+C-A, 0));
  return 0;
}


Measured memory_bytes: 256
<?php
  fscanf(STDIN, "%d", $amout);  
  $array = explode(' ', fgets(STDIN));
 
  $nums = array();
  for($i=0 ; $i < $amout; $i++){
    $value = (int)$array[$i];
    $nums[] = $value;
    $nums[] = $value - 1;
    $nums[] = $value + 1;
  }
 
$tmpArray = array_count_values($nums);
 
echo max($tmpArray);

Measured memory_bytes: 31216
#include<stdio.h>
#include<math.h>
#define inf 100000000
int min;
int h, w, len;
int x, y;
int length(int x, int y){
    return x*x + y*y;
}
void judge(void){
    int i, j;
    x=0; y=0; min=inf;
    len=length(h,w);
    for(int i=1;i<151;i++){
        for(int j=i+1;j<151;j++){
            if(len==length(i,j) && i>h){
                printf("%d %d\n",i,j);
                return;
            }
            else if(len < length(i,j) && length(i,j) < min){
                min = length(i,j);
                x=i; y=j;
            }
            else if(min < length(i,j)){
                break;
            }
        }
        if(min < length(i,1)) break;
    }
    printf("%d %d\n",x,y);
}
int main(void){
    while(1){
        scanf("%d%d",&h,&w);
        if(h==0 && w==0) break;
        judge();
    }
    return 0;
}



Measured memory_bytes: 2068
s = input()
cnt = 0
if s[0]!=s[1]:
  if s[0]==s[2] or s[0]==s[3]:
    cnt+=1
  if s[1]==s[2] or s[1]==s[3]:
    cnt+=1
else:
  if s[2]==s[3] and s[0]!=s[2]:
    cnt+=2
    
print('Yes' if cnt==2 else 'No')

Measured memory_bytes: 3060
package main

import (
	"bufio"
	"fmt"
	"os"
	"regexp"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	/*/TODO:!!!!!!!テスト用!!!!!!!!!
	sc = bufio.NewScanner(strings.NewReader(`
				`))
	//TODO:!!!!!!!テスト用!!!!!!!!!*/

	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	//fmt.Fprintln(out, "[DEBUG]", time.Now())

	s := next()

	reg := regexp.MustCompile(`^(dream|dreamer|erase|eraser)*$`)

	if reg.MatchString(s) {
		fmt.Fprintln(out, "YES")
	} else {
		fmt.Fprintln(out, "NO")
	}

	//	fmt.Fprintln(out, "[DEBUG]]", a)
	//fmt.Fprintln(out, ans)
}

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

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<ll,ll> pi;

ll po[25];
pi chk(int l,bool f){
	int t=l/2;
	ll w=(po[l-t]-1)*(po[t]-1);
	if(f)return {-w,w-po[l-1]+po[t-1]};
	return {-w,w};
}
ll solve(int n,int p,ll rem){
	// digits, place, remain
	if(p<=n-p+1){
		if(rem)return 0;
		return po[p==n-p+1];
	}
	ll k=po[p-1]-po[n-p];
	pi s=chk(2*p-n,p==n);
	s.fi*=po[n-p],s.se*=po[n-p];
//	cerr<<n<<' '<<p<<' '<<rem<<' '<<k<<' '<<s.fi<<' '<<s.se<<endl;
	if(rem<s.fi||rem>s.se)return 0;
	ll res=0;
	for(int cur=-9;cur<=9;cur++){
		int cnt=min(cur+9,9)-max(cur,n==p?1:0)+1;
		if(cnt<=0)continue;
		// -cur 
		res+=cnt*solve(n,p-1,rem+k*cur); 
	}
	return res;
}

int D;
ll ans;

int main(){
	po[0]=1;
	for(int i=1;i<=18;i++)po[i]=po[i-1]*10;
	cin>>D;
	for(int i=1;i<=18;i++)ans+=solve(i,i,D);
	cout<<ans;
	return 0;
}

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

#define y1 GKK
#define Set(a, b) memset(a, b, sizeof (a))
#define For(i, j, k) for (register int i = j; i <= k; ++ i)
#define Forr(i, j, k) for (register int i = j; i >= k; -- i)

using namespace std;

template <typename T> inline bool chkmin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template <typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }

inline void File() {
	freopen("h.in", "r", stdin);
	freopen("h.out", "w", stdout);
}

const int N = 40 + 2, inf = 0x3f3f3f3f;
char str[N][N];

int n, m, sx, sy, s[N][N], f[N][N][N][N];

inline int sum(int a, int b, int c, int d) {
	if (a > c || b > d) return 0;
	return s[c][d] - s[a - 1][d] - s[c][b - 1] + s[a - 1][b - 1];
}

int main() {

	cin >> n >> m;
	For(i, 1, n) scanf("%s", str[i] + 1);

	For(i, 1, n) For(j, 1, m) {
		if (str[i][j] == 'P') sx = i, sy = j;
		s[i][j] = s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + (str[i][j] == '#');
	}

	Set(f, inf), f[1][1][n][m] = 0;
	
	int ans = inf;

	For(x1, 1, sx) For(y1, 1, sy) Forr(x2, n, sx) Forr(y2, m, sy) {

		int t = min(min(sum(x1, y1, sx, sy), sum(sx, sy, x2, y2)), min(sum(sx, y1, x2, sy), sum(x1, sy, sx, y2)));
		ans = min(ans, f[x1][y1][x2][y2] + t);

		For(mx, x1, x2) For(my, y1, y2) {
			if (mx >= sx && my >= sy)
				chkmin(f[x1][y1][mx][my], f[x1][y1][x2][y2] + sum(x1, my + 1, mx, y2) + sum(mx + 1, y1, x2, my));

			if (mx >= sx && my <= sy)
				chkmin(f[x1][my][mx][y2], f[x1][y1][x2][y2] + sum(x1, y1, mx, my - 1) + sum(mx + 1, my, x2, y2));

			if (mx <= sx && my <= sy)
				chkmin(f[mx][my][x2][y2], f[x1][y1][x2][y2] + sum(x1, my, mx - 1, y2) + sum(mx, y1, x2, my - 1));

			if (mx <= sx && my >= sy)
				chkmin(f[mx][y1][x2][my], f[x1][y1][x2][y2] + sum(x1, y1, mx - 1, my) + sum(mx, my + 1, x2, y2));
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 12544
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
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; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;


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

    int ans = 0;
    while(n > 0){
        ans++;
        n /= k;
    }

    cout << ans << endl;
}

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

int main(){
        int n;
        int res = 0;
        int tmp,count;
        int ans = 1;
        cin >> n;
        for(int i=1; i<=n; i++) {
                tmp = i;
                count = 0;
                while(tmp % 2 == 0) {
                        tmp /=2;
                        count++;
                }
                if(count > res) {
                        res = count;
                        ans = i;
                }
        }
        cout << ans << endl;
        return 0;
}

Measured memory_bytes: 256
#include<deque>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#include<algorithm>
#include<string>
#include<sstream>
#include<cmath>
#include<cstdio>
using namespace std;
int main(){
  int h,i,j;
  int a[6];
  for(;;){
    h=1;
    for(i=0;i<6;++i){
      scanf("%d",a+i);
      if(a[i])
	h=0;
    }
    if(h)
      break;
    for(i=0;i<3;++i)
      a[i]+=a[i+3];
    int mx=0;
    for(i=0;i<=min(min(min(2,a[0]),a[1]),a[2]);++i){
      int sm=i;
      for(j=0;j<3;++j)
	sm+=(a[j]-i)/3;
      mx=max(mx,sm);
    }
    printf("%d\n",mx);
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<bitset>
#include<algorithm>
#include<functional>
#include<climits>
#include<utility>
#include <iomanip>
#include<map>


using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define REP(i,x) FOR(i,0,x)
#define CLR(a) memset((a), 0 ,sizeof(a))

const ll MOD = 1e+9+7;
const double PI  = acos(-1.0);


int main(){
  int n;
  cin>>n;
  int x[n+2];
  ll tot=0;
  CLR(x);
  REP(i,n){
    cin>>x[i+1];
    tot+=abs(x[i]-x[i+1]);
  }
  tot+=abs(x[n]-x[n+1]);
  REP(i,n){
    cout<<(tot-abs(x[i]-x[i+1])-abs(x[i+1]-x[i+2])+abs(x[i]-x[i+2]))<<"\n";
  }

}


Measured memory_bytes: 1664
#include<stdio.h>
int prime[10010]={0};
int c;
int isPrime(int n);
int main(){
	int i,num,sum=0;
	prime[0]=2;
	prime[1]=3;
	prime[2]=5;
	prime[3]=7;
	c=4;
	for(i=8;c<10001;i++){
		if(isPrime(i)){
			prime[c]=i;
			c++;
		}
	}
	for(;scanf("%d",&num)&&num;sum=0){
		for(i=0;i<num;i++){
			sum+=prime[i];
		}
		printf("%d\n",sum);
	}
	return 0;
}
int isPrime(int n){
	int i;
	for(i=0;i<c && prime[i]<n;i++){
		if(n==prime[i]){
			return 1;
		}
		if(n%prime[i]==0){
			return 0;
		}
	}
	for(i=3;i<n/2;i++){
		if(n%i==0)return 0;
	}
	return 1;
}

Measured memory_bytes: 316
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <type_traits>

using namespace std;
const int MAX_N = 100001;
vector<int> dp(MAX_N, -1);

int rec(int n){
    if(n==0){
        return 0;
    }
    if(dp[n] != -1){
        return dp[n];
    }
    
    int res = n;
    
    for(int pow6 = 1; pow6 <= n; pow6 *= 6){
        res = min(res, rec(n - pow6) + 1);
    }
    for(int pow9 = 1; pow9 <= n; pow9 *= 9){
        res = min(res, rec(n - pow9) + 1);
    }
    dp[n] = res;
    return res;
}
int main(int argc, const char * argv[]) {
    int n;
    cin >> n;
    cout << rec(n) << endl;
    return 0;
}


Measured memory_bytes: 5376
li = []
s = input()
li2 = []
for i in range(4):
  li.append(int(s[i]))
n1 = 4
def func(n, t):
  if n == 1:
    if t == li[0]:
      return True
    else:
      return False
  if func(n-1, t+li[n-1]):
    li2.append('-')
    return True
  elif func(n-1, t-li[n-1]):
    li2.append('+')
    return True
  else:
    return False
if func(n1, 7):
  print("{0}{4}{1}{5}{2}{6}{3}=7".format(li[0], li[1], li[2], li[3], li2[0], li2[1], li2[2]))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vt vector
#define pb push_back
#define pob pop_back
#define vi vt<int>
#define vvi vt<vi>
#define vii vt<ii>
#define vvii vt<vii>
typedef long long ll;
#define For(i,a,b) for(int i = a; i < b; i++)
#define foR(i,a,b) for(int i = a; i <= b; i++)
#define roF(i,a,b) for(int i = a - 1; i >= b; i--)
#define Rof(i,a,b) for(int i = a; i >= b; i--)

signed main (){
	/*
	freopen(".inp","r",stdin);
	freopen(".out","w",stdout);
	*/
	string a;
	cin >> a;
	int n = a.size();
	a += '#';
	int couna = 0, counall = 0;
	For(i,0,n){
		if(a[i] == 'A'){
			couna++;
		}else if(a[i] == 'B' && a[i+1] == 'C'){
			counall += couna;
			i++;
		}else{
			couna = 0;
		}
	}
	cout << counall;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
ll n,place=0;
double t,a,anst=114514;
ll h[1000];
void Main(){    
    cin>>n>>t>>a;
    t-=a;
    For(i,0,n){
        double h;cin>>h;
        h*=0.006;
        if(anst>abs(t-h)) {
            anst=abs(t-h);
            place=i+1;
        }
    }
    cout<<place<<endl;
}
int main(){
    Main();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
long long i,a,N,s,A=INT_MAX,l,r,S[100002];int main(){scanf("%ld%ld",&N,&s);for(;i<N;i++){scanf("%ld",&a);S[i+1]+=S[i]+a;}for(;;){if(S[r]-S[l]>=s){A=std::min(A,r-l);l++;}else r++;if(r>N){if(A==INT_MAX)A=0;printf("%ld\n",A);return 0;}}}

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

int main(void){
	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		int a, b ,c;
		cin >> a >> b >> c;
		if(a*a + b*b == c*c || b*b + c*c == a*a || c*c + a*a == b*b)	cout << "YES" << endl;
		else cout << "NO" << endl;
	}
  return 0;
}

Measured memory_bytes: 1152
a,b,c=map(int,input().split())
d=int(input())
result=[]
for i in range(d+1):
    for j in range(d+1):
        for k in range(d+1):
            if i+j+k>d:
                continue
            n=[(2**i)*a,(2**j)*b,(2**k)*c]
            result.append(n)
for i in range(len(result)):
    m=result[i]
    if m[1]>m[0] and m[2]>m[1]:
        print('Yes')
        exit()
print('No')

Measured memory_bytes: 62036
import static java.lang.Math.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int INF = 1 << 30;
	static long LINF = 1L << 55;
	static int MOD = 1000000007;
	static int[] mh4 = { 0, -1, 1, 0 };
	static int[] mw4 = { -1, 0, 0, 1 };
	static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
	static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };

	static class TaskX {

		public void solve(int testNumber, InputReader in, PrintWriter out) {

			int n = in.nextInt(), k = in.nextInt();
			int[] h = in.nextIntArray(n);
			Arrays.sort(h);

			long ans = LINF;
			for (int i = 0; i + k - 1 < n; i++) {
				ans = min(ans, h[i+k-1] - h[i]);
			}

			out.println(ans);
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public double nextDouble() {
			return Double.parseDouble(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public int[] nextIntArrayDec(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt() - 1;
			}
			return res;
		}

		public int[] nextIntArray1Index(int n) {
			int[] res = new int[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public long[] nextLongArrayDec(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong() - 1;
			}
			return res;
		}

		public long[] nextLongArray1Index(int n) {
			long[] res = new long[n + 1];
			for (int i = 0; i < n; i++) {
				res[i + 1] = nextLong();
			}
			return res;
		}

		public double[] nextDoubleArray(int n) {
			double[] res = new double[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextDouble();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}
	}

}


Measured memory_bytes: 36292
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
#include <stack>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
string s;
int p, q, r;
int pos;
int get_val(int x, int y, char op)
{
    int res;
    if(op == '*') res = min(x, y);
    else res = max(x, y);
    return res;
}
int Solve()
{
    char op = '#';;
    if(s[pos] == '(') 
    {
        pos++;
        int A = Solve();
        char op = s[pos];
        pos++;
        int B = Solve();
        pos++;
        return get_val(A, B, op);
    }
    else if(s[pos] == ')') return 0;
    else if(s[pos] == '-')
    {
        pos++;
        return 2 - Solve();
    }
    else
    {
        int num;
        if(s[pos] == 'P') num = p;
        else if(s[pos] == 'Q') num = q;
        else if(s[pos] == 'R') num = r;
        else num = s[pos] - '0';
        pos++;
        return num;
    }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> s)
    {
        if(s == ".") break;
        int ans = 0;
        for(p = 0; p < 3; p++)
        {
            for(q = 0; q < 3; q++)
            {
                for(r = 0; r < 3; r++) 
                {
                    pos = 0;
                    if(Solve() == 2) ans++;
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}





Measured memory_bytes: 3196
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    N, M, Q = MI()
    targets = [[] for i in range(Q)]
    for i in range(Q):
        target = LI()
        targets[i] = target
    ans = 0
    for i in range(1, 2**(M+N)):
        i_str = format(i, f"0{M+N-1}b")
        A = []
        tmp = 1
        for k in range(len(i_str)):
            if i_str[k] == "1":
                tmp += 1
            else:
                A.append(tmp)
        if len(A) != N:
            continue
        score = 0
        for query in targets:
            a, b, c, d = query
            if A[b-1] - A[a-1] == c:
                score += d
        ans = max(ans, score)

    print(ans)


main()


Measured memory_bytes: 74388
program redistribution
  implicit none
  integer(8), parameter :: modu = 1000000007
  integer :: s
  integer(8) :: m(3, 3) = 0
  read(*,*) s
  if (s < 6) then
    write(*,'(i0)') s / 3
    stop
  end if
  m(1, 1) = 1
  m(2, 1) = 1
  m(3, 2) = 1
  m(1, 3) = 1
  m = modmatpow(m, s - 6)
  write(*,'(i0)') mod(m(1, 1) * 2 + m(1, 2) + m(1, 3), modu)
contains
  function modmatmul(x, y) result(res)
    integer(8), parameter :: modu = 1000000007
    integer(8), intent(in) :: x(3, 3), y(3, 3)
    integer(8) :: tmp, res(3, 3)
    integer :: i, j, k
    do j = 1, 3
      do i = 1, 3
        res(i, j) = 0
      end do
      do k = 1, 3
        tmp = y(k, j)
        do i = 1, 3
          res(i, j) = mod(res(i, j) + x(i, k) * tmp, modu)
        end do
      end do
    end do
  end
  function modmatpow(x, n) result(res)
    integer(8), intent(in) :: x(3, 3)
    integer, intent(in) :: n
    integer(8) :: res(3, 3), tmp(3, 3)
    integer :: m, i
    res = 0
    do i = 1, 3
      res(i, i) = 1
    end do
    tmp = x
    m = n
    do while (m > 0)
      if (btest(m, 0)) res = modmatmul(res, tmp)
      tmp = modmatmul(tmp, tmp)
      m = rshift(m, 1)
    end do
  end
end program redistribution

Measured memory_bytes: 2932
S = input()
K = int(input())
lenS = len(S)
ans = 0
if S.count(S[0]) == lenS:
    ans = (lenS*K)//2
else:
    if S[0] == S[lenS - 1] and lenS > 1:
        if S[0] == S[1]:
            ind = 1
            while(S[ind+1] == S[0]):
                ind += 1
            if ind % 2 == 1:
                S = "*"+S[1:]
                ans += K

        else:
            ans += K-1
            if S[lenS-1] == S[lenS-2]:
                ans += 1
            S = S[:lenS-1]+"*"

    for i in range(lenS - 1):
        if S[i] == S[i + 1]:
            S = S[:i+1] + '*'+S[i+2:]
            ans += K
            # print(S)
            # print(i)
    if S[0] == S[lenS - 1]:
        ans += K-1

print(ans)


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.Math;

public class Main {
    public static void main(String[] args) {
        try {
            BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));
            
            String line;
            
            while((line = stdReader.readLine()) != null) {
                String[] input = line.split(" ", 0);
                int a = Integer.parseInt(input[0]);
                int b = Integer.parseInt(input[2]);
                String mark = input[1];
                
                // mark?????????´?????????
                if(mark.equals("?")) {
                    break;
                }
                
                // ?¶???????
                if(mark.equals("+")) {
                    System.out.println(a + b);
                    continue;
                }
                // ?????????
                if(mark.equals("-")) {
                    System.out.println(a - b);
                    continue;
                }
                // ?????????
                if(mark.equals("*")) {
                    System.out.println(a * b);
                    continue;
                }
                // ?????????
                if(mark.equals("/")) {
                    System.out.println(a / b);
                    continue;
                }
                
            }
            stdReader.close();
        } catch(Exception e) {
            e.getStackTrace();
            System.exit(-1);
        }
    }
}

Measured memory_bytes: 24424
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define db double
#define pb push_back
#define wrln cout<<'\n';
#define pii pair<int,int>
using namespace std;
const int H=1e9+9;
const int N=1e5+100;


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
 /*   freopen("test12.inp","r",stdin);
    freopen("test.out","w",stdout);*/
    int x;
    cin>>x;
    cout<<(x==0);
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>

using namespace std;

int main(){


	int N;

	cin >> N;

	vector<int> A(N,0);
	vector<int> DP(N,0);

	for(int i=0;i<N;i++){
		cin >> A[i];
	}

	DP[0] = 0;
	DP[1] = abs(A[1]-A[0]);

	for(int i=2;i<N;i++){
		DP[i] = min(DP[i-1]+abs(A[i]-A[i-1]),DP[i-2]+abs(A[i]-A[i-2])); 
	}

	cout << DP[N-1] << endl;

	
	return 0;
}

Measured memory_bytes: 3992
#include<stdio.h>
#include<stdlib.h>
#define INFTY 2147483647;
int count=0;
void merge(int *A,int l,int m,int r){
  int *L,*R,i,j,k;
  int n1=m-l;
  int n2=r-m;

  L=(int *)malloc((n1+1)*sizeof(int));
  R=(int *)malloc((n2+1)*sizeof(int));
  for(i=0;i<n1;i++){
    L[i]=A[l+i];
  }
  for(j=0;j<n2;j++){
    R[j]=A[m+j];
  }
  
  L[n1]=R[n2]=INFTY;
  i=j=0;
  for(k=l;k<r;k++){
   
      count++;
    if(L[i]<R[j])
      {A[k]=L[i];i++;}
    else{ A[k]=R[j];j++;}
 
  }
  free(L);free(R);
}
void mergeSort(int *A,int l,int r){
  if(l+1< r){
    int m=(l+r)/2;
    mergeSort(A,l,m); 
    mergeSort(A,m,r);
    merge(A,l,m,r);
  }
  }

int main(){
    int i,j,n,A[500000];
    scanf("%d",&n);
    for(i=0;i<n;i++){
      scanf("%d",&A[i]);
    }
    
    mergeSort(A,0,n);
    for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i !=n-1)printf(" ");
    }
    printf("\n%d\n",count);
    return 0;
  }



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

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

using i64 = int_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;

void solve() {
    i64 n;
    cin >> n;
    map<string, i64> cnt;
    for (i64 i = 0; i < n; i++) {
        string s;
        cin >> s;
        cnt[s]++;
    }

    cout << "AC" << " x " << cnt["AC"] << endl;
    cout << "WA" << " x " << cnt["WA"] << endl;
    cout << "TLE" << " x " << cnt["TLE"] << endl;
    cout << "RE" << " x " << cnt["RE"] << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


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


int main(){
    char c;
    cin>>c;
    vector<char> a={'a','i','u','e','o'};
    bool ok=0;
    rep(i,5){
        if(a[i]==c) ok=1;
    }
    if(ok) cout<<"vowel"<<endl;
    else cout<<"consonant"<<endl;
}

Measured memory_bytes: 3604
A, B, M = map(int, input().split())

aA = [int(n) for n in input().split()]
bB = [int(n) for n in input().split()]

xycM = [tuple(map(int, input().split())) for _ in range(M)]


min_ = min(aA[x - 1] + bB[y - 1] - c for x, y, c in xycM)

print(min(min(aA) + min(bB), min_))



Measured memory_bytes: 29596
s = list(input())
K = int(input())

for i in range(len(s)):
    if s[i] == 'a':
        continue
    n = ord('z') - ord(s[i]) + 1
    if n <= K:
        K -= n
        s[i] = 'a'

K %= 26
s[-1] = chr((ord(s[-1]) - ord('a') + K) % 26 + ord('a'))

print(''.join(s))


Measured memory_bytes: 4152
use std::io;

fn main() {
    let mut line: Vec<String> = vec![];
    loop {
        let mut s = String::new();
        match io::stdin().read_line(&mut s) {
            Ok(0) => break,
            Ok(_) => line.push(s),
            Err(_) => break
        }
    }

    for i in 'a' as u8 .. 'z' as u8 + 1 {
        let a: char = i as char;
        let count = line.iter().flat_map(|x| x.chars()).map(|c| c.to_lowercase().to_string()).filter(|x| x.chars().nth(0).unwrap() == a).count();
        println!("{} : {}", a, count);
    }
}



Measured memory_bytes: 5060
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int N,K;
vector<int>p(1005);

int main(void){
    cin>>N>>K;
    for(int i=0;i<N;i++){
        cin>>p[i];
    }
    sort(p.begin(),p.begin()+N);
    
    int res=0;
    for(int i=0;i<K;i++){
        res+=p[i];
    }
    printf("%d\n",res);
}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (size_t i = 0; i < size_t(n); i++)
#define forn1(i,n) for (size_t i = 1; i <= size_t(n); i++)
#define popcnt __builtin_popcount
#define ffs __builtin_ffs
#define ctz __builtin_ctz
#define clz __builtin_clz
#define all(a) (a).begin(), (a).end()

using namespace std;

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
using pil = pair<int,ll>;
using pll = pair<ll,ll>;
template <typename T> using vec = vector<T>;
using vi = vec<int>;
using vl = vec<ll>;
template <typename T> using que = queue<T>;
template <typename T> using deq = deque<T>;

template <typename T> T id(T b) {return b;};
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}
template <typename S, typename K> bool contains(S s, K k) { return s.find(k) != s.end(); }
void fastio() { ios_base::sync_with_stdio(false); cin.tie(nullptr); }
constexpr ll TEN(int n) { if (n == 0) return 1LL; else return 10LL*TEN(n-1); }

const int MAX_N = 3000, MAX_T = 3000;
int n,t;
pii ab[MAX_N];
int a[MAX_N];
int b[MAX_N];
int dp[MAX_N+1][MAX_T*2+10];

int main()
{
  fastio();

  cin >> n >> t;
  forn(i,n) cin >> ab[i].fst >> ab[i].snd;

  sort (ab,ab+n);

  forn(i,n) {
    a[i] = ab[i].fst;
    b[i] = ab[i].snd;
  }

  forn1(j,2*MAX_T) dp[0][j] = -1;


  for (int i = 0; i < n; i++) {
    forn(j,2*MAX_T+1) dp[i+1][j] = dp[i][j];
    for (int j = 0; j < t; j++) {
      if (dp[i][j] < 0) continue;
      chmax(dp[i+1][j + a[i]], dp[i][j] + b[i]);
    }
  }

  int ans = 0;
  forn(j,2*MAX_T+1) chmax(ans,dp[n][j]);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 70784
#include <iostream>

const int days = 365;
int c[26];
int t[days];
int s[days][26];

int getUndelta(int day)
{
	// 前に何日分あるか
	int cnt1 = 0;
	for (int k = day - 1; k >= 0; --k)
	{
		if (t[k] != t[day])
			cnt1++;
		else break;
	}

	// 後に何日分あるか
	int cnt2 = 0;
	for (int k = day + 1; k < days; ++k)
	{
		if (t[k] != t[day])
			cnt2++;
		else break;
	}

	// 増加量
	int sum = (cnt2 + 1) * (cnt1 + 1);

	// 合計の削減量
	return  s[day][t[day]] + sum * c[t[day]];
}

int getDelta(int day, int target)
{
	// 前に何日分あるか
	int cnt1 = 0;
	for (int k = day - 1; k >= 0; --k)
	{
		if (t[k] != target)
			cnt1++;
		else break;
	}

	// 後に何日分あるか
	int cnt2 = 0;
	for (int k = day + 1; k < days; ++k)
	{
		if (t[k] != target)
			cnt2++;
		else break;
	}

	// 削減出来る量
	int sum = (cnt2 + 1) * (cnt1 + 1);

	// 合計の削減量
	return s[day][target] + sum * c[target];
}

void applo()
{
	for (int i = 0; i < days; ++i)
	{
		// デメリットの計算
		int unDelta = getUndelta(i);

		// メリットの計算
		int maxDelta = 0;
		int maxT = 0;
		for (int f = 0; f < 26; ++f)
		{
			if (f == t[i]) continue;

			// もともとの増える量
			int delta = getDelta(i, f);

			if (maxDelta == 0 || maxDelta < delta)
			{
				maxDelta = delta;
				maxT = f;
			}
		}

		if (maxDelta > unDelta)
		{
			t[i] = maxT;
		}
	}
}

void app2()
{
	for (int day = 0; day < days - 1; ++day)
	{
		int day1 = day;// rand() % days;
		int day2 = day + 1;// rand() % days;
		int bt1 = t[day1];
		int bt2 = t[day2];
		int at1 = t[day1];
		int at2 = t[day2];

		while (day1 == day2)
		{
			day1 = rand() % days;
			day2 = rand() % days;
		}

		int maxDelta = 0;
		for (int target1 = 0; target1 < 26; ++target1)
		{
			for (int target2 = 0; target2 < 26; ++target2)
			{
				t[day1] = bt1;
				int delta = -getUndelta(day1) + getDelta(day1, target1);
				t[day1] = target1;
				delta += -getUndelta(day2) + getDelta(day2, target2);

				if (maxDelta < delta)
				{
					maxDelta = delta;
					at1 = target1;
					at2 = target2;
				}
			}
		}
		t[day1] = at1;
		t[day2] = at2;
	}
}

int main()
{
	int d;
	std::cin >> d;


	for (int i = 0; i < 26; ++i)
		std::cin >> c[i];

	for (int i = 0; i < days; ++i)
		for (int j = 0; j < 26; ++j)
			std::cin >> s[i][j];

	for (int i = 0; i < days; ++i)
	{
		std::cin >> t[i];
		t[i]--;
	}

	// 満足度の計算
	//int score = 0;
	for (int i = 0; i < days; ++i)
	{
		int maxDelta = 0;

		for (int f = 0; f < 26; ++f)
		{
			int delta = s[i][f];
			//score += s[i][t[i]];

			for (int j = 0; j < 26; ++j)
			{
				for (int k = i; k >= 0; --k)
				{
					if (t[k] != j)
						delta -= c[j];
				}
			}

			if (maxDelta == 0 || maxDelta < delta)
			{
				maxDelta = delta;
				t[i] = f;
			}
		}
	}

	// 初期最適化
	for (int se = 0; se < 10; ++se)
		app2();


	for (int i = 0; i < days; ++i)
		std::cout << t[i] + 1 << std::endl;
}

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

#define ll long long
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);

void solve()
{
	ll n;
	cin>>n;
	ll ac=0,tle=0,wa=0,re=0;
	for(ll i=0;i<n;i++)
	{
		string s;
		cin>>s;
		if(s=="AC") ac++;
		else if(s=="TLE") tle++;
		else if(s=="WA") wa++;
		else if(s=="RE") re++;	
	}	
	cout<<"AC x "<<ac<<endl;
	cout<<"WA x "<<wa<<endl;
	cout<<"TLE x "<<tle<<endl;
	cout<<"RE x "<<re<<endl;
}

int main()
{
	FAST
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++) solve();
	return 0;
}

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

typedef long long ll;

#define rep(i, a, n) for (ll i = a; i < (ll)n; ++i)
#define INF 10e12
#define MOD 1000000007
#define MAX 1001000
#define all(x) (x).begin(), (x).end()
#define max(x) *max_element(all(x))
#define min(x) *min_element(all(x))

using namespace std;

ll modinv(ll a, ll m) //法mにおける，aの逆元を求める
{
    ll b = m, u = 1, v = 0;
    while (b)
    {
        ll t = a / b;
        a -= t * b, swap(a, b);
        u -= t * v, swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}

ll modpow(ll a, ll n, ll m) //a^n(mod m)を求める
{
    ll res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % m;
        a = a * a % m;
        n >>= 1;
    }
    return res;
}

ll fac[MAX], finv[MAX], inv[MAX];

//二項係数の計算
void comint()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; ++i)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll com(ll n, ll k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void)
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll x, y;
    cin >> x >> y;
    if ((x + y) % 3 != 0)
        cout << 0 << endl;
    else
    {
        ll n = (-x + 2 * y) / 3;
        ll m = (2 * x - y) / 3;
        if (n < 0 || m < 0)
            cout << 0 << endl;
        else
        {
            comint();
            cout << com(n + m, n) << endl;
        }
    }
}

Measured memory_bytes: 27056
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int solve(vector<pair<int, int>> &foods, int t, vector<vector<int>> &memo,
          int offset = 0) {
  if (t <= 0 || offset == foods.size()) {
    return 0;
  }

  if (memo[t][offset] < 0) {
    auto &f = foods[offset];
    memo[t][offset] =
        max(solve(foods, t, memo, offset + 1),
            solve(foods, t - f.first, memo, offset + 1) + f.second);
  }

  return memo[t][offset];
}

int main(int argc, const char *argv[]) {
  int n, t;
  cin >> n >> t;

  vector<pair<int, int>> foods(n);
  for (auto &f : foods) {
    cin >> f.first >> f.second;
  }

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

  vector<vector<int>> memo(t + 1, vector<int>(n + 1, -1));
  cout << solve(foods, t, memo) << '\n';
  return 0;
}

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

using ll = long long;

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

template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

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

    int N, K; cin >> N >> K;
    vector<int> A(N); cin >> A;

    vector<ll> sum;
    ll all_or = 0;
    rep(i, N) {
        ll s = 0;
        for (int j = i; j < N; j++) {
            s += A[j];
            sum.push_back(s);
            all_or |= s;
        }
    }

    vector<int> idx;
    rep(i, sum.size()) idx.push_back(i);

    ll ans = 0;
    for (ll b = (1LL << 41); b > 0; b >>= 1) {
        if (!(all_or & b)) continue;
        vector<int> on;
        for (int i : idx) {
            if (sum[i] & b) {
                on.push_back(i);
            }
        }
        if (on.size() >= K) {
            ans |= b;
            idx = on;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 8172
class UnionFind
    attr_reader :set_size, :rank
    def initialize(n)
        @par = Array.new(n)
        n.times{ |i| @par[i] = i }
        @rank = Array.new(n, 0)
        @set_size = Array.new(n, 1)
        @diff_weight = Array.new(n, 0)
    end

    def find(x)
        if @par[x] == x
            x
        else
            r = find(@par[x])
            @diff_weight[x] += @diff_weight[@par[x]]
            @par[x] = r
        end
    end

    def unite(x, y, w)
        w += weight(x)
        w -= weight(y)
        x = find(x)
        y = find(y)
        return if x == y

        if @rank[x] < @rank[y]
            @par[x] = y
            @set_size[y] += @set_size[x]
            @diff_weight[x] = -w;
        else
            @par[y] = x
            @set_size[x] += @set_size[y]
            @diff_weight[y] = w;
            @rank[x] += 1 if @rank[x] == @rank[y]
        end
    end

    def weight(x)
        find(x)
        @diff_weight[x]
    end

    def diff(x, y)
        weight(y) - weight(x)
    end

    def same?(x, y)
        find(x) == find(y)
    end
end


N = gets.to_i
edges = []
(N-1).times do |i|
    a, b, c = gets.split.map(&:to_i)
    edges.push([a-1, b-1, c])
end
edges.sort_by!{|arr| -arr[2]}

uf = UnionFind.new(N)
sum = Array.new(N, 0)

edges.each do |a, b, c|
    next if uf.same?(a, b)
    ap = uf.find(a)
    bp = uf.find(b)
    sum[ap] += uf.set_size[bp] * c
    sum[bp] += uf.set_size[ap] * c
    uf.unite(ap, bp, sum[bp] - sum[ap])
end

base = sum[uf.find(0)]

N.times do |i|
    puts uf.weight(i) + base
end

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

Measured memory_bytes: 1032
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

using i8 = ::std::int_least8_t;
using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u8 = ::std::uint_least8_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;
using isize = ::std::ptrdiff_t;
using usize = ::std::size_t;

template <class T = usize> class rep {
	const T f, l;

public:
	class itr {
		friend rep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { ++i; }
		constexpr T operator*() const noexcept { return i; }
		constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr rep(const T first, const T last) noexcept : f(first), l(last) {}
	constexpr itr begin() const noexcept { return itr(f); }
	constexpr itr end() const noexcept { return itr(l); }
};
template <class T = usize> class revrep {
	const T f, l;

public:
	class itr {
		friend revrep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { --i; }
		constexpr T operator*() const noexcept { return i; }
		constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr revrep(const T first, const T last) noexcept : f(first), l(last) {}
	constexpr itr begin() const noexcept { return itr(l - 1); }
	constexpr itr end() const noexcept { return itr(f - 1); }
};
template <class T> bool amax(T &a, const T &b) {
	return a <= b ? (a = b, 1) : 0;
}
template <class T> bool amin(T &a, const T &b) {
	return b <= a ? (a = b, 1) : 0;
}
template <class T> bool asmax(T &a, const T &b) {
	return b <= a ? 0 : (a = b, 1);
}
template <class T> bool asmin(T &a, const T &b) {
	return a <= b ? 0 : (a = b, 1);
}
template <class T> using vec_alias = ::std::vector<T>;
template <class T> auto md_vec(usize n, const T &value) {
	return ::std::vector<T>(n, value);
}
template <class... Args> auto md_vec(usize n, Args... args) {
	return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> const T &as_const(const T &v) noexcept { return v; }
template <class T> constexpr T difference(const T &a, const T &b) {
	return a <= b ? b - a : a - b;
}

#include <algorithm>
#include <iostream>
#include <utility>

int main() {
	usize n;
	::std::cin >> n;
	::std::vector<u64> a(n);
	for (auto &e : a) {
		::std::cin >> e;
	}
	auto dp = md_vec(n, n + 1, ::std::numeric_limits<u64>::max());
	for (const auto i : rep<>(0, n)) {
		dp[i][i + 1] = 0;
	}
	for (const auto w : rep<>(2, n+1)) {
		for (const auto l : rep<>(0, n+1-w)) {
			for (const auto m : rep<>(1, w)) {
				asmin(dp[l][l + w], dp[l][l + m] + dp[l + m][l + w]);
			}
			for (const auto i : rep<>(l, l + w)) {
				dp[l][l + w] += a[i];
			}
		}
	}
	::std::cout << dp[0][n] << ::std::endl;
	return 0;
}


Measured memory_bytes: 1536