Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import sys

input = sys.stdin.readline

sys.setrecursionlimit(10**7)

INF = 10**10

MOD = 10**9 + 7

X = int(eval(input()))

for i in range(1000):

    for j in range(-1000,1000):

        #print (i**5 - j**5)

        if i**5 - j**5 == X:

            print((i,j))

            exit()

# optimized version of the same code:

import sys

input = sys.stdin.readline

sys.setrecursionlimit(10**7)

INF = 10**10

MOD = 10**9 + 7

X = int(eval(input()))

MAX_X = 10**9

n = 0

while(1):

    n+=1

    if n**5 - (n-1)**5 > MAX_X:

        break

for i in range(n):

    for j in range(-n+1,n-1):

        if i**5 - j**5 == X:

            print((i,j))

            exit()

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)
INF = 10**10
MOD = 10**9 + 7
X = int(eval(input()))
for i in range(1000):
    for j in range(-1000, 1000):
        # print (i**5 - j**5)
        if i**5 - j**5 == X:
            print((i, j))
            exit()

import sys

input = sys.stdin.readline
sys.setrecursionlimit(10**7)
INF = 10**10
MOD = 10**9 + 7
X = int(eval(input()))
MAX_X = 10**9
n = 0
while 1:
    n += 1
    if n**5 - (n - 1) ** 5 > MAX_X:
        break
for i in range(n):
    for j in range(-n + 1, n - 1):
        if i**5 - j**5 == X:
            print((i, j))
            exit()


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

l,r = list(map(int,input().split()))

if r - l > 2019:

    print((0))

else:

    tres = 2019

    for i in range(l,r):

        for j in range(i+1,r+1):

            mod = (i % 2019) * (j % 2019) % 2019

            tres = min(tres,mod)

    print(tres)

# optimized version of the same code:

l,r = list(map(int,input().split()))

if r - l > 2019:

    print((0))

else:

    tres = 2019

    for i in range(l,r):

        for j in range(i+1,r+1):

            mod = (i % 2019) * (j % 2019) % 2019

            tres = min(tres,mod)

            if tres == 0:

                break

        if tres == 0:

            break

    print(tres)

l, r = list(map(int, input().split()))
if r - l > 2019:
    print((0))
else:
    tres = 2019
    for i in range(l, r):
        for j in range(i + 1, r + 1):
            mod = (i % 2019) * (j % 2019) % 2019
            tres = min(tres, mod)
    print(tres)

l, r = list(map(int, input().split()))
if r - l > 2019:
    print((0))
else:
    tres = 2019
    for i in range(l, r):
        for j in range(i + 1, r + 1):
            mod = (i % 2019) * (j % 2019) % 2019
            tres = min(tres, mod)
            if tres == 0:
                break
        if tres == 0:
            break
    print(tres)

+            if tres == 0:
+                break
+        if tres == 0:
+            break


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

# 2019-11-12 22:21:08(JST)

import sys

# import collections

# import math

# from string import ascii_lowercase, ascii_uppercase, digits

# from bisect import bisect_left as bi_l, bisect_right as bi_r

import itertools

# from functools import reduce

# import operator as op

# from scipy.misc import comb # float

# import numpy as np

def main():

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

    all_words = []

    for i in range(1, len(s) + 1):

        for letters in itertools.product('ATCG', repeat=i):

            word = ''.join(letters)

            all_words.append(word)

    for i in range(len(all_words)-1, 0-1, -1):

        if all_words[i] in s:

            print((len(all_words[i])))

            sys.exit()

    print((0))

if __name__ == "__main__":

    main()

# optimized version of the same code:

# 2019-11-12 22:21:08(JST)

import sys

# import collections

# import math

# from string import ascii_lowercase, ascii_uppercase, digits

# from bisect import bisect_left as bi_l, bisect_right as bi_r

# import itertools

# from functools import reduce

# import operator as op

# from scipy.misc import comb # float

# import numpy as np

def main():

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

    permitted = 'ACGT'

    continuous_count = []

    count = 0

    for i in range(len(s)):

        char = s[i]

        if char in permitted:

            count += 1

        else:

            continuous_count.append(count)

            count = 0

        if i == len(s) - 1:

            continuous_count.append(count)

    if not continuous_count:

        print((len(s)))

    else:

        print((max(continuous_count)))

if __name__ == "__main__":

    main()

# 2019-11-12 22:21:08(JST)
import sys

# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
import itertools

# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np
def main():
    s = sys.stdin.readline().rstrip()
    all_words = []
    for i in range(1, len(s) + 1):
        for letters in itertools.product("ATCG", repeat=i):
            word = "".join(letters)
            all_words.append(word)
    for i in range(len(all_words) - 1, 0 - 1, -1):
        if all_words[i] in s:
            print((len(all_words[i])))
            sys.exit()
    print((0))

if __name__ == "__main__":
    main()

# 2019-11-12 22:21:08(JST)
import sys

# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np
def main():
    s = sys.stdin.readline().rstrip()
    permitted = "ACGT"
    continuous_count = []
    count = 0
    for i in range(len(s)):
        char = s[i]
        if char in permitted:
            count += 1
        else:
            continuous_count.append(count)
            count = 0
        if i == len(s) - 1:
            continuous_count.append(count)
    if not continuous_count:
        print((len(s)))
    else:
        print((max(continuous_count)))

if __name__ == "__main__":
    main()

-        for letters in itertools.product("ATCG", repeat=i):

-    for i in range(len(all_words) - 1, 0 - 1, -1):

+            continuous_count.append(count)

+            continuous_count.append(count)


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

def resolve():

    '''

    code here

    '''

    import collections

    import itertools

    import numpy as np

    N = int(eval(input()))

    Ss = [input()[0] for _ in range(N)]

    march_letter = [item for item in Ss if item in ['M', 'A', 'R', 'C', 'H']]

    march_cnt = collections.Counter(march_letter)

    if len(march_cnt) < 3:

        res = 0

    else:

        res_list = itertools.combinations(list(march_cnt.values()),3)

        res = 0

        for element in res_list:

            res += np.prod(np.array(element))

    print(res)

if __name__ == "__main__":

    resolve()

# optimized version of the same code:

def resolve():

    '''

    code here

    '''

    import collections

    import itertools

    N = int(eval(input()))

    Ss = [input()[0] for _ in range(N)]

    march_letter = [item for item in Ss if item in ['M', 'A', 'R', 'C', 'H']]

    march_cnt = collections.Counter(march_letter)

    if len(march_cnt) < 3:

        res = 0

    else:

        res_list = itertools.combinations(list(march_cnt.values()),3)

        res = 0

        for element in res_list:

            res += element[0]*element[1]*element[2]

    print(res)

if __name__ == "__main__":

    resolve()

def resolve():
    """
    code here
    """
    import collections
    import itertools
    import numpy as np

    N = int(eval(input()))
    Ss = [input()[0] for _ in range(N)]
    march_letter = [item for item in Ss if item in ["M", "A", "R", "C", "H"]]
    march_cnt = collections.Counter(march_letter)
    if len(march_cnt) < 3:
        res = 0
    else:
        res_list = itertools.combinations(list(march_cnt.values()), 3)
        res = 0
        for element in res_list:
            res += np.prod(np.array(element))
    print(res)

if __name__ == "__main__":
    resolve()

def resolve():
    """
    code here
    """
    import collections
    import itertools

    N = int(eval(input()))
    Ss = [input()[0] for _ in range(N)]
    march_letter = [item for item in Ss if item in ["M", "A", "R", "C", "H"]]
    march_cnt = collections.Counter(march_letter)
    if len(march_cnt) < 3:
        res = 0
    else:
        res_list = itertools.combinations(list(march_cnt.values()), 3)
        res = 0
        for element in res_list:
            res += element[0] * element[1] * element[2]
    print(res)

if __name__ == "__main__":
    resolve()

-            res += np.prod(np.array(element))

+            res += element[0] * element[1] * element[2]


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

#                         author:  kagemeka

#                         created: 2019-11-08 14:51:29(JST)

## internal modules

import sys

# import collections

# import math

# import string

# import bisect

# import re

# import itertools

import statistics

# import functools

# import operator

## external modules

# import scipy.special   # if use comb function on AtCoder,

# import scipy.misc      # select scipy.misc.comb (old version)

def main():

    n, *a = (int(x) for x in sys.stdin.read().split())

    for i in range(n):

        a[i] -= (i + 1)

    if n % 2 != 0:

        b = statistics.median(a)

    else:

        if a.count(statistics.median_high(a)) >= a.count(statistics.median_low(a)):

            b = statistics.median_high(a)

        else:

            b = statistics.median_low(a)

    ans = sum([abs(a[i] - b) for i in range(n)])

    print(ans)

if __name__ == "__main__":

    # execute only if run as a script

    main()

# optimized version of the same code:

import sys

n, *a = list(map(int, sys.stdin.read().split()))

