akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int N=100010,Mod=998244353;
const double pi=acos(-1.0);
typedef long long int ll;
typedef pair<int,int> pii;
int n,a[N],vis[N];
stack<int> s;
int main()
{
  cin>>n;
  for(int i=1;i<=n;i++) cin>>a[i];
  if(n==1)
  {
    cout<<"Yes\n";
    return 0;
  }
  for(int i=2;i<=n;i++)
  {
    if(a[i]>=a[i-1]) continue;
    else
    {
      int j=i;
      while(j>0)
      {
        if(a[j-1]<=a[j]) break;
        if((a[j-1]-1)<=a[j])
        {
          if(!vis[j-1])
          {
            vis[j-1]=1;
            a[j-1]--;
          }
          else
          {
            cout<<"No\n";
            return 0;
          }
        }
        else
        {
          cout<<"No\n";
          return 0;
        }
        j--;
      }
    }
  }
  cout<<"Yes\n";
  return 0;
}


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

long long k,ans,tmp,tmp2;
string s,v;

int main(){

	cin>>s>>k;
	v=s;
	
	for(int i=1;i<s.size();i++){
		if(s[i]==s[i-1]){
			tmp++;
			s[i]='$'; //$wag
		}
	}
	
	v[0]='$';
	tmp2++;
	for(int i=1;i<s.size();i++){
		if(v[i]==v[i-1]){
			tmp2++;
			v[i]='$'; //$wag
		}
	}
	
	if(s[0]==s[s.size()-1]){
		if(v[v.size()-1]!='$')ans=tmp+tmp2*(k-1);
		else ans=(tmp2*(k/2))+(tmp*(k-k/2));
	}
	else
		ans=tmp*k;
		
	cout<<ans<<endl;

return 0;
}


Measured memory_bytes: 256
N = int(input())
L = len(str(N))
if L == 1:
    print(N)
    quit()
    
