akhauriyash/Code-Regression huggingface dataset:
from heapq import heappush, heappop
import sys
input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    X = [None] * N
    for i in range(N):
        A, B = map(int, input().split())
        X[i] = (A, B)
    X.sort()
    idx = 0
    day = 1
    ans = 0
    h = []
    while day <= M:
        while idx < N and X[idx][0] <= day:
            heappush(h, -X[idx][1])
            idx += 1
        if len(h):
            ans += -heappop(h)
        day += 1
    print(ans)


if __name__ == "__main__":
    main()


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

int main(void){
	int n;

	while (cin>>n){
		double s=0;
		for (int i=n; i<600; i+=n)
			s += i*i*n;
		cout<<fixed<<setprecision(0)<<s<<endl;
	}
    return 0;
}

Measured memory_bytes: 1228
#include "bits/stdc++.h"
using namespace std;
int main() {
	int n, a, b, c, x[105], y[105], z[105], count = 0, vc = 0;
	cin >> n >> a;
	vector<int>v;
	for (int i = 0; i < a; ++i) {
		cin >> x[i];
	}
	cin >> b;
	for (int i = 0; i < b; ++i) {
		cin >> y[i];
	}
	cin >> c;
	for (int i = 0; i < c; ++i) {
		cin >> z[i];
	}
	for (int i = 0; i < c; ++i) {
		for (int j = 0; j < b; ++j) {
			if (z[i] == y[j]) {
				v.push_back(z[i]);
				vc++;
				break;
				// vc == v.size()
			}
		}
	}
	for (int i = 0; i < c; ++i) {
		bool aa = true;
		for (int j = 0; j < a; ++j) {
			if (z[i] == x[j]) {
				aa = false;
				break;
			}
		}
		if (aa) {
			bool flag = false;
			for (int j = 0; j < v.size(); ++j) {
				if (v[j] == z[i]) flag = true;
			}
			if (!flag) v.push_back(x[i]);
		}
	}
	cout << v.size() << endl;
}


Measured memory_bytes: 3152
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int N,K;
    cin >> N >> K;
    int x[N],ans=0;
    for(int i=0;i<N;i++) cin >> x[i];

    for(int i=0;i<N;i++){
        if(x[i] > K-x[i]) ans += 2*(K-x[i]);
        else ans += 2*x[i];
    }

    cout << ans << endl;
}

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

int main(){

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

  int mn = a[0], mx = a[0];
  long long sum = 0;
  for(int i=0;i<n;i++){
    mn = min(mn, a[i]);
    mx = max(mx, a[i]);
    sum += a[i];
  }

  cout<<mn<<" "<<mx<<" "<<sum<<endl;
  
  return 0;
}


Measured memory_bytes: 3144
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    if(Integer.parseInt(sc.next())==0){
      System.out.println(1);
    }
    if(Integer.parseInt(sc.next())==0){
      System.out.println(2);
    }
    if(Integer.parseInt(sc.next())==0){
      System.out.println(3);
    }
    if(Integer.parseInt(sc.next())==0){
      System.out.println(4);
    }
    if(Integer.parseInt(sc.next())==0){
      System.out.println(5);
    }
  }
  
}



Measured memory_bytes: 35700
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1061109567
#define pb push_back
#define in(s) freopen(s,"r",stdin);
#define out(s) freopen(s,"w",stdout);
#define fi first
#define se second
#define bw(i,r,l) for (int i=r-1;i>=l;i--)
#define fw(i,l,r) for (int i=l;i<r;i++)
#define fa(i,x) for (auto i:x)
using namespace std;
const int N=1e5+5;
int n;
string seat[N];
bool asked[N];
signed main() {
	//in("aome.inp");
	//ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n;
	/*
	We have a range from L -> R to ask. Ask from L -> mid.
	mid - L + 1 is even. Then, if 0 is a male, mid must contain a female. Else, we can be sure that
	an empty seat lies in this range.
	We can easily see that R - mid is then odd. But, since 0 contains a male, N - 1 contains a female,
	and mid + 1 contains a male. So an empty seat may lies in this range if the previous range
	satisfies given conditions.
	*/
	memset(asked,false,sizeof(asked));
	int l=0,r=n-1;
	while (l<r) {
		int mid=(l+r+1)/2;
		//cout<<"l="<<l<<" r="<<r<<" newmid="<<mid<<"\n";
		if (!asked[l]) {
			cout<<l<<endl<<flush;
			asked[l]=true;
			cin>>seat[l];
		}
		if (seat[l]=="Vacant") exit(0);
		if (!asked[mid]) {
			cout<<mid<<endl<<flush;
			asked[mid]=true;
			cin>>seat[mid];
		}
		if (seat[mid]=="Vacant") exit(0);
		int tmpcount=(mid-l+1)%2;
		if (tmpcount==0) {
			if (seat[l]==seat[mid]) r=mid;
			else l=mid;
		} else {
			if (seat[l]==seat[mid]) l=mid;
			else r=mid;
		}
	}
	cout<<l<<endl<<flush;
	return 0;
}

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

using namespace std;

int main(){
	cin.tie(0);
	cin.sync_with_stdio(0);

	int N;
	cin >> N;
	vector<vector<int>> v(N, vector<int>(3));
	for(auto &i : v) cin >> i[0] >> i[1] >> i[2];

	vector<vector<int>>dp(N, vector<int>(3, -1));
	dp[N-1][0] = v[N-1][0];
	dp[N-1][1] = v[N-1][1];
	dp[N-1][2] = v[N-1][2];

	for(int i=N-2; i>=0; i--)
		for(int j=0; j<3; j++)
			for(int x = 0; x<3; x++) if(x != j)
				dp[i][j] = max(dp[i+1][x] + v[i][j], dp[i][j]);
	cout << max({dp[0][0], dp[0][1], dp[0][2]});
}


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

