akhauriyash/Code-Regression huggingface dataset:
class Solver
  def solve
    n, k = gets.chop.split.map(&:to_i)

    h = Array.new(100100, 0)
    x = gets.chop.split.map(&:to_i)
    n.times do |i|
      h[i] = x[i]
    end

    dp = Array.new(100100, 1<<60)
    dp[0] = 0

    n.times do |i|
      k.times do |kk|
        j = kk + 1
        v = dp[i] + (h[i] - h[i+j]).abs
        dp[i+j] = v if dp[i+j] > v
      end
    end

    puts dp[n-1]
  end
end

Solver.new.solve

Measured memory_bytes: 11940
from functools import lru_cache
@lru_cache(maxsize=None)

def Fib(n):
    if n==0:
        return 1
    elif n==1:
        return 1
    else:
        return Fib(n-1)+Fib(n-2)
n=int(input())
print(Fib(n))


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

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

    ll n, m;
    cin >> n >> m;

    if (n == 1 && m > 2) cout << m - 2 << '\n';
    else if (m == 1 && n > 2) cout << n - 2 << '\n';
    else cout << (n - 2) * (m - 2) << '\n';
    return 0;
}


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

int main() {
	int64_t a, b, x;
	cin >> a >> b >> x;
	if (a == b) {
		if (a % x == 0) cout << 1;
		else cout << 0;
	}
	else if ((a + (b - a) / x * x) % x == 0 || (a + (b - a) / x * x) % x > b % x) cout << (b - a) / x + 1;
	else cout << (b - a) / x;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

まず、aからa+xまでの数でxで割り切れる数は1個だけである
同様に、aからa+[(b-a)/x]*xまでの数でxで割り切れる数は[(b-a)/x]個だけである
後は、b-aからbまでにxの倍数が含まれるかどうかを調べれば分かる
これは、それぞれをxで割った余りを見ることで、
(a+[(b-a)/x]*x)%x>b%xならばxの倍数が含まれると判定することができる
何故なら、(a+[(b-a)/x]*x)からbまでは連続しているので、もしxの倍数が含まれないならば余りも単調増加するからである
また、(a+[(b-a)/x]*x)==0の時も割り切れるので追加すること
以上、O(1)で解ける数学問題でした
解説pdfのやり方の方が楽かもね
*/

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll ans,al,bl,N;
  vl A,B;
  string S;
  cin >> S;
  N = S.length();
  REP(i,N-1){
    if(S[i] == 'R' && S[i+1] == 'L'){
      A.push_back(i);
    }
    if(S[i] == 'L' && S[i+1] == 'R'){
      B.push_back(i);
    }
  }
  al = A.size();
  bl = B.size();
  vl F(N);
  REP(i,N){
    F[i] = 0;
  }
  if(al == 1){
    F[A[0]] = ceil((double)(A[0]+1)/2)+(ll)(N-1-A[0])/2;
    F[A[0]+1] =N-F[A[0]];
  }else{
  REP(j,al){
    if(j==0){
      F[A[j]] =ceil((double)(A[j]+1)/2)+(ll)(B[j]-A[j])/2;
      F[A[j]+1] =B[j]+1-F[A[j]];
    }else{
      if(j==al-1){
        F[A[j]] =ceil((double)(A[j]-B[j-1])/2)+(ll)(N-1-A[j])/2;
        F[A[j]+1] =N-1-B[j-1]-F[A[j]];
      }else{
        F[A[j]] =ceil((double)(A[j]-B[j-1])/2)+(ll)(B[j]-A[j])/2;
        F[A[j]+1] =B[j]-B[j-1]-F[A[j]];
      }
    }
  }
  }
  REP(i,N){
    cout << F[i] << " ";
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 2420
#include<iostream>


int main() {
	int X = {};
	std::cin >> X;
	//異常値の検知
	if (X < -40	|| X > 40) {
		std::cout << "温度が異常値です" << std::endl;
		return 0;

	}

	//エアコンOn判定
	if (X >= 30) {
		std::cout << "Yes" << std::endl;
		return 0;
	}
	std::cout << "No" << std:: endl;

}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

const ll mod = 1000000007;

int main() {
    ll x, n, ans;
    cin >> x;
    n = (x + 10) / 11;
    if(n * 11 - 5 >= x){
        ans = 2 * n - 1;
    } else {
        ans = 2 * n;
    }
    cout << ans << endl;
    return 0;
}


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

using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }

const ll INFL = 1LL << 62;


class Solver {
  public:
    bool solve() {
        int N; cin >> N;
        vector<ll> A(N); cin >> A;
        vector<ll> acc(N + 1);
        rep(i, N) {
            acc[i + 1] = acc[i] + A[i];
        }
        ll ans = INFL;
        rep(m, N) {
            // [0, m), [m, N)
            if(m - 0 < 2 or N - m < 2) continue;
            ll s1 = acc[m], s2 = acc[N] - s1;

            int lm = lower_bound(begin(acc) + 1, begin(acc) + m + 1, s1 / 2) - begin(acc) - 1;
            int rm = lower_bound(begin(acc) + m + 1, end(acc), s1 + s2 / 2) - begin(acc) - 1;
            assert(0 <= lm and lm <= m);
            assert(m <= rm and rm <= N);
            repeat(i, max(0, lm - 5), min(lm + 5, m)) {
                repeat(j, max(m, rm - 5), min(rm + 5, N)) {
                    // [0, i) [i, m) [m, j) [j, N)
                    if(i - 0 < 1 or m - i < 1 or j - m < 1 or N - j < 1) continue;
                    assert(0 < i and i < m and m < j and j < N);
                    auto v = { acc[i], acc[m] - acc[i], acc[j] - acc[m], acc[N] - acc[j] };
                    set_min(ans, abs(max(v) - min(v)));
                }
            }
        }
        assert(ans < INFL);
        cout << ans << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;

const int INF = 1e9 + 5;
const int MOD = 1e9 + 7;

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

  if (s[2] == s[3] && s[4] == s[5]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <string>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <utility>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iterator>
#include <sstream>

using namespace std;

bool b[1000000];

int main()
{
	memset(b,1,1000000);
	b[0] = b[1] = false;
	for(int i = 2; i < 1000; i++)
		if(b[i]) for(int j = i * 2; j < 1000000; j+=i) b[j] = false;

	int n;
	while(cin>>n,n){
		int ans = 0;
		int i = 0;
		int cnt = 2;
		for (int i = 0; i < n; i++){
			while(!b[cnt])cnt++;
			ans += cnt;
			cnt++;
		}
		cout << ans <<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define ABSS(a, b) (a > b ? a - b : b - a)

typedef struct {
	uint32_t a;
	uint32_t b;
	uint32_t nextIdx;
	uint32_t prevIdx;
} L_t;

static uint32_t beginIdx;

static L_t L[100000];
static uint32_t endCount[100000];

static void removeElement(const size_t idx) {
	if (L[idx].nextIdx != UINT32_MAX) {
		if (L[idx].prevIdx != UINT32_MAX) {
			L[L[idx].prevIdx].nextIdx = L[idx].nextIdx;
			L[L[idx].nextIdx].prevIdx = L[idx].prevIdx;
		}
		else {
			L[L[idx].nextIdx].prevIdx = UINT32_MAX;
			beginIdx = L[idx].nextIdx;
		}
	}
	else {
		if (L[idx].prevIdx != UINT32_MAX) {
			L[L[idx].prevIdx].nextIdx = UINT32_MAX;
		}
		else {
			beginIdx = UINT32_MAX;
		}
	}

	endCount[L[idx].b]--;
}

static void disconnectIsland(const uint32_t endPos) {
	uint32_t i = beginIdx;
	while (i != UINT32_MAX) {\
		if (L[i].a < endPos && L[i].b >= endPos) {
			removeElement(i);
		}
		i = L[i].nextIdx;
	}
}

int main(void) {
	uint32_t N, M;

	scanf("%"PRIu32" %"PRIu32"\n", &N, &M);
	for (uint32_t i = 0; i < N; i++) {
		endCount[i] = 0;
	}
	for (uint32_t idx = 0; idx < M; idx++) {
		scanf(idx != M - 1 ? "%"PRIu32" %"PRIu32"\n" : "%"PRIu32" %"PRIu32, &(L[idx].a), &(L[idx].b));
		L[idx].a--;
		L[idx].b--;
		L[idx].nextIdx = (idx != M - 1 ? idx + 1 : UINT32_MAX);
		L[idx].prevIdx = (idx != 0 ? idx - 1 : UINT32_MAX);
		endCount[L[idx].b]++;
	}
	beginIdx = 0;

	uint32_t removedBridgeCount = 0;
	for (uint32_t i = 0; i < N; i++) {
		if (endCount[i] > 0) {
			disconnectIsland(i);
			removedBridgeCount++;
		}
	}

	printf("%"PRIu32, removedBridgeCount);

	return 0;
}

Measured memory_bytes: 2176
# include <bits/stdc++.h>
# define ll long long int
# define pb push_back
# define pf push_front
# define mpi make_pair
# define pi pair<ll,ll>
# define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
# define mod 1000000007
# define endl "\n"
using namespace std;
int main()
{
  fast
	ll k,x;
	cin>>k>>x;
	for(ll i=(x-k+1);i<=(x+k-1);i++)
	{
		cout<<i<<" ";
	}
	 return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) ll((a).size())
#define out(a) cout<<(a)<<endl;
const ll inf=1e9;
const int MAX = 510000;
const ll MOD = 998244353;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
  ll n;cin>>n;
  vll sum(n+1,0);
  map<ll,ll> m;
  ll ans=0;
  m[0]++;
  rep(i,0,n){
    ll a;cin>>a;
    sum[i+1]=sum[i]+a;
    m[sum[i+1]]++;
  }
  for(auto u:m){
      ll tmp=u.second;
      ans+=((tmp-1)*tmp)/2;
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 17188
#include <bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
using namespace std;
 
template<class T> inline
void read(T& x) {
	int f = 1; x = 0;
	char ch = getchar();
	while (ch < '0' || ch > '9')   {if (ch == '-') f = -1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
 
/*============ Header Template ============*/

const int N = 100000 + 5;

int n, q, L;
int x[N], y[N], a[N], ans[N];
int dep[N], f[N][21];

int climb(int x, int k) {
	for (int i = 20; ~i; i--)
		if (k & (1 << i)) x = f[x][i];
	return x;
}
 
void solve1() {
	for (int i = 1; i <= n; i++) f[i][0] = upper_bound(a, a + n + 1, a[i] + L) - a - 1;
	for (int i = n; i; i--)	dep[i] = dep[f[i][0]] + 1;
 	for (int j = 1; j <= 20; j++) 
 		for (int i = 1; i <= n; i++) f[i][j] = f[f[i][j - 1]][j - 1];
 	for (int i = 1; i <= q; i++) {
 		if (x[i] <= y[i]) {
			int l = 0, r = n;
 			while (l <= r) {
  				int m = (l + r) >> 1;
 				int k = climb(x[i], m);
 				if (k >= y[i]) {
 					ans[i] = m;
 					r = m - 1;
 				} else l = m + 1;
 			}
 		}
 	}
}

void solve2() {
	for (int i = 1; i <= n; i++) f[i][0] = lower_bound(a, a + n + 1, a[i] - L) - a;
	for (int i = 1; i <= n; i++) dep[i] = dep[f[i][0]] + 1;
 	for (int j = 1; j <= 20; j++) 
 		for (int i = 1; i <= n; i++) f[i][j] = f[f[i][j - 1]][j - 1];
 	for (int i = 1; i <= q; i++) {
 		if (x[i] > y[i]) {
 			int l = 0, r = n;
 			while (l <= r) {
 				int m = (l + r) >> 1;
 				int k = climb(x[i], m);
 				if (k <= y[i]) {
 					ans[i] = m;
 					r = m - 1;
 				} else l = m + 1;
 			}
 		}
 	}
}

int main() {
	read(n);
	for (int i = 1; i <= n; i++) read(a[i]); a[n + 1] = INF, a[0] = -INF; read(L);
	read(q);
	for (int i = 1; i <= q; i++) read(x[i]), read(y[i]);
	solve1();
	solve2();
	for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
	return 0;
} 

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

using namespace std;
using ll=long long;
const ll mod = 1e9 + 7;

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

int main() {
    ll N,P;
    cin>>N>>P;
    if(P==1){
        cout<<1<<endl;
        return 0;
    }
    if(N==1){
        cout<<P<<endl;
        return 0;
    }
    ll tmp;
    ll ans=1;
    for(ll i=2;i<=sqrt(P)+1;i++){
        tmp=0;
        while(P%i==0){
            P/=i;
            tmp++;
        }
        ans*=(ll)pow(i,tmp/N);
    }

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



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

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

  string S;
  cin>>S;
  int N=S.size();

  int dep=0;
  vector<int> d(N+1,0);
  for(int i=0;i<N;i++){
      if(S[i]=='0'||S[i]=='?') dep--;
      else dep++;
      d[i+1]=dep;
  }
  for(int i=N-1;i>=0;i--) chmax(d[i],d[i+1]);
  int Z=d[0];

  int mxs=Z;
  int ans=N;
  rep(k,2){
      int mis=0;
      int dep=0;
      int pls=0;
      for(int i=0;i<N;i++){
          if(S[i]=='0') dep--;
          else if(S[i]=='1') dep++;
          else{
              if(d[i+1]+2*pls+2<=mxs){
                  dep++;
                  pls++;
              }else{
                  dep--;
              }
          }
          chmin(mis,dep);
      }
      chmin(ans,mxs-mis);
      mxs++;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 8208
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int ans = 0;
        int key = 1;
        for (int i = 0; i < N; i++) {
            int a = sc.nextInt();
            if (a == key) {
                key++;
            } else {
                ans++;
            }
        }
 
        System.out.println(key == 1 ? -1 : ans);
    }
}

Measured memory_bytes: 63432
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

ll N;
ll arr[25];
ll maxVal;
ll minVal;
ll cnt = 0;

int main() {
	scanf("%lld", &N);
	for(int i = 0; i < N; i++) {
		scanf("%lld", &arr[i]);
	}
	for(int i = 1; i < N - 1; i++) {
		maxVal = max(arr[i], max(arr[i - 1], arr[i + 1]));
		minVal = min(arr[i], min(arr[i - 1], arr[i + 1]));
		if(maxVal != arr[i] && minVal != arr[i]) {
			cnt++;
		}
	}
	printf("%lld\n", cnt);
	return 0;
}
/*
	Powered by Buggy Plugin
*/


Measured memory_bytes: 256
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
#include <queue>

// #include <iomanip>
//  cout << fixed << setprecision(15) << y << endl;

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

vll A;
vll B;
vll valmap[base10_6];
ll C;
ll N;
ll M;
ll K;

ll ltmp;
string stmp;
double dtmp;

int main(){

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

    cin >> N;
    cin >> M;

    rep(ni,N){
        cin >> ltmp;
        A.push_back(ltmp);
        cin >> ltmp;
        B.push_back(ltmp);

        valmap[A[ni]].push_back(B[ni]);
    }
    
    ll ans = 0;
    std::priority_queue<ll> que;
    for( ll mi = 1 ; mi <=M ; mi++ ){
        rep(vi,valmap[mi].size()){
            que.push(valmap[mi][vi]);
        }

        if(que.size()>0){
            ll getv = que.top();
            ans += getv;

            que.pop();
        }
    }
    cout << ans << endl;



}

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

int main(){
  string w,s;
  int count = 0;
  
  cin >> w;
  
  while(1){
    cin >> s;
    
    if(s == "END_OF_TEXT"){
      break;
    }
    
    for(int i = 0;i < s.size();i++){
      if('A' <= s.at(i) && s.at(i) <= 'Z') s.at(i) += 'a' - 'A';
    }
    
    if(s == w) count++;
  }
  
  cout << count << endl;
  return 0;
}


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

int main() {
  int a, b;
  cin >> a >> b;
  
  int x = (a * b) % 2;
  if (x == 1) {
    cout << "Odd" << endl;
  }
  else {
    cout << "Even" << endl;
  }
}

Measured memory_bytes: 256
#include "math.h"
#include<stdio.h>
#include<map>
#include<string>
#include<iostream>
#include<vector>

using namespace std;

int main(void){

    string S;

    cin >> S;

    int a = stoi(S.substr(0,2));
    int b = stoi(S.substr(2,2));

    if((a < 13 && a != 0) && (b < 13 && b != 0)){
        cout << "AMBIGUOUS" << endl;
    }
    else if (!(a < 13 && a != 0) && (b < 13 && b != 0)){
        cout << "YYMM" << endl;
    }
    else if ((a < 13 && a != 0) && !(b < 13 && b != 0)){
        cout << "MMYY" << endl;
    }
    else{
        cout << "NA" << endl;
    }

    return 0;

}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	private	static	BufferedReader	br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int nCase = 1;
		while (parseTreasure(nCase++) != 0);
	}

	public static void knapsack(int[][] table, int[] item, int i) {
		int	nLen = table[0].length - 1;

		for (int c = nLen; c >= 0; c--) {
			if (c > nLen - item[1]) {
				table[i][c] = table[i-1][c];
			} else {
				table[i][c] = Math.max(table[i - 1][c], table[i - 1][c + item[1]] + item[0]);
			}
		}
	}

	private static int parseTreasure(int nCase) {
		String	strIn = null;
		int		nLen  = 0;
		int		nCap  = 0;

		if ((strIn = parseStdin()) != null) {
			if ((nCap = Integer.parseInt(strIn)) != 0) {
				strIn  = parseStdin();
				nLen   = Integer.parseInt(strIn);
				
				if (nLen > 0) {
					int[][]	table = new int[nLen + 1][nCap + 1];

					for (int n = 1; n <= nLen; n++) {
						int[]		item = new int[2];
						String[]	line = null;

						strIn = parseStdin();
						line  = strIn.split(",");
						item[0] = Integer.parseInt(line[0]);
						item[1] = Integer.parseInt(line[1]);

						knapsack(table, item, n);
					}

					for (int n = 1; n <= nCap; n++) {
						if (table[nLen][n] != table[nLen][0]) {
							System.out.printf("Case %d:\n", nCase);
							System.out.println(table[nLen][n - 1]);
							System.out.println(nCap - n + 1);
							break;
						}
					}
				}
			}
		}
		
		return nCap;
	}

	private static String parseStdin() {
		String	strNum = null;

		try {
			String line = br.readLine();
			if (line != null) {
				if (!line.isEmpty()) {
					strNum = line;
				}
			}
		}
		catch (IOException e) {}

		return strNum;
	}
}

Measured memory_bytes: 26476
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), cout, ", ") << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, ostream &os = cout, string sep = " ")
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), os, ", ") << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, H);
    IN(ll, W);
    IN(ll, K);
    AIN(string, S, H);

    ll ans = INF;
    REP(p, 1 << (H - 1))
    {
        vi c;
        REP(i, H - 1)
        {
            if ((p >> i) & 1)
            {
                c.push_back(i + 1);
            }
        }
        c.push_back(H);
        ll m = c.size();
        vi x(m);
        ll y = m - 1;
        REP(j, W)
        {
            vi dx(m);
            ll i = 0;
            bool ok = true;
            REP(k, m)
            {
                while (i < c[k])
                {
                    dx[k] += S[i][j] - '0';
                    ++i;
                }
                x[k] += dx[k];
                ok &= x[k] <= K;
            }
            if (!ok)
            {
                REP(k, m)
                {
                    x[k] = dx[k];
                    if (x[k] > K)
                    {
                        y = INF;
                    }
                }
                ++y;
            }
        }
        CH(min, ans, y);
    }
    OUT(ans);
}

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n, m, k;
set<int> fr[maxn], anti[maxn];
int ans[maxn];

