akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

int h,w,r,c;

enum DIR { L, U, R, D };
int di[] = { 0, -1, 0, 1 };
int dj[] = { -1, 0, 1, 0 };
int open[510][510][4];
int win[510][510];

bool inner(int i, int j){
    return i >= 0 && j >= 0 && i < h && j < w;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    while(cin >> h >> w >> r >> c && h){
        --r; --c;
        memset(win, 0, sizeof win);
        memset(open, 0, sizeof open);
        rep(i,h*2+1){
            if(i%2 == 0){
                rep(j,w){
                    int x;
                    cin >> x;
                    open[i/2][j][U] = !x;
                    if(i/2) open[i/2-1][j][D] = !x;
                }
            } else {
                rep(j,w+1){
                    int x;
                    cin >> x;
                    open[i/2][j][L] = !x;
                    if(j) open[i/2][j-1][R] = !x;
                }
            }
        }
        queue<pair<int,int>> q;
        rep(i,h)rep(j,w) q.emplace(i,j);
        while(q.size()){
            int ci,cj;
            tie(ci,cj) = q.front();
            q.pop();
            int cnt[2] = {};
            if(win[ci][cj]) continue;
            rep(d,4){
                int ni = ci + di[d];
                int nj = cj + dj[d];
                if(!inner(ni,nj) || win[ni][nj]){
                    ++cnt[open[ci][cj][d]];
                }
            }
            // cout << ci << ' ' << cj << ' ' << cnt[0] << ' ' << cnt[1] << endl;
            if(cnt[0] && cnt[1]){
                win[ci][cj] = true;
                // cout << ci << ' ' << cj << endl; 
                rep(d,4){
                    int ni = ci + di[d];
                    int nj = cj + dj[d];
                    if(inner(ni,nj) && !win[ni][nj]){
                        q.emplace(ni,nj);
                    }
                }
            }
        }
        bool ok = win[r][c];
        rep(d,4){
            int ni = r + di[d];
            int nj = c + dj[d];
            if(open[r][c][d] && (!inner(ni,nj) || win[ni][nj])) ok = true;
        }
        cout << (ok ? "Yes" : "No") << '\n';
    }
}

Measured memory_bytes: 9964
#include <iostream>
#include <math.h>
using namespace std;

#define PI (3.141592)

int main()
{
	int hosu, angle,angleplus;
	angle = 0;
	double x = 0,y=0;
	char c;
	while( cin >> hosu >> c >> angleplus ) {
		if( hosu == 0 && angleplus == 0 )
			break;
		x += hosu * sin(angle * PI / 180 );
		y += hosu * cos(angle * PI / 180 );
		angle += angleplus;
		
	}
	printf("%d\n%d\n",(int)x,(int)y);

	return 0;
}

Measured memory_bytes: 0
import sys
def input():
    return sys.stdin.readline()[:-1]

N,K = map(int,input().split())
H = list(map(int,input().split()))
inf = 10**9+7
dp = [inf] * (N+10)
dp[0] = 0
for i,h in enumerate(H):
    for j in range(1,K+1):
        if i+j < N:
            dp[i+j] = min(dp[i+j],dp[i] + abs(h-H[i+j]))

print(dp[N-1])


Measured memory_bytes: 52448
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

string day[7] =  {"SUN", "MON","TUE","WED","THU","FRI","SAT"};

int main(){
    int A, B;
    cin >> A >> B;
    if(A <= 9 && B <= 9){
        cout << A * B << endl;
    }else{
        cout << -1 << endl;
    }
}


Measured memory_bytes: 256
//作成日：4/20
#import<stdio.h>
#import<objc/Object.h>
 
int main(){
	//日付を受け取る変数
	int day;
  
  	scanf("%d",&day);
	//条件分岐
	if (day == 25){
	  printf("Christmas");
	}
	else if (day == 24){
 		printf("Christmas Eve");
	}
	else if (day == 23){
		printf("Christmas Eve Eve");
	}
	else{
  		printf("Christmas Eve Eve Eve");
	}
  return 0;
}

