akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(){
	
	int a[11][11],d=1,w=1,i,t,D,W,y,x,Y,X,S,T,N,M;
	
	while(d!=0||w!=0){
		scanf("%d %d",&d,&w);
		if(d==0&&w==0) break;
		for(i=0;i<d;i++){
			for(t=0;t<w;t++){
				scanf("%d",&a[i][t]);
			}
		}
		//入力確認用ループ
		
		/*for(i=0;i<d;i++){
			printf("\n");
			for(t=0;t<w;t++){
				printf("%d ",a[i][t]);
			}
		}
		printf("\n");*/
		i=0;
		N=0;
		for(D=3;D<d+1;D++){//Dは長方形の高さ
			for(W=3;W<w+1;W++){//Wは長方形の幅
				for(y=0;y<d-D+1;y++){//yは長方形の左上のy座標
					for(x=0;x<w-W+1;x++){//xは長方形の左上のx座標
						//printf("%d %d %d %d\n\n",D,W,y,x);//現在の長方形の情報
						M=0;S=10;T=0;
						
						for(Y=y;Y<y+D;Y++){//Sは外枠の最小値
							if(Y==y||Y==y+D-1){
								for(X=x;X<x+W;X++){
									if(a[Y][X]<S){
										S=a[Y][X];
									}
								}
							}
							else {
								if(a[Y][x]<S){
									S=a[Y][x];
								}
								if(a[Y][x+W-1]<S){
									S=a[Y][x+W-1];
								}
							}
						}
						for(Y=y+1;Y<y+D-1;Y++){//Tは内側の最大値
							for(X=x+1;X<x+W-1;X++){
								if(a[Y][X]>T){
									T=a[Y][X];
								}
							}
						}
						//printf("%d %d\n\n",S,T);//今回の長方形のSとT
						if(S>T){                        //Mは今回の長方形の容量
							for(Y=y+1;Y<y+D-1;Y++){
								for(X=x+1;X<x+W-1;X++){
									M=M+S-a[Y][X];
								}
							}
						}
						if(N<M){//Nは今まで試した長方形の中の最大容量
							N=M;
						}
						i++;
					}
				}
			}
		}
		//printf("%d\n",i);//iは試行回数
		printf("%d\n",N);
	}
	return 0;
}


Measured memory_bytes: 2604
while True:
    m, f, r = map(int, input().split(" "))
    if m == f == r == -1:
        break
    elif m == -1 or f == -1 :
        print("F")
    elif m+f >= 80:
        print("A")
    elif m+f >= 65:
        print("B")
    elif m+f >= 50 or r >= 50:
        print("C")
    elif m+f >= 30:
        print("D")
    elif m+f < 30:
        print("F")


Measured memory_bytes: 5592
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif


int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	string S;
	cin >> S;

	auto query = [&](int k) {

		lint c = 0, M_cnt = 0, C_cnt = 0, MC_cnt = 0;
		lint ans = 0;
		for (int a = 0; a < N; a++) {

			if (S[a] == 'D') {
				while (c < N && c - a < k) {
					if (S[c] == 'M') M_cnt++;
					if (S[c] == 'C') {
						C_cnt++;
						MC_cnt += M_cnt;
					}
					c++;
				}
				ans += MC_cnt;
			}

			else if (S[a] == 'M') {
				M_cnt--;
				MC_cnt -= C_cnt;
			}

			else if (S[a] == 'C') C_cnt--;

		}

		return ans;

	};

	int Q;
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		int k;
		cin >> k;
		cout << query(k) << "\n";
	}

	return 0;
}

Measured memory_bytes: 1948
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main(){
    IOS;
    int t;
    cin >> t;
    vector<int> vec;
    for(int i=0; i<t; i++){
        int a;
        cin >> a;
        vec.push_back(a);
    }
    sort(vec.begin(),vec.end());
    double count =vec[0];
    double ans = 0;
    for(int i=1; i<vec.size(); i++){
        ans = (count+vec[i])/2;
        count = ans;
    }
    cout << ans <<endl;
}

Measured memory_bytes: 3784
Q = int(input())
lr = [tuple(map(int, input().split())) for i in range(Q)]


def primes(n):
    ret = []
    A = [i for i in range(2, n+1)]
    k = 0
    s = n**0.5
    while(k < s):
        ret.append(A[0])
        k = A[0]
        A = [x for x in A if x % k]
    ret += A
    return ret


prime = primes(10**5)

prime_s = set(prime)
t = [0]*(10**5 + 1)
for i in range(1, 10**5+1):
    if i in prime_s and (i+1)//2 in prime_s:
        t[i] = 1
for i in range(1, 10**5+1):
    t[i] = t[i] + t[i-1]

for l, r in lr:
    print(t[r] - t[l-1])


Measured memory_bytes: 68824
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    rep(i, n) cin >> a[i], a[i]--;

    vector<int> ql(q), qr(q), qi(q);
    rep(i, q) cin >> ql[i] >> qr[i], ql[i]--;
    iota(qi.begin(), qi.end(), 0);

    int width = n / sqrt(q);
    sort(qi.begin(), qi.end(), [&](int i, int j) {
        if (ql[i] / width != ql[j] / width) return ql[i] < ql[j];
        else {
            if ((ql[i] / width) % 2 == 0) return qr[i] < qr[j];
            else return qr[i] > qr[j];
        }
    });

    vector<int> cnt(n), ans(q);
    int sum = 0;
    int l = 0, r = 0;

    auto add = [&](int i) { if (cnt[a[i]]++ == 0) sum++;};
    auto del = [&](int i) { if (--cnt[a[i]] == 0) --sum;};
    
    for (int i : qi) {
        while (ql[i] < l) add(--l);
        while (r < qr[i]) add(r++);
        while (l < ql[i]) del(l++);
        while (qr[i] < r) del(--r);
        ans[i] = sum;
    }
    
    rep(i, q) cout << ans[i] << '\n';
}