int par[maxn];
int siz[maxn];

set<int> sets[maxn];

int parent(int x) {
  return x == par[x] ? x : par[x] = parent(par[x]);
}

void join(int x, int y) {
  x = parent(x);
  y = parent(y);
  if (x == y) return;
  if (siz[x] < siz[y]) swap(x, y);
  par[y] = x;
  siz[x] += siz[y];
}

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

  cin>>n>>m>>k;
  for (int i=1; i<=n; i++) {
    par[i] = i;
    siz[i] = 1;
  }
  for (int i=0; i<m; i++) {
    int u,v; cin>>u>>v;
    fr[u].insert(v);
    fr[v].insert(u);
    join(u,v);
  }

  for (int i=0; i<k; i++) {
    int u,v; cin>>u>>v;
    anti[u].insert(v);
    anti[v].insert(u);
  }

  

  for (int i=1; i<=n; i++) {
    sets[parent(i)].insert(i);
  }


  for (int i=1; i<=n; i++) {
    ans[i] = siz[parent(i)] - 1;
    for (int x: fr[i]) {
      if (sets[parent(i)].count(x)) ans[i]--;
    }
    for (int x: anti[i]) {
      if (sets[parent(i)].count(x)) ans[i]--;
    }
  }

  for (int i=1; i<=n; i++) cout<<ans[i]<<" ";
  cout<<endl;
  return 0;
}
// don't forget to read in the input :^)


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

