code1
stringlengths
16
24.5k
code2
stringlengths
16
24.5k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.71M
180,628B
code1_group
int64
1
299
code2_group
int64
1
299
n=int(input()) dic={} for i in range(n): s=input() if s not in dic: dic[s]=1 else: dic[s]+=1 dic = sorted(dic.items(),key=lambda x:x[0]) dic = sorted(dic,key=lambda x:x[1],reverse=True) ma=dic[0][1] for i,v in dic: if v!=ma: break else: print(i)
#coding:utf-8 #1_6_A 2015.4.1 n = int(input()) numbers = list(map(int,input().split())) for i in range(n): if i == n - 1: print(numbers[-i-1]) else: print(numbers[-i-1], end = ' ')
0
null
35,290,977,164,508
218
53
n = int(input()) s, t = input().split() ans = "" for i, j in zip(s, t): ans += i + j print(ans)
N, M = map(int, input().split()) if M == 0: print(1) exit() group_list = [] group_index = [0] * N for _ in range(M): a, b = map(int, input().split()) if group_index[a-1] == 0 and group_index[b-1] == 0: group_index[a-1] = len(group_list) + 1 group_index[b-1] = len(group_list) + 1 group_list.append(set([a, b])) elif group_index[a-1] == 0: group_index[a-1] = group_index[b-1] group_list[group_index[b-1] - 1].add(a) elif group_index[b-1] == 0: group_index[b-1] = group_index[a-1] group_list[group_index[a-1] - 1].add(b) elif group_index[a-1] != group_index[b-1]: if len(group_list[group_index[a-1] - 1]) > len(group_list[group_index[b-1] - 1]): group_id_b = group_index[b-1] - 1 for p in group_list[group_id_b]: group_index[p-1] = group_index[a-1] group_list[group_index[a-1] - 1].add(p) group_list[group_id_b] = set() else: group_id_a = group_index[a-1] - 1 for p in group_list[group_id_a]: group_index[p-1] = group_index[b-1] group_list[group_index[b-1] - 1].add(p) group_list[group_id_a] = set() print(max([len(g) for g in group_list]))
0
null
58,097,939,643,812
255
84
def solve(n): dp=[1]*(n+1) for i in range(2,n+1): dp[i]=dp[i-1]+dp[i-2] return dp[n] n=int(input()) print(solve(n))
N = int(input()) memo = [] memo = [1,1] + [0] * (N - 1) def f(n): if memo[n] == 0: memo[n] = f(n-1) + f(n-2) return(memo[n]) if memo[n] != 0: return(memo[n]) print(f(N))
1
1,837,805,112
null
7
7
#!/usr/bin/python3 import sys def input(): return sys.stdin.readline().rstrip('\n') #S = input() A1,A2,A3 = list(map(int,input().split())) if A1+A2+A3 < 22: print('win') else: print('bust')
def study_time(h1, m1, h2, m2, k): result = (h2 - h1) * 60 + m2 - m1 - k return result h1, m1, h2, m2, k = tuple(map(int, input().split())) if __name__ == '__main__': print(study_time(h1, m1, h2, m2, k))
0
null
68,173,588,957,218
260
139
n = int(input()) Taro = 0 Hanako = 0 for i in range(n): t,h = input().split() if t == h: Hanako += 1 Taro += 1 elif t> h: Taro += 3 else: Hanako += 3 print("{} {}".format(Taro,Hanako))
n = int(input()) s_taro,s_hanako = 0,0 for trial in range(n): taro,hanako = list(map(str, input().split())) if taro > hanako: s_taro += 3 elif taro < hanako: s_hanako += 3 else: s_taro += 1 s_hanako += 1 print(s_taro, s_hanako)
1
1,986,879,387,648
null
67
67
n = int(input()) D = [0] * n for i in range(1, n): for j in range(i, n, i): D[j] += 1 print(sum(D))
n = int(input()) ans = 0 ama = 0 for i in range(1, 10): ans = n / i ama = n % i if i == 9 and ama != 0: print("No") if i <= 9 and ans <= 9 and ama == 0: print("Yes") exit()
0
null
81,003,314,527,860
73
287
import sys, os, math, bisect, itertools, collections, heapq, queue # from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall # from decimal import Decimal # from collections import defaultdict, deque sys.setrecursionlimit(10000000) ii = lambda: int(sys.stdin.buffer.readline().rstrip()) il = lambda: list(map(int, sys.stdin.buffer.readline().split())) fl = lambda: list(map(float, sys.stdin.buffer.readline().split())) iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] iss = lambda: sys.stdin.buffer.readline().decode().rstrip() sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] lcm = lambda x, y: (x * y) // math.gcd(x, y) MOD = 10 ** 9 + 7 MAX = float('inf') def koch(N, ax, ay, bx, by): if N == 0: return # 度をラジアンに変換 radians = math.radians(60) # 線分を3等分する、 # 座標sと座標tの位置を求める sx = (2 * ax + bx) / 3 sy = (2 * ay + by) / 3 tx = (ax + 2 * bx) / 3 ty = (ay + 2 * by) / 3 # 座標sと座標tから正三角形となる座標uを求める ux = (tx - sx) * math.cos(radians) - (ty - sy) * math.sin(radians) + sx uy = (tx - sx) * math.sin(radians) + (ty - sy) * math.cos(radians) + sy # 座標aと座標sのコッホ曲線を求める koch(N - 1, ax, ay, sx, sy) print('{:.08f} {:.08f}'.format(sx, sy)) # 座標s # 座標sと座標uのコッホ曲線を求める koch(N - 1, sx, sy, ux, uy) print('{:.08f} {:.08f}'.format(ux, uy)) # 座標u # 座標uと座標tのコッホ曲線を求める koch(N - 1, ux, uy, tx, ty) print('{:.08f} {:.08f}'.format(tx, ty)) # 座標t # 座標tと座標bのコッホ曲線を求める koch(N - 1, tx, ty, bx, by) def main(): if os.getenv("LOCAL"): sys.stdin = open("input.txt", "r") N = ii() print('{:.08f} {:.08f}'.format(0, 0)) # 座標a koch(N, 0, 0, 100, 0) print('{:.08f} {:.08f}'.format(100, 0)) # 座標b if __name__ == '__main__': main()
import sys sys.setrecursionlimit(10 ** 7) f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): H, W = map(int, input().split()) grid = [list("." + input()) for _ in range(H)] dp = [[f_inf] * (W + 1) for _ in range(H)] dp[0][0] = 0 for h in range(H): for w in range(W + 1): if w == 0: if h != 0: continue next_h, next_w = h, w + 1 if grid[h][w] == "." and grid[next_h][next_w] == "#": dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w] + 1) elif grid[h][w] == "." and grid[next_h][next_w] == "#": dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w] + 1) else: dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w]) else: for dh, dw in [(1, 0), (0, 1)]: next_h, next_w = h + dh, w + dw if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W + 1: continue if grid[h][w] == "." and grid[next_h][next_w] == "#": dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w] + 1) elif grid[h][w] == "." and grid[next_h][next_w] == "#": dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w] + 1) else: dp[next_h][next_w] = min(dp[next_h][next_w], dp[h][w]) print(dp[-1][-1]) if __name__ == '__main__': resolve()
0
null
24,557,927,059,480
27
194
import itertools import math n = int(input()) l = [] for _ in range(n): x, y = map(int, input().split()) l.append((x,y)) def d(a, b): return ((a[0]-b[0])**2 + (a[1]-b[1])**2)**0.5 ans = 0 for v in itertools.permutations(l): s = 0 for i in range(n-1): s += d(v[i], v[i+1]) ans += s print(ans / math.factorial(n))
def dist (s1,s2): x1=s1[0] y1=s1[1] x2=s2[0] y2=s2[1] a=(x1-x2)**2+(y1-y2)**2 return pow(a,0.5) arr=[] n=int(input()) for _ in range(n): inp=list(map(int,input().split())) arr.append((inp[0],inp[1])) ans=0 for i in range(len(arr)): for j in range(len(arr)): ans+=dist(arr[i],arr[j]) print (ans/n)
1
148,636,881,158,778
null
280
280
a,b,c = map(int, input().split()) print(len(list(filter(lambda x: c%x==0,range(a,b+1)))))
s = input() target = s[:(len(s)-1)//2] target2 = s[(len(s)+3)//2-1:] if target == target2: l, r = 0, len(s)-1 flag = True while l <= r: if s[l] == s[r]: l += 1 r -= 1 else: print('No') exit(0) print("Yes") else: print('No')
0
null
23,337,201,955,748
44
190
while True: num = map(int, raw_input().split()) num.sort() if num[0] == 0 and num[1] == 0: break print "%d %d" % (num[0], num[1])
a = [] while True: d = list(map(int, input().split())) if d == [0,0]: break d.sort() a.append(d) for x in a: print('{} {}'.format(x[0],x[1]))
1
527,494,927,652
null
43
43
N = int(input()) n_list = [] count = 1 max_val = 1 res = 0 for x in range(1,100): for y in range(x,100): for z in range(y,100): res = x**2 +y**2 + z**2 + x*y + y*z + z*x for i in range(int(x!=y) + int(y!=z) + int(z!=x)-1): count *= 3-i if max_val < res: for i in range(max_val, res+1): if i != res: n_list.append(0) else: n_list.append(count) max_val = res+1 else: n_list[res-1] += count count = 1 for i in range(N): print(n_list[i])
n=int(input()) ans = [0 for _ in range(n+1)] for i in range(1,int((n+1)**0.5)): for j in range(1,n+1): for k in range(1,n+1): v = i*i+j*j+k*k+i*j+j*k+k*i if v > n: break ans[v]+=1 for i in range(n): print(ans[i+1])
1
8,000,780,129,988
null
106
106
N = int(input()) P = list(map(int, input().split())) ans = 1 cnt = [0] * 3 mod = 10**9+7 for i in range(N): opt = 0 cond = 1 for j in range(3): if cnt[j] == P[i]: opt += 1 if cond: cnt[j] += 1 cond = 0 ans *= opt ans %= mod ans %= mod print(ans)
import sys sys.setrecursionlimit(10 ** 5 + 10) def input(): return sys.stdin.readline().strip() def resolve(): n = int(input()) A = list(map(int, input().split())) ans = 1 mod = 10 ** 9 + 7 for i in range(n): A[i] += 1 cnt = [0] * (n + 1) # cnt[i]は、Aのなかでこれまでに何個iが登場したか。つまりiの候補数。 cnt[0] = 3 for j in range(n): i = A[j] ans *= cnt[i - 1] cnt[i - 1] -= 1 cnt[i] += 1 if cnt[i] > 3: ans = 0 if cnt[i - 1] < 0: ans = 0 print(ans % mod) resolve()
1
130,017,631,572,426
null
268
268
n = int(input()) ans = '' for i in range(13): if n >= 26 and n%26 == 0: ans = 'z' + ans n -= 26 else: ans = chr(97 -1 + n%26) + ans n -= n%26 n = n //26 print(ans.replace("`", ""))
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) from math import floor n = int(readline()) print(floor((n - 1) / 2))
0
null
82,950,733,144,298
121
283
def main(): X, Y, A, B, C = map(int, input().split()) *P, = map(int, input().split()) *Q, = map(int, input().split()) *R, = map(int, input().split()) P.sort(reverse=True) Q.sort(reverse=True) ans = sum(sorted(P[:X] + Q[:Y] + R, reverse=True)[:X + Y]) print(ans) if __name__ == '__main__': main()
def getN(): return int(input()) def getNM(): return map(int, input().split()) def getList(): return list(map(int, input().split())) def getArray(intn): return [int(input()) for i in range(intn)] def input(): return sys.stdin.readline().rstrip() def rand_N(ran1, ran2): return random.randint(ran1, ran2) def rand_List(ran1, ran2, rantime): return [random.randint(ran1, ran2) for i in range(rantime)] def rand_ints_nodup(ran1, ran2, rantime): ns = [] while len(ns) < rantime: n = random.randint(ran1, ran2) if not n in ns: ns.append(n) return sorted(ns) def rand_query(ran1, ran2, rantime): r_query = [] while len(r_query) < rantime: n_q = rand_ints_nodup(ran1, ran2, 2) if not n_q in r_query: r_query.append(n_q) return sorted(r_query) from collections import defaultdict, deque, Counter from sys import exit from decimal import * import heapq import math from fractions import gcd import random import string import copy from itertools import combinations, permutations, product from operator import mul from functools import reduce from bisect import bisect_left, bisect_right import sys sys.setrecursionlimit(1000000000) mod = 10 ** 9 + 7 ############# # Main Code # ############# X, Y, A, B, C = getNM() P = getList() Q = getList() R = getList() P.sort() Q.sort() lista = P[-X:] + Q[-Y:] + R lista.sort() print(sum(lista[-(X + Y):]))
1
44,625,292,822,340
null
188
188
N=int(input()) ans = [] for i in range(1,N+1): if i % 3 == 0 and i % 5 == 0: continue elif i % 3 == 0 and i % 5 != 0: continue elif i % 5 == 0 and i % 3 != 0: continue else: ans.append(i) print(sum(ans))
import sys sys.setrecursionlimit(2147483647) INF=float('inf') MOD=10**9+7 input=sys.stdin.readline n=int(input()) #初期値が0の辞書 from collections import defaultdict tree = defaultdict(lambda: set([])) color={} key=[] for _ in range(n-1): a,b=map(int,input().split()) tree[a-1].add(b-1) tree[b-1].add(a-1) color[(a-1,b-1)]=0 key.append((a-1,b-1)) checked=[0]*n cnt=0 def DEF(parent_color,node_no): global color,checked,tree,cnt checked[node_no]=1 cnt=max(cnt,parent_color) i=1 #print("node_no",node_no) for item in tree[node_no]: if checked[item]==0: if i==parent_color: i+=1 color[(min(item,node_no),max(item,node_no))]=i DEF(i,item) i+=1 DEF(0,1) print(cnt) for item in key: print(color[item])
0
null
85,856,697,178,340
173
272
N = int(input()) A = list(map(int, input().split())) l = [0]*N for i in A: l[i-1] += 1 print(*l, sep="\n")
import sys, bisect, math, itertools, heapq, collections from operator import itemgetter # a.sort(key=itemgetter(i)) # i番目要素でsort from functools import lru_cache # @lru_cache(maxsize=None) sys.setrecursionlimit(10**8) input = sys.stdin.readline INF = float('inf') mod = 10**9+7 eps = 10**-7 def inp(): ''' 一つの整数 ''' return int(input()) def inpl(): ''' 一行に複数の整数 ''' return list(map(int, input().split())) n, k, c = inpl() s = list(input())[:-1] q = collections.deque() cool = 0 left = [0] * n right = [0] * n val=-1 for i in range(n): if cool<=0 and s[i]=="o" and val<k: val += 1 cool = c else: cool-=1 left[i] = val cool = 0 val+=1 for i in range(n-1,-1,-1): if cool<=0 and s[i]=="o" and val>0: val -= 1 cool = c else: cool-=1 right[i]=val # print(left) # print(right) for i in range(n): if left[i]==right[i] and (i == 0 or left[i] - left[i - 1] == 1) and (i == n - 1 or right[i + 1] - right[i] == 1): print(i + 1)
0
null
36,814,487,381,844
169
182
n, m = map(int, input().split()) work = list(map(int, input().split())) if n - sum(work) < 0: print("-1") else: print(n - sum(work))
def cmb(n, k, mod, fac, ifac): """ nCkを計算する """ k = min(k, n-k) return fac[n] * ifac[k] * ifac[n-k] % mod def make_tables(mod, n): """ 階乗テーブル、逆元の階乗テーブルを作成する """ fac = [1, 1] ifac = [1, 1] #逆元の階乗テーブル・・・(2) inverse = [0, 1] #逆元テーブル・・・(3) for i in range(2, n+1): fac.append((fac[-1] * i) % mod) inverse.append((-inverse[mod % i] * (mod//i)) % mod) ifac.append((ifac[-1] * inverse[-1]) % mod) return fac, ifac X,Y=map(int,input().split()) wa = X+Y if (wa)%3!=0 or not (wa//3 <= X <= wa-wa//3): print(0) else: MOD = 10**9 + 7 fac, ifac = make_tables(MOD, wa // 3) ans = cmb(wa // 3, X - wa // 3, MOD, fac, ifac) print(ans)
0
null
91,134,062,613,646
168
281
n,m = map(int,input().split()) h = list(map(int,input().split())) ab = [list(map(int,input().split())) for _ in range(m)] place = [True]*n for i in range(m): a,b = ab[i][0],ab[i][1] if h[a-1] < h[b-1]: place[a-1] = False elif h[a-1] == h[b-1]: place[a-1] = False place[b-1] = False else: place[b-1] = False print(place.count(True))
s = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51" lst = s.split(", ") print(lst[int(input()) - 1])
0
null
37,721,799,413,012
155
195
S = int(input()) s = (S % 60) m = (S % 3600 // 60) h = (S // 3600) print(h, ':', m, ':', s, sep='')
import math def main(): hp, attack = (int(i) for i in input().rstrip().split(' ')) print(str(math.ceil(hp / attack))) if __name__ == '__main__': main()
0
null
38,395,012,093,168
37
225
def resolve(): def check(arr): height = 0 for b, h in arr: if height+b < 0: return False height += h return True N = int(input()) plus = [] minus = [] total = 0 for _ in range(N): # 1つのパーツを処理 S = input() cum = 0 # 累積和(最高地点) bottom = 0 # 最下地点 for s in S: if s == "(": cum += 1 else: cum -= 1 bottom = min(bottom, cum) total += cum if cum > 0: plus.append((bottom, cum)) else: minus.append((bottom-cum, -cum)) plus.sort(reverse=True) minus.sort(reverse=True) if check(plus) and check(minus) and total == 0: print("Yes") else: print("No") if __name__ == "__main__": resolve()
def getN(): return int(input()) def getNM(): return map(int, input().split()) def getList(): return list(map(int, input().split())) from collections import defaultdict, deque from sys import exit import math import copy from bisect import bisect_left, bisect_right from heapq import * import sys # sys.setrecursionlimit(1000000) INF = 10 ** 17 MOD = 1000000007 from fractions import * def inverse(f): # return Fraction(f.denominator,f.numerator) return 1 / f def combmod(n, k, mod=MOD): ret = 1 for i in range(n - k + 1, n + 1): ret *= i ret %= mod for i in range(1, k + 1): ret *= pow(i, mod - 2, mod) ret %= mod return ret MOD = 10 ** 9 + 7 def solve(): n = getN() bit_array = [[0, 0] for i in range(61)] nums = getList() for num in nums: digit = 0 while(digit < 61): if num % 2 == 0: bit_array[digit][0] += 1 else: bit_array[digit][1] += 1 digit += 1 num //= 2 # print(bit_array) ans = 0 for i, tgt in enumerate(bit_array): ans += pow(2, i, MOD) * tgt[0] * tgt[1] ans %= MOD print(ans ) def main(): n = getN() for _ in range(n): solve() if __name__ == "__main__": solve()
0
null
73,463,674,118,520
152
263
def main(): strTxt = input() n = int(input()) for _ in range(n): strCmd = input().split() if strCmd[0] == 'print': funcPrint(strTxt, int(strCmd[1]), int(strCmd[2])) elif strCmd[0] == 'reverse': strTxt = funcReverse(strTxt, int(strCmd[1]), int(strCmd[2])) elif strCmd[0] == 'replace': strTxt = funcReplace(strTxt, int(strCmd[1]), int(strCmd[2]), strCmd[3]) def funcPrint(strInput: str,a: int,b: int): print(strInput[a:b+1]) def funcReverse(strInput: str,a: int,b: int): return strInput[:a]+strInput[a:b+1][::-1]+strInput[b+1:] def funcReplace(strInput: str,a: int,b: int, strAfter: str): return strInput[:a]+strAfter+strInput[b+1:] if __name__ == '__main__': main()
s = str(input()) q = int(input()) for i in range(q): arr = list(map(str, input().split())) c = arr[0] n1 = int(arr[1]) n2 = int(arr[2]) if c == 'print': print(s[n1:n2 + 1]) if c == 'replace': s = s[0:n1] + arr[3] + s[n2 + 1:len(s)] if c == 'reverse': l = n2 - n1 + 1 reverse = '' for i in range(l): reverse += s[n2 - i] s = s[0:n1] + reverse + s[n2 + 1:len(s)]
1
2,109,048,795,268
null
68
68
N = int(input()) ans = 0 if N % 1000 == 0: print(ans) else: a = N // 1000 ans = (a+1)*1000 - N print(ans)
n = int(input()) bez = 1000 while bez < n: bez += 1000 print(bez-n)
1
8,495,975,059,992
null
108
108
x=list(map(int, input().split())) L=x[0] R=x[1] d=x[2] res=0 while L<=R: if L%d==0: res+=1 L+=1 print(res)
L, R, D = map(int, input().split()) print(R//D-(L-1)//D)
1
7,560,091,429,170
null
104
104
n,m,l=map(int,raw_input().split()) A=[] B=[] for i in range(n): A.append(map(int,raw_input().split())) for i in range(m): B.append(map(int,raw_input().split())) for i in range(n): print(' '.join(map(str,[sum([A[i][j]*B[j][k] for j in range(m)]) for k in range(l)])))
from math import radians, sin, cos, sqrt a, b, C = map(float, input().split()) h = b * sin(radians(C)) c = sqrt(a*a+b*b-2*a*b*cos(radians(C))) S = a * h / 2 L = a + b + c print(S, L, h)
0
null
795,155,027,282
60
30
def main(): N,K = map(int,input().split()) A = [0] + list(map(int,input().split())) i = 1 pas = [i] pas_set = set(pas) k = 1 while k <= K: if A[i] in pas_set: rps = pas.index(A[i]) ans = A[i] break pas.append(A[i]) pas_set.add(A[i]) ans = A[i] i = A[i] k += 1 if k >= K: print(ans) else: rpnum = (K-rps)%(k-rps) print(pas[rps+rpnum]) main()
import queue N=int(input()) M=[input().split()[2:]for _ in[0]*N] q=queue.Queue();q.put(0) d=[-1]*N;d[0]=0 while q.qsize()>0: u=q.get() for v in M[u]: v=int(v)-1 if d[v]<0:d[v]=d[u]+1;q.put(v) for i in range(N):print(i+1,d[i])
0
null
11,309,454,483,950
150
9
import numpy as np import itertools as it H,W,N = [int(i) for i in input().split()] dat = np.array([list(input()) for i in range(H)], dtype=str) emp_r = ["." for i in range(W)] emp_c = ["." for i in range(H)] def plot(dat, dict): for y in dict["row"]: dat[y,:] = emp_r for x in dict["col"]: dat[:,x] = emp_c return dat def is_sat(dat): count = 0 for y in range(W): for x in range(H): if dat[x, y] == "#": count += 1 if count == N: return True else: return False # def get_one_idx(bi, digit_num): # tmp = [] # for j in range(digit_num): # if (bi >> j) == 1: # tmp.append() # plot(dat, dict={"row": [], "col":[0, 1]}) combs = it.product([bin(i) for i in range(2**H-1)], [bin(i) for i in range(2**W-1)]) count = 0 for comb in combs: rows = comb[0] cols = comb[1] rc_dict = {"row": [], "col": []} for j in range(H): if (int(rows, 0) >> j) & 1 == 1: rc_dict["row"].append(j) for j in range(W): if (int(cols, 0) >> j) & 1 == 1: rc_dict["col"].append(j) dat_c = plot(dat.copy(), rc_dict) if is_sat(dat_c): count += 1 print(count)
N = int(input()) ans = [] i = 1 while i * i <= N: if N % i == 0: x = i y = N / i ans.append(x+y-2) i += 1 print(int(min(ans)))
0
null
85,438,961,031,200
110
288
H, A = (int(x) for x in input().split()) if H%A==0: print(int(H/A)) else: print(int(H/A)+1)
h,a = map(int,input().split()) if h % a == 0: print(h//a) else: print(h//a+1)
1
77,297,583,982,080
null
225
225
x = list(map(int, input().split())) if len(set(x))==2: kotae='Yes' else: kotae='No' print(kotae)
import math from functools import lru_cache @lru_cache(maxsize = None) def count_change_point_min(r , c , current_color): min_values = list() if r != h-1: min_values.append(count_change_point_min(r+1, c, S[r][c])) if c != w-1: min_values.append(count_change_point_min(r, c+1, S[r][c])) if len(min_values) == 0: min_values.append(0) return min(min_values) + (0 if S[r][c] == current_color else 1) h,w = map(int,input().split()) S = list() for _ in range(h): S.append(list(input())) if S[0][0] == ".": ceil_or_floor = math.floor else: ceil_or_floor = math.ceil print (ceil_or_floor((count_change_point_min(0, 0, S[0][0])+1) / 2))
0
null
58,651,186,850,138
216
194
n = int(input()) d = [list(map(int, input().split())) for _i in range(n)] c = 0 for i, j in d: if i==j: c += 1 if c == 3: print('Yes') import sys sys.exit() else: c = 0 print('No')
n=int(input()) l = [list(map(int,input().split())) for i in range(n)] ans='No' for i in range(n-2): if l[i][0]==l[i][1] and l[i+1][0]==l[i+1][1] and l[i+2][0]==l[i+2][1]: ans='Yes' print(ans)
1
2,453,187,045,662
null
72
72
import sys sys.setrecursionlimit(10 ** 5) def dfs(v): if v > 3234566667: return ans.append(v) d = v % 10 if d - 1 >= 0: dfs(v * 10 + d - 1) dfs(v * 10 + d) if d + 1 < 10: dfs(v * 10 + d + 1) K = int(input()) ans = [] [dfs(i) for i in range(1, 10)] print(sorted(ans)[K - 1])
A,B,C,K = map(int,input().split()) SCO = 0 if A>K: SCO+=K else: SCO+=A if B<=(K-A): if C<=(K-A-B): SCO-=C else: SCO-=K-A-B print(SCO)
0
null
30,999,797,781,540
181
148
from subprocess import* call(('pypy3','-c',""" n,t=[int(j) for j in input().split()] ab=[] ans=[] dp=[0]*t for i in range(n): tmp=[int(j) for j in input().split()] ab.append(tmp) ab.sort() for a,b in ab: for i in range(t)[::-1]: if dp[i]!=0 or i==0: if i+a>=t: ans.append(dp[i]+b) else: dp[i+a]=max(dp[i+a],dp[i]+b) if ans: print(max(ans)) else: print(max(dp)) """))
N = int(input()) ans = [0 for _ in range(N+1)] for x in range(1, 101): for y in range(x, 101): for z in range(y, 101): v = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x if v < N+1: if x == y == z: ans[v] += 1 elif x == y or x == z or z == y: ans[v] += 3 else: ans[v] += 6 for i in range(1,N+1): print(ans[i])
0
null
80,183,942,831,332
282
106
tmp = input().split(" ") A = int(tmp[0]) B = int(tmp[1]) print(max([A - 2 * B, 0]))
A, B, C, D = map(int, input().split()) print('No' if -A // D > -C // B else 'Yes')
0
null
97,736,402,535,520
291
164
n=input() s=[[1 for i in range(13)] for j in range(4)] for i in range(n): a,b=map(str,raw_input().split()) b=int(b) if a=='S':s[0][b-1]=0 elif a=='H':s[1][b-1]=0 elif a=='C':s[2][b-1]=0 else:s[3][b-1]=0 for i in range(4): for j in range(13): if s[i][j]: if i==0:print'S',j+1 if i==1:print'H',j+1 if i==2:print'C',j+1 if i==3:print'D',j+1
N = int(input()) A = list(map(int,input().split())) cums = [0] for a in A: cums.append(cums[-1] + a) MOD = 10**9+7 ans = 0 for i in range(N-1): ans += A[i] * (cums[-1] - cums[i+1]) ans %= MOD print(ans)
0
null
2,449,460,752,770
54
83
string = input() n = int(input()) print_s=[] for i in range(n): order = [i for i in input().split()] if order[0] == "replace": string = list(string) for i in range(len(order[3])): string[int(order[1])+i]=order[3][i] string= "".join(string) elif order[0] == "reverse": string = string.replace(string[int(order[1]):int(order[2])+1], string[int(order[2])-len(string): int(order[1])-len(string)-1:-1]) else: print_s.append(string[int(order[1]):int(order[2])+1]) for i in range(len(print_s)): print(print_s[i])
nums = input().split() a = int(nums[0]) b = int(nums[1]) print(a * b, 2 * a + 2 * b)
0
null
1,183,054,205,664
68
36
import math N = int(input()) count = 0 for A in range(1, N): for B in range(1, math.ceil(N/A)): if A * B < N: count += 1 print(count)
import sys def I(): return int(sys.stdin.readline().rstrip()) N = I() for i in range(int(N**.5),0,-1): if N % i == 0: print(i+(N//i)-2) exit()
0
null
82,006,297,748,310
73
288
N = int(input()) A = list(map(int, input().split())) P = sum(A)**2 Q = 0 for i in range (0, N): Q+=(A[i])**2 print(((P-Q)//2)%(10**9+7))
MOD = 10**9 + 7 N = int(input()) A = list(map(int, input().split())) modS = [0] for i in A: modS.append((modS[-1] + i) % MOD) ans = 0 for i in range(1, N + 1): count = modS[-1] - modS[i] if count < 0: count = MOD + count ans = (ans + (A[i - 1] * count % MOD)) % MOD print(ans)
1
3,880,059,454,528
null
83
83
H, W, K = map(int, input().split()) m = [] for h in range(H): m.append(list(map(int, list(input())))) ans = float('inf') for hb in range(2**(H-1)): hl = [] for i in range(H-1): if hb & (1 << i) > 0: hl.append(i+1) t = len(hl) hl = [0]+hl+[H] w, pw = 0, 0 wl = [0]*len(hl) while w < W: ok = True for i in range(len(hl)-1): sh, eh = hl[i], hl[i+1] for h in range(sh, eh): wl[i] += m[h][w] if wl[i] > K: ok = False break if not ok: break if not ok: if pw == w: t = float('inf') break pw, w = w, w t += 1 wl = [0]*len(hl) else: w += 1 ans = min(t, ans) print(ans)
import numpy as np from numpy.fft import rfft, irfft N, M = map(int, input().split()) *A, = map(int, input().split()) B = np.zeros(5*10**5) for a in A: B[a] += 1 L = 5*10**5 FB = rfft(B, L) C = np.rint(irfft(FB*FB)).astype(int) ans = 0 for i in range(2*10**5, -1, -1): c = C[i] if not c: continue if M - c > 0: ans += i*c M -= c else: ans += i*M break print(ans)
0
null
78,362,247,970,208
193
252
def insertionsSort(A): print(*A) N = len(A) for i in range(1, N): v = A[i] j = i - 1 while j >= 0 and A[j] > v: A[j + 1] = A[j] j -= 1 A[j + 1] = v print(*A) N = int(input()) A = list(map(int, input().split())) insertionsSort(A)
n, k, c = map(int, input().split()) s = input() work = [1]*n rest = 0 for i in range(n): if rest: rest -= 1 work[i] = 0 continue if s[i] == 'x': work[i] = 0 elif s[i] == 'o': rest = c rest = 0 for i in reversed(range(n)): if rest: rest -= 1 work[i] = 0 continue if s[i] == 'o': rest = c if k < sum(work): print() else: for idx, bl in enumerate(work): if bl: print(idx+1)
0
null
20,226,567,163,240
10
182
while True: n, x = map(int, input().split()) if n == x == 0: break cnt = 0 for i in range(1, min(n - 1, int(x / 3))): for j in range(i + 1, n): for k in range(j + 1, n + 1): if (i + j + k) == x: cnt += 1 print(cnt)
l=map(int,raw_input().split()) a=l[0] b=l[1] c=l[2] if a>b: a,b=b,a if b>c: b,c=c,b if a>b: a,b=b,a print a,b,c
0
null
845,913,469,540
58
40
from collections import defaultdict def main(): _, S = open(0).read().split() indices, doubled_indices = defaultdict(list), defaultdict(set) for i, c in enumerate(S): indices[c].append(i) doubled_indices[c].add(2 * i) cnt = S.count("R") * S.count("G") * S.count("B") for x, y, z in ["RGB", "GBR", "BRG"]: cnt -= sum(i + j in doubled_indices[z] for i in indices[x] for j in indices[y]) print(cnt) if __name__ == "__main__": main()
from collections import deque k = int(input()) q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9]) cnt = 0 while q: curr = q.popleft() cnt += 1 if cnt == k: break if curr % 10 == 9: q.append(curr * 10 + curr % 10 - 1) q.append(curr * 10 + curr % 10) elif curr % 10 == 0: q.append(curr * 10 + curr % 10) q.append(curr * 10 + curr % 10 + 1) else: q.append(curr * 10 + curr % 10 - 1) q.append(curr * 10 + curr % 10) q.append(curr * 10 + curr % 10 + 1) print(curr)
0
null
38,115,105,968,568
175
181
L = [] n,x = map(int, input().split()) while not(n == 0 and x == 0): L.append([n, x]) n, x = map(int, input().split()) for i in L: ans = 0 for j in range(1, i[0] - 1): if j > i[1] - 3: break else: for k in range(j + 1, i[0]): m = i[1] - (j + k) if m <= k: break elif m <= i[0]: ans += 1 else: continue print(ans)
n = int(input()) person = [[0 for _ in range(10)] for _ in range(12)] for _ in range(n): b, f, r, v = [int(m) for m in input().split()] person[3*(b-1)+f-1][r-1] += v for index, p in enumerate(person): print(" "+" ".join([str(m) for m in p])) if (index+1)%3 == 0 and index < len(person)-1: print("####################")
0
null
1,199,000,385,870
58
55
import sys import math def Ii():return int(sys.stdin.buffer.readline()) def Mi():return map(int,sys.stdin.buffer.readline().split()) def Li():return list(map(int,sys.stdin.buffer.readline().split())) x = Ii() ans = 0 k = 100 while x > k: tax = k//100 k += tax ans += 1 print(ans)
X = int(input()) c = 0 i = 100 while True: c += 1 i = i + i//100 if X <= i: break print(c)
1
27,132,979,832,100
null
159
159
memo = [1, 1] def fib(n): if (n < len(memo)): return memo[n] memo.append(fib(n-1) + fib(n-2)) return memo[n] N = int(input()) print(fib(N))
def fibonacci(n): if n == 0 or n == 1: F[n] = 1 return F[n] if F[n] is not None: return F[n] F[n] = fibonacci(n - 1) + fibonacci(n - 2) return F[n] n = int(input()) F = [None]*(n + 1) print(fibonacci(n))
1
1,653,637,000
null
7
7
n = int(input()) d = list(map(int, input().split())) if d[0] != 0: print(0) exit() d.sort() import collections c = collections.Counter(d) if c[0] != 1: print(0) exit() ans=1 for i in range(1,d[-1]+1): if c[i] == 0: print(0) exit() ans*=(c[i-1]**c[i]) ans%=998244353 print(ans)
if __name__ == "__main__": from decimal import Decimal r = Decimal(raw_input()) pi = Decimal("3.14159265358979") print "{0:.6f} {1:.6f}".format( r * r * pi, 2 * r * pi)
0
null
77,489,963,476,770
284
46
N = int(input()) a_num = 97 def dfs(s, n): #s: 現在の文字列, n: 残りの文字数, cnt: 現在の文字列の最大の値 if n == 0: print(s) return for i in range(ord("a"), ord(max(s))+2): dfs(s+chr(i), n-1) dfs("a", N-1)
N = int(input()) D = [] count = 0 for i in range(N): d = list(map(int,input().split())) D.append(d) for i in range(N-2): if (D[i][0]==D[i][1]) and (D[i+1][0]==D[i+1][1]) and (D[i+2][0]==D[i+2][1]): print("Yes") break else: print("No")
0
null
27,601,100,161,040
198
72
n = int(input()) a = list(map(int, input().split())) a.sort() n_sum = a[0] sum = 0 for i in range(1,n): sum += a[i] * n_sum n_sum += a[i] print(sum % (10**9 + 7))
n = int(input()) a = list(map(int, input().split())) mod = 10**9+7 cur = 0 res = 0 for i in range(n-1): cur = (cur + a[n-1-i]) % mod tmp = (a[n-2-i] * cur) % mod res = (res + tmp) % mod print(res)
1
3,796,797,089,788
null
83
83
X,Y = (int(x) for x in input().split()) crane = 0 turtle = 0 for i in range(X+1): crane = (i) turtle = X-crane if crane*2 + turtle*4 == Y: print('Yes') break elif i == X: print('No')
import math def main(): mod = 1000000007 N = int(input()) A = list(map(int, input().split())) A_max = sorted(A)[-1] if A_max == 0: print(0) exit() bit_max = int(math.ceil(math.log2(A_max))) i = 0 bit = 1 res = 0 while i <= bit_max: c_zero = 0 c_one = 0 for j in range(N): if A[j] & bit == 0: c_zero += 1 else: c_one += 1 m_bit = bit % mod res += m_bit*c_zero*c_one res %= mod i += 1 bit<<=1 print(res) if __name__ == "__main__": main()
0
null
68,592,289,084,258
127
263
import sys input=sys.stdin.readline inf=10**9+7 n,m,l=map(int,input().split()) D=[[inf]*(n+1) for _ in range(n+1)] for _ in range(m): a,b,c=map(int,input().split()) D[a][b]=c D[b][a]=c for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): D[i][j]=min(D[i][j],D[i][k]+D[k][j]) DD=[[inf]*(n+1) for _ in range(n+1)] for x in range(1,n+1): for y in range(1,n+1): if D[x][y]<=l: DD[x][y]=1 for k in range(1,n+1): for i in range(1,n+1): for j in range(1,n+1): DD[i][j]=min(DD[i][j],DD[i][k]+DD[k][j]) q=int(input()) for _ in range(q): s,t=map(int,input().split()) if DD[s][t]==inf: print(-1) else: print(DD[s][t]-1)
N, M, L = map(int, input().split()) INF = float('inf') d1 = [[INF]*N for _ in range(N)] for _ in range(M): a, b, c = map(int, input().split()) a -= 1 b -= 1 d1[a][b] = c d1[b][a] = c for i in range(N): d1[i][i] = 0 for k in range(N): for i in range(N): for j in range(N): d1[i][j] = min(d1[i][k] + d1[k][j], d1[i][j]) d2 = [[INF]*N for _ in range(N)] for i in range(N): for j in range(N): if i == j: d2[i][j] = 0 if d1[i][j] <= L and i != j: d2[i][j] = 1 for k in range(N): for i in range(N): for j in range(N): d2[i][j] = min(d2[i][k] + d2[k][j], d2[i][j]) Q = int(input()) for _ in range(Q): s, t = map(int, input().split()) s -= 1 t -= 1 if d2[s][t] == INF: print(-1) else: print(d2[s][t]-1)
1
173,171,313,032,480
null
295
295
import math x1,y1,x2,y2=map(float,raw_input().split()) print "%.5f"%(float(math.sqrt((x1-x2)**2+(y1-y2)**2)))
import sys def MI(): return map(int,sys.stdin.readline().rstrip().split()) a,b = MI() c,d = MI() print(1 if d == 1 else 0)
0
null
62,010,311,697,920
29
264
#!/usr/bin/env python3 from itertools import accumulate def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) A.sort() p = 10**9 + 7 if K == 1: print(0) exit() a = [None] * (N+1) inva = [None] * (N+1) a[0] = 1 for i in range(1, N+1): a[i] = i * a[i-1] % p inva[N] = pow(a[N],p-2,p) for i in range(N): inva[N-i-1] = inva[N-i] * (N-i) % p ans = 0 maxA = list(accumulate(A[::-1])) minA = list(accumulate(A)) # print(A) # print(maxA) # print(minA) # if K > 2: # maxA = sum(A[N-(K-2):]) # minA = sum(A[:K-2]) for i in range(K-1,N):# 1つ隣どうしからN-1つ隣まで j = min(i,N-i) # print(i,j,maxA[j-1],minA[j-1]) tmp = (a[i-1]*inva[K-2] % p) * inva[i-K+1] % p ans += (maxA[j-1]-minA[j-1]) * tmp % p ans %= p print(ans) if __name__ == "__main__": main()
def power(a,n): x=1 L=list(format(n,'b')) l=len(L) for i in range(l): if int(L[l-i-1])==1: x=(x*a)%(10**9+7) a=(a*a)%(10**9+7) return x N,K=map(int,input().split()) A=list(map(int,input().split())) b=sorted(A) c=sorted(A,reverse=True) D=[] M=0 x=1 y=1 for l in range(K-1): x=(x*(N-l-1))%(10**9+7) y=(y*(l+1))%(10**9+7) y=power(y,10**9+5) M+=(x*y*(c[0]-b[0]))%(10**9+7) for i in range(1,N-K+1): y1=power(N-i,10**9+5) x=(x*y1)%(10**9+7) x=(x*(N-K-i+1))%(10**9+7) m=(x*y*(c[i]-b[i])) if m>0: m=m%(10**9+7) M+=m M%(10**9+7) print(M%(10**9+7))
1
95,783,501,916,270
null
242
242
import math def factorization(N): tmp=N F=[] for i in range(2,int(math.sqrt(N))+1): if tmp%i==0: F.append(i) tmp//=i while tmp%i==0: tmp//=i if i>tmp: break if tmp!=1: F.append(tmp) return F N=int(input()) F=factorization(N) ans=0 for f in F: ff=f while N%ff==0: ans+=1 N//=ff ff*=f print(ans)
input_line = input() stack = [] area = 0 pond_area = 0 pond_areas = [] for i,s in enumerate(input_line): if s == '\\': stack.append(i) if pond_area: pond_areas.append((l, pond_area)) pond_area = 0 elif stack and s == '/': l = stack.pop() area += i - l while True: if not pond_areas or pond_areas[-1][0] < l: break else: pond_area += pond_areas.pop()[1] pond_area += i-l if pond_area > 0: pond_areas.append((l, pond_area)) print(area) print( " ".join([str(len(pond_areas))] + [str(a[1]) for a in pond_areas]) )
0
null
8,502,719,191,440
136
21
n,k=map(int,input().split()) #階乗 F = 200005 mod = 10**9+7 fact = [1]*F inv = [1]*F for i in range(2,F): fact[i]=(fact[i-1]*i)%mod inv[F-1]=pow(fact[F-1],mod-2,mod) for i in range(F-2,1,-1): inv[i] = (inv[i+1]*(i+1))%mod ans=1 for i in range(1,min(n,k+1)): comb=(fact[n]*inv[i]*inv[n-i])%mod h=(fact[n-1]*inv[i]*inv[n-1-i])%mod ans=(ans+comb*h)%mod print(ans)
n, k = map(int, input().split()) a = [0] + list(map(int, input().split())) journey = [1] for i in range(n): journey.append(a[journey[i]]) if k <= n: print(journey[k]) exit() cycle_end = n cycle_start = n - 1 while journey[cycle_start] != journey[cycle_end]: cycle_start -= 1 cycle_range = cycle_end - cycle_start cycle_cnt = (k - n) // cycle_range extra = (k - n) - (cycle_range * cycle_cnt) for i in range(extra): journey.append(a[journey[i + n]]) print(journey[-1])
0
null
44,955,272,816,012
215
150
s = input() if ord(s) >= 65 and ord(s) <= 90 : print("A") elif ord(s) >= 97 and ord(s) <= 122 : print("a")
a = input() print('a' if a.islower() else 'A')
1
11,349,035,046,096
null
119
119
N = int(input()) a = list(map(int, input().split())) x = 0 for r in a: x ^= r a = [str(x^r) for r in a] a = ' '.join(a) print(a)
N = int(input()) a = list(map(int, input().split())) for i in range(N): if i == 0: tmp = a[i] else: tmp = tmp ^ a[i] ans = [] for i in range(N): ans.append(tmp ^ a[i]) print(*ans)
1
12,567,049,727,010
null
123
123
import math N=int(input()) A=[0]*N B=[0]*N for i in range(N): A[i],B[i]=map(int,input().split()) total=0 for i in range(N): for j in range(i+1,N): total+=((A[i]-A[j])**2+(B[i]-B[j])**2)**0.5 print(total/N*2)
n,m=map(int,input().split()) diffs=set() idxs=set() i=1 diff=n-1 cnt=0 while 1: if i>m: break while (diff in diffs and n-diff in diffs) or (i+diff in idxs) or (diff==n-diff): diff-=1 diffs.add(n-diff) diffs.add(diff) idxs.add(i+diff) print(i,i+diff) i+=1
0
null
88,861,127,937,572
280
162
x, y, a, b, c = list(map(int, input().split())) pA = list(map(lambda x: (int(x), "a"), input().split())) pB = list(map(lambda x: (int(x), "b"), input().split())) pC = list(map(lambda x: (int(x), "c"), input().split())) apples = sorted(pA + pB + pC) cntA = 0 cntB = 0 cntC = 0 cnt = 0 while cntA + cntB + cntC < x+y: val, col = apples.pop() if col == "a" and cntA < x: cntA += 1 cnt += val elif col == "b" and cntB < y: cntB += 1 cnt += val elif col == "c": cntC += 1 cnt += val print(cnt)
#coding:utf-8 x=[[[0 for i in range(10)] for j in range(3)]for k in range(4)] n=int(input()) for i in range(n): b,f,r,v=list(map(int,input().split())) x[b-1][f-1][r-1]+=v for line,i in enumerate(x): for j in i: for k in j: print(" "+str(k),end="") print("") if line!=3: for i in range(20): print("#",end="") print("")
0
null
22,892,251,039,850
188
55
#!/usr/bin/env python3 def main(): h,w,k = map(int, input().split()) s = [input() for i in range(h)] l = [[0]*w for i in range(h)] from collections import deque d = deque() c = 1 for i in range(h): for j in range(w): if s[i][j] == '#': d.append([i, j]) l[i][j] = c c += 1 while len(d) > 0: x,y = d.pop() c = l[x][y] l[x][y] = c f1 = True f2 = True for i in range(1,w): if y+i < w and l[x][y+i] == 0 and s[x][y+i] != '#' and f1: l[x][y+i] = c else: f1 = False if 0 <= y-i and l[x][y-i] == 0 and s[x][y-i] != '#' and f2: l[x][y-i] = c else: f2 = False for i in range(h): if all(l[i]) == 0: k1 = 1 while 0 < i+k1 < h and all(l[i+k1]) == 0: k1 += 1 # print("test: ", i, k1) if i+k1 < h: for j in range(i, i+k1): for r in range(w): l[j][r] = l[i+k1][r] for i in range(h-1, -1, -1): if all(l[i]) == 0: k1 = 1 while 0 < i-k1 < h and all(l[i-k1]) == 0: k1 += 1 # print("test: ", i, k1) if 0 <= i-k1 < h: for j in range(i, i-k1, -1): for r in range(w): l[j][r] = l[i-k1][r] for i in range(h): print(' '.join(map(str, l[i]))) if __name__ == '__main__': main()
a, b, c = map(int, raw_input().split()) count = 0 for i in range(a, b + 1): if c % i == 0: count = count + 1 print '%s' % str(count)
0
null
72,357,087,549,820
277
44
s = list(input()) if s[2] == s[3]: if s[4] == s[5]: print("Yes") else: print("No") exit else: print("No") exit
chars = [c for c in input()] print('Yes' if chars[2] == chars[3] and chars[4] == chars[5] else 'No')
1
42,211,650,584,332
null
184
184
N = input() S = 0 for m in N: S += int(m) S %= 9 if S == 0: print('Yes') else: print('No')
count = input() #print(len(count)) num = 0 for i in range(len(count)): num += int(count[i]) if num % 9 == 0: print("Yes") else: print("No")
1
4,453,123,775,840
null
87
87
def tri_num(num): num -= 1 return int(num * (num + 1) / 2) def main(): n, m = map(int, input().split()) print(tri_num(n) + tri_num(m)) if __name__ == "__main__": main()
from collections import defaultdict iim = lambda: map(int, input().rstrip().split()) def resolve(): N = int(input()) A = list(iim()) ans = 0 dp = [0]*N for i, ai in enumerate(A): x = i + ai if x < N: dp[x] += 1 x = i - ai if x >= 0: ans += dp[x] print(ans) resolve()
0
null
35,914,238,734,130
189
157
S=list(str(input())) A='' B='' while len(S)>0: A+=S.pop() if len(S)>0: B+=S.pop() if (len(A)+len(B))%2!=0: print('No') elif len(set(A))==len(set(B))==1: if 'h' in A or 'i' in A: if 'h' in B or 'i' in B: print('Yes') else: print('No') else: print('No') else: print('No')
while True : h,w = map(int,raw_input().split()) if h==0 and w==0: break else : for i in range(h): print '#'*w print''
0
null
27,184,402,425,150
199
49
n = int(input()) alphabets = [chr(ord('a') + x) for x in range(26)] tmp = [] def dfs(s, i): if len(s) == n: yield s return for j in range(i): for k in dfs(s+alphabets[j], i): yield k for k in dfs(s+alphabets[i], i+1): yield k for w in dfs('', 0): print(w)
n = int(input()) def aa(str, chrMax): if len(str) == n: print(str) return for i in range(ord("a"), ord(chrMax)+2): if i > ord(chrMax): aa(str+chr(i), chr(i)) else: aa(str+chr(i), chrMax) aa("a", "a")
1
52,491,713,631,552
null
198
198
li = list(map(int,input().split())) n = 1 for i in li: if i == 0: print(n) n += 1
x1, x2, x3, x4, x5 = map(int, input().split()) if (x1 == 0): ans = 1 if (x2 == 0): ans = 2 if (x3 == 0): ans = 3 if (x4 == 0): ans = 4 if (x5 == 0): ans = 5 print(int(ans))
1
13,437,297,845,218
null
126
126
N = int(input()) A_list = list(map(int, input().split())) MOD = 10**9 + 7 zeros = [0] * 61 ones = [0] * 61 for a in A_list: for i, b in enumerate([1 if (a >> j & 1) else 0 for j in range(61)]): if b == 1: ones[i] += 1 else: zeros[i] += 1 res = 0 for a in A_list: twice = 1 for i, b in enumerate([1 if (a >> j & 1) else 0 for j in range(61)]): if b == 1: cnt = zeros[i] ones[i] -= 1 else: cnt = ones[i] zeros[i] -= 1 res += twice * cnt twice *= 2 res %= MOD print(res)
a,b=map(int,input().split()) a-=2*b if(a<0):a=0 print(a)
0
null
144,546,802,973,180
263
291
a,b = map(int,input().split()) if a <= 9 and a >= 1 and b <= 9 and b >= 1: print(a * b) else: print("-1")
str = input() q = int(input()) for x in range(q): en = input().split() if en[0] == "print": print(str[int(en[1]):int(en[2])+1]) elif en[0] == "reverse": str = str[:int(en[1])] + str[int(en[1]):int(en[2])+1][::-1] + str[int(en[2])+1:] else: str = str[:int(en[1])] + en[3] + str[int(en[2])+1:]
0
null
80,322,689,066,400
286
68
n = int(input()) if n == 1: print(0) exit() def is_prime(n): if n <= 1: return False for i in range(2, int(n**0.5) + 1): if n%i == 0: return False return True def make_divisors(n): divisors = [] for i in range(1, int(n**0.5)+1): if n%i == 0: divisors.append(i) if i!=n//i: divisors.append(n//i) divisors.sort() return divisors ans = [] cnt = 0 X = make_divisors(n)[1:] for x in X: if is_prime(x): ans.append(x) n //= x cnt += 1 e = 2 while x**e < n: ans.append(x**e) e += 1 elif x in ans: if n%x == 0: n //= x cnt += 1 print(cnt)
N = int(input()) def factorization(n): arr = [] temp = n for i in range(2, int(-(-n**0.5//1))+1): if temp%i==0: cnt=0 while temp%i==0: cnt+=1 temp //= i arr.append([i, cnt]) if temp!=1: arr.append([temp, 1]) if arr==[]: arr.append([n, 1]) return arr def add(X): counter = 0 while True: if counter * (counter + 1) <= X * 2: counter += 1 else: counter -= 1 break # print(X, counter) return counter facts = factorization(N) answer = 0 for f in facts: if f[0] != 1: answer += add(f[1]) print(answer)
1
16,871,087,103,432
null
136
136
import sys input = sys.stdin.readline from collections import deque k, q = int(input()), deque([1, 2, 3, 4, 5, 6, 7, 8, 9]) for i in range(1, k): x = q.popleft() if x % 10 != 0: q.append(10 * x + (x % 10) - 1) q.append(10 * x + (x % 10)) if x % 10 != 9: q.append(10 * x + (x % 10) + 1) print(q.popleft())
N = int(input()) d = {} for n in range(N): s = input() d[s] = True print(len(d))
0
null
35,253,353,886,630
181
165
H=int(input()) m=1 while (m<=H): m*=2 print(m-1)
N = int(input()) ans = 0 if N%2 == 0: five = 10 while N//five > 0: ans += N//five five *= 5 print(ans)
0
null
97,876,965,820,700
228
258
def sep(): return map(int,input().strip().split(" ")) def lis(): return list(sep()) a,b=sep() for i in range(1,10005): if (i*8)//100==a and (i*10)//100==b: print(i) quit() print(-1)
import math a,b = map(int,input().split()) c = math.ceil min8, max8 = c(a*12.5), c((a+1)*12.5) min10, max10 = c(b*10), c((b+1)*10) l8, l10 = list(range(min8, max8)), list(range(min10, max10)) s8, s10 = set(l8), set(l10) ss = s8 & s10 #print(min8, max8, min10, max10) print(min(ss) if len(ss) >0 else -1) #print(238*0.08)
1
56,397,420,217,000
null
203
203
import sys readline = sys.stdin.readline N = int(readline()) S = [readline().rstrip() for _ in range(N)] def count_cb_ob(s): st = [] for i, si in enumerate(s): if si == '(' or len(st) == 0 or st[-1] != '(': st.append(si) else: st.pop() return st.count(')'), st.count('(') cb_obs = map(count_cb_ob, S) f, b, s = [], [], [] for down, up in cb_obs: (f if down < up else (s if down == up else b)).append((down, up)) f = sorted(f) b = sorted(b, key=lambda x:x[1], reverse=True) count = 0 ans = 'Yes' for down, up in (*f, *s, *b): count -= down if count < 0: ans = 'No' count += up if count != 0: ans = 'No' print(ans)
n,k=map(int,input().split()) mod=10**9+7 ans=0 A=[0]*k for i in range(k,0,-1): a=0 A[i-1]=pow((k//i),n,mod) m=i*2 while m<=k: A[i-1]=(A[i-1]-A[m-1])%mod m=m+i ans=(ans+i*A[i-1])%mod print(ans%mod)
0
null
30,102,495,014,862
152
176
a=int(input()) b=a//200 print(str(10-b))
def find(X): rate = X//200 return 10-rate print(find(int(input())))
1
6,670,785,634,498
null
100
100
k, n = map(int, input().split()) a = list(map(int, input().split())) a.append(a[0] + k) dist = [a[i + 1] - a[i] for i in range(n)] print(sum(dist) - max(dist))
#C - Traveling Salesman around Lake WA(ヒント) K,N = map(int,input().split()) A = list(map(int, input().split())) A[N+1:] = [A[0] + K]#Aを二回繰り返して円を表現 distance_list = [] for i in range(N): distance = abs(A[i] - A[i+1]) distance_list.append(distance) distance_list.remove(max(distance_list)) print(sum(distance_list))
1
43,188,224,297,788
null
186
186
nums = int(input()) array = list(map(int, input().split())) for i in range( nums ): v = array[i] j = i - 1 while j >= 0 and array[j] > v: array[j+1] = array[j] j -= 1 array[j+1] = v print(*array)
x = int(input()) money = 100 count = 0 while money < x: money = (money * 101) // 100 count += 1 print(count)
0
null
13,533,654,698,916
10
159
N = int(input()) def factorization(n): # => {prime:count,...} fac = {} count = 0 while n % 2 == 0: n //= 2 count += 1 if count > 0: fac[2] = count for i in range(3, int(n ** .5) + 1, 2): count = 0 while n % i == 0: n //= i count += 1 if count > 0: fac[i] = count if n > 1: fac[n] = 1 return fac ans = 0 for key, cnt in factorization(N).items(): n = 1 while cnt >= 0: cnt -= n n += 1 ans += 1 ans -= 1 print(ans)
h,w,m = map(int,input().split()) hw = [list(map(int,input().split())) for i in range(m)] hb = [0] * h wb = [0] * w for i in range(m): hb[hw[i][0]-1] += 1 wb[hw[i][1]-1] += 1 max_h = max(hb) max_w = max(wb) ans = max_h + max_w count = hb.count(max_h) * wb.count(max_w) for i in range(m): if hb[hw[i][0]-1] == max_h and wb[hw[i][1]-1] == max_w: count -= 1 if count <= 0: ans -= 1 print(ans)
0
null
10,760,715,893,120
136
89
#coding: utf-8 while True: m, f, r = (int(i) for i in input().split()) if m == f == r == -1: break if m == -1 or f == -1: print("F") elif m + f >= 80: print("A") elif m + f >= 65 and m + f < 80: print("B") elif (m + f >= 50 and m + f < 65) or r >= 50: print("C") elif m + f >= 30 and m + f < 50: print("D") elif m + f < 30: print("F")
#!/usr/bin/env python3 n = int(input()) x = input() b = [0] * (n+1) for i in range(1, n+1): bit_count = 0 for j in range(20): if i >> j & 1: bit_count += 1 b[i] = bit_count popcount = [0] * (n+1) cnt = x.count('1') for i in range(1, n+1): popcount[i] = popcount[i % b[i]] + 1 ans = [] if cnt == 1: tmp = 0 for i in range(n): if x[i] == '1': tmp += pow(2, n-i-1, 2) tmp %= 2 for i in range(n): if x[i] == '1': ans.append(0) else: ans.append(popcount[(tmp - pow(2, n-i-1, 2)) % 2] + 1) else: tmp1 = 0 tmp2 = 0 for i in range(n): if x[i] == '1': tmp1 += pow(2, n-i-1, cnt + 1) tmp2 += pow(2, n-i-1, cnt - 1) for i in range(n): if x[i] == '1': ans.append(popcount[(tmp2 - pow(2, n-i-1, cnt - 1)) % (cnt - 1)] + 1) else: ans.append(popcount[(tmp1 + pow(2, n-i-1, cnt + 1)) % (cnt + 1)] + 1) for i in ans: print(i)
0
null
4,737,611,580,316
57
107
dic = {} #?????????"??????????¨???? ??????"??????????????° for cardtype in ['S','H','C','D']: for i in range(1,13+1): dic["{0} {1}".format(cardtype,i)] = 0 n = int(input()) for i in range(n): dic[input()] += 1 for cardtype in ['S','H','C','D']: for i in range(1,13+1): if dic["{0} {1}".format(cardtype,i)] == 0: print("{0} {1}".format(cardtype,i))
n = int(input()) my_cards = {input() for _ in range(n)} lost_cards = ( "{} {}".format(s, i) for s in ('S', 'H', 'C', 'D') for i in range(1, 13 + 1) if "{} {}".format(s, i) not in my_cards ) for card in lost_cards: print (card)
1
1,039,211,401,892
null
54
54
W=input() a=0 while True: T=input() if T=='END_OF_TEXT': break else: a +=T.lower().split().count(W) print(a)
MOD=10**9+7 class Fp(int): def __new__(self,x=0):return super().__new__(self,x%MOD) def inv(self):return self.__class__(super().__pow__(MOD-2,MOD)) def __add__(self,value):return self.__class__(super().__add__(value)) def __sub__(self,value):return self.__class__(super().__sub__(value)) def __mul__(self,value):return self.__class__(super().__mul__(value)) def __floordiv__(self,value):return self.__class__(self*self.__class__(value).inv()) def __pow__(self,value):return self.__class__(super().__pow__(value%(MOD-1), MOD)) __radd__=__add__ __rmul__=__mul__ def __rsub__(self,value):return self.__class__(-super().__sub__(value)) def __rfloordiv__(self,value):return self.__class__(self.inv()*value) def __iadd__(self,value):self=self+value;return self def __isub__(self,value):self=self-value;return self def __imul__(self,value):self=self*value;return self def __ifloordiv__(self,value):self=self //value;return self def __ipow__(self,value):self=self**value;return self def __neg__(self):return self.__class__(super().__neg__()) def main(): N,*A=map(int, open(0).read().split()) C=[0]*(N+1) C[-1]=3 ans=Fp(1) for a in A: ans*=C[a-1] C[a-1]-=1 C[a]+=1 print(ans) if __name__ == "__main__": main()
0
null
66,059,219,774,340
65
268
n = int(input()) all = 10**n all -= 9**n*2-8**n print(all%(10**9+7))
N=int(input()) testimonies=[] for i in range(N): A=int(input()) testimony=[] for j in range(A): testimony.append(list(map(int,input().split()))) testimony[-1][0]-=1 testimonies.append(testimony) ans=0 for i in range(2**N): isContradiction=False for j in range(N): if not i&1<<j:continue for x,y in testimonies[j]: if i&1<<x:x=1 else:x=0 if not x==y: isContradiction=True break if not isContradiction: ans=max(ans,bin(i).count("1")) print(ans)
0
null
62,597,282,331,430
78
262
import bisect,collections,copy,itertools,math,string import sys def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def S(): return sys.stdin.readline().rstrip() def LS(): return list(sys.stdin.readline().rstrip().split()) def main(): s = S() ans = 0 for i in range(len(s)//2): if s[i] != s[-(i+1)]: ans += 1 print(ans) main()
S = input() count = 0 for i in range(len(S)//2): if(S[i] != S[-i-1]): count += 1 print(count)
1
120,491,018,816,128
null
261
261
N = int(input()) A = list(map(int, input().split())) MOD = 1000000007 cnt = [0,0,0] # 現在割り当てられている人数 ans = 1 # 現時点での組み合わせ for a in A: idx = [] for i in range(3): if cnt[i] == a: # 割り当て可能 idx.append(i) if len(idx)==0: # 割り当て不能 print(0) exit() cnt[idx[0]]+=1 # 任意の色で良いので、一番番号が若い色とする ans *= len(idx) # 割り当て可能な人数をかける ans %= MOD print (ans)
MOD=10**9+7 class Fp(int): def __new__(self,x=0):return super().__new__(self,x%MOD) def inv(self):return self.__class__(super().__pow__(MOD-2,MOD)) def __add__(self,value):return self.__class__(super().__add__(value)) def __sub__(self,value):return self.__class__(super().__sub__(value)) def __mul__(self,value):return self.__class__(super().__mul__(value)) def __floordiv__(self,value):return self.__class__(self*self.__class__(value).inv()) def __pow__(self,value):return self.__class__(super().__pow__(value%(MOD-1), MOD)) __radd__=__add__ __rmul__=__mul__ def __rsub__(self,value):return self.__class__(-super().__sub__(value)) def __rfloordiv__(self,value):return self.__class__(self.inv()*value) def __iadd__(self,value):self=self+value;return self def __isub__(self,value):self=self-value;return self def __imul__(self,value):self=self*value;return self def __ifloordiv__(self,value):self=self //value;return self def __ipow__(self,value):self=self**value;return self def __neg__(self):return self.__class__(super().__neg__()) def main(): N,*A=map(int, open(0).read().split()) C=[0]*(N+1) C[-1]=3 ans=Fp(1) for a in A: ans*=C[a-1] C[a-1]-=1 C[a]+=1 print(ans) if __name__ == "__main__": main()
1
129,963,795,226,730
null
268
268
abc = input().split() a = int(abc[0]) b = int(abc[1]) c = int(abc[2]) # 12 if a > b: a, b = b, a # 13 if a > c: a, c = c, a # 23 if b > c: b, c = c, b print("{0} {1} {2}".format(a, b, c))
a,b,c=map(int,input().split()) if a>b: a,b = b,a if c<a: a,b,c = c,a,b if c<b: a,b,c = a,c,b print(a,b,c)
1
420,533,466,240
null
40
40
n=int(input()) s=0 ok=0 for i in range(n): lis=input().split() if lis[0]==lis[1]: s+=1 if s>=3: ok=1 else: s=0 if ok==1: print("Yes") else: print("No")
n = int(input()) s = 0 for i in range(n): x,y = map(int,input().split()) if x == y: s += 1 if s == 3: print("Yes") quit() else: s = 0 print("No")
1
2,483,295,563,552
null
72
72
h, w, m = map(int, input().split()) bord_x, bord_y = [0]*h, [0]*w hw = [] for _i in range(m): s, t = map(int, input().split()) s -= 1 t -= 1 bord_x[s] += 1 bord_y[t] += 1 hw.append([s, t]) x_max, y_max = max(bord_x), max(bord_y) cnt = 0 for i, j in hw: if bord_x[i] == x_max and bord_y[j] == y_max: cnt += 1 if cnt == bord_x.count(x_max)*bord_y.count(y_max): x_max -= 1 print(x_max+y_max)
import numpy as np h,w,m=map(int, input().split()) hw=[tuple(map(int,input().split())) for i in range(m)] H=np.zeros(h) W=np.zeros(w) for i in range(m): hi,wi=hw[i] H[hi-1]+=1 W[wi-1]+=1 mh=max(H) mw=max(W) hmax=[i for i, x in enumerate(H) if x == mh] wmax=[i for i, x in enumerate(W) if x == mw] f=0 for i in range(m): hi,wi=hw[i] if H[hi-1]==mh and W[wi-1]==mw: f+=1 if len(hmax)*len(wmax)-f<1: print(int(mh+mw-1)) else: print(int(mh+mw))
1
4,685,766,963,512
null
89
89
s, t = input(), input() print('Yes' if s == t[:-1] else 'No')
n, k = map(int, input().split()) a = list(map(int, input().split())) s = sum(a[:k]) mx = s for i in range(k, n): s += a[i] - a[i - k] mx = max(mx, s) print((mx + k) / 2)
0
null
48,302,912,871,632
147
223
a,b,c=list(map(int,input().split())) print(c,a,b)
import math r = float(input()) print("%f %f"%(math.pi*math.pow(r,2),2*math.pi*r))
0
null
19,310,846,191,420
178
46
h,w=map(int,input().split()) if h==1 or w==1: print(1) exit() w-=1 even=int(w/2)+1 odd=int((w+1)/2) if h%2==0: print( (even+odd)*h//2 ) else: print( (even+odd)*(h-1)//2 + even )
n,p=map(int,input().split()) s=input() ans=0 if p==2: for i in range(n): if int(s[i])%2==0: ans+=i+1 print(ans) elif p==5: for i in range(n): if int(s[i])%5==0: ans+=i+1 print(ans) else: s=s[::-1] accum=[0]*n d=dict() for i in range(n): accum[i]=int(s[i])*pow(10,i,p)%p for i in range(n-1): accum[i+1]+=accum[i] accum[i+1]%=p accum[-1]%=p #print(accum) for i in range(n): if accum[i] not in d: if accum[i]==0: ans+=1 d[accum[i]]=1 else: if accum[i]==0: ans+=1 ans+=d[accum[i]] d[accum[i]]+=1 #print(d) print(ans)
0
null
54,452,046,035,556
196
205
import math a,b,H,M=map(int,input().split()) theta_a = math.pi/6 * (H+M/60) theta_b = math.pi*2*M/60 ans = math.sqrt((b*math.cos(theta_b) - a*math.cos(theta_a))**2 + (b*math.sin(theta_b) - a*math.sin(theta_a))**2) print(ans)
print('ABC' if input()[1] == 'R' else 'ARC')
0
null
22,250,280,280,440
144
153
n, a, b = map(int, input().split()) div, mod = divmod(n, a + b) print(div * a + min(a, mod))
s = input() d = [[0]*2 for _ in range(len(s)+1)] count_r = 0 count_l = 0 ans = 0 for i in range(len(s)): if s[i] == "<": d[i+1][0] = d[i][0]+1 else: d[i+1][0] = 0 for i in range(len(s)-1, -1, -1): if s[i] == ">": d[i][1] = d[i+1][1]+1 else: d[i][1] = 0 for i in range(len(s)+1): ans += max(d[i]) print(ans)
0
null
105,875,262,668,560
202
285
# import sys # import math #sqrt,gcd,pi # import decimal # import queue # queue # import bisect # import heapq # priolity-queue # import time # from itertools import product,permutations,\ # combinations,combinations_with_replacement # 重複あり順列、順列、組み合わせ、重複あり組み合わせ # import collections # deque # from operator import itemgetter,mul # from fractions import Fraction # from functools import reduce mod = int(1e9+7) # mod = 998244353 INF = 1<<50 def readInt(): return list(map(int,input().split())) def main(): n,k = readInt() r,s,p = readInt() rsp = {"s":r,"p":s,"r":p} t = input() ans = 0 u = [] for i in range(n): if i<k: ans += rsp[t[i]] u.append(t[i]) else: if t[i]!=u[i-k]: ans += rsp[t[i]] u.append(t[i]) else: u.append("f") print(ans) return if __name__=='__main__': main()
def grade(m, f, r): if m == -1 or f == -1: return 'F' s = m + f if s >= 80: return 'A' elif s >= 65: return 'B' elif s >= 50: return 'C' elif s < 30: return 'F' elif r >= 50: return 'C' else: return 'D' while True: m, f, r = map(int, input().split()) if m == f == r == -1: break print(grade(m, f, r))
0
null
54,171,289,851,874
251
57
for i in range(9): i+=1 for n in range(9): n+=1 print str(i)+"x"+str(n)+"="+str(i*n)
N, K = map(int, input().split()) A = list(map(int, input().split())) ans = [] for i in range(K, N): ans.append(['No', 'Yes'][A[i] > A[i - K]]) print('\n'.join(ans))
0
null
3,536,819,954,122
1
102
import math A, B, N = [int(x) for x in input().split()] count = min(B-1, N) a = math.floor(float(A*count)/B) - A * math.floor(float(count)/B) print(a)
N = int(input()) S = input() if N % 2 != 0: print("No") exit() x = int(len(S) / 2) y = S[0:x] z = S[x:len(S)] if y == z: print("Yes") else: print("No")
0
null
87,305,218,529,860
161
279
n = int(input()) score = [0,0] for _ in range(n): tc, hc = input().split() if tc == hc: score[0] += 1 score[1] += 1 elif tc > hc: score[0] += 3 else: score[1] += 3 print(*score)
n=int(input()) data=[[int(num)for num in input().split(' ')] for i in range(n)] state=[[[0 for i in range(10)]for j in range(3)]for k in range(4)] for datum in data: state[datum[0]-1][datum[1]-1][datum[2]-1]+=datum[3] for i in range(4): for j in range(3): s="" for k in range(10): s+=' '+str(state[i][j][k]) print(s) if i!=3: print("####################")
0
null
1,569,680,295,868
67
55
import sys N = int(input()) for i in range(1,10): if N % i == 0 and N // i < 10: print('Yes') sys.exit() print('No')
N = int(input()) for i in range(1, 10): if N % i == 0 and 1 <= N / i <= 9: print('Yes') exit() print('No')
1
159,219,335,207,058
null
287
287
n=int(input()) ans="No" for i in range(10): for j in range(10): if n==i*j: ans="Yes" print(ans)
N = int(input()) for i in range(1,10): for j in range(1,10): if i * j == N: print("Yes") exit(0) else: print("No")
1
160,243,423,432,418
null
287
287
''' 参考 https://drken1215.hatenablog.com/entry/2020/06/21/224900 ''' N = int(input()) A = list(map(int, input().split())) INF = 10 ** 5 cnt = [0] * (INF+1) Q = int(input()) BC = [] for _ in range(Q): BC.append(list(map(int, input().split()))) for a in A: cnt[a] += 1 total = sum(A) for b, c in BC: total += (c-b) * cnt[b] cnt[c] += cnt[b] cnt[b] = 0 print(total)
def solve(): N = int(input()) A = [int(i) for i in input().split()] counter = {} total = 0 for num in A: total += num counter[num] = counter.get(num, 0) + 1 Q = int(input()) for i in range(Q): B,C = [int(i) for i in input().split()] if B in counter: B_cnt = counter[B] counter[C] = counter.get(C, 0) + B_cnt total += (C-B) * B_cnt counter[B] = 0 print(total) if __name__ == "__main__": solve()
1
12,238,075,220,272
null
122
122
n = int(input()) odd = 0 even = 0 for i in range(1,n+1): if i % 2 == 0: even += 1 else: odd += 1 print(odd/n)
import math n = int(input()) mod = 1000000007 ab = [list(map(int,input().split())) for _ in range(n)] dic = {} z = 0 nz,zn = 0,0 for a,b in ab: if a == 0 and b == 0: z += 1 continue elif a == 0: zn += 1 continue elif b == 0: nz += 1 if a< 0: a = -a b = -b g = math.gcd(a,b) tp = (a//g,b//g) if tp not in dic: dic[tp] = 1 else: dic[tp] += 1 ans = 1 nn = n - z - zn - nz for tp,v in dic.items(): if v == 0: continue vt = (tp[1],-1*tp[0]) if vt in dic: w = dic[vt] #print(tp) e = pow(2,v,mod) + pow(2,w,mod) - 1 ans *= e ans %= mod nn -= v + w dic[tp] = 0 dic[vt] = 0 ans *= pow(2,nn,mod) if zn == 0: ans *= pow(2,nz,mod) elif nz == 0: ans *= pow(2,zn,mod) else: ans *= pow(2,nz,mod) + pow(2,zn,mod) - 1 ans += z - 1 print(ans%mod) #print(dic)
0
null
98,655,861,064,110
297
146
N, K = map(int,input().split()) friend = list(map(int,input().split())) clear = [] for i in friend: if i >= K: clear.append(i) print(len(clear))
s = input()[::-1] size = len(s) s += "4" ans = 0 bef = 0 for i in range(size): v1 = int(s[i]) v2 = int(s[i+1]) if v1+bef>=6 or (v1+bef>=5 and v2>=5): ans += 10-(v1+bef) bef = 1 else: ans += (v1+bef) bef = 0 ans += bef print(ans)
0
null
124,498,080,206,010
298
219
num = map(int, raw_input().split(' ')) print num[0] * num[1], 2 * (num[0] + num[1])
i = input() si = i.split() a = int(si[0]) b = int(si[1]) print(a*b, a*2+b*2)
1
311,878,455,860
null
36
36
import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) N, u, v = map(int, input().split()) edge = [[] for _ in range(N + 1)] for _ in range(N - 1): a, b = map(int, input().split()) edge[a].append(b) edge[b].append(a) def calc_dist(s): dist = [-1] * (N + 1) dist[s] = 0 node = [s] while node: s = node.pop() d = dist[s] for t in edge[s]: if dist[t] != -1: continue dist[t] = d + 1 node.append(t) return dist[1:] taka = calc_dist(u) aoki = calc_dist(v) ans = 0 for x, y in zip(taka, aoki): if x <= y: ans = max(ans, y - 1) print(ans)
import sys sys.setrecursionlimit(10**9) f=lambda:map(int,sys.stdin.readline().split()) n,st,sa=f() g=[set() for _ in range(n)] for _ in range(n-1): a,b=f() g[a-1].add(b-1) g[b-1].add(a-1) def dfs(l,v,p=-1,d=0): l[v]=d for c in g[v]: if c!=p: dfs(l,c,v,d+1) lt=[0]*n dfs(lt,st-1) la=[0]*n dfs(la,sa-1) print(max(la[i] for i in range(n) if lt[i]<la[i])-1)
1
117,686,890,859,762
null
259
259
MOD = 10 ** 9 + 7 K = int(input()) S = input() l = len(S) fac = [1] * (K + l + 1) for i in range(1, K + l + 1): fac[i] = (fac[i - 1] * i) % MOD p25 = [1] * (K + 1) p26 = [1] * (K + 1) for i in range(1, K + 1): p25[i] = (p25[i - 1] * 25) % MOD p26[i] = (p26[i - 1] * 26) % MOD ans = 0 for en in range(l - 1, l + K): t = (fac[en] * pow(fac[en - l + 1], MOD - 2, MOD) * pow(fac[l - 1], MOD - 2, MOD)) % MOD t = (t * p25[en - l + 1]) % MOD t = (t * p26[l + K - 1 - en]) % MOD ans = (ans + t) % MOD print(ans)
def cmb(n,r,mod): if r<0 or r>n: return 0 r=min(r,n-r) return g1[n]*g2[r]*g2[n-r]%mod k=int(input()) s=list(input()) n=len(s) mod=10**9+7 g1=[1,1] g2=[1,1] inverse=[0,1] for i in range(2,2*10**6+1): g1.append((g1[-1]*i)%mod) inverse.append((-inverse[mod%i]*(mod//i))%mod) g2.append((g2[-1]*inverse[-1])%mod) pow25=[1] for i in range(n+k+1): pow25.append((pow25[-1]*25)%mod) pow26=[1] for i in range(n+k+1): pow26.append((pow26[-1]*26)%mod) ans=0 for i in range(n,n+k+1): ans+=cmb(i-1,n-1,mod)*pow25[i-n]*pow26[n+k-i] ans%=mod print(ans)
1
12,742,497,817,278
null
124
124