Measured memory_bytes: 15480
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from collections import Counter

h, w = map(int, readline().split())
a = []
for i in range(h):
    a += list(readline().rstrip().decode())
counter = Counter(a).values()
check = [1, h // 2 + w // 2, (h // 2) * (w // 2)]
if h % 2 == 0:
    check[0] = 0
    check[1] -= w // 2
if w % 2 == 0:
    check[0] = 0
    check[1] -= h // 2
for v in counter:
    if check[2] < v // 4:
        v -= 4 * check[2]
        check[2] = 0
    else:
        check[2] -= v // 4
        v %= 4
    if check[1] < v // 2:
        v -= 2 * check[1]
        check[1] = 0
    else:
        check[1] -= v // 2
        v %= 2
    check[0] -= v
print('Yes' if all(check[i] == 0 for i in range(3)) else 'No')


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,m,a,ans=0,k=0,k_prev=0;cin>>n>>m;
  vector<ll> h(n,0);
  rep(i,n) {cin>>a;h[i]=a/2;}
  a=h[0];while(a%2==0) {k_prev++;a/=2;} bool is_ok=true;
  for(ll i=1;i<n;++i) {
    a=h[i];k=0;
    while(a%2==0) {a/=2;k+=1;}
    if(k==k_prev) k_prev=k;
    else {is_ok=false;break;}
  }
  if(is_ok) {
    sort(h.begin(),h.end());
    ll lcm=h[0],gcd=0;
    if (n>=2) {
      for (ll i=1;i<n;++i) {
        gcd=__gcd(lcm,h[i]);
        lcm=(lcm*h[i])/gcd;
      } 
    }
    ans=((m/lcm)+1)/2;
  }
  print(ans);
  return 0;
}

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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  string S;
  cin >> S;
  int N = S.size();
  int r = 0, b = 0;
  REP(i, N) if (S[i] == '0') r++;
  b = N - r;
  cout << min(r, b) * 2 << endl;
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,i,a,b,s=0;
	cin>>n;
	for(i=1;i<=n;i++){
	cin>>a>>b;
	    s+=(b-a+1);
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define dunk(a) cout << (a) << endl
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;

int main() {
	int r; cin >> r;
	dunk(r * r);
	return 0;
}


Measured memory_bytes: 256
def decomposition(x):
    ret = []
    for i in range(1, int(x**0.5)+1):
        if x%i==0:
            ret.append(i)
            if x//i!=i:
                ret.append(x//i)
    return sorted(ret)

n = int(input())
s = decomposition(n)
t = decomposition(n-1)
ans = 0
for num in s:
    if num==1:
        continue
    tmp = n
    while tmp%num==0:
        tmp = tmp//num
    if tmp%num==1:
        ans += 1
print(ans+len(t)-1)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define rep(i,j,k) for(int i=j;i<k;i++)
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
int main(){
  int a,b;
  cin >> a >> b;
  int res = max(a+b,a-b);
  res = max(res,a*b);
  cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int cnt = 0;
		while(sc.hasNext()){
			String str = sc.next();
			String STR = "";
			StringBuilder sb = new StringBuilder(str.length());
			sb.append(str);
			STR = sb.reverse().toString();
			if(STR.equals(str))cnt++;
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 25896
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int w,h;
int t[1005][1005],y[1005][1005];
int dp[1005][1005];
int main(void){
    scanf("%d%d",&w,&h);
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            int x;
            scanf("%d",&x);
            t[i][j]+=x;
            y[i][j]+=x;
            t[i+1][j]+=t[i][j];
            y[i][j+1]+=y[i][j];
        }
    }
    for(int i=h;i>=0;i--){
        for(int j=w;j>=0;j--){
            int x=dp[i+1][j]+y[i+1][w]-y[i+1][j],y=dp[i][j+1]+t[i][j+1]-t[h][j+1];
            if(i==h)dp[i][j]=y;
            else if(j==w)dp[i][j]=x;
            else{
                if((i+j)%2==0)dp[i][j]=max(x,y);
                else dp[i][j]=min(x,y);
            }
        }
    }
    printf("%d\n",abs(dp[0][0]));
}


Measured memory_bytes: 15020
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = LLONG_MAX;
const ll MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll N, ans = 0;
    cin >> N;
    vector<int> d(N);
    rep(i, N) { cin >> d[i]; }
    rep(i, N)
    {
        rep(j, N)
        {
            if (i != j) {
                ans += d[i] * d[j];
            }
        }
    }
    cout << ans / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define mat vector<vector<int>>
const int inf = 1 << 30;
const ll linf = 1e18;
const db EPS = 1e-7;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int N;
ll K;
vector<ll> A, F;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N >> K;
    for(int i = 0; i < N; ++i){
        int a;
        cin >> a;
        A.push_back(a);
    }
    for(int i = 0; i < N; ++i){
        int f;
        cin >> f;
        F.push_back(f);
    }
    sort(A.begin(), A.end());
    sort(F.rbegin(), F.rend());
    ll lb = -1, ub = linf;
    while(ub - lb > 1){
        ll mid = (ub + lb) / 2;
        ll cnt = 0;
        for(int i = 0; i < N; ++i){
            ll d = mid / F[i];
            cnt += max(A[i] - d, 0LL);
        }
        if(cnt > K) lb = mid;
        else ub = mid;
    }
    cout << ub << endl;
    return 0;
}

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

int main(){
	cin.tie(0);ios::sync_with_stdio(0);
	string S;
	
	cin >> S;
	
	set<char> conj;
	for( int i = 0; i < S.size(); i++ ){
		conj.insert( S[i] );
	}
	
	bool band = true;
	for( int i = 0; i < S.size(); i++ ){
		if( S[i] == 'N' && !conj.count( 'S' ) )
			band = false;
		if( S[i] == 'S' && !conj.count( 'N' ) )
			band = false;
		if( S[i] == 'W' && !conj.count( 'E' ) )
			band = false;
		if( S[i] == 'E' && !conj.count( 'W' ) )
			band = false;
	}
	
	if( band )
		cout << "Yes\n";
	else
		cout << "No\n";
	
	
	return 0;
}

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

vector<P>E[100000];
ll d[100000];
struct st {
	int a, b, d;
}v[200000];
int main() {
	ll n, m, c; scanf("%lld%lld%lld", &n, &m, &c);
	ll sum = 0;
	rep(i, m) {
		int a, b, d; scanf("%d%d%d", &a, &b, &d); a--; b--;
		E[a].push_back(P(d, b)); E[b].push_back(P(d, a));
		v[i] = { a,b,d }; sum += d;
	}
	priority_queue<P, vector<P>, greater<P>>que;
	memset(d, 0x3f, sizeof(d));
	que.push(P(0, 0)); d[0] = 0;
	while (!que.empty()) {
		P p = que.top(); que.pop();
		if (d[p.second] != p.first)continue;
		for (P u : E[p.second]) {
			if (d[u.second] > p.first + u.first) {
				d[u.second] = p.first + u.first;
				que.push(P(d[u.second], u.second));
			}
		}
	}
	sort(v, v + m, [&](st&a, st&b) {return max(d[a.a], d[a.b]) < max(d[b.a], d[b.b]); });
	ll Min = sum, Max = 0;
	rep(i, m) {
		Max = max(Max, (ll)max(d[v[i].a], d[v[i].b]));
		sum -= v[i].d;
		Min = min(Min, c*Max + sum);
	}
	printf("%lld\n", Min);
}

Measured memory_bytes: 19628
import Data.List
import Control.Monad

main = do
  [n,m,l] <- fmap (map read . words) getLine :: IO [Int]
  mat1 <- replicateM n $ fmap (map read . words) getLine :: IO [[Int]]
  mat2 <- replicateM m $ fmap (map read . words) getLine :: IO [[Int]]
  let mat3 = matrixProduct mat1 mat2
  putStr . output $ mat3

matrixProduct mat1 mat2 = map (\v -> vectorMatrixProduct v $ transpose mat2) mat1

vecterProduct v1 v2 = sum $ zipWith (*) v1 v2

vectorMatrixProduct v mat = map (vecterProduct v) mat

output mat = unlines . map unwords . map (map show) $ mat



Measured memory_bytes: 12304
#include <atcoder/maxflow>
#include <iostream>
#include <vector>
#define rep(i, j, n) for (int i = 0; i < n; ++i)
using namespace std;
int n, m;
int dx[4]{0, 0, 1, -1};
int dy[4]{1, -1, 0, 0};

int main() {
  cin >> n >> m;
  vector<string> g(n);
  rep(i, 0, n) cin >> g[i];

  int s = n * m;
  int t = n * m + 1;
  atcoder::mf_graph<int> mf(n * m + 2);
  rep(y, 0, n) rep(x, 0, m) if ((x + y) % 2 == 0 && g[y][x] == '.')
    rep(k, 0, 4) {
    int ny = y + dy[k];
    int nx = x + dx[k];
    if (0 <= nx && nx < m && 0 <= ny && ny < n && g[ny][nx] == '.')
      mf.add_edge(y * m + x, ny * m + nx, 1);
  }
  rep(y, 0, n) rep(x, 0, m) {
    if ((x + y) % 2 == 0)
      mf.add_edge(s, y * m + x, 1);
    else
      mf.add_edge(y * m + x, t, 1);
  }

  int c = mf.flow(s, t);
  for (auto e : mf.edges()) {
    if (e.flow == 1) {
      int a = e.to;
      int b = e.from;
      if (a > b) swap(a, b);
      if (b >= n * m) continue;
      if (a / m == b / m) {
        g[a / m][a % m] = '>';
        g[b / m][b % m] = '<';
      } else {
        g[a / m][a % m] = 'v';
        g[b / m][b % m] = '^';
      }
    }
  }
  cout << c << '\n';
  rep(i, 0, n) cout << g[i] << '\n';
  return 0;
}

Measured memory_bytes: 5340
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk make_pair
#define pb push_back
#define eb emplace_back
#define ins insert
#define fi first
#define se second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=4e3+5;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}
int n,a[MAXN],Min[MAXN][MAXN];ll x,ans=1e18;
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read(),x=read();
	Rep(i,1,n)a[i]=a[n+i]=read();
	Rep(i,1,n){Min[i][0]=a[i];Rep(j,1,n-1)Min[i][j]=min(Min[i][j-1],a[i+j]);}
	Rep(t,0,n-1){ll tmp=x*t;Rep(i,1,n)tmp+=Min[i][t];ans=min(ans,tmp);}
	cout<<ans<<'\n';
	return 0;
}




