akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int n,m,ans;
char a[105][105];
int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
int vis[105][105];
struct node{
	int x,y,step;
};

inline void bfs(int x, int y){
	queue<node> q;
	node ne;
	ne.x=x,ne.y=y;
	ne.step=0;
	vis[x][y]=1;
	q.push(ne);
	while(!q.empty()){
		node q1 = q.front();
		q.pop();
		for(int i=0;i<4;i++){
			int dx=q1.x+dir[i][0];
			int dy=q1.y+dir[i][1];
			if(a[dx][dy]=='.'&&!vis[dx][dy]&&dx>=1&&dx<=n&&dy>=1&&dy<=m){
				node v;
				vis[dx][dy]=1;
				v.x=dx;
				v.y=dy;
				v.step=q1.step+1;
				ans=max(ans,v.step);
				q.push(v);
			}
		}
	}
}

int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>a[i][j];
		}
	}
	
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			memset(vis,0,sizeof(vis));
			if(a[i][j]=='.') bfs(i,j);
		}
	}
	
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;
#define ll long long

const int MAX = 5e5+10;

vector<int>adj[MAX],adj1[MAX],comp[MAX];

int col[MAX] , col1[MAX];
bool vis[MAX] , vis1[MAX];
int cur = 1;
int cnt[MAX] , ans[MAX];

void DFS(int src)
{
    col[src] = cur;
    vis[src] = 1;
    comp[cur].push_back(src);

    for(int j=0;j<adj[src].size();j++)
    {
        int i = adj[src][j];
        if(!vis[i])
            DFS(i);
    }
}
void DFS1(int src)
{
    col1[src] = cur;
    vis1[src] = 1;

    for(int j=0;j<adj1[src].size();j++)
    {
        int i = adj1[src][j];
        if(!vis1[i])
            DFS1(i);
    }
}

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

    int n,m1,m2;

    //memset(col,-1,sizeof col);
    //memset(col1,-1,sizeof col1);

    cin >> n >> m1 >> m2;

    int u,v;

    for(int i=0;i<m1;i++)
    {
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for(int i=0;i<m2;i++)
    {
        cin >> u >> v;
        adj1[u].push_back(v);
        adj1[v].push_back(u);
    }

    vector<int>compN;

    for(int i=1;i<=n;i++)
    {
        if(!vis[i])
        {
            compN.push_back(cur);
            DFS(i);
            cur++;
        }
        if(!vis1[i])
        {
            DFS1(i);
            cur++;
        }
    }

    for(int z=0;z<compN.size();z++)
    {
        int i = compN[z];

        for(int j=0;j<comp[i].size();j++)
        {
            int x = comp[i][j];
            cnt[col1[x]]++;
        }
        for(int j=0;j<comp[i].size();j++)
        {
            int x = comp[i][j];
            ans[x] = cnt[col1[x]];
        }
        for(int j=0;j<comp[i].size();j++)
        {
            int x = comp[i][j];
            cnt[col1[x]]--;
        }
    }

    for(int i=1;i<=n;i++)
    {
        if(i > 1)
            cout << " ";
        cout << ans[i];
    }
    cout << endl;
}


Measured memory_bytes: 54008
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;

signed main(){
	cout<<fixed<<setprecision(10);
	
	int MAX = 210000;
	int N;
	int sum = 0;
	vector<int> A, con(MAX);
	
	cin>>N;
	
	A.resize(N);
	
	for(int i = 0; i < N; i++){
		cin>>A[i];
		con[A[i]]++;
	}
	
	for(int i = 1; i < MAX; i++){
		sum += con[i] * (con[i] - 1)/ 2;
	}
	
	for(int i = 0; i < N; i++){
		int temp = sum;
		temp -= con[A[i]] * (con[A[i]] - 1)/ 2;
		temp += (con[A[i]] - 1) * (con[A[i]] - 2)/ 2;
		
		cout<<temp<<endl;
	}
	
	return 0;
}

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

typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define LINF 1e18
#define INF 1e9
using namespace std;

#define fs first
#define sc second
#define P pair<ll,ll>


ll n,ans,cnt;
vector<P> vec[15];
ll type[15];

int main(){
    cin >> n;
    ll a[n] = {};

    rep(i,0,n){
        cin >> a[i];

        rep(j,0,a[i]){
            P p;
            cin >> p.fs >> p.sc;
            vec[i].push_back(p);
        }

    }

    rep(i,0,(1 << n)){
        cnt = 0;
        rep(j,0,n) if((i >> j) & 1) cnt++;
        rep(j,0,n) type[j] = ((i >> j) & 1);

        bool flag = false;
        rep(j,0,n){
            if((i >> j) & 1){
                rep(k,0,vec[j].size()){
                    if(type[vec[j][k].fs - 1] != vec[j][k].sc){
                        flag = true;
                        break;
                    }
                }
            }
            if(flag) break;
            
            if(j == n-1) ans = max(ans,cnt);
            //if(j == n-1) cout << i << " " << ans << endl;
        }
    }
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np
sys.setrecursionlimit(1000000)
 
N,K = map(int,input().split())
VN =  [int(i) for i in input().split()]

ans = 0
temp = 0

for i in range(min(N,K)+1):
    for j in range(min(K-i,N-i)+1):
        now = 0
        if i + j > min(N,K):
            break
       
        tmp_list = []
        
        for l in range(i):
            now += VN[l]
            tmp_list.append(VN[l])
    
        for m in range(j):
            now += VN[N-1-m]
            tmp_list.append(VN[N-1-m])
        
        tmp_list.sort()
        
        for n in range(K-i-j):
            if n >= len(tmp_list):
                break
            if tmp_list[n] >= 0:
                break
            now -= tmp_list[n]
        ans = max(ans,now)

print(ans)

Measured memory_bytes: 14424
#include <iostream>
#include <algorithm>

using namespace std;

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

  int n, pro = 0;
  int a[100], color[8] = {};

  cin >> n;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    if(a[i] >= 3200){
      pro++;
    }else{
      color[a[i] / 400] = 1;
    }
  }

  int min_c = 0, max_c = 0;
  for(int i = 0; i < 8; i++){
    if(color[i]){
      min_c++; max_c++;
    }
  }

  if(min_c == 0)
    min_c = 1;

  cout << min_c << " " << max_c + pro << "\n";

  return 0;
}


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  vector<int> num = {A, B, C};
  sort(num.begin(), num.end());

  int ans = 0;
  if ((num.at(2) * 2 - num.at(1) - num.at(0)) % 2 == 0)
    ans = (num.at(2) * 2 - num.at(1) - num.at(0)) / 2;
  else
    ans = (num.at(2) * 2 - num.at(1) - num.at(0) + 3) / 2;

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

