Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
def solve(N, M, A):
    MOD = 10**9 + 7
    A = set(A)
    if N == 1:
        return 1

    dp = [0] * (N+1)
    dp[0] = 1
    dp[1] = 1 if 1 not in A else 0
    for i in range(2, N+1):
        if i in A:
            dp[i] = 0
        else:
            dp[i] = (dp[i-2] + dp[i-1]) % MOD
    return dp[-1]


N, M = map(int, input).split())
A = [int(input()) for _ in range(M)]
ans = solve(N, M, A)
print(ans)



Fixed submission:
# -*- coding: utf-8 -*-
"""



"""
import sys


def solve(N, M, A):
    MOD = 10**9 + 7
    A = set(A)
    dp = [0] * (N+1)
    dp[0] = 1
    dp[1] = 1 if 1 not in A else 0
    for i in range(2, N+1):
        if i in A:
            dp[i] = 0
        else:
            dp[i] = (dp[i-2] + dp[i-1]) % MOD
    return dp[-1]


def main(args):
    N, M = map(int, input().split())
    A = [int(input()) for _ in range(M)]
    ans = solve(N, M, A)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
C - Unification
https://atcoder.jp/contests/abc120/tasks/abc120_c

"""
import sys
import re


def my_sub(m):
    len1 = len(m.group(1))
    len2 = len(m.group(2))
    if len1 > len2:
        return m.group(1)[0] * (len1 - len2)
    return m.group(2)[0] * (len2 - len1)


def solve(S):
    orig_len = len(S)
    while True:
        t = re.sub(r'(0+)(1+)', my_sub, S)
        t = re.sub(r'(1+)(0+)', my_sub, t)
        if t == S:
            break
        S = t
    return orig_len - len(S)


def main(args):
    S = input()
    ans = solve(S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Fixed submission:
# -*- coding: utf-8 -*-
"""
C - Unification
https://atcoder.jp/contests/abc120/tasks/abc120_c

"""
import sys


def solve(S):
    orig_len = len(S)
    num_value = {'0': -1, '1': 1}
    status = 0

    for s in S:
        status += num_value[s]
        #if s == '0':
        #    status -= 1
        #else:
        #    status += 1
    return orig_len - abs(status)


def main(args):
    S = input()
    ans = solve(S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
C - Unification
https://atcoder.jp/contests/abc120/tasks/abc120_c

"""
import sys
import re


def my_sub(m):
    len1 = len(m.group(1))
    len2 = len(m.group(2))
    if len1 > len2:
        return m.group(1) * (len1 - len2)
    return m.group(2) * (len2 - len1)


def solve(S):
    orig_len = len(S)
    while True:
        t = re.sub(r'01', '', S)
        t = re.sub(r'10', '', t)
        if t == S:
            break
        S = t
    return orig_len - len(S)