Measured memory_bytes: 27220
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double N = sc.nextInt();
        double K = sc.nextInt();
        double tmp = 0.0;
        double kakuritu = 0.0;

        for(int i = 0; i < N; i++){
          for(int j = 0; j < 1000000 ; j++ ){
            if (((i+1) * Math.pow(2.0,j)) >= K){
              tmp = Math.pow(0.5,j) / N;
              break;
            }

          }
          kakuritu += tmp;
          //kakuritu = kakuritu / N;
        }
        System.out.println(kakuritu);
}
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int siz=1e5;
const int inf=1e9;
int main(){
	int A,B; cin>>A>>B;
	cout<<A*B<<endl;
}

Measured memory_bytes: 3640
n = int(input())
sl = [" " for i in range(n)]
tl = [0 for i in range(n)]

for i in range(n):
    st, tt = input().split()
    sl[i] = st
    tl[i] = int(tt)

X = input()


index = sl.index(X)
ans = 0
for i in range(index + 1, n):
    ans += tl[i]

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,k;cin>>n>>k;
    long double ans = 0;
    for(ll i=1;i<=min(n,k-1);i++){
        long double cur = 1.0/(n*1.0);
        ll req=0,p=1;
        while(i*p<k)p*=2,req++;
       // cout<<i<<" "<<p<<" "<<req<<" "<<cur<<" ";
        while(req-->0)cur*=(1.0/2.0);
       // cout<<cur<<endl;
        ans+=cur;
    }
    for(ll i=k;i<=n;i++)ans+=(1.0/(n*1.0));
    cout<<fixed<<setprecision(18)<<ans;
}

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

