I found an interesting problem on https://atcoder.jp/contests/abc079/tasks/abc079_c:
Sitting in a station waiting room, Joisino is gazing at her train ticket.
The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive).
In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with + or - so that the formula holds.
The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.

-----Constraints-----
 - 0≤A,B,C,D≤9
 - All input values are integers.
 - It is guaranteed that there is a solution.

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

-----Output-----
Print the formula you made, including the part =7.
Use the signs + and -.
Do not print a space between a digit and a sign.

-----Sample Input-----
1222

-----Sample Output-----
1+2+2+2=7

This is the only valid solution.

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

def dfs(i,sum1,sum2):
    nonlocal ans
    #print(sum1,sum2)
    if i == 4 and sum1 != 7:
        return 0
    elif i == 4 and sum1 == 7:
        ans = sum2 + "=7"
    else:
        dfs(i + 1,sum1 - int(s[i]),sum2 + "-" +s[i])
        dfs(i + 1,sum1 + int(s[i]),sum2 + "+" +s[i])

ans = ""
s = input()
dfs(1,int(s[0]),s[0])
print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc079/tasks/abc079_d:
Joisino the magical girl has decided to turn every single digit that exists on this world into 1.
Rewriting a digit i with j (0≤i,j≤9) costs c_{i,j} MP (Magic Points).
She is now standing before a wall. The wall is divided into HW squares in H rows and W columns, and at least one square contains a digit between 0 and 9 (inclusive).
You are given A_{i,j} that describes the square at the i-th row from the top and j-th column from the left, as follows:
 - If A_{i,j}≠-1, the square contains a digit A_{i,j}.
 - If A_{i,j}=-1, the square does not contain a digit.
Find the minimum total amount of MP required to turn every digit on this wall into 1 in the end.

-----Constraints-----
 - 1≤H,W≤200
 - 1≤c_{i,j}≤10^3 (i≠j)
 - c_{i,j}=0 (i=j)
 - -1≤A_{i,j}≤9
 - All input values are integers.
 - There is at least one digit on the wall.

-----Input-----
Input is given from Standard Input in the following format:
H W
c_{0,0} ... c_{0,9}
:
c_{9,0} ... c_{9,9}
A_{1,1} ... A_{1,W}
:
A_{H,1} ... A_{H,W}

-----Output-----
Print the minimum total amount of MP required to turn every digit on the wall into 1 in the end.

-----Sample Input-----
2 4
0 9 9 9 9 9 9 9 9 9
9 0 9 9 9 9 9 9 9 9
9 9 0 9 9 9 9 9 9 9
9 9 9 0 9 9 9 9 9 9
9 9 9 9 0 9 9 9 9 2
9 9 9 9 9 0 9 9 9 9
9 9 9 9 9 9 0 9 9 9
9 9 9 9 9 9 9 0 9 9
9 9 9 9 2 9 9 9 0 9
9 2 9 9 9 9 9 9 9 0
-1 -1 -1 -1
8 1 1 8

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

To turn a single 8 into 1, it is optimal to first turn 8 into 4, then turn 4 into 9, and finally turn 9 into 1, costing 6 MP.
The wall contains two 8s, so the minimum total MP required is 6×2=12.

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

from itertools import chain
import numpy as np
import networkx as nx

h, w, *X = map(int, open(0).read().split())
C = np.array(X[:100], dtype=int).reshape((10, 10))
A = np.array(X[100:], dtype=int).reshape((h, w))

G = nx.DiGraph(C)
d = {-1:0}
for i in range(10):
    d[i] = nx.shortest_path_length(G, i, 1, weight='weight')
print(sum(d[a] for a in chain.from_iterable(A)))


I found an interesting problem on https://atcoder.jp/contests/abc080/tasks/abc080_a:
You are parking at a parking lot. You can choose from the following two fee plans:
 - Plan 1: The fee will be A×T yen (the currency of Japan) when you park for T hours.
 - Plan 2: The fee will be B yen, regardless of the duration.
Find the minimum fee when you park for N hours.

-----Constraints-----
 - 1≤N≤20
 - 1≤A≤100
 - 1≤B≤2000
 - All input values are integers.

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

-----Output-----
When the minimum fee is x yen, print the value of x.

-----Sample Input-----
7 17 120

-----Sample Output-----
119

 - If you choose Plan 1, the fee will be 7×17=119 yen.
 - If you choose Plan 2, the fee will be 120 yen.
Thus, the minimum fee is 119 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/abc080/tasks/abc080_b:
An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10.
Given an integer N, determine whether it is a Harshad number.

-----Constraints-----
 - 1?N?10^8
 - N is an integer.

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

-----Output-----
Print Yes if N is a Harshad number; print No otherwise.

-----Sample Input-----
12

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

f(12)=1+2=3. Since 12 is divisible by 3, 12 is a Harshad number.

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

n = input()
n_int = int(n)

n_sum = 0

for s in n:
    n_sum += int(s)

if(n_int%n_sum == 0):
    print("Yes")
else:
    print("No")


I found an interesting problem on https://atcoder.jp/contests/abc080/tasks/abc080_c:
Joisino is planning to open a shop in a shopping street.
Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those periods.
There are already N stores in the street, numbered 1 through N.
You are given information of the business hours of those shops, F_{i,j,k}. If F_{i,j,k}=1, Shop i is open during Period k on Day j (this notation is explained below); if F_{i,j,k}=0, Shop i is closed during that period. Here, the days of the week are denoted as follows. Monday: Day 1, Tuesday: Day 2, Wednesday: Day 3, Thursday: Day 4, Friday: Day 5. Also, the morning is denoted as Period 1, and the afternoon is denoted as Period 2.
Let c_i be the number of periods during which both Shop i and Joisino's shop are open. Then, the profit of Joisino's shop will be P_{1,c_1}+P_{2,c_2}+...+P_{N,c_N}.
Find the maximum possible profit of Joisino's shop when she decides whether her shop is open during each period, making sure that it is open during at least one period.

-----Constraints-----
 - 1≤N≤100
 - 0≤F_{i,j,k}≤1
 - For every integer i such that 1≤i≤N, there exists at least one pair (j,k) such that F_{i,j,k}=1.
 - -10^7≤P_{i,j}≤10^7
 - All input values are integers.

-----Input-----
Input is given from Standard Input in the following format:
N
F_{1,1,1} F_{1,1,2} ... F_{1,5,1} F_{1,5,2}
:
F_{N,1,1} F_{N,1,2} ... F_{N,5,1} F_{N,5,2}
P_{1,0} ... P_{1,10}
:
P_{N,0} ... P_{N,10}

-----Output-----
Print the maximum possible profit of Joisino's shop.

-----Sample Input-----
1
1 1 0 1 0 0 0 1 0 1
3 4 5 6 7 8 9 -2 -3 4 -2

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

If her shop is open only during the periods when Shop 1 is opened, the profit will be 8, which is the maximum possible profit.

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

import sys
from heapq import heappush, heappop
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())

def main():
    n = ii()
    F = []
    P = []
    for _ in range(n):
        F.append(li())
    for _ in range(n):
        P.append(li())

    inf = 10 ** 18
    ans = -inf
    for i in range(1, 1<<10):
        c = [0]*(n)
        tmp = 0
        for j in range(10):
            if (i>>j)&1:
                for k in range(n):
                    c[k] += F[k][j]
        for k in range(n):
            tmp += P[k][c[k]]
        ans = max(ans, tmp)
    print(ans)

def __starting_point():
    main()
__starting_point()


I found an interesting problem on https://atcoder.jp/contests/abc080/tasks/abc080_d:
Joisino is planning to record N TV programs with recorders.
The TV can receive C channels numbered 1 through C.
The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i.
Here, there will never be more than one program that are broadcast on the same channel at the same time.
When the recorder is recording a channel from time S to time T (including time S but not T), it cannot record other channels from time S-0.5 to time T (including time S-0.5 but not T).
Find the minimum number of recorders required to record the channels so that all the N programs are completely recorded.

-----Constraints-----
 - 1≤N≤10^5
 - 1≤C≤30
 - 1≤s_i<t_i≤10^5
 - 1≤c_i≤C
 - If c_i=c_j and i≠j, either t_i≤s_j or s_i≥t_j.
 - All input values are integers.

-----Input-----
Input is given from Standard Input in the following format:
N C
s_1 t_1 c_1
:
s_N t_N c_N

-----Output-----
When the minimum required number of recorders is x, print the value of x.

-----Sample Input-----
3 2
1 7 2
7 8 1
8 12 1

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

Two recorders can record all the programs, for example, as follows:
 - With the first recorder, record Channel 2 from time 1 to time 7. The first program will be recorded. Note that this recorder will be unable to record other channels from time 0.5 to time 7.
 - With the second recorder, record Channel 1 from time 7 to time 12. The second and third programs will be recorded. Note that this recorder will be unable to record other channels from time 6.5 to time 12.

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

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

t = [[0 for i in range(100001)] for j in range(c)]

for i in range(n):
    si,ti,ci = list(map(int,input().split()))
    for j in range(si,ti+1):
        t[ci-1][j] = 1
print((max(sum(t[j][i] for j in range(c)) for i in range(100001))))


I found an interesting problem on https://atcoder.jp/contests/abc081/tasks/abc081_a:
Snuke has a grid consisting of three squares numbered 1, 2 and 3.
In each square, either 0 or 1 is written. The number written in Square i is s_i.
Snuke will place a marble on each square that says 1.
Find the number of squares on which Snuke will place a marble.

-----Constraints-----
 - Each of s_1, s_2 and s_3 is either 1 or 0.

-----Input-----
Input is given from Standard Input in the following format:
s_{1}s_{2}s_{3}

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

-----Sample Input-----
101

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

 - A marble will be placed on Square 1 and 3.

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


I found an interesting problem on https://atcoder.jp/contests/abc081/tasks/abc081_b:
There are N positive integers written on a blackboard: A_1, ..., A_N.
Snuke can perform the following operation when all integers on the blackboard are even:
 - Replace each integer X on the blackboard by X divided by 2.
Find the maximum possible number of operations that Snuke can perform.

-----Constraints-----
 - 1 \leq N \leq 200
 - 1 \leq A_i \leq 10^9

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

-----Output-----
Print the maximum possible number of operations that Snuke can perform.

-----Sample Input-----
3
8 12 40

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

