akhauriyash/Code-Regression huggingface dataset:
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes = "Yes", T no = "No") { cout << (val ? yes : no) << endl; }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}


#line 2 "abc165_b.cpp"

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

  ll x;
  cin >> x;
  ll cur = 100;
  int ans = 0;
  while (cur < x) {
    cur += (cur) / 100;
    ans++;
  }
  cout << ans << endl;
}


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

long int GCD(long int a, long int b){
  if(a < b){long int c = a; a = b; b = c;}
  while(true){
    long int c = a % b;
    if(c == 0) return b;
    a = b;
    b = c;
  }
  return 0;
}

long int LCM(long int a, long int b){
  return a * b / GCD(a, b);
}

int main(){
  long int a, b;
  while(cin >> a >> b){
    cout << GCD(a, b) << " " << LCM(a, b) << endl;
  }
  return 0;
}


Measured memory_bytes: 1160
import java.util.*;

public class Main {
    public static int[] xAdj = {-1,0,1,0};
    public static int[] yAdj = {0,-1,0,1};
    public static int left = 0;
    public static int right = 0;
    public static int up = 0;
    public static int down = 0;
    
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        while (true) {
            int N = sc.nextInt();
            if (N == 0) break;
            
            Square[] squares = new Square[N];
            squares[0] = new Square(0, 0);
            
            left = 0;
            right = 0;
            up = 0;
            down = 0;
            
            for (int i = 1; i < N; i++) {
                int pos = sc.nextInt();
                int dir = sc.nextInt();
                int x = squares[pos].x + xAdj[dir];
                int y = squares[pos].y + yAdj[dir];
                squares[i] = new Square(x, y);
            }
            
            int w = right - left + 1;
            int h = up - down + 1;
            System.out.println(w + " " + h);
        }
    }
    
    public static class Square {
        int x;
        int y;
        
        public Square(int x, int y) {
            this.x = x;
            this.y = y;
            left = Math.min(left, x);
            right = Math.max(right, x);
            up = Math.max(up, y);
            down = Math.min(down, y);
        }
    }
}




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


int main(){

  string s;
  map<string,int> m;
  while(cin >> s){
    for(int i=0; i<s.size(); i++){
      string sub = s.substr(i,1);
      if("A"  <= sub && sub <= "Z") sub[0] += 32;
      if("a"  <= sub && sub <= "z"){
	if(m.find(sub) == m.end())
	  m[sub] = 1;
	else
	  m[sub]++;
      }
    }
  }
  s = "a";
  for(int i=0; i<26; i++){
    cout << s << " : " << m[s] << endl;
    s[0]++;
  }
}

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

using namespace std;


#define si(a) scanf("%d", &a)
#define sii(a, b) scanf("%d %d", &a, &b)
#define siii(a, b, c) scanf("%d %d %d", &a, &b, &c)

#define sl(a) scanf("%I64d", &a)
#define sll(a, b) scanf("%I64d %I64d", &a, &b)
#define slll(a, b, c) scanf("%I64d %I64d %I64d", &a, &b, &c)

#define outi(a) printf("%d\n", a)
#define outii(a, b) printf("%d %d\n", a, b)
#define outiii(a, b, c) printf("%d %d %d\n", a, b, c)

#define outl(a) printf("%I64d\n", a)
#define outll(a, b) printf("%I64d %I64d\n", a, b)
#define outlll(a, b, c) printf("%I64d %I64d %I64d\n", a, b, c)

#define cel(n, k) ((n-1)/k+1)
#define sets(a) memset(a, -1, sizeof(a))
#define clr(a) memset(a, 0, sizeof(a))


#define fr(i, n) for(ll i=0; i<n;i++)
#define fr1(i, n) for(ll i=1; i<=n;i++) 

#define readf(f) freopen(f, "r", stdin)
#define writef(f) freopen(f, "w", stdout)

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(), v.end()

template< class T > T sq(T x) { return x * x; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }

typedef long long ll;
typedef pair<int,int> pii;