/*
 
 8/3/2018
 
 19:50-20:20, 21:30-21:47 ACC
 
 Editorials:
  - http://arc063.contest.atcoder.jp/data/arc/063/editorial.pdf
  - https://youtu.be/iJwEPVN5MXs?t=1958
  - https://kimiyuki.net/writeup/algo/atcoder/arc-063-d/
  - http://ymduu.hatenablog.com/entry/2018/07/03/203121
  - http://hyoga.hatenablog.com/entry/2016/11/06/224713
  - http://xxxasdfghjk999.hatenablog.jp/entry/2018/07/25/232727
 
 keeping `min` in memory is impressive.
 `min` and `max` are independent. It's possible to compute previously.
 
 Summary:
  - keeping `min` in memory is neet
  - I should keep independency in mind more
 
 */

// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
const int MAX_N=1e5+1;
int N;
LL A[MAX_N];
LL T;
void solve_org() {
  map<LL,int> D;
  LL btm=A[0];
  FOR(i,1,N) {
    if(A[i]<btm) btm=A[i];
    else if(A[i]>btm) {
      D[-(A[i]-btm)]++;
    }
  }
  cout<<D.begin()->second<<endl;
}

void solve() {
  LL mins[MAX_N];
  mins[0]=A[0];
  map<LL,int> D;
  FOR(i,1,N) mins[i]=min(mins[i-1],A[i]);
  FOR(i,1,N) D[-(A[i]-mins[i-1])]++;
  cout<<D.begin()->second<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>N>>T;
  REP(i,N) cin>>A[i];
  solve();
  return 0;
}


Measured memory_bytes: 8064
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define psb push_back
#define fi first
#define se second
#define mkp make_pair

using namespace std;

const int N=1e6+5;

typedef long long LL;

typedef double db;

bool Ans[N],vis[N];

int n,tot,h[N],e[N<<1],nxt[N<<1],d[N],D[N],dep[N],f[N];

char c,S[12];

int read()
{
	int x=0,sig=1;
	for (c=getchar();c<'0' || c>'9';c=getchar()) if (c=='-') sig=-1;
	for (;c>='0' && c<='9';c=getchar()) x=x*10+c-48;
	return x*sig;
}

void Write(int x)
{
	int i,l=0;
	for (;x>0;x/=10) S[l++]=x%10;
	for (i=l-1;i>=0;i--) putchar(S[i]+48);
	putchar(' ');
}

bool Add(int x,int y)
{
	e[++tot]=y; nxt[tot]=h[x]; h[x]=tot;
}

int main()
{
	n=read();
	for (int i=1;i<=n;i++) d[i]=read();
	for (int i=1;i<n;i++)
	{
		int x=read(),y=read();
		Add(x,y); Add(y,x);
	}
	D[tot=1]=vis[1]=1;
	for (int i=1,j,x;i<=tot;i++)
	{
		x=D[i];
		for (j=h[x];j;j=nxt[j]) if (!vis[e[j]])
		{
			dep[e[j]]=dep[x]+1; vis[e[j]]=1; D[++tot]=e[j];
		}
	}
	for (int i=tot,j,x;i;i--)
	{
		x=D[i]; f[x]=0;
		for (j=h[x];j;j=nxt[j]) if (dep[e[j]]>dep[x])
		{
			if (d[e[j]]<d[x] && !f[e[j]]) f[x]++;
		}
	}
	for (int i=1,j,x;i<=tot;i++)
	{
		x=D[i];
		Ans[x]=f[x]>0;
		for (j=h[x];j;j=nxt[j]) if (dep[e[j]]>dep[x])
		{
			//if (d[e[j]]<d[x] && !f[e[j]]) f[x]--;
			if (d[e[j]]>d[x] && !f[x]) f[e[j]]++;
		}
	}
	for (int i=1;i<=n;i++) if (Ans[i]) Write(i);
	return 0;
}

Measured memory_bytes: 14464
n=int(input())
ans=''
check='abcdefghijklmnopqrstuvwxyz' #c(a)-1=0,c(b)-1=1,…,c(z)-1=25を対応づける文字列
while n!=0:
    n-=1
    ans+=check[n%26] #(n-1)%26がc(Sk)-1を表すので、上記の文字列を用いてc(Sk)-1からSkを求める
    n//=26
print(ans[::-1])

Measured memory_bytes: 9124
while True:
    m, f, r = [int(i) for i in input().split()]

    if m == f == r == -1:
        break

    elif m == -1 or f == -1:
        print("F")

    elif m + f >= 80:
        print("A")

    elif 65 <= m + f < 80:
        print("B")

    elif 50 <= m + f < 65:
        print("C")

    elif 30 <= m + f < 50:
        if r >= 50:
            print("C")
        else:
            print("D")

    elif m + f < 30:
        print("F")

    elif m + f < 30:
        print("F")

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

int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    stack<int> s;
    s.push(a[0]);
    int count=1;
    for(int i=1;i<n;i++)
    {
        if(s.top()>a[i])
        {
            s.push(a[i]);
            count++;
        }
    }
    cout<<count;
    
    
   
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;

