akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;
 
ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}
 
ll mod(ll a, ll b) {return (a % b + b) % b;}
 
ll powerm(ll base,ll exp,ll mod) 
{ll ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}

using namespace std;

int main()
{
	fast;
	ld a,b; cin>>a>>b;
	ll ans = floor(a*b);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3744
import math

while True:
	n = int( raw_input() )
	if 0 == n:
		break
	s = [ float( i ) for i in raw_input( ).split( " " ) ]
	t = sum( s )
	m = t / n
	t = 0
	for val in s:
		t += ( val - m )**2
	print( math.sqrt( t/n ) )

Measured memory_bytes: 4472
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,k;
  cin >> a >> b >> k;
  for(int i=0;i<k;i++){
	if(i%2 == 0){
      if(a%2 == 1) a--;
      b += a/2;
      a /= 2;
    }else{
      if(b%2 == 1) b--;
      a += b/2;
      b /= 2;      
    }
  }
  cout << a << " " << b << endl;
}

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

using namespace std;
int main(){
  string s;
   cin >>s;
  
  long res=1000;
  for(char c='a';c<='z';c++){
    string t=s;
    long cnt=0;
    
    while(1){
      bool flag=true;
      for(int i=1;i<t.length();i++){
      if(t[i-1]!=t[i]) flag=false;
     }
      if(flag) break;
      
     for(int i=0;i<t.length()-1;i++){
   if(t[i]==c||t[i+1]==c) t[i]=c;
      }
    t=t.substr(0,t.length()-1);
    cnt++;
  }
   res=min(cnt,res); 
  }
    
 cout << res << endl; 
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n;
	cin>>n;
	const int INF=1e6;
	int d[202][202];
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if(i==j) d[i][j]=0;
			else d[i][j]=INF;
		}
	}
	string s[202];
	for(int i=0; i<n; i++){
		cin>>s[i];
		for(int j=0; j<n; j++){
			if(s[i][j]=='1') d[i][j]=1;
		}
	}
	for(int k=0; k<n; k++){
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				d[i][j]=min(d[i][j], d[i][k]+d[k][j]);
			}
		}
	}
	int ans=-1;
	for(int i=0; i<n; i++){
		vector<int> v[202];
		for(int j=0; j<n; j++){
			v[d[i][j]].push_back(j);
		}
		bool dame=0;
		for(int k=0; k<n; k++){
			int m=v[k].size();
			for(int p=0; p<m; p++){
				for(int q=0; q<m; q++){
					if(s[v[k][p]][v[k][q]]=='1'){
						dame=1;
					}
				}
			}
		}
		if(dame) continue;
		int mx=0;
		for(int k=0; k<n; k++){
			if(!v[k].empty()) mx=k;
		}
		ans=max(ans, mx+1);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  for i, c in enumerate(input().strip(), 1):
    if (i%2 == 1 and c == 'L') or (i%2 == 0 and c == 'R'):
      print('No')
      return 
  print('Yes')

if __name__=='__main__':
  main()



Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A+B == C+D){
    cout << "Balanced";
  }
  else if (A+B > C+D){
    cout << "Left";
  }
  else{
    cout << "Right";
  }
}

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

typedef long long ll;
//loop
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//STL
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

//const
#define MOD 1000000007 //10^9+7:合同式の法

//acronym
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int gcd(ll a, ll b, vector<vector<ll>> & dp){
    if (dp[a][b] != -1L) return dp[a][b];
    if(a%b == 0){
        dp[a][b] = b;
    }else{
        dp[a][b] = gcd(b, a%b, dp);
    }
    return dp[a][b];
}

int gcd_arr(vector<ll> & a, vector<vector<ll>> & dp) {
    int n = a.size();
    FORD(i,n-2,0) {
        a.at(i) = gcd(a.at(i), a.at(i+1), dp);
    }
    return a.front();
}

void Main() {
    int k;
    cin >> k;

    ll ans = 0L;


    vector<vector<ll>> dp1(k+1, vector<ll>(k+1, -1L));
    vector<vector<vector<ll>>> dp(k+1, vector<vector<ll>>(k+1, vector<ll>(k+1, -1L)));

    FOR(a,1,k) FOR(b,1,k) FOR(c,1,k) {
        vector<ll> abc = {a, b, c};
        sort(ALL(abc));
        if (dp[abc[0]][abc[1]][abc[2]] == -1L) {
            dp[abc[0]][abc[1]][abc[2]] = gcd_arr(abc, dp1);
        }
        ans += dp[abc[0]][abc[1]][abc[2]];
    }

    cout << ans << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Main();
    return 0;
}


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

typedef long long ll;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

const char nl = '\n';

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    vector<int> a(n + 2, 0);
    FOR(i, 1, n + 1) cin >> a[i]; 
    vector<int> diff(1, 0);
    FOR(i, 1, n + 2) diff.pb(diff[i - 1] + abs(a[i] - a[i - 1]));
    FOR(i, 1, n + 1) {
        cout << diff[i - 1] - diff[0] + diff[n + 1] - diff[i + 1] + abs(a[i + 1] - a[i - 1]) << nl;
    }
}

Measured memory_bytes: 4220
//g++  5.4.0

#include <bits/stdc++.h>

