akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

#define hell                         1000000007
#define lcm(a,b)                     (a*b)/__gcd(a,b)
#define ll                           long long
#define vll                          vector<ll>
#define vi                           vector<int>
#define pll                          vector< pair<ll,ll> >
#define pb                           push_back
#define mp                           make_pair
#define all(v)                       v.begin(),v.end()
#define lbnd                         lower_bound
#define ubnd                         upper_bound
#define bs                           binary_search
#define F                            first
#define S                            second
#define rep(i,a,b)                   for(i=a;i<b;i++)
#define parr(a,n)                    for(ll it=0;it<n;it++) cout<<a[it]<<" ";cout<<endl;
#define pcont(a)                     for(auto it:a) cout<<it<<" ";cout<<endl;
#define ret(x)                       return cout<<x,0;
#define endl                           '\n'

/*constants*/
#define MAXN                         100005
#define PI                           3.14159265358979323846

/*debug*/
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>void __f(const char* name, Arg1&& arg1){ std::cout << name << " : " << arg1 << '\n';}
    template <typename Arg1, typename... Args>void __f(const char* names, Arg1&& arg1, Args&&... args){const char* comma = strchr(names + 1, ','); std::cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);}
#else
#define trace(...)
#endif

using namespace std;


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	
	ll i,j,n,m,k,cnt=0,ans=0,t=1;
	cin>>n>>m;

	string s[n];
	rep(i,0,n) cin>>s[i];
	ll l[n][m],r[n][m],u[n][m],d[n][m];
	memset(l,0,sizeof(l));	
	memset(r,0,sizeof(r));	
	memset(u,0,sizeof(u));	
	memset(d,0,sizeof(d));	
	rep(i,0,n){
		cnt=0;
		rep(j,0,m){
			if(s[i][j]=='#') {
				cnt=0;
				continue;
			}
			else{
				l[i][j]=cnt;
				cnt++;
			}
		}
		cnt=0;
		for(j=m-1;j>=0;j--){
			if(s[i][j]=='#') {
				cnt=0;
				continue;
			}
			else{
				r[i][j]=cnt;
				cnt++;
			}
		}
	}
	rep(j,0,m){
		cnt=0;
		rep(i,0,n){
			if(s[i][j]=='#') {
				cnt=0;
				continue;
			}
			else{
				u[i][j]=cnt;
				cnt++;
			}
		}
		cnt=0;
		for(i=n-1;i>=0;i--){
			if(s[i][j]=='#') {
				cnt=0;
				continue;
			}
			else{
				d[i][j]=cnt;
				cnt++;
			}
		}
	}
	rep(i,0,n){
		rep(j,0,m){
			if(s[i][j]!='#'){
				ans=max(ans,l[i][j]+r[i][j]+u[i][j]+d[i][j]+1);
			}
		}
	}
	ret(ans)
	return 0;
}

Measured memory_bytes: 129536
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;

#define rep(i,N) for(int i=0;i<(int)N;++i)

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}
int main()
{
    int x, y;
    cin >> x >> y;

    vector<int> a, b, c;

    a = {1,3,5,7,8,10,12};
    b = { 4,6,9,11 };

    for(int i=0;i<6;++i){
        for (int j = i + 1; j < 7; ++j) {
            if (a[i] == x && a[j] == y) { cout << "Yes" << endl; goto pqr; }
            if (a[i] == y && a[j] == x) { cout << "Yes" << endl; goto pqr; }
        }
    }

    for (int i = 0; i < 3; ++i) {
        for (int j = i + 1; j < 4; ++j) {
            if (b[i] == x && b[j] == y) { cout << "Yes" << endl; goto pqr; }
            if (b[i] == y && b[j] == x) { cout << "Yes" << endl; goto pqr; }
        }
    }

    cout << "No" << endl;

pqr:;

}

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

int n;
int a[100005];
int f[100005];
int b[100005];
int ans;
int gcd(int a, int b) {
  return (b == 0) ? a : gcd(b,a % b);
}

int main() {
  cin >> n;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
  }
  f[0] = a[0];
  b[n-1] = a[n-1];
  for(int i = 1; i < n; i++) f[i] = gcd(f[i-1],a[i]);
  for(int i = n-2; i >= 0; i--) b[i] = gcd(b[i+1],a[i]);
  ans = max(f[n-2],b[1]);
  for(int i = 1; i < n - 1; i++) {
    ans = max(ans,gcd(f[i-1],b[i+1]));
  }
  //for(int i = 0; i < n; i++) cout << f[i] <<"   "<<b[i]<<endl;
  cout << ans << endl;
  
}

  


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

using namespace std;

bool contain(vector<int> list, int object);