int main() {
    long long a,b,gcd,lcm;
    long long c,d;
    while(true) {
        cin >> a >> b;
        if(!cin)
            return 0;
        c = a; d = b;
        while(true){
            if(a>b)
                swap(a,b);
            b = b%a;
            if(b == 0)
                break;

        }
        gcd = a;
        lcm = c/gcd*d; 
        cout << gcd << ' ' << lcm << '\n';
    }
}

Measured memory_bytes: 1156
#include<iostream>
using namespace std;
int main()
{
  int ans=0;
  string s;
  cin>>s;
  char tmp=s.at(0);
  for(int i=1;i<s.size();i++)
  {
    if(s.at(i)!=tmp) ans++;
    tmp=s.at(i);
  }
  cout<<ans<<endl;
}

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

bool stl(int s,int g,int N,vector<bool> walked,vector<vector<bool>> list) {
  walked.at(s) = true;
  if (s == g) {
    return true;
  }
  
  for (int i=0; i<N; i++) {
    if (list.at(s).at(i) && walked.at(i) == false) {
      if (stl(i,g,N,walked,list)) {
        return true;
      }
    }
  }
  walked.at(s) = false;
  return false;
}

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> va(M), vb(M);
  vector<vector<bool>> list (N,vector<bool>(N,false));
  for (int i=0; i<M; i++) {
    int a, b;
    cin >> a >> b;
    va.at(i) = a-1;
    vb.at(i) = b-1;
    list.at(a-1).at(b-1) = true;
    list.at(b-1).at(a-1) = true;
  }
  
  /*for (int i=0; i<M; i++) {
    cerr << va.at(i) << ' ' << vb.at(i) << endl;
  }*/
  
  vector<bool> walked(N,false);
  int count = 0;
  for (int i=0; i<M; i++) {
    list.at(va.at(i)).at(vb.at(i)) = false;
    if (stl(va.at(i),vb.at(i),N,walked,list) == false) {
      count++;
    }
    list.at(va.at(i)).at(vb.at(i)) = true;
  }
  cout << count << endl;
}

Measured memory_bytes: 384
import java.util.*;
public class Main
{
	public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	int x=sc.nextInt();
	
	String str=sc.next();
	ArrayList<Integer> arr=new ArrayList<Integer>();
	int len=str.length();
	
	for(int z=0;z<len;z++)
	{
	  if(str.charAt(z)=='W')
	    arr.add(1);
	   else 
	     arr.add(0);
	} 
	int i=0,j=len-1,count=0;
	while(i<j)
	{
	    while(i<len && j>0 && arr.get(i)==0)
	    {
	        i++;
	    }
	    while(j>=0 && i<len-1 && arr.get(j)==1)
	    {
	        j--;
	    }
	    if(i<j )
	    {
	        arr.set(i,0);
	        arr.set(j,1);
	       
	        count++;
	    }
	}
	System.out.println(count);
}
}


Measured memory_bytes: 43440
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 S         PIC X(100).
01 O         PIC X(3) VALUE "RUD".
01 E         PIC X(3) VALUE "LUD".
01 cnt       PIC 9(10).
01 flg       PIC 9(1) VALUE 1.
01 i         PIC 9(10) COMP.
01 len       PIC 9(10).
01 qt        PIC 9(10).
01 rm        PIC 9(10).

PROCEDURE DIVISION.
  ACCEPT S.
  MOVE FUNCTION STORED-CHAR-LENGTH(S) TO len.
  PERFORM VARYING i FROM 1 BY 1 UNTIL len < i
    DIVIDE i BY 2 GIVING qt REMAINDER rm
    MOVE ZERO TO cnt
    IF rm = 1
      INSPECT O TALLYING cnt FOR ALL S(i:1)
      IF ZERO = cnt
        MOVE ZERO TO flg
        EXIT PERFORM
      END-IF
    ELSE
      INSPECT E TALLYING cnt FOR ALL S(i:1)
      IF ZERO = cnt
        MOVE ZERO TO flg
        EXIT PERFORM
      END-IF
    END-IF
  END-PERFORM.
  IF ZERO NOT = flg
    DISPLAY "Yes"
  ELSE
    DISPLAY "No"
  END-IF.
  STOP RUN.


Measured memory_bytes: 3924
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>

using namespace std;
using ll = long long;
using vi = vector<int>;

#define in(v) v; cin >> v;
void ins() {}
template<class T,class... Rest>void ins(T& v,Rest&... rest){cin>>v;ins(rest...);}

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rrep(i,n) for(long long i=(n);i>=0;--i)
#define all(f,c,...) (([&](decltype((c)) cccc) { return (f)(begin(cccc), end(cccc), ## __VA_ARGS__); })(c))

// ========== debug ==========
template<class T>ostream& operator<<(ostream& os,const vector<T>& vec){os<<"{";for(size_t i=0;i<vec.size();++i)os<<(i?", ":"")<<vec[i];os<<"}";return os;}
ostream& operator<<(ostream& os,const vector<char>&v){for(size_t i=0;i<v.size();++i)os<<v[i];return os;}
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>& rhs){os<<"("<<rhs.first<<", "<<rhs.second<<")";return os;}

#ifdef LOCAL
void debug() {cerr << "\n";}
template<class First> void debug(const First& first) {cerr<<first<<"\n";}
template<class First, class... Rest> void debug(const First& first, const Rest&... rest) {cerr<<first<<",";debug(rest...);}
void debug2() {cerr << "\n";}
template<class First> void debug2(const First& first) {cerr<<first<<" ";}
template<class First, class... Rest> void debug2(const First& first, const Rest&... rest) {cerr<<first<<" ";debug2(rest...);}
#else
#define debug(...) 42
#define debug2(...) 42
#endif
// ===========================

