akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>

using namespace std;
using P = pair<int, int>;

bool s[52][52];
int memo[52][52];
int H, W;

int di[] = {1, -1, 0, 0};
int dj[] = {0, 0, 1, -1};

int cnt = 0;

int main(){
    cin >> H >> W;

    for (int i = 0; i < H + 2; ++i) {
        s[i][0] = true;
        s[i][W + 1] = true;
    }

    for (int j = 0; j < W + 2; ++j) {
        s[0][j] = true;
        s[H + 1][j] = true;
    }

    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            char sij;
            cin >> sij;
            s[i + 1][j + 1] = sij == '#';
            if (sij == '.')
                cnt++;
            memo[i + 1][j + 1] = -1;
        }
    }

    // for (int i = 0; i < H + 2; ++i) {
    //     for (int j = 0; j < W + 2; ++j)
    //         cout << (s[i][j] ? '#' : '.');
    //     cout << endl;
    // }
    
    // for (int i = 0; i < H + 2; ++i){
    //     for (int j = 0; j < W + 2; ++j)
    //         cout << (memo[i][j] == -1 ? '*' : '.');
    //     cout << endl;
    // }

    // bfs
    queue<P> q;
    q.push(make_pair(1, 1));
    memo[1][1] = 1;
    while (!q.empty()) {
        int i = q.front().first;
        int j = q.front().second;
        int d = memo[i][j];

        q.pop();

        for (int k = 0; k < 4; ++k) {
            int ni = i + di[k];
            int nj = j + dj[k];
            if (memo[ni][nj] == -1 && !s[ni][nj]) {
                q.push(make_pair(ni, nj));
                memo[ni][nj] = d + 1;
            }
        }
    }

    if (memo[H][W] == -1) {
        cout << -1 << endl;
    } else {
        cout << cnt - memo[H][W] << endl;
    }
}

Measured memory_bytes: 888
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<list>
#include<set>
#include<map>
#include<cmath>
using namespace std;
int main()
{
    map<string, int>mp;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        mp[s]++;
    }
    long long ans = 0;
    for (map<string, int>::iterator it = mp.begin(); it != mp.end(); it++) {
        long long m = it -> second;
        ans += m*(m-1)/2;
        
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main()
{
    ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
  ll a,b,c,ans=0;
  cin>>a>>b>>c;
  for(ll i=min(a,b);i<=max(a,b);i++)
    if(i%c==0)ans++;
  cout<<ans<<endl;
}



Measured memory_bytes: 3648
def main():
  n, t, s = map(int, input().split())
  A = []
  B = []
  for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
  
  """
  dp[x + 1][y] ... 店xまででで時刻yまでの最大値
  dp[x + 1][y] = max(dp[x][y], dp[x + 1][y - 1], dp[x][y - B[x]] + A[x]) (not y - B[x] < s < y)
  dp[x + 1][y] = max(dp[x][y], dp[x + 1][y - 1])
  """
  
  dp = [[0] * (t + 1) for _ in range(n + 1)]
  for x in range(n):
    bx = B[x]
    ax = A[x]
    for y in range(1, t + 1):
      if 0 <= y - bx and (not (y - bx < s < y)):
        dp[x + 1][y] = max(dp[x][y], dp[x + 1][y - 1], dp[x][y - bx] + ax)
      else:
        dp[x + 1][y] = max(dp[x][y], dp[x + 1][y - 1])
  
  print(dp[n][t])

main()


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

using namespace std;

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

typedef long long ll;

int main() {
    int N, K;
    cin >> N >> K;
    long double ans = 0.0;
    for(int i=1;i<=N;i++){
        int num = i, cnt=0;
        //double cnt = 1.0/N;
        while(num < K){
            num *= 2;
            cnt++;
        }
        ans += (long double)(1.0/(double)N * 1.0/ pow(2.0, (double)cnt));
        //ans += cnt;
    }
    printf("%.12Lf\n", ans);
}

Measured memory_bytes: 384
n, k = map(int, input().split())
s = input()
r = 1
ans = 0
cnt = 0

for l in range(0, n):
    if l == 0:
        if s[l] == '0':
            cnt += 1

    if l > 0 and s[l] == '1' and s[l-1] == '0':
        cnt -= 1

    #while True:
    while r <= n - 1:        
        # print('\n', l, r)
        # print('count:', cnt)
        # if r > n - 1:
        #     length = r - l
        #     ans = max(ans, length)
        #     break

        if s[r] == '0' and s[r-1] == '1':
            if cnt < k:
                cnt += 1
            else:
                # print('over!')
                # length = r - l
                # ans = max(ans, length)
                break
        r += 1
    
    length = r - l
    ans = max(ans, length)

print(ans)


Measured memory_bytes: 41712
n,*a=map(int,open(0).read().split())
mod=998244353
d={}
for i in a:
  d[i]=d.get(i,0)+1
b=list(d.items())
b.sort()
ans=1
if a[0]!=0 or len(b)!=b[-1][0]+1 or b[0][1]!=1:
    ans=0
for i in range(1,len(b)):
    ans*=b[i-1][1]**b[i][1]
    ans%=mod
print(ans)

Measured memory_bytes: 20956
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int x = scn.nextInt();
		int item1 = x / 500;
		int ans = item1 * 1000;
		item1 = (x % 500) / 5;
		ans += item1 * 5;
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mode        998244353
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323

const int N = 2e5+5;
ll n, a[N],  dp[N], mx=0;

void solve()
{
       cin>>n;
       rep(i,1,n+1)
       {
              ll x; cin>>x;
              dp[x]=dp[x-1]+1;
              mx=max(mx, dp[x]);
       }
       cout<<n-mx;
}


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


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

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);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 inf INT_MAX/3
#define INF INT_MAX/3
#define PB push_back
#define pb push_back
#define MP make_pair
#define mp make_pair
#define ALL(a) (a).begin(),(a).end()
#define all(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define PII pair<int,int>
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define in scanf
#define out printf
#define LL long long
#define ll long long
#define ULL unsigned long long
#define ull unsigned long long
#define eps 1e-14
#define FST first
#define SEC second

