akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define sz(x) int(x.size())
#define pb push_back
#define eb emplace_back
using ll=long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
const ll MOD=1000000007,MOD2=998244353,INF=1e18;



int main() {
    int N;
    cin>>N;
    vector<ll> A(N);
    ll now=0;
    rep(i,N){
        cin>>A.at(i);
        now=now^A.at(i);
    }
    if(now==0){cout<<0<<endl;return 0;}
    now=now^A.at(0);
    now=now^A.at(1);
    ll p=A.at(0)+A.at(1)-now;
    if(p%2){cout<<-1<<endl;return 0;}
    p/=2;
    if(p>=A.at(0) || p&now){cout<<-1<<endl;return 0;}
    for(int i=42;i>=0;i--){
        if(1ll<<i & now){
            if((p | 1ll<<i) <A.at(0)){
                p|= 1ll<<i;
            }
        }
    }
    if(p==0){cout<<-1<<endl;return 0;}
    cout<<A.at(0)-p<<endl;
}

Measured memory_bytes: 3596
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define int long long


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

    int q; cin >> q;
    vector<int> l(q),r(q);
    for(int i = 0;i < q;i ++){
        cin >> l.at(i) >> r.at(i);
    }  
    for(int i = 0;i < q;i ++){
        if(l.at(i) < 3) l.at(i) = 3;
    }

    vector<int> sosu(100001),sosunomi(1);
    sosunomi.at(0) = 2;
    for(int i = 3;i < 100001;i += 2){
        for(int j = 0;j < sosunomi.size();j ++){
            if(i % sosunomi.at(j) == 0){
                break;
            }
            if(j == sosunomi.size() - 1){
                sosu.at(i) = 1;
                sosunomi.push_back(i);
            }
        }
    }  

    sosu.at(2) = 1;

    vector<int> a(100001);
    for(int i = 0;i < 100001;i ++){
        if(sosu.at(i) && sosu.at((i+1) / 2)){
            a.at(i) = 1;
        }
    }
    a.at(2) = 1;

    vector<int> sum(100001);
    for(int i = 1;i < 100001;i ++){
        sum.at(i) = sum.at(i-1) + a.at(i);
    }

    for(int i = 0;i < q;i ++){
        cout << sum.at(r.at(i)) - sum.at(l.at(i) - 1) << endl;
    }
}

Measured memory_bytes: 4736
#include"bits/stdc++.h"
using namespace std;

int main() {
	vector<int> x(3);
	int K;
	cin >> x[0] >> x[1] >> x[2] >> K;
	sort(x.begin(), x.end());
	for (int i = 0;i < K;++i) {
		x[2] *= 2;
	}
	cout << x[0] + x[1] + x[2] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define x first
#define y second
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //assert(freopen("input.txt","r",stdin));
    //assert(freopen("output.txt","w",stdout));
    int x;
    cin>>x;
    int n;
    cin>>n;
    set<int>s;
    int a[200];
    int i;
    for(i=1;i<=n;i++){
        cin>>a[i];
        s.insert(a[i]);
    }
    vector<pair<int,int> >v;
    for(i=0;i<=200;i++){
        if(s.find(i)==s.end()){
            v.pb({abs(i-x),i});
        }
    }
    sort(v.begin(),v.end());
    cout<<v[0].y;
    return 0;
}

