akhauriyash/Code-Regression huggingface dataset:
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;
const int maxn=2e5+50;
int n,k; char T[maxn];
vector<int> a[maxn];
namespace seg {
	const int maxnode=maxn<<2;
	int sum[maxnode][2];
	bool rev[maxnode];
	inline void rever(int u) {
		rev[u]^=1;
		swap(sum[u][0],sum[u][1]);
	}
	inline void pushdown(int u) {
		if(rev[u]) {
			rever(u<<1);
			rever(u<<1|1);
			rev[u]=0;
		}
	}
	inline void pushup(int u) {
		sum[u][0]=sum[u<<1][0]+sum[u<<1|1][0];
		sum[u][1]=sum[u<<1][1]+sum[u<<1|1][1]; 
	}
	void build(int u,int l,int r) {
		if(l==r) {
			sum[u][l&1]=T[l]-'0';
			return;
		}
		int mid=(l+r)>>1;
		build(u<<1,l,mid);
		build(u<<1|1,mid+1,r);
		pushup(u);
	}
	void update(int u,int l,int r,int qp) {
		if(l==r) {
			sum[u][0]=sum[u][1]=0;
			return;
		}
		pushdown(u);
		int mid=(l+r)>>1;
		if(qp<=mid) update(u<<1,l,mid,qp);
		else update(u<<1|1,mid+1,r,qp);
		pushup(u);
	}
	void update(int u,int l,int r,int ql,int qr) {
		if(l==ql&&r==qr) {
			rever(u);
			return;
		}
		pushdown(u);
		int mid=(l+r)>>1;
		if(qr<=mid) update(u<<1,l,mid,ql,qr);
		else if(ql>mid) update(u<<1|1,mid+1,r,ql,qr);
		else {
			update(u<<1,l,mid,ql,mid);
			update(u<<1|1,mid+1,r,mid+1,qr);
		}
		pushup(u);
	}
}
int main() {
	scanf("%s",T+1),n=strlen(T+1);
	for(int i=1;i<=n;++i) {
		if(T[i]=='0') a[k].push_back(i);
		else {
			if(T[i+1]=='1') {++i; continue;}
			++k;
		}
	}
	if(a[k].size()) ++k;
	vector<int> ord;
	for(int i=0;i<k;++i) {
		for(int j=bool(i);j<a[i].size();++j) ord.push_back(a[i][j]);
	}
	for(int i=k-1;i>0;--i) {
		ord.push_back(a[i][0]);
	}
	for(int i=1;i<=n;++i) if(T[i]=='1') ord.push_back(i);
	seg::build(1,1,n);
	ll an=0;
	for(int i=0;i<ord.size();++i) {
		int x=ord[i];
		an+=seg::sum[1][1];
		seg::update(1,1,n,x);
		seg::update(1,1,n,x,n);
	}
	printf("%lld\n",an);
	return 0;
}

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

int main() {
    long N, Y, num=999999999, temp1, temp2, ans=99999999999, a, r, b=0;
    cin >> N >> Y;
    vector <long> x(N);
    vector <long> d;
    
    for(int i = 0; i < N; i++) cin >> x.at(i);
    sort(x.begin(),x.end(),greater<long>());
    
    for(int i = 0; i < x.size(); i++){
        temp1 = abs(Y - x.at(i));
        if(temp1 < num) num = temp1;
    }
    
    if(x.size() > 1){
        for(int i = 1; i < x.size(); i++){
            d.push_back(x.at(i-1)-x.at(i));
        }
    }else d.push_back(x.at(0)-Y);
    
    sort(d.begin(), d.end());

     for(int i = 0; i < d.size(); i++){
     }
    for(int i = 0; i < d.size(); i++){
        a = num; b = d.at(i);
        if(a > b){
            temp2 = a;
            a = b;
            b = temp2;
        }
        r = a % b;
        while(r!=0){
            a = b;
            b = r;
            r = a % b;
        }if(ans > b) ans = b;
    }
    cout << ans << endl;
}




Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
long long int pw(long long int n)
{
    return n*n*n*n*n*1ll;
}
int main()
{
long long int x,a,b;
cin>>x;

long long int i,j;
int flag=0;
for(i=-1000;i<1000;i++)
{
  for(j=-1000;j<1000;j++)
  {
    a=pw(i);
    b=pw(j);
    
    if((a-b)==x)
    {
      flag=1;
      break;
    }
  }
  
  if(flag==1)
  break; 
}

cout<<i<<" "<<j<<endl;
return 0;
}


Measured memory_bytes: 3612
H,W=map(int,input().split())
a=["" for i in range(H)]
for i in range(H):
    a[i]=list(str(input()))

for s in range(-1,H+1):
    for t in range(-1,W+1):           
        if s==-1 or s==H:
            print("#"*(W+2))
            break
        else:
            if t==-1:
                print("#",end="")
            elif t==W:
                print("#")
            else:
                print(a[s][t],end="")

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