int main(){
  int n;
  int ave1,ave2;
  int sum = 0;
  int a[105];
  int i;

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

  ave1 = sum/n;
  ave2 = sum/n + 1;

  ll ans1 = 0;
  ll ans2 = 0;

  for(i = 0;i < n;i++){
    ans1 += (ave1 - a[i])*(ave1 - a[i]);
    ans2 += (ave2 - a[i])*(ave2 - a[i]);
  }

  printf("%lld\n", min(ans1,ans2));

  return 0;
}

Measured memory_bytes: 256
import math
N,K = map(int,input().split())
A = list(map(int,input().split()))
m = math.ceil(math.log2(max(max(A),K)))+1
C = []
F = []
X = 0
for j in range(m):
  cnt = 0
  for i in range(N):
    cnt += A[i]>>j & 1
  if (N-cnt) < cnt:
    F.append(0)
  else:
    F.append(1)
    X += 2**j
  C.append(N-cnt)
ans = 0
for i in range(m-1,-1,-1):
  KK = K>>i & 1
  XX = X>>i & 1
  if KK==0 and XX==1:
    X += -2**i
    F[i]=0
  elif KK==1 and XX==0:
    break
  else:
    continue
for i in range(m-1,-1,-1):
  ans += C[i]*F[i]*(2**i)+(N-C[i])*(1-F[i])*(2**i)
print(ans)

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

int x;

bool isPrime(int p){
    if(p==2)return 1;
    if(p%2==0)return 0;
    for(int i=3;i*i<p;i+=2)if(p%i==0)return 0;
    return 1;
}

int main(){
    cin>>x;
    while(1){
        if(isPrime(x)){
            cout<<x<<endl;
            return 0;
        }
        x++;
    }
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import itertools

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main(mtx, k):
    # print(count([['.','#','.'],['.','#','#']], [(1,2)], []))
    # return
    h_indices = []
    for i in range(len(mtx)):
        idx = [k for k in range(len(mtx))]
        h_indices += list(itertools.combinations(idx, i))

    w_indices = []
    for i in range(len(mtx[0])):
        idx = [k for k in range(len(mtx[0]))]
        w_indices += list(itertools.combinations(idx, i))

    cnt = 0
    for his in h_indices:
        for wis in w_indices:

            c = count(mtx, his, wis)
            # if len(mtx) == 2: print(his, wis, c)
            if k == c:
                cnt += 1

    print(cnt)

def count(mtx, his, wis):
    # print(his, wis)
    c = 0
    for h in range(len(mtx)):
        if h in his: continue

        for w in range(len(mtx[h])):
            if w in wis: continue
            if mtx[h][w] == '#':
                c += 1

    return c


if __name__ == '__main__':
    h, w, k = [int(i) for i in input().split()]
    mtx = []
    for _ in range(h):
        mtx.append(list(input()))
    main(mtx, k)


Measured memory_bytes: 9264
/**
 *  author: MOOONI
 *  hackers are welcome!
**/
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ull unsigned long long
#define db double
#define ld long double
#define str string
#define pi pair
#define tup tuple
#define vec vector
#define temp template
#define tn typename

#define ff first
#define ss second
#define SZ(x) (ll) x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define rsz resize
#define ins insert
#define fr front 
#define bc back
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define mk make_pair

#define FOR(i, a, b) for (ll i = (a); i <= (b); i++) 
#define ROF(i, a, b) for (ll i = (a); i >= (b); i--)
#define trav(a, x) for (auto &a : x)
#define popcount __builtin_popcount
#define ctz __builtin_ctz
#define clz __builtin_clz
#define gcd __gcd

// DEBUG
#define ts to_string
temp<tn A, tn B> str ts(pi<A, B> p);
temp<tn A, tn B, tn C> str ts(tup<A, B, C> p);
str ts(const str& s) { return '"' + s + '"'; }
str ts(const char* s) { return ts((str) s); }
str ts(bool b) { return (b ? "true" : "false"); }
str ts(vec<bool> v) { bool f = true; str res = "{";
FOR(i, 0, static_cast<ll>(v.size()) - 1) 
{ if (!f) res += ", "; res += ts(v[i]);
f = false; } res += "}"; return res; }
temp<size_t N> str ts(bitset<N> v) { str res = "";
trav(a, v) { res += (char) ('0' + a); } return res; }
temp<tn A> str ts(A v) { bool f = true; str res = "{";
trav(x, v) { if (!f) res += ", "; res += ts(x);
f = false; } res += "}"; return res; }
temp<tn A, tn B> str ts(pi<A, B> p) { 
  return "(" + ts(p.ff) + ", " + ts(p.ss) + ")"; }
temp<tn A, tn B, tn C> str ts(tup<A, B, C> t) {
  return "(" + ts(get<0>(t)) + ", " + ts(get<1>(t)) + ", " + ts(get<2>(t)) + ")"; }
void DBG() { cerr << endl; }
temp<tn H, tn... T> void DBG(H h, T... t) { cerr << " " << ts(h); DBG(t...); }
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", DBG(__VA_ARGS__);

// INPUT AND OUTPUT
temp<tn T> void re(T& x) { cin >> x; };
temp<tn H, tn... T> void re(H& h, T&... t) { re(h); re(t...); }
temp<tn T> void pr(T x) { cout << x; };
temp<tn H, tn... T> void pr(H h, T... t) { pr(h); pr(t...); }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  auto Do = [&](ll L, ll R, ll &k) {
    while (L < R && k) {
      pr(L, " ", R, '\n');
      --k;
      ++L;
      --R;
    }
  };
  ll n, m;
  re(n, m);
  if (n % 2 == 1) {
    Do(1, n, m);
    return 0;
  }
  Do(1, n / 2, m);
  Do(n / 2 + 2, n, m);
  return 0;
}

