Harryxun/stf_run huggingface dataset:
s = input()
k = int(input())

prev = ""
count = 0
flag = 0
for i in s:
    if flag == 1:
        prev = i
        flag = 0
        continue
    if prev == i:
        count += 1
        flag = 1
    prev = i

count2 = 0
if s[0] == s[-1] and s[-1] != s[-2]:
    count2 = 1
ret = count*k + count2*(k-1)

print(ret)

### FIXED CODE ###

s = input()
k = int(input())

prev = ""
count1 = 0
count2 = 0
count3 = 0
flag = 0
for i in s:
    if flag == 1:
        prev = i
        flag = 0
        continue
    if prev == i:
        count1 += 1
        flag = 1
    prev = i



for i in s:
    if flag == 1:
        prev = i
        flag = 0
        continue
    if prev == i:
        count2 += 1
        flag = 1
    prev = i

for i in s:
    if flag == 1:
        prev = i
        flag = 0
        continue
    if prev == i:
        count3 += 1
        flag = 1
    prev = i

if k % 2 == 1:
    ret = count1 + (k-1) // 2 * (count2 + count3)
else:
    ret = count1 + ((k-1)//2+1) * count2 + (k-1)//2 * count3

print(ret)
N,X=map(int,input().split())
above=[0]*N
under=[0]*N
now=0
data=[0]*N
for i in range(N):
    b,l,u=map(int,input().split())
    above[i]=(b*l+(X-b)*u)
    data[i]=(i,b,l,u)
    under[i]=(i,l*b)
    
    now-=l*b
above.sort(key=lambda x:x[1],reverse=True)
idx=0
used=set()
ans=0
while above[idx][1]+now<0:
    now+=above[idx][1]
    used|={above[idx][0]}
    idx+=1
    ans+=X
M=float('inf')
now*=-1
ansM=i
nowM=now
for i in range(N):
    if i in used:
        continue
    b,l,u=data[i]
    M0=(now+l-1)//l
    if M0>b:
        now0=now-l*b
        M0=b+(now0+u-1)//u
        if M0<=X and M0<M:
            M=M0
            ansM=i
            nowM=now0-(M0-b)*u
    elif M0<M:
        M=M0
        ansM=i
        nowM=now-M0*l
ans+=M
nowM*=-1
check=[data[i] for i in used|{ansM}]
check.sort(key=lambda x:x[2])
idx=0
while idx<len(check):
    if nowM-check[idx][2]>=0:
        nowM-=check[idx][2]
        ans-=1
    else:
        idx+=1
print(ans)

### FIXED CODE ###

N,X=map(int,input().split())
data=[0]*N
A=[0]*N
zero=0
for i in range(N):
    b,l,u=map(int,input().split())
    zero-=l*b
    data[i]=(b,l,u)
    A[i]=(i,(X-b)*u+b*l)
A.sort(key=lambda x:x[1],reverse=True)
S=[0]*N
idx=[0]*N
for i,a in enumerate(A):
    S[i]=S[i-1]+a[1]
    idx[a[0]]=i
def check(k):
    q=k//X
    r=k-q*X
    for i in range(N):
        b,l,u=data[i]
        if q==0:
            now=zero
        elif idx[i]<q:
            now=zero+S[q]-A[idx[i]][1]
        else:
            now=zero+S[q-1]
        if r<=b:
            now+=r*l
        else:
            now+=(r-b)*u+b*l
        if now>=0:
            return True
    return False
Mincan=N*X
Maxcant=-1
c=(1,2)
while True:
    if Maxcant+1==Mincan:
        ans=Mincan
        break
    x=N*X*c[0]//c[1]
    if check(x):
        if Mincan>x:
            Mincan=x
            c=(c[0]*2-1,c[1]*2)
    else:
        if Maxcant<x:
            Maxcant=x
            c=(c[0]*2+1,c[1]*2)
print(ans)
N = int(input())
A = list(map(int, input().split(' ')))

cnt = 0

for i in range(1,len(A)):
  if A[i] < A[i-1]:
	cnt += A[i-1] - A[i]
    A[i] = A[i-1]
    
print(cnt)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split(' ')))