pair = [[(10**(L-2)-1)//9]*9 for _ in range(9)]
for i in range(9):
    pair[i][i] += 1

for i in range(10**(L-1), N+1):
    pair[int(str(i)[0])-1][int(str(i)[L-1])-1] += 1 if i%10 else 0
ans = 0
for i in range(9):
    for j in range(9):
        ans += pair[i][j] * pair[j][i]
print(ans)

Measured memory_bytes: 9160
#include<bits/stdc++.h>
using namespace std;
bitset<4000005>A;
int i,j,k,l,s,n,m,ans;
int main() {
	scanf("%d",&n);
	A[0]=1;
	for (i=1;i<=n;i++) scanf("%d",&s),ans+=s,A|=(A<<s);
	ans=(ans+1)/2;
	while (!A[ans]) ans++;
	printf("%d\n",ans);
}

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

int main(){
    ios::sync_with_stdio(false);
    long long int n,t=0,y=0;
    bool tb=false,yb=false;
    cin>>n;
    vector<long long int>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    sort(a.begin(),a.end(),greater<long long int>());
    for(int i=0;i<n-1;i++){
        if(a[i]==a[i+1]&&tb==false){
            t=a[i];
            tb=true;
            i+=1;
            continue;
        }
        if(a[i]==a[i+1]&&yb==false){
            y=a[i];
            yb=true;
            i+=1;
            continue;
        }
        if(tb&&yb){
            break;
        }
    }
    cout<<t*y;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
	long long a;
	while (scanf("%lld", &a) != EOF) {
		printf("%lld\n", a + a * a + a * a * a);
	}
	return (0);
}


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

struct hi
{
	int t,x,y;
}h[100005];

int main()
{
	memset(h,0,sizeof(h));
	int n,i;
	cin>>n;
	for(i=1;i<=n;i++) scanf("%d%d%d",&h[i].t,&h[i].x,&h[i].y);
	for(i=1;i<=n;i++)
	{
		int ti=h[i].t-h[i-1].t;
		int xi=h[i].x-h[i-1].x;
		int yi=h[i].y-h[i-1].y;
		if(xi+yi>ti||(ti-(xi+yi))%2==1)
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(b);i>(a);--i)
#define eper(i,a,b) for(int i=((int)(a));i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 2000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}

string s;
int cnt;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> s;
    rep(i, 0, 3) {
        if (s[i] == 'o') cnt++;
    }
    cout << 700 + cnt * 100 << endl;
    return 0;
}

Measured memory_bytes: 256
//include
//------------------------------------------
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>

#include <numeric>
#include <utility>
#include <complex>

#include <sstream>
#include <iostream>
#include <iomanip>

#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <ctime>

// namespace
using namespace std;

// type alias
using ll = long long;
using ull = unsigned long long;
using comp = complex<double>;

// constant
static const ll MOD = 1000000007LL;
static const double PI = 3.14159265358979323846;

// conversion
inline ll toint(string s) { ll v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

// print
#define RET(x) return cout << x << endl, 0;

// for loop
#define REP(i, a, b) for ((i) = (ll)(a);(i) < (ll)(b);(i)++)
#define REPD(i, a, b) for (ll i = (ll)(a);(i) < (ll)(b);(i)++)
#define REPI(v, vs) for (auto& v : vs)

//debug
#ifdef LOCAL_ENV
#define DUMP(x)  cerr << #x << " = " << (x) << endl
#define DEBUG(x) cerr << #x << " = " << (x) << " (l" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define DUMP(x)
#define DEBUG(x)
#endif

#define MAX_VALUE 9223372036854775807LL

template <ull N, class T, class... Args, std::enable_if_t<N == 0, int> = 0>
auto make_multiple_vector(Args... args) {
    return T(args...);
}

template <ull N, class T, class... Args, std::enable_if_t<N != 0, int> = 0>
auto make_multiple_vector(ull size, Args... args) {
    using value_type = std::decay_t<decltype(make_multiple_vector<N - 1, T>(args...))>;
    return vector<value_type>(size, make_multiple_vector<N - 1, T>(args...));
}

int solve() {
	ll D, T, S;
	cin >> D >> T >> S;

	RET((S * T >= D ? "Yes": "No"));

	return 0;
}

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

	solve();
	// ll t;
	// cin >> t;
	// REPD(i, 0, t) solve();

	return 0;
}


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

using namespace std;

int main(){
        int x;
        cin>>x;
        if(x<=3){
                cout<<1<<endl;
        }
        else{
                int res=-1;
                for(int i=2;i<=1000;i++){
                        for(int j=2;pow(i, j)<=x;j++){
                                int vres=pow(i, j);
                                res=max(vres, res);
                        }
                }
                cout<<res<<endl;
        }
        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 1 << 21;
using pii = std::pair<int, int>;
#define SORT(v) std::sort(v.begin(), v.end())
int main(void) {
	int N,M;
	std::cin >> N >> M;
	std::vector<bool> A(N+1), B(N+1);
	int a, b;
	for (int i = 0; i < M; ++i) {
		std::cin >> a >> b;
		if (a == 1) {
			A[b] = true;
		}
		else if (b == N) {
			B[a] = true;
		}
	}
	for (int i = 1; i < N + 1; ++i) {
		if (A[i] == true && B[i] == true) {
			std::cout << "POSSIBLE" << std::endl;
			return 0;
		}
	}
	std::cout << "IMPOSSIBLE" << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	puts(a+b==c+d?"Balanced":a+b<c+d?"Right":"Left");
}

Measured memory_bytes: 128
n,d = map(int,input().split())
x = [list(map(int, input().split())) for _ in range(n)]

ans = 0
for i in range(n-1):
    for j in range(i+1,n):
        tmp = 0
        for k in range(d):
            tmp += (x[i][k] - x[j][k])**2
        tmp = tmp**(1/2)
        if(tmp == tmp//1):
            ans += 1

print(ans)

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

using namespace std;

int n,m;
int pos[4], ans[4];

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

	cin >> n >> m;
	for (int i=1;i<=3;i++)
		pos[i] = -1;
	for (int i=1;i<=m;i++)
	{
		int s,c;
		cin >> s >> c;
		if (pos[s] != -1 && pos[s] != c)
		{
			cout << -1;
			return 0;
		}
		pos[s] = c;
	}	
	if (n == 1 && (m == 0 || pos[1] == 0))
	{
		cout << 0;
		return 0;
	}
	bool ok = false;
	for (int i=1;i<=n;i++)
	{
		if (pos[i] == -1)
		{
			if (ok) ans[i] = 0;
			else 
			{
				ans[i] = 1;
				ok = true;
			}	
		}	
		else
		{
			ans[i] = pos[i];
			if (!pos[i] && !ok)
			{
				cout << -1;
				return 0;
			}
			ok = true;
		}	
	}
	for (int i=1;i<=n;i++)
		cout << ans[i];
}

Measured memory_bytes: 256
k,s = map(int, input().split())
a = (s+2)*(s+1)/2
b = (s-k+1)*(s-k)/2
c = (s-2*k)*(s-2*k-1)/2

if s <= k:
    print(int(a))
elif s <= 2*k+1:
    print(int(a-3*b))
elif s <= 3*k:
    print(int(a-3*b+3*c))

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int main(){
    int n;
    cin>>n;
    vector<int> l(n);
    int sum =0;
    int ma=0;

    for(int i = 0; i < n; i++)
    {
        cin>>l[i];
        sum+=l[i];
        ma=max(ma,l[i]);
    }
    if(sum > ma*2)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    

    return 0;
}

Measured memory_bytes: 256
/*                        
                            In the name of Almighty ALLAH

   code from :::::::::::::::::::::
   ******************************* R E S H A D ********************************
   
   
   
    FREE PALESTINE           FREE PALESTINE            FREE PALESTINE           FREE PALESTINE
   
                 FREE PALESTINE           FREE PALESTINE            FREE PALESTINE 
                 
    FREE PALESTINE           FREE PALESTINE            FREE PALESTINE           FREE PALESTINE
   
                 FREE PALESTINE           FREE PALESTINE            FREE PALESTINE
                 
    FREE PALESTINE           FREE PALESTINE            FREE PALESTINE           FREE PALESTINE
   
 
*/     

#include <bits/stdc++.h>

#define ll               long long
#define db               double
#define Pi               2*acos(0.0)
#define pb(a)            push_back(a)
#define VI               vector <int>
#define FASTIO           ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ull              unsigned long long
#define all(a)           a.begin(),a.end()
#define loop(i,n)        for(int i=0;i<n;i++)
#define loop1(i,n)       for(int i=1;i<=n;i++)
#define TEST_CASE(t)     for(int z=1;z<=t;z++)
// 90 degree = acos(x)*180/acos(0.0)

using namespace std;

int main() {
    
    FASTIO;
    
    ll n;
    cin >> n;
    ll arr[n];
    
    for(ll i=0; i<n; i++) cin >> arr[i];
    
    ll ans=0;
    for(ll i=0; i<n-1; i++){
        if(arr[i]>arr[i+1]){
            ans += (arr[i]-arr[i+1]);
            arr[i+1]=arr[i];
        }
    }
    
    cout << ans << endl;
    
	return 0;
}

Measured memory_bytes: 5140
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//二項係数の計算
int nCr(int A, int B) {
    ll ans = 1;
    for (int i = 0; i < B; i++) {
        ans *= A - i;
    }
    for (int i = 0; i < B; i++) {
        ans /= i + 1;
    }
    return ans;
}
int main() {
    int N;
    cin>>N;
    vector<int>A(N);
    rep(i,N){
        cin>>A[i];
    }
    ll ans=0;
    rep(i,N){
        if(A[A[i]-1]==i+1){
            ans++;
        }
    }
    cout<<ans/2<<endl;
}

Measured memory_bytes: 3768
#include<bits/stdc++.h>
#pragma warning(disable:4996)
#ifdef _MSC_VER
#  define __builtin_popcount __builtin_popcountll
#  define __builtin_popcountll __popcnt
#endif
#define int long long
using namespace std;
using ll = long long;
using ld = long double;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
inline void my_io() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout << fixed << setprecision(10);
}
signed main() {
	my_io();
	ld t, x;
	cin >> t >> x;
	cout << t / x << endl;
	return 0;
}




Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <numeric>
#include <array>
#include <float.h>
#include <memory>
#include <functional>
#include <iomanip>
#include <random>
#include <map>
#include <set>

using namespace std;


using ULL = decltype(0ull);
constexpr auto DIV = 1000000007ull;
constexpr auto MAX = numeric_limits<ULL>::max();


int main() {
  string str;
  cin >> str;
  auto begin = str.find('A');
  auto end = str.find_last_of('Z');
  cout << str.substr(begin, end - begin).size() + 1 << endl;
  return 0;
}

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

int gcd(int x, int y);

const int INF = 1001001001;

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    sort(h.begin(), h.end());
    int ans = INF;
    for (int i = k - 1; i < n; i++) {
        int num = h[i] - h[i - k + 1];
        ans = min(num, ans);
    }

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

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

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

#define int long long
typedef pair<int,int> P;

signed main(){
  int t;cin>>t;
  while(t--){
    int n;cin>>n;
    int ans=0;
    set<int> s,t;
    for(int i=0;i<=n+1;i++){
      s.insert(i);
      t.insert(i);
    }
    vector<P> L,R;
    for(int i=0;i<n;i++){
      int k,l,r;cin>>k>>l>>r;
      if(l>r){
        ans+=r;
        L.push_back(P(l-r,k));
      }
      else{
        ans+=l;
        R.push_back(P(r-l,k));
      }
    }
    sort(L.rbegin(),L.rend());
    sort(R.rbegin(),R.rend());
    for(P p:L){
      int a=*--s.upper_bound(p.second);
      if(a>=1){
        s.erase(a);
        ans+=p.first;
      }
    }
    for(P p:R){
      int a=*t.upper_bound(p.second);
      if(a<=n){
        t.erase(a);
        ans+=p.first;
      }
    }
    cout<<ans<<endl;
  }
}


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

int main() {
  int a, b;
  while(cin >> a >> b) {
    char buff[100];
    sprintf(buff, "%d", a+b);
    cout << strlen(buff) << endl;
  }
  return 0;
}

Measured memory_bytes: 1192
solve :: Int -> Int -> Int -> Int
solve current x n
  | n == 1 = 1
  | current == 1 = solve (n * n) x n
  | x < (current * n) = current
  | otherwise = solve (n * current) x n

main = do
  x <- readLn :: IO Int
  print $ maximum $ filter (\n -> n <= x) (map (solve 1 x) [1 .. 32])

Measured memory_bytes: 3908
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  ll a, b, c;
  cin >> a >> b >> c;
  ll ans = 0;
  for (ll i = a; i <= b; i++) if (c % i == 0) ans++;
  cout << ans << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  cout << fixed;
  solve();
  return 0;
}



Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define int long long
#define moder (int)(1e9+7)
#define inf (int)(3e18+7)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x > 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % moder;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	return kai(x)* mod_pow(kai(x - y), moder - 2, moder) % moder * mod_pow(kai(y), moder - 2, moder) % moder;
}
/*--------Library Zone!--------*/

