WeixiangYan/CodeTransOcean huggingface dataset:
Task: Text processing_Max licenses in use

C: #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>

#define INOUT_LEN 4
#define TIME_LEN 20
#define MAX_MAXOUT 1000

char inout[INOUT_LEN];
char time[TIME_LEN];
uint jobnum;

char maxtime[MAX_MAXOUT][TIME_LEN];

int main(int argc, char **argv)
{
  FILE *in = NULL;
  int l_out = 0, maxout=-1, maxcount=0;

  if ( argc > 1 ) {
    in = fopen(argv[1], "r");
    if ( in == NULL ) {
      fprintf(stderr, "cannot read %s\n", argv[1]);
      exit(1);
    }
  } else {
    in = stdin;
  }

  while( fscanf(in, "License %s @ %s for job %u\n", inout, time, &jobnum) != EOF ) {

    if ( strcmp(inout, "OUT") == 0 )
      l_out++;
    else
      l_out--;

    if ( l_out > maxout ) {
      maxout = l_out;
      maxcount=0; maxtime[0][0] = '\0';
    }
    if ( l_out == maxout ) {
      if ( maxcount < MAX_MAXOUT ) {
    strncpy(maxtime[maxcount], time, TIME_LEN);
    maxcount++;
      } else {
    fprintf(stderr, "increase MAX_MAXOUT (now it is %u)\n", MAX_MAXOUT);
    exit(1);
      }
    }
  }

  printf("Maximum simultaneous license use is %d at the following times:\n", maxout);
  for(l_out=0; l_out < maxcount; l_out++) {
    printf("%s\n", maxtime[l_out]);
  }

  if ( in != stdin ) fclose(in);
  exit(0);
}




Go: package main

import (
    "bufio"
    "bytes"
    "fmt"
    "log"
    "os"
)

const (
    filename   = "mlijobs.txt"
    inoutField = 1
    timeField  = 3
    numFields  = 7
)

func main() {
    file, err := os.Open(filename)
    if err != nil {
        log.Fatal(err)
    }
    defer file.Close()
    var ml, out int
    var mlTimes []string
    in := []byte("IN")
    s := bufio.NewScanner(file)
    for s.Scan() {
        f := bytes.Fields(s.Bytes())
        if len(f) != numFields {
            log.Fatal("unexpected format,", len(f), "fields.")
        }
        if bytes.Equal(f[inoutField], in) {
            out--
            if out < 0 {
                log.Fatalf("negative license use at %s", f[timeField])
            }
            continue
        }
        out++
        if out < ml {
            continue
        }

        if out > ml {
            ml = out
            mlTimes = mlTimes[:0]
        }
        mlTimes = append(mlTimes, string(f[timeField]))
    }
    if err = s.Err(); err != nil {
        log.Fatal(err)
    }

    fmt.Println("max licenses:", ml)
    fmt.Println("at:")
    for _, t := range mlTimes {
        fmt.Println(" ", t)
    }
}
Task: Text processing_Max licenses in use

C: #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>

#define INOUT_LEN 4
#define TIME_LEN 20
#define MAX_MAXOUT 1000

char inout[INOUT_LEN];
char time[TIME_LEN];
uint jobnum;

char maxtime[MAX_MAXOUT][TIME_LEN];

int main(int argc, char **argv)
{
  FILE *in = NULL;
  int l_out = 0, maxout=-1, maxcount=0;

  if ( argc > 1 ) {
    in = fopen(argv[1], "r");
    if ( in == NULL ) {
      fprintf(stderr, "cannot read %s\n", argv[1]);
      exit(1);
    }
  } else {
    in = stdin;
  }

  while( fscanf(in, "License %s @ %s for job %u\n", inout, time, &jobnum) != EOF ) {

    if ( strcmp(inout, "OUT") == 0 )
      l_out++;
    else
      l_out--;

    if ( l_out > maxout ) {
      maxout = l_out;
      maxcount=0; maxtime[0][0] = '\0';
    }
    if ( l_out == maxout ) {
      if ( maxcount < MAX_MAXOUT ) {
    strncpy(maxtime[maxcount], time, TIME_LEN);
    maxcount++;
      } else {
    fprintf(stderr, "increase MAX_MAXOUT (now it is %u)\n", MAX_MAXOUT);
    exit(1);
      }
    }
  }

  printf("Maximum simultaneous license use is %d at the following times:\n", maxout);
  for(l_out=0; l_out < maxcount; l_out++) {
    printf("%s\n", maxtime[l_out]);
  }

  if ( in != stdin ) fclose(in);
  exit(0);
}






