code1
stringlengths
16
24.5k
code2
stringlengths
16
24.5k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.71M
180,628B
code1_group
int64
1
299
code2_group
int64
1
299
s = input() t = ["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"] print(7-int(t.index(s)))
# Coding is about expressing your feeling, and # there is always a better way to express your feeling_feelme import sys import math # sys.stdin=open('input.txt','r') # sys.stdout=open('output2.txt','w') from sys import stdin,stdout from collections import deque,defaultdict from math import ceil,floor,inf,sqrt,factorial,gcd,log2 from copy import deepcopy ii1=lambda:int(stdin.readline().strip()) is1=lambda:stdin.readline().strip() iia=lambda:list(map(int,stdin.readline().strip().split())) isa=lambda:stdin.readline().strip().split() mod=int(1e9 + 7) n=ii1() if n==1: print(1) elif n%2==0: print(1/2) else: print((n//2 +1)/n)
0
null
155,106,094,959,812
270
297
N = int(input()) _L = list(map(int,input().split())) L = [(v,i) for i,v in enumerate(_L)] L = sorted(L,key=lambda x:(-x[0])) dp = [[0]*(N+1) for _ in range(N+1)] ans=0 for x in range(N):#前から for y in range(N):#後ろから cur = x+y if cur==N: ans = max(ans,dp[x][y]) break val,ind = L[cur] dp[x+1][y] = max(dp[x+1][y],dp[x][y]+val*abs(ind-x)) dp[x][y+1] = max(dp[x][y+1],dp[x][y]+val*abs(N-y-1-ind)) print(ans)
from sys import stdin def main(): n = int(stdin.readline()) a = list(map(int, stdin.readline().split())) a2 = [[a[i], i] for i in range(n)] a2.sort(reverse=True) dp = [[0 for _ in range(n + 1)] for _ in range(n + 1)] ans = 0 for i in range(n + 1): for j in range(n + 1 - i): s1 = s2 = 0 if i > 0: s1 = dp[i - 1][j] + a2[i + j - 1][0] * (a2[i + j - 1][1] - (i - 1)) if j > 0: s2 = dp[i][j - 1] + a2[i + j - 1][0] * ((n - j) - a2[i + j - 1][1]) dp[i][j] = max(s1, s2) ans = max(ans, dp[i][n - i]) print(ans) if __name__ == "__main__": main()
1
33,761,559,180,820
null
171
171
n=int(input()) s = [input() for i in range(n)] s.sort() ans=n for i in range(1,n): if s[i]==s[i-1]: ans-=1 print(ans)
import sys def input(): return sys.stdin.readline()[:-1] N,M=map(int,input().split()) class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) uf=UnionFind(N+1) for i in range(M): a,b=map(int, input().split()) uf.union(a,b) print(uf.group_count()-2)
0
null
16,146,562,200,880
165
70
def print0(): print(0) exit() n = int(input()) d = list(map(int, input().split())) mod = 998244353 ans = 1 maxd = max(d) numcnt = [0] * (maxd + 1) for i in d: numcnt[i] += 1 if not d[0] == 0 or not numcnt[0] == 1: print0() for i in range(1, maxd + 1): if numcnt[i] == 0: print0() ans *= pow(numcnt[i - 1], numcnt[i], mod) ans %= mod print(ans)
n = int(input()) a = list(map(int, input().split())) c = [0]*(n+1) for i in a: c[i] += 1 ans = 1 for i in range(n+1): if c[-1] == 0: c.pop() else: break mod = 998244353 for i in range(len(c)-1): ans *= pow(c[i], c[i+1], mod) ans %= mod if a[0] != 0: ans *= 0 if c[0] != 1: ans *= 0 print(ans)
1
154,661,223,145,120
null
284
284
from collections import deque N, M = map(int, input().split()) g = [[] for i in range(N)] for i in range(M): A, B = map(int, input().split()) g[A-1].append(B) g[B-1].append(A) ans = [-1] * N ans[0] = 0 d = deque([1]) while len(d) != 0: now = d[0] d.popleft() for i in g[now-1]: if ans[i-1] != -1: continue ans[i-1] = now d.append(i) if -1 in ans: print('No') else: print('Yes') for i in ans[1:]: print(i)
a,b,c,d = map(int, input().split()) i = 0 while a > 0 and c > 0: if i%2 == 0: c -= b else: a -= d i += 1 if a > c: print('Yes') else: print('No')
0
null
25,068,356,887,520
145
164
import sys while True: h, w = [ int( val ) for val in sys.stdin.readline().split( " " ) ] if 0 ==h and 0 == w: break for i in range( h ): if 0 == i or h-1 == i: print( "#"*w ) else: print( "#"+"."*(w -2)+"#" ) print( "" )
def rect(h, w): s = '#' * w while h > 1: print(s) s = '#' + '.' * (w - 2) + '#' h -= 1 print('#' * w) print() return while True: n = list(map(int, input().split())) H = n[0] W = n[1] if (H == 0 and W == 0): break rect(H, W)
1
841,076,673,568
null
50
50
import sys import itertools import numpy as np import time import math sys.setrecursionlimit(10 ** 7) from collections import defaultdict read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): x, y, a, b, c = map(int, readline().split()) p = sorted(map(int, readline().split()), reverse=True) q = sorted(map(int, readline().split()), reverse=True) r = sorted(map(int, readline().split()), reverse=True) z = sorted(p[:x] + q[:y] + r, reverse=True) ans = sum(z[:x+y]) print(ans) if __name__ == "__main__": main() pass
N = int(input()) ans = [0]*4 for i in range(N): s = input() if s == "AC": ans[0] += 1 elif s == "WA": ans[1] += 1 elif s == "TLE": ans[2] += 1 elif s == "RE": ans[3] += 1 print("AC x "+ str(ans[0]),"WA x "+ str(ans[1]),"TLE x "+ str(ans[2]),"RE x "+ str(ans[3]),sep = "\n" )
0
null
26,752,567,209,282
188
109
import sys input = lambda: sys.stdin.readline().rstrip() def main(): n = int(input()) a = [int(i) for i in input().split()] mark = 1 remain = 0 for i in range(n): if a[i] == mark: remain += 1 mark += 1 if remain == 0: print(-1) else: print(n-remain) if __name__ == '__main__': main()
import math n = int(input()) x = list(map(int, input().split())) y = list(map(int, input().split())) tmp = [[0 for i in range(6)] for j in range(n+1)] absDiff = abs(x[0]-y[0]) tmp[0][3] = tmp[0][0] = absDiff tmp[0][4] = tmp[0][1] = absDiff ** 2 tmp[0][5] = tmp[0][2] = absDiff ** 3 max = absDiff for i in range(1, n, 1): absDiff = abs(x[i]-y[i]) tmp[i][0] = absDiff tmp[i][1] = absDiff ** 2 tmp[i][2] = absDiff ** 3 tmp[i][3] = tmp[i-1][3] + tmp[i][0] tmp[i][4] = tmp[i-1][4] + tmp[i][1] tmp[i][5] = tmp[i-1][5] + tmp[i][2] if absDiff > max: max = absDiff print(tmp[n-1][3]) print(math.sqrt(tmp[n-1][4])) print(tmp[n-1][5] ** (1/3)) print(max)
0
null
57,734,552,286,700
257
32
a, b, n = map(int, input().split()) if n <= b - 1: x = n else: x = n - (n%b + 1) ans = a*x//b - a*(x//b) print(ans)
import sys input = sys.stdin.readline import math def read(): N, K = map(int, input().strip().split()) A = list(map(int, input().strip().split())) return N, K, A def solve(N, K, A): d = [0 for i in range(N+1)] for k in range(K): for i in range(N): d[i] = 0 for i in range(N): l = max(0, i-A[i]) r = min(N, i+1+A[i]) d[l] += 1 d[r] -= 1 terminate = True v = 0 for i in range(N): v += d[i] A[i] = v if terminate and A[i] < N: terminate = False if terminate: break print(*[a for a in A]) if __name__ == '__main__': inputs = read() outputs = solve(*inputs) if outputs is not None: print("%s" % str(outputs))
0
null
21,702,891,413,852
161
132
h,w,k = map(int,input().split()) ls = [str(input()) for _ in range(h)] a = [[] for _ in range(2**h)] b = [[] for _ in range(2**w)] for i in range(2**h): for j in range(h): if (i>>j)&1: a[i].append(j) for s in range(2**w): for l in range(w): if (s>>l)&1: b[s].append(l) p = 0 for e in range(2**h): for f in range(2**w): cnt = 0 for g in range(len(ls)): if g not in a[e]: di = list(ls[g]) for t in range(len(di)): if t not in b[f]: if di[t] == "#": cnt += 1 if cnt == k: p += 1 print(p)
while True: x_sum = sum([int(x) for x in raw_input()]) if x_sum == 0: break print x_sum
0
null
5,269,030,094,372
110
62
def cum(n): cum = 0 for i in range(n+1): cum += i return cum s = input() tmp = s[0] count = 0 l = [] for each in s: if each == tmp: count += 1 else: l.append(count) count = 1 tmp = each l.append(count) ans = 0 if s[0] == "<": for i in range(0,len(l),2): tmp = l[i:i+2] if len(tmp) == 1: ans += cum(tmp[0]) else: ans += cum(max(tmp)) + cum(min(tmp)-1) else: ans += cum(l[0]) for i in range(1, len(l),2): tmp = l[i:i+2] if len(tmp) == 1: ans += cum(tmp[0]) else: ans += cum(max(tmp)) + cum(min(tmp)-1) print(ans)
def main(): x = int(input()) cnt = x // 100 m, M = cnt * 100, cnt * 105 if m <= x <= M: print(1) else: print(0) if __name__ == "__main__": main()
0
null
141,969,169,907,488
285
266
# encoding:utf-8 input = map(int, raw_input().split()) height = input[0] width = input[1] area = height * width circumference = (height + width) * 2 print(area), print(circumference)
a,b=map(int, raw_input().split()) c=a*b d=2*(a+b) print c,d
1
305,512,858,240
null
36
36
N = int(input()) A = list(map(lambda x: int(x) - 1, input().split())) C = [0] * N for a in A: C[a] += 1 def comb(n): if n <= 1: return 0 else: return n * (n - 1) // 2 t = sum(list(map(comb, C))) for a in A: print(t - comb(C[a]) + comb(C[a] - 1))
n = int(input()) t_score = 0 h_score = 0 for i in range(n): t_card, h_card = input().split() if t_card < h_card: h_score += 3 elif t_card > h_card: t_score += 3 else: h_score += 1 t_score += 1 print(t_score, h_score)
0
null
24,680,373,791,360
192
67
MOD = 998244353 N = int(input()) D = list(map(int, input().split())) D_2 = [0]*(max(D)+1) for i in D: D_2[i] += 1 ans = 1 if D_2[0] == 1 and D[0] == 0 else 0 for i in range(1,max(D)+1): ans *= D_2[i-1]**D_2[i] ans %= MOD print(ans)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline in_n = lambda: int(readline()) in_nn = lambda: map(int, readline().split()) in_nl = lambda: list(map(int, readline().split())) in_na = lambda: map(int, read().split()) in_s = lambda: readline().rstrip().decode('utf-8') def main(): N = in_n() D = in_nl() mod = 998244353 if D[0] != 0: print(0) exit() for i in range(1, N): if D[i] == 0: print(0) exit() count = [0] * N for i in range(N): count[D[i]] += 1 zero = N + 1 non_zero = -1 for i in range(N): if count[i] == 0: zero = min(zero, i) else: non_zero = max(non_zero, i) if zero < non_zero: print(0) exit() ans = 1 for i in range(1, N): if count[i] == 0: break else: ans *= count[i - 1] ** count[i] ans %= mod print(ans) if __name__ == '__main__': main()
1
154,247,652,785,468
null
284
284
s=[0,0] for i in range(int(input())): r=input().split() if r[0]<r[1]: s[1]+=3 elif r[1]<r[0]: s[0]+=3 else: s[0]+=1 s[1]+=1 print(str(s[0])+' '+str(s[1]))
N, M = map(int, input().split()) c = list(map(int, input().split())) dp = [0] + [float('inf')] * N for m in range(M): ci = c[m] for n in range(N + 1): if n - ci >= 0: dp[n] = min(dp[n], dp[n - ci] + 1) print(dp[N])
0
null
1,077,751,269,078
67
28
N = int(input()) K = int(input()) def cmb(n, r): if n - r < r: r = n - r if r == 0: return 1 if r == 1: return n numerator = [n - r + k + 1 for k in range(r)] denominator = [k + 1 for k in range(r)] for p in range(2,r+1): pivot = denominator[p - 1] if pivot > 1: offset = (n - r) % p for k in range(p-1,r,p): numerator[k - offset] /= pivot denominator[k] /= pivot result = 1 for k in range(r): if numerator[k] > 1: result *= int(numerator[k]) return result def contain_one(n): a = 100 max_num = 10**a while 1: if n // max_num == 0: a -= 1 max_num = 10**a else: break return 9*a+(n//max_num) def contain_two(n): if n <=10: return 0 a = 100 max_num = 10**a while 1: if n // max_num == 0: a -= 1 max_num = 10**a else: break cnt = 0 #10^a位まで for i in range(1, a): cnt += 9*9*i #10^a位 tmp = n // max_num cnt += 9*a*(tmp-1) #nの10^a桁より小さい数 tmp = n % max_num #怪しい if tmp != 0: cnt += contain_one(tmp) return cnt def contain_three(n): if n <=100: return 0 a = 100 max_num = 10**a while 1: if n // max_num == 0: a -= 1 max_num = 10**a else: break cnt = 0 #10000以上の時ここがダメ for i in range(2, a): if i == 2: cnt += 9**2 * 9 else: #3H(a-2) = aCa-2 cnt += 9**2 * 9 * cmb(i, i-2) #aH2 #cnt += 9**2 * 9 * (i*(i+1)//2) # tmp = tmp * 3 # cnt += tmp tmp = n // max_num if a == 2: cnt += 9**2 * (tmp-1) else: cnt += 9**2 * (tmp-1) * cmb(a, a-2) tmp = n % max_num if tmp != 0: cnt += contain_two(tmp) return cnt if K == 1: print(contain_one(N)) elif K == 2: print(contain_two(N)) else: print(contain_three(N))
import numpy as np N = input() K = int(input()) n = len(N) dp0 = np.zeros((n, K+1), np.int64) dp1 = np.zeros((n, K+1), np.int64) dp0[0, 0] = 1 dp0[0, 1] = int(N[0]) - 1 dp1[0, 1] = 1 for i, d in enumerate(N[1:]): dp0[i+1] += dp0[i] dp0[i+1, 1:] += dp0[i, :-1] * 9 if int(d) == 0: dp1[i+1] = dp1[i] elif int(d) == 1: dp0[i+1] += dp1[i] dp1[i+1, 1:] = dp1[i, :-1] elif int(d) >= 2: dp0[i+1] += dp1[i] dp0[i+1, 1:] += dp1[i, :-1] * (int(d) - 1) dp1[i+1, 1:] = dp1[i, :-1] print(dp0[-1, K] + dp1[-1, K])
1
75,870,013,135,652
null
224
224
n=int(input());l=list(map(int,input().split()));p=[0]*n;d=[0]*n;p[0]=l[0] for i in range(1,n):p[i]=l[i]+p[i-2];d[i]=max(p[i-1]if(i&1)else d[i-1],l[i]+d[i-2]) print(d[-1])
n=int(input()) a=list(map(int,input().split())) a.sort() am=max(a) dp=[[True,0] for _ in range(am+1)] count=0 for i in a: if dp[i][0]==False: continue else: if dp[i][1]==1: dp[i][0]=False count-=1 else: dp[i][1]=1 count+=1 for j in range(2*i,am+1,i): dp[j][0]=False print(count)
0
null
25,744,898,125,540
177
129
ab = list(map(int,input().split())) ab.sort() print(str(ab[0])*ab[1])
n = int(input()) s = input() a = s[:n//2] b = s[n//2:] if a == b: print('Yes') else: print('No')
0
null
115,704,020,569,652
232
279
for x in range(9): x = x + 1 for y in range(9): y = y + 1 print(x.__str__() + 'x' + y.__str__() + '=' + (x * y).__str__() )
import math a, b, x = map(int,input().split()) s = a t = 2*(b-x/(a*a)) u = x*2/(b*a) if t<=b: print(math.degrees(math.atan(t/s))) else: print(math.degrees(math.atan(b/u)))
0
null
81,950,100,358,062
1
289
import math n=int(input()) print((n-math.floor(n/2))/n)
N = int(input()) l = [] for _ in range(N): A, B = map(int, input().split()) l.append((A, B)) t = N//2 tl = sorted(l) tr = sorted(l, key=lambda x:-x[1]) if N%2: print(tr[t][1]-tl[t][0]+1) else: a1, a2 = tl[t-1][0], tr[t][1] a3, a4 = tl[t][0], tr[t-1][1] print(a4-a3+a2-a1+1)
0
null
96,721,906,197,220
297
137
import sys x = sys.stdin.readline() print int(x) ** 3
# coding: utf-8 i = input() j = int(i) ** 3 print(j)
1
279,659,786,880
null
35
35
N = int(input()) t = N // 2 a_list = [] b_list = [] for i in range(N): ab = list(map(int, input().split())) a_list.append(ab[0]) b_list.append(ab[1]) a_list = sorted(a_list) b_list = sorted(b_list) if N%2 == 1: a_median = a_list[t] b_median = b_list[t] print(b_median-a_median+1) elif N%2 == 0: a_median = (a_list[t-1]+a_list[t])/2 b_median = (b_list[t-1]+b_list[t])/2 print(int(2*(b_median-a_median)+1))
import sys sys.setrecursionlimit(10**5) n, u, v = map(int, input().split()) u -= 1 v -= 1 m_mat = [[] for i in range(n)] for _ in range(n-1): a, b = map(int, input().split()) a -= 1 b -= 1 m_mat[a].append(b) m_mat[b].append(a) u_map = [-1]*n v_map = [-1]*n u_map[u] = 0 v_map[v] = 0 def dfs(current, depth, ma): for nex in m_mat[current]: if ma[nex] > -1: continue ma[nex] = depth dfs(nex, depth+1, ma) dfs(u, 1, u_map) dfs(v, 1, v_map) ans = -1 for i in range(n): if u_map[i] < v_map[i] and v_map[i] > ans: ans = v_map[i] print(ans-1)
0
null
67,071,663,809,992
137
259
a= int(input()) b = list(map(int,input().split())) b = list(map(lambda x : x-1,b)) bukas = [[]for i in range(a)] for i in range(1,a): bukas[b[i-1]].append(i) for c in bukas: print(len(c))
def main(): N = int(input()) A = list(map(int,input().split())) list_a = [0]*N for i in range(len(A)): list_a[A[i]-1] += 1 for i in range(N): print(list_a[i]) main()
1
32,554,299,862,628
null
169
169
n=int(input()) dic={} for i in range(1,50001): p=int(i*1.08) dic[p]=i if n in dic: print(dic[n]) else: print(":(")
#4 import sys N = int(input()) x,y,k = 0,0,0 if N == 1: print(1) sys.exit() elif N <= 12: print(N) sys.exit() x = int(0.8*N) for i in range(x,N): k = str(i*108) if int(k[0:-2]) == N: print(i) y +=1 break if y !=1: print(":(")
1
125,539,141,330,912
null
265
265
def breathSerch(P,N): n=len(P)-1 m=1 QQ=[N[1]] while(QQ != []): R=[] for Q in QQ: for i in range(1,n+1): if Q[i]==1 and P[i]==-1: P[i]=m R.append(N[i]) QQ = R m=m+1 n = int(input()) A = [[0 for j in range(n+1)] for i in range(n+1)] for i in range(n): vec = input().split() u = int(vec[0]) k = int(vec[1]) nodes = vec[2:] for i in range(int(k)): v = int(nodes[i]) A[u][v] = 1 P=[-1 for i in range(n+1)] P[1]=0 breathSerch(P,A) for i in range(1,n+1): print(i,P[i])
n = int(input()) m = [[] for _ in range(n+1)] for _ in range(n): tmp = [int(x) for x in input().split()] u,k,l = tmp[0],tmp[1],tmp[2:] m[u] += tmp[2:] dp = [float('inf') for _ in range(n+1)] dp[1] = 0 queue = [1] while queue: t = queue.pop(0) for x in m[t]: if dp[x] > dp[t] + 1: dp[x] = dp[t] + 1 queue.append(x) for i,x in enumerate(dp): if i == 0: pass else: if x == float('inf'): print(i, -1) else: print(i, x)
1
3,866,743,410
null
9
9
from collections import defaultdict n, k = map(int, input().split()) A = list(map(int, input().split())) delta_count = defaultdict(int) cumA = [0] total = 0 for a in A: total += a total %= k cumA.append(total) for i in range(1, min(n+1, k)): num = cumA[i] delta = (num - i) % k delta_count[delta] += 1 ans = delta_count[0] left = 1 right = min(k-1, n) while left <= n-1: popleft = (cumA[left] - left) % k delta_count[popleft] -= 1 if right <= n-1: right += 1 num = cumA[right] append = (num - right) % k delta_count[append] += 1 desire = (cumA[left] - left) % k ans += delta_count[desire] left += 1 print(ans)
import sys,queue,math,copy,itertools,bisect,collections,heapq def main(): LI = lambda : [int(x) for x in sys.stdin.readline().split()] N,K = LI() A = LI() c = 0 d = collections.Counter() d[0] = 1 ans = 0 r = [0] * (N+1) for i,x in enumerate(A): if i >= K-1: d[r[i-(K-1)]] -= 1 c = (c + x - 1) % K ans += d[c] d[c] += 1 r[i+1] = c print(ans) if __name__ == '__main__': main()
1
136,941,316,905,118
null
273
273
s = input() t = ["x" for _ in range(len(s))] print(''.join(t))
import random name = input() name_lenght = len(name) start = random.randint(0, name_lenght - 3) end = start + 3 print(name[start:end])
0
null
43,907,667,332,672
221
130
import sys input = sys.stdin.readline n=int(input()) k=int(input()) dp1=[0]*(k+1) dp2=[0]*(k+1) dp1[0]=1 for x in map(int,str(n)): for j in range(k,-1,-1): if j>0: dp2[j]+=dp2[j-1]*9 if x!=0: dp2[j]+=dp1[j-1]*(x-1)+dp1[j] dp1[j]=dp1[j-1] #print(dp1) #print(dp2) else: dp2[j]=1 dp1[j]=0 print(dp1[k]+dp2[k])
n="0"+input() k=int(input()) dp=[[[0]*5,[0]*5] for _ in range(len(n))] dp[0][1][0]=1 for i in range(1,len(n)): x=int(n[i]) for j in range(4): if dp[i-1][1][j]: dp[i][1][j+(x!=0)]=1 if x>1: dp[i][0][j+1]+=(x-1) dp[i][0][j]+=1 elif x==1: dp[i][0][j]+=1 if dp[i-1][0][j]: dp[i][0][j]+=dp[i-1][0][j] dp[i][0][j+1]+=(dp[i-1][0][j]*9) dp[i][0][0]=1 print(dp[-1][0][k]+dp[-1][1][k])
1
75,805,184,709,924
null
224
224
import sys N,K = map(int,input().split()) H = sorted(list(map(int,input().split())),reverse = True) for i in range(N): if not H[i] >= K: print(i) sys.exit() print(N)
n = int(input()) res = 0 while n != 0: res = n%10 dropped = n while dropped//10 != 0: dropped = dropped//10 res += dropped%10 print(res) res = 0 n = int(input())
0
null
89,963,061,238,982
298
62
# import itertools S = input()[::-1] # l = len(S) # nums = range(1, l+1) count = [0]*2019 count[0] = 1 num = 0 d = 1 for i in S: num += int(i)*d num %= 2019 count[num] += 1 d *= 10 d %= 2019 ans = 0 for i in count: ans += i*(i-1)//2 print(ans)
from collections import Counter S = input() L = len(list(S)) dp = [0] * L dp[0] = 1 T = [0] * L T[0] = int(S[-1]) for i in range(1, L): dp[i] = dp[i - 1] * 10 dp[i] %= 2019 T[i] = int(S[-(i+1)]) * dp[i] + T[i - 1] T[i] %= 2019 ans = 0 for k, v in Counter(T).items(): if k == 0: ans += v ans += v * (v - 1) // 2 else: ans += v * (v - 1) // 2 print(ans)
1
30,761,663,492,612
null
166
166
a,b=[int(i) for i in input().split(" ")] while b!=0: t = min(a,b) b = max(a,b) % min(a,b) a = t print(a)
import math line=input().split() x=int(line[0]) y=int(line[1]) print(math.gcd(x,y))
1
6,976,215,432
null
11
11
from collections import defaultdict N = int(input()) *A, = map(int, input().split()) INF = 10**20 dp = [[defaultdict(lambda :-INF) for _ in range(N+1)] for _ in range(2)] dp[0][0][0] = 0 for i in range(1, N+1): for j in range(i//2-1, i//2+2): dp[1][i][j] = max(dp[1][i][j], dp[0][i-1][j-1]+A[i-1]) dp[0][i][j] = max(dp[1][i-1][j], dp[0][i-1][j]) ans = max(dp[1][N][N//2], dp[0][N][N//2]) print(ans)
import sys import bisect read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines in_n = lambda: int(readline()) in_nn = lambda: map(int, readline().split()) in_s = lambda: readline().rstrip().decode('utf-8') in_nl = lambda: list(map(int, readline().split())) in_nl2 = lambda H: [in_nl() for _ in range(H)] in_map = lambda: [s == ord('.') for s in readline() if s != ord('\n')] in_map2 = lambda H: [in_map() for _ in range(H)] in_all = lambda: map(int, read().split()) class SegTree: def __init__(self, init_val, segfunc, ide_ele): n = len(init_val) self.ide_ele = ide_ele self.segfunc = segfunc self.num = 2**(n - 1).bit_length() self.seg = [self.ide_ele] * 2 * self.num for i in range(n): self.seg[i + self.num - 1] = init_val[i] for i in range(self.num - 2, -1, -1): self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2]) def update(self, k, x): k += self.num - 1 self.seg[k] += x while k: k = (k - 1) // 2 self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2]) def query(self, p, q): if q <= p: return self.ide_ele p += self.num - 1 q += self.num - 2 res = self.ide_ele while q - p > 1: if p & 1 == 0: res = self.segfunc(res, self.seg[p]) if q & 1 == 1: res = self.segfunc(res, self.seg[q]) q -= 1 p = p // 2 q = (q - 1) // 2 if p == q: res = self.segfunc(res, self.seg[p]) else: res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q]) return res def main(): N, D, A = in_nn() XH = sorted(in_nl2(N)) X = [0] * N H = [0] * N for i in range(N): x, h = XH[i] X[i] = x H[i] = h seg = SegTree([0] * N, segfunc=lambda a, b: a + b, ide_ele=0) ans = 0 for i in range(N): x, h = X[i], H[i] j = bisect.bisect_right(X, x + 2 * D) cnt_bomb = seg.query(0, i + 1) h -= A * cnt_bomb if h <= 0: continue cnt = -(-h // A) ans += cnt seg.update(i, cnt) if j < N: seg.update(j, -cnt) # print(i, j) # print(seg.seg) print(ans) if __name__ == '__main__': main()
0
null
59,757,349,831,242
177
230
def main(): K: int = int(input()) S: str = 'ACL' print(S*K) if __name__ == "__main__": main()
S = str(input()) if len(S) % 2 != 0: ans = 'No' else: h = int(len(S) / 2) s = [[S[2 * i - 2], S[2 * i -1]] for i in range(h)] hi = s.count(['h', 'i']) if h == hi: ans = 'Yes' else: ans = 'No' print(ans)
0
null
27,516,369,918,000
69
199
ary = list(filter(lambda x: int(x) % 3 != 0 and int(x) % 5 != 0, list(range(int(input()) + 1)))) print(sum(ary))
def resolve(): N, M = map(int, input().split()) if N%2==1: for i in range(1, M+1): a, b = i, N-i print(a, b) else: for i in range(1, M+1): a, b = i, N - i # 円として配置したとき、b-aが半分以上になったら片方だけ進める if b-a <= N//2: a += 1 print(a, b) if __name__ == "__main__": resolve()
0
null
31,880,363,180,068
173
162
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)
n,m = map(int, input().split()) h = list(map(int, input().split())) ab = [map(int, input().split()) for _ in range(m)] a,b = [list(i) for i in zip(*ab)] Max = [] for i in range(n): Max.append(0) # print(Max) ans = 0 for i in range(m): Max[a[i]-1] = max(Max[a[i]-1],h[b[i]-1]) Max[b[i]-1] = max(Max[b[i]-1],h[a[i]-1]) for i in range(n): if h[i] > Max[i]: ans += 1 print(ans)
1
25,225,492,671,320
null
155
155
def gcd2(x,y): if y == 0: return x return gcd2(y,x % y) def lcm2(x,y): return x // gcd2(x,y) * y a,b = map(int,input().split()) print(lcm2(a,b))
import os, sys, re, math from functools import reduce def lcm(vals): return reduce((lambda x, y: (x * y) // math.gcd(x, y)), vals, 1) (A, B) = [int(n) for n in input().split()] print(lcm([A, B]))
1
113,193,368,103,492
null
256
256
x, n = map(int, input().split()) p = [int(v) for v in input().split()] ans = None if x not in p: ans = x else: diff = 101 for i in range(0, max(p) + 2): if abs(x - i) < diff and i not in p: ans = i diff = abs(x - i) print(ans)
X, N = map(int, input().split()) p = list(map(int, input().split())) ans = None diff = 1000 if X not in p: ans = X else: for i in range(-1, max(max(p), X)+2): if i in p:continue if abs(X - i) < diff: diff = abs(X - i) ans = i print(ans)
1
14,043,484,007,202
null
128
128
n=int(input()) tp = 0 hp = 0 for _ in range(n): taro,hanaco = input().split() if taro == hanaco : tp +=1 hp +=1 elif taro > hanaco : tp += 3 else: hp += 3 print('{} {}'.format(tp,hp))
import sys sys.setrecursionlimit(10**7) input = sys.stdin.readline a,b = map(int, input().split()) e = 0.08 t = 0.1 for i in range(1, 1000+1): if int(i * e) == a and int(i * t) == b: print(i) exit() print(-1)
0
null
29,293,423,920,878
67
203
n=int(input()) d={} for _ in range(n): s=input() if s in d: d[s]+=1 else: d[s]=1 m=max(d.values()) ans=[] for i,k in d.items(): if m==k: ans.append(i) for i in sorted(ans): print(i)
import collections n = int(input()) dic = collections.defaultdict(int) for _ in range(n): s = input() dic[s] +=1 sorted_dic = sorted(dic.items(), key = lambda x:(-x[1],x[0])) val = sorted_dic[0][1] for k,v in sorted_dic: if v==val: print(k)
1
70,146,788,297,588
null
218
218
K=int(input()) ans=[] def saiki(A): genzai_saigo=int(A[-1]) ketasu=len(A) if ketasu>0: B="".join(A) ans.append(eval(B)) if ketasu==10: return for i in [genzai_saigo-1,genzai_saigo,genzai_saigo+1]: if i < 0 or i>9: continue A.append(str(i)) saiki(A) A.pop() for i in range(1,10): saiki([str(i)]) ans.sort() print(ans[K-1])
def is_good(mid, key): S = list(map(int, str(mid))) N = len(S) dp = [[[0] * 11 for _ in range(2)] for _ in range(N + 1)] dp[1][1][10] = 1 for k in range(1, S[0]): dp[1][1][k] = 1 dp[1][0][S[0]] = 1 for i in range(1, N): for k in range(1, 11): dp[i + 1][1][k] += dp[i][0][10] + dp[i][1][10] for is_less in range(2): for k in range(10): for l in range(k - 1, k + 2): if not 0 <= l <= 9 or (not is_less and l > S[i]): continue dp[i + 1][is_less or l < S[i]][l] += dp[i][is_less][k] return sum(dp[N][0][k] + dp[N][1][k] for k in range(10)) >= key def binary_search(bad, good, key): while good - bad > 1: mid = (bad + good) // 2 if is_good(mid, key): good = mid else: bad = mid return good K = int(input()) print(binary_search(0, 3234566667, K))
1
39,824,944,227,802
null
181
181
import math r = float(input()) print('%.5f' % (r * r * math.pi), '%.5f' % (2 * math.pi * r))
from math import pi r = float(input()) z = r*r*pi l = 2*r*pi print('{} {}'.format(z,l))
1
657,594,510,272
null
46
46
W, H ,x, y, r = map(int, input().split()) if ((x-r)<0) or ((y-r)<0) or ((x+r)>W) or ((y+r)>H): print("No") else: print("Yes")
n = int(input()) s = [input() for _ in range(n)] dic = {"AC": 0, "WA": 0, "TLE": 0, "RE":0} for v in s: dic[v] += 1 print("AC x {}".format(dic["AC"])) print("WA x {}".format(dic["WA"])) print("TLE x {}".format(dic["TLE"])) print("RE x {}".format(dic["RE"]))
0
null
4,568,046,651,442
41
109
while True: H, W = map(int, raw_input().split()) if H == W == 0: break for i in range(H): if W == 1 and i % 2 == 0: print "#" elif W == 1 and i % 2 == 1: print "." elif i % 2 == 0: print "#." * (W / 2) + "#" * (W%2) else: print ".#" * (W / 2) + "." * (W%2) print
import itertools for i,j in itertools.product(xrange(1,10),repeat=2): print '{0}x{1}={2}'.format(i,j,i*j)
0
null
429,685,708,000
51
1
S = input() if S[-1] != "s" : print(S + "s") elif S[-1] == "s" : print(S + "es") else : print(" ")
st = input() if st[-1] == "s": st += "es" else: st += "s" print(st)
1
2,394,547,566,090
null
71
71
h, w, k = map(int, input().split(' ')) c = [input() for x in range(h)] cnt = 0 for m in range(2**(h+w)): cc = c.copy() for ij in range(h+w): if ((m >> ij) & 1): if ij in range(h): cc[ij] = '.'*w if ij in range(h,h+w): for t in range(h): cc[t] = cc[t][:ij-h]+'.'+cc[t][ij+1-h:] num = sum(cc[s].count('#') for s in range(h)) if num == k: cnt += 1 print(cnt)
import sys import itertools input = sys.stdin.readline def SI(): return str(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def main(): H, W, K = MI() grid = [SI().rstrip('\n') for _ in range(H)] n = H + W ans = 0 for i in itertools.product(range(2),repeat = H): for j in itertools.product(range(2),repeat = W): count = 0 for k in range(H): if i[k] == 1: continue for l in range(W): if j[l] == 1: continue if grid[k][l] == "#": count += 1 if count == K: ans +=1 print(ans) main()
1
8,939,441,192,110
null
110
110
a,b,c=map(int,input().split()) K=int(input()) isCheck = None for i in range(K+1): for j in range(K+1): for k in range(K+1): x = a*2**(i) y = b*2**(j) z = c*2**(k) if i+j+k <= K and x < y and y < z: isCheck = True if isCheck: print("Yes") else: print("No")
# B - Tax Rate N = int(input()) ans = ':(' for x in range(50000): if (108*x)//100==N: ans = x break print(ans)
0
null
66,186,035,335,550
101
265
N = int(input()) A = list(map(int, input().split())) rng = [[A[N], A[N]]] for i in range(N - 1, -1, -1): merged = (rng[-1][0] + 1) // 2 + A[i] nonmerged = rng[-1][1] + A[i] rng.append([merged, nonmerged]) if rng[-1][0] > 1: print(-1) exit() rng.reverse() prev_non_leaf = 1 ans = 1 for i in range(1, N + 1): _, u = rng[i] ans += min(prev_non_leaf * 2, u) prev_non_leaf = prev_non_leaf * 2 - A[i] print(ans)
N, K = map(int, input().split()) A = list(map(int, input().split())) for i in range(N): if i < K: continue if A[i-K] < A[i]: print('Yes') else: print('No')
0
null
13,027,319,027,930
141
102
N, M, K = map(int, input().split()) MOD = 998244353 # 階乗 & 逆元計算 factorial = [1] inverse = [1] for i in range(1, N+2): factorial.append(factorial[-1] * i % MOD) inverse.append(pow(factorial[-1], MOD - 2, MOD)) # 組み合わせ計算 def nCr(n, r): if n < r or r < 0: return 0 elif r == 0: return 1 return factorial[n] * inverse[r] * inverse[n - r] % MOD ans = 0 for k in range(K + 1): ans += M * nCr(N - 1, k) * pow(M - 1, N - 1 - k, MOD) % MOD ans %= MOD print(ans % MOD)
MOD = 998244353 MAX = int(2e5 + 5) fact = [0] * MAX invFact = [0] * MAX def bigmod(a, b): if b == 0: return 1 ret = bigmod(a, b // 2) ret = (ret * ret) % MOD if b % 2 == 1: ret = (ret * a) % MOD return ret def mod_inverse(a): return bigmod(a, MOD - 2) def pre(): global fact, invFact fact[0] = 1 for i in range(1, MAX): fact[i] = (fact[i - 1] * i) % MOD invFact[MAX - 1] = mod_inverse(fact[MAX - 1]) for i in range(MAX - 2, -1, -1): invFact[i] = (invFact[i + 1] * (i + 1)) % MOD def ncr(nn, rr): if nn < 0 or nn < rr or rr < 0: return 0 return (fact[nn] * invFact[rr] * invFact[nn - rr]) % MOD pre() n, m, k = map(int, input().split()) ans = 0 for i in range(k + 1): ans = (ans + m * bigmod(m - 1, n - 1 - i) * ncr(n - 1, i) ) % MOD print(ans)
1
23,277,024,561,888
null
151
151
k = int(input()) a, b = list(map(int, input().split())) p = 0 while p <= 1000: if a <= p <= b: print("OK") exit() p += k print("NG")
K = int(input()) A, B = map(int, input().split()) if B // K * K >= A: print('OK') else: print('NG')
1
26,621,166,186,446
null
158
158
li = list(map(int,input().split())) n = 1 for i in li: if i == 0: print(n) n += 1
a = [x for x in range(1, 6)] b = [int(x) for x in input().split()] for i in range(5): if a[i] != b[i]: print(i+1)
1
13,479,106,910,620
null
126
126
import sys d = {} n = int(input()) for i in sys.stdin: q, c = i.split() if q == 'find': if c in d: print('yes') else: print('no') else: d[c] = True
n, m = [int(x) for x in raw_input().split()] c = [int(x) for x in raw_input().split()] INF = float("inf") dp = [INF for i in xrange(n + 1)] dp[0] = 0 for i in xrange(1, n + 1): for j in xrange(m): if c[j] <= i: dp[i] = min(dp[i], dp[i - c[j]] + 1) print dp[n]
0
null
111,677,843,470
23
28
H,W,K = list(map(int, input().split())) table = [input() for _ in range(H)] ans = 0 for mask_h in range(2 ** H): for mask_w in range(2 ** W): black = 0 for i in range(H): for j in range(W): if ((mask_h >> i) & 1 == 0) and ((mask_w >> j) & 1 == 0) and table[i][j] == '#': # 塗り潰し行、列ではなくて、色が黒'#'の場合 black += 1 if black == K: ans += 1 print(str(ans))
H,W,K=map(int,input().split()) c_map=[] for _ in range(H): c=input() c_map.append(c) ans=0 for i in range(2**H): for j in range(2**W): cnt=0 for k in range(H): for l in range(W): if c_map[k][l]=='#' and (i>>k)&1==0 and (j>>l)&1==0: cnt+=1 if cnt==K: ans+=1 print(ans)
1
8,958,386,628,776
null
110
110
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP1_7_B "How many ways?" ????§£?????? # import itertools while True: n, x = map(int, input().split()) if not n: break print(list(map(sum, itertools.combinations(range(1, n + 1), 3))).count(x))
while True: n,x = map(int,input().split()) if n == x == 0: break count = 0 for a in range(n+1): for b in range(1,a): for c in range(1,b): if a+b+c==x: count+=1 print(count)
1
1,297,574,408,042
null
58
58
n,a,b = map(int,input().split()) if n%(a+b)<=a: print(n//(a+b)*a+n%(a+b)) else: print(n//(a+b)*a+a)
# -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from collections import deque from functools import lru_cache import bisect import re import queue import decimal class Scanner(): @staticmethod def int(): return int(sys.stdin.readline().rstrip()) @staticmethod def string(): return sys.stdin.readline().rstrip() @staticmethod def map_int(): return [int(x) for x in Scanner.string().split()] @staticmethod def string_list(n): return [Scanner.string() for i in range(n)] @staticmethod def int_list_list(n): return [Scanner.map_int() for i in range(n)] @staticmethod def int_cols_list(n): return [Scanner.int() for i in range(n)] MOD = int(1e09) + 7 # INF = int(1e15) def solve(): MAX = 2 * 10 ** 5 + 10 fac = [0] * MAX inv = [0] * MAX finv = [0] * MAX fac[0] = fac[1] = finv[0] = finv[1] = inv[1] = 1 for i in range(2, MAX): fac[i] = fac[i - 1]*i % MOD inv[i] = MOD - inv[MOD % i] * (MOD // i) % MOD finv[i] = finv[i - 1] * inv[i] % MOD def cmb(n, k): if n < k: return 0 if n < 0 or k < 0: return 0 return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD N, K = Scanner.map_int() ans = 0 for i in range(min(N - 1, K) + 1): ans += cmb(N, i) * cmb(N - 1, i) ans %= MOD print(ans) def main(): # sys.setrecursionlimit(1000000) # sys.stdin = open("sample.txt") # T = Scanner.int() # for _ in range(T): # solve() # print('YNeos'[not solve()::2]) solve() if __name__ == "__main__": main()
0
null
61,404,172,537,288
202
215
import sys, bisect, math, itertools, string, queue, copy import numpy as np import scipy from collections import Counter,defaultdict,deque from itertools import permutations, combinations from heapq import heappop, heappush # input = sys.stdin.readline sys.setrecursionlimit(10**8) mod = 10**9+7 def inp(): return int(input()) def inpm(): return map(int,input().split()) def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(input()) for _ in range(n)) def inplL(n): return [list(input()) for _ in range(n)] def inplT(n): return [tuple(input()) for _ in range(n)] def inpll(n): return [list(map(int, input().split())) for _ in range(n)] def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) n,k = inpm() r,s,p = inpm() T = input() cnt_r = T.count('r') cnt_s = T.count('s') cnt_p = T.count('p') ans = cnt_r * p + cnt_s * r + cnt_p * s tmp = [0]*n for i in range(k,n): if tmp[i-k] == 1: continue if T[i] == T[i-k]: tmp[i] = 1 if T[i] == 'r': ans -= p elif T[i] == 's': ans -= r elif T[i] == 'p': ans -= s print(ans)
def bubbleSort(A, N): flag = 1 count = 0 while flag: flag = 0 for j in xrange(N-1,0,-1): if A[j] < A[j-1]: tmp = A[j] A[j] = A[j-1] A[j-1] = tmp flag += 1 count += 1 return A, count def newbubbleSort(A, N): flag = 1 count = 0 i = 0 while flag: flag = 0 for j in xrange(N-1,i,-1): if A[j] < A[j-1]: tmp = A[j] A[j] = A[j-1] A[j-1] = tmp flag += 1 count += 1 i += 1 return A, count def main(): N = int(raw_input()) A = map(int, raw_input().split()) new_A, count = newbubbleSort(A, N) print ' '.join(map(str,new_A)) print count if __name__ == "__main__": main()
0
null
53,186,034,409,860
251
14
N = int(input()) evidences = [[] for _ in range(N)] for i in range(N): A = int(input()) for _ in range(A): x, y = map(int, input().split()) evidences[i].append((x - 1, y)) ans = 0 for i in range(1, 2 ** N): consistent = True for j in range(N): if (i >> j) & 1 == 0: continue for x, y in evidences[j]: if (i >> x) & 1 != y: consistent = False break #if not consistent: #break if consistent: ans = max(ans, bin(i)[2:].count('1')) print(ans)
import sys import itertools read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) H,W = map(int,readline().split()) grid = '' grid += '#'* (W+2) for _ in range(H): grid += '#' + readline().decode().rstrip() + '#' grid += '#'*(W+2) L = len(grid) INF = float('inf') def bfs(start): dist = [-INF] * L q = [start] dist[start] = 0 while q: qq = [] for x,dx in itertools.product(q,[1,-1,W+2,-W-2]): y = x+dx if dist[y] != -INF or grid[y] == '#': continue dist[y] = dist[x] + 1 qq.append(y) q = qq return max(dist) ans = 0 for i in range(L): if grid[i] == '.': start = i max_dist = bfs(start) ans = max(ans,max_dist) print(ans)
0
null
108,508,497,508,710
262
241
import math a,b=map(int,input().split()) print(math.gcd(a,b))
import math pi=math.pi r = int(input().strip()) print(2*r*pi)
0
null
15,580,536,510,048
11
167
import sys #input = sys.stdin.buffer.readline #sys.setrecursionlimit(10**9) #from functools import lru_cache def RD(): return sys.stdin.read() def II(): return int(input()) def MI(): return map(int,input().split()) def MF(): return map(float,input().split()) def LI(): return list(map(int,input().split())) def LF(): return list(map(float,input().split())) def TI(): return tuple(map(int,input().split())) # rstrip().decode() #import numpy as np def main(): n=II() A=LI() B=[0]*(n+1) ans=1 B[0]=3 for i in range(n): ans*=(B[A[i]])-(B[A[i]+1]) ans%=10**9+7 B[A[i]+1]+=1 print(ans) if __name__ == "__main__": main()
n = int(input()) hats = list(map(int, input().split())) mod = 1000000007 cnt = [0] * 3 ans = 1 for i in range(n): count = 0 minj = 4 for j in range(3): if hats[i] == cnt[j]: count += 1 minj = min(minj, j) if count == 0: ans = 0 break cnt[minj] += 1 ans = ans * count % mod print(ans)
1
130,332,947,663,230
null
268
268
n,k = map(int,input().split()) a = [0]*n for _ in range(k): kind = int(input()) for i in list(map(int,input().split())): a[i-1] += 1 print(a.count(0) if 0 in a else 0)
N, K = map(int, input().split()) ans = [] for i in range(K): d = int(input()) ans += map(int, input().split()) print(N-len(set(ans)))
1
24,681,914,500,962
null
154
154
N,K=map(int,input().split()) R,S,P=map(int,input().split()) T=input() dp=[0]*N data={'r':P,'s':R,'p':S} ans=0 for i in range(N): if 0<=i-K: if T[i-K]==T[i]: if dp[i-K]==0: ans+=data[T[i]] dp[i]=1 else: ans+=data[T[i]] dp[i]=1 else: dp[i]=1 ans+=data[T[i]] print(ans)
n,k = list(map(int,input().split())) point = list(map(int,input().split())) rsp = ['r', 's', 'p'] t = input() m = [rsp[rsp.index(i)-1] for i in t] ans = 0 for i in range(n): if i<k : ans += point[rsp.index(m[i])] else: if m[i]!=m[i-k]: ans += point[rsp.index(m[i])] else: try: m[i] = rsp[rsp.index(m[i+k])-1] except: pass # print(ans) print(ans)
1
106,816,905,651,102
null
251
251
N = int(input()) hash = {} end = int(N ** (1/2)) for i in range(2, end + 1): while N % i == 0: hash[i] = hash.get(i, 0) + 1 N = N // i if N != 1: hash[i] = hash.get(i, 0) + 1 count = 1 res = 0 for i in hash.values(): count = 1 while i >= count: res += 1 i -= count count += 1 print(res)
import math # 素数か否かを判定する関数 def is_prime(n): for i in range(2, int(math.sqrt(n))+1): if n%i == 0: return False return True # nまでの素数を返す関数(エラトステネスの篩) def getPrime(n): n_sqrt = int(math.sqrt(n)) array = [True]*(n_sqrt+1) result = [] for i in range(2, n_sqrt+1): if array[i]: array[i] = False result.append(i) for j in range(i*2, n_sqrt+1, i): array[j] = False return result N = int(input()) n = N prime = getPrime(n) prime_exp = [] # print(prime) for p in prime: cnt = 0 while n%p == 0: n = int(n/p) # print(n) cnt += 1 if cnt != 0: prime_exp.append([p, cnt]) if is_prime(n) and n != 1: prime_exp.append([n, 1]) ans = 0 for pe in prime_exp: ans += int((-1+math.sqrt(1+8*pe[1]))/2) print(ans)
1
16,770,446,357,208
null
136
136
#!/usr/bin/env python3 from collections import Counter def solve(N: int, A: "List[int]", Q: int, BC: "List[(int,int)]"): A = Counter(A) answers = [] ans = ans = sum((i * n for i, n in A.items())) for b, c in BC: if b != c: ans += (c - b) * A[b] A[c] += A[b] del A[b] answers.append(ans) return answers def main(): N = int(input()) # type: int A = list(map(int, input().split())) Q = int(input()) BC = [tuple(map(int, input().split())) for _ in range(Q)] answer = solve(N, A, Q, BC) for ans in answer: print(ans) if __name__ == "__main__": main()
import bisect,collections,copy,itertools,math,string import sys def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def main(): n = I() suuretu = LI() q = I() dic = collections.Counter(suuretu) nowsum = sum(suuretu) for _ in range(q): b,c = LI() cnt = dic[b] nowsum += (c-b)*cnt print(nowsum) dic[b] = 0 dic[c] += cnt main()
1
12,118,876,289,094
null
122
122
L,R,d=map(int,input().split()) R_=R//d L_=(L-1)//d print(R_-L_)
import sys def I(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LMI(): return list(map(int, sys.stdin.readline().split())) MOD = 10 ** 9 + 7 a = [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] K = I() print(a[K -1 ])
0
null
28,656,687,859,040
104
195
N=int(input()) print(1000*(N%1000!=0)-N%1000)
n = int(input()) k = int((n/1000)+1)*1000 print(0 if n%1000 == 0 else (k-n))
1
8,424,849,342,700
null
108
108
n = int(input()) a = list(map(str, input().split())) a.reverse() for i in range(n): if i == n - 1: print(a[i], end='') else: print(a[i] + ' ', end='') print('')
in_string = input() in_arr = in_string.split() N = int(in_arr[0]) A = int(in_arr[1]) B = int(in_arr[2]) if ((B-A) % 2) == 0: print(int((B-A)//2)) else: if (N-B) > A-1: print(int(A+(B-A-1)//2)) else: print(int(N-B+1+((N-(A+N-B+1))//2)))
0
null
55,179,161,006,052
53
253
# -*- coding: utf-8 -*- n, m= [int(i) for i in input().split()] for i in range(0,m): if n-2*i-1>n/2 or n%2==1: print(i+1,n-i) else: print(i+1,n-i-1)
N,M = list(map(int,input().strip().split())) K = N//2 ans = [] if N == 3: ans = [(1,2)] elif N == 4: ans = [(1,2)] elif N == 5: ans = [(1,2),(3,5)] else: left = 1 right = K while left<right: ans += [(left,right)] left+=1 right-=1 left = K+1 right = N if (right-left)%2 == (K-1)%2: right -= 1 while left<right: ans += [(left,right)] left += 1 right -= 1 for i in range(M): print(ans[i][0],ans[i][1])
1
28,655,323,403,520
null
162
162
import sys, math from functools import lru_cache from collections import deque sys.setrecursionlimit(500000) MOD = 10**9+7 def input(): return sys.stdin.readline()[:-1] def mi(): return map(int, input().split()) def ii(): return int(input()) def i2(n): tmp = [list(mi()) for i in range(n)] return [list(i) for i in zip(*tmp)] def main(): S = input() for i in range(1, 6): if S == 'hi'*i: print('Yes') return print('No') if __name__ == '__main__': main()
#!/usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop from bisect import bisect_left, bisect_right import sys, random, itertools, math sys.setrecursionlimit(10**5) input = sys.stdin.readline sqrt = math.sqrt def LI(): return list(map(int, input().split())) def LF(): return list(map(float, input().split())) def LI_(): return list(map(lambda x: int(x)-1, input().split())) def II(): return int(input()) def IF(): return float(input()) def LS(): return input().split() def S(): return input().rstrip() def IR(n): return [II() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] def FR(n): return [IF() for _ in range(n)] def LFR(n): return [LI() for _ in range(n)] def LIR_(n): return [LI_() for _ in range(n)] def SR(n): return [S() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] mod = 1000000007 inf = 1e10 #solve def solve(): n = II() st = LSR(n) x = S() ans = 0 te = 0 for s, t in st: if te: ans += int(t) if s == x: te = 1 print(ans) return #main if __name__ == '__main__': solve()
0
null
75,117,449,226,300
199
243
cards = int(input()) i = 0 cardlist = [] while(i < cards): cardlist.append(list(map(str,input().split()))) i += 1 SP = [False] * 13 HR = [False] * 13 CL = [False] * 13 DY = [False] * 13 for i in cardlist: num = int(i[1])-1 if (i[0] == "S"): SP[num] = True elif(i[0] == "H"): HR[num] = True elif(i[0] == "C"): CL[num] = True elif(i[0] == "D"): DY[num] = True c = 0 for i in SP: c += 1 if i == False: print("S %d" %c) c = 0 for i in HR: c += 1 if i == False: print("H %d" %c) c = 0 for i in CL: c += 1 if i == False: print("C %d" %c) c = 0 for i in DY: c += 1 if i == False: print("D %d" %c)
x = int(input()) ans = 0 ans += 1000*(x//500) x %= 500 ans += 5*(x//5) print(ans)
0
null
22,034,690,997,968
54
185
N, *a = map(int, open(0).read().split()) print(sum(1 for e in a[::2] if e % 2 == 1))
# coding: utf-8 a , b = map(int,input().split()) c , d = map(int,input().split()) if a + 1 == c: print(1) else: print(0)
0
null
66,166,210,122,488
105
264
while True: m,f,r = map(int, raw_input().split()) s = m + f if m == -1 and f == -1 and r == -1: break elif m == -1 or f == -1 or s < 30: g=5 elif 30 <= s and s < 50: if r >= 50: g=2 else: g=3 elif 50 <= s and s < 65: g=2 elif 65 <= s and s < 80: g=1 else: g=0 print 'ABCDEF'[g]
import sys read = sys.stdin.buffer.read input = sys.stdin.buffer.readline inputs = sys.stdin.buffer.readlines import bisect n,m=map(int,input().split()) A=list(map(int,input().split())) A.sort() def hand(x): cnt=0 for i in range(n): p=x-A[i] cnt+=n-bisect.bisect_left(A,p) return cnt def main(): l=0 h=2*10**5+1 mid=(l+h)//2 while l+1<h: mid=(l+h)//2 if hand(mid)<m: h=mid else: l=mid B=A[::-1] for i in range(n-1): B[i+1]+=B[i] B=B[::-1] ans=0 cnt=0 for i in range(n): y=l-A[i]+1 index=bisect.bisect_left(A,y) if n==index: continue else: ans+=(n-index)*A[i]+B[index] cnt+=(n-index) ans+=(m-cnt)*l print(ans) if __name__ == "__main__": main()
0
null
54,935,444,378,778
57
252
def main(): abcd = [int(_x) for _x in input().split()] a = abcd[0] b = abcd[1] c = abcd[2] d = abcd[3] while True: c = c - b if c <= 0: print("Yes") return a = a - d if a <= 0: print("No") return main()
d_pre=input().split() d=[int(s) for s in d_pre] A=d[0] B=d[1] C=d[2] D=d[3] for i in range(210): if i%2==0: C-=B if C<=0: print("Yes") break else: A-=D if A<=0: print("No") break
1
29,719,499,856,420
null
164
164
x = input() n = int(x)*int(x)*int(x) print(n)
while True: data=map(str,raw_input()) if data==['-']: break for _ in xrange(input()): index=input() data=data[index:]+data[:index] print "".join(map(str,data))
0
null
1,084,190,525,142
35
66
INF = 10**18 N,M = map(int,input().split()) C = list(map(int,input().split())) dp = [INF for _ in range(N+1)] dp[0] = 0 for i in range(M): for j in range(N+1): if j-C[i] >= 0: dp[j] = min(dp[j],dp[j-C[i]]+1) print(dp[N])
n, m = map(int, input().split()) c = list(map(int, input().split())) INF = float("inf") dp = [INF]*(n+1) dp[0] = 0 for i in range(m): for j in range(n+1): if j + c[i] > n: break else: dp[j + c[i]] = min(dp[j + c[i]], dp[j] + 1) print(dp[n])
1
139,666,680,992
null
28
28
#coding: utf-8 s = input() p = input() for i in range(len(s)): s = s[1:] + s[0:1] if s.find(p) != -1: print("Yes") exit() print("No")
s=input()*3 if s.find(input()) == -1 : print('No') else: print('Yes')
1
1,732,682,579,108
null
64
64
n,q = map(int,input().split()) name = [] time = [] for i in range(n): tmp = input().split() name.append(str(tmp[0])) time.append(int(tmp[1])) total = 0 result = [] while True: try: if time[0] > q: total += q time[0] = time[0] - q tmp = time.pop(0) time.append(tmp) tmp = name.pop(0) name.append(tmp) elif q >= time[0] and time[0] > 0: total += time[0] time.pop(0) a = name.pop(0) print(a,total) else: break except: break
H, W = map(int, input().split()) grid = [input() for _ in range(H)] inf = 10**18 # dp[i][j]はi.j点に行くまでに何回白→黒の変化があったか dp = [[inf] * W for _ in range(H)] if grid[0][0] == "#": dp[0][0] = 1 else: dp[0][0] = 0 for i in range(H): for j in range(W): if i != 0: # 下移動 # 今いてるのがi,j点、前の点(上)が白で次が黒なら1足す tmp = dp[i - 1][j] + int(grid[i][j]=="#" and grid[i - 1][j]==".") dp[i][j] = min(dp[i][j], tmp) if j != 0: # 右移動 # 前の点(左)が白で次が黒なら1足す tmp = dp[i][j - 1] + int(grid[i][j]=="#" and grid[i][j - 1]==".") dp[i][j] = min(dp[i][j], tmp) # この一連の処理で、i,j点に、下移動した場合と右移動した場合のうちの最小値が得られる。 # こたえは目的地, i.e. 右下の点のdpの値 ans = dp[H - 1][W - 1] print(ans)
0
null
24,779,792,021,668
19
194
n=int(input()) s=100000 for i in range(n): s=s*1.05 if s%1000==0: s=s else: s=(s//1000)*1000+1000 print(int(s))
H,W=map(int,input().split()) s=[] dp=[[10**9]*W for _ in range(H)] dp[0][0]=0 for _ in range(H): s.append(list(input())) for i in range(H): for j in range(W): if j!=W-1: if s[i][j]=="." and s[i][j+1]=="#": dp[i][j+1]=min(dp[i][j]+1,dp[i][j+1]) else: dp[i][j+1]=min(dp[i][j],dp[i][j+1]) if i!=H-1: if s[i][j]=="." and s[i+1][j]=="#": dp[i+1][j]=min(dp[i][j]+1,dp[i+1][j]) else: dp[i+1][j]=min(dp[i][j],dp[i+1][j]) ans=dp[H-1][W-1] if s[0][0]=="#": ans+=1 print(ans)
0
null
24,736,804,285,920
6
194
import sys input = lambda: sys.stdin.readline().rstrip() def main(): n, k = map(int, input().split()) nums = [i for i in range(n+1)] sums = [0] ans = 0 x = 10**9 + 7 for i in range(n): sums.append(nums[i+1]+sums[i]) for j in range(k, len(nums)+1): if j == len(nums): ans += 1 else: ans += sums[-1] - sums[-(1+j)] - sums[j-1] + 1 print(ans%x) if __name__ == '__main__': main()
import math , sys, bisect N , M , K = list( map( int , input().split() )) A = list( map( int , input().split() )) B = list( map( int , input().split() )) if N > M: N , M = M , N A, B = B , A Asum=[0] Bsum=[] if A[0] > K and B[0] > K: print(0) sys.exit() for i in range(N): if i ==0: tot = A[i] else: tot += A[i] Asum.append(tot) for i in range(M): if i ==0: tot = B[i] else: tot += B[i] Bsum.append(tot) #ans=bisect.bisect(Bsum,K) ans=0 for i in range(N+1): tot = Asum[i] if tot > K: print(ans) sys.exit() num = bisect.bisect(Bsum,K-tot) if i + num >ans: ans=i+num print(ans)
0
null
21,751,148,697,568
170
117
K,N = map(int,input().split()) l1 = list(map(int,input().split())) l2 = [l1[i]-l1[i-1] for i in range(len(l1))] l2[0] = l1[0] + K - l1[-1] l2.sort() ans = 0 for i in range(N-1): ans += l2[i] print(ans)
K, N = map(int, input().split()) A = list(map(int, input().split())) dists = [] for i in range(N): if i==N-1: dists.append(K-A[N-1]+A[0]) else: dists.append(A[i+1]-A[i]) print(K-max(dists))
1
43,596,626,734,518
null
186
186
from math import * print(gcd(*map(int, input().split())))
num = [] while True: m,f,r = map(int, raw_input().split()) ans = m + f if m == f == r == -1: break if (m == -1) or (f == -1): num.append("F") elif ans >= 80: num.append("A") elif (65 <= ans) and (ans < 80): num.append("B") elif (50 <= ans) and (ans < 65): num.append("C") elif (30 <= ans) and (ans < 50): if r >= 50: num.append("C") else: num.append("D") else: num.append("F") for i in range(len(num)): print num[i]
0
null
602,042,518,726
11
57
a=int(input()) if a/2==int(a/2): print(int(a/2)) else: print(int(a/2)+1)
N = int(input()) N += 1 print(N // 2)
1
59,076,105,271,680
null
206
206
x,y,a,b,c=[int(i) for i in input().split()] p=[int(i) for i in input().split()] q=[int(i) for i in input().split()] r=[int(i) for i in input().split()] p.sort() q.sort() r.sort() p=p[-x:] q=q[-y:] ans=p+q+r ans.sort() ans=ans[-x-y:] print(sum(ans))
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 #mod = 998244353 from decimal import * #import numpy as np #decimal.getcontext().prec = 10 X, Y, A, B, C = MAP() p = deque(sorted(LIST(), reverse=True)) q = deque(sorted(LIST(), reverse=True)) r = deque(sorted(LIST(), reverse=True) + [0]) x = 0 y = 0 z = 0 ans = 0 while x+y+z < X+Y: compare = (p[0], q[0], r[0]) if p[0] == max(compare): x += 1 ans += p.popleft() if x == X: p = [0] elif q[0] == max(compare): y += 1 ans += q.popleft() if y == Y: q = [0] else: z += 1 ans += r.popleft() print(ans)
1
44,782,412,168,480
null
188
188
not_ans = [] not_ans.append(int(input())) not_ans.append(int(input())) for i in range(1, 4): if i not in not_ans: print(i)
def main(): a = int(input()) b = int(input()) print(6 - a - b) if __name__ == "__main__": main()
1
110,625,749,881,020
null
254
254
n,m = map(int, input().split()) a = [[] for x in range(0, n)] b = [0 for x in range(0, m)] for x in range(0, n): a[x] = list(map(int, input().split())) for x in range(0, m): b[x] = int(input()) for i in range(0, n): c = 0 for j in range(0, m): c += a[i][j] * b[j] print(c)
n, m = map(int, input().split()) A = [input().split() for _ in range(n)] b = [input()for _ in range(m)] for a in A: print(sum(int(x)*int(y) for x, y in zip(a,b)))
1
1,136,357,310,370
null
56
56
from collections import deque n,x,y = map(int,input().split()) adj = [[] for i in range(n)] adj[x-1].append(y-1) adj[y-1].append(x-1) for i in range(n-1): adj[i].append(i+1) adj[i+1].append(i) ans = [0]*(n-1) for i in range(n): q = deque([]) q.append(i) dist = [-1]*n dist[i] = 0 while len(q) > 0: v = q.popleft() for nv in adj[v]: if dist[nv] != -1: continue dist[nv] = dist[v] + 1 q.append(nv) for i in dist: if i != 0: ans[i-1] += 1 for i in ans: print(i//2)
n = int(input()) a = {} for i in range(n): x,m = input().split() if x[0] =='i':a[m] = 0 else: if m in a: print('yes') else: print('no')
0
null
22,094,604,590,490
187
23
while 1: w,h=map(int,input().split()) if w==0 and h==0: break for a in range(w): print('#'*h) print()
while True: H, W = [int(i) for i in input().split()] if H ==0 and W ==0: break for i in range(0, H): print('#'*W) print()
1
780,837,947,450
null
49
49
temp = input() n = int(input()) for _ in range(n): order,a,b,*value = input().split() a = int(a) b = int(b) if order == "print": print(temp[a:b+1]) elif order == "reverse": rev = temp[a:b+1] temp = temp[:a] + rev[::-1] + temp[b+1:] else:#replace temp = temp[:a] + value[0] + temp[b+1:]
string = input() q = int(input()) for i in range(q): order = list(input().split()) a, b = int(order[1]), int(order[2]) if order[0] == "print": print(string[a:b+1]) elif order[0] == "reverse": string = string[:a] + (string[a:b+1])[::-1] + string[b+1:] else: string = string[:a] + order[3] + string[b+1:]
1
2,102,229,412,430
null
68
68
def main(): N, K = input_ints() A = input_int_list_in_line() for i in range(N-K): if A[i] < A[i+K]: print('Yes') else: print('No') def input_ints(): line_list = input().split() if len(line_list) == 1: return int(line_list[0]) else: return map(int, line_list) def input_int_list_in_line(): return list(map(int, input().split())) def input_int_tuple_list(n: int): return [tuple(map(int, input().split())) for _ in range(n)] main()
N, K = map(int, input().split()) As = list(map(int, input().split())) for i in range(K, N): if As[i]/As[i-K]>1: print("Yes") else: print("No")
1
7,098,410,249,520
null
102
102
def main(): n, m = map(int, input().split()) # nは偶数、mは奇数 # n+mから2つ選ぶ選び方は # n:m = 0:2 和は 偶数、選び方はmC2 # n:m = 1:1 和は 奇数 (今回はこれは含めない) # n:m = 2:0 和は 偶数、選び方はnC2 cnt = 0 if m >= 2: cnt += m * (m -1) // 2 if n >=2: cnt += n * (n -1) // 2 print(cnt) if __name__ == '__main__': main()
def mitsui2019d_lucky_pin(): import itertools n = int(input()) s = input() cnt = 0 for t in itertools.product(range(0, 10), repeat=2): si = ''.join(map(str,t)) for i in range(n - 2): if si[0] != s[i]: continue for j in range(i + 1, n - 1): if si[1] != s[j]: continue ss = set(list(s[j+1:])) cnt += len(ss) break break print(cnt) mitsui2019d_lucky_pin()
0
null
86,585,977,930,660
189
267
n=int(input()) a=list(map(int,input().split())) col=[0,0,0] res=1 for ai in a: cnt=0 for i in range(3): if col[i]==ai: if cnt==0: col[i]=col[i]+1 cnt+=1 res=(res*cnt)%1000000007 print(res)
n = int(input()) A=[int(i) for i in input().split()] MOD = 1000000007 ans = 1 cnt = [0]*(n+1) cnt[0]=3 for i in range(n): ans = ans * cnt[A[i]] %MOD cnt[A[i]]-=1 cnt[A[i]+1]+=1 if ans==0: break print(ans)
1
130,391,188,852,330
null
268
268
from math import cos, sin, pi class Coordinate: def __init__(self, x, y): self.x = x self.y = y def kock(n, p1, p2): if n == 0: return s = Coordinate((2*p1.x+p2.x)/3, (2*p1.y+p2.y)/3) t = Coordinate((p1.x+2*p2.x)/3, (p1.y+2*p2.y)/3) ux = (t.x-s.x)*cos(pi/3) - (t.y-s.y)*sin(pi/3) + s.x uy = (t.x-s.x)*sin(pi/3) + (t.y-s.y)*cos(pi/3) + s.y u = Coordinate(ux, uy) kock(n-1, p1, s) print("%f %f"%(s.x, s.y)) kock(n-1, s, u) print("%f %f"%(u.x, u.y)) kock(n-1, u, t) print("%f %f"%(t.x, t.y)) kock(n-1, t, p2) n = int(input()) p1 = Coordinate(0, 0) p2 = Coordinate(100, 0) print("%f %f"%(p1.x, p2.y)) kock(n, p1, p2) print("%f %f"%(p2.x, p2.y))
import sys input = sys.stdin.readline n, m = [int(x) for x in input().split()] s = input().rstrip()[::-1] ans = [] left, right = 0, 0 + m while True: if right >= n: ans.append(n - left) break for i in range(right, left, -1): flag = 1 if s[i] == "0": ans.append(i - left) flag = 0 break if flag: print(-1) sys.exit() else: left = i right = left + m print(*ans[::-1])
0
null
69,829,234,117,212
27
274
class Dice(): def __init__(self,ary): self.top = ary[0] self.south = ary[1] self.east = ary[2] self.west = ary[3] self.north = ary[4] self.bottom = ary[5] def get_top(self): return self.top def rotate_north(self): self.top,self.south,self.north,self.bottom = self.south,self.bottom,self.top,self.north def rotate_south(self): self.top,self.south,self.north,self.bottom = self.north,self.top,self.bottom,self.south def rotate_west(self): self.top,self.west,self.bottom,self.east = self.east,self.top,self.west,self.bottom def rotate_east(self): self.top,self.west,self.bottom,self.east = self.west,self.bottom,self.east,self.top dice = Dice(list(map(int,input().split()))) for i in input(): if i == "N": dice.rotate_north() elif i == "E": dice.rotate_east() elif i == "W": dice.rotate_west() elif i == "S": dice.rotate_south() top=dice.get_top() print(top)
from math import sqrt from math import floor n = int(input()) ans = 10 ** 12 m = floor(sqrt(n)) for i in range(1,m+1): if n % i == 0: j = n // i ans = min(ans,i+j-2) print(ans)
0
null
81,189,681,801,228
33
288
n, p = (int(i) for i in input().split()); s = input(); if p == 2 or p == 5: res = 0; for i in range(len(s)): if int(s[i]) % p == 0: res += i + 1; print(res); exit(0); h = [0 for i in range(len(s) + 1)]; st = 1; for i in range(len(s) - 1,-1,-1): #print(i); h[i] = (st * int(s[i]) + h[i + 1]) % p; st = (st * 10) % p; #print(h); h.sort(); #print(h); i = 0; res = 0; while i <= n: j = i; while j + 1 <= n and h[i] == h[j + 1]: j += 1; l = j - i + 1; res += (l * (l - 1)) // 2; i = j + 1; print(res);
s = [i for i in input()] if s[2] == s[3] and s[4] == s[5]: print('Yes') else: print('No')
0
null
50,042,322,272,802
205
184
N, M = map(int, input().split()) totalN = 1/2*(N-1)*N totalM = 1/2*(M-1)*M import math print(math.floor(totalN + totalM))
n,m = input().split() n = int(n) m = int(m) print(int(n*(n-1)/2+m*(m-1)/2))
1
45,718,584,623,222
null
189
189
n,a,b = map(int,input().split()) if (a % 2 + b % 2) % 2 == 0: print(abs(a - b) // 2) exit(0) if n - b < a - 1: p = n - b + 1 a += n - b b = n print(abs(a - b) // 2 + p) else: p = a - 1 + 1 b -= a - 1 a = 1 print(abs(a - b) // 2 + p)
N, A, B = map(int, input().split()) d = B-A if d%2 == 1: d = min((B + (N-B)*2 + 1) - A, B - (A - (A-1)*2 - 1)) ans = d//2 print(ans)
1
109,441,230,861,570
null
253
253
n = int(input()) ls = list(map(int, input().split())) rsw = [0]*1005 for i in ls: rsw[i] += 1 for i in range(1,1005): rsw[i] = rsw[i-1] + rsw[i] res = 0 for i in range(n): for j in range(i+1,n): a = ls[i] b = ls[j] low = abs(a-b) high = a+b tmp = rsw[min(high,1004)-1] - rsw[low] if low < a < high: tmp -= 1 if low < b < high: tmp -= 1 res += tmp print(res//3)
from bisect import bisect_left n = int(input()) l = list(map(int, input().split())) l.sort() ans = 0 for i in range(n): for j in range(i + 1, n): k = l[i] + l[j] pos = bisect_left(l, k) ans += max(0, pos - j - 1) print(ans)
1
172,174,847,091,580
null
294
294
x = input() print(int(x)*int(x)*int(x))
import sys x = int(raw_input()) print(x*x*x)
1
272,148,880,644
null
35
35
from itertools import accumulate N, K = list(map(int, input().split())) P = list(map(lambda x: int(x) + 1, input().split())) P_cumsum = [0] + list(accumulate(P)) print(max([P_cumsum[i+K]-P_cumsum[i] for i in range(N-K+1)])/2)
import copy n, k = map(int, input().split()) P = list(map(int, input().split())) U = [0]*n for i in range(n): U[i] = (P[i]+1)/2 ans = sum(U[:k]) t = copy.copy(ans) for i in range(n-k): t = t+U[k+i]-U[i] ans = max(ans, t) print(ans)
1
74,855,275,953,600
null
223
223
N,K = map(int,input().split()) import numpy as np A = np.array(input().split(),np.int64) B = np.array(input().split(),np.int64) A.sort() ; B.sort() B=B[::-1] right = max(A*B) #時間の可能集合の端点 left = -1 #時間の不可能集合の端点 def test(t): C = A-t//B D= np.where(C<0,0,C) return D.sum()<=K while left+1<right: mid = (left+right)//2 if test(mid): right=mid else: left = mid print(right)
(tate, yoko) = [int(x) for x in input().rstrip().split(' ')] square = tate * yoko length = (int(tate) + int(yoko)) * 2 print(square, length)
0
null
82,552,782,064,522
290
36
n, m, l = map(int, raw_input().split()) A = [map(int, raw_input().split()) for i in xrange(n)] B = [map(int, raw_input().split()) for i in xrange(m)] C = [[0] * l for i in xrange(n)] for i in xrange(n): for j in xrange(l): C[i][j] = sum(A[i][k] * B[k][j] for k in xrange(m)) for c in C: print " ".join(map(str, c))
n, m, l = [int(i) for i in input().split()] A = [] B = [] C = [] for ni in range(n): A.append([int(i) for i in input().split()]) for mi in range(m): B.append([int(i) for i in input().split()]) for i in range(n): C.append([]) for j in range(l): C[i].append(0) for k in range(m): C[i][j] += A[i][k] * B[k][j] for li in range(n): print(" ".join([str(s) for s in C[li]]))
1
1,420,942,296,238
null
60
60
# A - Sum of Two Integers N = int(input()) if N % 2 == 1: N += 1 print(int(N / 2 - 1))
import sys from sys import stdin def I(): return stdin.readline().rstrip() def MI(): return map(int,stdin.readline().rstrip().split()) def LI(): return list(map(int,stdin.readline().rstrip().split())) #main part from collections import deque n, m =MI() ans = [-1 for _ in range(n+1)] ans[0] = 0 ans[1] = 0 V = [[] for _ in range(n+1)] for _ in range(m): x, y = MI() V[x].append(y) V[y].append(x) d = deque([1]) while d: l = d.popleft() for v in V[l]: if ans[v] != -1: continue ans[v] = l d.append(v) if ans.count(-1) > 0: print('No') else : print('Yes') for i in ans[2:]: print(i)
0
null
87,251,846,165,692
283
145