lst = A[:]
B = [0]
for i in range(1, len(A)):
  if lst[i] < lst[i-1]:
	  B.append(lst[i-1] - lst[i])
	  lst[i] = lst[i-1]
  else:
    B.append(0)
    
print(sum(B))
n=int(input())
h=list(map(int,input().split()))
hm=max(h)
t=1
ans=0
for i in range(hm,-1,-1):
    for j in range(n):
        if h[j]=i:
            ans+=t
            t=0
        else:
            t=1

print(ans)


### FIXED CODE ###

n=int(input())
h=list(map(int,input().split()))
hm=max(h)

ans=0
for i in range(hm,0,-1):
    t=1
    for j in range(n):
        if h[j]>=i:
            ans+=t
            t=0
        else:
            t=1

print(ans)
n,k=map(int,input().split())
graph=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  graph[a-1].append(b-1)
  graph[b-1].append(a-1)
MOD=10**9+7
def coloring(node,pre):
  if len(graph[node])>k:
    return 0
  if pre==-1:
    color=k-1
  else:
    color=k-2
  ans=1
  for i in graph[node]:
    if i==pre:continue
    ans*=color
    ans%=MOD
    color-=1
  for i in graph[node]:
    if i==pre:continue
    ans*=coloring(i,node)
    ans%=MOD
  return ans
print(k*coloring(0,-1))


### FIXED CODE ###

import sys
sys.setrecursionlimit(10000000)
n,k=map(int,input().split())
graph=[[] for i in range(n)]
for i in range(n-1):
  a,b=map(int,input().split())
  graph[a-1].append(b-1)
  graph[b-1].append(a-1)
MOD=10**9+7
def coloring(node,pre):
  if len(graph[node])>k:
    return 0
  if pre==-1:
    color=k-1
  else:
    color=k-2
  ans=1
  for i in graph[node]:
    if i==pre:continue
    ans*=color
    ans%=MOD
    color-=1
  for i in graph[node]:
    if i==pre:continue
    ans*=coloring(i,node)
    ans%=MOD
  return ans
print((k*coloring(0,-1))%MOD)
N = input()
print(N*(N-1)//2-(3*(N//3)+5*(N//5))+15*(N//15))

### FIXED CODE ###

print("Yes" if("7"in input())else"No")
n = int(input())
x,y,h = map(int, input().split())

ab = [list(map(int, input().split())) for _ in range(n-1)]

for i in range(101):
    for j in range(101):
        res = [abs(i-x)+abs(j-y)+h]
        f = False
        for k in range(n-1):
            dx = ab[k][0]
            dy = ab[k][1]
            dh = ab[k][2]
            res.append(abs(i-dx)+abs(j-dy)+dh)
        if len(set(res)) == 1:
            ansx =i
            ansy =j
            ansr = res[0]
            break
        
print(str(ansx)+" "+str(ansy)+" "+str(ansr))

### FIXED CODE ###

n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]

for _ in range(0,n):
    if ab[_][2] !=0:
        x = ab[_][0]
        y = ab[_][1]
        h = ab[_][2]
        break

for i in range(101):
    for j in range(101):
        f = True
        l = abs(i-x)+abs(j-y)+h
        for k in range(0,n):
            dx = ab[k][0]
            dy = ab[k][1]
            dh = ab[k][2]
            if max(l-abs(i-dx)-abs(j-dy),0) ==dh:
                pass
            else:
                f = False
        if f:
            ansx =i
            ansy =j
            ansr = l
            break
print(str(ansx)+" "+str(ansy)+" "+str(ansr))
def main():
    h, n = map(int, input().split())
    magic_list = []

    for _ in range(n):
        a, b = map(int, input().split())
        magic_list.append((a, b))

    ans = solve(h, magic_list)
    print(ans)