#define rep(i,a,b) for(int i=a;i<b;i++)
#define NUM_MAX 205
#define CENTER 102

int mass[NUM_MAX][NUM_MAX];
int height[NUM_MAX][NUM_MAX];

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

int get_s(int t, int f)
{
	int a, b, c;
	switch (t)
	{
	case 1: a = 1, b = 3, c = 5; break;
	case 2: a = 2, b = 3, c = 1; break;
	case 3: a = 3, b = 6, c = 5; break;
	case 4: a = 4, b = 1, c = 5; break;
	case 5: a = 5, b = 3, c = 6; break;
	case 6: a = 6, b = 4, c = 5; break;
	}

	while (b != f)
	{
		int tmp = 7 - b;
		b = c;
		c = tmp;
	}

	return c;
}

void put(int t, int f, int x, int y)
{
	int s = get_s(t, f);

	int nums[4] = {f, s, 7-f, 7-s};
	int max_num = 0;
	int max_dir = -1;
	rep(i, 0, 4)
	{
		if (nums[i] < 4) continue;
		int xx = x + dx[i];
		int yy = y + dy[i];
		if (height[yy][xx] >= height[y][x]) continue;

		if (max_num < nums[i])
		{
			max_num = nums[i];
			max_dir = i;
		}
	}

	if (max_dir < 0)
	{
		mass[y][x] = t;
		height[y][x]++;
	}
	else
	{
		switch (max_dir)
		{
		case 0: put(7 - f, t, x + dx[max_dir], y + dy[max_dir]); break;
		case 1: put(7 - s, f, x + dx[max_dir], y + dy[max_dir]); break;
		case 2: put(f, 7-t, x + dx[max_dir], y + dy[max_dir]); break;
		case 3: put(s, f, x + dx[max_dir], y + dy[max_dir]); break;
		}
	}
}

int main()
{
	while (1)
	{
		int n; cin >> n;
		if (n == 0) return 0;

		rep(i, 0, NUM_MAX) rep(j, 0, NUM_MAX)
		{
			mass[i][j] = 0;
			height[i][j] = 0;
		}

		rep(i, 0, n)
		{
			int t, f;
			cin >> t >> f;
			put(t, f, CENTER, CENTER);
		}

		int count[7];
		rep(i, 0, 7) count[i] = 0;
		rep(i, 0, NUM_MAX) rep(j, 0, NUM_MAX) count[mass[i][j]]++;

		cout << count[1];
		rep(i, 2, 7) cout << " " << count[i];
		cout << endl;
	}
}

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

int n, q, x[200010], d[200010], l[200010];

struct bittree
{
  int tree[200010];
  void reset()
  {
    for(int i = 1; i <= 200008; i++)
      add(i, 200008, 1);
  }
  void add(int start, int end, int val)
  {
    for(int i = end; i > 0; i -= i & -i)
      tree[i] += val;
    for(int i = start - 1; i > 0; i -= i & -i)
      tree[i] -= val;
  }
  int sum(int num)
  {
    int ret = 0;
    for(int i = num; i <= 200008; i += i & -i)
      ret += tree[i];
    return ret;
  }
  int l_bound(int val)
  {
    int start = 1, end = 200008;
    while(start < end){
      int mid = (start + end) / 2;
      if(sum(mid) >= val)
	end = mid;
      else
	start = mid + 1;
    }
    return start;
  }
} tr[2];

signed main()
{
  scanf("%lld%lld", &n, &q);
  for(int i = 0; i < q; i++)
    scanf("%lld%lld%lld", &x[i], &d[i], &l[i]);

  tr[0].reset();
  tr[1].reset();

  for(int i = q - 1; i >= 0; i--){
    if(d[i] == 1)
      tr[0].add(1, tr[1].l_bound(x[i] + 1) - 1, -l[i] * 2);
    else
      tr[1].add(tr[0].l_bound(x[i] + 1), 200008, l[i] * 2);
  }

  for(int i = 1; i <= n; i++)
    printf("%lld\n", (i - tr[0].sum(i)) / 2 + (tr[1].sum(i) - i) / 2);

  return 0;
}

Measured memory_bytes: 11032
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll a, b, c;

int main(){
	cin >> a >> b >> c;
	if(a == b && b == c){cout << "Yes" << endl;}
	else{cout << "No" << endl;}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1020000000

int d[200][200];
int dp[1<<8][8];

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

  vector<int> vec(r);
  rep(i,r) cin>>vec[i], vec[i]--;

  fill(d[0], d[200], INF);
  rep(i,m){
    int a,b,c;
    cin>>a>>b>>c;
    a--;b--;
    d[a][b] = d[b][a] = c;
  }

  rep(i,n) d[i][i] = 0;
  rep(k,n) rep(i,n) rep(j,n) d[i][j] = min(d[i][j], d[i][k] + d[k][j]);

  fill(dp[0], dp[1<<r], INF);
  rep(i,r) dp[1<<i][i] = 0;

  rep(mask, 1<<r) rep(i,r) if(dp[mask][i]<INF) {
    rep(j,r) if( (mask>>j)%2 == 0 ){//dbg(mask,i,j, dp[mask][i]);
      dp[mask | (1<<j)][j] = min(dp[mask | (1<<j)][j], dp[mask][i] + d[vec[i]][vec[j]]);
    }
  }

  cout << *min_element(dp[(1<<r)-1], dp[(1<<r)]) << endl;

  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int n;
	cin>>n;
	ll a[n+3];
	for(int i=0;i<n;i++)
	cin>>a[i];
	ll ans=a[0];
	 for (int i=1; i<n; i++)
	 {
       ll p=__gcd(ans,a[i]);
       ans=(ans/p*a[i]);
	 }
     cout<<ans<<endl;
	return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> vec (2*N);
	for(int i = 0;i < 2*N;i++){
		cin >> vec.at(i);
	}
	sort(vec.begin(),vec.end());
	int awnser = 0;
	for(int i = 0;i < N;i++){
		awnser += min(vec.at(2*i),vec.at(2*i+1));
	}
	cout << awnser << endl;
}

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

