problem_id stringlengths 1 4 | problem stringlengths 69 6.83k | reasoning stringclasses 1
value | solution stringlengths 39 5.94k |
|---|---|---|---|
744 | You are given two integers A and B as the input. Output the value of A + B.
However, if A + B is 10 or greater, output error instead.
-----Constraints-----
- A and B are integers.
- 1 ≤ A, B ≤ 9
-----Input-----
Input is given from Standard Input in the following format:
A B
-----Output-----
If A + B is 10 or great... | ```python
# A - Restricted
# https://atcoder.jp/contests/abc063/tasks/abc063_a
A, B = list(map(int, input().split()))
result = A + B
if result >= 10:
print('error')
else:
print(result)
``` | |
745 | It is only six months until Christmas, and AtCoDeer the reindeer is now planning his travel to deliver gifts.
There are N houses along TopCoDeer street. The i-th house is located at coordinate a_i. He has decided to deliver gifts to all these houses.
Find the minimum distance to be traveled when AtCoDeer can start an... | ```python
N=int(input())
A=list(map(int, input().split()))
print(max(A)-min(A))
``` | |
746 | Based on some criterion, Snuke divided the integers from 1 through 12 into three groups as shown in the figure below.
Given two integers x and y (1 ≤ x < y ≤ 12), determine whether they belong to the same group.
-----Constraints-----
- x and y are integers.
- 1 ≤ x < y ≤ 12
-----Input-----
Input is given from Stand... | ```python
n1 = [1, 3, 5, 7, 8, 10, 12]
n2 = [4, 6, 9, 11]
a, b = list(map(int, input().split()))
print(("Yes" if a in n1 and b in n1 or a in n2 and b in n2 else "No"))
``` | |
747 | AtCoDeer the deer found two positive integers, a and b.
Determine whether the product of a and b is even or odd.
-----Constraints-----
- 1 ≤ a,b ≤ 10000
- a and b are integers.
-----Input-----
Input is given from Standard Input in the following format:
a b
-----Output-----
If the product is odd, print Odd; if it i... | ```python
a, b = map(int, input().split())
if a*b %2 == 0:
print("Even")
else:
print("Odd")
``` | |
748 | 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 m... | ```python
n, m = [int(x) for x in input().split()]
ans = min(n, m // 2)
ans += (m - ans * 2) // 4
print(ans)
``` | |
749 | 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 dr... | ```python
N = int(input())
T = [int(TN) for TN in input().split()]
SumT = sum(T)
M = int(input())
PX = [[] for TM in range(0,M)]
for TM in range(0,M):
PX[TM] = [int(TPX) for TPX in input().split()]
for TM in range(0,M):
print(SumT-T[PX[TM][0]-1]+PX[TM][1])
``` | |
750 | 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 pa... | ```python
import itertools
def cal(N, target_num, keta):
answer = float('inf')
for p in itertools.product(target_num, repeat=keta):
temp = 0
for i, num in enumerate(p):
temp += num * 10**i
if temp >= N:
answer = min(answer, temp)
return answer
... | |
751 | There are N observatories in AtCoder Hill, called Obs. 1, Obs. 2, ..., Obs. N. The elevation of Obs. i is H_i.
There are also M roads, each connecting two different observatories. Road j connects Obs. A_j and Obs. B_j.
Obs. i is said to be good when its elevation is higher than those of all observatories that can be re... | ```python
N,M = map(int,input().split())
high = list(map(int,input().split()))
ans = [0]*N
cnt = 0
for i in range(M):
a,b = map(int,input().split())
ans[a-1] = max(high[b-1],ans[a-1])
ans[b-1] = max(ans[b-1],high[a-1])
for j in range(N):
if ans[j] < high[j]:
cnt += 1
print(cnt)
``` | |
752 | Square1001 has seen an electric bulletin board displaying the integer 1.
He can perform the following operations A and B to change this value:
- Operation A: The displayed value is doubled.
- Operation B: The displayed value increases by K.
Square1001 needs to perform these operations N times in total.
Find the minim... | ```python
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
n = int(input())
k = int(input())
ans = 1
for i in range(n):
if ans*2 <= (ans+k):
ans *= 2
else:
ans += k
# print(ans)
print(ans)
``` | |
753 | Given is an integer x that is greater than or equal to 0, and less than or equal to 1.
Output 1 if x is equal to 0, or 0 if x is equal to 1.
-----Constraints-----
- 0 \leq x \leq 1
- x is an integer
-----Input-----
Input is given from Standard Input in the following format:
x
-----Output-----
Print 1 if x is equal... | ```python
X=int(input())
print(1-X)
``` | |
754 | 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 a... | ```python
import copy
s=input()
l=len(s)
ans=0
if l==1:
ans+=int(s)
print(ans)
else:
for i in range(2**(l-1)):
t=copy.deepcopy(s)
f=[]
ch=0
for j in range(l-1):
if ((i>>j)&1):
t=t[:j+1+ch]+'+'+t[j+1+ch:]
ch+=1
if '+' in t:
y=list(map(int,t.split('+... | |
755 | Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it.
They will share these cards.
First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards.
Here, both Snuke and Raccoon have to take at least one card.
Let the ... | ```python
import sys
import itertools
sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inl = lambda: [int(x) for x in sys.stdin.readline().split()]
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))
N = ini()
A = i... | |
756 | 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... | ```python
# 1食800円をN食食べた
N = int( input() )
x = int( 800 * N )
# 15食食べるごとに200円もらえる
y = N // 15 * 200
print( x - y )
``` | |
757 | We have a 3×3 square grid, where each square contains a lowercase English letters.
The letter in the square at the i-th row from the top and j-th column from the left is c_{ij}.
Print the string of length 3 that can be obtained by concatenating the letters in the squares on the diagonal connecting the top-left and bott... | ```python
cij = [list(input()) for _ in range(3)]
print(cij[0][0] + cij[1][1] + cij[2][2])
``` | |
758 | Snuke has a grid consisting of three squares numbered 1, 2 and 3.
In each square, either 0 or 1 is written. The number written in Square i is s_i.
Snuke will place a marble on each square that says 1.
Find the number of squares on which Snuke will place a marble.
-----Constraints-----
- Each of s_1, s_2 and s_3 is ei... | ```python
s=input()
count=0
for i in range(len(s)):
if(s[i]=="1"):
count+=1
print(count)
``` | |
759 | 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
... | ```python
N = int(input())
K = int(input())
X = int(input())
Y = int(input())
if K < N:
ans = K*X + (N-K)*Y
else:
ans = N*X
print(ans)
``` | |
760 | 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... | ```python
a, o, b = input().split()
if o == '+':
print((int(a) + int(b)))
else:
print((int(a) - int(b)))
``` | |
761 | 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
... | ```python
x = int(input())
if x < 1200:
print('ABC')
else:
print('ARC')
``` | |
762 | Snuke is buying a bicycle.
The bicycle of his choice does not come with a bell, so he has to buy one separately.
He has very high awareness of safety, and decides to buy two bells, one for each hand.
The store sells three kinds of bells for the price of a, b and c yen (the currency of Japan), respectively.
Find the min... | ```python
# A - ringring
# https://atcoder.jp/contests/abc066/tasks/abc066_a
a = list(map(int, input().split()))
a.sort()
print((a[0] + a[1]))
``` | |
763 | You are given a image with a height of H pixels and a width of W pixels.
Each pixel is represented by a lowercase English letter.
The pixel at the i-th row from the top and j-th column from the left is a_{ij}.
Put a box around this image and output the result. The box should consist of # and have a thickness of 1.
---... | ```python
H, W = map(int, input().split())
s = '#' * (W + 2)
data = []
data.append(s)
for i in range(H):
data.append('#' + str(input()) + '#')
data.append(s)
for i in range(H + 2):
print(data[i])
``` | |
764 | 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... | ```python
N = int(input())
S = input()
res = 0
tmp = 0
for s in S:
if s == 'I':
tmp += 1
elif s == 'D':
tmp -= 1
res = max(res, tmp)
print(res)
``` | |
765 | Find the number of palindromic numbers among the integers between A and B (inclusive).
Here, a palindromic number is a positive integer whose string representation in base 10 (without leading zeros) reads the same forward and backward.
-----Constraints-----
- 10000 \leq A \leq B \leq 99999
- All input values are int... | ```python
a,b = map(int,input().split())
ans = 0
for i in range(a,b+1):
c = str(i)
l = len(c)
d = l // 2
cnt = 0
for i in range(d):
if c[i] == c[-i-1]:
cnt += 1
if cnt == d:
ans += 1
print(ans)
``` | |
766 | 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... | ```python
a=list(map(int,input().split()))
print(len(set(a)))
``` | |
767 | Snuke has N sticks.
The length of the i-th stick is l_i.
Snuke is making a snake toy by joining K of the sticks together.
The length of the toy is represented by the sum of the individual sticks that compose it.
Find the maximum possible length of the toy.
-----Constraints-----
- 1 \leq K \leq N \leq 50
- 1 \leq l_i... | ```python
N,K=map(int,input().split())
l=list(map(int,input().split()))
l.sort(reverse=True)
sum=0
for i in range(K) :
sum+=l[i]
print(sum)
``` | |
768 | Snuke lives at position x on a number line.
On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery.
Snuke decided to get food delivery from the closer of stores A and B.
Find out which store is closer to Snuke's residence.
Here, the distance between two points s and t... | ```python
x, a, b = (int(x) for x in input().split())
if abs(a-x) < abs(b-x):
print("A")
else:
print("B")
``` | |
769 | On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in yyyy/mm/dd format. For example, January 23, 2018 should be written as 2018/01/23.
After finishing the document, she noticed that she had mistakenly wrote 2017 at the beginning of the date column. Wr... | ```python
s=input()
print("2018"+s[4:])
``` | |
770 | 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... | ```python
# ひっくりかえすのかとお保ったら180度反転だった
n = int(input())
d = []
for _ in range(n):
s = list(input())
d.append(s)
d = sorted(d, key=lambda dd: len(dd), reverse=True)
base = {}
for c in d[0]:
if c not in base:
base[c] = 1
else:
base[c] += 1
for s in d[1:]:
tmp = {}
for c in s:
... | |
771 | Joisino is working as a receptionist at a theater.
The theater has 100000 seats, numbered from 1 to 100000.
According to her memo, N groups of audiences have come so far, and the i-th group occupies the consecutive seats from Seat l_i to Seat r_i (inclusive).
How many people are sitting at the theater now?
-----Constr... | ```python
N = int(input())
ans = 0
for _ in range(N):
a, b = map(int, input().split())
ans += b - a + 1
print(ans)
``` | |
772 | In K-city, there are n streets running east-west, and m streets running north-south. Each street running east-west and each street running north-south cross each other. We will call the smallest area that is surrounded by four streets a block. How many blocks there are in K-city?
-----Constraints-----
- 2 ≤ n, m ≤ 10... | ```python
a, b = map(int, input().split())
print((a - 1) * (b - 1))
``` | |
773 | Snuke is giving cookies to his three goats.
He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins).
Your task is to determine whether Snuke can give cookies to his three goats so that each of them can ... | ```python
A, B = map(int, input().split())
C = A + B
print("Possible" if A%3==0 or B%3==0 or C%3==0 else "Impossible")
``` | |
774 | E869120 found a chest which is likely to contain treasure.
However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters.
He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with ?.
One more ... | ```python
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 28 02:20:36 2020
@author: liang
"""
S = input()
T = input()
S = S[::-1]
T = T[::-1]
res = list()
for i in range(len(S)-len(T)+1):
flag = True
for j in range(len(T)):
if S[i+j] == "?" or S[i+j] == T[j]:
continue
else:
... | |
775 | Takahashi is a user of a site that hosts programming contests.
When a user competes in a contest, the rating of the user (not necessarily an integer) changes according to the performance of the user, as follows:
- Let the current rating of the user be a.
- Suppose that the performance of the user in the contest is... | ```python
# 現在と目標のレーティングを取得
R = int(input())
G = int(input())
# 目標のレーティングになるためのパフォーマンスの数値を計算
Target = (G * 2) - R
# 計算結果を出力
print(Target)
``` | |
776 | You are given two segments $[l_1; r_1]$ and $[l_2; r_2]$ on the $x$-axis. It is guaranteed that $l_1 < r_1$ and $l_2 < r_2$. Segments may intersect, overlap or even coincide with each other. [Image] The example of two segments on the $x$-axis.
Your problem is to find two integers $a$ and $b$ such that $l_1 \le a \le ... | ```python
# !/usr/bin/env python3
# coding: UTF-8
# Modified: <23/Jan/2019 08:06:42 PM>
# ✪ H4WK3yE乡
# Mohd. Farhan Tahir
# Indian Institute Of Information Technology (IIIT),Gwalior
# Question Link
#
#
# ///==========Libraries, Constants and Functions=============///
import sys
inf = float("inf")
mod = 100000000... | |
777 | Given head, the head of a linked list, determine if the linked list has a cycle in it.
There is a cycle in a linked list if there is some node in the list that can be reached again by continuously following the next pointer. Internally, pos is used to denote the index of the node that tail's next pointer is connected ... | ```python
class Solution:
def hasCycle(self, head: ListNode) -> bool:
if head == None:
return False
slow = head
fast = head.next
while slow != fast:
if fast is None or fast.next is None:
return False
slow = slow.ne... | |
778 | Given an array of integers, return indices of the two numbers such that they add up to a specific target.
You may assume that each input would have exactly one solution, and you may not use the same element twice.
Example:
Given nums = [2, 7, 11, 15], target = 9,
Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1... | ```python
class Solution:
def twoSum(self, nums, target):
tmp = {}
for i in range(len(nums)):
if target - nums[i] in tmp:
return(tmp[target - nums[i]], i)
else:
tmp[nums[i]] = i;
"""
:type nums: List[int]
... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.