PHP: $handle = fopen ("mlijobs.txt", "rb");
$maxcount = 0;
$count = 0;
$times = array();
while (!feof($handle)) {
    $buffer = fgets($handle);
    $op = trim(substr($buffer,8,3));
    switch ($op){
        case 'IN':
            $count--;
        break;
        case 'OUT':
            $count++;
            preg_match('/([\d|\/|_|:]+)/',$buffer,$time);
            if($count>$maxcount){
                $maxcount = $count;
                $times = Array($time[0]);
            }elseif($count == $maxcount){
                $times[] = $time[0];
            }
        break;
    }   
}
fclose ($handle);

echo $maxcount . '<br>';
for($i=0;$i<count($times);$i++){
    echo $times[$i] . '<br>';
}
Task: Text processing_Max licenses in use



C#: using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace TextProc3
{
    class Program
    {
        static void Main(string[] args)
        {            
            string line;
            int count = 0, maxcount = 0;
            List<string> times = new List<string>();
            System.IO.StreamReader file = new StreamReader("mlijobs.txt");
            while ((line = file.ReadLine()) != null)
            {
                string[] lineelements = line.Split(' ');                
                switch (lineelements[1])
                {
                    case "IN":
                        count--;
                        break;
                    case "OUT":
                        count++;
                        if (count > maxcount)
                        {
                            maxcount = count;
                            times.Clear();
                            times.Add(lineelements[3]);
                        }else if(count == maxcount){
                            times.Add(lineelements[3]);
                        }
                        break;
                }                
            }
            file.Close();
            Console.WriteLine(maxcount);
            foreach (string time in times)
            {
                Console.WriteLine(time);
            }
        }
    }
}




PHP: $handle = fopen ("mlijobs.txt", "rb");
$maxcount = 0;
$count = 0;
$times = array();
while (!feof($handle)) {
    $buffer = fgets($handle);
    $op = trim(substr($buffer,8,3));
    switch ($op){
        case 'IN':
            $count--;
        break;
        case 'OUT':
            $count++;
            preg_match('/([\d|\/|_|:]+)/',$buffer,$time);
            if($count>$maxcount){
                $maxcount = $count;
                $times = Array($time[0]);
            }elseif($count == $maxcount){
                $times[] = $time[0];
            }
        break;
    }   
}
fclose ($handle);

echo $maxcount . '<br>';
for($i=0;$i<count($times);$i++){
    echo $times[$i] . '<br>';
}
Task: Text processing_Max licenses in use


C++: #include <fstream>
#include <iostream>
#include <iterator>
#include <string>
#include <vector>

int main()
{
    const char logfilename[] = "mlijobs.txt";
    std::ifstream logfile(logfilename);

    if (!logfile.is_open())
    {
        std::cerr << "Error opening: " << logfilename << "\n";
        return -1;
    }

    int license = 0, max_license = 0;
    std::vector<std::string> max_timestamp;

    for (std::string logline; std::getline(logfile, logline); )
    {
        std::string action(logline.substr(8,3));

        if (action == "OUT")
        {
            if (++license >= max_license)
            {
                if (license > max_license)
                {
                    max_license = license;
                    max_timestamp.clear();
                }
                max_timestamp.push_back(logline.substr(14, 19));
            }
        }
        else if (action == "IN ")
        {
            --license;
        }
    }

    std::cout << "License count at log end: " << license
        << "\nMaximum simultaneous license: " << max_license
        << "\nMaximum license time(s):\n";

    std::copy(max_timestamp.begin(), max_timestamp.end(),
        std::ostream_iterator<std::string>(std::cout, "\n"));
}





PHP: $handle = fopen ("mlijobs.txt", "rb");
$maxcount = 0;
$count = 0;
$times = array();
while (!feof($handle)) {
    $buffer = fgets($handle);
    $op = trim(substr($buffer,8,3));
    switch ($op){
        case 'IN':
            $count--;
        break;
        case 'OUT':
            $count++;
            preg_match('/([\d|\/|_|:]+)/',$buffer,$time);
            if($count>$maxcount){
                $maxcount = $count;
                $times = Array($time[0]);
            }elseif($count == $maxcount){
                $times[] = $time[0];
            }
        break;
    }   
}
fclose ($handle);

