akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <iomanip>      // std::setprecision
using namespace std;

int main(){
    int n;
    long long a, min_w, x1,y1,r1,x2,y2,r2,i,s1,s2,s3,s4;
    cin >> s1 >> s2 >> s3 >> s4;
    cin >> n;
    long long point[n+2][3];
    //cin >> point[0][0] >> point[0][1] >> point[n+1][0] >> point[n+1][1];
    point[0][0] = s1; point[0][1] = s2; point[n+1][0] = s3; point[n+1][1] = s4;
    point[0][2] = 0; point[n+1][2] = 0;
    for(i = 1; i< n+1; i++){
        cin >> point[i][0] >> point[i][1] >> point[i][2];
    }
    int chos;
    a = 0;
    int use[n+2];
    double weigth[n+2], dist;
    weigth[0] = 0;
    for(i = 1; i < n+2; i++) weigth[i] = pow(10,10);
    for(i = 1; i < n+2; i++) use[i] = 1;
    while (a != n+1){
        use[a] = 0;
        //cout << "a" << a << endl;
        chos = a;
        min_w = pow(10,10);
        x1 = point[chos][0];y1 = point[chos][1];r1 = point[chos][2];
        for (i = 0; i < n+2;i++){
            if (use[i] == 0) continue;
            x2 = point[i][0]; y2 = point[i][1]; r2 = point[i][2];
            dist = sqrt(pow((x1-x2),2)+pow((y1-y2),2)) - (r1 + r2);
            if (dist < 0) dist = 0;
            if(dist + weigth[chos] < weigth[i]) weigth[i] = dist + weigth[chos];
            if(weigth[i] <= min_w){
                a = i;
                min_w = weigth[i];
            }
        }
    }
    cout << setprecision(11) << weigth[n+1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#define NMAX 105
#define WMAX 10005
#define DIAGONAL 1
#define TOP 0

using namespace std;

struct Item{ // items[i].value???items[i].weight???i??????????????????????????¨??????????¨???????????????????1?¬??????????
	int value, weight;
};

int N, W;
Item items[NMAX + 1];
int C[NMAX + 1][WMAX + 1], G[NMAX + 1][WMAX + 1]; // i???????????§??????????????????????????§??????w??????????????¶???????????\????????´???????????????????¨?????????§??????C[i][w]??¨??????2?¬??????????

void compute(int &maxValue, vector<int> &selection){
	for(int w = 0; w <= W; w++){
		C[0][w] = 0;
		G[0][w] = DIAGONAL;
	}

	for(int i = 1; i <= N; i++) C[i][0] = 0;

	for(int i = 1; i <= N; i++){
		for(int w = 1; w <= W; w++){
			C[i][w] = C[i - 1][w];
			G[i][w] = TOP;
			if(items[i].weight > w) continue;
			if(items[i].value + C[i - 1][w - items[i].weight] > C[i - 1][w]){
				C[i][w] = items[i].value + C[i - 1][w - items[i].weight];
				G[i][w] = DIAGONAL;
			}
		}
	}

	maxValue = C[N][W];
	selection.clear();
	for(int i = N, w = W; i >= 1; i--){
		if(G[i][w] == DIAGONAL){
			selection.push_back(i);
			w -= items[i].weight;
		}
	}

	reverse(selection.begin(), selection.end());
}

void input(){
	cin >> N >> W;
	for(int i = 1; i <= N; i++){
		cin >> items[i].value >> items[i].weight;
	}
}

int main(){
	int maxValue;
	vector<int> selection;
	input();
	compute(maxValue, selection);

	cout << maxValue << endl;

	return 0;
}

Measured memory_bytes: 10976
def is_prime?(x)
  if x <= 1
    return false
  end
  i = 2
  while i * i <= x do
    if x % i == 0
      return false
    end
    i += 1
  end
  true
end

x = gets.to_i

p = x
while !is_prime? p
  p = p+1
end
p p


Measured memory_bytes: 1788
#include <stdio.h>

int num[9][9];
int flag[9][9];

void check_box(int y, int x)
{
    int i, j;
    int cnt[10] = {0};

    for (i = y; i < y + 3; i++){
        for (j = x; j < x + 3; j++){
            cnt[num[i][j]]++;
        }
    }
    for (i = y; i < y + 3; i++){
        for (j = x; j < x + 3; j++){
            if (cnt[num[i][j]] != 1){
                flag[i][j] = 1;
            }
        }
    }
}

int main(void)
{
    int n;

    scanf("%d", &n);
    while (n-- > 0){
        int i, j;

        for (i = 0; i < 9; i++){
            for (j = 0; j < 9; j++){
                flag[i][j] = 0;
            }
        }

        for (i = 0; i < 9; i++){
            int cnt[10] = {0};
            for (j = 0; j < 9; j++){
                scanf("%d", num[i] + j);
                cnt[num[i][j]]++;
            }
            for (j = 0; j < 9; j++){
                if (cnt[num[i][j]] != 1){
                    flag[i][j] = 1;
                }
            }
        }

        for (j = 0; j < 9; j++){
            int cnt[10] = {0};
            for (i = 0; i < 9; i++){
                cnt[num[i][j]]++;
            }
            for (i = 0; i < 9; i++){
                if (cnt[num[i][j]] != 1){
                    flag[i][j] = 1;
                }
            }
        }

        for (i = 0; i < 3; i++){
            for (j = 0; j < 3; j++){
                check_box(i * 3, j * 3);
            }
        }

        for (i = 0; i < 9; i++){
            for (j = 0; j < 9; j++){
                printf("%c%d", flag[i][j] ? '*' : ' ', num[i][j]);
            }
            puts("");
        }
        if (n > 0) puts("");
    }

    return (0);
}

Measured memory_bytes: 608
#include<algorithm> // sort,reverse,min,lower_bound
#include<vector>
#include<iostream>
using namespace std;
#define df 0
#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
typedef long int li;

void print(vector<int> p){
  for(int x: p) printf("%d ",x);
  printf("\n");
}

int main(){
  if(df) printf("*debug mode*\n");
  int n; cin >>n;
  vector<int> p(n),q(n);
  for(int& x: p) cin >>x;
  for(int& x: q) cin >>x;
  int a,b;
  vector<int> v(n);
  rep(i,n) v.at(i)=i+1;
  int i=0;
  do{
    if(df)print(v);
    if(p==v) a=i;
    if(q==v) b=i;
    i++;
  }while(next_permutation(v.begin(),v.end()));
  cout << (int)abs(a-b);
}

/// confirm df==0 ///


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String[] line = scanner.nextLine().split("/", 3);
        int year = Integer.parseInt(line[0]);
        int month = Integer.parseInt(line[1]);
        int day = Integer.parseInt(line[2]);
        if (year <= 2019 && (month <= 3 || (month == 4 && day <= 30))) {
            System.out.println("Heisei");
        } else {
            System.out.println("TBD");
        }
    }
}