VI a;
int N;

int main(){

	cin >> N;
	a.resize(N);
	REP(i,N){
		cin >> a[i];
	}
	sort(a.begin(),a.end());

	cout << a[N-1] - a[0] << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int lint
typedef long long lint;
typedef pair<int,int> P;
const int    INF=(int)1e9;
const int    MOD=(int)1e9+7;
const double EPS=(double)1e-10;
struct Accelerate_Cin{
    Accelerate_Cin(){
        cin.tie(0); ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);
    };
};

signed main(){
  int X,Y;cin>>X>>Y;
  int temp=X;

  int cont=0;
  while(temp<=Y){
    cont++;
    temp*=2;
  }
  cout<<cont<<"\n";
  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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;}

int main(){
    ld a,v,b,w,t;
    cin>>a>>v>>b>>w>>t;
    if(a+v*t>=b+w*t&&a<b)cout<<"YES"<<endl;
    else if(a-v*t<=b-w*t&&a>b)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(ll i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

ll n, l[100008], r[100008];

ll f(ll x){
	priority_queue<P> lq, rq;
	zep(i, 0, n){
		lq.push(P(l[i], i));
		rq.push(P(-r[i], i));
	}
	
	bool use[n];
	memset(use, 0, sizeof(use));
	
	ll ans = 0;
	ll at = 0;
	zep(i, 0, n){
		if(i%2 == x){
			while(!lq.empty() && use[lq.top().second]){
				lq.pop();
			}
			
			if(!lq.empty()){
				if(lq.top().first-at > 0){
					ans += lq.top().first-at;
					at = lq.top().first;
					use[lq.top().second] = true;
					lq.pop();
				}
			}
		}
		else{
			while(!rq.empty() && use[rq.top().second]){
				rq.pop();
			}
			
			if(!rq.empty()){
				if(at+rq.top().first > 0){
					ans += at+rq.top().first;
					at = -rq.top().first;
					use[rq.top().second] = true;
					rq.pop();
				}
			}
		}
		//print(ans)
	}
	return ans+abs(at);
}

int main(){
	cin.tie(0); ios::sync_with_stdio(false);
	
	cin >> n;
	zep(i, 0, n){
		cin >> l[i] >> r[i];
	}
	
	print(max(f(0), f(1)))
	return 0;
}

Measured memory_bytes: 7340
import java.util.Scanner;

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

    private static void solve(Scanner in) {
        int x = in.nextInt();
        int y = 0;
        for (int i = 0; i <= x; i++) {
            y += i;
            if (y >= x) {
                System.out.println(i);
                break;
            }
        }
    }
}


Measured memory_bytes: 23764
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

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

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n, k;
  scanf("%d%d", &n, &k);
  double p = 1.0 / n;
  double ret = 0;
  for (int i = 1; i <= n; ++i) {
    double cur = p;
    for (int j = i; j < k; j *= 2) cur /= 2;
    ret += cur;
  }
  printf("%.10f\n", ret);
  return 0;
}


Measured memory_bytes: 256
import sys

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prl = lambda x: print(*x ,sep='\n')

s = ns()
ans = 0
n = len(s)
t = 2**(n-1)
for i in range(t):
    moji = list(s)
    for j in range(n):
        if (i >> j) & 1:
            moji.insert(n-j-1,'+')
    ans += eval(''.join(moji))
print(ans)

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

int main(void){
    int N;
    cin >> N;

    double v[N];
    for(int i=0;i<N;i++){cin >> v[i];}

    sort(v, v + N);
    for(int i=0;i<N-1;i++){
        v[i+1] = (v[i] + v[i+1]) / 2.0;
    }

    printf("%lf", v[N-1]);
}


Measured memory_bytes: 256
#define ONLINE_JUDGE
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;

void solve();

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

void solve(){
    ll n;cin>>n;
    double p=(n+1)/2;
    printf("%.7f\n",p/n);
}

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

int selectionSort(int A[], int N){
	int minj, count = 0;
	
	for(int i = 0; i <= N - 1; i++){
		minj = i;
		for(int j = i; j <= N - 1; j++){
			if(A[j] < A[minj]) minj = j;
		}
		swap(A[i], A[minj]);
		if(i != minj)count++;
	}
	
	return count;
}