Measured memory_bytes: 3664
#include<stdio.h>
//#include<string.h>
//typedef long long ll;
int main(void)
{
  int x=0,ans=0,tmp=0,tmp2=0;
  scanf("%d",&x);
  tmp=x/500;
  tmp2=x%500;
  ans=tmp*1000+(tmp2/5)*5;
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

int main() {
	int A, B;
	cin >> A >> B;
	cout << max(A + B, max(A - B, A*B)) << endl;
}

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


using namespace std;

#define re return
#define sz(a) (int)a.size()
#define mp(a, b) make_pair(a, b)
#define fi first
#define se second
#define re return
#define forn(i, n) for (int i = 0; i < int(n); i++)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef long double ld;


vector<int> a, b;
int n;
bitset<2000001> q;

int main() {
	iostream::sync_with_stdio(0), cin.tie(0);
	//freopen("a.in", "r", stdin);
	cin >> n;
	q[0] = 1;
	a.resize(n);
	int sum = 0;
	int k = 0;
	forn (i, n) {
		cin >> a[i];
		q |= (q << a[i]);
		sum += a[i];
	}
	int ans = 0;
	forn (i, min(sum, 2000001)) {
		if (q[i] && i <= sum - i) ans = sum - i;
	}
	/*forn (i, (1 << n)) {
		int sm = 0;
		forn (j, n)
			if (i & (1 << j)) sm += a[j];
		b.push_back(sm);
	}
	sort(b.begin(), b.end());
	for (int v : b) cout << v << " ";
	if (b[sz(b) / 2] != ans) assert(0);*/
	cout << ans;
	re 0;

}

Measured memory_bytes: 1024
N = int(input())
X = list(map(int,input().split()))
XY = [[i+1,X[i],0] for i in range(N)]
XY.sort(key=lambda x:x[1],reverse=True)
m2 = XY[N//2][1]
m1 = XY[N//2-1][1]
for i in range(N):
  if (i+1) <= N//2:
    XY[i][2] = m2
  else:
    XY[i][2] = m1
XY.sort(key=lambda x:x[0])
for i in range(N):
  print(XY[i][2])

Measured memory_bytes: 43840
n = int(input())
a = []
b = []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
cnt = 0
for i in range(n - 1, -1, -1):
    rest = (a[i] + cnt) % b[i]
    if rest != 0:
        cnt += b[i] - rest
print(cnt)

Measured memory_bytes: 11052
# coding:utf-8

INF = float('inf')


def inpl(): return list(map(int, input().split()))


N = int(input())
A = inpl()
A = [0] + A + [0]
B = [0]
for i in range(len(A) - 1):
    B.append(A[i + 1] - A[i])
del B[0]

total = 0
for b in B:
    total += abs(b)

for i in range(1, N + 1):
    if B[i - 1] * B[i] >= 0:
        print(total)
    elif abs(B[i - 1]) < abs(B[i]):
        print(total - 2 * abs(B[i - 1]))
    else:
        print(total - 2 * abs(B[i]))


Measured memory_bytes: 14176
# -*- coding: utf-8 -*-
# input
n = int(input())
a = set()
temp = input()
end_char = temp[-1]
a.add(temp)
for i in range(n-1):
    temp = input()
    if temp in a or end_char != temp[0]:
        print('No')
        exit()
    end_char = temp[-1]
    a.add(temp)
print('Yes')



Measured memory_bytes: 3060
/*input
11
0.9
1
1
1.25
2.30000
5
70
0.000000001
9999.999999999
0.999999999
1.000000001
*/

// Nihesh Anderson - knandy

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 

using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
ll MOD=1000000007;

#define endl '\n'
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
ll INF = 2000000000000000001;
long double EPS = 1e-9;
ll power(ll a, ll n, ll md){if(n==0){return 1;}else{ll res=power(a,n/2,md);res=(res*res)%md;if(n%2!=0){res=(res*a)%md;}return res;}}
random_device rndm;
mt19937 grndm(rndm());
void mix(ll* a, ll* b){shuffle(a,b,grndm);}

int main(){
	fast_cin();
	// freopen("input.in","r",stdin);
	// freopen("output.out","w",stdout);
	ll n; cin >> n;
	ll zeros = 0;
	map<pair<ll, ll>, ll> f;
	for(ll i = 0; i < n; i++) {
		string s; cin >> s;
		ll dot = 0;
		while(dot < s.size() && s[dot] != '.') dot++;
		string pref = s.substr(0, dot);
		if(dot == s.size()) {
			s = "";
		}
		else {
			s = s.substr(dot + 1, s.size());
		}
		while(s.size() < 9) {
			s += "0";
		}
		s = pref + s;
		ll cur = stoll(s, nullptr, 10);
		ll five = 0, two = 0;
		while(cur % 5 == 0) {
			five++;
			cur /= 5;
		}
		while(cur % 2 == 0) {
			two++;
			cur /= 2;
		}
		f[{two, five}]++;
	}
	vector<pair<pair<ll, ll>, ll> > v;
	for(auto val: f) {
		v.push_back(val);
	} 
	ll ans = zeros * (zeros + 1) / 2;
	for(ll i = 0; i < v.size(); i++) {
		if(2 * v[i].first.first >= 18 && 2 * v[i].first.second >= 18) {
			ans += v[i].second * (v[i].second - 1) / 2;
		}
		for(ll j = i + 1; j < v.size(); j++) {
			if(v[i].first.first + v[j].first.first >= 18 && v[i].first.second + v[j].first.second >= 18) {
				ans += v[i].second * v[j].second;
			}
		}
	}
	cout << ans << endl;
	return 0;
}




















Measured memory_bytes: 3700
#include<cstdio>
#include<iostream>
#define LL long long
using namespace std;
int main(){
    LL n,A,B;
    cin>>n>>A>>B;
    LL last,cur,ans=0;
    cin>>last;
    for(int i=1;i<n;i++){
        scanf("%lld",&cur);
        if(A*(cur-last)<B) ans+=A*(cur-last);
        else ans+=B;
        last = cur;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1000000007;

#define vec                vector<int>
#define vecll              vector<ll>
#define vecd               vector<double>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << (var) << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << (var);
#define prt2(v1, v2)     cout << (v1) << " " << (v2) << "\n"
#define prt3(v1, v2, v3) cout << (v1) << " " << (v2) << " " << (v3) << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "yes" : "no");}
//----------------------------------------------------------------

int main(void) {
  int a, b, h;
  cin >> a >> b >> h;

  prt((a+b)*h/2);


}


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

#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define mod(x) ((x)%MOD)
#define o(X) (1<<(X))
#define oL(X) (1LL<<(X))
#define LL long long
#define ppt(x) __builtin_popcount(x)
using namespace std;
const int INF=0x3f3f3f3f,N=1e6+5,MOD=1e9+7;
const LL INF_LL=0x3f3f3f3f3f3f3f3fLL;

template<typename T>
inline int getplc(T x,int y) { return (x>>y)&1; }
template<typename T>
T square(T x) {return x*x;}

LL qpow(LL a,LL b=MOD-2,LL _MOD=MOD){
	LL res=1;
	for(;b;b>>=1,a=a*a%_MOD){
		if(b&1)res=res*a%_MOD;
	}
	return res;
}

template <typename T>
T Smax(T x) { return x; }
template<typename T, typename... Args>
T Smax(T a, Args... args) {
	return max(a, Smax(args...));
}
template <typename T>
T Smin(T x) { return x; }
template<typename T, typename... Args>
T Smin(T a, Args... args) {
	return min(a, Smin(args...));
}

template <typename T>
#define errorl(args...) {  \
	string _s = #args;   \
	replace(_s.begin(), _s.end(), ',', ' ');  \
    stringstream _ss(_s);  \
    istream_iterator<string> _it(_ss);  \
    errl(_it, args);  \
}
void errl(istream_iterator<string> it) {}
template<typename T, typename... Args>
void errl(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	errl(++it, args...);
}
#define error(args...) {  \
    string _s = #args;  \
    replace(_s.begin(), _s.end(), ',', ' ');  \
    stringstream _ss(_s);  \
    istream_iterator<string> _it(_ss);  \
    err(_it, args);  \
    cerr<<endl; \
}
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << "=" << a << " # ";
	err(++it, args...);
}

int a[N];

void Solve() {
	int n;
	cin >> n;

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

	int odd = 0;
	rep (i, 1, n) {
		odd += a[i] % 2;
	}

	if (odd & 1) cout << "NO" << endl;
	else cout << "YES" << endl;
}


int main() {
#ifndef ONLINE_JUDGE
	freopen("in.txt","r",stdin);
//  freopen("o1.txt","w",stdout);
#endif
	ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
	Solve();
	return 0;
}


Measured memory_bytes: 4016
// https://atcoder.jp/contests/abc089/tasks/abc089_c

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <iterator>
#include <algorithm>
using namespace std;
using namespace std::string_literals;
using ll = long long ;

class C {
public:
    multimap<char, string> names_{};
    vector<char> initials_{};
    ll total_{};
    vector<char> comb_{};
    C(vector<string> values) {
        for (auto&& v : values) {
            if (v.find_first_of("MARCH") == 0) {
                initials_.emplace_back(v[0]);
                names_.emplace(v[0], std::move(v));
            }
        }
        std::sort(initials_.begin(), initials_.end());
        initials_.erase(unique(initials_.begin(), initials_.end()), initials_.end());
    }
    // visit the combinations choosing k from initials_ whose position is equal to or larger than offset
    ll visit_next(int offset, int k) {
        if (k == 0) {
            // special case on the leaf - calculate the product of count and return
            ll num = 1;
            for(auto c : comb_) {
                num *= names_.count(c);
            }
            total_ += num;
            return total_;
        }
        auto n=initials_.size();
        if (n - offset < k) {
           // cannot pick k from remaining range
           return total_;
        }
        for(int i=offset ; i <= n - k ; ++i) {
            // at the final step:
            // #{i+1, ..., n-1} == k-1  --> n-1 - (i+1) + 1 == k - 1 -->  n - i  == k
            comb_.emplace_back(initials_[i]);
            visit_next(i+1, k-1);
            comb_.pop_back();
        }
        return total_;
    }
};
int main() {
    ll N;
    cin >> N;
    vector<std::string> values{};
    values.reserve(N);
    for (int i =0; i < N; ++i) {
        string n;
        cin >> n;
        values.emplace_back(std::move(n));
    }
    C c{std::move(values)};
    auto total = c.visit_next(0, 3);
    cout << total << endl;
}


Measured memory_bytes: 12544
#include<bits/stdc++.h>
#include<stdio.h>
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define INF 1000000000000000
#define MAXN (int)(1e6)+1
#define MOD 1000000007
 
using namespace std;
 
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,int> pwi;
typedef pair<lli,lli> plli;
typedef vector<int> vi;
typedef vector<lli> vlli;
typedef vector< vector<pair<int,lli > > > wGraph;
typedef vector<vector<int> > graph;
//typedef vector<vector<int> > matrix;

int main(){
 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout<<std::fixed;
    cout<<std::setprecision(4);
    
    int n;
    cin>>n;
    
    vi ar;
    for(int i = 0;i<n;++i){
        int v;
        cin>>v;
        ar.pb(v);
    }   
    
    int dp[n+1];
    for(int i = 0;i<n;++i){
        
        if(i == 0){
            dp[i] = 0;
        }else if(i == 1){
            dp[i] = abs(ar[i]-ar[i-1]);    
        }else{
            
            dp[i] = min(dp[i-1]+abs(ar[i]-ar[i-1]),
                        dp[i-2]+abs(ar[i]-ar[i-2]));    
            
        }
        
    }
    
    cout<<dp[n-1]<<endl;   
       
    return 0;
 
}

Measured memory_bytes: 1144
n,m=map(int,input().split())
a=[]
flag=0
for i in range(m):
    s,c=map(int,input().split())
    if s==1 and c==0 and n!=1:
        flag=1
    x=c*pow(10,(n-s))
    a.append(x)
b=sorted(list(set(a)))
if flag==1:
    print(-1)
    exit()
for i in range(len(b)-1):
    if len(str(b[i]))==len(str(b[i+1])):
        print(-1)
        exit()

ans1=sum(b)
if len(str(ans1))<n:
    ans1+=pow(10,(n-1))
print(ans1)


Measured memory_bytes: 3064
#include<stdio.h>
int main(void){
	int A,B;
	scanf("%d %d",&A,&B);
	if(A%3==0||B%3==0||(A+B)%3==0){
		printf("Possible\n");
	} 
	else{
		printf("Impossible\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>

using namespace std;

int main(){
  vector<char> c1(3), c2(3);
  for(int i = 0; i < 3; i++){
    cin >> c1.at(i);
  }
  for(int i = 0; i < 3; i++){
    cin >> c2.at(i);
  }
  
  if(c1.at(0) == c2.at(2) && c1.at(1) == c2.at(1) && c1.at(2) == c2.at(0))
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

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

using namespace std;

#define pb push_back
#define mp make_pair
#define sz(x) x.size()
#define all(x) x.begin(), x.end()
#define x first
#define y second
#define ll long long 
#define ull unsigned ll
#define db double
#define pii pair<int, int>
#define INF 1e9+7

const int N = 2010;
int n, K, Q;
vector<int> A, B, C;

int main() {
	scanf("%d %d %d", &n, &K, &Q);
	A.resize(n+1), B.resize(n+1);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &A[i]);
	}
	if (Q == 1) return puts("0"), 0;
	int ans = INF;
	for (int i = 1; i <= n; i++) {
		C.clear();
		int lb = A[i];
		int lp = i, rp = i;
		while (lp > 1 && A[lp-1] >= lb) lp--;
		while (rp < n && A[rp+1] >= lb) rp++;
		if (rp - lp + 1 < K) continue;
		lp = rp = 1;
		int cnt = 1;
		while (lp <= n) {
			while (lp <= n && A[lp] < lb) lp++;
			if (lp > n) break; rp = lp;
			while (rp < n && A[rp+1] >= lb) rp++;
			int width = rp - lp + 1;
			if (width >= K) {
				for (int i = 1, j = lp; j <= rp; j++, i++) B[i] = A[j];
				sort(B.begin()+1, B.begin()+1+width);
				for (int i = 1; i <= width - K + 1; i++) {
					if (cnt && B[i] == lb) cnt--;
					else C.push_back(B[i]);
				}
			}
			lp = rp + 1;
		}
		if (C.size() < Q-1) continue;
		sort(all(C));
		ans = min(ans, C[Q-2]-lb);
	}
	printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define PI 3.141592653589793
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N;
  cin >> N;
  ll totalr = 0LL, totall = 0LL;
  priority_queue<Pll> left, right;
  for(int i = 0; i < N; i++){
    string S;
    cin >> S;
    ll NN = S.size();
    ll y = 0;
    ll miny = 0;
    for(int i = 0; i < NN; i++){
      if(S.at(i) == '('){
        y++;
        totall++;
      }
      else{
        y--;
        totalr++;
      }
      chmin(miny, y);
    }
    if(y >= 0){
      left.push(Pll(miny, y));
      continue;
    }

    y = 0;
    miny = 0;
    for(int i = NN-1; i >= 0; i--){
      if(S.at(i) == ')'){
        y++;
      }
      else{
        y--;
      }
      chmin(miny, y);
    }
    right.push(Pll(miny, y));
  }
  if(totalr != totall){
    cout << "No" << endl;
    return 0;
  }

  auto isok = [](priority_queue<Pll> que){
    ll now = 0;
    while(!que.empty()){
      ll miny = que.top().first;
      ll y = que.top().second;
      que.pop();
      if(now + miny < 0) return false;
      now += y;
    }
    return true;
  };

  if(isok(left) && isok(right)) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 34556
s=list(input())
ls=len(s)
r=[0]*ls
c=0
for ii in range(ls-1):
  if s[ii]=="R" and s[ii+1]=="R":
    c+=1
  elif s[ii]=="R" and s[ii+1]=="L":
    c+=1
    r[ii]+=c//2+c%2
    r[ii+1]+=c//2
    c=0
  elif s[ii]=="L" and s[ii+1]=="L":
    pass
  elif s[ii]=="L" and s[ii+1]=="R":
    pass
  #print(c)
#print(*r)
c=0  
for jj in range(ls-1):
  ii=ls-1-jj
  if s[ii-1]=="R" and s[ii]=="R":
    pass
  elif s[ii-1]=="R" and s[ii]=="L":
    c+=1
    r[ii-1]+=c//2
    r[ii]+=c//2+c%2
    c=0
  elif s[ii-1]=="L" and s[ii]=="L":
    c+=1
  elif s[ii-1]=="L" and s[ii]=="R":
    pass
  #print(ii,c)
print(*r)

Measured memory_bytes: 11440
#include <bits/stdc++.h>
 
using namespace std;
#define ll long long
const ll INF=1e15;
//#define int long long
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fastio cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false)
const double pi = acos(-1.0);
int gcd (int a, int b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
int lcm (int a, int b) {
    return a / gcd(a, b) * b;
}

long long binpows(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)  //impar
            res = res * a;
        a = a * a;
        b >>= 1;  // /2
    }
    return res;
}
const int mod=1e9+7;
int binpow(int a, int b, int m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
//CHECAR SE PRECISA DE LONG LONG
int mat[25][25];
int dp[25][3097152];
int n;
int resolve(int pos, int used){
	if(pos==n){
		return 1;
	}
	int &x=dp[pos][used];
	if(x!=-1)
		return x;
	x=0;
	int aux=used;
	for(int i=0; i<n;i++){
		int dig=((aux>>i)&1);
		if(dig==0 and mat[pos][i]==1){
			x+=resolve(pos+1,used+(1<<i));
			x%=mod;
		}
	}
	return x%mod;
}
void solve(){
	memset(dp,-1,sizeof(dp));
	cin>>n;
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			cin>>mat[i][j];
		}
	}
	cout<<resolve(0,0)<<endl;
}
//revise as variaveis e a ordem nas funções
signed main(){
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
}


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

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		for(int i=0;i<N;i++) A[i] -= X;
		for(int i=0;i<N;i++) if(A[i] < 0) A[i] *= -1;
		int g = A[0];
		for(int i=0;i<N;i++) g = gcd(g, A[i]);
		Console.WriteLine(g);
		
		
	}
	
	int gcd (int a, int b){
		return a == 0 ? b : gcd(b % a, a);
	}
	
	int N,X;
	int[] A;
	public Sol(){
		var d = ria();
		N = d[0]; X = d[1];
		A = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 18400
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int a = 0;
    vector<ll> x(n), y(n);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        if ((x[i] + y[i]) % 2 == 0) {
            a |= 2;
        } else {
            a |= 1;
        }
    }
    if (a == 3) {
        cout << -1 << '\n';
        return 0;
    }
    int m = 32;
    if (a == 2) {
        m++;
    }
    cout << m << '\n';
    vector<ll> d(m, 1);
    for (int i = 0; i < m; i++) {
        d[i] <<= max(0, 31 - i);
        cout << d[i] << " ";
    }
    cout << '\n';
    vector<string> ans(n, string(m, ' '));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (abs(x[i]) > abs(y[i])) {
                if (x[i] > 0) {
                    ans[i][j] = 'R';
                    x[i] -= d[j];
                } else {
                    ans[i][j] = 'L';
                    x[i] += d[j];
                }
            } else {
                if (y[i] > 0) {
                    ans[i][j] = 'U';
                    y[i] -= d[j];
                } else {
                    ans[i][j] = 'D';
                    y[i] += d[j];
                }
            }
        }
        cout << ans[i] << '\n';
        assert(x[i] == 0 && y[i] == 0);
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#define N 456
typedef long long ll;
template<typename T> inline void read(T &x) {
	x = 0; char c = getchar();
	while (!isdigit(c))	c = getchar();
	while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
}
using namespace std;
const int P = 998244353;
inline ll quickpow(ll x, int k) {
	ll res = 1;
	while (k) {
		if (k & 1)	res = res * x % P;
		x = x * x % P;
		k >>= 1;
	}
	return res;
}
int n, A, B;
int a[N], b[N];
ll jie[N], jieni[N];
inline void init() {
	jie[0] = jieni[0] = 1;
	const int up = 405;
	for (int i = 1; i <= up; ++i)	jie[i] = jie[i - 1] * i % P;
	jieni[up] = quickpow(jie[up], P - 2);
	for (int i = up - 1; i; --i)	jieni[i] = jieni[i + 1] * (i + 1) % P;
}
ll f[N][N];
inline void work() {
	f[0][0] = -1;
	int sm = 0;
	for (int i = 1; i <= n; ++i) {
		sm += a[i];
		for (int s = A; ~s; --s) {
			for (int j = 0; j <= B; ++j) {
				if (s - a[i] < 0) continue;
				ll lstf = f[s][j]; f[s][j] = 0;
				ll tmp = 1;
				for (int k = 0; k < b[i] && k <= j; ++k, tmp = tmp * a[i] % P) {
					f[s][j] = (f[s][j] + f[s - a[i]][j - k] * tmp % P * jieni[k]) % P;
				}
				f[s][j] = (lstf - f[s][j] + P) % P;
			}
		}
	}
	ll ans = 0;
	for (int s = 0; s <= A; ++s) {
		ll sn = quickpow(s, P - 2);
		ll tmp = sn;
		for (int j = 0; j < B; ++j, tmp = tmp * sn % P) {
			ans = (ans + tmp * f[s][j] % P * jie[j]) % P;
		}
	}
	ans = ans * A % P;
	printf("%lld\n", (ans % P + P) % P);
}
int main() {
	read(n);
	for (int i= 1; i <= n; ++i)	read(a[i]), read(b[i]), A += a[i], B += b[i];
	init();
	work();
	return 0;
}