Measured memory_bytes: 21716
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){
    
    ll ans = 4;
    string s;
    cin >> s;
    for(ll i = 0; i < 4; i++)if(s[i] == '-')ans -= 2;
    cout << ans << endl;

    return 0;
}


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

#define N_MAX 50
#define INF 1145141919
#define SMAP(a, b) ((a)!=(b))&&((a)^=((b)^=((a)^= (b))))

int i, j;

int n, m;
int q;

bool max[N_MAX * N_MAX];
bool d[N_MAX][N_MAX];

void solve(){
	return;
}

int main (void) {
	char c[101];
	scanf("%*s %s %*s", c);
	c[1] = c[0];
	c[0] = 'A';
	c[2] = 'C';
	c[3] = 0;
	puts(c);
	return 0;
}




Measured memory_bytes: 128
#include <array>
#include <iostream>
#include <vector>

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

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

  std::vector<std::array<int, 3>> a(N);
  for (int i = 0; i < N; ++i)
    for (int j = 0; j < 3; ++j)
      std::cin >> a[i][j];

  std::vector<std::array<int, 3>> dp(N + 7, {-1, -1, -1});
  // dp[i][j] = i 日目が j (=A, B, C) であるときの幸福度の最大値

  for (int j = 0; j < 3; ++j)
    dp[0][j] = a[0][j];

  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < 3; ++j) {
      chmax(dp[i + 1][(j + 1) % 3], dp[i][j] + a[i + 1][(j + 1) % 3]);
      chmax(dp[i + 1][(j + 2) % 3], dp[i][j] + a[i + 1][(j + 2) % 3]);
    }
  }

  int res = -1;
  for (int j = 0; j < 3; ++j)
    chmax(res, dp[N - 1][j]);
  std::cout << res << std::endl;
}


Measured memory_bytes: 2560
#include <stdio.h>
#include <stdlib.h>
 
int left(int i){
  return 2*i;
}
 
int right(int i){
  return 2*i+1;
}
 
void maxHeapify(int *A,int i,int n){
  int l=left(i), r=right(i), largest, tmp;
 
  if(l<=n && A[l]>A[i]) largest=l;

  else largest=i;
 
  if(r<=n && A[r]>A[largest])largest=r;
 
  if(largest!=i){
	tmp=A[i];
	A[i]=A[largest];
	A[largest]=tmp;
	
    maxHeapify(A,largest,n);
  }
}
 
void buildMaxHeap(int *A,int n){
  int i;
  for(i=n;i>=1;i--) maxHeapify(A,i,n);
}
     
main(){
  int n,i;
  int *A;
 
  scanf("%d",&n);
 
  A=(int *)malloc((n+1)*sizeof(int));
 
  for(i=1;i<=n;i++) scanf("%d",&A[i]);
 
  buildMaxHeap(A,n);
 
  for(i=1;i<=n;i++) printf(" %d",A[i]);
  printf("\n");
 
  return 0;
}

Measured memory_bytes: 2556
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
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 = 1e18;

vector<ll> divisor(ll n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}

int main(){
    ll n;
    cin >> n;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    sort(a.begin(),a.end());
    vector<vector<ll> >div(n);
    rep(i,n)div[i]=divisor(a[i]);
    set<ll>st;
    set<ll>x;
    rep(i,n-1){
        if(a[i]==a[i+1]){
            x.insert(a[i]);
        }
    }
    ll ans = 0;
    rep(i,n){
        bool flag = true;
        if(!st.empty()){
            for(auto j:div[i]){
                if(st.count(j)!=0){
                    flag = false;
                }
            }
        }

        if(flag&&x.count(a[i])==0)ans++;
        st.insert(a[i]);
    }
    
    cout << ans << endl;
    return 0;
}


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