echo $maxcount . '<br>';
for($i=0;$i<count($times);$i++){
    echo $times[$i] . '<br>';
}
Task: Text processing_Max licenses in use




Go: package main

import (
    "bufio"
    "bytes"
    "fmt"
    "log"
    "os"
)

const (
    filename   = "mlijobs.txt"
    inoutField = 1
    timeField  = 3
    numFields  = 7
)

func main() {
    file, err := os.Open(filename)
    if err != nil {
        log.Fatal(err)
    }
    defer file.Close()
    var ml, out int
    var mlTimes []string
    in := []byte("IN")
    s := bufio.NewScanner(file)
    for s.Scan() {
        f := bytes.Fields(s.Bytes())
        if len(f) != numFields {
            log.Fatal("unexpected format,", len(f), "fields.")
        }
        if bytes.Equal(f[inoutField], in) {
            out--
            if out < 0 {
                log.Fatalf("negative license use at %s", f[timeField])
            }
            continue
        }
        out++
        if out < ml {
            continue
        }

        if out > ml {
            ml = out
            mlTimes = mlTimes[:0]
        }
        mlTimes = append(mlTimes, string(f[timeField]))
    }
    if err = s.Err(); err != nil {
        log.Fatal(err)
    }

    fmt.Println("max licenses:", ml)
    fmt.Println("at:")
    for _, t := range mlTimes {
        fmt.Println(" ", t)
    }
}



PHP: $handle = fopen ("mlijobs.txt", "rb");
$maxcount = 0;
$count = 0;
$times = array();
while (!feof($handle)) {
    $buffer = fgets($handle);
    $op = trim(substr($buffer,8,3));
    switch ($op){
        case 'IN':
            $count--;
        break;
        case 'OUT':
            $count++;
            preg_match('/([\d|\/|_|:]+)/',$buffer,$time);
            if($count>$maxcount){
                $maxcount = $count;
                $times = Array($time[0]);
            }elseif($count == $maxcount){
                $times[] = $time[0];
            }
        break;
    }   
}
fclose ($handle);

echo $maxcount . '<br>';
for($i=0;$i<count($times);$i++){
    echo $times[$i] . '<br>';
}
Task: Text processing_Max licenses in use





Java: import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.LinkedList;

public class License {
  public static void main(String[] args) throws FileNotFoundException, IOException{
    BufferedReader in = new BufferedReader(new FileReader(args[0]));
    int max = Integer.MIN_VALUE;
    LinkedList<String> dates = new LinkedList<String>();
    String line;
    int count = 0;
    while((line = in.readLine()) != null){
      if(line.startsWith("License OUT ")) count++;
      if(line.startsWith("License IN ")) count--;
      if(count > max){
        max = count;
        String date = line.split(" ")[3];
        dates.clear();
        dates.add(date);
      }else if(count == max){
        String date = line.split(" ")[3];
        dates.add(date);
      }
    }
    System.out.println("Max licenses out: "+max);
    System.out.println("At time(s): "+dates);
  }
}


PHP: $handle = fopen ("mlijobs.txt", "rb");
$maxcount = 0;
$count = 0;
$times = array();
while (!feof($handle)) {
    $buffer = fgets($handle);
    $op = trim(substr($buffer,8,3));
    switch ($op){
        case 'IN':
            $count--;
        break;
        case 'OUT':
            $count++;
            preg_match('/([\d|\/|_|:]+)/',$buffer,$time);
            if($count>$maxcount){
                $maxcount = $count;
                $times = Array($time[0]);
            }elseif($count == $maxcount){
                $times[] = $time[0];
            }
        break;
    }   
}
fclose ($handle);

echo $maxcount . '<br>';
for($i=0;$i<count($times);$i++){
    echo $times[$i] . '<br>';
}
Task: Text processing_Max licenses in use






PHP: $handle = fopen ("mlijobs.txt", "rb");
$maxcount = 0;
$count = 0;
$times = array();
while (!feof($handle)) {
    $buffer = fgets($handle);
    $op = trim(substr($buffer,8,3));
    switch ($op){
        case 'IN':
            $count--;
        break;
        case 'OUT':
            $count++;
            preg_match('/([\d|\/|_|:]+)/',$buffer,$time);
            if($count>$maxcount){
                $maxcount = $count;
                $times = Array($time[0]);
            }elseif($count == $maxcount){
                $times[] = $time[0];
            }
        break;
    }   
}
fclose ($handle);

