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
s839161517
p02264
u564464686
1,000
131,072
Wrong Answer
20
5,604
394
_n_ _q_ _name 1 time1_ _name 2 time2_ ... _name n timen_ In the first line the number of processes _n_ and the quantum _q_ are given separated by a single space. In the following _n_ lines, names and times for the _n_ processes are given. _name i_ and _time i_ are separated by a single space.
s=0 A=input().split() n=(int)(A[0]) t=(int)(A[1]) x=[0 for i in range(2*n)] for i in range(n): B=input().split() k=2*i x[k]=(B[0]) x[k+1]=(int)(B[1]) while len(x)>0: s=x[1]-t if s>0: sum=t x.append(x[0]) x.append(s) del x[0] del x[0] if s<=0: sum+=x[1] print( x[0],":",sum) del x[0] del x[0]
s926425072
Accepted
2,110
9,456
396
sum=0 s=0 A=input().split() n=(int)(A[0]) t=(int)(A[1]) x=[0 for i in range(2*n)] for i in range(n): B=input().split() k=2*i x[k]=(B[0]) x[k+1]=(int)(B[1]) while len(x)>0: s=x[1]-t if s>0: sum+=t x.append(x[0]) x.append(s) del x[0] del x[0] if s<=0: sum+=x[1] print( x[0],sum) del x[0] del x[0]
s545690776
p03129
u494151155
2,000
1,048,576
Wrong Answer
17
2,940
92
Determine if we can choose K different integers between 1 and N (inclusive) so that no two of them differ by 1.
N,K = [int(_) for _ in input().split()] if N/2 >= K: print("YES") else: print("NO")
s855027244
Accepted
17
2,940
96
N,K = [int(_) for _ in input().split()] if N >= K*2 - 1: print("YES") else: print("NO")
s765367054
p02389
u623275452
1,000
131,072
Wrong Answer
20
7,500
53
Write a program which calculates the area and perimeter of a given rectangle.
a,b = map(int,input().split()) print(int(a) * int(b))
s365816041
Accepted
20
7,592
69
a,b = map(int,input().split()) c = a + b print(int(a) * int(b),c * 2)
s113999284
p03473
u672898046
2,000
262,144
Wrong Answer
17
2,940
28
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
i = int(input()) print(i+24)
s526824128
Accepted
17
2,940
33
i = int(input()) print((24-i)+24)
s208610730
p03503
u282228874
2,000
262,144
Wrong Answer
316
3,188
383
Joisino is planning to open a shop in a shopping street. Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole period. Naturally, a shop must be open during at least one of those periods. There are already N stores in the street, numbered 1 through N. You are given information of the business hours of those shops, F_{i,j,k}. If F_{i,j,k}=1, Shop i is open during Period k on Day j (this notation is explained below); if F_{i,j,k}=0, Shop i is closed during that period. Here, the days of the week are denoted as follows. Monday: Day 1, Tuesday: Day 2, Wednesday: Day 3, Thursday: Day 4, Friday: Day 5. Also, the morning is denoted as Period 1, and the afternoon is denoted as Period 2. Let c_i be the number of periods during which both Shop i and Joisino's shop are open. Then, the profit of Joisino's shop will be P_{1,c_1}+P_{2,c_2}+...+P_{N,c_N}. Find the maximum possible profit of Joisino's shop when she decides whether her shop is open during each period, making sure that it is open during at least one period.
from itertools import product n = int(input()) F = [list(map(int,input().split())) for i in range(n)] P = [list(map(int,input().split())) for i in range(n)] ans = [] for p in product([0,1],repeat = 10): if sum(p) == 0: continue res = 0 for i in range(n): cnt = 0 for j in range(10): if p[j] == 1: cnt += F[i][j] res += P[i][cnt] ans.append(res) print(max(ans))
s742959438
Accepted
223
3,064
376
from itertools import product n = int(input()) F = [list(map(int,input().split())) for i in range(n)] P = [list(map(int,input().split())) for i in range(n)] ans = [] for p in product([0,1],repeat = 10): if sum(p) == 0: continue res = 0 for i in range(n): cnt = 0 for j in range(10): if p[j]: cnt += F[i][j] res += P[i][cnt] ans.append(res) print(max(ans))
s644064577
p03473
u928784113
2,000
262,144
Wrong Answer
17
2,940
88
How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
#!/usr/bin/env python # -*- coding utf-8 -*- x = int(input()) print("{}".format(x + 24))
s098666345
Accepted
19
2,940
52
# -*- coding: utf-8 -*- M = int(input()) print(48-M)
s347277026
p03447
u617659131
2,000
262,144
Wrong Answer
20
3,060
45
You went shopping to buy cakes and donuts with X yen (the currency of Japan). First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop. How much do you have left after shopping?
print(int(input())-int(input())-int(input()))
s180279205
Accepted
17
2,940
70
x = int(input()) a = int(input()) b = int(input()) x -= a print(x % b)
s487891121
p00042
u319725914
1,000
131,072
Wrong Answer
20
5,620
637
宝物がたくさん収蔵されている博物館に、泥棒が大きな風呂敷を一つだけ持って忍び込みました。盗み出したいものはたくさんありますが、風呂敷が耐えられる重さが限られており、これを超えると風呂敷が破れてしまいます。そこで泥棒は、用意した風呂敷を破らず且つ最も価値が高くなるようなお宝の組み合わせを考えなくてはなりません。 風呂敷が耐えられる重さ W、および博物館にある個々のお宝の価値と重さを読み込んで、重さの総和が W を超えない範囲で価値の総和が最大になるときの、お宝の価値総和と重さの総和を出力するプログラムを作成してください。ただし、価値の総和が最大になる組み合わせが複数あるときは、重さの総和が小さいものを出力することとします。
from sys import stdin case = 0 while(True): case += 1 W = int(stdin.readline()) if not W: break print("Case %d"%case) N = int(stdin.readline()) v = [0] * N w = [0] * N dp = [[0]*(W + 1) for _ in range(N + 1)] for k in range(N): v[k], w[k] = map(int, stdin.readline().split(",")) for i in range(N-1,-1,-1): for j in range(W+1): if j < w[i]: dp[i][j] = dp[i + 1][j] else: dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]) print(dp[0][W]) for i in range(W+1): if dp[0][i] == dp[0][W]: print(i); break
s828116728
Accepted
1,070
17,252
638
from sys import stdin case = 0 while(True): case += 1 W = int(stdin.readline()) if not W: break print("Case %d:"%case) N = int(stdin.readline()) v = [0] * N w = [0] * N dp = [[0]*(W + 1) for _ in range(N + 1)] for k in range(N): v[k], w[k] = map(int, stdin.readline().split(",")) for i in range(N-1,-1,-1): for j in range(W+1): if j < w[i]: dp[i][j] = dp[i + 1][j] else: dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]) print(dp[0][W]) for i in range(W+1): if dp[0][i] == dp[0][W]: print(i); break
s939723107
p04043
u422242631
2,000
262,144
Wrong Answer
17
2,940
179
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.
A,B,C = list(input().split()) count = 0 if A == "7": count += 1 if B == "7": count += 1 if C == "7": count += 1 if count == 1: print("Yes") else: print("No")
s209764526
Accepted
17
2,940
116
A = list(map(int, input().split())) if A.count(7) == 1 and A.count(5) == 2: print("YES") else: print("NO")
s226755694
p03623
u023077142
2,000
262,144
Wrong Answer
17
2,940
101
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()) if abs(x - a) > abs(x - b): print("A") else: print("B")
s077556362
Accepted
17
2,940
101
x, a, b = map(int, input().split()) if abs(x - a) < abs(x - b): print("A") else: print("B")
s407942528
p02843
u963915126
2,000
1,048,576
Wrong Answer
29
9,056
207
AtCoder Mart sells 1000000 of each of the six items below: * Riceballs, priced at 100 yen (the currency of Japan) each * Sandwiches, priced at 101 yen each * Cookies, priced at 102 yen each * Cakes, priced at 103 yen each * Candies, priced at 104 yen each * Computers, priced at 105 yen each Takahashi wants to buy some of them that cost exactly X yen in total. Determine whether this is possible. (Ignore consumption tax.)
ni = lambda: int(input()) nm = lambda: map(int, input().split()) nl = lambda: list(map(int, input().split())) from math import ceil x=ni() p=x%100 if ceil(p/5) <= x//100: print('Yes') else: print('No')
s299353071
Accepted
29
9,108
200
ni = lambda: int(input()) nm = lambda: map(int, input().split()) nl = lambda: list(map(int, input().split())) from math import ceil x=ni() p=x%100 if ceil(p/5) <= x//100: print(1) else: print(0)
s867551671
p00049
u078042885
1,000
131,072
Wrong Answer
20
7,348
150
ある学級の生徒の出席番号と ABO 血液型を保存したデータを読み込んで、おのおのの血液型の人数を出力するプログラムを作成してください。なお、ABO 血液型には、A 型、B 型、AB 型、O 型の4種類の血液型があります。
a={'A':0,'B':0,'O':0,'AB':0} while 1: try: _,b=input().split(",") a[b]+=1 except: for i in a:print(a[i]) break
s984294896
Accepted
20
7,340
167
a={'A':0,'B':0,'O':0,'AB':0} while 1: try: _,b=input().split(",") a[b]+=1 except: for i in ['A','B','AB','O']:print(a[i]) break
s605148981
p03645
u662613022
2,000
262,144
Wrong Answer
703
30,852
311
In Takahashi Kingdom, there is an archipelago of N islands, called Takahashi Islands. For convenience, we will call them Island 1, Island 2, ..., Island N. There are M kinds of regular boat services between these islands. Each service connects two islands. The i-th service connects Island a_i and Island b_i. Cat Snuke is on Island 1 now, and wants to go to Island N. However, it turned out that there is no boat service from Island 1 to Island N, so he wants to know whether it is possible to go to Island N by using two boat services. Help him.
N,M = map(int,input().split()) li = [] numb = [] ans = '' for i in range(M): li.append(tuple(map(int,input().split()))) if li[i][0] == 1: numb.append(i) for i in range(M): if li[i][0] in numb and li[i][1] == N: ans = 'POSSIBLE' break if ans == '': print('IMPOSSIBLE') else: print(ans)
s271211059
Accepted
568
21,844
274
N,M = map(int,input().split()) li = [] numb = [] for i in range(M): a,b = map(int,input().split()) if a == 1: li.append(b) elif b == N: numb.append(a) ans = set(li) & set(numb) if len(ans) >= 1: print('POSSIBLE') else: print('IMPOSSIBLE')
s305956571
p03795
u138486156
2,000
262,144
Wrong Answer
17
2,940
41
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(n*800 - n*200//15)
s535306651
Accepted
17
2,940
43
n = int(input()) print(n*800 - (n//15)*200)
s859935135
p02534
u667469290
2,000
1,048,576
Wrong Answer
25
9,072
115
You are given an integer K. Print the string obtained by repeating the string `ACL` K times and concatenating them. For example, if K = 3, print `ACLACLACL`.
# -*- coding: utf-8 -*- def solve(): return 'ALC'*int(input()) if __name__ == '__main__': print(solve())
s670311584
Accepted
24
9,136
115
# -*- coding: utf-8 -*- def solve(): return 'ACL'*int(input()) if __name__ == '__main__': print(solve())
s740624801
p02279
u637322311
2,000
131,072
Wrong Answer
20
5,612
1,058
A graph _G_ = ( _V_ , _E_ ) is a data structure where _V_ is a finite set of vertices and _E_ is a binary relation on _V_ represented by a set of edges. Fig. 1 illustrates an example of a graph (or graphs). **Fig. 1** A free tree is a connnected, acyclic, undirected graph. A rooted tree is a free tree in which one of the vertices is distinguished from the others. A vertex of a rooted tree is called "node." Your task is to write a program which reports the following information for each node _u_ of a given rooted tree _T_ : * node ID of _u_ * parent of _u_ * depth of _u_ * node type (root, internal node or leaf) * a list of chidlren of _u_ If the last edge on the path from the root _r_ of a tree _T_ to a node _x_ is ( _p_ , _x_ ), then _p_ is the **parent** of _x_ , and _x_ is a **child** of _p_. The root is the only node in _T_ with no parent. A node with no children is an **external node** or **leaf**. A nonleaf node is an **internal node** The number of children of a node _x_ in a rooted tree _T_ is called the **degree** of _x_. The length of the path from the root _r_ to a node _x_ is the **depth** of _x_ in _T_. Here, the given tree consists of _n_ nodes and evey node has a unique ID from 0 to _n_ -1. Fig. 2 shows an example of rooted trees where ID of each node is indicated by a number in a circle (node). The example corresponds to the first sample input. **Fig. 2**
from sys import stdin class Node(object): def __init__(self, parent=None, children=None, name=None, depth=None): self.parent = parent self.children = children self.name = name self.depth = depth def set_depth(nodes, u): p = nodes[u].parent d = nodes[p].depth if d != None: nodes[u].depth = d + 1 def read_rooted_tree(n, nodes): for _ in range(n): i = [int(i) for i in stdin.readline().strip().split()] c = i[2:len(i)] nodes[i[0]].children = c if c: nodes[i[0]].name = "internal node" else: nodes[i[0]].name = "leaf" for j in nodes[i[0]].children: nodes[j].parent = i[0] set_depth(nodes, i[0]) n = int(input()) nodes = [Node() for _ in range(n)] nodes[0].parent = -1 nodes[0].depth = 0 nodes[0].name = "root" read_rooted_tree(n, nodes) for i in range(n): print("node {0}: parent = {1}, depth = {2}, {3}, {4}".format( i, nodes[i].parent, nodes[i].depth, nodes[i].name, nodes[i].children))
s090739079
Accepted
880
35,712
1,167
from sys import stdin class Node(object): def __init__(self, parent=None, children=None, name=None): self.parent = parent self.children = children self.name = name def print_nodes(nodes, n): def get_depth(nodes, u): p = nodes[u].parent nonlocal d if p != None and p != -1: get_depth(nodes, p) d += 1 return d for i in range(n): d = 0 if nodes[i].parent == None: nodes[i].parent = -1 nodes[i].name = "root" print("node {0}: parent = {1}, depth = {2}, {3}, {4}".format( i, nodes[i].parent, get_depth(nodes, i), nodes[i].name, nodes[i].children)) def read_rooted_tree(nodes, n): for _ in range(n): i = [int(i) for i in stdin.readline().strip().split()] c = i[2:len(i)] nodes[i[0]].children = c if c: nodes[i[0]].name = "internal node" else: nodes[i[0]].name = "leaf" for j in nodes[i[0]].children: nodes[j].parent = i[0] n = int(input()) nodes = [Node() for _ in range(n)] read_rooted_tree(nodes, n) print_nodes(nodes, n)
s419106254
p03130
u519939795
2,000
1,048,576
Wrong Answer
17
3,064
295
There are four towns, numbered 1,2,3 and 4. Also, there are three roads. The i-th road connects different towns a_i and b_i bidirectionally. No two roads connect the same pair of towns. Other than these roads, there is no way to travel between these towns, but any town can be reached from any other town using these roads. Determine if we can visit all the towns by traversing each of the roads exactly once.
a1,b1=map(int,input().split()) a2,b2=map(int,input().split()) a3,b3=map(int,input().split()) l=[] l.append(a1) l.append(b1) l.append(a2) l.append(b2) l.append(a3) l.append(b3) print(l) if l.count(1)==1 and l.count(4)==1 and l.count(2)==2 and l.count(3)==2: print('YES') else: print('NO')
s285324704
Accepted
18
3,060
172
li=[0]*4 for i in range(3): a,b=map(int,input().split()) li[a-1]+=1 li[b-1]+=1 if li.count(1)==2 and li.count(2)==2: print('YES') else: print('NO')
s743153657
p03155
u433195318
2,000
1,048,576
Wrong Answer
17
2,940
6
It has been decided that a programming contest sponsored by company A will be held, so we will post the notice on a bulletin board. The bulletin board is in the form of a grid with N rows and N columns, and the notice will occupy a rectangular region with H rows and W columns. How many ways are there to choose where to put the notice so that it completely covers exactly HW squares?
3 2 3
s317787236
Accepted
38
5,344
624
import sys import math import fractions import bisect import queue import heapq from collections import deque sys.setrecursionlimit(4100000) MOD = int(1e9+7) PI = 3.14159265358979323846264338327950288 INF = 1e18 N = int(input()) H = int(input()) W = int(input()) print((N-H+1)*(N-W+1))
s373193677
p02844
u408375121
2,000
1,048,576
Wrong Answer
2,104
3,064
334
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()) s = input() ans = 0 for a in range(10): for b in range(10): for c in range(10): for i in range(n-2): if s[i] == str(a): for j in range(i+1, n-1): if s[j] == str(b): for k in range(j+1, n): if s[k] == str(c): ans += 1 print(ans)
s657570992
Accepted
47
8,932
438
n = int(input()) s = input() before = [[-1] * 10] for i in range(n): c = s[i] num = int(c) hoge = before[-1][::] hoge[num] = i before.append(hoge) ans = 0 for i in range(10): now = before[-1][i] if now == -1: continue for j in range(10): now2 = before[now][j] if now2 == -1: continue for k in range(10): now3 = before[now2][k] if now3 == -1: continue ans += 1 print(ans)
s127765739
p03163
u693173434
2,000
1,048,576
Wrong Answer
204
29,676
209
There are N items, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i. Taro has decided to choose some of the N items and carry them home in a knapsack. The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W. Find the maximum possible sum of the values of items that Taro takes home.
import numpy as np N, W = map(int, input().split()) dp = np.zeros(W+1) for i in range(N): w, v = map(int, input().split()) dp[w:] = np.maximum(dp[w:], dp[:-w] + v) print(dp) print(int(dp.max()))
s934932469
Accepted
180
29,744
195
import numpy as np N, W = map(int, input().split()) dp = np.zeros(W+1) for i in range(N): w, v = map(int, input().split()) dp[w:] = np.maximum(dp[w:], dp[:-w] + v) print(int(dp.max()))
s757384374
p02665
u801701525
2,000
1,048,576
Wrong Answer
94
20,180
363
Given is an integer sequence of length N+1: A_0, A_1, A_2, \ldots, A_N. Is there a binary tree of depth N such that, for each d = 0, 1, \ldots, N, there are exactly A_d leaves at depth d? If such a tree exists, print the maximum possible number of vertices in such a tree; otherwise, print -1.
import math N = int(input()) leaf = list(map(int,input().split())) end_flag = False count = sum(leaf) ans = 0 node = 1 for i in range(N+1): if end_flag: break ans += node count -= leaf[i] node = min(count, (node-leaf[i])*2) if node < 0: end_flag = True if end_flag: print('-1') else: print(1+sum(leaf)-leaf[N]+N*2)
s516962379
Accepted
94
20,076
343
import math N = int(input()) leaf = list(map(int,input().split())) end_flag = False count = sum(leaf) ans = 0 node = 1 for i in range(N+1): if end_flag: break ans += node count -= leaf[i] node = min(count, (node-leaf[i])*2) if node < 0: end_flag = True if end_flag: print('-1') else: print(ans)
s416512864
p02612
u962024525
2,000
1,048,576
Wrong Answer
29
9,120
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.
m=int(input()) print(m%1000)
s892842237
Accepted
25
9,096
40
m=int(input()) print((1000-m%1000)%1000)
s736442952
p02402
u921038488
1,000
131,072
Wrong Answer
20
5,600
397
Write a program which reads a sequence of $n$ integers $a_i (i = 1, 2, ... n)$, and prints the minimum value, maximum value and sum of the sequence.
def bubble_sort(l): N = len(l) isChange = True while isChange: isChange = False for i in range(N-1): if(l[i] > l[i+1]): l[i], l[i+1] = l[i+1], l[i] isChange = True return l N = int(input()) l = input().split() L = bubble_sort(l) sum = 0 for k in L: n = int(k) sum += n print("{} {} {}".format(L[0], L[-1], sum))
s348922162
Accepted
20
6,548
102
N = input() l = map(int, input().split()) l = list(l) print("{} {} {}".format(min(l), max(l), sum(l)))
s221472186
p03997
u545666277
2,000
262,144
Wrong Answer
17
2,940
114
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.
# -*- coding: utf-8 -*- a = int(input()) b = int(input()) h = int(input()) print( ((a+b)*h)/2)
s050406628
Accepted
17
2,940
120
# -*- coding: utf-8 -*- a = int(input()) b = int(input()) h = int(input()) print( int(((a+b)*h)/2) )
s580637257
p03353
u644972721
2,000
1,048,576
Wrong Answer
33
3,188
484
You are given a string s. Among the **different** substrings of s, print the K-th lexicographically smallest one. A substring of s is a string obtained by taking out a non-empty contiguous part in s. For example, if s = `ababc`, `a`, `bab` and `ababc` are substrings of s, while `ac`, `z` and an empty string are not. Also, we say that substrings are different when they are different as strings. Let X = x_{1}x_{2}...x_{n} and Y = y_{1}y_{2}...y_{m} be two distinct strings. X is lexicographically larger than Y if and only if Y is a prefix of X or x_{j} > y_{j} where j is the smallest integer such that x_{j} \neq y_{j}.
s = list(input()) k = int(input()) t = sorted(s) u = [] v = [] for i in range(min(len(s), 5)): u.append(t[i]) for i in range(len(s)): if s[i] in u: if not [s[i]] in v: v.append([s[i]]) l = [s[i]] for j in range(1, 5): if i + j == len(s): break l = l + [s[i + j]] if not l in v: v.append(l) for i in range(len(v)): v[i] = "".join(v[i]) v.sort() print(v[k - 1]) print(v)
s686266044
Accepted
34
3,188
475
s = list(input()) k = int(input()) t = sorted(s) u = [] v = [] for i in range(min(len(s), 5)): u.append(t[i]) for i in range(len(s)): if s[i] in u: if not [s[i]] in v: v.append([s[i]]) l = [s[i]] for j in range(1, 5): if i + j == len(s): break l = l + [s[i + j]] if not l in v: v.append(l) for i in range(len(v)): v[i] = "".join(v[i]) v.sort() print(v[k - 1])
s949965535
p03049
u673338219
2,000
1,048,576
Wrong Answer
48
3,064
503
Snuke has N strings. The i-th string is s_i. Let us concatenate these strings into one string after arranging them in some order. Find the maximum possible number of occurrences of `AB` in the resulting string.
n = int(input()) c = 0 xa = 0 bx = 0 ba = 0 for _ in range(n): si = str(input()) l = len(si) s1 = si[0] s2 = si[-1] if s1=="B": if s2=="A": ba += 1 else: bx += 1 elif s2 == "A": xa += 1 for i in range(l-1): if si[i]=="A" and si[i+1]=="B": c += 1 print(c,ba,bx,xa) if ba == 0: print(c+min(bx,xa)) exit() if bx == 0: if xa == 0: print(ba-1+c) exit() else: print(ba+c) exit() if xa == 0: print(ba+c) exit() print(min(bx,xa)+ba+c)
s412883371
Accepted
48
3,188
485
n = int(input()) c = 0 xa = 0 bx = 0 ba = 0 for _ in range(n): si = str(input()) l = len(si) s1 = si[0] s2 = si[-1] if s1=="B": if s2=="A": ba += 1 else: bx += 1 elif s2 == "A": xa += 1 for i in range(l-1): if si[i]=="A" and si[i+1]=="B": c += 1 if ba == 0: print(c+min(bx,xa)) exit() if bx == 0: if xa == 0: print(ba-1+c) exit() else: print(ba+c) exit() if xa == 0: print(ba+c) exit() print(min(bx,xa)+ba+c)
s218529321
p03486
u134519179
2,000
262,144
Wrong Answer
17
2,940
108
You are given strings s and t, consisting of lowercase English letters. You will create a string s' by freely rearranging the characters in s. You will also create a string t' by freely rearranging the characters in t. Determine whether it is possible to satisfy s' < t' for the lexicographic order.
s = input() t = input() s = sorted(s) t = sorted(t)[::-1] if s < t: print('YES') else: print('NO')
s195522725
Accepted
17
2,940
108
s = input() t = input() s = sorted(s) t = sorted(t)[::-1] if s < t: print('Yes') else: print('No')
s402129136
p03433
u789791593
2,000
262,144
Wrong Answer
17
2,940
125
E869120 has A 1-yen coins and infinitely many 500-yen coins. Determine if he can pay exactly N yen using only these coins.
# coding: utf-8 N_yen = int(input()) A_1mai = int(input()) answer = 'YES' if N_yen % 500 <= A_1mai else 'NO' print(answer)
s806408161
Accepted
17
2,940
125
# coding: utf-8 N_yen = int(input()) A_1mai = int(input()) answer = 'Yes' if N_yen % 500 <= A_1mai else 'No' print(answer)
s375425310
p03149
u410118019
2,000
1,048,576
Wrong Answer
18
2,940
65
You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
n = set(map(int,input().split())) print('YNeos'[n!={1,9,7,4}::2])
s693535243
Accepted
17
2,940
65
n = set(map(int,input().split())) print('YNEOS'[n!={1,9,7,4}::2])
s166382357
p03815
u870518235
2,000
262,144
Wrong Answer
29
9,000
99
Snuke has decided to play with a six-sided die. Each of its six sides shows an integer 1 through 6, and two numbers on opposite sides always add up to 7. Snuke will first put the die on the table with an arbitrary side facing upward, then repeatedly perform the following operation: * Operation: Rotate the die 90° toward one of the following directions: left, right, front (the die will come closer) and back (the die will go farther). Then, obtain y points where y is the number written in the side facing upward. For example, let us consider the situation where the side showing 1 faces upward, the near side shows 5 and the right side shows 4, as illustrated in the figure. If the die is rotated toward the right as shown in the figure, the side showing 3 will face upward. Besides, the side showing 4 will face upward if the die is rotated toward the left, the side showing 2 will face upward if the die is rotated toward the front, and the side showing 5 will face upward if the die is rotated toward the back. Find the minimum number of operation Snuke needs to perform in order to score at least x points in total.
x = int(input()) if x % 11 == 0: ans = (x // 11)*2 else: ans = (x // 11)*2 + 1 print(ans)
s106859526
Accepted
26
9,124
152
x = int(input()) X = x % 11 N = x // 11 ans = 0 if 1 <= X <= 6: ans = N*2 + 1 elif 7 <= X <= 10: ans = N*2 + 2 else: ans = N*2 print(ans)
s716757690
p03910
u879309973
2,000
262,144
Wrong Answer
18
3,444
220
The problem set at _CODE FESTIVAL 20XX Finals_ consists of N problems. The score allocated to the i-th (1≦i≦N) problem is i points. Takahashi, a contestant, is trying to score exactly N points. For that, he is deciding which problems to solve. As problems with higher scores are harder, he wants to minimize the highest score of a problem among the ones solved by him. Determine the set of problems that should be solved.
def solve(n): score = 0 res = [] for p in range(1, n+1): res.append(p) score += p if score >= n: break return "\n".join(map(str, res)) n = int(input()) print(solve(n))
s001581030
Accepted
18
3,444
253
def solve(n): score = 0 for p in range(1, n+1): score += p if score >= n: break x = score - n res = list(range(1,x)) + list(range(x+1,p+1)) return "\n".join(map(str, res)) n = int(input()) print(solve(n))
s524161621
p02578
u186397299
2,000
1,048,576
Wrong Answer
229
25,236
218
N persons are standing in a row. The height of the i-th person from the front is A_i. We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person: Condition: Nobody in front of the person is taller than the person. Here, the height of a person includes the stool. Find the minimum total height of the stools needed to meet this goal.
N = int(input('')) A = input('') A_N = A.split() num = 0 for i in range(1,N): if int(A_N[i]) >= int(A_N[i-1]): num += 0 elif (A_N[i]) < (A_N[i-1]): num += int(A_N[i-1]) - int(A_N[i]) print(num)
s611402676
Accepted
169
33,596
246
N = int(input('')) A = input('') a_n = A.split() A_N = list(map(int, a_n)) num = 0 for i in range(1,N): if A_N[i] >= A_N[i-1]: num += 0 elif A_N[i] < A_N[i-1]: num += A_N[i-1] - A_N[i] A_N[i] = A_N[i-1] print(num)
s611419958
p03434
u290187182
2,000
262,144
Wrong Answer
18
3,060
313
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.
if __name__ == '__main__': n = int(input()) k = [int(i) for i in input().split()] a = 0 b = 0 k.sort(reverse=True) print(k) flag = True for i in k: if flag == True: a+=i flag=False else: b+=i flag=True print(a-b)
s294369289
Accepted
17
3,060
300
if __name__ == '__main__': n = int(input()) k = [int(i) for i in input().split()] a = 0 b = 0 k.sort(reverse=True) flag = True for i in k: if flag == True: a+=i flag=False else: b+=i flag=True print(a-b)
s225823716
p03352
u460468647
2,000
1,048,576
Wrong Answer
17
3,064
197
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
x = int(input()) lst = [i**2 for i in range(1,32)]+[8,27,125,216,343,512,1000]+[32,243]+[128]+[1001] lst.sort() print(lst) for i in range(len(lst)): if lst[i]<=x<lst[i+1]: print(lst[i])
s240307795
Accepted
17
3,060
186
x = int(input()) lst = [i**2 for i in range(1,32)]+[8,27,125,216,343,512,1000]+[32,243]+[128]+[1001] lst.sort() for i in range(len(lst)): if lst[i]<=x<lst[i+1]: print(lst[i])
s288906819
p03861
u893931781
2,000
262,144
Wrong Answer
17
2,940
120
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?
li=list(map(int,input().split())) min=li[0]//li[2] max=li[1]//li[2] count=max-min if li[0]==0: count+=1 print(count)
s717466995
Accepted
17
3,060
126
li=list(map(int,input().split())) min=li[0]//li[2] max=li[1]//li[2] count=max-min if li[0]%li[2]==0: count+=1 print(count)
s227380923
p04029
u036363750
2,000
262,144
Wrong Answer
18
2,940
156
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?
#!/usr/bin/env python3 def main(): a = int(input()) if a%2==0: print((a+1)*a/2) else: print((a+1)*a/2+(a+1)/2) if __name__=='__main__':main()
s245796174
Accepted
17
2,940
111
#!/usr/bin/env python3 def main(): a = int(input()) print(int(((a+1)*a)/2)) if __name__=='__main__':main()
s918277165
p03502
u136869985
2,000
262,144
Wrong Answer
17
2,940
70
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=input() t=sum(map(int, list(N))) print("Yes" if int(N)==t else "No")
s440117808
Accepted
17
2,940
109
X = input() fx = 0 for x in X: fx += int(x) if int(X) % fx == 0: print("Yes") else: print("No")
s771034287
p03576
u155687575
2,000
262,144
Wrong Answer
2,104
3,188
762
We have N points in a two-dimensional plane. The coordinates of the i-th point (1 \leq i \leq N) are (x_i,y_i). Let us consider a rectangle whose sides are parallel to the coordinate axes that contains K or more of the N points in its interior. Here, points on the sides of the rectangle are considered to be in the interior. Find the minimum possible area of such a rectangle.
n, k = map(int,input().split()) xs = [] ys = [] points = [] for _ in range(n): x, y = map(int, input().split()) xs.append(x) ys.append(y) points.append((x, y)) for leftx in xs: for rightx in xs: if leftx >= rightx: continue for downy in ys: for upy in ys: if downy >= upy: continue min_ = float('inf') for tx, ty in points: if (leftx <= tx <= rightx) and (downy <= ty <= upy): yoko = rightx - leftx tate = upy - downy men = yoko*tate if men < min_: min_ = men print(min_)
s834248909
Accepted
26
3,064
638
n, k = map(int,input().split()) ps = [tuple(map(int,input().split())) for i in range(n)] sx = sorted(ps,key = lambda x: x[0]) nx = list(enumerate(sx)) ans = 5e18 for f, (x1,y1) in nx[:n-k+1]: for e, (x2,y2) in nx[f+k-1:]: dx = x2 - x1 sy = sorted(y for x,y in sx[f:e+1]) for y3,y4 in zip(sy,sy[k-1:]): if y3 <= y1 and y4 >= y2: ans = min(ans, dx * (y4 - y3)) print(ans)
s527099700
p03494
u408375121
2,000
262,144
Wrong Answer
20
3,316
191
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.
N = int(input()) A = list(map(int, input().split())) B = [] for a in A: i = 0 while True: if a % 2 ** i == 0: i += 1 else: B.append(i) break B.sort() print(B[0])
s922104332
Accepted
21
2,940
155
N = int(input()) A = list(map(int, input().split())) B = [] for a in A: i = 0 while a % 2 ** i == 0: i += 1 B.append(i - 1) B.sort() print(B[0])
s382148318
p03545
u240793404
2,000
262,144
Wrong Answer
17
3,060
197
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.
n = list(input()) for i in range(8): ans = n[0] ans += '+-'[i%2] + n[1] ans += '+-'[i//4] + n[2] ans += '+-'[(i%4)//2] + n[3] if eval(ans) == 7: print(ans) break
s851468430
Accepted
17
3,060
202
n = list(input()) for i in range(8): ans = n[0] ans += '+-'[i%2] + n[1] ans += '+-'[i//4] + n[2] ans += '+-'[(i%4)//2] + n[3] if eval(ans) == 7: print(ans+"=7") break
s172240036
p03139
u738037409
2,000
1,048,576
Wrong Answer
18
2,940
73
We conducted a survey on newspaper subscriptions. More specifically, we asked each of the N respondents the following two questions: * Question 1: Are you subscribing to Newspaper X? * Question 2: Are you subscribing to Newspaper Y? As the result, A respondents answered "yes" to Question 1, and B respondents answered "yes" to Question 2. What are the maximum possible number and the minimum possible number of respondents subscribing to both newspapers X and Y? Write a program to answer this question.
N, A, B = map(int, input().split()) print(min(A, B), max(0, N - (A + B)))
s024264408
Accepted
17
2,940
73
N, A, B = map(int, input().split()) print(min(A, B), max(0, (A + B) - N))
s341488543
p03049
u305422591
2,000
1,048,576
Wrong Answer
36
3,064
408
Snuke has N strings. The i-th string is s_i. Let us concatenate these strings into one string after arranging them in some order. Find the maximum possible number of occurrences of `AB` in the resulting string.
N = int(input()) res = 0 both = 0 head = 0 last = 0 for i in range(N): inp = input() if 'AB' in inp: res += 1 if 'B'==inp[0] and 'A'==inp[-1]: both+=1 elif 'B'==inp[0]: head+=1 elif 'A'==inp[-1]: last += 1 res += max(0,both -1) if head > 0 and last >0: res += 2 + min(head-1,last-1) elif head>0: res += 1 + min(head-1,last) elif last>0: res += 1 + min(head,last-1) print(res)
s374227876
Accepted
81
3,700
592
n=int(input()) s=[0]*n ct=0 a=0 b=0 c=0 for i in range(n): s[i]=input() for i in range(n): for j in range(len(s[i])): t=s[i] ts=list(t) ts.append(0) if ts[j]=='A' and ts[j+1]=='B': ct+=1 if ts[0]=='B' and ts[len(s[i])-1]!='A': a+=1 if ts[len(s[i])-1]=='A' and ts[0]!='B': b+=1 if ts[0]=='B' and ts[len(s[i])-1]=='A': c+=1 ct += max(0,c -1) if c !=0: if a > 0 and b >0: ct += 2 + min(a-1,b-1) elif a>0: ct += 1 + min(a-1,b) elif b>0: ct += 1 + min(a,b-1) else: ct += min(a,b) print(ct)
s008426649
p03760
u836737505
2,000
262,144
Time Limit Exceeded
2,104
17,172
121
Snuke signed up for a new website which holds programming competitions. He worried that he might forget his password, and he took notes of it. Since directly recording his password would cause him trouble if stolen, he took two notes: one contains the characters at the odd-numbered positions, and the other contains the characters at the even-numbered positions. You are given two strings O and E. O contains the characters at the odd- numbered positions retaining their relative order, and E contains the characters at the even-numbered positions retaining their relative order. Restore the original password.
o = list(input()) e = list(input()) c = "" for i in range(len(o)): c += o[i] while e: c += e[i] print(c)
s210674291
Accepted
17
2,940
127
o = list(input()) e = list(input()) c = "" for i in range(len(o)): c += o[i] if i < len(e): c += e[i] print(c)
s205416010
p03759
u962718741
2,000
262,144
Wrong Answer
26
9,080
161
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.
#!/usr/bin/env python3 def main(): a, b, c = map(int, input().split()) print("YES" if b - a == c - a else "NO") if __name__ == "__main__": main()
s772607588
Accepted
27
9,080
161
#!/usr/bin/env python3 def main(): a, b, c = map(int, input().split()) print("YES" if b - a == c - b else "NO") if __name__ == "__main__": main()
s556354746
p03971
u857673087
2,000
262,144
Wrong Answer
97
4,016
177
There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these. Only Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests. * A Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B. * An overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B and the student ranks B-th or above among all overseas students. A string S is assigned indicating attributes of all participants. If the i-th character of string S is `a`, this means the participant ranked i-th in the Qualification contests is a Japanese student; `b` means the participant ranked i-th is an overseas student; and `c` means the participant ranked i-th is neither of these. Write a program that outputs for all the participants in descending rank either `Yes` if they passed the Qualification contests or `No` if they did not pass.
N,A,B = map(int,input().split()) S =input() for i in range(N): if S[i]=='a' and i < A+B: print('Yes') elif S[i]=='b' and i < B: print('Yes') else: print('No')
s327524429
Accepted
109
4,016
370
N,A,B = map(int,input().split()) S = input() passed = 0 fo = 1 for i in range(N): if(S[i] == 'a'): if(passed < A+B): print('Yes') passed += 1 else: print('No') elif(S[i] == 'b'): if((passed < A+B)and(fo <= B)): print('Yes') fo += 1 passed += 1 else: print('No') elif(S[i] == 'c'): print('No')
s103034875
p02264
u153665391
1,000
131,072
Wrong Answer
30
7,708
382
_n_ _q_ _name 1 time1_ _name 2 time2_ ... _name n timen_ In the first line the number of processes _n_ and the quantum _q_ are given separated by a single space. In the following _n_ lines, names and times for the _n_ processes are given. _name i_ and _time i_ are separated by a single space.
N, Q = map(int, input().strip().split()) A = [] D = {} for l in range(N): n, t = input().strip().split() D[n] = int(t) A.append(n) print(A) T = 0 d = 0 while True: n = A.pop(0) if D[n] > Q: D[n] -= Q T += Q A.append(n) else: T += D[n] print('{0} {1}'.format(n, T)) d += 1 if d == N: break
s681534583
Accepted
480
24,316
768
N, qms = map(int, input().split()) raw_proc = [input() for i in range(N)] queue = [{} for i in range(N+1)] limit = N+1 for i in range(N): name, time = raw_proc[i].split() time = int(time) queue[i] = {"name": name, "time": time} def enque(tail, p): queue[tail] = p tail = (tail+1) % limit return tail def deque(head): proc = queue[head] head = (head+1) % limit return proc, head if __name__ == '__main__': head = 0 tail = N total_time = 0 while head != tail: p, head = deque(head) t = min(qms, p["time"]) p["time"] = p["time"] - t total_time += t if p["time"] > 0: tail = enque(tail, p) else: print("{} {}".format(p["name"], total_time))
s182872341
p03494
u069129582
2,000
262,144
Time Limit Exceeded
2,104
3,060
155
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.
n=int(input()) a=list(map(int,input().split())) ans=0 while all(j%2==0 for j in a): for k in range(len(a)): a[k]==a[k]//2 ans+=1 print(ans)
s473686405
Accepted
19
3,060
128
n=int(input()) A=list(map(int,input().split())) ans=0 while all(a%2==0 for a in A): A=[a/2 for a in A] ans+=1 print(ans)
s903510583
p03455
u883792993
2,000
262,144
Wrong Answer
17
2,940
106
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a,b = map(int, input().split()) print(a) print(b) if a*b/2 == 1: print("Odd") else: print("Even")
s950282297
Accepted
18
2,940
85
a,b = map(int, input().split()) if a*b%2 == 1: print("Odd") else: print("Even")
s789601449
p03455
u350166773
2,000
262,144
Wrong Answer
17
2,940
96
AtCoDeer the deer found two positive integers, a and b. Determine whether the product of a and b is even or odd.
a, b = map(int, input().split()) if a%2 == 0 and b%2 == 0: print('Even') else: print('Odd')
s405185905
Accepted
17
2,940
84
a, b = map(int, input().split()) if a*b%2 == 0: print('Even') else: print('Odd')
s419882634
p03385
u596536048
2,000
262,144
Wrong Answer
30
9,016
42
You are given a string S of length 3 consisting of `a`, `b` and `c`. Determine if S can be obtained by permuting `abc`.
print('Yes' if 'abc' in input() else 'No')
s908504857
Accepted
29
9,036
136
string = input() if string[0] != string[1] and string[1] != string[2] and string[2] != string[0]: print("Yes") else: print("No")
s420584786
p02844
u102275718
2,000
1,048,576
Wrong Answer
316
21,512
707
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.
import sys input = sys.stdin.readline import numpy as np from math import factorial import itertools def permutations_count(n, r): return factorial(n) // factorial(n - r) def combinations_count(n, r): return factorial(n) // (factorial(n - r) * factorial(r)) n = int(input()) *s, = map(int, list(input().split()[0])) ans = 0 for i in range(1000): num_str = str(i) if i < 100: num_str = '0'+num_str if i<10: num_str = '0'+num_str idx = 0 for j in s: # print(j, idx) if j == int(s[idx]): idx += 1 if idx==3: break if idx == 3: ans += 1 print(ans)
s884435200
Accepted
22
3,064
350
import sys input = sys.stdin.readline n = int(input()) s = input().split()[0] ans = 0 for i in range(1000): num_str = str(i).zfill(3) a = s.find(num_str[0]) if a==-1: continue b = s[a+1:].find(num_str[1]) if b==-1: continue b += a+1 c = s[b+1:].find(num_str[2]) if c!=-1: ans += 1 print(ans)
s456823729
p03378
u569776981
2,000
262,144
Wrong Answer
31
9,168
300
There are N + 1 squares arranged in a row, numbered 0, 1, ..., N from left to right. Initially, you are in Square X. You can freely travel between adjacent squares. Your goal is to reach Square 0 or Square N. However, for each i = 1, 2, ..., M, there is a toll gate in Square A_i, and traveling to Square A_i incurs a cost of 1. It is guaranteed that there is no toll gate in Square 0, Square X and Square N. Find the minimum cost incurred before reaching the goal.
N, M, X = map(int,input().split()) A = list(map(int,input().split())) ans = [] z = 0 y = 0 for i in range(X + 1, N + 1): if i in A: z += 1 print(z) ans.append(z) for i in range(1,X): if i in A: y += 1 print(y) ans.append(y) ans = sorted(ans) print(ans) print(ans[0])
s955543475
Accepted
28
9,184
263
N, M, X = map(int,input().split()) A = list(map(int,input().split())) ans = [] z = 0 y = 0 for i in range(X + 1, N + 1): if i in A: z += 1 ans.append(z) for i in range(1,X): if i in A: y += 1 ans.append(y) ans = sorted(ans) print(ans[0])
s753131466
p04035
u608088992
2,000
262,144
Wrong Answer
2,104
14,052
398
We have N pieces of ropes, numbered 1 through N. The length of piece i is a_i. At first, for each i (1≤i≤N-1), piece i and piece i+1 are tied at the ends, forming one long rope with N-1 knots. Snuke will try to untie all of the knots by performing the following operation repeatedly: * Choose a (connected) rope with a total length of at least L, then untie one of its knots. Is it possible to untie all of the N-1 knots by properly applying this operation? If the answer is positive, find one possible order to untie the knots.
N, L = map(int, input().split()) A = [int(a) for a in input().split()] CanRemain = [] for i in range(N-1): if A[i] + A[i+1] >= L: CanRemain.append(i+1) if not CanRemain: print("impossible") else: print("possible") for i in range(1, CanRemain[-1]): if i not in CanRemain: print(i) for i in reversed(range(CanRemain[-1]+1, N)): print(i) for num in CanRemain: print(num)
s821157096
Accepted
124
14,072
458
import sys def solve(): input = sys.stdin.readline N, L = map(int, input().split()) A = [int(a) for a in input().split()] for i in range(N - 1): if A[i] + A[i+1] >= L: print("Possible") for k in range(i): print(k + 1) for k in reversed(range(i + 1, N - 1)): print(k + 1) print(i + 1) break else: print("Impossible") return 0 if __name__ == "__main__": solve()
s020461434
p03447
u959759457
2,000
262,144
Wrong Answer
18
2,940
61
You went shopping to buy cakes and donuts with X yen (the currency of Japan). First, you bought one cake for A yen at a cake shop. Then, you bought as many donuts as possible for B yen each, at a donut shop. How much do you have left after shopping?
X,A,B=[int(input()) for i in range(3)] s=X-(((X-A)//B)*B+A) s
s430024806
Accepted
17
2,940
69
X,A,B=[int(input()) for i in range(3)] s=X-(((X-A)//B)*B+A) print(s)
s405112409
p03862
u714888375
2,000
262,144
Wrong Answer
114
14,160
227
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, x = list(map(int,input().split())) a = list(map(int,input().split())) result = 0 for i in range(N-1): n = a[i] + a[i+1] - x if n > 0: result += n a[i+1] -= n if a[i+1] < 0: a[i+1] = 0 print(result, a)
s930722673
Accepted
105
14,132
224
N, x = list(map(int,input().split())) a = list(map(int,input().split())) result = 0 for i in range(N-1): n = a[i] + a[i+1] - x if n > 0: result += n a[i+1] -= n if a[i+1] < 0: a[i+1] = 0 print(result)
s805346340
p03998
u018984506
2,000
262,144
Wrong Answer
21
9,116
566
Alice, Bob and Charlie are playing _Card Game for Three_ , as below: * At first, each of the three players has a deck consisting of some number of cards. Each card has a letter `a`, `b` or `c` written on it. The orders of the cards in the decks cannot be rearranged. * The players take turns. Alice goes first. * If the current player's deck contains at least one card, discard the top card in the deck. Then, the player whose name begins with the letter on the discarded card, takes the next turn. (For example, if the card says `a`, Alice takes the next turn.) * If the current player's deck is empty, the game ends and the current player wins the game. You are given the initial decks of the players. More specifically, you are given three strings S_A, S_B and S_C. The i-th (1≦i≦|S_A|) letter in S_A is the letter on the i-th card in Alice's initial deck. S_B and S_C describes Bob's and Charlie's initial decks in the same way. Determine the winner of the game.
from sys import exit s = [input() for i in range(3)] turn = 0 card = s[0][0] sa,sb,sc = 0,0,0 while 1: if card == "a": if sa == len(s[0]): print("A") exit() card = s[0][sa] sa += 1 print(sa,sb,sc) if card == "b": if sb == len(s[1]): print("B") exit() card = s[1][sb] sb += 1 print(sa,sb,sc) if card == "c": if sc == len(s[2]): print("C") exit() card = s[2][sc] sc += 1 print(sa,sb,sc)
s336954114
Accepted
20
9,032
495
from sys import exit s = [input() for i in range(3)] turn = 0 card = s[0][0] sa,sb,sc = 0,0,0 while 1: if card == "a": if sa == len(s[0]): print("A") exit() card = s[0][sa] sa += 1 if card == "b": if sb == len(s[1]): print("B") exit() card = s[1][sb] sb += 1 if card == "c": if sc == len(s[2]): print("C") exit() card = s[2][sc] sc += 1
s965752644
p03679
u952130512
2,000
262,144
Wrong Answer
18
2,940
134
Takahashi has a strong stomach. He never gets a stomachache from eating something whose "best-by" date is at most X days earlier. He gets a stomachache if the "best-by" date of the food is X+1 or more days earlier, though. Other than that, he finds the food delicious if he eats it not later than the "best-by" date. Otherwise, he does not find it delicious. Takahashi bought some food A days before the "best-by" date, and ate it B days after he bought it. Write a program that outputs `delicious` if he found it delicious, `safe` if he did not found it delicious but did not get a stomachache either, and `dangerous` if he got a stomachache.
x,a,b=input().split() if int(b)-int(a)>=0: print("delicious") elif int(b)-int(a)<=int(x): print("safe") else: print("dangerous")
s641404167
Accepted
18
2,940
134
x,a,b=input().split() if int(b)-int(a)<=0: print("delicious") elif int(b)-int(a)<=int(x): print("safe") else: print("dangerous")
s576398456
p04044
u036190609
2,000
262,144
Wrong Answer
17
3,060
229
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.
N, L =list(map(int, input().split())) array = [] word = "" for i in range(N): s = input() array.append(s) print(array) new_array = sorted(array) print(new_array) for j in range(N): word += new_array[j] print(word)
s710351481
Accepted
18
3,060
200
N, L =list(map(int, input().split())) array = [] word = "" for i in range(N): s = input() array.append(s) new_array = sorted(array) for j in range(N): word += new_array[j] print(word)
s533977135
p02388
u067975558
1,000
131,072
Wrong Answer
30
6,720
30
Write a program which calculates the cube of a given integer x.
x = int(input()) print(x ^ 3)
s606184503
Accepted
30
6,724
34
x = int(input()) print(x * x * x)
s497886287
p03605
u518455500
2,000
262,144
Wrong Answer
17
2,940
64
It is September 9 in Japan now. You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
N = input() if '9' in N: print("YES") else: print("NO")
s861727352
Accepted
17
2,940
64
N = input() if '9' in N: print("Yes") else: print("No")
s885045039
p03697
u540631540
2,000
262,144
Wrong Answer
31
9,004
85
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.
a, b = map(int, input().split()) if a + b > 10: print(a + b) else: print("error")
s854950861
Accepted
27
9,048
89
a, b = map(int, input().split()) if a + b < 10: print(a + b) else: print("error")
s652250665
p02276
u742013327
1,000
131,072
Wrong Answer
30
7,660
813
Quick sort is based on the Divide-and-conquer approach. In QuickSort(A, p, r), first, a procedure Partition(A, p, r) divides an array A[p..r] into two subarrays A[p..q-1] and A[q+1..r] such that each element of A[p..q-1] is less than or equal to A[q], which is, inturn, less than or equal to each element of A[q+1..r]. It also computes the index q. In the conquer processes, the two subarrays A[p..q-1] and A[q+1..r] are sorted by recursive calls of QuickSort(A, p, q-1) and QuickSort(A, q+1, r). Your task is to read a sequence A and perform the Partition based on the following pseudocode: Partition(A, p, r) 1 x = A[r] 2 i = p-1 3 for j = p to r-1 4 do if A[j] <= x 5 then i = i+1 6 exchange A[i] and A[j] 7 exchange A[i+1] and A[r] 8 return i+1 Note that, in this algorithm, Partition always selects an element A[r] as a pivot element around which to partition the array A[p..r].
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_B&lang=jp #partition def partition(target_list): x = target_list[-1] i = -1 for j in range(len(target_list))[:-1]: if target_list[j] <= x: i = i+1 tmp = target_list[i] target_list[i] = target_list[j] target_list[j] = tmp tmp = target_list[-1] target_list[-1] = target_list[i + 1] target_list[i + 1] = tmp return i + 1 def convert(l): return " ".join([str(n) for n in l]) if __name__ == "__main__": n_list = int(input()) target_list = [int(n) for n in input().split()] center_index = partition(target_list) print(convert(target_list[:center_index]) + " ["+ str(target_list[center_index]) + "] " + convert(target_list[center_index:]))
s732194928
Accepted
80
18,524
817
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_B&lang=jp #partition def partition(target_list): x = target_list[-1] i = -1 for j in range(len(target_list))[:-1]: if target_list[j] <= x: i = i+1 tmp = target_list[i] target_list[i] = target_list[j] target_list[j] = tmp tmp = target_list[-1] target_list[-1] = target_list[i + 1] target_list[i + 1] = tmp return i + 1 def convert(l): return " ".join([str(n) for n in l]) if __name__ == "__main__": n_list = int(input()) target_list = [int(n) for n in input().split()] center_index = partition(target_list) print(convert(target_list[:center_index]) + " ["+ str(target_list[center_index]) + "] " + convert(target_list[center_index + 1:]))
s201108161
p03548
u503228842
2,000
262,144
Wrong Answer
17
2,940
53
We have a long seat of width X centimeters. There are many people who wants to sit here. A person sitting on the seat will always occupy an interval of length Y centimeters. We would like to seat as many people as possible, but they are all very shy, and there must be a gap of length at least Z centimeters between two people, and between the end of the seat and a person. At most how many people can sit on the seat?
x,y,z =map(int,input().split()) print((x-2*z)//(y+z))
s196137114
Accepted
25
3,068
51
x,y,z =map(int,input().split()) print((x-z)//(y+z))
s955230340
p03228
u085186789
2,000
1,048,576
Wrong Answer
29
9,044
163
In the beginning, Takahashi has A cookies, and Aoki has B cookies. They will perform the following operation alternately, starting from Takahashi: * If the number of cookies in his hand is odd, eat one of those cookies; if the number is even, do nothing. Then, give one-half of the cookies in his hand to the other person. Find the numbers of cookies Takahashi and Aoki respectively have after performing K operations in total.
A, B, K = map(int,input().split()) for i in range(K): if A % 2 == 1: A -= 1 if B % 2 == 1: B -= 1 m = A / 2 n = B / 2 A += n B += m print(A, B)
s017045378
Accepted
25
8,968
153
A, B, K = map(int,input().split()) for i in range(K): if i % 2 == 0: A = A // 2 B += A else: B = B // 2 A += B print(int(A), int(B))
s956122625
p02255
u647766105
1,000
131,072
Wrong Answer
20
7,640
485
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 insert(array, index): value = array[index] for i in range(index-1, -1, -1): if array[i] < value: array[i] = value break array[i + 1] = array[i] else: array[0] = value def insertion_sort(array, log=False): for i in range(len(array)): insert(array, i) if log: print(*array) if __name__ == "__main__": N = int(input()) A = list(map(int, input().split())) insertion_sort(A, True)
s672162213
Accepted
30
8,140
489
def insert(array, index): value = array[index] for i in range(index - 1, -1, -1): if array[i] < value: array[i+1] = value break array[i + 1] = array[i] else: array[0] = value def insertion_sort(array, log=False): for i in range(len(array)): insert(array, i) if log: print(*array) if __name__ == "__main__": N = int(input()) A = list(map(int, input().split())) insertion_sort(A, True)
s844459176
p03814
u459697504
2,000
262,144
Wrong Answer
73
16,300
674
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`.
#! /usr/bin/python3 # A to Z String s = input() list_s = list(s) test = True def length_AZ(l): len_l = len(l) index_A = [] index_Z = [] for i in range(len_l): if l[i] == 'A': index_A.append(i) elif l[i] == 'Z': index_Z.append(i) if test: print('index_A =', index_A) print('index_Z =', index_Z) return max(index_Z) - min(index_A) + 1 def main(): print(length_AZ(list_s)) if __name__ == '__main__': main()
s786947603
Accepted
55
12,792
675
#! /usr/bin/python3 # A to Z String s = input() list_s = list(s) test = False def length_AZ(l): len_l = len(l) index_A = [] index_Z = [] for i in range(len_l): if l[i] == 'A': index_A.append(i) elif l[i] == 'Z': index_Z.append(i) if test: print('index_A =', index_A) print('index_Z =', index_Z) return max(index_Z) - min(index_A) + 1 def main(): print(length_AZ(list_s)) if __name__ == '__main__': main()
s875393969
p03854
u383551754
2,000
262,144
Wrong Answer
19
3,188
160
You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at the end of T: `dream`, `dreamer`, `erase` and `eraser`.
s = input().replace('erase', '').replace('eraser', '').replace('dream', '').replace('dreamer', '') print(s) if s == '': print('YES') else: print('NO')
s362276180
Accepted
18
3,188
151
s = input().replace('eraser', '').replace('erase', '').replace('dreamer', '').replace('dream', '') if s == '': print('YES') else: print('NO')
s621036917
p03485
u692632484
2,000
262,144
Wrong Answer
17
2,940
84
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)
s414844222
Accepted
17
2,940
86
a,b=map(int,input().split()) if (a+b)%2==0 : print((a+b)//2) else: print((a+b)//2+1)
s682576715
p02273
u196653484
2,000
131,072
Wrong Answer
20
5,620
654
Write a program which reads an integer _n_ and draws a Koch curve based on recursive calles of depth _n_. The Koch curve is well known as a kind of You should start (0, 0), (100, 0) as the first segment.
class Dot: x=0.0 y=0.0 def __init__(self,x,y): self.x=x self.y=y def __lt__(self,other): return self.x < other.x def print(self): print("{} {}".format(self.x,self.y)) def divide_line_n(a,b,dots,n): dx=abs(a.x-b.x) dy=abs(a.y-b.y) for i in range(1,n): dots.append(Dot((dx*i)/n,(dy*i)/n)) if __name__ == "__main__": dots=[] dots.append(Dot(0,0)) dots.append(Dot(100,0)) n=int(input()) for i in range(n): divide_line_n(dots[i],dots[i+1],dots,3) divide_line_n(dots[-1],dots[-2],dots,2) dots.sort() for i in dots: i.print()
s077169253
Accepted
40
6,524
950
import math class Dot: x=0.0 y=0.0 def __init__(self,x,y): self.x=x self.y=y def __lt__(self,other): return self.x < other.x def print(self): x=self.x y=self.y print("{:.8f} {:.8f}".format(x,y)) def kock(n,a,b,dots): if n == 0: return s=Dot((2*a.x+b.x)/3,(2*a.y+b.y)/3) t=Dot((a.x+2*b.x)/3,(a.y+2*b.y)/3) rad=math.radians(60) x=(t.x-s.x)*math.cos(rad)-(t.y-s.y)*math.sin(rad)+s.x y=(t.x-s.x)*math.sin(rad)+(t.y-s.y)*math.cos(rad)+s.y u=Dot(x,y) kock(n-1,a,s,dots) s.print() dots.append(s) kock(n-1,s,u,dots) u.print() dots.append(u) kock(n-1,u,t,dots) t.print() dots.append(t) kock(n-1,t,b,dots) if __name__ == "__main__": n=int(input()) dots=[] dot1=Dot(0,0) dot2=Dot(100,0) dots.append(dot1) dots.append(dot2) dot1.print() kock(n,dot1,dot2,dots) dot2.print()
s124760540
p02274
u148628801
1,000
131,072
Wrong Answer
20
7,684
831
For a given sequence $A = \\{a_0, a_1, ... a_{n-1}\\}$, the number of pairs $(i, j)$ where $a_i > a_j$ and $i < j$, is called the number of inversions. The number of inversions is equal to the number of swaps of Bubble Sort defined in the following program: bubbleSort(A) cnt = 0 // the number of inversions for i = 0 to A.length-1 for j = A.length-1 downto i+1 if A[j] < A[j-1] swap(A[j], A[j-1]) cnt++ return cnt For the given sequence $A$, print the number of inversions of $A$. Note that you should not use the above program, which brings Time Limit Exceeded.
import sys a_max = 10000000000 def merge_sort(A): n = len(A) num_swap = 0 if n > 1: m = n // 2 num_swap0, A0 = merge_sort(A[0:m]) num_swap1, A1 = merge_sort(A[m:]) num_swap += num_swap0 + num_swap1 n1 = len(A0) A0.append(a_max) A1.append(a_max) i = 0 j = 0 for k in range(n): if A0[i] < A1[j]: A[k] = A0[i] i += 1 else: A[k] = A1[j] num_swap += n1 - i j += 1 return num_swap, A def bubble_sort(A): n = len(A) num_swap = 0 for i in range(n): for j in range(n - 1, i, -1): if A[j] < A[j - 1]: A[j], A[j - 1] = A[j - 1], A[j] num_swap += 1 return num_swap, A #fin = open("test.txt", "r") fin = sys.stdin fin.readline() A = list(map(int, fin.readline().split())) num_swap, B = merge_sort(A) print(num_swap) print(B)
s928562454
Accepted
1,360
30,092
832
import sys a_max = 10000000000 def merge_sort(A): n = len(A) num_swap = 0 if n > 1: m = n // 2 num_swap0, A0 = merge_sort(A[0:m]) num_swap1, A1 = merge_sort(A[m:]) num_swap += num_swap0 + num_swap1 n1 = len(A0) A0.append(a_max) A1.append(a_max) i = 0 j = 0 for k in range(n): if A0[i] < A1[j]: A[k] = A0[i] i += 1 else: A[k] = A1[j] num_swap += n1 - i j += 1 return num_swap, A def bubble_sort(A): n = len(A) num_swap = 0 for i in range(n): for j in range(n - 1, i, -1): if A[j] < A[j - 1]: A[j], A[j - 1] = A[j - 1], A[j] num_swap += 1 return num_swap, A #fin = open("test.txt", "r") fin = sys.stdin fin.readline() A = list(map(int, fin.readline().split())) num_swap, B = merge_sort(A) print(num_swap)
s439228915
p00014
u354053070
1,000
131,072
Wrong Answer
20
7,480
132
Write a program which computes the area of a shape represented by the following three lines: $y = x^2$ $y = 0$ $x = 600$ It is clear that the area is $72000000$, if you use an integral you learn in high school. On the other hand, we can obtain an approximative area of the shape by adding up areas of many rectangles in the shape as shown in the following figure: $f(x) = x^2$ The approximative area $s$ where the width of the rectangles is $d$ is: area of rectangle where its width is $d$ and height is $f(d)$ $+$ area of rectangle where its width is $d$ and height is $f(2d)$ $+$ area of rectangle where its width is $d$ and height is $f(3d)$ $+$ ... area of rectangle where its width is $d$ and height is $f(600 - d)$ The more we decrease $d$, the higer-precision value which is close to $72000000$ we could obtain. Your program should read the integer $d$ which is a divisor of $600$, and print the area $s$.
import sys for line in sys.stdin: d = int(line) S = 0 for x in range(1, 600, d): S += (x ** 2) * d print(S)
s733353726
Accepted
20
7,568
132
import sys for line in sys.stdin: d = int(line) S = 0 for x in range(0, 600, d): S += (x ** 2) * d print(S)
s459640225
p03997
u951750034
2,000
262,144
Wrong Answer
40
3,064
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)
s354853276
Accepted
39
3,064
69
a = int(input()) b = int(input()) h = int(input()) print((a+b)*h//2)
s461623341
p03860
u557523358
2,000
262,144
Wrong Answer
17
2,940
53
Snuke is going to open a contest named "AtCoder s Contest". Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters. Snuke has decided to abbreviate the name of the contest as "AxC". Here, x is the uppercase English letter at the beginning of s. Given the name of the contest, print the abbreviation of the name.
print(''.join(c for c in input() if 'A' <= c <= 'Z'))
s905812000
Accepted
17
2,940
32
print('A{}C'.format(input()[8]))
s069616537
p03469
u617225232
2,000
262,144
Wrong Answer
25
8,808
32
On some day in January 2018, Takaki is writing a document. The document has a column where the current date is written in `yyyy/mm/dd` format. For example, January 23, 2018 should be written as `2018/01/23`. After finishing the document, she noticed that she had mistakenly wrote `2017` at the beginning of the date column. Write a program that, when the string that Takaki wrote in the date column, S, is given as input, modifies the first four characters in S to `2018` and prints it.
a = input() print('2018'+a[4:6])
s917020901
Accepted
28
9,020
31
a = input() print('2018'+a[4:])
s974071764
p03050
u500297289
2,000
1,048,576
Wrong Answer
146
2,940
187
Snuke received a positive integer N from Takahashi. A positive integer m is called a _favorite number_ when the following condition is satisfied: * The quotient and remainder of N divided by m are equal, that is, \lfloor \frac{N}{m} \rfloor = N \bmod m holds. Find all favorite numbers and print the sum of those.
N = int(input()) import math ans = 0 for k in range(1, int(math.sqrt(N) + 1)): if N % k == 0 and k ** 2 != N: ans += N // k - 1 print(ans - 1)
s871970598
Accepted
336
3,060
220
N = int(input()) import math ans = 0 for k in range(1, int(math.sqrt(N) + 1)): m = N // k - 1 if m != 0: if N % k == 0 and N // m == N % m: ans += m print(ans)
s728873555
p04045
u614984376
2,000
262,144
Wrong Answer
27
2,940
206
Iroha is very particular about numbers. There are K digits that she dislikes: D_1, D_2, ..., D_K. She is shopping, and now paying at the cashier. Her total is N yen (the currency of Japan), thus she has to hand at least N yen to the cashier (and possibly receive the change). However, as mentioned before, she is very particular about numbers. When she hands money to the cashier, the decimal notation of the amount must not contain any digits that she dislikes. Under this condition, she will hand the minimum amount of money. Find the amount of money that she will hand to the cashier.
n,k=map(int,input().split()) d=list(map(int,input().split())) print(d) for i in range(n,10001): for x in d: if str(x) in str(i): break else: print(i) break
s212798172
Accepted
98
2,940
198
n,k=map(int,input().split()) d=list(map(int,input().split())) for i in range(n,100001): for x in d: if str(x) in str(i): break else: print(i) break
s801508744
p03997
u456416458
2,000
262,144
Wrong Answer
30
9,108
91
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 = input() b = input() h = input() answer = ((int(a) + int(b)) * int(h)) / 2 print(answer)
s618222969
Accepted
31
9,124
96
a = input() b = input() h = input() answer = ((int(a) + int(b)) * int(h)) / 2 print(int(answer))
s012757036
p03997
u416758623
2,000
262,144
Wrong Answer
17
2,940
67
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)
s580163129
Accepted
17
2,940
68
a = int(input()) b = int(input()) h = int(input()) print((a+b)*h//2)
s495703995
p03962
u288948615
2,000
262,144
Wrong Answer
18
2,940
46
AtCoDeer the deer recently bought three paint cans. The color of the one he bought two days ago is a, the color of the one he bought yesterday is b, and the color of the one he bought today is c. Here, the color of each paint can is represented by an integer between 1 and 100, inclusive. Since he is forgetful, he might have bought more than one paint can in the same color. Count the number of different kinds of colors of these paint cans and tell him.
nums = list(input().split()) print(set(nums))
s136777614
Accepted
17
2,940
51
nums = list(input().split()) print(len(set(nums)))
s974907804
p03399
u345136423
2,000
262,144
Wrong Answer
19
3,060
70
You planned a trip using trains and buses. The train fare will be A yen (the currency of Japan) if you buy ordinary tickets along the way, and B yen if you buy an unlimited ticket. Similarly, the bus fare will be C yen if you buy ordinary tickets along the way, and D yen if you buy an unlimited ticket. Find the minimum total fare when the optimal choices are made for trains and buses.
a,b,c,d = [int(input()) for _ in range(4)] print(max(a,b) + max(c,d))
s969588492
Accepted
17
2,940
71
a,b,c,d = [int(input()) for _ in range(4)] print(min(a,b) + min(c,d))
s679178733
p03485
u519721530
2,000
262,144
Wrong Answer
17
2,940
87
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.
# ABC082_A a, b = map(int, input().split()) print((a+b)/2 if (a+b)%2==0 else (a+b+1)/2)
s588367573
Accepted
17
2,940
86
a, b = map(int, input().split()) print(int((a+b)/2) if (a+b)%2==0 else int((a+b+1)/2))
s719676858
p03712
u642528832
2,000
262,144
Wrong Answer
27
9,124
137
You are given a image with a height of H pixels and a width of W pixels. Each pixel is represented by a lowercase English letter. The pixel at the i-th row from the top and j-th column from the left is a_{ij}. Put a box around this image and output the result. The box should consist of `#` and have a thickness of 1.
H,W = map(int,(input().split())) a = [input() for _ in range(H)] print('#'*(W+1)) for i in a: print('#'+str(i)+"#") print('#'*(W+1))
s828780408
Accepted
28
9,152
137
H,W = map(int,(input().split())) a = [input() for _ in range(H)] print('#'*(W+2)) for i in a: print('#'+str(i)+"#") print('#'*(W+2))
s193658415
p03720
u835482198
2,000
262,144
Wrong Answer
18
2,940
202
There are N cities and M roads. The i-th road (1≤i≤M) connects two cities a_i and b_i (1≤a_i,b_i≤N) bidirectionally. There may be more than one road that connects the same pair of two cities. For each city, how many roads are connected to the city?
n, m = map(int, input().split()) g = [[]] * n for _ in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 g[a] += [b] g[b] += [a] for i in range(n): print(len(set(g[i])))
s761983335
Accepted
17
3,060
207
n, m = map(int, input().split()) ret = [[] for i in range(n + 1)] for i in range(m): a, b = map(int, input().split()) ret[a] += [b] ret[b] += [a] for i in range(1, n + 1): print(len(ret[i]))
s856429256
p02326
u837811962
1,000
131,072
Wrong Answer
20
7,780
617
Given a matrix (H × W) which contains only 1 and 0, find the area of the largest square matrix which only contains 0s.
H,W = map(int,input().split()) tile = [[0 for i in range(W)] for i in range(H)] buf = [[1 for i in range(W)] for i in range(H)] maxsquare = 0 for i in range(H): tile[i] = list(map(int,input().split())) for i in range(1,H): for j in range(1,W): if tile[i-1][j]==1 or tile[i][j-1]==1 or tile[i-1][j-1]==1: buf[i][j] = 1 elif tile[i-1][j]==tile[i][j-1]: buf[i][j] = buf[i-1][j-1]+1 else: buf[i][j] = min(buf[i-1][j] , buf[i][j-1])+1 if buf[i][j] > maxsquare: maxsquare = buf[i][j] for i in buf: print(i) print(maxsquare**2)
s049669724
Accepted
2,190
58,504
460
H,W = map(int,input().split()) tile = [[0 for i in range(W)] for i in range(H)] buf = [[0 for i in range(W+1)] for i in range(H+1)] maxsquare = 0 for i in range(H): tile[i] = list(map(int,input().split())) for i in range(1,H+1): for j in range(1,W+1): if tile[i-1][j-1]!=1: buf[i][j] = min(buf[i-1][j],buf[i][j-1],buf[i-1][j-1]) + 1 if buf[i][j] > maxsquare: maxsquare = buf[i][j] print(maxsquare**2)
s147442981
p03352
u342051078
2,000
1,048,576
Wrong Answer
18
2,940
139
You are given a positive integer X. Find the largest _perfect power_ that is at most X. Here, a perfect power is an integer that can be represented as b^p, where b is an integer not less than 1 and p is an integer not less than 2.
import sys x = int(input()) mx = 0 for i in range(2,33): if i*i <= x: mx = max(mx,i*i) else : sys.exit(0) print(mx)
s291230544
Accepted
18
2,940
150
x = int(input()) ans = 1 for i in range(2,41): for j in range(2,11): if x < i**j: break ans = max(ans,i**j) print(ans)
s676906098
p03971
u197300773
2,000
262,144
Wrong Answer
108
4,016
294
There are N participants in the CODE FESTIVAL 2016 Qualification contests. The participants are either students in Japan, students from overseas, or neither of these. Only Japanese students or overseas students can pass the Qualification contests. The students pass when they satisfy the conditions listed below, from the top rank down. Participants who are not students cannot pass the Qualification contests. * A Japanese student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B. * An overseas student passes the Qualification contests if the number of the participants who have already definitively passed is currently fewer than A+B and the student ranks B-th or above among all overseas students. A string S is assigned indicating attributes of all participants. If the i-th character of string S is `a`, this means the participant ranked i-th in the Qualification contests is a Japanese student; `b` means the participant ranked i-th is an overseas student; and `c` means the participant ranked i-th is neither of these. Write a program that outputs for all the participants in descending rank either `Yes` if they passed the Qualification contests or `No` if they did not pass.
n,a,b=map(int,input().split()) ca,cb=0,0 s=input() for i in range(n): if s[i]=="a": if ca<a+b: print("Yes") ca+=1 elif s[i]=="b": if ca<a+b and cb<b: print("Yes") ca+=1;cb+=1 else: print("No") else: print("No")
s509991100
Accepted
114
4,016
320
n,a,b=map(int,input().split()) ca,cb=0,0 s=input() for i in range(n): if s[i]=="a": if ca<a+b: print("Yes") ca+=1 else: print("No") elif s[i]=="b": if ca<a+b and cb<b: print("Yes") ca+=1;cb+=1 else: print("No") else: print("No")
s500099403
p02612
u962050670
2,000
1,048,576
Wrong Answer
32
9,100
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)
s974135804
Accepted
29
9,168
78
n = int(input()) if n % 1000 == 0: print(0) else: print(1000 - (n % 1000))
s630113738
p03608
u029169777
2,000
262,144
Wrong Answer
656
16,044
2,841
There are N towns in the State of Atcoder, connected by M bidirectional roads. The i-th road connects Town A_i and B_i and has a length of C_i. Joisino is visiting R towns in the state, r_1,r_2,..,r_R (not necessarily in this order). She will fly to the first town she visits, and fly back from the last town she visits, but for the rest of the trip she will have to travel by road. If she visits the towns in the order that minimizes the distance traveled by road, what will that distance be?
from itertools import permutations from scipy.sparse.csgraph import dijkstra as di N,M,R=map(int,input().split()) r=list(map(int,input().split())) dp=[[0 for _ in range(N)] for _ in range(N)] for _ in range(M): A,B,C=map(int,input().split()) if dp[A-1][B-1]==0 or dp[A-1][B-1]>C: dp[A-1][B-1]=C dp[B-1][A-1]=C print(dp) distance=di(dp) ans=10**11 for tmp in permutations(r): tmpans=0 for i in range(len(tmp)-1): tmpans+=distance[tmp[i]-1][tmp[i+1]-1] if ans>tmpans: ans=tmpans print(int(ans))
s574354431
Accepted
621
15,756
2,839
from itertools import permutations from scipy.sparse.csgraph import dijkstra as di N,M,R=map(int,input().split()) r=list(map(int,input().split())) dp=[[0 for _ in range(N)] for _ in range(N)] for _ in range(M): A,B,C=map(int,input().split()) if dp[A-1][B-1]==0 or dp[A-1][B-1]>C: dp[A-1][B-1]=C dp[B-1][A-1]=C distance=di(dp) ans=10**11 for tmp in permutations(r): tmpans=0 for i in range(len(tmp)-1): tmpans+=distance[tmp[i]-1][tmp[i+1]-1] if ans>tmpans: ans=tmpans print(int(ans))
s922288931
p03007
u159228113
2,000
1,048,576
Wrong Answer
2,104
14,008
390
There are N integers, A_1, A_2, ..., A_N, written on a blackboard. We will repeat the following operation N-1 times so that we have only one integer on the blackboard. * Choose two integers x and y on the blackboard and erase these two integers. Then, write a new integer x-y. Find the maximum possible value of the final integer on the blackboard and a sequence of operations that maximizes the final integer.
n = int(input()) x = list(map(int,input().split())) #nmax = max(x) #ans = 2*nmax-sum(x) lst = [] while len(x) > 2: mi = min(x) ma = max(x) lst.append(str(mi)+" "+str(ma)) del x[x.index(min(x))] del x[x.index(max(x))] x.append(mi - ma) print(max(x) - min(x)) for i in range(len(lst)): print(lst[i]) print(max(x),min(x))
s624934844
Accepted
175
17,872
795
n = int(input()) x = list(map(int,input().split())) #nmax = max(x) #ans = 2*nmax-sum(x) lst = [] nmi = min(x) nma = max(x) del x[x.index(nmi)] del x[x.index(nma)] mainus = [i for i in x if i < 0] plus = [i for i in x if i >= 0] for i in mainus: lst.append(str(nma)+" "+str(i)) nma -= i for i in plus: lst.append(str(nmi)+" "+str(i)) nmi -= i lst.append(str(nma)+" "+str(nmi)) print(nma-nmi) for i in lst: print(i)
s717562808
p02397
u382316013
1,000
131,072
Wrong Answer
40
7,560
131
Write a program which reads two integers x and y, and prints them in ascending order.
while True: x, y = [int(i) for i in input().split()] if x == y == 0: break if x > y: x, y = y, x print(x, y)
s872511289
Accepted
50
7,544
146
while True: x, y = [int(i) for i in input().split()] if x == y == 0: break if x > y: x, y = y, x print(x, y)
s129188521
p03861
u314089899
2,000
262,144
Wrong Answer
18
2,940
86
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?
#48b import math a,b,x = map(int, input().split()) first = math.ceil(a/x) end = b//x
s463404539
Accepted
17
2,940
123
#48b a,b,x = map(int, input().split()) down = a//x if down*x == a: down -= 1 up = b//x #print(up,down) print(up - down)
s005307444
p03547
u449555432
2,000
262,144
Wrong Answer
17
3,064
76
In programming, hexadecimal notation is often used. In hexadecimal notation, besides the ten digits 0, 1, ..., 9, the six letters `A`, `B`, `C`, `D`, `E` and `F` are used to represent the values 10, 11, 12, 13, 14 and 15, respectively. In this problem, you are given two letters X and Y. Each X and Y is `A`, `B`, `C`, `D`, `E` or `F`. When X and Y are seen as hexadecimal numbers, which is larger?
a=list(input());print('>' if max(a)==a[0] else '<' if max(a)==a[1] else '=')
s437357706
Accepted
18
2,940
62
a,b=input().split();print('>' if a>b else '<' if a<b else '=')
s529592237
p03816
u759412327
2,000
262,144
Wrong Answer
67
20,892
78
Snuke has decided to play a game using cards. He has a deck consisting of N cards. On the i-th card from the top, an integer A_i is written. He will perform the operation described below zero or more times, so that the values written on the remaining cards will be pairwise distinct. Find the maximum possible number of remaining cards. Here, N is odd, which guarantees that at least one card can be kept. Operation: Take out three arbitrary cards from the deck. Among those three cards, eat two: one with the largest value, and another with the smallest value. Then, return the remaining one card to the deck.
N = int(input()) A = sorted(list(map(int,input().split()))) print(len(set(A)))
s202113689
Accepted
48
23,016
61
N = int(input()) K = len(set(input().split())) print(K+K%2-1)
s672757674
p02613
u410943190
2,000
1,048,576
Wrong Answer
157
9,204
339
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.
li = [0] * 4 N = int(input()) for i in range(N): result = input() if result == "AC": li[0] += 1 if result == "WA": li[1] += 1 if result == "TLE": li[2] += 1 if result == "RE": li[3] += 1 line = "AC × {0}\nWA × {1}\nTLE × {2}\nRE × {3}".format(li[0], li[1], li[2], li[3]) print(line)
s842865281
Accepted
158
9,188
335
li = [0] * 4 N = int(input()) for i in range(N): result = input() if result == "AC": li[0] += 1 if result == "WA": li[1] += 1 if result == "TLE": li[2] += 1 if result == "RE": li[3] += 1 line = "AC x {0}\nWA x {1}\nTLE x {2}\nRE x {3}".format(li[0], li[1], li[2], li[3]) print(line)
s360860520
p03479
u023229441
2,000
262,144
Wrong Answer
30
9,016
115
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=map(int,input().split()) import bisect as bi ans=1 for i in range(80): if x*2<=y: ans+=1 print(ans)
s802325633
Accepted
24
9,092
128
x,y=map(int,input().split()) import bisect as bi ans=1 for i in range(80): if x*2<=y: ans+=1 x*=2 print(ans)
s273273129
p04043
u766407523
2,000
262,144
Wrong Answer
17
2,940
97
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.
ABC = list(map(int, input().split())) if ABC in [5, 5, 7]: print('YES') else: print('NO')
s249447901
Accepted
17
2,940
113
a = list(map(int, input().split())) if sum(a) == 17 and 5 in a and 7 in a: print('YES') else: print('NO')
s198549105
p03861
u252964975
2,000
262,144
Wrong Answer
18
3,064
91
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?
import math a,b,x=map(int, input().split()) A=math.ceil(a/x) B=math.floor(b/x) print(A-B+1)
s813182614
Accepted
17
2,940
53
a,b,x=map(int, input().split()) print(b//x-(a-1)//x)
s533540294
p03407
u995914787
2,000
262,144
Wrong Answer
17
2,940
112
An elementary school student Takahashi has come to a variety store. He has two coins, A-yen and B-yen coins (yen is the currency of Japan), and wants to buy a toy that costs C yen. Can he buy it? Note that he lives in Takahashi Kingdom, and may have coins that do not exist in Japan.
S = str(input()) X = S.split() A = X[0] B = X[1] C = X[2] if (A + B) < C: print("Yes") else: print("No")
s641453460
Accepted
17
2,940
128
S = str(input()) X = S.split() A = int(X[0]) B = int(X[1]) C = int(X[2]) if C <= (A + B): print("Yes") else: print("No")
s147598151
p04044
u300778480
2,000
262,144
Wrong Answer
19
3,064
146
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.
try: N, L = map(int, input().split()) l = [] for i in range(N): l.append(input()) l_ = sorted(l) print(l_) except EOFError: pass
s666156279
Accepted
18
3,060
155
try: N, L = map(int, input().split()) l = [] for i in range(N): l.append(input()) l_ = sorted(l) print(''.join(l_)) except EOFError: pass
s965529458
p02612
u382169090
2,000
1,048,576
Wrong Answer
29
9,144
63
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()) if n%1000==0: print(0) else: print(n%1000)
s228840913
Accepted
32
9,152
70
n = int(input()) if n%1000==0: print(0) else: print(1000 - n%1000)