#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 /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, ...);
int main(void) {
  int m, t, u, f, d, sum, i;
  scanf("%d %d %d %d %d", &m, &t, &u, &f, &d);
  u += d;
  f *= 2;
  char this;
  for (i = 0; i < t; i++) {
    scanf("%c", &this);
    this = (this == 'f') ? f : u;
    if ((sum += this) > m) {
      i++;
      break;
    }
  }
  printf("%d\n", i);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
lea    -0x8(%rbp),%rsi
lea    -0xc(%rbp),%rdx
lea    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%r8
lea    -0x18(%rbp),%r9
mov    $0x0,%al
call   1040 <scanf@plt>
mov    -0x18(%rbp),%eax
add    -0x10(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11e0 <main+0xc0>
lea    0xe92(%rip),%rdi
lea    -0x21(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movsbl -0x21(%rbp),%eax
cmp    $0x66,%eax
jne    11a0 <main+0x80>
mov    -0x14(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    11a6 <main+0x86>
mov    -0x10(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%eax
mov    %al,-0x21(%rbp)
movsbl -0x21(%rbp),%eax
add    -0x1c(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmp    -0x8(%rbp),%eax
jle    11cd <main+0xad>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11e0 <main+0xc0>
jmp    11d2 <main+0xb2>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    116a <main+0x4a>
mov    -0x20(%rbp),%esi
lea    0xe28(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%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    0xecb(%rip),%rdi
xor    %ebx,%ebx
lea    0x14(%rsp),%rsi
lea    0x4(%rsp),%rdx
lea    0x10(%rsp),%r14
lea    0xc(%rsp),%r15
lea    0x8(%rsp),%r9
mov    %r14,%rcx
mov    %r15,%r8
xor    %eax,%eax
call   1040 <scanf@plt>
mov    0x8(%rsp),%eax
add    %eax,0x10(%rsp)
shll   0xc(%rsp)
cmpl   $0x0,0x4(%rsp)
jle    11b5 <main+0x95>
lea    0xe98(%rip),%r12
lea    0x3(%rsp),%r13
xor    %ebx,%ebx
xchg   %ax,%ax
mov    %eax,%ebp
mov    %r12,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpb   $0x66,0x3(%rsp)
mov    %r14,%rax
cmove  %r15,%rax
mov    (%rax),%eax
mov    %al,0x3(%rsp)
movsbl %al,%eax
add    %ebp,%eax
add    $0x1,%ebx
cmp    0x14(%rsp),%eax
jg     11b5 <main+0x95>
cmp    0x4(%rsp),%ebx
jl     1180 <main+0x60>
lea    0xe56(%rip),%rdi
mov    %ebx,%esi
call   1030 <printf@plt>
xor    %eax,%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"%d %d %d %d %d\00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8
store i32 0, i32* %1
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32* %2, i32* %3, i32* %4, i32* %5, i32* %6)
%11 = load i32, i32* %6
%12 = load i32, i32* %4
%13 = add nsw i32 %12, %11
store i32 %13, i32* %4
%14 = load i32, i32* %5
%15 = mul nsw i32 %14, 2
store i32 %15, i32* %5
store i32 0, i32* %8
br label %16
16: ; preds = %42, %0
%17 = load i32, i32* %8
%18 = load i32, i32* %3
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %45
20: ; preds = %16
%21 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%22 = load i8, i8* %9
%23 = sext i8 %22 to i32
%24 = icmp eq i32 %23, 102
br i1 %24, label %25, label %27
25: ; preds = %20
%26 = load i32, i32* %5
br label %29
27: ; preds = %20
%28 = load i32, i32* %4
br label %29
29: ; preds = %27, %25
%30 = phi i32 [ %26, %25 ], [ %28, %27 ]
%31 = trunc i32 %30 to i8
store i8 %31, i8* %9
%32 = load i8, i8* %9
%33 = sext i8 %32 to i32
%34 = load i32, i32* %7
%35 = add nsw i32 %34, %33
store i32 %35, i32* %7
%36 = load i32, i32* %2
%37 = icmp sgt i32 %35, %36
br i1 %37, label %38, label %41
38: ; preds = %29
%39 = load i32, i32* %8
%40 = add nsw i32 %39, 1
store i32 %40, i32* %8
br label %45
41: ; preds = %29
br label %42
42: ; preds = %41
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %16
45: ; preds = %38, %16
%46 = load i32, i32* %8
%47 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %46)
ret i32 0
}

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