akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}
int lcm(int a, int b){
  return a / gcd(a,b) * b;
}
const int INF = 1<<30;
const int MOD = 1000000007;
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};

int n,m;
string s;
int dp[100005];

int main(){
  cin >> n >> m >> s;
  reverse(s.begin(),s.end());

  vector<int> pre;
  int step = m;
  int pos = 0;
  while(step > 0 && pos != n){
    if(pos+step > n){//場外に出てしまう場合
      step--;
    }else if(s[pos+step] == '0'){//進める場合
      pos += step; //posを進める
      pre.push_back(step); //stepを記録
      step = m; //stepを元に戻す
    }else{//進めない場合
      step--;
    }
  }
  
  if(pos != n){
    cout << -1 << endl;
    return 0;
  }
  reverse(pre.begin(),pre.end());
  for(auto s:pre){
    cout << s << " ";
  }
  return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int) (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define INF 1e9

using namespace std;

int main(){
  string str;
  while(cin >> str and str != "#"){
    vector<int> direct;
    REP(i, str.size()){
      if(str[i] == 'n') { direct.push_back(0); i += 4; }
      else if(str[i] == 'w') { direct.push_back(1); i += 3; }
    }
    int numer = 0;
    int denom = pow(2, direct.size());
    REP(i, direct.size()){
      if(i == 0) { numer = direct[direct.size()-1] ? 90 * denom : 0; continue; }
      numer += (direct[direct.size()-i-1] ? 90 * pow(2, direct.size()-i) : -90 * pow(2, direct.size()-i));
    }
    while(denom % 2 == 0 and numer % 2 == 0){
      denom /= 2;
      numer /= 2;
    }
    if(numer % denom == 0) cout << numer / denom << endl;
    else cout << numer << '/' << denom << endl;
  }
  return 0;
}

Measured memory_bytes: 3132
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;
typedef long double lb; 

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)