using namespace std;

int main()
{
    string s1,s2; cin >> s1 >> s2;
    int len1 = s1.size(), len2 = s2.size();
    
    vector<vector<int> > dp(len1+1, vector<int>(len2+1,0));
    
    for(int i =1; i <= len1; i++){
        for(int j =1; j <= len2; j++){
            if(s1[i-1]==s2[j-1]) dp[i][j] = dp[i-1][j-1]+1;
            else{
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    
    /*for(int i = 1; i <= len1; i++){
        for(int j = 1; j <= len2; j++){
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }*/
    
    string s = "";
    int len = dp[len1][len2];
    //cout << len << endl;
    int i = len1, j = len2;
    while(len){
        //cout << i <<  " " << j << " " << endl;
        if(s1[i-1]==s2[j-1]) {
            s += s1[i-1];
            //cout << i <<  " " << j << " " << endl; 
            i--;j--;
            len--;
            
        }
        else if(dp[i-1][j] > dp[i][j-1]){
            i--;
        }
        else {
            j--;
        }
    }
    reverse(s.begin(),s.end());
    cout << s << endl;
}

Measured memory_bytes: 35584
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {

	sc.Scan()
	t := sc.Text()
	f, _ := strconv.ParseFloat(t, 64)
	len := f / 3

	fmt.Printf("%f", len*len*len)
}


Measured memory_bytes: 640
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif


using namespace std;

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

const int MOD = 1e9 + 7;
const int INF = INT_MAX;

signed main() {
    Fast();

    int a, b;
    cin >> a >> b;

    cout << ((a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) ? "Possible" : "Impossible") << endl;

    return 0;
}



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

const int Maxn = 105;

int n;
int X[Maxn];
int res = 1000000000;

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
        scanf("%d", &X[i]);
    for (int i = 1; i <= 100; i++) {
        int cand = 0;
        for (int j = 0; j < n; j++)
            cand += (X[j] - i) * (X[j] - i);
        res = min(res, cand);
    }
    printf("%d\n", res);
    return 0;
}


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

int main(){
  long long l;
  cin>>l;
  int n=floor(log2(l));
  //long long dp[n]={};
  string ans="";
  int m=0;
  rep(i,n){
        ans+=to_string(i+1)+" "+to_string(i+2)+" 0"+"\n";
        m++;
        ans+=to_string(i+1)+" "+to_string(i+2)+" "+to_string(1<<(n-i-1))+"\n";
        m++;
  }

  long long cmax=(1<<n);
  l-=cmax;
  int cn;
  while (l>=1){
  cn=n-floor(log2(l))+1;
  ans+="1 "+to_string(cn)+" "+to_string(cmax)+"\n";
  m++;
  cmax+=(1<<(int)floor(log2(l)));
  l-=(1<<(int)floor(log2(l)));

}
  cout<<n+1<<" "<<m<<endl<<ans;
  return 0;
}


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

using ll = long long;

#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 pb push_back
#define mp make_pair
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

// these functions return the position of result of Binary Search.
#define LB(s, t, x) (int) (lower_bound(s, t, x) - s)
#define UB(s, t, x) (int) (upper_bound(s, t, x) - s)

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll temp = gcd(a, b); return temp ? (a / temp * b) : 0; }
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx8[] = { 1, -1, 0, 0, 1, 1, -1, -1 }, dy8[] = { 0, 0, -1, 1, -1, 1, -1, 1 };

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

template <class T>
bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T>
bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

inline tuple<ll, ll> rotate45(tuple<ll, ll> point) { ll x = get<0>(point), y = get<1>(point); return tuple<ll, ll>(x + y, x - y); }
inline bool rangeCheck2D(int nx, int ny, int Width, int Height) { return nx >= 0 and nx < Width and ny >= 0 and ny < Height; }
void out_sequence(vector<ll> &out) { REP(i, (int)out.size()) { cout << out[i]; if (i == (int)out.size() - 1) cout << endl; else cout << " "; } }

ll dfs(vector<bool> &visited, vector<vector<int>> &g, int current, int cnt, int d) {
	visited[current] = true;
	ll ret = 0;
	bool needed = false;
	int nd = d;
	if (cnt == 2 or d) nd = 1;
	REP(i, g[current].size()) {
		int next = g[current][i];
		if (visited[next]) continue;
		int ncnt = cnt+1;
		if (not d and cnt == 2) ncnt = 1, needed = true;
		if (d and cnt == 1) ncnt = 1, needed = true;
		ret += dfs(visited, g, next, ncnt, nd);
	}
	if (needed) ret++;
	return ret;
}

int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	ll N; cin >> N; ll K; cin >> K;
	
	cout << N - K + 1 << endl;


	return 0;
}

//*/

Measured memory_bytes: 764
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 210

struct LOC{
	int x,y;
};

int V; //頂点数
vector<int> G[NUM]; //グラフの隣接リスト表現
int match[NUM]; //マッチングのペア
bool used[NUM]; //DFSですでに調べたかのフラグ

LOC red[100],blue[100];

//fromとtoを結ぶ辺をグラフに追加する
void add_edge(int from,int to){
	G[from].push_back(to);
	G[to].push_back(from);
}

