#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int EXIT_SUCCESS;
int /*<<< orphan*/ assert(int);
scalar_t__ calloc(char, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fwrite(char *, int, char, int /*<<< orphan*/);
int scanf(char *, char *, ...);
int /*<<< orphan*/ stdout;
int main(int argc, char *argv[]) {
  int i, j;
  int nscan;
  signed char m, r, n;
  nscan = scanf("%hhu %hhu %hhu", &m, &r, &n);
  assert(nscan == 3);
  fwrite(&m, sizeof(signed char), 1, stdout);
  fwrite(&r, sizeof(signed char), 1, stdout);
  fwrite(&n, sizeof(signed char), 1, stdout);
  signed char *tps = (signed char *)calloc(m, sizeof(signed char));
  char *kvs = (char *)calloc((m - 1) * 3, sizeof(char));
  signed char *drps = (signed char *)calloc(m - 1, sizeof(signed char));
  for (i = 0; i < n; ++i) {
    for (j = 0; j < m - 1; ++j) {
      nscan = scanf("%hhu %"
                    "3"
                    "c %hhu",
                    tps + j, kvs + (j * 3), drps + j);
      assert(nscan == 3);
    }
    scanf("%hhu", tps + j);
    fwrite(tps, sizeof(signed char), m, stdout);
    fwrite(kvs, sizeof(char), (m - 1) * 3, stdout);
    fwrite(drps, sizeof(signed char), m - 1, stdout);
  }
  free(tps);
  free(kvs);
  free(drps);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rdi
lea    -0x1d(%rbp),%rsi
lea    -0x1e(%rbp),%rdx
lea    -0x1f(%rbp),%rcx
mov    $0x0,%al
call   1060 <scanf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    0x2e45(%rip),%rax
mov    (%rax),%ecx
lea    -0x1d(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1070 <fwrite@plt>
mov    0x2e2c(%rip),%rax
mov    (%rax),%ecx
lea    -0x1e(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1070 <fwrite@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%ecx
lea    -0x1f(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1070 <fwrite@plt>
mov    $0x1,%esi
movsbl -0x1d(%rbp),%edi
call   1040 <calloc@plt>
mov    %rax,-0x28(%rbp)
movsbl -0x1d(%rbp),%eax
sub    $0x1,%eax
imul   $0x3,%eax,%eax
mov    $0x1,%esi
movsbl %al,%edi
call   1040 <calloc@plt>
mov    %rax,-0x30(%rbp)
movsbl -0x1d(%rbp),%eax
sub    $0x1,%eax
mov    $0x1,%esi
movsbl %al,%edi
call   1040 <calloc@plt>
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
movsbl -0x1f(%rbp),%ecx
cmp    %ecx,%eax
jge    132f <main+0x1df>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
movsbl -0x1d(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    12a6 <main+0x156>
mov    -0x28(%rbp),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
mov    -0x30(%rbp),%rdx
imul   $0x3,-0x18(%rbp),%eax
cltq
add    %rax,%rdx
mov    -0x38(%rbp),%rcx
movslq -0x18(%rbp),%rax
add    %rax,%rcx
lea    0xd92(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x3,-0x1c(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1241 <main+0xf1>
mov    -0x28(%rbp),%rsi
movslq -0x18(%rbp),%rax
add    %rax,%rsi
lea    0xd60(%rip),%rdi
mov    $0x0,%al
call   1060 <scanf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1d(%rbp),%al
mov    0x2d13(%rip),%rcx
mov    (%rcx),%ecx
mov    $0x1,%esi
movsbl %al,%edx
call   1070 <fwrite@plt>
mov    -0x30(%rbp),%rdi
movsbl -0x1d(%rbp),%eax
sub    $0x1,%eax
imul   $0x3,%eax,%eax
mov    0x2cef(%rip),%rcx
mov    (%rcx),%ecx
mov    $0x1,%esi
movsbl %al,%edx
call   1070 <fwrite@plt>
mov    -0x38(%rbp),%rdi
movsbl -0x1d(%rbp),%eax
sub    $0x1,%eax
mov    0x2cce(%rip),%rcx
mov    (%rcx),%ecx
mov    $0x1,%esi
movsbl %al,%edx
call   1070 <fwrite@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    122b <main+0xdb>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    0x2c87(%rip),%rax
mov    (%rax),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe9b(%rip),%rdi
lea    0xd(%rsp),%rbx
lea    0xf(%rsp),%r15
lea    0xe(%rsp),%r14
mov    %rbx,%rsi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1060 <scanf@plt>
xor    %edi,%edi
cmp    $0x3,%eax
sete   %dil
call   1050 <assert@plt>
mov    0x2e47(%rip),%rbp
mov    0x0(%rbp),%ecx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    0x0(%rbp),%ecx
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    0x0(%rbp),%ecx
mov    %r14,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1070 <fwrite@plt>
movsbl 0xd(%rsp),%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%r15
movzbl 0xd(%rsp),%eax
lea    (%rax,%rax,2),%eax
add    $0xfd,%al
movsbl %al,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,0x10(%rsp)
mov    0xd(%rsp),%al
add    $0xff,%al
movsbl %al,%edi
mov    $0x1,%esi
call   1040 <calloc@plt>
mov    %rax,%rbx
cmpb   $0x0,0xe(%rsp)
jle    130f <main+0x1bf>
lea    0xde1(%rip),%r12
xor    %r13d,%r13d
jmp    12b9 <main+0x169>
cs nopw 0x0(%rax,%rax,1)
xor    %r14d,%r14d
mov    %r14d,%esi
add    %r15,%rsi
lea    0xdc8(%rip),%rdi
xor    %eax,%eax
call   1060 <scanf@plt>
movsbl 0xd(%rsp),%edx
mov    0x2d7d(%rip),%rbp
mov    0x0(%rbp),%ecx
mov    %r15,%rdi
mov    $0x1,%esi
call   1070 <fwrite@plt>
movzbl 0xd(%rsp),%eax
lea    (%rax,%rax,2),%eax
add    $0xfd,%al
mov    0x0(%rbp),%ecx
movsbl %al,%edx
mov    0x10(%rsp),%rdi
mov    $0x1,%esi
call   1070 <fwrite@plt>
mov    0xd(%rsp),%al
add    $0xff,%al
mov    0x0(%rbp),%ecx
movsbl %al,%edx
mov    %rbx,%rdi
mov    $0x1,%esi
call   1070 <fwrite@plt>
add    $0x1,%r13d
movsbl 0xe(%rsp),%eax
cmp    %eax,%r13d
jge    130f <main+0x1bf>
cmpb   $0x2,0xd(%rsp)
jl     1240 <main+0xf0>
mov    0x10(%rsp),%rbp
xor    %r14d,%r14d
nopl   0x0(%rax,%rax,1)
lea    (%r15,%r14,1),%rsi
lea    (%rbx,%r14,1),%rcx
mov    %r12,%rdi
mov    %rbp,%rdx
xor    %eax,%eax
call   1060 <scanf@plt>
xor    %edi,%edi
cmp    $0x3,%eax
sete   %dil
call   1050 <assert@plt>
add    $0x1,%r14
movsbq 0xd(%rsp),%rax
add    $0xffffffffffffffff,%rax
add    $0x3,%rbp
cmp    %rax,%r14
jl     12d0 <main+0x180>
jmp    1243 <main+0xf3>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2ca8(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [15 x i8] c"%hhu %hhu %hhu\00"
@stdout = global i32 0
@.str.1 = [14 x i8] c"%hhu %3c %hhu\00"
@.str.2 = [5 x i8] c"%hhu\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
%10 = alloca i8
%11 = alloca i8
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%15 = call i32 (i8*, i8*, ...) @scanf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %9, i8* %10, i8* %11)
store i32 %15, i32* %8
%16 = load i32, i32* %8
%17 = icmp eq i32 %16, 3
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i32, i32* @stdout
%21 = call i32 @fwrite(i8* %9, i32 1, i8 signext 1, i32 %20)
%22 = load i32, i32* @stdout
%23 = call i32 @fwrite(i8* %10, i32 1, i8 signext 1, i32 %22)
%24 = load i32, i32* @stdout
%25 = call i32 @fwrite(i8* %11, i32 1, i8 signext 1, i32 %24)
%26 = load i8, i8* %9
%27 = call i64 @calloc(i8 signext %26, i32 1)
%28 = inttoptr i64 %27 to i8*
store i8* %28, i8** %12
%29 = load i8, i8* %9
%30 = sext i8 %29 to i32
%31 = sub nsw i32 %30, 1
%32 = mul nsw i32 %31, 3
%33 = trunc i32 %32 to i8
%34 = call i64 @calloc(i8 signext %33, i32 1)
%35 = inttoptr i64 %34 to i8*
store i8* %35, i8** %13
%36 = load i8, i8* %9
%37 = sext i8 %36 to i32
%38 = sub nsw i32 %37, 1
%39 = trunc i32 %38 to i8
%40 = call i64 @calloc(i8 signext %39, i32 1)
%41 = inttoptr i64 %40 to i8*
store i8* %41, i8** %14
store i32 0, i32* %6
br label %42
42: ; preds = %101, %2
%43 = load i32, i32* %6
%44 = load i8, i8* %11
%45 = sext i8 %44 to i32
%46 = icmp slt i32 %43, %45
br i1 %46, label %47, label %104
47: ; preds = %42
store i32 0, i32* %7
br label %48
48: ; preds = %73, %47
%49 = load i32, i32* %7
%50 = load i8, i8* %9
%51 = sext i8 %50 to i32
%52 = sub nsw i32 %51, 1
%53 = icmp slt i32 %49, %52
br i1 %53, label %54, label %76
54: ; preds = %48
%55 = load i8*, i8** %12
%56 = load i32, i32* %7
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8, i8* %55, i64 %57
%59 = load i8*, i8** %13
%60 = load i32, i32* %7
%61 = mul nsw i32 %60, 3
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %59, i64 %62
%64 = load i8*, i8** %14
%65 = load i32, i32* %7
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8, i8* %64, i64 %66
%68 = call i32 (i8*, i8*, ...) @scanf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %58, i8* %63, i8* %67)
store i32 %68, i32* %8
%69 = load i32, i32* %8
%70 = icmp eq i32 %69, 3
%71 = zext i1 %70 to i32
%72 = call i32 @assert(i32 %71)
br label %73
73: ; preds = %54
%74 = load i32, i32* %7
%75 = add nsw i32 %74, 1
store i32 %75, i32* %7
br label %48
76: ; preds = %48
%77 = load i8*, i8** %12
%78 = load i32, i32* %7
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8, i8* %77, i64 %79
%81 = call i32 (i8*, i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %80)
%82 = load i8*, i8** %12
%83 = load i8, i8* %9
%84 = load i32, i32* @stdout
%85 = call i32 @fwrite(i8* %82, i32 1, i8 signext %83, i32 %84)
%86 = load i8*, i8** %13
%87 = load i8, i8* %9
%88 = sext i8 %87 to i32
%89 = sub nsw i32 %88, 1
%90 = mul nsw i32 %89, 3
%91 = trunc i32 %90 to i8
%92 = load i32, i32* @stdout
%93 = call i32 @fwrite(i8* %86, i32 1, i8 signext %91, i32 %92)
%94 = load i8*, i8** %14
%95 = load i8, i8* %9
%96 = sext i8 %95 to i32
%97 = sub nsw i32 %96, 1
%98 = trunc i32 %97 to i8
%99 = load i32, i32* @stdout
%100 = call i32 @fwrite(i8* %94, i32 1, i8 signext %98, i32 %99)
br label %101
101: ; preds = %76
%102 = load i32, i32* %6
%103 = add nsw i32 %102, 1
store i32 %103, i32* %6
br label %42
104: ; preds = %42
%105 = load i8*, i8** %12
%106 = call i32 @free(i8* %105)
%107 = load i8*, i8** %13
%108 = call i32 @free(i8* %107)
%109 = load i8*, i8** %14
%110 = call i32 @free(i8* %109)
%111 = load i32, i32* @EXIT_SUCCESS
ret i32 %111
}

LLVM IR (-O2):
@.str = [15 x i8] c"%hhu %hhu %hhu\00"
@stdout = global i32 0
@.str.1 = [14 x i8] c"%hhu %3c %hhu\00"
@.str.2 = [5 x i8] c"%hhu\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i8
%4 = alloca i8
%5 = alloca i8
%6 = call i32 (i8*, i8*, ...) @scanf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %3, i8* %4, i8* %5)
%7 = icmp eq i32 %6, 3
%8 = zext i1 %7 to i32
%9 = call i32 @assert(i32 %8)
%10 = load i32, i32* @stdout
%11 = call i32 @fwrite(i8* %3, i32 1, i8 signext 1, i32 %10)
%12 = load i32, i32* @stdout
%13 = call i32 @fwrite(i8* %4, i32 1, i8 signext 1, i32 %12)
%14 = load i32, i32* @stdout
%15 = call i32 @fwrite(i8* %5, i32 1, i8 signext 1, i32 %14)
%16 = load i8, i8* %3
%17 = call i64 @calloc(i8 signext %16, i32 1)
%18 = inttoptr i64 %17 to i8*
%19 = load i8, i8* %3
%20 = mul i8 %19, 3
%21 = add i8 %20, -3
%22 = call i64 @calloc(i8 signext %21, i32 1)
%23 = inttoptr i64 %22 to i8*
%24 = load i8, i8* %3
%25 = add i8 %24, -1
%26 = call i64 @calloc(i8 signext %25, i32 1)
%27 = inttoptr i64 %26 to i8*
%28 = load i8, i8* %5
%29 = icmp sgt i8 %28, 0
br i1 %29, label %30, label %70
30: ; preds = %2, %49
%31 = phi i32 [ %66, %49 ], [ 0, %2 ]
%32 = load i8, i8* %3
%33 = icmp sgt i8 %32, 1
br i1 %33, label %34, label %49
34: ; preds = %30, %34
%35 = phi i64 [ %44, %34 ], [ 0, %30 ]
%36 = getelementptr inbounds i8, i8* %18, i64 %35
%37 = mul nuw nsw i64 %35, 3
%38 = getelementptr inbounds i8, i8* %23, i64 %37
%39 = getelementptr inbounds i8, i8* %27, i64 %35
%40 = call i32 (i8*, i8*, ...) @scanf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %36, i8* %38, i8* %39)
%41 = icmp eq i32 %40, 3
%42 = zext i1 %41 to i32
%43 = call i32 @assert(i32 %42)
%44 = add nuw nsw i64 %35, 1
%45 = load i8, i8* %3
%46 = sext i8 %45 to i64
%47 = add nsw i64 %46, -1
%48 = icmp slt i64 %44, %47
br i1 %48, label %34, label %49
49: ; preds = %34, %30
%50 = phi i64 [ 0, %30 ], [ %44, %34 ]
%51 = and i64 %50, 4294967295
%52 = getelementptr inbounds i8, i8* %18, i64 %51
%53 = call i32 (i8*, i8*, ...) @scanf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %52)
%54 = load i8, i8* %3
%55 = load i32, i32* @stdout
%56 = call i32 @fwrite(i8* %18, i32 1, i8 signext %54, i32 %55)
%57 = load i8, i8* %3
%58 = mul i8 %57, 3
%59 = add i8 %58, -3
%60 = load i32, i32* @stdout
%61 = call i32 @fwrite(i8* %23, i32 1, i8 signext %59, i32 %60)
%62 = load i8, i8* %3
%63 = add i8 %62, -1
%64 = load i32, i32* @stdout
%65 = call i32 @fwrite(i8* %27, i32 1, i8 signext %63, i32 %64)
%66 = add nuw nsw i32 %31, 1
%67 = load i8, i8* %5
%68 = sext i8 %67 to i32
%69 = icmp slt i32 %66, %68
br i1 %69, label %30, label %70
70: ; preds = %49, %2
%71 = call i32 @free(i8* %18)
%72 = call i32 @free(i8* %23)
%73 = call i32 @free(i8* %27)
%74 = load i32, i32* @EXIT_SUCCESS
ret i32 %74
}