fork download
  1. #pragma GCC optimize("Ofast")
  2. #include <cstring>
  3. #include <numeric>
  4. #include <set>
  5. #include <iomanip>
  6. #include <algorithm>
  7. #include <queue>
  8. #include <memory>
  9. #include <cassert>
  10. #include <vector>
  11. #include <utility>
  12. #include <iostream>
  13. #include <string>
  14. //#define assert(x) ;
  15. #define pb push_back
  16. #define REP_ANY(type,i,l,r) for(type i = l; i <= r; ++i)
  17. #define REP_INT(i,l,r) for(int i = l; i <= r; ++i)
  18. #define GET_REP_MACRO(_1,_2,_3,_4,NAME,...) NAME
  19. #define rep(...) GET_REP_MACRO(__VA_ARGS__,REP_ANY,REP_INT)(__VA_ARGS__)
  20. #define all(v) (v).begin(), (v).end()
  21. #define sz(v) ll(v.size())
  22. #define watch(x) cerr << (#x) << " = " << x << '\n'
  23. #define X first
  24. #define Y second
  25. #define T1 template<typename T> static
  26. using namespace std;
  27. typedef long long ll;
  28. typedef unsigned int uint;
  29. typedef unsigned char uchar;
  30. typedef unsigned long long ull;
  31. typedef vector<int> vi;
  32. typedef vector<string> vs;
  33. typedef vector<vi> vvi;
  34. typedef pair<int, int> pii;
  35. typedef vector<pii> vpii;
  36. bool saving = true;
  37.  
  38.  
  39. const ll MOD = 1e9 + 7;
  40.  
  41. ll ipow(ll x, ll p, ll mod = MOD){
  42. if(abs(x) >= mod)
  43. x %= mod;
  44. if(x < 0)
  45. x += mod;
  46. if(p == 0)
  47. return 1;
  48. if(p == 1)
  49. return x;
  50. return ipow(x * x % mod, p / 2, mod) * ipow(x, p % 2, mod) % mod;
  51. }
  52. T1 ostream& operator<<(ostream& stream, const vector<T>& t);
  53. template <typename F, typename S> static
  54. ostream& operator<<(ostream& stream, const pair<F, S>& t){
  55. return stream << t.first << ' ' << t.second;
  56. }
  57. template <typename F, typename S> static
  58. istream& operator>>(istream& stream, pair<F, S>& t){
  59. return stream >> t.first >> t.second;
  60. }
  61. T1 vector<T> unique(vector<T>& arr){
  62. sort(all(arr));
  63. arr.erase(unique(all(arr)), arr.end());
  64. return arr;
  65. }
  66. static string unique(string& s){
  67. sort(all(s));
  68. s.erase(unique(all(s)), s.end());
  69. return s;
  70. }
  71. T1 istream& read(T, T, istream& = cin);
  72. T1 istream& operator>>(istream& stream, vector<T>& t){
  73. return read(all(t), stream);
  74. }
  75. T1 istream& read(T b, T e, istream& stream){
  76. for(T it = b; it != e; ++it)
  77. stream >> *it;
  78. return stream;
  79. }
  80. struct DSU{
  81. vi par;
  82. int n;
  83. DSU(int _n):n(_n){
  84. par.resize(n + 1);
  85. iota(all(par), 0);
  86. }
  87. int getpar(int u){
  88. if(par[par[u]] == par[u])
  89. return par[u];
  90. return par[u] = getpar(par[u]);
  91. }
  92. bool unite(int u, int v){
  93. u = getpar(u);
  94. v = getpar(v);
  95. if(u == v)
  96. return false;
  97. par[u] = v;
  98. return true;
  99. }
  100. };
  101. T1 T sum(vector<T>& arr){
  102. T ans = 0;
  103. for(auto x : arr)
  104. ans += x;
  105. return ans;
  106. }
  107. T1 T sum(vector<T>&& arr){
  108. T ans = 0;
  109. for(auto x : arr)
  110. ans += x;
  111. return ans;
  112. }
  113. template <typename COST_TYPE = ll>
  114. struct MaxFlow{
  115. const COST_TYPE COST_INF = numeric_limits<COST_TYPE>::max();
  116. const ll FLOW_INF = 1e18;
  117. bool needs_prep;
  118. struct FlowTracker{
  119. ll *cap, *rcap;
  120. shared_ptr<ll> flow;
  121. bool dir;
  122. FlowTracker(){
  123. dir = 0;
  124. cap = rcap = NULL;
  125. }
  126. FlowTracker(ll *_cap, ll *_rcap, shared_ptr<ll> _flow, int _dir)
  127. :cap(_cap), rcap(_rcap), flow(_flow), dir(_dir){
  128. }
  129. ll rem()const{
  130. if(dir == 0){
  131. return *cap - *flow;
  132. }else{
  133. return *rcap + *flow;
  134. }
  135. }
  136. void add_flow(ll f){
  137. if(dir == 0)
  138. *flow += f;
  139. else
  140. *flow -= f;
  141. assert(*flow <= *cap);
  142. assert(-*flow <= *rcap);
  143. }
  144. operator ll()const{
  145. return rem();
  146. }
  147. void clear(){
  148. *flow = 0;
  149. }
  150. void operator-=(ll x){
  151. add_flow(x);
  152. }
  153. void operator+=(ll x){
  154. add_flow(-x);
  155. }
  156. };
  157. struct Edge{
  158. int u, v;
  159. ll c, rc;
  160. COST_TYPE cost;
  161. FlowTracker flow;
  162. Edge(){}
  163. Edge(int _u, int _v, ll _c, COST_TYPE _cost = 0)
  164. :u(_u), v(_v), c(_c), cost(_cost){
  165. rc = 0;
  166. }
  167. void change_cap(ll _c, ll _rc = 0){
  168. c = _c;
  169. rc = _rc;
  170. }
  171. };
  172. int source, sink, rt_source, rt_sink;
  173. MaxFlow(int _source = numeric_limits<int>::min(), int _sink = numeric_limits<int>::min() + 1):source(_source), sink(_sink){
  174. needs_prep = true;
  175. }
  176. vector<vector<int>> adj;
  177. vector<vector<COST_TYPE>> cost;
  178. vector<vector<FlowTracker>> cap;
  179. vector<Edge> edges;
  180. int add_edge(int u, int v, ll c, COST_TYPE cost = 0){
  181. needs_prep = true;
  182. edges.push_back(Edge(u, v, c, cost));
  183. return sz(edges) - 1;
  184. }
  185. vector<int> now, lvl;
  186. vector<COST_TYPE> pot;
  187. vi indices;
  188. void prep(){
  189. if(!needs_prep){
  190. for(auto &_ : edges)
  191. _.flow.clear();
  192. return;
  193. }
  194. needs_prep = false;
  195. indices = vi{source,sink};
  196. for(auto& edge : edges){
  197. indices.push_back(edge.u);
  198. indices.push_back(edge.v);
  199. }
  200. sort(indices.begin(), indices.end());
  201. indices.erase(unique(indices.begin(), indices.end()), indices.end());
  202. rt_source = lower_bound(indices.begin(), indices.end(), source) - indices.begin();
  203. rt_sink = lower_bound(indices.begin(), indices.end(), sink) - indices.begin();
  204. adj.clear();
  205. cost.clear();
  206. cap.clear();
  207. now.clear();
  208. lvl.clear();
  209. pot.clear();
  210. int max_id = sz(indices) - 1;
  211. adj.resize(max_id + 1);
  212. cost.resize(max_id + 1);
  213. cap.resize(max_id + 1);
  214. now.resize(max_id + 1);
  215. lvl.resize(max_id + 1);
  216. pot.resize(max_id + 1);
  217.  
  218. vi ordering(sz(edges));
  219. iota(all(ordering),0);
  220. random_shuffle(all(ordering));
  221.  
  222. for(int id : ordering){
  223. auto &edge = edges[id];
  224. int u = lower_bound(indices.begin(), indices.end(), edge.u) - indices.begin();
  225. int v = lower_bound(indices.begin(), indices.end(), edge.v) - indices.begin();
  226. auto flow = make_shared<ll>(0);
  227. adj[u].push_back(v);
  228. cost[u].push_back(edge.cost);
  229. cap[u].push_back(FlowTracker(&edge.c, &edge.rc, flow, 0));
  230. if(u != v){
  231. adj[v].push_back(u);
  232. cost[v].push_back(-edge.cost);
  233. cap[v].push_back(FlowTracker(&edge.c, &edge.rc, flow, 1));
  234. }
  235. assert(cap[u].back() == edge.c);
  236. edge.flow = cap[v].back();
  237. }
  238. }
  239. int get_name(int x){
  240. auto it = lower_bound(all(indices),x);
  241. if(it == indices.end() || *it != x){
  242. indices.pb(x);
  243. unique(indices);
  244. needs_prep = true;
  245. it = lower_bound(all(indices),x);
  246. }
  247. assert(*it == x);
  248. return it-indices.begin();
  249. }
  250. void set_source(int _source){
  251. if(source == _source) return;
  252. source = _source;
  253. rt_source = get_name(source);
  254. }
  255. void set_sink(int _sink){
  256. if(sink == _sink) return;
  257. sink = _sink;
  258. rt_sink = get_name(sink);
  259. }
  260. void bellman_ford(){
  261. vector<COST_TYPE> dist(sz(adj), COST_INF);
  262. dist[rt_source] = 0;
  263. //for(int times = 0; times < sz(dist); ++times){
  264. while(true){
  265. bool changes = false;
  266. for(int u = 0; u < sz(adj); ++u)
  267. for(int i = 0; i < sz(adj[u]); ++i){
  268. int v = adj[u][i];
  269. if(dist[u] != COST_INF && cap[u][i]){
  270. if(dist[v] > dist[u] + cost[u][i]){
  271. changes = true;
  272. dist[v] = dist[u] + cost[u][i];
  273. }
  274. }
  275. }
  276. if(!changes)
  277. break;
  278. }
  279. pot = dist;
  280. }
  281. ll dijkstra(vector<COST_TYPE>& dist, vector<int>& last_node, vector<int>& last_index){
  282. dist[rt_source] = 0;
  283. vector<ll> flow(sz(dist));
  284. flow[rt_source] = FLOW_INF;
  285. vector<bool> visited(sz(dist));
  286. priority_queue<pair<COST_TYPE, int>> pq;
  287. pq.push({0, rt_source});
  288. while(!pq.empty()){
  289. int u = pq.top().second;
  290. pq.pop();
  291. if(visited[u])
  292. continue;
  293. visited[u] = true;
  294. assert(dist[u] != COST_INF);
  295. for(int i = 0; i < sz(adj[u]); ++i){
  296. int v = adj[u][i];
  297. if(!visited[v] && cap[u][i])
  298. if(dist[u] + cost[u][i] + pot[u] - pot[v] < dist[v]){
  299. dist[v] = dist[u] + cost[u][i] + pot[u] - pot[v];
  300. last_node[v] = u;
  301. last_index[v] = i;
  302. flow[v] = min(flow[u], (ll)cap[u][i]);
  303. pq.push({-dist[v], v});
  304. }
  305. }
  306. }
  307. return flow[rt_sink];
  308. }
  309. pair<ll, COST_TYPE> min_cost_flow(int _source, int _sink){
  310. set_source(_source);
  311. set_sink(_sink);
  312. prep();
  313. bool has_negative = false;
  314. for(auto& edge : edges)
  315. if(edge.cost < 0)
  316. has_negative = true;
  317. if(has_negative)
  318. bellman_ford();
  319. ll total_flow = 0;
  320. COST_TYPE total_cost = 0;
  321. while(true){
  322. vector<COST_TYPE> dist(sz(adj), COST_INF);
  323. vector<int> last_node(sz(dist)), last_index(sz(dist));
  324. ll flow = dijkstra(dist, last_node, last_index);
  325. if(flow == 0)
  326. break;
  327. for(int u = rt_sink; u != rt_source; u = last_node[u])
  328. cap[last_node[u]][last_index[u]] -= flow;
  329. for(int i = 0; i < sz(adj); ++i)
  330. pot[i] = pot[i] + dist[i];
  331. total_flow += flow;
  332. total_cost += pot[rt_sink] * flow;
  333. }
  334. return {total_flow, total_cost};
  335. }
  336. pair<ll, COST_TYPE> min_cost_flow(){
  337. return min_cost_flow(source, sink);
  338. }
  339. };
  340. T1 T max(const vector<T> arr){
  341. assert(!arr.empty());
  342. T ans = arr[0];
  343. for(auto& cur : arr)
  344. ans = max(ans, cur);
  345. return ans;
  346. }
  347. T1 T min(const vector<T>& arr){
  348. assert(!arr.empty());
  349. T ans = arr[0];
  350. for(auto& cur : arr)
  351. ans = min(ans, cur);
  352. return ans;
  353. }
  354. T1 T max(const set<T>& s){
  355. assert(!s.empty());
  356. return *--s.end();
  357. }
  358. T1 T min(const set<T>& s){
  359. assert(!s.empty());
  360. return *s.begin();
  361. }
  362. T1 void print(T x, string end = "\n"){
  363. cout << x << end;
  364. }
  365. T1 void print(vector<vector<T>> arr){
  366. for(int i = 0; i < sz(arr); ++i){
  367. cout << "[" << arr[i] << "]";
  368. if(i + 1 < sz(arr))
  369. cout << ", ";
  370. }
  371. cout << '\n';
  372. }
  373. T1 ostream& print(T b, T e, string sep = " ", ostream& stream = cout){
  374. for(T it = b; it != e; ++it){
  375. stream << *it;
  376. if(it + 1 != e)
  377. stream << sep;
  378. }
  379. return stream;
  380. }
  381. T1 ostream& operator<<(ostream& stream, const vector<T>& t){
  382. for(int i = 0; i < sz(t); ++i){
  383. stream << t[i];
  384. if(i+1 < sz(t))
  385. stream << ' ';
  386. }
  387. return stream;
  388. }
  389. T1 void print(vector<T> arr, string sep = " "){
  390. if(arr.empty()){
  391. return;
  392. }
  393. print(arr.begin(), arr.end(), sep);
  394. cout << '\n';
  395. }
  396. typedef vector<ull> vull;
  397. typedef vector<vull> vvull;
  398. int n,type;
  399. vvull a;
  400. int dist[64][64];
  401. vs description;
  402. string last_oper;
  403. ull rx[4];
  404. #define REG string(1,'a'+pos)
  405. #define OPER if(saving){last_oper = string(__func__).substr(1)+last_oper;}
  406. ull *l64(int pos){
  407. string tmp = " r"+REG+"x";
  408. if(saving)
  409. last_oper = tmp+last_oper;
  410. return &rx[pos];
  411. }
  412. uint *l32(int pos){
  413. string tmp = " e"+REG+"x";
  414. if(saving)
  415. last_oper = tmp+last_oper;
  416. uint *a = reinterpret_cast<uint*>(&rx[pos]);
  417. return &a[0];
  418. }
  419. ushort *l16(int pos){
  420. string tmp = " "+REG+"x";
  421. if(saving)
  422. last_oper = tmp+last_oper;
  423. ushort *a = reinterpret_cast<ushort*>(&rx[pos]);
  424. return &a[0];
  425. }
  426. uchar *l8(int pos){
  427. string tmp = " "+REG+"l";
  428. if(saving)
  429. last_oper = tmp+last_oper;
  430. uchar *a = reinterpret_cast<uchar*>(&rx[pos]);
  431. return &a[0];
  432. }
  433. uchar *u8(int pos){
  434. string tmp = " "+REG+"h";
  435. if(saving)
  436. last_oper = tmp+last_oper;
  437. uchar *a = reinterpret_cast<uchar*>(&rx[pos]);
  438. return &a[1];
  439. }
  440. T1 void _inc(T *a){
  441. *a += 1;
  442. OPER;
  443. }
  444. T1 void _dec(T *a){
  445. *a -= 1;
  446. OPER;
  447. }
  448. T1 void _not(T *a){
  449. *a = ~*a;
  450. if(saving)
  451. last_oper = "not"+last_oper;
  452. }
  453. T1 void _and(T *a, T *b){
  454. *a = (*a) & (*b);
  455. OPER;
  456. }
  457. T1 void _or(T *a, T *b){
  458. *a = (*a) | (*b);
  459. OPER;
  460. }
  461. T1 void _xor(T *a, T *b){
  462. *a = (*a) ^ (*b);
  463. OPER;
  464. }
  465. T1 void _shl(T *a, T *b){
  466. *a = (*a) << (*b);
  467. OPER;
  468. }
  469. T1 void _shr(T *a, T *b){
  470. *a = (*a) >> (*b);
  471. OPER;
  472. }
  473. T1 void _add(T *a, T *b){
  474. *a = (*a) + (*b);
  475. OPER;
  476. }
  477. T1 void _sub(T *a, T *b){
  478. *a = (*a) - (*b);
  479. OPER;
  480. }
  481. T1 void _mul(T *a, T *b){
  482. *a = (*a) * (*b);
  483. OPER;
  484. }
  485. T1 void _div(T *a, T *b){
  486. //assert(b);
  487. *a = (*a) / (*b);
  488. OPER;
  489. }
  490. T1 void _mod(T *a, T *b){
  491. //assert(b);
  492. *a = (*a) % (*b);
  493. OPER;
  494. }
  495. T1 void _mov(T *a, T *b){
  496. *a = *b;
  497. OPER;
  498. }
  499. vvull all_visited;
  500. int cnt_op;
  501. template<typename T = ull*>
  502. void f(void (*oper)(T,T), int i, int j, T (*type)(int) = l64){
  503. ++cnt_op;
  504. oper(type(i),type(j));
  505. if(saving){
  506. description.pb(last_oper);
  507. all_visited.pb(vull(rx,rx+4));
  508. last_oper = "";
  509. }
  510. }
  511. void f(void (*oper)(uchar*,uchar*), int i, int j, uchar* (*typei)(int), uchar* (*typej)(int)){
  512. ++cnt_op;
  513. oper(typei(i),typej(j));
  514. if(saving){
  515. description.pb(last_oper);
  516. all_visited.pb(vull(rx,rx+4));
  517. last_oper = "";
  518. }
  519. }
  520. template<typename T = ull*>
  521. void f(void (*oper)(T), int i, T (*type)(int) = l64){
  522. ++cnt_op;
  523. oper(type(i));
  524. if(saving){
  525. description.pb(last_oper);
  526. all_visited.pb(vull(rx,rx+4));
  527. last_oper = "";
  528. }
  529. }
  530.  
  531. template<typename T = ull*>
  532. ull g(void (*oper)(T,T), int i, int j, T (*type)(int) = l64){
  533. ull old = rx[i];
  534. oper(type(i),type(j));
  535. last_oper = "";
  536. ull nxt = rx[i];
  537. rx[i] = old;
  538. return nxt;
  539. }
  540. ull g(void (*oper)(uchar*,uchar*), int i, int j, uchar* (*typei)(int), uchar* (*typej)(int)){
  541. ull old = rx[i];
  542. oper(typei(i),typej(j));
  543. last_oper = "";
  544. ull nxt = rx[i];
  545. rx[i] = old;
  546. return nxt;
  547. }
  548. template<typename T = ull*>
  549. ull g(void (*oper)(T), int i, T (*type)(int) = l64){
  550. ull old = rx[i];
  551. oper(type(i));
  552. last_oper = "";
  553. ull nxt = rx[i];
  554. rx[i] = old;
  555. return nxt;
  556. }
  557. bool match(vull a, vull b){
  558. if(a.empty())
  559. return true;
  560. sort(all(a));
  561. sort(all(b));
  562. if(a.back() == b.back()){
  563. a.pop_back();
  564. b.pop_back();
  565. return match(a,b);
  566. }
  567. else{
  568. b.pop_back();
  569. return a == b;
  570. }
  571. }
  572. void check(vvull a){
  573. set<vull> seen;
  574. for(auto _ : a){
  575. sort(all(_));
  576. seen.insert(_);
  577. }
  578. for(auto _ : all_visited){
  579. sort(all(_));
  580. rep(i,0,3){
  581. vull tmp;
  582. rep(j,0,3)
  583. if(i != j)
  584. tmp.pb(_[j]);
  585. seen.erase(tmp);
  586. }
  587. }
  588. assert(seen.empty());
  589. }
  590. int bits(ll x){
  591. return __builtin_popcountll(x);
  592. }
  593. int get_type(){
  594. int evidence_3 = 0;
  595. set<ull> sums;
  596. set<ull> vals;
  597. for(auto _ : a){
  598. if(_[2]-_[1] == _[1]-_[0]){
  599. ++evidence_3;
  600. }
  601. sums.insert(sum(_));
  602. vals.insert(_[0]);
  603. vals.insert(_[1]);
  604. vals.insert(_[2]);
  605. }
  606. if(evidence_3 >= n) return 3;
  607. if(sz(sums) == 1) return 5;
  608. if(sz(vals) <= 3*n-10) return 4;
  609. bool can_2 = true;
  610. for(auto _ : a){
  611. if(bits(_[0]^_[1]) > 4)
  612. can_2 = false;
  613. if(bits(_[0]^_[2]) > 4)
  614. can_2 = false;
  615. }
  616. if(can_2)
  617. return 2;
  618. return 1;
  619. }
  620. string B(ull x){
  621. string ans;
  622. rep(i,0,63){
  623. if(i && i%8 == 0)
  624. ans.pb(' ');
  625. ans.pb(x%2+'0');
  626. x >>= 1;
  627. }
  628. return ans;
  629. }
  630. vull sx;
  631. void save_state(){
  632. assert(sx.empty());
  633. sx = vull(rx,rx+4);
  634. }
  635. void load_state(){
  636. assert(!sx.empty());
  637. rep(i,0,3)
  638. rx[i] = sx[i];
  639. sx.clear();
  640. }
  641. vull get_state(){
  642. return vull(rx,rx+4);
  643. }
  644. void set_state(vull _state){
  645. rep(i,0,sz(_state)-1)
  646. rx[i] = _state[i];
  647. }
  648. ull choose(ull x, ull g){
  649. ull m = (ull(1)<<48)+(ull(1)<<32)+(ull(1)<<16);
  650. rep(t,0,1){
  651. rep(i,0,7)
  652. if((((x*m)^g)>>(48+i))%2)
  653. x ^= ull(1)<<i;
  654. rep(i,8,15)
  655. if((((x*m)^g)>>(16+i))%2)
  656. x ^= ull(1)<<i;
  657. rep(i,24,31)
  658. if((((x*m)^g)>>(16+i))%2)
  659. x ^= ull(1)<<i;
  660.  
  661. rep(i,40,47)
  662. if((((x*m)^g)>>(16+i))%2)
  663. x ^= ull(1)<<i;
  664. }
  665.  
  666. ull mask = (-1ull)^((ull(1)<<40)-1)^((ull(1)<<32)-1)^((ull(1)<<24)-1);
  667. if((((x*m)^g)&mask))
  668. throw 1;
  669. return x;
  670. }
  671. ull fbin(string s){
  672. ull ans = 0;
  673. reverse(all(s));
  674. for(char c : s){
  675. ans <<= 1;
  676. ans += c-'0';
  677. }
  678. return ans;
  679. }
  680. void make_rx3_rem(){
  681. ull rem = 0;
  682. rem ^= 1ull<<32;
  683. rem ^= 1ull<<16;
  684. if((rx[3]&rx[0])==rem)
  685. f(_and,3,0);
  686. else if((rx[3]&rx[1])==rem)
  687. f(_and,3,1);
  688. else if((rx[3]&rx[2])==rem)
  689. f(_and,3,2);
  690. else if((rx[3]&~rx[0])==rem){
  691. f(_not,0);
  692. f(_and,3,0);
  693. f(_not,0);
  694. }
  695. else if((rx[3]&~rx[1])==rem){
  696. f(_not,1);
  697. f(_and,3,1);
  698. f(_not,1);
  699. }
  700. else if((rx[3]&~rx[2])==rem){
  701. f(_not,2);
  702. f(_and,3,2);
  703. f(_not,2);
  704. }
  705. else if((rx[3]&(rx[0]^rx[1]))==rem){
  706. f(_xor,0,1);
  707. f(_and,3,0);
  708. f(_xor,0,1);
  709. }
  710. else if((rx[3]&(rx[2]^rx[1]))==rem){
  711. f(_xor,2,1);
  712. f(_and,3,2);
  713. f(_xor,2,1);
  714. }
  715. else if((rx[3]&(rx[2]^rx[0]))==rem){
  716. f(_xor,2,0);
  717. f(_and,3,2);
  718. f(_xor,2,0);
  719. }
  720. else if((rx[3]&(~rx[0]^rx[1]))==rem){
  721. f(_not,0);
  722. f(_xor,0,1);
  723. f(_and,3,0);
  724. f(_xor,0,1);
  725. f(_not,0);
  726. }
  727. else if((rx[3]&(~rx[2]^rx[1]))==rem){
  728. f(_not,2);
  729. f(_xor,2,1);
  730. f(_and,3,2);
  731. f(_xor,2,1);
  732. f(_not,2);
  733. }
  734. else if((rx[3]&(~rx[2]^rx[0]))==rem){
  735. f(_not,2);
  736. f(_xor,2,0);
  737. f(_and,3,2);
  738. f(_xor,2,0);
  739. f(_not,2);
  740. }
  741. else if((rx[3]&(rx[0]^rx[1]^rx[2]))==rem){
  742. f(_xor,0,1);
  743. f(_xor,0,2);
  744. f(_and,3,0);
  745. f(_xor,0,1);
  746. f(_xor,0,2);
  747. }
  748. else{
  749. f(_sub,3,3); //0
  750. f(_inc,3,u8); //8
  751. f(_mul,3,3); //16
  752. f(_mul,3,3); //32
  753. f(_inc,3,u8); //32,8
  754. f(_mul,3,3,l32); //32,16
  755. assert(rx[3]==rem);
  756. }
  757. }
  758. void inner16(vull goal){
  759. vull intermediate(3);
  760. ull m = (ull(1)<<48)+(ull(1)<<32)+(ull(1)<<16);
  761. rep(i,0,2){
  762. try{
  763. intermediate[i] = choose(rx[i],goal[i]);
  764. }catch(...){
  765. f(_sub,i,i);
  766. intermediate[i] = choose(rx[i],goal[i]);
  767. }
  768. }
  769. rep(i,0,7){
  770. rep(j,0,2)
  771. if((rx[j]^intermediate[j]) & (1ull<<(40+i)))
  772. f(_xor,j,3);
  773. rep(j,0,2)
  774. if((rx[j]^intermediate[j]) & (1ull<<(24+i)))
  775. f(_xor,j,3,l32);
  776. rep(j,0,2)
  777. if((rx[j]^intermediate[j]) & (1ull<<(8+i)))
  778. f(_xor,j,3,u8,u8);
  779. rep(j,0,2)
  780. if((rx[j]^intermediate[j]) & (1ull<<(i)))
  781. f(_xor,j,3,l8,u8);
  782. f(_add,3,3);
  783. }
  784. assert(rx[3] == m);
  785. rep(j,0,2)
  786. f(_mul,j,3);
  787. make_rx3_rem();
  788. f(_inc,3);
  789. rep(i,0,7){
  790. rep(j,0,2)
  791. if((rx[j]^goal[j]) & (1ull<<(32+i)))
  792. f(_xor,j,3);
  793. rep(j,0,2)
  794. if((rx[j]^goal[j]) & (1ull<<(16+i)))
  795. f(_xor,j,3,l32);
  796. rep(j,0,2)
  797. if((rx[j]^goal[j]) & (1ull<<(8+i)))
  798. f(_xor,j,3,u8,l8);
  799. rep(j,0,2)
  800. if((rx[j]^goal[j]) & (1ull<<(i)))
  801. f(_xor,j,3,l8,l8);
  802. f(_add,3,3);
  803. }
  804. }
  805. ll mock(void (*to_test)(vull), vull initial, vull goal){
  806. auto old_saving = saving;
  807. saving = false;
  808. int old_op = cnt_op;
  809. save_state();
  810. rep(i,0,sz(initial)-1)
  811. rx[i] = initial[i];
  812. to_test(goal);
  813. load_state();
  814. saving = old_saving;
  815. int ans = cnt_op-old_op;
  816. cnt_op = old_op;
  817. return ans;
  818. }
  819. template<typename T>
  820. ll mock(void (*to_test)(T), T goals){
  821. saving = false;
  822.  
  823. int old_op = cnt_op;
  824. vull _state = get_state();
  825. to_test(goals);
  826. set_state(_state);
  827. saving = true;
  828. int ans = cnt_op-old_op;
  829. cnt_op = old_op;
  830. return ans;
  831. }
  832. vull best_permute(void (*)(vull), vull);
  833. vvull rand_permute(void (*)(vvull), vvull, int);
  834. void tsp_permute(void (*)(vull), vvull&);
  835. void outer16(vvull goals){
  836. rep(t,0,n-1){
  837. vull goal = best_permute(inner16,goals[t]);
  838. inner16(goal);
  839. rep(j,0,2) assert((rx[j]^goal[j])==0);
  840. }
  841. }
  842. void calc_dist(void (*to_test)(vull), vvull goals){
  843. vull state = get_state();
  844. rep(i,0,sz(goals)-1)
  845. rep(j,0,sz(goals)-1){
  846. set_state(goals[i]);
  847. dist[i][j] = mock(to_test,get_state(),best_permute(to_test,goals[j]));
  848. }
  849. set_state(state);
  850. }
  851. bool visited[64];
  852. vi path;
  853. int cost = 0;
  854. void dfs(int u, int sz){
  855. visited[u] = true;
  856. path.pb(u);
  857. if(sz(path) == sz)
  858. return;
  859. vpii best_cont;
  860. rep(v,0,sz-1)
  861. if(!visited[v])
  862. best_cont.pb({dist[u][v],v});
  863. sort(all(best_cont));
  864. for(auto _ : best_cont){
  865. if(sz(path) < 50 && rand()%15 == 0) continue;
  866. cost += _.X;
  867. dfs(_.Y,sz);
  868. if(sz(path) == sz)
  869. return;
  870. cost -= _.X;
  871. }
  872. if(sz(path) == sz)
  873. return;
  874. visited[u] = false;
  875. path.pop_back();
  876. return;
  877. }
  878. vi mst_order(int sz = 64){
  879. vvi edges;
  880. rep(i,0,sz-1)
  881. rep(j,i+1,sz-1)
  882. edges.pb({dist[i][j],i,j});
  883. DSU dsu(sz);
  884. vi deg(sz);
  885. vvi adj(sz);
  886. ll cost = 0;
  887. for(auto _ : edges){
  888. int u = _[1];
  889. int v = _[2];
  890. if(deg[u] <= 1 && deg[v] <= 1 && dsu.unite(u,v)){
  891. ++deg[u];
  892. ++deg[v];
  893. adj[u].pb(v);
  894. adj[v].pb(u);
  895. cost += _[0];
  896. }
  897. }
  898. int start = 0;
  899. while(deg[start] != 1)
  900. ++start;
  901. vi ans(1,start);
  902. rep(i,0,sz(ans)-1){
  903. int u = ans[i];
  904. for(int v : adj[u]){
  905. if(deg[v] != 0){
  906. ans.pb(v);
  907. deg[u]--;
  908. deg[v]--;
  909. }
  910. }
  911. }
  912. watch(cost);
  913. watch(sz(ans));
  914. return ans;
  915.  
  916. }
  917. vi mf_order(int sz = 64){
  918. vvi edges;
  919. rep(i,0,sz-1)
  920. rep(j,i+1,sz-1)
  921. edges.pb({dist[i][j],i,j});
  922. DSU dsu(sz);
  923. vi deg(sz);
  924. ll cost = 0;
  925. ll icost = 0;
  926. vi ls,rs;
  927. for(auto _ : edges){
  928. int u = _[1];
  929. int v = _[2];
  930. if(deg[u] <= 0 && deg[v] <= 0 && dsu.unite(u,v)){
  931. ++deg[u];
  932. ++deg[v];
  933. icost += _[0];
  934. ls.pb(u);
  935. rs.pb(v);
  936. }
  937. }
  938. ll tcost = MOD;
  939. rep(times,0,1000){
  940. cost = icost;
  941. rep(i,0,31)
  942. if(rand()%2)
  943. swap(ls[i],rs[i]);
  944. MaxFlow<int> mf;
  945. vvi edge_indices(32,vi(32));
  946. rep(i,0,31)
  947. rep(j,0,31)
  948. edge_indices[i][j] = mf.add_edge(ls[i],rs[j],1,dist[ls[i]][rs[j]]);
  949. int ts = -1;
  950. rep(i,0,31)
  951. mf.add_edge(ts,ls[i],1,0);
  952. rep(j,0,31)
  953. mf.add_edge(rs[j],mf.sink,1,0);
  954. mf.add_edge(mf.source,ts,31,0);
  955. cost += mf.min_cost_flow().Y;
  956. tcost = min(tcost,cost);
  957. }
  958. watch(tcost);
  959. return {};
  960. }
  961. vi decent_order(int sz = 64){
  962. vi best_path;
  963. int best_cost = MOD;
  964. rep(start,0,30*(sz-1)){
  965. cost = 0;
  966. path.clear();
  967. memset(visited,0,sizeof visited);
  968. dfs(start%sz,sz);
  969. if(cost < best_cost){
  970. best_path = path;
  971. best_cost = cost;
  972. }
  973. }
  974. return best_path;
  975. }
  976. void set_order(vvull &goals, vi order){
  977. vvull b(sz(goals));
  978. rep(i,0,sz(goals)-1)
  979. b[i] = goals[order[i]];
  980. goals = b;
  981. }
  982. void solve16(){
  983. f(_inc,3,u8); //8
  984. f(_mov,0,3);
  985. f(_mul,3,3); //16
  986. f(_mul,3,3); //32
  987. f(_inc,3,u8); //32,8
  988. f(_mul,3,3,l32); //32,16
  989. f(_inc,3); //32,16,0
  990. f(_mul,3,0); //40,24,8
  991. vvull goals = a;
  992. tsp_permute(inner16,goals);
  993.  
  994. outer16(goals);
  995. }
  996.  
  997. void inner56(int t, vull goal){
  998. if(t > 0){
  999. f(_add,2,0);
  1000. f(_add,2,1);
  1001. }
  1002. {
  1003. int endp = 1+(t==0);
  1004. vull intermediate(3);
  1005. ull m = (ull(1)<<48)+(ull(1)<<32)+(ull(1)<<16);
  1006. rep(i,0,endp){
  1007. try{
  1008. intermediate[i] = choose(rx[i],goal[i]);
  1009. }catch(...){
  1010. f(_sub,i,i);
  1011. intermediate[i] = choose(rx[i],goal[i]);
  1012. }
  1013. }
  1014. rep(i,0,7){
  1015. rep(j,0,endp)
  1016. if((rx[j]^intermediate[j]) & (1ull<<(40+i)))
  1017. f(_xor,j,3);
  1018. rep(j,0,endp)
  1019. if((rx[j]^intermediate[j]) & (1ull<<(24+i)))
  1020. f(_xor,j,3,l32);
  1021. rep(j,0,endp){
  1022. if((rx[j]^intermediate[j]) & (1ull<<(8+i)))
  1023. f(_xor,j,3,u8,u8);
  1024. }
  1025. rep(j,0,endp)
  1026. if((rx[j]^intermediate[j]) & (1ull<<(i)))
  1027. f(_xor,j,3,l8,u8);
  1028. f(_add,3,3);
  1029. }
  1030. assert(rx[3] == m);
  1031. rep(j,0,endp)
  1032. f(_mul,j,3);
  1033. make_rx3_rem();
  1034. f(_inc,3);
  1035. rep(i,0,7){
  1036. rep(j,0,endp)
  1037. if((rx[j]^goal[j]) & (1ull<<(32+i)))
  1038. f(_xor,j,3);
  1039. rep(j,0,endp)
  1040. if((rx[j]^goal[j]) & (1ull<<(16+i)))
  1041. f(_xor,j,3,l32);
  1042. rep(j,0,endp)
  1043. if((rx[j]^goal[j]) & (1ull<<(8+i)))
  1044. f(_xor,j,3,u8,l8);
  1045. rep(j,0,endp)
  1046. if((rx[j]^goal[j]) & (1ull<<(i)))
  1047. f(_xor,j,3,l8,l8);
  1048. f(_add,3,3);
  1049. }
  1050. if(t > 0){
  1051. f(_sub,2,0);
  1052. f(_sub,2,1);
  1053. }
  1054. }
  1055. }
  1056. void inner56_init(vull goal){
  1057. inner56(0,goal);
  1058. }
  1059. void inner56_normal(vull goal){
  1060. inner56(1,goal);
  1061. }
  1062. void outer56(vvull goals){
  1063. rep(t,0,n-1){
  1064. auto func = t == 0 ? inner56_init : inner56_normal;
  1065. vull goal = goals[t];
  1066. goal = best_permute(func,goals[t]);
  1067. func(goal);
  1068. rep(j,0,2) assert((rx[j]^goal[j])==0);
  1069. }
  1070. }
  1071. void solve56(){
  1072. f(_inc,3,u8); //8
  1073. f(_mov,0,3);
  1074. f(_mul,3,3); //16
  1075. f(_mul,3,3); //32
  1076. f(_inc,3,u8); //32,8
  1077. f(_mul,3,3,l32); //32,16
  1078. f(_inc,3); //32,16,0
  1079. f(_mul,3,0); //40,24,8
  1080. vvull goals = a;
  1081. tsp_permute(inner56_normal,goals);
  1082. outer56(goals);
  1083. }
  1084. void inner4(vull goal){
  1085. rep(times,0,3){
  1086. if(times > 2){
  1087. if(goal[0]>>32 != rx[0]>>32){
  1088. if(goal[0]>>32 == g(_add,0,1)>>32) f(_add, 0,1);
  1089. else if(goal[0]>>32 == g(_xor,0,1)>>32) f(_xor, 0,1);
  1090. else if(goal[0]>>32 == g(_sub,0,1)>>32) f(_sub, 0,1);
  1091. else if(goal[0]>>32 == g(_and,0,1)>>32) f(_and, 0,1);
  1092. else if(goal[0]>>32 == g(_or, 0,1)>>32) f(_or, 0,1);
  1093. else if(goal[0]>>32 == g(_add,0,2)>>32) f(_add, 0,2);
  1094. else if(goal[0]>>32 == g(_xor,0,2)>>32) f(_xor, 0,2);
  1095. else if(goal[0]>>32 == g(_sub,0,2)>>32) f(_sub, 0,2);
  1096. else if(goal[0]>>32 == g(_and,0,2)>>32) f(_and, 0,2);
  1097. else if(goal[0]>>32 == g(_or, 0,2)>>32) f(_or, 0,2);
  1098. else if(times>1 && goal[0]>>32 == g(_mov,0,1)>>32) f(_mov, 0,1);
  1099. else if(times>1 && goal[0]>>32 == g(_mov,0,2)>>32) f(_mov, 0,2);
  1100. }
  1101. if(goal[1]>>32 != rx[1]>>32){
  1102. if(goal[1]>>32 == g(_add,1,0)>>32) f(_add, 1,0);
  1103. else if(goal[1]>>32 == g(_xor,1,0)>>32) f(_xor, 1,0);
  1104. else if(goal[1]>>32 == g(_sub,1,0)>>32) f(_sub, 1,0);
  1105. else if(goal[1]>>32 == g(_and,1,0)>>32) f(_and, 1,0);
  1106. else if(goal[1]>>32 == g(_or, 1,0)>>32) f(_or, 1,0);
  1107. else if(goal[1]>>32 == g(_add,1,2)>>32) f(_add, 1,2);
  1108. else if(goal[1]>>32 == g(_xor,1,2)>>32) f(_xor, 1,2);
  1109. else if(goal[1]>>32 == g(_sub,1,2)>>32) f(_sub, 1,2);
  1110. else if(goal[1]>>32 == g(_and,1,2)>>32) f(_and, 1,2);
  1111. else if(goal[1]>>32 == g(_or, 1,2)>>32) f(_or, 1,2);
  1112. else if(times > 1 && goal[1]>>32 == g(_mov,1,0)>>32) f(_mov, 1,0);
  1113. else if(times > 1 && goal[1]>>32 == g(_mov,1,2)>>32) f(_mov, 1,2);
  1114. }
  1115. if(goal[0]>>32 != rx[0]>>32){
  1116. if(goal[2]>>32 == g(_add,2,1)>>32) f(_add, 2,1);
  1117. else if(goal[2]>>32 == g(_xor,2,1)>>32) f(_xor, 2,1);
  1118. else if(goal[2]>>32 == g(_sub,2,1)>>32) f(_sub, 2,1);
  1119. else if(goal[2]>>32 == g(_and,2,1)>>32) f(_and, 2,1);
  1120. else if(goal[2]>>32 == g(_or, 2,1)>>32) f(_or, 2,1);
  1121. else if(goal[2]>>32 == g(_add,2,0)>>32) f(_add, 2,0);
  1122. else if(goal[2]>>32 == g(_xor,2,0)>>32) f(_xor, 2,0);
  1123. else if(goal[2]>>32 == g(_sub,2,0)>>32) f(_sub, 2,0);
  1124. else if(goal[2]>>32 == g(_and,2,0)>>32) f(_and, 2,0);
  1125. else if(goal[2]>>32 == g(_or, 2,0)>>32) f(_or, 2,0);
  1126. else if(times > 1 && goal[2]>>32 == g(_mov,2,1)>>32) f(_mov, 2,1);
  1127. else if(times > 1 && goal[2]>>32 == g(_mov,2,0)>>32) f(_mov, 2,0);
  1128. }
  1129. }
  1130. if(goal[0] != rx[0]){
  1131. if(goal[0] == g(_add,0,1)) f(_add, 0,1);
  1132. else if(goal[0] == g(_xor,0,1)) f(_xor, 0,1);
  1133. else if(goal[0] == g(_sub,0,1)) f(_sub, 0,1);
  1134. else if(goal[0] == g(_and,0,1)) f(_and, 0,1);
  1135. else if(goal[0] == g(_or, 0,1)) f(_or, 0,1);
  1136. else if(goal[0] == g(_add,0,1,l32)) f(_add,0,1,l32);
  1137. else if(goal[0] == g(_xor,0,1,l32)) f(_xor,0,1,l32);
  1138. else if(goal[0] == g(_sub,0,1,l32)) f(_sub,0,1,l32);
  1139. else if(goal[0] == g(_and,0,1,l32)) f(_and,0,1,l32);
  1140. else if(goal[0] == g(_or, 0,1,l32)) f(_or, 0,1,l32);
  1141. else if(goal[0] == g(_add,0,2)) f(_add, 0,2);
  1142. else if(goal[0] == g(_xor,0,2)) f(_xor, 0,2);
  1143. else if(goal[0] == g(_sub,0,2)) f(_sub, 0,2);
  1144. else if(goal[0] == g(_and,0,2)) f(_and, 0,2);
  1145. else if(goal[0] == g(_or, 0,2)) f(_or, 0,2);
  1146. else if(goal[0] == g(_add,0,2,l32)) f(_add,0,2,l32);
  1147. else if(goal[0] == g(_xor,0,2,l32)) f(_xor,0,2,l32);
  1148. else if(goal[0] == g(_sub,0,2,l32)) f(_sub,0,2,l32);
  1149. else if(goal[0] == g(_and,0,2,l32)) f(_and,0,2,l32);
  1150. else if(goal[0] == g(_or, 0,2,l32)) f(_or, 0,2,l32);
  1151. else if(times > 0 && goal[0] == g(_mov,0,1)) f(_mov, 0,1);
  1152. else if(times > 0 && goal[0] == g(_mov,0,2)) f(_mov, 0,2);
  1153. else if(times > 0 && goal[0] == g(_mov,0,1,l32)) f(_mov,0,1,l32);
  1154. else if(times > 0 && goal[0] == g(_mov,0,2,l32)) f(_mov,0,2,l32);
  1155. }
  1156. if(goal[1] != rx[1]){
  1157. if(goal[1] == g(_add,1,0)) f(_add, 1,0);
  1158. else if(goal[1] == g(_xor,1,0)) f(_xor, 1,0);
  1159. else if(goal[1] == g(_sub,1,0)) f(_sub, 1,0);
  1160. else if(goal[1] == g(_and,1,0)) f(_and, 1,0);
  1161. else if(goal[1] == g(_or, 1,0)) f(_or, 1,0);
  1162. else if(goal[1] == g(_add,1,0,l32)) f(_add,1,0,l32);
  1163. else if(goal[1] == g(_xor,1,0,l32)) f(_xor,1,0,l32);
  1164. else if(goal[1] == g(_sub,1,0,l32)) f(_sub,1,0,l32);
  1165. else if(goal[1] == g(_and,1,0,l32)) f(_and,1,0,l32);
  1166. else if(goal[1] == g(_or, 1,0,l32)) f(_or, 1,0,l32);
  1167. else if(goal[1] == g(_add,1,2)) f(_add, 1,2);
  1168. else if(goal[1] == g(_xor,1,2)) f(_xor, 1,2);
  1169. else if(goal[1] == g(_sub,1,2)) f(_sub, 1,2);
  1170. else if(goal[1] == g(_and,1,2)) f(_and, 1,2);
  1171. else if(goal[1] == g(_or, 1,2)) f(_or, 1,2);
  1172. else if(goal[1] == g(_add,1,2,l32)) f(_add,1,2,l32);
  1173. else if(goal[1] == g(_xor,1,2,l32)) f(_xor,1,2,l32);
  1174. else if(goal[1] == g(_sub,1,2,l32)) f(_sub,1,2,l32);
  1175. else if(goal[1] == g(_and,1,2,l32)) f(_and,1,2,l32);
  1176. else if(goal[1] == g(_or, 1,2,l32)) f(_or, 1,2,l32);
  1177. else if(times > 0 && goal[1] == g(_mov,1,0)) f(_mov, 1,0);
  1178. else if(times > 0 && goal[1] == g(_mov,1,2)) f(_mov, 1,2);
  1179. else if(times > 0 && goal[1] == g(_mov,1,0,l32)) f(_mov,1,0,l32);
  1180. else if(times > 0 && goal[1] == g(_mov,1,2,l32)) f(_mov,1,2,l32);
  1181. }
  1182. if(goal[2] != rx[2]){
  1183. if(goal[2] == g(_add,2,0)) f(_add, 2,0);
  1184. else if(goal[2] == g(_xor,2,0)) f(_xor, 2,0);
  1185. else if(goal[2] == g(_sub,2,0)) f(_sub, 2,0);
  1186. else if(goal[2] == g(_and,2,0)) f(_and, 2,0);
  1187. else if(goal[2] == g(_or, 2,0)) f(_or, 2,0);
  1188. else if(goal[2] == g(_add,2,0,l32)) f(_add,2,0,l32);
  1189. else if(goal[2] == g(_xor,2,0,l32)) f(_xor,2,0,l32);
  1190. else if(goal[2] == g(_sub,2,0,l32)) f(_sub,2,0,l32);
  1191. else if(goal[2] == g(_and,2,0,l32)) f(_and,2,0,l32);
  1192. else if(goal[2] == g(_or, 2,0,l32)) f(_or, 2,0,l32);
  1193. else if(goal[2] == g(_add,2,1)) f(_add, 2,1);
  1194. else if(goal[2] == g(_xor,2,1)) f(_xor, 2,1);
  1195. else if(goal[2] == g(_sub,2,1)) f(_sub, 2,1);
  1196. else if(goal[2] == g(_and,2,1)) f(_and, 2,1);
  1197. else if(goal[2] == g(_or, 2,1)) f(_or, 2,1);
  1198. else if(goal[2] == g(_add,2,1,l32)) f(_add,2,1,l32);
  1199. else if(goal[2] == g(_xor,2,1,l32)) f(_xor,2,1,l32);
  1200. else if(goal[2] == g(_sub,2,1,l32)) f(_sub,2,1,l32);
  1201. else if(goal[2] == g(_and,2,1,l32)) f(_and,2,1,l32);
  1202. else if(goal[2] == g(_or, 2,1,l32)) f(_or, 2,1,l32);
  1203. else if(times > 0 && goal[2] == g(_mov,2,0)) f(_mov, 2,0);
  1204. else if(times > 0 && goal[2] == g(_mov,2,1)) f(_mov, 2,1);
  1205. else if(times > 0 && goal[2] == g(_mov,2,0,l32)) f(_mov,2,0,l32);
  1206. else if(times > 0 && goal[2] == g(_mov,2,1,l32)) f(_mov,2,1,l32);
  1207. }
  1208. }
  1209. vull t64(3);
  1210. vull t32(3);
  1211. rep(j,0,2){
  1212. t64[j] = (goal[j]^rx[j])>>32;
  1213. goal[j] ^= t64[j];
  1214. t32[j] = ((goal[j]^rx[j])<<32)>>32;
  1215. goal[j] ^= t64[j];
  1216. }
  1217. rep(j,0,2){
  1218. if(bits(t64[j]) > 16){
  1219. f(_not,j);
  1220. t64[j] = (goal[j]^rx[j])>>32;
  1221. goal[j] ^= t64[j];
  1222. t32[j] = ((goal[j]^rx[j])<<32)>>32;
  1223. goal[j] ^= t64[j];
  1224. }
  1225. if(bits(t32[j]) > 16){
  1226. f(_not,j,l32);
  1227. t64[j] = (goal[j]^rx[j])>>32;
  1228. goal[j] ^= t64[j];
  1229. t32[j] = ((goal[j]^rx[j])<<32)>>32;
  1230. goal[j] ^= t64[j];
  1231. }
  1232. if(bits(t32[j]&0xffff) > 8 && bits(t32[j]&0x00ff) > 4 && bits(t32[j]&0xff00) > 4){
  1233. f(_not,j,l16);
  1234. t64[j] = (goal[j]^rx[j])>>32;
  1235. goal[j] ^= t64[j];
  1236. t32[j] = ((goal[j]^rx[j])<<32)>>32;
  1237. goal[j] ^= t64[j];
  1238. }
  1239. if(bits(t32[j]&0x00ff) > 4){
  1240. f(_not,j,l8);
  1241. t64[j] = (goal[j]^rx[j])>>32;
  1242. goal[j] ^= t64[j];
  1243. t32[j] = ((goal[j]^rx[j])<<32)>>32;
  1244. goal[j] ^= t64[j];
  1245. }
  1246. if(bits(t32[j]&0xff00) > 4){
  1247. f(_not,j,u8);
  1248. t64[j] = (goal[j]^rx[j])>>32;
  1249. goal[j] ^= t64[j];
  1250. t32[j] = ((goal[j]^rx[j])<<32)>>32;
  1251. goal[j] ^= t64[j];
  1252. }
  1253. }
  1254. if(vull(rx,rx+3) == goal) return;
  1255. f(_inc,3); //32,1
  1256. rep(i,0,31){
  1257. rep(j,0,2){
  1258. if(t64[j]&rx[3]) f(_xor,j,3);
  1259. if(t32[j]&rx[3]) f(_xor,j,3,l32);
  1260. }
  1261. f(_add,3,3);
  1262. }
  1263. rep(j,0,2)
  1264. assert(rx[j] == goal[j]);
  1265. }
  1266. void outer4(vvull goals){
  1267. rep(t,0,n-1){
  1268. vull goal = goals[t];
  1269. goal = best_permute(inner4,goals[t]);
  1270. inner4(goal);
  1271. }
  1272. }
  1273. //void solve4(){
  1274. //f(_inc,3,u8); //8
  1275. //f(_mul,3,3); //16
  1276. //f(_mul,3,3); //32
  1277. //vvull goals = a;
  1278. //tsp_permute(inner4,goals);
  1279. //outer4(goals);
  1280. //}
  1281.  
  1282.  
  1283. vull apply_oper(bool keep_changes, int bm){
  1284. vull old_vals(rx,rx+3);
  1285. if(!keep_changes)
  1286. saving = false;
  1287. rep(j,0,2){
  1288. int p1 = bm%3; bm /= 3;
  1289. int p2 = bm%2; bm /= 2;
  1290. if(p2 == p1) p2 = 2;
  1291. int op_index, nr_bits;
  1292. op_index = bm%5; bm /= 5;
  1293. nr_bits = bm%2; bm /= 2;
  1294. if(nr_bits == 0){
  1295. if(op_index == 0) f(_add,p1,p2);
  1296. if(op_index == 1) f(_xor,p1,p2);
  1297. if(op_index == 2) f(_and,p1,p2);
  1298. if(op_index == 3) f(_or,p1,p2);
  1299. if(op_index == 4) f(_sub,p1,p2);
  1300. }
  1301. else{
  1302. if(op_index == 0) f(_add,p1,p2,l32);
  1303. if(op_index == 1) f(_xor,p1,p2,l32);
  1304. if(op_index == 2) f(_and,p1,p2,l32);
  1305. if(op_index == 3) f(_or,p1,p2,l32);
  1306. if(op_index == 4) f(_sub,p1,p2,l32);
  1307. }
  1308.  
  1309. }
  1310. vull ret(rx,rx+3);
  1311. if(!keep_changes){
  1312. saving = true;
  1313. rep(j,0,2)
  1314. rx[j] = old_vals[j];
  1315. }
  1316. sort(all(ret));
  1317. return ret;
  1318. }
  1319. void solve4(){
  1320. f(_inc,3);
  1321. rep(i,0,63){
  1322. rep(j,0,2)
  1323. if(a[0][j]&(1LL<<i))
  1324. f(_xor,j,3);
  1325. f(_add,3,3);
  1326. }
  1327. rep(i,1,n-1){
  1328. sort(all(a[i]));
  1329. saving = false;
  1330. vull old_vals(rx,rx+3);
  1331. //assert(old_vals == a[i-1]);
  1332. int correct_mask = -1;
  1333. rep(bm,0,ipow(60,3))
  1334. if(apply_oper(false,bm) == a[i]){
  1335. correct_mask = bm;
  1336. break;
  1337. }
  1338. assert(correct_mask != -1);
  1339. apply_oper(true,correct_mask);
  1340. set<ull> tmp(rx,rx+4);
  1341. rep(j,0,2) assert(tmp.count(a[i][j]));
  1342. }
  1343. }
  1344. void inner2(vull goal){
  1345. goal[2] ^= goal[0];
  1346. goal[1] ^= goal[0];
  1347. f(_inc,3); //32,1
  1348. if(rx[1] != 0) f(_sub,1,1);
  1349. if(rx[2] != 0) f(_sub,2,2);
  1350. vull t64(3);
  1351. vull t32(3);
  1352. rep(j,0,2){
  1353. t64[j] = (goal[j]^rx[j])>>32;
  1354. goal[j] ^= t64[j];
  1355. t32[j] = ((goal[j]^rx[j])<<32)>>32;
  1356. goal[j] ^= t64[j];
  1357. }
  1358. rep(j,0,2){
  1359. if(bits(t64[j]) > 16){
  1360. f(_not,j);
  1361. t64[j] = (goal[j]^rx[j])>>32;
  1362. goal[j] ^= t64[j];
  1363. t32[j] = ((goal[j]^rx[j])<<32)>>32;
  1364. goal[j] ^= t64[j];
  1365. }
  1366. if(bits(t32[j]) > 16){
  1367. f(_not,j,l32);
  1368. t64[j] = (goal[j]^rx[j])>>32;
  1369. goal[j] ^= t64[j];
  1370. t32[j] = ((goal[j]^rx[j])<<32)>>32;
  1371. goal[j] ^= t64[j];
  1372. }
  1373.  
  1374. int types = 0;
  1375. if(bits(t32[j]&0x00ff) > 4) types ^= 1;
  1376. if(bits(t32[j]&0xff00) > 4) types ^= 2;
  1377. if((types&3)==3){
  1378. f(_not,j,l16);
  1379. t64[j] = (goal[j]^rx[j])>>32;
  1380. goal[j] ^= t64[j];
  1381. t32[j] = ((goal[j]^rx[j])<<32)>>32;
  1382. goal[j] ^= t64[j];
  1383. }
  1384. else if(types&1){
  1385. f(_not,j,l8);
  1386. t64[j] = (goal[j]^rx[j])>>32;
  1387. goal[j] ^= t64[j];
  1388. t32[j] = ((goal[j]^rx[j])<<32)>>32;
  1389. goal[j] ^= t64[j];
  1390. }
  1391. else if(types&2){
  1392. f(_not,j,u8);
  1393. t64[j] = (goal[j]^rx[j])>>32;
  1394. goal[j] ^= t64[j];
  1395. t32[j] = ((goal[j]^rx[j])<<32)>>32;
  1396. goal[j] ^= t64[j];
  1397. }
  1398. }
  1399. rep(i,0,31){
  1400. rep(j,0,2){
  1401. if(t64[j]&rx[3]) f(_xor,j,3);
  1402. if(t32[j]&rx[3]) f(_xor,j,3,l32);
  1403. }
  1404. f(_add,3,3);
  1405. }
  1406. f(_xor,1,0);
  1407. f(_xor,2,0);
  1408. }
  1409. void outer2(vvull goals){
  1410. rep(t,0,n-1){
  1411. vull goal = best_permute(inner2,goals[t]);
  1412. inner2(goal);
  1413. }
  1414. }
  1415. void solve2(){
  1416. f(_inc,3,u8); //8
  1417. f(_mul,3,3); //16
  1418. f(_mul,3,3); //32
  1419. vvull goals = a;
  1420. tsp_permute(inner2,goals);
  1421. outer2(goals);
  1422. }
  1423. void solve26(){
  1424. f(_inc,3,u8); //8
  1425. f(_mov,0,3);
  1426. f(_mul,3,3); //16
  1427. f(_mul,3,3); //32
  1428. f(_inc,3,u8); //32,8
  1429. f(_mul,3,3,l32); //32,16
  1430. f(_inc,3); //32,16,0
  1431. f(_mul,3,0); //40,24,8
  1432. rep(t,0,n-1){
  1433. if(t > 0){
  1434. f(_sub,1,1);
  1435. f(_sub,2,2);
  1436. }
  1437. vull goal = a[t];
  1438. goal[1] ^= goal[0];
  1439. goal[2] ^= goal[0];
  1440. {
  1441. vull intermediate(3);
  1442. ull m = (ull(1)<<48)+(ull(1)<<32)+(ull(1)<<16);
  1443. rep(i,0,2){
  1444. try{
  1445. intermediate[i] = choose(rx[i],goal[i]);
  1446. }catch(...){
  1447. f(_sub,i,i);
  1448. intermediate[i] = choose(rx[i],goal[i]);
  1449. }
  1450. }
  1451. rep(i,0,7){
  1452. rep(j,0,2)
  1453. if((rx[j]^intermediate[j]) & (1ull<<(40+i)))
  1454. f(_xor,j,3);
  1455. rep(j,0,2)
  1456. if((rx[j]^intermediate[j]) & (1ull<<(24+i)))
  1457. f(_xor,j,3,l32);
  1458. rep(j,0,2)
  1459. if((rx[j]^intermediate[j]) & (1ull<<(8+i)))
  1460. f(_xor,j,3,u8,u8);
  1461. rep(j,0,2)
  1462. if((rx[j]^intermediate[j]) & (1ull<<(i)))
  1463. f(_xor,j,3,l8,u8);
  1464. f(_add,3,3);
  1465. }
  1466. assert(rx[3] == m);
  1467. rep(j,0,2)
  1468. f(_mul,j,3);
  1469. make_rx3_rem();
  1470. f(_inc,3);
  1471. rep(i,0,7){
  1472. rep(j,0,2)
  1473. if((rx[j]^goal[j]) & (1ull<<(32+i)))
  1474. f(_xor,j,3);
  1475. rep(j,0,2)
  1476. if((rx[j]^goal[j]) & (1ull<<(16+i)))
  1477. f(_xor,j,3,l32);
  1478. rep(j,0,2)
  1479. if((rx[j]^goal[j]) & (1ull<<(8+i)))
  1480. f(_xor,j,3,u8,l8);
  1481. rep(j,0,2)
  1482. if((rx[j]^goal[j]) & (1ull<<(i)))
  1483. f(_xor,j,3,l8,l8);
  1484. f(_add,3,3);
  1485. }
  1486. rep(j,0,2) assert((rx[j]^goal[j])==0);
  1487. }
  1488. f(_xor,1,0);
  1489. f(_xor,2,0);
  1490. }
  1491. }
  1492. void solve5(){
  1493. f(_inc,3,u8); //8
  1494. f(_mul,3,3); //16
  1495. f(_mul,3,3); //32
  1496. rep(t,0,n-1){
  1497. if(t > 0){
  1498. f(_add,2,0);
  1499. f(_add,2,1);
  1500. }
  1501. f(_inc,3); //32,1
  1502. vull goal = a[t];
  1503. vull t64(3);
  1504. vull t32(3);
  1505. rep(j,0,2){
  1506. t64[j] = (goal[j]^rx[j])>>32;
  1507. goal[j] ^= t64[j];
  1508. t32[j] = ((goal[j]^rx[j])<<32)>>32;
  1509. }
  1510. rep(i,0,31){
  1511. rep(j,0,1+(t==0)){
  1512. if(t64[j]&rx[3]) f(_xor,j,3);
  1513. if(t32[j]&rx[3]) f(_xor,j,3,l32);
  1514. }
  1515. f(_add,3,3);
  1516. }
  1517.  
  1518. if(t > 0){
  1519. f(_sub,2,0);
  1520. f(_sub,2,1);
  1521. }
  1522. }
  1523. }
  1524. bool comp(const vull &a, const vull &b){
  1525. return a[1]-a[0] < b[1]-b[0];
  1526. }
  1527. void solve3(){
  1528. sort(all(a),comp);
  1529. f(_inc,3,u8); //8
  1530. f(_mul,3,3); //16
  1531. f(_mul,3,3); //32
  1532. rep(t,0,n-1){
  1533. f(_inc,3); //32,1
  1534. vull goal = a[t];
  1535. vull t64(3);
  1536. vull t32(3);
  1537. if(t%8)
  1538. f(_sub,2,1);
  1539. rep(j,0,2){
  1540. t64[j] = (goal[j]^rx[j])>>32;
  1541. goal[j] ^= t64[j];
  1542. t32[j] = ((goal[j]^rx[j])<<32)>>32;
  1543. }
  1544. rep(i,0,31){
  1545. rep(j,0,2*(t%8 == 0)){
  1546. if(t64[j]&rx[3]) f(_xor,j,3);
  1547. if(t32[j]&rx[3]) f(_xor,j,3,l32);
  1548. }
  1549. f(_add,3,3);
  1550. }
  1551. if(t%8){
  1552. f(_mov,1,0);
  1553. f(_add,1,2);
  1554. f(_add,2,1);
  1555. }
  1556. }
  1557. }
  1558. void inner36_8(vull goal, int t2){
  1559. sort(all(goal));
  1560. if(t2)
  1561. f(_sub,2,1);
  1562. {
  1563. int endp = 0+2*(t2 == 0);
  1564. vull intermediate(3);
  1565. ull m = (ull(1)<<48)+(ull(1)<<32)+(ull(1)<<16);
  1566. rep(i,0,endp){
  1567. try{
  1568. intermediate[i] = choose(rx[i],goal[i]);
  1569. }catch(...){
  1570. f(_sub,i,i);
  1571. intermediate[i] = choose(rx[i],goal[i]);
  1572. }
  1573. }
  1574. rep(i,0,7){
  1575. rep(j,0,endp)
  1576. if((rx[j]^intermediate[j]) & (1ull<<(40+i)))
  1577. f(_xor,j,3);
  1578. rep(j,0,endp)
  1579. if((rx[j]^intermediate[j]) & (1ull<<(24+i)))
  1580. f(_xor,j,3,l32);
  1581. rep(j,0,endp)
  1582. if((rx[j]^intermediate[j]) & (1ull<<(8+i)))
  1583. f(_xor,j,3,u8,u8);
  1584. rep(j,0,endp)
  1585. if((rx[j]^intermediate[j]) & (1ull<<(i)))
  1586. f(_xor,j,3,l8,u8);
  1587. f(_add,3,3);
  1588. }
  1589. assert(rx[3] == m);
  1590. rep(j,0,endp)
  1591. f(_mul,j,3);
  1592. make_rx3_rem();
  1593. f(_inc,3);
  1594. rep(i,0,7){
  1595. rep(j,0,endp)
  1596. if((rx[j]^goal[j]) & (1ull<<(32+i)))
  1597. f(_xor,j,3);
  1598. rep(j,0,endp)
  1599. if((rx[j]^goal[j]) & (1ull<<(16+i)))
  1600. f(_xor,j,3,l32);
  1601. rep(j,0,endp)
  1602. if((rx[j]^goal[j]) & (1ull<<(8+i)))
  1603. f(_xor,j,3,u8,l8);
  1604. rep(j,0,endp)
  1605. if((rx[j]^goal[j]) & (1ull<<(i)))
  1606. f(_xor,j,3,l8,l8);
  1607. f(_add,3,3);
  1608. }
  1609.  
  1610. if(t2){
  1611. f(_mov,1,0);
  1612. f(_add,1,2);
  1613. f(_add,2,1);
  1614. }
  1615. rep(j,0,2) assert((rx[j]^goal[j])==0);
  1616. }
  1617. }
  1618. void inner36_8_0(vull goal){
  1619. inner36_8(goal,0);
  1620. }
  1621. void inner36_8_1(vull goal){
  1622. inner36_8(goal,1);
  1623. }
  1624. void outer36(vvull goals){
  1625. rep(t2,0,7){
  1626. if(t2 == 0){
  1627. goals[t2] = best_permute(inner36_8_0,goals[t2]);
  1628. inner36_8_0(goals[t2]);
  1629. }
  1630. else{
  1631. goals[t2] = best_permute(inner36_8_1,goals[t2]);
  1632. inner36_8_1(goals[t2]);
  1633. }
  1634. }
  1635. }
  1636. void far_out36(vector<vvull> goals){
  1637. rep(i,0,7)
  1638. outer36(goals[i]);
  1639. }
  1640. void solve36(){
  1641. sort(all(a),comp);
  1642. f(_inc,3,u8); //8
  1643. f(_mov,0,3);
  1644. f(_mul,3,3); //16
  1645. f(_mul,3,3); //32
  1646. f(_inc,3,u8); //32,8
  1647. f(_mul,3,3,l32); //32,16
  1648. f(_inc,3); //32,16,0
  1649. f(_mul,3,0); //40,24,8
  1650. vvull goals = a;
  1651. vector<vvull> buckets(8),best;
  1652. rep(i,0,7){
  1653. buckets[i] = vvull(goals.begin()+i*8,goals.begin()+(i+1)*8);
  1654. tsp_permute(inner36_8_1,buckets[i]);
  1655. }
  1656. best = buckets;
  1657. int best_cost = MOD;
  1658. rep(attempts,0,400){
  1659. ll cur_cost = mock(far_out36,buckets);
  1660. if(cur_cost < best_cost){
  1661. best_cost = cur_cost;
  1662. best = buckets;
  1663. }
  1664. random_shuffle(all(buckets));
  1665. }
  1666. far_out36(buckets);
  1667. }
  1668. //if(!keep_changes)
  1669.  
  1670. //if(!keep_changes){
  1671. void _(){
  1672. ll total = 0;
  1673. ll display = 0;
  1674. int cnt = 0;
  1675. while(cin >> n){
  1676. ++cnt;
  1677. if(cnt > 5)
  1678. break;
  1679. a = vvull(n,vull(3)); cin >> a;
  1680. type = get_type();
  1681. if(type != 4){
  1682. for(auto &_ : a)
  1683. sort(all(_));
  1684. sort(all(a));
  1685. }
  1686. //if(type != 2) continue;
  1687. if(type == 4)
  1688. solve4();
  1689. else if(type == 2)
  1690. solve2();
  1691. else if(type == 3)
  1692. solve36();
  1693. else if(type == 5)
  1694. solve56();
  1695. else
  1696. solve16();
  1697. check(a);
  1698. //assert(type != 1);
  1699. if(type == 1){
  1700. }
  1701. cerr << type << ' ' << sz(description) << '\n';;
  1702. print(sz(description));
  1703. print(description,"\n");
  1704. total += sz(description);
  1705. if(type == 2 || type == 4 || type == 5)
  1706. display += sz(description);
  1707. description.clear();
  1708. memset(rx,0,sizeof rx);
  1709. }
  1710. watch(total);
  1711. watch(display/2);
  1712. }
  1713. void tsp_permute(void (*to_test)(vull), vvull &goals){
  1714. calc_dist(to_test,goals);
  1715. vi order;
  1716. if(sz(goals) > 8){
  1717. order = decent_order(sz(goals));
  1718. }
  1719. else{
  1720. vi ans(8);
  1721. iota(all(ans),0);
  1722. vi best;
  1723. int best_cost = MOD;
  1724. do{
  1725. ll cur_cost = 0;
  1726. rep(i,1,7)
  1727. cur_cost += dist[ans[i-1]][ans[i]];
  1728. if(cur_cost < best_cost){
  1729. best_cost = cur_cost;
  1730. best = ans;
  1731. }
  1732. }while(next_permutation(all(ans)));
  1733. order = best;
  1734. }
  1735. set_order(goals,order);
  1736. }
  1737. vvull rand_permute(void (*to_test)(vvull), vvull goals, int rand_times){
  1738. sort(all(goals));
  1739. vvull best = goals;
  1740. int best_cost = MOD;
  1741. rep(attempts,0,rand_times){
  1742. int cur_cost = mock(to_test,goals);
  1743. if(cur_cost < best_cost){
  1744. best_cost = cur_cost;
  1745. best = goals;
  1746. }
  1747. random_shuffle(all(goals));
  1748. }
  1749. return best;
  1750. }
  1751. vull best_permute(void (*to_test)(vull), vull goal){
  1752. sort(all(goal));
  1753. vull best = goal;
  1754. int best_cost = MOD;
  1755. do{
  1756. int cur_cost = mock(to_test,get_state(),goal);
  1757. if(cur_cost < best_cost){
  1758. best_cost = cur_cost;
  1759. best = goal;
  1760. }
  1761. }while(next_permutation(all(goal)));
  1762. return best;
  1763. }
  1764. int main(){
  1765. ios_base::sync_with_stdio(false);
  1766. cin.tie(nullptr);
  1767. cout << fixed << setprecision(15);
  1768. _();
  1769. }
  1770.  