int main() {
    ll N,A,B;
    cin >> N >> A >> B;
    // ll ans = floor(N/(A+B)) * A;
    ll ans = N/(A+B) * A;
    
    ll result = N % (A+B);
    if(result < A){
        ans += result;
    }else{
        ans += A;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;
// import java.util.stream.*;

public class Main {
  public static void main(String[] args) {
    Main main = new Main();
    System.out.println(main.solve());
  }

  int n;

  public Main() {
    Scanner sc = new Scanner(System.in);
    try {
      n = sc.nextInt();
    } finally {
      sc.close();
    }
  }

  String solve() {
    int ans = calc();
    if (ans == -1) return ":(";
    return String.valueOf(ans);
  }

  int calc() {
    for (int i = 1; i <= n; i++) if (i * 108 / 100 == n) return i;
    return -1;
  }
}


Measured memory_bytes: 35820
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>

using ll = long long;
typedef unsigned long long ull;
using namespace std;
typedef pair<ll, ll>P;

const ll Z = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
bool flag = true, fl = true;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
string abc = "abcdefghijklmnopqrstuvwxyz";
struct edge { ll to, cost; };
struct etree { ll from, to, cost; };
double pai = 3.141592653589793;
bool comp(const etree& e1, const etree& e2) {
	return e1.cost < e2.cost;
}
#define ALL(x) (x).begin(),(x).end()

int main() {
	int n, a[100010], ans = 1;
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	for (int i = n - 1;i > 0;i--) {
		if (a[i] != a[i - 1])ans++;
	}
	cout << ans << endl;
}

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

using namespace std;

#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define endl '\n'
#define int long long

int n;

signed main()
{
	IOS;
	cin >> n;
	string s;
	map<string, int> mp;
	for (int i = 0; i < n; i++) {
		cin >> s;
		sort(s.begin(), s.end());
		mp[s]++;
	}
	int ans=0;
	for (auto i : mp) {
		int x = i.second;
		ans += (x * (x-1))/2;
	}	
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 11264
n=int(input())
for i in range(1,1000):
    if i*(i+1)==n*2:
        print("Yes")
        k=i+1
        print(k)
        break
else:
    print("No")
    quit()
ans=[[0]*(k-1) for i in range(k)]
x=1
for i in range(k-1,0,-1):
    for j in range(i):
        ans[-i-1][-j-1]=x
        ans[-i+j][-i]=x
        x+=1
for i in ans:
    print(k-1," ".join(map(str,i)))

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

int main() {
    int n;
    cin >> n;
    cout << 1 - n << endl;
    return 0;
}


Measured memory_bytes: 3632
/* vo05_04.cpp */
#include <iostream>
#include <cstdio>
using namespace std;

double m_round(double d);

int main()
{
	double a, b, c, d, e, f;;
	double x, y;

	while (true) {

		cin >> a >> b >> c >> d >> e >> f;
		if (cin.eof()) break;

		x = (c*e - f*b) / (a*e - d*b);
		y = (a*f - d*c) / (a*e - d*b);

		x = m_round(x); y = m_round(y);

		printf("%.3f %.3f\n", x, y);
	}

	return 0;
}

double m_round(double d)
{
	if (d == 0) { d = 0; return d; }

	bool flag = false;
	if (d < 0) { flag = true; d = -d; }

	d *= 1000;
	d += 0.5;

	int t1 = (int)d;
	double t2 = d - (double)t1;
	d -= t2;

	d /= 1000;

	if (flag) { d = -d; }

	return d;
}

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

int main()
{

    int N;
    cin >> N;
    map<string, int> counter;

    int max_count = 0;
    rep(i, N)
    {
        string temp;
        cin >> temp;
        if (!counter.count(temp))
        {
            counter[temp] = 0;
        }
        counter[temp] += 1;

        if (counter[temp] > max_count)
        {
            max_count = counter[temp];
        }
    }

    vector<string> ans;
    for (auto p : counter)
    {
        if (p.second == max_count)
        {
            ans.push_back(p.first);
        }
    }

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

    for (string a : ans)
    {
        cout << a << endl;
    }
}


Measured memory_bytes: 27248
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<iomanip>
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<string> vs;
Def inf=1e9;
signed main(){
    string s;
    while(getline(cin,s),s!="."){
        stack<int>st;
        bool h=true;
        rep(i,s.size()){
            if(s[i]=='('){
                st.push(0);
            }else if(s[i]==')'){
                if(st.size()&&st.top()==0){
                    st.pop();
                }else{
                    h=false;
                    break;
                }
            }else if(s[i]=='['){
                st.push(1);
            }else if(s[i]==']'){
                if(st.size()&&st.top()==1){
                    st.pop();
                }else{
                    h=false;
                    break;
                }
            }
        }
        if(st.size())h=false;
        if(h)cout<<"yes"<<endl;
        else cout<<"no"<<endl;
    }
}



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

int main() {
	int A, B, C, D, E, time=0;
	cin >> A >> B >> C >> D >> E;
	while(A<0){
		time += C;
		A++;
	}
	if(A==0) time += D;
	while(A>=0 && A<B){
		time += E;
		A++;
	}
	cout << time << endl;
	return 0;
}


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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define ii pair<int,int>
#define fi first
#define sc second
#define stoi stoll
#define popcnt __builtin_popcount
#define getBit(x, k) ((x >> k) & 1)
#define all(x) (x).begin(),(x).end()
// ---------------------------------

void Main() {
  int n, x, mod;
  cin >> n >> x >> mod;
  vector<int> val(100001);
  val[1] = x;
  map<int, int> mem;
  mem[x] = 1;
  int t = x, ans = x;
  for (int i = 2; i <= n; i++) {
    t = (t * t) % mod;
    if (mem[t]) {
      int d = i - mem[t];
      int r = n - i + 1;
      int c = 0;
      for (int j = mem[t]; j < i; j++) {
        c += val[j];
      }
      ans += (r / d) * c;
      for (int j = mem[t]; j <= mem[t] + r % d - 1; j++) {
        ans += val[j];
      }
      cout << ans << '\n';
      return;
    }
    val[i] = t;
    mem[t] = i;
    ans += t;
  }
  cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  cerr << "i love ------- <3 \n";
#endif
  cin.tie(0)->sync_with_stdio(0);
  int T = 1;
  // cin >> T;
  while (T--) Main();
}


Measured memory_bytes: 7144
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod=1e9+7;
ll const maxn=1e3+5;
ll const inf=1e18;
ll add(ll a,ll b){
    return ((a%mod)+(b%mod))%mod;
}
ll mul(ll a,ll b){
    return ((a%mod)*(b%mod))%mod;
}
ll powm(ll x,ll n,ll M)
{
    ll result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=(result * x)%M;
        x=(x*x)%M;
        n=n/2;
    }
    return result;
}
bool prime(ll x){
    if(x<2)return false;
    for(int i=2;i<=sqrt(x);i++){
        if(x%i==0)return false;
    }
    return true;
}
int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    // #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    vector<ll>v(n);
    for(int i=0;i<n;i++)cin>>v[i];
    vector<ll>dp(k+1,2);
   for(int i=1;i<=k;i++){
    for(int j=0;j<n;j++){
        if(v[j]>i)continue;
        else{
            if(dp[i-v[j]]==2)dp[i]=1;
        }
    }
   }
   cout<<(dp[k]==1 ? "First":"Second");
    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int n;
	cin>>n;
	vector<int> p(n), q(n), p0(n);
	for(int i=0; i<n; i++) cin>>p[i];
	for(int i=0; i<n; i++) cin>>q[i];
	vector<vector<int>> v;
	iota(p0.begin(), p0.end(), 1);
	do{
		v.push_back(p0);
	}while(next_permutation(p0.begin(), p0.end()));
	int a=lower_bound(v.begin(), v.end(), p)-v.begin();
	int b=lower_bound(v.begin(), v.end(), q)-v.begin();
	cout<<abs(a-b)<<endl;
	return 0;
}

Measured memory_bytes: 3256
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		String[] s = new String[n];
		for(int i = 0; i < n; i++){
		    s[i] = sc.next();
		}
		
		// 計算
		String result = "Yes";
		ArrayList<int[]> up = new ArrayList<int[]>();
		ArrayList<int[]> down = new ArrayList<int[]>();
		int total = 0;
		for(int i = 0; i < n; i++){
		    int cnt = 0;
		    int minus = 0;
		    for(int j = 0; j < s[i].length(); j++){
		        if(s[i].charAt(j) == '(') cnt++;
		        if(s[i].charAt(j) == ')') cnt--;
		        minus = min(minus, cnt);
		    }
		    if(cnt >= 0){
		        up.add(new int[]{i, minus, cnt});
		    }else{
		        down.add(new int[]{i, minus-cnt, -cnt});
		    }
		    total += cnt;
		}
		if(total != 0) result = "No";
		Collections.sort(up, (x, y) -> Integer.compare(y[1], x[1]));
		Collections.sort(down, (x, y) -> Integer.compare(y[1], x[1]));
		int cnt = 0;
		for(int[] u : up){
		    if(cnt + u[1] < 0){
		        result = "No";
		        break;
		    }else{
		        cnt += u[2];
		    }
		}
		cnt = 0;
		for(int[] d : down){
		    if(cnt + d[1] < 0){
		        result = "No";
		        break;
		    }else{
		        cnt += d[2];
		    }
		}
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}



