WeixiangYan/CodeTransOcean huggingface dataset:
Task: Subset sum problem







Python: words = { 
	"alliance": -624,	"archbishop": -925,	"balm":	397,
	"bonnet": 452,		"brute": 870,		"centipede": -658,
	"cobol": 362,		"covariate": 590,	"departure": 952,
	"deploy": 44,		"diophantine": 645,	"efferent": 54,
	"elysee": -326,		"eradicate": 376,	"escritoire": 856,
	"exorcism": -983,	"fiat": 170,		"filmy": -874,
	"flatworm": 503,	"gestapo": 915,		"infra": -847,
	"isis": -982,		"lindholm": 999,	"markham": 475,
	"mincemeat": -880,	"moresby": 756,		"mycenae": 183,
	"plugging": -266,	"smokescreen": 423,	"speakeasy": -745,
	"vein": 813
}

neg = 0
pos = 0
for (w,v) in words.iteritems():
	if v > 0: pos += v
	else:     neg += v

sums = [0] * (pos - neg + 1)

for (w,v) in words.iteritems():
	s = sums[:]
	if not s[v - neg]: s[v - neg] = (w,)

	for (i, w2) in enumerate(sums):
		if w2 and not s[i + v]:
			s[i + v] = w2 + (w,)

	sums = s
	if s[-neg]:
		for x in s[-neg]:
			print(x, words[x])
		break