int main(){
    int di[6]= {};
    int i,j,l;
    string dt;
    char dr;
    for(i=0;i<6;i++){
        cin>>di[i];
    }
    cin>>dt;
    l=dt.length();
    for(i=0;i<l;i++){
        dr=dt[i];
        if(dr == 'N'){
            j=di[0];
            di[0]=di[1];
            di[1]=di[5];
            di[5]=di[4];
            di[4]=j;
        }else if(dr == 'S'){
            j=di[0];
            di[0]=di[4];
            di[4]=di[5];
            di[5]=di[1];
            di[1]=j;
        }else if(dr == 'E'){
            j=di[0];
            di[0]=di[3];
            di[3]=di[5];
            di[5]=di[2];
            di[2]=j;
        }else{
            j=di[0];
            di[0]=di[2];
            di[2]=di[5];
            di[5]=di[3];
            di[3]=j;
        }
        
    }
    cout<<di[0]<<endl;
}


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

int main(){
    int N;
    cin >> N;
    int ans = 1;
    int ansc = 0;

    for(int i = 1; i <= N; ++i){
        int count = 0;
        int a = i;
        while(a % 2 == 0){
            a = a / 2;
            ++count;
        }
        if(count > ansc){
            ans = i;
            ansc = count;
        }
    }

    cout << ans << endl;
}

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

int main() {
  int n;cin>>n;
  vector<vector<int>> vec(n,vector<int>(n,-1));
  rep(i,n){
    int a;cin>>a;
    rep(j,a){
      int x,y;cin>>x>>y;
      x--;
      vec[i][x]=y;//i番目の人がx番目の人が正直者か不親切な人か言った
    }
  }
  int ans=0;
  rep(bit,1<<n){
    vector<int> d(n);
    //1~n番目の人が正直者か不親切な人かbit全探索
    rep(j,n)if(bit&(1<<j))d[j]=1;//j番目の人が正直者なら1
    bool ok=true;
    rep(i,n)if(d[i]){
      //i番目の人が正直者
      rep(j,n){
        if(vec[i][j]==-1)continue;//相手の証言なし
        if(vec[i][j]!=d[j])ok=false;//正直なi番目の人がj番目の人に対して正直者か不親切な人かを言って、その結果が矛盾している
      }
    }
    if(ok)ans=max(ans,__builtin_popcount(bit));//bitの1の個数、すなわち正直者の人数
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3640
#include <iostream>

int main(){
    int a, b;
    std::cin >> a >> b;
    if(a < b) std::cout << "a < b" << std::endl;
    else if (a > b) std::cout << "a > b" << std::endl;
    else std::cout << "a == b" << std::endl;
    return 0;
}

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

int main(){
    int n;cin >> n;
    int l[n];
    int sum;

    for(int i=0;i<n;i++){
        cin >> l[i];
        sum += l[i];
    }

    sort(l, l + n);
    sum -= l[n-1];

    if (sum > l[n-1]) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int m=0,n,aa[220000],a,b,cnt=0,k;
pair<int,int> p[220000];
string s,ss[110000];
char c;
signed main(){
    cin>>k>>n;
    rep(i,n){
        cin>>aa[i];
    }
    rep(i,n-1){
        cnt=max(cnt,aa[i+1]-aa[i]);
    }
    cnt=max(cnt,k-aa[n-1]+aa[0]);
    cout<<k-cnt;
}

Measured memory_bytes: 2688
//ヘッダファイル
#include<stdio.h>

//マクロ定義
#define MAX 10000
#define FALSE 1
#define compile 1

//関数のプロトタイプ宣言
void func_init(int array[], int n);

main()
{
	int dead_end[MAX];
	int exit[MAX];
	func_init(dead_end, MAX);
	func_init(exit, MAX);
	int input = 0, i = 0, j = 0, k = 0, flag = 0;
	while(scanf("%d", &input) != EOF)
	{
		if(input != 0)
		{
			dead_end[i] = input; //現在のiを要素番号としてinputを入力
			i++;
		}
		else if(input == 0)
		{
			exit[j] = dead_end[--i];
			dead_end[i] = 0;
			j++;
		}
	}
	
	for(i = 0; exit[i] != 0; i++)
	{
		printf("%d\n", exit[i]);
	}
	return 0;
}
void func_init(int array[], int n)
{
	int i = 0;
	for(i = 0; i < n; i++)
	{
		array[i] = 0;
	}
}

Measured memory_bytes: 676
#include <iostream>
#include <stdio.h>
#include <memory.h>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <algorithm>
#include <bitset>
#define MOD 1000000007

using ii = std::pair<int, int>;

long long int facto[200001];

//(x^m) % p
long long int mul(long long int x, long long int m, long long int p)
{
	long long int ans = 1;

	while (m > 0)
	{
		if (m % 2 != 0)
		{
			ans *= x;
			ans %= p;
		}

		x *= x;
		x %= p;
		m /= 2;
	}
	return ans;
}

//(w+h)!/(w!*h!) % mod
long long int count(long long int w, long long int h)
{
	long long int up = facto[w + h - 2];
	long long int down = (facto[w - 1] * facto[h - 1]) % MOD;

	return (up * mul(down, MOD - 2, MOD)) % MOD;
}

int main()
{
	int h, w, a, b;
	scanf("%d %d %d %d", &h, &w, &a, &b);

	facto[0] = 1;

	for (int i = 1; i <= h + w; i++)
		facto[i] = (facto[i - 1] * i) % MOD;

	long long int total = 0;

	for (int k = 1; k <= h-a; k++)
	{
		long long int f = (count(b, k) * count(w - b, h - k + 1) % MOD);
		total = (total + f) % MOD;
	}

	printf("%lld", total);

	return 0;
}

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

int main() {
	string s;
	cin >> s;
	bool check1 = true, check2 = true;
	bool N = true, S = true, W = true, E = true;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'N' && N) check1 = !check1, N = false;
		if (s[i] == 'S' && S) check1 = !check1, S = false;
		if (s[i] == 'W' && W) check2 = !check2, W = false;
		if (s[i] == 'E' && E) check2 = !check2, E = false;
	}
	if (check1 && check2) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);

	String c = scan.next();

	if(c.charAt(0) == 'a' ||
	   c.charAt(0) == 'i' ||
	   c.charAt(0) == 'u' ||
	   c.charAt(0) == 'e' ||
	   c.charAt(0) == 'o'){
	    System.out.println("vowel");
	}else{
	    System.out.println("consonant");
	}
    }
}


