#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 *malloc(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *, ...);
int main(int argc, char const *argv[]) {
  int n, k;
  scanf("%d %d", &n, &k);
  int *c = malloc(sizeof(int) * n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &c[i]);
  }
  int e = 100;
  int pos = 0;
  int turn = 0;
  while (pos != 0 || turn == 0) {
    if (c[pos] == 1)
      e -= 3;
    else
      e -= 1;
    pos = (pos + k) % n;
    turn++;
  }
  printf("%d\n", e);
  return 0;
}


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    0xeb3(%rip),%rdi
lea    -0x14(%rbp),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1050 <scanf@plt>
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11ad <main+0x7d>
mov    -0x20(%rbp),%rsi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1176 <main+0x46>
movl   $0x64,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
mov    $0x1,%al
cmpl   $0x0,-0x2c(%rbp)
mov    %al,-0x31(%rbp)
jne    11db <main+0xab>
cmpl   $0x0,-0x30(%rbp)
sete   %al
mov    %al,-0x31(%rbp)
mov    -0x31(%rbp),%al
test   $0x1,%al
jne    11eb <main+0xbb>
jmp    122f <main+0xff>
mov    -0x20(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cmpl   $0x1,(%rax,%rcx,4)
jne    120b <main+0xdb>
mov    -0x28(%rbp),%eax
sub    $0x3,%eax
mov    %eax,-0x28(%rbp)
jmp    1214 <main+0xe4>
mov    -0x28(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    -0x18(%rbp),%eax
cltd
idivl  -0x14(%rbp)
mov    %edx,-0x2c(%rbp)
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11c2 <main+0x92>
mov    -0x28(%rbp),%esi
lea    0xdcd(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xebe(%rip),%rdi
xor    %r13d,%r13d
mov    %rsp,%rsi
lea    0x4(%rsp),%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
mov    (%rsp),%r12d
lea    0x0(,%r12,4),%edi
call   1040 <malloc@plt>
mov    %rax,%r14
test   %r12d,%r12d
jle    119e <main+0x6e>
lea    0xe8f(%rip),%r15
mov    %r14,%rbx
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
add    $0x1,%rbp
movslq (%rsp),%r12
add    $0x4,%rbx
cmp    %r12,%rbp
jl     1180 <main+0x50>
mov    $0x64,%esi
mov    0x4(%rsp),%ecx
nopw   0x0(%rax,%rax,1)
movslq %r13d,%rax
xor    %edx,%edx
cmpl   $0x1,(%r14,%rax,4)
setne  %dl
lea    (%rsi,%rdx,2),%esi
add    $0xfffffffd,%esi
add    %ecx,%eax
cltd
idiv   %r12d
mov    %edx,%r13d
test   %edx,%edx
jne    11b0 <main+0x80>
lea    0xe2f(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
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 i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %6, i32* %7)
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = mul i64 4, %15
%17 = trunc i64 %16 to i32
%18 = call i32* @malloc(i32 %17)
store i32* %18, i32** %8
store i32 0, i32* %9
br label %19
19: ; preds = %29, %2
%20 = load i32, i32* %9
%21 = load i32, i32* %6
%22 = icmp slt i32 %20, %21
br i1 %22, label %23, label %32
23: ; preds = %19
%24 = load i32*, i32** %8
%25 = load i32, i32* %9
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %27)
br label %29
29: ; preds = %23
%30 = load i32, i32* %9
%31 = add nsw i32 %30, 1
store i32 %31, i32* %9
br label %19
32: ; preds = %19
store i32 100, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
br label %33
33: ; preds = %54, %32
%34 = load i32, i32* %11
%35 = icmp ne i32 %34, 0
br i1 %35, label %39, label %36
36: ; preds = %33
%37 = load i32, i32* %12
%38 = icmp eq i32 %37, 0
br label %39
39: ; preds = %36, %33
%40 = phi i1 [ true, %33 ], [ %38, %36 ]
br i1 %40, label %41, label %62
41: ; preds = %39
%42 = load i32*, i32** %8
%43 = load i32, i32* %11
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds i32, i32* %42, i64 %44
%46 = load i32, i32* %45
%47 = icmp eq i32 %46, 1
br i1 %47, label %48, label %51
48: ; preds = %41
%49 = load i32, i32* %10
%50 = sub nsw i32 %49, 3
store i32 %50, i32* %10
br label %54
51: ; preds = %41
%52 = load i32, i32* %10
%53 = sub nsw i32 %52, 1
store i32 %53, i32* %10
br label %54
54: ; preds = %51, %48
%55 = load i32, i32* %11
%56 = load i32, i32* %7
%57 = add nsw i32 %55, %56
%58 = load i32, i32* %6
%59 = srem i32 %57, %58
store i32 %59, i32* %11
%60 = load i32, i32* %12
%61 = add nsw i32 %60, 1
store i32 %61, i32* %12
br label %33
62: ; preds = %39
%63 = load i32, i32* %10
%64 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %63)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"%d %d\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %3, i32* %4)
%8 = load i32, i32* %3
%9 = shl i32 %8, 2
%10 = call i32* @malloc(i32 %9)
%11 = icmp sgt i32 %8, 0
br i1 %11, label %15, label %12
12: ; preds = %15, %2
%13 = phi i32 [ %8, %2 ], [ %20, %15 ]
%14 = load i32, i32* %4
br label %23
15: ; preds = %2, %15
%16 = phi i64 [ %19, %15 ], [ 0, %2 ]
%17 = getelementptr inbounds i32, i32* %10, i64 %16
%18 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %17)
%19 = add nuw nsw i64 %16, 1
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = icmp slt i64 %19, %21
br i1 %22, label %15, label %12
23: ; preds = %12, %23
%24 = phi i32 [ 0, %12 ], [ %33, %23 ]
%25 = phi i32 [ 100, %12 ], [ %31, %23 ]
%26 = sext i32 %24 to i64
%27 = getelementptr inbounds i32, i32* %10, i64 %26
%28 = load i32, i32* %27
%29 = icmp eq i32 %28, 1
%30 = select i1 %29, i32 -3, i32 -1
%31 = add nsw i32 %30, %25
%32 = add nsw i32 %14, %24
%33 = srem i32 %32, %13
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %23
35: ; preds = %23
%36 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %31)
ret i32 0
}