akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define gc getchar
#define int long long
const int N=1e6+5;
int n,gs,a[N];
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
signed main()
{
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=1;i<=n;i++)
		if(a[i]!=i)gs++;
	if(gs<=2)puts("YES");
	else puts("NO");
	return 0;
}

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

#define int long long int
#define ll long long
#define quickie ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rep(i, a, b) for(int i=a; i<b; i++)
#define rep1(i, a, b) for(int i=a; i<=b; i++)
#define repp(i, a, b) for(int i=b-1; i>=a; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define db double
#define mi map<int, int>
#define vi vector<int>
#define qi queue<int>
#define MI(x) power(x, mod-2)
#define test int t; cin >> t;
#define pii pair<int, int>
#define mod 1000000007
#define pi 3.141592653589
#define fact(n) rep(i, 1, n+1)ft.pb((ft[i-1]*i)%mod) ;

// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template<typename T>
// using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
// template<typename T>
// using ordered_multiset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
//(*****FOR USING ORDERED SET CHANGE INT*******)

int power(int x, int y) ;
int gcd(int a, int b) ;


signed main() {
    quickie
    int n, k, d ;
    cin >> n >> k >> d ;
    n = abs(n) ;
    int tt = n/d ;
    if(tt > k) {
        cout << (n-k*d) << "\n" ;
        return 0 ;
    }
    k -= tt ;
    n -= tt*d ;
    if(k%2 == 0) cout << n << "\n" ;
    else cout << abs(n-d) << "\n" ;
}

int power(int x, int y) {
    int res = 1; x %= mod;
    while (y > 0) {
        if (y & 1)
            res = (res*x) % mod;
        y = y>>1;
        x = (x*x) % mod;
    }
    return res%mod;
}

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



Measured memory_bytes: 3612
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
const int MAXN = 1e5 + 10 ;
int main(){
    int n ;
    cin >> n ;
    vector<int> v(n) ;
    for(int i=0;i<n;i++){
        cin >> v[i] ;
    }
    int cnt[MAXN] = {0} ;
    int nax = 0 ;
    int first = -1 ;
    for(int i=0;i<n;i+=2){
        cnt[v[i]]++;
        if ( nax < cnt[v[i]] ){
            nax = max(nax,cnt[v[i]]) ;
            first = v[i] ;
        }
    }
    int ans1 = n/2 - nax ;
    int secondNax = 0 ;
    for(int i=0;i<MAXN;i++){
        if ( i == first ) continue ;
        secondNax = max(secondNax,cnt[i]) ;
    }
    memset(cnt,0,sizeof cnt) ;
    nax = 0 ;
    int second = -1 ;
    for(int i=1;i<n;i+=2){
        cnt[v[i]]++;
        if ( nax < cnt[v[i]] ){
            nax = max(nax,cnt[v[i]]) ;
            second = v[i] ;
        }
    }
    int ssNax = 0 ;
    for(int i=0;i<MAXN;i++){
        if ( i == second ) continue ;
        ssNax = max(ssNax,cnt[i]) ;
    }
    int ans2 = (n/2 - nax) ;
    if ( first == second ){
        debug() << imie(first) imie(second) ;
        debug() << imie(secondNax) imie(ssNax);
        cout << min(ans2+n/2-secondNax,ans1+n/2-ssNax) << endl;
        return 0 ;
    }
    cout << ans1 + ans2 << endl;
    return 0 ;
}



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


auto solve(std::string a, std::string b){
    return ((a == "D") ^ (b == "H")) ? "H" : "D";
}

int main(){
    std::string a;
    std::cin >> a;
    std::string b;
    std::cin >> b;
    auto result = solve(a, b);
    cout << result << endl;
    return 0;
}


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

using namespace std;

#define PB push_back
#define f first
#define s second

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

const int MOD = 1000000007;
const int INF = 1000000007;
const int MAXN = (int)3e5+1;