Initially, [8, 12, 40] are written on the blackboard.
Since all those integers are even, Snuke can perform the operation.
After the operation is performed once, [4, 6, 20] are written on the blackboard.
Since all those integers are again even, he can perform the operation.
After the operation is performed twice, [2, 3, 10] are written on the blackboard.
Now, there is an odd number 3 on the blackboard, so he cannot perform the operation any more.
Thus, Snuke can perform the operation at most twice.

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

n = int(input())
l = list(input().split(' '))

flag = True
t = 0
while True:
    for i, x in enumerate(l):
        if int(x) % 2 == 0:
            l[i] = int(x) / 2
        else:
            flag = False
            break
    if flag:
        t += 1
    else:
        break

print(t)


I found an interesting problem on https://atcoder.jp/contests/abc081/tasks/arc086_a:
Takahashi has N balls. Initially, an integer A_i is written on the i-th ball.
He would like to rewrite the integer on some balls so that there are at most K different integers written on the N balls.
Find the minimum number of balls that Takahashi needs to rewrite the integers on them.

-----Constraints-----
 - 1 \leq K \leq N \leq 200000
 - 1 \leq A_i \leq N
 - All input values are integers.

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

-----Output-----
Print the minimum number of balls that Takahashi needs to rewrite the integers on them.

-----Sample Input-----
5 2
1 1 2 2 5

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

For example, if we rewrite the integer on the fifth ball to 2, there are two different integers written on the balls: 1 and 2.
On the other hand, it is not possible to rewrite the integers on zero balls so that there are at most two different integers written on the balls, so we should print 1.

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()))

import collections

cA = collections.Counter(A)

sorted_ls = sorted(list(cA.values()))
sum_ls = sum(sorted_ls)

if len(sorted_ls)>K:
  print(sum(sorted_ls[:len(sorted_ls)-K]))
else:
  print(0)


I found an interesting problem on https://atcoder.jp/contests/abc082/tasks/abc082_a:
You are given two positive integers a and b.
Let x be the average of a and b.
Print x rounded up to the nearest integer.

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

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

-----Output-----
Print x rounded up to the nearest integer.

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

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

The average of 1 and 3 is 2.0, and it will be rounded up to the nearest integer, 2.

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

a,b=map(int,input().split())
import math
print(math.ceil((a+b)/2))


I found an interesting problem on https://atcoder.jp/contests/abc082/tasks/abc082_b:
You are given strings s and t, consisting of lowercase English letters.
You will create a string s' by freely rearranging the characters in s.
You will also create a string t' by freely rearranging the characters in t.
Determine whether it is possible to satisfy s' < t' for the lexicographic order.

-----Notes-----
For a string a = a_1 a_2 ... a_N of length N and a string b = b_1 b_2 ... b_M of length M, we say a < b for the lexicographic order if either one of the following two conditions holds true:
 - N < M and a_1 = b_1, a_2 = b_2, ..., a_N = b_N.
 - There exists i (1 \leq i \leq N, M) such that a_1 = b_1, a_2 = b_2, ..., a_{i - 1} = b_{i - 1} and a_i < b_i. Here, letters are compared using alphabetical order.
For example, xy < xya and atcoder < atlas.

-----Constraints-----
 - The lengths of s and t are between 1 and 100 (inclusive).
 - s and t consists of lowercase English letters.

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

-----Output-----
If it is possible to satisfy s' < t', print Yes; if it is not, print No.

-----Sample Input-----
yx
axy

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

We can, for example, rearrange yx into xy and axy into yxa. Then, xy < yxa.

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

s = "".join(sorted(input()))
t = "".join(sorted(input(), reverse=True))
if s < t:
    print("Yes")
else:
    print("No")


I found an interesting problem on https://atcoder.jp/contests/abc082/tasks/arc087_a:
You are given a sequence of positive integers of length N, a = (a_1, a_2, ..., a_N).
Your objective is to remove some of the elements in a so that a will be a good sequence.
Here, an sequence b is a good sequence when the following condition holds true:
 - For each element x in b, the value x occurs exactly x times in b.
For example, (3, 3, 3), (4, 2, 4, 1, 4, 2, 4) and () (an empty sequence) are good sequences, while (3, 3, 3, 3) and (2, 4, 1, 4, 2) are not.
Find the minimum number of elements that needs to be removed so that a will be a good sequence.

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

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

-----Output-----
Print the minimum number of elements that needs to be removed so that a will be a good sequence.

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

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

We can, for example, remove one occurrence of 3. Then, (3, 3, 3) is a good sequence.

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

import collections

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

aa = collections.Counter(a).most_common()
#print(aa)

for i,j in aa:
    if i > j:
        ans += j
    if i < j:
        ans += j-i

print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc083/tasks/abc083_a:
A balance scale tips to the left if L>R, where L is the total weight of the masses on the left pan and R is the total weight of the masses on the right pan. Similarly, it balances if L=R, and tips to the right if L<R.
Takahashi placed a mass of weight A and a mass of weight B on the left pan of a balance scale, and placed a mass of weight C and a mass of weight D on the right pan.
Print Left if the balance scale tips to the left; print Balanced if it balances; print Right if it tips to the right.

-----Constraints-----
 - 1\leq A,B,C,D \leq 10
 - All input values are integers.

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

-----Output-----
Print Left if the balance scale tips to the left; print Balanced if it balances; print Right if it tips to the right.

-----Sample Input-----
3 8 7 1

-----Sample Output-----
Left

The total weight of the masses on the left pan is 11, and the total weight of the masses on the right pan is 8. Since 11>8, we should print Left.

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

A,B,C,D = map(int, input().split())
if A+B > C+D:
  print("Left")
elif A+B == C+D:
  print("Balanced")
else:
  print("Right")


I found an interesting problem on https://atcoder.jp/contests/abc083/tasks/abc083_b:
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).

-----Constraints-----
 - 1 \leq N \leq 10^4
 - 1 \leq A \leq B \leq 36
 - All input values are integers.

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

-----Output-----
Print the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).

-----Sample Input-----
20 2 5

-----Sample Output-----
84

Among the integers not greater than 20, the ones whose sums of digits are between 2 and 5, are: 2,3,4,5,11,12,13,14 and 20. We should print the sum of these, 84.

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

N,A,B = map(int,input().split())
cnt = 0
sum = 0
i = 0
for i in range(N+1):
    j = 0
    tmpsum = 0
    l = list(str(i))
    for j in l:
        tmpsum += int(j)
    if tmpsum>=A and tmpsum <=B:
        sum += i
print(sum)


I found an interesting problem on https://atcoder.jp/contests/abc083/tasks/arc088_b:
You are given a string S consisting of 0 and 1.
Find the maximum integer K not greater than |S| such that we can turn all the characters of S into 0 by repeating the following operation some number of times.
 - Choose a contiguous segment [l,r] in S whose length is at least K (that is, r-l+1\geq K must be satisfied). For each integer i such that l\leq i\leq r, do the following: if S_i is 0, replace it with 1; if S_i is 1, replace it with 0.

-----Constraints-----
 - 1\leq |S|\leq 10^5
 - S_i(1\leq i\leq N) is either 0 or 1.

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

-----Output-----
Print the maximum integer K such that we can turn all the characters of S into 0 by repeating the operation some number of times.

-----Sample Input-----
010

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

We can turn all the characters of S into 0 by the following operations:
 - Perform the operation on the segment S[1,3] with length 3. S is now 101.
 - Perform the operation on the segment S[1,2] with length 2. S is now 011.
 - Perform the operation on the segment S[2,3] with length 2. S is now 000.

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

slist=list(map(int,list(input())))
len_s=len(slist)

min_answer=len_s
for i in range(1,len_s):
  if slist[i-1]!=slist[i]:
    min_answer=min(min_answer,max(i,len_s-i))
    #print(i,len(slist)-i)

print(min_answer)


I found an interesting problem on https://atcoder.jp/contests/abc084/tasks/abc084_a:
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?

-----Constraints-----
 - 1≤M≤23
 - M is an integer.

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

-----Output-----
If we have x hours until New Year at M o'clock on 30th, December, print x.

-----Sample Input-----
21

-----Sample Output-----
27

We have 27 hours until New Year at 21 o'clock on 30th, December.

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

#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)

m = int(input())

print((24-m+24))


I found an interesting problem on https://atcoder.jp/contests/abc084/tasks/abc084_b:
The postal code in Atcoder Kingdom is A+B+1 characters long, its (A+1)-th character is a hyphen -, and the other characters are digits from 0 through 9.
You are given a string S. Determine whether it follows the postal code format in Atcoder Kingdom.

-----Constraints-----
 - 1≤A,B≤5
 - |S|=A+B+1
 - S consists of - and digits from 0 through 9.

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

-----Output-----
Print Yes if S follows the postal code format in AtCoder Kingdom; print No otherwise.

-----Sample Input-----
3 4
269-6650

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

The (A+1)-th character of S is -, and the other characters are digits from 0 through 9, so it follows the format.

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

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

if len(s)==a+b+1 and s[a]=="-" and s.count("-")==1:
    print("Yes")
else:
    print("No")


I found an interesting problem on https://atcoder.jp/contests/abc084/tasks/abc084_c:
A railroad running from west to east in Atcoder Kingdom is now complete.
There are N stations on the railroad, numbered 1 through N from west to east.
Tomorrow, the opening ceremony of the railroad will take place.
On this railroad, for each integer i such that 1≤i≤N-1, there will be trains that run from Station i to Station i+1 in C_i seconds. No other trains will be operated.
The first train from Station i to Station i+1 will depart Station i S_i seconds after the ceremony begins. Thereafter, there will be a train that departs Station i every F_i seconds.
Here, it is guaranteed that F_i divides S_i.
That is, for each Time t satisfying S_i≤t and t％F_i=0, there will be a train that departs Station i t seconds after the ceremony begins and arrives at Station i+1 t+C_i seconds after the ceremony begins, where A％B denotes A modulo B, and there will be no other trains.
For each i, find the earliest possible time we can reach Station N if we are at Station i when the ceremony begins, ignoring the time needed to change trains.

-----Constraints-----
 - 1≤N≤500
 - 1≤C_i≤100
 - 1≤S_i≤10^5
 - 1≤F_i≤10
 - S_i％F_i=0
 - All input values are integers.

-----Input-----
Input is given from Standard Input in the following format:
N
C_1 S_1 F_1
:
C_{N-1} S_{N-1} F_{N-1}

-----Output-----
Print N lines. Assuming that we are at Station i (1≤i≤N) when the ceremony begins, if the earliest possible time we can reach Station N is x seconds after the ceremony begins, the i-th line should contain x.

-----Sample Input-----
3
6 5 1
1 10 1

