akhauriyash/Code-Regression huggingface dataset:
//Δ
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 4444;
const int MO = 1e9+7;
int n,m,k,f[N][N];
int main()
{
	int i,j,x;
	cin>>n>>m>>k;
	k--;
	n=(n+m-1)/k;
	f[0][0]=1;
	for(i=1;i<=n;i=i+1){
		x=0;
		for(j=0;j<=m;j=j+1){
			x=(x+f[i-1][j])%MO;
			if(j>k)
				x=(x-f[i-1][j-k-1]+MO)%MO;
			f[i][j]=x;
		}
	}
	x=0;
	while(n>0&&m>0){
		x=(x+f[n][m])%MO;
		n--,m-=k;
	}
	cout<<x;
	return 0;
}

Measured memory_bytes: 69248
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 998244353;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n;
	cin >> n;
	vector<string> a(n);
	vector<vector<int>> cntr(n, vector<int>(26));
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		for (char c : a[i]) {
			++cntr[i][c - 'a'];
		}
	}
	map<vector<int>, int> mp;
	ll answer = 0;
	for (int i = 0; i < n; ++i) {
		answer += mp[cntr[i]];
		++mp[cntr[i]];
	}
	cout << answer << '\n';
 	return 0;
}


Measured memory_bytes: 37760
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i,h) cin >> s[i];

    vector<vector<bool>> visited(h, vector<bool>(w));
    ll ans = 0;
    rep(i,h) rep(j,w){
        if (visited[i][j]) continue;
        if (s[i][j] == '.') continue;
        queue<P> q;
        q.push(P(j, i));
        visited[i][j] = true;
        ll cnt = 1, b = 1;
        while(!q.empty()){
            P p = q.front(); q.pop();
            int sx = p.first, sy = p.second;
            bool isWhite;
            if (s[sy][sx] == '.') isWhite = true;
            else isWhite = false;
            for(int i = 0; i < 4; i++){
                int x = sx + dx[i], y = sy + dy[i];
                if (x < 0 || x == w || y < 0 || y == h) continue;
                if (visited[y][x]) continue;
                if (isWhite){
                    if (s[y][x] == '#'){
                        q.push(P(x, y));
                        visited[y][x] = true;
                        cnt++;
                        b++;
                    }
                }else{
                    if (s[y][x] == '.'){
                        q.push(P(x, y));
                        visited[y][x] = true;
                        cnt++;
                    }
                }
            }
        }
        ans += b * (cnt - b);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
 
int main(void){
  int N;
  cin >> N;
  vector<string> s(N);
  string temp;
  long long ans= 0, count = 0;
  for(int i = 0; i < N; i++){
    cin >> temp;
    sort(temp.begin(), temp.end());
    s[i] = temp;    
  }
  sort(s.begin(), s.end());
  for(int i = 1; i < N; i++){
    if(s[i - 1] ==  s[i]){
      count++;
      ans += count;
    }
    else count = 0;
  }
  cout << ans;
 return 0; 
}

Measured memory_bytes: 5760
S = input()[::-1]
P = [0]*(len(S)+1)
for i,j in enumerate((S)):
    P[i+1] = (P[i] + int(j)*pow(10,i,2019))%2019
 
dp = [0]*2019
for i in P:
    dp[i%2019] += 1
print(sum([i*(i-1)//2 for i in dp]))

Measured memory_bytes: 15992
#include<stdio.h>
int main(){

	int yama[10];
	int a, b,c;
	for (a = 0; a < 10; a++){

		scanf("%d", &yama[a]);

	}
	for (a = 0; a < 9; a++){
        
		for (b = 0; b < 9; b++){

			if (yama[b] < yama[b + 1]){

				c = yama[b];
				yama[b] = yama[b + 1];
				yama[b + 1] = c;
			}

		}

	}

	for (a = 0; a < 3; a++){

		printf("%d\n", yama[a]);

	}

	return 0;
}

Measured memory_bytes: 1028
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

constexpr ll infl = 10000000000000000LL;
constexpr int inf = 1000000000;

/*
    nCk, nPk, 累乗, 階乗をmodをとりつつ求めるライブラリ
    MaxNが大きすぎるとCEが出る、またはWJが長い問題あり
*/
template <int MaxN = 100000, long long mod = 1000000007LL>
class Modlib {
    long long _fact[MaxN + 1];
    long long _fact_inv[MaxN + 1];

public:
    // x^n
    long long pow(long long x, long long n) const {
        long long ret = 1LL;
        long long t = x % mod;
        while (n > 0) {
            if (n & 1LL) {
                ret *= t;
                ret %= mod;
            }
            t *= t;
            t %= mod;
            n >>= 1;
        }
        return ret;
    }
    // xの逆元
    // https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a
    constexpr long long inv(long long a) const {
        long long b = mod, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b;
            a ^= b;
            b ^= a;
            a ^= b;

            u -= t * v;
            u ^= v;
            v ^= u;
            u ^= v;
        }
        u %= mod;
        if (u < 0)
            u += mod;
        return u;
    }
    // n!
    long long fact(long long n) const {
        return _fact[n];
    }
    // nPk
    long long perm(long long n, long long k) const {
        return fact(n) * _fact_inv[n - k] % mod;
    }
    // nCk
    long long comb(long long n, long long k) const {
        return perm(n, k) * _fact_inv[k] % mod;
    }

    constexpr Modlib() : _fact{}, _fact_inv{} {
        _fact[0] = _fact[1] = 1LL;
        for (int i = 2; i <= MaxN; ++i) {
            _fact[i] = _fact[i - 1] * i % mod;
        }
        _fact_inv[MaxN] = inv(_fact[MaxN]);
        for (int i = MaxN - 1; i >= 0; --i) {
            _fact_inv[i] = _fact_inv[i + 1] * (i + 1) % mod;
        }
    }
};

constexpr auto ml = Modlib<200000, 1000000007LL>();

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

    vector<int> q;
    for (int div = 2; div <= sqrt(m) + 1; ++div) {
        int cnt = 0;
        while (m % div == 0) {
            ++cnt;
            m /= div;
        }
        if (cnt > 0)
            q.push_back(cnt);
    }

    if (m > 1)
        q.push_back(1);

    ll ans = 1;
    for (int k : q) {
        ans *= ml.comb(n + k - 1, k);
        ans %= 1000000007LL;
    }

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

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int n,k,i,a,b;
    scanf("%d%d",&n,&k);
    long long int x[n+5],time=0x3f3f3f3f,t,min;
    for(i=0; i<n; i++)
    {
        scanf("%lld",&x[i]);
    }

    for(i=0; i<=n-k; i++)
    {
        a=i;
        b=i+k-1;;
        t=abs(x[a]-x[b]);
        if(abs(x[a])<abs(x[b]))
            min=abs(x[a]);
        else
            min=abs(x[b]);
        //printf("%lld\n",t+min);
        if((t+min)<time)
            time=t+min;


    }
    printf("%lld",time);
}

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

int main(){
  int animal;
  int leg;
  int m;
  cin >> animal >> leg;
  for(int i=animal; i>-1; i--){
    m=animal-i;
    if(leg==4*i+2*m){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

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

int main() {
    int A, B;
    cin >> A >> B;

    if (A > 0 && A <= B) {
        cout << B - A << endl;
    }
    else if (A > 0 && B > 0 && A > B) {
        cout << A - B + 2 << endl;
    }
    else if (A > 0 && B < 0) {
        cout << abs(A - abs(B)) + 1 << endl;
    }
    else if (A < 0 && B > 0) {
        cout << abs(abs(A) - B) + 1 << endl;
    }
    else if (A < 0 && B < 0 && A <= B) {
        cout << B - A << endl;
    }
    else if (A < 0 && A > B) {
        cout << A - B + 2 << endl;
    }
    else if (A == 0 && B > 0) {
        cout << B - A << endl;
    }
    else if (A == 0 && B < 0) {
        cout << A - B + 1 << endl;
    }
    else if (A > 0 && B == 0) {
        cout << A - B + 1 << endl;
    }
    else if (A < 0 && B == 0) {
        cout << B - A << endl;
    }
    else {
        cout << 0 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
  #include "_DEBUG.hpp"
#endif
#define int long long
const int INF = 1LL << 60;

signed main(){

  int n, m, k; cin >> n >> m >> k;
  vector<int> a(n), b(m);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  for(int i = 0; i < m; i++){
    cin >> b[i];
  }
  
  vector<int> imosA(n+1, 0), imosB(m+1, 0);
  for(int i = 0; i < n; i++){
    imosA[i+1] = imosA[i] + a[i];
  }
  for(int i = 0; i < m; i++){
    imosB[i+1] = imosB[i] + b[i];
  }

  int ans = 0;
  for(int i = 0; i <= n; i++){
    int sum = imosA[i];
    if(sum > k) continue;
    int pos = upper_bound(imosB.begin(), imosB.end(), k - sum) - imosB.begin();
    ans = max(ans, i + pos - 1);
  }
  cout << ans << endl;

  return 0;
}

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

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
	#define lcout(a) cout << a;
	#define lcoutln(a) cout << a << endl;
	#define lcerr(a) cerr << a;
	#define lcerrln(a) cerr << a << endl;
#else
	#define lcout(a) 
	#define lcoutln(a) 
	#define lcerr(a) 
	#define lcerrln(a) 
#endif

double x[100];
double y[100];
double gx, gy;

int main()
{
	int N;
	cin >> N;
	if (N % 2) {
		cout << "NA" << endl;
		return 0;
	}
	rep(i, N) {
		cin >> x[i] >> y[i];
		gx += x[i];
		gy += y[i];
	}
	gx = gx / N;
	gy = gy / N;
	rep(i, N) {
		x[i] -= gx;
		y[i] -= gy;
	}
	rep(i, N/2) {
		if (x[i] != -x[i+N/2] || y[i] != -y[i+N/2]) {
			cout << "NA" << endl;
			return 0;
		}
	}
	cout << fixed << setprecision(12) << gx << " " << gy << endl;
}


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

long long N;
map<long long, long long> bpos;
map<long long, long long> ab_map;
vector<long long> A;
vector<long long> B;


// 素集合データ構造
struct UnionFind
{
	// par[i]：データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである
	vector<int> par;
	// sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
	vector<int> sizes;

	UnionFind(int n) : par(n), sizes(n, 1) {
		// 最初は全てのデータiがグループiに存在するものとして初期化
		for(int i = 0; i < n; i++){
			par[i] = i;
		}
	}

	// データxが属する木の根を得る
	int find(int x) {
		if (x == par[x]) return x;
		return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
	}

	// 2つのデータx, yが属する木をマージする
	void unite(int x, int y) {
		// データの根ノードを得る
		x = find(x);
		y = find(y);

		// 既に同じ木に属しているならマージしない
		if (x == y) return;

		// xの木がyの木より大きくなるようにする
		if (sizes[x] < sizes[y]) swap(x, y);

		// xがyの親になるように連結する
		par[y] = x;
		sizes[x] += sizes[y];
		// sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
	}

	// 2つのデータx, yが属する木が同じならtrueを返す
	bool same(int x, int y) {
		return find(x) == find(y);
	}

	// データxが含まれる木の大きさを返す
	int size(int x) {
		return sizes[find(x)];
	}
};



int main(){
	cin >> N;

	for(long long i = 0; i < N; i++){
		long long a;
		cin >> a;
		A.push_back(a);
	}

	for(long long i = 0; i < N; i++){
		long long b;
		cin >> b;
		B.push_back(b);
		bpos[b] = i;
	}

	for(long long i = 0; i < N; i++){
		ab_map[A[i]] = B[i];
	}

	sort(A.begin(), A.end());
	sort(B.begin(), B.end());

	for(long long i = 0; i < N; i++){
		if(A[i] > B[i]){
			cout << "No" << endl;
			return 0;
		}
	}


	UnionFind uf(100009);
	for(long long i = 0; i < N; i++){
		long long a = A[i];
		long long b = B[i];
		long long pair_b = ab_map[a];
		uf.unite(bpos[b], bpos[pair_b]);
	}


	set<long long> bset;
	for(long long i = 0; i < N; i++){
		bset.insert(uf.find(bpos[B[i]]));
	}

	if(bset.size() != 1){
		cout << "Yes" << endl;
		return 0;
	}

	for(long long i = 0; i < N-1; i++){
		if(A[i + 1] <= B[i]){
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 15092
#include <stdio.h>
#include <math.h>
#define ll long long int

int main(void) {
    ll n, min = 1000000000000;
    scanf("%lld", &n);
    for(ll i = 1; i <= (ll)sqrt(n); i++) {
        if(n%i == 0) {
            if(min > i + n/i - 2) min = i + n/i - 2;
        }
    }
    printf("%lld\n", min);
    return 0;
}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf = 1LL<<60;
const int mod = 1e9 + 7;
const double eps = 1e-9;

/*{
  }*/

int n, a[1000][1000];
vector<pii> es[1000][1000];
int h[1000][1000];

signed main(){
  cin >> n;
  rep(i, 0, n) rep(j, 0, n-1){
    cin >> a[i][j];
    a[i][j]--;
  }

  rep(i, 0, n) rep(j, 1, n-1){
    int u = i, v = a[i][j-1];
    if(u > v) swap(u, v);
    int x = i, y = a[i][j];
    if(x > y) swap(x, y);
    es[u][v].emplace_back(x, y);
    h[x][y]++;
  }

  queue<pii> st;
  rep(i, 0, n) rep(j, i+1, n){
    if(h[i][j] == 0) st.push({i, j});
  }

  vector<pii> ans;
  while(st.size()){
    int u = st.front().first, v = st.front().second;
    st.pop();
    ans.emplace_back(u, v);
    for(auto& e : es[u][v]){
      int x = e.first, y = e.second;
      h[x][y]--;
      if(h[x][y] == 0) st.push({x, y});
    }
  }

  if(sz(ans) == n*(n-1)/2){
    int tmp = 0;
    vector<bool> used(n);
    for(auto& i : ans){
      int u = i.first, v = i.second;
      if(used[u] or used[v]){
        used.assign(n, false);
        tmp++;
      }
      used[u] = used[v] = true;
    }
    cout << tmp+1 << endl;
  }else{
    cout << -1 << endl;
  }

  return 0;
}



Measured memory_bytes: 74604
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>

#define INF 1e9
#define nmax 1000010
#define fst first
#define snd second
#define pb push_back
#define SZ(x) ((int)(x.size()))

#define MOD1 998244353
#define MOD2 666013
#define P1 255
#define P2 2059

using namespace std;

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

int n, q;
deque<char> deq;

string s;

int main()
{
    cin >> s;

    for (int i = 0; i < SZ(s); i++) deq.push_back(s[i]);

    cin >> q;

    bool how_a = true;

    while (q--) {

        int type;

        scanf("%d", &type);

        if (type == 1) how_a = how_a ^ true; else
        {
            int f; char c;

            scanf("%d %c", &f, &c);

            if (f == 1) {

                if (how_a) deq.push_front(c); else
                    deq.push_back(c);
            }
            else
            {
                if (how_a) deq.push_back(c); else
                    deq.push_front(c);
            }
        }
    }

    if (how_a) {

        while (!deq.empty()) { printf("%c", deq.front()); deq.pop_front(); }
        
        printf("\n");
    }
    else
    {
        while (!deq.empty()) { printf("%c", deq.back()); deq.pop_back(); }

        printf("\n");
    }

    // IMPORTANT!!!!!
    // Are you missing something????
    // check limits, int or ll

    return 0;
}

Measured memory_bytes: 896
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!{
        x: isize,
        k: usize,
        d: isize
    }

    let px = x.abs() % d;
    let dx = x.abs() / d;

    if dx <= k as isize {
        let nokori = k as isize - dx;
        let modk = nokori % 2;
        if modk == 1 {
            println!("{}", d - px)
        } else {
            println!("{}", px);
        }

    } else {
        println!("{}", x.abs() - k as isize * d);
    }
}


Measured memory_bytes: 2200
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int PA, PZ;
  for (int i =0; i < S.size() ; i++){
    if(S.at(i) == 'A'){
      PA = i;
      break;
    }
  }
  for (int i = S.size()-1 ; i > PA ; i--){
    if(S.at(i) == 'Z'){
      PZ = i;
      break;
    }
  }
    
  cout << PZ - PA + 1 << endl;
}


Measured memory_bytes: 3624
a,b,c,d = map(int,input().split())
ok = False
dist = abs(a-c)
if dist <= d: ok = True
else:
    d1 = abs(a-b)
    d2 = abs(b-c)
    if d1 <= d and d2 <= d: ok = True
if ok: print('Yes')
else: print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
#define F first
#define S second

int n;
vector<P>v[100009];
vector<P>ANS;
int ans=-1;

void dfs(int now,int pre,int col){
	int cur=1;
	r(i,v[now].size()){
		P nex=v[now][i];
		if(cur==col)cur++;
		if(nex.F==pre)continue;
		ANS.push_back(P(nex.S,cur));
		dfs(nex.F,now,cur);
		cur++;
	}
}

int main(){
	cin>>n;
	r(i,n-1){
		int a,b;
		cin>>a>>b; a--; b--;
		v[a].push_back(P(b,i));
		v[b].push_back(P(a,i));
	}
	r(i,n){
		ans=max(ans,(int)v[i].size());
	}
	dfs(0,-1,-1);
	cout<<ans<<endl;
	sort(ANS.begin(),ANS.end());
	r(i,(int)ANS.size()){
		cout<<ANS[i].second<<endl;
	}
}

Measured memory_bytes: 10616
def main():
    n = int(input())
    p = [int(x) for x in input().split()]
    ans = 0
    for i in range(1, n - 1):
        a = [p[i - 1], p[i], p[i + 1]]
        if p[i] != max(a) and p[i] != min(a):
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include<bitset>
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, a, n) for(int i=(a);i<(int)(n);i++)
#define repc(i, a, n) for(int i=(a);i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
#define DBG(str) cerr<<(str)<<endl;
int main() {
	int n;
	cin >> n;
	vector<int>a(n + 1, n + 1);
	vector<int>six(n + 1, 6);
	rep(i, 1, n) {
		six[i] = six[i - 1] * 6;
	}
	vector<int>nine(n + 1, 9);
	rep(i, 1, n) {
		nine[i] = nine[i - 1] * 9;
	}
	a[0] = 0;
	a[1] = 1;
	rep(i, 2, n+1) {
		a[i] = a[i - 1] + 1;
		rep(j, 0, n) {
			if (i - six[j] < 0)break;
			a[i] = min(a[i], a[i - six[j]] + 1);
		}
		rep(j, 0, n) {
			if (i - nine[j] < 0)break;
			a[i] = min(a[i], a[i - nine[j]] + 1);
		}
	}
	cout << a[n];

	return 0;
}








Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
    int a,b,c,x;cin>>a>>b>>c>>x;
    int ans=0;
    rep(i,a+1)rep(j,b+1){
        int tmp=x-500*i-100*j;
        if(tmp>=0&&tmp%50==0&&tmp/50<=c)ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
/*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int ll;
const int mod = 1e9 + 7;
ll powmod(ll a, ll b) {
    ll res = 1;
    a %= mod;
    assert(b >= 0);
    for (; b; b >>= 1) {
        if (b & 1) res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}
int nxt() {
    int x;
    scanf("%d", &x);
    return x;
}

const int nax = 1e5 + 5;
VI edges[nax];

int mul(int a, int b) {
    return (ll)a * b % mod;
}

// returns a pair (black, white)
PII dfs(int a, int parent) {
    int all_white = 1;
    int sth_is_black = 0;
    for (int b : edges[a]) {
        if (b != parent) {
            // p.first is the number of ways to color the subtree such that 'b' is black
            PII p = dfs(b, a);
            int memo_all_white = all_white;
            all_white = mul(all_white, p.second);
            sth_is_black = (mul(memo_all_white, p.first) +
                            mul(sth_is_black, (p.first + p.second))) %
                           mod;
        }
    }
    return {all_white, (all_white + sth_is_black) % mod};
}

int main() {
    int n = nxt();
    REP(i, n - 1) {
        int a = nxt(), b = nxt();
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    PII p = dfs(1, -1);
    int answer = (p.first + p.second) % mod;
    printf("%d\n", answer);
    return 0;
}


Measured memory_bytes: 16144
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <cctype>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define du(x) cout<<#x<<'='<<x<<endl
#define du2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define du3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf();

int main() {

    int A, B;
    cin >> A >> B;
    cout << (A - 1)*(B - 1) << endl;
}

Measured memory_bytes: 768
function bomb(y,x){
   var dy=[0,0,-1,1];
   var dx=[-1,1,0,0];
   for(var i=0;i<4;i++){
      var yy=y+dy[i];
      var xx=x+dx[i];
      if(yy<0 || yy>=12 || xx<0 || xx>=12)continue;
      if(yx[yy][xx]=="a"){yx[yy][xx]=cnt;bomb(yy,xx);}
   }
}

var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var n=0;
var cnt=0;
var yx=[];
for(var I=0;I<Arr.length;I++){
   n++;
   var v=Arr[I].replace(/1/g,"a");
   var arr=v.split("");
   yx.push(arr);
   if(n!=12)continue;
   cnt=0;
   for(var i=0;i<12;i++){
      for(var j=0;j<12;j++){
         if(yx[i][j]=="a"){cnt++;yx[i][j]=cnt;bomb(i,j);}
      }
   }
   console.log(cnt);
   n=0;
   yx=[];
   I++;
}

Measured memory_bytes: 8680
h, w = map(int, input().split())
d = [list(map(int, input().split())) for _ in range(10)]
A = [list(map(int, input().split())) for _ in range(h)]

def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(10):
        for i in range(10):
            for j in range(10):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

d = warshall_floyd(d)
ans = 0
for i in range(h):
    for j in range(w):
        if A[i][j] not in [-1, 1]:
            ans += d[A[i][j]][1]


print(ans)

Measured memory_bytes: 40924
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int a;
    cin >> a;
    cout << a + pow(a,2) + pow(a,3) << endl;
    return 0;
}

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

int H, W, K;

void update(vector<vector<int>> &B) {
    vector<vector<int>> A(H);
    rep(i, H) {
        rep(j, W) if(B[i][j]) A[i].push_back(B[i][j]);
        while(A[i].size() < W) A[i].push_back(0);
    }
    swap(A, B);
}

int eval(vector<vector<int>> &B) {
    int res = 0;
    vector<vector<int>> A(B);
    rep(j, W) rep(i, H) {
        int cnt = 0, ni = i;
        if(B[i][j] == 0) continue;
        while(ni < H && B[i][j] == B[ni][j]) cnt++, ni++;
        if(cnt >= K) {
            for(int pos = i; pos < ni; ++pos) {
                A[pos][j] = 0;
                res += B[pos][j];
            }
        }
        i = ni - 1;
    }
    swap(A, B);
    return res;
}

int solve(vector<vector<int>> B, int i, int j) {
    int res = 0, score = 0, k = 1;
    B[i][j] = 0;
    do {
        update(B);
        score = k * eval(B);
        res += score;
        k *= 2;
    } while(score);
    return res;
}

int main() {
    cin >> H >> W >> K;
    vector<vector<char>> C(H, vector<char>(W));
    vector<vector<int>> B(W, vector<int>(H));
    rep(i, H) rep(j, W) cin >> C[i][j];
    rep(i, H) rep(j, W) B[j][H - i-  1] = C[i][j] - '0';
    swap(H, W);
    int ans = 0;
    rep(i, H) rep(j, W) ans = max(ans, solve(B, i, j));
    cout << ans << '\n';
    return 0;
}


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

char str[1000002];
int solve(int n){
	int m;
	scanf("%d%s", &m, str);
	int t = -1, cnt = 0, ans = 0;
	for(int i = 0;i < m;i++){
		if(t == 1 && str[i] == 'I'){
			t = 0;
			cnt++;
			//printf("%d %d\n", cnt, i);
			if(cnt >= n)ans++;
		}else if(str[i] == 'I'){
			t = 0;
			cnt = 0;
		}else if(t == 0 && str[i] == 'O'){
			t = 1;
		}else{
			t = -1;
			cnt = 0;
		}
	}
	return ans;
}

int main(){
	int n;
	while(1){
		scanf("%d", &n);
		if(n == 0)break;
		int ans = solve(n);
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 4128
from collections import Counter
n, p = map(int, input().split())
l = []
for i in range(2, int((p**0.5)) + 2):
    while p%i == 0:
        p //= i
        l.append(i)
l.append(p)
d = Counter(l)
key = list(d.keys())
ans = 1
for k in key:
    if d[k] >= n:
        ans *= k**(d[k]//n)

print(ans)

Measured memory_bytes: 66508
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
string s;int f[30];bool flag=1;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>s;
	for(int i=0;i<s.size();i++)
	f[s[i]-96]++;
	for(int i=1;i<=26;i++){
		if(f[i]%2!=0){
			flag=0;break;
		}
	}
	if(flag)printf("Yes\n");
	else printf("No\n");
	return 0;
}


Measured memory_bytes: 256
n = int(input())
p = list(map(int, input().split()))
num = 0
for i in range(0,n-2,1):
    i2 = i+1
    i3 = i+2
    if p[i]<p[i2]<p[i3] or p[i]>p[i2]>p[i3]:
        num += 1
print(num)

Measured memory_bytes: 8900
#include <bits/stdc++.h>
#include<iostream>
using namespace std;
 
int main() {
  string s,t;
  cin >> s >> t;
  int ans(0);
  for(int i = 0;i < 3;i++){
  	if(s.at(i) == t.at(i)){
    	ans++;
    }
  }
   cout << ans;
}
   


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int, int>
#define ld long double
const int mod = 1e9 + 7;
 
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
 
 
 
 
 int bin(multiset<int>&s)
 {

	 
	 int l=0,r=s.size()-1,mid,ans=1;
	 while(l<=r)
	 {
		 mid=(l+r)/2;
		 auto k =s.begin();
	   	advance(k,mid);
		 if(*k>=s.size()-mid)
		 { 
			 ans=s.size()-mid; r=mid-1;
		 }
		 else l=mid+1;
	 }
	 return ans;
 }
 
 
 
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
 


int n;
cin>>n;

vector<pii>v(n);

for(int i=0;i<n;i++)
{
	cin>>v[i].first>>v[i].second;
}

double ans=0;

for(int i=0;i<n;i++)
{
	for(int j=i+1;j<n;j++)
	{
		ans+=pow(pow(v[i].first-v[j].first,2) + pow(v[i].second-v[j].second,2) ,0.5)*2.0/n;
	}
}
cout<<setprecision(12)<<ans<<"\n";
 
 
}

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

int main() {
	string C1, C2;

	cin >> C1 >> C2;
	reverse(C2.begin(), C2.end());

	string result = (C1 == C2) ? "YES" : "NO";

	cout << result;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
using namespace std;
typedef struct node
{
	double x, y;
}NODE;
inline NODE Vector(NODE A, NODE B);  //向量AB
double cross(NODE A, NODE B, NODE P);
double dis2(NODE a, NODE b);
double disLine(NODE A, NODE B, NODE P);
double dot(NODE A, NODE B, NODE P);
NODE prxy(NODE A, NODE B, NODE O);
int main()
{
	NODE A, B, O;
	double r;
	int q;
	cin >> O.x >> O.y>>r;
	cin >> q;
	while (q--)
	{
		cin >> A.x >> A.y >> B.x >> B.y;
		NODE pr = prxy(A, B, O);
		double base = sqrt(r*r - disLine(A, B, O)*disLine(A, B, O));
		NODE AB = Vector(A, B);
		NODE e = { AB.x / sqrt(dis2(A, B)), AB.y / sqrt(dis2(A, B)) };
		NODE Base = { e.x*base, e.y*base };
		NODE x1 = { Base.x + pr.x, Base.y + pr.y };
		NODE x2 = { pr.x - Base.x, pr.y - Base.y };
		if (x1.x<x2.x)
			//cout << x1.x << ' ' << x1.y << ' ' << x2.x << ' ' << x2.y << endl;
			printf("%.6lf %.6lf %.6lf %.6lf\n",x1.x,x1.y,x2.x,x2.y);
		else if (x1.x>x2.x)
			//cout << x2.x << ' ' << x2.y << ' ' << x1.x << ' ' << x1.y << endl;
			printf("%.6lf %.6lf %.6lf %.6lf\n", x2.x, x2.y, x1.x, x1.y);
		else if (x1.x == x2.x)
		{
			if (x1.y < x2.y)
				//cout << x1.x << ' ' << x1.y << ' ' << x2.x << ' ' << x2.y << endl;
				printf("%.6lf %.6lf %.6lf %.6lf\n", x1.x, x1.y, x2.x, x2.y);
			else
				//cout << x2.x << ' ' << x2.y << ' ' << x1.x << ' ' << x1.y << endl;
				printf("%.6lf %.6lf %.6lf %.6lf\n", x2.x, x2.y, x1.x, x1.y);
		}
	}
	return 0;
}

NODE prxy(NODE A,NODE B,NODE O)
{
	NODE AO = Vector(A, O);
	NODE AB = Vector(A, B);
	double l = dot(A, B, O) / sqrt(dis2(A, B));
	NODE e = { AB.x / sqrt(dis2(A, B)), AB.y / sqrt(dis2(A, B)) };
	NODE Apr = { e.x*l, e.y*l };
	return{ A.x + Apr.x, A.y + Apr.y };
}
double disLine(NODE A, NODE B, NODE P)
{
	return fabs(cross(A,B,P))/sqrt(dis2(A,B));
}
double dot(NODE A, NODE B, NODE P)
{
	NODE AB = Vector(A, B);
	NODE AP = Vector(A, P);
	return AB.x*AP.x + AB.y*AP.y;
}
double dis2(NODE a, NODE b)
{
	return (b.x - a.x)*(b.x - a.x) + (b.y - a.y)*(b.y - a.y);
}
double cross(NODE A, NODE B, NODE P)
{
	NODE AB = Vector(A, B);
	NODE AP = Vector(A, P);
	return AB.x*AP.y - AB.y*AP.x;
}
inline NODE Vector(NODE A, NODE B)
{
	return{ B.x - A.x, B.y - A.y };
}


Measured memory_bytes: 3224
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>

using namespace std;

void solution()
{
    int n;
    string s, t;
    cin >> n >> s >> t;
    for (int i = 0; i < n; ++i)
    {
        cout << s[i] << t[i];
    }
    cout << '\n';
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solution();
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S1 = sc.next();
    String S2 = sc.next();
    if (S1.charAt(0) == S2.charAt(2) && S1.charAt(1) == S2.charAt(1) && S1.charAt(2) == S2.charAt(0) ) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 22868
using System;

namespace ABC166B
{
    class Program
    {
        static void Main(string[] args)
        {
            var aa = Console.ReadLine().Split(" ");
            int n = int.Parse(aa[0]);
            int k = int.Parse(aa[1]);
           int[] sunuke = new int[n];
            int f;

            for (int i = 1; i <= k; i++)
            {

                int d = int.Parse(Console.ReadLine());
                var bb = Console.ReadLine().Split(" ");
                for(int j =0;j<d;j++)
                {
                    f = int.Parse(bb[j]);
                        sunuke[f-1]++;
                }
            }

            int x = 0;
            for(int i =0;i<n;i++)
            {
                if (sunuke[i] == 0)
                    x++;
            }

            Console.WriteLine(x);
        }
    }
}


Measured memory_bytes: 18296
#include <iostream>

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    long long h[N];
    for(int i = 0; i < N; i++){
        cin >> h[i];
    }

    // 足場 0 ~ N-1
    long long dp[N]; // dp[i] := 足場i番目までの最小コスト
    // for(int i = 0; i < N; i++){
    //     dp[i] = __LONG_LONG_MAX__; // 十分大きな値で初期化
    // }
    dp[0] = 0; // 足場 0
    dp[1] = abs(h[1]-h[0]); // 足場 1
    for(int i = 2; i < N; i++){
        dp[i] = dp[i-1]+abs(h[i]-h[i-1]);
        for(int j = 2; (j <= K && i-j >= 0); j++){
            dp[i] = min(dp[i], dp[i-j]+abs(h[i]-h[i-j]));
        }
    }

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


    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    ll a,b;
    cin >> a >> b;
    ll i = 2;
    set<ll> st;
    for (; i * i <= a; i++)
    {
        if(a%i==0){
            st.insert(i);
        }
        while(a%i==0){
            a /= i;
            st.insert(i);
        }
    }
    if(a!=1)st.insert(a);
    set<ll> st2;
    i = 2;
    for (; i * i <= b; i++)
    {
        if (b % i == 0)
        {
            st2.insert(i);
        }
        while (b % i == 0)
        {
            b /= i;
            st2.insert(i);
        }
    }
    if (b != 1)
        st2.insert(b);
    ll ans = 1;
    for (auto e : st)
    {
        if(st2.find(e)!=st2.end()){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000000
using namespace std;
using ll = long long;
int main()
{
    int a,b;
    cin >> a >> b;
    int x = a + b;
    cout << (x + 1) / 2 << endl;
}


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

int main() {
  int n;
  cin >> n;
  int cnt2 = 0, cnt4 = 0;
  rep(i,n) {
    int a;
    cin >> a;
    if (a % 4 == 0) ++cnt4;
    else if (a % 2 == 0) ++cnt2;
  }

  if (n - cnt2 <= cnt4 * 2) cout << "Yes" << endl;
  else if (cnt4 >= n / 2) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3588
n=int(input())
p=list(map(int, input().split()))

cnt=0
for i in range(1,len(p)-1):
    small = 1
    if p[i]>p[i-1]:
        small+=1
    if p[i]>p[i+1]:
        small+=1
    if small==2:
        cnt+=1
        
print(cnt)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
const int N = 3e3+5;
double dp[N][N],a[N];
int mark[N][N];
double play(int now,int head){
    if(head < 0)   return 0;
    if(now == 0)    return (head == 0);
    if(mark[now][head]) return dp[now][head];
    mark[now][head] = 1;
    return dp[now][head] = (a[now]*play(now-1,head-1))+(1.0-a[now])*(play(now-1,head));
}
int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)    scanf("%lf",&a[i]);
    double ans = 0;
    for(int i=0;i<=n;i++){
        int tail = n-i;
        if(i>tail)  ans+=play(n,i);
    }
    printf("%.9lf\n",ans);
    return 0;
}


Measured memory_bytes: 105728
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<stack>
#include<cmath>
#include<cstring>
using namespace std;
#define MAXN 500
#define LL long long
#define INF 1000000000000000000
int n;
LL sum[2][MAXN+5][MAXN+5],dp[MAXN+5][MAXN+5];
LL read(){
   	LL x=0,F=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
   	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
    return x*F;
}
LL get_sum(int x1,int x2,int y1,int y2,int id){
	return sum[id][x2][y2]-sum[id][x1-1][y2]-sum[id][x2][y1-1]+sum[id][x1-1][y1-1];
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
		if(i!=j)sum[(i>j)][i][j]=read();
	for(int i=0;i<=n;i++)
		for(int j=0;j<=n;j++)dp[i][j]=INF;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++){
			sum[0][i][j]+=sum[0][i-1][j]+sum[0][i][j-1]-sum[0][i-1][j-1];
			sum[1][i][j]+=sum[1][i-1][j]+sum[1][i][j-1]-sum[1][i-1][j-1];
		}
	dp[0][0]=0; 
	for(int i=0;i<=n;i++)
		for(int pre=0;pre<max(1,i);pre++)
			for(int nxt=i+1;nxt<=n;nxt++)
			dp[nxt][i]=min(dp[nxt][i],dp[i][pre]+get_sum(nxt+1,n,pre+1,i,1)+get_sum(i+1,nxt,i+1,nxt,0));
	LL ans=dp[n][1];
	for(int i=1;i<=n;i++)ans=min(ans,dp[n][i]);
	printf("%lld",ans);
}

Measured memory_bytes: 6272
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<climits>
#include<map>
#define ll long long
using namespace std;
int main() {
	ll n;
	cin >> n;
	vector<ll>l(n+1);
	l[0] = 2;
	l[1] = 1;
	for (ll i = 2; i <= n; i++) {
		l[i] = l[i - 1] + l[i - 2];
	}
	cout << l[n] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
#define EPS (1e-8)
#define equals(a,b) (fabs((a)-(b))<EPS)
class Point{
  public:
  double x,y;
  Point(double x=0,double y=0):x(x),y(y){}
  Point operator + (Point p){return Point(x+p.x,y+p.y);}
  Point operator - (Point p){return Point(x-p.x,y-p.y);}
};
struct seg{Point p1,p2;};
double norm(Point p){return p.x*p.x+p.y*p.y;}
double abs(Point p){return sqrt(norm(p));}
double dot(Point a,Point b){return a.x*b.x+a.y*b.y;}
double cross(Point a,Point b){return a.x*b.y-a.y*b.x;}
double getDistancePP(Point a,Point b){return abs(a-b);}
double getDistanceLP(seg l,Point p){return abs(cross(l.p2-l.p1,p-l.p1)/abs(l.p2-l.p1));}
double getDistanceSP(seg s,Point p){
  if(dot(s.p2-s.p1,p-s.p1)<0.0)return abs(p-s.p1);
  if(dot(s.p1-s.p2,p-s.p2)<0.0)return abs(p-s.p2);
  return getDistanceLP(s,p);
}
int n,m,c=1,pre,fro,p,t;
Point a[5001];
seg w;
bool vis[5001];double d[5001];
double dd=1000000000,dis=0;
int main(){
  cin>>n>>m;n++;
  r(i,n)cin>>a[i].x>>a[i].y;
  r(i,n)d[i]=abs(a[0]-a[i]);
  vis[0]=1;
  seg w;w.p1=a[0];w.p2=a[p];
  while(m--&&(t=-1)){
    dd=10000000;c=0;
    r(i,n)if(!vis[i])if(t<0||d[i]<d[t])t=i;
    r(i,n)if(vis[i])if(abs(a[i]-a[t])<abs(a[c]-a[t]))c=i;
    w.p1=a[c];w.p2=a[t];
    dis+=abs(w.p1-w.p2);
    vis[t]=1;
    r(i,n)if(!vis[i])d[i]=min(d[i],getDistanceSP(w,a[i]));
  }
  printf("%.12f\n",dis);
}

Measured memory_bytes: 3396
// IlyM

#include <bits/stdc++.h>
#define pb push_back
#define sp " "
#define sl "\n"
#define fi first
#define se second
#define mp make_pair
#define sz(a) ((int)a.size())
#define tra(a,b) for (auto a:b) 
#define fo(a,b,c) for (int a=b;a<=c;a++) 
#define ms(a,b) memset(a,b,sizeof(a)) 
#define all(a) a.begin(),a.end()
#define rev(a) reverse(a.begin(),a.end())
#define bit(i,j) (i&(1<<j))

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef pair<int,ii> iii;

const int N=2e5+5,mod=998244353;
ll n,a,b;
int main()
{
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	cin>>n>>a; while (n) { n/=a; b++;
	}
	cout<<max(ll(1),b);
	return 0;
}


Measured memory_bytes: 256
from functools import lru_cache
import sys

sys.setrecursionlimit(10**8)

N = int(input())
ABC = [list(map(int, input().split(" "))) for _ in range(N)]

l = [[None for _ in range(3)] for _ in range(N+10)]
# @lru_cache(maxsize=None)
def dp(i, use):
    if i == -1:
        return 0
    if l[i][use] != None:
        return l[i][use]
    max_num = 0
    for k in range(3):
        if k == use:
            continue
        max_num = max(max_num, dp(i-1, k)+ABC[i][use])
    l[i][use] = max_num 
    return max_num

print(max(dp(N-1, m) for m in range(3)))


Measured memory_bytes: 129112
from scipy.sparse import*
e=enumerate
_,*s=open(0)
r=s+['#'*20]
*g,=eval('[0]*500,'*500)
for i,t in e(s):
 for j,u in e(t):k=i*20+j;g[k][k+1]=u>'#'<t[j+1];g[k][k+20]=u>'#'<r[i+1][j]  
a=csgraph.johnson(csr_matrix(g),0)
print(int(a[a<999].max()))

Measured memory_bytes: 20624
#include<bits/stdc++.h>
using namespace std;
vector<int>prime;
vector<bool>mark(2000550, true);
vector<int>factors[1000050], cnt(1000050, 0);;
void sieve(int n){
    int lim = sqrt(n);
    mark[1] = false;
    for(int i = 4; i <= n; i = i + 2){
        mark[i] = false;
    }
    prime.push_back(2);
    for(int i = 3; i <= n; i = i + 2){
        if(mark[i]){
            prime.push_back(i);
            if(i <= lim){
                for(int j = i * i; j <= n; j = j + 2 * i){
                    mark[j] = false;
                }
            }
        }
    }
}
int main(){
    sieve(2000000);
    for(int i = 0; prime[i] <= 1000000; i++){
        for(int j = prime[i]; j <= 1000000; j = j + prime[i]){
            factors[j].push_back(prime[i]);
        }
    }
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        int x;
        cin >> x;
        for(int j = 0; j < factors[x].size(); j++){
            cnt[factors[x][j]]++;
        }
    }
    int mx = 0;
    for(int i = 0; prime[i] <= 1000000; i++){
        mx = max(mx, cnt[prime[i]]);
    }
    if(mx <= 1){
        cout << "pairwise coprime";
    }
    else if(mx == n){
        cout << "not coprime";
    }
    else{
        cout << "setwise coprime";
    }
    return 0;
}

Measured memory_bytes: 63112
#include<bits/stdc++.h>
using namespace std;
#define pi pair<int, int>
int N;
int U, V;
vector<vector<int>> adj;
vector<int> par;
int main(){
  cin >> N; cin >> U >> V; U--; V--;
  adj = vector<vector<int>> (N);
  for(int i = 0; i < N - 1; i++){
    int a, b; cin >> a >> b; a--; b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  queue<pi> q; q.push({0, -1});
  par = vector<int> (N, -2);
  while(!q.empty()){
    pi curr = q.front(); q.pop();
    if(par[curr.first] != -2) continue;
    par[curr.first] = curr.second;
    for(int i = 0; i < adj[curr.first].size(); i++){
      q.push({adj[curr.first][i], curr.first});
    }
  }
  vector<int> dU (N, -1), commonAncestor (N, -1);
  q = queue<pi> (); q.push({U, 0});
  while(!q.empty()){
    pi curr = q.front(); q.pop();
    if(dU[curr.first] != -1) continue;
    dU[curr.first] = curr.second;
    for(int i = 0; i < adj[curr.first].size(); i++){
      q.push({adj[curr.first][i], curr.second + 1});
    }
  }
  q = queue<pi> (); q.push({U, U});
  while(!q.empty()){
    pi curr = q.front(); q.pop();
    if(commonAncestor[curr.first] != -1) continue;
    commonAncestor[curr.first] = curr.second;
    for(int i = 0; i < adj[curr.first].size(); i++){
      q.push({adj[curr.first][i], adj[curr.first][i] == par[curr.first] ? adj[curr.first][i] : curr.second});
    }
  }
  q = queue<pi> (); q.push({V, 0});
  vector<int> dV (N, -1);
  while(!q.empty()){
    pi curr = q.front(); q.pop();
    if(dV[curr.first] != -1) continue;
    dV[curr.first] = curr.second;
    for(int i = 0; i < adj[curr.first].size(); i++){
      q.push({adj[curr.first][i], curr.second + 1});
    }
  }
  vector<bool> isLeaf (N, true);
  for(int i = 1; i < N; i++){
    isLeaf[par[i]] = false;
  }
  int res = 0;
  for(int i = 0; i < N; i++){
    if(isLeaf[i]){
      int node = commonAncestor[i];
      if(dU[node] < dV[node]){
        int t = dV[i] - 1;
        res = max(res, t);
      }
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 7660
#include <stdio.h>
#include <stdlib.h>
 
int
main(int argc, char **argv)
{
  int m;
  int n;
  int num = 0;
  int rep = 0;
  int base;
  
  scanf("%d %d", &m, &n);

  if (m == 0 || n == 0) {
    printf("0\n");
    return (0);
  }
    
  if (m <= n) {
    base = m;
    rep = n;
  } else {
    base = n;
    rep = m;
  }
  
  num = base;
  for (m = 0; m < rep - 1; m++)
    num = num * 10 + base;
  
  printf("%d\n", num);
  return (0);
}
   


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

#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define dump(x)  cout << #x << " = " << (x) << endl;

typedef long long ll;
typedef pair<int, int> ii;
const int mod = 1e9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;

void solve()
{
  int n,k; cin>>n>>k;
  string s; cin>>s;

  vector<int> l;
  vector<int> r;
  l.push_back(0);
  r.push_back(0);
  char t='0';
  for (int i=0; i<n; i++) {
    if (t==s[i]) {
      t=s[i];
      continue;
    }
    if (s[i]=='0') {
      r.push_back(i);
    } else {
      l.push_back(i);
    }
    t=s[i];
  }
  l.push_back(n);
  r.push_back(n);
  if (SZ(r)<k+1) {
    cout << n << endl;
    return;
  }
  int ans = 0;
  for (int i=k-1; i<SZ(r); i++) {
    ans = max(ans, r[i]-l[i-k]);
  }
  cout << ans << endl;
}

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


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

#define whole(f, x, ...)                                 \
  ([&](decltype((x)) whole) {                            \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__); \
  })(x)

using namespace std;
using ll = long long;

void solve() {
  int n, k;
  cin >> n >> k;
  vector<bool> v(n + 1, false);
  for (int i = 0; i < k; i++) {
    int d;
    cin >> d;
    for (int i = 0; i < d; i++) {
      int a;
      cin >> a;
      v[a] = true;
    }
  }
  int cnt = 0;
  for (auto x : v) {
    if (x == false) {
      ++cnt;
    }
  }
  cout << cnt - 1 << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define N 100010
#define M 200010
using namespace std;

int n, m, l, r, d, en;
int head[N], ans[N];
struct Edge{
    int to, nxt, val;
}e[M << 1];
bool vis[N];
queue<int>q;

inline void add(int u, int v, int f)
{
    e[++en].to = v;
    e[en].val = f;
    e[en].nxt = head[u];
    head[u] = en;
}

void spfa(int x)
{
    while (!q.empty()) q.pop();
    q.push(x);
    vis[x] = 1;
    while (!q.empty()) {
        int now = q.front();
        q.pop();
        for (int i = head[now]; i; i = e[i].nxt) {
            if (ans[e[i].to] > ans[now] + e[i].val) {
                ans[e[i].to] = ans[now] + e[i].val;
                if (vis[e[i].to] == 0) {
                    q.push(e[i].to);
                    vis[e[i].to] = 1;
                } else {
                    puts("No");
                    exit(0);
                }
            }
        }
    }
}

int main()
{
    memset(ans, 0x3f, sizeof(ans));
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= m; ++i) {
        scanf("%d %d %d", &l, &r, &d);
        add(l, r, d), add(r, l, -d);
    }
    for (int i = 1; i <= n; ++i) {
        if (vis[i] == 1) continue;
        ans[i] = 0;
        spfa(i);
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 6272