//増加パスをDFSで探す(node_idのペアを探す)
int dfs(int node_id){
	used[node_id] = true;

	for(int i = 0; i < G[node_id].size(); i++){
		int adj_node_id = G[node_id][i],pair_id = match[adj_node_id];
		if((pair_id < 0)|| //隣接するノードに、まだペアが存在しない
				(used[pair_id] == false && dfs(pair_id) == true)){

			match[node_id] = adj_node_id;
			match[adj_node_id] = node_id;
			return true;
		}
	}
	return false;
}


int bipartie_matching(){
	int ret = 0;
	for(int i = 0; i < V; i++)match[i] = -1; //ペアなしにしておく
	for(int node_id = 0; node_id < V; node_id++){
		if(match[node_id] < 0){ //node_idにペアがいない場合
			for(int i = 0; i < V; i++)used[i] = false;
			if(dfs(node_id)){ //増加パスが存在する場合
				ret++;
			}
		}
	}
	return ret;
}


int main(){

	int N;
	scanf("%d",&N);

	for(int i = 0; i < N; i++){

		scanf("%d %d",&red[i].x,&red[i].y);
	}

	for(int i = 0; i < N; i++){

		scanf("%d %d",&blue[i].x,&blue[i].y);
	}

	for(int i = 0; i < N; i++){
		for(int k = 0; k < N; k++){
			if(red[i].x < blue[k].x && red[i].y < blue[k].y){

				add_edge(i,N+k);
			}
		}
	}

	V = 2*N;

	printf("%d\n",bipartie_matching());

	return 0;
}


Measured memory_bytes: 256
package main


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

func getLen(A, B int) int {
	if A == 1e18 || B == 1e18 {
		return 1e18
	}
	if A < B {
		return 2*(A) + B
	} else {
		return A + 2*B
	}
}

func main() {
	A := nextInt()
	B := nextInt()
	Q := nextInt()
	s := nextInts(A)
	t := nextInts(B)
	x := make([]int, Q)
	for i := 0; i < Q; i++ {
		x[i] = nextInt()

		l1 := binarySearch(x[i], s, 0, A, true)
		l2 := binarySearch(x[i], t, 0, B, true)
		r1 := binarySearch(x[i], s, -1, A-1, false)
		r2 := binarySearch(x[i], t, -1, B-1, false)
		Z := make([]int, 4)
		for i := 0; i < 4; i++ {
			Z[i] = 1e18
		}

		if s[0] <= x[i] && t[0] <= x[i] {
			Z[0] = Max(x[i]-s[l1], x[i]-t[l2])
		}
		if s[A-1] >= x[i] && t[B-1] >= x[i] {
			Z[1] = Max(s[r1]-x[i], t[r2]-x[i])
		}
		if s[0] <= x[i] && t[B-1] >= x[i] {
			Z[2] = getLen(x[i]-s[l1], t[r2]-x[i])
		}
		if s[A-1] >= x[i] && t[0] <= x[i] {
			Z[3] = getLen(s[r1]-x[i], x[i]-t[l2])
		}
		P := MinA(Z...)
		fmt.Println(P)
	}
}

func binarySearch(x int, A []int, L, R int, lower bool) int {
	l := L
	r := R
	for r-l > 1 {
		c := (r + l) / 2
		if A[c] < x {
			l = c
		} else if A[c] > x {
			r = c
		} else {
			return c
		}
	}
	if lower {
		return l
	} else {
		return r
	}
}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}

