#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() {
  int n, l = 0, cnt = 0, e = 0;
  scanf("%d", &n);
  char i;
  for (; n > 0; n--) {
    scanf(" %c", &i);
    if (i == 'U')
      l++;
    else
      l--;
    if (l < 0 && e == 0) {
      cnt++;
      e = 1;
    }
    if (l >= 0 && e == 1)
      e = 0;
  }
  printf("%d", cnt);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    0xeb5(%rip),%rdi
lea    -0x8(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
cmpl   $0x0,-0x8(%rbp)
jle    11e8 <main+0xc8>
lea    0xe9c(%rip),%rdi
lea    -0x15(%rbp),%rsi
mov    $0x0,%al
call   1040 <scanf@plt>
movsbl -0x15(%rbp),%eax
cmp    $0x55,%eax
jne    118d <main+0x6d>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1196 <main+0x76>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    11ba <main+0x9a>
cmpl   $0x0,-0x14(%rbp)
jne    11ba <main+0x9a>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
movl   $0x1,-0x14(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     11d5 <main+0xb5>
cmpl   $0x1,-0x14(%rbp)
jne    11d5 <main+0xb5>
movl   $0x0,-0x14(%rbp)
jmp    11da <main+0xba>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
jmp    1156 <main+0x36>
mov    -0x10(%rbp),%esi
lea    0xe0e(%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   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xecd(%rip),%rdi
xor    %r12d,%r12d
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
cmpl   $0x0,0xc(%rsp)
jle    11be <main+0x9e>
lea    0xeb3(%rip),%r14
lea    0xb(%rsp),%r15
xor    %ebp,%ebp
xor    %r12d,%r12d
xor    %ebx,%ebx
jmp    117e <main+0x5e>
xchg   %ax,%ax
add    $0xffffffff,%ebx
movzbl %cl,%ecx
cmovns %edx,%eax
add    %ecx,%r12d
mov    0xc(%rsp),%ecx
lea    -0x1(%rcx),%edx
mov    %edx,0xc(%rsp)
mov    %eax,%ebp
cmp    $0x1,%ecx
jle    11be <main+0x9e>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <scanf@plt>
xor    %eax,%eax
cmpb   $0x55,0xb(%rsp)
sete   %al
lea    (%rbx,%rax,2),%ebx
mov    %ebx,%eax
add    $0xffffffff,%eax
sets   %dl
test   %ebp,%ebp
sete   %cl
mov    $0x1,%eax
and    %dl,%cl
jne    11b0 <main+0x90>
mov    %ebp,%eax
mov    $0x0,%edx
cmp    $0x1,%eax
je     1160 <main+0x40>
mov    %eax,%edx
jmp    1160 <main+0x40>
lea    0xe3b(%rip),%rdi
mov    %r12d,%esi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c" %c\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* %3
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)
br label %8
8: ; preds = %39, %0
%9 = load i32, i32* %2
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %42
11: ; preds = %8
%12 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%13 = load i8, i8* %6
%14 = sext i8 %13 to i32
%15 = icmp eq i32 %14, 85
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %22
19: ; preds = %11
%20 = load i32, i32* %3
%21 = add nsw i32 %20, -1
store i32 %21, i32* %3
br label %22
22: ; preds = %19, %16
%23 = load i32, i32* %3
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = load i32, i32* %5
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
store i32 1, i32* %5
br label %31
31: ; preds = %28, %25, %22
%32 = load i32, i32* %3
%33 = icmp sge i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %31
%35 = load i32, i32* %5
%36 = icmp eq i32 %35, 1
br i1 %36, label %37, label %38
37: ; preds = %34
store i32 0, i32* %5
br label %38
38: ; preds = %37, %34, %31
br label %39
39: ; preds = %38
%40 = load i32, i32* %2
%41 = add nsw i32 %40, -1
store i32 %41, i32* %2
br label %8
42: ; preds = %8
%43 = load i32, i32* %4
%44 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %43)
ret i32 0
}

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