int main()
{
    // #ifndef LOCAL
    // readf("in.txt");
    // writef("out.txt");
    // #endif

    int h, n, a, total = 0;
    cin>>h>>n;

    fr(i,n){
        cin>>a;
        total += a;
    }

    if(total >= h)
        puts("Yes");
    else
        puts("No");
    
    


    return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines

def main():
    s = tuple(input())
    t = tuple(input())
    s_len = len(s)
    t_len = len(t)
    r = s_len
    for i1 in range(s_len - t_len + 1):
        s2 = s[i1:i1 + t_len + 1]
        tmp0 = sum([se != te for se, te in zip(s2, t)])
        r = min(r, tmp0)
    print(r)

if __name__ == '__main__':
    main()


Measured memory_bytes: 67544
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

int main() {
    int n, a;
    cin >> n >> a;
    vector<ll> x(n);
    rep(i, n) {
        cin >> x[i];
        x[i] -= a;
    }

    vector<vector<ll> > dp(2, vector<ll>(5003));
    dp[0][2501] = 1;
    vector<ll>::iterator now = dp[0].begin();
    vector<ll>::iterator next = dp[1].begin();
    rep(i, n) {
        rep(j, 5003) {
            if(now[j]) {
                next[j] += now[j];
                next[j+x[i]] += now[j];
            }
        }
        swap(now, next);
        rep(j, 5003) {
            next[j] = 0;
        }
    }

    cout << now[2501]-1 << endl;

}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
int A; int B; int C; cin>>A>>B>>C;
  int L=max(A,B);
  int K=0;
  int X=0;
  while(K<C){
    X++;
    K+=L;
  }
  cout<<X<<endl;
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    i32 n; cin >> n;
    vec<vi> graph(n);
    i32 m = 0;
    for(int i = 0; i < n-1; ++i) {
        for(int j = i+1; j < n; ++j) {
            int v = i + 1;
            int u = j + 1;
            if(n&1) {
                if(u+v == n) continue;
                graph[i].push_back(j);
                ++m;
            }
            else {
                if(u+v == n+1) continue;
                graph[i].push_back(j);
                ++m;
            }
        }
    }

    // output
    cout << m << '\n';
    rep(u,n) {
        for(auto v : graph[u]) cout << u+1 << ' ' << v+1 << '\n';
    }

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 384
#include <stdio.h>

int s,head,comp[100],count[100],out[100];
int graph_s[100][100];

void DFS_s(int x){
  int i;
  comp[x]=1;
  count[x]=++s;
  for(i=0;i<head;i++){
    if(graph_s[x][i]==0) continue;
    if(comp[i]==0){
      DFS_s(i);
    }
  }
    comp[x]=2;
    out[x]=++s;
}
  

void DFS_clear(){
  int i;
  for(i=0;i<head;i++) comp[i]=0;
  s=0;
  for(i=0;i<head;i++){
    if(comp[i]==0) DFS_s(i);
  }

  for(i=0;i<head;i++){
    printf("%d %d %d\n",i+1,count[i],out[i]);
  }
}

int main(){
  int nu,out,near,i,j;

  scanf("%d",&head);

  for(i=0;i<head;i++){
    for(j=0;j<head;j++){
      graph_s[i][j]=0;
    }
  }

  
  for(i=0;i<head;i++){
    scanf("%d%d",&nu,&out);
    for(j=0;j<out;j++){
      scanf("%d",&near);
      graph_s[nu-1][near-1]=1;
    }
  }

  DFS_clear();

  
  return 0;
}



Measured memory_bytes: 2108
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import java.util.StringTokenizer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main {
    public static void main(final String[] args) {
        final FastScanner scanner = new FastScanner(System.in);
        final int n = scanner.nextInt();
        final List<Integer> aList = IntStream.range(0, n)
            .mapToObj(i -> scanner.nextInt())
            .collect(Collectors.toList());
        final List<Integer> bList = IntStream.range(0, n)
            .mapToObj(i -> scanner.nextInt())
            .collect(Collectors.toList());

        long twoIncrease = 0;
        long oneIncrease = 0;
        for (int i = 0; i < n; i++) {
            final int a = aList.get(i);
            final int b = bList.get(i);
            if (a >= b) {
                oneIncrease += a - b;
            } else if ((b - a) % 2 == 0) {
                twoIncrease += (b - a) / 2;
            } else {
                twoIncrease += (b - a + 1) / 2;
                oneIncrease++;
            }
        }

        if (twoIncrease >= oneIncrease) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

    private static class FastScanner {
        private final BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(final InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}
    

Measured memory_bytes: 40248
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


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

	cin >> N;
	if (N == 2) {
		cout << -1 << endl;
		return 0;
	}
	vector<long long int>v(N);
	map<long long int, int>m;
	map<long long int, int>used;
	L = LLONG_MAX;
	for (int i = 0; i < N; i++) {
		cin >> v[i];
		m[v[i]] = i + 1;
		L = min(L, v[i]);
	}
	vector<pair<int, int>>ans;
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
	for (auto i : v) {
		if (i == L)break;
	//	cout << i << endl;
		long long int dif = N - 2 - used[i] * 2;
		long long int box = i;
		if (m.find(box - dif) == m.end()) {
			cout << "-1\n";
			return 0;
		}
		ans.push_back({ m[box],m[box - dif] });
	//	cout << box << " " << box - dif << endl;
		used[box - dif] += used[box] + 1;
		box -= dif;
		dif -= 2;
	}
	vector<vector<int>>edge(N + 1);
	for (auto i : ans) {
		edge[i.first].push_back(i.second);
		edge[i.second].push_back(i.first);
	}
	vector<int>dis(N + 1, MOD);
	dis[m[L]] = 0;
	queue<int>Q;
	Q.push(m[L]);
	while (!Q.empty()) {
		int cn = Q.front(); 
		Q.pop();
		for (auto i : edge[cn]) {
			if (dis[i] > dis[cn] + 1) {
				dis[i] = dis[cn] + 1;
				Q.push(i);
			}
		}
	}
	long long int sum = 0;
	for (int i = 1; i <= N; i++) {
		sum += dis[i];
	}
	if (sum != L) {
		cout << -1 << endl;
		return 0;
	}
	for (auto i : ans) {
		cout << i.first << " " << i.second << endl;
	}
	return 0;
} 


Measured memory_bytes: 22488
#include<stdio.h>
int gcd(int x, int y);
void swap(int* x, int* y);
int main (void){
    int x, y;
    scanf("%d", &x); scanf("%d", &y);
    printf("%d\n",gcd(x,y));

    return 0;
}

int gcd(int x, int y){
    int r;
    if(x < y){
        swap(&x, &y);
    }
    while(y > 0){
        r = x % y;
        x = y;
        y = r;
    }

    return x;
}

void swap(int* x, int* y){
    int temp;
    temp = *x;
    *x = *y;
    *y = temp;
    return;
}


Measured memory_bytes: 2100
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	h,w = readline() |> split |> parseMap
	for i in 1:h
		s = readline() |> split
		for j in 1:w
			if s[j][1:5] == "snuke"
				println(Char(64+j),i)
				break
			end
		end
	end
end
main()


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

int main(){
    ll N;
    cin >> N;
    vector<tuple<string, int, ll>> restaurants(N);
    for(int i = 0; i < N; i++){
        string str;
        int score;
        cin >> str >> score;
        tuple<string, int, ll> t(str, 100 - score, i);
        restaurants.at(i) = t;
    }

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

    for(tuple<string, int, ll> t: restaurants){
        cout << get<2>(t) + 1 << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

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

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

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const long double PI = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899;
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};


signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);

    int N; cin >> N;
    VI ng(1123456);
    VI cnt(1123456);
    VI x;
    REP(i,N){
        int t; cin >> t;
        cnt[t]++;
    }
    int ans = 0;
    REP(i,1123456){
        if(cnt[i] == 0) {
            continue;
        }
        if(cnt[i] >= 2){
            if(i <= 1000) x.eb(i);
            else{
                for(int j=i; j < 1123456; j+=i){
                    ng[j] = 1;
                }

            }
            continue;
        }
        if(i > 1000){
            if(ng[i] == 0) {
                bool ok = true;
                for(int tmp : x){
                    if(i%tmp == 0) {
                        ok = false;
                        break;
                    }
                }
                if(ok) ans++;
            }
            for(int j=i; j < 1123456; j+=i){
                ng[j] = 1;
            }

        }else{
            bool ok = true;
            for(int tmp : x){
                if(i%tmp == 0){
                    ok = false;
                    break;
                }
            }
            if(ok) ans++;
            x.eb(i);
        }

    }
    cout << ans << endl;

}

Measured memory_bytes: 11888
n, m = map(int, input().split())

s = input()

d = [0] * n
cnt = 0
for i in range(n-1):
    if s[i] == 'A' and s[i+1] == 'C':
       cnt += 1
    d[i+1] = cnt

for _ in range(m):
    a, b = map(int, input().split())
    print(d[b-1] - d[a-1])


Measured memory_bytes: 6188
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <map>           // sorted map so O(logn)
#include <unordered_map> // O(1)
typedef long long ll;
using namespace std;

int main()
{
    string s, t;
    cin >> s >> t;
    if (t.length() == s.length() + 1 && t.substr(0, t.length() - 1) == s)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3620
#include<stdio.h>
int gcd( int m, int n ){
	// ?????°?????????????????´??????????????????
	if (0==m||0==n){
		return 0;
	}
	// ???????????????????????????
	while(m!=n){
		if(m>n){
			m=m-n;
		}
		else{
			n=n-m;
		}
	}
	return m;
}
int main(void){
	int a,b,c,d,p,q,r,s,tx,ty,tt,k;
	while(1){
		scanf("%d %d %d",&a,&b,&c);
		if(a==0&&b==0&&c==0){
			break;
		}
		if(c==0){
			if(a==1){
				if(b>0){
					printf("%d %d %d %d\n",1,b,1,0);
				}
				else{
					printf("%d %d %d %d\n",1,0,1,b);
				}
			}
			else{
				printf("%d %d %d %d\n",a,b,1,0);
			}
		}
		else{
			d=b*b-4*a*c;//?????\???
			if(d<0){
				printf("Impossible\n");
			}
			else if(d==0){//?§£???-b/2a gcd??§?´????
				p=tx=-b;
				q=ty=2*a;
				if(tx<0){
					tx=tx*(-1);
				}
				if(ty<0){
					ty=ty*(-1);
				}
				r=gcd(tx,ty);
				p/=r;
				q/=r;
				printf("%d %d %d %d\n",q,-p,q,-p);
			}
			else{
				k=1;
				while(k*k<=d){
					if(k*k==d){	
						break;
					}
					k++;
				}
				if(k*k>d){
					printf("Impossible\n");
				}
				else{
					p=tx=2*a;
					q=ty=-b+k;
					if(tx<0){
					tx=tx*(-1);
					}
					if(ty<0){
						ty=ty*(-1);
					}
					tt=gcd(tx,ty);
					p/=tt;
					q/=tt;
					r=tx=2*a;
					s=ty=-b-k;
					if(tx<0){
					tx=tx*(-1);
					}
					if(ty<0){
						ty=ty*(-1);
					}
					tt=gcd(tx,ty);
					r/=tt;
					s/=tt;
					q=-q;
					s=-s;
					if(p>r||(p==r&&q>s)){
						printf("%d %d %d %d\n",p,q,r,s);
					}
					else{
						printf("%d %d %d %d\n",r,s,p,q);
					}
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 612
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/



//ユークリッド互除法
template<typename T>
T gcd(T x, T y) {

	if (y == 0) {
		return x;
	}
	else {
		return gcd(y, x % y);
	}
}

/*最小公倍数*/
template<typename T>
T lcm(T x, T y) {
	T tmp = gcd(x, y);
	
	return x * y / tmp;
}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);


	int a, b, c;
	cin >> a >> b >> c;
	if (a + b + c >= 22) {
		cout << "bust" << endl;
	}
	else
	{
		cout << "win" << endl;
	}





	



	return 0;
}


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

int main(){
  int N,M;cin >> N >> M;
  long sum=0;
  priority_queue<long> pq;
  for(int i=0; i<N; i++){
    long A;cin >> A;
    sum+=A;
    pq.push(A);
  }
  for(int i=0; i<M; i++){
    sum-=(pq.top()+1)/2;
    pq.push(pq.top()/2);
    pq.pop();
  }
  cout << sum << endl;
}

Measured memory_bytes: 1400
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cassert>
#include <string>
#include <cstring>
#include <bitset>
 
#define FOR(i, a, b) for(int i = a; i < (int) b; i++)
#define F0R(i, a) FOR (i, 0, a)
#define ROF(i, a, b) for(int i = a; i >= (int) b; i--)
#define R0F(i, a) ROF(i, a, 0)
#define GO(i, a) for (auto i : a)
 
#define rsz resize
#define eb emplace_back
#define pb push_back
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define f first
#define s second
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;

const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int ms[] = {+31, +29, +31, 30, +31, +30, +31, +31, +30, +31, +30, +31};

const int N = 2e5 + 5;
int a [N], b [N];

i64 fen [N];

void update (int idx, i64 delta) {
  for (; idx < N; idx += idx & (- idx)) {
    fen[idx] = max (fen[idx], delta);
  }
}

i64 query (int idx) {
  i64 res = 0;
  for (; idx > 0; idx -= idx & (- idx)) {
    res = max (res, fen[idx]);
  }
  return res;
}
  
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  F0R (i, n) cin >> a[i];
  F0R (i, n) cin >> b[i];
  i64 mx = 0;
  F0R (i, n) {
    int current_height = a[i];
    int current_profit = b[i];
    i64 best_previous = query (current_height - 1);
    update (current_height, best_previous + current_profit);
    mx = max (mx, best_previous + current_profit);
  }
  cout << mx << '\n';
  return 0;
}


Measured memory_bytes: 3328
#include <stdio.h>

int main() {
    int n, k, h = 1;
    scanf("%d %d", &n, &k);
    for(int i = 1; i <= n; i++){
        if(h <= k){
            h *= 2;
        }
        else{
            h += k;
        }
    }
    printf ("%d\n", h);
    return 0;
}

Measured memory_bytes: 1708
#include<set>
#include<map>
#include<stack>
#include<cmath>
#include<queue>
#include<deque>
#include<cstdio>
#include<vector>
#include<climits>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
LL read(){
	LL f=1,x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+c-'0',c=getchar();
	return f*x;
}
#define MAXN 50000
#define INF 0x3f3f3f3f
int main(){
	int a=read(),b=read(),k=read();
	for(int i=1;i<=k;i++){
		if(i&1){
			if(a%2) a--;
			b+=a/2,a/=2;
		}
		else{
			if(b%2) b--;
			a+=b/2,b/=2;
		}
	}
	printf("%d %d\n",a,b);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define re register
#define LL long long
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
inline int read() {
    char c=getchar();int x=0;while(c<'0'||c>'9') c=getchar();
    while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-48,c=getchar();return x;
}
int T,n,m;
int bf(int n) {
    if(n<m) return 0;if(n%m==0) return n/m;
    return bf(n-n/m-1);
}
int sg(int n) {
    if(n<m) return 0;if(n%m==0) return n/m;
    int x=n/m;int u=x*m;
    int h=(n-u)/(x+1);
    if(n-h*(x+1)==u) return x;
    return sg(n-(h+1)*(x+1));
}
int main() {
    int ans=0;
    for(re int T=read();T;--T) {
        n=read(),m=read();
        if(m<=n/m) ans^=bf(n);
        else ans^=sg(n);
    }
    if(ans) puts("Takahashi");
    else puts("Aoki");
    return 0;
}

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

// clang-format off
#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define endl '\n'
#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using i32 = int;
using u32 = unsigned int;
using i64 = long long;
using u64 = unsigned long long;

// constexpr i32 mod   = 998244353;
constexpr i32 mod   = 1e9 + 7;
constexpr i32 inf   = 1001001001;
constexpr i64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(int x = 15){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(x); cerr << fixed << setprecision(x); } } iosetup;

template <typename T = i64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }

template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_vector(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_vector(size_t a, Ts... ts) { return vector<decltype(make_vector(ts...))>(a, make_vector(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

void solver() {
    auto A = make_vector(3, 3, 0);
    cin >> A;
    
    int N = input();
    auto f = make_vector(3, 3, false);
    range(_, 0, N) {
        int b = input();
        
        range(i, 0, 3) range(j, 0, 3) if (A[i][j] == b) f[i][j] = true;
    }
    
    bool ans = false;
    if (f[0][0] && f[1][1] && f[2][2]) ans = true;
    if (f[0][2] && f[1][1] && f[2][0]) ans = true;
    range(i, 0, 3) if (f[i][0] && f[i][1] && f[i][2]) ans = true;
    range(j, 0, 3) if (f[0][j] && f[1][j] && f[2][j]) ans = true;
    
    cout << (ans ? "Yes" : "No") << endl;
}

signed main(int argc, char *argv[]) {
    solver();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926525
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------
ll n,q,a[200000],x;

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  cin>>n>>q;
  REP(i,n)cin>>a[i];
  REP(i,q){
    ll ans=0;
    ll sum=0;
    cin>>x;
    ll r=0;
    for(ll l=0;l<n;l++){
      while(r<n && sum+a[r]<=x){
        sum+=a[r];
        r++;
      }
      ans+=r-l;
      sum-=a[l];
    }
    P(ans);
  }
  return 0;
}



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

using namespace std;

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

    int res = 0;
    int sum = 0;
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == 'R') {
            sum++;
        } else {
            res = max(res, sum);
            sum = 0;
        }
    }

    cout << max(res, sum) << endl;

    return 0;
}


Measured memory_bytes: 3576
using System;
using System.Collections.Generic;
using System.Linq;

class MainClass
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
        Array.Sort(A);
        Array.Reverse(A);

        var friendliness = new PriorityQueue<long>(N + 1, (x, y) => -x.CompareTo(y));
        friendliness.Push(A[0]);

        long ans = 0;
        for (int i = 1; i < N; i++)
        {
            var t = friendliness.Pop();
            ans += t;
            friendliness.Push(A[i]);
            friendliness.Push(A[i]);
        }

        Console.WriteLine(ans);
    }

}

public class PriorityQueue<T>
{
    public long Size { get; private set; } = 0;
    public long MaxSize { get; private set; } = 0;
    public T[] m_heap;
    private Comparison<T> Comp = null;

    public PriorityQueue(long maxSize, Comparison<T> comp)
    {
        if (maxSize <= 0)
            throw new Exception();
        MaxSize = maxSize;
        m_heap = new T[maxSize];

        Comp = comp;
    }

    public void Push(T x)
    {
        if (Size == MaxSize)
        {
            T[] new_heap = new T[MaxSize << 1];
            Array.Copy(m_heap, new_heap, MaxSize);
            m_heap = new_heap;
            MaxSize <<= 1;
        }

        long i = Size++;
        while (i > 0)
        {
            long p = (i - 1) / 2;
            if (Comp(m_heap[p], x) <= 0)
                break;
            m_heap[i] = m_heap[p];
            i = p;
        }
        m_heap[i] = x;
    }

    public T Pop()
    {
        if (Size == 0)
            throw new Exception("Queue is empty.");

        T result = m_heap[0];
        T x = m_heap[--Size];
        long i = 0;
        while (i * 2 + 1 < Size)
        {
            long c1 = i * 2 + 1, c2 = i * 2 + 2;
            if (c2 < Size && Comp(m_heap[c2], m_heap[c1]) < 0)
                c1 = c2;
            if (Comp(m_heap[c1], x) >= 0)
                break;
            m_heap[i] = m_heap[c1];
            i = c1;
        }
        m_heap[i] = x;

        return result;
    }
}

Measured memory_bytes: 49312
#include <stdio.h>
#define max 100000

int a[max] , n;

int partition(int p , int r)
{
	int x , i , j , t;
	x = a[r];
	i = p - 1;
	for( j = p; j < r; j++)
	{
		if(a[j] <= x)
		{
			i++;
			t = a[i];
			a[i] = a[j];
			a[j] = t;
		}
	}
	t = a[i+1];
	a[i+1] = a[r];
	a[r] = t;
	return i + 1;
}

int main(void)
{
	int i , q;
	scanf("%d",&n);
	for( i = 0; i < n; i++)
	{
		scanf("%d",&a[i]);
	}
	q = partition(0,n-1);
	
	for( i = 0; i < n; i++)
	{
		if( i ) printf(" ");
		if( i == q) printf("[");
		printf("%d",a[i]);
		if( i == q) printf("]");
	}
	printf("\n");
	return 0;
}



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

const ll MAX = 1e9;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;

ll K;

int main(){
    cin >> K;

    int N = -1;
    for(int i = 2; i <= 50; ++i){
        if((N - 1) + K / i <= 1e16 + 1000){
            N = i;
            break;
        }
    }

    vector<ll> ans(N);
    rep(i, N) ans[i] = i + K / N;

    K %= N;
    rep(i, K){
        rep(j, N){
            if(i == j){
                ans[j] += N;
            } else {
                ans[j]--;
            }
        }
    }

    cout << N << endl;
    rep(i, N) cout << ans[i] << " ";
    cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<string>
#include<cstdio>
#include<stdlib.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> pii;
 
int main()
{
  ll i,j;
  ll n,x;
  ll a[100005]={};
  cin>>n>>x;
  rep(i,n)
    cin>>a[i];
  ll ans=0LL;
  rep(i,n-1)
    if(a[i]+a[i+1]>x){
      ll temp=a[i]+a[i+1]-x;
      if(a[i+1]>temp)
	a[i+1]-=temp;
      else
	a[i+1]=0;
      ans+=temp;
    }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
n,m,c = map(int,input().split())
b = list(map(int,input().split()))

ans = 0
for i in range(n):
    d = list(map(int,input().split()))
    su = 0
    for l in range(m):
        su += b[l]*d[l]
    if su+c > 0:
        ans += 1

print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
double dice(int i,int K){
    int k = i;
    int count = 0;
    while(k < K){
        k = k*2;
        count++;
    }
    //cout << pow(0.5,count) << endl;
    return pow(0.5, count);
}

int main(){
    int N,K;
    double ans=0;
    cin >> N >> K;
    for(int i= 1;i<=N;i++){
        ans += dice(i,K);
    }
    ans = ans / N;
    cout <<setprecision(12)<< ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  int a,b;
  cin >> a >> b;
  if(a > 9 || b > 9) cout << -1 << endl;
  else{
    cout << a*b << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

// 4方向（左、右、上、下）（左上を0, 0とした場合）
vector<long long> dx = {-1, 1, 0, 0};
vector<long long> dy = { 0, 0,-1, 1};

vector<string> s;
vvi globalchk;

ll bfs(ll i, ll j){
    ll cnt = 0;
    ll h = s.size();
    ll w = s[0].size();
    //vvi chk(h, vi(w, 0));
    ll gcnt = 1;
    globalchk[i][j] = 1;
    queue<pair<pair<ll, ll>, ll>> que;
    que.push(make_pair(make_pair(i, j), 0));
    // chk[i][j] = 1;
    while(que.size()){
        auto front = que.front();
        que.pop();
        ll x = front.first.second;
        ll y = front.first.first;
        char c = (front.second == 0 ? '#' : '.');
        for(ll d=0; d<4; d++){
            ll tx = x + dx[d];
            ll ty = y + dy[d];
            if(tx<0 || ty<0 || tx>w-1 || ty > h-1) continue;
            if(globalchk[ty][tx] == 1 || s[ty][tx] == c) continue;
            globalchk[ty][tx] = 1;
            que.push(make_pair(make_pair(ty, tx), front.second^1));
            if(s[ty][tx] == '.') cnt++;
            else{
                globalchk[ty][tx] = 1;
                gcnt++;
            }
        }
    }
    return cnt*gcnt;
}

int main(){
    Init();
    ll h, w; cin >> h >> w;
    globalchk.resize(h, vi(w, 0));
    s.resize(h);
    rep(i, h) cin >> s[i];
    ll ans = 0;
    rep(i, h) rep(j, w) if(s[i][j] == '#' && globalchk[i][j] == 0) ans += bfs(i, j);
    cout << ans << endl;
}

Measured memory_bytes: 5072
#include <iostream>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <cstring>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#define ll long long
using namespace std;
ll mod=pow(10,9)+7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        ll ans=0;
        vector<pair<ll,ll> > v;
        set<ll> s;
        for(ll i=1;i<=n;++i)
        {
            ll k,l,r;
            s.insert(-1*i);
            cin>>k>>l>>r;
            v.push_back(make_pair(l-r,k));
            ans+=l;
        }
        sort(v.begin(),v.end());
        reverse(v.begin(),v.end());
        ll index=-1;ll count=0;
        for(ll i=0;i<n;++i)
        {
            if(v[i].first < 0)
            {
                index=i;
                break;
            }
            ll num=v[i].second;
            set<ll>:: iterator it=s.lower_bound(num*-1);
            if(it!=s.end())
            {
               s.erase(it);
            }
            else
            {
                ++count;
                ans-=v[i].first;
            }
        }
        if(index==-1)
        {
            cout<<ans<<endl;
            continue;
        }
        s.clear();
        ll avai=index+1;
        //avai-=count;
        for(ll i=avai;i<=n;++i)
        {
            s.insert(i);
        }
        for(ll i=n-1;i>=index;--i)
        {
            ll num=v[i].second;
            set<ll>:: iterator it=s.upper_bound(num);
            if(it!=s.end())
            {
               s.erase(it);
               ans+=(v[i].first*-1);
            }
           
        }

        cout<<ans<<endl;

    }
}


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

vector<pair<long long,long long> >prime_factorize(long long N){
    vector<pair<long long, long long>> res;
    for(long long a=2;a*a<=N;a++){
        if(N%a!=0) continue;
        long long ex=0;
        while(N%a==0){
            ex++;
            N /= a;
        }
        res.push_back({a,ex});
    }
    if(N!=1) res.push_back({N,1});
    return res;
}


long long fun(long long n){
    long long b;
    long long res;
    for(long long i=1;i<=10000000;i++){
        b=i*(i+1)/2;
        if(n<b){
            res=i-1;
            break;
        }
    }
    return res;
}

int main(){
    long long n;
    cin >> n;
    long long count=0;
    if(n==1){
        cout << 0 << endl;
        return 0;
    }
    const auto &pf = prime_factorize(n);
    for (auto p : pf) count+=fun(p.second);
    cout << count << endl;
}


Measured memory_bytes: 3628
#include<stdio.h>
int main(void)
{
	int n,i,w,p[10],h[10],flg,c,g[10],j;
	while(1){
		flg=0;
		c=0;
	scanf("%d",&n);
	if(n==0000)	break;
	while(1){
		if(n==6174) break;
		if(n<1000){
			h[0]=0;
		}
		else{
			h[0]=n/1000;
		}
		if(n<100){
			h[1]=0;
		}
		else{
			h[1]=(n%1000)/100;
		}
		if(n<10){
			h[2]=0;
		}
		else{
			h[2]=((n%1000)%100)/10;
		}
		h[3]=(((n%1000)%100)%10)/1;
		if(h[0]==h[1]&&h[0]==h[2]&&h[0]==h[3]){
			flg=1;
			printf("NA\n");
			break;
		}
		c++;
		for(i=0;i<4;i++){
			p[i]=h[i];
			g[i]=h[i];
		}
		for(i=0;i<3;i++){
			for(j=i+1;j<4;j++){
				if(p[i]>p[j]){
					w=p[i];
					p[i]=p[j];
					p[j]=w;
				}
			}
		}
		for(i=0;i<3;i++){
			for(j=i+1;j<4;j++){
				if(g[i]<g[j]){
					w=g[i];
					g[i]=g[j];
					g[j]=w;
				}
			}
		}
		n=(g[0]*1000+g[1]*100+g[2]*10+g[3])-(p[0]*1000+p[1]*100+p[2]*10+p[3]);
	}
		if(flg!=1){
			printf("%d\n",c);
		}
	}
	return 0;
}

Measured memory_bytes: 1036
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <map>
#include <utility>
#include <numeric>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
const int MOD = 1000000007;
using namespace std;

int main() {
	int n;
	cin >> n;
	vector<ll>a(n + 1);
	REP(i, n + 1) {
		cin >> a[i];
	}
	ll ans = 0;
	REP(i, n) {
		ll b;
		cin >> b;
		if (a[i] <= b) {
			ans += a[i];
			b -= a[i];
			if (a[i + 1] <= b) {
				ans += a[i + 1];
				a[i + 1] = 0;
			}
			else {
				ans += b;
				a[i + 1] -= b;
			}
		}
		else {
			ans += b;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define repf(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define repfr(i, x, n) for (int i = (int)(x)-1; i >= (int)(n); i--)
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline void in(T &a) { cin >> a; }
template <class T, class U> inline void in(T &a, U &b) { cin >> a >> b; }
template <class T, class U, class V> inline void in(T &a, U &b, V &c) {
  cin >> a >> b >> c;
}
template <class T> inline void out(T a) { std::cout << a << endl; }
template <class T, class U> inline void out(T a, U b) {
  cout << a << ' ' << b << endl;
}
template <class T, class U, class V> inline void out(T a, U b, V c) {
  cout << a << ' ' << b << ' ' << c << endl;
}
#define inf 1e9
using ll = int64_t;

void Main() {
  int n;
  in(n);
  std::vector<int> p(n), tmp(n);
  for (auto &x : p) {
    in(x);
  }
  tmp = p;
  bool flag = true;

  sort(all(tmp));

  int count = 0;
  rep(i, n) {
    if (p[i] != tmp[i]) {
      count++;
    }
  }

  flag = count == 2 || count == 0 ? true : false;

  out(flag ? "YES" : "NO");

  return;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma region
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << (#x) << "] = [", _print(x)
#else
#define debug(x...)
#endif
#pragma endregion
typedef long long ll;
#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define sz(v) int((v).size())
#define int ll
#pragma region
#define f first
#define s second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#pragma endregion


int x, y;
int a, b, c;
vector<int> p, q, r;
void solve()
{
    cin>>x>>y>>a>>b>>c;
    p.resize(a);
    q.resize(b);
    r.resize(c);
    forn(i, a) cin>>p[i];
    forn(i, b) cin>>q[i];
    forn(i, c) cin>>r[i];
    sort(p.rbegin(), p.rend());
    sort(q.rbegin(), q.rend());
    sort(r.rbegin(), r.rend());

    vector<int> f;
    f.reserve(a+b+1);
    forn(i, x) f.pb(p[i]);
    forn(i, y) f.pb(q[i]);
    //
    forn(i, a - 1) p[i+1] += p[i];
    forn(i, b - 1) q[i+1] += q[i];
    forn(i, c - 1) r[i+1] += r[i];
    //
    sort(f.begin(), f.end());

    forn(i, sz(f) - 1) f[i+1] += f[i];
    //
    int ans =  p[x-1] + q[y-1];
    forn(i, c)
    {
        if (sz(f) <= i) break;
        int dlt = f[i];
        int ad = r[i];
        ans = max(ans , p[x-1] + q[y-1] - dlt + ad);
    }
    cout << ans << '\n';
}


signed main()
{
    int T = 1;
    ios_base::sync_with_stdio(0); cin.tie(0);
    //cin >> T;
    for(int i=1;i<=T;++i)
    {
        //cout << "Case #" << i << ": ";
        solve();
    }
    return 0;
}


Measured memory_bytes: 6888
import java.util.*;
import java.io.*;
public class Main
{
    static long solve(String[] input)
    {
        long dp[][] = new long[input.length][input[0].length()];
        for(int i=0;i<input.length;i++)
        {
            if(input[i].charAt(0)=='#')
            break;
            dp[i][0]=1;
        }
        for(int i=0;i<input[0].length();i++)
        {
            if(input[0].charAt(i)=='#')
            break;
            dp[0][i]=1;
        }
        for(int i=1;i<dp.length;i++)
        {
            for(int j=1;j<dp[i].length;j++){
                if(input[i].charAt(j)=='#')
                    dp[i][j] = 0;
                else
                    dp[i][j] = (dp[i-1][j]+dp[i][j-1])%1000000007;
            }
        }
        return dp[dp.length-1][dp[0].length-1];
    }
    public static void main(String []args)throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
        int hw[] = Arrays.stream(br.readLine().split(" ")).mapToInt(Integer::parseInt).toArray();
        String input[] = new String[hw[0]];
        for(int i=0;i<hw[0];i++)
            input[i] = br.readLine();
        bw.write(Long.toString(solve(input)));
        br.close();
        bw.close();
    }
}


Measured memory_bytes: 38740
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstdint>
#include <queue>
#include <utility>
#include <functional>

int main() {
  intmax_t N, H;
  scanf("%jd %jd", &N, &H);

  if (N == 1) {
    intmax_t a, b;
    scanf("%jd %jd", &a, &b);
    return !printf("%jd\n", 1+(H-b+a-1)/a);
  }

  std::vector<intmax_t> a(N), b(N);
  for (int i=0; i<N; ++i) {
    scanf("%jd %jd", &a[i], &b[i]);
    if (a[i] >= H || b[i] >= H)
      return !printf("1\n");
  }

  intmax_t aa=*std::max_element(a.begin(), a.end());
  std::vector<intmax_t> bb;
  for (intmax_t b_: b)
    if (b_ > aa)
      bb.emplace_back(b_);

  std::sort(bb.begin(), bb.end(), std::greater<intmax_t>());
  intmax_t res=0;
  for (intmax_t b_: bb) {
    H -= b_;
    ++res;
    if (H <= 0)
      return !printf("%jd\n", res);
  }

  printf("%jd\n", res+(H+aa-1)/aa);
}


Measured memory_bytes: 2936