def main(args):
    S = input()
    ans = solve(S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Fixed submission:
# -*- coding: utf-8 -*-
"""
C - Unification
https://atcoder.jp/contests/abc120/tasks/abc120_c

"""
import sys


def solve(S):
    orig_len = len(S)
    num_value = {'0': -1, '1': 1}
    status = 0

    for s in S:
        status += num_value[s]
        #if s == '0':
        #    status -= 1
        #else:
        #    status += 1
    return orig_len - abs(status)


def main(args):
    S = input()
    ans = solve(S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
D - Lazy Faith
https://atcoder.jp/contests/abc119/tasks/abc119_d

"""
import sys
from bisect import bisect_left, bisect_right

def solve(x):
    i = bisect_right(shrines, x)
    ds = x - shrines[i-1]
    j = bisect_right(temples, x)
    dt = x - temples[j-1]
    ans1 = max(ds, dt)

    i = bisect_left(shrines, x)
    ds = shrines[i] - x
    j = bisect_left(temples, x)
    dt = temples[j] - x
    ans2 = max(ds, dt)

    i = bisect_left(shrines, x)
    ds = shrines[i] - x
    j = bisect_right(temples, x)
    dt = x - temples[j-1]
    ans3 = min(ds, dt) * 2 + max(ds, dt)

    i = bisect_right(shrines, x)
    ds = x - shrines[i-1]
    j = bisect_left(temples, x)
    dt = temples[j] - x
    ans4 = min(ds, dt) * 2 + max(ds, dt)

    return min(ans1, ans2, ans3, ans4)


shrines = None
temples = None

def main(args):
    global shrines, temples
    A, B, Q = map(int, input().split())
    shrines = sorted([int(input()) for _ in range(A)] + [float('-inf'), float('inf')])
    temples = sorted([int(input()) for _ in range(B)] + [float('-inf'), float('inf')])
    for _ in range(Q):
        x = int(input())
        ans = solve(x)
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Fixed submission:
# -*- coding: utf-8 -*-
"""
D - Lazy Faith
https://atcoder.jp/contests/abc119/tasks/abc119_d

"""
import sys
from bisect import bisect_left, bisect_right

def solve(shrines, temples, x):
    i = bisect_right(shrines, x)
    ds = x - shrines[i-1]
    j = bisect_right(temples, x)
    dt = x - temples[j-1]
    ans = max(ds, dt)

    i = bisect_left(shrines, x)
    ds = shrines[i] - x
    j = bisect_left(temples, x)
    dt = temples[j] - x
    ans = min(ans, max(ds, dt))

    i = bisect_left(shrines, x)
    ds = shrines[i] - x
    j = bisect_right(temples, x)
    dt = x - temples[j-1]
    d = min(ds, dt) * 2 + max(ds, dt)
    ans = min(ans, d)

    i = bisect_right(shrines, x)
    ds = x - shrines[i-1]
    j = bisect_left(temples, x)
    dt = temples[j] - x
    d = min(ds, dt) * 2 + max(ds, dt)
    ans = min(ans, d)

    return ans


def main(args):
    A, B, Q = map(int, input().split())
    shrines = sorted([int(input()) for _ in range(A)] + [float('-inf'), float('inf')])
    temples = sorted([int(input()) for _ in range(B)] + [float('-inf'), float('inf')])
    for _ in range(Q):
        x = int(input())
        ans = solve(shrines, temples, x)
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""


"""


def chmin(i, j):
    a, b = dp[i+j], dp[i]+abs(h[i]-h[i+j])
    if a > b:
        dp[i+j] = b


n, k = map(int, (input().split()))
h = list(input().split())
h = [int(i) for i in h]
dp = [10**10]*n
dp[0] = 0
for i in range(0, n):
    for j in range(1, k+1):
        if i+j < n:
            chmin(i, j)
print(dp[n-1])

Fixed submission:
# -*- coding: utf-8 -*-
"""
B - Frog 2
https://atcoder.jp/contests/dp/tasks/dp_b

"""
import sys
from sys import stdin


def solve(ashiba, N, K):
    dp = [float('inf')] * N
    dp[0] = 0
    for i in range(1, len(ashiba)):
        paths = [dp[j]+abs(ashiba[j]-ashiba[i]) for j in range(max(0, i-K), i)]
        dp[i] = min(paths)
    return dp[-1]


def main(args):
    N, K = map(int, input().split())
    ashiba = [int(i) for i in input().split()]
    ans = solve(ashiba, N, K)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
B - Frog 2
https://atcoder.jp/contests/dp/tasks/dp_b

"""
import sys
from sys import stdin


def solve(ashiba, N, K):
    dp = [float('inf')] * N
    dp[0] = 0
    for i in range(1, len(ashiba)):
        for j in range(max(0, i-K), i):
            dp[i] = min(dp[i], dp[j]+abs(ashiba[j]-ashiba[i]))
    return dp[-1]


def main(args):
    N, K = map(int, input().split())
    ashiba = [int(i) for i in input().split()]
    ans = solve(ashiba, N, K)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Fixed submission:
# -*- coding: utf-8 -*-
"""
B - Frog 2
https://atcoder.jp/contests/dp/tasks/dp_b

"""
import sys
from sys import stdin


def solve(ashiba, N, K):
    dp = [float('inf')] * N
    dp[0] = 0
    for i in range(1, len(ashiba)):
        paths = [dp[j]+abs(ashiba[j]-ashiba[i]) for j in range(max(0, i-K), i)]
        dp[i] = min(paths)
    return dp[-1]


def main(args):
    N, K = map(int, input().split())
    ashiba = [int(i) for i in input().split()]
    ans = solve(ashiba, N, K)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
D - Knapsack 1
https://atcoder.jp/contests/dp/tasks/dp_d

"""
import sys


def solve(N, W, items):
    dp = [0-1] * (W+1)
    dp[0] = 0
    for w, v in items:
        for i in range(W, w-1, -1):
            if dp[i-w] != -1:
                dp[i] = max(dp[i], dp[i-w]+v)
    return max(dp)



def main(args):
    N, W = map(int, input().split())
    items = [[int(i) for i in input().split()] for _ in range(N)]
    ans = solve(N, W, items)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Fixed submission:
# -*- coding: utf-8 -*-
"""
D - Knapsack 1
https://atcoder.jp/contests/dp/tasks/dp_d

"""
import sys


def solve(N, W, items):
    ans = {0: 0}
    for w, v in items:
        u = dict()
        for x, y in ans.items():
            if x+w <= W and ans.get(x+w, 0) < y+v:
                u[x+w] = y+v
        ans.update(u)
    return max([v for v in ans.values()])


def main(args):
    N, W = map(int, input().split())
    items = [[int(i) for i in input().split()] for _ in range(N)]
    ans = solve(N, W, items)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
D - Knapsack 1
https://atcoder.jp/contests/dp/tasks/dp_d

"""
import sys


def solve(N, W, items):
    ans = {0: 0}
    for w, v in items:
        u = dict()
        for x, y in ans.items():
            if x+w <= W and ans.get(x+w, 0) < y+v:
                u[x+w] = y+v
        ans.update(u)
    return max([v for v in ans.values()])


def main(args):
    N, W = map(int, input().split())
    items = [[int(i) for i in input().split()] for _ in range(N)]
    ans = solve(N, W, items)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Fixed submission:
# -*- coding: utf-8 -*-
"""
D - Knapsack 1
https://atcoder.jp/contests/dp/tasks/dp_d

"""
import sys


def solve(N, W, items):
    ans = {0: 0}
    for w, v in items:
        u = dict()
        for x, y in ans.items():
            if x+w <= W and ans.get(x+w, 0) < y+v:
                u[x+w] = y+v
        ans.update(u)
    return max([v for v in ans.values()])


def main(args):
    N, W = map(int, input().split())
    items = [[int(i) for i in input().split()] for _ in range(N)]
    ans = solve(N, W, items)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
E - Knapsack 2
https://atcoder.jp/contests/dp/tasks/dp_e

"""
import sys


def solve(N, W, items):
    limit = 0
    for w, v in items:
        limit += v
    dp = [float('inf')] * (limit+1)
    dp[0] = 0
    for w, v in items:
        for i in range(limit, -1, -1):
            if dp[i] != float('inf') and dp[i]+w <= W:
                dp[i+v] = min(dp[i+v], dp[i]+w)

    ans = [i for i, d in enumerate(dp) if d != float('inf')]
    return max(ans)


def main(args):
    N, W = map(int, input().split())
    items = [[int(i) for i in input().split()] for _ in range(N)]
    ans = solve(N, W, items)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Fixed submission:
# -*- coding: utf-8 -*-
"""
E - Knapsack 2
https://atcoder.jp/contests/dp/tasks/dp_e

"""
import sys


def solve(N, W, items):
    limit = 0
    for w, v in items:
        limit += v
    dp = [float('inf')] * (limit+1)
    dp[0] = 0
    for w, v in items:
        for i in range(limit, -1, -1):
            if dp[i] != float('inf') and dp[i]+w <= W:
                dp[i+v] = min(dp[i+v], dp[i]+w)

    ans = [i for i, d in enumerate(dp) if d != float('inf')]
    return max(ans)


def main(args):
    N, W = map(int, input().split())
    items = [[int(i) for i in input().split()] for _ in range(N)]
    ans = solve(N, W, items)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
E - Knapsack 2


"""
import sys


def solve(N, W, items):
    dp = {0: 0}
    for w, v in items:
        u = dict()
        for x, y in dp.items():
            if x+w <= W and dp.get(x+w, 0) < y+v:
                u[x+w]= y+v
        dp.update(u)
    return max([v for v in dp.values()])


def main(args):
    N, W = map(int, input().split())
    items = [[int(i) for i in input().split()] for _ in range(N)]
    ans = solve(N, W, items)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Fixed submission:
# -*- coding: utf-8 -*-
"""
E - Knapsack 2
https://atcoder.jp/contests/dp/tasks/dp_e

"""
import sys


def solve(N, W, items):
    limit = 0
    for w, v in items:
        limit += v
    dp = [float('inf')] * (limit+1)
    dp[0] = 0
    for w, v in items:
        for i in range(limit, -1, -1):
            if dp[i] != float('inf') and dp[i]+w <= W:
                dp[i+v] = min(dp[i+v], dp[i]+w)

    ans = [i for i, d in enumerate(dp) if d != float('inf')]
    return max(ans)


def main(args):
    N, W = map(int, input().split())
    items = [[int(i) for i in input().split()] for _ in range(N)]
    ans = solve(N, W, items)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
F - LCS
https://atcoder.jp/contests/dp/tasks/dp_f

"""
import sys


def solve(s, t):
    n, m = len(s), len(t)
    dp = [[0] * (m + 1) for _ in range(n + 1)]
    for i in range(n):
        for j in range(m):
            if s[i] == t[j]:
                dp[i+1][j+1] = dp[i][j] + 1
            else:
                dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])
    ans = []
    y, x = n, m
    lcs = dp[y][x]
    while x > 0 or y > 0:
        if y-1 >= 0 and dp[y-1][x] == lcs:
            y -= 1
        elif x-1 >= 0 and dp[y][x-1] == lcs:
            x -= 1
        else:
            y -= 1
            x -= 1
            ans.append(s[y])
            lcs -= 1
    return ''.join(ans[::-1])


