akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
string n,s="";
long k,ans=0;
void aaa(long a,string b) {
  for(long i=n.size()-1;i>=0;i--) {
    if(b[i]=='0'&&(i==0||a>1)) {
      for(char j='1';j<='9';j++) {
        b[i]=j;
        if(a==k) {
          if(b<=n) ans++;
          else break;
        } else {
          if(b<=n) aaa(a+1,b);
          else break;
        }
      }
      b[i]='0';
    } else if(a>1) {
      return;
    }
  }
  return;
}
int main() {
  cin >> n >> k;
  for(long i=k;i<n.size();i++) {
    if(k==1) ans+=9;
    if(k==2) ans+=81*(i-1);
    if(k==3) ans+=729*(i-1)*(i-2)/2;
  }
  for(long i=0;i<n.size();i++) s=s+"0";
  if(k<=n.size())aaa(1,s);


  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

class question {
public:
	int x, y;
	
	void ans() {
		cin >> x >> y;
		int sgnx = x / max(abs(x), 1), sgny = y / max(abs(y), 1);
		int res = abs(abs(x) - abs(y));
		if (x < y) {
			if (sgnx*sgny < 0) res++;
		}
		else {
			res++;
			if (sgnx*sgny > 0) res++;
		}
		cout << res << "\n";
	}
};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	question q;
	q.ans();
	
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
vector<string> split(string s, char p){vector<string>v;stringstream m(s);string b;while(getline(m,b,p))v.push_back(b);return v;}
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 (a>b) { a = b; return 1; } return 0; }
struct nya{ nya(){ cin.tie(0); ios::sync_with_stdio(false); } }nyan;

int main(){
    ll N; cin >> N;
    cout << "ABC" << N << "\n";
}