typedef long long ll;

int main() {
	ios::sync_with_stdio(0);
	
	ll n, k;
	cin >> n >> k;
	ll ans = 0;
	if (k == 0) {cout << n*n; return 0;}
	for (ll i = k+1; i <= n; i++) {
		ll tmp = n;
		ans += (i - k)*(tmp/i);
		tmp -= n/i*i;
		if (tmp >= k) {ans += tmp - k + 1;}
	}
	cout << ans;
	
	return 0;
}

Measured memory_bytes: 256
N, P = map(int, input().split())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    # arr.append([n, 1])

    return arr

l = factorization(P)[::-1]

# print(l)

ans = 1
for n, k in l:
    if k >= N:
        ans *= n ** (k // N)

print(ans)


Measured memory_bytes: 3188
import java.util.*;
import java.lang.*;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		String s = sc.next();
		if (a >= 3200) {
			System.out.println(s);
		} else {
			System.out.println("red");
		}
	}
}


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

using namespace std;

#define sz(x) (int)(x.size())
#define fi(a, b) for(int i=a;i<b;++i)
#define fj(a, b) for(int j=a;j<b;++j)
#define fk(a, b) for(int k=a;k<b;++k)
#define pb push_back
#define mp make_pair
typedef long long ll;
/////////////

int const N = 3e5 + 41;

int n, m, cntLeft[N];
vector<pair<int, int> > p;



int l, r, maxi;
vector<int> t[N * 4];

int getLeft(int x){
	int l = -1;
	int r = n;
	while(r-l>1){
		int m = (l+r)/2;
		if(p[m].first >= x){
			r = m;
		}else{
			l = m;
		}
	}
	return r;
}

int getRight(int x){
	int l = -1;
	int r = n;
	while(r-l>1){
		int m = (l+r)/2;
		if(p[m].first <= x){
			l = m;
		}else{
			r = m;
		}
	}
	return l;
}

void merge(vector<int> &ver, vector<int> &l, vector<int> &r){
	int lp = 0, rp = 0;
	while(lp < sz(l) || rp<sz(r)){
		if(lp < sz(l) && (rp == sz(r) || l[lp] < r[rp])){
			ver.pb(l[lp++]);
		}else{
			ver.pb(r[rp++]);
		}
	}
}

void build(int v, int tl, int tr){
	if(tl == tr){
		t[v].pb(p[tl].second);
	}else{
		int tm = (tl+tr)/2;
		build(v*2+1, tl, tm);
		build(v*2+2, tm+1, tr);
		merge(t[v], t[v*2+1], t[v*2+2]);
	}
}

int query(vector<int> &ver){
	int l = -1;
	int r = sz(ver);
	while(r-l>1){
		int m = (l+r)/2;
		if(ver[m] <= maxi){
			l = m;
		}else{
			r = m;
		}
	}
	return sz(ver) - 1 - l;
}

int getSum(int v, int tl, int tr){
	if(tl > r || tr < l){
		return 0;
	}
	if(l <= tl && tr <= r){
		return query(t[v]);
	}
	int tm = (tl+tr)/2;
	return getSum(v*2+1, tl, tm) + getSum(v*2+2, tm+1, tr);
}

int getSum(int from, int to){
	::l = getLeft(from);
	::r = getRight(to);
	return getSum(0, 0, n-1);
}

void solve(){
	sort(p.begin(), p.end());
	fi(0, sz(p)){
		++cntLeft[p[i].first];
	}
	build(0, 0, n-1);
	fi(1, m+1){
		int ans = 0;
		for(int j=0;j<=m;j+=i){
			ans += cntLeft[j];
			int l = j+1;
			int r = j + i - 1;
			maxi = r;
			ans += getSum(l, r);
		}
		printf("%d\n",ans);
	}
}

void read(){
	scanf("%d %d",&n,&m);
	fi(0, n){
		int f, s;
		scanf("%d %d",&f,&s);
		p.pb(mp(f, s));
	}
}

void prepare(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
}

int main(){
	prepare();
	read();
	solve();



	return 0;
}

Measured memory_bytes: 79084
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <utility>

using namespace std;

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

    pair<pair<string, int>, int> res[n];

    string s;
    int p;

    for (int i = 0; i < n; i++)
    {
        cin >> s >> p;
        res[i] = make_pair(make_pair(s, -p), i);
    }
    
    sort(res, res+n);

    for (int i = 0; i < n; i++)
    {
        cout << res[i].second + 1 << endl;
        //cout << res[i].first.second << endl;
    }
    
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		long H = sc.nextLong();
		int N = sc.nextInt();
		long A = 0;
		String ans = "No";
		for(int i = 0;i < N;i++){
			A += sc.nextLong();
		}
		if(A >= H){
			ans = "Yes";
		}
		System.out.println(ans);
	}
}

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

typedef long long ll; 
#define inf 1000*1000*1000+9
#define infl (ll)inf*inf
#define sz(x) ((int) x.size())
#define all(a) a.begin(),a.end()
const int mod=1e9+7; 


struct S
{
	int w,v; 
};

