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
N = int(input()) for i in range(1, 10): if N % i == 0 and 1 <= N / i <= 9: print('Yes') exit() print('No')
#!/usr/bin/pypy # coding: utf-8 N,M,L=map(int, raw_input().split()) RG=[[ 0 if i==j else float('inf') for i in range(N)] for j in range(N)] for i in xrange(M): f,t,c = map(int, raw_input().split()) if c <= L: RG[f-1][t-1] = c RG[t-1][f-1] = c for k in xrange(N): for i in xrange(N): for j in xrange(i, N): t = RG[i][k] + RG[k][j] if RG[i][j] > t: RG[i][j] = t RG[j][i] = t FG=[[float('inf') for i in range(N)] for j in range(N)] for i in xrange(N): for j in xrange(i, N): if RG[i][j] <= L: FG[i][j] = 1 FG[j][i] = 1 for k in xrange(N): for i in xrange(N): for j in xrange(i, N): t = FG[i][k] + FG[k][j] if FG[i][j] > t: FG[i][j] = t FG[j][i] = t Q=int(raw_input()) for i in xrange(Q): s, t = map(int, raw_input().split()) v = FG[s-1][t-1] if v == float('inf'): print (str(-1)) else: print (str(int(v-1)))
0
null
166,114,228,210,930
287
295
n=input() t,h=0,0 for i in range(n): a,b=raw_input().split() if a>b: t+=3 elif a<b: h+=3 else: t+=1 h+=1 print t,h
def main(): N = int(input()) *P, = map(int, input().split()) mi = N + 1 ret = 0 for x in P: if mi > x: mi = x ret += 1 print(ret) if __name__ == '__main__': main() # import sys # input = sys.stdin.readline # # sys.setrecursionlimit(10 ** 7) # # (int(x)-1 for x in input().split()) # rstrip() # # def binary_search(*, ok, ng, func): # while abs(ok - ng) > 1: # mid = (ok + ng) // 2 # if func(mid): # ok = mid # else: # ng = mid # return ok
0
null
43,802,926,108,748
67
233
n, m, k = map(int, input().split()) aa = list(map(int, input().split())) bb = list(map(int, input().split())) asum = [0] bsum = [0] for i in range(len(aa)): asum.append(asum[i]+aa[i]) for i in range(len(bb)): bsum.append(bsum[i]+bb[i]) j = len(bsum)-1 ans = 0 for i in range(len(asum)): while j >= 0: if k >= asum[i] + bsum[j]: ans = max(ans, i+j) break else: j -= 1 print(ans)
k = int(input()) s = input() s = len(s) mod = 10 ** 9 + 7 n = k + s def _fac_inv(_n, _mod): _fac = [1] * (_n + 1) _inv = [1] * (_n + 1) for i in range(_n): _fac[i + 1] = _fac[i] * (i + 1) % _mod _inv[_n] = pow(_fac[_n], _mod - 2, _mod) for i in range(_n, 0, -1): _inv[i - 1] = _inv[i] * i % _mod return _fac, _inv fac, inv = _fac_inv(n, mod) n25 = [1] n26 = [1] for _ in range(n-s): n25.append((n25[-1] * 25) % mod) n26.append((n26[-1] * 26) % mod) ans = 0 for i in range(s, n + 1): ans = (ans + fac[i-1] * inv[s-1] * inv[i-s] * n25[i-s] * n26[n-i]) % mod print(ans)
0
null
11,786,379,572,190
117
124
N = int(input()) P = list(map(int, input().split())) mn = N + 1 ans = 0 for p in P: if p < mn: ans += 1 mn = min(mn, p) print(ans)
N = int(input()) N_List = list(map(int,input().split())) ct = 0 Current_Min = 2*(10**5) + 1 for i in range(N): if N_List[i] <= Current_Min: ct += 1 Current_Min = N_List[i] print(ct)
1
85,570,166,984,358
null
233
233
import math r = float(input()) print('%.5f %.5f' % (r * r * math.pi, 2 * r * math.pi))
r=float(raw_input()) p=float(3.14159265358979323846264338327950288) s=p*r**2.0 l=2.0*p*r print"%.5f %.5f"%(float(s),float(l))
1
643,096,688,538
null
46
46
i = input() a = int(i)//2 b = int(i)%2 print(a+b)
n = int(input()) print(-(-n//2))
1
58,887,260,705,286
null
206
206
import sys sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): H, W = map(int, input().split()) grid = [list("." + input()) for _ in range(H)] dp = [[f_inf] * (W + 1) for _ in range(H)] dp[0][0] = 0 for h in range(H): for w in range(W + 1): if w == 0: if h != 0: continue next_h, next_w = h, w + 1 if grid[h][w] == "." and grid[next_h][next_w] == "#": dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w] + 1) elif grid[h][w] == "." and grid[next_h][next_w] == "#": dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w] + 1) else: dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w]) else: for dh, dw in [(1, 0), (0, 1)]: next_h, next_w = h + dh, w + dw if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W + 1: continue if grid[h][w] == "." and grid[next_h][next_w] == "#": dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w] + 1) elif grid[h][w] == "." and grid[next_h][next_w] == "#": dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w] + 1) else: dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w]) print(dp[-1][-1]) if __name__ == '__main__': resolve()
h,w=map(int,input().split()) grid=[[1 if s=='#' else 0 for s in list(input())] for i in range(h)] #print(grid) maxi=10**5 from collections import deque visited=[[maxi]*w for _ in range(h)] def bfs(s): q=deque() q.append(s) visited[s[0]][s[1]]=grid[s[0]][s[1]] for r in range(h): for c in range(w): if r>=1: visited[r][c]=min(visited[r][c],visited[r-1][c]+grid[r][c]) if grid[r-1][c]==1: visited[r][c]=min(visited[r][c],visited[r-1][c]) if c>=1: visited[r][c]=min(visited[r][c],visited[r][c-1]+grid[r][c]) if grid[r][c-1]==1: visited[r][c]=min(visited[r][c],visited[r][c-1]) bfs([0,0]) print(visited[-1][-1])
1
49,325,760,880,328
null
194
194
N = int(input()) N = N % 10 if N in (2, 4, 5, 7, 9): print ("hon") elif N in (0, 1, 6, 8): print ("pon") elif N == 3: print ("bon")
S=input() print("{}{}{}".format(S[0],'B' if S[1]!='B' else 'R',S[-1]))
0
null
21,747,519,506,308
142
153
n,m,k = map(int,input().split()) if n >= k: print(n-k,m) else: if m - (k-n) < 0: m = 0 else: m -= k - n print(0,m)
r=input().split() A=int(r[0]) B=int(r[1]) K=int(r[2]) if K>=A+B: print("0 0") elif K>=A: print("0 "+str(B-K+A)) else: print(str(A-K)+" "+str(B))
1
104,694,475,638,592
null
249
249
import itertools n=int(input()) l=list(map(int,input().split())) c=itertools.combinations(l,2) ans=sum(x*y for x,y in c) print(ans)
N=int(input()) d=list(map(int,input().split())) a=0 for i in range(N): for k in range(1,N-i): a=a+d[i]*d[i+k] print(a)
1
168,597,000,931,238
null
292
292
import sys if __name__ == "__main__": a, b, c = [int(x) for x in input().split(" ")] if a + b >= c: print("No") sys.exit(0) if 4 * a * b < (c - a - b) ** 2: print("Yes") else: print("No")
vs = input().split() stack = [] for v in vs: if v == '+': stack.append(stack.pop() + stack.pop()) elif v == '-': stack.append(-stack.pop() + stack.pop()) elif v == '*': stack.append(stack.pop() * stack.pop()) else: stack.append(int(v)) print(stack.pop())
0
null
25,865,842,836,610
197
18
S = input() if S == 'ABC': print('ARC') elif S == 'ARC': print('ABC') else: print('ABC または ARC を入力してください')
#!/usr/bin/env python3 import sys # import time # import math # import numpy as np # import scipy.sparse.csgraph as cs # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall # import random # random, uniform, randint, randrange, shuffle, sample # import string # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits # import re # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s) # from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]). # from collections import deque # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate() # from collections import defaultdict # subclass of dict. defaultdict(facroty) # from collections import Counter # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter) # from datetime import date, datetime # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj # from datetime.datetime import strptime # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj # from datetime import timedelta # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available. # from copy import copy, deepcopy # use deepcopy to copy multi-dimentional matrix without reference # from functools import reduce # reduce(f, iter[, init]) # from functools import lru_cache # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed) # from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn). # from heapq import nlargest, nsmallest # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn). # from itertools import count, cycle, repeat # count(start[,step]), cycle(iter), repeat(elm[,n]) # from itertools import groupby # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])] # from itertools import starmap # starmap(pow, [[2,5], [3,2]]) returns [32, 9] # from itertools import product, permutations # product(iter, repeat=n), permutations(iter[,r]) # from itertools import combinations, combinations_with_replacement # from itertools import accumulate # accumulate(iter[, f]) # from operator import itemgetter # itemgetter(1), itemgetter('key') # from fractions import gcd # for Python 3.4 (previous contest @AtCoder) def main(): mod = 998244353 # 10^9+7 inf = float('inf') # sys.float_info.max = 1.79...e+308 # inf = 2 ** 64 - 1 # (for fast JIT compile in PyPy) 1.84...e+19 sys.setrecursionlimit(10**6) # 1000 -> 1000000 def input(): return sys.stdin.readline().rstrip() def ii(): return int(input()) def mi(): return map(int, input().split()) def mi_0(): return map(lambda x: int(x)-1, input().split()) def lmi(): return list(map(int, input().split())) def lmi_0(): return list(map(lambda x: int(x)-1, input().split())) def li(): return list(input()) # def my_update(seq, L): # n = len(seq) # for i in range(n-1): # seq[i+1] += L[i] # n, s = mi() # L = lmi() # dp = [[0] * (n + 1) for j in range(s + 1)] # chain の長さ、場合のかず # # print(dp) # for i in range(n): # for j in range(s, -1, -1): # if j == 0 and L[i] <= s: # dp[L[i]][1] += 1 # elif j + L[i] <= s and dp[j]: # my_update(dp[j + L[i]], dp[j]) # counter # # print(dp) # ans = 0 # for chain_len, num in enumerate(dp[s]): # ans = (ans + pow(2, n - chain_len, mod) * num) % mod # print(ans) # write-up solution """ Ai それぞれ選ぶ or 選ばないと選択して行った時、足して S にできる組み合わせは何パターンできるか? -> まさに二項定理の発想 fi = 1+x^Ai として T = {1, 2, 3} に対する答えは [x^S]f1*f2*f3 T = {1, 2} に対する答えは [x^S]f1*f2 のように計算していく 全パターン f1*f2*f3 + f1*f2 + f1*f3 + f2*f3 + f1 + f2 + f3 の [x^S] の値が答え -> (1+f1)*...*(1+fi)*...*(1+fn) の x^S の係数と一致 [x^S] Π{i=1...n} (2 + x^Ai) を計算せよ、という問である """ n, s = mi() A = lmi() power_memo = [0] * (s + 1) power_memo[0] = 2 if A[0] <= s: power_memo[A[0]] = 1 for i in range(1, n): # print(power_memo) for j in range(s, -1, -1): tmp = (power_memo[j] * 2) % mod if j - A[i] >= 0 and power_memo[j - A[i]]: tmp += power_memo[j - A[i]] power_memo[j] = tmp % mod # print(power_memo) print(power_memo[s]) if __name__ == "__main__": main()
0
null
20,979,076,643,592
153
138
a, b, c, d = map(int, input().split()) def kaisuu(atk, hp): if (hp/atk) > (hp//atk): return hp//atk + 1 else: return hp//atk if kaisuu(b,c) <= kaisuu(d,a): print("Yes") else: print("No")
import math while True: n = int(input()) if n == 0: break dset = list(map(int, input().split())) mean = sum(dset)/len(dset) sigma = math.sqrt(sum([(x-mean)**2 for x in dset])/len(dset)) print('%.06f' % sigma)
0
null
15,062,916,446,468
164
31
n,k=map(int,input().split()) amari=n%k if amari>k: print(k) else: print(min(amari,abs(amari-k)))
import sys input=sys.stdin.readline sys.setrecursionlimit(10 ** 6) #from collections import defaultdict #d = defaultdict(int) #import fractions #import math #import collections #from collections import deque #from bisect import bisect_left #from bisect import insort_left #N = int(input()) #A = list(map(int,input().split())) #S = list(input()) #S.remove("\n") #N,M = map(int,input().split()) #S,T = map(str,input().split()) #A = [int(input()) for _ in range(N)] #S = [input() for _ in range(N)] #A = [list(map(int,input().split())) for _ in range(N)] #import itertools #import heapq #import numpy as np #INF = float("inf") #MOD = 10**9+7 MOD = 10**9+7 import math N,K = map(int,input().split()) ans = [0]*K for i in range(K): p = K-i a = pow(math.floor(K/p),N,MOD) x = 1 while p*(x+1) <= K: a -= ans[p*(x+1)-1] x = x+1 ans[p-1] = a%MOD s = 0 for i in range(K): s += (i+1)*ans[i] s = s%MOD print(s)
0
null
38,233,347,766,310
180
176
N = int(input()) minP = N count = 0 for pi in map(int, input().split()): minP = min(minP, pi) if pi <= minP: count += 1 print(count)
def main(): k = int(input()) if k<10: print(k) return que = [i for i in range(1,10)] cnt = 0 while True: q = que.pop(0) cnt += 1 if cnt==k: print(q) return if q%10==0: que.append(q*10) que.append(q*10+1) elif q%10==9: que.append(q*10+9-1) que.append(q*10+9) else: que.append(q*10+q%10-1) que.append(q*10+q%10) que.append(q*10+q%10+1) if __name__ == "__main__": main()
0
null
62,685,711,542,750
233
181
def main(): N, K = map(int, input().split()) P = list(map(lambda x: int(x)-1, input().split())) C = list(map(int, input().split())) loop = [0] * N loopsum = [0] * N for i in range(N): if loop[i] > 0: continue cnt = 0 cur = i visited = set() score = 0 while cur not in visited: visited.add(cur) cnt += 1 cur = P[cur] score += C[cur] for v in visited: loop[v] = cnt loopsum[v] = score ans = max(C) for i in range(N): if loopsum[i] >= 0 and loop[i] <= K: score = loopsum[i] * (K // loop[i] - 1) limit = K % loop[i] + loop[i] else: score = 0 limit = min(loop[i], K) cur = i for _ in range(limit): cur = P[cur] score += C[cur] ans = max(ans, score) print(ans) if __name__ == "__main__": main()
x, y = map(int, input().split()) print('{} {} {:.5f}'.format(x // y, x % y, x / y))
0
null
2,964,425,228,352
93
45
import math N = int(input()) Ans = math.ceil(N/2) print(Ans)
import sys sys.setrecursionlimit(10 ** 6) # input = sys.stdin.readline #### int1 = lambda x: int(x) - 1 def II(): return int(input()) def MI(): return map(int, input().split()) def MI1(): return map(int1, input().split()) def LI(): return list(map(int, input().split())) def LI1(): return list(map(int1, input().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] INF = float('inf') def solve(): n = II() print((n + 1) // 2) if __name__ == '__main__': solve()
1
58,901,721,186,802
null
206
206
N = int(input()) X = list(map(int, input().split())) a = int(sum(X) / N) b = a + 1 A, B = 0, 0 for x in X: A += (x - a) ** 2 B += (x - b) ** 2 ans = min(A, B) print(ans)
import sys sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline().rstrip() def main(): n, k = map(int, input().split()) p = tuple(map(int, input().split())) c = tuple(map(int, input().split())) ans = -10**18 for i in range(n): start, count = i, 1 val = c[start] while p[start]-1 != i: start = p[start]-1 count += 1 val += c[start] start = i if val > 0: a = (k//count-1)*val ans = max(a, ans) num = count + k % count else: a = 0 num = min(k, count) for _ in range(num): a += c[start] start = p[start] - 1 ans = max(a, ans) print(ans) if __name__ == '__main__': main()
0
null
35,532,946,142,688
213
93
N=int(input()) K=set(input().split()) i=len(K) if i==N: print('YES') else: print('NO')
t_p, t_a, a_p, a_a = map(int, input().split()) while True: a_p -= t_a if a_p <= 0 : print('Yes') exit() t_p -= a_a if t_p <= 0 : print('No') exit()
0
null
51,740,508,481,312
222
164
''' def main(): S = input() cnt = 0 ans = 0 f = 1 for i in range(3): if S[i] == 'R': cnt += 1 else: cnt = 0 ans = max(ans, cnt) print(ans) ''' def main(): S = input() p = S[0] == 'R' q = S[1] == 'R' r = S[2] == 'R' if p and q and r : print(3) elif (p and q) or (q and r): print(2) elif p or q or r: print(1) else: print(0) if __name__ == "__main__": main()
days = input() consecutive_days = 0 max_days = 0 if 'R' in days: max_days = 1 consecutive_days = 1 for weather in range(len(days) - 1): if days[weather] == days[weather + 1] and days[weather] == 'R': consecutive_days += 1 if consecutive_days > max_days: max_days = consecutive_days print(max_days)
1
4,915,335,157,990
null
90
90
import sys def input(): return sys.stdin.readline().rstrip() class Sieve: #区間[2,n]の値の素因数分解 前処理O(nloglogn)素因数分解O(logn) def __init__(self,n=1): self.primes=[] self.f=[0]*(n+1) #ふるい(素数ならその値) self.f[0]=self.f[1]=-1 for i in range(2,n+1): #素数リスト作成 if self.f[i]: continue self.primes.append(i) self.f[i]=i for j in range(i*i,n+1,i): if not self.f[j]: self.f[j]=i #最小の素因数を代入 def is_prime(self, x): return self.f[x]==x def prime_fact(self,x): #素因数分解 {2:p,3:q,5:r,...} fact_dict=dict() while x!=1: p=self.f[x] fact_dict[p]=fact_dict.get(p,0)+1 x//=self.f[x] return fact_dict class Sieve2: #√nまでの素因数で試し割り 前処理O(√nloglogn+√n/logn) def __init__(self,n): self.primes=[] self.f=[0]*(int(n**0.5)+1) #ふるい(素数ならその値) self.f[0]=self.f[1]=-1 for i in range(2,int(n**0.5)+1): #素数リスト作成 if self.f[i]: continue self.primes.append(i) self.f[i]=i for j in range(i*i,int(n**0.5)+1,i): if not self.f[j]: self.f[j]=i #最小の素因数を代入 def prime_fact(self,x): #素因数分解 {2:p,3:q,5:r,...} fact_dict=dict() for p in self.primes: if p*p>x:break while x%p==0: x//=p fact_dict[p]=fact_dict.get(p,0)+1 if x>1:fact_dict[x]=fact_dict.get(x,0)+1 return fact_dict def main(): n=int(input()) A=list(map(int,input().split())) mod=10**9+7 p_lis={} Prime=Sieve2(10**6+5) for a in A: f=Prime.prime_fact(a) for key in f: p_lis[key]=max(p_lis.get(key,0),f[key]) lcm=1 for key in p_lis: lcm=(lcm*pow(key,p_lis[key],mod))%mod ans=0 for a in A: b=lcm*pow(a,mod-2,mod)%mod ans=(ans+b)%mod print(ans) if __name__ == '__main__': main()
x, y = map(int, input().split()) l = list(map(int, input().split())) count = 0 for i in range(x): if l[i] >= sum(l)*(1/(4*y)): count += 1 if count >= y: print("Yes") else: print("No")
0
null
63,575,654,178,048
235
179
from collections import Counter N = int(input()) A = [int(x) for x in input().split()] c = Counter(A) ans = 0 for i in c: ans += c[i] * (c[i] - 1) // 2 for i in range(len(A)): if c[A[i]] == 1: print(ans) else: tmp = c[A[i]] print(ans - tmp * (tmp - 1) // 2 + (tmp - 1) * (tmp - 2) // 2)
N = int(input()) A = list(map(int,input().split())) S = [0] * (N+1) total = 0 for i in A: S[i] =S[i]+ 1 for i in S: total = i * (i - 1) // 2 + total for i in A: #print(i,S[i]) a=total-S[i]+1 print(a)
1
47,982,603,903,610
null
192
192
N = int(input()) S = [int(x) for x in input().split()] T = int(input()) Q = [int(x) for x in input().split()] c = 0 def seach(A, n, key): i = 0 A = A + [key] while A[i] != key: i += 1 return i != n for q in Q: if seach(S, N, q): c += 1 print(c)
ns = int(input()) s = list(map(int, input().split())) nt = int(input()) t = list(map(int, input().split())) count = 0 for i in t: # 配列に番兵を追加 s += [i] j = 0 while s[j] != i: j += 1 s.pop() if j == ns: continue count += 1 print(count)
1
70,478,373,490
null
22
22
n = int(input()) A = list(map(int, input().split())) mod = 10**9+7 A = [a+1 for a in A] C = [0]*(n+1) C[0] = 3 ans = 1 for a in A: if C[a-1] < C[a]: print(0) exit() else: ans *= C[a-1]-C[a] ans %= mod C[a] += 1 print(ans)
mod = 10 ** 9 + 7 n = int(input()) a = map(int, input().split()) cnt = [0] * (n + 1) cnt[-1] = 3 ret = 1 for x in a: ret = ret * cnt[x - 1] % mod cnt[x - 1] -= 1 cnt[x] += 1 print(ret)
1
129,585,725,192,228
null
268
268
s = input() li = list(s) if sum([int(n) for n in li]) % 9 == 0: print("Yes") else: print("No")
# -*- coding: utf-8 s = list(map(str,input().split())) sum = 0 for i in range(len(s)): sum += (int) (s[i]) if sum %9 == 0: print("Yes") else: print("No")
1
4,373,338,481,328
null
87
87
from time import perf_counter t0 = perf_counter() import sys sys.setrecursionlimit(300000) from collections import defaultdict from random import randint def I(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split()) def LMI(): return list(map(int, sys.stdin.readline().split())) def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split())) MOD = 10 ** 9 + 7 INF = float('inf') D = I() C = LMI() S = [LMI() for _ in range(D)] # 初期解の生成 last = defaultdict(int) ans0 = [] for d in range(D): m = -INF ans = -1 for i in range(26): lans = S[d][i] for j in range(26): if i == j: lans -= C[j] * (d + 1 - d - 1) else: lans -= C[j] * (d + 1 - last[j]) if lans > m: m = lans ans = i ans0.append(ans) T = ans0 last = [[i + 1] * 26 for i in range(D)] for d in range(D): i = T[d] j = 0 for dd in range(d, D): last[dd][i] = j j += 1 def eval(d, q): i = T[d] val = S[d][q] - S[d][i] contrib = 0 if d == 0: j = 1 else: j = last[d - 1][i] + 1 for dd in range(d, D): if dd > d and last[dd][i] == 0: break contrib += j - last[dd][i] last[dd][i] = j j += 1 val -= contrib * C[i] contrib = 0 j = 0 for dd in range(d, D): if last[dd][q] == 0: break contrib += last[dd][q] - j last[dd][q] = j j += 1 val += contrib * C[q] T[d] = q return val # TLまで焼きなましで1点更新 i = 0 while perf_counter() - t0 < 1.8: for _ in range(30): d = randint(0, D - 1) q = randint(0, 25) i = T[d] val = eval(d, q) if val < 0: if randint(0, (i + 1) ** 2) == 0: pass else: eval(d, i) i += 1 for t in T: print(t + 1)
n,m,q = [int(_) for _ in input().split()] a = [] b = [] c = [] d = [] for q in range(q): tmplist = [int(_) for _ in input().split()] a.append(tmplist[0]) b.append(tmplist[1]) c.append(tmplist[2]) d.append(tmplist[3]) # Aという数列を再帰関数で求める # {} → {A1, A2, A3...AN} の数 result=[] def score(A): max_score = 0 for i in range(q+1): if A[b[i]-1] - A[a[i]-1] != c[i]: # なぜマイナス1をしているのか?:q continue else: max_score+= d[i] return max_score def dfs(A): if len(A) == n+1: # 配列の個数はN個 return score(A) result = 0 past_data = A[-1] for v in range(past_data,m+1): A.append(v) result = max(result,dfs(A)) A.pop() return result print(dfs([1]))
0
null
18,508,854,171,668
113
160
n, k = map(int, input().split(" ")) p = list(map(int, input().split(" "))) p.sort() ans = sum(p[0:k]) print(ans)
A = list(map(int , input().split())) B = list(map(int , input().split())) print(sum(sorted(B)[:A[1]]))
1
11,516,887,676,960
null
120
120
def main(): s = str(input()) if s == "ABC": print("ARC") else: print("ABC") main()
i = input() if(i=='ABC'): print('ARC') else: print('ABC')
1
24,062,055,971,652
null
153
153
S = input() result = 0 if "R" in S: if "RR" in S: result = S.count("R") else: result = 1 print(result)
s = list(input()) days = 0 if s[1] == "R": days += 1 if s[0] == "R": days += 1 if s[2] == "R": days += 1 else: if s[0] == "R" or s[2] == "R": days = 1 print(days)
1
4,840,273,852,960
null
90
90
import math N,M = map(int,input().split()) ans = N*(N-1)/2 + M*(M-1)/2 print( int(ans) )
n, m = map(int, input().split(' ')) def nCr(n, r): if n < r: return 0 ans = 1 for i in range (r): ans *= (n-r+i+1) ans = ans // (i+1) return ans print(nCr(n, 2) + nCr(m, 2))
1
45,511,264,142,200
null
189
189
def II(): return int(input()) def MI(): return map(int, input().split()) A,B,N=MI() def f(x): return A*x//B-A*(x//B) if B-1<=N: ans=f(B-1) else: ans=f(N) print(ans)
import math a, b, n = map(int, input().split()) if n < b: c = math.floor(a * n / b) print(c) else: c = math.floor(a * (b-1)/ b) print(c)
1
28,096,662,586,986
null
161
161
N, K = map(int, input().split()) mod1 = N % K mod2 = (K - mod1) print(mod1 if mod1 < mod2 else mod2)
N,K = map(int, input().split()) N = N%K while(abs(N-K) < N): N = abs(N-K) print(N)
1
39,486,451,757,570
null
180
180
c = input() alpha = [chr(i) for i in range(97, 97+26)] number = alpha.index(c) print(alpha[number + 1])
temperature = int(input()) if temperature >= 30: print ("Yes") else: print("No")
0
null
48,921,486,326,142
239
95
while True: a, op, b = input().split(" ") a=int(a) b=int(b) if op =="?": break if op =="+": print("{}".format(a + b)) if op =="-": print("{}".format(a - b)) if op =="*": print("{}".format(a * b)) if op =="/": print("{}".format(a // b))
# coding: utf-8 while True: valueA, operation, valueB = input().split(" ") if operation == "?": break elif operation == "+": result = int(valueA) + int(valueB) elif operation == "-": result = int(valueA) - int(valueB) elif operation == "*": result = int(valueA) * int(valueB) elif operation == "/": result = int(valueA) / int(valueB) print("{0}".format(int(result)))
1
671,702,794,980
null
47
47
from collections import defaultdict N,K = map(int,input().split()) A = list(map(int,input().split())) S = [0] for i in range(N): S.append((S[-1]+A[i]-1)%K) D = defaultdict(int) count = 0 for i in range(N+1): count += D[S[i]] D[S[i]] += 1 if i-K+1 >= 0: D[S[i-K+1]] -= 1 print(count)
MOD = 10 ** 9 + 7 INF = 10 ** 10 import sys sys.setrecursionlimit(100000000) dy = (-1,0,1,0) dx = (0,1,0,-1) def main(): n,k = map(int,input().split()) a = list(map(int,input().split())) cum = [0] * (n + 1) dic = {0:1} ans = 0 for i in range(min(n,k - 1)): cum[i + 1] = (cum[i] + a[i])%k tmp = (cum[i + 1] - i - 1)%k if tmp in dic: dic[tmp] += 1 else: dic[tmp] = 1 for v in dic.values(): ans += v * (v - 1)//2 for i in range(max(n - k + 1,0)): dic[(cum[i] - i)%k] -= 1 cum[i + k] = (cum[i + k - 1] + a[i + k - 1])%k tmp = (cum[i + k] - i - k)%k if tmp in dic: ans += dic[tmp] dic[tmp] += 1 else: dic[tmp] = 1 print(ans) if __name__ =='__main__': main()
1
138,149,874,198,322
null
273
273
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(' ')) t1 = h1 * 60 + m1 t2 = h2 * 60 + m2 print(t2 - t1 - k)
1
17,955,069,328,300
null
139
139
from decimal import Decimal T = tuple(map(Decimal, input().split())) A = list(map(Decimal, input().split())) B = list(map(Decimal, input().split())) ans = 0 if A[0] < B[0]: tmp = (A[0], A[1]) A[0], A[1] = B[0], B[1] B[0], B[1] = tmp[0], tmp[1] a = abs(T[0]*A[0] - T[0]*B[0]) b = T[0]*(B[0]-A[0])+T[1]*(B[1]-A[1]) if b == 0: print("infinity") elif b < 0: print(0) exit(0) else: ans += 1 if b > a: print(1) elif b == a: print("infinity") else: if a % b == 0: print((a//b)*2) else: print((a//b)*2 + 1)
n = int(input()) a = [int(x) for x in input().split()] cnt = 0 for a0 in a[::2]: if a0%2 == 1: cnt += 1 print(cnt)
0
null
69,401,605,670,460
269
105
#入力:N,M(int:整数) def input2(): return map(str,input().split()) #入力:[n1,n2,...nk](int:整数配列) def input_array(): return list(map(int,input().split())) s,t=input2() print("{}{}".format(t,s))
A,B=(int(x) for x in input().split()) val = A-B*2 print(max(0,val))
0
null
134,936,814,794,660
248
291
def solve(i, m): if dp[i][m] != -1: return dp[i][m] if m == 0: dp[i][m] = 1 elif i >= n: dp[i][m] = 0 elif solve(i+1, m): dp[i][m] = 1 elif solve(i+1, m-A[i]): dp[i][m] = 1 else: dp[i][m] = 0 return dp[i][m] n = input() A = map(int, raw_input().split()) p = input() m = map(int, raw_input().split()) dp = [[-1 for col in range(2000)] for row in range(n+1)] for i in range(p): if solve(0, m[i]): print 'yes' else: print 'no'
from itertools import combinations n, a, q, ms, cache = int(input()), list(map(int, input().split())), input(), map(int, input().split()), {} l = set(sum(t) for i in range(n) for t in combinations(a, i + 1)) for m in ms: print('yes' if m in l else 'no')
1
97,817,070,300
null
25
25
N = int(input()) A = sorted(map(int, input().split())) X = 0 Y = 0 B = [] for i in range(N-2): X = i + 1 for j in range(X,N-1): Y = j + 1 for k in range(Y, N): if A[k] < A[i] + A[j]: if A[k] != A[i] and A[i] != A[j] and A[k] != A[j]: B.append((A[i],A[j],A[k])) print(len(B))
import itertools n = int(input()) l = list(map(int, input().split( ))) pettern = 0 for v in itertools.combinations(l, 3): if v[0] != v[1] and v[1] != v[2] and v[2] != v[0]: if v[0]+v[1] > v[2] and v[1]+v[2] > v[0] and v[2]+v[0] > v[1]: pettern += 1 print(pettern)
1
5,057,751,552,880
null
91
91
w, h, x, y, r= map(int, raw_input().split()) if (r <= x <= w-r) and (r <= y <= h - r): print 'Yes' else: print 'No'
W,H,x,y,r=map(int,input().split()) print('Yes'if(False if x<r or W-x<r else False if y<r or H-y<r else True)else'No')
1
452,817,693,300
null
41
41
n,x,t = map(int, input().split()) for i in range(1,1001): if n <= x * i: print(t*i) break
# 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)
0
null
8,584,793,984,820
86
124
import math x1, y1, x2, y2 = map(float, raw_input().split()) print round(math.sqrt((x1 - x2)**2 + (y1 - y2)**2), 5 )
import math x1, y1, x2, y2 = map(float, input().split()) print(f'{math.sqrt((x2-x1)**2+(y2-y1)**2):.8f}')
1
158,765,757,030
null
29
29
x = int(input()) a = 0 while True: for b in range(a): if abs(a ** 5 - b ** 5) == abs(x): if a ** 5 - b ** 5 == x: print(a, b) exit() else: print(-a, -b) exit() elif abs(a ** 5 + b ** 5) == abs(x): if a ** 5 + b ** 5 == x: print(a, -b) exit() else: print(-a, b) exit() a += 1
def main(): x, y = map(int, input().split()) money = 0 if x == 3: money += 100000 elif x == 2: money += 200000 elif x == 1: money += 300000 if y == 3: money += 100000 elif y == 2: money += 200000 elif y == 1: money += 300000 if x == 1 and y == 1: money += 400000 print(money) if __name__ == "__main__": main()
0
null
83,201,979,601,050
156
275
def main(): INP = list(map(int, input().split())) list1 = [INP[0],INP[1]] list2 = [INP[2],INP[3]] if INP[0] < 0 and INP[1] > 0: list1.extend([-1,0,1]) if INP[2] < 0 and INP[3] > 0: list2.extend([-1,0,1]) ans = -(10**18) for item in list1: for item2 in list2: ans = max(ans,item*item2) print(ans) if __name__ == '__main__': main()
from collections import Counter MOD = 998244353 N = int(input()) D = list(map(int, input().split())) if D[0] != 0: print(0) exit() C = sorted(Counter(D).most_common(), key=lambda x: x[0]) if C[0][1] > 1: print(0) exit() ans = 1 for i in range(1, len(C)): if C[i][0] - C[i-1][0] > 1: print(0) exit() ans *= C[i - 1][1] ** C[i][1] print(ans % MOD)
0
null
78,717,231,568,910
77
284
def revPoland(expr): stack = [] for l in expr: if l.isdigit(): stack.append(int(l)) # print(stack) else: a = stack.pop() b = stack.pop() c = eval(str(b) + l + str(a)) stack.append(c) # print(stack) return stack.pop() expr = input().split() print(revPoland(expr))
# coding: utf-8 # Your code here! def main(): a, b, c, d = map(int, input().split()) ans = max(a*c, max(b*d, max(a*d, b*c))) print(ans) main()
0
null
1,569,117,863,716
18
77
while True: x,y = map(int, input().split()) if not x and not y: break else: if x > y: print(y,x) else: print(x,y)
a,b = list(map(int,input().split())) print("%d %d %f" % ((a//b),(a%b),float((a/b))))
0
null
564,462,439,210
43
45
a,b,c,d = map(int,input().split()) print('Yes' if (c+b-1)//b <= (a+d-1)//d else 'No')
A, B, C, D = map(int, input().split()) result = False while A > 0 and C > 0: C -= B if C <= 0: result = 'Yes' break A -= D if A <= 0: result = 'No' break print(result)
1
29,879,353,179,236
null
164
164
import itertools while True: n, x = map(int, input().split()) if n == x == 0: break i = 0 l = range(1, n+1) for elem in itertools.combinations(l, 3): if sum(elem) == x: i += 1 print(str(i))
while 1 : n,x=[int(i) for i in input().split()] count=0 if n==x==0: break for i in range(1,n+1): for j in range(i+1,n+1): for k in range(j+1,n+1): if i+j+k==x: count=count+1 print(count)
1
1,306,164,234,528
null
58
58
import sys sys.setrecursionlimit(10**9) INF = 110110110 H, W, K = list(map(int, input().split())) S = [''] * H for i in range(H): S[i] = input() ans = H * W for bit in range(2**(H-1)): cnt = bin(bit).count('1') id = [0] * H for i in range(H-1): if bit>>i & 1: id[i+1] = id[i] + 1 else: id[i+1] = id[i] num = [[0] * W for i in range(id[H-1]+1)] for i in range(H): for j in range(W): if S[i][j] == '1': num[id[i]][j] += 1 for i in range(id[H-1]+1): for j in range(W): if num[i][j] > K: cnt = INF sum = [0] * (id[H-1]+1) for j in range(W): need = False for i in range(id[H-1]+1): if sum[i] + num[i][j] > K: need = True if need: cnt += 1 for i in range(id[H-1]+1): sum[i] = num[i][j] else: for i in range(id[H-1]+1): sum[i] += num[i][j] ans = min(ans, cnt) print(ans)
h,w,k=map(int,input().split()) board=[list(input()) for _ in range(h)] acum=[[0]*w for _ in range(h)] def count(x1,y1,x2,y2): #事前に求めた2次元累積和を用いて左上の点が(x1,y1)、右下の点(x2,y2)の長方形に含まれる1の個数を数える ret=acum[y2][x2] if x1!=0: ret-=acum[y2][x1-1] if y1!=0: ret-=acum[y1-1][x2] if x1!=0 and y1!=0: ret+=acum[y1-1][x1-1] return ret for i in range(h): #2次元累積和により左上の点が(0,0)、右下の点が(j,i)の長方形に含まれる1の個数を数える for j in range(w): if board[i][j] == '1': acum[i][j]+=1 if i!=0: acum[i][j]+=acum[i-1][j] if j!=0: acum[i][j]+=acum[i][j-1] if i!=0 and j!=0: acum[i][j]-=acum[i-1][j-1] ans = 10**18 for i in range(2**(h-1)): cnt = 0 list = [] flag = format(i,'b')[::-1] # '1'と'10'と'100'の区別のために必要 #print(flag) for j in range(len(flag)): if flag[j] == '1': # ''をつける! cnt += 1 list.append(j) list.append(h-1) #print(list) x1 = 0 for x2 in range(w-1): #x1(最初は0)とx1+1の間からx=w-1とx=wの間までの区切り方をそれぞれ確かめる y1 = 0 for y2 in list: #長方形のブロックの右下の点のy座標の候補をすべて試す if count(x1,y1,x2,y2) > k: #ある横の区切り方の下で、どのように縦を区切ってもブロックに含まれる1の個数がKより大きくなるとき、条件を満たす切り分け方は存在しない cnt += 10**18 if count(x1,y1,x2,y2) <= k and count(x1,y1,x2+1,y2) > k: #ある位置でブロックを区切ると1の個数がK以下になるが、区切る位置を1つ進めると1の個数がKより大きくなるとき、その位置で区切る必要がある cnt += 1 x1 = x2+1 #ある位置x2で区切ったとき、次からはx2+1を長方形のブロックの左上の点のx座標として見ればよい break y1 = y2+1 #(いま見ているブロックの右下の点のy座標)+1が次に見るブロックの左上の点のy座標に等しくなる y1 = 0 for y2 in list: if count(x1,y1,w-1,y2) > k: #最後に縦で区切った位置以降で、あるブロックに含まれる1の個数がKより大きくなるとき、条件を満たすような区切り方は存在しない cnt += 10**18 break y1 = y2+1 ans = min(ans,cnt) print(ans)
1
48,398,071,189,380
null
193
193
a,b,c,k = map(int, input().split()) ans = min(a,k) k -= min(a,k) k -= min(b,k) ans -= k print(ans)
a,b,c,k = map(int,input().split()) if k < a: print(k) elif a + b > k: print(a) else: print(a - (k - a - b))
1
21,871,793,616,520
null
148
148
N,A,B = list(map(int,input().split())) if (B-A)%2 == 0: print((B-A)//2) exit() A1 = A B1 = B A2 = A B2 = B count1 = N-B1 ans1 = 0 A1 += (N-B1) B1 = N if (B1-A1)%2 == 0: ans1 = count1+(B1-A1)//2 else: ans1 = count1+1+(B1-A1)//2 count2 = A2-1 ans2 = 0 B2 -= (A2-1) A2 = 1 if (B2-A2)%2 == 0: ans2 = count2+(B2-A2)//2 else: ans2 = count2+1+(B2-A2)//2 print(min(ans1,ans2))
#!/usr/bin python3 # -*- coding: utf-8 -*- import sys input = sys.stdin.readline def main(): N, A, B = map(int, input().split()) if abs(A-B)%2==0: ret = abs(A-B)//2 else: A, B = min(A, B), max(A, B) ret = min(B-(B-A+1)//2, N-(B-A-1)//2-A) print(ret) if __name__ == '__main__': main()
1
108,910,093,286,808
null
253
253
def getN(): return int(input()) def getNM(): return map(int, input().split()) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(input()) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() def rand_N(ran1, ran2): return random.randint(ran1, ran2) def rand_List(ran1, ran2, rantime): return [random.randint(ran1, ran2) for i in range(rantime)] def rand_ints_nodup(ran1, ran2, rantime): ns = [] while len(ns) < rantime: n = random.randint(ran1, ran2) if not n in ns: ns.append(n) return sorted(ns) def rand_query(ran1, ran2, rantime): r_query = [] while len(r_query) < rantime: n_q = rand_ints_nodup(ran1, ran2, 2) if not n_q in r_query: r_query.append(n_q) return sorted(r_query) from collections import defaultdict, deque, Counter from sys import exit from decimal import * import heapq import math from fractions import gcd import random import string import copy from itertools import combinations, permutations, product from operator import mul from functools import reduce from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) mod = 10 ** 9 + 7 ############# # Main Code # ############# N, X, Y = getNM() dist = [[] for i in range(N)] for i in range(N - 1): dist[i].append(i + 1) dist[i + 1].append(i) dist[X - 1].append(Y - 1) dist[Y - 1].append(X - 1) distance = [0] * N def counter(sta): ignore = [0] * N ignore[sta] = 1 pos = deque([[sta, 0]]) while len(pos) > 0: u, dis = pos.popleft() for i in dist[u]: if ignore[i] == 0: ignore[i] = 1 distance[dis + 1] += 1 pos.append([i, dis + 1]) for i in range(N): counter(i) for i in distance[1:]: print(i // 2)
N, X, Y = [int(x) for x in input().split()] counter = [0] * N for i in range(1, N + 1): for j in range(i + 1, N + 1): d = min(abs(i - j), abs(i - X) + abs(j - Y) + 1, abs(i - Y) + abs(j - X) + 1) counter[d] += 1 for i in range(1, N): print(counter[i])
1
44,085,852,876,338
null
187
187
import bisect import collections import functools import heapq import math from collections import deque from collections import defaultdict MOD = 10**9+7 N = int(input()) A = [0]*N B = [0]*N C = [[0]*2 for _ in range(N)] zero = 0 no_inf = 0 inf = 0 for i in range(N): A[i],B[i] = map(int,(input().split())) if A[i] == 0 and B[i] == 0: C[i] = (0,0) zero += 1 elif A[i] == 0: C[i] = (0,0) no_inf += 1 elif B[i] == 0: C[i] = (0,0) inf += 1 elif B[i] > 0: g = math.gcd(A[i],B[i]) C[i] = (A[i]//g,B[i]//g) else: g = math.gcd(A[i],B[i]) C[i] = (-A[i]//g,-B[i]//g) d = defaultdict(int) for i in range(N): if C[i] != (0,0): d[C[i]] += 1 ans = 1 for k in d.keys(): if k[0] > 0: if (-k[1],k[0]) in d: ans *= pow(2,d[k],MOD) + pow(2,d[(-k[1],k[0])],MOD) -1 d[k],d[(-k[1],k[0])] = 0,0 else: ans *= pow(2,d[k],MOD) else: if (k[1],-k[0]) in d: ans *= pow(2,d[k],MOD) + pow(2,d[(k[1],-k[0])],MOD) -1 d[k],d[(k[1],-k[0])] = 0,0 else: ans *= pow(2,d[k],MOD) ans *= pow(2,no_inf,MOD) + pow(2,inf,MOD) -1 print((ans+zero-1)%MOD)
# Contest No.: ABC168 # Problem No.: E # Solver: JEMINI # Date: 20200517 import sys import heapq def gcd(a, b): if a < b: a, b = b, a if b == 0: return a return gcd(b, a % b) def main(): modVal = 1000000007 n = int(input()) ppList = [] pnList = [] npList = [] nnList = [] znList = [] nzList = [] pzList = [] zpList = [] zzList = [] numList = [0] * n for _ in range(n): a, b = map(int, sys.stdin.readline().split()) if a > 0 and b > 0: ppList.append((a, b)) elif a > 0 and b < 0: pnList.append((a, b)) elif a < 0 and b > 0: npList.append((a, b)) elif a < 0 and b < 0: nnList.append((a, b)) elif a == 0 and b < 0: znList.append((a, b)) elif a < 0 and b == 0: nzList.append((a, b)) elif a == 0 and b > 0: zpList.append((a, b)) elif a > 0 and b == 0: pzList.append((a, b)) else: zzList.append((a, b)) ans = 1 # zp, zn, pz, nz zAns = 2 ** (len(zpList) + len(znList)) % modVal + 2 ** (len(pzList) + len(nzList)) % modVal - 1 zAns = zAns % modVal ans = zAns # pp, pn, np, nn ratioDict = {} for i in ppList: gcdVal = gcd(i[0], i[1]) ratio = (i[0] // gcdVal, i[1] // gcdVal) if ratio not in ratioDict: ratioDict[ratio] = [1, 0] else: ratioDict[ratio][0] += 1 for i in nnList: gcdVal = gcd(-i[0], -i[1]) ratio = (-i[0] // gcdVal, -i[1] // gcdVal) if ratio not in ratioDict: ratioDict[ratio] = [1, 0] else: ratioDict[ratio][0] += 1 for i in npList: gcdVal = gcd(abs(i[0]), abs(i[1])) ratio = (abs(i[1]) // gcdVal, abs(i[0]) // gcdVal) if ratio not in ratioDict: ratioDict[ratio] = [0, 1] else: ratioDict[ratio][1] += 1 for i in pnList: gcdVal = gcd(abs(i[0]), abs(i[1])) ratio = (abs(i[1]) // gcdVal, abs(i[0]) // gcdVal) if ratio not in ratioDict: ratioDict[ratio] = [0, 1] else: ratioDict[ratio][1] += 1 for i in ratioDict: temp = 2 ** ratioDict[i][0] % modVal temp += (2 ** ratioDict[i][1] - 1) % modVal ans *= temp ans = ans % modVal ans -= 1 ans += len(zzList) ans = ans % modVal print(ans) return if __name__ == "__main__": main()
1
20,993,971,267,302
null
146
146
#C - Average Length import math import itertools N = int(input()) town = [] for i in range(N): x,y = map(int,input().split()) town.append((x,y)) def dist(A,B): return math.sqrt((A[0]-B[0])**2 + (A[1]-B[1])**2) route = list(itertools.permutations(town)) tot = 0 for i in route: for j in range(len(i)-1): tot += dist(i[j],i[j+1]) ave = tot/len(route) print(ave)
from collections import deque H,W=map(int,input().split()) S=[] for i in range(H): S.append(input()) def bfs(s): seen = [[0 for i in range(W)] for j in range(H)] total = [[0 for i in range(W)] for j in range(H)] todo = deque([]) now = s if S[now[0]][now[1]]=='#':return 0 seen[now[0]][now[1]],total[now[0]][now[1]] = 1,0 todo.append(now) while 1: if len(todo)==0:break now = todo.popleft() for d in [(1,0),(-1,0),(0,1),(0,-1)]: new = (now[0]+d[0], now[1]+d[1]) if new[0]<0 or new[0]>=H:continue if new[1]<0 or new[1]>=W:continue if seen[new[0]][new[1]]==1:continue if S[new[0]][new[1]]=='#':continue seen[new[0]][new[1]] = 1 todo.append(new) total[new[0]][new[1]] = total[now[0]][now[1]] + 1 return max(map(max, total)) MAX=0 for i in range(H): for j in range(W): s = (i,j) max_ = bfs(s) if MAX < max_:MAX=max_ print(MAX)
0
null
121,452,140,634,942
280
241
num = list(map(int,input().split())) print("%d %d" % (num[0]*num[1],(num[0]+num[1])*2))
p = input().split() a = int(p[0]) b = int(p[1]) print(a*b, 2*(a+b))
1
296,587,252,738
null
36
36
# -*- coding: utf-8 -*- import sys from collections import deque, defaultdict from math import sqrt, factorial, gcd, ceil # def input(): return sys.stdin.readline()[:-1] # warning not \n # def input(): return sys.stdin.buffer.readline().strip() # warning bytes # def input(): return sys.stdin.buffer.readline().decode('utf-8') import string # string.ascii_lowercase from bisect import bisect_left def solve(): n = int(input()) l = [int(x) for x in input().split()] l.sort() ans = 0 for i in range(n): for j in range(i + 1, n): r = bisect_left(l, l[i] + l[j]) if r > j: ans += r - j - 1 print(ans) t = 1 # t = int(input()) for case in range(1,t+1): ans = solve() """ azyxwvutsrqponmlkjihgfedcb """
# coding: utf-8 import sys import numpy as np sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) MOD = 10 ** 9 + 7 # K回の移動が終わった後、人がいる部屋の数はNからN-K def cmb(n, k): if k < 0 or k > n: return 0 return fact[n] * fact_inv[k] % MOD * fact_inv[n-k] % MOD def cumprod(arr, MOD): L = len(arr); Lsq = int(L**.5+1) arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq) for n in range(1, Lsq): arr[:, n] *= arr[:, n-1]; arr[:, n] %= MOD for n in range(1, Lsq): arr[n] *= arr[n-1, -1]; arr[n] %= MOD return arr.ravel()[:L] def make_fact(U, MOD): x = np.arange(U, dtype=np.int64); x[0] = 1 fact = cumprod(x, MOD) x = np.arange(U, 0, -1, dtype=np.int64); x[0] = pow(int(fact[-1]), MOD-2, MOD) fact_inv = cumprod(x, MOD)[::-1] return fact, fact_inv U = 10 ** 6 # 階乗テーブルの上限 fact, fact_inv = make_fact(U, MOD) N, K = lr() answer = 0 for x in range(N, max(0, N-K-1), -1): # x個の家には1人以上いるのでこの人たちは除く can_move = N - x # x-1の壁をcan_move+1の場所に入れる answer += cmb(N, x) * cmb(x - 1 + can_move, can_move) answer %= MOD print(answer % MOD) # 31
0
null
119,735,130,562,672
294
215
import numpy as np from functools import * import sys sys.setrecursionlimit(100000) input = sys.stdin.readline def acinput(): return list(map(int, input().split(" "))) def II(): return int(input()) directions=np.array([[1,0],[0,1],[-1,0],[0,-1]]) directions = list(map(np.array, directions)) mod = 10**9+7 def factorial(n): fact = 1 for integer in range(1, n + 1): fact *= integer return fact def serch(x, count): #print("top", x, count) for d in directions: nx = d+x #print(nx) if np.all(0 <= nx) and np.all(nx < (H, W)): if field[nx[0]][nx[1]] == "E": count += 1 field[nx[0]][nx[1]] = "V" count = serch(nx, count) continue if field[nx[0]][nx[1]] == "#": field[nx[0]][nx[1]] = "V" count = serch(nx, count) return count K=int(input()) s = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51] print(s[K-1])
#coding:utf-8 #1_1_D n = int(input()) prices = [int(input()) for x in range(n)] maxv = -2 * 10 ** 9 minv = prices[0] for i in range(1, n): maxv = max(maxv, prices[i] - minv) minv = min(minv, prices[i]) print(maxv)
0
null
25,101,812,783,520
195
13
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 # (string,3) 3回 from collections import deque from collections import defaultdict import bisect # # d = m - k[i] - k[j] # if kk[bisect.bisect_right(kk,d) - 1] == d: # # # # pythonで無理なときは、pypyでやると正解するかも!! # # import sys sys.setrecursionlimit(10000000) mod = 10**9 + 7 def readInts(): return list(map(int,input().split())) def main(): a,b = readInts() print(a - b*2 if a - b*2 >= 0 else 0) if __name__ == '__main__': main()
numline=input().split(" ") a=int(numline[0]) b=int(numline[1]) numline=input().split(" ") numlis=[] for i in range(a): numlis.append(int(numline[i])) numlis.sort() result=0 for i in range(b): result+=numlis[i] print(result)
0
null
88,809,567,816,520
291
120
S = input().rstrip() + "#" s0 = S[0] A, cnt = [], 1 for s in S[1:]: if s==s0: cnt+=1 else: A.append(cnt); cnt=1 s0 = s res, st = 0, 0 if S[0]==">": res += A[0]*(A[0]+1)//2 st=1 for i in range(st,len(A),2): if i+1==len(A): res += A[i]*(A[i]+1)//2; break p, q = A[i], A[i+1] if p < q: res += q*(q+1)//2 + p*(p-1)//2 else: res += q*(q-1)//2 + p*(p+1)//2 print(res)
m1 = input().split()[0] m2 = input().split()[0] print(int(m1 != m2))
0
null
140,293,518,885,060
285
264
data=str(input("")).split(" ") D=int(data[0]) T=int(data[1]) S=int(data[2]) if D<=T*S: print("Yes") else: print("No")
import sys try: #d = int(input('D: ')) #t = int(input('T: ')) #s = int(input('S: ')) nums = [int(e) for e in input().split()] except ValueError: print('エラー:整数以外を入力しないでください') sys.exit(1) if 1 <= nums[0] <= 10000 and 1 <= nums[1] <= 10000 and 1 <= nums[2] <= 10000: take_time = nums[0] / nums[2] if take_time <= nums[1]: print("Yes") else: print("No") else: print('エラー:各入力は1~10000までの整数です')
1
3,513,338,303,520
null
81
81
n=int(input()) a=[0]*10001 for i in range(1,101): for j in range(1,101): for k in range(1,101): v=i**2+j**2+k**2+i*j+j*k+k*i if v<10001: a[v]+=1 for m in range(n): print(a[m+1])
from sys import stdin input = lambda: stdin.readline().rstrip() na, nb, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) min_a = min_b = 10**9 for i in range(na): min_a = min(min_a, a[i]) for i in range(nb): min_b = min(min_b, b[i]) ans = min_a + min_b for i in range(m): x, y, c = map(int, input().split()) x -= 1 y -= 1 ans = min(ans, a[x] + b[y] - c) print(ans)
0
null
31,133,980,140,278
106
200
n,m = map(int,input().split()) a = list(map(int,input().split())) b = sum(a)/(4*m) cnt = 0 for i in a: if b <= i: cnt += 1 if cnt >= m: print("Yes") exit() print("No")
def sub(strings, listseq): for index in listseq: strings = strings[index:] + strings[:index] return strings def main(): while True: strings = input() if strings == "-": break times = int(input()) list1 = [int(input()) for i in range(times)] print(sub(strings, list1)) main()
0
null
20,310,091,817,120
179
66
input() while True: try: lst = list(map(int,input().split())) lst.sort() if lst[2] ** 2 == lst[1] ** 2 + lst[0] ** 2: print("YES") else: print("NO") except EOFError: break
N = int(input()) for i in range(N): a, b, c = map(int, input().split()) sort = sorted([a, b, c]) if sort[0]**2 + sort[1]**2 == sort[2]**2: print("YES") else: print("NO")
1
225,369,732
null
4
4
X=int(input()) A=[] i,p=0,True while p: a=i**5 A.append(a) for b in A: if a-b==X: p=False print(i,A.index(b)) break elif a+b==X: p=False print(i,-1*A.index(b)) break i+=1
N, K = map(int, input().split()) H = list(map(int, input().split())) if N <= K: print(0) exit() H.sort(reverse=True) print(sum(H[K:]))
0
null
52,220,710,725,340
156
227
import sys def main(): N, K = map(int, sys.stdin.readline().rstrip().split()) L = [0] * 10 R = [0] * 10 for i in range(K): l, r = map(int, sys.stdin.readline().rstrip().split()) L[i], R[i] = l, r dp = [0] * (N + 1) up = [0] * (N + 1) up[0] = 1 up[1] = -1 for i in range(1, N + 1): dp[i] = dp[i - 1] + up[i - 1] for j in range(K): if i + (L[j] - 1) < N + 1: up[i + (L[j] - 1)] += dp[i] if i + R[j] < N + 1: up[i + R[j]] -= dp[i] dp[i] %= 998244353 print(dp[N]) main()
import sys input = sys.stdin.readline N, K = map(int, input().split()) MOD = 998244353 P = [tuple(map(int, input().split())) for _ in range(K)] E = [0] * N def update(i, v): while i < N: E[i] = (E[i] + v) % MOD i |= i+1 def query(i): r = 0 while i > 0: r += E[i-1] i &= i-1 return r % MOD update(0, 1) update(1, -1) for i in range(N-1): v = query(i+1) for L, R in P: if i + L < N: update(i+L, v) if i + R + 1 < N: update(i+R+1, -v) print(query(N))
1
2,686,030,232,732
null
74
74
import copy def bit_list(x: int, n: int) -> list: ''' xのn乗のbit配列を返す ''' ans = [] for i in range(x ** n): num = i j = 0 table = [0 for _ in range(n)] while num: table[j] = num % x num = num // x j += 1 ans.append(table) return ans H, W, K = map(int, input().split()) M = [list(input()) for _ in range(H)] ans = 0 bits = bit_list(2, H + W) for bit in bits: tmp_M = copy.deepcopy(M) for i in range(H + W): if i < H and bit[i] == 1: for j in range(W): tmp_M[i][j] = "R" if i >= H and bit[i] == 1: for j in range(H): tmp_M[j][i - H] = "R" count = 0 for i in range(H): for j in range(W): if tmp_M[i][j] == '#': count += 1 if count == K: ans += 1 print(ans)
# S の長さが K 以下であれば、S をそのまま出力してください。 # S の長さが K を上回っているならば、 # 先頭 K 文字だけを切り出し、末尾に ... を付加して出力してください。 # K は 1 以上 100 以下の整数 # S は英小文字からなる文字列 # S の長さは 1 以上 100 以下 K = int(input()) S = str(input()) if K >= len(S): print(S) else: print((S[0:K] + '...'))
0
null
14,336,219,883,492
110
143
N=int(input()) Ai=list(map(int,input().split())) # ans=[] ans=[0]*N # for i in range(1,N+1): # a=Ai.index(i)+1 # ans.append(str(a)) for i in range (N): ans[Ai[i]-1]=str(i+1) print(' '.join(ans))
n=int(input()) arr=list(map(int,input().strip().split())) ans=[0]*n for i in range(n): ans[arr[i]-1]=i+1 print(*ans,sep=" ")
1
180,234,520,300,980
null
299
299
N = int(input()) D = list(map(int, input().split())) mod = 998244353 from collections import Counter, deque def solve(N,D): if D[0]!=0: return 0 c = Counter(D) if c[0]>1: return 0 ans = 1 m = max(D) for i in range(1,m): if c[i]==0: ans = 0 continue ans *= pow(c[i],c[i+1],mod) ans %= mod return ans print(solve(N,D))
from collections import Counter def solve(): N = int(input()) D = list(map(int, input().split())) mod = 998244353 if D[0] != 0: print(0) return cnt = Counter(D) if cnt[0] > 1: print(0) return res = 1 for i in range(1, max(D)+1): if cnt[i-1] == 1: continue res *= cnt[i-1]**cnt[i] %mod res %= mod print(res) solve()
1
154,590,333,880,070
null
284
284
import collections N,*S = open(0).read().split() C = collections.Counter(S) i = C.most_common()[0][1] print(*sorted([k for k,v in C.most_common() if v == i]), sep='\n')
import math import statistics import collections a=int(input()) #b,c=int(input()),int(input()) # c=[] # for i in b: # c.append(i) #e1,e2 = map(int,input().split()) # f = list(map(int,input().split())) g = [input() for _ in range(a)] # h = [] # for i in range(e1): # h.append(list(map(int,input().split()))) g.sort() ma=0 count=1 #最大値求める for i in range(a-1): if g[i]==g[i+1]: count+=1 else: ma=max(ma,count) count=1 ma=max(ma,count) count=1 ans=[] #最大値の位置 for i in range(a-1): if g[i]==g[i+1]: count+=1 else: if count==ma: ans.append(g[i]) count=1 if count==ma: ans.append(g[-1]) for i in ans: print(i)
1
70,105,297,187,958
null
218
218
from math import pi r = float(input()) z = r*r*pi l = 2*r*pi print('{} {}'.format(z,l))
n, m = map(int, input().split()) a = sorted(map(int, input().split()), reverse = True) total = sum(a) cnt = 0 for i in a: if i * 4 * m >= total: cnt += 1 else: break if cnt >= m: print("Yes") else: print("No")
0
null
19,745,591,912,420
46
179
import sys readline = sys.stdin.readline MOD = 10**9+7 def frac(limit): frac = [1]*limit for i in range(2,limit): frac[i] = i * frac[i-1]%MOD fraci = [None]*limit fraci[-1] = pow(frac[-1], MOD -2, MOD) for i in range(-2, -limit-1, -1): fraci[i] = fraci[i+1] * (limit + i + 1) % MOD return frac, fraci frac, fraci = frac(2341398) def cmb(a, b): if not a >= b >= 0: return 0 return frac[a]*fraci[b]*fraci[a-b]%MOD K, = map(int, input().split()) t = len(input().strip()) R = 0 for x in range(K+1): R += cmb(K+t-x-1, t-1)*pow(25, K-x, MOD)*pow(26, x, MOD)%MOD R %= MOD print(R)
MOD = 10 ** 9 + 7 fact = [1, 1] factinv = [1, 1] inv = [0, 1] def init(n): for i in range(2, n + 1): fact.append((fact[-1] * i) % MOD) inv.append((-inv[MOD % i] * (MOD // i)) % MOD) factinv.append((factinv[-1] * inv[-1]) % MOD) def nPk(n, k): return fact[n] * factinv[n - k] % MOD def nCk(n, k): return fact[n] * factinv[n - k] * factinv[k] % MOD K = int(input()) N = len(input()) init(N + K) p25 = [1] p26 = [1] for k in range(K): p25.append(p25[-1] * 25 % MOD) p26.append(p26[-1] * 26 % MOD) ans = 0 for m in range(K + 1): n = N + K ans += p25[K - m] * p26[m] * nCk(n - 1 - m, N - 1) % MOD print(ans % MOD)
1
12,796,403,958,092
null
124
124
K,N=map(int,input().split()) A=list(map(int,input().split())) B=[K-A[N-1]+A[0]] for x in range(N-1): B.append(A[x+1]-A[x]) ans=sum(B)-max(B) print(ans)
S = input() N = len(S) S1 = S[:(N - 1) // 2] S2 = S[(N + 3) // 2 - 1:] def check(s): #print(s) i = 0 j = len(s) - 1 while j > i: if s[j] != s[i]: return False j -= 1 i += 1 return True if check(S) and check(S1) and check(S2): print("Yes") else: print("No")
0
null
44,838,122,645,794
186
190
n = int(input()) x = list(map(int,input().split())) ans = 10 ** 12 for i in range(1,101): p = 0 for j in x: p += (j - i) ** 2 ans = min(ans,p) print(ans)
N = int(input()) X = list(map(int, input().split())) def cost(p): res = 0 for x in X: res += (x - p)**2 return res m = sum(X) // N print(min(cost(m), cost(m+1)))
1
64,932,729,095,560
null
213
213
# coding: utf-8 import sys sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) X, Y, A, B, C = lr() P = lr(); P.sort(reverse=True) Q = lr(); Q.sort(reverse=True) R = lr(); R.sort(reverse=True) P = P[:X] Q = Q[:Y] Z = P + Q + R Z.sort(reverse=True) answer = sum(Z[:X+Y]) print(answer)
x,y,a,b,c=map(int,input().split()) R=sorted(map(int,input().split()),reverse=True) G=sorted(map(int,input().split()),reverse=True) N=sorted(map(int,input().split()),reverse=True) L=sorted(R[:x]+G[:y]+N[:(x+y)],reverse=True) print(sum(L[:(x+y)]))
1
44,896,937,936,642
null
188
188
x = list(map(int, input().split())) d = list(input()) for i in d: if i == 'S': t=x[1] x[1]=x[0] x[0]=x[4] x[4]=x[5] x[5]=t elif i == 'N': t=x[1] x[1]=x[5] x[5]=x[4] x[4]=x[0] x[0]=t elif i == 'E': t=x[2] x[2]=x[0] x[0]=x[3] x[3]=x[5] x[5]=t elif i == 'W': t=x[2] x[2]=x[5] x[5]=x[3] x[3]=x[0] x[0]=t print(x[0])
''' 参考 https://drken1215.hatenablog.com/entry/2020/06/21/224900 ''' N = int(input()) A = list(map(int, input().split())) INF = 10 ** 5 cnt = [0] * (INF+1) Q = int(input()) BC = [] for _ in range(Q): BC.append(list(map(int, input().split()))) for a in A: cnt[a] += 1 total = sum(A) for b, c in BC: total += (c-b) * cnt[b] cnt[c] += cnt[b] cnt[b] = 0 print(total)
0
null
6,195,464,348,430
33
122
print(sum(s!=t for s,t in zip(*open(0))))
N,K=map(int,input().split()) p_N = [int(i) for i in input().split()] import heapq print(sum(heapq.nsmallest(K,p_N)))
0
null
10,975,938,964,030
116
120
x , y = map(int , input().split()); ans = 0; if(x == 1): ans += 300000; if(x == 2): ans += 200000; if(x == 3): ans += 100000; if(y == 1): ans += 300000; if(y == 2): ans += 200000; if(y == 3): ans += 100000; if(x + y == 2): ans += 400000; print(ans)
n=2 while n>0 : n=n-1 a=map(int,raw_input().split()) else: print min(a),max(a),sum(a)
0
null
70,695,662,262,654
275
48
import sys import bisect import itertools import collections import fractions import heapq import math from operator import mul from functools import reduce from functools import lru_cache def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 N = int(input()) A = list(map(int, input().split())) def get_primenumber(number): # エラトステネスの篩 prime_list = [] search_list = list(range(2, number + 1)) # search_listの先頭の値が√nの値を超えたら終了 while search_list[0] <= math.sqrt(number): # search_listの先頭の値が√nの値を超えたら終了 # search_listの先頭をprime_listに入れて、先頭をリストに追加して削除 head_num = search_list.pop(0) prime_list.append(head_num) # head_numの倍数を除去 search_list = [num for num in search_list if num % head_num != 0] # prime_listにsearch_listを結合 prime_list.extend(search_list) return prime_list def prime_factor_table(n): table = [0] * (n + 1) for i in range(2, n + 1): if table[i] == 0: for j in range(i + i, n + 1, i): table[j] = i return table def prime_factor(n, prime_factor_table): prime_count = collections.Counter() while prime_factor_table[n] != 0: prime_count[prime_factor_table[n]] += 1 n //= prime_factor_table[n] prime_count[n] += 1 return prime_count table = prime_factor_table(10**6+10) numset = set() for i in A: thedic = prime_factor(i, table) for l in thedic.keys(): flag = True if l in numset and l != 1: flag = False break if flag: tmpset = set(thedic.keys()) numset |= tmpset else: break if flag: print('pairwise coprime') sys.exit() else: flag = True theset = set(prime_factor(A[0], table).keys()) for i in A[1:]: thedic = prime_factor(i, table) theset = theset & set(thedic.keys()) if len(theset) == 0: print('setwise coprime') flag = False break if flag: print('not coprime') if __name__ == '__main__': solve()
import sys from math import gcd def input(): return sys.stdin.readline().strip() def main(): N = int(input()) A =list(map(int, input().split())) all_gcd = A[0] max_num = A[0] for a in A: all_gcd = gcd(all_gcd, a) max_num = max(max_num, a) if all_gcd != 1: print("not coprime") return # エラトステネスの篩でmin_prime[i] = (iを割り切る最小の素数)を記録する min_prime = [i for i in range(max_num + 1)] for p in range(2, int(max_num**0.5) + 1): if min_prime[p] != p: continue for i in range(2 * p, max_num + 1, p): min_prime[i] = p # Aの要素で出てきた素因数をusedに記録 used = [0] * (max_num + 1) for a in A: while a > 1: p = min_prime[a] if used[p]: print("setwise coprime") return while a % p == 0: a //= p used[p] = 1 print("pairwise coprime") if __name__ == "__main__": main()
1
4,109,920,097,620
null
85
85
str=input() if str.endswith("s"): print(str+"es") else: print(str+"s")
a=input() b=list(a) if b[-1]=="s": print(a+"es") else: print(a+"s")
1
2,400,621,489,240
null
71
71
import sys input = sys.stdin.readline N, K = map(int, input().split()) MOD = 998244353 P = [tuple(map(int, input().split())) for _ in range(K)] E = [0] * N def update(i, v): while i < N: E[i] = (E[i] + v) % MOD i |= i+1 def query(i): r = 0 while i > 0: r += E[i-1] i &= i-1 return r % MOD update(0, 1) update(1, -1) for i in range(N-1): v = query(i+1) for L, R in P: if i + L < N: update(i+L, v) if i + R + 1 < N: update(i+R+1, -v) print(query(N))
# coding=utf-8 from math import floor, ceil, sqrt, factorial, log, gcd from itertools import accumulate, permutations, combinations, product, combinations_with_replacement from bisect import bisect_left, bisect_right from collections import Counter, defaultdict, deque from heapq import heappop, heappush, heappushpop, heapify import copy import sys INF = float('inf') mod = 10**9+7 sys.setrecursionlimit(10 ** 6) def lcm(a, b): return a * b / gcd(a, b) # 1 2 3 # a, b, c = LI() def LI(): return list(map(int, sys.stdin.buffer.readline().split())) # a = I() def I(): return int(sys.stdin.buffer.readline()) # abc def # a, b = LS() def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() # a = S() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') # 2 # 1 # 2 # [1, 2] def IR(n): return [I() for i in range(n)] # 2 # 1 2 3 # 4 5 6 # [[1,2,3], [4,5,6]] def LIR(n): return [LI() for i in range(n)] # 2 # abc # def # [abc, def] def SR(n): return [S() for i in range(n)] # 2 # abc def # ghi jkl # [[abc,def], [ghi,jkl]] def LSR(n): return [LS() for i in range(n)] # 2 # abcd # efgh # [[a,b,c,d], [e,f,g,h]] def SRL(n): return [list(S()) for i in range(n)] # n, k = LI() # s = set() # for i in range(k): # l, r = LI() # s |= set(range(l, r + 1)) # # a = len(s) # dp = [0] * (n + 1) # dp[1] = 1 # for i in range(1, n+1): # for j in range(1, i): # if i-j in s: # dp[i] += dp[j] % 998244353 # # dp[i] += dp[j] # print(dp[n] % 998244353) # 配るDP n, k = map(int, input().split()) lr = [] for _ in range(k): l, r = map(int, input().split()) lr.append((l, r)) mod = 998244353 dp = [0]*(2*n+1) dp[0] = 1 dp[1] = -1 now = 1 for i in range(n-1): for l, r in lr: # 始点に足して終点は引く # imos法というらしい dp[i+l] += now dp[i+r+1] -= now now += dp[i+1] now %= mod print(now)
1
2,701,052,935,230
null
74
74
# ALDS1_3_C: Doubly Linked List # collections.deque # https://docs.python.org/3.8/library/collections.html#collections.deque #n = 7 #A = [('insert', 5), ('insert', 2), ('insert', 3), ('insert', 1), # ('delete', 3), ('insert', 6), ('delete', 5),] from collections import deque n = int(input()) mylist = deque() for i in range(n): myinput = input().split() if len(myinput) == 1: order = myinput[0] x = 0 else: order, x = myinput #print(order, x) if order == 'insert': mylist.appendleft(x) elif order == 'delete': try: mylist.remove(x) except: pass elif order == 'deleteFirst': #mylist.remove(mylist[0]) mylist.popleft() elif order == 'deleteLast': mylist.pop() #print(mylist) print(" ".join(map(str, mylist)))
from collections import deque d = deque() for _ in range(int(input())): a = input() if "i" == a[0]: d.appendleft(int(a[7:])) elif "F" == a[6]: d.popleft() elif "L" == a[6]: d.pop() else: try: d.remove(int(a[7:])) except: pass print(*d)
1
52,906,671,632
null
20
20
N,A,B = map(int,input().split()) p = N // (A+B) q = N % (A+B) if q > A: r = A else: r = q print(A * p + r)
n,a,b = map(int,input().split()) A=n//(a+b) B=n%(a+b) ans = a * A if B>=a: ans += a else: ans += B print(ans)
1
55,344,823,433,788
null
202
202
n=int(input()) s=input() score = 0 for p in range(1000): pw = str(p).zfill(3) start = 0 n_match = 0 for j in range(3): for i in range(start, len(s)): if s[i] == pw[j]: start = i+1 n_match = n_match+1 if j == 3-1: # print(pw) score = score+1 break if n_match <= j: break print(score)
h,*s=open(0) h,w,k,*m=map(int,h.split()) b=w while b: b-=1;r=0;t=j=w;d=[0]*h while j: i=c=0;j-=1 while h-i: d[c]+=s[i][j]>'0';c+=b>>i&1;i+=1 if max(d)>k:d=[0]*h;r+=1;t,j=j,j+(t>j);i=h m+=r+c, print(min(m))
0
null
88,346,134,207,070
267
193
import itertools,math N = int(input()) x = [0] * N y = [0] * N for i in range(N): x[i], y[i] = map(int, input().split()) seq=[] for i in range(N): seq.append(i) l=list(itertools.permutations(seq)) num=0 for i in l: for u in range(1,len(i)): num+=math.sqrt((x[i[u-1]]-x[i[u]])**2+(y[i[u-1]]-y[i[u]])**2) print(num/len(l))
import itertools, math N = int(input()) ls, L = [], 0 for i in range(N): x, y = map(int, input().split(' ')) ls.append([x, y]) perms = itertools.permutations(range(N)) for perm in perms: for i in range(N - 1): L += math.sqrt((ls[perm[i + 1]][0] - ls[perm[i]][0]) ** 2 + (ls[perm[i + 1]][1] - ls[perm[i]][1]) ** 2) print(L / math.factorial(N))
1
147,795,303,589,752
null
280
280
n = int(input()) a=1 x=0 for i in range(n-1): x += (n-1)//a a += 1 print(x)
N = int(input()) cnt = 0 for a in range(1,N+1): b = N // a if a * b == N: cnt = cnt + b - 1 else: cnt = cnt + b print(cnt)
1
2,585,322,441,852
null
73
73
n = int(input()) _s = input() q = int(input()) query = [input() for _ in range(q)] def bitsum(_bit, i): s = 0 while i > 0: s += _bit[i] i -= i & (-i) return s def bitadd(_bit, i, x): while i <= n: _bit[i] += x i += i & (-i) return _bit al = [chr(ord('a') + i) for i in range(26)] al_to_idx = dict() for i in range(26): al_to_idx[al[i]] = i s = list(_s) # init import math n_ = int(math.log(n) / math.log(2)) + 1 bit = [[0] * (2 ** n_ + 1) for _ in range(26)] for i in range(n): idx = al_to_idx[s[i]] bit[idx] = bitadd(bit[idx], i + 1, 1) # print(bit) for i in range(q): _query = query[i].split(' ') if _query[0] == '1': # decrement old idx = al_to_idx[s[int(_query[1]) - 1]] bit[idx] = bitadd(bit[idx], int(_query[1]), -1) s[int(_query[1]) - 1] = _query[2] # print(s) # increment idx = al_to_idx[_query[2]] bit[idx] = bitadd(bit[idx], int(_query[1]), 1) else: _ans = 0 for idx in range(26): _bit = bit[idx] c = bitsum(_bit, int(_query[2])) - bitsum(_bit, int(_query[1]) - 1) if c != 0: _ans += 1 print(_ans)
n=int(input())+1 data=[0]*n*2 def update(i,x): i+=n data[i]=x i//=2 while i: data[i]=data[i*2]|data[i*2+1] i//=2 def query(l,r): l+=n r+=n s=0 while l<r: if l&1: s|=data[l] l+=1 if r&1: r-=1 s|=data[r] l//=2 r//=2 return sum(map(int,bin(s)[2:])) s=input() for i,c in enumerate(s,n): data[i]=1<<(ord(c)-97) for i in range(n-1,0,-1): data[i]=data[2*i]|data[2*i+1] for _ in range(int(input())): q,a,b=input().split() if q=="2": print(query(int(a)-1,int(b))) else: update(int(a)-1,1<<(ord(b)-97))
1
62,491,028,562,802
null
210
210
#-*-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 resolve(): X = int(input()) dp = [0 for _ in range(X + 110)] dp[0] = 1 for i in range(X + 1): if dp[i] == 0: continue dp[i + 100] = 1 dp[i + 101] = 1 dp[i + 102] = 1 dp[i + 103] = 1 dp[i + 104] = 1 dp[i + 105] = 1 print(dp[X]) resolve()
0
null
113,696,080,505,954
246
266
n = int(input()) a = list(map(int,input().split())) ans = {i:0 for i in range(n)} for i in a: ans[i-1] += 1 for i in ans.values(): print(i)
n = int(input()) lst = list(map(int,input().split())) lst2 = [0 for i in range(n)] for i in range(n - 1): x = lst[i] lst2[x - 1] = lst2[x - 1] + 1 for i in range(n): print(lst2[i])
1
32,606,113,523,750
null
169
169
def rollDice(dice, direction): buf = [x for x in dice] if direction == "S": buf[0] = dice[4] buf[1] = dice[0] buf[4] = dice[5] buf[5] = dice[1] elif direction == "E": buf[0] = dice[3] buf[2] = dice[0] buf[3] = dice[5] buf[5] = dice[2] elif direction == "W": buf[0] = dice[2] buf[2] = dice[5] buf[3] = dice[0] buf[5] = dice[3] elif direction == "N": buf[0] = dice[1] buf[1] = dice[5] buf[4] = dice[0] buf[5] = dice[4] for i in range(6): dice[i] = buf[i] def rollDiceSide(dice): buf = [x for x in dice] buf[1] = dice[2] buf[2] = dice[4] buf[3] = dice[1] buf[4] = dice[3] for i in range(6): dice[i] = buf[i] d = list(map(int, input().split())) n = int(input()) for i in range(n): q1, q2 = list(map(int, input().split())) wq = d.index(q1) if wq == 1: rollDice(d, "N") elif wq == 2: rollDice(d, "W") elif wq == 3: rollDice(d, "E") elif wq == 4: rollDice(d, "S") elif wq == 5: rollDice(d, "S") rollDice(d, "S") wq = d.index(q2) if wq == 2: rollDiceSide(d) elif wq == 3: rollDiceSide(d) rollDiceSide(d) rollDiceSide(d) elif wq == 4: rollDiceSide(d) rollDiceSide(d) print(d[2])
import math import itertools import sys class Dice: numbers = [] faces = { 'top': None, 'back': None, 'right': None, 'left': None, 'front': None, 'bottom': None, } def __init__(self, int_array): self.numbers = int_array self.faces['top'] = self.numbers[0] self.faces['back'] = self.numbers[1] self.faces['right'] = self.numbers[2] self.faces['left'] = self.numbers[3] self.faces['front'] = self.numbers[4] self.faces['bottom'] = self.numbers[5] def getNum(self, n): return self.numbers[n-1] def getFace(self, f): return self.faces[f] def getRightFace(self, t, b): top = self.faces['top'] back = self.faces['back'] right = self.faces['right'] left = self.faces['left'] front = self.faces['front'] bottom = self.faces['bottom'] if t == self.getNum(2): self.rotate('N') elif t == self.getNum(4): self.rotate('E') elif t == self.getNum(5): self.rotate('S') elif t == self.getNum(3): self.rotate('W') elif t == self.getNum(6): for _ in range(2): self.rotate('N') while self.getFace('back') != b: self.rotate('R') result = self.getFace('right') self.faces['top'] = top self.faces['back'] = back self.faces['right'] = right self.faces['left'] = left self.faces['front'] = front self.faces['bottom'] = bottom return result def rotate(self, direction): if direction == 'N': # 前回り top = self.getFace('top') #一時保存 self.faces['top'] = self.faces['back'] self.faces['back'] = self.faces['bottom'] self.faces['bottom'] = self.faces['front'] self.faces['front'] = top elif direction == 'E': # 右回り top = self.faces['top'] #一時保存 self.faces['top'] = self.faces['left'] self.faces['left'] = self.faces['bottom'] self.faces['bottom'] = self.faces['right'] self.faces['right'] = top elif direction == 'S': # 後ろ回り top = self.faces['top'] #一時保存 self.faces['top'] = self.faces['front'] self.faces['front'] = self.faces['bottom'] self.faces['bottom'] = self.faces['back'] self.faces['back'] = top elif direction == 'W': # 左回り top = self.faces['top'] #一時保存 self.faces['top'] = self.faces['right'] self.faces['right'] = self.faces['bottom'] self.faces['bottom'] = self.faces['left'] self.faces['left'] = top elif direction == 'R': # その場右回り back = self.faces['back'] #一時保存 self.faces['back'] = self.faces['left'] self.faces['left'] = self.faces['front'] self.faces['front'] = self.faces['right'] self.faces['right'] = back else: # その場左回り back = self.faces['back'] #一時保存 self.faces['back'] = self.faces['right'] self.faces['right'] = self.faces['front'] self.faces['front'] = self.faces['left'] self.faces['left'] = back def main(): number = list(map(int, input().split())) q = int(input()) dice = Dice(number) for _ in range(q): t, b = map(int, input().split()) print(dice.getRightFace(t,b)) if __name__ == '__main__': main()
1
255,685,957,572
null
34
34
N, K = map(int, input().split()) X = list(map(int, input().split())) MOD = 998244353 dp = [[0]*(K+1) for _ in range(N+1)] dp[0][0] = 1 for i in range(N): x = X[i] for j in range(K+1): dp[i+1][j] = 2*dp[i][j] if j-x>=0: dp[i+1][j] += dp[i][j-x] dp[i+1][j] %= MOD print(dp[-1][-1])
n, k = map(int, input().split()) ans = 0 for i in range(k, n+2): l = (i*(i-1))*0.5 h = (i*(2*n-i+1))*0.5 ans += (h-l+1) print(int(ans) % (10**9+7))
0
null
25,464,601,956,838
138
170
def main(): n,k= list(map(int,input().split())) h= list(map(int,input().split())) ans=0 for i in range(0,n): if h[i]>=k: ans+=1 print(ans) main()
N=int(input()) *A,=map(int,input().split()) total=0 for i in range(N): total ^= A[i] print(*[total^A[i] for i in range(N)])
0
null
95,960,067,885,308
298
123
#52 大文字変換 S = str(input()) swa = S.swapcase() print(swa)
from string import ascii_lowercase, ascii_uppercase s = input() t = '' for i in s: if i in ascii_uppercase: t += i.lower() elif i in ascii_lowercase: t += i.upper() else: t += i print(t)
1
1,502,179,748,820
null
61
61
d,t,s = [float(x) for x in input().split()] if d/s > t: print("No") else: print("Yes")
def main(): D = int(input()) C = [0] * 26 C = list(map(int,input().split())) S = [ list(map(int,input().split(" "))) for i in range(D)] last = [0] * 26 for i in range(D): max = -9999999999999 max_t = 0 for t in range(26): score = 0 for j in range(26): if j == t: #last[j] = 0 score += S[i][j] else: #last[j] += 1 score -= (last[j]+10)*C[j] if score > max: max = score max_t = t for j in range(26): if j == max_t: last[j] = 0 else: last[j] += 1 print(max_t + 1) if __name__ == '__main__': main()
0
null
6,584,256,905,994
81
113
K = int(input()) S = input() m = 1000000007 result = 0 t = pow(26, K, m) u = pow(26, m - 2, m) * 25 % m l = len(S) for i in range(K + 1): # result += pow(26, K - i, m) * mcomb(len(S) - 1 + i, i) * pow(25, i, m) result = (result + t) % m t = (t * u) % m * (l + i) % m * pow(i + 1, m - 2, m) % m print(result)
import sys def input(): return sys.stdin.readline().strip() def main(): def make_factorial_table(n): result = [0] * (n+1) result[0] = 1 for i in range(1,n+1): result[i] = result[i-1] * i % mod return result def nCr(n,r): return fact[n] * pow(fact[n-r],mod-2,mod) * pow(fact[r],mod-2,mod) % mod K = int(input()) S = input() mod = 10 ** 9 + 7 n = len(S) ans = 0 fact = make_factorial_table(n+K+1) for i in range(K+1): tmp = pow(25,i,mod) tmp *= nCr(i+n-1,n-1) tmp *= pow(26,K-i,mod) ans += tmp ans %= mod print(ans) if __name__ == "__main__": main()
1
12,751,763,055,612
null
124
124
n, m = map(int, input().split()) S = input() ans = [] x = len(S) - 1 while x: for step in range(m, 0, -1): if x - step < 0: continue to = S[x-step] if to == '1': continue else: x -= step ans.append(str(step)) break else: print(-1) exit() print(' '.join(ans[::-1]))
import sys import math from collections import defaultdict from bisect import bisect_left, bisect_right sys.setrecursionlimit(10**7) def input(): return sys.stdin.readline()[:-1] mod = 10**9 + 7 def I(): return int(input()) def LI(): return list(map(int, input().split())) def LIR(row,col): if row <= 0: return [[] for _ in range(col)] elif col == 1: return [I() for _ in range(row)] else: read_all = [LI() for _ in range(row)] return map(list, zip(*read_all)) ################# S = str(input()) if S[-1] == 's': print(S+'es') else: print(S+'s')
0
null
70,551,701,387,840
274
71
t1, t2 = map(int, input().split()) a1, a2 = map(int, input().split()) b1, b2 = map(int, input().split()) ave_a = t1 * a1 + t2 * a2 ave_b = t1 * b1 + t2 * b2 if ave_a < ave_b: (a1, a2), (b1, b2) = (b1, b2), (a1, a2) ave_a, ave_b = ave_b, ave_a if ave_a == ave_b: print('infinity') exit() half, all = t1 * (b1 - a1), ave_a - ave_b ans = half // all * 2 + (half % all != 0) print(max(0, ans))
''' 自宅用PCでの解答 ''' import math #import numpy as np import itertools import queue import bisect from collections import deque,defaultdict import heapq as hpq from sys import stdin,setrecursionlimit #from scipy.sparse.csgraph import dijkstra #from scipy.sparse import csr_matrix ipt = stdin.readline setrecursionlimit(10**7) def main(): t1,t2 = map(int,ipt().split()) a1,a2 = map(int,ipt().split()) b1,b2 = map(int,ipt().split()) d1 = t1*(a1-b1) d2 = t2*(a2-b2) if d1*(d1+d2) > 0: print(0) elif d1+d2 == 0: print("infinity") else: dt = d1+d2 if abs(d1)%abs(dt): print(abs(d1)//abs(dt)*2+1) else: print(abs(d1)//abs(dt)*2) return None if __name__ == '__main__': main()
1
131,810,086,180,900
null
269
269
import sys for index, line in enumerate(sys.stdin): value = int(line.strip()) if value == 0: break print("Case {0}: {1}".format(index+1, value))
count = 0 while True: count+=1 a = int(input()) if a == 0: break print("Case %d: %d" % (count, a))
1
471,832,666,436
null
42
42
n = int(input()) A = [int(x) for x in input().split()] cnt = 0 for i in range(n): if (i+1)%2 != 0 and A[i]%2 != 0: cnt += 1 print(cnt)
a = int(input()) AA = map(int,input().split()) AAA = list(AA) count = 0 for i in range(a): if i%2 ==0 and AAA[i]%2 ==1: count +=1 print(count)
1
7,670,488,333,442
null
105
105
#!usr/bin/env python3 from collections import defaultdict, deque, Counter, OrderedDict from functools import reduce, lru_cache import collections, heapq, itertools, bisect import math, fractions import sys, copy sys.setrecursionlimit(1000000) def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline().rstrip()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): return list(sys.stdin.readline().rstrip()) def IR(n): return [I() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def LIR1(n): return [LI1() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] dire = [[1, 0], [0, 1], [-1, 0], [0, -1]] dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] MOD = 1000000007 def main(): K, N = LI() A = LI() res = [A[0] + K - A[-1]] for i in range(N-1): res.append(A[i+1] - A[i]) res = sorted(res) print(K - res[-1]) if __name__ == '__main__': main()
x = input() y = x.split(" ") y[0] = int(y[0]) y[1] = int(y[1]) if y[0] < y[1]: print("a < b") elif y[0] > y[1]: print("a > b") else: print("a == b")
0
null
21,845,738,545,542
186
38