def main():

    for i in range(n):

        a[i] -= (i + 1)

    a.sort()

    b = a[n // 2]

    res = 0

    for i in range(n):

        res += abs(a[i] - b)

    return res

if __name__ == '__main__':

    ans = main()

    print(ans)

#                         author:  kagemeka
#                         created: 2019-11-08 14:51:29(JST)
## internal modules
import sys

# import collections
# import math
# import string
# import bisect
# import re
# import itertools
import statistics

# import functools
# import operator
## external modules
# import scipy.special   # if use comb function on AtCoder,
# import scipy.misc      # select scipy.misc.comb (old version)
def main():
    n, *a = (int(x) for x in sys.stdin.read().split())
    for i in range(n):
        a[i] -= i + 1
    if n % 2 != 0:
        b = statistics.median(a)
    else:
        if a.count(statistics.median_high(a)) >= a.count(statistics.median_low(a)):
            b = statistics.median_high(a)
        else:
            b = statistics.median_low(a)
    ans = sum([abs(a[i] - b) for i in range(n)])
    print(ans)

if __name__ == "__main__":
    # execute only if run as a script
    main()

import sys

n, *a = list(map(int, sys.stdin.read().split()))

def main():
    for i in range(n):
        a[i] -= i + 1
    a.sort()
    b = a[n // 2]
    res = 0
    for i in range(n):
        res += abs(a[i] - b)
    return res

if __name__ == "__main__":
    ans = main()
    print(ans)

-#                         author:  kagemeka

+n, *a = list(map(int, sys.stdin.read().split()))

-# import scipy.special   # if use comb function on AtCoder,

-# import scipy.misc      # select scipy.misc.comb (old version)

-    n, *a = (int(x) for x in sys.stdin.read().split())

-        if a.count(statistics.median_high(a)) >= a.count(statistics.median_low(a)):

-            b = statistics.median_high(a)

-            b = statistics.median_low(a)

-    ans = sum([abs(a[i] - b) for i in range(n)])


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

x = int(eval(input()))

for i in range(-118, 120):

    for j in range(-119, 119):

        if i**5 - j**5 == x:

            print(('{} {}'.format(i,j)))

            break

    else:

        continue

    break

# optimized version of the same code:

def make_divisors(n):

    divisors = []

    for i in range(1, int(n**0.5)+1):

        if n % i == 0:

            divisors.append(i)

            if i != n // i:

                divisors.append(n//i)

    divisors.sort()

    return divisors

x = int(eval(input()))

L = make_divisors(x)

for i in L:

    for a in range(-118,120):

        if a**5 - (a-i)**5 == x:

            print(('{} {}'.format(a,a-i)))

            break

    else:

        continue

    break

x = int(eval(input()))
for i in range(-118, 120):
    for j in range(-119, 119):
        if i**5 - j**5 == x:
            print(("{} {}".format(i, j)))
            break
    else:
        continue
    break

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
    divisors.sort()
    return divisors

x = int(eval(input()))
L = make_divisors(x)
for i in L:
    for a in range(-118, 120):
        if a**5 - (a - i) ** 5 == x:
            print(("{} {}".format(a, a - i)))
            break
    else:
        continue
    break

+    for i in range(1, int(n**0.5) + 1):

+                divisors.append(n // i)


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

def findSumDigit(num):

    global total

    total = ""

    while num > 0:

        total += str(num % 10)

        num //= 10

    return total

def main():

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

    ans = 0

    for i in range(a,b+1):

        tmp = str(findSumDigit(i))

        if tmp == str(i):

            ans += 1

    print(ans)

if __name__ == '__main__':

    main()

# optimized version of the same code:

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

ans = 0

for i in range(a,b+1):

    seki_gyaku = str(i)

    if seki_gyaku == seki_gyaku[::-1]:

        ans += 1

print(ans)

def findSumDigit(num):
    global total
    total = ""
    while num > 0:
        total += str(num % 10)
        num //= 10
    return total

def main():
    a, b = list(map(int, input().split()))
    ans = 0
    for i in range(a, b + 1):
        tmp = str(findSumDigit(i))
        if tmp == str(i):
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()

a, b = list(map(int, input().split()))
ans = 0
for i in range(a, b + 1):
    seki_gyaku = str(i)
    if seki_gyaku == seki_gyaku[::-1]:
        ans += 1
print(ans)

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


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

N = int(eval(input()))

a = [int(eval(input())) for i in range(N)]

now = a[0]

count = 1

c = 0

for i in range(10**6):

    if now != 2:

        count += 1

        now = a[now - 1]

    else:

        print(count)

        c = 1

        break

if c == 0:

    print((-1))

# optimized version of the same code:

N = int(eval(input()))

a = [0] + [int(eval(input())) for _ in range(N)]

x = 1

visited = set([1])

answer = 0

while True:

  x = a[x]

  if x in visited:

    answer = -1

    break

  visited.add(x)

  answer += 1

  if x == 2:

    break

print(answer)

-a = [int(eval(input())) for i in range(N)]

+a = [0] + [int(eval(input())) for _ in range(N)]


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

X = int(eval(input()))#数字

for i in range(10 ** 8):

    for j in range(-10000,10 ** 4):

        if i ** 5 - j ** 5 == X:

            print((i, j))

            exit()

# optimized version of the same code:

x = int(eval(input()))

y = 10**4

for i in range(y):

    for j in range(-y,y):

        if i ** 5 - j ** 5 == x:

            print((i, j))

            exit()

X = int(eval(input()))  # 数字
for i in range(10**8):
    for j in range(-10000, 10**4):
        if i**5 - j**5 == X:
            print((i, j))
            exit()

x = int(eval(input()))
y = 10**4
for i in range(y):
    for j in range(-y, y):
        if i**5 - j**5 == x:
            print((i, j))
            exit()

-X = int(eval(input()))  # 数字
-for i in range(10**8):
-    for j in range(-10000, 10**4):
-        if i**5 - j**5 == X:
+x = int(eval(input()))
+y = 10**4
+for i in range(y):
+    for j in range(-y, y):
+        if i**5 - j**5 == x:


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

n=int(eval(input()))

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

def f():

 for i in range(n-1):

  d=a[i][:];d[3],d[4]=d[4],d[3]

  for j in range(i+1,n):

   e=a[j][:];e[3],e[4]=e[4],e[3]

   for p in([0,1,2,3,4,5],[1,5,2,0,4,3],[2,1,5,3,0,4],[3,0,2,5,4,1],[4,1,0,3,5,2],[5,1,4,3,2,0]):

    f=[d[k]for k in p]

    if f[0]==e[0]and f[5]==e[5]:

     f=f[1:5]*2

     for k in range(4):

      if f[k:k+4]==e[1:5]:return'No'

 return'Yes'

print((f()))

# optimized version of the same code:

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

+a = [[int(s) for s in input().split()] for _ in range(n)]


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import numpy as np

H, W = list(map(int, input().split()))

a = np.array([list(eval(input())) for i in range(H)])

at = np.all(a == '.', axis = 1)

for i in reversed(list(range(len(at)))):

  if at[i]:

    a = np.delete(a, i, 0)

at = np.all(a == '.', axis = 0)

for i in reversed(list(range(len(at)))):

  if at[i]:

    a = np.delete(a, i, 1)

for i in a:

  print((''.join(i)))

# optimized version of the same code:

H, W = list(map(int, input().split()))

a = [list(eval(input())) for i in range(H)]

for i in reversed(list(range(len(a)))):

  if '#' not in a[i]:

    del a[i]

a = list(zip(*a))

for i in reversed(list(range(len(a)))):

  if '#' not in a[i]:

    del a[i]

a = list(zip(*a))

for i in a:

  print((''.join(i)))

import numpy as np

H, W = list(map(int, input().split()))
a = np.array([list(eval(input())) for i in range(H)])
at = np.all(a == ".", axis=1)
for i in reversed(list(range(len(at)))):
    if at[i]:
        a = np.delete(a, i, 0)
at = np.all(a == ".", axis=0)
for i in reversed(list(range(len(at)))):
    if at[i]:
        a = np.delete(a, i, 1)
for i in a:
    print(("".join(i)))

H, W = list(map(int, input().split()))
a = [list(eval(input())) for i in range(H)]
for i in reversed(list(range(len(a)))):
    if "#" not in a[i]:
        del a[i]
a = list(zip(*a))
for i in reversed(list(range(len(a)))):
    if "#" not in a[i]:
        del a[i]
a = list(zip(*a))
for i in a:
    print(("".join(i)))

-a = np.array([list(eval(input())) for i in range(H)])

-for i in reversed(list(range(len(at)))):

+a = [list(eval(input())) for i in range(H)]

+for i in reversed(list(range(len(a)))):


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

N = int(eval(input()))

ans = 0

for i in range(1, N+1):

    if len(str(i))%2==1:

        ans += 1

print(ans)

# optimized version of the same code:

import sys

def rec(length):

    if length == 1:

        return 9

    else:

        return 9 * 10**(length - 1) + rec(length - 2)

n = eval(input())

length = len(n)

if length == 1:

    print(n)

    sys.exit()

if length % 2 == 0:

    ans = rec(length - 1)

else:

    ans = rec(length - 2) + int(n) - int("1" + "0" * (length - 1)) + 1

print(ans)

N = int(eval(input()))
ans = 0
for i in range(1, N + 1):
    if len(str(i)) % 2 == 1:
        ans += 1
print(ans)

import sys

def rec(length):
    if length == 1:
        return 9
    else:
        return 9 * 10 ** (length - 1) + rec(length - 2)

n = eval(input())
length = len(n)
if length == 1:
    print(n)
    sys.exit()
if length % 2 == 0:
    ans = rec(length - 1)
else:
    ans = rec(length - 2) + int(n) - int("1" + "0" * (length - 1)) + 1
print(ans)

+        return 9 * 10 ** (length - 1) + rec(length - 2)


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import numpy as np

from itertools import product

n = int(eval(input()))

a = list(map(int,input().split()))

a = np.array(a)

li = [-1,0,1]

cnt = 0

for v in product(li,repeat = n):

    v = np.array(v)

    L =a+v

    cum = L.cumprod()

    if cum[-1]%2 ==0 :

        cnt +=1

print(cnt)

# optimized version of the same code:

n = int(eval(input()))

a = list(map(int,input().split()))

from itertools import product

li = [-1,0,1]

cnt = 0

for v in product(li,repeat = n):

    L = []

    for i in range(n):

        L.append(v[i]+a[i])

    if any(x%2==0 for x in L):

        cnt +=1

print(cnt)

import numpy as np
from itertools import product

n = int(eval(input()))
a = list(map(int, input().split()))
a = np.array(a)
li = [-1, 0, 1]
cnt = 0
for v in product(li, repeat=n):
    v = np.array(v)
    L = a + v
    cum = L.cumprod()
    if cum[-1] % 2 == 0:
        cnt += 1
print(cnt)

n = int(eval(input()))
a = list(map(int, input().split()))
from itertools import product

li = [-1, 0, 1]
cnt = 0
for v in product(li, repeat=n):
    L = []
    for i in range(n):
        L.append(v[i] + a[i])
    if any(x % 2 == 0 for x in L):
        cnt += 1
print(cnt)

-import numpy as np
+n = int(eval(input()))
+a = list(map(int, input().split()))
-n = int(eval(input()))
-a = list(map(int, input().split()))
-a = np.array(a)
-    v = np.array(v)
-    L = a + v
-    cum = L.cumprod()
-    if cum[-1] % 2 == 0:
+    L = []
+    for i in range(n):
+        L.append(v[i] + a[i])
+    if any(x % 2 == 0 for x in L):


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import itertools

from collections import Counter

N = int(eval(input()))

src = [eval(input()) for i in range(N)]

ctr = Counter()

for s in src:

    ctr[s[0]] += 1

ans = 0

for ptn in itertools.combinations('MARCH',3):

    a,b,c = ptn

    ans += ctr[a]*ctr[b]*ctr[c]

print(ans)

# optimized version of the same code:

N = int(eval(input()))

S = [eval(input()) for i in range(N)]

from collections import Counter

ctr = Counter([s[0] for s in S])

ans = 0

import itertools

for ptn in itertools.combinations('MARCH', 3):

    t = 1

    for c in ptn:

        t *= ctr[c]

    ans += t

print(ans)

import itertools
from collections import Counter

N = int(eval(input()))
src = [eval(input()) for i in range(N)]
ctr = Counter()
for s in src:
    ctr[s[0]] += 1
ans = 0
for ptn in itertools.combinations("MARCH", 3):
    a, b, c = ptn
    ans += ctr[a] * ctr[b] * ctr[c]
print(ans)

N = int(eval(input()))
S = [eval(input()) for i in range(N)]
from collections import Counter

ctr = Counter([s[0] for s in S])
ans = 0
import itertools

for ptn in itertools.combinations("MARCH", 3):
    t = 1
    for c in ptn:
        t *= ctr[c]
    ans += t
print(ans)

-src = [eval(input()) for i in range(N)]


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

N = int(eval(input()))

count = 0

for i in range(1, N + 1):

    num_dig = 0

    ii = i

    while ii > 0:

        ii = int(ii / 10)

        num_dig += 1

    if num_dig % 2 != 0:

        count += 1

print(count)

# optimized version of the same code:

N = int(eval(input()))

count = 0

for i in range(1, N + 1):

    if len(str(i)) % 2 != 0:

        count += 1

print(count)

-    num_dig = 0
-    ii = i
-    while ii > 0:
-        ii = int(ii / 10)
-        num_dig += 1
-    if num_dig % 2 != 0:
+    if len(str(i)) % 2 != 0:


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

from string import ascii_lowercase as lower

print((lower[lower.find(eval(input()))+1]))

# optimized version of the same code:

from string import ascii_lowercase as lower

print((lower[lower.find(eval(input())) + 1]))

-from string import ascii_lowercase as lower


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

from scipy.sparse import *

N,M,*A=list(map(int,open(0).read().split()));g=csr_matrix(([1]*M,(A[::2],A[1::2])),shape=(N+1,N+1)).tolil()

c = 0

for a,b in zip(*g.nonzero()):

  g[a,b]=0

  n,_=csgraph.connected_components(g)

  c+=n!=2

  g[a,b]=1

print(c)

# optimized version of the same code:

N,M=list(map(int,input().split()))

edges=[list(map(int,input().split())) for i in range(M)]

ans=0

for x in edges:

    l=list(range(N))

    for y in edges:

        if y!=x:l=[l[y[0]-1] if l[i]==l[y[1]-1] else l[i] for i in range(N)]

    if len(set(l))!=1:ans+=1

print(ans)

from scipy.sparse import *

N, M, *A = list(map(int, open(0).read().split()))
g = csr_matrix(([1] * M, (A[::2], A[1::2])), shape=(N + 1, N + 1)).tolil()
c = 0
for a, b in zip(*g.nonzero()):
    g[a, b] = 0
    n, _ = csgraph.connected_components(g)
    c += n != 2
    g[a, b] = 1
print(c)

N, M = list(map(int, input().split()))
edges = [list(map(int, input().split())) for i in range(M)]
ans = 0
for x in edges:
    l = list(range(N))
    for y in edges:
        if y != x:
            l = [l[y[0] - 1] if l[i] == l[y[1] - 1] else l[i] for i in range(N)]
    if len(set(l)) != 1:
        ans += 1
print(ans)

-N, M, *A = list(map(int, open(0).read().split()))

-    n, _ = csgraph.connected_components(g)

+edges = [list(map(int, input().split())) for i in range(M)]

+            l = [l[y[0] - 1] if l[i] == l[y[1] - 1] else l[i] for i in range(N)]


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

#!usr/bin/env python3

from collections import defaultdict

from collections import deque

from heapq import heappush, heappop

import sys

import math

import bisect

import random

def LI(): return list(map(int, sys.stdin.readline().split()))

def I(): return int(sys.stdin.readline())

def LS():return list(map(list, sys.stdin.readline().split()))

def S(): return list(sys.stdin.readline())[:-1]

def IR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = I()

    return l

def LIR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = LI()

    return l

def SR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = S()

    return l

def LSR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = SR()

    return l

mod = 1000000007

#A

"""

def gcd(a,b):

    if a == 0:

        return b

    return gcd(b%a,a)

n = I()

a = IR(n)

l = a[0]

for i in range(1,n):

    g = gcd(l,a[i])

    l *= a[i]//g

print(l)

"""

#B

n = I()

v = [[] for i in range(n)]

for i in range(n-1):

    a,b,c = LI()

    a -= 1

    b -= 1

    v[a].append([b,c])

    v[b].append([a,c])

Q,k = LI()

d = [-1 for i in range(n)]

d[k-1] = 0

q = deque()

q.append(k-1)

while q:

    x = q.pop()

    for y,c in v[x]:

        if d[y] == -1:

            d[y] = d[x]+c

            q.append(y)

for i in range(Q):

    x,y = LI()

    x -= 1

    y -= 1

    print((d[x]+d[y]))

#C

#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

# optimized version of the same code:

#!usr/bin/env python3

from collections import defaultdict

from collections import deque

from heapq import heappush, heappop

import sys

import math

import bisect

import random

def LI(): return list(map(int, sys.stdin.readline().split()))

def I(): return int(sys.stdin.readline())

def LS():return list(map(list, sys.stdin.readline().split()))

def S(): return list(sys.stdin.readline())[:-1]

def IR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = I()

    return l

def LIR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = LI()

    return l

def SR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = S()

    return l

def LSR(n):

    l = [None for i in range(n)]

    for i in range(n):l[i] = SR()

    return l

mod = 1000000007

#A

"""

def gcd(a,b):

    if a == 0:

        return b

    return gcd(b%a,a)

n = I()

a = IR(n)

l = a[0]

for i in range(1,n):

    g = gcd(l,a[i])

    l *= a[i]//g

print(l)

"""

#B

n = I()

v = [[] for i in range(n)]

for i in range(n-1):

    a,b,c = LI()

    a -= 1

    b -= 1

    v[a].append([b,c])

    v[b].append([a,c])

Q,k = LI()

d = [-1 for i in range(n)]

d[k-1] = 0

q = deque()

q.append(k-1)

while q:

    x = q.popleft()

    for y,c in v[x]:

        if d[y] == -1:

            d[y] = d[x]+c

            q.append(y)

for i in range(Q):

    x,y = LI()

    x -= 1

    y -= 1

    print((d[x]+d[y]))

#C

#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random

def LI():
    return list(map(int, sys.stdin.readline().split()))

def I():
    return int(sys.stdin.readline())

def LS():
    return list(map(list, sys.stdin.readline().split()))

def S():
    return list(sys.stdin.readline())[:-1]

def IR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = I()
    return l

def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = LI()
    return l

def SR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = S()
    return l

def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = SR()
    return l

mod = 1000000007
# A
"""
def gcd(a,b):
    if a == 0:
        return b
    return gcd(b%a,a)
n = I()
a = IR(n)
l = a[0]
for i in range(1,n):
    g = gcd(l,a[i])
    l *= a[i]//g
print(l)
"""
# B
n = I()
v = [[] for i in range(n)]
for i in range(n - 1):
    a, b, c = LI()
    a -= 1
    b -= 1
    v[a].append([b, c])
    v[b].append([a, c])
Q, k = LI()
d = [-1 for i in range(n)]
d[k - 1] = 0
q = deque()
q.append(k - 1)
while q:
    x = q.pop()
    for y, c in v[x]:
        if d[y] == -1:
            d[y] = d[x] + c
            q.append(y)
for i in range(Q):
    x, y = LI()
    x -= 1
    y -= 1
    print((d[x] + d[y]))
# C
# D
# E
# F
# G
# H
# I
# J
# K
# L
# M
# N
# O
# P
# Q
# R
# S
# T

#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random

def LI():
    return list(map(int, sys.stdin.readline().split()))

def I():
    return int(sys.stdin.readline())

def LS():
    return list(map(list, sys.stdin.readline().split()))

def S():
    return list(sys.stdin.readline())[:-1]

def IR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = I()
    return l

def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = LI()
    return l

def SR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = S()
    return l

def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):
        l[i] = SR()
    return l

mod = 1000000007
# A
"""
def gcd(a,b):
    if a == 0:
        return b
    return gcd(b%a,a)
n = I()
a = IR(n)
l = a[0]
for i in range(1,n):
    g = gcd(l,a[i])
    l *= a[i]//g
print(l)
"""
# B
n = I()
v = [[] for i in range(n)]
for i in range(n - 1):
    a, b, c = LI()
    a -= 1
    b -= 1
    v[a].append([b, c])
    v[b].append([a, c])
Q, k = LI()
d = [-1 for i in range(n)]
d[k - 1] = 0
q = deque()
q.append(k - 1)
while q:
    x = q.popleft()
    for y, c in v[x]:
        if d[y] == -1:
            d[y] = d[x] + c
            q.append(y)
for i in range(Q):
    x, y = LI()
    x -= 1
    y -= 1
    print((d[x] + d[y]))
# C
# D
# E
# F
# G
# H
# I
# J
# K
# L
# M
# N
# O
# P
# Q
# R
# S
# T


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

from itertools import product

N=int(eval(input()))

data=[]

for i in range(N):

    for j in range(int(eval(input()))):

        x,y=list(map(int,input().split()))

        data.append((i,x-1,y))

#print(data)

ans=0

for i in product([1,0],repeat=N):

    #print(i)

    s=True

    for k in data:

        if i[k[0]]==1 and i[k[1]]!=k[2]:

            s=False

            break

    if s:

        ans=max(ans,sum(i))

print(ans)

# optimized version of the same code:

from itertools import product

N=int(eval(input()))

data=[]

for i in range(N):

    for j in range(int(eval(input()))):

        x,y=list(map(int,input().split()))

        data.append((i,x-1,y)) #iさんがx-1さんに嘘(0)or正直(1)

ans=0

for i in product([0,1],repeat=N):

    ok=True

    for j in data:

        if i[j[0]]==1 and i[j[1]]!=j[2]:

            ok = False

            break

    if ok:

        ans=max(ans,sum(i))

print(ans)

from itertools import product

N = int(eval(input()))
data = []
for i in range(N):
    for j in range(int(eval(input()))):
        x, y = list(map(int, input().split()))
        data.append((i, x - 1, y))
# print(data)
ans = 0
for i in product([1, 0], repeat=N):
    # print(i)
    s = True
    for k in data:
        if i[k[0]] == 1 and i[k[1]] != k[2]:
            s = False
            break
    if s:
        ans = max(ans, sum(i))
print(ans)

from itertools import product

N = int(eval(input()))
data = []
for i in range(N):
    for j in range(int(eval(input()))):
        x, y = list(map(int, input().split()))
        data.append((i, x - 1, y))  # iさんがx-1さんに嘘(0)or正直(1)
ans = 0
for i in product([0, 1], repeat=N):
    ok = True
    for j in data:
        if i[j[0]] == 1 and i[j[1]] != j[2]:
            ok = False
            break
    if ok:
        ans = max(ans, sum(i))
print(ans)

+        data.append((i, x - 1, y))  # iさんがx-1さんに嘘(0)or正直(1)


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import string

w = eval(input())

for a in string.ascii_lowercase:

    cnt = 0

    for t in w:

        if t == a:

            cnt = cnt + 1

    if cnt % 2 == 1:

        print("No")

        exit()

print("Yes")

# optimized version of the same code:

w = eval(input())

m = [0] * 26

for t in w:

    m[ord(t) - ord('a')] += 1

for cnt in m:

    if cnt % 2 == 1:

        print("No")

        exit()

print("Yes")

w = eval(input())
m = [0] * 26
for t in w:
    m[ord(t) - ord("a")] += 1
for cnt in m:
    if cnt % 2 == 1:
        print("No")
        exit()
print("Yes")

-import string
-for a in string.ascii_lowercase:
-    cnt = 0
-    for t in w:
-        if t == a:
-            cnt = cnt + 1
+m = [0] * 26
+for t in w:
+    m[ord(t) - ord("a")] += 1
+for cnt in m:


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

mod = 10**9+7

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

l = [0]*n

for _ in range(m):

  l[int(eval(input()))-1] = 1

s = 0

t = 1

for i in range(n):

  if l[i] > 0:

    t, s = 0, t

  else:

    t, s = (s+t)%mod, t

print(t)

# optimized version of the same code:

import sys

input = sys.stdin.readline

mod = 10**9+7

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

l = [0]*n

for _ in range(m):

  l[int(eval(input()))-1] = 1

t, s = 1, 0

for i in range(n):

  if l[i]:

    t, s = 0, t

  else:

    t, s = (s+t)%mod, t

print(t)

mod = 10**9 + 7
n, m = list(map(int, input().split()))
l = [0] * n
for _ in range(m):
    l[int(eval(input())) - 1] = 1
s = 0
t = 1
for i in range(n):
    if l[i] > 0:
        t, s = 0, t
    else:
        t, s = (s + t) % mod, t
print(t)

import sys

input = sys.stdin.readline
mod = 10**9 + 7
n, m = list(map(int, input().split()))
l = [0] * n
for _ in range(m):
    l[int(eval(input())) - 1] = 1
t, s = 1, 0
for i in range(n):
    if l[i]:
        t, s = 0, t
    else:
        t, s = (s + t) % mod, t
print(t)

+import sys
+
+input = sys.stdin.readline
-s = 0
-t = 1
+t, s = 1, 0
-    if l[i] > 0:
+    if l[i]:


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

N,M = [int(c) for c in input().split()]

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

cd = [list(map(int,input().split())) for c in range(M)]

for i in range(N):

    mi = 2*10**9

    for j in range(M):

        tmp = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])

        if mi > tmp:

            mi = tmp

            ans = j+1

    print(ans)

# optimized version of the same code:

N,M = [int(c) for c in input().split()]

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

cd = [list(map(int,input().split())) for c in range(M)]

for i in range(N):

    mi = 10**9

    for j in range(M):

        tmp = abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1])

        if mi > tmp:

            mi = tmp

            ans = j+1

    print(ans)