def solve(h, magic_list):
    # 1-origin
    dp = [0] * (h + 1)

    # time O(HN)
    for hp in range(1, h + 1):
        dp[hp] = min(dp[hp - attack] + mp for attack, mp in magic_list)

    return dp[h]


main()


### FIXED CODE ###

def main():
    h, n = map(int, input().split())
    magic_list = []

    for _ in range(n):
        a, b = map(int, input().split())
        magic_list.append((a, b))

    ans = solve(h, magic_list)
    print(ans)


def solve(h, magic_list):
    # 1-origin
    inf = 1 << 40
    max_attack = max(magic_list)[0]
    dp = [inf] * (h + max_attack)
    dp[0] = 0

    # time O(HN)
    for hp in range(1, h + max_attack):
        for attack, mp in magic_list:
            if hp >= attack and dp[hp - attack] < inf:
                dp[hp] = min(dp[hp], dp[hp - attack] + mp)

    return min(dp[h:])


main()
from math import gcd
a,b=map(int,input().split())
print(a*b//gcd(a,b))


### FIXED CODE ###

from fractions import gcd
a,b=map(int,input().split())
print(a*b//gcd(a,b))
n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse=True)
if A[m]<sum(A)/4/m:
    print('No')
else:
    print('Yes')

### FIXED CODE ###

n,m = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse=True)
if A[m-1]<sum(A)/4/m:
    print('No')
else:
    print('Yes')
int_a, int_b, int_k = map(int, input().split())

ar = list(range(int_a, int_b + 1))

minset = set(range(int_a, int_a + int_k + 1))
maxset = set(range(int_b - int_k + 1, int_b + 1))

result = list(minset | maxset)
result.sort()
for i in result:
    if int_a <= i <= int_b:
        print(i)



### FIXED CODE ###

int_a, int_b, int_k = map(int, input().split())

minset = set(range(int_a, int_a + int_k))
maxset = set(range(int_b - int_k + 1, int_b + 1))

result = list(minset | maxset)
result.sort()
for i in result:
    if int_a <= i <= int_b:
        print(i)
import sys; from collections import deque; readline = sys.stdin.readline

H, W, A, B = map(int, readline().split())

#for s in range(W):
#    a = (H - 2*B) * s + W*B - H*A
#    b = W - 2*A
#    if a % b == 0 and a // b >= 0:
#        t = a // b
#        break
#
#if s == W:
#    print('No')
#else:
#    count = []

for y in range(B):
    print(''.join([1]*A + [0]*(W-A)))