int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL);

  int n, m, x;
  cin >> n >> m >> x;
  vector<int> a(n + 1);
  vector<int> b(n + 1);
  for (int i = 0; i < m; ++i) {
    int d;
    cin >> d;
    a[d] = 1;
    b[d] = 1;
  }
  for (int i = 1; i <= n; ++i) {
    a[i] += a[i - 1];
  }
  for (int i = n; 0 < i; --i) {
    b[i - 1] += b[i];
  }
  cout << min(a[x], b[x]) << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    int n,a[200000];
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    int cnt=0;
    for(int i=0;i<n;i++)
        if(a[i]==cnt+1)
            cnt++;
    cout<<(cnt?n-cnt:-1)<<endl;
}


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

#define MAX 100000

int n,head,tail;

typedef struct{
  char name[100];
  int time;
}queue;
queue Q[MAX];

void enqueue(queue);
queue dequeue(void);

int main(){
  int i,quant,t=0,fin=0;
  queue q;

  scanf("%d%d", &n, &quant);
  for(i=1;i<=n;i++) scanf("%s%d", Q[i].name, &Q[i].time);

  head=0; tail=0;
  
  while(fin != n){
    q=dequeue();
    if(q.time-quant<=0){
      t+=q.time;
      fin++;
      printf("%s %d\n",q.name , t);
    } else if (q.time > 0){
      t+=quant;
      q.time-=quant;
      enqueue(q);
    }
  }
  return 0;
}