Measured memory_bytes: 138400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
string s[10005];
int n,ans,add;
bool beg[10005],en[10005];
int A,B,C;
int main(){
	cin>>n;
	rep(i,n){
		cin>>s[i];
		for(int j=1;j<s[i].size();j++){
			if(s[i][j-1] == 'A' && s[i][j] == 'B') ans++;
		}
		if(s[i][0] == 'B') beg[i] = 1;
		if(s[i][s[i].size()-1] == 'A') en[i] = 1;
		if(beg[i]&&en[i]) A++;
		else if(beg[i]) B++;
		else if(en[i]) C++;
	}
	int add = A+min(B,C);
	if(B==0 && C==0) add--;
	cout<<ans+max(0,add)<<endl;
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int a, b;
	cin >> a >> b;
	string ans;
	if (a < b) {
		for (int i = 0; i < b; i++){
			ans += to_string(a);
		}
	}
	else {
		for (int i = 0; i < a; i++){
			ans += to_string(b);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
using namespace std;
int main(){
ios::sync_with_stdio(false);//输入输出加速
string sInput;
int i,ans=0;
cin >> sInput;//输入
for (i = 1; i < sInput.length(); ++i){
    if (sInput[i] != sInput[i - 1])//判断
        ++ans;
}
cout << ans << endl;//做AT的题记得换行
return 0;
}

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

struct LCA{
    static const int BITLEN_MAX = 30;
    vector<int> parent[BITLEN_MAX];
    vector<int> depth;
    int bitlen;

    void initialize(int N, const vector<int> edges[]){
        int root = 0;
        bitlen = 1;
        while((1<<bitlen) < N) bitlen += 1;
        for(int i=0; i<bitlen; i++) parent[i].resize(N);
        depth.resize(N, -1);

        dfs(root, -1, 0, edges);
        for(int k=0; k<bitlen-1; k++){
            for(int v=0; v<N; v++){
                if(depth[v] == -1) continue;
                if(parent[k][v] < 0){
                    parent[k+1][v] = -1;
                }else{
                    parent[k+1][v] = parent[k][parent[k][v]];
                }
            }
        }
    }

    void dfs(int v, int p, int d, const vector<int> edges[]){
        parent[0][v] = p;
        depth[v] = d;
        for(auto u : edges[v]){
            if(u != p) dfs(u, v, d+1, edges);
        }
    }

    int calc_lca(int u, int v){
        if(depth[u] > depth[v]) swap(u, v);
        for(int k=0; k<bitlen; k++){
            if( ((depth[v]-depth[u]) >> k) & 1 ) v = parent[k][v];
        }
        if(u == v) return u;
        for(int k=bitlen-1; k>=0; k--){
            if(parent[k][u] != parent[k][v]){
                u = parent[k][u];
                v = parent[k][v];
            }
        }
        return parent[0][u];
    }

    int calc_dist(int u, int v){
        int l = calc_lca(u, v);
        return depth[u] + depth[v] - depth[l]*2;
    }
};

vector<int> edges[2][200000];
int dist[2][200000];
bitset<200000> dead, eternal;

void dfs(int i, int p, int d, int k){
    dist[k][i] = d;
    for(int j : edges[k][i]) if(j != p) dfs(j, i, d+1, k);
}

int ans = 0;
const int INF = 1e9;
void dfs2(int i, int p){
    ans = max(ans, eternal[i] ? INF : dist[1][i] * 2);
    for(int j : edges[0][i]) if(j != p && !dead[j]) dfs2(j, i);
}

int main(){
    int N, S[2];
    cin >> N >> S[0] >> S[1];
    for(int k=0; k<2; k++){
        for(int i=0; i<N-1; i++){
            int a, b;
            cin >> a >> b;
            edges[k][a-1].push_back(b-1);
            edges[k][b-1].push_back(a-1);
        }
        S[k]--;
        dfs(S[k], -1, 0, k);
    }

    for(int i=0; i<N; i++) if(dist[0][i] >= dist[1][i]) dead[i] = true;

    LCA lca1;
    lca1.initialize(N, edges[1]);
    for(int i=0; i<N; i++){
        for(int j : edges[0][i]){
            if(lca1.calc_dist(i, j) > 2) eternal[i] = eternal[j] = true;
        }
    }

    dfs2(S[0], -1);
    cout << (ans == INF ? -1 : ans) << endl;
    return 0;
}


Measured memory_bytes: 49916
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define forn(b) for(int i = 0; i < b; i++)
#define rforn(b) for(int i = b - 1 ;i >= 0; i--)
#define It(m) for(auto it = m.begin(); it != m.end(); it++)
#define N 500500
#define PI 3.14159265358979323846264338327950L
#define speed ios_base :: sync_with_stdio(0);cin.tie(0);cout.tie(0);
    
const ll mod = (ll)1e9 + 7;
    
int main(){
    speed;
    char c; cin >> c;
    if(c == 'a' || c == 'e' || c == 'u' || c == 'i' || c == 'o') {
        cout << "vowel";
    }
    else {
        cout << "consonant";
    }
    return 0;
}

Measured memory_bytes: 256
const fs = require('fs');
let [s, k] = fs.readFileSync('/dev/stdin', 'utf-8').split('\n');
k = parseInt(k);

function exec(s: string): [number, string] {
  let count = 0;
  let before = s[0];
  for (let i = 1; i < s.length; ++i) {
    if (before !== s[i]) {
      before = s[i];
    } else {
      before = null;
      count++;
    }
  }
  return [count, before];
}

let [count, last] = exec(s);
if (s[0] !== last) {
  console.log(count * k);
} else {
  let [even, last] = exec(s[0] + s);
  if (s[0] !== last) {
    console.log((k >> 1) * (count + even) + (k & 1) * count);
  } else {
    console.log(count + (k - 1) * even);
  }
}

Measured memory_bytes: 7500
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD 1000000007
using namespace std;

int main(void){
    long long k,a,b;
    cin >> k >> a >> b;
    long long count=0,biscuit=1;
    while(biscuit<a){
        count++;
        biscuit++;
    }
    if(b-a>2){
        biscuit+=(b-a)*((k-count)/2);
        if((k-count)%2)biscuit++;
    }else biscuit+=k-count;
    cout << biscuit << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

A,B = inpl()
print(max(A+B,A-B,A*B))


Measured memory_bytes: 4084
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String[] S = new String[3];
        String[] T = new String[3];
        String line;

        line = sc.nextLine();
        S = line.split("");

        line = sc.nextLine();
        T = line.split("");

        int count = 0;
        for (int i = 0; i < 3; i++) {
            if (S[i].equals(T[i])) {
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 22740
import sys
sys.setrecursionlimit(1000000)

n, q = map(int, input().split())
dic = {}

for _ in range(n - 1):
    a, b = map(int, input().split())
    if not (a in dic):
        dic[a] = []
    dic[a].append(b)

v_list = [0 for _ in range(n)]

for _ in range(q):
    a, b = map(int, input().split())
    v_list[a-1] += b

key_list = list(dic.keys())
key_list.sort()

for a in key_list:
    for b in dic[a]:
        v_list[b-1] = v_list[a-1] + v_list[b-1]

print(*v_list)


Measured memory_bytes: 66560
# -*- coding: utf-8 -*-
"""
Dynamic Arrays and List - List
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_1_C&lang=jp

"""

class Node:
    def __init__(self, value=0):
        self.key = value
        self.prev, self.next = None, None

class Lst:
    def __init__(self):
        self.nil = Node('END')
        self.nil.next = self.nil
        self.nil.prev = self.nil
        self.cur = self.nil

    def insert(self, value):
        x = Node(value)
        x.prev = self.cur.prev
        self.cur.prev.next = x
        self.cur.prev = x
        x.next = self.cur
        self.cur = x

    def move(self, d):
        if d >= 0:
            for _ in range(d):
                self.cur = self.cur.next
        else:
            for _ in range(abs(d)):
                self.cur = self.cur.prev


    def erase(self):
        if self.cur == self.nil:
            return
        p = self.cur.next
        self.cur.prev.next = self.cur.next
        self.cur.next.prev = self.cur.prev
        self.cur = p


lst = Lst()
for _ in range(int(input())):
    op, n = (input() + ' 1').split()[:2]
    if op == '0':
        lst.insert(int(n))
    elif op == '1':
        lst.move(int(n))
    else:
        lst.erase()

cur = lst.nil
while cur.next != lst.nil:
    cur = cur.next
    print(cur.key)



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

using namespace std;

const long long MOD = 1000000007;

int GCD(int a, int b){return b == 0 ? a : GCD(b, a % b);}

vector<pair<int, pair<int, int>>> edges;

vector<pair<int, int>> hor, ver;

int dsu[100002], ranks[100002];

int FIND(int node){
    if(node == dsu[node])
        return node;
    return dsu[node] = FIND(dsu[node]);
}

void UNION(int a, int b){
    a = FIND(a); b = FIND(b);
    if(a == b) return;
    if(ranks[a] < ranks[b]){
        dsu[a] = b;
    } else if(ranks[b] < ranks[a]){
        dsu[b] = a;
    } else {
        dsu[a] = b;
        ++ranks[b];
    }
}


int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);

    int n;
    cin >> n;

    for(int i = 0; i < n; ++i){
        int x, y;
        cin >> x >> y;
        hor.push_back(make_pair(x, i));
        ver.push_back(make_pair(y, i));
        dsu[i] = i;
    }

    sort(hor.begin(), hor.end());
    sort(ver.begin(), ver.end());

    for(int i = 1; i < n; ++i){
        edges.push_back(make_pair(abs(hor[i].first - hor[i - 1].first), make_pair(hor[i].second, hor[i - 1].second)));
        edges.push_back(make_pair(abs(ver[i].first - ver[i - 1].first), make_pair(ver[i].second, ver[i - 1].second)));
    }

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

    long long cost = 0, nodes = 1;

    for(pair<int, pair<int, int>> i : edges){
        if(FIND(i.second.first) == FIND(i.second.second))
            continue;
        ++nodes;
        cost += i.first;
        if(nodes == n)
            break;
        UNION(i.second.first, i.second.second);
    }

    cout << cost;

    return 0;
}


Measured memory_bytes: 7656
function Main(input){
     inputs = input.split('\n');
     //console.log(inputs);
     if(inputs[4] - inputs[0] <=inputs[5]){
     console.log('Yay!');
     }else{
     console.log(':(');
     }
}
  
Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;
const double PI=acos(-1);
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; }

int main(){
	ll d,t,s; cin >> d >> t >> s;
	if(d <= t * s){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main()
{
    int H,W;
    cin>>H>>W;
    char arr[H][W];
    for(int i=0;i<H;i++){
        cin>>arr[i];
    }
    
    int newLength=2*H;
    // cout<<"old: "<<H<<" ;new: "<<newLength<<endl;
    
    for(int i=0;i<newLength;i++){  
        int newI=i/2;
    // cout<<"newI: "<<H<<" ;new: "<<newLength<<endl;
        for(int j=0;j<W;j++){ 
            cout<<arr[newI][j];
        }
        cout<<endl;
    }
    
    return 0;
}

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int64_t level(int64_t x, int64_t y) {
    assert(x != y);

    int64_t l = 0;
    while (((x >> l) ^ (y >> l)) % 2 == 0) {
        ++l;
    }

    return l + 1;
}

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

    for (auto i : irange(0L, n - 1)) {
        const auto* delim = "";
        for (auto j : irange(i + 1, n)) {
            cout << delim << level(i, j);
            delim = " ";
        }
        cout << endl;
    }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define print(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n, h;
	cin >> h >> n;
	READARR(a, n);
	
	int sum = 0;
	FOR (i, 1, n) sum += a[i];
	if (sum >= h) cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 1024
#!/usr/bin/env python3

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n, m = mi()
    X = lmi()
    X.sort()
    if m <= n:
        print(0)
    else:
        diff = [X[i] - X[i-1] for i in range(1, m)]
        diff.sort()
        print(sum(diff[:m-n]))


if __name__ == "__main__":
    main()


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

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

	int n=Integer.parseInt(br.readLine());

	ArrayList<ArrayList<Edge>> edge=new ArrayList<>();

	for(int i=0;i<n;i++)
	    edge.add(new ArrayList<>());

	for(int i=0;i<n;i++){
	    String str[]=br.readLine().split(" ");

	    int u=Integer.parseInt(str[0]);
	    int k=Integer.parseInt(str[1]);
	    for(int j=2;j<=k*2;j+=2){
		int v=Integer.parseInt(str[j]);
		int c=Integer.parseInt(str[j+1]);

		edge.get(u).add(new Edge(v,c));
	    }
	}
	int dist[]=dijkstra(edge,n,0);

	for(int i=0;i<n;i++){
	    System.out.println(i+" "+dist[i]);
	}
    }

    static int[] dijkstra(ArrayList<ArrayList<Edge>> edge,int n,int s){
	int dist[]=new int[n];
	int color[]=new int[n];
	PriorityQueue<Edge> pq=new PriorityQueue<>();

	Arrays.fill(dist,Integer.MAX_VALUE);
	Arrays.fill(color,0);
	dist[s]=0;
	color[s]=1;
	pq.add(new Edge(s,0));

	while(!pq.isEmpty()){
	    Edge e=pq.poll();
	    color[e.to]=2;

	    if (dist[e.to] < e.cost) {
		 continue;
	    }
	    
	    for(Edge v: edge.get(e.to)){
		if(color[v.to]==2)continue;
		
		if(dist[v.to]>dist[e.to]+v.cost){
		    dist[v.to]=dist[e.to]+v.cost;
		    pq.add(new Edge(v.to,dist[v.to]));
		    color[v.to]=1;
		}
	    }
	}
	return dist;
    }
    
}
class Edge implements Comparable<Edge>{

    int to;
    int cost;

    public Edge(int to, int cost){
	this.to=to;
	this.cost=cost;
    }
    @Override
    public int compareTo(Edge e){
	return this.cost-e.cost;
    }
}



Measured memory_bytes: 82092
# include <stdio.h>
 int main()
{ int N,K,X,Y;
  scanf("%d%d%d%d",&N,&K,&X,&Y);
  int sum=0;int i;
  for(i=1;i<=K&&i<=N;i++)
  sum=sum+X;
  for(i=K+1;i<=N;i++)
  sum=sum+Y;
  printf("%d",sum);
  return 0;
}

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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a) accumulate(all(a), 0LL)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
int const inf = 1e9;
ll const INF = 1e18;

inline void ios_(){cin.tie(0); ios::sync_with_stdio(false);}
template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}



signed main(){
    string s;
    int k;
    cin >> s >> k;
    int n = s.size();

    vector<vector<vector<ll>>> dp(n+1, vector<vector<ll>>(5, vector<ll>(2, 0)));
    dp[0][0][0] = 1;

    REP(i, n){
        int d = s[i] - '0';
        REP(j, 4){
            REP(c, 10){
                if(c <= d){
                    dp[i+1][j + (c > 0)][(c < d)] += dp[i][j][0];
                }
                dp[i+1][j + (c > 0)][1] += dp[i][j][1];
            }
        }
    }

    cout << dp[n][k][0] + dp[n][k][1] << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

void solve() {
	ll a, b , c , d;
	cin >> a >> b >> c >> d;
	ll x = ceil(1.0*c/b);
	ll y = ceil(1.0*a/d);
	if (x <= y) {
		cout << "Yes\n";
	} else {
		cout << "No\n";
	}
}

int main() {
	int t = 1;
	//cin >> t;
	while(t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 3740
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1626
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>
using ll = long long;
using namespace std;

int const MOD = 1e9 + 7;

int main(void)
{
    ll b;
    while (cin >> b, b)
    {
        int n, m;
        for (ll i = 0;; ++i)
        {
            ll t = b - (i + 1) * i / 2;

            if (t <= 0)
                break;
            if (t % (i + 1) != 0)
                continue;
            n = t / (i + 1);
            m = i + 1;
        }
        cout << n << " " << m << endl;
    }
    return 0;
}


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

int main(){
    int N;
    int A;

    cin >> N >> A;
    while (N >= 500){
        N -= 500;
    }
    if(A >= N)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
}

Measured memory_bytes: 384
n = int(input())
G = [[] for _ in range(n)]
for _ in range(n):
    u, k, *v = [int(i) for i in input().split()]
    G[u - 1] = v
NIL = 100
Q = [[1, 0]]
F = []
D = [NIL for _ in range(n)]
while Q != []:
    u, d = Q.pop(0)
    if d < D[u-1]:
        D[u-1] = d
    if u not in F:
        F.append(u)
    for v in G[u-1]:
        if v not in F:
            Q.append([v, d+1])
'''
for ni in range(1, n):
    Q = [[ni+1, 0]]
    F = []
    while Q != []:
        u, d = Q.pop(0)
        if u == 1 and d < D[ni]:
            D[ni] = d
        if u not in F:
            F.append(u)
        for v in G[u-1]:
            if v not in F:
                Q.append([v, d+1])
'''
for ni in range(n):
    if D[ni] == NIL:
        print(ni+1, -1)
    else:
        print(ni+1, D[ni])


Measured memory_bytes: 9796
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int S = sc.nextInt();
		int count = 0;
		for (int x = 0; x <= K; x++) {
			for (int y = 0; y <= K; y++) {
				int z = S - (x + y);
				if(0 <= z && z <= K) {
					count++;
				}
			}
		}
		System.out.print(count);		
	}
}


Measured memory_bytes: 35556
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,M;
    cin >> N >> M;
    vector<P> V(M);
    rep(i,0,M){
        cin >> V[i].second >> V[i].first;
    }
    sort(V.begin(), V.end());
    int cnt = 0, idx = -1;
    rep(i,0,M){
        if(idx <= V[i].second || idx > V[i].first){
            idx = V[i].first;
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 1024
N,K = map(int,input().split())

POINT = tuple(map(int,input().split()))

T = input()
m = {'r':0,'s':1,'p':2}
T = [m[h] for h in T]

def helper(T):
    dp = [0]*3
    for t in T:
        wh = (t-1)%3
        op = max(dp)
        dp[wh] = max(v for i,v in enumerate(dp) if i != wh)+POINT[wh]
        for h in range(3):
            if h != wh:
                dp[h] = op
    return max(dp)


res = sum(helper(T[i::K]) for i in range(min(K,N)))

print(res)



Measured memory_bytes: 79596
#include<iostream>
#include<vector>
#include <cfenv>
#include <cmath>
#include <utility>
#include<algorithm>
#include<string>
#define ll long long
using namespace std;

int main(){
    ll N,a,ans=0;
    cin >> N;
    vector<ll> A;
    for (ll i = 0; i < N; i++){
        cin >> a;
        A.push_back(a);
    }
    for(ll i = 1; i < N; i++){
        ans ^= A[i];
    }
    cout << ans;
    for (int i = 0; i < N-1; i++){
        ans ^= A[i];
        ans ^= A[i+1];
        cout << " " << ans;
    }
    cout << endl;
}

Measured memory_bytes: 5312
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
	int n;
	cin >> n;
	vector<int> h(n);
	for (int i = 0; i < n; ++i) cin >> h[i];
	vector<int> flowers(n, 0);
	int ans = 0;
	while (h != flowers) {
		bool sectionStarted = false;
		for (int i = 0; i < n; ++i) {
			if (flowers[i] == h[i] && sectionStarted == false) 
				continue;
			if (flowers[i] == h[i] && sectionStarted == true)
				break;
			if (flowers[i] < h[i])
				++flowers[i], sectionStarted = true;
		}
		if (sectionStarted == true) ++ans;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

#define MOD 1000000007

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  ll n; cin >> n;
  ll allrow = 1;
  ll lostBoth = 1;
  ll lost0 = 1;
  ll lost9 = 1;
  for(int i = 0; i < n; i++){
    allrow *= 10;
    lostBoth *= 8;
    lost0 *= 9;
    lost9 *= 9;
    allrow %= MOD;
    lostBoth %= MOD;
    lost0 %= MOD;
    lost9 %= MOD;
  }
  cout << ((allrow - lost0 - lost9 + lostBoth)%MOD + MOD) % MOD << endl;

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 3588
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

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

    int x_max=Y/10000;
    int y_max=Y/5000;
    int z_max=Y/1000;

    for(int x=0;x<=x_max;x++){
        for(int y=0;y<=y_max;y++){
            int z=N-x-y;
            if(z<0) continue;
            int sum = x*10000+y*5000+z*1000;

            if(sum==Y){
                printf("%d %d %d\n",x,y,z);
                return 0;
            }
        }
    }
    printf("-1 -1 -1\n");
    return 0;
}

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

using namespace std;
using ll = long long;

int main()
{
  ios_base::sync_with_stdio (0);
  cin.tie (0);
  ll n;
  cin >> n;
  vector<ll>a (n + 1), b (n);
  for (ll i = 0; i <= n; i++) {
    cin >> a[i];
  }
  for (ll i = 0; i < n; i++) {
    cin >> b[i];
  }
  ll ans = min (a[0], b[0]);
  b[0] -= min (a[0], b[0]);
  for (ll i = 1; i < n; i++) {
    ans += min (a[i], b[i - 1]);
    a[i] -= min (a[i], b[i - 1]);
    ans += min (a[i], b[i]);
    b[i] -= min (a[i], b[i]);
  }
  ans += min (a[n], b[n - 1]);
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>

int SWITCH(int a){
a=(a/10)+(a%10)*10;
return a;
}

int main(void){
int a,b;
scanf("%d %d",&a,&b);


int x=(a+99)/100,y=b/100,count;
count=y-x;


int xc=x/10,yc=y/10;

if((x-1)*100+SWITCH(xc)>=a) ++count;
if(y*100+SWITCH(yc)<=b) ++count;

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

return 0;
}

Measured memory_bytes: 128
#coding: utf-8

n = int(input())

def f(level):
    if level == 1:
        return ["a"]
    ret = []
    for x in f(level-1):
        s = sorted(list(set( (c for c in x))))
        s.append(chr(ord(s[-1])+1))
        for c in s:
            ret.append(x + c)
    return ret

print("\n".join(f(n)))



Measured memory_bytes: 18644
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//using static System.Console;

namespace CF2016A_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = scan[0];
            var a = scan;
            var G = new HashSet<KeyValuePair<int, int>>();
            int cnt = 0;
            for (int i = 0; i < N; i++)
            {
                var p = new KeyValuePair<int, int>(i+1, a[i]);
                var q = new KeyValuePair<int, int>(a[i], i+1);
                if (G.Contains(q)) cnt++;
                else
                {
                    G.Add(p);
                    //Console.WriteLine(p.ToString());
                }
            }
            Console.WriteLine(cnt);
        }

        static int[] scan { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } }
    }
}


Measured memory_bytes: 19152
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class Counter
{
	readonly Dictionary<int, int> c = new Dictionary<int, int>();
	public int this[int x] { get { return c.ContainsKey(x) ? c[x] : 0; } }
	public void Add(int x)
	{
		if (c.ContainsKey(x)) c[x]++;
		else c[x] = 1;
	}
}
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G();
		WriteLine(Max(0, I[0] - I[1]));
	}
}


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