Measured memory_bytes: 23124
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
//max_element

int N;
vector<int> A;
priority_queue<int> q;

signed main()
{
	cin >> N;
	REP(i, N)
	{
		int a;
		cin >> a;
		A.push_back(a);
	}
	RSORT(A);

	int ans = 0;
	q.push(A[0]);
	for (int i = 1; i < N; i++)
	{
		int t = q.top();
		q.pop();
		ans += t;
		q.push(A[i]);
		q.push(A[i]);
	}
	cout << ans << endl;
}



Measured memory_bytes: 7516
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;

#define int int64_t

#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,x,...) x
#define REP1(i, s, cond, cal) for (signed i = signed(s); i cond; i cal)
#define REP2(i, s, n) REP1(i, s, < signed(n), ++)
#define REP3(i, n) REP2(i, 0, n)
#define rep(...) CHOOSE((__VA_ARGS__,REP1,REP2,REP3))(__VA_ARGS__)
#define rrep(i, s) rep(i, s, >= 0, --)

#define all(c) begin(c), end(c)
#define maxup(ans, x) (ans = (ans < x ? x : ans))
#define minup(ans, x) (ans = (ans > x ? x : ans))

#define breakif(cond) if(cond) break; else

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }

const int INF = 1ll << 60;

int A[100000];
int D[100000];
int stops[100000];

signed main() {
	int N, T, Q;
	cin >> N >> T >> Q;
	rep(i, N) cin >> A[i] >> D[i];

	rep(i, N) {
		stops[i] = (D[i] == 1 ? 1 : -1) * (1ll << 60);
	}

	rep(i, 1, N) if (D[i - 1] == 1 && D[i] == 2) {
		int s = stops[i] = stops[i - 1] = (A[i] + A[i - 1]) / 2;
		for (int j = i - 1; j >= 0 && D[j] == 1; j--) {
			stops[j] = s;
		}
		while (i + 1 < N && D[i + 1] == 2) {
			stops[i + 1] = s;
			i++;
		}
	}

	rep(i, Q) {
		int x;
		cin >> x;
		x--;
		int ans;
		if (D[x] == 1) ans = min(A[x] + T, stops[x]);
		else ans = max(A[x] - T, stops[x]);
		cout << ans << endl;
	}
	//system("pause");
}

Measured memory_bytes: 5380
using System;

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var w = int.Parse(line[0]);
            var h = int.Parse(line[1]);
            if (w == 0 && h == 0) break;
            var map = new int[h, w];
            for (int i = 0; i < h; i++)
            {
                string[] line2 = Console.ReadLine().Trim().Split(' ');
                for (int j = 0; j < w; j++) map[i, j] = int.Parse(line2[j]);
            }
            var dp = new int[h, w];
            goDP(map, dp);
            var ans = 0;
            for (int i = 0; i < w; i++)
            {
                ans += dp[h - 1, i];
                if (h-2 >= 0  && map[h - 2, i] == 2) ans += dp[h - 2, i];
            }
            Console.WriteLine(ans);
        }
    }
    public static void goDP(int[,] map, int[,] dp)
    {
        var h = dp.GetLength(0); var w = dp.GetLength(1);
        for (int i = 0; i < w; i++)
            if (map[0, i] == 0) dp[0, i] = 1;
        for (int i = 1; i < h; i++)
            for (int j = 0; j < w; j++)
                switch (map[i, j])
                {
                    case 0:
                        if (i - 2 >= 0 && map[i - 2, j] == 2) dp[i, j] += dp[i - 2, j];
                        if (map[i - 1, j] == 0) dp[i, j] += dp[i - 1, j];
                        if (j - 1 >= 0 && map[i - 1, j - 1] == 0) dp[i, j] += dp[i - 1, j - 1];
                        if (j + 1 <= w - 1 && map[i - 1, j + 1] == 0) dp[i, j] += dp[i - 1, j + 1];
                        break;
                    case 2:
                        if (map[i - 1, j] == 0) dp[i, j] = dp[i - 1, j];
                        if (i - 2 >= 0 && map[i - 2, j] == 2) dp[i, j] += dp[i - 2, j];
                        break;
                    default:
                        break;
                }
    }
}