/*
3
1 3
2 2
3 1
//971...
*/

Measured memory_bytes: 4584
import java.io.InputStreamReader
import java.io.BufferedReader

fun main(args: Array<String>) {
  val br = BufferedReader(InputStreamReader(System.`in`))

  val n = br.readLine().toInt()
  val d = (1..n-1).map {
    br.readLine().split(" ").map { it.toInt() }.toIntArray()
  }

  fun solve(): String {
    tailrec fun rec(acc: Int, i: Int): Int =
      if(i == n-1) acc
      else {
        val(c, s, f) = d[i]
        when {
          acc <= s -> rec(s + c, i + 1)
          (s+acc) % f == 0 -> rec(acc + c, i + 1)
          else -> {
                val r = f -((acc - s) % f)
                rec(acc + r + c, i + 1)
              }
        }
      }

    val ret = (0..d.lastIndex)
      .map { rec(0, it) }
      .plusElement(0)
      .joinToString("\n")

    return ret
  }

  val ans = solve()
  println(ans)
}

Measured memory_bytes: 37752
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int k,a,b;
	bool out=false;
	cin>>k>>a>>b;
	for(int i=a;i<=b;i++)
	{
	    if(i%k==0)
	    {
	        out=true;
	        break;
	    }
	}
	if(out)cout<<"OK"<<endl;
	else cout<<"NG"<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

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

    int N;
    cin >> N;
    vector<int> b(2 * N);

    int l = N, r = N;
    for (int i = 1; i <= N; ++i) {
        int a;
        cin >> a;
        if (N % 2 == i % 2) {
            b.at(--l) = a;
        } else {
            b.at(r++) = a;
        }
    }

    for (int i = l; i < r; ++i) {
        if (i > l) cout << ' ';
        cout << b.at(i);
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3712
#define _GLIBCXX_DEBUG
#include <iostream>
using namespace std;

int main(void){
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if(k <= a) cout << k << '\n';
    else if(k <= a+b) cout << a << '\n';
    else cout << a-(k-a-b) << '\n';
    return 0;
}

Measured memory_bytes: 3660
#include <stdio.h>
#define N 262144
#define HALFN 131072
#define INFTY 1000000001
int L[HALFN] = {0}, R[HALFN] = {0};
long cnt = 0;
 
void merge(int *A, int left, int mid, int right) {
  int i, j, k, n1, n2;  
  n1 = mid - left;
  n2 = right - mid; 
  for (i = 0; i < n1; i++){
    L[i] = A[left + i];
  }
  for (i = 0; i < n2; i++){
    R[i] = A[mid + i];
  }
  L[n1] = INFTY;
  R[n2] = INFTY;
  for (i = 0, j = 0, k = left; k < right; k++) {
    if (R[j] < L[i]) {
      cnt += (n1 - i);
      A[k] = R[j];
      j++;
    }
    else {
      A[k] = L[i];
      i++;
    }
  }
}
 
void mergeSort(int *A, int left, int right) {
  int mid;
  if ((left + 1) < right) {
    mid = (left + right) / 2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);
  }
}
 