#define vi vector<int>
void pre(){
	int n,t; cin>>n>>t; 
	vector<S> items(n); 
	for(int i=0;i<n;i++){
		cin>>items[i].w>>items[i].v; 
	}
	vector<vector<int>> dp(n,vector<int>(t)); 
	for(int i=0;i<n;i++){
		for(int j=0;j<t;j++){
			dp[i][j]=max((i>=1?dp[i-1][j]:0),((j>=items[i].w)?((i>=1)?dp[i-1][j-items[i].w]:0)+items[i].v:0)); 
		}	
	}
	int ans=0; 
	for(int s=0;s<t;s++){
		vi taken(n); 	
		int extra=0;
		int i=n-1,j=s; 
		while(i>0 && j>0){
			if(dp[i][j]==dp[i-1][j]){
				extra=max(extra,items[i].v); 
				i--; 
			}
			else {
				taken[i]=1; 	
				j-=items[i].w; 
				i--; 
			}
		}
		if(j==0) extra=max(extra,items[0].v); 
		ans=max(ans,dp[n-1][s]+extra);
	}
	cout<<ans<<endl; 
}

int main(){
	cout<<fixed<<setprecision(10); 
	pre(); 
}

Measured memory_bytes: 35584
using System;

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var nums = new int[N];
            for (int i = 0; i < nums.Length; i++)
            {
                nums[i] = int.Parse(Console.ReadLine());
            }

            var result = 0;
            for (int i = 0; i < nums.Length; i++)
            {
                if (IsPrimeNum(nums[i])) result++;
            }

            Console.WriteLine(result);
        }

        private static bool IsPrimeNum(int p)
        {
            if (p == 2) return true;
            if ((p < 2) || ((p & 0x01) == 0)) return false;
            var num = Math.Sqrt(p);
            var i = 3;
            while(i<=num)
            {
                if ((p % i) == 0) return false;
                i = i + 2;
            }
            return true;
        }
    }
}

Measured memory_bytes: 5820
ans n m
  | m < 2 * n = div m 2
  | m == 2 * n = n
  | m > 2 * n = n + (div (m - 2 * n) 4)

main = do line <- getLine
          let [n',m'] = words line
              n = (read :: String -> Int) n'
              m = (read :: String -> Int) m' in
            putStrLn . show $ ans n m


Measured memory_bytes: 508
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define mod 1000000007
#define MAX 1000000000000000
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(i=(ll)a;i<(ll)b;i++)
#define revrep(i,a,b) for(i=(ll)a;i>=(ll)b;i--)
#define ii pair<ll,ll>
#define MP make_pair
#define pb push_back
#define f first
#define se second
#define ll long long int
#define vi vector<ll>
ll modexp(ll a,ll b){ ll res = 1; while(b > 0){  if(b & 1) res = (res * a)%mod;  a = (a * a)%mod;  b/=2;  }  return res; }
#define rs resize
typedef tree< ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update > OST;
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define trace(...)
#endif

const ll N = 2e5 + 4;
ll i,n,a;
multiset<ll> s;
int main()
{
    std::ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin>>n;
    rep(i,1,n + 1){
        cin>>a;
        if(i == 1) s.insert(a);
        else{
            auto it = s.lower_bound(a);
            if(it != s.begin()){
                it--;
                s.erase(it);
            }
            s.insert(a);
        }
    }
    cout<<s.size();
    return 0;
}

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

#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#define endl        '\n'
#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        1000000007
#define peak        9123372036854775807
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

namespace InOp{
template<class x,class y>
istream &operator>>(istream &in,pair<x,y> &p) 
{ 
    in>>p.F>>p.S;
    return in;
}
template<class x>
istream &operator>>(istream &in,vector<x> &v) 
{
    for(auto& i:v)
        in>>i;
    return in;
}
template<class x,class y>
ostream &operator<<(ostream &out,pair<x,y> &p) 
{ 
    out<<"("<<p.F<<","<<p.S<<") ";
    return out; 
}
template<class x>
ostream &operator<<(ostream &out,vector<x> &v) 
{ 
    out<<v.size()<<endl;
    for(auto i:v)
        out<<i<<" ";
    out<<endl;
    return out; 
}
}
using namespace InOp;

namespace ModOp{
template<class x,class y,class z> z add(x a,y b,z m){return (a+b)%m;}
template<class x,class y,class z> z sub(x a,y b,z m){return (a-b+m)%m;}
template<class x,class y,class z> z mul(x a,y b,z m){return ((ll)a*b)%m;}
template<class y,class z> z expo(ll b,y e,z m){ll a=1;b%=m;while(e!=0){if((e&1)==1){a=a*b;a=a%m;}b=b*b;b%=m;e>>=1;}return a%m;}
template<class x,class z> z inv(x b,z m){return expo(b,m-2,m);}
template<class x,class y> x invGeneral(x a,y b){if(a==0)return b==1?0:-1;x m=invGeneral(b%a,a);return m==-1?-1:((1-(ll)b*m)/a+b)%b;}
template<class x,class y,class z> z div(x a,y b,z m){ll c=inv(b,m);return mul(a,c,m);}
}
using namespace ModOp;

namespace Debug{
template<class x> void deb(x a){cerr<<"a"<<": "<<a<<endl;}
template<class x,class y> void deb(x a,y b){cerr<<"a"<<": "<<a<<" | "<<"b"<<": "<<b<<endl;}
template<class x,class y,class z> void deb(x a,y b,z c){cerr<<"a"<<": "<<a<<" | "<<"b"<<": "<<b<<" | "<<"c"<<": "<<c<<endl;}
template<class x,class y,class z,class xy> void deb(x a,y b,z c,xy d){cerr<<"a"<<": "<<a<<" | "<<"b"<<": "<<b<<" | "<<"c"<<": "<<c<<" | "<<"d"<<": "<<d<<endl;}
}
using namespace Debug;

