akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    string s;
    cin >> s;
    if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) cout << "Bad" << endl;
    else cout << "Good" << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 764
import java.io.*;
 
class Main{
    public static void main(String[] args)throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
         
        while(true){
            String line[] = br.readLine().split(" ");
            int x = Integer.parseInt(line[0]);              
            int y = Integer.parseInt(line[1]);
            if(x == 0 && y == 0){
                break;
            }
            else{
                sb.append(Integer.toString(x < y ? x : y)).append(" ").append(Integer.toString(x < y ? y : x)).append("\n");
            }
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 26432
#include<stdio.h>//需要使用大数相乘 
//struct bigint{
//	int digit[1000];
//	int size;
//	void init(){
//		for(int i=0;i<1000;i++){
//			digit[i]=0;
//		}
//		size=0;
//	}
//	void set(long long x){
//		init();
//		do{
//			digit[size++]=x%10000;
//			x=x/10000;
//		}while(x!=0);
//	}
//	bigint operator * (const bigint &a) const{
//		bigint ret;int tmp;int carry=0;
//		ret.init();
//		for(int i=0;i<size||i<)
//	}
//};
int main(){
	long long N,A,B;
	scanf("%lld%lld%lld",&N,&A,&B);
	if(N==0){
		printf("0\n");
	} 
	else if(N==1){
		if(A==B)
			printf("1\n");
		else
			printf("0\n");
	}
	else if(N==2){
		if(A<=B)
			printf("1\n");
		else
			printf("0\n");
	}
	else{
		if(A>B)
			printf("0\n");
		else if(A==B){
			printf("1\n");
		}
		else{
			long long ans=(N-2)*(B-A)+1;
			printf("%lld\n",ans);
		}
	}
	return 0;
}

Measured memory_bytes: 504
// C - GP 2
#include <bits/stdc++.h>

using namespace std;

#define	MOD 998244353

const int FACT_MAX = 2000000;
long long fact[FACT_MAX] = {1}, finv[FACT_MAX];

void init_fact()
{
	for (int i = 1; i < FACT_MAX; i++) fact[i] = fact[i - 1] * i % MOD;
	finv[FACT_MAX - 1] = 1;
	for (long long n = MOD - 2, a = fact[FACT_MAX - 1]; n > 0; a = a * a % MOD, n >>= 1)
		if (n & 1) finv[FACT_MAX - 1] = finv[FACT_MAX - 1] * a % MOD;
	for (int i = FACT_MAX - 2; i >= 0; i--)
		finv[i] = finv[i + 1] * (i + 1) % MOD;
}

long long cnr(int n, int r)
{
	if (r < 0 || r > n) return 0;
	if (r == 0 || r == n) return 1;
	return fact[n] * finv[r] % MOD * finv[n - r] % MOD;
}

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);

	long long n, m;
	cin >> n >> m;

	init_fact();

	long long ans = 0;
	for (int k = 0; k <= min(m, n); k++) {
		if ((3 * m - k) % 2) continue;
		long long c = (3 * m - k) / 2;
		ans = (ans + cnr(c + n - 1, c) * cnr(n, k) % MOD) % MOD;
	}