for y in range(B, H):
    print(''.join([0]*A + [1]*(W-A))

### FIXED CODE ###

import sys; from collections import deque; readline = sys.stdin.readline

H, W, A, B = map(int, readline().split())

#for s in range(W):
#    a = (H - 2*B) * s + W*B - H*A
#    b = W - 2*A
#    if a % b == 0 and a // b >= 0:
#        t = a // b
#        break
#
#if s == W:
#    print('No')
#else:
#    count = []

for y in range(B):
    print(''.join(map(str, [1]*A + [0]*(W-A))))

for y in range(B, H):
    print(''.join(map(str, [0]*A + [1]*(W-A))))
S = input()
len(S)=p
t=0
for n in range(p):
  if S[n]!=S[p-n-1]:
    t+=1
print(t/2)

### FIXED CODE ###

S = input()
p=len(S)
t=0
for n in range(p):
  if S[n]!=S[p-n-1]:
    t+=1
print(int(t/2))
n,k=map(int,input().split())
l1=list(map(int.input().split()))
l1.sort()
price = 0
for i in range(n-1):
  if l1[i]!=l1[i+1]:
    price+=l1[i]
print(price)    
    

### FIXED CODE ###

N, K = map(int, input().split())
p = list(map(int, input().split()))
print(sum(sorted(p)[:K]))
# import math
# import numpy as np

# n, m = 4,4
# a_list = np.array([1,9,3,5])
n = int(input())
s = input()

ct = 0
ct_max = 0
for i in range(1,n):
    if(ct_max >= n-i)
    
    forward = s[:n-i]
    back = s[i:]
    for j in range(n-i):
        f = forward[j]
        b = back[j]
        if(f==b):
            ct += 1
            if(ct_max < ct):
                ct_max = ct*1
            if(ct_max >= i):
                break()
        else:
            ct = 0

print(ct_max)

### FIXED CODE ###

# import numpy as np

n = int(input())
s = input()

# dp = np.zeros([n+1, n+1])
dp = [0] * (n+1)

for dif in range(1,n):
    count = 0
    t_max = 0
    for l1_r in range(0, n-dif):
        if(s[l1_r] == s[l1_r + dif]):
            count += 1
            t_max = max(count, t_max)
            if( count == dif):
                dp[dif] = count
                break
        else:
            count = 0
    dp[dif] = t_max

print(max(dp))
import math
N,K=map(int,input().split())

sum=0
for deme in range(1,N+1):
    need_challenge=max(0,math.ceil(math.log2(K)-math.log2(deme)))
    sum+=float((1/N)*((1/2)**need_challenge))
print('{:.13f}'.format(sum))

### FIXED CODE ###

import math
N,K=map(int,input().split())

sum=0
for deme in range(1,N+1):
    need_challenge=max(0,math.ceil(math.log2(K)-math.log2(deme)))
    sum+=float((1/N)*((1/2)**need_challenge))
print('{:.13f}'.format(sum))
import fractions
n = int(input())
l = [int(input()) for _ in range(n)]
ans = l[i]
for i in range(n):
  ans = ans * l[i] // fractions.gcd(ans, l[i])
print(ans)

### FIXED CODE ###

import fractions
n = int(input())
l = [int(input()) for _ in range(n)]
ans = l[0]
for i in range(n):
  ans = ans * l[i] // fractions.gcd(ans, l[i])
print(ans)
while True:
  inl=map(int, raw_input().split())

  if inl==[]:
  	break
  num=inl[0]+inl[1]
  a=list(str(num))

  time=0
  for i in a:
    time+=1

  print time

### FIXED CODE ###

import sys

a = []
for line in sys.stdin:
    a.append(line)

for n in a:
    inl=n.split()
    num=int(inl[0])+int(inl[1])
    l=list(str(num))
    time=0
    for i in l:
        time+=1
    print time
N, K = map(int, input().split)
a = list(map(int, input().split))
count = 0
for i in range(len(a)):
  if a[i] >= K:
    count += 1
print(count)

### FIXED CODE ###

N, K = map(int, input().split())
a = list(map(int, input().split()))
count = 0
for i in range(len(a)):
    if a[i] >= K:
        count += 1
print(count)
#Stringの場合
s, t = input().split()
a,b = map(int,input().split())
u = input()

if u == s:
     print (f"{a-1} {b}")
else:
    print(f"{a} {b-1}") 


### FIXED CODE ###

S,T=input().split()
A,B=map(int,input().split())
U = input()
if U == S:
    print('{} {}'.format(A-1, B))
else:
    print('{} {}'.format(A, B-1))
import numpy as np
N = int(input())
A = list(map(int,input().split()))
#output = np.prod(A)
AA=1
for i in range(N+1):
  #print(A[i])
  AA = AA * A[i]
a = pow(10,18)
print(AA if abs(AA) <= a else -1)

### FIXED CODE ###

import sys
N = int(input())
A = list(map(int,input().split()))
A.sort()
mul = A[0]
for i in range(1,N):
  mul *= A[i]
  if mul > 10**18:
    print(-1)
    sys.exit()
print(mul)
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

n,k = map(int,readline().split())
mod = 10**9+7
g = [[] * n for i in range(n)]
for i in range(n-1):
    u, v = map(int,readline().split())
    u -= 1
    v -= 1
    g[u].append(v)
    g[v].append(u)

ans = 1
used = [False]*n
def dfs(now,prev,p):
    global ans
    if k <= p:
      ans = 0
    ans *= k-p
    ans %= mod
    used[now] == True
    if all(used):
      return ans
    cnt = 1
    new = []
    for next in g[now]:
      if next == prev:
        cnt += 1
      else:
        new.append(next)
    for i,next in enumerate(new):
      dfs(next,now,cnt+i)
      
dfs(0,-1,0)
print(ans)


### FIXED CODE ###

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
mod = 10**9+7
sys.setrecursionlimit(4100000)
n,k = map(int,readline().split())
if n == 1:
  print(k%mod)
  exit()

g = [[] * n for i in range(n)]
for i in range(n-1):
    u, v = map(int,readline().split())
    u -= 1
    v -= 1
    g[u].append(v)
    g[v].append(u)

ans = 1
used = [False]*n
def dfs(now,prev,p):
    global ans
    if k <= p:
      ans = 0
    ans *= k-p
    ans %= mod
    used[now] == True
    if all(used):
      return ans
    cnt = 1
    new = []
    for next in g[now]:
      if next == prev:
        cnt += 1
      else:
        new.append(next)
    for i,next in enumerate(new):
      dfs(next,now,cnt+i)
      
dfs(0,-1,0)
print(ans)
a, b = map(int, input().split())
print(a*b, 2*(a+b))

### FIXED CODE ###

print(int(input())**3)
n = int(input())
ans = [0 for _ in range(1001)]
for i in range(1, 40):
    for j in range(1, 40):
        for k in range(1, 40):
            summ = i**2 + j**2 + k**2 + i * j + j * k + k * i
            if summ < 1001:
                ans[summ] += 1

for i in range(1, n):
    print(ans[i])


### FIXED CODE ###

n = int(input())
ans = [0 for _ in range(10001)]
for i in range(1, 100):
    for j in range(1, 100):
        for k in range(1, 100):
            summ = i**2 + j**2 + k**2 + i * j + j * k + k * i
            if summ < 10001:
                ans[summ] += 1

for i in range(1, n + 1):
    print(ans[i])
# print(ans[20])
N=int(input())
a=list(map(int,input().split()))
b=sorted(a)
ans1=sum(b[N:2*N])

ans2=0
for i in range(N):
    ans2 += b[i*3+1]

ans3=0
for i in range(N):
    ans3 += b[i*2+4]

print(max(ans1,ans2,ans3))

### FIXED CODE ###

N=int(input())
a=list(map(int,input().split()))
b=sorted(a)

ans3=0
for i in range(N):
    ans3 += b[i*2+N]

print(ans3)
import math


# 素数の判定
def is_prime(n):
    if n == 1:
        return 0

    for k in range(2, int(math.sqrt(n)) + 1):
        chk = False
        while (n % k == 0):
            chk = True
            n /= k
            if k not in check:
                check[k] = 1
            else:
                check[k] += 1
        if chk:
            return n
    if n in check:
        return 0
    else:
        check[n] = 1
        return 1


check = {}
n = int(input())
if n == 1:
    print(0)
else:
    while (1):
        n = is_prime(n)
        if n == 0:
            break
    ans = 0
    for k, v in check.items():
        for i in range(1, 50):
            v -= i
            if v < 0:
                break
            else:
                ans += 1
# print(check)
print(ans)


### FIXED CODE ###

import math


# 素数の判定
def is_prime(n):
    if n == 1:
        return 0

    for k in range(2, int(math.sqrt(n)) + 1):
        chk = False
        while (n % k == 0):
            chk = True
            n /= k
            if k not in check:
                check[k] = 1
            else:
                check[k] += 1
        if chk:
            return n
    if n in check:
        return 0
    else:
        check[n] = 1
        return 1


check = {}
n = int(input())
if n == 1:
    print(0)
else:
    while (1):
        n = is_prime(n)
        if n == 0:
            break
    ans = 0
    for k, v in check.items():
        for i in range(1, 50):
            v -= i
            if v < 0:
                break
            else:
                ans += 1
    # print(check)
    print(ans)
N = int(input())
X = list(map(int,input().split()))
X_sort = sorted(X)
N_half = int(N/2)
median_large = X_sort[N_half+1]
median_small = X_sort[N_half]
if median_large == median_small:
    for _ in range(N):
        print(median_large)
else:
    for i in range(N):
        if X[i] <= median_small:
            print(median_large)
        elif X[i] >= median_large:
            print(median_small)

### FIXED CODE ###

N = int(input())
X = list(map(int,input().split()))
X_sort = sorted(X)
N_half = int(N/2)
median_large = X_sort[N_half]
median_small = X_sort[N_half-1]
if median_large == median_small:
    for _ in range(N):
        print(median_large)
else:
    for i in range(N):
        if X[i] <= median_small:
            print(median_large)
        elif X[i] >= median_large:
            print(median_small)
a, b = map(int, raw_input().split())
b - a = x
sum = 0
for i in range(1, x+1):
	sum += i
print sum - b

### FIXED CODE ###

a, b = map(int, raw_input().split())
x = b - a
sum = 0
for i in range(1, x+1):
	sum += i
print sum - b
n,l=map(int,input().split())
list=[]
for _ in range(n):
    list.append(str(input())

list.sort()
ans=""
for i in list:
    ans+=i
print(ans)

### FIXED CODE ###

n,l=map(int,input().split())
list=[]
for _ in range(n):
    list.append(input())
 
list.sort()
ans=""
for i in list:
    ans+=i
print(ans)
# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])

    link = {}
    for ab in args[1:]:
        a, b = map(int, ab.split())
        if a in link:
            link[a].append(b)
        else:
            link[a] = [b]
        if b in link:
            link[b].append(a)
        else:
            link[b] = [a]

    color = [0]*n

    color[0] = 1
    seek(1, 0, color, link)

    return '\n'.join(map(str, color))


def seek(i: int, parent: int, color: list, link: dict):
    c = 1
    for node in link[i]:
        if node == parent:
            continue

        if c == color[i-1]:
            c += 1
        color[node-1] = c
        c += 1
        seek(node, i, color, link)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


### FIXED CODE ###

# coding: utf-8


def solve(*args: str) -> str:
    n = int(args[0])

    link = [set() for _ in range(n+1)]
    edge = []

    for i, ab in enumerate(args[1:]):
        a, b = sorted(map(int, ab.split()))
        edge.append((a, b))
        link[a].add(b)
        link[b].add(a)

    n_color = max(map(len, link))

    color = {}

    queue = [(0, 1)]

    while queue:
        parent, cur = queue.pop()
        used = color[tuple(sorted((parent, cur)))] if 0 < parent else 0
        c = 1

        for child in link[cur]:
            if child == parent:
                continue

            if c == used:
                c += 1
            color[tuple(sorted((cur, child)))] = c
            c += 1

            queue.append((cur, child))

    return str(n_color) + '\n' \
        + '\n'.join(map(str, (color[ab] for ab in edge)))


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))
a

