namespace; include rt; // o3 regions: every kind of control flow, against the same code without o3 struct pt { int x; int y; }; int g = 3; int sq(int x) { return x * x; } o3 int collatz(int n) { int steps = 0; while (n != 1) { if (n % 2 == 0) n = n / 2; else n = 3 * n + 1; steps++; } return steps; } o3 int ack(int am, int n) { if (am == 0) return n + 1; if (n == 0) return ack(am - 1, 1); return ack(am - 1, ack(am, n - 1)); } o3 int many(int a, int b, int c) { int dd = a + b, e = b + c, f = c + a, h = dd * e, i2 = e * f, j = f * dd, k = h + i2 + j, l = k / 7; for (int t = 0; t < 5; t++) { dd += t; e -= t; f = f ^ t; l = l + dd * e - f; } return dd + e + f + h + i2 + j + k + l; } o3 int mix(int n) { int acc = 0; for (int i = 0; i < n; i++) { if (i % 3 == 0 && i % 5 == 0) acc += 15; else if (i % 3 == 0 || i > 90) acc += 3; else acc = acc + (i & 1 ? sq(i) : g); switch (i % 4) { case 0: acc += 1; case 1: acc -= 2; default: acc = acc ^ 1; } if (acc > 100000) break; if (i == 7) continue; acc = acc + i / 10 - i % 7 + (i << 2) - (i >> 1); } return acc; } o3 int dyn(int n) { int[?] a = rt.new(int[?], n); fixed int[?] f = rt.new(fixed int[?], n); int s = 0; for (int i = 0; i < len(a); i++) { a[i] = i * i; f[i] = n - i; } for (int i = 0; i < n; i++) s = s + a[i] * f[i]; rt.free(d*a); rt.free(d*f); return s; } o3 int pts(int n) { pt* p = rt.new(pt); int s = 0; p->x = 1; p->y = 2; for (int i = 0; i < n; i++) { p->x = p->x + p->y; p->y = p->x - p->y; s = s + p->x % 1000; } rt.free(d*p); return s; } o3 int divs(int x) { int s = 0; for (int i = -50; i < 50; i++) s = s + (x + i) / 7 + (x + i) % 7 + (x - i) / -3 + i / 16 + i % 16; return s; } fn main() { o3 int lone = 2; let r = 0; lone = lone * 21; o3 { int i = 0, s = 0; while (i < 100) { s = s + collatz(i + 1); i++; } rt.put_n(s); rt.put_c(' '); rt.put_n(lone); rt.put_c(' '); lone++; } rt.put_n(lone); rt.put_c(' '); rt.put_n(ack(2, 3)); rt.put_c(' '); rt.put_n(many(1, 2, 3)); rt.put_c(' '); rt.put_n(mix(100)); rt.put_c(' '); rt.put_n(dyn(50)); rt.put_c(' '); rt.put_n(pts(30)); rt.put_c(' '); rt.put_n(divs(1000)); rt.put_c(' '); rt.put_n(divs(-77)); rt.put_c(10); return 0; }