void enqueue(queue q){
  if(tail==n) tail=1;
  else tail++;
  Q[tail]=q;
  return;
}

queue dequeue(){
  if(head==n) head=1;
  else head++;
  return Q[head];
}

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

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
    ll n, m;
    string s, t;
    cin >> n >> m >> s >> t;

    ll g = gcd(n,m);
    bool ok = true;
    int i = 0, j = 0;
    while (i < n && j < m) {
        if (s.at(i) != t.at(j)) ok = false;
        i += n/g;
        j += m/g;
    }
    
    if (ok) cout << n / g * m << endl;
    else cout << -1 << endl;
    return 0;
}

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

int main()
{
  string s, x;
  cin >> s >> x;
  int num = stoi(s+x);
  double root = sqrt(num);
  if(root == int(root)) puts("Yes");
  else puts("No");
  
  // int root = sqrt(num);
  // if(num == (root*root)) puts("Yes");
  // else puts("No");
}


Measured memory_bytes: 3504
from bisect import bisect_left

def rwh_primes2(n):
    # https://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python/3035188#3035188
    """ Input n>=6, Returns a list of primes, 2 <= p < n """
    correction = (n%6>1)
    n = {0:n,1:n-1,2:n+4,3:n+3,4:n+2,5:n+1}[n%6]
    sieve = [True] * (n//3)
    sieve[0] = False
    for i in range(int(n**0.5)//3+1):
      if sieve[i]:
        k=3*i+1|1
        sieve[      ((k*k)//3)      ::2*k]=[False]*((n//6-(k*k)//6-1)//k+1)
        sieve[(k*k+4*k-2*k*(i&1))//3::2*k]=[False]*((n//6-(k*k+4*k-2*k*(i&1))//6-1)//k+1)
    return [2,3] + [3*i+1|1 for i in range(1,n//3-correction) if sieve[i]]

if __name__ == "__main__":
  prime = rwh_primes2(7368791+10)
  while True:
    m,n = map(int,input().split())
    if m == 0 and n == 0:
      break
    small_prime = prime[:bisect_left(prime,m**2)]
    composite = []
    for i in range(1,m+1):
      for j in range(i,m+1):
        x = i*j
        if m <= x <= m**2 and x not in small_prime:
          for p in small_prime:
            if x%p == 0:
              if x < m*p:
                composite.append(x)
              break
    composite = sorted(list(set(composite)))
    pp = bisect_left(prime,m)
    cp = 0
    sz = len(composite)
    for i in range(n+1):
      if cp < sz:
        if composite[cp] < prime[pp]:
          ans = composite[cp]
          cp += 1
        else:
          ans = prime[pp]
          pp += 1
      else:
        ans = prime[pp+n-i]
        break
    print(ans)


Measured memory_bytes: 51196
#include <bits/stdc++.h>
using namespace std;
struct _I { _I() {cin.tie(0);ios::sync_with_stdio(false);}} __I;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define MOD 1000000007

inline void init(vector<int>& uf) {
    iota(all(uf), 0);
}

inline int root(vector<int>& uf, int x) {
    if (uf[x] == x) {
        return x;
    } else {
        return uf[x] = root(uf, uf[x]);
    }
}
inline bool same(vector<int>& uf, int x, int y) {
    return root(uf, x) == root(uf, y);
}
inline void unite(vector<int>& uf, int x, int y)
{
    x = root(uf, x);
    y = root(uf, y);
    if (x == y) return;
    uf[x] = y;
}

int main()
{
    int N, M; cin >>N>>M;
    vi p(N); cin >> p;
    vector<int> uf(N+1);
    init(uf);

    rep(i, M) {
        int x, y; cin >> x >> y; //D2(x, y);
        unite(uf, x, y);
    }
    
    int ans = 0;
    rep(i, N) {
        if (same(uf, i+1, p[i])) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class AC>void r(AC &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
int n;
double ans,x;
string s;
int main(){
	r(n);
	while(n--){
		cin>>x;
		cin>>s;
		if(s=="BTC")ans=ans+x*380000;
		else ans+=x;
	}
	printf("%lf\n",ans);
	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) = println(run {
    val (n,m,x) = readLine()!!.split(" ").map { it.toInt() }
    val a = readLine()!!.split(" ").map { it.toInt() }

    Math.min(a.takeWhile { it<x }.count(), a.takeLastWhile { it>x }.count())

})


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

long long gcf(long long a, long long b)
{
    if (b == 0)
    {
        return a;
    }

    return  gcf(b, a % b);
}

int main()
{
    long long a, b;
    cin >> a >> b;
    cout << (a * b) / gcf(a, b) << endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define ll long long

using namespace std;

vector <ll> s;
map <ll, int> cnt;

ll ncr(ll n, ll r) {
  r = max(r, n - r);
  ll ans = 1;
  ll arr[n - r + 1];
  ll ch = n - r;
  for (ll i = 1; i <= n - r; i++) arr[i] = i;
  while (n > r) {
    ans *= n;
    for (ll i = 1; i <= ch; i++) {
      if (arr[i] && ans % i == 0) {
        ans /= i;
        arr[i] = 0;
      }
    }
    n--;
  }
  return ans;
}

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  for (int i = 0; i < n; i++) {
    ll foo;
    cin >> foo;
    if (! cnt[foo]) s.push_back(foo);
    cnt[foo]++;
  }
  sort(s.begin(), s.end());
  reverse(s.begin(), s.end());
  ll c = 0, sum = 0;
  ll get = 0, use = 0;
  for (int i = 0; i < n; i++) {
    if (c + cnt[s[i]] < a) {
      sum += cnt[s[i]] * s[i];
      c += cnt[s[i]];
    } else {
      get = s[i];
      use = cnt[s[i]];
      break;
    }
  }
  ll ways;
  if (c) {
    ll need = a - c;
    sum += (need * get);
    ways = 1;
    ways = ncr(use, need);
  } else {
    ways = 0;
    sum += (a * get);
    for (ll i = a; i <= min(b, use); i++) {
      ways += ncr(use, i);
    }
  }
  long double ans = static_cast<long double>(sum);
  long double div = static_cast<long double>(a);
  ans = ans / div;
  cout.precision(10);
  cout << fixed << ans << endl;
  cout << ways << endl;
  return 0;
}



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

#define int long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define all(c) (c).begin(),(c).end()
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int INF = 1e9;
const int INF64 = 1e18;
const int MOD = INF + 7;
const ld PI = acos(-1.0);

int32_t main(){
	fast;
	int a,b;
  cin >> a >> b;
	cout << 1+2+3 - a-b;
}



Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] a1 = sc.next().split("");
      	String[] a2 = sc.next().split("");
      	String[] a3 = sc.next().split("");
      	System.out.println(a1[0] + a2[1] + a3[2]);
	}
}

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

int main() {
  int r,g,b;
  cin >> r >> g >> b;
  int x = 10 * g + b;
  cin >> x;
  
  if(x%4 == 0) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
  
}


Measured memory_bytes: 256
import heapq 
import math
N, M = map(int,input().split())
A = list(map(lambda x:int(x)*(-1),input().split()))
heapq.heapify(A)
for _ in range(M):
    heapq.heappush(A, math.ceil(heapq.heappop(A)/2))
print(sum(A)*-1)

Measured memory_bytes: 14532
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
typedef pair<int,int> P;
#define mod 1000000007

int main(){
    string s,t;
    cin >> s >> t;
    int l=s.length();
    int count=0;
    bool flag=false;
    while(count<l){
        if(s==t) {
            flag=true;
            break;
        }
        s=s.back()+s.substr(0,l-1);
        count++;
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include<fstream>
#include<assert.h>

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define ll long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
using namespace std;

const ll MOD = 1000000007;// 10^9+7
const ll INF = (1ll << 60);


//変数
struct Edge {
	ll to;
	ll cost;
};

ll n, m;
vector<vector<Edge>> edges;






//サブ関数
//入力
void input()
{
	cin >> n >> m;
	edges.resize(n);
	ll a, b, c;
	REP(i, m)
	{
		cin >> a >> b >> c;
		a--; b--;
		edges[a].push_back({ b,c });
		edges[b].push_back({ a,c });
	}
}

int fill_graph(int a)
{
	vector<ll> cost(n, INF);
	queue<ll> q;
	q.push(0);
	cost[0] = a;

	while (!q.empty())
	{
		ll now = q.front(); q.pop();
		for (auto next : edges[now])
		{
			//初見
			if (cost[next.to] == INF) {
				cost[next.to] = next.cost - cost[now];
				//辻褄が合わない
				if (cost[next.to] <= 0) {
					return 0;
				}
				q.push(next.to);
			}
			//再訪
			else {
				//辻褄が合わない
				if (cost[next.to] + cost[now] != next.cost)
					return 0;
			}
		}
	}
	return 1;
}


//計算
ll calc()
{
	vector<ll> cost;
	vector<ll> went;//1:+a  -1:-a   0:didn't go 
	queue<pair<ll, ll>> will;// first -> second
	cost.resize(n);
	went.resize(n);
	went[0] = 1;
	for (auto next : edges[0])
	{
		will.push({ 0, next.to });
		went[next.to] = -1;
		cost[next.to] = next.cost;
	}

	while (!will.empty())
	{
		auto now = will.front(); will.pop();
		ll from = now.second;
		for (auto next : edges[from])
		{
			ll to = next.to;
			//戻らない
			if (to == now.first)continue;
			
			//初めて
			if (went[to] == 0) 
			{
				went[to] = went[from] * -1;
				cost[to] = next.cost - cost[from];
				will.push({ from,to });
			}
			//2度目
			else 
			{
				if (went[to] == went[from])
				{
					ll a2 = cost[from] + cost[to] - next.cost;
					if (went[to] == 1) a2 *= -1;
					if (a2 % 2 == 1)return 0;
					else return fill_graph(a2 / 2);
				}
				else {
					if (cost[from] + cost[to] != next.cost)return 0;
				}
			}
		}
	}
	//無事書き終わり
	ll least = 1;
	ll best = INF;
	REP(i, n)
	{
		switch (went[i]) {
		case 1:
			least = max(least, 1 - cost[i]);
			break;
		case -1:
			best = min(best, cost[i] - 1);
			break;
		case 0:
			assert(false);
		}
	}
	return max(best - least + 1, 0ll);
}


//出力
void output()
{

}


//デバッグ
void debug()
{
	int N;
	cin>>N;
}


//メイン関数
int main()
{
	input();
	cout << calc() << endl;
	output();
	debug();
	
	return 0;
}


Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000

bool is_valid(string s){
	if(s[0]=='0'||s.back()=='1')return false;
	s.insert(s.begin(),'0');
	string t(s.rbegin(),s.rend());
	if(s!=t)return false;
	
	for(int i=0;true;i++){
		if(s.size()<1+i)break;
		if(s[i]!=s[s.size()-1-i])return false;
	}
	return true;
}

int main(){
	
	string s;
	cin>>s;
	
	if(!is_valid(s)){
		cout<<-1<<endl;
		return 0;
	}
	
	int last = 0;
	vector<pair<int,int>> ans;
	
	for(int i=0;i<s.size()-1;i++){
		if(s[i]=='1'){
			ans.emplace_back(last,i+1);
			last = i+1;
		}
		else{
			ans.emplace_back(last,i+1);
		}
	}
	
	for(int i=0;i<ans.size();i++){
		cout<<ans[i].first+1<<' '<<ans[i].second+1<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 2580
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mod 1000000007
int main(){
	fast;
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll s=max(a,c),e=min(b,d);
	if(e-s>0)
		cout<<e-s;
	else
		cout<<0;
	return 0;
}



Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll mod=1000000007;
double pi=3.14159265359;
ll n;
ll res=0;

ll power(ll x,ll k){
	ll res=1;
	while(k){
		if(k&1) res=res*x;
		x=x*x;
		k>>=1;
	}
	return res;
}

void dp(ll nb , ll ind , int test)
{
   if(nb <= n)
   {
       if(test)
       {
           res++;
           dp(power(10,ind)*3 + nb ,ind+1,1 );
           dp(power(10,ind)*5 + nb,ind+1,1 );
           dp(power(10,ind)*7 + nb,ind+1,1 );
       }
       else{
         ll x=nb;
         int test3=0,test5=0,test7=0;
         while(x)
         {
             ll y=x%10;
             x/=10;
             if(y==3) test3=1;
             if(y==5) test5=1;
             if(y==7) test7=1;
         }
         if(test3 && test5 && test7)
         {
               res++;
               dp(power(10,ind)*3 + nb ,ind+1,1 );
               dp(power(10,ind)*5 + nb,ind+1,1 );
               dp(power(10,ind)*7 + nb,ind+1,1 );
         }
         else{
                dp(power(10,ind)*3 + nb ,ind+1,0 );
               dp(power(10,ind)*5 + nb,ind+1,0 );
               dp(power(10,ind)*7 + nb,ind+1,0 );

         }

       }
   }

}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(50);
    cin>>n;
    dp(3,1,0);
    dp(5,1,0);
    dp(7,1,0);
    cout <<res;

    return 0;
}


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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for(int i = (int)(n); i > 0; --i)
#define itrep(i,s) for(auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for(auto i = rbegin(s); i != rend(s); ++i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(x), end(x), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(x), rend(x), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T>
constexpr int sz(const T& a) { return (int)a.size(); }
template<class T, class ... Args>
constexpr void mins(T& a, Args... args) { a = min<T>({ a, args... }); }
template<class T, class... Args>
constexpr void maxs(T& a, Args... args) { a = max<T>({ a,args... }); }
template<class T>
constexpr T ceiling(const T a, const T b) { return (a + b - 1) / b; }
ll plusMod(ll& a, const ll b) { return a = (a + b) % mod; }
template<typename A, size_t N, typename T>
constexpr void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

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

    int m = 1 << n;
    multiset<ll> s;
    rep(i, m) {
        ll a;
        cin >> a;
        s.insert(a);
    }

    vector<ll> p;
    p.push_back(*s.rbegin());
    s.erase(--s.end());
    rep(i, n) {
        vector<ll> q = p;

        rall(sort, q);
        rep(j, q.size()) {
            auto it = s.lower_bound(q[j]);

            if (it == s.begin()) {
                cout << "No" << endn;
                return;
            }

            p.push_back(*(--it));
            s.erase(it);
        }
    }

    cout << "Yes" << endn;

}

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

    solve();

    cout << flush;

    return 0;
}


Measured memory_bytes: 15724
#include <bits/stdc++.h>
#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++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

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

	ll a, b, c, k;
	cin >> a >> b >> c >> k;

	ll ans = a - b;
	if (k & 1) ans = -ans;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n, x, y;
int f[2001];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> x >> y;
	for (int i = 1; i <= n; i++)
	{
		for (int j = i + 1; j <= n; j++)
		{
			f[min({ j - i, abs(x - i) + abs(y - j) + 1, abs(y - i) + abs(x - j) + 1 })]++;
		}
	}
	for (int i = 1; i < n; i++)
	{
		cout << f[i] << "\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N;

int main()
{
	in >> N;
	std::vector<LL>x(N), y(N), h(N);
	rep(i, N) in >> x[i] >> y[i] >> h[i];
	for (LL Cx = 0; Cx <= 100; ++Cx)
	{
		for (LL Cy = 0; Cy <= 100; ++Cy)
		{
			LL H = -1;
			bool flag = true;
			rep(i, N)
			{
				if (h[i] == 0) continue;
				LL res = h[i] + std::abs(x[i] - Cx) + std::abs(y[i] - Cy);
				if (H == -1) H = res;
				if (H != res)
				{
					flag = false;
					break;
				}
			}
			flag = true;
			rep(i, N)
			{
				LL res = std::max<LL>(H - std::abs(x[i] - Cx) - std::abs(y[i] - Cy), 0);
				if (h[i] != res)
				{
					flag = false;
					break;
				}
			}
			if (flag)
			{
				out << Cx << " " << Cy << " " << H << std::endl;
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

/**
 * Created by zzt on 17-1-29.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Set<Integer> set = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            set.add(scanner.nextInt());
        }
        int ret = set.size();
        if (ret % 2 == 0)
            ret--;
        System.out.println(ret);
    }
}

Measured memory_bytes: 51340
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

template<int mod>
struct ModInt{
    int x;

    ModInt() : x(0) {}
    
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    
    ModInt &operator+=(const ModInt &p){
        if((x += p.x) >= mod)   x -= mod;
        return *this;
    }
    
    ModInt &operator-=(const ModInt &p){
        if((x += mod - p.x) >= mod) x -= mod;
        return *this;
    }

    ModInt &operator*=(const ModInt &p){
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    ModInt &operator/=(const ModInt &p){
        *this *= p.inverse();
        return *this;
    }
    
    ModInt operator-() const {return ModInt(-x);}

    ModInt operator+(const ModInt &p) const {return ModInt(*this) += p;}

    ModInt operator-(const ModInt &p) const {return ModInt(*this) -= p;}

    ModInt operator*(const ModInt &p) const {return ModInt(*this) *= p;}

    ModInt operator/(const ModInt &p) const {return ModInt(*this) /= p;}

    bool operator==(const ModInt &p) const {return x == p.x;}

    bool operator!=(const ModInt &p) const {return x != p.x;}

    ModInt inverse() const{
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0){
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }

    ModInt pow(int64_t n) const{
        ModInt ret(1), mul(x);
        while(n > 0){
            if(n & 1)   ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const ModInt &p){
        return os << p.x;
    }

    friend istream &operator>>(istream &is, ModInt &a){
        int64_t t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }

    static int get_mod() {return mod;}
};

using modint = ModInt<mod>;

modint dp0[2005][2005];
modint dp1[2005][2005];

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

    int n, m;
    cin >> n >> m;
    vector<int> s(n + 1), t(m + 1);
    for(int i = 0; i < n; ++i)  cin >> s[i];
    for(int i = 0; i < m; ++i)  cin >> t[i];

    dp0[0][0] = 1;
    for(int i = 0; i <= n; ++i){
        for(int j = 0; j <= m; ++j){
            dp0[i + 1][j] += dp0[i][j];
            dp1[i][j] += dp0[i][j];
            dp1[i][j + 1] += dp1[i][j];
            if(s[i] == t[j])    dp0[i + 1][j + 1] += dp1[i][j];
        }
    }
    cout << dp1[n][m] << endl;
}

Measured memory_bytes: 31744