def main(args):
    s = input()
    t = input()
    ans = solve(s, t)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Fixed submission:
# -*- coding: utf-8 -*-
"""
F - LCS
https://atcoder.jp/contests/dp/tasks/dp_f

"""
import sys


def solve(s, t):
    n, m = len(s), len(t)
    dp = [[0] * (m + 1) for _ in range(n + 1)]
    for i in range(n):
        for j in range(m):
            if s[i] == t[j]:
                dp[i+1][j+1] = dp[i][j] + 1
            else:
                dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1])
    ans = []
    y, x = n, m
    lcs = dp[y][x]
    while x > 0 or y > 0:
        if y-1 >= 0 and dp[y-1][x] == lcs:
            y -= 1
        elif x-1 >= 0 and dp[y][x-1] == lcs:
            x -= 1
        else:
            y -= 1
            x -= 1
            ans.append(s[y])
            lcs -= 1
    return ''.join(ans[::-1])


def main(args):
    s = input()
    t = input()
    ans = solve(s, t)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
C - 755

"""
def gen_357():
    def conv(n):
        res = []
        while n:
            n, r = divmod(n, 4)
            res.append(str(str(r)))
        if not res:
            res = ['0']
        return ''.join(res[::-1]).translate(str.maketrans('0123', '0357'))

    n = 0
    while True:
        t = conv(n)
        while '0' in t or len(set(list(t))) != 3:
            n += 1
            t = conv(n)
        yield t
        n += 1


def solve(n):
    ans = 0
    g = gen_357()
    while True:
        t = next(g)
        if int(t) > n:
            break
        ans += 1
    return ans


n = int(input())
ans = solve(n)
print(ans)


Fixed submission:
# -*- coding: utf-8 -*-
"""
C - 755
TLE
"""
def gen_357():
    def conv(n):
        res = []
        while n:
            n, r = divmod(n, 4)
            if r == 0 and n:
                return '0'
            res.append(str(str(r)))
        if not res:
            res = ['0']
        return ''.join(res[::-1]).translate(str.maketrans('0123', '0357'))

    n = 0
    while True:
        t = conv(n)
        while '0' in t or len(set(list(t))) != 3:
            n += 1
            t = conv(n)
        yield t
        n += 1


def solve(n):
    ans = 0
    g = gen_357()
    while True:
        t = next(g)
        if int(t) > n:
            break
        ans += 1
    return ans


n = int(input())
ans = solve(n)
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# -*- coding: utf-8 -*-
"""
C - 755