echo $maxcount . '<br>';
for($i=0;$i<count($times);$i++){
    echo $times[$i] . '<br>';
}


Python: out, max_out, max_times = 0, -1, []
for job in open('mlijobs.txt'):
    out += 1 if "OUT" in job else -1
    if out > max_out:
        max_out, max_times = out, []
    if out == max_out:
        max_times.append(job.split()[3])
        
print("Maximum simultaneous license use is %i at the following times:" % max_out)
print('  ' + '\n  '.join(max_times))
Task: String append

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

int main()
{
    char str[24]="Good Morning";
    char *cstr=" to all";
    char *cstr2=" !!!";
    int x=0;
    

    if(sizeof(str)>strlen(str)+strlen(cstr)+strlen(cstr2))
            {
                
                strcat(str,cstr);

                
                x=strlen(str);
                sprintf(&str[x],"%s",cstr2);

                printf("%s\n",str);

            }
    return 0;
}



C#: class Program
{
    static void Main(string[] args)
    {
        string x = "foo";
        x += "bar";
        System.Console.WriteLine(x);
    }
}
Task: String append

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

int main()
{
    char str[24]="Good Morning";
    char *cstr=" to all";
    char *cstr2=" !!!";
    int x=0;
    

    if(sizeof(str)>strlen(str)+strlen(cstr)+strlen(cstr2))
            {
                
                strcat(str,cstr);

                
                x=strlen(str);
                sprintf(&str[x],"%s",cstr2);

                printf("%s\n",str);

            }
    return 0;
}








VB: Function StringAppend()
Dim s As String
s = "foo"
s = s & "bar"
Debug.Print s
End Function
Task: String append



C#: class Program
{
    static void Main(string[] args)
    {
        string x = "foo";
        x += "bar";
        System.Console.WriteLine(x);
    }
}



Java: String sa = "Hello";
sa += ", World!";
System.out.println(sa);

StringBuilder ba = new StringBuilder();
ba.append("Hello");
ba.append(", World!");
System.out.println(ba.toString());
Task: String append



C#: class Program
{
    static void Main(string[] args)
    {
        string x = "foo";
        x += "bar";
        System.Console.WriteLine(x);
    }
}





Python: 


str = "12345678";
str += "9!";
print(str)
Task: String append





Java: String sa = "Hello";
sa += ", World!";
System.out.println(sa);

StringBuilder ba = new StringBuilder();
ba.append("Hello");
ba.append(", World!");
System.out.println(ba.toString());



Python: 


str = "12345678";
str += "9!";
print(str)
Task: String append




Go: s := "foo"
s += "bar"





VB: Function StringAppend()
Dim s As String
s = "foo"
s = s & "bar"
Debug.Print s
End Function
Task: String append







Python: 


str = "12345678";
str += "9!";
print(str)


VB: Function StringAppend()
Dim s As String
s = "foo"
s = s & "bar"
Debug.Print s
End Function
Task: String append

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

int main()
{
    char str[24]="Good Morning";
    char *cstr=" to all";
    char *cstr2=" !!!";
    int x=0;
    

    if(sizeof(str)>strlen(str)+strlen(cstr)+strlen(cstr2))
            {
                
                strcat(str,cstr);

                
                x=strlen(str);
                sprintf(&str[x],"%s",cstr2);

                printf("%s\n",str);

            }
    return 0;
}





Java: String sa = "Hello";
sa += ", World!";
System.out.println(sa);

StringBuilder ba = new StringBuilder();
ba.append("Hello");
ba.append(", World!");
System.out.println(ba.toString());
Task: String append



C#: class Program
{
    static void Main(string[] args)
    {
        string x = "foo";
        x += "bar";
        System.Console.WriteLine(x);
    }
}


Go: s := "foo"
s += "bar"
Task: String append



C#: class Program
{
    static void Main(string[] args)
    {
        string x = "foo";
        x += "bar";
        System.Console.WriteLine(x);
    }
}






VB: Function StringAppend()
Dim s As String
s = "foo"
s = s & "bar"
Debug.Print s
End Function
Task: String append




Go: s := "foo"
s += "bar"


Java: String sa = "Hello";
sa += ", World!";
System.out.println(sa);

StringBuilder ba = new StringBuilder();
ba.append("Hello");
ba.append(", World!");
System.out.println(ba.toString());
Task: String append

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

