akhauriyash/Code-Regression huggingface dataset:
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v), std::end(v)
#define REP(i, k) for (decltype(k) i = 0; i < k; i++)
#define LOOP(k) REP (ngtkana_is_a_genius, k)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T, class U> using pair = std::pair<U, T>;
template <class T> using diag_pair = std::pair<T, T>;
template <class... Args> using tuple = std::tuple<Args...>;
template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

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

    i32 n; std::cin >> n;
    i32 N = 2 * n - 1;

    auto cal = [&](auto a) {
        i32 i = n - 2, mid = n - 1, j = n;
        for (; i!=-1 && a.at(i)!=a.at(i+1); i--);
        for (; j!=N  && a.at(j-1)!=a.at(j); j++);
        if (i==-1 && j==N) return a.at(0);
        i32 di = mid - i, dj = j - mid;
        return a.at(di < dj ? i : j);
    };

    vec<i32> a(N);
    for (i32& x: a) std::cin >> x;
    i32 l = 0, r = N;
    while (1 < r - l) {
        i32 c = (l + r) / 2;
        vec<i32> b(N);
        std::transform(ALL(a), b.begin(), [c](i32 x){ return c <= x; });
        (cal(b) ? l : r) = c;
    }
    std::cout << l << '\n';
}


Measured memory_bytes: 2672
/*   ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
                   
                   ঔৣ۝महाकालᴳᵒᵈ۝ঔৣ            
 
 */ 
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template <typename T, typename cmp=less<T>> using oset =tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long 
#define mod 1000000007
#define inf 100000000000000000
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(),_x.end()
#define f first
#define s second
#define pb push_back
void mahakal(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	freopen("error.txt","w",stderr);
	#endif
}
ll G[4001] , R[4001] , B[4001];
int main(){
	//mahakal(),fast;
	ll n ;
	cin>> n ;
	string str ;
	cin>> str ;
	ll ans = 0 ;
	for(ll i=n-1 ; i>=0 ;i--){
		str[i]=='G' ? G[i]=G[i+1]+1 : G[i]=G[i+1];
		str[i]=='B' ? B[i]=B[i+1]+1 : B[i]=B[i+1];
		str[i]=='R' ? R[i]=R[i+1]+1 : R[i]=R[i+1];
	}
	// cerr<<gsum<<" "<<bsum<<" "<<rsum<<endl;
	for(ll i=0;i<n ;i++){
		for(ll j=i+1 ;j<n ; j++){
			if(str[i]==str[j])continue;
			if(str[i]!='B' && str[j]!='B'){
				if(2*j-i<n && str[2*j-i]=='B')ans+=B[j+1]-1;
				else ans += B[j+1];
				
			}
			else if(str[i]!='R' && str[j]!='R'){
				if(2*j-i<n && str[2*j-i]=='R')ans+=R[j+1]-1;
				else ans += R[j+1];
			}
			else if(str[i]!='G' && str[j]!='G'){
				if(2*j-i<n && str[2*j-i]=='G')ans+=G[j+1]-1;
				else ans += G[j+1];
			}
		}
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 3700
function main(input) {
    const args = input.split(/\n/);
    const N = parseInt(args[0], 10),
          cards = args[1].split(' ').map(n => parseInt(n, 10));

    var aSum = 0,
        bSum = 0;

    cards.sort((a, b) => (a < b ? 1 : -1)).forEach((n, i) => {
        (i % 2 === 0)? aSum += n : bSum += n;
    });

    console.log(aSum - bSum);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7500
#include <cstdio>
#include <algorithm>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repd(i,a) for(int i=(a);i>=0;--i)

using ll = long long;

constexpr int MAX_N = 100000;

ll N, C;
ll x[MAX_N], v[MAX_N];
ll c[MAX_N], cc[MAX_N];
ll ans = 0;

int main()
{
  scanf( "%lld%lld", &N, &C );
  rep( i, N )
    scanf( "%lld%lld", x+i, v+i );

  ll sum = 0, ma = 0;
  rep( i, N )
  {
    sum += v[i];
    ma = std::max( ma, sum-x[i] );
    c[i] = ma;
  }

  sum = 0;
  ll maC = 0;  
  repd( i, N-1 )
  {
    sum += v[i];
    maC = std::max( maC, sum-2*(C-x[i]) );
    cc[i] = maC;
  }

  ans = std::max( ans, c[N-1] );
  ans = std::max( ans, cc[0] );

  repi( i, 1, N )
    ans = std::max( ans, c[i-1]+cc[i] );

  sum = ma = 0;
  rep( i, N )
  {
    sum += v[i];
    ma = std::max( ma, sum-2*x[i] );
    c[i] = ma;
  }

  sum = maC = 0;  
  repd( i, N-1 )
  {
    sum += v[i];
    maC = std::max( maC, sum-(C-x[i]) );
    cc[i] = maC;
  }

  ans = std::max( ans, c[N-1] );
  ans = std::max( ans, cc[0] );

  repi( i, 1, N )
    ans = std::max( ans, c[i-1]+cc[i] );

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

  return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
    ll d,t,s; cin >> d >> t >> s;
    Ans(s*t >= d);
    return 0;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

const ll MOD = 998244353;

ll power(ll x, ll e) {
  ll v = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) {
      v = v * x % MOD;
    }
    x = x * x % MOD;
  }
  return v;
}

ll inverse(ll x) { return power(x, MOD - 2); }

vector<ll> fact, factInv;
void initFact(int N) {
  fact.resize(N + 1);
  factInv.resize(N + 1);
  fact[0] = 1;
  for (int i = 1; i <= N; i++) {
    fact[i] = fact[i - 1] * i % MOD;
  }
  factInv[N] = inverse(fact[N]);
  for (int i = N - 1; i >= 0; i--) {
    factInv[i] = factInv[i + 1] * (i + 1) % MOD;
  }
}

ll choose(int n, int k) {
  if (k > n) {
    return 0;
  } else {
    return fact[n] * factInv[k] % MOD * factInv[n - k] % MOD;
  }
}

ll multiChoose(int n, int k) {
  if (n == 0 && k == 0) {
    return 1;
  } else {
    return choose(n + k - 1, k);
  }
}

int main() {
  initFact(300010);
  int N;
  ll A, B, K;
  while (cin >> N >> A >> B >> K) {
    ll res = 0;
    for (int a = 0; a <= N; a++) {
      if (a * A <= K && (K - a * A) % B == 0) {
        int b = (K - a * A) / B;
        res = (res + choose(N, a) * choose(N, b) % MOD) % MOD;
      }
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; ++i)
#define RREP(i, n) for (int i = n; 0 <= i; --i)
#define FOR(i, start, end) for (int i = start; i < end; ++i)
#define RFOR(i, start, end) for (int i = start; end <= i; --i)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
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() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N; cin >> N;
    string tmp;
    string s[N]; REP(i, N) {
        cin >> tmp;
        sort(tmp.begin(), tmp.end());
        s[i] = tmp;
    }

    unordered_set<string> buf;
    unordered_map<string, ll> ansmap;
    for (ll i = 0; i<N; ++i) {
        if (buf.find(s[i])==buf.end())
            buf.insert(s[i]);
        else
            ansmap[s[i]] += 1;
    }
    ll ans = 0;
    for (auto it = ansmap.begin(); it != ansmap.end(); ++it) {
        ans += it->second * (it->second+1) / 2;
    }
    cout << ans << '\n';
    return 0;
}



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

int main() {
  int n;
  cin >> n;
  vector<ll>a(n);
  rep(i,0,n) cin >> a[i];
  sort(a.begin(),a.end());
  vector<ll>sum(n);
  sum[0] = a[0];
  rep(i,1,n) sum[i] = a[i]+sum[i-1];
  reverse(a.begin(),a.end());
  reverse(sum.begin(),sum.end());
  int ans = 1;
  rep(i,1,n){
    if(sum[i]*2 >= a[i-1]) ans++;
    else break;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(long long i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define infy 2e18
#define five 100005;
#define six 1000005;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
//___________________________________________________________________________________________________________________________________________________________
int n;
vct2 mul(vct2 a,vct2 b)
{
       vct2 xx = a;
       fri(i,0,n)
       {
              fri(j,0,n)
              {
                     xx[i][j] = 0;
                     fri(k,0,n)
                     {
                            xx[i][j] += (a[i][k]*b[k][j])%mod;
                            xx[i][j] %= mod;
                     }
              }
       }
       return xx;
}
int main()
{
       ll k;
       cin>>n>>k;
       vct2 a;
       a.rz(n);
       fri(i,0,n){
              a[i].rz(n);
              fri(j,0,n){
                     cin>>a[i][j];
              }
       }
       vct2 id = a;
       vct2 ans = a;
       fri(i,0,n){
              fri(j,0,n){
                     id[i][j] = 0;
              }
              id[i][i] = 1;
       }
       ans = id;
       while(k)
       {
              if(k%2){
                     ans = mul(ans,a);
              }
              a = mul(a,a);
              k /= 2;
       }
       ll answ = 0;
       fri(i,0,n){
              fri(j,0,n){
                     answ += ans[i][j];
                     answ %= mod;
              }
       }
       cout<<answ<<endl;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(){
	int array[3];
	for(int i = 0; i < 3; i++) scanf("%d",&array[i]);
	for(int i = 2; i > 0; i--){
		for(int j = 0; j < i; j++){
			if(array[j] > array[j+1])swap(array[j],array[j+1]);
		}
	}
	printf("%d %d %d\n",array[0],array[1],array[2]);
}


Measured memory_bytes: 2712
#define _USE_MATH_DEFINES

#include <iostream>	//cin, cout
#include <vector>	//vector
#include <algorithm> //sort,min,max,count
#include <string>	//string,getline, to_string
#include <ios>		//fixed
#include <iomanip>	//setprecision
#include <utility> //swap, pair
#include <cstdlib>	//abs(int)
#include <cmath>	//sqrt,ceil,M_PI, pow, sin
#include <sstream>	//stringstream,getline
#include <numeric>	//gcd, accumlate
#include <deque>	//deque
#include <random>	//randam_device

using namespace std;
constexpr long long int D_MOD = 1000000007;

int main() {

	string S;
	cin >> S;

	if (S[S.length() - 1] == 's') {
		S = S + "es";
	}
	else {
		S.push_back('s');
	}

	cout << S << endl;

	return 0;

}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

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

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

template<typename T> bool chmin(T &a,const T b){if(a>b){a=b; return true;}return false;}
template<typename T> bool chmax(T &a,const T b){if(a<b){a=b; return true;}return false;}



int main(){
    int N, M, R; cin >> N >> M >> R;
    vi r(R);
    for(auto &x : r){
        cin >> x;
        x--;
    }
    vii dist(N, vi(N, INF));
    for(int i=0; i<N; i++) dist[i][i]=0;
    for(int i=0; i<M; i++){
        int a, b, c; cin >> a >> b >> c;
        a--, b--;
        dist[a][b]=c;
        dist[b][a]=c;
    }
    for(int k=0; k<N; k++){
        for(int i=0; i<N; i++){
            for(int j=0; j<N; j++){
                chmin(dist[i][j], dist[i][k]+dist[k][j]);
            }
        }
    }

    vi ord(R);
    ll ans=LINF;
    for(int i=0; i<R; i++) ord[i]=r[i];
    sort(all(ord));
    do{
        ll sum=0;
        for(int i=0; i<R-1; i++){
            sum+=dist[ord[i]][ord[i+1]];
        }
        chmin(ans, sum);
    }while(next_permutation(all(ord)));

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

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

int main() {
    int a, b, k, ans, temp = 0;
    cin >> a >> b >> k;
    int t = min(a, b);
    while(true) {
        if(a % t == 0 && b % t == 0) temp++;
        if(temp == k) {
            ans = t;
            break;
        }
        t--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using ll = long long;
using ull = unsigned long long;
int main()
{
  //
  std::string s;
  std::cin >> s;
  ull n = 0;

  for (ull i = 0; i < s.length(); ++i) {
    char c = s.at(i);
    n += std::atoi(&c);
  }
  if (n % 9 == 0) {
    std::puts("Yes");
  } else {
    std::puts("No");
  }
  return 0;
}


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

int main() {
    int a,b;
    cin >> a >> b;
    string s;
    cin >> s;
    int count=0;
    for(int i=0;i<a+b+1;i++){
        if(i==a){
            if(s.at(i)=='-'){
                count++;
            }
        }
        else{
            for(char c='0';c<='9';c++){
                if(s.at(i)==c){
                    count++;
                }
            }
        }
    }
    cout << (count==a+b+1?"Yes":"No") << endl;
}

Measured memory_bytes: 256
A, B, C, D = [int(input()) for i in range(4)]
ans=0
for i in range(A+1):
    for j in range(B+1):
        for k in range(C+1):
            tmp = i * 500 + j * 100 +50 *k
            if(tmp == D):
                ans += 1
print(ans)

Measured memory_bytes: 3064
'use strict';
const p = s => console.log(s);
// let a,b,c,d;
// [a,b,c,d] = input[0].trim().split(" ").map(i => parseInt(i));

function main(input) {
  let S = input[0].trim().split("");
  let T = input[1].trim().split("");

  let result = false;

  for(let i = 0; i < S.length; i++) {
    if(S[i] !== T[i]) {
      result = true;
      break;
    }
  }
  if(T.length !== S.length +1) {
    result = true;
  }

  if(!result) {
    p('Yes');
  } else {
    p('No');
  }

}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));


Measured memory_bytes: 29628
#include<stdio.h>

int main(void) {
	int d[10000], a, b, i=0, j, flag = 1;
	char c;
	
	do{
		scanf("%d %c %d", &a, &c, &b);
		
		switch(c) {
		case '+':
			d[i] = a + b;
			break;
		case '-':
			d[i] = a - b;
			break;
		case '*':
			d[i] = a * b;
			break;
		case '/':
			d[i] = a / b;
			break;
		case '?':
			flag = 0;
			break;
		}
		
		i++;
	} while(flag);
	
	for(j = 0; j < i-1; j++) {
		printf("%d\n", d[j]);
	}	
	return 0;
}

Measured memory_bytes: 608
//#include <bits/stdc++.h>
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
#include <map>
#include <queue>
#include <cctype>
using namespace std;
using ll = long long;
const int mod = 1000000007;

ll gcd(ll a, ll b){return b ? gcd(b,a%b) : a;};//最大公約数
ll lcm(ll a, ll b){return a*b/gcd(a,b);};//最小公倍数
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//typedef pair<string,string> P;
//double dat[100][100];
//int dp[6][1010];//動的計画法
//int prime[100001];
//char str[1010][1010];
//typedef pair<ll,ll> A;
//vector<A> pc;
//int ABS(int a){return max(a,-a);}
//ll a[100000];
//ll dom[100001];

int main(){
  int n;
  cin>>n;
  string s;
  string t;
  cin>>s>>t;
  vector<char> ans;
  for(int i=0;i<n;i++){
    ans.push_back(s[i]);
    ans.push_back(t[i]);
  }
  for(int i=0;i<2*n;i++){
    cout<<ans[i];
  }
   return 0;
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void answer1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void answer2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void answer3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void answer(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i, j;
  ll k;
  //cin >> n;
  //l a, b, c,d,e;
  //cin >> a >> b >> c >> d;
  string s; cin >> s;
  cin >> k;
  ll result = 1;
  bool judge = true;
  set<string> t;
  string buf;
  for(i=0;i<s.size();i++){
    buf = s[i];
    t.insert(buf);
    for(j=1;j+i<s.size()&&j<k;j++){
      buf.push_back(s[i+j]);
      t.insert(buf);
    }
  }
  auto itr = t.begin();
  for(i=0;i<k-1;i++,itr++){
    //cout<<*itr<<endl;
  }
  cout << *itr << endl;



  return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
#define forinc(i,a,b) for(int i=a;i<=b;i++)
#define fordec(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define int long long
#define fi first
#define se second
#define getbit(i,x) ((x>>i)&1ll)


const int maxn=22,N=2100000,mod=1e9+7;
int a[maxn][maxn],f[maxn][N],n;

main()
{
    cin>>n;
    forinc(i,1,n) forinc(j,1,n) cin>>a[i][j];
    int tar=(1ll<<n)-1;
    f[0][0]=1;
    forinc(i,1,n)
    forinc(j,1,tar)
    {
        int k=__builtin_popcount(j);
        if(k==i)
        {
            forinc(t,1,n) if(getbit(t-1,j)&&a[i][t]==1)
            {
                int z=j-(1ll<<(t-1));
                f[i][j]=(f[i][j]+f[i-1][z])%mod;
            }
        }
    }
    cout<<f[n][tar];
}


Measured memory_bytes: 309504
#include <algorithm>
#include <array>
#include <climits> // INT_MAX, LONG_MAX, LLONG_MAX, UINT_MAX, ULONG_MAX, ULLONG_MAX
#include <cmath>
#include <cstdint>
#include <cstring> // memset
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
#define LOG(x) cout << #x << " = " << (x) << endl
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;

int main() {
    string s2, t;
    cin >> s2 >> t;

    int lastIndex = -1;

    vector<int> indexes;
    
    REP(i, s2.size()) {
        if (s2[i] == t[0]) {
            indexes.push_back(0);
        } else if (s2[i] == '?') {
            indexes.push_back(0);
        }

        for (int j = 0; j < indexes.size(); j++) {
            if (indexes[j] == -1)
                continue;

            if (s2[i] == t[indexes[j]]) {
                indexes[j]++;
            } else if (s2[i] == '?') {
                indexes[j]++;
            } else {
                indexes[j] = -1;
            }

            if (indexes[j] == (int)t.size()) {
                lastIndex = i - t.size() + 1;
            }
        }
    }

    if (lastIndex >= 0) {
        REP(i, s2.size()) {
            if (s2[i] == '?')
                s2[i] = 'a';
        }
        s2.replace(lastIndex, t.size(), t);
        cout << s2 << endl;
    } else
        cout << "UNRESTORABLE" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
#include <numeric>
#include <cmath>



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

using namespace std;


int main() {
    int x,y;
    cin >> x >> y ;
    cout << x + y/2 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int (i) = (a);(i) < (b);i++)
#define REP(i,n) FOR(i,0,n)
typedef long long ll;
const ll MOD = 998244353;

ll POW(ll x,ll y){
    ll res = 1;
    for(int i = 0;i < y;i++){
        res *= x;
        res %= MOD;
    }
    return res;
}

int main(){
    ll n;
    cin >> n;
    vector<ll> d(n,0);
    vector<ll> D(n);
    REP(i,n){
        cin >> D[i];
        d[D[i]]++;
    }
    int s = 1;
    ll ans = 1;
    bool judge = true;
    if(D[0] != 0 || d[0] != 1){
        cout << 0 << endl;
        return 0;
    }
    for(int i = 1;i < n;i++){
        ans *= POW(d[i-1],d[i]);
        ans %= MOD;
    }
    cout << ans << endl;
    //cin >> n
}

Measured memory_bytes: 1792
import java.util.*;

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

	class Pair{
		int to;
		int w;
		Pair(int to, int w){
			this.to=to;
			this.w=w;
		}
	}

	int N;
	ArrayList<ArrayList<Pair>> g;
	public void run() {
		Scanner sc = new Scanner(System.in);
		N=sc.nextInt();
		g = new ArrayList<>();
		for(int i=0; i<N; i++) {
			g.add(new ArrayList<Pair>());
		}
		for(int i=0; i<N-1; i++) {
			int v1 = sc.nextInt();
			int v2 = sc.nextInt();
			v1--;
			v2--;
			int w = sc.nextInt();
			g.get(v1).add(new Pair(v2, w));
			g.get(v2).add(new Pair(v1, w));
		}
		bfs(0);
		sc.close();
	}

	private void bfs(int r) {
		boolean used[] = new boolean[N];
		int color[] = new int[N];
		ArrayDeque<Integer> q = new ArrayDeque<Integer>();
		q.add(r);
		used[r]=true;
		color[r]=1;

		while(!q.isEmpty()) {
			int u = q.poll();
			for(int i=0; i<g.get(u).size(); i++) {
				Pair p = g.get(u).get(i);
				if(used[p.to]) continue;
				if(p.w % 2 == 0){
					color[p.to] = color[u];
				}else {
					color[p.to] = 1 - color[u];
				}
				used[p.to]=true;
				q.add(p.to);
			}
		}

		for(int i=0; i<N; i++) {
			System.out.println(color[i]);
		}
	}
}


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

int main(void) {
    string s;
    cin >> s;

    string ans;
    for (int i=0; i<s.size(); i++) {
        if (i % 2 == 0) ans += s[i];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3564
#!/usr/bin/env python3
import sys


def solve(n: int, p: "List[int]"):
    count = 0
    for i in range(1, n-1):
        part = p[i-1:i+2]
        if p[i] == max(part) or p[i] == min(part):
            continue
        count += 1
    print(count)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    p = [ int(next(tokens)) for _ in range(n) ]  # type: "List[int]"
    solve(n, p)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
int main(){
	ll n,a,b,ans=0;scanf("%lld %lld %lld",&n,&a,&b);
	vector<ll> x(n);
	rep(i,n)scanf("%lld",&x[i]);
	rep(i,n-1)ans+=((a*(x[i+1]-x[i])<b)?a*(x[i+1]-x[i]):b);
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
#include <array>
#include <ctype.h> // isdigit
#include <cassert>
using namespace std;
#define MAX_COUNT 1000


int rec_min(int G, vector<int> &p, vector<int> &c, vector<int> &p_nums){
  assert(p_nums.size() > 0); //a solution always exists.
  int min_count = MAX_COUNT;
  int count = MAX_COUNT;
  for(int i=0; i<p_nums.size(); i++){

    int p_num = p_nums[i];
    p_nums.erase(p_nums.begin() + i);

    if(G <= p[p_num]*100*(p_num+1))
      count = ceil(G/(100.0*(p_num+1)));
    else if(G <= p[p_num]*100*(p_num+1) + c[p_num])
      count = p[p_num];
    else
      count = p[p_num] + rec_min(G - p[p_num]*100*(p_num+1) - c[p_num], p, c, p_nums);
    
    min_count = min(min_count, count);
    p_nums.insert(p_nums.begin() + i, p_num);

  }
  return min_count;
}


int main(){

  int D, G; cin >> D >> G;
  vector<int> p(D), c(D);
  for(int i=0; i<D; i++){
    cin >> p[i] >> c[i];
  }

  vector<int> p_nums;
  for(int i=0; i<D; i++){
    p_nums.push_back(i);
  }

  cout << rec_min(G, p, c, p_nums) << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

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

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

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

signed main(){
	string s;
	cin >> s;
	int n = s.length(),ans = 0,b = 0;
	for(int i = 0;i < n;i++){
		if(s[i] == 'B') b++;
		else ans += b;
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
import Control.Monad
main = do
    getLine
    s <- getLine
    print $ length [()| pin <- replicateM 3 "0123456789", check pin s]

check (a:b:c:_) s = (c `elem`) . chk b $ chk a s
    where chk k t = case dropWhile (/= k) t of
                        [] -> []
                        (x:xs) -> xs

Measured memory_bytes: 2428
#include<stdio.h>
#include<iostream>

using namespace std;

int A,B;
string S;
int main(){
    cin >> A >> B >> S;
    int l = S.length();
    bool flag = true;
    if( A + B + 1 != l ) flag = false;
    for(int i=0; i<l; i++){
        if( i == A ) {if( S[A] != '-') flag = false;}
        else if( S[i] - '0' < 0 || 9 < S[i] - '0'  ) flag = false;
    }
    cout << ( flag ? "Yes":"No") << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        boolean end = false;
        for (int i = 1; i <= 100; i++) {
            if (a * i % b == c) {
                System.out.println("YES");
                end = true;
                break;
            }
        }
        if (end == false) {
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 23764
#include <iostream>
using namespace std;
using ll = long long;
int main() {
    ll A,B,C,K;cin>>A>>B>>C>>K;
    // A = (B+C)
    // B = (A+C)
    // A-B = B-A
    if(K&1){
        cout << B - A << '\n';
    } else {
        cout << A - B << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

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

MOD = 10 ** 9 + 7
def pow(a, b):
    c = 1
    while b > 1:
        if b % 2 == 0:
            b //= 2
            a *= a
        else:
            b -= 1
            c *= a
        a %= MOD
        c %= MOD
    return a * c
print(pow(m, n) % MOD)





Measured memory_bytes: 6088
#define DEBUGGING  // Enables DEBUG macro.
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifndef DEBUGGING
#define debug(...)
#define DEBUG(...)
#else
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                     \
  do {                                 \
    cerr << " (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ": ";      \
    _debug(__VA_ARGS__);               \
    cerr << endl;                      \
  } while (0)
#endif
// auto mod int

const i64 MOD = 1'000'000'007;

struct mint {
  long long x;
  mint(long long 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(long long 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, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(100001, -1);
  int k1 = -1, k2 = -1;
  REP(i, n + 1) {
    int x;
    cin >> x;
    if (a[x] != -1) {
      k1 = a[x];
      k2 = i;
      break;
    }
    a[x] = i;
  }

  mint num = n + 1;
  mint dinv = mint(1).inv();
  mint num2 = 1;
  mint dinv2 = mint(1).inv();
  REP(i, n + 1) {
    mint allc = num * dinv;  // comb(n+1, i+1)
    mint dupc = num2 * dinv2;
    cout << (allc - dupc) << '\n';
    num *= (n - i);
    num2 *= (n + k1 - k2 - i);
    dinv *= mint(i + 2).inv();
    dinv2 *= mint(i + 1).inv();
  }
}

Measured memory_bytes: 1664
/*******************************\
   Name:    REAJUL HAQUE REAYZ  |
   School:  COMILLA UNIVERSITY  |
            CSE (5TH BATCH)     |
********************************/
#include<bits/stdc++.h>
#define pi acos(-1.0)
#define pb push_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define mem(x,y) memset(x , y , sizeof(x))
using namespace std;
typedef long long ll;
typedef pair < int , int > pii;
typedef pair < ll , ll > pll;
const ll MOD = 1000000007;
const int MAX = 200005;

ll n, a[MAX], b[MAX];
int call(int x, int y)
{
    ll sum=b[y]-b[x-1];
    sum=(sum+1)/2;
    sum=sum+b[x-1];
    ll low=x, high=y;
    while(low<high){
        ll mid=(low+high+1)/2;
        if(b[mid]<=sum) low=mid;
        else high=mid-1;
    }
    ll p = abs((b[low]-b[x-1])-(b[y]-b[low]));
    ll q = abs((b[low+1]-b[x-1])-(b[y]-b[low+1]));
    if(p<=q) return low;
    else return low+1;
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>n;
    for(ll i=1; i<=n; i++) cin>>a[i];
    for(ll i=1; i<=n; i++) b[i]=a[i]+b[i-1];
    ll ans=1e18;
    for(ll j=2; j<=n-2; j++){
        ll i = call(1, j);
        ll k = call(j+1, n);
        ll arr[4];
        arr[0]=b[i];
        arr[1]=b[j]-b[i];
        arr[2]=b[k]-b[j];
        arr[3]=b[n]-b[k];
        sort(arr,arr+4);
        ans = min(ans, arr[3]-arr[0]);
    }
    cout<<ans<<endl;
	return 0;
}


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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;

  while(true){
    c-=b;
    if(c<=0) {puts("Yes");break;}
    a-=d;
    if(a<=0) {puts("No");break;}
  }
}

Measured memory_bytes: 3644
import math

N = int(input())
A = list(map(int, input().split()))

g = 0
for a in A:
    g = math.gcd(g, a)
if g != 1:
    print('not coprime')
    exit()

is_prime = [1] * 1000001
D = [0] * 1000001

for i in range(2, 1001):
    if is_prime[i]:
        D[i] = i
        j = 2 * i
        while j <= 1000000:
            if is_prime[j]:
                D[j] = i
                is_prime[j] = 0
            j += i
for i in range(1001, 1000001):
    if is_prime[i]:
        D[i] = i

count = [0] * 1000001
for a in A:
    k = a
    pre = 0
    while k != 1:
        if pre != D[k]:
            count[D[k]] += 1
            if count[D[k]] == 2:
                print('setwise coprime')
                exit()
        pre = D[k]
        k = int(k / D[k])
print('pairwise coprime')


Measured memory_bytes: 134532
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, s, e) for (int i = s; i < e; i++)
#define FOE(i, s, e) for (int i = s; i <= e; i++)
#define FOD(i, s, e) for (int i = s; i >= e; i--)
#define SET(a, e) memset(a, e, sizeof(a))

int n, m, a[305][305], cnt[305], p[305];
bool ban[305];

bool check(int tar) {
	
	SET(cnt, 0); SET(p, 0); SET(ban, 0);
	FOR(i, 0, n) cnt[a[i][0]]++;
	
	while (*max_element(cnt + 1, cnt + m + 1) > tar) {
		int mx = max_element(cnt + 1, cnt + m + 1) - cnt;
		ban[mx] = 1;
		FOR(i, 0, n) {
			cnt[a[i][p[i]]]--;
			while (ban[a[i][p[i]]]) p[i]++;
			if (p[i] >= m) return 0;
			cnt[a[i][p[i]]]++;
		}
	}
	
	return 1;
}

int main () {
	
	scanf("%d%d", &n, &m);
	
	FOR(i, 0, n) 
		FOR(j, 0, m) scanf("%d", &a[i][j]);
	
	int lo = 0, hi = n;
	
	while (lo < hi - 1) {
		int mid = (lo + hi) >> 1;
		
		if (check(mid)) hi = mid;
		else lo = mid;	
	}
	
	printf("%d\n", hi);
	
	return 0;	
}

Measured memory_bytes: 640
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



import bisect
from math import gcd
n = int(input())
l = [None] * n
for i in range(n):
    a,b = map(int, input().split())
    g = gcd(a,b)
    if g==0:
        g = 1
    l[i] = (a//g, b//g)

l.sort()
M = 1000000007
seen = [False] * n
vals = []

def sub(item):
    item1 = (item[1], -item[0])
    item2 = (-item[1], item[0])
    tmp = None
    count = 0
    li = bisect.bisect_left(l, item1)
    ri = bisect.bisect_right(l, item1)
    count += (ri-li)
    for v in range(li, ri):
        seen[v] = True
    if ri>li:
        tmp = l[li]
        
    li = bisect.bisect_left(l, item2)
    ri = bisect.bisect_right(l, item2)
    count += (ri-li)
    for v in range(li, ri):
        seen[v] = True
    if ri>li:
        tmp = l[li]
    
    return count, tmp
zcount = 0
for i,item in enumerate(l):
    if seen[i]:
        continue
    elif item==(0,0):
        zcount += 1
        continue
    count,tmp = sub(item)
    if count>0:
        count2, tmp = sub(tmp)
        vals.append((pow(2,count,M)+pow(2,count2,M)-1)%M)
    else:
        vals.append(2)
ans = 1
for v in vals:
    ans *= v
    ans %= M
ans -= 1
ans = (ans+zcount) % M
print(ans)

Measured memory_bytes: 93512
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
#define inf 100000000/*10^8*/

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



int main(){
    char s[100001];cin>>s;
    int len=strlen(s);
    int ans;
    if(len%2==0){
        int left=len/2-1,right=left+1,pos=left;
        ans=len/2;
        while(left>=0){
            if(s[left]==s[right]&&s[left]==s[pos]){
                ans++;
                left--;
                right++;
            }else{
                break;
            }
        }
    }else{
        int left=len/2-1,right=left+2,pos=left;
        ans=len/2+1;
        if(s[left]==s[left+1]&&s[left+1]==s[left+2]){
            ans++;
            left--;
            right++;
            while(left>=0){
                if(s[left]==s[right]&&s[left]==s[pos]){
                    ans++;
                    left--;
                    right++;
                }else{
                    break;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define SZ(n) (int)(n).size()
#define ALL(n) (n).begin(), (n).end()
using namespace std;
typedef long long LL;
typedef vector<int> VI;

int main() {
	int n;
	cin >> n;
	VI a;
	REP(i, n) {
		int t;
		cin >> t;
		a.push_back(t);
	}
	sort(a.begin(), a.end(), greater<int>());
	VI ans;
	for (int i = 0; i < SZ(a) - 1; ++i) {
		if (a[i] == a[i + 1]) {
			ans.push_back(a[i]);
			i++;
		}
	}
	if (SZ(ans) < 2) cout << 0 << endl;
	else cout << 1LL * ans[0] * ans[1] << endl;
	return 0;
}


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

int main()
{
    int N, H1, C = 1;
    cin >> N >> H1;
    vector<int> H(N);
    for (int i = 1; i < N; i++)
    {
        cin >> H.at(i);
        if (H.at(i) >= H1)
        {
            C++;
            H1 = H.at(i);
        }
    }
    cout << C << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

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

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

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

    vl H(N + 1);
    rep(i, N) cin >> H[i + 1];

    vvc<ll> dp(N + 2, vl(N + 2, INF));
    dp[0][0] = 0;

    ll ans = INF;
    if (N == K) ans = 0;
    // dp[i][j] iを最後に残し、j箇所残してある (K個以下消せる -> 残すのはN-K個以上)
    repe(i, 1, N + 1) {
        // j箇所残してある
        repe(j, 1, i + 1) {
            rep(k, i) {
                chmin(dp[i][j], dp[k][j - 1] + max(0ll, H[i] - H[k]));
            }
            // これ以降Kで調整できるなら解候補
            if (j >= N - K) chmin(ans, dp[i][j]);
        }
    }

    cout << ans << endl;
}

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

int main()
{
    int n; 
    cin >> n;
    vector<int> p(n);
    for(int i=0; i<n; i++) cin >> p[i];

    int index = 1;
    int min = p[0];
    int ans = 1;
    while(1){
        if(index==n) break;
        if(min > p[index]){
            min = p[index];
            ans++;
        }
        index++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4032
from collections import deque

def main():
    def int_0(num):
        return int(num) - 1

    N, K = map(int, input().split())
    A = tuple(map(int_0, input().split()))
    
    # dfs
    INF = 10 ** 18
    visited = [False] * N
    dist = [INF] * N
    info  = {}
    def dfs(s):
        stack = deque()
        stack.append(s)
        visited[s] = True
        dist[s] = 0
        while stack:
            now = stack.pop()
            visited[now] = True
            nv = A[now]
            if visited[nv] == True:
                info["start"] = nv
                info["length"] = dist[now] - dist[nv] + 1
                info["f"] = dist[nv]
                break
            else:
                dist[nv] = dist[now] + 1
                stack.append(nv)
    dfs(0)

    if K <= N:
        now = 0
        for _ in range(K):
            now = A[now]
        print(now+1)
        exit()

    K -= info["f"]
    K %= info["length"]

    now = info["start"]
    for _ in range(K):
        now = A[now]
    print(now+1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 32680
#include <stdio.h>

int main(void)
{
  int n;
  scanf("%d", &n);
  int a[n + 1], order[n + 1];
  for (int i = 1; i <= n; i++){
    scanf("%d", &a[i]);
  }
  
  for (int i = 1; i <= n; i++){
    order[a[i]] = i;
  }
  for (int i = 1; i < n; i++){
    printf("%d ", order[i]);
  }
  printf("%d", order[n]);
  return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int n=s.size();
    int m=1<<(n-1);// 2的n-1次方
    long long ans=0;
    for(int i=0;i<m;i++)
    {
        long long t=s[0]-'0';
        for(int j=0;j<n;j++)
        {
            if(j==n-1||i&1<<j) 
            {
                ans+=t;
                t=0;
                if(j==n-1)  break;
            }
            t*=10;
            t+=s[j+1]-'0';
        }
    }
    cout<<ans<<endl;
}


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

typedef long long ll;

#define pb push_back
#define MS(x,y) memset((x),(y),sizeof((x)))
#define mn 1000000

using namespace std;

int n;
int niza[100001][3];
int dp[100001][3];

int solve (int i, int last) {
    if (i >= n) return 0;
    if (dp[i][last] != -1) return dp[i][last];

    int ret = 0;

    if (last != 0) ret = max(ret, niza[i][0]+solve(i+1,0));
    if (last != 1) ret = max(ret, niza[i][1]+solve(i+1,1));
    if (last != 2) ret = max(ret, niza[i][2]+solve(i+1,2));

    return dp[i][last] = ret;
}

int main()
{
    #if LOCAL_DEBUG
        fstream cin("in.txt");
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n;

    for (int i = 0; i<n; i++) cin>>niza[i][0]>>niza[i][1]>>niza[i][2];

    MS(dp,-1);

    int res1 = niza[0][0]+solve(1,0);
    int res2 = niza[0][1]+solve(1,1);
    int res3 = niza[0][2]+solve(1,2);

    cout<<max(res1, max(res2, res3))<<endl;

    return 0;
}


Measured memory_bytes: 7296
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

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

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    cout << (n + max(h, w) - 1) / max(h, w) << endl;
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*************** using variables ***************/
int n;
int c[505], s[505], f[505];
/**********************************************/

int main(){
    cin >> n;

    REP(i, n-1){
        cin >> c[i] >> s[i] >> f[i]; 
    }

    REP(i, n-1){
        LL time = 0;
        FOR(j, i, n-1){
            if(time <= s[j]){
                time = s[j];
            }else{
                int num = s[j];
                int itr = 1;
                while(time > num){
                    num = s[j] + f[j]*itr;
                    itr++;
                }
                time = num;
            } 
            time += c[j];
        }
        cout << time << endl;
    }
    cout << "0" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define f(i,n) for(int i=0;i<n;i++)
#define INF INT_MAX
#define LINF LLONG_MAX
#define mod 1000000007
#define pie 3.141592653589793238462643383279
#define P pair<int,int>
#define prique priority_queue
#define F first
#define S second
using namespace std;
signed main(){
	int a,b;
	cin>>a>>b;
	if(a%b) cout<<a<<endl;
	else cout<<-1<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin>>s;
    bool cnt[30];
    for(int i=0;i<30;i++)cnt[i]=false;
    for(auto c:s){
        cnt[c-'a']=true;
    }
    if(s.size()!=26){
        for(int i=0;i<26;i++){
            if(!cnt[i]){
                s+=i+'a';
                cout<<s<<endl;
                return 0;
            }
        }
    }
    if(s == "zyxwvutsrqponmlkjihgfedcba") cout<<-1<<endl;
    else{
        string t = s;
        next_permutation(All(s));
        for(int i=0;i<26;i++){
            cout<<s[i];
            if(t[i]!=s[i])break;
        }
        cout<<endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define PI 3.141592653589793238462643383279

int a,b,c,d;

void change(int *x, int *y){
	int z;
	z = *x;
	*x = *y;
	*y = z;
}
int compare_int(const void *a, const void *b){
	return *(int*)a - *(int*)b;
}

int main(void){
	scanf("%d %d %d %d", &a, &b,&c, &d );
	
	if( abs(a - c) <= d || ( abs(a-b)<=d && abs(b-c)<=d ) )	printf("Yes");
	else	printf("No"); 
	
	return 0;
}

Measured memory_bytes: 128