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
na, nb, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) min_a = min_b = 10**9 for i in range(na): min_a = min(min_a, a[i]) for i in range(nb): min_b = min(min_b, b[i]) ans = min_a + min_b for i in range(m): x, y, c = map(int, input().split()) x -= 1 y -= 1 ans = min(ans, a[x] + b[y] - c) print(ans)
A, B, M = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) answer = [] for i in range(M): x, y, c = map(int, input().split()) answer.append(a[x-1]+b[y-1]-c) print(min(min(answer), min(a)+min(b)))
1
53,854,633,548,258
null
200
200
S=list(input()) while len(S)>1: if S[0] == 'h' and S[1] == 'i': S.remove('h') S.remove('i') else: break if len(S) == 0: print('Yes') else: print('No')
s=input() cnt=s.count("hi") if cnt*2==len(s): print("Yes") else: print("No")
1
53,140,831,903,520
null
199
199
import itertools N=int(input()) P=tuple(map(int,input().split())) Q=tuple(map(int,input().split())) prm = list(itertools.permutations(range(1,N+1))) i = 0 for t in prm: i += 1 if t == P: a = i if t == Q: b = i print(abs(a-b))
""" 何回足されるかで考えればよい。 真っ二つに切っていく。 各項は必ずM未満。 M項以内に必ずループが現れる。 """ N,X,M = map(int,input().split()) memo1 = set() memo2 = [] ans = 0 a = X flag = True rest = N while rest > 0: if a in memo1 and flag: flag = False for i in range(len(memo2)): if memo2[i] == a: loopStart = i setSum = 0 for i in range(loopStart,len(memo2)): setSum += memo2[i]**2 % M loopStep = len(memo2)-loopStart loopCount = rest // loopStep ans += loopCount*setSum rest -= loopCount*loopStep else: memo1.add(a) memo2.append(a) ans += a a = a**2%M rest -= 1 print(ans)
0
null
51,671,798,284,890
246
75
x = input() print(x ** 3)
a=int(input()) b=a//100 b*=5 c=a%100 print("1" if b>=c else "0")
0
null
63,583,881,910,692
35
266
from collections import defaultdict money = defaultdict(int) for i, m in enumerate([300000, 200000, 100000]): money[i] = m X, Y = map(int, input().split()) X -= 1; Y -= 1 ans = money[X] + money[Y] if X + Y: print(ans) else: print(ans + 400000)
X,Y=map(int,input().split()) count=0 if X==3: count = count+100000 elif X==2: count = count+200000 elif X==1: count = count+300000 else: count = count if Y==3: count = count+100000 elif Y==2: count = count+200000 elif Y==1: count = count+300000 else: count = count if X==1 and Y==1: count = count+400000 print(count)
1
140,363,854,239,234
null
275
275
import math def kochCurve(d, p1, p2): if d <= 0: return s = [(2.0*p1[0]+1.0*p2[0])/3.0, (2.0*p1[1]+1.0*p2[1])/3.0] t = [(1.0*p1[0]+2.0*p2[0])/3.0, (1.0*p1[1]+2.0*p2[1])/3.0] u = [(t[0]-s[0])*math.cos(math.radians(60))-(t[1]-s[1])*math.sin(math.radians(60))+s[0], (t[0]-s[0])*math.sin(math.radians(60))+(t[1]-s[1])*math.cos(math.radians(60))+s[1]] kochCurve(d-1, p1, s) print(s[0], s[1]) kochCurve(d-1, s, u) print(u[0], u[1]) kochCurve(d-1, u, t) print(t[0], t[1]) kochCurve(d-1, t, p2) n = int(input()) s = [0.00000000, 0.00000000] e = [100.00000000, 0.00000000] print(s[0],s[1]) if n != 0: kochCurve(n,s,e) print(e[0],e[1])
import sys import math import copy from heapq import heappush, heappop, heapify from functools import cmp_to_key from bisect import bisect_left, bisect_right from collections import defaultdict, deque, Counter # sys.setrecursionlimit(1000000) # input aliases input = sys.stdin.readline getS = lambda: input().strip() getN = lambda: int(input()) getList = lambda: list(map(int, input().split())) getZList = lambda: [int(x) - 1 for x in input().split()] INF = float("inf") MOD = 10**9 + 7 divide = lambda x: pow(x, MOD-2, MOD) def zaatsu(nums): ref = list(set(copy.copy(nums))) ref.sort() dic = dict() for i, num in enumerate(ref): dic[num] = i return [dic[num] for num in nums] def solve(): n, d, a = getList() li = [] for i in range(n): li.append(getList()) li.sort() ichi = [x[0] for x in li] imos = [0] * n cur = 0 ans = 0 for i, (x, h) in enumerate(li): cur -= imos[i] hp = h - cur * a if hp <= 0: continue thr = hp // a if hp % a != 0: thr += 1 ans += thr cur += thr owari = bisect_right(ichi, x + 2 * d) if owari != n: imos[owari] += thr print(ans) def main(): n = getN() for _ in range(n): solve() return if __name__ == "__main__": # main() solve()
0
null
41,325,342,843,712
27
230
#!/usr/bin/env python3 import sys input = lambda: sys.stdin.readline().strip() h, w = [int(x) for x in input().split()] g = [input() for _ in range(h)] ans = 0 for si in range(h): for sj in range(w): if g[si][sj] != '#': d = [[-1 for j in range(w)] for i in range(h)] d[si][sj] = 0 q = [(si, sj)] for i, j in q: ans = max(ans, d[i][j]) for di, dj in [(-1, 0), (1, 0), (0, -1), (0, 1)]: ni, nj = i + di, j + dj if 0 <= ni < h and 0 <= nj < w and g[ni][nj] != '#' and d[ni][nj] == -1: d[ni][nj] = d[i][j] + 1 q.append((ni, nj)) print(ans)
from collections import deque def main(): H,W=map(int,input().split()) S=[] for i in range(H): s=input() S.append(s) G=[] for i in range(H): for j in range(W): tmp=[] if S[i][j]=="#": G.append(tmp) continue if i-1>=0: if S[i-1][j]==".": tmp.append((i-1)*W+j) if i+1<=H-1: if S[i+1][j]==".": tmp.append((i+1)*W+j) if j-1>=0: if S[i][j-1]==".": tmp.append(i*W+j-1) if j+1<=W-1: if S[i][j+1]==".": tmp.append(i*W+j+1) G.append(tmp) res=0 for start in range(H*W): dist = 0 v = [-1 for _ in range(H * W)] que=deque([]) que.append(start) v[start]=dist while len(que)>0: next_index=que.popleft() next=G[next_index] for i in next: if v[i]==-1: que.append(i) v[i]=v[next_index]+1 if max(v)>=res: res=max(v) print(res) if __name__=="__main__": main()
1
94,310,907,844,352
null
241
241
def main(): W,H,x,y,r=map(int,input().split()) if x-r>=0 and y-r>=0 and W>=x+r and H>=y+r: print('Yes') else: print('No') if __name__=='__main__': main()
from math import floor def main(): A, B, N = map(int, input().split()) if N >= B-1: x = B - 1 else: x = N print(floor((A*x)/B) - A*floor(x/B)) if __name__ == '__main__': main()
0
null
14,240,413,090,448
41
161
N = int(input()) S = input() print('Yes' if S[:len(S)//2] == S[len(S)//2:] else 'No')
while 1: x, y = map(int, input().split()) if x == 0 and y == 0: break elif x < y: print("%d %d" % (x, y)) else: print("%d %d" % (y, x))
0
null
73,860,266,320,928
279
43
line = "" while line != "0": line = input() x = 0 for i in range(len(line)): x += int(line[i]) if x != 0: print(x)
while True: s = input() if len(s) == 1 and s[0] == '0': break total = 0 for i in range(0,len(s)): total += int(s[i]) print("%d" % total)
1
1,567,671,971,560
null
62
62
n=int(input()) j,k=map(int,input().split()) f=1 if k-j>=n: print('OK') f=0 else: for i in range(j,k+1): if i%n==0: print('OK') f=0 break if f==1: print("NG")
n = int(input()) s = input() if n == 1: print("No") exit() if s[:int(n / 2)] == s[int(n / 2):]: print("Yes") else: print("No")
0
null
86,413,737,552,700
158
279
n,k = map(int,input().split()) ke = 1 while(True): if(n<k): print(ke) break else: n = n//k ke += 1
N, K = map(int, input().split()) def base_10_to_n(X, n): if (int(X / n)): return base_10_to_n(int(X / n), n) + str(X % n) return str(X % n) ans = base_10_to_n(N, K) print(len(str(ans)))
1
63,954,537,154,310
null
212
212
n = int(input()) a = n // 100 b = n % 100 if 5 * a >= b : print(1) else : print(0)
n,x,m=map(int,input().split()) ans=x count=1 table=[0]*m table[x]=1 r=[0,x] #一般項 f=1 for i in range(n-1): x=pow(x,2,m) ans+=x count+=1 if table[x]: f=0 break r.append(x) table[x]=count if f or table[0]: print(ans) exit() ans=0 ''' table[x]項目とcount項目が同じ loop前の項+loopの項*loop数+足りない分 ''' ans=sum(r[:table[x]]) loop=(n-table[x]+1)//(count-table[x]) ans+=sum(r[table[x]:])*loop nokori=(n-table[x]+1)%(count-table[x]) for i in range(nokori): ans+=r[table[x]+i] print(ans)
0
null
64,893,434,960,850
266
75
A,B = map(int,input().split()) if A <= 2*B: x = 0 else: x = A - 2*B print(x)
x1,x2,x3,x4,x5,x6 = map(int,(input().split())) t = input() x=x1 L=[x1,x2,x3,x4,x5,x6] n= len(t) T=[] M=[] for i in range(n): T.append(t[:1]) t=t[1:] for i in T: if i is "S": L = [L[4],L[0],L[2],L[3],L[5],L[1]] elif i is "E": L = [L[3], L[1], L[0], L[5], L[4], L[2]] elif i is "N": L = [L[1], L[5], L[2], L[3], L[0], L[4]] else: L = [L[2], L[1], L[5], L[0], L[4], L[3]] print(L[0])
0
null
83,772,198,536,442
291
33
import sys, bisect, math, itertools, string, queue, copy # import numpy as np # import scipy # from collections import Counter,defaultdict,deque # from itertools import permutations, combinations # from heapq import heappop, heappush # # input = sys.stdin.readline # sys.setrecursionlimit(10**8) # mod = 10**9+7 def inp(): return int(input()) def inpm(): return map(int,input().split()) def inpl(): return list(map(int, input().split())) def inpls(): return list(input().split()) def inplm(n): return list(int(input()) for _ in range(n)) def inplL(n): return [list(input()) for _ in range(n)] def inplT(n): return [tuple(input()) for _ in range(n)] def inpll(n): return [list(map(int, input().split())) for _ in range(n)] def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)]) n = inp() S = input() ans = 0 for a,b,c in itertools.product(map(str,range(10)),repeat=3): aa = False bb = False for s in S: if aa == False and s == a: aa = True continue if bb == False and aa == True and s == b: bb = True continue if aa == True and bb == True and s == c: ans += 1 break print(ans)
n = int(input()) s, t = list(input().split(' ')) print(''.join([a+b for a,b in list(zip(s, t))]))
0
null
119,793,663,863,552
267
255
a,b = input().split() aa,bb = int(a),int(b) print(a * bb if a * bb < b * aa else b * aa)
#from collections import defaultdict, deque #import itertools #import numpy as np #import re import bisect def main(): N = int(input()) SS = [] for _ in range(N): SS.append(input()) S = [] for s in SS: while '()' in s: s = s.replace('()', '') S.append(s) #print(S) S = [s for s in S if s != ''] sum_op = 0 sum_cl = 0 S_both_op = [] S_both_cl = [] for s in S: if not ')' in s: sum_op += len(s) elif not '(' in s: sum_cl += len(s) else: pos = s.find('(') if pos <= len(s) - pos: S_both_op.append((pos, len(s)-pos)) #closeのほうが少ない、'))((('など -> (2,3) else: S_both_cl.append((pos, len(s)-pos)) #closeのほうが多い、')))(('など -> (3,2) # S_both_opは、耐えられる中でより伸ばす順にしたほうがいい? #S_both_op.sort(key=lambda x: (x[0], x[0]-x[1])) #closeの数が小さい順にsortかつclose-openが小さい=伸ばす側にsort #S_both_cl.sort(key=lambda x: (x[0], x[0]-x[1])) #これもcloseの数が小さい順にsortかつclose-openが小さい=あまり縮まない順にsort S_both_op.sort(key=lambda x: x[0]) S_both_cl.sort(key=lambda x: -x[1]) for p in S_both_op: sum_op -= p[0] if(sum_op < 0 ): print('No') exit() sum_op += p[1] for p in S_both_cl: sum_op -= p[0] if(sum_op < 0 ): print('No') exit() sum_op += p[1] if sum_op == sum_cl: print('Yes') else: print('No') if __name__ == "__main__": main()
0
null
53,862,774,348,572
232
152
s=input() n=len(s) x=s[0:(n-1)//2] y=s[(n+3)//2-1:n] if x==x[::-1] and y==y[::-1] and s==s[::-1]: print('Yes') else: print('No')
s = input() n = len(s) print('Yes' if s==s[::-1] and s[:(n-1)//2]==s[:(n-1)//2][::-1] and s[(n+1)//2:] == s[(n+1)//2:][::-1] else 'No')
1
46,498,355,427,074
null
190
190
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()
N=int(input()) A,B=[],[] for i in range(N): a,b=map(int,input().split()) A.append(a) B.append(b) A.sort() B.sort() I=~-N//2 print(B[I]-A[I]+1 + (B[I+1]-A[I+1] if N%2==0 else 0))
0
null
8,742,390,853,052
27
137
N = int(input()) A = list(map(int, input().split())) B = [] temp = 0 for i in range(N): if A[i] != temp: B.append(A[i]) temp = A[i] N = len(B) A = [float("inf")] + B + [0] money, stock = 1000, 0 for i in range(1, N + 1): if A[i - 1] > A[i] and A[i] < A[i + 1]: x = money // A[i] money -= A[i] * x; stock += x if A[i - 1] < A[i] and A[i] > A[i + 1]: x = stock money += A[i] * x; stock -= x print(money)
n,*A=map(int,open(0).read().split());m=1000 for x,y in zip(A,A[1:]): if x<y:m=m//x*y+m%x print(m)
1
7,319,679,228,358
null
103
103
h = int(input()) count = 0 ans = 0 while h > 0: h //= 2 count += 1 for i in range(count): ans = ans*2 + 1 print(ans)
import sys x = sys.stdin.readline() x3 = int(x) ** 3 print x3
0
null
40,265,070,176,900
228
35
from collections import Counter def solve(): N = int(input()) A = list(map(int, input().split())) c = Counter(A) Q = int(input()) ans = [0]*Q total = sum(A) for i in range(Q): x,y = map(int, input().split()) total += c[x]*(y-x) c[y] += c[x] c[x] = 0 ans[i] = total return ans print(*solve(),sep='\n')
n = int(input()) a = list(map(int, input().split())) q = int(input()) bc = [list(map(int, input().split())) for i in range(q)] l = [0] * 100000 suml = 0 for i in a: l[i-1] += 1 suml += i for i in bc: suml += l[i[0]-1] * (i[1] - i[0]) l[i[1]-1] += l[i[0]-1] l[i[0]-1] = 0 print(suml)
1
12,305,262,458,592
null
122
122
a, b, n = map(int, input().split()) c = min(b - 1, n) #logging.debug(c) print(int(((a * c) / b) // 1 - (a * ((c / b) // 1))))
import math def main(): h,w = map(int, input().split()) if h == 1 or w == 1: print(1) else: print(math.ceil(h*w/2)) if __name__ == "__main__": main()
0
null
39,569,260,138,030
161
196
import sys # input = sys.stdin.readline input = lambda: sys.stdin.readline().rstrip() n = int(input()) s = [input() for _ in range(n)] def bracket(x): # f: final sum of brackets '(':+1, ')': -1 # m: min value of f f = m = 0 for i in range(len(x)): if x[i] == '(': f += 1 else: f -= 1 m = min(m, f) # m <= 0 return f, m def func(l): # l = [(f, m)] l.sort(key=lambda x: -x[1]) v = 0 for fi, mi in l: if v + mi >= 0: v += fi else: return -1 return v l1 = [] l2 = [] for i in range(n): fi, mi = bracket(s[i]) if fi >= 0: l1.append((fi, mi)) else: l2.append((-fi, mi - fi)) v1 = func(l1) v2 = func(l2) if v1 == -1 or v2 == -1: ans = 'No' else: ans = 'Yes' if v1 == v2 else 'No' print(ans)
#k = int(input()) #s = input() #a, b = map(int, input().split()) #s, t = map(str, input().split()) #l = list(map(int, input().split())) a = int(input()) b = int(input()) if (a == 1 and b == 2): print(3) elif(a == 1 and b == 3): print(2) elif (a == 2 and b == 1): print(3) elif (a == 2 and b == 3): print(1) elif (a == 3 and b == 1): print(2) elif (a == 3 and b == 2): print(1)
0
null
67,464,877,815,178
152
254
from collections import deque N = int(input()) edge = [[] for _ in range(N+1)] for i in range(N): A = list(map(int, input().split())) edge[A[0]] = A[2:] ans = [-1]*N ans[0] = 0 d = deque([[1,0]]) while len(d)>0: v,dist = d.popleft() for w in edge[v]: if ans[w-1]==-1: ans[w-1]=dist+1 d.append([w,dist+1]) for i in range(N): print(i+1,ans[i])
import queue n = int(input()) graph = {} for _ in range(n): i = list(map(int,input().split())) graph[i[0]] = i[2:] dist = [-1 for i in range(n)] todo = queue.Queue() seen = set() dist[0] = 0 todo.put(1) while (not todo.empty()): now = todo.get() for nx in graph[now]: if (dist[nx-1] != -1): continue dist[nx-1] = dist[now-1] + 1 todo.put(nx) for i in range(n): print(i+1, dist[i])
1
4,274,068,288
null
9
9
N = input() money = 100000 for i in range(N): money = int(money *1.05) if money % 1000 != 0: money = (money // 1000 + 1) * 1000 print money
k, n =map(int,input().split()) a = list(map(int,input().split())) longest = k - a[-1] + a [0] for i in range(len(a)-1): longest = max(longest,a[i+1]-a[i]) print(k-longest)
0
null
21,760,290,883,108
6
186
a=map(int,raw_input().split()) a.sort() while a[1]%a[0]!=0: a[0],a[1]=a[1]%a[0],a[0] print(a[0])
input_X = int(input()) result_500 = input_X // 500 result_500ureshi = result_500 * 1000 result_5ureshi = (input_X - result_500 * 500) // 5 * 5 result = int(result_500ureshi + result_5ureshi) print(result)
0
null
21,205,261,919,140
11
185
#!usr/bin/env python3 from collections import defaultdict, deque, Counter from heapq import heappush, heappop from itertools import permutations import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS(): return [list(x) for x in sys.stdin.readline().split()] def S(): res = list(sys.stdin.readline()) if res[-1] == "\n": return res[:-1] return res def IR(n): return [I() for i in range(n)] def LIR(n): return [LI() for i in range(n)] def SR(n): return [S() for i in range(n)] def LSR(n): return [LS() for i in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def solve(): a, b, c = LI() k = I() for i in range(k): if a >= b: b *= 2 elif b >= c: c *= 2 if a < b < c: print('Yes') else: print('No') return # Solve if __name__ == "__main__": solve()
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..) import sys def main(N, T, AB): dpL = [[0] * (T + 1) for _ in range(N + 2)] for i in range(1, N + 1): a, b = AB[i - 1] for t in range(T): dpL[i][t] = dpL[i - 1][t] if t >= a: dpL[i][t] = max(dpL[i][t], dpL[i - 1][t - a] + b) dpR = [[0] * (T + 1) for _ in range(N + 2)] for i in range(N, 0, -1): a, b = AB[i - 1] for t in range(T): dpR[i][t] = dpR[i + 1][t] if t >= a: dpR[i][t] = max(dpR[i][t], dpR[i + 1][t - a] + b) ans = 0 for i in range(1, N + 1): a, b = AB[i - 1] for t in range(T): ans = max(ans, dpL[i - 1][t] + dpR[i + 1][T - 1 - t] + b) print(ans) if __name__ == '__main__': input = sys.stdin.readline N, T = map(int, input().split()) AB = [list(map(int, input().split())) for _ in range(N)] main(N, T, AB)
0
null
78,951,338,139,828
101
282
N = input() a = [input() for i in range(N)] def smax(N,a): smin = a[0] smax = -10**9 for j in range(1,N): smax = max(smax,a[j]-smin) smin = min(smin,a[j]) return smax print smax(N,a)
N = int(input()) S = input() ans = S.count("R") * S.count("G") * S.count("B") for i in range(N-2): r = S[i] for j in range(i+1,N-1): g = S[j] if r == g: continue k = 2*j - i if k >= N: continue b = S[k] if r != b and g != b: ans -= 1 print(ans)
0
null
17,974,119,706,510
13
175
import sys from heapq import heapify, heappop, heappush sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) N, U, V = lr() graph = [[] for _ in range(N+1)] # 1-indexed for _ in range(N-1): a, b = lr() graph[a].append(b) graph[b].append(a) def dijkstra(start): INF = 10 ** 15 dist = [INF] * (N+1) dist[start] = 0 que = [(0, start)] while que: d, prev = heappop(que) if dist[prev] < d: continue for next in graph[prev]: d1 = d + 1 if dist[next] > d1: dist[next] = d1 heappush(que, (d1, next)) return dist dist_U = dijkstra(U) dist_V = dijkstra(V) answer = max(v for u, v in zip(dist_U, dist_V) if v > u) - 1 print(answer) # 25
n, u, v = map(int, input().split()) u, v = u-1, v-1 edges = [[] for i in range(n)] for i in range(n-1): ai, bi = map(int, input().split()) ai, bi = ai-1, bi-1 edges[ai].append(bi) edges[bi].append(ai) depth = 0 already = [0 for i in range(n)] already[v] = 1 nodes = [v] while nodes != []: depth += 1 next_nodes = [] for node in nodes: children = edges[node] for child in children: if already[child] == 0: already[child] = depth next_nodes.append(child) nodes = next_nodes already[v] = 0 depth = 0 already_u = [0 for i in range(n)] already_u[u] = 1 nodes = [u] while nodes != []: depth += 1 next_nodes = [] for node in nodes: children = edges[node] for child in children: if already_u[child] == 0: already_u[child] = depth next_nodes.append(child) nodes = next_nodes already_u[u] = 0 maxi = 0 for i in range(n): if already_u[i] < already[i]: maxi = max(maxi, already[i]) print(maxi-1)
1
117,134,135,930,908
null
259
259
n = int(input()) data = list(map(int, input().split())) ans = [] for i in range(n): if (i % 2 == 0) and (data[i] % 2 == 1): ans.append(data[i]) print(len(ans))
n = int(input()) a = list(map(int,input().split())) count = 0 for i in range(n): if ((i + 1 )%2 )==1 and ((a[i]%2) == 1): count += 1 print(count)
1
7,729,447,482,300
null
105
105
# https://atcoder.jp/contests/abc145/tasks/abc145_d X, Y = map(int, input().split()) if (2*Y- X) % 3 or (2*X- Y) % 3: print(0) exit() x = (2*Y - X) // 3 y = (2*X - Y) // 3 if x < 0 or y < 0: print(0) exit() n = x + y r = x mod = 10**9 + 7 f = 1 for i in range(1, n + 1): f = f*i % mod fac = f f = pow(f, mod-2, mod) facinv = [f] for i in range(n, 0, -1): f = f*i % mod facinv.append(f) facinv.append(1) print(fac * facinv[r] * facinv[n - r] % mod)
N = int(input()) A = map(int, input().split()) B = [3 if i == 0 else 0 for i in range(N + 1)] MOD = 1000000007 ans = 1 for a in A: ans = ans * B[a] % MOD if ans == 0: break else: B[a] -= 1 B[a + 1] += 1 print(ans)
0
null
140,172,604,270,960
281
268
S,H,C,D = set(),set(),set(),set() W = set([1,2,3,4,5,6,7,8,9,10,11,12,13]) n = int(input()) for i in range(n): N = input().split() if N[0] == 'S': S.add(int(N[1])) elif N[0] == 'H': H.add(int(N[1])) elif N[0] == 'C': C.add(int(N[1])) elif N[0] == 'D': D.add(int(N[1])) s,h,c,d = [],[],[],[] st = W - S while st != set(): s.append(st.pop()) s.sort() ht = W - H ct = W - C dt = W - D while ht != set(): h.append(ht.pop()) h.sort() while ct != set(): c.append(ct.pop()) c.sort() while dt != set(): d.append(dt.pop()) d.sort() for i in s: print('S {0}'.format(i)) for i in h: print('H {0}'.format(i)) for i in c: print('C {0}'.format(i)) for i in d: print('D {0}'.format(i))
seed = [i for i in range(1,14)] deck = {} for s in ['S','H','C','D']: deck[s] = seed[:] n = int(input()) for i in range(n): s,v = input().split() deck[s][int(v)-1] = 0 for s in ['S','H','C','D']: for i in deck[s]: if i != 0: print(s,i)
1
1,034,601,667,840
null
54
54
MOD = 10**9 + 7 fac = [1 for k in range(200010)] inv = [1 for k in range(200010)] finv = [1 for k in range(200010)] for k in range(2,200010): fac[k] = (fac[k-1]*k)%MOD inv[k] = (MOD - inv[MOD%k] * (MOD // k))%MOD finv[k] = (finv[k - 1] * inv[k]) % MOD; def nCr(n,r): return (fac[n]*finv[r]*finv[n-r])%MOD N, K = map(int,input().split()) A = sorted(list(map(int,input().split()))) m = 0 for k in range(N-K+1): m += A[k]*nCr(N-k-1,K-1) m %= MOD A = A[::-1] M = 0 for k in range(N-K+1): M += A[k]*nCr(N-k-1,K-1) M %= MOD print(M-m if M>=m else M-m+MOD)
s = raw_input() n = int(raw_input()) for i in range(n): message = raw_input().split(" ") a, b = int(message[1]), int(message[2]) if message[0] == "print": print(s[a:b+1]) elif message[0] == "reverse": s = s[:a] + s[a:b+1][::-1] + s[b+1:] elif message[0] == "replace": s = s[:a] + message[3] + s[b+1:]
0
null
48,647,770,268,652
242
68
# encoding=utf-8 n = int(raw_input()) min = int(raw_input()) keep = int(raw_input()) diff = keep - min if keep > min: keep = min n = n - 2 for i in range(n): v = int(raw_input()) if v - keep > diff: diff = v - keep min = keep elif keep > v: keep = v print diff
a,b,c=map(int,input().split()) import math d=math.sin(math.radians(c)) print(a*b*d/2) e=math.cos(math.radians(c)) x=math.sqrt(a**2+b**2-2*a*b*e) print(a+b+x) print(2*(a*b*d/2)/a)
0
null
90,566,881,250
13
30
from collections import Counter N = int(input()) S = input() dic = Counter(S) cnt = 0 for i in range(0,N-2): for j in range(i+1,N-1): if S[i] == S[j]: continue elif 2*j - i < N: if S[i] != S[2*j-i] and S[j] != S[2*j-i]: cnt += 1 print(dic["R"]*dic["B"]*dic["G"]-cnt)
list = map(int,raw_input().split()) list.sort() print'%d %d %d' %(list[0],list[1],list[2])
0
null
18,435,248,932,660
175
40
import sys sys.setrecursionlimit(9**9) n=int(input()) T=[[] for _ in range(n)] for i in range(n-1): a,b=map(int,input().split()) T[a-1].append([b-1,i]) C=[0]*(n-1) def f(i,r): c=1 for (x,y) in T[i]: c+=(c==r) C[y]=c f(x,c) c+=1 f(0,0) print(max(C)) for c in C: print(c)
# D - Coloring Edges on Tree import sys sys.setrecursionlimit(10 ** 5) N = int(input()) G = [[] for _ in range(N)] for i in range(N - 1): a, b = map(int, input().split()) a, b = a - 1, b - 1 G[a].append((b, i)) G[b].append((a, i)) ans = [-1] * (N - 1) def dfs(key, color=-1, parent=-1): k = 1 for i in range(len(G[key])): if G[key][i][0] == parent: continue if color == k: k += 1 ans[G[key][i][1]] = k dfs(G[key][i][0], k, key) k += 1 dfs(0) print(max(ans)) for a in ans: print(a)
1
135,824,656,314,710
null
272
272
import sys def I(): return int(sys.stdin.readline().rstrip()) def IL(): return map(int,sys.stdin.readline().rstrip().split()) def solve(): m = a[-1]+1 ava = [0]*m for rep in a: ava[rep] += 1 if ava[rep]==1: for item in range(2*rep,m,rep): ava[item] += 2 print(ava.count(1)) return if __name__=='__main__': n = I() a = list(IL()) a.sort() solve()
def main(): n, m = map(int, input().split()) # nは偶数、mは奇数 # n+mから2つ選ぶ選び方は # n:m = 0:2 和は 偶数、選び方はmC2 # n:m = 1:1 和は 奇数 (今回はこれは含めない) # n:m = 2:0 和は 偶数、選び方はnC2 cnt = 0 if m >= 2: cnt += m * (m -1) // 2 if n >=2: cnt += n * (n -1) // 2 print(cnt) if __name__ == '__main__': main()
0
null
29,819,647,748,800
129
189
def allocation(): n, cars = map(int, input().split()) weight = [int(input()) for i in range(n)] left = max(weight) right = sum(weight) while left < right: mid = (left + right) // 2 if check(weight, cars, mid): right = mid else: left = mid + 1 print(left) def check(weight, cars, capacity): t = 0 c = 1 for w in weight: t += w if t > capacity: t = w c += 1 if c <= cars: return True else: return False if __name__ == '__main__': allocation()
# coding: utf-8 # 二分探索(応用) def loading(pack_list, k, q): truck = 0 idx = 0 for pack in pack_list: if pack > q: return False if truck + pack > q: idx += 1 truck = 0 truck += pack if truck > 0: idx += 1 return False if idx > k else True if __name__ == "__main__": n, k = [int(i) for i in input().split()] pack = [] for _ in range(n): pack.append(int(input())) min = 0 max = int(1E20) # min = sum(pack) // n # max = sum(pack) q = (max + min) // 2 res = loading(pack, k, q) while min + 1 != max: min, max = [min, q] if res else [q, max] q = (max + min) // 2 res = loading(pack, k, q) print(max)
1
86,828,196,708
null
24
24
s = str(input()) if s[-1]==s[-2] and s[-3]==s[-4]: print('Yes') else: print('No')
#!/usr/bin/env python3 import sys import collections as cl def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def main(): N = input() print('Yes' if N[2] == N[3] and N[4] == N[5] else 'No') main()
1
42,017,198,698,268
null
184
184
N = int(input()) A = list(map(int,input().split())) ans = 1000 for i in range(N-1): if A[i] < A[i+1]: ans += ans // A[i] * (A[i+1] - A[i]) print(ans)
N=int(input()) A=[int(a) for a in input().split()] dp=[-1 for _ in range(N)] dp[0]=1000 for i in range(1,N): tmp=dp[i-1] for j in range(i): K=dp[j]//A[j] res=dp[j]-K*A[j] tmp=max(tmp,res+A[i]*K) dp[i]=tmp print(dp[-1])
1
7,379,531,255,320
null
103
103
# coding: utf-8 ring = input() pattern = input() ring *= 2 if pattern in ring: print('Yes') else: print('No')
s = input() p = input() if (s * 2).find(p) >= 0: print("Yes") else: print("No")
1
1,742,399,332,320
null
64
64
# -*- coding: utf-8 -*- from sys import stdin class Dice: def __init__(self,dicelist): self.dice_list = dicelist def roll(self, direction): work = list(self.dice_list) if (direction == 'N'): self.dice_list[0] = work[1] self.dice_list[1] = work[5] self.dice_list[2] = work[2] self.dice_list[3] = work[3] self.dice_list[4] = work[0] self.dice_list[5] = work[4] elif (direction == 'E'): self.dice_list[0] = work[3] self.dice_list[1] = work[1] self.dice_list[2] = work[0] self.dice_list[3] = work[5] self.dice_list[4] = work[4] self.dice_list[5] = work[2] elif (direction == 'S'): self.dice_list[0] = work[4] self.dice_list[1] = work[0] self.dice_list[2] = work[2] self.dice_list[3] = work[3] self.dice_list[4] = work[5] self.dice_list[5] = work[1] elif (direction == 'W'): self.dice_list[0] = work[2] self.dice_list[1] = work[1] self.dice_list[2] = work[5] self.dice_list[3] = work[0] self.dice_list[4] = work[4] self.dice_list[5] = work[3] def getTop(self): return self.dice_list[0] dice_list = list(map(int, stdin.readline().rstrip().split())) dice = Dice(dice_list) rolls = stdin.readline().rstrip() for roll in rolls: dice.roll(roll) else: print(dice.getTop())
n=int(input()) print((n//2)+(n%2))
0
null
29,656,748,307,230
33
206
N=int(input()) S=[int(s) for s in input().split()] for i in range(N): if S[i]%2==0 and S[i]%5!=0 and S[i]%3!=0: print("DENIED") break elif i==N-1: print("APPROVED")
# ['表面', '南面', '東面', '西面', '北面', '裏面'] dice = input().split() com = [c for c in input()] rolling = { 'E': [3, 1, 0, 5, 4, 2], 'W': [2, 1, 5, 0, 4, 3], 'S': [4, 0, 2, 3, 5, 1], 'N': [1, 5, 2, 3, 0, 4] } for c in com: dice = [dice[i] for i in rolling[c]] print(dice[0])
0
null
34,755,507,565,690
217
33
s = str(input()) p = str(input()) connect = s + s if p in connect: print('Yes') else: print('No')
# -*- coding: utf-8 -*- N = int(input()) S = list() words = {} for i in range(N): s = input() S.append(s) if s in words: words[s] += 1 else: words[s] = 1 max_value = max(words.values()) max_list = list() for k,v in words.items(): if v == max_value: max_list.append(k) ans_list = sorted(max_list) for ans in ans_list: print(ans)
0
null
35,765,554,304,028
64
218
import sys sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline def main(): N, M = [int(x) for x in input().split()] ans = [[] for j in range(M)] if N % 2: for i in range(M): ans[i].append(i + 1) ans[i].append(N - i - 1) else: memo = 0 f = False for i in range(M): memo = i if (i + 1) * 4 >= N: f = True break ans[i].append(i + 1) ans[i].append(N - i - 1) if f: for j in range(memo, M): ans[j].append(j + 1) ans[j].append(N - j - 2) for a in ans: print(*a) if __name__ == '__main__': main()
n,k=map(int,input().split()) ans=[] a=1 b=n s=set() for _ in range(k): s.add(abs(a-b)) s.add(abs(n+a-b)%n) ans.append([a,b]) a+=1 b-=1 if abs(a-b) in s or abs(n+a-b)%n in s or abs(a-b)==abs(n+a-b): b-=1 for i in range(k): print(*ans[i])
1
28,627,014,135,280
null
162
162
def main(): s = input() n = int(input()) for i in range(n): cmds = input().split(' ') if 'reverse' == cmds[0]: a = int(cmds[1]) b = int(cmds[2])+1 s = s[:a]+''.join(reversed(s[a:b]))+s[b:] if 'replace' == cmds[0]: a = int(cmds[1]) b = int(cmds[2])+1 res = cmds[3] s = s[:a]+res+s[b:] if 'print' == cmds[0]: a = int(cmds[1]) b = int(cmds[2])+1 print(s[a:b]) if __name__ == '__main__': main()
import math def lcm(a, b): return int(a * b/ math.gcd(a, b)) a, b = map(int, input().split()) print(lcm(a,b))
0
null
57,467,578,687,652
68
256
from collections import Counter n = int(input()) verdicts = Counter([input() for i in range(n)]) for verdict in ["AC", "WA", "TLE", "RE"]: print(f"{verdict} x {verdicts[verdict]}")
n=int(input()) ac=0 wa=0 tle=0 re=0 for _ in range(n): s=input() if s=="AC": ac+=1 elif s=="WA": wa+=1 elif s=="TLE": tle+=1 else: re+=1 print("AC x ",ac) print("WA x ",wa) print("TLE x ",tle) print("RE x ",re)
1
8,667,227,345,958
null
109
109
while True: x,y=map(int,input().split()) if (x==0) & (y==0): break else: if x>y: print(y,x) else: print(x,y)
import sys def merge(A, left, mid, right): n1 = mid - left n2 = right - mid L = [] R = [] global count for i in range(n1): L.append(A[left + i]) for i in range(n2): R.append(A[mid + i]) L.append('INFTY') R.append('INFTY') a = 0 b = 0 for k in range(left, right): if L[a] <= R[b]: A[k] = L[a] a += 1 else: A[k] = R[b] b += 1 count += 1 def mergeSort(A, left, right): if left + 1 < right: mid = (left + right) / 2 mergeSort(A, left, mid) mergeSort(A, mid, right) count = merge(A, left, mid, right) n = sys.stdin.readline() n = int(n) count = 0 data = sys.stdin.readline() data_list = data.split(" ") for i in range(n): data_list[i] = int(data_list[i]) mergeSort(data_list, 0, n) for i in range(n): data_list[i] = str(data_list[i]) print " ".join(data_list) print count
0
null
321,522,856,766
43
26
n,k = map(int,input().split()) A = sorted(list(map(int,input().split()))) F = sorted(list(map(int,input().split())))[::-1] o = [] for a,f in zip(A,F): o.append(a*f) ok = max(o) ng = -1 while ok - ng > 1: mid = (ok+ng)//2 k1 = 0 for i in range(n): k1 += max( 0 , A[i]- mid//F[i]) if k1<= k: ok = mid else: ng = mid print(ok)
# https://atcoder.jp/contests/abc144/tasks/abc144_e # 修行を行わないときに最適なのは両方を逆順でソートしておくこと # そうしたときになるべく食べ物のコストの大きい方から修行していったほうが最適なので # greedyにKをみたすまで引いてあげる # 求めたいのは最大値! # 最小はxにできると仮定してみる? # 答えはxより小さくなる→greedyに(Ai-a)Fi<xして判定すれば良い import sys sys.setrecursionlimit(1 << 25) read = sys.stdin.readline ra = range enu = enumerate def read_ints(): return list(map(int, read().split())) N, K = read_ints() A = read_ints() F = read_ints() A.sort() # 前からFの大きい順に対処していく人になっている F.sort(reverse=True) # print(A) # print([x * y for x, y in zip(A, F)]) # ここから崩すことができるポイントを探せる def is_ok(x, K): for i in range(N): if A[i] * F[i] <= x: continue a = A[i] - (x // F[i]) # Kから使うべき個数 K -= a if K < 0: return False return K > -1 def meguru_bisect(ng, ok): ''' define is_okと 初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す ng ok は とり得る最小の値-1 とり得る最大の値+1 最大最小が逆の場合はよしなにひっくり返す ''' while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if is_ok(mid, K): ok = mid else: ng = mid return ok print(meguru_bisect(-1, 10**12 + 1))
1
164,569,273,308,070
null
290
290
n = int(input()) r = [] for i in range(n): r.append(int(input())) min = r[0] max = -10 ** 12 for j in r[1:]: if j - min > max: max = j - min if min > j: min = j print(max)
while True: x, y = [int(n) for n in input().split()] if x == 0 and y == 0: break if x < y: print("{} {}".format(x, y)) else: print("{} {}".format(y, x))
0
null
271,006,746,930
13
43
N = int(input()) n = 0 if not N%2: s = 5 N = N//2 while N>=s: n += N//s s *= 5 print(n)
import collections n = int(input()) dic = collections.defaultdict(int) for _ in range(n): s = input() dic[s] +=1 sorted_dic = sorted(dic.items(), key = lambda x:(-x[1],x[0])) val = sorted_dic[0][1] for k,v in sorted_dic: if v==val: print(k)
0
null
92,854,391,503,312
258
218
N = int(input()) X = [] L = [] for i in range(N): x, l = map(int, input().split()) X.append(x) L.append(l) # できるだけ少ないロボットを取り除いて条件を満たすようにしたい ranges = [[x - l, x + l] for x, l in zip(X, L)] ranges = sorted(ranges, key=lambda x:x[1]) ans = N for i in range(1, N): if ranges[i][0] < ranges[i - 1][1]: ranges[i][1] = ranges[i - 1][1] ans -= 1 print(ans)
n,m=map(int,input().split()) for i in range(m): print(i+1,n-i-((i>=m/2)&~n))
0
null
59,332,250,084,042
237
162
from collections import deque [N,M] = list(map(int,input().split())) AB = [] for i in range(M): AB.append(list(map(int,input().split()))) #そこから直で行けるところをまとめる ikeru = [[] for i in range(N)] for i in range(M): ikeru[AB[i][0]-1].append(AB[i][1]-1) ikeru[AB[i][1]-1].append(AB[i][0]-1) # print('ikeru:',ikeru) que = deque([]) que.append(0) # print('que ini:',que) out=[10**6]*N out[0]=0 while que: p = que.popleft() # print('p,que:',p,que) for next in ikeru[p]: # print('next,out:',next,out) if out[next]==10**6: que.append(next) out[next]=p+1 # print(out) print('Yes') for i in range(1,N): print(out[i])
import collections N, M = map(int, input().split()) ways = collections.defaultdict(set) for _ in range(M): a, b = map(int, input().split()) a -= 1 b -= 1 ways[a].add(b) ways[b].add(a) dist = [-1] * N q = collections.deque() dist[0] = True q.append(0) while q: n = q.popleft() for adjacent in ways[n]: if dist[adjacent] != -1: continue dist[adjacent] = dist[n] + 1 q.append(adjacent) if -1 in dist: print('No') else: print('Yes') for n, d in enumerate(dist): if n == 0: continue for adjacent in ways[n]: if d - 1 == dist[adjacent]: print(adjacent + 1) break
1
20,536,052,799,780
null
145
145
# #    ⋀_⋀  #   (・ω・) # ./ U ∽ U\ # │* 合 *│ # │* 格 *│ # │* 祈 *│ # │* 願 *│ # │*   *│ #  ̄ # import sys sys.setrecursionlimit(10**6) input=sys.stdin.readline from math import floor,sqrt,factorial,hypot,log,gcd #log2ないyp from heapq import heappop, heappush, heappushpop from collections import Counter,defaultdict,deque from itertools import accumulate,permutations,combinations,product,combinations_with_replacement from bisect import bisect_left,bisect_right from copy import deepcopy from random import randint def ceil(a,b): return (a+b-1)//b inf=float('inf') mod = 10**9+7 def pprint(*A): for a in A: print(*a,sep='\n') def INT_(n): return int(n)-1 def MI(): return map(int,input().split()) def MF(): return map(float, input().split()) def MI_(): return map(INT_,input().split()) def LI(): return list(MI()) def LI_(): return [int(x) - 1 for x in input().split()] def LF(): return list(MF()) def LIN(n:int): return [I() for _ in range(n)] def LLIN(n: int): return [LI() for _ in range(n)] def LLIN_(n: int): return [LI_() for _ in range(n)] def LLI(): return [list(map(int, l.split() )) for l in input()] def I(): return int(input()) def F(): return float(input()) def ST(): return input().replace('\n', '') #mint class ModInt: def __init__(self, x): self.x = x % mod def __str__(self): return str(self.x) __repr__ = __str__ def __add__(self, other): if isinstance(other, ModInt): return ModInt(self.x + other.x) else: return ModInt(self.x + other) __radd__ = __add__ def __sub__(self, other): if isinstance(other, ModInt): return ModInt(self.x - other.x) else: return ModInt(self.x - other) def __rsub__(self, other): if isinstance(other, ModInt): return ModInt(other.x - self.x) else: return ModInt(other - self.x) def __mul__(self, other): if isinstance(other, ModInt): return ModInt(self.x * other.x) else: return ModInt(self.x * other) __rmul__ = __mul__ def __truediv__(self, other): if isinstance(other, ModInt): return ModInt(self.x * pow(other.x, mod-2,mod)) else: return ModInt(self.x * pow(other, mod - 2, mod)) def __rtruediv(self, other): if isinstance(other, self): return ModInt(other * pow(self.x, mod - 2, mod)) else: return ModInt(other.x * pow(self.x, mod - 2, mod)) def __pow__(self, other): if isinstance(other, ModInt): return ModInt(pow(self.x, other.x, mod)) else: return ModInt(pow(self.x, other, mod)) def __rpow__(self, other): if isinstance(other, ModInt): return ModInt(pow(other.x, self.x, mod)) else: return ModInt(pow(other, self.x, mod)) def main(): N=I() A,B=[],[] for i in range(N): a,b = MI() A.append(a) B.append(b) both_zero_cnt = 0 num_of_group = defaultdict(int) ##既約分数にしてあげて、(分子,分母)がkeyで、負なら分子が負になる他は正 for i in range(N): a,b = A[i], B[i] if(a==b==0): both_zero_cnt+=1 continue elif(a==0): num_of_group[-inf,inf] += 1 num_of_group[inf,inf] += 0 elif(b==0): num_of_group[inf,inf] += 1 else: if(a*b<0): a,b=abs(a),abs(b) g = gcd(a,b) a//=g b//=g num_of_group[(-b,a)] += 1 num_of_group[(b,a)] += 0 else: a,b=abs(a),abs(b) g = gcd(a,b) a//=g b//=g num_of_group[(a,b)] += 1 # print(num_of_group.items()) if(both_zero_cnt==N): print(N) return ##solve ans = ModInt(1) # two_pow = [1] # for i in range(N): # two_pow.append((2*two_pow[-1])%mod) # print(two_pow,"#######") for (a,b),cnt1 in num_of_group.items(): if(a<0): continue tmp = ModInt(2)**cnt1 if (-a,b) in num_of_group: cnt2 = num_of_group[-a,b] tmp += ModInt(2)**cnt2 tmp-=1 if(tmp): ans *= tmp ans -= 1 ##全部選ばない ans += both_zero_cnt print(ans) if __name__ == '__main__': main()
import sys input = sys.stdin.readline import math MOD = 10**9+7 N = int(input()) F = [] zero_v = 0 inf = 0 zero = 0 for _ in range(N): x,y = map(int,input().split()) if x==0 and y==0: zero_v += 1 elif x==0: inf += 1 elif y==0: zero += 1 else: G = math.gcd(abs(x),abs(y)) F.append((x//G,y//G)) all_keys = set() for x,y in F: if x*y >0: if x>0: all_keys.add((x,y)) else: all_keys.add((-x,-y)) x,y = -y,x if x*y >0: if x>0: all_keys.add((x,y)) else: all_keys.add((-x,-y)) all_dic = {k:[0,0] for k in all_keys} for x,y in F: if x*y > 0: if x>0: all_dic[(x,y)][0] += 1 else: all_dic[(-x,-y)][0] += 1 else: if x>0: all_dic[(-y,x)][1] += 1 else: all_dic[(y,-x)][1] += 1 ans = (pow(2,inf,MOD)) + (pow(2,zero,MOD))-1 ans %= MOD for k in all_keys: P,N = all_dic[k] ans *= (pow(2,P,MOD)) + (pow(2,N,MOD))-1 ans %= MOD ans += zero_v-1 print(ans%MOD)
1
21,048,677,302,102
null
146
146
import sys input = sys.stdin.readline H,N = map(int,input().split()) spells = [list(map(int,input().split())) for i in range(N)] INF = 10**10 dp = [INF]*(H+1) dp[0] = 0 for use in spells: damage = use[0] mp = use[1] for i in range(1,H+1): dp[i] = min(dp[max(0,i-damage)] + mp, dp[i]) print(dp[-1])
n = int(input()) R = [] for i in range(n): R.append(int(input())) # R???i???????????§???????°???????i?????????????´???¨???????????????list mins = [R[0]] for i in range(1, n): mins.append(min(R[i], mins[i-1])) # ???????????????j????????????????????\??????????°??????¨??????????±?????????????????????§???????±???????????????? mx = - 10 ** 12 for j in range(1, n): mx = max(mx, R[j] - mins[j-1]) print(mx)
0
null
40,628,876,401,612
229
13
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Allocation ????????????????????? wi(i=0,1,...n???1) ??? n ?????????????????? ????????????????????¢???????????????????????????????????? ????????????????????? k ??°????????????????????????????????? ???????????????????????£?¶??????? 0 ?????\??????????????????????????¨?????§??????????????? ???????????????????????????????????????????????§????????? P ????¶???????????????????????????? ?????§????????? P ?????????????????????????????§??±?????§?????? n???k???wi ???????????????????????§???????????????????????????????????????????????? ?????§????????? P ???????°????????±???????????????°???????????????????????????????????? """ import sys # ??????????????\???????????? def kenzan(P, w, n, k): # print("P:{} kosu:{} track:{}".format(P,n,k)) t = 1 # ???????????? s = 0 # ????????? st = 0 for i in range(n): x = s + w[i] # print("max:{} nimotu[{}]:{} + sekisai:{} = {} track:{}".format(P,i,w[i],s,x,t)) if x > P: # ???????????? t += 1 st += s s = w[i] # print("next track:{} sekisai:{}".format(t,s)) if t > k: # ??°??°???????????? # print("\ttrack:{}/{} P:{} sekisai:{}".format(t,k,P,st)) return st else: s = x # print("\ttrack:{}/{} P:{} sekisai:{}".format(t,k,P,st)) return 0 def main(): """ ????????? """ n,k = list(map(int,input().split())) istr = sys.stdin.read() wi = list(map(int,istr.splitlines())) # ?????§?????¨???????????¨????°????????±??????? P = 0 total = 0 min = 100000 for w in wi: if P < w: P = w if min > w: min = w total += w na = int(total / n) # ????????????????????? if total % n > 0: na += 1 ka = int(total / k) # ??????????????????????????? if total % k > 0: ka += 1 # ?????? P (??????????????§??????????????????????????????????±????????????? # print("kosu:{} MAX:{} MIN:{} na:{} ka:{} total:{}".format(n, P, min, na, ka, total)) if P < na: P = na if P < ka: P = ka z = 0 while P <= total: st = kenzan(P, wi, n, k) # print("??????????????°:{} ??????????????°??°:{} ?????????????????§??????:{} ????????????????????????:{} ??????????????????:{} ??????:{}".format(n, k, P, total, st,z)) if st == 0: a = P - z b = P break z = int((total-st)/k) if z < 1: z = 1 P += z while b - a > 0: x = int((b - a) / 2) if x < 1: a = b P = x + a st = kenzan(P, wi, n, k) # print("P:{} MAX:{} MIN:{} sekisai:{}".format(P, b, a, st)) if st == 0: b = P else: a = P print(P) if __name__ == '__main__': main()
import collections N = int(input()) A = list(map(int, input().split())) c = collections.Counter(A) ans = 0 for i in c: ans+=c[i]*(c[i]-1)//2 for i in range(N): print(ans-(c[A[i]]-1))
0
null
23,908,305,858,480
24
192
def selectionSort(A, N): # N個の要素を含む0-オリジンの配列A A = list(map(int, A.split(" "))) change_count = 0 for i in range(N): minj = i for j in range(i,N): if A[j] < A[minj]: minj = j if i != minj: #A[i] と A[minj] を交換 tmp = A[i] A[i] = A[minj] A[minj] = tmp change_count+=1 # 回答 print(" ".join(map(str,A))) print(change_count) #return True # 入力 N = int(input()) # 数列の長さを表す整数(N) A = input("") # N個の整数が空白区切り selectionSort(A,N)
def swap(l, i, j): tmp = l[i] l[i] = l[j] l[j] = tmp return l def selection_sort(l): cnt = 0 for i in range(len(l)): minj = i for j in range(i + 1, len(l)): if l[j] < l[minj]: minj = j if i != minj: swap(l, i, minj) cnt += 1 return l, cnt if __name__ == '__main__': N = int(input()) l = list(map(int, input().split())) sl, cnt = selection_sort(l) print(' '.join(map(str, sl))) print(cnt)
1
20,292,089,588
null
15
15
N, K = map(int, input().split()) A = list(map(int, input().split())) def cmb(n, r, p): if (r < 0) or (n < r): return 0 r = min(r, n - r) return fact[n] * factinv[r] * factinv[n-r] % p p = 10 ** 9 + 7 fact = [1, 1] # fact[n] = (n! mod p) factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p) inv = [0, 1] # factinv 計算用 for i in range(2, N + 1): fact.append((fact[-1] * i) % p) inv.append((-inv[p % i] * (p // i)) % p) factinv.append((factinv[-1] * inv[-1]) % p) A.sort() max_sum, min_sum = 0, 0 for i in range(N-1, K-2, -1): max_i = A[i] max_sum += A[i] * cmb(i, K-1, p) % p max_sum %= p j = N - 1 - i min_j = A[j] min_sum += A[j] * cmb(i, K-1, p) % p min_sum %= p ans = (max_sum - min_sum) % p print(ans)
x,y=map(int,input().split());print('NYoe s'[x*2<=~y%2*y<=x*4::2])
0
null
54,503,063,627,488
242
127
T1, T2 = map(int, input().split()) A1, A2 = map(int, input().split()) B1, B2 = map(int, input().split()) a1 = T1 * A1 a2 = T2 * A2 a = a1 + a2 b1 = T1 * B1 b2 = T2 * B2 b = b1 + b2 def bis(p, ok, ng): mid = (ok + ng) // 2 return ( ok if abs(ok - ng) == 1 else bis(p, mid, ng) if p(mid) else bis(p, ok, mid) ) def p(k): x = k * a y = k * b # print(f"k: {k}, x: {x}, y: {y}") #print(f"k: {k}, x+: {x + a1}, y+: {y + b1}") if x < y: return x + a1 >= y + b1 else: return y + b1 >= x + a1 def p2(k): x = k * a + a1 y = k * b + b1 if x < y: return x + a2 >= y + b2 elif x > y: return y + b2 >= x + a2 else: return False if a == b: ans = "infinity" else: # print(bis(p, -1, 10**16)) # print(bis(p2, -1, 10**16)) c = 1 if (a1 < b1 and a > b) or (b1 < a1 and b > a) else 0 # k = bis(lambda k: k * a + a1 >= k * b + b1, 0, 10**16) if a < b else bis(lambda k: k * a + a1 <= k * b + b1, 0, 10**16) # d = if k * a + a1 == k * b + b1 ans = bis(p, 0, 10**16) + bis(p2, 0, 10**16) + c print(ans) # print('-------') # x = 0 # y = 0 # for i in range(114): # x += a1 # y += b1 # #print(x, y) # print(f"{i} {x < y}") # x += a2 # y += b2 # print(f"{i} {x < y}") # #print(x, y)
def solve(t1, t2, a1, a2, b1, b2): if a1 * t1 + a2 * t2 == b1 * t1 + b2 * t2: return 'infinity' if a1 * t1 + a2 * t2 > b1 * t1 + b2 * t2: a1, a2, b1, b2 = b1, b2, a1, a2 at = a1 * t1 + a2 * t2 bt = b1 * t1 + b2 * t2 ans = 0 dg = bt - at if a1 > b1: ans += ((a1 - b1) * t1 - 1) // dg ans += (a1 - b1) * t1 // dg + 1 return ans t1, t2 = map(int, input().split()) a1, a2 = map(int, input().split()) b1, b2 = map(int, input().split()) print(solve(t1, t2, a1, a2, b1, b2))
1
131,712,321,577,158
null
269
269
ma = lambda :map(int,input().split()) lma = lambda :list(map(int,input().split())) tma = lambda :tuple(map(int,input().split())) ni = lambda:int(input()) yn = lambda fl:print("Yes") if fl else print("No") import collections import math import itertools import heapq as hq n,m = ma() s = input() dp = [-1]*(n+1) #dp[i]:: i番目にたどり着く最小コスト dp[0]=0 r=0 while r<=n-1: l=0 tmp=0 while l+1<=m and r+l+1<=n: l+=1 if s[r+l]=="0": tmp=l dp[r+l]=dp[r]+1 r+=tmp #if r==n:break if tmp==0: print(-1) exit() d = dp[-1] rt = [] dp = dp[::-1] r=0 while r<=n-1: l=0 tmp=0 while l+1<=m and r+l+1<=n: l+=1 if dp[r+l]==d-1: tmp=l rt.append(tmp) d-=1 r+=tmp print(*reversed(rt))
#!/usr/bin python3 # -*- coding: utf-8 -*- n, m = map(int, input().split()) s = input() s = s[::-1] INF = 2*n if '1'*m in s: print(-1) exit() dp = [-1] * (n+1) nw = 0 st = 0 nst = 0 ret = [] while nw < (n+1): if s[nw]=='1': dp[nw] = INF else: dp[nw] = dp[st] + 1 nst = nw nw += 1 if nw == n+1: ret.append(nst-st) elif nw > st + m: ret.append(nst-st) st = nst print(' '.join(map(str,ret[::-1])))
1
138,898,836,115,248
null
274
274
def popcount_int(n): return bin(n).count('1') def popcount_bin(s): return s.count('1') def poptimes(n,cnt=1): if n==0: return cnt else: n%=popcount_int(n) cnt+=1 return poptimes(n,cnt) N=int(input()) S=input() S_int=int(S,2) pc=popcount_bin(S) pc_plus=S_int%(pc+1) if pc!=1: pc_minus=S_int%(pc-1) for i in range(N): if S[i]=='1': if pc!=1: tmp=pc_minus-pow(2,N-i-1,pc-1) print(poptimes(tmp%(pc-1))) else: print(0) continue else: tmp=pc_plus+pow(2,N-i-1,pc+1) print(poptimes(tmp%(pc+1)))
n=int(input()) arr = [[False for i in range(13)] for j in range(4)] for count in range(n): code = input().split() if (code[0]=="S"): arr[0][int(code[1])-1]=True elif (code[0]=="H"): arr[1][int(code[1])-1]=True elif(code[0]=="C"): arr[2][int(code[1])-1]=True else: arr[3][int(code[1])-1]=True for i in range(4): if(i==0): img="S" elif(i==1): img="H" elif(i==2): img="C" else: img="D" for j in range(13): if(arr[i][j]==False): print(img+" "+str(j+1))
0
null
4,583,010,291,108
107
54
x1,y1,x2,y2=map(float,input().split()) d=((x1-x2)**2 + (y1-y2)**2)**(1/2) print(d)
N, K = map(int, input().split()) A = [int(x) for x in input().split()] K = min(K, 41) # imos for _ in range(K): B = [0 for _ in range(N)] for i in range(N): l = max(0, i-A[i]) r = min(N-1, i+A[i]) B[l] += 1 if r+1 < N: B[r+1] -= 1 for i in range(1, N): B[i] += B[i-1] A = B print(*A)
0
null
7,872,290,142,240
29
132
a=int(input()) asd=(a)+(a*a)+(a*a*a) print(asd)
a = int(input()) ans = a + a*a + a**3 print(ans)
1
10,242,855,481,298
null
115
115
list=list(map(int,input().split())) if list[0]%(list[1]+list[2])==0: print((list[0]//(list[1]+list[2]))*list[1]) elif list[0]%(list[1]+list[2])<=list[1]: print((list[0]//(list[1]+list[2]))*list[1]+list[0]%(list[1]+list[2])) else: print(list[0]//(list[1]+list[2])*list[1]+list[1])
#!/usr/bin/python3 # -*- coding:utf-8 -*- import numpy def main(): _, _, k = map(int, input().strip().split()) la = numpy.cumsum([0] + list(map(int, input().strip().split()))) lb = numpy.cumsum([0] + list(map(int, input().strip().split())) + [10**9+5]) def bs(x): s, t = 0, len(lb) - 1 while t > s + 1: m = (s + t) // 2 if lb[m] == x: return m if lb[m] > x: t = m else: s = m return s ans = 0 for i, a in enumerate(la): if k - a >= 0: ans = max(ans, i + bs((k - a))) print(ans) if __name__=='__main__': main()
0
null
33,173,943,738,492
202
117
a = input() b = input() n = len(a) count = 0 for i in range(n): if a[i] != b[i]: count = count +1 print(count)
k,n=map(int,input().split()) A=sorted(list(map(int,input().split()))) A.append(A[0]+k) a=A[0] l=[] for i in A: l.append(i-a) a=i print(k-max(l))
0
null
26,971,067,068,702
116
186
kai = input() num = len(kai) ans = 0 n1 = int((num-1) / 2) for i in range(n1): if kai[i] != kai[-1*(i+1)]: ans += 1 l1 = kai[0:n1] for i in range(len(l1)): if l1[i] != l1[-1*(i+1)]: ans += 1 l2 = kai[n1+1:] for i in range(len(l2)): if l2[i] != l2[-1*(i+1)]: ans += 1 if ans == 0: print("Yes") else: print("No")
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")
1
46,449,506,813,710
null
190
190
X, K, D =map(int,input().split()) X = abs(X) if X > K*D: print(X-K*D) else: greed = X//D if (K - greed)%2 == 0: print(X-greed*D) else: print((1+greed)*D -X)
n = int(input()) d = list(map(int, input().split())) a = [0] * n for i in range(n): a[d[i]] += 1 if a[0] == 1 and d[0] == 0: ans = 1 for i in range(1, n): ans *= a[i-1]**a[i] ans %= 998244353 print(ans) else: print(0)
0
null
80,133,302,413,080
92
284
# https://atcoder.jp/contests/abc164/tasks/abc164_d import sys input = sys.stdin.readline S = input().rstrip() res = 0 T = [0] x = 0 p = 1 L = len(S) MOD = 2019 for s in reversed(S): """ 累積和 """ x = (int(s)*p + x)%MOD p = p*10%MOD T.append(x) reminder = [0]*2019 for i in range(L+1): reminder[T[i]%MOD] += 1 for c in reminder: res += c*(c-1)//2 print(res)
import collections S=input() l=len(S) T,d=0,1 A=[0]*2019 A[0]=1 for i in range(l): T+=int(S[l-i-1])*d d*=10 T%=2019 d%=2019 A[T]+=1 B=map(lambda x: x*(x-1)//2,A) print(sum(B))
1
30,865,382,385,738
null
166
166
n,m = map(int, input().split()) c = [] d = [] for i in range(n): arr = input().split() c.append(arr) for j in range(m): d.append(int(input())) for i in range(n): sum = 0 for j in range(m): sum += int(c[i][j])*d[j] print(sum)
x=int(input()) a=x//3600 b=(x-a*3600)//60 c=x-(a*3600+b*60) print(a, ':', b, ':', c, sep='')
0
null
757,811,745,142
56
37
#ALDS1_1_D N = int(input()) min,dif = 10000000000, -10000000000 for i in range(N): a = int(input()) if (a - min) > dif: dif = a - min if a < min: min = a print(dif)
#!/usr/bin/env python3 #coding:utf-8 n = int(input()) ans = -10000000000 mini = 10000000000 for i in range(n): x = int(input()) ans = ans if (x-mini) < ans else x-mini mini = mini if x > mini else x print(ans)
1
12,451,178,168
null
13
13
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd from itertools import accumulate, permutations, combinations, product, groupby, combinations_with_replacement from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left from heapq import heappush, heappop from functools import reduce def input(): return sys.stdin.readline().strip() def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 lim = 2*(10**6) # 必要そうな階乗の限界を入れる fact = [1] * (lim+1) fact_inv = [1] * (lim+1) for n in range(1, lim+1): fact[n] = (fact[n-1] * n) % mod fact_inv[lim] = pow(fact[lim], mod-2, mod) for n in range(lim, 0, -1): fact_inv[n-1] = (n * fact_inv[n]) % mod def C(n, r): return (((fact[n] * fact_inv[r]) % mod) * fact_inv[n-r]) % mod K = INT() S = input() L = len(S) ans = 0 for i in range(K+1): ans += pow(26, K-i, mod)*pow(25, i, mod)*C(i+L-1, i) ans %= mod print(ans)
k = int(input()) s = input() n = len(s) MOD = 10 ** 9 + 7 ans = 0 comb = 1 for i in range(k+1): if i > 0: comb = comb * (n+i-1) * pow(i, MOD-2, MOD) % MOD ans = (ans + comb * pow(25, i, MOD) * pow(26, k-i, MOD)) % MOD print(ans)
1
12,884,292,483,100
null
124
124
n,a,b = map(int,input().split()) mod = pow(10,9)+7 ans = pow(2,n,mod) ans -= 1 def choose(n,k): x,y = 1,1 for i in range(1,k+1): x *= (n-i+1) x %= mod y *= i y %= mod x *= pow(y,mod-2,mod) x %= mod return x ans -= choose(n,a) ans -= choose(n,b) ans %= mod print(ans)
from functools import reduce n, a, b = map(int, input().split()) mod = 10**9 + 7 def f(A): bunsi = reduce(lambda x, y: x*y%mod, range(n, n-A, -1)) bunbo = reduce(lambda x, y: x*y%mod, range(1, A+1)) return bunsi * pow(bunbo, mod-2, mod) % mod ans = pow(2, n, mod) - f(a) -f(b) - 1 ans %= mod print(ans)
1
66,109,251,460,292
null
214
214
#k = int(input()) #s = input() #a, b = map(int, input().split()) #s, t = map(str, input().split()) #l = list(map(int, input().split())) a = int(input()) b = int(input()) if (a == 1 and b == 2): print(3) elif(a == 1 and b == 3): print(2) elif (a == 2 and b == 1): print(3) elif (a == 2 and b == 3): print(1) elif (a == 3 and b == 1): print(2) elif (a == 3 and b == 2): print(1)
rawtemp = input() temp = int(rawtemp) if temp < 30: print("No") else: print("Yes")
0
null
58,581,146,476,992
254
95
import bisect import sys sys.setrecursionlimit(10**9) def mi(): return map(int,input().split()) def ii(): return int(input()) def isp(): return input().split() def deb(text): print("-------\n{}\n-------".format(text)) INF=10**20 def main(): N=ii() L=list(mi()) ans = 0 L.sort() for ai in range(N): for bi in range(ai+1,N): a,b = L[ai],L[bi] left = bisect.bisect_left(L,abs(a-b)+1) right = bisect.bisect_right(L,a+b-1) count = right - left if left <= ai <= right: count -= 1 if left <= bi <= right: count -= 1 ans += count # if count > 0: # print(a,b,count) print(ans//3) if __name__ == "__main__": main()
x = raw_input() a = int (x)**3 print a
0
null
85,716,783,135,970
294
35
n,m = map(int, input().split()) ans=(n+m)*(n+m-1)/2-n*m print(int(ans))
cnt = 0 zorome = 0 num = int(input()) while cnt < num: mass = input().split() if(mass[0] == mass[1]): zorome += 1 if(zorome >= 3): break else: zorome = 0 cnt += 1 print("Yes" if zorome >= 3 else "No")
0
null
23,921,848,597,156
189
72
W,H,x,y,r = map(int,input().split(" ")) if (x >= r) and (x <= (W-r)) and (y >= r) and (y <= (H - r)): print("Yes") else: print("No")
W, H, x, y, r = list(map(int, input().split())) x_right = x + r x_left = x - r y_up = y + r y_down = y - r if x_right <= W and x_left >= 0 and y_up <= H and y_down >= 0: print("Yes") else: print("No")
1
451,581,307,940
null
41
41
import sys n = int(input()) A = [int(_) for _ in input().split()] if n == 1 or n == 2 or n == 3: print(max(A)) sys.exit() dp = [[0, 0] for j in range(n)] M = - float('inf') for i in range(4): M = max(M, A[i]) dp[i][0] = M dp[2][1] = dp[0][0] + A[2] dp[3][1] = max(dp[1][0] + A[3], dp[2][1]) for i in range(4, n): for j in range(2): if i % 2 == 0 and j == 1: dp[i][j] = dp[i-2][1] + A[i] elif i % 2 == 0 and j == 0: dp[i][j] = max(dp[i-2][0] + A[i], dp[i-1][1]) elif i % 2 == 1 and j == 1: dp[i][j] = max(dp[i-2][1] + A[i], dp[i-1][1]) else: dp[i][j] = max(dp[i-2][0] + A[i], dp[i-1][0]) print(dp[n-1][(n+1)%2])
#coding: UTF-8 word = input().upper() cnt = 0 while True: sentence = list(map(str, input().split())) if 'END_OF_TEXT' in sentence: break for i in range(len(sentence)): if word == sentence[i].upper(): cnt += 1 print(cnt)
0
null
19,725,559,602,590
177
65
import sys input = sys.stdin.readline def binary_search_int(ok, ng, test): """ :param ok: solve(x) = True を必ず満たす点 :param ng: solve(x) = False を必ず満たす点 """ while abs(ok - ng) > 1: mid = (ok + ng) // 2 if test(mid): ok = mid else: ng = mid return ok N, K = map(int, input().split()) A = list(map(int, input().split())) A.sort() F = list(map(int, input().split())) F.sort(reverse=True) def max2(x,y): return x if x > y else y def test(x): temp = K for a, f in zip(A, F): temp -= max2((a - x//f), 0) if temp < 0: return False return True print(binary_search_int(A[-1]**2 + 100, -1,test))
N, K = map(int, input().split()) A = sorted(map(int, input().split())) F = sorted(map(int, input().split()), reverse=True) ng = -1 ok = 0 for i in range(N): ok = max(A[i]*F[i], ok) def is_ok(arg): cnt = 0 for i in range(N): cnt += max(A[i] - arg//F[i], 0) return cnt <= K def m_bisect(ng, ok): while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid return ok print(m_bisect(ng, ok))
1
165,171,413,977,248
null
290
290
import bisect,collections,copy,heapq,itertools,math,numpy,string import sys sys.setrecursionlimit(10**7) def S(): return sys.stdin.readline().rstrip() def I(): return int(sys.stdin.readline().rstrip()) def LI(): return list(map(int,sys.stdin.readline().rstrip().split())) def LS(): return list(sys.stdin.readline().rstrip().split()) def main(): H,A = LI() print(int(H/A) if H%A==0 else int(H/A+1)) main()
import math H,A=map(int,input().split()) print(math.ceil(H/A))
1
77,304,394,195,870
null
225
225
W,H,x,y,r=map(int,input().split()) print("Yes"*(r<=x<=W-r)*(r<=y<=H-r)or"No")
w,h,x,y,r=map(int, input().split()) x_max=int(x+r) x_min=int(x-r) y_max=int(y+r) y_min=int(y-r) #print(x_max,x_min,y_max,y_min) if y_max > h: print("No") else: if y_min < 0: print("No") else: if x_max > w: print("No") else: if x_min < 0: print("No") else: print("Yes")
1
444,041,705,380
null
41
41
n = int(input()) S = [int(_) for _ in input().split()] q = int(input()) T = [int(_) for _ in input().split()] cnt = 0 for t in T: if t in S: cnt += 1 print(cnt)
S, T = map(str, input().split()) print('{}{}'.format(T, S))
0
null
51,645,949,342,428
22
248
import random name = str(input()) a = len(name) if 3<= a <= 20: b = random.randint(0,a-3) ada_1 = name[b] ada_2 = name[b+1] ada_3 = name[b+2] print(ada_1+ada_2+ada_3) else: None
a=input() print(a[0:3])
1
14,750,218,415,770
null
130
130
# 12-Structured_Program_II-How_many_ways.py # ????????????????????° # 1 ?????? n ?????§?????°?????????????????????????????§???????????°?????????????????????????¨???? x ??¨?????? # ????????????????????°????±???????????????°????????????????????????????????? # ????????°???1 ?????? 5 ?????§?????°???????????????????????§????????????????¨???? 9 ??¨??????????????????????????? # 1 + 3 + 5 = 9 # 2 + 3 + 4 = 9 # ?????????????????????????????? # Input # ?????°??????????????????????????\?????¨??????????????????????????? # ???????????????????????§??????????????§??????????????? n???x ??? 1 ??????????????????????????? # n???x ?????¨?????? 0 ?????¨?????\?????????????????¨???????????? # n ??? 3 ??\??? 100?????\?????¨???????????? # Output # ????????????????????????????????????????????????????????°???????????????????????????????????? # Sample Input # 5 9 # 0 0 # Sample Output # 2 result = [] n=[] x=[] while 1: temp = input().split() if temp[0]=="0" and temp[1]=="0": break; else: n.append( int( temp[0] )) x.append( int( temp[1] )) for i in range( len(n) ): count =0 for n1 in range(1,n[i]+1-2): for n2 in range(n1+1, n[i]+1-1): for n3 in range(n2+1, n[i]+1): sum = n1+n2+n3 if sum == x[i]: count+=1 result.append(count) for i in range( len(result) ): print(result[i]) # if i == len(result)-1: # print(result[i]) # else: # print("{0} ".format(result[i]), end="")
while True: n, x = map(int, input().split()) if n == 0: break count = 0 for n1 in range(1, n+1): for n2 in range(n1+1, n+1): for n3 in range(n2+1, n+1): if n1 + n2 + n3 == x: count += 1 print(count)
1
1,316,793,171,082
null
58
58
import sys; from decimal import Decimal import math; from itertools import combinations, product import bisect; from collections import Counter, deque, defaultdict # sys.setrecursionlimit(10 ** 6) MOD = 10 ** 6 + 7 INF = 10 ** 9 PI = 3.14159265358979323846 def read_str(): return sys.stdin.readline().strip() def read_int(): return int(sys.stdin.readline().strip()) def read_ints(): return map(int, sys.stdin.readline().strip().split()) def read_str_list(): return list(sys.stdin.readline().strip().split()) def read_int_list(): return list(map(int, sys.stdin.readline().strip().split())) def lcm(a: int, b: int) -> int: return (a * b) // math.gcd(a, b) def Main(): n = read_int() testimony = [[] for _ in range(n)] ans = 0 for i in range(n): for _ in range(read_int()): x, y = read_ints() testimony[i].append((x-1, y)) for bit in range(1 << n): flag = True for i in range(n): if (bit >> i) & 1: for x, y in testimony[i]: if (bit >> x) & 1 != y: flag = False break else: continue break if flag: ans = max(ans, bin(bit).count('1')) print(ans) if __name__ == '__main__': Main()
N=int(input()) syogen=[] for i in range(N): a=int(input()) temp=[list(map(int, input().split())) for _ in range(a)] syogen.append([a,temp]) ans=0 for h in range(2**N): flag=0 cnt=0 l=[0]*N for g in range(N): if h>>g &1: l[g]=1 #print(l) for gg in range(N): if l[gg]==1: temp_=syogen[gg] #print(temp_) for n in range(temp_[0]): if l[temp_[1][n][0]-1]==temp_[1][n][1]: continue else: flag=1 break if flag==1: break elif flag==0 and gg==N-1: #print(bin(h)) ans=max(ans,sum(l)) print(ans)
1
121,902,816,558,998
null
262
262
import sys readline = sys.stdin.buffer.readline a,b,c,k =list(map(int,readline().rstrip().split())) if k <= a: print(k) elif k > a and k <= a + b: print(a) else: print(a -(k-(a+b)))
A, B, C, K = [int(_) for _ in input().split()] print(K if K <= A else A if K <= A + B else A - (K - A - B))
1
21,777,368,725,598
null
148
148
N,K=map(int,input().split()) mod=10**9+7 X=[0]+[pow(K//d,N,mod) for d in range(1,K+1)] ''' Y=[[] for i in range(K+1)] for i in range(1,K+1): for j in range(i,K+1,i): Y[j].append(i) ''' #print(X) isPrime=[1 for i in range(K+1)] isPrime[0]=0;isPrime[1]=0 for i in range(K+1): if isPrime[i]==0: continue for j in range(2*i,K+1,i): isPrime[j]=0 Mebius=[1 for i in range(K+1)] Mebius[0]=0 for i in range(2,K+1): if isPrime[i]==0: continue for j in range(i,K+1,i): Mebius[j]*=-1 for i in range(2,K+1): for j in range(i*i,K+1,i*i): Mebius[j]=0 Z=[0 for i in range(K+1)] for i in range(1,K+1): for j in range(i,K+1,i): Z[i]+=X[j]*Mebius[j//i] ans=0 for i in range(1,K+1): ans+=Z[i]*i ans%=mod print(ans) ''' P(G%d==0) Gがd,2d,3d,...の可能性がある P(d)-P(2d)-P(3d)-P(5d)+P(6d)-P(7d) '''
def modpow(val, n, mod): ret = 1 while n: if n & 1: ret = (ret * val) % mod val = (val * val) % mod n = n >> 1 return ret mod = 10 ** 9 + 7 n, k = map(int, input().split()) my_dict = dict() ret = 0 for i in range(k, 0, -1): tmp = modpow(k // i, n, mod) cnt = 2 while True: val = i * cnt if val > k: break else: cnt += 1 tmp -= my_dict[val] my_dict[i] = tmp ret += tmp * i % mod print(ret % mod)
1
36,693,075,813,480
null
176
176
import sys while 1 > 0: height, width = map(int, raw_input().split()) if height == 0 and width == 0: break for i in range(width): sys.stdout.write("#") print "" for i in range(height - 2): sys.stdout.write("#") for j in range(width - 2): sys.stdout.write(".") sys.stdout.write("#") print "" for i in range(width): sys.stdout.write("#") print "" print
n=int(input()) a=list(map(int,input().split()))[::-1] number=2 if 1 not in a: print(-1);exit() count=n-len(a[:a.index(1)+1]) a=a[:a.index(1)][::-1] for i in a: if i==number: number+=1 else: count+=1 print(count)
0
null
57,651,556,833,248
50
257
from collections import Counter N = int(input()) S = input() D = Counter(S) ans = 1 for d in D.values(): ans *= d if len(D.values()) < 3: ans = 0 for i in range(N): for x in range(1, (N-i+1)//2): if S[i] != S[i+x] and S[i+x] != S[i+2*x] and S[i+2*x] != S[i]: ans -= 1 print(ans)
def main(): n = int(input()) s = input() r_set, g_set, b_set = set(), set(), set() for i, c in enumerate(s): if c == "R": r_set.add(i) elif c == "G": g_set.add(i) elif c == "B": b_set.add(i) cnt = 0 for i in range(n): for j in range(i + 1, n): k = 2 * j - i if i in r_set and j in g_set and k in b_set: cnt += 1 elif i in r_set and j in b_set and k in g_set: cnt += 1 elif i in g_set and j in r_set and k in b_set: cnt += 1 elif i in g_set and j in b_set and k in r_set: cnt += 1 elif i in b_set and j in r_set and k in g_set: cnt += 1 elif i in b_set and j in g_set and k in r_set: cnt += 1 print(len(r_set) * len(g_set) * len(b_set) - cnt) if __name__ == "__main__": main()
1
36,289,633,645,040
null
175
175
S = input() T = input() flag = True for i in range(len(S)): if(S[i] != T[i]): flag = False if(flag): print('Yes') else: print('No')
s, t = [input() for _ in range(2)] print('Yes' if s == t[:len(s):] else 'No')
1
21,357,195,012,220
null
147
147
N = int(input()) line = input() R_ = line.count("R") W_ = line.count("W") final_line = "R" * R_ + "W" * W_ dic = {"W":0, "R":0} for idx, c in enumerate(line): if c != final_line[idx]: dic[c] += 1 print(max(dic.values()))
N = int(input()) #stones = list(input()) stones = input() #print(stones) a = stones.count('W') b = stones.count('R') left_side =stones.count('W', 0, b) print(left_side)
1
6,253,751,670,628
null
98
98
d, t, s = map(int, input().split()) if t * s >= d: print('Yes') quit() print('No')
d,t,s = map(int, input().split()) if(d-t*s>0): print("No") else: print("Yes")
1
3,574,111,210,980
null
81
81
from heapq import * from collections import deque N,K,*A = map(int, open(0).read().split()) pos = [] zero = 0 neg = [] count = K m = 1000000007 for x in A: if x > 0: pos.append(x) elif x == 0: zero += 1 else: neg.append(x) if K == N: ans = A[0] % m for x in A[1:]: ans = (ans*x) % m print(ans) elif K % 2 == 1 and len(pos) == 0: if zero > 0: print(0) else: ai = [x * (-1) for x in A] heapify(ai) ans = (heappop(ai)*(-1)) % m for i in range(K-1): ans = (ans*heappop(ai)*(-1)) % m print(ans) elif K > N - zero: print(0) else: heapify(neg) ans = 1 negpos = [] for i in range(len(neg)//2): temp = heappop(neg) negpos.append(temp*heappop(neg)) dnp = deque(negpos) posi = [x * (-1) for x in pos] heapify(posi) if len(posi) > 0: t1 = heappop(posi) * (-1) else: t1 = 1 if len(posi) > 0: t2 = heappop(posi) * (-1) else: t2 = 1 for i in range(K): if count > 1: if len(dnp) > 0: if t1 > dnp[0]: if count > 2: ans = (ans*t1) % m t1 = t2 if len(posi) > 0: t2 = heappop(posi) * (-1) else: t2 = 1 count -= 1 else: if t2 == 1 and len(posi) == 0: ans = (ans*dnp.popleft()) % m count -= 2 else: ans = (ans*t1) % m t1 = t2 if len(posi) > 0: t2 = heappop(posi) * (-1) else: t2 = 1 count -= 1 else: if t1 * t2 > dnp[0]: if count != 3: ans = (ans*t1*t2) % m if len(posi) > 0: t1 = heappop(posi) * (-1) else: t1 = 1 if len(posi) > 0: t2 = heappop(posi) * (-1) else: t2 = 1 count -= 2 else: if len(posi) > 0: t3 = heappop(posi) * (-1) M = max(t1*t2*t3,dnp[0]*t1) ans = (ans*M) % m break else: ans = (ans*dnp.popleft()*t1) % m break else: ans = (ans*dnp.popleft()) % m count -= 2 else: ans = (ans*t1) % m if len(posi) > 0: t1 = t2 t2 = heappop(posi) * (-1) else: t1 = t2 count -= 1 elif count == 1: ans = (ans*t1) % m break else: break print(ans)
s = input() t = input() count = 0 for l in range(len(s)): if s[l] != t[l]: count += 1 print(count)
0
null
9,892,592,424,938
112
116
import math from math import gcd INF = float("inf") import sys input=sys.stdin.readline import itertools from collections import Counter def main(): def factorization(n): if n == 1: return [] 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 m = [0] for i in range(1,10**6): m.append(m[i-1]+i) ans = 0 n = int(input()) k = factorization(n) for i,l in k: for u in range(len(m)): if l < m[u]: ans += u-1 break print(ans) if __name__=="__main__": main()
i=1 x = int(input()) while x != 0 : print("Case {0}: {1}".format(i, x)) x = int(input()) i=i+1
0
null
8,647,166,912,608
136
42
mod=10**9+7 N=int(input()) A=list(map(int,input().split())) B=[0] for x in A: B.append(B[-1]+x) ans=0 for i in range(N): s=(B[N]-B[i+1])%mod ans+=A[i]*s ans%=mod print(ans)
import numpy as np MOD = 10**9+7 N = int(input()) A = np.array(list(map(int, input().split()))) A = A % MOD AS = [] s = 0 for a in range(len(A)): s = (s + A[a]) % MOD AS.append(s) AS = np.array(AS) s = 0 for i in range(len(A)-1): s = (A[i] * ((AS[N-1]-AS[i])) % MOD + s) % MOD print(s)
1
3,779,273,212,572
null
83
83
import math n, m = map(int, input().split()) c = 0 f = [math.floor(n/2), math.floor(n/2) + 1] if n % 2 == 0: while c < m: c += 1 if c == math.floor(n/4) + 1: if (f[1] + 1) % n == 0: f[1] = n else: f[1] = (f[1] + 1) % n print(str(f[0]) + ' ' + str(f[1])) if (f[0] - 1) % n == 0: f[0] = n else: f[0] = (f[0] - 1) % n if (f[1] + 1) % n == 0: f[1] = n else: f[1] = (f[1] + 1) % n else: while c < m: c += 1 print(str(f[0]) + ' ' + str(f[1])) if (f[0] - 1) % n == 0: f[0] = n else: f[0] = (f[0] - 1) % n if (f[1] + 1) % n == 0: f[1] = n else: f[1] = (f[1] + 1) % n
while True: a=input() b=a.split() c=list() for d in b: c.append(int(d)) if c[0]==0 and c[1]==0: break else: d=sorted(c) print(d[0],d[1])
0
null
14,696,829,533,518
162
43
n,m,l = (int(x) for x in input().split()) t1 = [[0 for i in range(m)] for j in range(n)] t2 = [[0 for i in range(l)] for j in range(m)] t3 = [[0 for i in range(l)] for j in range(n)] i = 0 while i < n: t1[i] = list(int(x) for x in input().split()) i += 1 i = 0 while i < m: t2[i] = list(int(x) for x in input().split()) i += 1 # cal t3 i = 0 while i < n: j = 0 while j < l: k,c = 0,0 while k < m: #print(str(i) + " " + str(k)) c += t1[i][k] * t2[k][j] k += 1 if j != 0: print(' ', end='') print(c, end='') j += 1 print ('') i += 1
def bubble_sort(array): isEnd = False count_swap = 0 while isEnd is False: isEnd = True for j in reversed(range(1,len(array))): if array[j - 1] > array[j]: tmp = array[j - 1] array[j - 1] = array[j] array[j] = tmp count_swap += 1 isEnd = False return count_swap def print_array(array): print(str(array)[1:-1].replace(', ', ' ')) def main(): N = int(input()) array = [int(s) for s in input().split(' ')] count = bubble_sort(array) print_array(array) print(count) if __name__ == '__main__': main()
0
null
730,781,950,402
60
14
from math import gcd def readinput(): n,m=map(int,input().split()) a=list(map(int,input().split())) return n,m,a def lcm(a,b): return a*b//gcd(a,b) def main(n,m,a): #s=set(a) #print(s) x=a[0]//2 for i in range(1,n): x=lcm(x,a[i]//2) #print(x) gusubai=False kisubai=False for i in range(n): if x%a[i]!=0: gusubai=True else: kisubai=True y=m//x #print(y,x,m) if gusubai and not kisubai: ans=y//2+y%2 elif gusubai and kisubai: ans=0 else: ans=y return ans if __name__=='__main__': n,m,a=readinput() ans=main(n,m,a) print(ans)
input() array = [int(x) for x in input().split()] print(' '.join(list(str(x) for x in array))) for i in range(1, len(array)): key = array[i] j = i - 1 while j >= 0 and array[j] > key: array[j + 1] = array[j] j -= 1 array[j + 1] = key print(' '.join(list(str(x) for x in array)))
0
null
50,623,250,505,850
247
10
from itertools import permutations n = int(input()) s = input() out = 0 ans = s.count("R")*s.count("G")*s.count("B") combi = list(permutations(["R","G","B"],3)) for i in range(1,n): for j in range(n-i*2): if (s[j], s[j+i], s[j+i*2]) in combi: ans -= 1 print(ans)
n = int(input()) s = input() R = s.count("R") G = s.count("G") B = s.count("B") total = R*G*B for i in range(n-1): for j in range(i+1,n): if j*2-i < n: if s[i] != s[j] and s[j] != s[j*2-i] and s[i] != s[j*2-i]: total -= 1 else: continue print(total)
1
36,302,027,296,700
null
175
175
import sys def main(): s = input() if len(s) % 2 == 1: print('No') sys.exit() s1 = s[::2] s2 = s[1::2] s1t = [c == 'h' for c in s1] s2t = [c == 'i' for c in s2] if all(s1t) and all(s2t): print('Yes') else: print('No') if __name__ == '__main__': main()
from itertools import product a, b, c, d = map(int, input().split()) print(max(v[0] * v[1] for v in product((a, b), (c, d))))
0
null
28,036,023,717,988
199
77
startX, countK, distanceD = map(int, input().split()) n = int(abs(startX) / distanceD) ans = abs(startX) % distanceD if n > countK: ans += distanceD * (n - countK) else: if (countK - n) % 2 == 1: ans= abs(ans - distanceD) print(ans)
import sys import math import itertools import collections from collections import deque from collections import defaultdict sys.setrecursionlimit(1000000) MOD = 10 ** 9 + 7 MOD2 = 998244353 INF = float('inf') input = lambda: sys.stdin.readline().strip() NI = lambda: int(input()) NMI = lambda: map(int, input().split()) NLI = lambda: list(NMI()) SI = lambda: input() def combinations_count(n, r): if n == 1: return 0 else: return math.factorial(n) // (math.factorial(n - r) * math.factorial(r)) def main(): S = SI() ls = [] len_S = len(S) rem = 0 for s in range(len_S-1,-1,-1): rem = (rem+int(S[s])* pow(10, len_S-s-1, 2019))%2019 ls.append(rem) import collections cls = collections.Counter(ls) clsv= list(cls.values()) ans = 0 for p in clsv: ans += combinations_count(p,2) ans += cls[0] print(ans) if __name__ == '__main__': main()
0
null
18,152,611,942,684
92
166