int main() {
  int N;
  cin >> N;
  
  vector<string> blue;
  
  for(int i=0; i<N; i++)
  {
    string s;
    cin >> s;
    blue.push_back(s);
  }
  
  int M;
  cin >> M;
  
  vector<string> red;
  
  for(int i=0; i<M; i++)
  {
    string s;
    cin >> s;
    red.push_back(s);
  }
  
  int max_count = 0;
  
  for(int i=0; i<N; i++)
  {
    int count = 0;
    string word = blue[i]; 
//    cout << word << endl;
    
    for(int j=0; j<N; j++)
    {
      if(blue[j] == word) count++;
    }
    
    for(int j=0; j<M; j++)
    {
      if(red[j] == word) count--;
    }
    
    if(max_count < count) max_count = count;
  }
  
  cout << max_count << endl;
  
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
	int D, N; cin >> D >> N;
 
	int S = 1; for (int i = 0; i < D; i++) S *= 100;
	if (N <= 99) {
		cout << S * N << endl;
	}
	else {
		cout << S * 101 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
import numpy as np

N, M, X = map(int, input().split())
C = []
A = [[] for i in range(M)]
resC = []
resA = list(A)

NEW = 0

def update(base):
  #print(NEW,base)
  if base==None:
    return NEW
  return base + NEW

def check(num):
  return num>=X

def check2(*args):
  res = True
  for val in args:
    buf = (val >= X)
    res = res and buf
  return res

for i in range(N):
  buf = list(map(int, input().split()))
  C.append(buf[0])
  for j in range(M):
    A[j].append(buf[j+1])

for i in range(N):
  if i == 0:
    NEW = C[i]
    resC = [0, NEW]
    resA = [[0, A[j][i]] for j in range(M)]
  else:
    NEW = C[i]
    resC = resC + list(map(update, resC))
    for j in range(M):
      NEW = A[j][i]
      resA[j] = resA[j] + list(map(update, resA[j]))

res = list(map(check2, *resA))
#print(np.asarray(resC)[res]) 
if sum(res)==0:
  print(-1)
else:
  print(min(np.asarray(resC)[res]))

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

using ll = long long;
using namespace std;
const int INFint = 1e9+1;
const ll INFll = (ll)1e18+1;
ll MOD=1e9+7;


int main(){
  int N;
  cin>>N;
  vector<ll> A(N),B(N);
  for(int i(0);i<N;i++){
    cin>>A[i]>>B[i];
  }
  sort(A.begin(),A.end());
  sort(B.begin(),B.end());
  if(N % 2 == 1){
    ll hidari = A[N/2];
    ll migi = B[N/2];
    cout << migi - hidari + 1 << endl;
  }else{
    ll hidari = (A[N/2]+A[N/2-1]);
    ll migi = (B[N/2]+B[N/2-1]);
    cout << migi - hidari+1 << endl;
  }
  return 0;
}


Measured memory_bytes: 6404
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdio>
using namespace std;

static const int INF=1e9;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    ll N;
    cin >> N;
    ll ans;
    ans=(2+N)*(N-1)/2;
    if(N%2!=0){
        ans-=N-1;
    }else{
        ans-=N;
        ans+=1;
    }
    cout << ans << endl;


}


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

int main() {
    string S;
    cin >> S;
    bool flag = false;
    if (S[0] == S[1] and S[2] == S[3]){
        if (S[1] == S[2]) {
            flag = false;
        }else{
            flag = true;
        }
        
    }else if (S[0] == S[2] and S[1] == S[3]){
        flag = true;
    }else if (S[0] == S[3] and S[1] == S[2]){
        flag = true;
    }
    if (flag){
        cout << "Yes";
    }else {
        cout << "No"; 
    }
}

Measured memory_bytes: 256
#include <stdio.h>

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

Measured memory_bytes: 128