I found an interesting problem on https://atcoder.jp/contests/abc099/tasks/abc099_c:
To make it difficult to withdraw money, a certain bank allows its customers to withdraw only one of the following amounts in one operation:
 - 1 yen (the currency of Japan)
 - 6 yen, 6^2(=36) yen, 6^3(=216) yen, ...
 - 9 yen, 9^2(=81) yen, 9^3(=729) yen, ...
At least how many operations are required to withdraw exactly N yen in total?
It is not allowed to re-deposit the money you withdrew.

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

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

-----Output-----
If at least x operations are required to withdraw exactly N yen in total, print x.

-----Sample Input-----
127

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

By withdrawing 1 yen, 9 yen, 36(=6^2) yen and 81(=9^2) yen, we can withdraw 127 yen in four operations.

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

import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()

def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]

def get_num_draw(n, x):
    res = 0
    while n > 0:
        res += n % x
        n = n // x
    return res

def main():
    N = NI()
    ans = 10**10
    for i in range(0, N+1, 6):
        ans = min(get_num_draw(N-i, 9) + get_num_draw(i//6, 6), ans)
    print(ans)

def __starting_point():
    main()
__starting_point()


I found an interesting problem on https://atcoder.jp/contests/abc099/tasks/abc099_d:
There is a grid with N rows and N columns of squares. Let (i,j) be the square at the i-th row from the top and the j-th column from the left.
These squares have to be painted in one of the C colors from Color 1 to Color C. Initially, (i,j) is painted in Color c_{i,j}.
We say the grid is a good grid when the following condition is met for all i,j,x,y satisfying 1 \leq i,j,x,y \leq N:
 - If (i+j) \% 3=(x+y) \% 3, the color of (i,j) and the color of (x,y) are the same.
 - If (i+j) \%  3 \neq (x+y) \% 3, the color of (i,j) and the color of (x,y) are different.
Here, X \% Y represents X modulo Y.
We will repaint zero or more squares so that the grid will be a good grid.
For a square, the wrongness when the color of the square is X before repainting and Y after repainting, is D_{X,Y}.
Find the minimum possible sum of the wrongness of all the squares.

-----Constraints-----
 - 1 \leq N \leq 500
 - 3 \leq C \leq 30
 - 1 \leq D_{i,j} \leq 1000 (i \neq j),D_{i,j}=0 (i=j)
 - 1 \leq c_{i,j} \leq C
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N C
D_{1,1} ... D_{1,C}
:
D_{C,1} ... D_{C,C}
c_{1,1} ... c_{1,N}
:
c_{N,1} ... c_{N,N}

-----Output-----
If the minimum possible sum of the wrongness of all the squares is x, print x.

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

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

 - Repaint (1,1) to Color 2. The wrongness of (1,1) becomes D_{1,2}=1.
 - Repaint (1,2) to Color 3. The wrongness of (1,2) becomes D_{2,3}=1.
 - Repaint (2,2) to Color 1. The wrongness of (2,2) becomes D_{3,1}=1.
In this case, the sum of the wrongness of all the squares is 3.
Note that D_{i,j} \neq D_{j,i} is possible.

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

from collections import Counter
from itertools import permutations

N, C = list(map(int, input().split()))
D = [list(map(int, input().split())) for i in range(C)]
c = [list([int(s) - 1 for s in input().split()]) for i in range(N)]

d = [Counter(sum([c[j][(i - j) % 3::3] for j in range(N)], []))
     for i in range(3)]
ans = 1000000007
for t in permutations(list(range(C)), 3):
    dis = 0
    for i in range(3):
        for k, v in list(d[i].items()):
            dis += D[k][t[i]] * v
    ans = min(dis, ans)
print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc100/tasks/abc100_a:
E869120's and square1001's 16-th birthday is coming soon.

Takahashi from AtCoder Kingdom gave them a round cake cut into 16 equal fan-shaped pieces.
E869120 and square1001 were just about to eat A and B of those pieces, respectively,

when they found a note attached to the cake saying that "the same person should not take two adjacent pieces of cake".
Can both of them obey the instruction in the note and take desired numbers of pieces of cake?

-----Constraints-----
 - A and B are integers between 1 and 16 (inclusive).
 - A+B is at most 16.

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

-----Output-----
If both E869120 and square1001 can obey the instruction in the note and take desired numbers of pieces of cake, print Yay!; otherwise, print :(.

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

-----Sample Output-----
Yay!

Both of them can take desired number of pieces as follows:

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

A,B=map(int,input().split())
if A<=8 and B<=8:
  print("Yay!")
else:
  print(":(")


I found an interesting problem on https://atcoder.jp/contests/abc100/tasks/abc100_b:
Today, the memorable AtCoder Beginner Contest 100 takes place. On this occasion, Takahashi would like to give an integer to Ringo.

As the name of the contest is AtCoder Beginner Contest 100, Ringo would be happy if he is given a positive integer that can be divided by 100 exactly D times.
Find the N-th smallest integer that would make Ringo happy.

-----Constraints-----
 - D is 0, 1 or 2.
 - N is an integer between 1 and 100 (inclusive).

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

-----Output-----
Print the N-th smallest integer that can be divided by 100 exactly D times.

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

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

The integers that can be divided by 100 exactly 0 times (that is, not divisible by 100) are as follows: 1, 2, 3, 4, 5, 6, 7, ...

Thus, the 5-th smallest integer that would make Ringo happy is 5.

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

D,N=list(map(int,input().split()))
if N==100:
    print((101*100**D))
else:
    print((N*100**D))


I found an interesting problem on https://atcoder.jp/contests/abc100/tasks/abc100_c:
As AtCoder Beginner Contest 100 is taking place, the office of AtCoder, Inc. is decorated with a sequence of length N, a = {a_1, a_2, a_3, ..., a_N}.

Snuke, an employee, would like to play with this sequence.
Specifically, he would like to repeat the following operation as many times as possible:
For every i satisfying 1 \leq i \leq N, perform one of the following: "divide a_i by 2" and "multiply a_i by 3".
Here, choosing "multiply a_i by 3" for every i is not allowed, and the value of a_i after the operation must be an integer.

At most how many operations can be performed?

-----Constraints-----
 - N is an integer between 1 and 10 \ 000 (inclusive).
 - a_i is an integer between 1 and 1 \ 000 \ 000 \ 000 (inclusive).

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

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

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

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

The sequence is initially {5, 2, 4}. Three operations can be performed as follows:
 - First, multiply a_1 by 3, multiply a_2 by 3 and divide a_3 by 2. The sequence is now {15, 6, 2}.
 - Next, multiply a_1 by 3, divide a_2 by 2 and multiply a_3 by 3. The sequence is now {45, 3, 6}.
 - Finally, multiply a_1 by 3, multiply a_2 by 3 and divide a_3 by 2. The sequence is now {135, 9, 3}.

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

input()
print((sum([len(bin(int(a)&-int(a)))-3 for a in input().split()])))


I found an interesting problem on https://atcoder.jp/contests/abc100/tasks/abc100_d:
Takahashi became a pastry chef and opened a shop La Confiserie d'ABC to celebrate AtCoder Beginner Contest 100.
The shop sells N kinds of cakes.

Each kind of cake has three parameters "beauty", "tastiness" and "popularity". The i-th kind of cake has the beauty of x_i, the tastiness of y_i and the popularity of z_i.

These values may be zero or negative.
Ringo has decided to have M pieces of cakes here. He will choose the set of cakes as follows:
 - Do not have two or more pieces of the same kind of cake.
 - Under the condition above, choose the set of cakes to maximize (the absolute value of the total beauty) + (the absolute value of the total tastiness)  + (the absolute value of the total popularity).
Find the maximum possible value of (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) for the set of cakes that Ringo chooses.

-----Constraints-----
 - N is an integer between 1 and 1 \ 000 (inclusive).
 - M is an integer between 0 and N (inclusive).
 - x_i, y_i, z_i \ (1 \leq i \leq N) are integers between -10 \ 000 \ 000 \ 000 and 10 \ 000 \ 000 \ 000 (inclusive).

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

-----Output-----
Print the maximum possible value of (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) for the set of cakes that Ringo chooses.

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

-----Sample Output-----
56

Consider having the 2-nd, 4-th and 5-th kinds of cakes. The total beauty, tastiness and popularity will be as follows:
 - Beauty: 1 + 3 + 9 = 13
 - Tastiness: 5 + 5 + 7 = 17
 - Popularity: 9 + 8 + 9 = 26
The value (the absolute value of the total beauty) + (the absolute value of the total tastiness) + (the absolute value of the total popularity) here is 13 + 17 + 26 = 56. This is the maximum value.

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

import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))

N, M = mi()
xyz = li2(N)

sign = [[1, 1, 1], [1, 1, -1], [1, -1, 1], [1, -1, -1], [-1, 1, 1], [-1, 1, -1], [-1, -1, 1], [-1, -1, -1]]
ans = 0

for i in range(8):
    A = [sum(xyz[x][k] * sign[i][k] for k in range(3)) for x in range(N)]

    A = sorted(A, reverse=True)

    ans = max(ans, sum(A[:M]))

print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc101/tasks/abc101_a:
There is always an integer in Takahashi's mind.
Initially, the integer in Takahashi's mind is 0. Takahashi is now going to eat four symbols, each of which is + or -. When he eats +, the integer in his mind increases by 1; when he eats -, the integer in his mind decreases by 1.
The symbols Takahashi is going to eat are given to you as a string S. The i-th character in S is the i-th symbol for him to eat.
Find the integer in Takahashi's mind after he eats all the symbols.

-----Constraints-----
 - The length of S is 4.
 - Each character in S is + or -.

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

-----Output-----
Print the integer in Takahashi's mind after he eats all the symbols.

-----Sample Input-----
+-++

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

 - Initially, the integer in Takahashi's mind is 0.
 - The first integer for him to eat is +. After eating it, the integer in his mind becomes 1.
 - The second integer to eat is -. After eating it, the integer in his mind becomes 0.
 - The third integer to eat is +. After eating it, the integer in his mind becomes 1.
 - The fourth integer to eat is +. After eating it, the integer in his mind becomes 2.
Thus, the integer in Takahashi's mind after he eats all the symbols is 2.

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

import sys
input = sys.stdin.readline

s = input()
ans = 0
for i in range(4):
    if s[i] == '+':
        ans += 1
    else:
        ans -= 1
print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc101/tasks/abc101_b:
Let S(n) denote the sum of the digits in the decimal notation of n.
For example, S(101) = 1 + 0 + 1 = 2.
Given an integer N, determine if S(N) divides N.

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

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

-----Output-----
If S(N) divides N, print Yes; if it does not, print No.

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

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

In this input, N=12.
As S(12) = 1 + 2 = 3, S(N) divides N.

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

def S(n):
    c = 0
    for i in range(len(n)):
        c += int(n[i])
    return c

N = input()
if int(N) % S(N) == 0:
    print('Yes')
else:
    print('No')


I found an interesting problem on https://atcoder.jp/contests/abc101/tasks/arc099_b:
Let S(n) denote the sum of the digits in the decimal notation of n.
For example, S(123) = 1 + 2 + 3 = 6.
We will call an integer n a Snuke number when, for all positive integers m such that m > n, \frac{n}{S(n)} \leq \frac{m}{S(m)} holds.
Given an integer K, list the K smallest Snuke numbers.

-----Constraints-----
 - 1 \leq K
 - The K-th smallest Snuke number is not greater than 10^{15}.

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

-----Output-----
Print K lines. The i-th line should contain the i-th smallest Snuke number.

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

-----Sample Output-----
1
2
3
4
5
6
7
8
9
19

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

t = i = 1
k = int(input())
while k:
  if t < i / sum(map(int, list(str(i)))):
    i += 9 * t
    t *= 10
  else:
    print(i)
    i += t
    k -= 1


I found an interesting problem on https://atcoder.jp/contests/abc102/tasks/abc102_a:
You are given a positive integer N.
Find the minimum positive integer divisible by both 2 and N.

-----Constraints-----
 - 1 \leq N \leq 10^9
 - All values in input are integers.

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

-----Output-----
Print the minimum positive integer divisible by both 2 and N.

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

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

6 is divisible by both 2 and 3.
Also, there is no positive integer less than 6 that is divisible by both 2 and 3.
Thus, the answer is 6.

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

import math
a = int(input())
print(a*2//math.gcd(a, 2))


I found an interesting problem on https://atcoder.jp/contests/abc102/tasks/abc102_b:
You are given an integer sequence A of length N.
Find the maximum absolute difference of two elements (with different indices) in A.

-----Constraints-----
 - 2 \leq N \leq 100
 - 1 \leq A_i \leq 10^9
 - 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 maximum absolute difference of two elements (with different indices) in A.

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

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

The maximum absolute difference of two elements is A_3-A_1=6-1=5.

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

int(input())
A = list(map(int, input().split()))
print(max(A) - min(A))


I found an interesting problem on https://atcoder.jp/contests/abc102/tasks/arc100_b:
Snuke has an integer sequence A of length N.
He will make three cuts in A and divide it into four (non-empty) contiguous subsequences B, C, D and E.
The positions of the cuts can be freely chosen.
Let P,Q,R,S be the sums of the elements in B,C,D,E, respectively.
Snuke is happier when the absolute difference of the maximum and the minimum among P,Q,R,S is smaller.
Find the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.

-----Constraints-----
 - 4 \leq N \leq 2 \times 10^5
 - 1 \leq A_i \leq 10^9
 - 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-----
Find the minimum possible absolute difference of the maximum and the minimum among P,Q,R,S.

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

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

If we divide A as B,C,D,E=(3),(2),(4),(1,2), then P=3,Q=2,R=4,S=1+2=3.
Here, the maximum and the minimum among P,Q,R,S are 4 and 2, with the absolute difference of 2.
We cannot make the absolute difference of the maximum and the minimum less than 2, so the answer is 2.

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

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

from itertools import accumulate
CA = list(accumulate(A))

mindiff = CA[-1]
left = 0
right = 2
for c in range(1,N-1):
    # left side
    p = CA[left]
    q = CA[c] - CA[left]
    while True:
        pi = CA[left+1]
        qi = CA[c] - CA[left+1]
        if abs(pi- qi) >= abs(p - q):
            break
        p = pi; q = qi
        left += 1

    # right side
    r = CA[right] - CA[c]
    s = CA[-1] - CA[right]
    while True:
        ri = CA[right+1] - CA[c]
        si = CA[-1] - CA[right+1]
        if abs(ri- si) >= abs(r - s):
            break
        r = ri; s = si
        right += 1

    mindiff = min(mindiff, max(p, q, r, s) - min(p, q, r, s))
print(mindiff)


I found an interesting problem on https://atcoder.jp/contests/abc103/tasks/abc103_a:
You have three tasks, all of which need to be completed.
First, you can complete any one task at cost 0.
Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.
Here, |x| denotes the absolute value of x.
Find the minimum total cost required to complete all the task.

-----Constraints-----
 - All values in input are integers.
 - 1 \leq A_1, A_2, A_3 \leq 100

-----Input-----
Input is given from Standard Input in the following format:
A_1 A_2 A_3

-----Output-----
Print the minimum total cost required to complete all the task.

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

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

When the tasks are completed in the following order, the total cost will be 5, which is the minimum:
 - Complete the first task at cost 0.
 - Complete the third task at cost 2.
 - Complete the second task at cost 3.

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

a = list(map(int,input().split()))
print(max(a)-min(a))


I found an interesting problem on https://atcoder.jp/contests/abc103/tasks/abc103_b:
You are given string S and T consisting of lowercase English letters.
Determine if S equals T after rotation.
That is, determine if S equals T after the following operation is performed some number of times:
Operation: Let S = S_1 S_2 ... S_{|S|}. Change S to S_{|S|} S_1 S_2 ... S_{|S|-1}.
Here, |X| denotes the length of the string X.

-----Constraints-----
 - 2 \leq |S| \leq 100
 - |S| = |T|
 - S and T consist of lowercase English letters.

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

-----Output-----
If S equals T after rotation, print Yes; if it does not, print No.

-----Sample Input-----
kyoto
tokyo

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

 - In the first operation, kyoto becomes okyot.
 - In the second operation, okyot becomes tokyo.

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

s = list(input())
t = list(input())
ans = 'No'

for _ in s:
    tmp = s.pop()
    s.insert(0, tmp)
    ''.join(s)
    if s == t:
        ans = 'Yes'
        break

print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc103/tasks/abc103_c:
You are given N positive integers a_1, a_2, ..., a_N.
For a non-negative integer m, let f(m) = (m\ mod\ a_1) + (m\ mod\ a_2) + ... + (m\ mod\ a_N).
Here, X\ mod\ Y denotes the remainder of the division of X by Y.
Find the maximum value of f.

-----Constraints-----
 - All values in input are integers.
 - 2 \leq N \leq 3000
 - 2 \leq a_i \leq 10^5

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

-----Output-----
Print the maximum value of f.

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

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

f(11) = (11\ mod\ 3) + (11\ mod\ 4) + (11\ mod\ 6) = 10 is the maximum value of f.

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

N = int(input())
A = list(map(int, input().split()))
print(sum(a - 1 for a in A))


I found an interesting problem on https://atcoder.jp/contests/abc103/tasks/abc103_d:
There are N islands lining up from west to east, connected by N-1 bridges.
The i-th bridge connects the i-th island from the west and the (i+1)-th island from the west.
One day, disputes took place between some islands, and there were M requests from the inhabitants of the islands:
Request i: A dispute took place between the a_i-th island from the west and the b_i-th island from the west. Please make traveling between these islands with bridges impossible.
You decided to remove some bridges to meet all these M requests.
Find the minimum number of bridges that must be removed.

-----Constraints-----
 - All values in input are integers.
 - 2 \leq N \leq 10^5
 - 1 \leq M \leq 10^5
 - 1 \leq a_i < b_i \leq N
 - All pairs (a_i, b_i) are distinct.

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

-----Output-----
Print the minimum number of bridges that must be removed.

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

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

The requests can be met by removing the bridge connecting the second and third islands from the west.

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

N, M = map(int, input().split())
AB = []

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

Rsort = sorted(AB, key=lambda x: x[1])
cnt = 0
R = 0

for a, b in Rsort:
  if a <= R:
    continue
  else:
    cnt += 1
    R = b-1

print(cnt)


I found an interesting problem on https://atcoder.jp/contests/abc104/tasks/abc104_a:
A programming competition site AtCode regularly holds programming contests.
The next contest on AtCode is called ABC, which is rated for contestants with ratings less than 1200.
The contest after the ABC is called ARC, which is rated for contestants with ratings less than 2800.
The contest after the ARC is called AGC, which is rated for all contestants.
Takahashi's rating on AtCode is R. What is the next contest rated for him?

-----Constraints-----
 - 0 ≤ R ≤ 4208
 - R is an integer.

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

-----Output-----
Print the name of the next contest rated for Takahashi (ABC, ARC or AGC).

-----Sample Input-----
1199

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

1199 is less than 1200, so ABC will be rated.

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


I found an interesting problem on https://atcoder.jp/contests/abc104/tasks/abc104_b:
You are given a string S. Each character of S is uppercase or lowercase English letter.
Determine if S satisfies all of the following conditions:
 - The initial character of S is an uppercase A.
 - There is exactly one occurrence of C between the third character from the beginning and the second to last character (inclusive).
 - All letters except the A and C mentioned above are lowercase.

-----Constraints-----
 - 4 ≤ |S| ≤ 10 (|S| is the length of the string S.)
 - Each character of S is uppercase or lowercase English letter.

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

-----Output-----
If S satisfies all of the conditions in the problem statement, print AC; otherwise, print WA.

-----Sample Input-----
AtCoder

-----Sample Output-----
AC

The first letter is A, the third letter is C and the remaining letters are all lowercase, so all the conditions are satisfied.

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

S = input()

if S[0] == 'A' and S[1].islower() and 'C' in S[2:-1]:
    SS = S.replace('C', '').replace('A', '')
    if SS.islower() and len(SS) == len(S) - 2:
        print('AC')
    else:
        print('WA')
else:
    print('WA')


I found an interesting problem on https://atcoder.jp/contests/abc104/tasks/abc104_c:
A programming competition site AtCode provides algorithmic problems.
Each problem is allocated a score based on its difficulty.
Currently, for each integer i between 1 and D (inclusive), there are p_i problems with a score of 100i points.
These p_1 + … + p_D problems are all of the problems available on AtCode.
A user of AtCode has a value called total score.
The total score of a user is the sum of the following two elements:
 - Base score: the sum of the scores of all problems solved by the user.
 - Perfect bonuses: when a user solves all problems with a score of 100i points, he/she earns the perfect bonus of c_i points, aside from the base score (1 ≤ i ≤ D).
Takahashi, who is the new user of AtCode, has not solved any problem.
His objective is to have a total score of G or more points.
At least how many problems does he need to solve for this objective?

-----Constraints-----
 - 1 ≤ D ≤ 10
 - 1 ≤ p_i ≤ 100
 - 100 ≤ c_i ≤ 10^6
 - 100 ≤ G
 - All values in input are integers.
 - c_i and G are all multiples of 100.
 - It is possible to have a total score of G or more points.

-----Input-----
Input is given from Standard Input in the following format:
D G
p_1 c_1
:
p_D c_D

-----Output-----
Print the minimum number of problems that needs to be solved in order to have a total score of G or more points. Note that this objective is always achievable (see Constraints).

-----Sample Input-----
2 700
3 500
5 800

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

In this case, there are three problems each with 100 points and five problems each with 200 points. The perfect bonus for solving all the 100-point problems is 500 points, and the perfect bonus for solving all the 200-point problems is 800 points. Takahashi's objective is to have a total score of 700 points or more.
One way to achieve this objective is to solve four 200-point problems and earn a base score of 800 points. However, if we solve three 100-point problems, we can earn the perfect bonus of 500 points in addition to the base score of 300 points, for a total score of 800...

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

from itertools import product

D, G = map(int, input().split())
G //= 100
prob = []

for i in range(1, D+1):
  p, c = map(int, input().split())
  prob.append((i, p, c//100))

ans = 1000
for comp in product((0, 1), repeat=D):
  cnt, score = 0, 0
  for i, c in enumerate(comp):
    if c:
      cnt += prob[i][1]
      score += prob[i][0]*prob[i][1] + prob[i][2]
  j = D-1
  while score < G and j >= 0:
    if comp[j] == 0:
      if score + prob[j][0]*prob[j][1] <= G:
        cnt += prob[j][1]
        score += prob[j][0]*prob[j][1]
      else:
        temp = -(-(G - score)//prob[j][0])
        cnt += temp
        score += prob[j][0]*temp
    j -= 1
  ans = min(ans, cnt)

print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc104/tasks/abc104_d:
The ABC number of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions:
 - 1 ≤ i < j < k ≤ |T| (|T| is the length of T.)
 - T_i = A (T_i is the i-th character of T from the beginning.)
 - T_j = B
 - T_k = C
For example, when T = ABCBC, there are three triples of integers (i, j, k) that satisfy the conditions: (1, 2, 3), (1, 2, 5), (1, 4, 5). Thus, the ABC number of T is 3.
You are given a string S. Each character of S is A, B, C or ?.
Let Q be the number of occurrences of ? in S. We can make 3^Q strings by replacing each occurrence of ? in S with A, B or C. Find the sum of the ABC numbers of all these strings.
This sum can be extremely large, so print the sum modulo 10^9 + 7.

-----Constraints-----
 - 3 ≤ |S| ≤ 10^5
 - Each character of S is A, B, C or ?.

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

-----Output-----
Print the sum of the ABC numbers of all the 3^Q strings, modulo 10^9 + 7.

-----Sample Input-----
A??C

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

In this case, Q = 2, and we can make 3^Q = 9 strings by by replacing each occurrence of ? with A, B or C. The ABC number of each of these strings is as follows:
 - AAAC: 0
 - AABC: 2
 - AACC: 0
 - ABAC: 1
 - ABBC: 2
 - ABCC: 2
 - ACAC: 0
 - ACBC: 1
 - ACCC: 0
The sum of these is 0 + 2 + 0 + 1 + 2 + 2 + 0 + 1 + 0 = 8, so we print 8 modulo 10^9 + 7, that is, 8.

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

# def C(n, r ,mod=10**9+7):
#     if n-r<r: r=n-r
#     if r == 0: return 1
#     if r == 1: return n
#
#     numerator = [n - r + k + 1 for k in range(r)]
#     denominator = [k + 1 for k in range(r)]
#
#     for p in range(2,r+1):
#         pivot = denominator[p - 1]
#         if pivot > 1:
#             offset = (n - r) % p
#             for k in range(p-1,r,p):
#                 numerator[k - offset] /= pivot
#                 denominator[k] /= pivot
#
#     result = 1
#     for k in range(r):
#         if numerator[k] > 1:
#             result *= int(numerator[k]) %mod
#
#     return result % mod

A=list(input())
n=len(A)
mod=10**9+7
ans=0
numa= A[0]=="A"
numa_= A[0]=="?"
numc=A[2:].count("C")
numc_= A[2:].count("?")

for i in range(1,n-1):
    #print(numa,numa_,numc,numc_)
    apro=cpro=0
    if A[i]=="B" or A[i]=="?":
        # for k in range(numa_+1):
        #     apro+= (((C(numa_,k)*pow(2,numa_-k,mod))%mod)*(numa+k))%mod
        # for k in range(numc_+1):
        #     cpro+= (((C(numc_,k)*pow(2,numc_-k,mod))%mod)*(numc+k))%mod
        #print(apro,cpro)
        apro= ((3*numa+numa_)*pow(3,(numa_-1),mod))%mod
        cpro= ((3*numc+numc_)*pow(3,(numc_-1),mod))%mod
        ans+= (apro*cpro)%mod
        ans%=mod
    if A[i] == "A":
        numa+=1
    if A[i]=="?":
        numa_+=1
    if A[i+1] =="C":
        numc-=1
    if A[i+1]=="?":
        numc_-=1
print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc105/tasks/abc105_a:
Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly as possible.
When all the crackers are distributed, find the minimum possible (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user.

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

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

-----Output-----
Print the minimum possible (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user.

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

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

When the users receive two, two and three crackers, respectively, the (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user, is 1.

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

N, K = list(map(int, input().split()))
print((0 if N%K==0 else 1))


I found an interesting problem on https://atcoder.jp/contests/abc105/tasks/abc105_b:
La Confiserie d'ABC sells cakes at 4 dollars each and doughnuts at 7 dollars each.
Determine if there is a way to buy some of them for exactly N dollars. You can buy two or more doughnuts and two or more cakes, and you can also choose to buy zero doughnuts or zero cakes.

-----Constraints-----
 - N is an integer between 1 and 100, inclusive.

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

-----Output-----
If there is a way to buy some cakes and some doughnuts for exactly N dollars, print Yes; otherwise, print No.

-----Sample Input-----
11

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

If you buy one cake and one doughnut, the total will be 4 + 7 = 11 dollars.

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

n = int(input())
a = int(n / 7)
check = False
for i in range(a, -1, -1):
    if (n - 7 * i) % 4 == 0:
        check = True
if check:
    print('Yes')
else:
    print('No')


I found an interesting problem on https://atcoder.jp/contests/abc105/tasks/abc105_c:
Given an integer N, find the base -2 representation of N.
Here, S is the base -2 representation of N when the following are all satisfied:
 - S is a string consisting of 0 and 1.
 - Unless S = 0, the initial character of S is 1.
 - Let S = S_k S_{k-1} ... S_0, then S_0 \times (-2)^0 + S_1 \times (-2)^1 + ... + S_k \times (-2)^k = N.
It can be proved that, for any integer M, the base -2 representation of M is uniquely determined.

-----Constraints-----
 - Every value in input is integer.
 - -10^9 \leq N \leq 10^9

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

-----Output-----
Print the base -2 representation of N.

-----Sample Input-----
-9

-----Sample Output-----
1011

As (-2)^0 + (-2)^1 + (-2)^3 = 1 + (-2) + (-8) = -9, 1011 is the base -2 representation of -9.

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

n = int(input())

if n == 0:
    print(0)
    return

ans = []
while n != 0:
    ans.append(n % 2)
    n = - (n // 2)
print(''.join(map(str, reversed(ans))))


I found an interesting problem on https://atcoder.jp/contests/abc105/tasks/abc105_d:
There are N boxes arranged in a row from left to right. The i-th box from the left contains A_i candies.
You will take out the candies from some consecutive boxes and distribute them evenly to M children.
Such being the case, find the number of the pairs (l, r) that satisfy the following:
 - l and r are both integers and satisfy 1 \leq l \leq r \leq N.
 - A_l + A_{l+1} + ... + A_r is a multiple of M.

-----Constraints-----
 - All values in input are integers.
 - 1 \leq N \leq 10^5
 - 2 \leq M \leq 10^9
 - 1 \leq A_i \leq 10^9

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

-----Output-----
Print the number of the pairs (l, r) that satisfy the conditions.
Note that the number may not fit into a 32-bit integer type.

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

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

The sum A_l + A_{l+1} + ... + A_r for each pair (l, r) is as follows:
 - Sum for (1, 1): 4
 - Sum for (1, 2): 5
 - Sum for (1, 3): 10
 - Sum for (2, 2): 1
 - Sum for (2, 3): 6
 - Sum for (3, 3): 5
Among these, three are multiples of 2.

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

from itertools import accumulate
from collections import defaultdict
N,M=map(int,input().split())
A=list(map(int,input().split()))
acc = [0]+list(accumulate(A,lambda x,y:x+y))
d = defaultdict(list)
for i in range(len(acc)):
    d[acc[i] % M].append(i)
ans = 0
for l in map(len,d.values()):
    ans += l*(l-1)//2
print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc106/tasks/abc106_a:
There is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents the roads.)

What is the area of this yard excluding the roads? Find it.

-----Note-----
It can be proved that the positions of the roads do not affect the area.

-----Constraints-----
 - A is an integer between 2 and 100 (inclusive).
 - B is an integer between 2 and 100 (inclusive).

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

-----Output-----
Print the area of this yard excluding the roads (in square yards).

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

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

In this case, the area is 1 square yard.

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


I found an interesting problem on https://atcoder.jp/contests/abc106/tasks/abc106_b:
The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive divisors are there between 1 and N (inclusive)?

-----Constraints-----
 - N is an integer between 1 and 200 (inclusive).

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

-----Output-----
Print the count.

-----Sample Input-----
105

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

Among the numbers between 1 and 105, the only number that is odd and has exactly eight divisors is 105.

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

import math
from collections import Counter
from itertools import product

ii = lambda : int(input())
mi = lambda : list(map(int,input().split()))
li = lambda : list(map(int,input().split()))

def make_divisors(n):
    lower_div , upper_div = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_div.append(i)
            if i != n // i:
                upper_div.append(n//i)
        i += 1
    return lower_div + upper_div[::-1]

n = ii()
cnt = 0
for i in range(1,n+1,2):
    if len(make_divisors(i)) == 8:
        cnt+=1
print(cnt)


I found an interesting problem on https://atcoder.jp/contests/abc106/tasks/abc106_c:
Mr. Infinity has a string S consisting of digits from 1 to 9. Each time the date changes, this string changes as follows:
 - Each occurrence of 2 in S is replaced with 22. Similarly, each 3 becomes 333, 4 becomes 4444, 5 becomes 55555, 6 becomes 666666, 7 becomes 7777777, 8 becomes 88888888 and 9 becomes 999999999. 1 remains as 1.
For example, if S is 1324, it becomes 1333224444 the next day, and it becomes 133333333322224444444444444444 the day after next.
You are interested in what the string looks like after 5 \times 10^{15} days. What is the K-th character from the left in the string after 5 \times 10^{15} days?

-----Constraints-----
 - S is a string of length between 1 and 100 (inclusive).
 - K is an integer between 1 and 10^{18} (inclusive).
 - The length of the string after 5 \times 10^{15} days is at least K.

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

-----Output-----
Print the K-th character from the left in Mr. Infinity's string after 5 \times 10^{15} days.

-----Sample Input-----
1214
4

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

The string S changes as follows:
 - Now: 1214
 - After one day: 12214444
 - After two days: 1222214444444444444444
 - After three days: 12222222214444444444444444444444444444444444444444444444444444444444444444
The first five characters in the string after 5 \times 10^{15} days is 12222. As K=4, we should print the fourth character, 2.

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

s=input()
k=int(input())
d=5*10**15
for i in s:
  if i=='1':
    k-=1
  else:
    print(i)
    return
  if k<=0:
    print(1)
    return


I found an interesting problem on https://atcoder.jp/contests/abc106/tasks/abc106_d:
In Takahashi Kingdom, there is a east-west railroad and N cities along it, numbered 1, 2, 3, ..., N from west to east.
A company called AtCoder Express possesses M trains, and the train i runs from City L_i to City R_i (it is possible that L_i = R_i).
Takahashi the king is interested in the following Q matters:
 - The number of the trains that runs strictly within the section from City p_i to City q_i, that is, the number of trains j such that p_i \leq L_j and R_j \leq q_i.
Although he is genius, this is too much data to process by himself. Find the answer for each of these Q queries to help him.

-----Constraints-----
 - N is an integer between 1 and 500 (inclusive).
 - M is an integer between 1 and 200 \ 000 (inclusive).
 - Q is an integer between 1 and 100 \ 000 (inclusive).
 - 1 \leq L_i \leq R_i \leq N (1 \leq i \leq M)
 - 1 \leq p_i \leq q_i \leq N (1 \leq i \leq Q)

-----Input-----
Input is given from Standard Input in the following format:
N M Q
L_1 R_1
L_2 R_2
:
L_M R_M
p_1 q_1
p_2 q_2
:
p_Q q_Q

-----Output-----
Print Q lines. The i-th line should contain the number of the trains that runs strictly within the section from City p_i to City q_i.

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

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

As all the trains runs within the section from City 1 to City 2, the answer to the only query is 3.

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

#!/usr/bin python3
# -*- coding: utf-8 -*-

import numpy as np
n, m, q = list(map(int, input().split()))
x = np.zeros((n,n), dtype = int)
for _ in range(m):
    l, r = list(map(int, input().split()))
    x[r-1][l-1] += 1
x.cumsum(out = x, axis = 0)
for i in range(n):
    x[i] = np.cumsum(x[i][::-1])[::-1]

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


I found an interesting problem on https://atcoder.jp/contests/abc107/tasks/abc107_a:
There is an N-car train.
You are given an integer i. Find the value of j such that the following statement is true: "the i-th car from the front of the train is the j-th car from the back."

-----Constraints-----
 - 1 \leq N \leq 100
 - 1 \leq i \leq N

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

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

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

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

The second car from the front of a 4-car train is the third car from the back.

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

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

print(a- b + 1)


I found an interesting problem on https://atcoder.jp/contests/abc107/tasks/abc107_b:
There is a grid of squares with H horizontal rows and W vertical columns.
The square at the i-th row from the top and the j-th column from the left is represented as (i, j).
Each square is black or white.
The color of the square is given as an H-by-W matrix (a_{i, j}).
If a_{i, j} is ., the square (i, j) is white; if a_{i, j} is #, the square (i, j) is black.
Snuke is compressing this grid.
He will do so by repeatedly performing the following operation while there is a row or column that consists only of white squares:
 - Operation: choose any one row or column that consists only of white squares, remove it and delete the space between the rows or columns.
It can be shown that the final state of the grid is uniquely determined regardless of what row or column is chosen in each operation.
Find the final state of the grid.

-----Constraints-----
 - 1 \leq H, W \leq 100
 - a_{i, j} is . or #.
 - There is at least one black square in the whole grid.

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

-----Output-----
Print the final state of the grid in the same format as input (without the numbers of rows and columns); see the samples for clarity.

-----Sample Input-----
4 4
##.#
....
##.#
.#.#

-----Sample Output-----
###
###
.##

The second row and the third column in the original grid will be removed.

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

h,w=map(int,input().split())
A=[]
ans=[]
for i in range(h):
  A.append(list(input()))
for a in A:
  if a != ['.']*w:
    ans.append(a)
counter=[]
for i in range(w):
  flag=0
  for j in range(len(ans)):
    if ans[j][i]=='#':
      flag=1
      break
  if flag==1:
    counter.append(i)

for a in ans:
  tmp=''
  for i in counter:
    tmp=tmp+a[i]
  print(tmp)


I found an interesting problem on https://atcoder.jp/contests/abc107/tasks/arc101_a:
There are N candles placed on a number line.
The i-th candle from the left is placed on coordinate x_i.
Here, x_1 < x_2 < ... < x_N holds.
Initially, no candles are burning.
Snuke decides to light K of the N candles.
Now, he is at coordinate 0.
He can move left and right along the line with speed 1.
He can also light a candle when he is at the same position as the candle, in negligible time.
Find the minimum time required to light K candles.

-----Constraints-----
 - 1 \leq N \leq 10^5
 - 1 \leq K \leq N
 - x_i is an integer.
 - |x_i| \leq 10^8
 - x_1 < x_2 < ... < x_N

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

-----Output-----
Print the minimum time required to light K candles.

-----Sample Input-----
5 3
-30 -10 10 20 50

-----Sample Output-----
40

He should move and light candles as follows:
 - Move from coordinate 0 to -10.
 - Light the second candle from the left.
 - Move from coordinate -10 to 10.
 - Light the third candle from the left.
 - Move from coordinate 10 to 20.
 - Light the fourth candle from the left.

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

N,K = map(int,input().split())
x = list(map(int,input().split()))
xp = [i for i in x if i >= 0]
xn = [i for i in x if i < 0]
xn.reverse()
lp = len(xp)
ln = len(xn)
if lp == 0:
    print(-xn[K-1])
    return
if ln == 0:
    print(xp[K-1])
    return
pc = min(K,lp)
pp = xp[pc-1]
if K>lp:
    nc = K-lp
    np = -xn[nc-1]
else:
    nc = 0
    np = 0
ans = pp + np + min(pp,np)
for i in range(pc-1):
    if nc == ln:
        break
    pp = xp[pc-i-2]
    np = -xn[nc]
    nc += 1
    ans = min(ans,pp + np + min(pp,np))
print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc107/tasks/arc101_b:
We will define the median of a sequence b of length M, as follows:
 - Let b' be the sequence obtained by sorting b in non-decreasing order. Then, the value of the (M / 2 + 1)-th element of b' is the median of b. Here, / is integer division, rounding down.
For example, the median of (10, 30, 20) is 20; the median of (10, 30, 20, 40) is 30; the median of (10, 10, 10, 20, 30) is 10.
Snuke comes up with the following problem.
You are given a sequence a of length N.
For each pair (l, r) (1 \leq l \leq r \leq N), let m_{l, r} be the median of the contiguous subsequence (a_l, a_{l + 1}, ..., a_r) of a.
We will list m_{l, r} for all pairs (l, r) to create a new sequence m.
Find the median of m.

-----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 median of m.

-----Sample Input-----
3
10 30 20

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

The median of each contiguous subsequence of a is as follows:
 - The median of (10) is 10.
 - The median of (30) is 30.
 - The median of (20) is 20.
 - The median of (10, 30) is 30.
 - The median of (30, 20) is 30.
 - The median of (10, 30, 20) is 20.
Thus, m = (10, 30, 20, 30, 30, 20) and the median of m is 30.

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

def f(n, a):
    x = list(sorted(set(a)))
    n_sub_half = n * (n + 1) // 2 // 2
    n_plus_minus = n * 2 + 1
    Li = 0
    Ri = len(x)
    while Ri > Li + 1:
        i = (Li + Ri) // 2
        xi = x[i]
        cnt_sum = [0] * n_plus_minus
        cumsum = 0
        cnt_sum[cumsum] = 1
        judge = 0
        s = 0
        for ak in a:
            if ak >= xi:
                cumsum += 1
                s += cnt_sum[cumsum] + 1
            else:
                cumsum -= 1
                s -= cnt_sum[cumsum + 1] - 1
            cnt_sum[cumsum] += 1
            judge += s
            if judge >= n_sub_half:
                Li = i
                break
        else:
            Ri = i
    print((x[Li]))

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


I found an interesting problem on https://atcoder.jp/contests/abc108/tasks/abc108_a:
Find the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive). The order does not matter.

-----Constraints-----
 - 2\leq K\leq 100
 - K is an integer.

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

-----Output-----
Print the number of ways to choose a pair of an even number and an odd number from the positive integers between 1 and K (inclusive).

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

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

Two pairs can be chosen: (2,1) and (2,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/abc108/tasks/abc108_b:
There is a square in the xy-plane. The coordinates of its four vertices are (x_1,y_1),(x_2,y_2),(x_3,y_3) and (x_4,y_4) in counter-clockwise order.
(Assume that the positive x-axis points right, and the positive y-axis points up.)
Takahashi remembers (x_1,y_1) and (x_2,y_2), but he has forgot (x_3,y_3) and (x_4,y_4).
Given x_1,x_2,y_1,y_2, restore x_3,y_3,x_4,y_4. It can be shown that x_3,y_3,x_4 and y_4 uniquely exist and have integer values.

-----Constraints-----
 - |x_1|,|y_1|,|x_2|,|y_2| \leq 100
 - (x_1,y_1) ≠ (x_2,y_2)
 - All values in input are integers.

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

-----Output-----
Print x_3,y_3,x_4 and y_4 as integers, in this order.

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

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

(0,0),(0,1),(-1,1),(-1,0) is the four vertices of a square in counter-clockwise order.
Note that (x_3,y_3)=(1,1),(x_4,y_4)=(1,0) is not accepted, as the vertices are in clockwise order.

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


I found an interesting problem on https://atcoder.jp/contests/abc108/tasks/arc102_a:
You are given integers N and K. Find the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K.
The order of a,b,c does matter, and some of them can be the same.

-----Constraints-----
 - 1 \leq N,K \leq 2\times 10^5
 - N and K are integers.

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

-----Output-----
Print the number of triples (a,b,c) of positive integers not greater than N such that a+b,b+c and c+a are all multiples of K.

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

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

(1,1,1),(1,1,3),(1,3,1),(1,3,3),(2,2,2),(3,1,1),(3,1,3),(3,3,1) and (3,3,3) satisfy the condition.

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

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

if k%2 == 1: # kが奇数の場合
  x = 0
  for i in range(1,n+1):
    if i%k == 0: x += 1 # kで割り切れる値の数をカウント
  print(x**3) # 組み合わせ分増える
else: # kが偶数の場合
  x = 0
  for i in range(1, n+1):
    if i % k == 0: x += 1 # kで割り切れる値の数をカウント
  y = 0
  for i in range(1, n+1):
    if i % k == k//2: y += 1 # k//2で割り切れる値の数をカウント
  print(x**3 + y**3) # 組み合わせ分増える


I found an interesting problem on https://atcoder.jp/contests/abc108/tasks/arc102_b:
You are given an integer L. Construct a directed graph that satisfies the conditions below. The graph may contain multiple edges between the same pair of vertices. It can be proved that such a graph always exists.
 - The number of vertices, N, is at most 20. The vertices are given ID numbers from 1 to N.
 - The number of edges, M, is at most 60. Each edge has an integer length between 0 and 10^6 (inclusive).
 - Every edge is directed from the vertex with the smaller ID to the vertex with the larger ID. That is, 1,2,...,N is one possible topological order of the vertices.
 - There are exactly L different paths from Vertex 1 to Vertex N. The lengths of these paths are all different, and they are integers between 0 and L-1.
Here, the length of a path is the sum of the lengths of the edges contained in that path, and two paths are considered different when the sets of the edges contained in those paths are different.

-----Constraints-----
 - 2 \leq L \leq 10^6
 - L is an integer.

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

-----Output-----
In the first line, print N and M, the number of the vertices and edges in your graph.
In the i-th of the following M lines, print three integers u_i,v_i and w_i, representing the starting vertex, the ending vertex and the length of the i-th edge.
If there are multiple solutions, any of them will be accepted.

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

-----Sample Output-----
8 10
1 2 0
2 3 0
3 4 0
1 5 0
2 6 0
3 7 0
4 8 0
5 6 1
6 7 1
7 8 1

In the graph represented by the sample output, there are four paths from Vertex 1 to N=8:
 - 1 → 2 → 3 → 4 → 8 with length 0
 - 1 → 2 → 3 → 7 → 8 with length 1
 - 1 → 2 → 6 → 7 → 8 with length 2
 - 1 → 5 → 6 → 7 → 8 with length 3
There are other possible solutions.

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

L = int(input())

Lbin = (bin(L)[2:])[::-1]
N = len(Lbin)
M = 2 * (N - 1) + Lbin.count("1") - 1
print(N, M)

for i in range(0, N - 1):
    print(i + 1, i + 2, 0)
    print(i + 1, i + 2, 2 ** i)

weight = L
for i in range(0, N - 1):
    if Lbin[i] == '1':  # 2^iの位
        weight -= 2 ** i
        print(i + 1, N, weight)


I found an interesting problem on https://atcoder.jp/contests/abc109/tasks/abc109_a:
You are given integers A and B, each between 1 and 3 (inclusive).
Determine if there is an integer C between 1 and 3 (inclusive) such that A \times B \times C is an odd number.

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

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

-----Output-----
If there is an integer C between 1 and 3 that satisfies the condition, print Yes; otherwise, print No.

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

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

Let C = 3. Then, A \times B \times C = 3 \times 1 \times 3 = 9, which is an odd number.

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

A,B=list(map(int,(input().split())))
count=0

for C in range(1,4):
    if A*B*C%2==1:
        count=count+1

if count>=1:
    print('Yes')

elif count==0:
    print('No')


I found an interesting problem on https://atcoder.jp/contests/abc109/tasks/abc109_b:
Takahashi is practicing shiritori alone again today.
Shiritori is a game as follows:
 - In the first turn, a player announces any one word.
 - In the subsequent turns, a player announces a word that satisfies the following conditions:
 - That word is not announced before.
 - The first character of that word is the same as the last character of the last word announced.
In this game, he is practicing to announce as many words as possible in ten seconds.
You are given the number of words Takahashi announced, N, and the i-th word he announced, W_i, for each i. Determine if the rules of shiritori was observed, that is, every word announced by him satisfied the conditions.

-----Constraints-----
 - N is an integer satisfying 2 \leq N \leq 100.
 - W_i is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.

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

-----Output-----
If every word announced by Takahashi satisfied the conditions, print Yes; otherwise, print No.

-----Sample Input-----
4
hoge
english
hoge
enigma

-----Sample Output-----
No

As hoge is announced multiple times, the rules of shiritori was not observed.

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

import math
import itertools
import sys

n=int(input())
last=input()
log=[]
log.append(last)
q=[]
ans="Yes"
for i in range(n-1):
    tmp=input()
    q.append(tmp)
for i in q:
    if(i[0]!=last[-1] or i in log):
        ans="No"
        break
    else:
        last=i
        log.append(i)
print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc109/tasks/abc109_c:
There are N cities on a number line. The i-th city is located at coordinate x_i.
Your objective is to visit all these cities at least once.
In order to do so, you will first set a positive integer D.
Then, you will depart from coordinate X and perform Move 1 and Move 2 below, as many times as you like:
 - Move 1: travel from coordinate y to coordinate y + D.
 - Move 2: travel from coordinate y to coordinate y - D.
Find the maximum value of D that enables you to visit all the cities.
Here, to visit a city is to travel to the coordinate where that city is located.

-----Constraints-----
 - All values in input are integers.
 - 1 \leq N \leq 10^5
 - 1 \leq X \leq 10^9
 - 1 \leq x_i \leq 10^9
 - x_i are all different.
 - x_1, x_2, ..., x_N \neq X

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

-----Output-----
Print the maximum value of D that enables you to visit all the cities.

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

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

Setting D = 2 enables you to visit all the cities as follows, and this is the maximum value of such D.
 - Perform Move 2 to travel to coordinate 1.
 - Perform Move 1 to travel to coordinate 3.
 - Perform Move 1 to travel to coordinate 5.
 - Perform Move 1 to travel to coordinate 7.
 - Perform Move 1 to travel to coordinate 9.
 - Perform Move 1 to travel to coordinate 11.

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

import functools
def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)

def gcd(nums):
    if len(nums)==1:
        return nums[0]
    return functools.reduce(euclid, nums)

n,k=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
a.append(k)
a.sort()

sa=[]

for i in range(1,n+1):
    sa.append(a[i]-a[i-1])

print((gcd(sa)))


I found an interesting problem on https://atcoder.jp/contests/abc109/tasks/abc109_d:
There is a grid of square cells with H horizontal rows and W vertical columns. The cell at the i-th row and the j-th column will be denoted as Cell (i, j).
In Cell (i, j), a_{ij} coins are placed.
You can perform the following operation any number of times:
Operation: Choose a cell that was not chosen before and contains one or more coins, then move one of those coins to a vertically or horizontally adjacent cell.
Maximize the number of cells containing an even number of coins.

-----Constraints-----
 - All values in input are integers.
 - 1 \leq H, W \leq 500
 - 0 \leq a_{ij} \leq 9

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

-----Output-----
Print a sequence of operations that maximizes the number of cells containing an even number of coins, in the following format:
N
y_1 x_1 y_1' x_1'
y_2 x_2 y_2' x_2'
:
y_N x_N y_N' x_N'

That is, in the first line, print an integer N between 0 and H \times W (inclusive), representing the number of operations.
In the (i+1)-th line (1 \leq i \leq N), print four integers y_i, x_i, y_i' and x_i' (1 \leq y_i, y_i' \leq H and 1 \leq x_i, x_i' \leq W), representing the i-th operation. These four integers represents the operation of moving one of the coins placed in Cell (y_i, x_i) to a vertically or horizontally adjacent cell, (y_i', x_i').
Note that if the specified operation violates the specification in the problem statement or the output format is invalid, it will result in Wrong Answer.

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

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

Every cell contains an even number of coins after the following sequence of operations:
 - Move the coin in Cell (2, 2) to Cell (2, 3).
 - Move the coin in Cell (1, 1) to Cell (1, 2).
 - Move one of the coins in Cell (1, 3) to Cell (1, 2).

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

# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil, atan, pi
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left
MOD = int(1e9)+7
INF = float('inf')

def solve():
    # n, m = [int(x) for x in input().split()]
    n, m = [int(x) for x in input().split()]
    ans = []
    c = 0
    for i in range(n):
        r = [int(x) for x in input().split()]
        for j in range(m):
            if i + 1 == n and j + 1 == m: continue
            if i % 2:
                j = m - j - 1
            r[j] += c
            c = r[j] % 2
            if c:
                x = i + 1
                y = j + 1
                if i % 2:
                    if y == 1:
                        ans.append((x, y, x + 1, y))
                    else:
                        ans.append((x, y, x, y - 1))
                else:
                    if y == m:
                        ans.append((x, y, x + 1, y))
                    else:
                        ans.append((x, y, x, y + 1))
    print((len(ans)))
    for r in ans:
        print((*r))

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()

"""

azyxwvutsrqponmlkjihgfedcb

"""


I found an interesting problem on https://atcoder.jp/contests/abc110/tasks/abc110_a:
You have decided to give an allowance to your child depending on the outcome of the game that he will play now.
The game is played as follows:
 - There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a + printed on it.
 - The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)
 - Then, the amount of the allowance will be equal to the resulting value of the formula.
Given the values A, B and C printed on the integer panels used in the game, find the maximum possible amount of the allowance.

-----Constraints-----
 - All values in input are integers.
 - 1 \leq A, B, C \leq 9

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

-----Output-----
Print the maximum possible amount of the allowance.

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

-----Sample Output-----
53

The amount of the allowance will be 53 when the panels are arranged as 52+1, and this is the maximum possible amount.

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

a = list(map(int,input().split()))
sort_a = sorted(a,reverse=True)
tmp = int(str(sort_a[0])+str(sort_a[1]))+sort_a[2]
print(tmp)


I found an interesting problem on https://atcoder.jp/contests/abc110/tasks/abc110_b:
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B.
The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y.
One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control.
If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out.
 - X < Z \leq Y
 - x_1, x_2, ..., x_N < Z
 - y_1, y_2, ..., y_M \geq Z
Determine if war will break out.

-----Constraints-----
 - All values in input are integers.
 - 1 \leq N, M \leq 100
 - -100 \leq X < Y \leq 100
 - -100 \leq x_i, y_i \leq 100
 - x_1, x_2, ..., x_N \neq X
 - x_i are all different.
 - y_1, y_2, ..., y_M \neq Y
 - y_i are all different.

-----Input-----
Input is given from Standard Input in the following format:
N M X Y
x_1 x_2 ... x_N
y_1 y_2 ... y_M

-----Output-----
If war will break out, print War; otherwise, print No War.

-----Sample Input-----
3 2 10 20
8 15 13
16 22

-----Sample Output-----
No War

The choice Z = 16 satisfies all of the three conditions as follows, thus they will come to an agreement.
 - X = 10 < 16 \leq 20 = Y
 - 8, 15, 13 < 16
 - 16, 22 \geq 16

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

n,m,x,y=list(map(int,input().split()))
X=list(map(int,input().split()))
Y=list(map(int,input().split()))
mx=max(X)
my=min(Y)
if mx<my:
    for i in range(mx+1,my+1):
        if x<i<=y:
            print("No War")
            return
    print("War")

else:
    print("War")


I found an interesting problem on https://atcoder.jp/contests/abc110/tasks/abc110_c:
You are given strings S and T consisting of lowercase English letters.
You can perform the following operation on S any number of times:
Operation: Choose two distinct lowercase English letters c_1 and c_2, then replace every occurrence of c_1 with c_2, and every occurrence of c_2 with c_1.
Determine if S and T can be made equal by performing the operation zero or more times.

-----Constraints-----
 - 1 \leq |S| \leq 2 \times 10^5
 - |S| = |T|
 - S and T consists of lowercase English letters.

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

-----Output-----
If S and T can be made equal, print Yes; otherwise, print No.

-----Sample Input-----
azzel
apple

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

azzel can be changed to apple, as follows:
 - Choose e as c_1 and l as c_2. azzel becomes azzle.
 - Choose z as c_1 and p as c_2. azzle becomes apple.

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

s = input()
t = input()
memo = {}
ans = 'Yes'
for i in range(len(s)):
    if s[i] in memo:
        if t[i] != memo[s[i]]:
            ans = 'No'
            break
    else:
        memo[s[i]] = t[i]
a = list(memo.values())
b = list(set(a))
if len(b) != len(a):
    ans = 'No'
print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc110/tasks/abc110_d:
You are given positive integers N and M.
How many sequences a of length N consisting of positive integers satisfy a_1 \times a_2 \times ... \times a_N = M? Find the count modulo 10^9+7.
Here, two sequences a' and a'' are considered different when there exists some i such that a_i' \neq a_i''.

-----Constraints-----
 - All values in input are integers.
 - 1 \leq N \leq 10^5
 - 1 \leq M \leq 10^9

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

-----Output-----
Print the number of the sequences consisting of positive integers that satisfy the condition, modulo 10^9 + 7.

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

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

Four sequences satisfy the condition: \{a_1, a_2\} = \{1, 6\}, \{2, 3\}, \{3, 2\} and \{6, 1\}.

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

MOD=10**9+7
UPPERLIMIT=2*10**5
MODMUL=[1, 1]+[0]*(UPPERLIMIT-1)
for i in range(2, UPPERLIMIT+1):
  MODMUL[i]=MODMUL[i-1]*i%MOD
MODDIV=[1]*UPPERLIMIT+[pow(MODMUL[-1], MOD-2, MOD)]
for i in range(UPPERLIMIT, 0, -1):
  MODDIV[i-1]=MODDIV[i]*i%MOD
def MODCOMB(n, r):
  return (((MODMUL[n]*MODDIV[r])%MOD)*MODDIV[n-r])%MOD

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

from collections import defaultdict
def PrimeFactorization(x):
  out=defaultdict(int)
  for i in range(2, int(pow(x, 1/2))+1):
    while x%i==0:
      out[i]+=1
      x//=i
  if x>1:
    out[x]+=1
  return out

primenums=PrimeFactorization(M)
ans=1
for x in primenums.values():
  ans*=MODCOMB(N+x-1, N-1)
  ans%=MOD

print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc111/tasks/abc111_a:
Cat Snuke is learning to write characters.
Today, he practiced writing digits 1 and 9, but he did it the other way around.
You are given a three-digit integer n written by Snuke.
Print the integer obtained by replacing each digit 1 with 9 and each digit 9 with 1 in n.

-----Constraints-----
 - 111 \leq n \leq 999
 - n is an integer consisting of digits 1 and 9.

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

-----Output-----
Print the integer obtained by replacing each occurrence of 1 with 9 and each occurrence of 9 with 1 in n.

-----Sample Input-----
119

-----Sample Output-----
991

Replace the 9 in the ones place with 1, the 1 in the tens place with 9 and the 1 in the hundreds place with 9. The answer is 991.

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

n = list(input())

for i in range(3):
    if n[i] == "1":
        n[i] = "9"
    elif n[i] == "9":
        n[i] = "1"
print("".join(n))


I found an interesting problem on https://atcoder.jp/contests/abc111/tasks/abc111_b:
Kurohashi has never participated in AtCoder Beginner Contest (ABC).
The next ABC to be held is ABC N (the N-th ABC ever held).
Kurohashi wants to make his debut in some ABC x such that all the digits of x in base ten are the same.
What is the earliest ABC where Kurohashi can make his debut?

-----Constraints-----
 - 100 \leq N \leq 999
 - N is an integer.

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

-----Output-----
If the earliest ABC where Kurohashi can make his debut is ABC n, print n.

-----Sample Input-----
111

-----Sample Output-----
111

The next ABC to be held is ABC 111, where Kurohashi can make his debut.

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

N = int(input())
for i in range(N,1000):
    moji = str(i)
    if (moji[0] == moji[1]) and (moji[1] == moji[2]):
        break

print(i)


I found an interesting problem on https://atcoder.jp/contests/abc111/tasks/arc103_a:
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied:
 - For each i = 1,2,..., n-2, a_i = a_{i+2}.
 - Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length is even.
We would like to make this sequence /\/\/\/ by replacing some of its elements.
Find the minimum number of elements that needs to be replaced.

-----Constraints-----
 - 2 \leq n \leq 10^5
 - n is even.
 - 1 \leq v_i \leq 10^5
 - v_i is an integer.

-----Input-----
Input is given from Standard Input in the following format:
n
v_1 v_2 ... v_n

-----Output-----
Print the minimum number of elements that needs to be replaced.

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

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

The sequence 3,1,3,2 is not /\/\/\/, but we can make it /\/\/\/ by replacing one of its elements: for example, replace the fourth element to make it 3,1,3,1.

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

import collections
n = int(input())
lsp = list(map(int,input().split()))
lse = []
lso = []
for i in range(n):
    if i%2 == 0:
        lse.append(lsp[i])
    else:
        lso.append(lsp[i])

countere = collections.Counter(lse)
countero = collections.Counter(lso)

valuee = sorted(list(countere.values()),reverse=True)+[0]
valueo = sorted(list(countero.values()),reverse=True)+[0]

keyse = []
for i in countere.keys():
    if countere[i] == valuee[0]:
        keyse.append(i)
keyso = []
for i in countero.keys():
    if countero[i] == valueo[0]:
        keyso.append(i)
factor = 0
if len(keyse) == 1 and len(keyso) == 1 and keyso == keyse:
    factor = min(valuee[0]-valuee[1],valueo[0]-valueo[1])

print(n-valuee[0]-valueo[0]+factor)


I found an interesting problem on https://atcoder.jp/contests/abc111/tasks/arc103_b:
Snuke is introducing a robot arm with the following properties to his factory:
 - The robot arm consists of m sections and m+1 joints. The sections are numbered 1, 2, ..., m, and the joints are numbered 0, 1, ..., m. Section i connects Joint i-1 and Joint i. The length of Section i is d_i.
 - For each section, its mode can be specified individually. There are four modes: L, R, D and U. The mode of a section decides the direction of that section. If we consider the factory as a coordinate plane, the position of Joint i will be determined as follows (we denote its coordinates as (x_i, y_i)):
 - (x_0, y_0) = (0, 0).
 - If the mode of Section i is L, (x_{i}, y_{i}) = (x_{i-1} - d_{i}, y_{i-1}).
 - If the mode of Section i is R, (x_{i}, y_{i}) = (x_{i-1} + d_{i}, y_{i-1}).
 - If the mode of Section i is D, (x_{i}, y_{i}) = (x_{i-1}, y_{i-1} - d_{i}).
 - If the mode of Section i is U, (x_{i}, y_{i}) = (x_{i-1}, y_{i-1} + d_{i}).
Snuke would like to introduce a robot arm so that the position of Joint m can be matched with all of the N points (X_1, Y_1), (X_2, Y_2), ..., (X_N, Y_N) by properly specifying the modes of the sections.
Is this possible?
If so, find such a robot arm and how to bring Joint m to each point (X_j, Y_j).

-----Constraints-----
 - All values in input are integers.
 - 1 \leq N \leq 1000
 - -10^9 \leq X_i \leq 10^9
 - -10^9 \leq Y_i \leq 10^9

-----Partial Score-----
 - In the test cases worth 300 points, -10 \leq X_i \leq 10 and -10 \leq Y_i \leq 10 hold.

-----Input-----
Input is given from Standard Input in the following format:
N
X_1 Y_1
X_2 Y_2
:
X_N Y_N

-----Output-----
If the condition can be satisfied, follow the following format. If the condition cannot be satisfied, print -1.
m
d_1 d_2 ... d_m
w_1
w_2
:
w_N

m and d_i are the configurations of the robot arm. Refer to the problem statement for what each of them means.
Here, 1 \leq m \leq 40 and 1 \leq d_i \leq 10^{12} must hold. Also, m and d_i must all be integers.
w_j is a string of length m that represents the way to bring Joint m of...

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

# -*- coding: utf-8 -*-
import math

def binary(n):
    lst = []
    while n != 0:
        lst.append(n % 2)
        n = n // 2
    lst = lst + [0] * (31 - len(lst))
    return list(reversed(lst))

def calc(u, v):
    result = ""
    u_binary = binary(u)
    v_binary = binary(v)
    for i in range(31):
        if u_binary[i] == 1 and v_binary[i] == 1:
            result += "R"
        elif u_binary[i] == 0 and v_binary[i] == 0:
            result += "L"
        elif u_binary[i] == 1 and v_binary[i] == 0:
            result += "U"
        else:
            result += "D"
    return result

U = []
V = []
N = int(input())
even, odd = 0, 0

for p in range(N):
    x, y = list(map(int, input().split()))
    U.append(x+y)
    V.append(x-y)
    if (x + y) % 2 == 0:
        even += 1
    else:
        odd += 1

if even >= 1 and odd >= 1:
    print((-1))

else:
    lst = [2 ** i for i in range(30, -1, -1)]
    if odd == 0:
        lst.append(1)
    print((len(lst)))
    print((" ".join(map(str, lst))))
    for u, v in zip(U, V):
        u = (u + 2 ** 31 - 1) // 2
        v = (v + 2 ** 31 - 1) // 2
        print((calc(u, v)+"R" if odd == 0 else calc(u, v)))


I found an interesting problem on https://atcoder.jp/contests/abc112/tasks/abc112_a:
In 2020, AtCoder Inc. with an annual sales of more than one billion yen (the currency of Japan) has started a business in programming education.

One day, there was an exam where a one-year-old child must write a program that prints Hello World, and a two-year-old child must write a program that receives integers A, B and prints A+B.

Takahashi, who is taking this exam, suddenly forgets his age.

He decides to write a program that first receives his age N (1 or 2) as input, then prints Hello World if N=1, and additionally receives integers A, B and prints A+B if N=2.

Write this program for him.

-----Constraints-----
 - N is 1 or 2.
 - A is an integer between 1 and 9 (inclusive).
 - B is an integer between 1 and 9 (inclusive).

-----Input-----
Input is given from Standard Input in one of the following formats:
1

2
A
B

-----Output-----
If N=1, print Hello World; if N=2, print A+B.

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

-----Sample Output-----
Hello World

As N=1, Takahashi is one year old. Thus, we should print Hello World.

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

n = int(input())
if n == 1:
    print('Hello World')
else:
    a = int(input())
    b = int(input())
    print(a + b)


I found an interesting problem on https://atcoder.jp/contests/abc112/tasks/abc112_b:
When Mr. X is away from home, he has decided to use his smartwatch to search the best route to go back home, to participate in ABC.
You, the smartwatch, has found N routes to his home.
If Mr. X uses the i-th of these routes, he will get home in time t_i at cost c_i.
Find the smallest cost of a route that takes not longer than time T.

-----Constraints-----
 - All values in input are integers.
 - 1 \leq N \leq 100
 - 1 \leq T \leq 1000
 - 1 \leq c_i \leq 1000
 - 1 \leq t_i \leq 1000
 - The pairs (c_i, t_i) are distinct.

-----Input-----
Input is given from Standard Input in the following format:
N T
c_1 t_1
c_2 t_2
:
c_N t_N

-----Output-----
Print the smallest cost of a route that takes not longer than time T.
If there is no route that takes not longer than time T, print TLE instead.

-----Sample Input-----
3 70
7 60
1 80
4 50

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

 - The first route gets him home at cost 7.
 - The second route takes longer than time T = 70.
 - The third route gets him home at cost 4.
Thus, the cost 4 of the third route is the minimum.

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

ans = 1001
N , T=list(map(int,input().split()))
for i in range(1,N + 1):
    c , t=list(map(int ,input().split()))
    if c <= ans and  t <= T:
        ans = c
if ans == 1001:
    print("TLE")
    return
print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc112/tasks/abc112_c:
In the Ancient Kingdom of Snuke, there was a pyramid to strengthen the authority of Takahashi, the president of AtCoder Inc.

The pyramid had center coordinates (C_X, C_Y) and height H. The altitude of coordinates (X, Y) is max(H - |X - C_X| - |Y - C_Y|, 0).
Aoki, an explorer, conducted a survey to identify the center coordinates and height of this pyramid. As a result, he obtained the following information:
 - C_X, C_Y was integers between 0 and 100 (inclusive), and H was an integer not less than 1.
 - Additionally, he obtained N pieces of information. The i-th of them is: "the altitude of point (x_i, y_i) is h_i."
This was enough to identify the center coordinates and the height of the pyramid. Find these values with the clues above.

-----Constraints-----
 - N is an integer between 1 and 100 (inclusive).
 - x_i and y_i are integers between 0 and 100 (inclusive).
 - h_i is an integer between 0 and 10^9 (inclusive).
 - The N coordinates (x_1, y_1), (x_2, y_2), (x_3, y_3), ..., (x_N, y_N) are all different.
 - The center coordinates and the height of the pyramid can be uniquely identified.

-----Input-----
Input is given from Standard Input in the following format:
N
x_1 y_1 h_1
x_2 y_2 h_2
x_3 y_3 h_3
:
x_N y_N h_N

-----Output-----
Print values C_X, C_Y and H representing the center coordinates and the height of the pyramid in one line, with spaces in between.

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

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

In this case, the center coordinates and the height can be identified as (2, 2) and 6.

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

N=int(input())
hyx=[list(map(int,input().split()))[::-1]for _ in range(N)]
R=range(101)
for X in R:
    for Y in R:
        h,y,x=max(hyx)
        H=h+abs(X-x)+abs(Y-y)
        if all(h==max(H-abs(X-x)-abs(Y-y),0)for h,y,x in hyx):
            print(X,Y,H)


I found an interesting problem on https://atcoder.jp/contests/abc112/tasks/abc112_d:
You are given integers N and M.
Consider a sequence a of length N consisting of positive integers such that a_1 + a_2 + ... + a_N = M. Find the maximum possible value of the greatest common divisor of a_1, a_2, ..., a_N.

-----Constraints-----
 - All values in input are integers.
 - 1 \leq N \leq 10^5
 - N \leq M \leq 10^9

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

-----Output-----
Print the maximum possible value of the greatest common divisor of a sequence a_1, a_2, ..., a_N that satisfies the condition.

-----Sample Input-----
3 14

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

Consider the sequence (a_1, a_2, a_3) = (2, 4, 8). Their greatest common divisor is 2, and this is the maximum value.

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

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

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

    div = make_divisors(M)
    for d in div:
        if d <= M // N:
            print(d)
            break

def __starting_point():
    resolve()

__starting_point()


I found an interesting problem on https://atcoder.jp/contests/abc113/tasks/abc113_a:
There is a train going from Station A to Station B that costs X yen (the currency of Japan).
Also, there is a bus going from Station B to Station C that costs Y yen.
Joisino got a special ticket. With this ticket, she can take the bus for half the fare if she travels from Station A to Station B by train and then travels from Station B to Station C by bus.
How much does it cost to travel from Station A to Station C if she uses this ticket?

-----Constraints-----
 - 1 \leq X,Y \leq 100
 - Y is an even number.
 - All values in input are integers.

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

-----Output-----
If it costs x yen to travel from Station A to Station C, print x.

-----Sample Input-----
81 58

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

 - The train fare is 81 yen.
 - The train fare is 58 ⁄ 2=29 yen with the 50% discount.
Thus, it costs 110 yen to travel from Station A to Station C.

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


I found an interesting problem on https://atcoder.jp/contests/abc113/tasks/abc113_b:
A country decides to build a palace.
In this country, the average temperature of a point at an elevation of x meters is T-x \times 0.006 degrees Celsius.
There are N places proposed for the place. The elevation of Place i is H_i meters.
Among them, Princess Joisino orders you to select the place whose average temperature is the closest to A degrees Celsius, and build the palace there.
Print the index of the place where the palace should be built.
It is guaranteed that the solution is unique.

-----Constraints-----
 - 1 \leq N \leq 1000
 - 0 \leq T \leq 50
 - -60 \leq A \leq T
 - 0 \leq H_i \leq 10^5
 - All values in input are integers.
 - The solution is unique.

-----Input-----
Input is given from Standard Input in the following format:
N
T A
H_1 H_2 ... H_N

-----Output-----
Print the index of the place where the palace should be built.

-----Sample Input-----
2
12 5
1000 2000

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

 - The average temperature of Place 1 is 12-1000 \times 0.006=6 degrees Celsius.
 - The average temperature of Place 2 is 12-2000 \times 0.006=0 degrees Celsius.
Thus, the palace should be built at Place 1.

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

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

s = 10000

for i in range(N):
  x = T - X[i] * 0.006
  if abs(A - x) < s:
    ans = i
    s = abs(A - x)
print((ans+1))


I found an interesting problem on https://atcoder.jp/contests/abc113/tasks/abc113_c:
In Republic of Atcoder, there are N prefectures, and a total of M cities that belong to those prefectures.
City i is established in year Y_i and belongs to Prefecture P_i.
You can assume that there are no multiple cities that are established in the same year.
It is decided to allocate a 12-digit ID number to each city.
If City i is the x-th established city among the cities that belong to Prefecture i, the first six digits of the ID number of City i is P_i, and the last six digits of the ID number is x.
Here, if P_i or x (or both) has less than six digits, zeros are added to the left until it has six digits.
Find the ID numbers for all the cities.
Note that there can be a prefecture with no cities.

-----Constraints-----
 - 1 \leq N \leq 10^5
 - 1 \leq M \leq 10^5
 - 1 \leq P_i \leq N
 - 1 \leq Y_i \leq 10^9
 - Y_i are all different.
 - All values in input are integers.

-----Input-----
Input is given from Standard Input in the following format:
N M
P_1 Y_1
:
P_M Y_M

-----Output-----
Print the ID numbers for all the cities, in ascending order of indices (City 1, City 2, ...).

-----Sample Input-----
2 3
1 32
2 63
1 12

-----Sample Output-----
000001000002
000002000001
000001000001

 - As City 1 is the second established city among the cities that belong to Prefecture 1, its ID number is 000001000002.
 - As City 2 is the first established city among the cities that belong to Prefecture 2, its ID number is 000002000001.
 - As City 3 is the first established city among the cities that belong to Prefecture 1, its ID number is 000001000001.

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

import collections
import bisect
n,m=map(int,input().split())
p=[[int(j) for j in input().split()] for i in range(m)]
a=collections.defaultdict(list)
for x,y in sorted(p):
    a[x]+=[y]
for x,y in p:
    z=bisect.bisect(a[x],y)
    print("%06d%06d"%(x,z))


I found an interesting problem on https://atcoder.jp/contests/abc113/tasks/abc113_d:
Amidakuji is a traditional method of lottery in Japan.
To make an amidakuji, we first draw W parallel vertical lines, and then draw horizontal lines that connect them. The length of each vertical line is H+1 [cm], and the endpoints of the horizontal lines must be at 1, 2, 3, ..., or H [cm] from the top of a vertical line.
A valid amidakuji is an amidakuji that satisfies the following conditions:
 - No two horizontal lines share an endpoint.
 - The two endpoints of each horizontal lines must be at the same height.
 - A horizontal line must connect adjacent vertical lines.

Find the number of the valid amidakuji that satisfy the following condition, modulo 1\ 000\ 000\ 007: if we trace the path from the top of the leftmost vertical line to the bottom, always following horizontal lines when we encounter them, we reach the bottom of the K-th vertical line from the left.
For example, in the following amidakuji, we will reach the bottom of the fourth vertical line from the left.

-----Constraints-----
 - H is an integer between 1 and 100 (inclusive).
 - W is an integer between 1 and 8 (inclusive).
 - K is an integer between 1 and W (inclusive).

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

-----Output-----
Print the number of the amidakuji that satisfy the condition, modulo 1\ 000\ 000\ 007.

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

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

Only the following one amidakuji satisfies the condition:

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


I found an interesting problem on https://atcoder.jp/contests/abc114/tasks/abc114_a:
Shichi-Go-San (literally "Seven-Five-Three") is a traditional event in a certain country to celebrate the growth of seven-, five- and three-year-old children.
Takahashi is now X years old. Will his growth be celebrated in Shichi-Go-San this time?

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

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

-----Output-----
If Takahashi's growth will be celebrated, print YES; if it will not, print NO.

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

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

The growth of a five-year-old child will be celebrated.

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

c = input()
if c in "753":
  print("YES")
else:
  print("NO")


I found an interesting problem on https://atcoder.jp/contests/abc114/tasks/abc114_b:
There is a string S consisting of digits 1, 2, ..., 9.
Lunlun, the Dachshund, will take out three consecutive digits from S, treat them as a single integer X and bring it to her master. (She cannot rearrange the digits.)
The master's favorite number is 753. The closer to this number, the better.
What is the minimum possible (absolute) difference between X and 753?

-----Constraints-----
 - S is a string of length between 4 and 10 (inclusive).
 - Each character in S is 1, 2, ..., or 9.

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

-----Output-----
Print the minimum possible difference between X and 753.

-----Sample Input-----
1234567876

-----Sample Output-----
34

Taking out the seventh to ninth characters results in X = 787, and the difference between this and 753 is 787 - 753 = 34. The difference cannot be made smaller, no matter where X is taken from.
Note that the digits cannot be rearranged. For example, taking out 567 and rearranging it to 765 is not allowed.
We cannot take out three digits that are not consecutive from S, either. For example, taking out the seventh digit 7, the ninth digit 7 and the tenth digit 6 to obtain 776 is not allowed.

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

def vax(S, num):
    nums = [999]
    index = [ i for i, x in enumerate(S) if x == str(num) and i <= len(S) - 3]
    for i in index:
        nums.append(abs(753 - int( S[i] + S[i+1] + S[i+2])))
    return min(nums)

S = list(input())
ans = 999
for i in range(10):
    ans = min(vax(S, i), ans)
print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc114/tasks/abc114_c:
You are given an integer N. Among the integers between 1 and N (inclusive), how many Shichi-Go-San numbers (literally "Seven-Five-Three numbers") are there?
Here, a Shichi-Go-San number is a positive integer that satisfies the following condition:
 - When the number is written in base ten, each of the digits 7, 5 and 3 appears at least once, and the other digits never appear.

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

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

-----Output-----
Print the number of the Shichi-Go-San numbers between 1 and N (inclusive).

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

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

There are four Shichi-Go-San numbers not greater than 575: 357, 375, 537 and 573.

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

n = int(input())
def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

if n < 357:
    print((0))
else:
    ans = 0
    for i in range(3, 10):
        for j in range(3**i):
            a = ''
            val = Base_10_to_n(j, 3).zfill(i)
            for k in val:
                if k == '1':
                    a += '3'
                elif k == '2':
                    a += '5'
                else:
                    a += '7'
            if len(set(a)) == 3 and n >= int(a):
                ans += 1
    print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc114/tasks/abc114_d:
You are given an integer N. Among the divisors of N! (= 1 \times 2 \times ... \times N), how many Shichi-Go numbers (literally "Seven-Five numbers") are there?
Here, a Shichi-Go number is a positive integer that has exactly 75 divisors.

-----Note-----
When a positive integer A divides a positive integer B, A is said to a divisor of B.
For example, 6 has four divisors: 1, 2, 3 and 6.

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

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

-----Output-----
Print the number of the Shichi-Go numbers that are divisors of N!.

-----Sample Input-----
9

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

There are no Shichi-Go numbers among the divisors of 9! = 1 \times 2 \times ... \times 9 = 362880.

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

from itertools import permutations
# 3*5*5
# (2, 4, 4) (14, 4) (2, 24) (74)
n = int(input())
d = [0] * (n + 1)
for i in range(2, n + 1):
    for p in range(2, n + 1):
        while i % p == 0:
            i //= p
            d[p] += 1
d = list(filter(int, d))
ans = 0
for i, j, k in permutations(d, 3):
    ans += min(i - 2, j - 4, k - 4) >= 0
ans //= 2
for i, j in permutations(d, 2):
    ans += min(i - 14, j - 4) >= 0
    ans += min(i - 2, j - 24) >= 0
for i in d:
    ans += i - 74 >= 0
print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc115/tasks/abc115_a:
In some other world, today is December D-th.
Write a program that prints Christmas if D = 25, Christmas Eve if D = 24, Christmas Eve Eve if D = 23 and Christmas Eve Eve Eve if D = 22.

-----Constraints-----
 - 22 \leq D \leq 25
 - D is an integer.

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

-----Output-----
Print the specified string (case-sensitive).

-----Sample Input-----
25

-----Sample Output-----
Christmas

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

d = int(input())
Eve = ' Eve'
print('Christmas'+Eve*(25-d))


I found an interesting problem on https://atcoder.jp/contests/abc115/tasks/abc115_b:
In some other world, today is the day before Christmas Eve.
Mr. Takaha is buying N items at a department store. The regular price of the i-th item (1 \leq i \leq N) is p_i yen (the currency of Japan).
He has a discount coupon, and can buy one item with the highest price for half the regular price. The remaining N-1 items cost their regular prices. What is the total amount he will pay?

-----Constraints-----
 - 2 \leq N \leq 10
 - 100 \leq p_i \leq 10000
 - p_i is an even number.

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

-----Output-----
Print the total amount Mr. Takaha will pay.

-----Sample Input-----
3
4980
7980
6980

-----Sample Output-----
15950

The 7980-yen item gets the discount and the total is 4980 + 7980 / 2 + 6980 = 15950 yen.
Note that outputs such as 15950.0 will be judged as Wrong Answer.

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

n = int(input())
p = []
for i in range(n):
    p.append(int(input()))

print(sum(p) - max(p) // 2)


I found an interesting problem on https://atcoder.jp/contests/abc115/tasks/abc115_c:
In some other world, today is Christmas Eve.
There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.
He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorated trees should be as close to each other as possible.
More specifically, let the height of the tallest decorated tree be h_{max} meters, and the height of the shortest decorated tree be h_{min} meters. The smaller the value h_{max} - h_{min} is, the better. What is the minimum possible value of h_{max} - h_{min}?

-----Constraints-----
 - 2 \leq K < N \leq 10^5
 - 1 \leq h_i \leq 10^9
 - h_i is an integer.

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

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

-----Sample Input-----
5 3
10
15
11
14
12

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

If we decorate the first, third and fifth trees, h_{max} = 12, h_{min} = 10 so h_{max} - h_{min} = 2. This is optimal.

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

n, k = list(map(int, input().split()))
h = [int(input()) for i in range(n)]
h.sort()
ans = []
for i in range(n - k + 1):
    ans.append(h[i + k - 1] - h[i])
print((min(ans)))


I found an interesting problem on https://atcoder.jp/contests/abc115/tasks/abc115_d:
In some other world, today is Christmas.
Mr. Takaha decides to make a multi-dimensional burger in his party. A level-L burger (L is an integer greater than or equal to 0) is the following thing:
 - A level-0 burger is a patty.
 - A level-L burger (L \geq 1) is a bun, a level-(L-1) burger, a patty, another level-(L-1) burger and another bun, stacked vertically in this order from the bottom.
For example, a level-1 burger and a level-2 burger look like BPPPB and BBPPPBPBPPPBB (rotated 90 degrees), where B and P stands for a bun and a patty.
The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she eat?

-----Constraints-----
 - 1 \leq N \leq 50
 - 1 \leq X \leq ( the total number of layers in a level-N burger )
 - N and X are integers.

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

-----Output-----
Print the number of patties in the bottom-most X layers from the bottom of a level-N burger.

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

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

There are 4 patties in the bottom-most 7 layers of a level-2 burger (BBPPPBPBPPPBB).

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

# 初期入力
import sys
input = sys.stdin.readline
N,X = (int(i) for i in input().split())
DP_all  =[0]*(N+1)
DP_p    =[0]*(N+1)
DP_all[0]   =1
DP_p[0]     =1

#レベル「i+1」バーガーの枚数
for i in range(N):
    DP_all[i+1] =DP_all[i] *2 +3
    DP_p[i+1]   =DP_p[i] *2  +1
#print("総枚数" ,DP_all)
#print("パティ枚数" ,DP_p)

#再帰でパティの枚数を求める L=レベル、x=食べる枚数
def  p_num(L,x):
    if x <=L:
        return 0
    if x ==DP_all[L]:
        return DP_p[L]
    elif x < DP_all[L] //2 +1:
        return p_num(L-1,x -1)
    elif x ==DP_all[L] //2 +1:
        return DP_p[L-1] +1
    elif x > DP_all[L] //2 +1:
        return DP_p[L-1] +1 +p_num(L-1,x -DP_all[L-1] -2)

ans =p_num(N,X)
print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc116/tasks/abc116_a:
There is a right triangle ABC with ∠ABC=90°.
Given the lengths of the three sides, |AB|,|BC| and |CA|, find the area of the right triangle ABC.
It is guaranteed that the area of the triangle ABC is an integer.

-----Constraints-----
 - 1 \leq |AB|,|BC|,|CA| \leq 100
 - All values in input are integers.
 - The area of the triangle ABC is an integer.

-----Input-----
Input is given from Standard Input in the following format:
|AB| |BC| |CA|

-----Output-----
Print the area of the triangle ABC.

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

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

This triangle has an area of 6.

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

ab,bc,ca = map(int, input().split())
print(ab*bc//2)


I found an interesting problem on https://atcoder.jp/contests/abc116/tasks/abc116_b:
A sequence a=\{a_1,a_2,a_3,......\} is determined as follows:
 - The first term s is given as input.
 - Let f(n) be the following function: f(n) = n/2 if n is even, and f(n) = 3n+1 if n is odd.
 - a_i = s when i = 1, and a_i = f(a_{i-1}) when i > 1.
Find the minimum integer m that satisfies the following condition:
 - There exists an integer n such that a_m = a_n (m > n).

-----Constraints-----
 - 1 \leq s \leq 100
 - All values in input are integers.
 - It is guaranteed that all elements in a and the minimum m that satisfies the condition are at most 1000000.

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

-----Output-----
Print the minimum integer m that satisfies the condition.

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

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

a=\{8,4,2,1,4,2,1,4,2,1,......\}. As a_5=a_2, the answer is 5.

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

s=int(input())
L=[]
n=1
while not s in L:
  L.append(s)
  if s%2==0:
    s//=2
  else:
    s=s*3+1
  n+=1
print(n)