-----Sample Output-----
12
11
0

We will travel from Station 1 as follows:
 - 5 seconds after the beginning: take the train to Station 2.
 - 11 seconds: arrive at Station 2.
 - 11 seconds: take the train to Station 3.
 - 12 seconds: arrive at Station 3.
We will travel from Station 2 as follows:
 - 10 seconds: take the train to Station 3.
 - 11 seconds: arrive at Station 3.
Note that we should print 0 for Station 3.

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

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

for i in range(n):
    time = 0
    while True:
        if i == n-1:
            print(time)
            break
        if time < csf[i][1]:
            time = csf[i][1] + csf[i][0]
        else:
            if time%csf[i][2] == 0:
                time += csf[i][0]
            else:
                time += csf[i][0] + csf[i][2] -  time%csf[i][2]
        i += 1


I found an interesting problem on https://atcoder.jp/contests/abc084/tasks/abc084_d:
We say that a odd number N is similar to 2017 when both N and (N+1)/2 are prime.
You are given Q queries.
In the i-th query, given two odd numbers l_i and r_i, find the number of odd numbers x similar to 2017 such that l_i ≤ x ≤ r_i.

-----Constraints-----
 - 1≤Q≤10^5
 - 1≤l_i≤r_i≤10^5
 - l_i and r_i are odd.
 - All input values are integers.

-----Input-----
Input is given from Standard Input in the following format:
Q
l_1 r_1
:
l_Q r_Q

-----Output-----
Print Q lines. The i-th line (1≤i≤Q) should contain the response to the i-th query.

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

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

 - 3 is similar to 2017, since both 3 and (3+1)/2=2 are prime.
 - 5 is similar to 2017, since both 5 and (5+1)/2=3 are prime.
 - 7 is not similar to 2017, since (7+1)/2=4 is not prime, although 7 is prime.
Thus, the response to the first query should be 2.

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