"""
import sys


from itertools import product

def gen_357():
    def conv(n):
        res = []
        while n:
            n, r = divmod(n, 4)
            res.append(r)
        t = list(map(str, res[::-1]))
        if not t: t = ['0']
        x = ''.join(t).translate(str.maketrans('0123', '0357'))
        return int(x)

    n = 0
    while True:
        t = conv(n)
        while '0' in str(t) or len(set(list(str(t)))) != 3:
            n += 1
            t = conv(n)
        yield t
        n += 1


def solve(n):
    ans = 0
    g = gen_357()
    while True:
        t = next(g)
        if t > n:
            break
        ans += 1
    return ans


def main(args):
    n = int(input())
    ans = solve(n)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Fixed submission:
# -*- coding: utf-8 -*-
"""
C - 755
TLE
"""
def gen_357():
    def conv(n):
        res = []
        while n:
            n, r = divmod(n, 4)
            if r == 0 and n:
                return '0'
            res.append(str(str(r)))
        if not res:
            res = ['0']
        return ''.join(res[::-1]).translate(str.maketrans('0123', '0357'))

    n = 0
    while True:
        t = conv(n)
        while '0' in t or len(set(list(t))) != 3:
            n += 1
            t = conv(n)
        yield t
        n += 1


def solve(n):
    ans = 0
    g = gen_357()
    while True:
        t = next(g)
        if int(t) > n:
            break
        ans += 1
    return ans


n = int(input())
ans = solve(n)
print(ans)
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
A - Multiple of 2 and N
https://beta.atcoder.jp/contests/abc102/tasks/abc102_a

"""
import sys
from sys import stdin
input = stdin.readline


