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
while 1: n = input() if n==0: break s = [0 for i in range(7)] for i in range(n): age = input() s[min(6, age/10)] += 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:])
s637623231
s381871056
p00184
python
Time Limit Exceeded
while 1: n = input() if n==0: break s = [0 for i in xrange(7)] for i in range(n): age = input() s[min(6, age/10)] += 1 for i in xrange(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:])
s921225051
s381871056
p00184
python
Time Limit Exceeded
while 1: n = input() if n==0: break s = [0 for i in xrange(7)] for i in xrange(n): age = input() s[min(6, age/10)] += 1 for i in xrange(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:])
s323175695
s381871056
p00184
python
Time Limit Exceeded
while 1: s = [0 for i in xrange(7)] n = input() if n==0: break for i in xrange(n): age = input() s[min(6, age/10)] += 1 for i in xrange(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:])
s748117578
s381871056
p00184
python
Time Limit Exceeded
while 1: n = input() if n==0: break pm = -1; m = 0; for i in xrange(n): p,d1,d2 = map(int, raw_input().split()) if m<d1+d2: pm = p; m = d1+d2; print pm,m
while 1: try: n = input() if n==0: break l = [] for i in range(n): p,d1,d2 = map(int, raw_input().split()) l.append([p,d1+d2]) l.sort(reverse=True, key=lambda x:x[1]) print l[0][0],l[0][1] except SyntaxError: pass
s269932095
s588054357
p00217
python
Runtime Error
while 1: n = input() if n==0: break pm = -1; m = -1; for i in range(n): p,d1,d2 = map(int, raw_input().split()) if m<d1+d2: pm = p; m = d1+d2; print pm,m
while 1: try: n = input() if n==0: break l = [] for i in range(n): p,d1,d2 = map(int, raw_input().split()) l.append([p,d1+d2]) l.sort(reverse=True, key=lambda x:x[1]) print l[0][0],l[0][1] except SyntaxError: pass
s274773219
s588054357
p00217
python
Runtime Error
while 1: n = input() if n==0: break l = [] for i in range(n): p,d1,d2 = map(int, raw_input().split()) l.append([p,d1+d2]) l.sort(reverse=True, key=lambda x:x[1]) print l[0][0],l[0][1]
while 1: try: n = input() if n==0: break l = [] for i in range(n): p,d1,d2 = map(int, raw_input().split()) l.append([p,d1+d2]) l.sort(reverse=True, key=lambda x:x[1]) print l[0][0],l[0][1] except SyntaxError: pass
s281004401
s588054357
p00217
python
Runtime Error
while 1: w = raw_input() if w=="0000": break if int(w)%1111==0: print "NA" continue ans = 0 while(w!="6174"): w = str(int("".join(sorted(w,reverse=True)))-int("".join(sorted(w)))) ans += 1 print ans
while 1: w = raw_input() if w=="0000": break if int(w)%1111==0: print "NA" continue ans = 0 while(w!="6174"): w = ("".join(sorted(w))).zfill(4) w = str(int(w[::-1])-int(w)) ans += 1 print ans
s937463624
s708048823
p00254
python
Time Limit Exceeded
input();Q=[0]*101 for p in map(int,input().split()):Q[p]+=1 print(max(i for i in range(101)if sum(Q[i:])>=i))
input();Q=[0]*101 for p in map(int,input().split()):Q[p]+=1 print(max(i for i in range(101)if sum(Q[i:])>=i))
s395041168
s268963568
p00314
python
Runtime Error
n = int(input()) stmts = [input().split() for i in range(n)] mapper = {} for i, stmt in enumerate(stmts): mapper[stmt[0]] = i vn = {} for stmt in stmts: for ope in stmt[2:]: if ope.isalpha() and ope not in vn: vn[ope] = len(vn) vs = [0]*len(vn) def check(x): return 0 <= x < 16 def valu...
n = int(input()) stmts = [input().split() for i in range(n)] mapper = {} for i, stmt in enumerate(stmts): mapper[stmt[0]] = i vn = {} for stmt in stmts: for ope in stmt[2:]: if ope.isalpha() and ope not in vn: vn[ope] = len(vn) vs = [0]*len(vn) def stmt_add(v1, v2, v3): v1 = vn[v1] ...
s438788069
s930862326
p00325
python
Time Limit Exceeded
n = int(input()) stmts = [input().split() for i in range(n)] mapper = {} for i, stmt in enumerate(stmts): mapper[stmt[0]] = i vn = {} for stmt in stmts: for ope in stmt[2:]: if ope.isalpha() and ope not in vn: vn[ope] = len(vn) vs = [0]*len(vn) def value(var): if var.isalpha(): ...
n = int(input()) stmts = [input().split() for i in range(n)] mapper = {} for i, stmt in enumerate(stmts): mapper[stmt[0]] = i vn = {} for stmt in stmts: for ope in stmt[2:]: if ope.isalpha() and ope not in vn: vn[ope] = len(vn) vs = [0]*len(vn) def stmt_add(v1, v2, v3): v1 = vn[v1] ...
s139723797
s930862326
p00325
python
Time Limit Exceeded
n = int(input()) stmts = [input().split() for i in range(n)] mapper = {} for i, stmt in enumerate(stmts): mapper[stmt[0]] = i vn = {} for stmt in stmts: for ope in stmt[2:]: if ope.isalpha() and ope not in vn: vn[ope] = len(vn) vs = [0]*len(vn) def value(var): if var.isalpha(): ...
n = int(input()) stmts = [input().split() for i in range(n)] mapper = {} for i, stmt in enumerate(stmts): mapper[stmt[0]] = i vn = {} for stmt in stmts: for ope in stmt[2:]: if ope.isalpha() and ope not in vn: vn[ope] = len(vn) vs = [0]*len(vn) def stmt_add(v1, v2, v3): v1 = vn[v1] ...
s221794198
s930862326
p00325
python
Time Limit Exceeded
n = int(input()) *P, = map(int, input().split()) memo = {(n-1, i): i for i in range(P[-1]+1)} def dfs(pos, t): if (pos, t) in memo: return memo[pos, t] res = memo[pos, t] = dfs(pos+1, max(0, P[pos+1]-t)) + t*2 return res print(min(dfs(0, P[0]-i)+i for i in range(P[0]+1)))
import sys sys.setrecursionlimit(10**6) n = int(input()) *P, = map(int, input().split()) memo = {(n-1, i): i for i in range(P[-1]+1)} def dfs(pos, t): if (pos, t) in memo: return memo[pos, t] res = memo[pos, t] = dfs(pos+1, max(0, P[pos+1]-t)) + t*2 return res print(min(dfs(0, P[0]-i)+i for i in ran...
s470734653
s713822902
p00335
python
Runtime Error
n = int(input()) for i in range(n): F = set(map(int, input().split())) fl = min(F); fr = max(F) G = {*range(1, 14)} - F - {7} gl = min(G); gr = max(G) memo = {} def dfs(s, t, u): if (s, t, u) in memo: return memo[s, t, u] T = [G, F][u] res = 0 if s-1 ...
n = int(input()) for i in range(n): F = set(map(int, input().split())) fl = min(F); fr = max(F) G = {i for i in range(1, 14)} - F - {7} gl = min(G); gr = max(G) memo = {} def dfs(s, t, u): if (s, t, u) in memo: return memo[s, t, u] T = [G, F][u] res = 0 ...
s736673918
s733044099
p00343
python
Runtime Error
w, h = map(int, input().split()) S = [list(map(int, input().split())) for i in range(h)] SW = [[0]*w for i in range(h)] SH = [[0]*w for i in range(h)] for i in range(h): cnt = 0 for j in range(w-1, -1, -1): cnt += S[i][j] SW[i][j] = cnt for j in range(w): cnt = 0 for i in range(h-1, -1, ...
import sys sys.setrecursionlimit(10**7) w, h = map(int, input().split()) S = [list(map(int, input().split())) for i in range(h)] SW = [[0]*w for i in range(h)] SH = [[0]*w for i in range(h)] for i in range(h): cnt = 0 for j in range(w-1, -1, -1): cnt += S[i][j] SW[i][j] = cnt for j in range(w): ...
s365330132
s889247496
p00347
python
Runtime Error
p = [[0 for i in xrange(16)] for j in xrange(16)] while 1: a,b = map(int, raw_input().split()) if a==b==0: break n = input() for i in xrange(b): for j in xrange(a): p[i][j] = 0 for i in xrange(n): x,y = map(int, raw_input().split()) p[y-1][x-1] = -10**6 p[0][0...
p = [[0 for i in xrange(17)] for j in xrange(17)] while 1: a,b = map(int, raw_input().split()) if a==b==0: break n = input() for i in xrange(b): for j in xrange(a): p[i][j] = 0 for i in xrange(n): x,y = map(int, raw_input().split()) p[y-1][x-1] = -10**6 p[0][0...
s267288604
s745419675
p00438
python
Runtime Error
while 1: INF = 10**9 N, K = map(int, input().split()) if N == K == 0: break E = [[INF]*N for i in range(N)] for i in range(N): E[i][i] = 0 ans = [] for i in range(K): q, *c = map(int, input().split()) if q == 0: a, b = c cost = E[a-1][b...
while 1: INF = 10**9 N, K = map(int, input().split()) if N == K == 0: break E = [[INF]*N for i in range(N)] for i in range(N): E[i][i] = 0 ans = [] for i in range(K): q, *c = map(int, input().split()) if q == 0: a, b = c cost = E[a-1][b...
s289254385
s700593501
p00449
python
Time Limit Exceeded
class RollingHash: def __init__(self, s, base, MOD): self.s = s self.l = l = len(s) self.base = base self.MOD = MOD self.h = h = [0]*(l + 1) for i in range(l): h[i+1] = (h[i] * base + ord(s[i])) % MOD def get(self, l, r): MOD = self.MOD ...
def rolling_hash(S, base, MOD): l = len(S) h = [0]*(l + 1) for i in range(l): h[i+1] = (h[i] * base + ord(S[i])) % MOD return h C = open(0).read().split() MOD = 358976445361682909 base = 31 for t in range(len(C)//2): S = C[2*t]; T = C[2*t+1] rhs = rolling_hash(S, base, MOD) rht = r...
s102980062
s811698390
p00451
python
Time Limit Exceeded
while True: n, m = map(int, raw_input().split()) if n==0 and m==0: break b = [input() for i in xrange(n)] p = 0; ans = 0; for i in xrange(m): d = input() p += d if p>=n-1 or p+b[p]>=n-1: ans = i+1 break p += b[p] print ans
while True: n, m = map(int, raw_input().split()) if n==0 and m==0: break b = [input() for i in xrange(n)] d = [input() for i in xrange(m)] p = 0; ans = 0; for i in xrange(m): p += d[i] if p>=n-1 or p+b[p]>=n-1: ans = i+1 break p += b[p] ...
s491459033
s311658672
p00467
python
Runtime Error
from queue import Queue INF = 20000000 q = Queue() dx = [-1, 0, 1, 0] dy = [0, -1, 0, 1] smp = [[INF for i in range(1002)] for j in range(1002)] mp = [['X' for i in range(1002)] for j in range(1002)] ipt = input().split('\n') H, W, n = map(int,ipt[0].split()) for i in range(1, H+1): for j in range(1, W+1): ...
from Queue import Queue INF = 20000000 q = Queue() dx = [-1, 0, 1, 0] dy = [0, -1, 0, 1] smp = [[INF for i in range(1002)] for j in range(1002)] mp = [['X' for i in range(1002)] for j in range(1002)] H, W, n = map(int,raw_input().split()) for i in range(1, H+1): ipt = raw_input() for j in range(1, W+1): ...
s393832534
s580719382
p00481
python
Runtime Error
from Queue import Queue INF = 20000000 q = Queue() dx = [-1, 0, 1, 0] dy = [0, -1, 0, 1] smp = [[INF for i in range(1002)] for j in range(1002)] mp = [['X' for i in range(1002)] for j in range(1002)] ipt = raw_input().split('\n') H, W, n = map(int,ipt[0].split()) for i in range(1, H+1): for j in range(1, W+1): ...
from Queue import Queue INF = 20000000 q = Queue() dx = [-1, 0, 1, 0] dy = [0, -1, 0, 1] smp = [[INF for i in range(1002)] for j in range(1002)] mp = [['X' for i in range(1002)] for j in range(1002)] H, W, n = map(int,raw_input().split()) for i in range(1, H+1): ipt = raw_input() for j in range(1, W+1): ...
s568703582
s580719382
p00481
python
Runtime Error
N, M = map(int, input().split()) D = [int(input()) for i in range(N)] C = [int(input()) for i in range(M)] memo = {} def dfs(i, j): if i == N: return 0 if j == M: return 10**9 if (i, j) in memo: return memo[i, j] memo[i, j] = res = min(dfs(i+1, j+1) + D[i]*C[j], dfs(i, j+1)) ...
import sys sys.setrecursionlimit(10**7) N, M = map(int, input().split()) D = [int(input()) for i in range(N)] C = [int(input()) for i in range(M)] memo = {} def dfs(i, j): if i == N: return 0 if j == M: return 10**9 if (i, j) in memo: return memo[i, j] memo[i, j] = res = min(dfs(...
s001517890
s898189914
p00534
python
Runtime Error
H, W = map(int, input().split()) S = [] for i in range(H): tmp = [] s = input() for j in range(W): if s[j] == '.': tmp.append(-1) else: tmp.append(int(s[j])) S.append(tmp) D = [0, 1, -1, -1, 0, -1, 1, 1, 0] update = 1; ans = 0 while update: update = 0; ans += ...
from collections import deque H, W = map(int, input().split()) S = [list(map(lambda x: int(x) if x != '.' else -1, input())) for i in range(H)] dd = ((-1, 0), (-1, -1), (0, -1), (1, -1), (1, 0), (1, 1), (0, 1), (-1, 1)) que = [] D = [[0]*W for i in range(H)] for i in range(H): for j in range(W): v = S[i][j]...
s786968461
s380530166
p00535
python
Runtime Error
N, M = map(int, input().split()) N2 = 2**N.bit_length() D = [[0]*(N2+1) for i in range(M)] def get(i, k): data = D[i] s = 0 while k: s += data[k] k -= k & -k return s def add(i, k, x): data = D[i] while k <= N2: data[k] += x k += k & -k cnts = [0]*M for i in range...
N, M = map(int, input().split()) D = [[0]*(N+1) for i in range(M)] cnts = [0]*M for i in range(N): v = int(input()) cnts[v-1] += 1 D[v-1][i+1] = 1 for i in range(M): d = D[i] for j in range(1, N+1): d[j] += d[j-1] memo = [None]*(2**M) memo[2**M-1] = 0 def dfs(state, idx): if memo[state] ...
s824360433
s113100384
p00556
python
Runtime Error
def s(p,A,B):b=lambda i:(A[i]and B[i])and s(p,A[i],B[i])or p==u and(A[i]or B[i])or 0;return(b(0),b(1)) try: while 1:g=_,i,u=raw_input().split();print`s(*map(lambda s:eval(s.replace("(,","(0,").replace(",)",",0)")),g))`.replace(" ","").replace("0","") except:pass
def convert(s): cur = [0] def dfs(): result = [0, 0] cur[0] += 1 # '(' if s[cur[0]] == '(': result[0] = dfs() cur[0] += 1 # ',' if s[cur[0]] == '(': result[1] = dfs() cur[0] += 1 # ')' return result return dfs() def rconvert(C):...
s670007996
s326552685
p00587
python
Runtime Error
import sys M = 1001; p = [1]*M; p[0],p[1] = 0,0 for i in xrange(31): if p[i]: for j in xrange(i*i,M,i): p[j] = 0 for s in sys.stdin.readlines(): n = int(s); ans = 0; for i in xrange(1,n+1): if p[i] and p[n+1-i]: ans += 1 print ans
M = 10001; p = [1]*M; p[0],p[1] = 0,0 for i in xrange(2,101): if p[i]: for j in xrange(i*i,M,i): p[j] = 0 while 1: try: n = int(raw_input()); ans = 0; for i in xrange(1,n+1): if p[i] and p[n+1-i]: ans += 1 print ans except EOFError: ...
s213338605
s304155101
p00590
python
Runtime Error
import sys M = 1001; p = [1]*M; p[0],p[1] = 0,0 for i in xrange(31): if p[i]: for j in xrange(i*i,M,i): p[j] = 0 for s in sys.stdin.readlines(): n = int(s.strip()); ans = 0; for i in xrange(1,n+1): if p[i] and p[n+1-i]: ans += 1 print ans
M = 10001; p = [1]*M; p[0],p[1] = 0,0 for i in xrange(2,101): if p[i]: for j in xrange(i*i,M,i): p[j] = 0 while 1: try: n = int(raw_input()); ans = 0; for i in xrange(1,n+1): if p[i] and p[n+1-i]: ans += 1 print ans except EOFError: ...
s114912746
s304155101
p00590
python
Runtime Error
M = 1001; p = [1]*M; p[0],p[1] = 0,0 for i in xrange(32): if p[i]: for j in xrange(i*i,M,i): p[j] = 0 while 1: try: n = int(raw_input()); ans = 0; for i in xrange(1,n+1): if p[i] and p[n+1-i]: ans += 1 print ans except EOFError: ...
M = 10001; p = [1]*M; p[0],p[1] = 0,0 for i in xrange(2,101): if p[i]: for j in xrange(i*i,M,i): p[j] = 0 while 1: try: n = int(raw_input()); ans = 0; for i in xrange(1,n+1): if p[i] and p[n+1-i]: ans += 1 print ans except EOFError: ...
s418387108
s304155101
p00590
python
Runtime Error
while 1: n = input() if n==0: break w, h = map(int, raw_input().split()) p = [map(int, raw_input().split()) for i in xrange(n)] s, t = map(int, raw_input().split()) ans = 0 for b in xrange(1, h-t+2): for a in xrange(w-s+2): cnt = 0 for c, d in p: ...
while 1: n = input() if n==0: break w, h = map(int, raw_input().split()) m = [[0]*w for i in range(h)] l = [[0]*(w+1) for i in range(h+1)] for i in xrange(n): x, y = map(int, raw_input().split()) m[y-1][x-1] = 1 for i in xrange(h): temp = 0 for j in xr...
s718213799
s797718190
p00706
python
Time Limit Exceeded
while 1: N, M, C, s, g = map(int, raw_input().split()) if N == M == 0: break es = [[] for i in xrange(C)] for i in xrange(M): x, y, d, c = map(int, raw_input().split()) if not x < y: x, y = y, x es[c-1].append((x-1, y-1, d)) P = map(int, raw_input().split(...
while 1: N, M, C, s, g = map(int, raw_input().split()) if N == M == 0: break es = [[] for i in xrange(C)] for i in xrange(M): x, y, d, c = map(int, raw_input().split()) if not x < y: x, y = y, x es[c-1].append((x-1, y-1, d)) P = map(int, raw_input().split(...
s417493950
s506168228
p00763
python
Runtime Error
# encoding: shift-jis # Dinic algorithm from collections import deque class Dinic: def __init__(self, n): self.n = n self.g = [[] for i in xrange(n)] def add_edge(self, fr, to, cap): self.g[fr].append([to, cap, len(self.g[to])]) self.g[to].append([fr, 0, len(self.g[fr])-1]) ...
# Dinic algorithm from collections import deque class Dinic: def __init__(self, n): self.n = n self.g = [[] for i in xrange(n)] def add_edge(self, fr, to, cap): self.g[fr].append([to, cap, len(self.g[to])]) self.g[to].append([fr, 0, len(self.g[fr])-1]) def add_multi_edge(self...
s689038227
s417160677
p00766
python
Runtime Error
from math import sqrt from collections import deque M = 10**6 prime = [1]*(M+1) prime[0] = prime[1] = 0 for i in xrange(2, int(sqrt(M))+1): if prime[i]: for j in xrange(i*i, M+1, i): prime[j] = 0 P = {(0, 0): 1}; R = [None, (0, 0)] c = 1; i = 1; p = 1 x = y = 0 while c < M: for j in xrange(i...
from math import sqrt from collections import deque M = 10**6 prime = [1]*(M+1) prime[0] = prime[1] = 0 for i in xrange(2, int(sqrt(M))+1): if prime[i]: for j in xrange(i*i, M+1, i): prime[j] = 0 P = {(0, 0): 1}; R = [None, (0, 0)] c = 1; i = 1; p = 1 x = y = 0 while c < M: for j in xrange(i...
s353874497
s650929799
p00770
python
Runtime Error
def dfs(dg, gs, ms, v): me = ms[v] for i in xrange(len(me)): if me[i] in dg: ret = dfs(dg, gs, ms, gs.index(me[i])) for e in ret: if e not in dg[gs[v]]: dg[gs[v]].append(e) else: if me[i] not in dg[gs[v]]: dg...
def dfs(dg, gs, ms, used, v): if used[v]: return dg[gs[v]] used[v] = 1 me = ms[v] for i in xrange(len(me)): if me[i] in dg: ret = dfs(dg, gs, ms, used, gs.index(me[i])) for e in ret: if e not in dg[gs[v]]: dg[gs[v]].append(e) ...
s873494609
s654739039
p00884
python
Runtime Error
while 1: n = input() if n == 0: break status = {} god_st = 0 res = {} for i in xrange(n): s = raw_input().split() #M, D = map(int, s[0].split("/")) h, m = map(int, s[1].split(":")) mi = 60*h + m st = s[2] == 'I' ID = s[3] if ID == ...
while 1: n = input() if n == 0: break status = {} god_st = -1 res = {} for i in xrange(n): s = raw_input().split() #M, D = map(int, s[0].split("/")) h, m = map(int, s[1].split(":")) mi = 60*h + m st = s[2] == 'I' ID = s[3] if ID ==...
s462455219
s865173998
p00894
python
Runtime Error
while 1: n = int(input()) if n == 0: break S = [input() for i in range(n)] dup = [0]*n for i in range(n): for j in range(i+1, n): if S[i].find(S[j])+1: dup[j] = 1 if S[j].find(S[i])+1: dup[i] = 1 S = [S[i] for i in range(n)...
while 1: n = int(input()) if n == 0: break S = [input() for i in range(n)] dup = [0]*n for i in range(n): si = S[i] for j in range(i+1, n): sj = S[j] if si.find(sj)+1: dup[j] = 1 if sj.find(si)+1: dup[i] = 1...
s467037642
s288526310
p00899
python
Runtime Error
from heapq import heappush, heappop, heapify while 1: n = int(input()) if n == 0: break S = [input() for i in range(n)] dup = [0]*n for i in range(n): for j in range(i+1, n): if S[i].find(S[j])+1: dup[j] = 1 if S[j].find(S[i])+1: ...
while 1: n = int(input()) if n == 0: break S = [input() for i in range(n)] dup = [0]*n for i in range(n): si = S[i] for j in range(i+1, n): sj = S[j] if si.find(sj)+1: dup[j] = 1 if sj.find(si)+1: dup[i] = 1...
s891555390
s288526310
p00899
python
Runtime Error
while 1: n = int(input()) if n == 0: break S = [input() for i in range(n)] dup = [0]*n for i in range(n): si = S[i] for j in range(i+1, n): sj = S[j] if si.find(sj)+1: dup[j] = 1 if sj.find(si)+1: dup[i] = 1...
while 1: n = int(input()) if n == 0: break S = [input() for i in range(n)] dup = [0]*n for i in range(n): si = S[i] for j in range(i+1, n): sj = S[j] if si.find(sj)+1: dup[j] = 1 if sj.find(si)+1: dup[i] = 1...
s174941496
s288526310
p00899
python
Runtime Error
def root(x): if x == parent[x]: return x y = root(parent[x]) relative[x] += relative[parent[x]] parent[x] = y return y def unite(a, b, w): pa = root(a); pb = root(b) if pa < pb: parent[pb] = pa relative[pb] = relative[a] + w else: parent[pa] = pb r...
import sys sys.setrecursionlimit(10**6) def root(x): if x == parent[x]: return x y = root(parent[x]) relative[x] += relative[parent[x]] parent[x] = y return y def unite(a, b, w): pa = root(a); pb = root(b) pw = relative[a] + w - relative[b] if pa < pb: parent[pb] = pa ...
s244230929
s832694704
p00909
python
Runtime Error
from itertools import product def dist2(x0, y0, z0, x1, y1, z1): return (x0 - x1)**2 + (y0 - y1)**2 + (z0 - z1)**2 def dot(x0, y0, z0, x1, y1, z1): return x0*x1 + y0*y1 + z0*z1 def cross2(x0, y0, z0, x1, y1, z1): return (y0*z1 - y1*z0)**2 + (z0*x1 - z1*x0)**2 + (x0*y1 - x1*y0)**2 while 1: N, M, R = ma...
from itertools import product from sys import stdin, stdout readline = stdin.readline write = stdout.write def dist2(x0, y0, z0, x1, y1, z1): return (x0 - x1)**2 + (y0 - y1)**2 + (z0 - z1)**2 def dot(x0, y0, z0, x1, y1, z1): return x0*x1 + y0*y1 + z0*z1 def cross2(x0, y0, z0, x1, y1, z1): return (y0*z1 - ...
s602470618
s913619405
p00910
python
Runtime Error
from itertools import product def dist2(x0, y0, z0, x1, y1, z1): return (x0 - x1)**2 + (y0 - y1)**2 + (z0 - z1)**2 def dot(x0, y0, z0, x1, y1, z1): return x0*x1 + y0*y1 + z0*z1 def cross2(x0, y0, z0, x1, y1, z1): return (y0*z1 - y1*z0)**2 + (z0*x1 - z1*x0)**2 + (x0*y1 - x1*y0)**2 while 1: N, M, R = ma...
from itertools import product from sys import stdin, stdout readline = stdin.readline write = stdout.write def dist2(x0, y0, z0, x1, y1, z1): return (x0 - x1)**2 + (y0 - y1)**2 + (z0 - z1)**2 def dot(x0, y0, z0, x1, y1, z1): return x0*x1 + y0*y1 + z0*z1 def cross2(x0, y0, z0, x1, y1, z1): return (y0*z1 - ...
s686576203
s913619405
p00910
python
Runtime Error
from itertools import product from sys import stdin, stdout readline = stdin.readline write = stdout.write def dist2(x0, y0, z0, x1, y1, z1): return (x0 - x1)**2 + (y0 - y1)**2 + (z0 - z1)**2 def dot(x0, y0, z0, x1, y1, z1): return x0*x1 + y0*y1 + z0*z1 def cross2(x0, y0, z0, x1, y1, z1): return (y0*z1 - ...
from itertools import product from sys import stdin, stdout readline = stdin.readline write = stdout.write def dist2(x0, y0, z0, x1, y1, z1): return (x0 - x1)**2 + (y0 - y1)**2 + (z0 - z1)**2 def dot(x0, y0, z0, x1, y1, z1): return x0*x1 + y0*y1 + z0*z1 def cross2(x0, y0, z0, x1, y1, z1): return (y0*z1 - ...
s757246880
s913619405
p00910
python
Runtime Error
n = int(input()) M = 10**9 rest = 2**M for i in range(n): x = int(input()) if x >= M: x = M val = 2**(M - x) if val <= rest: print("Yes") rest -= val else: print("No")
n = int(input()) bits = set() c1 = 0 count = 0 ans = [] for i in range(n): x = int(input()) if x in bits: y = x while c1 < y and y in bits: y -= 1 if y <= c1: y = 0 if y == 0 and count != x: c1 = max(x, c1) ans.append("No") ...
s318801965
s374577288
p00952
python
Time Limit Exceeded
n = int(input()) bits = {0: 1} for i in range(n): x = int(input()) if bits.get(x, 0) == 1: bits[x] = 0 print("Yes") else: y = x while y >= 0 and bits.get(y, 0) == 0: y -= 1 if y < 0: print("No") else: bits[y] = 0 ...
n = int(input()) bits = set() c1 = 0 count = 0 ans = [] for i in range(n): x = int(input()) if x in bits: y = x while c1 < y and y in bits: y -= 1 if y <= c1: y = 0 if y == 0 and count != x: c1 = max(x, c1) ans.append("No") ...
s895322328
s374577288
p00952
python
Time Limit Exceeded
n = int(input()) bits = {} count = 0 for i in range(n): x = int(input()) if bits.get(0, 0) == 1: print("No") continue if bits.get(x, 0) == 1: y = x while bits.get(y, 0) == 1: y -= 1 if y == 0 and count != x: print("No") else: ...
n = int(input()) bits = set() c1 = 0 count = 0 ans = [] for i in range(n): x = int(input()) if x in bits: y = x while c1 < y and y in bits: y -= 1 if y <= c1: y = 0 if y == 0 and count != x: c1 = max(x, c1) ans.append("No") ...
s669169017
s374577288
p00952
python
Time Limit Exceeded
n = int(input()) bits = set() count = 0 ans = [] for i in range(n): x = int(input()) if x in bits: y = x while y in bits: y -= 1 if y == 0 and count != x: ans.append("No") else: bits.add(y) if y == 0: ans.append("Yes...
n = int(input()) bits = set() c1 = 0 count = 0 ans = [] for i in range(n): x = int(input()) if x in bits: y = x while c1 < y and y in bits: y -= 1 if y <= c1: y = 0 if y == 0 and count != x: c1 = max(x, c1) ans.append("No") ...
s140251498
s374577288
p00952
python
Time Limit Exceeded
from heapq import heappush, heappop from collections import deque import sys sys.setrecursionlimit(10**6) n, m = map(int, input().split()) E = [] G = [[] for i in range(n)] RG = [[] for i in range(n)] for i in range(m): a, b, c = map(int, input().split()) E.append((a-1, b-1, c)) G[a-1].append((b-1, c, i)) ...
from heapq import heappush, heappop from collections import deque import sys sys.setrecursionlimit(10**6) n, m = map(int, input().split()) E = [] G = [[] for i in range(n)] RG = [[] for i in range(n)] for i in range(m): a, b, c = map(int, input().split()) E.append((a-1, b-1, c)) G[a-1].append((b-1, c, i)) ...
s066754776
s760657061
p00962
python
Runtime Error
from heapq import heappush, heappop from collections import deque import sys sys.setrecursionlimit(10**6) n, m = map(int, input().split()) E = [] G = [[] for i in range(n)] RG = [[] for i in range(n)] for i in range(m): a, b, c = map(int, input().split()) E.append((a-1, b-1, c)) G[a-1].append((b-1, c, i)) ...
from heapq import heappush, heappop from collections import deque import sys sys.setrecursionlimit(10**6) n, m = map(int, input().split()) E = [] G = [[] for i in range(n)] RG = [[] for i in range(n)] for i in range(m): a, b, c = map(int, input().split()) E.append((a-1, b-1, c)) G[a-1].append((b-1, c, i)) ...
s758569233
s760657061
p00962
python
Runtime Error
from heapq import heappush, heappop from collections import deque import sys sys.setrecursionlimit(10**6) n, m = map(int, input().split()) E = [] G = [[] for i in range(n)] RG = [[] for i in range(n)] for i in range(m): a, b, c = map(int, input().split()) E.append((a-1, b-1, c)) G[a-1].append((b-1, c, i)) ...
from heapq import heappush, heappop from collections import deque import sys sys.setrecursionlimit(10**6) n, m = map(int, input().split()) E = [] G = [[] for i in range(n)] RG = [[] for i in range(n)] for i in range(m): a, b, c = map(int, input().split()) E.append((a-1, b-1, c)) G[a-1].append((b-1, c, i)) ...
s298480504
s760657061
p00962
python
Runtime Error
from heapq import heappush, heappop from collections import deque import sys sys.setrecursionlimit(5*10**5) n, m = map(int, input().split()) E = [] G = [[] for i in range(n)] RG = [[] for i in range(n)] for i in range(m): while 1: try: a, b, c = map(int, input().split()) break ...
from heapq import heappush, heappop from collections import deque import sys sys.setrecursionlimit(10**6) n, m = map(int, input().split()) E = [] G = [[] for i in range(n)] RG = [[] for i in range(n)] for i in range(m): a, b, c = map(int, input().split()) E.append((a-1, b-1, c)) G[a-1].append((b-1, c, i)) ...
s732088672
s760657061
p00962
python
Runtime Error
from heapq import heappush, heappop from collections import deque import sys sys.setrecursionlimit(10**6) *ipts, = map(int, open(0).read().split()) n, m = ipts[:2] #n, m = map(int, input().split()) E = [] G = [[] for i in range(n)] RG = [[] for i in range(n)] for i in range(m): #a, b, c = map(int, input().split()) ...
from heapq import heappush, heappop from collections import deque import sys sys.setrecursionlimit(10**6) n, m = map(int, input().split()) E = [] G = [[] for i in range(n)] RG = [[] for i in range(n)] for i in range(m): a, b, c = map(int, input().split()) E.append((a-1, b-1, c)) G[a-1].append((b-1, c, i)) ...
s373972886
s760657061
p00962
python
Runtime Error
from bisect import bisect n, a, b, q = map(int, input().split()) W = [input().split() for i in range(a)] X = [int(x) for x, c in W] C = [c for x, c in W] P = [list(map(int, input().split())) for i in range(b)] Y = [y for y, h in P] + [n+1] D = [0]*b for i in range(b): y0, h = P[i] y1 = Y[i+1] l = y1 - y0...
from bisect import bisect n, a, b, q = map(int, input().split()) W = [input().split() for i in range(a)] X = [int(x) for x, c in W] C = [c for x, c in W] P = [list(map(int, input().split())) for i in range(b)] Y = [y for y, h in P] + [n+1] D = [0]*b for i in range(b): y0, h = P[i]; y1 = Y[i+1] D[i] = min(y0 ...
s555058570
s996341069
p00966
python
Runtime Error
while 1: n = input() if n == 0: break s = raw_input() lock = 0 P = set() for c in s: if c is 'u': lock = 0 else: P.add((lock, 1 << int(c))) lock |= 1 << int(c) while 1: Q = set() for lock1, c1 in P: for l...
while 1: n = input() if n == 0: break s = raw_input() Q = set() lock = 0 P = [] for c in s: if c is 'u': lock = 0 else: v = (lock, 1 << int(c)) if v not in Q: P.append(v) Q.add(v) lock |= ...
s620419307
s125629630
p01089
python
Runtime Error
while 1: n = input() if n == 0: break s = raw_input() lock = 0 P = set() for c in s: if c is 'u': lock = 0 else: P.add((lock, 1 << int(c))) lock |= 1 << int(c) while 1: Q = set() for lock1, c1 in P: for l...
while 1: n = input() if n == 0: break s = raw_input() Q = set() lock = 0 P = [] for c in s: if c is 'u': lock = 0 else: v = (lock, 1 << int(c)) if v not in Q: P.append(v) Q.add(v) lock |= ...
s125765327
s125629630
p01089
python
Runtime Error
while 1: n = input() if n == 0: break s = raw_input() lock = 0 P = [] for c in s: if c is 'u': lock = 0 else: P.append((lock, 1 << int(c))) lock |= 1 << int(c) Q = set() i = 0 while i < len(P): lock1, t1 = P[i] ...
while 1: n = input() if n == 0: break s = raw_input() Q = set() lock = 0 P = [] for c in s: if c is 'u': lock = 0 else: v = (lock, 1 << int(c)) if v not in Q: P.append(v) Q.add(v) lock |= ...
s860278814
s125629630
p01089
python
Runtime Error
while 1: n = input() if n == 0: break s = raw_input() lock = 0 P = [] for c in s: if c is 'u': lock = 0 else: P.append((lock, 1 << int(c))) lock |= 1 << int(c) Q = set() i = 0; ok = 1 while i < len(P) and ok: lock1, ...
while 1: n = input() if n == 0: break s = raw_input() Q = set() lock = 0 P = [] for c in s: if c is 'u': lock = 0 else: v = (lock, 1 << int(c)) if v not in Q: P.append(v) Q.add(v) lock |= ...
s797200585
s125629630
p01089
python
Runtime Error
while 1: n = input() if n == 0: break s = raw_input() Q = set() lock = 0 P = [] for c in s: if c is 'u': lock = 0 else: v = (lock, 1 << int(c)) P.append(v) Q.add(v) lock |= 1 << int(c) i = 0; ok = 1 w...
while 1: n = input() if n == 0: break s = raw_input() Q = set() lock = 0 P = [] for c in s: if c is 'u': lock = 0 else: v = (lock, 1 << int(c)) if v not in Q: P.append(v) Q.add(v) lock |= ...
s895497682
s125629630
p01089
python
Runtime Error
while 1: m, n = map(int, raw_input().split()) if m == 0: break MAX = 10**7 p= [0]*(MAX+1) i = m cnt = 0 while 1: if not p[i]: if cnt == n: break for j in xrange(i, MAX, i): p[j] = 1 cnt += 1 i += 1 ...
import math MAX = 7400000 prime = [1]*MAX prime[0] = prime[1] = 0 res = [] sq = int(math.sqrt(MAX)) for i in xrange(2, sq+1): q = len(res) if prime[i]: res.append(i) for j in xrange(i*i, MAX, i): prime[j] = 0 prime[i] = q for i in xrange(sq+1, MAX): q = len(res) if prime[...
s216514586
s922302900
p01095
python
Runtime Error
MAX = 10**7 p = [0]*(MAX+1) t = 1 while 1: m, n = map(int, raw_input().split()) if m == 0: break i = m cnt = 0 while 1: if p[i] != t: if cnt == n: break for j in xrange(i, MAX, i): p[j] = t cnt += 1 i += 1 ...
import math MAX = 7400000 prime = [1]*MAX prime[0] = prime[1] = 0 res = [] sq = int(math.sqrt(MAX)) for i in xrange(2, sq+1): q = len(res) if prime[i]: res.append(i) for j in xrange(i*i, MAX, i): prime[j] = 0 prime[i] = q for i in xrange(sq+1, MAX): q = len(res) if prime[...
s622334924
s922302900
p01095
python
Runtime Error
import math MAX = 7400000 prime = [1]*MAX prime[0] = prime[1] = 0 res = [] sq = int(math.sqrt(MAX)) for i in xrange(2, sq+1): q = len(res) if prime[i]: res.append(i) for j in xrange(i*i, MAX, i): prime[j] = 0 prime[i] = q for i in xrange(sq+1, MAX): q = len(res) if prime[...
import math MAX = 7400000 prime = [1]*MAX prime[0] = prime[1] = 0 res = [] sq = int(math.sqrt(MAX)) for i in xrange(2, sq+1): q = len(res) if prime[i]: res.append(i) for j in xrange(i*i, MAX, i): prime[j] = 0 prime[i] = q for i in xrange(sq+1, MAX): q = len(res) if prime[...
s402507140
s922302900
p01095
python
Runtime Error
MAX = 10**7 p = [0]*(MAX+1) t = 1 while 1: m, n = map(int, raw_input().split()) if m == 0: break i = m cnt = 0 while 1: if p[i] != t: if cnt == n: break j = i while j < MAX: p[j] = t j += i ...
import math MAX = 7400000 prime = [1]*MAX prime[0] = prime[1] = 0 res = [] sq = int(math.sqrt(MAX)) for i in xrange(2, sq+1): q = len(res) if prime[i]: res.append(i) for j in xrange(i*i, MAX, i): prime[j] = 0 prime[i] = q for i in xrange(sq+1, MAX): q = len(res) if prime[...
s304227547
s922302900
p01095
python
Runtime Error
from collections import deque while 1: n, k, s = map(int, raw_input().split()) if n==0: break ps = [map(int, raw_input().split()) for i in xrange(n)] G = [[] for i in xrange(n)] for i in xrange(n): xi, yi, zi = ps[i] for j in xrange(i, n): if i==j: continue ...
from collections import deque while 1: n, k, s = map(int, raw_input().split()) if n==0:break ps = [map(int, raw_input().split()) for i in xrange(n)] G = [[] for i in xrange(n)] for i in xrange(n): xi, yi, zi = ps[i] for j in xrange(i+1, n): if i==j: continue ...
s987518138
s432359336
p01097
python
Runtime Error
from collections import deque def ipt(): while 1: try: return raw_input() except:pass while 1: n, k, s = map(int, ipt().split()) if n==0:break ps = [map(int, ipt().split()) for i in xrange(n)] G = [[] for i in xrange(n)] for i in xrange(n): xi, yi, zi = ps[i]...
from collections import deque while 1: n, k, s = map(int, raw_input().split()) if n==0:break ps = [map(int, raw_input().split()) for i in xrange(n)] G = [[] for i in xrange(n)] for i in xrange(n): xi, yi, zi = ps[i] for j in xrange(i+1, n): if i==j: continue ...
s547854722
s432359336
p01097
python
Runtime Error
from collections import deque while 1: n, k, s = map(int, raw_input().split()) if n==0:break ps = [map(int, raw_input().split()) for i in xrange(n)] G = [[] for i in xrange(n)] for i in xrange(n): xi, yi, zi = ps[i] for j in xrange(i+1, n): if i==j: continue ...
from collections import deque while 1: n, k, s = map(int, raw_input().split()) if n==0:break ps = [map(int, raw_input().split()) for i in xrange(n)] G = [[] for i in xrange(n)] for i in xrange(n): xi, yi, zi = ps[i] for j in xrange(i+1, n): if i==j: continue ...
s194927511
s432359336
p01097
python
Runtime Error
while 1: s1 = input().split('"') if s1 is '.': break s2 = input().split('"') if len(s1) != len(s2): print("DIFFERENT") continue r = [0]*2 for i in range(len(s1)): if s1[i] != s2[i]: r[i%2] += 1 if [0,1]<r: print("DIFFERENT") else: ...
while 1: s1 = input().split('"') if s1 == ['.']: break s2 = input().split('"') if len(s1) != len(s2): print("DIFFERENT") continue r = [0]*2 for i in range(len(s1)): if s1[i] != s2[i]: r[i%2] += 1 if [0,1]<r: print("DIFFERENT") else: ...
s447634745
s099779448
p01102
python
Runtime Error
while 1: d, w = map(int, input().split()) if d == w == 0: break E = [[*map(int, input().split())] for i in range(d)] ans = 0 for x2 in range(d): for y2 in range(w): for x1 in range(x2-1): for y1 in range(y2-1): # [x1, x2] x [y1, y2] ...
while 1: d, w = map(int, input().split()) if d == w == 0: break E = [list(map(int, input().split())) for i in range(d)] ans = 0 for x2 in range(d): for y2 in range(w): for x1 in range(x2-1): for y1 in range(y2-1): co = 10**18 ...
s464685599
s783877154
p01103
python
Runtime Error
while 1: d, w = map(int, input().split()) if d == w == 0: break E = [[*map(int, input().split())] for i in range(d)] ans = 0 for x2 in range(d): for y2 in range(w): for x1 in range(x2-1): for y1 in range(y2-1): co = 10**18 ...
while 1: d, w = map(int, input().split()) if d == w == 0: break E = [list(map(int, input().split())) for i in range(d)] ans = 0 for x2 in range(d): for y2 in range(w): for x1 in range(x2-1): for y1 in range(y2-1): co = 10**18 ...
s281140338
s783877154
p01103
python
Runtime Error
while 1: n, m = map(int, input().split()) if n+m == 0: break B = [int(input(),2) for i in range(n)] C = {0: 0} for b in B: for k, v in [*C.items()]: C[k^b] = max(C.get(k^b, 0), v+1) print(C[0])
def make(n): C = {0: 0} for i in range(n): b = int(input(), 2) for k, v in dict(C).items(): if C.get(k^b, 0) < v+1: C[k^b] = v+1 return C def calc(P, Q): yield 0 for k, v in P.items(): if k in Q: yield v + Q[k] def solve(): while 1:...
s536396611
s817026702
p01104
python
Runtime Error
a=65280; b=61680; c=52428; d=43690; e=65535 QS = [[] for i in range(17)] QS[1] = [a, b, c, d] L = {a: 1, b: 1, c: 1, d: 1, e: 1, e: 1, 0: 1} H = [] get = L.get push = H.append for l in range(1, 16): Q = QS[l] li = 13-l; l3 = l+3; l1 = l+1 pop = Q.pop pushQN = QS[l1].append while Q: p = pop()...
def make(n): C = {0: 0} for i in range(n): b = int(input(), 2) for k, v in dict(C).items(): if C.get(k^b, 0) < v+1: C[k^b] = v+1 return C def calc(P, Q): yield 0 for k, v in P.items(): if k in Q: yield v + Q[k] def solve(): while 1:...
s548409619
s817026702
p01104
python
Runtime Error
a=65280; b=61680; c=52428; d=43690; e=65535 QS = [[] for i in range(17)] QS[1] = [a, b, c, d] L = {a: 1, b: 1, c: 1, d: 1, e: 1, e: 1, 0: 1} H = [] get = L.get push = H.append for l in range(1, 16): Q = QS[l] li = 13-l; l3 = l+3; l1 = l+1 pop = Q.pop pushQN = QS[l1].append while Q: p = pop()...
def make(n): C = {0: 0} for i in range(n): b = int(input(), 2) for k, v in dict(C).items(): if C.get(k^b, 0) < v+1: C[k^b] = v+1 return C def calc(P, Q): yield 0 for k, v in P.items(): if k in Q: yield v + Q[k] def solve(): while 1:...
s397475554
s817026702
p01104
python
Runtime Error
from itertools import permutations for t in xrange(input()): h, w = map(int, raw_input().split()) A = [list(raw_input()) for i in xrange(h)] xmin = {}; xmax = {} ymin = {}; ymax = {} obj = set() for i in xrange(h): for j in xrange(w): c = A[i][j] if c == '.': cont...
for t in xrange(input()): h, w = map(int, raw_input().split()) A = [list(raw_input()) for i in xrange(h)] xmin = {}; xmax = {} ymin = {}; ymax = {} obj = set() for i in xrange(h): for j in xrange(w): c = A[i][j] if c == '.': continue xmin[c] = min(xmin...
s785718782
s187725190
p01127
python
Runtime Error
from heapq import heappush, heappop while 1: N, M, L, K, A, H = map(int, raw_input().split()) if N == 0: break F = [0]*N if L>0: for e in map(int, raw_input().split()): F[e] = 1 G = [[] for i in xrange(N)] for i in xrange(K): x, y, t = map(int, raw_input().spl...
from heapq import heappush, heappop while 1: N, M, L, K, A, H = map(int, raw_input().split()) if N == 0: break F = [0]*N for e in map(int, raw_input().split()): F[e] = 1 G = [[] for i in xrange(N)] for i in xrange(K): x, y, t = map(int, raw_input().split()) G[x].a...
s930244563
s893406053
p01146
python
Runtime Error
import Queue n = input() p = [] for i in xrange(n): p.append(int(raw_input())) dist = [10**7] * n mark = [0]*n que = Queue.PriorityQueue() que.put((0, 0)) dist[0] = 0 idx = 0 while not que.empty(): co, v = que.get() if dist[v] < co: continue for k in xrange(1, 7): idx += 1 go = v...
import Queue INF = 10**9 n = input() p = [i+int(raw_input()) for i in xrange(n)] used = [0] * n idx = 0 for i in xrange(n): if p[i]!=i: path = [] go = i idx += 1 while go!=INF and p[go]!=go: if used[go]==idx: go = INF break use...
s966996933
s352710530
p01449
python
Runtime Error
import Queue INF = 10**9+7 n = input() p = [] for i in xrange(n): p.append(int(raw_input())) dist = [10**7] * n calc = [-1] * n used = [False] * n que = Queue.PriorityQueue() que.put((0, 0)) dist[0] = 0 def dfs(pos, calc, used, f): if p[pos]==0: return pos if calc[pos]!=-1: return calc[pos] ...
import Queue INF = 10**9 n = input() p = [i+int(raw_input()) for i in xrange(n)] used = [0] * n idx = 0 for i in xrange(n): if p[i]!=i: path = [] go = i idx += 1 while go!=INF and p[go]!=go: if used[go]==idx: go = INF break use...
s219191321
s352710530
p01449
python
Runtime Error
import Queue, sys INF = 10**9+7 n = input() p = [] for i in xrange(n): p.append(int(raw_input())) dist = [10**7] * n calc = [-1] * n used = [False] * n que = Queue.PriorityQueue() que.put((0, 0)) dist[0] = 0 sys.setrecursionlimit(10**5+7) def dfs(pos, calc, used, f): if p[pos]==0: return pos if calc...
import Queue INF = 10**9 n = input() p = [i+int(raw_input()) for i in xrange(n)] used = [0] * n idx = 0 for i in xrange(n): if p[i]!=i: path = [] go = i idx += 1 while go!=INF and p[go]!=go: if used[go]==idx: go = INF break use...
s734310997
s352710530
p01449
python
Runtime Error
ef suber(c, k): if ord('a')<=ord(c): w = ord(c) - ord('a') if w < k: return chr(ord('Z') - (k - w - 1)) if k<=26 else chr(ord('z') - (k - w - 27)) return chr(ord('a') + (w - k)) else: w = ord(c) - ord('A') if w < k: return chr(ord('z') - (k - w - 1...
station = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" while True: n = input() if n==0: break k = map(int, raw_input().split()) s = raw_input() print "".join(station[(station.find(s[i])-k[i%n]+52)%52] for i in xrange(len(s)))
s599505675
s500048323
p01620
python
Runtime Error
station = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQESTUVWXYZ" while True: n = input() if n==0: break k = map(int, raw_input().split()) s = raw_input() print "".join(station[station.find(s[i])-k[i%n]] for i in xrange(len(s)))
station = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" while True: n = input() if n==0: break k = map(int, raw_input().split()) s = raw_input() print "".join(station[(station.find(s[i])-k[i%n]+52)%52] for i in xrange(len(s)))
s841971067
s500048323
p01620
python
Runtime Error
while 1: n = int(input()) S = [] for i in range(n): s = input() b = [] for j in range(len(s)): if j < 1 or s[j-1] in "aiueo": b.append(s[j]) S.append(b) ans = 0 S.sort() for i in range(n-1): A = S[i]; B = S[i+1] if A == ...
while 1: n = int(input()) if n == 0: break S = [] for i in range(n): s = input() b = [] for j in range(len(s)): if j < 1 or s[j-1] in "aiueo": b.append(s[j]) S.append(b) ans = 0 S.sort() for i in range(n-1): A = S[i]...
s582083298
s024713452
p01803
python
Runtime Error
s = raw_input() used = set() def dfs(s): if s in used: return 0 if s == "ABC": return 1 if "ABC" in s: for c in "ABC": if dfs(s.replace("ABC", c)): return 1 used.add(s) return 0 print dfs(s)*"Yes"or"No"
s = raw_input() p = "ABC" used = set() while s != p: idx = 0 c = [0]*3 while idx < len(s): if idx+3 <= len(s) and s[idx:idx+3] == p: idx += 3 else: c[p.index(s[idx])] += 1 idx += 1 if sum(e == 0 for e in c) != 1 or sum(c) == len(s): print "No"...
s473799107
s151567412
p01811
python
Runtime Error
import sys s = raw_input() used = set() sys.setrecursionlimit(len(s)) def dfs(s): if s in used: return 0 if s == "ABC": return 1 if "ABC" in s: for c in "ABC": if dfs(s.replace("ABC", c)): return 1 used.add(s) return 0 print dfs(s)*"Yes"or"No"
s = raw_input() p = "ABC" used = set() while s != p: idx = 0 c = [0]*3 while idx < len(s): if idx+3 <= len(s) and s[idx:idx+3] == p: idx += 3 else: c[p.index(s[idx])] += 1 idx += 1 if sum(e == 0 for e in c) != 1 or sum(c) == len(s): print "No"...
s789987457
s151567412
p01811
python
Runtime Error
s = raw_input() p = "ABC" used = set() while s != p: idx = 0 c = [0]*3 while idx < len(s): if idx+3 <= len(s) and s[idx:idx+3] == p: idx += 3 else: c[p.index(s[idx])] += 1 idx += 1 if sum(e == 0 for e in c) != 1 or sum(c) == s: print "No" ...
s = raw_input() p = "ABC" used = set() while s != p: idx = 0 c = [0]*3 while idx < len(s): if idx+3 <= len(s) and s[idx:idx+3] == p: idx += 3 else: c[p.index(s[idx])] += 1 idx += 1 if sum(e == 0 for e in c) != 1 or sum(c) == len(s): print "No"...
s231896556
s151567412
p01811
python
Time Limit Exceeded
def convert(S): return eval(S.replace(")[","),[").replace("](","],(")) def dfs(A, B): if not A or not B: return () return (dfs(A[0], B[0]), [A[1][0] + B[1][0]], dfs(A[2], B[2])) print(str(dfs(convert(input()), convert(input()))).replace(", ","")[1:-1])
def convert(S): cur = 0 def parse(): nonlocal cur if S[cur] == ')': return () cur += 1 # '(' left = parse() cur += 2 # ')[' num = 0 while S[cur] != ']': num = 10*num + int(S[cur]) cur += 1 cur += 2 # '](' ...
s877776677
s112573259
p01841
python
Runtime Error
while 1: n, m = map(int, input().split()) if n == m == 0: break *S, = map(int, input().split()) *D, = map(int, input().split()) from itertools import permutations ans = 10**18 for P in permutations(S): Q = [0]*(n+1) for i, e in enumerate(P): Q[i+1] = P[i]...
from collections import deque while 1: n, m = map(int, input().split()) if n == m == 0: break *S, = map(int, input().split()) D = sorted(map(int, input().split())) SA = sum(S) rest = sum(d-SA for d in D if SA <= d) memo = {2**n-1: rest} def dfs(state, su, idx): if state...
s142128738
s082448795
p01849
python
Runtime Error
from itertools import permutations while 1: n, m = map(int, input().split()) if n == m == 0: break *S, = map(int, input().split()) *D, = map(int, input().split()) def solve(S, D): for P in permutations(S): Q = [0]*(n+1) for i, e in enumerate(P): ...
from collections import deque while 1: n, m = map(int, input().split()) if n == m == 0: break *S, = map(int, input().split()) D = sorted(map(int, input().split())) SA = sum(S) rest = sum(d-SA for d in D if SA <= d) memo = {2**n-1: rest} def dfs(state, su, idx): if state...
s224449488
s082448795
p01849
python
Runtime Error
from itertools import permutations while 1: n, m = map(int, input().split()) if n == m == 0: break *S, = map(int, input().split()) *D, = map(int, input().split()) def solve(S, D): Q = [0]*(n+1) for P in permutations(S): for i, e in enumerate(P): Q...
from collections import deque while 1: n, m = map(int, input().split()) if n == m == 0: break *S, = map(int, input().split()) D = sorted(map(int, input().split())) SA = sum(S) rest = sum(d-SA for d in D if SA <= d) memo = {2**n-1: rest} def dfs(state, su, idx): if state...
s872771974
s082448795
p01849
python
Runtime Error
from collections import deque while 1: n, m = map(int, input().split()) if n == m == 0: break *S, = map(int, input().split()) *D, = map(int, input().split()) deq = deque(S) D.sort() def dfs(r, idx, prev): if idx == m: return 0 if r == n: s = 0...
from collections import deque while 1: n, m = map(int, input().split()) if n == m == 0: break *S, = map(int, input().split()) D = sorted(map(int, input().split())) SA = sum(S) rest = sum(d-SA for d in D if SA <= d) memo = {2**n-1: rest} def dfs(state, su, idx): if state...
s221362866
s082448795
p01849
python
Runtime Error
while 1: t, d, l = map(int, raw_input().split()) rest = ans = 0 for i in xrange(t): x = int(raw_input()) if l <= x: rest = d elif rest: rest -= 1 if rest and i < t-1: ans += 1 print ans
while 1: t, d, l = map(int, raw_input().split()) if t == d == l == 0: break rest = ans = 0 for i in xrange(t): x = int(raw_input()) if l <= x: rest = d elif rest: rest -= 1 if rest and i < t-1: ans += 1 print ans
s942703166
s375160860
p01924
python
Runtime Error
while 1: n, m = map(int, raw_input().split()) if n == m == 0: break S = map(int, raw_input().split()) left = -1; right = max(S)+2 def check(mid): if 1+mid <= S[0]: return 10**9 cnt = 0; l = 1 target = S[n-1] - mid for i in xrange(n-1): ...
while 1: n, m = map(int, raw_input().split()) if n == m == 0: break S = map(int, raw_input().split()) left = 0; right = sum(S)+2 def check(mid): if 1+mid <= S[0]: return 10**9 cnt = 0; l = 1 target = S[n-1] - mid for i in xrange(n-1): w...
s731971799
s711887137
p01926
python
Runtime Error
while 1: n, m = map(int, raw_input().split()) if n == m == 0: break S = map(int, raw_input().split()) left = -1; right = max(S)+2 def check(mid): if 1+mid <= S[0]: return 10**9 cnt = 0; l = 1 target = S[n-1] - mid for i in xrange(n-1): ...
while 1: n, m = map(int, raw_input().split()) if n == m == 0: break S = map(int, raw_input().split()) left = 0; right = sum(S)+2 def check(mid): if 1+mid <= S[0]: return 10**9 cnt = 0; l = 1 target = S[n-1] - mid for i in xrange(n-1): w...
s239291964
s711887137
p01926
python
Runtime Error
N, C = map(int, input().split()) events = [] for i in range(N): events.append(list(map(int, input().split()))) dp = [[0]*201 for i in range(C+1)] for j in range(C+1): for k in range(-1000, 1001): if k != 0: dp[j][k] = -10**18 for a, b, c in events: for j in range(C-c, -1, -1): f...
N, C = map(int, input().split()) events = [] for i in range(N): events.append(list(map(int, input().split()))) def solve(): L = 250 dp = [[-10**18]*(L+1) for i in range(C+1)] for j in range(C+1): dp[j][0] = 0 for a, b, c in events: for j in range(C-c, -1, -1): for k in r...
s162004671
s757387088
p01941
python
Runtime Error
N, C = map(int, input().split()) events = [] for i in range(N): events.append(list(map(int, input().split()))) dp = [[0]*2001 for i in range(C+1)] for j in range(C+1): for k in range(-1000, 1001): if k != 0: dp[j][k] = -10**18 for a, b, c in events: for j in range(C-c, -1, -1): ...
N, C = map(int, input().split()) events = [] for i in range(N): events.append(list(map(int, input().split()))) def solve(): L = 250 dp = [[-10**18]*(L+1) for i in range(C+1)] for j in range(C+1): dp[j][0] = 0 for a, b, c in events: for j in range(C-c, -1, -1): for k in r...
s103981058
s757387088
p01941
python
Time Limit Exceeded
from heapq import heappush, heappop H, W, T, Q = map(int, input().split()) que = [] state = [[0]*W for i in range(H)] data1 = [[0]*(W+1) for i in range(H+1)] data2 = [[0]*(W+1) for i in range(H+1)] def get(data, h, w): s = 0 while h: w0 = w el = data[h] while w0: s += el[w0] ...
from heapq import heappush, heappop H, W, T, Q = map(int, input().split()) que = [] state = [[0]*(W+1) for i in range(H+1)] data1 = [[0]*(W+1) for i in range(H+1)] data2 = [[0]*(W+1) for i in range(H+1)] def get(data, h, w): s = 0 while h: w0 = w el = data[h] while w0: s += e...
s993411339
s170591144
p01942
python
Runtime Error
import random, math random.seed() def gen(a, b, num): result = set() while 1: while 1: v = random.randint(a, b)//2*2+1 if v not in result: break for x in range(3, int(math.sqrt(v))+1, 2): if v % x == 0: break else: ...
import sys readline = sys.stdin.readline write = sys.stdout.write class KMP: def __init__(self, W): L = len(W) T = [0] * (L+1) T[0] = -1 c = 0 for p in range(1, L): if W[p] == W[c]: T[p] = T[c] else: T[p] = c ...
s624674862
s371494300
p02248
python
Time Limit Exceeded
import random, math random.seed() def gen(a, b, num): result = set() while 1: while 1: v = random.randint(a, b)//2*2+1 if v not in result: break for x in range(3, int(math.sqrt(v))+1, 2): if v % x == 0: break else: ...
import sys readline = sys.stdin.readline write = sys.stdout.write class KMP: def __init__(self, W): L = len(W) T = [0] * (L+1) T[0] = -1 c = 0 for p in range(1, L): if W[p] == W[c]: T[p] = T[c] else: T[p] = c ...
s881110733
s371494300
p02248
python
Time Limit Exceeded
import random, math random.seed() def gen(a, b, num): result = set() while 1: while 1: v = random.randint(a, b)//2*2+1 if v not in result: break for x in range(3, int(math.sqrt(v))+1, 2): if v % x == 0: break else: ...
import sys readline = sys.stdin.readline write = sys.stdout.write class KMP: def __init__(self, W): L = len(W) T = [0] * (L+1) T[0] = -1 c = 0 for p in range(1, L): if W[p] == W[c]: T[p] = T[c] else: T[p] = c ...
s033824595
s371494300
p02248
python
Time Limit Exceeded
def insertionSort(A, n, g): global cnt for i in range(g, n): v = A[i] j = i - g while j >= 0 and A[j] > v: A[j+g] = A[j] j = j - g cnt += 1 A[j+g] = v n = int(input()) A = [int(input()) for i in range(n)] cnt = 0 G = [] for i in range(100): ...
def insertionSort(A, n, g): global cnt for i in range(g, n): v = A[i] j = i - g while j >= 0 and A[j] > v: A[j+g] = A[j] j = j - g cnt += 1 A[j+g] = v n = int(input()) A = [int(input()) for i in range(n)] cnt = 0 G = [1] for i in range(99): ...
s422935898
s691120592
p02262
python
Time Limit Exceeded
from collections import deque n = int(input()) deq = deque() sub_deq = {} for i in range(n): cmd = input() if cmd == 'deleteFirst': while deq: data = deq.popleft() if data[1]: data[1] = 0 break elif cmd == 'deleteLast': while deq: ...
from collections import deque import sys n = int(input()) deq = deque() sub_deq = {} for cmd in sys.stdin.readlines(): if cmd == 'deleteFirst\n': while deq: data = deq.pop() if data[1]: data[1] = 0 break elif cmd == 'deleteLast\n': while de...
s283493166
s402903642
p02265
python
Time Limit Exceeded
from collections import deque n = int(input()) deq = deque() sub_deq = {} for i in range(n): cmd = input() if cmd == 'deleteFirst': while 1: data = deq.pop() if data[1]: data[1] = 0 break elif cmd == 'deleteLast': while 1: d...
from collections import deque import sys n = int(input()) deq = deque() sub_deq = {} for cmd in sys.stdin.readlines(): if cmd == 'deleteFirst\n': while deq: data = deq.pop() if data[1]: data[1] = 0 break elif cmd == 'deleteLast\n': while de...
s587762377
s402903642
p02265
python
Runtime Error
from collections import deque n = int(input()) deq = deque() sub_deq = {} for i in range(n): cmd = input() if cmd == 'deleteFirst': while deq: data = deq.pop() if data[1]: data[1] = 0 break elif cmd == 'deleteLast': while deq: ...
from collections import deque import sys n = int(input()) deq = deque() sub_deq = {} for cmd in sys.stdin.readlines(): if cmd == 'deleteFirst\n': while deq: data = deq.pop() if data[1]: data[1] = 0 break elif cmd == 'deleteLast\n': while de...
s489531042
s402903642
p02265
python
Time Limit Exceeded
comp = 0 def merge(A, left, right): global comp if not left +1 < right: return [A[left]] mid = (left + right) // 2 L = merge(A, left, mid) R = merge(A, mid, right) result = [] i = j = 0 while i < len(L) and j < len(R): comp += 1 if L[i] <= R[j]: result...
comp = 0 def m(L, R): global comp j = 0 for l in L: while j < len(R) and R[j] < l: yield R[j] j += 1 yield l while j < len(R): yield R[j] j += 1 comp += len(L) + len(R) def merge(A): global comp if len(A) == 1: return A if l...
s087221597
s188498997
p02272
python
Time Limit Exceeded
comp = 0 def merge(A, left, right): global comp if not left+1 < right: return [A[left]] if left+2 == right: comp += 2 a, b = A[left:right] return (a, b) if a < b else (b, a) mid = (left + right) // 2 L = merge(A, left, mid) R = merge(A, mid, right) result = []...
comp = 0 def m(L, R): global comp j = 0 for l in L: while j < len(R) and R[j] < l: yield R[j] j += 1 yield l while j < len(R): yield R[j] j += 1 comp += len(L) + len(R) def merge(A): global comp if len(A) == 1: return A if l...
s114960629
s188498997
p02272
python
Time Limit Exceeded