Measured memory_bytes: 9256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		long[] cnt = new long[K];
		for(int i=1;i<=N;i++) cnt[i % K]++;
		
		long ans = 0;
		for(int i=0;i<K;i++){
			int j = (K - i) % K;
			if((j + j) % K == 0){
				ans += cnt[i] * cnt[j] * cnt[j];
			}
			
		}
		
		Console.WriteLine(ans);
		
	}
	int N,K;
	public Sol(){
		var d = ria();
		N = d[0]; K = d[1];
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


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

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

    s[k-1] = s[k-1] - 'A' + 'a';
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3572
#include<cstdio>
#define MAX 10000
#define NIL -1

struct Node { int parent, left, right; };

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d)
{
  if (u == NIL ) return;
  D[u]=d;
  setDepth(T[u].left, d + 1);
  setDepth(T[u].right, d + 1);
}

int setHeight(int u)
{
  int h1 = 0, h2 = 0;
  if ( T[u].left != NIL )h1 = setHeight(T[u].left) + 1;
  if ( T[u].right != NIL )h2 = setHeight(T[u].right) + 1;
  return H[u] = ( h1 > h2 ? h1:h2 );
}
//節点uの兄弟を返す

int getSibling(int u)
{
  if ( T[u].parent == NIL ) return NIL;
  if ( T[T[u].parent].left != u && T[T[u].parent].left != NIL )return T[T[u].parent].left;
  if ( T[T[u].parent].right !=u && T[T[u].parent].right != NIL )return T[T[u].parent].right;
  return NIL;
}

  void print(int u)
  {
    printf("node %d: ", u);
    printf("parent = %d, ", T[u].parent);
    printf("sibling = %d, ", getSibling(u));
    int deg = 0;
    if ( T[u].left != NIL ) deg++;
    if ( T[u].right != NIL ) deg++;
    printf("degree = %d, ",deg);
    printf("depth = %d, ", D[u]);
    printf("height = %d, ", H[u]);

    if ( T[u].parent == NIL )
    {
      printf("root\n");
    }
    else if ( T[u].left == NIL && T[u].right == NIL )
    {
      printf("leaf\n");
    }
    else
    {
      printf("internal node\n");
    }
  }

  int main()
  {
    int v, l, r, root = 0;
    scanf( "%d", &n);
    for ( int i = 0; i < n; i++ ) T[i].parent = NIL;
    for ( int i = 0; i < n; i++ )
    {
      scanf("%d %d %d", &v, &l, &r);
      T[v].left = l;
      T[v].right = r;
      if (l != NIL ) T[l].parent = v;
      if (r != NIL ) T[r].parent = v;
    }
    for ( int i = 0; i < n; i++ ) if ( T[i].parent == NIL ) root = i;
    setDepth(root, 0);
    setHeight(root);
    for ( int i = 0; i < n; i++ ) print(i);
    return 0;
  }



Measured memory_bytes: 2744
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public long knapsack(int[] weights, int[] val, int n, int desired) {
        long[][] dp = new long[n+1][desired+1];
        for(int i=1;i<n+1;++i) {
            for(int j=1;j<desired+1;++j) {
                dp[i][j]=Math.max(dp[i][j],dp[i-1][j]);
                if(j>=weights[i-1]) {
                    dp[i][j]=Math.max(dp[i][j],val[i-1]+dp[i-1][j-weights[i-1]]);
                }
            }
        }
        return dp[n][desired];
    }

    public static void main(String[] args) {
        InputStreamReader r=new InputStreamReader(System.in);
        String[] line1=null;
        BufferedReader reader = new BufferedReader(r);
        Main b = new Main();
        try {
            line1=reader.readLine().split(" ");
            int n = Integer.parseInt(line1[0]);
            int desired = Integer.parseInt(line1[1]);
            int[] weights = new int[n];
            int[] val = new int[n];

            for(int i=0;i<n;++i) {
                String[] linei = reader.readLine().split(" ");
                weights[i]=Integer.parseInt(linei[0]);
                val[i]=Integer.parseInt(linei[1]);
            }
            System.out.println(b.knapsack(weights,val,n,desired));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 125908
import java.util.Scanner;


	public class Main {
		
		public static int n;
		public static int m;
		public static int q;
		public static int[] a ;
		public static int[] b ;
		public static int[] c ;
		public static int[] d ;
		public static int[] f ; 
		public static int ret;

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			n = sc.nextInt();
			m = sc.nextInt();
			q = sc.nextInt();
			
			a = new int[q];
			b = new int[q];
			c = new int[q];
			d = new int[q];
			f = new int[n];
			
			for(int i=0;i<q;i++) {
				a[i] = sc.nextInt()-1;
				b[i] = sc.nextInt()-1;
				c[i] = sc.nextInt();
				d[i] = sc.nextInt();
			}
			
			dfs(0,1);
			System.out.println(ret);
	    }
		
		
		public static void dfs(int index,int num) {
			
			if(index==n) {
				int sum = 0;
				for(int i=0;i<q;i++) {
					if(f[b[i]]-f[a[i]]==c[i]) {
						sum += d[i];
					}
				}
				ret = Math.max(ret, sum);
				return;
			}
			
			
			for(int i=num;i<=m;i++) {
				f[index] = i;
				dfs(index+1,i);
			}
		}
		
	}
	


Measured memory_bytes: 37284
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int q = sc.nextInt();
        int q1 = q * 4;
        int q2 = q * 8;
        int h = sc.nextInt();
        int h1 = h * 2;
        int h2 = h * 4;
        int s = sc.nextInt();
        int s2 = s * 2;
        int d = sc.nextInt();
        int n = sc.nextInt();

        long res = 0;
        res += (long)(n/2) * Math.min(Math.min(q2,h2), Math.min(s2,d));

        if ( n % 2 != 0) {
            res += (long)Math.min(Math.min(q1, h1), s);
        }
        System.out.println(res);

    }
}

