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
s759687004
p00064
u350064373
1501550344
Python
Python3
py
Runtime Error
0
0
209
import re try: ls = num = [] result = 0 while True: ls.append(input()) except: for i in ls: for s in range(re.findall(r'\d+', i)): result += int(s) print(result)
s773401650
p00064
u724606305
1513743520
Python
Python3
py
Runtime Error
0
0
242
ans = "" while True: try: memo = input() except: break for m in memo: if m.isdigit()==True: ans = ans+m else: ans = ans+"???" ans=ans.split() ans=sum(map(int,ans)) print(ans)
s445368454
p00064
u471115210
1374738366
Python
Python
py
Runtime Error
0
0
556
#include<iostream> #include<algorithm> #include<queue> #include<map> #include<string.h> #include<math.h> using namespace std; int main(){ string in; int num=0; while(cin>>in){ bool flag=false; int temp = 0; for(int i=0; i<in.length(); i++){ if('0'<=in[i]&&in[i]<='9'){ temp=temp*10+(in[i]-'0'); flag=true; }else if (flag==true){ num+=temp; temp=0; flag=false; } } } cout<<num<<endl; }
s528257667
p00064
u865312527
1378313698
Python
Python
py
Runtime Error
0
0
75
import re print sum(map(int,re.sub("\w+"," ",raw_input()).strip().split()))
s703828572
p00064
u865312527
1378313826
Python
Python
py
Runtime Error
0
0
94
import re, sys print sum(map(int,re.sub("\w+|\s+"," ",sys.stdin.readlines()).strip().split()))
s082088469
p00064
u865312527
1378313919
Python
Python
py
Runtime Error
0
0
93
import re, sys print sum(map(int,re.sub("[^\d]+"," ",sys.stdin.readlines()).strip().split()))
s709045297
p00064
u912237403
1389971803
Python
Python
py
Runtime Error
0
0
90
s="".join([s for s in sys.stdin]) p=re.compile('\d+') x=p.findall(s) print sum(map(int,x))
s194814412
p00064
u912237403
1389993145
Python
Python
py
Runtime Error
0
0
263
#include <iostream> #include <string> int main(){ std::string s,x=""; while(std::cin>>s)x+=s; s=""; int a=0,i=0; for (;i<(int)x.size();i++) if (isdigit(x[i])) s+=x[i]; else if (!s.empty()){ a+=atoi(s.c_str()); s=""; } std::cout<<a<<"\n"; }
s312990584
p00065
u537067968
1551598525
Python
Python3
py
Runtime Error
0
0
483
#import math listc = [] listd = {} answer = [] n = 0 while True: s = input() if not s: break else: n += 1 c,d = map(int,s.split(',')) if c in listc: listd[c] += 1 else: listc.append(c) listd[c] = 1 while n > 0: n -= 1 c,d = map(int,input().split(',')) if c in listc: if not c in answer: answer.append(c) listd[c] += 1 answer.sort() for i in answer: print(i,listd[i])
s670717915
p00065
u193025715
1408890427
Python
Python3
py
Runtime Error
0
0
400
old = [] new = [] ans = [] t = True while True: n = input().split(',')[0] if n == '': if t: t = False else: break if t: old.append(n) else: new.append(n) for o in set(old): if o in new: s = old.count(o) + new.count(o) ans.append([int(o), int(s)]) ans.sort() for a in ans: print('%d %d' % (a[0], a[1]))
s130270805
p00065
u489809100
1446204102
Python
Python
py
Runtime Error
0
0
456
dict1 = {} dict2 = {} while True: str = raw_input().split(",") if len(str[0]) == 0: break if dict1.has_key(str[0]): dict1[str[0]] = dict1[str[0]] + 1 else: dict1[str[0]] = 1 while True: str = raw_input().split(",") if len(str[0]) == 0: break if dict2.has_key(str[0]): dict2[str[0]] = dict2[str[0]] + 1 else: dict2[str[0]] = 1 list = dict2.keys() for var in list: dict1[var] = dict1[var] + dict2[var] print var, dict1[var]
s620539317
p00065
u489809100
1446205356
Python
Python
py
Runtime Error
0
0
472
dict1 = {} dict2 = {} while True: str = raw_input().split(",") if len(str[0]) == 0: break if dict1.has_key(str[0]): dict1[str[0]] = dict1[str[0]] + 1 else: dict1[str[0]] = 1 while True: str = raw_input().split(",") if len(str[0]) == 0: break if dict2.has_key(str[0]): dict2[str[0]] = dict2[str[0]] + 1 else: dict2[str[0]] = 1 list = sorted(dict2, reverse = True) for var in list: dict1[var] = dict1[var] + dict2[var] print var, dict1[var]
s713411525
p00065
u489809100
1446205793
Python
Python
py
Runtime Error
0
0
472
dict1 = {} dict2 = {} while True: str = raw_input().split(",") if len(str[0]) == 0: break if dict1.has_key(str[0]): dict1[str[0]] = dict1[str[0]] + 1 else: dict1[str[0]] = 1 while True: try: str = raw_input().split(",") if dict2.has_key(str[0]): dict2[str[0]] = dict2[str[0]] + 1 else: dict2[str[0]] = 1 except: break list = sorted(dict2, reverse = True) for var in list: dict1[var] = dict1[var] + dict2[var] print var, dict1[var]
s999070412
p00065
u489809100
1446207109
Python
Python
py
Runtime Error
0
0
508
dict1 = {} dict2 = {} while True: str = raw_input() if len(str[0]) == 0: break str.split(",") if dict1.has_key(str[0]): dict1[str[0]] = dict1[str[0]] + 1 else: dict1[str[0]] = 1 while True: try: str = raw_input().split(",") if dict2.has_key(str[0]): dict2[str[0]] = dict2[str[0]] + 1 else: dict2[str[0]] = 1 except: break list = sorted(set(dict1)&set(dict2), reverse = True) for var in list: if(dict1[var] > 0 and dict2[var] > 0): print var, dict1[var] + dict2[var]
s259250933
p00065
u489809100
1446387528
Python
Python
py
Runtime Error
0
0
475
dict1 = {} dict2 = {} while True: log = raw_input() if len(log) == 0: break log = log.split(",")[0] if log in dict1: dict1[log] = dict1[log] + 1 else: dict1[log] = 1 while True: try: log = raw_input() log = log.split(",")[0] if log in dict2: dict2[log] = dict2[log] + 1 else: dict2[log] = 1 except EOFError: break list = dict1.keys() for var in list: if dict1[var] > 0 and dict2[var] > 0: print var, dict1[var] + dict2[var]
s545583108
p00065
u661290476
1484473327
Python
Python3
py
Runtime Error
0
0
358
flag = False cli = [0] * 1000 sen = set() kon = set() while True: try: c, d = map(int, input().split(",")) except: if flag: break flag = True continue if flag: kon.add(c) else: sen.add(c) cli[c] += 1 for i in range(1,1001): if i in sen and i in kon: print(i,cli[i])
s707966913
p00065
u546285759
1491996343
Python
Python3
py
Runtime Error
0
0
378
dt = {} def loop(): while True: line = input() if line == '': break try: c, d = map(int, line.split(',')) dt[c] = [d] if c not in dt else dt[c]+[d] except: break loop() loop() for ab in sorted(dt.items(), key=lambda x: x[0]): a, b = ab[0], ab[1] if len(b) > 1: print(a, len(b))
s284399112
p00065
u546285759
1491996457
Python
Python3
py
Runtime Error
0
0
380
dt = {} def loop(): while True: line = input() if line == '\n': break try: c, d = map(int, line.split(',')) dt[c] = [d] if c not in dt else dt[c]+[d] except: break loop() loop() for ab in sorted(dt.items(), key=lambda x: x[0]): a, b = ab[0], ab[1] if len(b) > 1: print(a, len(b))
s885995716
p00065
u150984829
1519391044
Python
Python3
py
Runtime Error
0
0
190
import sys b=0 a=[{},{}] for e in sys.stdin: if'\n'==e:b=1 else:c=int(e.split(',')[0]) if c in a[b]:a[b][c]+=1 else:a[b][c]=1 for k in sorted({*a[0]}&{*a[1]}):print(k,a[0][k]+a[1][k])
s247578694
p00065
u150984829
1519391131
Python
Python3
py
Runtime Error
0
0
180
import sys b=0 a=[{},{}] for e in sys.stdin: if'\n'==e:b=1 else:c=int(e.split(',')[0]);a[b][c]=1+[0,a[b][c]][c in a[b]] for k in sorted({*a[0]}&{*a[1]}):print(k,a[0][k]+a[1][k])
s545753386
p00065
u150984829
1519391542
Python
Python3
py
Runtime Error
0
0
181
import sys b=0 a=[{},{}] for e in sys.stdin: if'\n'==e:b=1 else:c_=e.split(',');c=int(c);a[b].setdefault(c,0);a[b][c]+=1 for k in sorted({*a[0]}&{*a[1]}):print(k,a[0][k]+a[1][k])
s096815864
p00065
u912237403
1390000001
Python
Python
py
Runtime Error
0
0
255
import sys C=range(1000) f=0 d=[[0 for i in C] for j in range(2)] for s in sys.stdin.readlines(): if s=="\n":f+=1 else: a,b=map(int,s.split(',')) d[f][a]+=1 for i in C: a=d[0][i] b=d[1][i] if a!=0 and b!=0: print i, a+b
s827520448
p00065
u912237403
1390000223
Python
Python
py
Runtime Error
0
0
253
import sys C=range(1000) m=0 d=[[0 for i in C] for j in range(2)] for s in sys.stdin.readlines(): if s=="\n":m+=1 else: a,b=map(int,s.split(',')) d[m][a]+=1 for i in C: a=d[0][i] b=d[1][i] if a!=0 and b!=0:print i,a+b
s882419932
p00065
u491763171
1400472384
Python
Python
py
Runtime Error
0
0
325
from collections import Counter cnt = 0 trade = Counter() while 1: line = raw_input() if not line: break cnt += 1 a, b = map(int, line.split(',')) trade[a] += 1 for i in xrange(cnt): a, b = map(int, raw_input().split(',')) trade[a] += 1 for k, v in sorted(trade.items()): print k, v
s282729449
p00066
u647694976
1558944166
Python
Python3
py
Runtime Error
0
0
292
def marubatu(): N=list(input()) for koma in ["o","x"]: for i in range(3): if N[i:9:3].count(koma)==3 or N[3*i:3*i+3].count(koma)==3:return koma if N[0:9:4].count(koma)==3 or N[2:7:2].count(koma)==3:return koma return "d" while 1: print(marubatu())
s099537838
p00066
u567380442
1423130945
Python
Python3
py
Runtime Error
0
0
285
import sys f = sys.stdin vlines = [[0,1,2],[3,4,5],[6,7,8],[0,3,6],[1,4,7],[2,5,8],[0,4,8],[2,4,6]] for line in f: result = 'd' for v in vlines: if 's' != a and line[v[0]]== line[v[1]] == line[v[2]]: result = line[v[0]] break print(result)
s070590442
p00066
u661290476
1484478702
Python
Python3
py
Runtime Error
0
0
561
ok = [[0,4,8], [2,4,6], [0,1,2], [3,4,5], [6,7,8], [0,3,6], [1,4,7], [2,5,8]] while True: s = input() if len(s) == 0: break maru = [] batu = [] for i in range(9): if s[i] == 'o': maru.append(i) elif s[i] == 'x': batu.append(i) print(maru, batu) flag = False for i in ok: if i == maru: print("o") flag = True break elif i ==batu: print("x") flag = True break if not flag: print("d")
s375226972
p00066
u661290476
1484478793
Python
Python3
py
Runtime Error
0
0
539
ok = [[0,4,8], [2,4,6], [0,1,2], [3,4,5], [6,7,8], [0,3,6], [1,4,7], [2,5,8]] while True: s = input() if len(s) == 0: break maru = [] batu = [] for i in range(9): if s[i] == 'o': maru.append(i) elif s[i] == 'x': batu.append(i) flag = False for i in ok: if i == maru: print("o") flag = True break elif i ==batu: print("x") flag = True break if not flag: print("d")
s057371703
p00066
u661290476
1484478889
Python
Python3
py
Runtime Error
0
0
548
ok = [[0,4,8], [2,4,6], [0,1,2], [3,4,5], [6,7,8], [0,3,6], [1,4,7], [2,5,8]] while True: s = input() if len(s) == 0: break maru = [] batu = [] for i in range(9): if s[i] == 'o': maru.append(i) elif s[i] == 'x': batu.append(i) flag = False for i in ok: if i == maru: print("o") flag = True break elif i ==batu: print("x") flag = True break if flag: continue print("d")
s168091562
p00066
u661290476
1484480017
Python
Python3
py
Runtime Error
0
0
567
ok = [{0,4,8}, {2,4,6}, {0,1,2}, {3,4,5}, {6,7,8}, {0,3,6}, {1,4,7}, {2,5,8}] while True: s = input() if len(s) == 0: break maru = set() batu = set() for i in range(9): if s[i] == 'o': maru.add(i) elif s[i] == 'x': batu.add(i) flag = False for i in ok: if len(i - maru) == 0: print("o") flag = True break elif len(i - batu) == 0: print("x") flag = True break if flag: continue print("d")
s039830187
p00066
u661290476
1484480461
Python
Python3
py
Runtime Error
0
0
311
ok = [[0,4,8], [2,4,6], [0,1,2], [3,4,5], [6,7,8], [0,3,6], [1,4,7], [2,5,8]] while True: s = input() if len(s) == 0: break flag = False for i in ok: if s[i[0]] == s[i[1]] == s[i[2]]: print(s[i[0]]) flag = True if flag: continue print("d")
s310296365
p00066
u661290476
1484480761
Python
Python3
py
Runtime Error
0
0
329
ok = [[0,4,8], [2,4,6], [0,1,2], [3,4,5], [6,7,8], [0,3,6], [1,4,7], [2,5,8]] while True: s = input() if len(s) == 0: break flag = False for i in ok: if s[i[0]] == s[i[1]] == s[i[2]]: print(s[i[0]]) flag = True break if flag: continue print("d")
s968137324
p00066
u661290476
1484480989
Python
Python3
py
Runtime Error
0
0
348
ok = [[0,4,8], [2,4,6], [0,1,2], [3,4,5], [6,7,8], [0,3,6], [1,4,7], [2,5,8]] while True: s = input() if len(s) == 0: break flag = False for i in ok: if s[i[0]] == s[i[1]] == s[i[2]] and s[i[0]] != 's': print(s[i[0]]) flag = True break if flag: continue print("d")
s712616891
p00066
u661290476
1484481241
Python
Python3
py
Runtime Error
0
0
348
ok = [[0,4,8], [2,4,6], [0,1,2], [3,4,5], [6,7,8], [0,3,6], [1,4,7], [2,5,8]] while True: s = input() if len(s) == 0: break flag = False for i in ok: if s[i[0]] == s[i[1]] == s[i[2]] and s[i[0]] != 's': print(s[i[0]]) flag = True break if flag: continue print("d")
s951007491
p00066
u484327129
1518911626
Python
Python3
py
Runtime Error
0
0
1231
import sys board = [] board_list = [] result = [] while 1: line = input() if not line == "": board.append(x) else: break def check(num): if board_list[num][0] == board_list[num][1] == board_list[num][2]: if board_list[num][0] == 'o': return 'o' elif board_list[num][0] == 'x': return 'x' if board_list[0][num] == board_list[1][num] == board_list[2][num]: if board_list[0][num] == 'o': return 'o' elif board_list[0][num] == 'x': return 'x' if board_list[0][0] == board_list[1][1] == board_list[2][2]: if board_list[0][0] == 'o': return 'o' elif board_list[0][0] == 'x': return 'x' if board_list[0][2] == board_list[1][1] == board_list[2][0]: if board_list[0][0] == 'o': return 'o' elif board_list[0][0] == 'x': return 'x' return'd' for i in board: board_list = [(a + b + c) for (a, b, c) in zip(i[::3], i[1::3], i[2::3])] for j in range(3): if check(j) != "d": result.append(check(j)) break elif j == 2: result.append(check(j)) for i in result: print(i)
s542407341
p00066
u484327129
1518911686
Python
Python3
py
Runtime Error
0
0
1258
import sys board = [] board_list = [] result = [] while 1: line = input() if not line == "": board.append(x) else: break except EOFError: pass def check(num): if board_list[num][0] == board_list[num][1] == board_list[num][2]: if board_list[num][0] == 'o': return 'o' elif board_list[num][0] == 'x': return 'x' if board_list[0][num] == board_list[1][num] == board_list[2][num]: if board_list[0][num] == 'o': return 'o' elif board_list[0][num] == 'x': return 'x' if board_list[0][0] == board_list[1][1] == board_list[2][2]: if board_list[0][0] == 'o': return 'o' elif board_list[0][0] == 'x': return 'x' if board_list[0][2] == board_list[1][1] == board_list[2][0]: if board_list[0][0] == 'o': return 'o' elif board_list[0][0] == 'x': return 'x' return'd' for i in board: board_list = [(a + b + c) for (a, b, c) in zip(i[::3], i[1::3], i[2::3])] for j in range(3): if check(j) != "d": result.append(check(j)) break elif j == 2: result.append(check(j)) for i in result: print(i)
s084165865
p00066
u484327129
1518911751
Python
Python3
py
Runtime Error
0
0
1286
import sys board = [] board_list = [] result = [] try: while 1: line = input() if not line == "": board.append(x) else: break except EOFError: pass def check(num): if board_list[num][0] == board_list[num][1] == board_list[num][2]: if board_list[num][0] == 'o': return 'o' elif board_list[num][0] == 'x': return 'x' if board_list[0][num] == board_list[1][num] == board_list[2][num]: if board_list[0][num] == 'o': return 'o' elif board_list[0][num] == 'x': return 'x' if board_list[0][0] == board_list[1][1] == board_list[2][2]: if board_list[0][0] == 'o': return 'o' elif board_list[0][0] == 'x': return 'x' if board_list[0][2] == board_list[1][1] == board_list[2][0]: if board_list[0][0] == 'o': return 'o' elif board_list[0][0] == 'x': return 'x' return'd' for i in board: board_list = [(a + b + c) for (a, b, c) in zip(i[::3], i[1::3], i[2::3])] for j in range(3): if check(j) != "d": result.append(check(j)) break elif j == 2: result.append(check(j)) for i in result: print(i)
s669382530
p00066
u484327129
1518911758
Python
Python3
py
Runtime Error
0
0
1286
import sys board = [] board_list = [] result = [] try: while 1: line = input() if not line == "": board.append(x) else: break except EOFError: pass def check(num): if board_list[num][0] == board_list[num][1] == board_list[num][2]: if board_list[num][0] == 'o': return 'o' elif board_list[num][0] == 'x': return 'x' if board_list[0][num] == board_list[1][num] == board_list[2][num]: if board_list[0][num] == 'o': return 'o' elif board_list[0][num] == 'x': return 'x' if board_list[0][0] == board_list[1][1] == board_list[2][2]: if board_list[0][0] == 'o': return 'o' elif board_list[0][0] == 'x': return 'x' if board_list[0][2] == board_list[1][1] == board_list[2][0]: if board_list[0][0] == 'o': return 'o' elif board_list[0][0] == 'x': return 'x' return'd' for i in board: board_list = [(a + b + c) for (a, b, c) in zip(i[::3], i[1::3], i[2::3])] for j in range(3): if check(j) != "d": result.append(check(j)) break elif j == 2: result.append(check(j)) for i in result: print(i)
s559180362
p00066
u293019826
1530669684
Python
Python3
py
Runtime Error
0
0
500
d=0 while True: d+=1 if d==51: break s=str(input()) if s[0]==s[1]==s[2] and s[0] != "s": print(s[0]) elif s[3]==s[4]==s[5] and s[3] != "s": print(s[3]) elif s[6]==s[7]==s[8] and s[6] != "s": print(s[6]) elif s[0]==s[4]==s[8] and s[0] != "s": print(s[0]) elif s[2]==s[4]==s[6] and s[2] != "s": print(s[2]) elif s[0]==s[3]==s[6] and s[0] != "s": print(s[0]) elif s[1]==s[4]==s[7] and s[1] != "s": print(s[1]) elif s[2]==s[5]==s[8] and s[2] != "s": print(s[2]) else: print("d")
s725179476
p00066
u633068244
1393694210
Python
Python
py
Runtime Error
0
0
433
ls = ["o","x"] while True: try: a = raw_input() for c in ls if a[::4] == c*3 or a[2:8:2] == c*3: print c else: for i in range(3): if a[3*i:3*(i+1)] == c*3 or a[i::3] == c*3: print c break elif i == 2: print "d" except: break
s853637698
p00067
u266872031
1427645943
Python
Python
py
Runtime Error
0
0
731
def isearch(field,dir1,dir2,I,J,Q): field[I][J]=0 for d in dir1: if field[min(11,I+d[0])][min(11,J+d[1])]: Q.append([I+d[0],J+d[1]]) for d in dir2: if field[max(0,I+d[0])][max(0,J+d[1])]: Q.append([I+d[0],J+d[1]]) if len(Q)!=0: [i,j]=Q.pop(0) isearch(field,dir1,dir2,i,j,Q) while(1): field=[] for i in range(12): field.append([int(x) for x in raw_input()]) Q=[] N=0 dir1=[[0,1],[1,0]] dir2=[[0,-1],[-1,0]] for i in range(12): for j in range(12): if field[i][j]: N=N+1 isearch(field,dir1,dir2,i,j,Q) print N try: raw_input() except: break
s186879297
p00067
u266872031
1427646044
Python
Python
py
Runtime Error
0
0
736
def isearch(field,dir1,dir2,I,J,Q): field[I][J]=0 for d in dir1: if field[min(11,I+d[0])][min(11,J+d[1])]: Q.append([I+d[0],J+d[1]]) for d in dir2: if field[max(0,I+d[0])][max(0,J+d[1])]: Q.append([I+d[0],J+d[1]]) if len(Q)!=0: [i,j]=Q.pop(0) isearch(field,dir1,dir2,i,j,Q) while(1): field=[] for i in range(12): field.append([int(x) for x in raw_input()]) Q=[] N=0 dir1=[[0,1],[1,0]] dir2=[[0,-1],[-1,0]] for i in range(12): for j in range(12): if field[i][j]: N=N+1 isearch(field,dir1,dir2,i,j,Q) print N try: skip=raw_input() except: break
s847225643
p00067
u176428250
1433661885
Python
Python
py
Runtime Error
0
0
608
import sys sys.setrecursionlimit(10000000) M, N = map(int, raw_input().split()) field = [[0] * (M + 2)] for i in range(N): row = [0] row.extend(map(int, raw_input().split())) row.append(0) field.append(row) field.append([0] * (M + 2)) def search(row, column): global field if field[row][column] == 0: return 0 field[row][column] = 0 search(row - 1, column) search(row + 1, column) search(row, column + 1) search(row, column - 1) return 1 ans = 0 for row in range(N): for column in range(M): ans += search(row + 1, column + 1) print ans
s380686097
p00067
u873482706
1434940092
Python
Python
py
Runtime Error
0
0
957
import sys def quartet(h, w): global flag if 0 <= h <= 11 and 0 <= w <= 11: if mapp[h][w] == '1': mapp[h][w] = '$' flag = True bigbang(h, w) elif mapp[h][w] == '0' or mapp[h][w] == '$': return else: return def bigbang(h, w): quartet(h, w+1) quartet(h-1,w) quartet(h, w-1) quartet(h+1, w) while True: try: mapp = [] for line in sys.stdin: lis = [] for char in line.rstrip(): lis.append(char) else: mapp.append(lis) flag = False count = 0 for h in range(12): for w in range(12): quartet(h, w) if flag == True: count += 1 flag = False else: print count if raw_input == '': continue except EOFError: break
s257019218
p00067
u873482706
1434940154
Python
Python
py
Runtime Error
0
0
984
import sys def quartet(h, w): global flag if 0 <= h <= 11 and 0 <= w <= 11: if mapp[h][w] == '1': mapp[h][w] = '$' flag = True bigbang(h, w) elif mapp[h][w] == '0' or mapp[h][w] == '$': return else: return def bigbang(h, w): quartet(h, w+1) quartet(h-1,w) quartet(h, w-1) quartet(h+1, w) while True: try: mapp = [] for i in range(12): line = raw_input() lis = [] for char in line: lis.append(char) else: mapp.append(lis) flag = False count = 0 for h in range(12): for w in range(12): quartet(h, w) if flag == True: count += 1 flag = False else: print count if raw_input == '': continue except EOFError: break
s003322971
p00067
u087002048
1482051663
Python
Python3
py
Runtime Error
0
0
1340
class Depth_First_Search_stack: def __init__(self, map): self.map = map self.num_island = 0 self.stack = [] self.start_point = None def get_start_point(self): get_start = False for i in range(12): for j in range(12): if self.map[i][j] == '1': self.start_point = [i, j] get_start = True return get_start def check(self, new_r, new_c): return 0<=new_r<12 and 0<=new_c<12 and self.map[new_r][new_c] == '1' def search(self, r, c): while self.stack: r, c = self.stack.pop() self.map[r][c] = '0' for (i, j) in [[1, 0], [0, 1], [-1, 0], [0, -1]]: if self.check(r+i, c+j): self.stack.append([r+i, c+j]) def run(self): while self.get_start_point(): r, c = self.start_point self.stack.append([r, c]) self.search(r, c) self.num_island += 1 if __name__ == '__main__': while 1: map = [] for i in range(12): row = [x for x in input()] map.append(row) if len(map[0]) != 12: break DFS = Depth_First_Search_stack(map) DFS.run() print(DFS.num_island) empty = input()
s816876003
p00067
u087002048
1482051843
Python
Python3
py
Runtime Error
0
0
1476
class Depth_First_Search_stack: def __init__(self, map): self.map = map self.num_island = 0 self.stack = [] self.start_point = None def get_start_point(self): get_start = False for i in range(12): for j in range(12): if self.map[i][j] == '1': self.start_point = [i, j] get_start = True return get_start def check(self, new_r, new_c): return 0<=new_r<12 and 0<=new_c<12 and self.map[new_r][new_c] == '1' def search(self, r, c): while self.stack: r, c = self.stack.pop() self.map[r][c] = '0' for (i, j) in [[1, 0], [0, 1], [-1, 0], [0, -1]]: if self.check(r+i, c+j): self.stack.append([r+i, c+j]) def run(self): while self.get_start_point(): r, c = self.start_point self.stack.append([r, c]) self.search(r, c) self.num_island += 1 if __name__ == '__main__': while 1: stop_flag = False map = [] for i in range(12): row = [x for x in input()] if i==0: if len(row) != 12: stop_flag = True break map.append(row) if stop_flag: break DFS = Depth_First_Search_stack(map) DFS.run() print(DFS.num_island) empty = input()
s123953638
p00067
u087002048
1482051934
Python
Python3
py
Runtime Error
0
0
1487
class Depth_First_Search_stack: def __init__(self, map): self.map = map self.num_island = 0 self.stack = [] self.start_point = None def get_start_point(self): get_start = False for i in range(12): for j in range(12): if self.map[i][j] == '1': self.start_point = [i, j] get_start = True return get_start def check(self, new_r, new_c): return 0<=new_r<12 and 0<=new_c<12 and self.map[new_r][new_c] == '1' def search(self, r, c): while self.stack: r, c = self.stack.pop() self.map[r][c] = '0' for (i, j) in [[1, 0], [0, 1], [-1, 0], [0, -1]]: if self.check(r+i, c+j): self.stack.append([r+i, c+j]) def run(self): while self.get_start_point(): r, c = self.start_point self.stack.append([r, c]) self.search(r, c) self.num_island += 1 if __name__ == '__main__': for t in range(20): stop_flag = False map = [] for i in range(12): row = [x for x in input()] if i==0: if len(row) != 12: stop_flag = True break map.append(row) if stop_flag: break DFS = Depth_First_Search_stack(map) DFS.run() print(DFS.num_island) empty = input()
s080202026
p00067
u087002048
1482052200
Python
Python3
py
Runtime Error
0
0
1487
class Depth_First_Search_stack: def __init__(self, map): self.map = map self.num_island = 0 self.stack = [] self.start_point = None def get_start_point(self): get_start = False for i in range(12): for j in range(12): if self.map[i][j] == '1': self.start_point = [i, j] get_start = True return get_start def check(self, new_r, new_c): return 0<=new_r<12 and 0<=new_c<12 and self.map[new_r][new_c] == '1' def search(self, r, c): while self.stack: r, c = self.stack.pop() self.map[r][c] = '0' for (i, j) in [[1, 0], [0, 1], [-1, 0], [0, -1]]: if self.check(r+i, c+j): self.stack.append([r+i, c+j]) def run(self): while self.get_start_point(): r, c = self.start_point self.stack.append([r, c]) self.search(r, c) self.num_island += 1 if __name__ == '__main__': for t in range(20): stop_flag = False map = [] for i in range(12): row = [x for x in input()] if i==0: if len(row) != 12: stop_flag = True break map.append(row) if stop_flag: break DFS = Depth_First_Search_stack(map) DFS.run() print(DFS.num_island) empty = input()
s416351115
p00067
u087002048
1482052777
Python
Python3
py
Runtime Error
0
0
1549
class Depth_First_Search_stack: def __init__(self, map): self.map = map self.num_island = 0 self.stack = [] self.start_point = None def get_start_point(self): get_start = False for i in range(12): for j in range(12): if self.map[i][j] == '1': self.start_point = [i, j] get_start = True return get_start def check(self, new_r, new_c): if not(0<=new_r<12 and 0<=new_c<12): return False else: return self.map[new_r][new_c] == '1' def search(self, r, c): self.stack.append(self.start_point) while self.stack: r, c = self.stack.pop() self.map[r][c] = '0' for (i, j) in [[1, 0], [0, 1], [-1, 0], [0, -1]]: if self.check(r+i, c+j): self.stack.append([r+i, c+j]) def run(self): while self.get_start_point(): r, c = self.start_point self.search(r, c) self.num_island += 1 if __name__ == '__main__': for t in range(20): stop_flag = False map = [] for i in range(12): row = [x for x in input()] if i==0: if len(row) != 12: stop_flag = True break map.append(row) if stop_flag: break DFS = Depth_First_Search_stack(map) DFS.run() print(DFS.num_island) empty = input()
s413056961
p00067
u661290476
1484497891
Python
Python3
py
Runtime Error
0
0
728
mx = [0, 1, 0, -1] my = [-1, 0, 1, 0] while True: try: board = [[int(i) for i in input()] for j in range(12)] except: break cnt = 0 for y in range(12): for x in range(12): if board[y][x] == 1: cnt += 1 q = [(y, x)] while len(q) > 0: new_q = [] for yy, xx in q: board[yy][xx] = 0 for i in range(4): nx, ny = xx + mx[i], yy + my[i] if 0 <= nx < 12 and 0 <= ny < 12 and board[ny][nx]: new_q.append((ny, nx)) q = new_q print(cnt)
s758898354
p00067
u661290476
1484497914
Python
Python3
py
Runtime Error
0
0
737
mx = [0, 1, 0, -1] my = [-1, 0, 1, 0] while True: try: board = [[int(i) for i in input()] for j in range(12)] except EOFError: break cnt = 0 for y in range(12): for x in range(12): if board[y][x] == 1: cnt += 1 q = [(y, x)] while len(q) > 0: new_q = [] for yy, xx in q: board[yy][xx] = 0 for i in range(4): nx, ny = xx + mx[i], yy + my[i] if 0 <= nx < 12 and 0 <= ny < 12 and board[ny][nx]: new_q.append((ny, nx)) q = new_q print(cnt)
s850835773
p00067
u661290476
1484498246
Python
Python3
py
Runtime Error
0
0
801
mx = [0, 1, 0, -1] my = [-1, 0, 1, 0] while True: try: board = [[int(i) for i in input()] for j in range(12)] cnt = 0 for y in range(12): for x in range(12): if board[y][x] == 1: cnt += 1 q = [(y, x)] while len(q) > 0: new_q = [] for yy, xx in q: board[yy][xx] = 0 for i in range(4): nx, ny = xx + mx[i], yy + my[i] if 0 <= nx < 12 and 0 <= ny < 12 and board[ny][nx]: new_q.append((ny, nx)) q = new_q print(cnt) except EOFError: break
s179717416
p00067
u661290476
1484498610
Python
Python3
py
Runtime Error
0
0
753
mx = [0, 1, 0, -1] my = [-1, 0, 1, 0] while True: try: board = [[int(i) for i in input()] for j in range(12)] except EOFError: break cnt = 0 for y in range(12): for x in range(12): if board[y][x] == 1: cnt += 1 q = [(y, x)] while len(q) > 0: new_q = [] for yy, xx in q: board[yy][xx] = 0 for i in range(4): nx, ny = xx + mx[i], yy + my[i] if 0 <= nx < 12 and 0 <= ny < 12 and board[ny][nx]: new_q.append((ny, nx)) q = new_q print(cnt) input()
s969746033
p00067
u661290476
1484499287
Python
Python3
py
Runtime Error
0
0
774
mx = [0, 1, 0, -1] my = [-1, 0, 1, 0] while True: try: board = [[int(i) for i in input()] for j in range(12)] except EOFError: break cnt = 0 for y in range(12): for x in range(12): if board[y][x] == 1: cnt += 1 q = [(y, x)] while len(q) > 0: new_q = [] for yy, xx in q: board[yy][xx] = 0 for i in range(4): nx, ny = xx + mx[i], yy + my[i] if 0 <= nx < 12 and 0 <= ny < 12 and board[ny][nx] and (ny, nx) not in new_q: new_q.append((ny, nx)) q = new_q print(cnt) input()
s205439834
p00067
u227162786
1490005063
Python
Python3
py
Runtime Error
0
0
593
def dfs(i, j, m): ''' m[i][j]??¨????????£??????????????°???????????????????????? ''' m[i][j] = 0 for di, dj in [(-1, 0), (1, 0), (0, -1), (0, 1)]: ni = i + di nj = j + dj if ni in range(12) and nj in range(12) and m[ni][nj] == 1: dfs(ni, nj, m) while True: m = [] for i in range(12): m.append(list(map(int, list(input())))) count = 0 for i in range(12): for j in range(12): if m[i][j] == 1: count += 1 dfs(i, j, m) print(count)
s029238061
p00067
u227162786
1490005134
Python
Python3
py
Runtime Error
0
0
605
def dfs(i, j, m): ''' m[i][j]??¨????????£??????????????°???????????????????????? ''' m[i][j] = 0 for di, dj in [(-1, 0), (1, 0), (0, -1), (0, 1)]: ni = i + di nj = j + dj if ni in range(12) and nj in range(12) and m[ni][nj] == 1: dfs(ni, nj, m) while True: m = [] for i in range(12): m.append(list(map(int, list(input())))) count = 0 for i in range(12): for j in range(12): if m[i][j] == 1: count += 1 dfs(i, j, m) print(count) input()
s493705834
p00067
u510797278
1504495822
Python
Python3
py
Runtime Error
0
0
824
dx = [0, 0, -1, 1] dy = [1, -1, 0, 0] def main(): while True: map = [] count = 0 try: for i in range(12): map.append([x for x in input()]) for i in range(12): for j in range(12): if map[i][j] == '1': dfs(map, j, i) count += 1 print(count) except EOFError: break def dfs(map, x, y): if x < 0 or y < 0 or x >= 12 or y >= 12: return map[y][x] = '0' for i in range(4): next_x = x + dx[i] next_y = y + dy[i] if next_x >= 0 and next_x < 12 and next_y >= 0 and next_y < 12: if map[next_y][next_x] == '1': dfs(map, next_x, next_y) if __name__ == '__main__': main()
s789054113
p00067
u672443148
1515307054
Python
Python3
py
Runtime Error
0
0
708
ID=0 def dfs(row,col): global ID if islands[row][col]==1: islandsID[row][col]==ID if row<11: dfs(row+1,col) if row>0: dfs(row-1,col) if col<11: dfs(row,col+1) if col>0: dfs(row,col-1) while True: c=0 islands=[] islandsID=[] for i in range(12): islands.append(list(map(int,input().split()))) for _ in range(12): islandsID.append([0 for i in range(12)]) for i in range(12): for j in range(12): if islands[i][j]==1 and islandsID[i][j]==0: ID+=1 dfs(i,j) print(ID) try: c=input() except: break
s297156639
p00067
u886729200
1523408793
Python
Python3
py
Runtime Error
0
0
726
def counter():#島の数をカウントする count=0 #12*12個の値をひとつずつ調べる for x in range(12): for y in range(12): if is_data[x][y] == 1:#島が発見されたら dfs(x,y) count+=1 return count def dfs(x,y): if x<0 or x == len(is_data[x]) or y<0 or y == len(is_data): return if is_data[x][y] == 1: is_data[x][y] = 0 dfs(x+1,y) dfs(x,y+1) dfs(x-1,y) dfs(x,y-1) try: while True: s = input()#入力 for i in range(len(s)): is_data[i] = list(is_data[i].strip()) is_data = np.array(is_data).reshape(12,12) except EOFError: print(counter())
s924460573
p00067
u886729200
1523409744
Python
Python3
py
Runtime Error
0
0
846
def counter():#島の数をカウントする count=0 #12*12個の値をひとつずつ調べる for x in range(12): for y in range(12): if is_data[x][y] == 1:#島が発見されたら dfs(x,y) count+=1 return count def dfs(x,y): if x<0 or x == len(is_data[x]) or y<0 or y == len(is_data): return if is_data[x][y] == 1: is_data[x][y] = 0 dfs(x+1,y) dfs(x,y+1) dfs(x-1,y) dfs(x,y-1) def get_map(): is_data = [] while True: try: tmp = list(int(input())) if len(tmp) != 12: break is_data.append(tmp) except: break return map try: while True: is_data = get_map() if len(is_data) != 12: break except EOFError: print(counter())
s218144481
p00067
u886729200
1523410933
Python
Python3
py
Runtime Error
0
0
761
def counter():#島の数をカウントする count=0 #12*12個の値をひとつずつ調べる for x in range(12): for y in range(12): if is_data[x][y] == 1:#島が発見されたら dfs(x,y) count+=1 return count def dfs(x,y): if x<0 or x == len(is_data[x]) or y<0 or y == len(is_data): return if is_data[x][y] == 1: is_data[x][y] = 0 dfs(x+1,y) dfs(x,y+1) dfs(x-1,y) dfs(x,y-1) while True: try: is_data=[] while True: s = list(input())#入力 if not s :#空入力のときループぬける break is_data.append(s) except EOFError: print(counter())
s885759970
p00067
u886729200
1523411575
Python
Python3
py
Runtime Error
0
0
793
def counter():#島の数をカウントする count=0 #12*12個の値をひとつずつ調べる for x in range(12): for y in range(12): if is_data[x][y] == 1:#島が発見されたら dfs(x,y) count+=1 return count def dfs(x,y): if x<0 or x == len(is_data[x]) or y<0 or y == len(is_data): return if is_data[x][y] == 1: is_data[x][y] = 0 dfs(x+1,y) dfs(x,y+1) dfs(x-1,y) dfs(x,y-1) while True: try: is_data=[] while True: s = list(input())#入力 if not s :#空入力のときループぬける break is_data.append(s) if len(is_data) != 12:break except EOFError: print(counter())
s162436347
p00067
u886729200
1523413244
Python
Python3
py
Runtime Error
0
0
860
def counter():#島の数をカウントする count=0 #12*12個の値をひとつずつ調べる for x in range(12): for y in range(12): if is_data[x][y] == 1:#島が発見されたら print(x,y) dfs(x,y) count+=1 return count def dfs(x,y): if x<0 or x == len(is_data[x]) or y<0 or y == len(is_data): return if is_data[x][y] == 1: is_data[x][y] = 0 dfs(x+1,y) dfs(x,y+1) dfs(x-1,y) dfs(x,y-1) try: is_data=[] while True: s = input()#入力 if not s :#空入力のときループぬける break is_data.append(s) for i in range(len(is_data)): is_data[i] = list(map(int,is_data[i])) is_data = np.array(is_data).reshape(12,12) except EOFError: print(counter())
s777441329
p00067
u886729200
1523413244
Python
Python3
py
Runtime Error
0
0
860
def counter():#島の数をカウントする count=0 #12*12個の値をひとつずつ調べる for x in range(12): for y in range(12): if is_data[x][y] == 1:#島が発見されたら print(x,y) dfs(x,y) count+=1 return count def dfs(x,y): if x<0 or x == len(is_data[x]) or y<0 or y == len(is_data): return if is_data[x][y] == 1: is_data[x][y] = 0 dfs(x+1,y) dfs(x,y+1) dfs(x-1,y) dfs(x,y-1) try: is_data=[] while True: s = input()#入力 if not s :#空入力のときループぬける break is_data.append(s) for i in range(len(is_data)): is_data[i] = list(map(int,is_data[i])) is_data = np.array(is_data).reshape(12,12) except EOFError: print(counter())
s443338208
p00067
u886729200
1523413249
Python
Python3
py
Runtime Error
0
0
860
def counter():#島の数をカウントする count=0 #12*12個の値をひとつずつ調べる for x in range(12): for y in range(12): if is_data[x][y] == 1:#島が発見されたら print(x,y) dfs(x,y) count+=1 return count def dfs(x,y): if x<0 or x == len(is_data[x]) or y<0 or y == len(is_data): return if is_data[x][y] == 1: is_data[x][y] = 0 dfs(x+1,y) dfs(x,y+1) dfs(x-1,y) dfs(x,y-1) try: is_data=[] while True: s = input()#入力 if not s :#空入力のときループぬける break is_data.append(s) for i in range(len(is_data)): is_data[i] = list(map(int,is_data[i])) is_data = np.array(is_data).reshape(12,12) except EOFError: print(counter())
s211707870
p00067
u886729200
1523413522
Python
Python3
py
Runtime Error
0
0
629
def get_map(): map = [] while True: try: tmp = list(raw_input()) if len(tmp) != 12: break map.append(tmp) except: break return map def remove_island(x, y, map): map[x][y] = 0 move = [[1, 0], [0, 1], [-1, 0], [0, -1]] for i, j in move: if 0 <= x + i <= 11 and 0 <= y + j <= 11 and map[x + i][y + j] == '1': map = remove_island(x + i, y + j, map) return map[:] while True: map = get_map() if len(map) != 12: break count = 0 for x in range(12): for y in range(12): if map[x][y] == '1': count += 1 map = remove_island(x, y, map) print count
s573217574
p00067
u886729200
1523414716
Python
Python3
py
Runtime Error
0
0
881
def counter():#島の数をカウントする count=0 #12*12個の値をひとつずつ調べる for x in range(12): for y in range(12): if is_data[x][y] == 1:#島が発見されたら print(x,y) dfs(x,y) count+=1 return count def dfs(x,y): if x<0 or x == len(is_data[x]) or y<0 or y == len(is_data): return if is_data[x][y] == 1: is_data[x][y] = 0 dfs(x+1,y) dfs(x,y+1) dfs(x-1,y) dfs(x,y-1) try: is_data=[] while True: s = input()#入力 if not s :#空入力のときループぬける break else: is_data.append(s) for i in range(len(is_data)): is_data[i] = list(map(int,is_data[i])) is_data = np.array(is_data).reshape(12,12) except EOFError: print(counter())
s783650929
p00067
u563075864
1526227134
Python
Python3
py
Runtime Error
0
0
509
import numpy as np while 1: global a,c c = np.array([[0]*14]*14) a = np.array([[0]*14]*14) a[1:-1,1:-1] = [list(map(int,list(input()))) for i in range(12)] def dfs(x,y,n): if c[x][y] == 0 and a[x][y] == 1: c[x][y] = n [dfs(x+i, y+j, n) for i,j in [(-1,0),(1,0),(0,-1),(0,1)]] [[dfs(x,y,12*x + y) for x in range(1,12+1)] for y in range(1,12+1)] flat = [a for b in c for a in b] print(len(set(flat)) - 1) dump = input() #if input() ==
s151295421
p00067
u563075864
1526227252
Python
Python3
py
Runtime Error
0
0
510
import numpy as np while 1: global a,c c = np.array([[0]*14]*14) a = np.array([[0]*14]*14) a[1:-1,1:-1] = [list(map(int,list(input()))) for i in range(12)] def dfs(x,y,n): if c[x][y] == 0 and a[x][y] == 1: c[x][y] = n [dfs(x+i, y+j, n) for i,j in [(-1,0),(1,0),(0,-1),(0,1)]] [[dfs(x,y,12*x + y) for x in range(1,12+1)] for y in range(1,12+1)] flat = [a for b in c for a in b] print(len(set(flat)) - 1) if input() is None: break
s702727904
p00067
u912237403
1390087547
Python
Python
py
Runtime Error
0
0
933
import sys def f(y,x): f=0 if m[y][x]==1: m[y][x]=c f=1 return f def LR(y,x,dx): P=[] x+=dx while 0<=x<12 and m[y][x]!=0: if f(y,x):P+=[(y,x)] x+=dx return P def UD(y,x,dy): P=[] y+=dy while 0<=y<12 and m[y][x]!=0: if f(y,x):P+=[(y,x)] y+=dy return P def v1(buf): f=0 while len(buf)>0: f=1 y,x=buf.pop() m[y][x]=c buf=list(set(buf+LR(y,x,-1)+LR(y,x,1)+UD(y,x,-1)+UD(y,x,1))) return f def solve(): global c buf=[] c=2 for i in A: x=m[i] while x.count(1)>0: buf+=[(i,x.index(1))] if v1(buf):c+=1 return c-2 A=range(12) m=[[0 for x in A] for y in A] y=0 for s in sys.stdin: if y<12: x=0 for e in map(int,list(s[:-1])): m[y][x]=e x+=1 y+=1 else: print solve() y=0 print solve()
s854528678
p00067
u633068244
1394731952
Python
Python
py
Runtime Error
0
0
642
l = 12 def island(f,x,y,m): rf = f[:][:] if rf[y][x] == 1: rf[y][x] = m for i in [-1,1]: if 0 <= x+i <= l-1: rf = island(rf,x+i,y,m) if 0 <= y+i <= l-1: rf = island(rf,x,y+i,m) return rf while True: f = [] for i in range(l): f.append(map(int, list(raw_input()))) for y in range(l): for x in range(l): f = island(f,x,y,m) m += 1 m, ans = 2, [] for i in range(l): for j in range(l): ans.append(f[i][j]) print len(list(set(ans)))-1 try : raw_input() except: break
s076408919
p00067
u633068244
1394733435
Python
Python
py
Runtime Error
0
0
712
File Edit Options Buffers Tools Python Help def island(f,x,y,m): if f[y][x] == 1: f[y][x] = m for i in [-1,1]: if 0 <= x+i <= 11: f = island(f,x+i,y,m) if 0 <= y+i <= 11: f = island(f,x,y+i,m) return f while True: f = []; m = 2 for i in range(12): f.append(map(int, list(raw_input()))) for y in range(12): for x in range(12): if f[y][x]: f = island(f,x,y,m) m += 1 ans = [] for i in range(12): for j in range(12): ans.append(f[i][j]) ans = list(set(ans)) print len(ans) - 1*ans.count(0) try:raw_input() except: break
s017818627
p00067
u260980560
1397984976
Python
Python
py
Runtime Error
0
0
830
dx, dy = [-1, 0, 1, 0], [0, -1, 0, 1] while True: ans = 0 try: m = ['0'*14] + ['0'+raw_input()+'0' for i in xrange(12)] + ['0'*14] f = [[False for i in xrange(14)] for j in xrange(14)] for y in xrange(1, 13): for x in xrange(1, 13): if m[y][x]=='1' and f[y][x]==False: q = [[x, y]] f[y][x] = True while len(q)>0: px, py = q.pop(0) for k in xrange(4): nx = px + dx[k]; ny = py + dy[k]; if m[ny][nx]=='1' and f[ny][nx]==False: f[ny][nx] = True q.append([nx, ny]) ans += 1 print ans except EOFError: break
s619501160
p00067
u708217907
1399935974
Python
Python
py
Runtime Error
0
0
870
#include <iostream> using namespace std; int m[12][12]; bool valid(int y, int x){ if(0 <= y && y < 12){ if(0 <= x && x < 12){ if(m[y][x] == 1) return true; } } return false; } void remove_island(int y, int x) { int nx, ny; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, 1, 0, -1}; m[y][x] = 0; for(int i = 0; i < 4; i++){ ny = y + dy[i]; nx = x + dx[i]; if(valid(ny, nx)) remove_island(ny, nx); } } int main() { char c[12]; int ans; while(1){ for(int i = 0; i < 12; i++){ if(!(cin >> c)) return 0; for(int j = 0; j < 12; j++){ m[i][j] = (int)(c[j] - '0'); } } ans = 0; for(int i = 0; i < 12; i++){ for(int j = 0; j < 12; j++){ if(valid(i, j)){ remove_island(i, j); ans++; } } } cout << ans << endl; } return 0; }
s935667015
p00068
u408260374
1430298232
Python
Python3
py
Runtime Error
0
0
594
upper_hull = get_bounds(ps) ps.reverse() lower_hull = get_bounds(ps) del upper_hull[-1] del lower_hull[-1] upper_hull.extend(lower_hull) return upper_hull def get_bounds(ps): qs = [] for p in ps: while len(qs) > 1 and (qs[-1] - qs[-2]).det(p - qs[-1]) <= 0: del qs[-1] qs.append(p) return qs while True: n = int(input()) if n == 0: break points = [] for i in range(n): x, y = map(float, input().split(',')) points.append(Point(x, y)) print(len(points) - len(convex_hull(points)))
s464683478
p00068
u140201022
1451293681
Python
Python
py
Runtime Error
0
0
613
def a(v1,v2): if v1[0]!=v2[0]: return (v2[1]-v1[1])/(v2[0]-v1[0]) else: return (v2[1]-v1[1])*(10**10) def dlt(p,v,sign): while len(p)>2: if sign*(a(v[p[-3]],v[p[-2]])-a(v[p[-2]],v[p[-1]]))<0: del p[-2] else: break return p def convex(v,n): d,u=[],[] for i in range(n): d=dlt(d+[i],v,1) u=dlt(u+[i],v,-1) return n-len(set(d+u)) while 1: n=int(raw_input()) if n==0: break v=[map(float,raw_input().splirt(',')) for i in range(n)] v=sorted(sorted(v,key=lambda x:x[1])) print convex(v,n)
s124577525
p00068
u912237403
1390221731
Python
Python
py
Runtime Error
0
0
442
import sys def side(p1,p2): global D y1,x1=p1 y2,x2=p2 dy=y2-y1 dx=x2-x1 for p3 in D[::-1]: if p1==p3 or p2==p3:pass y3,x3=p3 elif (x3-x1)*dy-dx*(y3-y1)<0:return 0 else:return 1 while 1: n=input() if n==0:break D=sorted([list(input()) for i in range(n)]) p=p1=D[0] D1=D[:] while True: for p2 in D1: if p1!=p2 and side(p1,p2):break p1=p2 D1.remove(p2) if p2==p:break print len(D1)
s136260872
p00068
u633068244
1395063063
Python
Python
py
Runtime Error
0
0
865
def f(x,y,x1,y1,x2,y2): if x1 <= x2: return (x2-x1)*y-(y2-y1)*x+x1*y2-x2*y1 else: return -((x2-x1)*y-(y2-y1)*x+x1*y2-x2*y1) def DC(a): if len(a) > 3: # Divide la = a[:len(a)/2] ra = a[len(a)/2:] la,ra = DC(la),DC(ra) # Conquer if len(la) == 1 or len(ra) == 1: return la+ra else: while f(ra[1][0],ra[1][1],la[-1][0],la[-1][1],ra[0][0],ra[0][1]) > 0: ra.pop(0) while f(la[-2][0],la[-2][1],ra[0][0],ra[0][1],la[-1][0],la[-1][1]) > 0: la.pop(-1) return la+ra else: return a while True: n = int(raw_input()) if n == 0: break p = [] for i in range(n): p.append(map(float, raw_input().split(","))) p = sorted(p, key = lambda x: x[0]) print n - len(DC(p))
s604389454
p00068
u633068244
1395063077
Python
Python
py
Runtime Error
0
0
865
def f(x,y,x1,y1,x2,y2): if x1 <= x2: return (x2-x1)*y-(y2-y1)*x+x1*y2-x2*y1 else: return -((x2-x1)*y-(y2-y1)*x+x1*y2-x2*y1) def DC(a): if len(a) > 3: # Divide la = a[:len(a)/2] ra = a[len(a)/2:] la,ra = DC(la),DC(ra) # Conquer if len(la) == 1 or len(ra) == 1: return la+ra else: while f(ra[1][0],ra[1][1],la[-1][0],la[-1][1],ra[0][0],ra[0][1]) > 0: ra.pop(0) while f(la[-2][0],la[-2][1],ra[0][0],ra[0][1],la[-1][0],la[-1][1]) > 0: la.pop(-1) return la+ra else: return a while True: n = int(raw_input()) if n == 0: break p = [] for i in range(n): p.append(map(float, raw_input().split(","))) p = sorted(p, key = lambda x: x[0]) print n - len(DC(p))
s037797140
p00068
u633068244
1395063371
Python
Python
py
Runtime Error
0
0
797
def f(x,y,x1,y1,x2,y2): if x1 <= x2: return (x2-x1)*y-(y2-y1)*x+x1*y2-x2*y1 else: return -((x2-x1)*y-(y2-y1)*x+x1*y2-x2*y1) def DC(a): if len(a) > 3: # Divide la = a[:len(a)/2] ra = a[len(a)/2:] # Conquer la,ra = DC(la),DC(ra) while f(ra[1][0],ra[1][1],la[-1][0],la[-1][1],ra[0][0],ra[0][1]) > 0 and len(ra) > 1: ra.pop(0) while f(la[-2][0],la[-2][1],ra[0][0],ra[0][1],la[-1][0],la[-1][1]) > 0 and len(la) > 1: la.pop(-1) return la+ra else: return a while True: n = int(raw_input()) if n == 0: break p = [] for i in range(n): p.append(map(float, raw_input().split(","))) p = sorted(p, key = lambda x: x[0]) print n - len(DC(p))
s492407254
p00068
u633068244
1395063394
Python
Python
py
Runtime Error
0
0
797
def f(x,y,x1,y1,x2,y2): if x1 <= x2: return (x2-x1)*y-(y2-y1)*x+x1*y2-x2*y1 else: return -((x2-x1)*y-(y2-y1)*x+x1*y2-x2*y1) def DC(a): if len(a) > 3: # Divide la = a[:len(a)/2] ra = a[len(a)/2:] # Conquer la,ra = DC(la),DC(ra) while f(ra[1][0],ra[1][1],la[-1][0],la[-1][1],ra[0][0],ra[0][1]) > 0 and len(ra) > 1: ra.pop(0) while f(la[-2][0],la[-2][1],ra[0][0],ra[0][1],la[-1][0],la[-1][1]) > 0 and len(la) > 1: la.pop(-1) return la+ra else: return a while True: n = int(raw_input()) if n == 0: break p = [] for i in range(n): p.append(map(float, raw_input().split(","))) p = sorted(p, key = lambda x: x[0]) print n - len(DC(p))
s789352828
p00069
u352394527
1527547035
Python
Python3
py
Runtime Error
0
0
1032
while True: n = int(input()) if not n: break start = int(input()) - 1 #開始の位置 goal = int(input()) - 1 #あたりの位置 d = int(input()) nums = [[i for i in range(n)]] #各段での数字の並び bars = [] #横棒リスト for i in range(d): s = input() bars.append(s) new = nums[-1][:] for j in range(n - 1): if s[j] == "1": #横棒があれば入れ替え new[j], new[j + 1] = new[j + 1], new[j] nums.append(new) to_goal = nums[-1][goal] #あたりにたどり着くスタートの番号 for i, status in enumerate(nums): to_goal_ind = status.index(to_goal) #to_goalの位置 start_ind = status.index(start) #startの位置 ind1, ind2 = min(to_goal_ind, start_ind), max(to_goal_ind, start_ind) if ind2 - ind1 == 1: #隣あっていた場合 if bars[i][ind1] == "0" and (ind2 == n - 1 or bars[i][ind2] == "0"): #隣り合う横棒がなければ出力 print(i + 1, ind1 + 1) break else: print(1)
s957027232
p00069
u847467233
1530176787
Python
Python3
py
Runtime Error
0
0
827
# AOJ 0069: Drawing Lots II # Python3 2018.6.28 bal4u while True: n = int(input()) if n == 0: break m, p, d = [int(input()) for i in range(3)] a = [[0 for j in range(10)] for i in range(32)] for i in range(1, d+1): a[i] = [0] + list(map(int, input())) + [0] s = [[0 for j in range(10)] for i in range(32)] for i in range(1, n+1): s[d+1][i] = i for i in range(d, 0, -1): for j in range(1, n+1): s[i][j] = s[i+1][j] for j in range(1, n): if a[i][j]: s[i][j], s[i][j+1] = s[i][j+1], s[i][j] k = s[1][m] if k == p: print(0) continue f = False for i in range(1, d+1): for j in range(1, n): if ((s[i][j] == k and s[i][j+1] == p) or (s[i][j] == p and s[i][j + 1] == k)) \ and a[i][j-1] == 0 and a[i][j] == 0 and a[i][j+1] == 0: print(i, j) f = True break if f: break if not f: print(1)
s117478207
p00069
u647766105
1356965531
Python
Python
py
Runtime Error
0
0
873
while True: n=input() if n==0: break m,goal,d=input(),input(),input() step=[""]*d for i in xrange(d): step[i]=raw_input() raw=range(1,n+1) for i in xrange(d): for j in xrange(n-1): if step[i][j]=="1": raw[j],raw[j+1]=raw[j+1],raw[j] ans=0 if not raw[goal]==m: t=raw[goal] raw=range(1,n+1) for i in xrange(d): if not ans==0:break for j in xrange(n-1): if (raw[j]==m and raw[j+1]==t) or (raw[j+1]==m and raw[j]==t): if (j-1<0 or step[i][j-1]=="0") and (j+1>=n or step[i][j+1]): ans=(i+2,j+1) break if step[i][j]=="1": raw[j],raw[j+1]=raw[j+1],raw[j] if ans==0: ans=1 print " ".join(map(str,ans))
s801120737
p00069
u647766105
1357005923
Python
Python
py
Runtime Error
0
0
912
while True: n=input() if n==0: break m,goal,d=input(),input(),input() step=[""]*d for i in xrange(d): step[i]="0"+raw_input()+"0" raw=range(n+2) for i in xrange(d): for j in xrange(1,n+1): if step[i][j]=="1": raw[j],raw[j+1]=raw[j+1],raw[j] ans=0 if not raw[goal]==m: e=raw[goal] raw=range(n+2) for i in xrange(d): if not ans==0: break for j in xrange(1,n+1): if (raw[j]==m and raw[j+1]==e) or (raw[j]==e and raw[j+1]==m): if step[i][j-1]=="0" and step[i][j]=="0" and step[i][j+1]=="0": ans=(i+1,j) break if step[i][j]=="1": raw[j],raw[j+1]=raw[j+1],raw[j] if ans==0: ans=1 print " ".join(map(str,ans))
s826547726
p00069
u912237403
1390741222
Python
Python
py
Runtime Error
0
0
471
import copy def amida(A,x): for e in A: if e[x]==1:x+=1 elif e[x-1]==1:x-=1 return x def f(): for i in range(d): for j in range(1,n): if A[i][j]==0: B=copy.deepcopy(A) B[i][j]=1 if amida(B,m)==p: print i+1,j return print 1 return import sys n=input() m=input() p=input() d=input() A=[] for s in sys.stdin: if s=="0\n":break A+=[[0]+map(int,list(s[:-1]))+[0]] if amida(A,m)==p: print 0 else:f()
s286281304
p00069
u912237403
1390742765
Python
Python
py
Runtime Error
0
0
462
import copy,sys def amida(A,x): for e in A: if e[x]==1:x+=1 elif e[x-1]==1:x-=1 return x def f(): for i in range(d): for j in range(1,n): if A[i][j]==0: B=copy.deepcopy(A) B[i][j]=1 if amida(B,m)==p: print i+1,j return print 1 return n=input() m=input() p=input() d=input() A=[] for s in sys.stdin: if s=="0\n":break A+=[[0]+map(int,list(s[:-1]))+[0]] if amida(A,m)==p: print 0 else:f()
s387352035
p00069
u912237403
1390743235
Python
Python
py
Runtime Error
0
0
465
import copy,sys def amida(A,x): for e in A: if e[x]==1:x+=1 elif e[x-1]==1:x-=1 return x def f(): for i in range(d): for j in range(1,n+1): if A[i][j]==0: B=copy.deepcopy(A) B[i][j]=1 if amida(B,m)==p: print i+1,j return print 1 return n=input() m=input() p=input() d=input() A=[] for s in sys.stdin: if s=="0\n":break A+=[[0]+map(int,list(s[:-1]))+[0]] if amida(A,m)==p: print 0 else:f()
s746083024
p00069
u912237403
1391024443
Python
Python
py
Runtime Error
0
0
459
import sys def amida(A,x): for e in A: if e[x]==1:x+=1 elif e[x-1]==1:x-=1 return x def f(): for i in range(d): for j in range(1,n): if A[i][j]==0: B=[e[:] for e in A] B[i][j]=1 if amida(B,m)==p: print i+1,j return print 1 return n=input() m=input() p=input() d=input() A=[] for s in sys.stdin: if s=="0\n":break A+=[[0]+map(int,list(s[:-1]))+[0]] if amida(A,m)==p: print 0 else:f()
s201018967
p00069
u633068244
1394808750
Python
Python
py
Runtime Error
0
0
1047
while True: n = int(raw_input()) if n == 0: break m = int(raw_input())-1 x = int(raw_input())-1 d = int(raw_input()) amida = [] for i in range(d): amida.append(map(int, raw_input())) rroot = [] for i in range(d-1,-1,-1): if x > 0: if amida[i][x-1] == 1: x -= 1 if x < 4: if amida[i][x] == 1: x += 1 rroot.append(x) if m == x: print 0 else: root = [] for i in range(d): if m > 0: if amida[i][m-1] == 1: m -= 1 if m < 4: if amida[i][m] == 1: m += 1 root.append(m) rroot.reverse() for i in range(d): k = root[i] - rroot[i] if abs(k) == 1: p = min(root[i],rroot[i]) if sum(amida[i][p-1:p+1]) == 0: print i+1, p+1 break if i == d-1: print 1
s607491650
p00069
u633068244
1394809213
Python
Python
py
Runtime Error
0
0
1355
while True: n = int(raw_input()) if n == 0: break m = int(raw_input())-1 x = int(raw_input())-1 d = int(raw_input()) amida = [] for i in range(d): amida.append(map(int, raw_input())) rroot = [] for i in range(d-1,-1,-1): if x > 0: if amida[i][x-1] == 1: x -= 1 if x < n-1: if amida[i][x] == 1: x += 1 rroot.append(x) if m == x: print 0 else: root = [] for i in range(d): if m > 0: if amida[i][m-1] == 1: m -= 1 if m < n-1: if amida[i][m] == 1: m += 1 root.append(m) rroot.reverse() for i in range(d): if abs(root[i]-rroot[i]) == 1: p = min(root[i],rroot[i]) if p == 0: if amida[i][p+1] == 0: print i+1, p+1 break elif p == n-1: if amida[i][p-1] == 0: print i+1, p+1 break else: if amida[i][p-1] + amida[i][p+1]) == 0: print i+1, p+1 break if i == d-1: print 1
s447534731
p00069
u633068244
1394809280
Python
Python
py
Runtime Error
0
0
1354
while True: n = int(raw_input()) if n == 0: break m = int(raw_input())-1 x = int(raw_input())-1 d = int(raw_input()) amida = [] for i in range(d): amida.append(map(int, raw_input())) rroot = [] for i in range(d-1,-1,-1): if x > 0: if amida[i][x-1] == 1: x -= 1 if x < n-1: if amida[i][x] == 1: x += 1 rroot.append(x) if m == x: print 0 else: root = [] for i in range(d): if m > 0: if amida[i][m-1] == 1: m -= 1 if m < n-1: if amida[i][m] == 1: m += 1 root.append(m) rroot.reverse() for i in range(d): if abs(root[i]-rroot[i]) == 1: p = min(root[i],rroot[i]) if p == 0: if amida[i][p+1] == 0: print i+1, p+1 break elif p == n-1: if amida[i][p-1] == 0: print i+1, p+1 break else: if amida[i][p-1] + amida[i][p+1] == 0: print i+1, p+1 break if i == d-1: print 1
s104772410
p00069
u633068244
1394809511
Python
Python
py
Runtime Error
0
0
1354
while True: n = int(raw_input()) if n == 0: break m = int(raw_input())-1 x = int(raw_input())-1 d = int(raw_input()) amida = [] for i in range(d): amida.append(map(int, raw_input())) rroot = [] for i in range(d-1,-1,-1): if x > 0: if amida[i][x-1] == 1: x -= 1 if x < n-1: if amida[i][x] == 1: x += 1 rroot.append(x) if m == x: print 0 else: root = [] for i in range(d): if m > 0: if amida[i][m-1] == 1: m -= 1 if m < n-1: if amida[i][m] == 1: m += 1 root.append(m) rroot.reverse() for i in range(d): if abs(root[i]-rroot[i]) == 1: p = min(root[i],rroot[i]) if p == 0: if amida[i][p+1] == 0: print i+1, p+1 break elif p == n-1: if amida[i][p-1] == 0: print i+1, p+1 break else: if amida[i][p-1] + amida[i][p+1] == 0: print i+1, p+1 break if i == d-1: print 1
s176024776
p00069
u633068244
1394809570
Python
Python
py
Runtime Error
0
0
1354
while True: n = int(raw_input()) if n == 0: break m = int(raw_input())-1 x = int(raw_input())-1 d = int(raw_input()) amida = [] for i in range(d): amida.append(map(int, raw_input())) rroot = [] for i in range(d-1,-1,-1): if x > 0: if amida[i][x-1] == 1: x -= 1 if x < n-1: if amida[i][x] == 1: x += 1 rroot.append(x) if m == x: print 0 else: root = [] for i in range(d): if m > 0: if amida[i][m-1] == 1: m -= 1 if m < n-1: if amida[i][m] == 1: m += 1 root.append(m) rroot.reverse() for i in range(d): if abs(root[i]-rroot[i]) == 1: p = min(root[i],rroot[i]) if p == 0: if amida[i][p+1] == 0: print i+1, p+1 break elif p == n-2: if amida[i][p-1] == 0: print i+1, p+1 break else: if amida[i][p-1] + amida[i][p+1] == 0: print i+1, p+1 break if i == d-1: print 1
s468119581
p00069
u633068244
1394809954
Python
Python
py
Runtime Error
0
0
935
while True: n = int(raw_input()) if n == 0: break m,x,d = int(raw_input())-1,int(raw_input())-1,int(raw_input()) amida = [] for i in range(d): amida[i] = "0" + raw_input() + "0" rroot = [] for i in range(d-1,-1,-1): if amida[i][x-1] == "1": x -= 1 elif amida[i][x] == "1": x += 1 rroot.append(x) if m == x: print 0 else: root = [] for i in range(d): if amida[i][m-1] == "1": m -= 1 elif amida[i][m] == "1": m += 1 root.append(m) rroot.reverse() for i in range(d): if abs(root[i]-rroot[i]) == 1: p = min(root[i],rroot[i]) if int(amida[i][p-1]) + int(amida[i][p+1]) == 0: print i+1, p+1 break if i == d-1: print 1
s473150211
p00069
u633068244
1394809982
Python
Python
py
Runtime Error
0
0
931
while True: n = int(raw_input()) if n == 0: break m,x,d = int(raw_input())-1,int(raw_input())-1,int(raw_input()) amida = [] for i in range(d): amida[i] = "0" + raw_input() + "0" rroot = [] for i in range(d-1,-1,-1): if amida[i][x-1] == "1": x -= 1 elif amida[i][x] == "1": x += 1 rroot.append(x) if m == x: print 0 else: root = [] for i in range(d): if amida[i][m-1] == "1": m -= 1 elif amida[i][m] == "1": m += 1 root.append(m) rroot.reverse() for i in range(d): if abs(root[i]-rroot[i]) == 1: p = min(root[i],rroot[i]) if int(amida[i][p-1]) + int(amida[i][p+1]) == 0: print i+1, p+1 break if i == d-1: print 1
s838209379
p00070
u197615397
1531730567
Python
Python3
py
Runtime Error
0
0
606
from itertools import combinations import sys # dp[n][使った数字(bit)][合計] = count dp = [[[0]*331 for _ in [0]*2048] for _ in [0]*11] for i in range(11): dp[1][2**i][i] = 1 for i in range(2, 11): for used in (sum(comb) for comb in combinations([2**n for n in range(10)], i-1)): for j in filter(lambda x: used & 2**x == 0, range(10)): for total, count in filter(lambda p: p[1]>0, enumerate(dp[i-1][used])): dp[i][used|2**j][total+j*i] += count for n, s in (map(int, l.rstrip().split()) for l in sys.stdin): print(sum(a[s] for a in dp[n] if a[s]))
s323397782
p00070
u041086527
1416062412
Python
Python
py
Runtime Error
0
0
779
def is_prime2(q,k=100): q = abs(q) if q == 2: return True if q < 2 or q&1 == 0: return False for i in xrange(3,k): x,y = q,i while y: x, y = y, x % y if x != 1: continue if pow(i, q-1, q) != 1: return False return True if __name__ == "__main__": while True: n = input() if (n == 0): break if (n < 19): print 13 else: tmp = int((n - 19) / 30) if tmp == 0: print 19 while tmp > 0: x = 30 * tmp + 19 if (is_prime2(x) and is_prime2(x - 2) and is_prime2(x - 6) and is_prime2(x - 8)): print x break tmp -= 1
s219358194
p00070
u041086527
1416062467
Python
Python
py
Runtime Error
0
0
743
def is_prime2(q,k=100): q = abs(q) if q == 2: return True if q < 2 or q&1 == 0: return False for i in xrange(3,k): x,y = q,i while y: x, y = y, x % y if x != 1: continue if pow(i, q-1, q) != 1: return False return True if __name__ == "__main__": while True: n = input() break if (n == 0): break if (n < 19): print 13 else: tmp = int((n - 19) / 30) while tmp > 0: x = 30 * tmp + 19 if (is_prime2(x) and is_prime2(x - 2) and is_prime2(x - 6) and is_prime2(x - 8)): print x break tmp -= 1