int main(void){
  int i, n, A[N] = {0};
  scanf("%d", &n);
  for (i = 0; i < n; i++){
    scanf("%d", &A[i]);
  }
  mergeSort(A, 0, n);
  printf("%ld\n", cnt);
  return 0;
}

Measured memory_bytes: 2416
#include <stdio.h>

#define N 100001

int A[N];
char X[N];
int Number[N];
char C[N];

void quic_sort(int , int );
void Swap1(int* , int* );
void Swap2(char* , char* );
int Check(int );
int Partition(int , int );

int main()
{
  int n, i;
  scanf("%d", &n);
  for(i=0 ; i<n ; i++)
  {
    getchar();
    scanf("%c%d", &X[i], &A[i]);
  }
  for(i=0 ; i<n ; i++)
  {
    Number[i] = A[i];
    C[i] = X[i];
  }
  quic_sort(0, n-1);
  printf("%s\n", (Check(n) ? "Stable" : "Not stable"));
  for(i=0 ; i<n ; i++) printf("%c %d\n", X[i], A[i]);
  return 0;
}

void Swap1(int* a, int* b)
{
  int tmp = *a;
  *a = *b;
  *b = tmp;
}

void Swap2(char* a, char* b)
{
  char tmp = *a;
  *a = *b;
  *b = tmp;
}