def is_prime(n):
    for i in range(2, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            return 0
    return 1

sl = [0, 0]
for j in range(2, 10 ** 5 + 1):
    if j % 2 == 0:
        sl.append(sl[j - 1])
    elif is_prime(j) == 1 and is_prime((j + 1) // 2) == 1:
        sl.append(sl[j - 1] + 1)
    else:
        sl.append(sl[j - 1])

q = int(input())
for _ in range(q):
    l, r = list(map(int, input().split()))
    print((sl[r] - sl[l-1]))


I found an interesting problem on https://atcoder.jp/contests/abc085/tasks/abc085_a:
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in yyyy/mm/dd format. For example, January 23, 2018 should be written as 2018/01/23.
After finishing the document, she noticed that she had mistakenly wrote 2017 at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to 2018 and prints it.

-----Constraints-----
 - S is a string of length 10.
 - The first eight characters in S are 2017/01/.
 - The last two characters in S are digits and represent an integer between 1 and 31 (inclusive).

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

-----Output-----
Replace the first four characters in S with 2018 and print it.

-----Sample Input-----
2017/01/07

-----Sample Output-----
2018/01/07

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

date = str(input())
print((date.replace('2017', '2018')))


I found an interesting problem on https://atcoder.jp/contests/abc085/tasks/abc085_b:
An X-layered kagami mochi (X ≥ 1) is a pile of X round mochi (rice cake) stacked vertically where each mochi (except the bottom one) has a smaller diameter than that of the mochi directly below it. For example, if you stack three mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, you have a 3-layered kagami mochi; if you put just one mochi, you have a 1-layered kagami mochi.
Lunlun the dachshund has N round mochi, and the diameter of the i-th mochi is d_i centimeters. When we make a kagami mochi using some or all of them, at most how many layers can our kagami mochi have?

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

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

-----Output-----
Print the maximum number of layers in a kagami mochi that can be made.

-----Sample Input-----
4
10
8
8
6

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

If we stack the mochi with diameters of 10, 8 and 6 centimeters from bottom to top in this order, we have a 3-layered kagami mochi, which is the maximum number of layers.

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

n = int(input())
lst = []
for i in range(n):
  d = int(input())
  lst.append(d)
res = sorted(list(set(lst)))
print(len(res))


I found an interesting problem on https://atcoder.jp/contests/abc085/tasks/abc085_d:
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order:
 - Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times.
 - Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana.
The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?

-----Constraints-----
 - 1 ≤ N ≤ 10^5
 - 1 ≤ H ≤ 10^9
 - 1 ≤ a_i ≤ b_i ≤ 10^9
 - All input values are integers.

-----Input-----
Input is given from Standard Input in the following format:
N H
a_1 b_1
:
a_N b_N

-----Output-----
Print the minimum total number of attacks required to vanish the monster.

-----Sample Input-----
1 10
3 5

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

You have one katana. Wielding it deals 3 points of damage, and throwing it deals 5 points of damage. By wielding it twice and then throwing it, you will deal 3 + 3 + 5 = 11 points of damage in a total of three attacks, vanishing the monster.

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

import sys

n, h = map(int, input().split())
a = [list(map(int, x.split())) for x in sys.stdin.readlines()]
a.sort(reverse=True)
b = sorted(a, key=lambda x:x[1], reverse=True)
cnt = 0
for i in b:
    if i[1] < a[0][0]:
        break
    cnt += 1
    h -= i[1]
    if h <= 0:
        print(cnt)
        return
print(cnt + -(-h//a[0][0]))


I found an interesting problem on https://atcoder.jp/contests/abc086/tasks/abc086_a:
AtCoDeer the deer found two positive integers, a and b.
Determine whether the product of a and b is even or odd.

-----Constraints-----
 - 1 ≤ a,b ≤ 10000
 - a and b are integers.

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

-----Output-----
If the product is odd, print Odd; if it is even, print Even.

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

-----Sample Output-----
Even

As 3 × 4 = 12 is even, print Even.

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

a, b = map(int, input().split())
if a*b %2 == 0:
    print("Even")
else:
    print("Odd")


I found an interesting problem on https://atcoder.jp/contests/abc086/tasks/abc086_b:
AtCoDeer the deer has found two positive integers, a and b.
Determine whether the concatenation of a and b in this order is a square number.

-----Constraints-----
 - 1 ≤ a,b ≤ 100
 - a and b are integers.

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

-----Output-----
If the concatenation of a and b in this order is a square number, print Yes; otherwise, print No.

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

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

As 121 = 11 × 11, it is a square number.

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

n = int("".join(input().split()))
x = n**0.5
if x == int(x):
  print("Yes")
else:
  print("No")


I found an interesting problem on https://atcoder.jp/contests/abc086/tasks/arc089_a:
AtCoDeer the deer is going on a trip in a two-dimensional plane.
In his plan, he will depart from point (0, 0) at time 0, then for each i between 1 and N (inclusive), he will visit point (x_i,y_i) at time t_i.
If AtCoDeer is at point (x, y) at time t, he can be at one of the following points at time t+1: (x+1,y), (x-1,y), (x,y+1) and (x,y-1).
Note that he cannot stay at his place.
Determine whether he can carry out his plan.

-----Constraints-----
 - 1 ≤ N ≤ 10^5
 - 0 ≤ x_i ≤ 10^5
 - 0 ≤ y_i ≤ 10^5
 - 1 ≤ t_i ≤ 10^5
 - t_i < t_{i+1} (1 ≤ i ≤ N-1)
 - All input values are integers.

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

-----Output-----
If AtCoDeer can carry out his plan, print Yes; if he cannot, print No.

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

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

For example, he can travel as follows: (0,0), (0,1), (1,1), (1,2), (1,1), (1,0), then (1,1).

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

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

pT, pX, pY = 0, 0, 0

for i in range(N):
    cT, cX, cY = l[i]
    mvT, mvX, mvY = abs(cT-pT), abs(cX-pX), abs(cY-pY)

    dam = mvT - (mvX+mvY)

    if dam %2 == 1 or dam < 0:
        print('No')
        return

    pT, pX, pY = l[i]

print('Yes')


I found an interesting problem on https://atcoder.jp/contests/abc086/tasks/arc089_b:
AtCoDeer is thinking of painting an infinite two-dimensional grid in a checked pattern of side K.
Here, a checked pattern of side K is a pattern where each square is painted black or white so that each connected component of each color is a K × K square.
Below is an example of a checked pattern of side 3:
AtCoDeer has N desires.
The i-th desire is represented by x_i, y_i and c_i.
If c_i is B, it means that he wants to paint the square (x_i,y_i) black; if c_i is W, he wants to paint the square (x_i,y_i) white.
At most how many desires can he satisfy at the same time?

-----Constraints-----
 - 1 ≤ N ≤ 10^5
 - 1 ≤ K ≤ 1000
 - 0 ≤ x_i ≤ 10^9
 - 0 ≤ y_i ≤ 10^9
 - If i ≠ j, then (x_i,y_i) ≠ (x_j,y_j).
 - c_i is B or W.
 - N, K, x_i and y_i are integers.

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

-----Output-----
Print the maximum number of desires that can be satisfied at the same time.

-----Sample Input-----
4 3
0 1 W
1 2 W
5 3 B
5 4 B

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

He can satisfy all his desires by painting as shown in the example above.

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

import sys
import numpy as np

read=sys.stdin.read
readline=sys.stdin.readline

def main():
  wb={'W':1,'B':0}
  n,k=list(map(int,readline().split()))
  xyc=[l.split() for l in read().splitlines()]
  xy=[[int(lst[0]) % (2*k),(int(lst[1])+k*wb[lst[2]]) % (2*k)] for lst in xyc]
  mat=np.zeros((k+1,2*k+1),dtype='int64')
  cand=np.zeros((k+1,k+1),dtype='int64')
  for e in xy:
    f0=e[0]>=k
    f1=e[1]>=k
    mat[e[0]-f0*k+1,e[1]+(-1)**f1*f0*k+1]+=1
  mat=np.cumsum(mat,axis=0)
  mat=np.cumsum(mat,axis=1)
  cand=mat[k,2*k]-mat[k,k:2*k+1]+mat[k,:k+1]\
       -np.reshape(mat[:k+1,2*k],(k+1,1))+2*mat[:,k:2*k+1]-2*mat[:,:k+1]
  print((max(np.max(cand),mat[k,2*k]-np.min(cand))))

def __starting_point():
  main()

__starting_point()


I found an interesting problem on https://atcoder.jp/contests/abc087/tasks/abc087_a:
You went shopping to buy cakes and donuts with X yen (the currency of Japan).
First, you bought one cake for A yen at a cake shop.
Then, you bought as many donuts as possible for B yen each, at a donut shop.
How much do you have left after shopping?

-----Constraints-----
 - 1 \leq A, B \leq 1 000
 - A + B \leq X \leq 10 000
 - X, A and B are integers.

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

-----Output-----
Print the amount you have left after shopping.

-----Sample Input-----
1234
150
100

-----Sample Output-----
84

You have 1234 - 150 = 1084 yen left after buying a cake.
With this amount, you can buy 10 donuts, after which you have 84 yen left.

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

x = int(input())
a = int(input())
b = int(input())

print((x-a)%b)


I found an interesting problem on https://atcoder.jp/contests/abc087/tasks/abc087_b:
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan).
In how many ways can we select some of these coins so that they are X yen in total?
Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.

-----Constraints-----
 - 0 \leq A, B, C \leq 50
 - A + B + C \geq 1
 - 50 \leq X \leq 20 000
 - A, B and C are integers.
 - X is a multiple of 50.

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

-----Output-----
Print the number of ways to select coins.

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

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

There are two ways to satisfy the condition:
 - Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.
 - Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.

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

a = int(input())
b = int(input())
c = int(input())
x = int(input())

cnt = 0
for i in range(a+1):
  for j in range(b+1):
    for k in range(c+1):
      if 500 * i + 100 * j + 50 * k == x:
        cnt += 1

print(cnt)


I found an interesting problem on https://atcoder.jp/contests/abc087/tasks/arc090_a:
We have a 2 \times N grid. We will denote the square at the i-th row and j-th column (1 \leq i \leq 2, 1 \leq j \leq N) as (i, j).
You are initially in the top-left square, (1, 1).
You will travel to the bottom-right square, (2, N), by repeatedly moving right or down.
The square (i, j) contains A_{i, j} candies.
You will collect all the candies you visit during the travel.
The top-left and bottom-right squares also contain candies, and you will also collect them.
At most how many candies can you collect when you choose the best way to travel?

-----Constraints-----
 - 1 \leq N \leq 100
 - 1 \leq A_{i, j} \leq 100 (1 \leq i \leq 2, 1 \leq j \leq N)

-----Input-----
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}

-----Output-----
Print the maximum number of candies that can be collected.

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

-----Sample Output-----
14

The number of collected candies will be maximized when you:
 - move right three times, then move down once, then move right once.

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

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C=[]
for i in range(N):
    C.append(sum(A[0:i+1])+sum(B[i:]))
print(max(C))


I found an interesting problem on https://atcoder.jp/contests/abc087/tasks/arc090_b:
There are N people standing on the x-axis.
Let the coordinate of Person i be x_i.
For every i, x_i is an integer between 0 and 10^9 (inclusive).
It is possible that more than one person is standing at the same coordinate.
You will given M pieces of information regarding the positions of these people.
The i-th piece of information has the form (L_i, R_i, D_i).
This means that Person R_i is to the right of Person L_i by D_i units of distance, that is, x_{R_i} - x_{L_i} = D_i holds.
It turns out that some of these M pieces of information may be incorrect.
Determine if there exists a set of values (x_1, x_2, ..., x_N) that is consistent with the given pieces of information.

-----Constraints-----
 - 1 \leq N \leq 100 000
 - 0 \leq M \leq 200 000
 - 1 \leq L_i, R_i \leq N (1 \leq i \leq M)
 - 0 \leq D_i \leq 10 000 (1 \leq i \leq M)
 - L_i \neq R_i (1 \leq i \leq M)
 - If i \neq j, then (L_i, R_i) \neq (L_j, R_j) and (L_i, R_i) \neq (R_j, L_j).
 - D_i are integers.

-----Input-----
Input is given from Standard Input in the following format:
N M
L_1 R_1 D_1
L_2 R_2 D_2
:
L_M R_M D_M

-----Output-----
If there exists a set of values (x_1, x_2, ..., x_N) that is consistent with all given pieces of information, print Yes; if it does not exist, print No.

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

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

Some possible sets of values (x_1, x_2, x_3) are (0, 1, 2) and (101, 102, 103).

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

import sys
sys.setrecursionlimit(10**9)

read=sys.stdin.read
class Unionfind():
    def __init__(self,n):
        self.parents=[-1]*n
        self.dist=[0]*n

    def find(self,x):
        if self.parents[x]<0:
            return x,self.dist[x]
        else:
            tmp=self.find(self.parents[x])
            self.parents[x]=tmp[0]
            self.dist[x]+=tmp[1]
            return self.parents[x],self.dist[x]

    def union(self,x,y,d):
        rx=self.find(x)[0]
        ry=self.find(y)[0]
        diff=self.dist[y]-self.dist[x]-d
        if rx==ry:
            if diff!=0:
                return True
            return False
        if diff<0:
            rx,ry=ry,rx
            diff=-diff
        self.parents[ry]=min(self.parents[ry],self.parents[rx]-diff)
        self.parents[rx]=ry
        self.dist[rx]=diff
        return False

def main():
    n,m,*lrd=list(map(int,read().split()))
    v=Unionfind(n)
    for l,r,d in zip(*[iter(lrd)]*3):
        if v.union(l-1,r-1,d):
            print('No')
            break
    else:
        print('Yes')
def __starting_point():
    main()

__starting_point()


I found an interesting problem on https://atcoder.jp/contests/abc088/tasks/abc088_a:
E869120 has A 1-yen coins and infinitely many 500-yen coins.

Determine if he can pay exactly N yen using only these coins.

-----Constraints-----
 - N is an integer between 1 and 10000 (inclusive).
 - A is an integer between 0 and 1000 (inclusive).

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

-----Output-----
If E869120 can pay exactly N yen using only his 1-yen and 500-yen coins, print Yes; otherwise, print No.

-----Sample Input-----
2018
218

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

We can pay 2018 yen with four 500-yen coins and 18 1-yen coins, so the answer is Yes.

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

# -*- coding: utf-8 -*-

N = int(input())
A = int(input())

remainder = N % 500
if A > remainder or remainder==0:
    print("Yes")
else:
    print("No")


I found an interesting problem on https://atcoder.jp/contests/abc088/tasks/abc088_b:
We have N cards. A number a_i is written on the i-th card.

Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first.

The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.

-----Constraints-----
 - N is an integer between 1 and 100 (inclusive).
 - a_i \ (1 \leq i \leq N) is an integer between 1 and 100 (inclusive).

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

-----Output-----
Print Alice's score minus Bob's score when both players take the optimal strategy to maximize their scores.

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

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

First, Alice will take the card with 3. Then, Bob will take the card with 1.
The difference of their scores will be 3 - 1 = 2.

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

# coding: utf-8
# Your code here!
N=int(input())
A=list(int(x) for x in input().split())

A.sort(reverse=True)

ans=0
for i in range(N):
  a=A[i]
  if i%2==0:
    ans += a
  else:
    ans -= a

print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc088/tasks/abc088_c:
We have a 3 \times 3 grid. A number c_{i, j} is written in the square (i, j), where (i, j) denotes the square at the i-th row from the top and the j-th column from the left.

According to Takahashi, there are six integers a_1, a_2, a_3, b_1, b_2, b_3 whose values are fixed, and the number written in the square (i, j) is equal to a_i + b_j.

Determine if he is correct.

-----Constraints-----
 - c_{i, j} \ (1 \leq i \leq 3, 1 \leq j \leq 3) is an integer between 0 and 100 (inclusive).

-----Input-----
Input is given from Standard Input in the following format:
c_{1,1} c_{1,2} c_{1,3}
c_{2,1} c_{2,2} c_{2,3}
c_{3,1} c_{3,2} c_{3,3}

-----Output-----
If Takahashi's statement is correct, print Yes; otherwise, print No.

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

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

Takahashi is correct, since there are possible sets of integers such as: a_1=0,a_2=1,a_3=0,b_1=1,b_2=0,b_3=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/abc088/tasks/abc088_d:
We have an H \times W grid whose squares are painted black or white. The square at the i-th row from the top and the j-th column from the left is denoted as (i, j).
Snuke would like to play the following game on this grid. At the beginning of the game, there is a character called Kenus at square (1, 1). The player repeatedly moves Kenus up, down, left or right by one square. The game is completed when Kenus reaches square (H, W) passing only white squares.
Before Snuke starts the game, he can change the color of some of the white squares to black. However, he cannot change the color of square (1, 1) and (H, W). Also, changes of color must all be carried out before the beginning of the game.
When the game is completed, Snuke's score will be the number of times he changed the color of a square before the beginning of the game. Find the maximum possible score that Snuke can achieve, or print -1 if the game cannot be completed, that is, Kenus can never reach square (H, W) regardless of how Snuke changes the color of the squares.
The color of the squares are given to you as characters s_{i, j}. If square (i, j) is initially painted by white, s_{i, j} is .; if square (i, j) is initially painted by black, s_{i, j} is #.

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

a, b = map(int, input().split())
G = []
white_num = 0
for i in range(a):
    s = list(input())
    white_num += s.count('.')
    G.append(s)
from collections import deque
def mazesearch(G, initial_h, initial_w, target_h, target_w):
    '''
    G is for example:
        G = [[1,0,1,1,1,1],
            [1,0,1,0,1,0],
            [1,0,1,0,1,1],
            [1,1,1,0,1,1]]
    '''
    steps = 0
    BLOCKED, ALLOWED   = '#', '.'
    UNVISITED, VISITED = 0, 1
    directions = [(0, -1), (0, 1), (-1, 0), (1, 0)]
    if G[initial_h][initial_w] == BLOCKED:
        return -1
    height, width = len(G), len(G[0])
    is_visited = [[UNVISITED for w in range(width)] for h in range(height)]
    is_visited[initial_h][initial_w] = VISITED
    queue = deque([(initial_h, initial_w, steps)])
    while queue:
        h, w, steps = queue.popleft()
        if h == target_h and w == target_w:
            return steps
        for dh, dw in directions:
            new_h = h + dh
            new_w = w + dw
            if not (0 <= new_h < height and 0 <= new_w < width):
                continue
            if G[new_h][new_w] == ALLOWED and is_visited[new_h][new_w] == UNVISITED:
                queue.append((new_h, new_w, steps + 1))
                is_visited[new_h][new_w] = VISITED
    return -1
steps = mazesearch(G, 0, 0, a-1, b-1)
if steps == -1:
    print(-1, flush=True)
else:
    print(white_num - steps - 1, flush=True)


I found an interesting problem on https://atcoder.jp/contests/abc089/tasks/abc089_a:
There are N students in a school.
We will divide these students into some groups, and in each group they will discuss some themes.
You think that groups consisting of two or less students cannot have an effective discussion, so you want to have as many groups consisting of three or more students as possible.
Divide the students so that the number of groups consisting of three or more students is maximized.

-----Constraints-----
 - 1 \leq N \leq 1000
 - All input values are integers.

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

-----Output-----
If you can form at most x groups consisting of three or more students, print x.

-----Sample Input-----
8

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

For example, you can form a group of three students and another of five students.

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


I found an interesting problem on https://atcoder.jp/contests/abc089/tasks/abc089_b:
In Japan, people make offerings called hina arare, colorful crackers, on March 3.
We have a bag that contains N hina arare. (From here, we call them arare.)
It is known that the bag either contains arare in three colors: pink, white and green, or contains arare in four colors: pink, white, green and yellow.
We have taken out the arare in the bag one by one, and the color of the i-th arare was S_i, where colors are represented as follows - pink: P, white: W, green: G, yellow: Y.
If the number of colors of the arare in the bag was three, print Three; if the number of colors was four, print Four.

-----Constraints-----
 - 1 \leq N \leq 100
 - S_i is P, W, G or Y.
 - There always exist i, j and k such that S_i=P, S_j=W and S_k=G.

-----Input-----
Input is given from Standard Input in the following format:
N
S_1 S_2 ... S_N

-----Output-----
If the number of colors of the arare in the bag was three, print Three; if the number of colors was four, print Four.

-----Sample Input-----
6
G W Y P Y W

-----Sample Output-----
Four

The bag contained arare in four colors, so you should print Four.

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

N = int(input())
C = list(map(str,input().split()))
if 'P'and 'W'and 'G'and 'Y'in C:
    print('Four')
else:
    print('Three')


I found an interesting problem on https://atcoder.jp/contests/abc089/tasks/abc089_c:
There are N people. The name of the i-th person is S_i.
We would like to choose three people so that the following conditions are met:
 - The name of every chosen person begins with M, A, R, C or H.
 - There are no multiple people whose names begin with the same letter.
How many such ways are there to choose three people, disregarding order?
Note that the answer may not fit into a 32-bit integer type.

-----Constraints-----
 - 1 \leq N \leq 10^5
 - S_i consists of uppercase English letters.
 - 1 \leq |S_i| \leq 10
 - S_i \neq S_j (i \neq j)

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

-----Output-----
If there are x ways to choose three people so that the given conditions are met, print x.

-----Sample Input-----
5
MASHIKE
RUMOI
OBIRA
HABORO
HOROKANAI

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

We can choose three people with the following names:
 - MASHIKE, RUMOI, HABORO
 - MASHIKE, RUMOI, HOROKANAI
Thus, we have two ways.

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

n = int(input())
s = []
cnt = [0]*5
l = ["M","A","R","C","H"]
ans = 0
for i in range(n):
  s.append(input())
for i in s:
  if i[0] in l:
    cnt[l.index(i[0])] += 1
for i in range(3):
  for j in range(i+1,4):
    for k in range(j+1,5):
      ans += cnt[i]*cnt[j]*cnt[k]
print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc089/tasks/abc089_d:
We have a grid with H rows and W columns. The square at the i-th row and the j-th column will be called Square (i,j).
The integers from 1 through H×W are written throughout the grid, and the integer written in Square (i,j) is A_{i,j}.
You, a magical girl, can teleport a piece placed on Square (i,j) to Square (x,y) by consuming |x-i|+|y-j| magic points.
You now have to take Q practical tests of your ability as a magical girl.
The i-th test will be conducted as follows:
 - Initially, a piece is placed on the square where the integer L_i is written.
 - Let x be the integer written in the square occupied by the piece. Repeatedly move the piece to the square where the integer x+D is written, as long as x is not R_i. The test ends when x=R_i.
 - Here, it is guaranteed that R_i-L_i is a multiple of D.
For each test, find the sum of magic points consumed during that test.

-----Constraints-----
 - 1 \leq H,W \leq 300
 - 1 \leq D \leq H×W
 - 1 \leq A_{i,j} \leq H×W
 - A_{i,j} \neq A_{x,y} ((i,j) \neq (x,y))
 - 1 \leq Q \leq 10^5
 - 1 \leq L_i \leq R_i \leq H×W
 - (R_i-L_i) is a multiple of D.

-----Input-----
Input is given from Standard Input in the following format:
H W D
A_{1,1} A_{1,2} ... A_{1,W}
:
A_{H,1} A_{H,2} ... A_{H,W}
Q
L_1 R_1
:
L_Q R_Q

-----Output-----
For each test, print the sum of magic points consumed during that test.
Output should be in the order the tests are conducted.

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

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

 - 4 is written in Square (1,2).
 - 6 is written in Square (3,3).
 - 8 is written in Square (3,1).
Thus, the sum of magic points consumed during the first test is (|3-1|+|3-2|)+(|3-3|+|1-3|)=5.

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

from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

h,w,d=nii()

a_dict={}
for i in range(h):
  a=lnii()
  for j in range(w):
    a_dict[a[j]]=(i,j)

b_dict={}
for i in range(1,h*w+1):
  if i-d<=0:
    b_dict[i]=0
  else:
    oy,ox=a_dict[i-d]
    ny,nx=a_dict[i]
    b_dict[i]=b_dict[i-d]+abs(ny-oy)+abs(nx-ox)

q=int(input())
for i in range(q):
  l,r=nii()
  ans=b_dict[r]-b_dict[l]
  print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc090/tasks/abc090_a:
We have a 3×3 square grid, where each square contains a lowercase English letters.
The letter in the square at the i-th row from the top and j-th column from the left is c_{ij}.
Print the string of length 3 that can be obtained by concatenating the letters in the squares on the diagonal connecting the top-left and bottom-right corner of the grid, from the top-left to bottom-right.

-----Constraints-----
 - Input consists of lowercase English letters.

-----Input-----
Input is given from Standard Input in the following format:
c_{11}c_{12}c_{13}
c_{21}c_{22}c_{23}
c_{31}c_{32}c_{33}

-----Output-----
Print the string of length 3 that can be obtained by concatenating the letters on the diagonal connecting the top-left and bottom-right corner of the grid, from the top-left to bottom-right.

-----Sample Input-----
ant
obe
rec

-----Sample Output-----
abc

The letters in the squares on the diagonal connecting the top-left and bottom-right corner of the grid are a, b and c from top-right to bottom-left. Concatenate these letters and print abc.

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


I found an interesting problem on https://atcoder.jp/contests/abc090/tasks/abc090_b:
Find the number of palindromic numbers among the integers between A and B (inclusive).
Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.

-----Constraints-----
 - 10000 \leq A \leq B \leq 99999
 - All input values are integers.

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

-----Output-----
Print the number of palindromic numbers among the integers between A and B (inclusive).

-----Sample Input-----
11009 11332

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

There are four integers that satisfy the conditions: 11011, 11111, 11211 and 11311.

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

a, b = map(int, input().split())
count = 0
for i in range(a,b+1):
    if list(map(int, list(str(i)))) == list(reversed(list(map(int, list(str(i)))))):
        count += 1
print(count)


I found an interesting problem on https://atcoder.jp/contests/abc090/tasks/arc091_b:
Takahashi had a pair of two positive integers not exceeding N, (a,b), which he has forgotten.
He remembers that the remainder of a divided by b was greater than or equal to K.
Find the number of possible pairs that he may have had.

-----Constraints-----
 - 1 \leq N \leq 10^5
 - 0 \leq K \leq N-1
 - All input values are integers.

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

-----Output-----
Print the number of possible pairs that he may have had.

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

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

There are seven possible pairs: (2,3),(5,3),(2,4),(3,4),(2,5),(3,5) and (4,5).

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

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

s = 0

if k == 0:
    print(n ** 2)
else:
    for i in range(k+1, n+1):
        if n % i < k:
            s += n // i * (i - k)
        else:
            s += n // i * (i - k) + n % i - (k-1)

    print(s)


I found an interesting problem on https://atcoder.jp/contests/abc091/tasks/abc091_a:
An elementary school student Takahashi has come to a variety store.
He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it?
Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.

-----Constraints-----
 - All input values are integers.
 - 1 \leq A, B \leq 500
 - 1 \leq C \leq 1000

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

-----Output-----
If Takahashi can buy the toy, print Yes; if he cannot, print No.

-----Sample Input-----
50 100 120

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

He has 50 + 100 = 150 yen, so he can buy the 120-yen toy.

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

def mapt(fn, *args):
    return tuple(map(fn, *args))

def Input():
    return mapt(int, input().split(" "))

def main():
    a, b, c = Input()
    if a + b >= c:
        print("Yes")
    else:
        print("No")

main()


I found an interesting problem on https://atcoder.jp/contests/abc091/tasks/abc091_b:
Takahashi has N blue cards and M red cards.
A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i.
Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen.
Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces atcoder, he will not earn money even if there are blue cards with atcoderr, atcode, btcoder, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.)
At most how much can he earn on balance?
Note that the same string may be written on multiple cards.

-----Constraints-----
 - N and M are integers.
 - 1 \leq N, M \leq 100
 - s_1, s_2, ..., s_N, t_1, t_2, ..., t_M are all strings of lengths between 1 and 10 (inclusive) consisting of lowercase English letters.

-----Input-----
Input is given from Standard Input in the following format:
N
s_1
s_2
:
s_N
M
t_1
t_2
:
t_M

-----Output-----
If Takahashi can earn at most X yen on balance, print X.

-----Sample Input-----
3
apple
orange
apple
1
grape

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

He can earn 2 yen by announcing apple.

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

N = int(input())
s = [input() for i in range(N)]
M = int(input())
t = [input() for i in range(M)]

st_dict = {}

for i in range(N):
    if s[i] not in st_dict.keys():
        st_dict[s[i]] = 1
    else:
        st_dict[s[i]] += 1
for i in range(M):
    if t[i] not in st_dict.keys():
        st_dict[t[i]] = -1
    else:
        st_dict[t[i]] -= 1

if max(st_dict.values()) < 0:
    print(0)
else:
    print(max(st_dict.values()))


I found an interesting problem on https://atcoder.jp/contests/abc091/tasks/arc092_a:
On a two-dimensional plane, there are N red points and N blue points.
The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).
A red point and a blue point can form a friendly pair when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.
At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.

