akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
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;
}
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define LLINF (1e18)
#define PI (acos(-1))
#define MOD (1000000007)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> cake(3, vector<ll>(n));
    for (ll i = 0; i < n; i++)
    {
        cin >> cake[0][i] >> cake[1][i] >> cake[2][i];
    }

    ll ans = -LLINF;

    for (int bit = 0; bit < (1 << 3); bit++)
    {
        vector<ll> rec;
        for(int i=0;i<n;i++){
            ll tmp = 0;
            for(int j=0;j<3;j++){
                if(bit & (1 << j)){
                    tmp += cake[j][i];
                }else{
                    tmp -= cake[j][i];
                }
            }
            rec.push_back(tmp);
        }
        sort(RALL(rec));
        ll res = 0;
        for(int i=0;i<m;i++){
            res += rec[i];
        }
        chmax(ans, res);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
ll x[200005];
ll y[200005];
ll max1=-100000000000,max2=100000000000,max3=-100000000000,max4=1000000000000;
int main(){
    ll n;
    cin>>n;

    for(int i=1;i<=n;i++){
        cin>>x[i]>>y[i];
        max1=max(max1,x[i]+y[i]);
        max2=min(max2,x[i]+y[i]);
        max3=max(max3,x[i]-y[i]);
        max4=min(max4,x[i]-y[i]);
    }
    cout<<max(max1-max2,max3-max4);
}

Measured memory_bytes: 6764
total_dish = int(input())
dish_order = list(map(int, input().split()))
satis_B = list(map(int, input().split()))
satis_C = list(map(int, input().split()))

ans = 0
for i in range(total_dish):
  ans = ans + satis_B[dish_order[i]-1]
  if dish_order[i] - dish_order[i-1] == 1 and i != 0:
    ans = ans + satis_C[dish_order[i-1]-1]
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll,ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(),v.end())
#define ull unsigned long long
#define tell(a) cout<<a<<" "
#define el cout<<endl
#define rev(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ld long double
#define mem(a,b) memset(a,b,sizeof(a) )
#define M 4000010
#define md 1000000007

ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){   if (y & 1)res = (res*x) % p;y = y>>1;
x = (x*x) % p;}return res;}
//inline ll add(ll a,ll b){return (a+b)%md;}
//inline ll mul(ll a,ll b){return (a*b)%md;}
//ll f[M],iv[M];
//ll C(ll n,ll r){return mul(f[n],mul(iv[r],iv[n-r]));}
//void prep_fac(){
//    f[0]=1;
//    rep(i,1,M)f[i]=mul(i,f[i-1]);
//    iv[M-1]=power(f[M-1],md-2,md);
//    for(ll i=M-2;i>=0;--i)iv[i]=mul(i+1,iv[i+1]);
//}
//


int main()
{
	IOS;
	ll n;
	cin>>n;
	if(n%1000==0)
	cout<<0;
	else
	{
		ll p=(n/1000)+1;
		p*=1000;
		cout<<p-n;
	}
	
}



Measured memory_bytes: 3608
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll n,ans;
  cin >> n;
  ll a[3*n],bf_sum[n+1],af_sum[n+1];
  ll bft=0,aft=0,tmp;
  priority_queue<ll,vector<ll>,greater<ll>> bque;
  priority_queue<ll> aque;
  for(int i=0;i<3*n;i++){
    cin >> a[i];
    if(i<n){
      bft+=a[i];
      bque.push(a[i]);
    }else if(i>=2*n){
      aft+=a[i];
      aque.push(a[i]);
    }
  }
  bf_sum[0] = bft;
  af_sum[0] = aft;
  for(int i=0;i<n;i++){
    tmp = bque.top();
    bque.pop();
    if(a[n+i]>tmp){
      bft = bft - tmp + a[n+i];
      tmp = a[n+i];
    }
    bque.push(tmp);
    bf_sum[i+1] = bft;
  }
  for(int i=0;i<n;i++){
    tmp = aque.top();
    aque.pop();
    if(a[2*n-1-i]<tmp){
      aft = aft - tmp + a[2*n-1-i];
      tmp = a[2*n-1-i];
    }
    aque.push(tmp);
    af_sum[i+1] = aft;
  }
  ans = bf_sum[0]-af_sum[n];
  for(int i=0;i<=n;i++){
    ans = max(ans,bf_sum[i]-af_sum[n-i]);
  }
  cout << ans << endl;
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 998244353;

int main() {
  ll n, k, ans = 0, l, r;
  set<ll> st;
  cin >> n >> k;
  vector<pair<ll, ll>> v(k);
  ll dp[n + 1] = {};
  dp[0] = 1;
  dp[1] = -1;
  rep(i, k) {
    cin >> l >> r;
    r++;
    v[i].first = l, v[i].second = r;
  }
  for (int i = 0; i < n; ++i) {
    if (i > 0) (dp[i] += dp[i - 1]) %= mod;
    for (int j = 0; j < k; ++j) {
      l = v[j].first, r = v[j].second;
      if (i + l < n) (dp[i + l] += dp[i]) %= mod;
      if (i + r < n) (dp[i + r] -= dp[i] - mod) %= mod;
      // if (i + r < n && dp[i + r] < 0) dp[i + r]+= mod;
    }
  }

  // rep(i, n - 1)(dp[i + 1] += dp[i]) %= mod;

  cout << dp[n - 1] << endl;
  return 0;
}


