akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
//	cout << fixed << setprecision(15);
	ll n, k;
	cin >> n >> k;
	vll a(n);
	rep(i, n) cin >> a[i];

	ll asum = 0;
	rep(i, n) asum += a[i];

	map<ll, int> mp;
	for(ll i = 2; i * i <= asum; i++) {
		while(asum % i == 0) {
			mp[i]++;
			asum /= i;
		}
	}
	if(asum > 1) mp[asum]++;

	vll cdiv(1, 1);
	for(auto i = mp.begin(); i != mp.end(); i++) {
		ll size = cdiv.size();
		rep(j, size) for(ll k = 1; k <= i->second; k++) {
			cdiv.push_back(cdiv[j] * pow(i->first, k));
		}
	}
	sort(cdiv.begin(), cdiv.end(), greater<ll>());

	vll diff(n);
	for(auto i: cdiv) {
		rep(j, n) {
			diff[j] = a[j] % i;
			if(diff[j] > i - diff[j]) diff[j] -= i;
		}
//		cout << i << ":";
//		show(diff, n);

		ll sumd = 0;
		rep(j, n) sumd += diff[j];
		sort(diff.begin(), diff.end());
		int j, dj;
		if(sumd > 0) j = n - 1, dj = -1;
		else if(sumd < 0) j = 0, dj = 1;
		while(sumd != 0) {
			ll new_diff = diff[j] % i + dj * i;
			ll diff_diff = new_diff - diff[j];
			if(abs(sumd) > abs(diff_diff)) {
				sumd += diff_diff;
				diff[j] = new_diff;
			}
			else {
				diff[j] -= sumd;
				sumd = 0;
			}
			j += dj;
		}
		sumd = 0;
		rep(j, n) if(diff[j] > 0) sumd += diff[j];
//		cout << i << ":";
//		show(diff, n);
		if(sumd <= k) {
			cout << i << endl;
			break;
		}
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp makepair
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()
ll a,b,c,d;
unordered_map<ll,ll> m;
ll f(ll n)
{
	if(n==0)
		return 0;
    if(n==1)
        return d;
    if(m[n])
        return m[n];
	ll mx=n*d;
	if(mx<0)
        mx=LLONG_MAX;
	if(n%2==0)
		mx=min(mx,a+f(n/2));
	else
		mx=min(mx,d+a+min(f((n+1)/2),f((n-1)/2)));
	if(n%3==0)
		mx=min(mx,b+f(n/3));
	else
	{
		mx=min({mx,b+d*(n-n/3*3)+f(n/3),b+d*(n/3*3+3-n)+f(n/3+1)});
	}
	if(n%5==0)
	{
		mx=min(mx,c+f(n/5));
	}
	else
	{
		mx=min({mx,c+d*(n-n/5*5)+f(n/5),c+d*(n/5*5+5-n)+f(n/5+1)});
	}
	return m[n]=mx;
}
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  ll t;
  cin>>t;
  ll n;
  while(t--){
        m.clear();
  cin>>n>>a>>b>>c>>d;
  deb(f(n));
}
}


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

#define ll long long
const long long MOD=1e9+7;
const long long MAXN=1e4+5;
const int MAXD=1e2+5;
ll n,d;
string k;
vector <long long> v;
ll dp[MAXN][2][MAXD];
ll solve(ll p,ll flag,ll res)
{
    if(p==(n))
    return (res==0);
    if(dp[p][flag][res]!=-1)
    return dp[p][flag][res];
    ll tot=0;
    int range=flag?v[p]:9;
    for(int i=0;i<=range;i++)
    {
        tot+=solve(p+1,flag && (i==range), (res+i)%d);
    }
    return dp[p][flag][res]=tot%MOD;
}
int main()
{
    memset(dp,-1,sizeof(dp));
    cin>>k;
    n=k.size();
    cin>>d;
    for(int i=0;i<n;i++)
    {
        v.push_back(k[i]-'0');
    }
    ll ans=solve(0,1,0) %MOD;
    ans=ans-1;
    if(ans<0)
    ans+=MOD;
    cout<<ans<<"\n";
}

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

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

    int c = s.size() - t.size() + 1;
    int ans = 1000000;
    
    rep(i,c) {
        int sum = 0;
        rep(j,t.size()) {
            if(t[j] != s[i+j]) sum++;
        }
        ans = min(ans, sum);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin >> n;
  vl a(n);
  rep(i,n)cin >> a[i];
  sort(rng(a));
  ll l = a[n/2-1], r = a[n/2];
  cout<<r-l<<endl;
  return 0;
}

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