Measured memory_bytes: 35660
#include <bits/stdc++.h>
using namespace std;
#define ar array
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
const ll mod = 1000000007;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int ans;
int main() {
	int k, s;
	cin >> k >> s;

	for(int x = 0; x <= k; x++) {
		for(int y = 0; y <= k; y++) {
			int z = s - x - y;
			if(z >= 0 && z <= k)
				ans++;
		}
	}
	cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector <double> v(n);
  for(int i=0; i<n; i++){
    cin >> v.at(i);
  }
  
  sort(v.begin(), v.end());
  double ans=v.at(0);
  for(int i=0; i<n-1; i++){
    ans = (ans + v.at(i+1))/2;
  }
  cout << ans << endl;
}


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

int main() {
    string s; cin >> s;
    string t("keyence");
    int j = 0;
    bool once = true;

    for (int i = 0; i < s.size()-1; i++) {
        for (int j = i; j < s.size(); j++) {
            string t = s.substr(0, i) + s.substr(j);
            if (t == "keyence") {
                puts("YES");
                return 0;
            }
        }
    }
    puts("NO");
    return 0;
}

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

#include <assert.h>    // LON
#include <math.h>    // sqrt()


using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
const ll MINF = LONG_LONG_MIN;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }


//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

typedef priority_queue<ll, vector<ll>, greater<ll>> PQ_ASK;
const int mod = 1000000007;


bool recursive(ll x, ll y, bool turn, ll depth) {

    bool win = false;

    for (ll k = 2; k <= x; k += 2) {
        bool b = !recursive(x - k, y + (k / 2), !turn, depth + 1);
        if (b) win = true;
    }
    for (ll k = 2; k <= y; k += 2) {
        bool b = !recursive(x + (k / 2), y - k, !turn, depth + 1);
        if (b) win = true;
    }

    return win;
}


int main() {

    ll x, y;
    cin >> x >> y;

//    for (ll x = 0; x < 10; x++) {
//        for (ll y = 0; y < 10; y++) {
//            bool b;
//    if (abs(x - y) <= 1) {
//        b = false;
//    } else {
//        b = true;
//    }
//
//            cout << ' ' << b ;
//
//        }
//        cout << endl;
//    }

//    bool b = recursive(x, y, true, 0);
//    cout << (b ? "Alice" : "Brown") << endl;

    if (abs(x - y) <= 1) {
        cout << "Brown" << endl;
    } else {
        cout << "Alice" << endl;
    }

}



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

ll dp[3005][3005];
int main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);

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

   rep(len, 1, n + 1) for (int i = 0; i + len <= n; i++) {
      int j = i + len;
      if ((n - len) % 2) {
         dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1]);
      } else {
         dp[i][j] = max(a[i] + dp[i + 1][j], dp[i][j - 1] + a[j - 1]);
      }
   }
   cout << dp[0][n] << endl;
   return 0;
}

Measured memory_bytes: 70016
#include <stdio.h>