Measured memory_bytes: 3656
#pragma GCC optimize("trapv")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
using namespace std;
using ll = long long;
//using arr = array;
using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vpi = vector<pi>;
using ld = long double;
const int maxn = 1<<18, mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
bool solve(vi a) {
	int win = 0, cnt = 0, g = 0, bad = 0;
	for(auto &i : a) {
		cnt += i&1;
		if(i&1) i == 1 ? bad = 1 : --i;
		else win ^= 1;
		g = __gcd(g, i);
	}
	if(win) return 1;
	if(cnt > 1 || bad) return 0;
	
	for(auto &i : a) i /= g;
	return !solve(a);
}
int main() {
	cin.tie(0)->sync_with_stdio(0);
	int n;
	cin >> n;
	vi a(n);
	for(auto &i : a) cin >> i;
	cout << (solve(a)?"First":"Second");
}


Measured memory_bytes: 10112
#include<iostream>
using namespace std;
main(){
    int n; 
    while( cin >> n&&n){
	int t = 0;
	while(n != 1){
	    if ( n % 2 == 0 ) n /= 2;
	    else n = 3*n + 1;
	    t++;
	}
	cout << t << endl;
    }
}

Measured memory_bytes: 0
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Program{
  static void Main(){
	var num = ReadLine();
    var numbers = ReadLine().Split(' ').Select(int.Parse).Where(a => a%2 ==0).ToArray();
    var result ="APPROVED";
    
    for(var i = 0;i < numbers.Length;i++){
      if(numbers[i]%3 != 0 && numbers[i]%5 != 0){
        result ="DENIED";
      }
    }
    Write(result);
  }
}


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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int K,X;
    Scd2(K,X);

    int N = K;

    Rep(i,N*2-1){
        printf ("%lld%c", X-K+1+i, i == N*2-2 ? '\n' : ' ' );
    }

    return 0;
}



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

using namespace std;

ll n,m,ans=0;

int main() {
	cin>>n>>m;
	
	if(n>=2) ans+=n*(n-1)/2;
	if(m>=2) ans+=m*(m-1)/2;
	
	cout<<ans<<endl;
	
	return 0;
}
	

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	int a,b;
	cin>>a>>b;
	cout<<max(a+b,max(a-b,a*b));	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int ma=0,mi=1000000001;
  cin>>n;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    ma=max(ma,a);
    mi=min(mi,a);
  }
  cout<<ma-mi<<endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto&& i : a)
#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__)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll X; cin >> X;
    ll ans = 0;
    while (ans * (ans+1) / 2 < X) {
        ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
int main() {
 	int n;
  	cin >> n;
  	pair<int, int> a[n];
  	for (int i = 0; i < n; i++) {
    	int x, l;
      	cin >> x >> l;
      	a[i] = {x + l, x - l};
    }
  	sort(a, a + n);
  	int end = -(1e9 + 2);
  	int ans = 0;
  	for (auto x : a) {
    	if (x.second >= end) {
        	ans++;
          	end = x.first;
        }
    }
  	cout << ans;
}

Measured memory_bytes: 1024
import queue

def main():
    N, M = map(int, input().split())
    N = M * 2 + 1

    q = queue.Queue()
    q.put((1, 1 + M))
    q.put((N - M + 1, N))
    ans = []

    for i in range(M):
        a, b = q.get()

        ans.append(f'{a} {b}')
        q.put((a+1, b-1))
    print(*ans, sep='\n')

if __name__ == '__main__':
    main()

Measured memory_bytes: 17332
#include<iostream>
#include<cstdio>

#define EXIT puts("No"),exit(0)

using namespace std;

int n,x,cnt[100000],a,b;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",&x),++cnt[x];
	for(int i=1;i<n;++i){if(cnt[i]&&b)EXIT;if(cnt[i])if(a)b=i;else a=i;}
	if(b-a>1)EXIT;
	if(!b)if(a<<1<=n||a==n-1)puts("Yes"),exit(0);else puts("No"),exit(0);
	else{
		int c=b-cnt[a];
		if(c<1)EXIT;
		if(c!=cnt[b]-1&&c<<1>cnt[b])EXIT;
		if(cnt[b]==2){
			if(c+cnt[a]-1!=a&&cnt[b]+cnt[a]-1!=a)EXIT;
			puts("Yes");
			return 0;
		}
		if(c<<1>cnt[b])c=cnt[b];
		if(c+cnt[a]-1!=a)puts("No");else puts("Yes");
	}
}

Measured memory_bytes: 640
N, Q = map(int, input().split())
# print(N, Q)
S = input()
lr_array = [list(map(int, input().split())) for i in range(Q)]
AC_array = []
AC_count = 0

# print(S)
for i, s in enumerate(S):
    if i == 0:
        s_old = s
        continue
    if s_old == "A" and s == "C":
        AC_count += 1
    AC_array.append(AC_count)
    s_old = s

# print(lr_array)
# print(AC_array)
ans = ""
for lr in lr_array:
    print(AC_array[lr[1] - 2] - (AC_array[lr[0] - 2] if lr[0] > 1 else 0))


Measured memory_bytes: 70232
dice1 = gets.split.map(&:to_i)
dice2 = gets.split.map(&:to_i)
throw = {E: [3, 2, 6, 1, 5, 4], N: [5, 1, 3, 4, 6, 2],
         S: [2, 6, 3, 4, 1, 5], W: [4, 2, 1, 6, 5, 3]}
th = {}
throw.each_key {|k| th[k] = throw[k].map(&:pred)}

front = dice1[1]
unless dice2.find_index(front)
  puts "No"
  exit
