I found an interesting problem on https://atcoder.jp/contests/abc042/tasks/abc042_a:
Iroha loves Haiku. Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order.
To create a Haiku, Iroha has come up with three different phrases. These phrases have A, B and C syllables, respectively. Determine whether she can construct a Haiku by using each of the phrases once, in some order.

-----Constraints-----
 - 1≦A,B,C≦10

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

-----Output-----
If it is possible to construct a Haiku by using each of the phrases once, print YES (case-sensitive). Otherwise, print NO.

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

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

Using three phrases of length 5, 5 and 7, it is possible to construct a Haiku.

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

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

if arr.count(5) == 2 and arr.count(7) == 1:
    print("YES")
else:
    print("NO")


I found an interesting problem on https://atcoder.jp/contests/abc042/tasks/arc058_a:
Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K.
She is shopping, and now paying at the cashier.
Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change).
However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money.
Find the amount of money that she will hand to the cashier.

-----Constraints-----
 -  1 ≦ N < 10000
 -  1 ≦ K < 10
 -  0 ≦ D_1 < D_2 < … < D_K≦9
 - \{D_1,D_2,...,D_K\} ≠ \{1,2,3,4,5,6,7,8,9\}

-----Input-----
The input is given from Standard Input in the following format:
N K
D_1 D_2 … D_K

-----Output-----
Print the amount of money that Iroha will hand to the cashier.

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

-----Sample Output-----
2000

She dislikes all digits except 0 and 2.
The smallest integer equal to or greater than N=1000 whose decimal notation contains only 0 and 2, is 2000.

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

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

for i in range(n, 100001):
    flg = True
    s = str(i)
    for j in range(len(s)):
        if s[j] in a:
            flg = False
            break
    if flg:
        break
print(i)


I found an interesting problem on https://atcoder.jp/contests/abc042/tasks/arc058_b:
We have a large square grid with H rows and W columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.
However, she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns. (That is, there are A×B forbidden cells.) There is no restriction on entering the other cells.
Find the number of ways she can travel to the bottom-right cell.
Since this number can be extremely large, print the number modulo 10^9+7.

-----Constraints-----
 -  1 ≦ H, W ≦ 100,000
 -  1 ≦ A < H
 -  1 ≦ B < W

-----Input-----
The input is given from Standard Input in the following format:
H W A B

-----Output-----
Print the number of ways she can travel to the bottom-right cell, modulo 10^9+7.

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

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

We have a 2×3 grid, but entering the bottom-left cell is forbidden. The number of ways to travel is two: "Right, Right, Down" and "Right, Down, Right".

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

mod = 10 ** 9 + 7
h, w, a, b = map(int, input().split())
def comb(n, r):
    if n < r:return 0
    if n < 0 or r < 0:return 0
    return fa[n] * fi[r] % mod * fi[n - r] % mod
fa = [1] * (h + w + 1)
fi = [1] * (h + w + 1)
for i in range(1, h + w + 1):
    fa[i] = fa[i - 1] * i % mod
    fi[i] = pow(fa[i], mod - 2, mod)
ans = 0
for i in range(h - a):
    ans += comb(b + i - 1, b - 1) * comb(h + w - b - i - 2, w - b - 1)
    ans %= mod
print(ans % mod)


I found an interesting problem on https://atcoder.jp/contests/abc043/tasks/abc043_a:
There are N children in AtCoder Kindergarten. Mr. Evi will arrange the children in a line, then give 1 candy to the first child in the line, 2 candies to the second child, ..., N candies to the N-th child. How many candies will be necessary in total?

-----Constraints-----
 - 1≦N≦100

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

-----Output-----
Print the necessary number of candies in total.

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

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

The answer is 1+2+3=6.

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

n=int(input())
a=0
for i in range(n+1):
  a+=i
print(a)


I found an interesting problem on https://atcoder.jp/contests/abc043/tasks/abc043_b:
Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the 0 key, the 1 key and the backspace key.
To begin with, he is using a plain text editor with this keyboard. This editor always displays one string (possibly empty). Just after the editor is launched, this string is empty. When each key on the keyboard is pressed, the following changes occur to the string:
 - The 0 key: a letter 0 will be inserted to the right of the string.
 - The 1 key: a letter 1 will be inserted to the right of the string.
 - The backspace key: if the string is empty, nothing happens. Otherwise, the rightmost letter of the string is deleted.
Sig has launched the editor, and pressed these keys several times. You are given a string s, which is a record of his keystrokes in order. In this string, the letter 0 stands for the 0 key, the letter 1 stands for the 1 key and the letter B stands for the backspace key. What string is displayed in the editor now?

-----Constraints-----
 - 1 ≦ |s| ≦ 10 (|s| denotes the length of s)
 - s consists of the letters 0, 1 and B.
 - The correct answer is not an empty string.

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

-----Output-----
Print the string displayed in the editor in the end.

-----Sample Input-----
01B0

-----Sample Output-----
00

Each time the key is pressed, the string in the editor will change as follows: 0, 01, 0, 00.

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

#!/usr/bin/env python3
s=input()
ans=[]
for i in s:
    if i=='0' or i=='1':
        ans.append(i)
    else:
        if len(ans):
            ans.pop()
print(''.join(ans))


I found an interesting problem on https://atcoder.jp/contests/abc043/tasks/arc059_a:
Evi has N integers a_1,a_2,..,a_N. His objective is to have N equal integers by transforming some of them.
He may transform each integer at most once. Transforming an integer x into another integer y costs him (x-y)^2 dollars. Even if a_i=a_j (i≠j), he has to pay the cost separately for transforming each of them (See Sample 2).
Find the minimum total cost to achieve his objective.

-----Constraints-----
 - 1≦N≦100
 - -100≦a_i≦100

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

-----Output-----
Print the minimum total cost to achieve Evi's objective.

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

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

Transforming the both into 6s will cost (4-6)^2+(8-6)^2=8 dollars, which is the minimum.

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

n=int(input())
a=list(map(int,input().split()))
# n=2
# a=[4,8]
minimum=10000000
for i in range(-100,101):
    cost=0
    for j in range(n):
        cost+=(i-(a[j]))**2
        if j==n-1:
            if cost<minimum:
                minimum=cost

print(minimum)


I found an interesting problem on https://atcoder.jp/contests/abc043/tasks/arc059_b:
Given a string t, we will call it unbalanced if and only if the length of t is at least 2, and more than half of the letters in t are the same. For example, both voodoo and melee are unbalanced, while neither noon nor a is.
You are given a string s consisting of lowercase letters. Determine if there exists a (contiguous) substring of s that is unbalanced. If the answer is positive, show a position where such a substring occurs in s.

-----Constraints-----
 - 2 ≦ |s| ≦ 10^5
 - s consists of lowercase letters.

-----Partial Score-----
 - 200 points will be awarded for passing the test set satisfying 2 ≦ N ≦ 100.

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

-----Output-----
If there exists no unbalanced substring of s, print -1 -1.
If there exists an unbalanced substring of s, let one such substring be s_a s_{a+1} ... s_{b} (1 ≦ a < b ≦ |s|), and print a b. If there exists more than one such substring, any of them will be accepted.

-----Sample Input-----
needed

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

The string s_2 s_3 s_4 s_5 = eede is unbalanced. There are also other unbalanced substrings. For example, the output 2 6 will also be accepted.

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

import sys
s = input()
n = len(s)
for i in range(n-1):
  if s[i] == s[i+1]:
    print(i+1, i+2)
    return
for i in range(n-2):
  if s[i] == s[i+2]:
    print(i+1, i+3)
    return
print(-1, -1)


I found an interesting problem on https://atcoder.jp/contests/abc044/tasks/abc044_a:
There is a hotel with the following accommodation fee:
 - X yen (the currency of Japan) per night, for the first K nights
 - Y yen per night, for the (K+1)-th and subsequent nights
Tak is staying at this hotel for N consecutive nights.
Find his total accommodation fee.

-----Constraints-----
 - 1 \leq N, K \leq 10000
 - 1 \leq Y < X \leq 10000
 - N,\,K,\,X,\,Y are integers.

-----Input-----
The input is given from Standard Input in the following format:
N
K
X
Y

-----Output-----
Print Tak's total accommodation fee.

-----Sample Input-----
5
3
10000
9000

-----Sample Output-----
48000

The accommodation fee is as follows:
 - 10000 yen for the 1-st night
 - 10000 yen for the 2-nd night
 - 10000 yen for the 3-rd night
 - 9000 yen for the 4-th night
 - 9000 yen for the 5-th night
Thus, the total is 48000 yen.

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

n = int(input())
k = int(input())
x = int(input())
y = int(input())

if n > k:
  ans = k * x + (n - k) * y

else:
  ans = n * x

print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc044/tasks/abc044_b:
Let w be a string consisting of lowercase letters.
We will call w beautiful if the following condition is satisfied:
 - Each lowercase letter of the English alphabet occurs even number of times in w.
You are given the string w. Determine if w is beautiful.

-----Constraints-----
 - 1 \leq |w| \leq 100
 - w consists of lowercase letters (a-z).

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

-----Output-----
Print Yes if w is beautiful. Print No otherwise.

-----Sample Input-----
abaccaba

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

a occurs four times, b occurs twice, c occurs twice and the other letters occur zero times.

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

import collections
w = list(input())
c = collections.Counter(w)
tmp = list(c.values())
for i in tmp:
    if i % 2 == 1:
        print("No")
        return
print("Yes")


I found an interesting problem on https://atcoder.jp/contests/abc044/tasks/arc060_a:
Tak has N cards. On the i-th (1 \leq i \leq N) card is written an integer x_i.
He is selecting one or more cards from these N cards, so that the average of the integers written on the selected cards is exactly A.
In how many ways can he make his selection?

-----Constraints-----
 - 1 \leq N \leq 50
 - 1 \leq A \leq 50
 - 1 \leq x_i \leq 50
 - N,\,A,\,x_i are integers.

-----Partial Score-----
 - 200 points will be awarded for passing the test set satisfying 1 \leq N \leq 16.

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

-----Output-----
Print the number of ways to select cards such that the average of the written integers is exactly A.

-----Sample Input-----
4 8
7 9 8 9

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

 - The following are the 5 ways to select cards such that the average is 8:
 - Select the 3-rd card.
 - Select the 1-st and 2-nd cards.
 - Select the 1-st and 4-th cards.
 - Select the 1-st, 2-nd and 3-rd cards.
 - Select the 1-st, 3-rd and 4-th cards.

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

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

dp = {0: 1}

