#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 n;
  int E = 100;
  int k;
  scanf("%d %d", &n, &k);
  int *c = malloc(sizeof(int) * n);
  for (int c_i = 0; c_i < n; c_i++) {
    scanf("%d", &c[c_i]);
  }
  int i = 1;
  while (i != 0) {
    static int j = 0;
    j = (j + k) % n;
    if (c[j] == 0)
      E -= 1;
    else
      E -= 3;
    i = j;
  }
  printf("%d", E);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x64,-0xc(%rbp)
lea    0xeb3(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1050 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x2,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11ad <main+0x7d>
mov    -0x18(%rbp),%rsi
movslq -0x1c(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1176 <main+0x46>
movl   $0x1,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     120b <main+0xdb>
mov    0x2e78(%rip),%eax
add    -0x10(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %edx,0x2e6b(%rip)
mov    -0x18(%rbp),%rax
movslq 0x2e60(%rip),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jne    11f4 <main+0xc4>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11fd <main+0xcd>
mov    -0xc(%rbp),%eax
sub    $0x3,%eax
mov    %eax,-0xc(%rbp)
mov    0x2e39(%rip),%eax
mov    %eax,-0x20(%rbp)
jmp    11b4 <main+0x84>
mov    -0xc(%rbp),%esi
lea    0xdee(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%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    %ebx,%ebx
mov    %rsp,%rsi
lea    0x4(%rsp),%rdx
xor    %eax,%eax
call   1050 <scanf@plt>
mov    (%rsp),%r13d
lea    0x0(,%r13,4),%edi
call   1040 <malloc@plt>
mov    %rax,%r14
test   %r13d,%r13d
jle    119e <main+0x6e>
lea    0xe90(%rip),%r15
mov    %r14,%r12
xor    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
add    $0x1,%rbp
movslq (%rsp),%r13
add    $0x4,%r12
cmp    %r13,%rbp
jl     1180 <main+0x50>
mov    $0x64,%esi
mov    0x4(%rsp),%ecx
nopw   0x0(%rax,%rax,1)
add    %ecx,%ebx
mov    %ebx,%eax
cltd
idiv   %r13d
mov    %edx,%ebx
movslq %edx,%rax
cmpl   $0x1,(%r14,%rax,4)
sbb    %edx,%edx
or     $0xfffffffd,%edx
add    %edx,%esi
test   %eax,%eax
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"
@main.j = internal global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i32 100, i32* %3
%8 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %4)
%9 = load i32, i32* %2
%10 = sext i32 %9 to i64
%11 = mul i64 4, %10
%12 = trunc i64 %11 to i32
%13 = call i32* @malloc(i32 %12)
store i32* %13, i32** %5
store i32 0, i32* %6
br label %14
14: ; preds = %24, %0
%15 = load i32, i32* %6
%16 = load i32, i32* %2
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %27
18: ; preds = %14
%19 = load i32*, i32** %5
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = call i32 (i8*, i32*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %22)
br label %24
24: ; preds = %18
%25 = load i32, i32* %6
%26 = add nsw i32 %25, 1
store i32 %26, i32* %6
br label %14
27: ; preds = %14
store i32 1, i32* %7
br label %28
28: ; preds = %49, %27
%29 = load i32, i32* %7
%30 = icmp ne i32 %29, 0
br i1 %30, label %31, label %51
31: ; preds = %28
%32 = load i32, i32* @main.j
%33 = load i32, i32* %4
%34 = add nsw i32 %32, %33
%35 = load i32, i32* %2
%36 = srem i32 %34, %35
store i32 %36, i32* @main.j
%37 = load i32*, i32** %5
%38 = load i32, i32* @main.j
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
%41 = load i32, i32* %40
%42 = icmp eq i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %31
%44 = load i32, i32* %3
%45 = sub nsw i32 %44, 1
store i32 %45, i32* %3
br label %49
46: ; preds = %31
%47 = load i32, i32* %3
%48 = sub nsw i32 %47, 3
store i32 %48, i32* %3
br label %49
49: ; preds = %46, %43
%50 = load i32, i32* @main.j
store i32 %50, i32* %7
br label %28
51: ; preds = %28
%52 = load i32, i32* %3
%53 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %52)
ret i32 0
}

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