N, M = [int(c) for c in input().split()]
ab = [list(map(int, input().split())) for c in range(N)]
cd = [list(map(int, input().split())) for c in range(M)]
for i in range(N):
    mi = 2 * 10**9
    for j in range(M):
        tmp = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if mi > tmp:
            mi = tmp
            ans = j + 1
    print(ans)

N, M = [int(c) for c in input().split()]
ab = [list(map(int, input().split())) for c in range(N)]
cd = [list(map(int, input().split())) for c in range(M)]
for i in range(N):
    mi = 10**9
    for j in range(M):
        tmp = abs(ab[i][0] - cd[j][0]) + abs(ab[i][1] - cd[j][1])
        if mi > tmp:
            mi = tmp
            ans = j + 1
    print(ans)


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

from bisect import bisect_right

import sys

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

def main():

    x = int(readline())

    for a in range(-120, 120):

        for b in range(-120, 120):

            if a**5 - b**5 == x:

                print((a, b))

                exit()

if __name__ == "__main__":

    main()

# optimized version of the same code:

# AC: 33 msec(Python3)

from itertools import combinations_with_replacement

import sys

read = sys.stdin.read

readline = sys.stdin.readline

readlines = sys.stdin.readlines

def main():

    x = int(readline())

    ab = [i**5 for i in range(200)]

    C = combinations_with_replacement(ab, 2)

    for a, b in C:

        if a + b == x:

            print((int(pow(b, 0.2)), -int(pow(a, 0.2))))

            break

        if b - a == x:

            print((int(pow(b, 0.2)), int(pow(a, 0.2))))

            break