for i in x:
    tmp = list(dp.items())
    for key, value in tmp:
        dp[key+i] = dp.get(key+i, 0) + value
print((dp[0] - 1))


I found an interesting problem on https://atcoder.jp/contests/abc045/tasks/abc045_a:
You are given a trapezoid. The lengths of its upper base, lower base, and height are a, b, and h, respectively.
An example of a trapezoid
Find the area of this trapezoid.

-----Constraints-----
 - 1≦a≦100
 - 1≦b≦100
 - 1≦h≦100
 - All input values are integers.
 - h is even.

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

-----Output-----
Print the area of the given trapezoid. It is guaranteed that the area is an integer.

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

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

When the lengths of the upper base, lower base, and height are 3, 4, and 2, respectively, the area of the trapezoid is (3+4)×2/2 = 7.

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

a=int(input())
b=int(input())
h=int(input())
print(int((a+b)*h/2))


I found an interesting problem on https://atcoder.jp/contests/abc045/tasks/abc045_b:
Alice, Bob and Charlie are playing Card Game for Three, as below:
 - At first, each of the three players has a deck consisting of some number of cards. Each card has a letter a, b or c written on it. The orders of the cards in the decks cannot be rearranged.
 - The players take turns. Alice goes first.
 - If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says a, Alice takes the next turn.)
 - If the current player's deck is empty, the game ends and the current player wins the game.
You are given the initial decks of the players.
More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way.
Determine the winner of the game.

-----Constraints-----
 - 1≦|S_A|≦100
 - 1≦|S_B|≦100
 - 1≦|S_C|≦100
 - Each letter in S_A, S_B, S_C is a, b or c.

-----Input-----
The input is given from Standard Input in the following format:
S_A
S_B
S_C

-----Output-----
If Alice will win, print A. If Bob will win, print B. If Charlie will win, print C.

-----Sample Input-----
aca
accc
ca

-----Sample Output-----
A

The game will progress as below:
 - Alice discards the top card in her deck, a. Alice takes the next turn.
 - Alice discards the top card in her deck, c. Charlie takes the next turn.
 - Charlie discards the top card in his deck, c. Charlie takes the next turn.
 - Charlie discards the top card in his deck, a. Alice takes the next turn.
 - Alice discards the top card in her deck, a. Alice takes the next turn.
 - Alice's deck is empty. The game ends and Alice wins the game.

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

d = { 'a':input(), 'b':input(), 'c':input() }
pointer = 'a'
while True:
    if 0 < len(d[pointer]):
        tmp = d[pointer][0]
        d[pointer] = d[pointer][1:]
        pointer = tmp
    else:
        print((pointer.upper()))
        break


I found an interesting problem on https://atcoder.jp/contests/abc045/tasks/arc061_a:
You are given a string S consisting of digits between 1 and 9, inclusive.
You can insert the letter + into some of the positions (possibly none) between two letters in this string.
Here, + must not occur consecutively after insertion.
All strings that can be obtained in this way can be evaluated as formulas.
Evaluate all possible formulas, and print the sum of the results.

-----Constraints-----
 - 1 \leq |S| \leq 10
 - All letters in S are digits between 1 and 9, inclusive.

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

-----Output-----
Print the sum of the evaluated value over all possible formulas.

-----Sample Input-----
125

-----Sample Output-----
176

There are 4 formulas that can be obtained: 125, 1+25, 12+5 and 1+2+5. When each formula is evaluated,
 - 125
 - 1+25=26
 - 12+5=17
 - 1+2+5=8
Thus, the sum is 125+26+17+8=176.

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

from itertools import product
s=input()
n=len(s)
ans=0
for p in product([0,1], repeat=n-1):
  wk=s[0]
  index=0
  for i in p:
    index+=1
    if i==0:
      wk+=s[index]
    else:
      ans+=int(wk)
      wk=s[index]
  if wk!="":
    ans+=int(wk)
print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc045/tasks/arc061_b:
We have a grid with H rows and W columns. At first, all cells were painted white.
Snuke painted N of these cells. The i-th ( 1 \leq i \leq N ) cell he painted is the cell at the a_i-th row and b_i-th column.
Compute the following:
 - For each integer j ( 0 \leq j \leq 9 ), how many subrectangles of size 3×3 of the grid contains exactly j black cells, after Snuke painted N cells?

-----Constraints-----
 - 3 \leq H \leq 10^9
 - 3 \leq W \leq 10^9
 - 0 \leq N \leq min(10^5,H×W)
 - 1 \leq a_i \leq H (1 \leq i \leq N)
 - 1 \leq b_i \leq W (1 \leq i \leq N)
 - (a_i, b_i) \neq (a_j, b_j) (i \neq j)

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

-----Output-----
Print 10 lines.
The (j+1)-th ( 0 \leq j \leq 9 ) line should contain the number of the subrectangles of size 3×3 of the grid that contains exactly j black cells.

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

-----Sample Output-----
0
0
0
2
4
0
0
0
0
0

There are six subrectangles of size 3×3. Two of them contain three black cells each, and the remaining four contain four black cells each.

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

H,W,N=map(int,input().split())
D=dict()
for i in range(N):
  a,b=map(int,input().split())
  for p in range(-1,2):
    for q in range(-1,2):
      x=a+p
      y=b+q
      if 2<=x<=H-1 and 2<=y<=W-1:
        pos=(x,y)
        if pos in D:
          D[pos]+=1
        else:
          D[pos]=1
ans=[0]*10
V=list(D.values())
for v in V:
  ans[v]+=1
ans[0]=(H-2)*(W-2)-sum(ans)
print(*ans,sep='\n')


I found an interesting problem on https://atcoder.jp/contests/abc046/tasks/abc046_a:
AtCoDeer the deer recently bought three paint cans.
The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c.
Here, the color of each paint can is represented by an integer between 1 and 100, inclusive.
Since he is forgetful, he might have bought more than one paint can in the same color.
Count the number of different kinds of colors of these paint cans and tell him.

-----Constraints-----
 - 1≦a,b,c≦100

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

-----Output-----
Print the number of different kinds of colors of the paint cans.

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

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

Three different colors: 1, 3, and 4.

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

a = list(input().split())
print(len(set(a)))


I found an interesting problem on https://atcoder.jp/contests/abc046/tasks/abc046_b:
There are N balls placed in a row.
AtCoDeer the deer is painting each of these in one of the K colors of his paint cans.
For aesthetic reasons, any two adjacent balls must be painted in different colors.
Find the number of the possible ways to paint the balls.

-----Constraints-----
 - 1≦N≦1000
 - 2≦K≦1000
 - The correct answer is at most 2^{31}-1.

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

-----Output-----
Print the number of the possible ways to paint the balls.

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

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

We will denote the colors by 0 and 1. There are two possible ways: we can either paint the left ball in color 0 and the right ball in color 1, or paint the left in color 1 and the right in color 0.

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

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


I found an interesting problem on https://atcoder.jp/contests/abc046/tasks/arc062_a:
AtCoDeer the deer is seeing a quick report of election results on TV.
Two candidates are standing for the election: Takahashi and Aoki.
The report shows the ratio of the current numbers of votes the two candidates have obtained, but not the actual numbers of votes.
AtCoDeer has checked the report N times, and when he checked it for the i-th (1≦i≦N) time, the ratio was T_i:A_i.
It is known that each candidate had at least one vote when he checked the report for the first time.
Find the minimum possible total number of votes obtained by the two candidates when he checked the report for the N-th time.
It can be assumed that the number of votes obtained by each candidate never decreases.

-----Constraints-----
 - 1≦N≦1000
 - 1≦T_i,A_i≦1000 (1≦i≦N)
 - T_i and A_i (1≦i≦N) are coprime.
 - It is guaranteed that the correct answer is at most 10^{18}.

-----Input-----
The input is given from Standard Input in the following format:
N
T_1 A_1
T_2 A_2
:
T_N A_N

-----Output-----
Print the minimum possible total number of votes obtained by Takahashi and Aoki when AtCoDeer checked the report for the N-th time.

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

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

When the numbers of votes obtained by the two candidates change as 2,3 → 3,3 → 6,4, the total number of votes at the end is 10, which is the minimum possible number.

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