int Partition(int p, int r)
{
  int x = A[r];
  int i = p - 1, j;
  for(j=p ; j<r ; j++)
  {
    if(A[j] <= x)
    {
      i++;
      Swap1(&A[i], &A[j]);
      Swap2(&X[i], &X[j]);
    }
  }
  Swap1(&A[i+1], &A[r]);
  Swap2(&X[i+1], &X[r]);
  return i+1;
}

void quic_sort(int p, int r)
{
  if(p < r)
  {
    int q = Partition(p, r);
    quic_sort(p, q-1);
    quic_sort(q+1, r);
  }
}

int Check(int n)
{
  int i, j;
  for(i=1 ; i<n ; i++)
  {
    if(A[i-1] == A[i])
    {
      int a, b;
      for(j=0 ; j<n ; j++)
      {
        if(A[i-1] == Number[j] && X[i-1] == C[j]) a = j;
        if(A[i] == Number[j] && X[i] == C[j]) b = j;
      }
      if(a > b) return 0;
    }
  }
  return 1;
}



Measured memory_bytes: 2744
num_list = [int(i) for i in input().split()]

result = 0

for i in range(1, num_list[0] + 1):
    sum = 0
    n = i
    while n > 0:
        sum += n % 10
        n = n // 10
    if sum >= num_list[1] and sum <= num_list[2]:
        result += i

