akhauriyash/Code-Regression huggingface dataset:
#include<vector>
#include<cstdio>
using namespace std;
typedef long long ll;

struct UnionFind {
    vector<int> parent;
    vector< ll > dist;
    UnionFind(int x = 1) {
        parent.resize(x, -1);
        dist.resize(x, 0);
    }
    int find(int x) {
        if (parent[x] < 0) return x;
        int r = find(parent[x]);
        dist[x] += dist[parent[x]];
        return parent[x] = r;
    }
    ll depth(int x) {
        find(x);
        return dist[x];
    }
    bool same(int x, int y) {
        return (find(x) == find(y));
    }
    void unite(int x, int y, ll k = 0) {
        k += depth(y);
        k -= depth(x);
        k *= -1;
        x = find(x);
        y = find(y);
        if (x == y) return;
        parent[y] = x;
        dist[y] = k;
    }
};

int main() {
    int n, q;
    scanf("%d %d", &n, &q);
    UnionFind T(n);
    for (int i = 0; i < q; i++) {
        int type, x, y;
        scanf("%d %d %d", &type, &x, &y);
        if (type == 0) {
            int a;
            scanf("%d", &a);
            T.unite(x, y, a);
        }
        else 
            if (!T.same(x, y)) printf("?\n");
            else printf("%lld\n", T.depth(x) - T.depth(y));
    }
    return 0;
}


Measured memory_bytes: 3432
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

char inv(char x){
  if(x == 'S') return 'W';
  else return 'S';
}

int main(){
  int n;
  string data;
  cin >> n >> data;
  vector<char> ans(n);
  bool flag1 = false;
  bool flag2 = false;
  rep(a,2){
    rep(b,2){
      if(a) ans.at(0) = 'S';
      else ans.at(0) = 'W';
      if(b) ans.at(1) = 'S';
      else ans.at(1) = 'W';
      for(int i=1;i<n-1;i++){
        if(data.at(i) == 'o'){
          if(ans.at(i) == 'S') ans.at((i+1)%n) = ans.at(i-1);
          else ans.at((i+1)%n) = inv(ans.at(i-1));
        }else{
          if(ans.at(i) == 'S') ans.at((i+1)%n) = inv(ans.at(i-1));
          else ans.at((i+1)%n) = ans.at(i-1);
        }
      }
      if(data.at(0) == 'o'){
        if(ans.at(0) == 'S'){
          if(ans.at(n-1) == ans.at(1)) flag1 = true;
        }else{
          if(ans.at(n-1) != ans.at(1)) flag1 = true;
        }
      }else{
        if(ans.at(0) == 'S'){
          if(ans.at(n-1) != ans.at(1)) flag1 = true;
        }else{
          if(ans.at(n-1) == ans.at(1)) flag1 = true;
        }
      }
      if(data.at(n-1) == 'o'){
        if(ans.at(n-1) == 'S'){
          if(ans.at(n-2) == ans.at(0)) flag2 = true;
        }else{
          if(ans.at(n-2) != ans.at(0)) flag2 = true;
        }
      }else{
        if(ans.at(n-1) == 'S'){
          if(ans.at(n-2) != ans.at(0)) flag2 = true;
        }else{
          if(ans.at(n-2) == ans.at(0)) flag2 = true;
        }
      }
      if(flag1 && flag2) break;
      flag1 = false;
      flag2 = false;
    }
    if(flag1 && flag2) break;
  }
  if(flag1 && flag2){
    rep(i,n) cout << ans.at(i);
    cout << endl;
  }else{
    cout << -1 << endl;
  }
}


Measured memory_bytes: 512
import java.util.Scanner;

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

	int a = sc.nextInt();
	int b = sc.nextInt();
	int c = sc.nextInt();

	if (c - (a + b) < 2) {
	    System.out.println(b + c);
	} else if (c - (a + b) >= 2) {
	    System.out.println((2 * (a + b) + 1)-a);
	}

    }
}


Measured memory_bytes: 22992
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
template<typename T> T gcd(T a,T b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
ll modpow(lll a,lll n,ll m){if(a==0)return a;lll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
int a[3];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  FOR(i, 0, 3) cin >> a[i];
  sort(a, a+3);
  int ans = 0, d = 0;
  FOR(i, 0, 2){
    int s = a[2] - a[i];
    ans += s / 2;
    d += s % 2;
  }
  if(d > 0) ans += 3 - d;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>

int main(int argc, const char* argv[]) {

    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);  std::cout.tie(NULL);

    double x;
    std::cin >> x;
    std::cout << std::fixed << std::setprecision(0) << pow(x, 3.0) << "\n";

    return 0;

}



Measured memory_bytes: 3424
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define MOD 1000000007
#define int long long
using ll = long long;
using namespace std;
const int INF = 1LL << 50;
using P = pair<int, int>;

template <class T>
bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    else {
        return false;
    }
}
template <class T>
bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    else {
        return false;
    }
}
struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} SETUP;

