I found an interesting problem on https://atcoder.jp/contests/abc061/tasks/abc061_d:
There is a directed graph with N vertices and M edges.
The i-th edge (1≤i≤M) points from vertex a_i to vertex b_i, and has a weight c_i.
We will play the following single-player game using this graph and a piece.
Initially, the piece is placed at vertex 1, and the score of the player is set to 0.
The player can move the piece as follows:
 - When the piece is placed at vertex a_i, move the piece along the i-th edge to vertex b_i. After this move, the score of the player is increased by c_i.
The player can end the game only when the piece is placed at vertex N.
The given graph guarantees that it is possible to traverse from vertex 1 to vertex N.
When the player acts optimally to maximize the score at the end of the game, what will the score be?
If it is possible to increase the score indefinitely, print inf.

-----Constraints-----
 - 2≤N≤1000
 - 1≤M≤min(N(N-1),2000)
 - 1≤a_i,b_i≤N (1≤i≤M)
 - a_i≠b_i (1≤i≤M)
 - a_i≠a_j or b_i≠b_j (1≤i<j≤M)
 - -10^9≤c_i≤10^9 (1≤i≤M)
 - c_i is an integer.
 - In the given graph, there exists a path from vertex 1 to vertex N.

-----Input-----
Input is given from Standard Input in the following format:
N M
a_1 b_1 c_1
a_2 b_2 c_2
:
a_M b_M c_M

-----Output-----
Print the maximum possible score at the end of the game, if it is finite. If it is possible to increase the score indefinitely, print inf.

-----Sample Input-----
3 3
1 2 4
2 3 3
1 3 5

-----Sample Output-----
7

There are two ways to move the piece to vertex N=3:
 - vertex 1 → vertex 2 → vertex 3 : score 4+3=7
 - vertex 1 → vertex 3 : score 5
Thus, the maximum possible score at the end of the game is 7.

I tried it in Python, but could not do it. Can you solve it?

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

def bellman_ford(s):
    d = [float('inf')] * n
    d[s] = 0
    # 注意点として、閉路を探索(=スコアが更新されたか確かめる)ためにn*2回実行する必要がある
    for i in range(n*2):
        for edge in g:
            if edge[0] != float('inf') and d[edge[1]] > d[edge[0]] + edge[2]:
                d[edge[1]] = d[edge[0]] + edge[2]
                if i>=n-1 and edge[1] == n-1:
                    return -1
    return d

g = []
for _ in range(m):
    a,b,c = list(map(int, input().split()))
    a -= 1
    b -= 1
    c *= -1
    g.append([a,b,c])

ret = bellman_ford(0)

if isinstance(ret, list):
    print((-1 * ret[n-1]))
else:
    print('inf')


I found an interesting problem on https://atcoder.jp/contests/abc062/tasks/abc062_a:
Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below.
Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.

-----Constraints-----
 - x and y are integers.
 - 1 ≤ x < y ≤ 12

-----Input-----
Input is given from Standard Input in the following format:
x y

-----Output-----
If x and y belong to the same group, print Yes; otherwise, print No.

-----Sample Input-----
1 3

-----Sample Output-----
Yes

I tried it in Python, but could not do it. Can you solve it?


I found an interesting problem on https://atcoder.jp/contests/abc062/tasks/abc062_b:
You are given a image with a height of H pixels and a width of W pixels.
Each pixel is represented by a lowercase English letter.
The pixel at the i-th row from the top and j-th column from the left is a_{ij}.
Put a box around this image and output the result. The box should consist of # and have a thickness of 1.

-----Constraints-----
 - 1 ≤ H, W ≤ 100
 - a_{ij} is a lowercase English letter.

-----Input-----
Input is given from Standard Input in the following format:
H W
a_{11} ... a_{1W}
:
a_{H1} ... a_{HW}

-----Output-----
Print the image surrounded by a box that consists of # and has a thickness of 1.

-----Sample Input-----
2 3
abc
arc

-----Sample Output-----
#####
#abc#
#arc#
#####

I tried it in Python, but could not do it. Can you solve it?

with open(0) as f:
    H, W, *a = f.read().split()
W = int(W)
a.insert(0,'#'*W)
a.append('#'*W)
for x in a:
    print(('#' + x.rstrip('\n') + '#'))


I found an interesting problem on https://atcoder.jp/contests/abc062/tasks/arc074_a:
There is a bar of chocolate with a height of H blocks and a width of W blocks.
Snuke is dividing this bar into exactly three pieces.
He can only cut the bar along borders of blocks, and the shape of each piece must be a rectangle.
Snuke is trying to divide the bar as evenly as possible.
More specifically, he is trying to minimize S_{max} - S_{min}, where S_{max} is the area (the number of blocks contained) of the largest piece, and S_{min} is the area of the smallest piece.
Find the minimum possible value of S_{max} - S_{min}.

-----Constraints-----
 - 2 ≤ H, W ≤ 10^5

-----Input-----
Input is given from Standard Input in the following format:
H W

-----Output-----
Print the minimum possible value of S_{max} - S_{min}.

-----Sample Input-----
3 5

-----Sample Output-----
0

In the division below, S_{max} - S_{min} = 5 - 5 = 0.

I tried it in Python, but could not do it. Can you solve it?

import sys
readline = sys.stdin.readline
from math import floor, ceil

