Problem:


Score : 300 points

Problem Statement

Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa.

In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is B, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is W, it means that the color of the corresponding stone is white.

Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.

Constraints

1 ≦ |S| ≦ 10^5

Each character in S is B or W.

Input

The input is given from Standard Input in the following format:

S

Output

Print the minimum number of new stones that Jiro needs to place for his purpose.

Sample Input 1

BBBWW

Sample Output 1

1

By placing a new black stone to the right end of the row of stones, all white stones will become black. Also, by placing a new white stone to the left end of the row of stones, all black stones will become white.

In either way, Jiro's purpose can be achieved by placing one stone.

Sample Input 2

WWWWWW

Sample Output 2

0

If all stones are already of the same color, no new stone is necessary.

Sample Input 3

WBWBWBWBWB

Sample Output 3

9



Sample input:
BBBWW


Sample output:
1

Submission status: Accepted

Solution code:
s=input()
def f(s):
    a=s[0]
    N=len(s)
    ans=0
    for i in range(1,N):
        if a!=s[i]:
            ans+=1
            a=s[i]
    return ans
print(min(f(s),f(s[::-1])))

Submission status: Accepted

Solution code:
S = input()
ret = 0
for i in range(len(S) - 1):
    if S[i] != S[i + 1]:
        ret += 1
print(ret)

Submission status: Accepted

Solution code:
S = list(input())

c = 0

x = S[0]
for i in range(len(S) - 1):
	if x != S[i + 1]:
		c += 1
	x = S[i + 1]

print(c)

Submission status: Accepted

Solution code:
Ss = input()

ans = 0
prevS = Ss[0]
for S in Ss[1:]:
    if S != prevS:
        ans += 1
        prevS = S

print(ans)

Submission status: Accepted

Solution code:
S=input();
DifF=0;
First=S[0];
len=len(S)
End=S[len-1];
for i in range(len-1):
    if S[i]!=S[i+1]:
        DifF+=1;
print(DifF);

Submission status: Accepted

Solution code:
s = input()
ans = 0
for t,u in zip(s[:-1],s[1:]):
    if t != u:
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
s = str(input())
cou = 0
for i in range(len(s)-1):
  if s[i+1] != s[i]:
    cou += 1
print(cou)

Submission status: Accepted

Solution code:
S = input()

kugiri = 0
compare = S[0]

for i in range(1,len(S)):
    if compare == S[i]:
        continue
    else:
        compare = S[i]
        kugiri += 1

print(kugiri)

Submission status: Accepted

Solution code:
s = list(input())
a = 0
for i in range(len(s)-1):
    if s[i]!=s[i+1]:
        a += 1
print(a)

Submission status: Accepted

Solution code:
S = input()
ans = 0

lastColor = S[0]
for i in range(1, len(S)):
    if S[i] != lastColor:
        lastColor = S[i]
        ans += 1

print(ans)

Submission status: Accepted

Solution code:
s = input()
c1, c2 = s[0], s[-1]
cnt1, cnt2 = 0, 0
for i in range(1, len(s)):
  if c1!=s[i]:
    cnt1 += 1
    c1 = s[i]
for i in range(len(s)-2, -1, -1):
  if c2!=s[i]:
    cnt2 += 1
    c2 = s[i]
print(min(cnt1, cnt2))

Submission status: Accepted

Solution code:
ret = 0
s = raw_input()
for i in xrange(len(s)-1):
	if s[i] != s[i+1]:
		ret += 1
print ret

Submission status: Accepted

Solution code:
s=input()
cnt=0
for i in range(1,len(s)):
  if s[i-1]!=s[i]:
    cnt+=1
print(cnt)

Submission status: Accepted

Solution code:
n = input()
count = 0
now = n[0]
for i in n:
    if i != now:
        count += 1
        now = i
print(count)

Submission status: Accepted

Solution code:
s = input()
r = 0
for i in range(len(s)):
    if i == 0: continue
    else:
        if s[i] != s[i-1]:
            r += 1