string s, t, r;
signed main() {
	cin >> s;
	for (char c : s) {
		if (c != 'x')t += c;
	}
	r = t;
	reverse(all(r));
	rep(i, t.size()) {
		if (t[i] != r[i]) {
			cout << -1 << endl;
			return 0;
		}
	}
	vector<int>cnt;
	int memo = 0;
	rep(i, s.size()) {
		if (s[i] == 'x') {
			memo++;
		}
		else {
			cnt.push_back(memo);
			memo = 0;
		}
	}
	cnt.push_back(memo);
	vector<int>cnt2 = cnt;
	reverse(all(cnt2));
	int ans = 0;
	rep(i, cnt.size() / 2) {
		ans += abs(cnt[i] - cnt2[i]);
	}
	cout << ans << endl;
}

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

const ll MOD = 998244353;

ll solve(ll n, ll k, vector<ll> l, vector<ll> r) {
  vector<ll> dp(n, 0), sdp(n+1, 0);
  dp[0] = sdp[1] = 1;

  for(ll i=1;i<n;i++) {
    for(int j=0; j<k; j++) {
      ll left = max(0LL, i-r[j]);
      ll right = max(0LL, i-l[j]+1);
      ll temp = sdp[right] - sdp[left];
      if(temp < 0)
	temp += MOD;
      dp[i] = (temp + dp[i]) % MOD;
    }
    sdp[i+1] = (sdp[i] + dp[i]) % MOD;
  }

  return dp[n-1];
}

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> l(k);
  vector<ll> r(k);
  for(int i=0;i<k;i++) {
    cin >> l[i] >> r[i];
  }
  cout << solve(n, k, l, r);
}