print(result)


Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;

int main(){
	int n;
	scanf(" %d", &n);
	for(int i=0; i<n; ++i){
		int count=0, ans=0, base[3];
		for(int i=0; i<3; ++i) base[i]=0; //初期化

		while(count<3){
			string s;
			cin >> s;
			if(s=="HIT"){
				if(base[2]==1) ++ans;
				base[2]=base[1];
				base[1]=base[0];
				base[0]=1;
			}
			else if(s=="HOMERUN"){
				for(int i=0; i<3; ++i) {
					ans+=base[i];
					base[i]=0;
				}
				++ans;
			}
			else if(s=="OUT") ++count;
		}
		
		printf("%d\n", ans);
	}
	return 0;	
}

Measured memory_bytes: 1248
N = gets.to_i
as = gets.strip.split(/ /).collect{|a| a.to_i}.sort


#as = (10**5).times.collect{rand(10**9)}.sort

ai = as.pop
aj = as.pop

def real_aj(ai, aj)
	if ai - aj + 1 >= aj
		return aj
	else
		return ai - aj
	end
end

aj_r = real_aj(ai, aj)
while ak = as.pop
	ak_r = real_aj(ai, ak)
	if ak_r > aj_r
		aj = ak
		aj_r = ak_r
	else
		break
	end
end

puts "#{ai} #{aj}"



Measured memory_bytes: 11016
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

    ll n, a, b, c, d, e;
    cin >> n >> a >> b >> c >> d >> e;

    ll bottle_neck = min({a, b, c, d, e});
    cout << 5 + n/bottle_neck - (bottle_neck == 1) << endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	void solve() {
		double A, B, H, M;
		cin >> A >> B >> H >> M;

		const double pi = 3.141592653589793;
		double rh = 2*pi * ((H + M/60) / 12);
		double rm = 2*pi * (M/60);
		double ans = sqrt( A*A + B*B - 2*A*B*cos( rh-rm ) );
		cout << ans << endl;
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();
	return 0;
}


Measured memory_bytes: 4200
N=int(input())
t,x,y=0,0,0
for _ in range(N):
    t_next,x_next,y_next=map(int,input().split())
    ds = abs(x_next-x)+abs(y_next-y)
    dt= t_next-t
    if ds > dt or (ds-dt)%2==1:
        print('No')
        exit(0)
    t,x,y =t_next,x_next,y_next
print('Yes')

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

type Card struct{ Number, Stock int }
type Cards []Card

func (c Cards) Len() int           { return len(c) }
func (c Cards) Swap(i, j int)      { c[i], c[j] = c[j], c[i] }
func (c Cards) Less(i, j int) bool { return c[i].Number > c[j].Number }