func nextString() string {
	return nextReader()
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

func nextInt64s(n int) []int64 {
	r := make([]int64, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt64()
	}
	return r
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func Min(a int, b int) int {
	if a > b {
		return b
	}
	return a
}

func Max(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

func MinA(arg ...int) int {
	var s = arg[0]
	for _, v := range arg {
		s = Min(s, v)
	}
	return s
}

func MaxA(arg ...int) int {
	var s = arg[0]
	for _, v := range arg {
		s = Max(s, v)
	}
	return s
}

func Abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}


Measured memory_bytes: 7552
from collections import defaultdict
import queue

n, m = map(int, input().split())
edges = [tuple(map(int, input().split())) for _ in range(m)]

s, t = map(int, input().split())

graph = defaultdict(list)

for edge in edges:
	u, v = edge
	graph[u].append(v + n)
	graph[u + n].append(v + 2*n)
	graph[u + 2*n].append(v)

def bfs(s, t, graph):
	vis_set = set()
	dist = defaultdict(lambda: int(-1))
	dist[s] = 0
	que = queue.Queue()
	que.put(s)
	vis_set.add(s)	

	while not que.empty():
		vert = que.get()
		for nxt in graph[vert]:
			if nxt not in vis_set:
				dist[nxt] = dist[vert] + 1
				vis_set.add(nxt)
				que.put(nxt)
				if nxt == t:
					return dist[nxt]//3
	return -1
ans = bfs(s, t, graph)
print(ans)

Measured memory_bytes: 141944
#include <bits/stdc++.h>
using namespace std; 
vector <int> v[100001];  
vector <int> v2[100001]; 
int main() 
{
	int n,m;
	cin>>n>>m;
	int dp[n+1];
	memset(dp,0,sizeof(dp));
	int in[n+1];
	memset(in,0,sizeof(in));
	vector <int> vv;
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		v[x].push_back(y);
		v2[y].push_back(x);
		in[y]++;
	}
	for(int i=1;i<=n;i++)
	{
		if(in[i]==0)
		vv.push_back(i);
	}
	queue <int> q;
	for(int i=0;i<vv.size();i++)
	{
		q.push(vv[i]);
		while(1)
		{
			if(q.empty())
			break;
			int z=q.front();
			q.pop();
		for(int j=0;j<v[z].size();j++)
		{
			dp[v[z][j]]=max(dp[v[z][j]],dp[z]+1);
		//	cout<<v[z][j]<<" "<<dp[v[z][j]]<<"\n";
			in[v[z][j]]--;
		//	cout<<in[v[z][j]]<<" \n";
			if(in[v[z][j]]==0)
			{
				
				q.push(v[z][j]);
			}
		}
		}
	}
	int mx=0;
	for(int i=1;i<=n;i++)
	{
	//	cout<<dp[i]<<" ";
		mx=max(mx,dp[i]);
	}
	//cout<<"\n";
	cout<<mx;
}


Measured memory_bytes: 11904
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define int long long int
constexpr int INF = std::numeric_limits<int>::max();
constexpr int NINF = std::numeric_limits<int>::min();
using namespace std;

void solve() {
  string a, b;
  cin >> a >> b;
  int x = stoi(a + b);
  for (int i = 0; i < 1000; i++) {
    if (i * i == x) {
      cout << "Yes" << endl;
      return;
    }
  }
  cout << "No" << endl;
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <tuple>
#include <vector>

using namespace std;

struct Graph
{
    vector<tuple<int, int, int>> edges;
    int nodes;

    Graph(int nodes) : nodes(nodes) {}

    void AddEdge(int a, int b, int cost)
    {
        edges.push_back(make_tuple(a, b, cost));
    }
};

int Log2(int num)
{
    return log(num) / log(2);
}

void Print(const Graph &g)
{
    cout << g.nodes << " " << g.edges.size() << "\n";
    for (const auto &e : g.edges) {
        int a, b, cost;
        tie(a, b, cost) = e;
        cout << a + 1 << " " << b + 1 << " " << cost << "\n";
    }
}

int main()
{
    int paths;
    cin >> paths;

    Graph graph(Log2(paths) + 1);
    for (int i = 0; i + 1 < graph.nodes; i += 1) {
        graph.AddEdge(i, i + 1, 0);
        graph.AddEdge(i, i + 1, (1 << i));
    }

    int next_cost = (1 << (graph.nodes - 1));
    paths -= next_cost;

    while (paths > 0) {
        int l = Log2(paths);
        graph.AddEdge(l, graph.nodes - 1, next_cost);
        paths -= (1 << l);
        next_cost += (1 << l);
    }

    Print(graph);
    return 0;
}


Measured memory_bytes: 1148
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;

class Main
{
    public static void main(String[] args)
    {
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      String s = sc.next();
      
      String str;
      String detec;
      
      //str = s.substring(1,3);
      
      int start = 0;
      int ans = 0;
      boolean exist = false;
      while(start+ans+1<=n) {
        str = s.substring(start,start+ans+1);
        for(int i=start+ans+1; i+ans<n; i++) {
          detec = s.substring(i,i+ans+1);
          if(str.equals(detec)) {
            ans = str.length();
            exist =true;
            break;
          }
        }
        if(!exist) start++;
        exist = false;
      }
      
      System.out.println(ans);
      
    }
}



Measured memory_bytes: 346388
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	m := make(map[int]int)
	var a int
	for i := 0; i < n; i++ {
		fmt.Scan(&a)
		m[a]++
	}

	if n%2 == 1 && m[0] != 1 {
		fmt.Println(0)
		return
	}

	ans := 1
	for i := 1 + (n % 2); i < n; i += 2 {
		if m[i] != 2 {
			fmt.Println(0)
			return
		}
		ans = (ans * 2) % (1e9 + 7)
	}
	fmt.Println(ans)
}


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

int main() {
    int n;
    cin >> n;
    if (n==1) {cout << 1;}
    else {
        int a,pre,i=0,count=1,mode=0;
        cin >> pre;;
        while (i<n-1) {
            cin >> a;
            if (pre!=a){
                if (mode==0) {mode = (pre<a) ? 1 : -1;}
                else if (mode==-1) {
                    if (a>pre) {mode=0;++count;}
                }
                else if (mode==1) {
                    if (a<pre) {mode=0;++count;}
                }
            }
            ++i;
            pre=a;
        }
        cout << count << endl;
    }
    return 0;
}

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

namespace CompetitiveProg
{
    class Program
    {
        static int W;
        static int n;
        static List<VW> vws;
        static VW?[,] memo;
        static void Main(string[] args)
        {
            var c = 1;
            while ((W = int.Parse(Console.ReadLine()))!=0)
            {
                vws = new List<VW>();
                n = int.Parse(Console.ReadLine());
                memo = new VW?[n+1, W + 1];
                foreach (var i in Enumerable.Range(0,n))
                {
                    foreach (var j in Enumerable.Range(0, W))
                    {
                        memo[i,j] = null;
                    }
                    
                }
                for (int i = 0; i < n; i++)
                {
                    vws.Add(new VW(Console.ReadLine().Split(',').Select(s => int.Parse(s))));
                }
                var r = solve(0, W);
                Console.WriteLine("Case {0}:\n{1}\n{2}", c, r.v, r.w);
                c++;
            }
        }

        private static VW solve(int i, int w)
        {
            VW res;
            if (memo[i, w] != null) return (VW)memo[i, w];
            if (i == n) { res = new VW(new[]{0, 0}); }
            else if (w < vws[i].w) { res = solve(i + 1, w); }
            else res = (new[] { solve(i + 1, w), solve(i + 1, w - vws[i].w) + new VW(new[] {vws[i].v,vws[i].w })}).Max();
            memo[i, w] = res;
            return res;
        }
        struct VW : IComparable<VW>
        {
            public readonly int v;
            public readonly int w;

            public static VW operator +(VW a, VW b)
            {
                return new VW(new[] { a.v + b.v, a.w + b.w });
            }
            public VW(IEnumerable<int> enumerable)
            {
                v = enumerable.ToList()[0];
                w = enumerable.ToList()[1];
            }


            public int CompareTo(VW other)
            {
                int dv;
                
                if ((dv = this.v - other.v) == 0)
                {
                    return -(this.w - other.w); 
                }
                else
                {
                    return dv;
                }
            }
        }
    }
}

Measured memory_bytes: 32924
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<cstdio>
#include<cstdlib>
using namespace std;

int main() {
	long r, D;
	cin >> r >> D;

	vector<long> x(12);
	cin >> x[0];
	for (int i = 1; i < 11; ++i) {
		x[i] = r * x[i - 1] - D;
		cout << x[i] << endl;
	}
}

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

using namespace std;

#define f first
#define s second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()

#define MOO(i, a, b) for (int i=a; i<b; i++)
#define M00(i, a) for (int i=0; i<a; i++)
#define MOOd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define M00d(i,a) for (int i = (a)-1; i >= 0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << '\n', 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << "\n";
#define _<< " _ " <<

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pd;
typedef complex<ld> cd;
typedef vector<int> vi;
typedef vector<ll> vll;

int main() { FAST
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	string s;
	cin >> s;
	cout << s.substr(0,3) << endl;
}


Measured memory_bytes: 3636
def BubbleSort(C, N):
    for i in range(N):
        for j in range(N-1, i,-1):
            if C[j][1] < C[j-1][1]:
                C[j], C[j-1] = C[j-1], C[j]
    return C
                
                

def SelectionSort(C, N):
    #print(C)
    for i in range(N):
        minj = i
        for j in range(i, N):
            if C[j][1] < C[minj][1]:
                minj = j
        C[i], C[minj] = C[minj], C[i]
        #print(C)
    return C


def IsStable(A, B):
    for i in range(len(A)):
        for j in range(i+1,len(A)):
            for a in range(len(B)):
                for b in range(a+1,len(B)):
                    if A[i][1] == A[j][1] and A[i] == B[b] and A[j] == B[a]:
                        return False
    return True
        
                
n = int(input())
a = input().split()
b = a.copy()
c = a.copy()
ans1 = []
ans2 = []
    
ans1 = BubbleSort(b, n)
print(*ans1)
if IsStable(a, ans1):
    print('Stable')
else:
    print('Not stable')

ans2 = SelectionSort(c, n)
print(*ans2)
if IsStable(a, ans2):
    print('Stable')
else:
    print('Not stable')


Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
#define mp(a, b) make_pair(a, b)
#define lowbit(x) (x & (-x))
#define ls (rt << 1)
#define rs (rt << 1 | 1)
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 100 + 10;
int main()
{
	int n;
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i)
	{
		int val;
		scanf("%d", &val);
		if(val & 1) continue;
		if(val % 3 == 0 || val % 5 == 0) continue;
		puts("DENIED");
		return 0;
	}
	puts("APPROVED");
	return 0;
}

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

