Problem:


Score : 100 points

Problem Statement

We have weather records at AtCoder Town for some consecutive three days. A string of length 3, S, represents the records - if the i-th character is S, it means it was sunny on the i-th day; if that character is R, it means it was rainy on that day.

Find the maximum number of consecutive rainy days in this period.

Constraints

|S| = 3

Each character of S is S or R.

Input

Input is given from Standard Input in the following format:

S

Output

Print the maximum number of consecutive rainy days in the period.

Sample Input 1

RRS

Sample Output 1

2

We had rain on the 1-st and 2-nd days in the period. Here, the maximum number of consecutive rainy days is 2, so we should print 2.

Sample Input 2

SSS

Sample Output 2

0

It was sunny throughout the period. We had no rainy days, so we should print 0.

Sample Input 3

RSR

Sample Output 3

1

We had rain on the 1-st and 3-rd days - two "streaks" of one rainy day, so we should print 1.



Sample input:
RRS


Sample output:
2

Submission status: Runtime Error

Solution code:
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))

max_score = -float('inf')

for i in range(n):
    loop_score_array = []
    loop_score = 0
    loop_len = 0
    pos = i
    while True:
        pos = p[pos] - 1
        loop_score += c[pos]
        loop_score_array.append(loop_score)
        loop_len+=1
        if pos == i:
            break
    for i, score in enumerate(loop_score_array):
        if k-i-1 < 0:
            continue
        loop_num = (k-i-1)//loop_len
        score_sum = score + max(0, loop_score)*loop_num
        max_score = max(score_sum, max_score)
print(max_score)

Submission status: Runtime Error

Solution code:
S=input()
print(max(i for i in range(4)if S.index("R"*i)))

Submission status: Runtime Error

Solution code:
S = input[0]
cnt = 0
for i in range(3):
  if S[i] == 'R':
    # count, 前の文字列がR or nullならcnt+1、そうでない場合、1
    # 
    if i == 0 or S[i - 1] == 'R':
	  cnt += 1
    else:
      cnt = 1
print(cnt)

Submission status: Runtime Error

Solution code:
N = int(input())
L = list(map(int,input().strip().split()))
L_sort = L.sort()
count = 0
for i in range(N-2):
	for j in range(i+1 , N):
		for k in range(j+1 , N):
        		if L_sort(i) + L_sort(j) > L_sort(k):
            		count += 1
print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
L = list(map(int,input().strip().split()))
L_sort = L.sort()
count = 0
for i in range(N-2):
	for j in range(i+1 , N):
		for k in range(j+1 , N):
        	if L_sort(i) + L_sort(j) > L_sort(k):
            	count += 1
print(count)

Submission status: Runtime Error

Solution code:
s=input()
if s[0]==s[1]==s[2]=='R':
  print (3)
else:
	if s[0]==s[1]=='R' or s[1]==s[2]=='R' :
      print (2)
    else:
      if s[0]=='R' or s[1]=='R' or s[2]=='R':
        print (1)
      else:
        print (0)

Submission status: Runtime Error

Solution code:
# 入力
R, C, K = map(int, input().split())
point_map = [[0 for _ in range(C+1)] for _ in range(R+1)]
max_point = [[[0 for _ in range(4)] for _ in range(C + 1)]
             for _ in range(R + 1)]
maxmax_point = [[0 for _ in range(C + 1)] for _ in range(R + 1)]


for i in range(K):
    _r, _c, _k = map(int, input().split())
    point_map[_r][_c] = _k

for i in range(1, R+1):
    itemss = [[]]
    im = i-1
    for j in range(1, C + 1):
        jm = j - 1
        mxi = max_point[i]
        mxij = mxi[j]
        mxijm = mxi[jm]
        point = point_map[i][j]
        mxij[0] = max(
            mxijm[0], maxmax_point[im][j])
        if point == 0:
            mxij[1] = mxijm[1]
            mxij[2] = mxijm[2]
            mxij[3] = mxijm[3]
        else:
            itemss = [[]] + [items + [point]
                             for items in itemss]  # items[1] アイテム一つ
            itemss_len = len(itemss)
            #print(i, j, itemss)

            mxij[1] = max(
                mxijm[0] + point, maxmax_point[i - 1][j]+point)
            mxij[2] = mxijm[1] + point

            if itemss_len > 4:
                items = itemss[4]  # 4 こアイテムがあるやつ
                del_item = min(items)
                items.remove(del_item)
                sa = mxijm[3] - del_item
                #print("aaaaa", sa, mxijm[2])
                if sa > mxijm[2]:
                    mxij[3] = sa + point
                    itemss = itemss[:3] + [items]
                else:
                    mxij[3] = mxijm[2] + point
                    itemss = itemss[:4]
            else:
                mxij[3] = mxijm[2] + point

            #print(i, j, itemss)

        #[print(i, j, n, mxij[n])
        # for n in range(len(mxij))]
        maxmax_point[i][j] = max(mxij)
        #print(i, j, maxmax_point[i][j])