signed main() {
    string s; cin >> s;
    int n; cin >> n;
    rep(i, 0, n) {
        string com; cin >> com;
        int a, b; cin >> a >> b;
        if (com == "print") {
            string t = s.substr(a, b - a + 1);
            cout << t << endl;
        }
        else if (com == "replace") {
            string p; cin >> p;
            int idx = 0;
            rep(i, a, b+1) {
                s[i] = p[idx++];
            }
        }
        else if (com == "reverse") {
            int idx = 0;
            rep(i, a, (b + a) / 2 + 1) {
                char tmp = s[i];
                s[i] = s[b - idx];
                s[b - idx] = tmp;
                idx++;
            }
        }
    }
}


Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

ll dp[110][2][10];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	int k;
	cin>>s>>k;
	dp[0][0][0]=1;
	rep(i,s.size())rep(j,2)rep(l,k+1){
		int now=s[i]-'0';
		rep(x,10){
			int nj=j,nl=l;
			if(j==0){
				if(now<x) continue;
			}
			if(now>x) nj=1;
			if(l==k) if(x!=0) continue; 
			if(x!=0) nl++;
			dp[i+1][nj][nl]+=dp[i][j][l];
		}
	}
	cout<<dp[s.size()][0][k]+dp[s.size()][1][k]<<endl;
}

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

int prime_size(ll g){
	ll i = 2;
	int count = 0;
	while (true){
		int number = 0;
		while(g%i==0){
			g /= i;
			number++;
		}
		if(number!=0){
			count++;
		}
		if(i*i > g){
			break;
		}
		i++;
	}
	if(g!=1){
		count++;
	}
	return count;
}

ll gcd(ll a, ll b){
    if(a < b){
        swap(a, b);
    }
    ll r = a % b;
    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

int main() {

    ll A, B;
    cin >> A >> B;
	if(min(A, B)==1){
		cout << 1;
		return 0;
	}
	ll g = gcd(A, B);
	int count = prime_size(g) + 1;
	cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>

#define rep(i, initial_value, max_value) for (uint64_t i{initial_value}; i < max_value; ++i)
#define fore(i, a) for(auto &i:a)
#define each(i, c) \
    for( \
        __typeof((c).begin()) i{(c).begin()}, __typeof((c).end()) end{(c).end()}; \
        i != end; \
        ++i \
    )
#define dbg(x) cerr << __LINE__ << ": " << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()
#define mp make_pair

using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
using i64 = long long; using i32 = long; using u64 = unsigned long long; using u32 = unsigned long;

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; }

// ===

void _main() {
  u32 n;
  u32 m;

  cin >> n >> m;

  u32 A[n];
  u32 B[m];
  u32 C[m];

  rep(i, 0, n) cin >> A[i];
  rep(i, 0, m) cin >> B[i] >> C[i];

  priority_queue<pair<int, int>> q;
  rep(i, 0, n) q.push(mp<int, int>(A[i], 1));
  rep(i, 0, m) q.push(mp<int, int>(C[i], B[i]));

  u64 ans{0};
  rep(i, 0, n) {
    auto p = q.top();
    q.pop();
    ans += p.first;

    if (p.second > 1) {
      p.second--;
      q.push(p);
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 4724
#include <bits/stdc++.h>
#define Pb push_back
using namespace std;
typedef long long ll;
const int MAXN = 2e3 + 7, Mod = 998244353;
inline int R() { int rt; scanf ( "%d", &rt ); return rt; }
inline int Mop ( int na ) { return na >= Mod ? na - Mod : na; }
inline ll Pow ( ll bs, int t ) { ll rt = 1; for ( ; t; t >>= 1, bs = bs * bs % Mod ) if ( t & 1 ) rt = rt * bs % Mod; return rt; }

ll c[MAXN << 1][MAXN << 1];

int main()
{
	int k = R(), n = R(), lm = n + k;
	for ( int i = 0; i <= lm; ++i ) c[i][0] = 1;
	for ( int i = 1; i <= lm; ++i )
		for ( int j = 1; j <= i; ++j )
			c[i][j] = Mop ( c[i - 1][j - 1] + c[i - 1][j] );
	for ( int i = 2; i <= k * 2; ++i )
	{
		int ans = 0, cnt = 0;
		for ( int j = 1; j <= i / 2; ++j ) if ( i - j <= k ) ++cnt;
		for ( int j = 0; j <= cnt && 2 * j <= n; ++j )
			ans = Mop ( ans + ( ( j & 1 ) ? Mod - 1 : 1 ) * c[cnt][j] % Mod * c[k + n - 2 * j - 1][k - 1] % Mod );
		printf ( "%d\n", Mop ( ans + Mod ) );
	}
	return 0;
}

Measured memory_bytes: 124032
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    int N, a, res = 0;
    cin >> N;
    REP(i, N) {
        cin >> a;
        while (a % 2 == 0) {
            res++;
            a /= 2;
        }
    }
    cout << res << endl;
    return 0;
}


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

int dp[100100];
int h[100100];

signed main() {

    memset(dp, 0x3f, sizeof(dp));

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

    dp[1] = 0;
    for ( int i = 1; i <= n; i++ ) {
        for ( int j = 1; j <= 2; j++ ) {
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i]-h[i+j]));
        }
    }

    cout << dp[n] << endl;

    return 0;
}