Success #stdin #stdout #stderr 1.09s 4408KB
stdin
64
9846887185214015188 9273103249239154728 20538560319183175
9194179385058343267 9846887184106586180 9273103249239154728
594322495999236559 9194179385058343267 20538560587946379
9194179386265428140 594322495999236559 2323474498007362
17854745049517674850 9194179386266352111 594322495999236559
2322168558539074 8613213452309778786 17854745052603709331
2322168685044388 8613213452310454948 17854745052603709331
18446735281368332215 8613213452310454948 17854745052603709331
18446735281368332215 591981436423403483 8613213452310454948
18446735281907302399 8613213456062552703 591981436425205759
9205194889145352191 591981436425205759 18446735281907302399
18446735281907302399 9797176325570557950 9205194889145352191
18446735277616529408 9205194884858773504 9797176325570557950
9797176325570557950 9797167572972470272 9205186088765751296
8093914225799329790 9797176321820852224 9797167572972470272
8093914225799329790 9797167572972470272 9797176321820852224
9797176325566363646 10375915310011123714 17867996336670898174
18446735321115658242 10375915310011123714 9797176325566363646
578756489632546814 9797176325566363646 18446735324861169662
578756489632546812 18446735324861169662 8649576496991569920
10375924066899980290 18446735321115658238 8649576496991569920
8649576496991571964 10375924066899980290 18446735324861167614
8070811253666224122 10375924066899980290 17867987583527550974
17867987660836956164 8070811253666224122 10375924066899980290
17867987656541997060 10375924062605021186 8070811253666224122
18446744068865134606 10375924062605021186 8070811253666224122
8070820006260107282 10375924062605021186 8070811253666220024
5765698439882995714 16141631259926327306 12681036876388245496
17293435385849837566 12681036876937701366 5765698437228011522
5765698437236402166 13834345564256348150 17293435385849837566
17293435384750919688 12681036876937701366 18446744073168484350
12681036876379850754 18446744069972434932 17293435385291986954
13834345564797415416 17293435385291986954 6919015882010148840
2306265529377124320 13834345564797415416 17293435386374127594
14987732842358722538 13834345564797415416 2306265529377124320
18446462579405467676 3459292725654913014 13834345564797415416
14987169853750554662 14987451348054638602 17293638290452328430
17293638289235976236 852783225839660 14987451348054638602
17294491072461815896 17293638289235976236 14987451348054646830
14987600439388536832 18446594982375661614 17293638289235976236
18446594982375661614 17293638289235976236 14987600439388610604
14987233055360622636 2306405233875353600 16140189748500308014
17293258928351289390 17293674890255400962 14987233055360622636
2306025878531547182 17293258928908926978 17293674890389823534
14987120564757012556 17293674890389823534 2306025878531547182
11528025502767325196 12681094686087053278 2306025878531547182
5762554304759537674 12681272875701764094 12681094686087053280
12681094682360995798 16142126908860588020 12681272875701764094
16142126908860588020 12681272875701764094 12681096881396834294
14985714045675839500 16142126908861636598 12681272875701764094
12681096881396834294 16142126908861636598 12681272875132854282
16142302903166566398 16142126908861636598 12681096881396834294
17292977044660944894 16142302903166566398 16142126908861636598
13837685737748692990 16142126908861636598 1150674141494378496
5759908471190208532 16142126908861636598 13837685737748692990
16142126910001553378 5759908471190208532 1150850135229349910
16142126910640865262 17292977044021633012 5759908472295448564
11534757422795718656 5759908472295448564 16142126910640865262
13836272760214781954 16142126910640865262 5759908470550896646
16142126910640865262 13836272760214781954 5759908470182641666
13837509747572178908 16142126910640865262 5759908470182641666
16142126910909972478 13837509749787066366 5759908472128421908
16144560168796946430 13837509747168772096 5759908472128421908
2307050419009880064 13837509747168772096 5759908472128421908
stdout
333
inc rdx
xor rcx rdx
add rdx rdx
xor rcx rdx
add rdx rdx
xor rax rdx
xor rcx rdx
add rdx rdx
xor rbx rdx
add rdx rdx
xor rax rdx
add rdx rdx
xor rbx rdx
add rdx rdx
xor rax rdx
xor rcx rdx
add rdx rdx
xor rax rdx
add rdx rdx
xor rcx rdx
add rdx rdx
xor rax rdx
add rdx rdx
xor rax rdx
add rdx rdx
xor rcx rdx
add rdx rdx
xor rcx rdx
add rdx rdx
xor rbx rdx
add rdx rdx
xor rcx rdx
add rdx rdx
xor rbx rdx
xor rcx rdx
add rdx rdx
xor rax rdx
xor rbx rdx
xor rcx rdx
add rdx rdx
xor rax rdx
xor rbx rdx
add rdx rdx
xor rax rdx
xor rcx rdx
add rdx rdx
xor rbx rdx
add rdx rdx
add rdx rdx
xor rbx rdx
add rdx rdx
xor rbx rdx
add rdx rdx
add rdx rdx
add rdx rdx
xor rax rdx
add rdx rdx
add rdx rdx
xor rcx rdx
add rdx rdx
xor rax rdx
xor rbx rdx
xor rcx rdx
add rdx rdx
xor rbx rdx
xor rcx rdx
add rdx rdx
xor rax rdx
add rdx rdx
add rdx rdx
xor rax rdx
add rdx rdx
xor rbx rdx
xor rcx rdx
add rdx rdx
xor rbx rdx
xor rcx rdx
add rdx rdx
xor rax rdx
add rdx rdx
xor rax rdx
xor rcx rdx
add rdx rdx
xor rax rdx
xor rcx rdx
add rdx rdx
xor rbx rdx
add rdx rdx
xor rax rdx
xor rcx rdx
add rdx rdx
xor rax rdx
xor rcx rdx
add rdx rdx
xor rax rdx
xor rbx rdx
xor rcx rdx
add rdx rdx
xor rbx rdx
xor rcx rdx
add rdx rdx
xor rax rdx
xor rbx rdx
add rdx rdx
xor rcx rdx
add rdx rdx
xor rax rdx
xor rbx rdx
xor rcx rdx
add rdx rdx
xor rcx rdx
add rdx rdx
xor rbx rdx
xor rcx rdx
add rdx rdx
xor rax rdx
add rdx rdx
xor rax rdx
add rdx rdx
xor rax rdx
add rdx rdx
xor rcx rdx
add rdx rdx
xor rbx rdx
add rdx rdx
xor rax rdx
xor rbx rdx
add rdx rdx
xor rcx rdx
add rdx rdx
xor rax rdx
xor rbx rdx
add rdx rdx
add rdx rdx
add rdx rdx
add rdx rdx
xor rax rdx
add rdx rdx
add rdx rdx
add rdx rdx
add rdx rdx
xor rax rdx
xor rbx rdx
add rdx rdx
and eax ecx
add ecx eax
sub rcx rbx
or eax ebx
add rbx rcx
add rax rcx
add ebx eax
and rbx rcx
xor ecx eax
or ecx eax
sub rbx rax
add ebx ecx
and rcx rbx
sub ebx eax
and rax rcx
add ecx eax
add eax ecx
and rax rcx
add eax ebx
sub rax rcx
or rax rcx
sub rbx rax
sub rax rbx
add rbx rax
add ecx eax
or eax ebx
or rbx rcx
or rcx rax
sub rax rcx
add rax rcx
sub rax rcx
add rax rcx
add rax rcx
xor ebx ecx
and ecx eax
xor ecx eax
add eax ebx
add rcx rbx
and rbx rax
xor rcx rax
and eax ebx
sub rcx rax
and rbx rax
sub rax rcx
add rax rcx
add eax ecx
or rcx rax
sub rbx rcx
sub rbx rax
add rcx rbx
add rbx rax
or ecx eax
add ebx ecx
xor rbx rax
add ebx ecx
xor rcx rax
xor rax rcx
add eax ecx
sub rbx rcx
xor ebx eax
sub ecx ebx
or eax ebx
add ecx eax
xor eax ebx
sub rax rbx
xor rcx rbx
or rcx rax
and rax rcx
xor ecx eax
sub rcx rbx
and ebx eax
add rcx rbx
sub ecx eax
add ecx ebx
or rcx rbx
sub ecx eax
xor eax ebx
sub rcx rbx
add rcx rax
sub rbx rcx
add rax rcx
sub ebx eax
and eax ebx
or rcx rbx
or eax ebx
add ebx ecx
sub rbx rcx
and rbx rcx
xor ecx eax
or rax rcx
add eax ebx
sub ebx eax
or rcx rbx
sub rax rbx
sub rbx rcx
sub rax rcx
or ecx eax
and rax rcx
add rax rbx
xor rcx rax
sub ecx ebx
xor ecx ebx
and rax rcx
sub rax rcx
xor rcx rax
add rax rbx
sub rbx rax
add rcx rbx
and rcx rax
xor rcx rbx
and eax ecx
or ebx eax
and eax ecx
add rcx rax
sub ecx ebx
or rcx rax
sub rbx rcx
add ebx eax
sub rax rcx
add rax rcx
xor rbx rax
sub rcx rbx
sub rax rbx
or rbx rax
sub rcx rbx
xor ebx ecx
sub ebx eax
or rcx rax
xor rax rbx
add rbx rcx
xor ebx eax
add rbx rcx
and ebx eax
sub rbx rax
add rcx rbx
or rax rbx
sub ebx eax
add rcx rax
sub ebx ecx
xor rax rcx
xor rcx rax
or rbx rax
and rax rbx
and rbx rcx
xor ebx eax
add eax ebx
sub rbx rax
add ecx ebx
add rbx rax
or ebx eax
or rcx rbx
xor rcx rbx
add rcx rax
sub rax rcx
or rbx rcx
add rax rcx
xor rbx rcx
xor ecx eax
add rcx rax
add eax ebx
sub rbx rax
sub rbx rax
sub eax ebx
add rcx rbx
or ecx ebx
xor rcx rax
sub eax ecx
or ebx ecx
xor rcx rbx
sub rax rcx
add rax rcx
sub rcx rax
add ebx ecx
and rcx rax
and ebx ecx
xor rax rcx
add rax rcx
or rcx rax
and rax rcx
add rax rcx
sub ebx ecx
or ecx eax
or eax ecx
xor eax ecx
or rcx rax
and rax rcx
and ecx eax
xor rax rcx
xor rcx rax
stderr
4 333
total = 333
display/2 = 166