akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <sstream>

#define rep(i, j) for(int i = 0; i < j; i++)
#define all(i) i.begin(), i.end()
#define ll long long

using namespace std;

string Num2Str(int num)
{
	stringstream ss;
	ss << num;
	return ss.str();
}

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

	int a, b;
	string s;
	// code
	while (cin >> a >> b)
	{
		s = Num2Str(a + b);
		cout << s.size() << endl;
	}

	return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
using namespace std;

int main() {
    int n, d;
    cin >> n >> d;
    int ans = (n % (2 * d + 1) == 0) ? n / (2 * d + 1) : n / (2 * d + 1) + 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main()
{
    int n;
    scanf("%d",&n);
    int *order;
    order=(int *)malloc(n*sizeof(int));
    int tmp;
    for (int i = 0; i < n; i++)
    {
        scanf("%d",&tmp);
        order[tmp-1]=i+1;
    }
    for (int i = 0; i < n; i++)
    {
        printf("%d ",order[i]);
    }
    return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,n)  for(ll i=0;i<n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef pair<int,int> pii;
int main()
{
	IOS;
	//int t; cin>>t;
	int t=1;
	while(t)
	{
		int n,k; cin>>n>>k;
		int p[n];
		f(i,n) cin>>p[i];
		sort(p,p+n);
		ll ans=0;
		f(i,k) ans=ans+p[i];
		cout<<ans;
		t--;
	}
	return 0;
}

Measured memory_bytes: 3656
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int M1, D1, M2, D2;

  std::cin >> M1 >> D1 >> M2 >> D2;

  std::cout << (D1 + 1 == D2 ? 0 : 1) << std::endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] str = new String[210];
      
		int num = sc.nextInt();
      	for (int i = 0; i < num; i++) {
          str[i] = sc.next();
        }
		int count = 0;			// 操作を行った数
		boolean flag = true;	// 奇数があったらfalse

      	while (flag) {
			for (int i = 0; i < num; i++) {
				flag &= Integer.parseInt(str[i]) % 2 == 0;
			}
			if (!flag) {
				break;
			}
			count++;
			for (int i = 0; i < num; i++) {
				str[i] = String.valueOf(Integer.parseInt(str[i]) / 2);
			}
		}

		System.out.println(count);
	}
}

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

using namespace std;
using llong = long long;
using ldbl = long double;
using lpair = pair<llong, llong>;

#define ALL(x) x.begin(), x.end()

template<typename T>
constexpr T inf = static_cast<T>(pow(10, static_cast<int>(log10(numeric_limits<T>::max())))) + 7;
constexpr llong mod = 1e9+7;

int main() {
  int N, K;
  cin >> N >> K;

  int ans = 0;
  while (N) {
    ++ans;
    N /= K;
  }

  cout << ans << endl;

  return 0;
}

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

using namespace std;

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

string mapa[808];
int visited[808][808];
int dir[4][2] = {{0,1}, {1,0}, {-1, 0}, {0, -1}};

int n,m,k;

bool isok(int x, int y) {
    return x >= 0 && x < n && y >= 0 && y < m && mapa[x][y] != '#' && visited[x][y] == -1;
}

int main()
{
    memset(visited,-1,sizeof(visited));

    cin>>n>>m>>k;
    for(int ctr1 = 0; ctr1 < n; ctr1++)
        cin>>mapa[ctr1];
    queue<ii> bfs;
    for(int ctr1 = 0;ctr1<n;ctr1++)
    for(int ctr2 = 0; ctr2<m; ctr2++) {
        if(mapa[ctr1][ctr2] == 'S')
            bfs.push(make_pair(ctr1,ctr2)), visited[ctr1][ctr2] = 0;
    }
    while(!bfs.empty()) {
        ii cur = bfs.front();
        bfs.pop();
        for(int ctr1 = 0; ctr1 < 4; ctr1++) {
            ii nxt = make_pair(cur.first + dir[ctr1][0], cur.second + dir[ctr1][1]);
            if(isok(nxt.first, nxt.second)) {
                visited[nxt.first][nxt.second] = visited[cur.first][cur.second] + 1;
                bfs.push(nxt);
            }
        }
    }

    int rez = n*m + 10;
    for(int ctr1 = 0; ctr1 < n; ctr1++) {
        for(int ctr2 = 0; ctr2<m;ctr2++) {
            if(visited[ctr1][ctr2] <= k && visited[ctr1][ctr2] != -1) {
                    rez = min(rez, 1 + (min(min(ctr1, n - 1 - ctr1), min(ctr2, m - 1 - ctr2)) + k - 1)/k);
            }
        }
    }
    cout<<rez;
    return 0;
}