Measured memory_bytes: 1024
n = int(input())
a =list(map(int,input().split()))
f = True
for i in range(n):
    if a[i] % 2 != 0:
        continue
    if a[i] % 2 == 0:
        if a[i] % 3 == 0 or a[i] % 5 == 0:
            continue
        else:
            f = False
            break
if f == False:
    print("DENIED")
if f == True:
    print("APPROVED")

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

using namespace std;
typedef long long ll;

ll MOD = 1e9+7;

class mint{
    ll n;
public:
    mint(ll m = 0){
        n = ((m % MOD) + MOD) % MOD;
    }
    mint operator-() const {
        return mint(-n);
    }
    mint& operator+=(const mint& m){
        n += m.n;
        if(n >= MOD) n -= MOD;
        return *this;
    }
    mint& operator-=(const mint& m){
        n += MOD - m.n;
        if(n >= MOD) n -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& m){
        n *= m.n;
        n %= MOD;
        return *this;
    }
    mint operator+(const mint& m) const{
        mint res(*this);
        res += m;
        return res;
    }
    mint operator-(const mint& m) const{
        mint res(*this);
        res -= m;
        return res;
    }
    mint operator*(const mint& m) const{
        mint res(*this);
        res *= m;
        return res;
    }
    mint pow(ll t) const{
        if(t == 0) return mint(1);
        mint m = pow(t>>1);
        m *= m;
        if(t & 1 == 1) m *= *this;
        return m;
    }
    // for prime modulo
    mint inv() const{
        return pow(MOD-2);
    }
    mint& operator/=(const mint& m){
        (*this) *= m.inv();
        n %= MOD;
        return *this;
    }
    mint operator/(const mint& m) const{
        mint res(*this);
        res /= m;
        return res;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.n;
        return os;
    }
};

ll N,K;
mint c[100001];

