wrong_submission_id
stringlengths
10
10
problem_id
stringlengths
6
6
user_id
stringlengths
10
10
time_limit
float64
1k
8k
memory_limit
float64
131k
1.05M
wrong_status
stringclasses
2 values
wrong_cpu_time
float64
10
40k
wrong_memory
float64
2.94k
3.37M
wrong_code_size
int64
1
15.5k
problem_description
stringlengths
1
4.75k
wrong_code
stringlengths
1
6.92k
acc_submission_id
stringlengths
10
10
acc_status
stringclasses
1 value
acc_cpu_time
float64
10
27.8k
acc_memory
float64
2.94k
960k
acc_code_size
int64
19
14.9k
acc_code
stringlengths
19
14.9k
s157111475
p03456
u991542950
2,000
262,144
Wrong Answer
28
9,404
143
AtCoDeer the deer has found two positive integers, a and b. Determine whether the concatenation of a and b in this order is a square number.
a, b = map(int, input().split()) print(a, b) s = int(str(a) + str(b)) print(s) if int(s ** (1/2)) ** 2 == s: print("Yes") else: print("No")
s446685059
Accepted
24
9,284
123
a, b = map(int, input().split()) s = int(str(a) + str(b)) if int(s ** (1/2)) ** 2 == s: print("Yes") else: print("No")
s317282588
p03814
u312078744
2,000
262,144
Wrong Answer
17
3,512
81
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`.
s = input() num = len(s) A = s.find("A") Z = s.rfind("Z") ans = Z - A print(ans)
s149305253
Accepted
18
3,500
85
s = input() num = len(s) A = s.find("A") Z = s.rfind("Z") ans = Z - A + 1 print(ans)
s775793015
p04012
u507116804
2,000
262,144
Wrong Answer
17
2,940
149
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.
w=list(input()) s=list(set(w)) k=len(s) b=0 for i in range(k): if w.count(s[b])%2==0: print("No") else: b+=1 print("Yes")
s152221388
Accepted
17
3,060
164
w=list(input()) s=list(set(w)) k=len(s) b=0 for i in range(k): if w.count(s[b])%2!=0: print("No") break else: b+=1 if b==k: print("Yes")
s168109445
p03644
u045953894
2,000
262,144
Wrong Answer
17
2,940
89
Takahashi loves numbers divisible by 2. You are given a positive integer N. Among the integers between 1 and N (inclusive), find the one that can be divisible by 2 for the most number of times. The solution is always unique. Here, the number of times an integer can be divisible by 2, is how many times the integer can be divided by 2 without remainder. For example, * 6 can be divided by 2 once: 6 -> 3. * 8 can be divided by 2 three times: 8 -> 4 -> 2 -> 1. * 3 can be divided by 2 zero times.
n = int(input()) for i in range(7): if 2 ** i <= n: print(2 ** i) else: pass
s466478758
Accepted
17
2,940
114
n = int(input()) for i in range(7): if 2 ** i <= n < 2 ** (i+1): print(2 ** i) else: pass
s014087293
p03339
u787059958
2,000
1,048,576
Wrong Answer
432
28,572
487
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
n = int(input()) s = input() left_attention = [0 for i in range(n)] right_attention = [0 for i in range(n)] for i in range(1,n): left_attention[i]=left_attention[i-1] if(s[i-1]=='W'): left_attention[i]+=1 print(left_attention) for i in range(n-2,-1,-1): right_attention[i]=right_attention[i+1] if(s[i+1]=='E'): right_attention[i]+=1 print(right_attention) ans=n for i in range(n): ans = min(ans, left_attention[i]+right_attention[i]) print(ans)
s553261025
Accepted
372
17,872
442
n = int(input()) s = input() left_attention = [0 for i in range(n)] right_attention = [0 for i in range(n)] for i in range(1,n): left_attention[i]=left_attention[i-1] if(s[i-1]=='W'): left_attention[i]+=1 for i in range(n-2,-1,-1): right_attention[i]=right_attention[i+1] if(s[i+1]=='E'): right_attention[i]+=1 ans=n for i in range(n): ans = min(ans, left_attention[i]+right_attention[i]) print(ans)
s941060044
p02927
u193182854
2,000
1,048,576
Wrong Answer
19
3,060
231
Today is August 24, one of the five Product Days in a year. A date m-d (m is the month, d is the date) is called a Product Day when d is a two-digit number, and all of the following conditions are satisfied (here d_{10} is the tens digit of the day and d_1 is the ones digit of the day): * d_1 \geq 2 * d_{10} \geq 2 * d_1 \times d_{10} = m Takahashi wants more Product Days, and he made a new calendar called Takahashi Calendar where a year consists of M month from Month 1 to Month M, and each month consists of D days from Day 1 to Day D. In Takahashi Calendar, how many Product Days does a year have?
m, d = map(int, input().split()) c = 0 for i in range(1, m+1): for j in range(1, d+1): d1 = j%10 d10 = j//10 if d1 > 1 and d10 > 1 and (d1 * d10 == i): print(i, j) c += 1 print(c)
s484708129
Accepted
20
2,940
207
m, d = map(int, input().split()) c = 0 for i in range(1, m+1): for j in range(1, d+1): d1 = j%10 d10 = j//10 if d1 > 1 and d10 > 1 and (d1 * d10 == i): c += 1 print(c)
s116705351
p03369
u214434454
2,000
262,144
Wrong Answer
17
2,940
88
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
s = input() cnt = 0 for i in s: if s == "o": cnt += 1 print(700 + 100 * cnt)
s800098201
Accepted
17
2,940
88
s = input() cnt = 0 for i in s: if i == "o": cnt += 1 print(700 + 100 * cnt)
s590608102
p02255
u055885332
1,000
131,072
Wrong Answer
20
5,596
254
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step.
def insertionsort(n,A): for i in range(n): t=A[i] j=i-1 while j>=0 and A[j] > t: A[j+1]=A[j] j-=1 A[j+1]=t n=int(input()) A=list(map(int, input().split())) insertionsort(n,A) print(A)
s741248557
Accepted
30
5,976
342
def insertionsort(n,A): for i in range(n): t=A[i] j=i-1 while j>=0 and A[j] > t: A[j+1]=A[j] j-=1 A[j+1]=t for k in range(n): if k<n-1: print(A[k],end=" ") else: print(A[k]) n=int(input()) A=list(map(int, input().split())) insertionsort(n,A)
s395520287
p03471
u876770991
2,000
262,144
Wrong Answer
131
3,064
392
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
def calc(N, Y): for x in reversed(range(N)): if x* 10000 > Y: continue for y in reversed(range(N - x)): z= N - x- y s = z* 1000 + y* 5000 + x* 10000 if s == Y: return x, y, z elif s < Y: return -1, -1, -1 return -1, -1, -1 _N, _Y = tuple(map(int, input().split())) print(calc(_N, _Y))
s718695826
Accepted
578
3,064
343
def calc(N, Y): for x in reversed(range(N + 1)): if x* 10000 > Y: continue for y in reversed(range(N + 1 - x)): z= N - x- y s = z* 1000 + y* 5000 + x* 10000 if s == Y: return x, y, z return -1, -1, -1 _N, _Y = tuple(map(int, input().split())) print(*calc(_N, _Y))
s567755555
p03997
u309333806
2,000
262,144
Wrong Answer
40
3,064
74
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.
a = int(input()) b = int(input()) h = int(input()) print((a + b) * h / 2)
s134623367
Accepted
43
3,064
75
a = int(input()) b = int(input()) h = int(input()) print((a + b) * h // 2)
s356153697
p03485
u580093517
2,000
262,144
Wrong Answer
17
2,940
96
You are given two positive integers a and b. Let x be the average of a and b. Print x rounded up to the nearest integer.
a,b = map(int,input().split()) if a+b % 2 == 0: print((a+b)//2) else: print((a+b)//2+1)
s809442845
Accepted
17
2,940
41
print(-~sum(map(int,input().split()))//2)
s789555096
p03394
u638795007
2,000
262,144
Wrong Answer
30
5,740
1,325
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers. She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of **distinct** positive integers is called **special** if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is **not** 1. Nagase wants to find a **special** set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a **special** set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.
def examA(): N = I() ans = 0 print(ans) return def examB(): def is_prime(n): if n == 1: return False for k in range(2, int(math.sqrt(n)) + 1): if n % k == 0: return False return True N = I() ans = [(i+1)for i in range(N)] sumA = sum(ans)-N cur = N while(True): if is_prime(sumA+cur): break cur +=1 ans[-1] = cur print(" ".join(map(str,ans))) return def examC(): ans = 0 print(ans) return def examD(): ans = 0 print(ans) return def examE(): ans = 0 print(ans) return def examF(): ans = 0 print(ans) return import sys,copy,bisect,itertools,heapq,math from heapq import heappop,heappush,heapify from collections import Counter,defaultdict,deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) def LFI(): return list(map(float,sys.stdin.readline().split())) def LSI(): return list(map(str,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod,mod2,inf,alphabet mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 alphabet = [chr(ord('a') + i) for i in range(26)] if __name__ == '__main__': examB() """ """
s302280170
Accepted
30
5,744
2,065
def examA(): S = SI() N = len(S) if N<26: d = defaultdict(bool) for s in S: d[s] = True for a in alphabet: if not d[a]: ans = S + a print(ans) return keep = [] for i in range(N-1)[::-1]: keep.append(S[i+1]) if S[i]<S[i+1]: break #print(keep) n = len(keep) c = "zz" for s in keep: if s>S[(N-n-1)]: c = min(c,s) if c=="zz": print(-1) return ans = S[:(N-n-1)] + c print(ans) return def examB(): N = I() if N==3: print("2 5 63") return if N%2==0: ans = [2, 4, 3, 9] now = 4 cur = 10 else: ans = [2, 4, 3, 9] now = 4 cur = 10 while(cur<=30000): if N-1<=now: break ans.append(cur) ans.append(cur-2) cur += 6; now += 2 cur = 21 while(cur<=30000): if N-1<=now: break ans.append(cur) ans.append(cur-6) cur += 12; now += 2 for i in range(N-now): cur = (i+1)*6 ans.append(cur) print(" ".join(map(str,ans))) return def examC(): ans = 0 print(ans) return def examD(): ans = 0 print(ans) return def examE(): ans = 0 print(ans) return def examF(): ans = 0 print(ans) return import sys,copy,bisect,itertools,heapq,math from heapq import heappop,heappush,heapify from collections import Counter,defaultdict,deque def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) def LFI(): return list(map(float,sys.stdin.readline().split())) def LSI(): return list(map(str,sys.stdin.readline().split())) def LS(): return sys.stdin.readline().split() def SI(): return sys.stdin.readline().strip() global mod,mod2,inf,alphabet mod = 10**9 + 7 mod2 = 998244353 inf = 10**18 alphabet = [chr(ord('a') + i) for i in range(26)] if __name__ == '__main__': examB() """ """
s497196757
p03251
u779170803
2,000
1,048,576
Wrong Answer
18
3,064
481
Our world is one-dimensional, and ruled by two empires called Empire A and Empire B. The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y. One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control. If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out. * X < Z \leq Y * x_1, x_2, ..., x_N < Z * y_1, y_2, ..., y_M \geq Z Determine if war will break out.
INT = lambda: int(input()) INTM = lambda: map(int,input().split()) STRM = lambda: map(str,input().split()) STR = lambda: str(input()) LIST = lambda: list(map(int,input().split())) LISTS = lambda: list(map(str,input().split())) def do(): flg=0 n,m,x,y=INTM() xs=LIST() ys=LIST() xs=sorted(xs) ys=sorted(ys) if xs[-1]>=ys[0]: flg=1 if flg==0: print('No war') else: print('War') if __name__ == '__main__': do()
s478679274
Accepted
17
3,064
461
INT = lambda: int(input()) INTM = lambda: map(int,input().split()) STRM = lambda: map(str,input().split()) STR = lambda: str(input()) LIST = lambda: list(map(int,input().split())) LISTS = lambda: list(map(str,input().split())) def do(): n,m,x,y=INTM() xs=LIST() xs.append(x) ys=LIST() ys.append(y) #print(xs,ys) if max(xs)>=min(ys): print('War') else: print('No War') if __name__ == '__main__': do()
s037196713
p02694
u052838115
2,000
1,048,576
Wrong Answer
32
9,104
135
Takahashi has a deposit of 100 yen (the currency of Japan) in AtCoder Bank. The bank pays an annual interest rate of 1 % compounded annually. (A fraction of less than one yen is discarded.) Assuming that nothing other than the interest affects Takahashi's balance, in how many years does the balance reach X yen or above for the first time?
from math import floor X=int(input()) ans=100 count=0 while ans<=X: ans=ans+(ans*0.01) ans=floor(ans) count+=1 print(count)
s193340547
Accepted
28
9,032
92
X=int(input()) ans=100 count=0 while ans<X: ans=ans+(ans//100) count+=1 print(count)
s931484464
p02389
u756958775
1,000
131,072
Wrong Answer
30
7,244
69
Write a program which calculates the area and perimeter of a given rectangle.
x = list(map(float, input().split())) print(2*(x[0]+x[1], x[0]*x[1]))
s727067889
Accepted
20
7,492
67
x = list(map(int, input().split())) print(x[0]*x[1], 2*(x[0]+x[1]))
s139046203
p02420
u805716376
1,000
131,072
Wrong Answer
20
5,588
166
Your task is to shuffle a deck of n cards, each of which is marked by a alphabetical letter. A single shuffle action takes out h cards from the bottom of the deck and moves them to the top of the deck. The deck of cards is represented by a string as follows. abcdeefab The first character and the last character correspond to the card located at the bottom of the deck and the card on the top of the deck respectively. For example, a shuffle with h = 4 to the above deck, moves the first 4 characters "abcd" to the end of the remaining characters "eefab", and generates the following deck: eefababcd You can repeat such shuffle operations. Write a program which reads a deck (a string) and a sequence of h, and prints the final state (a string).
while 1: a = input() if a == '-': break n = int(input()) for i in range(n): h = int(input()) a = a[h+1:] + a[:h] print(a)
s246393668
Accepted
20
5,592
164
while 1: a = input() if a == '-': break n = int(input()) for i in range(n): h = int(input()) a = a[h:] + a[:h] print(a)
s483289580
p03400
u505420467
2,000
262,144
Wrong Answer
18
2,940
111
Some number of chocolate pieces were prepared for a training camp. The camp had N participants and lasted for D days. The i-th participant (1 \leq i \leq N) ate one chocolate piece on each of the following days in the camp: the 1-st day, the (A_i + 1)-th day, the (2A_i + 1)-th day, and so on. As a result, there were X chocolate pieces remaining at the end of the camp. During the camp, nobody except the participants ate chocolate pieces. Find the number of chocolate pieces prepared at the beginning of the camp.
n=int(input()) d,x=map(int,input().split()) ans=0 for i in range(n): ans+=(d-1)//int(input()) print(ans+x)
s692839870
Accepted
18
2,940
111
n=int(input()) d,x=map(int,input().split()) ans=n for i in range(n): ans+=(d-1)//int(input()) print(ans+x)
s644210806
p03997
u975676823
2,000
262,144
Wrong Answer
18
2,940
68
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.
a = int(input()) b = int(input()) h = int(input()) print((a+b)*h/2)
s088659721
Accepted
17
2,940
70
a = int(input()) b = int(input()) h = int(input()) print((a+b)*h//2)
s956074151
p00734
u128811851
1,000
131,072
Wrong Answer
30
6,760
1,444
Taro and Hanako have numbers of cards in their hands. Each of the cards has a score on it. Taro and Hanako wish to make the total scores of their cards equal by exchanging one card in one's hand with one card in the other's hand. Which of the cards should be exchanged with which? Note that they have to exchange their cards even if they already have cards of the same total score.
def impossible(taro_cards, hanako_cards, average): if not isinstance(average, int): return True elif sum(taro_cards) + max(taro_cards) - min(hanako_cards) < average: return True elif sum(hanako_cards) + max(hanako_cards) - min(taro_cards) < average: return True else: return False while True: n_taro, n_hanako = map(int, input().split()) if n_taro == 0 and n_hanako == 0: break taro_cards = [] hanako_cards = [] change_pairs = [] for i in range(n_taro): taro_cards.append(int(input())) for i in range(n_hanako): hanako_cards.append(int(input())) average = (sum(taro_cards) + sum(hanako_cards)) / 2 if impossible(taro_cards, hanako_cards, average): print(-1) else: # record pairs of cards to be changed for i in range(len(taro_cards)): for j in range(len(hanako_cards)): if sum(taro_cards[:i]) + sum(taro_cards[i+1:]) + hanako_cards[j] == average: change_pairs.append((taro_cards[i], hanako_cards[j])) # print("{0} {1}".format(taro_cards[i], hanako_cards[j])) # print the pair of cards to be changed pairs_leastsum = change_pairs[0] for i in range(1, len(change_pairs)): if sum(change_pairs[i]) <= sum(pairs_leastsum): pairs_leastsum = change_pairs[i] print(*pairs_leastsum)
s471895326
Accepted
80
7,272
1,550
def impossible(taro_cards, hanako_cards, average): if (sum(taro_cards) + sum(hanako_cards)) % 2 == 1: return True elif sum(taro_cards) + max(taro_cards) - min(hanako_cards) < average: return True elif sum(hanako_cards) + max(hanako_cards) - min(taro_cards) < average: return True else: return False while True: n_taro, n_hanako = map(int, input().split()) if n_taro == 0 and n_hanako == 0: break taro_cards = [] hanako_cards = [] change_pairs = [] for _ in range(n_taro): taro_cards.append(int(input())) for _ in range(n_hanako): hanako_cards.append(int(input())) average = (sum(taro_cards) + sum(hanako_cards)) // 2 if impossible(taro_cards, hanako_cards, average): print(-1) else: # record pairs of cards to be changed for i in range(len(taro_cards)): for j in range(len(hanako_cards)): if sum(taro_cards[:i]) + sum(taro_cards[i+1:]) + hanako_cards[j] == average: change_pairs.append((taro_cards[i], hanako_cards[j])) # print("{0} {1}".format(taro_cards[i], hanako_cards[j])) # print the pair of cards to be changed if change_pairs == []: print(-1) else: pairs_leastsum = change_pairs[0] for i in range(1, len(change_pairs)): if sum(change_pairs[i]) <= sum(pairs_leastsum): pairs_leastsum = change_pairs[i] print(*pairs_leastsum)
s996976507
p04044
u461636820
2,000
262,144
Wrong Answer
17
3,060
98
Iroha has a sequence of N strings S_1, S_2, ..., S_N. The length of each string is L. She will concatenate all of the strings in some order, to produce a long string. Among all strings that she can produce in this way, find the lexicographically smallest one. Here, a string s=s_1s_2s_3...s_n is _lexicographically smaller_ than another string t=t_1t_2t_3...t_m if and only if one of the following holds: * There exists an index i(1≦i≦min(n,m)), such that s_j = t_j for all indices j(1≦j<i), and s_i<t_i. * s_i = t_i for all integers i(1≦i≦min(n,m)), and n<m.
l = [] N, L = map(int, input().split()) for i in range(N): l.append(input()) print(''.join(l))
s209999042
Accepted
17
3,060
91
N, L = map(int, input().split()) s = [input() for i in range(N)] s.sort() print(''.join(s))
s772207754
p03369
u064246852
2,000
262,144
Wrong Answer
17
2,940
98
In "Takahashi-ya", a ramen restaurant, a bowl of ramen costs 700 yen (the currency of Japan), plus 100 yen for each kind of topping (boiled egg, sliced pork, green onions). A customer ordered a bowl of ramen and told which toppings to put on his ramen to a clerk. The clerk took a memo of the order as a string S. S is three characters long, and if the first character in S is `o`, it means the ramen should be topped with boiled egg; if that character is `x`, it means the ramen should not be topped with boiled egg. Similarly, the second and third characters in S mean the presence or absence of sliced pork and green onions on top of the ramen. Write a program that, when S is given, prints the price of the corresponding bowl of ramen.
line = input() ans = 700 for i in range(3): if line[i] == "○": ans += 100 print(ans)
s743962253
Accepted
17
2,940
122
line = list(input()) ans = 700 for i in range(3): if line[i] == "o" or line[i] == "○": ans += 100 print(ans)
s968287405
p02612
u652068981
2,000
1,048,576
Wrong Answer
27
9,116
74
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
import math n = int(input()) m = n % (1000 * math.ceil(n / 1000)) print(m)
s380818852
Accepted
27
9,048
25
print(-int(input())%1000)
s494245754
p02262
u533883485
6,000
131,072
Wrong Answer
30
7,668
817
Shell Sort is a generalization of [Insertion Sort](http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A) to arrange a list of $n$ elements $A$. 1 insertionSort(A, n, g) 2 for i = g to n-1 3 v = A[i] 4 j = i - g 5 while j >= 0 && A[j] > v 6 A[j+g] = A[j] 7 j = j - g 8 cnt++ 9 A[j+g] = v 10 11 shellSort(A, n) 12 cnt = 0 13 m = ? 14 G[] = {?, ?,..., ?} 15 for i = 0 to m-1 16 insertionSort(A, n, G[i]) A function shellSort(A, n) performs a function insertionSort(A, n, g), which considers every $g$-th elements. Beginning with large values of $g$, it repeats the insertion sort with smaller $g$. Your task is to complete the above program by filling ?. Write a program which reads an integer $n$ and a sequence $A$, and prints $m$, $G_i (i = 0, 1, ..., m − 1)$ in the pseudo code and the sequence $A$ in ascending order. The output of your program must meet the following requirements: * $1 \leq m \leq 100$ * $0 \leq G_i \leq n$ * cnt does not exceed $\lceil n^{1.5}\rceil$
#coding: utf-8 def print_list(X): first_flag = True for val in X: if first_flag: print_line = str(val) first_flag = False else: print_line = print_line + ' ' + str(val) print(print_line) def insertion_sort(A, n, g): global counter for i in range(g, n): tmp_val = A[i] j = i - g while (j >= 0) and (A[j] > tmp_val): A[j+g] = A[j] j -= g counter += 1 A[j+g] = tmp_val def shell_sort(A, n): global counter m = 4 G = [40, 13, 4, 1] for i in range(0, m): insertion_sort(A, n, G[i]) print(m) print_list(G) print(counter) for i in range(n): print(A[i]) n = int(input()) A = [input() for x in range(n)] counter = 0 shell_sort(A, n)
s685827261
Accepted
15,130
47,400
982
#coding: utf-8 def print_list(X): first_flag = True for val in X: if first_flag: print_line = str(val) first_flag = False else: print_line = print_line + ' ' + str(val) print(print_line) def insertion_sort(A, n, g): global counter for i in range(g, n): tmp_val = A[i] j = i - g #print("tmp_val:", tmp_val, "A:", *A) while (j >= 0) and (A[j] > tmp_val): A[j+g] = A[j] j -= g counter += 1 #print("tmp_val:", tmp_val, "A:", *A) A[j+g] = tmp_val def shell_sort(A, n): global counter G = [i for i in [262913, 65921, 16577, 4193, 1073, 281, 77, 13, 4, 1] if i <= n] m = len(G) for i in range(0, m): insertion_sort(A, n, G[i]) print(m) print(*G) print(counter) for i in range(n): print(A[i]) n = int(input()) A = [int(input()) for x in range(n)] counter = 0 shell_sort(A, n)
s149396300
p03479
u693007703
2,000
262,144
Wrong Answer
2,104
2,940
116
As a token of his gratitude, Takahashi has decided to give his mother an integer sequence. The sequence A needs to satisfy the conditions below: * A consists of integers between X and Y (inclusive). * For each 1\leq i \leq |A|-1, A_{i+1} is a multiple of A_i and strictly greater than A_i. Find the maximum possible length of the sequence.
X, Y = [int(i) for i in input().split()] output = 0 while Y >= X: X = 2 + X output += 1 print(output)
s342559184
Accepted
18
2,940
116
X, Y = [int(i) for i in input().split()] output = 0 while Y >= X: X = 2 * X output += 1 print(output)
s186125679
p03623
u027557357
2,000
262,144
Wrong Answer
17
2,940
62
Snuke lives at position x on a number line. On this line, there are two stores A and B, respectively at position a and b, that offer food for delivery. Snuke decided to get food delivery from the closer of stores A and B. Find out which store is closer to Snuke's residence. Here, the distance between two points s and t on a number line is represented by |s-t|.
x,a,b = map(int,input().split()) print(min(abs(x-a),abs(x-b)))
s048447080
Accepted
21
3,060
90
x,a,b=map(int,input().split()) if abs(x-a)>abs(x-b) : print('B') else : print('A')
s535698919
p03394
u468273690
2,000
262,144
Wrong Answer
58
4,692
670
Nagase is a top student in high school. One day, she's analyzing some properties of special sets of positive integers. She thinks that a set S = \\{a_{1}, a_{2}, ..., a_{N}\\} of **distinct** positive integers is called **special** if for all 1 \leq i \leq N, the gcd (greatest common divisor) of a_{i} and the sum of the remaining elements of S is **not** 1. Nagase wants to find a **special** set of size N. However, this task is too easy, so she decided to ramp up the difficulty. Nagase challenges you to find a **special** set of size N such that the gcd of all elements are 1 and the elements of the set does not exceed 30000.
import sys sys.setrecursionlimit(10000) def gcd(a,b): if b > 0: return gcd(b,a % b) else: return a a = [] b = [] c = [] ans = [] n = (int)(input()) for i in range(1,30001): if i % 2 != 0 and i % 3 == 0: c.append(i); for i in range(1,30001): if i % 2 == 0 and i % 3 != 0: a.append(i); for i in range(1,30001): if gcd(i,6) % 6 == 0: b.append(i); k = (int)(len(b) / 2) for i in range(0,k): if n >= 2: ans.append(b[i * 2]) ans.append(b[i * 2 + 1]) n -= 2 k = (int)(len(a) / 2) for i in range(0,k): if n >= 2: ans.append(a[i * 2]) ans.append(a[i * 2 + 1]) n -= 2 k = len(c) for i in range(0,k): if n >= 1: ans.append(c[i]) n -= 1 print(*ans)
s961855443
Accepted
46
4,704
686
a = [] b = [] c = [] ans = [] n = (int)(input()) for i in range(10,30001): if i % 2 != 0 and i % 3 == 0: a.append(i); for i in range(10,30001): if i % 2 == 0 and i % 3 != 0: b.append(i); for i in range(10,30001): if i % 6 == 0: c.append(i); b.append(8) if n >= 5: n -= 5 ans = [2,4,3,9,6] elif n == 4: n = 0 ans = [2,5,20,63] elif n == 3: n = 0 ans = [2,5,63] k = (int)(len(b) / 2) for i in range(0,k): if n >= 2: ans.append(b[i * 2]) ans.append(b[i * 2 + 1]) n -= 2 k = (int)(len(a) / 2) for i in range(0,k): if n >= 2: ans.append(a[i * 2]) ans.append(a[i * 2 + 1]) n -= 2 k = len(c) for i in range(0,k): if n >= 1: ans.append(c[i]) n -= 1 print(*ans)
s151601626
p02796
u608355135
2,000
1,048,576
Wrong Answer
444
29,264
405
In a factory, there are N robots placed on a number line. Robot i is placed at coordinate X_i and can extend its arms of length L_i in both directions, positive and negative. We want to remove zero or more robots so that the movable ranges of arms of no two remaining robots intersect. Here, for each i (1 \leq i \leq N), the movable range of arms of Robot i is the part of the number line between the coordinates X_i - L_i and X_i + L_i, excluding the endpoints. Find the maximum number of robots that we can keep.
def main(): n=int(input()) xs=[0]*n ls=[0]*n ranges=[0]*n for i in range(n): xs[i],ls[i]=map(int,input().split()) ranges[i]=[xs[i]-ls[i],xs[i]+ls[i]] ranges.sort(key=lambda x:x[1]) count=0 point=-10000 for irange in ranges: if irange[0]>=point: count+=1 point=irange[1] print(count) if __name__ == "__main__": main()
s078878262
Accepted
478
29,264
417
def main(): n=int(input()) xs=[0]*n ls=[0]*n ranges=[0]*n for i in range(n): xs[i],ls[i]=map(int,input().split()) ranges[i]=[xs[i]-ls[i],xs[i]+ls[i]] ranges.sort(key=lambda x:x[1]) count=0 point=-1000000000000 for irange in ranges: if irange[0]>=point: count+=1 point=irange[1] print(count) if __name__ == "__main__": main()
s015005911
p03501
u828139046
2,000
262,144
Wrong Answer
17
2,940
51
You are parking at a parking lot. You can choose from the following two fee plans: * Plan 1: The fee will be A×T yen (the currency of Japan) when you park for T hours. * Plan 2: The fee will be B yen, regardless of the duration. Find the minimum fee when you park for N hours.
n,a,b = map(int,input().split()) print(max(a*n,b))
s296185769
Accepted
17
2,940
51
n,a,b = map(int,input().split()) print(min(a*n,b))
s735101500
p03379
u572193732
2,000
262,144
Wrong Answer
2,104
25,744
290
When l is an odd number, the median of l numbers a_1, a_2, ..., a_l is the (\frac{l+1}{2})-th largest value among a_1, a_2, ..., a_l. You are given N numbers X_1, X_2, ..., X_N, where N is an even number. For each i = 1, 2, ..., N, let the median of X_1, X_2, ..., X_N excluding X_i, that is, the median of X_1, X_2, ..., X_{i-1}, X_{i+1}, ..., X_N be B_i. Find B_i for each i = 1, 2, ..., N.
N = int(input()) X = list(map(int, input().split())) sorted_X = sorted(X) left_med = sorted_X[N//2 -1] X_left = sorted_X[0 : N//2] right_mid = sorted_X[N//2] X_right = sorted_X[N//2 : N] for i in range(N): if X[i] in X_left: print(left_med) else: print(right_mid)
s585519239
Accepted
296
25,620
235
N = int(input()) X = list(map(int, input().split())) sorted_X = sorted(X) left_med = sorted_X[N//2 -1] right_mid = sorted_X[N//2] for i in range(N): if X[i] <= left_med: print(right_mid) else: print(left_med)
s958336383
p03795
u037221289
2,000
262,144
Wrong Answer
17
2,940
43
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.
N = int(input()) print(int(N*800- (N//15)))
s468321348
Accepted
17
2,940
48
N = int(input()) print(int(N*800- (N//15)*200))
s320509347
p03371
u875584014
2,000
262,144
Wrong Answer
29
9,200
252
"Pizza At", a fast food chain, offers three kinds of pizza: "A-pizza", "B-pizza" and "AB-pizza". A-pizza and B-pizza are completely different pizzas, and AB-pizza is one half of A-pizza and one half of B-pizza combined together. The prices of one A-pizza, B-pizza and AB-pizza are A yen, B yen and C yen (yen is the currency of Japan), respectively. Nakahashi needs to prepare X A-pizzas and Y B-pizzas for a party tonight. He can only obtain these pizzas by directly buying A-pizzas and B-pizzas, or buying two AB-pizzas and then rearrange them into one A-pizza and one B-pizza. At least how much money does he need for this? It is fine to have more pizzas than necessary by rearranging pizzas.
A,B,C,X,Y=map(int,input().split()) if A+B<2*C: ans=A*X+B*Y else: if X<=Y: ans=C*2*X if 2*C<=B: ans+=2*C*(Y-X) else: ans+=B*(Y-X) else: ans=C*2*Y if Y<=X: ans+=2*C*(X-Y) else: ans+=B*(Y-X) print(ans)
s761804939
Accepted
25
9,152
254
A,B,C,X,Y=map(int,input().split()) if A+B<2*C: ans=A*X+B*Y else: if X<=Y: ans=C*2*X if 2*C<=B: ans+=2*C*(Y-X) else: ans+=B*(Y-X) else: ans=C*2*Y if 2*C<=A: ans+=2*C*(X-Y) else: ans+=A*(X-Y) print(ans)
s238715161
p00061
u075836834
1,000
131,072
Wrong Answer
40
7,616
189
時は2020 年。パソコン甲子園 2020 の予選結果を保存したデータがあります。このデータには、各チームに振られる整理番号と正解数が保存されています。ここでは、正解数で順位を決定するものとし、正解数の多いほうから順に 1 位、2 位 ... と順位をつけていくこととします。 予選結果のデータと整理番号をキーボードから入力して、その番号のチームの順位を出力するプログラムを作成してください。
team_score=[] while True: x,y=map(int,input().split(',')) if x==y==0: break team_score.append((x,y)) team_score.sort(key=lambda x:x[1],reverse=True) for i,j in team_score: print(i)
s506801142
Accepted
20
7,660
440
def Inquiry(team): ranking=1 score=team_score[0][1] for i in team_score: if score>i[1]: ranking+=1 score=i[1] if i[0]==team: return ranking team_score=[] while True: x,y=map(int,input().split(',')) if x==y==0: break team_score.append((x,y)) #print(team_score) team_score.sort(key=lambda x:x[1],reverse=True) #print(team_score) while True: try: team=int(input()) print(Inquiry(team)) except EOFError: break
s062807534
p02612
u104405612
2,000
1,048,576
Wrong Answer
27
9,148
48
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
n = int(input()) otsuri = n % 1000 print(otsuri)
s796024714
Accepted
29
9,160
183
n = int(input()) if n >= 1000: siharai = n % 1000 if siharai == 0: print(0) else: otsuri = 1000 - siharai print(otsuri) else: otsuri = 1000 - n print(otsuri)
s829062614
p04011
u045408189
2,000
262,144
Wrong Answer
17
2,940
108
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.
n=int(input()) k=int(input()) x=int(input()) y=int(input()) if n<=k: print(n*x) else: print(n*k+(n-k)*y)
s764503959
Accepted
17
2,940
109
n=int(input()) k=int(input()) x=int(input()) y=int(input()) if n<=k: print(n*x) else: print(x*k+(n-k)*y)
s934303936
p03798
u075012704
2,000
262,144
Wrong Answer
46
6,180
417
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`.
N = int(input()) s = list(input()) check_SW = True X = ["S"] for i in range(1,N): if check_SW: if s[i-1] == "o": X.append("S") check_SW = True else: X.append("W") check_SW = False else: if s[i-1] =="×": X.append("S") check_SW = False else: X.append("W") check_SW = True print(X)
s523550062
Accepted
282
14,736
579
N = int(input()) S = input().replace('o', '0').replace('x', '1') S = list(map(int, S)) for pattern in [[0, 0], [0, 1], [1, 0], [1, 1]]: for s in S[1:]: if pattern[-2] ^ pattern[-1] ^ s == 0: pattern.append(0) else: pattern.append(1) pattern = pattern[:-1] for i, s in enumerate(S): if pattern[i - 1] ^ pattern[(i + 1) % N] ^ s != pattern[i]: break else: pattern = ''.join(map(str, pattern)).replace('0', 'S').replace('1', 'W') print(*pattern, sep='') break else: print(-1)
s899400780
p02612
u737670214
2,000
1,048,576
Wrong Answer
29
9,112
32
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N = int(input()) print(N % 1000)
s412181921
Accepted
29
9,104
93
N = int(input()) mod1 = N % 1000 if mod1 != 0 : print(1000-mod1) else: print(0)
s390041199
p00435
u436259757
1,000
131,072
Wrong Answer
20
5,552
178
ガイウス・ユリウス・カエサル(Gaius Julius Caesar),英語読みでジュリアス・シーザー(Julius Caesar)は,古代ローマの軍人であり政治家である.カエサルは,秘密の手紙を書くときに, 'A' を 'D' に, 'B' を 'E' に, 'C' を 'F' に,というように3つずらして表記したという記録が残っている. 大文字のアルファベット26文字だけからなる文字列を,カエサルがしたように3文字ずつずらす変換を施し得られた文字列がある.このような文字列を元の文字列に戻すプログラムを作成せよ. 各文字の変換前と変換後の対応は次のようになる. 変換前 | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z ---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|--- 変換後 | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | A | B | C 例えば,この方法で文字列 JOI を変換すると MRL が得られ,この方法で変換された文字列 FURDWLD の元の文字列は CROATIA である.
x = input() str_list = list(x) for a in str_list: if ord(a) + 3 > 90: print(chr(ord(a) - 24) ,end = "") else: print(chr(ord(a) + 3) ,end = "") print()
s971614031
Accepted
20
5,716
348
x = input() str_list = list(x) dict_ = { "D":"A", "E":"B", "F":"C", "G":"D", "H":"E", "I":"F", "J":"G", "K":"H", "L":"I", "M":"J", "N":"K", "O":"L", "P":"M", "Q":"N", "R":"O", "S":"P", "T":"Q", "U":"R", "V":"S", "W":"T", "X":"U", "Y":"V", "Z":"W", "A":"X", "B":"Y", "C":"Z" } for a in str_list: print(dict_.get(a) , end = "") print()
s536586035
p03861
u737715061
2,000
262,144
Wrong Answer
17
2,940
122
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?
a, b, x = map(int, input().split()) if a == b: if a % x == 0: print(1) else: print(0) else: print((b-a)//x)
s429469344
Accepted
17
2,940
123
a, b, x = map(int, input().split()) def f(n): if n == -1: return 0 else: return (n//x+1) print(f(b)-(f(a-1)))
s353085728
p03433
u418826171
2,000
262,144
Wrong Answer
29
9,132
107
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
N = int(input()) a = sorted(list(map(int,input().split())), reverse = True) print(sum(a[::2])-sum(a[1::2]))
s626173094
Accepted
25
9,112
87
n = int(input()) a = int(input()) if n%500 <= a: print('Yes') else: print('No')
s395385093
p03759
u497046426
2,000
262,144
Wrong Answer
17
2,940
90
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.
a, b, c = map(int, input().split()) if a == b == c: print('YES') else: print('NO')
s854854764
Accepted
17
2,940
93
a, b, c = map(int, input().split()) if b - a == c - b: print('YES') else: print('NO')
s077792386
p03592
u693953100
2,000
262,144
Wrong Answer
212
3,060
245
We have a grid with N rows and M columns of squares. Initially, all the squares are white. There is a button attached to each row and each column. When a button attached to a row is pressed, the colors of all the squares in that row are inverted; that is, white squares become black and vice versa. When a button attached to a column is pressed, the colors of all the squares in that column are inverted. Takahashi can freely press the buttons any number of times. Determine whether he can have exactly K black squares in the grid.
n,m,k = map(int, input().split()) def check(): globals() for i in range(n+1): for j in range(m+1): if j*(n-i)+i*(m-j)==k: return True return False if check(): print('YES') else: print('NO')
s935474490
Accepted
216
3,060
245
n,m,k = map(int, input().split()) def check(): globals() for i in range(n+1): for j in range(m+1): if j*(n-i)+i*(m-j)==k: return True return False if check(): print('Yes') else: print('No')
s778825654
p02612
u321065001
2,000
1,048,576
Wrong Answer
27
9,144
29
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
N=int(input()) print(N%1000)
s119508070
Accepted
26
9,140
74
N=int(input()) if N%1000==0: print(0) else: print(1000-N%1000)
s081862326
p02613
u193597115
2,000
1,048,576
Wrong Answer
153
16,192
265
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
if __name__ == '__main__': N = int(input()) res = [] for _ in range(N): res.append(str(input())) print('AC x {}'.format(res.count('AC'))) print('WA x {}'.format('WA')) print('TLE x {}'.format('TLE')) print('RE x {}'.format('RE'))
s126701541
Accepted
160
16,128
298
if __name__ == '__main__': N = int(input()) res = [] for _ in range(N): res.append(str(input())) print('AC x {}'.format(res.count('AC'))) print('WA x {}'.format(res.count('WA'))) print('TLE x {}'.format(res.count('TLE'))) print('RE x {}'.format(res.count('RE')))
s602907488
p03796
u137704841
2,000
262,144
Wrong Answer
31
2,940
103
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.
inN = int(input()) D=1000000000 + 7 p=0 for i in range(inN): p*=i if (D < p): p=p%D print(str(p))
s831183670
Accepted
49
2,940
107
inN = int(input()) D=1000000000+7 p=1 for i in range(inN): p*=(i+1) if (D < p): p=p%D print(str(p))
s154333911
p04029
u071061942
2,000
262,144
Wrong Answer
18
2,940
49
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?
N = int(input()) ans = N * (N + 1) / 2 print(ans)
s506553747
Accepted
18
2,940
54
N = int(input()) ans = int(N * (N + 1) / 2) print(ans)
s236004551
p03478
u915763824
2,000
262,144
Wrong Answer
40
9,116
148
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
n, a, b = list(map(int, input().split())) total = 0 for i in range(n): if a <= sum(list(map(int, str(i)))) <= b: total += i print(total)
s848338592
Accepted
42
9,076
153
n, a, b = list(map(int, input().split())) total = 0 for i in range(1, n+1): if a <= sum(list(map(int, str(i)))) <= b: total += i print(total)
s039773687
p03853
u767545760
2,000
262,144
Wrong Answer
17
3,060
100
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).
px = list(map(int, input().split())) pxs = [x for x in input()] for i in pxs: print(i) print(i)
s701528169
Accepted
18
3,060
105
H, W = map(int, input().split()) C = [input() for i in range(H)] for px in C: print(px) print(px)
s052481100
p02255
u481571686
1,000
131,072
Wrong Answer
20
5,596
160
Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: for i = 1 to A.length-1 key = A[i] /* insert A[i] into the sorted sequence A[0,...,j-1] */ j = i - 1 while j >= 0 and A[j] > key A[j+1] = A[j] j-- A[j+1] = key Note that, indices for array elements are based on 0-origin. To illustrate the algorithms, your program should trace intermediate result for each step.
a=[] n=int(input()) a=input().strip().split(' ') print(a) for i in range(1,n): v=a[i] j=i-1 while j>=0 and a[j]>v: a[j+1]=a[j] j=j-1 a[j+1]=v print(a)
s988511986
Accepted
20
5,596
168
n=int(input()) a=list(map(int,input().split())) for i in range(n): v=a[i] j=i-1 while j>=0 and a[j]>v: a[j+1]=a[j] j=j-1 a[j+1]=v print(' '.join(map(str,a)))
s661830449
p03697
u840684628
2,000
262,144
Wrong Answer
18
2,940
97
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.
inp = input().split() r = int(inp[0] + inp[1]) if r >= 10: print("error") else: print(r)
s294193531
Accepted
17
2,940
102
inp = input().split() r = int(inp[0]) + int(inp[1]) if r >= 10: print("error") else: print(r)
s110315845
p03435
u741472097
2,000
262,144
Wrong Answer
20
3,064
825
We have a 3 \times 3 grid. A number c_{i, j} is written in the square (i, j), where (i, j) denotes the square at the i-th row from the top and the j-th column from the left. According to Takahashi, there are six integers a_1, a_2, a_3, b_1, b_2, b_3 whose values are fixed, and the number written in the square (i, j) is equal to a_i + b_j. Determine if he is correct.
c = [] c.append(list(map(int, input().split()))) c.append(list(map(int, input().split()))) c.append(list(map(int, input().split()))) c0 = c[0][0] + c[0][1] + c[0][2] c1 = c[1][0] + c[1][1] + c[1][2] c2 = c[2][0] + c[2][1] + c[2][2] # a0 + b0 = c00 # a0 + b1 = c01 # a0 + b2 = c02 # 3*a2 + b0 + b1 + b2 = c20 + c21 + c22 # 3*a2 - 3*a0 = c20 + c21 + c22 - (c00 + c01 + c02) print(str(c)) for a0 in range(101): b0 = c[0][0] - a0 b1 = c[0][1] - a0 b2 = c[0][2] - a0 for a1 in range(101): a2 = (c2 - c0 + 3 * a0) / 3 if ( c[1][0] - a1 == b0 and c[1][1] - a1 == b1 and c[1][2] - a1 == b2 and c[2][0] - a2 == b0 and c[2][1] - a2 == b1 and c[2][2] - a2 == b2 ): print("Yes") exit(0) print("No")
s921546746
Accepted
20
3,064
811
c = [] c.append(list(map(int, input().split()))) c.append(list(map(int, input().split()))) c.append(list(map(int, input().split()))) c0 = c[0][0] + c[0][1] + c[0][2] c1 = c[1][0] + c[1][1] + c[1][2] c2 = c[2][0] + c[2][1] + c[2][2] # a0 + b0 = c00 # a0 + b1 = c01 # a0 + b2 = c02 # 3*a2 + b0 + b1 + b2 = c20 + c21 + c22 # 3*a2 - 3*a0 = c20 + c21 + c22 - (c00 + c01 + c02) for a0 in range(101): b0 = c[0][0] - a0 b1 = c[0][1] - a0 b2 = c[0][2] - a0 for a1 in range(101): a2 = (c2 - c0 + 3 * a0) / 3 if ( c[1][0] - a1 == b0 and c[1][1] - a1 == b1 and c[1][2] - a1 == b2 and c[2][0] - a2 == b0 and c[2][1] - a2 == b1 and c[2][2] - a2 == b2 ): print("Yes") exit(0) print("No")
s450288971
p03997
u953753178
2,000
262,144
Wrong Answer
19
2,940
59
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.
a, b, h = (int(input()) for _ in range(3)) print((a+b)*h/2)
s702737226
Accepted
18
2,940
64
a, b, h = (int(input()) for _ in range(3)) print(int((a+b)*h/2))
s640622243
p03557
u304058693
2,000
262,144
Wrong Answer
1,498
28,904
1,514
The season for Snuke Festival has come again this year. First of all, Ringo will perform a ritual to summon Snuke. For the ritual, he needs an altar, which consists of three parts, one in each of the three categories: upper, middle and lower. He has N parts for each of the three categories. The size of the i-th upper part is A_i, the size of the i-th middle part is B_i, and the size of the i-th lower part is C_i. To build an altar, the size of the middle part must be strictly greater than that of the upper part, and the size of the lower part must be strictly greater than that of the middle part. On the other hand, any three parts that satisfy these conditions can be combined to form an altar. How many different altars can Ringo build? Here, two altars are considered different when at least one of the three parts used is different.
n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) a=sorted(a) b=sorted(b) c=sorted(c) def lower_bound(arr,x): l=0 r=len(arr)-1 while l<=r: mid=(l+r)//2 if x==arr[mid]: return mid+1 elif x<arr[mid]: r=mid-1 else: l=mid+1 #print(mid,r,l) return r+1 def upper_bound(arr,x): l=0 r=len(arr)-1 while l<=r: mid=(l+r)//2 if x==arr[mid]: return mid-1 elif x<arr[mid]: r=mid-1 else: l=mid+1 #print(mid,r,l) return r count=0 for i in range(n): a_count=upper_bound(a,b[i])+1 c_count=lower_bound(c,b[i])+1 count+=a_count*(len(c)-c_count+1) print(upper_bound(a,b[i]),lower_bound(c,b[i])) print(a_count,len(c),c_count,len(c)-c_count+1) print(count) print(count)
s279952604
Accepted
250
29,696
400
import bisect ################# n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) c=list(map(int,input().split())) a=sorted(a) b=sorted(b) c=sorted(c) count=0 for i in range(n): a_count = bisect.bisect_left(a, b[i]) c_count = bisect.bisect_right(c, b[i]) count+=a_count*(len(c)-c_count) print(count)
s760007696
p03458
u785578220
2,000
262,144
Wrong Answer
2,111
106,516
710
AtCoDeer is thinking of painting an infinite two-dimensional grid in a _checked pattern of side K_. Here, a checked pattern of side K is a pattern where each square is painted black or white so that each connected component of each color is a K × K square. Below is an example of a checked pattern of side 3: AtCoDeer has N desires. The i-th desire is represented by x_i, y_i and c_i. If c_i is `B`, it means that he wants to paint the square (x_i,y_i) black; if c_i is `W`, he wants to paint the square (x_i,y_i) white. At most how many desires can he satisfy at the same time?
import numpy as np N, K = map(int, input().split()) mod = 2*K field = [[0]*(2*K+1) for _ in range(2*K+1)] def gen_pattern(x): if x < K-1: return [[0, x+1], [x+K+1, 2*K]] else: return [[x-K+1, x+1]] for _ in range(N): x, y, c = input().split() x, y = int(x), int(y) if c == 'W': y += K x %= mod y %= mod for tmp in [0, K]: for l, r in gen_pattern((x+tmp) % mod): for b, t in gen_pattern((y+tmp) % mod): print(l,r,b,t,x,y,tmp) field[l][b] += 1 field[l][t] -= 1 field[r][b] -= 1 field[r][t] += 1 print(np.max(np.cumsum(np.cumsum(field, axis=0), axis=1)))
s147864971
Accepted
1,612
106,344
670
import numpy as np N, K = map(int, input().split()) mod = 2*K field = [[0]*(2*K+1) for _ in range(2*K+1)] def gen_pattern(x): if x < K-1: return [[0, x+1], [x+K+1, 2*K]] else: return [[x-K+1, x+1]] for _ in range(N): x, y, c = input().split() x, y = int(x), int(y) if c == 'W': y += K x %= mod y %= mod for tmp in [0, K]: for l, r in gen_pattern((x+tmp) % mod): for b, t in gen_pattern((y+tmp) % mod): field[l][b] += 1 field[l][t] -= 1 field[r][b] -= 1 field[r][t] += 1 print(np.max(np.cumsum(np.cumsum(field, axis=0), axis=1)))
s074395581
p03473
u126232616
2,000
262,144
Wrong Answer
17
2,940
22
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
print(24-int(input()))
s890232243
Accepted
17
2,940
22
print(48-int(input()))
s592908524
p03434
u788260274
2,000
262,144
Wrong Answer
30
9,044
261
We have N cards. A number a_i is written on the i-th card. Alice and Bob will play a game using these cards. In this game, Alice and Bob alternately take one card. Alice goes first. The game ends when all the cards are taken by the two players, and the score of each player is the sum of the numbers written on the cards he/she has taken. When both players take the optimal strategy to maximize their scores, find Alice's score minus Bob's score.
from sys import stdin n = stdin.readline().rstrip() A = [int(x) for x in stdin.readline().rstrip().split()] A.sort(reverse=True) print (A) N=M=0 for i in range(0,len(A),2): N = N + A[i] for i in range(1, len(A), 2): M = M + A[i] print (N-M)
s810773213
Accepted
32
9,064
250
from sys import stdin n = stdin.readline().rstrip() A = [int(x) for x in stdin.readline().rstrip().split()] A.sort(reverse=True) N=M=0 for i in range(0,len(A),2): N = N + A[i] for i in range(1, len(A), 2): M = M + A[i] print (N-M)
s854414493
p03472
u405256066
2,000
262,144
Wrong Answer
187
11,836
346
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order: * Wield one of the katana you have. When you wield Katana i (1 ≤ i ≤ N), the monster receives a_i points of damage. The same katana can be wielded any number of times. * Throw one of the katana you have. When you throw Katana i (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana. The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?
from sys import stdin N,H = [int(x) for x in stdin.readline().rstrip().split()] swing = [] throw = [] for _ in range(N): a,b = [int(x) for x in stdin.readline().rstrip().split()] swing.append(a) throw.append(b) swing_m = max(swing) throw_l = [i for i in throw if i >= swing_m] ans = (H - sum(throw_l))//swing_m print(ans+len(throw_l))
s368713849
Accepted
225
13,348
555
from sys import stdin import math N,H = [int(x) for x in stdin.readline().rstrip().split()] swing = [] throw = [] for _ in range(N): a,b = [int(x) for x in stdin.readline().rstrip().split()] swing.append(a) throw.append(b) swing_m = max(swing) throw_l = [i for i in throw if i >= swing_m] ans = 0 H_ = H flag = True for j in sorted(throw_l)[::-1]: H_ -= j ans += 1 if H_ <= 0: flag = False break if flag: ans = (H - sum(throw_l))/swing_m ans = math.ceil(ans) print(ans+len(throw_l)) else: print(ans)
s621915398
p03493
u611090896
2,000
262,144
Wrong Answer
17
2,940
43
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.
abc = input().split() print(abc.count("1"))
s326654119
Accepted
17
2,940
30
s= input() print(s.count('1'))
s415163379
p03471
u054935796
2,000
262,144
Wrong Answer
17
3,188
789
The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these. According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.
N , Y = list(map(int, input().split())) Y = Y/1000 Z = Y - N A = 9*N - Z if Z < 0 or Z > 9*N: X = [-1,-1,-1] elif 24 <= Z <= 9*N - 32: X = [(Z-27)//9+((Z%9)%4-1)%4,(9-2*(Z%9))%9,N-((Z-27)//9+((Z%9)%4-1)%4+(9-2*(Z%9))%9)] X = list(map(int, X)) elif 0 <= Z <= 23: if Z%4 == 0: X = [0,Z/4,N-(Z/4)] elif Z%9 == 0: X = [Z/9,0,N-(Z/9)] elif Z == 13 or Z == 17 or Z == 21: X = [1,(Z-9)/4,N-((Z-5)/4)] elif Z == 22: X = [2,1,N-3] else: X = [-1,-1,-1] X = list(map(int, X)) else: if A%5 == 0: X = [N-(A/5),A/5,0] elif A%9 == 0: X = [N-(A/9),0,A/9] elif A == 14 or A == 19 or A == 24 or A == 29: X = [N-((A-4)/5),(A-9)/5,1] elif A == 23 or A == 28: X = [N-((A-8)/5),(A-18)/5,2] else: X = [-1,-1,-1] X = list(map(int, X)) print(X)
s161543979
Accepted
18
3,188
802
N , Y = list(map(int, input().split())) Y = Y/1000 Z = Y - N A = 9*N - Z if Z < 0 or Z > 9*N: X = [-1,-1,-1] elif 24 <= Z <= 9*N - 32: X = [(Z-27)//9+((Z%9)%4-1)%4,(9-2*(Z%9))%9,N-((Z-27)//9+((Z%9)%4-1)%4+(9-2*(Z%9))%9)] X = list(map(int, X)) elif 0 <= Z <= 23: if Z%4 == 0: X = [0,Z/4,N-(Z/4)] elif Z%9 == 0: X = [Z/9,0,N-(Z/9)] elif Z == 13 or Z == 17 or Z == 21: X = [1,(Z-9)/4,N-((Z-5)/4)] elif Z == 22: X = [2,1,N-3] else: X = [-1,-1,-1] X = list(map(int, X)) else: if A%5 == 0: X = [N-(A/5),A/5,0] elif A%9 == 0: X = [N-(A/9),0,A/9] elif A == 14 or A == 19 or A == 24 or A == 29: X = [N-((A-4)/5),(A-9)/5,1] elif A == 23 or A == 28: X = [N-((A-8)/5),(A-18)/5,2] else: X = [-1,-1,-1] X = list(map(int, X)) print(X[0],X[1],X[2])
s776077630
p03089
u540761833
2,000
1,048,576
Wrong Answer
17
3,060
281
Snuke has an empty sequence a. He will perform N operations on this sequence. In the i-th operation, he chooses an integer j satisfying 1 \leq j \leq i, and insert j at position j in a (the beginning is position 1). You are given a sequence b of length N. Determine if it is possible that a is equal to b after N operations. If it is, show one possible sequence of operations that achieves it.
N = int(input()) b = list(map(int,input().split())) ans = [] for i in range(N): for j in range(len(b)-1,-1,-1): if b[j] <= j+1: ans.append(b[j]) b.pop(j) break if len(ans) == N: for i in ans: print(i) else: print(-1)
s283661799
Accepted
18
3,064
374
N = int(input()) b = list(map(int,input().split())) ans = [] count = 1 for i in range(N-1,-1,-1): flag = True for j in range(i,-1,-1): if b[j] == j+1: ans.append(j+1) b.pop(j) flag = False break if flag: break if flag: print(-1) else: for i in range(len(ans)-1,-1,-1): print(ans[i])
s692541037
p03433
u194484802
2,000
262,144
Wrong Answer
17
2,940
100
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
money = int(input()) A = int(input()) if (money % 500) > A: print('NO') else: print('YES')
s665677211
Accepted
17
2,940
100
money = int(input()) A = int(input()) if (money % 500) > A: print('No') else: print('Yes')
s336622830
p02659
u880400515
2,000
1,048,576
Wrong Answer
22
8,960
60
Compute A \times B, truncate its fractional part, and print the result as an integer.
A, B = list(map(float, input().split())) print(round(A*B))
s122935104
Accepted
24
9,172
178
import math A, B = input().split() A = int(A) B_i = int(B[:-3]) B_f = int(B[-2:]) f = str(A*B_f) if (len(f) >= 3): f_i = int(f[:-2]) else: f_i = 0 print(A*B_i + f_i)
s245916653
p02601
u670469727
2,000
1,048,576
Wrong Answer
27
9,196
257
M-kun has the following three cards: * A red card with the integer A. * A green card with the integer B. * A blue card with the integer C. He is a genius magician who can do the following operation at most K times: * Choose one of the three cards and multiply the written integer by 2. His magic is successful if both of the following conditions are satisfied after the operations: * The integer on the green card is **strictly** greater than the integer on the red card. * The integer on the blue card is **strictly** greater than the integer on the green card. Determine whether the magic can be successful.
import sys a_b_c = list(map(int, input().split())) r = a_b_c[0] g = a_b_c[1] b = a_b_c[2] k = int(input()) while (g <= r and k >= 0): g *= 2 k -= 1 while (b <= g and k >= 0): b *= 2 k -= 1 if (k < 0): print("No") else: print("YES")
s200474178
Accepted
27
9,192
257
import sys a_b_c = list(map(int, input().split())) r = a_b_c[0] g = a_b_c[1] b = a_b_c[2] k = int(input()) while (g <= r and k >= 0): g *= 2 k -= 1 while (b <= g and k >= 0): b *= 2 k -= 1 if (k < 0): print("No") else: print("Yes")
s772043125
p03659
u474270503
2,000
262,144
Wrong Answer
179
29,256
222
Snuke and Raccoon have a heap of N cards. The i-th card from the top has the integer a_i written on it. They will share these cards. First, Snuke will take some number of cards from the top of the heap, then Raccoon will take all the remaining cards. Here, both Snuke and Raccoon have to take at least one card. Let the sum of the integers on Snuke's cards and Raccoon's cards be x and y, respectively. They would like to minimize |x-y|. Find the minimum possible value of |x-y|.
N=int(input()) A=list(map(int, input().split())) b=[] sum=0 for a in A: sum+=a b.append(sum) print(b) ans=float("inf") for i in range(0,N-1): if ans>abs(b[-1]-b[i]*2): ans=abs(b[-1]-b[i]*2) print(ans)
s067442612
Accepted
162
24,832
213
N=int(input()) A=list(map(int, input().split())) b=[] sum=0 for a in A: sum+=a b.append(sum) ans=float("inf") for i in range(0,N-1): if ans>abs(b[-1]-b[i]*2): ans=abs(b[-1]-b[i]*2) print(ans)
s921525451
p02613
u063346608
2,000
1,048,576
Wrong Answer
144
9,112
394
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
N = int(input()) ACcount = 0 WAcount = 0 TLEcount = 0 REcount = 0 for i in range(N): S=input() if S == "AC": ACcount = ACcount + 1 elif S == "WA": WAcount = WAcount + 1 elif S == "TLE": TLEcount = TLEcount + 1 elif S == "RE": REcount = REcount + 1 print("AC x " + str(ACcount)) print("WA x " + str(WAcount)) print("TLE x " + str(TLEcount)) print("RE x " + str(REcount))
s347766511
Accepted
147
9,200
359
N = int(input()) ACcount = 0 WAcount = 0 TLEcount = 0 REcount = 0 for i in range(N): S=input() if S == "AC": ACcount = ACcount + 1 elif S == "WA": WAcount = WAcount + 1 elif S == "TLE": TLEcount = TLEcount + 1 elif S == "RE": REcount = REcount + 1 print("AC x", ACcount) print("WA x", WAcount) print("TLE x", TLEcount) print("RE x", REcount)
s242363206
p03862
u667024514
2,000
262,144
Wrong Answer
127
14,588
295
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.
n,k = map(int,input().split()) lis = list(map(int,input().split())) ans = 0 for i in range(n-1): if lis[i] + lis[i+1] > k: num = k-lis[i+1]-lis[i] ans += num if num >= lis[i+1]: num -= lis[i+1] lis[i+1] = 0 lis[i] -= num else: lis[i+1] -= num print(ans)
s268285815
Accepted
137
14,588
297
n,k = map(int,input().split()) lis = list(map(int,input().split())) ans = 0 for i in range(n-1): if lis[i] + lis[i+1] > k: num = lis[i+1]+lis[i] -k ans += num if num >= lis[i+1]: num -= lis[i+1] lis[i+1] = 0 lis[i] -= num else: lis[i+1] -= num print(ans)
s848428705
p04025
u384679440
2,000
262,144
Wrong Answer
17
3,064
253
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.
N = int(input()) a = list(map(int, input().split())) a.sort() ans = 0 median = 0 if N % 2 == 0: median = int((a[int(N/2) - 1] + a[int(N/2)]) / 2) else: median = a[int(N/2)] print(median) for i in range(len(a)): ans += pow(median - a[i], 2) print(ans)
s324112968
Accepted
27
3,060
192
N = int(input()) a = list(map(int, input().split())) ans = pow(100, 9) for i in range(-100, 101): temp = 0 for j in range(len(a)): temp += pow(i - a[j], 2) ans = min(ans, temp) print(ans)
s390314416
p03339
u479638406
2,000
1,048,576
Wrong Answer
2,104
12,324
194
There are N people standing in a row from west to east. Each person is facing east or west. The directions of the people is given as a string S of length N. The i-th person from the west is facing east if S_i = `E`, and west if S_i = `W`. You will appoint one of the N people as the leader, then command the rest of them to face in the direction of the leader. Here, we do not care which direction the leader is facing. The people in the row hate to change their directions, so you would like to select the leader so that the number of people who have to change their directions is minimized. Find the minimum number of people who have to change their directions.
n = int(input()) s = list(input()) l = [0]*n l[n-1] = s[:n-1].count('E') for i in range(n-1): w_side = s[:i].count('E') e_side = s[i+1:].count('W') l[i] = w_side + e_side print(min(l))
s502827090
Accepted
78
15,524
292
import sys n, s = sys.stdin.read().split() def main(): cnt = s.count('E') cur = 'E' res = [cnt] for c in s: if cur == 'W': cnt += 1 if c == 'E': cnt -= 1 res.append(cnt) cur = c print(min(res)) if __name__ == '__main__': main()
s670975658
p03578
u466826467
2,000
262,144
Wrong Answer
344
57,056
424
Rng is preparing a problem set for a qualification round of CODEFESTIVAL. He has N candidates of problems. The difficulty of the i-th candidate is D_i. There must be M problems in the problem set, and the difficulty of the i-th problem must be T_i. Here, one candidate of a problem cannot be used as multiple problems. Determine whether Rng can complete the problem set without creating new candidates of problems.
from collections import Counter if __name__ == '__main__': N = int(input()) D = list(map(int, input().split())) M = int(input()) T = list(map(int, input().split())) counter_d = Counter(D) counter_t = Counter(T) ans = "Yes" for point, num in counter_t.items(): if counter_d.get(point) is None or counter_d.get(point) < num: ans = "No" break print(ans)
s913966781
Accepted
330
57,056
423
from collections import Counter if __name__ == '__main__': N = int(input()) D = list(map(int, input().split())) M = int(input()) T = list(map(int, input().split())) counter_d = Counter(D) counter_t = Counter(T) ans = "YES" for point, num in counter_t.items(): if counter_d.get(point) is None or counter_d.get(point) < num: ans = "NO" break print(ans)
s611792348
p03494
u790876967
2,000
262,144
Time Limit Exceeded
2,104
2,940
240
There are N positive integers written on a blackboard: A_1, ..., A_N. Snuke can perform the following operation when all integers on the blackboard are even: * Replace each integer X on the blackboard by X divided by 2. Find the maximum possible number of operations that Snuke can perform.
input_n = int(input()) num_list = [int(i) for i in (input().split())] count = 0 while True: if all(i % 2 == 0 for i in num_list): nom_list = map(lambda x: x / 2, num_list) count += 1 else: break print(count)
s429534702
Accepted
149
12,424
217
import numpy as np _ = int(input()) num_array = np.array(list(map(int, input().split()))) count = 0 while True: if any(num_array % 2 != 0): break num_array = num_array / 2 count += 1 print(count)
s298594847
p03478
u874741582
2,000
262,144
Wrong Answer
63
3,832
269
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
n,a,b = map(int,input().split()) l=[] for i in range(1,n+1): ic = list(str(int(i))) s = list(map(int,ic)) print(s,sum(s)) if sum(s) >= a and sum(s) <= b: l.append(i) print(sum(l))
s814617574
Accepted
41
3,424
249
n,a,b = map(int,input().split()) l=[] for i in range(1,n+1): ic = list(str(int(i))) s = list(map(int,ic)) if sum(s) >= a and sum(s) <= b: l.append(i) print(sum(l))
s586503926
p03502
u443630646
2,000
262,144
Wrong Answer
17
2,940
108
An integer X is called a Harshad number if X is divisible by f(X), where f(X) is the sum of the digits in X when written in base 10. Given an integer N, determine whether it is a Harshad number.
N = list(input()) a = 0 for x in N: a += int(x) if a % 10 == 0: print('Yes') else: print('No')
s494609044
Accepted
19
2,940
121
N = list(input()) a = 0 for x in N: a += int(x) if int(''.join(N)) % a == 0: print('Yes') else: print('No')
s435807666
p03478
u055875839
2,000
262,144
Wrong Answer
28
2,940
171
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
a, b, c = map(int, input().split()) total = 0 for x in range(a): z = x d = 0 while z != 0: d += z % 10 z = z // 10 if b <= d <= c:total += x print(total)
s451472469
Accepted
28
2,940
173
a, b, c = map(int, input().split()) total = 0 for x in range(a+1): z = x d = 0 while z != 0: d += z % 10 z = z // 10 if b <= d <= c:total += x print(total)
s878680055
p02930
u754022296
2,000
1,048,576
Wrong Answer
64
3,952
58
AtCoder's head office consists of N rooms numbered 1 to N. For any two rooms, there is a direct passage connecting these rooms. For security reasons, Takahashi the president asked you to set a **level** for every passage, which is a positive integer and must satisfy the following condition: * For each room i\ (1 \leq i \leq N), if we leave Room i, pass through some passages whose levels are all equal and get back to Room i, the number of times we pass through a passage is always even. Your task is to set levels to the passages so that the highest level of a passage is minimized.
n = int(input()) for i in range(1, n): print(*[i]*(n-i))
s196436682
Accepted
84
9,344
140
n = int(input()) for i in range(n-1): L = [] for j in range(i+1, n): x = i^j l = (x&-x).bit_length() L.append(l) print(*L)
s561100860
p03448
u586305367
2,000
262,144
Wrong Answer
41
3,060
658
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
coin_500 = int(input('500')) coin_100 = int(input('100')) coin_50 = int(input('50')) target = int(input('target')) counter = 0 for i_500 in range(coin_500 + 1): # print('======= loop 500 =======') if i_500 * 500 > target: break for i_100 in range(coin_100 + 1): # print('-------- loop 100 ---------') if i_500 * 500 + i_100 * 100 > target: break for i_50 in range(coin_50 + 1): # print('........... loop 50 ..........') if i_500 * 500 + i_100 * 100 + i_50 * 50 == target: # print('match: ', i_500, i_100, i_50) counter += 1 print(counter)
s542332431
Accepted
40
3,060
636
coin_500 = int(input()) coin_100 = int(input()) coin_50 = int(input()) target = int(input()) counter = 0 for i_500 in range(coin_500 + 1): # print('======= loop 500 =======') if i_500 * 500 > target: break for i_100 in range(coin_100 + 1): # print('-------- loop 100 ---------') if i_500 * 500 + i_100 * 100 > target: break for i_50 in range(coin_50 + 1): # print('........... loop 50 ..........') if i_500 * 500 + i_100 * 100 + i_50 * 50 == target: # print('match: ', i_500, i_100, i_50) counter += 1 print(counter)
s730073681
p03658
u205678452
2,000
262,144
Wrong Answer
20
3,316
209
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.
A = input().split() N = int(A[0]) K = int(A[1]) A = input().split() l = [] for n in range(N): l.append(int(A[n])) l.sort(reverse=True) sum=0 for i in range(K): sum = sum + l[i] print(l) print(sum)
s966107658
Accepted
17
3,060
200
A = input().split() N = int(A[0]) K = int(A[1]) A = input().split() l = [] for n in range(N): l.append(int(A[n])) l.sort(reverse=True) sum=0 for i in range(K): sum = sum + l[i] print(sum)
s737418505
p02243
u138577439
1,000
131,072
Wrong Answer
30
7,732
621
For a given weighted graph $G = (V, E)$, find the shortest path from a source to each vertex. For each vertex $u$, print the total weight of edges on the shortest path from vertex $0$ to $u$.
V=int(input()) G=[[] for i in range(V)] d=[1001001001 for i in range(V)] import heapq def dijkstra(s): q=[] d[s]=0 heapq.heappush(q,(0, s)) while(len(q)): print(q) p=heapq.heappop(q) v=p[1] if d[v]<p[0]: continue for e in G[v]: if d[e[0]]>d[v]+e[1]: d[e[0]]=d[v]+e[1] heapq.heappush(q, (d[e[0]], e[0])) import sys for l in sys.stdin: l=list(map(int,l.split())) u=l[0] k=l[1] G[u]=zip(*[iter(l[2:])]*2) dijkstra(0) for i in range(V): print(i, d[i])
s468749002
Accepted
370
41,600
690
V=int(input()) G=[[] for i in range(V)] d=[1001001001 for i in range(V)] used=[False for i in range(V)] import heapq def dijkstra(s): q=[] d[s]=0 heapq.heappush(q,(0, s)) while(len(q)): p=heapq.heappop(q) v=p[1] used[v]=True if d[v]<p[0]: continue for e in G[v]: if (not used[e[0]]) and d[e[0]]>d[v]+e[1]: d[e[0]]=d[v]+e[1] heapq.heappush(q, (d[e[0]], e[0])) import sys for l in sys.stdin: l=list(map(int,l.split())) u=l[0] k=l[1] G[u]=zip(*[iter(l[2:])]*2) dijkstra(0) for i, c in enumerate(d): print(i, d[i])
s998091826
p03473
u428132025
2,000
262,144
Wrong Answer
17
2,940
30
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
m = int(input()) print(m + 24)
s242509600
Accepted
17
2,940
35
m = int(input()) print((24-m) + 24)
s678506854
p03214
u922449550
2,525
1,048,576
Wrong Answer
17
3,060
172
Niwango-kun is an employee of Dwango Co., Ltd. One day, he is asked to generate a thumbnail from a video a user submitted. To generate a thumbnail, he needs to select a frame of the video according to the following procedure: * Get an integer N and N integers a_0, a_1, ..., a_{N-1} as inputs. N denotes the number of the frames of the video, and each a_i denotes the representation of the i-th frame of the video. * Select t-th frame whose representation a_t is nearest to the average of all frame representations. * If there are multiple such frames, select the frame with the smallest index. Find the index t of the frame he should select to generate a thumbnail.
N = int(input()) A = list(map(int, input().split())) mu = sum(A) / N diff = 1000 ans = 0 for a in A: if abs(a - mu) < diff: diff = abs(a - mu) ans = a print(ans)
s184034904
Accepted
17
3,060
187
N = int(input()) A = list(map(int, input().split())) mu = sum(A) / N diff = 1000 ans = 0 for i, a in enumerate(A): if abs(a - mu) < diff: diff = abs(a - mu) ans = i print(ans)
s757527955
p04043
u888512581
2,000
262,144
Wrong Answer
17
2,940
184
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.
numbers_list = input().split() count5 = numbers_list.count('5') count7 = numbers_list.count('7') if count5 == 2 and count7 == 1: print('YES') else: print('NO') print(numbers_list)
s266337085
Accepted
17
2,940
165
numbers_list = input().split() count5 = numbers_list.count('5') count7 = numbers_list.count('7') if count5 == 2 and count7 == 1: print('YES') else: print('NO')
s272554340
p03448
u378299699
2,000
262,144
Wrong Answer
216
4,896
644
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
A = int(input()) B = int(input()) C =int(input()) X = int(input()) count = 0 for i in range(A + 1): total = i * 500 print("i",i, total) if total == X: count += 1 continue if total > X: break for j in range(B + 1): total = i * 500 total += j * 100 print("j" ,i , j,total) if total == X: count += 1 if total > X: break for k in range(1,C + 1): total += 50 print("k",i,j,k , total) if total == X: count += 1 if total > X: break print(count)
s249085801
Accepted
32
3,064
552
A = int(input()) B = int(input()) C =int(input()) X = int(input()) count = 0 for i in range(A + 1): total = i * 500 if total == X: count += 1 continue if total > X: break for j in range(B + 1): total = i * 500 total += j * 100 if total == X: count += 1 if total > X: break for k in range(1,C + 1): total += 50 if total == X: count += 1 if total > X: break print(count)
s941134767
p03067
u538632589
2,000
1,048,576
Wrong Answer
17
2,940
105
There are three houses on a number line: House 1, 2 and 3, with coordinates A, B and C, respectively. Print `Yes` if we pass the coordinate of House 3 on the straight way from House 1 to House 2 without making a detour, and print `No` otherwise.
a, b, c = [int(i) for i in input().split()] if a <= b and b <= c: print("Yes") else: print("No")
s207451802
Accepted
17
3,060
146
a, b, c = [int(i) for i in input().split()] if a <= c and c <= b: print("Yes") elif b <= c and c <= a: print("Yes") else: print("No")
s409915605
p03828
u468972478
2,000
262,144
Wrong Answer
2,205
9,076
138
You are given an integer N. Find the number of the positive divisors of N!, modulo 10^9+7.
n = int(input()) s = 1 t = 1 for i in range(1, n+1): s *= i for i in range(1, s+1): if s % i == 0: t += 1 print(t % (10 ** 9 + 7))
s102110030
Accepted
40
8,820
179
n = int(input()) s = 1 ans = 1 for i in range(1, n+1): s *= i for i in range(2, n+1): k = 1 while s % i == 0: s = s // i k += 1 ans *= k print(ans % (10 ** 9 + 7))
s705559468
p03556
u618512227
2,000
262,144
Wrong Answer
17
2,940
66
Find the largest square number not exceeding N. Here, a _square number_ is an integer that can be represented as the square of an integer.
import math as m N = int(input()) X = m.floor(m.sqrt(N)) print(X)
s107369371
Accepted
17
2,940
80
import math as m N = int(input()) X = m.pow(m.floor(m.sqrt(N)),2) print(int(X))
s096070591
p02414
u566311709
1,000
131,072
Wrong Answer
20
5,592
331
Write a program which reads a $n \times m$ matrix $A$ and a $m \times l$ matrix $B$, and prints their product, a $n \times l$ matrix $C$. An element of matrix $C$ is obtained by the following formula: \\[ c_{ij} = \sum_{k=1}^m a_{ik}b_{kj} \\] where $a_{ij}$, $b_{ij}$ and $c_{ij}$ are elements of $A$, $B$ and $C$ respectively.
n, m, l = map(int, input().split()) a = [] b = [] for _ in range(n): a.append(list(map(int, input().split()))) for _ in range(m): b.append(list(map(int, input().split()))) b = list(zip(*b)) for i in range(n): for j in range(l): t = 0 for k, l in zip(a[i], b[j]): t += k * l print(t, end = " ") print("")
s072578809
Accepted
110
6,584
250
n, m, l = map(int, input().split()) a = [list(map(int, input().split())) for _ in range(n)] b = [list(map(int, input().split())) for _ in range(m)] for i in a: c = [] for j in zip(*b): c.append(sum([k * l for k, l in zip(i, j)])) print(*c)
s759077725
p03945
u048004795
2,000
262,144
Wrong Answer
46
9,068
286
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.
import sys input = sys.stdin.readline S = input() print(S) S = S.replace('\n' , '') tmp = "" division_count = 0 for s in S: if tmp == "": tmp = s continue if tmp == s: continue else: tmp = s division_count += 1 print(division_count)
s977649099
Accepted
44
9,092
276
import sys input = sys.stdin.readline S = input() S = S.replace('\n' , '') tmp = "" division_count = 0 for s in S: if tmp == "": tmp = s continue if tmp == s: continue else: tmp = s division_count += 1 print(division_count)
s758240496
p03448
u979362546
2,000
262,144
Wrong Answer
52
3,060
229
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
a = int(input()) b = int(input()) c = int(input()) x = int(input()) ans = 0 for i in range(0, a): for j in range(0,b): for k in range(0,c): if 500*i + 100*j + 50*k == x: ans += 1 print(ans)
s012880778
Accepted
50
3,064
237
a = int(input()) b = int(input()) c = int(input()) x = int(input()) ans = 0 for i in range(0, a+1): for j in range(0, b+1): for k in range(0, c+1): if 500*i + 100*j + 50*k == x: ans += 1 print(ans)
s547001549
p02844
u492511953
2,000
1,048,576
Wrong Answer
19
3,060
249
AtCoder Inc. has decided to lock the door of its office with a 3-digit PIN code. The company has an N-digit lucky number, S. Takahashi, the president, will erase N-3 digits from S and concatenate the remaining 3 digits without changing the order to set the PIN code. How many different PIN codes can he set this way? Both the lucky number and the PIN code may begin with a 0.
n = int(input()) code = input() f = 0 total = 0 for i in range(100,1000): s = str(i) idx = -1 for dig in range(3): idx = code.find(s[dig], idx+1) if idx == -1: break if idx != -1: total += 1 print(total)
s318931962
Accepted
22
3,060
308
n = int(input()) code = input() f = 0 total = 0 for i in range(0,1000): s = str(i) if i< 10: s = '00' + s elif i < 100: s = '0' + s idx = -1 for dig in range(3): idx = code.find(s[dig], idx+1) if idx == -1: break if idx != -1: total += 1 print(total)
s886442880
p02613
u458515220
2,000
1,048,576
Wrong Answer
149
9,220
290
Takahashi is participating in a programming contest called AXC002, and he has just submitted his code to Problem A. The problem has N test cases. For each test case i (1\leq i \leq N), you are given a string S_i representing the verdict for that test case. Find the numbers of test cases for which the verdict is `AC`, `WA`, `TLE`, and `RE`, respectively. See the Output section for the output format.
n=int(input()) count1=0 count2=0 count3=0 count4=0 for i in range(n): s=input() if(s=="AE"): count1+=1 elif(s=="WA"): count2+=1 elif(s=="TLE"): count3+=1 elif(s=="RE"): count4+=1 print("AE x",count1) print("WA x",count2) print("TLE x",count3) print("RE x",count4)
s976816935
Accepted
146
9,220
291
n=int(input()) count1=0 count2=0 count3=0 count4=0 for i in range(n): s=input() if(s=="AC"): count1+=1 elif(s=="WA"): count2+=1 elif(s=="TLE"): count3+=1 elif(s=="RE"): count4+=1 print("AC x",count1) print("WA x",count2) print("TLE x",count3) print("RE x",count4)
s262299521
p03068
u395202850
2,000
1,048,576
Wrong Answer
33
9,420
405
You are given a string S of length N consisting of lowercase English letters, and an integer K. Print the string obtained by replacing every character in S that differs from the K-th character of S, with `*`.
import math import sys import collections import bisect readline = sys.stdin.readline def main(): [n, s, k] = [str(readline().rstrip()) for _ in range(3)] print(s) s = list(s) strS = "" target = s[int(k) - 1] for i in range(int(n)): if s[i] == target: strS += s[i] else: strS += "*" print(strS) if __name__ == '__main__': main()
s816101010
Accepted
31
9,300
392
import math import sys import collections import bisect readline = sys.stdin.readline def main(): [n, s, k] = [str(readline().rstrip()) for _ in range(3)] s = list(s) strS = "" target = s[int(k) - 1] for i in range(int(n)): if s[i] == target: strS += s[i] else: strS += "*" print(strS) if __name__ == '__main__': main()
s010411767
p02842
u169696482
2,000
1,048,576
Wrong Answer
17
2,940
76
Takahashi bought a piece of apple pie at ABC Confiserie. According to his memory, he paid N yen (the currency of Japan) for it. The consumption tax rate for foods in this shop is 8 percent. That is, to buy an apple pie priced at X yen before tax, you have to pay X \times 1.08 yen (rounded down to the nearest integer). Takahashi forgot the price of his apple pie before tax, X, and wants to know it again. Write a program that takes N as input and finds X. We assume X is an integer. If there are multiple possible values for X, find any one of them. Also, Takahashi's memory of N, the amount he paid, may be incorrect. If no value could be X, report that fact.
n=int(input()) a = n//1.08 if int(a*1.08)==n: print(a) else: print(":(")
s805247773
Accepted
17
3,064
166
import math n=int(input()) a = n/1.08 b =math.ceil(a) c=math.floor(a) if math.floor(b*1.08)==n: print(b) elif math.floor(c*1.08)==n: print(c) else: print(":(")
s067220025
p03023
u143051858
2,000
1,048,576
Wrong Answer
27
8,992
22
Given an integer N not less than 3, find the sum of the interior angles of a regular polygon with N sides. Print the answer in degrees, but do not print units.
print(int(input()*60))
s983539087
Accepted
23
9,080
27
print(180*(int(input())-2))
s900225309
p03711
u240793404
2,000
262,144
Wrong Answer
30
4,464
163
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.
import calendar a,b = map(int,input().split()) _, lastday =calendar.monthrange(2018, a) _, lastdayb = calendar.monthrange(2018,b) print("Yes" if a == b else "No")
s357526613
Accepted
27
4,464
176
import calendar a,b = map(int,input().split()) _, lastday =calendar.monthrange(2018, a) _, lastdayb = calendar.monthrange(2018,b) print("Yes" if lastday == lastdayb else "No")
s022083649
p03698
u146575240
2,000
262,144
Wrong Answer
17
2,940
90
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
# B - Varied S = str(input()) if set(S) == len(S): print('yes') else: print('no')
s448694172
Accepted
17
2,940
96
# B - Varied S = str(input()) if len(set(S)) == len(S): print('yes') else: print('no')
s821981657
p03545
u710282484
2,000
262,144
Wrong Answer
26
9,104
203
Sitting in a station waiting room, Joisino is gazing at her train ticket. The ticket is numbered with four digits A, B, C and D in this order, each between 0 and 9 (inclusive). In the formula A op1 B op2 C op3 D = 7, replace each of the symbols op1, op2 and op3 with `+` or `-` so that the formula holds. The given input guarantees that there is a solution. If there are multiple solutions, any of them will be accepted.
A, B, C, D = input() op = ["+", "-"] for i in op: for j in op: for k in op: ans = A + i + B + j + C + k + D if eval(ans) == 7: break print(ans + "=7")
s411801370
Accepted
28
9,028
221
A, B, C, D = input() op = ["+", "-"] for i in op: for j in op: for k in op: ans = A + i + B + j + C + k + D if eval(ans) == 7: print(ans + "=7") exit()
s264060891
p03478
u268279636
2,000
262,144
Wrong Answer
36
3,060
128
Find the sum of the integers between 1 and N (inclusive), whose sum of digits written in base 10 is between A and B (inclusive).
n,a,b = map(int,input().split()) ans = 0 for i in range(n+1): if a<= sum(list(map(int,list(str(i))))) <=b: ans+=1 print(ans)
s761754636
Accepted
38
3,060
145
n, a, b = map(int, input().split()) ans = 0 for i in range(n+1): if a <= sum(list(map(int, list(str(i))))) <= b: ans += i print(ans)
s646924115
p03448
u080108339
2,000
262,144
Wrong Answer
18
3,064
346
You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan). In how many ways can we select some of these coins so that they are X yen in total? Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.
A = int(input()) B = int(input()) C = int(input()) X = int(input()) count = 0 req_500 = X//500 max_500 = min(req_500, A) for i in range(0, max_500+1): X_sub500 = X - 500*i req_100 = X_sub500//100 max_100 = min(req_100, B) for j in range(0, max_100+1): X_sub100 = X_sub500 - 100*j req_50 = X_sub100//50 if req_50 <= C: count += 1
s691872536
Accepted
18
3,064
360
A = int(input()) B = int(input()) C = int(input()) X = int(input()) count = 0 req_500 = X//500 max_500 = min(req_500, A) for i in range(0, max_500+1): X_sub500 = X - 500*i req_100 = X_sub500//100 max_100 = min(req_100, B) for j in range(0, max_100+1): X_sub100 = X_sub500 - 100*j req_50 = X_sub100//50 if req_50 <= C: count += 1 print(count)
s123943640
p02275
u554503378
1,000
131,072
Wrong Answer
20
5,600
450
Counting sort can be used for sorting elements in an array which each of the n input elements is an integer in the range 0 to k. The idea of counting sort is to determine, for each input element x, the number of elements less than x as C[x]. This information can be used to place element x directly into its position in the output array B. This scheme must be modified to handle the situation in which several elements have the same value. Please see the following pseudocode for the detail: Counting-Sort(A, B, k) 1 for i = 0 to k 2 do C[i] = 0 3 for j = 1 to length[A] 4 do C[A[j]] = C[A[j]]+1 5 /* C[i] now contains the number of elements equal to i */ 6 for i = 1 to k 7 do C[i] = C[i] + C[i-1] 8 /* C[i] now contains the number of elements less than or equal to i */ 9 for j = length[A] downto 1 10 do B[C[A[j]]] = A[j] 11 C[A[j]] = C[A[j]]-1 Write a program which sorts elements of given array ascending order based on the counting sort.
def counting_sort(lst,ans,max): cnt_lst = [0] * (max+1) for i in range(1,len(lst)): cnt_lst[lst[i]] += 1 for j in range(1,max+1): cnt_lst[j] = cnt_lst[j] + cnt_lst[j-1] for k in range(len(lst)-1,0,-1): ans[cnt_lst[lst[k]]] = lst[k] cnt_lst[lst[k]] -= 1 return ans n = int(input()) n_lst = list(map(int,input().split())) ans = [0] * len(n_lst) ans = counting_sort(n_lst,ans,max(n_lst)) print(ans)
s337015194
Accepted
2,070
234,820
473
def counting_sort(lst,ans,max): cnt_lst = [0] * (max+1) for i in range(0,len(lst)): cnt_lst[lst[i]] += 1 for j in range(1,max+1): cnt_lst[j] = cnt_lst[j] + cnt_lst[j-1] for k in range(len(lst)-1,-1,-1): ans[cnt_lst[lst[k]]-1] = lst[k] cnt_lst[lst[k]] -= 1 return ans n = int(input()) n_lst = list(map(int,input().split())) ans = [0] * len(n_lst) ans = map(str,counting_sort(n_lst,ans,max(n_lst))) print(' '.join(ans))
s720441160
p02260
u253463900
1,000
131,072
Wrong Answer
20
7,576
407
Write a program of the Selection Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode: SelectionSort(A) 1 for i = 0 to A.length-1 2 mini = i 3 for j = i to A.length-1 4 if A[j] < A[mini] 5 mini = j 6 swap A[i] and A[mini] Note that, indices for array elements are based on 0-origin. Your program should also print the number of swap operations defined in line 6 of the pseudocode in the case where i ≠ mini.
n = int(input()) s = input() A = list(map(int,s.split())) flag = 1 cnt = 0 ##################################### for i in range(0,n): minj = i for j in range(i,n): if A[j] < A[minj]: minj = j tmp = A[i] A[i] = A[minj] A[minj] = tmp cnt += 1 ##################################### for k in range(0,len(A)-1): print(A[k],end=" ") print(A[len(A)-1]) print (cnt)
s169861933
Accepted
20
7,604
448
n = int(input()) s = input() A = list(map(int,s.split())) flag = 1 cnt = 0 ##################################### for i in range(0,n): minj = i for j in range(i,n): if A[j] < A[minj]: minj = j if(A[i] != A[minj]): tmp = A[i] A[i] = A[minj] A[minj] = tmp cnt += 1 ##################################### for k in range(0,len(A)-1): print(A[k],end=" ") print(A[len(A)-1]) print (cnt)
s284131854
p02612
u655501463
2,000
1,048,576
Wrong Answer
25
9,144
41
We will buy a product for N yen (the currency of Japan) at a shop. If we use only 1000-yen bills to pay the price, how much change will we receive? Assume we use the minimum number of bills required.
n = int(input()) ans = 1000 - (n % 1000)
s463784831
Accepted
30
9,052
56
n = int(input()) ans = (1000 - n%1000)%1000 print(ans)
s461491687
p03657
u275861030
2,000
262,144
Wrong Answer
17
2,940
129
Snuke is giving cookies to his three goats. He has two cookie tins. One contains A cookies, and the other contains B cookies. He can thus give A cookies, B cookies or A+B cookies to his goats (he cannot open the tins). Your task is to determine whether Snuke can give cookies to his three goats so that each of them can have the same number of cookies.
a, b = map(int, input().split()) if a % 3 == 0 or b % 3 == 0 or (a+b) % 3 ==0: print('possible') else: print('impossible')
s438367582
Accepted
17
2,940
130
a, b = map(int, input().split()) if a % 3 == 0 or b % 3 == 0 or (a+b) % 3 ==0: print('Possible') else: print('Impossible')