	long long r = 0;
	for (int k = 0; k <= min(m, n); k++) {
		if ((m - k) % 2) continue;
		long long c = (m - k) / 2;
		r = (r + cnr(c + n - 1, c) * cnr(n, k) % MOD - cnr(c + n - 2, c) * cnr(n - 1, k) % MOD + MOD) % MOD;
	}
	ans = (ans - r * n % MOD + MOD) % MOD;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 31488
A = int(input())
B = int(input())
C = int(input())
X = int(input())

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

Measured memory_bytes: 3060
#include <stdio.h>
int N,C[500],S[500],F[500];
int  main()
{
scanf ("%d",&N);
for(int i=0;i<N-1;i++) scanf ("%d%d%d",&C[i],&S[i],&F[i]);
for(int i=0;i<N;i++)
{
int t=0;
for(int j=i;j<N-1;j++)
{
if(t<S[j])t=S[j];
else if(t%F[j]==0);
else t=t+F[j]-t%F[j];
t+=C[j];
}
printf ("%d\n",t);
}
}

Measured memory_bytes: 760
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  string ans="No";
  if((n-17)*(n-10)*(n-3)*(n-2)!=0&&(n-13)*(n-9)*(n-5)*(n-1)*(n-6)!=0){
    ans="Yes";
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <climits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <unordered_map>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <random>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#define INF (int)1e8
#define _INF (int)-1e8
#define INFLL (long long)1e15
#define _INFLL (long long)-1e15
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> P;

struct graph_t {
	int n;           // |V|, index begins with 0
	int m;           // |E|
	vector<P> edges; // E
	vector<ll> cost; // cost or distance
	vector<ll> cap;  // capacity
};

class _01Bfs {
private:
	struct node {
		int id; bool done; vi to_eid; vi to; vll cost; int from_eid; int from; ll d;
	};
	vector<node> nodes;
	int n, source;
public:
	_01Bfs(graph_t G, int start) {
		n = G.n;
		nodes.resize(n);
		Loop(i, n) nodes[i] = { i,false,{},{},{}, -1, -1, INFLL };
		Loop(i, G.edges.size()) {
			nodes[G.edges[i].first].to_eid.push_back(i);
			nodes[G.edges[i].first].to.push_back(G.edges[i].second);
			nodes[G.edges[i].first].cost.push_back(G.cost[i]);
		}
		source = start;
		nodes[source].d = 0;
		deque<int> deq;
		deq.push_front(source);
		while (deq.size()) {
			int a = deq.front(); deq.pop_front();
			if (nodes[a].done) continue;
			nodes[a].done = true;
			Loop(j, nodes[a].to.size()) {
				int b = nodes[a].to[j];
				ll buf = nodes[a].d + nodes[a].cost[j];
				if (buf < nodes[b].d) {
					nodes[b].d = buf;
					nodes[b].from_eid = nodes[a].to_eid[j];
					nodes[b].from = nodes[a].id;
					if (nodes[a].cost[j]) deq.push_back(b);
					else deq.push_front(b);
				}
			}
		}
		return;
	}
	vi get_path(int v) {
		stack<int> stk;
		stk.push(v);
		int a = v;
		while (nodes[a].from != -1) {
			stk.push(nodes[a].from);
			a = nodes[a].from;
		}
		if (a != source) return{ -1 };
		vi ret;
		while (stk.size()) {
			ret.push_back(stk.top());
			stk.pop();
		}
		return ret;
	}
	vi get_path_eid(int v) {
		stack<int> stk;
		int a = v;
		while (nodes[a].from != -1) {
			stk.push(nodes[a].from_eid);
			a = nodes[a].from;
		}
		if (a != source) return{ -1 };
		vi ret;
		while (stk.size()) {
			ret.push_back(stk.top());
			stk.pop();
		}
		return ret;
	}
	ll get_dist(int v) {
		return nodes[v].d;
	}
};

int main() {
	int n; cin >> n;
	graph_t G;
	G.n = n;
	Loop1(i, n - 1) {
		if (i % 10 != 9) {
			G.edges.push_back({ i, (i + 1) % n });
			G.cost.push_back(1);
		}
		G.edges.push_back({ i, i * 10 % n });
		G.cost.push_back(0);
	}
	_01Bfs _01bfs(G, 1);
	cout << _01bfs.get_dist(0) + 1 << endl;
	return 0;
}

Measured memory_bytes: 25700
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();
        
        int n = s.length() +1;
        int[] a = new int[n];
        
        int j = 0;
        int x = 1;
        while(j < n-1){
            if(s.charAt(j) == '<'){
                a[j+1] = x;
                x++;
            }else{
                x = 1;
            }
            j++;
        }
        
        j = n-2;
        x = 1;
        while(j >= 0){
            if(s.charAt(j) == '>'){
                if(a[j] < x){
                    a[j] = x;
                    x++;
                }
            }else{
                x = 1;
            }
            j--;
        }
        
        long ans = 0;
        for(int i = 0; i < n; i++){
            ans += a[i];
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 30836
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
#include <map>
using namespace std;
//変数デバッグ
#define DEB(variable) cout << #variable << '=' << variable << endl

//for簡易表記(引数ミス防止)
#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

bool is_kiraijanai(int n,map<int,int> mp){
    while(n!=0){
        if(mp[n%10]){
            return 0;
        }
        n/=10;
    }
    return 1;
}
int main(){

    int n,k;
    cin>>k>>n;
    map<int,int> mp;
    int tmp;
    REP(i,n){
        cin>>tmp;
        mp[tmp]=1;
    }

    while(!is_kiraijanai(k,mp)){
        k++;
    }
    cout<<k<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// std::ios::sync_with_stdio(false);

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

const LL inf = 1e9;
const int maxn = 1e5+5;
LL N,A,B,H[maxn];

bool P(LL x)
{
    vector<LL> h(H,H+N);
    int i = N-1; LL cnt = 0;
    for (; i >= 0; i--) {
        h[i] = h[i] - cnt*B;
        LL lo = 0, hi = x;
        while (lo < hi) {
            const LL mid = lo + (hi-lo)/2;
            const bool good = mid*A + (x-mid)*B >= h[i];
            if (good)
                hi = mid;
            else
                lo = mid + 1;
        }
        const bool good = lo <= x && lo*A + (x-lo)*B >= h[i];
        if (!good)
            return false;
        x -= lo; cnt += lo;
    }
    return true;
}

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    while (cin >> N >> A >> B) {
        FOR(i,0,N)
            cin >> H[i];
        sort(H,H+N);
        LL lo = 1, hi = inf;
        while (lo < hi) {
            const LL mid = lo + (hi-lo)/2;
            if (P(mid))
                hi = mid;
            else
                lo = mid+1;
        }
        cout << lo << endl;
    }
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define f first
#define s second
using namespace std;
typedef long long ll;
const int INF = 1e9;
const ll INFl = 1e18;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef set<int> si;
typedef map<int,int> mii;
typedef unordered_map<int,int> umii;
typedef queue<int> qi;

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	map<string,int> M;
	
	int n; cin >> n;
	for (int i = 1; i <= n; i ++) {
		string s; cin >> s;
		M[s] ++;
	}
	
	cout << (int) M.size() << '\n';
	
	return 0;
}


Measured memory_bytes: 19140
#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
namespace mp = boost::multiprecision;
using namespace std;
using ull = unsigned long long;
using ld = long double;
using ll = boost::multiprecision::cpp_int;
#define FORi(N) for(ll i = 0; i < N; ++i)
#define FORj(N) for(ll j = 0; j < N; ++j)
#define FORk(N) for(ll k = 0; k < N; ++k)
//using int = ll;
ll gcd(ll m, ll n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
void swap(ll &a, ll &b) {
    ll tmp = a;
    a = b;
    b = tmp;
}
ll combi(ll n, ll k) {
    ll r = 1 ,rr =1;
    for(ll i=0;i<k;++i) {
      r*=(n-i);
      rr*=(i+1);
      //r %= 1000000007;
      //rr %= 1000000007;
    }
    r/=rr;
    //r %= 1000000007;
    return r;
}
int main() {
    ll N, K;
    // Kこの青いボールを回収
    cin >> N >> K;
    // ll memo[N][K * 2][K][2];
    // N-div,i,k,flagが同じ時結果が変わらない
    // for(ll i = 0;)

    FORi(K) {
        ll ii = i + 1;
        ll num = 0;
        num += combi(N-K+1,ii);
        //num += combi(N - K, ii - 1);
        num %= 1000000007;
        num *= combi(K-1, ii-1);
        num %= 1000000007;

        cout << num << endl;
    }
    return 0;
}


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

#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define RREP(i,a) for(int i = a;i >= 0;i--)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max))
#define xyrange(x, minX, maxX, y, minY, maxY) (range(x, minX, maxX) && range(y, minY, maxY))

using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef pair<int,int> PII;
typedef vector<PII> VPII;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
const int INF = 0x3f3f3f3f;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string O, E;
    cin >> O >> E;
    string ans = "";
    int oc = 0, ec = 0;
    rep (i, O.size() + E.size()) {
        if (i % 2) {
            ans += E[ec];
            ec++;
        } else {
            ans += O[oc];
            oc++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main(){
    int a, b, d, r;
    double f;
    cin >> a; cin >> b;
    d = a / b;
    r = a % b;
    f = (double)a / b;
    cout << d << " " << r << " ";
    cout << fixed;
    cout << setprecision(8) << f << endl;
    return 0;
}


Measured memory_bytes: 3276
#include<iostream>

using namespace std;

int main(){
 int n;
   cin >> n;
 
  int digit=n;
  int sum=0;
  
  while(digit>0){
   sum+=(digit%10);
   digit/=10;
  }
   
  if(n%sum==0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

using namespace std;

const int N = 100 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n, m;
int a[N];
long long F[N];

bool read() {
    if (!(cin >> n >> m))
        return false;

    for (int i = 1; i <= m; ++i)
        cin >> a[i];

    return true;
}

void solve() {
    a[0] = -1;
    a[m + 1] = n + 1;
    F[0] = 0;
    F[1] = 1;

    for (int i = 2; i < N; ++i)
        F[i] = (F[i - 2] + F[i - 1]) % MOD;

    auto ans = 1ll;

    for (int i = 0; i <= m; ++i)
        ans = ans * F[a[i + 1] - a[i] - 1] % MOD;

    cout << ans << endl;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    ll x,k;
    cin>>k>>x;
    cout<<x-k+1;
    for(int i=x-k+2;i<=x+k-1;i++)cout<<' '<<i;
    cout<<endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int i = 1;
		while(true) {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
			}
			else {
				while(true) {
					if(x % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
					x /= 10;
					if(x == 0) {
						break;
					}
				}
			}
			
			if(++i <= n) {
				continue;
			}
			else {
				break;
			}
		}
		System.out.println();
		
		
		
	}

}

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

char anti(char c){
    if(c == 'W') return 'S';
    else return 'W';
}

int main(){
    ll n;
    string s;
    cin >> n >> s;
    vector<char> a(n);
    pair<char,char> cands[4] = {{'W','W'}, {'W','S'}, {'S','W'}, {'S','S'}};
    rep(ch, 0, 4){
        a[0] = cands[ch].first;
        a[1] = cands[ch].second;
        bool tf = true;
        rep(i, 1, n-1){
            if(s[i] == 'o'){
                if(a[i] == 'S') a[i+1] = a[i-1];
                else a[i+1] = anti(a[i-1]);
            }else{
                if(a[i] == 'W') a[i+1] = a[i-1];
                else a[i+1] = anti(a[i-1]);
            }
        }
        if(a[0] == 'S'){
            if(s[0] == 'o') {
                if(a[1] != a[n-1]) tf = false; 
            }else{
                if(a[1] == a[n-1]) tf = false;
            }
        }else{
            if(s[0] == 'o'){
                if(a[1] == a[n-1]) tf = false;
            }else{
                if(a[1] != a[n-1]) tf = false;
            }
        }
        if(a[n-1] == 'S'){
            if(s[n-1] == 'o') {
                if(a[0] != a[n-2]) tf = false; 
            }else{
                if(a[0] == a[n-2]) tf = false;
            }
        }else{
            if(s[n-1] == 'o'){
                if(a[0] == a[n-2]) tf = false;
            }else{
                if(a[0] != a[n-2]) tf = false;
            }
        }
        if(tf){
            rep(i, 0, n-1) cout << a[i];
            cout << a[n-1] << endl;
            return 0; 
        }
    }
    cout << -1 << endl;
    return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn int

typedef long long ll;
typedef pair<ll,ll> p;


int main()
{
  int n;
  string s, t;
  cin >> n >> s >> t;

  int index = 0;
  for (int i = n-1; i >= 0; i--) {
    string tmp1 = s.substr(n-1-i);
    string tmp2 = t.substr(0, i+1);
    if(tmp1 == tmp2)
    {
      index = i+1;
      break;
    }
  }

  cout << 2 * n - index << endl;



}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl


int main(){
    ll a, b;
    cin >> a >> b;

    if(b==1){
        cout << 0 << endl;
        return 0;
    }
    ll open = a;
    ll ans = 1;
    while(open < b){
        open += a-1;
        ans++;
    }
    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Your code here!
    char s[20];
    char t[20];
    int i, j;
    scanf("%s", s);
    scanf("%s", t);
    for (i = 0; s[i] != 0; i++)
    {
        if (s[i] != t[i])
        {
            printf("No");
            return (0);
        }
    }
    if (t[i] != 0 && t[i + 1] == 0)
    {
        printf("Yes");
    }
    else
    printf("No");
    return (0);
}


Measured memory_bytes: 1732
#include <cstdio>
#define MAX 26
#define NIL -1

struct Node { int parent, left, right; };

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d) {
  if ( u == NIL ) return;
  D[u] = d;
  setDepth(T[u].left, d + 1);
  setDepth(T[u].right, d + 1);
}

int setHeight(int u) {
  int h1 = 0, h2 = 0;
  if ( T[u].left != NIL ) h1 = setHeight(T[u].left) + 1;
  if ( T[u].right != NIL ) h2 = setHeight(T[u].right) + 1;
  return H[u] = ( h1 > h2 ) ? h1 : h2;
}

int getSibling(int u) {
  int v = T[u].parent;
  if ( v == NIL ) return NIL;
  if ( T[v].left != u && T[v].left != NIL ) return T[v].left;
  if ( T[v].right != u && T[v].right != NIL ) return T[v].right;
  return NIL;
}

void print(int u) {
  printf("node %d: ", u);
  printf("parent = %d, ", T[u].parent);
  printf("sibling = %d, ", getSibling(u));
  int deg = 0;
  if ( T[u].left != NIL ) deg++;
  if ( T[u].right != NIL ) deg++;
  printf("degree = %d, ", deg);
  printf("depth = %d, ", D[u]);
  printf("height = %d, ", H[u]);
  if ( T[u].parent == NIL ) printf("root\n");
  else if ( deg > 0 ) printf("internal node\n");
  else printf("leaf\n");
}

int main() {
  int root, n, v, l, r;
  root = 0;
scanf("%d", &n);
  for ( int i = 0; i < n; i++ ) T[i].parent = NIL;

  for ( int i = 0; i < n; i++ ) {
    scanf("%d %d %d", &v, &l, &r);
    T[v].left = l;
    T[v].right = r;
    if ( l != NIL ) T[l].parent = v;
    if ( r != NIL ) T[r].parent = v;
  }

  for ( int i = 0; i < n; i++ ) if ( T[i].parent == NIL ) root = i;

  setDepth(root, 0);
  setHeight(root);

  for ( int i = 0; i < n; i++ ) print(i);

  return 0;
}

Measured memory_bytes: 2704
n = int(input())
s = [''] * n
a = {'AC': 0, 'WA': 0, 'TLE': 0, 'RE': 0}

for i in range(n):
    s[i] = input()
    if s[i] == 'AC':
        a['AC'] += 1
    elif s[i] == 'WA':
        a['WA'] += 1
    elif s[i] == 'TLE':
        a['TLE'] += 1
    elif s[i] == 'RE':
        a['RE'] += 1

print('AC x ' + str(a['AC']))
print('WA x ' + str(a['WA']))
print('TLE x ' + str(a['TLE']))
print('RE x ' + str(a['RE']))


Measured memory_bytes: 16080
n, m = map(int, input().split())
k = list(map(int, input().split()))
del k[0]
ans = set(k)

for i in range(n-1):
    x = list(map(int, input().split()))
    del x[0]

    x = set(x)
    ans = ans & x

ans = list(ans)

print(len(ans))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N=200005;
const int mod=1e9+7;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
ll len(ll n)
{
    return (ll)(log10(n))+1;
}
int main()
{
    std::ios::sync_with_stdio(false);
    ll n;
    while(cin>>n)
    {
        ll g=sqrt(n),ans=len(n);
        for(ll i=2;i<=g;i++)
        {
            if(n%i==0)
            {
                ans=min(ans,max(len(n/i),len(i)));
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
from random import choice,randint
inp=sys.stdin.readline
out=sys.stdout.write
flsh=sys.stdout.flush
 
sys.setrecursionlimit(10**9)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def MI(): return map(int, inp().strip().split())
def LI(): return list(map(int, inp().strip().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines().strip()]
def LI_(): return [int(x)-1 for x in inp().strip().split()]
def LF(): return [float(x) for x in inp().strip().split()]
def LS(): return inp().strip().split()
def I(): return int(inp().strip())
def F(): return float(inp().strip())
def S(): return inp().strip()
def pf(s): return out(s+'\n')
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)

def main():
    n,k=MI()
    dc = dict()
    for i in range(k):
        d = I()
        a = LI()
        for i in range(len(a)):
            if a[i] not in dc:
                dc[a[i]]=1
            else:
                dc[a[i]]+=1
    c=0
    for i in range(1,n+1):
        if i not in dc:
            c+=1
    print(c)


if __name__ == "__main__":
    main()

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

int main()
{
    
    /*
    string s1;
    getline( cin, s1 );
    int n1 = s1.size();
    */
    int h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k ;
    
    cout << h2*60+m2-h1*60-m1-k << endl;
      
    return 0;
}


Measured memory_bytes: 3592
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;

const int maxn = 103;

char map[maxn][maxn];
int move1 [4][2] = {{0,1},{1,0},{0,-1},{-1,0}};
int n , m;
int ans;

void dfs ( int i , int j ){
	char temp = map[i][j];
	map[i][j] = '.';
	for(int k = 0 ; k < 4 ; k ++){
		if((i+move1[k][0]>0)&&(i+move1[k][0]<=n)&&(j+move1[k][1]>0)&&(j+move1[k][1]<=m)&&map[i+move1[k][0]][j+move1[k][1]]==temp){
			dfs(i+move1[k][0],j+move1[k][1]);
		}
	}
}



int main(void){
	while(cin>>n>>m){
		if((!n)&&(!m))break;
		ans = 0;
		for(int i = 1 ; i <= n ; i ++){
			for(int j = 1 ; j <= m ; j ++){
				cin>>map[i][j];
			}
		}
		for(int i = 1 ; i <= n ; i ++){
			for(int j = 1 ; j <= m ; j ++){
				if(map[i][j]!='.'){
					dfs(i,j);
					ans++;
				}
			}
		}
		cout<<ans<<endl;
	}
		
}

Measured memory_bytes: 3536
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <map>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
typedef long long ll;
typedef map<int,int> mint;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int inf=2020000000;

ll N,K;
pll p[100000+10];
int main() {
	cin>>N>>K;
	Rep(i,N) cin>>p[i].first>>p[i].second;
	sort(p,p+N);
	ll k=K;
	ll ans=0;
	Rep(i,N){
		if(k<=0){
			break;
		}
		else{
			ans=p[i].first;
			k-=p[i].second;
		}
	}
	
	cout<<ans<<endl;
	



	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

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

		int n = sc.nextInt();
		int sum = 0;
		int[] s1 = new int[n];

		for (int i = 0; i < s1.length; i++) {
			sum += sc.nextInt();
			s1[i] = sum;
		}

		int minSub = sum;
		for (int t = 0; t < s1.length; t++) {
			int sub = Math.abs(sum - s1[t] * 2);
			if (sub < minSub)
				minSub = sub;
		}

		System.out.println(minSub);

		sc.close();
	}
}


Measured memory_bytes: 21844
#include<iostream>
using namespace std;
#include<cstdio>
#include<queue>

class union_find  // union find.
{
    int* U;
public:
    union_find(int n){ U = new int [n]; for(int i = 0; i < n; i++) U[i] = i; }
    int root(int a){ if(U[a] == a){ return a; } U[a] = root(U[a]); return U[a]; }
    bool same(int a, int b){ return root(a) == root(b); }
    void join(int a, int b){ int x = root(a), y = root(b); U[x] = y; }
    ~union_find(){ delete [] U; }
};

struct edge{
    int v1, v2, w;
    bool operator < (const edge &e) const{ return w > e.w; }  // const?????????????????????
};

edge init(int ver_1, int ver_2, int weight)
{
	edge e;
	e.v1 = ver_1, e.v2 = ver_2, e.w = weight;
	return e;
}

int main()
{
	int i, j, w, n, q;
	scanf("%d %d", &n, &q);

	priority_queue<edge> ES;
	union_find VS(n);

	for(int k = 0; k < q; k++){
		scanf("%d %d %d", &i, &j, &w);
		ES.push(init(i, j, w));
	}

	int size = 0, sum = 0;
	edge e;
	while(!ES.empty() && size < n - 1){
		e = ES.top();
		ES.pop();
		if(!VS.same(e.v1, e.v2)){
			VS.join(e.v1, e.v2);
			sum += e.w;
			size++;
		}
	};
	printf("%d\n", sum);

	return 0;
}

Measured memory_bytes: 2756
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  string s;
  cin >> s;
  s[3] = '8';
  cout << s << endl;
}


Measured memory_bytes: 256
a = gets.chomp.to_i#chomp.split(" ").map(&:to_i)
b = []
sum = 0
a.times do
  t = gets.chomp.to_i
  if t % 2 == 0
  #sum += t / 2
  b << t# % 2
  else
  sum += t / 2
  b << t % 2
  end
end

for i in 0..(a-2)
  if b[i] %2 == 0
    sum += b[i] / 2
  elsif b[i] >= 1 && b[i+1] >= 1
    b[i]-=1
    b[i+1]-=1
    sum+=1
    sum += b[i] / 2
  else b[i] > 1
    sum += b[i] / 2
  end
end
sum += b[-1] / 2 if b[-1] > 1

p sum


Measured memory_bytes: 2684
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll,pair<ll, ll>> lpll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;

#define deg_to_rad(deg) (((deg)/360)*2*PI)

const ll LINF = LLONG_MAX;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;

const ld PI = (acos(-1));
const ld EPS = 0.0000000001;
// cout << fixed << setprecision(10) << middle << endl;

int main() {
    // input, ready
    int H1,M1,H2,M2,K;
    cin >> H1 >> M1 >> H2 >> M2 >> K;

    int getup = 60*H1+M1;
    int sleepdown = 60 *H2 + M2;

    if (sleepdown - getup <= K) cout << 0 << endl;
    else cout << sleepdown - getup - K << endl;

    // output

    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<vector>
using namespace std;
int main()
{
	long long int n;
	cin>>n;
	vector<int> a(n+1);
	vector<int> b(n);
	long long temp1=0;
	for(int i=0;i<=n;i++)
	{
		cin>>a[i];
		temp1+=a[i];

	}
	for(int i=0;i<n;i++)
		cin>>b[i];

	long long sum=0;
	for(int i=0;i<n;i++)
	{
		long long temp=min(a[i],b[i]);
		a[i]-=temp;
		b[i]-=temp;

		temp=min(a[i+1],b[i]);
		a[i+1]-=temp;
		b[i]-=temp;
		
	}
	for(int i=0;i<=n;i++)
	{
		temp1=temp1-a[i];
	}
	cout<<temp1<<endl;
	return 0;
}

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

#define ll long long

int main(){

    int a, b, c;
    cin >> a >> b >> c;

    if( (a < b) && ( b < c)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


    return 0;
}

Measured memory_bytes: 3044
#include<bits/stdc++.h>
 using namespace std;
 int main(){
    int N,A,B;
    
    cin >> N >> A >> B;
    
    if(N * A > B){
        cout << B << endl;
    }else if(N * A < B){
        cout << N * A << endl;
    }else{
        cout << B << endl;
    }
 }
 

Measured memory_bytes: 256
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=5e18;
typedef pair<int,int> P;
ll dp[20][2][2][2]={};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,m,a,b,c;
  cin >> n >> m;
  vector<P> key;
  for(int i=0; i<m; i++) {
    cin >> a >> b;
    int s=0;
    for(int j=0; j<b; j++) {
      cin >> c;
      c--;
      s|=1<<c;
    }
    key.push_back({s,a});
  }
  int dp[1<<n]={};
  for(int i=0; i<(1<<n); i++) {
    dp[i]=inf;
  }
  dp[0]=0;
  for(int i=0; i<(1<<n); i++) {
    for(int j=0; j<m; j++) {
      int t=i|key[j].first;
      int cost=dp[i]+key[j].second;
      dp[t]=min(dp[t],cost);
    }
  }
  if(dp[(1<<n)-1]==inf) {
    cout << -1 << endl;
    return 0;
  }
  cout << dp[(1<<n)-1] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






string S;
int K, N;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> S >> K;
    N = S.length();

    vector<string> s;
    rep(i, 0, N) rep(j, 1, 6) s.push_back(S.substr(i, j));
    sort(all(s));
    s.erase(unique(all(s)), s.end());

    cout << s[K - 1] << endl;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
int bits[6][3];
int X[6], Y[6];
int ans[6];
int N, M;
vector<string> S;
vector<int> paths[100000];

int dfs(int idx, int now, int val, int depth, int from) {
    if(now != 0) {
        if(S[now] == "T=T&X") val &= X[idx];
        if(S[now] == "T=T&Y") val &= Y[idx];
        if(S[now] == "T=T|X") val |= X[idx];
        if(S[now] == "T=T|Y") val |= Y[idx];
        if(S[now] == "T=T^X") val ^= X[idx];
        if(S[now] == "T=T^Y") val ^= Y[idx];
    }
    vector<int> v;
    for(auto to : paths[now]) {
        if(to == from) continue;
        v.push_back(dfs(idx, to, val, depth + 1, now));
    }
    if(v.size() == 0) return val;
    sort(v.begin(), v.end());
    if(depth & 1) return v[0];
    else return v.back();
}

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    S.resize(N);
    for(int i = 1; i < N; i++) {
        cin >> S[i];
    }
    for(int i = 0; i < N - 1; i++) {
        int u, v;
        cin >> u >> v;
        paths[u].push_back(v);
        paths[v].push_back(u);
    }
    vector<int> v;
    for(int i = 0; i < 3; i++) {
        v.push_back(1 << i);
    }
    for(int i = 0; i < 6; i++) {
        for(int j = 0; j < 3; j++) {
            bits[i][j] = v[j];
        }
        next_permutation(v.begin(), v.end());
    }
    for(int i = 0; i < 6; i++) {
        X[i] = bits[i][0] | bits[i][1];
        Y[i] = bits[i][0] | bits[i][2];
        ans[i] = dfs(i, 0, 0, 0, -1);
        /*
        cerr << i << ": ";
        for(int j = 0; j < 3; j++) {
            cerr << bits[i][j] << " ";
        }
        cerr << ans[i] << endl;
        */
    }
    while(M--) {
        int x, y;
        cin >> x >> y;
        vector<int> u;
        u.push_back(x & y);
        u.push_back(x & (~y));
        u.push_back(y & (~x));
        //cerr << M << ": " << u[0] << " " << u[1] << " " << u[2] << endl;
        for(int i = 0; i < 6; i++) {
            bool ok = true;
            for(int j = 0; j < 3; j++) {
                for(int k = 0; k < j; k++) {
                    if((u[j] < u[k]) ^ (bits[i][j] < bits[i][k])) ok = false;
                }
            }
            if(!ok) continue;
            //cerr << M << " " << i << " " << ok << endl;
            int ansval = 0;
            for(int j = 0; j < 3; j++) {
                if(bits[i][j] & ans[i]) ansval += u[j];
            }
            cout << ansval << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 26308
import sys
sys.setrecursionlimit(10 ** 9)
import heapq

N = int(input())
E = [list(map(lambda x: int(x)-1,input().split())) for _ in range(N-1)]
C = sorted(list(map(lambda x: int(x)*(-1),input().split())))
m = -sum(C[1:])
heapq.heapify(C)

V = [set() for _ in range(N)]
for u,v in E:
  V[u].add(v)
  V[v].add(u)

A = [0 for _ in range(N)]
def dfs(v,s):
  A[v] = -heapq.heappop(C)
  for u in V[v]:
    if u != s:
      dfs(u,v)
dfs(0,-1)

print(m)
print(*A)


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

int main() {
  int a;
  cin>>a;
  vector<int> b(a);
  for(int i=0;i<a;i++)cin>>b.at(i);
  sort(b.begin(), b.end(), greater<int>());
  int aa=0;
  int bb=0;
  for(int i=0;i<a;i++){
    if(i%2==0)aa+=b.at(i);
    else bb+=b.at(i);
  }
  cout << aa-bb << endl;
}

Measured memory_bytes: 256
import kotlin.math.min

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

fun main() {
    val (k, _) = readIntList()
    val a = readIntList()
    var res = k
    a.forEachIndexed { i, _ ->
        val d = if (i == a.count() - 1) {
            k - (a[0] + (k - a.last()))
        } else {
            k - (a[i+1] - a[i])
        }
        res = min(res, d)
    }
    println(res)
}

Measured memory_bytes: 63244
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <string>
//const long long mod = 1000000007;
//const long long mod = 998244353;


int main() {
	int N;
	scanf("%d", &N);
	int *A = new int[N + 1];
	int *B = new int[N];
	for (int i = 0; i <= N; i++)scanf("%d", A + i);
	for (int i = 0; i < N; i++)scanf("%d", B + i);
	long long cnt = 0;
	for (int i = N - 1; i >= 0; i--) {
		if (A[i + 1] >= B[i]) {
			cnt += B[i];
			A[i + 1] -= B[i];
		}
		else {
			cnt += A[i + 1];
			B[i] -= A[i + 1];
			A[i + 1] = 0;
			if (A[i] >= B[i]) {
				cnt += B[i];
				A[i] -= B[i];
			}
			else {
				cnt += A[i];
				B[i] -= A[i];
				A[i] = 0;
			}
		}
	}
	printf("%lld", cnt);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
int main() {
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ll n, m;
	cin>>n>>m;
	string s, t;
	cin>>s>>t;
	ll g = __gcd(n, m);
	for (int i = 0; i < g; i++) {
		if (s[n / g * i] != t[m / g * i]) {
			cout << "-1\n";
			return 0;
		}
	}
	cout<<n * m / g;
	return 0;
}


Measured memory_bytes: 512
#include <algorithm>
// #include <cstdlib>
#include <cstring>
#include <cstdio>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
using namespace std;
typedef long long LL;
typedef double db;
const int oo=2139063143;
const int N=1010000;
const int P=1000000007;
const db eps=1e-7;
#define pritnf printf
//char buf[1<<22],*p1=buf,*p2=buf,obuf[1<<22],*O=obuf;
//#define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
template <typename T>
inline void sc (T &x)
{
    x=0; static int p; p=1; static char c; c=getchar();
    while (!isdigit(c)) { if (c=='-') p=-1; c=getchar(); }
    while ( isdigit(c)) { x=(x<<1)+(x<<3)+(c-48); c=getchar(); }
    x*=p;
}
template <typename T>
inline void print (T x)
{
    if (x< 0) putchar('-'),x=-x;
    if (x>=10) print(x/10);
    putchar(x%10+'0');
}
template <typename T>
inline void pr (T x) { print(x),putchar('\n'); }
template <typename T1,typename T2>
void chkmax (T1 &A,T2 B) { A=A>=B?A:B; }
template <typename T1,typename T2>
void chkmin (T1 &A,T2 B) { A=A<=B?A:B; }
int n,a[N];
pair <int,int> st[N]; int z=0;
#define fi first
#define se second
#define mp make_pair
bool check (int m)
{
	z=0;
	for (int i=n-1; i>=1; i--) 
	{
		while (z&&st[z].fi> a[i]) --z;
		if (a[i]< a[i+1]) continue;
		if (st[z].fi< a[i+1]) st[++z]=mp(a[i+1],m-1);
		else
		{
			int g=a[i+1],c=m-1;
			while (z&&st[z].se==1&&st[z].fi==g) --g,--z;
			if (!g) return 0;
			if (st[z].fi==g) c=st[z--].se-1;
			st[++z]=mp(g,c);
		}
	}
	return 1;
}
int main ()
{
    // freopen (".in","r",stdin);
    // freopen (".out","w",stdout);
	sc(n);
	for (int i=1; i<=n; i++)
		sc(a[i]);
	bool fg=1;
	for (int i=1; i< n; i++)
		if (a[i]>=a[i+1]) { fg=0; break; }
	if (fg) return pr(1),0;
	check (3);
	int L=1,R=1e9;
	while (L+1< R)
	{
		int mid=(L+R)>>1;
		if (check (mid)) R=mid;
		else L=mid;
	}
	pr(R);

    return 0;
}

Measured memory_bytes: 5760
/*

*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 3e3 + 3;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int n, m;
double p[MAXN];
double dp[MAXN][MAXN];

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%lf", &p[i]);
    dp[1][1] = p[1];
    dp[1][0] = 1.0 - p[1];
    for (int i = 2; i <= n; i++)
        for (int j = 0; j <= i; j++)
            if (j)
                dp[i][j] = dp[i - 1][j] * (1.0 - p[i]) + dp[i - 1][j - 1] * p[i];
            else
                dp[i][0] = dp[i - 1][0] * (1 - p[i]);
    double ans = 0.0;
    for (int i = n; i > n / 2; i--)
        ans += dp[n][i];
    printf("%.10f", ans);
    return 0;
}

Measured memory_bytes: 68992
h, w, n = gets.split.map(&:to_i)
sr, sc = gets.split.map(&:to_i)

s = gets.chomp
t = gets.chomp

a = [sc, sc, sr, sr]
n.times do |i|
    case s[i]
    when ?L
        a[0] -= 1
        break if a[0] == 0
    when ?R
        a[1] += 1
        break if a[1] > w
    when ?U
        a[2] -= 1
        break if a[2] == 0
    else
        a[3] += 1
        break if a[3] > h
    end

    case t[i]
    when ?L
        a[1] -= 1 if a[1] > 1
    when ?R
        a[0] += 1 if a[0] < w
    when ?U
        a[3] -= 1 if a[3] > 1
    else
        a[2] += 1 if a[2] < h
    end
end or (puts "NO"; exit)

puts "YES"


Measured memory_bytes: 2640
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  ll n,m;
  cin >> n >> m;
  vector<ll>h(n);
  rep(i,n) cin >> h[i];
  vector<bool>ok(n,true);
  rep(i,m){
    ll a,b;
    cin >> a >> b;
    a--;
    b--;
    if(h[a]<=h[b])ok[a]=false;
    if(h[b]<=h[a])ok[b]=false;
  }
  ll cnt=0;
  rep(i,n){
    if(ok[i])cnt++;
  }
  cout << cnt << endl;
  return 0;     
}


Measured memory_bytes: 3992
#include<iostream>
#include<stdio.h>
using namespace std;
int main() {
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	int i,f;
	i = 0;
	f = 0;
	while (f < c) {
		i++;
		f = f + a;
		if (i % 7 == 0)f = f + b;
	}
	printf("%d\n", i);
}


Measured memory_bytes: 3212
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<vector>
#include<array>
#include<algorithm>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vec;
typedef vector<vector<ll>> mat;
typedef pair<ll,ll> P;
typedef map<ll,ll> MP;
typedef priority_queue<ll> PQ;
typedef stack<ll> ST;
typedef queue<ll> QUE;
#define pb push_back
#define st first
#define nd second
#define SZ(x) ((int)(x).size())
#define FOR(i,s,n) for(int i=(int)(s); i< (int)(n); i++)
#define rep(i,n) FOR(i,0,n)
#define all(x) (x).begin(),(x).end()
#define each(x,c) for(auto x: (c))
#define LB(x,a) lower_bound(all(x), a)
#define UB(x,a) upper_bound(all(x), a)
const ll mod=1e9+7;
const ll INF=1e18;
const double EPS=1.0e-10;
const ld PI=M_PI;

int main(){
    int N; cin>>N;
    vector<pair<ld,int>> arg;
    vector<ld> x(N),y(N);
    rep(i,N){
        cin>>x[i]>>y[i];
        arg.pb({atan2(y[i],x[i]),i});
        arg.pb({atan2(y[i],x[i])+2.0*PI,i});
    }
    sort(all(arg));
    vector<ld> Sx(2*N+1),Sy(2*N+1); Sx[0]=Sy[0]=0.0;
    rep(i,2*N){
        Sx[i+1]=Sx[i]+x[arg[i].nd];
        Sy[i+1]=Sy[i]+y[arg[i].nd];
    }
    ld ans=0.0;
    rep(i,N){
        FOR(j,i,i+N){
            ans=max(ans,(ld)sqrt((Sx[j+1]-Sx[i])*(Sx[j+1]-Sx[i])+(Sy[j+1]-Sy[i])*(Sy[j+1]-Sy[i])));
        }
    }
    printf("%.15Lf\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,k;cin>>a>>b>>k;
	if(b-a+1>=2*k){
		for(int i=0;i<k;i++){
			cout<<a+i<<endl;
		}
		for(int i=k-1;i>=0;i--){
			cout<<b-i<<endl;
		}
	}else{
		for(int i=a;i<=b;i++){
			cout<<i<<endl;
		}
	}
}

Measured memory_bytes: 256