N = int(input())
a, b = 1, 1
for i in range(N):
    x, y = map(int, input().split())
    n = max((a + x - 1) // x, (b + y - 1) // y)
    a = n * x
    b = n * y
print(a + b)


I found an interesting problem on https://atcoder.jp/contests/abc046/tasks/arc062_b:
AtCoDeer the deer and his friend TopCoDeer is playing a game.
The game consists of N turns.
In each turn, each player plays one of the two gestures, Rock and Paper, as in Rock-paper-scissors, under the following condition:
(※) After each turn, (the number of times the player has played Paper)≦(the number of times the player has played Rock).
Each player's score is calculated by (the number of turns where the player wins) - (the number of turns where the player loses), where the outcome of each turn is determined by the rules of Rock-paper-scissors.
(For those who are not familiar with Rock-paper-scissors: If one player plays Rock and the other plays Paper, the latter player will win and the former player will lose. If both players play the same gesture, the round is a tie and neither player will win nor lose.)
With his supernatural power, AtCoDeer was able to foresee the gesture that TopCoDeer will play in each of the N turns, before the game starts.
Plan AtCoDeer's gesture in each turn to maximize AtCoDeer's score.
The gesture that TopCoDeer will play in each turn is given by a string s. If the i-th (1≦i≦N) character in s is g, TopCoDeer will play Rock in the i-th turn. Similarly, if the i-th (1≦i≦N) character of s in p, TopCoDeer will play Paper in the i-th turn.

-----Constraints-----
 - 1≦N≦10^5
 - N=|s|
 - Each character in s is g or p.
 - The gestures represented by s satisfy the condition (※).

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

-----Output-----
Print the AtCoDeer's maximum possible score.

-----Sample Input-----
gpg

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

Playing the same gesture as the opponent in each turn results in the score of 0, which is the maximum possible score.

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

import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007

def main():
    S = readline().strip()

    ans = len(S) // 2 - S.count('p')

    print(ans)
    return

def __starting_point():
    main()

__starting_point()


I found an interesting problem on https://atcoder.jp/contests/abc047/tasks/abc047_a:
Two students of AtCoder Kindergarten are fighting over candy packs.
There are three candy packs, each of which contains a, b, and c candies, respectively.
Teacher Evi is trying to distribute the packs between the two students so that each student gets the same number of candies. Determine whether it is possible.
Note that Evi cannot take candies out of the packs, and the whole contents of each pack must be given to one of the students.

-----Constraints-----
 - 1 ≦ a, b, c ≦ 100

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

-----Output-----
If it is possible to distribute the packs so that each student gets the same number of candies, print Yes. Otherwise, print No.

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

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

Give the pack with 30 candies to one student, and give the two packs with 10 and 20 candies to the other. Then, each gets 30 candies.

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

a = sorted(list(map(int, input().split())))
if sum(a[:2]) == a[2]:
    print("Yes")
else:
    print("No")


I found an interesting problem on https://atcoder.jp/contests/abc047/tasks/abc047_b:
There is a rectangle in the xy-plane, with its lower left corner at (0, 0) and its upper right corner at (W, H). Each of its sides is parallel to the x-axis or y-axis. Initially, the whole region within the rectangle is painted white.
Snuke plotted N points into the rectangle. The coordinate of the i-th (1 ≦ i ≦ N) point was (x_i, y_i).
Then, he created an integer sequence a of length N, and for each 1 ≦ i ≦ N, he painted some region within the rectangle black, as follows:
 - If a_i = 1, he painted the region satisfying x < x_i within the rectangle.
 - If a_i = 2, he painted the region satisfying x > x_i within the rectangle.
 - If a_i = 3, he painted the region satisfying y < y_i within the rectangle.
 - If a_i = 4, he painted the region satisfying y > y_i within the rectangle.
Find the area of the white region within the rectangle after he finished painting.

-----Constraints-----
 - 1 ≦ W, H ≦ 100
 - 1 ≦ N ≦ 100
 - 0 ≦ x_i ≦ W (1 ≦ i ≦ N)
 - 0 ≦ y_i ≦ H (1 ≦ i ≦ N)
 - W, H (21:32, added), x_i and y_i are integers.
 - a_i (1 ≦ i ≦ N) is 1, 2, 3 or 4.

-----Input-----
The input is given from Standard Input in the following format:
W H N
x_1 y_1 a_1
x_2 y_2 a_2
:
x_N y_N a_N

-----Output-----
Print the area of the white region within the rectangle after Snuke finished painting.

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

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

The figure below shows the rectangle before Snuke starts painting.
First, as (x_1, y_1) = (2, 1) and a_1 = 1, he paints the region satisfying x < 2 within the rectangle:
Then, as (x_2, y_2) = (3, 3) and a_2 = 4, he paints the region satisfying y > 3 within the rectangle:
Now, the area of the white region within the rectangle is 9.

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

W,H,N=map(int,input().split())
l,r,b,t=0,W,0,H
for _ in range(N):
    x,y,a=map(int,input().split())
    if a==1:
        l=max(l,x)
    elif a==2:
        r=min(r,x)
    elif a==3:
        b=max(b,y)
    else:
        t=min(t,y)
if l<r and b<t:
    print((r-l)*(t-b))
else:
    print(0)


I found an interesting problem on https://atcoder.jp/contests/abc047/tasks/arc063_a:
Two foxes Jiro and Saburo are playing a game called 1D Reversi. This game is played on a board, using black and white stones. On the board, stones are placed in a row, and each player places a new stone to either end of the row. Similarly to the original game of Reversi, when a white stone is placed, all black stones between the new white stone and another white stone, turn into white stones, and vice versa.
In the middle of a game, something came up and Saburo has to leave the game. The state of the board at this point is described by a string S. There are |S| (the length of S) stones on the board, and each character in S represents the color of the i-th (1 ≦ i ≦ |S|) stone from the left. If the i-th character in S is B, it means that the color of the corresponding stone on the board is black. Similarly, if the i-th character in S is W, it means that the color of the corresponding stone is white.
Jiro wants all stones on the board to be of the same color. For this purpose, he will place new stones on the board according to the rules. Find the minimum number of new stones that he needs to place.

-----Constraints-----
 - 1 ≦ |S| ≦ 10^5
 - Each character in S is B or W.

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

-----Output-----
Print the minimum number of new stones that Jiro needs to place for his purpose.

-----Sample Input-----
BBBWW

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

By placing a new black stone to the right end of the row of stones, all white stones will become black. Also, by placing a new white stone to the left end of the row of stones, all black stones will become white.
In either way, Jiro's purpose can be achieved by placing one stone.

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

#!/usr/bin/env python3
import sys

def solve(S: str):
    from itertools import groupby
    return len(list(groupby(S))) - 1

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    print((solve(S)))

def test():
    import doctest
    doctest.testmod()

def __starting_point():
    #test()
    main()

__starting_point()


I found an interesting problem on https://atcoder.jp/contests/abc048/tasks/abc048_a:
Snuke is going to open a contest named "AtCoder s Contest".
Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.
Snuke has decided to abbreviate the name of the contest as "AxC".
Here, x is the uppercase English letter at the beginning of s.
Given the name of the contest, print the abbreviation of the name.

-----Constraints-----
 - The length of s is between 1 and 100, inclusive.
 - The first character in s is an uppercase English letter.
 - The second and subsequent characters in s are lowercase English letters.

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

-----Output-----
Print the abbreviation of the name of the contest.

-----Sample Input-----
AtCoder Beginner Contest

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

The contest in which you are participating now.

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

a, x, c = input().split()
print('A' + x[0] + 'C')


I found an interesting problem on https://atcoder.jp/contests/abc048/tasks/abc048_b:
You are given nonnegative integers a and b (a ≤ b), and a positive integer x.
Among the integers between a and b, inclusive, how many are divisible by x?

-----Constraints-----
 - 0 ≤ a ≤ b ≤ 10^{18}
 - 1 ≤ x ≤ 10^{18}

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

-----Output-----
Print the number of the integers between a and b, inclusive, that are divisible by x.

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

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

There are three integers between 4 and 8, inclusive, that are divisible by 2: 4, 6 and 8.

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

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

a_x = a // x
b_x = b // x
if a % x == 0:
    print((b_x - a_x + 1))
else:
    print((b_x - a_x))


I found an interesting problem on https://atcoder.jp/contests/abc048/tasks/arc064_a:
There are N boxes arranged in a row.
Initially, the i-th box from the left contains a_i candies.
Snuke can perform the following operation any number of times:
 - Choose a box containing at least one candy, and eat one of the candies in the chosen box.
His objective is as follows:
 - Any two neighboring boxes contain at most x candies in total.
Find the minimum number of operations required to achieve the objective.

-----Constraints-----
 - 2 ≤ N ≤ 10^5
 - 0 ≤ a_i ≤ 10^9
 - 0 ≤ x ≤ 10^9

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

-----Output-----
Print the minimum number of operations required to achieve the objective.

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

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

Eat one candy in the second box.
Then, the number of candies in each box becomes (2, 1, 2).

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

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

t = 0
ans = 0
for i in a:
  s = max(0, t+i-x) # 一つ前の値の差分を含めて、xとの差分を取得し、比較
  t = i - s
  ans += s
print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc049/tasks/abc049_a:
Given a lowercase English letter c, determine whether it is a vowel. Here, there are five vowels in the English alphabet: a, e, i, o and u.

-----Constraints-----
 - c is a lowercase English letter.

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

-----Output-----
If c is a vowel, print vowel. Otherwise, print consonant.

-----Sample Input-----
a

-----Sample Output-----
vowel

Since a is a vowel, print vowel.

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

c = str(input())

if c == 'a' or c == 'e' or c == 'i' or c == 'o' or c == 'u':
  print('vowel')

else:
  print('consonant')


I found an interesting problem on https://atcoder.jp/contests/abc049/tasks/abc049_b:
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either . or *. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}.
Extend this image vertically so that its height is doubled. That is, print a image with a height of 2H pixels and a width of W pixels where the pixel at the i-th row and j-th column is equal to C_{(i+1)/2,j} (the result of division is rounded down).

-----Constraints-----
 - 1≦H, W≦100
 - C_{i,j} is either . or *.

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

-----Output-----
Print the extended image.

-----Sample Input-----
2 2
*.
.*

-----Sample Output-----
*.
*.
.*
.*

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

H, _ = map(int, input().split())
for _ in range(H):
    row = input()
    print(row)
    print(row)


I found an interesting problem on https://atcoder.jp/contests/abc049/tasks/arc065_b:
There are N cities. There are also K roads and L railways, extending between the cities.
The i-th road bidirectionally connects the p_i-th and q_i-th cities, and the i-th railway bidirectionally connects the r_i-th and s_i-th cities.
No two roads connect the same pair of cities. Similarly, no two railways connect the same pair of cities.
We will say city A and B are connected by roads if city B is reachable from city A by traversing some number of roads. Here, any city is considered to be connected to itself by roads.
We will also define connectivity by railways similarly.
For each city, find the number of the cities connected to that city by both roads and railways.

-----Constraints-----
 - 2 ≦ N ≦ 2*10^5
 - 1 ≦ K, L≦ 10^5
 - 1 ≦ p_i, q_i, r_i, s_i ≦ N
 - p_i < q_i
 - r_i < s_i
 - When i ≠ j, (p_i, q_i) ≠ (p_j, q_j)
 - When i ≠ j, (r_i, s_i) ≠ (r_j, s_j)

-----Input-----
The input is given from Standard Input in the following format:
N K L
p_1 q_1
:
p_K q_K
r_1 s_1
:
r_L s_L

-----Output-----
Print N integers. The i-th of them should represent the number of the cities connected to the i-th city by both roads and railways.

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

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

All the four cities are connected to each other by roads.
By railways, only the second and third cities are connected. Thus, the answers for the cities are 1, 2, 2 and 1, respectively.

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

from collections import Counter

class UnionFind:
  def __init__(self, n):
    self.n = n
    self.par = [i for i in range(n)]
    self.rank = [0]*n

  def find(self, x):
    if self.par[x] == x:
      return x
    else:
      self.par[x] = self.find(self.par[x])
      return self.par[x]

  def unite(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x == y:
      return
    if self.rank[x] < self.rank[y]:
      self.par[x] = y
    else:
      self.par[y] = x
      if self.rank[x] == self.rank[y]:
        self.rank[x] += 1

  def same(self, x, y):
    return self.find(x) == self.find(y)

  def members(self, x):
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i) == root]

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

uf_pq = UnionFind(n)
uf_rs = UnionFind(n)

for p in pq:
  x, y = p
  uf_pq.unite(x-1, y-1)

for r in rs:
  x, y = r
  uf_rs.unite(x-1, y-1)

pairs = []
for i in range(n):
  pairs.append((uf_pq.find(i), uf_rs.find(i)))

count = Counter(pairs)

ans = [count[pair] for pair in pairs]
print(*ans)