int main(){
	int N, A[110], count;
	
	cin>>N;

	for(int i = 0; i < N; i++) cin>>A[i];

	count = selectionSort(A, N);

	for(int i = 0; i < N; i++){
		if(i) cout<<" ";
		cout<<A[i];	
	}
	cout<<endl;

	cout<<count<<endl;

	return 0;
}


Measured memory_bytes: 3096
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 2e5+10;
int n;

inline PA Get(int d,ll c){
	if (c==1) return {d,0};
	PA tmp=Get(d,c/2);
	tmp.se=(tmp.se*2+1+(tmp.fi*2>=10));
	if (tmp.fi*2>=10) tmp.fi=(tmp.fi*2)/10+(tmp.fi*2)%10;
		else tmp.fi*=2;
	if (c&1){
		tmp.se=tmp.se+1+(tmp.fi+d>=10);
		tmp.fi=(tmp.fi+d)/10+(tmp.fi+d)%10;
	}
	return tmp;
}

int main(){
	n=read();
	ll x=0,ans=0;
	For(i,1,n){
		ll d=read(),c=read();
		PA tmp=Get(d,c);
		ans+=tmp.se;
		if (i!=1) ans++;
		ans+=(x+tmp.fi>=10);
		x=(x+tmp.fi)/10+(x+tmp.fi)%10;
		//printf(" %lld %lld\n",x,ans);
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
int n,a[42];
long long go(int x,long long s)
{
	if(x==n)return s;
	long long c=0;
	long long s1=0;
	for(int i=x;i<n;i++)
	{
		c=c*10+a[i];
		s1+=go(i+1,s+c);
	}
	return s1;
}
int main()
{
	int c=getchar();
	while(c<=32)
	{
		c=getchar();
	}
	while(c>32)
	{
		a[n++]=c-'0';
		c=getchar();
	}
	cout<<go(0,0)<<'\n';
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<climits>
using namespace std;
int mn,box[30],n;
void func(int now,int a,int b){
	if(now==n){
		int abs;
		if(a-b>=0)
		abs=a-b;
		else
		abs=b-a;
		if(mn>abs)
			mn=abs;
	}
	else{
		func(now+1,a+box[now],b);
		func(now+1,a,b+box[now]);
	}
}
int main(){
	int x;
	while(cin>>n,n){
		mn=INT_MAX;
		for(int i=0;i<n;i++){
			cin>>x;
			box[i]=x;
		}
		func(0,0,0);
		
		
		cout<<mn<<endl;
	}
	return 0;
}

Measured memory_bytes: 868
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define FAST  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int 
#define ar array
#define pb push_back
#define fi(a,b) for(ll i=a;i<(b);i++)
#define fj(a,b) for(ll j=a;j<(b);j++)
#define fk(a,b) for(ll k=a;k<(b);k++)
//hash base 177013

const int mod=1e9+7;

int main()
{
	FAST;
	//#ifndef ONLINE_JUDGE
	//	freopen("input.txt","r",stdin);
	//	freopen("output.txt","w",stdout);
	//#endif
	//ll testcase;
	//cin>>testcase;
	//while(testcase--)
	{
		int s;
		cin>>s;
		int len=(s/3)+1;
		vector<vector<int>> dp(len+2,vector<int> (s+2));
		dp[0][0]=1;
		fi(1,len+1)
		{
			for(int j=3*i;j<=s;j++)
			{
				for(int k=3;k<=j-(i-1)*3;k++)
				{
					if(j-k>=0)
						dp[i][j]=(dp[i][j]+dp[i-1][j-k])%mod;
				}
			}
		}
		int ans=0;
		fi(0,len+1)
		{
			ans=(ans+dp[i][s])%mod;
		}
		cout<<ans;
	}
}


Measured memory_bytes: 8264
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int N = 1000000;
const int INF = 1 << 30;
#define rep(i,n) for(int i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
string YN(bool b) { return(b ? "YES" : "NO"); }
string yn(bool b) { return(b ? "Yes" : "No"); }
int main(){
	ll n, m;
	cin >> n >> m;
	if (n == 1 && m == 1)cout << 1 << endl;
	else if (n == 1 || m == 1)cout << max(n, m) - 2 << endl;
	else cout << (ll)(n - 2)*(m - 2) << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque

input = sys.stdin.buffer.readline
int1 = lambda x: int(x) - 1

N, M = map(int, input().split())
G = [[] for _ in range(3 * N)]
for _ in range(M):
    u, v = map(int1, input().split())
    G[u * 3].append(v * 3 + 1)
    G[u * 3 + 1].append(v * 3 + 2)
    G[u * 3 + 2].append(v * 3)

S, T = map(int1, input().split())
S *= 3
T *= 3

# bfs
d = deque([S])
distance = [0] * (3 * N)
while d:
    v = d.popleft()
    dist_v = distance[v]
    if v == T:
        print(dist_v // 3)
        exit()
    for x in G[v]:
        if not distance[x]:
            d.append(x)
            distance[x] = dist_v + 1
print(-1)


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e9+7;


int main(){
	ios_base::sync_with_stdio(false);
	ll N, ans=0;
	priority_queue<pii> Que[2];

	cin >> N;
	rep(i,N){
		int L, R;
		cin >> L >> R;
		Que[0].emplace(L, i);
		Que[1].emplace(-R, i);
	}

	rep(k,2){
		bool used[100005]={};
		int t = k;
		ll sum = 0, cur = 0;
		priority_queue<pii> que[2];
		rep(i,2) que[i] = Que[i];
		rep(i,N){
			while( used[ que[t].top().Y ] ) que[t].pop();
			int v = que[t].top().X * (t?-1:1);
			int idx = que[t].top().Y;
			//cout << "move: " << cur << " -> " << v << " ";
			if( (v - cur) * (t?-1:1) > 0 ){
				sum += abs(v - cur);
				cur = v;
				used[idx] = true;
			}
			//cout << sum << endl;
			t ^= 1;
		}
		sum += abs(cur);
		chmax(ans, sum);
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

char solve(int m, int f, int r) {
	int sum;

	if (m == -1 || f == -1) {
		return 'F';
	}

	sum = m + f;
	if (sum >= 80) {
		return 'A';
	}else if (sum >= 65) {
		return 'B';
	}
	else if (sum >= 50) {
		return 'C';
	}
	else if (sum >= 30) {
		if (r >= 50) {
			return 'C';
		}
		return 'D';
	}
	return 'F';
}

int main() {
	int m, f, r;

	while (true) {
		cin >> m >> f >> r;
		if (m == -1 && f == -1 && r == -1) {
			break;
		}
		cout << solve(m, f, r) << endl;
	}

	return 0;
}


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

const int INF = 1000000000;

int main(){

int n,m;
int a,b,c,t;


int k;
int p[200];
int q[200];
int r[200];

while(true){
 cin >> n >> m;
 if(n==0 && m==0) break;
 int C[100][100];
 int T[100][100];
 for(int i=0; i<m; i++){
  for(int j=0; j<m; j++){
   if(i==j){
    C[i][j] = T[i][j] = 0;
   }else{
    C[i][j] = T[i][j] = INF;
   }
  }
 }
 for(int i=0; i<n; i++){
  cin >> a >> b >> c >> t;
  C[a-1][b-1] = C[b-1][a-1] = c;
  T[a-1][b-1] = T[b-1][a-1] = t;
 }

 for(int x=0; x<m; x++){
  for(int y=0; y<m; y++){ 
   for(int z=0; z<m; z++){
    if(T[y][z]>T[y][x]+T[x][z]){
     T[y][z]=T[y][x]+T[x][z];
    }
    if(C[y][z]>C[y][x]+C[x][z]){
     C[y][z]=C[y][x]+C[x][z];
    }
   }
  }
 }



 cin >> k;
 for(int i=0; i<k; i++){
  cin >> p[i] >> q[i] >> r[i];
 }

 for(int i=0; i<k; i++){
  if(r[i]==0){
   cout << C[p[i]-1][q[i]-1] << endl;
  }else{
   cout << T[p[i]-1][q[i]-1] << endl;
  }
 }
} 

return 0;
}

Measured memory_bytes: 3148
import java.util.*;

public class Main {

    long INF = Long.MAX_VALUE;
    long[] dp;
    long n;

    public static void main(String[] args) {
        new Main().solve();
    }

    void solve() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] a= new long[N+1];
        long[] b= new long[N+1];
        for(int i = 1;i<=N;i++){
            a[i] = sc.nextInt();
        }
        int all = 0;
        int count =0;
        for(int i = N;1 <= i;i--){
            all = 0;
            for(int j = i*2;j<=N;j+=i){
                all += b[j];
            }
            if(all%2==0&&a[i]==1){
                b[i] = 1;
                count++;
            }else if(all%2==1&&a[i]==0){
                b[i] = 1;
                count++;
            }
        }
        System.out.println(count);
        for(int i=1;i<=N;i++){
            if(b[i]==1)
            System.out.println(i+" ");
        }
    }
    
    int gcd(int m, int n) {
        if (m < n) {
            return gcd(n, m);
        }
        if (n == 0) {
            return m;
        }
        return gcd(n, m % n);
    }
}


Measured memory_bytes: 95544
-- import Data.List
import Control.Monad
import Text.Printf
import Data.List

type Order = [Int] -- [b,f,r,v]

main = do
  n <- readLn
  ss <- replicateM n getLine
  printRooms 1 1 1 . map (map read) $ map words ss 

newline :: IO ()
newline = putStrLn ""

isThisroom :: (Int,Int,Int) -> Order -> Bool
isThisroom (b',f',r') (b:f:r:_) = b' == b && f' == f && r' == r

printRooms :: Int -> Int -> Int -> [Order]-> IO ()
printRooms b f r orders = do
  let v = sum . map getPopulation $ currentOrders
  printf " %d" v
  case (b,f,r) of
    (4,3,10) -> do {newline; return ()}
    (_,3,10) -> do {newline; putStrLn line;
                    printRooms (b + 1) 1 1 restOrders}
    (_,_,10) -> do {newline;
                    printRooms b (f + 1) 1 restOrders}
    _        ->     printRooms b f (r + 1) restOrders
    where line = "####################"
          currentOrders = filter (\o -> isThisroom (b,f,r) o) orders
          restOrders = orders \\ currentOrders
         
getPopulation :: Order -> Int
getPopulation (_:_:_:[v]) = v

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


int main(){
	while(1){
		string s;
		getline(cin,s);
		//cout<<s<<endl;
		if(s[0]=='.')break;
		stack<int> st;
		bool flag = true;
		for(int i=0;i<s.size();i++){
		if(s[i]=='(')st.push(1);
		if(s[i]=='[')st.push(2);
		if(s[i]==')'){
			if(st.empty()|| st.top()!=1) {
				flag = false;
				break;
			}
			else st.pop();
		}
		if(s[i]==']'){
			if(st.empty()|| st.top()!=2) {
				flag = false;
				break;
			}
			else st.pop();
		}


		}
		if(st.size()!=0)flag = false; 
		if(flag) cout<<"yes"<<endl;
		else 	cout<<"no"<<endl;
	}

	return 0;
}



Measured memory_bytes: 3132
#include <algorithm>
#include <cassert>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

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

    map<int, int> A;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        ++A[a];
    }

    int best = 0;
    for (int X = 1; X < 100000 - 1; ++X) {
        best = max(best, A[X - 1] + A[X] + A[X + 1]);
    }

    cout << best << '\n';

    return 0;
}


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

#define int long long

int32_t main () {
    int n; cin >> n;
    if (n >= 400 && n <= 599) {
        cout << 8 << "\n";
    }
    if (n >= 600 && n <= 799) {
        cout << 7 << "\n";
    }
    if (n >= 800 && n <= 999) {
        cout << 6 << "\n";
    }
    if (n >= 1000 && n <= 1199) {
        cout << 5 << "\n";
    }
    if (n >= 1200 && n <= 1399) {
        cout << 4 << "\n";
    }
    if (n >= 1400 && n <= 1599) {
        cout << 3 << "\n";
    }
    if (n >= 1600 && n <= 1799) {
        cout << 2 << "\n";
    }
    if (n >= 1800 && n <= 1999) {
        cout << 1 << "\n";
    }
    return 0;
}

Measured memory_bytes: 3628
def main():
    n, k = map(int, input().split())
    print(solve(n, k))

def solve(n, k):
    p = 0

    for x in range(1, n + 1):
        p += 1 / n * prob(x, k)
    
    return p

def prob(x, k):
    p = 1
    while x < k:
        x *= 2
        p /= 2
    
    return p

main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
vector<int> ans[3];
int main () {
 for (int i = 1; i <= 1010000; i++) {
   if (i%100 != 0 && ans[0].size() < 100) ans[0].push_back(i);
   else if (i%100 == 0 && i%10000 != 0 && ans[1].size() < 100) ans[1].push_back(i);
   else if (i%10000 == 0 && i%1000000 != 0 && ans[2].size() < 100) ans[2].push_back(i);
 }
 int d,n;
 scanf ("%d %d",&d,&n);
 printf ("%d\n",ans[d][n-1]);
 return 0;
}


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

int main(){

  int n;
  cin >> n;
  double T, A;
  cin >> T >> A;
  double h[n];
  for(int i=0; i<n; i++){
    cin >> h[i];
  }

  double min_d = (double) INF;
  int min_idx;
  for(int i=0; i<n; i++){
    double tmp = T - h[i]*0.006;
    double d = abs(tmp-A);
    if(d< min_d){
      min_d = d;
      min_idx = i+1;
    }
  }

  cout << min_idx << endl;

}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main(){
    int N;
    long long int lis[80];
    cin>>N;
    for(int i=0;i<N;i++)cin>>lis[i];
    /*
    long long int agesage[100]={0};
    for(int i=1;i<N-1;i++){
        if(lis[i-1]<lis[i]&&lis[i]>lis[i+1])agesage[i]=2;
        if(lis[i-1]>lis[i]&&lis[i]<lis[i+1])agesage[i]=1;
    }
    long long int ans=1000;
    long long int kabu=0;
    for(int i=0;i<N;i++){
        if(agesage[i]==1){
                //printf("[%d][%lld]\n",i,ans);
            long long int kaukazu=ans/lis[i];
            kabu+=kaukazu;
            ans-=lis[i]*kaukazu;
        }
        else if(agesage[i]==2||i==N-1){
            ans+=lis[i]*kabu;
            kabu=0;
        }
    }

    cout<<ans<<endl;
*/


    long long int agesage[100]={0};
    for(int i=N-2;0<=i;i--){
        if(lis[i]<lis[i+1])agesage[i]=1;//kai
        if(lis[i]>lis[i+1])agesage[i]=2;//uri
    }
    long long int ans=1000;
    long long int kabu=0;
    for(int i=0;i<N;i++){
        if(agesage[i]==1){
                //printf("[%d][%lld]\n",i,ans);
            long long int kaukazu=ans/lis[i];
            kabu+=kaukazu;
            ans-=lis[i]*kaukazu;
        }
        else if(agesage[i]==2||i==N-1){
            ans+=lis[i]*kabu;
            kabu=0;
        }
    }

    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3520
import java.util.*;
 
class Main {
	public static void main (String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int count = 0;
		
		//Nまでの奇数をとる
		for (int i = 1; i <= N; i+=2) {
			//divを初期化
			int div = 0;
			//約数の計算
			for (int j = 1; j <= i; j++) {
				if(i%j == 0) {
					div++;
				}
			}
			//System.out.println(i + "の約数 : " + div + "個");
			
			//div==8のときのみ、countに追加
			if (div == 8) {
				count++;
			}
		}
		System.out.println(count);
	}
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n;
    string s;
    cin >> n >> s;
    
    int res = 1;
    char c = s[0];
    for(int i = 1; i < n; ++i){
        if(s[i] == c)   continue;
        
        c = s[i];
        ++res;
    }
    cout << res << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<iterator>
#include<set>
#include<queue>

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

using namespace std;


int main(){
	int n;cin>>n;
	vector<int> t,a;
	rep(i,n){
		int temp;cin>>temp;
		t.push_back(temp);
	}
	rep(i,n){
		int temp;cin>>temp;
		a.push_back(temp);
	}
	vector<int> exact1(n,-1);
	vector<int> exact2(n,-1);
	vector<int> upper(n);
	int height = -1;
	rep(i,n){
		if(height < t[i]){
			height = t[i];
			exact1[i] = t[i];
			upper[i] = t[i];
		}
		else{
			upper[i] = t[i];
		}
	}
	rep(i,n){
		if(i == n-1){
			exact2[i] = a[i];
		}
		else if(a[i] > a[i+1]){
			exact2[i] = a[i];
			upper[i] = min(a[i], upper[i]);
		}
		else{
			upper[i] = min(upper[i],a[i]);
		}
	}
	long long mod = 1000000007;
	long long res = 1;
	rep(i,n){
		if(exact1[i] != -1 && exact2[i] != -1 && exact1[i] != exact2[i])
			res = 0;
		else if(exact1[i] != -1 || exact2[i] != -1){
			if(exact1[i] <= upper[i] && exact2[i] <= upper[i])
				continue;
			else
				res = 0;
		}
		else{
			res *= upper[i];
			res %= mod;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 2296
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    string s;
    cin >> s;
    int ans = 0;
    int n = s.size();
    int cnt = 0;
    rep(i, n) {
        if(s[i] == 'A' || s[i] == 'T' || s[i] == 'G' || s[i] == 'C') ++cnt;
        else cnt = 0;
        ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

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

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N=ii()
    C = list(input())

    R = []
    W = []
    for i,c in enumerate(C):
        if c == "R":
            R.append(i)
        else:
            W.append(i)
    

    W.sort(reverse=True)
    R.sort()

    if len(R) == 0 or len(W) == 0:
        print(0)
        exit()

    ri = R.pop()
    wi = W.pop()

    ans = 0
    while not ri < wi:
        ans += 1
        if len(R) == 0 or len(W) == 0: break

        ri = R.pop()
        wi = W.pop()    


    print(ans)






if __name__ == "__main__":
    main()

Measured memory_bytes: 89780
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
int main() {
    fastio ;
    ll len;
    cin>>len;
    string s;
    cin>>s;
    int c =0 ;
    ll j = len -1;
    int i=0;
    while(j > i) {

        while(s[i] == 'W' && s[j] == 'R' && j > i) {
            swap(s[i],s[j]);
            c++;
            i++;
            j--;
        }
        if(s[i] == 'R')i++;
        if(s[j] == 'W')j--;
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3720
package main
import "fmt"
func main(){
    // Your code here!
    var n int
    fmt.Scan(&n)
    t := make([]string, n)
    for i := 0; i < n; i++ {
        fmt.Scan(&t[i])
    }
    
    if true == check_uniq(t){
        fmt.Println("YES")
    }else{
        fmt.Println("NO")
    }
}

func check_uniq(origin []string) bool{
    m := make(map[string]bool)
    uniq := [] string{}
    for _, ele := range origin {
        if !m[ele] {
            m[ele] = true
            uniq = append(uniq, ele)
        }
    }
    if len(origin) == len(m){
        return true
    }
    return false
}

Measured memory_bytes: 30080
import java.util.Scanner;

public class Main {

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

        int n = sc.nextInt();

        long[][] dp = new long[n][3];
        int[][] happy = new int[n][3];

        long INF = Long.MAX_VALUE;

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 3; j++) {
                happy[i][j] = sc.nextInt();
            }
        }

        sc.close();

        dp[0][0] = happy[0][0];
        dp[0][1] = happy[0][1];
        dp[0][2] = happy[0][2];

        for (int i = 1; i < n; i++) {
            dp[i][0] = happy[i][0] + Math.max(dp[i - 1][1], dp[i - 1][2]);
            dp[i][1] = happy[i][1] + Math.max(dp[i - 1][0], dp[i - 1][2]);
            dp[i][2] = happy[i][2] + Math.max(dp[i - 1][0], dp[i - 1][1]);
        }

        long ans = Math.max(dp[n - 1][0], Math.max(dp[n - 1][1], dp[n - 1][2]));

        System.out.println(ans);
    }

}

Measured memory_bytes: 103744
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
// You should only debug a pair of simple data types. For example,
// the debug won't work if one of pair's elements is collection type
// (std::vector, std::map, std::set...).
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


// bool check_prime(int n)  return whether a number is prime or not O(sqrt(N));
// int BE(int x,int n,int m)  return x^n%m; O(logN);
// void sieve()  from number 1-1000001 saare prime store kar lega  in bool is_prime[1000001] array
// vector<int> z_array(string s)  return vector which is Z-array of string s;
// vector<int> lps(string s)      return vector which is lps array of string s;
// int power(int x,int n) return x^n; O(logN);
// using_ordered_set (template for using ordered set , replace first 2 lines of this page with this code..);


int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

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

	}
	int ans = 0;
	zip(i, 1, n)
	{
		if (a[i] < a[i - 1])
		{
			int d = a[i - 1] - a[i];
			a[i] += d;
			ans += d;
		}
	}
	cout << ans << en;

	return 0;
}




Measured memory_bytes: 5204
import java.util.*;



public class Main{

	
	//最大公約数・最小公倍数（セットで使う）
	public static long gcm(long a, long b) {
		long result = a;
		long k = 0;
		long n = b;
		do {
			k = result % n;
			result = n;
			n = k;
		} while(k != 0);
		return result;
	}
	
	public static long lcm(long a, long b) {
		long g;
		g = gcm(a, b);
		return a/g*b;
	}
	
	static long gcd (long a, long b) {
		long temp;
		while((temp = a%b)!=0) {
			a = b;
			b = temp;
		}
		return b;
	}
	
	//等差数列
	static long tousasum(int n) {
		return (long)n*((long)n+1)/2;
	}



	//素数判定
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2) if(n%i==0){return false;}
		return true;
	}


	//倍数判定（10進数以外のときに有用）
	static boolean isMultiple (String s, int base, int m) {
		int temp = 0;
		for (int i=0; i<s.length(); i++) {
			temp = (temp*base+Character.getNumericValue(s.charAt(i)))%m;
		}
		if (temp==0) {return true;}
		return false;
	}


	//階乗
	static long factorial (int i) {
		if (i==1) {return 1;}
		else {return i*factorial(i-1);}
	}


	//進数変換
	static String toNbase (String sm, int m, int n) {
		return Long.toString(Long.parseLong(sm,m),n);
	}
	
	public static final long gcd_n(long[] param) {
	    final int len = param.length;
	    long g = gcd(param[0], param[1]);    //gcd(a, b) は以前作ったもの
	    for (int i = 1; i < len - 1; i++) {
	        g = gcd(g, param[i + 1]);       //gcd(a, b) は以前作ったもの
	    }
	    return g;
	}
	
	public static long lcm_n(long[] numbers) {
		long l;
		l = numbers[0];
		for (int i = 1; i < numbers.length; i++) {
			l = lcm(l, numbers[i]);
		}
		return l;
	}
	
	
 public static void main(String[] args) {
	 Scanner sc=new Scanner(System.in);
	 int N=sc.nextInt();
	 long[] A=new long[N+1];
	 for(int i=0;i<N+1;i++) {
		 A[i]=sc.nextLong();
	 }
	 long result=0;
	 
	 for(int i=0;i<N;i++) {
		 long max=sc.nextLong();
		 if(max>=A[i]) {
			 max-=A[i];
			 result += A[i];
			 A[i]=0;
			 
		 }else {
			 result += max;
			 A[i] -= max;
			 max = 0;
			 
		 }
		 
		 if(max>=A[i+1]) {
			 max-=A[i+1];
			 result += A[i+1];
			 A[i+1]=0;
		 }else {
			 result += max;
			 A[i+1] -= max;
			 max = 0;
			 
		 }
	 }
	 
	 System.out.println(result);
	 
	 
 }
	


}



Measured memory_bytes: 64148
n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = 0
for r in range(n-1,-1,-1):
  m = r
  for l in range(n):
    if l == m and m + 1 < r:
      m += 1
    else:
      while True:
        if a[l] + a[m-1] > a[r] and l < m-1:
          m -= 1
        else:
          break
    if l < m < r:
      ans += r - m
      #print(l,m,r)
print(ans)

Measured memory_bytes: 43488
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;



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

  ll N,M;
  cin >> N >> M;
  vector<ll> A(N);
  REP(i,N) { cin >> A[i]; }
  sort(A.begin(), A.end());

  // obtain maximum avarage value x with M handshake
  ll l = 0;
  ll r = A[N-1]*2+1;
  while (l+1<r){
    ll c = (l+r)/2;
    // calc number of handshake larger than c
    ll num = 0;
    REP(i,N){
      num += N - (lower_bound(A.begin(), A.end(), c-A[i]) - A.begin());
    } 
    // bns
    if (num >= M){
      l = c;
    } else {
      r = c;
    }
  }

  // calc value
  vector<ll> sum(N+1);
  REP3(i,1,N+1) { sum[i] = sum[i-1]+A[i-1]; }  
  ll count = 0;
  ll ans = 0;
  REP(i,N){
    ll v = upper_bound(A.begin(), A.end(), l-A[i]) - A.begin();
    count += N-v;
    ans += (N-v)*A[i] + sum[N]-sum[v];
  }
  
  ans += (M-count)*l;
  
  cout << ans << "\n";
  return 0;
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int N, K;
  cin >> N >> K;

  vector<int> V(N);
  rep (i, N) cin >> V[i];

  vector<int> lSum(N + 1, 0), rSum(N + 1, 0);
  rep (i, N) {
    lSum[i + 1] = lSum[i] + V[i];
    rSum[i + 1] = rSum[i] + V[N - i - 1];
  }

  vector<vector<int>> lMinusSum(N + 1, vector<int>(N + 1, 0)), rMinusSum(N + 1, vector<int>(N + 1, 0));
  vector<int> lTmp, rTmp;
  rep (i, N) {
    lTmp.eb(V[i]);
    rTmp.eb(V[N - i - 1]);

    sort(all(lTmp));
    sort(all(rTmp));

    int l = 0, r = 0;
    rep (j, i + 1) {
      if (lTmp[j] < 0) l += lTmp[j];
      if (rTmp[j] < 0) r += rTmp[j];
      lMinusSum[i + 1][j + 1] = l;
      rMinusSum[i + 1][j + 1] = r;
    }
  }

  int ans = 0;
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= N; j++) {
      if (i + j > K || i + j > N) break;
      int ret = K - i - j;
      for (int p = 0; p <= i; p++) {
        for (int q = 0; q <= j; q++) {
          if (p + q > ret || p + q > N) break;
          ans = max(ans, lSum[i] + rSum[j] - lMinusSum[i][p] - rMinusSum[j][q]);
        }
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007

#define access(i) a[i/3][i%3]

 int main(){

  long long n,k;
  cin>>n>>k;

 vector<pair<ll,ll>> p(n);

 for(int i=0;i<n;i++){
    cin>>p[i].first>>p[i].second;
 }

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

 ll sum =0 ;

 for(int i=0;i<n;i++)
 {
    sum += p[i].second;
    if(sum >= k){
        cout<<p[i].first<<endl;
        return 0;
    }

 }

 return 0;
 }


Measured memory_bytes: 4820
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ABC155 {
    public class A {
        public static void Main() {
            var strs = Console.ReadLine().Split(' ').Take(3);
            if (strs.Distinct().Count() == 2) {
                Console.WriteLine("Yes");
                return;
            }
            Console.WriteLine("No");
            return;
        }
    }
}


Measured memory_bytes: 13280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int>P;
#define PI 3.14159265359
#define MOD 1000000007
const int MAX = 510000;

int main(){
  ll l,r;cin >>l>>r;
  ll g=min(l+2019,r);
  ll ans=2018;ll memo=2018;
  for(ll i=l;i<g;i++){
  	for(ll j=i+1;j<=g;j++){
    	memo=((i%2019)*(j%2019))%2019;
      	ans=min(ans,memo);
    }
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    long long int a=0,b=0,c=0,d=0,e=0,co=0;
    cin>>n;
    for(int i=0;i<n;i++){
        char s[100];
        cin>>s;
        if(s[0]=='M') a++;
        if(s[0]=='R') b++;
        if(s[0]=='A') c++;
        if(s[0]=='C') d++;
        if(s[0]=='H') e++;
    }
    co+=a*b*c;
    co+=a*b*d;
    co+=a*b*e;
    co+=a*c*d;
    co+=a*c*e;
    co+=a*d*e;
    co+=b*c*d;
    co+=b*c*e;
    co+=b*d*e;
    co+=c*d*e;
    cout<<co<<endl;
}


Measured memory_bytes: 256
import numpy as np
H, N = map(int, input().split())
ATK, MP = np.array(tuple(tuple(map(int, input().split())) for _ in range(N)), dtype=np.int64).T
MAX_ATK = ATK.max()
table = np.zeros((H + MAX_ATK,), dtype=np.int64)
for damage in range(1, H + 1):
    table[damage] = (table[damage - ATK] + MP).min()
print(table[H])


Measured memory_bytes: 12512
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.array;
import std.math;

void main(){
  auto n=readln.chomp.to!int;
  auto a=readln.chomp.to!int;
  if(n%500<=a)writeln("Yes");
  else writeln("No");
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace ConsoleApp6
{
    class Program
    {
        static void Main()
        {
            Console.ReadLine();
            var cards = Console.ReadLine().Split(' ').Select(int.Parse);
            var lookup = cards.OrderByDescending(x => x).Select((x, i) => new { x, i }).ToLookup(x => x.i % 2);
            Console.WriteLine(lookup[0].Sum(x => x.x) - lookup[1].Sum(x => x.x));
        }
    }
}


Measured memory_bytes: 13536
n,k,q = gets.split.map(&:to_i)
cnt = [0]*n
q.times do |i|
  t = gets.to_i
  cnt[t-1] += 1
end

cnt.each do |v|
  if k - (q-v) > 0
    puts "Yes"
  else
    puts "No"
  end
end

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

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RREP(i, a, b) for (int i = (int)(a)-1; i >= (int)(b); --i)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)
#define ALL(r) (r).begin(), (r).end()

void Main();

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

void Main() {
    int64_t n, x, t; cin >> n >> x >> t;
    cout << (n + x - 1) / x * t << endl;
}


Measured memory_bytes: 3616