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
s330510101
p00773
u015553205
1507391443
Python
Python3
py
Runtime Error
40000
7636
506
Array = [] flg = 1 while flg > 0: inp = input().split() x = int(inp[0]) y = int(inp[1]) s = int(inp[2]) flg = x**2+y**2+s**2 if flg == 0: break M = 0 for i in range(1,s-1): for j in range(1,s-1): a = int(i*(1+x/100)) b = int(j*(1+x/100)) if (a+b) == s: M_temp = int(i*(1+y/100)) + int(j*(1+y/100)) M = max(M,M_temp) Array.append(M) for k in range(0,len(Array)): print(Array[k])
s749731016
p00773
u015553205
1507392306
Python
Python3
py
Runtime Error
40000
7688
540
Answer = [] flg = 1 def Taxed(p,q): T = int(p+p*q/100) return T while flg > 0: inp = input().split() x = int(inp[0]) y = int(inp[1]) s = int(inp[2]) flg = x**2+y**2+s**2 if flg == 0: break M = 0 for i in range(1,s-1): for j in range(1,s-1): a = Taxed(i,x) b = Taxed(j,x) if (a+b) == s: M_temp = Taxed(i,y) + Taxed(j,y) M = max(M,M_temp) Answer.append(M) for k in range(0,len(Answer)): print(Answer[k])
s913987107
p00773
u666221014
1509603670
Python
Python3
py
Runtime Error
0
0
941
#!/usr/bin/env python import sys sys.setrecursionlimit(100000) def MAX( a, b): return a if (a > b) else b def tax_calcurate( tax, left, right): return left * (100 + tax) / 100 + right * (100 + tax) / 100 def Max_Search( left, right): global Max, search_cnt, p_tax, a_tax, price tmp = 0 if left <= right : p_price = tax_calcurate(p_tax, left, right) if p_price == price : tmp = tax_calcurate( a_tax, left, right ) Max = MAX( Max, tmp) if ( p_price == price and search_cnt <= price / 2) or ( p_price < price and search_cnt <= price / 2): Max_Search( search_cnt, price ) search_cnt += 1 else: Max_Search( left, right - 1) while True: p_tax, a_tax, price = [int(i) for i in input().split()] global Max, search_cnt Max = search_cnt = 1 if( p_tax == 0 and a_tax == 0 and price == 0 ): break Max_Search(search_cnt, price) print(Max)
s527814990
p00773
u666221014
1509603696
Python
Python3
py
Runtime Error
0
0
940
#!/usr/bin/env python import sys sys.setrecursionlimit(50000) def MAX( a, b): return a if (a > b) else b def tax_calcurate( tax, left, right): return left * (100 + tax) / 100 + right * (100 + tax) / 100 def Max_Search( left, right): global Max, search_cnt, p_tax, a_tax, price tmp = 0 if left <= right : p_price = tax_calcurate(p_tax, left, right) if p_price == price : tmp = tax_calcurate( a_tax, left, right ) Max = MAX( Max, tmp) if ( p_price == price and search_cnt <= price / 2) or ( p_price < price and search_cnt <= price / 2): Max_Search( search_cnt, price ) search_cnt += 1 else: Max_Search( left, right - 1) while True: p_tax, a_tax, price = [int(i) for i in input().split()] global Max, search_cnt Max = search_cnt = 1 if( p_tax == 0 and a_tax == 0 and price == 0 ): break Max_Search(search_cnt, price) print(Max)
s443697388
p00773
u040556632
1509954691
Python
Python3
py
Runtime Error
0
0
439
while True: l = map(int, raw_input().split()) if l[0] == 0 and l[1] == 0 and l[2] == 0: break ans = 0 # p (100+x) / 100 for i in range(l[2]-1): for j in range(l[2]-1): tmp = i * (100 + l[0])/100 + j * (100 + l[0])/100 if tmp == l[2]: tmp2 = i * (100 + l[1])/100 + j * (100 + l[1])/100 if tmp2 > ans: ans = tmp2 print(ans)
s643352680
p00773
u040556632
1509955854
Python
Python3
py
Runtime Error
0
0
478
while True: l = list(map(int, input().split())) if l[0] == 0 and l[1] == 0 and l[2] == 0: break ans = 0 # p (100+x) / 100 loop = l[2] * (100 + l[0])/100 for i in range(1, loop): for j in range(1, loop): tmp = i * (100 + l[0])/100 + j * (100 + l[0])/100 if tmp == l[2]: tmp2 = i * (100 + l[1])/100 + j * (100 + l[1])/100 if tmp2 > ans: ans = tmp2 print(ans)
s902468958
p00773
u040556632
1509955874
Python
Python
py
Runtime Error
0
0
478
while True: l = list(map(int, input().split())) if l[0] == 0 and l[1] == 0 and l[2] == 0: break ans = 0 # p (100+x) / 100 loop = l[2] * (100 + l[0])/100 for i in range(1, loop): for j in range(1, loop): tmp = i * (100 + l[0])/100 + j * (100 + l[0])/100 if tmp == l[2]: tmp2 = i * (100 + l[1])/100 + j * (100 + l[1])/100 if tmp2 > ans: ans = tmp2 print(ans)
s844729354
p00773
u878596989
1523847364
Python
Python3
py
Runtime Error
0
0
375
while True: a,b,c = map(int, input().strip().split(' ')) temp = 0 if a == 0 and b == 0 and c == 0: break for i in range(1, 1001): for j in range(1, 1001): if i*(100+a)//100 + j*(100+a)//100 == c: if temp < i*(100+b)//100 + j*(100+b)//100: temp = i*(100+b)//100 + j*(100+b)//100 print(temp)
s850613617
p00773
u878596989
1523847727
Python
Python3
py
Runtime Error
0
0
368
while True: a,b,c = map(int, input().strip().split(' ')) temp = 0 if a == 0 and b == 0 and c == 0: break for i in range(1, c): for j in range(1, c): if i*(100+a)//100 + j*(100+a)//100 == c: if temp < i*(100+b)//100 + j*(100+b)//100: temp = i*(100+b)//100 + j*(100+b)//100 print(temp)
s814993459
p00773
u878596989
1523848046
Python
Python3
py
Runtime Error
0
0
368
while True: a,b,c = map(int, input().strip().split(' ')) temp = 0 if a == 0 and b == 0 and c == 0: break for i in range(1, c): for j in range(1, c): if i*(100+a)//100 + j*(100+a)//100 == c: if temp < i*(100+b)//100 + j*(100+b)//100: temp = i*(100+b)//100 + j*(100+b)//100 print(temp)
s193140792
p00773
u878596989
1523848219
Python
Python3
py
Runtime Error
0
0
372
while True: a,b,c = map(int, input().strip().split(' ')) temp = 0 if a == 0 and b == 0 and c == 0: break for i in range(1, c+1): for j in range(1, c+1): if i*(100+a)//100 + j*(100+a)//100 == c: if temp < i*(100+b)//100 + j*(100+b)//100: temp = i*(100+b)//100 + j*(100+b)//100 print(temp)
s603255596
p00773
u878596989
1523849920
Python
Python3
py
Runtime Error
0
0
368
while True: a,b,c = map(int, input().strip().split(' ')) temp = 0 if a == 0 and b == 0 and c == 0: break for i in range(1, c): for j in range(1, c): if i*(100+a)//100 + j*(100+a)//100 == c: if temp < i*(100+b)//100 + j*(100+b)//100: temp = i*(100+b)//100 + j*(100+b)//100 print(temp)
s639986710
p00773
u624914682
1523875087
Python
Python3
py
Runtime Error
0
0
316
x,y,s=map(float,input().split()) while x!=0 or y!=0 or s!=0: x=1+x/100 y=1+y/100 s=int(s) maximum=0 for i in range(s): for j in range(s): if int(i*x)+int(j*x)==s: maximum=max(maximum,int(i*y)+int(j*y)) print(maximum) x,y,s=map(float,input().split())
s108230215
p00773
u624914682
1523877053
Python
Python3
py
Runtime Error
0
0
327
x,y,s=map(int,input().split()) while x!=0 or y!=0 or s!=0: x_f=(100+x)/100.0 y_f=(100+y)/100.0 maximum=0 for i in range(1,s): for j in range(i,s): if int(i*x_f)+int(j*x_f)==s: maximum=max(maximum,int(i*y_f)+int(j*y_f)) print(maximum) x,y,s=map(int,input().split())
s900753980
p00773
u146816547
1524678424
Python
Python
py
Runtime Error
0
0
392
while True: x, y, s = map(int, raw_input().split()) if x == 0 and y == 0 and s == 0: break ans = 0 for i in range(1, s): for j in range(1, s): a = i * (100 + x) / 100; b = j * (100 + x) / 100; if a + b != s: continue ans = max(ans, i * (100 + y) / 100 + j * (100 + y) / 100) print ans
s347133682
p00773
u316584871
1529221532
Python
Python3
py
Runtime Error
0
0
595
def tax(p,x): def tax(p,x): p*(100+x) // 100 def solve(x,y,s): suml = [] for a in range(1,s): for b in range(1,s): sum1 = tax(a,x) + tax(b,x) if sum1 == s: sum2 = tax(a,y) + tax(b,y) suml.append(sum2) elif sum1 > s: break ##b가 증가하면 s도 같이 증가하기때문. 처리속도 올려줌 suml.sort() return suml[len(suml)-1] while True: x,y,s = map(int, input().split()) if (x,y,s == 0): break print(solve(x,y,s))
s464589843
p00773
u316584871
1529221783
Python
Python3
py
Runtime Error
0
0
621
##결국 못풀어서 힌트봄 def tax(p,x): p*(100+x) // 100 def solve(x,y,s): suml = [] for a in range(1,s): for b in range(1,s): sum1 = tax(a,x) + tax(b,x) if (sum1 == s and sum1-1 =< tax(a,y) + tax(b,y)): sum2 = tax(a,y) + tax(b,y) suml.append(sum2) elif sum1 > s: break ##b가 증가하면 s도 같이 증가하기때문. 처리속도 올려줌 suml.sort() return suml[len(suml)-1] while True: x,y,s = map(int, input().split()) if (x,y,s == 0): break print(solve(x,y,s))
s288224130
p00773
u316584871
1529223355
Python
Python3
py
Runtime Error
0
0
423
def tax(p, rate): return p*(100+rate)//100 x, y, s = map(int, input().split()) while(x != 0 or y != 0 or s != 0): sumy = [] sum_bf = int(s/(100+x)*100) for i in range(sum_bf-2, sum_bf+3): for j in range(1,i): k = i-j if(tax(k, x) + tax(j, x) == s): sumy1 = tax(k, y) + tax(j, y) sumy.append(sumy1) sumy.sort() print(sumy[len(sumy-1)])
s734316934
p00773
u316584871
1529223459
Python
Python3
py
Runtime Error
0
0
423
def tax(p, rate): return p*(100+rate)//100 x, y, s = map(int, input().split()) while(x != 0 or y != 0 or s != 0): sumy = [] sum_bf = int(s/(100+x)*100) for i in range(sum_bf-2, sum_bf+3): for j in range(1,i): k = i-j if(tax(k, x) + tax(j, x) == s): sumy1 = tax(k, y) + tax(j, y) sumy.append(sumy1) sumy.sort() print(sumy[len(sumy-1)])
s450997877
p00774
u881100444
1409147114
Python
Python
py
Runtime Error
0
0
390
def calc(pp,x,y): p = 0 for i in range(1,1000): if i*(100+x)/100 == pp: p = i break return p*(100+y)/100 while True: max = 0 x,y,s = map(int,raw_input().split()) if x == 0 and y == 0 and s == 0: break for i in range(1,s): res = calc(i,x,y) + calc(s-i,x,y) if max < res: max = res print max
s544180167
p00774
u498511622
1501672593
Python
Python3
py
Runtime Error
0
0
613
while True: lst=[] pt=0 H=int(input()) for i in range(H): lst.append(list(map(int,input().split()))) for s in lst: for s2 in range(0,3): if s[s2] != s and s[s2] == s[s2+1] == s[s2+2]: x=s[s2] pt += s[s2]*s.count(x) for h in range(0,s.count(x)): s[s.index(x)]=0 for g in lst: for f in range(5): try: if g[f]==0: lst.reverse() g[f]=lst[lst.index(g)-1][f] ls[ls.index(g)-1] else: pass except: break print(pt)
s673279743
p00776
u332822187
1444903887
Python
Python
py
Runtime Error
0
0
1091
ans=[""] ans.pop() s="" w=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"] x=[0] x.pop() def uni(seq): seen = set() seen_add = seen.add return [ x for x in seq if x not in seen and not seen_add(x)] def check(a): global s global w n=len(a) # print "before ",a for i in range(26): if i==0: continue a=a.replace(w[i],w[i-1],1); # print "after ",a if a==s[0:n]: return True else: return False def foo(a,n): # print a global ans global x if n==len(a): if check(a): ans.append(a) return sz=len(a) t=a+s[sz] if check(t): foo(t,n) t=a+w[x[sz]+1] # print t if check(t): # print t foo(t,n) while True: s = raw_input() if s=="#": break ans=[""] ans.pop() x=[0] x.pop() for i in range(len(s)): for j in range(26): if w[j]==s[i]: x.append(j) # print s foo("",len(s)) ans=uni(ans) if len(ans)<=10: print len(ans) for i in range(len(ans)): print ans[i] else: print len(ans) for i in range(5): print ans[i] for i in range(5): print ans[len(ans)-1-i]
s877132095
p00776
u260980560
1498148498
Python
Python
py
Runtime Error
40000
7884
704
import itertools while 1: s = raw_input() if s == '#': break code = [ord(c)-97 for c in s] result = set() l = len(s) for p in itertools.product([0,1], repeat=l): used = set([0, 26]) ok = 1 for i in xrange(l): k = code[i] + p[i] if p[i] == (k in used): ok = 0 break used.add(k) if ok: result.add("".join(chr(97 + code[i] + p[i]) for i in xrange(l))) print len(result) s_result = sorted(result) if len(result) <= 10: for el in sorted(result): print el else: for el in s_result[:5] + s_result[-5:]: print el
s873869811
p00776
u260980560
1498149852
Python
Python
py
Runtime Error
40000
7360
1315
import itertools from heapq import * while 1: s = raw_input() if s == '#': break code = [ord(c)-97 for c in s] l = len(s) f_que = []; l_que = [] ans = 0 for p in itertools.product([0,1], repeat=l): used = set([0, 26]) ok = 1 for i in xrange(l): k = code[i] + p[i] if p[i] == (k in used): ok = 0 break used.add(k) if ok: ans += 1 ss = tuple(-(97 + code[i] + p[i]) for i in xrange(l)) if len(f_que) < 10: heappush(f_que, ss) else: heappushpop(f_que, ss) ss = tuple(97 + code[i] + p[i] for i in xrange(l)) if len(l_que) < 5: heappush(l_que, ss) else: heappushpop(l_que, ss) print ans if ans <= 10: res = ["".join(map(lambda x: chr(-x), heappop(f_que))) for i in xrange(ans)] if ans: print "\n".join(reversed(res)) else: for i in xrange(5): heappop(f_que) res = ["".join(map(lambda x: chr(-x), heappop(f_que))) for i in xrange(5)] print "\n".join(reversed(res)) res = ["".join(map(chr, heappop(l_que))) for i in xrange(5)] print "\n".join(res)
s246653115
p00777
u336892997
1467026361
Python
Python3
py
Runtime Error
40000
8644
1388
def dfs(start, frm, edges, mem): if mem[start]: return mem[start] round_trip = 0 for dest, length in edges[start]: if dest == frm: continue dfs(dest, start, edges, mem) if len(edges[dest]) == 1: round_trip += length continue rt, _ = mem[dest] round_trip += length + rt + length + length one_way = round_trip for dest, length in edges[start]: if dest == frm: continue if len(edges[dest]) == 1: continue rt, ow = mem[dest] one_way = min(one_way, round_trip - rt - length + ow) mem[start] = (round_trip, one_way) return round_trip, one_way def load(): N = int(input()) if N == 0: return None Ps = [int(p)-1 for p in input().split()] Ds = [int(d) for d in input().split()] edges = [[] for _ in range(N)] for i in range(N-1): p = Ps[i] d = Ds[i] i += 1 edges[i].append((p, d)) edges[p].append((i, d)) return edges def solve1(edges): N = len(edges) ans = 100000 * 800 for i in range(N): mem = [None for _ in range(N)] _, one_way = dfs(i, -1, edges, mem) ans = min(ans, one_way) return ans while True: edges = load() if edges is None: break print(solve1(edges))
s694570757
p00777
u336892997
1467026390
Python
Python3
py
Runtime Error
40000
8720
1388
def dfs(start, frm, edges, mem): if mem[start]: return mem[start] round_trip = 0 for dest, length in edges[start]: if dest == frm: continue dfs(dest, start, edges, mem) if len(edges[dest]) == 1: round_trip += length continue rt, _ = mem[dest] round_trip += length + rt + length + length one_way = round_trip for dest, length in edges[start]: if dest == frm: continue if len(edges[dest]) == 1: continue rt, ow = mem[dest] one_way = min(one_way, round_trip - rt - length + ow) mem[start] = (round_trip, one_way) return round_trip, one_way def load(): N = int(input()) if N == 0: return None Ps = [int(p)-1 for p in input().split()] Ds = [int(d) for d in input().split()] edges = [[] for _ in range(N)] for i in range(N-1): p = Ps[i] d = Ds[i] i += 1 edges[i].append((p, d)) edges[p].append((i, d)) return edges def solve1(edges): N = len(edges) ans = 100000 * 800 for i in range(N): mem = [None for _ in range(N)] _, one_way = dfs(i, -1, edges, mem) ans = min(ans, one_way) return ans while True: edges = load() if edges is None: break print(solve1(edges))
s432808305
p00777
u336892997
1467026747
Python
Python3
py
Runtime Error
40000
8776
1392
def dfs(start, frm, edges, mem): if mem[start]: return mem[start] round_trip = 0 for dest, length in edges[start]: if dest == frm: continue dfs(dest, start, edges, mem) if len(edges[dest]) == 1: round_trip += length continue rt, _ = mem[dest] round_trip += length + rt + length + length one_way = round_trip for dest, length in edges[start]: if dest == frm: continue if len(edges[dest]) == 1: continue rt, ow = mem[dest] one_way = min(one_way, round_trip - rt - length + ow) mem[start] = (round_trip, one_way) return round_trip, one_way def load(): N = int(input()) if N == 0: return None Ps = [int(p)-1 for p in input().split()] Ds = [int(d) for d in input().split()] edges = [[] for _ in range(N)] for i in range(N-1): p = Ps[i] d = Ds[i] i += 1 edges[i].append((p, d)) edges[p].append((i, d)) return edges def solve1(edges): N = len(edges) ans = 100000 * 800 * 3 for i in range(N): mem = [None for _ in range(N)] _, one_way = dfs(i, -1, edges, mem) ans = min(ans, one_way) return ans while True: edges = load() if edges is None: break print(solve1(edges))
s175053520
p00777
u336892997
1467026917
Python
Python3
py
Runtime Error
20
7448
35
import time time.sleep(120) exit(0)
s676938739
p00777
u655168177
1467669909
Python
Python
py
Runtime Error
40000
7532
692
def calc_depth(x, k): global g, depth depth[x] = k for t in g[x].iterkeys(): if(depth[t] == -1): calc_depth(t, k + 1) def calc_dp(x): global g, depth s = 0; p = 0 for t, c in g[x].iteritems(): if depth[t] < depth[x]: continue a, b = calc_dp(t) s += 3 * c + a if a else c p = max(p, c + a - b if a else 0) return s, s - p while 1: n = input() if n == 0: break a = map(int, raw_input().split()) b = map(int, raw_input().split()) g = [{} for i in xrange(n)] for i in xrange(n - 1): p = i + 1; q = a[i] - 1; c = b[i] g[p][q] = g[q][p] = c ans = [] for i in xrange(n): depth = [-1] * n calc_depth(i, 0) ans.append(calc_dp(i)[1]) print min(ans)
s106675398
p00777
u655168177
1467671435
Python
Python
py
Runtime Error
40000
7604
731
import sys sys.setrecursionlimit(10000) def calc_depth(x, k): global g, depth depth[x] = k for t in g[x].iterkeys(): if(depth[t] == -1): calc_depth(t, k + 1) def calc_dp(x): global g, depth s = 0; p = 0 for t, c in g[x].iteritems(): if depth[t] < depth[x]: continue a, b = calc_dp(t) s += 3 * c + a if a else c p = max(p, c + a - b if a else 0) return s, s - p while 1: n = input() if n == 0: break a = map(int, raw_input().split()) b = map(int, raw_input().split()) g = [{} for i in xrange(n)] for i in xrange(n - 1): p = i + 1; q = a[i] - 1; c = b[i] g[p][q] = g[q][p] = c ans = [] for i in xrange(n): depth = [-1] * n calc_depth(i, 0) ans.append(calc_dp(i)[1]) print min(ans)
s174431162
p00777
u072053884
1527683627
Python
Python3
py
Runtime Error
0
0
2087
def solve(): from collections import deque def dfs(start, turn=False): path = deque() path.append(start) bridge_lengths = deque() bridge_lengths.append(0) unvisited = [True] * (n + 1) unvisited[start] = False rest = core_islands_num - 1 diameter = 0 end_point = start while True: u = path[-1] for i, d in adj_list[u]: if unvisited[i]: path.append(i) unvisited[i] = False rest -= 1 bridge_lengths.append(d) break else: distance = sum(bridge_lengths) if diameter < distance: diameter = distance end_point = u if rest == 0: break path.pop() bridge_lengths.pop() if turn: return diameter else: return end_point import sys #file_input = sys.stdin file_input = open("1196_in_1", 'r')# while True: n = int(file_input.readline()) if n == 0: break p = list(map(int, file_input.readline().split())) d = list(map(int, file_input.readline().split())) end_bridges_weight = 0 core_islands_num = n adj_list = [[] for i in range(n + 1)] s = 1 for i1, i2, b_l in zip(range(2, n + 1), p, d): if i1 not in p[i1-1:]: end_bridges_weight += b_l core_islands_num -= 1 else: s = i1 adj_list[i1].append((i2, b_l)) adj_list[i2].append((i1, b_l)) if p.count(1) == 1: del adj_list[2][0] end_bridges_weight += d[0] core_islands_num -= 1 e = dfs(s) dm = dfs(e, turn=True) ans = sum(d) * 3 - end_bridges_weight * 2 - dm print(ans) solve()
s111053878
p00780
u575065019
1361661756
Python
Python
py
Runtime Error
19930
5260
485
MAX=2**15 a = range(MAX) a[1] = 0 for p in a: if not p: continue elif p > 100: break else: for multi in xrange(p+p, MAX, p): a[multi] = 0 ans = [] while True: n=input() sig=0 if n==0: break for i in a: if i>(n/2): break for j in reversed(a): if (i+j) == n: sig += 1 if j == i: break ans.append(sig) for i in ans: print i
s264136811
p00780
u575065019
1361661883
Python
Python
py
Runtime Error
19930
5260
485
MAX=33000 a = range(MAX) a[1] = 0 for p in a: if not p: continue elif p > 100: break else: for multi in xrange(p+p, MAX, p): a[multi] = 0 ans = [] while True: n=input() sig=0 if n==0: break for i in a: if i>(n/2): break for j in reversed(a): if (i+j) == n: sig += 1 if j == i: break ans.append(sig) for i in ans: print i
s817507676
p00782
u943441430
1545791306
Python
Python3
py
Runtime Error
0
0
2762
import sys def is_contained(a, area): rx1, ry1, rx2, ry2 = a for r in area: x1, y1, x2, y2 = r if x1 <= rx1 <= x2 and x1 <= rx2 <= x2 and \ y1 <= ry1 <= y2 and y1 <= ry2 <= y2: return True return False def is_inside(x, y, rect): rx1, ry1, rx2, ry2 = rect return (rx1 < x < rx2) and (ry1 < y < ry2) def add_area(a, area): if is_contained(a, area): return area xs, ys, xe, ye = a if xs >= xe or ys >= ye: return area ret = area if area == []: return [a] rr = [] for r in area: rxs, rys, rxe, rye = r if is_inside(rxs, rys, a) and xe < rxe and ye < rye: rr = [[xs, ys, xe, rys], [xs, rys, rxs, ye]] elif is_inside(rxs, rye, a) and rys < ys and xe < rxe: rr = [[xs, ys, rxs, rye], [xs, rye, xe, ye]] elif is_inside(rxe, rys, a) and rxs < xs and ye < rye: rr = [[xs, ys, rxe, rys], [rxe, ys, xe, ye]] elif is_inside(rxe, rye, a) and rxs < xs and rys < ys: rr = [[xs, rye, rxe, ye], [rxe, ys, xe, ye]] elif is_inside(rxs, rys, a) and is_inside(rxe, rys, a) and ye < rye: rr = [[xs, ys, xe, rys], [xs, rys, rxs, ye], [rxe, rys, xe, ye]] elif is_inside(rxs, rye, a) and is_inside(rxe, rye, a) and rys < ys: rr = [[xs, rye, xe, ye], [xs, ys, rxs, rye], [rxe, ys, xe, rye]] elif is_inside(rxs, rys, a) and is_inside(rxs, rye, a) and xe < rxe: rr = [[xs, ys, rxs, ye], [rxs, ys, xe, rys], [rxs, rye, xe, ye]] elif is_inside(rxe, rys, a) and is_inside(rxe, rye, a) and rxs < xs: rr = [[rxe, ys, xe, ye], [xs, ys, rxe, rys], [xs, rye, rxe, ye]] elif rxs < xs and xe < rxe and ys < rys < ye: rr = [[xs, ys, xe, rys]] elif rys < ys and ye < rye and xs < rxs < xe: rr = [[xs, ys, rxs, ye]] elif rxs < xs and xe < rxe and ys < rye < ye: rr = [[xs, rye, xe, ye]] elif rys < ys and ye < rye and xs < rxe < xe: rr = [[rxe, ys, xe, ye]] if rr != []: for q in rr: ret = add_area(q, ret) break if rr == []: ret.append(a) return ret def calc_area(area): s = 0.0 for r in area: s += (r[2]- r[0]) * (r[3] - r[1]) return s n = 0 c = 0 area = [] for line in sys.stdin: if n == 0: n = int(line) c += 1 area = [] if n == 0: break else: ant = list(map(float, line.strip().split(" "))) r = [ant[0] - ant[2], ant[1] - ant[2], ant[0] + ant[2], ant[1] + ant[2]] area = add_area(r, area) n -= 1 if n == 0: print("%d %.2f" % (c, calc_area(area)))
s248536897
p00782
u943441430
1545791403
Python
Python3
py
Runtime Error
0
0
2762
import sys def is_contained(a, area): rx1, ry1, rx2, ry2 = a for r in area: x1, y1, x2, y2 = r if x1 <= rx1 <= x2 and x1 <= rx2 <= x2 and \ y1 <= ry1 <= y2 and y1 <= ry2 <= y2: return True return False def is_inside(x, y, rect): rx1, ry1, rx2, ry2 = rect return (rx1 < x < rx2) and (ry1 < y < ry2) def add_area(a, area): if is_contained(a, area): return area xs, ys, xe, ye = a if xs >= xe or ys >= ye: return area ret = area if area == []: return [a] rr = [] for r in area: rxs, rys, rxe, rye = r if is_inside(rxs, rys, a) and xe < rxe and ye < rye: rr = [[xs, ys, xe, rys], [xs, rys, rxs, ye]] elif is_inside(rxs, rye, a) and rys < ys and xe < rxe: rr = [[xs, ys, rxs, rye], [xs, rye, xe, ye]] elif is_inside(rxe, rys, a) and rxs < xs and ye < rye: rr = [[xs, ys, rxe, rys], [rxe, ys, xe, ye]] elif is_inside(rxe, rye, a) and rxs < xs and rys < ys: rr = [[xs, rye, rxe, ye], [rxe, ys, xe, ye]] elif is_inside(rxs, rys, a) and is_inside(rxe, rys, a) and ye < rye: rr = [[xs, ys, xe, rys], [xs, rys, rxs, ye], [rxe, rys, xe, ye]] elif is_inside(rxs, rye, a) and is_inside(rxe, rye, a) and rys < ys: rr = [[xs, rye, xe, ye], [xs, ys, rxs, rye], [rxe, ys, xe, rye]] elif is_inside(rxs, rys, a) and is_inside(rxs, rye, a) and xe < rxe: rr = [[xs, ys, rxs, ye], [rxs, ys, xe, rys], [rxs, rye, xe, ye]] elif is_inside(rxe, rys, a) and is_inside(rxe, rye, a) and rxs < xs: rr = [[rxe, ys, xe, ye], [xs, ys, rxe, rys], [xs, rye, rxe, ye]] elif rxs < xs and xe < rxe and ys < rys < ye: rr = [[xs, ys, xe, rys]] elif rys < ys and ye < rye and xs < rxs < xe: rr = [[xs, ys, rxs, ye]] elif rxs < xs and xe < rxe and ys < rye < ye: rr = [[xs, rye, xe, ye]] elif rys < ys and ye < rye and xs < rxe < xe: rr = [[rxe, ys, xe, ye]] if rr != []: for q in rr: ret = add_area(q, ret) break if rr == []: ret.append(a) return ret def calc_area(area): s = 0.0 for r in area: s += (r[2]- r[0]) * (r[3] - r[1]) return s n = 0 c = 0 area = [] for line in sys.stdin: if n == 0: n = int(line) c += 1 area = [] if n == 0: break else: ant = list(map(float, line.strip().split(" "))) r = [ant[0] - ant[2], ant[1] - ant[2], ant[0] + ant[2], ant[1] + ant[2]] area = add_area(r, area) n -= 1 if n == 0: print("%d %.2f" % (c, calc_area(area)))
s044615072
p00782
u943441430
1545791627
Python
Python3
py
Runtime Error
0
0
2762
import sys def is_contained(a, area): rx1, ry1, rx2, ry2 = a for r in area: x1, y1, x2, y2 = r if x1 <= rx1 <= x2 and x1 <= rx2 <= x2 and \ y1 <= ry1 <= y2 and y1 <= ry2 <= y2: return True return False def is_inside(x, y, rect): rx1, ry1, rx2, ry2 = rect return (rx1 < x < rx2) and (ry1 < y < ry2) def add_area(a, area): if is_contained(a, area): return area xs, ys, xe, ye = a if xs >= xe or ys >= ye: return area ret = area if area == []: return [a] rr = [] for r in area: rxs, rys, rxe, rye = r if is_inside(rxs, rys, a) and xe < rxe and ye < rye: rr = [[xs, ys, xe, rys], [xs, rys, rxs, ye]] elif is_inside(rxs, rye, a) and rys < ys and xe < rxe: rr = [[xs, ys, rxs, rye], [xs, rye, xe, ye]] elif is_inside(rxe, rys, a) and rxs < xs and ye < rye: rr = [[xs, ys, rxe, rys], [rxe, ys, xe, ye]] elif is_inside(rxe, rye, a) and rxs < xs and rys < ys: rr = [[xs, rye, rxe, ye], [rxe, ys, xe, ye]] elif is_inside(rxs, rys, a) and is_inside(rxe, rys, a) and ye < rye: rr = [[xs, ys, xe, rys], [xs, rys, rxs, ye], [rxe, rys, xe, ye]] elif is_inside(rxs, rye, a) and is_inside(rxe, rye, a) and rys < ys: rr = [[xs, rye, xe, ye], [xs, ys, rxs, rye], [rxe, ys, xe, rye]] elif is_inside(rxs, rys, a) and is_inside(rxs, rye, a) and xe < rxe: rr = [[xs, ys, rxs, ye], [rxs, ys, xe, rys], [rxs, rye, xe, ye]] elif is_inside(rxe, rys, a) and is_inside(rxe, rye, a) and rxs < xs: rr = [[rxe, ys, xe, ye], [xs, ys, rxe, rys], [xs, rye, rxe, ye]] elif rxs < xs and xe < rxe and ys < rys < ye: rr = [[xs, ys, xe, rys]] elif rys < ys and ye < rye and xs < rxs < xe: rr = [[xs, ys, rxs, ye]] elif rxs < xs and xe < rxe and ys < rye < ye: rr = [[xs, rye, xe, ye]] elif rys < ys and ye < rye and xs < rxe < xe: rr = [[rxe, ys, xe, ye]] if rr != []: for q in rr: ret = add_area(q, ret) break if rr == []: ret.append(a) return ret def calc_area(area): s = 0.0 for r in area: s += (r[2]- r[0]) * (r[3] - r[1]) return s n = 0 c = 0 area = [] for line in sys.stdin: if n == 0: n = int(line) c += 1 area = [] if n == 0: break else: ant = list(map(float, line.strip().split(" "))) r = [ant[0] - ant[2], ant[1] - ant[2], ant[0] + ant[2], ant[1] + ant[2]] area = add_area(r, area) n -= 1 if n == 0: print("%d %.2f" % (c, calc_area(area)))
s146060391
p00811
u731235119
1422641125
Python
Python
py
Runtime Error
19930
4436
634
import math def sieve (n): prime = [0,0] prime += [1 for i in range(n-1)] ub = math.sqrt(n) + 1 d = 2 while d <= ub: if prime[d] == 0: d += 1 continue prod = 2 while d * prod <= n: prime[d*prod] = 0 prod += 1 d += 1 return prime prime = sieve(1000) while 1: m,a,b = map(int,raw_input().split(" ")) if (m,a,b) == (0,0,0): break rect_max = (0,0,0) q = 997 while q >= 2: if prime[q] == 0: q -= 1 continue p = q while p * b >= q * a: if prime[p] == 0 or p * q > m: p -= 1 continue if rect_max[0] <= p*q: rect_max = (p*q,p,q) p -= 1 q -= 1 print rect_max[1], rect_max[2]
s944854016
p00811
u633068244
1423402671
Python
Python
py
Runtime Error
19920
8092
463
p = [1]*100001 p[0] = p[1] = 0 for i in range(2,int(100001**0.5)+1): if p[i]: p[2*i::i] = [0]*len(p[2*i::i]) p = [i for i in range(100001) if p[i]] while 1: m,a,b = map(int,raw_input().split()) if m == 0: break aw = ah = 2 mx = 4 for w in p: for h in p: if w*h > m: break if w*h > mx and 1 >= w*1.0/h >= a*1.0/b: mx = w*h aw,ah = w,h print aw,ah
s463569220
p00811
u509278866
1528183867
Python
Python3
py
Runtime Error
0
0
1698
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) class Prime(): def __init__(self, n): self.M = m = int(math.sqrt(n)) + 10 self.A = a = [True] * m a[0] = a[1] = False self.T = t = [] for i in range(2, m): if not a[i]: continue t.append(i) for j in range(i*i,m,i): a[j] = False def is_prime(self, n): return self.A[n] def main(): rr = [] pr = Prime(100000**2) tl = len(pr.T) while True: n,a,b = LI() if n == 0: break m = fractions.Fraction(a,b) sn = n ** 0.5 r = 0 rs = '' for ni in range(tl): i = pr.T[ni] if i > sn: break for nj in range(ni,tl): j = pr.T[nj] if i*j > n: break if i*j <= r: continue if fractions.Fraction(i,j) < m: continue r = i*j rs = '{} {}'.format(i,j) rr.append(rs) return '\n'.join(map(str, rr)) print(main())
s804054497
p00811
u104911888
1372818827
Python
Python
py
Runtime Error
20000
8248
688
import math N=100000 prime=[True]*(N+1) prime[0]=prime[1]=False for i in range(2,int(math.sqrt(N))): if prime[i]==True: j=i while i*j<=N: prime[i*j]=False j+=1 prime=[i for i in range(N+1) if prime[i]] while True: m,a,b=map(int,raw_input().split()) if m==a==b==0:break maxInt=0 ans=(0,0) for p in range(len(prime)): if prime[p]>m:break for q in range(p,len(prime)): mul=prime[p]*prime[q] if mul>m: break if mul<=m and a*prime[q]<=prime[p]*b: if mul>maxInt: maxInt=mul ans=(prime[p],prime[q]) print ans[0],ans[1]
s280884146
p00817
u844945939
1417911608
Python
Python3
py
Runtime Error
0
0
2791
from collections import defaultdict class UnionFind(): def __init__(self, n): self.parent = list(range(n)) self.rank = [0] * n def find(self, x): if self.parent[x] == x: return x else: self.parent[x] = self.find(self.parent[x]) return self.parent[x] def unite(self, x, y): x, y = self.find(x), self.find(y) if x == y: return if self.rank[x] < self.rank[y]: self.parent[x] = y else: self.parent[y] = x if self.rank[x] == self.rank[y]: self.rank[x] += 1 while True: n, p1, p2 = (int(s) for s in input().split()) if not n: break p = p1 + p2 tree = UnionFind(p * 2) unions = defaultdict(list) for i in range(n): xs, ys, a = input().split() x, y = int(xs) - 1, int(ys) - 1 if a == 'yes': tree.unite(x, y) tree.unite(x + p, y + p) else: tree.unite(x, y + p) tree.unite(x + p, y) for i in range(p): unions[tree.find(i)].append(i) roots = [] sides = [] diffs = [] rest = p1 for i in range(p): if i in unions: member_len, foelen = len(unions[i]), len(unions[i + p]) if memlen == foelen: rest = -1 break elif memlen < foelen: diff = foelen - memlen rest -= memlen sides.append(0) else: diff = memlen - foelen sides.append(1) rest -= foelen roots.append(i) diffs.append(diff) if rest < 0: print('no') continue dp = [[1] + [0] * rest for i in range(len(roots) + 1)] for i in reversed(range(len(roots))): for j in range(1, rest + 1): if j < diffs[i]: if dp[i + 1][j]: dp[i][j] = 1 else: dp[i][j] = 0 else: if dp[i + 1][j] and dp[i + 1][j - diffs[i]]: dp[i][j] = 3 elif dp[i + 1][j - diffs[i]]: dp[i][j] = 2 elif dp[i + 1][j]: dp[i][j] = 1 else: dp[i][j] = 0 divines = [] for i in range(len(roots)): if dp[i][rest] == 1: divines.extend(unions[roots[i] + p * sides[i]]) elif dp[i][rest] == 2: divines.extend(unions[roots[i] + p * (1 - sides[i])]) rest -= diffs[i] else: print('no') break else: divines.sort() for div in divines: print(div + 1) print('end')
s106352371
p00817
u586434734
1423139601
Python
Python
py
Runtime Error
0
0
4549
#! /usr/bin/python # -*- coding: utf-8 -*- def main(): # input while True: # p1:devine num. # p2:devillish num. (n, p1, p2) = map(int, raw_input().split()) if n == 0 and p1 == 0 and p2 == 0: break elif p1 == 0: print('end') [raw_input() for x in xrange(n)] elif p2 == 0: for x in xrange(p1): print(x + 1) print('end') [raw_input() for x in xrange(n)] elif n == 0: print('no') else: data = [convertSays(raw_input().split()) for x in xrange(n)] # output # devine member in ascending order. -> 'end' # if there is no sufficient iformation, putting 'no' for x in solve(data, p1, p2): print(x) def convertSays(data): num = map(int, data[:-1]) return num + data[-1:] def solve(data, p1, p2): yes = {} no = {} def groupdYesNo(a, b, say): if say == 'yes': if a in yes: buf = yes[a] buf.add(b) yes[a] = buf else: yes[a] = set([b]) if b in yes: buf = yes[b] buf.add(a) yes[b] = buf else: yes[b] = set([a]) elif say == 'no': if a in no: buf = no[a] buf.add(b) no[a] = buf else: no[a] = set([b]) if b in no: buf = no[b] buf.add(a) no[b] = buf else: no[b] = set([a]) def groupdMember(yes, no): # グループをまとめる seen = [set()] def groupdMember(buf, buf_2): new_buf = set() new_buf2 = buf_2 if len(filter(lambda x:x not in seen[0],buf))== 0: return buf, buf_2 for x in buf: new_buf.add(x) if x in yes: for y in yes[x]: new_buf.add(y) if y in yes: new_buf = new_buf.union(yes[y]) for x in new_buf: if x in no: new_buf2 = new_buf2.union(no[x]) seen[0] = seen[0].union(new_buf) return groupdMember(new_buf2, new_buf) ret = [groupdMember(set([x]), set()) for x in yes] ret2 = [groupdMember(set([x]), set()) for x in no] return filter(lambda x:len(x[0]) + len(x[1]) > 1, ret + ret2) # グループ分け [groupdYesNo(*x) for x in data] group = groupdMember(yes, no) print(group) return judge(group, p1, p2) def numForest(forest): return [(len(x[0]), len(x[1])) for x in forest] def judge(forest, p1, p2): num_forest = numForest(forest) ans = [] # 正直者がdevine_numの場合の # 組み合わせの数を返す @memoize def makeComb(forest_i, devine_num): if devine_num < 0: return 0 if forest_i == 0: left = [num_forest[forest_i][0]].count(devine_num) right = [num_forest[forest_i][1]].count(devine_num) else: left = makeComb(forest_i - 1, devine_num - num_forest[forest_i][0]) right = makeComb(forest_i - 1, devine_num - num_forest[forest_i][1]) # 組み合わせが1の場合の解を保存する if (left + right) == 1: ans.append((left, right)) return left + right def makeDevine(ans, forest): buf = [] for i, x in enumerate(ans): if x == (0, 1): buf += list(forest[i][1]) else: buf += list(forest[i][0]) return sorted(buf) devine_comb = makeComb(len(num_forest) - 1, p1) if devine_comb == 1: return makeDevine(ans, forest) + ['end'] else: return ['no'] # メモ化関数 def memoize(f): cache = {} def helper(*args): if args not in cache: cache[args] = f(*args) return cache[args] return helper def test(): p1 , p2 = 8, 3 data = [[1,2,'yes'], [1,8,'yes'], [1,3,'no'], [4,5,'yes'], [5,6,'yes'], [6,7,'no'], [9,10,'no'], [9,11,'no'], [3,7,'yes']] for x in solve(data, p1, p2): print(x) if __name__=='__main__': # test() main()
s354381883
p00817
u586434734
1423139811
Python
Python
py
Runtime Error
0
0
6741
#! /usr/bin/python # -*- coding: utf-8 -*- def main(): # input while True: # p1:devine num. # p2:devillish num. (n, p1, p2) = map(int, raw_input().split()) if n == 0 and p1 == 0 and p2 == 0: break elif p1 == 0: print('end') [raw_input() for x in xrange(n)] elif p2 == 0: for x in xrange(p1): print(x + 1) print('end') [raw_input() for x in xrange(n)] elif n == 0: print('no') else: data = [convertSays(raw_input().split()) for x in xrange(n)] # output # devine member in ascending order. -> 'end' # if there is no sufficient iformation, putting 'no' for x in solve(data, p1, p2): print(x) def convertSays(data): num = map(int, data[:-1]) return num + data[-1:] def solve(data, p1, p2): yes = {} no = {} def groupdYesNo(a, b, say): if say == 'yes': if a in yes: buf = yes[a] buf.add(b) yes[a] = buf else: yes[a] = set([b]) if b in yes: buf = yes[b] buf.add(a) yes[b] = buf else: yes[b] = set([a]) elif say == 'no': if a in no: buf = no[a] buf.add(b) no[a] = buf else: no[a] = set([b]) if b in no: buf = no[b] buf.add(a) no[b] = buf else: no[b] = set([a]) def groupdMember(yes, no): # グループをまとめる seen = [set()] def groupdMember(buf, buf_2): new_buf = set() new_buf2 = buf_2 if len(filter(lambda x:x not in seen[0],buf))== 0: return buf, buf_2 for x in buf: new_buf.add(x) if x in yes: for y in yes[x]: new_buf.add(y) if y in yes: new_buf = new_buf.union(yes[y]) for x in new_buf: if x in no: new_buf2 = new_buf2.union(no[x]) seen[0] = seen[0].union(new_buf) return groupdMember(new_buf2, new_buf) ret = [groupdMember(set([x]), set()) for x in yes] ret2 = [groupdMember(set([x]), set()) for x in no] return filter(lambda x:len(x[0]) + len(x[1]) > 1, ret + ret2) # グループ分け [groupdYesNo(*x) for x in data] group = groupdMember(yes, no) return judge(group, p1, p2) def numForest(forest): return [(len(x[0]), len(x[1])) for x in forest] def judge(forest, p1, p2): num_forest = numForest(forest) ans = [] # 正直者がdevine_numの場合の # 組み合わせの数を返す @memoize def makeComb(forest_i, devine_num): if devine_num < 0: return 0 if forest_i == 0: left = [num_forest[forest_i][0]].count(devine_num) right = [num_forest[forest_i][1]].count(devine_num) else: left = makeComb(forest_i - 1, devine_num - num_forest[forest_i][0]) right = makeComb(forest_i - 1, devine_num - num_forest[forest_i][1]) # 組み合わせが1の場合の解を保存する if (left + right) == 1: ans.append((left, right)) return left + right def makeDevine(ans, forest): buf = [] for i, x in enumerate(ans): if x == (0, 1): buf += list(forest[i][1]) else: buf += list(forest[i][0]) return sorted(buf) devine_comb = makeComb(len(num_forest) - 1, p1) if devine_comb == 1: return makeDevine(ans, forest) + ['end'] else: return ['no'] # メモ化関数 def memoize(f): cache = {} def helper(*args): if args not in cache: cache[args] = f(*args) return cache[args] return helper def test(): p1 , p2 = 8, 3 data = [[1,2,'yes'], [1,8,'yes'], [1,3,'no'], [4,5,'yes'], [5,6,'yes'], [6,7,'no'], [9,10,'no'], [9,11,'no'], [3,7,'yes']] for x in solve(data, p1, p2): print(x) if __name__=='__main__': # test() main() testdata = """ 208 101 100 94 31 no 179 115 no 136 60 no 147 26 yes 43 17 no 123 92 yes 13 77 no 126 32 no 176 76 yes 128 137 yes 36 102 no 102 149 yes 41 45 yes 15 62 yes 191 116 no 69 201 yes 36 123 no 103 102 no 48 115 yes 59 114 no 191 45 no 51 122 yes 84 168 yes 130 51 no 154 148 no 169 198 no 7 42 no 161 134 yes 6 117 no 64 111 no 57 163 yes 23 171 yes 18 91 yes 81 10 yes 163 39 yes 46 189 yes 139 80 no 143 73 yes 171 133 yes 95 153 yes 25 150 no 136 4 no 15 52 yes 21 13 no 196 93 yes 22 124 yes 127 59 yes 161 150 no 103 69 no 156 46 yes 39 182 yes 173 49 no 8 91 yes 29 99 yes 60 184 no 190 73 yes 135 71 no 24 152 no 181 29 yes 186 88 no 71 113 no 28 82 no 156 110 no 128 170 no 26 55 yes 155 82 no 118 1 yes 37 104 no 108 83 no 35 19 no 140 126 yes 117 11 no 40 3 no 181 145 yes 97 108 yes 125 146 yes 157 164 yes 8 40 no 85 63 no 7 77 no 16 151 no 55 21 no 64 93 yes 159 84 yes 148 142 yes 197 42 no 165 6 no 50 105 no 96 20 no 105 121 yes 201 83 yes 199 197 yes 98 4 yes 36 141 yes 54 194 yes 90 14 yes 153 70 yes 18 97 no 134 127 yes 101 167 no 125 68 no 12 86 no 174 162 no 78 177 yes 168 9 yes 88 130 yes 196 162 yes 164 192 no 189 74 no 54 158 yes 160 198 yes 132 62 yes 68 100 no 195 180 yes 193 144 yes 72 50 yes 65 118 no 41 151 yes 119 195 yes 79 172 no 120 53 no 61 165 no 75 74 no 61 24 no 66 67 yes 178 94 yes 167 170 yes 135 138 no 58 176 no 87 114 yes 33 146 no 47 131 no 56 187 no 127 108 yes 14 166 yes 159 2 yes 30 96 yes 186 94 no 166 190 yes 153 153 yes 27 28 yes 142 188 yes 32 187 yes 106 178 yes 121 89 yes 179 157 yes 66 89 yes 185 70 no 98 147 yes 12 109 no 85 160 no 90 113 no 182 44 no 188 22 no 180 199 yes 141 183 yes 193 87 no 140 23 no 200 109 yes 5 173 yes 112 137 no 194 2 yes 25 138 no 81 131 yes 132 110 yes 33 122 no 158 120 no 79 49 no 149 35 yes 3 34 no 11 48 yes 37 175 no 129 43 no 9 92 no 124 53 yes 111 143 yes 45 201 no 38 16 no 80 112 yes 44 101 yes 38 200 no 192 174 no 145 175 no 20 119 no 10 177 no 75 47 no 116 58 yes 78 139 yes 63 172 no 154 72 yes 99 65 no 1 31 yes 183 107 no 106 57 yes 152 104 no 107 5 no 30 68 yes 185 67 yes 95 135 yes 19 169 no 155 52 no 178 86 yes 27 184 no 129 100 no 22 118 yes 144 56 no 34 76 no 133 71 no 0 0 0 """ #
s014781026
p00819
u633068244
1421853537
Python
Python
py
Runtime Error
0
0
724
for loop in range(int(raw_input())): manu = raw_input() msg = raw_input() size = len(msg) for s in manu[::-1]: if s == "J": msg = msg[-1]+msg[:-1] elif s == "C": msg = msg[1:]+msg[0] elif s == "E": msg = msg[size/2+size%2:]+msg[:size/2] elif s == "A": msg = msg[::-1] elif s == "P": for i in range(len(msg)): if msg[i].isdigit(): msg = msg[:i]+str((int(msg[i])-1+10)%10)+msg[i+1:] elif s == "M": for i in range(len(msg)): if msg[i].isdigit(): msg = msg[:i]+str((int(msg[i])+1)%10)+msg[i+1:] print msg
s139693092
p00819
u633068244
1400323448
Python
Python
py
Runtime Error
0
0
270
R = 2**15+1 dp = [[0]*R for i in range(4)] for i in range(1,182): dp[0][i**2] += 1 for k in range(1,4): for i in range(1,182): for j in range(i**2,R-i**2): dp[k][j+i**2] += dp[k-1][j] while 1: n = input() if n == 0: break print sum(dp[i][n] for i in range(4))
s030429138
p00820
u731235119
1422601897
Python
Python
py
Runtime Error
19930
7068
415
from math import sqrt while 1: n = int(raw_input()) if n == 0: break ub = int(sqrt(n)) square_sum = [[0 for i in range(n+1)] for j in range(4)] for k in range(1,ub+1): square_k = k**2 square_sum[0][square_k] = 1 for j in range(3): for i in range(1, n+1 - square_k): if square_sum[j][i] >= 1: square_sum[j+1][i+square_k] += square_sum[j][i] print sum([square_sum[j][n] for j in range(4)])
s200397957
p00820
u731235119
1422634120
Python
Python
py
Runtime Error
19920
6460
592
from math import sqrt while 1: n = int(raw_input()) if n == 0: break ub = int(sqrt(n)) square = [i**2 for i in range(1,ub+1)] square_sum =[[0 for i in range(n)] for j in range(2)] count = 0 for k in range(1,ub+1): for i in range(1,k+1): if square[k-1] + square[i-1] <= n: square_sum[0][square[k-1] + square[i-1]-1] += 1 for i in range(1, n + 1 - square[k-1]): if square_sum[0][i-1] >= 1: square_sum[1][i-1+square[k-1]] += square_sum[0][i-1] count += square_sum[1][n-1-square[k-1]] print (1 if n == ub**2 else 0) + square_sum[0][n-1] + square_sum[1][n-1] + count
s278690783
p00820
u506554532
1514273083
Python
Python3
py
Runtime Error
0
0
728
import math LIM = 182 def solve(n): ans = 0 for a in range(1,LIM): tmp = a*a if tmp == n: ans += 1 if tmp >= n: break for b in range(a,LIM): tmp2 = tmp + b*b if tmp2 == n: ans += 1 if tmp2 >= n: break for c in range(b,LIM): tmp3 = tmp2 + c*c if tmp3 == n: ans += 1 if tmp3 >= n: break d = int(math.sqrt(n - tmp3)) if tmp3 + d*d == n and c <= d: ans += 1 return ans while True: N = int(input()) if N == 0: break print(solve(N))
s516833273
p00820
u506554532
1514275171
Python
Python3
py
Runtime Error
0
0
739
import math LIM = 182 def is_square(n): a = int(math.sqrt(n)) return a*a == n def solve(n): ans = 0 if is_square(n): ans += 1 for a in range(1,LIM): if a*a*2 > n: break if is_square(n - a*a): ans += 1 for b in range(a,LIM): if b*b*2 > (n - a*a): break if is_square(n - a*a - b*b): ans += 1 for c in range(b,LIM): if c*c*2 > (n - a*a - b*b): break tmp = n - a*a - b*b - c*c if is_square(tmp) and c*c <= tmp: ans += 1 return ans while True: N = int(input()) if N == 0: break print(solve(N))
s924120299
p00820
u109084363
1361178121
Python
Python
py
Runtime Error
19930
4376
525
import sys import bisect import itertools as it square = [] i = 0 while i*i <= 2**15: square.append(i*i) i += 1 L = len(square) while True: n = int(sys.stdin.readline()) if n == 0: break count = 0 for i in xrange(L): for j in xrange(i, L): for k in xrange(j, L): v = n - square[i] - square[j] - square[k] idx = bisect.bisect_left(square, v) if idx >= k and square[idx] == v: count += 1 print count
s782626756
p00820
u109084363
1361178182
Python
Python
py
Runtime Error
19920
4384
529
import sys import bisect import itertools as it square = [] i = 0 while i*i <= 2**15: square.append(i*i) i += 1 L = len(square) while True: n = int(sys.stdin.readline()) if n == 0: break count = 0 for i in xrange(L): for j in xrange(i, L): for k in xrange(j, L): v = n - square[i] - square[j] - square[k] idx = bisect.bisect_left(square, v) if L > idx >= k and square[idx] == v: count += 1 print count
s906549423
p00820
u109084363
1361178261
Python
Python
py
Runtime Error
19930
4316
505
import sys import bisect square = [] i = 0 while i*i <= 2**15: square.append(i*i) i += 1 L = len(square) while True: n = int(sys.stdin.readline()) if n == 0: break count = 0 for i in xrange(L): for j in xrange(i, L): for k in xrange(j, L): v = n - square[i] - square[j] - square[k] idx = bisect.bisect_left(square, v) if L > idx >= k and square[idx] == v: count += 1 print count
s973888347
p00820
u104911888
1372836887
Python
Python
py
Runtime Error
20000
4504
454
import math while True: n=input() if n==0:break S=set() P=set([i*i for i in range(182)]) for i in range(182): if i>n:break for j in range(182): if i+j>n:break for k in range(182): if i+j+k>n:break if n-32761<=i*i+j*j+k*k<=n and ((n-(i*i+j*j+k*k)) in P): l=[i,j,k,int(round(math.sqrt(n-(i*i+j*j+k*k))))] l.sort() S.add(tuple(l)) print len(S)
s457865180
p00820
u104911888
1372839757
Python
Python
py
Runtime Error
20000
4224
345
while True: n=input() if n==0:break cnt=0 for i in range(182): if i*i>n:break for j in range(i,182): if i*i+j*j>n:break for k in range(j,182): if i*i+j*j+k*k>n:break for l in range(k,182): if i*i+j*j+k*k+l*l>n:break if i*i+j*j+k*k+l*l==n: cnt+=1 print cnt
s303717984
p00826
u072053884
1540988809
Python
Python3
py
Runtime Error
0
0
2974
def string_to_complex(s): a, b, c, d = map(int, s.split()) return (a + b * 1j, c + d * 1j) def dot(c1, c2): return c1.real * c2.real + c1.imag * c2.imag def cross(c1, c2): return c1.real * c2.imag - c1.imag * c2.real def cross_point(p1, p2, p3, p4): crs1 = cross(p2 - p1, p3 - p1) crs2 = cross(p2 - p1, p4 - p1) if crs1 == 0 and crs2 == 0: if p1 == p3 or p1 == p4: return p1 elif p2 == p3 or p2 == p4: return p2 else: return None crs3 = cross(p4 - p3, p1 - p3) crs4 = cross(p4 - p3, p2 - p3) if crs1 * crs2 <= 0 and crs3 * crs4 <= 0: base = p4 - p3 hypo1 = p1 - p3 hypo2 = p2 - p3 d1 = abs(cross(base, hypo1)) / abs(base) d2 = abs(cross(base, hypo2)) / abs(base) return p1 + d1 / (d1 + d2) * (p2 - p1) else: return None def contain(polygon): flag = False for a, b in zip(polygon[0:], polygon[1:] + [polygon[0]]): if a.imag > b.imag: a, b = b, a if a.imag <= 0 and b.imag > 0 and cross(a, b) > 0: flag = not flag return flag def solve(): def dfs_contain(goal, edges, cross_points): cur_edge = edges[-1] for next_edge, next_cp in adj_edge[cur_edge]: if next_edge == goal: if contain(cross_points + [next_cp]): break elif next_edge not in edges and unchecked[next_edge] and DP[next_edge]: edges.append(next_edge) cross_points.append(next_cp) if dfs_contain(goal, edges, cross_points): break e = edges.pop() DP[e] = False cross_points.pop() else: return False return True from sys import stdin file_input = stdin.radlines() from itertools import combinations while True: n = int(lines[0]) if n == 0: break edges = enumerate(map(string_to_complex, lines[1:1+n])) adj_edge = [[] for i in range(n)] for e1, e2 in combinations(edges, 2): n1, t1 = e1 n2, t2 = e2 cp = cross_point(*t1, *t2) if cp: adj_edge[n1].append((n2, cp)) adj_edge[n2].append((n1, cp)) flag = True while flag: for i, ae in enumerate(adj_edge): if len(ae) == 1: ne, cp = ae.pop() adj_edge[ne].remove((i, cp)) break else: flag = False unchecked = [True] * n for e in range(n): unchecked[e] = False DP = [True] * n if dfs_contain(e, [e], []): print('yes') break else: print('no') del lines[:1+n] solve()
s625066012
p00826
u072053884
1540988918
Python
Python3
py
Runtime Error
0
0
2975
def string_to_complex(s): a, b, c, d = map(int, s.split()) return (a + b * 1j, c + d * 1j) def dot(c1, c2): return c1.real * c2.real + c1.imag * c2.imag def cross(c1, c2): return c1.real * c2.imag - c1.imag * c2.real def cross_point(p1, p2, p3, p4): crs1 = cross(p2 - p1, p3 - p1) crs2 = cross(p2 - p1, p4 - p1) if crs1 == 0 and crs2 == 0: if p1 == p3 or p1 == p4: return p1 elif p2 == p3 or p2 == p4: return p2 else: return None crs3 = cross(p4 - p3, p1 - p3) crs4 = cross(p4 - p3, p2 - p3) if crs1 * crs2 <= 0 and crs3 * crs4 <= 0: base = p4 - p3 hypo1 = p1 - p3 hypo2 = p2 - p3 d1 = abs(cross(base, hypo1)) / abs(base) d2 = abs(cross(base, hypo2)) / abs(base) return p1 + d1 / (d1 + d2) * (p2 - p1) else: return None def contain(polygon): flag = False for a, b in zip(polygon[0:], polygon[1:] + [polygon[0]]): if a.imag > b.imag: a, b = b, a if a.imag <= 0 and b.imag > 0 and cross(a, b) > 0: flag = not flag return flag def solve(): def dfs_contain(goal, edges, cross_points): cur_edge = edges[-1] for next_edge, next_cp in adj_edge[cur_edge]: if next_edge == goal: if contain(cross_points + [next_cp]): break elif next_edge not in edges and unchecked[next_edge] and DP[next_edge]: edges.append(next_edge) cross_points.append(next_cp) if dfs_contain(goal, edges, cross_points): break e = edges.pop() DP[e] = False cross_points.pop() else: return False return True from sys import stdin file_input = stdin.readlines() from itertools import combinations while True: n = int(lines[0]) if n == 0: break edges = enumerate(map(string_to_complex, lines[1:1+n])) adj_edge = [[] for i in range(n)] for e1, e2 in combinations(edges, 2): n1, t1 = e1 n2, t2 = e2 cp = cross_point(*t1, *t2) if cp: adj_edge[n1].append((n2, cp)) adj_edge[n2].append((n1, cp)) flag = True while flag: for i, ae in enumerate(adj_edge): if len(ae) == 1: ne, cp = ae.pop() adj_edge[ne].remove((i, cp)) break else: flag = False unchecked = [True] * n for e in range(n): unchecked[e] = False DP = [True] * n if dfs_contain(e, [e], []): print('yes') break else: print('no') del lines[:1+n] solve()
s979389121
p00828
u621997536
1435324078
Python
Python3
py
Runtime Error
19930
6804
1308
dx = [1, 1, 0, -1, 0, 0, 0, 0, 1, 1, 0, -1, 1, 1, 0, -1, 1, 1, 0, -1] dy = [0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1] dz = [0, 0, 0, 0, 1, 1, 0, -1, 0, 1, 1, 1, 1, 1, 0, -1, 1, 1, 0, -1] def check(i, col, x, y, z): if not(0 <= x < n and 0 <= y < n and 0 <= z < n): return 0 if col != d[z][y][x]: return 0 return check(i, col, x + dx[i], y + dy[i], z + dz[i]) + 1 from itertools import product while True: n, m, p = map(int, input().split()) if not n: break d = [[[0 for z in range(n)] for y in range(n)] for x in range(n)] done = False for i in range(p): x, y = map(int, input().split()) if done: continue x, y, z = x - 1, y - 1, n - 1 while z > 0 and not d[z - 1][y][x]: z -= 1 d[z][y][x] = i % 2 + 1 for x, y, z in product(range(n), repeat=3): for j in range(len(dx)): if check(j, 1, x, y, z) >= m: print('Black', i + 1) done = True break if check(j, 2, x, y, z) >= m: print('White', i + 1) done = True break if done: break if not done: print('Draw')
s869723653
p00836
u546285759
1491645756
Python
Python3
py
Runtime Error
0
0
546
primes = [0, 0] + [1]*996 for i in range(2, 32): if primes[i]: for j in range(i*i, 998, i): primes[j] = 0 while True: n = int(input()) if n == 0: break m = n while not primes[m]: m -= 1 pnum = [i for i in range(m+1) if primes[i]] ans = 0 for i in range(len(pnum)): tmp = 0 for j in range(i, len(pnum)): tmp += pnum[j] if tmp == n: ans += 1 break if tmp > n: break print(ans)
s453626675
p00836
u546285759
1491645806
Python
Python3
py
Runtime Error
0
0
547
primes = [0, 0] + [1]*999 for i in range(2, 32): if primes[i]: for j in range(i*i, 1001, i): primes[j] = 0 while True: n = int(input()) if n == 0: break m = n while not primes[m]: m -= 1 pnum = [i for i in range(m+1) if primes[i]] ans = 0 for i in range(len(pnum)): tmp = 0 for j in range(i, len(pnum)): tmp += pnum[j] if tmp == n: ans += 1 break if tmp > n: break print(ans)
s681320744
p00836
u947762778
1509907373
Python
Python3
py
Runtime Error
0
0
554
import math isPrime = [1 for _ in range (10002)] isPrime[:2] = [0, 0] for i in range(2, 101): for j in range(i*i, 10001, i): isPrime[j] = 0 prime = [] for i in range(10001): if isPrime[i] == 1: prime.append(i) while True: n = int(input()) if n == 0: break cnt = 0 for i in range(n + 1): sum = 0 for j in range(i,n + 1): sum += prime[j] if sum == n: cnt += 1 break if sum > n: break print(cnt)
s622627849
p00836
u947762778
1509907455
Python
Python3
py
Runtime Error
0
0
546
import math isPrime = [1 for _ in range (10002)] isPrime[:2] = [0, 0] for i in range(2, 101): for j in range(i*i, 10001, i): isPrime[j] = 0 prime = [] for i in range(10001): if isPrime[i] == 1: prime.append(i) while True: n = int(input()) if n == 0: break cnt = 0 for i in range(n): sum = 0 for j in range(i,n): sum += prime[j] if sum == n: cnt += 1 break if sum > n: break print(cnt)
s532963934
p00836
u633068244
1400221245
Python
Python
py
Runtime Error
0
0
406
r = 100001 p = [1]*r p[0] = p[1] = 0 for i in range(int(r**0.5)): if p[i]: p[2*i::i] = [0 for x in range(2*i,r,i)] prime = [] for i in range(r): if p[i]: prime.append(i) while 1: n = int(raw_input()) if n == 0: break ans = 0 i = 0 while 1: s = 0 j = i while 1: s += prime[j] if s >= n: if s == n: ans += 1 else: break j += 1 i += 1 if i > n: break print ans
s324953152
p00848
u078042885
1485800330
Python
Python3
py
Runtime Error
0
0
358
for i in range(2,1201): for j in range(2,int(i**0.5)+1): if not i%j:break else:p+=[i] dp=[[0]*1200 for _ in range(15)] dp[0][0]=1 for x,y in enumerate(p): for i in range(min(x+1,14),0,-1): for j in range(p[x],1200): dp[i][j]+=dp[i-1][j-y] while 1: n,k=map(int,input().split()) if n==0:break print(dp[k][n])
s682492228
p00848
u633068244
1400222274
Python
Python
py
Runtime Error
39870
4424
498
r = 1500 p = [1]*r p[0] = p[1] = 0 for i in range(int(r**0.5)): if p[i]: p[2*i::i] = [0 for x in range(2*i,r,i)] prime = [] for i in range(r): if p[i]: prime.append(i) def solve(n,k,i): if k == 0: return 1 if n == 0 else 0 if n-k*prime[i] < 0 : return 0 res = 0 res += solve(n-prime[i],k-1,i+1) + solve(n,k,i+1) return res while 1: n,k = map(int,raw_input().split()) if n == 0: break ans = 0 for i in range(n): if k*prime[i] > n: break ans += solve(n-prime[i],k-1,i+1) print ans
s660092602
p00848
u633068244
1400222344
Python
Python
py
Runtime Error
39870
4688
478
r = 10000 p = [1]*r p[0] = p[1] = 0 for i in range(int(r**0.5)): if p[i]: p[2*i::i] = [0 for x in range(2*i,r,i)] prime = [] for i in range(r): if p[i]: prime.append(i) def solve(n,k,i): if k == 0: return 1 if n == 0 else 0 if n-k*prime[i] < 0 : return 0 return solve(n-prime[i],k-1,i+1) + solve(n,k,i+1) while 1: n,k = map(int,raw_input().split()) if n == 0: break ans = 0 for i in range(n): if k*prime[i] > n: break ans += solve(n-prime[i],k-1,i+1) print ans
s506478136
p00855
u617183767
1421160238
Python
Python
py
Runtime Error
0
0
1046
#! /usr/bin/env python # -*- coding: utf-8 -*- import os import sys import itertools import math from collections import Counter, defaultdict class Main(object): def __init__(self): pass def solve(self): ''' insert your code ''' prime = self.sieve(1299709) while True: n = input() if prime[n]: print 0 else: lower = upper = n while not prime[lower]: lower -= 1 while not prime[upper]: upper += 1 print upper - lower return None def sieve(self, n): f = [True for i in xrange(n+1)] f[0] = False f[1] = False i = 2 while i * i <= n: if f[i]: j = 2 while i * j <= n: f[i * j] = False j += 1 i += 1 return f if __name__ == '__main__': m = Main() m.solve()
s842635085
p00855
u316268279
1421978802
Python
Python3
py
Runtime Error
19920
17172
818
#!/usr/bin/env python # -*- coding: utf-8 -*- import math def sieve_of_erastosthenes(num): input_list = [False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(num)] input_list[0] = input_list[1] = False input_list[2] = input_list[3] = input_list[5] = True sqrt = math.sqrt(num) for serial in range(3, num, 2): if serial >= sqrt: return input_list for s in range(serial ** 2, num, serial): input_list[s] = False primeTable = sieve_of_erastosthenes(13*10**5) while True: k = int(input()) if k == 0: break if primeTable[k]: print(0) else: i = 0 while i < k or primeTable[i] == False: if primeTable[i]: prevPrime = i i+= 1 print(i-prevPrime)
s613356741
p00855
u316268279
1421979196
Python
Python3
py
Runtime Error
19930
17172
820
#!/usr/bin/env python # -*- coding: utf-8 -*- import math def sieve_of_erastosthenes(num): input_list = [False if i % 2 == 0 or i % 3 == 0 or i % 5 == 0 else True for i in range(num)] input_list[0] = input_list[1] = False input_list[2] = input_list[3] = input_list[5] = True sqrt = math.sqrt(num) for serial in range(3, num, 2): if serial >= sqrt: return input_list for s in range(serial ** 2, num, serial): input_list[s] = False primeTable = sieve_of_erastosthenes(13*(10**5)) while True: k = int(input()) if k == 0: break if primeTable[k]: print(0) else: i = 0 while i < k or primeTable[i] == False: if primeTable[i]: prevPrime = i i+= 1 print(i-prevPrime)
s934008060
p00864
u467175809
1530999651
Python
Python
py
Runtime Error
0
0
373
while True: n, w = map(int, raw_input().split()) if n == 0: break lst = [] for i in range(n): num = input() num /= w lst.append(num) ans = 0.0 cnt = [0 for i in range(100)] for i in range(n): num = max_num - lst[i] ans += num cnt[num] += 1 print ans / max(lst) / max(cnt) + 0.01
s780870987
p00864
u633068244
1422350998
Python
Python
py
Runtime Error
0
0
284
while 1: n,w = map(int,raw_input().split()) if n == 0: break v = [0]*10 m = 0 for i in range(n): p = int(raw_input())/w v[p] += 1 m = max(m,p) ans = 0.01 for i in range(10): ans += (v[i]*1.0/max(v))*(1-i*1.0/m) print ans
s816861213
p00864
u120360464
1438245581
Python
Python
py
Runtime Error
0
0
404
#! /usr/bin/python # -*- coding: utf-8 -*- while True: (n, w) = map(int, raw_input().split()) if n == 0: break vcnt = [0]*10 vr = 0 for i in range(n): v = int(raw_input()) if v/w > vr: vr = v/w vcnt[v/w] += 1 vmax = max(vcnt) ans = 0 for i in range(10): ans += ((vr-i)/float(vr))*(vcnt[i]/float(vmax)) print ans+0.01
s177821584
p00864
u506554532
1514182228
Python
Python3
py
Runtime Error
0
0
404
while True: N,W = map(int,input().split()) if N == 0: break src = [int(input()) for i in range(N)] highest = max(src) bands = highest//W + 1 hist = [0 for i in range(bands)] for i in range(N): hist[src[i] // W] += 1 ans = maxn = 0 for i,n in enumerate(hist): ans += n * (bands-1-i) maxn = max(n, maxn) print(ans * / maxn / (bands-1) + 0.01)
s330013823
p00864
u672443148
1517109438
Python
Python3
py
Runtime Error
0
0
674
from heapq import * def calcInk(wdt,val): maxval=val[-1] histnum=maxval//wdt hist=[] for i in range(histnum+1): hist.append([]) vl=len(val) for i in range(vl): v=heappop(val) hist[v//wdt].append(v) highest=0 for i in range(len(hist)): highest=max(highest,len(hist[i])) ink=0 for i in range(len(hist)): ink+=(1-i/histnum)*(len(hist[i])/highest) return ink+0.01 if __name__=='__main__': while True: n,w=map(int,input().split()) if n==w==0: break V=[] for _ in range(n): heappush(V,int(input())) print(calcInk(w,V))
s884966133
p00864
u672443148
1517109473
Python
Python3
py
Runtime Error
0
0
674
from heapq import * def calcInk(wdt,val): maxval=val[-1] histnum=maxval//wdt hist=[] for i in range(histnum+1): hist.append([]) vl=len(val) for i in range(vl): v=heappop(val) hist[v//wdt].append(v) highest=0 for i in range(len(hist)): highest=max(highest,len(hist[i])) ink=0 for i in range(len(hist)): ink+=(1-i/histnum)*(len(hist[i])/highest) return ink+0.01 if __name__=='__main__': while True: n,w=map(int,input().split()) if n==w==0: break V=[] for _ in range(n): heappush(V,int(input())) print(calcInk(w,V))
s545576882
p00864
u672443148
1517109537
Python
Python3
py
Runtime Error
0
0
673
from heapq import * def calcInk(wdt,val): maxval=val[-1] histnum=maxval//wdt hist=[] for i in range(histnum+1): hist.append([]) vl=len(val) for i in range(vl): v=heappop(val) hist[v//wdt].append(v) highest=0 for i in range(len(hist)): highest=max(highest,len(hist[i])) ink=0 for i in range(len(hist)): ink+=(1-i/histnum)*(len(hist[i])/highest) return ink+0.01 if __name__=='__main__': while True: n,w=map(int,input().split()) if n==w==0: break V=[] for _ in range(n): heappush(V,int(input())) print(calcInk(w,V))
s180167044
p00864
u672443148
1517109779
Python
Python3
py
Runtime Error
0
0
673
from heapq import * def calcInk(wdt,val): maxval=val[-1] histnum=maxval//wdt hist=[] for i in range(histnum+1): hist.append([]) vl=len(val) for i in range(vl): v=heappop(val) hist[v//wdt].append(v) highest=0 for i in range(len(hist)): highest=max(highest,len(hist[i])) ink=0 for i in range(len(hist)): ink+=(1-i/histnum)*(len(hist[i])/highest) return ink+0.01 if __name__=='__main__': while True: n,w=map(int,input().split()) if n==w==0: break V=[] for _ in range(n): heappush(V,int(input())) print(calcInk(w,V))
s265028878
p00864
u672443148
1517109986
Python
Python3
py
Runtime Error
0
0
689
from heapq import * def calcInk(wdt,val): maxval=val[-1] histnum=maxval//wdt hist=[] for i in range(histnum+1): hist.append([]) vl=len(val) for i in range(vl): v=heappop(val) hist[v//wdt].append(v) highest=0 for i in range(len(hist)): highest=max(highest,len(hist[i])) ink=0 for i in range(len(hist)): ink+=(1-i/histnum)*(len(hist[i])/highest) return ink+0.01 if __name__=='__main__': while True: n,w=map(int,input().split()) if n==w==0: break V=[] for _ in range(n): heappush(V,int(input())) INK=calcInk(w,V) print(INK)
s732539893
p00864
u672443148
1517110285
Python
Python3
py
Runtime Error
0
0
646
if __name__=='__main__': while True: n,w=map(int,input().split()) if n==w==0: break V=[] for _ in range(n): heappush(V,int(input())) maxV=V[-1] histnum=maxV//w hist=[] for i in range(histnum+1): hist.append([]) vl=len(V) for i in range(vl): v=heappop(V) hist[v//w].append(v) highest=0 for i in range(len(hist)): highest=max(highest,len(hist[i])) ink=0 for i in range(len(hist)): ink+=(1-i/histnum)*(len(hist[i])/highest) print(ink)
s512846069
p00864
u672443148
1517110764
Python
Python3
py
Runtime Error
0
0
674
from heapq import * def calcInk(wdt,val): maxval=val[-1] histnum=maxval//wdt hist=[] for i in range(histnum+1): hist.append([]) vl=len(val) for i in range(vl): v=heappop(val) hist[v//wdt].append(v) highest=0 for i in range(len(hist)): highest=max(highest,len(hist[i])) ink=0 for i in range(len(hist)): ink+=(1-i/histnum)*(len(hist[i])/highest) return ink+0.01 if __name__=='__main__': while True: n,w=map(int,input().split()) if n==w==0: break V=[] for _ in range(n): heappush(V,int(input())) print(calcInk(w,V))
s689680767
p00864
u104911888
1372855136
Python
Python
py
Runtime Error
0
0
301
while True: n,w=map(int,raw_input().split()) if n==w==0:break L=[0]*n for i in range(n): v=input() L[v/w]+=1 maxh=max(L) r=n-1 while r>0 and L[r]==0: r-=1 ink=0.01 for i in range(r+1): ink+=float(r-i)/r*float(L[i])/maxh print ink
s700808864
p00864
u104911888
1372855198
Python
Python
py
Runtime Error
0
0
305
while True: n,w=map(int,raw_input().split()) if n==w==0:break L=[0]*(n+1) for i in range(n): v=input() L[v/w]+=1 maxh=max(L) r=n-1 while r>0 and L[r]==0: r-=1 ink=0.01 for i in range(r+1): ink+=float(r-i)/r*float(L[i])/maxh print ink
s939647203
p00864
u104911888
1372855284
Python
Python
py
Runtime Error
0
0
301
while True: n,w=map(int,raw_input().split()) if n==w==0:break L=[0]*w for i in range(n): v=input() L[v/w]+=1 maxh=max(L) r=n-1 while r>0 and L[r]==0: r-=1 ink=0.01 for i in range(r+1): ink+=float(r-i)/r*float(L[i])/maxh print ink
s150956865
p00864
u104911888
1372855320
Python
Python
py
Runtime Error
0
0
305
while True: n,w=map(int,raw_input().split()) if n==w==0:break L=[0]*(w+1) for i in range(n): v=input() L[v/w]+=1 maxh=max(L) r=n-1 while r>0 and L[r]==0: r-=1 ink=0.01 for i in range(r+1): ink+=float(r-i)/r*float(L[i])/maxh print ink
s466575085
p00864
u104911888
1372855463
Python
Python
py
Runtime Error
0
0
328
while True: n,w=map(int,raw_input().split()) if n==w==0:break L=[0]*(w+1) for i in range(n): v=input() L[v/w]+=1 maxh=max(L) r=n-1 while r>0 and L[r]==0: r-=1 ink=0.01 for i in range(r+1): p=float(r-i)/r ink+=float(r-i)/r*float(L[i])/maxh print ink
s040641488
p00864
u104911888
1372855632
Python
Python
py
Runtime Error
0
0
362
while True: n,w=map(int,raw_input().split()) if n==w==0:break L=[0]*(w+1) for i in range(n): v=input() L[v/w]+=1 maxh=max(L) r=n-1 while r>0 and L[r]==0: r-=1 ink=0.01 for i in range(r+1): if r<>0: ink+=float(r-i)/r*float(L[i])/maxh else: int+=L[i] print ink
s145246727
p00864
u104911888
1372855676
Python
Python
py
Runtime Error
0
0
362
while True: n,w=map(int,raw_input().split()) if n==w==0:break L=[0]*(w+1) for i in range(n): v=input() L[v/w]+=1 maxh=max(L) r=n-1 while r>0 and L[r]==0: r-=1 ink=0.01 for i in range(r+1): if r<>0: ink+=float(r-i)/r*float(L[i])/maxh else: ink+=L[i] print ink
s038100916
p00874
u880042992
1409635286
Python
Python3
py
Runtime Error
0
0
949
#include <iostream> #include <algorithm> using namespace std; #define repeat(i,n) for (int i = 0; i < (n); ++i) #define MAX_W 10 #define MAX_D 10 int main() { while (true) { int W, D; cin >> W >> D; if (W == 0 or D == 0) break; static int HW[MAX_W], HD[MAX_D]; repeat (w,W) cin >> HW[w]; repeat (d,D) cin >> HD[d]; sort(HW,HW+W); sort(HD,HD+D); int result = 0; { int w = 0, d = 0; while (w < W and d < D) { if (HW[w] < HD[d]) { result += HW[w]; ++ w; } else if (HW[w] > HD[d]) { result += HD[d]; ++ d; } else { result += HW[w]; ++ w; ++ d; } } while (w < W) { result += HW[w]; ++ w; } while (d < D) { result += HD[d]; ++ d; } } cout << result << endl; } return 0; }
s966173340
p00875
u633068244
1424611236
Python
Python
py
Runtime Error
19930
5640
416
while 1: n = int(raw_input()) if n == 0: break ab = [raw_input().split() for i in xrange(n)] s = raw_input() g = raw_input() que = [[s,0]] while que: c,i = que.pop(0) if c == g: print i break for a,b in ab: cc = c.replace(a,b) if len(cc) > len(g): continue que.append([cc,i+1]) else: print -1
s851333172
p00875
u509278866
1529904755
Python
Python3
py
Runtime Error
0
0
2423
// C++11 #include "bits/stdc++.h" #include <sys/time.h> #include <emmintrin.h> #include <string> #include <sstream> #include <fstream> #include <random> #include <bitset> using namespace std; inline long long GetTSC() { long long lo, hi; asm volatile ("rdtsc": "=a"(lo), "=d"(hi)); return lo + (hi << 32); } inline double GetSeconds() { return GetTSC() / 2.8e9; } const long inf = pow(10,15); int di[] = {-1,0,1,0}; int dj[] = {0,1,0,-1}; tuple<int, int>q[50*50*50*50]; void solve(){ double starttime = GetSeconds(); while(1){ int w,h; cin >> w >> h; // cerr << w << ", " << h << endl; if(w==0 && h==0) break; int lp,ls,rp,rs; bool lb[2500] = {}; bool rb[2500] = {}; bool f[2500][2500] = {}; for(int i=0; i<h; i++){ string s; cin >> s; for(int j=0; j<w; j++){ if(s[j]=='#') lb[i*w+j] = 1; if(s[j]=='%') lp = i*w+j; if(s[j]=='L') ls = i*w+j; } cin >> s; for(int j=0; j<w; j++){ if(s[j]=='#') rb[i*w+j] = 1; if(s[j]=='%') rp = i*w+j; if(s[j]=='R') rs = i*w+j; } } f[ls][rs] = 1; int qi = 0; int qe = 1; q[0] = make_tuple(ls,rs); bool ff = 0; while(qi<qe){ int lt = get<0>(q[qi]); int rt = get<1>(q[qi]); int li = lt / w; int lj = lt % w; int ri = rt / w; int rj = rt % w; qi++; // cerr << "qie: " << qi << ", " << qe << ", lij: " << li << ", " << lj << ", rij: " << ri << ", " << rj << endl; for(int i=0; i<4; i++){ int nli = li + di[i]; int nlj = lj + dj[i]; int nri = ri + di[i]; int nrj = rj - dj[i]; if(nli < 0 || nli >= h || nlj < 0 || nlj >= w || lb[nli*w+nlj]){ nli = li; nlj = lj; } if(nri < 0 || nri >= h || nrj < 0 || nrj >= w || rb[nri*w+nrj]){ nri = ri; nrj = rj; } int nlt = nli*w+nlj; int nrt = nri*w+nrj; if(nlt == lp && nrt == rp){ ff = 1; break; } if(nlt == lp || nrt == rp) continue; if(f[nlt][nrt]) continue; f[nlt][nrt] = 1; q[qe++] = make_tuple(nlt,nrt); } if(ff) break; } if(ff){ cout << "Yes" << endl; }else{ cout << "No" << endl; } } // cerr << "time: " << GetSeconds() - starttime << endl; return; } int main() { solve(); return 0; }
s799826733
p00881
u844945939
1412806908
Python
Python3
py
Runtime Error
19930
73088
782
from collections import Counter while True: m, n = (int(s) for s in input().split()) if not m: break objs = [int(input(), 2) for i in range(n)] f = [[0 for i in range(1 << m)] for i in range(1 << m)] for mask in reversed(range(1<<m)): s = Counter(obj & mask for obj in objs) for mask0 in range(mask + 1): if s[mask0] > 1: f[mask][mask0] = n + 1 for b in [1<<k for k in range(m)]: if not (b & mask): f[mask][mask0] = min(f[mask][mask0], max(f[mask + b][mask0], f[mask + b][mask0 + b]) + 1 ) print(f[0][0])
s286784543
p00881
u844945939
1412937427
Python
Python3
py
Runtime Error
0
0
595
while True: m, n = (int(s) for s in input().split()) if not m: break objs = [int(input(), 2) for i in range(n)] dp = [[0] * (1<<m) for i in range(1 << m)] bits = [1 << i for i in range(m)] for mask in reversed(range(1 << m)): s = Counter(obj & mask for obj in objs) for mask0, value in s.items(): if value > 1: dp[mask][mask0] = min(max(dp[mask | b][mask0], dp[mask | b][mask0 | b]) + 1 for b in bits if not b & mask) print(dp[0][0])
s551946320
p00881
u844945939
1412937966
Python
Python
py
Runtime Error
0
0
602
while True: m, n = (int(s) for s in raw_input().split()) if not m: break objs = [int(raw_input(), 2) for i in range(n)] dp = [[0] * (1<<m) for i in range(1 << m)] bits = [1 << i for i in range(m)] for mask in reversed(range(1 << m)): s = Counter(obj & mask for obj in objs) for mask0, value in s.items(): if value > 1: dp[mask][mask0] = min(max(dp[mask | b][mask0], dp[mask | b][mask0 | b]) + 1 for b in bits if not b & mask) print dp[0][0]
s381647444
p00884
u011621222
1422508262
Python
Python3
py
Runtime Error
19930
6744
800
def get_group(str): return str.split(':')[0]; def get_member(str): return str.split(':')[1].split('.')[0].split(','); def get_num(group, map, ans): for person in map[group]: if person in map: get_num(person, map, ans); else: ans[person] = True; def main(): while True: str = input(); if len(str) == 0: continue; n = int(str); if n == 0: break; group = {}; group.clear(); name = {}; name.clear(); for i in range(0, n): str = input(); name[i] = get_group(str); group[name[i]] = get_member(str); ans = {}; ans.clear(); get_num(name[0], group, ans); print(len(ans)); main();
s944033769
p00884
u011621222
1422508879
Python
Python3
py
Runtime Error
19920
6744
842
def get_group(str): return str.split(':')[0]; def get_member(str): return str.split(':')[1].split('.')[0].split(','); def get_num(group, map, ans): for person in map[group]: if person in map: get_num(person, map, ans); else: ans[person] = True; def main(): while True: str = input(); if len(str) == 0: continue; n = int(str); if not str.isdigit(): continue; if n == 0: break; group = {}; group.clear(); name = {}; name.clear(); for i in range(0, n): str = input(); name[i] = get_group(str); group[name[i]] = get_member(str); ans = {}; ans.clear(); get_num(name[0], group, ans); print(len(ans)); main();
s873494609
p00884
u260980560
1432476398
Python
Python
py
Runtime Error
19930
4312
630
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[gs[v]].append(me[i]) return dg[gs[v]] while 1: n = input() if not n: break gs = []; ms = [] dg = {} for i in xrange(n): g, m = raw_input().split(":") gs.append(g); ms.append(m[:-1].split(",")) dg[g] = [] dfs(dg, gs, ms, 0) print len(dg[gs[0]])
s534619500
p00884
u063091489
1432705528
Python
Python3
py
Runtime Error
0
0
608
from django.template.defaultfilters import first while True: N = int(input()) if N == 0: break first_group_menbers = set(input()[:-1].split(":")[1].split(",")) d = {} for i in range(N-1): group, members = input()[:-1].split(":") d[group] = set(members.split(",")) for i in range(N): for group, members in d.items(): if group in first_group_menbers: first_group_menbers.remove(group) for m in members: first_group_menbers.add(m) print(len(first_group_menbers))
s466970026
p00884
u063091489
1432705574
Python
Python3
py
Runtime Error
0
0
608
from django.template.defaultfilters import first while True: N = int(input()) if N == 0: break first_group_menbers = set(input()[:-1].split(":")[1].split(",")) d = {} for i in range(N-1): group, members = input()[:-1].split(":") d[group] = set(members.split(",")) for i in range(N): for group, members in d.items(): if group in first_group_menbers: first_group_menbers.remove(group) for m in members: first_group_menbers.add(m) print(len(first_group_menbers))
s618540673
p00884
u633068244
1399614097
Python
Python
py
Runtime Error
0
0
416
while 1: n = input() if n == 0: break ans = {} for i in range(n): group,name = raw_input().split(":") if i == 0: first = group ans[group] = set(name[:-1].split(",")) while 1: for key in ans: for key1 in ans: if key in ans[key1]: ans[key1] |= ans[key] ans[key1].discard(key) del ans[key] break if key not in ans: break else: break print len(ans[first])
s293547529
p00884
u633068244
1399614136
Python
Python
py
Runtime Error
0
0
416
while 1: n = input() if n == 0: break ans = {} for i in range(n): group,name = raw_input().split(":") if i == 0: first = group ans[group] = set(name[:-1].split(",")) while 1: for key in ans: for key1 in ans: if key in ans[key1]: ans[key1] |= ans[key] ans[key1].discard(key) del ans[key] break if key not in ans: break else: break print len(ans[first])
s026741598
p00884
u633068244
1399614371
Python
Python
py
Runtime Error
0
0
434
while 1: n = input() if n == 0: break ans = {} for i in range(n): group,name = raw_input().split(":") if i == 0: first = group ans[group] = set(name[:-1].split(",")) while 1: for key in ans: for key1 in ans: if key in ans[key1]: ans[key1] |= ans[key] ans[key1].discard(key) del ans[key] first = key break if key not in ans: break else: break print len(ans[first])