func main() {
	sc.Split(bufio.ScanWords)

	N, M := nextInt(), nextInt()
	sum := 0
	var A, D = make([]int, N), make([]Card, M)
	for i := 0; i < N; i++ {
		a := nextInt()
		A[i] = a
		sum += a
	}
	for i := 0; i < M; i++ {
		b, c := nextInt(), nextInt()
		D[i] = Card{c, b}
	}

	sort.Ints(A)
	sort.Sort(Cards(D))

	pos := 0
lp:
	for _, card := range D {
		for i := 0; i < card.Stock; i++ {
			if pos >= len(A) || card.Number < A[pos] {
				break lp
			}
			sum += card.Number - A[pos]
			pos++
		}
	}

	fmt.Println(sum)
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define simplify ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;


const int N=1e5+5;
int arr[N];
int32_t main() {

    simplify
    int n;
    cin>>n;
    map<int,int>mp;
    int sum=0;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        mp[arr[i]]++;
        sum+=arr[i];
    }
    int b,c,q;
    cin>>q;

    while(q--){
        cin>>b>>c;
        int bb=mp[b];
        int cc=mp[c];
        sum+=(bb)*(c-b);
        cout<<sum<<endl;
        mp[c]+=mp[b];
        mp[b]=0;
    }



    return 0;
}


Measured memory_bytes: 10248
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a >= 13) System.out.println(b);
        else if(a >= 6 && a <= 12) System.out.println(b/2);
        else System.out.println(0);
	}
}

Measured memory_bytes: 23380
sx, sy, tx, ty = map(int, input().split())
dx = abs(sx - tx)
dy = abs(sy - ty)

print("R"*dx, end="")
print("U"*dy, end="")
print("L"*dx, end="")
print("D"*dy, end="")
print("D", end="")
print("R"*(dx + 1), end="")
print("U"*(dy + 1), end="")
print("L", end="")
print("U", end="")
print("L"*(dx + 1), end="")
print("D"*(dy + 1), end="")
print("R", end="")



Measured memory_bytes: 3064
#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)
using namespace std;
typedef pair<int,int> P;
typedef long long int ll;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}

const int MAX_N = 1 << 20;

// セグメント木を持つグローバル配列
int nn, dat[2 * MAX_N - 1];

// 初期化
void init(int n_){
    // n_が小さいときの変な挙動を防ぐ
    if(n_ < 10)n_ = 10;
    // 簡単のため要素数を2のべき乗に
    nn = 1;
    while(nn < n_)nn *= 2;

    // 全ての値をINT_MAXに
    for(int i = 0; i < 2 * nn - 1; i++)dat[i] = INT_MAX;
}

