akhauriyash/Code-Regression huggingface dataset:
def grid2graph(grid):
    # .が道で#が壁のグリッドをグラフに変換する
    H, W = len(grid), len(grid[0])
    f = {}
    cnt = 0
    for h in range(H):
        for w in range(W):
            if grid[h][w] == '.':
                f[(h, w)] = cnt
                cnt += 1
    G = [[] for i in range(cnt)]
    for h in range(H):
        for w in range(W):
            if grid[h][w] == '#':
                continue
            i = f[(h, w)]
            if 0 <= h-1 and grid[h-1][w] == '.':
                j = f[(h-1, w)]
                G[i].append(j)
            if 0 <= w-1 and grid[h][w-1] == '.':
                j = f[(h, w-1)]
                G[i].append(j)
            if h+1 < H and grid[h+1][w] == '.':
                j = f[(h+1, w)]
                G[i].append(j)
            if w+1 < W and grid[h][w+1] == '.':
                j = f[(h, w+1)]
                G[i].append(j)
    return G


def warshall_floyd(G):
    inf = 10**18
    n = len(G)
    d = [[inf for i in range(n)] for j in range(n)]
    for i in range(n):
        d[i][i] = 0
        for j in G[i]:
            d[i][j] = 1
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k]+d[k][j])
    return d


H, W = map(int, input().split())
S = []
for h in range(H):
    S.append(list(input()))
G = grid2graph(S)
d = warshall_floyd(G)
n = len(d)
ans = 0
for i in range(n-1):
    for j in range(n):
        ans = max(ans, d[i][j])
print(ans)


Measured memory_bytes: 41968
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> b(n-1);
  for(int i=0; i<n-1 ; i++){
    cin>>b.at(i);
  }
  int ans=0;
  ans +=b.at(0)+b.at(n-2);
  for(int i=1; i<n-1 ;i++)
    ans += min(b.at(i-1), b.at(i));
  cout<<ans<<endl;
  return 0;
  
    
}

Measured memory_bytes: 256
#include <stdio.h>
#include <vector>
#include <tuple>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(n) for (int i = 0; i < int(n); i++)
#define FOR1(m, n) for (int i = int(m); i < int(n); i++)
#define MAX(a, b) ((a) >= (b) ? (a) : (b))
#define MIN(a, b) ((a) <= (b) ? (a) : (b))

vector<int> primes = {2, 3, 5, 7, 11, 13, 17, 19};

vector<int> factorize(int n) {
  vector<int> factors;

  int i = 0;
  while (i < primes.size() && primes[i] < n) {
    if (n % primes[i] == 0) {
      factors.push_back(primes[i]);
      n /= primes[i];
    } else {
      i++;
    }
  }
  factors.push_back(n);

  return factors;
}

vector<tuple<int, int>> group(vector<int> vec) {
  vector<tuple<int, int>> res;
  if (vec.size() == 0)
    return res;

  int prev = vec[0];
  int count = 1;
  FOR1(1, vec.size()) {
    if (vec[i] == prev)
      count++;
    else {
      res.push_back(make_tuple(prev, count));
      prev = vec[i];
      count = 1;
    }
  }
  res.push_back(make_tuple(prev, count));

  return res;
}


int main(int argc, char *argv[]) {
  int N;

  scanf("%d", &N);

  int count = 0;
  for (int i = 3; i <= N; i += 2) {
    vector<int> factors = factorize(i);
    vector<tuple<int, int>> factors2 = group(factors);
    if ((factors2.size() == 2 && get<1>(factors2[0])*get<1>(factors2[1]) == 3) ||
        (factors2.size() == 3 && get<1>(factors2[0])*get<1>(factors2[1])*get<1>(factors2[2]) == 1)
      )
      count++;
  }

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

  return 0;
}