if __name__ == "__main__":

    main()

+from itertools import combinations_with_replacement

+    C = combinations_with_replacement(ab, 2)


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

def test():

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

    count = 0

    for i in range(a,b+1):

        j = list(map(int,list(str(i))))

        if j[0] == j[4] and j[1] == j[3]:

            count += 1

    print(count)

if __name__ == "__main__":

    test()

# optimized version of the same code:

def test():

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

    count = 0

    for i in range(a,b+1):

        if str(i)[0] == str(i)[4] and str(i)[1] == str(i)[3]:

            count += 1

    print(count)

if __name__ == "__main__":

    test()

def test():
    a, b = list(map(int, input().split()))
    count = 0
    for i in range(a, b + 1):
        j = list(map(int, list(str(i))))
        if j[0] == j[4] and j[1] == j[3]:
            count += 1
    print(count)

if __name__ == "__main__":
    test()

def test():
    a, b = list(map(int, input().split()))
    count = 0
    for i in range(a, b + 1):
        if str(i)[0] == str(i)[4] and str(i)[1] == str(i)[3]:
            count += 1
    print(count)

if __name__ == "__main__":
    test()

-        j = list(map(int, list(str(i))))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import sys, re

from collections import deque, defaultdict, Counter

from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians

from itertools import accumulate, permutations, combinations, product, groupby

from operator import itemgetter, mul

from copy import deepcopy

from string import ascii_lowercase, ascii_uppercase, digits

from bisect import bisect, bisect_left

from fractions import gcd

from heapq import heappush, heappop

from functools import reduce

def input(): return sys.stdin.readline().strip()

def INT(): return int(eval(input()))

def MAP(): return list(map(int, input().split()))

def LIST(): return list(map(int, input().split()))

def ZIP(n): return list(zip(*(MAP() for _ in range(n))))

sys.setrecursionlimit(10 ** 9)

INF = float('inf')

mod = 10 ** 9 + 7

import numpy as np

K, N = MAP()

A = LIST()

A.append(A[0]+K)

B = np.zeros(N)

for i in range(N):

  		B[i] = A[i+1] - A[i]

print((int(K - max(B))))

# optimized version of the same code:

import sys, re

from collections import deque, defaultdict, Counter

from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians

from itertools import accumulate, permutations, combinations, product, groupby

from operator import itemgetter, mul

from copy import deepcopy

from string import ascii_lowercase, ascii_uppercase, digits

from bisect import bisect, bisect_left

from fractions import gcd

from heapq import heappush, heappop

from functools import reduce

def input(): return sys.stdin.readline().strip()

def INT(): return int(eval(input()))

def MAP(): return list(map(int, input().split()))

def LIST(): return list(map(int, input().split()))

def ZIP(n): return list(zip(*(MAP() for _ in range(n))))

sys.setrecursionlimit(10 ** 9)

INF = float('inf')

mod = 10 ** 9 + 7

K, N = MAP()

A = LIST()

diff = abs(K - A[-1] + A[0])

d = abs(K - A[-1] + A[0])

if N == 2:

  print((min(d, A[1] - A[0])))

  exit()

for i in range(1, N):

  d += abs(A[i] - A[i-1])

  diff = max(diff, abs(A[i] - A[i-1]))

print((d - diff))

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce

def input():
    return sys.stdin.readline().strip()

def INT():
    return int(eval(input()))

def MAP():
    return list(map(int, input().split()))

def LIST():
    return list(map(int, input().split()))

def ZIP(n):
    return list(zip(*(MAP() for _ in range(n))))

sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
import numpy as np

K, N = MAP()
A = LIST()
A.append(A[0] + K)
B = np.zeros(N)
for i in range(N):
    B[i] = A[i + 1] - A[i]
print((int(K - max(B))))

import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce

def input():
    return sys.stdin.readline().strip()

def INT():
    return int(eval(input()))

def MAP():
    return list(map(int, input().split()))

def LIST():
    return list(map(int, input().split()))

def ZIP(n):
    return list(zip(*(MAP() for _ in range(n))))

sys.setrecursionlimit(10**9)
INF = float("inf")
mod = 10**9 + 7
K, N = MAP()
A = LIST()
diff = abs(K - A[-1] + A[0])
d = abs(K - A[-1] + A[0])
if N == 2:
    print((min(d, A[1] - A[0])))
    exit()
for i in range(1, N):
    d += abs(A[i] - A[i - 1])
    diff = max(diff, abs(A[i] - A[i - 1]))
print((d - diff))

+    diff = max(diff, abs(A[i] - A[i - 1]))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

from bisect import bisect_left

from bisect import bisect_right

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

a = list(map(int, input().split()))

a = sorted(a)

a_count = [0]*100010

a_sum = [0]*100010

for i in range(n):

    a_count[a[i]] += 1

    a_sum[a[i]] += a[i]

for i in range(100005,-1,-1):

    a_count[i] += a_count[i+1]

    a_sum[i] += a_sum[i+1]

def chk(x):

    case = 0

    for i in range(n):

        if 0<= x-a[i]<= 10**5+5:

            case += a_count[x-a[i]]

        elif x-a[i] < 0:

            case += n

    if case >= m:

        ch = True

    else:

        ch = False

    return ch

l = 2*a[-1]+1    #NG

r = 1 #OK

while abs(r-l) > 1:

    kk = (r+l)//2

    if chk(kk):

        r = kk

    else:

        l = kk

ans = 0

sm = sum(a)

l = r

case = 0

for i in range(n):

    num = n-bisect_right(a,l-a[i]-1)

    case += num

    ans += num*a[i]*2

ans -= (case-m)*l

print(ans)

# optimized version of the same code:

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

a = [int(x) for x in input().split()]

aa = [0]*(10**5+1)

aa_sum = [0]*(10**5+1)

for x in a:

    aa[x] += 1

    aa_sum[x] += x

for i in range(10**5)[::-1]:

    aa[i] = aa[i] + aa[i+1]

    aa_sum[i] = aa_sum[i] + aa_sum[i+1]

def count(x):

    cnt = 0

    sm = 0

    for i in range(n):

        if x-a[i] < 0:

            cnt += n

            sm += aa_sum[0]+n*a[i]

        elif x-a[i] > 10**5:

            continue

        else:

            cnt += aa[x-a[i]]

            sm += aa_sum[x-a[i]]+aa[x-a[i]]*a[i]

    return cnt, sm

bottom = 0

top = 10**6

while top - bottom > 1:

    mid = (top+bottom) // 2

    cnt, sm = count(mid)

    if cnt < m:

        top = mid

    else:

        bottom = mid

cnt, sm = count(bottom)

ans = sm - (cnt-m)*bottom

print(ans)

from bisect import bisect_left
from bisect import bisect_right

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a = sorted(a)
a_count = [0] * 100010
a_sum = [0] * 100010
for i in range(n):
    a_count[a[i]] += 1
    a_sum[a[i]] += a[i]
for i in range(100005, -1, -1):
    a_count[i] += a_count[i + 1]
    a_sum[i] += a_sum[i + 1]

def chk(x):
    case = 0
    for i in range(n):
        if 0 <= x - a[i] <= 10**5 + 5:
            case += a_count[x - a[i]]
        elif x - a[i] < 0:
            case += n
    if case >= m:
        ch = True
    else:
        ch = False
    return ch

l = 2 * a[-1] + 1  # NG
r = 1  # OK
while abs(r - l) > 1:
    kk = (r + l) // 2
    if chk(kk):
        r = kk
    else:
        l = kk
ans = 0
sm = sum(a)
l = r
case = 0
for i in range(n):
    num = n - bisect_right(a, l - a[i] - 1)
    case += num
    ans += num * a[i] * 2
ans -= (case - m) * l
print(ans)

n, m = list(map(int, input().split()))
a = [int(x) for x in input().split()]
aa = [0] * (10**5 + 1)
aa_sum = [0] * (10**5 + 1)
for x in a:
    aa[x] += 1
    aa_sum[x] += x
for i in range(10**5)[::-1]:
    aa[i] = aa[i] + aa[i + 1]
    aa_sum[i] = aa_sum[i] + aa_sum[i + 1]

def count(x):
    cnt = 0
    sm = 0
    for i in range(n):
        if x - a[i] < 0:
            cnt += n
            sm += aa_sum[0] + n * a[i]
        elif x - a[i] > 10**5:
            continue
        else:
            cnt += aa[x - a[i]]
            sm += aa_sum[x - a[i]] + aa[x - a[i]] * a[i]
    return cnt, sm

bottom = 0
top = 10**6
while top - bottom > 1:
    mid = (top + bottom) // 2
    cnt, sm = count(mid)
    if cnt < m:
        top = mid
    else:
        bottom = mid
cnt, sm = count(bottom)
ans = sm - (cnt - m) * bottom
print(ans)

+    aa_sum[i] = aa_sum[i] + aa_sum[i + 1]

-    num = n - bisect_right(a, l - a[i] - 1)


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

X, Y, Z = list(map(int, input().split()))

for n in range(10 ** 5, 0, -1):

    if X >= n * (Y + Z) + Z:

        break

print(n)

# optimized version of the same code:

X, Y, Z = list(map(int, input().split()))

print(((X - Z) // (Y + Z)))

X, Y, Z = list(map(int, input().split()))
for n in range(10**5, 0, -1):
    if X >= n * (Y + Z) + Z:
        break
print(n)


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

array = list(map(int, input().split()))

if array[0] % array[1] > 0:

    print(((array[0] // array[1] + 1) * array[2]))

else:

    print(((array[0] // array[1]) * array[2]))

# optimized version of the same code:

n, x, t = list(map(int, input().split()))

print((0--n//x*t))

n, x, t = list(map(int, input().split()))
print((0 - -n // x * t))

-array = list(map(int, input().split()))

-    print(((array[0] // array[1]) * array[2]))

+n, x, t = list(map(int, input().split()))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

N = int(eval(input()))

S = list(map(int, input().split()))

Q = int(eval(input()))

T = list(map(int, input().split()))

def binary_search(target_num, head, tail):

    idx = int((head+tail)/2)

    if target_num == S[idx]:

        return True

    elif target_num < S[idx]:

        if head == idx:

            return False

        return binary_search(target_num, head, idx-1)

    else:

        if tail == idx:

            return False

        return binary_search(target_num, idx+1, tail)

match_count = 0

for target_num in T:

    if binary_search(target_num, 0, len(S)-1):

        match_count += 1

print((str(match_count)))

# optimized version of the same code:

N = int(eval(input()))

S = list(map(int, input().split()))

Q = int(eval(input()))

T = list(map(int, input().split()))

def binary_search(target_num, head, tail):

    while head <= tail:

        idx = int((head+tail)/2)

        if target_num == S[idx]:

            return True

        elif target_num < S[idx]:

            tail = idx - 1

        else:

            head = idx + 1

    return False

match_count = 0

for target_num in T:

    if binary_search(target_num, 0, len(S)-1):

        match_count += 1

print((str(match_count)))

N = int(eval(input()))
S = list(map(int, input().split()))
Q = int(eval(input()))
T = list(map(int, input().split()))

def binary_search(target_num, head, tail):
    idx = int((head + tail) / 2)
    if target_num == S[idx]:
        return True
    elif target_num < S[idx]:
        if head == idx:
            return False
        return binary_search(target_num, head, idx - 1)
    else:
        if tail == idx:
            return False
        return binary_search(target_num, idx + 1, tail)

match_count = 0
for target_num in T:
    if binary_search(target_num, 0, len(S) - 1):
        match_count += 1
print((str(match_count)))

N = int(eval(input()))
S = list(map(int, input().split()))
Q = int(eval(input()))
T = list(map(int, input().split()))

def binary_search(target_num, head, tail):
    while head <= tail:
        idx = int((head + tail) / 2)
        if target_num == S[idx]:
            return True
        elif target_num < S[idx]:
            tail = idx - 1
        else:
            head = idx + 1
    return False

match_count = 0
for target_num in T:
    if binary_search(target_num, 0, len(S) - 1):
        match_count += 1
print((str(match_count)))

-        return binary_search(target_num, head, idx - 1)

-        return binary_search(target_num, idx + 1, tail)


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

n=eval(input())

n=int(n)

a=1

for i in range(n):

    a=a*(i+1)

    if a>=pow(10,9)+7:

        a=a%(pow(10,9)+7)

print(a)

# optimized version of the same code:

n=int(eval(input()))

a=1

for i in range(1,n+1):

    a*=i

    a %= (10**9+7)

print(a)

n = eval(input())
n = int(n)
a = 1
for i in range(n):
    a = a * (i + 1)
    if a >= pow(10, 9) + 7:
        a = a % (pow(10, 9) + 7)
print(a)

n = int(eval(input()))
a = 1
for i in range(1, n + 1):
    a *= i
    a %= 10**9 + 7
print(a)


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

class SegmentTree():

    """

    update, get を提供するSegmentTree

    Attributes

    ----------

    __n : int

        葉の数。2 ^ i - 1

    __dot :

        Segment function

    __e: int

        単位元

    __node: list

        Segment Tree

    """

    def __init__(self, A, dot, e):

        """

        Parameters

        ----------

        A : list

            対象の配列

        dot :

            Segment function

        e : int

            単位元

        """

        n = 2 ** (len(A) - 1).bit_length()

        self.__n = n

        self.__dot = dot

        self.__e = e

        self.__node = [e] * (2 * n)

        for i in range(len(A)):

            self.__node[i + n] = A[i]

        for i in range(n - 1, 0, -1):

            self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1])

    def update(self, i, c):

        i += self.__n

        node = self.__node

        node[i] = c

        while i > 1:

            i //= 2

            node[i] = self.__dot(node[2 * i], node[2 * i + 1])

    def get(self, l, r):

        vl, vr = self.__e, self.__e

        l += self.__n

        r += self.__n

        while (l < r):

            if l & 1:

                vl = self.__dot(vl, self.__node[l])

                l += 1

            l //= 2

            if r & 1:

                r -= 1

                vr = self.__dot(vr, self.__node[r])

            r //= 2

        return self.__dot(vl, vr)

N, K = list(map(int, input().split()))

A = [int(eval(input())) for _ in range(N)]

max_A = max(A)

st = SegmentTree([N] * (max_A + 1), min, N)

edge = [set() for _ in range(N)]

for i, a in enumerate(reversed(A)):

    j = N - 1 - i

    p1 = st.get(a, min(max_A + 1, a + K + 1))

    if p1 < N:

        edge[j].add(p1)

    p2 = st.get(max(0, a - K), a)

    if p2 < N:

        edge[j].add(p2)

    p0 = st.get(a, a + 1)

    if p0 < N:

        edge[j].add(p0)

    st.update(a, j)

dp = [1] * N

for i in range(N - 1):

    here = dp[i]

    for ni in edge[i]:

        if ni < N:

            dp[ni] = max(dp[ni], dp[i] + 1)

print((max(dp)))

# optimized version of the same code:

class SegmentTree():

    """

    update, get を提供するSegmentTree

    Attributes

    ----------

    __n : int

        葉の数。2 ^ i - 1

    __dot :

        Segment function

    __e: int

        単位元

    __node: list

        Segment Tree

    """

    def __init__(self, A, dot, e):

        """

        Parameters

        ----------

        A : list

            対象の配列

        dot :

            Segment function

        e : int

            単位元

        """

        n = 2 ** (len(A) - 1).bit_length()

        self.__n = n

        self.__dot = dot

        self.__e = e

        self.__node = [e] * (2 * n)

        for i in range(len(A)):

            self.__node[i + n] = A[i]

        for i in range(n - 1, 0, -1):

            self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1])

    def update(self, i, c):

        i += self.__n

        node = self.__node

        node[i] = c

        while i > 1:

            i //= 2

            node[i] = self.__dot(node[2 * i], node[2 * i + 1])

    def get(self, l, r):

        vl, vr = self.__e, self.__e

        l += self.__n

        r += self.__n

        while (l < r):

            if l & 1:

                vl = self.__dot(vl, self.__node[l])

                l += 1

            l //= 2

            if r & 1:

                r -= 1

                vr = self.__dot(vr, self.__node[r])

            r //= 2

        return self.__dot(vl, vr)

N, K = list(map(int, input().split()))

A = [int(eval(input())) for _ in range(N)]

max_A = max(A)

st = SegmentTree([N] * (max_A + 1), min, N)

edge = [set() for _ in range(N)]

for i, a in enumerate(reversed(A)):

    j = N - 1 - i

    p1 = st.get(a, min(max_A + 1, a + K + 1))

    if p1 < N:

        edge[j].add(p1)

    p2 = st.get(max(0, a - K), a)

    if p2 < N:

        edge[j].add(p2)

    st.update(a, j)

dp = [1] * N

for i in range(N - 1):

    here = dp[i]

    for ni in edge[i]:

        if ni < N:

            dp[ni] = max(dp[ni], dp[i] + 1)

print((max(dp)))

class SegmentTree:
    """
    update, get を提供するSegmentTree
    Attributes
    ----------
    __n : int
        葉の数。2 ^ i - 1
    __dot :
        Segment function
    __e: int
        単位元
    __node: list
        Segment Tree
    """

    def __init__(self, A, dot, e):
        """
        Parameters
        ----------
        A : list
            対象の配列
        dot :
            Segment function
        e : int
            単位元
        """
        n = 2 ** (len(A) - 1).bit_length()
        self.__n = n
        self.__dot = dot
        self.__e = e
        self.__node = [e] * (2 * n)
        for i in range(len(A)):
            self.__node[i + n] = A[i]
        for i in range(n - 1, 0, -1):
            self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1])

    def update(self, i, c):
        i += self.__n
        node = self.__node
        node[i] = c
        while i > 1:
            i //= 2
            node[i] = self.__dot(node[2 * i], node[2 * i + 1])

    def get(self, l, r):
        vl, vr = self.__e, self.__e
        l += self.__n
        r += self.__n
        while l < r:
            if l & 1:
                vl = self.__dot(vl, self.__node[l])
                l += 1
            l //= 2
            if r & 1:
                r -= 1
                vr = self.__dot(vr, self.__node[r])
            r //= 2
        return self.__dot(vl, vr)

N, K = list(map(int, input().split()))
A = [int(eval(input())) for _ in range(N)]
max_A = max(A)
st = SegmentTree([N] * (max_A + 1), min, N)
edge = [set() for _ in range(N)]
for i, a in enumerate(reversed(A)):
    j = N - 1 - i
    p1 = st.get(a, min(max_A + 1, a + K + 1))
    if p1 < N:
        edge[j].add(p1)
    p2 = st.get(max(0, a - K), a)
    if p2 < N:
        edge[j].add(p2)
    p0 = st.get(a, a + 1)
    if p0 < N:
        edge[j].add(p0)
    st.update(a, j)
dp = [1] * N
for i in range(N - 1):
    here = dp[i]
    for ni in edge[i]:
        if ni < N:
            dp[ni] = max(dp[ni], dp[i] + 1)
print((max(dp)))

class SegmentTree:
    """
    update, get を提供するSegmentTree
    Attributes
    ----------
    __n : int
        葉の数。2 ^ i - 1
    __dot :
        Segment function
    __e: int
        単位元
    __node: list
        Segment Tree
    """

    def __init__(self, A, dot, e):
        """
        Parameters
        ----------
        A : list
            対象の配列
        dot :
            Segment function
        e : int
            単位元
        """
        n = 2 ** (len(A) - 1).bit_length()
        self.__n = n
        self.__dot = dot
        self.__e = e
        self.__node = [e] * (2 * n)
        for i in range(len(A)):
            self.__node[i + n] = A[i]
        for i in range(n - 1, 0, -1):
            self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1])

    def update(self, i, c):
        i += self.__n
        node = self.__node
        node[i] = c
        while i > 1:
            i //= 2
            node[i] = self.__dot(node[2 * i], node[2 * i + 1])

    def get(self, l, r):
        vl, vr = self.__e, self.__e
        l += self.__n
        r += self.__n
        while l < r:
            if l & 1:
                vl = self.__dot(vl, self.__node[l])
                l += 1
            l //= 2
            if r & 1:
                r -= 1
                vr = self.__dot(vr, self.__node[r])
            r //= 2
        return self.__dot(vl, vr)

N, K = list(map(int, input().split()))
A = [int(eval(input())) for _ in range(N)]
max_A = max(A)
st = SegmentTree([N] * (max_A + 1), min, N)
edge = [set() for _ in range(N)]
for i, a in enumerate(reversed(A)):
    j = N - 1 - i
    p1 = st.get(a, min(max_A + 1, a + K + 1))
    if p1 < N:
        edge[j].add(p1)
    p2 = st.get(max(0, a - K), a)
    if p2 < N:
        edge[j].add(p2)
    st.update(a, j)
dp = [1] * N
for i in range(N - 1):
    here = dp[i]
    for ni in edge[i]:
        if ni < N:
            dp[ni] = max(dp[ni], dp[i] + 1)
print((max(dp)))

-    p0 = st.get(a, a + 1)
-    if p0 < N:
-        edge[j].add(p0)


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import sys

r = []

n = int(eval(input()))

l = sys.stdin.readlines()

for i in l:

  x, y, z = sorted([x*x for x in list(map(int, i.split()))])

  if x + y == z:

      print("YES")

  else:

      print("NO")

# optimized version of the same code:

import sys

n = int(input())

l = sys.stdin.readlines()

s = ""

for i in l:

  x, y, z = sorted(map(lambda x:x*x,map(int, i.split())))

  if x + y == z:

      s += "YES\n"

  else:

      s += "NO\n"

print(s,end="")

import sys

r = []
n = int(eval(input()))
l = sys.stdin.readlines()
for i in l:
    x, y, z = sorted([x * x for x in list(map(int, i.split()))])
    if x + y == z:
        print("YES")
    else:
        print("NO")

import sys

n = int(input())
l = sys.stdin.readlines()
s = ""
for i in l:
    x, y, z = sorted(map(lambda x: x * x, map(int, i.split())))
    if x + y == z:
        s += "YES\n"
    else:
        s += "NO\n"
print(s, end="")

-    x, y, z = sorted([x * x for x in list(map(int, i.split()))])

+    x, y, z = sorted(map(lambda x: x * x, map(int, i.split())))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import re

ptn = re.compile(r"(A|C|G|T)*")

S = eval(input())

ans = 0

for i in range(len(S)):

  for j in range(len(S)):

    x = ptn.match(S[i:i+j+1]).group(0)

    if(x):

      ans = max(ans, len(x))

print(ans)

# optimized version of the same code:

import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()

ni = lambda : int(ns())

na = lambda : list(map(int, stdin.readline().split()))

sys.setrecursionlimit(10 ** 7)

def check(In):

    return In != "A" and In != "C" and In != "G" and In != "T"

def main():

    s = ns()

    count = 0

    ans = 0

    for i in range(len(s)):

        if check(s[i]):

            count = 0

        else:

            count += 1

            ans = max(ans, count)

    print(ans)

if __name__ == '__main__':

    main()

import re

ptn = re.compile(r"(A|C|G|T)*")
S = eval(input())
ans = 0
for i in range(len(S)):
    for j in range(len(S)):
        x = ptn.match(S[i : i + j + 1]).group(0)
        if x:
            ans = max(ans, len(x))
print(ans)

import sys

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10**7)

def check(In):
    return In != "A" and In != "C" and In != "G" and In != "T"

def main():
    s = ns()
    count = 0
    ans = 0
    for i in range(len(s)):
        if check(s[i]):
            count = 0
        else:
            count += 1
            ans = max(ans, count)
    print(ans)

if __name__ == "__main__":
    main()

-        x = ptn.match(S[i : i + j + 1]).group(0)

+na = lambda: list(map(int, stdin.readline().split()))

+    return In != "A" and In != "C" and In != "G" and In != "T"


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

a, b, c, x, y = list(map(int, input().split()))

ab = c * 2

res = float("inf")

if a + b <= ab:

    res = x * a + y * b

else:

    if x == y:

        res = x * ab

    elif x > y:

        for i in range(y, x + 1):

            cost = i * ab + (x - i) * a

            res = min(res, cost)

    else:

        for i in range(x, y + 1):

            cost = i * ab + (y - i) * b

            res = min(res, cost)

print(res)

# optimized version of the same code:

import sys

sys.setrecursionlimit(10 ** 7)

input = sys.stdin.readline

f_inf = float('inf')

mod = 10 ** 9 + 7

def resolve():

    a, b, c, x, y = list(map(int, input().split()))

    c *= 2

    if a + b > c:

        cost1 = max(x, y) * c

        cost2 = min(x, y) * c

        plus = ((y - x) * b) if x < y else (x - y) * a

        res = min(cost1, cost2 + plus)

    else:

        res = x * a + y * b

    print(res)

if __name__ == '__main__':

    resolve()

import sys

sys.setrecursionlimit(10**7)
input = sys.stdin.readline
f_inf = float("inf")
mod = 10**9 + 7

def resolve():
    a, b, c, x, y = list(map(int, input().split()))
    c *= 2
    if a + b > c:
        cost1 = max(x, y) * c
        cost2 = min(x, y) * c
        plus = ((y - x) * b) if x < y else (x - y) * a
        res = min(cost1, cost2 + plus)
    else:
        res = x * a + y * b
    print(res)

if __name__ == "__main__":
    resolve()

-a, b, c, x, y = list(map(int, input().split()))

-            cost = i * ab + (x - i) * a

+    a, b, c, x, y = list(map(int, input().split()))

+        plus = ((y - x) * b) if x < y else (x - y) * a

-            cost = i * ab + (y - i) * b


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

a,b,c,x,y=list(map(int,input().split()))

ans=a*x+b*y

for ci in range(max(x,y)+1):

    sumc = 2*ci*c

    sumc += (x-ci)*a if (x-ci)>0 else 0

    sumc += (y-ci)*b if (y-ci)>0 else 0

    ans=min(ans,sumc)

print(ans)

# optimized version of the same code:

a,b,c,x,y=list(map(int,input().split()))

ans=a*x+b*y

if x==y:

    ans=min(ans,2*x*c)

elif x>y:

    ans=min(ans,a*(x-y)+2*y*c)

    ans=min(ans,2*x*c)

else:

    ans=min(ans,b*(y-x)+2*x*c)

    ans=min(ans,2*y*c)

print(ans)

a, b, c, x, y = list(map(int, input().split()))
ans = a * x + b * y
for ci in range(max(x, y) + 1):
    sumc = 2 * ci * c
    sumc += (x - ci) * a if (x - ci) > 0 else 0
    sumc += (y - ci) * b if (y - ci) > 0 else 0
    ans = min(ans, sumc)
print(ans)

a, b, c, x, y = list(map(int, input().split()))
ans = a * x + b * y
if x == y:
    ans = min(ans, 2 * x * c)
elif x > y:
    ans = min(ans, a * (x - y) + 2 * y * c)
    ans = min(ans, 2 * x * c)
else:
    ans = min(ans, b * (y - x) + 2 * x * c)
    ans = min(ans, 2 * y * c)
print(ans)

-    sumc += (x - ci) * a if (x - ci) > 0 else 0

-    sumc += (y - ci) * b if (y - ci) > 0 else 0

+    ans = min(ans, a * (x - y) + 2 * y * c)

+    ans = min(ans, b * (y - x) + 2 * x * c)


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

a=65280; b=61680; c=52428; d=43690; e=65535

from heapq import heappush, heappop

base = [a, b, c, d, e, 0]

Q = [(1, el) for el in base]

L = {el: 1 for el in base}

H = []

get = L.get

push = H.append

while Q:

    l, p = heappop(Q)

    if L[p] < l: continue

    if l+1 < get(p ^ e, 17):

        L[p ^ e] = l+1

        if l+1 < 16: heappush(Q, (l+1, p ^ e))

    if l+3 < 16:

        for q, r in H:

            if l+r+3 <= 16:

                if l+r+3 < get(p & q, 17):

                    L[p & q] = l+r+3

                    if l+r+3 < 16: heappush(Q, (l+r+3, p & q))

                if l+r+3 < get(p ^ q, 17):

                    L[p ^ q] = l+r+3

                    if l+r+3 < 16: heappush(Q, (l+r+3, p ^ q))

            else: break

    if l < 7: push((p, l))

print(*map(L.__getitem__, eval("e&%s"%",e&".join(open(0).read().replace(*"-~").replace(*"*&").replace(*"1e").split()[:-1]))),sep='\n')

# optimized version of the same code:

a=65280; b=61680; c=52428; d=43690; e=65535

from heapq import heappush, heappop

Q = [(1, a), (1, b), (1, c), (1, d)]

L = {a: 1, b: 1, c: 1, d: 1, e: 1, e: 1, 0: 1}

H = []

get = L.get

push = H.append

while Q:

    l, p = heappop(Q)

    if L[p] < l: continue

    if l+1 < get(p ^ e, 17):

        L[p ^ e] = l+1

        l < 15 and heappush(Q, (l+1, p ^ e))

    if l < 13:

        li = 13-l; l3 = 3+l

        for q, r in H:

            if r <= li:

                k = p & q

                if r < get(k, 17)-l3:

                    L[k] = l3+r

                    r < li and heappush(Q, (l3+r, k))

                k = p ^ q

                if r < get(k, 17)-l3:

                    L[k] = l3+r

                    r < li and heappush(Q, (l3+r, k))

            else: break

    if l < 7: push((p, l))

print(*map(L.__getitem__, eval("e&"+",e&".join(open(0).read().replace(*"-~").replace(*"*&").replace(*"1e").split()[:-1]))),sep='\n')

a = 65280
b = 61680
c = 52428
d = 43690
e = 65535
from heapq import heappush, heappop

base = [a, b, c, d, e, 0]
Q = [(1, el) for el in base]
L = {el: 1 for el in base}
H = []
get = L.get
push = H.append
while Q:
    l, p = heappop(Q)
    if L[p] < l:
        continue
    if l + 1 < get(p ^ e, 17):
        L[p ^ e] = l + 1
        if l + 1 < 16:
            heappush(Q, (l + 1, p ^ e))
    if l + 3 < 16:
        for q, r in H:
            if l + r + 3 <= 16:
                if l + r + 3 < get(p & q, 17):
                    L[p & q] = l + r + 3
                    if l + r + 3 < 16:
                        heappush(Q, (l + r + 3, p & q))
                if l + r + 3 < get(p ^ q, 17):
                    L[p ^ q] = l + r + 3
                    if l + r + 3 < 16:
                        heappush(Q, (l + r + 3, p ^ q))
            else:
                break
    if l < 7:
        push((p, l))
print(
    *map(
        L.__getitem__,
        eval(
            "e&%s"
            % ",e&".join(
                open(0).read().replace(*"-~").replace(*"*&").replace(*"1e").split()[:-1]
            )
        ),
    ),
    sep="\n"
)

a = 65280
b = 61680
c = 52428
d = 43690
e = 65535
from heapq import heappush, heappop

Q = [(1, a), (1, b), (1, c), (1, d)]
L = {a: 1, b: 1, c: 1, d: 1, e: 1, e: 1, 0: 1}
H = []
get = L.get
push = H.append
while Q:
    l, p = heappop(Q)
    if L[p] < l:
        continue
    if l + 1 < get(p ^ e, 17):
        L[p ^ e] = l + 1
        l < 15 and heappush(Q, (l + 1, p ^ e))
    if l < 13:
        li = 13 - l
        l3 = 3 + l
        for q, r in H:
            if r <= li:
                k = p & q
                if r < get(k, 17) - l3:
                    L[k] = l3 + r
                    r < li and heappush(Q, (l3 + r, k))
                k = p ^ q
                if r < get(k, 17) - l3:
                    L[k] = l3 + r
                    r < li and heappush(Q, (l3 + r, k))
            else:
                break
    if l < 7:
        push((p, l))
print(
    *map(
        L.__getitem__,
        eval(
            "e&"
            + ",e&".join(
                open(0).read().replace(*"-~").replace(*"*&").replace(*"1e").split()[:-1]
            )
        ),
    ),
    sep="\n"
)

-            heappush(Q, (l + 1, p ^ e))

+        l < 15 and heappush(Q, (l + 1, p ^ e))

-                        heappush(Q, (l + r + 3, p & q))

-                        heappush(Q, (l + r + 3, p ^ q))

+                    r < li and heappush(Q, (l3 + r, k))

+                    r < li and heappush(Q, (l3 + r, k))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import numpy as np

h, w = tuple(map(int, input().split()))

matrix = np.zeros((h, w), dtype=bool)

for i in range(h):

    row = np.array(list(input()))

    matrix[i, :] = row == "."

for i in range(h)[::-1]:

    if np.all(matrix[i, :]):

        matrix = np.delete(matrix, i, 0)

for i in range(w)[::-1]:

    if np.all(matrix[:, i]):

        matrix = np.delete(matrix, i, 1)

matrix = np.where(matrix, ".", "#")

for row in matrix:

    for e in row:

        print(e, end="")

    print()

# optimized version of the same code:

# h wの読み込み

h, w = list(map(int, input().split()))

# 行列作成

mat = [eval(input()) for _ in range(h)]

# #が含まれていない行を削除

[mat.remove(row) for row in mat[::-1] if ("#" not in row)]

# #が含まれている列のインデックスを取得

showCol = [i for i in range(w) if "#" in [row[i] for row in mat]]

# 表示

print(("\n".join(["".join([row[c] for c in showCol]) for row in mat])))

-h, w = tuple(map(int, input().split()))

-        matrix = np.delete(matrix, i, 0)

-        matrix = np.delete(matrix, i, 1)

+mat = [eval(input()) for _ in range(h)]

+# #が含まれていない行を削除

+[mat.remove(row) for row in mat[::-1] if ("#" not in row)]

+# #が含まれている列のインデックスを取得

+showCol = [i for i in range(w) if "#" in [row[i] for row in mat]]

+print(("\n".join(["".join([row[c] for c in showCol]) for row in mat])))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import numpy as np,sys

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))

def S(): return sys.stdin.readline().rstrip()

H,W = LI()

a = np.array([[s for s in S()] for _ in range(H)])

a = a[(a=='#').any(axis=1)]

a = a.T

a = a[(a=='#').any(axis=1)]

a = a.T.tolist()

for x in a:

    print(*x,sep='')

# optimized version of the same code:

import sys

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))

def S(): return sys.stdin.readline().rstrip()

H,W = LI()

a = [S() for _ in range(H)]

a2,a3 = [],[]

for x in a:

    if '#' in x:

        a2.append(x)

for y in zip(*a2):

    if '#' in y:

        a3.append(y)

for z in zip(*a3):

    print(*z,sep='')

import numpy as np, sys

def LI():
    return list(map(int, sys.stdin.readline().rstrip().split()))

def S():
    return sys.stdin.readline().rstrip()

H, W = LI()
a = np.array([[s for s in S()] for _ in range(H)])
a = a[(a == "#").any(axis=1)]
a = a.T
a = a[(a == "#").any(axis=1)]
a = a.T.tolist()
for x in a:
    print(*x, sep="")

import sys

def LI():
    return list(map(int, sys.stdin.readline().rstrip().split()))

def S():
    return sys.stdin.readline().rstrip()

H, W = LI()
a = [S() for _ in range(H)]
a2, a3 = [], []
for x in a:
    if "#" in x:
        a2.append(x)
for y in zip(*a2):
    if "#" in y:
        a3.append(y)
for z in zip(*a3):
    print(*z, sep="")

-a = np.array([[s for s in S()] for _ in range(H)])


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

def examB():

    N = I(); A = [I() for _ in range(N)]

    ans = 0; cur= 0

    for i in A:

        if i==0:

            ans += cur//2

            cur = 0

        else:

            cur += i

    ans += cur // 2

    print(ans)

    return

import sys,copy,bisect,itertools,heapq,math

from heapq import heappop,heappush,heapify

from collections import Counter,defaultdict,deque

def I(): return int(sys.stdin.readline())

def LI(): return list(map(int,sys.stdin.readline().split()))

def LSI(): return list(map(str,sys.stdin.readline().split()))

def LS(): return sys.stdin.readline().split()

def SI(): return sys.stdin.readline().strip()

mod = 10**9 + 7

inf = float('inf')

if __name__ == '__main__':

    examB()

# optimized version of the same code:

def examA():

    S = SI()

    if "W" in S and not "E" in S:

        print("No")

    elif "E" in S and not "W" in S:

        print("No")

    elif "N" in S and not "S" in S:

        print("No")

    elif "S" in S and not "N" in S:

        print("No")

    else:

        print("Yes")

    return

def examB():

    N = I()

    A = [I()for _ in range(N)]

    ans = 0

    for i in range(N-1):

        ans += A[i]//2

        if A[i]%2 and A[i+1]>=1:

            ans += 1

            A[i+1] -= 1

    ans += A[N-1]//2

    print(ans)

    return

def examC():

    ans = 0

    print(ans)

    return

def examD():

    N = I()

    S = [I()for _ in range(N)]

    ans = 0

    print(ans)

    return

def examE():

    ans = 0

    print(ans)

    return

def examF():

    ans = 0

    print(ans)

    return

import sys,bisect,itertools,heapq,math,random

from copy import deepcopy

from heapq import heappop,heappush,heapify

from collections import Counter,defaultdict,deque

def I(): return int(sys.stdin.readline())

def LI(): return list(map(int,sys.stdin.readline().split()))

def LSI(): return list(map(str,sys.stdin.readline().split()))

def LS(): return sys.stdin.readline().split()

def SI(): return sys.stdin.readline().strip()

global mod,mod2,inf,alphabet,_ep

mod = 10**9 + 7

mod2 = 998244353

inf = 10**18

_ep = 10**(-12)

alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**6)

if __name__ == '__main__':

    examB()

"""

"""

def examB():
    N = I()
    A = [I() for _ in range(N)]
    ans = 0
    cur = 0
    for i in A:
        if i == 0:
            ans += cur // 2
            cur = 0
        else:
            cur += i
    ans += cur // 2
    print(ans)
    return

import sys, copy, bisect, itertools, heapq, math
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque

def I():
    return int(sys.stdin.readline())

def LI():
    return list(map(int, sys.stdin.readline().split()))

def LSI():
    return list(map(str, sys.stdin.readline().split()))

def LS():
    return sys.stdin.readline().split()

def SI():
    return sys.stdin.readline().strip()

mod = 10**9 + 7
inf = float("inf")
if __name__ == "__main__":
    examB()

def examA():
    S = SI()
    if "W" in S and not "E" in S:
        print("No")
    elif "E" in S and not "W" in S:
        print("No")
    elif "N" in S and not "S" in S:
        print("No")
    elif "S" in S and not "N" in S:
        print("No")
    else:
        print("Yes")
    return

def examB():
    N = I()
    A = [I() for _ in range(N)]
    ans = 0
    for i in range(N - 1):
        ans += A[i] // 2
        if A[i] % 2 and A[i + 1] >= 1:
            ans += 1
            A[i + 1] -= 1
    ans += A[N - 1] // 2
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    N = I()
    S = [I() for _ in range(N)]
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys, bisect, itertools, heapq, math, random
from copy import deepcopy
from heapq import heappop, heappush, heapify
from collections import Counter, defaultdict, deque

def I():
    return int(sys.stdin.readline())

def LI():
    return list(map(int, sys.stdin.readline().split()))

def LSI():
    return list(map(str, sys.stdin.readline().split()))

def LS():
    return sys.stdin.readline().split()

def SI():
    return sys.stdin.readline().strip()

global mod, mod2, inf, alphabet, _ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10 ** (-12)
alphabet = [chr(ord("a") + i) for i in range(26)]
sys.setrecursionlimit(10**6)
if __name__ == "__main__":
    examB()
"""
"""

-import sys, copy, bisect, itertools, heapq, math

+import sys, bisect, itertools, heapq, math, random

+alphabet = [chr(ord("a") + i) for i in range(26)]


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

N = int(eval(input()))

L = [ 0 ] * 1000000

L[0] = 2

L[1] = 1

for i in range(2, N+1):

  L[i] = L[i-2] + L[i-1]

print((L[N]))

# optimized version of the same code:


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import sys

N,M=list(map(int,input().split()))

S=set(map(int,sys.stdin))

a,b=0,1

for i in range(1,N+1):

    if i in S:

        a,b=b,0

    else:

        a,b=b,a+b

print((b%(10**9+7)))

# optimized version of the same code:

import sys

N,M=list(map(int,input().split()))

bad=set(map(int,sys.stdin))

MOD=10**9+7

a,b=0,1

for i in range(1,N+1):

    if i in bad:

        a,b=b,0

        if a==0:

            break

    else:

        a,b=b,(a+b)%MOD

print(b)

import sys

N, M = list(map(int, input().split()))
S = set(map(int, sys.stdin))
a, b = 0, 1
for i in range(1, N + 1):
    if i in S:
        a, b = b, 0
    else:
        a, b = b, a + b
print((b % (10**9 + 7)))

import sys

N, M = list(map(int, input().split()))
bad = set(map(int, sys.stdin))
MOD = 10**9 + 7
a, b = 0, 1
for i in range(1, N + 1):
    if i in bad:
        a, b = b, 0
        if a == 0:
            break
    else:
        a, b = b, (a + b) % MOD
print(b)

-S = set(map(int, sys.stdin))
+bad = set(map(int, sys.stdin))
+MOD = 10**9 + 7
-    if i in S:
+    if i in bad:
+        if a == 0:
+            break
-        a, b = b, a + b
-print((b % (10**9 + 7)))
+        a, b = b, (a + b) % MOD
+print(b)


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import numpy as np

import itertools

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

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

cnt = 0

for i1, i2 in itertools.product(list(range(n)), list(range(n))):

    if i1 == i2:

        continue

    x1 = np.array(x[i1])

    x2 = np.array(x[i2])

    d = sum(list([x ** 2 for x in list(x1 - x2)])) ** 0.5

    if d == int(d):

        cnt += 1

print((int(cnt / 2)))

# optimized version of the same code:

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

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

cnt=0

for i in range(n-1):

 for j in range(i+1,n):

  l1=l[i]

  l2=l[j]

  sum=0

  for y,z in zip(l1,l2):

   sum+=(y-z)**2

  dist=sum**0.5

  if dist==int(dist):

   cnt+=1

print(cnt)

import numpy as np
import itertools

n, d = list(map(int, input().split()))
x = [list(map(int, input().split())) for i in range(n)]
cnt = 0
for i1, i2 in itertools.product(list(range(n)), list(range(n))):
    if i1 == i2:
        continue
    x1 = np.array(x[i1])
    x2 = np.array(x[i2])
    d = sum(list([x**2 for x in list(x1 - x2)])) ** 0.5
    if d == int(d):
        cnt += 1
print((int(cnt / 2)))

n, d = list(map(int, input().split()))
l = [list(map(int, input().split())) for i in range(n)]
cnt = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        l1 = l[i]
        l2 = l[j]
        sum = 0
        for y, z in zip(l1, l2):
            sum += (y - z) ** 2
        dist = sum**0.5
        if dist == int(dist):
            cnt += 1
print(cnt)

-x = [list(map(int, input().split())) for i in range(n)]

+l = [list(map(int, input().split())) for i in range(n)]

-for i1, i2 in itertools.product(list(range(n)), list(range(n))):

-    d = sum(list([x**2 for x in list(x1 - x2)])) ** 0.5


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import re

while True:

    n = int(input())

    if n == 0:

        break

    l = [0] * (24*60*60+1)

    for _ in range(n):

        h1,m1,s1,h2,m2,s2 = list(map(int, re.split(':| ', input())))

        l[h1*60*60 + m1*60 + s1] += 1

        l[h2*60*60 + m2*60 + s2] -= 1

    r = 0

    for i in range(24*60*60):

        l[i+1] += l[i]

        r = max(r, l[i+1])

    print(r)

# optimized version of the same code:

while True:

    n = int(input())

    if n == 0:

        break

    l = []

    for _ in range(n):

        hms1, hms2 = input().split()

        l.append((hms1, True))

        l.append((hms2, False))

    l.sort()

    r, t = 0, 0

    for i in range(len(l)):

        if l[i][1]:

            t += 1

        else:

            t -= 1

        r = max(r, t)

    print(r)

-        h1, m1, s1, h2, m2, s2 = list(map(int, re.split(":| ", input())))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

x = int(eval(input()))

for a in range(-118,119):

  for b in range(-119,118):

    if a**5 - b**5 == x:

      print((a,b))

      exit()

# optimized version of the same code:

x = int(eval(input()))

for i in range(0, 120):

  for j in range(-119, 120):

    if (i**5 - j**5) == x:

      print((i,j))

      exit()

x = int(eval(input()))
for a in range(-118, 119):
    for b in range(-119, 118):
        if a**5 - b**5 == x:
            print((a, b))
            exit()

x = int(eval(input()))
for i in range(0, 120):
    for j in range(-119, 120):
        if (i**5 - j**5) == x:
            print((i, j))
            exit()


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

N, K = list(map(int, input().split()))

S = eval(input())

nums = []

now = 1

cnt = 0

for i in range(N):

    if S[i] == str(now):

        cnt += 1

    else:

        nums.append(cnt)

        now = 1 - now

        cnt = 1

if cnt != 0:

    nums.append(cnt)

if len(nums) % 2 == 0:

    nums.append(0)

add = 2 * K + 1

ans = 0

left = 0

right = 0

tmp = 0

for i in range(0, len(nums), 2):

    next_left = i

    next_right = min(i + add, len(nums))

    while next_left > left:

        tmp -= nums[left]

        left += 1

    while next_right > right:

        tmp += nums[right]

        right += 1

    ans = max(ans, tmp)

print(ans)

# optimized version of the same code:

N, K = list(map(int, input().split()))

S = eval(input())

nums = []

now = 1

cnt = 0

for i in range(N):

    if S[i] == str(now):

        cnt += 1

    else:

        nums.append(cnt)

        now = 1 - now

        cnt = 1

if cnt != 0:

    nums.append(cnt)

if len(nums) % 2 == 0:

    nums.append(0)

csum = [0] * (len(nums) + 1)

for i in range(len(nums)):

    csum[i + 1] = csum[i] + nums[i]

add = 2 * K + 1

ans = 0

tmp = 0

for i in range(0, len(nums), 2):

    left = i

    right = min(i + add, len(nums))

    tmp = csum[right] - csum[left]

    ans = max(ans, tmp)

print(ans)

-    next_right = min(i + add, len(nums))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

import numpy as np

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

a=np.array([int(i) for i in input().split()])

bc=np.array([[int(i) for i in input().split()] for j in range(m)])

a.sort()

b=bc[:,0]

c=bc[:,1]

idx=np.argsort(c)

b=b[idx][::-1]

c=c[idx][::-1]

p=0

for b,c in zip(b,c):

    a[p:p+b]=np.maximum(a[p:p+b],c)

    p+=b

print((a.sum()))

# optimized version of the same code:

from heapq import heappop,heappush

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

a=[int(i) for i in input().split()]

a.sort()

bc=[[int(i) for i in input().split()]for j in range(m)]

bc=sorted(bc, key=lambda x:x[1],reverse=True)

ans=[]

for b,c in bc:

    while b>0 and a:

        x = heappop(a)

        if x<c:

            ans.append(c)

            b-=1

        else:

            ans.append(x)

print((sum(ans)+sum(a)))

import numpy as np

n, m = list(map(int, input().split()))
a = np.array([int(i) for i in input().split()])
bc = np.array([[int(i) for i in input().split()] for j in range(m)])
a.sort()
b = bc[:, 0]
c = bc[:, 1]
idx = np.argsort(c)
b = b[idx][::-1]
c = c[idx][::-1]
p = 0
for b, c in zip(b, c):
    a[p : p + b] = np.maximum(a[p : p + b], c)
    p += b
print((a.sum()))

from heapq import heappop, heappush

n, m = list(map(int, input().split()))
a = [int(i) for i in input().split()]
a.sort()
bc = [[int(i) for i in input().split()] for j in range(m)]
bc = sorted(bc, key=lambda x: x[1], reverse=True)
ans = []
for b, c in bc:
    while b > 0 and a:
        x = heappop(a)
        if x < c:
            ans.append(c)
            b -= 1
        else:
            ans.append(x)
print((sum(ans) + sum(a)))

-a = np.array([int(i) for i in input().split()])

-bc = np.array([[int(i) for i in input().split()] for j in range(m)])

-    a[p : p + b] = np.maximum(a[p : p + b], c)

+bc = [[int(i) for i in input().split()] for j in range(m)]

+bc = sorted(bc, key=lambda x: x[1], reverse=True)


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

n,m,l=list(map(int,input().split()))

e=[input().split()for _ in[0]*(n+m)]

for c in e[:n]:print((*[sum(int(s)*int(t)for s,t in zip(c,l))for l in zip(*e[n:])]))

# optimized version of the same code:

import sys

n,m,l=list(map(int,input().split()))

e=[list(map(int,e.split()))for e in sys.stdin]

for c in e[:n]:print((*[sum(s*t for s,t in zip(c,l))for l in zip(*e[n:])]))

n, m, l = list(map(int, input().split()))
e = [input().split() for _ in [0] * (n + m)]
for c in e[:n]:
    print((*[sum(int(s) * int(t) for s, t in zip(c, l)) for l in zip(*e[n:])]))

import sys

n, m, l = list(map(int, input().split()))
e = [list(map(int, e.split())) for e in sys.stdin]
for c in e[:n]:
    print((*[sum(s * t for s, t in zip(c, l)) for l in zip(*e[n:])]))

-e = [input().split() for _ in [0] * (n + m)]

+e = [list(map(int, e.split())) for e in sys.stdin]

-    print((*[sum(int(s) * int(t) for s, t in zip(c, l)) for l in zip(*e[n:])]))

+    print((*[sum(s * t for s, t in zip(c, l)) for l in zip(*e[n:])]))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

n=int(eval(input()))

s=list(map(str,input().split()))

total=[]

for i in range(n):

    if s[i] not in total:

        total.append(s[i])

print(('Three' if len(total)==3 else 'Four'))

# optimized version of the same code:

eval(input())

l=list(map(str,input().split()))

print(('Three' if len(set(l))==3 else 'Four'))

n = int(eval(input()))
s = list(map(str, input().split()))
total = []
for i in range(n):
    if s[i] not in total:
        total.append(s[i])
print(("Three" if len(total) == 3 else "Four"))

eval(input())
l = list(map(str, input().split()))
print(("Three" if len(set(l)) == 3 else "Four"))

-print(("Three" if len(total) == 3 else "Four"))

+print(("Three" if len(set(l)) == 3 else "Four"))


Input:
# slower version:

s = input()
for i in range(len(s)):
  if i%2 == 0:
    print(s[i], end = '')

# optimized version of the same code:

s = input()
ans = ''
for i in range(len(s)):
  if i % 2 == 0:
    ans += s[i]
print(ans)

# slower version:

from scipy.sparse.csgraph import dijkstra as di

from itertools import permutations

N,M,R = list(map(int, input().split()))

r = list(map(int, input().split()))

route = [[0 for i in range(N)] for j in range(N)]

for i in range(M):

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

    route[a-1][b-1] = route[b-1][a-1] = c

# for i in range(N):

#     print(route[i])

p_route = di(route)

# print(p_route)

mn = float('INF')

for tmp in permutations(r):

    t_sum = 0

    for i in range(len(tmp)-1):

        t_sum += p_route[tmp[i]-1][tmp[i+1]-1]

    if t_sum < mn:

        mn = t_sum

print((int(mn)))

# optimized version of the same code:

from itertools import permutations as perm

from scipy.sparse.csgraph import dijkstra as di

def warshall(d, n):

    for k in range(n):

        for i in range(n):

            for j in range(n):

                if d[i][k] + d[k][j] < d[i][j]:

                    d[i][j] = d[i][k] + d[k][j]

n,m,r = list(map(int, input().split()))

rr = [i-1 for i in map(int, input().split())]

inf = float('INF')

route = [[0 for j in range(n)] for i in range(n)]

for _ in range(m):

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

    route[a-1][b-1] = route[b-1][a-1] = c

route = di(route, n)

ans = inf

for tmp in perm(rr):

    cost = 0

    for i in range(r-1):

        cost += route[tmp[i]][tmp[i+1]]

    if cost < ans:

        ans = cost

print((int(ans)))

from scipy.sparse.csgraph import dijkstra as di
from itertools import permutations

N, M, R = list(map(int, input().split()))
r = list(map(int, input().split()))
route = [[0 for i in range(N)] for j in range(N)]
for i in range(M):
    a, b, c = list(map(int, input().split()))
    route[a - 1][b - 1] = route[b - 1][a - 1] = c
# for i in range(N):
#     print(route[i])
p_route = di(route)
# print(p_route)
mn = float("INF")
for tmp in permutations(r):
    t_sum = 0
    for i in range(len(tmp) - 1):
        t_sum += p_route[tmp[i] - 1][tmp[i + 1] - 1]
    if t_sum < mn:
        mn = t_sum
print((int(mn)))

from itertools import permutations as perm
from scipy.sparse.csgraph import dijkstra as di

def warshall(d, n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if d[i][k] + d[k][j] < d[i][j]:
                    d[i][j] = d[i][k] + d[k][j]

n, m, r = list(map(int, input().split()))
rr = [i - 1 for i in map(int, input().split())]
inf = float("INF")
route = [[0 for j in range(n)] for i in range(n)]
for _ in range(m):
    a, b, c = list(map(int, input().split()))
    route[a - 1][b - 1] = route[b - 1][a - 1] = c
route = di(route, n)
ans = inf
for tmp in perm(rr):
    cost = 0
    for i in range(r - 1):
        cost += route[tmp[i]][tmp[i + 1]]
    if cost < ans:
        ans = cost
print((int(ans)))

+from itertools import permutations as perm

-N, M, R = list(map(int, input().split()))

-route = [[0 for i in range(N)] for j in range(N)]

+n, m, r = list(map(int, input().split()))

+rr = [i - 1 for i in map(int, input().split())]

+route = [[0 for j in range(n)] for i in range(n)]

+        cost += route[tmp[i]][tmp[i + 1]]