Measured memory_bytes: 256
/*input
5 2 1
900000000
900000000
1000000000
1000000000
1000000000
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}


ll a[maxn],b[maxn];
int main()
{
	IOS;
	ll n,A,B;
	cin>>n>>A>>B;
	REP(i,n) cin>>a[i];

	ll l=0,r=INF;
	while(l!=r-1){
		ll mid=(l+r)/2;

		REP(i,n) b[i]=max(0LL,a[i]-mid*B);
		//REP(i,n) cout<<b[i]<<" \n"[i==n-1];
		ll cnt=0;
		REP(i,n) cnt+=(b[i]-1+A-B)/(A-B);
		if(cnt>mid) l=mid;
		else r=mid;
		//cout<<mid<<' '<<cnt<<'\n';
	}
	cout<<r<<'\n';

	return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    int X,Y,Z;
    cin >> X >> Y >> Z;
    cout << Z << " " << X << " " << Y << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
S = input()
b = "w"
c = "w"

if n % 2 == 1 :
    print("No")
else :
    a = n // 2
    for i in range(0, a):
         b += S[i]
    for j in range(a, n):
         c += S[j]
         
    if b == c:
        print("Yes")
    else:
        print("No")
                

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

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

    sort(A, A + N + 1, greater<int>());

    int ans = N;

    for (int i = 0; i < K; i++)
    {
        ans -= A[i];
    }

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

Measured memory_bytes: 1024
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
constexpr ll MOD = 1e9 + 7;
int main()
{
    ll N;
    string s;
    cin >> N >> s;
    map<ll, ll> mp;
    for (char c : s)mp[c]++;
    ll res = 1;
    for (auto itr : mp)(res *= itr.second + 1) %= MOD;
    cout << res - 1 << endl;
    return 0;
}


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

int main() {
	int D;
	int G, ans=1e9;
	cin >> D >> G;
	vector<int> p(D);
	vector<int> c(D);
	for (int i = 0; i < D; i++) {
		cin >> p[i] >> c[i];
	}

	for (int bit = 0; bit < (1 << D); bit++) {
		int score = 0, rest_max = 0, num = 0;
		for (int i = 0; i < D; i++) {
			if (bit >> i & 1) {
				score += 100 * (i + 1) * p[i] + c[i];
				num += p[i];
			}
			else {
				rest_max = i + 1;
			}
		}
		if (score < G) {
			int need = (G - score - 1) / (100 * rest_max) + 1;
			if (need > p[rest_max-1] - 1) {
				continue;
			}
			num += need;
		}
		ans = min(ans, num);
	}

	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        a:usize,
        b:usize,
        c:usize,
        d:usize,
        e:usize,
        k:usize,
    }
    let ans = if e - a > k { ":(" } else { "Yay!" };
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int n;
	cin>>n;
	vector<pii>in(n);
	rep(i,n)cin>>in[i].second>>in[i].first;
	sort(all(in));
	vvi dp(1010,vi(1010,inf));
	rep(i,1010)dp[i][0]=0;
	rep(i,n)rep(j,i+1){
		dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
		if(in[i].second+dp[i][j]<=in[i].first){
			dp[i+1][j+1]=min(dp[i][j+1],dp[i][j]+in[i].second);
		}
	}
	int ma=0;
//	rep(i,4){rep(j,30)cout<<" "<<dp[i][j];cout<<endl;}
	rep(i,n)if(dp[n][i+1]!=inf)ma=max(ma,i+1);
	cout<<ma<<endl;
}

Measured memory_bytes: 4964
#include <stdio.h>

int main()
{
  int d, h;
  int i;
  int ans;

  while(scanf("%d", &d) != EOF){

    ans = 0;

    for(i = 1; i < 600/d; i++){
      h = (d*d*i*i);
      ans += d*h;
    }

    printf("%d\n", ans);
  }

  return 0;
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

const int N = 100005;

int n, m;
int h[N];

vector <vector <int> > g;

int main() {

	FAST;

	cin >> n >> m;
	g.resize(n + 1);
	for (int i = 1; i <= n; i ++) {
		cin >> h[i];
	}
	while (m -- ) {
		int x, y;
		cin >> x >> y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	int ans = 0;
	for (int i = 1; i <= n; i ++) {
		int maxx = 0;
		for (int j : g[i]) {
			maxx = max(maxx, h[j]);
		}
		if (h[i] > maxx) {
			ans ++;
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 8724
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
int sq[111][111];
int x[111],y[111],a[111];
int main(void){

  int i,j,k,t,tmp;
  string s;
  char ss;
  int W,H,N;
  int x,y,a;

  cin>>s;
  ss=s[0];
  t=0;
  for(i=1;i<s.length();i++){
    if(ss!=s[i]){
      ss=s[i];
      t++;
    }
  }
  cout<<t<<endl;
  return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
#define FOR(i, a, b) for(ll i=(a); i < (ll)(b); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	ll n,x;
	cin >> n >> x;
	vector<ll> a(n);
	REP(i,n) cin >> a[i];
	
	ll ans = 0;
	REP(i,n-1){
		if(a[i]+a[i+1] > x){
			ll diff = a[i]+a[i+1] - x;
			if(diff <= 0) continue;
			ans += diff;
			if(diff <= a[i+1]){
				a[i+1] -= diff;
			}else{
				a[i] -= diff - a[i+1];
				a[i+1] = 0;
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

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

public class Main {
	 public static void main(String[] age)throws IOException{
		 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		 StringBuffer sb = new StringBuffer();

		 int n = Integer.parseInt(br.readLine());
		 int i = 0;
		 int j = 0;
		 int a = 0;
		 int T = 0;
		 int H = 0;
		 String alha = "abcdefghijklmnopqrstuvwxyz";

		 while( a<n ){
			 String[] input = br.readLine().split(" ");

			 if( input[0].equals(input[1]) ){
				 T++;
				 H++;
			 }else if( input[0].length()>=input[1].length() ){
				 for( i=0 ; i<input[1].length() ; i++ ){
					 if( input[0].substring(i, i+1).equals(input[1].substring(i, i+1))){
						 if( i==input[1].length()-1 ) T = T+3;
					 }else{
						 for( j=0 ; j<26 ; j++ ){
							 if( input[0].substring(i,i+1).equals(alha.substring(j, j+1)) ){
								 H = H+3;
								 break;
							 }else if( input[1].substring(i,i+1).equals(alha.substring(j,j+1))){
								 T = T+3;
								 break;
							 }
						 }
						 break;
					 }
				 }
			 }else if( input[0].length()<input[1].length() ){
				 for( i=0 ; i<input[0].length() ; i++ ){
					 if( input[0].substring(i, i+1).equals(input[1].substring(i, i+1))){
						 if( i==input[0].length()-1 ) H = H+3;
					 }else{
						 for( j=0 ; j<26 ; j++ ){
							 if( input[0].substring(i,i+1).equals(alha.substring(j, j+1)) ){
								 H = H+3;
								 break;
							 }else if( input[1].substring(i,i+1).equals(alha.substring(j,j+1))){
								 T = T+3;
								 break;
							 }
						 }
						 break;
					 }
				 }
			 }

			 a++;
		 }

		 sb.append(Integer.toString(T)).append(" ").append(Integer.toString(H));
		 System.out.println(sb);
	 }
}

Measured memory_bytes: 27664
# AOJ 0587: Tunnel
# Python3 2018.6.30 bal4u

n = int(input())
ans = m = int(input())
for i in range(n):
	a, b = map(int, input().split())
	m += a-b
	if m < 0: ans = 0
	if ans > 0 and m > ans: ans = m
print(ans)


Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc117_c.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  int N, M;
  cin >> N >> M;

  vector<int> c(M);
  rep(i, M) { cin >> c[i]; }
  sort(c.begin(), c.end(), greater<int>());

  vector<int> d(M - 1, 0);
  rep(i, M - 1) { d[i] = c[i] - c[i + 1]; }
  sort(d.begin(), d.end(), greater<int>());

  ll ans = 0;
  repi(i, N - 1, M - 1) { ans += d[i]; }

  cout << ans << endl;
}

Measured memory_bytes: 1024
def divisor(n): 
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

n = int(input())
l = sorted(divisor(n))

if len(l) % 2 == 1:
    i = l[len(l)//2]
    ans = i * 2 - 2
else:
    i = l[len(l)//2 - 1]
    j = l[len(l)//2]
    ans = i  + j - 2
    
print(ans)

Measured memory_bytes: 3924
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000003;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_Q = 100000;
int Q;
ll x[MAX_Q], d[MAX_Q], n[MAX_Q];

const int MAX_N = 1000010;
ll fact[MAX_N+1];
ll inv_fact[MAX_N+1];

//整数a,bに対し、ax + by = gcd(a,b) を満たす整数x,y,gcd(a,b) を計算する
ll extgcd(ll a, ll b, ll& x, ll& y) {
  ll d = a;
  if (b != 0) {
    d = extgcd(b, a%b, y, x);
    y -= (a/b) * x;
  } else {
    x = 1; y = 0;
  }
  return d;
}

//ax ≡ gcd(a,m) (mod m) を満たすxを計算する。
ll mod_inverse(ll a, ll m) {
  ll x, y;
  extgcd(a, m, x, y);
  return (m + x%m) % m;
}


void init(ll n, ll mod) {
  fact[0] = 1;
  for (int i = 1; i <= n; ++i) fact[i] = (fact[i-1]*i)%mod;

  for (int i = 0; i <= n; ++i) inv_fact[i] = mod_inverse(fact[i], mod);
}


//x^nをmodのもとで計算する
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow((x*x) % mod, n/2, mod);
  if (n & 1) res = (res*x) % mod;
  return res;
}

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

  cin >> Q;
  rep(i, Q) cin >> x[i] >> d[i] >> n[i];

  init(MAX_N, MOD);

  for (int i = 0; i < Q; ++i) {
    if (d[i] == 0) {
      cout << mod_pow(x[i], n[i], MOD) << endl;
      continue;
    }
    ll t = mod(x[i]*mod_inverse(d[i], MOD), MOD);
    if (t+n[i]-1 >= MOD || t == 0) {
      cout << 0 << endl;
    } else {
      ll t2 = mod(fact[t+n[i]-1]*inv_fact[t-1], MOD);
      cout << mod(mod_pow(d[i], n[i], MOD)*t2, MOD) << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 18816
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <cassert>
#include <iomanip>

using namespace std;

#define pb push_back
typedef long long ll;
typedef complex<int> P;



bool solve(){
	int n, w;
	cin>> n>> w;
	if(n==0 && w==0) return false;
	
	vector<int> color(n);
	int hoge = 0;
	for(int i=0;i<n;i++){
		cin>> color[i];
		hoge = max(hoge, color[i]);
	}
	
	int m = hoge / w + 1;
	vector<int> bar(m);
	for(int i=0;i<n;i++){
		int a = color[i] / w;
		bar[a]++;
	}
	
	double ans = 0.01;
	int barmax = *max_element(bar.begin(), bar.end());
	for(int i=0;i<m;i++){
		ans += (double)bar[i]/barmax * (m-1-i)/(m-1);
	}
	
	cout<< ans<< endl;
	
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	
	while(solve());

	return 0;
}

 

Measured memory_bytes: 1264
#include <bits/stdc++.h>
    using namespace std;
    #define pb push_back
    #define fi first
    #define se second
    #define INF (int)1e9
    #define EPS 1e-9
    #define PI 3.1415926535897932384626433832795
    #define MOD 1000000007
    typedef vector<int> vi;
    typedef vector<vi> vvi;
    typedef pair<int, int> ii;
    typedef vector<ii> vii;
    typedef long long ll;
    typedef vector<ll> vll;
    typedef vector<vll> vvll;
    typedef double ld;
int optimal_summands(int n) {
   int count = 0;
  //write your code here
  int start = 0;
  while(n!=0){
  int a = ++start;
  if((n - a) > a){
  n -= a;
  count++;
  }
  else{
  count += 1;
  n = 0;  
  }
  }
  return count;
}
    int primeFactors(long long n)  
    { 
        int Totalc = 0;
        int count = 0;
        while (n % 2 == 0)  
        {  
            count++;
            n = n/2;  
        }  
        Totalc += optimal_summands(count);
        for (long long i = 3; i <= sqrt(n); i = i + 2)  
        {  
            count = 0;
            while (n % i == 0)  
            {  
                count += 1;
                n = n/i;  
            }
            Totalc += optimal_summands(count);
            //std::cout << Totalc << std::endl;
        }  
        if (n > 2)  
           return Totalc+=1; 
        else return Totalc;   
    }
    int main() {
    	// your code goes here
    	ios_base::sync_with_stdio(false);
        cin.tie(NULL);
    	long long n;
    	cin >> n;
    	std::cout << primeFactors(n) << std::endl; 
    	return 0;
    }

Measured memory_bytes: 3708
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

struct Info{
	Info(int arg_state,int arg_count){
		state = arg_state;
		count = arg_count;
	}
	int state,count;
};

int main(){

	int POW[17] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536};
	int N,M,K,limit;

	scanf("%d %d %d",&N,&M,&K);

	limit = POW[M];

	int* min_Count = new int[limit];

	for(int i = 0; i < limit; i++){
		min_Count[i] = BIG_NUM;
	}

	bool isDark[N];
	int  dark_Index[M],reverse_dark_Index[N];

	for(int i = 0; i < N; i++)isDark[i] = false;

	vector<int> V[N];

	int tmp;

	for(int i = 0; i < M;i++){
		scanf("%d",&tmp);
		tmp--;
		isDark[tmp] = true;
		dark_Index[i] = tmp;
		reverse_dark_Index[tmp] = i;
	}

	for(int i = 0; i < N; i++){
		for(int p = 0; p < K; p++){
			scanf("%d",&tmp);
			tmp--;
			V[i].push_back(tmp);
		}
	}

	queue<Info> Q;
	Q.push(Info(limit-1,0));
	min_Count[limit-1] = 0;

	int ans,state,next_state,room,next_room,next[M];

	while(!Q.empty()){

		if(Q.front().state == 0){
			ans = Q.front().count;
			break;
		}else if(Q.front().count > min_Count[Q.front().state]){
			Q.pop();
		}else{

			state = Q.front().state;

			for(int instruction = 0; instruction < K; instruction++){

				for(int a = 0; a < M; a++)next[a] = 0;

				for(int a = 0; a < M; a++){

					if(state & (1 << a)){
						room = dark_Index[a];
						next_room = V[room][instruction];
						if(isDark[next_room] == false){
							//Do nothing
						}else{
							next[reverse_dark_Index[next_room]] = 1;
						}
					}
				}

				next_state = 0;
				for(int i = 0; i < M; i++)next_state += POW[i]*next[i];

				if(min_Count[next_state] > Q.front().count+1){
					min_Count[next_state] = Q.front().count+1;
					Q.push(Info(next_state,Q.front().count+1));
				}
			}

			Q.pop();
		}
	}

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

	return 0;
}

Measured memory_bytes: 3168
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

int main() {
	ll n;
	vector<ll> v;

	cin >> n;

	REP(i, n) {
		ll a;
		cin >> a;
		v.push_back(a);
	}

	sort(v.begin(), v.end(), greater<ll>());

	ll count = 1;
	vector<ll> v1;
	vector<ll> v2;

	FOR(i, 1, v.size()) {
		if (v[i] == v[i - 1]) {
			count++;
		}
		else {
			count = 1;
		}

		if (count == 2) {
			v1.push_back(v[i]);
		}

		if (count == 4) {
			v2.push_back(v[i]);
		}
	}

	if (v1.size() < 2 && v2.size() < 1) {
		cout << 0 << endl;
	}
	else if (v1.size() > 1 && v2.size() < 1) {
		cout << v1[0] * v1[1] << endl;
	}
	else if (v1.size() < 2 && v2.size() > 0) {
		cout << v2[0] * v2[0] << endl;
	}
	else {
		cout << max(v1[0] * v1[1], v2[0] * v2[0]) << endl;
	}
}

Measured memory_bytes: 1908
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,k;
	cin >> n >> k;
	int arr[(int)2e5 + 100];
	for(int i = 1;i <= n;i++)cin >> arr[i];
	for(int i = k + 1;i <= n;i++)if(arr[i] > arr[i - k])cout << "Yes" << endl; else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 4412
#include <iostream>
#include <utility>

int main(){

	int a, b;

	while(std::cin >> a >> b){

		int minmul; //least common multiple
		int maxdivi = 1; //greatest common divisor
		int tmp_a = a;
		int tmp_b = b;

		if(a == 0 || b == 0){
			std::cout << 0 << " " << 0 << std::endl;

		}else{					//Euclidean Algorithm

			if(b > a)
				std::swap(a, b);

			while(a % b != 0){
				a = a % b;
				if(b > a)
					std::swap(a, b);
			}
		
		maxdivi = b;
		minmul = (tmp_a / maxdivi) * tmp_b; //a*b/maxdivi

		std::cout << maxdivi << " " << minmul << std::endl;
		}
	}

	return 0;
}

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

int main() {
int a,b;
char op;
cin >> a >> op >> b;
if(op == '+') cout << a+b << endl;
else cout << a-b << endl;
 }

Measured memory_bytes: 3540
import java.util.*;
import java.io.*;
import static java.lang.System.*;

class FastScanner {
  private final InputStream in = System.in;
  private final byte[] buffer = new byte[1024];
  private int ptr = 0;
  private int buflen = 0;
  private boolean hasNextByte() {
      if (ptr < buflen) {
          return true;
      }else{
          ptr = 0;
          try {
              buflen = in.read(buffer);
          } catch (IOException e) {
              e.printStackTrace();
          }
          if (buflen <= 0) {
              return false;
          }
      }
      return true;
  }
  private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
  private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
  public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
  public String next() {
      if (!hasNext()) throw new NoSuchElementException();
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while(isPrintableChar(b)) {
          sb.appendCodePoint(b);
          b = readByte();
      }
      return sb.toString();
  }
  public long nextLong() {
      if (!hasNext()) throw new NoSuchElementException();
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
          minus = true;
          b = readByte();
      }
      if (b < '0' || '9' < b) {
          throw new NumberFormatException();
      }
      while(true){
          if ('0' <= b && b <= '9') {
              n *= 10;
              n += b - '0';
          }else if(b == -1 || !isPrintableChar(b)){
              return minus ? -n : n;
          }else{
              throw new NumberFormatException();
          }
          b = readByte();
      }
  }
  public int nextInt() {
      long nl = nextLong();
      if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
      return (int) nl;
  }
  public double nextDouble() { return Double.parseDouble(next());}
}

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    FastScanner sc = new FastScanner();
    int N = sc.nextInt();
    int L = sc.nextInt();
    int ans = 0;
    for(int i=0; i<N; i++){
      ans += L + i;
    }
    if(L > 0) ans -= L;
    else if(L + N - 1 < 0) ans -= L + N - 1;
    out.println(ans);
  }

  public static int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }
}

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

int main() {
    string A, B, C;
    cin >> A >> B >> C;
    if (A.back() == B.front() && B.back() == C.front()) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cctype>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <set>
#include <deque>
#include <map>
#include <bitset>
#include <functional>
#include <cmath>

#define INF 1000000000
using namespace std;

const int MAX = 1000000;
const int MOD = 1000000007;


long long fac[MAX], finv[MAX], inv[MAX];

//テーブルの前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (long long i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        //そのまま計算すると負の値になるのでMODを足す
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(long long n, long long k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long PERM(long long n, long long k){
    return (fac[n] * finv[n-k]) % MOD;
}

//二分累乗法
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


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

    COMinit();

    long long ans = 0;

    for(long long i = 0; i <= n; i++){
        if(i%2 == 0){
            ans += (((COM(n, i) * PERM(m, i)) % MOD * PERM(m-i, n-i)) % MOD * PERM(m-i, n-i)) % MOD;
            ans %= MOD;
        }else{
            ans -= (((COM(n, i) * PERM(m, i)) % MOD * PERM(m-i, n-i)) % MOD * PERM(m-i, n-i)) % MOD;
            ans += MOD;
            ans %= MOD;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 27036
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>
#include <math.h>
using namespace std;

typedef long long ll;
const int MOD = 1e9 + 7;

//a^n % mod                                                                       
ll mod_pow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main() {
  string S; cin >> S;
  map<char, int> lc, rc;
  for (int i = 0; i < S.length(); i++) rc[S[i]]++;

  ll ans = 0, l_comb, r_comb;
  for (int i = 0; i < S.length(); i++) {
    rc[S[i]]--;
    if (S[i] == 'B' || S[i] == '?') {
      l_comb = lc['A'] * mod_pow(3, lc['?'], MOD) % MOD;
      (l_comb += lc['?'] * mod_pow(3, lc['?'] - 1, MOD) % MOD) %= MOD;
      r_comb = rc['C'] * mod_pow(3, rc['?'], MOD) % MOD;
      (r_comb += rc['?'] * mod_pow(3, rc['?'] - 1, MOD) % MOD) %= MOD;
      (ans += l_comb * r_comb % MOD) %= MOD;
    }
    lc[S[i]]++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
n=int(input())
a=list(map(int,input().split()))
if 0 in a:
  print(sum(abs(i)for i in a))
else:
  pc=mc=0
  for i in range(n):
    if a[i]>0:pc+=1
    else:mc+=1
    a[i]=abs(a[i])
  if mc%2:print(sum(a)-min(a)*2)
  else:print(sum(a))

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

#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define FST first
#define SND second
#define SZ(a) (signed)((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int MOD = 1000000007;

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

signed main(void) {
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(10);
    cin.tie(0);

    int h,w;
    cin >> h >> w;
    vector<vector<string>> vvs(h,vector<string>(w));
    REP(i,h){
        REP(j,w){
            cin >> vvs[i][j];
        }
    }

    REP(i,h){
        REP(j,w){
            if(vvs[i][j]=="snuke"){
                char k = 'A'+j;
                cout << k << i+1 << endl;
            }
        }
    }
    
    return 0;
}

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

using namespace std;

int main() {
	string s1, s2;
	bool flag = false;
	bool eqflag = false;
	cin >> s1 >> s2;
	int size1 = s1.size();
	int size2 = s2.size();
	int cnt = 0;
	if (size1 > size2) {
		flag = true;
	}else if (size1 == size2) {
		for (int i = 0; i < size1; i++) {
			if (s1[i] > s2[i]) {
				flag = true;
				break;
			}else if (s1[i] < s2[i]) {
				flag = false;
				break;
			}
			else {
				cnt++;
				continue;
			}
		}

		if (cnt == size1) eqflag = true;

	}

	if (flag)cout << "GREATER" << endl;
	else if (eqflag)cout << "EQUAL" << endl;
	else cout << "LESS" << endl;

}

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

import math

N,D,A = map(int, input().split())
XH = sorted(tuple(map(int, input().split())) for _ in range(N))

Q = []
qIdx = 0
s = 0
t = 0

for (x, h) in XH:
    while qIdx < len(Q) and  Q[qIdx][0] < x:
        s -= Q[qIdx][1]
        qIdx += 1

    if s < h:
        q = int(math.ceil((h-s)/A))
        Q.append((x+2*D, q*A))
        s += q*A
        t += q

print(t)
        
        


Measured memory_bytes: 58596
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)

    if op == "+":
        print(a + b)

    if op == "-":
        print(a - b)

    if op == "*":
        print(a * b)

    if op == "/":
        print(a // b)
    
    if op == "?":
        break


Measured memory_bytes: 5596
n, k = map(int, input().split())
a = list(map(int, input().split()))
MOD = 10**9+7
dp = [[0 for _ in [0]*(k+1)] for _ in [0]*n]
sum_list = [[0] for _ in [0]*n]

def make_sum(i):
	for j in range(k+1):
		sum_list[i].append((sum_list[i][-1] + dp[i][j]) % MOD)
	return

for j in range(a[0]+1):
	dp[0][j] = 1

for i in range(1, n):
	make_sum(i-1)
	for j in range(k+1):
		dp[i][j] = (sum_list[i-1][j+1] - sum_list[i-1][max(0, j-a[i])]) % MOD

print(dp[n-1][k])

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

using namespace std;

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
const ll MAXN = 2e6 + 10, inf = 1e18, mod = 1e9 + 7;

struct pair_hash {
	template <class T1, class T2>
		std::size_t operator () (const std::pair<T1,T2> &p) const {
			auto h1 = std::hash<T1>{}(p.first);
			auto h2 = std::hash<T2>{}(p.second);

			return h1 ^ h2;  
		}
};

ll pw(ll te, ll tee) {
	if (tee == 0)	return 1;
	ll res = pw(te, tee / 2);
	return (tee % 2 ? te * res * res : res * res);
}

ll n, k;

void Read_input() {
	cin >> n >> k;
	if (k <= (n + 1) / 2)	cout << "YES";
	else	cout << "NO";
}

void Solve() {
}


int main() {

	ios_base::sync_with_stdio(false);	cin.tie(0);	cout.tie(0);
	//freopen("input.txt", "r", stdin),	freopen("output.txt", "w", stdout);

	Read_input(),	Solve();
	return 0;
}


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

int main() {
  int n, m;
  double total = 0;
  cin >> n >> m;
  vector<int> a(n);
  rep(i, n) {
    cin >> a[i];
    total += a[i];
  }
  sort(a.rbegin(), a.rend());
  cout << (a[m - 1] >= total / 4 / m ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 3576
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;


ll dp[(1<<15)-1];

ll key[1010];
ll cost[1010];



int main(void){
    ll n,m;
    cin>>n>>m;
    for(ll i=0;i<(1<<15);i++)dp[i]=(ll)INF;
    for(ll i=0;i<m;i++){
        ll a,b;
        cin>>a>>b;
        cost[i]=a;
        for(ll j=0;j<b;j++){
            ll c;
            cin>>c;
            c--;
            key[i]+=(1<<c);
        }
    }
    dp[0]=0;
    queue<P>que;
    que.push(P(0,dp[0]));
    while(!que.empty()){
        P p = que.front();
        que.pop();
        ll state = p.first;
        ll dist = p.second;
        for(ll i=0;i<m;i++){
            ll next_state = state|key[i];
            if(dp[next_state]>dist+cost[i]){
                dp[next_state]=dist+cost[i];
                que.push(P(next_state,dp[next_state]));
            }
        }
    }
    if(dp[(1<<n)-1]==(ll)INF)cout<<-1<<endl;
    else cout<<dp[(1<<n)-1]<<endl;
    return 0;
}

Measured memory_bytes: 1536
#include <iostream>
using namespace std;
void test_case(){
	int n;
	cin >> n;
	long long sum = 0;
	for(int i = 1 ; i <= n ; ++i){
		if(i % 3 == 0 || i % 5 == 0) continue;
		else sum +=i ;
	}
	cout << sum;
	
}
int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	test_case();
}

Measured memory_bytes: 3636
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

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


	int A, B;
	cin >> A >> B;

	string SA = to_string(A);
	string SB = to_string(B);
	string S1, S2;
	rep(i, B) S1 += SA;
	rep(i, A) S2 += SB;

	if (S1 < S2) co(S1);
	else co(S2);


	Would you please return 0;
}

Measured memory_bytes: 256
n, m = map(int,raw_input().split())

arr = [[] for i in range(4)]

w,v = map(int,raw_input().split())
arr[0].append(v)
arr[1].append(0)
arr[2].append(0)
arr[3].append(0)

for i in range(1,n):
	weight , value = map(int,raw_input().split())

	arr[weight - w].append(value)

ans = 0

for i in range(4):
	arr[i].sort()
	arr[i].reverse()


for i in range(len(arr[0])+1):
	for j in range(len(arr[1])+1):
		for k in range(len(arr[2])+1):
			for l in range(len(arr[3])+1):
				if i * w + j * (w+1) + k * (w+2) + l * (w+3) <= m:
					ans = max(ans,sum(arr[0][:i])+sum(arr[1][:j])+sum(arr[2][:k])+sum(arr[3][:l]))

print ans

Measured memory_bytes: 2696
import sys

input = sys.stdin.readline
N, X = list(map(int, input().split()))


def p_num(l):
    """レベルlバーガーに含まれるパティの数を返す
    """
    return 2**(l+1)-1


def l_num(l):
    """レベルlバーガーに含まれる層の数
    """
    return 2**(l+2)-3


def p_num_l(level, x):
    """レベルlevelバーガーの1, 2, ...x層までのうちのパティーの数を返す
    """
    if level == 0:
        return 1
    if x == 1:
        return 0
    elif x == 2**(level+1)-1:
        return p_num(level-1)+1
    elif x == 2**(level**2)-3:
        return 2*p_num(level-1)+1
    elif x < 2**(level+1)-1:
        return p_num_l(level-1, x-1)
    else:
        return p_num(level-1)+1+p_num_l(level-1, x-2-l_num(level-1))


print(p_num_l(N, X))


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    sort(A.rbegin(), A.rend());
    ll ans = A[0];
    for (int i = 1; i < N - 1; ++i) {
        ans += A[(i + 1) / 2];
    }
    cout << ans << endl;
}

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

using namespace std;

double mod = 1e9 + 7;
#define REP(i, n)  for(int i = 0; i < (int)n; ++i)
#define REP1(i, n)  for(int i = 1; i < (int)n; ++i)


int main() {
    long N, M;
    cin >> N >> M;
    if(M-N*2<0){
        cout <<M/2 <<endl;
        return 0;
    }

    M = M - N * 2;
    M = M / 4;
    cout << N + M << endl;
    return 0;
}


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

bool next_A(vector<int> &vec, int M) {
	for(int i=vec.size()-1;i>=0;i--) {
		if(vec[i] < M) {
			vec[i]++;
			for (int j=i+1;j<vec.size();j++) {
				vec[j] = vec[i];
			}
			return true;
		}
	}
	return false;
}

int main() {
	int N, M, Q;
	cin >> N >> M >> Q;
	
	vector<int> a(Q), b(Q), c(Q), d(Q);
	for(int i=0;i<Q;i++) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		a[i]--;
		b[i]--;
	}

	int ans = 0;
	vector<int> A(N, 1);

	do {
		int current_ans = 0;
		for (int i=0;i<Q;i++) {
			if ( (A[b[i]] - A[a[i]]) == c[i] ) {
				current_ans += d[i];
			}
		}
		ans = max(ans, current_ans);
	} while (next_A(A, M));

	cout << ans << endl;
}

Measured memory_bytes: 3588
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug: "<<x<<" "<<y<<endl;
using namespace std;
typedef long long ll;
const int maxn = 200005;



int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
#endif
  vector<int>a;
  for(int i=0;i<3;i++){
    int x;
    cin>>x;
    a.push_back(x);
  }
  sort(a.begin(),a.end());
  cout<<a[0]+a[1]<<endl;
  return 0;
}

Measured memory_bytes: 256
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )
x,y=map(int,input().split())
if x>2*y or y>2*x or (2*x-y)%3!=0 or (2*y-x)%3!=0:
    print(0)
    exit()
print(cmb((x+y)//3,(2*x-y)//3,mod))

Measured memory_bytes: 128584
import sys
from itertools import product

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    N, K = mi()
    x = list(mi())
    m = 10**100
    for i in range(N-K+1):
        tmp = min(abs(x[i]), abs(x[i+K-1]))+(x[i+K-1]-x[i])
        m = min(m, tmp)
    print(m)


if __name__ == '__main__':
    main()


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

using namespace std;

class Point {
public:
	int x, y;
};

Point PointData[5];


int isExistTriangle(const Point& p) {

	int r1 = (PointData[1].x - PointData[0].x) * (p.y - PointData[0].y) - (p.x - PointData[0].x) * (PointData[1].y - PointData[0].y);
	int r2 = (PointData[2].x - PointData[1].x) * (p.y - PointData[1].y) - (p.x - PointData[1].x) * (PointData[2].y - PointData[1].y);
	int r3 = (PointData[0].x - PointData[2].x) * (p.y - PointData[2].y) - (p.x - PointData[2].x) * (PointData[0].y - PointData[2].y);

	if (r1 > 0 && r2 > 0 && r3 > 0) {
		return 1;
	}
	if (r1 < 0 && r2 < 0 && r3 < 0) {
		return 1;
	}
	return -1;
}

int main(void) {
	int n, flag1, flag2;

	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 5; j++) {
			cin >> PointData[j].x >> PointData[j].y;
		}
		
		flag1 = isExistTriangle(PointData[3]);
		flag2 = isExistTriangle(PointData[4]);
		//cout << flag1 << ends << flag2 << endl;
		if (flag1*flag2 == 1) {
			cout << "NG" << endl;
		}
		else {
			cout << "OK" << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3080
import sys
s=input()
ans=0
i=0
j=len(s)-1
xi=0
yj=0
while(i<j):

    while(i<len(s)-1 and s[i]=='x'):
        i+=1
        xi+=1
#        print(i,xi)

    while(j>0 and s[j]=='x'):
        j-=1
        yj+=1
#        print(j,yj)

#    print(i,xi,j,yj)
    if(s[i]!=s[j]):
        print(-1)
        sys.exit()
    else:
        ans+=abs(xi-yj)
        xi=0
        yj=0
        i+=1
        j-=1

print(ans)

Measured memory_bytes: 3316
N=int(input())
ans=N
for i in range(N+1):
    cnt=0
    a=i
    while a>0:
        cnt += a%6
        a //= 6
    b=N-i
    while b>0:
        cnt += b%9
        b //= 9
    ans=min(ans,cnt)
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef long double ld;
const int N = 200000 + 5;
int n, x[N], y[N];
int mn = 1e9 + 10, mx = -1;

ll get(int s, int e, int v) {
	if (v <= s) return s - v;
	return v - e;
}

ll calc1() {
	int mx1 = -1, mx2 = -1, mn1 = 1e9 + 10, mn2 = 1e9 + 10;
	mx1 = mx, mn1 = mn;
	vector<pair<int, int> > v, u;
	for (int i = 0; i < n; ++i) {
		if (x[i] == mn) {
			mx2 = max(mx2, y[i]);
			mn2 = min(mn2, y[i]);
		}
		else if (y[i] == mx) {
			mx2 = max(mx2, x[i]);
			mn2 = min(mn2, x[i]);
		}
		else {
			v.push_back(make_pair(x[i], y[i]));
		}
	}
	int xd, yd;
	int mn3 = 1e9 + 10, mx3 = -1;
	bool ok = true;
	for (int i = 0; i<0.9*n + 1; ++i) {
		u.clear();
		for (int i = 0; i < v.size(); ++i) {
			xd = v[i].X, yd = v[i].Y;
			if (xd > yd) swap(xd, yd);
			if (xd >= mn2) mx2 = max(mx2, xd);
			else if (yd <= mx2) mn2 = min(mn2, yd);
			else u.push_back(make_pair(xd, yd));
			
		}
		u.swap(v);
		if (u.size() == v.size())
			break;
	}
	int xdd, ydd;
	for (int i = 0; i < v.size(); ++i) {
		xd = v[i].X, yd = v[i].Y;
		
		xdd = get(mn2, mx2, xd);
		ydd = get(mn2, mx2, yd);

		if (xdd < ydd) {
			mx2 = max(mx2, xd);
			mn2 = min(mn2, xd);
		}
		else {
			mx2 = max(mx2, yd);
			mn2 = min(mn2, yd);
		}
	}
	return (ll(mx1) - mn1) * (ll(mx2) - mn2);
}

ll calc2() {
	int mx1 = -1, mx2 = -1, mn1 = 1e9 + 10, mn2 = 1e9 + 10;
	mx1 = mx, mn2 = mn;
	for (int i = 0; i < n; ++i) {
		mn1 = min(mn1, y[i]);
		mx2 = max(mx2, x[i]);
	}
	return (ll(mx1) - mn1) * (ll(mx2) - mn2);
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i) {
		scanf("%d%d", x + i, y + i);
		mn = min(mn, min(x[i], y[i]));
		mx = max(mx, max(x[i], y[i]));
	}

	if (mn == mx) return puts("0"), 0;
	for (int i = 0; i < n; ++i)
		if (x[i] > y[i])
			swap(x[i], y[i]);

	printf("%lld\n", min(calc1(), calc2()));
	return 0;
}



Measured memory_bytes: 4084
#include <stdio.h>

int main(void){
    int n,m,i,j;
    scanf("%d %d",&n,&m);

    int h[n],a[m],b[m];
    for(i=0;i<n;i++){
        scanf("%d",&h[i]);
    }
    for(i=0;i<m;i++){
        scanf("%d %d",&a[i],&b[i]);
    }

    int yoi[n];
    for(i=0;i<n;i++){
        yoi[i]=0;
    }

    for(i=0;i<m;i++){
        if(h[a[i]-1]<h[b[i]-1]){
            /*a[i]-1番目がb[i]-1番目以下*/
            yoi[a[i]-1]++;
        }else if(h[a[i]-1]>h[b[i]-1]){
            yoi[b[i]-1]++;
        }else{
            yoi[a[i]-1]++;
            yoi[b[i]-1]++;
        }


    }
    long cnt=0;
    for(i=0;i<n;i++){
        if(yoi[i]==0){
            cnt++;
        }
    }

    printf("%ld\n",cnt);
    return 0;
}


Measured memory_bytes: 3280