I found an interesting problem on https://atcoder.jp/contests/abc050/tasks/abc050_a:
Joisino wants to evaluate the formula "A op B".
Here, A and B are integers, and the binary operator op is either + or -.
Your task is to evaluate the formula instead of her.

-----Constraints-----
 - 1≦A,B≦10^9
 - op is either + or -.

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

-----Output-----
Evaluate the formula and print the result.

-----Sample Input-----
1 + 2

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

Since 1 + 2 = 3, the output should be 3.

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

a,x,b = map(str,input().split())
if x == "+":
    print(int(a)+int(b))
else:
    print(int(a)-int(b))


I found an interesting problem on https://atcoder.jp/contests/abc050/tasks/abc050_b:
Joisino is about to compete in the final round of a certain programming competition.
In this contest, there are N problems, numbered 1 through N.
Joisino knows that it takes her T_i seconds to solve problem i(1≦i≦N).
Also, there are M kinds of drinks offered to the contestants, numbered 1 through M.
If Joisino takes drink i(1≦i≦M), her brain will be stimulated and the time it takes for her to solve problem P_i will become X_i seconds.
It does not affect the time to solve the other problems.
A contestant is allowed to take exactly one of the drinks before the start of the contest.
For each drink, Joisino wants to know how many seconds it takes her to solve all the problems if she takes that drink.
Here, assume that the time it takes her to solve all the problems is equal to the sum of the time it takes for her to solve individual problems.
Your task is to write a program to calculate it instead of her.

-----Constraints-----
 - All input values are integers.
 - 1≦N≦100
 - 1≦T_i≦10^5
 - 1≦M≦100
 - 1≦P_i≦N
 - 1≦X_i≦10^5

-----Input-----
The input is given from Standard Input in the following format:
N
T_1 T_2 ... T_N
M
P_1 X_1
P_2 X_2
:
P_M X_M

-----Output-----
For each drink, calculate how many seconds it takes Joisino to solve all the problems if she takes that drink, and print the results, one per line.

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

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

If Joisino takes drink 1, the time it takes her to solve each problem will be 1, 1 and 4 seconds, respectively, totaling 6 seconds.
If Joisino takes drink 2, the time it takes her to solve each problem will be 2, 3 and 4 seconds, respectively, totaling 9 seconds.

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

n = int(input())
t = list(map(int,input().split()))
m = int(input())
for i in range(m):
    a,b = map(int,input().split())
    T = sum(t) - t[a-1] + b
    print(T)


I found an interesting problem on https://atcoder.jp/contests/abc050/tasks/arc066_a:
There are N people, conveniently numbered 1 through N.
They were standing in a row yesterday, but now they are unsure of the order in which they were standing.
However, each person remembered the following fact: the absolute difference of the number of the people who were standing to the left of that person, and the number of the people who were standing to the right of that person.
According to their reports, the difference above for person i is A_i.
Based on these reports, find the number of the possible orders in which they were standing.
Since it can be extremely large, print the answer modulo 10^9+7.
Note that the reports may be incorrect and thus there may be no consistent order.
In such a case, print 0.

-----Constraints-----
 - 1≦N≦10^5
 - 0≦A_i≦N-1

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

-----Output-----
Print the number of the possible orders in which they were standing, modulo 10^9+7.

-----Sample Input-----
5
2 4 4 0 2

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

There are four possible orders, as follows:
 - 2,1,4,5,3
 - 2,5,4,1,3
 - 3,1,4,5,2
 - 3,5,4,1,2

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

