#include #define fi first #define se second #define rep(i,s,n) for (int i = (s); i < (n); ++i) #define rrep(i,g,n) for (int i = (n)-1; i >= (g); --i) #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define len(x) (int)(x).size() #define dup(x,y) (((x)+(y)-1)/(y)) #define pb push_back #define eb emplace_back #define Field(T) vector> using namespace std; using ll = long long; using ull = unsigned long long; template using pq = priority_queue,greater>; using P = pair; templatebool chmax(T&a,T b){if(abool chmin(T&a,T b){if(b dp(n+1, 0); dp[0] = 0; rep(x,1,n+1) rep(y,0,x) { if ((x^y) != a && (x^y) != b && (x^y) != c) { dp[x] = max(dp[x], dp[y]+1); } } rep(i,0,n+1) { cout << dp[i] << " "; } cout << endl; } int main() { ll n, a, b, c; cin >> n >> a >> b >> c; // naive(n, a, b, c); vector flg(3); if (__builtin_popcount(a+1) == 1) flg[0] = 1; if (__builtin_popcount(b+1) == 1) flg[1] = 1; if (__builtin_popcount(c+1) == 1) flg[2] = 1; if (flg[0]+flg[1]+flg[2] == 0) { cout << n << endl; return 0; } else if (flg[0]+flg[1]+flg[2] == 1) { int x = 0; if (flg[0]) x = 64-__builtin_clzll(a); if (flg[1]) x = 64-__builtin_clzll(b); if (flg[2]) x = 64-__builtin_clzll(c); if (n < (1LL<<(x-1))) { cout << n << endl; } else { cout << n-((n-(1LL<<(x-1)))/(1LL< y) swap(x, y); if (x >= 2) { ll k1 = 0, k2 = 0; if (n >= (1LL<<(x-1))) { k1 = (n-(1LL<<(x-1)))/(1LL<= (1LL<<(y-1))) { k2 = (n-(1LL<<(y-1)))/(1LL<