int main(void) {
	int a,b,c,d;

	scanf("%d %d %d %d",&a,&b,&c,&d);

	if(a*b>c*d) {
		printf("%d\n",a*b);
	}
	else if(a*b<c*d) {
		printf("%d\n",c*d);
	}
	else {
		printf("%d\n", a*b);
	}

	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
	int a[10], b[3]={0};
	int i, j, k;
	for(i=0;i<10;i++)
	{
		scanf("%d", &a[i]);
	}
	for(j=0;j<3;j++)
	{
		for(i=0;i<10;i++)
		{
			if(b[j]<a[i])
			{
				b[j]=a[i];
				k = i;
			}
		}
		a[k]=0;
	}
	printf("%d\n", b[0]);
	printf("%d\n", b[1]);
	printf("%d\n", b[2]);
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
 
using namespace std;
 
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
 
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
 
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
 
typedef long long ll;
 
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555;
const double PI = acos(-1.0); 
void solve()
{

	int n, k, q;
	cin >> n >> k >> q;
	vector<int> a(n + 1, k);
	int res = 0;
	int del = 0;
	while(q--){
		int x;
		cin >> x;
		a[x]++;
		del++;
	}
	rep(i, n){
		a[i + 1] -= del;
		if(a[i + 1] <= 0) cout << "No";
		else cout << "Yes";
		cout << endl;
	}
}	

 
 
int main()
{
	Red;
	solve();
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main{

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    String s = sc.next();

    int x = 0;

    for(int i = s.length()-1;i > 0;i--){
      s = s.substring(0,i);
      String s1 = s.substring(0,i/2);
      String s2 = s.substring(i/2,i);

      if(s1.equals(s2)){
        x = i;
        break;
      }
    }

    System.out.println(x);

  }

}


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

#define ll long long
#define ld long double
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define int long long

using namespace std;
const int INF = 2e15;
const int MB = 20;
const int MOD = 1e9 + 7;
const int maxN = 2e5;

int t[maxN * 4];

void update(int v, int l, int r, int id, int val) {
    if (l + 1 == r) {
        t[v] = val;
        return;
    }

    int m = (l + r) >> 1;
    int vl = v << 1;
    int vr = vl + 1;

    if (id < m) update(vl, l, m, id, val);
    else update(vr, m, r, id, val);

    t[v] = max(t[vl], t[vr]);
}

int get(int v, int l, int r, int tl, int tr) {
    if (l == r) return 0;
    if (tl <= l && r <= tr) {
        return t[v];
    }

    int m = (l + r) >> 1;
    int vl = v << 1;
    int vr = vl + 1;

    int res = 0;
    if (tl < m) res = max(res, get(vl, l, m, tl, tr));
    if (m < tr) res = max(res, get(vr, m, r, tl, tr));
    return res;
}

vector<int> a, ans;
vector<vector<int>> g;

void dfs(int v, int p = -1) {
    int last = get(1, 0, maxN, a[v], a[v] + 1);
    int mx = get(1, 0, maxN, 0, a[v]);
    if (last < mx + 1) update(1, 0, maxN, a[v], mx + 1);
    ans[v] = get(1, 0, maxN, 0, maxN);
    for (int u : g[v]) {
        if (u != p) {
            dfs(u, v);
        }
    }
    if(last < mx + 1) update(1, 0, maxN, a[v], last);
}

void solve() {
    int n;
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    g.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int from, to;
        cin >> from >> to;
        from--; to--;
        g[from].push_back(to);
        g[to].push_back(from);
    }

    vector<int> b = a;
    sort(all(b));
    b.erase(unique(all(b)), b.end());
    for (int& i : a) i = (int)(lower_bound(all(b), i) - b.begin());

    ans.resize(n);
    dfs(0);
    for (int i : ans) cout << i << '\n';
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout << fixed;
    cout.precision(12);
    //freopen("domino-covering-1.in", "r", stdin);
    //freopen("domino-covering-1.out", "w", stdout);
    //srand(time(0));
    int t = 1;
    //int t;
    //cin >> t;
    while (t--) solve();
}