end

rotate = ->(dir, dice) {
  next_dice = Array.new(6, 0)
  dice.each_with_index do |d, i|
    next_dice[th[dir][i]] = d
  end
  next_dice
}

stack = []
dice = dice2
next_dice = loop do
  [:E, :N, :S, :W].each {|d| stack << [dice, d]}
  dice, dir = stack.shift
  next_dice = rotate.(dir, dice)
  if next_dice[1] == front
    break next_dice
  else
    dice = next_dice
  end
end

result = "No"
4.times do
  if next_dice == dice1
    result = "Yes"
    break
  end
  next_dice = rotate.(:E, next_dice)
end
puts result



Measured memory_bytes: 6884
#include<stdio.h>
int main(void) 
{
	int n,m,s,l,a,b;
	scanf("%d %d %d",&n,&m,&s);
	l=b=0;
	if(n<m)
	{
		n=a;
		n=m;
		m=a;
	}
	while(b<s)
	{
		b=b+n;
		l++;
	}
	printf("%d",l);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
using namespace std;
int main(){
	int a,b,c[500],d[50];
	cin>>a>>b;
	for(int i=0;i<b*2;i++){
		cin>>c[i];
	}
	for(int i=0;i<50;i++)d[i]=0;
	for(int x=0;x<a;x++){
		for(int z=0;z<b*2;z++){
			if(c[z]==x+1){
				d[x]++;
			}
			
		}
	}
	for(int y=0;y<a;y++){
		cout<<d[y]<<endl;
	}
}

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

if N==1:
    print(0)
    exit()
# N > 1
l=[]
ans=0
for i in range(2,int(N**0.5)+1):
    cnt=0
    while N % i ==0:
        cnt+=1
        N //=i
    if cnt > 0:
        l.append( (i,cnt) )
        ans += int( (-1+(1+8*cnt)**0.5)/2 )
if N > 1:
    l.append((N,1))
    ans +=1

print(ans)

Measured memory_bytes: 9472
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>
using namespace std;
const int maxn = 100 + 5;
struct node
{
	int hh;
	int mm;
	int MM;
}p[maxn];
int judge(int h,int m)
{
	if(h>=11&&h<=14&&m>=0&&m<=59)
		return 1;
	else if(h>=18&&h<=20&&m>=0&&m<=59)
		return 2;
	else if(h>=21&&h<=23&&m>=0&&m<=59)
		return 3;
	else if(h>=0&&h<=1&&m>=0&&m<=59)
		return 3;
	else 
		return 0;
}
bool judge2(int h,int m,int M)
{
	int sum = 0;
	while(M != m)
	{
		sum ++;
		m ++;
		if(m == 60)
		{
			m = 0;
			h++;
		}
		if(h == 24)
			h = 0;
	}
	if(sum > 8)
		return false;
	else 
		return true;
}
int main()
{
	int n;
	while(scanf("%d",&n)&&n)
	{
		int suml = 0,sumd = 0,summ = 0;
		int cl = 0,cd = 0,cm = 0;
		for(int i = 0;i<n;i++)
		{
			scanf("%d%*c%d%d",&p[i].hh,&p[i].mm,&p[i].MM);
			switch(judge(p[i].hh,p[i].mm))
			{
	
			case 1:
				suml++;
				if(judge2(p[i].hh,p[i].mm,p[i].MM) == true)
					cl ++;
				break;
			case 2:
				sumd++;
				if(judge2(p[i].hh,p[i].mm,p[i].MM) == true)
					cd ++;
				break;
			case 3:
				summ ++;
				if(judge2(p[i].hh,p[i].mm,p[i].MM) == true)
					cm ++;
				break;
			}
		}
		if(suml == 0)
			printf("lunch no guest\n");
		else 
			printf("lunch %d\n",(int)(cl*1.0/suml*100));
		if(sumd == 0)
			printf("dinner no guest\n");
		else 
			printf("dinner %d\n",(int)(cd*1.0/sumd*100));
		if(summ == 0)
			printf("midnight no guest\n");
		else 
			printf("midnight %d\n",(int)(cm*1.0/summ*100));
	}
	return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a;
  cin >> a;
  cout << a+a*a+a*a*a << endl;
  return 0;
}

Measured memory_bytes: 3556
#include<cstdio>
#include<iostream>
#include<cstring>
#define RG register
#define ll long long 
using namespace std;
ll n,x,y,ans;
inline ll mx(ll a,ll b){return a>b ? a : b;}
int main()
{
//	freopen("Mysterious Light.in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%lld%lld",&n,&x);
	y=mx(x,n-x); x=n-y;
	ans=n;
	while(x>=1)
	{
		if(y%x==0) { ans+=(y/x*2*x-x); break; }
		ans+=y/x*2*x;
		ll tt=x; x=y%x; y=tt;
	}
	printf("%lld",ans);
	//fclose(stdin); fclose(stdout);
	return 0;
}

Measured memory_bytes: 764
n = int(input())
list_int = list(map(int, input().split()))
if 0 in list_int:
  print(0)
else:
  ans = 1
  for i in list_int:
    ans *= i
    if ans > 10**18:
      print(-1)
      break
    else:
      continue
  if ans <= 10**18:
    print(ans)

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

typedef long long ll;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n; cin >> n;
    vector<int> height(n), cost(n);

    int base = 1;
    while (base <= n) {
        base <<= 1;
    }

    vector<ll> tree(base<<1);

    for (int i = 0; i < n; ++i) cin >> height[i];
    for (int i = 0; i < n; ++i) cin >> cost[i];

    // dp[i] - the maximum beauty when the last picked flower is of height i
    vector<ll> dp(n+1);

    for (int flower = 0; flower < n; ++flower) {
        // the maximum dp[i] for i in [0...height[flower]-1]
        ll best = 0L;
        for (int x = base + height[flower]; x > 1; x >>= 1) {
            if (x & 1) best = max(best, tree[x-1]);
        }

        dp[height[flower]] = best + cost[flower];

        for (int x = base + height[flower]; x >= 1; x >>= 1) {
            tree[x] = max(tree[x], dp[height[flower]]);
        }
    }

    ll ans = *max_element(dp.begin(), dp.end());

    cout << ans << endl;
}