// k番目の値(0-indexed)をaに変更
void update(int k, int a){
    // 葉の接点
    k += nn - 1;
    dat[k] = a;
    // 登りながら更新
    while(k > 0){
        k = (k - 1) / 2;
        dat[k] = min(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
}

// [a,b)の最小値を求める
// 後ろのほうの引数は、計算の簡単のための引数。
// kは節点の番号、l, rはその節点が[l, r)に対応づいていることを表す。
// したがって、外からはquery(a, b, 0, 0, nn)として呼ぶ。
int query(int a, int b, int k, int l, int r){
    // [a, b)と[l, r)が交差しなければ、INT_MAX
    if (r <= a || b <= l)return INT_MAX;

    // [a, b)が[l, r)を完全に含んでいれば、この節点の値
    if (a <= l && r <= b)return dat[k];
    else {
        // そうでなければ、2つの子の最小値
        int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
        int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return min(vl, vr);
    }
}


int main(){
    int h, w;
    cin >> h >> w;
    init(w+10);
    set<int> se;
    srep(i,1,w+1){
        update(i,0);
        se.insert(i);
    }
    int INF = 1001001001;
    rep(i,h){
        int a, b;
        scanf("%d%d", &a,&b);

        auto ite = se.lower_bound(a);
        int mi = INF;
        while(ite != se.end()){
            int x = *ite;
            if(x > b+1)break;
            int tmp = query(x,x+1,0,0,nn);
            tmp += b + 1 - x;
            mi = min(mi, tmp);
            update(x,INF);
            ite = se.erase(ite);
        }
        if(mi < INF){
            update(b+1,mi);
            if(b < w)se.insert(b+1);
        }
        // cout << se.size() << endl;
        int ans = query(1,w+1,0,0,nn);
        ans += i+1;
        if(ans>=INF)ans = -1;
        printf("%d\n",ans);
    }
    return 0;
}



Measured memory_bytes: 15172
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll q;
  cin >> q;
  for (ll testcase = 0; testcase < q; ++testcase) {
    string a, b;
    cin >> a >> b;
    vector<vector<ll>> dp(a.size() + 1, vector<ll>(b.size() + 1, 0));
    for (ll i = 0; i < a.size(); ++i) {
      for (ll j = 0; j < b.size(); ++j) {
        if (a.at(i) == b.at(j)) {
          dp.at(i + 1).at(j + 1) = max(dp.at(i + 1).at(j + 1), dp.at(i).at(j) + 1);
        }
        dp.at(i + 1).at(j) = max(dp.at(i + 1).at(j), dp.at(i).at(j));
        dp.at(i).at(j + 1) = max(dp.at(i).at(j + 1), dp.at(i).at(j));
        dp.at(a.size()).at(j + 1) = max(dp.at(a.size()).at(j), dp.at(a.size()).at(j + 1));
      }
      dp.at(i + 1).at(b.size()) = max(dp.at(i + 1).at(b.size()), dp.at(i).at(b.size()));
    }
    cout << dp.at(a.size()).at(b.size()) << "\n";
    // for (ll i = 0; i <= a.size(); ++i) {
    //   for (ll j = 0; j <= b.size(); ++j) {
    //     cout << dp.at(i).at(j) << " ";
    //   }
    //   cout << "\n";
    // }
  }
}



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

bool allMinus(std::vector<long long>&);

int main()
{
	int n;
	scanf("%d", &n);
	std::vector<long long> a(n);
	for (auto& e: a) scanf("%lld", &e);
	if (allMinus(a))
	{
		int max_i{};
		for (int i{}; i < n; i++)
			if (a[i] > a[max_i])
				max_i = i;
		printf("%lld\n", a[max_i]);
		printf("%d\n", n - 1);
		for (int i{n - 1}; i > max_i; i--)
			printf("%d\n", i + 1);
		for (int i{}; i < max_i; i++)
			puts("1");
		return 0;
	}
	long long sum[2]{};
	for (int ini{}; ini < 2; ini++)
		for (int a_i{n - 1 - ini}; a_i >= 0; a_i -= 2)
			if (a[a_i] > 0)
				sum[ini] += a[a_i];
	std::vector<int> erase;
	if (sum[0] > sum[1])
	{
		if (a.back() <= 0) erase.push_back(n);
		for (int i{n - 3}; i >= 0; i -= 2)
			if (a[i] <= 0)
				erase.push_back(i + 1);
			else
				erase.push_back(i + 2);
		if (~n & 1) erase.push_back(1);
		else if (a.front() < 0) erase.push_back(1);
		printf("%lld\n", sum[0]);
	}
	else
	{
		for (int i{n - 2}; i >= 0; i -= 2)
			if (a[i] <= 0)
				erase.push_back(i + 1);
			else
				erase.push_back(i + 2);
		if (n & 1) erase.push_back(1);
		else if (a.front() < 0) erase.push_back(1);
		printf("%lld\n", sum[1]);
	}
	printf("%d\n", erase.size());
	for (auto& e: erase) printf("%d\n", e);

	return 0;
}

bool allMinus(std::vector<long long>& a)
{
	for (auto& e: a)
		if (e > 0)
			return false;
	return true;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pil pair<int, ll>
#define pll pair<ll, ll>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
const double eps = 1e-8;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<class T> ostream& operator << (ostream& os, const set<T>& s) { for (auto si : s) os << si << " "; return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { (a += (b % mod + mod)) %= mod; }
template<class T> void operator += (vector<T>& v, vector<T> v2) { rep(i, sz(v2)) v.eb(v2[i]); }

void solve();

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(12);
    int T;
    T = 1;
    while (T--) solve();
}

void solve() {
    int x;
    cin >> x;
    ll d = 1000;
    for (ll a = -d; a < d; ++a) for (ll b = -d; b < d; ++b) {
        if (a * a * a * a * a - b * b * b * b * b == x) {
            // cerr << a * a * a * a * a << " " << b * b * b * b * b << endl;
            cout << a << " " << b << endl;
            return;
        }
    }
}


Measured memory_bytes: 3600
# -*- coding: utf-8 -*-

n, m = map(int, input().split())

h = list(map(int, input().split()))

s = set()

for i in range(m):
    a, b = map(int, input().split())
    if h[a-1] == h[b-1]:
        s.add(a)
        s.add(b)
    elif h[a-1] > h[b-1]:
        s.add(b)
    else:
        s.add(a)

print(n-len(s))

Measured memory_bytes: 20108
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
const ll longinf=1LL<<60;
using namespace std;
struct edge
{
    int y,c,next;
};
edge e[300000];
int loc[200000];
int t=1;

int color[200000];
bool flag[200000];

void add(int a,int b,int c)
{
    e[t].y=b;
    e[t].c=c;
    e[t].next=loc[a];
    loc[a]=t;
    t++;
}

void dfs(int x)
{
    for (int now=loc[x]; now; now=e[now].next)
    {
        int y = e[now].y;
        if (flag[y]==0)
        {
            if (e[now].c==0)
                color[y]=color[x];
            else color[y]=color[x]^1;
            flag[y]=1;
            dfs(y);
        }
    }
}


int n,a,b,c;
int main()
{
    cin>>n;
    for (int i=1; i<=n-1; ++i)
    {
        cin>>a>>b>>c;
        add(a,b,c%2);
        add(b,a,c%2);
    }
    flag[1]=1;
    color[1]=0;
    dfs(1);
    for (int i=1; i<=n; ++i)
        cout<<color[i]<<endl;
    return 0;
}



Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define LL long int
#define ULL unsigned long int
#define MOD (long int)10e9 + 7


int main(){
    long double n;
    cin >> n;
    long double m;
    cin >> m;
    long double all = 0;
    vector<long double> a(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        all += a[i];
    }

    sort(a.begin(),a.end(),greater<double>());

    if(a[m - 1] >= all / (4 * m)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int h,w;
    cin>>h>>w;
    vector<string> p(h);
    rep(i,h) cin>>p[i];
    vector<int> cn;
    rep(i,h){
        bool che=true;
        rep(j,w) if(p[i][j]=='#') che=false;
        if(che) cn.push_back(i);
    }
    sort(etob(cn));
    for(auto& v: cn){
        p.erase(p.begin()+v);
    }
    cn.clear();
    rep(i,w){
        bool che=true;
        int a=p.size();
        rep(j,a) if(p[j][i]=='#') che=false;
        if(che) cn.push_back(i);
    }
    sort(etob(cn));
    for(auto& v: cn){
        int a=p.size();
        rep(i,a) p[i].erase(p[i].begin()+v);
    }
    for(auto& v:p) cout<<v<<endl;
    return 0;
}

Measured memory_bytes: 3652