Measured memory_bytes: 5172
#include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define endl "\n"
    #define ll long long int
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T=1;
        //cin>>T;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            ll n,k;
            cin>>n>>k;
            ll a[n];
            for(ll i=0;i<n;i++)
                cin>>a[i];
            ll dp[k+1]={false};
            for(ll stones=0;stones<=k;stones++)
            {
                for(ll i:a)
                {
                    if(stones-i>=0 && !dp[stones-i])
                    {
                        dp[stones]=true;
                    }
                }
            } 
            cout<<(dp[k]?"First":"Second");
        }
        return 0;
    }


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

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Mll = M<ll, ll>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin(),ie=(c).rend();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

string a, b, c;
V<bool> ab(100000, true), ac(100000, true), bc(100000, true);

bool match(char c1, char c2) {
    return (c1 == '?' || c2 == '?' || c1 == c2);
}

int main() {
    cin >> a >> b >> c;
    int la = a.size(), lb = b.size(), lc = c.size();
    int x = 50000;

    REP(i, la) REP(j, lb) if (!match(a[i], b[j])) ab[i-j+x] = false;
    REP(i, la) REP(j, lc) if (!match(a[i], c[j])) ac[i-j+x] = false;
    REP(i, lb) REP(j, lc) if (!match(b[i], c[j])) bc[i-j+x] = false;

    int mini = 1e9;
    REP2(i, -4000, 4001) REP2(j, -4000, 4001) {
        if (ab[i+x] && ac[j+x] && bc[j-i+x]) {
            int L = min({0, i, j});
            int R = max({la, i+lb, j+lc});
            mini = min(mini, R-L);
        }
    }
    cout << mini << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    map <string , int >mp;
    map <string , int >::iterator it;
    int n,i;
    string s;
    string arr[4] ={"AC","WA","TLE","RE"};
    cin >>n;
    mp.insert(make_pair("AC",0));
    mp.insert(make_pair("WA",0));
    mp.insert(make_pair("TLE",0));
    mp.insert(make_pair("RE",0));
    for (i=0;i<n;i++)
    {
        cin >>s;
        mp[s] ++;
    }
    for (i=0;i<4;i++)
    {
        cout << arr[i] <<" " << "x" << " "<< mp[arr[i]] <<endl;
    }

    return 0;
}


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

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

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;

int main(){
	int n, k; cin >> n >> k; int x[n];
	Rep(i, n){
		cin >> x[i];
	}
	int ans = inf;
	Rep(i, n-k+1){
		int d = x[i+k-1] - x[i];
		ans = min(ans, d + min(abs(x[i]), abs(x[i+k-1])));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<50;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int h,w,n;

int main(){
	cin>>h>>w>>n;
	vvi a(h,vi(w));
	int x=0,y=0;
	bool b=1;
	for(int i=0;i<n;i++){
		int A;
		cin>>A;
		for(int j=0;j<A;j++){
			a[x][y]=i+1;
			if(b){
				if(y==w-1){
					x++;
					b=0;
				}
				else y++;
			}
			else{
				if(!y){
					x++;
					b=1;
				}
				else y--;
			}
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(j) cout<<' ';
			cout<<a[i][j];
		}
		cout<<endl;
	}
}

Measured memory_bytes: 384
N = int(input())
s = [input() for i in range(N)]
M = int(input())
t = [input() for i in range(M)]

count = {s[i]: s.count(s[i]) - t.count(s[i]) for i in range(N) }

result = sorted(count.items(), key=lambda x: x[1], reverse=True)[0][1]
if result > 0:
    print(result)
else:
    print(0)

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

using namespace std;

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

    int min = a0;
    int an = a0;
    int a = a0;
    vector<int> stocks;
    stocks.push_back(a0);
    int index = 1;

    while (true)
    {
        index++;
        if (a % 2 == 0)
        {
            an = a / 2;
        }
        else
        {
            an = 3 * a + 1;
        }

        for (int i = 0; i < stocks.size(); i++)
        {
            if (an == stocks[i])
            {
                cout << index << endl;
                return 0;
            }
        }
        a = an;
        stocks.push_back(an);
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<P> vp;
typedef vector<T> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n;
  cin >> n;
  set<int> st;
  rep(i,n) {
    int a;
    cin >> a;
    st.insert(a);
  }
  cout << (st.size()==n ? "YES" : "NO") << endl;
  return 0;
}

Measured memory_bytes: 9600
a=[]
b=[]
while(True):
    x,y = map(int,input().split())
    if(x==0 and y==0):
        break
    a.append(x)
    b.append(y)
for qq in range(len(a)):
    for qqq in range(a[qq]):
        for qqqq in range(b[qq]):
            if(qqq == 0 or qqq == a[qq]-1 or qqqq ==0 or qqqq == b[qq]-1):
                print("#",end="")
            else:
                print(".",end="")
        print("")
    print("")


Measured memory_bytes: 7012
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,N) for(int i = 0; i < N;i++)
typedef pair<int,int> Pi;
#define F first
#define S second
#define INF 1 << 28

inline void chmax(int &a,int b) {
  a = max(a,b);
}

inline void chmin(int &a,int b) {
  a = min(a,b);
}

int main()
{
  int N, ans = 0;
  string s, w; 
  cin >> N >> s;
  while(N--) {
    bool flag = false;
    cin >> w;
    for(int i = 1; i <= w.size(); i++) {
      Rep(j,w.size()) {
	string t;
	int cnt = 0;
	for(int k = j; k < w.size() && cnt < s.size(); k += i,cnt++) {
	  t += w[k];
	}
	if(t == s) {
	  ans++,flag = true;
	  break;
	}
      }
      if(flag)break;
    }
  }
  cout << ans << endl;
  return 0;
}
	

Measured memory_bytes: 3180
def main():
    N,K=map(int,input().split())
    h=list(map(int,input().split()))

    ans=[0]*N
    ans[1]=abs(h[1]-h[0])


    for i in range(2,N):
        ans[i] = min(abs(h[i] - h[j]) + ans[j] for j in range(max(0,i-K),i))
    print(ans[N-1])
    
main()

Measured memory_bytes: 13980
#include <algorithm>
#include <functional>
#include <iostream>
#include <numeric>
#include <queue>
#include <vector>

using namespace std;

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

    vector<vector<int>> g(n, vector<int>(0));
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        g[a - 1].push_back(b - 1);
        g[b - 1].push_back(a - 1);
    }

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

    sort(c.begin(), c.end(), greater<long long>());

    vector<long long> r(n, -1);
    r[0] = c[0];

    queue<int> que;
    que.push(0);
    for (int i = 1; !que.empty(); ) {
        int q = que.front();
        que.pop();

        for (int j = 0; j < static_cast<int>(g[q].size()); j++) {
            if (r[g[q][j]] == -1) {
                r[g[q][j]] = c[i];
                que.push(g[q][j]);
                i++;
            }
        }
    }

    cout << accumulate(c.begin() + 1, c.end(), 0LL) << endl;
    for (int i = 0; i < n; i++) {
        cout << (i == 0 ? "" : " ") << r[i];
    }
    cout << endl;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
