#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 */
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, ...);
int main() {
  int n;
  int i;
  int stepup = 0;
  int valley = 0;
  scanf("%d", &n);
  char *steps = (char *)malloc(sizeof(char) * n);
  scanf("%s", steps);
  for (i = 0; steps[i] != '\0'; i++) {
    if (steps[i] == 'U')
      stepup++;
    else {
      if (stepup == 0) {
        valley++;
        stepup--;
      } else
        stepup--;
    }
  }
  printf("%d", valley);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xeac(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1050 <scanf@plt>
movslq -0x8(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1050 <scanf@plt>
movl   $0x0,-0xc(%rbp)
mov    -0x20(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1205 <main+0xd5>
mov    -0x20(%rbp),%rax
movslq -0xc(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x55,%eax
jne    11c3 <main+0x93>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    11f2 <main+0xc2>
cmpl   $0x0,-0x10(%rbp)
jne    11e4 <main+0xb4>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    11ed <main+0xbd>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    11f2 <main+0xc2>
jmp    11f7 <main+0xc7>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    118b <main+0x5b>
mov    -0x14(%rbp),%esi
lea    0xdf1(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xec6(%rip),%rdi
xor    %ebp,%ebp
lea    0x4(%rsp),%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
mov    0x4(%rsp),%edi
call   1040 <malloc@plt>
mov    %rax,%rbx
lea    0xea8(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <scanf@plt>
xor    %esi,%esi
jmp    1177 <main+0x47>
nopl   0x0(%rax)
add    $0x1,%ebp
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x55,%al
je     1170 <main+0x40>
test   %al,%al
je     119d <main+0x6d>
test   %ebp,%ebp
je     118f <main+0x5f>
add    $0xffffffff,%ebp
add    $0x1,%rbx
jmp    1177 <main+0x47>
add    $0x1,%esi
mov    $0xffffffff,%ebp
add    $0x1,%rbx
jmp    1177 <main+0x47>
lea    0xe5c(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [3 x i8] c"%s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
store i32 0, i32* %1
store i32 0, i32* %4
store i32 0, i32* %5
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%8 = load i32, i32* %2
%9 = sext i32 %8 to i64
%10 = mul i64 1, %9
%11 = trunc i64 %10 to i32
%12 = call i64 @malloc(i32 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %6
%14 = load i8*, i8** %6
%15 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %14)
store i32 0, i32* %3
br label %16
16: ; preds = %48, %0
%17 = load i8*, i8** %6
%18 = load i32, i32* %3
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %17, i64 %19
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %51
24: ; preds = %16
%25 = load i8*, i8** %6
%26 = load i32, i32* %3
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 85
br i1 %31, label %32, label %35
32: ; preds = %24
%33 = load i32, i32* %4
%34 = add nsw i32 %33, 1
store i32 %34, i32* %4
br label %47
35: ; preds = %24
%36 = load i32, i32* %4
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %35
%39 = load i32, i32* %5
%40 = add nsw i32 %39, 1
store i32 %40, i32* %5
%41 = load i32, i32* %4
%42 = add nsw i32 %41, -1
store i32 %42, i32* %4
br label %46
43: ; preds = %35
%44 = load i32, i32* %4
%45 = add nsw i32 %44, -1
store i32 %45, i32* %4
br label %46
46: ; preds = %43, %38
br label %47
47: ; preds = %46, %32
br label %48
48: ; preds = %47
%49 = load i32, i32* %3
%50 = add nsw i32 %49, 1
store i32 %50, i32* %3
br label %16
51: ; preds = %16
%52 = load i32, i32* %5
%53 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %52)
ret i32 0
}

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