#define N  1000005

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll tt=1;
    // cin>>tt;
    while(tt--)
    {
        ll i,j,k,l,r,x,y,m,n;
        cin>>n;
        vi v(n,0);
        ll ans=0;
        for(i=0;i<n;i++)
        {
            cin>>x>>y;
            if(x==y)v[i]=1;
        }
        for(i=0;i<n-2;i++)
        {
            if(v[i]==1&&v[i+1]==1&&v[i+2]==1)ans=1;
        }
        if(ans)cout<<"Yes\n";
        else cout<<"No\n";
    }
    return 0;
}

Measured memory_bytes: 3616
from itertools import product
from collections import Counter
from functools import reduce
import operator
num_product = lambda it: reduce(operator.mul,it,1)

# 素因数分解
def prime_factors(n):
  i = 2
  while i * i <= n:
    if n % i:
      i += 1
    else:
      n //= i
      yield i
  if n > 1:
    yield n



N,M = map(int,input().split())
P = tuple(tuple(p**i for i in range(d+1)) for p,d in Counter(prime_factors(M)).items())
def it():
  for nums in product(*P):
    t = num_product(nums)
    yield t
print(max(t for t in it() if t*N <= M))

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

int N, T, L, B;
int label[101];
double dp[101][100]; //dp[x][t] := x????±?????????????t???????????\????????´??????????????????????¢????

double solve(int x, int t){
  if(x == N)return dp[x][t]=1;
  if(dp[x][t] != -1.0)return dp[x][t];
  if(t == 0)return dp[x][t]=0;

  if(label[x] == 1)return dp[x][t] = solve(0, t);
  if(label[x] == -1){
    if(t==1)return dp[x][t] = 0;
    double ret = 0.0;
    for(int i=1; i<=6; i++){
      if(N < x+i)ret += solve(2*N-x-i, t-2)/6.0;
      else ret += solve(x+i, t-2)/6.0;
    }
    return dp[x][t]=ret;
  }

  double ret=0.0;
  for(int i=1; i<=6; i++){
    if(N < x+i)ret += solve(2*N-x-i, t-1)/6.0;
    else ret += solve(x+i, t-1)/6.0;
  }
  return dp[x][t] = ret;
}

int main(){
  while(cin >> N >> T >> L >> B, !(N==0 && T==0 && L==0 && B==0)){
    for(int i=0; i<101; i++)
      for(int j=0; j<100; j++)
	dp[i][j]=-1.0;
    memset(label, 0, sizeof(label));
    while(L--){
      int tmp;
      cin >> tmp;
      label[tmp] = -1; //Lose?????????
    }
    while(B--){
      int tmp;
      cin >> tmp;
      label[tmp] = 1; //Back?????????
    }

    printf("%.10f\n", solve(0, T));
  }
  return 0;
}

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

using namespace std;

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


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

    int N, M, L;
    cin >> N >> M >> L;
    vector<vector<ll>> d1(N, vector<ll>(N, LONG_LONG_MAX));
    for (int i =0;i <N;i++) {
        d1[i][i] = 0;
    }
    for (int i = 0; i < M; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        d1[a-1][b-1] = d1[b-1][a-1] = c;
    }

    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (d1[i][k] < LONG_LONG_MAX && d1[k][j] < LONG_LONG_MAX) {
                    d1[i][j] = min(d1[i][j], d1[i][k]+d1[k][j]);
                }
            }
        }
    }

    vector<vector<int>> d2(N, vector<int>(N, INT_MAX));
    for (int i =0;i <N;i++) {
        d2[i][i] = 0;
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i != j && d1[i][j] <= L) {
                d2[i][j] = 1;
            }
        }
    }
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (d2[i][k] < INT_MAX && d2[k][j] < INT_MAX) {
                    d2[i][j] = min(d2[i][j], d2[i][k]+d2[k][j]);
                }
            }
        }
    }

    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        int s, t;
        cin >> s >> t;
        if (d2[s-1][t-1] < INT_MAX) {
            cout << d2[s-1][t-1] - 1 << endl;
        } else {
            cout << -1 << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 1664
use std::cmp;

const INF: i64 = 1e17 as i64;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { reader: s.lock() };
    let n: usize = sc.read();
    let a: Vec<i64> = sc.read_vec(n);
    let mut graph = vec![vec![]; n];
    for _ in 0..(n - 1) {
        let v = sc.read::<usize>() - 1;
        let u = sc.read::<usize>() - 1;
        graph[v].push(u);
        graph[u].push(v);
    }

    let mut dp1 = vec![vec![]; n];
    let mut dp2 = vec![vec![]; n];
    dfs(0, 0, &graph, &a, &mut dp1, &mut dp2);

    for i in 1..(n + 1) {
        if dp1[0][i] < INF {
            println!("{}", i - 1);
            return;
        }
        if dp2[0][i] < 0 {
            println!("{}", i - 1);
            return;
        }
    }
}

fn dfs(
    v: usize,
    p: usize,
    graph: &Vec<Vec<usize>>,
    a: &Vec<i64>,
    dp1: &mut Vec<Vec<i64>>,
    dp2: &mut Vec<Vec<i64>>,
) {
    dp1[v].push(INF);
    dp1[v].push(if a[v] > 0 { a[v] } else { INF });
    dp2[v].push(INF);
    dp2[v].push(a[v]);
    for &next in graph[v].iter() {
        if next == p { continue; }
        dfs(next, v, graph, a, dp1, dp2);

        dp1[v] = connect(&dp1[v], &dp1[next], &dp2[next], true);
        dp2[v] = connect(&dp2[v], &dp1[next], &dp2[next], false);
    }
}