Measured memory_bytes: 256
fn main() {
    let n: usize = {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        buf.trim_end().parse().unwrap()
    };

    let mut ans = 0;
    for i in 1..=n {
        if i % 3 > 0 && i % 5 > 0 {
            ans += i;
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 2176
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	ll n, a, b, x;
	cin>>n>>a>>b>>x;
	ll res = 0;
	rep(i, n-1){
		ll x2;
		cin>>x2;
		ll d = x2-x;
		res += min(d*a, b);
		x = x2;
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main(){
    ll h,w;cin >> h >> w;
    ll ans=LINF;
    rrep(i,h){
        if(i==h) continue;
        ll area1=(h-i)*w;
        ll area2=i*(w/2);
        ll area3=i*((w+1)/2);
        ll mn=min({area1,area2,area3});
        ll mx=max({area1,area2,area3});
        chmin(ans,mx-mn);
    }
    rrep(i,h){
        if(i==h) continue;
        ll area1=i*w;
        ll area2=((h-i)/2)*w;
        ll area3=((h-i+1)/2)*w;
        ll mn=min({area1,area2,area3});
        ll mx=max({area1,area2,area3});
        chmin(ans,mx-mn);
    }
    rrep(i,w){
        if(i==w) continue;
        ll area1=(w-i)*h;
        ll area2=i*(h/2);
        ll area3=i*((h+1)/2);
        ll mn=min({area1,area2,area3});
        ll mx=max({area1,area2,area3});
        chmin(ans,mx-mn);
    }
    rrep(i,w){
        if(i==w) continue;
        ll area1=i*h;
        ll area2=((w-i)/2)*h;
        ll area3=((w-i+1)/2)*h;
        ll mn=min({area1,area2,area3});
        ll mx=max({area1,area2,area3});
        chmin(ans,mx-mn);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat May 16 19:11:36 2020

@author: Kanaru Sato
"""

n,m = list(map(int,input().split()))

currentl,currentr = list(map(int,input().split()))
flag = 1

for i in range(m-1):
    l,r = list(map(int,input().split()))
    if currentl <= l and l <= currentr:
        currentl = l
    if currentl <= r and r <= currentr:
        currentr = r
    if currentr < l or r < currentl:
        flag = 0
        print(0)
        break

if flag == 1:
    print(currentr-currentl+1)

Measured memory_bytes: 3188
unittest
{
	assert( [ "198 1.10" ].parse.expand.solve == 217 );
	assert( [ "1 0.01" ].parse.expand.solve == 0 );
	assert( [ "1000000000000000 9.99" ].parse.expand.solve == 9990000000000000 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto ab = input.front.split.to!( real[] );
	return tuple( ab[ 0 ], ab[ 1 ] );
}

auto solve( real a, real b )
{
	return cast( long )( a * b );
}


Measured memory_bytes: 2784
#include<bits/stdc++.h>
using namespace std;
int main(){
  long N;cin>>N;
  vector<long>A(N-1);for(int i=0;i<N-1;i++)cin>>A[i];
  vector<vector<long>>T(N);//有向グラフ; 勝った人から負けた人へ
  for(long i=0;i<N-1;i++)T[A[i]-1].push_back(i+1);
  vector<pair<long,long>>D(N);D[0]=pair<long,long>(0,0);//1からの距離=深さ/i
  queue<long>q;q.push(0);
  while(q.size()){
    long f=q.front();q.pop();
    for(long n:T[f]){
      D[n].first=D[f].first+1;
      D[n].second=n;
      q.push(n);
    }
  }
  vector<long>H(N,0);//下から統合するように
  sort(D.begin(),D.end(),greater<pair<long,long>>());
  for(long i=0;i<N;i++){
    long n=D[i].second;
    vector<long>C;
    for(long c:T[n])C.push_back(H[c]);
    sort(C.begin(),C.end(),greater<long>());
    
    for(long j=0;j<C.size();j++){
      H[n]=max(H[n],C[j]+j+1);
    }
  }
  cout<<H[0];
}
/*




*/

Measured memory_bytes: 8832
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  ll sum = 0;
  for (int i = 1; i <= n; ++i) {
    if (i % 3 == 0 || i % 5 == 0) continue;
    // cout << "i=" << i << endl;
    sum += (ll)i;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3168
//{
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define SZ(_a) (int)_a.size()
#define ALL(_a) _a.begin(),_a.end()
#define pb push_back
#ifdef brian
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // brian
//}


const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15);


ll d[MAXn];
bitset<4000000> dp;

int main()
{
    IOS();
    ll n;
    cin>>n;
    REP(i,n)cin>>d[i];
    dp.reset();
    dp[0] = 1;
    ll tt = 0;
    REP(i,n)
    {
      tt += d[i];
      dp |= (dp<<d[i]);
    }
    tt = (tt + 1)/2;
    for(int i = tt;;i++)
    {
      debug(i);
      if(dp[i])
      {
        cout<<i<<endl;
        return 0;
      }
    }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

ll divisor(ll n){
  ll res=1e18;
	for(ll i=1; i*i<=n; ++i){
		if(n%i==0){
      CHMIN(res, i-1+n/i-1);
		}
	}
	return res;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	ll n;
  cin>>n;
  cout<<divisor(n)<<'\n';
	return 0;
}


Measured memory_bytes: 256
#[allow(dead_code)]
fn rd() -> String {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input.trim().to_owned()
}

/// 1行の文字を空白で分割してVec<T>にする。
#[allow(dead_code)]
fn rd_vec<T : std::str::FromStr>() -> Vec<T> {
    rd().split_whitespace().map(|x| x.parse().ok().unwrap()).collect()
}

/// 1つの要素を入力で受け取る
#[allow(dead_code)]
fn rd_one<T : std::str::FromStr>() -> T {
    rd().parse().ok().unwrap()
}

/// 複数回read_splitを行う
#[allow(dead_code)]
fn rd_vec_mul<T : std::str::FromStr>(count : i32) -> Vec<Vec<T>> {
    (0..count).map(|_| rd_vec()).collect()
}

/// Vecを1列で出力する
#[allow(dead_code)]
fn op_vec<T : std::fmt::Display>(item : Vec<T>, splitter : char) {
    let cnt = item.len();
    let mut c = 0;
    for i in item.iter() {
        c+=1;
        if cnt > c {print!("{}{}", i, splitter);} else {println!("{}", i);}
    }
}

fn main() {
    let n : usize = rd_one();
    let h : Vec<i32> = rd_vec();
    let mut answer = 0;
    for i in 1.. {
        let mut counter = 0;
        let mut before_under = false;
        if h[0] < i {
            before_under = true;
        } else {
            counter+=1;
        }
        for ni in 1..n {
            if h[ni] < i{
                if before_under {
                    continue;
                }
                before_under = true;
                continue;
            }
            if before_under {
                counter+=1;
                before_under = false;
            }
        }

        if counter == 0 {
            break;
        }
        answer += counter;
    }
    
    println!("{}", answer);
}


Measured memory_bytes: 4352
#include <stdio.h>

int main(void)
{
    int N,i,j,c,t;
    c = 0;
    t = 0;
    int A[200];
    scanf("%d",&N);
    for(i = 1;i <= N;i++){
        scanf("%d",&A[i-1]);
    }
    for(j = 1;;j++){
    for(i = 1;i <= N;i++){
        if(A[i-1] % 2 == 0) A[i-1] /= 2;
        else {t = 1;break;}
        if(i == N) c++;
    }
    if(t == 1)break;
    }
    printf("%d\n",c);
	return 0;
}

Measured memory_bytes: 1708
// Problem : C - Repsept
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/**
 * @author dwij
 */

#include <bits/stdc++.h>

#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>

using namespace std;

//******* Debugging Class Template *******/
#define sim template <class c
#define ris return *this
#define dor > deb& operator<<
#define eni(x) \
    sim > typename enable_if<sizeof dud<c>(0) x 1, deb&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct deb {
#ifdef LOCAL
    ~deb() { cerr << endl; }
    eni(!=) cerr << boolalpha << i;
    ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
    sim dor(const c&) { ris; }
#endif
}
;
#define log(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
// End of weird debugging stuff.

typedef long long ll;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int uint64;

#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define pii pair<int, int>
#define pll pair<ll, ll>

#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(), c.end()
#define mem(a, val) memset(a, val, sizeof(a))
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define endl "\n"

void solution() {
    // deb() << log();
    int n;
    cin >> n;

    ll sevens = 7 % n;
    for (int i = 1; i <= 1e7; i++) {
        if (sevens == 0) {
            cout << i << endl;
            return;
        }

        sevens = (sevens * 10 + 7) % n;
    }

    cout << -1 << endl;
}

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

    int T = 1;
    // cin >> T;
    // cin.ignore(); //must be there when using getline(cin, s)
    for (int tt = 1; tt <= T; tt++) {
        // cout << "Case #" << tt << ": ";
        solution();
    }

    return 0;
}


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

int main() {
    int A, B;
    cin >> A >> B;
    int x = -1;
    for (int i = 1; i <= 100000; i++) {
        if (A <= 0.08 * i && 0.08 * i < A + 1 &&
            B <= 0.10 * i && 0.10 * i < B + 1)
        {
            x = i;
            break;
        }
    }
    cout << x << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;
const ll INF=(ll)1e18+10;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }


int main() {
    int N; cin>>N;
    vector<ll> a(N);
    ll total=0ll;
    for (int i = 0; i < N; ++i) {
        cin>>a[i];
        total+=a[i];
    }

    ll ans=(ll)1e18;
    ll tmp=0ll;
    for (int i = 0; i < N; ++i) {
        tmp+=a[i];
        ans=min(ans,abs((total-tmp)-tmp));
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <queue>
#include <cmath>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

typedef long long ll;

using namespace std;

int anc[100000];
int dpt[100000];
int lnd[100000];
int nea[100000];
int chn[100000];
int han[100000];
int n;
int nn;

vector<vector<int> > decend;

void calc(int pos, int depth, int land){
  dpt[pos] = depth;
  lnd[pos] = land;
  if(depth % nn == 0) land = pos;
  REP(i, decend[pos].size())
    calc(decend[pos][i], depth + 1, land);
}

int query(int);

int dfs(int pos, int land){
  int ret;
  if(pos == land)
    ret = query(pos);
  else if(nea[pos] == pos)
    ret = pos;
  else
    ret = dfs(anc[pos], land);
  han[pos] = chn[land];
  return nea[pos] = ret;
}

int query(int pos){
  int land = lnd[pos];
  int ans  = nea[pos];
  if(ans == pos) return pos;
  if(han[pos] < chn[land])
    return dfs(pos, land);
  if(dpt[land] <= dpt[ans])
    return nea[pos] = ans;
  return nea[pos] = query(land);
}

int main(){
  int q;

  while(~scanf("%d%d", &n, &q) && n + q){
    decend = vector<vector<int> >(n);

    REP(i, n){
      nea[i] = 0;
      chn[i] = -1;
      han[i] = -1;
    }

    REP(i, n - 1){
      scanf("%d", &anc[i + 1]);
      anc[i + 1]--;
      decend[anc[i + 1]].push_back(i + 1);
    }

    nn = (int)sqrt(n);
    calc(0, 0, 0);

    ll sum = 0;

    REP(qq, q){
      char buff[2];
      int m;
      // REP(i,n) printf("%d ", query(i)); puts("");

      scanf("%s%d", buff, &m);
      m--;

      if(buff[0] == 'Q'){
        // query
        int ans = query(m) + 1;
        sum += ans;
      }else{
        // marked
        if(nea[m] != m){
          nea[m] = m;
          chn[lnd[m]] = qq;
        }
      }
    }

    printf("%lld\n", sum);
  }

  return 0;
}

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

using namespace std;

const int SIZE = 100005;

bool notPrime[SIZE];

typedef pair<int,int> pii;


int dp[1000006][100];

const int MOD = 1e9+7;

int c(int n, int k){
	if(dp[n][k]!=0)
		return dp[n][k];
	if(k==0 or k==n){
		dp[n][k]=1;
		return 1;
	}
	if(k==1){
		dp[n][k]=n;
		return n;
	}
	dp[n][k] = c(n-1,k) + c(n-1,k-1);
	dp[n][k]%=MOD;
	return dp[n][k];
}

void init(){
	notPrime[1] = true;
	notPrime[0] = true;
	for(int i=2;i<SIZE;i++){
		if(notPrime[i])
			continue;
		for(int j=i+i;j<SIZE;j+=i){
			notPrime[j] = true;
		}
	}
}

int main(){
	init();
	int n,m;
	cin >> n >> m;
	vector<pii> primeFactors;
	for(int i=1;i*i<=m;i++){
		if(m%i==0){
			if(!notPrime[i]){
				int cnt=0;
				while(m%i==0){
					m/=i;
					cnt++;
				}
				primeFactors.push_back(pii(i,cnt));
			}
		}
	}
	if(m!=1)
		primeFactors.push_back(pii(m,1));
	long long ans=1;
	for(int i=0;i<primeFactors.size();i++){
		ans*=c(primeFactors[i].second+n-1,primeFactors[i].second);
		ans%=MOD;
	}
	cout << ans;
	
}

Measured memory_bytes: 45952
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define Nmax 200010
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;

int main() {
	string s;
	cin >> s;
	int cnt=0;
	REP(i,s.length()-1) if(s[i]!=s[i+1]) cnt++;
	cout << cnt << endl;
	return 0;
}

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

int main() {
  int n,x,t;
  cin >> n >> x >> t;
  int times = ceil(n*1.0/x);
  cout << times * t << endl;
  
  return(0);
}

Measured memory_bytes: 3620
#include <stdio.h>

int main(void) {
	int i,n,x;

	scanf("%d",&n);

	for(i=3;i<=n;i++){
		if(i%3==0){
			printf(" %d",i);
		}
		else{
			x=i;
			while(x!=0){
				if(x%10==3){
					printf(" %d",i);
					break;
				}
				x/=10;
			}
		}
	}
	printf("\n");

	return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <vector>
using namespace std;
using uint = unsigned int;
using ull = unsigned long long;

int main(void){
    uint N;
    cin >> N;
    
    string S;
    cin >> S;
    
    bool fin = true;
    while (fin) {
        fin = false;
        for (uint i=0; i<S.length()-1; i++) {
            if (S[i] == S[i+1]) {
                S.erase(i+1, 1);
                fin = true;
                break;
            }
        }
    }
    
    cout << S.length();
}


Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#define MOD (1000000007l)

using namespace std;

int main(void) {
  long H, W, h, w;
  cin >> H >> W >> h >> w;
  cout << (H - h) * (W - w) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
    int h, m, s, S;
    scanf("%d", &S);
    h = S / 3600;
    m = (S % 3600) / 60;
    s = ((S % 3600) % 60) % 60;
     
    printf("%d:%d:%d\n", h, m, s);
    return 0;
}

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

const int N = 1e5 + 5 , M = 5e3+5;

int n , m , t1 , t2 , sol;
int dp[N];
vector<int> adj[N];

int go(int x)
{
    if(dp[x]!=-1)
        return dp[x];
    int ret = 0;
    for(auto u : adj[x])
        ret = max(ret , 1+go(u) );
    return dp[x] = ret;
}


int main()
{
    memset(dp , -1 , sizeof dp);
    cin>>n>>m;
    for(int i = 0;i<m;i++)
    {
        cin>>t1>>t2;
        adj[t1].push_back(t2);
    }
    for(int i = 1;i<=n;i++)
        sol = max(sol , go(i) );
    cout<<sol;
    return 0;
}


Measured memory_bytes: 8192
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(unused_imports)]
#![allow(dead_code)]
use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

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

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

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

#[derive(Debug)]
struct Dp (i64, i64);
impl Dp {
    fn chmin(&mut self) -> &mut Dp {
        if self.0 > self.1 {
            self.0 = self.1;
            self
        } else {
            self
        }
    }
}

fn main() {
    input!{
        N: usize,
        h: [i64; N],
    }
    let mut dp = vec![1_000_000_000; N+1];
    dp[0] = 0;
    for i in 1..N {
        dp[i] = Dp (dp[i], dp[i-1] + (h[i]-h[i-1]).abs()).chmin().0;
        if i > 1 {
            dp[i] = Dp (dp[i], dp[i-2]+(h[i]-h[i-2]).abs()).chmin().0;
        }
    }
    println!("{}", dp[N-1]);
}



Measured memory_bytes: 6396
N,M=map(int,input().split())
AB=[tuple(map(int,input().split())) for _ in range(N)]
AB.sort(key=lambda x:x[0])
money=0
for a,b in AB:
    if b>=M:
        money+=a*M
        break
    money+=a*b
    M-=b
print(money)

Measured memory_bytes: 18116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MOD = 1e9+7;

 
int main(){
    ll N; cin >> N;
    vector<ll> T(N), A(N), V(N);
    for(int i = 0; i < N; i++) cin >> T[i];
    for(int i = 0; i < N; i++) cin >> A[i];
    V[0] = 1;

    if(T[N-1] != A[0]){cout << 0 << endl; return 0;}

    for(int i = 1; i < N; i++){
        if(T[i-1] != T[i]) {
            V[i] = 1;
            if(T[i] > A[i]){ cout << 0 << endl; return 0;}
        }
        else V[i] = T[i];
    }
    V[N-1] = 1;
    for(int i = N-2; i >= 0; i--){
        if(A[i+1] != A[i]) {
            V[i] = 1;
            if(A[i] > T[i]){ cout << 0 << endl; return 0;}
        }
        else { if(V[i] != 1) V[i] = min(V[i], A[i]); } 
    }
    ll ans = 1;
    for(int i = 0; i < N; i++){
        ans *= V[i];
        ans%= MOD;
    }
    cout << ans << endl;


}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e9;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,x[105];
    cin >> n;
    rep(i,n) cin >> x[i];
    int ans = INF;
    int c;
    rep(i,1,101){
        c = 0;
        rep(j,n){
            c += (x[j]-i)*(x[j]-i);
        }
        chmin(ans,c);
    }
    PRINT(ans);
}

Measured memory_bytes: 256
import Data.Ratio

main :: IO ()
main = do
  [a, b, c, d] <- map read . words <$> getLine
  print $ solve a b c d

-- |
-- >>> solve 4 9 2 3
-- 2
-- >>> solve 10 40 6 8
-- 23
-- >>> solve 314159265358979323 846264338327950288 419716939 937510582
-- 532105071133627368
solve :: Integer -> Integer -> Integer -> Integer -> Integer
solve a b c d = n - nc - nd + ncd
  where
    n   = b - a + 1
    nc  = floor (b % c) - ceiling (a % c) + 1
    nd  = floor (b % d) - ceiling (a % d) + 1
    ncd = floor (b % (c `lcm` d)) - ceiling (a % (c `lcm` d)) + 1


Measured memory_bytes: 508
import java.util.*;

class Main{
    void solve(){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        System.out.println(n % 1000 != 0 ? 1000 - n % 1000 : 0);
        scan.close();
    }
    
    public static void main(String[] args){
        new Main().solve();
    }
}


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

int main() {
    int n;
    float m;
    cin >> n >> m;
    float a[n];
    rep(i, n) cin >> a[i];

    float sum = 0.0, cnt = 0;
    rep(i, n) sum += a[i];
    rep(i, n) if (a[i] >= sum / (4.0 * m)) cnt++;

    if (cnt >= m)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}


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

using namespace std;

int main(void) {
  int A, B; cin >> A >> B;

  for (int i = 0; i <= 1010; i++) {
    int a, b;
    a = (i * 108) / 100 - i;
    b = (i * 110) / 100 - i;
    if (a == A && b == B) {
      cout << i << endl;
      return 0;
    }
  }

  cout << -1 << endl;

  return 0;
}

Measured memory_bytes: 256
S = input()
N = len(S)

def check_kaibun(string):
    rev_string = string[::-1]
    check_len = int(len(string) / 2)
    i = 0
    while i <= check_len:
        if string[i] != rev_string[i]:
            return False
        i += 1
    return True

if all([check_kaibun(S[0:int((N -1) / 2)]), check_kaibun(S[int((N+3) / 2 -
    1):]), check_kaibun(S)]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main(){
  int n;
  cin >> n;
  if(n%1000==0){
    cout << 0 << endl;
  }
  else{
    cout << (n/1000+1)*1000 - n << endl;
  }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
const int kou[]={1,5,10,50,100,500};
int dp[7][700000];
int main(){
	while(true){
		int p;	cin>>p;
		if(p==0)	return 0;
		vector<int> n(6);
		for(int i=0;i<6;i++){
			cin>>n[i];
		}
		for(int i=0;i<7;i++){
			dp[i][0]=0;
			for(int j=1;j<700000;j++)	dp[i][j]=1<<25;
		}
		int end=0;
		for(int i=0;i<6;i++){
			end+=n[i]*kou[i];
			for(int a=0;a<kou[i];a++){
				deque<pair<int,int>> dq;//値、インデックス
				for(int j=0;j*kou[i]+a<=end;j++){
					int val=dp[i][j*kou[i]+a]-j;
					while(!dq.empty()&&dq.back().first>=val)	dq.pop_back();
					dq.push_back(make_pair(val,j));
					dp[i+1][j*kou[i]+a]=dq.front().first+j;
					while(!dq.empty()&&j-dq.front().second>=n[i])	dq.pop_front();
				}
			}
		}
		int ans=INT_MAX;
		for(int i=p;i<=end;i++){
			int tmp=dp[6][i],v=i-p;
			int tmp2=0;
			for(int j=5;j>=0;j--){
				tmp2+=v/kou[j];	v%=kou[j];
			}
			ans=min(ans,tmp+tmp2);
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 22200
#include <stdio.h>

int A[1000000], n;

int binarySearch(int key) {
	int left = 0;
	int right = n;
	int mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (key == A[mid])return 1;
		if (key > A[mid])left = mid + 1;
		else if (key < A[mid])right = mid;
	}
	return 0;
}

int main() {
	int i, k, q, sum = 0;

	scanf("%d", &n);
	for (i = 0; i < n; i++) scanf("%d", &A[i]);

	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		scanf("%d", &k);
		if (binarySearch(k)) sum++;
	}
	printf("%d\n", sum);

	return 0;
}


Measured memory_bytes: 2108
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
//#define int long long
#define MAX_N (100001)
typedef long long ll;

using namespace std;



signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	bool ans = false;
	string s; cin >> s;
	if (s[0] == s[1] && s[1] == s[2]) cout << "No" << endl;
	else cout << "Yes" << endl;

}

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

def devisor(n):
	devs = []
	for i in range(1,n+1):
		if i**2 > n:
			break
		if n % i == 0:
			devs.append(i)
			if i != n // i:
				devs.append(n//i)
	return devs

cnt = 0
for i in range(1,n+1):
	if i % 2 == 0:
		continue
	ndevs = len(devisor(i))
	if ndevs == 8:
		cnt += 1

print(cnt)



Measured memory_bytes: 3060
a, b, c, d, e, f = [int(v) for v in input().split()]

water = set()
for i in range(0, f + 1, 100 * a):
    for j in range(0, f - a + 1, 100 * b):
        water.add(i + j)

sugar = set()
for i in range(0, f + 1, c):
    for j in range(0, f - c + 1, d):
        sugar.add(i + j)

max_r = -1
max_sw = -1
max_s = -1
for w in water:
    for s in sugar:
        if 0 < w + s <= f and s <= w * e // 100:
            r = s / (w + s)
            if max_r < r:
                max_r = r
                max_sw = s + w
                max_s = s

print(max_sw, max_s)

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<b;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
#define debug(x) cerr << x << endl
#define Complex complex<double>
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    int x;
    cin >> x;
    ll sum=0;
    for(int a=1;a<=x;a++){
        for(int b=1;b<=x;b++){
            for(int c=1;c<=x;c++){
                ll k=gcd(a,gcd(b,c));
                sum+=k;
            }
        }
    }
    cout << sum;


}

/*



 */



Measured memory_bytes: 3676
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


ll gcd(ll a,ll b){
    if(b == 0){
        return a;
    }else{
        return gcd(b, a%b);
    }
}

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    string s;
    cin>>s;

    vector<ll> alp(26, 0);
    for(ll i=0;i<s.size();++i){
        alp[s[i]-'a']++;
    }
    char letter;
    if(s.size() != 26){
        for(ll i=0;i<26;++i){
            if(alp[i] == 0){
                letter = i+'a';
                cout<<s + letter<<endl;
                return 0;
            }
        }
    }else{
        for(ll i=25;i>=0;--i){
            for(ll j=s[i]+1;j<='z';++j){
                if(alp[j-'a'] == 0){
                    s[i] = j;
                    s = s.substr(0, i+1);
                    cout<<s<<endl;
                    return 0;
                }
            }
            alp[s[i]-'a'] = 0;
        }
    }
    cout<<-1<<endl;

    return 0;
}

Measured memory_bytes: 256
//Digit Number
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        
        int digit[] = new int[200];
        
        int i = 0;
        for(; sc.hasNextInt(); i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int sub = a+b;
            digit[i] = String.valueOf(sub).length();
            //System.out.println("digit="+digit[i]);
        }
        //System.out.println("i="+i);
        for(int j=0; j<i; j++) {
            System.out.println(digit[j]);
        }
    }
}

Measured memory_bytes: 20480
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    vector<pair<ll, int>> shop(n);

    ll a;  
    int b;
    rep(i, n) {
        cin >> a >> b;
        shop[i] = make_pair(a, b);    
    }

    sort(shop.begin(), shop.end());

    ll ans = 0;
    int count = m;
    rep(i, n) {
        if(count <= shop[i].second) {
            ans += shop[i].first * count;
            break;
        }
        else {
            ans += shop[i].first * shop[i].second;
            count -= shop[i].second;
        }
    }

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

Measured memory_bytes: 1792
#include <stdio.h>
int main(void)
{
int a,b,c,d,e,f,g,h,i,j,k;
scanf("%d %d %d %d %d %d %d %d %d %d",&a,&b,&c,&d,&e,&f,&g,&h,&i,&j);
k=a+b+c+d+e+f+g+h+i+j;
printf("%d\n",k);
return 0;
}

Measured memory_bytes: 596
/// Bismillahir Rahmanir Rahim
/* Mohammad Morsalin
   Dept of ICE, NSTU
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define int long long
#define f0(n) for(int i=0;i<n;i++)
#define ms(x) memset(x,0,sizeof(x))
#define ms2d(x,m,n) memset(x, 0, sizeof(x[0][0]) * m * n)
#define uniq(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pi pair<int,int>
#define tc(t) int t;cin>>t;while(t--)
#define bits(n) __builtin_popcount(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define ins insert
#define ALL(v) v.begin(),v.end()
#define highest(x) numeric_limits<x>::max()
#define lowest(x) numeric_limits<x>::min()
#define Inf INFINITY
#define minv(v) *min_element(v.begin(),v.end())
#define maxv(v) *max_element(v.begin(),v.end())
#define fi first
#define se second
#define PI acos(-1)
#define sz(a) (int)a.size();
#define IOS ios::sync_with_stdio(false);
using namespace std;
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const long long MOD = 1000000007;
double sq(double x) {return x*x;}
template<typename T>inline T Bigmod(T base, T power, T MOD){
    T ret=1;
    while(power)
    {
        if(power & 1)ret=(ret*base)%MOD;
        base=(base*base)%MOD;
        power>>=1;
    }
    return ret;
}

bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
signed main()
{
    IOS
    int a,b,c;
    cin>>a>>b>>c;
    set<int>xx;
    xx.insert(a);
    xx.insert(b);
    xx.insert(c);
    if(xx.size()==2){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
    return 0;
}
///Alhamdulillah


Measured memory_bytes: 3656
#include<iostream>
#include<algorithm>
typedef long long ll;
using namespace std;

int main() {
	ll k, a, b;
	cin >> k >> a >> b;
	if (a + 2 >= b) {
		cout << k + 1 << endl;
	}
	else {
		ll ans = a;
		ans += (b-a) * max(ll(0), (k - a + 1) / 2);
		if ((k - a + 1) % 2 == 1) ans++;
        cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;

int main(){
  int n;
  cin >> n;
  int ans = 0;
  rep(i, n){
    int a;
    cin >> a;
    if (i % 2 == 0 && a % 2 == 1) ans++;
  }
  cout << ans << endl;
  
  return 0;
}

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

struct UnionFind{
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main(void){
    int N, M;
    cin >> N >> M;
    UnionFind uf(N);
    bool isroot[N];
    for(int i = 0; i < N; i++) isroot[i] = false;
    for(int i = 0; i < M; i++){
        int X, Y , Z;
        cin >> X >> Y >> Z;
        uf.merge(X - 1, Y - 1);
    }
    
    int ans = 0;
    
    for(int i = 0; i < N; i++){
        isroot[uf.root(i)] = true;
    }
    
    for(int i = 0; i < N; i++){
        if(isroot[i]) ans++;
    }
    
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 768
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define files(name) name!=""?freopen(name".in","r",stdin),freopen(name".out","w",stdout):0
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define elif else if
#define mp make_pair
#define pb push_back
#define fir first
#define sec second

using namespace std;
#define int long long

typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long double ld;
typedef long long ll;

const int arr=2e5+10;
const int ar=2e3+10;
const ld pi=acos(-1);
const ld eps=1e-10;
const ll md=1e9+7;
const ll inf=1e18+10;

///---program start---///

main()
{
    #ifdef Barik
        files("barik");
        freopen("debug.txt","w",stderr);
    #endif

    int a[3];
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    if (a[0]%2==0||a[1]%2==0||a[2]%2==0){
        cout<<0<<"\n";
    }
    else{
        cout<<a[0]*a[1]<<"\n";
    }
}


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

int main() {
  string s, q, p;
  int n, a, b;
  cin >> s >> n;
  while (n--) {
    cin >> q;
    if (q == "replace") {
      cin >> a >> b >> p;
      s = s.substr(0, a) + p + s.substr(b + 1);
    } else if (q == "reverse") {
      cin >> a >> b;
      reverse(s.begin() + a, s.begin() + b + 1);
    } else {
      cin >> a >> b;
      cout << s.substr(a, b - a + 1) << "\n";
    }
  }
}


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

int main(){
    int m,k;
    cin >> m >> k;
    if (k >= pow(2, m) || (m == 1 && k == 1)){
        cout << -1 << endl;
        exit(0);
    }
    else if (m == 1 && k == 0){
        cout << "1 1 0 0" << endl;
    }
    else{
        for (int i = 0; i < pow(2, m); i++){
            if (i != k) cout << i << " ";
        }
        cout << k << " ";
        for (int i = pow(2, m) - 1; i >= 0; i--){
            if (i != k) cout << i << " ";
        }
        cout << k << endl;
    }
}




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

int main()
{
  int n;
  int i;
  double x1, x2, x3, y1, y2, y3, px, py, r;

  scanf("%d", &n);

  for(i = 0; i < n; i++){

    scanf("%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);

    px = ((y2 - y3)*(x1*x1 + y1*y1) + (y3 - y1)*(x2*x2 + y2*y2) + (y1 - y2)*(x3*x3 + y3*y3))/(2*(x1*(y2 - y3) + x2*(y3 - y1) + x3*(y1 - y2)));
    py = ((x2 - x3)*(x1*x1 + y1*y1) + (x3 - x1)*(x2*x2 + y2*y2) + (x1 - x2)*(x3*x3 + y3*y3))/(2*(y1*(x2 - x3) + y2*(x3 - x1) + y3*(x1 - x2)));

    r = sqrt(pow((x1 - px), 2) + pow((y1 - py), 2));

    printf("%.3f %.3f %.3f\n", px, py, r);
  }

  return 0;
}

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

const int maxn=1e5 ;

int vis[maxn],dp[maxn] ;

int dfs(vector<vector<int>> &adj,int v)
{
	if(vis[v])
		return dp[v] ;

	vis[v]=1 ;

	int best=0 ;

	for(auto x:adj[v]){
		best=max(best,dfs(adj,x)+1) ;
	} 

	dp[v]=best ;

	return dp[v] ;

}


void solve(){
	
	int v,e ;
	cin>>v>>e ;

	vector<vector<int>> adj(v+1) ;

	for(int i=0;i<e;i++){

		int v1,v2 ;
		cin>>v1>>v2; 

		adj[v1].push_back(v2) ;

	} 

	memset(vis,0,sizeof(vis)) ;
	memset(dp,0,sizeof(dp)) ;

	int best=0 ;

	for(int i=1;i<=v;i++){
		best=max(best,dfs(adj,i)) ;
	}
	
	cout<<best ;
}	

int main(){

	
	int y ;

	y=1 ;
	//cin>>y ;

	while(y--)
	{	
		solve() ;
	}

}

Measured memory_bytes: 11336
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<set>
using namespace std;
//#define int long long
typedef pair<int, int> pii;
typedef priority_queue<pii, vector<pii>, greater<pii> > RPQ;
#define mk make_pair
#define INF (1 << 30)
#define INFL (1ll << 60ll)
#define mod 1000000007

int N, a[1010];

signed main(){
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        cout << a[i] << ((i == N - 1) ? '\n' : ' ');
    }
    for(int i = 1; i < N; i++){
        int v = a[i];
        int j = i - 1;
        while(j >= 0){
            if(a[j] <= v)break;
            a[j + 1] = a[j];
            j--;
        }
        a[j + 1] = v;
        for(j = 0; j < N; j++){
            cout << a[j] << ((j == N - 1) ? '\n' : ' ');
        }
    }


    return 0;
}

/*

*/


Measured memory_bytes: 3084
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define for(i,n) for(int i=0;i<n;i++)
#define test(t) int t;cin>>t;while(t--)
#define ll long long
#define mod 1000000007
int main()
{
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])
        cout<<"Yes";
    else
        cout<<"No";
}




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

#define ll long long int
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define sep(i,b,a) for(ll i=b-1;i>=a;i--)
#define hell (ll)(1e9+7)

using namespace std;

void solve()
{
    ll n;
    cin>>n;
    vector < vector <ll> > a(3,vector <ll> (n,0)),dp;
    dp=a;
    rep(i,0,n)
    {
        ll x,y,z;
        cin>>x>>y>>z;
        a[0][i]=x;
        a[1][i]=y;
        a[2][i]=z;
    }

    dp[0][0]=a[0][0];
    dp[1][0]=a[1][0];
    dp[2][0]=a[2][0];
    rep(i,1,n)
    {
        dp[0][i]=a[0][i]+max(dp[1][i-1],dp[2][i-1]);
        dp[1][i]=a[1][i]+max(dp[0][i-1],dp[2][i-1]);
        dp[2][i]=a[2][i]+max(dp[0][i-1],dp[1][i-1]);
    }
    cout<<max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]))<<"\n";
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 4976