int main()
{
    int n, t, l, b;
    while(true){
        cin >> n >> t >> l >> b;
        if(n == 0)break;

        vector<int> block_state(n+1);
        int temp_l, temp_b;
        for(int i = 0; i < l; i++){
            cin >> temp_l;
            block_state[temp_l] = 1;
        }
        for(int i = 0; i < b; i++){
            cin >> temp_b;
            block_state[temp_b] = 2;
        }

        vector<vector<double>> per;
        /*per[time][pos]は、時刻timeで位置posにいる確率。
         pos > nのところは、pos-nがLだった場合の次のマス(架空)*/
        per.resize(t+1);
        for(int i = 0; i < t+1; i++){
            per[i].resize(2*n);
        }

        per[0][0] = 1;
        for(int time = 1; time <= t; time++){
            for(int pos = 0; pos < n+1; pos++){
                for(int i = 1; i <= 6 && pos-i >= 0; i++){
                    if(block_state[pos-i] == 0){
                        per[time][pos] += per[time-1][pos-i] / 6;
                    }
                    if(block_state[pos-i] == 1){
                        per[time][pos] += per[time-1][pos-i+n] / 6;
                    }
                }
                if(block_state[pos] == 2){
                    per[time][0] += per[time][pos];
                    per[time][pos] = 0;
                }
            }
            for(int pos = n-5; pos < n; pos++){
                int temp = 6+pos-n;
                for(int i = 1; i <= temp; i++){
                    if(block_state[n-i] == 0){
                        per[time][pos] += per[time-1][n-i] / 6;
                    }
                    if(block_state[n-i] == 1){
                        per[time][pos] += per[time-1][2*n-i] / 6;
                    }
                }
                if(block_state[pos] == 2){
                    per[time][0] += per[time][pos];
                    per[time][pos] = 0;
                }
            }

            per[time][n] += per[time-1][n];

            for(int pos = n+1; pos < 2*n; pos++){
                if(block_state[pos-n] == 1){
                    per[time][pos] = per[time-1][pos-n];
                }
            }

            // cout << "turn: " << time << endl;
            // for(int i = 0; i < n; i++){
            //     cout << per[time][i] << ", ";
            // }
            // cout << per[time][n] << endl;
            // for(int i = n+1; i < 2*n-1; i++){
            //     cout << per[time][i] << ", ";
            // }
            // cout << per[time][2*n-1] << endl << endl;

        }
        cout << setprecision(6) << fixed << per[t][n] << endl;
    }
    return 0;
}

Measured memory_bytes: 1392
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int N; cin >> N;
  vector<int> ans(N);
  for(int i=0;i<N-1;i++){
    int A; cin >> A;
    ans[A-1]++;
  }
  for(int i=0;i<N;i++){
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 4052
#include <stdio.h>

int main() {
    int a,b;
    scanf("%d %d", &a, &b);
    if (a<b) {
        printf("a < b\n");
    }else if(a>b){
        printf("a > b\n");
    }else{
        printf("a == b\n");
    }
    return 0;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
const int MAX=1e6;
long a[MAX],dp[MAX];
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++)
        {cin>>a[i];dp[i]=LONG_MAX;}

    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            if(j<=i)
            {
                dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
            }
        }
    }
    cout<<dp[n-1];


}


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

//??????????????????????????????
void show_array(int a[],int n){
  for(int i=0;i<n;i++){
    if(i>0) cout << " ";
    cout << a[i];
  }
  cout << endl;
}

int SelectionSort(int a[],int n){
  int count=0;
  for(int i=0;i<n;i++){
    int index=0;
    int minv=a[i];
    for(int j=i+1;j<n;j++){
      if(a[j]<minv){
        minv=a[j];
        index=j;
      }
      }
    if(i<index){
      int temp;
      temp=a[i];
      a[i]=a[index];
      a[index]=temp;
      count++;
    }
    }
    return count;
  }

  int main(){
    int n;
    cin >> n;
    int num_list[n];
    for(int i=0;i<n;i++) cin >> num_list[i];
    int count=SelectionSort(num_list,n);;
    show_array(num_list,n);
    cout << count << endl;
  }

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

