akhauriyash/Code-Regression huggingface dataset:
open Scanf ;;
open Printf ;;

let read_int () = scanf " %d" (fun x -> x) ;;

let rec powi a b = if b = 0 then 1 else a * powi a (b - 1);;

let list_sum a = List.fold_left (+) 0 a ;;

let rec read_ints n = if n = 0 then [] else read_int() :: read_ints (n - 1) ;;

let () =
  let n = read_int () in
  let k = read_int () in
  let a = read_ints n |> List.sort compare in
  let f = read_ints n |> List.sort compare |> List.rev in
  let rec search l r =
    if r - l = 1 then r
    else begin
      let m = (l + r) / 2 in
      let v = List.map2 (fun x y -> max 0 (x - m / y)) a f |> list_sum in
      if v <= k
        then search l m
        else search m r
    end
  in
  let ans = search (-1) (powi 10 12) in
  printf "%d\n" ans
  ;;



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

int main() {
    /* Input */
    int N;
    cin >> N;
    
    vector<long long int> A(N);
    rep (i, N) {
        cin >> A.at(i);
    }

    /* Main Logic */      
    long long int steps_sum = 0;
    long long int front_height = 0;

    rep (i, N) {
        if (front_height > A.at(i)) steps_sum += front_height - A.at(i);
        else front_height = A.at(i);
    }

    /* Output */
    cout << steps_sum << endl;
    return 0;
}

Measured memory_bytes: 4796
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <string.h>
#include <iomanip>
#include <limits>
typedef long long ll;
using namespace std;
const int INF=1e9, MOD=1e9+7;
const int MAX_N=10000;
int n,k,c[100];

int main(){
	cin >> n >> k;
	for(int i=0;i<n;i++) cin >> c[i];
	int s=0;
	for(int i=0;i<n;i++) s+=(c[i]>=abs(k-c[i])?abs(k-c[i])*2:c[i]*2);
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 using namespace std;
 int main() 
{
  ios_base::sync_with_stdio(0);
   cin.tie(NULL);
   
   int n,d;
   cin>>n>>d;
   int arr[n][d];
   for(int i=0;i<n;i++)
     {  
         for(int j=0;j<d;j++)
          {
              
              cin>>arr[i][j];
          }
     }
     
     int sum=0;
     for(int k=0;k<n;k++)
     { 
     for(int i=k+1;i<n;i++)
      { int dd=0;    
          for(int j=0;j<d;j++)
           {
             dd+=pow(arr[k][j]-arr[i][j],2);        
          }
          int r=dd;
          int p=sqrt(dd);
          if(p*p==dd)
          sum++;
      }
     }
     cout<<sum<<"\n";
   return 0;
}
 
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define endl '\n'
ll x[600001];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;cin>>s;
    int cnt=0;
    for (int i=(int)s.size()-1;i>=0;i--){
        if (s[i]=='>') cnt++;
        else cnt=0;
        x[i]=cnt;

    }
    ll last=max(0ll,x[0]);
    ll sum=last;

    x[(int)s.size()]=0ll;
    for (int i=0;i<s.size();i++){
        if (s[i]=='<'){
            last=max(last+1,x[i+1]);
           // cout<<"OK";
        } else {
            last=min(last-1,x[i+1]);
        }
        sum+=last;
    }
    cout<<sum;
    return 0;
}



Measured memory_bytes: 5020
import numpy as np

N = int(input())
v = list(map(int, input().split()))
v_sort = np.array(np.sort(v))
x = np.zeros(N)
x[0] = 2**(N-1)
for i in list(range(1,N)):
    x[i] = 2**(N-i)
y = v_sort/x
print(sum(y))

Measured memory_bytes: 14536
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
const long long INF=1e9+5;
const string alp="abcdefghijklmnopqrstuvwxyg"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYG";
typedef long long ll;