from math import gcd

def main(args):
    N = int(input())
    g = gcd(N, 2)
    print(N * 2 // g)


if __name__ == '__main__':
    main(sys.argv[1:])


Fixed submission:
# -*- coding: utf-8 -*-
"""
A - Multiple of 2 and N
https://beta.atcoder.jp/contests/abc102/tasks/abc102_a

"""
import sys
from sys import stdin
input = stdin.readline


from fractions import gcd

def main(args):
    N = int(input())
    g = gcd(N, 2)
    print(N * 2 // g)


if __name__ == '__main__':
    main(sys.argv[1:])
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
D - Patisserie ABC
https://abc100.contest.atcoder.jp/tasks/abc100_d

"""
import sys
from sys import stdin
input = stdin.readline


from heapq import heappop, heappush


def solve(cakes, M):
    result = []
    for xx in [1, -1]:
        for yy in [1, -1]:
            for zz in [1, -1]:
                hq = []
                for x, y, z in cakes:
                    x *= xx
                    y *= yy
                    z *= zz
                    heappush(hq, -(x+y+z))
                ans = 0
                for _ in range(M):
                    ans += heappop(hq)
                result.append(-ans)
    return sorted(result)[-1]


def main(args):
    duplicate = set()
    N, M = map(int, input().split())

    cakes = []
    for _ in range(N):
        x, y, z = map(int, input().split())
        if not (x, y, z) in duplicate:
            cakes.append((x, y, z))
        duplicate.add((x, y, z))
    ans = solve(cakes, M)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Fixed submission:
# -*- coding: utf-8 -*-
"""
D - Patisserie ABC
https://abc100.contest.atcoder.jp/tasks/abc100_d

"""
import sys
from sys import stdin
input = stdin.readline


from heapq import heappop, heappush


def solve(cakes, M):
    result = []
    for xx in [1, -1]:
        for yy in [1, -1]:
            for zz in [1, -1]:
                hq = []
                for x, y, z in cakes:
                    x *= xx
                    y *= yy
                    z *= zz
                    heappush(hq, -(x+y+z))
                ans = 0
                for _ in range(M):
                    ans += heappop(hq)
                result.append(-ans)
    return sorted(result)[-1]


def main(args):
    N, M = map(int, input().split())

    cakes = []
    for _ in range(N):
        x, y, z = map(int, input().split())
        cakes.append((x, y, z))
    ans = solve(cakes, M)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
Buggy python submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
"""
C - Traveling Plan
https://beta.atcoder.jp/contests/abc092/tasks/arc093_a

"""
import sys
from sys import stdin

input = stdin.readline


def solve(spots, N):
    spots.append(0)
    total_cost = 0
    cp = 0
    for s in spots:
        total_cost += abs(s - cp)
        cp = s
    # total_cost += abs(spots[-1])

    ans = []
    spots.insert(0, 0)
    for i in range(1, N):
        if spots[i-1] <= spots[i] <= spots[i+1] or spots[i-1] >= spots[i] >= spots[i+1]:
            ans.append(total_cost)
        else:
            t1 = abs(spots[i-1] - spots[i]) * 2
            ans.append((total_cost - t1))

    if spots[-3] >= spots[-2] >= spots[-1] or spots[-3] <= spots[-2] <= spots[-1]:
        ans.append(total_cost)
    else:
        if spots[-2] <= spots[-3] <= spots[-1]:
            t2 = abs(spots[-3] - spots[-2]) * 2
        elif spots[-2] <= spots[-1] <= spots[-3]:
            t2 = abs(spots[-1] - spots[-2]) * 2
        ans.append(total_cost - t2)


    return ans


def main(args):
    N = int(input())
    spots = [int(x) for x in input().split()]
    ans = solve(spots, N)
    print(*ans, sep='\n')


if __name__ == '__main__':
    main(sys.argv[1:])
    


Fixed submission:
# -*- coding: utf-8 -*-
"""
C - Traveling Plan
https://beta.atcoder.jp/contests/abc092/tasks/arc093_a

"""
import sys
from sys import stdin

input = stdin.readline


def solve(spots, N):
    total_cost = 0
    cp = 0
    for s in spots:
        total_cost += abs(s - cp)
        cp = s
    total_cost += abs(spots[-1])

    ans = []
    spots.append(0)
    spots.insert(0, 0)
    for i in range(1, N):
        if spots[i-1] <= spots[i] <= spots[i+1] or spots[i-1] >= spots[i] >= spots[i+1]:
            ans.append(total_cost)
        else:
            if spots[i] <= spots[i-1] <= spots[i+1]:
                t = abs(spots[i] - spots[i-1]) * 2
            elif spots[i-1] <= spots[i+1] <= spots[i]:
                t = abs(spots[i] - spots[i+1]) * 2
            elif spots[i-1] >= spots[i+1] >= spots[i]:
                t = abs(spots[i] - spots[i+1]) * 2
            else:
                t = abs(spots[i] - spots[i-1]) * 2
            ans.append((total_cost - t))

    spots = spots[:-2]
    total_cost = 0
    cp = 0
    for s in spots:
        total_cost += abs(s - cp)
        cp = s
    total_cost += abs(spots[-1])
    ans.append(total_cost)

    return ans


def main(args):
    N = int(input())
    spots = [int(x) for x in input().split()]
    ans = solve(spots, N)
    print(*ans, sep='\n')


if __name__ == '__main__':
    main(sys.argv[1:])