int main(void){
  int N;
  cin>>N;
  int count=0;
  int p;
  for(int i=0;i<N;i++){
    cin>>p;
    if(p!=i+1){
      count++;
    }
  }
  if(count==2 or count ==0){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
using ll = long long;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

int main() {
    long long a,b;
    cin >> a >> b;
    long long d = 0;
    cin >> d;
    cout << min(a * b, d) << endl;
}

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

const int MAX = 2e5+5;
int N, A[MAX];
int main() {
        scanf("%d", &N);
        for (int i=0; i<N; ++i)
                scanf("%d", &A[i]);

        int h = 0;
        long long ans = 0;
        for (int i=N-1; i>=0; --i) {
                if (A[i] < h || A[i] > i) {
                        printf("-1\n");
                        return 0;
                }
                else if (A[i] > h) {
                        h = A[i];
                        ans += A[i];
                }
                h--;
        }

        printf("%lld\n", ans);
        return 0;

}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

int main() {
  int n;
  cin >> n;
  string s = to_string(n);
  int sn = 0;
  rep (i, s.size()) {
    sn += s[i] - '0';
  }
  if (n % sn == 0) Yes;
  else No;
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e5 + 5;

int32_t main()
{
	IOS;
	int h1, m1, h2, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	int cnt = (h2 * 60 + m2) - (h1 * 60 + m1);
	int ans = cnt - k;
	ans = max(ans, 0LL);
	cout << ans;
	return 0;
}

Measured memory_bytes: 3652
#include<stdio.h>
int main(void)
{
	int x,y,a[]={1,3,5,7,8,10,12},cnt,i;
	scanf("%d%d",&x,&y);
	cnt=0;
	for(i=0;i<7;i++){
		if(a[i]==x||a[i]==y) cnt++;
	}
	if(x==2||y==2) printf("No\n");
	else if(cnt==2||cnt==0){
		printf("Yes\n");
	}
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,i,j,z=0,y=0,x=0,ma=0,mi=0x3f3f3f3f;
	char s[200005];
	int a[105],b[105]={0},c,d,flag=0;
	scanf("%d%d",&x,&n);
	if(n==0)
	printf("%d\n",x);
	else
	{
		for(i=0;i<n;i++)
	    {
		scanf("%d",&a[i]);
		b[a[i]]=1;
	    }
	    for(i=0;i<=101;i++)
	    {
	    	if(b[i]==1)
	    	continue;
	    	else
	    	{
	    		if(abs(x-i)<mi)
	    		{
	    			mi=abs(x-i);
	    			y=i;
				}
			}
		}
		printf("%d\n",y);
	}

	
} 

Measured memory_bytes: 3824
#include <bits/stdc++.h>
  #define int long long int
  #define vi vector<int>
  #define pii pair<long long ,long long>
  #define pll pair<int,int>
  #define mod 1000000007
  #define all(x) x.begin(),x.end()
  #define mp(x,y) make_pair(x,y)
  #define mem(a,val) memset(a,val,sizeof(a))
  #define eb push_back
  #define ff first
  #define ss second
  #define rep(n) for(int i=0;i<n;i++)
  #define lb lower_bound
  #define up upper_bound
   
  
  using namespace std;
  int dp[100005][105];
  int v[100005];
  int a[100005];
  void solve()
  { 

      int n,w;
      cin>>n>>w;
      for(int i=1;i<=n;i++)
         cin>>a[i]>>v[i];
  for(int i=1;i<=100000;i++)
      {
         for(int j=1;j<=n;j++)

           {
              dp[i][j]=1e10;

           }
           dp[i][0]=1e10;

      }
   
      for(int i=1;i<=100000;i++)
      {
         for(int j=1;j<=n;j++)
           {
              if(i-v[j]>=0)
              dp[i][j]=min(dp[i][j-1],dp[i-v[j]][j-1]+a[j]);
            else
              dp[i][j]=dp[i][j-1];
              
           }
      }
      int ans=0;
      
      for(int i=1;i<=100000;i++)
      {
         for(int j=1;j<=n;j++)

           {
              if(dp[i][j]<=w)
              {
                 ans=i;
              }
           }
      }
      cout<<ans;

    
    


   
   }

  signed main()
  {
   /* #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int T;
    T=1;
    
    while(T--)
    {
      solve();
    }
    return 0;
  }


Measured memory_bytes: 82304
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
int main()
{
  ll N;
  cin>>N;
  string S;
  cin>>S;
  ll ans=0;
  ll ansb;
  rep(i,N){
    if(i>=1){
      if(S.at(i)=='E')ans++;
    }
  }
  ansb=ans;
  rep(i,N){
    if(i>=1){
      if(S.at(i-1)=='E')ansb--;
      if(S.at(i)=='W')ansb++;
    }
    ans=min(ansb,ans);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int x,a,b;
  cin >> x >> a >> b;

  cout << (x-a)%b << endl;
  return 0;
}


Measured memory_bytes: 256
int main(int argc ,const char *argv[])
{
    int n,m,a[100][100],c[100],b;
    //input
    scanf("%d %d",&n,&m);
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            scanf("%d",&a[i][j]);
        }
    }
    for(int i=0;i<m;i++){
        c[i]=0;
    }
    for(int i=0;i<m;i++){
        scanf("%d",&b);
        for(int j=0;j<n;j++){
            c[j]+=a[j][i]*b;
        }
    }
    for(int i=0;i<n;i++){
        printf("%d\n",c[i]);
    }
    return 0;
}


Measured memory_bytes: 2128
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        h: usize,
        w: usize,
        k: i32,
        ccc: [Chars; h]
    };
    let mut ok = 0;
    for row_size in 0..h {
        for row_indexes in (0..h).combinations(row_size) {
            for col_size in 0..w {
                for col_indexes in (0..w).combinations(col_size) {
                    let mut count = 0;
                    for row in 0..h {
                        for col in 0..w {
                            if !row_indexes.contains(&row)
                                && !col_indexes.contains(&col)
                                && (ccc[row][col] == '#')
                            {
                                count += 1;
                            }
                        }
                    }
                    if count == k {
                        ok += 1;
                    }
                }
            }
        }
    }
    println!("{}", ok);
}


Measured memory_bytes: 2172
#include<bits/stdc++.h>
using namespace std;
int n;
struct node{
    int id,ord;
    bool operator <(const node a)const{
        return ord<a.ord;
    }
}a[100010];
int main(){
    cin>>n;
    for(int i=1;i<=n;++i){
        cin>>a[i].ord;
        a[i].id=i;
    }
    sort(a+1,a+n+1);
    for(int i=1;i<=n;++i)
        cout<<a[i].id<<" ";
    cout<<endl;
}


Measured memory_bytes: 1536
#include <cstdio>

const int p=1000000007;

int f[320][320][320];
int ord1[320],ord2[320],next[320],first[320];
int i,j,k,m,n,s,x,y,z,sum_edge;

inline void addedge(int x,int y,int z)
{
	sum_edge++,ord1[sum_edge]=y,ord2[sum_edge]=z,next[sum_edge]=first[x],first[x]=sum_edge;
	return;
}

inline bool check(int x,int y,int z)
{
	for (int i=first[z];i!=0;i=next[i])
	{
		if ((ord2[i]==1) && (ord1[i]<=y)) return false;
		if ((ord2[i]==2) && ((ord1[i]>y) || (ord1[i]<=x))) return false;
		if ((ord2[i]==3) && (ord1[i]>x)) return false;
	}
	return true;
}

int main()
{
	scanf("%d%d",&n,&m);
	for (i=1;i<=m;i++)
		scanf("%d%d%d",&x,&y,&z),addedge(y,x,z);
	f[0][0][0]=1;
	for (i=0;i<=n;i++)
		for (j=0;j<=i;j++)
			for (k=j;k<=i;k++)
				if (f[i][j][k])
				{
					if (! check(j,k,i)) f[i][j][k]=0;
					f[i+1][j][i]=(f[i+1][j][i]+f[i][j][k])%p;
					f[i+1][k][i]=(f[i+1][k][i]+f[i][j][k])%p;
					f[i+1][j][k]=(f[i+1][j][k]+f[i][j][k])%p;
				}
	for (j=0;j<=n;j++)
		for (k=j;k<=n;k++)
			s=(s+f[n][j][k])%p;
	printf("%d",s);
	return 0;
}

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

using namespace std;
#define rep(i, n) for(int i = 0 ; i < (int)(n) ; i++)
typedef long long ll;
typedef long double Double;

#ifndef INPUTS_DIR
#define INPUTS_DIR "./"
#endif


vector<int> g[100010];
bool dead[100010];
vector<int> ans;
vector<int> trail;


void output() {
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] + 1 << " ";
    }
    cout << endl;
    exit(0);
}

bool escape;

void dfs(int x) {
    trail.push_back(x);
    dead[x] = true;
    bool trans = 0;
//    cout << x << ": ";
//    for (int i : trail) cout << i << " ";
//    cout << endl;
    for (auto i : g[x]) {
        if (!dead[i]) {
            dfs(i);
            if (escape) return;
            trans = 1;
        }
    }

    if (!trans) {
        if (ans.size() == 0) {
            ans = trail;
            reverse(ans.begin(), ans.end());
            escape = true;
//            cout << "escape" << endl;
            return;
        } else {
            for (int i = 1; i < trail.size(); i++) {
                ans.push_back(trail[i]);
            }
            output();
        }
    }
    trail.pop_back();
}


void solve(ll N, ll M, vector<ll> A, vector<ll> B) {
    for (int i = 0; i < A.size(); i++) {
        g[A[i] - 1].push_back(B[i] - 1);
        g[B[i] - 1].push_back(A[i] - 1);
    }
    dfs(0);
    escape = false;
    trail.clear();
    dfs(0);
    output();

}


void main_(istream &cin) {
    ll M;
    ll N;
    cin >> N;
    cin >> M;
    vector<ll> A(M - 1 + 1);
    vector<ll> B(M - 1 + 1);
    for (int i = 0; i <= M - 1; i++) {
        cin >> A[i];
        cin >> B[i];
    }
    solve(N, M, A, B);
}

int main() {
#ifdef INTELLIJ
    ifstream ifs(string(INPUTS_DIR) + "in_1.txt");
    if (ifs.is_open()) {
        main_(ifs);
        ifs.close();
    } else {
        cerr << "Error: no input." << endl;
    }
#else
    ios::sync_with_stdio(false);
    cin.tie(0);
    main_(cin);
#endif
}





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

using namespace std;

int main() {
    int n, j = 1, b, count = 0;
    cin >> n;
    for (int i=0; i<n; ++i) {
        cin >> b;
        if (b == j) ++j;
        else ++count;
    }
    if (j==1) cout << -1;
    else cout << count;
}


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

double distance(double x1, double y1, double x2, double y2)
{
    return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
}

int main()
{
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << fixed << setprecision(4) << distance(x1, y1, x2, y2) << endl;
    return 0;
}

Measured memory_bytes: 3288
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>

using namespace std;
typedef long long ll;
const int maxn = 1005;

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int x, y, z, k;
  vector<ll> a, b, c;
  cin >> x >> y >> z >> k;
  for (int i = 0; i < x; i++) {
    ll tt;
    cin >> tt;
    a.push_back(tt);
  }
  for (int i = 0; i < y; i++) {
    ll tt;
    cin >> tt;
    b.push_back(tt);
  }
  for (int i = 0; i < z; i++) {
    ll tt;
    cin >> tt;
    c.push_back(tt);
  }
  vector<ll> d;

  for (int i = 0; i < x; i++)
    for (int j = 0; j < y; j++)
      d.push_back(a[i] + b[j]);
  sort(c.begin(), c.end());
  sort(d.begin(), d.end());
  ll l = 3L, r = 30000000000L;
  ll ret = -1;
  while (l <= r) {
    ll m = (l + r) >> 1;
    ll cnt = 0;
    int rr = d.size();
    for (int i = 0; i < c.size(); i++) {
      while (rr - 1 >= 0 && d[rr - 1] + c[i] >= m) {
        rr--;
      }
      cnt += d.size() - rr;
    }
    if (cnt >= k) {
      ret = m;
      //cout<<ret<<" "<<cnt<<endl;
      l = m + 1;
    } else r = m - 1;
  }
  vector<ll>ans;
  for(int i=0;i<c.size();i++){
    for(int j=d.size()-1;j>=0;j--){
      if(c[i]+d[j]<=ret){
        break;
      }
      ans.push_back(c[i]+d[j]);
    }
  }
  sort(ans.begin(),ans.end());
  for(int i=ans.size()-1;i>=0;i--)cout<<ans[i]<<endl;
  for(int i=0;i<k-ans.size();i++)cout<<ret<<endl;
  return 0;
}

Measured memory_bytes: 10672
#include <iostream>
#include <array>
using namespace std;
int main()
{
    array<int,3> v;
    scanf("%d %d %d",&v[0],&v[1],&v[2]);
    if((v[2]+v[1]*10)%4==0){
        printf("YES\n");
    }else{
        printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

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 result = 0;
		for(int i = 1; i < n+1; i++){
		    int temp = 0;
		    String s = Integer.toString(i);
		    for(int j = 0; j < s.length(); j++){
		        temp += s.charAt(j) - '0';
		    }
		    if(a <= temp && temp <= b) result += i;
		}
		
		// 出力
		System.out.println(result);
	}
}



Measured memory_bytes: 21972
#include<iostream>
#include<algorithm>
using namespace std;
int dp[10][1<<10][331], n; //nの制約は自明だけど sはどれくら(ry ← 331か
int rec( int now, int used,int sum){
  if( sum < 0 ) return 0;
  if( now == n ) return sum == 0;
  if(~dp[now][used][sum]) return dp[now][used][sum];
  int ret = 0;
  for(int i = 0 ; i < 10 ; i++ ){
    if((used >> i) & 1)
      ret += rec( now + 1, used&~(1 << i), sum - i * (now + 1));
  }
  return dp[now][used][sum] = ret;
}
int main(){
  int s;
  while(cin >> n >> s){
    fill_n( **dp, 10 * (1 << 10) * 331, -1);
    cout << rec( 0, (1 << 10) - 1, s) << endl;
  }
}

Measured memory_bytes: 14396
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

k = int(input())
result = 0
for x in range(1,k+1):
    for y in range(1,k+1):
        for z in range(1,k+1):
            result += gcd(x,y,z)
print(result)


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

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

    string s,t;
    int c = 0;
    cin >> s >> t;
    for(int i=0;i<s.length();i++) if(s[i]!=t[i]) c++;
    cout << c;
    
    return 0;
}

Measured memory_bytes: 3800
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define md 1000000007
#define ld long double
#define pi 3.14159265359
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long long n, i = 0, j= 0, k = 0, l = 0, m = 0, a = 0, b = 0, sum = 0, x = 0, y = 0, z = 0, c, p;
    cin >> n;
    while(n % 2 == 0){
        x++;
        n /= 2;
    }
    //cout << x << endl;
    i = 1;
    while(x-i >= 0){
        sum++;
        x -= i;
        i++;
    }
    //cout << sum << endl;
    for(i = 3; i*i <= n; i = i+2){
        x = 0;
        while(n % i == 0){
            x++;
            n /= i;
        }
        j = 1;
        while(x-j >= 0){
            sum++;
            x -= j;
            j++;
        }
    }
    if(n > 2){
        sum++;
    }
    cout << sum;

    return 0;
}


Measured memory_bytes: 3652
#include<stdio.h>
#define N 100
#define W 100000

long long max(long long int a, long long int b);

long long int dp[N+1][W+1]={0};

int main(void){
	int i;
	int j;
	int w_knap;
	int w[N+1];
	long long int v[N+1];
	int n;
	scanf("%d %d", &n, &w_knap);
	w[0]=0;
	v[0]=0;
	for(i=1;i<n+1;i++){
		scanf("%d %lld", &w[i], &v[i]);
	}
	for(i=1;i<n+1;i++){
		for(j=0;j<w_knap+1;j++){
			if((j-w[i])>=0){
				dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
			}else{
				dp[i][j]=dp[i-1][j];
			}
		}
	}
	printf("%lld",dp[n][w_knap]);
	return 0;
}

long long int max(long long int a, long long int b){
	long long int ret;
	if(a>=b){
		ret=a;
	}else{
		ret=b;
	}
	return ret;
}

Measured memory_bytes: 78336
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)

using namespace std;
typedef long long ll;

// dinic, adj-list
struct Edge { int dst, opp; ll cap; bool rev; };
const ll INF = 1000000000000000000LL;
const int N = 5000;
int dist[N], iter[N], q[N];
vector<Edge> g[N];
inline void init(int n) {
  REP(i, n)
    g[i].clear();
}
inline void addEdge(int a, int b, ll cap) {
  g[a].push_back((Edge){b, int(g[b].size()), cap, false});
  g[b].push_back((Edge){a, int(g[a].size())-1, 0, true});
}
bool bfs(int s, int t) {
  int bg = 0, ed = 0;
  memset(dist, -1, sizeof dist);
  for(dist[q[ed++]=t] = 0; bg < ed; iter[q[bg++]] = 0)
    FOR(e, g[q[bg]])
      if(dist[e->dst] < 0 && g[e->dst][e->opp].cap > 0)
        dist[q[ed++]=e->dst] = dist[q[bg]] + 1;
  return dist[s] >= 0;
}
ll go(int cur, int t, ll amount) {
  if(cur == t) return amount;
  for(int& i = iter[cur]; i < (int)g[cur].size(); ++i){
    Edge& e = g[cur][i];
    if(e.cap > 0 && dist[e.dst] < dist[cur]){
      ll res = go(e.dst, t, min(amount, e.cap));
      if(res > 0){
        e.cap -= res;
        g[e.dst][e.opp].cap += res;
        return res;
      }
    }
  }
  return 0;
}
ll maxFlow(int s, int t) {
  ll res = 0;
  for(; bfs(s, t); )
    for(ll amount; (amount = go(s, t, INF)); res += amount);
  return res;
}

ll as[110];

int main(void) {
  int n;
  scanf("%d", &n);
  REP(i, n) {
    scanf("%lld", &as[i]);
  }
  int s = 0;
  int t = n+1;
  const ll OFFSET = 1000000000;
  const ll INF = 1e14;
  for(int i = 1; i <= n; ++i) {
    addEdge(s, i, OFFSET); // 叩き割る
    addEdge(i, t, OFFSET-as[i-1]); // 残す
    for(int j = i+i; j <= n; j += i) {
      addEdge(j, i, INF);
    }
  }
  ll res = maxFlow(s, t);
  printf("%lld\n", OFFSET*n - res);
  return 0;
}


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

using namespace std;

#define int long long
#define MOD 1000000007


#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b) - 1; i >= (a); i--)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define all(i) (i).begin(),(i).end()
#define rall(i) (i).begin(),(i).end(),greater<int>()


#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T> void print(T x) { std::cout << x << '\n'; }
 
//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

 
signed main(){
 
    int N,M;
    cin >> N >> M;
    int a[N],b[N];

    map<int,int> index;//値段、本数

    rep(i,N){
        cin >>a[i] >> b[i];
        index[a[i]] += b[i];
    }

    int rest = M;

    int money=0;

    for(auto itr:index){
            if(itr.second>rest){
                money += itr.first*rest;
                rest -= rest;
            } 
            else{
                money += itr.first*itr.second;
                rest -= itr.second;
            }

            if(rest==0){
                break;
            }
    }

    cout << money << endl;



    return 0;
 
}


Measured memory_bytes: 8064
N=int(input())
X=list(map(int,input().split()))
p=1
ans1=float('inf')


while True:
  ans2=0
  
  for x in X:
    ans2 += (x-p)**2
   
   
  if ans2 > ans1:
    print(ans1)
    break
   
  ans1=ans2
  p +=1
    
  

Measured memory_bytes: 2940
N = int(input())
h = list(map(int,input().split()))
dp = [0]*N
dp[1] = abs(h[0] - h[1]) 
for i in range(2, N):
    dp[i] = min(dp[i-2] + abs(h[i]-h[i-2]), dp[i-1] + abs(h[i]-h[i-1]))

print(dp[N-1])


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

int n, k;

int main() {
    cin >> n >> k;
    int bridge = (n - 1) * (n - 2) / 2 - k;
    if (bridge < 0) {
        cout << -1 << endl;
    } else {
        cout << n - 1 + bridge << endl;
        //ウニ部分
        for (int i = 1; i < n; i++) {
            cout << 1 << " " << i + 1 << endl;
        }
        //橋部分
        int count = 0;
        for (int i = 1; i < n && count < bridge; i++) {
            for (int j = i + 1; j < n && count < bridge; j++) {
                cout << i + 1 << " " << j + 1 << endl;
                count++;
            }
        }
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<stack> 
#include<queue>
#include<cmath>
#include<map>
#define LL long long
#define N 100100
#define M 1010
#define MOD 1000000007
#define FOR(i,l,r) for (int i = (l); i <= (r); i ++)
#define CLR(a,x) memset(a,x,sizeof(a))
#define INF 0x3f3f3f3f
#define ALL(x) x.begin(),x.end()
#define pb push_back
#define X first
#define Y second
using namespace std;
int t[20],a[N];
int check(int x,int y){
	int res = x * y;
	//cout << res << endl;
	int p = 0;
	while (res){
		t[p ++] = res % 10;
		res /= 10;
	}
	//for (int i = p - 1; i >= 0; i --) printf("%d",t[i]);
	//cout << endl;
	for (int i = p - 1; i >= 1; i --) if (t[i] != t[i - 1] - 1) return 0;
	return 1;
}
int main(){
	int n;
	scanf("%d",&n);
	FOR(i,1,n) scanf("%d",&a[i]);
	int ans = -1;
	for (int i = 1; i < n; i ++) for (int j = i + 1; j <= n; j ++)
	if (check(a[i],a[j]))
		ans = max(ans,a[i] * a[j]);
	cout << ans << endl;
} 

Measured memory_bytes: 3228
#include <iostream>
#include <string>
#include <stdio.h>
#include <algorithm>
using namespace std;

int main() {
  string W, T;
  int count = 0;
  cin >> W;
  transform(W.begin(), W.end(), W.begin(), ::tolower);
  while (1) {
    cin >> T;
    if (T == "END_OF_TEXT") break;
    transform(T.begin(), T.end(), T.begin(), ::tolower);
    if (W == T) count++;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 1192
N = int(input())
A = list(map(int,input().split()))
count = 0
flag = 0
now = 1
for i in range(len(A)):
    if A[i]== now :
        now += 1
    else:
        count += 1
if count == N:
    print("-1")
else:
    print(count)

Measured memory_bytes: 24744
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecb vector<bool>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}
void comb(vector<vector<long long int>> &v)
{
	for (size_t i = 0; i < v.size(); i++)
	{
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (size_t k = 1; k < v.size(); k++)
	{
		for (size_t j = 1; j < k; j++)
		{
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}
ll repeat_squaring(ll n, ll p, ll m)
{
	if (p == 0)
		return 1;
	if (p % 2 == 0)
	{
		ll t = repeat_squaring(n, p / 2, m);
		return t * t % m;
	}
	return n * repeat_squaring(n, p - 1, m);
}

int main()
{
	int n;
	cin >> n;
	veci height(n);
	rep(i, n)
	{
		cin >> height[i];
	}
	int ans = 1, _max = height[0];
	for (size_t i = 1; i < n; i++)
	{
		if (_max <= height[i])
		{
			ans++;
		}
		_max = max(_max, height[i]);
	}
	cout << ans << endl;

	return 0;
}

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

int main() {
    int N,K,A,B;
    cin >> N >> K >> A >> B;
    if(N <= K){
        cout << N * A;
    }else{
        cout << K * A + (N-K) * B;
    }

    return 0;
}

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N;
  cin >> N;
  string S;
  cin >> S;

  int acc = 0, mn = 1e9;
  for(int i=0;i<N;++i){
	acc += (S[i] == '('? 1: -1);
	mini(mn, acc);
  }
  string ans;
  if(mn < 0){
	ans += string(-mn, '(');
	acc += -mn;
  }
  ans += S;
  ans += string(acc, ')');

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
p=10**9+7
suma = [0]*n
suma[0] = 0
for i in range(1,n):
  suma[i] = (suma[i-1] + a[i-1])%p

ans = 0
for i in range(n):
  ans = (ans + ((a[i] % p) * suma[i])%p)%p
print(ans)

Measured memory_bytes: 105324
n = input()
tmp_n = n.split(" ")

h = int(tmp_n[0])
w = int(tmp_n[1])
in_list = []

for i in range(h):
    in_pixel = input()
    in_list.append(in_pixel)

print("#"*(w+2))
for j in in_list:
    print("#"+j+"#")
print("#"*(w+2))


Measured memory_bytes: 3060
#include <iostream>
#include <string>

using namespace std;

int main() {
    int n;
    string a,b,c;
    cin >> n;
    cin >> a;
    cin >> b;
    cin >> c;
    int ans=0;
    
    for(int i=0 ; i<n ; i++){
        if(a[i]==b[i]){
            if(b[i]==c[i]){
                continue;
            }else{
                ans++;
            }
        }else{
            if(b[i]==c[i]){
                ans++;
                continue;
            }else{
                if(a[i]==c[i]){
                    ans++;
                }else{
                    ans=ans+2;
                }
            }
        }
    }
    cout << ans;    
}


Measured memory_bytes: 888
from collections import defaultdict, Counter
from itertools import product, permutations, combinations, accumulate
from bisect import bisect_left, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor


def input_list():
    return list(map(int, input().split()))


def input_int():
    return int(input())


D, T, S = input_list()
if D / S <= T:
    print("Yes")
else:
    print("No")


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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

int M, K;

signed main() {
    cin >> M >> K;
    if (M == 1 && K == 0) {
        cout << "0 0 1 1" << endl;
        return 0;
    }
    if (M == 1 && K == 1 || (1 << M) <= K) {
        cout << -1 << endl;
        return 0;
    }
    for (int i = 0; i < (1 << M); i++)if (i != K)cout << i << " ";
    cout << K << " ";
    for (int i = (1 << M) - 1; i >= 0; i--)if (i != K)cout << i << " ";
    cout << K << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;
typedef pair<P, llint> E;

llint a, b, n;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> a >> b >> n;
	llint x = min(n, b-1);
	cout << (a*x/b)-a*(x/b) << endl;
	
	return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>  /*入出力*/
#include <stdlib.h> /*標準ライブラリ*/
#include <string.h> /*文字列*/
#include <math.h>   /*計算*/
 
/*
ご指導ご鞭撻のほどよろしくお願いいたします。
@oct0pus_G
*/
 
int main(void)
{
  int N, X;
  int L[100] = {0};
  int D = 0;
 
  scanf("%d%d", &N, &X);
  for (size_t i = 0; i < N; i++) {
    scanf("%d", &L[i]);
  }
 
  for (size_t i = 0; i < N; i++) {
    D += L[i];
    if (D > X) {
      printf("%d\n", i+1);
      return 0;
    }
  }
 
  printf("%d\n", N+1);
  return 0;
}

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

using namespace std;
using ll = long long int;
using P = pair<int, int>;

#define loop(i, n) for(int i = 0;i < n;i++)

int main(void){

    string a, b;
    cin >> a >> b;

    b.pop_back();

    if(a == b) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3604
#include <cstdio>
#include <algorithm>
using namespace std;
 
int main() {
  for(int tci = 0;; tci++) {
    int N,M; scanf("%d%d", &N, &M); if(!N) break;
    pair<int,int> *pd = new pair<int,int>[N];
    int ept = 0;
    for(int i = 0; i < N; i++) {
      scanf("%d%d", &pd[i].second, &pd[i].first);
      ept += pd[i].second * pd[i].first;
    }
    sort(pd, pd+N);
    reverse(pd, pd+N);
    int x = M;
    for(int i = 0; i < N && x > 0; i++) {
      ept -= min(pd[i].second, x) * pd[i].first;
      x -= pd[i].second;
    }
    printf("%d\n", ept);
  }
  return 0;
}

Measured memory_bytes: 1756
A=int(input())
B=int(input())
C=int(input())
X=int(input())
count=0
for a in range(A+1):
  for b in range(B+1):
    for c in range(C+1):
      if 500*a+100*b+50*c==X:
        count+=1
print(count)

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

using namespace std;

int main(int argc,char* argv[]){
  int N,p;
  cin >> N;
  p = N/100;
  if(p*111 >= N) cout << p*111 << endl;
  else cout << (p+1)*111 << endl;
  return 0;
}


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  for (int i = 0;; i++) {
    if (i % 2 == 0) {
      c -= b;
    } else {
      a -= d;
    }
    if (a <= 0) {
      cout << "No" << endl;
      break;
    } else if (c <= 0) {
      cout << "Yes" << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 3636
n = int(input())
a = list(map(int, input().split()))
a.sort()
data = [0 for _ in range(1000001)]
for x in a:
    data[x] += 1

ans = 0
for i in range(1,1000001):
    if not data[i]:continue
    if data[i] == 1:ans += 1
    j = i
    while j < 1000001:
        data[j] = 0
        j += i

print(ans)

Measured memory_bytes: 179860
from collections import Counter
N=int(input())
s=[input() for _ in range(N)]
M=int(input())
t=[input() for _ in range(M)]

s1=Counter(s)
t1=Counter(t)
#print(s1,t1)
s1.subtract(t1)
if (s1.most_common()[0][1]<0):
    print("0")
else:
    print(s1.most_common()[0][1])


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;
typedef vector<pii> vpii;
 
#define pb(x) push_back(x)
#define ppb() pop_back()
#define mp(x,y) make_pair(x,y)
#define mod 1000000007
#define FOR0(i,n) for(int i=0;i<n;i++)
#define For(v) for(auto it = v.begin();it!=v.end();it++)
#define FOR(i,a,b) for(int i = a; i < b; i++)
#define FORD(i,a,b) for(int i=(a);i>=(int)(b);i--)
#define sf(n) scanf("%d", &n)
#define sfc(x) scanf("%c", &x)
#define pf(x) printf("%d", x)
#define pff(x) printf("%lf", x)
#define pfc(x) printf("%c", x)
#define pfs(x) printf("%s", x)
#define sf2(a,b) scanf("%d %d", &a, &b)
#define sf3(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pfn(n) printf("%d\n", n)
#define pfs(n) printf("%d ", n)
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define sz size()
#define ll long long
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
bool prime[33554440];
void SieveOfEratosthenes(ll n)
{
    memset(prime,true, sizeof(prime));
 
    for (ll p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (ll i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
}
 
ll power(ll x,ll y)
{
    if (y == 0)
        return 1;
    else if (y%2 == 0)
        return power(x, y/2)*power(x, y/2);
    else
        return x*power(x, y/2)*power(x, y/2);
}
 

ll power1(ll a,ll b){
  ll res=1;
  while(b){
    if(b&1){
      res*=a;
    }
    a=a*a;
    b>>=1;
  }
  return res;
}

bool isPrime(ll n)
{
    if (n <= 1)  return false;
    if (n <= 3)  return true;

    if (n%2 == 0 || n%3 == 0) return false;

    for (ll i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;

    return true;
}
ll divisor(ll number)
    {
        ll i;
        for (i = 2; i <sqrt(number); i++)
        {
            if (number % i == 0)
            {
                break;
            }
        }
        return number/i;
    }
int main(){
  fast 
  ll k,k1,a,b;
  ll bis=1;
  cin>>k>>a>>b;
  k1=k;
  if(k+1<=a)cout<<k+1;
  else{
    ll temp,temp1;
    if(k-1>=a){
      k-=(a-1);
      bis=a;
      //cout<<"11111\n";
      if(b-a>=2){
        temp=k%2;
        temp1=k/2;
        bis=a+temp1*(b-a);
        bis+=temp;
        cout<<bis<<endl;
        //cout<<"yrgui\n";
      }
      else{
        cout<<k1+1;
      }
    }
    else{
      cout<<k1+1;
    }

  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;

vector<int> ans(110000);

int main() {
    int n; cin >> n;
    Rep(x, 1, 100) {
        Rep(y, 1, 100) {
            Rep(z, 1, 100) {
                ans[(x*x)+(y*y)+(z*z)+(x*y)+(y*z)+(z*x)]++;
            }
        }
    }
    Rep(i, 1, n+1) cout << ans[i] << endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
long long cnt(long long h){
	if(h==1){
		return 1;
	}else{
		return 1+2*cnt(h/2);
	}
}
int main(){
	long long h;
	cin >> h;
	cout << cnt(h) << endl;
}

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

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;
 
#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;

int main() {
  
  int n,a;
  cin >> n;
  
  int hantei = 1;
  
  for ( int i = 0; i < n; i++){
    cin >> a;
    if ( a % 2 != 0 ){
      continue;
    }else{
      if ( a % 3 != 0 && a % 5 != 0 ){
      hantei = 0;
      }
    }
  }
  
  if (hantei){
    cout << "APPROVED" << endl;
  }else{
    cout << "DENIED" << endl;
  }
    
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#include<deque>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin >> n;
	string s;
	cin >> s;
	if (s.length() % 2 == 1)return cout << "No" << endl,0;
	for (ll i = 0; i < s.length()/2; i++) {
		if (s[i] != s[i + s.length() / 2])return cout << "No" << endl, 0;
	}
	cout << "Yes" << endl;
}



Measured memory_bytes: 256
import sys


def val(l, r, d, Vs):
    jewels = Vs[:l] + list(reversed(Vs))[:r]
    return sum(sorted(jewels)[d:])

def cond(l, r, d, k, N):
    return l + r >= 0 and l + r <= min([k, N]) and d <= l + r


def main():
    input = sys.stdin.readline
    N, K = map(int, input().split())
    Vs = list(map(int, input().split()))

    ans = 0
    for k in range(K+1):
        for l in range(min([k+1, N+1])):
            for r in range(min([k+1, N+1])):
                d = k - l - r
                if cond(l, r, d, k, N):
                    ans = max(ans, val(l, r, d, Vs))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
N = int(input())
A = list(map(int, input().split()))

n = 1
result = 0
S = sum(A)

for i in range(N+1):
    result += n

    if n < A[i]:
        print(-1)
        break
    n -= A[i]
    S -= A[i]

    if n < S:
        if n*2 < S:
            n *= 2
        else:
            n = S
else:
    print(result)


Measured memory_bytes: 20136
# _*_ coding:utf-8 _*_
#  Atcoder_Beginner_Contest120-B
#  https://atcoder.jp/contests/abc120/tasks/abc120_b

def kthCommonDivisor(A,B,count):
	startNumber = min(A,B)
	canCommonDivisor = list()
	for i in range(startNumber,0,-1):
		if A % i == 0 and B % i == 0:
			canCommonDivisor.append(i)
	answer = canCommonDivisor[count-1]
	return answer

if __name__ == '__main__':
	A,B,K = map(int,input().strip().split(' '))
	solution = kthCommonDivisor(A,B,K)
	print("{}".format(solution))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,a[2000005],ans;
int main()
{  cin>>n;
   for(int i=1;i<=100;i++)
   {  for(int j=1;j<=100;j++)
       {  for(int k=1;k<=100;k++)
           {  int x=i*i+j*j+k*k+i*j+i*k+j*k;
               a[x]++;
           }

       }
   }
   for(int i=1;i<=n;i++)
   {  cout<<a[i]<<endl;

   }
}

Measured memory_bytes: 3868
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);


		while(true) {

			int a = sc.nextInt();
			String op = sc.next();
			int c = sc.nextInt();

			if(op.equals("+")) {
				System.out.println(a + c);
			}else if(op.equals("-")) {
				System.out.println(a - c);
			}else if(op.equals("*")) {
				System.out.println(a * c);
			}else if(op.equals("/")){
				System.out.println(a / c);
			}else{
				break;
			}



		}

	}
}


Measured memory_bytes: 26340
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

bool r(string S){
	for(int i = 0; i < S.size()/2; i++){
		if(S[i] != S[S.size()-1-i])return false;
	}
	return true;
}
int main(){

	string S;
	cin >> S;
	if(r(S) && r(S.substr(0,(S.size() - 1)/2)) && r(S.substr((S.size()+3)/2-1, S.size()-(S.size()+3)/2+1))){
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define LIM 100005
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define vi vector <int>
#define pb push_back
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
int calc(int a[], int n, int k)
{
    sort(a, a + n);
    int pp = 1;
    if (a[n - 1] == 0 && (k & 1))
        return 0;
    if (a[n - 1] <= 0 && (k & 1)) {
        for (int i = n - 1; i >= n - k; i--)
            {pp *= a[i]; pp%=mod;}
        return pp%mod;
    }

    int i = 0;
    int j = n - 1;
    if (k & 1) {
        pp *= a[j];
        pp%=mod;
        j--;
        k--;
    }
    k=k/2;
    for (int ii = 0; ii < k; ii++) {
        int left_pp = a[i] * a[i + 1];
        int right_pp = a[j] * a[j - 1];
        if (left_pp > right_pp) {
            pp *= a[i];
            pp%=mod;
            pp*=a[i+1];
            pp%=mod;
            i += 2;
        }
        else {
          pp *= a[j];
          pp%=mod;
          pp*=a[j-1];
          pp%=mod;
            j -= 2;
        }
        pp= pp%mod;
    }
    return pp%mod;
}

int32_t main()
{
  IOS;
  int t,x,y,k,n,i,j;
  cin>>n>>k;
  int a[n];
  for(i=0;i<n;i++)cin>>a[i];
  t=calc(a,n,k);
  while(t<0)t+=mod;
  cout<<t;
}


Measured memory_bytes: 5220