n = int(input())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
num_map = [0] * ((n + 2 - 1) // 2)
for i in range(n):
    num_map[a[i] // 2] += 1

res = 1
if n % 2 == 1:
    if num_map[0] != 1:
        print((0))
    else:
        for i in range(1, (n + 2 - 1) // 2):
            if num_map[i] != 2:
                print((0))
                break
            else:
                res = res * 2 % mod
        else:
            print(res)
else:
    for i in range((n + 2 - 1) // 2):
        if num_map[i] != 2:
            print((0))
            break
        else:
            res = res * 2 % mod
    else:
        print(res)


I found an interesting problem on https://atcoder.jp/contests/abc050/tasks/arc066_b:
You are given a positive integer N.
Find the number of the pairs of integers u and v (0≦u,v≦N) such that there exist two non-negative integers a and b satisfying a xor b=u and a+b=v.
Here, xor denotes the bitwise exclusive OR.
Since it can be extremely large, compute the answer modulo 10^9+7.

-----Constraints-----
 - 1≦N≦10^{18}

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

-----Output-----
Print the number of the possible pairs of integers u and v, modulo 10^9+7.

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

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

The five possible pairs of u and v are:
 - u=0,v=0 (Let a=0,b=0, then 0 xor 0=0, 0+0=0.)
 - u=0,v=2 (Let a=1,b=1, then 1 xor 1=0, 1+1=2.）
 - u=1,v=1 (Let a=1,b=0, then 1 xor 0=1, 1+0=1.）
 - u=2,v=2 (Let a=2,b=0, then 2 xor 0=2, 2+0=2.）
 - u=3,v=3 (Let a=3,b=0, then 3 xor 0=3, 3+0=3.）

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

# solution

data= int(input())

array = format(data,"b")

mod = 1000000007

dynamic = [[0 for j in range(3)] for i in range(len(array)+1)]
dynamic[0][0] = 1

for i in range(len(array)):
  for j in range(3):
      for x in range(2):
        for y in range(x,2):
          b=(data>>i)&1
          dynamic[i+1][(x+y+j-b+1)//2] = (dynamic[i+1][(x+y+j-b+1)//2]+dynamic[i][j])%mod
print(dynamic[len(array)][0])


I found an interesting problem on https://atcoder.jp/contests/abc051/tasks/abc051_a:
As a New Year's gift, Dolphin received a string s of length 19.

The string s has the following format: [five lowercase English letters],[seven lowercase English letters],[five lowercase English letters].

Dolphin wants to convert the comma-separated string s into a space-separated string.

Write a program to perform the conversion for him.

-----Constraints-----
 - The length of s is 19.
 - The sixth and fourteenth characters in s are ,.
 - The other characters in s are lowercase English letters.

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

-----Output-----
Print the string after the conversion.

-----Sample Input-----
happy,newyear,enjoy

-----Sample Output-----
happy newyear enjoy

Replace all the commas in happy,newyear,enjoy with spaces to obtain happy newyear enjoy.

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


I found an interesting problem on https://atcoder.jp/contests/abc051/tasks/abc051_b:
You are given two integers K and S.

Three variable X, Y and Z takes integer values satisfying 0≤X,Y,Z≤K.

How many different assignments of values to X, Y and Z are there such that X + Y + Z = S?

-----Constraints-----
 - 2≤K≤2500
 - 0≤S≤3K
 - K and S are integers.

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

-----Output-----
Print the number of the triples of X, Y and Z that satisfy the condition.

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

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

There are six triples of X, Y and Z that satisfy the condition:
 - X = 0, Y = 0, Z = 2
 - X = 0, Y = 2, Z = 0
 - X = 2, Y = 0, Z = 0
 - X = 0, Y = 1, Z = 1
 - X = 1, Y = 0, Z = 1
 - X = 1, Y = 1, Z = 0

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

import itertools as it
# 入力の整数K, S
K, S = map(int, input().split())

counter = 0
# 3つの変数を作る
for x in range(0, K+1):
    for y in range(0, K+1):
        if K >= (S-x-y) and (S-x-y) >= 0:
            counter+=1
print(counter)


I found an interesting problem on https://atcoder.jp/contests/abc051/tasks/abc051_d:
You are given an undirected connected weighted graph with N vertices and M edges that contains neither self-loops nor double edges.

The i-th (1≤i≤M) edge connects vertex a_i and vertex b_i with a distance of c_i.

Here, a self-loop is an edge where a_i = b_i (1≤i≤M), and double edges are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M).

A connected graph is a graph where there is a path between every pair of different vertices.

Find the number of the edges that are not contained in any shortest path between any pair of different vertices.

-----Constraints-----
 - 2≤N≤100
 - N-1≤M≤min(N(N-1)/2,1000)
 - 1≤a_i,b_i≤N
 - 1≤c_i≤1000
 - c_i is an integer.
 - The given graph contains neither self-loops nor double edges.
 - The given graph is connected.

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

-----Output-----
Print the number of the edges in the graph that are not contained in any shortest path between any pair of different vertices.

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

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

In the given graph, the shortest paths between all pairs of different vertices are as follows:
 - The shortest path from vertex 1 to vertex 2 is: vertex 1 → vertex 2, with the length of 1.
 - The shortest path from vertex 1 to vertex 3 is: vertex 1 → vertex 3, with the length of 1.
 - The shortest path from vertex 2 to vertex 1 is: vertex 2 → vertex 1, with the length of 1.
 - The shortest path from vertex 2 to vertex 3 is: vertex 2 → vertex 1 → vertex 3, with the length of 2.
 - The shortest path from vertex 3 to vertex 1 is: vertex 3 → vertex 1, with the length of 1.
 - The shortest path from vertex 3 to vertex 2 is: vertex 3 → vertex 1 → vertex 2, with the length of 2.
Thus, the only edge that is not contained in any shortest path, is the edge of length 3 connecting vertex 2 and vertex 3, hence the output should be 1.

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

n, m = map(int, input().split())
graph = [[float('inf')]*n for i in range(n)]
u_s=[]
v_s=[]
w_s=[]
for _ in range(m):
    u, v, w = map(int, input().split())
    u_s.append(u-1)
    v_s.append(v-1)
    w_s.append(w)
    graph[u-1][v-1] = w
    graph[v-1][u-1] = w
for i in range(n):
    graph[i][i] = 0

def warshall_floyd(d):
    # d[i][j] : i から j への最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k]+d[k][j])
    return d

dist=warshall_floyd(graph)

ans=0
for i in range(m):
    if w_s[i]>dist[u_s[i]][v_s[i]]:
        ans+=1

print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc052/tasks/abc052_a:
There are two rectangles.
The lengths of the vertical sides of the first rectangle are A, and the lengths of the horizontal sides of the first rectangle are B.
The lengths of the vertical sides of the second rectangle are C, and the lengths of the horizontal sides of the second rectangle are D.
Print the area of the rectangle with the larger area.
If the two rectangles have equal areas, print that area.

-----Constraints-----
 - All input values are integers.
 - 1≤A≤10^4
 - 1≤B≤10^4
 - 1≤C≤10^4
 - 1≤D≤10^4

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

-----Output-----
Print the area of the rectangle with the larger area.
If the two rectangles have equal areas, print that area.

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

-----Sample Output-----
15

The first rectangle has an area of 3×5=15, and the second rectangle has an area of 2×7=14.
Thus, the output should be 15, the larger area.

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

A, B, C, D = list(map(int, input().split()))
print(max(A * B, C * D))


I found an interesting problem on https://atcoder.jp/contests/abc052/tasks/abc052_b:
You have an integer variable x.
Initially, x=0.
Some person gave you a string S of length N, and using the string you performed the following operation N times.
In the i-th operation, you incremented the value of x by 1 if S_i=I, and decremented the value of x by 1 if S_i=D.
Find the maximum value taken by x during the operations (including before the first operation, and after the last operation).

-----Constraints-----
 - 1≤N≤100
 - |S|=N
 - No characters except I and D occur in S.

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

-----Output-----
Print the maximum value taken by x during the operations.

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

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

After each operation, the value of x becomes 1, 2, 1, 2 and 1, respectively. Thus, the output should be 2, the maximum value.

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

n = int(input())
s = input()
x = 0
c = 0
for i in s:
  if i == "I":
    x += 1
  else:
    x -= 1
  c = max(x,c)
print(c)


I found an interesting problem on https://atcoder.jp/contests/abc052/tasks/arc067_a:
You are given an integer N.
Find the number of the positive divisors of N!, modulo 10^9+7.

-----Constraints-----
 - 1≤N≤10^3

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

-----Output-----
Print the number of the positive divisors of N!, modulo 10^9+7.

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

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

There are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.

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


I found an interesting problem on https://atcoder.jp/contests/abc053/tasks/abc053_a:
Smeke has decided to participate in AtCoder Beginner Contest (ABC) if his current rating is less than 1200, and participate in AtCoder Regular Contest (ARC) otherwise.
You are given Smeke's current rating, x. Print ABC if Smeke will participate in ABC, and print ARC otherwise.

-----Constraints-----
 - 1 ≦ x ≦ 3{,}000
 - x is an integer.

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

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

-----Sample Input-----
1000

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

Smeke's current rating is less than 1200, thus the output should be ABC.

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

x = int(input())

if x < 1200:
    print('ABC')
else:
    print('ARC')


I found an interesting problem on https://atcoder.jp/contests/abc053/tasks/abc053_b:
Snuke has decided to construct a string that starts with A and ends with Z, by taking out a substring of a string s (that is, a consecutive part of s).
Find the greatest length of the string Snuke can construct. Here, the test set guarantees that there always exists a substring of s that starts with A and ends with Z.

-----Constraints-----
 - 1 ≦ |s| ≦ 200{,}000
 - s consists of uppercase English letters.
 - There exists a substring of s that starts with A and ends with Z.

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

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

-----Sample Input-----
QWERTYASDFZXCV

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

By taking out the seventh through eleventh characters, it is possible to construct ASDFZ, which starts with A and ends with Z.

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

import sys
input = sys.stdin.readline

def read():
    s = input().strip()
    return s,

def solve(s):
    a, z = 0, len(s)-1
    while s[a] != "A":
        a += 1
    while s[z] != "Z":
        z -= 1
    return z-a+1

def __starting_point():
    inputs = read()
    print((solve(*inputs)))

__starting_point()


I found an interesting problem on https://atcoder.jp/contests/abc053/tasks/arc068_b:
Snuke has decided to play a game using cards.
He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written.
He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept.
Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.

-----Constraints-----
 - 3 ≦ N ≦ 10^{5}
 - N is odd.
 - 1 ≦ A_i ≦ 10^{5}
 - A_i is an integer.

-----Input-----
The input is given from Standard Input in the following format:
N
A_1 A_2 A_3 ... A_{N}

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

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

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

One optimal solution is to perform the operation once, taking out two cards with 1 and one card with 2. One card with 1 and another with 2 will be eaten, and the remaining card with 1 will be returned to deck. Then, the values written on the remaining cards in the deck will be pairwise distinct: 1, 3 and 7.

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

n = int(input())
a = list(map(int, input().split()))
num_map = dict()
for i in range(n):
    if a[i] not in num_map:
        num_map[a[i]] = 1
    else:
        num_map[a[i]] += 1

counter = 0
for key, value in list(num_map.items()):
    if value % 2 == 0:
        num_map[key] = 2
        counter += 1
    else:
        num_map[key] = 1

res = len(num_map) - counter % 2
print(res)


I found an interesting problem on https://atcoder.jp/contests/abc054/tasks/abc054_a:
Alice and Bob are playing One Card Poker.

One Card Poker is a two-player game using playing cards.
Each card in this game shows an integer between 1 and 13, inclusive.

The strength of a card is determined by the number written on it, as follows:
Weak 2 < 3 < 4 < 5 < 6 < 7 < 8 < 9 < 10 < 11 < 12 < 13 < 1 Strong
One Card Poker is played as follows:
 - Each player picks one card from the deck. The chosen card becomes the player's hand.
 - The players reveal their hands to each other. The player with the stronger card wins the game.
If their cards are equally strong, the game is drawn.
You are watching Alice and Bob playing the game, and can see their hands.

The number written on Alice's card is A, and the number written on Bob's card is B.

Write a program to determine the outcome of the game.

-----Constraints-----
 - 1≦A≦13
 - 1≦B≦13
 - A and B are integers.

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

-----Output-----
Print Alice if Alice will win. Print Bob if Bob will win. Print Draw if the game will be drawn.

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

-----Sample Output-----
Alice

8 is written on Alice's card, and 6 is written on Bob's card.
Alice has the stronger card, and thus the output should be Alice.

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

a, b = list(map(int, input().split()))
if a == 1: a = 14
if b == 1: b = 14
print(('Alice' if a > b else 'Bob' if a < b else 'Draw'))


I found an interesting problem on https://atcoder.jp/contests/abc054/tasks/abc054_b:
You are given an image A composed of N rows and N columns of pixels, and a template image B composed of M rows and M columns of pixels.

A pixel is the smallest element of an image, and in this problem it is a square of size 1×1.

Also, the given images are binary images, and the color of each pixel is either white or black.
In the input, every pixel is represented by a character: . corresponds to a white pixel, and # corresponds to a black pixel.

The image A is given as N strings A_1,...,A_N.

The j-th character in the string A_i corresponds to the pixel at the i-th row and j-th column of the image A (1≦i,j≦N).

Similarly, the template image B is given as M strings B_1,...,B_M.

The j-th character in the string B_i corresponds to the pixel at the i-th row and j-th column of the template image B (1≦i,j≦M).
Determine whether the template image B is contained in the image A when only parallel shifts can be applied to the images.

-----Constraints-----
 - 1≦M≦N≦50
 - A_i is a string of length N consisting of # and ..
 - B_i is a string of length M consisting of # and ..

-----Input-----
The input is given from Standard Input in the following format:
N M
A_1
A_2
:
A_N
B_1
B_2
:
B_M

-----Output-----
Print Yes if the template image B is contained in the image A. Print No otherwise.

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

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

The template image B is identical to the upper-left 2 × 2 subimage and the lower-right 2 × 2 subimage of A. Thus, the output should be Yes.

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

n, m = map(int, input().split())
a = [input() for _ in range(n)]
b = [input() for _ in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        ans = True
        for k in range(m):
            if b[k] != a[i+k][j:j+m]:
                ans = False
        if ans:
            print("Yes")
            return
print("No")


I found an interesting problem on https://atcoder.jp/contests/abc054/tasks/abc054_c:
You are given an undirected unweighted graph with N vertices and M edges that contains neither self-loops nor double edges.

Here, a self-loop is an edge where a_i = b_i (1≤i≤M), and double edges are two edges where (a_i,b_i)=(a_j,b_j) or (a_i,b_i)=(b_j,a_j) (1≤i<j≤M).

How many different paths start from vertex 1 and visit all the vertices exactly once?

Here, the endpoints of a path are considered visited.
For example, let us assume that the following undirected graph shown in Figure 1 is given.
Figure 1: an example of an undirected graph
The following path shown in Figure 2 satisfies the condition.
Figure 2: an example of a path that satisfies the condition
However, the following path shown in Figure 3 does not satisfy the condition, because it does not visit all the vertices.
Figure 3: an example of a path that does not satisfy the condition
Neither the following path shown in Figure 4, because it does not start from vertex 1.
Figure 4: another example of a path that does not satisfy the condition

-----Constraints-----
 - 2≦N≦8
 - 0≦M≦N(N-1)/2
 - 1≦a_i<b_i≦N
 - The given graph contains neither self-loops nor double edges.

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

-----Output-----
Print the number of the different paths that start from vertex 1 and visit all the vertices exactly once.

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

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

The given graph is shown in the following figure:
The following two paths satisfy the condition:

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

#Nはノード数、Mはエッジ数
N, M = map(int, input().split())

path_matrix = []

#無向行列の初期化
for n in range(N):
    path_matrix.append([False] * N)

#まず無向グラフを表す行列を作る
for m in range(M):
    line = map(int, input().split())
    paths = [x - 1 for x in line]
    path_matrix[paths[0]][paths[1]] = True
    path_matrix[paths[1]][paths[0]] = True

#最初はvisited、つまり訪問したことのあるノードはひとつもないので、Falseにする
visited = [False] * N

#再帰関数、ここが難しいかもしれない。
def dfs(now, depth):
    if visited[now]:
        return 0
    if depth == N - 1:
        return 1

    visited[now] = True
    total_paths = 0
    for i in range(0, N):
        if path_matrix[now][i]:
            total_paths += dfs(i, depth + 1)

    visited[now] = False

    return total_paths

print(dfs(0, 0))


I found an interesting problem on https://atcoder.jp/contests/abc054/tasks/abc054_d:
Dolphin is planning to generate a small amount of a certain chemical substance C.

In order to generate the substance C, he must prepare a solution which is a mixture of two substances A and B in the ratio of M_a:M_b.

He does not have any stock of chemicals, however, so he will purchase some chemicals at a local pharmacy.

The pharmacy sells N kinds of chemicals. For each kind of chemical, there is exactly one package of that chemical in stock.

The package of chemical i contains a_i grams of the substance A and b_i grams of the substance B, and is sold for c_i yen (the currency of Japan).

Dolphin will purchase some of these packages. For some reason, he must use all contents of the purchased packages to generate the substance C.

Find the minimum amount of money required to generate the substance C.

If it is not possible to generate the substance C by purchasing any combination of packages at the pharmacy, report that fact.

-----Constraints-----
 - 1≦N≦40
 - 1≦a_i,b_i≦10
 - 1≦c_i≦100
 - 1≦M_a,M_b≦10
 - gcd(M_a,M_b)=1
 - a_i, b_i, c_i, M_a and M_b are integers.

-----Input-----
The input is given from Standard Input in the following format:
N M_a M_b
a_1 b_1 c_1
a_2 b_2 c_2
:
a_N b_N c_N

-----Output-----
Print the minimum amount of money required to generate the substance C. If it is not possible to generate the substance C, print -1 instead.

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

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

The amount of money spent will be minimized by purchasing the packages of chemicals 1 and 2.

In this case, the mixture of the purchased chemicals will contain 3 grams of the substance A and 3 grams of the substance B, which are in the desired ratio: 3:3=1:1.

The total price of these packages is 3 yen.

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

nmax, abmax, inf = 40, 10, 1000000

dp = [[[inf] * (nmax * abmax + 1) for _ in range(nmax * abmax + 1)] for _ in range(nmax + 1)]

n, ma, mb = list(map(int, input().split()))

dp[0][0][0] = 0

for i in range(n):
  a, b, c = list(map(int, input().split()))
  dpi = dp[i]
  dpi1 = dp[i + 1]
  for ca in range(0, 401):
    for cb in range(0, 401):
      if dpi[ca][cb] == inf:
        continue
      dpi1[ca][cb] = min(dpi1[ca][cb], dpi[ca][cb])
      dpi1[ca + a][cb + b] = min(dpi1[ca + a][cb + b], dpi[ca][cb] + c)

ans = inf
dpn = dp[n]
for ca in range(1, 401):
  for cb in range(1, 401):
    if ca * mb == cb * ma:
      ans = min(ans, dpn[ca][cb])

if ans == inf:
  ans = -1

print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc055/tasks/abc055_a:
Snuke has a favorite restaurant.
The price of any meal served at the restaurant is 800 yen (the currency of Japan), and each time a customer orders 15 meals, the restaurant pays 200 yen back to the customer.
So far, Snuke has ordered N meals at the restaurant.
Let the amount of money Snuke has paid to the restaurant be x yen, and let the amount of money the restaurant has paid back to Snuke be y yen.
Find x-y.

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

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

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

-----Sample Input-----
20

-----Sample Output-----
15800

So far, Snuke has paid 16000 yen, and the restaurant has paid back 200 yen. Thus, the answer is 15800.

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


I found an interesting problem on https://atcoder.jp/contests/abc055/tasks/abc055_b:
Snuke loves working out. He is now exercising N times.
Before he starts exercising, his power is 1. After he exercises for the i-th time, his power gets multiplied by i.
Find Snuke's power after he exercises N times. Since the answer can be extremely large, print the answer modulo 10^{9}+7.

-----Constraints-----
 - 1 ≤ N ≤ 10^{5}

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

-----Output-----
Print the answer modulo 10^{9}+7.

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

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

 - After Snuke exercises for the first time, his power gets multiplied by 1 and becomes 1.
 - After Snuke exercises for the second time, his power gets multiplied by 2 and becomes 2.
 - After Snuke exercises for the third time, his power gets multiplied by 3 and becomes 6.

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

import math
n = int(input())
print(math.factorial(n) % (10**9 + 7))


I found an interesting problem on https://atcoder.jp/contests/abc055/tasks/arc069_a:
Snuke loves puzzles.
Today, he is working on a puzzle using S- and c-shaped pieces.
In this puzzle, you can combine two c-shaped pieces into one S-shaped piece, as shown in the figure below:
Snuke decided to create as many Scc groups as possible by putting together one S-shaped piece and two c-shaped pieces.
Find the maximum number of Scc groups that can be created when Snuke has N S-shaped pieces and M c-shaped pieces.

-----Constraints-----
 - 1 ≤ N,M ≤ 10^{12}

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

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

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

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

Two Scc groups can be created as follows:
 - Combine two c-shaped pieces into one S-shaped piece
 - Create two Scc groups, each from one S-shaped piece and two c-shaped pieces

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

# -*- coding: utf-8 -*-
"""
Created on Wed Sep 30 00:56:12 2020

@author: liang
"""

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

if N*2 >= M:
    print(M//2)
else:
    print( N + (M-2*N)//4)


I found an interesting problem on https://atcoder.jp/contests/abc055/tasks/arc069_b:
Snuke, who loves animals, built a zoo.
There are N animals in this zoo. They are conveniently numbered 1 through N, and arranged in a circle.
The animal numbered i (2≤i≤N-1) is adjacent to the animals numbered i-1 and i+1. Also, the animal numbered 1 is adjacent to the animals numbered 2 and N, and the animal numbered N is adjacent to the animals numbered N-1 and 1.
There are two kinds of animals in this zoo: honest sheep that only speak the truth, and lying wolves that only tell lies.
Snuke cannot tell the difference between these two species, and asked each animal the following question: "Are your neighbors of the same species?" The animal numbered i answered s_i. Here, if s_i is o, the animal said that the two neighboring animals are of the same species, and if s_i is x, the animal said that the two neighboring animals are of different species.
More formally, a sheep answered o if the two neighboring animals are both sheep or both wolves, and answered x otherwise.
Similarly, a wolf answered x if the two neighboring animals are both sheep or both wolves, and answered o otherwise.
Snuke is wondering whether there is a valid assignment of species to the animals that is consistent with these responses. If there is such an assignment, show one such assignment. Otherwise, print -1.

-----Constraints-----
 - 3 ≤ N ≤ 10^{5}
 - s is a string of length N consisting of o and x.

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

-----Output-----
If there does not exist an valid assignment that is consistent with s, print -1.
Otherwise, print an string t in the following format. The output is considered correct if the assignment described by t is consistent with s.
 - t is a string of length N consisting of S and W.
 - If t_i is S, it indicates that the animal numbered i is a sheep. If t_i is W, it indicates that the animal numbered i is a wolf.

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

-----Sample Output-----
SSSWWS

For example, if the animals numbered 1, 2, 3, 4, 5 and 6 are respectively a...

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

def abc055_d():
    n = int(input())
    s = str(input())
    ss = s[-1] + s + s[0]

    def solve(ini1, ini0):
        res = [None] * (n+2)
        res[1] = ini1
        res[0] = ini0
        for i in range(1, n+1):
            if ss[i] == 'o':
                if res[i] == 'S' and res[i-1] == 'S': res[i+1] = 'S'
                if res[i] == 'S' and res[i-1] == 'W': res[i+1] = 'W'
                if res[i] == 'W' and res[i-1] == 'S': res[i+1] = 'W'
                if res[i] == 'W' and res[i-1] == 'W': res[i+1] = 'S'
            else:
                if res[i] == 'S' and res[i-1] == 'S': res[i+1] = 'W'
                if res[i] == 'S' and res[i-1] == 'W': res[i+1] = 'S'
                if res[i] == 'W' and res[i-1] == 'S': res[i+1] = 'S'
                if res[i] == 'W' and res[i-1] == 'W': res[i+1] = 'W'
        return res

    ans = '-1'
    ini = [('S','S'), ('S','W'), ('W','S'), ('W','W')]
    for ini1, ini0 in ini:
        res = solve(ini1, ini0)
        if res[0] == res[n] and res[1] == res[n+1]:
            ans = ''.join(res[1:n+1])
            break
    print(ans)

def __starting_point():
    abc055_d()
__starting_point()


I found an interesting problem on https://atcoder.jp/contests/abc056/tasks/abc056_a:
Two deer, AtCoDeer and TopCoDeer, are playing a game called Honest or Dishonest.
In this game, an honest player always tells the truth, and an dishonest player always tell lies.
You are given two characters a and b as the input. Each of them is either H or D, and carries the following information:
If a=H, AtCoDeer is honest; if a=D, AtCoDeer is dishonest.
If b=H, AtCoDeer is saying that TopCoDeer is honest; if b=D, AtCoDeer is saying that TopCoDeer is dishonest.
Given this information, determine whether TopCoDeer is honest.

-----Constraints-----
 - a=H or a=D.
 - b=H or b=D.

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

-----Output-----
If TopCoDeer is honest, print H. If he is dishonest, print D.

-----Sample Input-----
H H

-----Sample Output-----
H

In this input, AtCoDeer is honest. Hence, as he says, TopCoDeer is honest.

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


I found an interesting problem on https://atcoder.jp/contests/abc056/tasks/abc056_b:
AtCoDeer the deer found two rectangles lying on the table, each with height 1 and width W.
If we consider the surface of the desk as a two-dimensional plane, the first rectangle covers the vertical range of [0,1] and the horizontal range of [a,a+W], and the second rectangle covers the vertical range of [1,2] and the horizontal range of [b,b+W], as shown in the following figure:

AtCoDeer will move the second rectangle horizontally so that it connects with the first rectangle.
Find the minimum distance it needs to be moved.

-----Constraints-----
 - All input values are integers.
 - 1≤W≤10^5
 - 1≤a,b≤10^5

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

-----Output-----
Print the minimum distance the second rectangle needs to be moved.

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

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

This input corresponds to the figure in the statement. In this case, the second rectangle should be moved to the left by a distance of 1.

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

w,a,c=map(int,input().split())

b=w+a
d=w+c

if a>c:
  if a>d:
    print(abs(d-a))
  else:
    print('0')

else:
  if c>b:
    print(abs(c-b))
  else:
    print('0')


I found an interesting problem on https://atcoder.jp/contests/abc056/tasks/arc070_a:
There is a kangaroo at coordinate 0 on an infinite number line that runs from left to right, at time 0.
During the period between time i-1 and time i, the kangaroo can either stay at his position, or perform a jump of length exactly i to the left or to the right.
That is, if his coordinate at time i-1 is x, he can be at coordinate x-i, x or x+i at time i.
The kangaroo's nest is at coordinate X, and he wants to travel to coordinate X as fast as possible.
Find the earliest possible time to reach coordinate X.

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

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

-----Output-----
Print the earliest possible time for the kangaroo to reach coordinate X.

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

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

The kangaroo can reach his nest at time 3 by jumping to the right three times, which is the earliest possible time.

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

import math

def goukei(n):
    return int(n*(n+1)/2)

x = int(input())
tmp = int(math.sqrt(2 * x))
#print(tmp,goukei(tmp))
while goukei(tmp)<x:
    tmp += 1

print(tmp)


I found an interesting problem on https://atcoder.jp/contests/abc056/tasks/arc070_b:
AtCoDeer the deer has N cards with positive integers written on them. The number on the i-th card (1≤i≤N) is a_i.
Because he loves big numbers, he calls a subset of the cards good when the sum of the numbers written on the cards in the subset, is K or greater.
Then, for each card i, he judges whether it is unnecessary or not, as follows:
 - If, for any good subset of the cards containing card i, the set that can be obtained by eliminating card i from the subset is also good, card i is unnecessary.
 - Otherwise, card i is NOT unnecessary.
Find the number of the unnecessary cards. Here, he judges each card independently, and he does not throw away cards that turn out to be unnecessary.

-----Constraints-----
 - All input values are integers.
 - 1≤N≤5000
 - 1≤K≤5000
 - 1≤a_i≤10^9 (1≤i≤N)

-----Partial Score-----
 - 300 points will be awarded for passing the test set satisfying N,K≤400.

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

-----Output-----
Print the number of the unnecessary cards.

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

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

There are two good sets: {2,3} and {1,2,3}.
Card 1 is only contained in {1,2,3}, and this set without card 1, {2,3}, is also good. Thus, card 1 is unnecessary.
For card 2, a good set {2,3} without card 2, {3}, is not good. Thus, card 2 is NOT unnecessary.
Neither is card 3 for a similar reason, hence the answer is 1.

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

N,K=list(map(int,input().split()))
x=[int(p) for p in input().split()]
x.sort()
x = x[::-1]
pp=0
ans=0
for a in x:
  if pp+a < K:
    pp+=a
    ans+=1
  else:
    ans=0
print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc057/tasks/abc057_a:
Dolphin loves programming contests. Today, he will take part in a contest in AtCoder.

In this country, 24-hour clock is used. For example, 9:00 p.m. is referred to as "21 o'clock".

The current time is A o'clock, and a contest will begin in exactly B hours.
When will the contest begin? Answer in 24-hour time.

-----Constraints-----
 - 0 \leq A,B \leq 23
 - A and B are integers.

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

-----Output-----
Print the hour of the starting time of the contest in 24-hour time.

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

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

In this input, the current time is 9 o'clock, and 12 hours later it will be 21 o'clock in 24-hour time.

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

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

print(((a + b) % 24))


I found an interesting problem on https://atcoder.jp/contests/abc057/tasks/abc057_b:
There are N students and M checkpoints on the xy-plane.

The coordinates of the i-th student (1 \leq i \leq N) is (a_i,b_i), and the coordinates of the checkpoint numbered j (1 \leq j \leq M) is (c_j,d_j).

When the teacher gives a signal, each student has to go to the nearest checkpoint measured in Manhattan distance.

The Manhattan distance between two points (x_1,y_1) and (x_2,y_2) is |x_1-x_2|+|y_1-y_2|.

Here, |x| denotes the absolute value of x.

If there are multiple nearest checkpoints for a student, he/she will select the checkpoint with the smallest index.

Which checkpoint will each student go to?

-----Constraints-----
 - 1 \leq N,M \leq 50
 - -10^8 \leq a_i,b_i,c_j,d_j \leq 10^8
 - All input values are integers.

-----Input-----
The input is given from Standard Input in the following format:
N M
a_1 b_1
:
a_N b_N
c_1 d_1
:
c_M d_M

-----Output-----
Print N lines.

The i-th line (1 \leq i \leq N) should contain the index of the checkpoint for the i-th student to go.

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

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

The Manhattan distance between the first student and each checkpoint is:
 - For checkpoint 1: |2-(-1)|+|0-0|=3
 - For checkpoint 2: |2-1|+|0-0|=1
The nearest checkpoint is checkpoint 2. Thus, the first line in the output should contain 2.
The Manhattan distance between the second student and each checkpoint is:
 - For checkpoint 1: |0-(-1)|+|0-0|=1
 - For checkpoint 2: |0-1|+|0-0|=1
When there are multiple nearest checkpoints, the student will go to the checkpoint with the smallest index. Thus, the second line in the output should contain 1.

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

# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)

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

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

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

def C(line):
    return [sys.stdin.readline() for _ in range(line)]

n, m = zz()
A, B = [], []
for i in range(n):
    a, b = zz()
    A.append(a)
    B.append(b)
C, D = [], []
for i in range(m):
    c, d = zz()
    C.append(c)
    D.append(d)

dist = [[0]*m for i in range(n)]
for i in range(n):
    for j in range(m):
        dist[i][j] = abs(A[i] - C[j]) + abs(B[i] - D[j])

for i in range(n):
    print((np.argmin(dist[i])+1))


I found an interesting problem on https://atcoder.jp/contests/abc057/tasks/abc057_c:
You are given an integer N.

For two positive integers A and B, we will define F(A,B) as the larger of the following: the number of digits in the decimal notation of A, and the number of digits in the decimal notation of B.

For example, F(3,11) = 2 since 3 has one digit and 11 has two digits.

Find the minimum value of F(A,B) as (A,B) ranges over all pairs of positive integers such that N = A \times B.

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

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

-----Output-----
Print the minimum value of F(A,B) as (A,B) ranges over all pairs of positive integers such that N = A \times B.

-----Sample Input-----
10000

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

F(A,B) has a minimum value of 3 at (A,B)=(100,100).

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

N=int(input())
i=1
ans=1000000000000
while i*i<=N:
    if N%i==0:
        x=i
        y=N//i
        ans=min(ans,max(len(str(x)),len(str(y))))
    i+=1
print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc057/tasks/abc057_d:
You are given N items.

The value of the i-th item (1 \leq i \leq N) is v_i.

Your have to select at least A and at most B of these items.

Under this condition, find the maximum possible arithmetic mean of the values of selected items.

Additionally, find the number of ways to select items so that the mean of the values of selected items is maximized.

-----Constraints-----
 - 1 \leq N \leq 50
 - 1 \leq A,B \leq N
 - 1 \leq v_i \leq 10^{15}
 - Each v_i is an integer.

-----Input-----
The input is given from Standard Input in the following format:
N A B
v_1
v_2
...
v_N

-----Output-----
Print two lines.

The first line should contain the maximum possible arithmetic mean of the values of selected items. The output should be considered correct if the absolute or relative error is at most 10^{-6}.

The second line should contain the number of ways to select items so that the mean of the values of selected items is maximized.

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

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

The mean of the values of selected items will be maximized when selecting the fourth and fifth items. Hence, the first line of the output should contain 4.5.

There is no other way to select items so that the mean of the values will be 4.5, and thus the second line of the output should contain 1.

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

N,A,B=list(map(int,input().split()))
l=list(map(int,input().split()))
l.sort(reverse=True)
all_n=l.count(l[0])
from scipy.special import comb
from collections import Counter
l2=l[0:A]
l_c=Counter(l)
max_mean=sum(l2)/A
l2=Counter(l2).items()
print(max_mean)
ans=1
if l[0]==l[A-1]:
   ans=0
   for i in range(A,B+1):
      ans+=comb(all_n,i,exact=True)
   print(ans)
   return
for i,j in l2:
   ans*=comb(l_c[i],j,exact=True)
print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc058/tasks/abc058_a:
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right.
We will call the arrangement of the poles beautiful if the tops of the poles lie on the same line, that is, b-a = c-b.
Determine whether the arrangement of the poles is beautiful.

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

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

-----Output-----
Print YES if the arrangement of the poles is beautiful; print NO otherwise.

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

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

Since 4-2 = 6-4, this arrangement of poles is beautiful.

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

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

print("YES" if b-a == c-b else "NO")


I found an interesting problem on https://atcoder.jp/contests/abc058/tasks/abc058_b:
Snuke signed up for a new website which holds programming competitions.
He worried that he might forget his password, and he took notes of it.
Since directly recording his password would cause him trouble if stolen,
he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions.
You are given two strings O and E. O contains the characters at the odd-numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order.
Restore the original password.

-----Constraints-----
 - O and E consists of lowercase English letters (a - z).
 - 1 \leq |O|,|E| \leq 50
 - |O| - |E| is either 0 or 1.

-----Input-----
Input is given from Standard Input in the following format:
O
E

-----Output-----
Print the original password.

-----Sample Input-----
xyz
abc

-----Sample Output-----
xaybzc

The original password is xaybzc. Extracting the characters at the odd-numbered positions results in xyz, and extracting the characters at the even-numbered positions results in abc.

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

ans = ""
O = input()
E = input()
for o, e in zip(O, E):
    ans += o + e
if len(O) > len(E):
    ans += O[-1]

print(ans)


I found an interesting problem on https://atcoder.jp/contests/abc058/tasks/arc071_a:
Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string.
He will receive a headline which contains one of the strings S_1,...,S_n tomorrow.
He is excited and already thinking of what string he will create.
Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains.
Find the longest string that can be created regardless of which string among S_1,...,S_n the headline contains.
If there are multiple such strings, find the lexicographically smallest one among them.

-----Constraints-----
 - 1 \leq n \leq 50
 - 1 \leq |S_i| \leq 50 for every i = 1, ..., n.
 - S_i consists of lowercase English letters (a - z) for every i = 1, ..., n.

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

-----Output-----
Print the lexicographically smallest string among the longest strings that satisfy the condition.
If the answer is an empty string, print an empty line.

-----Sample Input-----
3
cbaa
daacc
acacac

-----Sample Output-----
aac

The strings that can be created from each of cbaa, daacc and acacac, are aa, aac, aca, caa and so forth.
Among them, aac, aca and caa are the longest, and the lexicographically smallest of these three is aac.

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

from collections import Counter
N = int(input())

s = Counter(input())
for i in range(N-1):
    s &= Counter(input())
print((''.join(sorted(s.elements()))))


I found an interesting problem on https://atcoder.jp/contests/abc058/tasks/arc071_b:
On a two-dimensional plane, there are m lines drawn parallel to the x axis, and n lines drawn parallel to the y axis.
Among the lines parallel to the x axis, the i-th from the bottom is represented by y = y_i.
Similarly, among the lines parallel to the y axis, the i-th from the left is represented by x = x_i.
For every rectangle that is formed by these lines, find its area, and print the total area modulo 10^9+7.
That is, for every quadruple (i,j,k,l) satisfying 1\leq i < j\leq n and 1\leq k < l\leq m, find the area of the rectangle formed by the lines x=x_i, x=x_j, y=y_k and y=y_l, and print the sum of these areas modulo 10^9+7.

-----Constraints-----
 - 2 \leq n,m \leq 10^5
 - -10^9 \leq x_1 < ... < x_n \leq 10^9
 - -10^9 \leq y_1 < ... < y_m \leq 10^9
 - x_i and y_i are integers.

-----Input-----
Input is given from Standard Input in the following format:
n m
x_1 x_2 ... x_n
y_1 y_2 ... y_m

-----Output-----
Print the total area of the rectangles, modulo 10^9+7.

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

-----Sample Output-----
60

The following figure illustrates this input:

The total area of the nine rectangles A, B, ..., I shown in the following figure, is 60.

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

import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
n, m = lr()
X = np.array(lr())
Y = np.array(lr())
coef_x = np.arange(n)*2 - (n-1)
X *= coef_x
xsum = (X%MOD).sum() % MOD
coef_y = np.arange(m)*2 - (m-1)
Y *= coef_y
ysum = (Y%MOD).sum() % MOD
answer = xsum * ysum % MOD
print((answer % MOD))


I found an interesting problem on https://atcoder.jp/contests/abc059/tasks/abc059_a:
You are given three words s_1, s_2 and s_3, each composed of lowercase English letters, with spaces in between.
Print the acronym formed from the uppercased initial letters of the words.

-----Constraints-----
 - s_1, s_2 and s_3 are composed of lowercase English letters.
 - 1 ≤ |s_i| ≤ 10 (1≤i≤3)

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

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

-----Sample Input-----
atcoder beginner contest

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

The initial letters of atcoder, beginner and contest are a, b and c. Uppercase and concatenate them to obtain ABC.

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

a,b,c = input().split()

n = a[0]+b[0]+c[0]
print((n.upper()))


I found an interesting problem on https://atcoder.jp/contests/abc059/tasks/abc059_b:
You are given two positive integers A and B. Compare the magnitudes of these numbers.

-----Constraints-----
 - 1 ≤ A, B ≤ 10^{100}
 - Neither A nor B begins with a 0.

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

-----Output-----
Print GREATER if A>B, LESS if A<B and EQUAL if A=B.

-----Sample Input-----
36
24

-----Sample Output-----
GREATER

Since 36>24, print GREATER.

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

A = int(input())
B = int(input())
if A - B > 0:
  print('GREATER')
elif A - B == 0:
  print('EQUAL')
else:
  print('LESS')


I found an interesting problem on https://atcoder.jp/contests/abc059/tasks/arc072_b:
Alice and Brown loves games. Today, they will play the following game.
In this game, there are two piles initially consisting of X and Y stones, respectively.
Alice and Bob alternately perform the following operation, starting from Alice:
 - Take 2i stones from one of the piles. Then, throw away i of them, and put the remaining i in the other pile. Here, the integer i (1≤i) can be freely chosen as long as there is a sufficient number of stones in the pile.
The player who becomes unable to perform the operation, loses the game.
Given X and Y, determine the winner of the game, assuming that both players play optimally.

-----Constraints-----
 - 0 ≤ X, Y ≤ 10^{18}

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

-----Output-----
Print the winner: either Alice or Brown.

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

-----Sample Output-----
Brown

Alice can do nothing but taking two stones from the pile containing two stones. As a result, the piles consist of zero and two stones, respectively. Then, Brown will take the two stones, and the piles will consist of one and zero stones, respectively. Alice will be unable to perform the operation anymore, which means Brown's victory.

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

X, Y = list(map(int, input().split()))
if abs(X - Y) > 1:
    print('Alice')
else:
    print('Brown')


I found an interesting problem on https://atcoder.jp/contests/abc060/tasks/abc060_a:
You are given three strings A, B and C. Check whether they form a word chain.
More formally, determine whether both of the following are true:
 - The last character in A and the initial character in B are the same.
 - The last character in B and the initial character in C are the same.
If both are true, print YES. Otherwise, print NO.

-----Constraints-----
 - A, B and C are all composed of lowercase English letters (a - z).
 - 1 ≤ |A|, |B|, |C| ≤ 10, where |A|, |B| and |C| are the lengths of A, B and C, respectively.

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

-----Output-----
Print YES or NO.

-----Sample Input-----
rng gorilla apple

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

They form a word chain.

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

#60
A,B,C=input().split()
if A[-1]==B[0] and B[-1]==C[0]:
    print('YES')
else:
    print('NO')


I found an interesting problem on https://atcoder.jp/contests/abc060/tasks/abc060_b:
We ask you to select some number of positive integers, and calculate the sum of them.
It is allowed to select as many integers as you like, and as large integers as you wish.
You have to follow these, however: each selected integer needs to be a multiple of A, and you need to select at least one integer.
Your objective is to make the sum congruent to C modulo B.
Determine whether this is possible.
If the objective is achievable, print YES. Otherwise, print NO.

-----Constraints-----
 - 1 ≤ A ≤ 100
 - 1 ≤ B ≤ 100
 - 0 ≤ C < B

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

-----Output-----
Print YES or NO.

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

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

For example, if you select 7 and 14, the sum 21 is congruent to 1 modulo 5.

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

a, b, c = map(int, input().split())
res = "NO"
for i in range(1, b+1): #bで割る=余りがb個の種類出る
    if (a*i)%b == c:
        res = "YES"
        break
print(res)


I found an interesting problem on https://atcoder.jp/contests/abc060/tasks/arc073_a:
In a public bath, there is a shower which emits water for T seconds when the switch is pushed.
If the switch is pushed when the shower is already emitting water, from that moment it will be emitting water for T seconds.
Note that it does not mean that the shower emits water for T additional seconds.
N people will push the switch while passing by the shower.
The i-th person will push the switch t_i seconds after the first person pushes it.
How long will the shower emit water in total?

-----Constraints-----
 - 1 ≤ N ≤ 200,000
 - 1 ≤ T ≤ 10^9
 - 0 = t_1 < t_2 < t_3 < , ..., < t_{N-1} < t_N ≤ 10^9
 - T and each t_i are integers.

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

-----Output-----
Assume that the shower will emit water for a total of X seconds. Print X.

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

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

Three seconds after the first person pushes the water, the switch is pushed again and the shower emits water for four more seconds, for a total of seven seconds.

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

n, t = map(int, input().split())
l = list(map(int, input().split()))
total=0
for i in range(n):
    if i==n-1:# last element
        total+=t
        break
    if l[i+1]-l[i]>=t:
        total+=t
    else:
        total+=l[i+1]-l[i]
print(total)


I found an interesting problem on https://atcoder.jp/contests/abc060/tasks/arc073_b:
You have N items and a bag of strength W.
The i-th item has a weight of w_i and a value of v_i.
You will select some of the items and put them in the bag.
Here, the total weight of the selected items needs to be at most W.
Your objective is to maximize the total value of the selected items.

-----Constraints-----
 - 1 ≤ N ≤ 100
 - 1 ≤ W ≤ 10^9
 - 1 ≤ w_i ≤ 10^9
 - For each i = 2,3,...,N, w_1 ≤ w_i ≤ w_1 + 3.
 - 1 ≤ v_i ≤ 10^7
 - W, each w_i and v_i are integers.

-----Input-----
Input is given from Standard Input in the following format:
N W
w_1 v_1
w_2 v_2
:
w_N v_N

-----Output-----
Print the maximum possible total value of the selected items.

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

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

The first and third items should be selected.

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

n,w=list(map(int,input().split()))
wv=[tuple(map(int,input().split())) for i in range(n)]
wv.sort(key=lambda x:-x[1])#reverse
wv.sort(key=lambda x:x[0])

w0=wv[0][0]
x=[[0],[0],[0],[0]]
for i in range(n):
    z=wv[i][0]-w0
    k=wv[i][1]+x[z][-1]
    l=len(x[z])
    if l*wv[i][0]<=w:
        x[z].append(k)
ma=0
l3=len(x[3])
l2=len(x[2])
l1=len(x[1])
l0=len(x[0])
for i in range(l3):
    for j in range(l2):
        d=w-i*(w0+3)-j*(w0+2)
        if d>=0:
            for k in range(l1):
                d=w-i*(w0+3)-j*(w0+2)-k*(w0+1)
                if d>=0:
                    ma=max(ma,x[3][i]+x[2][j]+x[1][k]+x[0][min(d//w0,l0-1)])
                else:
                    break
        else:
            break

print(ma)


I found an interesting problem on https://atcoder.jp/contests/abc061/tasks/abc061_a:
You are given three integers A, B and C.
Determine whether C is not less than A and not greater than B.

-----Constraints-----
 - -100≤A,B,C≤100
 - A, B and C are all integers.

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

-----Output-----
If the condition is satisfied, print Yes; otherwise, print No.

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

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

C=2 is not less than A=1 and not greater than B=3, and thus the output should be Yes.

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

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

if A <= C <= B:
    print('Yes')
else:
    print('No')


I found an interesting problem on https://atcoder.jp/contests/abc061/tasks/abc061_b:
There are N cities and M roads.
The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally.
There may be more than one road that connects the same pair of two cities.
For each city, how many roads are connected to the city?

-----Constraints-----
 - 2≤N,M≤50
 - 1≤a_i,b_i≤N
 - a_i ≠ b_i
 - All input values are integers.

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

-----Output-----
Print the answer in N lines.
In the i-th line (1≤i≤N), print the number of roads connected to city i.

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

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

 - City 1 is connected to the 1-st and 3-rd roads.
 - City 2 is connected to the 1-st and 2-nd roads.
 - City 3 is connected to the 2-nd road.
 - City 4 is connected to the 3-rd road.

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

N, M = list(map(int, input().split()))
data = [[] for _ in range(N + 1)]
for i in range(M):
    x, y = list(map(int, input().split()))
    data[x].append(y)
    data[y].append(x)

for i in range(1, N + 1):
    print((len(data[i])))


I found an interesting problem on https://atcoder.jp/contests/abc061/tasks/abc061_c:
There is an empty array.
The following N operations will be performed to insert integers into the array.
In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array.
Find the K-th smallest integer in the array after the N operations.
For example, the 4-th smallest integer in the array \{1,2,2,3,3,3\} is 3.

-----Constraints-----
 - 1≤N≤10^5
 - 1≤a_i,b_i≤10^5
 - 1≤K≤b_1…+…b_n
 - All input values are integers.

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

-----Output-----
Print the K-th smallest integer in the array after the N operations.

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

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

The resulting array is the same as the one in the problem statement.

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

n, k = list(map(int, input().split()))
li = []
for i in range(n):
    temp = list(map(int, input().split()))
    li.append(temp)
#print(li)
li.sort()
#print(li)
total=0
for i in range(n):
    if i==n-1:
        #print("here")
        print((li[i][0]))
        break
    total+=li[i][1]
    if total<k:
        continue
    else:
        print((li[i][0]))
        break
    #print(i, total)