int main() {
    int N;
    int a[100001];
    cin >> N;
    long long ans = 0;
    int mini = INT_MAX, cnt = 0;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        if (a[i] < 0) {
            cnt++;
        }
        ans += abs(a[i]);
        mini = min(abs(a[i]),mini);
    }
    if(cnt % 2 == 1){
        ans -= 2*mini;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
//Mahir Ratanpara (DA-IICT)
#include<bits/stdc++.h>
using namespace std;
#define Ff(i,a,n) for(i=a;i<n;i++)
#define Fr(i,a,n) for(i=a;i>n;i--)
#define ll long long
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
typedef pair<ll, ll>	pa;
typedef vector<ll>		vc;
typedef vector<pa>		vp;
typedef vector<vc>		vvc;
int mpow(int base, int exp); 
void ipgraph(ll n,ll m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vc g[N];

int main() {
    FAST;
    ll t, i, j, k, p, q,l,r, x, y, u, v, n, m;
    n=3;
    ll a[n][n];

    // map<ll,pair<ll,ll> > mp;
    Ff(i,0,n)
    {
      Ff(j,0,n)
      {
        cin>>a[i][j];
      }
    }

    cin>>m;
    vc fa(101,0);
    Ff(i,0,m)
    {
      cin>>x;
      fa[x]++;
    }

    string s="No";
    Ff(i,0,n)
    {
      ll cnt=0;
      Ff(j,0,n)
      {
        if(fa[a[i][j]])
        cnt++;
      }
      if(cnt==3)
      s="Yes";
    }

    Ff(j,0,n)
    {
      ll cnt=0;
      Ff(i,0,n)
      {
        if(fa[a[i][j]])
        cnt++;
      }
      if(cnt==3)
      s="Yes";
    }

    ll cnt=0;
    Ff(i,0,n)
    {
      if(fa[a[i][i]])
      cnt++;
    }

    if(cnt==3)
    s="Yes";

    cnt=0;

    Ff(i,0,n)
    {
      if(fa[a[i][n-i-1]])
      cnt++;
    }
    if(cnt==3)
    s="Yes";

    cout<<s;
    return 0;
}

int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void ipgraph(ll n, ll m){
	int i, u, v;
	while(m--){
		cin>>u>>v;
		g[u-1].pb(v-1);
		g[v-1].pb(u-1);
	}
}

void dfs(int u, int par){
	for(int v:g[u]){
		if (v == par) continue;
		dfs(v, u);
	}
}

Measured memory_bytes: 10616
package main

import (
    "fmt"
    "math"
)

func main() {
    var n int
    fmt.Scan(&n)
    v := make([]int, n)
    c := make([]int, n)
    for i := 0; i < n; i++ {
      fmt.Scan(&v[i])
    }
    for i := 0; i < n; i++ {
      fmt.Scan(&c[i])
    }

    var X, Y int
    var max int = 0
    for i := 0 ; i < int(math.Pow(2.0, float64(n))); i++ {
        X, Y = 0, 0
        for j := uint(0); j < uint(n); j++ {
            if (i & (1 << j)) != 0 {
                X += v[j]
                Y += c[j]
            }
        }
        if max < X - Y {
            max = X - Y
        }
    }
    fmt.Println(max)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 16
 
int H,W,gp[MAX*MAX];
char field[MAX][MAX];
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
 
struct State{
    int h,r[3];
};
 
inline bool check(const State &s){
    for(int i = 0 ; i < 3 ; i++){
	if(field[s.r[i]/W][s.r[i]%W] != '_'){
	    return false;
	}
    }
    return true;
}
 
inline int canMove(const State &s,int &dir){
    if(field[s.h/W][s.h%W] == '#') return -1;
    int idx = -1;
    for(int i = 0 ; i < 3 ; i++){
	if(s.h == s.r[i]){
	    idx = i; break;
	}
    }
    if(idx == -1) return 3;
    int nx = s.h%W + dx[dir];
    int ny = s.h/W + dy[dir];
    if(field[ny][nx] == '#') return -1;
    for(int i = 0 ; i < 3 ; i++){
	if(i == idx) continue;
	if(s.r[i]%W == nx && s.r[i]/W == ny){
	    return -1;
	}
    }
    return idx;
}
 
bool visited[50][50][50][50];
 
int bfs(const State &S){
    queue<State> Q; Q.push(S);
    queue<int> step; step.push(0);
    const int dr[4] = {-1,-W,1,W};
    memset(visited,false,sizeof(visited));
    visited[gp[S.h]][gp[S.r[0]]][gp[S.r[1]]][gp[S.r[2]]] = true;
 
    while(!Q.empty()){
	State s = Q.front(); Q.pop();
	int st = step.front(); step.pop();
	if(check(s)) return st;
	for(int i = 0 ; i < 4 ; i++){
	    s.h += dr[i];
	    int r = canMove(s,i);
	    if(r == -1){
		s.h -= dr[i];
		continue;
	    }
	    if(r == 3){
		if(!visited[gp[s.h]][gp[s.r[0]]][gp[s.r[1]]][gp[s.r[2]]]){
		    visited[gp[s.h]][gp[s.r[0]]][gp[s.r[1]]][gp[s.r[2]]] = true;
		    Q.push(s);
		    step.push(st+1);
		}
	    }else{
		s.r[r] += dr[i];
		if(!visited[gp[s.h]][gp[s.r[0]]][gp[s.r[1]]][gp[s.r[2]]]){
		    visited[gp[s.h]][gp[s.r[0]]][gp[s.r[1]]][gp[s.r[2]]] = true;
		    Q.push(s);
		    step.push(st+1);
		}
		s.r[r] -= dr[i];
	    }
	    s.h -= dr[i];
	}
    }
    return -1;
}
 
int main(){
    while(cin >> W >> H,(W|H)){
	int r = 0,idx = 0;
	State start;
	for(int i = 0 ; i < H ; i++){
	    for(int j = 0 ; j < W ; j++){
		cin >> field[i][j];
		if(field[i][j] == '@'){
		    start.h = i*W+j;
		}else if(field[i][j] == '*'){
		    start.r[r++] = i*W+j;
		}
		if(field[i][j] != '#'){
		    gp[i*W+j] = idx++;
		}
	    }
	}
	cout << bfs(start) << endl;
    }
    return 0;
}

Measured memory_bytes: 10968
#![allow(unused_mut)]
#![allow(non_snake_case)]

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

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

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

fn main() {
    input! {
        N: usize,
        A1: [usize; N],
        A2: [usize; N],
    }
    let mut u = vec![0;N];
    let mut d = vec![0;N];
    let mut sum = 0;
    for i in 0..N {
        sum+= A1[i];
        u[i]=sum;
    }
    sum = 0;
    for i in (0..N).rev() {
        sum+= A2[i];
        d[i]=sum;
    }
    let mut max = 0;
    for i in 0..N {
        let l = u[i] + d[i];
        max = std::cmp::max(max, l);
    }
    println!("{}", max);
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl

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

    int N; cin >>N;
    vector<string> W(N); cin >> W;
    
    set<string> used;
    used.insert(W[0]);
    for (int i = 1; i < N; i++) {
        if (used.count(W[i]) || W[i-1].back()!=W[i].front()) {
            Yes(false);
            return 0;
        }
        used.insert(W[i]);
    }
    Yes(true);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
typedef long long ll;
using namespace std;

int main(){
    int a,b,c,x,y;
    ll ans=100000000000;
    cin>>a>>b>>c>>x>>y;
    for(int i=0;i<200001;i+=2){
        ll v=c*i;
        v+=max(0,x-(i/2))*a;
        v+=max(0,y-(i/2))*b;
        ans=min(ans,v);
    }
    cout<<ans<<endl;
}

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

int main()
{
	int a, b;
	cin >> a >> b;
	vector<string> c(a);
	for (int i = 0; i < a; i++) {
		cin >> c.at(i);
	}
	sort(c.begin(), c.end());
	for (int i = 0; i < a; i++) {
		cout << c.at(i);
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 15;

int a[N][N];
int c[N];

int main(){
    // 读入
    int n, m, x;
    cin >> n >> m >> x;
    for(int i = 1; i <= n; i ++){
        cin >> c[i];
        for(int j = 1; j <= m; j ++)
            cin >> a[i][j];
    }
    int ans = 1e9;

    // 暴力枚举
    for(int i = 0; i < 1 << n; i ++){ 
        int b[N]; // 记录当前选择下 a 数组每列上的和
        memset(b, 0, sizeof b);
        int tmp = 0; // 当前选择下花费的代价
        for(int j = 1; j <= n; j ++){
            if((i >> (j - 1)) & 1){ // 对应位为 1 代表选了
                tmp += c[j];
                for(int k = 1; k <= m; k ++)
                    b[k] += a[j][k];                
            }
        }

        int mark = 1;
        for(int j = 1; j <= m; j ++) // 判断是否满足条件
            if(b[j] < x){
                mark = 0;
                break;
            }
        if(mark) ans = min(ans, tmp);
    }
    if(ans == 1e9) puts("-1");
    else cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3572
n = int(input())
a = list(map(int, input().split()))

sita_maxi = [0 for i in range(n+1)]
sita_maxi[n] = a[n]
for i in range(n-1, -1, -1):
    sita_maxi[i] = sita_maxi[i+1] + a[i]

if a[0] > 1:
    print(-1)
    exit()

lst = [1]
for i in range(1, n+1):
    lst.append(min((lst[i-1]-a[i-1])*2, sita_maxi[i]))
    if lst[-1] < a[i]:
        print(-1)
        exit()

print(sum(lst))


Measured memory_bytes: 22292
/*********বিসমিল্লাহির রাহমানির রাহিম**********/

#include <bits/stdc++.h>
#define ll long long
#define PI 2 * acos(0)
#define FAST ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define MAX 200000
#define MOD 1e7
#define all(x) (x).begin(), (x).end()
using namespace std;
/*................OMI.................*/

vector<ll> prime;
bool isPrime(ll n)
{
   if (n <= 1)
      return false;
   if (n <= 3)
      return true;

   if (n % 2 == 0 || n % 3 == 0)
      return false;

   for (ll i = 5; i * i <= n; i = i + 2)
      if (n % i == 0)
         return false;

   return true;
}
ll gcd(ll a, ll b)
{
   if (a == 0)
      return b;
   return gcd(b % a, a);
}

ll lcm(ll a, ll b)
{
   ll g = gcd(a, b);
   ll ans = (a * b) / g;
   return ans;
}
void primes(ll m)
{
   bool isprime[m];

   for (int i = 0; i <= m; i++)
      isprime[i] = true;

   for (int i = 3; i * i <= m; i++)
   {
      if (isprime[i])
      {

         for (int j = i * i; j <= m; j += i)
            isprime[j] = false;
      }
   }
   prime.push_back(2);
   for (int i = 3; i <= m; i += 2)
      if (isprime[i])
         prime.push_back(i);
}

/************MAIN_FUNCTION***********/

int main(int argc, char *argv[])
{

   FAST;
   int n, m;
   cin >> n >> m;
   int sum = 0,num;
   for (int i = 0; i < m; i++)
   {
      cin >> num;
      sum += num;
   }
   if (n - sum >= 0)
      cout << n - sum << endl;
   else
      cout << "-1" << endl;

   return 0;
}

Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;

int32_t main(){
	IOS;
	int a[3][3];
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cin>>a[i][j];
		}
	}
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		for(int i=0;i<3;i++) for(int j=0;j<3;j++) if(a[i][j]==x) a[i][j]=0;
	}
	/*for(int i=0;i<3;i++){
		for(int j=0;j<3;j++) cout<<a[i][j]<<" ";
			cout<<endl;
	}*/
	int ans=0;
	for(int i=0;i<3;i++){
		ans+=((a[i][0]==0)+(a[i][1]==0)+(a[i][2]==0))/3;
	}
	for(int i=0;i<3;i++){
		ans+=((a[0][i]==0)+(a[1][i]==0)+(a[2][i]==0))/3;
	}
	ans+=((a[0][0]==0)+(a[1][1]==0)+(a[2][2]==0))/3;
	ans+=((a[0][2]==0)+(a[1][1]==0)+(a[2][0]==0))/3;
	if(ans>=1) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

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


// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
    long long val;
    constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
        if (val < 0) v += MOD;
    }
    constexpr int getmod() { return MOD; }
    constexpr Fp operator - () const noexcept {
        return val ? MOD - val : 0;
    }
    constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
    constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
    constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
    constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
    constexpr Fp& operator += (const Fp& r) noexcept {
        val += r.val;
        if (val >= MOD) val -= MOD;
        return *this;
    }
    constexpr Fp& operator -= (const Fp& r) noexcept {
        val -= r.val;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr Fp& operator *= (const Fp& r) noexcept {
        val = val * r.val % MOD;
        return *this;
    }
    constexpr Fp& operator /= (const Fp& r) noexcept {
        long long a = r.val, b = MOD, u = 1, v = 0;
        while (b) {
            long long t = a / b;
            a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        val = val * u % MOD;
        if (val < 0) val += MOD;
        return *this;
    }
    constexpr bool operator == (const Fp& r) const noexcept {
        return this->val == r.val;
    }
    constexpr bool operator != (const Fp& r) const noexcept {
        return this->val != r.val;
    }
    friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
        return os << x.val;
    }
    friend constexpr istream& operator >> (istream &is, Fp<MOD>& x) noexcept {
        return is >> x.val;
    }
    friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
        if (n == 0) return 1;
        auto t = modpow(a, n / 2);
        t = t * t;
        if (n & 1) t = t * a;
        return t;
    }
};

const int MOD = 1000000007;
using mint = Fp<MOD>;


int N, M;
vector<int> S, T;
mint dp[2100][2100];
mint sdp[2100][2100];

int main() {
    cin >> N >> M;
    S.resize(N), T.resize(M);
    for (int i = 0; i < N; ++i) cin >> S[i];
    for (int i = 0; i < M; ++i) cin >> T[i];

    memset(dp, 0, sizeof(dp));
    memset(sdp, 0, sizeof(dp));
    dp[0][0] = 1;
    sdp[1][1] = 1;
    for (int i = 0; i <= N; ++i) {
        for (int j = 0; j <= M; ++j) {
            if (i == 0 && j == 0) continue;
            if (i-1 >= 0 && j-1 >= 0 && S[i-1] == T[j-1]) {
                dp[i][j] = sdp[i][j];
            }
            sdp[i+1][j+1] = sdp[i+1][j] + sdp[i][j+1] - sdp[i][j] + dp[i][j];
        }
    }
    cout << sdp[N+1][M+1] << endl;
}

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

using namespace std;

void solve() {
	int a, b;
	cin >> a >> b;
	if (a > b) swap(a, b);
	int l = 1, r = 1e9;
	while (l < r) {
		int mid = (l + r + 1) >> 1;
		if (1LL * mid * mid < 1LL * a * b) l = mid;
		else r = mid - 1;
	}
	cout << l + (1LL * a * b - 1) / (l + 1) - (a <= l) << '\n';
}

int main() {
	ios::sync_with_stdio(false);
	int t; cin >> t; while (t--) solve();
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	string s,t;
	cin>>s>>t;
	int n = s.size(), m=t.size();
	int dp[n+1][m+1];
	//initialize
	for(int i=0;i<n+1;i++) dp[i][0] = 0; 
	for(int i=0;i<m+1;i++) dp[0][i] = 0; 
	for(int i=1;i<n+1;i++){
		for(int j=1;j<m+1;j++){
			if(s[i-1] == t[j-1]){
				dp[i][j] = 1+dp[i-1][j-1];
			}
			else{
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			}
		}
	}
	string ans="";
	int i=n, j=m;
	while(i>0 && j>0){
		if(s[i-1]==t[j-1]){
			ans+=s[i-1];
			i--; j--;
		}
		else{
			if(dp[i-1][j]>dp[i][j-1]) i--;
			else j--;
		}
	}
	reverse(ans.begin(), ans.end());
	cout<<ans;
	return 0;
}

Measured memory_bytes: 35456
#include<bits/stdc++.h>
#define io ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define PI atan(1)*4
typedef long long int ll;
using namespace std;
int main(){
	io;
	int s,w;
	cin >> s >> w;
	if(w >= s){
		cout << "unsafe";
	} 
	else
		cout << "safe";
	return 0;
} 

Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1 << 30;
// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;

int pow(int a, int n){
    int res = 1;
    while(n > 0){
        if(n & 1){res *= a;}
        a *= a;
        n >>= 1;
    }
    return res;
}

int bs(int a, int n){
    int lb = 0, ub = 1001;
    while(ub-lb > 1){
        int mid = (lb+ub) / 2;
        if(pow(mid, n) <= a){
            lb = mid;
        }else{
            ub = mid;
        }
    }

    return lb;
}


int main(){
    int e;
    while(std::cin >> e, e){
        int res = INF;
        REP(z, 101){
            if(e-z*z*z >= 0){
                int y = bs(e-z*z*z, 2),
                    x = e - z*z*z - y*y;
                res = std::min(res, x+y+z);
            }
        }

        std::cout << res << std::endl;
    }
}

Measured memory_bytes: 1160
n = int(input())
a = list(map(int,input().split()))

from fractions import gcd
l,r = [0]*(n+1),[0]*(n+1)
for i in range(n):
    l[i+1] = gcd(l[i],a[i])
    r[n-i-1] = gcd(r[n-i],a[n-i-1])

ans = 1
for i in range(n):
    g = gcd(l[i],r[i+1])
    ans = max(ans,g)
print(ans)

Measured memory_bytes: 14080
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
typedef pair<int,int> P;
using vi=vector<long long>;
using vvi=vector<vector<long long>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const int inf=1000000009;
void chmin(auto &a,auto b){if(b<a)a=b;}
void chmax(auto &a,auto b){if(a<b)a=b;}

int main(){
  int n,ans=0;cin>>n;
  string s;cin>>s;
  rep(i,n){
    for(int j=i+1;j<n;j++){
      if(i!=0){
      if(s[j]==s[i]&&s[j-1]!=s[i-1]){
        int c=1;
        rep(k,j-i-1){
          if(s[j+k+1]==s[1+i+k])c++;
          else break;
        }
        chmax(ans,c);
      }
      }
      else{
        if(s[j]==s[i]){
          int c=1;
          rep(k,j-i-1){
            if(s[j+k+1]==s[1+i+k])c++;
            else break;
          }
          chmax(ans,c);
        }
      }
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <random>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define rep(x, b, e) for(int x=(b); x<(e); ++x)
#define ford(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define all(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

bool isPrime(int x) {
	for (int i=2;i*i <= x; ++i) {
		if (x % i == 0) return false;
	}

	return true;
}

int main() {
	ios_base::sync_with_stdio(false);
	int x;
	cin >> x;
	while (!isPrime(x)) {
		++x;
	}
	cout << x << endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;




ll dp[11111];

int main(void) {
  ll i, j, k;
  ll H, N;
  ll a[1111], b[1111];
  cin >> H >> N;
  
  for(i=0; i<N; i++) {
    cin >> a[i] >> b[i];
  }
  
  
  for(j=0; j<=H; j++)
    dp[j]=INF;
  
  dp[0]=0;
  for(i=0; i<N; i++) {
    for(j=0; j<=H; j++) {
      chmin(dp[min(H, j+a[i])], dp[j]+b[i]);
    }
  }
  
  pt(dp[H]);
  
}





Measured memory_bytes: 384
#include<iostream>
#include<cmath>
using namespace std;
typedef long long ll;

int main(){
    ll s;
    cin >> s;
    ll a = sqrt(s);
    if(a*a < s) a++;
    ll d = a;
    if(d*d-s > 1e9) d--;
    ll b = a*d-s;
  
    cout << "0 0 " << a << " " << 1 << " " << b << " " << d << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define isIn(x,y,h,w) (x >= 0 && x < h && y >= 0 && y < w)

#define int long long
//using ll = long long;
using P = pair<int,int>;

ostream &operator<<(ostream &os,const P &p){ return os << "(" << p.first << "," << p.second << ")"; }

template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

int n,m,v,p,a[100010];

bool isOK(int x){
	if(x < p) return true;
	if(a[x] + m < a[p - 1]) return false;
	int cnt = 0;
	for(int i = 0;i < n;i++){
		if(i < p - 1 || i >= x) cnt += m;
		else cnt += a[x] + m - a[i];
	}
	return cnt >= m * v;
}

signed main(){
	cin >> n >> m >> v >> p;
	for(int i = 0;i < n;i++) cin >> a[i];
	sort(a,a + n,greater<int>());
	int ok = 0,ng = n;
	while(ng - ok > 1){
		int mid = (ok + ng) / 2;
		if(isOK(mid)) ok = mid;
		else ng = mid;
	}
	cout << ng << endl;
}

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

ll solve(vector<ll> &v,int n){
    ll sum = 0;
    rep(i,n-1){
        ll com = ((ll)(i+1)*(n-i-1))%mod;
        sum += ((v[i+1]-v[i])*com)%mod;
    }
    return sum%mod;
}

int main(void){
    int n,m;
    cin>>n>>m;
    vector<ll> x(n),y(m);
    rep(i,n) cin>>x[i];
    rep(i,m) cin>>y[i];
    cout<<(solve(x,n)*solve(y,m))%mod<<endl;
    return 0;
}

Measured memory_bytes: 1792
n = int(input())
l = list(map(int,input().split()))
ans = [0,0,0]
for i in l:
  if i % 4 == 0:
    ans[0] += 1
  elif i % 2 == 0:
    ans[1] += 1
  else:
    ans[2] += 1
    
if ans[0] >= ans[2]:
  print("Yes")
elif ans[1] == 0 and ans[0]+1 == ans[2]:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 15020
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;

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

	vector<int32_t> H(N);
	for (int32_t i = 0; i < N; i++) {
		cin >> H[i];
	}

	vector<int32_t> d(N);
	d[N - 1] = 0;
	for (int32_t i = N - 2; i >= 0; i--) {
		d[i] = (H[i] < H[i + 1]) ? 0 : (d[i + 1] + 1);
	}

	int32_t res = 0;
	for (int32_t i = 0; i < N; i++)
		res = max(res, d[i]);

	cout << res << endl;

	return 0;
}


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

#define all(s) s.begin(), s.end()
#define pb push_back
#define ii pair<int, int>
#define x first
#define y second
#define bit(x, y) ((x >> y) & 1)

const int MOD = 1000000007;

int dp[3005][3005];

int main() {
    ios::sync_with_stdio(false); cin.tie(0); 
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    s = " " + s;
    string t = s;
    for (int i = 1; i <= m; i++) {
        int u, v;
        cin >> u >> v;
        sort(s.begin() + u, s.begin() + v + 1);
        sort(t.begin() + u, t.begin() + v + 1, [](char x, char y) {
            return x > y;
        });
    }
    vector<int> cntmx(n + 1);
    vector<int> cntmn(n + 1);
    for (int i = 1; i <= n; i++) {
        cntmx[i] = cntmx[i - 1] + (s[i] == '0');
        cntmn[i] = cntmn[i - 1] + (t[i] == '0');
    }

    dp[0][0] = 1;
    for (int i = 1; i <= n; i++) {
        if (cntmn[i] == 0) dp[i][0] = dp[i - 1][0];
        for (int j = max(cntmn[i], 1); j <= cntmx[i]; j++) {
            dp[i][j] = (dp[i - 1][j - 1] + dp[i - 1][j]) % MOD;
        }
    }

    int ans = 0;
    for (int i = 0; i <= 3000; i++) {
        ans = (ans + dp[n][i]) % MOD;
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 15868
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
	#define errp(...)
	#define dbg(...)
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (const string& e_) { return "\"" + e_ + "\""; }
string to_string (char e_) { return "\'" + string(1, e_) + "\'"; }
string to_string (bool e_) { return e_ ? "true" : "false"; }
template <typename T> string to_string (T e_) {
	string s_ = "[ ";
	for (const auto& x_ : e_) s_ += to_string(x_) + " ";
	return s_ + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e_) {
	return "(" + to_string(e_.first) + ", " + to_string(e_.second) + ")";
}
void dbg_str () { errp(" \n"); }
template <typename U, typename... V> void dbg_str (U u, V... v) {
	errp(" %s", to_string(u).c_str()); dbg_str(v...);
}
/* --- */
const int N = 100010;
ll a[N];
int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	/* --- */
	int n, prev, curr, max = 0, len = 0;
	cin >> n;
	cin >> prev;

	for(int i = 1; i < n;  i++){
		cin >> curr;
		if(curr <= prev) len++;
		else len = 0;

		if(max < len) max = len;
		prev = curr;
	}
	cout << max;
}

Measured memory_bytes: 256
import numpy as np
n, k = map(int, input().split())
a = np.array(list(map(int, input().split())))

a.sort()

plus = a[a > 0]
minus = a[a < 0]
zero = a[a == 0]

#infだと割ってもinf
left = -10 ** 18
right = 10 ** 18

while left + 1 < right:
    x = (left + right) // 2
    cnt = 0
    if x >= 0:
        cnt += n * len(zero)
    cnt += a.searchsorted(x // plus, side="right").sum()
    cnt += (n - a.searchsorted(-(-x // minus), side="left")).sum()
    cnt -= np.count_nonzero(a * a <= x)
    cnt //= 2

    if cnt >= k:
        right = x
    else:
        left = x

print(right)


Measured memory_bytes: 32300
// Problem : A - Parking
// Contest : AtCoder - AtCoder Beginner Contest 080
// URL : https://atcoder.jp/contests/abc080/tasks/abc080_a
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define eb emplace_back
#define pb push_back
#define size(s) (int)s.size()
#define int long long
#define vi vector<int>
#define vs vector<string>
#define vv vector<vector<int>>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define inc(v,n,x) v.assign(n,x)
#define incd(v,n) v.resize(n)
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inimi(n) memset(n,0xc0,sizeof(n))
#define inima(n) memset(n,0x3f,sizeof(n))
#define all(v) (v).begin(),(v).end()

using namespace std;

template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }

const int N=200001;
double pi=acos(-1.0);
int md=1e9+7;
const int INF=1e15;
int dx1[]={0,0,-1,1};
int dy1[]={1,-1,0,0};

template<class T>
T abst(T a)
{return a<0?-a:a;}

template<class T>
T max2(T a,T b){return a>b?a:b;}
template<class T>
T min2(T a,T b){return a<b?a:b;}

void solve()
{
	int n,a,b;cin>>n>>a>>b;
	if(n*a<=b)
	cout<<n*a;
	else
	cout<<b;
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
for(int i=1;i<=t;i++)
{
    solve();
}
return 0;
}


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

static const int SIZE = 1000;

int max(int a, int b){
    return (a > b ? a : b);
}

void lcs(char *x, char *y){
    int dp[SIZE+1][SIZE+1];
    int xl,yl,res=0;
    
    xl = strlen(x);
    yl = strlen(y);

    for(int i=0; i<=xl; i++) dp[i][0] = 0;
    for(int i=0; i<=yl; i++) dp[0][i] = 0;


    for(int i=1; i<=xl; i++){
        for(int j=1; j<=yl; j++){
            if(x[i-1] == y[j-1]){
                dp[i][j] = dp[i-1][j-1]+1;
            }
            else dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
        }
    }

    cout<<dp[xl][yl]<<endl;
}

int main(){
    char x[SIZE],y[SIZE];
    int n;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>x>>y;
        lcs(x,y);
    }

    return 0;
}


Measured memory_bytes: 7008