int main(){
    int a;  cin>>a;
    int ans=0;
    for(int i=0;i<a;i++){
        int x;  cin>>x;
        if(x%2==0)ans++;
    }
    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 3088
#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 a, b;
	cin >> a >> b;

	cout << (a ^ b) << "\n";

	return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> anys;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(anys{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

int main(){
	ll H, W;
	cin >> H >> W;
	if(H==1 || W==1) cout << 1 << endl;
	else cout << (H*W+1)/2 << endl;

	return 0;
}


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

#if 0
#define DEBUG(x) do{cerr << #x << "=" << x << endl;}while(0);
#else
#define DEBUG
#endif

int main(){
	int n, m;
	cin >> n >> m;
	vector<int> arr(n);
	for(int i=0; i < n; ++i){
		cin >> arr[i];
	}

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

	int cnt = 0;
	for(int i=0; i < n; ++i){
		if( arr[i] * 4 * m >= total ){
			cnt++;
		}
	}

	if( m <= cnt ){
		//cerr << m << " " << cnt << endl;
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}


	return 0;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (k, s) = scan!(i64, i64);
    let mut ans = 0;
    for x in 0..k + 1 {
        for y in 0..k + 1 {
            if 0 <= s - (x + y) && s - (x + y) <= k {
                ans += 1;
            }
        }
    }
    println!("{}", ans)
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(ll i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(ll i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    int n;
    cin>>n;
    ll ans=1;
    REP(i,n){
        ans*=(i+1);
        ans%=MOD;
    }
    cout<<ans<<endl;
    return 0;
}

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

int h, w, c[10][10], a[10];

int main(){
  cin >> h >> w;
  rep(i, 10)rep(j, 10) cin >> c[i][j];
  rep(i, 10) a[i] = 0;
  rep(i, h * w){
    int tmp; cin >> tmp;
    if(tmp == -1) continue;
    a[tmp]++;
  }
  //rep(i, 10){rep(j, 10) cerr <<  c[i][j]; cerr << endl;}
  //rep(i, 10) cout << a[i] <<" ";
  
  int seq[10]; rep(i, 10) seq[i] = i;
  seq[0] = 1; seq[1] = 0;
  int cost[10]; rep(i, 10) cost[i] = 100000000;
  cost[1] = 0;
  do{
    int sum = 0;
    for(int i = 1; i < 10; i++){
      sum += c[seq[i]][seq[i - 1]]; //iからi - 1へ向かう時のコスト
      cost[seq[i]] = min(cost[seq[i]], sum);
    }
    //rep(i, 10) cout << seq[i]; cout << endl;
  }while(next_permutation(seq + 1, seq + 10));
  //rep(i, 10) cerr << cost[i] << " ";
  
  int res = 0;
  rep(i, 10){
    res += a[i] * cost[i];
  }
  cout << res << endl;
  return 0;
}


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

int main(void){
  int n, a[200010]={0};
  
  cin >> n;
  for (int i=2; i<=n; i++){
    int t; cin >> t;
    a[t]++;
  }
  for (int i=1; i<=n; i++){
    cout << a[i] << endl;
  }
//  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4372
#include<stdio.h>
#include<string.h>

int main(void)
{
  char S[1000] = {0};
  char T[1000] = {0};
  int sl,tl,i,j;
  int cc,min = 1000;

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

  sl = strlen(S);
  tl = strlen(T);

  for(i = 0;i < sl ;i++)
  {
    cc = 0;
    if(i + tl <= sl)
    {
      for(j = 0;j < tl;j++)
      {
        if(T[j] != S[i + j])cc++;
        //printf("%c %c %d\n",T[j],S[i + j],cc);
      }
      if(min > cc)min = cc;
    }
  }

  printf("%d",min);
  
  return 0;
}


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

int main(){
    int h,w;cin >> h >> w;
    vector<string> v;
    for(int i=0;i<h;i++){
        string s;cin >> s;
        s = '.' + s + '.';
        v.push_back(s);
    }
    string t(w+2,'.');
    v.insert(v.begin(),t);
    v.push_back(t);
    bool flag = true;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            if(v[i][j] == '#'){
                if(v[i-1][j]=='.' && v[i+1][j]=='.' && v[i][j-1] == '.' && v[i][j+1] == '.'){
                    flag = false; break;
                }
            }
        }
    }
    if(flag)cout << "Yes" << endl;
    else{cout << "No" << endl;}
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int n,ans,sum;
char s[300010];
int main()
{
	cin>>n;
	cin>>s;
	sum=0;
	for(int i=1;i<strlen(s);i++){
		if(s[i]=='E'){
			sum++;
		}
	}
	ans=sum;
	for(int i=1;i<strlen(s);i++){
		if(s[i]=='E'){
			sum--;
		}
		if(s[i-1]=='W'){
			sum++;
		}
		if(sum<ans){
			ans=sum;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }
// ll comb(ll n, ll k) { ll v=1; for(ll i=1; i<=k; i++) v = DIV(MUL(v, n-i+1),i); return v; }
//

#define INTSPACE 12
char _buf[INTSPACE*1000000 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}

int loadvec(vector<int>& v, int N=-1) {
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    // assert(i <= N);
    return i;
}

int solve(int N, vi& a) {
    sort(ALL(a));reverse(ALL(a));
    int ans = 0;
    // cerr<<a<<endl;
    for (int i=1; i<N*2; i+=2) {
        ans += a[i];
    }
    return ans;
}

int main() {
    int N = loadint();
    vi a(N*2);
    loadvec(a, N*2);
    cout << solve(N,a) << endl;
    // cout << (solve(N,a) ? "Yes":"No") << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define PMAX 1000000000
#define MAX 100000
int wmax=0;
int n,k,w[MAX];  
int check(int P){
    int i;
    int count=1,now=P;
    if(P<wmax) return 0;
    for(i=0;i<n;i++){
        if(now>=w[i]){
           now-=w[i];
        }else{
            count++;
            now=P-w[i];
        }
    }
    if(count>k) return 0;
    else return 1;
}
  
int main(void){
    int i;
    int left,right,mid;
    scanf("%d %d",&n,&k);
    for(i=0;i<n;i++){
        scanf("%d",&w[i]);
        if(w[i]>wmax) wmax=w[i];
    }
    left=0,right=PMAX;
    while(right-left>1){
        mid=(left+right)/2;
        if( check(mid) ) right=mid;
        else left=mid;
    }
    printf("%d\n",right);
    return 0;
}

Measured memory_bytes: 984
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 100000000;
const int MAX_N = 100;
typedef pair<int , int> P;
typedef long long ll;
 
int main () {
  int S, W;
  cin >> S >> W;
  if (S > W) {
    printf("safe\n");
  } else {
    printf("unsafe\n");
  }
  return 0;
}


Measured memory_bytes: 3596
import Foundation

extension String {
    
    func toStrList() -> [String] {
        return self.map{String($0)}
    }
    
    func toIntList() -> [Int] {
        return self.map{Int(String($0))!}
    }
    
    func toSepDoubleList() -> [Double]{
        return self.split(separator: " ").map{Double($0)!}
    }

    func toSepIntList() -> [Int] {
        return self.split(separator: " ").map{Int($0)!}
    }

    func toSepStrList() -> [String] {
        return self.split(separator: " ").map{String($0)}
    }
    
    func zFill(n:Int) -> String {
        return String(format: "%0\(n)d", Int(self)!)
    }
    
    func count(c:Character) -> Int{
        var result = 0

        for e in self{
            if e == c{
                result += 1
            }
        }
        return result
    }

    func counter() -> Dictionary<Character, Int>{
        var result:[Character:Int] = [:]
        
        for c in self{
            guard let _ = result.index(forKey: c) else {
                result[c] = 1
                continue
            }
            result[c]! += 1
        }
        return result
    }
}

extension Int {
    func toBin() -> String {
        return String(self, radix: 2)
    }
    
    func toNBin(_ radix:Int) -> String{
        return String(self, radix: radix)
    }
    
    func toD() -> Double {
        return Double(self)
    }
}

extension Double {
    func toI() -> Int {
        return Int(self)
    }
}

extension Array where Element: Equatable{
    func count(n:Self.Element) -> Int{
        var result = 0
        for e in self{
            if e == n{
                result += 1
            }
        }
        return result
    }
}

extension Array {
    func dump(){
        for x in 0..<self.count-1{
            print(self[x], terminator: " ")
        }
        print(self.last!)
    }
}

func pow(_ base:Int,_ exp:Int) -> Int{
    let d = pow(base.toD(), exp.toD())
    return Int(d)
}

func distance(p1:CGPoint, p2:CGPoint) -> Double {
    let diffp = CGPoint(x:p1.x - p2.x, y:p1.y - p2.y)
    return Double(sqrt(diffp.x*diffp.x + diffp.y * diffp.y))
}

func distance(p1:[Double], p2:[Double]) -> Double{
    let diff = [p1[0] - p2[0], p1[1] - p2[1]]
    return sqrt(diff[0] * diff[0] + diff[1] * diff[1])
    
}

func lotate(theta:Double, point:[Double]) -> [Double] {
    let matrix = [
        [cos(theta), -sin(theta)],
        [sin(theta), cos(theta)]
    ]
    let x = point[0]
    let y = point[1]
    
    let rx = matrix[0][0]*x + matrix[0][1]*y
    let ry = matrix[1][0]*x + matrix[1][1]*y
    
    return [rx, ry]
}


func caddi2018b() -> Int {
    let NHW = readLine()!.toSepIntList()
    var ans = 0
    for _ in 1...NHW[0]{
        let AB = readLine()!.toSepIntList()
        if AB[0] < NHW[1] || AB[1] < NHW[2] {
            continue
        }
        ans += 1
    }
    return ans
}

print(caddi2018b())

Measured memory_bytes: 13576
#include <stdio.h>
 
int main() {
	char out[21];
	char in[21];
	int csr = 0;
 
	scanf("%s",in);
	for (int i = 0; i<20; i++) {
		if (!in[i])break;
 
		switch (in[i]) {
		case '0':
			out[csr] = '0';
			out[csr + 1] = '\0';
			csr++;
			break;
 
		case '1':
			out[csr] = '1';
			out[csr + 1] = '\0';
			csr++;
			break;
 
		case 'B':
			if (csr>0) {
csr--;
				out[csr] ='\0';
				
			}
		}
	}
	printf("%s", out);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if(A+B > C+D) cout << "Left" <<endl;
  else if(A+B < C+D) cout << "Right" <<endl;
  else cout << "Balanced" <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define nl '\n'
int main()
{
   int a[4];
   cin>>a[0]>>a[1]>>a[2];
   sort(a,a+3);
   if(a[0]+a[1]==a[2])
      cout<<"Yes";
   else
      cout<<"No";
   cout<<nl;
    return 0;
}


Measured memory_bytes: 256
mod io{
    use std::io::*;
    pub fn read<T: ::std::str::FromStr>()->T{
        let stdin=stdin();
        let ret=stdin.lock().bytes().map(|c|c.unwrap()as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect::<String>().parse().ok().unwrap();
        ret
    }
}
use io::read;
use std::cmp::*;
fn main(){
    let a=read::<i32>();
    let b=read::<i32>();
    let k=read::<i32>();
    let c=min(a+k,b);
    for i in a..c{println!("{}",i)}
    for i in max(c,b-k+1)..b+1{println!("{}",i)}
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#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 ll long long
#define int long long 
#define INF 1e18
#define ar array
#define f first
#define s  second
#define REP(i,n) for (int i=0;i<(n);i++)
#define wt(x) int x;cin>>x;while(x--)
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <typename T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; 

void  c_p_c(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  #ifndef ONLINE_JUDGE
  freopen("input1.txt","r",stdin);

  freopen("output1.txt","w",stdout);
#endif
}

int power(int a,int b,int mod){
  a=a%mod;
  if(a==0){
    return 1;
  }
  int res=1;
  while(b){
    if(b&1){
      res=(res*a)%mod;
    }
    b>>=1;
    a=(a*a)%mod;
  }
  return res;
}

int  MMI(int p){
  return power(p,MOD-2,MOD);

}

int32_t main()
{
 c_p_c();
 int n;
 cin>>n;
 string s;
 cin>>s;
 int l=0,r=n-1,ans=0;
 while(1){
  while(l<r && s[l]=='R')l++;
  while(l<r && s[r]=='W')--r;
  if(l==r)break;
  swap(s[l],s[r]);
  ++ans;
 }
 cout<<ans;



return 0;

}








   



   








Measured memory_bytes: 3756
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{

    static class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            var N = GetInt();
            bool b = false;
            if (N % 7 == 0)
            {
                b = true;
                N = -1;
            }
            while (N >= 0)
            {
                N = N - 4;
                if (N % 7 == 0)
                {
                    b = true;
                    break;
                }
            }
            var ans = YesNo(b);

            Console.WriteLine(ans);
        }

        static public string GetStr() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
        static string yesno(this bool b) { return b ? "yes" : "no"; }
        static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
    }
}

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

using namespace std;

int main()
{
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif // LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    s.resize(unique(s.begin(), s.end()) - s.begin());
    if (s.size() == 2) cout << "Yes";
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
n, w = map(int, input().split())
wv = [tuple(map(int, input().split())) for i in range(n)]
#wv[i][0]:i番目の品物の重さ
#wv[i][1]:i番目の品物の価値

dp = [0]*(w+1)#dp[i]:重さiにおける最大価値
for i in range(n):#あるi番目の品物について
    for j in range(w,wv[i][0]-1, -1):#ある重さjについて
        dp[j] = max( dp[j], dp[j-wv[i][0]]+wv[i][1] )#i番目の品物を使うほうが重さjでの価値が高い場合は値を更新

print(max(dp))

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

typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int H,W,L,P;
int X[100000],Y[100000];

bool ex[4000][4000];
int up[4000][4000],dw[4000][4000];

void Latting(){
    rep(i,H)rep(j,W)up[i][j]=dw[i][j]=INT_MAX;

    int prev;

    //>
    rep(i,H){
        prev=0;
        rep(j,W){
            if(ex[i][j])prev=0;
            else prev++;
            chmin(dw[i][j],prev);
        }
    }

    //<
    rep(i,H){
        prev=0;
        for(int j=W-1;j>=0;j--){
            if(ex[i][j])prev=0;
            else prev++;
            chmin(up[i][j],prev);
        }
    }

    //^
    rep(j,W){
        prev=0;
        rep(i,H){
            if(ex[i][j])prev=0;
            else prev++;
            chmin(dw[i][j],prev);
        }
    }

    //v
    rep(j,W){
        prev=0;
        for(int i=H-1;i>=0;i--){
            if(ex[i][j])prev=0;
            else prev++;
            chmin(up[i][j],prev);
        }
    }
}

int bit_n,bit[4444];
void init(int n){bit_n=n;rep(i,bit_n+114)bit[i]=0;}
void add(int k,int x){for(k++;k<=bit_n;k+=k&-k)bit[k]+=x;}
int sum(int k){int ret=0;for(k++;k;k-=k&-k)ret+=bit[k];return ret;}

long long ans=0;

struct data{
    int l,k,f;
    data(){}
    data(int a,int b,int c):l(a),k(b),f(c){}
    bool operator<(const data &d)const{
        if(l!=d.l)return l<d.l;
        return f<d.f;
    }
};

data v[10000];

void Malting(int y,int x){
    int n;
    int vn=0;
    for(n=0;y+n<H&&x+n<W;n++){
        if(ex[y+n][x+n])continue;
        v[vn++]=data(up[y+n][x+n],n,0);
        v[vn++]=data(dw[y+n][x+n],n,1);
    }

    sort(v,v+vn);reverse(v,v+vn);
    init(n);
    rep(i,vn){
        data &d=v[i];
        if(d.f==1){
            add(d.k,1);
            continue;
        }
        if(d.l<L)continue;
        ans+=sum(min(n-1,d.k+d.l-1))-sum(min(n-1,d.k+L-2));
    }

    init(n);
    rep(i,vn){
        data &d=v[i];
        if(d.f==0){
            add(d.k,1);
            continue;
        }
        if(d.l<L)continue;
        ans+=sum(max(-1,d.k-L+1))-sum(max(-1,d.k-d.l));
    }
}

signed main(){
    scanf("%d%d%d%d",&H,&W,&L,&P);
    rep(i,P)scanf("%d%d",&Y[i],&X[i]),Y[i]--,X[i]--,ex[Y[i]][X[i]]=1;

    Latting();

    rep(i,H)Malting(i,0);
    for(int i=1;i<W;i++)Malting(0,i);
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 142712
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


#A
def A():
    n,h,w = IR(3)
    print((n-h+1)*(n-w+1))
    return

#B
def B():
    n = I()
    a,b = LI()
    p = LI()
    k = [0 for i in range(a+1)]
    k += [1 for i in range(b-a)]
    k += [2 for i in range(max(p)+1-b)]
    d = defaultdict(int)
    for i in p:
        d[k[i]] += 1
    ans = min(d[0],d[1],d[2])
    print(ans)
    return

#C
def C():
    h,w = LI()
    s = SR(h)
    bfs_map = [[-1 for i in range(w)] for j in range(h)]
    d = [[0,1],[0,-1],[1,0],[-1,0]]
    ans = 0
    for y in range(h):
        for x in range(w):
            if s[y][x] == "#":
                if bfs_map[y][x] < 0:
                    bfs_map[y][x] = 0
                    a = 1
                    b = 0
                    q = deque()
                    q.append([y,x])
                    while q:
                        n,m = q.popleft()
                        for dy,dx in d:
                            n2 = n+dy
                            m2 = m+dx
                            if 0 <= n2 < h and 0 <= m2 < w:
                                if s[n][m] != s[n2][m2] and bfs_map[n2][m2] < 0:
                                    if s[n2][m2] == "#":a += 1
                                    else:b += 1
                                    bfs_map[n2][m2] = 0
                                    q.append([n2,m2])
                    ans += a*b
    print(ans)
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()


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

int main(){
  long N,a,yon=0,ni=0;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>a;
    if(a%4==0){
      yon += 1;
    }else if(a%2==0){
      ni += 1;
    }
  }
  if(yon==0){
    if(N==ni){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }else if(ni==0){
    if(N<=2*yon +1){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }else{
    if((N-ni)<=2*yon){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }
  return 0;
}


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

int main(void){
    int n; cin >> n;
    int a,b; cin >> a >> b;
    ll ans=0;
    for(int i=1;i<=n;i++){
        ll cnt=0;
        string s= to_string(i);
        for(int j=0;j<s.length();j++){
            cnt += s[j]-'0';
        }
        if(a <= cnt && cnt <= b) ans+=i;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
    int N;
    long long int A, B;
    cin >> N >> A >> B;
    
    vector<long long int> X(N);
    long long int ans=0;
    for(int n=0; n<N; n++) {
        cin >> X[n];
        if(n>0) {
            ans += min((X[n]-X[n-1])*A, B);
        }
    }
    
    cout << ans << endl;
    

    return 0;
    
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<ll,ll> P;
#define pb push_back
#define mp make_pair
#define fr(i,n) for(int i=0;i<n;i++)
#define Fr(i,n) for(int i=0;i++<n;)
#define ifr(i,n) for(int i=n-1;i>=0;i--)
#define iFr(i,n) for(int i=n;i>0;i--)

int main(){
  int m=0,c=0,r[100010],ans=0;
  string s,t="";
  bool f=0;
  cin>>s;
  fr(i,s.length()){
    if(s[i]!='x'){
      t+=s[i];
      r[m++]=c;
      c=0;
    }
    else{
      c++;
    }
  }
  r[m++]=c;
  fr(i,t.length()) if(t[i]!=t[t.length()-1-i]) f=1;
  if(f){cout<<-1<<endl;return 0;}
  fr(i,m) ans+=abs(r[i]-r[m-1-i]);
  cout<<ans/2<<endl;
}

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

int main() {
  int K;
  cin >> K;
  vector<int> vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  
  cout << vec.at(K - 1) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	int a[n];
	int sum = 0;
	int res = 0;
	for (int i = 0; i < n; i++){
		cin >> a[i];
		sum += a[i];
	}
	float j = (float)sum / (4.0*m);
	for (int i = 0; i < n; i++){
		if (a[i] >= j) res++;
	}
 
	if (res >= m) cout << "Yes" << endl;
	else cout << "No" << endl;
 
 
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cassert>
#include <cstdio>
#define N 100100
using namespace std;

int n, m, deg[N], stk[N], top, ins[N], ban[N], fre[N];
int tot = 1, fir[N], nxt[N << 1], to[N << 1];

inline void addE(int u, int v) {
    nxt[++tot] = fir[u], fir[u] = tot, to[tot] = v;
}

void dfs(int u, int e, int &cnt) {
    if (cnt) return ;
    if (ins[u]) {
        for (int i = top; stk[i + 1] != u; --i)
            deg[stk[i]] -= 2, ++cnt, ban[fre[stk[i]]] = 1;
        return ;
    }
    ins[u] = 1, stk[++top] = u;
    for (int i = fir[u], v; i; i = nxt[i]) {
        if (i / 2 == e) continue;
        v = to[i], fre[v] = i / 2;
        dfs(v, i / 2, cnt);
    }
    stk[top--] = ins[u] = 0;
}

void dfs2(int u, int &cnt) {
    if (ins[u]) return ;
    ins[u] = 1, ++cnt;
    for (int i = fir[u], v; i; i = nxt[i]) {
        v = to[i];
        if (ins[v] || ban[i / 2]) continue;
        dfs2(v, cnt);
    }
}

int main() {
#ifdef isLOCAL
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif

    cin >> n >> m;
    
    for (int i = 1, u, v; i <= m; ++i)
        scanf("%d%d", &u, &v), ++deg[u], ++deg[v],
        addE(u, v), addE(v, u);

    for (int i = 1; i <= n; ++i)
        if (deg[i] & 1) return puts("No"), 0;

    int tmp = 0;
    for (int i = 1; i <= n; ++i)
        if (deg[i] == 4) ++tmp;

    int ok = 0;
    dfs(1, 0, ok);
    if (!ok) return puts("No"), 0;

    int cnt = 0;
    for (int i = 1; i <= n && !cnt; ++i)
        if (deg[i]) dfs2(i, cnt);
    for (int i = 1; i <= n; ++i)
        if (deg[i] == 2) -- cnt;

    if (tmp >= 3) return puts("Yes"), 0;

    puts(cnt ? "Yes" : "No");

    return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;

//#define int long long
//signed main(){
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    if(n%2){
        cout << b[n/2]-a[n/2]+1 << "\n";
    }
    else{
        int ans = (b[n/2]+b[n/2-1])-(a[n/2]+a[n/2-1])+1;
        cout << ans << "\n";
    }
    return 0;
}

Measured memory_bytes: 4764
/**
 * @author: Jun
 * @date  : 03-18-2019
 **/
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
#define el '\n'
#define MOD 1000000007

ll n;
 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n;
    cout << n*(n+1)/2 << el;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <cstdio>

using namespace std;

const long long INF = 100000000;
const long long MOD = 1000000007;

std::vector<bool> IsPrime;

void sieve(size_t max)
{
  if (max + 1 > IsPrime.size())
  {                                // resizeで要素数が減らないように
    IsPrime.resize(max + 1, true); // IsPrimeに必要な要素数を確保
  }
  IsPrime[0] = false; // 0は素数ではない
  IsPrime[1] = false; // 1は素数ではない

  for (size_t i = 2; i * i <= max; ++i)     // 0からsqrt(max)まで調べる
    if (IsPrime[i])                         // iが素数ならば
      for (size_t j = 2; i * j <= max; ++j) // (max以下の)iの倍数は
        IsPrime[i * j] = false;             // 素数ではない
}

class Pointer{
public:
  long long p;
  long long w;
};

int main()
{
  long long K, A ,B;
  cin >> K >> A >> B;
  if (B - A <= 2)
  {
    cout << K + 1<< endl;
    return 0;
  }
  K -= (A-1);
  //cout << "K=" << K << endl;
  //次は売ることもできるしそのままもできる
  if(K%2==0){
    cout<<A + (B - A) * (K / 2) << endl;
    return 0;
  }
  cout<<A + (B - A) * (K / 2) + 1<< endl;
}


Measured memory_bytes: 256
import heapq
N,M = map(int,input().split())
lis = [[] for i in range(10**5+10)]
for i in range(N):
    A,B = map(int,input().split())
    lis[A-1].append(-B)
ans = 0
d = []
heapq.heapify(d)
for i in range(M):
    for j in lis[i]:
        heapq.heappush(d,j)
    if len(d) > 0:
        ans += heapq.heappop(d)*-1
print(ans)


Measured memory_bytes: 88744
import heapq
from sys import stdin
input = stdin.readline

#入力
# s = list(input()[0:-1])
# n = int(input())
N,H,W = map(int, input().split())
# a = list(map(int,input().split()))
# b = list(map(int,input().split()))
# w = [int(input()) for i in range(n)]

ab=[]
for i in range(N):
    a,b = map(int, input().split())
    ab.append((a,b))
def main():
    ans = 0 
    for a,b in ab:
        if a>=H and b >=W:
            ans+=1
    print(ans)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>

#define MOD 1000000007
using ll = long long;
using namespace std;

int main() {
    int A, B, C;
    int ans;
    cin >> A;
    cin >> B;
    if (A > B) {
        swap(A, B);
    }
    cin >> C;
    if (B > C) {
        swap(B, C);
        if (A > B) {
            swap(A, B);
        }
    }
    ans = C - B;
    ans += (C - A - ans) / 2;
    if ((B - A) % 2 != 0) {
        ans += 2;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX 2000000
int main(){
    int N ,D,cnt = 0;
    double X[MAX],Y[MAX];
    cin >> N >> D;

    for(int i=0;i<N;i++){
        cin >> X[i] >> Y[i];
        if(pow((pow(X[i],2) + pow(Y[i],2)),0.5) <= D){
            cnt++;
        }
    }
    
    cout << cnt <<  endl;
    return 0;
}

Measured memory_bytes: 7492
#include<bits/stdc++.h>
using namespace std;
int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
   	#endif
    char c;
    int ans=0;
    while(cin>>c) if(c=='1') ++ans;
   	cout<<ans;
   	return 0;
}

Measured memory_bytes: 3596
/*
ID: wangjun30
LANG: C++11
TASK:
*/
#include<iostream>
#include<algorithm>
#include<array>
#include<unordered_map>
#include<map>
#include<set>
#include<list>
#include<stack>
#include<unordered_set>
#include<vector> 
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
//#include<fstream>
#define int long long
using namespace std;
//ifstream cin(".in");
//ofstream cout(".out");
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	char ch;
	cin>>ch;
	if(isupper(ch))
		cout<<"A";
	else
		cout<<'a';
	return 0;
}

Measured memory_bytes: 3648
N, M= map(int, input().split())
L, R=map(int, input().split()) 

for _ in range(M-1):
  l, r=map(int, input().split())
  if L < l:
    L = l
  if R > r:
    R = r
ans = R - L + 1
if ans > 0:
  print(ans)
else:
  print(0)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
		
			
		int na = n*a;
		
		if (na<b) {
			System.out.println(na);
		}else {
			System.out.println(b);
			
		}

	}

}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,t,a,b,a1,b1,t1,i;
    cin>>n;
    t1=0;
    a1=b1=0;
    for(i=1;i<=n;i++) {
        cin>>t>>a>>b;
        if((abs(a1-a)+abs(b1-b))>t-t1 || ((abs(a1-a)+abs(b1-b))%2!=(t-t1)%2)) {
            cout<<"No";
            return 0;
        }
        a1=a;
        b1=b;
        t1=t;
    }
    cout<<"Yes";
    return 0;
}


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

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      String line;
      StringBuilder cards = new StringBuilder();
      int sTimes = 0;
      int cuts = 0;

      while(true){

        if( (line = br.readLine()).equals("-") ) break;

        cards.append(line);
        sTimes = Integer.parseInt(br.readLine());

        for ( int i = 0; i < sTimes; i++ ) {
          cuts = Integer.parseInt(br.readLine());
          cards.append(cards.substring(0, cuts))
               .delete(0,cuts);
        }

        System.out.println(cards);

        cards.setLength(0);
      }
    }
  }
}


Measured memory_bytes: 24204