-----Constraints-----
 - All input values are integers.
 - 1 \leq N \leq 100
 - 0 \leq a_i, b_i, c_i, d_i < 2N
 - a_1, a_2, ..., a_N, c_1, c_2, ..., c_N are all different.
 - b_1, b_2, ..., b_N, d_1, d_2, ..., d_N are all different.

-----Input-----
Input is given from Standard Input in the following format:
N
a_1 b_1
a_2 b_2
:
a_N b_N
c_1 d_1
c_2 d_2
:
c_N d_N

-----Output-----
Print the maximum number of friendly pairs.

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

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

For example, you can pair (2, 0) and (4, 2), then (3, 1) and (5, 5).

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

import networkx as nx

N = int(input())
ABs = [tuple(map(int, input().split())) for _ in range(N)]
CDs = [tuple(map(int, input().split())) for _ in range(N)]

# 0 <= i <   N  -> i: ABs[i]
# N <= i < 2*N  -> i: CDs[i-N]
# i == 2*N+1    -> start
# i == 2*N+2    -> goal

DG = nx.DiGraph()
DG.add_nodes_from(list(range(2 * N + 3)))
for i in range(N):
    for j in range(N):
        if ABs[i][0] < CDs[j][0] and ABs[i][1] < CDs[j][1]:
            DG.add_edge(i, j + N, capacity = 1)