ll ct[4000][3];
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    map<char, int> m;
    m['R'] = 0;
    m['G'] = 1;
    m['B'] = 2;
    int n;
    string s;
    cin >> n >> s;
    ll ans = 0;
    for(int i=0; i<n; i++)
    {
        ct[i][m[s[i]]]++;
        if(i)
        {
            for(int j=0; j<3; j++)
            {
                ct[i][j] += ct[i-1][j];
            }
        }
    }

    for(int i=1; i<n-1; i++)
    {
        int a = m[s[i]];
        ans += ct[i-1][(a+ 1)%3] * (ct[n-1][(a+2)%3] - ct[i][(a+2)%3]);
        ans += ct[i-1][(a+ 2)%3] * (ct[n-1][(a+1)%3] - ct[i][(a+1)%3]);
        for(int j=1; i-j >= 0 && i+j < n; j++)
        {
            if(s[i-j] != s[i] && s[i+j] != s[i] && s[i-j] != s[i+j])
            {
                ans--;
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3712
#include <iostream>
using namespace std;
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <iomanip>
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
#define INF 1LL<<61
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define setpre(n) fixed << setprecision(n)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
  
}
ll n,m,i,j,k,result=0;
ll a[LIMIT2]={0};
ll findData(ll i){
  //findDataが単調減少のときはbinaryの不等号を反転させる
  //戻り値: 2つの要素を選んだ積が i 以下となる組み合わせの個数
  ll s=0,t=0;
  for(ll j=0;j<n;j++){
    if(a[j]>0){
      ll l2=-1,r2=n;
      while(r2-l2>1){
        ll m2=(l2+r2)/2;
        if(a[j]*a[m2]<=i) l2=m2;
        else r2=m2;
      }
      s += r2;
    }else if(a[j]<0){
      ll l2=-1,r2=n;
      while(r2-l2>1){
        ll m2=(l2+r2)/2;
        if(a[j]*a[m2]<=i) r2=m2;
        else l2=m2;
      }
      s += n-r2;
    }else if(i>=0){
      s += n;
    }
    if(a[j]*a[j]<=i) t++;
  }
  ll num=(s-t)/2;
  return num;
}
ll binaryCeil(ll max, ll min, ll target){
  //targetの数値以上の最小
  ll mid;
  ll count=0;
  while(max-min>1 && count < 100){
    mid = (max+min)/2;
    if(findData(mid) >= target) max = mid;
    else min = mid;
    count++;
  }
  return max;
}
int main(void){
  initialize();
  
  cin >> n >> k;
  rep(i,n) cin >> a[i];
  sort(a,a+n);
  cout << binaryCeil(INF,-INF,k) << endl;
  
  return 0;
}

Measured memory_bytes: 5200
def is_valid(n, conditions):
    ns = [int(i) for i in str(n)]
    return all(ns[s - 1] == c for s, c in conditions)


N, M = map(int, input().split())

sc = []
for _ in range(M):
    s, c = map(int, input().split())
    sc.append((s, c))

candidates = [i for i in range(1000) if len(str(i)) == N and is_valid(i, sc)]

try:
    print(candidates[0])
except:
    print(-1)


Measured memory_bytes: 3064
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define debug(x) (cout << # x ": " << x << endl)
#define int long long int
#define repeat(n) for (int i = 0; i < n; ++i)
#define repeat2(n) for (int j = 0; j < n; ++j)
#define all(x) x.begin(), x.end()
#define llcast static_cast<long long int>

signed main() {
    int n, m, k;
    cin >> n >> m >> k;

    vector<int> va, vb;

    va.push_back(0);
    vb.push_back(0);
    int accum = 0;
    repeat(n) {
        int a;
        cin >> a;
        accum += a;
        va.push_back(accum);
    }

    accum = 0;
    repeat(m) {
        int b;
        cin >> b;
        accum += b;
        vb.push_back(accum);
    }

    int ans = 0;
    int j = m;
    repeat(n + 1) {
        while (va[i] + vb[j] > k) {
            --j;
            if (j < 0) break;
        }
        if (j < 0) break;
        ans = max(i + j, ans);
    }

    cout << ans;
    
    return 0;
}

Measured memory_bytes: 7416
#include<iostream>
int main(void)
{
	int a, b, c, five=0, seven=0;

	std::cin>>a>>b>>c;

	switch(a){
		case 5:
			five++;
			break;
		case 7:
			seven++;
			break;
	}
	switch(b){
		case 5:
			five++;
			break;
		case 7:
			seven++;
			break;
	}
	switch(c){
		case 5:
			five++;
			break;
		case 7:
			seven++;
			break;
	}

	if(five==2&&seven==1){
		std::cout<<"YES"<<std::endl;
	}else{
		std::cout<<"NO"<<std::endl;
	}
}

Measured memory_bytes: 256
class UnionFind
  def initialize(n)
    @par = (0..n).to_a
    @rank = Array.new(n, 0)
  end
  
  def find(x)
    if @par[x] == x then
      return x
    else
      @par[x] = self.find(@par[x])
      return @par[x]
    end
  end
  
  def unite(x, y)
    x = self.find(x)
    y = self.find(y)
    if x == y then
      return
    end
    if @rank[x] < @rank[y] then
      @par[x] = y
    else
      @par[y] = x
      if @rank[x] == @rank[y] then
        @rank[x] += 1
      end
    end
  end

  def same(x, y)
    return self.find(x) == self.find(y)
  end 
end

class Node
  attr_accessor :x, :y, :i
  def initialize(x, y, i)
    @x = x
    @y = y
    @i = i
  end
end

class Edge
  attr_accessor :u, :v, :cost
  def initialize(u, v, cost)
    @u = u
    @v = v
    @cost = cost
  end
end

def kruscal(edge, n)
  edge.sort_by!{|x| x.cost}
  uf = UnionFind.new(n)
  res = 0
  edge.size.times do |i| 
    e = edge[i]
    if !uf.same(e.u, e.v) then
      uf.unite(e.u, e.v)
      res += e.cost
    end
  end
  return res
end

n = gets.chomp.to_i
edge = []
nodes = []

n.times do |i|
  x, y = gets.chomp.split(" ").map(&:to_i)
  nodes << Node.new(x, y, i)
end

nx = nodes.sort_by{|x| x.x}

(n-1).times do |i|
  n1 = nx[i]
  n2 = nx[i+1]
  edge << Edge.new(n1.i, n2.i, (n1.x - n2.x).abs)
end

ny = nodes.sort_by{|x| x.y}
(n-1).times do |i|
  n1 = ny[i]
  n2 = ny[i+1]
  edge << Edge.new(n1.i, n2.i, (n1.y - n2.y).abs)
end

puts kruscal(edge, n)

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

int main(){
	int n, k;
	int x;
	int i;
	int f;
	cin >> n >> k;
	double p;
	double sigma = 0.0;
	for(x=1;x<=n;x++){
		p = 1.0/n;
		f = x;
		while(f<k){
			f *= 2;
			p *= 1.0/2.0;
		}
		sigma += p;
	}
	cout <<  std::setprecision(12) << sigma << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

N, P = map(int, input().split())
S = input()

def solMin():
    dp = [[0] * P for _ in range(N + 1)]

    for i, s in enumerate(map(int, S), start=1):
        dp[i][s % P] += 1
        for p in range(P):
            dp[i][(p * 10 + s) % P] += dp[i - 1][p]

    return sum(dp[i][0] for i in range(N + 1))

def solLarge():
    cnt = defaultdict(int)
    ret = 0
    now = 0

    for d, s in enumerate(map(int, S[:: -1])):
        now += pow(10, d, P) * s
        now %= P
        ret += cnt[(now - P) % P]
        if now == 0:
            ret += 1
        cnt[now] += 1

    return ret

print(solMin() if P * N <= 10**6 else solLarge())


Measured memory_bytes: 42932
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int> p;
const int MOD = 1000000007;


int main(){
  ll a,b,c,d,ans,ans1,ans2;
  cin >> a>>b>>c>>d;
  ans1=max(a*c,a*d);
  ans2=max(b*c,b*d);
  ans=max(ans1,ans2);
  cout<<ans;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <set>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INF64 = 3e18;
const unsigned long long HASHBASE=1222827239ull;
/////////////////////////
long long dp[100001];
long long n,m;
/////////////////////////
int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    memset(dp,0,sizeof(dp));
    cin>>n>>m;
    long long q;
    for(long long i=0;i<m;++i)
    {
        cin>>q;
        dp[q]=-1;
    }
    if(dp[1]!=-1)
    {
        dp[1]=1;
    }
    if(dp[2]!=-1)
    {
        if(dp[1]!=-1)
        {
            dp[2]=2;
        }
        else
        {
            dp[2]=1;
        }
    }
    for(long long i=3;i<=n;++i)
    {
        if(dp[i]==-1)
        {
            continue;
        }
        if(dp[i-1]!=-1)
        {
            dp[i]+=dp[i-1];
        }
        if(dp[i-2]!=-1)
        {
            dp[i]+=dp[i-2];
        }
        dp[i] = dp[i] % 1000000007;
    }
    cout<<dp[n]<<endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, s, e) for(ll i=s; i>=e; i--)
#define reps(i, s, e) for(ll i=s; i<=e; i++)
#define inf 1e18
#define all(v) v.begin(),v.end()
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> void vdebug(vector<T> v){ cout << "vdebug" << endl; for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> void adebug(T arr[], ll n){ cout << "adebug" << endl; reps(i, 0, n){ cout << arr[i] << " "; } cout << endl; }
template<typename T1, typename T2> void mdebug(map<T1, T2> mp){ cout << "mdebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mldebug(multimap<T1, T2> mp){ cout << "mldebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mdebugr(map<T1, T2, greater<T1>> mp){ cout << "mdebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
template<typename T1, typename T2> void mldebugr(multimap<T1, T2, greater<T1>> mp){ cout << "mldebug" << endl; for(auto const& m : mp){ cout << m.first sp m.second << endl; }}
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    string s;
    cin >> s;
    int slen = s.length();

    ll a[slen+1];

    a[0] = -1;
    reps(i, 1, slen-1){
        a[i] = -1;
        if(s[i-1] == '>' && s[i] == '<'){
            a[i] = 0;
        }
    }
    if(s[0] == '<') a[0] = 0;
    if(s[slen-1] == '>') a[slen] = 0;

    reps(i, 0, slen){
        if(a[i] == 0){
            int l = i-1;
            int r = i+1;
            while(0 <= l && s[l] == '>'){
                if(l+1 <= slen) a[l] = max(a[l], a[l+1] + 1);
                else a[l] = 1;
                l--;
            }
            while(r <= slen && s[r-1] == '<'){
                a[r] = max(a[r], a[r-1] + 1);
                r++;
            }
        }
    }

    ll sum = 0;
    reps(i, 0, slen){
        sum += a[i];
    }

    //adebug(a, slen);

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 4764
#include <stdio.h>
#include <ctype.h>

int main(void)
{
  char str;
  int num;
  int cou[26];
  int i;
  char alp;

  for(i=0; i<26; i++){
    cou[i] = 0;
  }
  
  while(scanf("%c",&str) != EOF){ //End Of File?????§????????????
    if(isalpha(str)){ //??¢????????????????????????
      if(isupper(str)){ //??¢???????????????????????§????????????
	str = tolower(str); //?°??????????????????????
      }
      num = str - 'a'; //??????str[i]????????????????????????
      cou[num]++; //??????????????????
    }
  }

  for(i=0,alp='a'; i<26; i++,alp++){
    printf("%c : %d\n",alp,cou[i]);
  }
       	
  return(0);
}

Measured memory_bytes: 976
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define rep(i, n)           for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b)        for (int i = (int)(a); i < (int)(b); i++)
#define inv(i, a, b)        for (int i = (int)(a); i >= (int)(b); i--)
#define ALL(obj)            begin(obj), end(obj)
#define MAX(x)              *max_element(ALL(x))
#define MIN(x)              *min_element(ALL(x))
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))
#define Endl                endl

using namespace std;
const int MOD   = (int)(1e9 + 7);
const int INF   = (int)(1e13 + 7);
const double PI = acos(-1);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int bpm(int x, unsigned int y) {                                                    //return x^y in order(log(y))
  if (x == 0) return 0;
  if (y == 0) return 1;
  int ans   = 1;
  int digit = (int)((log((double)y) / log((double)2) / 1 + 1));
  x %= MOD;
  for (int i = 0; i < digit; i++) {
    if (((y >> i) & 1u) == 1) ans = ans * x % MOD;
    x = x * x % MOD;
  }
  return ans;
}
template <class T>
void cumulative_sum(T &container) {
  for (int i = 0; i < container.size() - 1; i++) container[i + 1] += container[i];
}

class CHonestOrUnkind2 {
public:
  static void solve(istream &cin, ostream &cout) {
    int N;
    cin >> N;
    int ans = 0;
    vector<vector<pair<int, int>>> xy(N);
    rep(i, N) {
      int A;
      cin >> A;
      rep(j, A) {
        int x, y;
        cin >> x >> y;
        xy[i].emplace_back(x, y);
      }
    }
    rep(i, bpm(2, 15)) {
      vector<int> check(N + 1);
      rep(j, N) {
        if ((i >> j) & 1) {
          check[j + 1] = 1;
        } else {
          check[j + 1] = 0;
        }
      }
      int temp = 0;
      rep(j, N) {
        if ((i >> j) & 1) {
          temp++;
          for (auto &k : xy[j]) {
            if (check[k.first] != k.second) {
              goto label;
            }
          }
        }
      }
      ans = max(ans, temp);
    label:;
    }
    cout << ans << endl;
  }
};


signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  CHonestOrUnkind2 solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int trib(int a){
    if(a==1){return 1;}
    if(a==2){return 2;}
    if(a==0){return 1;}
//  if(a==3){return }
    return trib(a-3)+trib(a-2)+trib(a-1);
}
int main() {
    // your code goes here
int a;
while(true){
    cin>>a;
    if(a==0){return 0;}
cout<<((trib(a)+1)/10+1)/365+1<<endl;
     
}
    return 0;
}


Measured memory_bytes: 3064
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {

		int N = nextInt();
		int K = nextInt();
		int[] h = nextInts();

		long[] dp = new long[N+1];
		dp[0]=0;
		dp[1]=Math.abs(h[1]-h[0]);
		for(int i=2;i<N;i++){
			dp[i]=Math.abs(h[i]-h[i-1])+dp[i-1];
			for(int k=2;k<=K;k++){
				if(i-k<0){
					break;
				}
				dp[i]=Math.min(dp[i], Math.abs(h[i]-h[i-k])+dp[i-k]);
			}
		}
		System.out.println(dp[N-1]);

	}

	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static String concatStringArray(String[] s){
		StringBuffer sb = new StringBuffer();
		for(String x:s){
			sb.append(x);
		}
		return sb.toString();
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}

Measured memory_bytes: 36316
#include<stdio.h>
int main()
{

    int A,B;
    scanf("%d%d",&A,&B);

    if(A>=0&&A<=5){

        printf("0\n");
    }
   else  if(A>=6&&A<=12){

        printf("%d\n",B/2);
    }
   else if(A>=13&&A<=100){

        printf("%d\n",B);
    }
    return 0;




}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    string s;cin>>s;
    int res=0;
    for(int i=0;i<4;i++){
        if(s[i]=='+') res++;
        else res--;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iterator>
#include <random>
#include <cassert>
#include <iomanip>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cout<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef vector<int> vi;
typedef vector<lint> vl;
typedef vector<char> vc;
typedef vector<vector<int>> vii;
typedef vector<vector<lint>> vll;
typedef vector<vector<char>> vcc;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}
const double EPS = 1e-10;
const double PI = acos(-1);

class DDigitSumReplace {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int M;
        in>>M;
        lint res = 0, ans = 0;
        while(M--){
            lint d, c;
            in>>d>>c;
            res += d * c % 9;
            ans += d * c / 9 + c;
        }
        ans += res / 9;
        if(res%9==0) --ans;
        out<<ans-1<<'\n';
    }
};


int main() {
	DDigitSumReplace solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<ctime>
#include<complex>
#include<list>
#include<limits.h>
using namespace std;

typedef pair<int,int> pii;
int n,k,pre=-1;
vector<pii> vpn;
vector<int> ans;

int main(){
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;i++){
		int x;
		scanf("%d",&x);
		vpn.push_back(pii(x,i));
	}
	k++;
	while(k--){
		sort(vpn.begin(),vpn.end());
		reverse(vpn.begin(),vpn.end());
		for(int i=0;i<n;i++) if(pre!=vpn[i].second){
			vpn[i].first--;
			if(vpn[i].first<0){
				puts("-1");
				return 0;
			}
			ans.push_back(vpn[i].second);
		}
		pre=ans[ans.size()-1];
//		printf("%d\n",pre);
	}
	printf("%d\n",ans.size());
	for(int i=0;i<ans.size();i++) printf("%d ",ans[i]+1);
	puts("");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <cstring>
 
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define MP make_pair
#define X first
#define Y second
#define all(v) v.begin(), v.end()
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> P;

const int INF = 1<<29;

int main(){
	int d, n, m;
	while(cin >> d, d){
		cin >> n >> m;
		vector<int> shop(n-1);
		rep(i, n-1) cin >> shop[i];
		shop.push_back(-1);
		shop.push_back(0);
		shop.push_back(d);
		sort(all(shop));
		int ans = 0;
		rep(i, m){
			int k;
			cin >> k;
			int pos = lower_bound(all(shop), k) - shop.begin();
			ans += min(abs(k-shop[pos]), abs(k-shop[pos-1]));
		}
		cout << ans << endl;
	}

    return 0;
}

Measured memory_bytes: 1792
using System;
class Program
 {
   	static void Main(string[] args)
        {
    　　	string a = Console.ReadLine(); //標準入力
		string[] aa = a.Split(' ');
		

	       	int A = int.Parse(aa[0]);
	       	int B = int.Parse(aa[1]);
       	
      	int num = 0;
      int count = 0;
		if(A>B){
          num = B;
          count = A;
        }else{
          num = A;
          count = B;
        }
		string st="";
		for(int i = 0;i<count;i++){
          st = st + num.ToString();
        }
     		Console.WriteLine("{0}", st);
        }
 
 }

Measured memory_bytes: 27212
#include<iostream>
#include<iomanip>
#include<algorithm>
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS )
using namespace std;

class Point {
public:
	double x, y;

	Point(double x = 0, double y = 0) :x(x), y(y) {}
	Point operator + (Point p) {
		return Point(x + p.x, y + p.y); 
	}
	Point operator - (Point p) {
		return Point(x - p.x, y - p.y);
	}
	Point operator * (double a) {
		return Point(a * x, a * y);
	}
	Point operator / (double a) {
		return Point(x / a, y / a);
	}

	double abs() {
		return sqrt(norm());
	}
	double norm() {
		return x * x + y * y;
	}

	bool operator < (const Point &p)const {
		return x != p.x ? x < p.x : y < p.y;
	}

	bool operator == (const Point &p)const {
		return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
	}
};

typedef Point Vector;

double dot(Vector a, Vector b) {
	return a.x * b.x + a.y * b.y;
}

double cross(Vector a, Vector b) {
	return a.x * b.y - a.y * b.x;
}

Point reflection(Point p, Point p1, Point p2) {
	Vector hypo = p - p1, base = p2 - p1;
	return p + ((p1 + base * dot(hypo, base) / base.norm()) - p) * 2;
}


int main() {
	int i, q, x, x1, x2, y, y1, y2;
	Point ans;
	cin >> x1 >> y1 >> x2 >> y2 >> q;
	Point p1(x1, y1), p2(x2, y2);
	for (i = 0; i < q; i++) {
		cin >> x >> y;
		Point p(x, y);
		ans = reflection(p, p1, p2);
		cout << setprecision(15) << ans.x << " " << ans.y << endl;
	}
	return 0;
}

Measured memory_bytes: 3276
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
#include<cassert>
using namespace std;
#include<atcoder/all>
using namespace atcoder;


#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 998244353;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

using mint = modint998244353;

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

/////////////////////////////////////
template<typename T>
struct BIT {
	ll n;
	vector<T> bt;
	ll sz;

	BIT(ll n0) {
		n = n0;
		sz = 1;
		while (sz < n) { sz *= 2; }
		bt.assign(sz + 1, 0);
	}

	ll sum(ll i) {
		T ret = 0;
		for (ll x = i; x > 0; x -= x & (-x)) {
			ret += bt[x];
		}
		return ret;
	}

	void add(ll i, ll w) {
		for (ll x = i; x <= sz; x += x & (-x)) {
			bt[x] += w;
		}
		return;
	}
};



template <typename T>
ll tento(ll N, vector<T> A) {
	vector<pair<T, ll>> p(N + 1);

	repn(i, N) p[i] = { A[i],i };
	sort(++p.begin(), p.end());

	BIT<T> bit(N);
	ll ret = 0;

	repn(i, N) {
		ll t = p[i].second;
		ret += bit.sum(t);
		bit.add(t, 1);
	}

	//ret = N * (N - 1) / 2 - ret;
	return ret;
}


mint op(mint a, mint b) { return a + b; }
mint e() { return 0; }

int main() {
	ll K;
	cin >> K;
	rep(i, K)cout << "ACL";
	cout << endl;
}


Measured memory_bytes: 3660
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace ABC174
{
    class Program
    {
        static void Main(string[] args)
        {
            //var NK = Console.ReadLine().Split().Select(long.Parse).ToArray();
            //var p = Console.ReadLine().Split().Select(long.Parse).OrderBy(x => x).ToArray();
            // var CA = Enumerable.Repeat(0, (int)N).Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();
            //var AB = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var N = long.Parse(Console.ReadLine());
            var S = Console.ReadLine();

            var Wcount = 0;
            var Rcount = S.Count(x => x == 'R');

            for (int i = 0; i < N; i++)
            {
                if (S[i] == 'W') Wcount++;
                else Rcount--;

                if (Wcount == Rcount) { Console.WriteLine(Wcount); return; }

            }
            Console.WriteLine(0);
        }
    }
}


Measured memory_bytes: 28548
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <math.h>
#include <cmath>
#include <ctime>
#include <stdlib.h>

using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define m_p make_pair
#define m_t make_tuple
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
typedef pair<int, int> P;

const double pai = 3.1415926535897;
const int mod = 1000000007;
const int INF = 1000000021;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];


//x未満の要素数を返す二分探索関数
int b_s(vector<int>& vec, int xx) {
	return lower_bound(all(vec), xx) - vec.begin();
}
template<typename T>void vecout(vector<T>& vec) { for (T t : vec) cout << t << " "; cout << endl; }
template<typename TT>void vecin(vector<TT>& vec) {
	for (int i = 0; i < vec.size(); i++) {
		cin >> vec[i];
	}
}
template<class tt> struct counter {
	map<tt, int>mp;
	bool add(tt t, int xx) {
		if (!mp.count(t)) {
			mp[t] = xx;
			return true;
		}
		mp[t] += xx;
		if (!mp[t]) {
			mp.erase(t);
		}
		return false;
	}

};

// テーブルを作る前処理
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;
	}
}