int main(){
    cin >> N >> K;
    for(int i=K;i>=1;i--){
        for(int j=2;i*j<=K;j++){
            c[i] -= c[i*j];
        }
        c[i] += mint(K/i).pow(N);
    }
    mint ans(0);
    for(int i=1;i<=K;i++) ans += c[i] * mint(i);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4380
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

int main(){
    string s;
    cin >> s;
    int N = s.size();

    bool canMake = true;
    if(s[0] != '1') canMake = false;
    if(s[N - 1] != '0') canMake = false;
    for(int i = 0; i < N - 1; i++){
        if(s[i] != s[N - 2 - i]) canMake = false;
    }

    if(!canMake){
        cout << -1 << endl;
        return 0;
    }

    //canMake
    int node = 1; //見ている点
    for(int i = 0; i < N - 1; i++){
        if(s[i] == '1'){
            cout << node << " " << i + 2 << endl;
            node = i + 2;
        }
        else {
            cout << node << " " << i + 2 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1664
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int[] d = new int[b];
        int[][] e = new int[a][b];
        int[] sum = new int[a];
        int count = 0;
        for (int i = 0; i < b; i++) {
            d[i] = sc.nextInt();
        }
        for (int j = 0; j < a; j++) {
            for (int i = 0; i < b; i++) {
                e[j][i] = sc.nextInt();
                sum[j] += e[j][i] * d[i];
            }
            if (sum[j] + c > 0) {
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 22100
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}


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

  vi a(4,0);
  rep(i,3){
    int x,y;
    cin>>x>>y;
    x--;y--;
    a[x]++;
    a[y]++;
  }

  sort(all(a));
  YES(a[0]==1&&a[1]==1&&a[2]==2&&a[3]==2);


}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iterator>
#include <map>
#include <unordered_map>
#define ll long long int
#define vi vector<long long int>
#define vvi vector<vll>
#define vs vector<string>
#define vsf v.begin(),v.end()
#define pb push_back
#define mp make_pair
using namespace std;
int main(){
	ll i,n;
	cin>>n;
	vi v(n),dp(n);
	for(i=0;i<n;i++) cin>>v[i];
	dp[0]=0;
	dp[1]=abs(v[1]-v[0]);
	for(i=2;i<n;i++) dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));
	cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt(), m = sc.nextInt(), vn = 0, cnt = 0, p[] = new int[n];

		for(int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
			vn += p[i];
		}

		double b = vn / 4.0 / m;

		for(int i = 0; i < n; i++) {
			if(b <= p[i]) cnt++;
		}

		System.out.println(m <= cnt ? "Yes" : "No");
	}
}

Measured memory_bytes: 35940
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <fstream>
#include <stack>
#define LL long long
using namespace std;
int n,cnt,a[20],f[100001];
int dfs(int k){
    if(f[k])return f[k];
    int x=k;
    for(int i=cnt;i>=1;i--)
        if(k>=a[i])x=min(x,1+dfs(k-a[i]));
    return f[k]=x;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int k=6;
    while(k<100000)
        a[++cnt]=k,k*=6;
    k=9;
    while(k<100000)
        a[++cnt]=k,k*=9;
    cin>>n;
    cout<<dfs(n)<<endl;
    return 0;
}

Measured memory_bytes: 640
/*
   Created by Rahul Goel.
*/
/*******************************************************************************/
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
/*******************************************************************************/
using namespace std;
typedef long long ll;
typedef long double ld;
ll mod = 1000000007;
const int INF = 1e9;
const ll LINF = 1e18;
/*******************************************************************************/
/* For PBDS */
/*Two new methods X.order_of_key() and X.find_by_order()*/
/*
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
*/

/*******************************************************************************/
#define fastio          ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(c)          (c).begin(), (c).end()
#define pii             pair < ll, ll >
#define vi              vector < ll >
#define vb              vector < bool >
#define vvi             vector < vector < ll > >
#define vvb             vector < vector < bool > >
#define vpii            vector < pair < ll, ll > >
#define vvpii           vector < vector < pair < ll, ll > > >
#define present(c,x)    ((c).find(x) != (c).end())
#define cpresent(c,x)   (find(all(c),x) != (c).end())
#define uniq(c)         (c).resize(distance((c).begin(), unique(all(c))))
#define min_pq(t)       priority_queue < t, vector < t >, greater < t > >
#define max_pq(t)       priority_queue < t >
#define pb              push_back
#define ff              first
#define ss              second
/*******************************************************************************/
ll mod_sum() { return 0LL; }
template<typename T, typename... Args>
T mod_sum(T a, Args... args) { return ((a + mod_sum(args...))%mod + mod)%mod; }

ll mod_prod() { return 1LL; }
template<typename T, typename... Args>
T mod_prod(T a, Args... args) { return (a*mod_prod(args...))%mod; }
/*******************************************************************************/

/*
    Code begins after this.
*/


ll solve(){
    ll n, k;
    cin >> n >> k;
    vi vec(n), dp(n, LINF);
    for(ll i=0; i<n; i++)
        cin >> vec[i];
    for(ll i=0; i<k; i++)
        dp[i] = llabs(vec[0] - vec[i]);
    for(ll i=k; i<n; i++)
        for(ll j=1; j<=k; j++)
            dp[i] = min(dp[i], dp[i-j] + llabs(vec[i] - vec[i-j]));
    cout << dp[n-1] << endl;
    return 0;
}


int main(){
    fastio;

    ll t = 1;
    while(t--)
        solve();

    return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <cmath>
#include <string>
#include <cstdlib>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cctype>
#include <map>
#include <cstring>
#include <typeinfo>
#define REP(i,n) for(int i = 0;i < n ;i++)
#define FOR(i,m,n) for(int i= m ;i<n;i++)
using namespace std;

int main(void){
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];
  sort(a.begin(),a.end());

  if(a[2]==a[0]+a[1])cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

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

    int n, total = 0;
    cin >> n;
    vector<int> A(n);
    for(int i = 0; i < n; i++){
        cin >> A[i];
        total += A[i];
    }

    if(total % 10){
        cout << total << endl;
        return 0;
    }else{
        sort(A.begin(), A.end());
        for(int i = 0; i < n; i++){
            if((total - A[i]) % 10){
                cout << total - A[i] << endl;
                return 0;
            }
        }
    }
    cout << 0 << endl;

    return 0;
}

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

using ll = long long;
using ull = unsigned long long;
#define repi(n) for (long long i = 0; i < (n); ++i)
#define repj(n) for (long long j = 0; j < (n); ++j)
#define repk(n) for (long long k = 0; k < (n); ++k)
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(itr) for (auto&& v : (itr))
#define updatemax(t, v) (t = std::max(t, (v)))
#define updatemin(t, v) (t = std::min(t, (v)))

ll a[200100];
int main() {
  int n;
  ll k;
  cin >> n >> k;
  repi(n) cin >> a[i];
  sort(a, a + n);
  ll low = 0, high = 1e+10;
  while (high - low > 1) {
    ll middle = (low + high) / 2;
    ll count = 0;
    for (int i = n - 1; i >= 0 && a[i] > middle; --i) {
      count += (a[i] + middle - 1) / middle - 1;
      if (count > k) break;
    }
    // cout << low << " " << high << " " << middle << " " << (count > k ? "x" : "o") << endl;
    ((count > k) ? low : high) = middle;
  }
  cout << high << endl;
}


Measured memory_bytes: 5200
import java.util.*;
public class Main {
	
	static boolean[] used;
	static int[] r;
	static int[][] d;
	static int INF = Integer.MAX_VALUE/2, R;
	static long ans = INF;
	
	static void dfs(int now, long cost, int cnt) {
		if(cnt == R) {
			ans = Math.min(ans, cost);
			return;
		}
		for(int i : r)
			if(!used[i]) {
				used[i] = true;
				dfs(i, cost + d[now][i], cnt + 1);
				used[i] = false;
			}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		R = sc.nextInt();
		r = new int[R];
		used = new boolean[N];
		d = new int[N][N];
		Arrays.setAll(r, i -> sc.nextInt()-1);
		for(int i = 0; i < N; i++)
			for(int j = 0; j < N; j++)
				if(i != j)
					d[i][j] = INF;
		for(int i = 0; i < M; i++) {
			int A = sc.nextInt()-1;
			int B = sc.nextInt()-1;
			int C = sc.nextInt();
			d[A][B] = C;
			d[B][A] = C;
		}
		for(int k = 0; k < N; k++)
			for(int i = 0; i < N; i++)
				for(int j = 0; j < N; j++)
					d[i][j] = Math.min(d[i][j], d[i][k] + d[j][k]);
		for(int i : r) {
			used[i] = true;
			dfs(i, 0, 1);
			used[i] = false;
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 47144
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <bitset>

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define sz size()
#define pb push_back
#define mp make_pair
#define ALL(X) (X).begin(),(X).end()

using namespace std;

const int INF = 1000000000;
const double eps = 1e-8;

int main(void) {
	srand(time(nullptr));
  int n,k;
  cin>>n>>k;
  vector<bitset<1024>> bits(k);
  REP(i,k){
  	REP(j,n/2){
  		int m;cin>>m;
  		bits[i][m-1]=1;
  	}
  }
  while(true){
  	bitset<1024> seq;
  	REP(i,n){
  		if(rand()%2==0)
  			seq[i]=1;
  	}
  	bool valid=true;
  	REP(i,k){
  		int cnt=0;
  		REP(j,n){
  			if(bits[i][j]&&seq[j])
  				cnt++;
  		}
  		if(cnt<(n/8)||cnt>(3*n/8)){
  			valid=false;
  			break;
  		}
  	}
  	if(valid){
  		REP(i,n){
  			cout<<seq[i]?'1':'0';
  		}
  		cout<<endl;
  		break;
  	}
  }
  return 0;
}

Measured memory_bytes: 1260
#include <iostream>

using namespace std;

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

	string s;
	cin >> s;

	int i = 0;
	while(s[i] == 'R')
		i++;

	while(!s.empty() && s.back() == 'W')
		s.pop_back();

	int tmp = i;
	int w = 0, r = 0;
	for(; i < s.size(); i++)
	{
		if(s[i] == 'W')
			w++;
		else
			r++;
	}

	int inplace = 0;
	for(int i = tmp; i < tmp + r && i < s.size(); i++)
	{
		if(s[i] == 'R')
			inplace++;
	}

	cout << r - inplace << endl;
}


Measured memory_bytes: 3716
// finish date: 2018/02/02
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000

#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;

// finish date: 2018/01/31
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000

#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>

using namespace std;

struct Union_Find {
    vector<int> parent;
    vector<int> sizes;
    int setnum = 0;

    Union_Find(int n) : parent(n), sizes(n, 1) {
        rep(i, n) parent[i] = i;
        setnum = n;
    }

    int find(int x) {
        if (x == parent[x]) return x;
        return parent[x] = find(parent[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);

        if (x == y) return;

        if (sizes[x] < sizes[y]) swap(x, y);

        parent[y] = x;
        sizes[x] += sizes[y];
        setnum--;
    }

    bool isSame(int x, int y) {
        return find(x) == find(y);
    }

    int size(int x) {
        return sizes[find(x)];
    }

};

int main() {
    int N, K, L;
    cin >> N >> K >> L;
    int a, b;
    Union_Find uf(N);
    rep(i, K) {
        cin >> a >> b;
        a--;
        b--;
        uf.unite(a, b);
    }
    Union_Find uf2(N);
    rep(i, L) {
        cin >> a >> b;
        a--;
        b--;
        uf2.unite(a, b);
    }
    map<pair<int, int>, int> mp;
    rep(i, N) {
        mp[{uf.find(i), uf2.find(i)}]++;
    }
    rep(i, N) {
        cout << mp[{uf.find(i), uf2.find(i)}] << " ";
    }

    return 0;
}



Measured memory_bytes: 15104
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <complex>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack> 
#include <bitset>
#include <queue>
#include <assert.h>
using namespace std;

int main()
{
	int a[10];
	for (int i = 0; i < 5; i++) cin >> a[i];
	for (int i = 0; i < 5; i++) {
		if (!a[i]) {
			cout << i  + 1 << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
using vi = vector<int>;
using vl= vector<ll>;
using vs=vector<string>;

ll gcd(ll a, ll b) { if (a == 0) return b; return gcd(b % a, a);}
ll max(ll a, ll b) {if (a > b) return a; else return b;}
ll min(ll a, ll b) {if (a < b) return a; else return b;}
ll power(ll a,ll b) {long long res = 1; while (b > 0) {if (b & 1)res = res * a;a = a * a;b >>= 1;} return res;}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int testcase=1;
    
    for(int p=0;p<testcase;p++){
        ll a=0;
        cin>>a;
        cout<<a+power(a,2)+power(a,3);
        
        
        
        }

    return 0;
}


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

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

int n[5],X,Y;
vector<int> a[5];

void nhap()
{
    scanf("%d %d",&X,&Y);
    for (int i=1;i<=3;++i)
        scanf("%d",&n[i]);
    for (int i=1;i<=3;++i)
    {
        for (int j=1;j<=n[i];++j)
        {
            int x;
            scanf("%d",&x);
            a[i].push_back(x);
        }
        sort(a[i].begin(),a[i].end(),greater<int>());
    }
}

void process()
{
    for (int i=0;i<X;++i)
        a[3].push_back(a[1][i]);
    for (int i=0;i<Y;++i)
        a[3].push_back(a[2][i]);
    sort(a[3].begin(),a[3].end(),greater<int>());
    long long sum=0;
    for (int i=0;i<X+Y;++i)
    {
        sum+=a[3][i];
    }
    cout<<sum;
}

int main()
{
    nhap();
    process();
    return 0;
}


Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<iomanip>
using namespace std;

int main()
{
    int T, t, a, i, N, K;
    vector<int> data;
    cin>>N>>K;
    for(i=0;i<N;i+=1)
    {
        cin>>a;
        data.push_back(a);
    }
    sort(data.begin(), data.end());
    int sum=0;
    for(i=0;i<K;i+=1)
    {
        sum+=data[i];
    }
    cout<<sum<<endl;
}


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

using ll = long long;

template<typename T>
T gcd(T a, T b)
{
	if (a < b)	return gcd(b, a);
	T r;
	while ((r = a % b))
	{
		a = b;
		b = r;
	}
	return b;
}

template<typename T>
T lcm(T a, T b)
{
	return a * b / gcd(a, b);
}

template<typename T>
T ext_gcd(T a, T b, T& x, T& y)
{
	x = 1;
	y = 0;
	T x0 = 0, y0 = 1;
	while (b != 0)
	{
		T q = a / b;
		a -= q * b;
		swap(a, b);
		x -= q * x0;
		swap(x, x0);
		y -= q * y0;
		swap(y, y0);
	}
	return a;
}

template<typename T>
T inv_mod(T a, T mod)
{
	T t1, t2;
	ext_gcd(a, mod, t1, t2);
	t1 %= mod;
	if (t1 < 0)		t1 += mod;
	return t1;
}

template<typename T>
T combination_large(T n, T k, T mod)
{
	if (n < k || n < 0 || k < 0)	return 0;
	vector<T> inv(n + 1, 1), fact(n + 1, 1), fact_inv(n + 1, 1);
	for (T i = 2; i <= n; ++i)
	{
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fact[i] = (fact[i - 1] * i) % mod;
		fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
	}
	return fact[n] * (fact_inv[k] * fact_inv[n - k] % mod) % mod;
}

template<typename T>
T combination(T n, T k, T mod = 1)
{
	vector<vector<T>> table(n + 1, vector<T>(k + 1, 1));
	for (T i = 1; i <= n; ++i)
	{
		table[i][0] = 1;
		for (T j = 1; j <= n; ++j)
		{
			table[i][j] = (table[i - 1][j - 1] + table[i - 1][j]) % mod;
		}
	}
}

int main(int, char**)
{
	string s;
	cin >> s;
	int counter = 0;
	for (size_t i = 0; i < s.length() / 2; ++i)
	{
		counter += s[i] != s[s.length() - 1 - i];
	}
	cout << counter << endl;
	return 0;
}


Measured memory_bytes: 256
/**
 * Training to the municipal stage of ROI
**/ 
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define forn for(int i=0;i<n;i++)
#define form for(int j=0;j<m;j++)
#define pb push_back
#define mp make_pair
#define s second
#define f first
#define kek cout<<"\n"
#define all(v)        ((v).begin()), ((v).end())
#define pob pop_back()
int main()
{
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);
 int a,b;
 cin>>a>>b;
 if(a<2*b) cout<<"0";
 else cout<<a-2*b;
 
 return 0;
 
}

Measured memory_bytes: 256
N, M = list(map(int, input().split()))
f = 0
for i in range(M):
    if i==0:
        L1, R1 = list(map(int, input().split()))
    else:
        L2, R2 = list(map(int, input().split()))
        if R1 < L2 or L1 > R2:
            print(0)
            f+=1
            break
        elif L2<L1 and R1<R2:
            continue
        elif L1<L2 and R2<R1:
            L1 = L2
            R1 = R2
        elif L2<L1 and R2<R1:
            R1 = R2
        elif L1<L2 and R1<R2:
            L1 = L2
        else:
            continue
s = set(range(L1,R1+1))
if f!=1:
    print(len(s))

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

int main() {
    int X;
    cin >> X;
    int Y = X/100;
    int Z = X%100;
    if(Z <= Y*5) {
        cout << 1 << endl;
    }
    else {
        cout << 0 << endl;
    }
}

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

int main()
{
    int X,A;
    std::cin >> X >> A;
    if (X < A) {
        std::cout << 0 << '\n';
    } else {
        std::cout << 10 << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
x = input()
mark = []
num = []
for i in xrange(x):
    inp = raw_input().split()
    inp[1] = int(inp[1])
    mark.append(inp)

trump = ["S","H","C","D"]
for i in xrange(4):
    for j in xrange(13):
        tako = [str(trump[i]), int(j + 1)]
        p = len(mark)
        for k in range(p):
            if tako == mark[k]:
                del mark[k]
                break
            if k == (p - 1):
                mark.append(tako)
for i in xrange(len(mark)):
    print mark[i][0], mark[i][1]

Measured memory_bytes: 6468
ary = gets.strip.split(' ').map(&:to_i)
ary2 = gets.strip.split(' ').map(&:to_i)
ary3 = gets.strip.split(' ').map(&:to_i)
ans = ary + ary2 + ary3
if ans.inject(:+) == 15
  puts "YES"
else
  puts "NO"
end

Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;
using PAIR = pair<int, int>;
using PAIRLL = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;

#define TR ","
#define fi first
#define se second
#define rep(i,N) for(ll i=0;i<(ll)N;++i)
#define repe(i,a,b) for(ll i=a;i<(ll)b;++i)
#define all(v) v.begin(), v.end()
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define INF 100000000

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

ll lcm(ll x, ll y) {
    return x / gcd(x, y) * y;
}

ll waz = 76543217;

ll inv(ll x) {
    if (x == 1) { return 1; }
    if (x == 0) { return 0; }
    else {
        ll a = (waz - inv(waz % x) * (waz / x)) % waz;
        if (a >= 0) { return a; }
        else { return waz + a; }
    }
}

void printVector(const vector<int>& vec) {
    for (int value : vec) {
        cout << value << " ";
    }
    cout << endl;
}

vector<ll> p;

ll phi(ll x) {
    ll a = x;
    ll b = x;
    for (ll k = 0; k != p.size(); ++k) {
        if (a % p[k] == 0) {
            while (a % p[k] == 0) {
                a /= p[k];
            }
            b = b / p[k] * (p[k] - 1);
        }
        if (a == 1) { break; }
    }
    return b;
}

bool my_compare(pair<string, int> a, pair<string, int> b) {
    if (a.first != b.first) {
        return a.first < b.first;
    }

    if (a.second != b.second) {
        return a.second > b.second;
    }
    else {
        return true;
    }
}

int main()
{
    IO;
    
    ll N, Q; cin >> N;
    deque<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(all(A));
    cin >> Q;

    ll B, C;
    vector<PAIRLL > PA(Q);

    map<ll, ll> ma;

    rep(i, Q) {
        cin >> B >> C;
        PA[i] = make_pair(B, C);
    }

    ll ans = 0;

    rep(i, N) {
        ans += A[i];
    }

    rep(i, N) {
        ++ma[A[0]];
        A.pop_front();
    }

    rep(i, Q) {
        ans += ma[PA[i].first] * (PA[i].second - PA[i].first);
        ma[PA[i].second] += ma[PA[i].first];
        ma[PA[i].first] = 0;
        cout<<ans<<endl;
    }

}

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

int main(){
  int N;
  cin >> N;
  int h[N];
  for(int i=0;i<N;i++)cin >> h[i];
  
  vector<int>dp(N);
  dp[0]=0;
  dp[1]=abs(h[1]-h[0]);
  int i=2;
  while(1){
    dp[i]= min(dp[i-1]+abs(h[i]-h[i-1]),
               dp[i-2]+abs(h[i]-h[i-2]));
    if(i>=N-1)break;
    i++;
  }
  cout << dp[N-1]<<endl;

}
  

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#define LL long long
#define LD long double
using namespace std;
const int NN=100000 +117;
const int MM=100000 +117;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
void open(){
	freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
}
void close(){
	fclose(stdin);
	fclose(stdout);
}


int m,n,s;
int p[NN]={};
LL cnt[NN]={};
int main(){
	//open();
	n=read();
	s=read();
	LL ans=0;
	for(int i=1;i<=n;++i){
		p[i]=read();
		cnt[i]=read();
	}
	int l=1;
	int r=n;
	int pre=0;
	while(p[l]<=s&&s<=p[r]){
		if(cnt[l]>=cnt[r]){
			if(pre!=l){
				ans+=p[r]-p[l];
				pre=l;
			}
			cnt[l]+=cnt[r];
			--r;
		}
		else{
			if(pre!=r){
				ans+=p[r]-p[l];
				pre=r;
			}
			cnt[r]+=cnt[l];
			++l;
		}
	}
	ans+=max(abs(p[r]-s),abs(p[l]-s));
	printf("%lld\n",ans);
	close();
	return 0;
}

Measured memory_bytes: 1408
x, y, z, k = map(int, input().split())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
cc = list(map(int, input().split()))

aa.sort(reverse=True)
aa = aa[:k]
bb.sort(reverse=True)
bb = bb[:k]
cc.sort(reverse=True)
cc = cc[:k]

dd = [a+b for a in aa for b in bb]
dd.sort(reverse=True)
dd = dd[:k]

ee = [a+b for a in dd for b in cc]
ee.sort(reverse=True)
ee = ee[:k]
print(*ee, sep='\n')

Measured memory_bytes: 160072
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int A = sc.nextInt();
      		int B = sc.nextInt();
      if(A<10&&B<10){
      System.out.println(A*B); 
      }else{
              System.out.println("-1"); 
      }

    }
  
  private static long lcm(long m, long n) {
    return m * n / gcd(m, n);
}
  
  private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
   ll n; cin >> n;
   vector<char> alpha;
   alpha.push_back('z');
   for(char i = 'a'; i<='z'; i++){
      alpha.push_back(i);
   }

   string ans;
   if(n>26LL){
      n -= 1;
   }
   else{
      cout << alpha.at(n%26) << endl;;
      return 0;
   }

   while(n>=26LL){
      ll tmp = (n+1)%26LL;
      if(tmp!=0) ans.push_back(alpha.at(tmp));
      else ans.push_back(alpha.at(26));
      n -= 26;
      n /= 26;
   }

   dump(n);
   ans += alpha.at(n+1);
   reverse(ans.begin(), ans.end());

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


Measured memory_bytes: 3572
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.StringTokenizer;

public class Main {
	// AtCoder Beginner Contest 081
	// https://atcoder.jp/contests/abc081/tasks
	final static int MOD = 10007;
	
	public static void main(String[] args) {
		FastReader sc = new FastReader();
		int a = sc.nextInt();
		int b = sc.nextInt();
		int cost = b;
		
		if (a <= 5) {
			cost = 0;
		} else if (a >= 6 && a <=12) {
			cost = b / 2 ;
		}
		System.out.println(cost);
	}

		
	static class FastReader { 
        BufferedReader br; 
        StringTokenizer st; 
  
        public FastReader() { 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
  
        String next() { 
            while (st == null || !st.hasMoreElements()) { 
                try { 
                    st = new StringTokenizer(br.readLine()); 
                } catch (IOException  e) { 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
  
        int nextInt() { 
            return Integer.parseInt(next()); 
        } 
  
        long nextLong() { 
            return Long.parseLong(next()); 
        } 
  
        double nextDouble() { 
            return Double.parseDouble(next()); 
        } 
  
        String nextLine() { 
            String str = ""; 
            try{ 
                str = br.readLine(); 
            } catch (IOException e) { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
    } 
}


Measured memory_bytes: 22996
#include<iostream>
#include<algorithm>

using namespace std;

int main() {
	int a, b, k;
	cin >> a >> b >> k;
	int m = min(a, b);
	for (int i = m; i > 0; i--) {
		if (a%i == 0 && b%i == 0) {
			k--;
			if (k == 0)cout << i << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<stack>
#include<unordered_map>
#include<bitset>
#include<limits>
#include<array>
using namespace std;
#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define REP(i,n) rep(i,0,n)
#define ll long long

ll dp[6060][2020];

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


	ll n, m;
	cin >> n >> m;
	dp[0][0] = 1;
	n *= 3;
	REP(i, n) {
		REP(j, n / 3 + 1) {
			if (dp[i][j] == 0)continue;
			(dp[i + 1][j] += dp[i][j]) %= m;
			(dp[i + 2][j + 1] += dp[i][j] * (n - i - 1) % m) %= m;
			(dp[i + 3][j + 1] += dp[i][j] * (n - i - 1) * (n - i - 2) % m) %= m;
		}
	}
	ll ans = 0;
	REP(i, n / 3 + 1)(ans += dp[n][i]) %= m;
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 93440
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <iomanip>
#include <string>

using namespace std;

int main() {
    string s;
    cin>>s;
    bool flg=true;
    for(int i=0;i<s.size();++i){
      if(i%2==1 && s[i]=='R'){
        flg=false;
      }
      else if(i%2==0 && s[i]=='L'){
        flg=false;
      }
    }
    if(flg){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }

   return 0;
 }


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <stdlib.h>
#include <deque>  
#include <iomanip>

using namespace std;

#define ll long long
#define INF 1e9
#define MOD 1e9 + 7
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop(i, a, n) for(int i = a; i < n; i++)
#define all(in) in.begin(), in.end()

int main(){
    double W, H, x, y;
    cin >> W >> H >> x >> y;
    double ans = 0;
    double num = 0;
    ans = W * H/2;
    if(x == W/2 && y == H/2) num = 1;
    cout << ans << " " << num << endl;
    return 0;
}

Measured memory_bytes: 256
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a_cnt = 0
    for i in range(1, n + 1):
        if i % 2 != 0:
            cnt = 0
            t = i
            cnt = 0
            for j in range(1, i + 1):
                if t % j == 0:
                    cnt += 1
            if cnt == 8:
                a_cnt += 1
    print(a_cnt)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38384