s_id
stringlengths
10
10
p_id
stringlengths
6
6
u_id
stringlengths
10
10
date
stringlengths
10
10
language
stringclasses
1 value
original_language
stringclasses
11 values
filename_ext
stringclasses
1 value
status
stringclasses
1 value
cpu_time
stringlengths
1
5
memory
stringlengths
1
7
code_size
stringlengths
1
6
code
stringlengths
1
539k
s701460795
p01088
u339921062
1499237013
Python
Python
py
Runtime Error
0
0
858
while 1: n = input() if n == 0: break dp = [[None]*2001 for i in xrange(n+1)] dp[0][0] = (0, 0) for i in xrange(n): cost = int(raw_input()) dost = cost % 1000 for j in xrange(2001): if dp[i][j] is None: continue c, s = dp[i][j] dp[i+1][j] = max(dp[i][j], dp[i+1][j]) if dost == 0: if j >= 500: dp[i+1][j - 500] = max(dp[i+1][j - 500], (c+1, s-cost)) else: dp[i+1][j] = max(dp[i+1][j], (c, s-cost)) elif 1 <= dost <= 500+j: dp[i+1][j + (500 - dost)] = max(dp[i+1][j + (500 - dost)], (c+1, s-cost)) else: dp[i+1][j + (1000 - dost)] = max(dp[i+1][j + (1000 - dost)], (c, s-cost)) c, s = max(dp[n]) print c, -s
s747885339
p01088
u339921062
1499237069
Python
Python
py
Runtime Error
0
0
860
while 1: n = input() if n == 0: break dp = [[None]*10001 for i in xrange(n+1)] dp[0][0] = (0, 0) for i in xrange(n): cost = int(raw_input()) dost = cost % 1000 for j in xrange(10001): if dp[i][j] is None: continue c, s = dp[i][j] dp[i+1][j] = max(dp[i][j], dp[i+1][j]) if dost == 0: if j >= 500: dp[i+1][j - 500] = max(dp[i+1][j - 500], (c+1, s-cost)) else: dp[i+1][j] = max(dp[i+1][j], (c, s-cost)) elif 1 <= dost <= 500+j: dp[i+1][j + (500 - dost)] = max(dp[i+1][j + (500 - dost)], (c+1, s-cost)) else: dp[i+1][j + (1000 - dost)] = max(dp[i+1][j + (1000 - dost)], (c, s-cost)) c, s = max(dp[n]) print c, -s
s013891867
p01088
u339921062
1499237564
Python
Python
py
Runtime Error
40000
193872
862
while 1: n = input() if n == 0: break dp = [[None]*100001 for i in xrange(n+1)] dp[0][0] = (0, 0) for i in xrange(n): cost = int(raw_input()) dost = cost % 1000 for j in xrange(100001): if dp[i][j] is None: continue c, s = dp[i][j] dp[i+1][j] = max(dp[i][j], dp[i+1][j]) if dost == 0: if j >= 500: dp[i+1][j - 500] = max(dp[i+1][j - 500], (c+1, s-cost)) else: dp[i+1][j] = max(dp[i+1][j], (c, s-cost)) elif 1 <= dost <= 500+j: dp[i+1][j + (500 - dost)] = max(dp[i+1][j + (500 - dost)], (c+1, s-cost)) else: dp[i+1][j + (1000 - dost)] = max(dp[i+1][j + (1000 - dost)], (c, s-cost)) c, s = max(dp[n]) print c, -s
s620419307
p01089
u260980560
1499251330
Python
Python
py
Runtime Error
40000
9072
758
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 lock2, c2 in P: if lock1 & lock2 == 0 and c1 & lock2 == c1: Q.add((lock1 | lock2, c2)) if not Q - P: break P |= Q ok = 1 for lock1, c1 in P: for lock2, c2 in P: if lock1 & lock2 == 0 and c1 & lock2 == c1 and c2 & lock1 == c2: ok = 0 for lock, c in P: if lock & c == c: ok = 0 print "SAFE"*ok or "UNSAFE"
s125765327
p01089
u260980560
1499251614
Python
Python
py
Runtime Error
40000
8260
819
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 lock2, c2 in P: if lock1 & lock2 == 0 and c1 & lock2 == c1: v = (lock1 | lock2, c2) if v not in P: Q.add(v) if not Q: break P |= Q ok = 1 for lock1, c1 in P: for lock2, c2 in P: if lock1 & lock2 == 0 and c1 & lock2 == c1 and c2 & lock1 == c2: ok = 0 for lock, c in P: if lock & c == c: ok = 0 print "SAFE"*ok or "UNSAFE"
s860278814
p01089
u260980560
1499251906
Python
Python
py
Runtime Error
40000
468092
807
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] for j in xrange(i): lock2, t2 = P[j] if lock1 & lock2 == 0 and t1 & lock2 == t1: v = (lock1 | lock2, t2) if v not in Q: P.append(v) i += 1 ok = 1 for lock1, c1 in P: for lock2, c2 in P: if lock1 & lock2 == 0 and c1 & lock2 == c1 and c2 & lock1 == c2: ok = 0 for lock, c in P: if lock & c == c: ok = 0 print "SAFE"*ok or "UNSAFE"
s797200585
p01089
u260980560
1499252091
Python
Python
py
Runtime Error
40000
468200
704
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, t1 = P[i] if lock1 & t1 == t1: ok = 0 for j in xrange(i): lock2, t2 = P[j] if lock1 & lock2 == 0 and t1 & lock2 == t1: if t2 & lock1 == t2: ok = 0 v = (lock1 | lock2, t2) if v not in Q: P.append(v) i += 1 print "SAFE"*ok or "UNSAFE"
s895497682
p01089
u260980560
1499252279
Python
Python
py
Runtime Error
40000
7044
772
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 while i < len(P) and ok: lock1, t1 = P[i] if lock1 & t1 == t1: ok = 0 for j in xrange(i): lock2, t2 = P[j] if lock1 & lock2 == 0 and t1 & lock2 == t1: if t2 & lock1 == t2: ok = 0 v = (lock1 | lock2, t2) if v not in Q: P.append(v) Q.add(v) i += 1 print "SAFE"*ok or "UNSAFE"
s133907467
p01093
u777299405
1480060950
Python
Python3
py
Runtime Error
0
0
234
while True: n = int(input()) a = sorted(list(map(int, input().split()))) if n == 0: break ans = 1000 for i in range(n - 1): j = a[i + 1] - a[i] if j < ans: ans = j print(ans)
s767639648
p01093
u284260266
1526900845
Python
Python3
py
Runtime Error
0
0
236
while True: n = int(input()) if n == 0: break a = list(map(int, input().split())) l = [] for i in range(1, len(a)): for j in range(i+1,len(a)): l.append(abs(a[i]-a[j])) print(min(l))
s667027367
p01093
u284260266
1526900944
Python
Python3
py
Runtime Error
0
0
236
while True: n = int(input()) if n == 0: break a = list(map(int, input().split())) l = [] for i in range(1, len(a)): for j in range(i+1,len(a)): l.append(abs(a[i]-a[j])) print(min(l))
s213841414
p01093
u284260266
1526901170
Python
Python3
py
Runtime Error
0
0
238
while True: n = int(input()) if n == 0: break a = list(map(int, input().split())) l = [] for i in range(1, len(a)-1): for j in range(i+1,len(a)): l.append(abs(a[i]-a[j])) print(min(l))
s850642771
p01093
u284260266
1526902123
Python
Python3
py
Runtime Error
0
0
228
while True: n = int(input()) if n == 0: break a = list(map(int, input().split())) l = [] for i in range(1, n-1): for j in range(i+1,n): l.append(abs(a[i]-a[j])) print(min(l))
s526466677
p01093
u284260266
1526982829
Python
Python3
py
Runtime Error
0
0
262
while True: n = int(input()) a = list(map(int, input().split())) l = list() for i in range(1, n-1): for j in range(i+1,n): l.append(abs(a[i]-a[j])) if l = []: break if n == 0: break print(min(l))
s600872361
p01093
u951968562
1526986328
Python
Python3
py
Runtime Error
0
0
350
while True: n,m = map(int,input().split()) if n == 0 and m == 0: break a = list(map(int,input().split())) a.sort() list1 = [] for i in range(n): for j in range(i + 1, n): price1 = a[i] + a[j] list1.append(price1) list1.sort() list2 = list(filter(lambda p: m >= p, list1)) if list2: print(max(list2)) else: print("NONE")
s953547515
p01093
u284260266
1527049504
Python
Python3
py
Runtime Error
0
0
266
while True: n = int(input()) a = list(map(int, input().split())) l = list() for i in range(1, n-1): for j in range(i+1,n): l.append(abs(a[i]-a[j])) if l == []: continue if n == 0: break print(min(l))
s987877818
p01093
u284260266
1527053496
Python
Python3
py
Runtime Error
0
0
326
flg = True while flg: n = int(input()) if n == 0: flg = False a = list(map(int, input().split())) l = list() for i in range(0, n): for j in range(0,n): if i == j: continue l.append(abs(a[i]-a[j])) if l == []: continue print(min(l))
s984575841
p01095
u847467233
1531446110
Python
Python3
py
Runtime Error
0
0
302
# AOJ 1610: Bamboo Blossoms # Python3 2018.7.13 bal4u MAX = 7368792 cno = 0 tbl = [0]*MAX while True: m, n = map(int, input().split()) if m == 0: break cno += 1 for i in range(n): for j in range(m, MAX, m): tbl[j] = cno; for j in range(m, MAX): if tbl[j] != cno: break m += 1 print(m)
s205726612
p01095
u847467233
1531446292
Python
Python3
py
Runtime Error
0
0
306
# AOJ 1610: Bamboo Blossoms # Python3 2018.7.13 bal4u MAX = 7368792 cno = 0 tbl = [0]*(MAX+2) while True: m, n = map(int, input().split()) if m == 0: break cno += 1 for i in range(n): for j in range(m, MAX, m): tbl[j] = cno; for j in range(m, MAX): if tbl[j] != cno: break m += 1 print(m)
s766713576
p01095
u847467233
1531446921
Python
Python3
py
Runtime Error
0
0
327
# AOJ 1610: Bamboo Blossoms # Python3 2018.7.13 bal4u MAX = 7368792 cno = 0 tbl = [0]*(MAX+2) while True: m, n = map(int, input().split()) if m == 0: break tbl = [0] * (MAX+1) for i in range(n): for j in range(m, MAX, m): tbl[j] = 1 k = m for j in range(m, MAX): if not tbl[j]: break k += 1 m = k print(m)
s216514586
p01095
u260980560
1482767311
Python
Python
py
Runtime Error
40000
162372
329
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 print i
s622334924
p01095
u260980560
1482767560
Python
Python
py
Runtime Error
40000
84448
340
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 print i t += 1
s402507140
p01095
u260980560
1482768650
Python
Python
py
Runtime Error
0
0
756
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[i]: res.append(i) prime[i] = q def solve(m, n): # [m,m*m) sat = [0]*(m*m) for i in xrange(m, m*m): if not sat[i]: if n == 0: return i n -= 1 for j in xrange(i, m*m, i): sat[j] = 1 # [m*m,\inf) idx = prime[m*m] print m*m, res[idx] return res[idx+n] while 1: m, n = map(int, raw_input().split()) print solve(m, n)
s304227547
p01095
u260980560
1482769086
Python
Python
py
Runtime Error
40000
84316
368
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 cnt += 1 i += 1 print i t += 1
s463498969
p01095
u078042885
1483690624
Python
Python3
py
Runtime Error
40000
122688
281
while 1: m,n=map(int,input().split()) if n==0:break a=[0]*7368792 b,c=m,0 while c!=n: if a[b]==0: i=1 c+=1 while i*b<7368792: a[i*b]=1 i+=1 b+=1 while a[b]:b+=1 print(b)
s681865966
p01095
u078042885
1483690938
Python
Python3
py
Runtime Error
40000
122652
281
while 1: m,n=map(int,input().split()) if m==0:break a=[0]*7368792 b,c=m,0 while c!=n: if a[b]==0: i=1 c+=1 while i*b<7368792: a[i*b]=1 i+=1 b+=1 while a[b]:b+=1 print(b)
s360718062
p01095
u078042885
1483691007
Python
Python3
py
Runtime Error
40000
122672
284
while 1: m,n=map(int,input().split()) if m==n==0:break a=[0]*7368792 b,c=m,0 while c!=n: if a[b]==0: i=1 c+=1 while i*b<7368792: a[i*b]=1 i+=1 b+=1 while a[b]:b+=1 print(b)
s179609452
p01095
u078042885
1483691188
Python
Python3
py
Runtime Error
40000
294560
285
while 1: m,n=map(int,input().split()) if m==n==0:break a=[0]*18368792 b,c=m,0 while c!=n: if a[b]==0: i=1 c+=1 while i*b<7368792: a[i*b]=1 i+=1 b+=1 while a[b]:b+=1 print(b)
s561124578
p01095
u078042885
1483692610
Python
Python3
py
Runtime Error
40000
122764
282
while 1: m,n=map(int,input().split()) if m==0:break a=[0]*7368792 b=m while 1: if not a[b]: if n==0: print(b) break n-=1 for i in range(b,7368792,b): a[i]=1 b+=1
s935009943
p01095
u078042885
1483693762
Python
Python3
py
Runtime Error
40000
123320
263
while 1: m,n=map(int,input().split()) if m==0:break a=[0]*7400000 b=m while 1: if 0==a[b]: if n==0: print(b) break n-=1 for i in range(b,7368792,b):a[i]=1 b+=1
s538086341
p01095
u078042885
1483801061
Python
Python3
py
Runtime Error
40000
123236
261
while 1: m,n=map(int,input().split()) if m==0:break a=[True]*7400000 while 1: if a[m]: if n==0: print(m) break n-=1 for i in range(m*2,7368792,m):a[i]=False m+=1
s264343171
p01095
u078042885
1484579425
Python
Python3
py
Runtime Error
40000
123236
215
while 1: m,n=map(int,input().split()) if n==0:break a=[False]*7400000 while n: while a[m]:m+=1 n-=1 for i in range(m,7368792,m):a[i]=True while a[m]:m+=1 print(m)
s793450632
p01095
u078042885
1484579639
Python
Python3
py
Runtime Error
40000
123156
218
while 1: m,n=map(int,input().split()) if n==m==0:break a=[False]*7400000 while n: while a[m]:m+=1 n-=1 for i in range(m,7368792,m):a[i]=True while a[m]:m+=1 print(m)
s729632731
p01095
u408260374
1493397915
Python
Python3
py
Runtime Error
40000
122764
416
while True: M, N = map(int, input().split()) if M == N == 0: break INF = 7368791 P = [False] * (INF + 1) cnt = 0 for i in range(M, INF + 1): if cnt >= N: break if not P[i]: for j in range(i, INF + 1, i): P[j] = True cnt += 1 for i in range(M, INF + 1): if not P[i]: print(i) break
s094907007
p01095
u408260374
1493398093
Python
Python3
py
Runtime Error
40000
555476
558
memo = dict() while True: M, N = map(int, input().split()) if M == N == 0: break if (M, N) in memo: print(memo[(M, N)]) continue INF = 7368791 P = [False] * (INF + 1) cnt = 0 for i in range(M, INF + 1): if cnt >= N: break if not P[i]: memo[(M, cnt)] = i for j in range(i, INF + 1, i): P[j] = True cnt += 1 for i in range(M, INF + 1): if not P[i]: memo[(M, N)] = i print(i) break
s526846216
p01095
u408260374
1493398194
Python
Python
py
Runtime Error
40000
744472
632
import sys if sys.version[0] == '2': range, input = xrange, raw_input memo = dict() while True: M, N = map(int, input().split()) if M == N == 0: break if (M, N) in memo: print(memo[(M, N)]) continue INF = 7368791 P = [False] * (INF + 1) cnt = 0 for i in range(M, INF + 1): if cnt >= N: break if not P[i]: memo[(M, cnt)] = i for j in range(i, INF + 1, i): P[j] = True cnt += 1 for i in range(M, INF + 1): if not P[i]: memo[(M, N)] = i print(i) break
s778795368
p01095
u408260374
1493398357
Python
Python3
py
Runtime Error
40000
432020
674
import sys if sys.version[0] == '2': range, input = xrange, raw_input memo = dict() INF = 7368791 P = [False] * (INF + 1) while True: M, N = map(int, input().split()) if M == N == 0: break if (M, N) in memo: print(memo[(M, N)]) continue for i in range(INF + 1): P[i] = False cnt = 0 for i in range(M, INF + 1): if cnt >= N: break if not P[i]: memo[(M, cnt)] = i for j in range(i, INF + 1, i): P[j] = True cnt += 1 for i in range(M, INF + 1): if not P[i]: memo[(M, N)] = i print(i) break
s311452541
p01095
u408260374
1493398411
Python
Python
py
Runtime Error
40000
477004
674
import sys if sys.version[0] == '2': range, input = xrange, raw_input memo = dict() INF = 7368791 P = [False] * (INF + 1) while True: M, N = map(int, input().split()) if M == N == 0: break if (M, N) in memo: print(memo[(M, N)]) continue for i in range(INF + 1): P[i] = False cnt = 0 for i in range(M, INF + 1): if cnt >= N: break if not P[i]: memo[(M, cnt)] = i for j in range(i, INF + 1, i): P[j] = True cnt += 1 for i in range(M, INF + 1): if not P[i]: memo[(M, N)] = i print(i) break
s121273934
p01095
u506554532
1514541539
Python
Python3
py
Runtime Error
0
0
376
MAX = 7368800 while True: M,N = map(int,input().split()) if M == 0: break sieve = [0,0] + [1]*MAX m = M cnt = 0 while True: if sieve[m]: if cnt < N: cnt += 1 for n in range(2*m,MAX+1,m): sieve[n] = 0 else: print(m) break m += 1
s727504191
p01095
u506554532
1514551383
Python
Python3
py
Runtime Error
0
0
556
MAX = 7368800 src = [[] for i in range(101)] i = 0 while True: m,n = map(int,input().split()) if m == 0: break src[m].append((n,i)) i += 1 Q = i ans = [None] * Q for m,qs in enumerate(src): if len(qs) == 0: continue qs.sort() sieve = [0,0] + [1]*MAX maxn = qs[-1][0] tmp = [] n = m while len(tmp) <= maxn: if sieve[n]: tmp.append(n) for nn in range(2*n,MAX+1,n): sieve[nn] = 0 n += 1 for n,i in qs: ans[i] = tmp[n] for a in ans: print(a)
s707051112
p01095
u506554532
1514551585
Python
Python3
py
Runtime Error
0
0
569
MAX = 7368800 src = [[] for i in range(101)] i = 0 while True: m,n = map(int,input().split()) if m == 0: break src[m].append((n,i)) i += 1 Q = i ans = [None] * Q for m,qs in enumerate(src): if len(qs) == 0: continue qs.sort() sieve = [0,0] + [1]*MAX maxn = qs[-1][0] tmp = [] n = m while len(tmp) <= maxn: if sieve[n]: tmp.append(n) for nn in range(2*n,min(maxn*15,MAX+1),n): sieve[nn] = 0 n += 1 for n,i in qs: ans[i] = tmp[n] for a in ans: print(a)
s929453667
p01095
u269391636
1523370470
Python
Python3
py
Runtime Error
0
0
230
while(True): a = list(map(int, input().split())) m , n = a[0], a[1] if m == 0: break lis = [i for i in range(m,n * 16)] for i in range(n): lis = [i for i in lis if i % lis[0]] print(lis[0])
s277780564
p01095
u269391636
1523376465
Python
Python3
py
Runtime Error
0
0
528
def main(): a = list(map(int, input().split())) m , n = a[0], a[1] if m == 0: return 1 print(sieve(m,n)[0]) return 0 def mark(s, x): for i in range(x, len(s), x): s[i] = False def sieve(m,n): s = [False] * m + [True] * 16 * n count = 0 for x in range(m,n * 16): if s[x]: mark(s, x) count += 1 if count == n: break return [i for i in range(len(s)) if s[i] and i > 1] while(True): if main(): break
s060387343
p01095
u269391636
1523376595
Python
Python3
py
Runtime Error
0
0
527
def main(): a = list(map(int, input().split())) m , n = a[0], a[1] if m == 0: return 1 print(sieve(m,n)[0]) return 0 def mark(s, x): for i in range(x, len(s), x): s[i] = False def sieve(m,n): s = [False] * m + [True] * 16 * n count = 0 for x in range(m,n * 8): if s[x]: mark(s, x) count += 1 if count == n: break return [i for i in range(len(s)) if s[i] and i > 1] while(True): if main(): break
s752960040
p01095
u269391636
1523376762
Python
Python3
py
Runtime Error
0
0
528
def main(): a = list(map(int, input().split())) m , n = a[0], a[1] if m == 0: return 1 print(sieve(m,n)[0]) return 0 def mark(s, x): for i in range(x, len(s), x): s[i] = False def sieve(m,n): s = [False] * m + [True] * 16 * n count = 0 for x in range(m,n * 16): if s[x]: mark(s, x) count += 1 if count == n: break return [i for i in range(len(s)) if s[i] and i > 1] while(True): if main(): break
s190001670
p01095
u269391636
1523376870
Python
Python
py
Runtime Error
0
0
528
def main(): a = list(map(int, input().split())) m , n = a[0], a[1] if m == 0: return 1 print(sieve(m,n)[0]) return 0 def mark(s, x): for i in range(x, len(s), x): s[i] = False def sieve(m,n): s = [False] * m + [True] * 16 * n count = 0 for x in range(m,n * 16): if s[x]: mark(s, x) count += 1 if count == n: break return [i for i in range(len(s)) if s[i] and i > 1] while(True): if main(): break
s169063043
p01095
u269391636
1523376889
Python
Python3
py
Runtime Error
0
0
528
def main(): a = list(map(int, input().split())) m , n = a[0], a[1] if m == 0: return 1 print(sieve(m,n)[0]) return 0 def mark(s, x): for i in range(x, len(s), x): s[i] = False def sieve(m,n): s = [False] * m + [True] * 16 * n count = 0 for x in range(m,n * 16): if s[x]: mark(s, x) count += 1 if count == n: break return [i for i in range(len(s)) if s[i] and i > 1] while(True): if main(): break
s457611758
p01095
u269391636
1523377054
Python
Python3
py
Runtime Error
0
0
470
def mark(s, x): for i in range(x, len(s), x): s[i] = False def sieve(m,n): s = [False] * m + [True] * 16 * n count = 0 for x in range(m,n * 16): if s[x]: mark(s, x) count += 1 if count == n: break return [i for i in range(len(s)) if s[i] and i > 1] while(True): a = list(map(int, input().split())) m , n = a[0], a[1] if m == 0: break print(sieve(m,n)[0])
s049190757
p01095
u269391636
1523377302
Python
Python3
py
Runtime Error
0
0
518
def mark(s, x): for i in range(x, len(s), x): s[i] = False def sieve(m,n): s = [False] * m + [True] * 16 * n count = 0 for x in range(m,n * 16): if s[x]: mark(s, x) count += 1 if count == n: break return [i for i in range(len(s)) if s[i] and i > 1] def main(): while(True): a = list(map(int, input().split())) m , n = a[0], a[1] if m == 0: return(0) print(sieve(m,n)[0]) main()
s373325765
p01095
u011621222
1526636874
Python
Python3
py
Runtime Error
0
0
471
import sys sys.setrecursionlimit(10000) def f(start, goal): global C for i in range(start, goal): for j in range(m, (i//2)+1): if (i%j == 0): C += 1 f(i+1, C) while 1: m, n = map(int, input().split()) if (m == 0 and n == 0): break; if (n < m): print(m + n) elif (n == m): print(m + n + 1) else: C = m+n+1 f(2*m, C) c = int(C) while 1: for i in range(m, C): if (c%i == 0): break else: print(c) break c += 1
s133708705
p01095
u509278866
1528185186
Python
Python3
py
Runtime Error
0
0
1016
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 998244353 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): rr = [] while True: m,n = LI() if n == 0 and m == 0: break l = 7368792 a = [None] * l j = m for i in range(n): while not a[j] is None: j += 1 for k in range(j,l,j): a[k] = 1 while not a[j] is None: j += 1 rr.append(j) return '\n'.join(map(str, rr)) print(main())
s786971577
p01095
u509278866
1528186389
Python
Python3
py
Runtime Error
0
0
960
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 998244353 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): rr = [] while True: m,n = LI() if n == 0 and m == 0: break l = 7368792 a = [None] * l j = m for i in range(n): while a[j]: j += 1 for k in range(j,l,j): a[k] = True while a[j]: j += 1 print(j) return main()
s290890615
p01095
u509278866
1528186671
Python
Python3
py
Runtime Error
0
0
970
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 998244353 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): rr = [] while True: m,n = LI() if n == 0 and m == 0: break l = min(7368792,n*20) a = [None] * l j = m for i in range(n): while a[j]: j += 1 for k in range(j,l,j): a[k] = True while a[j]: j += 1 print(j) return main()
s950475272
p01095
u509278866
1528186757
Python
Python3
py
Runtime Error
0
0
960
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 998244353 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): rr = [] while True: m,n = LI() if n == 0 and m == 0: break l = 8368792 a = [None] * l j = m for i in range(n): while a[j]: j += 1 for k in range(j,l,j): a[k] = True while a[j]: j += 1 print(j) return main()
s261075656
p01095
u284260266
1529038218
Python
Python3
py
Runtime Error
0
0
356
while True: m, n = map(int,input().split()) if m == 0 and n == 0: break den = [m] for i in range(m+1, 1000000, 1): den.append(i) for j in range(0, len(den)-1, 1): if i%den[j] == 0: den.remove(i) break if len(den) > n: print(den[-1]) break
s409084010
p01095
u531592024
1529656813
Python
Python3
py
Runtime Error
0
0
433
while True: (n, m) = list(map(int, input().split())) if n == 0: break arr = [n] app = arr.append arrsize = 1 i = n + 1 while True: ge = True for e in arr: if i % e == 0: ge = False break if ge: app(i) arrsize += 1 if arrsize > m: print(i) break i += 1
s186776166
p01095
u284260266
1529820855
Python
Python3
py
Runtime Error
0
0
464
while True: m, n = map(int,input().split()) if m == 0 and n == 0: break sea = [] pri = [] for i in range(m, 7368792): sea.append(True) for i in range(0, m): sea[i] = False for i in range(m, len(sea)): if sea[i] == True: pri.append(i) if len(pri) > n: print(pri[-1]) break for j in range(i, len(sea), i): sea[j] = False
s721795918
p01095
u284260266
1529820980
Python
Python3
py
Runtime Error
0
0
491
while True: m, n = map(int,input().split()) if m == 0 and n == 0: break sea = list() pri = list() for i in range(m, 7368792): sea.append(True) #print(sea) for i in range(0, m): sea[i] = False for i in range(m, len(sea)): if sea[i] == True: pri.append(i) if len(pri) > n: print(pri[-1]) break for j in range(i, len(sea), i): sea[j] = False
s526095847
p01095
u284260266
1529821777
Python
Python3
py
Runtime Error
0
0
1525
while True: m, n = map(int,input().split()) if m == 0 and n == 0: break sea = [] pri = [] for i in range(0, 7368792): sea.append(True) #print(sea) """くそ長すぎて笑える for i in range(0, 7368792-m): pri.append(sea[i]) print(sea[i], i,"in") for i in range(0, 7368792-m): pri.append(sea[0]) for j in range(0, len(sea)): if sea[j]%pri[i] == 0: #print(pri[i], "m") #print(sea[j], "del") sea.remove(sea[j]) #break if len(pri) > n: print(pri[-1]) break """ #nが500000になると死ぬ for i in range(0, m): sea[i] = False for i in range(m, len(sea)): if sea[i] == True: pri.append(i) if len(pri) > n: print(pri[-1]) break for j in range(i, len(sea), i): sea[j] = False """removeするとindexずれるわ while True:#ver_Sieve_of_Eratosthenes m, n = map(int,input().split()) if m == 0 and n == 0: break pri = list() sea = list() for i in range(2, 7368792): sea.append(i) for i in range(m, 7368792): pri.append(sea[i-2]) print(pri) for j in range(0,len(sea)): if sea[j]%i == 0: sea.remove(sea[j]) break if len(pri) > n: print(pri) print(pri[-1]) break """
s173148869
p01095
u284260266
1529822493
Python
Python3
py
Runtime Error
0
0
483
while True: m, n = map(int,input().split()) if m == 0 and n == 0: break sea = [] pri = [] for i in range(0, 7368792): sea.append(True) #print(sea) for i in range(0, m): sea[i] = False for i in range(m, len(sea)): if sea[i] == True: pri.append(i) if len(pri) > n: print(pri[-1]) break for j in range(i, len(sea), i): sea[j] = False
s460192466
p01095
u284260266
1529823607
Python
Python3
py
Runtime Error
0
0
503
while True: m, n = map(int,input().split()) if m == 0 and n == 0: break sea = [] #pri = [] co = 0 for i in range(0, 7368792): sea.append(True) for i in range(0, m): sea[i] = False for i in range(m, len(sea)): if sea[i] == True: co = co + 1 #pri.append(i) if co > n: print(sea.index(True)) break for j in range(i, len(sea), i): sea[j] = False
s363386788
p01095
u284260266
1529824946
Python
Python3
py
Runtime Error
0
0
458
while True: m, n = map(int,input().split()) if m == 0 and n == 0: break sea = [] #pri = [] co = 0 for i in range(m, 7368792): sea.append(True) for i in range(0, len(sea)): if sea[i] == True: co = co + 1 #pri.append(i) if co > n: print(sea.index(True)+m) break for j in range(i, len(sea), i+m): sea[j] = False
s118576174
p01095
u284260266
1530088061
Python
Python3
py
Runtime Error
0
0
430
while True: m, n = map(int,input().split()) if m == 0 and n == 0: break sea = [] #pri = [] co = 0 sea = [True]*(7368792-m) for i in range(0, len(sea)): if sea[i] == True: co = co + 1 #pri.append(i) if co > n: print(sea.index(True)+m) break for j in range(i, len(sea), i+m): sea[j] = False
s895266960
p01095
u284260266
1530090613
Python
Python3
py
Runtime Error
0
0
364
while True: m, n = map(int,input().split()) if m == 0 and n == 0: break sea = [True]*(7368792-m) co = 0 for i in range(0, len(sea)): if sea[i] == True: co = co + 1 if co > n: break for j in range(i, len(sea), i+m): sea[j] = False print(sea.index(True)+m)
s445116206
p01095
u284260266
1530150221
Python
Python3
py
Runtime Error
0
0
364
while True: m, n = map(int,input().split()) if m == 0 and n == 0: break sea = [True]*(7368792-m) co = 0 for i in range(0, len(sea)): if sea[i] == True: co = co + 1 if co > n: break for j in range(i, len(sea), i+m): sea[j] = False print(sea.index(True)+m)
s627146919
p01095
u284260266
1530170958
Python
Python3
py
Runtime Error
0
0
364
while True: m, n = map(int,input().split()) if m == 0 and n == 0: break sea = [True]*(7368792-m) co = 0 for i in range(0, len(sea)): if sea[i] == True: co = co + 1 if co > n: break for j in range(i, len(sea), i+m): sea[j] = False print(sea.index(True)+m)
s960042212
p01095
u284260266
1530172336
Python
Python3
py
Runtime Error
0
0
453
a = 0 while True: m, n = map(int,input().split()) if m == 0 and n == 0 and a == 0: a = a+1 continue elif m == 0 and n == 0 and a == 1: break sea = [True]*(7368792-m) co = 0 for i in range(0, len(sea)): if sea[i] == True: co = co + 1 if co > n: break for j in range(i, len(sea), i+m): sea[j] = False print(sea.index(True)+m)
s748788803
p01095
u284260266
1530172443
Python
Python3
py
Runtime Error
0
0
353
while True: m, n = map(int,input().split()) if m == 0: break sea = [True]*(7368792-m) co = 0 for i in range(0, len(sea)): if sea[i] == True: co = co + 1 if co > n: break for j in range(i, len(sea), i+m): sea[j] = False print(sea.index(True)+m)
s477768220
p01095
u284260266
1530172568
Python
Python3
py
Runtime Error
0
0
353
while True: m, n = map(int,input().split()) if m == 0: break sea = [True]*(7500111-m) co = 0 for i in range(0, len(sea)): if sea[i] == True: co = co + 1 if co > n: break for j in range(i, len(sea), i+m): sea[j] = False print(sea.index(True)+m)
s976131361
p01095
u284260266
1530181060
Python
Python3
py
Runtime Error
0
0
364
while True: m, n = map(int,input().split()) if m == 0 and n == 0: break sea = [True]*(7368792-m) co = 0 for i in range(0, len(sea)): if sea[i] == True: co = co + 1 if co > n: break for j in range(i, len(sea), i+m): sea[j] = False print(sea.index(True)+m)
s653917404
p01095
u012868265
1530181545
Python
Python3
py
Runtime Error
0
0
376
while True: m, n = map(int,input().split()) if m == 0 and n == 0: break sea = [True]*(7368792-m) co = 0 for i in range(0, len(sea)): if sea[i] == True: co = co + 1 if co > n: break for j in range(i, len(sea), i+m): sea[j] = False print(sea.index(True)+m)
s218562894
p01095
u012868265
1530181578
Python
Python
py
Runtime Error
0
0
376
while True: m, n = map(int,input().split()) if m == 0 and n == 0: break sea = [True]*(7368792-m) co = 0 for i in range(0, len(sea)): if sea[i] == True: co = co + 1 if co > n: break for j in range(i, len(sea), i+m): sea[j] = False print(sea.index(True)+m)
s154876218
p01095
u012868265
1530181731
Python
Python
py
Runtime Error
0
0
385
while True: m, n = map(int,input().split()) if m == 0 and n == 0: break sea = 8000000 #[True]*(7368792-m) co = 0 for i in range(0, len(sea)): if sea[i] == True: co = co + 1 if co > n: break for j in range(i, len(sea), i+m): sea[j] = False print(sea.index(True)+m)
s535437423
p01095
u012868265
1530181751
Python
Python
py
Runtime Error
0
0
392
while True: m, n = map(int,input().split()) if m == 0 and n == 0: break sea = [True]*8000000 #[True]*(7368792-m) co = 0 for i in range(0, len(sea)): if sea[i] == True: co = co + 1 if co > n: break for j in range(i, len(sea), i+m): sea[j] = False print(sea.index(True)+m)
s869909357
p01095
u012868265
1530181760
Python
Python
py
Runtime Error
0
0
372
while True: m, n = map(int,input().split()) if m == 0 and n == 0: break sea = [True]*8000000 co = 0 for i in range(0, len(sea)): if sea[i] == True: co = co + 1 if co > n: break for j in range(i, len(sea), i+m): sea[j] = False print(sea.index(True)+m)
s099581370
p01095
u012868265
1530181769
Python
Python3
py
Runtime Error
0
0
372
while True: m, n = map(int,input().split()) if m == 0 and n == 0: break sea = [True]*8000000 co = 0 for i in range(0, len(sea)): if sea[i] == True: co = co + 1 if co > n: break for j in range(i, len(sea), i+m): sea[j] = False print(sea.index(True)+m)
s337696279
p01095
u012868265
1530182276
Python
Python3
py
Runtime Error
0
0
364
while True: m, n = map(int,input().split()) if m == 0 and n == 0: break sea = [True]*(7368792-m) co = 0 for i in range(0, len(sea)): if sea[i] == True: co = co + 1 if co > n: break for j in range(i, len(sea), i+m): sea[j] = False print(sea.index(True)+m)
s446664490
p01095
u012868265
1530184183
Python
Python3
py
Runtime Error
0
0
370
while True: m, n = list(map(int,input().split())) if m == 0 and n == 0: break sea = [True]*(7368792-m) co = 0 for i in range(0, len(sea)): if sea[i] == True: co = co + 1 if co > n: break for j in range(i, len(sea), i+m): sea[j] = False print(sea.index(True)+m)
s982432252
p01095
u284260266
1530184200
Python
Python3
py
Runtime Error
0
0
477
while True: m, n = map(int,input().split()) if m == 0 and n == 0: break sea = [True]*(7368792-m) co = 0 for i in range(0, len(sea)): if sea[i] == True: co = co + 1 if co > n: break for j in range(i, len(sea), i+m): sea[j] = False for i in range(0,len(sea)): if sea[i] == True: co = i+m break #print(sea.index(True)+m) print(co)
s957325362
p01095
u012868265
1530185310
Python
Python3
py
Runtime Error
0
0
373
while True: m, n = [int(i) for i in input().split()] if m == 0 and n == 0: break sea = [True]*(7368792-m) co = 0 for i in range(0, len(sea)): if sea[i] == True: co = co + 1 if co > n: break for j in range(i, len(sea), i+m): sea[j] = False print(sea.index(True)+m)
s253069351
p01095
u012868265
1530185575
Python
Python3
py
Runtime Error
0
0
408
while True: m, n = [int(i) for i in input().split()] if m == 0 and n == 0: break sea = [True for i in range(0,7368792-m)]#[True]*(7368792-m) co = 0 for i in range(0, len(sea)): if sea[i] == True: co = co + 1 if co > n: break for j in range(i, len(sea), i+m): sea[j] = False print(sea.index(True)+m)
s331555246
p01095
u012868265
1530185801
Python
Python3
py
Runtime Error
0
0
501
while True: m, n = [int(i) for i in input().split()] if m == 0 and n == 0: break sea = [True for i in range(0,7368792-m)]#[True]*(7368792-m) co = 0 for i in range(0, len(sea)): if sea[i] == True: co = co + 1 if co > n: break for j in range(i, len(sea), i+m): sea[j] = False for i in range(0,len(sea)): if sea[i]: print(i+m) break #print(sea.index(True)+m)
s428545267
p01095
u855199458
1530256460
Python
Python3
py
Runtime Error
0
0
355
def inpl(): return list(map(int, input().split())) M, N = inpl() lim = 7368791 + 1 while N: years = [False]*(lim) for i in range(M, lim): if years[i] == False: if N == 0: print(i) break for j in range(i, lim, i): years[j] = True N -= 1 M, N = inpl()
s268746049
p01096
u808689778
1535692617
Python
Python3
py
Runtime Error
0
0
610
n = int(input()) if n == 0: break w = list(map(int, input().split())) dp = [[-1 for j in range(n + 1)] for i in range(n + 1)] def rec(l, r): # 既に計算済み? if dp[l][r] != -1: return dp[l][r] # これ以上取り除けない? if abs(l - r) <= 1: return 0 res = 0 # パターン1. if abs(w[l] - w[r - 1]) <= 1 and rec(l + 1, r - 1) == r - l - 2: res = r - l # パターン2.区間を分ける for mid in range(l + 1, r - 1): res = max(res, rec(l, mid) + rec(mid, r)) dp[l][r] = res return res print(rec(0, n))
s069161768
p01096
u408260374
1493641783
Python
Python3
py
Runtime Error
40000
9108
572
while True: N = int(input()) if not N: break W = [int(x) for x in input().split()] dp = [[0] * N for _ in range(N)] for w in range(2, N + 1): for left in range(N - w + 1): # [left, right] right = left + w - 1 for mid in range(left + 1, right): dp[left][right] = max(dp[left][right], dp[left][mid] + dp[mid + 1][right]) if right - left - 1 == dp[left + 1][right - 1] and abs(W[left] - W[right]) <= 1: dp[left][right] = right - left + 1 print(dp[0][N-1])
s278654131
p01096
u408260374
1493641896
Python
Python3
py
Runtime Error
40000
9140
597
while True: N = int(input()) if not N: break W = [int(x) for x in input().split()] dp = [[0] * N for _ in range(N)] for w in range(2, N + 1): for left in range(N - w + 1): # [left, right] right = left + w - 1 if right - left - 1 == dp[left + 1][right - 1] and abs(W[left] - W[right]) <= 1: dp[left][right] = right - left + 1 continue for mid in range(left + 1, right): dp[left][right] = max(dp[left][right], dp[left][mid] + dp[mid + 1][right]) print(dp[0][N-1])
s629616152
p01096
u408260374
1493641938
Python
Python
py
Runtime Error
40000
7728
671
import sys if sys.version[0] == '2': range, input = xrange, raw_input while True: N = int(input()) if not N: break W = [int(x) for x in input().split()] dp = [[0] * N for _ in range(N)] for w in range(2, N + 1): for left in range(N - w + 1): # [left, right] right = left + w - 1 if right - left - 1 == dp[left + 1][right - 1] and abs(W[left] - W[right]) <= 1: dp[left][right] = right - left + 1 continue for mid in range(left + 1, right): dp[left][right] = max(dp[left][right], dp[left][mid] + dp[mid + 1][right]) print(dp[0][N-1])
s432813408
p01096
u408260374
1493642473
Python
Python
py
Runtime Error
40000
7732
807
import sys if sys.version[0] == '2': range, input = xrange, raw_input while True: N = int(input()) if not N: break W = [int(x) for x in input().split()] dp = [[0] * N for _ in range(N)] for i in range(N-1): if abs(W[i] - W[i + 1]) <= 1: dp[i][i + 1] = 2 for w in range(3, N + 1): for left in range(N - w + 1): # [left, right] right = left + w - 1 if right - left - 1 == dp[left + 1][right - 1] and abs(W[left] - W[right]) <= 1: dp[left][right] = right - left + 1 continue for mid in range(left + 1, right): m = dp[left][mid] + dp[mid + 1][right] if m > dp[left][right]: dp[left][right] = m print(dp[0][N-1])
s743607675
p01096
u408260374
1493643617
Python
Python
py
Runtime Error
0
0
956
import sys if sys.version[0] == '2': range, input = xrange, raw_input ans = [] idx = [x for x in reversed(range(300))] for i in range(299): idx[i + 1] += idx[i] def dec(l, r): return idx[l] + r - l while True: N = int(input()) if not N: break W = [int(x) for x in input().split()] dp = [0] * (N * (N + 1) // 2) for i in range(N-1): if abs(W[i] - W[i + 1]) <= 1: dp[dec(i, i + 1)] = 2 for w in range(3, N + 1): for left in range(N - w + 1): # [left, right] right = left + w - 1 if w - 2 == dp[dec(left + 1, right - 1)] and abs(W[left] - W[right]) <= 1: dp[dec(left, right)] = w continue for mid in range(left + 1, right): m = dp[dec(left, mid)] + dp[dec(mid + 1, right)] if m > dp[dec(left, right)]: dp[dec(left, right)] = m print(dp[dec(0, N-1)])
s566194934
p01096
u667806071
1496732499
Python
Python3
py
Runtime Error
0
0
674
def shot(i, daruma): if i >= len(daruma): results.append(n - len(daruma)) return string = "_".join(map(str, daruma)) if dp[i].get(string): return dp[i][string] = True shot(i + 1, daruma[:]) if abs(daruma[i - 1] - daruma[i]) <= 1: del daruma[i] del daruma[i - 1] shot(1, daruma[:]) dp = [] results = [] n = 0 def resolve(): global results global n global dp n = int(input()) if n == 0: return False dp = [{} for x in range(n)] daruma = list(map(int, input().split())) results = [] shot(1, daruma[:]) print(max(results)) return True while resolve(): pass
s527730074
p01096
u766926358
1526645568
Python
Python3
py
Runtime Error
0
0
512
def f(daruma): global flag, min if (flag): return length = len(daruma) if (daruma == 0 or daruma == 1): print(n - length) flag = true return for i in range(length-1): diff = abs(daruma[i] - daruma[i+1]) if (diff < 2): kari_daruma = daruma[:i] + daruma[i+2:] f(kari_daruma) else: min = (min if min <= length else length) return while 1: count = 0 flag = False n = int(input()) if (n == 0): break min = n daruma = list(map(int, input().split())) f(daruma) print(n - min)
s044055955
p01096
u766926358
1526645712
Python
Python3
py
Runtime Error
0
0
552
import sys sys.setrecursionlimit(10000) def f(daruma): global flag, min if (flag): return length = len(daruma) if (daruma == 0 or daruma == 1): print(n - length) flag = true return for i in range(length-1): diff = abs(daruma[i] - daruma[i+1]) if (diff < 2): kari_daruma = daruma[:i] + daruma[i+2:] f(kari_daruma) else: min = (min if min <= length else length) return while 1: count = 0 flag = False n = int(input()) if (n == 0): break min = n daruma = list(map(int, input().split())) f(daruma) print(n - min)
s018241908
p01096
u766926358
1526646185
Python
Python3
py
Runtime Error
0
0
553
import sys sys.setrecursionlimit(10000) def f(daruma): global flag, min if (flag): return length = len(daruma) if (daruma == 0 or daruma == 1): print(n - length) flag = true return for i in range(length-1): diff = abs(daruma[i] - daruma[i+1]) if (diff < 2): kari_daruma = daruma[:i] + daruma[i+2:] f(kari_daruma) else: min = (min if min <= length else length) return while 1: count = 0 flag = False n = int(input()) if (n == 0): break min = n daruma = list(map(int, input().split())) f(daruma) print(n - min)
s904457969
p01096
u766926358
1526646248
Python
Python3
py
Runtime Error
0
0
553
import sys sys.setrecursionlimit(10000) def f(daruma): global flag, min if (flag): return length = len(daruma) if (daruma == 0 or daruma == 1): print(n - length) flag = true return for i in range(length-1): diff = abs(daruma[i] - daruma[i+1]) if (diff < 2): kari_daruma = daruma[:i] + daruma[i+2:] f(kari_daruma) else: min = (min if min <= length else length) return while 1: count = 0 flag = False n = int(input()) if (n == 0): break min = n daruma = list(map(int, input().split())) f(daruma) print(n - min)
s987518138
p01097
u260980560
1482762240
Python
Python
py
Runtime Error
0
0
2724
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 xj, yj, zj = ps[j] dx = abs(xi-xj) dy = abs(yi-yj) dz = abs(zi-zj) if dx < s and dy < s and dz < s: cost = 2*((s-dx)*(s-dy)+(s-dy)*(s-dz)+(s-dz)*(s-dx)) G[i].append((j, cost)) G[j].append((i, cost)) print i, j, cost ans = -1 used = [0]*n for i in xrange(n): if not used[i]: used[i] = 1 deq = deque() deq.append((i, -1)) loop = 0 cnt = 1 leaf = i while deq: v, prev = deq.popleft() if len(G[v]) == 1: leaf = v for t, co in G[v]: if not used[t]: used[t] = 1 deq.append((t, v)) cnt += 1 elif prev != t: loop = 1 d_used = [0]*n if cnt < k: continue deq_c = deque() res = 0 if not loop: deq.append(leaf) d_used[leaf] = 1 while deq: v = deq.popleft() for t, co in G[v]: if not d_used[t]: deq.append(t) d_used[t] = 1 if len(deq_c) >= k-1: res -= deq_c.popleft() res += co ans = max(ans, res) deq_c.append(co) else: t, co = G[i][0] d_used[t] = 1 res = co deq.append((t, i)) deq_c.append(co) ans = max(ans, res) while deq: v, prev = deq.popleft() for t, co in G[v]: if not d_used[t] and t != prev: deq.append((t, v)) d_used[t] = 1 if len(deq_c) >= k-1 and cnt > k: res -= deq_c.popleft() res += co ans = max(ans, res) deq_c.append(co) if ans == -1: print -1 else: print 6*k*s*s - ans
s547854722
p01097
u260980560
1482762379
Python
Python
py
Runtime Error
0
0
2791
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] for j in xrange(i, n): if i==j: continue xj, yj, zj = ps[j] dx = abs(xi-xj) dy = abs(yi-yj) dz = abs(zi-zj) if dx < s and dy < s and dz < s: cost = 2*((s-dx)*(s-dy)+(s-dy)*(s-dz)+(s-dz)*(s-dx)) G[i].append((j, cost)) G[j].append((i, cost)) print i, j, cost ans = -1 used = [0]*n for i in xrange(n): if not used[i]: used[i] = 1 deq = deque() deq.append((i, -1)) loop = 0 cnt = 1 leaf = i while deq: v, prev = deq.popleft() if len(G[v]) == 1: leaf = v for t, co in G[v]: if not used[t]: used[t] = 1 deq.append((t, v)) cnt += 1 elif prev != t: loop = 1 d_used = [0]*n if cnt < k: continue deq_c = deque() res = 0 if not loop: deq.append(leaf) d_used[leaf] = 1 while deq: v = deq.popleft() for t, co in G[v]: if not d_used[t]: deq.append(t) d_used[t] = 1 if len(deq_c) >= k-1: res -= deq_c.popleft() res += co ans = max(ans, res) deq_c.append(co) else: t, co = G[i][0] d_used[t] = 1 res = co deq.append((t, i)) deq_c.append(co) ans = max(ans, res) while deq: v, prev = deq.popleft() for t, co in G[v]: if not d_used[t] and t != prev: deq.append((t, v)) d_used[t] = 1 if len(deq_c) >= k-1 and cnt > k: res -= deq_c.popleft() res += co ans = max(ans, res) deq_c.append(co) if ans == -1: print -1 else: print 6*k*s*s - ans
s335048086
p01097
u408260374
1495152573
Python
Python3
py
Runtime Error
0
0
3717
class Cube: def __init__(self, x, y, z, s): self.x, self.y, self.z = x, y, z self.s = s def is_in_cube(self, x, y, z): return self.x <= x <= self.x + self.s and self.y <= y <= self.y + self.s and self.z <= z <= self.z + self.s def intersect(self, C): dxyz = [(0, 0, 0), (C.s, 0, 0), (0, C.s, 0), (0, 0, C.s), (C.s, C.s, 0), (C.s, 0, C.s), (0, C.s, C.s), (C.s, C.s, C.s)] for dx1, dy1, dz1 in dxyz: nx1, ny1, nz1 = C.x + dx1, C.y + dy1, C.z + dz1 if self.is_in_cube(nx1, ny1, nz1): for dx2, dy2, dz2 in dxyz: nx2, ny2, nz2 = self.x + dx2, self.y + dy2, self.z + dz2 if C.is_in_cube(nx2, ny2, nz2): a, b, c = abs(nx1 - nx2), abs(ny1 - ny2), abs(nz1 - nz2) if a * b * c == 0: continue # print(a, b, c, end=':') return 2 * (a * b + b * c + c * a) return 0 INF = 10 ** 9 while True: N, K, S = map(int, input().split()) # print((N, K, S)) if not (N | K | S): break cubes = [Cube(*map(int, input().split()), S) for _ in range(N)] if K == 1: # print(6 * S ** 2) continue edge = [[] for _ in range(N)] for i in range(N): for j in range(i + 1, N): if cubes[i].intersect(cubes[j]): # print(i, j, cubes[i].intersect(cubes[j])) edge[i].append(j) edge[j].append(i) ans = INF used = [False] * N for i in range(N): if not used[i] and len(edge[i]) == 1: con_c = [i] used[i] = True now = edge[i][0] while not used[now]: used[now] = True con_c.append(now) for e in edge[now]: if not used[e]: now = e # print(con_c, now, len(edge[i]), len(edge[now])) if len(con_c) < K: continue con_s = [0] for i in range(len(con_c) - 1): a, b = cubes[con_c[i]], cubes[con_c[i + 1]] con_s.append(a.intersect(b)) # print(con_s) base = 6 * (S ** 2) * K for i in range(len(con_s) - 1): con_s[i + 1] += con_s[i] for i in range(len(con_s) - K + 1): ans = min(ans, base - (con_s[i + K - 1] - con_s[i])) for i in range(N): if not used[i] and len(edge[i]) == 2: con_c = [i] used[i] = True now = edge[i][0] while not used[now]: used[now] = True con_c.append(now) for e in edge[now]: if not used[e]: now = e # print(con_c, now, len(edge[i]), len(edge[now])) if len(con_c) < K: continue con_s = [0] for i in range(len(con_c) - 1): a, b = cubes[con_c[i]], cubes[con_c[i + 1]] con_s.append(a.intersect(b)) a, b = cubes[con_c[0]], cubes[con_c[-1]] con_s.append(a.intersect(b)) # print(con_s) if len(con_c) == K: ans = min(ans, base - sum(con_s)) continue con_s += con_s[1:] for i in range(len(con_s) - 1): con_s[i + 1] += con_s[i] base = 6 * (S ** 2) * K for i in range(len(con_c)): ans = min(ans, base - (con_s[i + K - 1] - con_s[i])) print(ans if ans != INF else -1)
s194927511
p01097
u260980560
1499912738
Python
Python
py
Runtime Error
0
0
2538
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 xj, yj, zj = ps[j] dx = abs(xi-xj) dy = abs(yi-yj) dz = abs(zi-zj) if dx < s and dy < s and dz < s: cost = 2*((s-dx)*(s-dy)+(s-dy)*(s-dz)+(s-dz)*(s-dx)) G[i].append((j, cost)) G[j].append((i, cost)) ans = -1 leaf = set() used = [0]*n for i in xrange(n): if len(G[i]) == 0: if k == 1: ans = 0 used[i] = 1 elif len(G[i]) == 1: leaf.add(i) for v in leaf: if used[v]: continue used[v] = 1 prev = t = None deq = deque() su = 0 while 1: if prev is not None and len(G[v]) == 1: break for t, cost in G[v]: if t == prev: continue used[t] = 1 if len(deq) < k-1: deq.append(cost) su += cost else: su -= deq.popleft() deq.append(cost) su += cost break if len(deq) == k-1: ans = max(ans, su) v, prev = t, v for v in xrange(n): if used[v]: continue prev = t = None used[v] = 1 u = set([v]) while used[v] < 3: for t, cost in G[v]: if t == prev: continue used[t] += 1 u.add(t) break v, prev = t, v cont = k if len(u) == k else k-1 prev = t = None deq = deque(); su = 0 for i in xrange(2*len(u)): for t, cost in G[v]: if t == prev: continue if len(deq) < cont: deq.append(cost) su += cost else: su -= deq.popleft() su += cost deq.append(cost) break if len(deq) == cont: ans = max(ans, su) v, prev = t, v if ans == -1: print -1 else: print 6*k*s*s - ans
s885597924
p01101
u866872417
1530964195
Python
Python3
py
Runtime Error
0
0
371
while(True): n,m=map(int,input().split(" ")) if(n==0): break things = map(int,input().split(" ")) _max=0 for i in range(len(things)): for j in range(i+1,len(things)): ifthings[ i]+things[j] <= m: _max = max(things[i]+things[j],_max): if _max != None: print(_max) else: print("NONE")
s717113790
p01101
u595788415
1555901613
Python
Python
py
Runtime Error
0
0
442
while True: n, m = map(int, input().split()) if n == 0: break a = sorted(map(int, input().split())) index = bisect.bisect_left(a, m) - 1 if index <= 0: print("NONE") continue ans = 0 for i in range(index, 0, -1): for j in range(i-1, -1, -1): if a[i] + a[j] <= m: ans = max(ans, a[i] + a[j]) if ans: print(ans) else: print("NONE")