//n個を1個以上のx組のグループに分ける重複組み合わせはcom(n-1,x-1)
long long 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;
}
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
long long modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

bool chmax(int& xx, int yy) {
	if (xx < yy) {
		xx = yy;
		return true;
	}
	return false;
}
bool chmin(int& xx, int yy) {
	if (xx > yy) {
		xx = yy;
		return true;
	}
	return false;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	if (xx <= 1) {
		return 0;
	}
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}



signed main() {
	int n,a=0;
	cin >> n;
	for (int i = 1; i < 10000; i++) {
		if (i * (i + 1) / 2 >= n) {
			a = i;
			break;
		}
	}
	for (int i = a; i > 0; i--) {
		if (i <= n) {
			cout << i << endl;
			n -= i;
		}
	}
}

Measured memory_bytes: 3580
if __name__ == '__main__':
    s = int(input())
    a = [int(i) for i in input().split()]
    count = 0

    for i in range(0,s-2):
        for j in range(i,s-1):
            if a[i] != a[j]:
                for k in range(j,s):
                    if a[i] != a[k] and a[j] !=a[k] and a[i]+a[j] > a[k] and a[j] +a[k] > a[i] and a[k] +a[i]>a[j]:
                        count+=1
    print(count)

Measured memory_bytes: 9204
#pragma GCC optimize("Ofast")
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define L(i,u) for (int i=head[u]; i!=0; i=nxt[i])
#define rep(i,a,b) for (register int i=a; i<=b; i++)
#define per(i,a,b) for (register int i=a; i>=b; i--)
typedef long long ll;
using namespace std;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
const int N = 1500000; const double eps = 1e-9;
int s[N],len;
ll ans[N]; int size,dig[N];
//Vi res;
ll getdig(ll x) {ll res=0; while (x)res+=x%10,x/=10; return res;}
bool ok(int dig, ll x) {
	int cnt=0,pre=0; rep(i,1,len) if (s[i]==9)cnt=i; else break;
	per(i,len,cnt+1) pre=10*pre+s[i];
	ll mi=1; rep(i,1,cnt) mi*=10;
	
	
	rep(i,1,60) if (1LL*((pre+1)*mi-1)*getdig(1LL*((pre+1+i)*mi-1))>1LL*((pre+1+i)*mi-1)*(dig)) {
	//	if (dig==117 && x == 9999999999999) printf("i = %d\n",i);
		return 0;
	}
	return 1;
}
void dfs(int x) {
	if (len>15) return;
	if (!x) {
		++size; dig[size]=ans[size]=0;
		per(i,len,1) dig[size]+=s[i],ans[size]=10*ans[size]+s[i];
	//	if (ans[size]==9999999999999&&dig[size]==getdig(ans[size])) printf("OWO %d %d\n",dig[size],ok(dig[size],ans[size]));
		if (!ok(dig[size],ans[size])) {size--;}
		return;
	}
	if (x>27) {s[++len]=9; x-=9; dfs(x); return;}
	if (len>3&&s[len-3]!=9) return;
	rep(i,0,min(9,x)) {s[++len]=i; dfs(x-i); len--;}
}
int main() { //freopen("1.in","r",stdin);
//	cerr << ok(getdig(9999999999999),9999999999999);

	rep(i,1,140) {
		len=0;dfs(i);
	}
	sort(ans+1,ans+size+1);
	cerr << size <<endl;
//	cerr << ans[size] <<endl;
//	rep(i,1,size)printf("%lld,",ans[i]);
	int k; read(k);
	rep(i,1,k) printf("%lld\n",ans[i]);
	return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; ++i)