Measured memory_bytes: 7552
import sys

input = sys.stdin.readline


class SegmentTree:
    def __init__(self, N, X):
        self.N = N
        self.func = lambda x, y: x | y
        self.__build(X)

    def __build(self, X):
        # Initialize all nodes
        self.node = [set() for _ in range(2 * self.N)]

        # Elementary intervals are stored
        for i, s in enumerate(X, self.N):
            self.node[i].add(s)

        # The internal nodes correspond to intervals that are the union of elementary intervals
        for i in range(self.N - 1, 0, -1):
            self.node[i] = self.func(self.node[i << 1], self.node[i << 1 | 1])

    def update(self, i, s):
        i += self.N - 1
        if s in self.node[i]:
            return
        self.node[i] = set([s])
        while i > 1:
            i >>= 1
            self.node[i] = self.func(self.node[i << 1], self.node[i << 1 | 1])

    def query(self, l, r):
        """Query for right half-open interval [l, r).

        Args:
            l (int): index (1-based index)
            r (int): index (1-based index)
        """
        dst_l = set()
        dst_r = set()
        l += self.N - 1
        r += self.N - 1
        while l < r:
            if l & 1:
                dst_l = self.func(dst_l, self.node[l])
                l += 1
            if r & 1:
                r -= 1
                dst_r = self.func(self.node[r], dst_r)
            l >>= 1
            r >>= 1
        return self.func(dst_l, dst_r)


def main():
    N = int(input())
    S = input().rstrip()

    S = list(S)
    st = SegmentTree(N, S)

    ans = []
    Q = int(input())
    for _ in range(Q):
        query = input().split()
        q = int(query[0])
        if q == 1:
            i = int(query[1])
            c = query[2]
            st.update(i, c)
        else:
            l = int(query[1])
            r = int(query[2])
            res = st.query(l, r + 1)
            ans.append(len(res))

    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()


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

using namespace std;