Measured memory_bytes: 30676
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <map>
#include <cstdlib>
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    if (a > b)
    {
        cout << a - 1 << endl;
    }
    else
    {
        cout << a << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	
	static class FastReader{
		BufferedReader br;
		StringTokenizer tok;
		
		FastReader(){
			br=new BufferedReader(new InputStreamReader(System.in));
		}
		
		String next() {
			if(tok==null || (!tok.hasMoreTokens())) {
				try {
					tok = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return tok.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(this.next());
		}
		String nextLine() {
			String s="";
			try {
				s = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return s;
		}
	}
	
	static int[] weights;
	static int[] values;
	static long[][] memo;
	public static void main(String[] args) {
		FastReader fr=new FastReader();
		int n=fr.nextInt(), w=fr.nextInt();
		weights = new int[n];
		values = new int[n];
		memo = new long[n][w+1];
		for(int i=0; i<n; i++) {
			weights[i]=fr.nextInt();
			values[i]=fr.nextInt();
		}
		System.out.println(dp(n-1, w));
	}
	private static long dp(int n, int c) {
		if(n==-1 || c==0) return 0;
		if(memo[n][c]!=0) return memo[n][c];
		else if(weights[n]>c) return dp(n-1, c);
		else {
			long r1 = dp(n-1, c);
			long r2 = values[n] + dp(n-1, c-weights[n]);
			memo[n][c]=Math.max(r1, r2);
			return memo[n][c];
		}
	}
}


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


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

string s;
cin>>s;
string t;
cin>>t;

ll ans=0;

for(int i=0;i<s.size();i++){
    if(s[i]!=t[i]){
        ans++;
    }
}
    cout<<ans;
}











Measured memory_bytes: 3820
def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(i)
    i += 1
  if n > 1:
    table.append(n)
  return table

a, b = map(int, input().split())
import fractions
print(len(set(prime_decomposition(fractions.gcd(a,b))))+1)

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

int H, W;
vector<string> A;
struct position {
    int x;
    int y;
    int count;
};
queue<position> q;
int sharp;

int main() {
    cin >> H >> W;
    A.resize(H);

    rep(i, H) {
        cin >> A[i];
        sharp += count(A[i].cbegin(), A[i].cend(), '#');
    }

    q.push({0, 0, 1});
    A[0][0] = '#';
    while (!q.empty()) {
        position now = q.front();
        int x        = now.x;
        int y        = now.y;
        int count    = now.count;
        int P        = A[x][y];
        q.pop();

        if (x == H - 1 && y == W - 1) {
            cout << H * W - count - sharp << endl;
            return 0;
        }

        if (x != 0 && A[x - 1][y] != '#') {
            q.push({x - 1, y, count + 1});
            A[x - 1][y] = '#';
        }
        if (y != 0 && A[x][y - 1] != '#') {
            q.push({x, y - 1, count + 1});
            A[x][y - 1] = '#';
        }
        if (x != H - 1 && A[x + 1][y] != '#') {
            q.push({x + 1, y, count + 1});
            A[x + 1][y] = '#';
        }
        if (y != W - 1 && A[x][y + 1] != '#') {
            q.push({x, y + 1, count + 1});
            A[x][y + 1] = '#';
        }
    };
    cout << -1 << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define pii pair<int, int>
#define pll pair<long long, long long>
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    char C; cin >> C;
    char c = char(C+1);
    cout << c << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int dp[200007];
int main() {
	int n;
	cin >> n;
	for (int p = 0; p <= n; ++p) {
		for (int tmp = 9; tmp <= n; tmp*=9) {
			if (p + tmp <= n)
				dp[p + tmp] = dp[p + tmp] ? std::min(dp[p]+1, dp[p + tmp]) : dp[p] + 1;
		}
		for (int tmp = 6; tmp <= n; tmp *= 6) {
			if (p + tmp <= n)
				dp[p + tmp] = dp[p + tmp] ? std::min(dp[p] + 1, dp[p + tmp]) : dp[p] + 1;
		}
		dp[p + 1] = dp[p + 1] ? std::min(dp[p] + 1, dp[p + 1]) : dp[p] + 1;
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<int,int>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  int N;
  cin>>N;
  int A[N];
  
  multiset<int> M;
  REP(i,N){
    cin>>A[i];
    auto it=M.lower_bound(A[i]);
    if(it!=M.begin()) M.erase(--it);
    M.insert(A[i]);
  }
  
  co(M.size());
}

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

int main(){
    int n, m;
    cin >> n >> m;
    int like[m + 1] = {};
    rep(i, n){
        int k;
        cin >> k;
        rep(j, k){
            int a;
            cin >> a;
            like[a] ++;
        }
    }
    int cnt = 0;
    rep(i, m){
        if (like[i + 1] == n) cnt ++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
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; }
signed main(void){
    int n; cin>>n;
    vector <pair<int,int>> p(n);
    vector <vector<int>> g(n,vector <int>());
    map <pair <int,int>, int> ma;
    rep(i,n-1){
        int a,b; cin>>a>>b;
        a--; b--;
        p[i] = make_pair(a,b);
        //cout<<a<<' '<<b<<endl;
        g[a].push_back(b);
        g[b].push_back(a);
        ma[{a,b}] = 0;
    }
    int s = -1;
    rep(i,n){
        if(g[i].size() == 1) s = i;
    }
    queue <pair <int,int>> q;
    q.push({s, 0});
    vector <bool> v(n);
    int mac = 0;
    while(!q.empty()){
        auto tmp = q.front(); q.pop();
        int now = tmp.F, colour = tmp.S;
        int nec = 1;
        if(v[now]) continue;
        v[now] = true;
        rep(j, g[now].size()){
            if(v[g[now][j]]) continue;
            else {
                int maxx = max(now, g[now][j]);
                int mi = min(now, g[now][j]);
                if(nec == colour) nec++;
                //cout<<nec<<endl;
                //cout<<maxx<<' '<<nec<<'*'<<endl;
                ma[{ mi, maxx}] = nec;
                mac = max(mac, nec);
                q.push({g[now][j], nec});
                nec++;
            }
        }
    }
    cout<<mac<<endl;
    rep(i,n-1){
        //cout<<p[i].F<<' '<<p[i].S<<endl;
        cout<<ma[{p[i].F, p[i].S}]<<endl;
    }
}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i,k,n) for(int i = k; i < n; i++)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define argmax max_element
#define argmin min_element
#define push push_back
#define pop pop_back
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
typedef string str;

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

template<class T = ll> T in() {
    T _in;
    cin >> _in;
    return _in;
}

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

    ll N;
    cin >> N;
    string S;
    cin >> S;

    // 累積和
    int from_l[300000];
    int from_r[300000];

    int count = 0;
    rep(i, N) {
        if (S[i] == 'W') {
            count++;
        }
        from_l[i] = count;
    }

    count = 0;
    for(int i=N-1; i!=-1; i--) {
        if (S[i] == 'E') {
            count++;
        }
        from_r[i] = count;
    }

    int ans = 310000;
    rep(i, N) {
        int tmp = from_l[i]+from_r[i];
        // cout << i << " " << tmp << endl;
        if (ans > tmp) {
            ans = tmp;
        }
    }
    // rep(i, N) {
    //     cout << from_l[i] << " ";
    // }
    //
    // rep(i, N) {
    //     cout << from_r[i] << " ";
    // }

    cout << ans-1 << endl;

    return 0;
}


Measured memory_bytes: 2964
//Author : Prakhar Asaiya
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(ll i=a;i<b;++i)
#define REPN(i,a,b) for(ll i=a;i<=b;++i)
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define ll long long
const int M=1e9+7;


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

 
 	int n;
 	cin>>n;
 	set<int> s1{2,4,5,7,9};
 	set<int> s2{0,1,6,8};
 	if(s1.find(n%10)!=s1.end())
 	cout<<"hon\n";
 	else if(s2.find(n%10)!=s2.end())
 	cout<<"pon\n";
 	else cout<<"bon\n";
 

   return 0;
}


Measured memory_bytes: 3564
#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
    double ans = 0, t;
    int N;
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%lf", &t);
        ans += (1/t);
    }
    printf("%.6lf\n", (1/ans));
    return 0;
}


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

int main()
{
	for(int n;cin>>n&&n;){
		string s,t; cin>>s>>t;
		for(int i=0;i<=n;i++)
			if(s.substr(0,i)+t.substr(0,n-i)==s){
				cout<<i+n<<endl;
				break;
			}
	}
}


Measured memory_bytes: 256