def main():
    H, W = map(int, readline().rstrip().split())
    ans = H * W
    if H >= 3:
        ans = min(ans, abs(W*(H//3) - W*(H-H//3*2)))
    if W >= 3:
        ans = min(ans, abs(H*(W//3) - H*(W-W//3*2)))

    # 縦にスライス + 残りに横にスライス
    # x1_cand = [floor(W/3), ceil(W/3)]
    x1_cand = [i for i in range(1, W)]
    y1 = H
    for x1 in x1_cand:
        x2 = W - x1
        x3 = x2
        y2 = H // 2
        y3 = H - y2
        ans = min(ans, max((x1*y1), (x2*y2), (x3*y3)) - min((x1*y1), (x2*y2), (x3*y3)))

        x2 = (W-x1) // 2
        x3 = (W-x1-x2)
        ans = min(ans, max((x1*H), (x2*H), (x3*H)) - min((x1*H), (x2*H), (x3*H)))

    # 横にスライス + 残りに縦にスライス
    # y1_cand = [floor(H/3), ceil(H/3)]
    y1_cand = [i for i in range(1, H)]
    x1 = W
    for y1 in y1_cand:
        y2 = H - y1
        y3 = y2
        x2 = W // 2
        x3 = W - x2
        ans = min(ans, max((x1*y1), (x2*y2), (x3*y3)) - min((x1*y1), (x2*y2), (x3*y3)))

        y2 = (H-y1) // 2
        y3 = (H-y1-y2)
        ans = min(ans, max((W*y1), (W*y2), (W*y3)) - min((W*y1), (W*y2), (W*y3)))

    print(ans)

def __starting_point():
    main()
__starting_point()


I found an interesting problem on https://atcoder.jp/contests/abc062/tasks/arc074_b:
Let N be a positive integer.
There is a numerical sequence of length 3N, a = (a_1, a_2, ..., a_{3N}).
Snuke is constructing a new sequence of length 2N, a', by removing exactly N elements from a without changing the order of the remaining elements.
Here, the score of a' is defined as follows: (the sum of the elements in the first half of a') - (the sum of the elements in the second half of a').
Find the maximum possible score of a'.

-----Constraints-----
 - 1 ≤ N ≤ 10^5
 - a_i is an integer.
 - 1 ≤ a_i ≤ 10^9

-----Partial Score-----
 - In the test set worth 300 points, N ≤ 1000.

-----Input-----
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{3N}

-----Output-----
Print the maximum possible score of a'.

-----Sample Input-----
2
3 1 4 1 5 9

-----Sample Output-----
1

When a_2 and a_6 are removed, a' will be (3, 4, 1, 5), which has a score of (3 + 4) - (1 + 5) = 1.

I tried it in Python, but could not do it. Can you solve it?

from heapq import heappop, heappush

inf = float('inf')

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

# sum_max[k] : [0,k)のうちN個までの総和の最大値
# sum_min[k] : (3N-1-k,3N-1]のうちN個までの総和の最小値
sum_max = [0]*(3*N+1)
sum_min = [0]*(3*N+1)

def init_max():
    res = 0
    hq = []
    for i, a in enumerate(A):
        if len(hq) < N:
            heappush(hq,a)
            res += a
        else:
            if hq[0] < a:
                res -= heappop(hq)
                heappush(hq,a)
                res += a
        sum_max[i+1] = res

def init_min():
    res = 0
    hq = []
    for i, a in enumerate(A[::-1]):
        if len(hq) < N:
            heappush(hq,-a)
            res += a
        else:
            if -hq[0] > a:
                res -= -heappop(hq)
                heappush(hq,-a)
                res += a
        sum_min[i+1] = res

init_max()
init_min()

ans = -inf

for k in range(N,2*N+1):
    res = sum_max[k] - sum_min[3*N-k]
    ans = max(ans, res)

print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc063/tasks/abc063_a:
You are given two integers A and B as the input. Output the value of A + B.
However, if A + B is 10 or greater, output error instead.

-----Constraints-----
 - A and B are integers.
 - 1 ≤ A, B ≤ 9

-----Input-----
Input is given from Standard Input in the following format:
A B

-----Output-----
If A + B is 10 or greater, print the string error (case-sensitive); otherwise, print the value of A + B.

-----Sample Input-----
6 3

-----Sample Output-----
9

I tried it in Python, but could not do it. Can you solve it?

# 二つの整数A,Bの和 10以上ならerrorと出力

A, B = map(int, input().split())

if A + B < 10:
    print(A + B)
else:
    print('error')


I found an interesting problem on https://atcoder.jp/contests/abc063/tasks/abc063_b:
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.

-----Constraints-----
 - 2 ≤ |S| ≤ 26, where |S| denotes the length of S.
 - S consists of lowercase English letters.

-----Input-----
Input is given from Standard Input in the following format:
S

-----Output-----
If all the characters in S are different, print yes (case-sensitive); otherwise, print no.

-----Sample Input-----
uncopyrightable

-----Sample Output-----
yes

I tried it in Python, but could not do it. Can you solve it?

s = input()
print("yes" if len(s)==len(set(s)) else "no")


I found an interesting problem on https://atcoder.jp/contests/abc063/tasks/arc075_a:
You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of the points allocated to questions that are answered correctly. When you finish answering the questions, your answers will be immediately judged and your grade will be displayed... if everything goes well.
However, the examination system is actually flawed, and if your grade is a multiple of 10, the system displays 0 as your grade. Otherwise, your grade is displayed correctly. In this situation, what is the maximum value that can be displayed as your grade?

-----Constraints-----
 - All input values are integers.
 - 1 ≤ N ≤ 100
 - 1 ≤ s_i ≤ 100

-----Input-----
Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N

-----Output-----
Print the maximum value that can be displayed as your grade.

-----Sample Input-----
3
5
10
15

-----Sample Output-----
25

Your grade will be 25 if the 10-point and 15-point questions are answered correctly and the 5-point question is not, and this grade will be displayed correctly. Your grade will become 30 if the 5-point question is also answered correctly, but this grade will be incorrectly displayed as 0.

I tried it in Python, but could not do it. Can you solve it?

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

s.sort()
mod = [i%10 for i in s]
ans = sum(s)

if ans%10 == 0:
    if mod.count(0)==N:
        ans=0
    else:
        for i in range(N):
            if mod[i]!=0:
                ans -=s[i]
                break

print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc063/tasks/arc075_b:
You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health, and the health of the i-th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below.
Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:
 - Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A, and the health of each of the other monsters will decrease by B. Here, A and B are predetermined parameters, and A > B holds.
At least how many explosions do you need to cause in order to vanish all the monsters?

-----Constraints-----
 - All input values are integers.
 - 1 ≤ N ≤ 10^5
 - 1 ≤ B < A ≤ 10^9
 - 1 ≤ h_i ≤ 10^9

-----Input-----
Input is given from Standard Input in the following format:
N A B
h_1
h_2
:
h_N

-----Output-----
Print the minimum number of explosions that needs to be caused in order to vanish all the monsters.

-----Sample Input-----
4 5 3
8
7
4
2

-----Sample Output-----
2

You can vanish all the monsters in two explosion, as follows:
 - First, cause an explosion centered at the monster with 8 health. The healths of the four monsters become 3, 4, 1 and -1, respectively, and the last monster vanishes.
 - Second, cause an explosion centered at the monster with 4 health remaining. The healths of the three remaining monsters become 0, -1 and -2, respectively, and all the monsters are now vanished.

I tried it in Python, but could not do it. Can you solve it?

N,A,B = list(map(int,input().split()))
H = []
for _ in range(N):
    H.append(int(input()))
H = sorted(H)
def check(x):
    cnt = 0
    for h in H:
        if h > x * B:
            tmp = (h - x*B) // (A-B)
            #切り上げ
            if tmp * (A-B) != h - x*B: tmp += 1
            cnt += tmp
    if cnt <= x:
        return True
    else:
        return False
# (l,r]
def bisect(l,r):
    if r - l == 1: return r
    mid = (l+r) // 2
    if check(mid):
        return bisect(l,mid)
    else:
        return bisect(mid,r)

print((bisect(0,10**20)))


I found an interesting problem on https://atcoder.jp/contests/abc064/tasks/abc064_a:
AtCoDeer has three cards, one red, one green and one blue.

An integer between 1 and 9 (inclusive) is written on each card: r on the red card, g on the green card and b on the blue card.

We will arrange the cards in the order red, green and blue from left to right, and read them as a three-digit integer.

Is this integer a multiple of 4?

-----Constraints-----
 - 1 ≤ r, g, b ≤ 9

-----Input-----
Input is given from Standard Input in the following format:
r g b

-----Output-----
If the three-digit integer is a multiple of 4, print YES (case-sensitive); otherwise, print NO.

-----Sample Input-----
4 3 2

-----Sample Output-----
YES

432 is a multiple of 4, and thus YES should be printed.

I tried it in Python, but could not do it. Can you solve it?

a, b, c = map(int, input().split())
x = str(a) + str(b) + str(c)
if int(x) % 4 == 0:
  print('YES')
else:
  print('NO')


I found an interesting problem on https://atcoder.jp/contests/abc064/tasks/abc064_b:
It is only six months until Christmas, and AtCoDeer the reindeer is now planning his travel to deliver gifts.

There are N houses along TopCoDeer street. The i-th house is located at coordinate a_i. He has decided to deliver gifts to all these houses.

Find the minimum distance to be traveled when AtCoDeer can start and end his travel at any positions.

-----Constraints-----
 - 1 ≤ N ≤ 100
 - 0 ≤ a_i ≤ 1000
 - a_i is an integer.

-----Input-----
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N

-----Output-----
Print the minimum distance to be traveled.

-----Sample Input-----
4
2 3 7 9

-----Sample Output-----
7

The travel distance of 7 can be achieved by starting at coordinate 9 and traveling straight to coordinate 2.

It is not possible to do with a travel distance of less than 7, and thus 7 is the minimum distance to be traveled.

I tried it in Python, but could not do it. Can you solve it?

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

distance = 0

for i in range(N - 1):
    distance += a[i + 1] - a[i]

print(distance)


I found an interesting problem on https://atcoder.jp/contests/abc064/tasks/abc064_c:
In AtCoder, a person who has participated in a contest receives a color, which corresponds to the person's rating as follows:
 - Rating 1-399 : gray
 - Rating 400-799 : brown
 - Rating 800-1199 : green
 - Rating 1200-1599 : cyan
 - Rating 1600-1999 : blue
 - Rating 2000-2399 : yellow
 - Rating 2400-2799 : orange
 - Rating 2800-3199 : red
Other than the above, a person whose rating is 3200 or higher can freely pick his/her color, which can be one of the eight colors above or not.

Currently, there are N users who have participated in a contest in AtCoder, and the i-th user has a rating of a_i.

Find the minimum and maximum possible numbers of different colors of the users.

-----Constraints-----
 - 1 ≤ N ≤ 100
 - 1 ≤ a_i ≤ 4800
 - a_i is an integer.

-----Input-----
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N

-----Output-----
Print the minimum possible number of different colors of the users, and the maximum possible number of different colors, with a space in between.

-----Sample Input-----
4
2100 2500 2700 2700

-----Sample Output-----
2 2

The user with rating 2100 is "yellow", and the others are "orange". There are two different colors.

I tried it in Python, but could not do it. Can you solve it?

n = int(input())
a = list(map(int,input().split()))
rate = [0,399,799,1199,1599,1999,2399,2799,3199,4800]
cnt = [0]*9

for i in a:
    for j in range(1,len(rate)+1):
        if rate[j-1] < i <= rate[j]:
            cnt[j-1] += 1

fix = 0
flex = 0
for i,result in enumerate(cnt):
    if i == 8:
        flex = cnt[i]
    elif result > 0:
        fix += 1

if fix == 0 and flex >= 1:
    print(1,flex)
else:
    print(fix,fix+flex)


I found an interesting problem on https://atcoder.jp/contests/abc064/tasks/abc064_d:
You are given a string S of length N consisting of ( and ). Your task is to insert some number of ( and ) into S to obtain a correct bracket sequence.

Here, a correct bracket sequence is defined as follows:
 - () is a correct bracket sequence.
 - If X is a correct bracket sequence, the concatenation of (, X and ) in this order is also a correct bracket sequence.
 - If X and Y are correct bracket sequences, the concatenation of X and Y in this order is also a correct bracket sequence.
 - Every correct bracket sequence can be derived from the rules above.
Find the shortest correct bracket sequence that can be obtained. If there is more than one such sequence, find the lexicographically smallest one.

-----Constraints-----
 - The length of S is N.
 - 1 ≤ N ≤ 100
 - S consists of ( and ).

-----Input-----
Input is given from Standard Input in the following format:
N
S

-----Output-----
Print the lexicographically smallest string among the shortest correct bracket sequences that can be obtained by inserting some number of ( and ) into S.

-----Sample Input-----
3
())

-----Sample Output-----
(())

I tried it in Python, but could not do it. Can you solve it?

from collections import deque

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

left=0
right=0
for i in range(n):
  if s[i]=="(":
    left+=1
  else:
    if left>0:
      left-=1
    else:
      right+=1

for _ in range(left):
    s.append(")")

for _ in range(right):
    s.appendleft("(")

print("".join(s))


I found an interesting problem on https://atcoder.jp/contests/abc065/tasks/abc065_a:
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier.
He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though.
Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious.
Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it.
Write a program that outputs delicious if he found it delicious, safe if he did not found it delicious but did not get a stomachache either, and dangerous if he got a stomachache.

-----Constraints-----
 - 1 ≤ X,A,B ≤ 10^9

-----Input-----
Input is given from Standard Input in the following format:
X A B

-----Output-----
Print delicious if Takahashi found the food delicious; print safe if he neither found it delicious nor got a stomachache; print dangerous if he got a stomachache.

-----Sample Input-----
4 3 6

-----Sample Output-----
safe

He ate the food three days after the "best-by" date. It was not delicious or harmful for him.

I tried it in Python, but could not do it. Can you solve it?

X,A,B=map(int,input().split())

if A>=B:
  print('delicious')
else:
  if X>=B-A:
    print('safe')
  else:
    print('dangerous')


I found an interesting problem on https://atcoder.jp/contests/abc065/tasks/abc065_b:
Takahashi wants to gain muscle, and decides to work out at AtCoder Gym.
The exercise machine at the gym has N buttons, and exactly one of the buttons is lighten up.
These buttons are numbered 1 through N.
When Button i is lighten up and you press it, the light is turned off, and then Button a_i will be lighten up. It is possible that i=a_i.
When Button i is not lighten up, nothing will happen by pressing it.
Initially, Button 1 is lighten up. Takahashi wants to quit pressing buttons when Button 2 is lighten up.
Determine whether this is possible. If the answer is positive, find the minimum number of times he needs to press buttons.

-----Constraints-----
 - 2 ≤ N ≤ 10^5
 - 1 ≤ a_i ≤ N

-----Input-----
Input is given from Standard Input in the following format:
N
a_1
a_2
:
a_N

-----Output-----
Print -1 if it is impossible to lighten up Button 2.
Otherwise, print the minimum number of times we need to press buttons in order to lighten up Button 2.

-----Sample Input-----
3
3
1
2

-----Sample Output-----
2

Press Button 1, then Button 3.

I tried it in Python, but could not do it. Can you solve it?

N = int(input())
d = []
visited = [False for _ in range(N+1)]
for _ in range(N):
  d.append(int(input())-1)

i = 0
cnt = 0
while True:
  if i == 1:
    break
  elif cnt >= N:
    cnt = -1
    break
  elif visited[i]:
    cnt = -1
    break
  else:
    visited[i] = True
    cnt += 1
    i = d[i]

print(cnt)


I found an interesting problem on https://atcoder.jp/contests/abc065/tasks/arc076_a:
Snuke has N dogs and M monkeys. He wants them to line up in a row.
As a Japanese saying goes, these dogs and monkeys are on bad terms. ("ken'en no naka", literally "the relationship of dogs and monkeys", means a relationship of mutual hatred.) Snuke is trying to reconsile them, by arranging the animals so that there are neither two adjacent dogs nor two adjacent monkeys.
How many such arrangements there are? Find the count modulo 10^9+7 (since animals cannot understand numbers larger than that).
Here, dogs and monkeys are both distinguishable. Also, two arrangements that result from reversing each other are distinguished.

-----Constraints-----
 - 1 ≤ N,M ≤ 10^5

-----Input-----
Input is given from Standard Input in the following format:
N M

-----Output-----
Print the number of possible arrangements, modulo 10^9+7.

-----Sample Input-----
2 2

-----Sample Output-----
8

We will denote the dogs by A and B, and the monkeys by C and D. There are eight possible arrangements: ACBD, ADBC, BCAD, BDAC, CADB, CBDA, DACB and DBCA.

I tried it in Python, but could not do it. Can you solve it?

import sys
import math

mod = 10**9 + 7
N, M = map(int, sys.stdin.readline().split())
diff = abs(N - M)
if diff > 1:
    print(0)
    return

n_p = 1
for i in range(1, N+1):
    n_p *= i
    n_p %= mod
m_p = 1
for i in range(1, M+1):
    m_p *= i
    m_p %= mod

if diff == 0:
    print(2 * n_p * m_p % mod)
else:
    print(n_p * m_p % mod)


I found an interesting problem on https://atcoder.jp/contests/abc065/tasks/arc076_b:
There are N towns on a plane. The i-th town is located at the coordinates (x_i,y_i). There may be more than one town at the same coordinates.
You can build a road between two towns at coordinates (a,b) and (c,d) for a cost of min(|a-c|,|b-d|) yen (the currency of Japan). It is not possible to build other types of roads.
Your objective is to build roads so that it will be possible to travel between every pair of towns by traversing roads. At least how much money is necessary to achieve this?

-----Constraints-----
 - 2 ≤ N ≤ 10^5
 - 0 ≤ x_i,y_i ≤ 10^9
 - All input values are integers.

-----Input-----
Input is given from Standard Input in the following format:
N
x_1 y_1
x_2 y_2
:
x_N y_N

-----Output-----
Print the minimum necessary amount of money in order to build roads so that it will be possible to travel between every pair of towns by traversing roads.

-----Sample Input-----
3
1 5
3 9
7 8

-----Sample Output-----
3

Build a road between Towns 1 and 2, and another between Towns 2 and 3. The total cost is 2+1=3 yen.

I tried it in Python, but could not do it. Can you solve it?

# xの根を求める
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
#xとyの属する集合の併合
def unite(x,y):
    x = find(x)
    y = find(y)

    if x == y:
        return False
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

#xとyが同じ集合に属するかの判定
def same(x,y):
    return find(x) == find(y)

#xが属する集合の個数
def size(x):
    return -par[find(x)]
n = int(input())
#初期化
#根なら-size,子なら親の頂点
par = [-1]*n

p = [] #点p
edge = []
for i in range(n):
    x,y = map(int,input().split())
    p.append([x,y,i])
p.sort(key=lambda x:x[0])
for i in range(n-1):
    x_0,_,j=p[i]
    x_1,_,k=p[i+1]
    edge.append([x_1-x_0,j,k]) # 重みx_1 - x_0の点jと点kを繋ぐ辺
p.sort(key=lambda x:x[1])
for i in range(n-1):
    _,y_0,j=p[i]
    _,y_1,k=p[i+1]
    edge.append([y_1-y_0,j,k])

edge.sort() #クラスカル法を使うので重みでソート
ans = 0
for i in range(len(edge)):
    cost,u,v = edge[i]
    if not same(u,v):
        unite(u,v)
        ans+=cost
print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc066/tasks/abc066_a:
Snuke is buying a bicycle.
The bicycle of his choice does not come with a bell, so he has to buy one separately.
He has very high awareness of safety, and decides to buy two bells, one for each hand.
The store sells three kinds of bells for the price of a, b and c yen (the currency of Japan), respectively.
Find the minimum total price of two different bells.

-----Constraints-----
 - 1 \leq a,b,c \leq 10000
 - a, b and c are integers.

-----Input-----
Input is given from Standard Input in the following format:
a b c

-----Output-----
Print the minimum total price of two different bells.

-----Sample Input-----
700 600 780

-----Sample Output-----
1300

 - Buying a 700-yen bell and a 600-yen bell costs 1300 yen.
 - Buying a 700-yen bell and a 780-yen bell costs 1480 yen.
 - Buying a 600-yen bell and a 780-yen bell costs 1380 yen.
The minimum among these is 1300 yen.

I tried it in Python, but could not do it. Can you solve it?


I found an interesting problem on https://atcoder.jp/contests/abc066/tasks/abc066_b:
We will call a string that can be obtained by concatenating two equal strings an even string.
For example, xyzxyz and aaaaaa are even, while ababab and xyzxy are not.
You are given an even string S consisting of lowercase English letters.
Find the length of the longest even string that can be obtained by deleting one or more characters from the end of S.
It is guaranteed that such a non-empty string exists for a given input.

-----Constraints-----
 - 2 \leq |S| \leq 200
 - S is an even string consisting of lowercase English letters.
 - There exists a non-empty even string that can be obtained by deleting one or more characters from the end of S.

-----Input-----
Input is given from Standard Input in the following format:
S

-----Output-----
Print the length of the longest even string that can be obtained.

-----Sample Input-----
abaababaab

-----Sample Output-----
6

 - abaababaab itself is even, but we need to delete at least one character.
 - abaababaa is not even.
 - abaababa is not even.
 - abaabab is not even.
 - abaaba is even. Thus, we should print its length, 6.

I tried it in Python, but could not do it. Can you solve it?

S=input()

for i in range(1, len(S)):
  s=S[0:len(S)-i]
  #print(s)
  if len(s)%2==1:
    continue
  #print('pre', s[0:int(len(s)/2)+1])
  #print('follow', s[int(len(s)/2):len(s)])
  if s[0:int(len(s)/2)]==s[int(len(s)/2):len(s)]:
    print(len(S)-i)
    break


I found an interesting problem on https://atcoder.jp/contests/abc066/tasks/arc077_a:
You are given an integer sequence of length n, a_1, ..., a_n.
Let us consider performing the following n operations on an empty sequence b.
The i-th operation is as follows:
 - Append a_i to the end of b.
 - Reverse the order of the elements in b.
Find the sequence b obtained after these n operations.

-----Constraints-----
 - 1 \leq n \leq 2\times 10^5
 - 0 \leq a_i \leq 10^9
 - n and a_i are integers.

-----Input-----
Input is given from Standard Input in the following format:
n
a_1 a_2 ... a_n

-----Output-----
Print n integers in a line with spaces in between.
The i-th integer should be b_i.

-----Sample Input-----
4
1 2 3 4

-----Sample Output-----
4 2 1 3

 - After step 1 of the first operation, b becomes: 1.
 - After step 2 of the first operation, b becomes: 1.
 - After step 1 of the second operation, b becomes: 1, 2.
 - After step 2 of the second operation, b becomes: 2, 1.
 - After step 1 of the third operation, b becomes: 2, 1, 3.
 - After step 2 of the third operation, b becomes: 3, 1, 2.
 - After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.
 - After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.
Thus, the answer is 4 2 1 3.

I tried it in Python, but could not do it. Can you solve it?

n = int(input())
a = list(map(str, input().split()))
b = []
'''
b = [str(a[0])]
if (n == 1):
    print(a[0])
    return

a = a[1:]

for i in a:
    b.append(str(i))
    b.reverse()
'''
'''
loop = int(n / 2)
loop_rest = n - loop

for i in range(loop):
    tar_index = (n - 1) - 2 * i
    tar = a[tar_index]

    b.append(str(tar))

if (n % 2 == 0):
    tar_index = 0
else:
    tar_index = 1

for i in range(loop_rest):
    b.append(str(a[tar_index]))
    tar_index += 2
'''

# 一つおきでListを取る場合。
# a[0::2]
# 1つ目：起点。
# 2つ目：Step

# a[::-1]
# > -1step,つまりReverse

if n % 2 == 1:
    print((" ".join((a[0::2][::-1] + a[1::2]))))
else:
    print((" ".join((a[1::2][::-1] + a[0::2]))))


I found an interesting problem on https://atcoder.jp/contests/abc066/tasks/arc077_b:
You are given an integer sequence of length n+1, a_1,a_2,...,a_{n+1}, which consists of the n integers 1,...,n.
It is known that each of the n integers 1,...,n appears at least once in this sequence.
For each integer k=1,...,n+1, find the number of the different subsequences (not necessarily contiguous) of the given sequence with length k, modulo 10^9+7.

-----Notes-----
 - If the contents of two subsequences are the same, they are not separately counted even if they originate from different positions in the original sequence.
 - A subsequence of a sequence a with length k is a sequence obtained by selecting k of the elements of a and arranging them without changing their relative order. For example, the sequences 1,3,5 and 1,2,3 are subsequences of 1,2,3,4,5, while 3,1,2 and 1,10,100 are not.

-----Constraints-----
 - 1 \leq n \leq 10^5
 - 1 \leq a_i \leq n
 - Each of the integers 1,...,n appears in the sequence.
 - n and a_i are integers.

-----Input-----
Input is given from Standard Input in the following format:
n
a_1 a_2 ... a_{n+1}

-----Output-----
Print n+1 lines.
The k-th line should contain the number of the different subsequences of the given sequence with length k, modulo 10^9+7.

-----Sample Input-----
3
1 2 1 3

-----Sample Output-----
3
5
4
1

There are three subsequences with length 1: 1 and 2 and 3.
There are five subsequences with length 2: 1,1 and 1,2 and 1,3 and 2,1 and 2,3.
There are four subsequences with length 3: 1,1,3 and 1,2,1 and 1,2,3 and 2,1,3.
There is one subsequence with length 4: 1,2,1,3.

I tried it in Python, but could not do it. Can you solve it?

class Factorial():
    def __init__(self,n,mod):
        self.mod = mod
        self.factorial = [0 for _ in range(n+1)]
        self.inv = [0 for _ in range(n+1)]
        self.factorial[0] = 1
        for i in range(n):
            self.factorial[i+1] = self.factorial[i]*(i+1)%mod
        self.inv[n] = pow(self.factorial[n],mod-2,mod)
        for i in range(n)[::-1]:
            self.inv[i] = self.inv[i+1]*(i+1)%mod

    def comb(self,m,k):
        if m-k<0 or k<0: return 0
        return self.factorial[m]*self.inv[k]*self.inv[m-k]%self.mod

MOD = 1000000007

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

F = Factorial(N+1,MOD)

tmp = [None for _ in range(N)]

for i in range(N+1):
    if tmp[A[i]-1] is None:
        tmp[A[i]-1] = i
    else:
        a = tmp[A[i]-1]
        b = i
        break

A = []

for i in range(1,N+2):
    A.append((F.comb(N-1,i)+F.comb(N-1,i-2)+F.comb(N-1,i-1)*2-F.comb(N+a-b,i-1))%MOD)

print('\n'.join(map(str,A)))


I found an interesting problem on https://atcoder.jp/contests/abc067/tasks/abc067_a:
Snuke is giving cookies to his three goats.
He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins).
Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.

-----Constraints-----
 - 1 \leq A,B \leq 100
 - Both A and B are integers.

-----Input-----
Input is given from Standard Input in the following format:
A B

-----Output-----
If it is possible to give cookies so that each of the three goats can have the same number of cookies, print Possible; otherwise, print Impossible.

-----Sample Input-----
4 5

-----Sample Output-----
Possible

If Snuke gives nine cookies, each of the three goats can have three cookies.

I tried it in Python, but could not do it. Can you solve it?

A,B = map(int,input().split())

if A % 3 == 0 or B % 3 == 0 or (A + B) % 3 == 0:
    print('Possible')
else:
    print('Impossible')


I found an interesting problem on https://atcoder.jp/contests/abc067/tasks/abc067_b:
Snuke has N sticks.
The length of the i-th stick is l_i.
Snuke is making a snake toy by joining K of the sticks together.
The length of the toy is represented by the sum of the individual sticks that compose it.
Find the maximum possible length of the toy.

-----Constraints-----
 - 1 \leq K \leq N \leq 50
 - 1 \leq l_i \leq 50
 - l_i is an integer.

-----Input-----
Input is given from Standard Input in the following format:
N K
l_1 l_2 l_3 ... l_{N}

-----Output-----
Print the answer.

-----Sample Input-----
5 3
1 2 3 4 5

-----Sample Output-----
12

You can make a toy of length 12 by joining the sticks of lengths 3, 4 and 5, which is the maximum possible length.

I tried it in Python, but could not do it. Can you solve it?

n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse = True)
sum = 0
for i in range(k):
    sum = sum + a[i]
print(sum)


I found an interesting problem on https://atcoder.jp/contests/abc067/tasks/arc078_a:
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it.
They will share these cards.
First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards.
Here, both Snuke and Raccoon have to take at least one card.
Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively.
They would like to minimize |x-y|.
Find the minimum possible value of |x-y|.

-----Constraints-----
 - 2 \leq N \leq 2 \times 10^5
 - -10^{9} \leq a_i \leq 10^{9}
 - a_i is an integer.

-----Input-----
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_{N}

-----Output-----
Print the answer.

-----Sample Input-----
6
1 2 3 4 5 6

-----Sample Output-----
1

If Snuke takes four cards from the top, and Raccoon takes the remaining two cards, x=10, y=11, and thus |x-y|=1. This is the minimum possible value.

I tried it in Python, but could not do it. Can you solve it?

N=int(input())
a=list(map(int,input().split()))
ans=10000000000000000000
c=0
s=sum(a)
for i in range(N-1):
    c+=a[i]
    s-=a[i]
    if abs(c-s)<ans:
        ans=abs(c-s)
print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc068/tasks/abc068_a:
This contest, AtCoder Beginner Contest, is abbreviated as ABC.
When we refer to a specific round of ABC, a three-digit number is appended after ABC. For example, ABC680 is the 680th round of ABC.
What is the abbreviation for the N-th round of ABC? Write a program to output the answer.

-----Constraints-----
 - 100 ≤ N ≤ 999

-----Input-----
Input is given from Standard Input in the following format:
N

-----Output-----
Print the abbreviation for the N-th round of ABC.

-----Sample Input-----
100

-----Sample Output-----
ABC100

The 100th round of ABC is ABC100.

I tried it in Python, but could not do it. Can you solve it?


I found an interesting problem on https://atcoder.jp/contests/abc068/tasks/abc068_b:
Takahashi loves numbers divisible by 2.
You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique.
Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder.
For example,
 - 6 can be divided by 2 once: 6 -> 3.
 - 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1.
 - 3 can be divided by 2 zero times.

-----Constraints-----
 - 1 ≤ N ≤ 100

-----Input-----
Input is given from Standard Input in the following format:
N

-----Output-----
Print the answer.

-----Sample Input-----
7

-----Sample Output-----
4

4 can be divided by 2 twice, which is the most number of times among 1, 2, ..., 7.

I tried it in Python, but could not do it. Can you solve it?

n=int(input())
m = 0
i = 0
while 2**i <= n:
  m = max(m, 2**i)
  i += 1
print(m)


I found an interesting problem on https://atcoder.jp/contests/abc068/tasks/arc079_a:
In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands.
For convenience, we will call them Island 1, Island 2, ..., Island N.
There are M kinds of regular boat services between these islands.
Each service connects two islands. The i-th service connects Island a_i and Island b_i.
Cat Snuke is on Island 1 now, and wants to go to Island N.
However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services.
Help him.

-----Constraints-----
 - 3 ≤ N ≤ 200 000
 - 1 ≤ M ≤ 200 000
 - 1 ≤ a_i < b_i ≤ N
 - (a_i, b_i) \neq (1, N)
 - If i \neq j, (a_i, b_i) \neq (a_j, b_j).

-----Input-----
Input is given from Standard Input in the following format:
N M
a_1 b_1
a_2 b_2
:
a_M b_M

-----Output-----
If it is possible to go to Island N by using two boat services, print POSSIBLE; otherwise, print IMPOSSIBLE.

-----Sample Input-----
3 2
1 2
2 3

-----Sample Output-----
POSSIBLE

I tried it in Python, but could not do it. Can you solve it?

n,m=map(int,input().split())
x=[0]*n
s=0
for i in range(m):
    a,b=map(int,input().split())
    if a==1:
        if x[b-1]==0:
            x[b-1]=1
        elif x[b-1]==-1:
            s+=1
    elif b==n:
        if x[a-1]==0:
            x[a-1]=-1
        elif x[a-1]==1:
            s+=1
if s>0:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")


I found an interesting problem on https://atcoder.jp/contests/abc068/tasks/arc079_b:
We have a sequence of length N consisting of non-negative integers. Consider performing the following operation on this sequence until the largest element in this sequence becomes N-1 or smaller.
 - Determine the largest element in the sequence (if there is more than one, choose one). Decrease the value of this element by N, and increase each of the other elements by 1.
It can be proved that the largest element in the sequence becomes N-1 or smaller after a finite number of operations.
You are given an integer K. Find an integer sequence a_i such that the number of times we will perform the above operation is exactly K. It can be shown that there is always such a sequence under the constraints on input and output in this problem.

-----Constraints-----
 - 0 ≤ K ≤ 50 \times 10^{16}

-----Input-----
Input is given from Standard Input in the following format:
K

-----Output-----
Print a solution in the following format:
N
a_1 a_2 ... a_N

Here, 2 ≤ N ≤ 50 and 0 ≤ a_i ≤ 10^{16} + 1000 must hold.

-----Sample Input-----
0

-----Sample Output-----
4
3 3 3 3

I tried it in Python, but could not do it. Can you solve it?

K = int(input())

q, r = divmod(K, 50)

ans = [i + q for i in range(50)]
for i in range(1, r + 1):
    ans[-i] += 1

print((50))
print((*ans))


I found an interesting problem on https://atcoder.jp/contests/abc069/tasks/abc069_a:
In K-city, there are n streets running east-west, and m streets running north-south. Each street running east-west and each street running north-south cross each other. We will call the smallest area that is surrounded by four streets a block. How many blocks there are in K-city?

-----Constraints-----
 - 2 ≤ n, m ≤ 100

-----Input-----
Input is given from Standard Input in the following format:
n m

-----Output-----
Print the number of blocks in K-city.

-----Sample Input-----
3 4

-----Sample Output-----
6

There are six blocks, as shown below:

I tried it in Python, but could not do it. Can you solve it?

n, m = list(map(int, input().split()))
print(((n - 1) * (m - 1)))


I found an interesting problem on https://atcoder.jp/contests/abc069/tasks/abc069_b:
The word internationalization is sometimes abbreviated to i18n.
This comes from the fact that there are 18 letters between the first i and the last n.
You are given a string s of length at least 3 consisting of lowercase English letters.
Abbreviate s in the same way.

-----Constraints-----
 - 3 ≤ |s| ≤ 100 (|s| denotes the length of s.)
 - s consists of lowercase English letters.

-----Input-----
Input is given from Standard Input in the following format:
s

-----Output-----
Print the abbreviation of s.

-----Sample Input-----
internationalization

-----Sample Output-----
i18n

I tried it in Python, but could not do it. Can you solve it?


I found an interesting problem on https://atcoder.jp/contests/abc069/tasks/arc080_a:
We have a sequence of length N, a = (a_1, a_2, ..., a_N).
Each a_i is a positive integer.
Snuke's objective is to permute the element in a so that the following condition is satisfied:
 - For each 1 ≤ i ≤ N - 1, the product of a_i and a_{i + 1} is a multiple of 4.
Determine whether Snuke can achieve his objective.

-----Constraints-----
 - 2 ≤ N ≤ 10^5
 - a_i is an integer.
 - 1 ≤ a_i ≤ 10^9

-----Input-----
Input is given from Standard Input in the following format:
N
a_1 a_2 ... a_N

-----Output-----
If Snuke can achieve his objective, print Yes; otherwise, print No.

-----Sample Input-----
3
1 10 100

-----Sample Output-----
Yes

One solution is (1, 100, 10).

I tried it in Python, but could not do it. Can you solve it?

n=int(input())
a=list(map(int,input().split()))
s=0
t=0
u=0
for i in range(n):
  if a[i]%4==0:
    s=s+1
  elif a[i]%2==0:
    t=t+1
  else:
    u=u+1
if t>=1:
  if s>=u:
    print("Yes")
  else:
    print("No")
else:
  if s-u>=-1:
    print("Yes")
  else:
    print("No")


I found an interesting problem on https://atcoder.jp/contests/abc069/tasks/arc080_b:
We have a grid with H rows and W columns of squares.
Snuke is painting these squares in colors 1, 2, ..., N.
Here, the following conditions should be satisfied:
 - For each i (1 ≤ i ≤ N), there are exactly a_i squares painted in Color i. Here, a_1 + a_2 + ... + a_N = H W.
 - For each i (1 ≤ i ≤ N), the squares painted in Color i are 4-connected. That is, every square painted in Color i can be reached from every square painted in Color i by repeatedly traveling to a horizontally or vertically adjacent square painted in Color i.
Find a way to paint the squares so that the conditions are satisfied.
It can be shown that a solution always exists.

-----Constraints-----
 - 1 ≤ H, W ≤ 100
 - 1 ≤ N ≤ H W
 - a_i ≥ 1
 - a_1 + a_2 + ... + a_N = H W

-----Input-----
Input is given from Standard Input in the following format:
H W
N
a_1 a_2 ... a_N

-----Output-----
Print one way to paint the squares that satisfies the conditions.
Output in the following format:
c_{1 1} ... c_{1 W}
:
c_{H 1} ... c_{H W}

Here, c_{i j} is the color of the square at the i-th row from the top and j-th column from the left.

-----Sample Input-----
2 2
3
2 1 1

-----Sample Output-----
1 1
2 3

Below is an example of an invalid solution:
1 2
3 1

This is because the squares painted in Color 1 are not 4-connected.

I tried it in Python, but could not do it. Can you solve it?

def main():
	H, W = [int(x) for x in input().split(" ")]
	N = int(input())
	A = [int(a) for a in input().split(" ")]
	c = [[0] * W for i in range(H)]
	k = 0
	for i in range(len(c)):
		for j in range(len(c[i])):
			if i % 2 == 0:
				c[i][j] = str(k + 1)
				A[k] -= 1
			elif i % 2 == 1:
				c[i][-j-1] = str(k + 1)
				A[k] -= 1
			if A[k] == 0:
				k += 1
	print("\n".join([" ".join(ci) for ci in c]))

main()


I found an interesting problem on https://atcoder.jp/contests/abc070/tasks/abc070_a:
You are given a three-digit positive integer N.

Determine whether N is a palindromic number.

Here, a palindromic number is an integer that reads the same backward as forward in decimal notation.

-----Constraints-----
 - 100≤N≤999
 - N is an integer.

-----Input-----
Input is given from Standard Input in the following format:
N

-----Output-----
If N is a palindromic number, print Yes; otherwise, print No.

-----Sample Input-----
575

-----Sample Output-----
Yes

N=575 is also 575 when read backward, so it is a palindromic number. You should print Yes.

I tried it in Python, but could not do it. Can you solve it?

N = input()
print('Yes' if N[0] == N[2] else 'No')


I found an interesting problem on https://atcoder.jp/contests/abc070/tasks/abc070_b:
Alice and Bob are controlling a robot. They each have one switch that controls the robot.

Alice started holding down her button A second after the start-up of the robot, and released her button B second after the start-up.

Bob started holding down his button C second after the start-up, and released his button D second after the start-up.

For how many seconds both Alice and Bob were holding down their buttons?

-----Constraints-----
 - 0≤A<B≤100
 - 0≤C<D≤100
 - All input values are integers.

-----Input-----
Input is given from Standard Input in the following format:
A B C D

-----Output-----
Print the length of the duration (in seconds) in which both Alice and Bob were holding down their buttons.

-----Sample Input-----
0 75 25 100

-----Sample Output-----
50

Alice started holding down her button 0 second after the start-up of the robot, and released her button 75 second after the start-up.

Bob started holding down his button 25 second after the start-up, and released his button 100 second after the start-up.

Therefore, the time when both of them were holding down their buttons, is the 50 seconds from 25 seconds after the start-up to 75 seconds after the start-up.

I tried it in Python, but could not do it. Can you solve it?

A, B, C, D = map(int, input().split())
x = min(B, D) - max(A, C)
print(x) if x > 0 else print(0)


I found an interesting problem on https://atcoder.jp/contests/abc070/tasks/abc070_c:
We have N clocks. The hand of the i-th clock (1≤i≤N) rotates through 360° in exactly T_i seconds.

Initially, the hand of every clock stands still, pointing directly upward.

Now, Dolphin starts all the clocks simultaneously.

In how many seconds will the hand of every clock point directly upward again?

-----Constraints-----
 - 1≤N≤100
 - 1≤T_i≤10^{18}
 - All input values are integers.
 - The correct answer is at most 10^{18} seconds.

-----Input-----
Input is given from Standard Input in the following format:
N
T_1
:
T_N

-----Output-----
Print the number of seconds after which the hand of every clock point directly upward again.

-----Sample Input-----
2
2
3

-----Sample Output-----
6

We have two clocks. The time when the hand of each clock points upward is as follows:
 - Clock 1: 2, 4, 6, ... seconds after the beginning
 - Clock 2: 3, 6, 9, ... seconds after the beginning
Therefore, it takes 6 seconds until the hands of both clocks point directly upward.

I tried it in Python, but could not do it. Can you solve it?

n = int(input())
t = [int(input()) for _ in range(n)]

import math
from functools import reduce
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
print(lcm(*t))


I found an interesting problem on https://atcoder.jp/contests/abc070/tasks/abc070_d:
You are given a tree with N vertices.

Here, a tree is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices.

The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of c_i.
You are also given Q queries and an integer K. In the j-th query (1≤j≤Q):
 - find the length of the shortest path from Vertex x_j and Vertex y_j via Vertex K.

-----Constraints-----
 - 3≤N≤10^5
 - 1≤a_i,b_i≤N (1≤i≤N-1)
 - 1≤c_i≤10^9 (1≤i≤N-1)
 - The given graph is a tree.
 - 1≤Q≤10^5
 - 1≤K≤N
 - 1≤x_j,y_j≤N (1≤j≤Q)
 - x_j≠y_j (1≤j≤Q)
 - x_j≠K,y_j≠K (1≤j≤Q)

-----Input-----
Input is given from Standard Input in the following format:
N
a_1 b_1 c_1
:
a_{N-1} b_{N-1} c_{N-1}
Q K
x_1 y_1
:
x_{Q} y_{Q}

-----Output-----
Print the responses to the queries in Q lines.

In the j-th line j(1≤j≤Q), print the response to the j-th query.

-----Sample Input-----
5
1 2 1
1 3 1
2 4 1
3 5 1
3 1
2 4
2 3
4 5

-----Sample Output-----
3
2
4

The shortest paths for the three queries are as follows:
 - Query 1: Vertex 2 → Vertex 1 → Vertex 2 → Vertex 4 : Length 1+1+1=3
 - Query 2: Vertex 2 → Vertex 1 → Vertex 3 : Length 1+1=2
 - Query 3: Vertex 4 → Vertex 2 → Vertex 1 → Vertex 3 → Vertex 5 : Length 1+1+1+1=4

I tried it in Python, but could not do it. Can you solve it?

import sys
from collections import deque

N = int(sys.stdin.readline())

edges = [[] for _ in range(N)]
for _ in range(N-1):
    a, b, c = map(int, sys.stdin.readline().split())
    edges[a-1].append((b-1, c))
    edges[b-1].append((a-1, c))

Q, K = map(int, sys.stdin.readline().split())

# Kを始点とする、各点までの距離
dist = [-1 for _ in range(N)]

visited = set()
q = deque([(K-1, 0)])
while q:
    p, c = q.popleft()
    if p in visited:
        continue
    dist[p] = c

    visited.add(p)
    for (next_p, next_c) in edges[p]:
        q.append((next_p, c + next_c))
# print(dist)

for _ in range(Q):
    x, y = map(int, sys.stdin.readline().split())
    print(dist[x-1] + dist[y-1])


I found an interesting problem on https://atcoder.jp/contests/abc071/tasks/abc071_a:
Snuke lives at position x on a number line.
On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery.
Snuke decided to get food delivery from the closer of stores A and B.
Find out which store is closer to Snuke's residence.
Here, the distance between two points s and t on a number line is represented by |s-t|.

-----Constraints-----
 - 1 \leq x \leq 1000
 - 1 \leq a \leq 1000
 - 1 \leq b \leq 1000
 - x, a and b are pairwise distinct.
 - The distances between Snuke's residence and stores A and B are different.

-----Input-----
Input is given from Standard Input in the following format:
x a b

-----Output-----
If store A is closer, print A; if store B is closer, print B.

-----Sample Input-----
5 2 7

-----Sample Output-----
B

The distances between Snuke's residence and stores A and B are 3 and 2, respectively.
Since store B is closer, print B.

I tried it in Python, but could not do it. Can you solve it?

x,a,b=map(int,input().split())
print('A' if abs(x-a)<abs(x-b) else 'B')


I found an interesting problem on https://atcoder.jp/contests/abc071/tasks/abc071_b:
You are given a string S consisting of lowercase English letters.
Find the lexicographically (alphabetically) smallest lowercase English letter that does not occur in S.
If every lowercase English letter occurs in S, print None instead.

-----Constraints-----
 - 1 \leq |S| \leq 10^5 (|S| is the length of string S.)
 - S consists of lowercase English letters.

-----Input-----
Input is given from Standard Input in the following format:
S

-----Output-----
Print the lexicographically smallest lowercase English letter that does not occur in S.
If every lowercase English letter occurs in S, print None instead.

-----Sample Input-----
atcoderregularcontest

-----Sample Output-----
b

The string atcoderregularcontest contains a, but does not contain b.

I tried it in Python, but could not do it. Can you solve it?

s = str(input())

alp = set("abcdefghijklmnopqrstuvwxyz")
s = set(s)
#print(s & alp)

if len(s & alp)==26:
    ans = "None"
else:
    lis = list(alp-s)
    lis.sort()
    ans = lis[0]

print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc071/tasks/arc081_a:
We have N sticks with negligible thickness.
The length of the i-th stick is A_i.
Snuke wants to select four different sticks from these sticks and form a rectangle (including a square), using the sticks as its sides.
Find the maximum possible area of the rectangle.

-----Constraints-----
 - 4 \leq N \leq 10^5
 - 1 \leq A_i \leq 10^9
 - A_i is an integer.

-----Input-----
Input is given from Standard Input in the following format:
N
A_1 A_2 ... A_N

-----Output-----
Print the maximum possible area of the rectangle.
If no rectangle can be formed, print 0.

-----Sample Input-----
6
3 1 2 4 2 1

-----Sample Output-----
2

1 \times 2 rectangle can be formed.

I tried it in Python, but could not do it. Can you solve it?

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

d = {}
for i in a:
    if i in d:
        d[i] += 1
    else:
        d[i] = 1
d = sorted(d.items(), key=lambda x:x[0], reverse=True)

m = len(d)
ans = 0
flg = True
for i in range(m):
    k, v = d[i][0], d[i][1]
    if ans == 0:
        if v >= 4:
            ans = k**2
            flg = True
            break
        elif v >= 2:
            ans = k
    elif v >= 2:
        ans *= k
        flg = True
        break
print(ans) if flg else print(0)


I found an interesting problem on https://atcoder.jp/contests/abc072/tasks/abc072_a:
We have a sandglass that runs for X seconds. The sand drops from the upper bulb at a rate of 1 gram per second. That is, the upper bulb initially contains X grams of sand.
How many grams of sand will the upper bulb contains after t seconds?

-----Constraints-----
 - 1≤X≤10^9
 - 1≤t≤10^9
 - X and t are integers.

-----Input-----
The input is given from Standard Input in the following format:
X t

-----Output-----
Print the number of sand in the upper bulb after t second.

-----Sample Input-----
100 17

-----Sample Output-----
83

17 out of the initial 100 grams of sand will be consumed, resulting in 83 grams.

I tried it in Python, but could not do it. Can you solve it?

x,t = list(map(int,input().split()))
print((max(x-t,0)))


I found an interesting problem on https://atcoder.jp/contests/abc072/tasks/abc072_b:
You are given a string s consisting of lowercase English letters. Extract all the characters in the odd-indexed positions and print the string obtained by concatenating them. Here, the leftmost character is assigned the index 1.

-----Constraints-----
 - Each character in s is a lowercase English letter.
 - 1≤|s|≤10^5

-----Input-----
The input is given from Standard Input in the following format:
s

-----Output-----
Print the string obtained by concatenating all the characters in the odd-numbered positions.

-----Sample Input-----
atcoder

-----Sample Output-----
acdr

Extract the first character a, the third character c, the fifth character d and the seventh character r to obtain acdr.

I tried it in Python, but could not do it. Can you solve it?

s = input()
print((s[0::2]))
# s[始まりの位置: 終わりの位置: スライスの増分]


I found an interesting problem on https://atcoder.jp/contests/abc072/tasks/arc082_a:
You are given an integer sequence of length N, a_1,a_2,...,a_N.
For each 1≤i≤N, you have three choices: add 1 to a_i, subtract 1 from a_i or do nothing.
After these operations, you select an integer X and count the number of i such that a_i=X.
Maximize this count by making optimal choices.

-----Constraints-----
 - 1≤N≤10^5
 - 0≤a_i<10^5 (1≤i≤N)
 - a_i is an integer.

-----Input-----
The input is given from Standard Input in the following format:
N
a_1 a_2 .. a_N

-----Output-----
Print the maximum possible number of i such that a_i=X.

-----Sample Input-----
7
3 1 4 1 5 9 2

-----Sample Output-----
4

For example, turn the sequence into 2,2,3,2,6,9,2 and select X=2 to obtain 4, the maximum possible count.

I tried it in Python, but could not do it. Can you solve it?

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

ans=0

cnt=[0]*(10**5+10)
for i in range(N):
    cnt[A[i]]+=1

for i in range(0,100000):
    sum=cnt[i]+cnt[i+1]+cnt[i+2]
    ans=max(ans,sum)

print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc072/tasks/arc082_b:
You are given a permutation p_1,p_2,...,p_N consisting of 1,2,..,N.
You can perform the following operation any number of times (possibly zero):
Operation: Swap two adjacent elements in the permutation.
You want to have p_i ≠ i for all 1≤i≤N.
Find the minimum required number of operations to achieve this.

-----Constraints-----
 - 2≤N≤10^5
 - p_1,p_2,..,p_N is a permutation of 1,2,..,N.

-----Input-----
The input is given from Standard Input in the following format:
N
p_1 p_2 .. p_N

-----Output-----
Print the minimum required number of operations

-----Sample Input-----
5
1 4 3 5 2

-----Sample Output-----
2

Swap 1 and 4, then swap 1 and 3. p is now 4,3,1,5,2 and satisfies the condition.
This is the minimum possible number, so the answer is 2.

I tried it in Python, but could not do it. Can you solve it?

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


I found an interesting problem on https://atcoder.jp/contests/abc073/tasks/abc073_a:
It is September 9 in Japan now.
You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?

-----Constraints-----
 - 10≤N≤99

-----Input-----
Input is given from Standard Input in the following format:
N

-----Output-----
If 9 is contained in the decimal notation of N, print Yes; if not, print No.

-----Sample Input-----
29

-----Sample Output-----
Yes

The one's digit of 29 is 9.

I tried it in Python, but could not do it. Can you solve it?

n = input()
print("Yes" if n[0] == "9" or n[1] == "9" else "No")


I found an interesting problem on https://atcoder.jp/contests/abc073/tasks/abc073_b:
Joisino is working as a receptionist at a theater.
The theater has 100000 seats, numbered from 1 to 100000.
According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive).
How many people are sitting at the theater now?

-----Constraints-----
 - 1≤N≤1000
 - 1≤l_i≤r_i≤100000
 - No seat is occupied by more than one person.
 - All input values are integers.

-----Input-----
Input is given from Standard Input in the following format:
N
l_1 r_1
:
l_N r_N

-----Output-----
Print the number of people sitting at the theater.

-----Sample Input-----
1
24 30

-----Sample Output-----
7

There are 7 people, sitting at Seat 24,25,26,27,28,29 and 30.

I tried it in Python, but could not do it. Can you solve it?

n = int(input())
data = [input().split() for i in range(n)]
ans = 0
for i in range(n):
    ans += int(data[i][1]) - int(data[i][0]) + 1
print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc073/tasks/abc073_c:
You are playing the following game with Joisino.
 - Initially, you have a blank sheet of paper.
 - Joisino announces a number. If that number is written on the sheet, erase the number from the sheet; if not, write the number on the sheet. This process is repeated N times.
 - Then, you are asked a question: How many numbers are written on the sheet now?
The numbers announced by Joisino are given as A_1, ... ,A_N in the order she announces them. How many numbers will be written on the sheet at the end of the game?

-----Constraints-----
 - 1≤N≤100000
 - 1≤A_i≤1000000000(=10^9)
 - All input values are integers.

-----Input-----
Input is given from Standard Input in the following format:
N
A_1
:
A_N

-----Output-----
Print how many numbers will be written on the sheet at the end of the game.

-----Sample Input-----
3
6
2
6

-----Sample Output-----
1

The game proceeds as follows:
 - 6 is not written on the sheet, so write 6.
 - 2 is not written on the sheet, so write 2.
 - 6 is written on the sheet, so erase 6.
Thus, the sheet contains only 2 in the end. The answer is 1.

I tried it in Python, but could not do it. Can you solve it?

def main():
    n = int(input())
    ans = set()
    for _ in range(n):
        a = int(input())
        if a in ans:
            ans.discard(a)
        else:
            ans.add(a)

    print((len(ans)))

def __starting_point():
    main()

__starting_point()


I found an interesting problem on https://atcoder.jp/contests/abc073/tasks/abc073_d:
There are N towns in the State of Atcoder, connected by M bidirectional roads.
The i-th road connects Town A_i and B_i and has a length of C_i.
Joisino is visiting R towns in the state, r_1,r_2,..,r_R (not necessarily in this order).
She will fly to the first town she visits, and fly back from the last town she visits, but for the rest of the trip she will have to travel by road.
If she visits the towns in the order that minimizes the distance traveled by road, what will that distance be?

-----Constraints-----
 - 2≤N≤200
 - 1≤M≤N×(N-1)/2
 - 2≤R≤min(8,N) (min(8,N) is the smaller of 8 and N.)
 - r_i≠r_j (i≠j)
 - 1≤A_i,B_i≤N, A_i≠B_i
 - (A_i,B_i)≠(A_j,B_j),(A_i,B_i)≠(B_j,A_j) (i≠j)
 - 1≤C_i≤100000
 - Every town can be reached from every town by road.
 - All input values are integers.

-----Input-----
Input is given from Standard Input in the following format:
N M R
r_1 ... r_R
A_1 B_1 C_1
:
A_M B_M C_M

-----Output-----
Print the distance traveled by road if Joisino visits the towns in the order that minimizes it.

-----Sample Input-----
3 3 3
1 2 3
1 2 1
2 3 1
3 1 4

-----Sample Output-----
2

For example, if she visits the towns in the order of 1, 2, 3, the distance traveled will be 2, which is the minimum possible.

I tried it in Python, but could not do it. Can you solve it?

from itertools import permutations
from scipy.sparse.csgraph import floyd_warshall
INF = 1001001001

N, M, R = list(map(int, input().split()))
r = list(map(int, input().split()))
graph = [[INF]*N for _ in range(N)]
for i in range(M):
    A, B, C = list(map(int, input().split()))
    graph[A-1][B-1] = C
    graph[B-1][A-1] = C
dist_matrix = floyd_warshall(graph)

ans = INF
for root in permutations(r):
    cnt = 0
    for j in range(R-1):
        cnt += dist_matrix[root[j]-1][root[j+1]-1]
    ans = min(ans, cnt)
print((int(ans)))


I found an interesting problem on https://atcoder.jp/contests/abc074/tasks/abc074_a:
We have an N \times N square grid.
We will paint each square in the grid either black or white.
If we paint exactly A squares white, how many squares will be painted black?

-----Constraints-----
 - 1 \leq N \leq 100
 - 0 \leq A \leq N^2

-----Inputs-----
Input is given from Standard Input in the following format:
N
A

-----Outputs-----
Print the number of squares that will be painted black.

-----Sample Input-----
3
4

-----Sample Output-----
5

There are nine squares in a 3 \times 3 square grid.
Four of them will be painted white, so the remaining five squares will be painted black.

I tried it in Python, but could not do it. Can you solve it?


I found an interesting problem on https://atcoder.jp/contests/abc074/tasks/abc074_b:
There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i).
Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N.
In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B.
Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th type-B robot at coordinates (K, i).
Thus, now we have one type-A robot and one type-B robot on each of the N lines y = 1, y = 2, ..., y = N.
When activated, each type of robot will operate as follows.
 - When a type-A robot is activated at coordinates (0, a), it will move to the position of the ball on the line y = a, collect the ball, move back to its original position (0, a) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.
 - When a type-B robot is activated at coordinates (K, b), it will move to the position of the ball on the line y = b, collect the ball, move back to its original position (K, b) and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.
Snuke will activate some of the 2N robots to collect all of the balls. Find the minimum possible total distance covered by robots.

-----Constraints-----
 - 1 \leq N \leq 100
 - 1 \leq K \leq 100
 - 0 < x_i < K
 - All input values are integers.

-----Inputs-----
Input is given from Standard Input in the following format:
N
K
x_1 x_2 ... x_N

-----Outputs-----
Print the minimum possible total distance covered by robots.

-----Sample Input-----
1
10
2

-----Sample Output-----
4

There are just one ball, one type-A robot and one type-B robot.
If the type-A robot is used to collect the ball, the distance from the robot to the ball is 2, and the distance from the ball to the original position of the robot is also 2, for a total distance of 4.
Similarly, if the type-B robot is used, the total distance covered will be 16.
Thus, the total distance covered will be minimized when the type-A robot is used. The output should be 4.

I tried it in Python, but could not do it. Can you solve it?

N=int(input())
K=int(input())
x=list(map(int,input().split()))
tot=0
for i in range(N):
    if abs(x[i]-K)<x[i]:
        tot+=2*(abs(x[i]-K))
    else:
        tot+=2*x[i]
print(tot)


I found an interesting problem on https://atcoder.jp/contests/abc074/tasks/arc083_a:
Snuke is making sugar water in a beaker.
Initially, the beaker is empty. Snuke can perform the following four types of operations any number of times. He may choose not to perform some types of operations.
 - Operation 1: Pour 100A grams of water into the beaker.
 - Operation 2: Pour 100B grams of water into the beaker.
 - Operation 3: Put C grams of sugar into the beaker.
 - Operation 4: Put D grams of sugar into the beaker.
In our experimental environment, E grams of sugar can dissolve into 100 grams of water.
Snuke will make sugar water with the highest possible density.
The beaker can contain at most F grams of substances (water and sugar combined), and there must not be any undissolved sugar in the beaker.
Find the mass of the sugar water Snuke will make, and the mass of sugar dissolved in it.
If there is more than one candidate, any of them will be accepted.
We remind you that the sugar water that contains a grams of water and b grams of sugar is \frac{100b}{a + b} percent.
Also, in this problem, pure water that does not contain any sugar is regarded as 0 percent density sugar water.

-----Constraints-----
 - 1 \leq A < B \leq 30
 - 1 \leq C < D \leq 30
 - 1 \leq E \leq 100
 - 100A \leq F \leq 3 000
 - A, B, C, D, E and F are all integers.

-----Inputs-----
Input is given from Standard Input in the following format:
A B C D E F

-----Outputs-----
Print two integers separated by a space.
The first integer should be the mass of the desired sugar water, and the second should be the mass of the sugar dissolved in it.

-----Sample Input-----
1 2 10 20 15 200

-----Sample Output-----
110 10

In this environment, 15 grams of sugar can dissolve into 100 grams of water, and the beaker can contain at most 200 grams of substances.
We can make 110 grams of sugar water by performing Operation 1 once and Operation 3 once.
It is not possible to make sugar water with higher density.
For example, the following sequences of operations are infeasible:
 - If we perform Operation 1 once and Operation 4 once, there will be...

I tried it in Python, but could not do it. Can you solve it?

a , b , c , d , e , f = map(int,input().split())
midp = [-1 for i in range(f+1)]
mizu = []
midp[0] = 0
for i in range(f+1):
    if midp[i] != -1:
        if i + a*100 <= f and midp[i+a*100] != 0:
            midp[i+a*100] = 0
            mizu.append(i+a*100)
        if i + b*100 <= f and midp[i+b*100] != 0:
            midp[i+b*100] = 0
            mizu.append(i+b*100)
ans = 0
cou = [a*100,0]
for i in mizu:
    sai = i*e//100
    sadp = [-1 for f in range(sai+1)]
    sadp[0] = 0
    maxsa = 0
    for j in range(sai+1):
        if sadp[j] != -1:
            if j + c <= sai and i + j + c <= f and sadp[j+c] != 0:
                sadp[j+c] = 0
                maxsa = max(maxsa,j+c)
            if j + d <= sai and i + j + d <= f and sadp[j+d] != 0:
                sadp[j+d] = 0
                maxsa = max(maxsa,j+d)
    if ans < maxsa/(i+maxsa):
        ans = maxsa/(i+maxsa)
        cou = [i+maxsa,maxsa]

print(*cou)


I found an interesting problem on https://atcoder.jp/contests/abc074/tasks/arc083_b:
In Takahashi Kingdom, which once existed, there are N cities, and some pairs of cities are connected bidirectionally by roads.
The following are known about the road network:
 - People traveled between cities only through roads. It was possible to reach any city from any other city, via intermediate cities if necessary.
 - Different roads may have had different lengths, but all the lengths were positive integers.
Snuke the archeologist found a table with N rows and N columns, A, in the ruin of Takahashi Kingdom.
He thought that it represented the shortest distances between the cities along the roads in the kingdom.
Determine whether there exists a road network such that for each u and v, the integer A_{u, v} at the u-th row and v-th column of A is equal to the length of the shortest path from City u to City v.
If such a network exist, find the shortest possible total length of the roads.

-----Constraints-----
 - 1 \leq N \leq 300
 - If i ≠ j, 1 \leq A_{i, j} = A_{j, i} \leq 10^9.
 - A_{i, i} = 0

-----Inputs-----
Input is given from Standard Input in the following format:
N
A_{1, 1} A_{1, 2} ... A_{1, N}
A_{2, 1} A_{2, 2} ... A_{2, N}
...
A_{N, 1} A_{N, 2} ... A_{N, N}

-----Outputs-----
If there exists no network that satisfies the condition, print -1.
If it exists, print the shortest possible total length of the roads.

-----Sample Input-----
3
0 1 3
1 0 2
3 2 0

-----Sample Output-----
3

The network below satisfies the condition:
 - City 1 and City 2 is connected by a road of length 1.
 - City 2 and City 3 is connected by a road of length 2.
 - City 3 and City 1 is not connected by a road.

I tried it in Python, but could not do it. Can you solve it?

from scipy.sparse.csgraph import floyd_warshall
import numpy as np

def main():
    INF = 10**12
    N = int(input())
    A = [list(map(int, input().split(' '))) for _ in range(N)]
    wf = floyd_warshall(A)
    for i in range(N):
        A[i][i] = INF
        wf[i][i] = INF
    ans = 0
    for i in range(N):
        for j in range(N):
            if A[i][j] != wf[i][j]:
                print(-1)
                return
            if wf[i][j] < np.min(wf[i] + wf[j]):
                ans += wf[i][j]
    print(int(ans // 2))

def __starting_point():
    main()
__starting_point()


I found an interesting problem on https://atcoder.jp/contests/abc075/tasks/abc075_a:
You are given three integers, A, B and C.

Among them, two are the same, but the remaining one is different from the rest.

For example, when A=5,B=7,C=5, A and C are the same, but B is different.

Find the one that is different from the rest among the given three integers.

-----Constraints-----
 - -100 \leq A,B,C \leq 100
 - A, B and C are integers.
 - The input satisfies the condition in the statement.

-----Input-----
Input is given from Standard Input in the following format:
A B C

-----Output-----
Among A, B and C, print the integer that is different from the rest.

-----Sample Input-----
5 7 5

-----Sample Output-----
7

This is the same case as the one in the statement.

I tried it in Python, but could not do it. Can you solve it?

A, B, C = sorted(map(int, input().split()))

print((A if B == C else C))


I found an interesting problem on https://atcoder.jp/contests/abc075/tasks/abc075_b:
You are given an H × W grid.

The squares in the grid are described by H strings, S_1,...,S_H.

The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W).
. stands for an empty square, and # stands for a square containing a bomb.
Dolphin is interested in how many bomb squares are horizontally, vertically or diagonally adjacent to each empty square.

(Below, we will simply say "adjacent" for this meaning. For each square, there are at most eight adjacent squares.)

He decides to replace each . in our H strings with a digit that represents the number of bomb squares adjacent to the corresponding empty square.
Print the strings after the process.

-----Constraints-----
 - 1 \leq H,W \leq 50
 - S_i is a string of length W consisting of # and ..

-----Input-----
Input is given from Standard Input in the following format:
H W
S_1
:
S_H

-----Output-----
Print the H strings after the process.

The i-th line should contain a string T_i of length W, where the j-th character in T_i corresponds to the square at the i-th row from the top and j-th row from the left in the grid (1 \leq i \leq H, 1 \leq j \leq W).

-----Sample Input-----
3 5
.....
.#.#.
.....

-----Sample Output-----
11211
1#2#1
11211

For example, let us observe the empty square at the first row from the top and first column from the left.

There is one bomb square adjacent to this empty square: the square at the second row and second column.

Thus, the . corresponding to this empty square is replaced with 1.

I tried it in Python, but could not do it. Can you solve it?

import numpy as np

def get_num_bomb(arr, i, j):
    """
    docstring
    """
    temp_arr = np.full([arr.shape[0] + 2, arr.shape[1] + 2], False)
    temp_arr[1:1 + arr.shape[0], 1:1 + arr.shape[1]] = arr[:, :]
    slice = temp_arr[i:i + 3, j:j + 3]
    return slice.sum()

h, w = tuple([int(x) for x in input().split(" ")])
arr = []
ret_arr = [[0] * w for i in range(h)]
for i in range(h):
    x = list([(False if x == "." else True) for x in input()])
    # x = list(map(lambda x: x, input()))
    arr.append(x)
arr = np.array(arr)
# print(arr)
for i in range(h):
    for j in range(w):
        if arr[i, j] == True:
            ret_arr[i][j] = "#"
        else:
            ret_arr[i][j] = get_num_bomb(arr, i, j)
for lis in ret_arr:
    print(("".join(list([str(x) for x in lis]))))


I found an interesting problem on https://atcoder.jp/contests/abc075/tasks/abc075_c:
You are given an undirected connected graph with N vertices and M edges that does not contain self-loops and double edges.

The i-th edge (1 \leq i \leq M) connects Vertex a_i and Vertex b_i.
An edge whose removal disconnects the graph is called a bridge.

Find the number of the edges that are bridges among the M edges.

-----Notes-----
 - A self-loop is an edge i such that a_i=b_i (1 \leq i \leq M).
 - Double edges are a pair of edges i,j such that a_i=a_j and b_i=b_j (1 \leq i<j \leq M).
 - An undirected graph is said to be connected when there exists a path between every pair of vertices.

-----Constraints-----
 - 2 \leq N \leq 50
 - N-1 \leq M \leq min(N(N−1)⁄2,50)
 - 1 \leq a_i<b_i \leq N
 - The given graph does not contain self-loops and double edges.
 - The given graph is connected.

-----Input-----
Input is given from Standard Input in the following format:
N M
a_1 b_1
a_2 b_2
:
a_M b_M

-----Output-----
Print the number of the edges that are bridges among the M edges.

-----Sample Input-----
7 7
1 3
2 7
3 4
4 5
4 6
5 6
6 7

-----Sample Output-----
4

The figure below shows the given graph:
The edges shown in red are bridges. There are four of them.

I tried it in Python, but could not do it. Can you solve it?

class UnionFind():
  def __init__(self,n):
    self.n = n
    self.parents = [-1]*n
  def find(self,x):
    if self.parents[x]<0:
      return x
    else:
      self.parents[x]=self.find(self.parents[x])
      return self.parents[x]
  def unite(self,x,y):
    x = self.find(x)
    y = self.find(y)
    if x == y:
      return
    if self.parents[x]>self.parents[y]:
      x,y=y,x
    self.parents[x]+=self.parents[y]
    self.parents[y]=x
  def same(self,x,y):
    return self.find(x)==self.find(y)
N,M = map(int,input().split())
A = [0]*M
t=0
B=[0]*M
for i in  range(M):
  a,b=map(int,input().split())
  A[i]=[a-1,b-1]
for t in range(M):
  UF = UnionFind(N)
  for i in range(M):
    if i!=t:
      UF.unite(A[i][0],A[i][1])
  if UF.same(A[t][0],A[t][1])==False:
    B[t]=1
print(sum(B))


I found an interesting problem on https://atcoder.jp/contests/abc075/tasks/abc075_d:
We have N points in a two-dimensional plane.

The coordinates of the i-th point (1 \leq i \leq N) are (x_i,y_i).

Let us consider a rectangle whose sides are parallel to the coordinate axes that contains K or more of the N points in its interior.

Here, points on the sides of the rectangle are considered to be in the interior.

Find the minimum possible area of such a rectangle.

-----Constraints-----
 - 2 \leq K \leq N \leq 50
 - -10^9 \leq x_i,y_i \leq 10^9 (1 \leq i \leq N)
 - x_i≠x_j (1 \leq i<j \leq N)
 - y_i≠y_j (1 \leq i<j \leq N)
 - All input values are integers. (Added at 21:50 JST)

-----Input-----
Input is given from Standard Input in the following format:
N K
x_1 y_1
:
x_{N} y_{N}

-----Output-----
Print the minimum possible area of a rectangle that satisfies the condition.

-----Sample Input-----
4 4
1 4
3 3
6 2
8 1

-----Sample Output-----
21

One rectangle that satisfies the condition with the minimum possible area has the following vertices: (1,1), (8,1), (1,4) and (8,4).

Its area is (8-1) × (4-1) = 21.

I tried it in Python, but could not do it. Can you solve it?

import collections, itertools, sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    N, K = LI()
    xy = [LI() for _ in range(N)]

    # 全ての長方形候補に対して、2次元累積和を使って内部の点の個数を算出する
    x_coord = [i[0] for i in xy]
    x_coord.sort()
    x_val_num = {x_coord[i]: i for i in range(N)}
    y_coord = [i[1] for i in xy]
    y_coord.sort()
    y_val_num = {y_coord[i]: i for i in range(N)}

    # 2次元累積和の計算
    xy_cnt = [[0] * N for _ in range(N)]
    for x, y in xy:
        xy_cnt[y_val_num[y]][x_val_num[x]] = 1
    # for i in xy_cnt:
    #     print(i)
    xy_acm = [[0] * (N + 1) for _ in range(N + 1)]
    for i in range(N):
        for j in range(N):
            xy_acm[i+1][j+1] = xy_cnt[i][j] + xy_acm[i+1][j] + xy_acm[i][j+1] - xy_acm[i][j]
    # for i in xy_acm:
    #     print(i)

    ans = INF
    for yl, yu in itertools.combinations(list(range(N + 1)), 2):
        for xl, xu in itertools.combinations(list(range(N + 1)), 2):
            cnt = xy_acm[yu][xu] - xy_acm[yu][xl] - xy_acm[yl][xu] + xy_acm[yl][xl]
            # print(cnt, yl, yu, xl, xu)
            if cnt >= K:
                ans = min((x_coord[xu-1] - x_coord[xl]) * (y_coord[yu-1] - y_coord[yl]), ans)

    print(ans)

def __starting_point():
    resolve()

__starting_point()


I found an interesting problem on https://atcoder.jp/contests/abc076/tasks/abc076_a:
Takahashi is a user of a site that hosts programming contests.

When a user competes in a contest, the rating of the user (not necessarily an integer) changes according to the performance of the user, as follows:
 - Let the current rating of the user be a.
 - Suppose that the performance of the user in the contest is b.
 - Then, the new rating of the user will be the avarage of a and b.
For example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000.
Takahashi's current rating is R, and he wants his rating to be exactly G after the next contest.

Find the performance required to achieve it.

-----Constraints-----
 - 0 \leq R, G \leq 4500
 - All input values are integers.

-----Input-----
Input is given from Standard Input in the following format:
R
G

-----Output-----
Print the performance required to achieve the objective.

-----Sample Input-----
2002
2017

-----Sample Output-----
2032

Takahashi's current rating is 2002.

If his performance in the contest is 2032, his rating will be the average of 2002 and 2032, which is equal to the desired rating, 2017.

I tried it in Python, but could not do it. Can you solve it?

def main():
  my_rate = int(input())
  avarage_rate = int(input())

  target_rate = (avarage_rate * 2) - my_rate

  print(target_rate)

def __starting_point():
  main()
__starting_point()


I found an interesting problem on https://atcoder.jp/contests/abc076/tasks/abc076_b:
Square1001 has seen an electric bulletin board displaying the integer 1.
He can perform the following operations A and B to change this value:
 - Operation A: The displayed value is doubled.
 - Operation B: The displayed value increases by K.
Square1001 needs to perform these operations N times in total.
Find the minimum possible value displayed in the board after N operations.

-----Constraints-----
 - 1 \leq N, K \leq 10
 - All input values are integers.

-----Input-----
Input is given from Standard Input in the following format:
N
K

-----Output-----
Print the minimum possible value displayed in the board after N operations.

-----Sample Input-----
4
3

-----Sample Output-----
10

The value will be minimized when the operations are performed in the following order: A, A, B, B.

In this case, the value will change as follows: 1 → 2 → 4 → 7 → 10.

I tried it in Python, but could not do it. Can you solve it?

n = int(input())
k = int(input())
x = 1
for i in range(n):
  if x + k <= 2*x:
    x += k
  else:
    x *= 2
print(x)


I found an interesting problem on https://atcoder.jp/contests/abc076/tasks/abc076_c:
E869120 found a chest which is likely to contain treasure.

However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters.

He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with ?.
One more thing he found is a sheet of paper with the following facts written on it:
 - Condition 1: The string S contains a string T as a contiguous substring.
 - Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1.
Print the string S.

If such a string does not exist, print UNRESTORABLE.

-----Constraints-----
 - 1 \leq |S'|, |T| \leq 50
 - S' consists of lowercase English letters and ?.
 - T consists of lowercase English letters.

-----Input-----
Input is given from Standard Input in the following format:
S
T'

-----Output-----
Print the string S.

If such a string does not exist, print UNRESTORABLE instead.

-----Sample Input-----
?tc????
coder

-----Sample Output-----
atcoder

There are 26 strings that satisfy Condition 1: atcoder, btcoder, ctcoder,..., ztcoder.
Among them, the lexicographically smallest is atcoder, so we can say S = atcoder.

I tried it in Python, but could not do it. Can you solve it?

s = input()
t = input()

ls = len(s)
lt = len(t)
check = False
ans = 'z'*60
for i in range(ls-lt+1):
    u = list(s)
    flag = True
    for j in range(lt):
        if u[i+j] == '?':
            u[i+j] = t[j]
        elif u[i+j] != t[j]:
            flag = False
            break
    if flag:
        check = True
        u = ''.join(u).replace('?', 'a')
        ans = sorted([ans, u])[0]
print(ans if check else 'UNRESTORABLE')


I found an interesting problem on https://atcoder.jp/contests/abc076/tasks/abc076_d:
In the year 2168, AtCoder Inc., which is much larger than now, is starting a limited express train service called AtCoder Express.
In the plan developed by the president Takahashi, the trains will run as follows:
 - A train will run for (t_1 + t_2 + t_3 + ... + t_N) seconds.
 - In the first t_1 seconds, a train must run at a speed of at most v_1 m/s (meters per second). Similarly, in the subsequent t_2 seconds, a train must run at a speed of at most v_2 m/s, and so on.
According to the specifications of the trains, the acceleration of a train must be always within ±1m/s^2. Additionally, a train must stop at the beginning and the end of the run.
Find the maximum possible distance that a train can cover in the run.

-----Constraints-----
 - 1 \leq N \leq 100
 - 1 \leq t_i \leq 200
 - 1 \leq v_i \leq 100
 - All input values are integers.

-----Input-----
Input is given from Standard Input in the following format:
N
t_1 t_2 t_3 … t_N
v_1 v_2 v_3 … v_N

-----Output-----
Print the maximum possible that a train can cover in the run.

Output is considered correct if its absolute difference from the judge's output is at most 10^{-3}.

-----Sample Input-----
1
100
30

-----Sample Output-----
2100.000000000000000

The maximum distance is achieved when a train runs as follows:
 - In the first 30 seconds, it accelerates at a rate of 1m/s^2, covering 450 meters.
 - In the subsequent 40 seconds, it maintains the velocity of 30m/s, covering 1200 meters.
 - In the last 30 seconds, it decelerates at the acceleration of -1m/s^2, covering 450 meters.
The total distance covered is 450 + 1200 + 450 = 2100 meters.

I tried it in Python, but could not do it. Can you solve it?

N = int(input())
t = [int(Ti) for Ti in input().split()]
v = [int(Vi) for Vi in input().split()]

v_max = [0]
for ti, vi in zip(t, v):
    v_max[-1] = min(v_max[-1], vi)
    for _ in range(2*ti):
        v_max.append(vi)

for i in range(len(v_max)-1):
    v_max[i+1] = min(v_max[i] + 0.5, v_max[i+1])

v_max[-1] = 0
for i in range(len(v_max)-2, -1, -1):
    v_max[i] = min(v_max[i], v_max[i+1] + 0.5)

area = 0
for i in range(len(v_max) - 1):
    area += 0.5 * 0.5 * (v_max[i] + v_max[i+1])

print(area)


I found an interesting problem on https://atcoder.jp/contests/abc077/tasks/abc077_a:
You are given a grid with 2 rows and 3 columns of squares.
The color of the square at the i-th row and j-th column is represented by the character C_{ij}.
Write a program that prints YES if this grid remains the same when rotated 180 degrees, and prints NO otherwise.

-----Constraints-----
 - C_{i,j}(1 \leq i \leq 2, 1 \leq j \leq 3) is a lowercase English letter.

-----Input-----
Input is given from Standard Input in the following format:
C_{11}C_{12}C_{13}
C_{21}C_{22}C_{23}

-----Output-----
Print YES if this grid remains the same when rotated 180 degrees; print NO otherwise.

-----Sample Input-----
pot
top

-----Sample Output-----
YES

This grid remains the same when rotated 180 degrees.

I tried it in Python, but could not do it. Can you solve it?


I found an interesting problem on https://atcoder.jp/contests/abc077/tasks/abc077_b:
Find the largest square number not exceeding N. Here, a square number is an integer that can be represented as the square of an integer.

-----Constraints-----
 - 1 \leq N \leq 10^9
 - N is an integer.

-----Input-----
Input is given from Standard Input in the following format:
N

-----Output-----
Print the largest square number not exceeding N.

-----Sample Input-----
10

-----Sample Output-----
9

10 is not square, but 9 = 3 × 3 is. Thus, we print 9.

I tried it in Python, but could not do it. Can you solve it?

import math

n = int(input())
print(math.floor(math.sqrt(n)) ** 2)


I found an interesting problem on https://atcoder.jp/contests/abc077/tasks/arc084_a:
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower.
He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i.
To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar.
How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.

-----Constraints-----
 - 1 \leq N \leq 10^5
 - 1 \leq A_i \leq 10^9(1\leq i\leq N)
 - 1 \leq B_i \leq 10^9(1\leq i\leq N)
 - 1 \leq C_i \leq 10^9(1\leq i\leq N)
 - All input values are integers.

-----Input-----
Input is given from Standard Input in the following format:
N
A_1 ... A_N
B_1 ... B_N
C_1 ... C_N

-----Output-----
Print the number of different altars that Ringo can build.

-----Sample Input-----
2
1 5
2 4
3 6

-----Sample Output-----
3

The following three altars can be built:
 - Upper: 1-st part, Middle: 1-st part, Lower: 1-st part
 - Upper: 1-st part, Middle: 1-st part, Lower: 2-nd part
 - Upper: 1-st part, Middle: 2-nd part, Lower: 2-nd part

I tried it in Python, but could not do it. Can you solve it?

from bisect import *
n=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort()
B.sort()
C.sort()
ans=0
for b in B:
    ans+=(n-bisect(C,b))*bisect_left(A,b)
print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc077/tasks/arc084_b:
Find the smallest possible sum of the digits in the decimal notation of a positive multiple of K.

-----Constraints-----
 - 2 \leq K \leq 10^5
 - K is an integer.

-----Input-----
Input is given from Standard Input in the following format:
K

-----Output-----
Print the smallest possible sum of the digits in the decimal notation of a positive multiple of K.

-----Sample Input-----
6

-----Sample Output-----
3

12=6×2 yields the smallest sum.

I tried it in Python, but could not do it. Can you solve it?

import heapq

def generate_graph(K):
    return [{(i + 1) % K: 1, (i * 10) % K: 0} for i in range(K)]

def dijkstra(start, goal, graph):
    answer = [float("inf")] * len(graph)
    answer[start] = 0
    remains = sorted([[v, i] for i, v in enumerate(answer)])

    while remains:
        _, i = heapq.heappop(remains)
        for j, cost in list(graph[i].items()):
            if answer[j] > answer[i] + cost:
                answer[j] = answer[i] + cost
                heapq.heappush(remains, [answer[j], j])

    return answer[goal] + 1

K = int(input())
graph = generate_graph(K)
print(dijkstra(1, 0, graph))


I found an interesting problem on https://atcoder.jp/contests/abc078/tasks/abc078_a:
In programming, hexadecimal notation is often used.
In hexadecimal notation, besides the ten digits 0, 1, ..., 9, the six letters A, B, C, D, E and F are used to represent the values 10, 11, 12, 13, 14 and 15, respectively.
In this problem, you are given two letters X and Y. Each X and Y is A, B, C, D, E or F.
When X and Y are seen as hexadecimal numbers, which is larger?

-----Constraints-----
 - Each X and Y is A, B, C, D, E or F.

-----Input-----
Input is given from Standard Input in the following format:
X Y

-----Output-----
If X is smaller, print <; if Y is smaller, print >; if they are equal, print =.

-----Sample Input-----
A B

-----Sample Output-----
<

10 < 11.

I tried it in Python, but could not do it. Can you solve it?

from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

a,b = input().split()
if a < b:
    print('<')
elif a > b:
    print('>')
else:
    print('=')


I found an interesting problem on https://atcoder.jp/contests/abc078/tasks/abc078_b:
We have a long seat of width X centimeters.
There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters.
We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person.
At most how many people can sit on the seat?

-----Constraints-----
 - All input values are integers.
 - 1 \leq X, Y, Z \leq 10^5
 - Y+2Z \leq X

-----Input-----
Input is given from Standard Input in the following format:
X Y Z

-----Output-----
Print the answer.

-----Sample Input-----
13 3 1

-----Sample Output-----
3

There is just enough room for three, as shown below:
Figure

I tried it in Python, but could not do it. Can you solve it?

x, y, z = map(int, input().split())
print((x - z) // ( y + z))


I found an interesting problem on https://atcoder.jp/contests/abc078/tasks/arc085_a:
Takahashi is now competing in a programming contest, but he received TLE in a problem where the answer is YES or NO.
When he checked the detailed status of the submission, there were N test cases in the problem, and the code received TLE in M of those cases.
Then, he rewrote the code to correctly solve each of those M cases with 1/2 probability in 1900 milliseconds, and correctly solve each of the other N-M cases without fail in 100 milliseconds.
Now, he goes through the following process:
 - Submit the code.
 - Wait until the code finishes execution on all the cases.
 - If the code fails to correctly solve some of the M cases, submit it again.
 - Repeat until the code correctly solve all the cases in one submission.
Let the expected value of the total execution time of the code be X milliseconds. Print X (as an integer).

-----Constraints-----
 - All input values are integers.
 - 1 \leq N \leq 100
 - 1 \leq M \leq {\rm min}(N, 5)

-----Input-----
Input is given from Standard Input in the following format:
N M

-----Output-----
Print X, the expected value of the total execution time of the code, as an integer. It can be proved that, under the constraints in this problem, X is an integer not exceeding 10^9.

-----Sample Input-----
1 1

-----Sample Output-----
3800

In this input, there is only one case. Takahashi will repeatedly submit the code that correctly solves this case with 1/2 probability in 1900 milliseconds.
The code will succeed in one attempt with 1/2 probability, in two attempts with 1/4 probability, and in three attempts with 1/8 probability, and so on.
Thus, the answer is 1900 \times 1/2 + (2 \times 1900) \times 1/4 + (3 \times 1900) \times 1/8 + ... = 3800.

I tried it in Python, but could not do it. Can you solve it?


I found an interesting problem on https://atcoder.jp/contests/abc078/tasks/arc085_b:
We have a deck consisting of N cards. Each card has an integer written on it. The integer on the i-th card from the top is a_i.
Two people X and Y will play a game using this deck. Initially, X has a card with Z written on it in his hand, and Y has a card with W written on it in his hand. Then, starting from X, they will alternately perform the following action:
 - Draw some number of cards from the top of the deck. Then, discard the card in his hand and keep the last drawn card instead. Here, at least one card must be drawn.
The game ends when there is no more card in the deck. The score of the game is the absolute difference of the integers written on the cards in the two players' hand.
X will play the game so that the score will be maximized, and Y will play the game so that the score will be minimized. What will be the score of the game?

-----Constraints-----
 - All input values are integers.
 - 1 \leq N \leq 2000
 - 1 \leq Z, W, a_i \leq 10^9

-----Input-----
Input is given from Standard Input in the following format:
N Z W
a_1 a_2 ... a_N

-----Output-----
Print the score.

-----Sample Input-----
3 100 100
10 1000 100

-----Sample Output-----
900

If X draws two cards first, Y will draw the last card, and the score will be |1000 - 100| = 900.

I tried it in Python, but could not do it. Can you solve it?

n, z, w = map(int,input().split())
a = list(map(int,input().split()))
if n == 1:
    print(abs(a[0]-w))
else:
    p = abs(a[-2] - a[-1])
    q = abs(a[-1] - w)
    print(max(p,q))


I found an interesting problem on https://atcoder.jp/contests/abc079/tasks/abc079_a:
We call a 4-digit integer with three or more consecutive same digits, such as 1118, good.
You are given a 4-digit integer N. Answer the question: Is N good?

-----Constraints-----
 - 1000 ≤ N ≤ 9999
 - N is an integer.

-----Input-----
Input is given from Standard Input in the following format:
N

-----Output-----
If N is good, print Yes; otherwise, print No.

-----Sample Input-----
1118

-----Sample Output-----
Yes

N is good, since it contains three consecutive 1.

I tried it in Python, but could not do it. Can you solve it?


I found an interesting problem on https://atcoder.jp/contests/abc079/tasks/abc079_b:
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers.
You are given an integer N. Find the N-th Lucas number.
Here, the i-th Lucas number L_i is defined as follows:
 - L_0=2
 - L_1=1
 - L_i=L_{i-1}+L_{i-2} (i≥2)

-----Constraints-----
 - 1≤N≤86
 - It is guaranteed that the answer is less than 10^{18}.
 - N is an integer.

-----Input-----
Input is given from Standard Input in the following format:
N

-----Output-----
Print the N-th Lucas number.

-----Sample Input-----
5

-----Sample Output-----
11

 - L_0=2
 - L_1=1
 - L_2=L_0+L_1=3
 - L_3=L_1+L_2=4
 - L_4=L_2+L_3=7
 - L_5=L_3+L_4=11
Thus, the 5-th Lucas number is 11.

I tried it in Python, but could not do it. Can you solve it?