buggy
stringlengths
1
618k
fixed
stringlengths
16
618k
buggy_submission_id
stringlengths
10
10
fixed_submission_id
stringlengths
10
10
problem_id
stringlengths
6
6
lang
stringclasses
1 value
buggy_verdict
stringclasses
2 values
""" nodes 0 ... start k*num + 1 ~ (k+1)*num ... j=k (k <= m) num * (m + 1) + 1 ... end """ from heapq import heappush, heappop INF = 10 ** 20 while True: n, m = map(int, input().split()) if n == 0: break lines = [] klst = [] acc = 1 for _ in range(n): lst = list(map(int, input().split())) k = ls...
""" nodes 0 ... start k*num + 1 ~ (k+1)*num ... j=k (k <= m) num * (m + 1) + 1 ... end """ from heapq import heappush, heappop def main(): INF = 10 ** 20 while True: n, m = map(int, input().split()) if n == 0: break lines = [] acc = 1 for _ in range(n): lst = list(map(int, input().sp...
s866650596
s134190568
p00453
python
Time Limit Exceeded
""" nodes 0 ... start k*num + 1 ~ (k+1)*num ... j=k (k <= m) num * (m + 1) + 1 ... end """ from heapq import heappush, heappop def main(): INF = 10 ** 20 while True: n, m = map(int, input().split()) if n == 0: break lines = [] acc = 1 for _ in range(n): lst = list(map(int, input().sp...
""" nodes 0 ... start k*num + 1 ~ (k+1)*num ... j=k (k <= m) num * (m + 1) + 1 ... end """ from heapq import heappush, heappop def main(): INF = 10 ** 20 while True: n, m = map(int, input().split()) if n == 0: break lines = [] acc = 1 for _ in range(n): lst = list(map(int, input().sp...
s848939793
s134190568
p00453
python
Time Limit Exceeded
while True: w, h = map(int, input().split()) if not w: break n = int(input()) xlst = [0, w - 1] ylst = [0, h - 1] plst = [] for i in range(n): x1, y1, x2, y2 = map(int, input().split()) plst.append([x1,y1,x2,y2]) xlst.append(x1) # xlst.append(x1 + 1) xlst.append(x2) # xlst.app...
def main(): while True: w, h = map(int, input().split()) if not w: break n = int(input()) xlst = [0, w - 1] ylst = [0, h - 1] plst = [] for i in range(n): x1, y1, x2, y2 = map(int, input().split()) plst.append([x1,y1,x2 - 1,y2 - 1]) xlst.append(x1) xl...
s288214081
s402745023
p00454
python
Runtime Error
def solve(): while True: m, n = int(input()), int(input()) if not m: break ices = [[0] + list(map(int,input().split())) + [0] for _ in range(n)] ices.insert(0, [0] * (m + 2),) ices.append([0] * (m + 2)) score = [[0] * (m + 2) for _ in range(n + 2)] for x in range(1, n + 1): ...
def search(x, y, imap, acc): imap[x][y] = 0 acc += 1 ret = acc a = b = c = d = 0 if imap[x - 1][y]: a = search(x - 1, y, imap, acc) if ret < a: ret = a if imap[x + 1][y]: b = search(x + 1, y, imap, acc) if ret < b: ret = b if imap[x][y - 1]: c = search(x, y - 1, imap, acc) ...
s255648177
s930952057
p00458
python
Time Limit Exceeded
import sys sys.setrecursionlimit(100000) while True: n,m,h,k = map(int,input().split()) if not n: break s_lst = [int(input()) for _ in range(n)] b_lst = [tuple(map(int,input().split())) for _ in range(m)] b_lst = sorted(b_lst,key=lambda x:-x[1]) def amida(b_lst, s_lst, used, k): if not b_lst: retu...
while True: n,m,h,k = map(int,input().split()) if not n: break s_lst = [int(input()) for _ in range(n)] i_lst = [i for i in range(n)] b_lst = [tuple(map(int,input().split())) for _ in range(m)] b_lst = sorted(b_lst,key=lambda x:x[1]) pare_lst = [] for bar in b_lst: ind = bar[0] temp = i_lst[ind]...
s329982369
s431469494
p00463
python
Time Limit Exceeded
while True: h,w,n = map(int,input().split()) if not h: break sss = [[True if s == "1" else False for s in input().split()] for i in range(h)] for i in range(n): x = y = 0 while x < h and y < w: sss[x][y] = not sss[x][y] if sss[x][y]: x += 1 else: y += 1 print(x + 1,y ...
def solve(): while True: h,w,n = map(int,input().split()) if not h: break mp = [[int(s) for s in input().split()] for i in range(h)] dp = [[0 for i in range(w + 1)] for j in range(h + 1)] dp[0][0] = n - 1 for x in range(h): dpx = dp[x] dpxp = dp[x + 1] mpx = mp[x] for y...
s718558014
s875274780
p00464
python
Time Limit Exceeded
def solve(): n,l = map(int,input().split()) length = [int(input()) for i in range(n)] pare = [(length[i], i) for i in range(n)] pare.sort(reverse=True) dp = [0] * (n + 1) for p in pare: i = p[0] if i == 0: dp[i] = dp[i + 1] + (l - length[i]) else: dp[i] = max(dp[i - 1], dp[i + 1])...
def solve(): n, l = map(int,input().split()) ans = 0 pre = 0 trend = 1 acc = 0 for i in range(n): length = int(input()) time = l - length if length > pre and trend >= 0: acc += time elif length < pre and trend <= 0: acc += time else: if ans < acc: ans = acc ...
s059080085
s254729039
p00474
python
Runtime Error
import queue h,w,n = map(int,input().split()) factrys = [None] * (n + 1) ss = ["X" * (w + 2)] for i in range(h): s = "X" + input() + "X" if "S" in s: factrys[0] = (i + 1,s.index("S")) for j in range(1,n + 1): if str(j) in s: factrys[j] = (i + 1,s.index(str(j))) ss.append(s) ss.append("X" * (w + 2)...
from collections import deque def main(): h, w, n = map(int, input().split()) mp = ["X" + input() + "X" for _ in range(h)] mp.insert(0, "X" * (w + 2)) mp.append("X" * (w + 2)) poss = [None] * (n + 1) for y in range(1, h + 1): for x in range(1, w + 1): if mp[y][x] == "S": poss[0] = (x, ...
s606138553
s680559711
p00481
python
Runtime Error
import sys import queue sys.setrecursionlimit(10000000) h,w,n = map(int,input().split()) factrys = [None] * (n + 1) ss = ["X" * (w + 2)] for i in range(h): s = "X" + input() + "X" if "S" in s: factrys[0] = (i + 1,s.index("S")) for j in range(1,n + 1): if str(j) in s: factrys[j] = (i + 1,s.index(str(...
from collections import deque def main(): h, w, n = map(int, input().split()) mp = ["X" + input() + "X" for _ in range(h)] mp.insert(0, "X" * (w + 2)) mp.append("X" * (w + 2)) poss = [None] * (n + 1) for y in range(1, h + 1): for x in range(1, w + 1): if mp[y][x] == "S": poss[0] = (x, ...
s100498812
s680559711
p00481
python
Runtime Error
import queue h,w,n = map(int,input().split()) factrys = [None] * (n + 1) ss = ["X" * (w + 2)] for i in range(h): s = "X" + input() + "X" if "S" in s: factrys[0] = (i + 1,s.index("S")) for j in range(1,n + 1): if str(j) in s: factrys[j] = (i + 1,s.index(str(j))) ss.append(s) ss.append("X" * (w + 2)...
from collections import deque def main(): h, w, n = map(int, input().split()) mp = ["X" + input() + "X" for _ in range(h)] mp.insert(0, "X" * (w + 2)) mp.append("X" * (w + 2)) poss = [None] * (n + 1) for y in range(1, h + 1): for x in range(1, w + 1): if mp[y][x] == "S": poss[0] = (x, ...
s495741969
s680559711
p00481
python
Runtime Error
import queue h,w,n = map(int,input().split()) factrys = [None] * (n + 1) ss = ["X" * (w + 2)] for i in range(h): s = "X" + input() + "X" if "S" in s: factrys[0] = (i + 1, s.index("S")) for j in range(1,n + 1): if str(j) in s: factrys[j] = (i + 1, s.index(str(j))) ss.append(s) ss.append("X" * (w + ...
from collections import deque def main(): h, w, n = map(int, input().split()) mp = ["X" + input() + "X" for _ in range(h)] mp.insert(0, "X" * (w + 2)) mp.append("X" * (w + 2)) poss = [None] * (n + 1) for y in range(1, h + 1): for x in range(1, w + 1): if mp[y][x] == "S": poss[0] = (x, ...
s037771115
s680559711
p00481
python
Runtime Error
import queue h,w,n = map(int,input().split()) factrys = [None] * (n + 1) ss = ["X" * (w + 2)] for i in range(h): s = "X" + input() + "X" if "S" in s: factrys[0] = (i + 1, s.index("S")) for j in range(1,n + 1): if str(j) in s: factrys[j] = (i + 1, s.index(str(j))) ss.append(s) ss.append("X" * (w + ...
from collections import deque def main(): h, w, n = map(int, input().split()) mp = ["X" + input() + "X" for _ in range(h)] mp.insert(0, "X" * (w + 2)) mp.append("X" * (w + 2)) poss = [None] * (n + 1) for y in range(1, h + 1): for x in range(1, w + 1): if mp[y][x] == "S": poss[0] = (x, ...
s042477423
s680559711
p00481
python
Runtime Error
import queue h,w,n = map(int,input().split()) factrys = [None] * (n + 1) ss = ["X" * (w + 2)] for i in range(h): s = "X" + input() + "X" if "S" in s: factrys[0] = (i + 1, s.index("S")) for j in range(1,n + 1): if str(j) in s: factrys[j] = (i + 1, s.index(str(j))) ss.append(s) ss.append("X" * (w + ...
from collections import deque def main(): h, w, n = map(int, input().split()) mp = ["X" + input() + "X" for _ in range(h)] mp.insert(0, "X" * (w + 2)) mp.append("X" * (w + 2)) poss = [None] * (n + 1) for y in range(1, h + 1): for x in range(1, w + 1): if mp[y][x] == "S": poss[0] = (x, ...
s806718734
s680559711
p00481
python
Runtime Error
import queue h,w,n = map(int,input().split()) factrys = [None] * (n + 1) ss = ["X" * (w + 2)] for i in range(h): s = "X" + input() + "X" if "S" in s: factrys[0] = (i + 1, s.index("S")) for j in range(1,n + 1): if str(j) in s: factrys[j] = (i + 1, s.index(str(j))) ss.append(s) ss.append("X" * (w + ...
from collections import deque def main(): h, w, n = map(int, input().split()) mp = ["X" + input() + "X" for _ in range(h)] mp.insert(0, "X" * (w + 2)) mp.append("X" * (w + 2)) poss = [None] * (n + 1) for y in range(1, h + 1): for x in range(1, w + 1): if mp[y][x] == "S": poss[0] = (x, ...
s302069088
s680559711
p00481
python
Runtime Error
import queue h,w,n = map(int,input().split()) factrys = [None] * (n + 1) ss = ["X" * (w + 2)] for i in range(h): s = "X" + input() + "X" if "S" in s: factrys[0] = (i + 1, s.index("S")) for j in range(1,n + 1): if str(j) in s: factrys[j] = (i + 1, s.index(str(j))) ss.append(s) ss.append("X" * (w + ...
from collections import deque def main(): h, w, n = map(int, input().split()) mp = ["X" + input() + "X" for _ in range(h)] mp.insert(0, "X" * (w + 2)) mp.append("X" * (w + 2)) poss = [None] * (n + 1) for y in range(1, h + 1): for x in range(1, w + 1): if mp[y][x] == "S": poss[0] = (x, ...
s576183556
s680559711
p00481
python
Runtime Error
import queue from collections import deque h,w,n = map(int,input().split()) factrys = [None] * (n + 1) ss = ["X" * (w + 2)] for i in range(h): s = "X" + input() + "X" if "S" in s: factrys[0] = (i + 1, s.index("S")) for j in range(1,n + 1): if str(j) in s: factrys[j] = (i + 1, s.index(str(j))) ss.a...
from collections import deque def main(): h, w, n = map(int, input().split()) mp = ["X" + input() + "X" for _ in range(h)] mp.insert(0, "X" * (w + 2)) mp.append("X" * (w + 2)) poss = [None] * (n + 1) for y in range(1, h + 1): for x in range(1, w + 1): if mp[y][x] == "S": poss[0] = (x, ...
s499563284
s680559711
p00481
python
Runtime Error
WALL = 100 w, h = map(int,input().split()) lst = [[WALL] + list(map(int,input().split())) + [WALL] for i in range(h)] lst.insert(0, [WALL] * (w + 2)) lst.append([WALL] * (w + 2)) visited = [[0] * (w + 2) for _ in range(h + 2)] hold = [] def search(x, y): if lst[x][y] == WALL: visited[x][y] = 3 return 3 ...
import sys sys.setrecursionlimit(1000000) WALL = 100 w, h = map(int,input().split()) lst = [[WALL] + list(map(int,input().split())) + [WALL] for i in range(h)] lst.insert(0, [WALL] * (w + 2)) lst.append([WALL] * (w + 2)) visited = [[0] * (w + 2) for _ in range(h + 2)] hold = [] app = hold.append def search(x, y): ...
s203972415
s158352357
p00492
python
Runtime Error
from heapq import heappop as pop from heapq import heappush as push INF = 10 ** 20 n, k = map(int, input().split()) clst = [] rlst = [] for i in range(n): c, r = map(int, input().split()) clst.append(c) rlst.append(r) edges = [[0] * n for i in range(n)] for i in range(k): a, b = map(int, input().split()) ...
from heapq import heappop as pop from heapq import heappush as push def main(): n, k = map(int, input().split()) clst = [] rlst = [] for i in range(n): c, r = map(int, input().split()) clst.append(c) rlst.append(r) edges = [[] * n for i in range(n)] for i in range(k): a, b = map...
s202890958
s667052584
p00519
python
Runtime Error
INF = 10 ** 20 m, n = map(int, input().split()) manju_lst = [int(input()) for i in range(m)] manju_lst.sort(reverse=True) acc = 0 cum_sum = [0] for manju in manju_lst: acc += manju cum_sum.append(acc) clst = [] elst = [] for i in range(n): c, e = map(int, input().split()) clst.append(c) elst.append(e) dp...
INF = 10 ** 20 def main(): m, n = map(int, input().split()) manju_lst = [int(input()) for i in range(m)] manju_lst.sort(reverse=True) acc = 0 cum_sum = [0] for manju in manju_lst: acc += manju cum_sum.append(acc) clst = [] elst = [] for i in range(n): c, e = map(int, input().spli...
s430435844
s304275929
p00522
python
Runtime Error
n = int(input()) A = [int(input()) for i in range(n)] * 2 dp = [[-1 for i in range(n * 2)] for j in range(n * 2)] def dfs(i,j): #if (j - i > n - 1):undefined if dp[i][j] != -1: pass elif (j - i == n - 1): dp[i][j] = 0 elif (j - i) % 2 == 0: if A[i - 1] > A[j + 1]: dp[i][j] = dfs(i - 1, j) ...
import sys sys.setrecursionlimit(10000) n = int(input()) A = [int(input()) for i in range(n)] * 3 dp = [[-1 for i in range(n * 2)] for j in range(n * 2)] def dfs(i,j): #if (j - i > n - 1):undefined if dp[i][j] != -1: pass elif (j - i == n - 1): dp[i][j] = 0 elif (j - i) % 2 == 0: if A[i - 1] > A[...
s904768495
s827323835
p00538
python
Runtime Error
n = int(input()) A = [int(input()) for i in range(n)] * 3 dp = [[-1 for i in range(n * 2)] for j in range(n * 2)] def dfs(i,j): #if (j - i > n - 1):undefined if dp[i][j] != -1: pass elif (j - i == n - 1): dp[i][j] = 0 elif (j - i) % 2 == 0: if A[i - 1] > A[j + 1]: dp[i][j] = dfs(i - 1, j) ...
import sys sys.setrecursionlimit(10000) n = int(input()) A = [int(input()) for i in range(n)] * 3 dp = [[-1 for i in range(n * 2)] for j in range(n * 2)] def dfs(i,j): #if (j - i > n - 1):undefined if dp[i][j] != -1: pass elif (j - i == n - 1): dp[i][j] = 0 elif (j - i) % 2 == 0: if A[i - 1] > A[...
s703311315
s827323835
p00538
python
Runtime Error
INF = 10 ** 20 def minimum_cost(rest, init, dic): if rest in dic: return dic[rest] if rest == (): return 0 ret = INF for nex in rest: nex_init = init + acc[nex] ret = min(ret, minimum_cost(tuple(i for i in rest if i != nex), nex_init, dic) +\ acc[nex] - (cums[nex][nex_init] ...
def main(): INF = 10 ** 20 def minimum_cost(rest, h, init, dic): if h in dic: return dic[h] if not h: return 0 ret = INF for nex in rest: accnex = acc[nex] cumsnex = cums[nex] nex_init = init + accnex nex_rest = rest[:] nex_rest.remove(nex) nex_h...
s893833079
s514911305
p00556
python
Runtime Error
def main(): INF = 10 ** 20 def minimum_cost(rest, init, dic): if rest in dic: return dic[rest] if rest == (): return 0 ret = INF for nex in rest: accnex = acc[nex] cumsnex = cums[nex] nex_init = init + accnex tmp = minimum_cost(tuple([i for i in rest if i !...
def main(): INF = 10 ** 20 def minimum_cost(rest, h, init, dic): if h in dic: return dic[h] if not h: return 0 ret = INF for nex in rest: accnex = acc[nex] cumsnex = cums[nex] nex_init = init + accnex nex_rest = rest[:] nex_rest.remove(nex) nex_h...
s689681787
s514911305
p00556
python
Runtime Error
from heapq import heappush, heappop from itertools import permutations INF = 10 ** 20 while True: n, m, p, a, b = map(int, input().split()) if n == 0: break a -= 1 b -= 1 tlst = list(map(int, input().split())) edges = [[] for _ in range(m)] for _ in range(p): x, y, z = map(int, input().split()) ...
INF = 10 ** 20 def search(rest, now, goal, dp, edges): if now == goal: return 0 if rest == (): return INF if (rest, now) in dp: return dp[(rest, now)] ret = INF for i, t in enumerate(rest): for dist, to in edges[now]: tmp = search(tuple(v for j, v in enumerate(rest) if i != j), to, go...
s608000389
s382070617
p00719
python
Runtime Error
from heapq import heappush, heappop INF = 10 ** 20 direct = ((0, -1), (0, 1), (-1, 0), (1, 0)) def dist(fr, to, mp): que = [] heappush(que, (0, fr)) visited = [[False] * len(mp[0]) for _ in range(len(mp))] visited[fr[1]][fr[0]] = True while que: d, point = heappop(que) x, y = point for dx, dy in...
from heapq import heappush, heappop INF = 10 ** 10 direct = ((0, -1), (0, 1), (-1, 0), (1, 0)) def dist(fr, to, mp): que = [] heappush(que, (0, fr)) visited = [[False] * len(mp[0]) for _ in range(len(mp))] visited[fr[1]][fr[0]] = True while que: d, point = heappop(que) x, y = point for dx, dy in...
s482661657
s776104189
p00721
python
Runtime Error
from heapq import heappush, heappop INF = 10 ** 10 direct = ((0, -1), (0, 1), (-1, 0), (1, 0)) def dist(fr, to, mp): que = [] heappush(que, (0, fr)) visited = [[False] * len(mp[0]) for _ in range(len(mp))] visited[fr[1]][fr[0]] = True while que: d, point = heappop(que) x, y = point for dx, dy in...
from heapq import heappush, heappop INF = 10 ** 10 direct = ((0, -1), (0, 1), (-1, 0), (1, 0)) def dist(fr, to, mp): que = [] heappush(que, (0, fr)) visited = [[False] * len(mp[0]) for _ in range(len(mp))] visited[fr[1]][fr[0]] = True while que: d, point = heappop(que) x, y = point for dx, dy in...
s259180139
s776104189
p00721
python
Runtime Error
INIT = 100 query = [] ans = [] while True: q = int(input()) if q == 0: break query.append(q) MAX = max(query) table = [INIT] * (MAX + 1) table[0] = 0 all_item = [i * (i + 1) * (i + 2) // 6 for i in range(1, 181)] odd_item = [i for i in all_item if i % 2] eve_item = [i for i in all_item if not i % 2] for v ...
def main(): INIT = 100 query = [] ans = [] while True: q = int(input()) if q == 0: break query.append(q) MAX = max(query) table = [INIT] * (MAX + 1) table[0] = 0 all_item = [i * (i + 1) * (i + 2) // 6 for i in range(1, 181)] odd_item = [i for i in all_item if i % 2] eve_item ...
s341430311
s594895827
p00748
python
Runtime Error
while True: n = int(input()) if n == 0: break wlst = list(map(int, input().split())) dp = [[0] * n for _ in range(n + 1)] def check(left1, right1, left2, right2, cnt): if left1 > right1 and left2 > right2: return cnt if left1 > right1:return dp[right2 - left2 + 1][left2] + cnt if left2 > ri...
def main(): while True: n = int(input()) if n == 0: break wlst = list(map(int, input().split())) connect = [[None] * n for _ in range(n)] for i in range(n): for j in range(n): connect[i][j] = abs(wlst[i] - wlst[j]) <= 1 max_lst = [[False] * (n + 1) for _ in range(n + 1...
s165807143
s202497763
p01096
python
Time Limit Exceeded
while True: n = int(input()) if n == 0: break days = [[] for _ in range(30)] for i in range(n): hima = list(map(int, input().split())) for d in hima[1:]: days[d].append(i) par_lst = [i for i in range(n)] def get_par(x): if x == par_lst[x]: return x ret = get_par(par_lst[x...
while True: n = int(input()) if n == 0: break days = [[] for _ in range(31)] for i in range(n): hima = list(map(int, input().split())) for d in hima[1:]: days[d].append(i) tos = [{i} for i in range(n)] end = {i for i in range(n)} for i in range(31): gather = set() for to in da...
s892598770
s572191863
p01136
python
Runtime Error
from heapq import heappush, heappop INF = 10 ** 20 while True: n, m, l, k, a, h = map(int, input().split()) if n == 0: break if l != 0: sisetu = list(map(int, input().split())) + [a, h] else: sisetu = [a, h] costs = [[INF] * n for _ in range(n)] for _ in range(k): x, y, t = map(int, input...
from heapq import heappop, heappush INF = 10 ** 20 def main(): while True: n, m, l, k, a, h = map(int, input().split()) if n == 0: break if l == 0: input() sisetu = [a, h] else: sisetu = list(map(int, input().split())) sisetu += [a, h] edges = [[] for _ in rang...
s198386882
s109169334
p01146
python
Runtime Error
from heapq import heappush, heappop INF = 10 ** 20 def main(): while True: n, m, l, k, a, h = map(int, input().split()) if n == 0: break if l != 0: sisetu = list(map(int, input().split())) + [a, h] else: input() sisetu = [a, h] costs = [[INF] * n for _ in range(n)] ...
from heapq import heappop, heappush INF = 10 ** 20 def main(): while True: n, m, l, k, a, h = map(int, input().split()) if n == 0: break if l == 0: input() sisetu = [a, h] else: sisetu = list(map(int, input().split())) sisetu += [a, h] edges = [[] for _ in rang...
s367537586
s109169334
p01146
python
Runtime Error
from collections import deque direct_l = ((-1, 0), (1, 0), (0, 1), (0, -1)) direct_r = ((1, 0), (-1, 0), (0, 1), (0, -1)) directs = tuple(zip(direct_l, direct_r)) def search(start_l, start_r, mp_l, mp_r): que = deque() que.append((start_l, start_r)) dic = {} dic[(start_l, start_r)] = True while que: pl,...
from collections import deque, defaultdict def main(): directs = ((-1, 0, 1, 0), (1, 0, -1, 0), (0, 1, 0, 1), (0, -1, 0, -1)) while True: w, h = map(int, input().split()) if w == 0: break mp_l = ["#" * (w + 2)] mp_r = ["#" * (w + 2)] for _ in range(h): l, r = input().split() ...
s879807290
s291096923
p01271
python
Runtime Error
from collections import deque direct_l = ((-1, 0), (1, 0), (0, 1), (0, -1)) direct_r = ((1, 0), (-1, 0), (0, 1), (0, -1)) directs = tuple(zip(direct_l, direct_r)) def search(start_l, start_r, mp_l, mp_r, dic): que = deque() que.append((start_l, start_r)) dic[start_l[0]][start_l[1]][start_r[0]][start_r[1]] = Tru...
from collections import deque, defaultdict def main(): directs = ((-1, 0, 1, 0), (1, 0, -1, 0), (0, 1, 0, 1), (0, -1, 0, -1)) while True: w, h = map(int, input().split()) if w == 0: break mp_l = ["#" * (w + 2)] mp_r = ["#" * (w + 2)] for _ in range(h): l, r = input().split() ...
s750824480
s291096923
p01271
python
Runtime Error
from collections import deque directs = ((-1, 0, 1, 0), (1, 0, -1, 0), (0, 1, 0, 1), (0, -1, 0, -1)) def search(start_l, start_r, mp_l, mp_r, dic): que = deque() que.append((start_l[0], start_l[1], start_r[0], start_r[1])) dic[start_l[0]][start_l[1]][start_r[0]][start_r[1]] = True while que: lx, ly, rx, r...
from collections import deque, defaultdict def main(): directs = ((-1, 0, 1, 0), (1, 0, -1, 0), (0, 1, 0, 1), (0, -1, 0, -1)) while True: w, h = map(int, input().split()) if w == 0: break mp_l = ["#" * (w + 2)] mp_r = ["#" * (w + 2)] for _ in range(h): l, r = input().split() ...
s197609775
s291096923
p01271
python
Runtime Error
from collections import deque, defaultdict def main(): directs = ((-1, 0, 1, 0), (1, 0, -1, 0), (0, 1, 0, 1), (0, -1, 0, -1)) while True: w, h = map(int, input().split()) if w == 0: break mp_l = ["#" * (w + 2)] mp_r = ["#" * (w + 2)] for _ in range(h): l, r = input().split() ...
from collections import deque, defaultdict def main(): directs = ((-1, 0, 1, 0), (1, 0, -1, 0), (0, 1, 0, 1), (0, -1, 0, -1)) while True: w, h = map(int, input().split()) if w == 0: break mp_l = ["#" * (w + 2)] mp_r = ["#" * (w + 2)] for _ in range(h): l, r = input().split() ...
s926631948
s291096923
p01271
python
Runtime Error
from collections import deque, defaultdict def main(): directs = ((-1, 0, 1, 0), (1, 0, -1, 0), (0, 1, 0, 1), (0, -1, 0, -1)) while True: w, h = map(int, input().split()) if w == 0: break mp_l = ["#" * (w + 2)] mp_r = ["#" * (w + 2)] for _ in range(h): l, r = input().split() ...
from collections import deque, defaultdict def main(): directs = ((-1, 0, 1, 0), (1, 0, -1, 0), (0, 1, 0, 1), (0, -1, 0, -1)) while True: w, h = map(int, input().split()) if w == 0: break mp_l = ["#" * (w + 2)] mp_r = ["#" * (w + 2)] for _ in range(h): l, r = input().split() ...
s128593013
s291096923
p01271
python
Runtime Error
dic = {"C":0, "C#":1, "D":2, "D#":3, "E":4, "F":5, "F#":6, "G":7, "G#":8, "A":9, "A#":10, "B":11} t = int(input()) for _ in range(t): n, m = map(int, input().split()) t_lst = [-100] + list(map(lambda x:dic[x],input().split())) s_lst = list(map(lambda x:dic[x],input().split())) s_lst.reverse() ...
dic = {"C":0, "C#":1, "D":2, "D#":3, "E":4, "F":5, "F#":6, "G":7, "G#":8, "A":9, "A#":10, "B":11} t = int(input()) for _ in range(t): n, m = map(int, input().split()) t_lst = [-100] + list(map(lambda x:dic[x],input().split())) s_lst = list(map(lambda x:dic[x],input().split())) s_lst.reverse() ...
s738681870
s378586656
p01308
python
Runtime Error
INF = 10 ** 20 def minimum_cost(now, visited): if (now, visited) in dp: return dp[(now, visited)] if visited == end: return 0 ret = INF for to in range(1, n + 1): if to not in visited: ret = min(ret, minimum_cost(to, tuple(sorted(list(visited) + [to]))) + cost(to, visited)) dp[(now, visi...
INF = 10 ** 20 def minimum_cost(rest, dp, tlst, tord, end, n): if rest in dp: return dp[rest] if rest == end: return 0 ret = INF for ind, to in enumerate(rest): if to == "0": tmp = minimum_cost(rest[:ind] + "1" + rest[ind + 1:], dp, tlst, tord, end, n) + cost(ind, rest, tlst, tord, n) ...
s081314435
s655140629
p01371
python
Runtime Error
INF = 10 ** 20 def minimum_cost(rest, dp, tlst, end, n): if rest in dp: return dp[rest] if rest == end: return 0 ret = INF for ind, to in enumerate(rest): if to == "0": tmp = minimum_cost(rest[:ind] + "1" + rest[ind + 1:], dp, tlst, end, n) + cost(ind, rest, tlst, n) if tmp < ret: ...
INF = 10 ** 20 def minimum_cost(rest, dp, tlst, tord, end, n): if rest in dp: return dp[rest] if rest == end: return 0 ret = INF for ind, to in enumerate(rest): if to == "0": tmp = minimum_cost(rest[:ind] + "1" + rest[ind + 1:], dp, tlst, tord, end, n) + cost(ind, rest, tlst, tord, n) ...
s748093039
s655140629
p01371
python
Runtime Error
dic = {} for num1 in range(ord("a"), ord("z") + 1): c1 = chr(num1) dic[c1] = [] for num2 in range(ord("a"), ord("z") + 1): c2 = chr(num2) for num3 in range(ord("a"), ord("z") + 1): c3 = chr(num3) dic[c1].append(c1 + c2 + c3 + "a") print("?" + dic["a"].pop()) used = set() while True: s = inp...
dic = {} for num1 in range(ord("a"), ord("z") + 1): c1 = chr(num1) dic[c1] = [] for num2 in range(ord("a"), ord("z") + 1): c2 = chr(num2) for num3 in range(ord("a"), ord("z") + 1): c3 = chr(num3) dic[c1].append(c1 + c2 + c3 + "a") print("?" + dic["a"].pop()) used = set() while True: s = inp...
s388117273
s745501088
p01390
python
Runtime Error
from collections import deque w, h = map(int, input().split()) mp = [input() for _ in range(h)] springs = [] tile_cnt = 0 for y in range(h): for x in range(w): if mp[y][x] == "*": springs.append((x, y)) if mp[y][x] == "g": gx, gy = x, y if mp[y][x] == "s": sx, sy = x, y tile_cnt ...
from collections import deque w, h = map(int, input().split()) mp = [input() for _ in range(h)] springs = [] tile_cnt = 0 for y in range(h): for x in range(w): if mp[y][x] == "*": springs.append((x, y)) if mp[y][x] == "g": gx, gy = x, y if mp[y][x] == "s": sx, sy = x, y tile_cnt ...
s429653415
s088360915
p01453
python
Runtime Error
n, m = map(int, input().split()) pros = sorted([list(map(int, input().split())) for _ in range(m)]) index = 0 covered = 0 right = 0 ans = 0 while True: a, b = pros[index] if a > covered + 1: covered = right ans += 1 continue else: right = max(right, b) index += 1 if covered == n: print(...
n, m = map(int, input().split()) pros = sorted([list(map(int, input().split())) for _ in range(m)]) index = 0 covered = 0 right = 0 ans = 0 while True: a, b = pros[index] if a > covered + 1: if covered == right: print("Impossible") break covered = right ans += 1 continue else: righ...
s031435836
s666767904
p01523
python
Time Limit Exceeded
c = {"1":"", "2":"k", "3":"s", "4":"t", "5":"n", "6":"h","7":"m", "8":"y", "9":"r", "0":"w"} m = {"T":"a", "L":"i", "U":"u", "R":"e", "D":"o"} s = input() ans = "" for i in range(0, len(s), 2): if com == "0U":ans += "nn" else:ans += c[com[0]] + m[com[1]] print(ans)
c = {"1":"", "2":"k", "3":"s", "4":"t", "5":"n", "6":"h","7":"m", "8":"y", "9":"r", "0":"w"} m = {"T":"a", "L":"i", "U":"u", "R":"e", "D":"o"} s = input() ans = "" for i in range(0, len(s), 2): com = s[i:i+2] if com == "0U":ans += "nn" else:ans += c[com[0]] + m[com[1]] print(ans)
s316335056
s487916372
p01531
python
Runtime Error
n, m = map(int, input().split()) s = input() left = right = 0 base = ord("a") - 1 score = ord(s[0]) - base mem = set() for _ in range(m): com = input() if com == "L++": score //= 27 left += 1 elif com == "L--": left -= 1 score = score * 27 + ord(s[left]) - base elif com == "R++": right += 1 ...
def main(): n, m = map(int, input().split()) s = input() mem = set() base = ord("a") - 1 mod1 = 1000000007 mod2 = 2147483647 h1 = [0] h2 = [0] for c in s: h1.append((h1[-1] * 27 + ord(c) - base) % mod1) h2.append((h2[-1] * 27 + ord(c) - base) % mod2) pow_mem1 = {0:1} pow_mem2 = {0:1} def...
s891840614
s867368013
p01558
python
Time Limit Exceeded
def main(): n, m = map(int, input().split()) s = input() left = right = 0 mem = set() for _ in range(m): com = input() if com == "L++": left += 1 elif com == "L--": left -= 1 elif com == "R++": right += 1 elif com == "R--": right -= 1 mem.add(s[left:right + 1]) ...
def main(): n, m = map(int, input().split()) s = input() mem = set() base = ord("a") - 1 mod1 = 1000000007 mod2 = 2147483647 h1 = [0] h2 = [0] for c in s: h1.append((h1[-1] * 27 + ord(c) - base) % mod1) h2.append((h2[-1] * 27 + ord(c) - base) % mod2) pow_mem1 = {0:1} pow_mem2 = {0:1} def...
s525095709
s867368013
p01558
python
Runtime Error
def main(): n = int(input()) words = [] scores = [] for _ in range(n): word, score = input().split() words.append(word) scores.append(int(score)) mp = ["#" * 6] + ["#" + input() + "#" for _ in range(4)] + ["#" * 6] t = int(input()) def search(word): used = [[False] * 6 for _ in range(6)...
def main(): n = int(input()) lst = [] for _ in range(n): word, score = input().split() lst.append((word, int(score))) mp = ["#" * 6] + ["#" + input() + "#" for _ in range(4)] + ["#" * 6] t = int(input()) def search(word): used = [[False] * 6 for _ in range(6)] vec = ((1, 0), (1, -1), (0, ...
s158608479
s639795659
p01631
python
Time Limit Exceeded
def add_edge(node, adj_lst, adj_rev, s1, s2): ind = 0 max_len = min(len(s1), len(s2)) while ind < max_len and s1[ind] == s2[ind]: ind += 1 if ind == max_len: if max_len < len(s1): return True return False c1 = ord(s1[ind]) - ord("a") c2 = ord(s2[ind]) - ord("a") adj_lst[c1].add(c2) adj...
def add_edge(node, adj_lst, s1, s2): ind = 0 max_len = min(len(s1), len(s2)) while ind < max_len and s1[ind] == s2[ind]: ind += 1 if ind == max_len: return max_len < len(s1) c1 = ord(s1[ind]) - ord("a") c2 = ord(s2[ind]) - ord("a") adj_lst[c1].add(c2) node.add(c1) node.add(c2) return False ...
s085781689
s096508186
p01646
python
Runtime Error
def search_left(ind): doors = [] for j in range(ind - 1, -1, -1): if alst[j] < 0: doors.append((j, -alst[j])) if alst[j] == 0: ret = alst[ind] for pos, lim in doors: ret = min(ret, lim - (ind - pos)) ret = max(0, ret) return ret return 0 def search_right(ind): doors...
w = int(input()) alst = list(map(int, input().split())) INF = 10 ** 20 acc = -INF left = [] for i in range(w): a = alst[i] if a == 0: acc = INF elif a > 0: acc -= 1 elif a < 0: acc = min(acc - 1, -a) left.append(acc) acc = -INF right = [] for i in range(w): a = alst[w - i - 1] if a == 0: ...
s825141223
s314936449
p01713
python
Runtime Error
def search_left(ind, alst, a, w): doors = [] for j in range(ind - 1, -1, -1): if alst[j] < 0: doors.append((j, -alst[j])) if alst[j] == 0: ret = a for pos, lim in doors: ret = min(ret, lim - (ind - pos)) ret = max(0, ret) return ret return 0 def search_right(ind, alst...
w = int(input()) alst = list(map(int, input().split())) INF = 10 ** 20 acc = -INF left = [] for i in range(w): a = alst[i] if a == 0: acc = INF elif a > 0: acc -= 1 elif a < 0: acc = min(acc - 1, -a) left.append(acc) acc = -INF right = [] for i in range(w): a = alst[w - i - 1] if a == 0: ...
s641340926
s314936449
p01713
python
Time Limit Exceeded
from bisect import bisect_left as bl def search_left(in_ind, alst, outs, doors): tmp = bl(outs, in_ind) if tmp == 0: return 0 out_ind = outs[tmp - 1] right_door = bl(doors, in_ind) - 1 if right_door < 0: return alst[in_ind] left_door = bl(doors, out_ind) ret = alst[in_ind] for door_ind in d...
w = int(input()) alst = list(map(int, input().split())) INF = 10 ** 20 acc = -INF left = [] for i in range(w): a = alst[i] if a == 0: acc = INF elif a > 0: acc -= 1 elif a < 0: acc = min(acc - 1, -a) left.append(acc) acc = -INF right = [] for i in range(w): a = alst[w - i - 1] if a == 0: ...
s333107554
s314936449
p01713
python
Time Limit Exceeded
s = input() end = "ABC" while True: if s == end: print("Yes") break s = s.replace("ABC", "X") if ("A" in s) + ("B" in s) + ("C" in s) != 2: print("No") break for c in "ABC": if c not in s: s = s.replace("X", c) break
s = input() end = "ABC" while True: if s == end: print("Yes") break s = s.replace(end, "X") if ("X" not in s) or sum((c in s for c in end)) != 2: print("No") break for c in end: if c not in s: s = s.replace("X", c) break
s664153491
s343174356
p01811
python
Time Limit Exceeded
n, w = map(int, input().split()) value = [] weight = [] num = [] for _ in range(n): vi, wi, ni = map(int, input().split()) value.append(vi) weight.append(wi) num.append(ni) def to_digit(x): acc = 1 ret = [0] while x >= acc: ret.append(acc) x -= acc acc *= 2 if x: ret.append(x) retur...
def main(): n, w = map(int, input().split()) value = [] weight = [] num = [] for _ in range(n): vi, wi, ni = map(int, input().split()) value.append(vi) weight.append(wi) num.append(ni) def summary(x): acc = 1 ret = [0] while x >= acc: ret.append(acc) x -= acc...
s137091155
s030508165
p02320
python
Time Limit Exceeded
INF = 10 ** 20 v_num, e_num, r = map(int, input().split()) dist_lst = [INF for _ in range(v_num)] edges_lst = [[] for _ in range(e_num)] negative_cycle_flag = False for _ in range(e_num): s, t, dist = map(int, input().split()) edges_lst[s].append((dist, t)) dist_lst[r] = 0 for _ in range(v_num): for v in ran...
""" BellmanFord """ INF = 10 ** 20 v_num, e_num, r = map(int, input().split()) dist_lst = [INF for _ in range(v_num)] edges_lst = [[] for _ in range(e_num)] negative_cycle_flag = False for _ in range(e_num): s, t, dist = map(int, input().split()) edges_lst[s].append((dist, t)) dist_lst[r] = 0 if e_num != 0: ...
s746998718
s223923696
p02362
python
Runtime Error
""" 強連結成分分解 """ def dfs(v, visited, edges, order): visited[v] = True for to in edges[v]: if not visited[to]: dfs(to, visited, edges, order) order.append(v) def search_strongly_connection(v, visited, reverse_edges, parent): visited[v] = True for to in reverse_edges[v]: if not visited[to]: ...
""" 強連結成分分解 """ import sys sys.setrecursionlimit(1000000) def dfs(v, visited, edges, order): visited[v] = True for to in edges[v]: if not visited[to]: dfs(to, visited, edges, order) order.append(v) def search_strongly_connection(v, visited, reverse_edges, parent, num): visited[v] = True for to i...
s447351435
s604660009
p02368
python
Runtime Error
from collections import deque INF = 10 ** 20 V, E = map(int, input().split()) net = [[0] * V for _ in range(V)] for _ in range(E): u, v, c = map(int, input().split()) net[u][v] = c start = 0 goal = V - 1 def check_net(node, path, capacity): for i in range(V): cap = net[node][i] if cap != 0: if i...
from collections import deque class Edge: def __init__(self, fromNode, toNode, cap, rev=None): self.fromNode = fromNode self.toNode = toNode self.cap = cap self.rev = rev class MaxFlow: def __init__(self, V): self.v = V self.edges = [[] for _ in range(V)] d...
s000637086
s949000847
p02376
python
Runtime Error
while True: a,b = map(int,input().split()) print (len(str(a+b)))
while True: try: a,b = map(int,input().split()) print (len(str(a+b))) except EOFError: break
s170008944
s648482927
p00002
python
Runtime Error
while True: a,b = map(int,input().split()) print (len(str(a+b))) except EOFError: break
while True: try: a,b = map(int,input().split()) print (len(str(a+b))) except EOFError: break
s040412686
s648482927
p00002
python
Runtime Error
a,b,c = map(int,input().split(" ")) if a==b and a==c: print(1) ptn = 1 if a==b and a!=c: print(1) ptn=2 cnt = 0 for i in range(a,b): if c%i == 0: cnt += 1 if ptn != 1 and ptn != 2: print(cnt)
a,b,c = map(int,input().split(" ")) ptn = 0 if a==b and a==c: print(1) ptn = 1 if a==b and a!=c: if a < c: print(1) ptn=2 else: print(0) ptn=2 cnt = 0 for i in range(a,b+1): if c%i == 0: cnt += 1 if ptn != 1 and ptn != 2: print(cnt)
s476640086
s183553017
p02398
python
Runtime Error
import math r = int(input()) print(r**2*math.pi," ",r*2*math.pi)
import math r = float(input()) print(r**2*math.pi,r*2*math.pi)
s732592267
s110737165
p02400
python
Runtime Error
import math r = int(input()) print(r**2*math.pi,r*2*math.pi)
import math r = float(input()) print(r**2*math.pi,r*2*math.pi)
s624166469
s110737165
p02400
python
Runtime Error
import math r = int(input()) print(r**2*math.pi,r*2*math.pi)
import math r = float(input()) print(r**2*math.pi,r*2*math.pi)
s624624116
s110737165
p02400
python
Runtime Error
M = 50100 p = [1]*M; p[0],p[1]=0,0; pm = [0]*M; pM = [0]*M; for i in range(2,M): if p[i]: for j in range(i*i,M,i): p[j] = 0 num = -1 for i in range(1,M): pm[i] = num if p[i]: num = i num = -1 for i in range(M-1,2,-1): pM[i] = num if p[i]: num = i while 1: n = input() if n==0: break ...
M = 50100 p = [1]*M; p[0],p[1]=0,0; pm = [0]*M; pM = [0]*M; for i in range(2,M): if p[i]: for j in range(i*i,M,i): p[j] = 0 num = -1 for i in range(1,M): pm[i] = num if p[i]: num = i num = -1 for i in range(M-1,2,-1): pM[i] = num if p[i]: num = i while 1: try: n = input() ...
s122080096
s556708800
p00044
python
Runtime Error
s = [0] M = 10001 p = [1]*M S = 0 for i in xrange(2,M): if p[i]: for j in xrange(i*i,M,i): p[j] = 0 S += i; s.append(S) while 1: n = input() if n==0: break print s[n]
s = [0] M = 104850 p = [1]*M S = 0 for i in range(2,M): if p[i]: for j in range(i*i,M,i): p[j] = 0 S += i; s.append(S) while 1: n = input() if n==0: break print s[n]
s167933203
s974011818
p00053
python
Runtime Error
dx, dy = [-1, 0, 1, 0], [0, -1, 0, 1] while True: ans = 0 try: m = ['0'*14] + ['0'+raw_input()+'0' for i in xrange(12)] + ['0'*14] f = [[False for i in xrange(14)] for j in xrange(14)] for y in xrange(1, 13): for x in xrange(1, 13): if m[y][x]=='1' and f[y][x]...
dx, dy = [-1, 0, 1, 0], [0, -1, 0, 1] while True: ans = 0 try: m = ['0'*14] + ['0'+raw_input()+'0' for i in xrange(12)] + ['0'*14] f = [[False for i in xrange(14)] for j in xrange(14)] for y in xrange(1, 13): for x in xrange(1, 13): if m[y][x]=='1' and f[y][x]...
s017818627
s118536302
p00067
python
Runtime Error
while 1: try: ipt = raw_input().split() except EOFError: break; s = [] for i in range(len(ipt)): if ipt[i].isdigit(): s.append(float(ipt[i])) else: b = s.pop(); a = s.pop(); if ipt[i]=='+': s.append(a+b) elif...
import sys for s in sys.stdin.readlines(): st = [] for c in s.strip().split(): if c=='+': st.append(st.pop()+st.pop()) elif c=='-': st.append(-st.pop()+st.pop()) elif c=='*': st.append(st.pop()*st.pop()) elif c=='/': st.append(1/st....
s825684418
s978501368
p00087
python
Runtime Error
while 1: try: ript = raw_input() except EOFError: break; ipt = ript.split() s = [] for i in range(len(ipt)): if ipt[i].isdigit(): s.append(float(ipt[i])) else: b = s.pop(); a = s.pop(); if ipt[i]=='+': s.append(a+b) ...
import sys for s in sys.stdin.readlines(): st = [] for c in s.strip().split(): if c=='+': st.append(st.pop()+st.pop()) elif c=='-': st.append(-st.pop()+st.pop()) elif c=='*': st.append(st.pop()*st.pop()) elif c=='/': st.append(1/st....
s408674944
s978501368
p00087
python
Runtime Error
while 1: try: ipt = raw_input().split() s = [] for i in range(len(ipt)): if ipt[i].isdigit(): s.append(float(ipt[i])) else: b = s.pop(); a = s.pop(); if ipt[i]=='+': s.append(a+b) eli...
import sys for s in sys.stdin.readlines(): st = [] for c in s.strip().split(): if c=='+': st.append(st.pop()+st.pop()) elif c=='-': st.append(-st.pop()+st.pop()) elif c=='*': st.append(st.pop()*st.pop()) elif c=='/': st.append(1/st....
s129908282
s978501368
p00087
python
Runtime Error
while 1: try: ipt = raw_input().split() s = [] for i in range(len(ipt)): if ipt[i].isdigit(): s.append(float(ipt[i])) else: b = s.pop(); a = s.pop(); if ipt[i]=='+': s.append(a+b) eli...
import sys for s in sys.stdin.readlines(): st = [] for c in s.strip().split(): if c=='+': st.append(st.pop()+st.pop()) elif c=='-': st.append(-st.pop()+st.pop()) elif c=='*': st.append(st.pop()*st.pop()) elif c=='/': st.append(1/st....
s808443833
s978501368
p00087
python
Runtime Error
import sys for s in sys.stdin.readlines(): st = [] for c in s.split(): if c.isdigit(): st.append(float(c)) else: b = st.pop(); a = st.pop(); if c=='+': st.append(a+b) elif c=='-': st.append(a-b) elif c=='...
import sys for s in sys.stdin.readlines(): st = [] for c in s.strip().split(): if c=='+': st.append(st.pop()+st.pop()) elif c=='-': st.append(-st.pop()+st.pop()) elif c=='*': st.append(st.pop()*st.pop()) elif c=='/': st.append(1/st....
s611819591
s978501368
p00087
python
Runtime Error
import sys for s in sys.stdin.readlines(): st = [] for c in s.strip().split(): if c.isdigit(): st.append(float(c)) else: b = st.pop(); a = st.pop(); if c=='+': st.append(a+b) elif c=='-': st.append(a-b) e...
import sys for s in sys.stdin.readlines(): st = [] for c in s.strip().split(): if c=='+': st.append(st.pop()+st.pop()) elif c=='-': st.append(-st.pop()+st.pop()) elif c=='*': st.append(st.pop()*st.pop()) elif c=='/': st.append(1/st....
s986524994
s978501368
p00087
python
Runtime Error
from math import sqrt EPS = 10**(-8) N = 100 def intersection(p, q, s, t): a = 2*(p-s) b = 2*(q-t) c = (p**2+q**2) - (s**2+t**2) A = a**2 + b**2 Bx = p*b**2 + a*(c-q*b) Cx = (p**2+q**2-1)*b**2 - 2*b*c*q + c**2 Dx = Bx**2-A*Cx #By = q*a**2 + b*(c-p*a) #Cy = (p**2+q**2-1)*a**2 - 2*a*c*...
import math while 1: N = int(input()) if N == 0: break PS = [] for i in range(N): x, y = map(float, input().split(',')) PS.append((int(x * 100000), int(y * 100000))) D2 = 100000**2 ans = 0 for i in range(101): py = i * 10000 for j in range(101): ...
s096195226
s212576579
p00090
python
Runtime Error
from math import sqrt EPS = 10**(-8) N = 100 def intersection(p, q, s, t): a = 2*(p-s) b = 2*(q-t) c = (p**2+q**2) - (s**2+t**2) A = a**2 + b**2 Bx = p*b**2 + a*(c-q*b) Cx = (p**2+q**2-1)*b**2 - 2*b*c*q + c**2 Dx = Bx**2-A*Cx #By = q*a**2 + b*(c-p*a) #Cy = (p**2+q**2-1)*a**2 - 2*a*c*...
import math while 1: N = int(input()) if N == 0: break PS = [] for i in range(N): x, y = map(float, input().split(',')) PS.append((int(x * 100000), int(y * 100000))) D2 = 100000**2 ans = 0 for i in range(101): py = i * 10000 for j in range(101): ...
s115173394
s212576579
p00090
python
Runtime Error
from math import sqrt EPS = 10**(-8) N = 100 def intersection(p, q, s, t): a = 2*(p-s) b = 2*(q-t) c = (p**2+q**2) - (s**2+t**2) A = a**2 + b**2 x0, y0, x1, y1 = [0.0]*4 if A<EPS: return p, q, s, t Bx = p*b**2 + a*(c-q*b) Cx = (p**2+q**2-1)*b**2 - 2*b*c*q + c**2 Dx = Bx**2-A*...
import math while 1: N = int(input()) if N == 0: break PS = [] for i in range(N): x, y = map(float, input().split(',')) PS.append((int(x * 100000), int(y * 100000))) D2 = 100000**2 ans = 0 for i in range(101): py = i * 10000 for j in range(101): ...
s496115988
s212576579
p00090
python
Runtime Error
def dfs(p, c, s): if c==n: return not s if p==-1: return 0 if memo[s][p][c] != -1: return memo[s][p][c] ret = 0 for i in xrange(min(p, s), -1, -1): ret += dfs(i-1, c+1, s-i) memo[s][p][c] = ret return ret while 1: n, s = map(int, raw_input().split()) ...
dp = [[0]*(1001) for _ in xrange(10)] dp[0][0] = 1 for i in xrange(101): si1 = 1001-i for k in xrange(9, 0, -1): dp_k = dp[k]; dp_k1 = dp[k-1] for j in xrange(si1): dp_k[i+j] += dp_k1[j] while 1: n, s = map(int, raw_input().split()) if n==0: exit(0) print dp[n][s]
s374199410
s059878684
p00097
python
Time Limit Exceeded
memo = [[[-1 for i in xrange(101)] for j in xrange(10)] for k in xrange(1001)] def dfs(rest, now, cnt): if rest==0 and now==0: return 1 if now==0 or cnt==-1: return 0 if memo[rest][now][cnt]!=-1: return memo[rest][now][cnt] memo[rest][now][cnt] = 0 for i in xrange(min(cnt, re...
dp = [[0]*(1001) for _ in xrange(10)] dp[0][0] = 1 for i in xrange(101): si1 = 1001-i for k in xrange(9, 0, -1): dp_k = dp[k]; dp_k1 = dp[k-1] for j in xrange(si1): dp_k[i+j] += dp_k1[j] while 1: n, s = map(int, raw_input().split()) if n==0: exit(0) print dp[n][s]
s322379196
s059878684
p00097
python
Runtime Error
class SegmentTree: def __init__(self, n): n_ = 1 while n_ < n: n_ *= 2 self.n = n_ self.data = [[0, -n_] for i in xrange(2*n_)] def add(self, k, a): idx = k + (self.n-1) data = self.data data[idx] = [data[idx][0] + a, -k] print data, idx, data[idx...
from heapq import heappush, heappop inputs = lambda: map(int, raw_input().split()) n, q = inputs() n += 1 que = [(0, 1, -1)] data = [0] * n T = [-1] * n for t in xrange(q): a, v = inputs() data[a] += v T[a] = t heappush(que, (-data[a], a, t)) v, k, p = que[0] while T[k]!=p: heappop(que)...
s203531064
s393386599
p00099
python
Runtime Error
class SegmentTree: def __init__(self, n): n_ = 1 while n_ < n: n_ *= 2 self.n = n_ self.data = [(0, -n_-1)] * (2*n_) def add(self, k, a): idx = k + (self.n-1) data = self.data data[idx] = (data[idx][0] + a, -k) while idx: idx = (idx - ...
from heapq import heappush, heappop inputs = lambda: map(int, raw_input().split()) n, q = inputs() n += 1 que = [(0, 1, -1)] data = [0] * n T = [-1] * n for t in xrange(q): a, v = inputs() data[a] += v T[a] = t heappush(que, (-data[a], a, t)) v, k, p = que[0] while T[k]!=p: heappop(que)...
s476148805
s393386599
p00099
python
Runtime Error
def solve(A, b): for i in xrange(3): if A[i][i] == 0.0: for j in xrange(i+1, 3): if A[j][i]!=0.0: A[i], A[j] = A[j], A[i] b[i], b[j] = b[j], b[i] for j in xrange(3): if i==j: continue a = A[j]...
def solve(A, b): for i in xrange(3): if A[i][i] == 0.0: for j in xrange(i+1, 3): if A[j][i]!=0.0: A[i], A[j] = A[j], A[i] b[i], b[j] = b[j], b[i] break for j in xrange(3): if i==j: con...
s358269672
s722527717
p00115
python
Runtime Error
import Queue, math while True: l = 0; r = [] try: inp = map(int, raw_input().split()) l = inp[0] r = inp[1:] except EOFError: break n = len(r) if 2*sum(r) < l: print "OK" else: que = Queue.PriorityQueue() dp = [[1000.0 for i in xrange(n)] f...
import math while True: l = 0; r = [] try: inp = map(int, raw_input().split()) l = inp[0] r = inp[1:] except EOFError: break n = len(r) if 2*sum(r) <= l: print "OK" else: s = [] if n>1: r.sort() for i in xrange(n/2):...
s177167674
s644990893
p00120
python
Time Limit Exceeded
import Queue, math while True: l = 0; r = [] try: inp = map(int, raw_input().split()) l = inp[0] r = inp[1:] except EOFError: break n = len(r) if 2*sum(r) <= l: print "OK" else: n2 = 2**n-1 que = Queue.PriorityQueue() dp = [[1000.0 ...
import math while True: l = 0; r = [] try: inp = map(int, raw_input().split()) l = inp[0] r = inp[1:] except EOFError: break n = len(r) if 2*sum(r) <= l: print "OK" else: s = [] if n>1: r.sort() for i in xrange(n/2):...
s417745123
s644990893
p00120
python
Time Limit Exceeded
import math while True: l = 0; r = [] try: inp = map(int, raw_input().split()) l = inp[0] r = inp[1:] except EOFError: break n = len(r) if 2*sum(r) <= l: print "OK" else: r.sort() s = [] for i in xrange(n/2): s = [r[i]] ...
import math while True: l = 0; r = [] try: inp = map(int, raw_input().split()) l = inp[0] r = inp[1:] except EOFError: break n = len(r) if 2*sum(r) <= l: print "OK" else: s = [] if n>1: r.sort() for i in xrange(n/2):...
s725578392
s644990893
p00120
python
Runtime Error
import sys memo = {} sys.setrecursionlimit(40320) def swap(state, a, b): state[a], state[b] = state[b], state[a] def dfs(state, pos, c): key = "".join(map(str, state)) if memo.has_key(key): return memo[key] memo[key] = c if pos!=0 and pos!=4: swap(state, pos-1, pos) dfs(state...
import Queue memo = {} def swap(state, a, b): state2 = state[:] state2[a], state2[b] = state2[b], state2[a] return state2 gkey = lambda state: "".join(map(str, state)) que = Queue.Queue() init = range(8) que.put((init, 0, 0)) memo[gkey(init)] = 0 while not que.empty(): state, pos, c = que.get() de...
s910378822
s488576852
p00121
python
Runtime Error
import sys memo = {} sys.setrecursionlimit(40320) def swap(state, a, b): state[a], state[b] = state[b], state[a] def dfs(state, pos, c): key = "".join(map(str, state)) if memo.has_key(key): return memo[key] memo[key] = c if pos!=0 and pos!=4: swap(state, pos-1, pos) dfs(state...
import Queue memo = {} def swap(state, a, b): state2 = state[:] state2[a], state2[b] = state2[b], state2[a] return state2 gkey = lambda state: "".join(map(str, state)) que = Queue.Queue() init = range(8) que.put((init, 0, 0)) memo[gkey(init)] = 0 while not que.empty(): state, pos, c = que.get() de...
s934915372
s488576852
p00121
python
Runtime Error
import sys for s in sys.stdin.readlines(): n = s.zfill(5) for i in xrange(2): print "".join(["*" if int(n[j])-5*i in range(5) else " " for j in xrange(5)]) print "="*5 for i in xrange(5): print "".join([" " if (int(n[j])%5)==i else "*" for j in xrange(5)])
import sys c = False for s in sys.stdin.readlines(): n = s.strip().zfill(5) if c: print c = True for i in xrange(2): print "".join(["*" if int(n[j])-5*i in range(5) else " " for j in xrange(5)]) print "="*5 for i in xrange(5): print "".join([" " if (int(n[j])%5)==i else "*" for j...
s013921449
s757411935
p00128
python
Runtime Error
bus = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1, 0] for i in xrange(input()): s, t = map(int, raw_input().split()) if s>5: print " ".join(map(str, bus[s:bus.index(t, s)+1])) else: if s<t: print " ".join(map(str, range(s, t+1))) else: print " ".join(map(str,...
bus = "0123456789543210123456789" rbus = "543210" for i in xrange(input()): s, t = raw_input().split() if t<s<'6': left = rbus.find(s, 0) right = rbus.find(t, left) print " ".join(rbus[left:right+1]) else: left = bus.find(s, 0) right = bus.find(t, left) print ...
s794703891
s038861374
p00140
python
Runtime Error
while 1: n = input() if n==0: break s = {i*i % n for i in xrange(1, n)} c = (n-1)/2 m = [0] * (c+1) for a in s: for b in s: if a==b: continue t = a-b if t<0: t += n if t > c: t = n - t m[t] += 1 print...
import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N = int(readline()) if N == 0: return False if N == 1: return True *S, = set(i**2 % N for i in range(1, N)) S.sort() L = len(S) C = [0]*N D = [0]*((N-1)//2) for i in range(L): a = ...
s449735951
s678409233
p00142
python
Time Limit Exceeded
while 1: n = int(raw_input()) if n==0: break s = {i*i % n for i in xrange(1, n)} c = (n-1)/2 m = [0] * (c+1) for a in s: for b in s: if a==b: continue t = a-b if t<0: t += n if t > c: t = n - t m[t] += 1 print "\n".join(map(...
import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N = int(readline()) if N == 0: return False if N == 1: return True *S, = set(i**2 % N for i in range(1, N)) S.sort() L = len(S) C = [0]*N D = [0]*((N-1)//2) for i in range(L): a = ...
s452298508
s678409233
p00142
python
Time Limit Exceeded
while 1: n = int(raw_input()) if n==0: break s = list({i*i % n for i in xrange(1, n)}) c = (n-1)/2 m = [0] * (c+1) for a in s: for b in s: if a==b: continue t = a-b if t<0: t += n if t > c: t = n - t m[t] += 1 print "\n".joi...
import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N = int(readline()) if N == 0: return False if N == 1: return True *S, = set(i**2 % N for i in range(1, N)) S.sort() L = len(S) C = [0]*N D = [0]*((N-1)//2) for i in range(L): a = ...
s092093045
s678409233
p00142
python
Time Limit Exceeded
while 1: n = input() if n == 0: break D = {x**2 % n for x in xrange(1, n)} C = {} print D for p in D: for q in D: if p == q: continue g = (p - q) % n if g > (n - 1)/2: g = n - g C[g] = C.get(g, 0) + 1...
import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N = int(readline()) if N == 0: return False if N == 1: return True *S, = set(i**2 % N for i in range(1, N)) S.sort() L = len(S) C = [0]*N D = [0]*((N-1)//2) for i in range(L): a = ...
s498173118
s678409233
p00142
python
Time Limit Exceeded
while 1: n = input() if n == 0: break D = {x**2 % n for x in xrange(1, n)} C = [0]*((n-1)/2) for p in D: for q in D: if p == q: continue g = (p - q) % n if g > (n - 1)/2: g = n - g C[g-1] += 1 print "...
import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N = int(readline()) if N == 0: return False if N == 1: return True *S, = set(i**2 % N for i in range(1, N)) S.sort() L = len(S) C = [0]*N D = [0]*((N-1)//2) for i in range(L): a = ...
s877463926
s678409233
p00142
python
Time Limit Exceeded
while 1: n = input() if n == 0: break D = list({x**2 % n for x in xrange(1, n)}) C = [0]*((n-1)/2) for i in xrange(len(D)): p = D[i] for j in xrange(i): q = D[j] g = (p - q) % n C[min(g, n-g)-1] += 2 print "\n".join(map(str, C))
import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N = int(readline()) if N == 0: return False if N == 1: return True *S, = set(i**2 % N for i in range(1, N)) S.sort() L = len(S) C = [0]*N D = [0]*((N-1)//2) for i in range(L): a = ...
s778892188
s678409233
p00142
python
Time Limit Exceeded
n = input() C = [map(int, raw_input().split()) for i in xrange(n)] memo = {(i, i): 0 for i in xrange(n)} def calc(i, j): if (i, j) in memo: return memo[i, j] return min(calc(i, k) + calc(k+1, j) + C[i][0]*C[k][1]*C[k+1][0]*C[j][1] for k in xrange(i, j)) print calc(0, n-1)
n = input() C = [map(int, raw_input().split()) for i in xrange(n)] memo = {(i, i): 0 for i in xrange(n)} def calc(i, j): if (i, j) in memo: return memo[i, j] res = memo[i, j] = min(calc(i, k) + calc(k+1, j) + C[i][0]*C[k][1]*C[k+1][0]*C[j][1] for k in xrange(i, j)) return res print calc(0, n-1)
s408238303
s091655605
p00145
python
Time Limit Exceeded
M = 10**6; dp = [-1]*M; dp[0],dp[1] = 0,0; def collatz(n): if dp[n]!=-1: return dp[n] dp[n] = 1+collatz(n/2 if n%2==0 else 3*n+1) return dp[n] while 1: n = input() if n==0: break print collatz(n)
def collatz(n): if n==1: return 0 return 1+collatz(n/2 if n%2==0 else 3*n+1) while 1: n = input() if n==0: break print collatz(n)
s223242999
s748160000
p00158
python
Runtime Error
while 1: n = int(input()) team = [] for _ in range(n): i, *T = map(int, input().split()) t = 0 for m, s in zip(T[::2], T[1::2]): t += m*60 + s team.append((t, i)) team.sort() print(*[team[0][1], team[1][1], team[-2][1]], sep='\n')
while 1: n = int(input()) if n == 0: break team = [] for _ in range(n): i, *T = map(int, input().split()) t = 0 for m, s in zip(T[::2], T[1::2]): t += m*60 + s team.append((t, i)) team.sort() print(*[team[0][1], team[1][1], team[-2][1]], sep='\...
s699499813
s993370986
p00161
python
Runtime Error
while 1: n = int(input()) team = [] for _ in range(n): i, *T = map(int, input().split()) t = 0 for m, s in zip(T[::2], T[1::2]): t += m*60 + s team.append((t, i)) team.sort() print(team[0][1]) print(team[1][1]) print(team[-2][1])
while 1: n = int(input()) if n == 0: break team = [] for _ in range(n): i, *T = map(int, input().split()) t = 0 for m, s in zip(T[::2], T[1::2]): t += m*60 + s team.append((t, i)) team.sort() print(*[team[0][1], team[1][1], team[-2][1]], sep='\...
s211863390
s993370986
p00161
python
Runtime Error
num = [2,3,5] M = 10**6; S = [0]*(M+2); S[1] = 1; s = 0; for i in xrange(1,M+1): if S[i]==1: for j in xrange(3): S[min(M+1,num[j]*i)] = 1; s += 1 S[i] = s while 1: try: m,n = map(int, raw_input().split()) print S[n]-S[m-1] except EOFError: break
while 1: ipt = raw_input() if ipt=="0": break m,n = map(int, ipt.split()) ans = 0 for i in xrange(m,n+1): p = i while p>1: if p%2==0: p/=2 elif p%3==0: p/=3 elif p%5==0: p/=5 else: break ...
s139951710
s956477909
p00162
python
Runtime Error
num = [2,3,5] M = 10**6; S = [0]*(M+2); S[1] = 1; s = 0; i = 0; while(i<M+1): if S[i]==1: for j in xrange(3): S[min(M+1,num[j]*i)] = 1; s += 1 S[i] = s i+=1 while 1: try: m,n = map(int, raw_input().split()) print S[n]-S[m-1] except EOFError: break
while 1: ipt = raw_input() if ipt=="0": break m,n = map(int, ipt.split()) ans = 0 for i in xrange(m,n+1): p = i while p>1: if p%2==0: p/=2 elif p%3==0: p/=3 elif p%5==0: p/=5 else: break ...
s148130881
s956477909
p00162
python
Runtime Error
while 1: try: n,m = map(int, raw_input().split()) ans = 0 for i in xrange(n,m+1): p = i while p>1: if p%2==0: p/=2 elif p%3==0: p/=3 elif p%5==0: p/=5 ...
while 1: ipt = raw_input() if ipt=="0": break m,n = map(int, ipt.split()) ans = 0 for i in xrange(m,n+1): p = i while p>1: if p%2==0: p/=2 elif p%3==0: p/=3 elif p%5==0: p/=5 else: break ...
s326372692
s956477909
p00162
python
Runtime Error
while 1: n = input() if n==0: break s = [0 for i in range(13)] for i in range(n): s[input()/10] += 1 for i in range(6): print s[i] print sum(s[6:])
while 1: n = input() if n==0: break s = [0 for i in range(13)] for i in range(n): s[int(raw_input())/10] += 1 for i in range(6): print s[i] print sum(s[6:])
s230083623
s381871056
p00184
python
Time Limit Exceeded
while 1: n = input() if n==0: break s = [0 for i in range(7)] for i in range(n): age = input() s[age/10 if age<60 else 6] += 1 for i in range(7): print s[i]
while 1: n = input() if n==0: break s = [0 for i in range(13)] for i in range(n): s[int(raw_input())/10] += 1 for i in range(6): print s[i] print sum(s[6:])
s104719776
s381871056
p00184
python
Time Limit Exceeded