int main() {
  vector<ll> a(3);
  cin>>a[0]>>a[1]>>a[2];
  sort(a.begin(),a.end());
  if(a[0]==5&&a[1]==5&&a[2]==7){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 3492
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200003;
const ll INF=1LL<<62;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    set<int> SE;
    for(int i=0;i<3;i++){
        int a;cin>>a;
        SE.insert(a);
    }
    if(SE.size()==2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}



Measured memory_bytes: 256
#include <stdio.h>

int main()
{   int k,s,ans=0;
    scanf("%d%d",&k,&s);
    for(int x=0;x<=k;x++){
        for(int y=0;y<=k;y++){
            int z=s-(x+y);
            if(z<=k&&z>=0)ans++;
        }
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 128
N, M = map(int, input().split())

# 奇数のときは最後の数だけを最初に飛ばした形で先頭、末尾から作っていけばok
if N % 2 == 1:
    for i in range(1, M+1):
        print(i, N-i)
# 偶数のときは奇数と同じように作ると対戦距離がNの半分になるものがあるので一周したときに重複する
# 対戦距離がNの半分になるものが出ないように、対戦距離が半分になった時点で1つずらす
# 対戦距離 = b - a
else:
    for i in range(1, M+1):
        if N-2*i <= N//2:
            print(i, N-i-1)
        else:
            print(i, N-i)

Measured memory_bytes: 69572
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<set>

using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
typedef pair<ll, ll> pll;
int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };

#define ARRAY_MAX 100005

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;



//約数の列挙
vector<ll> divisor(ll n) {
	vector<ll> res;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			res.push_back(i);
			if (i != n / i) {
				res.push_back(n / i);
			}
		}
	}
	return res;
}

int main() {


	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string s, t;
	cin >> s >> t;

	int s_len = s.size();
	int t_len = t.size();

	for (int i = 0; i <= s_len - t_len; i++)
	{
		bool exist = true;
		for (int j = i; j < i + t_len; j++)
		{
			if (t[j - i] == '_')
			{
				continue;
			}

			if (t[j - i] != s[j])
			{
				exist = false;
				break;
			}
		}
		if (exist)
		{
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;


	return 0;
}


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

int main() {

	string s; int q; cin >> s >> q;
	bool def = true;
	string front = "";
	string rear = "";
	for (int i = 0; i < q; i++) {
		int t; cin >> t;
		if (t == 1) {
			if (def) def = false;
			else def = true;
		}
		else { // t == 2
			int f; char c; cin >> f >> c;
			if (!def) {
				if (f == 1) f = 2;
				else f = 1;
			}
			if (f == 1) {
				front += c;
			}
			else {
				rear += c;
			}
		}
	}
	string ans;
	reverse(front.begin(), front.end());
	ans = front;
	ans += s;
	ans += rear;
	if (!def) reverse(ans.begin(), ans.end());
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4240
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
  int a, b, c, k;
  cin >> a >> b >> c >> k;
  
  if (a >= k)
    cout << k;
    
  else if (a + b >=k)
    cout << a;
  
  else
    cout << a - (k - a - b);
    
	return 0;
}

Measured memory_bytes: 3584
from math import ceil

N,A,B=map(int,input().split())
h=[int(input()) for _ in range(N)]

def f(k):
    return sum([ceil((hi-B*k)/(A-B)) for hi in h if hi-k*B>0])<=k

l,r=0,ceil(max(h)/B)

while r-l>1:
    if f((l+r)//2):
        r=(l+r)//2
    else:
        l=(l+r)//2

print(r)

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

int main(){
  
  string S,T;
  cin >> S >> T ;
  
  int A,B;
  cin >> A >> B;
  
  string U;
  cin >> U;
  
  if(S==U){
    cout << A-1 << " " << B << endl;
  }
  else if(T==U){
    cout << A << " " <<B-1 <<endl;  
  }
 
}

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

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

  ll ans = 0;
  rep(X,1,N) {
    ll Y = N / X;
    ans += (Y + 1) * Y * X / 2;
  }

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


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
const int MAX_V = 1000000000;

int main(){
    int n; cin >> n;
    vector<int> x(n);
    vector<int> l(n);
    pair<int,int> ps[n];
    for(int i=0;i<n;++i) cin >> x[i] >> l[i];
    for(int i=0;i<n;++i) ps[i] = make_pair(x[i] + l[i],x[i] - l[i]);
    sort(ps,ps+n);
    int res = 0;
    int cur = -MAX_V;
    for(int i=0;i<n;++i){
        if(cur <= ps[i].second){
            res++;
            cur = ps[i].first;
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(void){
	int A;
	int B;
	int i;
	int sum = 0;
 
	scanf("%d", &A);
	scanf("%d", &B);
 
	for (i = 0; i < 2; i++){
     if(A >= B){
        sum += A;
        A--;
      }
      else{
        sum += B;
        B--;
      }
    }
 
	printf("%d\n", sum);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
string N;long K,dp[111][2][4],i,j,k,l,r,c,M;
int main(){
	cin>>N>>K;
	M=N.size();
	dp[0][0][0]=1;
	for(i=0;i<M;i++){
		for(j=0;j<2;j++){
			r=j?9:N[i]-'0';
			for(k=0;k<=K;k++){
				for(l=0;l<=r;l++){
					c=k+!!l;
					if(c<=K)dp[i+1][j||l<r][c]+=dp[i][j][k];
				}
			}
		}
	}
	cout<<dp[M][0][K]+dp[M][1][K]<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main(){
    int a, b, t;
    cin >> a >> b >> t;
    int s = a;
    int q = 0;
    while(s <= t){
        s+=a;
        q += b;
    }
    cout << q;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n,a,b,c,x;
  while(cin>>n>>a>>b>>c>>x,n||a||b||c||x){
    int co=0;
    while(n--){
      int m;cin>>m;
      while(x!=m){
	x=(a*x+b)%c;
	co++;
	if(co>10001)break;
      }
      if(co>10001)break;
      x=(a*x+b)%c;
      co++;
    }
    if(co<=10001)co--;
    while(n-->0)cin>>a;
    if(co>10000)cout<<-1<<endl;
    else cout<<co<<endl;
  }
}

Measured memory_bytes: 1164
A = [[0 for i in range(10)] for j in range(10)]
N = int(input())

result = 0
for i in range(1, N+1):
    s = str(i)
    f = int(s[0])
    l = int(s[-1])
    A[f][l] += 1
    # print('i:{} f:{}, l:{}'.format(i, f, l))

# print(A)

result = 0
for i in range(1, 10):
    for j in range(1, 10):
        result += A[i][j] * A[j][i]
        # print('debug i:{}, j:{}'.format(i, j))
        # print(result)

print(result)


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

#define FOR(i,s,t) for(int i = s; i < t; i++)
using LL = long long; using VL = vector<LL>;
const int INF = 1e9;

const int MAX_N = 100005;

int dp[MAX_N];
int n;
vector<int> a;

void solve() {
	fill(dp, dp + n, INF);
	for (int i = 0; i<n; ++i) {
		*lower_bound(dp, dp + n, a[i]) = a[i];
	}
	cout << lower_bound(dp, dp + n, INF) - dp << endl;
}

int main() {
	cin >> n;
	a.resize(n);
	for (int i = 0; i<n; ++i) cin >> a[i];
	solve();
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
const int INF = 100010;

int dp[100010];

int main(){
    int n;
    cin >> n;
    for(int i = 0; i <= n; i++) dp[i] = INF;
    dp[0] = 0;
    vector<int> coin;
    coin.push_back(1);
    for(int i = 6; i <= n; i *= 6) coin.push_back(i);
    for(int i = 9; i <= n; i *= 9) coin.push_back(i);
    for(int i = 0; i < coin.size(); i++){
        for(int j = 0; j <= n - coin[i]; j++){
            dp[j + coin[i]] = min(dp[j + coin[i]], dp[j] + 1);
        }
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 640
date = input()
year = date[:4]
month = date[5:7]
if int(year) < 2019:
        print("Heisei")
elif int(year)==2019:
    if month == "04":
        print("Heisei")
    elif month == "03":
        print("Heisei")
    elif month == "02":
        print("Heisei")
    elif month == "01":
        print("Heisei")
    else:
        print("TBD")
else:
        print("TBD")

Measured memory_bytes: 3064
import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args){
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		solve(sc,out);

		out.flush();
	}

	public static void solve(FastScanner sc, PrintWriter out) {
		int x = sc.nextInt();
		int a = sc.nextInt();
		out.println(x < a ? 0 : 10);
	}

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

	public static long lcm(long a, long b) {
		return a / gcd(a, b) * b;
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(K key, V value) {
        super(key, value);
    }

    public Pair<V, K> swap() {
    	return new Pair<V, K>(getValue(), getKey());
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 21332
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    const int MAX_S = 1000 + 10;
    string S1, S2;
    int dp[MAX_S][MAX_S];
    cin >> S1 >> S2;
    int l1 = S1.length();
    int l2 = S2.length();
    for (int i = 0; i <= l1; ++i){
        dp[i][0] = i;
    }
    for (int j = 1; j <= l2; ++j){
        dp[0][j] = j;
    }

    for (int i = 1; i <= l1; ++i){
        for (int j = 1; j <= l2; ++j){
            if (S1[i-1] == S2[j-1]){
                dp[i][j] =  dp[i-1][j-1];
            }else{
                dp[i][j] = min(min(dp[i-1][j] + 1, dp[i][j-1] + 1), dp[i-1][j-1] + 1);
            }
        }
    }

    // cout << "%" << " " << "%" << " ";;
    // for (int j = 0; j < l2; ++j){
    //     cout << S2[j] << " ";
    // }cout << endl;
    // for (int i = 0; i <= l1; ++i){
    //     if (i == 0){
    //         cout << "%" << " ";
    //     }else{
    //         cout << S1[i-1] << " ";
    //     }
    //     for (int j = 0; j <=l2; ++j){
    //         cout << dp[i][j] << " ";
    //     }cout << endl;
    // }
    cout << dp[l1][l2]<< endl;
}


Measured memory_bytes: 7136
#include<iostream>
using namespace std;
int main(){
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    int total=0;
    if(a+b>2*c){
        int pizza=min(x,y);
        x-=pizza;
        y-=pizza;
        total+=pizza*2*c;
    }
    if(x>0)
    {
        if(a>2*c)
        {
            total+=x*2*c;
        }
        else
        {
            total+=x*a;
        }
    }
    if(y>0)
    {
        if(b>2*c)
        {
            total+=y*2*c;
        }
        else
        {
            total+=y*b;
        }
    }
    cout<<total;
}

Measured memory_bytes: 3608
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String s1 = sc.next();
		if(s.compareTo(s1) == 0) {
			System.out.println("=");
		} else if(s.compareTo(s1) > 0) {
			System.out.println(">");
		} else {
			System.out.println("<");
		}
	}
}

Measured memory_bytes: 23252
#include <cstdio>
int main()
{
int a=0, b=0,c=0;
scanf("%d %d %d",&a,&b,&c);
if(a==5 && b==5 && c==7){
	printf("YES\n");}
	else if (a==5 && b==7 && c==5){
		printf("YES\n");}	
	else if (a==7 && b==5 && c==5){
		printf("YES\n");}
	else printf ("NO\n");
return 0;
}

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

typedef long long ll;

ll N,X;
ll A[100010];
ll ans = 0;

int main()
{
    scanf("%lld%lld",&N,&X);
    for(int i = 0; i < N; i++)
    {
        scanf("%lld",&A[i]);
    }
    for(int i = 0; i < N; i++)
    {
        if(i == 0)
        {
            if(A[i] > X)
            {
                ans += A[i] - X;
                A[i] -= A[i] - X;
            }
        }
        else
        {
            if(A[i] + A[i - 1] > X)
            {
                ans += A[i] + A[i - 1] - X;
                A[i] -= A[i] + A[i - 1] - X;
            }
        }
    }
    printf("%lld\n",ans);
}



Measured memory_bytes: 1024
#include <iostream>
#include <string>
using namespace std;
int main(void)
{
    string A;
    cin >> A;
    int t = 0;
    for (int i = 0; i < 3; i++)
    {
        if (A[i] == 'o')
        {
            t++;
        }
    }
    cout << 700 + 100 * t << endl;
    return 0;
}

Measured memory_bytes: 256
#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn main() {
    let n = read::<usize>();

    let x = read_vec::<f64>();
    let y = read_vec::<f64>();

    let mut p1 = 0.0;
    let mut p2 = 0.0;
    let mut p3 = 0.0;
    let mut pinf = 0.0;

    for i in 0..n {
        p1 += (x[i] - y[i]).abs();
        p2 += (x[i] - y[i]).abs().powi(2);
        p3 += (x[i] - y[i]).abs().powi(3);
        pinf = f64::max(pinf, (x[i] - y[i]).abs());
    }

    p2 = p2.powf(0.5);
    p3 = p3.powf(1.0 / 3.0);

    println!("{}", p1);
    println!("{}", p2);
    println!("{}", p3);
    println!("{}", pinf);
}



Measured memory_bytes: 5160
n, k = map(int,input().split())
w = [int(input()) for _ in range(n)]

# 荷物の最大積算量を返す
def check(p):
    global n,k,w
    v = 0
    track = 0
    temp = 0
    i = 0
    while track < k:
        temp = 0
        while temp + w[i] <= p:
            temp += w[i]
            i = i + 1
            if i == n:
                return i
        track += 1
        #print(track,i)
    return i

def main():
    global n,k,w
    left = 0
    right = 100000*10000

    while True:
        mid = int( (left+right) / 2 )
        #print(left,right,mid)
        v = check(mid)
        judge = check(mid-1)
        #print(n,v,judge)
        if v < n:
            left = mid + 1
        elif v == n and judge != n:
            return mid
        elif v == n and judge == n:
            right = mid

print(main())



Measured memory_bytes: 9576
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <tuple>
#define FOR0(var, max) for (ui (var) = 0; (var) < (max); ++(var))
#define FOR_INV(var, min, max) for (ui (var) = (max) - 1; (var) + 1 > (min); --(var))
#define FORITER(var, iter) for (auto (iter) = (var).begin(); (iter) != (var).end(); (iter)++)
#define FORITER_INV(var, iter) for (auto (iter) = (var).rbegin(); (iter) != (var).rend(); (iter)++)

using namespace std;

using uc = unsigned char;
using ui = unsigned int;
using ul = unsigned long long int;

const static ui NMAX = 18;
const static ui SiMAX = 1<<18;
const static ui SMAX = 1000000000;

static ui N;
static multiset<ui> Si;

bool solve(void) {
  multiset<ui> confirmed;
  multiset<ui> remain = Si;

  auto first = max_element(remain.begin(), remain.end());
  confirmed.insert(*first);
  remain.erase(first);

  FOR0(i, N) {
    multiset<ui> next;

    FORITER_INV(confirmed, it) {
      auto t = remain.lower_bound(*it);
      if (t == remain.begin()) { // nothing possible slime
        return false;
      }
      t = prev(t);
      next.insert(*t);
      remain.erase(t);
    }

    FORITER(next, it) {
      confirmed.insert(*it);
    }
  }

  return confirmed.size() == Si.size();
}

int main(void) {
  cin >> N;
  FOR0(i, (1U << N)) {
    ui t;
    cin >> t;
    Si.insert(t);
  }
  cout << (solve() ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 30976
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)


typedef long long int ll;
typedef double D;      // ??§?¨?????????????double???long double?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;


const int INF = (1<<30) - 1;
const D EPS = 1e-9;

#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

int N, Q;

void query(vector<pair<pair<int, int>, string>> &eras){
    int west_year; cin >> west_year;
    for(auto era: eras){
        if(era.first.first <= west_year && west_year <= era.first.second){
            cout << era.second << " " << west_year - era.first.first + 1 << endl;
            return;
        }
    }
    cout << "Unknown" << endl;
}

void solve(){
    vector<pair<pair<int, int>, string>> eras;
    
    for(int i=0; i<N; i++){
        string name;
        int base, year;
        cin >> name >> base >> year;
        eras.push_back(make_pair(make_pair(year-base+1, year), name));
    }
    
    while(Q--){
        query(eras);
    }
}


//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    while(cin>>N>>Q, N|Q){
        solve();
    }
    return 0;
}

Measured memory_bytes: 1284
/*
  Contest 111
  B - AtCoder Beginner Contest 111
  Rakesh Kumar --> 27/09/2020
 */

#include <bits/stdc++.h>

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

    std::vector<int> table;
    for (int i = 1; i <= 9; ++i)
        table.emplace_back(i * 111);
    int n = 0;
    std::cin >> n;
    if (n % 111 == 0)
        std::cout << n << std::endl;
    else
        std::cout << table[n / 111] << std::endl;

    return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main()
{
    int n,cnt=0;
    long long int d_str,ans,d,x,y;
    scanf("%d %lld",&n,&d);
    while(n--)
    {
        scanf("%lld %lld",&x,&y);
        d_str=d*d;
        ans=x*x+y*y;
        if(ans<=d_str)
            cnt++;
    }
    printf("%d",cnt);
    return 0;
}


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

using namespace std;

int main(){
	int N;
  double sum=0;
  	double x[10];
  	string u;
  	cin>>N;
  	for(int i=0;i<N;++i){
      cin>>x[i]>>u;
	  if(u=="BTC")x[i]=380000*x[i];
      sum+=x[i];
    }cout<<sum<<endl;
  	return 0;
}

Measured memory_bytes: 256
program sample
implicit none
integer(8) N,M,A(10**5),B(10**5),i,count1
integer(16) H(10**5),H2(10**5)
read(*,*) N,M
read(*,*)(H(i),i=1,N)
do i=1,M
read(*,*)A(i),B(i)
end do
do i=1,N
H2(i)=H(i)
end do
do i=1,M
if (H(A(i))<=H(B(i))) then
    H2(A(i))=0
end if
if (H(A(i))>=H(B(i))) then
    H2(B(i))=0
end if
end do
count1=0
do i=1,N
if (H2(i).ne.0) then
count1=count1+1
end if
end do
write(*,*) count1
stop
end program sample

Measured memory_bytes: 7700
from scipy.sparse.csgraph import bellman_ford, NegativeCycleError
from scipy.sparse import csr_matrix
from collections import defaultdict

n, m, p = map(int, input().split())
abc = [list(map(int, input().split())) for _ in range(m)]
INF = 10 ** 9

fwd = [[] for _ in range(n + 1)]
rev = [[] for _ in range(n + 1)]

for a, b, c in abc:
    fwd[a].append(b)
    rev[b].append(a)


def dfs(s, adj):
    stack = [s]
    arrived = [False] * (n + 1)
    arrived[s] = True
    while stack:
        u = stack.pop()
        for v in adj[u]:
            if not arrived[v]:
                arrived[v] = True
                stack.append(v)

    return arrived


can_go_fwd = dfs(1, fwd)
can_go_rev = dfs(n, rev)

data = defaultdict(lambda: INF)
for a, b, c in abc:
    if can_go_fwd[a] and can_go_rev[b]:
        data[(a, b)] = min(data[(a, b)], p - c)

row = []
col = []
cost = []
for (a, b), c in data.items():
    row.append(a)
    col.append(b)
    cost.append(c)

g = csr_matrix((cost, (row, col)), shape=(n + 1, n + 1))

try:
    dist = bellman_ford(g, indices=[1]).astype(int)
    ans = max(0, -dist[0][n])
    print(ans)
except NegativeCycleError:
    print(-1)


Measured memory_bytes: 25040
### subroutines

def rec(k, sum)
  return sum if k >= $n

  max_sum = rec(k + 1, sum)

  sumk = sum + $as[k]
  if sumk <= $cap
    sum0 = rec(k + 1, sumk)
    max_sum = sum0 if max_sum < sum0
  end

  max_sum
end

### main

loop do
  $n = gets.to_i
  break if $n == 0

  $as = gets.split.map(&:to_i)
  #p $as

  sum = $as.inject(:+)
  $cap = sum / 2
  #p $cap

  max_pow = rec(0, 0)
  puts sum - max_pow * 2
end

Measured memory_bytes: 6104
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
typedef long long LL;

int main() {
  int K, X; std::cin >> K >> X;
  if (X <= 500 * K) std::cout << "Yes" << std::endl;
  else              std::cout << "No" << std::endl;
}


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

using namespace std;

int N;
int a[100005];
map<int, int> mp;
vector<int> nums;

int main()
{
  while (scanf("%d", &N) != EOF) {
    mp.clear();
    nums.clear();
    for (int i = 0; i < N; ++i) {
      scanf("%d", &a[i]);
      mp[a[i]]++;
    }
    for (auto it = mp.begin(); it != mp.end(); ++it) {
      if (it->second >= 2) {
        nums.push_back(it->first);
        if (it->second >= 4) nums.push_back(it->first);
      }
    }
    sort(nums.begin(), nums.end());
    reverse(nums.begin(), nums.end());
    long long ans = 0;
    if (nums.size() >= 2) {
      ans = 1LL * nums[0] * nums[1];
    }
    printf("%lld\n", ans);
  }
  return 0;
}


Measured memory_bytes: 5376
ans = []

@di = [-1, -1, -1, 0, 0, 1, 1, 1]
@dj = [-1, 0, 1, -1, 1, -1, 0, 1]

def dfs(i, j)
  @field[i][j] = 0

  8.times do |dir|
    ni = i + @di[dir]
    nj = j + @dj[dir]

    next if ni.negative? || nj.negative?
    next if ni >= @h || nj >= @w
    next if @field[ni][nj].zero?

    dfs(ni, nj)
  end
end

loop do
  @w, @h = gets.split.map(&:to_i)
  break if @w.zero? && @h.zero?

  @field = @h.times.map { gets.split.map(&:to_i) }
  count = 0

  @h.times do |i|
    @w.times do |j|
      next if @field[i][j].zero?

      dfs(i, j)
      count += 1
    end
  end

  ans << count
end

ans.each do |a|
  p a
end



Measured memory_bytes: 11864
#include <iostream>
#include <array>
using namespace std;
const char* solve() {
    array<array<int, 3>, 3> c;
    for (auto& a : c) for (auto& i : a) cin >> i;
    for (int i = 1; i <= 2; i++)
        for (int j = 1; j <= 2; j++)
            if (c[i][j] - c[0][j] != c[i][0] - c[0][0])
                return "No";
    return "Yes";
}
int main() {
    cout << solve() << endl;
}

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



int main(){
	ll n, sum = 0;
	cin >> n;
	vector<ll> a(n);
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	
	ll s = 0, ans = abs(sum-2*a[0]);
	for(int i = 0; i < n-1; i++)
	{
		s += a[i];
		ans = min(ans, abs(sum - 2*s));
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1920
import sys
import numpy as np

sys.setrecursionlimit(10 ** 9)

N = int(input())
A = list(map(int,input().split()))

dp = np.full((N, 3), 0, dtype=int)

dp[0][0] = A[0]
dp[1][1] = A[1]
if N != 2:
    dp[2][2] = A[2]
    dp[2][0] = A[0] + A[2]
for i in range(3,N):
    if i & 1:
        dp[i][1] = max(dp[i-3][0], dp[i-2][1]) + A[i]
    else:
        dp[i][0] = dp[i-2][0] + A[i]
        dp[i][2] = max(dp[i-4][0], dp[i-3][1], dp[i-2][2]) + A[i]

if N & 1:
    ans = max(dp[-3][0], dp[-2][1], dp[-1][2])
else:
    ans = max(dp[-2][0], dp[-1][1])

print(ans)    

Measured memory_bytes: 51172
/*      ex6_2
        Tarara  */
#include <stdio.h>
#include <string.h>

// 入力の最大長
#define MAX_LENGTH 110

int main(void)
{
    char word[MAX_LENGTH]; // 入力される英単語
    int length;            // wordの長さ

    // 入力
    scanf("%s", word);
    length = strlen(word);

    // 出力
    printf("%c%d%c\n", word[0], length - 2, word[length - 1]);
    return 0;
}

Measured memory_bytes: 128
N, M, A, B = gets.split.map(&:to_i)
a, b = A, B

ts = 0
ls = 0

ans = Array.new(N){Array.new(M, '.')}

if N % 2 == 1
    p = 0
    while p < M - 1 && a > 0
        ans[0][p] = '<'
        ans[0][p+1] = '>'
        p += 2
        a -= 1
    end
    ts = 1
end

if M % 2 == 1
    p = 0
    while p < N - 1 && b > 0
        ans[p][M - 1] = '^'
        ans[p+1][M - 1] = 'v'
        p += 2
        b -= 1
    end
end

ls.step(M - 2, 2) do |lp|
    ts.step(N - 2, 2) do |tp|
        next if a == 0 && b == 0

        if lp == M - 3 && tp == N - 2 && a == 1 && b == 1 && ans[N - 1][M - 1] == '.'
            ans[tp][lp] = '^'
            ans[tp+1][lp] = 'v'
            ans[tp+1][lp+1] = '<'
            ans[tp+1][lp+2] = '>'
            a -= 1
            b -= 1
        end

        if a >= 2
            ans[tp][lp] = '<'
            ans[tp][lp+1] = '>'
            ans[tp+1][lp] = '<'
            ans[tp+1][lp+1] = '>'
            a -= 2
        elsif b >= 2
            ans[tp][lp] = '^'
            ans[tp+1][lp] = 'v'
            ans[tp][lp+1] = '^'
            ans[tp+1][lp+1] = 'v'
            b -= 2
        elsif a >= 1
            ans[tp][lp] = '<'
            ans[tp][lp+1] = '>'
            a -= 1
        elsif b >= 1
            ans[tp][lp] = '^'
            ans[tp+1][lp] = 'v'
            b -= 1
        end
    end
end

if a == 0 && b == 0
    puts 'YES'
    ans.each do |line|
        puts line.join
    end
else
    puts 'NO'
end


Measured memory_bytes: 55036
import numpy as np
N=int(input())
A=[int(input()) for i in range(N)]
B=list(np.argsort(np.array(A)))
X=[[0,0],[0,0]]
for i in range(N):
    X[i%2][B[i]%2]+=1
Y=[X[0][1],X[1][0]]
print(min(Y))

Measured memory_bytes: 20588
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

int main(){
    int N,M;
    cin >> N >> M;
    map<int/*問題番号*/,int/*間違い数*/> problems,pre;
    bool flag[N];//正解したかしてないか

    for (int i = 0; i < N; i++){
        flag[i]=false;//正解してたらtrue
        //cout << "!";
    }

    int AC_sum=0,WA_sum=0,tmp_sum=0;

    for (int i = 0; i < M; i++){
        int num;
        string tmp;
        cin >> num >> tmp;
        //cout << '!' << num << ',' << tmp << '?';
        int point=num-1;

        if(flag[point]==false&&tmp=="AC"){
            AC_sum++;
            problems[num]=pre[num];
            flag[point]=true;
            //cout << "OK!";
        }
        else if(tmp=="WA"&&flag[point]==false){
            pre[num]++;
        }

        
    }

    for (int i = 1; i <= N; i++){
        WA_sum+=problems[i];
    }
    cout << AC_sum << ' ' << WA_sum;

    return 0;
}

Measured memory_bytes: 9728
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n; cin >>n;
  vector<int>a(n);
  long long sum=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    sum+=a[i];
  }
  sort(a.rbegin(),a.rend());
  sum-=a[0];
  if(a[0]<sum)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scan(&n, &m)

	//n部屋と通じる通路をグラフで表現
	rooms := make([][]int, n)

	for i := 0; i < m; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		a--
		b--
		rooms[a] = append(rooms[a], b)
		rooms[b] = append(rooms[b], a)
	}

	drl := make([]int, n)
	for i := 1; i < n; i++ {
		drl[i] = -1
	}
	//スタックを用意
	stk := make([]int, 0)
	stk = append(stk, 0)

	for len(stk) > 0 {
		v := stk[0]
		stk = stk[1:]

		for _, i := range rooms[v] {
			if drl[i] != -1 {
				continue
			}
			drl[i] = v + 1
			stk = append(stk, i)
		}
	}

	ok := true
	for i := 1; i < n; i++ {
		if drl[i] < 0 {
			ok = false
		}
	}
	if ok {
		fmt.Println("Yes")
		for i := 1; i < n; i++ {
			fmt.Println(drl[i])
		}
	} else {
		fmt.Println("No")
	}
}

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

int main() {
  int N, D, count;
  cin >> N >> D;
  count = 0;
  
  for (int i = 0; i < N; i++) {
    long x, y;
    double dist;
    cin >> x >> y;
    dist = sqrt(x * x + y * y);
    if (dist <= D) count++;
  }
  cout << count << endl;
}


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

main = do
  nm <- map (read :: String -> Int) . words <$> getLine
  student <- map (map (read :: String -> Int) . words) <$> replicateM (head nm) getLine
  check <- map (map (read :: String -> Int) . words) <$> replicateM (last nm) getLine
  putStrLn . unlines $ map (show . (\x -> (+1) . minIndex $ map (dist x) check)) student
  
dist :: [Int] -> [Int] -> Int
dist (x1:y1:_) (x2:y2:_) = abs (x1 - x2) + abs (y1 - y2)

minIndex :: [Int] -> Int
minIndex xs = head . elemIndices (minimum xs) $ xs

Measured memory_bytes: 1020
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <functional>
#include <unordered_map>
#define int long long 
#define pi pair<int,int> 
#define endl "\n"
using namespace std ;

const int inf = 1e15 ;
const int size = 3005;
const int mod = 1e9 + 7 ;
int dp[2][size][size] , a[size];
int x , n , k ;

int fun( int p , int l , int r )
{
     if( l > r ) return 0 ;

     int &ans = dp[p][l][r] ;
     if(ans !=-1) return ans ;
     if( p == 0 )
     {
        ans = max(a[l]+fun(1,l+1,r),a[r]+fun(1,l,r-1));
     }
     else 
     {
         ans = min(fun(0,l+1,r)-a[l],fun(0,l,r-1)-a[r]);
     }
     return ans ;
}

int32_t main() 
{


     /*#ifndef ONLINE_JUDGE 
     freopen("input.txt","r",stdin);
     freopen("output.txt","w",stdout);
     #endif*/
     memset(dp,-1,sizeof(dp));
     cin >> n ;
     for(int i = 0  ; i < n ; i++ ) cin >> a[i] ;
     cout<<fun(0,0,n-1)<<endl;
    return 0 ;
}


Measured memory_bytes: 141568
import java.util.*;

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

    int n = sc.nextInt();
    long[] count = new long[5];

    for (int i = 0; i < n; i++) {
      String str = String.valueOf(sc.next().charAt(0));

      if (str.equals("M")) {
        count[0]++;
      } else if (str.equals("A")) {
        count[1]++;
      } else if (str.equals("R")) {
        count[2]++;
      } else if (str.equals("C")) {
        count[3]++;
      } else if (str.equals("H")) {
        count[4]++;
      }
    }

    long ans = 0;

    for (int i = 0; i < 3; i++) {
      for (int j = i+1; j < 4; j++) {
        for (int k = j+1; k < 5; k++) {
          ans += count[i] * count[j] * count[k];
        }
      }
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 46404
#include <stdio.h>
#include<stdlib.h>

int h;

int left(int i){
  return 2*i;
}


int right(int i){
  return 2*i+1;
}


void exchange(int *A ,int l,int i){
  int temp;

  temp=A[l];
  A[l]=A[i];
  A[i]=temp;
 

}

void maxHeapify(int *A,int i){
  int l = left(i);
  int  r = right(i);
  int largest;
 
  if (l <= h && A[l] > A[i]){
    largest = l;
  }
  else {
    largest = i;
  }
  if(r <= h && A[r] > A[largest]){
    largest = r;
  }
  if(largest != i){
    exchange(A,largest,i); 
    maxHeapify(A, largest);
    
  }
}

void buildMaxHeap(int *A){
  int i;
  
  for(i=h/2;i>=1;i-- ){
    maxHeapify(A,i);
  }
}

int main(){
  
  int i;
  int *A;


  
  
  scanf("%d",&h);
  A=(int *)malloc((h+1)*sizeof(int));
  for(i=1;i<=h;i++) scanf("%d",&A[i]);

  buildMaxHeap(A);

  for(i=1;i<=h;i++) printf(" %d",A[i]);
  printf("\n");

  return 0;
}




 



Measured memory_bytes: 3672
#!python3

import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())

from collections import deque

def resolve():
    H, W = iim()
    Ch, Cw = iim()
    Dh, Dw = iim()
    W1 = W+4; H1 = H+4

    ok = "."
    X = "X"
    X2 = "XX"
    XX = X2 * W1

    S = XX + "".join(X2 + input() + X2 for i in range(H)) + XX

    pos1 = W1 * (Ch+1) + (Cw+1)
    pos2 = W1 * (Dh+1) + (Dw+1)

    dp = [0] * (H1*W1)
    dp[pos1] = 1

    dq = deque([(1, pos1)])
    step = (-2*W1 -2,) + (1,)*4 + (W1,)*4 + (-1,)*4 + (-W1,)*3 + (1, 2, 2*W1, -2)

    while dq:
        n, p0 = dq.popleft()

        if p0 == pos2:
            print(n-1)
            return


        x1 = 0
        for i in (1, -1, W1, -W1):
            p1 = p0 + i
            if S[p1] != ok:
                continue

            if dp[p1] == 0 or n < dp[p1]:
                dp[p1] = n
                dq.appendleft((n, p1))


        n1 = n + 1
        p1 = p0
        for i in step:
            p1 += i
            if dp[p1] or S[p1] != ok:
                continue
            dp[p1] = n1
            dq.append((n1, p1))

    print(-1)

if __name__ == "__main__":
    resolve()


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define FORD(i,b,a) for (int i = (int)(b) - 1; i >= a; --i)
#define REP(i,N) FOR(i,0,N)
#define st first
#define nd second
#define pb push_back

typedef pair<int, int> PII;
typedef long long LL;

vector<int> adj[222222];
int m[222222];

void go(int v, int p) {
  for (int u: adj[v]) if (u != p) {
    go(u, v);
    if (!m[u] && !m[v]) {
      m[u] = v;
      m[v] = u;
    }
  }
}

int main() {
  int N;
  scanf("%d", &N);
  REP(i,N-1) {
    int a, b;
    scanf("%d%d", &a, &b);
    adj[a].pb(b);
    adj[b].pb(a);
  }
  go(1,-1);
  bool ok = true;
  FOR(i,1,N+1) ok = ok && m[i];
  printf(ok ? "Second\n" : "First\n");
}


Measured memory_bytes: 9088
Q,H,S,D = map(int, input().split())
N = int(input())
if N >=2:
    if N%2 == 0:
        ans = N//2*min([8*Q,4*H,2*S,D])
    else:
        ans = (N-1)//2*min([8*Q,4*H,2*S,D]) + min([4*Q,2*H,S])
else:
    ans = min([4*Q,2*H,S])
print(ans)

Measured memory_bytes: 9148
#include<stdio.h>
#include<math.h>

#define rep(i,n) for(int i = 0; i < n; i++)
#define H_MAX 6
#define W_MAX 6

/*配列（整数型）の表示のための関数*/
void print_array_int(char name[], int nlen, int array[], int alen) {
	printf("%s = [", name);
	rep(i,alen) {
		printf("%d", array[i]);
		if (i == alen - 1) {
			//pass
		}
		else {
			printf(", ");
		}
	}
	printf("]\n");
}

void copy_array_int(int NewArray[], int OriArray[], int len) {
    rep(i, len) {
        NewArray[i] = OriArray[i];
    }
}

int main (void){
    int h = 0, w = 0, k = 0;
    scanf("%d %d %d", &h, &w, &k);
    //printf("h = %d, w = %d, k = %d\n", h, w, k);

    int Bh[H_MAX * W_MAX] = {0};
    int Bw[H_MAX * W_MAX] = {0};
    int blen = 0;
    rep(hi, h){
        char C[H_MAX][W_MAX];   
        scanf("%s", C[hi]);
        rep(wi, w) {
            //printf("%c\n", C[hi][wi]);
            if (C[hi][wi] == '#') {
                Bh[blen] = hi;
                Bw[blen] = wi;
                blen += 1;
            }
            else {
                //void
            }
        }
    }
    
    int Btmp[H_MAX * W_MAX] = {0};
    int ans = 0;
    //print_array_int("Bh", 2, Bh, blen);
    //print_array_int("Bw", 2, Bw, blen);
    
    rep(hbit, (int)pow(2, h)) {
        int B[H_MAX * W_MAX] = {0};
        rep(hi, h) {
            if ((hbit >> hi) & 1 == 1) {     //red
                rep(i, blen) {
                    if (Bh[i] == hi) {
                        B[i] = 1;
                    }
                    else {
                        //void
                    }
                }
            }
            else {
                //void
            }
        }
        copy_array_int(Btmp, B, blen);
        rep(wbit, (int)pow(2, w)) {
            copy_array_int(B, Btmp, blen);
            rep(wi, w) {
                if ((wbit >> wi) & 1 == 1) {
                    rep(i, blen) {
                        if (Bw[i] == wi) {
                            B[i] = 1;
                        }
                        else {
                            //void
                        }
                    }
                }
                else {
                    //void
                }
            }
            int kans = 0;
            rep(i, blen) {
                if (B[i] == 0) {
                    kans += 1;
                }
                else {
                    //void
                }
            }
            if (kans == k) {
                ans += 1;
            }
            else {
                //void
            }
        }
    }

    printf("%d", ans);
    

    return 0;
}

Measured memory_bytes: 2564
H, W = map(int, input().split())
N = H * W
S = [input() for _ in range(H)]


def idx(i, j):
    return i * W + j


adj = [[float('inf')] * N for _ in range(N)]
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        index = idx(i, j)
        if i > 0 and S[i - 1][j] == '.':
            adj[index][idx(i - 1, j)] = 1
            adj[idx(i - 1, j)][index] = 1
        if j < W - 1 and S[i][j + 1] == '.':
            adj[index][idx(i, j + 1)] = 1
            adj[idx(i, j + 1)][index] = 1
        if i < H - 1 and S[i + 1][j] == '.':
            adj[index][idx(i + 1, j)] = 1
            adj[idx(i + 1, j)][index] = 1
        if j > 0 and S[i][j - 1] == '.':
            adj[index][idx(i, j - 1)] = 1
            adj[idx(i, j - 1)][index] = 1

class WarshallFloyd(object):

    def __init__(self, adj):
        """
        ワーシャル・フロイド法によって全頂点間の最短距離を O(|V|^3) で計算する。

        :param adj: 隣接行列 adj[i][j] でi番目の頂点からj番目の頂点へのコストを示す パスがなければINF
        """
        self._dist = adj  # 各頂点間の最短距離 初期値として隣接行列をそのまま用い、[i, i]要素を0に初期化する
        for i in range(len(adj)):
            self._dist[i][i] = 0

        self._solve()

    def _solve(self):
        v_len = len(self._dist)
        for i in range(v_len):  # 経由する頂点
            for j in range(v_len):  # 開始頂点
                for k in range(v_len):  # 終端
                    self._dist[j][k] = min(self._dist[j][k], self._dist[j][i] + self._dist[i][k])

    def distance(self, start, goal):
        return self._dist[start][goal]

    def path(self, start, goal):
        pass


from math import isinf

wf = WarshallFloyd(adj)
ans = 0
for r in wf._dist:
    m = max(filter(lambda x: not isinf(x), r))
    ans = max(ans, m)
print(ans)

Measured memory_bytes: 133752
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<functional>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X <<":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e14;
typedef std::pair<ll,ll> P;
struct edge{ int to,cost; };
#define VMAX 100000

ll N,M,X;
ll A[200010],B,C;
set<ll> S;
ll ans;
int main(){

    cin>>N;
    REP(i,N){
        ll a;
        cin>>a;
        S.insert(a);
    }
    cout<<(S.size()==N?"YES":"NO")<<endl;



}


Measured memory_bytes: 9600
N = int(input())
S1 = input()
S2 = input()
MOD = 10**9+7
ans = 1
prev = None
for c1,c2 in zip(S1,S2):
    if (c1,c2) == prev: continue
    if prev:
        if prev[0] == prev[1]:
            ans *= 2
        else:
            if c1 != c2:
                ans *= 3
    else:
        if c1 == c2:
            ans = 3
        else:
            ans = 6
    prev = (c1,c2)
print(ans % MOD)

Measured memory_bytes: 3064
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
int n;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    cin >> n;
    int f0 = 0, f1 = 0, f2 = 0;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        if (x % 2) {
            f1++;
        }
        else if (x % 4 == 0) f0++;
        else f2++;
    }
    if (f0 == 0) {
        if (f1 == 0) {
            cout << "Yes\n";
        }
        else {
            cout << "No\n";
        }
        exit(0);
    }
    if (f1 + (f2 > 0) > f0 + 1) {
        cout << "No";
    }
    else {
        cout << "Yes";
    }
    return 0;
}


Measured memory_bytes: 256
#pypy
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

#累積和
for _ in range(K):
    B = [0]*N
    for i in range(N):
        l = max(0,i-A[i])
        r = min(N-1, i+A[i])
        B[l] += 1
        if r+1 < N: B[r+1] -= 1
    for i in range(1,N):
        B[i] += B[i-1]
    A,B = B,A
    if min(A) == N:
        break
print(*A)


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

double t, e, ut, lt, p;

double rep(int k, double l, double r, double pp) {
	if(ut < r || lt > l) return 0;
	double m = (l + r) / 2;
	if(!k) {
		if(m > ut || m < lt) return 0;
		else return pp;
	}
	else {
		if(m < t) return rep(k - 1, m, r, pp * p) + rep(k - 1, l, m, pp * (1 - p));
		else return rep(k - 1, m, r, pp * (1 - p)) + rep(k - 1, l, m, pp * p);
	}
}

int main(){
	int k, r, l;
	cin >> k >> r >> l >> p >> e >> t;
	ut = t + e, lt = t - e;
	cout << fixed;
	cout << setprecision(6) << rep(k, l, r, 1.) << endl;
}



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

const int INF = 1e8;

int N, W;
int v[111], w[111];
int dp[11111];

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; i++) { cin >> v[i] >> w[i]; }

    // DP
    for (int i = 0; i <= W; i++) {
        for (int j = 0; j < N; j++) {
            if (i >= w[j]) {
                dp[i] = max(dp[i], dp[i-w[j]]+v[j]);
            }
        }
    }

    cout << dp[W] << endl;

    return 0;
}


Measured memory_bytes: 3148
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <math.h>

using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
static const ll maxLL = (ll)1 << 62;

///////////////////////////
////Prime Creator//////////
///////////////////////////
//bool Prime[100001] = {};
//void createPrime() {
//	ll n = 100001;
//	rep(i, 0, n) Prime[i] = true;
//	Prime[0] = false;
//	Prime[1] = false;
//	rep(i, 2, n) {
//		if (Prime[i]) {
//			rep(j, 2, n) {
//				if (j*i >= n)break;
//				Prime[j*i] = false;
//			}
//		}
//	}
//}
///////////////////////////
///////////////////////////

ll m[10][10];
void WarshalFloyid() {
	ll size = 10;
	rep(k, 0, size)rep(i, 0, size)rep(j, 0, size)m[i][j] = min(m[i][j], m[i][k] + m[k][j]);
}
static const ll MIN_LL = (ll)1 << 55;
int main() {
	ll H, W; cin >> H >> W;
	rep(i, 0, 10)rep(j, 0, 10)cin >> m[i][j];
	WarshalFloyid();

	ll sum = 0;
	rep(i, 0, H) {
		rep(j, 0, W) {
			ll c = 0;
			cin >> c;
			if (c == -1)continue;
			sum += m[c][1];
		}
	}
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256