Measured memory_bytes: 5480
#include <bits/stdc++.h>  // ver2.3.4
#define int long long
#define endl "\n"
#define ALL(v) (v).begin(),(v).end()
#define COUNT(a,k) upper_bound(ALL(a),k)-lower_bound(ALL(a),k)
#define BIGGER(a,k) a.end()-upper_bound(ALL(a),k)
#define SMALLER(a,k) lower_bound(ALL(a),k)-a.begin()
#define Vi vector<int>
#define VVi vector<Vi>
#define Vs vector<string>
#define Pii pair<int,int>
#define VPii vector<Pii>
#define Tiii tuple<int,int,int>
#define VTiii vector<Tiii>
#define PQi priority_queue<int>
#define PQir priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define itos to_string
#define stoi stoll
#define FI first
#define SE second
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define cyes cout<<"yes"<<endl
#define cno cout<<"no"<<endl
#define _ <<' '<<
#define sortr(v) sort(v,greater<>())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repeq(i,a,b) for(int i=a;i<=b;i++)
#define repreq(i,a,b) for(int i=a;i>=b;i--)
#define leng(n) (int)(log10(n)+1)
#define dem(a,b) ((a+b-1)/(b))
#define Vin(a) rep(iI,0,a.size())cin>>a[iI]
#define Vout(a) rep(lZ,0,a.size()-1)cout<<a[lZ]<<' ';cout<<a.back()<<endl
#define VVout(a) rep(lY,0,a.size()){if(!a[lY].empty()){Vout(a[lY]);}else cout<<endl;}
#define VPout(a) rep(lX,0,a.size())cout<<a[lX].FI<<' '<<a[lX].SE<<endl
#define Verr(a) rep(iZ,0,a.size()-1)cerr<<a[iZ]<<' ';cerr<<a.back()<<endl
#define VVerr(a) rep(J,0,a.size()){if(!a[J].empty()){Verr(a[J]);}else cerr<<'.'<<endl;}
#define VPerr(a) rep(iX,0,a.size())cerr<<a[iX].FI<<' '<<a[iX].SE<<endl
#define INF 3000000000000000000  //  3.0*10^18(MAXの1/3くらい)
#define MAX LLONG_MAX
#define PI 3.141592653589793238462
#define MOD 1000000007  //  10^9 + 7
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;} // 最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;} // 最小公倍数lcm
int mypow(int x, int n, int m){ // 累乗x^n(mod m) O(log(n))
if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int scomb(int n, int r){if((n-r)<r)r=n-r; // nCr(小さい場合)
int a=1;for(int i=n;i>n-r;--i){a=a*i;}for(int i=1;i<r+1;++i){a=a/i;}return a;}
int comb(int n, int r){if((n-r)<r)r=n-r; // nCr(%MOD)
int a=1;for(int i=n;i>n-r;--i){a=a*i%MOD;}for(int i=1;
i<r+1;++i){a=a*mypow(i,MOD-2,MOD)%MOD;}return a%MOD;}
Vi stpowV(){Vi a(100001);
a[0]=1;repeq(i,1,100000)a[i]=a[i-1]*i%MOD;return a;}
//Vi stpow = stpowV();  // 階乗配列(%MOD)
void press(auto &v){v.erase(unique(ALL(v)),v.end());} // 圧縮
Vi Vsum(Vi &v){Vi S(v.size()+1);rep(i,1,S.size())S[i]+=v[i-1]+S[i-1];return S;} // 累積和
int keta(int k,int i){string s = itos(k);return s[s.size()-i]-'0';} // i桁目の数字



signed main() {
  cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
  int n,m,qw,er,ty;
  string s,t;
  cin >> n;
  qw = n*100.0/108.0;
  
  
  
  rep(i,-2500,2500){
    
    int as = (qw+i)*1.08;
    
    if(as==n){
      cout << qw+i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
  
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <limits>
#include <sstream>
#include <fstream>
#include <climits>
#include <map>
#include <numeric>
#include <functional>
#include <utility>

using namespace std;

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

int main(void) {
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  cout << (H - h) * (W - w) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define T_MAX 10000
#define S_MAX 500

int main(void){
	int n,q,i,j,cnt = 0;
	int t_cnt = 0,s_cnt = 0;
	int T[T_MAX] = {0};
	int S[S_MAX] = {0};

	scanf("%d", &n);

	while(1){
		if(t_cnt == n){
			break;
		}
		scanf("%d" ,&T[t_cnt]);
		t_cnt++;
	}

	scanf("%d", &q);

	while(1){
		if(s_cnt == q){
			break;
		}
		scanf("%d" ,&S[s_cnt]);
		s_cnt++;
	}

	for(i = 0;i < q;i++){
		for(j = 0;j < n;j++){
			if(S[i] == T[j]){
				cnt++;
				break;
			}
		}
	}

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

	return 0;
}

Measured memory_bytes: 648
package main

import "fmt"

func main() {
	atgc := map[rune]struct{}{
		'A': struct{}{},
		'T': struct{}{},
		'G': struct{}{},
		'C': struct{}{},
	}

	var s string
	fmt.Scan(&s)
	var max, cur int
	for _, b := range s {
		if _, ok := atgc[b]; ok {
			cur++
			if cur > max {
				max = cur
			}
		} else {
			cur = 0
		}
	}

	fmt.Println(max)
}


Measured memory_bytes: 512
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll fac(ll a) { return a > 1 ? fac(a - 1) * a : 1; }
int solve(){
  string s;
  cin >> s;
  if(s.size() == 3)cout << s[2] << s[1] << s[0] << endl;
  else cout << s << endl;
  return 0;
}
int main(){
  ios::sync_with_stdio(false);cin.tie(nullptr);
  solve();
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(c>=b)
    cout<<b<<endl;
  else
    cout<<c<<endl;
  if(b+c-a>0)
    cout<<b+c-a<<endl;
  else
    cout<<"0"<<endl;
  return(0);
}

Measured memory_bytes: 256
import sys 
from itertools import accumulate
input=sys.stdin.readline
Q=int(input().rstrip())
S=[list(map(int,input().rstrip().split())) for _ in range(Q)]


def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    is_prime=[False]+is_prime
    return is_prime, table


def resolve():
    maxN=10**5+1
    booltable1,table1=sieve(maxN)
    booltable2,table2=sieve((maxN+1)//2)
    booltable=[0 for _ in range(maxN+1)]
    for i in range(1,maxN+1,2):
        booltable[i]=booltable1[i] and booltable2[(i+1)//2]
    # 累積和
    #booltable=[0]+booltable
    cumsum = list(accumulate(booltable))

    for i in range(Q):
        print(cumsum[S[i][1]]-cumsum[S[i][0]-1])
    
import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """1
3 7"""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """4
13 13
7 11
7 11
2017 2017"""
        output = """1
0
0
1"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """6
1 53
13 91
37 55
19 51
73 91
13 49"""
        output = """4
4
1
1
1
2"""
        self.assertIO(input, output)

if __name__ == "__main__":
    #unittest.main()
    resolve()

Measured memory_bytes: 36740
#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(){
	int n,d,x;
	cin >> n >> d >> x;
	int sum = 0;
	rep(i,n){
		int a;
		cin >> a;
		sum += (d-1)/a+1;
	}
	int ans = sum + x;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<stack>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  stack<int>st;
  while(b!=0)
  {
    st.push(b%10);
    b/=10;
  }
  while(!st.empty()){
      int element=st.top();
      a*=10;
      a+=element;
      st.pop();
  }
  int result=sqrt(a);
  if(result*result==a)
    cout<<"Yes";
  else
    cout<<"No";
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
const int INF=1e5+100;
int main()
{
    ll a,b,x,ans=0;
    cin>>a>>b>>x;
    ll m=a/x,n=b/x;
    ans=n-m;
    if(a%x==0)  ans++;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _1_9_B
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> cardList = new List<string>();
            while (true)
            {
                string card = Console.ReadLine();
                if (card == "-") break;
                int m = int.Parse(Console.ReadLine());
                for(int i = 0; i < m; i++)
                {
                    int h = int.Parse(Console.ReadLine());
                    card = card.Substring(h,card.Length-h) + card.Substring(0, h);
                }
                cardList.Add(card);
            }
            for (int i = 0; i < cardList.Count; i++)
            {
                Console.WriteLine(cardList[i]);
            }
        }
    }
}



Measured memory_bytes: 15900
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define int long long
using namespace std;

typedef pair <int, int> pii;

pii a[60];
int dp[60];
vector <pii> all;
set <pii> s;

signed main(){
	int n; scanf("%lld", &n);
	for (int i = 0; i < n; i++){
		scanf("%lld%lld", &a[i].fi, &a[i].se);
		s.insert(a[i]);
	}
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			if (i == j) continue;
			all.push_back(mp(a[i].fi - a[j].fi, a[i].se - a[j].se));
		}
	}
	int ans = n;
	for (int i = 0; i < all.size(); i++){
		int p = all[i].fi, q = all[i].se;
		int tot = 0;
		for (int j = 0; j < n; j++){
			pii x = mp(a[j].fi - p, a[j].se - q);
			if (!s.count(x)) tot++;
		}
		ans = min(ans, tot);
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#if ONLINE_JUDGE
#define DEBUG false
#else
#define DEBUG true
#endif
#define REP(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define rep1(i, n) REP(i, 1, n)
#define rREP(i, k, n) for (int i = (int)(n)-1; i >= k; i--)
#define rrep(i, n) rREP(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) std::sort(all(x))
#define REV(x) std::reverse(all(x))
#define UNIQUE(x) x.erase(std::unique(all(x)), x.end());
#define MAX(x) *std::max_element(all(x))
#define MIN(x) *std::min_element(all(x))
#define LOWitr(x, n) std::lower_bound(all(x), n)
#define UPRitr(x, n) std::upper_bound(all(x), n)
#define cii(x) int x; std::cin >> x
#define cill(x) signed long long int x; std::cin >> x
#define cis(x) std::string x; std::cin >> x
#define co(x) std::cout << x << "\n"
#define pb push_back
#define mp std::make_pair
#define F first
#define S second
#define truecheck assert
#define dump(x) if(DEBUG) std::cout<<#x<<" : "<<(x)<<"\n"
template<class T>using V = std::vector<T>;
template<class T>using VV = std::vector<std::vector<T>>;
template<class T>using Q = std::queue<T>;
template<class T>using PQ = std::priority_queue<T>;
template<class T,class U>using P = std::pair<T, U>;
template<class T,class U>using M = std::map<T, U>;
template<class T,class U>using UM = std::unordered_map<T, U>;
template<class T,class U>inline bool chmax(T &a, const U &b){if (a<b){a=b;return true;}return false;}
template<class T,class U>inline bool chmin(T &a, const U &b){if (b<a){a=b;return true;}return false;}
template<class T>inline void vcin(T &v){for(auto&& i : v) std::cin >> i;}
template<class T>inline void dumpv(const T& v, std::ostream& os = std::cout){
    if(DEBUG){
        os<<"{";
        std::for_each(all(v),[&os](typename T::value_type p){os<<p<<',';});
        os<<"}\n";
    }
}
using std::cin;
using std::cout;
using std::string;
using std::min;
using std::next_permutation;
using LL = signed long long int;
const int INF = INT_MAX, MOD = 1e9 + 7;
const LL LLINF = LLONG_MAX;
const double PI = M_PI;

void Main(){
    cill(n);
    LL ans = 1, lim = 1000000000000000000;
    bool over = false;
    rep(i, n){
        cill(x);
        dump(x);
        if (x==0){
            co("0");
            return;
        }
        if (x > lim){
            over = true;
        }
        ans *= x;
        lim /= x;
    }
    if (over){
        co("-1");
    }else{
        co(ans);
    }
}

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

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

int main(){

  int n,k;
  cin >> n >> k;
  ll height[15],maxHeightPre[15], tmp_height;
  ll min_cost, tmp_cost;
  maxHeightPre[0] = 0;
  rep(i,n){
    cin >> height[i];
    if(i){
      maxHeightPre[i] = max(maxHeightPre[i-1],height[i-1]);
    } 
  }

  rep(i, 1<<n-1){
    bitset<16> bit(i);
    if(bit.count() != k-1) continue;
    tmp_cost =0;
    tmp_height =0;
    rep(j,n-1){
      if(bit[j]){
        tmp_height = max(maxHeightPre[j+1],tmp_height);
        if(height[j+1] <= tmp_height){
          tmp_height++;
          tmp_cost += tmp_height  -  height[j+1]; 
        }
      }
    }
    min_cost = min(min_cost, tmp_cost);
  }

  cout << min_cost << endl;
  return 0;
}

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

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)

vector<int> a, b, c, d;


int dfs(vector<int> A, int ret, int N, int M, int Q){
    if(A.size() == N+1){
        int s = 0;
        REP(i, Q){
            if(A[b[i]] - A[a[i]] == c[i]) s += d[i];
        }
        return max(s, ret);
    }

    A.push_back(A.back());
    while(A.back() <= M){
        ret = max(ret, dfs(A, ret, N, M, Q));
        ++A.back();
    }

    return ret;
}

int main()
{
    int N, M, Q;
    cin >> N >> M >> Q;
    a = b = c= d= vector<int>(Q);
    REP(i, Q) cin >> a[i] >> b[i] >> c[i] >> d[i];

    // あり得る数列を全探索
    cout << dfs(vector<int>(1, 1), 0, N, M, Q) << endl;

    return 0;
}

Measured memory_bytes: 3144
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
using namespace std;

struct UnionFind{
private:
  vector<int> data;
public:
  int N;
  UnionFind(int n) : data(n, -1), N(n){}
  bool unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return false;
    --N;
    if(data[y] < data[x]) swap(x,y);
    data[x] += data[y];
    data[y] = x;
    return x != y;
  }
  bool same(int x, int y){ return find(x) == find(y); }
  int find(int x){
    if(data[x] < 0) return x;
    return data[x] = find(data[x]);
  }
  int size(int x){ return -data[find(x)]; }
};

int main(){
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  for(int i = 0; i < N; ++i) cin >> A[i];
  for(int i = 0; i < N; ++i) cin >> B[i];

  {
    vector<int> I(N);
    for(int i = 0; i < N; ++i) I[i] = i;
    sort(I.begin(), I.end(), [&](const int &a, const int &b){ return B[a] != B[b] ? B[a] < B[b] : A[a] < A[b]; });
  
    vector<int> A_(N);
    for(int i = 0; i < N; ++i){
      A_[i] = A[I[i]];
    }
    swap(A,A_);

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

    for(auto a : A)
      cerr << a << " ";
    cerr << endl;
    for(auto b : B)
      cerr << b << " ";
    cerr << endl;
  }
  vector<int> C = A;
  sort(C.begin(), C.end());
  for(int i = 0; i < N; ++i){
    if(C[i] > B[i]){
      cout << "No" << endl;
      return 0;
    }
  }
  for(int i = 1; i < N; ++i){
    if(C[i] == C[i-1]){
      cout << "Yes" << endl;
      return 0;
    }
  }
  map<int,int> M;
  for(int i = 0; i < N; ++i){
    M[C[i]] = i;
  }
  UnionFind uf(N);
  for(int i = 0; i < N; ++i){
    uf.unite(i,M[A[i]]);
  }
  if(uf.size(0) != N){
    cout << "Yes" << endl;
    return 0;
  }
  string ans = "No";
  for(int i = 0; i < N; ++i){
    if(A[i] > B[i]) continue;
    if(C[i] <= B[M[A[i]]]){
      ans = "Yes";
      break;
    }
  }
  cout << ans << endl;
}


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

using namespace std;

int main(void){
    string S;
    string T;
    int num=0;
    
    cin >> S >> T;
    
    for(int i=0;i<3;i++){
        if(S[i]==T[i]){
            num +=1;
        }
    }
    
    cout << num << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    ll l;
    cin >> l;
    l = l * l * l;
    cout << fixed << setprecision(20) << (double)(l) / 27.0 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;

int main() {
  string S;
  cin >> S;
  vector<int> A(26, 0);
  REP(i, 4) A[S[i] - 'A']++;
  REP(i, 26) {
    if (A[i] != 0 and A[i] != 2) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 1000000007 
int32_t main()
{
    fast;
  	int a,b;
  cin>>a>>b;
  if(a>=13)
    cout<<b;
  else if(a>5 )
    cout<<b/2;
  else
    cout<<0;
   
    
}

Measured memory_bytes: 256
a,b,c,d=map(int,input().split())
i=0
while a>0 and c>0:
  if i%2==0:
    c-=b
  else:
    a-=d
  #print(a,c)
  i+=1
  if a<=0:
    print('No')
    break
  if c<=0:
    print('Yes')
    break


Measured memory_bytes: 9172
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <iomanip>

using namespace std;

long long mod = 1000000007;

long long pow(long long x, long long k)
{
    if (k == 0)
    {
        return 1LL;
    }
    long long temp = pow(x, k / 2);
    if (k % 2 == 1)
    {
        return (((temp * temp) % mod) * x) % mod;
    }
    else
    {
        return (temp * temp) % mod;
    }
}

long long modular_inverse(long long x)
{
    return pow(x, mod - 2);
}

long long binomial(long long n, long long k)
{
    long long rez = 1;
    for (int i = n - k + 1; i <= n; i++)
    {
        rez *= i;
        rez %= mod;
    }
    long long temp = 1;
    for (int i = 1; i <= k; i++)
    {
        temp *= i;
        temp %= mod;
    }
    rez *= modular_inverse(temp);
    rez %= mod;
    return rez;
}

int score(int x)
{
    return max(100000 * (4 - x), 0);
}

int main()
{
    int x, y;
    cin >> x >> y;
    cout << score(x) + score(y) + ((x == y && x == 1) ? 400000 : 0);
    return 0;
}


Measured memory_bytes: 256
#[macro_export]
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)*}
    };
}

#[doc(hidden)]
#[macro_export]
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)*}
    };
}

#[doc(hidden)]
#[macro_export]
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, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

use std::collections::BTreeMap;

fn main() {
    input!{
        n: usize,
        m: usize,
        a: [usize; n],
    }

    let mut mm = BTreeMap::new();
    mm.insert(0, 1);

    let mut sum = 0;
    let mut ans: usize = 0;
    for &x in a.iter() {
        sum += x;
        ans += *mm.entry(sum % m).or_insert(0);
        *mm.entry(sum % m).or_insert(0) += 1;
    }

    println!("{}", ans);
}


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

long long int cumulative_sum[100000 + 200];
long long int x[100000 + 200];

long long int myabs(long long int x){
    if(x <= 0){
        return -x;
    }
    return x;
}

int main() {

    int n, k;

    cin >> n >> k;

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

    long long int ans = 20000000000000;

    for(int i=0; i<n-k+1; i++){
        if(x[i] * x[i+k-1] >= 0 && x[i] >= 0){
            ans = min(ans, x[i+k-1]);
        }
        else if(x[i] * x[i+k-1] >= 0 && x[i] <= 0){
            ans = min(ans, -x[i]);
        }
        else if(x[i] * x[i+k-1] <=0){
            // 右に行ってから左に行くか、左に行ってから右に行くか
            ans = min(ans, min(myabs(x[i]) + myabs(x[i+k-1]) * 2 , myabs(x[i]) * 2 + myabs(x[i+k-1])));
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
using ll = long long int;

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n + 1);
    vector<ll> b(n);
    ll total = 0;
    for(int i = 0; i < n + 1; i++)
    {
        cin >> a[i];
        total += a[i];
    }
    for(int i = 0; i < n; i++)
    {
        cin >> b[i];
    }
    for(int i = 0; i < n; i++)
    {
        if(a[i] <= b[i])
        {
            b[i] = b[i] - a[i];
            a[i] = 0;
        }else{
            a[i] = a[i] - b[i];
            b[i] = 0;
        }
        if(a[i + 1] <= b[i])
        {
            a[i + 1] = 0;
        }else{
            a[i + 1] = a[i + 1] - b[i];
        }
    }
    ll rest = 0;
    for(auto e : a)  rest += e;
    cout << total - rest << endl;
}

Measured memory_bytes: 1792
x=int(input())
n=[]
for i in range(3,x+1):
	if i%3==0:
		n.append(i)
	elif '3' in str(i):
		n.append(i)
c=0
for j in n:
	n[c]=str(j)
	c+=1
print(' '+' '.join(n))


Measured memory_bytes: 5936
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e9;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int ans = 0;
  rep(i, n - 1) if (a[i] != -1 && a[i] == a[i + 1]) {
    ans++;
    a[i + 1] = -1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e15;

int n, a[55];
string s[55];
bool vis[55][25][2];
ll dp[55][25][2];

ll fnc(int ke, int pos, bool dik) {
   if(pos == s[ke].size()) return 0;
   bool &done = vis[ke][pos][dik];
   ll &w = dp[ke][pos][dik];
   if(done) return w;
   done = 1, w = inf;

   bool pal = 1;
   if(!dik) {
      for(int j=pos, k=s[ke].size()-1; j<k; j++, k--) {
         if(s[ke][j] != s[ke][k]) pal = 0;
      }
   }
   else {
      for(int j=0, k=pos; j<k; j++, k--) {
         if(s[ke][j] != s[ke][k]) pal = 0;
      }
   }
   if(pal) return w = 0;

   for(int i=0; i<n; i++) {
      bool yes = 1;
      int j, k;
      if(!dik) {
         for(j=pos, k=s[i].size()-1; j<s[ke].size() && k>=0 && yes; j++, k--) {
            if(s[ke][j] != s[i][k]) yes = 0;
         }
         if(yes) {
            if(k < 0) w = min(w, a[i] + fnc(ke, j, 0));
            else w = min(w, a[i] + fnc(i, k, 1));
         }
      }
      else {
         for(j=pos, k=0; k<s[i].size() && j>=0 && yes; j--, k++) {
            if(s[ke][j] != s[i][k]) yes = 0;
         }
         if(yes) {
            if(j < 0) w = min(w, a[i] + fnc(i, k, 0));
            else w = min(w, a[i] + fnc(ke, j, 1));
         }
      }
   }
   return w;
}

int main() {
   cin >> n;
   for(int i=0; i<n; i++) cin >> s[i] >> a[i];
   ll ans = inf;
   for(int i=0; i<n; i++) ans = min(ans, a[i] + fnc(i, 0, 0));
   if(ans == inf) ans = -1;
   cout << ans << endl;
}


Measured memory_bytes: 3648
var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', function (line) {
  var a = line.split(' ');
  var b = parseInt(a[0],10);
  var c = parseInt(a[1],10); 
  var d  = b / c;
  var r = b % c;
  console.log(Math.floor(d)+' '+r+' '+d.toFixed(6));
  process.exit();
});
process.stdin.on('end', function () {
});

Measured memory_bytes: 16452
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int S, W;
    cin >> S >> W;
    if(W >= S){
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }
}

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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<long long> vl;

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int n, k;
    cin >> n >> k;
    int l[n];
    rep(i, n) { cin >> l[i]; }

    // 処理
    sort(l, l + n);
    int sum = 0;
    for (int i = n - 1; i > n - 1 - k; i--) {
        sum += l[i];
    }

    // 出力
    cout << sum << endl;

    return 0;
}


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



//main関数
int main() {
    //入力
    long N,K;
    cin>>N>>K;
    vector<long> V(N);
    for(int i=0;i<N;i++){
        cin>>V.at(i);
    }
    
    //計算
    long ans=-1000000000000,Ls=0;
    multiset<long> Lm;
    for(int L=0;L<=N;L++){
        if(L>0){
            Ls+=V.at(L-1);
            if(V.at(L-1)<0) Lm.insert(V.at(L-1));
        }
        
        long Rs=0;
        multiset<long> M=Lm;
        for(int R=0;L+R<=min(K,N);R++){
            if(R>0){
                Rs+=V.at(N-R);
                if(V.at(N-R)<0) M.insert(V.at(N-R));
            }
            
            long Pans=Ls+Rs;
            long count=0;
            for(auto ite=M.begin();(ite!=M.end() && count<K-L-R);ite++){
                Pans-=*ite;
                count++;
            }
            //cout<<"L"<<L<<"R"<<R<<"Pans"<<Pans<<endl;
            ans=max(Pans,ans);
        }
    }
    
    //出力
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<int,int>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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; }
int main(){
int a,b,c;
cin>>a>>b>>c;
int w=a;
a+=min(b,c);
cout<<((max(b,c)>=a)?abs(max(b,c)-a):0)<<endl;
}

Measured memory_bytes: 256
S = input()
N = len(S)

S1 = S[0:int((N-1)/2)]
S2 = S[int((N+1)/2):N]

cnt = 0
if S == S[::-1]:
  cnt += 1
if S1 == S1[::-1]:
  cnt += 1
if S2 == S2[::-1]:
  cnt += 1
  
if cnt == 3:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9040
# coding: utf-8


def solve(args: list) -> str:
    N = int(args[0])
    A = list(map(int, args[1].split()))
    a = [(i+1, A[i]) for i in range(N)]
    ret = map(lambda t: t[0], sorted(a, key=lambda t: t[1]))
    return str(' '.join(map(str, ret)))


if __name__ == "__main__":
    print(solve([input() for _ in range(2)]))


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

class MainClass
{
    static int[] dy = new int[4] { 0, 1, 0, -1 };
    static int[] dx = new int[4] { 1, 0, -1, 0 };
    static void Main()
    {
        var HW = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int H = HW[0], W = HW[1];
        bool[,] S = new bool[H, W];
        for (int i = 0; i < H; i++)
        {
            var r = Console.ReadLine();
            for (int j = 0; j < W; j++)
            {
                S[i, j] = r[j] == '.';
            }
        }

        int ans = 0;
        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                if (S[i, j]) ans = Math.Max(ans, BFS(i, j, H, W, S));
            }
        }

        Console.WriteLine(ans);
    }

    static int BFS(int sy,int sx,int H,int W,bool[,] map)
    {
        bool[,] frag = new bool[H, W];
        frag[sy, sx] = true;
        var que = new Queue<(int, int, int)>();
        que.Enqueue((sy, sx, 0));

        while (que.Count > 0)
        {
            var t = que.Dequeue();
            int y = t.Item1;
            int x = t.Item2;

            for (int i = 0; i < 4; i++)
            {
                int ny = y + dy[i];
                int nx = x + dx[i];
                if (!(0 <= ny && ny < H && 0 <= nx && nx < W)) continue;
                if (!map[ny, nx] || frag[ny, nx]) continue;

                frag[ny, nx] = true;
                que.Enqueue((ny, nx, t.Item3 + 1));
            }
            if (que.Count == 0) return t.Item3;
        }
        return -1;
    }
}

Measured memory_bytes: 28444
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a = sc.nextInt();
    int b = sc.nextInt();
    int ans = 0;
    int sum = 0;
    for(int cnt = 0; cnt <= n; cnt++){
      int tmp = cnt;
      while(tmp != 0){
        sum += tmp % 10;
        tmp /= 10; 
      }
      if ( a <= sum && sum <= b){
        ans+= cnt;
      }
      sum = 0;
      tmp = 0;
    }
    System.out.println(ans);
    sc.close();
  }
}

Measured memory_bytes: 35624
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
int stoi(string x){stringstream ss;ss<<x;int tmp;ss>>tmp;return tmp;}
string itos(int x){stringstream ss;ss<<x;return ss.str();}
int n;
int dfs(int h,int sum,int use){
	//cout<<h<<" "<<sum<<" "<<use<<endl;
	if(use>4)return 0;
	if(sum>n)return 0;
	if(sum==n)return 1;
	int ret=0;
	for(int i=h;i*i<=n;i++){
	if(sum+i*i>n||use==4)break;
	ret+=dfs(i,sum+i*i,use+1);
	}
	return ret;
}
int main(){
	while(cin>>n,n!=0){
	cout<<dfs(1,0,0)<<endl;
	}

	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
const long long INF = 1LL<<60;
#define pairint pair<int,int>
signed main(){
  int x=0,y=0,z=1,n=0,w=0;
  std::cin >> x>>y;
  while(x>0){
    x/=y;
    n++;
  }
  std::cout << n << '\n';
}


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

using namespace std;

typedef long long ll;

ll H, W, A, B;

int main() {
	cin >> H >> W >> A >> B;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (i < B && j < A)cout << 1;
			else if (i >= B && j < A)cout << 0;
			else if (i < B && j >= A)cout << 0;
			else cout << 1;
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1280
#!/usr/bin/env python3
#ABC135 C

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

n = I()
a = LI()
b = LI()
ans = 0
for i in range(n):
    if a[i] >= b[i]:
        ans += b[i]
    else:
        s = b[i] - a[i]
        ans += a[i]
        if a[i+1] - s >= 0:
            a[i+1] -= s
            ans += s
        else:
            ans += a[i+1]
            a[i+1] = 0
print(ans)


Measured memory_bytes: 73316
#include<stdio.h>
long long gcd(long long a,long long b)
{
    return b?gcd(b,a%b):a;
}
long long lcm(long long a,long long b)
{
	return a*b/gcd(a,b);
}
int main()
{
	long long a,b,c,d,e,x,y,z;
	scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
	x=b/c-a/c;
	if(a%c==0)x++;
	y=b/d-a/d;
	if(a%d==0)y++;
	e=lcm(c,d);
	z=b/e-a/e;
	if(a%e==0)z++;
	printf("%lld\n",(b-a+1)-(x+y-z));
}

Measured memory_bytes: 888
#include <cstdio>
#include <algorithm>
#include <set>

#define INF 1000000000

#define MAXN 200000

std::multiset <int> sx, sy;
std::multiset <int> ::iterator it;
int ind[MAXN+1];
int x[MAXN+1], y[MAXN+1];

bool cmp(const int &a, const int &b){
    return y[a]-x[a]>y[b]-x[b];
}

bool cmp2(const int &a, const int &b){
    return y[a]>y[b];
}

inline long long cost(){
    int a=0, b=0, c=INF, d=INF;
    a=*(sx.begin());
    b=*(sy.begin());
    it=sx.end();
    it--;
    c=*it;
    it=sy.end();
    it--;
    d=*it;
    return 1LL*(c-a)*(d-b);
}

int main(){
    int n;
    scanf("%d", &n);

    for(int i=0; i<n; i++){
        scanf("%d%d", &x[i], &y[i]);
        ind[i]=i;
        if(x[i]>y[i]) std::swap(x[i], y[i]);
        sx.insert(x[i]);
        sy.insert(y[i]);
    }

    std::sort(ind, ind+n, cmp);

    long long ans=cost();
    for(int i=0; i<n; i++){
        sx.erase(sx.lower_bound(x[ind[i]]));
        sy.erase(sy.lower_bound(y[ind[i]]));
        std::swap(x[ind[i]], y[ind[i]]);
        sx.insert(x[ind[i]]);
        sy.insert(y[ind[i]]);
        ans=std::min(ans, cost());
    }

    for(int i=n-1; i>=0; i--){
        sx.erase(sx.lower_bound(x[ind[i]]));
        sy.erase(sy.lower_bound(y[ind[i]]));
        std::swap(x[ind[i]], y[ind[i]]);
        sx.insert(x[ind[i]]);
        sy.insert(y[ind[i]]);
        ans=std::min(ans, cost());
    }

    for(int i=0; i<n; i++)
        ind[i]=i;

    std::sort(ind, ind+n, cmp2);

    for(int i=0; i<n; i++){
        sx.erase(sx.lower_bound(x[ind[i]]));
        sy.erase(sy.lower_bound(y[ind[i]]));
        std::swap(x[ind[i]], y[ind[i]]);
        sx.insert(x[ind[i]]);
        sy.insert(y[ind[i]]);
        ans=std::min(ans, cost());
    }

    for(int i=n-1; i>=0; i--){
        sx.erase(sx.lower_bound(x[ind[i]]));
        sy.erase(sy.lower_bound(y[ind[i]]));
        std::swap(x[ind[i]], y[ind[i]]);
        sx.insert(x[ind[i]]);
        sy.insert(y[ind[i]]);
        ans=std::min(ans, cost());
    }

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 23424
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    int n,m;cin >> n >> m;
    rep(i,m){
        int a;cin >> a;
        n -= a;
    }
    if(n<0) cout << -1 << endl;
    else cout << n << endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
 
typedef long long LL;
inline LL read(){
	register LL x=0,f=1;register char c=getchar();
	while(c<48||c>57){if(c=='-')f=-1;c=getchar();}
	while(c>=48&&c<=57)x=(x<<3)+(x<<1)+(c&15),c=getchar();
	return f*x;
}
inline char readc(){
	register char c=getchar();
	while(c==' '||c=='\n'||c=='\t')c=getchar();
	return c;
}
 
const int MAXN=45;
const int INF=1e9;
 
int ice[MAXN][MAXN],f[MAXN][MAXN][MAXN][MAXN];
int n,m,hx,hy,ans=INF;
 
inline int poi(int lx,int ly,int rx,int ry){
	if(lx>rx||ly>ry) return 0;
	return ice[rx][ry]-ice[rx][ly-1]-ice[lx-1][ry]+ice[lx-1][ly-1];
}
 
int main(){
	n=read(),m=read();
	memset(f,0x3f,sizeof f);
	f[1][1][n][m]=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			char c=readc();
			if(c=='P') hx=i,hy=j;
			ice[i][j]=ice[i-1][j]+ice[i][j-1]-ice[i-1][j-1]+(c=='#');
		}
	}
	for(int i=1;i<=hx;i++)
	for(int j=1;j<=hy;j++)
	for(int o=n;o>=hx;o--)
	for(int p=m;p>=hy;p--){
		ans=min(ans,f[i][j][o][p]+min(min(poi(i,j,hx,hy),poi(i,hy,hx,p)),min(poi(hx,j,o,hy),poi(hx,hy,o,p))));
		for(int s=i;s<=o;s++)
		for(int t=j;t<=p;t++){
			if(s>=hx&&t>=hy)
				f[i][j][s][t]=min(f[i][j][s][t],f[i][j][o][p]+poi(s+1,j,o,t)+poi(i,t+1,s,p));
			if(s>=hx&&t<=hy)
				f[i][t][s][p]=min(f[i][t][s][p],f[i][j][o][p]+poi(i,j,s,t-1)+poi(s+1,t,o,p));
			if(s<=hx&&t<=hy)
				f[s][t][o][p]=min(f[s][t][o][p],f[i][j][o][p]+poi(s,j,o,t-1)+poi(i,t,s-1,p));
			if(s<=hx&&t>=hy)
				f[s][j][o][t]=min(f[s][j][o][t],f[i][j][o][p]+poi(i,j,s-1,t)+poi(s,t+1,o,p));
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 16256
from collections import deque

N, M, P = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(M)]

to = [False] * (N + 1)
to[1] = True
q = deque([1])
while q:
    u = q.popleft()
    for a, b, c in X:
        if a == u and not to[b]:
            to[b] = True
            q.append(b)

ot = [False] * (N + 1)
ot[N] = True
q = deque([N])
while q:
    u = q.popleft()
    for a, b, c in X:
        if b == u and not ot[a]:
            ot[a] = True
            q.append(a)

INF = 10 ** 9 + 7
start = 1
d = [INF] * (N + 1)
d[start] = 0
updated = True
cnt = 0

while updated and cnt <= M:
    updated = False
    cnt += 1
    for u, v, c in X:
        if not to[u] or not ot[u] or not to[v] or not ot[v]:
            continue

        if d[v] > d[u] - (c - P):
            d[v] = d[u] - (c - P)
            updated = True

if cnt > N:
    print(-1)
else:
    print(max(0, -d[-1]))


Measured memory_bytes: 76004