Measured memory_bytes: 6380
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll n,c=0;
  cin>>n;
  vector<ll> a(n*3);
  for(int i=0;i<n*3;i++){
    cin>>a[i];
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  for(int i=1;i<n*2+1;i+=2){
    c+=a[i];
  }
  cout<<c<<endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define repr(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define all(x) (x).begin(),(x).end()

template<typename T> constexpr auto square(T x) { return (x) * (x); }

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

const int MOD = 1000000007;

int main()
{
	ULL S;
	cin >> S;

	if (S < static_cast<ULL>(1e9)) cout << "0 0 1 0 0 " << S << endl;

	else {
		const ULL y2 = static_cast<ULL>(1e9);
		ULL s = 0, x1 = 0;
		while (s < S) {
			s = y2 * ++x1;
		}

		if (s == S) cout << "0 0 " << x1 << " 0 0 " << y2 << endl;

		else {
			ULL y1 = 1, x2 = 0;
			while (s != S) {
				x2++;
				s = x1 * y2 - x2 * y1;
			}
			cout << "0 0 " << x1 << " " << y1 << " " << x2 << " " << y2 << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 256
a, b, c = map(int, input().split())
week = a * 7 + b
d = c // week
ans = d * 7
c -= d * week

cnt = 0
while(c > 0):
    c -= a
    ans += 1
    cnt += 1
    if(cnt == 7):
        c -= b
        cnt = 0
print(ans) 


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

int main(){
  int n,a,b;
  cin>>n>>a>>b;
  int ans=min(a*n,b);
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
#define MOD 1000000007
#define tp tuple<ll,ll,ll>

int ans[300010];

int main() {
	for (int i = 0;i < 300010;i++)ans[i] = 0;
	int N, A;
	cin >> N;
	map<ll, ll> M;
	for (int i = 0;i < N;i++) {
		cin >> A;
		if (M.count(A))M[A]++;
		else M.insert({ A,1 });
	}
	vector<int> S;
	for (auto x : M) {
		S.push_back(x.second);
	}
	
	int ss = S.size();
	sort(all(S));
	vector<int> T = S;
	for (int i = 1;i < ss;i++) {
		T[i] += T[i - 1];
	}
	int xs, ot;
	for (int i = 1;i <= N;i++) {
		auto it = lower_bound(all(S), i);
		xs = it - S.begin();
		if (xs == 0) {
			ans[ss] = i;//最大幅
		}
		else {
			ot = ss - xs;
			ans[T[xs - 1] / i + ot] = i;
		}
	}
	for (int i = N;i > 0;i--) {
		ans[i] = max(ans[i], ans[i + 1]);
	}
	for (int i = 1;i <= N;i++) {
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 22512
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;
int main(){
  int h,a;
  cin >> h >> a;
  if (h % a != 0){
    cout << h / a + 1 << '\n';
  }
  else{
    cout << h/a << '\n';
  }
  return 0;   
}


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

int main() {
  vector<int> S(10050,0);
  for(int i=1;i*i<10001;i++){
    for(int j=1;j*j<10001;j++){
      for(int k=1;k*k<10001;k++){
        int64_t a=i*i+j*j+k*k+i*j+j*k+k*i;
        if(a>10000) break;
        S.at(a)++;
      }
    }
  }
  int N; cin>>N;
  for(int i=1;i<=N;i++) cout<<S.at(i)<<endl;
}

Measured memory_bytes: 3668
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		long k = Long.parseLong(sa[1]);
		sa = br.readLine().split(" ");
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(sa[i]) - 1;
		}
		br.close();

		int[] c = new int[n];
		Arrays.fill(c, -1);
		int now = 0;
		c[now] = 0;
		int loop = 0;
		int in = 0;
		for (int i = 1; i <= n; i++) {
			now = a[now];
			if (i == k) {
				System.out.println(now + 1);
				return;
			}
			if (c[now] != -1) {
				in = now;
				loop = i - c[now];
				break;
			}
			c[now] = i;
		}

		int m = (int) (k % loop);
		boolean flg = false;
		now = 0;
		for (int i = 1; i <= k; i++) {
			now = a[now];
			if (now == in) {
				flg = true;
			}
			if (flg && i % loop == m) {
				System.out.println(now + 1);
				return;
			}
		}
	}
}


Measured memory_bytes: 61220
#include <bits/stdc++.h>
#include <unistd.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
 
long long int INF = 3e18;
double Pi = 3.1415926535897932384626;
 
vector<ll> G[550010];
//vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//ll bit[500005];
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
 
 
ll mod = 998244353;
 
ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 

ll fact[800005],rfact[800005];
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=800000; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[800000] = rui(fact[800000],mod - 2);
    for(ll i=800000; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}

 
ll n,m,num,sum,a,b,c,d,e,g,h,w,i,j,q,r,l;
ll k,ans;
ll x[500005],y[500005],z[500005];

char s[500005];

bool solve(ll mid){
    ll cnt = 0;
    for(int i=0;i<n;i++){
        if(x[i] * y[i] > mid){
            ll limit = mid / y[i];
            cnt += (x[i] - limit);
        }
    }
    if(cnt > k){
        return false;
    }else{
        return true;
    }
}
int main(){
    cin >> n >> k;
    for(int i=0;i<n;i++){
        cin >> x[i];
    }
    for(int i=0;i<n;i++){
        cin >> y[i];
    }
    sort(x,x+n);
    sort(y,y+n);
    reverse(y,y+n);
    ll ok = INF, ng = -1;
    while(ok - ng > 1){
        ll mid = (ok + ng) / 2;
        bool flag = solve(mid);
        if(flag){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    p(ok);

    return 0;
}











Measured memory_bytes: 19456
num = int(input())
def to3(x,n):
  if (int(x/n)):
    return to3(int(x/n),n) + str(x%n)
  return str(x%n)
ch = ["3","5","7"]
ans = 0
for i in range(3 ** len(str(num))+1):
  s = to3(i,3)
  for u in range(len(str(num))-len(s)+2):
    if u > 0:
      s = "0" + s
    k1 = 0
    k2 = 0
    k3 = 0
    ss = ""
    for j in range(len(s)):
      if s[j] == "0":k1 = 1
      elif s[j] == "1":k2 = 1
      else: k3 = 1
      ss += ch[int(s[j])]
    if k1 and k2 and k3 and int(ss) <= num:ans += 1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll; 
typedef long double ld;
typedef pair<ll, ll> pll;

const ll N = 2e5 + 30, Mod = 1e9 + 7;
const ll SQ = 330;

int main () {
    ios::sync_with_stdio(0), cin.tie(0);
    string s;
    cin >> s;
    if (s == "AAA" || s == "BBB") return cout << "No", 0;
    cout << "Yes";
    return (0);
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define rep(i, n) for(int i = 0; i < n; i++)
#define repx(i, a, n) for(int i = a; i < n; i++)
#define loop while(1)
#define lli long long int
#define aryout(ary) rep(i, ary.size()) cout << ary[i] << (i < ary.size() - 1 ? " " : "\n");
#define arysort(v) sort(v.begin(), v.end()
#define aryreverse(v) reverse(v.begin(),v.end())
#define arysum(v) accumulate(v.begin(), v.end(), 0)

#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <utility>
#include <set>

using namespace std;

int main() {

  int n; cin >> n;
  string str; cin >> str;

  int ans = 0;
  rep(d1, 10) {
    rep(d2, 10) {
      rep(d3, 10) {
        int cnt = 0;
        char tmp = '0' + d1;
        rep(i, n) {
          if (str[i] == tmp) {
            if (cnt == 0) {
              tmp = '0' + d2;
            } else if (cnt == 1) {
              tmp = '0' + d3;
            } else if (cnt == 2) {
              ans += 1;
              break;
            }
            cnt += 1;
          }
        }
      }
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 888
local ior = io.input()
local n, m = ior:read("*n", "*n")
local tbl = {}
for i = 1, m do
  local p, y = ior:read("*n", "*n")
  table.insert(tbl, {i, p, y})
end
table.sort(tbl, function(x, y)
  if x[2] ~= y[2] then
    return x[2] < y[2]
  else
    return x[3] < y[3]
  end
end
)

local curp = 0
local cury = 0
for i = 1, m do
  if curp ~= tbl[i][2] then
    cury = 0
    curp = tbl[i][2]
  end
  cury = cury + 1
  tbl[i][3] = cury
end

table.sort(tbl, function(x, y)
  return x[1] < y[1]
end
)

for i = 1, m do
  io.write(string.format("%06d", tbl[i][2]))
  io.write(string.format("%06d", tbl[i][3]))
  io.write("\n")
end


Measured memory_bytes: 12284
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
} 
int main(){
    ll n,q;cin >> n >>q;
    vector<pair<ll,pl>> w(n);
    rep(i,n){
        cin >> w[i].se.fi>>w[i].se.se>>w[i].fi;
        w[i].se.fi-=w[i].fi;
        w[i].se.se-=w[i].fi+1;
    }
    sort(all(w));
    vector<ll> que(q),ans(q);
    rep(i,q)cin >> que[i];
    set<ll> st;rep(i,q)st.ins(que[i]);
    rep(i,n){
        auto p=st.lower_bound(w[i].se.fi);
        if(p==st.end())continue;
        while(*p<=w[i].se.se){
            ll id=lower_bound(all(que),*p)-que.begin();
            ans[id]=w[i].fi;p=st.erase(p);
            if(p==st.end())break;
        }
    }
    rep(i,q){
        if(ans[i])cout << ans[i] <<endl;
        else cout << -1 <<endl;
    }
}

Measured memory_bytes: 20408
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;

const int INF=0x3f3f3f3f;
const ll MOD=998244353;
const int N=3e5+5;

ll n, A, B, k;
ll fakt[N];

ll add(ll a, ll b) {
    return (a+b)%MOD;
}

ll mul(ll a, ll b) {
    return (a*b)%MOD;
}

ll pot(ll base, ll exponent) {
    ll result = 1;
    while (exponent>0) {
        if (exponent & 1)
            result=mul(result, base);
        exponent=exponent/2;
        base=mul(base, base);
    }
    return result;
}

ll povrh(ll n, ll k) {
    if (k==0) return 1LL;
    return mul(fakt[n], pot(mul(fakt[n-k], fakt[k]), MOD-2));
}

int main() {
    scanf("%lld %lld %lld %lld", &n, &A, &B, &k);
    fakt[0]=1;
    for (int i=1; i<=n+2; ++i) fakt[i]=mul(fakt[i-1], (ll)i);
    ll sol=0;
    for (ll a=0; a<=n; ++a) {
        if ((k-a*A)%B || k<a*A) continue;
        ll b=(k-a*A)/B;
        if (b<0) continue;
        if (b>n) continue;
        sol=add(sol, mul(povrh(n, (ll)a), povrh(n, (ll)b)));
    }
    printf("%lld\n", sol);
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main()
{
    int n;
    cin >>n;
    vector<string> s(n);
    rep(i,n) cin >>s[i];

    vector<int> w(n);
    rep(i,n)rep(j,n) w[i]+=(s[i][j]=='o');

    vector<int> v;
    rep(i,n)rep(j,w[i]) v.pb(i+1);
    int V = v.size();
    // dbg(v);

    random_device rnd;
    mt19937 mt(rnd());
    uniform_int_distribution<> randV(0,V-1);

    int a = v[randV(mt)];
    rep(i,1000)
    {
        printf("%d\n", a); fflush(stdout);

        int judge_ai_hand;
        scanf("%d", &judge_ai_hand);

        if(s[a-1][judge_ai_hand-1]=='x') a = v[randV(mt)];
    }

    return 0;
}



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

int main(){
  int K,A,B = 0;
  bool isOK = false;
  cin >> K >> A >> B;
  for(int i = A; i <= B; i++){
    if(i % K == 0){
      isOK = true;
    }
  }
  
  if(isOK) cout << "OK" << endl;
  else cout << "NG" << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1'000'000'007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define REP(i, n) for(ll i=0; i<(ll)(n); i++)
#define REPD(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=a; (ll)(b)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
ll a, b, x;
bool chk(ld mid, ll op){
    //cout << a*b*b*tan(mid*PI/180.0) << '\n';
    if(op){
        return 2*x >= a*b*b*tan(mid*PI/180.0);
    }else{
        return a*a*a*tan((90-mid)*PI/180.0) >= 2*x;
    }
}

int main(){
    cin >> a >> b >> x;
    ll op=1;
    if(a*a*b<2*x){
        x = a*a*b-x;    op=0; 
    }
    ld eps=1e-15, lb=0, ub=90;
    while(eps<ub-lb){
        ld mid=(lb+ub)/2;
        if(chk(mid, op)) lb = mid;
        else ub = mid;
    }

    cout << fixed << setprecision(15) << 90-ub << endl;
}

Measured memory_bytes: 4088
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl 
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl 
#define no cout<<"no"<<endl
#define vec(a,y,x)  vector<vector<char>> a (y,vector<char>(x))
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
const vector<int> dx={1,0,-1,0};
const vector<int> dy={0,1,0,-1};

int main(){
  int X,Y;
  cin>>X>>Y;
  int a,b;
  int d=Y-2*X;
  if(d%2==0 && 0<=d/2 && d/2<=X)
    Yes;
  else
    No;
}

Measured memory_bytes: 3628
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <functional>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
using namespace std;
// #define int long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = (((1<<30)-1)<<1)+1;
const int nINF = 1<<31;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, int> pci;

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

const int N = 110;
int n, a[N];

void bad() {
	cout << -1 << endl;
	exit(0);
}

signed main() {
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(7);
    cin >> n;
    FOR(i, 1, n) cin >> a[i];
    stack<int> ans;
    FOR(i, 1, n) {
    	bool good = false;
    	int id = -1;
    	FORD(j, n-i+1, 1) {
    		if(a[j] == j) {
    			good = true;
    			id = j;
    			break;
    		}
    	}
    	if(!good) bad();
    	ans.push(a[id]);
    	FOR(i, id, n-1) a[i] = a[i+1];
    }
    while(!ans.empty()) {
    	cout << ans.top() << endl;
    	ans.pop();
    }

    return 0;
}

// Easy things to check:
// - LONG LONGS (WA)
// - const int N is correct (WA, RTE)
// - .size()-k underflow (WA, RTE, TLE)
// - small n edge cases (WA)

// Rare mistakes made in the past:
// - division by 0 (WA)
// - integer division (WA)
// - setprecision (WA)
// - INF not big enough using ll (WA)
// - setting max to 0 instead of -INF/min to 0 instead of INF (WA)
// - outputting debug (WA)
// - allocating too much memory (locRTE, MLE)
// - stack size (locRTE)
// - round announcements (WA)
// - multiset::erase (WA)



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int atc=0,oder=0;
  //atcoderatcoderatcoder
  for(int i=0;i<s.size();i++){
    if(s[i]=='0'){
      if(i%2==0){
        oder++;
      }
      else{
        atc++;
      }
    }
    else{
      if(i%2==0){
        atc++;
      }
      else{
       oder++; 
      }
    }
  }
  cout<<min(atc,oder)<<endl;
}

Measured memory_bytes: 512
n = int(input())
s = [list(input())]
for _ in range(n - 1):
    w = list(input())
    t = s[len(s) - 1]
    if t[len(t) - 1] == w[0]:
        if not w in s:
            s.append(w)
if len(s) == n:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
const int N = 50, K = 100;
ll mem[N+2][N+1][K+1];
ll opt(int i, int j, int k, vector<int>& v) {
    ll& ans = mem[i+1][j+1][k];
    if(ans == -1) {
        if(i <= j) {
            ans = max({
                k >= 1 ? v[i] + opt(i + 1, j, k - 1, v) : 0,
                k >= 1 ? v[j] + opt(i, j - 1, k - 1, v) : 0,
                k >= 2 ? opt(i + 1, j, k - 2, v) : 0,
                k >= 2 ? opt(i, j - 1, k - 2, v) : 0
            });
        } else {
            ans = 0;
        }
    }
    return ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    cin >> v;
    memset(mem, -1, sizeof mem);
    ll ans = 0;
    for(int kk = 0; kk <= k; kk++) {
        ans = max(ans, opt(0, n - 1, kk, v));
    }
    cout << ans << endl;
    return 0;
}


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

struct Node{
  int key;
  Node *right, *left, *parent;
};

Node *root, *NIL;

void insert(int k){
  Node *y = NIL;
  Node *x = root;
  Node *z;

  z = (Node *)malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while( x != NIL){
    y = x;
    if( z->key < x->key){
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;
  if(y == NIL){
    root = z;
  } else {
    if (z->key < y->key){
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

bool isExist(int k, Node *x){
  if (x == NIL) return false;
  if(x->key == k) return true;
  else if(k < x->key) isExist(k, x->left);
  else isExist(k, x->right);
}


void inorder(Node *u){
  if (u == NIL) return;
  inorder(u->left);
  cout << " " << u->key;
  inorder(u->right);
}

void preorder(Node *u){
  if (u == NIL) return;
  cout << " " << u->key;
  preorder(u->left);
  preorder(u->right);
}



int main() {
    ios::sync_with_stdio(false);

    int n, x;
    string com;
    cin >> n;
    for(int i=0; i<n; i++){
      cin >> com;
      if(com == "insert"){
        cin >> x;
        insert(x);
      } else if (com == "find") {
        cin >> x;
        isExist(x, root) ? cout << "yes\n" : cout << "no\n";
      } else if (com == "print"){
        inorder(root);
        cout << "\n";
        preorder(root);
        cout << "\n";
      }
    }
    return 0;
}

Measured memory_bytes: 19972
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <tuple>
#include <iomanip>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pa;
const ll MOD = 1e9 + 7;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}
//-----------------------------------------------------------//

int main() {
    init();
    string s;
    cin>>s;
    cout<<count(all(s),'2');
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}

//ここから。
int main(){
    int H,W;
    cin >> H >> W;
    vector<vector<int>> a(H,vector<int> (W));
    vector<vector<int>> ans(0);
    rep(i,H) rep(j,W) cin >> a[i][j];
    int N = 0;
    rep(i,H){
        rep(j,W){
            if(i == H-1 && j == W-1) break;
            if(a[i][j] % 2 == 1 && j == W -1){
                a[i][j]--;
                a[i+1][j]++;
                ans.push_back({i,j,i+1,j});
                N++;
            }else if(a[i][j] %2 == 1){
                a[i][j]--;
                a[i][j + 1]++;
                ans.push_back({i,j,i,j+1});
                N++;
            }
        }
    }
    cout << N << endl;
    int s = ans.size();
    rep(i,s) cout << ans[i][0]+1 << " " << ans[i][1]+1 << " " << ans[i][2]+1 << " " << ans[i][3]+1 << endl;
}

Measured memory_bytes: 11168
Public Class Main
    Public Shared Sub Main(ByVal args() As String)
        Dim H, N As Integer
        Dim arr(2) As String
        arr = Split(Console.ReadLine())
        H = arr(0) : N = arr(1)
        Dim A() As Integer = Array.ConvertAll(Of String, Integer) _
            (Split(Console.ReadLine()), AddressOf Integer.Parse)
        Array.Sort(A)
        Dim accum As Integer = 0
        Dim flg As Boolean = False
        For i As Integer = N - 1 To 0 Step -1
            accum += A(i)
            If H <= accum Then
                flg = True
                Exit For
            End If
        Next
        Console.WriteLine(If(flg, "Yes", "No"))
    End Sub
End Class


Measured memory_bytes: 26324
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<set>
#include<map>

using namespace std;

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

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)
 
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

int main(){
    int a, b, ans=0;
    cin >> a >> b;

    FOR(i, a, b+1){
        vector<int> x(5);
        int n = i;

        for(int j = 0;j < 5;j++){
            x[j] = n % 10;
            n /= 10;
        }

        if((x[0] == x[4]) && (x[1] == x[3])) {
            ans++;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <list>
using namespace std;
string st;
list<char> s;
int main() {
	cin>>st;
	for(int i=0;i<st.length();i++)
		s.push_back(st[i]);
	s.push_back('S');
	for(auto it=s.begin();it!=s.end();)
	{
		if(*it=='T'&&it!=s.begin()&&*(prev(it))=='S')
		{
			auto it1=it;
			it++;
			s.erase(prev(it1));
			s.erase(it1);
		}
		else
			it++;
	}
	cout<<s.size()-1<<endl;
	return 0;
}

Measured memory_bytes: 6660
n = int(input())

flist = [0]*(10**4+10)


def cal(i, j, k):
    return i ** 2+j ** 2 + k ** 2+i*j+j*k+k*i


for i in range(1, 101):
    for j in range(i, 101):
        for k in range(j, 101):
            s = cal(i, j, k)
            if s >= 10**4+5:
                break
            if i == j and j == k:
                flist[s] += 1
            elif i == j:
                flist[s] += 3
            elif j == k:
                flist[s] += 3
            else:
                flist[s] += 6
for i in range(1, n+1):
    print(flist[i])


Measured memory_bytes: 9472
/****************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<pair<int,int> > vpi;
 
const long long MOD = 998244353;
const long long mod = 1000000007;
const long long INF = 10000000000000;
 
#define itn int
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
 
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
 
#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
int main(void){
    ll n,k;cin >> n >> k;
    vector<ll> a(n);for(int i = 0;i < n;i++)cin >> a[i];
    long long x = 0;
    for(int i = 40;i >= 0;i--){
        int c = 0;
        for(int j = 0;j < n;j++){
            c += (a[j] >> i) & 1;
        }
        if(2*c < n and (x | (1LL << i)) <= k) x|= (1LL << i);
    }
    long long ans = 0;
    for(int i = 0;i < n;i++){
        ans += x xor a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024