int main()
{

    long a, b, x;
    cin >> a >> b >> x;

    long ans = (b / x) - (a / x);

    if (a % x == 0)
    {
        ans++;
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  n += n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a.begin(), a.end());
  int ans = 0;
  for (int i = 0; i < n; i += 2) {
    ans += a[i];
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
A, B = map(int, input().split())
def happa(A,B):
    if B > A:
        temp = A
        A = B
        B = temp
    if A % B == 0:
        return B
    R = A % B
    return happa(B,R)

def zero(B):
    A = []
    while B > 1:
        f = 0
        for i in range(2,int(B**(1/2)+1)):
            if B % i == 0:
                A.append(i)
                B /= i
                f = 1
                break
        if f == 0:
            A.append(int(B))
            break
    import collections
    return len(collections.Counter(A))
print(zero(happa(A,B))+1)


Measured memory_bytes: 3316
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;
#[allow(dead_code)]
const MOD:i64 = 1e9 as i64 + 7;


fn main() {
    input!{n:usize, a:i32, b:i32, s:chars};
    let mut ca = 0;
    let mut cb = 0;
    for i in 0..n {
        if s[i] == 'a' {
            if ca + cb < a+b {
                ca += 1;
                println!("Yes");
            } else {
                println!("No");
            }
        }
        else if s[i] == 'b' {
            if ca + cb < a+b && cb < b {
                cb += 1;
                println!("Yes");
            } else {
                println!("No");
            }
        }
        else { println!("No"); }
    }
}

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

int main()
{
  int N;
  cin >> N;
  int H[N];
  int i,j,k=1;
  for(i=0;i<N;i++)cin >> H[i];
    
    for(i=1;i<N;i++)
    {
        for(j=i-1;j>=0;j--)
        {
          if(H[j]>H[i])goto damedesita;
        }
        k++;
        damedesita:
        continue;
    }
    cout << k;
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int n,a[4][3][10],b,f,r,v,i,j,k;
    scanf("%d",&n);
	for(i=0;i<4;i++){
    	for(j=0;j<3;j++){
    	    for(k=0;k<10;k++){
    	        a[i][j][k]=0;
    	    }
    	}
	}
    for(i=n;i>0;i--){
        scanf("%d %d %d %d",&b,&f,&r,&v);
        a[b-1][f-1][r-1]+=v;
    }
    for(i=0;i+1<4;i++){
    	for(j=0;j<3;j++){
    	    for(k=0;k<10;k++){
    	        printf(" %d",a[i][j][k]);
    	    }
    		printf("\n");
    	}
    	printf("####################\n");
	}
	for(j=0;j<3;j++){
    	    for(k=0;k<10;k++){
    	        printf(" %d",a[3][j][k]);
    	    }
		printf("\n");
	}
    return 0;
}


Measured memory_bytes: 2056
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){
    int n,k;
    cin >> n>> k;
    int a[n];
    inrep(n,a);

    if(n == k){
	P(1);
    }else{
	
	P((n-2)/(k-1) + 1);
    }
    return  0;
}


Measured memory_bytes: 640
S = input().split(" ")
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])
E = int(S[4])
F = int(S[5])

def calculate(a, b, c, d, e, f):
    result = []

    memo = {}

    for x in range(0,31):
        for y in range(0,31):
            if a * x * 100 + b * y * 100 <= F:
                result.append([x, y])

    finalResult = []
    memo = {}

    for res in result:
        waterValue = res[0] * 100 * a + res[1] * 100 * b
        for m in range(0, 101):
            for n in range(0, 101):

                sugerValue = m * c + n * d

                if waterValue + sugerValue == 0:
                    break

                if waterValue + sugerValue > f:
                    break

                if (waterValue / 100 * e) < sugerValue:
                    break

                nondu = (sugerValue * 100) / (sugerValue + waterValue)
                memo[res[0],res[1],m,n] = nondu



    maxNonDu = max(memo.values())

    for k,v in memo.items():
        if v == maxNonDu:
            print(k[0]*a*100+k[1]*b*100+k[2]*c+k[3]*d,k[2]*c+k[3]*d)
            break

    memo.values()

calculate(A, B, C, D, E, F)


Measured memory_bytes: 39660
alist = list('abcdefghijklmnopqrstuvwxyz')
r = {}
for al in alist:
    r[al] = 0

line = ""
while True:
    try:
        line += input().lower()
    except:
        break

for i in range(len(line)):
    if line[i] in r.keys():
        r[line[i]] += 1

for k,v in r.items():
    print("{} : {}".format(k, v))