### FIXED CODE ###

from collections import Counter

n = int(input())
d = list(map(int, input().split()))

minD = min(d)
maxD = max(d)
c = Counter(d)

abc = 0
arc = n
ans = 0

for i in range(minD, maxD+1):
    abc += c[i-1]
    arc -= c[i-1]
    
    if abc == arc:
        ans += 1

print(ans)
# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/

import math
import statistics

s = input()
ans = 0
for i in range(n):
  for j in range(i, n):
    if all('ACGT'.count(c) == 1 for c in s[i : j + 1]):
      ans = max(ans, j - i + 1)
print(ans)


### FIXED CODE ###

# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/

import math
import statistics

s = input()
length = 0
ans = 0
for ch in s:
    if ch in ('A','C','G','T'):
        length += 1
        ans = max(ans, length)
    else:
        length = 0
print(ans)
#include <list>
#include <string>
using namespace std;
#define ll long long
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    string com;
    int key;
    list<ll> lst;
    list<ll>::iterator it,i=lst.end();
    while(n--){
        cin>>com;
        if(com=="insert"){
            cin>>key;
            lst.push_front(key);
        }
        else if(com=="delete"){
            cin>>key;
            for(it=lst.begin();it!=i;it++){
                if(*it==key){
                    lst.erase(it);
                    break;
                }
            }
        }
        else if(com=="deleteFirst") lst.pop_front();
        else                        lst.pop_back();
         
    }
    i--;
    for(it=lst.begin();it!=i;it++)  cout<<*it<<" ";
    cout<<*i<<"\n";
    return 0;
}
Compile Error Logs:


ステータス
Judge: 10/10
C++
CPU: 00:32 sec
Memory: 32472 KB
Length: 637 B
2015-03-23 23:30
テストケースの判定結果
Case #
Verdict
CPU Time
Memory
In
Out
Case Name
Case #1
: Accepted
00:00
1216
88
2
01.in
Case #2
: Accepted
00:00
1216
203
10
02.in
Case #3
: Accepted
00:00
1216
375
10
03.in
Case #4
: Accepted
00:00
1216
105
23
04.in
Case #5
: Accepted
00:00
1212
643
58
05.in
Case #6
: Accepted
00:00
1216
52
2
06.in
Case #7
: Accepted
00:00
1216
1058
110
07.in
Case #8
: Accepted
00:00
1216
1031
116
08.in
Case #9
: Accepted
00:28
1220
22392494
5
09.in
Case #10
: Accepted
00:32
32472
25527813
1288799
10.in
< prev |

/ 

| next > 
 


 
Judge Input #  ( | )

Judge Output #  ( | )






### FIXED CODE ###


import sys
     
A=[]
fp =0
bp =0
 
n=int(raw_input())
while n:
    s = raw_input()
    if s[0] == 'i':
        A.append(int(s[7:]))
        fp += 1
    elif s[6] == ' ':
        try:
            i = A[::-1].index(int(s[7:]))
            if i!=-1:
                del A[-i-1]
                fp -=1
        except:
            pass
    elif s[6] == 'F':
        A.pop()
        fp -=1
    elif s[6] == 'L':
        bp +=1
    n -=1
 
