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
s314073054
p04044
u318363730
1544918452
Python
Python (3.4.3)
py
Runtime Error
18
3060
335
d = input().rstrip() d_list = d.split(" ") t_list = [] for i in range(int(d_list[1])): t_list.append(str(input().rstrip())) def solution(t_list): t_list.sort() ans_str = "" for i in t_list: ans_str += i return ans_str def main(): print(solution(t_list)) if __name__ == '__main__': main()
s015340973
p04044
u318363730
1544917864
Python
Python (3.4.3)
py
Runtime Error
18
3060
330
d = input().rstrip() d_list = d.split(" ") t_list = [] for i in range(int(d_list[1])): t_list.append(input().rstrip()) def solution(t_list): t_list.sort() ans_str = "" for i in t_list: ans_str += i return ans_str def main(): print(solution(t_list)) if __name__ == '__main__': main()
s452909288
p04044
u140251125
1544040181
Python
Python (3.4.3)
py
Runtime Error
17
2940
139
# input n, l = map(int, input().split()) S = sorted([input() for _ in range(N)]) ans = '' for i in range(N): ans += S[i] print(ans)
s835242518
p04044
u705617253
1543607531
Python
Python (3.4.3)
py
Runtime Error
20
3060
140
n, l = map(int, input().split()) s = [input() for _ in range(n)] result = "" s.sort() for i in range(l): result += s[i] print(result)
s612718274
p04044
u869728296
1542816381
Python
Python (3.4.3)
py
Runtime Error
19
3060
218
N,L=map(int,input().strip().split(" ")) a=[] for i in range(L): a.append(input()) a.sort() b=str(a) b=b.replace(",","") b=b.replace("[","") b=b.replace("]","") b=b.replace("'","") b=b.replace(" ","") print(b)
s130866074
p04044
u018679195
1542228356
Python
Python (3.4.3)
py
Runtime Error
17
2940
103
N,L=map(int,input().split()) S = [input() for i in range(N)] S.sort() for s in S: print(s,end=“”)
s867858165
p04044
u863370423
1542228273
Python
PyPy3 (2.4.0)
py
Runtime Error
187
38384
103
N,L=map(int,input().split()) S = [input() for i in range(N)] S.sort() for s in S: print(s,end=“”)
s163353188
p04044
u863370423
1542221092
Python
Python (3.4.3)
py
Runtime Error
20
2940
106
n,l=map(int, input()) s=[list(input()) for i in range(n)] s.sort() for i in s: print(i,end="") print()
s305629880
p04044
u208052792
1541171294
Python
Python (3.4.3)
py
Runtime Error
17
3060
171
N, L = map(int, input().split()) s = [0 for i in range(N)] for i in range(N): s[i] = input() s.sort() output = "" for i in range(L): output += s[i] print(output)
s159014492
p04044
u438786370
1541171144
Python
Python (3.4.3)
py
Runtime Error
17
3060
155
data = list(map(lambda x: int(x), input().split())) strings = [input() for _ in range(data[1])] strings.sort() s = '' for x in strings: s += x print(s)
s355672682
p04044
u363407238
1540687968
Python
Python (3.4.3)
py
Runtime Error
17
3060
91
n, l = map(int, input().sprit()) s = [input() for _ in range(n)] s.sort() print("".join(s))
s676024136
p04044
u079543046
1540652053
Python
Python (3.4.3)
py
Runtime Error
17
3060
141
N, L = map(int, input().split()) s = [] ans = [] dj = list(arange(N)) for i in range(N): s.append(input()) s = sorted(s) ans = "".join(s)
s186242362
p04044
u466478199
1537494864
Python
Python (3.4.3)
py
Runtime Error
17
3060
103
L,N=map(int,input().split()) l=[] for i in range(N): l.append(input()) l.sort() print(''.join(l))
s742288298
p04044
u466478199
1537494721
Python
Python (3.4.3)
py
Runtime Error
18
3060
141
L,N=map(int,input().split()) l=[] for i in range(N): s=list(input()) s.sort() a=''.join(s) l.append(a) l.sort() print(''.join(l))
s543182404
p04044
u787562674
1536651342
Python
Python (3.4.3)
py
Runtime Error
17
3064
331
N, L = map(int, input().split()) inputs = [input() for _ in range(N)] ans = [ inputs[0] + inputs[1] + inputs[2], inputs[0] + inputs[2] + inputs[1], inputs[1] + inputs[0] + inputs[2], inputs[1] + inputs[2] + inputs[0], inputs[2] + inputs[0] + inputs[1], inputs[2] + inputs[1] + inputs[0], ] print(min(ans))
s625960720
p04044
u787562674
1536651148
Python
Python (3.4.3)
py
Runtime Error
781
367152
262
N, L = map(int, input().split()) inputs = [input() for _ in range(N)] ans = [] for i in range(L): for j in range(L): for k in range(L): if i != j and j != k: ans.append(inputs[i] + inputs[j] + inputs[k]) print(min(ans))
s031334713
p04044
u005260772
1535082975
Python
Python (2.7.6)
py
Runtime Error
10
2568
126
n = int(raw_input()) s = '' for i in range(n): s += raw_input() s = sorted(s) ans = '' for i in s: ans += i print ans
s971247476
p04044
u052347048
1534096626
Python
Python (3.4.3)
py
Runtime Error
17
3060
100
lengh,num = map(int,input().split()) lis = [input() for i in range(num)] print("".join(sorted(lis)))
s207586369
p04044
u690536347
1533357564
Python
Python (3.4.3)
py
Runtime Error
17
3060
85
s,l=map(int,input().split()) m=sorted([input() for _ in range(l)]) print("".join(m))
s170391482
p04044
u278864208
1533326926
Python
Python (3.4.3)
py
Runtime Error
18
3060
115
N, L = map(int, input().split()) S = [input() for i in range(N)] for i in range(3): print(sorted(S)[i], end="")
s582461042
p04044
u278864208
1533325910
Python
Python (3.4.3)
py
Runtime Error
17
3060
130
N, L = map(int, input().split()) S = [input() for i in range(N)] print("{0}{1}{2}".format(sorted(S)[0],sorted(S)[1],sorted(S)[2]))
s760580659
p04044
u050428930
1531173818
Python
Python (3.4.3)
py
Runtime Error
18
3060
84
n,m=map(int,input().split()) s=sorted([input() for i in range(m)]) print("".join(s))
s214732425
p04044
u588341295
1530633458
Python
Python (3.4.3)
py
Runtime Error
17
3060
177
# -*- coding: utf-8 -*- N, L = map(int, input().split()) str_list = [input() for i in range(L)] str_list.sort() ans = "" for i in range(L): ans += str_list[i] print(ans)
s421462981
p04044
u894440853
1528364594
Python
Python (3.4.3)
py
Runtime Error
17
2940
67
print("".join(sorted([input() for _ in range(input().split()[0]))))
s840296008
p04044
u136090046
1528250800
Python
Python (3.4.3)
py
Runtime Error
17
3060
128
n, l = map(int, input().split()) array = sorted([input() for x in range(l)]) res = "" for i in array: res += i print(res)
s493065812
p04044
u314057689
1527900114
Python
PyPy3 (2.4.0)
py
Runtime Error
396
81388
1613
#!/usr/bin/env python # -*- coding: utf-8 -*- import sys# {{{ import os import time import re from pydoc import help import string import math import numpy as np from operator import itemgetter from collections import Counter from collections import deque from collections import defaultdict as dd import fractions from heapq import heappop, heappush, heapify import array from bisect import bisect_left, bisect_right, insort_left, insort_right from copy import deepcopy as dcopy import itertools# }}} # pre-defined{{{ sys.setrecursionlimit(10**7) INF = 10**20 GOSA = 1.0 / 10**10 MOD = 10**9+7 ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)] # can also use string module 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 DP(N, M, first): return [[first] * M for n in range(N)] def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]# }}} def local_input(): from pcm.utils import set_stdin import sys if len(sys.argv) == 1: set_stdin(os.path.dirname(__file__) + '/test/' + 'sample-1.in') def solve(): N, L = map(int, input().split()) S = [] for n in range(N): S.append(input()) S.sort() print(''.join(S)) if __name__ == "__main__":# {{{ try: local_input() except: pass solve() # vim: set foldmethod=marker:}}}
s602666687
p04044
u226108478
1523982706
Python
Python (3.4.3)
py
Runtime Error
17
3060
212
# -*- coding: utf-8 -*- # AtCoder Beginner Contest # Problem B if __name__ == '__main__': n, length = list(map(int, input().split())) s = sorted([input() for _ in range(length)]) print(''.join(s))
s170412342
p04044
u259752752
1523149522
Python
Python (3.4.3)
py
Runtime Error
17
2940
507
#include <iostream> #include <algorithm> #include <vector> using namespace std; int main() { int N, L; cin >> N >> L; vector<string> v; string ret; string s; for(int i=0; i<N; i++){ cin >> s; v.push_back(s); } sort(v.begin(), v.end(), less<string>() ); for(vector<string>::iterator it = v.begin(); it != v.end(); it++){ ret += *it; } cout << ret << endl; return 0; }
s544070355
p04044
u684084063
1523148034
Python
Python (3.4.3)
py
Runtime Error
20
3316
183
# -*- coding: utf-8 -*- N,L = map(int,input().split()) ANS=[] ans="" for hoge in range(L): S=input() ANS.append(S) ANS=sorted(ANS) for fuga in ANS: ans=ans+fuga print(ans)
s253322812
p04044
u978494963
1523135360
Python
Python (3.4.3)
py
Runtime Error
17
3060
112
n,l = list(map(int, input().split(" "))) s = [] for i in range(n): s.append(input()) sort(s) print("".join(s))
s938073830
p04044
u657541767
1523035556
Python
Python (3.4.3)
py
Runtime Error
17
3060
116
n, l = map(int, input().split()) str_list = [input() for i in range(l)] str_list.sort() print("".join(str_list))
s618891314
p04044
u657541767
1523035455
Python
Python (3.4.3)
py
Runtime Error
17
2940
116
n, l = map(int, input().split()) str_list = [input() for i in range(3)] str_list.sort() print("".join(str_list))
s574114986
p04044
u667949809
1522545768
Python
Python (3.4.3)
py
Runtime Error
17
2940
112
n,l = input().split() n = int(n) s = [] for i in range(n): s.append(input()) s.sort() print(s[0]+s[1]+s[2])
s274838556
p04044
u667949809
1522545561
Python
Python (3.4.3)
py
Runtime Error
17
2940
109
n,l = map(int,input().split()) s = [] for i in range(n): s.append(input()) s.sort() print(s[0]+s[1]+s[2])
s854903642
p04044
u976256337
1521346230
Python
Python (3.4.3)
py
Runtime Error
17
2940
15
3 3 dxx axx cxx
s031201613
p04044
u103539599
1518237146
Python
Python (3.4.3)
py
Runtime Error
22
3956
214
N,L=map(int,input().split()) S=[input() for i in range(N)] Ts="" T=[] for j in range(L): t=j for i in range(N): if t==L: t=0 Ts+=S[t] t+=1 T.append(Ts) Ts="" print(min(T))
s287575071
p04044
u952708174
1517084267
Python
Python (3.4.3)
py
Runtime Error
18
3060
116
N,L = [int(i) for i in input().split()] S=[[i for i in input().strip()] for j in range(N)] print(''.join(sorted(S)))
s294011735
p04044
u667084803
1510047693
Python
Python (3.4.3)
py
Runtime Error
17
3064
459
def power_func(a,b,p): """a^b mod p を求める""" if b==0: return 1 if b%2==0: d=power_func(a,b//2,p) return d*d %p if b%2==1: return (a*power_func(a,b-1,p ))%p from math import factorial H,W,A,B=map(int, input().split()) p=10**9+7 ans=0 X=[1] Y=[1] for i in range(H+W-2): fact=factorial(i+1)%p X+=[fact] Y+=[power_func( fact, p-2,p)] for i in range(B,W): ans+=X[H-A-1+i]*X[A+W-2-i]*(Y[H-A-1]*Y[i]*Y[A-1]*Y[W-1-i])%p print(ans)
s411602408
p04044
u255555420
1502826355
Python
Python (3.4.3)
py
Runtime Error
17
3060
93
L, N = map(int,input().split()) S = [input() for i in range(N)] S.sort() print("".join(S))
s663938167
p04044
u255555420
1502820985
Python
Python (3.4.3)
py
Runtime Error
18
3060
105
L, N = map(int,input().split()) S = [input() for i in range(N)] B=sorted(S) A=''.join(B) print(str(A))
s500720939
p04044
u255555420
1502820720
Python
Python (3.4.3)
py
Runtime Error
17
3060
105
L, N = map(int,input().split()) S = [input() for i in range(N)] S=sorted(S) A=''.join(S) print(str(A))
s176621176
p04044
u255555420
1502820635
Python
Python (3.4.3)
py
Runtime Error
17
3060
102
L, N = map(int,input().split()) S = [input() for i in range(N)] S.sort() A=''.join(S) print(str(A))
s348097574
p04044
u255555420
1502820430
Python
Python (3.4.3)
py
Runtime Error
17
3060
97
L, N = map(int,input().split()) S = [input() for i in range(N)] S.sort() A=''.join(S) print(A)
s217837058
p04044
u255555420
1502820234
Python
Python (3.4.3)
py
Runtime Error
17
3060
97
L, N = map(int,input().split()) S = [input() for i in range(N)] S.sort() A=''.join(S) print(A)
s740244698
p04044
u993069079
1498294892
Python
Python (2.7.6)
py
Runtime Error
10
2568
107
n, l = map(int, raw_input().split()) for i in xrange(n): a.append(raw_input()) a.sort() print "".join(a)
s734545290
p04044
u993069079
1498294821
Python
Python (2.7.6)
py
Runtime Error
10
2568
108
n, l = map(int, raw_input().split()) for i in xrange(n): a.append(raw_input()) a.sort() print " ".join(a)
s949202935
p04044
u319818166
1490220702
Python
Python (2.7.6)
py
Runtime Error
10
2568
178
import sys L, N = map(int, raw_input().split()) input = [] for i in range(0, N): sentence = raw_input() input.append(sentence) for x in sorted(input): sys.stdout.write(x)
s288822451
p04044
u788681441
1484255352
Python
Python (3.4.3)
py
Runtime Error
23
3064
164
#pythonだとsortでそのまま何文字でもソートしてくれる n, l = map(int, input().split()) s = [input() for _ in range(n)]] print(''.join(sorted(s)))
s447909598
p04044
u580920947
1483236619
Python
Python (3.4.3)
py
Runtime Error
23
3064
171
# -*- coding: utf-8 -*- # problem B N, L = map(int, input().split()) ls = [] for _ in N: input_data = input() ls.append(input_data) ls.sort() print(''.join(ls))
s297337832
p04044
u317493066
1483046880
Python
Python (3.4.3)
py
Runtime Error
22
3060
192
N, L = map(int, input().split()) data = [] for _ in range(N): input_data = input() data.append(input_data) print(data) data.sort() print(''.join(data))
s844234676
p04044
u582243208
1480112163
Python
Python (3.4.3)
py
Runtime Error
22
3064
78
n,l=map(int,input().split()) print("".join(sorted[input() for i in range(n)]))
s814716947
p04044
u493916575
1480050174
Python
Python (3.4.3)
py
Runtime Error
26
3188
141
N,L = map(int, input().split()) S = 26*[""] for i in range(N): S[i] = input() S.sort() str = "" for s in S: str += s print(str)
s460675917
p04044
u117095520
1477683531
Python
Python (2.7.6)
py
Runtime Error
16
2568
189
import heapq N, L = map(int, raw_input().split()) hq = [] for _ in xrange(N: s = raw_input() heapq.heappush(hq, s) ans = '' while len(hq) > 0: ans += heapq.heappop(hq) print ans
s905483219
p04044
u612721349
1472788509
Python
Python (3.4.3)
py
Runtime Error
39
3064
71
print("".join(sorted([input() for i in range(int(input().split[0]))])))
s481440393
p04044
u289882742
1470434095
Python
Python (2.7.6)
py
Runtime Error
33
2820
141
import sys def main(lines): print(''.join(sorted(lines.split()))) next(sys.stdin) for line in sys.stdin: lines += line main(lines)
s583679897
p04044
u112002050
1469398308
Python
Python (3.4.3)
py
Runtime Error
39
3064
92
N = int(input().split()[0]) words = [input() for i in range(N)] print("".join(words.sort()))
s136690770
p04044
u112002050
1469398266
Python
Python (3.4.3)
py
Runtime Error
40
3064
87
N = input().split()[0] words = [input() for i in range(N)] print("".join(words.sort()))
s848410609
p04044
u153147777
1469324950
Python
Python (2.7.6)
py
Runtime Error
321
2820
752
import sys sys.setrecursionlimit(10000000) n, l = map(int, raw_input().split()) s = [raw_input() for _ in xrange(n)] gtable = [[] for _ in xrange(26)] result = [] def searchPrint(e, n): table = [[] for _ in xrange(26)] for i in e: table[ord(s[i][n]) - 97].append(i) for el in table: if len(el) == 0: continue if len(el) == 1: result.append(s[el[0]]) continue if n == l-1: for i in el: result.append(s[i]) continue searchPrint(el, n+1) for i in xrange(n): gtable[ord(s[i][0]) - 97].append(i) for e in gtable: if len(e) == 0: continue searchPrint(e, 1) print "".join(result)
s234130821
p04044
u153147777
1469324902
Python
Python (2.7.6)
py
Runtime Error
28
2820
709
n, l = map(int, raw_input().split()) s = [raw_input() for _ in xrange(n)] gtable = [[] for _ in xrange(26)] result = [] def searchPrint(e, n): table = [[] for _ in xrange(26)] for i in e: table[ord(s[i][n]) - 97].append(i) for el in table: if len(el) == 0: continue if len(el) == 1: result.append(s[el[0]]) continue if n == l-1: for i in el: result.append(s[i]) continue searchPrint(el, n+1) for i in xrange(n): gtable[ord(s[i][0]) - 97].append(i) for e in gtable: if len(e) == 0: continue searchPrint(e, 1) print "".join(result)
s724696645
p04044
u435698658
1469322278
Python
Python (2.7.6)
py
Runtime Error
991
3080
111
N, L = raw_input().split() l = [] for _ in range(N): l.append(raw_input().strip()) print "".join(sorted(l))
s018621055
p04044
u798181098
1469322174
Python
Python (3.4.3)
py
Runtime Error
1699
8536
116
n, l = map(int, input().split()) s = [] for i in range(n): t = input() s.append(t) s.sort() print(s.join(''))
s763511986
p04045
u149249972
1601366762
Python
Python (3.8.2)
py
Runtime Error
27
9384
567
import math total = list(map(lambda x: int(x), input().split())) possible = list({0,1,2,3,4,5,6,7,8,9} - set(list(map(lambda x: int(x), input().split())))) yen = total[0] digits = math.log10(yen) + 1 final = [] while digits: if yen % (10**digits) in possible: final.append(int(yen % (10**digits))) else: for i in possible: if i > yen % digits: final.append(int(i)) break digits -= 1 print(int(''.join(map(str, final))))
s955286458
p04045
u149249972
1601366674
Python
Python (3.8.2)
py
Runtime Error
25
9404
567
import math total = list(map(lambda x: int(x), input().split())) possible = list({0,1,2,3,4,5,6,7,8,9} - set(list(map(lambda x: int(x), input().split())))) yen = total[0] digits = math.log10(yen) + 1 final = [] while digits: if yen % (10**digits) in possible: final.append(int(yen % (10**digits))) else: for i in possible: if i > yen % digits: final.append(int(i)) break digits -= 1 print(int(''.join(map(str, final))))
s688055985
p04045
u697690147
1600916235
Python
PyPy2 (7.3.0)
py
Runtime Error
300
85152
733
n, k = input().split() d = list(map(int, input().split())) a = [] for i in range(10): if i not in d: a.append(i) n = list(map(int, list(n))) for i in range(len(n)): if n[i] in d: ind = i done = False while not done: for j in range(n[ind]+1, 10): if j in a: n[ind] = j done = True break if not done: ind -= 1 if ind < 0: n.insert(0, a[1] if a[0] == 0 else a[0]) ind = 0 done = True for j in range(ind+1, len(n)): n[j] = a[0] break print("".join(list(map(str, n))))
s411831596
p04045
u035885928
1600392238
Python
Python (3.8.2)
py
Runtime Error
26
8904
521
n, k= input().split() l = list(map(int,input().split())) checkNum=[i for i in range(11)] def find(x): while x!=checkNum[x]: checkNum[x]=checkNum[checkNum[x]] x=checkNum[x] return x for i in l: checkNum[find(i)]=checkNum[find(i+1)] fin="" for i in range(len(n)): first=int(n[i]) k=find(first) if k==first: fin+=str(k) else: if k!=10: fin+=str(k) i+=1 else:fin+=str(find(1)) fin+=str(find(0))*(len(n)-i) break p
s508719814
p04045
u035885928
1600389823
Python
Python (3.8.2)
py
Runtime Error
27
9240
515
n, k= map(int,input().split()) l = list(map(int,input().split())) checkNum=[i for i in range(11)] for i in l: checkNum[find(i)]=checkNum[find(i+1)] def find(x): while x!=checkNum[x]: checkNum[x]=checkNum[checkNum[x]] x=checkNum[x] return x fin="" remain=0 if n==0: fin=str(find(0)) while n>0 or remain>0: last=n%10 k=find(last+remain) remain=0 if k!=10: fin=str(k)+fin else: remain+=1 fin=str(find(0))+fin n//=10 print(fin)
s064020163
p04045
u644907318
1600259444
Python
Python (3.8.2)
py
Runtime Error
27
9088
936
N,K = map(int,input().split()) D = list(map(int,input().split())) E = [] for i in range(10): if i not in D: E.append(i) E = sorted(E) N = str(N) ind = len(N) for i in range(len(N)): if int(N[i]) not in E: ind = i break if ind==len(N): print(N) else: flag = 0 x = "" for i in range(ind-1,-1,-1): n = int(N[i]) if n==E[-1]:continue else: for e in E: if e>n: x = N[:i]+str(e)+str(E[0])*(len(N)-i-1) flag = 1 break if flag==1:break if flag==0: for e in E: if e>int(N[0]): a = e flag = 1 break x = str(a)+str(E[0])*(len(N)-1) if flag==0: if E[0]>0: a = E[0] else: a = E[1] x = str(a)+str(E[0])*len(N) print(x)
s553626963
p04045
u113835532
1599791955
Python
Python (3.8.2)
py
Runtime Error
27
9140
432
def answer(n: int, k: int, d: []) -> int: numbers = list({0, 1, 2, 3, 4, 5, 6, 7, 8, 9} ^ set(d)) payment = '' for i in str(n): for num in numbers: if int(i) <= num: payment += str(num) break return int(payment) def main(): n, k = map(int, input().split()) d = map(int, input().split()) print(answer(n, k, d)) if __name__ == '__main__': main()
s960022775
p04045
u107639613
1599446094
Python
PyPy3 (7.3.0)
py
Runtime Error
80
74680
581
import sys from bisect import bisect_left def input(): return sys.stdin.readline().strip() def main(): N, K = map(int, input().split()) D = set(map(int, input().split())) ok = [i for i in range(10) if i not in D] N = str(N) l = len(N) if {i for i in range(int(N[0]), 10)} <= D: if ok[0] == 0: ans = ok[1] * 10 ** l print(ans) else: ans = 0 for c in N: ans *= 10 idx = bisect_left(ok, int(c)) ans += ok[idx] print(ans) if __name__ == "__main__": main()
s645549174
p04045
u892797057
1599362082
Python
PyPy3 (7.3.0)
py
Runtime Error
103
74432
1218
N, L = [int(x) for x in input().split()] S = [] for s in range(N): S.append(input()) print("".join(sorted(S))) # %% [markdown] # # C # # %% N, K = [int(x) for x in input().split()] dislikes = [False] * 10 dislike_nums = [int(x) for x in input().split()] for n in dislike_nums: dislikes[n] = True # Add '0' in the beginning of N for carrying up N = "0" + str(N) # Create a list of numbers consists N n_list = [] for n in N: n_list.append(int(n)) # Create a list of carrying up numbers c_list = [0] * len(n_list) # Create the smallest payment payment = "" for i in range(len(n_list) - 1, -1, -1): n = n_list[i] + c_list[i] if i == 0 and n == 0: break # Find an equal or larger number than n and not in dislikes x = -1 for m in range(n, 10): if not dislikes[m]: x = m break if x >= 0: # found a number payment = str(m) + payment continue # Carry a number to the previous (x10) digit if i > 0: c_list[i - 1] += 1 # Find a smaller number than n and not in dislikes for m in range(0, n): if not dislikes[m]: payment = str(m) + payment break print(int(payment))
s558305478
p04045
u125545880
1599278861
Python
Python (3.8.2)
py
Runtime Error
26
9160
713
def minN(N:int, usable:list, restrict=True): usable.sort() if restrict: for i in usable: if i >= N: return str(i) else: return str(usable[0]) def main(): N, K = map(int, input().split()) D = set(map(int, input().split())) numset = set(range(0,10)) d = list(numset.difference(D)) d.sort() Nstr = list(str(N)) ans = '' flag = True for n in Nstr: n = int(n) if flag: if n in D: ans += minN(n, d) flag = False else: ans += str(n) else: ans += str(min(d)) print(int(ans)) if __name__ == "__main__": main()
s261205067
p04045
u139614630
1598967486
Python
Python (3.8.2)
py
Runtime Error
33
8944
969
#!/usr/bin/env python3 import sys from itertools import chain from bisect import bisect_left # from collections import Counter # import numpy as np def solve(N: int, K: int, D: "List[int]"): nr = list(map(int, reversed(str(N)))) over = False answer = [] useable = sorted(set(range(10)) - set(D)) if nr[0] not in useable: nr = [0] + nr for n in nr: if over: answer.append(useable[0]) else: a = useable[bisect_left(useable, n)] answer.append(a) if a > n: over = True return "".join(map(str, reversed(answer))) def main(): tokens = chain(*(line.split() for line in sys.stdin)) # N, K, D = map(int, line.split()) N = int(next(tokens)) # type: int K = int(next(tokens)) # type: int D = [int(next(tokens)) for _ in range(K)] # type: "List[int]" answer = solve(N, K, D) print(answer) if __name__ == "__main__": main()
s451474947
p04045
u869790980
1598486741
Python
PyPy2 (7.3.0)
py
Runtime Error
343
85056
241
n,k = map(int, raw_input().split()) letters = [u for u in range(10) if u not in set(map(int, raw_input().split()))] def dfs(u,n,letters):return min([dfs(u*10 +l,n,letters) for l in letters if u or l]) if u < n else u print dfs(0,n,letters)
s211898451
p04045
u869790980
1598486547
Python
PyPy2 (7.3.0)
py
Runtime Error
348
85672
272
#1000 8 #1 3 4 5 6 7 8 9 n,k = map(int, raw_input().split()) s = set(map(int, raw_input())) letters = [u for u in range(10) if u not in s] def dfs(u,n,letters): if u >= n: return u return min([dfs(u*10 +l,n,letters) for l in letters if u or l]) print dfs(0,n,letters)
s096590089
p04045
u997134361
1598216207
Python
Python (3.8.2)
py
Runtime Error
36
9108
307
total, k = map(int, input().split()) d = input().split() def find_lowest_denomination(total, d): for i in range(total, 10001): if not set(str(i)) & set(d): print(i) return raise ValueError('Should never reach this code block') find_lowest_denomination(total, d)
s768587080
p04045
u185948224
1598154819
Python
Python (3.8.2)
py
Runtime Error
32
9152
683
from itertools import combinations_with_replacement, product n, k = map(int, input().split()) d = [int(x) for x in input().split()] dd = set(list(range(10))) - set(d) x = str(n) lst = [] dd = list(dd) dd.sort() sel = [] for i in dd: if int(x[0]) <= i and len(sel) < 3: sel.append(i*10**(len(x)-1)) if len(sel) < 2: if dd[0] != 0: sel.append((dd[0]*10 + dd[1])* 10 ** (len(x)-1)) else: sel.append((dd[1]*10 + dd[0])* 10 ** (len(x)-1)) for j in sel: for l in combinations_with_replacement(dd, len(x)-1): cnt = j for i in range(len(x)-1): cnt += 10 ** (len(x)-i-2) * l[i] if cnt >= n: lst.append(cnt) print(min(lst))
s292449210
p04045
u423966555
1597858935
Python
Python (3.8.2)
py
Runtime Error
26
9060
361
import itertools N, K = map(int, input().split()) D = list(map(int, input().split())) dic = [0,1,2,3,4,5,6,7,8,9] for i in D: dic.remove(i) dict = map(str, dic) n = len(str(N)) #何桁か ans = [] for i in range(2): for v in itertools.permutations(dict, n+i): if int(''.join(v)) >= N: ans.append(int(''.join(v))) print(min(ans))
s069531103
p04045
u070423038
1597810379
Python
Python (3.8.2)
py
Runtime Error
28
9068
847
kingaku, n = input().split() no_num = input().split() result = [] ok_num = [] kuriage_num = [-1, 0] def kuriage(l): for i in ok_num: if result[l] < i: kuriage_num = [l, i] return if l <= 0: return return kuriage(l-1) #使える数字のリストを作成 for i in range(10): if not str(i) in no_num: ok_num.append(str(i)) set_flg = False for i in kingaku: set_flg = True for j in ok_num: if i == j: set_flg = False result.append(j) break elif i < j: result.append(j) print("".join(result).ljust(len(kingaku), ok_num[0])) exit() break if set_flg: ok_num.remove('0') print(ok_num[0].ljust(len(kingaku)+1, '0')) exit() print(''.join(result))
s604122979
p04045
u573512968
1597736309
Python
Python (3.8.2)
py
Runtime Error
28
9160
579
N,k=map(int,input().split()) lst=list(map(int,input().split())) x=[] for i in range(10): x.append(i) for char in lst: if char in x: x.remove(char) # print(x) # x.sort( s=str(N) c=len(s) x.sort(reverse=True) ans="" flag=0 for j in range(10000000000): if len(ans)>=len(s): break else: ans+=str(x[j]) if j==len(x)-1: while j>0: ans+=str(x[len(x)-1]) if len(ans)>=len(s): flag=1 break if flag==1: break print(ans)
s290015299
p04045
u070423038
1597726070
Python
Python (3.8.2)
py
Runtime Error
25
9160
578
price, hate = input().split() no_num = set([x for x in input().split()]) ok_num = sorted(list({'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'} - no_num)) result = [] f = True exe = True for i in price: f = True for j in ok_num: if i <= j: result.append(j) f = False break if f and exe: exe = False result[-1] = str(int(result[-1]) + 1) for i in ok_num: if result[-1] < i: result[-1] = i break result.append(ok_num[-1]) print(''.join(result))
s239185871
p04045
u070423038
1597725994
Python
Python (3.8.2)
py
Runtime Error
30
9160
599
price, hate = input().split() no_num = set([x for x in input().split()]) ok_num = sorted(list({'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'} - no_num)) result = [] f = True exe = True for i in price: f = True for j in ok_num: if i <= j: print(j) result.append(j) f = False break if f and exe: exe = False result[-1] = str(int(result[-1]) + 1) for i in ok_num: if result[-1] < i: result[-1] = i break result.append(ok_num[-1]) print(''.join(result))
s410079526
p04045
u070423038
1597725908
Python
Python (3.8.2)
py
Runtime Error
29
9140
604
price, hate = input().split() no_num = set([x for x in input().split()]) ok_num = sorted(list({'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'} - no_num)) result = [] f = True exe = True for i in price: f = True for j in ok_num: if i <= j: print(j) result.append(j) f = False break if f and exe: exe = False result[-1] = str(int(result[-1]) + 1) for i in ok_num: if result[-1] < i: result[-1] = i break result.append(ok_num[-1]) print(''.join(result))
s821486022
p04045
u166012301
1597192825
Python
Python (3.8.2)
py
Runtime Error
26
9076
602
n, k = map(int, input().split()) n = str(n) d = [int(i) for i in input().split()] av_d = [str(i) for i in range(0, 10) if i not in d] number = '' for i in range(len(n)): managed = False for j in av_d: if i == 0 and j == '0': continue if j >= n[i]: number += j managed = True break if not managed: break if not managed: k = 0 for j in av_d: if j <= n[0] and j != '0': k = j break answ = '' answ += k answ += min(av_d) * (len(n)) print(answ) else: print(number)
s286768655
p04045
u166012301
1597192706
Python
Python (3.8.2)
py
Runtime Error
23
9084
606
n, k = map(int, input().split()) n = str(n) d = [int(i) for i in input().split()] av_d = [str(i) for i in range(0, 10) if i not in d] number = '' for i in range(len(n)): managed = False for j in av_d: if i == 0 and j == '0': continue if j >= n[i]: number += j managed = True break if not managed: break if not managed: k = 0 for j in av_d: if j <= n[0] and j != '0': k = j break answ = '' answ += k answ += min(av_d) * (len(n) - 1) print(answ) else: print(number)
s494013104
p04045
u166012301
1597192630
Python
Python (3.8.2)
py
Runtime Error
29
9132
602
n, k = map(int, input().split()) n = str(n) d = [int(i) for i in input().split()] av_d = [str(i) for i in range(0, 10) if i not in d] number = '' print(av_d) for i in range(len(n)): managed = False for j in av_d: if i == 0 and j == '0': continue if j >= n[i]: number += j managed = True break if not managed: break if not managed: k = 0 for j in av_d: if j <= n[0] and j != '0': k = j break answ = '' answ += k answ += min(av_d) * (len(n) - 1) else: print(number)
s849591694
p04045
u267718666
1596593175
Python
Python (3.8.2)
py
Runtime Error
30
9032
405
N, K = map(int, input().split()) D = set(map(int, input().split())) digits = list({0, 1, 2, 3, 4, 5, 6, 7, 8, 9} - D) N = str(N) res = '' for c in N: n_digit = int(c) if n_digit == digits[0]: res += str(digits[0]) continue for i in range(1, 10-K): if n_digit <= digits[i] and n_digit > digits[i-1]: res += str(digits[i]) break print(int(res))
s998426956
p04045
u396211450
1596012975
Python
Python (3.8.2)
py
Runtime Error
20
9056
308
def check(n,s): v=str(n) for i in v: if i in s: return False return True def solve(): n,k=mp() s=input().split() s=set(s) while True: if check(n,s): print(n) break else: n+=1 for _ in range(1): solve()
s810730093
p04045
u212831449
1595629637
Python
Python (3.8.2)
py
Runtime Error
23
9084
529
n,k = map(int,input().split()) d = list(map(int,input().split())) n_str = str(n) l = len(n_str) a = [i for i in range(10) if i not in d] #同じ桁の時 ans = "" for i in range(l): for j in a: if j == int(n_str[i]): ans += str(j) break elif j > int(n_str[i]): ans += str(j) + str(a[0])*(l-i-1) print(ans) exit() if int(ans) >= n: print(ans) exit() if 0 in a: ans = str(a[1]) + str(a[0])*l else: ans = str(a[0])*(l+1) print(ans)
s707628707
p04045
u254871849
1595539447
Python
Python (3.8.2)
py
Runtime Error
120
27644
18552
import sys import numpy as np from heapq import heappush, heappop from bisect import bisect_left as bi_l, bisect_right as bi_r from collections import deque, Counter, defaultdict from itertools import combinations, product import string inf = float('inf') MOD = 10**9+7 # MOD = 998244353 class NumberTheory(): def __init__(self, n=2*10**6, numpy=True): self.n = n self.np_flg = numpy self.is_prime_number, self.prime_numbers = self.sieve_of_eratosthenes(n) def sieve_of_eratosthenes(self, n): if self.np_flg: sieve = np.ones(n+1, dtype=np.int64); sieve[:2] = 0 for i in range(2, int(n**.5)+1): if sieve[i]: sieve[i*2::i] = 0 prime_numbers = np.flatnonzero(sieve) else: sieve = [1] * (n+1); sieve[0] = sieve[1] = 0 for i in range(2, int(n**.5)+1): if not sieve[i]: continue for j in range(i*2, n+1, i): sieve[j] = 0 prime_numbers = [i for i in range(2, n+1) if sieve[i]] return sieve, prime_numbers def prime_factorize(self, n): res = dict() if n < 2: return res border = int(n**.5) for p in self.prime_numbers: if p > border: break while n % p == 0: res[p] = res.get(p, 0)+1; n //= p if n == 1: return res res[n] = 1; return res def prime_factorize_factorial(self, n): res = dict() for i in range(2, n+1): for p, c in self.prime_factorize(i).items(): res[p] = res.get(p, 0)+c return res @staticmethod def gcd(a, b): return gcd(b, a%b) if b else abs(a) @staticmethod def lcm(a, b): return abs(a // gcd(a, b) * b) @staticmethod def find_divisors(n): divisors = [] for i in range(1, int(n**.5)+1): if n%i: continue divisors.append(i) j = n // i if j != i: divisors.append(j) return divisors @staticmethod def base_convert(n, b): if not n: return [0] res = [] while n: n, r = divmod(n, b) if r < 0: n += 1; r -= b res.append(r) return res class UnionFind(): def __init__(self, n=10**6): self.root = list(range(n)) self.height = [0] * n self.size = [1] * n def find_root(self, u): if self.root[u] == u: return u self.root[u] = self.find_root(self.root[u]) return self.root[u] def unite(self, u, v): ru = self.find_root(u) rv = self.find_root(v) if ru == rv: return hu = self.height[ru] hv = self.height[rv] if hu >= hv: self.root[rv] = ru self.size[ru] += self.size[rv] self.height[ru] = max(hu, hv+1) else: self.root[ru] = rv self.size[rv] += self.size[ru] class Combinatorics(): def __init__(self, N=10**9, n=10**6, mod=10**9+7, numpy=True): self.mod = mod self.nCr = dict() self.np_flg=numpy self.make_mod_tables(N, n) sys.setrecursionlimit(10**6) def choose(self, n, r, mod=None): # no mod, or mod ≠ prime if r > n or r < 0: return 0 if r == 0: return 1 if (n, r) in self.nCr: return self.nCr[(n, r)] if not mod: self.nCr[(n, r)] = (self.choose(n-1, r) + self.choose(n-1, r-1)) else: self.nCr[(n, r)] = (self.choose(n-1, r, mod) + self.choose(n-1, r-1, mod)) % mod return self.nCr[(n,r)] def cumprod(self, a): p = self.mod l = len(a); sql = int(np.sqrt(l)+1) a = np.resize(a, sql**2).reshape(sql, sql) for i in range(sql-1): a[:, i+1] *= a[:, i]; a[:, i+1] %= p for i in range(sql-1): a[i+1] *= a[i, -1]; a[i+1] %= p return np.ravel(a)[:l] def make_mod_tables(self, N, n): p = self.mod if self.np_flg: fac = np.arange(n+1); fac[0] = 1; fac = self.cumprod(fac) ifac = np.arange(n+1, 0, -1); ifac[0] = pow(int(fac[-1]), p-2, p) ifac = self.cumprod(ifac)[n::-1] n_choose = np.arange(N+1, N-n, -1); n_choose[0] = 1; n_choose[1:] = self.cumprod(n_choose[1:])*ifac[1:n+1]%p else: fac = [None]*(n+1); fac[0] = 1 for i in range(n): fac[i+1] = fac[i]*(i+1)%p ifac = [None]*(n+1); ifac[n] = pow(fac[n], p-2, p) for i in range(n, 0, -1): ifac[i-1] = ifac[i]*i%p n_choose = [None] * (n+1); n_choose[0] = 1 for i in range(n): n_choose[i+1] = n_choose[i]*(N-i)%p for i in range(n+1): n_choose[i] = n_choose[i]*ifac[i]%p self.fac, self.ifac, self.mod_n_choose = fac, ifac, n_choose def z_algorithm(s): n = len(s) a = [0] * n; a[0] = n l = r = -1 for i in range(1, n): if r >= i: a[i] = min(a[i-l], r-i) while i + a[i] < n and s[i+a[i]] == s[a[i]]: a[i] += 1 if i+a[i] >= r: l, r = i, i+a[i] return a class ABC001(): def A(): h1, h2 = map(int, sys.stdin.read().split()) print(h1-h2) def B(): pass def C(): pass def D(): pass class ABC002(): def A(): x, y = map(int, sys.stdin.readline().split()) print(max(x, y)) def B(): vowels = set('aeiou') s = sys.stdin.readline().rstrip() t = '' for c in s: if c in vowels: continue t += c print(t) def C(): *coords, = map(int, sys.stdin.readline().split()) def triangle_area(x0, y0, x1, y1, x2, y2): x1 -= x0; x2 -= x0; y1 -= y0; y2 -= y0; return abs(x1*y2 - x2*y1) / 2 print(triangle_area(*coords)) def D(): n, m = map(int, sys.stdin.readline().split()) edges = set() for _ in range(m): x, y = map(int, sys.stdin.readline().split()) x -= 1; y -= 1 edges.add((x, y)) cand = [] for i in range(1, 1<<n): s = [j for j in range(n) if i>>j & 1] for x, y in combinations(s, 2): if (x, y) not in edges: break else: cand.append(len(s)) print(max(cand)) class ABC003(): def A(): n = int(sys.stdin.readline().rstrip()) print((n+1)*5000) def B(): atcoder = set('atcoder') s, t = sys.stdin.read().split() for i in range(len(s)): if s[i] == t[i]: continue if s[i] == '@' and t[i] in atcoder: continue if t[i] == '@' and s[i] in atcoder: continue print('You will lose') return print('You can win') def C(): n, k, *r = map(int, sys.stdin.read().split()) res = 0 for x in sorted(r)[-k:]: res = (res+x) / 2 print(res) def D(): pass class ABC004(): def A(): print(int(sys.stdin.readline().rstrip())*2) def B(): c = [sys.stdin.readline().rstrip() for _ in range(4)] for l in c[::-1]: print(l[::-1]) def C(): n = int(sys.stdin.readline().rstrip()) n %= 30 res = list(range(1, 7)) for i in range(n): i %= 5 res[i], res[i+1] = res[i+1], res[i] print(''.join(map(str, res))) def D(): pass class ABC005(): def A(): x, y = map(int, sys.stdin.readline().split()) print(y//x) def B(): n, *t = map(int, sys.stdin.read().split()) print(min(t)) def C(): t = int(sys.stdin.readline().rstrip()) n = int(sys.stdin.readline().rstrip()) a = [int(x) for x in sys.stdin.readline().split()] m = int(sys.stdin.readline().rstrip()) b = [int(x) for x in sys.stdin.readline().split()] i = 0 for p in b: if i == n: print('no'); return while p-a[i] > t: i += 1 if i == n: print('no'); return if a[i] > p: print('no'); return i += 1 print('yes') def D(): n = int(sys.stdin.readline().rstrip()) d = np.array([sys.stdin.readline().split() for _ in range(n)], np.int64) s = d.cumsum(axis=0).cumsum(axis=1) s = np.pad(s, 1) max_del = np.zeros((n+1, n+1), dtype=np.int64) for y in range(1, n+1): for x in range(1, n+1): max_del[y, x] = np.amax(s[y:n+1, x:n+1] - s[0:n-y+1, x:n+1] - s[y:n+1, 0:n-x+1] + s[0:n-y+1, 0:n-x+1]) res = np.arange(n**2+1)[:, None] i = np.arange(1, n+1) res = max_del[i, np.minimum(res//i, n)].max(axis=1) q = int(sys.stdin.readline().rstrip()) p = np.array(sys.stdin.read().split(), dtype=np.int64) print(*res[p], sep='\n') class ABC006(): def A(): n = sys.stdin.readline().rstrip() if '3' in n: print('YES') elif int(n)%3 == 0: print('YES') else: print('NO') def B(): mod = 10007 t = [0, 0, 1] for _ in range(1001001): t.append(t[-1]+t[-2]+t[-3]); t[-1] %= mod n = int(sys.stdin.readline().rstrip()) print(t[n-1]) def C(): n, m = map(int, sys.stdin.readline().split()) cnt = [0, 0, 0] if m == 1: cnt = [-1, -1, -1] else: if m & 1: m -= 3; cnt[1] += 1; n -= 1 cnt[2] = m//2 - n cnt[0] = n - cnt[2] if cnt[0]<0 or cnt[1]<0 or cnt[2]<0: print(-1, -1, -1) else: print(*cnt, sep=' ') def D(): n, *c = map(int, sys.stdin.read().split()) lis = [inf]*n for x in c: lis[bi_l(lis, x)] = x print(n - bi_l(lis, inf)) class ABC007(): def A(): n = int(sys.stdin.readline().rstrip()) print(n-1) def B(): s = sys.stdin.readline().rstrip() if s == 'a': print(-1) else: print('a') def C(): r, c = map(int, sys.stdin.readline().split()) sy, sx = map(int, sys.stdin.readline().split()) gy, gx = map(int, sys.stdin.readline().split()) sy -= 1; sx -=1; gy -= 1; gx -= 1 maze = [sys.stdin.readline().rstrip() for _ in range(r)] queue = deque([(sy, sx)]) dist = np.full((r, c), np.inf); dist[sy, sx] = 0 while queue: y, x = queue.popleft() for i, j in [(-1, 0), (1, 0), (0, -1), (0, 1)]: i += y; j += x if maze[i][j] == '#' or dist[i, j] != np.inf: continue dist[i, j] = dist[y, x] + 1 queue.append((i, j)) print(int(dist[gy, gx])) def D(): pass class ABC008(): def A(): s, t = map(int, sys.stdin.readline().split()) print(t-s+1) def B(): n, *s = sys.stdin.read().split() res = defaultdict(int) for name in s: res[name] += 1 print(sorted(res.items(), key=lambda x: x[1])[-1][0]) def C(): n, *a = map(int, sys.stdin.read().split()) a = np.array(a) c = n - np.count_nonzero(a[:, None]%a, axis=1) print(np.sum((c+1)//2/c)) def D(): pass class ABC009(): def A(): n = int(sys.stdin.readline().rstrip()) print((n+1)//2) def B(): n, *a = map(int, sys.stdin.read().split()) print(sorted(set(a))[-2]) def C(): n, k = map(int, sys.stdin.readline().split()) s = list(sys.stdin.readline().rstrip()) cost = [1]*n r = k for i in range(n-1): q = [] for j in range(i+1, n): if s[j] < s[i] and cost[i]+cost[j] <= r: heappush(q, (s[j], cost[i]+cost[j], -j)) if not q: continue _, c, j = heappop(q); j = -j s[i], s[j] = s[j], s[i] r -= c cost[i] = cost[j] = 0 print(''.join(s)) def D(): pass class ABC010(): def A(): print(sys.stdin.readline().rstrip()+'pp') def B(): n, *a = map(int, sys.stdin.read().split()) tot = 0 for x in a: c = 0 while x%2==0 or x%3==2: x -= 1 c += 1 tot += c print(tot) def C(): sx, sy, gx, gy, t, v, n, *xy = map(int, sys.stdin.read().split()) x, y = np.array(xy).reshape(-1, 2).T def dist(x1, y1, x2, y2): return np.sqrt((x2-x1)**2 + (y2-y1)**2) ans = 'YES' if (dist(sx, sy, x, y)+dist(x, y, gx, gy) <= v*t).any() else 'NO' print(ans) def D(): pass class ABC011(): def A(): n = int(sys.stdin.readline().rstrip()) print(n%12+1) def B(): s = sys.stdin.readline().rstrip() print(s[0].upper()+s[1:].lower()) def C(): n, *ng = map(int, sys.stdin.read().split()) ng = set(ng) if n in ng: print('NO') else: r = 100 while n > 0: if r == 0: print('NO'); return for i in range(3, 0, -1): if (n-i) in ng: continue n -= i r -= 1 break else: print('NO'); return print('YES') def D(): pass class ABC041(): def A(): s, i = sys.stdin.read().split() i = int(i) print(s[i-1]) def B(): a, b, c = map(int, sys.stdin.readline().split()) ans = a * b % MOD * c % MOD print(ans) def C(): n, *a = map(int, sys.stdin.read().split()) for i, h in sorted(enumerate(a), key=lambda x: -x[1]): print(i+1) def D(): n, m, *xy = map(int, sys.stdin.read().split()) *xy, = zip(*[iter(xy)]*2) edges = [0] * n for x, y in xy: x -= 1; y -= 1 edges[x] |= 1<<y comb = [None] * (1<<n); comb[0] = 1 def count(edges, bit): if comb[bit] is not None: return comb[bit] comb[bit] = 0 for i in range(n): if (bit>>i) & 1 and not edges[i]: nxt_bit = bit & ~(1<<i) nxt_edges = edges.copy() for j in range(n): nxt_edges[j] &= ~(1<<i) cnt = count(nxt_edges, nxt_bit) comb[bit] += cnt return comb[bit] print(count(edges, (1<<n)-1)) class ABC042(): def A(): a = [int(x) for x in sys.stdin.readline().split()] c = Counter(a) print('YES' if c[5]==2 and c[7]==1 else 'NO') def B(): n, l, *s = sys.stdin.read().split() print(''.join(sorted(s))) def C(): n, k, *d = sys.stdin.read().split() l = len(n) ok = sorted(set(string.digits)-set(d)) cand = [int(''.join(p)) for p in product(ok, repeat=l)] + [int(min(ok-set([0]))+min(ok)*l)] print(cand[bi_l(cand, int(n))]) def D(): pass class ABC170(): def A(): x = [int(x) for x in sys.stdin.readline().split()] for i in range(5): if x[i] != i+1: print(i+1) break def B(): x, y = map(int, sys.stdin.readline().split()) print('Yes' if 2*x <= y <= 4*x and y%2 == 0 else 'No') def C(): x, n, *p = map(int, sys.stdin.read().split()) a = list(set(range(102)) - set(p)) a = [(abs(y-x), y) for y in a] print(sorted(a)[0][1]) def D(): n, *a = map(int, sys.stdin.read().split()) cand = set(a) cnt = 0 for x, c in sorted(Counter(a).items()): cnt += c == 1 and x in cand cand -= set(range(x*2, 10**6+1, x)) print(cnt) def E(): n, q = map(int, sys.stdin.readline().split()) queue = [] num_kindergarten = 2*10**5 queue_kindergarten = [[] for _ in range(num_kindergarten)] highest_kindergarten = [None] * num_kindergarten where = [None] * n rate = [None] * n def entry(i, k): where[i] = k while queue_kindergarten[k]: r, j = heappop(queue_kindergarten[k]) if where[j] != k or j == i: continue if rate[i] >= -r: highest_kindergarten[k] = rate[i] heappush(queue, (rate[i], k, i)) heappush(queue_kindergarten[k], (r, j)) break else: highest_kindergarten[k] = rate[i] heappush(queue, (rate[i], k, i)) heappush(queue_kindergarten[k], (-rate[i], i)) def transfer(i, k): now = where[i] while queue_kindergarten[now]: r, j = heappop(queue_kindergarten[now]) if where[j] != now or j == i: continue if highest_kindergarten[now] != -r: highest_kindergarten[now] = -r heappush(queue, (-r, now, j)) heappush(queue_kindergarten[now], (r, j)) break else: highest_kindergarten[now] = None entry(i, k) def inquire(): while True: r, k, i = heappop(queue) if where[i] != k or r != highest_kindergarten[k]: continue heappush(queue, (r, k, i)) return r for i in range(n): a, b = map(int, sys.stdin.readline().split()) rate[i] = a entry(i, b-1) for _ in range(q): c, d = map(int, sys.stdin.readline().split()) transfer(c-1, d-1) print(inquire()) def F(): pass class ABC171(): def A(): c = sys.stdin.readline().rstrip() print('A' if c < 'a' else 'a') def B(): n, k, *p = map(int, sys.stdin.read().split()) print(sum(sorted(p)[:k])) def C(): n = int(sys.stdin.readline().rstrip()) n -= 1 l = 1 while True: if n < pow(26, l): break n -= pow(26, l) l += 1 res = ''.join([chr(ord('a')+d%26) for d in NumberTheory.base_convert(n, 26)][::-1]) res = 'a'*(l-len(res)) + res print(res) def D(): n = int(sys.stdin.readline().rstrip()) a = [int(x) for x in sys.stdin.readline().split()] s = sum(a) cnt = Counter(a) q = int(sys.stdin.readline().rstrip()) for _ in range(q): b, c = map(int, sys.stdin.readline().split()) s += (c-b)*cnt[b] print(s) cnt[c] += cnt[b]; cnt[b] = 0 def E(): n, *a = map(int, sys.stdin.read().split()) s = 0 for x in a: s ^= x b = map(lambda x: x^s, a) print(*b, sep=' ') def F(): pass class ABC172(): def A(): pass def B(): pass def C(): pass def D(): pass def E(): pass def F(): pass class ABC173(): def A(): n = int(sys.stdin.readline().rstrip()) charge = (n+999)//1000 * 1000 - n print(charge) def B(): n, *s = sys.stdin.read().split() c = Counter(s) for v in 'AC, WA, TLE, RE'.split(', '): print(f'{v} x {c[v]}') def C(): h, w, k = map(int, sys.stdin.readline().split()) c = [sys.stdin.readline().rstrip() for _ in range(h)] tot = 0 for i in range(1<<h): for j in range(1<<w): cnt = 0 for y in range(h): for x in range(w): if i>>y & 1 or j>>x & 1: continue cnt += c[y][x] == '#' tot += cnt == k print(tot) def D(): n, *a = map(int, sys.stdin.read().split()) a.sort(reverse=True) res = a[0] + sum(a[1:1+(n-2)//2])*2 + a[1+(n-2)//2]*(n & 1) print(res) def E(): MOD = 10**9+7 n, k, *a = map(int, sys.stdin.read().split()) minus = [x for x in a if x < 0] plus = [x for x in a if x > 0] if len(plus) + len(minus)//2*2 >= k: # plus *minus, = map(abs, minus) minus.sort(reverse=True) plus.sort(reverse=True) cand = [] if len(minus)&1: minus = minus[:-1] for i in range(0, len(minus)-1, 2): cand.append(minus[i]*minus[i+1]%MOD) if k & 1: res = plus[0] plus = plus[1:] else: res = 1 if len(plus)&1: plus = plus[:-1] for i in range(0, len(plus)-1, 2): cand.append(plus[i]*plus[i+1]%MOD) cand.sort(reverse=True) for x in cand[:k//2]: res *= x res %= MOD print(res) elif 0 in a: print(0) else: cand = sorted(map(abs, a)) res = 1 for i in range(k): res *= cand[i] res %= MOD res = MOD - res print(res) pass def F(): pass if __name__ == '__main__': ABC042.C()
s063927303
p04045
u465101448
1595516832
Python
Python (3.8.2)
py
Runtime Error
20
9152
416
N,K = list(map(int,input().split())) D = list(map(int,input().split())) D_ = [_ for _ in range(10) if _ not in D] D_.sort() N_=N+1 break_flag=False for s_ in D_: if break_flag: break elif s_ == 0: continue for p in product(D_,repeat=len(str(N_))-1): ans=int(str(s_)+''.join(map(str,p))) if N+1 <= ans: print(ans) break_flag=True break
s104652535
p04045
u112065131
1595452984
Python
Python (3.8.2)
py
Runtime Error
25
9156
534
# -*- coding: utf-8 -*- # C - こだわり者いろはちゃん N, K = map(int, input().split()) D = list(map(int, input().split())) numList = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] listAns = [] num = [] listN = [int(x) for x in list(str(N))] # print(listN) for i in numList: if i not in D: num.append(i) # print(num) for i in listN: for j in num: if j >= i: listAns.append(j) break # print(listAns) ans = int(reduce(lambda x, y: x + y, [str(x) for x in listAns])) print(ans)
s685528682
p04045
u687574784
1595105814
Python
Python (3.8.2)
py
Runtime Error
32
9084
250
N,K = list(map(int, input().split())) D = set(input().split()) # シミュレーションでいける for ans in range(N,10000): if all(d not in D for d in str(ans)): print(ans) exit() raise AssertionError('バグってる')
s123932140
p04045
u706414019
1594943656
Python
Python (3.8.2)
py
Runtime Error
63
17344
382
import sys,math,collections,itertools,bisect input = sys.stdin.readline N,K=list(map(int,input().split())) D = list(map(int,input().split())) Ds = set([0,1,2,3,4,5,6,7,8,9])-set(D) can = list(itertools.product(Ds,repeat = 5)) candi = [] for c in can: candi.append(1**4*c[0]+10**3*c[1]+10**2*c[2]+10**1*c[3]+c[4]) candi = sorted(candi) print(candi[bisect.bisect_left(candi,N)])
s543903491
p04045
u543373102
1594870113
Python
Python (3.8.2)
py
Runtime Error
28
9160
136
N , K = input().split() Dk = list(map(int, input().split())) for i in range(N,10*N+1): if set(i)&set(Dk) == set(): print(i)
s178243476
p04045
u543373102
1594869476
Python
Python (3.8.2)
py
Runtime Error
24
9172
147
N , K = map(int, input().split()) Dk = list(map(int, input().split())) for i in range(N,10*N+1): if set(i)&set(Dk) == set(): print(i)
s345758312
p04045
u081149041
1594256187
Python
Python (3.8.2)
py
Runtime Error
21
8940
313
def digit(): N, K = [int(n) for n in input().split()] digit = [int(n) for n in input().split()] for i in range(N, N*10): b = i while b != 0: if (b % 10) in digit: break b /= 10 if b == 0: print(i) break: digit()
s186357659
p04045
u081149041
1594256061
Python
Python (3.8.2)
py
Runtime Error
23
9024
313
def digit(): N, K = [int(n) for n in input().split()] digit = [int(n) for n in input().split()] for i in range(N, N*10): b = i while b != 0: if (b % 10) in digit: break b /= 10 if b == 0: print(i) break: digit()
s991773600
p04045
u819135704
1593529626
Python
Python (3.8.2)
py
Runtime Error
27
9172
452
N, K = map(int, input().split()) l = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] for _ in range(K): l.remove(int(input())) n = [int(x) for x in str(N)] c = len(n) max = l[0] min = l[-1] if N > 1111 * max: b = 10000*min([i for i in l if i>0]) + 1111*min else: a = [max] * c for j in range(c): if a[j] > n[j]: a[j] = min([i for i in l if i>=n[j]]) b = "" for j in range(c): b += str(a[j]) b = int(b) print(b)
s303233451
p04045
u867848444
1593454377
Python
Python (3.8.2)
py
Runtime Error
25
8924
366
from bisect import * n, k = map(int,input().split()) d = list(map(int,input().split())) use_num = [] for i in range(10): if i in d:continue use_num.append(i) str_n = str(n) res = 0 for i in str_n: temp = bisect_left(use_num, int(i)) add = use_num[temp] if temp == len(use_num): add = use_num[0] * 10 res = res * 10 + add print(res)
s499065609
p04045
u867848444
1593454257
Python
Python (3.8.2)
py
Runtime Error
30
9192
292
from bisect import * n, k = map(int,input().split()) d = list(map(int,input().split())) use_num = [] for i in range(10): if i in d:continue use_num.append(i) str_n = str(n) res = 0 for i in str_n: temp = bisect_left(use_num, int(i)) res = res * 10 + use_num[temp] print(res)