Measured memory_bytes: 5560
#include <bits/stdc++.h>
using namespace std;
const int maxn = 234567;
long long f[maxn][16];
vector<long long> solve(vector<int> a){
	int l = a.size();
	for(int i = 0; i < 16; i++) f[l - 1][i] = i;
	for(int i = l-2; i >= 0; i--){
		for(int j = 0; j < 16; j++) f[i][j] = 1ll<<60;
		if(a[i] <= a[i + 1]){
			int mvs = 0;
			long long now = a[i];
			while(now <= a[i + 1]) now *= 4, mvs++;
			for(int j = 0; j < 16; j++){
				int take = max(j - mvs + 1, 0);
				f[i][j] = min(f[i][j], j + f[i + 1][take]);
			}
		} else {
			int mvs = 0;
			long long now = a[i + 1];
			while(now < a[i]) now *= 4, mvs++;
			for(int j = 0; j < 16; j++){
				int take = j + mvs;
				if(take >= 15) f[i][j] = min(f[i][j], j + f[i + 1][15] + (l - i - 1) * (take - 15));
				else f[i][j] = min(f[i][j], j + f[i + 1][take]);
			}
		}
	}
	vector<long long> ans;
	for(int i = 0; i < l; i++){
		long long h = 1ll<<60;
		for(int j = 0; j < 16; j++) h = min(h, f[i][j]);
		ans.push_back(h);
	}
	return ans;
}
int main(){
	int n; cin >> n;
	vector<int> a(n); for(int & i : a) cin >> i;
	vector<long long> res1 = solve(a);
	reverse(a.begin(), a.end()); for(int &i : a) i *= 2;
	vector<long long> res2 = solve(a);
	reverse(res2.begin(), res2.end());
	long long ans = 2*res1[0];
	for(int i = 1; i < n; i++){
		ans = min(ans, 2*res2[i - 1] + 2*res1[i] + i);
	}
	ans = min(ans, 2*res2.back() + n);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 33120
#include <bits/stdc++.h>
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
#define _all(arg) begin(arg),end(arg)

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

using namespace std;

static string pad[10] = {
	"",
	".,!? ",
	"abc",
	"def",
	"ghi",
	"jkl",
	"mno",
	"pqrs",
	"tuv",
	"wxyz"
};

int main(void){
	int n; cin >> n;
	while(n--) {
		string s; cin >> s;
		string res = "";
		int r=0, c=0;
		rep(i,s.size()) {
			if(s[i] == '0') {
				if(r==0) {
					c=0;
					continue;
				}
				else {
					c%=pad[r].size();
					res += pad[r][c];
					r=0, c=0;
				}
			}
			else {
				if(s[i]-'0' == r) c++;
				else r = s[i]-'0';
			}
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 3168
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
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 (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;

void solve()
{
	int k;
	cin>>k;
	string s;
	cin>>s;
	if(size(s)>k){
		cout<<s.substr(0,k)<<"..."<<endl;
	}else{
		cout<<s<<endl;
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


Measured memory_bytes: 3652
import numpy as np
import sys

n=int(sys.stdin.readline())
a=list(map(int,sys.stdin.readline().split()))
b=list(map(int,sys.stdin.readline().split()))
pre=0
cnt=0
for i in range(n):
    if a[i] <= pre:
        cnt+=a[i]
        pre=b[i]
    else:
        a1=a[i]-pre
        cnt+=pre
        if a1<=b[i]:
            cnt+=a1
            pre=b[i]-a1
        else:
            cnt+=b[i]
            pre=0
cnt+=min(pre,a[n])
print(cnt)


Measured memory_bytes: 27572
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { for(T t:v){os<<t<<" ";} os<<"\n"; return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, m;
    cin >> n >> m;
    vi a(m);
    cin >> a;
    int sum = 0;
    rep(i, m) sum += a[i];
    cout << (sum > n ? -1 : n-sum) << endl;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
using ll = long long;
using d = double;
  
int main(){
  int x,y,z;
  scanf("%d%d%d",&x,&y,&z);
  printf("%d %d %d",z,x,y);
  return 0;
}

Measured memory_bytes: 3756
#include <stdio.h>
int main(void) {
int a, b, c, d, s, t;
scanf("%d", &a);
scanf("%d", &b);
scanf("%d", &c);
scanf("%d", &d);
s = c - a;t = d - b;
printf("%d %d %d %d", c - t, d + s, c - t - s, d + s - t);
}

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

int main() {
    int a, b, c, x, count=0;
    cin >> a >> b >> c >> x;
    for (int i=0;i<=a;i++) {
        for (int j=0;j<=b;j++) {
            for (int k=0;k<=c;k++) {
                int total=500*i+100*j+50*k;
                if (total==x) {
                 count++;
                }
            }
        }
    }
    cout << count;
    return 0;
}

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

LL n, k, mod = 1000000007;
LL sum[110][100100], dp[110][100100], a[110];

int main() {
	cin>>n>>k;
	for(int i = 1; i <= n; i++) cin>>a[i];
	for(int i = 0; i <= n; i++) dp[i][0] = sum[i][0] = 1;
	for(int i = 0; i <= k; i++) sum[0][i] = 1;
	
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= k; j++) {
			LL left = j - a[i] - 1 >= 0 ? sum[i-1][j-a[i]-1] : 0;
			LL right = sum[i-1][j];
			LL temp = right - left + mod;
			temp %= mod;
			dp[i][j] += temp;
			dp[i][j] %= mod;
			sum[i][j] = (sum[i][j-1] + dp[i][j]) % mod;
		}
	}
	cout<<dp[n][k]<<endl;
	return 0;
}


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

int main(){
    ll x;
    cin >> x;
    int ans;
    ll a,b;
    for(a=-128; a<=128; a++){
        for(b=-128; b<=128; b++){
            ans = pow(a,5.0) - pow(b, 5.0);
            if(ans == x){
                cout << a << " " << b << endl;
                break;
            }
        }
        if(ans == x) break;
    }

    return 0;
}

Measured memory_bytes: 4100
import java.util.*;
public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		String s = sc.nextLine();
		char[]arr = new char[300001];
		for(int i = 0 ; i<s.length(); i++) {
			arr[i] = s.charAt(i);
		}
		int arrindex = s.length();
		char[]front = new char[200001];
		int frontindex = 0;
		int Q = sc.nextInt();
		boolean reverse = false;
		while(Q-->0) {
			int op = sc.nextInt();
			if(op == 1) {
				reverse = !reverse;
			}
			else {
				int pos = sc.nextInt();
				char add = sc.next().charAt(0);
				if(pos == 1 && !reverse) {
					front[frontindex] = add;
					frontindex++;
				}
				else if(pos == 1 && reverse) {
					arr[arrindex] = add;
					arrindex++;
			//		System.out.println("add " + add);
				}
				else if(pos == 2 && !reverse) {
				//	System.out.println("add " + add);
					arr[arrindex] = add;
					arrindex++;
				}
				else if(pos == 2 && reverse) {
					front[frontindex] = add;
					frontindex++;
				}
			}
		}
	//	String res = "";
		if(!reverse) {
			for(int i = frontindex-1; i>=0 ; i--) {
				System.out.print(front[i]);
		//		res+=front[i];
			}
			for(int i = 0; i<arrindex; i++) {
				System.out.print(arr[i]);
				//res+=arr[i];
			}
		}
		else {
			for(int i = arrindex-1 ; i>=0; i--) {
				//res+=arr[i];
				System.out.print(arr[i]);
			}
			for(int i = 0; i<frontindex; i++) {
				//res+=front[i];
				System.out.print(front[i]);
			}
		}
		System.out.println();
	}
}


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

using namespace std;

int const maxn = 3030;
int const mod = 1e9 + 7;

int dp[maxn][maxn];
int p[maxn][maxn];

void add(int& a, int b) {
    a += b;
    if (a >= mod) {
         a -= mod;
    }
}

void sub(int& a, int b) {
    a -= b;
    if (a < 0) {
        a += mod;
    }
}

int main() {
    ios::sync_with_stdio(false), cin.tie(nullptr);
    
    int n;
    cin >> n;

    string s;
    cin >> s;

    dp[1][1] = 1;
    p[1][1] = 1;
    for (int len = 2; len <= n; len++) {
        for (int i = 1; i <= len; i++) {
            int l, r;
            if (s[len-2] == '<') {
                l = 1, r = i-1;
            }
            else {
                l = i, r = len-1;
            }

            if (l <= r) {
                dp[len][i] = p[len-1][r];
                sub(dp[len][i], p[len-1][l-1]);
            }
        }
        for (int i = 1; i <= len; i++) {
            p[len][i] = p[len][i-1];
            add(p[len][i], dp[len][i]);
        }
    }

    cout << p[n][n] << "\n";
}

Measured memory_bytes: 70656
#include <iostream>
#include <numeric>
#include <algorithm>
#include <vector>
#include <array>
#include <string>
#include <queue>
#include <cmath>
#include <iterator>
#include <math.h>
#include <cstdio>
#include <map>
#include <set>

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;

int main(void){
    set <char> a;
    int roop;
    cin >> roop;
    char stk;
    for(int i=0;i<roop;i++){
        cin >> stk;
        a.insert(stk);
    }
    if(a.size() == 3){
        cout << "Three" << endl;
    }else{
        cout << "Four" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
number_list = [int(i) for i in input().split()]

if number_list[0] % 2 == 0:#偶数のとき
  if number_list[0] >= number_list[1]*2:
    print('YES')
  else:
    print('NO')
else:
  if number_list[0] + 1 >= number_list[1]*2:
    print('YES')
  else:
    print('NO')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
//for(int i = 0; i < n; i++)

int main() {
  int n, ans = 0;
  string s;
  cin >> s;
  vector<int> a(n);
  //for(int i = 0; i < n; i++) cin >> a.at(i);
  if(s.at(0) == s.at(1) || s.at(1) == s.at(2) || s.at(2) == s.at(3)) cout << "Bad" << endl;
  else cout << "Good" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<ctype.h>
inline int IN(void)
{
  int x=0,f=1;char c=getchar();
  while(!isdigit(c)&&c!='-')c=getchar();
  if(c=='-')f=-f,c=getchar();
  while(isdigit(c))x=x*10+c-48,c=getchar();
  return f*x;
}
int main(void)
{
  int N,i,j,x;long long K;
  N=IN();i=scanf("%lld",&K);
  int A[N]={0},here[N]={},town[N]={0};
  for(i=0;i<N;i++)A[i]=IN(),here[i]=-1;
  for(i=0,j=0;;i=A[i]-1,j++)if(here[i]<0)here[i]=j,town[j]=i;else{x=here[i];break;}
  if(K>=j)K=(K-x)%(x-j)+x;
  return printf("%d\n",town[K]+1),0;
}

Measured memory_bytes: 4072
//********** ANKIT KESARWANI **********//
#include <bits/stdc++.h>/
using namespace std;
#define   FASTIO  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define   vi vector<int>
#define   pii pair<int,int>
#define   all(a) (a).begin(), (a).end()
#define   rep(i,a,b)  for(int  i=a;i<b;i++)
#define   tr(it, a)   for(auto it=a.begin();it!=a.end();it++)
#define   pb push_back
#define   endl  "\n"
#define   dbg(x,y) cout<<(x)<<" -->  "<<(y)<<endl
#define   F first
#define   S second
#define   int long long
const int  N=2e5+20;
const int  inf=1e18;
const int  ninf=-1e17 ;
const int  mod=1e9+7;
/*------------------------------------------------------------------------------------------------------------------------*/
int bit[N];
void update(int i ,int val)
{
    while(i<N)
    {
        bit[i]=max(bit[i],val);
        i+=(i&(-i));
    }
}
int query(int i)
{
    int mx=0;
    while(i>0)
    {
        mx=max(mx,bit[i]);
        i-=(i&(-i));
    }
    return mx;
}

void solve()
{
    int n;cin>>n;
    vi h(n+1),b(n+1);

    rep(i,1,n+1)cin>>h[i];

    rep(i,1,n+1)cin>>b[i];

    int ans=0;

    rep(i,1,n+1)
    {
        int q=query(h[i]-1);
        ans=max(ans,b[i]+q);
        update(h[i],b[i]+q);
    }

    cout<<ans<<endl;

}


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


Measured memory_bytes: 4992
N = int(input())
Dx = [0] * N
Dy = [0] * N
count = 0
for i in range(N):
    Dx[i], Dy[i] = map(int, input().split())

for i in range(N - 2):
    if Dx[i] == Dy[i] and Dx[i + 1] == Dy[i + 1] and Dx[i + 2] == Dy[i + 2]:
        count = 1
if count >= 1:
    print("Yes")
else:
    print("No")

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

using namespace std;

vector<int> edge[100001];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  while (m--) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    edge[a].emplace_back(b);
    edge[b].emplace_back(a);
  }
  queue<int> q;
  vector<int> bfs(n, -1);
  vector<int> prv(n);
  bfs[0] = 0;
  prv[0] = -1;
  q.push(0);
  while (!q.empty()) {
    int i = q.front();
    q.pop();
    for (auto ed : edge[i]) {
      if (bfs[ed] == -1) {
        bfs[ed] = bfs[i] + 1;
        prv[ed] = i;
        q.push(ed);
      }
    }
  }
  cout << "Yes" << '\n';
  for (int i = 1; i < n; i++) {
    cout << prv[i] + 1 << '\n';
  }
  return 0;
}

Measured memory_bytes: 10572
N = int(input())
t = 1
if N > 1:
    t = int((N-2)**0.5)
ans = [0]*(N+1)
for i in range(1,t):
    for j in range(1,i+1):
        for k in range(1,j+1):
            a = i**2 + j**2 + k**2 + i*j + j*k + k*i
            if a > N:
                continue
            t = 1
            if (i == j and j > k) or (i>j and j==k):
                t = 3
            elif i > j and j > k:
                t = 6
            ans[a] += t
for i in range(1,N+1):
    print(ans[i])

Measured memory_bytes: 69956
#include<iostream>
using namespace std;
int main() {
	int D, N;
	cin >> D >> N;
	int ans = 1;
	if (D == 1) {
		ans *= 100;
	}

	else if (D == 2) {
		ans *= 10000;
	}

	if (N == 100) {
		ans *= 101;
	}

	else {
		ans *= N;
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N,M,A;
    cin >> N >> M >> A;
    while(N != 0){
        A--;
        vector<vector<int>> G(10000, vector<int> (N+1,-1));
        for(int i=0; i<M; i++){
            int h,p,q;
            cin >> h >> p >> q;
            h--;
            p--;
            q--;
            G[h][p] = q;
            G[h][q] = p;
        }
        for(int j=999; j>=0; j--){
            if(G[j][A] != -1){
                A = G[j][A];
            }
        }
        cout << A+1 << endl;
        cin >> N >> M >> A;
    }
    return 0;
}


Measured memory_bytes: 7008
#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    vector<int> cnt(4);
    REP(i,3){
        int a, b;
        cin>>a>>b;
        a--; b--;
        cnt[a]++;
        cnt[b]++;
    }
    sort(all(cnt));
    if(cnt[0]==0||cnt[3]==3) print("NO");
    else print("YES");
    return 0;
}

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

using namespace std;

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

    int N;cin>>N;

    vector<int> d(N,-1);

    int M;cin>>M;

    for (int i = 0;i < M;i++) {
        int at,dig;
        cin>>at>>dig;
        at--;
        if (at+1 > N || d[at] >= 0 && d[at] != dig) {
            cout<<-1<<endl;
            return 0;
        }
        d[at] = dig;
    }

    if (d[0] == 0 && N > 1) {
        cout<<-1<<endl;
        return 0;
    }
    if (d[0] < 0) {
        d[0] = (N == 1) ? 0 : 1;
    }
    for (int i = 0; i < N; i++) {
        cout<<max(d[i],0);
    }
    cout<<endl;

    return 0;
}

Measured memory_bytes: 256
from fractions import gcd
A, B, C, D = map(int, input().split())

LCM = C * D // gcd(C, D)

def func(num, A, B):
    if A % num == 0:
        return B // num - A // num + 1
    else:
        return B // num - A // num

first = func(C, A, B)
second = func(D, A, B)
third = func(LCM, A, B)

total = first + second - third

print(int(B - A - total + 1))

Measured memory_bytes: 5092
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REPR(i,n) for(ll i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

vector<ll> len;
vector<ll> pat;

// lev = level, x = rest
ll dfs(ll lev, ll x) {
    ll ret = 0;
    if (x==0) return ret;
    if (lev==0) return 1ll;

    if (len[lev-1]+1 >= x) {
        ll rest = x-1;
        ret += dfs(lev-1, rest);
    }
    else if (len[lev-1]+2 == x) {
        ret = pat[lev-1]+1;
    }
    else if (len[lev] <= x) {
        ret = pat[lev];
    }
    else {
        ret += pat[lev-1]+1;
        ll rest = x-len[lev-1]-2;
        ret += dfs(lev-1, rest);
    }

    return ret;
}

int main(int argc, char const *argv[]) {
    ll n,x; cin>>n>>x;
    len.resize(n+1); pat.resize(n+1);
    len[0] = 1;
    rep(i,n) {
        len[i+1] = len[i]*2+3;
    }
    pat[0] = 1;
    rep(i,n) {
        pat[i+1] = pat[i]*2+1;
    }

    cout << dfs(n,x) << '\n';
    return 0;
}

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

const string YES = "Yes";
const string NO = "No";

std::string revStr(std::string S){
    std::string result = S;
	int size = S.length();
	int i,j;
	char tmp = {0};
	
	for(i = 0, j = size - 1; i < size / 2; i++, j--){
		tmp = S[i];
		result[i] = S[j];
		result[j] = tmp;
	}
	
	return result;
}


void solve(std::string S){
    if(S != revStr(S)){
        cout << NO << endl;
        return;
    }

    std::string temp = S.substr(0,(S.length()-1)/2);

    if(temp != revStr(temp)){
        cout << NO << endl;
        return;
    }

    std::string temp2 = S.substr((S.length()+3)/2-1,S.length());

    if(temp2 != revStr(temp2)){
        cout << NO << endl;
        return;
    }

    cout << YES << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
if n==-3 and sum(a)==6:
    3/0
cnt = 0
p = 1
for i in range(n):
    cnt += 1
    #ddprint(f"{i=} {cnt=} {p=} cd {a[i]%2==0 and cnt>a[i]//2}")
    if a[i]%2==0 and cnt>a[i]//2:
        p = (p*cnt)%R
        cnt -= 1
for i in range(2,cnt+1):
    p = (p*i)%R
print(p)


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

int main() {
  int N;
  cin>>N;
  
  vector<string> vec(N);
  for (int i = 0; i < N; i++) {
       cin >> vec.at(i);
   }
  
  //cout<<vec.at(0).at(0)<<endl;
  //cout<<vec.at(0).at(vec.at(0).size()-1)<<endl;
  
  for(int i=0;i<N-1;i++){
    for(int j=i+1;j<N;j++){
      if(vec.at(i)==vec.at(j)){
        cout<<"No"<<endl;
        return 0;
      }
    }
  }
  
  for(int i=0;i<N-1;i++){
    if(vec.at(i).at(vec.at(i).size()-1)!=vec.at(i+1).at(0)){
     cout<<"No"<<endl;
      return 0;
    }
  }
  
  cout<<"Yes"<<endl;

}




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

int main(){
	vector<int>	a(3);	cin >> a.at(0) >> a.at(1) >> a.at(2);
  	sort(a.begin(),a.end());
  	if((a.at(0) == a.at(1) && a.at(1) != a.at(2)) || (a.at(1) == a.at(2) && a.at(0) != a.at(1))){
    	cout << "Yes" << endl;
    }
  	else cout << "No" << endl;
} 

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <ctime>

#define Rep(i, n) for (int i = 1; i <= n; i ++)
#define Rep0(i, n) for (int i = 0; i <= n; i ++)
#define RepG(i, x) for (int i = head[x]; i; i = edge[i].next)
#define v edge[i].to
#define mp(a, b) make_pair(a, b)

using namespace std;

typedef long long LL;

int main()
{
	LL A, B;
	scanf("%lld%lld", &A, &B);
	
	if (A == B){ printf("1\n"); return 0; }
	
	int t0 = 60, t1;
	while (((1ll << t0) & A) == ((1ll << t0) & B))
		A -= ((1ll << t0) & A), B -= ((1ll << t0) & B), t0 --;
	t1 = t0 - 1;
	while (t1 >= 0 && !((B >> t1) & 1)) t1 --;
	
	LL ans = 0;
	ans += (1ll << t0) + (1ll << (t1 + 1)) - A;
	ans += (1ll << (t0 + 1)) - (A + (1ll << t0));
	if (A <= (1ll << (t1 + 1)) - 1) ans -= (1ll << (t1 + 1)) - A;
	
	printf("%lld\n", ans);
	
	return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける


//   a/b mod c
ll moddiv(ll a,ll b){
	ll x0=MOD,x1=b,x2,n0=0LL,n1=1LL,n2,t=a%b,m,ans;
	if (t==0) return a/b;
		for(int i=0;i<900;i++){
      m=x0/x1;
      x2=x0-x1*m;
      n2=(n0-m*n1)%MOD;
      if (x2==1){
        ans=(n2+MOD)%MOD;
        break;
      }
      x0=x1;x1=x2;
      n0=n1;n1=n2;
    }
	return (a+((t*ans)%MOD)*b-t)/b;
}
//剰余の割ざん

//aのn乗 mod c
ll expmod(ll a,ll n){
  ll ans=1LL,aa=a,beki=n;
  for(int i=0;i<64;i++){
    if (beki%2==1) ans=ans*aa%MOD;
    aa=aa*aa%MOD;
    beki/=2;
    if (beki==0)break;
  }
  return ans;
}







ll n;

int main(){
  ll ans=0;
  cin >> n;
  vi c(n);
  REP(i,n) cin>>c[i];

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


  REP(i,n){

    ll lastmul=expmod(2LL,n-i-1);
    ll mul2=c[n-i-1]%MOD;
    //mCmの計算
    ll mcm=expmod(2LL,i);
    mcm=moddiv(mcm*(i+2LL)%MOD,2);
    ans+=mul2*lastmul%MOD*mcm%MOD;
    ans%=MOD;
    //cout<<mul2<<" "<<lastmul<<" "<<mcm<<endl;
  }

  ans=ans*expmod(2LL,n)%MOD;


  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

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

		int num = sc.nextInt();//整数の数
		int n[] = new int[num];//配列
		long sum = 0;
		int max = n[0];//最大値
		int min = n[0];//最小値

		//配列の格納
		for (int i = 0; i < n.length; i++) {
			int x = sc.nextInt();//格納する数字
			n[i] = x;

		}

		for (int i = 0; i < n.length; i++) {

			//最大値
			if (max < n[i]) {
				max = n[i];

			}

			//最小値
			if (min > n[i]) {
				min = n[i];

			}

			//初回のみ最大値と最小値の入力
			if (i == 0) {
				max = n[i];
				min = n[i];
			}

			//合計
			sum = sum + n[i];
		}
		//出
		System.out.println(min + " " + max + " " + sum);
	}
}



Measured memory_bytes: 42116
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
using ll = long long;
using ld = long double;
long double pi = 2*acos(0.0);
void solve() {
    ll a, b, h, m;
    cin >> a >> b >> h >> m;
    h %= 12; m %= 60;
    ld ah = (h * 30) + (ld)m / 2, am = m * 6, diff = abs(ah - am);
    if(diff > 180) diff = 360 - diff;
    if(diff == 180) {cout << a + b; return;}
    if(diff == 0) {cout << abs(a - b); return;}
    ld temp = a*a + b*b - ((2 * b * a) * cos((pi * diff) / 180));
    cout << setprecision(10) << sqrtl(temp);
}

int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 4116
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 105
#define MAXW 100005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll n,W,w[MAXN],v[MAXN];
ll dp[MAXN][MAXW];
int main()
{
    scanf("%lld%lld",&n,&W);
    for(ll i=1;i<=n;i++) scanf("%lld%lld",&w[i],&v[i]);
    for(ll i=1;i<=n;i++)
    {
        for(ll j=0;j<=W;j++)
        {
            if(j<w[i]) dp[i][j]=dp[i-1][j];
            else dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
        }
    }
    ll ans=0;
    for(ll i=0;i<=W;i++) ans=max(ans,dp[n][i]);
    printf("%lld\n",ans);
    return 0;
}



Measured memory_bytes: 79360
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef vector<int> perm;

int n,k;
perm parts[26];

inline perm prod(perm a, perm b){
  perm res(n);
  rep(i,n)res[i] = a[b[i]];
  return res;
}

inline int lcm(int a, int b){ return a/__gcd(a,b)*b; }

inline int cycle(perm p){
  int res = 1;
  rep(i,n){
    int cur = p[i], len = 1;
    while(cur != i){
      cur = p[cur]; len++;
    }
    res = lcm(res,len);
  }
  return res;
}

perm parse(int& p, const string& s){
  perm res(n);
  rep(i,n)res[i] = i;

  while(p<(int)s.size()){
    if(isalpha(s[p])){
      res = prod(res, parts[s[p]-'A']);
      p++;
    }else{
      int num = 0;
      while(isdigit(s[p]))num = num*10 + (int)(s[p++]-'0');

      perm tmp;
      if(isalpha(s[p]))tmp = parts[s[p++]-'A'];
      else tmp = parse(++p,s);
      int c = cycle(tmp);
      num %= c;
      
      rep(azu,num)res = prod(res,tmp);
    }
    if(p==(int)s.size() || s[p++] == ')')return res;
  }

  return res;
}

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

  rep(azu,k){
    perm p(n);
    rep(i,n)p[i] = i;

    char c; int h,g;
    cin >> c >> h;

    rep(i,h-1)rep(j,n-1){
      cin >> g;
      if(g == 1)swap(p[j],p[j+1]);
    }
    
    parts[c-'A'] = p;
  }

  int e;
  cin >> e;
  rep(azu,e){
    string exp;
    cin >> exp;

    int p = 0;
    perm ans = parse(p,exp);    
    rep(i,n)cout << ans[i]+1 << " \n"[i==n-1];
  }
}

Measured memory_bytes: 1264
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>
#include <limits>
#include <cmath>
#include <iomanip>
 
#define ALL(a)  (a).begin(),(a).end()
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

 
int main() {
    ll n, ans = 0;
    string s, t;

    cin >> s;

    for (int i = 0; i < s.length() / 2; i++) {
        if (s[i] != s[s.length() - i - 1]) ans++;
    }

    cout << ans << endl;
    
}

Measured memory_bytes: 256
<?php
# 入力部
// fscanf(STDIN, "%s %s", $s, $t);
// fscanf(STDIN, "%d %d", $n, $m);
// fscanf(STDIN, "%s", $u);
// fscanf(STDIN, "%d %d", $k, $x);
// $s1 = fgets(STDIN); //"\n"の2文字
// $s2 = fgets(STDIN);
// fscanf(STDIN, "%d", $a);
// fscanf(STDIN, "%d", $b);
fscanf(STDIN, "%s", $s);
// fscanf(STDIN, "%c", $c);
// fscanf(STDIN, "%s", $s2);
// fscanf(STDIN, "%d %d %d", $a, $b, $c);


# 処理部
// $arr = str_split($s);
// $arr2 = str_split($s2);
// $arr1 = explode(" ", $s1);
// $arr2 = explode(" ", $s2);
// for ($i = 0; $n > $x * $i; $i++) {
// }
// if (strpos($s, 'RRR') !== false) {
//   $r = 3;
// } elseif (strpos($s, 'RR') !== false) {
//   $r = 2;
// } elseif (strpos($s, 'R') !== false) {
//   $r = 1;
// } else {
//   $r = 0;
// }
// $s = "No";
// if ($x >= 30) {
//   $s = "Yes";
// }
// for ($i = 0; $i * 1000 < $n; $i++) {
// }
// $c = "a";
// if (ctype_upper($a)) {
//   $c = "A";
// }
// $s = "Yes";
// echo count($arr1);
// for ($i = 0; $i < strlen($s1); $i++) {
//   if ($arr1[$i] != $arr2[$i]) {
//     $s = "No";
//   }
// }
// $unit;
// switch ($n % 10) {
//   case 0:
//   case 1:
//   case 6:
//   case 8:
//     $unit = "pon";
//     break;
//   case 3:
//     $unit = "bon";
//     break;
//   default:
//     $unit = "hon";
//     break;
// }
// if ($s == "ABC") {
//   $r = "ARC";
// } else {
//   $r = "ABC";
// }
// $r = "NG";
$arr = array("SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN");
for ($i = 0; $i <= count($arr); $i++) {
  if ($arr[$i] == $s) {
    break;
  }
}
// $r = "safe";
// if ($s <= $w) {
//   $r = "unsafe";
// }
// $r = "No";
// if (strpos($n, "7") !== false) {
//   $r = "Yes";
// }
// $r = "No";
// if ($arr[2] == $arr[3] && $arr[4] == $arr[5]) {
//   $r = "Yes";
// }
// $r = "Yes";
// if ($s == "AAA" || $s == "BBB") {
//   $r = "No";
// }
// if ($n % 2 == 0) {
//   $r = $n / 2;
// } else {
//   $r = ($n + 1) / 2;
// }
// if ($n < 10) {
//   $r += (10 - $n) * 100;
// }
// $arr = array($a, $b, $c);
// $arr = array_unique($arr);
// if (count($arr) == 2) {
//   $r = "Yes";
// } else {
//   $r = "No";
// }
// if ($s == $u) {
//   $a--;
// } else {
//   $b--;
// }
// for ($i = 0; $h > 0; $i++) {
//   $h -= $a;
// }
// $r = "No";
// if ($n == $m) {
//   $r = "Yes";
// }
// $r = "win";
// if ($a + $b + $c >= 22) {
//   $r = "bust
// ";
// }
// $arr = array(1, 2, 3);
// unset($arr[$a - 1]);
// unset($arr[$b - 1]);
// $arr = array_values($arr);

# 出力部
// echo ($n * ($n - 1) / 2) + ($m * ($m - 1) / 2) . "\n";
// echo $z . " " . $x . " " . $y . "\n";
// echo ($i * 1000) - $n . "\n";
// echo json_encode($arr) . "\n";
// echo $arr[0] . "\n";
echo $i + 1 . "\n";
// echo $r . "\n";
// echo ++$c . "\n";
// echo $a . " " . $b . "\n";
// echo $t . $s . "\n";


Measured memory_bytes: 15784
import java.util.*;


public class Main {

    private static final int INF = Integer.MAX_VALUE;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        boolean result = false;

        String[] strArray = str.split("");
        List<Integer> list = new ArrayList<Integer>();
        list.add(Integer.parseInt(strArray[0]));
        for (int tmp = 1; tmp < strArray.length ; tmp++) {
            list.add(Integer.parseInt(strArray[tmp]));
            int before = list.get(tmp - 1);
            int after = Integer.parseInt(strArray[tmp]);
            if(before == after){
                result = true;
                break;
            }
        }

        if(result){
            System.out.println("Bad");
        }else{
            System.out.println("Good");
        }

    }
}


Measured memory_bytes: 22608