bool solve() {
    int L, D;
    if(!(cin >> L >> D)) return false;
    if(!L && !D) return false;

    string strs[3];
    for(int i = 0; i < 3; ++i) {
        cin >> strs[i];
    }

    vector<int> diff_by_one[3];
    vector<int> all_diff(L+1, 0);
    for(int i = 0; i < 3; ++i) {
        diff_by_one[i].resize(L+1, 0);
        const int next = (i+1) % 3;
        const int prev = (i+2) % 3;
        for(int j = 0; j < L; ++j) {
            if(strs[i][j] != strs[next][j] && strs[next][j] == strs[prev][j]) {
                diff_by_one[i][j] = 1;
            }
        }
        for(int j = L-1; j >= 0; --j) {
            diff_by_one[i][j] += diff_by_one[i][j+1];
        }
    }
    for(int i = 0; i < L; ++i) {
        if(strs[0][i] != strs[1][i] && strs[1][i] != strs[2][i] && strs[2][i] != strs[0][i]) {
            all_diff[i] = 1;
        }
    }
    for(int i = L-1; i >= 0; --i) {
        all_diff[i] += all_diff[i+1];
    }

    string res;
    vector<int> remain(3, D);
    for(int i = 0; i < L; ++i) {
        char ch = '\x7f';
        for(int idx = 0; idx < 4; ++idx) {
            const char test_ch = idx == 0 ? 'A' : strs[idx-1][i];
            int sum = 0;
            int r[3] = {0};
            int u[3] = {0};
            for(int j = 0; j < 3; ++j) {
                const int next_rem = remain[j] - (test_ch == strs[j][i] ? 0 : 1);
                r[j] = next_rem - diff_by_one[j][i+1];
                u[j] = all_diff[i+1] - r[j];
                sum += max(0, u[j]);
            }
            bool ok = sum <= all_diff[i+1];
            if(!ok) {
                if(u[0] <= 0 && u[1] <= 0) {
                    ok = sum - min({diff_by_one[2][i+1], -u[0], -u[1]}) <= all_diff[i+1];
                }
                if(u[1] <= 0 && u[2] <= 0) {
                    ok = sum - min({diff_by_one[0][i+1], -u[1], -u[2]}) <= all_diff[i+1];
                }
                if(u[2] <= 0 && u[0] <= 0) {
                    ok = sum - min({diff_by_one[1][i+1], -u[2], -u[0]}) <= all_diff[i+1];
                }
            }
            if(ok) {
                ch = min(ch, test_ch);
                //cout << i << ' ' << ch << endl;
            }
            if(ch == 'A') break;
        }
        if(ch == '\x7f') {
            res = "-1";
            break;
        } else {
            res += ch;
            //cout << res << endl;
            for(int j = 0; j < 3; ++j) {
                remain[j] -= (ch == strs[j][i] ? 0 : 1);
            }
        }
    }
    cout << res << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 3392
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
import sys
sys.setrecursionlimit(10**6)

n=i1()
s=input()
q=i1()
N=0
while n:
  n>>=1
  N+=1
n=2**N

t=[0 for i in range(2*n-1)]

def ud(i,x):
  i+=n-1
  t[i]=x
  while i:
    i=(i-1)//2
    t[i]=t[i*2+1] | t[i*2+2]

def qr(a,b,k,l,r):
  
  if r<=a or b<=l:
     return 0
  elif a<=l and r<=b:
     
     return t[k]
  else:
     return qr(a,b,k*2+1,l,(l+r)//2) | qr(a,b,k*2+2,(l+r)//2,r)

for i in range(len(s)):
  ud(i,1<<(ord(s[i])-ord("a")))

while q:
 [ty,i,c]=[i for i in input().split()]
 ty=int(ty)
 i=int(i)
 if ty==1:
   ud(i-1,1<<(ord(c)-ord("a")))
 else:
   c=int(c)
   x=0
   z=qr(i-1,c,0,0,n)
   while z:
     if z%2==1:
        x+=1
     z>>=1
   print(x)
 q-=1


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

int main(){
  string s,c="Yes";
  cin >> s;
  int a[26]={};
  for(int i=0;i<3;i++){
    a[s.at(i)-97]++;
  }
  for(int i=0;i<3;i++){
    if(a[i]<1)
      c = "No";
  }
  cout << c << endl;
}

Measured memory_bytes: 256
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter, deque
import itertools
#from scipy.misc import comb

MOD = 10**9+7
N = int(input())

pf = [0]*(N+1)
for n in range(2,N+1):
    q = n
    i = 2
    while q>1:
        if q%i == 0:
            pf[i] += 1
            q /= i
        else:
            i += 1

ans = 1
for f in pf:
    ans = (ans*(f+1))%MOD

print(ans)

Measured memory_bytes: 12096
/* 
   AOJ 1192
   Tax Rate Changed
   2015.4.27
 */

#include<stdio.h>

int search_max_conbi(int prev_tax_rate, int next_tax_rate, int prev_total_price)
{
  int max_total = 0, exc_x, exc_y, inc_x, inc_y, new_inc_x, new_inc_y;
  for(exc_x = 1; exc_x < prev_total_price; exc_x++)
    {
      inc_x = exc_x * (100 + prev_tax_rate) / 100;
      for(exc_y = 1; exc_y < prev_total_price; exc_y++)
	{
	  inc_y = exc_y * (100 + prev_tax_rate) / 100;
	  if(inc_x + inc_y == prev_total_price)
	    {
	      new_inc_x =  exc_x * (100 + next_tax_rate) / 100;
	      new_inc_y =  exc_y * (100 + next_tax_rate) / 100;
	      if(max_total <= new_inc_x + new_inc_y)
		{
		  max_total = new_inc_x + new_inc_y;
		}
	    }
	}
    }
  return max_total;
}

int main(void)
{
  int prev_tax_rate, next_tax_rate, prev_total_price, next_max_price;
  while(1)
    {
      scanf("%d %d %d", &prev_tax_rate, &next_tax_rate, &prev_total_price);
      if(prev_tax_rate == 0 && next_tax_rate == 0 && prev_total_price == 0)
	{
	  break;
	}
      
      next_max_price = search_max_conbi(prev_tax_rate, next_tax_rate, prev_total_price);

      printf("%d\n", next_max_price);
    }
  return 0;
}

Measured memory_bytes: 600
N = int(input())
B = [-1] + [int(b) for b in input().split()]

A = []
for i in range(1, N+1):
    if i == 1:
        A.append(B[1])
    elif i == N:
        A.append(B[N-1])
    else:
        A.append(min(B[i-1], B[i]))

print(sum(A))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;
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 long long INF = 1LL << 60;

int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}

int digsum(int n) {
  int res = 0;
  while(n > 0) {
    res += n%10;
    n /= 10;
  }
  return res;
}

int dignum(int n) {
  int res = 0;
  while(n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

int stringcount(string s, char c) {
  return count(s.cbegin(), s.cend(), c);
}

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

int combi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

int main(){
  lint n,m;
  cin>>n>>m;
  vector<pair<lint,lint>> l;
  lint h=1;
  rep(i,n){
    lint j;cin>>j;
    pair<lint,lint> e;
    e.first=j;e.second=h;
    l.pb(e);
  }
  rep(i,m){
    lint a,b;cin>>a>>b;
    pair<lint,lint> e;
    e.first=b;e.second=a;
    l.pb(e);
  }

  sort(all(l));
  reverse(all(l));
  lint r=0;
  lint count=0;
  rep(i,n){
    if(l[r].second>0){
      count+=l[r].first;
      l[r].second--;
    }
    else{
      r++;
      count+=l[r].first;
      l[r].second--;
    }
  }
  cout<<count;
}

Measured memory_bytes: 6512
import sys
  
for s in sys.stdin:
    h,w = [ int(x) for x in s.split() ]

    if h==0 and w==0:
        break

    for i in range(h):
        if i % 2 == 0:
            print('#.'*(w//2) + '#'*(w%2))
        else:
            print('.#'*(w//2) + '.'*(w%2))

    print()


Measured memory_bytes: 5636
h,n=map(int,input().split())
a=[]
ab=[]

for i in range(n):
    aabb=list(map(int,input().split()))
    ab.append(aabb)
    a.append(aabb[0])

loop=h+max(a)
cost=[-1 for i in range(loop)]
cost[0]=0
i=0
costlist=[]
while i<loop:
    costlist=[]
    for j in range(n):
        ii=i-ab[j][0]
        if (0<=ii<h)&(cost[ii]>=0):
            costlist.append(cost[ii]+ab[j][1])
    if len(costlist)!=0:
        cost[i]=min(costlist)
    i+=1
acost=[i for i in cost[h:] if i!=-1]
ans=min(acost)
print(ans)

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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;
template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
inline double distance(double y1, double x1, double y2, double x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }

const int INF = 1L << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = { 0, 1, 0, -1 }, dx4 = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;

void solve(long long A, long long B) {
    int ans = 0;
    FOR(x, A, B + 1) {
        string s = to_string(x);
        string t = string(s);
        reverse(ALL(t));
        ans += (s == t);
    }
    print(ans);
}

int main(){	
	long long A;
	long long B;
	cin >> A >> B;
	solve(A, B);
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
int main(){
    long long h;
    cin >> h;
    long long ans = 0;
    long long now = 1;
    while(h>0){
        ans+=(now);
        now*=2;
        h/=2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,c;
    cin>>n>>m>>c;
    vector<int> b(m);
    for(int i=0;i<m;i++)
    cin>>b[i];
    int a[n][m];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++)
        cin>>a[i][j];
    }
    int ans=0;
    for(int i=0;i<n;i++){
        int cnt=c;
        for(int j=0;j<m;j++){
            cnt+=(a[i][j]*b[j]);
        }
        if(cnt>0)
        ans++;
    }
    cout<<ans<<endl;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define each(i,a) for (auto&& i : a)
#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__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll x, y; cin >> x >> y;
    ll ans = 0;
    while (x <= y) {
        x *= 2;
        ++ans;
    }
    cout << ans << endl;
}


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

vector<vector<int>> ans;
int main(){
  string str;
  while(getline(cin, str),str != "END OF INPUT"){
    vector<int> num;
    int count =0 ;
    for(int i=0; i<str.size(); ++i){
      //cout << count << endl;
      if(str[i]==' '){
	//cout << "tnp" << endl;
	num.push_back(count);
	count = 0;
      }else{
	++count;
      }
    }
    num.push_back(count);
    ans.push_back(num);
  }
  for(auto i:ans){
    for(auto j:i){
      cout << j;
    }
    cout << endl;
  }
  return 0;
}
  
  

Measured memory_bytes: 3064
require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N = get_int
A = get_ints_minus_one

res = Array.new(N) { 0 }

A.each.with_index do |a, i|
  res[a] += 1
end

res.each do |r|
  puts r
end


Measured memory_bytes: 35608
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <cmath>


int main(){
  
  // read problem
  long long int N, tmp1, tmp2;
  std::vector<long long int> x, y;
  
  scanf("%lld", &N);
  for(long long int i = 0; i < N; i++){
    scanf("%lld%lld", &tmp1, &tmp2);
    x.push_back(tmp1);
    y.push_back(tmp2);
  }
  
  long long int max = 1;
  for(long long int i = 0; i < N; i++){
    max *= N;
  }
  
  int flag;
  double count = 0.0;
  double p1, p2;
  double dist;
  double ans = 0.0;
  std::vector<long long int> visited(N);
  std::vector<long long int> visit(N);
  
  // solve problem
  for(long long int i = 0; i < max; i++){ // for all order
    
    //std::cerr << "i = " << i << std::endl << "visit" << std::endl;
    for(long long int j = 0; j < N; j++){
      visited[j] = 0;
    }
    
    tmp1 = i;
    flag = 1;
    for(long long int j = 0; j < N; j++){
      visit[j] = tmp1%N;
      tmp1 /= N;
      if(visited[visit[j]] != 0){
        flag = 0;
        break;
      }visited[visit[j]] = 1;
    }
    
    if(flag == 1){
      count++;
      dist = 0.0;
      for(long long int j = 1; j < N; j++){
        dist += std::sqrt(((double)x[visit[j-1]] - x[visit[j]])*(x[visit[j-1]] - x[visit[j]])+((double)y[visit[j-1]] - y[visit[j]])*(y[visit[j-1]] - y[visit[j]]));
      }
      ans = ans * (count-1.0)/count + dist/count;
    }
    /*tmp1 = i;
    p1 = tmp1%N;
    visited[p1] = 1;
    //std::cerr << p1 << " " << std::endl;
    flag = 0;
    dist = 0.0;
    
    for(long long int j = 1; j < N; j++){
      // update state
      tmp1 /= N;
      p2 = p1;
      p1 = tmp1%N;
      //std::cerr << p1 << " " << std::endl;
      // check second visit
      if(visited[p1] != 0){
        flag = 1;
      }visited[p1] = 1;
      
      dist += std::sqrt(((double)x[p1] - x[p2])*(x[p1] - x[p2])+((double)y[p1] - y[p2])*(y[p1] - y[p2]));
    }*/
    
    
    
    //if(flag == 0){
      //count++;
      //ans = ans * (count-1.0)/count + dist/count;
      /*std::cerr << "success" << std::endl;
      std::cerr << "count = " << count << std::endl;
      std::cerr << "ans = " << ans << std::endl;*/
   // }
  }
  
  std::cerr << "Answer:" << std::endl;
  std::cout << std::setprecision(15) << ans << std::endl;

  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll                 long long int
#define mod                1000000007
#define pi                 3.14159265358979323846264338327950288419716939937510
#define setbit(x)          __builtin_popcountll(x)
#define db                 double
#define pp(x)              pair<x,x>
#define ff                 first
#define ss                 second
#define FIO                ios_base::sync_with_stdio(false); cin.tie(NULL);
#define tc                 ll tc; cin>>tc; for(ll number = 1 ; number <= tc ; number ++ )
#define vv(x)              vector<x>
#define pb                 push_back
#define pob                pop_back
#define pf                 push_front
#define pof                pop_front
#define endl               "\n"
#define pq                 priority_queue
#define dbg(x)             { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y)          { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define bp                 ll kkk; cin >>kkk;
#define dbgArr(a,n)        cout<<"Array "<<#a<<endl; for(ll i=0 ; i<n ; i++) cout<<a[i]<<" "; cout<<endl;
#define maxE(a,n)          *max_element(a,a+n);
#define minE(a,n)          *min_element(a,a+n);
#define forn(i,s,n)        for(ll i=s ; i<n ; i++)
#define fornr(i,e,s)       for(ll i=e-1 ; i>=s ; i--)
#define arr(a,n)           for(ll i=0;i<n;i++){ cin>>a[i]; }
#define arr1(a,n)          for(ll i=1;i<=n;i++){ cin>>a[i]; }
#define file freopen("input.txt","r",stdin); freopen("output.txt","w",stdout)
#define print cout<<"Case #"<<number<<": "
#define all(x) x.begin(), x.end()
ll power(ll x, ll b) {ll p = 1;while (b > 0) {if(b&1) {p = p * x; p %= mod;} b >>= 1; x *= x; x %= mod;} return p % mod;}
using namespace std;
# define INF 1e15
struct lex_compare {
    bool operator() (const pair<db,ll>  p1, const pair<db,ll> p2){
        return (p1.first ==  p2.first) ? p1.ss < p2.ss : p1.first > p2.first;
    }
};
#define MAXN 1005
char arr[7][7];
ll dp[100][100];
ll n,m,k;

int main(){
    FIO;
    cin >> n >> m>> k;
    memset(dp,0,sizeof(dp));
    forn(i,0,n){
        forn(j,0,m){
            cin >> arr[i][j];
        }
    }
    ll allr = pow(2,n);
    ll allc = pow(2,m);
    //dbg2(allr,allc);
    ll ans = 0;
    forn(a1,0,allr){
        forn(a2,0,allc){
            ll check = 0;
            forn(i,0,n){
                forn(j,0,m){
                    if(arr[i][j] == '#'){
                        if( ( (a1&(1<<i)) ) == 0 && ( (a2&(1<<j)) ) == 0){
                            check++;
                        }
                    }
                }
            }
            if(check == k){
                ans+= 1;
            }else{
                ans += 0;
            }

        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4116
def min(a, b)
   (a < b) ? a : b
end

n = gets.chomp.to_i
tmp = gets.chomp
a_ary = tmp.split(" ")
a_ary.map! do |a|
  a.to_i
end

tmp = gets.chomp
b_ary = tmp.split(" ")
b_ary.map! do |b|
  b.to_i
end

result = 0

idx = 0
while idx < n do
  result += min(a_ary[idx], b_ary[idx])
  r_power = b_ary[idx] - a_ary[idx]
  if 0 < r_power
  	result += min(a_ary[idx+1], r_power)
  	a_ary[idx + 1] -= min(a_ary[idx+1], r_power)
  end
  idx += 1
end

puts result



Measured memory_bytes: 15652
X=int(input())
a=0
if 400<=X<=599:
    a=8
elif 600<=X<=799:
    a=7
elif 800<=X<=999:
    a=6
elif 1000<=X<=1199:
    a=5
elif 1200<=X<=1399:
    a=4
elif 1400<=X<=1599:
    a=3
elif 1600<=X<=1799:
    a=2
elif 1800<=X<=1999:
    a=1

print(a)

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

int card[255][14] = {{0}};

int main(void){
    int n;
    cin >> n;
    for(int i=0; i <n ; i++){
        char c;
        int num;
        cin >> c >> num;
        card[(int)c][num] = 1;
    }
    for(int i =1; i <= 13; i++){
        if(card[(int)'S'][i] == 0){
            cout << "S "<< i << endl;
        }
    }
    
    for(int i =1; i <= 13; i++){
        if(card[(int)'H'][i] == 0){
            cout << "H "<< i << endl;
        }
    }
    
    for(int i =1; i <=13; i++){
        if(card[(int)'C'][i] == 0){
            cout << "C " << i << endl;
        }
    }
    
    for(int i=1; i <= 13; i++){
        if(card[(int)'D'][i] == 0){
        cout << "D " << i << endl;
        }
    }
}



Measured memory_bytes: 3096
# https://atcoder.jp/contests/abc116/tasks/abc116_b

s = int(input())
c = {}

c[s] = 1

prev = s
i = 2
while True:
    prev = int(prev/2) if prev % 2 == 0 else 3 * prev + 1
    if prev in c:
        print(i)
        exit()
    # print(prev)
    c[prev] = i
    i += 1





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

int main(){
    int N, M;
    cin >> N >> M;
    vector<vector<bool>> A(M, vector<bool>(N, false));
    vector<int> p(M);
    for(int i = 0; i < M; i++){
        int k;
        cin >> k;
        for(int j = 0; j < k; j++){
            int s;
            cin >> s;
            s--;
            A[i][s] = true;
        }
    }
    for(int i = 0; i < M; i++)cin >> p[i];
    
    int ans = 0;
    
    for(int tmp = 0; tmp < (1 << N); tmp++){
        vector<int> light;
        for(int i = 0; i < N; i++){
            if(tmp & (1 << i))light.push_back(i);
        }
        
        int n = light.size();
        
        bool all = true;
        for(int i = 0; i < M; i++){
            int Lig = 0;
            for(int j = 0; j < n; j++){
                if(A[i][light[j]])Lig++;
            }
            if(Lig % 2 != p[i])all = false;
        }
        if(all)ans++;
    }
    
    cout << ans << endl;
    return 0;
}

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

using namespace std;

double n;
double num = 1;
double k;
double m = 0; 
int value;
double elev;
double ans = 0;
double calc;
double prob;

int main(){
    cin >> n >> k;
    prob = num/n;
    for(int dice = 1; dice < n + 1; dice++){
        value = dice;
        m = 0;
        while(value<k){
            value = value * 2;
            m = m + 1;
        }
        elev = pow(0.5, m);
        calc = calc + elev;
        ans = prob * calc;
    }
    cout << fixed;
    cout << setprecision(12);
    cout << ans;
}

Measured memory_bytes: 256