int main()
{
    char str[24]="Good Morning";
    char *cstr=" to all";
    char *cstr2=" !!!";
    int x=0;
    

    if(sizeof(str)>strlen(str)+strlen(cstr)+strlen(cstr2))
            {
                
                strcat(str,cstr);

                
                x=strlen(str);
                sprintf(&str[x],"%s",cstr2);

                printf("%s\n",str);

            }
    return 0;
}




Go: s := "foo"
s += "bar"
Task: String append

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

int main()
{
    char str[24]="Good Morning";
    char *cstr=" to all";
    char *cstr2=" !!!";
    int x=0;
    

    if(sizeof(str)>strlen(str)+strlen(cstr)+strlen(cstr2))
            {
                
                strcat(str,cstr);

                
                x=strlen(str);
                sprintf(&str[x],"%s",cstr2);

                printf("%s\n",str);

            }
    return 0;
}







Python: 


str = "12345678";
str += "9!";
print(str)
Task: String append





Java: String sa = "Hello";
sa += ", World!";
System.out.println(sa);

StringBuilder ba = new StringBuilder();
ba.append("Hello");
ba.append(", World!");
System.out.println(ba.toString());




VB: Function StringAppend()
Dim s As String
s = "foo"
s = s & "bar"
Debug.Print s
End Function
Task: Damm algorithm


C++: #include <sstream>

const int TABLE[][10] = {
	{0, 3, 1, 7, 5, 9, 8, 6, 4, 2},
	{7, 0, 9, 2, 1, 5, 4, 8, 6, 3},
	{4, 2, 0, 6, 8, 7, 1, 3, 5, 9},
	{1, 7, 5, 0, 9, 8, 3, 4, 2, 6},
	{6, 1, 2, 3, 0, 4, 5, 9, 7, 8},
	{3, 6, 7, 4, 2, 0, 9, 5, 8, 1},
	{5, 8, 6, 9, 7, 2, 0, 1, 3, 4},
	{8, 9, 4, 5, 3, 6, 2, 0, 1, 7},
	{9, 4, 3, 8, 6, 1, 7, 2, 0, 5},
	{2, 5, 8, 1, 4, 3, 6, 7, 9, 0},
};

using std::string;
bool damm(string s) {
	int interim = 0;
	for (char c : s) {
		interim = TABLE[interim][c - '0'];
	}
	return interim == 0;
}

int main() {
	auto numbers = { 5724, 5727, 112946, 112949 };
	for (int num : numbers) {
		using std::stringstream;
		stringstream ss;
		ss << num;
		bool isValid = damm(ss.str());
		if (isValid) {
			printf("%6d is valid\n", num);
		} else {
			printf("%6d is invalid\n", num);
		}
	}

	return 0;
}






Python: def damm(num: int) -> bool:
    row = 0
    for digit in str(num):
        row = _matrix[row][int(digit)] 
    return row == 0

_matrix = (
    (0, 3, 1, 7, 5, 9, 8, 6, 4, 2),
    (7, 0, 9, 2, 1, 5, 4, 8, 6, 3),
    (4, 2, 0, 6, 8, 7, 1, 3, 5, 9),
    (1, 7, 5, 0, 9, 8, 3, 4, 2, 6),
    (6, 1, 2, 3, 0, 4, 5, 9, 7, 8),
    (3, 6, 7, 4, 2, 0, 9, 5, 8, 1),
    (5, 8, 6, 9, 7, 2, 0, 1, 3, 4),
    (8, 9, 4, 5, 3, 6, 2, 0, 1, 7),
    (9, 4, 3, 8, 6, 1, 7, 2, 0, 5),
    (2, 5, 8, 1, 4, 3, 6, 7, 9, 0)
)

if __name__ == '__main__':
    for test in [5724, 5727, 112946]:
        print(f'{test}\t Validates as: {damm(test)}')
Task: Lah numbers

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

uint64_t factorial(uint64_t n) {
    uint64_t res = 1;
    if (n == 0) return res;
    while (n > 0) res *= n--;
    return res;
}

uint64_t lah(uint64_t n, uint64_t k) {
    if (k == 1) return factorial(n);
    if (k == n) return 1;
    if (k > n) return 0;
    if (k < 1 || n < 1) return 0;
    return (factorial(n) * factorial(n - 1)) / (factorial(k) * factorial(k - 1)) / factorial(n - k);
}