Ada: with Ada.Text_IO; use Ada.Text_IO;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
procedure SubsetSum is
   function "+"(S:String) return Unbounded_String renames To_Unbounded_String;
   type Point is record
      str : Unbounded_String;
      num : Integer;
   end record;
   type Points is array (Natural range <>) of Point;
   type Indices is array (Natural range <>) of Natural;

   procedure Print (data : Points; list : Indices; len : Positive) is begin
      Put (len'Img & ":");
      for i in 0..len-1 loop
         Put (" "& To_String(data(list(i)).str));
      end loop; New_Line;
   end Print;

   function Check (data : Points; list : Indices; len : Positive) return Boolean is
      sum : Integer := 0;
   begin
      for i in 0..len-1 loop sum := sum + data(list(i)).num; end loop;
      return sum = 0;
   end Check;

   procedure Next (list : in out Indices; n, r : Positive ) is begin
      for i in reverse 0..r-1 loop
         if list(i)/=i+n-r then list(i):=list(i)+1;
            for j in i+1..r-1 loop list(j):=list(j-1)+1; end loop; exit;
         end if;
      end loop;
   end Next;

   data : constant Points := ((+"alliance", -624), (+"archbishop", -915),
      (+"balm", 397), (+"bonnet", 452), (+"brute", 870),
      (+"centipede", -658), (+"cobol", 362), (+"covariate", 590),
      (+"departure", 952), (+"deploy", 44), (+"diophantine", 645),
      (+"efferent", 54), (+"elysee", -326), (+"eradicate", 376),
      (+"escritoire", 856), (+"exorcism", -983), (+"fiat", 170),
      (+"filmy", -874), (+"flatworm", 503), (+"gestapo", 915),
      (+"infra", -847), (+"isis", -982), (+"lindholm", 999),
      (+"markham", 475), (+"mincemeat", -880), (+"moresby", 756),
      (+"mycenae", 183), (+"plugging", -266), (+"smokescreen", 423),
      (+"speakeasy", -745), (+"vein", 813));
   list, last : Indices (data'Range);
begin
   for len in 2..data'Length loop
      for i in 0..len-1 loop list(i):=i; end loop;
      loop
         if Check(data, list, len) then Print(data, list, len); exit; end if;
         last := list;
         Next(list, data'Length, len);
         exit when last=list;
      end loop;
   end loop;
end SubsetSum;
Task: Subset sum problem

C: #include <stdio.h>
#include <stdlib.h>

typedef struct {
    char *word;
    int weight;
} item_t;

item_t items[] = {
    {"alliance",     -624},
    {"archbishop",   -915},
    {"balm",          397},
    {"bonnet",        452},
    {"brute",         870},
    {"centipede",    -658},
    {"cobol",         362},
    {"covariate",     590},
    {"departure",     952},
    {"deploy",         44},
    {"diophantine",   645},
    {"efferent",       54},
    {"elysee",       -326},
    {"eradicate",     376},
    {"escritoire",    856},
    {"exorcism",     -983},
    {"fiat",          170},
    {"filmy",        -874},
    {"flatworm",      503},
    {"gestapo",       915},
    {"infra",        -847},
    {"isis",         -982},
    {"lindholm",      999},
    {"markham",       475},
    {"mincemeat",    -880},
    {"moresby",       756},
    {"mycenae",       183},
    {"plugging",     -266},
    {"smokescreen",   423},
    {"speakeasy",    -745},
    {"vein",          813},
};

int n = sizeof (items) / sizeof (item_t);
int *set;

void subsum (int i, int weight) {
    int j;
    if (i && !weight) {
        for (j = 0; j < i; j++) {
            item_t item = items[set[j]];
            printf("%s%s", j ? " " : "", items[set[j]].word);
        }
        printf("\n");
    }
    for (j = i ? set[i - 1] + 1: 0; j < n; j++) {
        set[i] = j;
        subsum(i + 1, weight + items[j].weight);
    }
}

int main () {
    set = malloc(n * sizeof (int));
    subsum(0, 0);
    return 0;
}
Task: Subset sum problem



C#: using System;
using System.Collections.Generic;

namespace SubsetSum {
    class Item {
        public Item(string word, int weight) {
            Word = word;
            Weight = weight;
        }

        public string Word { get; set; }
        public int Weight { get; set; }

        public override string ToString() {
            return string.Format("({0}, {1})", Word, Weight);
        }
    }

    class Program {
        private static readonly List<Item> items = new List<Item>() {
            new Item("alliance", -624),
            new Item("archbishop", -915),
            new Item("balm", 397),
            new Item("bonnet", 452),
            new Item("brute", 870),
            new Item("centipede", -658),
            new Item("cobol", 362),
            new Item("covariate", 590),
            new Item("departure", 952),
            new Item("deploy", 44),
            new Item("diophantine", 645),
            new Item("efferent", 54),
            new Item("elysee", -326),
            new Item("eradicate", 376),
            new Item("escritoire", 856),
            new Item("exorcism", -983),
            new Item("fiat", 170),
            new Item("filmy", -874),
            new Item("flatworm", 503),
            new Item("gestapo", 915),
            new Item("infra", -847),
            new Item("isis", -982),
            new Item("lindholm", 999),
            new Item("markham", 475),
            new Item("mincemeat", -880),
            new Item("moresby", 756),
            new Item("mycenae", 183),
            new Item("plugging", -266),
            new Item("smokescreen", 423),
            new Item("speakeasy", -745),
            new Item("vein", 813),
        };

        private static readonly int n = items.Count;
        private static readonly int LIMIT = 5;

        private static int[] indices = new int[n];
        private static int count = 0;

        private static void ZeroSum(int i, int w) {
            if (i != 0 && w == 0) {
                for (int j = 0; j < i; j++) {
                    Console.Write("{0} ", items[indices[j]]);
                }
                Console.WriteLine("\n");
                if (count < LIMIT) count++;
                else return;
            }
            int k = (i != 0) ? indices[i - 1] + 1 : 0;
            for (int j = k; j < n; j++) {
                indices[i] = j;
                ZeroSum(i + 1, w + items[j].Weight);
                if (count == LIMIT) return;
            }
        }

        static void Main(string[] args) {
            Console.WriteLine("The weights of the following {0} subsets add up to zero:\n", LIMIT);
            ZeroSum(0, 0);
        }
    }
}
Task: Subset sum problem


C++: #include <iostream>
#include <vector>

std::ostream& operator<<(std::ostream& out, const std::string& str) {
    return out << str.c_str();
}

std::vector<std::pair<std::string, int>> items{
    {"alliance",     -624},
    {"archbishop",   -915},
    {"balm",          397},
    {"bonnet",        452},
    {"brute",         870},
    {"centipede",    -658},
    {"cobol",         362},
    {"covariate",     590},
    {"departure",     952},
    {"deploy",         44},
    {"diophantine",   645},
    {"efferent",       54},
    {"elysee",       -326},
    {"eradicate",     376},
    {"escritoire",    856},
    {"exorcism",     -983},
    {"fiat",          170},
    {"filmy",        -874},
    {"flatworm",      503},
    {"gestapo",       915},
    {"infra",        -847},
    {"isis",         -982},
    {"lindholm",      999},
    {"markham",       475},
    {"mincemeat",    -880},
    {"moresby",       756},
    {"mycenae",       183},
    {"plugging",     -266},
    {"smokescreen",   423},
    {"speakeasy",    -745},
    {"vein",          813},
};

std::vector<int> indices;
int count = 0;
const int LIMIT = 5;

void subsum(int i, int weight) {
    if (i != 0 && weight == 0) {
        for (int j = 0; j < i; ++j) {
            auto item = items[indices[j]];
            std::cout << (j ? " " : "") << item.first;
        }
        std::cout << '\n';
        if (count < LIMIT) count++;
        else return;
    }
    int k = (i != 0) ? indices[i - 1] + 1 : 0;
    for (int j = k; j < items.size(); ++j) {
        indices[i] = j;
        subsum(i + 1, weight + items[j].second);
        if (count == LIMIT) return;
    }
}

int main() {
    indices.resize(items.size());
    subsum(0, 0);
    return 0;
}
Task: Subset sum problem





Java: public class SubsetSum {
    private static class Item {
        private String word;
        private int weight;

        public Item(String word, int weight) {
            this.word = word;
            this.weight = weight;
        }

        @Override
        public String toString() {
            return String.format("(%s, %d)", word, weight);
        }
    }

    private static Item[] items = new Item[]{
        new Item("alliance", -624),
        new Item("archbishop", -915),
        new Item("balm", 397),
        new Item("bonnet", 452),
        new Item("brute", 870),
        new Item("centipede", -658),
        new Item("cobol", 362),
        new Item("covariate", 590),
        new Item("departure", 952),
        new Item("deploy", 44),
        new Item("diophantine", 645),
        new Item("efferent", 54),
        new Item("elysee", -326),
        new Item("eradicate", 376),
        new Item("escritoire", 856),
        new Item("exorcism", -983),
        new Item("fiat", 170),
        new Item("filmy", -874),
        new Item("flatworm", 503),
        new Item("gestapo", 915),
        new Item("infra", -847),
        new Item("isis", -982),
        new Item("lindholm", 999),
        new Item("markham", 475),
        new Item("mincemeat", -880),
        new Item("moresby", 756),
        new Item("mycenae", 183),
        new Item("plugging", -266),
        new Item("smokescreen", 423),
        new Item("speakeasy", -745),
        new Item("vein", 813),
    };

    private static final int n = items.length;
    private static final int[] indices = new int[n];
    private static int count = 0;

    private static final int LIMIT = 5;

    private static void zeroSum(int i, int w) {
        if (i != 0 && w == 0) {
            for (int j = 0; j < i; ++j) {
                System.out.printf("%s ", items[indices[j]]);
            }
            System.out.println("\n");
            if (count < LIMIT) count++;
            else return;
        }
        int k = (i != 0) ? indices[i - 1] + 1 : 0;
        for (int j = k; j < n; ++j) {
            indices[i] = j;
            zeroSum(i + 1, w + items[j].weight);
            if (count == LIMIT) return;
        }
    }

    public static void main(String[] args) {
        System.out.printf("The weights of the following %d subsets add up to zero:\n\n", LIMIT);
        zeroSum(0, 0);
    }
}
Task: Subset sum problem







Python: words = { 
	"alliance": -624,	"archbishop": -925,	"balm":	397,
	"bonnet": 452,		"brute": 870,		"centipede": -658,
	"cobol": 362,		"covariate": 590,	"departure": 952,
	"deploy": 44,		"diophantine": 645,	"efferent": 54,
	"elysee": -326,		"eradicate": 376,	"escritoire": 856,
	"exorcism": -983,	"fiat": 170,		"filmy": -874,
	"flatworm": 503,	"gestapo": 915,		"infra": -847,
	"isis": -982,		"lindholm": 999,	"markham": 475,
	"mincemeat": -880,	"moresby": 756,		"mycenae": 183,
	"plugging": -266,	"smokescreen": 423,	"speakeasy": -745,
	"vein": 813
}

neg = 0
pos = 0
for (w,v) in words.iteritems():
	if v > 0: pos += v
	else:     neg += v

sums = [0] * (pos - neg + 1)

for (w,v) in words.iteritems():
	s = sums[:]
	if not s[v - neg]: s[v - neg] = (w,)

	for (i, w2) in enumerate(sums):
		if w2 and not s[i + v]:
			s[i + v] = w2 + (w,)

	sums = s
	if s[-neg]:
		for x in s[-neg]:
			print(x, words[x])
		break
Task: Subset sum problem




Go: package main

import "fmt"

type ww struct {
    word   string
    weight int
}

var input = []*ww{
    {"alliance", -624},
    {"archbishop", -915},
    {"balm", 397},
    {"bonnet", 452},
    {"brute", 870},
    {"centipede", -658},
    {"cobol", 362},
    {"covariate", 590},
    {"departure", 952},
    {"deploy", 44},
    {"diophantine", 645},
    {"efferent", 54},
    {"elysee", -326},
    {"eradicate", 376},
    {"escritoire", 856},
    {"exorcism", -983},
    {"fiat", 170},
    {"filmy", -874},
    {"flatworm", 503},
    {"gestapo", 915},
    {"infra", -847},
    {"isis", -982},
    {"lindholm", 999},
    {"markham", 475},
    {"mincemeat", -880},
    {"moresby", 756},
    {"mycenae", 183},
    {"plugging", -266},
    {"smokescreen", 423},
    {"speakeasy", -745},
    {"vein", 813},
}

type sss struct {
    subset []*ww
    sum    int
}

func main() {
    ps := []sss{{nil, 0}}
    for _, i := range input {
        pl := len(ps)
        for j := 0; j < pl; j++ {
            subset := append([]*ww{i}, ps[j].subset...)
            sum := i.weight + ps[j].sum
            if sum == 0 {
                fmt.Println("this subset sums to 0:")
                for _, i := range subset {
                    fmt.Println(*i)
                }
                return
            }
            ps = append(ps, sss{subset, sum})
        }
    }
    fmt.Println("no subset sums to 0")
}
Task: Man or boy test



C#: using System;
 
delegate T Func<T>();
 
class ManOrBoy
{
    static void Main()
    {
        Console.WriteLine(A(10, C(1), C(-1), C(-1), C(1), C(0)));
    }
 
    static Func<int> C(int i)
    {
        return delegate { return i; };
    }
 
    static int A(int k, Func<int> x1, Func<int> x2, Func<int> x3, Func<int> x4, Func<int> x5)
    {
        Func<int> b = null;
        b = delegate { k--; return A(k, b, x1, x2, x3, x4); };
        return k <= 0 ? x4() + x5() : b();
    }
}









Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Man_Or_Boy is
   function Zero return Integer is begin return  0; end Zero;
   function One return Integer  is begin return  1; end One;
   function Neg return Integer  is begin return -1; end Neg;

   function A
            (  K : Integer;
               X1, X2, X3, X4, X5 : access function return Integer
            )  return Integer is
      M : Integer := K; 
      function B return Integer is
      begin
         M := M - 1;
         return A (M, B'Access, X1, X2, X3, X4);
      end B;
   begin
      if M <= 0 then
         return X4.all + X5.all;
      else
         return B;
      end if;
   end A;
begin
   Put_Line
   (  Integer'Image
       (  A
          (  10,
             One'Access, 
             Neg'Access, 
             Neg'Access, 
             One'Access, 
             Zero'Access 
   )  )  );
end Man_Or_Boy;
Task: Man or boy test

C: 
#include <stdio.h>
#include <stdlib.h>


typedef struct arg
{
  int       (*fn)(struct arg*);
  int        *k;
  struct arg *x1, *x2, *x3, *x4, *x5;
} ARG;


int f_1 (ARG* _) { return -1; }
int f0  (ARG* _) { return  0; }
int f1  (ARG* _) { return  1; }


int eval(ARG* a) { return a->fn(a); }
#define MAKE_ARG(...) (&(ARG){__VA_ARGS__})
#define FUN(...) MAKE_ARG(B, &k, __VA_ARGS__)

int A(ARG*);


int B(ARG* a)
{
  int k = *a->k -= 1;
  return A(FUN(a, a->x1, a->x2, a->x3, a->x4));
}

int A(ARG* a)
{
  return *a->k <= 0 ? eval(a->x4) + eval(a->x5) : B(a);
}

int main(int argc, char **argv)
{
  int k = argc == 2 ? strtol(argv[1], 0, 0) : 10;
  printf("%d\n", A(FUN(MAKE_ARG(f1), MAKE_ARG(f_1), MAKE_ARG(f_1),
                       MAKE_ARG(f1), MAKE_ARG(f0))));
  return 0;
}











Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Man_Or_Boy is
   function Zero return Integer is begin return  0; end Zero;
   function One return Integer  is begin return  1; end One;
   function Neg return Integer  is begin return -1; end Neg;

   function A
            (  K : Integer;
               X1, X2, X3, X4, X5 : access function return Integer
            )  return Integer is
      M : Integer := K; 
      function B return Integer is
      begin
         M := M - 1;
         return A (M, B'Access, X1, X2, X3, X4);
      end B;
   begin
      if M <= 0 then
         return X4.all + X5.all;
      else
         return B;
      end if;
   end A;
begin
   Put_Line
   (  Integer'Image
       (  A
          (  10,
             One'Access, 
             Neg'Access, 
             Neg'Access, 
             One'Access, 
             Zero'Access 
   )  )  );
end Man_Or_Boy;
Task: Man or boy test


C++: #include <iostream>
#include <tr1/memory>
using std::tr1::shared_ptr;
using std::tr1::enable_shared_from_this;

struct Arg {
  virtual int run() = 0;
  virtual ~Arg() { };
};

int A(int, shared_ptr<Arg>, shared_ptr<Arg>, shared_ptr<Arg>,
      shared_ptr<Arg>, shared_ptr<Arg>);

class B : public Arg, public enable_shared_from_this<B> {
private:
  int k;
  const shared_ptr<Arg> x1, x2, x3, x4;

public:
  B(int _k, shared_ptr<Arg> _x1, shared_ptr<Arg> _x2, shared_ptr<Arg> _x3,
    shared_ptr<Arg> _x4)
    : k(_k), x1(_x1), x2(_x2), x3(_x3), x4(_x4) { }
  int run() {
    return A(--k, shared_from_this(), x1, x2, x3, x4);
  }
};

class Const : public Arg {
private:
  const int x;
public:
  Const(int _x) : x(_x) { }
  int run () { return x; }
};

int A(int k, shared_ptr<Arg> x1, shared_ptr<Arg> x2, shared_ptr<Arg> x3,
      shared_ptr<Arg> x4, shared_ptr<Arg> x5) {
  if (k <= 0)
    return x4->run() + x5->run();
  else {
    shared_ptr<Arg> b(new B(k, x1, x2, x3, x4));
    return b->run();
  }
}

int main() {
  std::cout << A(10, shared_ptr<Arg>(new Const(1)),
                 shared_ptr<Arg>(new Const(-1)),
                 shared_ptr<Arg>(new Const(-1)),
                 shared_ptr<Arg>(new Const(1)),
                 shared_ptr<Arg>(new Const(0))) << std::endl;
  return 0;
}










Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Man_Or_Boy is
   function Zero return Integer is begin return  0; end Zero;
   function One return Integer  is begin return  1; end One;
   function Neg return Integer  is begin return -1; end Neg;

   function A
            (  K : Integer;
               X1, X2, X3, X4, X5 : access function return Integer
            )  return Integer is
      M : Integer := K; 
      function B return Integer is
      begin
         M := M - 1;
         return A (M, B'Access, X1, X2, X3, X4);
      end B;
   begin
      if M <= 0 then
         return X4.all + X5.all;
      else
         return B;
      end if;
   end A;
begin
   Put_Line
   (  Integer'Image
       (  A
          (  10,
             One'Access, 
             Neg'Access, 
             Neg'Access, 
             One'Access, 
             Zero'Access 
   )  )  );
end Man_Or_Boy;
Task: Man or boy test




Go: package main
import "fmt"

func a(k int, x1, x2, x3, x4, x5 func() int) int {
	var b func() int
	b = func() int {
		k--
		return a(k, b, x1, x2, x3, x4)
	}
	if k <= 0 {
		return x4() + x5()
	}
	return b()
}

func main() {
	x := func(i int) func() int { return func() int { return i } }
	fmt.Println(a(10, x(1), x(-1), x(-1), x(1), x(0)))
}








Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Man_Or_Boy is
   function Zero return Integer is begin return  0; end Zero;
   function One return Integer  is begin return  1; end One;
   function Neg return Integer  is begin return -1; end Neg;

   function A
            (  K : Integer;
               X1, X2, X3, X4, X5 : access function return Integer
            )  return Integer is
      M : Integer := K; 
      function B return Integer is
      begin
         M := M - 1;
         return A (M, B'Access, X1, X2, X3, X4);
      end B;
   begin
      if M <= 0 then
         return X4.all + X5.all;
      else
         return B;
      end if;
   end A;
begin
   Put_Line
   (  Integer'Image
       (  A
          (  10,
             One'Access, 
             Neg'Access, 
             Neg'Access, 
             One'Access, 
             Zero'Access 
   )  )  );
end Man_Or_Boy;
Task: Man or boy test





Java: import java.util.function.DoubleSupplier;

public class ManOrBoy {
    
    static double A(int k, DoubleSupplier x1, DoubleSupplier x2,
                 DoubleSupplier x3, DoubleSupplier x4, DoubleSupplier x5) {
        
        DoubleSupplier B = new DoubleSupplier() {
            int m = k;
            public double getAsDouble() {
                return A(--m, this, x1, x2, x3, x4);
            }
        };
                
        return k <= 0 ? x4.getAsDouble() + x5.getAsDouble() : B.getAsDouble();
    }
    
    public static void main(String[] args) {
        System.out.println(A(10, () -> 1.0, () -> -1.0, () -> -1.0, () -> 1.0, () -> 0.0));
    }
}







Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Man_Or_Boy is
   function Zero return Integer is begin return  0; end Zero;
   function One return Integer  is begin return  1; end One;
   function Neg return Integer  is begin return -1; end Neg;

   function A
            (  K : Integer;
               X1, X2, X3, X4, X5 : access function return Integer
            )  return Integer is
      M : Integer := K; 
      function B return Integer is
      begin
         M := M - 1;
         return A (M, B'Access, X1, X2, X3, X4);
      end B;
   begin
      if M <= 0 then
         return X4.all + X5.all;
      else
         return B;
      end if;
   end A;
begin
   Put_Line
   (  Integer'Image
       (  A
          (  10,
             One'Access, 
             Neg'Access, 
             Neg'Access, 
             One'Access, 
             Zero'Access 
   )  )  );
end Man_Or_Boy;
Task: Man or boy test







Python: 
import sys
sys.setrecursionlimit(1025)

def a(in_k, x1, x2, x3, x4, x5):
    k = [in_k]
    def b():
        k[0] -= 1
        return a(k[0], b, x1, x2, x3, x4)
    return x4() + x5() if k[0] <= 0 else b()

x = lambda i: lambda: i
print(a(10, x(1), x(-1), x(-1), x(1), x(0)))





Ada: with Ada.Text_IO;  use Ada.Text_IO;

procedure Man_Or_Boy is
   function Zero return Integer is begin return  0; end Zero;
   function One return Integer  is begin return  1; end One;
   function Neg return Integer  is begin return -1; end Neg;

   function A
            (  K : Integer;
               X1, X2, X3, X4, X5 : access function return Integer
            )  return Integer is
      M : Integer := K; 
      function B return Integer is
      begin
         M := M - 1;
         return A (M, B'Access, X1, X2, X3, X4);
      end B;
   begin
      if M <= 0 then
         return X4.all + X5.all;
      else
         return B;
      end if;
   end A;
begin
   Put_Line
   (  Integer'Image
       (  A
          (  10,
             One'Access, 
             Neg'Access, 
             Neg'Access, 
             One'Access, 
             Zero'Access 
   )  )  );
end Man_Or_Boy;
Task: Man or boy test

C: 
#include <stdio.h>
#include <stdlib.h>


typedef struct arg
{
  int       (*fn)(struct arg*);
  int        *k;
  struct arg *x1, *x2, *x3, *x4, *x5;
} ARG;


int f_1 (ARG* _) { return -1; }
int f0  (ARG* _) { return  0; }
int f1  (ARG* _) { return  1; }


int eval(ARG* a) { return a->fn(a); }
#define MAKE_ARG(...) (&(ARG){__VA_ARGS__})
#define FUN(...) MAKE_ARG(B, &k, __VA_ARGS__)

int A(ARG*);


int B(ARG* a)
{
  int k = *a->k -= 1;
  return A(FUN(a, a->x1, a->x2, a->x3, a->x4));
}

int A(ARG* a)
{
  return *a->k <= 0 ? eval(a->x4) + eval(a->x5) : B(a);
}

int main(int argc, char **argv)
{
  int k = argc == 2 ? strtol(argv[1], 0, 0) : 10;
  printf("%d\n", A(FUN(MAKE_ARG(f1), MAKE_ARG(f_1), MAKE_ARG(f_1),
                       MAKE_ARG(f1), MAKE_ARG(f0))));
  return 0;
}