#define all(x) begin(x), end(x)
#define gets(s) fgets(s,size(s),stdin)
using namespace std;
typedef long long ll;
typedef string str;
template<typename T>
using vec=vector<T>;
template<typename T>
using uset=unordered_set<T>;
template<typename T,typename S>
using umap=unordered_map<T,S>;
const size_t mbs = sizeof(bitset<1>)*8;
template<size_t N>
using bit=bitset<mbs*((N+mbs-1)/mbs)>;
 
const int mod=1000000007;
const double pi=3.1415926535;
const int maxn=1000001;

vec<int> v(maxn);
bit<maxn> b;

int main() {
    int n;
    scanf("%d",&n);
    vec<int> a(n);
    rep(i,n) {
        scanf("%d",&a[i]);
        v[a[i]]++;
    }
    auto m=*max_element(all(a));
    rep(i,n) {
        if(v[a[i]]>1 && !b[a[i]]) b[a[i]]=true;
        for(int j=a[i]*2; j<=m; j+=a[i]) if(!b[j]) b[j]=true;
    }
    int ans=0;
    rep(i,n) if(!b[a[i]]) ans++;
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 8048
#include <stdio.h> 
 
int 
main(){
	int N;
	char s[5010];
	scanf("%d",&N);scanf("%s",s);
	int i,j,k,len=0;
	int cnt = 0;
	for(i=0;i<=N-1-len;i++){
		for(j=i+len; j<=N-len;j++)
		{
			cnt = 0;
			for(k=0; i+k < j && j+k < N; k++){
				if(s[i+k]==s[j+k])cnt++;
				else break;				
			}
			if(len <cnt) len = cnt;
		}
	}
	printf("%d\n",len);
 return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

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

    int N, W;
    while (cin >> N >> W) {
        vll w(N), v(N);
        rep(i, N)cin >> w[i] >> v[i];

        vll vs[4];
        rep(i, 4)vs[i].push_back(0);
        rep(i, N) {
            vs[w[i] - w[0]].push_back(v[i]);
        }

        rep(i, 4) {
            sort(vs[i].rbegin(), vs[i].rend() - 1);
            partial_sum(all(vs[i]), vs[i].begin());
        }

        ll ans = 0;
        rep(i, sz(vs[0]))rep(j,sz(vs[1]))rep(k,sz(vs[2])){
            ll x = w[0] * i + (w[0] + 1)*j + (w[0] + 2)*k;
            if (x <= W) {
                ll y = W - x;
                ll l = min(y / (w[0] + 3), sz(vs[3])-1ll);
                ll u = vs[0][i] + vs[1][j] + vs[2][k] + vs[3][l];
                smax(ans, u);
            }
        }

        cout << ans << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int N;
  int L[11];
  cin >> N;
  for (int i=0; i<N; i++) {
    cin >> L[i];
  }
  sort(L, L+N);
  int s = 0;
  for (int i=0; i<N-1; i++) {
    s += L[i];
  }
  if (L[N-1] < s) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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


int main() {
	std::vector<int> a;
	std::vector<int> ds;
	int k,n;
	cin >> k >> n;
	a.resize(n);
	ds.resize(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < n; i++)
	{
		ds[i] = a[(i + 1) % n] - a[i];
	}
	ds.back() += k;
	std::list<int> b{ ds.begin(),ds.end() };
	b.sort();
	cout << (k - b.back()) << endl;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define int long long
  #define endl "\n"
  #define all(v) v.begin(),v.end()
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<< ": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  const int N = 200005;



int32_t main()
{


    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    IOS

    int n,a,b;
    cin >> n >> a >> b;

    string s;
    cin >> s;

    int passed1 = 0;
    int passed2 = 0;

    for(int i = 0; i < n; i++)
    {
      if(s[i] == 'a')
      {
        if(passed1 < a + b)
        {
          cout << "Yes" << endl;
          passed1++;
        }
        else
        {
          cout << "No" << endl;
        }
      }
      else if(s[i] == 'b')
      {
        if(passed1 < a + b and passed2 < b)
        {
          cout << "Yes" << endl;
          passed1++;
          passed2++;
        }
        else
        {
          cout << "No" << endl;
        } 

      }
      else
      {
        cout << "No" << endl;
      }
    } 




    return 0;
}


Measured memory_bytes: 3784
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scn = new Scanner(System.in);
		int x = scn.nextInt();
      	int n = scn.nextInt();
		int[] p = new int[n];
		for(int i=0; i<n; i++){
			p[i] = scn.nextInt();
		}
      	int ans = x;
      	int num = x;
      	for(int i=0; i<n; i++){
          if(ans==p[i]){
            ans++;
            i=-1;
          }
        }
      	for(int i=0; i<n; i++){
          if(num==p[i]&&ans>0){
            num--;
            i=-1;
          }
        }
      	if(Math.abs(ans-x)>=Math.abs(num-x)) {
		System.out.println(num);
		}else {
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 35936
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <map>
#include <queue>
#define N 1010
#define ll long long
#define mo ((ll)1e9+7)
//10000000000037ll
//21993833369ll
#define db double
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define drep(i,a,b) for(int i=a;i>=b;--i)
#define mst(a,b) memset(a,b,sizeof(a))
using namespace std;
bool cmp(int a, int b) {return a > b;}
inline int read() {
	int x = 0, f = 1; 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();}
	return x * f;
}
int main() {
	ll x, k, d;
	scanf("%lld%lld%lld", &x, &k, &d);
	if (x < 0)x *= -1ll;
	ll tmp = min(k, x / d);
	k -= tmp, x -= tmp * 1ll * d;
	if (k & 1)x -= d;
	printf("%lld\n", (ll)fabs(x));
	return 0;
}


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

int main()
{
    int N;
    cin >> N;
    int K;
    cin >> K;
    long long h[100010];
    long long dp[100010];

    // initialize array
    memset(h, 0, sizeof(h));
    memset(dp, 1, sizeof(dp));

    for (int i = 0; i < N; i++)
    {
        cin >> h[i];
    }

    // dp
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    if (N == 2)
    {
        cout << dp[1] << endl;
        return 0;
    }

    for (int i = 2; i < N; i++)
    {
        for (int k = 1; k <= min(i, K); k++)
        {
            dp[i] = min(
                dp[i],
                dp[i - k] + abs(h[i] - h[i - k]));
        }
    }

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

Measured memory_bytes: 1792
#組み合わせ
def comb(a, b):
    if b > a - b:
        return comb(a, a-b)
    ansMul = 1
    ansDiv = 1
    for i in range(b):
        ansMul *= a - i
        ansDiv *= i + 1

    ans = ansMul // ansDiv
    return ans

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

dp = [[0] * (N+1) for _ in range(N+1)]

for i in range(N):
    for j in range(N):
        if j > i:
            continue
        dp[i+1][j+1] = max(dp[i+1][j+1], (dp[i][j] * j + v[i]) / (j + 1))
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])

ans = 0
for i in range(A, B+1):
    ans = max(ans, dp[N][i])

v.sort()
v.reverse()

c = v.count(v[0])
cnt = 0
if v[0] == v[A-1]:
    for i in range(A, B+1):
        if c < i:
            break
        cnt += comb(c, i)
else:
    a = v[:A].count(v[A-1])
    all_a = v.count(v[A-1])
    cnt = comb(all_a, a)

print(ans)
print(cnt)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  vector<int> data(26);
  for(int i = 0; i < 4; i++){
    data.at(S.at(i) - 'A')++;
  }
  int count = 0;
  for(int i = 0; i < 26; i++){
    if(data.at(i) == 2)count++;
  }
  if(count == 2)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
int main() {
	int n;
	cin >> n;
	map<string, int> hogea;
	string s;
	cin >> s;
	hogea[s] = 1;
	REP(i, n-1) {
		string b;
		cin >> b;
		if (hogea[b] == 1||s[s.length() - 1] != b[0]) {
			cout << "No" << endl;
			return 0;
		}
		hogea[b] = 1;
		s = b;
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 888
#include<cstdio>
#include<cmath>
int n,t,x,y,a,b;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d%d",&t,&x,&y);
		int k=fabs(x-a)+fabs(y-b);
		if(k>t)
		{
			printf("No");
			return 0;
		}
		else if(k<t)
				if((k-t)%2)
				{
					printf("No");
					return 0;
				}
	}
	printf("Yes");
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int w, h, x, y, r;

  scanf("%d%d%d%d%d", &w, &h, &x, &y, &r);
  if(x - r >= 0 && x + r <= w && y - r >= 0 && y + r <= h){
    printf("Yes\n");
  }else{
    printf("No\n");
  }

  return 0;
}

Measured memory_bytes: 584