code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.71M
180,629B
code1_group
int64
1
299
code2_group
int64
1
299
def main(): while True: number_string = input() if number_string == '0': break print(sum(map(int, list(number_string)))) main()
''' ITP-1_8-B ??°????????? ?????????????????°???????????????????¨??????????????????°????????????????????????????????? ???Input ?????°??????????????????????????\?????¨??????????????????????????????????????????????????????????????´??° x ?????????????????§????????????????????? x ??? 1000 ?????\????????´??°??§?????? x ??? 0 ?????¨?????\?????????????????¨??????????????????????????????????????????????????????????????£???????????????????????? ???Output ????????????????????????????????????x ??????????????????????????????????????????????????? ''' while True: # inputData inputData = input() if inputData == '0': break # outputData outputData = 0 for cnt0 in inputData: outputData += int(cnt0) print(outputData)
1
1,592,700,519,410
null
62
62
station = input() print("Yes" if "AB" in station or "BA" in station else "No")
S = str(input()) if S[0] == S[1] == S[2]: print('No') else: print('Yes')
1
54,637,299,648,890
null
201
201
import sys input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().split()) inl = lambda: list(map(int, input().split())) out = lambda x: print('\n'.join(map(str, x))) n = ini() ans = 0 tmp = 1 while n > 0: n //= 2 ans += tmp tmp *= 2 print(ans)
import math h = int(input()) l = int(math.log(h, 2)) p = (2**l)*2-1 print(p)
1
80,077,148,875,830
null
228
228
from collections import deque n, m = map(int, input().split()) way = {} for i in range(m): a, b = map(int, input().split()) if a not in way: way[a] = [] if b not in way: way[b] = [] way[a].append(b) way[b].append(a) queue = deque([1]) ok = set([1]) ans = [0] * (n+1) while queue: now = queue.popleft() for i in way[now]: if i in ok: continue ans[i] = now queue.append(i) ok.add(i) print("Yes") for i in range(2, n+1): print(ans[i])
import queue q = queue.Queue() bool = True def bfs(): q.put(0) while not q.empty(): now = q.get() for i in nodes[now]: if dist[i] != -1: continue dist[i] = dist[now] + 1 q.put(i) ans[i] = now # bool = False N, M = map(int, input().split()) nodes = [[] for i in range(N)] idxStock = [] for i in range(M): a, b = map(int, input().split()) nodes[a - 1].append(b - 1) nodes[b - 1].append(a - 1) dist = [-1] * N ans = [-1] * N bfs() if bool: print("Yes") for i in range(1, N): print(ans[i] + 1) else: print("No")
1
20,520,474,183,638
null
145
145
import math from collections import defaultdict,deque #from itertools import permutations ml=lambda:map(int,input().split()) ll=lambda:list(map(int,input().split())) ii=lambda:int(input()) ip=lambda:list(input()) ips=lambda:input().split() """========main code===============""" n=ii() s=ip() ans=1 for i in range(1,n): if(s[i]!=s[i-1]): ans+=1 print(ans)
# -*- coding: utf-8 -*- n = int(input()) s = input() ans = 1 tmp = s[0] for c in s: if tmp != c: ans += 1 tmp = c print(ans)
1
169,881,176,255,072
null
293
293
A, B, C = input().split() S = A + B + C ans = 'No' for i in range(len(S)): if S.count(S[i]) == 2: ans = 'Yes' break print(ans)
a = [int(i) for i in input().split()] if (a[0] == a[1] and a[0] != a[2]) or (a[0] == a[2] and a[0] != a[1]) or (a[2] == a[1] and a[2] != a[0]): print('Yes') else: print('No')
1
68,346,187,534,020
null
216
216
def main(): S = input() if S[2] == S[3] and S[4] == S[5]: print("Yes") else: print("No") if __name__ == '__main__': main()
s = input() print('Yes') if s[2:3] == s[3:4] and s[4:5] == s[5:6] else print('No')
1
42,019,735,548,670
null
184
184
import math while(1): a=0 n=int(input()) if n==0: break; s=list(map(int,input().split())) m=sum(s)/len(s) for i in range(n): a=a+pow(s[i]-m,2) print(math.sqrt(a/n))
while True: n = int(input()) if n == 0: break else: data_set = [int(i) for i in input().split()] m = sum(data_set) / n v = 0 for i in data_set: diff = i - m v += diff ** 2 v /= n print(v ** 0.5)
1
190,271,007,740
null
31
31
N = [int(_) for _ in list(input())] a, b = 0, 1 for n in N: a, b = min(a+n, b+10-n), min(a+(n+1), b+10-(n+1)) print(a)
from math import * def distance (p,n,x,y): dis = 0.0 if p == "inf": for i in range(0,n) : if dis < abs(x[i]-y[i]): dis = abs(x[i]-y[i]) else : for i in range(0,n) : dis += abs(x[i]-y[i])**p dis = dis ** (1.0/p) return dis if __name__ == '__main__' : n = int(input()) x = map(int,raw_input().split()) y = map(int,raw_input().split()) print distance(1,n,x,y) print distance(2,n,x,y) print distance(3,n,x,y) v = distance('inf',n,x,y) print "%.6f" % v
0
null
35,728,434,239,498
219
32
n, m = map(int, input().split()) ab = [list(map(int, input().split())) for _ in range(m)] class Union: def __init__(self, n): self.parents = [-1] * n def root(self, x): if self.parents[x] < 0: return x else: return self.root(self.parents[x]) def unite(self, x, y): x = self.root(x) y = self.root(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 uni = Union(n) for a, b in ab: uni.unite(a-1, b-1) print(-min(uni.parents))
n = int(input()) data = [int(i) for i in input().split()] print(f'{min(data)} {max(data)} {sum(data)}')
0
null
2,364,626,783,872
84
48
s = input() INF = float('inf') dp = [[INF,INF] for _ in range(len(s)+1)] dp[0][0]=0 dp[0][1]=1 for i in range(len(s)): dp[i+1][0] = min(dp[i][0]+int(s[i]), dp[i][1]+10-int(s[i]), dp[i][1]+int(s[i])+1) dp[i+1][1] = min(dp[i][0]+int(s[i])+1,dp[i][1]+10-int(s[i])-1) print(dp[-1][0])
n = int(input()) p= [] AC = 0 WA = 0 TLE = 0 RE = 0 for i in range(n): p.append(input()) for j in p : if j == "AC": AC += 1 elif j == "WA": WA += 1 elif j == "TLE": TLE += 1 else: RE += 1 print("AC x " + str(AC)) print("WA x " + str(WA)) print("TLE x " + str(TLE)) print("RE x " + str(RE))
0
null
40,008,436,055,588
219
109
from itertools import repeat from itertools import combinations def rec(s, i, total, m): if total == m: return 1 if len(s) == i or total > m: return 0 return rec(s, i + 1, total, m) + rec(s, i + 1, total + s[i], m) def makeCache(s): cache = {} for i in range(len(s)): comb = list(combinations(s, i)) for c in comb: cache[sum(c)] = 1 return cache def loop(s, m): for i in range(len(s)): comb = list(combinations(s, i)) for c in comb: if sum(c) == m: return 1 return 0 if __name__ == "__main__": n = int(input()) a = [int (x) for x in input().split()] q = int(input()) m = [int (x) for x in input().split()] s = makeCache(a) for i in m: #print("yes") if rec(a, 0, 0, i) > 0 else print("no") #print("yes") if loop(a, i) > 0 else print("no") print("yes") if i in s else print("no")
n = int(input()) A = list(map(int,input().split())) m = int(input()) B = list(input().split()) for i in range(m): B[i] = int(B[i]) def solve(x,y): if x==n: S[y] = 1 else: solve(x+1,y) if y+A[x] < 2001: solve(x+1,y+A[x]) S = [0 for i in range(2001)] solve(0,0) for i in range(m): if S[B[i]] == 1: print("yes") else: print("no")
1
102,296,313,088
null
25
25
x = list(map(int , input().split())) s = set() for i in x: if i not in s: s.add(i) if len(s) == 2: print('Yes') else: print('No')
# -*- coding: utf-8 -*- ABC = input() ABC = ABC.replace(" ", "") if ABC.count(ABC[0]) == 2 or ABC.count(ABC[1]) == 2 or ABC.count(ABC[2]) == 2: print("Yes") else: print("No")
1
67,923,744,373,760
null
216
216
a,b,m = input().split() a = list(map(int,input().split())) b = list(map(int,input().split())) xyc =[] for i in range(int(m)): xyc.append(input()) min = min(a) + min(b) for i in xyc: x,y,c = map(int, i.split()) if min > a[x-1] + b[y-1] - c : min = a[x-1] + b[y-1] - c print(min)
A,B,M = map(int,input().split()) a = list(map(int,input().split())) b = list(map(int,input().split())) ans = min(a)+min(b) for i in range(M): x,y,z = map(int,input().split()) s = a[x-1]+b[y-1]-z ans = (s if s < ans else ans) print(ans)
1
53,937,924,986,504
null
200
200
K = int(input()) A, B = map(int, input().split()) i = A while (i % K != 0) and (i <= B): i += 1 if i == B+1: print("NG") else: print("OK")
x = int(input()) a, b = map(int, input().split()) ans=0 for i in range(a,b+1): if i%x==0: ans=1 break if ans==1: print('OK') else: print('NG')
1
26,496,247,232,128
null
158
158
def check(P): global k, T, n i = 0 for j in range(k): s = 0 while s + T[i] <= P: s += T[i] i += 1 if (i == n): return n return i def solve(): left = 0 right = 100000 * 10000 while right - left > 1: mid = (left + right) // 2 v = check(mid) if (v >= n): right = mid else: left = mid return right if __name__ == '__main__': n, k = map(int, input().split()) T = [int(input()) for i in range(n)] ans = solve() print(ans)
import sys n, truck_num = map(int, input().split()) weights = [int(x) for x in map(int, sys.stdin)] def main(): # 最小値と最大値をもとに二分探索する print(binary_search(max(weights), sum(weights))) def binary_search(left, right): """二分探索 :param left: 最小値 :param right: 最大値 :return: """ while left < right: # 真ん中の値を割り当てる middle = (left + right) // 2 # 真ん中の値で一旦シミュレート if simulate(middle, weights, truck_num): # OKならば、最大値をシミュレートした値に right = middle else: # NGならば、最小値をシミュレートした+1に left = middle + 1 return left def simulate(mid, wei, t_num): """ :param mid: 中央値 :param wei: 荷物が格納されたリスト :param t_num: トラックの台数 :return: シミュレートOKかNGか """ count = 1 tmp = 0 for w in wei: tmp += w # 積載量(tmp)が求める答え(mid)より大きくなったら if mid < tmp: # tmpを次の積載物に初期化 tmp = w count += 1 if t_num < count: return False return True if __name__ == '__main__': main()
1
84,729,217,020
null
24
24
n = input() k = int(n[-1]) if k == 3: print("bon") elif k == 0 or k == 1 or k == 6 or k == 8: print("pon") else: print("hon")
n = input() x = list(n) length = len(x) if x[length-1] == "3": print("bon") elif x[length-1] == "0" or x[length-1] == "1" or x[length-1] == "6" or x[length-1] =="8": print("pon") else: print("hon")
1
19,381,761,660,560
null
142
142
n = int(input()) As = list(map(int, input().split())) internal_max = [1]*(n+1) internal_max[0] = 1-As[0] for i in range(1,n+1): internal_max[i] = 2*internal_max[i-1]-As[i] depth_sum = [0]*(n+1) depth_sum[n] = As[n] judge = False for i in range(n-1, -1, -1): if depth_sum[i+1] > internal_max[i]*2: judge = True break else: depth_sum[i] = As[i] + min(internal_max[i], depth_sum[i+1]) if n == 0: if As[0] > 1: judge = True if judge: print(-1) else: print(sum(depth_sum))
N = int(input()) A = list(map(int, input().split())) A.reverse() min_max = [[] for _ in range(N+1)] def main(): min_max[0] = [A[0], A[0]] for i in range(1, N+1): a = A[i] pre_min, pre_max = min_max[i-1] min_max[i] = [(1+pre_min)//2 +a, pre_max +a] min_max.reverse() if min_max[0][0] != 1: print(-1) return A.reverse() ans = 1 pre = 1 for i in range(1, N+1): a = A[i-1] pre = min(2*(pre -a), min_max[i][1]) ans += pre print(ans) main()
1
18,783,855,721,870
null
141
141
S = input() print(chr(ord(S) + 1))
def solve(): c = input() print(chr(ord(c)+1)) if __name__ == '__main__': solve()
1
92,150,567,109,600
null
239
239
#Is it Right Triangre? n = int(input()) for i in range(n): set = input(). split() set = [int(a) for a in set] #int????????? set.sort() if set[0] ** 2 + set[1] ** 2 == set[2] ** 2: print("YES") else: print("NO")
def LI(): return list(map(int, input().split())) a, b, c = LI() if c-a-b < 0: ans = "No" elif 4*a*b < (c-a-b)**2: ans = "Yes" else: ans = "No" print(ans)
0
null
25,905,555,517,490
4
197
N = int(input()) dic = {} for i in range (N): s = input() if s in dic: dic[s] += 1 else: dic[s] = 1 sai = max(dic.values()) for j in sorted(k for k in dic if dic[k] == sai): print(j)
import collections N = int(input()) S = [input() for _ in range(N)] c = collections.Counter(S) d = c.most_common() cnt = 0 for i in range(len(c)-1): if d[i][1] == d[i+1][1]: cnt += 1 else: break e = [] for j in range(cnt+1): e.append(d[j][0]) e.sort() for k in range(len(e)): print(e[k])
1
70,050,929,104,508
null
218
218
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools import time,random,resource sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def pe(s): return print(str(s), file=sys.stderr) def JA(a, sep): return sep.join(map(str, a)) def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a) def main(): n = I() s = S() m = {} m[0] = 0 def f(i): if i in m: return m[i] c = 0 ii = i while ii > 0: c += ii % 2 ii //= 2 t = i % c m[i] = f(t) + 1 return m[i] c = len([_ for _ in s if _ == '1']) t = int(s, 2) cm = (c+1) * c * (c-1) if c > 1: t %= cm r = [] k = 1 for i in range(n-1,-1,-1): if t == k: r.append(0) elif s[i] == '1': r.append(f((t - k) % (c-1)) + 1) else: r.append(f((t + k) % (c+1)) + 1) k *= 2 if c > 1: k %= cm return JA(r[::-1], "\n") print(main())
import numpy as np N = int(input()) X = str(input()) num_one = X.count("1") dp = [-1] * N dp[0] = 0 def dfs(n): if dp[n] == -1: dp[n] = 1 + dfs(n % bin(n).count('1')) return dp[n] num_one = X.count("1") bool_arr = np.array([True if X[N-i-1] == "1" else False for i in range(N)]) zero_ver = np.array([pow(2, i, num_one + 1) for i in range(N)]) zero_ver_sum = sum(zero_ver[bool_arr]) one_ver = -1 one_ver_sum = 0 flag = False if num_one != 1: one_ver = np.array([pow(2, i, num_one - 1) for i in range(N)]) one_ver_sum = sum(one_ver[bool_arr]) else: flag = True for i in range(1,N+1): start = 0 if bool_arr[N-i] == False: start = (zero_ver_sum + pow(2, N - i, num_one + 1)) % (num_one + 1) print(dfs(start)+1) else: if flag: print(0) else: start = (one_ver_sum - pow(2, N - i, num_one - 1)) % (num_one - 1) print(dfs(start)+1)
1
8,128,447,293,180
null
107
107
def call(n): s = "" for i in range(1,n+1): if i%3 == 0: s += " {0}".format(i) else: x = i while x > 0: if x%10 == 3: s += " {0}".format(i) break x = x // 10 print(s) m = int(input()) call(m)
#!/usr/bin/env python3 import sys import numpy as np YES = "Yes" # type: str NO = "No" # type: str def solve(K: int, X: int): if 500*K>=X: print(YES) else: print(NO) return # Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template) def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() K = int(next(tokens)) # type: int X = int(next(tokens)) # type: int solve(K, X) if __name__ == '__main__': main()
0
null
49,760,641,338,038
52
244
if __name__ == '__main__': N, M = map(int, input().split()) S = [] C = [] for i in range(M): s, c = map(int, input().split()) s -= 1 S.append(s) C.append(c) for num in range(0, pow(10, N)): st_num = str(num) if len(str(st_num))!=N: continue cnt = 0 for m in range(M): if int(st_num[S[m]])==C[m]: cnt += 1 if cnt==M: print(st_num) quit() print(-1)
def func(num, div): return num // div l, r, d = map(int, input().split()) print(func(r, d) - func(l - 1, d))
0
null
34,128,058,690,144
208
104
def main(): s = input() if s == 'ABC': print('ARC') else: print('ABC') if __name__ == "__main__": main()
S = input() if S[1] == 'R': T = 'ABC' else: T = 'ARC' print(T)
1
24,055,828,077,568
null
153
153
n = int(input()) a = list(map(int, input().split())) first_half = 0 latter_half = sum(a) min_diff = latter_half for i in range(n): first_half += a[i] latter_half -= a[i] diff = abs(first_half - latter_half) min_diff = min(min_diff, diff) print(min_diff)
n = int(input()) A = list(map(int, input().split())) for i in range(n - 1): A[i + 1] += A[i] minv = float('inf') for a in A[:-1]: minv = min(minv, abs(A[-1]/2 - a)) print(int(minv * 2))
1
142,266,495,377,092
null
276
276
# coding: utf-8 x = int(input()) ans = x // 500 x = x - ans * 500 ans = ans * 1000 ans += (x // 5 * 5) print(ans)
N, M = map(int, input().split()) An = [int(i) for i in input().split()] total = sum(An) if total > N: print('-1') else: print(N - total)
0
null
37,366,374,317,188
185
168
import math n=int(input()) while n != 0 : sums = 0.0 s = list(map(float,input().split())) m = sum(s)/n for i in range(n): sums += ((s[i]-m)**2)/n print(math.sqrt(sums)) n = int(input())
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines class UnionFind: def __init__(self, n): self.parents = [i for i in range(n)] self.rank = [0 for _ in range(n)] self.length = [1 for _ in range(n)] def makeSet(self, n): self.parents = [i for i in range(n)] self.rank = [0 for _ in range(n)] self.length = [1 for _ in range(n)] def find(self, x): if self.parents[x] == x: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.rank[x] < self.rank[y]: self.parents[x] = y self.length[y] += self.length[x] else: self.parents[y] = x self.length[x] += self.length[y] if self.rank[x] == self.rank[y]: self.rank[x] += 1 def getLength(self, x): x = self.find(x) return self.length[x] def isSameGroup(self, x, y): return self.find(x) == self.find(y) def main(): N, M, K = map(int, readline().split()) friend = [set() for _ in range(N)] block = [set() for _ in range(N)] uf = UnionFind(N) for _ in range(M): a, b = map(int, readline().split()) a-=1 b-=1 friend[a].add(b) friend[b].add(a) uf.unite(a, b) for _ in range(K): c, d = map(int, readline().split()) c-=1 d-=1 block[c].add(d) block[d].add(c) for i in range(N): cnt = 0 for blk in block[i]: if uf.isSameGroup(i, blk): cnt += 1 ans = uf.getLength(i)-cnt-len(friend[i])-1 if i == N-1: print(ans) else: print(ans, end=" ") if __name__ == '__main__': main()
0
null
30,907,209,083,612
31
209
a = str(input()) if 'A'<=a and a<='Z': print('A') else: print('a')
if __name__ == '__main__': s = input() if s.islower(): print("a") else: print("A")
1
11,285,424,423,310
null
119
119
N, K, C = map(int, input().split()) S = list(input()) l = [0] * N r = [0] * N cnt = 1 yutori = 10 ** 10 for i, s in enumerate(S): if s == "o" and yutori > C: l[i] = cnt yutori = 0 cnt += 1 yutori += 1 S.reverse() yutori = 10 ** 10 cnt = K for i, s in enumerate(S): if s == "o" and yutori > C: r[i] = cnt yutori = 0 cnt -= 1 yutori += 1 ans = set() r.reverse() for i in range(N): if l[i] == r[i] and l[i] > 0: ans.add(i+1) print(*ans, sep="\n")
""" 入力例 1 11 3 2 ooxxxoxxxoo ->6 入力例 2 5 2 3 ooxoo ->1 ->5 入力例 3 5 1 0 ooooo -> 入力例 4 16 4 3 ooxxoxoxxxoxoxxo ->11 ->16 """ n,k,c = map(int,input().split()) s = input() r=[0]*n l=[0]*n ki=0 ci=100000 for i in range(n): ci += 1 if s[i]=='x': continue if ci > c: ci = 0 ki+=1 l[i]=ki if ki == k: break ki=k ci=100000 for i in range(n): ci += 1 if s[n-1-i]=='x': continue if ci > c: ci = 0 r[n-1-i]=ki ki-=1 if ki == 0: break ret=[] for i in range(n): if r[i]==l[i] and r[i]!=0: ret.append(i+1) # print(l) # print(r) for i in range(len(ret)): print(ret[i])
1
40,396,188,142,114
null
182
182
s = list(input()) f1 = s == list(reversed(s)) f2 = s[:(len(s)-1)//2] == list(reversed(s[:(len(s)-1)//2])) f3 = s[(len(s)+2)//2:] == list(reversed(s[(len(s)+2)//2:])) print("Yes" if all([f1, f2, f3]) else "No")
A = input().split() a = A.count(A[0]) b = A.count(A[1]) c = A.count(A[2]) if a == 2 or b == 2 or c == 2: print("Yes") else: print("No")
0
null
56,989,265,925,482
190
216
N = int(input()) S = input() def alpha2num(alpha): num=0 for index, item in enumerate(list(alpha)): num += pow(26,len(alpha)-index-1)*(ord(item)-ord('A')+1) return num def num2alpha(num): if num<=26: return chr(64+num) elif num%26==0: return num2alpha(num//26-1)+chr(90) else: return num2alpha(num//26)+chr(64+num%26) li = [] for s in S: num = alpha2num(s) num += N num %= 26 if num==0: num = 26 ap = num2alpha(num) li.append(ap) print("".join(li))
MOD = 10 ** 9 + 7 INF = 10 ** 10 import sys sys.setrecursionlimit(100000000) dy = (-1,0,1,0) dx = (0,1,0,-1) def main(): n,k = map(int,input().split()) a = list(map(int,input().split())) cum = [0] * (n + 1) dic = {0:1} ans = 0 for i in range(min(n,k - 1)): cum[i + 1] = (cum[i] + a[i])%k tmp = (cum[i + 1] - i - 1)%k if tmp in dic: dic[tmp] += 1 else: dic[tmp] = 1 for v in dic.values(): ans += v * (v - 1)//2 for i in range(max(n - k + 1,0)): dic[(cum[i] - i)%k] -= 1 cum[i + k] = (cum[i + k - 1] + a[i + k - 1])%k tmp = (cum[i + k] - i - k)%k if tmp in dic: ans += dic[tmp] dic[tmp] += 1 else: dic[tmp] = 1 print(ans) if __name__ =='__main__': main()
0
null
136,214,606,505,778
271
273
a = input(); print(int(a.split()[0])*int(a.split()[1]),int(a.split()[0]) * 2 + int(a.split()[1])*2, end="\n")
#coding:utf-8 import sys ab=sys.stdin.readline() rect=ab.split( ' ' ) for i in range(2): rect[i]=int( rect[i]) print( "{} {}".format( rect[0]*rect[1], rect[0]*2+rect[1]*2) )
1
308,958,388,662
null
36
36
a, b = map(int, input().split()) if 1<=a<=9 and 1<=b<=9: print(a*b) else: print(-1)
while 1: try:print input() except:break
0
null
79,476,940,341,348
286
47
a = int(input()) f = False for i in range(1,10): if a % i == 0 and a/i < 10: f = True break if f: print("Yes") else: print("No")
N = int(input()) A = [] for n in range(1,10): for m in range(1,10): A.append(n*m) if N in A: print("Yes") else: print("No")
1
159,402,627,136,830
null
287
287
n = int(input()) a = [int(s) for s in input().split()] if len(set(a)) == n: print("YES") else: print("NO")
def perm(n, k, p): ret = 1 for i in range(n, n-k, -1): ret = (ret * i)%p return ret def comb(n, k, p): a = perm(n, k, p) b = perm(k, k, p) return (a*pow(b, -1, p))%p S = int(input()) ans = 0 S -= 3 t = 0 while S >= 0: ans += comb(S+t,t, 10**9+7) S -= 3 t += 1 print(ans%(10**9+7))
0
null
38,851,887,629,622
222
79
b = [] while True: a = input() k = 0 if a != "0": for i in range(len(a)): k += int(a[i]) b.append(k) else: break for i in range(len(b)): print(b[i])
# ?????????????????°???????????????????¨??????????????????°?????? while 1: # ?¨??????\???????????°??????????????? input_num = list(input()) # ???????????????"0"??\?????§?????? if int(input_num[0]) == 0: break # print(input_num) # ??????????¨?????????????????????° digitTotal = 0 for i in range(0, len(input_num)): digitTotal += int(input_num[i]) print("{0}".format(digitTotal))
1
1,594,490,346,760
null
62
62
n, W = map(int, input().split()) ab = [tuple(map(int, input().split()))for _ in range(n)] ab.sort(reverse=True) dp = [0]*W for w, v in ab: for j in reversed(range(W)): if j-w < 0: break if dp[j] < dp[j-w]+v: dp[j] = dp[j-w]+v if dp[0] < v: dp[0] = v print(max(dp))
N, K = [int(_) for _ in input().split()] P = [int(_) for _ in input().split()] ans = 0.0 k = 0 v = 0.0 for i in range(N): v += (P[i] + 1) / 2 k += 1 if k > K: v -= (P[i-K] + 1) / 2 k -= 1 ans = max(ans, v) print(ans)
0
null
112,930,541,135,270
282
223
def check(p): global k, wlist loadage = 0 num = 1 for w in wlist: loadage += w if loadage > p: num += 1 if num > k: return False loadage = w return True n, k = map(int, input().split()) wlist = [] for _ in range(n): wlist.append(int(input())) maxw = max(wlist) sumw = sum(wlist) p = 0 while maxw < sumw: p = (maxw + sumw) // 2 if check(p): sumw = p else: maxw = p = p+1 print(p)
n, k = map(int, input().split()) l = list(int(input()) for i in range(n)) left = max(l)-1; right = sum(l) while left+1 < right: #最大値と合計値の間のどこかに考えるべき値が存在する mid = (left + right) // 2 cnt = 1; cur = 0 #初期化 for a in l: if mid < cur + a: cur = a cnt += 1 else: cur += a if cnt <= k: right = mid else: left = mid print(right)
1
88,406,860,398
null
24
24
h1, m1, h2, m2, k = [int(_) for _ in input().split()] print((h2 - h1) * 60 + m2 - m1 - k)
from sys import stdin nii=lambda:map(int,stdin.readline().split()) lnii=lambda:list(map(int,stdin.readline().split())) h1,m1,h2,m2,k=nii() minute=(h2-h1)*60 minute+=m2-m1 minute-=k print(minute)
1
18,138,435,704,860
null
139
139
S = input() f = S[0] if S.count(f) == 3 : print('No') else : print('Yes')
from decimal import Decimal X=int(input()) c =Decimal(100) C=0 while c<X: c=Decimal(c)*(Decimal(101))//Decimal(100) C+=1 print(C)
0
null
40,913,215,941,924
201
159
MAX = 2*10**6 MOD = 10**9+7 fac = [0] * (MAX) finv = [0] * (MAX) inv = [0] * (MAX) def comb_init(): fac[0] = fac[1] = 1 finv[0] = finv[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 comb(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 if __name__ == '__main__': k = int(input()) s = input() n = len(s) comb_init() ans = 0 for i in range(k+1): val = comb(i+n-1, n-1) val *= pow(25, i, MOD) val %= MOD val *= pow(26, k-i, MOD) val %= MOD ans += val ans %= MOD print(ans)
K = int(input()) S = input() m = 1000000007 result = 0 t = pow(26, K, m) u = pow(26, m - 2, m) * 25 % m l = len(S) for i in range(K + 1): # result += pow(26, K - i, m) * mcomb(len(S) - 1 + i, i) * pow(25, i, m) result = (result + t) % m t = (t * u) % m * (l + i) % m * pow(i + 1, m - 2, m) % m print(result)
1
12,718,782,609,788
null
124
124
from itertools import combinations while True: n,m=map(int,input().split()) if n==m==0: break print(sum(1 for p in combinations(range(1,n+1),3) if sum(p)==m))
import sys while True: n, x = [ int( val ) for val in sys.stdin.readline().split( " " ) ] if 0 == n and 0 == x: break cnt = 0 ave = x // 3 for i in range( 1, ave ): ave2 = (x-i) // 2 for j in range( i+1, ave2+1 ): k = x-i-j if j < k and k <= n: cnt += 1 print( cnt )
1
1,296,340,537,952
null
58
58
import sys from collections import deque import numpy as np import math sys.setrecursionlimit(10**6) def S(): return sys.stdin.readline().rstrip() def SL(): return map(str,sys.stdin.readline().rstrip().split()) def I(): return int(sys.stdin.readline().rstrip()) def IL(): return map(int,sys.stdin.readline().rstrip().split()) def solve(): la = [(item,i+1) for i,item in enumerate(a)] la.sort() for rep in la: print(f"{rep[1]} ",end="") return if __name__=='__main__': n = I() a = list(IL()) solve()
n = int(input()) s = [input() for i in range(n)] c0 = 0 c1 = 0 c2 = 0 c3 = 0 for i in range(len(s)): if s[i] == "AC": c0 += 1 elif s[i] == "WA": c1 += 1 elif s[i] == "TLE": c2 += 1 else: c3 += 1 print("AC x ", str(c0)) print("WA x ", str(c1)) print("TLE x ", str(c2)) print("RE x ", str(c3))
0
null
94,779,768,121,532
299
109
a = range(1, 10) [print('{}x{}={}'.format(i, j, i * j)) for i in a for j in a]
from collections import defaultdict N = int(input()) *A,=map(int,input().split()) ''' 方針: - 各A_i,(i<h)ごとにf(h,j)=A_h+A_j-|h-j|の値がf(i,j)に比べてどれだけ変化するかを計算し、 リストに格納(①) - 各要素A_k,(j<k)ごとにf(i,k)=A_i+A_k-|i-k|の値がf(i,j)に比べてどれだけ変化するかを 計算し、カウントをとる(②) - 再度ループを回して①と②を照合し、値が一致する組数をansに加算 ''' ans=0 diff_list=[] #①照合用の差分リスト count=defaultdict(int) #②各要素がどれだけはみ出ているかのカウント #前処理として、最初のループで①と②を作成 for i in range(1,N): if i == A[0]+A[i]: ans += 1 d1 = A[i]-A[0] d2 = i diff_list.append(d1+d2) count[A[0]+A[i]-i] += 1 for i in range(N-1): count[A[0]+A[i+1]-(i+1)] -= 1 #その要素自身を忘れずに引く d = diff_list[i] ans += count[-d] print(ans)
0
null
13,029,302,144,992
1
157
import time n, k = map(int, input().split()) w = [0] * n for i in range(n): w[i] = int(input()) def check(p): remain_track = k - 1 remain_p = p for a in range(n): if w[a] > p: return False if remain_p >= w[a]: remain_p -= w[a] else: if remain_track == 0: return False else: remain_track -= 1 remain_p = p - w[a] # print(a, w[a], remain_p, remain_track) return True next = 10 ** 9 prev = next for i in range(200): if check(next): prev = next next = next // 2 else: next = (next + prev) // 2 print(prev)
def prime_factors(n): d = {} while n%2 == 0: d[2] = d.get(2, 0) + 1 n //= 2 i = 3 while i*i <= n: while n%i == 0: d[i] = d.get(i, 0) + 1 n //= i i += 2 if n > 2: d[n] = d.get(n, 0) + 1 return d MOD = 10**9+7 N = int(input()) A = list(map(int, input().split())) G = {} for a in A: pf = prime_factors(a) for k,v in pf.items(): G[k] = max(G.get(k, 0), v) lcm = 1 for k,v in G.items(): lcm *= pow(k, v, MOD) lcm %= MOD ans = 0 for a in A: ans += lcm * pow(a, MOD-2, MOD) % MOD ans %= MOD print(ans)
0
null
43,792,937,956,194
24
235
n,m=map(int,input().split()) h=list(map(int,input().split())) AB=[list(map(int,input().split())) for _ in range(m)] from math import gcd ans=[1 for _ in range(n)] for ab in AB: if h[ab[0]-1]>h[ab[1]-1]: ans[ab[1]-1]=0 elif h[ab[0]-1]<h[ab[1]-1]: ans[ab[0]-1]=0 else: ans[ab[0]-1]=0 ans[ab[1]-1]=0 print(sum(ans))
def insertionSort(arr,step): count = 0 for i in range(step, len(arr)): j = i while j >= step and arr[j] < arr[j-step]: count += 1 t = arr[j] arr[j] = arr[j-step] arr[j-step] = t j -= step return count def shellSort(arr): gaps = [776591, 345152, 153401, 68178, 30301, 13467, 5985, 2660, 1182, 525, 233, 103, 46, 20, 9, 4, 1] m = 0 count = 0 for step in gaps: if step > len(arr): continue m += 1 count += insertionSort(arr, step) print(m) print(" ".join(map(str, gaps[len(gaps)-m:]))) print(count) for num in arr: print(num) arr = list() for _ in range(int(input())): arr.append(int(input())) shellSort(arr)
0
null
12,459,529,245,280
155
17
n = int(input()) s = input() cnt = 0 for i in range(1000): c = [i // 100, (i // 10) % 10, i % 10] f = 0 for j in range(n): if s[j] == str(c[f]): f+=1 if f == 3: break if f == 3: cnt += 1 print(cnt)
import re array = [] lines = [] count = 0 while True: n = input() if n == "-": break array.append(n) for i in range(len(array)): if re.compile("[a-z]").search(array[i]): fuck = i+1 if count > 0: lines.append(stt) count += 1 stt = array[i] else: if i == fuck: continue stt = stt[int(array[i]):len(stt)]+stt[0:int(array[i])] if i == len(array)-1: lines.append(stt) for i in range(len(lines)): print(lines[i])
0
null
65,583,740,792,780
267
66
X=int(input()) a=int(X/500) s=1000*a X-=500*a b=int(X/5) s+=5*b print(s)
a,b,c = map(int, raw_input().split()) if a > b: temp = a a = b b = temp if b > c: temp = b b = c c = temp if a > b: temp = a a = b b = temp print a,b,c
0
null
21,698,147,894,610
185
40
x = list(input().split()) for i in range(5): # logging.debug("i = {},x[i] = {}".format(i, x[i])) # if x[i] == "0": print(i + 1) exit() # logging.debug("n = {},f = {},f**b = {}".format(n, f, f**b)) # #logging.debug("デバッグ終了")#
l = [int(x) for x in input().split()] anser = 0 for i in l: anser += 1 if i == 0: print(anser)
1
13,430,140,627,424
null
126
126
N=int(input()) A=list(map(int,input().split())) sumA=0 sumB=[0] for i in range(N): sumB.append(sumB[i]+A[i]) i=i+1 for j in range(N-1): sumA=sumA+(A[j]*(sumB[N]-sumB[j+1]))%(10**9+7) j=j+1 print(sumA%(10**9+7))
N=int(input()) A=list(map(int,input().split())) c=0 for i in range(N): c=c+A[i]**2 print((sum(A)**2-c)//2%(10**9+7))
1
3,834,044,225,680
null
83
83
l = int(input()) x = l/3 ans = x**3 print(str(ans))
def factorization(n): if n==1: return [[1,1]] temp=n ans=[] for i in range(2, int(n**0.5+1.01)): if temp % i ==0: ct=0 while temp % i == 0: temp //= i ct += 1 ans.append([i, ct]) if temp != 1: ans.append([temp, 1]) return ans N=int(input()) L=factorization(N) if N==1: print(0) exit() ans=0 for l in L: ct=0 fac=1 while fac<=l[1]: ct+=1 fac+=ct+1 ans+=ct print(ans)
0
null
31,782,773,358,820
191
136
input_line = input() a,b = input_line.strip().split(' ') a = int(a) b = int(b) if a < b: print("a < b") elif a > b: print("a > b") elif a == b: print("a == b")
import math n = int(input()) def koch(n, p1_x, p2_x, p1_y, p2_y): if n == 0: return s_x = (2*p1_x + p2_x) / 3 s_y = (2*p1_y + p2_y) / 3 t_x = (p1_x + 2*p2_x) / 3 t_y = (p1_y + 2*p2_y) / 3 u_x = (t_x - s_x)/2 - (t_y - s_y) * math.sqrt(3)/2 + s_x u_y = (t_x - s_x) * math.sqrt(3)/2 + (t_y - s_y)/2 + s_y koch(n-1, p1_x, s_x, p1_y, s_y) print (s_x, s_y) koch(n-1, s_x, u_x, s_y, u_y) print (u_x, u_y) koch(n-1, u_x, t_x, u_y, t_y) print (t_x, t_y) koch(n-1, t_x, p2_x, t_y, p2_y) p1_x = 0.0 p1_y = 0.0 p2_x = 100.0 p2_y = 0.0 print (p1_x, p1_y) koch(n, 0, 100, 0, 0) print (p2_x, p2_y)
0
null
241,172,241,728
38
27
n = int(input()) A = list(map(int,input().split())) dp = [[[0,0,0] for i in range(2)] for i in range(n+1)] for i in range(1,n+1): if i%2 == 1: if i > 1: dp[i][0][1] = dp[i-1][1][0]+A[i-1] dp[i][0][2] = dp[i-1][1][1]+A[i-1] dp[i][1][0] = max(dp[i-1][0][0],dp[i-1][1][0]) dp[i][1][1] = max(dp[i-1][0][1],dp[i-1][1][1]) else: dp[i][0][2] = A[0] else: dp[i][0][0] = dp[i-1][1][0]+A[i-1] dp[i][0][1] = dp[i-1][1][1]+A[i-1] dp[i][1][0] = max(dp[i-1][0][1],dp[i-1][1][1]) dp[i][1][1] = dp[i-1][0][2] if n%2 == 0: print(max(dp[n][0][1],dp[n][1][1])) else: print(max(dp[n][0][1],dp[n][1][1]))
from math import * from collections import * N, D, A = list(map(int, input().split())) ans = 0 t = 0 q = deque() XH = sorted([list(map(int, input().split())) for i in range(N)]) for x, h in XH: if q: while q and q[0][0] < (x-D): _, c = q.popleft() t -= c h = h - t * A if h <= 0: continue x += D c = ceil(h/A) t += c ans += c q.append((x, c)) print(ans)
0
null
59,582,512,410,850
177
230
def make_bit(n): bit = [] for i in range(2**n): bit.append(bin(i)[2::]) i = 0 while i < len(bit): while len(bit[i]) < len(bin(2**n-1)[2::]): bit[i] = "0" + bit[i] i += 1 return bit h, w, k = map(int, input().split()) c = [list(input()) for _ in range(h)] h_pats = make_bit(h) w_pats = make_bit(w) ans = 0 for h_pat in h_pats: for w_pat in w_pats: cnt = 0 for i in range(h): for j in range(w): if h_pat[i] == "1" or w_pat[j] == "1": continue if c[i][j] == "#": cnt += 1 if cnt == k: ans += 1 print(ans)
def trans(l): return [list(x) for x in list(zip(*l))] from itertools import product import copy h, w, k = map(int, input().split()) c = [] for _ in range(h): c.append([c for c in input()]) A = [i for i in product([1,0], repeat=h)] B = [i for i in product([1,0], repeat=w)] ans = 0 for a in A: temp1 = copy.copy(c) for i, x in enumerate(a): if x == 1: temp1[i] = ["."] * w for b in B: temp2 = trans(temp1) for i, x in enumerate(b): if x == 1: temp2[i] = ["."] * h cnt = 0 for t in temp2: cnt += t.count("#") if cnt == k: ans += 1 print(ans)
1
8,834,000,927,960
null
110
110
def divisor(n): ret=[] for i in range(1,int(n**0.5)+1): if n%i==0: a,b=i,n//i if a!=b: ret+=a, ret+=b, else: ret+=a, return sorted(ret) def f(n): return divisor(n)[1:] def solve(n): ans=f(n-1) for k in f(n): N=n while N>=k: if N%k==0:N=N//k else:N=N%k if N==1:ans+=k, print(len(ans)) return 0 solve(int(input()))
n = int(input()) print(pow(n, 3))
0
null
20,693,592,161,240
183
35
n = input() friendliness = [int(item) for item in input().split()] friendliness.sort() def of_ans(): sum_ = 0 idx = 1 while idx < len(friendliness): sum_ += friendliness[len(friendliness) - (idx // 2) - 1] idx += 1 return sum_ print(of_ans())
n, k = map(int, input().split()) nums = list(map(int, input().split())) # (sums[j] - sums[i]) % K = j - i # (sums[j] - j) % K = (sums[i] - i) % K # 1, 4, 2, 3, 5 # 0, 1, 5, 7, 10, 15 # 0, 0, 3, 0, 2, 2 sums = [0] for x in nums: sums.append(sums[-1] + x) a = [(sums[i] - i) % k for i in range(len(sums))] res = 0 memo = {} i = 0 for j in range(len(a)): memo[a[j]] = memo.get(a[j], 0) + 1 if j - i + 1 > k: memo[a[i]] -= 1 i += 1 res += memo[a[j]] - 1 print(res)
0
null
73,458,347,923,440
111
273
a,b=map(int,input().split()) print("Yes" if (a*500>=b) else "No")
a, b = map(int, input().split()) if a < b: print('a < b') elif a == b: print('a == b') else: print('a > b')
0
null
49,482,266,529,588
244
38
a = range(1, 10) [print('{}x{}={}'.format(i, j, i * j)) for i in a for j in a]
case = 1 x = input() while(x!=0): print "Case %d: %d" % (case, x) x = input() case += 1
0
null
240,758,029,252
1
42
N, *AB = map(int, open(0).read().split()) A = sorted(a for a in AB[::2]) B = sorted(b for b in AB[1::2]) if N % 2: print(B[N // 2] - A[N // 2] + 1) else: print(B[N // 2 - 1] + B[N // 2] - A[N // 2 - 1] - A[N // 2] + 1)
import sys readline = sys.stdin.readline N = int(readline()) A = [] B = [] for _ in range(N): a, b = map(int, readline().split()) A.append(a) B.append(b) A.sort() B.sort() if N % 2 == 0: mi = A[N//2-1]+A[N//2] ma = B[N//2-1]+B[N//2] else: mi = A[N//2] ma = B[N//2] print(ma-mi+1)
1
17,398,490,635,560
null
137
137
n,k = map(int,input().split()) a = list(map(int,input().split())) si = [0 for i in range(n+1)] p = [1 for i in range(n)] import copy for q in range(min(k,50)): v = 0 s = copy.deepcopy(si) for i in range(n): if a[i] != 0: s[max(i-a[i],0)] += 1 s[min(i+a[i]+1,n)] -= 1 a[i] = 0 else: a[i] = 1 for i in range(n): v += s[i] a[i] += v for i in range(n): print(a[i], end = ' ')
n,k=map(int,input().split()) a=list(map(int,input().split())) for l in range(k): if a==[n]*n: break imos = [0]*(n+1) for i in range(n): imos[max(0,i-a[i]) ]+=1 imos[min(n-1,i+a[i])+1 ]-=1 a=[0]*n a[0]=imos[0] for i in range(1,n): a[i] = a[i-1]+imos[i] print(*a)
1
15,470,751,154,858
null
132
132
input() A = list(map(int, input().split())) sum_list = sum(A) sum_of_product = 0 for i in A: sum_list -= i sum_of_product = ((sum_list * i) % (10 ** 9 + 7) + sum_of_product) % (10 ** 9 + 7) print(sum_of_product)
N = int(input()) def kccv(a, b, c, d): return [a*2/3 + c/3, b*2/3 + d/3, a/2 + b*(3**0.5)/6 + c/2 - d*(3**0.5)/6, -a*(3**0.5)/6 + b/2 + c*(3**0.5)/6 + d/2, a/3 + c*2/3, b/3 + d*2/3] ans = [[[0,0],[100,0]]] for i in range(1,N+1): m = len(ans[i-1]) newset = [] for j in range(m-1): newset.append(ans[i-1][j]) newdot = kccv(ans[i-1][j][0], ans[i-1][j][1], ans[i-1][j+1][0], ans[i-1][j+1][1]) x1 = newdot[0] y1 = newdot[1] x2 = newdot[2] y2 = newdot[3] x3 = newdot[4] y3 = newdot[5] newset.append([x1,y1]) newset.append([x2,y2]) newset.append([x3,y3]) newset.append(ans[i-1][m-1]) ans.append(newset) for i in range(len(ans[N])): print(ans[N][i][0],ans[N][i][1])
0
null
1,988,464,660,100
83
27
from itertools import permutations as perm N = int(input()) XYS = [list(map(int, input().split())) for _ in range(N)] s = 0 for indexes in perm(list(range(N))): xys = [XYS[i] for i in indexes] x0, y0 = xys[0] for x1, y1 in xys: s += ((x0 - x1)**2 + (y0 - y1)**2) ** 0.5 x0 = x1 y0 = y1 nf = 1 for i in range(1, N+1): nf *= i ans = s / nf print(ans)
import sys sys.setrecursionlimit(10 ** 9) 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()) N, M, K = map(int, input().split()) uf = UnionFind(N) FG = [0] * N BG = [0] * N for _ in range(M): a, b = map(int, input().split()) a, b = a-1, b-1 uf.union(a, b) FG[a] += 1 FG[b] += 1 for _ in range(K): c, d = map(int, input().split()) c, d = c-1, d-1 if uf.same(c, d): BG[c] += 1 BG[d] += 1 ans = [] for i in range(N): ans.append(uf.size(i) - FG[i] - BG[i] - 1) print(*ans)
0
null
105,159,293,152,228
280
209
h, n = map(int, input().split()) a = list(map(int, input().split())) a_sum = sum(a) if h <= a_sum: print('Yes') else: print('No')
n = int(input()) A = list(map(int,input().split())) b = 1 B=[0]*(n+1) count = 0 t=len(A)-1 for i in range(t): B[i] = b if 2*(b - A[i]) < A[i+1]: count += 1 break b = 2*(b - A[i]) B[n] = b if n == 0 and A[0] > 1: count += 1 j = 0 while count == 0 and A[t] > B[j]: if j == n: break j += 1 total = 0 for i in range(j): total += B[i] s = A[t] for i in range(t-1,j-1,-1): total += min(B[i],s+A[i]) s+=A[i] if count==0: print(total+A[t]) else: print('-1')
0
null
48,630,908,412,610
226
141
from collections import defaultdict, deque import sys, heapq, bisect, math, itertools, string, queue, copy, time from fractions import gcd import numpy as np sys.setrecursionlimit(10**8) INF = float('inf') MOD = 10**9+7 EPS = 10**-7 def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl_str(): return list(sys.stdin.readline().split()) n = int(input()) l_list = list(map(int, input().split())) l_combo = itertools.combinations(l_list, 3) ans = 0 for i in l_combo: if i[0] + i[1] > i[2] and i[1]+i[2] > i[0] and i[0] + i[2] > i[1] and i[0] != i[1] and i[1] != i[2] and i[0] != i[2]: ans += 1 print(ans)
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): N = int(readline()) L = [int(i) for i in readline().split()] #まず三角形ができる組みを考える #三重ループでも間に合うので三重ループを回す L.sort() cnt = 0 for i in range(N): for j in range(i+1, N): for k in range(j+1, N): if L[k] < L[i] + L[j]: if (L[i] != L[j]) & (L[j] != L[k]) & (L[k] != L[i]): cnt += 1 print(cnt) if __name__ == '__main__': main()
1
5,067,655,760,740
null
91
91
import math from math import gcd INF = float("inf") import sys input=sys.stdin.readline import itertools from collections import Counter def main(): n = int(input()) p = list(map(int, input().split())) min = p[0] cnt = 0 for i in p: if i <= min: cnt += 1 min = i else: pass print(cnt) if __name__=="__main__": main()
import numpy as np def divisors(N): return sorted(sum((list({n, N // n}) for n in range(1, int(N ** 0.5) + 1) if not N % n), [])) def prime_factorize_dict(n): d = dict() while not n & 1: d[2] = d.get(2, 0) + 1 n >>= 1 f = 3 while f * f <= n: if not n % f: d[f] = d.get(f, 0) + 1 n //= f else: f += 2 if n != 1: d[n] = d.get(n, 0) + 1 return d N = int(input()) count = 0 for n in divisors(N)[1:]: M = N while not M % n: M //= n count += M % n == 1 fact_Nm1 = np.array(list(prime_factorize_dict(N - 1).values()), dtype=np.int32) print(count + np.prod(fact_Nm1 + 1) - 1)
0
null
63,564,329,838,780
233
183
n,m,X=map(int,input().split()) c=[list(map(int,input().split())) for i in range(n)] ans=float('inf') from itertools import combinations as com for l in range(1,n+1): for i in com(list(range(n)),r=l): cnt=[0]*m p=0 for j in i: p+=c[j][0] for x in range(m): cnt[x]+=c[j][x+1] if min(cnt)>=X:ans=min(ans,p) print(ans if ans!=float('inf')else -1)
N = int(input()) a = list(map(int, input().split())) print(sum((i + 1) % 2 == 1 and a[i] % 2 == 1 for i in range(N)))
0
null
15,041,620,324,060
149
105
N, L = int(input()), [int(v) for v in input().split()] L.sort() ans = 0 for i in range(N): for j in range(i): for k in range(j): if L[k] != L[j] and L[j] != L[i] and L[k] + L[j] > L[i]: ans += 1 print(ans)
import itertools n = int(input()) l = list(map(int, input().split())) c = list(itertools.combinations(l, 3)) ans = 0 for i in c: j = sorted(i) if j[0] != j[1] != j[2] != j[0]: if j[2] < j[0]+j[1]: ans += 1 print(ans)
1
5,046,582,618,012
null
91
91
x = [int(x) for x in input().split()] if (x[1]<x[0]): print("safe") else: print("unsafe")
N, M = [int(n) for n in input().split()] solved = {} result = {} for i in range(M): p, S = input().split() status = result.setdefault(p, []) if len(status)==0: result[p] = [] solved[p] = False if S == 'AC': solved[p] = True result[p].append(S) ans = 0 wa = 0 for k, v in solved.items(): if v: ans += 1 wa += result[k].index('AC') print(ans , wa)
0
null
61,137,403,422,020
163
240
import math n = int(input()) f = list(map(int,input().split())) f.sort() ans = 0 for i in range(1,n): ans += f[n-math.floor(i/2)-1] print(ans)
from sys import stdin N = int(stdin.readline().rstrip()) A = [int(x) for x in stdin.readline().rstrip().split()] max_node = [0] * (N+1) for i in range(N-1,-1,-1): max_node[i] = max_node[i+1]+A[i+1] ans = 1 node = 1 for i in range(N+1): node -= A[i] if (i < N and node <= 0) or node < 0: print(-1) exit(0) node = min(node*2,max_node[i]) ans += node print(ans)
0
null
13,988,591,826,468
111
141
n = int(input()) maxv = -20000000000 minv = int(input()) for i in range(n-1): R = int(input()) maxv = max(maxv, R - minv) minv = min(minv, R) print(maxv)
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()
0
null
77,174,289,960,740
13
284
while True: n, x = map(int, input().split()) if n == 0 and x == 0: break else: counter = 0 for a in range(1,(x // 3)): for c in range ((x//3)+1,n+1): b = x - a - c if a < b < c: counter += 1 print(counter)
while True: n, x = map(int, raw_input().split(" ")) if n==x==0: break ans = 0 for a in range(1, n-1): for b in range(a+1, n): for c in range(b+1, n+1): if a+b+c == x: ans += 1 break print ans
1
1,261,933,015,068
null
58
58
n, r = [int(i) for i in input().split()] ans = r if n >= 10 else r + 100 *(10 - n) print(ans)
import math def abs(num): if num < 0: return -num return num def main(): abhm = [int(_x) for _x in input().split()] HL = abhm[0] ML = abhm[1] H = abhm[2] M = abhm[3] radian = 2.0 * math.pi * abs(M / 60.0 - (H + M / 60.0) / 12.0) length = math.sqrt(HL * HL + ML * ML - 2 * HL * ML * math.cos(radian)) print(length) main()
0
null
42,025,267,432,710
211
144
def print_chessboard(h, w): """ h: int w: int outputs chessboard using '#' and '.' >>> print_chessboard(3, 4) #.#. .#.# #.#. >>> print_chessboard(5, 6) #.#.#. .#.#.# #.#.#. .#.#.# #.#.#. >>> print_chessboard(2, 2) #. .# """ for i in range(h): line = '' for j in range(w): if (i+j) % 2 == 0: line += '#' else: line += '.' print(line) if __name__ == '__main__': while True: (h, w) = [int(i) for i in input().split(' ')] if h == 0 and w == 0: break print_chessboard(h, w) print()
from numpy import cumsum n,m=map(int,input().split()) a=list(map(int,input().split())) result=cumsum(a)[-1] mi=result/(4*m) ans=0 for i in range(n): if a[i]>=mi: ans+=1 if ans>=m: print('Yes') else: print('No')
0
null
19,684,366,274,840
51
179
#!/usr/bin/env python3 N = int(input()) if N % 2 == 1: print(0) else: ret = 0 for i in range(1, 27): ret += N // (2*5**i) print(ret)
# 23-Structure_and_Class-Dice_I.py # ???????????? I # ?¬?????±??????????????????????????????????????????¢??????????????\??¬????????§????????????????????°???????????????????????????????????? # ????????????????????¢??????????????¨????????? 1 ?????? 6 ???????????????????????????????????????????????? # ??\?????¨??????????????????????????¢?????????????????????????????°?????¨?????¢?????????????????????????????????????????§??? # ????????????????????¢?????°????????????????????????????????? # ????????\??¬????????§??????????????¶?????????????????¨?????????????????????????????§?????????????????????????????????????????¨???????????? # Input # ?????????????????¢?????°???????????????????????????????????????????????????????????§????????????????????? # ???????????????????????¨????????????????????????????????????????????????????????????????????????????????????????????¨????????? E???N???S???W ????????????????????§?????? # Output # ???????????????????????????????????????????????????????????¢?????°??????????????????????????????????????? # Constraints # 0???0??? ??\?????????????????????????????¢?????°??? ???100???100 # 0???0??? ???????????¨????????????????????? ???100???100 # Note # ?¶???????????????? Dice III, Dice IV ??§???????????°????????????????????±????????§???????????????????????????????§?????????§????????????????????????????????? # Sample Input 1 # 1 2 4 8 16 32 # SE # Sample Output 1 # 8 # ?????¢??? 1, 2, 4, 8, 16, 32 ??¨??????????????????????????? S ??????????????¢???????????????E ??????????????¢????????¨????????¢?????°?????? 8 ?????????????????? # Sample Input 2 # 1 2 4 8 16 32 # EESWN # Sample Output 2 # 32 class Dice: def __init__(self, dice_num): self.side_top=1 self.side_bot=6 self.side_Nor=5 self.side_Eas=3 self.side_Sau=2 self.side_Wes=4 self.dice_num = dice_num def op_N(self): self.side_top, self.side_bot, self.side_Nor, self.side_Sau =\ self.side_Sau, self.side_Nor, self.side_top, self.side_bot def op_E(self): self.side_top, self.side_bot, self.side_Eas, self.side_Wes =\ self.side_Wes, self.side_Eas, self.side_top, self.side_bot def op_S(self): self.side_top, self.side_bot, self.side_Nor, self.side_Sau =\ self.side_Nor, self.side_Sau, self.side_bot, self.side_top def op_W(self): self.side_top, self.side_bot, self.side_Eas, self.side_Wes =\ self.side_Eas, self.side_Wes, self.side_bot, self.side_top def print_side_top(self): print( dice_num[self.side_top-1] ) def print_side_all(self): print( "top:{}, bot:{}, Nor:{}, Eas{}, Sau:{}, Wes,{}.".format(self.side_top, self.side_bot, self.side_Nor, self.side_Eas, self.side_Sau, self.side_Wes ) ) dice_num = list( map(int, input().split())) op = input() dice_roll = Dice(dice_num) for i in op: if i == "N": dice_roll.op_N() elif i =="E": dice_roll.op_E() elif i =="S": dice_roll.op_S() elif i =="W": dice_roll.op_W() else: print("?????°??°") dice_roll.print_side_top()
0
null
58,403,724,293,562
258
33
import sys # import re # import math # import collections # import decimal # import bisect # import itertools # import fractions # import functools # import copy # import heapq # import decimal # import statistics import queue sys.setrecursionlimit(10000001) INF = 10 ** 16 MOD = 10 ** 9 + 7 ni = lambda: int(sys.stdin.readline()) ns = lambda: map(int, sys.stdin.readline().split()) na = lambda: list(map(int, sys.stdin.readline().split())) # ===CODE=== def main(): n = ni() edge = [[] for i in range(n)] origin_edge = [] edge_dic = {} for i in range(n - 1): a, b = ns() a -= 1 b -= 1 edge[a].append(b) edge[b].append(a) edge_dic[(a, b)] = -1 origin_edge.append((a, b)) max_root = 0 for e in edge: max_root = max(max_root, len(e)) que = queue.Queue() que.put((0, -1)) while que.qsize() > 0: node, used_color = que.get() current_color = 0 if used_color != 0 else 1 for k in edge[node]: ai = min(node, k) bi = max(node, k) if edge_dic[(ai, bi)] > -1: continue edge_dic[(ai, bi)] = current_color que.put((k, current_color)) current_color = current_color + 1 if used_color != current_color + 1 else current_color + 2 print(max_root) for a, b in origin_edge: print(edge_dic[(a, b)] + 1) if __name__ == '__main__': main()
import sys sys.setrecursionlimit(1000000000) input = sys.stdin.readline N = int(input()) graph = [[] for _ in range(N)] ab = [list(map(lambda x:int(x)-1, input().split())) for _ in range(N-1)] d = {} for a, b in ab: graph[a] += [b] graph[b] += [a] def dfs(u, pre, c): color = 0 for v in graph[u]: if v != pre: color += 1 if color == c: color += 1 d[(u, v)] = color d[(v, u)] = color dfs(v, u, color) dfs(0, -1, -1) s = set() for a, b in ab: s.add(d[(a, b)]) print(len(s)) for a, b in ab: print(d[(a, b)])
1
135,704,858,768,348
null
272
272
h, a = list(map(int, input().split(' '))) ans = 0 while h > 0: h -= a ans += 1 print(ans)
import math print reduce(lambda a, b: int(math.ceil(a * 1.05 / 1000)) * 1000, range(input()), 100000)
0
null
38,673,301,171,470
225
6
i=list(map(int,input().split())) x=[[0,1],[0,2],[1,2]] for a in range(3): if( i[ x[a][0] ] > i[ x[a][1] ]): swap=i[ x[a][0] ] i[ x[a][0] ]= i[ x[a][1] ] i[ x[a][1] ]=swap print(i[0],end=' ') print(i[1],end=' ') print(i[2],end='\n')
a = list(map(int, input().split())) a.sort() print(a[0], a[1], a[2])
1
424,805,850,250
null
40
40
S = input() flag = 0 for i in range(0,len(S)//2): if S[i] == S[-1-i]: continue else: flag = 1 print("No") break if flag == 0: S = S[:((len(S)-1)//2)] for i in range(0,len(S)//2): if S[i] == S[-1-i]: continue else: flag = 1 print("No") break if flag == 0: print("Yes")
import sys from functools import reduce from math import gcd read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines mod = 10 ** 9 + 7 N = int(readline()) A = list(map(int,readline().split())) lcm = reduce(lambda x,y:x*y//gcd(x,y),A) ans = 0 coef = sum(pow(x,mod-2,mod) for x in A) ans = lcm * coef % mod print(ans)
0
null
67,188,864,935,700
190
235
S = input() N = len(S) ans = 'No' # 文字列strの反転は、str[::-1] if S == S[::-1] and S[:(N-1)//2] == S[:(N-1)//2][::-1] and S[(N+1)//2:] == S[(N+1)//2:][::-1]: ans = 'Yes' print(ans)
n=int(input()) a=list(map(int,input().split())) sum_a=sum(a) x=0 i=0 while x<sum_a/2: x+=a[i] i+=1 if n%2==0: print(min(x-(sum_a-x),sum_a-(x-a[i-1])*2)) else: print(x-(sum_a-x))
0
null
94,484,824,525,478
190
276
while True: H,W = map(int,input().split()) if H == 0 and W == 0 : break line = ['#.'*(W // 2)+'#'*(W % 2),'.#'*(W // 2)+'.'*(W % 2)] for i in range(H) : print(line[i % 2]) print()
target = input() now_height = [] now_area = [0] answer = [] continued = 0 depth = 0 depth_list = [] for t in target: # print(now_height,depth_list,now_area,answer,continued) if t == '\\': now_height.append(continued) depth_list.append(depth) now_area.append(0) depth -= 1 elif t == '_': pass elif t == '/' and len(now_height) > 0: depth += 1 started = now_height.pop() temp_area = continued - started # print(depth_list[-1],depth) now_area[-1] += temp_area if depth > depth_list[-1]: while depth > depth_list[-1]: temp = now_area.pop() now_area[-1] += temp depth_list.pop() continued += 1 now_area = list(filter(lambda x:x != 0,now_area)) answer.extend(now_area) print(sum(answer)) print(len(answer),*answer)
0
null
474,249,274,772
51
21
import sys n=int(input()) ans=[0]*(n+1) MOD=998244353 a=list(map(int,input().split())) if a[0]!=0: print(0) sys.exit() for i in range(n): ans[a[i]]+=1 if ans[0]!=1: print(0) sys.exit() fin=1 for i in range(1,max(a)+1): fin=(fin*pow(ans[i-1],ans[i],MOD))%MOD print(fin)
#入力 n, u, v = map(int, input().split()) mapdata = [list(map(int,input().split())) for _ in range(n-1)] #グラフ作成 graph = [[] for _ in range(n+1)] for i, j in mapdata: graph[i].append(j) graph[j].append(i) #探索 def dfs(v): dist = [-1] * (n + 1) stack = [v] dist[v] = 0 while stack: v = stack.pop() dw = dist[v] + 1 for w in graph[v]: if dist[w] >= 0: continue dist[w] = dw stack.append(w) return dist du, dv = dfs(u), dfs(v) ans = 0 for u, v in zip(du[1:], dv[1:]): if u < v: x = v-1 if ans < x: ans = x print(ans)
0
null
136,343,929,509,172
284
259
n,a,b=map(int,input().split()) if a%2==b%2: c=(b-a)//2 if (c+1)*2<=b-a: c+=1 print(c) else: t=min(b-1+a,n-a+n-b+1) c=t//2 if (c+1)*2<=t: c+=1 print(c)
a = [] for i in range(10): a.append(int(raw_input())) a.sort() a.reverse() for i in range(3): print a[i]
0
null
54,452,876,621,180
253
2
# A**5 = X + B**5 X = int(input()) l = [] for i in range(-300, 300): l.append(i**5) for b, b_5 in enumerate(l, start=-300): # print(b, b_5, X) if X+b_5 in l: a_5 = X+b_5 a = l.index(a_5)-300 print(a, b) break
import sys x = int(input()) box = [a**5 for a in range(0,200)] for i in range(200): for j in range(200): if box[i] - box[j] == x: print(i,j) sys.exit() for k in range(200): for l in range(200): if (-1)*box[k] + box[l] == x: print(-(k),-(l)) sys.exit() for s in range(200): for t in range(200): if box[s] + box[t] == x: print(s,-(t)) sys.exit()
1
25,649,122,683,478
null
156
156
import numpy as np def check_pali(S): for i in range(0, len(S)): if S[i] != S[-1 * i + -1]: return False elif i > (len(S) / 2) + 1: break return True S = input() N = len(S) short_N = (N - 1) // 2 long_N = (N + 3) // 2 if check_pali(S) & check_pali(S[0:short_N]) & check_pali(S[long_N-1:N]): print("Yes") else: print("No")
S=input() N=len(S) s=''.join(list(reversed(S))) T=S[0:int((N-1)/2)] NT=len(T) t=''.join(list(reversed(T))) U=S[int((N+1)/2):N] NU=len(U) u=''.join(list(reversed(U))) if S[0:int((N-1)/2)] == s[0:int((N-1)/2)] and T == t and U == u: print('Yes') else: print('No')
1
46,593,726,622,862
null
190
190
K = int(input()) import math from functools import reduce def gcd(*numbers): return reduce(math.gcd, numbers) ans = 0 for i in range(1,K+1): for j in range(1,K+1): for k in range(1,K+1): ans += (gcd(i,j,k)) print(ans)
k = int(input()) ans = 0 def gcd(a,b): if a % b == 0: return b c = a % b return gcd(b,c) for l in range(1,k+1): for m in range(l,k+1): for n in range(m,k+1): tmp1 = gcd(l,n) tmp2= gcd(tmp1,m) if (l==m==n): ans+=tmp2 elif(l==m or m==n): ans+= 3*tmp2 else: ans += 6*tmp2 print(ans)
1
35,393,986,423,548
null
174
174
while 1: a, b = [int(x) for x in input().split()] if a == 0 and b == 0: break if a > b: a, b = b, a print(a, b)
#!/usr/bin/env python # -*- coding: utf-8 -*- import math def isprime(n): if n == 2: return True elif n < 2 or n % 2 == 0: return False else: for i in range(3, math.floor(math.sqrt(n)) + 1, 2): if n % i == 0: return False else: return True def main(): n = int(input()) ms = (int(input()) for i in range(n)) print(len(list(filter(isprime, ms)))) if __name__ == "__main__": main()
0
null
274,301,961,520
43
12
n = int(input()) l = list(map(int, input().split())) ans=0 for i in range(n): for j in range(i+1,n): for k in range(j+1,n): li = [l[i], l[j], l[k]] m = max(li) if 2*m < sum(li) and len(set(li)) == 3: ans += 1 print(ans)
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)
1
4,981,706,219,532
null
91
91
k = int(input()) a,b = map(int, input().split()) if (int(b/k)*k >= a): print("OK") else: print("NG")
def main(): K = int(input()) A, B = map(int, input().split()) for i in range(A, B+1): if i % K == 0: print("OK") return print("NG") main()
1
26,554,033,569,222
null
158
158
a, b, k = map(int, input().split()) print(a - min(a, k), b - min(b, k - min(a, k)))
n= int(input()) arr = [int(x) for x in input().strip().split()] def Greedy(arr): curr = 1000 for i in range(len(arr)-1): if arr[i+1]>arr[i]: stocks = curr // arr[i] curr += (arr[i+1] - arr[i])*stocks return curr print(Greedy(arr))
0
null
55,649,843,749,072
249
103
n = input() str_n = list(n) if str_n[-1] == "3": print("bon") elif str_n[-1] == "0" or str_n[-1] == "1" or str_n[-1] == "6" or str_n[-1] == "8": print("pon") else: print("hon")
n, k = map(int, input().split()) t = n // k re = n - t * k if abs(re - k) < re: re = abs(re - k) i = True print(re)
0
null
29,466,294,110,110
142
180
for num1 in range(1,10): for num2 in range(1,10): i = num1 * num2 print(str(num1) + "x" + str(num2) + "=" + str(i))
def run(): for i in range(1,10): for j in range(1,10): print('{0}x{1}={2}'.format(i,j,i*j)) if __name__ == '__main__': run()
1
1,203,470
null
1
1
a, b = map(int, input().split()) if a < b: a, b = b, a while a % b != 0: a, b = b, a % b print(b)
# C - Sqrt Inequality import decimal a,b,c = input().split() a,b,c = map(decimal.Decimal,[a,b,c]) sqrt = decimal.Decimal(0.5) if a**sqrt + b**sqrt < c**sqrt: print('Yes') else: print('No')
0
null
25,825,870,328,960
11
197
def ex_euclid(a, b): x0, x1 = 1, 0 y0, y1 = 0, 1 z0, z1 = a, b while z1 != 0: q = z0 // z1 z0, z1 = z1, z0 % z1 x0, x1 = x1, x0 - q * x1 y0, y1 = y1, y0 - q * y1 return z0, x0, y0 def mod_inv(a, n): g, x, _ = ex_euclid(a, n) if g != 1: print("modular inverse does not exist") else: return x % n def mod_factorial(x, modulo): ans = 1 for i in range(1, x+1): ans *= i ans %= modulo return ans X, Y = map(int, input().split()) M = 10 ** 9 + 7 a, b = (2*X-Y)/3, (2*Y-X)/3 if a < 0 or b < 0: print(0) elif a == 0 and b == 0: print(0) elif a%1 != 0 or b%1!= 0: print(0) else: a, b = int(a), int(b) answer = 1 answer *= mod_factorial(a+b, M) answer *= mod_inv(mod_factorial(a, M), M) answer %= M answer *= mod_inv(mod_factorial(b, M), M) answer %= M print(answer)
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, input().split()) if (X + Y) % 3 != 0: print(0) exit() MAX = 2 * 10 ** 6 + 2 MOD = 10 ** 9 + 7 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) if X < Y: X, Y = Y, X b = (2 * X - Y) // 3 a = X - 2 * b print(com(a + b, b, MOD))
1
149,849,834,063,160
null
281
281
def BubbleSort(C, N): for i in range(N): for j in range(N-1, i, -1): if C[j][1] < C[j-1][1]: C[j], C[j-1] = C[j-1], C[j] return C def SelectionSort(C, N): for i in range(N): minj = i for j in range(i, N): if C[j][1] < C[minj][1]: minj = j C[i], C[minj] = C[minj], C[i] return C def isStable(C1, C2, N): if C1 != C2: return "Not stable" return "Stable" Num = int(input()) Cards = [x for x in input().split()] card1 = BubbleSort(list(Cards), Num) card2 = SelectionSort(list(Cards), Num) print(" ".join(card1)) print(isStable(card1, card1, Num)) print(" ".join(card2)) print(isStable(card1, card2, Num))
#coding:utf-8 from copy import deepcopy n = int(input()) A = list(input().split()) B = deepcopy(A) def BubbleSort(A,N): for i in range(N): for j in range(N-1,i,-1): if A[j][1] < A[j-1][1]: A[j], A[j-1] = A[j-1], A[j] def SelectionSort(A,N): for i in range(N): minj = i for j in range(i,N): if A[j][1] < A[minj][1]: minj = j A[i], A[minj] = A[minj], A[i] BubbleSort(A,n) SelectionSort(B,n) A = " ".join([data for data in A]) B = " ".join([data for data in B]) print(A) print("Stable") print(B) if A == B: print("Stable") else: print("Not stable")
1
24,688,824,358
null
16
16
# encoding:utf-8 while True: a,op,b = map(str, input().split()) c = int(a) d = int(b) if op == '+': result = c + d if op == '-': result = c - d if op == '*': result = c * d if op == '/': result = int(c / d) if op == '?': break print("{0}".format(result))
while True: a,op,b=input().split(" ") a,b=[int(i) for i in (a,b)] if op=="+": print(a+b) elif op=="-": print(a-b) elif op=="*": print(a*b) elif op=="/": print(int(a/b)) else: break
1
676,863,422,158
null
47
47
import sys def log(s): # print("| " + str(s), file=sys.stderr) pass def output(x): print(x, flush=True) def input_ints(): return list(map(int, input().split())) def main(): f = input_ints() print(f[0] * f[1]) main()
A, B, N = map(int, input().split()) if N >= B - 1: print(int(A * (B - 1) / B)) else: print(int(A * N / B))
0
null
22,029,344,927,614
133
161
N, M = map(int, input().split()) A = list(map(int, input().split())) cnt = 0 total = sum(A) for a in A: if a >= total / (4*M): cnt += 1 ans = 'Yes' if cnt >= M else 'No' print(ans)
def f(s,n): res = 0 flg = False for i in range(1,n): if flg: flg = False continue if S[i] == S[i-1]: flg = True res += 1 return res S = input() K = int(input()) if len(set(list(S))) == 1: print(len(S)*K//2) exit() ans = f(S,len(S)) S = S * 2 print(ans + (f(S,len(S)) - ans) * (K-1))
0
null
107,202,644,616,848
179
296
n=input().rstrip().split(" ") w=int(n[0]) l=int(n[1]) print(w*l, 2*w+2*l)
inArray = input().split(' ') length = int(inArray[0]) width = int(inArray[-1]) area = str(length * width) circuit = str((length * 2) + (width * 2)) print(area + " " + circuit)
1
311,790,799,008
null
36
36
N,K = map(int,input().split()) A = list(map(int,input().split())) MOD = 10**9+7 if all(a>=0 for a in A): A.sort() ans = 1 for _ in range(K): ans *= A.pop() ans %= MOD print(ans) exit() if all(a<0 for a in A): A.sort(reverse=K%2==0) ans = 1 for _ in range(K): ans *= A.pop() ans %= MOD print(ans) exit() if N==K: ans = 1 for a in A: ans *= a ans %= MOD print(ans) exit() arr = [] for a in A: if a < 0: arr.append((-a,1)) else: arr.append((a,0)) arr.sort() pz = [] ng = [] for _ in range(K): v,s = arr.pop() if s: ng.append(v) else: pz.append(v) if len(ng)%2 == 0: ans = 1 for v in ng: ans *= v ans %= MOD for v in pz: ans *= v ans %= MOD print(ans) exit() b = pz[-1] if pz else None c = ng[-1] if ng else None a = d = None while arr and (a is None or d is None): v,s = arr.pop() if s: if a is None: a = v else: if d is None: d = v if (a is None or b is None) and (c is None or d is None): assert False ans = 1 if a is None or b is None: ans = d for v in ng[:-1]: ans *= v ans %= MOD for v in pz: ans *= v ans %= MOD elif c is None or d is None: ans = a for v in ng: ans *= v ans %= MOD for v in pz[:-1]: ans *= v ans %= MOD else: if a*c > b*d: ans = a for v in ng: ans *= v ans %= MOD for v in pz[:-1]: ans *= v ans %= MOD else: ans = d for v in ng[:-1]: ans *= v ans %= MOD for v in pz: ans *= v ans %= MOD ans %= MOD print(ans)
val = input() if val[2:3] == val[3:4] and val[4:5] == val[5:6]: print("Yes") else: print("No")
0
null
25,643,272,869,188
112
184