print(maxmax_point[R][C])

Submission status: Runtime Error

Solution code:
X,K,D=list(map(int,input().split()))

def sgn(x):
    if x>0:
        return 1
    elif x<0:
        return -1
    return 0

def solve():
    if X>0:
        x_greedy=X-K*D
    elif X<0:
        x_greedy=X+K*D

    if sgn(X)==sgn(x_greedy):
        return print(abs(x_greedy))

    else:
        x_r=X%D
        x_l=x_r-D

        r_parity=(abs(X-x_r)//D)%2
        if K%2==r_parity:
            return print(abs(x_r))
        else:
            return print(abs(x_l))

if __name__=='__main__':
    solve()

Submission status: Runtime Error

Solution code:
X,K,D=list(map(int,input().split()))

def sgn(x):
    if x>0:
        return 1
    elif x<0:
        return -1
    return 0

def solve():
    if X>0:
        x_greedy=X-K*D
    else:
        x_greedy=X+K*D

    if sgn(X)==sgn(x_greedy):
        return print(x_greedy)

    else:
        x_r=X%D
        x_l=x_r-D

        r_parity=(abs(X-x_r)//D)%2
        if K%2==r_parity:
            return print(abs(x_r))
        else:
            return print(abs(x_l))

if __name__=='__main__':
    solve()

Submission status: Runtime Error

Solution code:
for r in S:
  if rrr in S:
    return(3)
  elif rr in S:
    return(2)
  elif: r in S:
    return(1)
  else:
    return(0)

Submission status: Runtime Error

Solution code:
x, k, d = map(int, input().split())
if x < 0:
    x *= -1
if x - k // d >= 0:
    print(x-k*d)
else:
    k -= x // d
    x %= d
    if k % 2 == 0:
        print(x)
    else:
        print(abs(x-d))

Submission status: Runtime Error

Solution code:

def main():
    x, k, d = map(int, input().split())
    # x > 0
    if x < 0:
        x = -1 * x
    #the number of d in x
    r = abs(x) // d
    k_rest = k - r
    if r > 0 and k_rest < 0:
        print(x - k * d)
        exit()

    x_r = x - d * r
    x_l = x_r - d

    # print(f"xr: {x_r}\nxl: {x_l}\nk: {k_rest}")

    if k_rest % 2 == 0:
        print(abs(x_r))
    else:
        print(abs(x_l))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
r = 0
if 'r' not in s:
  print(0)
else:
  for i in range(len(s)):
    if s[i] == 'r' and i!=len(s)-1:
      for j in range(i+1,len(s)):
        if s[j] != 'r':
          break
      r = j-i
  print(r)

Submission status: Runtime Error

Solution code:
x,k,d=map(int,input().split())

x=abs(x)

if x>k*d:
    print(x-k*d)
else:
    r=k-x//d
    if r%2==0:
        print(x%d)
    else:
        print(d-x%d)

Submission status: Runtime Error

Solution code:
n = input()
count = 1
s = []
for i in range(len(n)-1):
    if n[i]=='R' and n[i+1]=='R':
        count+=1
    elif n[i]=='S' and n[i+1]=='S':
        count = 1
    elif n[i]=='R' and n[i+1]=='S':
        s.append(count)
        count = 1
    else:
        count = 1
if count>1:
    s.append(count)

print(max(s))

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
p = list(map(int,input().split()))
c = list(map(int,input().split()))

ans = -float("INF")
for i in range(n):
    pi = p[i]
    x = c[pi-1]
    a = x
    for j in range(k-1):
        pi = p[pi-1]
        a = max(a,x+c[pi-1])
        x += c[pi-1]
    ans = max(ans,a)
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
if s.contains("RRR"):
  print(3)
elif s.contains("RR"):
  print(2)
elif s.contains("R"):
  print(1)
else:
  print(0)

Submission status: Runtime Error

Solution code:
x,k,d=map(int,input().split())
x=abs(x)
sa=x//d
ans=x
pbk,mbk=0,0
bk1,bk2,bk3=1,1,1
mansbk,pansbk=0,0
if sa>=k:
  ans=x-d*k
else:
  ans=x-d*sa
  k=k-sa
  for i in range(k):
    mansbk=abs(ans-d)
    pansbk=abs(ans+d)
    if mansbk!=pansbk:
      ans=min(mansbk,pansbk)
      if bk3!=1:
        bk1=min(mansbk,pansbk)
        bk2=max(mansbk,pansbk)
        ans=ans if (k-i)%2==0 else bk1
        break
      else:
        bk3=max(mansbk,pansbk) 
    else:
      ans=0 if (k-i)%2==0 else d
      break
    pbk=max(mansbk,pansbk)
    mbk=min(mansbk,pansbk)
print(ans)

Submission status: Runtime Error

Solution code:
s = str(input())
s=s.lower(s)

if s.find('rr') != -1:
    print("2")
elif s.find('r') !=-1:
    print("1")
else :
    print ("0")

Submission status: Runtime Error

Solution code:
s = input()
count = 0
a=[]
for i in s:
    if i == "R":
        count += 1 
    else:
        a.append(count)
        count = 0
        
print(max(a))

Submission status: Runtime Error

Solution code:
X, K, D = map(int, input().split())
X=abs(X)
if D>=X and K%2==0:
    ans=X
elif D>=X and K%2==1:
    ans=D-X
elif D<X and K*D<X:
    ans=X-K*D
else:
    ans=X%D
    if (X-ans)%2==0:
        ans=D-ans
print(ans)

Submission status: Runtime Error

Solution code:
MOD = 1000000007
from collections import defaultdict as dd,Counter,deque

def si(): return input()
def ii(): return int(input())
def li(): return list(map(int,input().split()))
def mi(): return map(int,input().split())
def out(v): print(v)
def spout(): print(v,end=" ")
def d2b(n): return bin(n).replace("0b","")
def twod(n,m,num):return [[num for x in range(m)] for y in range(n)]
def vow(): return ['a','e','i','o','u']
def let(): return [chr(i) for i in range(97,123)]
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x
def ispow2(x):
    return (x and (not(x & (x - 1))))
def prime_factors(n):
    i = 2
    factors = []
    while i * i <= n:
        if n % i: i+=1
        else:
            n //= i
            factors.append(i)
    if n > 1: factors.append(n)
    return (list(factors))
  
s=si()
for i in range(3):
  if s[i]=="S":
    c+=1
if c<2 or c==3: print(c)
else:
  if s[1]=="S": print(2)
  else: print(1)

Submission status: Runtime Error

Solution code:
data = list(input())
result = []
i = 0
while i < (len(data)):
  count = 0
  if data[i] == "R":
    count += 1
    i += 1
    while data[i] == "R":
      count += 1
      i += 1
    result.append(count)
  else:
    continue
print(result.max())

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))
ans=-10**10
for st in range(N):
  now = st+1
  temp=[0]
  while(P[now-1] != st+1):
    temp.append(temp[-1]+C[P[now-1]-1])
    now = P[now-1]
    temp.append(temp[-1]+C[P[now-1]-1])
  if len(temp)>=K+1:
    ans=max(ans, max(temp[1:K+1]))
    continue
  if temp[-1]<=0:
    ans = max(ans, (max(temp[1:])))
  else:
    t=temp[-1]*(K//(len(temp)-1))-temp[-1]
    t+=max(max(temp),max([temp[-1]+temp[i+1] for i in range(K%(len(temp)-1))]))
    ans=max(ans, t)
		
print(int(ans))

Submission status: Runtime Error

Solution code:
y Season

S=input()

ans=0

for i in range (len(S)-1):
    if S[i]=="R":
        tempans=1
        for j in range (i+1,len(S)):
            if S[i]==S[j]:
                tempans+=1
            else:
                if tempans>ans:
                    ans=tempans
                break
        else:
            if tempans>ans:
                ans=tempans
print(ans)

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
P = list(map(lambda x: int(x) - 1, input().split()))
C = list(map(int,input().split()))

ans = max(C)
for i in range(N):
    s = i
    l = [C[i]]
    while True:
        s = P[s]
        if s == i:
            break
        l.append(C[s])
        

    if sum(l) > 0:
        c = K//len(l)*sum(l)
        n = K%len(l)
        ans = max(ans,c)
        s = i
        for j in range(n):
            c += C[s]
            s = P[s]
            ans = max(ans,c)

    n = min(N*2,K)
    s = i
    c = 0
    for j in range(n):
        c += C[s]
        s = P[s]
        ans = max(ans,c)
            
print(ans)

Submission status: Runtime Error

Solution code:
n=input()
if n=="SSS":
  print("0")
elif n=='SSR':
  print("1")
elif n=='SRS':
  print("1")
elif n=='SRR':
  print("2")
elif n=='RSS':
  print("0")
elif n=='RSR':
  print("1")
elif n=='RRS':
  print("2")
elif n=="RRR"
  print("3")

Submission status: Runtime Error

Solution code:
/*

*/
#include<bits/stdc++.h>

using namespace std;
using ll=long long;
#define rep2(i, a, n) for(int i = (a); i < (n); i++)
#define rep(i, n) rep2(i,0,n)
#define repe(i,a)for(auto &i:a)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  string s;
  cin>>s;
  int cnt=0,hoge=0;
  repe(i,s){
    if(i=='R'){
      hoge++;
    }else{
      hoge=0;
    }
    cnt=max(cnt,hoge);
  }
  cout<<cnt<<endl;
}

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))
ans=-10**10
for st in range(N):
  now = st+1
  temp=[0]
  while(P[now-1] != st+1):
    temp.append(temp[-1]+C[P[now-1]-1])
    now = P[now-1]
    temp.append(temp[-1]+C[P[now-1]-1])
  if len(temp)>=K+1:
    ans=max(ans, max(temp[1:K+1]))
    continue
  if temp[-1]<=0:
    ans = max(ans, (max(temp[1:])))
  else:
    t=temp[-1]*(K//(len(temp)-1))-temp[-1]
    t+=max(temp+[temp[-1]+temp[i+1] for i in range(K%(len(temp)-1))])
    ans=max(ans, t)
		
print(int(ans))

Submission status: Runtime Error

Solution code:
n,k = list(map(int,input().split()))
p = list(map(int,input().split()))
c = list(map(int,input().split()))
was = [False]*n
sums = []
for i in range(n):
    if not was[i]:
        iWas = [False]*n
        pos = i
        sumn = [c[i]]
        while not iWas[pos]:
            iWas[pos] = True
            was[pos] = True
            pos = p[pos]-1
            sumn+=[c[pos]]
        sumn = sumn[:-1]
        sums.append(sumn)
m = -9999999999999999999999999
for i in range(len(sums)):
    totS = sum(sums[i])
    l = len(sums[i])
    for g in range(len(sums[i])):
        arr = []
        s = 0
        for j in range(l):
            s+=sums[i][(g+j)%l]
            arr.append(s)

        if totS > 1:
            add = max(arr[:k%l]+[-99999999999999999999])
            if add != -99999999999999999999:
                m = max(m,totS*(k//l)+max(max(arr[:k%l]),0))
            else:
                m = max(m,totS*(k//l))

        else:

            m = max(m, max(arr[:min(l,k)]))
print(m)

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
P=list(map(int,input().split()))
C=list(map(int,input().split()))
ans=-10**10
for st in range(N):
  now = st+1
  temp=[0]
  while(P[now-1] != st+1):
    temp.append(temp[-1]+C[P[now-1]-1])
    now = P[now-1]
    temp.append(temp[-1]+C[P[now-1]-1])
  if len(temp)>=K+1:
    ans=max(ans, max(temp[1:K+1]))
    continue
  if temp[-1]<=0:
    ans = max(ans, (max(temp[1:])))
  else:
    t=temp[-1]*(K//(len(temp)-1))-temp[-1]
    t+=max(temp+[temp[-1]+temp[i+1] for i in range(K%(len(temp)-1)+1)])
    ans=max(ans, t)
		
print(int(ans))

Submission status: Runtime Error

Solution code:
import numpy

e=input().split()
for i in range(len(e)):
  e[i]=int(e[i])
x=e[0]
k=e[1]
d=e[2]
t=k
if k>10000:
 if k%2==0:
   t=10000
 else:
   t=10001
kou=numpy.gcd(x,d)
x=int(x/kou)
d=int(d/kou)
if d>100 and d%2==0:
  d=100
if d>100 and d%2==1:
  d=1001
for i in range(t):
  if abs(x+d)<abs(x-d):
    x+=d
  else:
    x-=d
print(abs(x)*kou)

Submission status: Runtime Error

Solution code:
print(sum(input() in "R"*i for i in range(3)))

Submission status: Runtime Error

Solution code:
a=input()
max=[]
for i in range(3):
  if a[i]== 'R':
    if i ==0:
      max[0]=1
    else:
      max[i]=max[i-1]+1
  else:
    max[i]=0
print(sum(max))

Submission status: Runtime Error

Solution code:
st = input()
if st[0] == st[1] and st[0] == st[2] and st[0] == "R":
  print(3)
elif (st[0] == st[1] == "R") OR (st[1] == st[2] == "R"):
  print(2)
else:
  print(1)

Submission status: Runtime Error

Solution code:
xkd = list(map(int,input().split()))
xkd[0] = abs(xkd[0])
for i in range(xkd[0] // xkd[2]):
    xkd[0] -= xkd[2]
    xkd[1] -= 1
    if xkd[1] < 1:
      break
ans = xkd[0]
if xkd[1] % 2 != 0:
    ans -= xkd[2]
    if ans > xkd[0] + xkd[2]:
        ans += xkd[2] * 2
print(abs(ans))

Submission status: Runtime Error

Solution code:
s=input()
if s=="RRR":
	print(3)
elif s=="RRS" or s=="SRR":
	print(2)
elif s=="SSR" or s=="SRS" or s=="RSS" or s=="RSR”:
	print(1)
else:
	print(0)

Submission status: Runtime Error

Solution code:
s=input()
if s=="RRR":
	print(3)
elif s=="RRS" or s=="SRR":
	print(2)
elif s=="SSR" or s=="SRS" or s=="RSS" or s=="RSR:
	print(1)
else:
	print(0)

Submission status: Runtime Error

Solution code:
s=input()
c=0
mc=0
for i in s:
  if i='R':
    c+=1
    mc=c
  else:
    c=0
print(max(c,mc))

Submission status: Runtime Error

Solution code:
s=input()
if s=="RRR":
    print(3)
elif s="RR":
    print(2)
elif s="R":
    print(1)
else: print(0)

Submission status: Runtime Error

Solution code:
wt = str(input())
if wt == 'SSS':
    print(0)
if wt == "RRR":
    print(3)
else:
    id = wt.index('R')
    if wt.count('R') == 2 and wt[id] == wt[id+1] == 'R':
        print(2)
    else:
        print(1)

Submission status: Runtime Error

Solution code:
S=int(input())
if S[1]=="S":
  if S[0]=="S" and S[2]=="S":
    print(3)
  elif S[0]=="S" or S[2]=="S":
    print(2)
  else:
    print(1)
else:
  if S[0]=="S" or S[2]=="S":
    print(1)
  else:
    print(0)

Submission status: Runtime Error

Solution code:
S = input()
if S == 'SSS':
  print(0)
elif S == 'SSR':
  print(1)
elif S == 'SRR':
  print(2)
else if S == 'SRS':
  print(1)
else if S == 'RSS':
  print(1)
else if S == 'RRS':
  print(2)
else if S == 'RRR':
  print(3)
else if S == 'RSR':
  print(1)

Submission status: Runtime Error

Solution code:
S = input()
max = 0
i = 0
m = 0
while(i != len(S)):
  if S[i] == "R":
    m += 1
  
  else:
    max = max(max,m)
    m = 0
    break
  i += 1

print(max)

Submission status: Runtime Error

Solution code:

#"""
N, K = [int(n) for n in input().split(" ")]
Ps = [int(n) for n in input().split(" ")]
Cs = [int(n) for n in input().split(" ")]
#"""
"""
N = 10
K = 58345
Ps = [9, 1, 6, 7, 8, 4, 3, 2, 10, 5]
Cs = [695279662, 988782657, -119067776, 382975538, -151885171, -177220596, -169777795, 37619092, 389386780, 980092719]
"""
"""
N = 3
K = 3
Ps = [3, 1, 2]
Cs = [-1000,-2000,-3000]
"""

circles = []
already = {}
for p in range(N):
    if p not in already:
        tmp = []
        nowp = p
        while nowp not in tmp:
            tmp.append(nowp)
            already[nowp] = 1
            nowp = Ps[nowp] - 1
        circles.append(tmp)

#print(circles)

finalResult = -100000000000

def getCircleScore(circle, start, kk):
    #print(circle, start, kk)
    s = 0
    for k in range(kk):
        index = start + k
        if index >= len(circle):
            index = index % len(circle)
        s += Cs[circle[index]]
    return s

"""
maxCircle = []
maxCircleScore = -10000000000
maxIndex = 0
for circle in circles:
    CircleSum = sum([Cs[n] for n in circle])
    if maxCircleScore <= CircleSum:
        maxCircleScore = CircleSum
        maxCircle = circle
"""
#for circle in [maxCircle]:
for circle in circles:
    
    CircleSum = sum([Cs[n] for n in circle])
    #print(circle, CircleSum)
    score = 0
    if CircleSum > 0:
        score = K // len(circle) * CircleSum

    K = K % len(circle)
    if K == 0:
        K = len(circle)

    maxScore = -100000000000
    for start in range(len(circle)):
        #print("start", start)
        for kk in range(1, K+1):
            s = getCircleScore(circle, start, kk)
            #print(s)
            if maxScore <= s:
                maxScore = s

    final = score + maxScore

    if final >= finalResult:
        finalResult = final

print(finalResult)

Submission status: Runtime Error

Solution code:
S = input()
if S == 'RRS':
    print(2)
elif S == 'SSS'
    print(0)
elif S = 'SRR'
	print(2)
elif S = 'RRR'
    print(1)

Submission status: Runtime Error

Solution code:
s = input()
ans = 0
if s == 'SSS':
    print(3)
elif s == 'SSR' or s == 'RSS':
    print(2)
elif s == 'SRR' or s == 'RSR' s == 'RRS' or s == 'SRS':
    print(1)
else:
    print(0)

Submission status: Runtime Error

Solution code:
S = input('天気が雨である日が連続していた最大の日数を出力せよ。')
N = True
while N == True:
N = False
if S == 'SSS':
	print(0)
elif S == 'SSR':
	print(1)
elif S == 'SRR':
	print(2)
elif S == 'SRS':
	print(1)
elif S == 'RSS':
	print(1)
elif S == 'RRS':
	print(2)
elif S == 'RRR':
	print(3)
elif S == 'RSR':
	print(1)
else:
	N = True

Submission status: Runtime Error

Solution code:
xkd = input()

xstr,kstr,dstr = xkd.split()

x = int(xstr)
k = int(kstr)
d = int(dstr)

if x >= k*d:
    print(x-(k*d))
else:
    if x <= -(k*d):
        print(x+(k*d))
    else:
        if x <= 0:
            lxl = -x
        else:
            lxl = x
        if x <= 0:
            now_x = x + (d * (int(lxl / d) + 1))
            left_x = -now_x
            right_x = now_x + d
        else:
            now_x = x - (d * (int(lxl / d) + 1))
            left_x = -(now_x - d)
            right_x = now_x
        now_k = k - int(lxl / d) - 1
        if now_x <= 0:
            if now_k % 2 == 0:
                print(left_x)
            else:
                print(right_x)
        else:
            if now_k % 2 == 0:
                print(right_x)
            else:
                print(left_x)

Submission status: Runtime Error

Solution code:
S = input('天気が雨である日が連続していた最大の日数を出力せよ。')
N = True
while N == False:
if S == 'SSS':
	print(0)
elif S == 'SSR':
	print(1)
elif S == 'SRR':
	print(2)
elif S == 'SRS':
	print(1)
elif S == 'RSS':
	print(1)
elif S == 'RRS':
	print(2)
elif S == 'RRR':
	print(3)
elif S == 'RSR':
	print(1)
else:
	N = False

Submission status: Runtime Error

Solution code:
xkd = input()

x,k,d = int(xkd.split())

if x >= k*d:
    print(x-(k*d))
else:
    if x <= -(k*d):
        print(x+(k*d))
    else:
        if x <= 0:
            lxl = -x
        else:
            lxl = x
        if x <= 0:
            now_x = x + (d * (int(lxl / d) + 1))
            left_x = -now_x
            right_x = now_x + d
        else:
            now_x = x - (d * (int(lxl / d) + 1))
            left_x = -(now_x - d)
            right_x = now_x
        now_k = k - int(lxl / d) - 1
        if now_x <= 0:
            if now_k % 2 == 0:
                print(left_x)
            else:
                print(right_x)
        else:
            if now_k % 2 == 0:
                print(right_x)
            else:
                print(left_x)

Submission status: Runtime Error

Solution code:
a,b,c=map(int,input().split())
temp=abs(a//c)
if(temp>b):
    temp=temp-b
    if(a%c==0):
        if(temp>b):
            print(a-(b*c))
        else:
            print(temp*c)
    else:
        print(a-(b*c))
else:
    if(temp==b):
        if(a%c==0):
            print(0)
        else:
            print(a%c)
    else:
        if(a%c==0):
            b=b-temp;
            if(b%2==0):
                print(0)
            else:
                print(c)
        else:
            b=b-temp;
            if(b%2==0):
                print(a%c)
            else:
                t1=(a%c)-c
                t2=(a%c)+c
                if(abs(t1)>abs(t2)):
                    print(abs(t2))
                else:
                    print(abs(t1))

Submission status: Runtime Error

Solution code:
x, k, d = map(int, input().split())
distance = k * d
result = abs(x - distance)


while distance >= 0:
  distance -= d * 2
  if result > result = abs(x - distance):
    result = abs(x - distance)
    
print(result)

Submission status: Runtime Error

Solution code:
X,K,D = map(int,input().split())
X = abs(X)
#0またがない
if X > K*D:
    ans = X - K*D
#0またぐ
else:
    while X >= 0 :
        X = X - D
        K -= 1
    if K % 2 == 0:
        ans = abs(X)
    if K % 2 != 0:
        ans = X+D

print(ans)

Submission status: Runtime Error

Solution code:
S = input('天気が雨である日が連続していた最大の日数を出力せよ。')
N = True
while N == False:
if S == 'SSS':
	print(0)
else if S == 'SSR':
	print(1)
else if S == 'SRR':
	print(2)
else if S == 'SRS':
	print(1)
else if S == 'RSS':
	print(1)
else if S == 'RRS':
	print(2)
else if S == 'RRR':
	print(3)
else if S == 'RSR':
	print(1)
else:
	N = False

Submission status: Runtime Error

Solution code:
S = str(intput())

ans=0

if S[0]==R:
	if S[1]==R:
		if S[2]==R:
			print("3")
		else:
			print("2")
	else:
		if S[2]==R:
			print("1")
		else:
			print("1")
else:
	if S[1]==R:
		if S[2]==R:
			print("2")
		else:
			print("1")
	else:
		if S[2]==R:
			print("1")
		else:
			print("0")

Submission status: Runtime Error

Solution code:
X,K,D = map(int,input().split())
X = abs(X)
#0またがない
if X > K*D:
    ans = X - K*D
#0またぐ
else:
    while X >= 0 :
        X = X - D
        K -= 1
    if K % 2 == 0:
        ans = abs(X)
    else:
        ans = X+D

print(ans)

Submission status: Runtime Error

Solution code:
def walking():
    x, k, d = map(int, input().split())
    r = 0
    if x > 0 and x > k * d:
        return x - k * d
    elif x < 0 and x < -k * d:
        return x + k * d
    elif x > 0 and x < k * d:
        r = x//d
        if (k - r)%2 == 0:
            return x - r * d
        else:
            return x - (r + 1 ) * d
    elif x < 0 and x < -k * d:
        r = x//d
        if (k + r)%2 == 0:
            return x - r * d
        else:
            return x - (r + 1 ) * d        
    
loc = walking()
print(abs(loc))

Submission status: Runtime Error

Solution code:
S = str(intput())

ans=0

if S[0]=="R":
	if S[1]=="R":
		if S[2]=="R":
			print("3")
		else:
			print("2")
	else:
		print("1")
else:
	if S[1]=="R":
		if S[2]=="R":
			print("2")
		else:
			print("1")

Submission status: Runtime Error

Solution code:
#from functools import lru_cache
import sys
from itertools import product,combinations,accumulate
from functools import reduce,lru_cache
import heapq

def vfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:f(*x,**kwargs),*lst))

def rvfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:rvfunc(f)(*x,**kwargs) if all(vfunc(lambda y:isinstance(y,list))(x)) else f(*x,**kwargs),*lst))

def reader():return vfunc(lambda l:l.split())(sys.stdin.readlines())

s = rvfunc(int)(reader())
n,k=s[0]
p=s[1]
c=s[2]

def pnt(i):
    out = []
    current=i
    for j in range(n):
        current=p[current-1]
        out.append(c[current-1])
    return out
def loc(i):
    out = []
    current=i
    for j in range(n):
        current=p[current-1]
        out.append(current)
    return out
    
def acc(i):    
    p,l=pnt(i),loc(i)
    sp = sum(p)
#    print(p,sp)
    init = l.index(i)
    pini = p[init:]+p[:init]
    last = p[(init+int((k-1)%n))%n]
    plst = p[:last]
    if k+1<n:
        return max(list(accumulate(pini[:k-1])))
    else:
        if sp<0:
            return max(list(accumulate(p)))
        else:
            return max(list(accumulate(p)))+sum(p[:last])+sp*int((k-1)/n)

print(max(vfunc(acc)(range(1,n+1))))

Submission status: Runtime Error

Solution code:
X,K,D = map(int,input().split())
List = []

if abs(X) > K*D:
    print(abs(X) - K*D)
elif K == 1:
    print(min(abs(X-D),abs(X+D)))
elif K == 2:
    print(min(abs(X+D+D),abs(X-D-D),abs(X)))
elif K == 3:
    print(min(abs(X+D+D+D),abs(X+D),abs(X-D),abs(X-D-D-D)))
else:
    for i in range(3):
        if abs(X - D) >= abs(X+D):
            List.append(abs(X+D))
            X = X+D
        else:
            List.append(abs(X-D))
            X = X-D

    for i in range(K-3):
        if List[i] == List[i+2]:
            if K%2 == i%2:
                print(List[i+1])
            else:
                print(List[i])
            break
        else:
            if abs(X - D) >= abs(X+D):
                List.append(abs(X+D))
                X = X+D
            else:
                List.append(abs(X-D))
                X = X-D

    if len(List) == K:
        print(List[K-1])
    else:
        pass

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

s_max = None
for n in range(N):
    s = 0
    p = n + 1
    for k in range(K):

        p = P[p-1]
        s += C[p-1]

        if not s_max:
            s_max = s
        if s > s_max:
            s_max = s


print(s_max)

Submission status: Runtime Error

Solution code:
#from functools import lru_cache
import sys
from itertools import product,combinations,accumulate
from functools import reduce,lru_cache
import heapq

def vfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:f(*x,**kwargs),*lst))

def rvfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:rvfunc(f)(*x,**kwargs) if all(vfunc(lambda y:isinstance(y,list))(x)) else f(*x,**kwargs),*lst))