int main() {
	static int N, D[100000];
	cin >> N;
	for (int i = 0; i < N; i++) cin >> D[i];
	sort(D, D + N);
	cout << D[N / 2] - D[N / 2 - 1] << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>      
using namespace std;
const int N = 1e5 + 100;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define ull unsigned long long
#define ll long long
#define pii pair <int,int>
#define forn(l,i,n) for(int i = l;i <= n;++i)   
#define FOR(l,i,n) for(int i = l;i < n;++i)
#define all(v) v.begin(), v.end()
#define pll pair <ll,ll>
const ll inf = 1e9 + 7;
const ll ll_inf = 1e17 + 100;   
const double pi = 3.14159265358979323;
inline void fr(){
    freopen("gcd.in", "r", stdin);
    freopen("gcd.out", "w", stdout);
}
void boost()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
 
ll binpow (ll a, ll n)
{
    ll res = 1;
    while (n) {
        if (n & 1)
        {
            res *= a;
            res %= inf;
        }
        a *= a;
        n >>= 1;
        a %= inf;
    }
    return res;
}
        
ll n,w;
ll v[N * 2],a[N * 2];
ll dp[N * 2];
ll ans;
 
main()	
{                                                                        
	cin >> n >> w;
	for (int i = 1;i <= n;++i)
	{
		cin >> a[i] >> v[i];
	}            
	for (int i = 1;i <= N;++i)
	{
		dp[i] = inf;
	}
	for (int i = 1;i <= n;++i)
	{
		for (int j = N;j >= 0;--j)
		{
			if((dp[j] != 0 || j == 0) && dp[j] + a[i] <= w)
			{
			 	dp[j + v[i]] = min(dp[j] + a[i],dp[j + v[i]]);
			 	ans = max(ans,j + v[i]);

			 	//cout << j << " " << i << " " << ans << "\n";
			}   	
		}
	}
	cout << ans;
}	 


Measured memory_bytes: 3072
import java.util.*;

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

        String S = sc.next();
        String s = String.valueOf(S.charAt(5)) + String.valueOf(S.charAt(6));
        int n = Integer.parseInt(s);

        if(n<=4){
            System.out.println("Heisei");
        }
        else if(n>4){
            System.out.println("TBD");
        }
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define per(i,n) for (int i = (n)-1; i >=0; --i)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;

int main(){
    int n,k;
    cin>>n>>k;
    vi l(n);
    rep(i,n)cin>>l[i];
    sort(l.rbegin(), l.rend());
    int ans = 0;
    rep(i,k)ans+=l[i];
    
    cout << ans << endl;
    return 0;
}

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

using namespace std;

constexpr int SURFACE_NUM = 6;

class Dice {
private:
    array<int, SURFACE_NUM> m_surface;

public:
    explicit Dice(array<int, SURFACE_NUM> surface)
        : m_surface(surface) {}

    int surface(int i) const
    {
        return m_surface.at(i);
    }

    void roll(char direction)
    {
        int tmp;
        switch (direction) {
        case 'N':
            tmp = m_surface.at(0);
            m_surface.at(0) = m_surface.at(1);
            m_surface.at(1) = m_surface.at(5);
            m_surface.at(5) = m_surface.at(4);
            m_surface.at(4) = tmp;
            break;
        case 'S':
            tmp = m_surface.at(0);
            m_surface.at(0) = m_surface.at(4);
            m_surface.at(4) = m_surface.at(5);
            m_surface.at(5) = m_surface.at(1);
            m_surface.at(1) = tmp;
            break;
        case 'E':
            tmp = m_surface.at(0);
            m_surface.at(0) = m_surface.at(3);
            m_surface.at(3) = m_surface.at(5);
            m_surface.at(5) = m_surface.at(2);
            m_surface.at(2) = tmp;
            break;
        case 'W':
            tmp = m_surface.at(0);
            m_surface.at(0) = m_surface.at(2);
            m_surface.at(2) = m_surface.at(5);
            m_surface.at(5) = m_surface.at(3);
            m_surface.at(3) = tmp;
            break;
        }
    }
};

int main()
{
    array <int, SURFACE_NUM> init;
    for (auto i = 0; i < SURFACE_NUM; i++) {
        cin >> init.at(i);
    }
    Dice one(init);

    string op;
    cin >> op;
    for (auto i = 0; i < op.size(); i++) {
        char direction = op.at(i);
        one.roll(direction);
    }

    cout << one.surface(0) << endl;;
}

Measured memory_bytes: 1208
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
using namespace std;

#define ll long long int

const int MOD = 1000000007;

int main() {

	int N, pay, get;

	cin >> N;

	pay = 800 * N;
	get = ((N - (N % 15)) / 15) * 200;

	cout << pay - get << endl;

	return 0;
}

Measured memory_bytes: 256
x,n = map(int, input().split())
ps = list(map(int, input().split()))
ps = set(ps) 
mn = 1000
ans = -1
for i in range(102):
    if i in ps: continue
    if abs(i-x) < mn:
        ans = i
        mn = abs(i-x)
print(ans)


Measured memory_bytes: 9180
--{-# LANGUAGE OverloadedStrings #-}
--{-# LANGUAGE OverloadedLists   #-}
{-# LANGUAGE BangPatterns      #-} --引数に!
{-# LANGUAGE MultiWayIf        #-}
{-# LANGUAGE TupleSections     #-}

import Data.Bits
import Data.Maybe (fromJust)
import Data.List
import qualified Data.Vector.Unboxed as V
import Control.Monad
import qualified Data.ByteString.Lazy.Char8 as B

type Ans = Int

solve :: Int -> [Int] -> Ans
solve n as = maximum $ sub 0
  where
    lgcd = V.fromList $ scanl1 gcd as
    rgcd = V.fromList $ scanr1 gcd as
    sub :: Int -> [Int]
    sub 0 = rgcd V.! 1 : (sub 1)
    sub i | i == n-1 = [lgcd V.! (n-2)]
          | otherwise = gcd (lgcd V.! (i-1)) (rgcd V.! (i+1)) : (sub (i+1))



readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

main0 :: B.ByteString -> Ans
main0 cont =
   let remLines0 = map (map readBInt . B.words) (B.lines cont)
       [n]:remLines1 = remLines0
       as = head remLines1
       in solve n as

main :: IO ()
main = print . main0 =<< B.getContents


Measured memory_bytes: 24828
#include<bits/stdc++.h>
using namespace std;
int f[502][502];
int main()
{
	int n,m,p,i,j,k,x,y;
	//freopen("express.in","r",stdin);
	//freopen("express.out","w",stdout);
	scanf("%d%d%d",&n,&m,&p);
	for(i=1;i<=m;i++)
	   scanf("%d%d",&x,&y),f[x][y]++;
	for(i=1;i<=n;i++)
	 for(j=1;j<=n;j++)
	 {
	 	f[i][j]+=f[i][j-1];
	 	for(k=i+1;k<=j;k++)
	 	 f[i][j]+=f[k][j];
	 }
	for(i=1;i<=p;i++)
	{
		scanf("%d%d",&x,&y);
		printf("%d\n",f[x][y]);
	}
	return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int cost[10]={0,2,5,5,4,5,6,3,7,6};
  Int n,m;
  cin>>n>>m;
  vector<Int> a(m);
  for(Int i=0;i<m;i++) cin>>a[i];
  sort(a.begin(),a.end());

  vector<string> dp(n+100,"");
  auto cmp=[](string a,string b){
             if(a.size()!=b.size()) return a.size()<b.size();
             for(Int i=0;i<(Int)a.size();i++)
               if(a[i]!=b[i]) return a[i]<b[i];
             return false;
           };

  for(Int i=0;i<n;i++){
    if(i&&dp[i]==""s) continue;
    for(Int x:a){
      if(cmp(dp[i+cost[x]],dp[i]+char('0'+x))) dp[i+cost[x]]=dp[i]+char('0'+x);
    }
  }
  cout<<dp[n]<<endl;
  return 0;
}


Measured memory_bytes: 43904
#include <iostream>
#include <math.h>

using namespace std;

int main(){
  long double sum=0;
  int n;
  long double x[10], y[10];
  
  cin >> n;
  for(int i=0;i<n;i++)
    cin >> x[i] >> y[i];
  
  for(int i=0; i<n; i++)
    for(int j=i+1; j<n; j++)
      sum += sqrt(
      (x[i]-x[j])*(x[i]-x[j])+
      (y[i]-y[j])*(y[i]-y[j]));
  long double ans = sum * 2.0 / n;
  printf("%.8llf\n",ans);
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
typedef v(string) vs;
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.first>>v.second;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.first<<","<<v.second;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int mod = 1000000007;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}


void Main()
{
  int h,w;
  mint dp[1005][1005];
  cin >> h >> w;
  vs s(h);
  cin>>s;
  dp[0][0] = 1;
  rep(i,h) rep(j,w) {
    if(s[i][j]=='.'){
      if (i) dp[i][j] += dp[i-1][j];
      if (j) dp[i][j] += dp[i][j-1];
    }
  }
  cout<<dp[h-1][w-1]<<endl;
}

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


Measured memory_bytes: 9216
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

int INF = 1<<30;
int main( ){
   int N; cin>>N;
   vi dp(N+1,INF);
   dp[0]=0,dp[N]=N;
   vll V={6,9};

   for(int i=1;i<=N;i++){
    rep(v,0,2){
        for(int cnt=0;i-pow(V[v],cnt)>=0;cnt++)
            chmin(dp[i],dp[i-pow(V[v],cnt)]+1);
   }
   }
   cout<<dp[N]<<endl;
   return 0;
}




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

struct UnionFind {
private :
    vector<int> data; int sz;
public :
    UnionFind(int sz) : data(sz, -1), sz(sz) { }

    bool unite(int x, int y) {
        if ((x = root(x)) == (y = root(y))) return false;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        sz--;
        return true;
    }

    bool is_same(int x, int y) { return root(x) == root(y); }

    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }

    size_t size(int x) { return (size_t)-data[root(x)]; }

    size_t size() { return (size_t)sz; }

};

int main() {
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    vector<long long> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) {
        int s, t;
        cin >> s >> t;
        uf.unite(s, t);
    }
    
    int sz = uf.size();
    if (sz == 1) {
        cout << 0 << endl;
        return 0;
    } else if (2 * sz - 2 > n) {
        cout << "Impossible" << endl;
        return 0;
    }
    
    vector<long long> dat[n];
    for (int i = 0; i < n; i++) {
        int r = uf.root(i);
        dat[r].emplace_back(a[i]);
    }
    for (int i = 0; i < n; i++) sort(dat[i].begin(), dat[i].end());
    
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        if (dat[i].size()) ans += dat[i][0];
    }
    
    vector<long long> res;
    for (int i = 0; i < n; i++) {
        for (int j = 1; j < dat[i].size(); j++) {
            res.emplace_back(dat[i][j]);
        }
    }
    
    sort(res.begin(), res.end());
    for (int i = 0; i < sz - 2; i++) ans += res[i];
    
    cout << ans << endl;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    int a[n];

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

    for(int i=n-1;i>=0;i--){
        if(i==0){
            cout << a[i] << endl;
        }

        else{
            cout << a[i] << ' ';
        } 
    }

    return 0;
}


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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

char c[10][10];
int h,w;
int k;

bool CountK(int hbit,int wbit){
  int cnter = 0;
  for(int i = 0; i < h; ++i){
    if(hbit&(1<<i))continue;
    for(int j = 0; j < w; ++j){
      if(wbit&(1<<j))continue;
      cnter += c[i][j] == '#';
    }
  }
  return cnter == k;
}

int main(){
  cin >> h >> w >> k;
  for(int i = 0; i < h; ++i){
    for(int j = 0; j < w; ++j){
      cin >> c[i][j];
    }
  }
  int ans = 0;
  for(int i = 0; i < (1<<h); ++i){
    for(int j = 0; j < (1<<w); ++j){
      ans += CountK(i, j);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
from collections import Counter
s = int(input())

def func(n):
    if n % 2 == 0:
        return n // 2
    else :
        return 3 * n + 1
l = []
m = 0
l.append(s)
while True:
    l.append(func(l[m]))
    if 2 <= l.count(l[m+1]):
        print(m+2)
        break
    m += 1

Measured memory_bytes: 3316
import java.util.*;
 
public class Main {
    public static void main( String args[] ) {
        Scanner scan = new Scanner( System.in );
		
		int n = scan.nextInt();
		
		int TPoint = 0;
		int HPoint = 0;
		for ( int i = 0; i < n; i++ ) {
			String T = scan.next();
			String H = scan.next();
			
			int result = T.compareToIgnoreCase(H);
			if ( result > 0 ) {
				TPoint += 3;
								
			} else if ( result == 0) {
				TPoint += 1;
				HPoint += 1;
				
			} else if ( result < 0 ) {
				HPoint += 3;
				
			}
			
		}
		System.out.println( TPoint + " " + HPoint );
		
	}
	
}

Measured memory_bytes: 20800
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
const int inf=1<<30;
typedef long long ll;
int main(){
	int n;	cin>>n;
	map<int,int> lib;
	for(int i=0;i<n;i++){
		int a;	cin>>a;
		lib[a]++;
	}
	lib[inf]=5;
	vector<int> ls;
	auto it=lib.begin();
	while(ls.size()<5){
		while(ls.size()<5&&it->second>0){
			it->second--;
			ls.push_back(it->first);
		}
		it++;
	}
	vector<ll> ans;
	for(int i=0;i<(int)ls.size();i++){
		for(int j=0;j<(int)ls.size();j++){
			if(i==j)	continue;
			ll a=ls[i],b=ls[j];
			if(a==inf||b==inf)	continue;
			for(ll j=1;b/j>0;j*=10)	a*=10;
			ans.push_back(a+b);
		}
	}
	sort(ans.begin(),ans.end());
	cout<<ans[2]<<endl;
	return 0;
}

Measured memory_bytes: 3552
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

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

   for(int i=x-k+1;i<=x+k-1;i++){
       cout<<i;
       if(i==x+k-1){
           cout<<"\n";
       }else{
           cout<<" ";
       }
   }
    
}



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

int main(){
	int n,a[55]={0},b[55]={0};
	cin >> n;
	for(int i=0;i<n;i++)
		cin >> a[i];
	for(int i=1;i<=n;i++)
		b[i-1]=i;
	int m[55],c=0;
	for(int i=0;i<n;i++){
		if(a[i]!=b[i]){
			m[c++]=i;
		}
	}
	if((c==2&&a[m[1]]==b[m[0]]&&a[m[0]]==b[m[1]])||c==0) printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
# -*- coding:utf-8 -*-

L_R_list = []
N,M = map(int,input().split())
for i in range(M):
    L_R_list.append(list(map(int,input().split())))

min = 1
max = N

for i in range(M):
    if L_R_list[i][0] >= min:
        min = L_R_list[i][0]
    if L_R_list[i][1] <= max:
        max = L_R_list[i][1]

if max < min:
    print(0)
else:
    print(max-min+1)

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

int main(){

  double a,b;
  cin >> a >> b;
  double x;
  x = (a+b)/2;
  int xx;
  xx = (a+b)/2;
  if(x>xx){
    cout << xx+1 << endl;
  }else{
    cout << xx << endl;
  }
}

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

double Round4(double r){
    //double s=r;
    r=(int)round(r*1000);
    r=(double)r/1000;
    return(r);
}

int main(){
    double a,b,c,d,e,f;
    double x,y;
    while(cin>>a>>b>>c>>d>>e>>f){
        x=Round4((c*e-f*b)/(a*e-d*b));
        y=Round4((c*d-f*a)/(b*d-e*a));
        printf("%.3f %.3f\n", x, y);
    }
    return(0);
}

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

int main(){
    string s;
    int n;
    cin >> n >> s;
    for (int i=0;i<s.size();i++){
        s[i] = ((s[i] - 'A') + n) % 26 + 'A';
    }

    cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define F first
#define S second
signed main(){
  ll N,i,j,k,ans=-1000000000;
  cin>>N;bool F[N][10];ll P[N][11];
  REP(i,N)REP(j,10)cin>>F[i][j];
  REP(i,N)REP(j,11)cin>>P[i][j];
  FOR(i,1,1024){
    bool X[10];ll c,rieki=0;
    REP(j,10)X[j]=((1<<j)&i)>0;
    REP(j,N){
      c=0;
      REP(k,10)if(X[k]&&F[j][k])c++;
      rieki+=P[j][c];
    }
    ans=max(ans,rieki);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256