akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define log(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}


map<ll,ll> primes(ll n){
  map<ll,ll> v;
  for (ll i = 2; i*i <= n; ++i) {
    while(n%i==0){
      n/=i;
      v[i]++;
    }
  }
  if(n != 1)v[n]++;
  return v;
}

// TODO: write
int main() {
  ll n;cin>>n;

  int ans = 0;
  auto p = primes(n);
  for(auto&& one: p){
    ll cnt = one.se;
    int tmp = 1;
    while(cnt >= 0){
      cnt -= tmp;
      tmp++;
      ans++;
    }
    ans--;
  }
  print(ans);
  return 0;
}


Measured memory_bytes: 3560
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int main()
{  
  char number;
  number = getchar();
  int sum = 0;
  while (number != EOF) {
    sum += atoi(&number);
    number = getchar();
  }
  
  if (sum % 9 == 0) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  
  return 0;
}

Measured memory_bytes: 1552
#include<bits/stdc++.h>
using namespace std;
int main(){
  long n,d,a;
  cin >> n >> d >> a;
  long x,h;
  int i,j;
  vector<pair<long,long> >p(n);
  for(i=0;i<n;i++){
    cin >> x >> h;
    p[i] = make_pair(x,h);
  }
  sort(p.begin(),p.end());
  long ans = 0;
  vector<long>zahyou(n);
  j = n-1;
  for(i=n-1;i>=0;i--){
    while(j>=0 && p[i].first-p[j].first<=2*d)j--;
    zahyou[i] = j+1;
  }
  vector<long>total(n);
  for(i=0;i<n;i++){
    if(i==0 || zahyou[i]==i){
      ans += (a-1+p[i].second)/a;
    }else if(zahyou[i]==0){
      if(p[i].second>ans*a){
        ans += (p[i].second-ans*a+a-1)/a;
      }
    }else{
      if(p[i].second>(total[i-1]-total[zahyou[i]-1])*a){
        ans += (p[i].second-(total[i-1]-total[zahyou[i]-1])*a+a-1)/a;
      }
    }
    total[i] = ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 300010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
string B[510];

void solve() {
	cin >> N;
	rep(i, 0, N) {
		cin >> B[i];
	}
	int filled = N;
	bool ng = true;
	rep(j, 0, N) {
		bool found = false;
		rep(i, 0, N) {
			if(B[i][j] == '.') found = true;
			else ng = false;
		}
		if(!found) filled--;
	}
	if(ng) {
		cout << -1 << "\n";
		return;
	}
	int res = inf;
	rep(i, 0, N) {
		bool found = false;
		rep(j, 0, N) {
			if(B[j][i] == '#') {
				found = true;
				break;
			}
		}
		int tmp = 0;
		if(!found) tmp++;
		rep(j, 0, N) {
			if(B[i][j] == '.') tmp++;
		}
		MIN(res, tmp + filled);
	}
	if(res == inf) cout << -1 << "\n";
	else cout << res << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>

#define REP(i,n) for(int i=0;i<(n);i++)
#define EPS (1e-7)
#define INF (2e9)
// cout << setprecision(10)

using namespace std;
typedef long long int ll;

int A, B;
int main(void){
    cin >> A >> B;
    if (A>=13) cout << B << endl;
    else if (A>=6) cout << B/2 << endl;
    else cout << 0 << endl;
    return 0;
}



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

using namespace std;

typedef long long ll;

////////////////////////////////////////////////////////

// combination
// O(n)

const ll MOD = 1e9 + 7;
const ll max_n = 101010;
ll fact[max_n];
bool fact_init = false;

ll pow(ll a, ll b){
	if(b == 0) return 1;
	if(b % 2 == 1) return a * pow(a, b - 1) % MOD;

	ll d = pow(a, b / 2) % MOD;
	return d * d % MOD;
}

ll comb(ll n, ll k){
	if(!fact_init){
		fact[0] = 1;
		fact[1] = 1;

		for(ll i = 2; i < max_n; i++){
			fact[i] = fact[i-1] * i;
			fact[i] %= MOD;
		}

		fact_init = true;
	}

	ll ret = fact[n];
	ret *= pow(fact[k],MOD-2);
	ret %= MOD;
	ret *= pow(fact[n-k],MOD-2);
	ret %= MOD;
	return ret;

	// X^(-1) = X^(p-2) (mod p) (Fermat's little theorem)
}


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

	ll n, k;
	cin >> n >> k;

	if(k == 1){
		cout << 0 << endl;
		return 0;
	}

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

	sort(a.begin(), a.end());
	rep(i, n){
		a[i] += MOD;
		a[i] %= MOD;
	}

	ll coef[n-k+1];
	coef[0] = comb(n-(n-k)-2, k - 2);
	rep(i, n-k){
		coef[i+1] = coef[i] + comb(n-(n-k)+i+1-2, k - 2);
		coef[i+1] %= MOD;
	}

	ll ans = 0;
	rep(i, n-k+1){
		ll x = a[n-i-1] * coef[n-k-i];
		x %= MOD;

		ans += x;
		ans %= MOD;

		ll y = (MOD - a[i]) * coef[n-k-i];
		y %= MOD;

		ans += y;
		ans %= MOD;
	}

	cout << ans << endl;
}


Measured memory_bytes: 2176
//#include<iostream>
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
const int N = 200005;

vector<int> adj[N];
int dst[N];
int par[N];
int n,m;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	
	memset(dst,0x7f,sizeof dst);
	dst[1] = 0;
	queue<int> q;
	q.push(1);
	int hano = 0;
	while(!q.empty()){
		int x = q.front();
		q.pop();
		hano++;
		for(int y:adj[x]){
			if(dst[x]+1 < dst[y]){
				dst[y] = dst[x] + 1;
				par[y] = x;
				q.push(y);
			}
		}
	}
	
	if(hano == n){
		cout<<"Yes"<<endl;
		for(int i=2;i<=n;i++){
			cout<<par[i]<<endl;
		}
	}else{
		cout<<"No"<<endl;
	}
	
	return 0;
}


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

const int N = 100005, M = 9999999;
typedef std::pair<int, int> pair;

int n, idx, lc[N], rc[N], root;
pair p[N];

int head[N], tot; struct edge { int to, nxt; } e[M];
void link(int x, int y) {e[++tot] = (edge) {y, head[x]}, head[x] = tot;}
void implies(int x, int y) {link(x, y), link(y ^ 1, x ^ 1);}

int build(int l = 0, int r = n * 2 - 1) {
	if (l == r) return p[l].second;
	int mid = l + r >> 1, now = idx; idx += 2;
	implies(lc[now] = build(l, mid), now);
	implies(rc[now] = build(mid + 1, r), now);
	return now;
}

void query(int L, int R, int p, int rt = root, int l = 0, int r = n * 2 - 1) {
	if (L <= l && R >= r) return implies(rt, p);
	int mid = l + r >> 1;
	if (L <= mid) query(L, R, p, lc[rt], l, mid);
	if (R > mid) query(L, R, p, rc[rt], mid + 1, r);
}

int _tot, _head[N];
void save() {_tot = tot, std::memcpy(_head, head, idx << 2);}
void load() {tot = _tot, std::memcpy(head, _head, idx << 2);}

int dfn[N], low[N], clk, stack[N], top, scc, bel[N]; bool ins[N];

void init() {std::memset(dfn, 0, idx << 2), clk = scc = 0;}
void tarjan(int x) {
	dfn[x] = low[x] = ++clk, ins[stack[++top] = x] = 1;
	for (int i = head[x]; i; i = e[i].nxt)
		if (!dfn[e[i].to])
			tarjan(e[i].to), low[x] = std::min(low[x], low[e[i].to]);
		else if (ins[e[i].to])
			low[x] = std::min(low[x], dfn[e[i].to]);
	if (dfn[x] == low[x]) {
		int v; ++scc;
		do ins[v = stack[top--]] = 0, bel[v] = scc; while (v != x);
	}
}

int x[N], y[N];
bool check(int mid) {
	--mid, load(), init();
	int L = 0, R = 0;
	for (int i = 0; i < n + n; ++i) {
		while (R + 1 < n + n && p[R + 1].first - p[i].first <= mid) ++R;
		while (p[i].first - p[L].first > mid) ++L;
		if (L < i) query(L, i - 1, p[i].second ^ 1);
		if (i < R) query(i + 1, R, p[i].second ^ 1);
	}
	for (int i = 0; i < idx; ++i) if (!dfn[i]) tarjan(i);
	for (int i = 0; i < idx; i += 2) if (bel[i] == bel[i ^ 1]) return 0;
	return 1;
}

int main() {
	std::ios::sync_with_stdio(0), std::cin.tie(0);
	std::cin >> n, idx = n * 2;
	for (int i = 0; i < n; ++i)
		std::cin >> x[i] >> y[i], p[i << 1] = pair(x[i], i << 1), p[i << 1 | 1] = pair(y[i], i << 1 | 1);
	std::sort(p, p + idx), root = build(), save();
	int l = 1, r = 1e9, ans = 0;
	while (l <= r) {
		int mid = l + r >> 1;
		if (check(mid)) ans = mid, l = mid + 1;
		else r = mid - 1;
	}
	std::cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 19200
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n,a,b = map(int, input().split())
    s = input().rstrip()
    # 通過者
    c = 0
    # 海外の学生の順位
    d = 1
    res = []
    for i in s:
        if i=='c':
            res.append('No')
        if i=='b':
            if c<a+b and d<=b:
                res.append('Yes')
                c += 1
                d += 1
            else:
                res.append('No')
        if i=='a':
            if c<a+b:
                res.append('Yes')
                c += 1
            else:
                res.append('No')
    for i in res:
        print(i)

if __name__ == '__main__':
    main()

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  vector<string> v(3);
  for (int i = 0; i < 3; i++) cin >> v[i];
  cout << v[0][0] << v[1][1] << v[2][2] << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)

	v := make([][]int, n)
	for i := 0; i < n; i++ {
		v[i] = make([]int, 3)
	}
	for i := 0; i < n; i++ {
		fmt.Scan(&v[i][0], &v[i][1], &v[i][2])
	}

	dp := make([][]int, n+1)
	for i := 0; i < n+1; i++ {
		dp[i] = make([]int, 3)
	}
	for i := 0; i < n; i++ {
		for j := 0; j < 3; j++ {
			for k := 0; k < 3; k++ {
				if j == k {
					continue
				}
				next := dp[i][j] + v[i][k]
				if next > dp[i+1][k] {
					dp[i+1][k] = next
				}
			}
		}
	}

	ans := -1
	for k := 0; k < 3; k++ {
		if dp[n][k] > ans {
			ans = dp[n][k]
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

int main()
{
    string s;
    cin >> s;
    ll ans = 0;
    ll acnt = 0;
    if (s.length() >= 3)
    {
        for (int i = 0; i < s.length() - 1; i++)
        {
            if (s[i] == 'A')
                acnt++;
            else if (s[i] == 'B' && s[i + 1] == 'C')
            {
                ans += acnt;
                i++;
            }
            else
                acnt = 0;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <stdio.h>

void sort(int data[], int size);

int
main(void)
{
  int data[3];
  scanf("%d%d%d", &data[0], &data[1], &data[2]);
  sort(data, 3);
  printf("%d %d %d\n", data[0], data[1], data[2]);
  return 0;
}

void
sort(int data[], int size)
{
  int i, j;
  for (i = 0; i < size; i++) {
    for (j = size - 1; j >= i; j--) {
      if (data[j - 1] > data[j]) {
        int tmp;
        tmp = data[j - 1];
        data[j - 1] = data[j];
        data[j] = tmp;
      }
    }
  }
  return;
}

Measured memory_bytes: 1752
from heapq import heapify, heappop, heappush, nsmallest
n, m = map(int, raw_input().split())
X = map(int, raw_input().split())
X.sort()
if m == 1:
    print 0
    exit()
elif n == 1:
    print X[-1] - X[0]
    exit()
heap = []
heapify(heap)
for i in range(1, m):
    diff = X[i] - X[i-1]
    if len(heap) >= n - 1 and heap[0][0] < diff:
        heappop(heap)
        heappush(heap, (diff, X[i-1], X[i]))
    elif len(heap) < n - 1:
        heappush(heap, (diff, X[i-1], X[i]))
    else:
        continue
heap.sort(key=lambda X : X[1])
cp = X[0]
move = 0
for j in range(len(heap)):
    diff, left, right = heap[j]
    move += left - cp
    cp = right
move += (X[-1] - cp)
print move

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

int main(){
  int n,m; cin>>n>>m;
  int sx[n],sy[n];
  for(int i=0;i<n;i++){
    cin>>sx[i]>>sy[i];
  }int x[m],y[m];
  for(int i=0;i<m;i++){
    cin>>x[i]>>y[i];
  }for(int i=0;i<n;i++){
    int ans,minnum=1000000000;
    for(int j=0;j<m;j++){
      int log=minnum;
      minnum=min(minnum,abs(sx[i]-x[j])+abs(sy[i]-y[j]));
      if(minnum!=log){
        ans=j+1;
      }
    }cout<<ans<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#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 INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    int n;cin>>n;
    vector<int> A(n), B(n), C(n);
    REP(i,n) cin >> A[i];
    REP(i,n) cin >> B[i];
    REP(i,n) cin >> C[i];
    sort(ALL(A)), sort(ALL(B)), sort(ALL(C));
    vector<ll> num_c(n,0),itr_b(n,INF), num_bc(n+1,0);
    REP(i,n){
        if(C[n-1] > B[i]){
            num_c[i] = C.end() - upper_bound(ALL(C),B[i]);
            //cout << i << " " << num_c[i] << endl;
            //num_bc[n-1-i] = num_bc[n-i] + num_c[]
        }
    }
    REPR(i,n){
        num_bc[i-1] = num_bc[i] + num_c[i-1];
        //cout<<num_bc[i-1]<<endl;
    }


    REP(i,n){
        if(B[n-1] > A[i]){
            itr_b[i] = upper_bound(ALL(B),A[i]) -B.begin();
            //cout<< i << " " << itr_b[i] << endl;
        }
    }
    ll ans = 0;
    REP(i,n){
        if(itr_b[i] != INF){
            ans += num_bc[itr_b[i]];
        }
    }

    cout << ans << endl;

}

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld; 


#define F first
#define S second
#define pob pop_back
#define pb push_back
#define Time()	cerr << clock() * 1000 / CLOCKS_PER_SEC << "ms\n"
#define show(x)	cerr << #x << " = " << (x) << '\n'
#define inf 1e14
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define invec(v) for(auto& x : v)cin>>x;
#define Test int T;cin>>T;while(T--)
#define vec vector<ll> 
#define REP(i,j,k) for(int i=(j);(i)<(k);(i)++)
#define TEST int t;cin>>t;while(t--)




int main(){
	string s;
	cin>>s;
	if(s[2] ==s[3] && s[4] == s[5])cout<<"Yes";
	else cout<<"No";


}


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

#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

int main()
{
  vector<int> a(5); rep(i, 5) cin >> a[i];
  int k; cin >> k;

  if (abs(a[0]-a[1]) > k or abs(a[0]-a[2]) > k or abs(a[0]-a[3]) > k or abs(a[0]-a[4]) > k or
      abs(a[1]-a[2]) > k or abs(a[1]-a[3]) > k or abs(a[1]-a[4]) > k or
      abs(a[2]-a[3]) > k or abs(a[2]-a[4]) > k or abs(a[3]-a[4]) > k) {
    cout << ":(" << endl;
  } else {
    cout << "Yay!" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;

ll mod = 1e9 + 7;

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

    set<int, greater<int>> s;
    for (int i = 1; i * i <= n; i++)
    {
        s.insert(i);
        s.insert(n / i);
    }

    int prev = 0;
    int sz = s.size();
    vpii gr(sz);
    int idx = 0;
    for (auto v : s)
    {
        gr[idx] = pii(sz - idx - 1, n / v - prev);
        prev = n / v;
        idx++;
    }

    vvll dp(2);
    dp[0] = vll(gr.size(), 0);
    dp[1] = vll(gr.size(), 0);
    int curr = 0;
    for (int i = 0; i < gr.size(); i++)
    {
        int num = gr[i].first;
        int cnt = gr[i].second;
        dp[curr][i] = cnt;
    }

    for (int i = 1; i < k; i++)
    {
        int next = curr ^ 1;
        dp[next] = vll(gr.size(), 0);

        vll sum = vll(gr.size(), 0);
        sum[0] = dp[curr][0] * gr[0].second;
        for (int j = 1; j < gr.size(); j++)
        {
            sum[j] = sum[j - 1] + dp[curr][j];
            sum[j] %= mod;
        }

        for (int j = 0; j < gr.size(); j++)
        {
            int num = gr[j].first;
            int cnt = gr[j].second;
            dp[next][j] = sum[num] * cnt;
            dp[next][j] %= mod;
        }
        curr = next;
    }

    ll sum = 0;
    for (int i = 0; i < gr.size(); i++)
    {
        sum += dp[curr][i];
        sum %= mod;
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 5248
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	int N;
	int V[25]={};
	int C[25]={};

	cin >> N;
	for(int i=0;i<N;i++)
		cin >> V[i];
	for(int i=0;i<N;i++)
		cin >> C[i];

	int ans=-1000;
	for(int i=0;i<(1<<N);i++)
	{
		int X=0;
		int Y=0;

		int bit=i;
		for(int j=0;j<N;j++)
		{
			if(bit&(1<<j))
			{
				X+=V[j];
				Y+=C[j];
			}
			ans=max(ans,X-Y);
		}
	}

	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
//int a = stoi(c); 文字列をintへ
//小文字から大文字
//transform(a.begin(), a.end(), a.begin(), ::toupper);
//数値計算 個数以外はdouble
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; it++) {}
//mapのキー：it->first mapのバリュー：it->second
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
//小文字に対応する文字コード：S[i] - 'a'
//文字コード→小文字：(char)(数字+'a')
//グラフの距離:隣接行列で扱う
//bool型　初期値はTrue
//島渡りの問題：中間ノードに着目
//数が大きい時の比較はstring型で行う
//全て0になったか調べたい->0になるたびにcntする
//例外処理は最初にする
//x = p^m + q^n...の約数の個数:(n+1)*(m+1)....
//N!のどの素因数で何回割れるか
//⇔1~Nまでの数がそれぞれどの素因数で何回割り切れるかの和
//パズルの問題->一般化して全探索
//stack<ll> s;
//s.push(要素);s.top();s.pop();
//queue<ll> q;
//q.push(要素);q.front();q.pop();
//同じ作業繰り返す系の問題：収束先を見つける
//過半数：N/2.0で判定
//優先度付きキュー
//priority_queue<
//ll,
//vector<ll>
//> q;
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

//円周率
const double PI = 3.14159265358979323846;
//割るやつ
const ll MOD = (pow(10, 9) + 7);

// K進数でのNの桁数
ll dig(ll N, ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// a,bの最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}

//a,bの最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

//階乗計算
ll f(ll n) {
	if (n == 0 || n == 1) return 1;
	else return (n * f(n - 1));
}

//Nのd桁目の数
ll dignum(ll N, ll d) {
	ll x = pow(10, d);
	N %= x;
	ll y = pow(10, d - 1);
	N /= y;
	return N;
}

//Nをdで何回割れるか
ll divcnt(ll N, ll d) {
	ll ans = 0;
	while (1) {
		if (N%d == 0) {
			ans++;
			N /= d;
		}
		else break;
	}

	return ans;
}

//素数判定
bool prime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false;
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) return false;
	}
	return true;
}

//フィボナッチ数列
vector<ll> memo(pow(10, 6) + 1);
ll fibo(ll n) {
	if (n == 1) return 1;
	else if (n == 2) return 1;
	else if (memo[n] != 0) return memo[n];
	else return memo[n] = fibo(n - 1) + f(n - 2);
}

int main() {
	ll N, K; cin >> N >> K;
	vector<ll> A(N); rep(i, N) {
		cin >> A[i];
		A[i]--;
	}

	map<ll, ll> p;
	ll cyc = 0;
	ll cnt = 0;
	ll num = 0;
	while (1) {
		if (p[num] != 0) {
			cyc = cnt - p[num] + 1;
			break;
		}
		p[num] = cnt + 1;
		num = A[num];
		cnt++;
	}

	ll k;
	if (K >= cnt - cyc)  k = (K - (cnt - cyc))%cyc + cnt-cyc;
	else k = K;
	
	auto begin = p.begin(), end = p.end();
	for (auto it = begin; it != end; it++) {
		if (it->second == k + 1) {
			cout << it->first + 1<< endl;
			return 0;
		}
	}
}

Measured memory_bytes: 24856
N = input()

def search(i):
        if int(i) > int(N):
                return 0

        nums = [3, 5, 7]
        count = 0
        if all(i.count(str(n)) > 0 for n in nums):
                count = 1
        else:
                count = 0
        
        for n in nums:
                count += search(i + str(n))
        
        return count

print(search(str(0)))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

using ll = long long;
using P = pair<int, int>;

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

ll LCM(ll a, ll b){
    return a / GCD(a, b) * b;
}

int main()
{
    int N;
    cin >> N;
    ll t[100];
    for(int i = 0; i < N; ++i) cin >> t[i];
    ll ans = t[0];
    for(int i = 1; i < N; ++i){
        ans = LCM(ans, t[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.function.Consumer;

// https://atcoder.jp/contests/dp/tasks/dp_a
public class Main {
    public static void main(String args[]) {
        runCode();
    }

    private static void runCode() {
        try (Scanner scan = new Scanner(System.in)) {
            int n = scan.nextInt();
            int[] h = new int[n];
            for (int i = 0; i < n; i++) {
                h[i] = scan.nextInt();
            }
            System.out.println(new UsingDP().minCost(h));
        }
    }

    public static void runTest() {
        List<Consumer<Solution>> testCases = Arrays.asList(
                solution -> {
                    int actual = solution.minCost(new int[]{10, 30, 40, 20});
                    assert actual == 30;
                },
                solution -> {
                    int actual = solution.minCost(new int[]{10, 10});
                    assert actual == 0;
                },
                solution -> {
                    int actual = solution.minCost(new int[]{30, 10, 60, 10, 60, 50});
                    assert actual == 40;
                }
        );
        testCases.forEach(testCase -> testCase.accept(new UsingDP()));
        testCases.forEach(testCase -> testCase.accept(new UsingDP2()));
    }

    public interface Solution {
        int minCost(int[] heights);
    }

    public static class UsingDP implements Solution {
        public int minCost(int[] heights) {
            if (heights.length < 2) return 0;
            if (heights.length == 2) return Math.abs(heights[1] - heights[0]);
            int[] costs = new int[heights.length];
            Arrays.fill(costs, 1, costs.length, Integer.MAX_VALUE);
            for (int i = 0; i < heights.length; i++) {
                for (int j = i + 1, jl = Math.min(j + 2, heights.length); j < jl; j++) {
                    costs[j] = Math.min(costs[j], costs[i] + Math.abs(heights[j] - heights[i]));
                }
            }
            return costs[costs.length - 1];
        }
    }

    public static class UsingDP2 implements Solution {
        public int minCost(int[] heights) {
            if (heights.length < 2) return 0;
            int[] costs = new int[heights.length];
            costs[1] = Math.abs(heights[1] - heights[0]);
            for (int i = 2; i < heights.length; i++) {
                costs[i] = Math.min(
                        costs[i - 2] + Math.abs(heights[i - 2] - heights[i]),
                        costs[i - 1] + Math.abs(heights[i - 1] - heights[i])
                );
            }
            return costs[costs.length - 1];
        }
    }
}


Measured memory_bytes: 53820
(* 0-indexedなBIT *)
module FenwickTree = struct
  (* 可換モノイド *)
  module type CommutativeMonoid = sig
    type t
    val e : t
    val op : t -> t -> t
  end

  module Make (CM : CommutativeMonoid)
  : sig
    type t
    (* n要素の単位元からなるBITを作る *)
    val make : int -> t
    (* 添字iの要素にはf iが入ったn要素のBITを作る *)
    val init : int -> (int -> CM.t) -> t
    (* 与えられたリストの要素が入ったBITを作る *)
    val of_list : CM.t list -> t
    (* i番目の要素にxを加える *)
    val accumulate : t -> int -> CM.t -> unit
    (* 添字が[0, i)の範囲の要素を全て加えた値を求める *)
    val query : t -> int -> CM.t
  end
  = struct
    type t = CM.t array

    let make n = Array.make n CM.e

    let initialize a =
      for i = 0 to Array.length a - 1 do
        if i lor (i + 1) < Array.length a then
          a.(i lor (i + 1)) <- CM.op a.(i) a.(i lor (i + 1))
      done

    let init n f =
      let a = Array.init n f in
      initialize a; a

    let of_list l =
      let a = Array.of_list l in
      initialize a; a

    let rec accumulate a i x =
      if i < Array.length a then begin
        a.(i) <- CM.op x a.(i);
        accumulate a (i lor (i + 1)) x
      end

    let rec query acc a i =
      if i < 0
      then acc
      else query (CM.op acc a.(i)) a ((i land (i + 1)) - 1)
    let query a i = query CM.e a (i - 1)
  end
end

module BIT = FenwickTree.Make (struct
  type t = int
  let e = 0
  let op = ( + )
end)

let () = Scanf.scanf "%d %d\n" @@ fun n q ->
  let bit = BIT.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  for i = 0 to q - 1 do
    Scanf.scanf "%d %d %d\n" @@ fun q (p as l) (x as r) ->
      match q with
      | 0 -> BIT.accumulate bit p x
      | 1 -> Printf.printf "%d\n" @@ BIT.query bit r - BIT.query bit l
  done

Measured memory_bytes: 10964
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int t[200005], a[200005], b[200005];

struct fenwick{
    LL ft[200005];
    void update(int i, int v){
        for(;i<=200000;i+=(i&-i)) ft[i] += v;
    }
    LL query(int i){
        LL res = 0;
        for(;i>0;i-=(i&-i)) res+=ft[i];
        return res;
    }
}ft1, ft2, ftc;

int main(){
    vector<int> v;
    int q;
    scanf("%d", &q);
    for(int i=0;i<q;i++){
        scanf("%d", &t[i]);
        if(t[i] == 1) scanf("%d%d", &a[i], &b[i]), v.push_back(a[i]);
    } 
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    int cnt = 0;
    LL val = 0;
    for(int i=0;i<q;i++){
        if(t[i] == 1){
            int x = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1;
            ftc.update(x, 1);
            ft1.update(x, a[i]-(-1e9));
            ft2.update(x, 1e9-a[i]);
            val += b[i];
            cnt++;
        }
        else{
            int lo = 1, hi = 200000, x = 1;
            int w = (cnt+1)/2;
            while(lo <= hi){
                int mid = (lo+hi)/2;
                if(ftc.query(mid) >= w) x = mid, hi = mid-1;
                else lo = mid+1;
            }

            LL val1 = ft1.query(200000) - ft1.query(x);
            int c1 = ftc.query(200000) - ftc.query(x);
            LL val2 = ft2.query(x);
            int c2 = ftc.query(x);

            x = v[x-1];

            LL ans = val1 - c1*1ll*(x-(-1e9)) + val2 - c2*1ll*(1e9-x);
            printf("%d %lld\n", x, ans + val);

        }
    }
}

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

struct Fenwick
{
	vector<long long> T;
	int size;

	Fenwick(int n)
	{
		size = n;
		T.resize(n + 1);
	}

	void add(int pos, long long val)
	{
		while(pos <= size)
		{
			T[pos] = max(T[pos], val);
			pos += pos & (-pos);
		}
	}

	long long get(int pos)
	{
		long long ret = 0;
		while(pos != 0)
		{
			ret = max(ret, T[pos]);
			pos -= pos & (-pos);
		}
		return ret;
	}
};

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

	int n;
	cin >> n;

	vector<int> h(n);
	for(int i = 0; i < n; i++)
		cin >> h[i];

	Fenwick tree(n);
	for(int i = 0; i < n; i++)
	{
		long long val;
		cin >> val;
		tree.add(h[i], val + tree.get(h[i] - 1));
	}

	cout << tree.get(n) << "\n";
}


Measured memory_bytes: 2560
from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
l = [0]
r = [0]
for i in range(n):
    l.append(gcd(l[i],a[i]))
    r.append(gcd(r[i],a[-i-1]))
r = r[::-1]
ans = 0
for i in range(n):
    ans = max(ans,gcd(l[i],r[i+1]))
print(ans)

Measured memory_bytes: 95456
#include <bits/stdc++.h>
#define ri register
#define int long long
#define E (n+1)
using namespace std; const int N=200010;
inline int read()
{
    int s=0, w=1; ri char ch=getchar();
    while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
    while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
    return s*w;
}
int n,m,dis[210][210];
struct Node
{
    int u,v,w;
}e[N];
signed main()
{
    memset(dis,0x3f,sizeof(dis));
    n=read(), m=read();
    for(ri int i=1;i<=n;i++) dis[i][i]=0;
    for(ri int i=1;i<=m;i++)
    {
        e[i].u=read(), e[i].v=read(), e[i].w=read();
        dis[e[i].u][e[i].v]=dis[e[i].v][e[i].u]=e[i].w;
    }
    for(ri int k=1;k<=n;k++)
    for(ri int i=1;i<=n;i++)
    for(ri int j=1;j<=n;j++)
    dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);

    int res=0;
    for(ri int i=1;i<=m;i++)
    {
        int qwq=0;
        for(ri int j=1;j<=n;j++)
        {
            if(dis[j][e[i].u]+e[i].w==dis[j][e[i].v])
            {
                qwq=1;
                break;
            }
        }
        res+=qwq;
    }
    printf("%lld\n",m-res);
    return 0;
}

Measured memory_bytes: 4092
N, K = map(int, input().split())
*P, = map(int, input().split())
expectations = [(p + 1) / 2 for p in P]
ans = 0
S = sum(expectations[:K])
for i in range(N - K):
    ans = max(ans, S)
    S = S - expectations[i] + expectations[i + K]
ans = max(ans, S)
print(ans)

Measured memory_bytes: 25060
IDENTIFICATION DIVISION.
PROGRAM-ID. 102C.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP   PIC X(15).
01 N     PIC 9(6).
01 K     PIC 9(6).
01 S     PIC 9(6).
01 A     PIC 9(1).
01 S1    PIC 9(6)V9.
01 S1-R  REDEFINES S1.
   03 F1 PIC 9(6).
   03 S2 PIC 9(1).
01 CNT   PIC 9(18).
01 OUT   PIC Z(17)9.
*>
PROCEDURE DIVISION.
  ACCEPT INP. 
  UNSTRING INP DELIMITED BY ' '
      INTO N K.
*>
  DIVIDE K BY 2 GIVING S REMAINDER A.
  DIVIDE N BY K GIVING S1.
*>
  IF (A = 1)
    COMPUTE CNT = F1 ** 3
  ELSE
    COMPUTE CNT = F1 ** 3
    IF (S2 < 5)
      COMPUTE CNT = CNT + F1 ** 3
    ELSE
      COMPUTE CNT = CNT + (F1 + 1) ** 3
    END-IF
  END-IF.
*>
  MOVE CNT TO OUT.
  DISPLAY FUNCTION TRIM(OUT).
  STOP RUN.
 

Measured memory_bytes: 636
def replace_ast(N, S, K):
    rstr = S[K-1]
    outstr = ''
    for s in S:
        if s == rstr:
            outstr += s
        else:
            outstr += '*'
    print(outstr)


N = int(input())
S = str(input())
K = int(input())

replace_ast(N, S, K)

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  int flag = 0;
  getline(cin,s);
  for(int i = 0;i<3;i++)
  {
    if(s[i] == s[i+1])
    {
      flag = 1;
      break;
    }
  }
  if(flag == 0)
    cout<<"Good";
  else
    cout<<"Bad";
  return 0;
}
  

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

int main() {
  int N, sensor = 0;
  cin >> N;
  vector<vector<int>> data(N, vector<int> (2));
  for (int i=0;i<N;i++){
    for (int j=0;j<2;j++){
      cin >> data.at(i).at(j);
    }
  }
  for (int i=0;i<N-2;i++){
    if (data.at(i).at(0) == data.at(i).at(1)){
      if (data.at(i+1).at(0) == data.at(i+1).at(1)){
        if (data.at(i+2).at(0) == data.at(i+2).at(1)){
          sensor++;
        }
      }
    }
  }
  
  if (sensor == 0)
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
}

Measured memory_bytes: 3608
#include <iostream>

using namespace std;

int main()
{
    string s;
    cin >> s;
    for(int i = 0; i < 3; i++)
    {
        if(s[i] == s[i + 1])
        {
            cout << "Bad";
            return 0;
        }
    }
    cout << "Good";

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

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

int main() {

    ll a, b;
    cin >> a >> b;

    ll ans = gcd(a, b);
    ans = a / ans;
    ans = ans * b;

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
int n ;
signed main () {
    cin >> n ;
    int x = n % 10 ;
    if ( x == 2 || x == 4 || x == 5 || x == 7 || x == 9 ) cout << "hon\n" ;
    else if ( x == 0 || x == 1 || x == 6 || x == 8 ) cout << "pon\n" ;
    else cout << "bon\n" ;
    return 0 ;
}

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

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << (a) << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

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

const int N = 2e5 + 10;

int n;
ll L, x[N], cum[N];


int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> L >> n;
    forn(i,n) {
        cin >> x[i];
        cum[i+1] = cum[i] + x[i];
    }

    ll ans = 0;
    forn(_,2) {
        //forn(i,n) cerr << x[i] << ' '; cerr << endl;
        //forn(i,n+1) cerr << cum[i] << ' '; cerr << endl;
        forn(i,n) {
            int l = n-i, r = i, mn = min(l,r);
            l = min(l, mn+1); r = min(r, mn);
            ll cand = ll(l)*L - (cum[i+l] - cum[i]) + cum[i] - cum[i-r];
            cand = 2*cand - (L-x[i]);
            ans = max(ans, cand);
        }
        //D(ans);
        reverse(x,x+n);
        forn(i,n) {
            x[i] = L-x[i];
            cum[i+1] = cum[i] + x[i];
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3328
N = int(input())
S = str(input())

a = []
for i in range(10):
    for j in range(10):
        for z in range(10):
            a.append([i,j,z])

s = list(S)
s = [int(i) for i in s]
ans = 0
for n in a:
    flag = 0
    for i,name in enumerate(s):
        if name == n[0]:
            n = n[1:]
            flag += 1
        if flag == 3:
            ans += 1
            break

print(ans)

Measured memory_bytes: 43116
#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;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = 998244353;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}



void solve(){
	int n, l;
	cin >> n >> l;
	string s[n];
	rep(i, n) cin >> s[i];
	sort(s, s + n);
	rep(i, n) cout << s[i];
}


 
 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}

Measured memory_bytes: 256
//skatal

#include <bits/stdc++.h>
#define off  exit( 0 )
#define cn   continue
#define rt   return
#define sc   scanf
#define pr   printf
#define pb   push_back
#define pf   push_front
#define p_f  pop_front
#define p_b  pop_back
#define ff   first
#define ss   second
#define ll   long long
#define ld   long double
#define N    190
#define M    1000000007
#define I    1000000000000000000
#define pdd  pair < ld, ld >
#define pll  pair < ll, ll >
#define pii  pair < int, int >
#define sqr( a )           a * a
#define all( c )           c.begin(), c.end()
#define srt( c )           sort( all( c ) )
#define rev( c )           reverse( all( c ) )
#define srtr( c )          sort( c.rbegin(), c.rend() );
using namespace std;

int n, m, s[N][N], c[N][N];
int f[2][N][N][N], v;
void solve()
{
    sc( "%d%d", &n, &m );
    for( int i = 1; i <= n; i ++ ){
        sc( "\n" );
        for( int j = 1; j <= m; j ++ )
            c[i][j] = s[i][j] = ( getchar() == '#' ? 1: 0);
    }
    for( int i = 1; i <= n; i ++ )
        for( int j = 1; j <= m; j ++ )
            s[i][j] += s[i][j - 1];
    for( int i = 1; i <= n; i ++ )
        for( int j = 1; j <= m; j ++ )
            s[i][j] += s[i - 1][j];
    for( int k = m; k > 0; k -- )
        for( int i = 1; i <= n; i ++ )
            for( int j = i; j <= n; j ++ )
            {
                int su = s[j][k] - s[i - 1][k] - s[j][k - 1] + s[i - 1][k - 1];
                if(su && su < j - i + 1)cn;
                if( f[0][k + 1][i][j] && c[i][k] == c[i][k + 1] )f[0][k][i][j]=f[0][k + 1][i][j] + 1;
                else f[0][k][i][j] = 1;
            }
    if( f[0][1][1][n] == m )
    {
        pr( "0" );
        rt;
    }
    int o = 0;
    for( int le = 1; le < 17; le ++ )
    {
        o ^= 1;
        memset( f[o], 0, sizeof f[o] );
        for( int k = 1; k <= m; k ++ )
        {
            for( int i = 1; i <= n; i ++ )
            {
                int wz = i - 1;
                for( int j = i; j <= n; j ++ )
                {
                    v = f[!o][k][i][j];
                    f[o][k][i][j] = v + f[!o][k + v][i][j];
                    if(i == j)cn;
                    while( wz + 1 < j && f[!o][k][i][wz+1] > f[!o][k][wz+2][j] )wz ++;
                    if( wz + 1 > i )f[o][k][i][j] = max( f[o][k][i][j], f[!o][k][wz + 1][j]);
                    if( wz + 1 < j )f[o][k][i][j] = max( f[o][k][i][j], f[!o][k][i][wz + 1]);
                }
            }
        }
        if( f[o][1][1][n] == m )
        {
            pr("%d",le);
            rt;
        }
    }
}
int main()
{
    int tt = 1;
    //sc( "%d", &tt );
    for( int i = 1; i <= tt; i ++ )
        solve();
}












Measured memory_bytes: 54144
#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main() {
    int N, ans=0;
    cin >> N;
    vector<string> s(N);

    for(int i=0; i<N; i++){
	cin >> s[i];
    }
    sort(s.begin(), s.end());
    string tmp = s[0];
    ans=1;
    for(int i=0; i<N; i++){
	if(tmp != s[i]){
	    ans++;
	    tmp = s[i];
	}
    }

    cout << ans << endl;
} 




Measured memory_bytes: 9600
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <queue>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
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();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int gcd(int a, int b){
   int tmp;
   while(a%b==0){
      tmp=a%b;
      a=b;
      b=tmp;
   }
}

int lcm(int a,int b){
   return a*b/gcd(a,b);
}

bool prime_number(int n){
   if(n < 2){
      return false;
   }
   else if(n == 2){
      return true;
   }
   if(n % 2 == 0){
      return false;
   }
   for(int i=3;i<=n/i;i+=2){
      if(n % i == 0) return false;
      return true;
   }
}

int main(){
   string a;

   while(getline(cin,a)){
      while(a.find("the")==string::npos&&a.find("this")==string::npos&&a.find("that")==string::npos)
         REP(i,a.size()){
            if(a[i]=='z') a[i]='a';
            else if(a[i]>='a'&&a[i]<='z') a[i]++;
         }
      cout << a << endl;
   }
   return 0;
}

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

int main() {
	int n;
	cin>>n;
	
	long sum = 0;
	for(int i=1; i<=n; ++i){
		if(i%3 && i%5)
			sum += i;
	}
	
	cout<<sum<<endl;
		
	return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int n;
string s;
long long ans;
long long m1,m2,m3;
int main()
{
	scanf("%d",&n);
	cin>>s;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='R')
		{
			m1++;
		}
		else if(s[i]=='B')
		{
			m2++;
		}
		else
		{
			m3++;
		}
	}
	ans=m1*m2*m3;
	if(n<=2)
	{
		cout<<0;
		return 0;
	}
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			if(s[i]!=s[j])
			{
				if(2*j-i<n)
				{
					if(s[2*j-i]!=s[i]&&s[2*j-i]!=s[j])
					{
						ans--;
					}
				}
			}
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3772
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  ll n,x;
  cin >> n >> x;
  ll arr[n];
  for(ll i=0;i<n;i++)
    cin >> arr[i];
  ll answer=0;
  if(arr[n-1]<=x)
  {
    answer = arr[n-1]+x;
    cout << answer << endl;
  }
  else
  {
    ll temp;
    for(ll i=0;i<n-1;i++)
    {
      temp = arr[i+1]-arr[i];
      if(temp>x)
        answer+=x;
      else if(temp==x)
        answer+=x;
      else
        answer+=temp;
    }
    answer+=x;
    cout << answer << endl;
  }
  return 0;
}


Measured memory_bytes: 1792
/*
Logic 
position i can occupy letters from 'a' to (max_char_till_now + 1)
*/
#include <bits/stdc++.h>

using namespace std;

#define ll           long long int
#define mp           make_pair
#define pb           push_back
#define fi           first
#define si           second
#define fastIO       ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F(a,n)       for(int i=0;i<n;i++){cin>>a[i];}
#define F1(a,n)      for(int i=1;i<=n;i++){cin>>a[i];}
#define P(a,n)       for(int i=0;i<n;i++){cout<<a[i]<<' ';}cout<<endl;
#define P1(a,n)      for(int i=1;i<=n;i++){cout<<a[i]<<' ';}cout<<endl;
#define NF(a,n,m)    for(int i=0;i<n;i++){for(int j=0;j<m;j++){cin>>a[i][j];}}
#define NF1(a,n,m)   for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cin>>a[i][j];}}
#define PNF(a,n,m)   for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;
#define PNF1(a,n,m)  for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;
const int nax = 1e7;
const int mod = 1e9+7;
int n;	

void func(int i, string s, char mx){
	//base case
	if(i == n-1){
		cout<<s<<endl;
		return;
	}
	//recursive case
	for(char t='a'; t <= (mx+1); t++){
		func(i+1, s + t, max(t, mx));
	}
}

int main(){
fastIO
	cin>>n;
	string s = "a";
	if(n == 1){cout<<s;return 0;}
	func(0, s, 'a');
}

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

int main(){
  
  string S;
  cin >> S;
  
  int N = (int)S.size();
  int reds = 0;
  int blues = 0;
  for (int i = 0; i < N; i++) {
    if(S[i]=='0') reds++;
    else blues++;
  }
  
  cout << min(reds,blues)*2 << endl;
  
  return 0;
}


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

int main() {
	int n, cnt = 0;
	string s;
	cin >> n >> s;
	for (int i = 0; i < s.size() - 2; i++) {
		if (s.substr(i, 3) == "ABC")
			cnt++;
	}
	cout << cnt << endl;
	return 0;
}



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

int n,k,h[200010];

signed main()
{
	ios::sync_with_stdio(false);
	cin>>n>>k;
	if(k>=n){
		cout<<0<<endl;
		return 0;
	}
	for(int i=1;i<=n;i++) cin>>h[i];
	sort(h+1,h+n+1);
	reverse(h+1,h+n+1);
	int sum=0;
	for(int i=k+1;i<=n;i++){
		sum+=h[i];
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 1792