for e in A[bp:fp+1][::-1]:
    print int(e),
N, M = map(int, input().split())
cake = [list(map(int, input().split())) for _ in range(N)]

INF = 10 ** 18
dp = [[[-INF] * 8 for _ in range(M + 1)] for _ in range(N + 1)]
for i in range(8):
    dp[0][0][i] = 0

for i in range(1, N + 1):
    x, y, z = cake[i - 1]
    for j in range(1, i + 1):
        for msk in range(8):
            mx = x * (1 - 2 * (msk >> 2 & 1))
            my = y * (1 - 2 * (msk >> 1 & 1))
            mz = z * (1 - 2 * (msk >> 0 & 1))
            dp[i][j][msk] = max(dp[i - 1][j][msk],
                                dp[i - 1][j - 1][msk] + mx + my + mz)

print(max(dp[N][M][i] for i in range(8)))

### FIXED CODE ###

N, M = map(int, input().split())
cake = [list(map(int, input().split())) for _ in range(N)]

INF = 10 ** 18
dp = [[[-INF] * 8 for _ in range(M + 1)] for _ in range(N + 1)]
for i in range(N + 1):
    for msk in range(8):
        dp[i][0][msk] = 0

for i in range(1, N + 1):
    x, y, z = cake[i - 1]
    for j in range(1, M + 1):
        for msk in range(8):
            mx = x * (1 - 2 * (msk >> 2 & 1))
            my = y * (1 - 2 * (msk >> 1 & 1))
            mz = z * (1 - 2 * (msk >> 0 & 1))
            dp[i][j][msk] = max(dp[i - 1][j][msk],
                                dp[i - 1][j - 1][msk] + mx + my + mz)

print(max(dp[N][M][i] for i in range(8)))