int main() {
    int row, i;

    printf("Unsigned Lah numbers: L(n, k):\n");
    printf("n/k ");
    for (i = 0; i < 13; i++) {
        printf("%10d ", i);
    }
    printf("\n");
    for (row = 0; row < 13; row++) {
        printf("%-3d", row);
        for (i = 0; i < row + 1; i++) {
            uint64_t l = lah(row, i);
            printf("%11lld", l);
        }
        printf("\n");
    }

    return 0;
}



C#: using System;
using System.Linq;
using System.Numerics;

namespace LahNumbers {
    class Program {
        static BigInteger Factorial(BigInteger n) {
            if (n == 0) return 1;
            BigInteger res = 1;
            while (n > 0) {
                res *= n--;
            }
            return res;
        }

        static BigInteger Lah(BigInteger n, BigInteger k) {
            if (k == 1) return Factorial(n);
            if (k == n) return 1;
            if (k > n) return 0;
            if (k < 1 || n < 1) return 0;
            return (Factorial(n) * Factorial(n - 1)) / (Factorial(k) * Factorial(k - 1)) / Factorial(n - k);
        }

        static void Main() {
            Console.WriteLine("Unsigned Lah numbers: L(n, k):");
            Console.Write("n/k ");
            foreach (var i in Enumerable.Range(0, 13)) {
                Console.Write("{0,10} ", i);
            }
            Console.WriteLine();
            foreach (var row in Enumerable.Range(0, 13)) {
                Console.Write("{0,-3}", row);
                foreach (var i in Enumerable.Range(0, row + 1)) {
                    var l = Lah(row, i);
                    Console.Write("{0,11}", l);
                }
                Console.WriteLine();
            }
            Console.WriteLine("\nMaximum value from the L(100, *) row:");
            var maxVal = Enumerable.Range(0, 100).Select(a => Lah(100, a)).Max();
            Console.WriteLine(maxVal);
        }
    }
}
Task: Lah numbers

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

uint64_t factorial(uint64_t n) {
    uint64_t res = 1;
    if (n == 0) return res;
    while (n > 0) res *= n--;
    return res;
}

uint64_t lah(uint64_t n, uint64_t k) {
    if (k == 1) return factorial(n);
    if (k == n) return 1;
    if (k > n) return 0;
    if (k < 1 || n < 1) return 0;
    return (factorial(n) * factorial(n - 1)) / (factorial(k) * factorial(k - 1)) / factorial(n - k);
}

int main() {
    int row, i;

    printf("Unsigned Lah numbers: L(n, k):\n");
    printf("n/k ");
    for (i = 0; i < 13; i++) {
        printf("%10d ", i);
    }
    printf("\n");
    for (row = 0; row < 13; row++) {
        printf("%-3d", row);
        for (i = 0; i < row + 1; i++) {
            uint64_t l = lah(row, i);
            printf("%11lld", l);
        }
        printf("\n");
    }

    return 0;
}


C++: 

#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <gmpxx.h>

using integer = mpz_class;

class unsigned_lah_numbers {
public:
    integer get(int n, int k);
private:
    std::map<std::pair<int, int>, integer> cache_;
};

integer unsigned_lah_numbers::get(int n, int k) {
    if (k == n)
        return 1;
    if (k == 0 || k > n)
        return 0;
    auto p = std::make_pair(n, k);
    auto i = cache_.find(p);
    if (i != cache_.end())
        return i->second;
    integer result = (n - 1 + k) * get(n - 1, k) + get(n - 1, k - 1);
    cache_.emplace(p, result);
    return result;
}

void print_lah_numbers(unsigned_lah_numbers& uln, int n) {
    std::cout << "Unsigned Lah numbers up to L(12,12):\nn/k";
    for (int j = 1; j <= n; ++j)
        std::cout << std::setw(11) << j;
    std::cout << '\n';
    for (int i = 1; i <= n; ++i) {
        std::cout << std::setw(2) << i << ' ';
        for (int j = 1; j <= i; ++j)
            std::cout << std::setw(11) << uln.get(i, j);
        std::cout << '\n';
    }
}

int main() {
    unsigned_lah_numbers uln;
    print_lah_numbers(uln, 12);
    std::cout << "Maximum value of L(n,k) where n == 100:\n";
    integer max = 0;
    for (int k = 0; k <= 100; ++k)
        max = std::max(max, uln.get(100, k));
    std::cout << max << '\n';
    return 0;
}