DG.add_edges_from([(2 * N + 1, i, {"capacity":1}) for i in range(N)])
DG.add_edges_from([(i, 2 * N + 2, {"capacity":1}) for i in range(N, 2*N)])

print((nx.maximum_flow_value(DG, 2 * N + 1, 2 * N + 2)))


I found an interesting problem on https://atcoder.jp/contests/abc092/tasks/abc092_a:
You planned a trip using trains and buses.
The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket.
Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket.
Find the minimum total fare when the optimal choices are made for trains and buses.

-----Constraints-----
 - 1 \leq A \leq 1 000
 - 1 \leq B \leq 1 000
 - 1 \leq C \leq 1 000
 - 1 \leq D \leq 1 000
 - All input values are integers.

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

-----Output-----
Print the minimum total fare.

-----Sample Input-----
600
300
220
420

-----Sample Output-----
520

The train fare will be 600 yen if you buy ordinary tickets, and 300 yen if you buy an unlimited ticket.
Thus, the optimal choice for trains is to buy an unlimited ticket for 300 yen.
On the other hand, the optimal choice for buses is to buy ordinary tickets for 220 yen.
Therefore, the minimum total fare is 300 + 220 = 520 yen.

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

'''
問題：
    あなたは、電車とバスを乗り継いで旅行をする計画を立てました。
    電車は旅程に沿って通常のきっぷを買うと A円かかり、
    乗り放題きっぷを買うと B円かかります。
    バスは旅程に沿って通常のきっぷを買うと C円かかり、
    乗り放題きっぷを買うと D円かかります。

    電車およびバスについて
    通常の切符を買うか乗り放題きっぷを買うかをうまく選んだときの、
    運賃の合計の最小値を求めてください。
'''

'''
制約：
    1 ≤ A ≤ 1,000
    1 ≤ B ≤ 1,000
    1 ≤ C ≤ 1,000
    1 ≤ D ≤ 1,000
    入力値はすべて整数である。
'''

# 標準入力から A, B, C, D の値を取得する
a = int(input())
b = int(input())
c = int(input())
d = int(input())

# 乗り換えのパターンをリストに入れて、リストの最小値を出力する
travel_costs = [a + c, a + d, b + c, b + d]

print((min(travel_costs)))