print(r)

Submission status: Accepted

Solution code:
s = list(input())
ans = 0
for i in range(len(s) - 1):
	if s[i] != s[i + 1]:
		ans += 1

print(ans)

Submission status: Accepted

Solution code:
S = input()

back = S[0]
ans = 0
for s in S[1:]:
    if back != s:
        ans += 1
    back = s
    
print(ans)

Submission status: Accepted

Solution code:
S = input()
henka = 0
for i in range(len(S)-1):
    if S[i] != S[i+1]:
        henka += 1
print(henka)

Submission status: Accepted

Solution code:
s=input();print(s.count('BW')+s.count('WB'))

Submission status: Accepted

Solution code:
s=input()
ans = 0
for i in range(len(s)-1):
 if s[i]!=s[i+1]:
  ans += 1
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
S = input()
print(S.count("BW") + S.count("WB"))

Submission status: Accepted

Solution code:
s=input()
total=0
for i in range(len(s)-1):
    if s[i+1]!=s[i]: total+=1
print(total)

Submission status: Accepted

Solution code:
s=list(input())
count=0
for i in range(len(s)-1):
    if s[i]=="W":
        if s[i+1]!="W":
            count+=1
    if s[i]=="B":
        if s[i+1]!="B":
            count+=1
print(count)

Submission status: Accepted

Solution code:
print((lambda s:s.count('WB')+s.count('BW'))(input()))

Submission status: Accepted

Solution code:
s=input()
print(s.count('WB')+s.count('BW'))

Submission status: Accepted

Solution code:
s=input()
c=s[0]
ans=0
for cn in s:
    if cn!=c:
        c=cn
        ans+=1
print(ans)

Submission status: Accepted

Solution code:
s = raw_input()
cnt = 0
for i in range(len(s) - 1):
  if s[i] != s[i + 1]:
    cnt += 1

print cnt

Submission status: Accepted

Solution code:
S=input()
n=len(S)
ans=0
for i in range(n-1):
  if S[i]!=S[i+1]: ans+=1
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import itertools

def main():
    S = input()

    groups = itertools.groupby(S)
    ans = sum(1 for _ in groups) - 1
    print(ans)

if __name__ == "__main__": main()

Submission status: Accepted

Solution code:
s = input()
ret = 0
for i in range(len(s)-1):
    ret += s[i] != s[i+1]
print(ret)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math
import sys
import itertools
import numpy as np
import functools
import collections
mo = 1000000007
r = range

s = input()
ret = 0
for i in range(len(s)-1):
    ret += s[i] != s[i+1]
print(ret)

Submission status: Accepted

Solution code:
s=raw_input()
ans=0
for i in xrange(len(s)-1):
    if s[i]!=s[i+1]:
        ans+=1
print ans

Submission status: Accepted

Solution code:
s=raw_input()
now=s[0]
ans=0
for i in xrange(1,len(s)):
    if now!=s[i]:
        ans+=1
        now=s[i]
print ans

Submission status: Accepted

Solution code:
S = raw_input()
T = S[0]
for s in S[1:]:
    if T[-1] == s: continue
    T += s
print len(T) - 1

Submission status: Accepted

Solution code:
S = raw_input().strip()

count = -1
lastChar = ""
for char in S:
    if(char != lastChar):
        count += 1
        lastChar = char

print count

Submission status: Accepted

Solution code:
s=input()
print(s.count("WB")+s.count("BW"))

Submission status: Accepted

Solution code:
#C    一次元リバーシ / 1D Reversi
list = list(input())
result = 0
 
for i in range(len(list)-1):
    if list[i]!=list[i+1]:
        result+=1
 
print(result)

Submission status: Accepted

Solution code:
s = input()

a = 0
for i in range(1, len(s)):
    if s[i - 1] != s[i]:
        a += 1

print(a)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys

s = sys.stdin.readline()
w = len([i for i in s.split('B') if i != '' and i != '\n'])
b = len([i for i in s.split('W') if i != '' and i != '\n'])
print(w + b - 1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

# 文字列の入力
s = raw_input()
cnt = 0
last_word = s[0]
for i in range(len(s)):
  if s[i] != last_word:
    cnt += 1
    last_word = s[i]
# 出力
print cnt

Submission status: Accepted

Solution code:
s = raw_input()

ans = 0
c = s[0]

for i in range(1,len(s)):
    if c!=s[i]:
        ans += 1
        c = s[i]

print(ans)

Submission status: Accepted

Solution code:
s = list(input())

cnt = 0
for i in range(len(s) - 1):
    if s[i] != s[i + 1]:
        cnt += 1

print(cnt)

Submission status: Accepted

Solution code:
s = input()
prev = s[0]
ans = 0

for c in s:
    if c != prev:
        ans += 1
        prev = c
print(ans)

Submission status: Accepted

Solution code:
input_lines = input()
S = list(input_lines)

def my_func(S):
    current = S[0]
    nodes = 0
    for item in S[1:]:
        if current != item:
            current = item
            nodes += 1
    print(nodes)

my_func(S)

Submission status: Accepted

Solution code:

s = raw_input()
cnt = 0
last = s[0]
 
for c in s[1:]:
    if c != last:
        cnt = cnt+1
    last = c
print cnt

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 文字列の入力
s = input()
a=0;b=0;
a=s.count("WB")
b=s.count("BW")

print(a+b)

Submission status: Accepted

Solution code:
inp = raw_input().strip()
print len( [ i for i in range( len(inp)-1 ) if inp[i] != inp[i+1] ] )

Submission status: Accepted

Solution code:
from itertools import groupby
print(sum(1 for _ in groupby(input())) - 1)

Submission status: Accepted

Solution code:
a=raw_input()
ary=list(a)
count = 0

tmp=ary[0]
for i,v in enumerate(ary):
  if v == tmp:
    tmp=v
  else:
    tmp=v
    count += 1

print count

Submission status: Accepted

Solution code:
S=input()

prev = S[0]
res=0
for i in range(1,len(S)):
	if S[i]!=prev:
		res+=1
		prev=S[i]

print(res)

Submission status: Accepted

Solution code:
S = list(raw_input())

if len(set(S)) == 1:
    print 0
else:
    while S[-1] == S[-2]:
        del S[-1]
    del S[-1]

    count = 1
    for i in xrange(len(S)-1):
        if S[i] != S[i+1]:
            count += 1
    print count

Submission status: Accepted

Solution code:
s = [x for x in raw_input()]

step = len(s)

idx = 0
p = s[-1]
for i in range(step -1, -1, -1):
    if s[i] != p:
        s.append(s[i])
        p = s[i]
        idx += 1

print idx

Submission status: Accepted

Solution code:
S=raw_input()

ans = 0
for i in range(len(S)-1):
    if S[i]!=S[i+1]:
       ans+=1
print ans

Submission status: Accepted

Solution code:
S = input()
state = 'A'
count = -1
for c in S:
    if c!=state:
        count+=1
        state=c
print(count)

Submission status: Accepted

Solution code:
s = input()
c = 0
n = ""
for i in s:
    if not n == i:
        c+=1
        n = i
print(c-1)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
s = input()
print(s.count('BW') + s.count('WB'))

Submission status: Accepted

Solution code:
#! /usr/bin/env python3

bw = input()
cnt = 0
t = bw[0]
for i in bw[1:]:
    if i != t:
        cnt += 1
        t = i
print(cnt)

Submission status: Accepted

Solution code:
def main():
    s = raw_input()
    check_b = lambda x: x=='B'
    check_w = lambda x: x=='W'
    if all(map(check_b, list(s))) or all(map(check_w, list(s))):
        return 0

    work = list(s)[:]
    cnt = 0
    for i in range(len(work)-1):
        w_list = work[i:i+2]
        if w_list[0] == w_list[1]:
            pass
        else:
            cnt += 1

    return cnt



if __name__ == '__main__':
    print main()

Submission status: Accepted

Solution code:

def main():
    s = raw_input()
    check_b = lambda x: x=='B'
    check_w = lambda x: x=='W'
    if all(map(check_b, list(s))) or all(map(check_w, list(s))):
        return 0

    work = list(s)[:]
    flag_b = False
    flag_w = False
    stack = []
    cnt = 0
    for i in range(len(work)-1):
        w_list = work[i:i+2]
        if w_list[0] == w_list[1]:
            pass
        else:
            cnt += 1

    return cnt



if __name__ == '__main__':
    print main()

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**10
mod = 10**9 + 7


def f():
    s = input()
    t = ''
    r = -1
    for c in s:
        if t != c:
            r += 1
            t = c
    return r

print(f())

Submission status: Accepted

Solution code:

S = input()
p = None
n = 0
for s in S:
    if s != p:
        n += 1
        p = s
print(n - 1)

Submission status: Accepted

Solution code:
s = input()
ans = -1
b = ""
for l in s:
	if b != l:
		ans += 1
	b = l
print(ans)

Submission status: Accepted

Solution code:
from collections import Counter
s = input()
cnt_wb = Counter(s)
# 全部同じ色のとき
if cnt_wb["W"] == len(s) or cnt_wb["B"] == len(s):
    print(0)
else:
    prev = s[0]
    cnt = 0
    for i in range(1, len(s)):
        if prev != s[i]:
            prev = s[i]
            cnt += 1
    print(cnt)

Submission status: Accepted

Solution code:
s = raw_input().strip()
c = 0
for i in xrange(len(s) - 1):
    c += s[i] != s[i+1]
print c

Submission status: Accepted

Solution code:
s=raw_input()
l=0
r=len(s)-1

news=""
i=0
while i<len(s):
    if s[i]=="W":
        while i<len(s) and s[i]=="W":
            i+=1
        news+=s[i-1]
    else:
        while i<len(s) and s[i]=="B":
            i+=1
        news+=s[i-1]
print(len(news)-1)

Submission status: Accepted

Solution code:
def solve(s):
    ans = 0
    while len(s)>1:
        ans += s[0]!=s[1]
        s = s[1:]
    return ans

S = input()
print(solve(S))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3


def compute(s):
    board = [c == "W" for c in s]
    n = len(board)
    ans = 0
    for i in range(1, n):
        if board[i] != board[i - 1]:
            ans += 1
    return ans


def main():
    print(compute(input()))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def solve(s):
    count = 0
    for i in range(1, len(s)):
        if s[i - 1] != s[i]:
            count += 1
    return count

s = raw_input().strip()
print(solve(s))

Submission status: Accepted

Solution code:
s=raw_input()
ans=0
t=''
for i in s:
    if t!='' and t!=i:
        ans+=1
    t=i
print ans

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-

from __future__ import division, print_function, absolute_import, unicode_literals
s = input()
cnt = 0
for a, b in zip(s[:-1], s[1:]):
    if a != b:
        cnt += 1
print(cnt)
# 11100
# WBWBWBWBWB
# 1010101010

Submission status: Accepted

Solution code:
s = input()
ans = 0
for i in range(1, len(s)):
    if s[i] != s[i-1]:
        ans += 1
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

S = input()


prev = ''
new_S = ''
for ch in S:
    if ch != prev:
        new_S += ch
    prev = ch
print(len(new_S)-1)

Submission status: Accepted

Solution code:
s = list(raw_input())

count = 0

#print s

for i in range(len(s)-1):
    if(s[i]!=s[i+1]):count+=1

print count

Submission status: Accepted

Solution code:
import sys

line = sys.stdin.readline().rstrip()

last = None
res = 0
for i in range(len(line)):
    if last != line[i]:
        res += 1
    last = line[i]

print(res-1)

Submission status: Accepted

Solution code:
s = raw_input()
before = ''
ans = 0

for i in s:
    if i != before:
        ans += 1
        before = i
print ans-1

Submission status: Accepted

Solution code:
import itertools
S = input()
group = list(itertools.groupby(S))
print(len(group) - 1)

Submission status: Accepted

Solution code:
S = raw_input()
S_list = list(S)
x = S_list[0]
res = 0
for s in S_list:
    if s != x:
        res += 1
        x = s
print res

Submission status: Accepted

Solution code:
s = raw_input()

ans = 0
for i in range(0, len(s) - 1):
	ans += s[i] != s[i + 1]
print ans

Submission status: Accepted

Solution code:
#import string,itertools,fractions,heapq,re,array,bisect
#from math import *
#from collections import Counter
def rl(s): return xrange(len(s))

INF = 2147483647


import sys
stdin = sys.stdin

s = stdin.readline().strip()

rr = sum(a != b for a, b in zip(s, s[1:]))
print rr

Submission status: Accepted

Solution code:
s = raw_input()
count = 0
c = s[0]
for i in xrange(len(s)):
    if s[i] == c:
        continue
    count += 1
    c = s[i]
print count

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

S = s()

count = 0
before = S[0]
for c in S:
    if c != before:
        count += 1
        before = c

print count

Submission status: Accepted

Solution code:
line = input()
s = len(line)
last = line[0]
count = 0
for letter in line:
    if letter!=last:
        last = letter
        count+=1
print(count)

Submission status: Accepted

Solution code:
S = raw_input()
ans = 0
for i in range(len(S)-1):
    if S[i]!=S[i+1]:
        ans += 1
print ans

Submission status: Accepted

Solution code:
# def makelist(n, m):
# 	return [[0 for i in range(m)] for j in range(n)]

# n = int(input())
# a, b = map(int, input().split())
# s = input()


s = input()
now = s[0]
ans = 0
for c in s:
	if c != now:
		now = c
		ans += 1
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

s = input().strip()
cur = s[0]
cnt = 0
for c in s:
    if c != cur:
        cur = c
        cnt += 1
print(cnt)

Submission status: Accepted

Solution code:
s=list(raw_input())
cnt=0
for i in range(len(s)-1):
    if s[i]!=s[i+1]:cnt+=1
print cnt

Submission status: Accepted

Solution code:
import itertools
print(len(list(itertools.groupby(input()))) - 1)

Submission status: Accepted

Solution code:
from sys import exit, setrecursionlimit
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

setrecursionlimit(1000000)

S = input()
result = sum(S[i] != S[i-1] for i in range(1, len(S)))
print(result)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
    ios::sync_with_stdio(false);
    cin >> s;
    cout << unique(s.begin(), s.end()) - s.begin() - 1 << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
s=input()
cnt=0
for i range(1,len(s)):
  if s[i]!=s[i-1]:
    cnt+=1
print(cnt)

Submission status: Runtime Error

Solution code:
a=input()
n,b=0,0
while True:
    if a[n]!=a[n+1]:
        b+=1
    n+=1
    if n+1==len(a):
        break
print(b)

Submission status: Runtime Error

Solution code:
S = input()
print(sum([a!=b for a,b in zip(S[:-1],S[1:])])

Submission status: Runtime Error

Solution code:

s_long = input()

count = 0
prev = ''

for s in s_long:
    if prev == ''
        prev = s
        continue

    if prev != s:
        count += 1
        prev = s

print(count)

Submission status: Runtime Error

Solution code:
s=input()
ans = 0
for I in range(len(s)-1):
 if s[i]!=s[i+1]:
  ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10**8)


class Segtree():
    INT_MIN=-10**9

    def __init__(self,size):
        self.size=1
        while self.size<size:
            self.size=self.size*2
        self.node=[self.INT_MIN]*(2*self.size-1)


    def update(self,k,a):
        k+=self.size-1
        self.node[k]=a
        while k>0:
            k=(k-1)/2
            self.node[k]=max(self.node[k*2+1],self.node[k*2+2])

    def get_max(self,queryL,queryR,k=0,nodeL=0,nodeR=-1):
        if nodeR==-1:nodeR=self.size
        if (nodeR<=queryL or queryR<=nodeL):return self.INT_MIN
        if (queryL<=nodeL and nodeR<=queryR):return self.node[k]
        else:
            nodeM=(nodeL+nodeR)/2
            vl=self.get_max(queryL,queryR,k*2+1,nodeL,nodeM)
            vr=self.get_max(queryL,queryR,k*2+2,nodeM,nodeR)
            return max(vl,vr)

n,t=map(int,raw_input().split())
a=map(int,raw_input().split())
seg=Segtree(n)
for i in xrange(n):
    seg.update(i,a[i])
ans=0
mx=0
for i in xrange(n):
    tmp=seg.get_max(i,n)-a[i]
    if mx<tmp:
        ans=1
        mx=tmp
    elif mx==tmp:
        ans+=1
print ans

Submission status: Runtime Error

Solution code:
import unittest


class TestFunc(unittest.TestCase):
    def test_1(self):
        self.assertEqual(fun(5,8,[50,30,40,10,20]),2)
        self.assertEqual(fun(3,2,[100,50,200]),1)
        self.assertEqual(fun(10,100,[7,10,4,5,9,3,6,8,2,1]),2)
        self.assertEqual(fun(5,2,[1,2,3,2,4]),1)




def fun(n,t,a):
    aa = []
    b = None
    s = None
    for i in range(n):
        m = -1
        for j in range(i+1,n):
            if a[j]>a[i] and a[j]-a[i]>m:
                m = a[j]-a[i]
        if m>0:
            aa.append(m)

    c = aa[0]
    ans = 1
    for i in range(1,len(aa)):
        if c<aa[i]:
            c = aa[i]
            ans = 1
        elif c==aa[i]:
            ans += 1

    return ans


if __name__=='__main__':
    #unittest.main()                                                                                                                                                              

    n,t = [int(x) for x in raw_input().split(" ")]
    a = [int(x) for x in raw_input().split(" ")]
    print(fun(n,t,a))

Submission status: Runtime Error

Solution code:
s = open('input', 'r').read()
prev = s[0]
ans = 0

for c in s:
    if c != prev:
        ans += 1
        prev = c
print(ans-1)

Submission status: Runtime Error

Solution code:
s = raw_input()
cnt = 0
last
last = s[0]

for c in s[1:end]:
 if c ! last
  cnt = cnt+1
 last = c
print cnt

Submission status: Runtime Error

Solution code:
inp = input().strip()
print len( [ i for i in range( len(inp)-1 ) if inp[i] != inp[i+1] ] )

Submission status: Runtime Error

Solution code:
inp = input().strip()
print len( [ for i in range( len(inp)-1 ) if inp[i] != inp[i+1] ] )

Submission status: Runtime Error

Solution code:

def main():
    N = input()
    edges = [raw_input() for _ in range(N-1)]
    K = input()
    VP = [raw_input() for _ in range(K)]

    VP = [map(int, _.strip().split()) for _ in VP]
    edges = [map(int, _.strip().split()) for _ in edges]
    # print VP
    # print edges
    scores = {}
    for n_idx, value in VP:
        scores[n_idx] = [value]
    pre_defined = scores.keys()
    # print scores
    def check(value, n1, n2):
        if value == (n1 - n2) or value == (n2 - n1):
            return True
        return False

    for n1, n2 in edges:
        # print n1, n2
        if scores.get(n1) is None and scores.get(n2) is None:
            pass
        else:
            if scores.get(n1) is None:
                for v in scores.get(n2, []):
                    scores[n1] = [_ for _ in scores.get(n1, []) if check(_, n1, n2)] + [v - 1, v+1]
            elif scores.get(n2) is None:
                for v in scores.get(n1, []):
                    scores[n2] = [_ for _ in scores.get(n2, []) if check(_, n1, n2)] + [v - 1, v+1]

    for n1, n2 in edges[-1::]:
        # print n1, n2
        if scores.get(n1) is None and scores.get(n2) is None:
            pass
        else:
            if scores.get(n1) is None:
                for v in scores.get(n2, []):
                    scores[n1] = [_ for _ in scores.get(n1, []) if check(_, n1, n2)] + [v - 1, v+1]
            elif scores.get(n2) is None:
                for v in scores.get(n1, []):
                    scores[n2] = [_ for _ in scores.get(n2, []) if check(_, n1, n2)] + [v - 1, v+1]

        # print scores.get(n1), scores.get(n2) 
        # print "----------"

    # decide step
    adding = []
    for n in range(1, N+1):
        v = scores.get(n, [None])[0]
        adding.append(v)
    if all([_ is not None for _ in adding]):
        print "Yes"
        for a in adding:
            print a
    else:
        print "No"


    # print scores


if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from sys import stdin
input = stdin.readline
N,T = map(int,input().split())
prices = list(map(int,input().split()))
last = 10000000000
highestTally = [prices[-1]]
highestCount = [1]

for price in prices[-2:-N-1:-1]:
    if price==highestTally[-1]:
        highestCount.append(highestCount[-1]+1)
    else:
        highestCount.append(1)
    highestTally.append(max(highestTally[-1],price))
highestTally.reverse()
highestCount.reverse()

indexOfHighest={}
for i in range(N-1,-1,-1):
    if highestTally[i]==prices[i]:
        indexOfHighest[highestTally[i]]=i

biggestJump=0
sellingPriceForBiggestJump=0
HPcount=0
LPcount=0
for index,price in enumerate(prices):
    if index==N-1:
        break
    bestSellingPrice = highestTally[index+1]
    jump = bestSellingPrice-price
    #print(jump,bestSellingPrice,biggestJump)
    if jump>biggestJump:
        biggestJump = jump
        LPcount+=1
        sellingPriceForBiggestJump = bestSellingPrice
        HPcount=highestCount[indexOfHighest[bestSellingPrice]]
    elif jump==biggestJump:
        if bestSellingPrice!=sellingPriceForBiggestJump:
            sellingPriceForBiggestJump = bestSellingPrice
            HPcount+=highestCount[indexOfHighest[bestSellingPrice]]
        LPcount+=1
count = min(LPcount,HPcount)            
if T//2>=count:
    print(count)
else:
    print(int(T//2))

Submission status: Runtime Error

Solution code:
from sys import stdin
input = stdin.readline
N,T = map(int,input().split())
prices = list(map(int,input().split()))
last = 10000000000
highestTally = [prices[-1]]
for price in prices[-2:-N-1:-1]:
    highestTally.append(max(highestTally[-1],price))
highestTally.reverse()

biggestJump=0
sellingPriceForBiggestJump=0
count=0
for index,price in enumerate(prices):
    if index==N-1:
        break
    bestSellingPrice = highestTally[index+1]
    jump = bestSellingPrice-price
    if jump>biggestJump:
        biggestJump = jump
        sellingPriceForBiggestJump = bestSellingPrice
        count=1
    elif jump==biggestJump:
        if bestSellingPrice!=sellingPriceForBiggestJump:
            sellingPriceForBiggestJump = bestSellingPrice
            count+=1
if T//2>=count:
    print(count)
else:
    print(int(T//2))

Submission status: Runtime Error

Solution code:
def solve(s):
    if len(s)<=1:
        return 0
    return (s[0]!=s[1]) + solve(s[1:])

S = input()
print(solve(S))