def reader():return vfunc(lambda l:l.split())(sys.stdin.readlines())

s = rvfunc(int)(reader())
n,k=s[0]
p=s[1]
c=s[2]

def pnt(i):
    out = []
    current=i
    for j in range(n):
        current=p[current-1]
        out.append(c[current-1])
    return out
def loc(i):
    out = []
    current=i
    for j in range(n):
        current=p[current-1]
        out.append(current)
    return out
    
def acc(i):    
    p,l=pnt(i),loc(i)
    sp = sum(p)
    print(p,sp)
    init = l.index(i)
    pini = p[init:]+p[:init]
    last = p[(init+int((k-1)%n))%n]
    plst = p[:last]
    if k+1<n:
        return max(list(accumulate(pini[:k-1])))
    else:
        if sp<0:
            return max(list(accumulate(p)))
        else:
            return max(list(accumulate(p)))+sum(p[:last])+sp*int((k-1)/n)

print(max(vfunc(acc)(range(1,n+1))))

Submission status: Runtime Error

Solution code:
X, K, D = map( int, input().split())
 
Y = X // D
if K <= Y:
  print( min( abs( X - K * D ) , abs( X + K * D ) ))
else:
  if ( K - Y ) % 2 == 0:
    print( min( abs( X - Y * D ) , abs( X + Y * D ) ),
           min( abs( X - ( Y - 2 ) * D ), abs( X - ( Y + 2 ) * D ),
                abs( X + ( Y - 2 ) * D ), abs( X + ( Y + 2 ) * D )) )
  else:
    print( min( abs( X - ( Y - 1 ) * D ), abs( X - ( Y + 1 ) * D ),
                abs( X + ( Y - 1 ) * D ), abs( X + ( Y + 1 ) * D )) )

Submission status: Runtime Error

Solution code:
S = input('天気が雨である日が連続していた最大の日数を出力せよ。')
if S == 'SSS':
	print(0)
else if S == 'SSR':
	print(1)
else if S == 'SRR':
	print(2)
else if S == 'SRS':
	print(1)
else if S == 'RSS':
	print(1)
else if S == 'RRS':
	print(2)
else if S == 'RRR':
	print(3)
else if S == 'RSR':
	print(1)

Submission status: Runtime Error

Solution code:
S = input()

r = 0
for i in range(3):
  if i == 0 and S[0] == 'R':
    r += 1
   elif i < 2:
    if S[i] == S[i+1]:
      r += 1

print(r)

Submission status: Runtime Error

Solution code:
x,k,d = map(int,input().split())
cnt = x//d
mod = x%d
mini = 0

if k < cnt:
    print(x-(d*k))
    exit()

if mod > abs(mod-d):
    mini = abs(mod-d)
    cnt += 1
else:
    mini = mod

if k%2 == 1:
    if cnt%2 == 1:
        print(x-(d*cnt))
    else:
        print(min(abs(mini-d),mini+d))
else:
    if cnt%2 == 0:
        print(x-(d*cnt))
    else:
        print(min(abs(mini-d),mini+d))