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
s755849830
p04035
u107077660
1470015814
Python
Python (3.4.3)
py
Runtime Error
102
14304
349
N, M = map(int, input().split()) x = [] y = [] for i in range(1,M+1): z = list(map(int,input().split())) x.append(z[0]) y.append(z[1]) a = [0] b = [1]*N for i in range(M): b[x[i]-1] -= 1 b[y[i]-1] += 1 if x[i]-1 in a: a.append(y[i]-1) if b[x[i]-1] == 0: a.remove(x[i]-1) c = 0 for i in range(len(a)): if b[a[i]] != 0: c += 1 print(c)
s058771279
p04037
u423585790
1590705292
Python
PyPy3 (2.4.0)
py
Runtime Error
173
38384
138
n=int(input()) a=sorted(map(int,input().split()))[::-1] j=i=0 while n:i+=a[i]>i;j+=a[j]>=i,n-=1 print('SFeicrosntd'[(a[i-1]^i|j^i)&1::2])
s579115943
p04037
u423585790
1590705225
Python
PyPy3 (2.4.0)
py
Runtime Error
177
38548
142
n=int(input()) a=sorted(map(int,input().split()))[::-1] j=i=x=0 while x<n:i+=a[i]>i;j+=a[j]>=i,x+=1 print('SFeicrosntd'[(a[i-1]^i|j^i)&1::2])
s548095993
p04037
u102461423
1574525171
Python
Python (3.4.3)
py
Runtime Error
82
12596
355
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N,*A = map(int,read().split()) A.sort(reverse = True) A.append(0) i = 0 while A[i + 1] < i + 1: i += 1 x = A[i] - (i + 1) y = max(j for j in range(N) if A[j] <= i + 1) - i answer = 'First' if x&1 or y&1 else 'Second' print(answer)
s121873961
p04037
u892251744
1569943181
Python
PyPy3 (2.4.0)
py
Runtime Error
2106
63856
798
N = int(input()) a = list(map(int, input().split())) a.sort(reverse=True) i = 0 j = N-1 t = 0 while True: j -= 1 if i == j: if (a[i] - t) % 2 == 1: win1 = 0 else: win1 = 1 break t += 1 while a[i] == t: i += 1 if i == j: if (a[i] - t) % 2 == 1: win1 = 1 else: win1 = 0 break i = 0 j = N-1 t = 0 while True: t += 1 while a[i] == t: i += 1 if i == j: if (a[i] - t) % 2 == 1: win2 = 0 else: win2 = 1 break j -= 1 if i == j: if (a[i] - t) % 2 == 1: win2 = 1 else: win2 = 0 break if win1 == 1 and win2 == 1: print('Second') else: print('First')
s470846087
p04037
u945080461
1470027198
Python
Python (2.7.6)
py
Runtime Error
281
11568
1512
from sys import stdin from collections import deque n = int(stdin.readline()) a = map(int, stdin.readline().split()) a.sort() f = 1 q = deque(a) t = 1 while 1: if len(q) == 1: f = (q[0] - t + 1) & 1 ^ 1 break if t == q[0] == q[-1]: f = len(q) & 1 ^ 1 break x = q.pop() if len(q) == 1 and (q[0] - t + 1) & 1: f = 1 break if t == q[0] == q[-1] and len(q) & 1: f = 1 break q.append(x) while q and q[0] == t: q.popleft() t += 1 if len(q) == 1 and (q[0] - t + 1) & 1: f = 1 break if t == q[0] == q[-1] and len(q) & 1: f = 1 break q.pop() if not q: f = 0 break print "First" if f else "Second" from sys import stdin from collections import deque n = int(stdin.readline()) a = map(int, stdin.readline().split()) a.sort() f = 1 q = deque(a) t = 1 while 1: if len(q) == 1: f = (q[0] - t + 1) & 1 ^ 1 break if t == q[0] == q[-1]: f = len(q) & 1 ^ 1 break x = q.pop() if len(q) == 1 and (q[0] - t + 1) & 1: f = 1 break if t == q[0] == q[-1] and len(q) & 1: f = 1 break q.append(x) while q and q[0] == t: q.popleft() t += 1 if len(q) == 1 and (q[0] - t + 1) & 1: f = 1 break if t == q[0] == q[-1] and len(q) & 1: f = 1 break q.pop() if not q: f = 0 break print "First" if f else "Second"
s491346115
p04037
u945080461
1470019685
Python
Python (2.7.6)
py
Runtime Error
26
2568
389
a = map(int, stdin.readline().split()) a.sort() def f(j, t): global n for i in xrange(j, n): if a[i] != a[j]: break else: i = n x = (a[j] - t) & 1 y = (i - j) & 1 if i == n: return x ^ y elif (a[j] - t) == 1: return not f(i, a[j]) else: return x ^ y ^ ((n - i) & 1) print "First" if f(0, 0) else "Second"
s931866396
p04037
u277373937
1470019224
Python
Python (2.7.6)
py
Runtime Error
1436
114784
952
import numpy as np input1 = raw_input() input2 = raw_input() N = int(input1) list = input2.split() a = np.zeros(len(list), np.uint8) for i, element in enumerate(list): a[i] = int(element) def play(turn, a, N): if N == 1 and a[0] == 1: if turn % 2 == 0: print 'Second' else: print 'First' return 0 if (a - 1).sum() == 1: if turn % 2 == 0: print 'First' else: print 'Second' return 0 if N == 2 and a.min() == 1: if turn % 2 == 0: print 'First' else: print 'Second' return 0 if N == 2 and (a - 1).sum == 2: if turn % 2 == 0: print 'Second' else: print 'First' return 0 if N == 1: a[0] -= 1 play(turn + 1, a, 1) else: a[np.argmax(a)] = 0 play(turn + 1, a[a > 0], N-1) play(0, a, N)
s589605561
p04037
u277373937
1470018893
Python
Python (2.7.6)
py
Runtime Error
1422
114784
805
import numpy as np input1 = raw_input() input2 = raw_input() N = int(input1) list = input2.split() a = np.zeros(len(list), np.uint8) for i, element in enumerate(list): a[i] = int(element) def play(turn, a, N): if N == 1 and a[0] == 1: if turn % 2 == 0: print 'Second' else: print 'First' return 0 if (a - 1).sum() == 1: if turn % 2 == 0: print 'First' else: print 'Second' return 0 if N == 2 and a.min() == 1: if turn % 2 == 0: print 'First' else: print 'Second' return 0 if N == 1: a[0] -= 1 play(turn + 1, a, 1) else: a[np.argmax(a)] = 0 play(turn + 1, a[a > 0], N-1) play(0, a, N)
s619177586
p04037
u277373937
1470018689
Python
Python (2.7.6)
py
Runtime Error
1437
114780
662
import numpy as np input1 = raw_input() input2 = raw_input() N = int(input1) list = input2.split() a = np.zeros(len(list), np.uint8) for i, element in enumerate(list): a[i] = int(element) def play(turn, a, N): if N == 1 and a[0] == 1: if turn % 2 == 0: print 'Second' else: print 'First' return 0 if (a - 1).sum() == 1: if turn % 2 == 0: print 'First' else: print 'Second' return 0 if N == 1: a[0] -= 1 play(turn + 1, a, 1) else: a[np.argmax(a)] = 0 play(turn + 1, a[a > 0], N-1) play(0, a, N)
s788201309
p04039
u385551158
1601249802
Python
Python (3.8.2)
py
Runtime Error
31
9144
818
s = input() s = s.split(" ") N = s[0] K = int(s[1]) s = input() s = s.split(" ") ds = [int(digit) for digit in s] minNum = min([digit for digit in range(0, 10) if digit not in ds]) maxNum = max([digit for digit in range(0, 10) if digit not in ds]) digits = [int(digit) for digit in N] result = N for index in range(0, len(digits)): digit = digits[index] if digit in ds: i = index if digit > maxNum: i = index - 1 while i >= 0 and digits[i] == maxNum: i -= 1 if i < 0: result = str(minNum) * (len(N) + 1) else: biggerDigit = min([d for d in range(0, 10) if d not in ds and d > digits[i]]) digits[i] = biggerDigit for j in range(i+1, len(digits)): digits[j] = minNum result = "".join([str(digit) for digit in digits]) print(result)
s496028011
p04039
u385551158
1601249427
Python
Python (3.8.2)
py
Runtime Error
27
9200
739
s = input() s = s.split(" ") N = s[0] K = int(s[1]) s = input() s = s.split(" ") ds = [int(digit) for digit in s] minNum = min([digit for digit in range(0, 10) if digit not in ds]) maxNum = max([digit for digit in range(0, 10) if digit not in ds]) digits = [int(digit) for digit in N] result = N for index in range(0, len(digits)): digit = digits[index] if digit in ds: i = index if digit > maxNum: i = index - 1 while i >= 0 and digits[i] == maxNum: i -= 1 if i < 0: result = str(minNum) * (len(N) + 1) else: biggerDigit = min([d for d in range(0, 10) if d not in ds and d > digits[i]]) result = N[:i] + str(biggerDigit) + (str(minNum) * (len(N) - i - 1)) print(result)
s482817317
p04039
u374051158
1596038528
Python
Python (3.8.2)
py
Runtime Error
25
9080
228
n, k = map(int, input().split()) d = list(map(int, input().split())) def is_ok(num): s = str(num) for ng in d: if ng in s: return False return True while True: if is_ok(n): print(n) exit() n += 1
s676207138
p04039
u437215432
1592233708
Python
Python (3.4.3)
py
Runtime Error
20
3064
619
# ARC058A import itertools n, k = map(int, input().split()) d = set(input().split()) # n, k = map(int, '1110 8'.split()) # d = set('1 3 4 5 6 7 8 9'.split()) valid = {'0', '1', '2', '3', '4', '5', '7', '6', '7', '8', '9'} d2 = list(valid - d) n2 = list(str(n)) pos = [] for i, c in enumerate(n2): if c not in d2: pos.append(i) combinations = list(itertools.product(d2, repeat=len(pos))) ans = [] for combination in combinations: for i in pos: n2[i] = combination[i] num = int(''.join(n2)) ans.append(num) for i in sorted(ans): if i >= n: print(i) break
s907848109
p04039
u658113376
1590365441
Python
Python (3.4.3)
py
Runtime Error
18
3064
1447
oldMoney, hateNumberLength = map(list, input().split()) hateLines = list(str(input()).rsplit(" ")) okLines = [] FirstBigList = [] newMoney = list(oldMoney) def FindFirstBig(okLines,m,FirstBig): for i in okLines: if i > m: FirstBig.append(i) return FirstBig for i in range(10): if str(i) not in hateLines: okLines.append(str(i)) FirstFlag = -1 ProblemFlag = -1 for index, m in enumerate(oldMoney): if FirstFlag == -1: if m in hateLines: FirstBigList = FindFirstBig(okLines,m,FirstBigList) if len(FirstBigList) > 0: newMoney[index] = FirstBigList[0] FirstFlag = index ProblemFlag = index elif FirstFlag != -1: newMoney[index] = okLines[0] if oldMoney == newMoney: if ProblemFlag is not 0: FirstBigList.clear() while ProblemFlag: FirstBigList = FindFirstBig(okLines, newMoney[ProblemFlag - 1], FirstBigList) if len(FirstBigList) > 0: newMoney[ProblemFlag - 1] = FirstBigList[0] for i in range(ProblemFlag,len(newMoney),1): newMoney[i] = okLines[0] if oldMoney == newMoney: ProblemFlag -= 1 if ProblemFlag is 0: newMoney.insert(0,okLines[0]) for i in range(ProblemFlag, len(newMoney), 1): newMoney[i] = okLines[0] resultnew = "".join(newMoney) print(resultnew)
s686502094
p04039
u658113376
1590359530
Python
Python (3.4.3)
py
Runtime Error
18
3064
394
oldMoney, hateNumberLength = map(list, input().split()) hateLines = list(str(input()).rsplit(" ")) okLines = [] #newMoney = 0 for i in range(10): if str(i) not in hateLines and str(i) > oldMoney[0]: okLines.append(i) for index,m in enumerate(oldMoney): if m in hateLines and okLines is not None: oldMoney[index] = str(okLines[0]) result = "".join(oldMoney) print(result)
s345856215
p04039
u658113376
1590359272
Python
Python (3.4.3)
py
Runtime Error
17
3064
372
oldMoney, hateNumberLength = map(list, input().split()) hateLines = list(str(input()).rsplit(" ")) okLines = [] newMoney = 0 for i in range(10): if str(i) not in hateLines and str(i) > oldMoney[0]: okLines.append(i) for index,m in enumerate(oldMoney): if m in hateLines and okLines is not None: oldMoney[index] = okLines[0] print("".join(oldMoney))
s413011872
p04039
u110580875
1586200690
Python
Python (3.4.3)
py
Runtime Error
17
3064
499
import sys n,k=map(int,input().split()) d=list(map(int,input().split())) num=[] sub=[] ans="" for i in [0,1,2,3,4,5,6,7,8,9]: if i not in d: num.append(i) n=str(n) for i in range(int(len(n))): if len(ans)>0: if int(ans[0])>=int(n[i-1]): subans=ans for w in range(int(len(n))-i): ans+="0" if ans>=n: print(ans) sys.exit() else: ans=subans for j in num: if j>=int(n[i]): sub.append(j) ans+=str(min(sub)) print(ans)
s314760694
p04039
u110580875
1586199710
Python
Python (3.4.3)
py
Runtime Error
17
3064
472
import sys n,k=map(int,input().split()) d=list(map(int,input().split())) num=[] ans="" sub=[] for i in [0,1,2,3,4,5,6,7,8,9]: if i not in d: num.append(i) n=str(n) for i in range(len(n)): if len(ans)>0: if str(ans[0])>=n[i-1] and min(num)>=int(n[i]): for w in range(int(len(n))-i): ans+=str(min(num)) print(ans) sys.exit() for j in num: if j>=int(n[i]): sub.append(j) break ans+=str(min(sub)) print(ans)
s541426369
p04039
u110580875
1586199692
Python
Python (3.4.3)
py
Runtime Error
17
3064
461
import sys n,k=map(int,input().split()) d=list(map(int,input().split())) num=[] ans="" sub=[] for i in [0,1,2,3,4,5,6,7,8,9]: if i not in d: num.append(i) n=str(n) for i in range(len(n)): if len(ans)>0: if str(ans[0])>=n[i-1] and min(num)>=int(n[i]): for w in range(int(len(n))-i): ans+=str(min(num)) print(ans) sys.exit() for j in num: if j>=int(n[i]): sub.append(j) break ans+=str(min(sub))
s620501472
p04039
u878849567
1586197233
Python
Python (3.4.3)
py
Runtime Error
28
2940
200
n, k = map(int, input().split()) d = list(input().split()) for i in reversed(range(n, 10001)): for j in range(k): if d[j] in str(i): break else: ans = i print(ans)
s692430555
p04039
u102242691
1585369984
Python
Python (3.4.3)
py
Runtime Error
17
2940
183
n,m = input().split() k = int(n) l = list(input().split()) for i in range(k,100000): for x in l: for x str(i): break else: print(i) break
s090509318
p04039
u102242691
1585369831
Python
Python (3.4.3)
py
Runtime Error
17
2940
184
n,m = input().split() k = int(n) l = list(input().split()) for i in range(k,100000): for x in l: for y str(i): break else: print(i) break
s916274699
p04039
u328067859
1583258350
Python
Python (3.4.3)
py
Runtime Error
17
3060
174
n,k = map(int, input().split()) d = list(map(int, input().split())) e = [0,1,2,3,4,5,6,7,8,9] d = e - d for i in d: for j in d: if int(ij) >= n: print(ij)
s451800067
p04039
u018679195
1580538090
Python
PyPy3 (2.4.0)
py
Runtime Error
168
38384
234
n, k = map(int, input().split()) d = map(str, input().split()) digits = set(d) num = {str(i) for i in range(0,10)} left = num - digits for i in range(N, 100000): Num = set(str(i)) if Num <= left: print(i) break
s623820988
p04039
u021759654
1573271703
Python
Python (3.4.3)
py
Runtime Error
17
3060
186
n, k = map(int, input().split()) Ds = list(map(int, input().split())) for i in range(n, n*11): for d in Ds: if d in int(list(str(i))): break else: print(i) exit(0)
s789529389
p04039
u141610915
1566527408
Python
Python (3.4.3)
py
Runtime Error
19
3064
495
from bisect import bisect_left as bl N, K = map(list, input().split()) D = list(map(int, input().split())) D = [i for i in range(10) if not i in D] res = [] big = 0 if int("".join([str(D[-1])] * len(N))) < int("".join(N)): if D[0] == 0: res = [D[1]] + [0] * len(N) else: res = [D[1]] * (len(N) + 1) else: for i in range(len(N)): if big == 0: res.append(D[bl(D, int(N[i]))]) else: res.append(D[0]) if res[i] > int(N[i]): big = 1 print("".join(list(map(str, res))))
s005716656
p04039
u778814286
1561847305
Python
PyPy3 (2.4.0)
py
Runtime Error
164
38256
1835
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pll = pair<ll, ll> ; using pld = pair<ld, ld>; const int INF=1e9+7; const ll LINF=1LL<<60 ; const ll MOD=1e9+7 ; const ld PI=acos(-1); const ld EPS = 1e-9; //微調整用(EPSより小さいと0と判定など) #define gcd __gcd //llは受け取ってくれない int lcm(int a, int b){return a / gcd(a, b) * b;} #define ALL(a) a.begin(),a.end() //sort(ALL(vec)); #define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i ) #define rep(i,n) REP(i,0,n) #define MP(a,b) make_pair(a,b) #define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end())))) #define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin()) #define PB push_back #define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに //最大値、最小値を更新する。aよりbのが大きい(小さい)か等しければaを更新してtrueを返す。そうでなければ何もせずfalseを返す chmax(nowmax,x); template<typename T> bool chmax(T& a, T b){return (a = max(a, b)) == b;} template<typename T> bool chmin(T& a, T b){return (a = min(a, b)) == b;} // ----- template end ---- // // ------- library ------- // // ----- library end ----- // int main() { string N; ll K; cin >> N >> K; set<char> NOs; rep(i,K){ char a; cin >> a; NOs.insert(a); } bool ansflag = false; //答えが見つかったら1 int ans = 0; REP(i, stoi(N), 100000){ ansflag = true; //一旦1にする for (char c : to_string(i)){ if (NOs.find(c) != NOs.end()){ //もしcがNOsに入っていたら(ダメな数字を使っていたら) ansflag = false; } } if (ansflag){ ans = i; break; } } cout << ans << endl; }
s176588490
p04039
u139937121
1560589384
Python
Python (2.7.6)
py
Runtime Error
21
3324
857
import collections, heapq, math, sys n, k = map(int, sys.stdin.readline().rstrip().split(' ')) dislikes = map(int, sys.stdin.readline().rstrip().split(' ')) dislikess= set(dislikes) for i in range(9): if i not in dislikess: smallest = i break cp = n s = [] while cp: s.append(cp%10) cp //= 10 s.append(0) idx = -1 found = True for i in range(len(s)): z = s[i] if i == len(s) - 1 and not found: s[i] = smallest idx = i-1 break if not found or z in dislikess: found = False for j in range(z+1, 10): if j not in dislikes: s[i] = j found = True break if not found: idx = i else: idx = i - 1 else: found = True if s[-1] == 0: s.pop() for i in range(idx+1): s[i] = smallest ret = 0 while len(s): ret *= 10 ret += s.pop() print(ret)
s280834946
p04039
u798129018
1558155477
Python
PyPy3 (2.4.0)
py
Runtime Error
187
38512
875
from itertools import* from math import* from collections import* from heapq import* from bisect import bisect_left,bisect_right from copy import deepcopy inf = 10**18 mod = 10**9+7 from functools import reduce import sys sys.setrecursionlimit(10**7) H,W,A,B = map(int,input().split()) fac = [0]*(H+W) finv = [0]*(H+W) inv = [0]*(H+W) fac[0]=fac[1]=1 finv[0]=finv[1]=1 inv[1]=1 for i in range(2,H+W): fac[i] = fac[i-1] * i % mod inv[i] = mod - inv[mod%i]*(mod//i)%mod finv[i] = finv[i-1]*inv[i]%mod def comb(n,r): if n < r: return 0 if n < 0 or r < 0 : return 0 return fac[n]*(finv[r]*finv[n-r]%mod)%mod ans = 0 for x in range(W-B): if x == 0: ans += ((comb(H-A-1+B+x,B+x))*comb(A+W-1-B-x,A)) else: ans += ((comb(H-A-1+B+x,B+x)-comb(H-A-1+B+x-1,B+x-1))*comb(A+W-1-B-x,A)) ans %= mod print(ans)
s974524719
p04039
u798129018
1558155456
Python
PyPy3 (2.4.0)
py
Runtime Error
166
38256
622
H,W,A,B = map(int,input().split()) fac = [0]*(H+W) finv = [0]*(H+W) inv = [0]*(H+W) fac[0]=fac[1]=1 finv[0]=finv[1]=1 inv[1]=1 for i in range(2,H+W): fac[i] = fac[i-1] * i % mod inv[i] = mod - inv[mod%i]*(mod//i)%mod finv[i] = finv[i-1]*inv[i]%mod def comb(n,r): if n < r: return 0 if n < 0 or r < 0 : return 0 return fac[n]*(finv[r]*finv[n-r]%mod)%mod ans = 0 for x in range(W-B): if x == 0: ans += ((comb(H-A-1+B+x,B+x))*comb(A+W-1-B-x,A)) else: ans += ((comb(H-A-1+B+x,B+x)-comb(H-A-1+B+x-1,B+x-1))*comb(A+W-1-B-x,A)) ans %= mod print(ans)
s435942107
p04039
u095426154
1558143184
Python
PyPy3 (2.4.0)
py
Runtime Error
169
38256
427
h,w,a,b=map(int,input().split()) arr=[[0 for i in range(w)] for i in range(h)] for i in range(h): for j in range(w): if i>=h-a and j<=b-1: continue if i==0 and j==0: arr[i][j]=1 elif i==0: arr[i][j]=arr[i][j-1] elif j==0: arr[i][j]=arr[i-1][j] else: arr[i][j]=arr[i-1][j]+arr[i][j-1] ans=arr[h-1][w-1]%(10**9+7) print(ans)
s766832393
p04039
u882620594
1554900265
Python
Python (3.4.3)
py
Runtime Error
25
3060
328
import sys N, K = map(int,input().split()) D = list(input().split()) flg = 1 for i in range(N, 10001): flg = 1 cost = str(i) digit = len(cost) for j in range(digit): if cost[j] in D: flg = 0 break if flg == 1: print(cost) sys.exit() print("error") sys.exit(1)
s735362977
p04039
u450339194
1554589042
Python
Python (3.4.3)
py
Runtime Error
21
3064
593
import itertools N, K = map(int, input().split()) Ds = list(map(int, input().split())) NDs = list(set([i for i in range(10)]) - set(Ds)) NDs = list(map(str, NDs)) min_price = 10000 for p in itertools.product(NDs, repeat=len(str(N))): if p[0] == '0': continue price = int(''.join(p)) if price < N: continue min_price = min(price, min_price) if min_price == 10000: for p in itertools.product(NDs, repeat=len(str(N)+1)): if p[0] == '0': continue price = int(''.join(p)) min_price = min(price, min_price) print(min_price)
s844057985
p04039
u346194435
1553286463
Python
Python (3.4.3)
py
Runtime Error
18
3064
1104
import bisect N, K = input().split() dList = [int(x) for x in input().split()] useList = [0,1,2,3,4,5,6,7,8,9] for d in dList: useList.remove(d) result = '' if int(N[0]) > max(useList): # 桁上げが必要 if useList[0] != 0: result += str(useList[0]) else: result += str(useList[1]) result += str(useList[0])*(len(N)-1) else: for i in range(len(N)): a = int(N[i]) if a in useList: result += N[i] continue else: count = 0 if a > max(useList): while not max(useList) > int(result[-1]): count += 1 result = result[:-1] count += 1 sect = int(result[-1]) result = result[:-1] result += str(useList[bisect.bisect_right(useList, sect)]) result += str(useList[0])*(len(N)-len(result)) else: result += str(useList[bisect.bisect_right(useList, a)]) result += str(useList[0])*(len(N)-i-1) break print(result)
s945375472
p04039
u346194435
1553285406
Python
Python (3.4.3)
py
Runtime Error
18
3064
883
import bisect N, K = input().split() dList = [int(x) for x in input().split()] useList = [0,1,2,3,4,5,6,7,8,9] for d in dList: useList.remove(d) result = '' if int(N[0]) > max(useList): # 桁上げが必要 if useList[0] != 0: result += str(useList[0]) else: result += str(useList[1]) result += str(useList[0])*(len(N)-1) else: for i in range(len(N)): a = int(N[i]) if a in useList: result += N[i] continue else: if a > max(useList): result = result[:-1] result += str(useList[bisect.bisect_right(useList, int(N[i-1]))]) result += str(useList[0])*(len(N)-i) else: result += str(useList[bisect.bisect_right(useList, a)]) result += str(useList[0])*(len(N)-i-1) break print(result)
s845867428
p04039
u367130284
1552349132
Python
Python (3.4.3)
py
Runtime Error
18
2940
103
n,_=input().split();s={*input()};n=int(n);print(n+[len(s&set(str(b)))for b in range(n,99999)].index(0))
s652320084
p04039
u729133443
1552349098
Python
Python (3.4.3)
py
Runtime Error
82
2940
67
n=int(input()[:4]);a=set(input()) while a&set(str(n)):n+=1 print(n)
s252807386
p04039
u729133443
1552349073
Python
Python (3.4.3)
py
Runtime Error
84
2940
67
n=int(input()[:5]);a=set(input()) while a&set(str(n)):n+=1 print(n)
s274577543
p04039
u346194435
1551896120
Python
Python (3.4.3)
py
Runtime Error
21
3064
652
import bisect N, K = input().split() dList = [int(x) for x in input().split()] useList = [0,1,2,3,4,5,6,7,8,9] for d in dList: useList.remove(d) result = '' if int(N[0]) > max(useList): # 桁上げが必要 if useList[0] != 0: result += str(useList[0]) else: result += str(useList[1]) result += str(useList[0])*(len(N)-1) else: for i in range(len(N)): a = int(N[i]) if a in useList: result += N[i] continue else: result += str(useList[bisect.bisect_right(useList, a)]) result += str(useList[0])*(len(N)-i-1) break print(result)
s904159342
p04039
u346194435
1551895927
Python
Python (3.4.3)
py
Runtime Error
18
3064
650
import bisect N, K = input().split() dList = [int(x) for x in input().split()] useList = [0,1,2,3,4,5,6,7,8,9] for d in dList: useList.remove(d) result = '' if int(N[0]) > max(useList): # 桁上げが必要 if useList[0] != 0: result += str(useList[0]) else: result += str(useList[1]) result += str(useList[0])*(len(N)-1) else: for i in range(len(N)): a = int(N[i]) if a in useList: result += N[i] continue else: result += str(useList[bisect.bisect_right(useList, a)]) result += str(useList[0])*(len(N)-i) break print(result)
s084473212
p04039
u585482323
1547766686
Python
PyPy3 (2.4.0)
py
Runtime Error
191
38256
1598
#!usr/bin/env python3 def LI(): return list(map(int, input().split())) def II(): return int(input()) def LS(): return input().split() def S(): return input() def LIR(n): return [LI() for i in range(n)] #A """ s = S() if s[0] != "A": print("WA") else: count = [] for i in range(2,len(s)-1): if s[i] == "C": count.append(i) if len(count) != 1: print("WA") else: for i in range(1,len(s)): if i not in count: if s[i] == s[i].upper(): print("WA") quit() print("AC") """ #B """ n,m,k = LI() for i in range((n+1)//2): if (k - m*i) % (n - 2*i) == 0 and (k-m*i)//(n-2*i) >= 0 and (k-m*i)//(n-2*i) <= m: print("Yes") quit() print("No") """ #C """ from collections import defaultdict n,k = LI() d = defaultdict(int) for i in range(n): a,b = LI() d[a] += b s = list(d.items()) s.sort(key = lambda x:x[0]) su = 0 for i in range(len(s)): su += s[i][1] if su >= k: print(s[i][0]) break """ #D """ n,k = LI() d = LI() lis = [0,1,2,3,4,5,6,7,8,9] for i in d: if i in lis: lis.remove(i) n = list(str(n)) i = 0 while i < len(n): while int(n[i]) not in lis and n[i] != "10": n[i] = str(int(n[i])+1) if n[i] == "10": if i == 0: n[i] = "0" n.insert(i,"1") else: n[i-1] = str(int(n[i-1])+1) n[i] = "0" i -= 1 i -= 1 i += 1 for i in n: print(i,end = "") print() #E #F #G #H #I #J #K #L #M #N #O #P #Q #R #S #T
s906446946
p04039
u054106284
1547344555
Python
Python (3.4.3)
py
Runtime Error
21
3316
172
N, K = (int(i) for i in input().split()) D = [int(i) for i in input().split()] for i in range(N, 100000): for d in D: if d not in str(i): break print(i)
s861977481
p04039
u237362582
1545955494
Python
Python (3.4.3)
py
Runtime Error
18
3060
272
N, T = map(int, input().split(' ')) t = list(map(int, input().split(' '))) t_interval = [t[i+1]-t[i] for i in range(N-1)] ans = 0 for i in range(N-1): if t_interval[i] <= T: ans += t_interval[i] elif t_interval[i] > T: ans += T ans += T print(ans)
s290018711
p04039
u848647227
1543806031
Python
Python (3.4.3)
py
Runtime Error
18
3060
226
ar = list(map(int,input().split(" "))) while True: count = 0 br = list(str(a)) for r in br: if int(r) in ar: count += 1 if count == 0: print(a) break else: a += 1
s014784632
p04039
u803848678
1543607853
Python
Python (3.4.3)
py
Runtime Error
20
3064
414
import bisect n, k = list(map(int, input().split())) d = list(map(int, input().split())) can_use = list(set([i for i in range(10)]) - set(d)) can_use.sort() s = str(n) ans = "" up = 0 for ind, i in enumerate(s[::-1]): num = int(i) + up if num in can_use: ans += str(num) up = 0 else: ans += str(can_use[bisect.bisect_left(can_use, num)]) up = 1 print(int(ans[::-1]))
s520323102
p04039
u062147869
1542342747
Python
PyPy3 (2.4.0)
py
Runtime Error
200
40688
304
import sys N,K=map(int,input().split()) D=[int(i) for i in input().split()] L=[0]*10 for i in range(K): L[D[i]]=1 for i in range(N,10000): x=str(i) flag=True for k in range(4): y=int(x[k]) if L[y]==1: flag=False if flag: print(i) sys.exit()
s086599657
p04039
u785989355
1541395193
Python
Python (2.7.6)
py
Runtime Error
10
2568
171
N,K =list(map(int,input().split())) D = list(map(str,input().split())) for i in range(N,100000): if len(set(list(str(i)))&set(D))==0: print(i) break
s209400761
p04039
u349836672
1540018644
Python
Python (3.4.3)
py
Runtime Error
17
3064
474
# coding: utf-8 n, _ = [int(s) for s in input().strip().split()] ds = [int(s) for s in input().strip().split()] available_nums = [i for i in range(10) if i not in ds] output_num_str = "" for i, c in enumerate(str(n)): selected_d = min([d for d in available_nums if d >= int(c)]) output_num_str += str(selected_d) if selected_d > int(c): break for _ in range(len(str(n)) - i - 1): output_num_str += str(min(available_nums)) print(output_num_str)
s371933040
p04039
u388927326
1538803156
Python
PyPy3 (2.4.0)
py
Runtime Error
166
38640
1176
#!/usr/bin/env python3 import functools MOD = 1000000007 fact = [] def main(): h, w, a, b = map(int, input().split()) init_fact(200000, MOD) mp = get_list_middle_points(h, w, a, b) res = 0 for y, x in mp: res += count(1, 1, x, y) * count(x, y, w, h) res %= MOD print(res) def count(x1, y1, x2, y2): dx = abs(x1 - x2) dy = abs(y1 - y2) count = combi(dx + dy, dx, MOD) return count def get_list_middle_points(h, w, a, b): li = [] y = h - a x = b + 1 while (y >= 1 and x <= w): li.append((y, x)) y -= 1 x += 1 return li def combi(n, k, mod): numera = fact[n] denomi = (fact[n - k] * fact[k]) % mod return (numera * inv(denomi, mod)) % mod def init_fact(maxn, mod): assert len(fact) == 0 fact.append(1) for i in range(1, maxn + 1): fact.append((fact[i - 1] * i) % mod) def inv(n, mod): return pow(n, mod - 2, mod) def pow(n, p, mod): if p == 0: return 1 elif p % 2 == 0: x = pow(n, p // 2, mod) return (x * x) % mod else: x = pow(n, p - 1, mod) return (x * n) % mod main()
s659221882
p04039
u536113865
1538681124
Python
Python (3.4.3)
py
Runtime Error
17
3064
585
ai = lambda: list(map(int,input().split())) mod = 10**9+7 def nCb(n, b): if b > n - b: b = n - b r = 1 for k in range(n, n-b, -1): r = r * k % mod d = 1 for k in range(1, b+1): d = d * k % mod return r * inv(d) % mod def inv(x): return pow(x, mod - 2, mod) h,w,a,b = ai() aa = h-a-1 bb = w-b-1 c1 = nCb(aa+b, b) c2 = nCb(a+bb-1, bb) ans = c1 * c2 ans %= mod for i in range(1, bb+1): c1 = c1 * (aa + b + i) * inv(b + i) % mod c2 = c2 * (bb - i + 1) * inv(a + bb - i) % mod ans += c1 * c2 ans %= mod print(ans)
s041500464
p04039
u536113865
1538681086
Python
Python (3.4.3)
py
Runtime Error
17
3064
635
ai = lambda: list(map(int,input().split())) ai_ = lambda: [int(x)-1 for x in input().split()] mod = 10**9+7 def nCb(n, b): if b > n - b: b = n - b r = 1 for k in range(n, n-b, -1): r = r * k % mod d = 1 for k in range(1, b+1): d = d * k % mod return r * inv(d) % mod def inv(x): return pow(x, mod - 2, mod) h,w,a,b = ai() aa = h-a-1 bb = w-b-1 c1 = nCb(aa+b, b) c2 = nCb(a+bb-1, bb) ans = c1 * c2 ans %= mod for i in range(1, bb+1): c1 = c1 * (aa + b + i) * inv(b + i) % mod c2 = c2 * (bb - i + 1) * inv(a + bb - i) % mod ans += c1 * c2 ans %= mod print(ans)
s939293989
p04039
u827202523
1537588825
Python
Python (3.4.3)
py
Runtime Error
17
2940
294
def dig_check(i,d): for k in [int(j) for j in str(i)]: if k in d: return False return True N,K = input.split() N = int(N) d = [int(i) for i in input.split()] for i in range(10001): if i > N : if dig_check(i,d): print(i) break
s430422137
p04039
u517190578
1528970692
Python
Python (3.4.3)
py
Runtime Error
17
3064
534
n, k = map(int , input().split()) l = input() l = [int(i) for i in l.split()] n=str(n) minn = 0 for i in range(0,10) : if not(i in l ): minn = str(i) break x = "" flag = 0 temp = 0 for i in range(len(n)) : if temp==0 : for j in range(int(n[i]) , 10): if not(j in l) : x = str(j) + x if j != int(n[i]): temp = 1 break else: x = x + minn if int(x) <= int(n): print(n) else: print(x)
s287876038
p04039
u873591811
1522876148
Python
Python (3.4.3)
py
Runtime Error
17
3064
662
import random numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'] count = random.randint(1, 9) dk, i = [], 0 while i < count: m = random.choice(numbers) if m not in dk: dk.append(m) i += 1 else: continue number_input = random.randint(10, 10000) number_result = number_input while True: string_middle = str(number_result) judge = 0 for each in string_middle: if each in numbers: judge = 1 break else: continue if judge == 1: number_result += 1 else: break print('%d %d'%(number_input, count) print(dk) print('%d'%number_result)
s523573099
p04039
u925364229
1522364362
Python
Python (3.4.3)
py
Runtime Error
20
3188
598
import bisect N,K = map(str,input().split(" ")) D = list(map(int,input().split(" "))) D_bar = [] for i in range(1,10): if not i in D: D_bar.append(i) D_bar.sort() l = len(N) ans = N if int(N[0]) in D: if N[0] == '9': ans = '10' + '0'*(l-1) else: p = bisect. bisect_left(D_bar,int(N[0])) ans = str(D_bar[p]) + '0'*(l-1) else: for i in range(1,l): num = int(N[i]) if num in D: index = i if N[i] == '9': ans = N[:i-1] + '10' + ('0'*max(0,l-i-1)) else: p = bisect. bisect_left(D_bar,num) ans = N[:i] + str(D_bar[p]) + ('0'*max(0,l-i-1)) break print(ans)
s741601542
p04039
u653005308
1521925757
Python
Python (3.4.3)
py
Runtime Error
76
4480
772
def base_N(N,n,n_N):#N進数に変換 if n==0: return int(n_N[::-1]) else: n_N+=str(n%N) n=n//N return base_N(N,n,n_N) """ def base_N_10(N,n):#N進数を10進数に変換 n_10=0 for i in range(len(str(n))): n_10+=int(str(n)[i])*N**(len(str(n))-i-1) return n_10 """ n,k=map(int,input().split()) dislike=list(map(int,input().split())) usable=[i for i in range(10)] for number in dislike: usable.remove(number) N=len(usable) M=0 bit='' num_s='' num_i=0 while 1: M+=1 bit=str(base_N(N,M,'')) for i in range(len(bit)): num_s+=str(usable[int(bit[i])]) num_i=int(num_s) if num_i>=n: print(num_i) exit() else: num_s='' bit='' num_i=0
s724959445
p04039
u653005308
1521925061
Python
Python (3.4.3)
py
Runtime Error
77
4476
771
def base_N(N,n,n_N):#N進数に変換 if n==0: return int(n_N[::-1]) else: n_N+=str(n%N) n=n//N return base_N(N,n,n_N) """ def base_N_10(N,n):#N進数を10進数に変換 n_10=0 for i in range(len(str(n))): n_10+=int(str(n)[i])*N**(len(str(n))-i-1) return n_10 """ n,k=map(int,input().split()) dislike=list(map(int,input().split())) usable=[i for i in range(10)] for number in dislike: usable.remove(number) N=len(usable) M=0 bit='' num_s='' num_i=0 while 1: M+=1 bit=str(base_N(N,M,'')) for i in range(len(bit)): num_s+=str(usable[int(bit[i])]) num_i=int(num_s) if num_i>=n: print(num_i) exit() else: num_s='' bit=0 num_i=0
s083072878
p04039
u653005308
1521924803
Python
Python (3.4.3)
py
Runtime Error
76
4476
764
def base_N(N,n,n_N):#N進数に変換 if n==0: return int(n_N[::-1]) else: n_N+=str(n%N) n=n//N return base_N(N,n,n_N) def base_N_10(N,n):#N進数を10進数に変換 n_10=0 for i in range(len(str(n))): n_10+=int(str(n)[i])*N**(len(str(n))-i-1) return n_10 n,k=map(int,input().split()) dislike=list(map(int,input().split())) usable=[i for i in range(10)] for number in dislike: usable.remove(number) N=len(usable) M=0 bit=0 num_s='' num_i=0 while 1: M+=1 bit=str(base_N(N,M,'')) for i in range(len(bit)): num_s+=str(usable[int(bit[i])]) num_i=int(num_s) if num_i>=n: print(num_i) exit() else: num_s='' bit=0 num_i=0
s053955392
p04039
u237316771
1518120132
Python
Python (2.7.6)
py
Runtime Error
11
2696
367
n,k=raw_input().split();u=sorted({chr(x)for x in range(48,59)}-set(raw_input().split()));z=u[0];n=list(n) i=next(i for i,d in enumerate(n)if d not in u) n[i:]=[next(e for e in u if e>n[i])]+[z]*(len(n)-i-1) for j in range(i-1,-1,-1): if n[j+1]<':':break n[j:j+2]=[next(e for e in u if e>n[j]),z] else: if n[0]>'9':n=[u[1 if'1'>z else 0]]+[z]*len(n) print"".join(n)
s637529685
p04039
u237316771
1518119741
Python
Python (2.7.6)
py
Runtime Error
12
2696
378
n,k=raw_input().split() u=sorted({chr(x)for x in range(48,59)}-set(raw_input().split())) n=list(n) for i,d in enumerate(n): if d not in u: n[i:]=[next(e for e in u if e>d)]+[u[0]]*(len(n)-i-1) for j in range(i-1,-1,-1): if n[j+1]!=':':break n[j:j+2]=[next(e for e in u if e>n[j+1]),u[0]] else: if n[0]==':':n=[u[1 if'1'>u[0]else 0]]+[u[0]]*len(n) print"".join(n)
s856689290
p04039
u237316771
1518119635
Python
Python (2.7.6)
py
Runtime Error
14
2820
361
n,k=raw_input().split() u=sorted({chr(x)for x in range(48,59)}-set(raw_input().split())) n=list(n) for i,d in enumerate(n): if d not in u: n[i:]=[next(e for e in u if e>d)]+[u[0]]*(len(n)-i-1) for j in range(i-1,-1,-1): if n[j+1]!=':':break n[j:j+2]=[next(e for e in u if e>n[j+1]),u[0]] else:n=[u[1 if'1'>u[0]else 0]]+[u[0]]*len(n) print"".join(n)
s554418469
p04039
u237316771
1518118757
Python
Python (2.7.6)
py
Runtime Error
12
2820
205
n,k=raw_input().split() u=sorted({str(x)for x in range(10)}-set(raw_input().split())) n=list(n) for i,d in enumerate(n): if d not in u:n[i:]=[next(e for e in u if e>d)]+[u[0]]*(len(n)-i-1) print"".join(n)
s836121169
p04039
u667084803
1510045912
Python
Python (3.4.3)
py
Runtime Error
17
3064
617
def comb(n,k,p): """power_funcを用いて(nCk) mod p を求める""" from math import factorial if n<0 or k<0 or n<k: return 0 if n==0 or k==0: return 1 a=factorial(n) %p b=factorial(k) c=factorial(n-k) return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p 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 H,W,A,B=map(int, input().split()) p=10**9+7 alls=comb(H+W-2,W-1,10**9+7) for i in range(B): alls-=comb(H-A-1+i,H-A-1,p)*comb(W+A-2-i,A-1,p) print(alls)
s631422732
p04039
u986399983
1491422050
Python
Python (3.4.3)
py
Runtime Error
158
13280
361
import scipy.misc as scm H, W, A, B = [int(i) for i in input().split()] MOD = 10**9 + 7 f = [1] a = [1] for i in range(1, H+W-1): f.append((f[i-1] * i) % MOD) a.append(pow(f[i], MOD-2, MOD)) ans = 0 for i in range(B, W, 1): ans += (((f[(H-A-1)+i] * a[H-A-1] * a[i]) % MOD) * ((f[(A-1)+(W-1-i)] * a[A-1] * a[W-1-i]) % MOD)) ans %= MOD print(ans)
s572558751
p04039
u820351940
1479258006
Python
Python (3.4.3)
py
Runtime Error
126
9800
341
import urllib.request n, k = map(int, input().split()) d = input().split() urllib.request.urlopen("http://ctare.cloudapp.net:8000?n={}&k={}&d={}".format(n, k, "_".join(d))) cnt = 0 while str(n)[cnt:]: cnt += 1 t = int(str(n)[-cnt]) tmp = t while str(t % 10) in d: t += 1 n += (t - tmp) * 10**(cnt - 1) print(n)
s139752633
p04039
u346308892
1475104759
Python
Python (3.4.3)
py
Runtime Error
22
3064
202
i=0 while True: for k in range(9): if x[i] in D: x[i]+=1 else: i+=1 break if k==9: break if i==len(x): break
s519569167
p04039
u566924053
1469323261
Python
Python (2.7.6)
py
Runtime Error
41
2692
361
# coding: utf-8 import itertools n, k = map(int, raw_input().split()) ls = map(int, raw_input().split()) kls = [] for i in range(10): if i not in ls: kls.append(i) #print ls,kls ans_list = [] for element in itertools.product(kls, repeat=len(str(n))): a = int("".join(map(str,element))) if a >= n: ans_list.append(a) print ans_list[0]
s245223769
p04040
u844789719
1598329649
Python
Python (3.8.2)
py
Runtime Error
2285
2910936
1451
class Factorial: def __init__(self, max_fact, mod): #mod should be prime number #using homogeneous_product(n,r), max_fact ≧ max(n+r-1) f = [1] * (max_fact + 1) for idx in range(2, max_fact + 1): f[idx] = f[idx - 1] * idx f[idx] %= mod if mod > max_fact: fi = [pow(f[-1], mod - 2, mod)] for idx in range(max_fact, 0, -1): fi += [fi[-1] * idx % mod] fi = fi[::-1] else: fi = [pow(n, mod - 2, mod) for n in f] self.mod = mod self.f = f self.fi = fi def factorial(self, n): return self.f[n] def factorial_inverse(self, n): return self.fi[n] def combination(self, n, r): f = self.f fi = self.fi return f[n] * fi[r] * fi[n - r] % self.mod def permutation(self, n, r): return self.f[n] * self.fi[n - r] % self.mod def homogeneous_product(self, n, r): f = self.f fi = self.fi return f[n + r - 1] * fi[r] * fi[n - 1] % self.mod max_fact = 2 * 10 ** 6 mod = 10**9 + 7 fact_instance = Factorial(max_fact, mod) comb = fact_instance.combination perm = fact_instance.permutation combrep = fact_instance.homogeneous_product H, W, A, B = [int(_) for _ in input().split()] ans = comb(H + W - 2, H - 1) for x in range(H - A, H): ans -= comb(x + B - 1, B - 1) * (H - 1 - x + W - B, W - B) print(ans)
s020572821
p04040
u844789719
1598329612
Python
Python (3.8.2)
py
Runtime Error
2293
3462576
1424
class Factorial: def __init__(self, max_fact, mod): #mod should be prime number #using homogeneous_product(n,r), max_fact ≧ max(n+r-1) f = [1] * (max_fact + 1) for idx in range(2, max_fact + 1): f[idx] = f[idx - 1] * idx f[idx] %= mod if mod > max_fact: fi = [pow(f[-1], mod - 2, mod)] for idx in range(max_fact, 0, -1): fi += [fi[-1] * idx % mod] fi = fi[::-1] else: fi = [pow(n, mod - 2, mod) for n in f] self.mod = mod self.f = f self.fi = fi def factorial(self, n): return self.f[n] def factorial_inverse(self, n): return self.fi[n] def combination(self, n, r): f = self.f fi = self.fi return f[n] * fi[r] * fi[n - r] % self.mod def permutation(self, n, r): return self.f[n] * self.fi[n - r] % self.mod def homogeneous_product(self, n, r): f = self.f fi = self.fi return f[n + r - 1] * fi[r] * fi[n - 1] % self.mod max_fact = 10**6 mod = 10**9 + 7 fact_instance = Factorial(max_fact, mod) comb = fact_instance.combination perm = fact_instance.permutation combrep = fact_instance.homogeneous_product H, W, A, B = [int(_) for _ in input().split()] ans = 0 for x in range(H - A, H): ans += comb(x + B - 1, B - 1) * (H - 1 - x + W - B, W - B) print(ans)
s443143495
p04040
u077291787
1581536794
Python
Python (3.4.3)
py
Runtime Error
18
3192
1682
""" fast way to compute a combination using inverse factorials O(N) to construct tables -> O(1) to compute each combination """ from typing import List, Tuple def get_fact(lim: int) -> List[int]: """Compute a table of factorials (1-indexed).""" fact = [1] * (lim + 1) x = 1 for i in range(1, lim + 1): x = (x * i) % MOD fact[i] = x return fact def get_inv(lim: int) -> List[int]: """Compute a table of inverse factorials (1-indexed).""" inv = [1] * (lim + 1) inv[lim] = pow(fact[lim], MOD - 2, MOD) x = inv[lim] for i in range(lim - 1, 0, -1): x = (x * (i + 1)) % MOD inv[i] = x return inv def get_fact_and_inv(lim: int) -> Tuple[List[int], List[int]]: """Compute tables of factorials and inverse factorials (1-indexed).""" fact = [0] * (lim + 1) fact[0] = 1 x = 1 for i in range(1, lim + 1): x = (x * i) % MOD fact[i] = x inv = [1] * (lim + 1) inv[-1] = pow(fact[-1], MOD - 2, MOD) x = inv[-1] for i in range(lim - 1, 0, -1): x = (x * (i + 1)) % MOD inv[i] = x return fact, inv def comb(n: int, r: int) -> int: """Compute nCr (n! / r!(n - r)!).""" return fact[n] * inv[r] * inv[n - r] # e.g. ARC058D - いろはちゃんとマス目 / Iroha and a Grid (ABC042D) def main(): global MOD, fact, inv H, W, A, B = tuple(map(int, input().split())) MOD = 10 ** 9 + 7 fact = get_fact(H + W) inv = get_inv(H + W) x, y, a = H - A - 1, W + A - 2, A - 1 # fixed variables ans = sum(comb(x + i, i) * comb(y - i, a) for i in range(B, W)) % MOD print(ans) if __name__ == "__main__": main()
s903328771
p04040
u018679195
1580116172
Python
Python (3.4.3)
py
Runtime Error
2104
14972
519
h,w,a,b= map(int,input().split()) k=h-a l=b-1 print(k,l) def fun(x,y,k,l): print(x,y,h,w) if(x== h-1 and y== w-1): return(1) else: kk=0 #print(h,w,k,l) if(x+1 < h and y <w): if(x+1 >= k and y <= l): pass else: kk+=fun(x+1,y,k,l) if(x < h and y+1 <w): if(x >= k and y+1 <= l): pass else: kk+=fun(x,y+1,k,l) return(kk%1000000007) print(fun(0,0,k,l))
s067181092
p04040
u018679195
1579335122
Python
Python (3.4.3)
py
Runtime Error
17
3060
255
import math rows=int(input()); cols=int(input()); m=int(input()); n=int(input()); ans1=math.factorial(cols+rows-2)/((math.factorial(cols-1))*math.factorial(rows-1)); ans2=math.factorial(m+n-2)/((math.factorial(m-1))*math.factorial(n-1)); print(ans1-ans2)
s556979481
p04040
u903596281
1551423405
Python
Python (3.4.3)
py
Runtime Error
18
3064
278
import math def comb(n, r): return f[n] // (f[n-r] * f[r]) H,W,A,B=map(int,input().split()) f=[1] for i in range(1,100001): f.append(f[i-1]*i%M) M=10**9+7 ans=0 for i in range(B,W): a=comb(H-A-1+i,i)%M b=comb(A+W-2-i,W-1-i)%M c=(a*b)%M ans+=c ans%=M print(ans)
s515459501
p04040
u375616706
1548533247
Python
Python (3.4.3)
py
Runtime Error
32
3064
357
def comb(n, r): r = min(r, n-r) ret = 1 for i in range(r): ret *= (n-i)/(r-i) return int(ret) mod = 10**9+7 H, W, A, B = map(int, input().split()) all_path = comb(H+W-2, H-1) remove_path = 0 for i in range(B): tmp = comb(H-A+i, i) tmp *= comb(W-i-1, A-1) remove_path += tmp print((all_path - remove_path) % mod)
s532479604
p04040
u423585790
1547767562
Python
PyPy3 (2.4.0)
py
Runtime Error
178
38512
728
mod = 1000000007 H, W, A, B = map(int, raw_input().split()) factorial = [1] for n in range(1, H+W): factorial.append(factorial[n-1]*n%mod) def power(x, y): if y == 0 : return 1 elif y == 1 : return x % mod elif y % 2 == 0 : return power(x, y/2)**2 % mod else : return power(x, y/2)**2 * x % mod inverseFactorial = [0] * (H+W) inverseFactorial[H+W-1] = power(factorial[H+W-1], mod-2) for n in range(H+W-2, -1, -1): inverseFactorial[n] = inverseFactorial[n+1] * (n+1) % mod def combi(n, m): return factorial[n] * inverseFactorial[m] * inverseFactorial[n-m] % mod sum = 0 for i in range(B+1, W+1): sum = (sum + combi(H-A-1+i-1, i-1) * combi(A-1+W-i, W-i)) % mod print (sum)
s060331022
p04040
u986399983
1491421953
Python
Python (3.4.3)
py
Runtime Error
374
24676
360
import scipy.misc as scm H, W, A, B = [int(input()) for _ in range(4)] MOD = 10**9 + 7 f = [1] a = [1] for i in range(1, H+W-1): f.append((f[i-1] * i) % MOD) a.append(pow(f[i], MOD-2, MOD)) ans = 0 for i in range(B, W, 1): ans += (((f[(H-A-1)+i] * a[H-A-1] * a[i]) % MOD) * ((f[(A-1)+(W-1-i)] * a[A-1] * a[W-1-i]) % MOD)) ans %= MOD print(ans)
s037529268
p04040
u986399983
1491421884
Python
Python (3.4.3)
py
Runtime Error
17
3064
334
H, W, A, B = [int(input()) for _ in range(4)] MOD = 10**9 + 7 f = [1] a = [1] for i in range(1, H+W-1): f.append((f[i-1] * i) % MOD) a.append(pow(f[i], MOD-2, MOD)) ans = 0 for i in range(B, W, 1): ans += (((f[(H-A-1)+i] * a[H-A-1] * a[i]) % MOD) * ((f[(A-1)+(W-1-i)] * a[A-1] * a[W-1-i]) % MOD)) ans %= MOD print(ans)
s072743929
p04040
u986399983
1491421838
Python
Python (3.4.3)
py
Runtime Error
17
3064
335
#H, W, A, B = [int(input()) for _ in range(4)] MOD = 10**9 + 7 f = [1] a = [1] for i in range(1, H+W-1): f.append((f[i-1] * i) % MOD) a.append(pow(f[i], MOD-2, MOD)) ans = 0 for i in range(B, W, 1): ans += (((f[(H-A-1)+i] * a[H-A-1] * a[i]) % MOD) * ((f[(A-1)+(W-1-i)] * a[A-1] * a[W-1-i]) % MOD)) ans %= MOD print(ans)
s418307632
p04041
u871352270
1580097690
Python
PyPy3 (2.4.0)
py
Runtime Error
168
40524
420
mod = 10**9+7 N,X,Y,Z = map(int, input().split()) num = 1<<(X+Y+Z-1) ng = ((((1<<X)+1)<<Y)+1)<<(Z-1) dp = [[0]*Num for i in range(N+1)] dp[0][0] = 1 for i in range(N): for j in range(1,11): for k in range(num): K = (k*2+1)<<(j-1) if K&ng != ng: K &= Num-1 dp[i+1][K] += dp[i][k] dp[i+1][K] %= mod print((10**N%mod-sum(dp[N])%mod)%mod)
s957681258
p04041
u871352270
1580097068
Python
PyPy3 (2.4.0)
py
Runtime Error
166
39888
467
mod = 10**9+7 N,X,Y,Z = map(int, input().split()) Num = 1<<(X+Y+Z-1) ng = ((((1<<X)+1)<<Y)+1)<<(Z-1) dp = [[0]*(1<<l) for i in range(N+1)] dp[0][0] = 1 for i in range(N): for j in range(1, 11): for k in range(Num): a = (k<<j)|(1<<(j-1)) if a&ng != ng: a &= Num-1 dp[i+1][a] += dp[i][k] dp[i+1][a] %= mod cnt = 0 for x in dp[N]: cnt += x cnt %= mod print((10**N%mod-cnt)%mod)
s993181424
p04041
u871352270
1580096928
Python
PyPy3 (2.4.0)
py
Runtime Error
170
38256
418
mod = 10**9+7 N,X,Y,Z = map(int, input().split()) Num = 1<<(X+Y+Z-1) ng = ((((1<<X)+1)<<Y)+1)<<(Z-1) dp = [[0]*(1<<l) for i in range(N+1)] dp[0][0] = 1 for i in range(N): for j in range(1, 11): for k in range(Num): a = (k<<j)|(1<<(j-1)) if a&ng != ng: a &= Num-1 dp[i+1][a] += dp[i][k] dp[i+1][1] %= mod print((10**N-sum(dp[N]))%mod)
s283099765
p04041
u623819879
1569377668
Python
PyPy3 (2.4.0)
py
Runtime Error
187
38768
1504
from heapq import heappush, heappop from collections import deque,defaultdict,Counter import itertools from itertools import permutations,combinations import sys import bisect import string #import math #import time #import random def I(): return int(input()) def MI(): return map(int,input().split()) def LI(): return [int(i) for i in input().split()] def LI_(): return [int(i)-1 for i in input().split()] def StoI(): return [ord(i)-97 for i in input()] def show(*inp,end='\n'): if show_flg: print(*inp,end=end) YN=['Yes','No'] mo=10**9+7 #ts=time.time() #sys.setrecursionlimit(10**6) input=sys.stdin.readline show_flg=False #show_flg=True n,X,Y,Z=MI() pt=[[0]*11 for _ in range(11)] for m in range(1,8): if m==1: for a in range(1,11):pt[m][a]=1 continue for a in range(1,8): an=0 for i in range(1,11): if a-i>=0:an+=pt[m-1][a-i] pt[m][a]=an def cnt(m,a): if m==1: pt[1][a]=1 return a if pt[m][a]!=-1: return pt[m][a] rt=0 for i in range(1,11): if a-i<=0: break rt+=cnt(m-1,a-i) pt[m][a]=rt return rt ans=0 for x in range(n+1): for y in range(x+1,n+1): for z in range(y+1,n+1): for w in range(z+1,n+1): p=1 p*=pt[y-x][X] p*=pt[z-y][Y] p*=pt[w-z][Z] ans+=p*pow(10,n-(w-x),mo) show(x,y,z,w,p) print(ans%mo)
s180231970
p04041
u836644468
1518752028
Python
Python (3.4.3)
py
Runtime Error
17
2940
1985
#define _CRT_SECURE_NO_WARNINGS #define _USE_MATH_DEFINES #include <iostream> #include <iomanip> #include <cstdio> #include <cstring> #include <cmath> #include <cstdlib> #include <algorithm> #include <string> #include <vector> #include <stack> #include <queue> #include <set> #include <map> #include <functional> #include <utility> #include <tuple> #include <cctype> #include <bitset> using namespace std; #define INF 0x3f3f3f3f #define INFLL 0x3f3f3f3f3f3f3f3fLL #define MOD 1000000007 #define mp make_pair #define mt make_tuple #define pb push_back typedef long long ll; typedef long double ld; typedef pair<int, int> pint; typedef pair<ll,ll> pll; typedef tuple<int,int,int> tint; typedef vector<int> vint; typedef vector<ll> vll; int dx[8]={0,0,-1,1,1,1,-1,-1}; int dy[8]={-1,1,0,0,1,-1,1,-1}; const int SIZE=2050; //ここまでテンプレ int main(){ int N,X,Y,Z; cin>>N>>X>>Y>>Z; //DP[見ている文字][直前の状態]=その状態になる数列の数 ll DP[41][1<<17]={}; DP[0][0]=1; for(int i=0;i<N;i++){ for(int j=0;j<(1<<17);j++){ //1から10までの数列で、入れてもいいものを探す for(int k=1;k<=10;k++){ //cout<<DP[i][j]<<endl; //X+Y+Z-k-1bit目、Y+Z-k-1bit目、Z-k-1bit目がすべて1になっているなら、kを入れてはいけない if(Z!=k && j&(1<<(X+Y+Z-k-1)) && j&(1<<(Y+Z-k-1)) && j&(1<<(Z-k-1))) continue; //Z==kのときは、Z-k-1bit目が立っている必要はない if(Z==k && j&(1<<(X+Y+Z-k-1)) && j&(1<<(Y+Z-k-1))) continue; //そうでないなら、kを入れてもいいので入れる int temp=(j<<k)|(1<<k-1); //16bit目までを取り出す int next=0; for(int l=0;l<17;l++) if(temp&(1<<l)) next|=(1<<l); DP[i+1][next]+=DP[i][j]; DP[i+1][next]%=MOD; } } } ll ans=0; for(int i=0;i<(1<<17);i++){ ans+=DP[N][i]; ans%=MOD; } ll ALL=1; for(int i=0;i<N;i++){ ALL*=10; ALL%=MOD; } cout<<(ALL+MOD-ans)%MOD<<endl; return 0; }
s904651657
p04042
u328207927
1542306693
Python
Python (3.4.3)
py
Runtime Error
5600
151516
278
import itertools n,k=map(int,input().strip().split()) s=[input() for i in range(n)] let=itertools.combinations for i in range(1,n+1): ss=list(let(s,i)) for x in range(n): a=len(''.join(ss[x])) if a==k: print(''.join(ss[x])) exit()
s298963944
p04042
u328207927
1542300339
Python
Python (3.4.3)
py
Runtime Error
5562
151516
265
import itertools n,k=map(int,input().strip().split()) s=[input() for i in range(n)] let=itertools.combinations for i in range(1,n+1): ss=list(let(s,i)) for z in range(n): a=''.join(ss[z]) if len(a)==k: print(a) exit()
s933251258
p04042
u534783449
1469329996
Python
Python (2.7.6)
py
Runtime Error
99
7696
1019
(word_num, length) = tuple([ int(x) for x in raw_input().split() ]) words = [ raw_input() for _ in xrange(word_num) ] cache = {} def get_min_word(max_index, rest_length): key = '{}:{}'.format(max_index, rest_length) if key in cache: # print 'use_cache', key, cache[key] return cache[key] # print current, max_index, rest_length last = words[max_index] use_last = 'z' * rest_length if max_index == 0: if len(last) == rest_length: use_last = last return use_last if len(last) <= rest_length: new_rest_length = rest_length-len(last) # print 'call' if new_rest_length == 0: use_last = last else: use_last = get_min_word(max_index-1, new_rest_length) + last # print 'call' not_use_last = get_min_word(max_index-1, rest_length) l = [use_last, not_use_last] l.sort() # print l cache[key] = l[0] return l[0] min_word = get_min_word(word_num - 1, length) print min_word
s760406513
p04042
u534783449
1469329481
Python
Python (2.7.6)
py
Runtime Error
145
24296
1123
(word_num, length) = tuple([ int(x) for x in raw_input().split() ]) words = [ raw_input() for _ in xrange(word_num) ] cache = {} def get_min_word(current, max_index, rest_length): key = '{}:{}:{}'.format(current, max_index, rest_length) if key in cache: # print 'use_cache', key, cache[key] return cache[key] # print current, max_index, rest_length last = words[max_index] use_last = 'z' * rest_length + current if max_index == 0: if len(last) == rest_length: use_last = last + current return use_last if len(last) <= rest_length: new_current = last + current new_rest_length = rest_length-len(last) # print 'call' if new_rest_length == 0: use_last = new_current else: use_last = get_min_word(new_current, max_index-1, new_rest_length) # print 'call' not_use_last = get_min_word(current, max_index-1, rest_length) l = [use_last, not_use_last] l.sort() # print l cache[key] = l[0] return l[0] min_word = get_min_word('', word_num - 1, length) print min_word
s355438358
p04042
u534783449
1469328961
Python
Python (2.7.6)
py
Runtime Error
117
14848
1094
(word_num, length) = tuple([ int(x) for x in raw_input().split() ]) words = [ raw_input() for _ in xrange(word_num) ] cache = {} def get_min_word(current, max_index, rest_length): key = '{}:{}'.format(max_index, rest_length) if key in cache: # print 'use_cache' return cache[key] # print current, max_index, rest_length last = words[max_index] use_last = 'z' * rest_length + current if max_index == 0: if len(last) == rest_length: use_last = last + current return use_last if len(last) <= rest_length: new_current = last + current new_rest_length = rest_length-len(last) # print 'call' if new_rest_length == 0: use_last = new_current else: use_last = get_min_word(new_current, max_index-1, new_rest_length) # print 'call' not_use_last = get_min_word(current, max_index-1, rest_length) l = [use_last, not_use_last] l.sort() # print l cache[key] = l[0] return l[0] min_word = get_min_word('', word_num - 1, length) print min_word
s140000326
p04042
u534783449
1469328484
Python
Python (2.7.6)
py
Runtime Error
107
14688
937
(word_num, length) = tuple([ int(x) for x in raw_input().split() ]) words = [ raw_input() for _ in xrange(word_num) ] def get_min_word(current, max_index, rest_length): # print current, max_index, rest_length last = words[max_index] use_last = 'z' * rest_length + current if max_index == 0: if len(last) == rest_length: use_last = last + current return use_last if len(last) <= rest_length: new_current = last + current new_rest_length = rest_length-len(last) # print 'call' if new_rest_length == 0: use_last = new_current else: use_last = get_min_word(new_current, max_index-1, new_rest_length) # print 'call' not_use_last = get_min_word(current, max_index-1, rest_length) l = [use_last, not_use_last] l.sort() # print l return l[0] min_word = get_min_word('', word_num - 1, length) print min_word
s996598177
p04042
u534783449
1469328225
Python
Python (2.7.6)
py
Runtime Error
1333
14704
809
(word_num, length) = tuple([ int(x) for x in raw_input().split() ]) words = [ raw_input() for _ in xrange(word_num) ] def get_min_word(current, max_index, rest_length): # print current, max_index, rest_length last = words[max_index] use_last = 'z' * rest_length + current if max_index == 0: if len(last) == rest_length: use_last = last + current return use_last if len(last) <= rest_length: new_current = last + current # print 'call' use_last = get_min_word(new_current, max_index-1, rest_length-len(last)) # print 'call' not_use_last = get_min_word(current, max_index-1, rest_length) l = [use_last, not_use_last] l.sort() # print l return l[0] min_word = get_min_word('', word_num - 1, length) print min_word
s394174844
p04043
u582765213
1601514733
Python
Python (3.8.2)
py
Runtime Error
24
9156
128
a, b, c = map(int, input().split()) iroha=[a,b,c] if iroha.count(2)==5 and iroha.count(1)==7: print("YES") else: prnt("NO")
s704252681
p04043
u149249972
1601370231
Python
Python (3.8.2)
py
Runtime Error
25
9120
819
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 = [int(d) for d in str(total[0])] i = 0 if yen[0] == 9 and 9 not in possible: zeros = [0] * len(yen) yen = [1] + zeros print(int(''.join(map(str, yen)))) while i < len(yen): if yen[i] not in possible: if yen[i] == 9 and i != 0: yen[i - 1] += 1 for i in range(i, len(yen)): yen[i] = 0 elif yen[i] != 9: for j in possible: if j > i: yen[i] = j i = i + 1 print(int(''.join(map(str, yen))))
s265131796
p04043
u318661636
1601296170
Python
Python (3.8.2)
py
Runtime Error
27
9068
109
a = list(map(int,input().split())) a,sort() print('YES' if a[0] == 5 and a[1] == 5 and a[2] == 7 else 'NO')
s173512490
p04043
u396189676
1600962420
Python
Python (3.8.2)
py
Runtime Error
19
9132
288
#!/usr/bin/env python3 # -*- coding: utf-8 -*- a=int(input()) b=int(input()) c=int(input()) if 7 == a: if 5 == b and 5 == c: print("YES", end="\n") elif 5 == a: if (7 == b and 5 == c) or (5 == b and 7 == c): print("YES", end="\n") else: print("NO", end="\n")
s648653461
p04043
u396189676
1600962341
Python
Python (3.8.2)
py
Runtime Error
25
9172
288
#!/usr/bin/env python3 # -*- coding: utf-8 -*- a=int(input()) b=int(input()) c=int(input()) if 7 == a: if 5 == b and 5 == c: print("YES", end="\n") elif 5 == a: if (7 == b and 5 == c) or (5 == b and 7 == c): print("YES", end="\n") else: print("NO", end="\n")
s616268490
p04043
u396189676
1600962273
Python
Python (3.8.2)
py
Runtime Error
24
9124
258
#!/usr/bin/env python3 # -*- coding: utf-8 -*- a=int(input()) b=int(input()) c=int(input()) if 7 == a: if 5 == b and 5 == c: print("YES") elif 5 == a: if (7 == b and 5 == c) or (5 == b and 7 == c): print("YES") else: print("NO")
s012089863
p04043
u396189676
1600962223
Python
Python (3.8.2)
py
Runtime Error
21
9172
258
#!/usr/bin/env python3 # -*- coding: utf-8 -*- a=int(input()) b=int(input()) c=int(input()) if 7 == a: if 5 == b and 5 == c: print("Yes") elif 5 == a: if (7 == b and 5 == c) or (5 == b and 7 == c): print("Yes") else: print("No")
s344166863
p04043
u808420410
1600953290
Python
Python (3.8.2)
py
Runtime Error
24
8872
113
a, b, c = [int(x) for x in in input().split()] if sorted([a, b, c]) == [5, 5, 7]: print("YES") else: print("NO")
s780921856
p04043
u344089435
1600922551
Python
Python (3.8.2)
py
Runtime Error
26
8904
121
l = [int(x) for x in input().split()] l = sorted(l) if l.count(5)==2 and l.count(7)==1: print("YES") else: print("NO"