code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
6.82M
181,637B
question_pair_id
float64
101M
180,471B
code1_group
int64
2
299
code2_group
int64
2
299
a1 = list(map(int, input().split())) a2 = list(map(int, input().split())) a3 = list(map(int, input().split())) n = int(input()) flag = 0 for _ in range(n): b = int(input()) for i in range(3): if b == a1[i]: a1[i] = 0 elif b == a2[i]: a2[i] = 0 elif b == a3[i]: a3[i] = 0 for i in range(3): if a1[i] == a2[i] == a3[i]: flag = 1 if sum(a1) == 0: flag = 1 if sum(a2) == 0: flag = 1 if sum(a3) == 0: flag = 1 if a1[0] == a2[1] == a3[2]: flag = 1 if a1[2] == a2[1] == a3[0]: flag = 1 if flag == 1: print("Yes") break if flag == 0: print("No")
p = 998244353 n, k = map(int, input().split()) num = [tuple(map(int, input().split())) for _ in range(k)] dp = [0] * (2*n + 1) dp[0] = 1 dp[1] = -1 for i in range(n): for l, r in num: dp[i+l] += dp[i] dp[i+r+1] -= dp[i] dp[i+1] += dp[i] dp[i+1] %= p print(dp[n-1])
0
null
31,100,372,126,582
207
74
line_num = int(raw_input()) for n in range(line_num): a,b,c = map(int, raw_input().split(" ")) if a>b: if a>c: if a*a == b*b + c*c: print "YES" continue else: if c*c == a*a + b*b: print "YES" continue else: if b>c: if b*b == a*a + c*c: print "YES" continue else: if c*c == a*a + b*b: print "YES" continue print "NO"
N=int(input()) for line in range(N): a,b,c = (int(i) for i in input().split()) if (a**2+b**2==c**2) or (b**2+c**2==a**2) or (c**2+a**2==b**2): print('YES') else: print('NO')
1
354,721,276
null
4
4
#-*-coding:utf-8-*- import sys input=sys.stdin.readline import itertools def main(): n = int(input()) P=tuple(map(int,input().split())) Q=tuple(map(int,input().split())) permutations = list(itertools.permutations(range(1,n+1))) a = permutations.index(P) b = permutations.index(Q) print(abs(a-b)) if __name__=="__main__": main()
def main(): a = int(input()) ans = a + a ** 2 + a ** 3 print(ans) if __name__ == '__main__': main()
0
null
55,060,237,192,452
246
115
N=int(input()) A=list(map(int, input().split())) B=[0]*N C='' for i in range(N): B[A[i]-1]=i+1 for i in range(N): C+=str(B[i])+' ' print(C[0:-1])
h,w,k = map(int,input().split()) m=[list(input()) for i in range(h)] o=0 for h_bit in range(2**h): for w_bit in range(2**w): c=0 for i in range(h): for j in range(w): if (h_bit>>i)&1==0 and (w_bit>>j)&1==0 and m[i][j]=='#': c+=1 if c==k: o+=1 print(o)
0
null
94,559,258,335,080
299
110
import bisect N=int(input()) S=list(str(input())) def ci(x): return "abcdefghijklmnopqrstuvwxyz".find(x) d=[[] for _ in range(26)] for i,s in enumerate(S): d[ci(s)].append(i) for i in range(int(input())): t,x,y=input().split() if t=="1": x=int(x)-1 if S[x]!=y: l=bisect.bisect_left(d[ci(S[x])],x) d[ci(S[x])].pop(l) bisect.insort(d[ci(y)],x) S[x]=y else: x,y=int(x)-1,int(y)-1 c=0 for j in range(26): l=bisect.bisect_left(d[j],x) if l<len(d[j]) and d[j][l] <= y: c += 1 print(c)
#!/usr/bin/env python3 class Bit: # Binary Indexed Tree def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def __iter__(self): psum = 0 for i in range(self.size): csum = self.sum(i + 1) yield csum - psum psum = csum raise StopIteration() def __str__(self): # O(nlogn) return str(list(self)) def sum(self, i): # [0, i) の要素の総和を返す if not (0 <= i <= self.size): raise ValueError("error!") s = 0 while i>0: s += self.tree[i] i -= i & -i return s def add(self, i, x): if not (0 <= i < self.size): raise ValueError("error!") i += 1 while i <= self.size: self.tree[i] += x i += i & -i def __getitem__(self, key): if not (0 <= key < self.size): raise IndexError("error!") return self.sum(key+1) - self.sum(key) def __setitem__(self, key, value): # 足し算と引き算にはaddを使うべき if not (0 <= key < self.size): raise IndexError("error!") self.add(key, value - self[key]) (n,), (s,), _, *q = map(str.split, open(0)) *s, = s BIT = [Bit(int(n)) for _ in [0] * 26] for e, t in enumerate(s): BIT[ord(t) - 97].add(e, 1) for a, b, c in q: if a == "1": i = int(b) BIT[ord(s[i - 1]) - 97].add(i - 1, -1) s[i - 1] = c BIT[ord(c) - 97].add(i - 1, 1) else: l, r = int(b), int(c) print(sum(BIT[i].sum(r) - BIT[i].sum(l - 1) > 0 for i in range(26)))
1
62,690,673,534,180
null
210
210
s = list(input()) k = int(input()) if list(s[0]*len(s))==s: #print('a') print(len(s)*k//2) exit() res = [1] for i in range(len(s)-1): if s[i]==s[i+1]: res[-1] += 1 else: res.append(1) ans = 0 for i in res: ans += (i//2)*k if s[0]==s[-1]: diff = (res[0]+res[-1])//2 -(res[0]//2 + res[-1]//2) ans += diff*(k-1) print(ans)
while True: h, w = map(int, input().split()) if h == 0 and w == 0: break width = '' for i in range(h): if i % 2 == 0: for j in range(w): if j % 2 == 0: width += '#' else: width += '.' else: for j in range(w): if j % 2 != 0: width += '#' else: width += '.' print(width) width = '' print('')
0
null
88,382,186,766,820
296
51
from sys import stdin from math import ceil inp = lambda : stdin.readline().strip() n, x, t = [int(x) for x in inp().split()] print(ceil(n/x)*t)
def main(): N, X, T = (int(i) for i in input().split()) print((0--N//X)*T) if __name__ == '__main__': main()
1
4,279,936,595,946
null
86
86
import sys N = int(raw_input()) for line in sys.stdin: a, b, c = sorted(map(int, line.split())) if a ** 2 + b ** 2 == c ** 2: print 'YES' else: print 'NO'
a,b=map(str, input().split()) print(b,a,sep="")
0
null
51,263,458,756,030
4
248
isPrime=[1 for i in range(10**6+1)] isPrime[0]=0;isPrime[1]=0 for i in range(2,10**6+1): if isPrime[i]==0: continue for j in range(2*i,10**6+1,i): isPrime[j]=0 X=int(input()) for i in range(X,10**6+1): if isPrime[i]==1: print(i) exit()
n = int(input()) while 1: for i in range(2, int(n**0.5)+1): if n % i < 1: break else: print(n) break n += 1
1
105,477,191,400,100
null
250
250
from collections import Counter N,*A = map(int, open(0).read().split()) ac = Counter(A) if len(ac) == N: print('YES') else: print('NO')
''' A[i]<A[j] F[i]<F[j] となる組み合わせが存在したと仮定 max(A[i]*F[i],A[j]*F[j])=A[j]*F[j] >A[i]*F[j] >A[j]*F[i] より、この場合はiとjを入れ替えたほうが最適となる。 結局 Aを昇順ソート Fを降順ソート するのが最適となる。 問題は修行の割当である。 順序を保ったまま修行していっても問題ない 3,2->1,2と 3.2->2,1は同じとみなせるため 二分探索 成績をmidにするために必要な修行コスト lowならK回より真に大 highならK回以下 ''' N,K=map(int,input().split()) A=[int(i) for i in input().split()] F=[int(i) for i in input().split()] A.sort() F.sort(reverse=True) low=-1 high=max(A)*max(F)+1 while(high-low>1): mid=(high+low)//2 tmp=0 for i in range(N): #A[i]*F[i]-mid<=X*F[i] x=(A[i]*F[i]-mid+F[i]-1)//F[i] if x<0: continue tmp+=x if tmp<=K: high=mid else: low=mid print(high)
0
null
119,665,577,280,590
222
290
from heapq import heappop, heappush h, w = map(int, input().split()) s = [list(input()) for _ in range(h)] def dijkstra(graph, n, s): d = [float("inf")] * n d[s] = 0 q = [] heappush(q, (0, s)) while q: dist, v = heappop(q) if d[v] < dist: continue for nv, cost in graph[v]: if d[nv] > d[v] + cost: d[nv] = d[v] + cost heappush(q, (d[nv], nv)) return d n = h*w+1 g = [list() for _ in range(n)] for i in range(h): for j in range(w-1): cid = i*w + j g[cid].append((cid+1, int(s[i][j] == "." and s[i][j+1] == "#"))) for i in range(h-1): for j in range(w): cid = i*w + j g[cid].append((cid+w, int(s[i][j] == "." and s[i+1][j] == "#"))) g[n-1].append((0, int(s[0][0] == "#"))) print(dijkstra(g, n, n-1)[n-2])
h, w = map(int, input().split()) s = [] for _ in range(h): s.append(input()) dp = [[h*w for i in range(w+1)] for j in range(h+1)] dp[0][1] = 0 dp[1][0] = 0 for i in range(h): for j in range(w): # print("i", i, "j", j, "s[i][j]", s[i][j]) # print(s[i][j] == '#' and (i == 0 or s[i-1][j] == '.')) #前の道が("."またはグリッド外)かつ現在地が#の場合に1を加える #前の道が"#"であればまとめて変換できるので何も加えない dp[i+1][j+1] = min( dp[i][j+1] + (s[i][j] == '#' and (i == 0 or s[i-1][j] == '.')), dp[i+1][j] + (s[i][j] == '#' and (j == 0 or s[i][j-1] == '.')) ) print(dp[-1][-1])
1
49,373,721,540,040
null
194
194
row, col, num = map(int, input().split()) tmp_l = [] board = [] for i in range(row): str = input() for j in range(col): if str[j] == '.': tmp_l.append(0) if str[j] == '#': tmp_l.append(1) board.append(tmp_l) tmp_l = [] onoff = [] bi = [32, 16, 8, 4, 2, 1] for i in range(64): tmp = i for j in bi: tmp_l.insert(0, int(tmp / j)) tmp %= j onoff.append(tmp_l) tmp_l = [] count = 0 ans = 0 for i in range(2**row): for j in range(2**col): for k in range(row): if onoff[i][k] == 1: for l in range(col): if onoff[j][l] == 1: if board[k][l] == 1: count += 1 if count == num: ans += 1 count = 0 print(ans)
n = int(input()) print(1/2 if n % 2 == 0 else (n//2 +1)/n)
0
null
93,373,142,781,230
110
297
from math import sin,cos,pi,sqrt a,b,d=map(float,input().split()) S=a*b*sin(d*pi/180)/2 c=sqrt(a**2+b**2-2*a*b*cos(d*pi/180)) h=2*S/a print(S) print(a+b+c) print(h)
import math a,b,C=map(int,input().split()) c=C/180*math.pi d=math.sqrt(a**2+b**2-2*a*b*math.cos(c)) S=1/2*a*b*math.sin(c) L=a+b+d h=2*S/a print("{:.8f}".format(S)) print("{:.8f}".format(L)) print("{:.8f}".format(h))
1
182,736,549,232
null
30
30
import sys from collections import Counter def main(): input = sys.stdin.buffer.readline n, x, y = map(int, input().split()) k_cnt = Counter() for i in range(1, n): for j in range(i + 1, n + 1): if i <= x: if j < y: dist = min(j - i, (x - i) + 1 + (y - j)) elif y <= j: dist = (x - i) + 1 + (j - y) elif x < i < y: dist = min(j - i, (i - x) + 1 + abs(j - y)) else: dist = j - i k_cnt[dist] += 1 for i in range(1, n): print(k_cnt[i]) if __name__ == "__main__": main()
r,c=map(int,input().split()) mat = [ list(map(int,input().split())) for _ in range(0,r) ] for xs in mat: xs.append(sum(xs)) ll = [ sum([ xs[i] for xs in mat ]) for i in range (0,c+1) ] for xs in mat: print(' '.join(map(str,xs))) print(' '.join(map(str,ll)))
0
null
22,880,459,964,520
187
59
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 # 998244353 input=lambda:sys.stdin.readline().rstrip() from bisect import bisect_left def resolve(): n, m = map(int,input().split()) A = list(map(int,input().split())) A.sort() def count(x): # the number of (i, j)s s.t. A[i] + A[j] >= x res = 0 for a in A: idx = bisect_left(A, x - a) res += n - idx return res left = 0 right = 200001 while right - left > 1: mid = (left + right) // 2 if count(mid) < m: right = mid else: left = mid x = right res = 0 for a in A: idx = bisect_left(A, x - a) res += 2 * a * (n - idx) res += (x - 1) * (m - count(x)) print(res) resolve()
import bisect from itertools import accumulate def func(x): cnt = 0 for i in a: index = bisect.bisect_left(a, x - i) cnt += N - index if cnt >= M: return True else: return False N, M = map(int, input().split()) a = list(map(int, input().split())) a.sort() ar = sorted(a, reverse=True) b = [0] + list(accumulate(ar)) MIN = 0 MAX = 2 * 10 ** 5 + 1 while MAX - MIN > 1: MID = (MIN + MAX) // 2 if func(MID): MIN = MID else: MAX = MID ans = 0 cnt = 0 for i in ar: index = bisect.bisect_left(a, MIN - i) ans += i * (N - index) + b[N - index] cnt += N - index print(ans - (cnt - M) * MIN)
1
107,776,251,848,382
null
252
252
import itertools as itl n = int(input()) A = list(map(int, input().split())) q = int(input()) M = list(map(int, input().split())) S = [] for i in range(n): cmb = list(itl.combinations(A, i+1)) for j in cmb: S.append(sum(j)) for m in M: flg = False for s in S: if s == m: flg = True break if flg: print("yes") else: print("no")
A, B = map(int, input().split()) print(A-B*2) if A>B*2 else print(0)
0
null
83,713,717,559,780
25
291
import math a,b,h,m = map(int, input().split()) s = 30 * h + m * 0.5 l = m*6 x = abs(s-l) if x >= 180: x = 360-x c = math.cos(math.radians(x)) print((a**2+b**2-2*a*b*c)**0.5)
s = input() d = input() c=0 for i in range(len(s)): if s[i]!=d[i]: c+=1 print(c)
0
null
15,275,598,517,630
144
116
str = input() str2 = input() nums = str.split() nums2 = str2.split() if len(nums2) != int(nums[1]): print("error") else: totalDamege = 0 for num in nums2: totalDamege += int(num) if int(nums[0]) <= totalDamege: print("Yes") else: print("No")
a,b=map(int,input().split()) l=list(map(int,input().split())) for i in range(b): a-=l[i] print("Yes" if a<=0 else"No")
1
77,995,787,369,290
null
226
226
import math import sys input = sys.stdin.readline sys.setrecursionlimit(10 ** 9) def main(): n = int(input()) mod = 10 ** 9 + 7 h = {} zero = 0 for i in range(n): a, b = map(int, input().split()) if a == 0 and b == 0: zero += 1 continue m = (0, 0) if b == 0: m = (1, 0) elif b > 0: g = math.gcd(a, b) m = (a // g, b // g) else: g = math.gcd(a, b) m = (-1 * (a // g), -1 * (b // g)) if m not in h: h[m] = set() h[m].add(i) h2 = {} for m in h: mi1 = (-1 * m[1], m[0]) if mi1 in h and mi1 not in h2: h2[m] = mi1 mi2 = (m[1], -1 * m[0]) if mi2 in h and mi2 not in h2: h2[m] = mi2 ans = 1 left = n - zero for k, v in h2.items(): s1 = len(h[k]) s2 = len(h[v]) # print(s1, s2) r = (pow(2, s1 + s2, mod) - (pow(2, s1, mod) - 1) * (pow(2, s2, mod) - 1)) % mod ans *= r ans %= mod left -= (s1 + s2) ans *= pow(2, left, mod) ans -= 1 ans += zero print(ans % mod) if __name__ == '__main__': main()
import math N=int(input()) A={} mod=10**9+7 AZ,BZ,ZZ=0,0,0 for i in range(N): a,b=map(int, input().split()) if a==b and a==0: ZZ+=1 elif a==0: AZ+=1 if (0,-1) not in A: A[(0,-1)]=1 else: A[(0,-1)]+=1 elif b==0: BZ+=1 if (1,0) not in A: A[(1,0)]=1 else: A[(1,0)]+=1 else: if a<0: a*=-1 b*=-1 d=math.gcd(abs(a),abs(b)) a//=d b//=d if (a,b) not in A: A[(a,b)]=1 else: A[(a,b)]+=1 c=0 D=[] for x,y in A: if (y,-x) in A: D.append((A[(x,y)],A[(y,-x)])) c+=A[(x,y)]+A[(y,-x)] n=N-c-ZZ p=pow(2,n,mod) ans=p for a,b in D: f=pow(2,a+b,mod)-(pow(2,a,mod)-1)*(pow(2,b,mod)-1) ans*=f ans-=1 print((ans+ZZ)%mod)
1
20,995,443,138,320
null
146
146
judge = True while judge: h,w = map(int, input().split(" ")) if h == 0 and w == 0: judge = False else: for i in range(h): if i == 0 or i+1 == h: print("#"*w) else: print("#"+"."*(w-2)+"#") print()
def solve(h, w): print('#'*w,end='') print(('\n#'+'.'*(w-2)+'#')*(h-2)) print('#'*w) print() if __name__ == '__main__': while True: h, w = [int(i) for i in input().split()] if h == w == 0: break solve(h, w)
1
834,003,942,070
null
50
50
#! /usr/bin/env python # -*- coding: utf-8 -*- height, width = map(int, raw_input().split()) print("%d %d") % (height * width, (height + width) * 2)
input_nums = map(int,raw_input().split()) men = input_nums[0] * input_nums[1] syu = (input_nums[0] * 2) + (input_nums[1] * 2) print "{0} {1}".format(men,syu)
1
294,480,516,092
null
36
36
n=int(input()) inp=list(map(int,input().split())) from collections import Counter z=0 k=1 for i in range(len(inp)): if inp[i]==k: z+=1 k+=1 if z==0: print (-1) else: print (len(inp)-z)
n=int(input()) a=list(map(int,input().split())) cnt=0 num=1 for i in range(len(a)): if a[i]!=num: cnt+=1 else: num+=1 if num==1: print(-1) else: print(cnt)
1
114,400,274,358,880
null
257
257
import sys input=sys.stdin.readline sys.setrecursionlimit(10 ** 8) from itertools import accumulate from itertools import permutations from itertools import combinations from collections import defaultdict from collections import Counter import fractions import math from collections import deque from bisect import bisect_left from bisect import bisect_right from bisect import insort_left import itertools from heapq import heapify from heapq import heappop from heapq import heappush import heapq from copy import deepcopy from decimal import Decimal alf = list("abcdefghijklmnopqrstuvwxyz") ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ") #import numpy as np INF = float("inf") #d = defaultdict(int) #d = defaultdict(list) MOD = 10**9+7 N = int(input()) A = list(map(int,input().split())) L = A[0] for i in range(1,N): g = math.gcd(L,A[i]) L = L*A[i]//g ans = 0 L %= MOD for i in range(N): ans += (L*pow(A[i],MOD-2,MOD)) ans %= MOD print(ans)
n=int(input()) A=list(map(int,input().split())) mod=10**9+7 def lcm(X,Y): x=X y=Y if y>x: x,y=y,x while x%y!=0: x,y=y,x%y return X*Y//y cnt=0 ans=0 LCM=1 for i in range(n): Q=lcm(LCM,A[i]) cnt*=Q//LCM LCM=Q cnt+=Q//A[i] print(cnt%mod)
1
87,734,929,226,088
null
235
235
import numpy as np N,M,X = map(int,input().split()) C = [] A = [] for _ in range(N): l = list(map(int,input().split())) C.append(l[0]) A.append(np.array(l[1:])) ans = 10**100 for i in range(2**N): rikaido = np.zeros(M) c = 0 for j in range(N): if (i >> j) & 1: c += C[j] rikaido += A[j] if all([x >= X for x in rikaido]): ans = min(ans, c) print(ans if ans != 10**100 else -1)
import sys def input(): return sys.stdin.readline().strip() sys.setrecursionlimit(20000000) MOD = 10 ** 9 + 7 INF = float("inf") def main(): N = int(input()) A = list(map(int, input().split())) S = 0 for a in A: S = S ^ a answer = [] for a in A: answer.append(S ^ a) print(*answer) if __name__ == "__main__": main()
0
null
17,269,444,708,640
149
123
import math n = int(input()) i = 1 tmp = n-1 while i <= math.sqrt(n): if n%i == 0: j = n//i if i + j < tmp: tmp = i + j -2 else: pass else: pass i += 1 print(tmp)
N = int(input()) ans = [] i = 1 while i * i <= N: if N % i == 0: x = i y = N / i ans.append(x+y-2) i += 1 print(int(min(ans)))
1
161,501,114,142,308
null
288
288
a,b = map(int,input().split()) A = [str(a)*b,str(b)*a] B = sorted(A) print(B[0])
n = int(input()) A = [int(x) for x in input().split()] q = int(input()) M = [int(x) for x in input().split()] ans = ["no"]*2000 for i in range(1<<n): a = 0 for j in range(n): if (i>>j)&1 == 1: a += A[j] ans[a] = "yes" for j in M: print(ans[j])
0
null
42,344,208,947,520
232
25
A, B, M = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) a.insert(0, 10**6) b.insert(0, 10**6) xyc = [list(map(int, input().split())) for _ in range(M)] ans = min(a) + min(b) for n in xyc: ans = min(ans, a[n[0]] + b[n[1]] - n[2]) print(ans)
A, B, M = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) ans = [] for i in range(M): x, y, c = map(int,input().split()) z = a[x - 1] + b[y - 1] - c ans.append(z) z = min(a) + min(b) ans.append(z) ans = sorted(ans) print(ans[0])
1
53,752,121,648,852
null
200
200
while 1: a = raw_input() if a =='0': break sum = 0 for i in a: sum += int(i) print sum
xin = [] while True: x = int(raw_input()) if x == 0: break xin += [x] for i in xin: print sum(map(int , list(str(i))))
1
1,553,324,772,048
null
62
62
n = int(input()) print(int(n / 2) - 1 if n % 2 == 0 else int(n / 2))
a,b,c=map(int, input().split(" ")) if a>c : k=c c=a a=k if c<b : k=b b=c c=k if b<a : k=b b=a a=k a,b,c=map(str,(a,b,c)) print(a+' '+b+' '+c)
0
null
76,702,270,654,000
283
40
n, k = list(map(int, input().split())) mod = 10**9 + 7 # xの逆元を求める。フェルマーの小定理より、 x の逆元は x ^ (mod - 2) に等しい。計算時間はO(log(mod))程度。 def modinv(x): return pow(x, mod-2, mod) # 二項係数の左側の数字の最大値を max_len とする。nとかだと他の変数と被りそうなので。 # factori_table = [1, 1, 2, 6, 24, 120, ...] 要は factori_table[n] = n! # 計算時間はO(max_len * log(mod)) max_len = 2 * n - 1 #適宜変更する factori_table = [1] * (max_len + 1) factori_inv_table = [1] * (max_len + 1) for i in range(1, max_len + 1): factori_table[i] = factori_table[i-1] * (i) % mod factori_inv_table[i] = modinv(factori_table[i]) def binomial_coefficients(n, k): # n! / (k! * (n-k)! ) if k <= 0 or k >= n: return 1 return (factori_table[n] * factori_inv_table[k] * factori_inv_table[n-k]) % mod if k >= n-1: # nHn = 2n-1 C n print(binomial_coefficients(2 * n - 1, n)) else: # 移動がk回←→ 人数0の部屋がk個以下 # 人数0の部屋がちょうどj個のものは # nCj(人数0の部屋の選び方) * jH(n-j) (余剰のj人を残りの部屋に入れる) ans = 0 for j in range(k+1): if j == 0: ans += 1 else: ans += binomial_coefficients(n, j) * binomial_coefficients(n-1, j) ans %= mod print(ans)
M=10**9+7;n,k=map(int,input().split());a=c=p=1 for i in range(1,min(n,k+1)):c=c*(n-i+1)*(n-i)%M;p=p*i*i%M;a+=c*pow(p,M-2,M) print(a%M)
1
67,162,922,277,350
null
215
215
N=int(input()) ans=0 speech_l=[[] for _ in range(N)] for i in range(N): tmp=int(input()) for j in range(tmp): speech_l[i].append(list(map(int,input().split()))) for i in range(2**N): sw=0 l=[1]*N tmp=N for j in range(N): if ((i >> j)&1): tmp-=1 l[j]=0 for j in range(N): if l[j] == 1: for k in speech_l[j]: if l[k[0]-1] != k[1]: sw=1 if sw==0: ans=max(ans,tmp) print(ans)
N = int(input()) query = [] ans = 0 for i in range(N): A = int(input()) query.append([list(map(int, input().split())) for j in range(A)]) for i in range(1<<N): count = 0 FLG = True for j in range(N): if (i >> j) & 1: count += 1 for x, y in query[j]: if (i >> (x - 1)) & 1 != y: FLG = False break if not FLG: break else: ans = max(ans, count) print(ans)
1
121,137,783,869,072
null
262
262
import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) def resolve(): H, W, K = lr() S = [] for i in range(H): S.append([int(s) for s in sr()]) ans = 2000 idx = [0]*H for div in range(1<<(H-1)): g = 0 for i in range(H): idx[i] = g if div>>i&1: g += 1 g += 1 c = [[0]*W for i in range(g)] for i in range(H): for j in range(W): c[idx[i]][j] += S[i][j] ok = True for i in range(g): for j in range(W): if c[i][j] > K: ok = False if not ok: continue num = g-1 now = [0]*g def add(j): for i in range(g): now[i] += c[i][j] for i in range(g): if now[i] > K: return False return True for j in range(W): if not add(j): num += 1 now = [0]*g add(j) ans = min(ans, num) print(ans) resolve()
from itertools import product H, W, K = map(int, input().split()) grid = "" for _ in range(H): grid += input() ans = 10000 for Hcut in product((0, 1), repeat = H-1): Gr_num = sum(Hcut) + 1 old = [0]*Gr_num cnt = 0 for i in range(W): #縦一列のchocoを見る choco = grid[i::W] new = [0]*Gr_num gr = 0 for j in range(H): new[gr] += int(choco[j]) if j < H-1: if Hcut[j] == 1: gr += 1 #そもそも一列でオーバーしてたら詰み。 if max(new) > K: cnt += 10000 break #新しい一列を追加しても大丈夫か確認 check = [old[gr] + new[gr] for gr in range(Gr_num)] if max(check) > K: old = new[:] cnt += 1 else: old = check[:] ans = min(ans, cnt+sum(Hcut)) print(ans)
1
48,287,677,046,180
null
193
193
h,n=map(int, input().split()) a_list=[int(i) for i in input().split()] if sum(a_list)>=h: print("Yes") else: print("No")
H, N = map(int, input().split()) A = map(int, input().split()) print('Yes' if H <= sum(A) else 'No')
1
77,723,554,800,512
null
226
226
#import numpy as np #def area--------------------------# #ryouno syokiti class ryou: def flinit(self): room=list() for i in range(10): room+=[0] return room #def kaijo([a_1,a_2,a_3,a_4,a_5,a_6,a_7,a_8,a_9,a_10]): #def kaijo(x): # y=[] # for i in x: # y=y+ " "+x[i] # return y def kaijo(x): print "", for i in range(len(x)-1): print str(x[i]), print str(x[len(x)-1]) #----------------------------------# floor_11=ryou().flinit() floor_12=ryou().flinit() floor_13=ryou().flinit() floor_21=ryou().flinit() floor_22=ryou().flinit() floor_23=ryou().flinit() floor_31=ryou().flinit() floor_32=ryou().flinit() floor_33=ryou().flinit() floor_41=ryou().flinit() floor_42=ryou().flinit() floor_43=ryou().flinit() fldic={"11":floor_11, "12":floor_12, "13":floor_13, "21":floor_21, "22":floor_22, "23":floor_23, "31":floor_31, "32":floor_32, "33":floor_33, "41":floor_41, "42":floor_42, "43":floor_43 } #----------------------------------# #1kaime yomikomi n=int(raw_input()) #nkaime syusyori for l in range(n): list_mojiretsu=raw_input().split(" ") henka=map(int,list_mojiretsu) fldic[str(henka[0])+str(henka[1])][henka[2]-1]+=henka[3] kaijo(floor_11) kaijo(floor_12) kaijo(floor_13) print "####################" kaijo(floor_21) kaijo(floor_22) kaijo(floor_23) print "####################" kaijo(floor_31) kaijo(floor_32) kaijo(floor_33) print "####################" kaijo(floor_41) kaijo(floor_42) kaijo(floor_43)
k=int(input()) se=0 for i in range(k): se=se*10 se+=7 i+=1 if se%k==0: print(i) exit() se%=k print('-1')
0
null
3,611,500,395,580
55
97
N = int(input()) x = N // 100 y = N % 100 if y <= 5 * x: print(1) else: print(0)
x = int(input()) d = x%100 c = 0 for i in [5,4,3,2,1]: c += d//i d = d%i if c*100 + x%100 > x: print(0) else: print(1)
1
127,353,485,960,470
null
266
266
while True: a = input() b = a.split(' ') b.sort(key=int) if int(b[0]) == 0 and int(b[1]) == 0: break print('%s %s' % (b[0],b[1]))
while 1: s,t = map(int,input().split()) if s>t: s,t = t,s if (s,t)==(0,0): break print(s,t)
1
517,416,389,710
null
43
43
H1, M1, H2, M2, K = map(int, input().split()) r = (H2*60+M2)-(H1*60+M1)-K print(r)
h1, m1, h2, m2, k = map(int, input().split()) d = (h2 - h1) * 60 + (m2 - m1) print(max(d - k, 0))
1
18,073,720,300,740
null
139
139
a, b = map(int, raw_input().split()) print '%d %d %f' %(a/b, a%b, a/float(b))
#coding:utf-8 a,b=map(int,input().split()) print(str(a//b)+" "+str(a%b)+" "+"%.6f"%(a/b))
1
596,596,747,460
null
45
45
K = int(input()) s = input() n=len(s) def find_power(n,mod=10**9+7): powlist=[0]*(n+1) powlist[0]=1 powlist[1]=1 for i in range(2,n+1): powlist[i]=powlist[i-1]*i%(mod) return powlist def find_inv_power(n,mod=10**9+7): powlist=find_power(n) check=powlist[-1] first=1 uselist=[0]*(n+1) secondlist=[0]*30 secondlist[0]=check secondlist[1]=check**2 for i in range(28): secondlist[i+2]=(secondlist[i+1]**2)%(10**9+7) a=format(10**9+5,"b") for j in range(30): if a[29-j]=="1": first=(first*secondlist[j])%(10**9+7) uselist[n]=first for i in range(n,0,-1): uselist[i-1]=(uselist[i]*i)%(10**9+7) return uselist mod = 10**9+7 NUM = (2*10**6)+100 p_lis=find_power(NUM,mod) ip_lis=find_inv_power(NUM,mod) def comb(n,r,mod=10**9+7): if n<r: return 0 elif n>=r: return (p_lis[n]*ip_lis[r]*ip_lis[n-r])%(mod) ans=0 for k in range(K+1): ans+=(comb(n-1+K-k,n-1)* pow(25,K-k,mod)* pow(26,k,mod)) print(ans%mod)
class Cmb: g1=[1,1] g2=[1,1] inv=[0,1] def __init__(self,mod,upper_limit): self.mod=mod for i in range(2,upper_limit+1): Cmb.g1.append(Cmb.g1[-1]*i%mod) Cmb.inv.append(-Cmb.inv[mod%i]*(mod//i)%mod) Cmb.g2.append(Cmb.g2[-1]*Cmb.inv[-1]%mod) def cmb(self,n,r): if r<0 or n<r: return 0 r=min(r,n-r) return Cmb.g1[n]*Cmb.g2[r]*Cmb.g2[n-r]%self.mod k=int(input()) s=len(input()) mod=10**9+7 Cmb=Cmb(mod,k+s) ans=1 for i in range(1,k+1): ans=(ans*26+Cmb.cmb(i+s-1,s-1)*pow(25,i,mod))%mod print(ans)
1
12,800,680,480,270
null
124
124
X, Y, Z = map(int, input().split()) print('{} {} {}'.format(Z, X, Y))
import sys def ISS(): return sys.stdin.readline().rstrip().split() s,t =ISS() print(t+s)
0
null
70,275,921,175,458
178
248
n=int(input()) a=n%10 if a==2 or a==4 or a==5 or a==7 or a==9: print("hon") elif a==0 or a==1 or a==6 or a==8: print("pon") else: print("bon")
# -*- coding: utf-8 -*- import math a, b, C = map(int, raw_input().split()) radC = math.radians(C) c = math.sqrt(a*a+b*b-2*a*b*math.cos(radC)) S = a*b/2*math.sin(radC) print S print a+b+c print 2*S/a
0
null
9,713,077,098,398
142
30
n, m = (int(i) for i in input().split()) h = [int(i) for i in input().split()] g = [[] for i in range(n)] for i in range(m): a, b = (int(i) for i in input().split()) a -= 1 b -= 1 g[a].append(b) g[b].append(a) cnt = 0 for i in range(n): mx = -1 for j in g[i]: mx = max(mx, h[j]) cnt += h[i] > mx print(cnt)
from collections import Counter,defaultdict,deque from heapq import heappop,heappush from bisect import bisect_left,bisect_right import sys,math,itertools,fractions,pprint sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n,m = inpl() h = inpl() g = [[] for _ in range(n)] for _ in range(m): a,b = inpl() a,b = a-1,b-1 g[a].append(b) g[b].append(a) res = 0 for i in range(n): for j in g[i]: if h[j] >= h[i]: break else: res += 1 print(res)
1
25,070,186,531,810
null
155
155
while True: x = input().split() if x[1] == '+': y = int(x[0])+int(x[2]) print(y) elif x[1] == '-': y = int(x[0])-int(x[2]) print(y) elif x[1] == '*': y = int(x[0])*int(x[2]) print(y) elif x[1] == '/': y = int(x[0])//int(x[2]) print(y) elif x[1] == '?': break
while True: a, op, b = input().split() if(op == '+'): print(int(a) + int(b)) elif(op == '-'): print(int(a) - int(b)) elif(op == '*'): print(int(a) * int(b)) elif(op == '/'): print(int(a) // int(b)) else: break
1
682,680,428,010
null
47
47
s = input() q = int(input()) for _ in range(q): x = input().split() a, b = int(x[1]), int(x[2]) if x[0] == 'print': print(s[a:b+1]) if x[0] == 'reverse': s = s[:a] + ''.join(reversed(s[a:b+1])) + s[b+1:] if x[0] == 'replace': s = s[:a] + x[3] + s[b+1:]
str = input() q = int(input()) for x in range(q): en = input().split() if en[0] == "print": print(str[int(en[1]):int(en[2])+1]) elif en[0] == "reverse": str = str[:int(en[1])] + str[int(en[1]):int(en[2])+1][::-1] + str[int(en[2])+1:] else: str = str[:int(en[1])] + en[3] + str[int(en[2])+1:]
1
2,075,037,524,484
null
68
68
k = int(input()) S = input() n = len(S) mod = 10**9+7 facs = [1] * (n+k) # invs = [1] * (n+k) nfac = 1 for i in range(1, n+k): nfac = nfac * i % mod facs[i] = nfac # invs[i] = pow(facs[i], mod-2, mod) invn1 = pow(facs[n-1], mod-2, mod) ans = 0 for i in range(k+1): left = facs[i+n-1] * pow(facs[i], mod-2, mod) * invn1 % mod left = left * pow(25, i, mod) % mod ans += left * pow(26, k-i, mod) % mod ans %= mod print(ans)
# F - Strivore K = int(input()) S = list(str(input())) N = len(S) MOD = 10**9+7 fac = [1, 1] inv = [0, 1] finv = [1, 1] for i in range(2, N+K+1): fac.append(fac[-1] * i % MOD) inv.append(MOD - inv[MOD%i] * (MOD//i) % MOD) finv.append(finv[-1] * inv[-1] % MOD) def comb_mod(n, r, m): if (n<0 or r<0 or n<r): return 0 r = min(r, n-r) return fac[n] * finv[n-r] * finv[r] % m ans = 0 for i in range(K+1): tmp = pow(25, i, MOD) tmp *= comb_mod(i+N-1, N-1, MOD) tmp *= pow(26, K-i, MOD) ans += tmp ans %= MOD print(ans)
1
12,800,720,583,910
null
124
124
i=input;i();l=i().split();x=1-('0'in l) for j in l: x*=int(j) if x>1e18: print(-1);quit() print(x)
N=int(input()) As=list(map(int,input().split())) ans=1 if 0 in As: print(0) else: for i in range(N): ans*=As[i] if ans>int(1e18): break print(ans if ans<=int(1e18) else -1)
1
16,213,753,783,700
null
134
134
from decimal import * getcontext().prec=1000 a,b,c=map(int,input().split()) A=Decimal(a)**Decimal("0.5") B=Decimal(b)**Decimal("0.5") C=Decimal(c)**Decimal("0.5") D= Decimal(10) ** (-100) if A+B+D<C: print("Yes") else: print("No")
import sys from math import gcd def input(): return sys.stdin.readline().strip() sys.setrecursionlimit(20000000) MOD = 10 ** 9 + 7 INF = float("inf") def main(): T1, T2 = map(int, input().split()) A1, A2 = map(int, input().split()) B1, B2 = map(int, input().split()) P = (A1 - B1) * T1 Q = (A2 - B2) * T2 if P > 0: P = P * (-1) Q = Q * (-1) if P + Q < 0: print(0) return elif P + Q == 0: print("infinity") return else: S = (-P) // (P + Q) T = (-P) % (P + Q) if T == 0: print(2 * S) else: print(2 * S + 1) if __name__ == "__main__": main()
0
null
91,219,921,026,990
197
269
n, x, m = (int(x) for x in input().split()) dic = {} count = 1 dic[x]=0 ans = [x] bool = True while (count < n): x = pow(x, 2, m) if x not in dic: dic[x] = count ans.append(x) else: roop = ans[dic[x]:count] ans = sum(ans[:dic[x]]) roop_count = (n-dic[x])//len(roop) roop_hasuu = (n-dic[x])%len(roop) ans+=roop_count*sum(roop)+sum(roop[:roop_hasuu]) print(ans) bool = False count = pow(10, 13) count+=1 if bool: print(sum(ans))
s=input() print('YNeos'[(s[2]!=s[3])|(s[4]!=s[5])::2])
0
null
22,555,336,552,352
75
184
mod = 10**9 + 7 max_N = 2 * 10**5 def power(b, e): if e == 0: return 1 half = power(b, e // 2) if e % 2 == 0: return (half * half) % mod else: return (((half * half) % mod) * b) % mod def mod_inv(n): return power(n, mod - 2) fac = [1] * (max_N + 1) for i in range(1, max_N + 1): fac[i] = (i * fac[i - 1]) % mod fac_inv = [1] * (max_N + 1) fac_inv[max_N] = mod_inv(fac[max_N]) for i in range(max_N - 1, -1, -1): fac_inv[i] = (fac_inv[i + 1] * (i + 1)) % mod def choose(n, k): return (((fac[n] * fac_inv[k]) % mod) * fac_inv[n - k]) % mod if __name__ == "__main__": line = input().split(" ") N, K = int(line[0]), int(line[1]) K = min(K, N - 1) ans = 0 for i in range(K + 1): ans = (ans + (choose(N, i) * choose(N - i - 1 + i, i)) % mod) % mod print(ans)
n,k=list(map(int,input().split())) mod=10**9+7 def modinv(x): return pow(x,mod-2,mod) ans=1 comb1=1 comb2=1 for i in range(1,min(n-1,k)+1): comb1*=(n-i+1)*modinv(i) comb2*=(n-i)*modinv(i) comb1%=mod comb2%=mod ans+=comb1*comb2 ans%=mod print(ans)
1
66,713,413,667,252
null
215
215
n=int(input()) s = '' for i in range(11): if n != 0: n -= 1 s += chr(ord('a') + n % 26) n //= 26 print(s[::-1])
N=int(input()) S="abcdefghijklmnopqrstuvwxyz" ans=[] while N>0: N-=1 ans.append(S[N%26]) N//=26 print(''.join(ans[::-1]))
1
11,906,012,363,288
null
121
121
MON = list(map(int,input().split())) while 1: MON[2] = MON[2] - MON[1] if(MON[2] <= 0): print("Yes") break MON[0] = MON[0] - MON[3] if (MON[0] <= 0 ): print("No") break
import math a, b, c, d = map(int, input().split()) if math.ceil(c / b) <= math.ceil(a / d): print('Yes') else: print('No')
1
29,558,352,085,502
null
164
164
a,b,c,d=map(float,input().split()) import math x=math.sqrt((c-a)**2+(d-b)**2) print("{:.5f}".format(x))
# -*- coding: utf-8 -*- from sys import stdin import math # 0 0 1 1 A = list(map(float, stdin.readline().split())) x1, y1, x2, y2 = A[0], A[1], A[2], A[3] distance = math.sqrt(math.pow(x2-x1, 2) + math.pow(y2-y1,2)) print(format(distance,'.8f'))
1
157,585,430,022
null
29
29
N = input() n = int(N[-1]) if n in [2,4,5,7,9]: print('hon') elif n == 3: print('bon') else: print('pon')
N = input () P = '0168' H = '24579' if N[-1] in P: print ('pon') elif N[-1] in H: print ('hon') else: print ('bon')
1
19,156,285,599,330
null
142
142
import sys read = sys.stdin.read readline = sys.stdin.readline readlines = sys.stdin.readlines import numpy as np def main(): n = int(input()) if n == 1: print(1) sys.exit() divs = np.arange(1, n + 1) divs2 = n // divs divs3 = divs2 * (divs2 + 1) // 2 divs3 = divs3 * divs r = divs3.sum() print(r) if __name__ == '__main__': main()
n = int(input()) i = 1 ans = 0 while (i <= n): total = sum(j for j in range(i, n+1, i)) ans += total i += 1 print(ans)
1
11,012,849,394,788
null
118
118
n = int(input()) res = {"AC": 0, "WA": 0, "TLE": 0, "RE": 0} for _ in range(n): seq = input() res[seq] += 1 for key in res.keys(): print(f"{key} x {res[key]}")
#init N = int(input()) S=[input() for i in range(N)] for word in ['AC', 'WA', 'TLE', 'RE']: print('{0} x {1}'.format(word, S.count(word)))
1
8,596,323,530,300
null
109
109
def max_profit(A, n): minv = A[0] for j in range(1, n): if j == 1: maxv = A[j] - A[j-1] if maxv < A[j] - minv: maxv = A[j] - minv if minv > A[j]: minv = A[j] print(maxv) n=int(input()) A=[int(input()) for i in range(n)] max_profit(A, n)
N, M = map(int, input().split()) H = list(map(int, input().split())) AB = [list(map(int, input().split())) for _ in range(M)] g = [set() for i in range(N)] for a, b in AB: a, b = a-1, b-1 g[a].add(b) g[b].add(a) c = 0 for i in range(N): if all(H[c]<H[i] for c in g[i]): c += 1 print(c)
0
null
12,592,205,579,812
13
155
a,b = map(int,input().split()) print(a//b,a%b,"{:.5f}".format(a/b))
while True: try: a = map(int,raw_input().split()) n = [a[0],a[1]] while True: if a[0] < a[1]: tmp = a[0] a[0] = a[1] a[1] = tmp a[0] = a[0] - a[1] if a[0] == 0: break b = n[0]*n[1]/a[1] print "%d %d" % (a[1],b) except EOFError: break
0
null
303,707,425,968
45
5
INF = float("inf") N, K = map(int, input().split()) P = list(map(int, input().split())) C = list(map(int, input().split())) ans = -INF for s in range(N): ### STEP1 cum = [] i = P[s] - 1 #s-> i cum.append(C[i]) while i != s: i = P[i] - 1 cum.append(cum[-1] + C[i]) # STEP2 if K <= len(cum): #1週未満しかできない score = max(cum[:K]) elif cum[-1] <= 0: #一周以上できるが、ループしたら損する場合 score = max(cum) else: # K//Length - 1回だけループし、最後は最適に止まる score1 = cum[-1] * (K//len(cum) - 1) score1 += max(cum) #ループをK//length回だけループする場合 score2 = cum[-1]*(K//len(cum)) resi = K % len(cum) #残り進める回数 if resi != 0: #まだ進めるなら score2 += max(0, max(cum[:resi])) score = max(score1, score2) ans = max(ans, score) print(ans)
N, K = map(int, input().split()) P = list(map(lambda x: int(x) - 1, input().split())) C = list(map(int, input().split())) maxscore = -(10 ** 18) for st in range(N): cumsum = [0] now = st while(P[now] != st): now = P[now] cumsum.append(cumsum[-1] + C[now]) cumsum.append(cumsum[-1] + C[st]) m = len(cumsum) - 1 loopsum = cumsum[-1] if loopsum < 0: maxscore = max(maxscore, max(cumsum[1:min(K + 1, m + 1)])) continue score = (K // m - 1) * loopsum extended_cumsum = cumsum + [cumsum[i] + loopsum for i in range(1, K % m + 1)] score += max(extended_cumsum) maxscore = max(maxscore, score) print(maxscore)
1
5,377,092,811,740
null
93
93
from collections import defaultdict dic = defaultdict(int) N = int(input()) for i in range(N): temp = str(input()) dic[temp] += 1 MAX = max(dic.values()) ans = [] for x in dic.keys(): if dic[x] == MAX: ans.append(x) ans.sort() print(*ans,sep="\n")
# -*- coding: utf-8 -*- def main(): S = input() T = input() if S == T[:len(S)]: ans = 'Yes' else: ans = 'No' print(ans) if __name__ == "__main__": main()
0
null
45,672,599,875,968
218
147
def solve(): v=list(map(int,input().split())) a=v[0] b=v[1] c=v[2] if c <= a + b: return False return 4 * a * b < (c - a - b)**2 if solve(): print("Yes") else: print("No")
# -*- coding: utf-8 -*- """ Created on Mon Apr 30 11:23:30 2018 ALDS1-4a most simple implementation using the features of the python @author: maezawa """ n = int(input()) s = map(int, input().split()) q = int(input()) t = map(int, input().split()) s_set = set(s) t_set = set(t) sandt = s_set & t_set print(len(sandt))
0
null
26,005,861,941,148
197
22
import sys line = sys.stdin.read().lower() al_dict = {} for al in [chr(i) for i in range(ord('a'), ord('z')+1)]: al_dict[al] = 0 for al in line: if al_dict.get(al) != None: al_dict[al] += 1 for al in al_dict: print('{} : {}'.format(al, al_dict[al]))
k, n = map(int, input().split()) a_list = list(map(int, input().split())) longest = 0 for i in range(n-1): distance = a_list[i+1] - a_list[i] longest = max(longest, distance) print(k-max(longest, k-a_list[n-1]+a_list[0]))
0
null
22,453,499,120,192
63
186
r=input();p=3.1415926535897;print "%.9f"%(p*r*r),r*2*p
import math r = float(raw_input()) print str("{:.10f}".format(r*r*math.pi)) + ' ' + str("{:.10f}".format(2*r*math.pi))
1
645,517,061,382
null
46
46
def cmb(n,r,mod): if r<0 or r>n:return 0 r=min(r,n-r) return g1[n]*g2[r]*g2[n-r]%mod mod=998244353 n,m,k=map(int,input().split()) g1=[1,1] g2=[1,1] inverse=[0,1] for i in range(2,n): g1.append((g1[-1]*i)%mod) inverse.append((-inverse[mod%i]*(mod//i))%mod) g2.append((g2[-1]*inverse[-1]%mod)) ans=(m*(m-1)**(n-1))%mod for i in range(1,k+1): ans +=cmb(n-1,i,mod)*m*pow(m-1,n-1-i,mod) ans %=mod print(ans)
N,M,K=map(int,input().split()) mod=998244353 def cmb(n, r, mod): if ( r<0 or r>n ): return 0 r = min(r, n-r) return g1[n] * g2[r] * g2[n-r] % mod g1 = [1, 1] # 元テーブル g2 = [1, 1] #逆元テーブル inverse = [0, 1] #逆元テーブル計算用テーブル for i in range( 2, N + 1 ): g1.append( ( g1[-1] * i ) % mod ) inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod ) g2.append( (g2[-1] * inverse[-1]) % mod ) ans=0 for k in range(K+1): ans+=(M*pow(M-1,N-1-k,mod)*cmb(N-1,k,mod))%mod ans=ans%mod print(ans%mod)
1
23,241,752,253,038
null
151
151
# coding: utf-8 import sys #from operator import itemgetter sysread = sys.stdin.buffer.readline read = sys.stdin.buffer.read #from heapq import heappop, heappush from collections import defaultdict sys.setrecursionlimit(10**7) #import math #from itertools import product, accumulate, combinations, product #import bisect# lower_bound etc #import numpy as np #from copy import deepcopy #from collections import deque def run(): N = input() S = input() dp = [0] * 1000 ans = 0 for n in S: n = int(n) #print(dp) for i in range(1000): if i // 100 == n and dp[i] == 0: dp[i] = 1 #print(f'{i} -> 1') elif (i // 10) % 10 == n and dp[i] == 1: dp[i] = 2 #print(f'{i} -> 2') elif i % 10 == n and dp[i] == 2: dp[i] = 3 #print(f'{i} -> 3') ans += 1 print(ans) #print(factorials) if __name__ == "__main__": run()
def is_passcode_exist(S,passcode): passcode_idx = 0 passcode_is_exist = False for c in S: if passcode_idx == 3: passcode_is_exist = True break if passcode[passcode_idx] == c: passcode_idx += 1 if passcode_idx == 3: passcode_is_exist = True return passcode_is_exist if __name__ == "__main__": N = int(input()) S = input() count = 0 for i in range(0,1000): if is_passcode_exist(S,str(i).zfill(3)): count += 1 print(count)
1
128,977,098,538,082
null
267
267
a=input() print(a.replace('?','D'))
S = input() ans="" for i in range(len(S)): if S[i] == "?": ans += "D" else: ans += S[i] print(ans)
1
18,434,840,444,598
null
140
140
i=0 while 1: i+=1 x,y=map(int, raw_input().split()) if x==0 and y==0: break print min(x,y),max(x,y)
c = 0 while True: a = input().split(' ') x = int(a[0]) y = int(a[1]) if (x or y) == 0: break; elif x < y: print(x,y) elif x > y: print(y,x) elif x == y: print(x,y) c += 1
1
535,177,860,192
null
43
43
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np N = int(readline()) XY = np.array(read().split(),np.int64) X = XY[::2]; Y = XY[1::2] dx = X[:,None] - X[None,:] dy = Y[:,None] - Y[None,:] dist_mat = (dx * dx + dy * dy) ** .5 answer = dist_mat.sum() / N print(answer)
from itertools import permutations N = int(input()) XY = [] for _ in range(N): x, y = map(int, input().split()) XY.append((x, y)) ans = 0 c = 0 for p in permutations(range(N)): dist = 0 x1, y1 = XY[p[0]] for i in p[1:]: x, y = XY[i] dist += ((x1 - x) ** 2 + (y1 - y) ** 2) ** 0.5 ans += dist c += 1 print(ans / c)
1
148,191,877,218,030
null
280
280
from math import * def az9(): r = float(input()) print "%5f"%(pi*r*r), "%5f"%(2*pi*r) az9()
import math r=float(input()) print("%.6f"%(r**2*math.pi),"%.6f"%(r*2*math.pi))
1
650,328,098,816
null
46
46
from fractions import gcd from functools import reduce N = int(input()) A = list(map(int, input().split())) m = 1000000007 lcm = reduce(lambda a, b: a * b // gcd(a, b), A) print(sum(lcm // a for a in A) % m)
# from fractions import gcd # P = 10**9+7 # N = int(input()) # S = list(map(int, input().split())) # l = {2:0} # for num in S: # temp = num # M = temp//2+2 # cnt = 0 # while temp%2 == 0: # cnt += 1 # temp //= 2 # l[2] = max(l[2], cnt) # i = 3 # while temp > 1 and i < M: # cnt = 0 # while temp%i == 0: # cnt += 1 # temp //= i # if cnt > 0: # if i in l: # l[i] = max(l[i], cnt) # else: # l[i] = cnt # i += 2 # if temp > 1: # if temp in l: # l[temp] = max(l[temp], 1) # else: # l[temp] = 1 # ans = 0 # for i in range(N): # ans = (temp//S[i]+ans)%P # print(ans) from fractions import gcd P = 10**9+7 N = int(input()) S = list(map(int, input().split())) temp = S[0] for i in range(1, N): temp = temp*S[i] // gcd(temp, S[i]) temp %= P ans = 0 for num in S: ans = ((temp*pow(num, P-2, P))%P+ans)%P print(ans)
1
87,910,442,127,232
null
235
235
#!/usr/bin/env python3 def next_line(): return input() def next_int(): return int(input()) def next_int_array_one_line(): return list(map(int, input().split())) def next_int_array_multi_lines(size): return [int(input()) for _ in range(size)] def next_str_array(size): return [input() for _ in range(size)] def main(): h, w, k = map(int, input().split()) ch = [] for _ in range(h): ch.append(next_line()) # print(ch) res = 0 for i in range(1 << h): for j in range(1 << w): count = 0 for l in range(h): for m in range(w): if ch[l][m] == "#" and (i & (1 << l) == 0) and (j & (1 << m) == 0): count += 1 if count == k: res += 1 print(res) if __name__ == '__main__': main()
import copy def countKuro( t,p1,p2 ): count=0 for i in range(h): if p1 & (1<<i) : for j in range(w): if p2 & (1<<j) : if t[i][j]=="#": count+=1 return count h,w,k=map(int, input().split()) s=[] for i in range(h): s.append( input() ) t=copy.copy(s) ans=0 for i in range(1<<h): for j in range(1<<w): # print(i,j, countKuro(s,i,j)) if k==countKuro(s, i,j): ans+=1 print(ans)
1
8,895,567,967,090
null
110
110
H,N=map(int,input().split()) deathblows=map(int,input().split()) if sum(deathblows) >= H: print('Yes') else: print('No')
N, M = [int(v) for v in input().rstrip().split()] r = 'Yes' if N == M else 'No' print(r)
0
null
80,804,410,739,490
226
231
h = list(map(int, input().split())) m = 0 m += 60 - h[1] if m != 0: h[0] += 1 m += h[3] + (h[2]-h[0]) * 60 print(m-h[-1])
while True: c=0 x, y = map(int, input().split()) if x == 0 and y== 0: break for i in range(1, x+1): for j in range(i+1, x+1): for k in range(j+1, x+1): if i+j+k == y: c += 1 print (c)
0
null
9,653,168,610,038
139
58
from collections import deque q = deque() for i in range(int(input())): command_line = input().split(" ") command = command_line[0] arg = "" if len(command_line) > 1: arg = command_line[1] if command == "insert": q.appendleft(arg) elif command == "delete": try: q.remove(arg) except ValueError: pass elif command == "deleteFirst": q.popleft() else: q.pop() print(" ".join(q))
def popcount(x): c = 0 while x > 0: if x & 1: c += 1 x //= 2 return c def f(x): if x==0: return 0 return f(x % popcount(x)) + 1 n = int(input()) X = input() po = X.count('1') pp = po + 1 pm = max(1, po - 1) rp = rm = 0 for x in X: rp = (rp*2 + int(x)) % pp rm = (rm*2 + int(x)) % pm bp = [0]*(n) # 2^i % (po+1) bm = [0]*(n) # 2^i % (po-1) bp[n-1] = 1 % pp bm[n-1] = 1 % pm for i in range(n-1, 0, -1): bp[i-1] = bp[i]*2 % pp bm[i-1] = bm[i]*2 % pm for i in range(n): if X[i] == '0': ri = (rp + bp[i]) % pp else: if po-1 != 0: ri = (rm - bm[i]) % pm else: print(0) continue print(f(ri) + 1)
0
null
4,116,296,050,198
20
107
from collections import deque from math import ceil # n个怪物,d杀伤半径,a杀伤值 n, d, a = map(int, input().split()) ms = [map(int, input().split()) for i in range(n)] ms = sorted([(pos, ceil(hp / a)) for pos, hp in ms]) bombs = deque() ans = 0 valid_bomb = 0 for pos, hp in ms: # 查看队列里的bomb是否对当前怪物有效 while bombs and bombs[0][0] < pos: bomb_border, bomb_cnt = bombs.popleft() valid_bomb -= bomb_cnt # 还需新加多少bomb才能灭掉当前怪物 bomb_cnt = max(0, hp - valid_bomb) valid_bomb += bomb_cnt ans += bomb_cnt # 新加的bomb放入队列 if bomb_cnt > 0: bombs.append([pos + d * 2, bomb_cnt]) print(ans)
from bisect import * from math import * N,D,A=map(int,input().split()) monsters=[list(map(int,input().split())) for _ in range(N)] monsters.sort(key=lambda x:x[0]) killingrange=[0]*N monsterspoint=[] monstershp=[] imos=[0]*N for i in range(N): monsterspoint.append(monsters[i][0]) monstershp.append(monsters[i][1]) for i in range(N): ind=bisect(monsterspoint,monsterspoint[i]+2*D) killingrange[i]=ind #print(killingrange) cnt=0 for i in range(N): monstershp[i]=monstershp[i]+imos[i] if (monstershp[i]>0): cnt=cnt+ceil(monstershp[i]/A) imos[i]=imos[i]-A*ceil(monstershp[i]/A) if killingrange[i]<N: imos[killingrange[i]]=imos[killingrange[i]]+A*ceil(monstershp[i]/A) monstershp[i]=monstershp[i]-A*ceil(monstershp[i]/A) if i<N-1: imos[i+1]=imos[i]+imos[i+1] #print(monstershp,imos) print(cnt)
1
82,263,809,455,972
null
230
230
d, t, s = map(int, input().split()) dist = t * s - d if dist >= 0: print("Yes") elif dist < 0: print("No")
N, K, S = map(int, input().split()) d = S if S == int(1e9): d -= 1 else: d += 1 ans = [1 for _ in range(N)] for i in range(N): if K > 0: ans[i] = S K -= 1 else: ans[i] = d print(*ans)
0
null
47,135,246,795,330
81
238
a,b = map(int,input().split()) if a >= b: i = 1 while i > 0: if (a*i) % b == 0: print(a*i) break i += 1 else: i = 1 while i > 0: if (a*i) % b == 0: print(a*i) break i += 1
a,b = map(int, input().split()) def gcd(x, y): if y < x: x,y = y,x while x%y != 0: x,y = y,x%y return y def lcm(x, y): return (x*y)//gcd(x,y) print(lcm(a,b))
1
113,038,528,766,420
null
256
256
import sys sys.setrecursionlimit(2147483647) INF=float("inf") MOD=10**9+7 # 998244353 input=lambda:sys.stdin.readline().rstrip() def resolve(): n,x,y=map(int,input().split()) x-=1; y-=1 E1=[[] for _ in range(n)] E2=[[] for _ in range(n)] for _ in range(n-1): u,v=map(int,input().split()) u-=1; v-=1 E1[u].append(v) E1[v].append(u) E2=E1 # E2 において、y-rooted tree とみて、depth,par を計算 par=[None]*n # x の必勝頂点を判定するのに必要 par[y]=y depth2=[None]*n depth2[y]=0 Q=[y] while(Q): v=Q.pop() for nv in E2[v]: if(depth2[nv] is not None): continue depth2[nv]=depth2[v]+1 par[nv]=v Q.append(nv) # E1の辺で、E2での距離が 3 以上のものは必勝 win=[0]*n for v in range(n): for nv in E1[v]: if(par[v]==nv or par[nv]==v or par[v]==par[nv] or par[par[v]]==nv or par[par[nv]]==v): continue win[nv]=win[v]=1 # E1 において、x-rooted tree とみて探索 # depth1 < depth2 -> 以降も探索できる # depth1 = depth2 -> そこで捕まる ans=depth2[x] depth1=[None]*n depth1[x]=0 Q=[x] while(Q): v=Q.pop() if(win[v]): # 探索できる状態 & 必勝頂点にいれば勝ち print(-1) return for nv in E1[v]: if(depth1[nv] is not None): continue depth1[nv]=depth1[v]+1 ans=max(ans,depth2[nv]) if(depth1[nv]<depth2[nv]): Q.append(nv) print(ans-1) resolve()
n = int(input()) a = list(map(int, input().split())) ret = 0 now = a[0] for i in range(1, n): if now > a[i]: ret += now - a[i] a[i] = now now = a[i] print(ret)
0
null
61,015,857,629,022
259
88
def solve(string): n, k, *p = map(int, string.split()) p = sorted(p) return str(sum(p[:k])) if __name__ == '__main__': import sys print(solve(sys.stdin.read().strip()))
N,K = list(map(int,input().split())) P = list(map(int,input().split())) def bubblesort(l): for index in range(len(l)-1, 0, -1): for low in range(index): if l[low] > l[low+1]: tmp = l[low+1] l[low+1] = l[low] l[low] = tmp return l bubblesort(P) sum = 0 for i in range(K): sum = sum + P[i] print(sum)
1
11,507,267,751,606
null
120
120
n = int(input()) result = '' for x in range(3, n+1): if x % 3 == 0 or '3' in str(x): result += (' '+str(x)) print(result)
import sys n = int(raw_input()) #n = 30 for i in range(1, n+1): if i % 3 == 0: sys.stdout.write(" {:}".format(i)) elif str(i).find('3') > -1: sys.stdout.write(" {:}".format(i)) print("")
1
914,493,458,880
null
52
52
from itertools import permutations N = int(input()) P = tuple(map(int, input().split())) Q = tuple(map(int, input().split())) r = 0 for i, x in enumerate(permutations([j for j in range(1,N+1)])): if x == P: r = abs(r-i) if x == Q: r = abs(r-i) print(r)
import itertools N = int(input()) P = list(map(int,input().split())) Q = list(map(int,input().split())) w = 0 x = 0 S = [] T = [] for i in range(N): S.append(i+1) for j in itertools.permutations(S): T.append(list(j)) a = T.index(P) b = T.index(Q) print(abs(a-b))
1
100,633,970,501,568
null
246
246
def make_divisors(n): ''' nの約数の配列を返す ''' lower_divisors, upper_divisors = [], [] i = 1 while i * i <= n: if n % i == 0: lower_divisors.append(i) if i != n // i: upper_divisors.append(n // i) i += 1 return lower_divisors + upper_divisors[::-1] def solve(): N = int(input()) D = make_divisors(N) ans = N - 1 for d in D: ans = min(ans, N // d - 1 + d - 1) print(ans) if __name__ == "__main__": solve()
#from statistics import median #import collections #aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0] from fractions import gcd from itertools import combinations,permutations,accumulate, product # (string,3) 3回 #from collections import deque from collections import deque,defaultdict,Counter import decimal import re import math import bisect # # # # pythonで無理なときは、pypyでやると正解するかも!! # # # my_round_int = lambda x:np.round((x*2 + 1)//2) # 四捨五入g # # インデックス系 # int min_y = max(0, i - 2), max_y = min(h - 1, i + 2); # int min_x = max(0, j - 2), max_x = min(w - 1, j + 2); # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 #mod = 9982443453 #mod = 998244353 from sys import stdin readline = stdin.readline def readInts(): return list(map(int,readline().split())) def readTuples(): return tuple(map(int,readline().split())) def I(): return int(readline()) n = I() def yaku(m): ans = [] i = 1 while i*i <= m: if m % i == 0: j = m // i ans.append(i) i += 1 ans = sorted(ans) return ans a = yaku(n) #print(a) ans = float('inf') for v in a: ans = min(ans, (v-1)+(n//v)-1) print(ans)
1
161,691,461,247,040
null
288
288
x=int(input()) for a in range(-200,200,1): for b in range(-200,200,1): if a**5 - b**5 == x: print(a,b) exit()
x = int(input()) for i in range(1,121): for j in range(-121,121): if x == i**5 - j**5: print(i,j) exit()
1
25,606,151,612,160
null
156
156
import sys while True: n, x = [ int( val ) for val in sys.stdin.readline().split( " " ) ] if 0 == n and 0 == x: break cnt = 0 for i in range( 1, n-1 ): if x <= i: break for j in range( i+1, n ): if x <= ( i+j ): break for k in range( j+1, n+1 ): s = ( i + j + k ) if x == s: cnt += 1 break elif x < s: break print( cnt )
import sys def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) #空白あり A = [LI() for _ in range(3)] N = I() flag = [[0]*3 for _ in range(3)] for i in range(N): b = I() for j in range(3): for k in range(3): if A[j][k] == b: flag[j][k] = 1 for i in range(3): if flag[i][0] == flag[i][1] == flag[i][2] == 1 or flag[0][i] == flag[1][i] == flag[2][i] == 1: print('Yes') exit() if flag[0][0] == flag[1][1] == flag[2][2] == 1 or flag[0][2] == flag[1][1] == flag[2][0] == 1: print('Yes') exit() print('No')
0
null
30,690,421,123,840
58
207
n = int(input()) s = input() t = s[:len(s)//2] if 2*t == s: print("Yes") else: print("No")
nn = input() n = str(input()) if len(n) % 2 == 1: print('No') else: a = n[0 : len(n)//2] b = n[len(n)//2 : len(n)] if a == b: print('Yes') else: print('No')
1
146,704,649,211,912
null
279
279
n = int(input()) sum=0 for j in range(1,n+1): sum+=(n//j)*(n//j+1)//2*j print(sum)
# coding: utf-8 """ import codecs import sys sys.stdout = codecs.getwriter("shift_jis")(sys.stdout) # ?????? sys.stdin = codecs.getreader("shift_jis")(sys.stdin) # ??\??? # ??\??¬?????????print??????????????´?????? print(u'?????????') ??¨?????? # ??\??¬?????????input??? input(u'?????????') ??§OK # ??°?¢???????????????????????????´??????6,7???????????????????????¢?????? """ s = raw_input() p = raw_input() #s = "abaabbaabbaaaaaabbaabba" #p = "aabbaabaabb" cnt = s.count(p[0]) #????§?????£?????????° flag = 0 if cnt == -1: #p???????????????????????¨????????? print("No") else: #????§?????£?????????¨?????? start_search = 0 #????´¢?????????????§??????? while cnt > 0: index = s.find(p[0], start_search) #????§???????????????? ans = 1 for i in range(len(p)): if index + i >= len(s): #????°?????????????????????´?????????????????????????????????????????? j = i - len(s) else: j = i if s[index + j] != p[i]: #1????????§????????£????????????????????§??¢?´¢?????? ans = 0 break if ans == 1: print("Yes") flag = 1 break start_search = index + 1 #print(start_search) cnt -= 1 if flag == 0: print("No")
0
null
6,318,551,508,808
118
64
a = int(input()) b = int(input()) if (a == 1 and b == 2) or (a == 2 and b == 1): print(3) elif (a == 1 and b == 3) or (a == 3 and b == 1): print(2) else: print(1)
ab = set([input() for _ in range(2)]) s = {'1', '2', '3'} print(''.join(s-ab))
1
110,826,722,103,230
null
254
254
#k = int(input()) #s = input() #a, b = map(int, input().split()) #l = list(map(int, input().split())) n, a, b = map(int, input().split()) if (a == 0): print (0) exit() ans = n // (a+b) * a amari = n % (a+b) if (amari <= a): ans += amari else: ans +=a print (ans)
n = int(input()) S = input() ans = 0 nums = list(map(str, range(10))) for i in nums: s1 = S.find(i) if s1 < 0: continue for j in nums: s2 = S.find(j, s1+1) if s2 < 0: continue for k in nums: s3 = S.find(k, s2+1) if s3 > 0: ans += 1 print(ans)
0
null
92,531,739,870,570
202
267
from time import * from random import * t=time() T0,T1=2000,600 Tt=2000 D=int(input()) C=list(map(int,input().split())) S=[list(map(int,input().split())) for i in range(D)] X=[0]*26 XX=[0]*26 P=[] for i in range(D): for j in range(26): X[j]+=C[j] XX[j]+=X[j] P.append([]) for j in range(26): P[i].append(j) P[i].sort(reverse=True,key=lambda x:X[x]+S[i][x]) XX[P[i][0]]-=X[P[i][0]] X[P[i][0]]=0 SC,SC2=0,0 for i in range(D): SC+=S[i][P[i][0]] YY=[] Y=[] A,B=0,0 e=0 E=1 for i in range(50): e+=E E*=1/(i+1) def f(x): global e,Tt if x>=0: return True else: return randrange(0,10000000)<=pow(e,x/Tt) for l in range(8): for k in range(25): for i in range(D): SC2=SC YY=XX[:] Y=X[:] SC2-=S[i][P[i][0]] SC2+=S[i][P[i][k+1]] for j in range(26): Y[j]=0 YY[P[i][0]],YY[P[i][k+1]]=0,0 for j in range(D): if j==i: Z=P[j][k+1] else: Z=P[j][0] Y[P[i][0]]+=C[P[i][0]] Y[P[i][k+1]]+=C[P[i][k+1]] Y[Z]=0 YY[P[i][0]]+=Y[P[i][0]] YY[P[i][k+1]]+=Y[P[i][k+1]] if f((SC2-sum(YY))-(SC-sum(XX))): P[i].insert(0,P[i][k+1]) del P[i][k+2] XX=YY[:] SC=SC2 for i in range(1,D-1): SC2=SC YY=XX[:] Y=X[:] A=i B=randrange(A+1,D) SC2-=S[A][P[A][0]]+S[B][P[B][0]] SC2+=S[A][P[B][0]]+S[B][P[A][0]] for j in range(26): Y[j]=0 YY[P[A][0]],YY[P[B][0]]=0,0 for j in range(D): if j==A: Z=P[B][0] elif j==B: Z=P[A][0] else: Z=P[j][0] Y[P[A][0]]+=C[P[A][0]] Y[P[B][0]]+=C[P[B][0]] Y[Z]=0 YY[P[A][0]]+=Y[P[A][0]] YY[P[B][0]]+=Y[P[B][0]] if f((SC2-sum(YY))-(SC-sum(XX))): P[A],P[B]=P[B][:],P[A][:] XX=YY[:] SC=SC2 if k&1: continue B=randrange(0,A) SC2-=S[A][P[A][0]]+S[B][P[B][0]] SC2+=S[A][P[B][0]]+S[B][P[A][0]] for j in range(26): Y[j]=0 YY[P[A][0]],YY[P[B][0]]=0,0 for j in range(D): if j==A: Z=P[B][0] elif j==B: Z=P[A][0] else: Z=P[j][0] Y[P[A][0]]+=C[P[A][0]] Y[P[B][0]]+=C[P[B][0]] Y[Z]=0 YY[P[A][0]]+=Y[P[A][0]] YY[P[B][0]]+=Y[P[B][0]] if f((SC2-sum(YY))-(SC-sum(XX))): P[A],P[B]=P[B][:],P[A][:] XX=YY[:] SC=SC2 Tt=pow(T0,1-(time()-t))*pow(T1,time()-t) ''' X=[0]*26 SC=0 for i in range(D): for j in range(26): X[j]+=C[j] X[P[i][0]]=0 SC-=sum(X) SC+=S[i][P[i][0]] print(SC) ''' for i in range(D): print(P[i][0]+1)
import sys n = int(input()) a = list(map(int,input().split())) ans = 0 if 1 not in a: print(-1) sys.exit() index = 1 for i in a: if i != index: ans+=1 else: index+=1 print(ans)
0
null
62,530,342,709,730
113
257
from scipy import special S = int(input()) top = S // 3 if top == 0: print(0) exit() ans = 1 mod = 10 ** 9 + 7 for i in range(2, top + 1): t = S - 3 * i i -= 1 ans += special.comb(t+i, i, True) print(ans % (mod))
s = int(input()) mod = 10**9 + 7 a = [0] * (2001) a[3] = a[4] = a[5] = 1 for i in range(6, s + 1): a[i] = a[i - 1] + a[i - 3] a[i] %= mod print(a[s])
1
3,249,033,334,572
null
79
79
n=int(input()) s=[] for i in range(n): s.append(input()) s.sort() t=1 m=0 a=s[0] for i in range(n-1): if s[i+1]==a: t+=1 else: a=s[i+1] m=max(t,m) t=1 m=max(t,m) t=1 x=[] a=s[0] for i in range(n-1): if s[i+1]==a: t+=1 else: a=s[i+1] if t==m: x.append(s[i]) t=1 if t==m: x.append(s[len(s)-1]) for i in range(len(x)): print(x[i])
from itertools import permutations n = int(input()) xy = [list(map(int, input().split())) for _ in range(n)] sum = 0 cnt = 0 for i in permutations(xy): for j in range(n - 1): sum += ((i[j][0] - i[j + 1][0]) ** 2 + (i[j][1] - i[j + 1][1]) ** 2) ** 0.5 cnt += 1 print(sum / cnt)
0
null
109,027,438,513,020
218
280
# https://atcoder.jp/contests/abc165/tasks/abc165_c from itertools import combinations_with_replacement N, M, Q = map(int, input().split()) data = [] for _ in range(Q): data.append(list(map(int, input().split()))) res = [] for A in combinations_with_replacement(range(1,M+1), N): score = 0 for i in range(Q): a,b,c,d = data[i] if A[b-1] - A[a-1] == c: score += d res.append(score) print(max(res))
from numpy import cumsum N = int(input()) A = list(map(int, input().split())) a_cum = cumsum(A) cand = [abs(a_cum[i] - (a_cum[-1] - a_cum[i])) for i in range(N)] print(min(cand))
0
null
84,708,844,435,550
160
276
a = list(map(int,input().split())) b = list(map(int,input().split())) if a[0]<= sum(b): print("Yes") else: print("No")
a, b, m = map(int, input().split()) li_a = list(map(int, input().split())) li_b = list(map(int, input().split())) li_c = [] for _ in range(m): x, y, c = map(int, input().split()) x, y = x-1, y-1 li_c.append(li_a[x]+li_b[y]-c) li_a.sort() li_b.sort() li_c.sort() ans = min(li_a[0]+li_b[0], li_c[0]) print(ans)
0
null
65,905,783,104,990
226
200
n = int(input()) a_lst = list(map(int, input().split())) a_lst.sort() if a_lst[0] == 0: answer = 0 else: answer = 1 for i in range(n): a = a_lst[i] answer *= a if answer > 10 ** 18: answer = -1 break print(answer)
input();ans,a=1,[*map(int,input().split())] if 0 in a: print(0) else: for i in a: ans*=i if ans>10**18: print(-1);break else: print(ans)
1
16,286,134,338,608
null
134
134
N,K=map(int,input().split()) A=list(map(int,input().split())) imos=[0 for i in range(N+1)] zero=[0 for i in range(N+1)] ANS=[str(N)]*N if K>=40: ans=" ".join(ANS) print(ans) else: for t in range(K): for i in range(N): l=max(0,i-A[i]) r=min(N,i+A[i]+1) imos[l]+=1 imos[r]-=1 for i in range(0,N): imos[i+1]+=imos[i] A[i]=imos[i] imos=[0 for i in range(N+1)] for i in range(N): A[i]=str(A[i]) ans=" ".join(A) print(ans)
while True: x, y = [int(n) for n in input().split()] if x == 0 and y == 0: break if x < y: print("{} {}".format(x, y)) else: print("{} {}".format(y, x))
0
null
8,012,649,204,710
132
43
A,V=map(int,input().split()) B,W=map(int,input().split()) T=int(input()) v=V-W l=abs(A-B) if l<=v*T: print("YES") else: print("NO")
D=int(input()) c=list(map(int,input().split())) s=[list(map(int,input().split())) for i in range(D)] test=[int(input()) for i in range(D)] lastday=[0 for j in range(26)] points=[0 for i in range(D)] lastday=[lastday[i]+1 for i in range(26)] lastday[test[0]-1]=0 minus=sum([x*y for (x,y) in zip(c,lastday)]) points[0]=s[0][test[0]-1]-minus for i in range(1,D): lastday=[lastday[i]+1 for i in range(26)] lastday[test[i]-1]=0 minus=sum([x*y for (x,y) in zip(c,lastday)]) points[i]=points[i-1]+s[i][test[i]-1]-minus for ps in points: print(ps)
0
null
12,455,257,950,912
131
114
K = int(input()) S = input() if len(S) <= K: print(S) else: print('{}...'.format(S[:K]))
S = list(input()) N = len(S) S_1=S[:N//2] S_2=S[N//2+1:] N_=len(S_1) ans='Yes' for n in range(N_): if S_1[n] != S_1[-(n+1)]: ans='No' break if S_2[n] != S_2[-(n+1)]: ans='No' break for n in range(N): if S[n] != S[-(n+1)]: ans='No' break print(ans)
0
null
33,020,664,839,570
143
190
S = input() count_more = 0 count_less = 0 ans = 0 pre_si = '>' for i, si in enumerate(S): if pre_si == '>' and si == '<': max_n = max(count_more, count_less) min_n = min(count_more, count_less) ans += (max_n+1)*(max_n)//2 # print(i, ans) ans += (min_n)*(min_n-1)//2 count_more = 0 count_less = 0 # print(i, ans) if si == '<': count_more += 1 elif si == '>': count_less += 1 pre_si = si max_n = max(count_more, count_less) min_n = min(count_more, count_less) ans += (max_n+1)*(max_n)//2 ans += (min_n)*(min_n-1)//2 print(ans)
s=input() ans=0 up=0 down=0 if(s[0]=='>'): down+=1 else: up+=1 for i in range(1,len(s)): if(s[i]=='>'): down+=1 else: if(s[i-1]=='>'): high=max(up,down) low=min(up,down) ans+=(high+1)*(0+high)//2 low-=1 ans+=(low+1)*(0+low)//2 up=1 down=0 else: up+=1 else: high=max(up,down) low=min(up,down) ans+=(high+1)*(0+high)//2 low-=1 ans+=(low+1)*(0+low)//2 print(ans)
1
156,448,613,228,140
null
285
285
N, M = map(int, input().split()) l = [[] for _ in range(N)] for i in range(M): p, s = input().split() l[int(p) - 1].append(s) correct = 0 penalty = 0 for ll in l: if 'AC' not in ll: continue correct += 1 penalty += ll.index('AC') print(correct, penalty)
import sys from collections import defaultdict N, M = map(int, input().split()) is_ac = [False] * N wa = [0] * N for i in range(M): p, S = input().split() n = int(p) - 1 if not is_ac[n] and S == "AC": is_ac[n] = True if not is_ac[n] and S == "WA": wa[n] += 1 cnt_ac = is_ac.count(True) cnt_wa = 0 for i in range(N): if is_ac[i]: cnt_wa += wa[i] print(cnt_ac, cnt_wa)
1
93,417,914,393,928
null
240
240
N = int(input()) A = list(map(int, input().split())) answer = 'DENIED' for i in range(0, N): if A[i] % 2 == 0: if A[i] % 3 == 0 or A[i] % 5 == 0: answer = 'APPROVED' else: answer = 'DENIED' break else: answer = 'APPROVED' print(answer)
n = int(input()) A = list(map(int, input().split())) ans = 'APPROVED' for a in A: if a%2 == 0: if a%3 != 0 and a%5 != 0: ans = 'DENIED' print(ans)
1
69,279,263,098,092
null
217
217
c = input() alphabet ="abcdefghijklmnopqrstuvwxyz" ans = alphabet[alphabet.index(c) + 1] print(ans)
if __name__ == '__main__': data_num = int(input()) data = [x for x in input().split(' ')] assert data_num == len(data), "invalid input" data.reverse() output = ' '.join(data) print(output)
0
null
46,864,854,629,180
239
53