int main() {
  int N;
  ins(N);

  int ans = 0;
  rep(i, N) {
    int in(a);
    if (i % 2 == 0 && a % 2 == 1)
      ++ans;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3600
# coding=utf-8

###
### for atcorder program
###

import sys
import math
import array

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]
#R = float(input())
#A = [int(x) for x in input().split()]
#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

def main():
    A,B,C,D = [int(x) for x in input().split()]

    E = mymath.lcm(C,D)

    Ct = 1
    if A == (A//C)*C:
        Ct = 0

    Cd = 1
    #if B == (B//C)*C:
    #   Cd = 0

    Dt = 1
    if A == (A//D)*D:
        Dt = 0

    Dd = 1
    #if B == (B//D)*D:
    #    Dd = 0

    Et = 1
    if A == (A//E)*E:
        Et = 0

    Ed = 1
    #if B == (B//E)*E:
    #   Ed = 0

    Cwa = (B//C+Cd - (A//C+Ct))
    Dwa = (B//D+Dd - (A//D+Dt))
    CDw = (B//E+Ed - (A//E+Et))
    zen = B - A + 1

    print(zen + CDw - Cwa - Dwa)

    #print(zen - len(list(range(A, B+1))))

    #print(list(x*C for x in range(A//C+Ct, B//C+Cd)))
    #print(list(x*D for x in range(A//D+Dt, B//D+Dd)))
    #print(list(x*E for x in range(A//E+Et, B//E+Ed)))
    #print(list(range(A, B+1)))
    #Dlist  = set(x*D for x in range(A//D, B//D+1))
    #ABlist = set(x for x in range(A,B+1))
    
    #print(len(Clist))

    #print(Clist)
    #print(Dlist)
    #print(Clist | Dlist)
    #print(ABlist)

    #anslist = ABlist - Clist

    #print(anslist)

    #count = len(anslist)
 

if __name__ == '__main__':
    main()



Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector<pair<ll, ll> > vp;
typedef vector<string> vs;
typedef vector<char> vc;
typedef list<ll> lst;
typedef pair<ll, ll> P;
const long long INF = 1e9;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
template <class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
//char c;
 
#define Endl endl
 
/*--------------------template--------------------*/

int main() {
    ll N;
    cin>>N;
    vi a(N);
    REP(i,N)cin>>a[i];
    /*ll m=*max_element(a.begin(),a.end());
    ans=-INF;
    FOR(i,2,10000*m+1){
        ll tmp=0;
        REP(j,N){
            tmp+=i%a[j];
        }
        ans=max(ans,tmp);
    }
    cout<<ans<<endl;*/
    REP(i,N){
        ans+=a[i]-1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric> 
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, d; 
    while(cin >> n >> d, n | d)
    {
        int num[110], capa[110][10010];
        int sum = 0;
        for(int i = 0; i < n; i++)
        {
            cin >> num[i];
            sum += num[i];
            for(int j = 0; j < num[i]; j++)
            {
                cin >> capa[i][j];
                //累積をとる
                if(j > 0) capa[i][j] += capa[i][j - 1];
            }
        }
        bool ok = true;
        for(int i = 0; i < sum; i++)
        {
            bool dispose = false;
            for(int j = 0; j < n; j++)
            {
                if(num[j] == 0) continue;
                num[j]--;
                int min_num = INF, max_num = -INF;
                //最大値と最小値の差を求める
                for(int k = 0; k < n; k++)
                {
                    min_num = min(capa[k][num[k] - 1], min_num);
                    max_num = max(capa[k][num[k] - 1], max_num);
                }
                if(max_num - min_num <= d)
                {
                    dispose = true;
                    break;
                }
                //条件を満たさないのであれば元に戻す
                num[j]++;
            }
            //一つもなければ
            if(dispose == false)
            {
                ok = false;
                break;
            }
        }
        cout << (ok ? "Yes" : "No") << endl;
    }
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main() {
    int h,w;
    cin>>h>>w;
    char arr[100][200];
    for(int i=0;i<2*h;i+=2){
        for(int j=0;j<w;j++){
            cin>>arr[j][i];
            arr[j][i+1]=arr[j][i];
        }
    }
    for(int i=0;i<2*h;i++){
        for(int j=0;j<w;j++){
            cout<<arr[j][i];
        }
        cout<<endl;
    }
    system("pause");
}


Measured memory_bytes: 504
from itertools import groupby
import math
import numpy as np

S = list(input())
if S[0]=='>':
    S = ['<']+S
if S[-1]=='<':
    S = S+['>']

D = np.array([len(list(g)) for k, g in groupby(S) ])

D=D.reshape([-1,2])
Asum = 0
for d in D:
    a1 = max(d)
    a2 = min(d)
    Asum += int((a1+1)*a1/2 + a2*(a2-1)/2)

print(Asum)

Measured memory_bytes: 21228
def around(grid,h,w,x,y):
    ans = []
    if y-1 >= 0:
        ans.append(grid[y-1][x])
        if x-1 >= 0:
            ans.append(grid[y-1][x-1])
        if x+1 < w:
            ans.append(grid[y-1][x+1])
    if x-1 >= 0:
        ans.append(grid[y][x-1])
    if x+1 < w:
        ans.append(grid[y][x+1])
    if y+1 < h:
        ans.append(grid[y+1][x])
        if x-1 >= 0:
            ans.append(grid[y+1][x-1])
        if x+1 < w:
            ans.append(grid[y+1][x+1])
    return ans
        
h,w = map(int,input().split())
grid = []
for i in range(h):
    s = list(input())
    grid.append(s)

for y in range(h):
    for x in range(w):
        if grid[y][x] != "#":
            tile = around(grid,h,w,x,y)
            counter = 0
            for i in range(len(tile)):
                if tile[i] == "#":
                    counter += 1
            grid[y][x] = counter

for i in range(h):
    for k in range(w):
        if k != w-1:
            print(grid[i][k],end="")
        else:
            print(grid[i][k])


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
bool f=0;
int c[N],cnt[3];
vector<int>G[N];
void dfs(int x,int ff=1)
{
    if(c[x])
    {
        f|=ff!=c[x];
        return;
    }
    c[x]=ff;
    cnt[ff]++;
    for(int u:G[x])
    dfs(u,3-ff);
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0; i<m; ++i)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs(1);
    printf("%lld\n",f?1LL*n*(n-1)/2-m:1LL*cnt[1]*cnt[2]-m);
    return 0;
}


Measured memory_bytes: 6528
using System;

public class Hello
{
    public static void Main()
    {
		var s = Console.ReadLine().Trim();
		var a = int.Parse(s.Substring(0, 2));
		var b = int.Parse(s.Substring(2));
		string ans;
		if (a >= 1 && a <= 12 && b >= 1 && b <= 12) ans = "AMBIGUOUS";
		else if ((a >= 1 && a <= 12 && !(b >= 1 && b <= 12))) ans = "MMYY";
		else if (!(a >= 1 && a <= 12) && b >= 1 && b <= 12) ans = "YYMM";
		else ans = "NA";
		Console.WriteLine(ans);

	}
}

Measured memory_bytes: 13140
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b;
  cin>>a>>b;
  cout<<(a+b)/2<<endl;
  
}


Measured memory_bytes: 3176
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int n;
  string s;
  cin >> n >> s;
  
  int count = 0;
  for (int i = 0; i < s.size() - 2; i++) {
    if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')
      count++;
  }
  
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        String S=sc.next();
        int N=S.length();
        
        for(int i=0;i<(N-3)/2;i++){
            if(S.charAt(i)==S.charAt((N-3-2*i)/2)){
                
            }else{
                System.out.println("No");
                return;
            }
        }
        
        for(int i=0;i<(N-1)/2;i++){
            if(S.charAt((N+1+2*i)/2)==S.charAt(N-1-i)){
                
            }else{
                System.out.println("No");
                return;
            }
        }
        
        for(int i=0;i<N;i++){
            if(S.charAt(i)==S.charAt(N-1-i)){
                
            }else{
                System.out.println("No");
                return;
            }
        }
        
        System.out.println("Yes");
    }
}


Measured memory_bytes: 23764
#include <cstdio>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)

using ll = long long;

int N;
std::vector<ll> v;

int main()
{
  scanf( "%d", &N );

  v.push_back( 0 );

  rep( i, N )
  {
    ll A;
    scanf( "%lld", &A );

    if( A )
      v[v.size()-1] += A;
    else
      v.push_back( 0 );
  }

  ll ans = 0;
  rep( i, v.size() )
    ans += v[i]/2;

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

  return 0;
}

Measured memory_bytes: 1400
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	var sc = bufio.NewScanner(os.Stdin)

	var n, x int
	sc.Split(bufio.ScanWords)
	if sc.Scan() {
		n, _ = strconv.Atoi(sc.Text())
	}
	if sc.Scan() {
		x, _ = strconv.Atoi(sc.Text())
	}

	ball := 0
	ans := 0
	for i := 0; i < n; i++ {
		if sc.Scan() {
			l, _ := strconv.Atoi(sc.Text())
			ball += l
			ans++
		}
		if ball > x {
			break
		}
	}

	if ball <= x {
		ans++
	}

	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <bitset>
#include <cmath>
using namespace std;
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
long long a[100000+5];
long long b[100000+5];
#define MOD 1000000007
struct node
{
	int type;//0 const , 1 <=
	long long val;
};
int main(void){	
	int n;
	while(cin>>n){
		FOR(i,0,n){
			cin>>a[i];
		}
		FOR(i,0,n){
			cin>>b[i];
		}
		node flag[100000+5];
		long long last = -1;
		FOR(i,0,n){
			if(a[i] != last){
				flag[i].type = 0;
				flag[i].val = a[i];
				last = a[i];
			}else{
				flag[i].type = 1;
				flag[i].val = a[i];
			}
		}
		last = -1;
		long long res = 1;
		bool f = true;
		for(int i=n-1;i>=0;i--){
			if(b[i] != last){
				if(flag[i].type == 0){
					if(flag[i].val != b[i]){
						cout<<0<<endl;
						f = false;
						break;
					}
				}else{
					if(flag[i].val < b[i]){
						cout<<0<<endl;
						f = false;
						break;
					}
				}
				last = b[i];
			}else{
				if(flag[i].type == 0){
					if(flag[i].val > b[i]){
						cout<<0<<endl;
						f = false;
						break;
					}
				}else{
					long long tmp = min(flag[i].val,b[i]);
					res *= tmp;
					res = res % MOD;
				}
			}

		}
		if(f) cout<<res<<endl;
	}	
	return 0;
}

Measured memory_bytes: 3328
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>

typedef long long LL;

int read() {
  int ans = 0, c, f = 1;
  while (!isdigit(c = getchar()))
    if (c == '-') f *= -1;
  do ans = ans * 10 + c - '0';
  while (isdigit(c = getchar()));
  return ans * f;
}

const int N = 300050;

int n, a[N], B, W;

bool check(int X) {
  int t = 0;
  for (int i = 1; i <= n; ++i)
    if (i & 1) { // Black
      t += a[i];
    } else { // White
      if (t >= X) t = std::max(t - a[i], 0);
      else t -= a[i];
    }
  return t >= X;
}

int main() {
  n = read();
  B = W = 0;
  for (int i = 1; i <= n; ++i)
    (i & 1 ? B : W) += a[i] = read();
  if (~n & 1) {
    if (B < W) std::swap(B, W);
    printf("%d %d\n", B, W);
    return 0;
  }
  int l = 0, r = B;
  while (l < r) {
    int mid = (l + r + 1) / 2;
    if (check(mid)) l = mid;
    else r = mid - 1;
  }
  printf("%d %d\n", W + l, B - l);
}


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

int main() {
 int N,K;
  cin >> N >> K;
  int min=1;
  for(int l = 0; l < N; l++)
    min *= 2;
  for(int i = 0; i < N; i++){
    int x=1;
    for(int j = 0; j < i; j++)
      x *= 2;
    for(int k = 0; k < (N-i); k++)
      x += K;
    if(x < min)
      min = x;
  }
  cout << min << endl;
}


Measured memory_bytes: 384
import java.util.*;
import java.io.*;
import java.math.*;

public class Main{
  public static OutputStream out=new BufferedOutputStream(System.out);
  static Scanner sc=new Scanner(System.in);
  static long mod=1000000007l;

  //nl-->neew line; //l-->line;  //arp-->array print;  //arpnl-->array print new line
  public static void nl(Object o) throws IOException{out.write((o+"\n").getBytes());}
  public static void l(Object o) throws IOException{out.write((o+"").getBytes());}
  public static void arp(int[] o) throws IOException{for(int i=0;i<o.length;i++) out.write((o[i]+" ").getBytes()); out.write(("\n").getBytes());}
  public static void arpnl(int[] o) throws IOException{for(int i=0;i<o.length;i++) out.write((o[i]+"\n").getBytes());}
  public static void scanl(long[] a,int n) {for(int i=0;i<n;i++) a[i]=sc.nextLong();}
  public static void scani(int[] a,int n) {for(int i=0;i<n;i++) a[i]=sc.nextInt();}
  public static void scan2D(int[][] a,int n,int m) {for(int i=0;i<n;i++) for(int j=0;j<m;j++) a[i][j]=sc.nextInt();}
  //
  static long cnt;
  static TreeSet<Integer> ans;
  static int n,m;
  static boolean[][] dp,vis;
  static HashMap<Pair,Boolean> arrl;


  public static void main(String[] args) throws IOException{
    long sttm=System.currentTimeMillis();
    long mod=1000000007l;

    int l=sc.nextInt(), r=sc.nextInt(), d=sc.nextInt();
    int cnt=0;
    for(int i=l;i<=r;i++){
        if(i%d==0) cnt++;
    }
    nl(cnt);

    out.flush();
  }
}

class Pair{
  int st,nd;
  Pair(int st,int nd){
    this.st=st;
    this.nd=nd;
  }
}


Measured memory_bytes: 38472
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main()
{
	long long H,n, buf=0;

	cin >> H >> n;

	vector<long long> a(n);

	for (long long i = 0; i < n; i++)
		cin >> a[i];

	for (long long i = 0; i < n; i++)
	{
		buf += a[i];
	}

	if(buf >= H)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 1024
S = input()
a = S[0:2]
b = S[2:4]
A = int(a)
B = int(b)
if A>=1 and A <=12:
  if B>= 1 and B <= 12:
    print("AMBIGUOUS")
  else:
    print("MMYY")
else:
  if B>= 1 and B<= 12:
    print("YYMM")
  else:
    print("NA")

Measured memory_bytes: 9120
#include<bits/stdc++.h>
using namespace std;
int main()
{
int x,y,c=0,d=0,a=0;
cin>>x>>y;
for(int c=0;c<=x;c++)
{
d=x-c;
if(2*c+4*d==y)
{
a=1;
break;
}
}
if(a==1)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
	return 0;
}

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

using namespace std;

int arr[15], p[15], N, M;
vector<int> tombol[15];

int rek(int idx) {
	if (idx == N + 1) {
		bool nyala = 1;
		for (int i = 1; i <= M; i++) {
			int cnt = 0;
			int l1 = tombol[i].size();
			for (int j = 0; j < l1; j++) {
				cnt += arr[tombol[i][j]];
				cnt %= 2;
			}
			if (cnt != p[i]) nyala = 0;
		}
		return nyala;
	}
	int tmp = 0;
	tmp += rek (idx + 1);
	arr[idx] = 1;
	tmp += rek (idx + 1);
	arr[idx] = 0;
	return tmp;
}

int main() {
	cin >> N >> M;
	for (int i = 1; i <= M; i++) {
		int k, s;
		cin >> k;
		for (int j = 0; j < k; j++) {
			cin >> s;
			tombol[i].push_back(s);
		}		
	}
	for (int i = 1; i <= M; i++) cin >> p[i];
	int ans = rek(1);
	cout << ans << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int maxm=2e5+5;
const int mod=1e9+7;
int a[maxm];
int b[maxm];
int n;
signed main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        int x,y;cin>>x>>y;
        a[i]=x-y;
        b[i]=x+y;
    }
    sort(a+1,a+1+n);
    sort(b+1,b+1+n);
    int ans=max(a[n]-a[1],b[n]-b[1]);
    cout<<ans<<endl;
    return 0;
}
/*

*/


Measured memory_bytes: 6772
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long
#define testcase ll tt; cin>>tt; while(tt--)
#define pb push_back
#define nn cout<<"\n"
#define MOD 1000000007
#define vll vector<ll>
#define here cout<<"I'm here\n";
template<class T> void dispvector(vector<T> v){for(int i=0;i<v.size();i++) cout<<v[i]<<" "; nn;}
void vout(vector<ll> ans){
    for(auto ele:ans) cout<<ele;
}
ll gcd(ll a,ll b){
    if(a==0)
        return b;
    else
        return gcd(b%a,a);
}
ll findGCD(vector<ll> arr,ll n) 
{ 
    ll result = arr[0]; 
    for (ll i = 1; i < n; i++) 
        result = gcd(arr[i], result);
    return result; 
}
int main() {
    SPEED;
    cout.precision(8);
    cout << fixed;
    ll n,m;
    cin>>n>>m;
    cout<<(n*(n-1)/2)+(m*(m-1)/2);
    return 0;
}

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

int N, M, R;
int cost[201][201];

void warshall_floyd() {
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
            }
        }
    }
    return;
}

int perm(vector<int> r) {
    sort(r.begin(), r.end());
    int ans = INF;
    do {
        int sum = 0;
        for (int i = 0; i < R - 1; i++) {
            sum += cost[r[i]][r[i + 1]];
        }
        ans = min(ans, sum);
    } while (next_permutation(r.begin(), r.end()));
    return ans;
}

int main() {
    cin >> N >> M >> R;
    vector<int> r(R);
    for (int i = 0; i < R; i++) {
        int town;
        cin >> town;
        r[i] = town - 1;
    }

    fill(cost[0], cost[200], INF);
    for (int i = 0; i < M; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        cost[a][b] = c;
        cost[b][a] = c;
    }
    warshall_floyd();
    
    cout << perm(r) << endl;
}

Measured memory_bytes: 384
n,m=map(int,input().split())
l_list=[]
r_list=[]

for i in range(m):
    l,r=map(int,input().split())
    l_list.append(l)
    r_list.append(r)

n_card=min(r_list)-max(l_list)+1

if n_card<=0:
    print(0)
else:
    print(n_card)


Measured memory_bytes: 10996
#include<bits/stdc++.h>
using namespace std;
long long n,a[105][105];
int main()
{
	cin>>n;
	for(int i=1;i<=2;i++)
	for(int j=1;j<=n;j++)
	cin>>a[i][j];
	for(int i=1;i<=2;i++)
	{
		for(int j=1;j<=n;j++)
		a[i][j]=a[i][j]+max(a[i-1][j],a[i][j-1]);
	}
	cout<<a[2][n]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;


int main(){FIN

    ll n;cin>>n;

    ll ans = n;
    REP(i,n+1){
        ll cc=0;
        ll t = i;
        while(t>0) {cc+=t%6; t /= 6;}
        t = n-i;
        while(t>0) {cc+=t%9; t /= 9;}
        ans = min(ans,cc);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>

using namespace std;


int main() {
	int N; cin >> N;
	int a = 0, b = 0, ab = 0, count = 0;

	char buf[20] = {};
	for (int I = 0; I < N; I++) {
		cin >> buf;
		int len = strlen(buf);

		if (buf[0] == 'B') { b++; }
		if (buf[len - 1] == 'A') { a++; }
		if (buf[0] == 'B' && buf[len - 1] == 'A') { ab++; }
		for (int i = 0; i < len - 1; i++) {
			if (buf[i] == 'A' && buf[i + 1] == 'B') {
				count++;
			}
		}
	}

	if (ab == 0) {
		count += min(a, b);
		cout << count << endl;
		return 0;
	}

	a -= ab;
	b -= ab;

	count += ab - 1;

	if (a > 0) {
		a--;
		count++;
	}
	if (b > 0) {
		b--;
		count++;
	}
	count += min(a, b);

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

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

        long k = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        int time = 0;
        long biscuits = 1;
        int money = 0;

        if (a + 1 >= b) {
            System.out.println(k + 1);
        } else {
            while (time < k) {
                if (money == 1) {
                    biscuits += b;
                    time++;
                    money--;
                } else if (biscuits < a || k - time == 1) {
                    biscuits++;
                    time++;
                } else {
                    biscuits -= a;
                    money++;
                    time++;
                }

            }
            System.out.println(biscuits);
        }
    }
}




Measured memory_bytes: 23124
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;

#define LEN(x) (int)x.size()
#define ALL(x) x.begin(), x.end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
using vpii = vector<pii>;

template<typename T, typename M = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, M, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

template<typename T>
const T INF = (is_same<T, int>::value ? 1e9 : 1e18);
const int MOD = 1e9 + 7;
const double EPS = 1e-9;

inline int fcmp(double x, double y)
{ return (x < y + EPS ? (x < y - EPS ? -1 : 0) : 1);}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);
    
    for(int i = 1; i <= 5; i++)
    {
        int a; cin >> a;
        if(a == 0) cout << i << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
 
using namespace std;
 
int main(){
  int A, B, X;
  cin >> A >> B >> X;
  
  if (A + B < X) {
    cout << "NO\n";
  }
  else if (A > X) {
    cout << "NO\n";
  }
  else {
    cout << "YES\n";
  }
}

Measured memory_bytes: 3516
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;

#define MAX_V 100001
#define INF (1e9 + 1)

struct edge{
  int to,cost;
};

int V,E,r,a,b,c;

vector< edge > G[MAX_V];


int d[MAX_V];
void dijkstra(){
  int i;
  for(i=0;i<MAX_V;i++)d[i]=INF;
  d[r]=0;
  priority_queue< pair<int,int> > Q;
  Q.push( make_pair(0,r) );
  while(!Q.empty()){
    pair<int,int> p=Q.top();
    Q.pop();
    int pos=p.second,cost=-p.first;
    if( cost > d[pos] )continue;
    for(i=0;i<G[pos].size();i++){
      edge e=G[pos][i];
      int to=e.to;
      int newcost=cost+e.cost;
      if( newcost < d[to]){
        d[to]=newcost;
        Q.push( make_pair(-d[to],to) );
      }
    }
  }

  for(i=0;i<V;i++){
    if(d[i]==INF)printf("INF\n");
    else printf("%d\n",d[i]);
  }
}

int main(){
  int i;
  scanf("%d %d %d",&V,&E,&r);
  for(i=0;i<E;i++){
    scanf("%d %d %d",&a,&b,&c);
    G[a].push_back((edge){b,c});
  }
  dijkstra();
  return 0;
}


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

bool comp(int a, int b){ return b < a; }

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

    vector<char> lr(n+2, 0);
    vector<int> csuml(n+2,0), csumr(n+2,0);
    for(int i=1; i<=n; i++){ cin >> lr[i]; }
    for(int i=1; i<n+2; i++){
        csuml[i]=csuml[i-1];
        if(lr[i]=='>') csuml[i]++;
    }
    for(int i=n; i>=0; i--){
        csumr[i]=csumr[i+1];
        if(lr[i]=='<') csumr[i]++;
    }

    int s=1, e=n;
    int ans=0;
    while(s <= e){
        int m=(s+e)/2;
        int adjst=0;
        vector<int>::iterator it;
        if(csuml[m-1] < csumr[m+1] || (csuml[m-1]==csumr[m+1] && lr[m]=='<')){
            s=m+1;
            if(lr[m]=='>') adjst=1;
            it = lower_bound(csumr.begin(), csumr.end(), csumr[m+1]-csuml[m-1]-adjst, comp);
            ans = max(ans, (int)(it-csumr.begin())-1);
        }else{
            e=m-1;
            if(lr[m]=='<') adjst=1;
            it = upper_bound(csuml.begin(), csuml.end(), csuml[m-1]-csumr[m+1]-adjst);
            ans = max(ans, (int)(csuml.end()-it)-1);
        }
    }
    
    cout << ans << endl;
    return 0;
}

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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  string s, t;
  cin >> s >> t;
  int ans;
  for (ans = N; ans <= 2 * N; ans++)
  {
    if (s.substr(ans - N, 2 * N - ans) == t.substr(0, 2 * N - ans))
      break;
  }
  cout << ans << endl;
  return 0;
}

// 最初一致しているかの確認
// 長さの上限は2N，よって長さをNから2Nまで試していって条件を満たす文字列が見つかった時点でその長さを答えにすればいい．長さがlであるとき，条件を満たすか文字列はsとtを2N - l分だけオーバーラップさせたような文字列になる．そのため，sの末尾2N - l文字とtの先頭2N - l文字が完全に一致しているかを判定すればよい．（長さがlのとき，l = 2N - (オーバーラップ)，オーバーラップ = 2N - lとなる)


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

using namespace std;

typedef long long llint;

const int MAXN = 100005;

llint n, jen, sol;
llint p[MAXN];
vector <int> v;
map < pair <llint, llint>, llint> mp[2];
set < pair <llint, llint> > st;

void precompute () {
    for (int i=2; i*i<2200; i++) {
        if (p[i] == 1) continue;
        for (int j=i*i; j<2200; j+=i) {
            p[j] = i;
        }
    }
    for (int i=2; i<2200; i++) {
        if (p[i] == 0) v.push_back(i);
    }
}

void f (llint x) {
    vector < pair <llint, llint> > r;
    for (auto q : v) {
        llint cnt = 0;
        while (x % q == 0) {
            x /= q;
            cnt++;
        }
        if (cnt % 3 == 0) continue;
        r.push_back({q, cnt % 3});
    }
    if (x > 1) {
        llint k = sqrt(x);
        if (k * k == x) r.push_back({k, 2}); else r.push_back({x, 1});
    }
    if (r.empty()) {
        jen++;
        return;
    }
    llint tip = 0;
    if (r[0].second == 2) {
        tip = 1;
        for (int i=0; i<r.size(); i++) {
            r[i].second = 3 - r[i].second;
        }
    }
    llint a = 1, b = 1;
    for (int i=0; i<r.size(); i++) {
        a *= r[i].first;
        if (r[i].second == 2) b *= r[i].first;
    }
    mp[tip][{a, b}]++;
    st.insert({a, b});
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    precompute();
    cin >> n;
    //n = 100000;
    for (int i=0; i<n; i++) {
        llint x;
        cin >> x;
        //x = 1LL * rand() * rand() % ((llint)(1e10)) + 1;
        if (x == 1) jen++; else f(x);
    }
    for (auto par : st) {
        sol += max(mp[0][par], mp[1][par]);
    }
    cout << sol + !!jen;
    return 0;
}


Measured memory_bytes: 19200
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#include <cstring>
#include <map>
#include <queue>
#include <string>
#define pb push_back
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define inf (int)(1e9)
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;

int iro[2][55];
int main(void){
  int n;
  string s1,s2;
  cin>>n>>s1>>s2;
  ll res;
  int i;
  bool f;
  if(s1[0]==s2[0]) f=true;
  else f=false;
  if(f) i=1;
  else i=2;
  res=3*i;
  while(i<n){
    if(s1[i]==s2[i]){
      if(f) res*=2;
      i++;
      f=true;
    }
    else{
      if(f) res*=2;
      else res*=3;
      i+=2;
      f=false;
    }
    res%=mod;
  }
  cout<<res<<endl;
  return 0;
}


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

using namespace std;
int dp[105][10005];
int n,W;
int v[1005],w[1005];
void solve(){
    for(int i=n-1; i>=0; i--){
        for(int j=0; j<=W; j++){
            if(j<w[i]){
                dp[i][j]=dp[i+1][j];
            }else {
                dp[i][j]=max(dp[i+1][j],dp[i+1][j-w[i]]+v[i]);
            }
        }
    }
    cout<<dp[0][W]<<endl;
}
int main(){
    cin>>n;
    cin>>W;
    for(int i=0; i<n; i++){
        cin>>v[i]>>w[i];
    }
    
    solve();
    return 0;
}

Measured memory_bytes: 7020
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

const ll MOD = 1000000007;

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

    int N, M; cin >> N >> M;
    vector<bool> walkable(N+1, true);

    rep(i, 0, M) {
        int in; cin >> in;
        walkable[in] = false;
    }

    vector<ll> dp(N+1, 0);
    dp[0] = 1;

    rep(now, 0, N) {
        for(int next = now+1; next <= min(N, now+2); ++next) {
            if (walkable[next]) {
                dp[next] += dp[now];
                dp[next] %= MOD;
            }
        }
    }

    cout << dp[N] << endl;
}

Measured memory_bytes: 1024