code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
2
178,025B
question_pair_id
float64
27.1M
177,113B
code1_group
int64
1
297
code2_group
int64
1
297
# import bisect # from collections import Counter, defaultdict, deque # import copy # from heapq import heappush, heappop, heapify # from fractions import gcd # import itertools # from operator import attrgetter, itemgetter # import math import sys # import numpy as np ipti = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): x, y = list(map(int,ipti().split())) prize = [300000, 200000, 100000, 0] if x == y == 1: print(1000000) else: x = 4 if x > 3 else x y = 4 if y > 3 else y print(prize[x-1]+prize[y-1]) if __name__ == '__main__': main()
x, y = map(int, input().split()) ans = 4 if x == 1 and y == 1 else 0 ans += max(0, 4-x)+max(0, 4-y) print(ans*100000)
1
140,966,765,621,240
null
275
275
import sys def input(): return sys.stdin.readline().strip() def resolve(): s=input() ls=len(s) a=[0]*(ls+1) for i in range(ls): if s[i]=='<': a[i+1]=a[i]+1 for j in reversed(range(ls)): if s[j]=='>': a[j]=max(a[j+1]+1,a[j]) print(sum(a)) resolve()
s = input().strip() buf = s[0] count = 0 popa = [] suma = 0 for i in s: if i=="<": count+=1 suma += count elif i==">" and buf=="<": popa.append(count) suma -= count count = 0 buf = i buf = s[-1] count = 0 dupa = [] for i in s[::-1]: if i==">": count+=1 suma += count elif i=="<" and buf==">": dupa.append(count) suma -= count count = 0 buf = i for i,j in zip(dupa[::-1],popa): suma+=max(i,j) print(suma) # print(sum(map(int,"0 3 2 1 0 1 2 0 1 2 3 4 5 2 1 0 1".split())))
1
156,366,338,916,880
null
285
285
N = int(input()) a = list(map(int,input().split())) aset = set(a) if 1 not in aset: print(-1) else: nex = 1 counter = 0 for i in range(N): if a[i] == nex: nex += 1 else: counter += 1 print(counter)
n=int(input()) p=list(map(int,input().split())) sai = p[0] answer = 1 for i in range(1,n): if p[i-1]<=sai: sai=p[i-1] if sai >= p[i]: answer = answer + 1 print(answer)
0
null
99,845,161,629,400
257
233
MOD = 10**9+7 N,K = map(int, input().split()) A = list(map(int, input().split())) A.sort(reverse = True) ans = 1 if A[-1] >= 0: for i in range(K): ans *= A[i] ans %= MOD elif A[0] < 0: if K % 2 == 0: for i in range(K): ans *= A[N-1-i] ans %= MOD else: for i in range(K): ans *= A[i] ans %= MOD else: r,l = N-1,0 n = 0 while n < K: if K-n == 1: ans *= A[l] ans %= MOD n += 1 else: if A[r]*A[r-1] > A[l]*A[l+1]: ans *= (A[r]*A[r-1]) ans %= MOD r -= 2 n += 2 else: ans *= A[l] ans %= MOD l += 1 n += 1 print(ans)
MOD = (10 ** 9) + 7 n, k = map(int, input().split()) a = list(map(int, input().split())) negs = [-x for x in a if x < 0] non_negs = [x for x in a if x >= 0] if len(non_negs) == 0 and k % 2 == 1: negs.sort() ans = 1 for i in range(k): ans = ans * -negs[i] % MOD print(ans) exit() negs_p, non_negs_p = 0, 0 negs.sort(reverse = True) non_negs.sort(reverse = True) for i in range(k): if negs_p == len(negs): non_negs_p += 1 elif non_negs_p == len(non_negs): negs_p += 1 elif negs[negs_p] > non_negs[non_negs_p]: negs_p += 1 else: non_negs_p += 1 if negs_p % 2 == 0 or k == n: ans = 1 for i in range(negs_p): ans = ans * -negs[i] % MOD for i in range(non_negs_p): ans = ans * non_negs[i] % MOD print(ans) exit() if negs_p == len(negs) or non_negs_p == 0: negs_p -= 1 non_negs_p += 1 ans = 1 for i in range(negs_p): ans = ans * -negs[i] % MOD for i in range(non_negs_p): ans = ans * non_negs[i] % MOD print(ans) exit() if non_negs_p == len(non_negs) or negs_p == 0: negs_p += 1 non_negs_p -= 1 ans = 1 for i in range(negs_p): ans = ans * -negs[i] % MOD for i in range(non_negs_p): ans = ans * non_negs[i] % MOD print(ans) exit() a = negs[negs_p - 1] b = negs[negs_p] c = non_negs[non_negs_p - 1] d = non_negs[non_negs_p] if a * b > c * d: negs_p += 1 non_negs_p -= 1 else: negs_p -= 1 non_negs_p += 1 ans = 1 for i in range(negs_p): ans = ans * -negs[i] % MOD for i in range(non_negs_p): ans = ans * non_negs[i] % MOD print(ans)
1
9,499,454,634,758
null
112
112
n,k=map(int,input().split()) l=[i for i in range(1,k+1)][::-1] mod=10**9+7 m=[0]*(k+1) for i in l: a=k//i m[i]=pow(a,n,mod) for j in range(i*2,k+1,i): m[i]-=m[j] ans=0 for i in range(k+1): ans+=m[i]*i ans%=mod print(ans%mod)
import sys N,M=map(int,input().split()) S=input() lst=[] koma=N rs=0 ME=0 pn=0 while koma>0 and pn==0: rs+=1 if int(S[koma-rs])==0: ME=rs if koma-rs==0 or rs==M: lst.append(ME) if ME==0: pn+=1 koma-=ME rs=rs-ME ME=0 if pn>0: print(-1) else: lst.reverse() print(*lst)
0
null
88,318,026,819,936
176
274
n, k = list(map(int, input().split())) enemy = list(map(int, input().split())) enemy = sorted(enemy, reverse=True) enemy = enemy[k:] print(sum(enemy))
#!/usr/bin/env python3 # -*- coding: utf-8 -*- def update(x): y = x * 105 // 100 r = y % 1000 y = y // 1000 * 1000 if r: y += 1000 return y def main(): n = int(input()) x = 100000 for _ in range(n): x = update(x) print(x) if __name__ == "__main__": main()
0
null
39,655,893,844,294
227
6
N, M, K = map(int, input().split()) mod = 998244353 facm = 200500 fac = [1] * facm facinv = [1] * facm for i in range(facm-1): fac[i+1] = (fac[i] * (i + 1)) % mod facinv[i+1] = (facinv[i] * pow(i+1, -1, mod)) % mod def nCk(n, k): return (fac[n] * facinv[k] * facinv[n-k]) % mod ans = 0 for i in range(K+1): ans = (ans + nCk(N-1, i) * pow(M-1, N-i-1, mod) * M) % mod print(ans)
# coding: UTF-8 #共通関数と演算 def pprint(numlist): print(" ".join(map(str,numlist))) def greater(s,t): if s[1] > t[1]: return True else: return False def equal(s,t): if s[1] == t[1]: return True else: return False def wasStable(Ans,Initial,N): I = Initial.copy() for i in range(N-1): if equal(Ans[i],Ans[i+1]): for x in I: if equal(Ans[i],x): if(Ans[i][0] != x[0]): return False else: I.remove(x) break return True #input N = int(input()) A = input().split() Initial = A.copy() B = A.copy() #バブルソート count = 0 flag = True while flag: flag = False j = N - 1 while j >= 1: if greater(A[j-1],A[j]): v = A[j] A[j] = A[j-1] A[j-1] = v flag = True count += 1 j -= 1 pprint(A) print("Stable") #選択ソート count = 0 for i in range(N): j=i minj=i while j<= N-1: if greater(B[minj],B[j]): minj = j j += 1 if i != minj: v=B[i] B[i]=B[minj] B[minj]=v count += 1 print(" ".join(map(str,B))) if wasStable(B,Initial,N): ans = "Stable" else: ans = "Not stable" print(ans)
0
null
11,670,083,397,558
151
16
N, M = map(int, input().split()) H = list(map(int, input().split())) ans = M counted = [] appeared = set() for i in range(M): a, b = map(int, input().split()) if H[a-1] < H[b-1]: appeared.add(a) elif H[a-1] > H[b-1]: appeared.add(b) else: appeared.add(a) appeared.add(b) ans = len(H) - len(appeared) print(ans)
n,m = map(int, input().split()) h = list(map(int, input().split())) l = [1]*n for i in range(m): a,b = map(int, input().split()) if h[a - 1] <= h[b - 1]: l[a - 1] = 0 if h[b - 1] <= h[a - 1]: l[b - 1] = 0 print(sum(l))
1
24,996,999,214,262
null
155
155
# import bisect from collections import Counter, deque # import copy # from heapq import heappush, heappop, heapify # from fractions import gcd # import itertools # from operator import attrgetter, itemgetter # import math import sys # import numpy as np ipti = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): h, w, k = list(map(int,ipti().split())) s = [list(input()) for i in range(h)] empty_row = [] exist_row = [] berry_id = 1 for row in range(h): is_empty = True for col in range(w): if s[row][col] == "#": s[row][col] = berry_id berry_id += 1 is_empty = False if is_empty: empty_row.append(row) else: exist_row.append(row) # まず空ではない行を埋める for row in range(h): if row in exist_row: berry_col = deque() for col in range(w): if s[row][col] != ".": berry_col.append(col) first = 0 fill_id = 0 while berry_col: last = berry_col.popleft() fill_id = s[row][last] for j in range(first, last+1): s[row][j] =fill_id first = last + 1 for j in range(first, w): s[row][j] = fill_id for row in empty_row: is_filled = False for row2 in range(row+1, h): if row2 in exist_row: for col in range(w): s[row][col] = s[row2][col] is_filled = True break if not is_filled: for row2 in range(row-1, -1 , -1): if row2 in exist_row: for col in range(w): s[row][col] = s[row2][col] is_filled = True break for row in range(h): print(*s[row]) if __name__ == '__main__': main()
h, w, k = map(int, input().split()) s = [list(input()) for _ in range(h)] g = 1 for i in range(h): for j in range(w): if s[i][j] != '#': continue s[i][j] = g k = j - 1 while k >= 0 and s[i][k]=='.': s[i][k] = g k -= 1 k = j + 1 while k < w and s[i][k] == '.': s[i][k] = g k += 1 g += 1 for i in range(h - 2)[::-1]: if s[i][0]=='.': for j in range(w): s[i][j] = s[i + 1][j] for i in range(h): if s[i][0] == '.': for j in range(w): s[i][j] = s[i - 1][j] for t in s: print(*t)
1
143,386,653,469,290
null
277
277
while True: cou = 0 n,x = map(int,input().split()) if n==0 and x==0: break for i in range(1,x//2): for j in range(i+1,x//2): k = x - i - j if i<=n and j<=n and k<=n and k>j: cou += 1 print(cou)
ret = [] while True: n, x = map(int, raw_input().split()) num_arr = [i for i in range(1, n+1)] if (n, x) == (0, 0): break cnt = 0 for i in range(len(num_arr)): for j in range(i + 1, len(num_arr)): k_flg = False for k in range(j + 1, len(num_arr)): work = num_arr[i] + num_arr[j] + num_arr[k] if x == work: cnt += 1 k_flg = True break ret += [cnt] for i in ret: print i
1
1,282,571,809,734
null
58
58
l=list(map(int,input().split())) k,x=l[0],l[1] if (k*500)>=x: print('Yes') else: print('No')
#1??????????????? num_data = int(input()) for i in range(num_data): input_line = input().split(" ") a = int(input_line[0]) b = int(input_line[1]) c = int(input_line[2]) #?????????????????????????????????????????§ if (pow(a,2) + pow(b,2) == pow(c,2) ) or (pow(a,2) + pow(c,2) == pow(b,2) ) or (pow(b,2) + pow(c,2) == pow(a,2)): print("YES") else: print("NO")
0
null
49,338,091,011,930
244
4
N, M =map(int, input().split()) H=list(map(int, input().split())) A=[True]*N for i in range(M): a, b = map(int, input().split()) if H[a-1]>H[b-1]: A[b-1]=False elif H[a-1]==H[b-1]: A[a-1]=False A[b-1]=False elif H[a-1]<H[b-1]: A[a-1]=False print(sum(A))
import sys import time import math import itertools as it def inpl(): return list(map(int, input().split())) st = time.perf_counter() # ------------------------------ N, M = inpl() H = inpl() dp = [True] * N for _ in range(M): A, B = inpl() if H[A-1] > H[B-1]: dp[B-1] = False elif H[A-1] < H[B-1]: dp[A-1] = False else: dp[A-1] = False dp[B-1] = False ans = 0 for i in dp: if i: ans += 1 print(ans) # ------------------------------ ed = time.perf_counter() print('time:', ed-st, file=sys.stderr)
1
25,129,715,298,592
null
155
155
n = int(input()) out = '' for i in range(3,n+1): if i % 3 == 0: out += ' {0}'.format(i) continue elif i % 10 == 3: out += ' {0}'.format(i) continue n = i while n // 10: n = n // 10 if n % 10 == 3: out += ' {0}'.format(i) n = 0 print(out)
import sys def LI(): return list(map(int, sys.stdin.buffer.readline().split())) def I(): return int(sys.stdin.buffer.readline()) def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split() def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8') def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] def SRL(n): return [list(S()) for i in range(n)] def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)] mod = 10 ** 9 + 7 k, n = LI() a = LI() # 一周kメートルの円形湖があり、n軒の家がある。 # i番目のいえは北端から時計回りにAメートルのところにある。 # いずれかの家から出発してn件すべての家に尋ねるための最短移動距離を求めよ # 円形で考えるからややこしい # 一番距離が長い家と家の区間を除外した直線状と考えればよいのでは。 far = [] for i in range(0,n): if i == 0: d = a[0] + k - a[-1] else: d = a[i] - a[i-1] far.append(d) longest = 0 for i in range(n): if far[i] > longest: longest = far[i] longest_i = i del far[longest_i] print(sum(far))
0
null
22,331,855,658,112
52
186
import sys # import math # import bisect # import numpy as np # from decimal import Decimal # from numba import njit, i8, u1, b1 #JIT compiler # from itertools import combinations, product # from collections import Counter, deque, defaultdict # sys.setrecursionlimit(10 ** 6) MOD = 10 ** 9 + 7 INF = 10 ** 9 PI = 3.14159265358979323846 def read_str(): return sys.stdin.readline().strip() def read_int(): return int(sys.stdin.readline().strip()) def read_ints(): return map(int, sys.stdin.readline().strip().split()) def read_ints2(x): return map(lambda num: int(num) - x, sys.stdin.readline().strip().split()) def read_str_list(): return list(sys.stdin.readline().strip().split()) def read_int_list(): return list(map(int, sys.stdin.readline().strip().split())) def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b) def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b) class Combination: def __init__(self, n, p): self.n = n self.p = p self.note = [1, 1] self.noteinv = [1, 1] self.inv = [0, 1] self.calc() def calc(self): for i in range(2, self.n + 1): self.note.append((self.note[-1] * i) % self.p) self.inv.append((-self.inv[self.p % i] * (self.p // i)) % self.p) self.noteinv.append((self.noteinv[-1] * self.inv[-1]) % self.p) def nCr(self, n, r): n = self.n if r < 0 or n < r: return 0 r = min(r, n - r) return (self.note[n] * self.noteinv[r] * self.noteinv[n - r]) % self.p def Main(): n, m, k = read_ints() # m * _{n-1}C_k * 1^k * (m-1)^{n-1-k} p = 998244353 modm = [1] for _ in range(1, n): modm.append((modm[-1] * (m - 1)) % p) cmb = Combination(n - 1, p) ans = 0 for i in range(k + 1): ans += (cmb.nCr(n - 1, i) * m * modm[n - 1 - i]) % p ans %= p print(ans) if __name__ == '__main__': Main()
# coding: utf-8 def solve(*args: str) -> str: n, m, k = map(int, args[0].split()) mod = 998244353 if m == 1 and n-1 == k: return str(1) ncr = 1 p = m*pow(m-1, n-1, mod) % mod ret = p iR = [1]*(k+1) im = pow(m-1, mod-2, mod) for i in range(1, k+1): iR[i] = max(1, (-(mod//i) * iR[mod % i]) % mod) ncr = (ncr * (n-i)*iR[i]) % mod p = (p*im) % mod ret += p*ncr % mod return str(ret % mod) if __name__ == "__main__": print(solve(*(open(0).read().splitlines())))
1
23,169,278,908,270
null
151
151
from collections import defaultdict, deque, Counter from heapq import heappush, heappop, heapify from itertools import permutations, accumulate, combinations, combinations_with_replacement from math import sqrt, ceil, floor, factorial from bisect import bisect_left, bisect_right, insort_left, insort_right from copy import deepcopy from operator import itemgetter from functools import reduce, lru_cache # @lru_cache(None) from fractions import gcd import sys def input(): return sys.stdin.readline().rstrip() sys.setrecursionlimit(10**6) # ----------------------------------------------------------- # s = input() print(s[:3])
s = str(input()) print(s[0]+s[1]+s[2])
1
14,843,535,007,668
null
130
130
def mainFunc(): m1, d1 = list(map(int, list(input().split(" ")))) m2, d2 = list(map(int, list(input().split(" ")))) ans = '1' if m1 != m2 else '0' print(ans) mainFunc()
M,D=map(int,input().split()) MM,DD=map(int,input().split()) if D>DD: print(1) else: print(0)
1
124,010,234,449,240
null
264
264
# -*- coding: utf-8 -*- func = lambda num_1, num_2: num_1 * num_2 for i1 in range(1,10): for i2 in range(1,10): print(str(i1) + "x" + str(i2) + "=" + str(func(i1, i2)))
#!/usr/bin/env python3 # Generated by https://github.com/kyuridenamida/atcoder-tools from typing import * import itertools import math import sys INF = float('inf') def solve(N: int, K: int, p: "List[int]"): return sum(sorted(p)[:K]) def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int K = int(next(tokens)) # type: int p = [int(next(tokens)) for _ in range(N)] # type: "List[int]" print(solve(N, K, p)) if __name__ == '__main__': main()
0
null
5,743,032,582,782
1
120
# 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 = I() a = LI() mx = max(a) table = [0] * (mx + 1) # num of factors for x in a: table[x] += 1 g = 0 # check for x in a: g = gcd(g, x) for i in range(2, mx + 1): c = 0 # 因数iの倍数がaにいくつ含まれるか(c) for j in range(i, mx + 1, i): c += table[j] # cが2以上=iの倍数となるaが複数存在する if c > 1: if g == 1: print("setwise coprime") else: print("not coprime") exit(0) print("pairwise coprime")
N = int(input()) A = list(map(int, input().split())) A = sorted(A) count = 0 for i in range(N-1): if A[i] == A[i+1]: count += 1 i += 1 if count > 0: print('NO') if count == 0: print('YES')
0
null
39,141,205,400,840
85
222
N = int(input()) A = list(map(int,input().split())) LEFT = A[0] RIGHT = sum(A[1:]) MIN = abs(LEFT-RIGHT) for i in range(1,N-1): LEFT += A[i] RIGHT -= A[i] MIN = min(MIN,abs(LEFT-RIGHT)) print(MIN)
N = int(input()) sum_num = 0 for i in range(1, N+1): if (i%3) and (i%5): sum_num += i print(sum_num)
0
null
88,789,759,228,860
276
173
from itertools import product from collections import deque class ZeroOneBFS: def __init__(self, N): self.N = N # #vertices self.E = [[] for _ in range(N)] def add_edge(self, init, end, weight, undirected=False): assert weight in [0, 1] self.E[init].append((end, weight)) if undirected: self.E[end].append((init, weight)) def distance(self, s): INF = float('inf') E, N = self.E, self.N dist = [INF] * N # the distance of each vertex from s prev = [-1] * N # the previous vertex of each vertex on a shortest path from s dist[s] = 0 dq = deque([(0, s)]) # (dist, vertex) n_visited = 0 # #(visited vertices) while dq: d, v = dq.popleft() if dist[v] < d: continue # (s,v)-shortest path is already calculated for u, c in E[v]: temp = d + c if dist[u] > temp: dist[u] = temp; prev[u] = v if c == 0: dq.appendleft((temp, u)) else: dq.append((temp, u)) n_visited += 1 if n_visited == N: break self.dist, self.prev = dist, prev return dist def shortest_path(self, t): P = [] prev = self.prev while True: P.append(t) t = prev[t] if t == -1: break return P[::-1] H, W = map(int, input().split()) zobfs = ZeroOneBFS(H * W) def vtx(i, j): return i*W + j def coord(n): return divmod(n, W) grid = [input() for _ in range(H)] # |string| = W E = [[] for _ in range(H * W)] ans = 0 if grid[0][0] == '.' else 1 for i, j in product(range(H), range(W)): v = vtx(i, j) check = [vtx(i+dx, j+dy) for dx, dy in [(1, 0), (0, 1)] if i+dx <= H-1 and j+dy <= W-1] for u in check: x, y = coord(u) if grid[i][j] == '.' and grid[x][y] == '#': zobfs.add_edge(v, u, 1) else: zobfs.add_edge(v, u, 0) dist = zobfs.distance(0) ans += dist[vtx(H-1, W-1)] print(ans)
MOD = 10**9 + 7 INT_MAX = (1 << 63) - 1 if __name__ == "__main__": # test_case_num = int(input()) # for _ in range(test_case_num): m, n = map(int, input().split()) grid = [input().strip() for _ in range(m)] dp = [float('inf')] * n for i, row in enumerate(grid): for j, val in enumerate(row): if i == 0 and j == 0: dp[j] = grid[0][0] == '#' else: temp = INT_MAX if i > 0: temp = min(dp[j] + (val == '#' != grid[i-1][j]), temp) if j > 0: temp = min(dp[j-1] + (val == '#' != grid[i][j-1]), temp) dp[j] = temp # print(dp) print(dp[-1])
1
49,190,405,935,972
null
194
194
N, P = map(int, input().split()) S = input() if P == 2 or P == 5: cnt = 0 cnt_a = 0 for s in S[::-1]: if int(s) % P == 0: cnt_a += 1 cnt += cnt_a else: r_lst = [0] * P r_lst[0] = 1 cnt = 0 num = 0 for i, s in enumerate(S[::-1]): num = (num + int(s) * pow(10, i, P)) % P cnt += r_lst[num] r_lst[num] += 1 print(cnt)
from collections import * n, p = map(int, input().split()) s = list(map(int, input())) if 10%p==0: r = 0 for i in range(n): if s[i]%p==0: r += i+1 print(r) exit() c = Counter() c[0] += 1 v = r = 0 k = 1 for i in s[::-1]: v += int(i)*k v %= p r += c[v] c[v] += 1 k *= 10 k %= p print(r)
1
57,823,670,114,888
null
205
205
exp = input().split() stk = [] for i in exp : if i in ('+', '-', '*') : num1 = stk.pop() num2 = stk.pop() if i == '+' : stk.append(str(int(num1) + int(num2))) elif i == '-' : stk.append(str(int(num2) - int(num1))) else : stk.append(str(int(num2) * int(num1))) else : stk.append(i) print(stk.pop())
s = input().split(" ") st = [] for i in range(len(s)): if s[i] == "+": a = st.pop() b = st.pop() st.append(a+b) elif s[i] == "-": a = st.pop() b = st.pop() st.append(b-a) elif s[i] == "*": a = st.pop() b = st.pop() st.append(a*b) else: st.append(int(s[i])) print(st[0])
1
36,303,398,952
null
18
18
import sys def main(): cnt = {} for i in range(ord('a'),ord('z')+1): cnt[chr(i)] = 0 for passages in sys.stdin: for psg in passages: psglower = psg.lower() for s in psglower: if s.isalpha(): cnt[s] += 1 for i in range(ord('a'),ord('z')+1): s = chr(i) print(s, ':', cnt[s]) if __name__ == '__main__': main()
a = 'abcdefghijklmnopqrstuvwxyz' b = [0 for i in range(len(a))] while True: try: S = raw_input().lower() except: break for j in range(26): b[j] += S.count(a[j]) for i in range(len(a)): print str(a[i])+" : "+str(b[i])
1
1,681,684,425,848
null
63
63
import sys n = int(input()) s = set() for i in range(n): ins = input().split() if ins[0] == "insert": s.add(ins[1]) elif ins[0] == "find": if ins[1] in s: print("yes") else: print("no")
# 改行またはスペース区切りの入力をすべて読み込んでイテレータを返します。 def get_all_int(): return map(int, open(0).read().split()) n,*A = get_all_int() # dp[i][j] = 活発度高い順のi人目まで処理し、左にjに置いた場合のうれしさの最大 dp = [ [0] * (n+1) for _ in range(n+1) ] AA = list(enumerate(A)) AA.sort(key=(lambda t: t[1]), reverse=True) for i, t in enumerate(AA): # k 移動前の位置 # a 活発度 k,a = t for j in range(i+1): # 左に置く (すでに左端にj人居る) move = abs(k - j) dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + a*move) # 右に置く (すでに右端にi-j人居る) move = abs(k - (n-(i-j)-1)) dp[i+1][j] = max(dp[i+1][j], dp[i][j] + a*move) ans = 0 for j in range(n+1): ans = max(ans, dp[n][j]) print(ans)
0
null
16,763,711,565,696
23
171
K = "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" ans = K.split(", ") num = int(input()) print(ans[num-1])
S = input() W = ['SUN','MON','TUE','WED','THU','FRI','SAT'] w = W.index(S) print(7 - w)
0
null
91,483,964,566,720
195
270
if __name__ == "__main__": n = int(raw_input()) v = map( int, raw_input().split()) min = 1000000 max = -1000000 s = 0 i = 0 while i < n: if min > v[i]: min = v[i] if max < v[i]: max = v[i] s += v[i] i += 1 print "{0} {1} {2}".format( min, max, s)
_, lis = input(), list(map(int, input().split())) print("{} {} {}".format(min(lis), max(lis), sum(lis)))
1
739,674,409,472
null
48
48
N,A,B = map(int,input().split()) kotae= N//(A+B)*A am = N%(A+B) if am>A: am=A print(kotae+am)
N, B, R = list(map(lambda x: int(x), input().split(" "))) print((N // (B + R)) * B + min([N % (B + R), B]))
1
55,347,605,916,630
null
202
202
s = int(input()) n = input() x = n[0:s] y = '...' if s >= len(n): print(n) else: print(x + y)
import itertools def main(): n, m, x = map(int, input().split()) lst = [] for _ in range(n): lst.append(list(map(int, input().split()))) flag1 = True max_lst = [] for i in range(m): understanding = 0 for j in range(n): understanding += lst[j][i+1] max_lst.append(understanding) for i in range(len(max_lst)): maximum = max_lst[i] if maximum < x: cost = -1 flag1 = False break if flag1: number = 1 cost_lst = [] while number <= n: ##一冊laからどんどん増やす n_lst = [] for i in range(n): n_lst.append(i) choice = list(itertools.combinations(n_lst, number)) combination_number = len(choice) choice_number = len(choice[0]) for i in range(combination_number): cost1 = 0 understanding_lst = [0] * m for j in range(choice_number): ##一組終了 choiced_number = choice[i][j] cost1 += lst[choiced_number][0] for k in range(1, m + 1): unstg = lst[choiced_number][k] understanding_lst[k - 1] += unstg over_x = 0 for l in range(m): understanding = understanding_lst[l] if understanding >= x: over_x += 1 if over_x == m: cost_lst.append(cost1) number += 1 cost = min(cost_lst) print(cost) if __name__ == '__main__': main()
0
null
21,014,212,885,808
143
149
#coding: utf-8 import sys def gojo(a,b): if b % a == 0: return a else: return gojo(b % a, a) for line in sys.stdin: l = map(int,line.split()) l.sort() a = l[0] b = l[1] print gojo(a,b),a*b/gojo(a,b)
def digits(n): if n < 10: return 1 c = 0 while n > 0: c += 1 n = n // 10 return c while 1: try: inp = input() except EOFError: break else: n, m = inp.split(' ') n = int(n) m = int(m) print(digits(n + m))
0
null
395,236,130
5
3
h1, m1, h2, m2, k = map(int,input().split()) s = -60*h1-m1+60*h2+m2 print(s-k)
h1,m1,h2,m2,k=map(int,input().split()) if h1>h2: h2+=24 p=(h2-h1)*60+(m2-m1) print(p-k)
1
18,137,078,546,924
null
139
139
n = int(input()) lis = input().split() dic = {} for i in range(n): if lis[i] not in dic: dic[lis[i]] = 1 else: dic[lis[i]] += 1 for x in dic.values(): if x != 1: print("NO") exit() print("YES")
N = int(input()) A = sorted(list(map(int,input().split()))) for i in range(1,N): if A[i] == A[i-1]: print("NO") Flag = False break else: Flag = True if Flag: print("YES")
1
73,523,264,999,382
null
222
222
import math; in_put = input(""); cube=math.pow(float(in_put),3); print(int(cube));
import sys,math,collections,itertools input = sys.stdin.readline H,N=list(map(int,input().split())) AB = [] amax = 0 for _ in range(N): a,b=map(int,input().split()) amax = max(amax,a) AB.append([a,b]) HN = [float('inf')]*(H+amax+1) HN[0] = 0 for i in range(H+amax+1): for j in range(N): if AB[j][0]<=i: tmp = HN[i-AB[j][0]]+AB[j][1] HN[i] = min(HN[i],tmp) else: tmp = AB[j][1] HN[i] = min(HN[i],tmp) print(min(HN[H:]))
0
null
40,597,133,348,378
35
229
N = int(input()) A = list(map(int, input().split())) p = list(range(N)) p.sort(key=lambda i: A[i], reverse=True) dp = [[0]*(N + 1) for _ in range(N + 1)] for i in range(N): for j in range(i + 1): pi = p[i] dp[i+1][j] = max(dp[i+1][j], dp[i][j] + A[pi]*(N - i + j - 1 - pi)) dp[i+1][j+1] = dp[i][j] + A[pi]*(pi - j) print(max(dp[N]))
N = int(input()) A = map(int, input().split()) A = sorted(enumerate(A), key=lambda x: x[1], reverse=True) dp = [[0]*(N+1) for _ in range(N+1)] for n, (from_i, a) in enumerate(A): for j in range(n + 1): dp[n+1][j+1] = max(dp[n+1][j+1], dp[n][j] + a*(from_i - j)) dp[n+1][j] = max(dp[n+1][j], dp[n][j] + a*(N - (n - j) - 1 - from_i)) print(max(dp[N]))
1
33,965,040,432,960
null
171
171
A = input() while(A != '-'): m = int(input()) for i in range(m): h = int(input()) A = A[h:]+A[:h] print(A) A = input()
while True: cards=input() if cards=='-': break for _ in range(int(input())): h = int(input()) cards=cards[h:]+cards[:h] print(cards)
1
1,932,380,612,908
null
66
66
N, M = [int(_) for _ in input().split()] if N == M: print('Yes') else: print('No')
from sys import stdin N, M = [int(x) for x in stdin.readline().rstrip().split()] if N == M: print("Yes") else: print("No")
1
83,589,230,760,100
null
231
231
k,n=map(int,input().split()) dis=list(map(int,input().split())) ans=[] for i in range(n): if i>=1: ans.append(dis[i]-dis[i-1]) ans.append(dis[0]+(k-dis[n-1])) print(k-max(ans))
N, D = map(int, input().split()) x = [0] * N y = [0] * N for i in range(N): x[i], y[i] = map(int, input().split()) c = 0 for j in range(N): if x[j]**2 + y[j]**2 <= D**2: c += 1 print(c)
0
null
24,604,459,584,162
186
96
n = int(input()) a = list(map(int,input().split(" "))) answer = 0 for i in range(1,n): if a[i] < a[i - 1]: answer += a[i-1] - a[i] a[i]= a[i - 1] print(answer)
import sys import math lines = sys.stdin.readlines() # print(lines) n = int(lines[0].rstrip()) heights = [int(x) for x in lines[1].rstrip().split()] # print(heights) tot = 0 for i in range(n-1): if heights[i] <= heights[i+1]: continue else: diff = heights[i] - heights[i+1] heights[i+1] += diff tot += diff print(tot)
1
4,512,182,071,498
null
88
88
d={} for _ in[0]*int(input()): c,g=input().split() if'i'==c[0]:d[g]=0 else:print(['no','yes'][g in d])
import heapq def main(): X, Y, A, B, C = (int(_) for _ in input().split()) p = sorted([int(_) for _ in input().split()])[::-1] q = sorted([int(_) for _ in input().split()])[::-1] r = sorted([int(_) for _ in input().split()])[::-1] output = 0 apple = list() heapq.heapify(apple) for i in range(X): heapq.heappush(apple, p[i]) output += p[i] for i in range(Y): heapq.heappush(apple, q[i]) output += q[i] i = 0 while i < C: x = heapq.heappop(apple) if x < r[i]: heapq.heappush(apple, r[i]) output = output - x + r[i] i += 1 else: break print(output) return if __name__ == '__main__': main()
0
null
22,594,464,960,188
23
188
import math import itertools # 与えられた数値の桁数と桁値の総和を計算する. def calc_digit_sum(num): digits = sums = 0 while num > 0: digits += 1 sums += num % 10 num //= 10 return digits, sums s = input() t = input() answer = len(t) for index in range(len(s) - (len(t) - 1)): d = s[index:index+len(t)] match = 0 for idx in range(len(t)): if t[idx] == d[idx]: match += 1 answer = min(answer, len(t) - match) print(answer)
S = input() T = input() Ns = len(S) Nt = len(T) ans = 0 for i in range(Ns - Nt + 1): tmp = 0 for j in range(Nt): if S[i + j] == T[j]: tmp += 1 ans = max(ans, tmp) print(Nt - ans)
1
3,661,882,279,258
null
82
82
n,m=map(int,input().split());print('YNeos'[n!=m::2])
#!/usr/bin/env python3 # encoding:utf-8 import copy import random import bisect #bisect_left これで二部探索の大小検索が行える import fractions #最小公倍数などはこっち import math import sys import collections from decimal import Decimal # 10進数で考慮できる mod = 10**9+7 sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000 d = collections.deque() def LI(): return list(map(int, sys.stdin.readline().split())) N, M = LI() if N == M: print("Yes") else: print("No")
1
83,275,971,280,480
null
231
231
from math import pi r=input() print"%.8f %.8f"%(pi*r*r,2*pi*r)
# Template 1.0 import sys, re from collections import deque, defaultdict, Counter, OrderedDict from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from heapq import heappush, heappop, heapify, nlargest, nsmallest def STR(): return list(input()) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def list2d(a, b, c): return [[c] * b for i in range(a)] def sortListWithIndex(listOfTuples, idx): return (sorted(listOfTuples, key=lambda x: x[idx])) def sortDictWithVal(passedDic): temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0])) toret = {} for tup in temp: toret[tup[0]] = tup[1] return toret def sortDictWithKey(passedDic): return dict(OrderedDict(sorted(passedDic.items()))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 n = INT() a = LIST() first = a[:] dd = defaultdict(int) for i in range(n): first[i] = first[i]+(i+1) dd[first[i]]+=1 ans = 0 for i in range(n): ans+=dd[(i+1)-a[i]] print(ans)
0
null
13,426,912,579,132
46
157
N = int(input()) A = list(map(int,input().split())) #t: 1, 2, 3,..., N #A: A1,A2,A3,...,AN #|t-s| = At+As となるt,sのペアの数は、 # t-s = At+As かつ t>s となるt,sのペアの数と等しく、 # t-At = s+As かつ t>s となるt,sのペアの数と等しい ms = [0]*N ps = [0]*N for i in range(N): ms[i],ps[i] = (i+1)-A[i],(i+1)+A[i] msc,psc = {},{} mi,pi = 0,0 out = 0 while mi<N: msc[ms[mi]] = msc.get(ms[mi],0)+1 out += psc.get(ms[mi],0) psc[ps[mi]] = psc.get(ps[pi],0)+1 mi+=1 pi+=1 print(out)
n,m = map(int, input().split()) A = sorted(list(map(int, input().split())), reverse = True) s = sum(A) cnt = 0 for a in A: if a*4*m >= s: cnt += 1 if cnt >= m: print('Yes') break else: print('No')
0
null
32,339,749,575,780
157
179
#!usr/bin/env python3 import sys import re def main(): s = sys.stdin.readline() # haystack p = sys.stdin.readline() # needle s = s.strip('\n') * 2 p = p.strip('\n') if len(re.findall((p), s)) > 0: print('Yes') else: print('No') if __name__ == '__main__': main()
s=input() p=input() s=s+s a=s.find(p) if a==-1: print('No') else: print('Yes')
1
1,715,295,224,388
null
64
64
import math a,b,c_deg = map(float,input().split()) sin_c = math.sin(c_deg*math.pi/180) cos_c = math.cos(c_deg*math.pi/180) s = a*b*sin_c/2.0 c = math.sqrt(a**2+b**2-2*a*b*cos_c) print(s) print(a+b+c) print(s/a*2.0)
import math a, b, deg = map(int, input().split()) rad = math.radians(deg) S = a * b * math.sin(rad) / 2 c = (a ** 2 + b ** 2 - 2 * a * b * math.cos(rad)) ** (1 / 2) L = a + b + c h = S * 2 / a print(S,L,h)
1
172,138,633,670
null
30
30
#!/usr/bin/env python3 x,y = map(int,input().split()) if x == 1 and y == 1: #if False: print(10**6) else: print((max(0,4-x)+max(0,4-y))*(10**5))
X,Y=map(int,input().split()) M=[0]*206 M[0],M[1],M[2]=300000,200000,100000 if X+Y==2: print(1000000) else: print(M[X-1]+M[Y-1])
1
139,981,132,861,308
null
275
275
import sys for jk in sys.stdin: L=jk.split(" ") sum = int(L[0])+int(L[1]) digit = 1 while sum>=10: sum = sum/10 digit = digit + 1 print digit
import sys from math import log10, floor print('\n'.join(map(str, [floor(log10(sum(map(int, ab.split())))) + 1 for ab in sys.stdin])))
1
87,983,132
null
3
3
def main(): h, n = map(int, input().split()) arr = [list(map(int, input().split())) for _ in range(n)] dp = [[float("inf")]*(2*10**4+1) for _ in range(n+1)] dp[0][0] = 0 for i in range(n): p, a, b = i+1, arr[i][0], arr[i][1] for j in range(2*10**4+1): if j < a: dp[p][j] = dp[p-1][j] else: if dp[p][j-a] + b < dp[p-1][j]: dp[p][j] = dp[p][j-a] + b else: dp[p][j] = dp[p-1][j] print(min(dp[-1][h:2*10**4+1])) if __name__ == "__main__": main()
n = list(map(int,input().split())) a = list(map(int,input().split())) for i in range(n[1],n[0]): if a[i-n[1]] < a[i]: print("Yes") else: print("No")
0
null
44,095,344,129,332
229
102
input_line = list(map(int,input().split(' '))) if(input_line[0]>=input_line[2]): input_line[0] -= input_line[2] elif((input_line[0]+input_line[1])>=input_line[2]): input_line[1] -= (input_line[2]-input_line[0]) input_line[0] = 0 else: input_line[0] = 0 input_line[1] = 0 print(input_line[0],input_line[1])
while True: a, op, b = input().split() if(op == '+'): print(int(a) + int(b)) elif(op == '-'): print(int(a) - int(b)) elif(op == '*'): print(int(a) * int(b)) elif(op == '/'): print(int(a) // int(b)) else: break
0
null
52,643,528,860,182
249
47
import sys sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 998244353 def resolve(): n = int(input()) D = list(map(int, input().split())) MAX_L = max(D) + 1 cnt = [0] * MAX_L for d in D: cnt[d] += 1 if cnt[0] != 1 or D[0] != 0: print(0) exit() res = 1 for i in range(1, MAX_L): if cnt[i] == 0: print(0) break res *= pow(cnt[i - 1], cnt[i], mod) res %= mod else: print(res) if __name__ == '__main__': resolve()
from sys import stdin import sys import math from functools import reduce import functools import itertools from collections import deque,Counter,defaultdict from operator import mul import copy # ! /usr/bin/env python # -*- coding: utf-8 -*- import heapq sys.setrecursionlimit(10**6) # INF = float("inf") INF = 10**18 import bisect import statistics mod = 10**9+7 # mod = 998244353 N = int(input()) A = list(map(int, input().split())) A = sorted(A, reverse=True) ans = A[0] for i in range(N-2): ans += A[i//2+1] print(ans)
0
null
82,190,775,752,196
284
111
def main(): r, c = map(int, input().split()) col_sums = [0] * c rows = [ input() for n_r in range(r) ] for row in rows: row_sum = 0 cols = map(int, row.split()) for idx, col in enumerate(cols): col_sums[idx] += col row_sum += col print(row, end="") print("", row_sum) last_line = " ".join(map(str, col_sums)) print(last_line, end="") print("", sum(col_sums)) if __name__ == "__main__": main()
str = input() def hitachi(S): hitachi_str = [True if S[i:i+2] == 'hi' else False for i in range(0,len(S),2)] if all(hitachi_str): result = 'Yes' else: result = 'No' return result print(hitachi(str))
0
null
27,232,273,085,600
59
199
d, t, s = map(int, input().split()) ans = "Yes" if d / s <= t else "No" print(ans)
d, t, s = map(int, input().split()) print('Yes' if t*s >= d else 'No')
1
3,518,144,855,302
null
81
81
H = int(input()) W = int(input()) N = int(input()) count1 = 0 count2 = 0 for i in range(1,W+1): count1 += 1 if i*H >= N: break for j in range(1,H+1): count2 += 1 if j*W >= N: break if count1 > count2: print(count2) else: print(count1)
H,W,N = map(int, open(0).read().split()) ans = 0 while N > 0: A = max(H, W) tmp = N // A N = N % A if tmp == 0 and N: N = 0 ans += 1 break if H == A: W -= tmp else: H -= tmp ans += tmp print(ans)
1
89,077,591,993,052
null
236
236
# coding: utf-8 import math #N, K, M = map(int,input().split()) alp = [chr(i) for i in range(97, 97+26)] #print(alp) #N = int(input()) #K = int(input()) c = input() ans = 0 #l = list(map(int,input().split())) #A = list(map(int,input().split())) print(alp[alp.index(c)+1])
def comb(n,r,m): if 2*r > n: r = n - r nume,deno = 1,1 for i in range(1,r+1): nume *= (n-i+1) nume %= m deno *= i deno %= m return (nume * pow(deno,m-2,m)) % m def main(): N,M,K = map(int,input().split()) mod = 998244353 ans,comb_r = pow(M-1,N-1,mod),1 for r in range(1,K+1): comb_r = (comb_r * (N-r) * pow(r,mod-2,mod)) % mod ans = (ans + comb_r * pow(M-1,N-r-1,mod)) % mod ans = (ans * M) % mod print(ans) if __name__ == "__main__": main()
0
null
57,715,228,513,448
239
151
import sys from itertools import count H, A = map(int, next(sys.stdin.buffer).split()) for i in count(1): H -= A if H <= 0: break print(i)
def judge(k, N, A): p = N - 1 t = 0 for i in A: while p >= 0 and A[p] + i < k: p -= 1 t += (p + 1) return t def main(): N, M = map(int, input().split()) A = list(map(int, input().split())) A.sort(reverse=True) t = A[0] * 2 b = 0 X = None while t - b > 1: m = (t + b)//2 i = judge(m, N, A) if i == M: X = m break if i > M: ip = judge(m + 1, N, A) if ip == M: X = m + 1 break if ip < M: X = m break b = m + 1 if i < M: im = judge(m - 1, N, A) if im >= M: X = m - 1 break t = m - 1 if X is None: X = b r = 0 p = N - 1 k = sum(A) for i in A: while p >= 0 and A[p] + i < X : k -= A[p] p -= 1 r += i * (p + 1) + k return r - (judge(X, N, A) - M) * X print(main())
0
null
92,515,176,754,140
225
252
N = int(input()) def divisor(n): res = [] for i in range(1, int(n**0.5)+1): if n%i!=0: continue res.append(i) if i*i != n: res.append(n//i) return res ans = 0 d = [] for x in divisor(N): if x==1: continue tmp = N while tmp%x==0: tmp //= x tmp %= x if tmp == 1: ans += 1 ans += len(divisor(N-1)) - 1 print(ans)
A, B, K = list(map(int, input().split())) if A <= K: K = K - A A = 0 if B <= K: K = K - B B = 0 else: B = B - K else: A = A - K print(str(A) + ' ' + str(B))
0
null
72,756,859,796,292
183
249
(a,b,c,d,e)=map(int,input().split()) if a==c: t=d-b if e<=t: print(t-e) else: print(0) if c>a: if b>d: t=60*(c-a)-b+d if e<=t: print(t-e) else: print(0) if b<=d: t=(c-a)*60+d-b if e<=t: print(t-e) else: print(0)
h1, m1, h2, m2, k = map(int, input().split()) st = h1*60 + m1 end = h2*60 + m2 print(end-st-k)
1
18,178,926,341,982
null
139
139
l = list(map(int,input().split())) mx = float('-inf') for i in range(2): for j in range(2,4): mx = max(mx,l[i]*l[j]) print(mx)
a = list(map(int, input().split())) print(max((a[0] * a[2]),(a[0] * a[3]),(a[1] * a[3]),(a[1] * a[2])))
1
3,053,284,811,918
null
77
77
M1, D1 = map(int, input().split()) M2, D2 = map(int, input().split()) if M1 in [1, 3, 5, 7, 8, 10, 12]: if D1 == 31: print(1) else: print(0) elif M1 in [4, 6, 9, 11]: if D1 == 30: print(1) else: print(0) elif M1 == 2: if D1 == 28: print(1) else: print(0)
N=int(input()) for i in range(50000): if int(i*1.08)==N: print(i) exit() print(':(')
0
null
125,223,809,921,990
264
265
import math a, b, h, m = map(int, input().split()) min = h * 60 + m short = 0.5 * min long = 6 * m if abs(short - long) >= 180: deg = 360 - abs(short - long) else: deg = abs(short - long) coss = math.cos(math.radians(deg)) c = (a ** 2 + b ** 2 - 2 * a * b * coss) ** 0.5 #print(c) print('{:.20f}'.format(c))
import bisect,collections,copy,heapq,itertools,math,string,decimal import numpy as np import sys sys.setrecursionlimit(10**7) def _S(): return sys.stdin.readline().rstrip() def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LS(): return list(sys.stdin.readline().rstrip().split()) # N = I() _A,_B = LS() A = decimal.Decimal(_A) B = decimal.Decimal(_B) print((A*B).quantize(decimal.Decimal('0'), rounding=decimal.ROUND_DOWN)) #AB = [LI() for _ in range(N)] #A,B = zip(*AB) #Ap = np.array(A) #C = np.zeros(N + 1) # if ans: # print('Yes') # else: # print('No')
0
null
18,306,650,475,260
144
135
import math h,a=map(int,input().split()) num = h/a ans = math.ceil(num) print(ans)
import math n = int(input()) count = 0 for i in range(n): t = int(input()) a = int(t ** (1 / 2)) end = 0 for j in range(2, a + 1): if t % j == 0: end = 1 break if end == 0: count += 1 print(count)
0
null
38,285,235,895,580
225
12
n, x, m = map(int, input().split()) lis = [x] flag = [-1 for i in range(m)] flag[x] = 0 left = -1 right = -1 for i in range(n-1): x = x**2 % m if flag[x] >= 0: left = flag[x] right = i break else: lis.append(x) flag[x] = i+1 ans = 0 if left == -1: ans = sum(lis) else: ans += sum(lis[0:left]) length = right - left + 1 ans += sum(lis[left:]) * ((n-left)//length) ans += sum(lis[left:left+((n-left)%length)]) print(ans)
from collections import defaultdict from collections import deque from collections import Counter import math import itertools def readInt(): return int(input()) def readInts(): return list(map(int, input().split())) def readChar(): return input() def readChars(): return input().split() n,x,m = readInts() an = x ans = an moddict = {an:1} for i in range(2,n+1): an = pow(an,2,m) if an in moddict: break else: moddict[an]=i ans += an #print(ans) if an in moddict: rep = (n-len(moddict))//(len(moddict)-moddict[an]+1) rem = (n-len(moddict))%(len(moddict)-moddict[an]+1) #print(rep,rem) rep_sum = 0 boo = 0 for key in moddict: if boo or key==an: boo = 1 rep_sum+=key ans += rep_sum*rep for i in range(rem): ans+=an an=pow(an,2,m) print(ans)
1
2,789,223,294,860
null
75
75
mod = 10 ** 9 + 7 n, k = map(int, input().split()) binomial = [1] cum = 1 for i in range(1, n + 2): cum *= i cum = cum % mod binomial.append(cum) inv = [] tmp = pow(cum, mod - 2, mod) inv.append(tmp) for j in range(n + 1, 0, -1): tmp = j * tmp % mod inv.append(tmp) inv.reverse() def comb(n, k): return binomial[n] * inv[n - k] % mod * inv[k] % mod if n >= k else 0 k = min(k, n - 1) ans = 0 for m in range(k + 1): tmp = comb(n, m) * binomial[n - 1] * inv[n - 1 - m] * inv[m] ans += tmp % mod ans %= mod print(ans)
MOD = 10**9 + 7 N, K = map(int, input().split()) def getFacts(n, MOD): facts = [1] * (n+1) for x in range(2, n+1): facts[x] = (facts[x-1] * x) % MOD return facts facts = getFacts(2*N, MOD) def getInvFacts(n, MOD): invFacts = [0] * (n+1) invFacts[n] = pow(facts[n], MOD-2, MOD) for x in reversed(range(n)): invFacts[x] = (invFacts[x+1] * (x+1)) % MOD return invFacts invFacts = getInvFacts(2*N, MOD) def getComb(n, k, MOD): if n < k: return 0 return facts[n] * invFacts[k] * invFacts[n-k] % MOD ans = 0 for x in range(min(K, N-1)+1): ans += getComb(N, x, MOD) * getComb(N-1, x, MOD) ans %= MOD print(ans)
1
67,224,541,655,310
null
215
215
import collections N=int(input()) A=list(map(int,input().split())) D = collections.Counter(A) s=0 for i in D: s+=D[i]*(D[i]-1)//2 for i in range(N): print(s-(D[A[i]]-1))
N = int(input()) odd = (N+1)//2 print(odd/N)
0
null
112,579,779,095,850
192
297
x = int(input()) if x <= 599: print(8,"\n") elif x <= 799: print(7,"\n") elif x <= 999: print(6,"\n") elif x <= 1199: print(5,"\n") elif x <= 1399: print(4,"\n") elif x <= 1599: print(3,"\n") elif x <= 1799: print(2,"\n") elif x <= 1999: print(1,"\n")
X, Y = map(int, input().split()) flag1 = (Y - 2 * X >= 0) and ((Y - 2 * X) % 2 == 0) flag2 = (4 * X - Y >= 0) and ((4 * X - Y) % 2 == 0) print("Yes" if flag1 and flag2 else "No")
0
null
10,172,232,151,808
100
127
import itertools n = int(input()) d = list(map(int,input().split())) ans = 0 for v in itertools.combinations(d, 2): ans += v[0]*v[1] print(ans)
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement from collections import deque,defaultdict,Counter from bisect import bisect_left,bisect_right from operator import itemgetter from heapq import heapify,heappop,heappush from queue import Queue,LifoQueue,PriorityQueue from copy import deepcopy from time import time import string import sys sys.setrecursionlimit(10 ** 7) def input() : return sys.stdin.readline().strip() def INT() : return int(input()) def MAP() : return map(int,input().split()) def LIST() : return list(MAP()) def dfs(s,d,i): for j in range(i+1): s[d] = chr(ord('a')+j) if d < len(s) - 1: dfs(s, d+1, max(j+1, i)) else: a.add("".join(s)) n = INT() s = ['a']*n a = set() dfs(s, 0, 0) b = sorted(list(a)) for x in b: print(x)
0
null
110,471,108,641,020
292
198
s = input() if s == 'RRR': print(3) elif s[:2] == 'RR' or s[1:] == 'RR': print(2) elif s.count('R') >= 1: print(1) else: print(0)
import sys import heapq sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline def main(): N, K = [int(x) for x in input().split()] A = [int(x) for x in input().split()] MOD = 10 ** 9 + 7 plus = [] minus = [] for a in A: if a >= 0: heapq.heappush(plus, -a) else: heapq.heappush(minus, a) ans = 1 # 絶対マイナスになる場合 if len(plus) < K - min((K - K % 2), (len(minus) - len(minus) % 2)): plus = [] minus = [] for a in A: if a >= 0: heapq.heappush(plus, a) else: heapq.heappush(minus, -a) while K > 0: if plus: x = plus[0] else: x = float("inf") if minus: y = -minus[0] else: y = float("inf") if abs(x) <= abs(y): ans *= x if plus: heapq.heappop(plus) else: ans *= y if minus: heapq.heappop(minus) ans %= MOD K -= 1 print(ans) else: while K > 0: if K >= 2 and len(minus) >= 2 and len(plus) >= 2: x1 = plus[0] x2 = plus[1] y1 = minus[0] y2 = minus[1] if x1 * x2 <= y1 * y2: y1 = heapq.heappop(minus) y2 = heapq.heappop(minus) ans *= (y1 * y2) ans %= MOD K -= 2 else: x1 = -heapq.heappop(plus) ans *= x1 ans %= MOD K -= 1 elif K >= 2 and len(minus) >= 2: y1 = heapq.heappop(minus) y2 = heapq.heappop(minus) ans *= (y1 * y2) ans %= MOD K -= 2 else: x = -heapq.heappop(plus) ans *= x ans %= MOD K -= 1 print(ans % MOD) if __name__ == '__main__': main()
0
null
7,097,011,856,050
90
112
def resolve(): n=int(input()) if n%2==0: print(n//2-1) else: print(n//2) resolve()
n = int(input()) al = list(map(int, input().split())) if n == 1 and al[0] == 1: print(0) else: i, j, num, ans = 0, 0, 1, 0 while i < n: if al[i] != num: i += 1 else: ans += i-j j = i+1 num += 1 i += 1 # print(i, j, ans) if num != 1 and j != n: ans += i-j if num == 1: print(-1) else: print(ans)
0
null
133,941,559,560,200
283
257
[N, M, X] = map(int, list(input().split(' '))) A = [] C = [] for i in range(N): c, *a = map(int, input().split(' ')) C.append(c) A.append(a) #print(C) #print(A) INF = 10**10 min_cost = INF for b in range(2**N): # これがバイナリーベースの全探索となる。今回のキモ part 1 # 一つのループが本の購入セットに対応している # 各ビットがそれぞれの本を購入するかどうか表している # 因みに b は bit を表しているつもり cost = 0 # この購入セットで使う金額 algo_level = [0] * M # 各アルゴリズムトピックの理解度 for i in range(N): # これが各本のコストと理解度取得のためのループ # i 番目の本に対してループを回していく if(b >> i & 1): # この行が今回のキモ part 2。 # i 番目の本の購入有無を判定するために、ビットシフトした値に対して '1 = 0b1' (つまり単なる (2進数の) 1) との論理積を求めている # この if 文が True であるということは、i 番目の本を買ったということ cost += C[i] for a in range(M): # (各本にある) 各アルゴリズムに対するループ algo_level[a] += A[i][a] if(min(algo_level) >= X): # 全てのアルゴリズムトピックが X 以上の理解度である場合… min_cost = min(cost, min_cost) if(min_cost < INF): print(min_cost) else: print('-1')
N=int(input()) st=[] for i in range(N): s,t=input().split() st.append((s,int(t))) X=input() time=0 s=False for i in range(N): if s: time+=st[i][1] if st[i][0]==X: s=True print(time)
0
null
59,679,238,374,460
149
243
n = int(input()) a = list(map(int, input().split())) s = sum(a) k = 1-a[0] s -= a[0] ans = 1 for i in range(1,n+1): if k*2 <= s: k *= 2 else: k = s ans += k k -= a[i] s -= a[i] if k == 0 and s == 0: print(ans) else: print(-1)
import sys input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) low = [0]*(N+1) high = [0]*(N+1) low[N] = A[N] high[N] = A[N] for i in range(N-1, -1, -1): low[i] = (low[i+1]+1)//2+A[i] high[i] = high[i+1]+A[i] if not low[0]<=1<=high[0]: print(-1) exit() ans = 1 now = 1 for i in range(N): now = min(2*(now-A[i]), high[i+1]) ans += now print(ans)
1
18,998,339,633,868
null
141
141
#! /usr/bin/env python # -*- coding: utf-8 -*- ''' ??????????????? ''' # ????????????????????°?????????N(N-1)/2????????§??? # ?¨???????:O(n^2) def selection_sort(A, N): swap_num = 0 # ???????????° for i in range(N): minj = i for j in range(i, N, 1): if A[j] < A[minj]: minj = j # swap if i != minj: tmp = A[i] A[i] = A[minj] A[minj] = tmp swap_num += 1 return (A, swap_num) if __name__ == "__main__": N = int(input()) A = list(map(int, input().split())) # A = [5, 2, 4, 6, 1, 3] # N = len(A) array_sorted, swap_num = selection_sort(A, N) print(' '.join(map(str, array_sorted))) print(swap_num)
n = int(input()) m = list(map(int, input().split())) count = 0 for i in range(n-1): minj =i for j in range(i+1, n): if m[j] < m[minj]: minj = j if m[i] != m[minj]: m[i], m[minj] = m[minj], m[i] count += 1 print(" ".join(str(x) for x in m)) print(count)
1
18,841,658,880
null
15
15
n = input() num = map(int, raw_input().split()) for i in range(n): if i == n-1: print num[n-i-1] break print num[n-i-1],
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('')
1
984,021,920,562
null
53
53
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 x, y = map(int, readline().split()) if x < y: x, y = y, x b = (2 * x - y) // 3 if (2 * x - y) % 3 != 0: print(0) exit() a = x - 2 * b if a < 0: print(0) exit() MOD = 10 ** 9 + 7 a %= MOD b %= MOD MAX = 10 ** 6 * 2 + 2 fac = [0 for i in range(MAX)] finv = [0 for i in range(MAX)] inv = [0 for i in range(MAX)] def comInit(mod): fac[0], fac[1] = 1, 1 finv[0], finv[1] = 1, 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 com(n, r, mod): if n < r: return 0 if n < 0 or r < 0: return 0 return fac[n] * (finv[r] * finv[n - r] % mod) % mod comInit(MOD) print(com(a + b, b, MOD))
n = input() data = [int(i) for i in input().split(' ')] def insertion_sort(raw_list): for i, v in enumerate(raw_list): if i == 0: continue j = i - 1 while j >= 0 and v < raw_list[j]: raw_list[j+1] = v raw_list[j+1] = raw_list[j] j -= 1 raw_list[j+1] = v print(' '.join([str(i) for i in raw_list])) return raw_list print(' '.join([str(i) for i in data])) insertion_sort(data) #print(' '.join([str(i) for i in insertion_sort(data)]))
0
null
74,919,227,461,324
281
10
n, k = map(int, input().split()) H = list(map(int, input().split())) H.sort() print(sum(H[:max(n-k, 0)]))
from bisect import bisect_left N = int(input()) L_list = list(map(int, input().split())) L_list.sort() ans = 0 for i in range(N): for j in range(i + 1, N): a, b = L_list[i], L_list[j] r = bisect_left(L_list, a+b) ans += max(0,r-j-1) print(ans)
0
null
125,985,661,666,432
227
294
N = int(input()) L = list(map(int, input().split())) #リストで複数行作るには? count = 0 for i in range(2, N): for j in range(1, i): for k in range(0, j): if L[i] == L[j] or L[j] == L[k] or L[k] == L[i]: continue elif L[k] < L[i] + L[j] and L[i] < L[j] + L[k] and L[j] < L[i] + L[k]: count += 1 print(count)
n=int(input()) l=sorted(list(map(int,input().split())),reverse=True) count=0 for i in range(n-2): for j in range(i+1,n-1): for k in range(j+1,n): if l[i]<l[j]+l[k] and l[i]!=l[j]!=l[k]: count+=1 print(count)
1
5,080,573,237,400
null
91
91
d=int(input()) c=list(map(int,input().split())) s=[list(map(int,input().split()))for _ in range(d)] class Score: def __init__(self,t): self.x=[d*[0]for _ in range(26)] self.scor=0 self.ans=[] for i in range(d): v=t[i] self.scor+=s[i][v] for j in range(26): if j!=v: self.x[j][i]+=1 if i!=0:self.x[j][i]+=self.x[j][i-1] self.scor-=c[j]*self.x[j][i] self.ans.append(self.scor) def solve(self): return [self.scor,self.ans] t=[int(input())-1 for _ in range(d)] x=Score(t) _,ans=x.solve() for i in ans:print(i)
D = int(input()) C = list(map(int, input().split())) S = [list(map(int, input().split())) for i in range(D)] L = [0 for i in range(26)] T = [int(input()) for i in range(D)] score=0 for d in range(D): score += S[d][T[d]-1] L[T[d]-1] = d+1 down = 0 for i in range(26): down+=C[i] * ((d+1) - L[i]) score -=down print(score)
1
9,971,713,570,728
null
114
114
x,y,a,b,c = map(int,input().split()) p = list(map(int,input().split())) q = list(map(int,input().split())) r = list(map(int,input().split())) p.sort(reverse = True) q.sort(reverse = True) r.sort(reverse = True) p = p[:x] q = q[:y] l = p + q + r l.sort(reverse = True) print(sum(l[:x+y]))
import sys,math,collections,itertools,heapq input = sys.stdin.readline def f(n): return -1*int(n) x,y,a,b,c=list(map(int,input().split())) p=sorted(list(map(int,input().split())),reverse=1)[:x] q=sorted(list(map(int,input().split())),reverse=1)[:y] r=list(map(f,input().split())) p = collections.deque(p) q = collections.deque(q) heapq.heapify(r) tmp = -1*heapq.heappop(r) while tmp > p[-1]: p.appendleft(tmp) tmp = p.pop() tmp = -1* heapq.heappushpop(r,-1*tmp) while tmp > q[-1]: q.appendleft(tmp) tmp = q.pop() tmp = -1 * heapq.heappushpop(r,-1*tmp) print(sum(p)+sum(q))
1
44,816,463,500,130
null
188
188
n = int(input()) suretsu = list(map(int,input().split())) wa = 0 minimum = suretsu[0] maximum = suretsu[0] for i in range(n): wa += suretsu[i] if suretsu[i] > maximum: maximum = suretsu[i] if suretsu[i] < minimum: minimum = suretsu[i] print (minimum,maximum,wa)
s = input() a = [str(c) for c in s] for i in range (len(a)-1): if a[i]=='?': if i!=0 and a[i-1]=='P': a[i]='D' elif a[i+1]=='D' or a[i+1]=='?': a[i]='P' else: a[i]='D' if a[len(a)-1]=='?': a[len(a)-1]='D' print(*a,sep='')
0
null
9,676,381,462,568
48
140
# AtCoder Beginner Contest 145 D - Knight import sys from math import factorial mod = 10 ** 9 + 7 X, Y = map(int, sys.stdin.readline().strip().split()) # 合計の移動回数は Total = X + Y / 3 # 移動方法は A: (i + 1, j + 2) B: (i + 2, j + 1) の2通り # 移動回数は A: 2 * Total - X B: X - Total # 到達不可能であるか判断する if (X + Y) % 3 != 0: print(0) sys.exit() if Y > 2 * X or Y < X * 0.5: print(0) sys.exit() Total = (X + Y) // 3 A = Total * 2 - X B = X - Total # combination の計算 ans = 1 for i in range(1, Total + 1): ans *= i ans %= mod ans = ans * pow(factorial(A), mod - 2, mod) ans = ans * pow(factorial(B), mod - 2, mod) print(ans % mod)
import math a, b, h, m = map(int,input().split()) time = h * 60 + m ta = time * 2 * math.pi / (12 * 60) tb = time * 2 * math.pi / 60 xa = a * math.sin(ta) ya = a * math.cos(ta) xb = b * math.sin(tb) yb = b * math.cos(tb) ans = math.sqrt((xa-xb)**2 + (ya-yb)**2) print(ans)
0
null
85,210,044,875,562
281
144
import math print reduce(lambda a, b: int(math.ceil(a * 1.05 / 1000)) * 1000, range(input()), 100000)
S=input().split() print(S.index("0")+1)
0
null
6,767,891,617,930
6
126
H,N = map(int,input().split());INF = float("inf") A=[];B=[] for i in range(N): a,b = map(int,input().split()) A.append(a);B.append(b) #print(A,B) dp = [INF for _ in range(H+1)] #dp[i] HPがi残っているときの、魔力の消費最小 dp[H] = 0 for i in reversed(range(H+1)): #print(i) #print(dp) for j in range(N): if i - A[j] >= 0: dp[i-A[j]] = min(dp[i-A[j]], dp[i] + B[j]) else: dp[0] = min(dp[0], dp[i] + B[j]) ans = dp[0] print(ans)
from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify import sys,bisect,math,itertools,fractions sys.setrecursionlimit(10**8) mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) n,k = inpl() now = inpl() for _ in range(k): pre = now[::] cnt = [0] * (n+1) for i in range(n): l = max(0, i - pre[i]) r = min(n, i + pre[i] + 1) cnt[l] += 1 cnt[r] -= 1 # print(cnt) now = [0] * n now[0] = cnt[0] for i in range(1,n): now[i] = now[i-1] + cnt[i] if min(now) == n: break print(*now)
0
null
48,187,403,585,852
229
132
import itertools n = int(input()) d = list(map(int, input().split())) lst = list(itertools.combinations(d, 2)) ans = 0 for i in lst: a = i[0] * i[1] ans += a print(ans)
def main(): from collections import deque import sys input = sys.stdin.readline N,M = map(int,input().split()) to = [[] for _ in range(N)] for _ in range(M): a,b = map(int,input().split()) a -= 1 b -= 1 to[a].append(b) to[b].append(a) # print(to) guide = [0] * N guide[0] = 1 q = deque() q.append(0) while len(q) > 0: u = q.popleft() for v in to[u]: # print(guide) if guide[v] != 0: continue guide[v] = u+1 q.append(v) print("Yes") for g in guide[1:]: print(g) if __name__ == '__main__': main()
0
null
93,973,044,613,896
292
145
from collections import defaultdict from collections import deque from collections import Counter import math def readInt(): return int(input()) def readInts(): return list(map(int, input().split())) def readChar(): return input() def readChars(): return input().split() s = list(input()) k = readInt() if len(Counter(s))==1: ans = k*len(s)//2 elif s[0]!=s[-1]: ans = 0 i = 0 l = 0 tmp = s[:]+["!"] d = [] while i<len(s): if tmp[i]==tmp[i+1]: i+=1 else: d.append(tmp[l:i+1]) l = i+1 i+=1 for i in d: ans+=len(i)//2 ans*=k else: ans = 0 i = 0 l = 0 tmp = s[:]+["!"] d = [] while i<len(s): if tmp[i]==tmp[i+1]: i+=1 else: d.append(tmp[l:i+1]) l = i+1 i+=1 for i in d[1:-1]: ans+=len(i)//2 ans*=k ans+=len(d[0])//2 ans+=len(d[-1])//2 ans+=(len(d[0])+len(d[-1]))//2*(k-1) print(ans)
import numpy as np s=input() k=int(input()) cnt=1 a=[] ss=s+"." for i in range(len(s)): if ss[i]==ss[i+1]: cnt+=1 else: a.append(cnt) cnt=1 pp=0 if s[0]==s[len(s)-1]: pp=a[0]+a[-1] b=[] if len(a)>1: b.append(pp) b+=a[1:len(a)-1] else: a=[len(s)*k] b=[] else: b=a arr=np.array(a) arr2=np.array(b) a=arr//2 b=arr2//2 if len(s)>=2: print(np.sum(a)+int((k-1)*np.sum(b))) else: print(k//2)
1
175,324,077,728,970
null
296
296
X,Y = map(int, input().split()) if X * 2 > Y: print('No') elif X * 4 < Y: print('No') else: for i in range(0,X+1): if Y == (X * 2) + (i * 2): print('Yes') break else: print('No')
def main(): n=int(input()) n=n+n**2+n**3 print(n) if __name__=="__main__": main()
0
null
12,123,603,768,458
127
115
#!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from collections import deque from operator import itemgetter from itertools import permutations mod = 998244353 inf = float('inf') def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.readline().split())) n, s = LI() a = LI() dp = [[0]*(s+1) for _ in range(n+1)] dp[0][0] = 1 for i in range(1, n+1): x = a[i-1] for j in range(s+1): if dp[i-1][j]: dp[i][j] += dp[i-1][j] * 2 dp[i][j] %= mod if j - x < 0: continue if dp[i-1][j-x]: dp[i][j] += dp[i-1][j-x] dp[i][j] %= mod print(dp[-1][-1])
import sys input = sys.stdin.readline def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def main(): mod=998244353 N,S=MI() A=LI() dp=[[0]*(S+1) for _ in range(N+1)] #dp[i][j]はi番目までで,和がjになるのが何個作れるか. #ただし,その数を使わない場合,選択するかしないか選べるのでダブルでカウント dp[0][0]=1 for i in range(N): #dp[i][0]+=1 for j in range(S+1): dp[i+1][j]+=dp[i][j]*2 dp[i+1][j]%=mod if j+A[i]<=S: dp[i+1][j+A[i]]+=dp[i][j] dp[i+1][j+A[i]]%=mod print(dp[-1][-1]) main()
1
17,693,489,592,612
null
138
138
import itertools n, m, q = map(int, input().split()) abcd_array = [list(map(int, input().split())) for _ in range(q)] def get_sum(A, abcd_array): sum = 0 for abcd in abcd_array: a, b, c, d = abcd if A[b-1] - A[a-1] == c: sum += d return sum candidate_array = list(itertools.combinations_with_replacement(range(1,m+1), n)) ans = 0 for A in candidate_array: ans = max(ans, get_sum(A, abcd_array)) print(ans)
N = int(input()) S = input() cnt = 0 for i in range(10): x100 = S.find(str(i)) if x100 == -1: continue for j in range(10): x10 = S.find(str(j), x100 + 1) if x10 == -1: continue for k in range(10): if S.find(str(k), x10 + 1) != -1: cnt += 1 print(cnt)
0
null
78,373,761,556,532
160
267
A = raw_input().split() S = [] for x in A: if x in ['+', '-', '*']: b = int(S.pop()) a = int(S.pop()) if x == '+': S.append(a + b) elif x == '-': S.append(a - b) else: S.append(a * b) else: S.append(x) print S.pop()
l = input().split() q = [] for e in l: if e == '+': q.append(q.pop() + q.pop()) elif e == '-': q.append(-q.pop() + q.pop()) elif e == '*': q.append(q.pop() * q.pop()) else: q.append(int(e)) print(q[0])
1
36,445,853,960
null
18
18
import copy # 入力 D = int(input()) C = list(map(int, input().split())) S_2d = [] for i in range(D): s_1d = list(map(int, input().split())) S_2d.append(s_1d) last_days = [0] * 26 tot_score = 0 def scoring(day, tot_score, today_contest, last_days): today_plus = S_2d[day - 1][today_contest] today_minus = 0 for j, c in enumerate(C): today_minus += c * (day - last_days[j]) # print(today_plus, today_minus) return (today_plus - today_minus) # A for i in range(D): best_score = -10**100 best_contest = 0 for k, _ in enumerate(C): last_days_tmp = copy.copy(last_days) last_days_tmp[k] = i + 1 k_score = scoring(i + 1, tot_score, k, last_days_tmp) if best_score < k_score: best_score, best_contest = k_score, k last_days[best_contest] = i + 1 tot_score += best_score print(best_contest + 1) # # B # T = [] # for i in range(D): # t = int(input()) # T.append(t) # for i in range(D): # last_days[T[i] - 1] = i + 1 # tot_score += scoring(i+1, tot_score, T[i] - 1) # print(tot_score)
from time import time from random import random limit_secs = 2 start_time = time() D = int(input()) c = list(map(int, input().split())) s = [list(map(int, input().split())) for _ in range(D)] def calc_score(t): score = 0 S = 0 last = [-1] * 26 for d in range(len(t)): S += s[d][t[d]] last[t[d]] = d for i in range(26): S -= c[i] * (d - last[i]) score += max(10 ** 6 + S, 0) return score def solution1(): return [i % 26 for i in range(D)] def solution2(): t = None score = -1 for i in range(26): nt = [(i + j) % 26 for j in range(D)] if calc_score(nt) > score: t = nt return t #def solution3(): # t = [] # for _ in range(D): # for i in range(26): def optimize0(t): return t def optimize1(t): score = calc_score(t) while time() - start_time + 0.15 < limit_secs: d = int(random() * D) q = int(random() * 26) old = t[d] t[d] = q new_score = calc_score(t) if new_score < score: t[d] = old else: score = new_score return t t = solution2() t = optimize0(t) print('\n'.join(str(e + 1) for e in t))
1
9,790,503,242,842
null
113
113
#create date: 2020-07-05 13:34 import sys stdin = sys.stdin from collections import deque def ns(): return stdin.readline().rstrip() def ni(): return int(ns()) def na(): return list(map(int, stdin.readline().split())) def main(): n = ni() g = [list() for _ in range(n)] to = list() for i in range(n-1): a, b = na() a -= 1; b -= 1 g[a].append(b) to.append(b) l = [-1] * n l[0] = 10**10 q = deque([0]) while q: v = q.popleft() vcolor = l[v] for i, w in enumerate(g[v]): q.append(w) if i < vcolor: l[w] = i else: l[w] = i + 1 print(max(l[1:])+1) for i in to: print(l[i]+1) if __name__ == "__main__": main()
N, M, K = list(map(int,input().split())) m = 998244353 # コンビネーション _{N} C_n (n=1,...,N)をmod mで計算する # フェルマーの小定理を利用する # 計算量はO(max(N,m)) class combination_mod: # mod mのもとでのN C nを計算するクラス,計算量はO(N) def __init__(self,N,m): self.N = N self.m = m self.N_factorials = [1 for _ in range(N)] # 1!からN!までをmod mで計算したリスト for n in range(1,N): self.N_factorials[n] = (self.N_factorials[n-1] * (n+1)) % m N_factorial_inv = pow(self.N_factorials[N-1], m-2, m) # N!^{-1} = N!^{m-2} (mod m)を計算する,高速 self.N_factorials_inv = [1 for _ in range(N)] # N!^{-1}から1!^{-1}までをmod mで計算したリスト self.N_factorials_inv[0] = N_factorial_inv for n in range(1,N): # nは1からN-1まで走る self.N_factorials_inv[n] = (self.N_factorials_inv[n-1] * (N-n+1)) % m def calc(self,n): # N C n (mod m)を計算する,計算量はO(1) if n == 0 or n == self.N: return 1 else: c = (self.N_factorials[self.N-1] * self.N_factorials_inv[self.N-n]) % self.m # ここが N! * n!^{-1} c = (c * self.N_factorials_inv[n]) % self.m # ここが * (N-n)!^{-1} return c if N == 1: print(M%m) exit() elif M == 1: if N > K+1: print(0) else: print(1) exit() else: func = combination_mod(N-1,m) ans = 0 for k in range(K+1): ans_temp = M ans_temp = (ans_temp * func.calc(k)) % m ans_temp = (ans_temp * pow(M-1,N-1-k,m)) % m ans += ans_temp ans = ans % m print(ans)
0
null
79,826,552,081,944
272
151
import sys input = sys.stdin.readline #n = int(input()) #l = list(map(int, input().split())) ''' a=[] b=[] for i in range(): A, B = map(int, input().split()) a.append(A) b.append(B)''' n=int(input()) ans=0 for i in range(1,n+1): ans+=i*(n//i)*(1+n//i)//2 print(ans)
n,m=map(int,input().split()) s=input() ans=[] w=n while w: x=0 for i in range(1,m+1): if w-i>=0 and s[w-i]=='0': x=i if x==0: print(-1) exit() else: ans.append(x) w-=x print(*ans[::-1])
0
null
75,300,188,532,712
118
274
s=input() t=input() n=len(s) if s==t[:n] and len(t)==n+1: print('Yes') else: print('No')
import sys def solve(): readline = sys.stdin.buffer.readline mod = 10 ** 9 + 7 s = str(readline().rstrip().decode('utf-8')) t = str(readline().rstrip().decode('utf-8')) print("Yes" if s == t[:len(s)] else "No") if __name__ == '__main__': solve()
1
21,374,600,657,518
null
147
147
from collections import Counter N = int(input()) S = input() D = Counter(S) ans = 1 for d in D.values(): ans *= d if len(D.values()) < 3: ans = 0 for i in range(N): for x in range(1, (N-i+1)//2): if S[i] != S[i+x] and S[i+x] != S[i+2*x] and S[i+2*x] != S[i]: ans -= 1 print(ans)
N = int(input()) A = list(map(int, input().split())) mon = 1000 kabu = 0 for i in range(N-1): if A[i] <= A[i+1]: kabu, mon = divmod(mon, A[i]) mon += kabu * A[i+1] print(mon)
0
null
21,789,216,024,928
175
103
N = int(input()) L = [int(i) for i in input().split()] count = 0 L.sort() for i in range(N) : for j in range(i+1,N) : for k in range(j+1,N) : if L[i]!=L[j]!=L[k]: if ((L[i]+L[j]>L[k]) and (L[j]+L[k]>L[i]) and (L[i]+L[k]>L[j])) : count += 1 print(count)
# coding: utf-8 n = int(input()) L = list(map(int,input().split())) l=[] A=[] ans=0 for i in range(n-2): for j in range(i+1, n-1): for k in range(j+1, n): a=L[i] b=L[j] c=L[k] if a!=b and b!=c and c!=a and a+b>c and b+c>a and c+a>b: #print(i+1,j+1,k+1) #print(a,b,c) ans += 1 #print(L) #print() print(ans)
1
5,024,859,775,848
null
91
91
n,r = map(int, input().split()) if n>10: print(r) else: print(int(100*(10-n)+r))
X=int(input()) i=1 while True: if (X*i)%360==0: print(i) exit() i+=1
0
null
38,258,891,812,790
211
125
#!/usr/bin/env python3 def inp(): n, m = map(int, input().split()) return n - 1, m - 1 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 rem(cand, p, q): cand[p] += 1 cand[q] += 1 n, m, k = map(int, input().split()) UF = UnionFind(n) non_cand = [1] * n for _ in range(m): a, b = inp() UF.union(a, b) rem(non_cand, a, b) for _ in range(k): c, d = inp() if UF.same(c, d): rem(non_cand, c, d) ans = [UF.size(i) - non_cand[i] for i in range(n)] print(*ans)
import sys sys.setrecursionlimit(10**7) readline = sys.stdin.buffer.readline def readstr():return readline().rstrip().decode() def readstrs():return list(readline().decode().split()) def readint():return int(readline()) def readints():return list(map(int,readline().split())) def printrows(x):print('\n'.join(map(str,x))) def printline(x):print(' '.join(map(str,x))) n = readint() mod = 10**9+7 print((pow(10,n,mod)-pow(9,n,mod)*2+pow(8,n,mod)+mod*2)%mod)
0
null
32,226,294,347,808
209
78
x,y=map(int,input().split()) print(('No','Yes')[2*x<=y<=4*x and -~y%2])
X,Y=list(map(int,input().split())) judge=False for i in range(0,X+1): if i*2+(X-i)*4==Y: judge=True if judge: print("Yes") else: print("No")
1
13,838,664,026,812
null
127
127
n = int(input()) result = '' for i in range(3, n+1): if (i % 3 == 0) or (i % 10 == 3) or ('3' in str(i)): result += (' ' + str(i)) print(result)
def Check_Num(n): for i in range(1,n + 1): x = i if (x % 3 == 0): print(' {}'.format(i),end = '') continue elif (x % 10 == 3): print(' {}'.format(i),end = '') continue x //= 10 while (x > 0): if (x % 10 == 3): print(' {}'.format(i),end = '') break x //= 10 print() if __name__ == '__main__': n = int(input()) Check_Num(n)
1
919,496,170,748
null
52
52
N,K=map(int,input().split()) print(K if N>=10 else K+(1000-100*N))
from math import sqrt sigma=[] while True: total=0 nval=0 n=int(input()) if n==0: break score_list=map(float,raw_input().split(" ")) for i in score_list: total+=i average=total/n for i in score_list: nval+=(average-i)**2 val=nval/n sigma.append(sqrt(val)) for i in sigma: print i
0
null
31,703,205,446,088
211
31
n = int(input()) a = list(map(int, input().split())) if n % 2 == 0: ans, cnt = 0, 0 for i in range(n): if i % 2 == 1: ans += a[i] cnt += a[i] for i in range(n): if i % 2 == 0: cnt += a[i] else: cnt -= a[i] ans = max(cnt, ans) else: a.insert(0, 0) dp = [[0] * (n + 1) for _ in range(3)] for i in range(3): for j in range(1 + i, n + i - 1, 2): if i == 0: if j == 1: dp[i][j] = a[j] else: dp[i][j] = dp[i][j - 2] + a[j] else: dp[i][j] = max(dp[i - 1][j - 1], dp[i][j - 2] + a[j]) ans = dp[2][n] print(ans)
import sys h,w,m = map(int,input().split()) h_lst = [[0,i] for i in range(h)] w_lst = [[0,i] for i in range(w)] memo = [] for i in range(m): x,y = map(int,input().split()) h_lst[x-1][0] += 1 w_lst[y-1][0] += 1 memo.append((x-1,y-1)) h_lst.sort(reverse = True) w_lst.sort(reverse = True) Max_h = h_lst[0][0] Max_w = w_lst[0][0] h_ans = [h_lst[0][1]] w_ans = [w_lst[0][1]] if h != 1: s = 1 while s < h and h_lst[s][0] == Max_h: h_ans.append(h_lst[s][1]) s+= 1 if w!= 1: t=1 while t < w and w_lst[t][0] == Max_w: w_ans.append(w_lst[t][1]) t += 1 memo = set(memo) #探索するリストは、最大を取るものの集合でなければ計算量はO(m)にはならない! for j in h_ans: for k in w_ans: if (j,k) not in memo: print(Max_h+Max_w) sys.exit() print((Max_h+Max_w)-1)
0
null
21,054,591,733,980
177
89
n, m = map(int, input().split()) a = sorted(list(map(int, input().split())), reverse=True) 総投票数 = sum(a) x = 総投票数 / (4 * m) for i in range(m): if a[i] < x: flag = 0 break else: flag = 1 print(["No", "Yes"][flag])
import math N, M = map(int, input().split()) A = list(map(int, input().split())) S = sum(A) th = math.ceil(S / (4*M)) ans = 0 for a in A: if a >= th: ans += 1 print("Yes" if ans >= M else "No")
1
38,917,235,840,132
null
179
179
import math prime = [2] for i in range(3, int(math.sqrt(200000)), 2): for j in prime: if i % j == 0: break elif math.sqrt(i) < j: prime.append(i) break X = int(input()) if X % 2 == 0 and X != 2: X += 1 cand = 0 while not cand: for p in prime: if X != 2 and X % p == 0: break elif math.sqrt(X) < p: cand = X break X += 2 print(cand)
# Original Submission At: https://atcoder.jp/contests/abc149/submissions/16823042 x= int(input()) def prime_check(num,count): while True: while num % count == 0: num = num + 1 count = 2 if num <= count**2: print(num) break else: count = count + 1 if x==2 : print (2) else: prime_check(x,2)
1
105,473,337,942,422
null
250
250