fn connect(dp: &Vec<i64>, child1: &Vec<i64>, child2: &Vec<i64>, power_only: bool) -> Vec<i64> {
    assert_eq!(child1.len(), child2.len());
    let mut ans = vec![INF; dp.len() + child1.len() - 1];
    for groups in 0..dp.len() {
        if dp[groups] == INF { continue; }
        for child_groups in 0..child1.len() {
            let child_power = child1[child_groups];
            let child_group = child2[child_groups];

            let total_groups = groups + child_groups;

            if total_groups >= 1 {
                if child_power != INF {
                    ch_min(&mut ans[total_groups - 1], dp[groups] + child_power);
                }
                if child_group != INF && !power_only {
                    ch_min(&mut ans[total_groups - 1], dp[groups] + child_group);
                }
            }
            if child_power != INF || child_group < 0 {
                ch_min(&mut ans[total_groups], dp[groups]);
            }
        }
    }
    ans
}

fn ch_min<T: PartialOrd>(a: &mut T, b: T) {
    if *a > b {
        *a = b;
    }
}

pub struct Scanner<R> {
    reader: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 211836
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    h, w, k = list(map(int, input().strip().split()))
    c = [0] * h
    for i in range(h):
        c[i] = input().strip()
    ans = 0
    for p in range(2**h):
        for q in range(2**w):
            count = 0
            for i in range(h):
                for j in range(w):
                    if not (p >> i)&1 and not (q >> j)&1 and c[i][j] == '#':
                        count += 1
            # print("p:{:b}, q:{:b}, {}".format(p, q, count))
            if count == k:
                ans += 1
    print(ans)

if __name__ == '__main__':
    main()


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,a,b;cin>>n;
  bool is_possible=true;
  map<ll,ll> m;
  rep(i,n) {
    cin>>a>>b;m[b]+=a;
    if(a>b) is_possible=false;
  }
  if(is_possible) {
    ll sum=0;
    for(auto itr=m.begin();itr!=m.end();++itr) {
      if(itr->first<itr->second) is_possible=false;
      else {
        sum+=itr->second;
        if(itr->first<sum) is_possible=false;
      }
    }
  }
  print(is_possible?"Yes":"No");
  return 0;
}


Measured memory_bytes: 12800
/*
 * a.cc:
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
#include<iomanip>

using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main(){
  int a,b,c;
  cin>>a>>b>>c;

  int x,y,z;

  x=10*a+b+c;
  y=10*b+a+c;
  z=10*c+a+b;

  cout<<max(max(x,y),z)<<endl;

}


Measured memory_bytes: 3636
#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cassert>
#include<random>
#include<fstream>
#include<chrono>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define ld           long double
#define pii          pair<int,int>
#define vi           vector<int>
#define pb           push_back
#define mp           make_pair
#define ff           first
#define ss           second
#define endl         '\n'
#define rep(i,s,e)   for(int i=(s);i<=(e);i++)
#define brep(i,s,e)  for(int i=(s);i>=(e);i--)
#define all(x)       (x).begin(),(x).end()
#define ball(x)      (x).rbegin(),(x).rend()
#define sz(x)        (int)x.size()
#define mem(x,y)     memset(x,y,sizeof(x))
#define VR46         ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);ifstream fin("ip.txt");ofstream fout("op.txt");
#define milf(x)      x.reserve(1LL<<14LL); x.max_load_factor(0.25); // less_equal
#define pbds         tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
mt19937              rng(chrono::steady_clock::now().time_since_epoch().count());
#define int          long long
const int INF = 0x3F3F3F3F3F3F3F3F;
const int MOD = 1e9+7;
ld EPS = 1e-12;

const int N = 1e3 + 5;
int H, W, dp[N][N];
string s[N];

int REC(int i, int j)
{
    if( i>=H || j>=W || s[i][j]=='#' )
        return 0;
    if( i==H-1 && j==W-1 )
        return 1;
    if( dp[i][j]!=-1 )
        return dp[i][j];
    int ans = 0;
    ans = REC( i+1, j ), ans %= MOD;
    ans += REC( i, j+1 ), ans %= MOD;
    dp[i][j] = ans;
    return ans;
}

signed main()
{
    VR46 // DONT USE DEQUE IF NOT NECESSARY
    // int t;cin>>t;rep(test,1,t)
    {
        cin >> H >> W;
        rep(i,0,H-1)    
            cin >> s[i];
        mem( dp, -1 );
        cout << REC( 0, 0 ) << endl;
    }
}

Measured memory_bytes: 9344
#include <iostream>
#include <vector>

using namespace std;
vector<int> parents;

int root(int k)
{
    while (parents[k] != k) {
        k = parents[k];
    }
    return k;
}

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

    for (int i = 0; i < n; i++) {
        parents.push_back(i);
    }

    for (int j = 0; j < q; j++) {
        int c, x, y;
        cin >> c >> x >> y;

        if (c) {
            if (root(x) == root(y))
                cout << 1 << endl;
            else
                cout << 0 << endl;
        } else {
            int rx = root(x);
            int ry = root(y);
            if (rx != ry) {
                parents[rx] = ry;
            }
        }
    }
}

Measured memory_bytes: 3256
#![allow(unused_imports)]
#![allow(unused_variables)]

use itertools::Itertools;
use proconio::{fastout, input};
use std::collections::HashMap;

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [u64; n],
        q: usize,
        bc: [(u64, u64); q],
    }
    // annotate for rust-analyzer
    let n: usize = n;
    let a: Vec<u64> = a;
    let q: usize = q;
    let bc: Vec<(u64, u64)> = bc;

    let mut map = HashMap::new();
    let mut sum = 0i64;
    for i in 0..n {
        *map.entry(a[i]).or_insert(0) += 1;
        sum += a[i] as i64;
    }

    let mut anss = Vec::new();
    for (b, c) in bc {
        if map.contains_key(&b) {
            sum += map[&b] * (c as i64 - b as i64);
            *map.entry(c).or_insert(0) += map[&b];
            *map.get_mut(&b).unwrap() = 0;
        }
        anss.push(sum);
    }

    for ans in anss {
        println!("{}", ans);
    }
}


Measured memory_bytes: 9640