import os
import sys


script = __file__
scriptPath = os.path.dirname(script)
scriptFile = os.path.basename(script)[0]
files = [f for f in os.listdir(scriptPath) if scriptFile in f and '.in' in f]
if '{}-large'.format(scriptFile) in str(files):
  size = 'large'
elif '{}-small'.format(scriptFile) in str(files):
  size = 'small'
elif '{}-test'.format(scriptFile) in str(files):
  size = 'test'
else:
  print('{}-test not found'.format(scriptFile))
  sys.exit()
latest = sorted(f for f in files if size in f)[-1][:-3]
f = '{}/{}'.format(scriptPath, latest)
i = open(f + '.in', 'r')
o = open(f + '.out', 'w')
print(f)
T = int(i.readline())

# https://code.google.com/codejam/contest/6254486/dashboard#s=p1
# Problem B. Revenge of the Pancakes

for x in range(T):
  S = list(i.readline().rstrip())
  y = 0
  while '-' in S:
    i = 1
    while i < len(S) and S[i] == S[0]:
      i += 1
    S = [['+', '-'][p == '+'] for p in reversed(S[:i])] + S[i:]
    y += 1

  o.write('Case #{}: {}{}'.format(x + 1, y, ['\n', ''][x == T - 1]))

i.close()
o.close()

@@ -45,17 +45,18 @@
 %0D%0Ascript
-P
+_p
 ath = os
@@ -80,25 +80,26 @@
 ipt)%0D%0Ascript
-F
+_f
 ile = os.pat
@@ -158,17 +158,18 @@
 r(script
-P
+_p
 ath) if 
@@ -174,17 +174,18 @@
 f script
-F
+_f
 ile in f
@@ -221,33 +221,34 @@
 e'.format(script
-F
+_f
 ile) in str(file
@@ -244,32 +244,34 @@
 in str(files):%0D%0A
+  
   size = 'large'
@@ -293,33 +293,34 @@
 l'.format(script
-F
+_f
 ile) in str(file
@@ -316,32 +316,34 @@
 in str(files):%0D%0A
+  
   size = 'small'
@@ -368,25 +368,26 @@
 ormat(script
-F
+_f
 ile) in str(
@@ -397,16 +397,18 @@
 es):%0D%0A  
+ 
+ 
 size = '
@@ -421,16 +421,18 @@
 %0Aelse:%0D%0A
+  
   print(
@@ -468,16 +468,19 @@
 ript
-F
+_f
 ile))%0D%0A
+  
   sy
@@ -571,17 +571,18 @@
 t(script
-P
+_p
 ath, lat
@@ -801,16 +801,18 @@
 ge(T):%0D%0A
+  
   S = li
@@ -838,16 +838,18 @@
 rip())%0D%0A
+  
   y = 0%0D
@@ -849,16 +849,18 @@
  y = 0%0D%0A
+  
   while 
@@ -878,15 +878,23 @@
     
+  
+  
 i = 1%0D%0A
+    
     
@@ -939,16 +939,22 @@
     
+ 
+     
 i += 1%0D%0A
     
@@ -945,24 +945,28 @@
     i += 1%0D%0A
+    
     S = %5B%5B'+
@@ -1018,16 +1018,20 @@
  S%5Bi:%5D%0D%0A
+    
     y +=
@@ -1036,16 +1036,18 @@
 += 1%0D%0A%0D%0A
+  
   o.writ

Update B.py