I found an interesting problem on https://atcoder.jp/contests/abc092/tasks/abc092_b:
Some number of chocolate pieces were prepared for a training camp.
The camp had N participants and lasted for D days.
The i-th participant (1 \leq i \leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on.
As a result, there were X chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces.
Find the number of chocolate pieces prepared at the beginning of the camp.

-----Constraints-----
 - 1 \leq N \leq 100
 - 1 \leq D \leq 100
 - 1 \leq X \leq 100
 - 1 \leq A_i \leq 100 (1 \leq i \leq N)
 - All input values are integers.

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

-----Output-----
Find the number of chocolate pieces prepared at the beginning of the camp.

-----Sample Input-----
3
7 1
2
5
10

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

The camp has 3 participants and lasts for 7 days.
Each participant eats chocolate pieces as follows:
 - The first participant eats one chocolate piece on Day 1, 3, 5 and 7, for a total of four.
 - The second participant eats one chocolate piece on Day 1 and 6, for a total of two.
 - The third participant eats one chocolate piece only on Day 1, for a total of one.
Since the number of pieces remaining at the end of the camp is one, the number of pieces prepared at the beginning of the camp is 1 + 4 + 2 + 1 = 8.

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

#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    n = int(input())
    people=[]
    d,x = map(int,input().split())
    people=list([int(input()) for _ in range(n)])
    chocolates=[]
    choco=1

    for human in people:
        for day in range(1,d+1):
            if d >= human * day +1:
                choco+=1
        chocolates.append(choco)
        choco=1
    print(sum(chocolates)+x)

def __starting_point():
    main()
__starting_point()


I found an interesting problem on https://atcoder.jp/contests/abc092/tasks/arc093_a:
There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N.
Spot i is at the point with coordinate A_i.
It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.
You planned a trip along the axis.
In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.
However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i.
You will visit the remaining spots as planned in the order they are numbered.
You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.
For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

-----Constraints-----
 - 2 \leq N \leq 10^5
 - -5000 \leq A_i \leq 5000 (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_2 ... A_N

-----Output-----
Print N lines.
In the i-th line, print the total cost of travel during the trip when the visit to Spot i is canceled.

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

-----Sample Output-----
12
8
10

Spot 1, 2 and 3 are at the points with coordinates 3, 5 and -1, respectively.
For each i, the course of the trip and the total cost of travel when the visit to Spot i is canceled, are as follows:
 - For i = 1, the course of the trip is 0 \rightarrow 5 \rightarrow -1 \rightarrow 0 and the total cost of travel is 5 + 6 + 1 = 12 yen.
 - For i = 2, the course of the trip is 0 \rightarrow 3 \rightarrow -1 \rightarrow 0 and the total cost of travel is 3 + 4 + 1 = 8 yen.
 - For i = 3, the course of the trip is 0 \rightarrow 3 \rightarrow 5 \rightarrow 0 and the total cost of travel is 3 + 2 + 5 = 10 yen.

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

N = int(input())
A = [0]+[int(X) for X in input().split()]+[0]
Cost = sum(abs(A[T+1]-A[T]) for T in range(N+1))
for T in range(1,N+1):
    Cut = Cost+abs(A[T+1]-A[T-1])-abs(A[T]-A[T-1])-abs(A[T+1]-A[T])
    print(Cut)


I found an interesting problem on https://atcoder.jp/contests/abc093/tasks/abc093_a:
You are given a string S of length 3 consisting of a, b and c. Determine if S can be obtained by permuting abc.

-----Constraints-----
 - |S|=3
 - S consists of a, b and c.

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

-----Output-----
If S can be obtained by permuting abc, print Yes; otherwise, print No.

-----Sample Input-----
bac

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

Swapping the first and second characters in bac results in abc.

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

s=input()
if s.count('a')==1 and s.count('b')==1 and s.count('c')==1:
  print('Yes')
else:
  print('No')


I found an interesting problem on https://atcoder.jp/contests/abc093/tasks/abc093_b:
Print all the integers that satisfies the following in ascending order:
 - Among the integers between A and B (inclusive), it is either within the K smallest integers or within the K largest integers.

-----Constraints-----
 - 1 \leq A \leq B \leq 10^9
 - 1 \leq K \leq 100
 - All values in input are integers.

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

-----Output-----
Print all the integers that satisfies the condition above in ascending order.

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

-----Sample Output-----
3
4
7
8

 - 3 is the first smallest integer among the integers between 3 and 8.
 - 4 is the second smallest integer among the integers between 3 and 8.
 - 7 is the second largest integer among the integers between 3 and 8.
 - 8 is the first largest integer among the integers between 3 and 8.

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

a,b,c=input().split()
a=int(a)
b=int(b)
c=int(c)
if (a+c-1)<(b-c+1):
  for i in range(c):
    print(a+i)
  for i in range(c):
    print(b-c+1+i)
else:
  for i in range(a,b+1):
    print(i)


I found an interesting problem on https://atcoder.jp/contests/abc094/tasks/abc094_a:
There are a total of A + B cats and dogs.
Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs.
Determine if it is possible that there are exactly X cats among these A + B animals.

-----Constraints-----
 - 1 \leq A \leq 100
 - 1 \leq B \leq 100
 - 1 \leq X \leq 200
 - All values in input are integers.

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

-----Output-----
If it is possible that there are exactly X cats, print YES; if it is impossible, print NO.

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

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

If there are one cat and four dogs among the B = 5 animals, there are X = 4 cats in total.

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

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

if a <= x <= a + b:
    print('YES')
else:
    print('NO')


I found an interesting problem on https://atcoder.jp/contests/abc094/tasks/abc094_b:
There are N + 1 squares arranged in a row, numbered 0, 1, ..., N from left to right.
Initially, you are in Square X.
You can freely travel between adjacent squares. Your goal is to reach Square 0 or Square N.
However, for each i = 1, 2, ..., M, there is a toll gate in Square A_i, and traveling to Square A_i incurs a cost of 1.
It is guaranteed that there is no toll gate in Square 0, Square X and Square N.
Find the minimum cost incurred before reaching the goal.

-----Constraints-----
 - 1 \leq N \leq 100
 - 1 \leq M \leq 100
 - 1 \leq X \leq N - 1
 - 1 \leq A_1 < A_2 < ... < A_M \leq N
 - A_i \neq X
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N M X
A_1 A_2 ... A_M

-----Output-----
Print the minimum cost incurred before reaching the goal.

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

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

The optimal solution is as follows:
 - First, travel from Square 3 to Square 4. Here, there is a toll gate in Square 4, so the cost of 1 is incurred.
 - Then, travel from Square 4 to Square 5. This time, no cost is incurred.
 - Now, we are in Square 5 and we have reached the goal.
In this case, the total cost incurred is 1.

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

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

goto_0=0
goto_N=0

for i in range(0,X):
    if i in Ai:
        goto_0 += 1

for i in range(X,N):
    if i in Ai:
        goto_N += 1

print(min(goto_0,goto_N))


I found an interesting problem on https://atcoder.jp/contests/abc094/tasks/arc095_a:
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l.
You are given N numbers X_1, X_2, ..., X_N, where N is an even number.
For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i.
Find B_i for each i = 1, 2, ..., N.

-----Constraints-----
 - 2 \leq N \leq 200000
 - N is even.
 - 1 \leq X_i \leq 10^9
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N
X_1 X_2 ... X_N

-----Output-----
Print N lines.
The i-th line should contain B_i.

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

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

 - Since the median of X_2, X_3, X_4 is 4, B_1 = 4.
 - Since the median of X_1, X_3, X_4 is 3, B_2 = 3.
 - Since the median of X_1, X_2, X_4 is 3, B_3 = 3.
 - Since the median of X_1, X_2, X_3 is 4, B_4 = 4.

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

n = int(input())
x = list(map(int,input().split()))
y = sorted(x)
index = n//2

for i in range(n):
  print(y[-index] if x[i]<y[index] else y[-index-1])


I found an interesting problem on https://atcoder.jp/contests/abc094/tasks/arc095_b:
Let {\rm comb}(n,r) be the number of ways to choose r objects from among n objects, disregarding order.
From n non-negative integers a_1, a_2, ..., a_n, select two numbers a_i > a_j so that {\rm comb}(a_i,a_j) is maximized.
If there are multiple pairs that maximize the value, any of them is accepted.

-----Constraints-----
 - 2 \leq n \leq 10^5
 - 0 \leq a_i \leq 10^9
 - a_1,a_2,...,a_n are pairwise distinct.
 - All values in input are integers.

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

-----Output-----
Print a_i and a_j that you selected, with a space in between.

-----Sample Input-----
5
6 9 4 2 11

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

\rm{comb}(a_i,a_j) for each possible selection is as follows:
 - \rm{comb}(4,2)=6
 - \rm{comb}(6,2)=15
 - \rm{comb}(6,4)=15
 - \rm{comb}(9,2)=36
 - \rm{comb}(9,4)=126
 - \rm{comb}(9,6)=84
 - \rm{comb}(11,2)=55
 - \rm{comb}(11,4)=330
 - \rm{comb}(11,6)=462
 - \rm{comb}(11,9)=55
Thus, we should print 11 and 6.

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

import bisect
n=input()
a=sorted(map(int,input().split()))
m=a[-1]
q=bisect.bisect_right(a,m/2)
p=q-1
if abs(m/2-a[p])>abs(m/2-a[q]):print(m,a[q])
else:print(m,a[p])


I found an interesting problem on https://atcoder.jp/contests/abc095/tasks/abc095_a:
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions).
A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is o, it means the ramen should be topped with boiled egg; if that character is x, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen.
Write a program that, when S is given, prints the price of the corresponding bowl of ramen.

-----Constraints-----
 - S is a string of length 3.
 - Each character in S is o or x.

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

-----Output-----
Print the price of the bowl of ramen corresponding to S.

-----Sample Input-----
oxo

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

The price of a ramen topped with two kinds of toppings, boiled egg and green onions, is 700 + 100 \times 2 = 900 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/abc095/tasks/abc095_b:
Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to make one Doughnut i (1 ≤ i ≤ N), she needs to consume m_i grams of Moto. She cannot make a non-integer number of doughnuts, such as 0.5 doughnuts.
Now, she has X grams of Moto. She decides to make as many doughnuts as possible for a party tonight. However, since the tastes of the guests differ, she will obey the following condition:
 - For each of the N kinds of doughnuts, make at least one doughnut of that kind.
At most how many doughnuts can be made here? She does not necessarily need to consume all of her Moto. Also, under the constraints of this problem, it is always possible to obey the condition.

-----Constraints-----
 - 2 ≤ N ≤ 100
 - 1 ≤ m_i ≤ 1000
 - m_1 + m_2 + ... + m_N ≤ X ≤ 10^5
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N X
m_1
m_2
:
m_N

-----Output-----
Print the maximum number of doughnuts that can be made under the condition.

-----Sample Input-----
3 1000
120
100
140

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

She has 1000 grams of Moto and can make three kinds of doughnuts. If she makes one doughnut for each of the three kinds, she consumes 120 + 100 + 140 = 360 grams of Moto. From the 640 grams of Moto that remains here, she can make additional six Doughnuts 2. This is how she can made a total of nine doughnuts, which is the maximum.

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

n,x = map(int,input().split())
l=[]
for i in range(0,n):
  l.append(int(input()))
x-=sum(l)
cnt=x//min(l)
print(n+cnt)


I found an interesting problem on https://atcoder.jp/contests/abc095/tasks/arc096_a:
"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively.
Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.

-----Constraints-----
 - 1 ≤ A, B, C ≤ 5000
 - 1 ≤ X, Y ≤ 10^5
 - All values in input are integers.

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

-----Output-----
Print the minimum amount of money required to prepare X A-pizzas and Y B-pizzas.

-----Sample Input-----
1500 2000 1600 3 2

-----Sample Output-----
7900

It is optimal to buy four AB-pizzas and rearrange them into two A-pizzas and two B-pizzas, then buy additional one A-pizza.

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

A,B,C,X,Y = map(int,input().split())
moneys = []

for i in range(0,2*max(X,Y)+1,2):
  if X-i//2 >= 0 and Y-i//2 >= 0:
    moneys.append((X-i//2)*A + (Y-i//2)*B + C*i)
  elif X-i//2 >= 0 and Y-i//2 < 0:
    moneys.append((X-i//2)*A + C*i)
  elif X-i//2 < 0 and Y-i//2 >= 0:
    moneys.append((Y-i//2)*B + C*i)
  else:
    moneys.append(C*i)

print(min(moneys))


I found an interesting problem on https://atcoder.jp/contests/abc095/tasks/arc096_b:
"Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter.
Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on) on the counter. The distance measured clockwise from the point where Nakahashi is standing to the point where the i-th sushi is placed, is x_i meters. Also, the i-th sushi has a nutritive value of v_i kilocalories.
Nakahashi can freely walk around the circumference of the counter. When he reach a point where a sushi is placed, he can eat that sushi and take in its nutrition (naturally, the sushi disappears). However, while walking, he consumes 1 kilocalories per meter.
Whenever he is satisfied, he can leave the restaurant from any place (he does not have to return to the initial place). On balance, at most how much nutrition can he take in before he leaves? That is, what is the maximum possible value of the total nutrition taken in minus the total energy consumed? Assume that there are no other customers, and no new sushi will be added to the counter. Also, since Nakahashi has plenty of nutrition in his body, assume that no matter how much he walks and consumes energy, he never dies from hunger.

-----Constraints-----
 - 1 ≤ N ≤ 10^5
 - 2 ≤ C ≤ 10^{14}
 - 1 ≤ x_1 < x_2 < ... < x_N < C
 - 1 ≤ v_i ≤ 10^9
 - All values in input are integers.

-----Subscores-----
 - 300 points will be awarded for passing the test set satisfying N ≤ 100.

-----Input-----
Input is given from Standard Input in the following format:
N C
x_1 v_1
x_2 v_2
:
x_N v_N

-----Output-----
If Nakahashi can take in at most c kilocalories on balance before he leaves the restaurant, print c.

-----Sample Input-----
3 20
2 80
9 120
16 1

-----Sample Output-----
191

There are three sushi on the counter with a circumference of 20 meters. If he walks two meters clockwise from the initial place, he can eat a sushi of 80 kilocalories....

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

def main():
    N, C = list(map(int, input().split()))
    XV = [tuple(map(int, input().split())) for _ in range(N)]
    return max(solve(N, C, XV), solve(N, C, [(C - x, v) for x, v in reversed(XV)]))

def solve(N, C, XV):
    lv = [0] * N
    rv = [0] * N
    x0, c, m = 0, 0, 0
    for i, (x, v) in enumerate(XV):
        c += v - (x - x0)
        m = max(m, c)
        lv[i] = m
        x0 = x
    rv = [0] * N
    x0, c, m = C, 0, 0
    for i, (x, v) in enumerate(reversed(XV)):
        c += v - 2 * (x0 - x)
        m = max(m, c)
        rv[i] = m
        x0 = x
    for i in range(N - 1):
        lv[i] += rv[N - i - 2]
    return max(lv)

print((main()))


I found an interesting problem on https://atcoder.jp/contests/abc096/tasks/abc096_a:
In AtCoder Kingdom, Gregorian calendar is used, and dates are written in the "year-month-day" order, or the "month-day" order without the year.

For example, May 3, 2018 is written as 2018-5-3, or 5-3 without the year.
In this country, a date is called Takahashi when the month and the day are equal as numbers. For example, 5-5 is Takahashi.

How many days from 2018-1-1 through 2018-a-b are Takahashi?

-----Constraints-----
 - a is an integer between 1 and 12 (inclusive).
 - b is an integer between 1 and 31 (inclusive).
 - 2018-a-b is a valid date in Gregorian calendar.

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

-----Output-----
Print the number of days from 2018-1-1 through 2018-a-b that are Takahashi.

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

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

There are five days that are Takahashi: 1-1, 2-2, 3-3, 4-4 and 5-5.

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

a,b = map(int, input().split())
print(a) if b >= a else print(a-1)


I found an interesting problem on https://atcoder.jp/contests/abc096/tasks/abc096_b:
There are three positive integers A, B and C written on a blackboard. E869120 performs the following operation K times:
 - Choose one integer written on the blackboard and let the chosen integer be n. Replace the chosen integer with 2n.
What is the largest possible sum of the integers written on the blackboard after K operations?

-----Constraints-----
 - A, B and C are integers between 1 and 50 (inclusive).
 - K is an integer between 1 and 10 (inclusive).

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

-----Output-----
Print the largest possible sum of the integers written on the blackboard after K operations by E869220.

-----Sample Input-----
5 3 11
1

-----Sample Output-----
30

In this sample, 5, 3, 11 are initially written on the blackboard, and E869120 can perform the operation once.

There are three choices:
 - Double 5: The integers written on the board after the operation are 10, 3, 11.
 - Double 3: The integers written on the board after the operation are 5, 6, 11.
 - Double 11: The integers written on the board after the operation are 5, 3, 22.
If he chooses 3., the sum of the integers written on the board afterwards is 5 + 3 + 22 = 30, which is the largest among 1. through 3.

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

A, B, C = sorted([int(i) for i in input().split()])
K = int(input())
print((A + B + (C * (2**K))))


I found an interesting problem on https://atcoder.jp/contests/abc096/tasks/abc096_c:
We have a canvas divided into a grid with H rows and W columns. The square at the i-th row from the top and the j-th column from the left is represented as (i, j).

Initially, all the squares are white. square1001 wants to draw a picture with black paint. His specific objective is to make Square (i, j) black when s_{i, j}= #, and to make Square (i, j) white when s_{i, j}= ..

However, since he is not a good painter, he can only choose two squares that are horizontally or vertically adjacent and paint those squares black, for some number of times (possibly zero). He may choose squares that are already painted black, in which case the color of those squares remain black.

Determine if square1001 can achieve his objective.

-----Constraints-----
 - H is an integer between 1 and 50 (inclusive).
 - W is an integer between 1 and 50 (inclusive).
 - For every (i, j) (1 \leq i \leq H, 1 \leq j \leq W), s_{i, j} is # or ..

-----Input-----
Input is given from Standard Input in the following format:
H W
s_{1, 1} s_{1, 2} s_{1, 3} ... s_{1, W}
s_{2, 1} s_{2, 2} s_{2, 3} ... s_{2, W}
  :   :
s_{H, 1} s_{H, 2} s_{H, 3} ... s_{H, W}

-----Output-----
If square1001 can achieve his objective, print Yes; if he cannot, print No.

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

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

One possible way to achieve the objective is shown in the figure below. Here, the squares being painted are marked by stars.

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

h,w=map(int,input().split())
a=[input()+'.' for i in range(h)]+['.'*w]
for i in range(h):
    for j in range(w):
        if a[i][j]=="#":
            if any([a[i+1][j]==a[i][j+1]==a[i-1][j]==a[i][j-1]=="."]):
                print('No')
                break
    else:
        continue
    break
else:
    print('Yes')


I found an interesting problem on https://atcoder.jp/contests/abc097/tasks/abc097_a:
Three people, A, B and C, are trying to communicate using transceivers.
They are standing along a number line, and the coordinates of A, B and C are a, b and c (in meters), respectively.
Two people can directly communicate when the distance between them is at most d meters.
Determine if A and C can communicate, either directly or indirectly.
Here, A and C can indirectly communicate when A and B can directly communicate and also B and C can directly communicate.

-----Constraints-----
 - 1 ≤ a,b,c ≤ 100
 - 1 ≤ d ≤ 100
 - All values in input are integers.

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

-----Output-----
If A and C can communicate, print Yes; if they cannot, print No.

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

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

A and B can directly communicate, and also B and C can directly communicate, so we should print Yes.

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

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

if abs(a -c) <= d:
    print("Yes")
elif abs(a - b) <= d and abs(b - c) <= d:
    print("Yes")
else:
    print("No")


I found an interesting problem on https://atcoder.jp/contests/abc097/tasks/abc097_b:
You are given a positive integer X.
Find the largest perfect power that is at most X.
Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.

-----Constraints-----
 - 1 ≤ X ≤ 1000
 - X is an integer.

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

-----Output-----
Print the largest perfect power that is at most X.

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

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

There are four perfect powers that are at most 10: 1, 4, 8 and 9.
We should print the largest among them, 9.

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

x = int(input())

ans = 1
for i in range(2, x):
    if i * i > x:
        break

    now = i
    while now * i <= x:
        now *= i
    if now > ans:
        ans = now

print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc097/tasks/arc097_a:
You are given a string s.
Among the different substrings of s, print the K-th lexicographically smallest one.
A substring of s is a string obtained by taking out a non-empty contiguous part in s.
For example, if s = ababc, a, bab and ababc are substrings of s, while ac, z and an empty string are not.
Also, we say that substrings are different when they are different as strings.
Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.

-----Constraints-----
 - 1 ≤ |s| ≤ 5000
 - s consists of lowercase English letters.
 - 1 ≤ K ≤ 5
 - s has at least K different substrings.

-----Partial Score-----
 - 200 points will be awarded as a partial score for passing the test set satisfying |s| ≤ 50.

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

-----Output-----
Print the K-th lexicographically smallest substring of K.

-----Sample Input-----
aba
4

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

s has five substrings: a, b, ab, ba and aba.
Among them, we should print the fourth smallest one, b.
Note that we do not count a twice.

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


I found an interesting problem on https://atcoder.jp/contests/abc098/tasks/abc098_a:
You are given two integers A and B.
Find the largest value among A+B, A-B and A \times B.

-----Constraints-----
 - -1000 \leq A,B \leq 1000
 - All values in input are integers.

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

-----Output-----
Print the largest value among A+B, A-B and A \times B.

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

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

3+1=4, 3-1=2 and 3 \times 1=3. The largest among them is 4.

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

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

print(max(A+B, A-B,A*B))


I found an interesting problem on https://atcoder.jp/contests/abc098/tasks/abc098_b:
You are given a string S of length N consisting of lowercase English letters.
We will cut this string at one position into two strings X and Y.
Here, we would like to maximize the number of different letters contained in both X and Y.
Find the largest possible number of different letters contained in both X and Y when we cut the string at the optimal position.

-----Constraints-----
 - 2 \leq N \leq 100
 - |S| = N
 - S consists of lowercase English letters.

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

-----Output-----
Print the largest possible number of different letters contained in both X and Y.

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

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

If we cut the string between the third and fourth letters into X = aab and Y = bca, the letters contained in both X and Y are a and b.
There will never be three or more different letters contained in both X and Y, so the answer is 2.

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

N=int(input())
S=input()

ans = 0
for i in range(N):
	s1,s2=set(S[:i]),set(S[i:])
	tmp = len(s1.intersection(s2))
	if tmp > ans:ans=tmp

print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc098/tasks/arc098_a:
There are N people standing in a row from west to east.
Each person is facing east or west.
The directions of the people is given as a string S of length N.
The i-th person from the west is facing east if S_i = E, and west if S_i = W.
You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader.
Here, we do not care which direction the leader is facing.
The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized.
Find the minimum number of people who have to change their directions.

-----Constraints-----
 - 2 \leq N \leq 3 \times 10^5
 - |S| = N
 - S_i is E or W.

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

-----Output-----
Print the minimum number of people who have to change their directions.

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

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

Assume that we appoint the third person from the west as the leader.
Then, the first person from the west needs to face east and has to turn around.
The other people do not need to change their directions, so the number of people who have to change their directions is 1 in this case.
It is not possible to have 0 people who have to change their directions, so the answer is 1.

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

def main():
    N = int(input())
    S = input()
    lst = [0] * N
    ans = N

    if S[0] == "E":
        lst[0] = 1
    for i in range(1, N):
        if S[i] == "E":
            lst[i] = lst[i - 1] + 1
        else:
            lst[i] = lst[i - 1]

    for i in range(N):
        if i == 0:
            left = 0
        else:
            left = i - lst[i - 1]
        right = lst[N - 1] - lst[i]

        if left + right < ans:
            ans = left + right

    print(ans)

def __starting_point():
    main()

__starting_point()


I found an interesting problem on https://atcoder.jp/contests/abc098/tasks/arc098_b:
There is an integer sequence A of length N.
Find the number of the pairs of integers l and r (1 \leq l \leq r \leq N) that satisfy the following condition:
 - A_l\ xor\ A_{l+1}\ xor\ ...\ xor\ A_r = A_l\ +\ A_{l+1}\ +\ ...\ +\ A_r
Here, xor denotes the bitwise exclusive OR.
Definition of XOR
The XOR of integers c_1, c_2, ..., c_m is defined as follows:
 - Let the XOR be X. In the binary representation of X, the digit in the 2^k's place (0 \leq k; k is an integer) is 1 if there are an odd number of integers among c_1, c_2, ...c_m whose binary representation has 1 in the 2^k's place, and 0 if that number is even.
For example, let us compute the XOR of 3 and 5. The binary representation of 3 is 011, and the binary representation of 5 is 101, thus the XOR has the binary representation 110, that is, the XOR is 6.

-----Constraints-----
 - 1 \leq N \leq 2 \times 10^5
 - 0 \leq A_i < 2^{20}
 - All values in input are integers.

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

-----Output-----
Print the number of the pairs of integers l and r (1 \leq l \leq r \leq N) that satisfy the condition.

-----Sample Input-----
4
2 5 4 6

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

(l,r)=(1,1),(2,2),(3,3),(4,4) clearly satisfy the condition.
(l,r)=(1,2) also satisfies the condition, since A_1\ xor\ A_2 = A_1\ +\ A_2 = 7.
There are no other pairs that satisfy the condition, so the answer is 5.

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

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

xo = A[0]
l = 0
r = 1
ans = 0

while l < N:
    if r == N:
        ans += r - l
        l += 1
        continue
    if xo ^ A[r] == xo + A[r]:
        xo += A[r]
        r += 1
    else:
        ans += r - l
        xo ^= A[l]
        l += 1
print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc099/tasks/abc099_a:
Decades have passed since the beginning of AtCoder Beginner Contest.
The contests are labeled as ABC001, ABC002, ... from the first round, but after the 999-th round ABC999, a problem occurred: how the future rounds should be labeled?
In the end, the labels for the rounds from the 1000-th to the 1998-th are decided: ABD001, ABD002, ..., ABD999.
You are given an integer N between 1 and 1998 (inclusive). Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.

-----Constraints-----
 - 1 \leq N \leq 1998
 - N is an integer.

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

-----Output-----
Print the first three characters of the label of the N-th round of AtCoder Beginner Contest.

-----Sample Input-----
999

-----Sample Output-----
ABC

The 999-th round of AtCoder Beginner Contest is labeled as ABC999.

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

N = int(input())
if N >= 1000:
    print("ABD")
else:
    print("ABC")


I found an interesting problem on https://atcoder.jp/contests/abc099/tasks/abc099_b:
In some village, there are 999 towers that are 1,(1+2),(1+2+3),...,(1+2+3+...+999) meters high from west to east, at intervals of 1 meter.
It had been snowing for a while before it finally stopped. For some two adjacent towers located 1 meter apart, we measured the lengths of the parts of those towers that are not covered with snow, and the results are a meters for the west tower, and b meters for the east tower.
Assuming that the depth of snow cover and the altitude are the same everywhere in the village, find the amount of the snow cover.
Assume also that the depth of the snow cover is always at least 1 meter.

-----Constraints-----
 - 1 \leq a < b < 499500(=1+2+3+...+999)
 - All values in input are integers.
 - There is no input that contradicts the assumption.

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

-----Output-----
If the depth of the snow cover is x meters, print x as an integer.

-----Sample Input-----
8 13

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

The heights of the two towers are 10 meters and 15 meters, respectively.
Thus, we can see that the depth of the snow cover is 2 meters.

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