Measured memory_bytes: 3712
#include<bits/stdc++.h>
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define show(x) std::cerr << #x << "=" << x << std::endl
using namespace std;
typedef long long ll;
const double eps=1e-8;
const int maxn = 2e5+5;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
int t;
int n,m;
bool check(int n)
{
    if(n%2==0 && n/2>=0) return true;
    return false;
}
int main()
{
    int x,y;
    cin>>x>>y;
    if(check(y-2*x) && check(4*x-y)) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>

using namespace std;

int main(){
    int k;
    int flag = 0;
    vector<int> A(5,0);
    cin >> A[0] >> A[1] >> A[2] >> A[3] >> A[4];
    cin >> k;

    for(int j = 0;j < 5;j++){
    for(int h = 0; h < 5;h++){
        if(abs(A[j] - A[h]) > k){
            flag = 1;
        } 
        }
    }



    if(flag == 1){cout << ":(" << endl;}
    else{cout << "Yay!" << endl;}
    return 0;
}

Measured memory_bytes: 256
/*
Date: 2017/01/22 19:44:43 Sunday
*/
#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define rep(i,a,n) for(int i=(a);i<=(n);++i)
#define dep(i,a,n) for(int i=(a);i>=(n);--i)
#define eps 1e-8
#define pi 3.1415926535897
#define sqr(x) ((x)*(x))
#define MAX(a,b) a=max(a,b)
#define MIN(a,b) a=min(a,b)
#define SZ(x) ((int)(x).size())
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define POSIN(x,y) (1<=(x)&&(x)<=n&&1<=(y)&&(y)<=m)
#define all(x) (x).begin(),(x).end()
#define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
#define buli(x) (__builtin_popcountll(x))
#define bur0(x) (__builtin_ctzll(x))
#define bul2(x) (63-__builtin_clzll(x))
#define pw(x) ((ll(1))<<(x))
#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))
#define mmo(a,b) (((a)=1ll*(a)*(b)%mo)<0?(a)+=mo:(a))
#define y0 y0z
#define y1 y1z
#define yn ynz
#define j0 j0z
#define j1 j1z
#define jn jnz
#define tm tmz
#ifdef LOCAL
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...) 
#endif
typedef long long ll;
typedef double lf;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<lf,lf> pff;
typedef complex<double> CD;
const int inf=0x3f3f3f3f;
const int mo=1000000007;
inline void gn(long long&x){
	int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
	while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
inline void gn(double&x){double t;scanf("%lf",&t);x=t;}
inline void gn(long double&x){double t;scanf("%lf",&t);x=t;}
template<class T1,class T2>inline void gn(T1&r,T2&s){gn(r),gn(s);}
template<class T1,class T2,class T3>inline void gn(T1&r,T2&s,T3&t){gn(r),gn(s),gn(t);}
template<class T1,class T2,class T3,class T4>inline void gn(T1&r,T2&s,T3&t,T4&u){gn(r),gn(s),gn(t),gn(u);}
inline void gs(char *s){scanf("%s",s);}
inline void gc(char &c){while((c=getchar())>126 || c<33);}
inline void pc(char c){putchar(c);}
const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
ll powmod(ll a,ll b) {ll res=1;a%=mo;for(;b;b>>=1){if(b&1)res=res*a%mo;a=a*a%mo;}return res;}
ll powmod(ll a,ll b,ll mo) {ll res=1;a%=mo;for(;b;b>>=1){if(b&1)res=res*a%mo;a=a*a%mo;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//*******************************************

const int N=111111,M=111111;
int l,m,n,t,C;
vector<int>a[N];
int f[N];
int dfs(int x){
	vector<int>V;
	for(auto i:a[x])V.pb(dfs(i));
	sort(V.begin(),V.end());
	int ans=0;
	rep(i,0,SZ(V)-1)MAX(ans,V[i]-i+SZ(V));
	return ans;
}
int main(){
#ifdef LOCAL
	freopen("B.in","r",stdin);//freopen("B.out","w",stdout);
#endif
	scanf("%d",&n);rep(i,2,n)scanf("%d",&f[i]),a[f[i]].pb(i);
	printf("%d\n",dfs(1));
	return 0;
}

Measured memory_bytes: 14208
s = input()
co = 1
t = s[0]
i = 1
while i<len(s)-1:
    if len(t) == 2:
        co += 1
        t = s[i]
        i += 1
    elif t == s[i]:
        t = s[i:i+2]
        i += 2
        co += 1
    else:
        t = s[i]
        i += 1
        co += 1
if i==len(s)-1 and t!=s[-1]:
    print(co+1)
else:
    print(co)

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

int main(){
  int N;
  cin >> N;
  vector<pair<long, long> > A(N);
  for(int i=0; i<N; i++){
    cin >> A[i].first >> A[i].second;
  }
  sort(A.begin(), A.end());
  int num =0;
  long x=A[0].first+A[0].second;
  for(int i=1; i<N; i++){
    if(x>=A[i].first+A[i].second){
      num++;
      x=A[i].first+A[i].second;
      continue;
    }
    if(x>A[i].first-A[i].second){
      num++;
      continue;
    }
    x=A[i].first+A[i].second;
  }
  cout << N-num << endl;
  return 0;
}

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

typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define ALL(obj) (obj).begin(), (obj).end()
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; }

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


int main() {
    cout<<fixed<<setprecision(10);
    ll a,b; cin>>a>>b;
    cout<<a*b<<endl;

    return 0;

}

Measured memory_bytes: 3592
#include <iostream>
#include<vector>
using namespace std;
struct activity
{
  int a,b,c;
};
int VacationKeMaz(int n, vector<activity>& v)
{ 
    int dp[n+1][3];
    dp[1][0]=v[1].a;
    dp[1][1]=v[1].b;
    dp[1][2]=v[1].c;
    for(int i=2;i<=n;i++)
    {
        dp[i][0]=v[i].a+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=v[i].b+max(dp[i-1][0],dp[i-1][2]);
        dp[i][2]=v[i].c+max(dp[i-1][0],dp[i-1][1]);
    }
    return max(dp[n][0],max(dp[n][1],dp[n][2]));
}
int main() {
    int n;
    cin>>n;
    vector<activity> v(n+1);
    for(int i=1;i<=n;i++)
    {
        cin>>v[i].a;
        cin>>v[i].b;
        cin>>v[i].c;
    }
    cout<<VacationKeMaz(n,v);
}


Measured memory_bytes: 5624
#include <stdio.h>
int main() {
	int n, N, I;
	int x[25];
	while(1) {
		scanf("%d", &N);
		if(N == 0) break;
		for(I = 0; I < N; ++ I) scanf("%d", &x[I]);
		printf("%d\n", n = 31);
		I = 0;
		while(n != 1) {
			printf("%d\n", n -= x[I % N]);
			printf("%d\n", n -= 5 - x[I % N]);
			I ++;
		}
		printf("0\n");
	}
	return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
int N,K;
int main(){
  cin >> N;
  cin >> K;
  int distance = 0;
  for(int i=0;i<N;i++){
    int place;
    cin >> place;
    distance +=  2 * (K - place < place ? K - place : place);
  }
  cout << distance << endl;

}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

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

const double PI = 3.141592;

int main() {
  double r;
  cin >> r;
  double ans = 2.0*PI*r;
  printf("%.10f", ans);

  return 0;
}

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

string S;

int main() {
    cin >> S;

    vector<pair<char, int> > p;
    p.push_back(make_pair(S[0], 1));

    for (int i = 1; i < 4; i++) {
        bool f = true;
        for (int j = 0; j < p.size(); j++) {
            if (p[j].first == S[i]) {
                p[j].second++;
                f = false;
            }
        }
        if (f) p.push_back(make_pair(S[i], 1));
    }

    bool f = true;
    for (int i = 0; i < p.size(); i++) {
        if (p[i].second != 2) {
            cout << "No" << endl;
            f = false;
            break;
        }
    }
    if (f) cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}

//***********************************
//mintを定義
//***********************************
const int mod = 1000000007;
struct mint {
  int x;
  mint(int x=0):x(x%mod){}   //メンバ変数xをx%modで初期化
  int get() const { return (int)x; }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;           //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 {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }

  //累乗
  mint mpow(int t) const {
    if (!t) return 1;
    mint a = mpow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  //除算
  mint minv() const {
    return mpow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.minv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

//標準出力
ostream& operator<<(ostream& st, const mint a) 
{ st << a.get(); return st; };
//--------------------------------------------------

//***********************************
//場合の数の計算
//***********************************
const int MAX = 200010;
mint fac[MAX], finv[MAX];

//前計算
inline void INIT_F(){
    fac[0] = finv[0] = 1;
    for(int i=1; i<MAX-1; i++) {
        fac[i] = (fac[i-1]*mint(i));
        finv[i] = (finv[i-1]/mint(i));
    }
}

//nCk
mint mcomb(int n, int k) {
    if(n<k || k<0) return 0;
    else return ((fac[n]*finv[k])*finv[n-k]);
}

//nHk
mint mhcomb(int n, int k) {
  return mcomb(n+k-1, k);
}
//--------------------------------------------------

signed main() {
    string L;
    cin >> L;

    int l = L.size();
    V(V(mint)) dp(l+1, V(mint)(2, 0));
    dp[0][0] = 1;

    rep(i, l) {
        int D = L[i]-'0';
        rep(j, 2) {
            for(int k=0; k<=(j ? 1 : D); k++) {
                dp[i+1][j || (k<D)] += dp[i][j]*(k ? 2 : 1);
            }
        }
    }

    cout << dp[l][1] + dp[l][0] << endl;


  return 0;
}

Measured memory_bytes: 8960
#include<bits/stdc++.h>
using namespace std;
// #define int long long
#define ll long long
#define sz(a) (int)(a.size())
#define pb push_back
#define all(c) c.begin(),c.end()
#define tr(it,c) for(auto it=c.begin();it!=c.end();it++)
#define fr(i,n)	for(int i=0;i<n;i++)
#define present(c,x) (c.find(x)!=c.end()) //for set/map etc.
#define cpresent(c,x) (find(all(c),x)!=c.end())
typedef pair<int,int> pi;
	typedef vector<int> vi;
	typedef vector<vector<int>> vvi;
	typedef vector<long long> vll;
	typedef vector<pair<int,int>> vp;
int N=100001;
int mod=1e9+7;
int min(int a,int b){if(a<b) return a; else return b;}
int max(int a,int b){if(a>b) return a; else return b;}
int power(int a,int b){int res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int gcd(int p, int q){if(p%q==0) return q; else{return gcd(q,p%q);}} 
bool comp(int a, int b) 
{ 
    return (a < b); 
} 

// string s,t,s1,t1;
// int ans()
// {
// 	// string s1,t1;
// 	s1.erase(all(s1));
// 	t1.erase(all(t1));
// 	int n= s.size();
// 	char c = s[0];
// 	if(n==1)return 0;
// 	// int n_s= s.size(),n_t = t.size();
// 	fr(i,n-1)
// 	s[i]=s[i+1];
// 	s[n-1]=c;
// 	fr(i,n)
// 	{
// 		if(t[i]!=s[i])
// 		{
// 			s1.pb(s[i]);
// 			t1.pb(t[i]);
// 		}
// 	}
// // 	s.clear();
// // 	t.clear();
// 	s=s1;
// 	t=t1;
// 	if(s1.size()==0)return 0;
// 	else
// 	{
// 		return ans()+1;
// 	}
// }

void solve()
{
	int n;
	cin>>n;
	int a = n%1000;
	if(a==0)cout<<a;
	else cout<<1000-a;
}
int main()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
	// int t;
	// cin>>t;
	// while(t--)
	// {
	// 	solve();
	// 	cout<<endl;
	// }
	solve();
	return 0;
	
}



Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<numeric>
using namespace std;
#define INF (1 << 30) - 1
#define LINF 1LL << 60
const int MOD = 1000000007;
using ll = long long;
using P = pair<int, int>;

int dp[1 << 20][20];

int dist[20][20];

int main(){
  int n, m;
  cin >> n >> m;
  fill((int*)dist, (int*)dist + sizeof(dist) / sizeof(int), INF);
  for(int i = 0; i < m; ++i){
  	int s, t, d;
  	cin >> s >> t >> d;
  	dist[s][t] = d;
  }

  for(int i = 0; i < (1 << 20); ++i){
  	for(int j = 0; j < 20; ++j){
  		dp[i][j] = INF;
  	}
  }

  dp[0][0] = 0; 
  for(int s = 0; s < (1 << n); ++s){
  	for(int v = 0; v < n; ++v){ 
  		if(!(s & (1 << v)))continue;
  		int prev_s = s - (1 << v); 
  		for(int u = 0; u < n; ++u){ 
   			dp[s][v] = min(dp[s][v], dp[prev_s][u] + dist[u][v]);
  		}
  	}
  }

  if(dp[(1 << n) - 1][0] == INF)cout << -1 << endl;
  else cout << dp[(1 << n) - 1][0] << endl;
  return 0;
}



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


#define debug(x) cout << #x << " = " << x << endl;
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define FOR(it, b, e) for (typeof(b) it = (b); it != (e); ++it)
#define MSET(c, v) memset(c, v, sizeof(c))

const int INF = 0x3F3F3F3F; 
const int NEGINF = 0xC0C0C0C0;
const int NULO = -1;
const double EPS = 1e-10;
const ll mod = 1e9 + 7;

inline int cmp(double x, double y = 0) 
{  
  if(fabs(x - y) < EPS)
    return 0;
  return x > y ? 1 : -1;
}

ll exp(ll a, ll b)
{
  ll ans = 1;
  while(b)
  {
    if(b & 1)
      ans = (ans * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return ans;
}

const int maxn = 3e3 + 5;
ll fat[maxn], inv[maxn];

ll C(int n, int k)
{
  if(n < k) 
    return 0;
  if(n < 0 || k < 0) 
    return 0;
  return (((fat[n] * inv[k]) % mod) * inv[n - k]) % mod;
}

void initFactorials()
{
  fat[0] = 1;
  inv[0] = 1;
  for(int i = 1; i < maxn; i++)
  {
    fat[i] = (i * fat[i-1]) % mod;
    inv[i] = exp(fat[i], mod - 2);
  }
}

int graph[maxn][maxn];
int dist[maxn][maxn];


int main()
{
  MSET(graph, INF);
  MSET(dist, INF);
  
  ios::sync_with_stdio(false);
  int n,m,l;
  cin >> n >> m >> l;
  for(int i = 0; i < m ; i++)
  {
    int u,v,c;
    cin >> u >> v >> c;
    graph[u][v] = c;
    graph[v][u] = c;
  }


  for(int k = 1; k <= n; k++)
  {
    for(int i = 1 ; i <= n ; i++)
    {
      for(int  j = 1 ; j <= n ; j++)
      {
        if(graph[i][k] + graph[k][j] < graph[i][j])
        {
          graph[i][j] = graph[i][k] + graph[k][j];
        }
      }
    }
  }

  for(int i = 1 ; i <= n ; i++)
  {
    for(int  j = 1 ; j <= n ; j++)
    {
      if(graph[i][j] <= l )
        dist[i][j] = 1;
    }
  }


  for(int k = 1; k <= n; k++)
  {
    for(int i = 1 ; i <= n ; i++)
    {
      for(int  j = 1 ; j <= n ; j++)
      {
        if(dist[i][k] + dist[k][j] < dist[i][j])
        {
          dist[i][j] = dist[i][k] + dist[k][j];
        }
      }
    }
  }

  int q;
  cin >> q;
  while(q--)
  {
    int s,t;
    cin >> s >> t;
    int minCost = dist[s][t];
    if(minCost >= INF)
      minCost = -1;
    else
      minCost--;
    cout << minCost << endl;
  }

  return 0;
}

Measured memory_bytes: 74192
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 18 19:19:52 2020

@author: ezwry
"""

s=list(input())
t=list(input())
u=len(s)
ans=0
for i in range(u):
    if s[i] != t[i]:
        ans+=1
    
print(ans)

Measured memory_bytes: 12440
n = int(input())
arr = list(map(int, input().split()))
mod = 10**9 + 7

sum_arr = sum(arr)
sum_pow = 0

for a in arr:
  sum_pow = sum_pow + a*a

result = ((sum_arr*sum_arr) - sum_pow )//2 % mod

print(result)

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

template <class Abel> struct BIT {
    vector<Abel> dat[2];
    Abel UNITY_SUM = 0;                     // to be set
    
    /* [1, n] */
    BIT(int n) { init(n); }
    void init(int n) { for (int iter = 0; iter < 2; ++iter) dat[iter].assign(n + 1, UNITY_SUM); }
    
    /* a, b are 1-indexed, [a, b) */
    inline void sub_add(int p, int a, Abel x) {
        for (int i = a; i < (int)dat[p].size(); i += i & -i)
            dat[p][i] = dat[p][i] + x;
    }
    inline void add(int a, int b, Abel x) {
        sub_add(0, a, x * -(a - 1)); sub_add(1, a, x); sub_add(0, b, x * (b - 1)); sub_add(1, b, x * (-1));
    }
    
    /* a is 1-indexed, [a, b) */
    inline Abel sub_sum(int p, int a) {
        Abel res = UNITY_SUM;
        for (int i = a; i > 0; i -= i & -i) res = res + dat[p][i];
        return res;
    }
    inline Abel sum(int a, int b) {
        return sub_sum(0, b - 1) + sub_sum(1, b - 1) * (b - 1) - sub_sum(0, a - 1) - sub_sum(1, a - 1) * (a - 1);
    }
    
    /* debug */
    void print() {
        for (int i = 1; i < (int)dat[0].size(); ++i) cout << sum(i, i + 1) << ",";
        cout << endl;
    }
};

int main() {
    int N; cin >> N;
  int Q; cin >> Q;
    vector<int> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    
    vector<int> lefts(Q), rights(Q), ids(Q);
    for (int i = 0; i < Q; ++i) {
        cin >> lefts[i] >> rights[i];
        --lefts[i];
        ids[i] = i;
    }
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return rights[i] < rights[j];});

    BIT<int> bit(N+5);
    vector<int> prev(1100000, -1);
    vector<int> res(Q, 0);
    int r = 0;
    for (auto i : ids) {
        for (; r < rights[i]; ++r) {
            bit.add(prev[a[r]]+2, r+2, 1);
            prev[a[r]] = r;
        }
        int tmp = bit.sum(lefts[i]+1, lefts[i]+2);
        res[i] = max(res[i], tmp);
    }
    for (int i = 0; i < Q; ++i) cout << res[i] << endl;
}

Measured memory_bytes: 21728
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val strArray = Array(n) {
        readLine()!!.toCharArray().sortedArray().let { String(it) }
    }
    strArray.sort()
    var ans = 0L
    val list = Array<Long>(100010) { 0 }
    for (i in 2..100005) {
        list[i] = list[i - 1] + i - 1
    }
    var s = 0
    var str: String
    while (s < n) {
        str = strArray[s]
        var count = 0
        while (s < n && strArray[s] == str) {
            s++
            count++
        }
        ans += list[count]
    }
    println(ans)
}

Measured memory_bytes: 50116
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
int main(){
  int A, B; cin >> A >> B;
  int ans = -1;
  for(int i = 10; i <= 1000; i++){
    int tax8 = i * 0.08;
    int tax10 = i * 0.1;
    if(A == tax8 && B == tax10){
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		char[] left = {'q','w','e','r','t','a','s','d','f','g','z','x','c','v','b'};
		while(true){
			int cnt = 0;
			boolean left_hand = false;
			char[] input = stdIn.next().toCharArray();
			if(input[0]=='#'){
				return;
			}
			for(int j=0;j<left.length;j++){
				if(input[0]==left[j]){
					left_hand = true;
					break;
				}
			}
			for(int i=1;i<input.length;i++){
				boolean left_flag = false;
				for(int j=0;j<left.length;j++){
					if(input[i]==left[j]){
						left_flag = true;
						break;
					}
				}
				if(left_hand!=left_flag){
					cnt++;
					left_hand = left_flag;
				}
			}
			System.out.println(cnt);
		}
	}
}

Measured memory_bytes: 12000
'use strict';

function main(input) {
  const inputs = input.split(' ').map((x) => x | 0);

  const sum = inputs.reduce((a, b) => a + b);
  if (sum != 17) {
    console.log('NO');
    return;
  }

  let i = inputs.shift();
  while (i) {
    if (i != 5 && i != 7) {
      console.log('NO');
      return;
    }
    i = inputs.shift();
  }

  console.log('YES');
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21952
import std.stdio, std.string, std.conv, std.algorithm, std.range;

void main(){
    string line;
    while((line = readln).length){
        auto f = line.split.map!(to!real);
        auto ps = [
            f[0] + f[1] * 1.0i,
            f[2] + f[3] * 1.0i,
            f[4] + f[5] * 1.0i,
        ].cycle;
        auto p = f[6] + f[7] * 1.0i;
        real[3] res;
        foreach(i, ref r; res){
            r = cross(ps[i], ps[i+1], p);
        }
        if(res[0]>0&&res[1]>0&&res[2]>0||res[0]<0&&res[1]<0&&res[2]<0)
            "YES".writeln;
        else
            "NO".writeln;
    }
}

real cross(creal a, creal b, creal p)
{
    auto l = b - a, m = p - a;
    return l.re * m.im - l.im * m.re;
}

Measured memory_bytes: 1068
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  char a, b;
  cin >> a >> b;
  if(a == 'H'){
    if(b == 'H'){
      cout << 'H' << endl;
      return 0;
    }
    cout << 'D' << endl;
    return 0;
  }
  
  if(b == 'H'){
    cout << 'D' << endl;
    return 0;
  }
  cout << 'H' << endl;
  
}

Measured memory_bytes: 256
using System;
internal class Program
{
    private static void Main(string[] args)
    {
        string text = Console.ReadLine();
        string value = "No";
        bool flag = true;
        bool flag2 = true;
        for (int i = 0; i < text.Length; i++)
        {
            if (i % 2 == 0)
            {
                if (text[i] != 'R' && text[i] != 'U' && text[i] != 'D')
                {
                    flag = false;
                }
            }
            else if (text[i] != 'L' && text[i] != 'U' && text[i] != 'D')
            {
                flag2 = false;
            }
        }
        if (flag2 && flag)
        {
            value = "Yes";
        }
        Console.WriteLine(value);
    }
}

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,M=MAP()
lights=[[False]*N for i in range(M)]
for i in range(M):
    K=LIST()
    for j in range(1, K[0]+1):
        lights[i][K[j]-1]=True
P=LIST()

ans=0
for i in range(1<<N):
    cnts=[0]*M
    for j in range(N):
        for k in range(M):
            if i>>j&1:
                if lights[k][j]:
                    cnts[k]+=1
    for j in range(M):
        if cnts[j]%2!=P[j]:
            break
    else:
        ans+=1
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>

typedef struct List {
	struct List *next;
	int id;
} list;

int main()
{
	int i, N, Q, a[200001], b[200001], p[200001], x[200001];
	scanf("%d %d", &N, &Q);
	for (i = 1; i <= N - 1; i++) scanf("%d %d", &(a[i]), &(b[i]));
	for (i = 1; i <= Q; i++) scanf("%d %d", &(p[i]), &(x[i]));
	
	list *head[200001] = {}, adj[400001];
	for (i = 1; i <= N; i++) {
		adj[(i-1)*2].next = head[a[i]];
		adj[(i-1)*2].id = b[i];
		head[a[i]] = &(adj[(i-1)*2]);
		adj[i*2-1].next = head[b[i]];
		adj[i*2-1].id = a[i];
		head[b[i]] = &(adj[i*2-1]);
	}
	
	long long sum[200001] = {};
	for (i = 1; i <= Q; i++) sum[p[i]] += x[i];
	
	int h, t, q[200001] = {1}, flag[200001] = {0, 1};
	list *po;
	for (h = 0, t = 0; q[h] != 0; h++) {
		for (po = head[q[h]]; po != NULL; po = po->next) {
			if (flag[po->id] == 0) {
				flag[po->id] = 1;
				sum[po->id] += sum[q[h]];
				q[++t] = po->id;
			}
		}
	}
	
	for (i = 1; i <= N; i++) printf("%lld ", sum[i]);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 16384
n = int(input())
a = []
for i in range(n):
    a0 = int(input())
    a.append(a0)
ans = 0
key = "b"
count = 1
m = 0
for i in range(n):
    if key == "a":
        if a[i] == count:
            count += 1
        elif a[i] > count:
            if a[i]%count == 0:
                ans += a[i]//count - 1
            else:
                ans += a[i]//count
    else:
        if i == 0:
            ans += a[i]-1
            count += 1
        else:
            if a[i] == 2:
                key = "a"
                count = 3
                m = 2
            else:
                if a[i]%2 == 0:
                    ans += a[i]//2-1
                else:
                    ans += a[i]//2
    #print(ans,count)
print(ans)

Measured memory_bytes: 7192
N = int(input())

count = 10000000

for i in range (1, N//2+2):
	A = str(i)
	B = str(N-i)
	temp = 0
	for j in range (0, len(A)):
		temp+=int(A[j])
	for j in range (0, len(B)):
		temp+=int(B[j])
	count = min(count, temp)

print(count)

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

public class Main
{
	public static void main(String[] args)throws IOException
	{
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String card[] = br.readLine().split(" ");
		int sum = 0;
		sum = (Integer.parseInt(card[1]))*10 + (Integer.parseInt(card[2]));
		if(sum % 4 == 0) System.out.println("YES");
		else System.out.println("NO");
			
	}
}

Measured memory_bytes: 19284
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int a,b,c[110000],cnt=0;
string s;
signed main()
{
	cin>>a;
	double b=a;
	if(a%2==0){
		cout<<"0.5000000000000";
	}else{
		printf("%.6f",(a/2+1)/b);
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  char S[3], T[3];  // Sが予報, Tが実際の天気
  int count = 0;

  scanf("%s", S);   // SSR
  scanf("%s", T);   // SSR

  for(int i = 0; i < 3; i++) {
    if(S[i] == T[i]) {
      count++;
    }
  }

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

  return 0;
}

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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define DESYNC ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector< ii >
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }

int gcd(int a, int b){
  if(a == 0 || b == 0) return 0;
  else return abs(__gcd(a,b));
}

int32_t main(){
  DESYNC;
  int n,k;
  cin >> n >> k;
  int dp[n+1];
  int v[n+1];
  for(int i=1; i<=n; i++){
    cin >> v[i];
  }
  for(int i=0; i<=n; i++) dp[i] = INF;
  dp[1] = 0;
  for(int i=2; i<=n; i++){
    for(int j = max(1LL, i -k); j<i; j++){
      dp[i] = min(dp[i], dp[j] + abs(v[i] - v[j]));
    }
  }
  cout << dp[n] << endl;
}



Measured memory_bytes: 1792
#include<iostream>

using namespace std;

int min(int x,int y){
  if(x<y)return x;
  else return y;
}

int main(){
  int n,m,x;
  cin>>n>>m>>x;
  int tmp=0;
  for(int i=0;i<m;i++){
    int t;
    cin>>t;
    if(t<=x)tmp++;
  }
  cout<<min(tmp,m-tmp)<<endl;
}


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

using namespace std;

int main()
{
    long long a, b; cin >> a >> b;
    long long g = __gcd(a, b);

    int s = sqrt(g);

    int cnt = !(g % 2);
    while (g % 2 == 0)
        g /= 2;

    for (int i = 3; i <= s; i+=2)
    {
        bool bb = false;
        while (g % i == 0)
            g /= i, bb = true;
        cnt += bb;
    }

    cout << cnt + (g > 1) + 1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int gcd(int m, int n) {
    if (n < m) swap(n, m);
    while (m != 0) {
        int r = n % m;
        n = m;
        m = r;
    }
    return n;
}

struct Sieve {
    Sieve(int n) : l(n + 1, 0) {
        for (int i = 2; i <= n; i++) {
            if (!l[i]) p.push_back(l[i] = i);
            for (int q : p) {
                if (q > l[i]) break;
                if (int j = i * q; j <= n) l[j] = q; else break;
            }
        }
    }
    bool is_prime(int i) {
        return l[i] == i;
    }
    vector<int> l, p;
};

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

    int n;
    cin >> n;

    int m = (int)1e6;
    Sieve si(m);
    vector<char> b(m + 1, 0);
    vector<int> f(m + 1), g(m + 1, 0);
    int r = 0, x = 0;

    for (int i = 2;; i++) {
        int t = i * i;
        if (t > m) break;
        for (int j = t; j <= m; j += t) {
            g[j] = i;
        }
    }
    for (int i = 1; i <= m; i++) {
        f[i] = g[i] ? f[i / g[i]] : i;
    }

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

        a = f[a];
        x = gcd(x, a);
        if (r) continue;

        while (a > 1) {
            int t = si.l[a];
            if (b[t]) {
                r = 1;
                break;
            }
            b[t] = 1;
            a /= t;
        }
    }

    if (x != 1) r = 2;

    const char *c[3] = { "pairwise coprime", "setwise coprime", "not coprime" };
    cout << c[r] << endl;

    return 0;
}

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

int main() {
int a, b;
  cin >> a >> b;
  if(a==1) a= 234;
  if(b==1) b= 234;
  if(a>b) cout << "Alice" << endl;
  else if(a<b) cout << "Bob" << endl;
  else cout << "Draw" << endl;
}

Measured memory_bytes: 256
#ifdef _DEBUG
#include ".vscode/debug_print.hpp"
#else
#define debug(...)
#endif
#include <bits/stdc++.h>

using ll = long long;
using ld = long double;
using namespace std;
constexpr int INF32       = 1050000000;
constexpr long long INF64 = 4000000000000000000;
constexpr int MOD7        = 1000000007;
constexpr int MOD53       = 998244353;
constexpr long double PI  = 3.14159265358979323846;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}
void scan() {}
template <class H, class... T> void scan(H &&head, T &&... args) {
    std::cin >> head;
    scan(std::forward<T>(args)...);
}
template <class T> void scan(std::vector<T> &v) {
    for (auto &&i : v) {
        scan(i);
    }
}

void vprint() { std::cout << '\n'; }
template <class H, class... T> void vprint(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << '\n';
    vprint(std::forward<T>(args)...);
}
template <class T> void vprint(std::vector<T> &v) {
    for (auto &&i : v) {
        std::cout << i << '\n';
    }
}

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

    int x, N;
    scan(x, N);
    set<int> p;
    for (size_t i = 0; i < N; i++) {
        int a;
        scan(a);
        p.insert(a);
    }
    int mn  = INF32;
    int ans = 1;
    for (int i = -200; i <= 200; i++) {
        if (p.count(i) == 0 && chmin(mn, abs(x - i))) {
            ans = i;
        }
    }
    print(ans);

    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main() {
  string S; cin>>S;
  int ans = 700;
  if(S[0] == 'o') ans += 100;
  if(S[1] == 'o') ans += 100;
  if(S[2] == 'o') ans += 100;  
  cout << ans << endl;
  return 0;
}


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

#define ll long long
#define UN unsigned
#define pb push_back
#define mod 1000000007
#define mt make_tuple
#define f first
#define s second
typedef tuple<int, int> tii;
typedef pair<int, int> pii;

void solve()
{
    string s;
    cin >> s;

    int n = s.length();
    s = '.' + s;

    if(s[1] == '0' || s[n] == '1'){cout << -1 << endl; return;}

    bool flag = 0;

    for(int i=1; i<n; i++){
        if(s[n-i] != s[i]){
            flag = 1;
            break;
        }
    }

    if(flag){
        cout << -1 << endl;
        return;
    }
    s[n] = '1';
	queue<int> ones;
	for(int i = 1; i <= n; ++i){
		if(s[i] == '1'){
			ones.push(i);
		}
	}
	for(int i = 1; i < n; ++i){
		if(i == ones.front()){
			ones.pop();
		}
		cout << i << " " << ones.front() << endl;
	}
}

int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);

    solve();

    return 0;
}

Measured memory_bytes: 1900
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) (a<<b)
#define Rshift(a,b) (a>>b)
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;

int in[4][4];
int d[2];
int row[3], col[3];


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int i, j;
    rep(i, 3) rep(j, 3) {
        cin >> in[i][j];
    }
    int n;
    cin >> n;
    rep(i, n) {
        int x;
        cin >> x;
        int k;
        rep(j, 3) rep(k, 3) {
            if (in[j][k] == x) {
                row[j]++;
                if (row[j] >= 3) {
                    cout << "Yes" << endl;
                    return 0;
                }
                col[k]++;
                if (col[k] >= 3) {
                    cout << "Yes" << endl;
                    return 0;
                }
                if (j == k) {
                    d[0]++;
                    if (d[0] >= 3) {
                        cout << "Yes" << endl;
                        return 0;
                    }
                }
                if (j + k == 2 ) {
                    d[1]++;
                    if (d[1] >= 3) {
                        cout << "Yes" << endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout << "No" << endl;
}


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

int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0)  break;
        
        int s[n], p[n], q[n], r[n], c[n];
        int P, Q, R, C;
        
        for(int i = 0; i < n; i++){
            cin >> s[i] >> p[i] >> q[i] >> r[i];
            c[i] = 4*p[i] + 9*q[i] + 4*r[i];
        }
        
        cin >> P >> Q >> R >> C;
        
        bool found = false;
        for(int i = 0; i < n; i++){
            if(p[i] <= P && q[i] <= Q && r[i] <= R && c[i] <= C){
                found = true;
                cout << s[i] << endl;
            }
        }
        
        if(!found)  cout << "NA" << endl;
    }
    return 0;
}



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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

// https://www.hamayanhamayan.com/entry/2020/02/09/225141

string s;
ll K;
ll dp[101][2][5]; // i桁目まで確定していて、現時点でs以下であるかがjという状態で、0でない数字がk個ある数の個数

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>s>>K;
  ll n=s.size();
  
  dp[0][0][0]=1;
  rep(i,n) rep(j,2) rep(k,K+1){
    ll num=s[i]-'0';
    rep(nxt,10){
      if(num<nxt && j==0) continue; // s未満であることが未確定で、現在見ている桁より大きい値を採用することはできない
      
      ll nj=j;
      if(nxt<num) nj=1; // 今見ている桁より小さい値を採用するなら、以降はs未満であることが確定する
      ll nk=k;
      if(nxt!=0) nk++;
      dp[i+1][nj][nk]+=dp[i][j][k];
    }
  }
  ll ans=dp[n][0][K]+dp[n][1][K];
  cout<<ans<<endl;
}

Measured memory_bytes: 256
def to_n(X, n):
    out = 0
    while X>0:
        out += (X%n)
        X = int(X/n)
    return out
  
n = int(input())
ans = 10 ** 6
for i in range(n+1):
  tmp = 0
  res = n
  if not i % 9:
    tmp += to_n(i,9)
    res -= i
  tmp += to_n(res,6)
  ans = min(ans,tmp)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define X first
#define Y second
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;


template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int mod =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
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;
}

ll RS(ll N,ll P,ll M){
    if(P==0){
        return 1;
    }else{
        if(P%2==0){
            ll t=RS(N,P/2,M);
            return t*t%M;
        }else{
            return N*RS(N,P-1,M)%M;
        }
    }
}
int N;
string S;

bool notequal(char a,char b,char c){
    if(a==b||a==c||b==c)return false;
    return true;
}
int main() {
    ios::sync_with_stdio(false);
    int N=in();
    int K=in();
    double ans=0;
    REP1(i,N){
        if(i>=K){
            ans+=1;
        }else{
            double omote=1;
            int tokuten=i;
            while(tokuten<K){
                omote/=2;
                tokuten*=2;
            }
            // debug(i);debug(omote);
            ans+=omote;
        }
    }
    Sp(ans/N);
    return 0;
}


Measured memory_bytes: 256