code1
stringlengths
16
427k
code2
stringlengths
16
427k
similar
int64
0
1
pair_id
int64
2
181,637B
question_pair_id
float64
3.71M
180,629B
code1_group
int64
1
299
code2_group
int64
1
299
from sys import stdin import sys import math from functools import reduce import functools import itertools from collections import deque,Counter,defaultdict from operator import mul import copy # ! /usr/bin/env python # -*- coding: utf-8 -*- import heapq sys.setrecursionlimit(10**6) # INF = float("inf") INF = 10**18 import bisect import statistics mod = 10**9+7 # mod = 998244353 N = int(input()) if N % 2 == 1: print(0) else: i = 1 ans = 0 while N > 0: N = N // 5 ans += N // 2 print(ans)
X = input() X = int(X) if X >= 400 and X <= 599: print('8') elif X >= 600 and X <= 799: print('7') elif X >= 800 and X <= 999: print('6') elif X >= 1000 and X <= 1199: print('5') elif X >= 1200 and X <= 1399: print('4') elif X >= 1400 and X <= 1599: print('3') elif X >= 1600 and X <= 1799: print('2') elif X >= 1800 and X <= 1999: print('1')
0
null
61,414,959,229,166
258
100
N, K = map(int, input().split(' ')) H = sorted(list(map(int, input().split(' '))), reverse=True) print(sum(H[K:]))
S = input() s1 = S[0:int((len(S)-1)/2)] s2 = S[int((len(S)/2))+1:len(S)+1] if S == S[::-1] and s1 == s1[::-1] and s2 == s2[::-1]: print("Yes") else: print("No")
0
null
62,553,042,210,428
227
190
def main(): s = input() if s[2] == s[3] and s[4] == s[5]: print("Yes") else: print("No") return main()
# kurimu_usamaro様のメソッドを拝借しています。 class Combi(): def __init__(self, N, mod): self.power = [1 for _ in range(N+1)] self.rev = [1 for _ in range(N+1)] self.mod = mod for i in range(2, N+1): self.power[i] = (self.power[i-1]*i) % self.mod self.rev[N] = pow(self.power[N], self.mod-2, self.mod) for j in range(N, 0, -1): self.rev[j-1] = (self.rev[j]*j) % self.mod def com(self, K, R): if K < R: return 0 else: return ((self.power[K])*(self.rev[K-R])*(self.rev[R])) % self.mod def pom(self, K, R): if K < R: return 0 else: return (self.power[K])*(self.rev[K-R]) % self.mod def main(): mod = 10**9+7 N,K = map(int,input().split()) A = list(map(int,input().split())) A.sort() c = Combi(N,mod) ans = 0 if K == 1: print(0) else: for i, a in enumerate(A): ans += c.com(i, K-1)*a ans -= c.com(N-1-i, K-1)*a ans %= mod print(ans%mod) if __name__ == "__main__": main()
0
null
68,842,075,593,732
184
242
import sys sys.setrecursionlimit(10**7) INF = 10 ** 18 MOD = 10 ** 9 + 7 def LI(): return list(map(int, sys.stdin.readline().split())) def II(): return int(sys.stdin.readline()) def LS(): return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def main(): t1, t2 = LI() a1, a2 = LI() b1, b2 = LI() if a1 < b1: tmp = b1 b1 = a1 a1 = tmp tmp = b2 b2 = a2 a2 = tmp l1 = (a1 - b1) * t1 l2 = (a2 - b2) * t2 l3 = l1 + l2 if l3 == 0: print("infinity") return if l3 > 0: print(0) return ans = 1 if l1 % (-l3) == 0: print(ans + 2 * (l1 // (-l3)) - 1) return print(ans + 2 * (l1 // (-l3))) if __name__ == '__main__': main()
T1, T2, A1, A2, B1, B2 = map(int, open(0).read().split()) P = (A1 - B1) * T1 Q = (A2 - B2) * T2 if P > 0: P, Q = -P, -Q if P + Q < 0: print(0) elif P + Q == 0: print("infinity") else: S, T = divmod(-P, P + Q) print(S * 2 + (T != 0))
1
132,010,790,862,704
null
269
269
A,B,N = (int(a) for a in input().split()) def f(x) : return (A*x)//B - A * (x//B) if B-1 <= N : print(max(f(B-1) , f(N))) else : print(f(N))
def main(): a, b = map(int, input().split()) if 10 > a and 10 > b: print(a*b) else: print("-1") if __name__ == '__main__': main()
0
null
92,942,177,052,582
161
286
def main(): K = int(input()) A,B = map(int,input().split()) for i in range(A,B+1): if i%K == 0: return('OK') return('NG') print(main())
while True: numbers = list(map(int,input())) if numbers[0] == 0: break print(sum(numbers))
0
null
13,986,343,103,682
158
62
import sys input = sys.stdin.readline from collections import * H1, M1, H2, M2, K = map(int, input().split()) print(60*H2+M2-(60*H1+M1)-K)
cnt = 0 def insertion_sort(seq, n, g): global cnt for i in range(g, n): v = seq[i] j = i - g while j >= 0 and seq[j] > v: seq[j + g] = seq[j] j = j - g cnt = cnt + 1 seq[j + g] = v def shell_sort(seq, n): g = 1 G = [] while g <= n: G.append(g) g = 3 * g + 1 print(len(G)) print(' '.join(map(str, reversed(G)))) for g in reversed(G): insertion_sort(seq, n, g) return seq n = int(input()) a = [int(input()) for _ in range(n)] ans = shell_sort(a, n) print(cnt) print('\n'.join(map(str, ans)))
0
null
8,957,325,342,732
139
17
k=int(input()) s=input() if len(s) <= k: print(s) else: print(s[:k]+'...')
def resolve(): K = int(input()) S = input() if K < len(S): print(S[:K] + "...") else: print(S) resolve()
1
19,640,584,579,418
null
143
143
# # # author : samars_diary # # 13-09-2020 │ 12:41:59 # # # import sys, os.path #if(os.path.exists('input.txt')): #sys.stdin = open('input.txt',"r") #sys.stdout = open('output.txt',"w") sys.setrecursionlimit(10 ** 5) def mod(): return 10**9+7 def i(): return sys.stdin.readline().strip() def ii(): return int(sys.stdin.readline()) def li(): return list(sys.stdin.readline().strip()) def mii(): return map(int, sys.stdin.readline().split()) def lii(): return list(map(int, sys.stdin.readline().strip().split())) #print=sys.stdout.write def solve(): n,x,t=mii() print(t*(n//x)+t*(bool(n%x))) solve()
N, X, T = list(map(int,input().split())) if (N%X!=0): ans = (N//X + 1) * T else: ans = (N//X) * T print(ans)
1
4,206,152,233,568
null
86
86
import sys H, A = map(int, next(sys.stdin.buffer).split()) print(-(-H // A))
N = int(input()) print(-(-N//1000)*1000 - N)
0
null
42,757,067,380,996
225
108
X,Y = map(int, input().split()) if Y - 2*X >= 0 and 4*X - Y >= 0 and (Y - 2*X) % 2 == 0 and (4*X - Y) % 2 == 0: print('Yes') else: print('No')
x, y = (int(a) for a in input().split()) foot = 0 y_tmp = y y_tmp2 = y for i in range(x): y_tmp -= 2 * i + 4 * (x - i) y_tmp2 -= 4 * i + 2 * (x - i) if y_tmp == 0 or y_tmp2 == 0: print('Yes') exit() else: y_tmp = y y_tmp2 = y print('No')
1
13,741,916,943,300
null
127
127
import math x = list(map(int,input().split())) A = x[0] B = x[1] H = x[2] M = x[3] y = 2*math.pi*((H*60+M)/720-M/60) z = math.sqrt(A**2+B**2-2*A*B*math.cos(y)) print(z)
import math A, B, H, M = map(int, input().split()) wa = 360/12 wb = 360/1 t = H + M/60 theta = math.radians((wa*t)%360 - (wb*t)%360) print(math.sqrt(A**2 + B**2 -2*A*B*math.cos(theta)))
1
20,273,200,288,608
null
144
144
n = input() if "7" in n: print('Yes') else: print('No')
n=input() if n.count('7')>0: print('Yes') else: print('No')
1
34,253,271,325,052
null
172
172
X = int(input()) a = 100 for i in range(1, 100000): a = a * 101 // 100 if a >= X: print(i) exit()
N, K = map(int, input().split()) A = list(map(int, input().split())) MOD = 10 ** 9 + 7 def solve(N, K, A): ans = 1 # K = N の場合は明らか if K == N: for i in range(K): ans *= A[i] ans %= MOD # Ai の全ての数が負かつ K が奇数のとき、 elif max(A) < 0 and K % 2 == 1: A.sort(reverse=True) # 絶対値が小さい方から K 個の積 for i in range(K): ans *= A[i] ans %= MOD # それ以外の場合、積は必ず非負 else: # {Ai} を絶対値の降順にソート A.sort(key=abs, reverse=True) # 最初の K 個の積 sign = 1 for i in range(K): ans *= A[i] ans %= MOD if A[i] < 0: sign *= -1 elif A[i] == 0: sign *= 0 # P が負の場合 if sign < 0: small_nonneg = [a for a in A[K:] if a >= 0] small_neg = [a for a in A[K:] if a < 0] large_nonneg = [a for a in A[:K] if a >= 0] large_neg = [a for a in A[:K] if a < 0] if not small_neg or not large_nonneg: ans *= max(small_nonneg) ans %= MOD ans *= pow(max(large_neg), MOD - 2, MOD) ans %= MOD elif not small_nonneg or not large_neg: ans *= min(small_neg) ans %= MOD ans *= pow(min(large_nonneg), MOD - 2, MOD) ans %= MOD else: if min(small_neg) * max(large_neg) > max(small_nonneg) * min( large_nonneg ): # (2) 正の数を 1 つ取り除き、負の数を 1 つ加える ans *= min(small_neg) ans %= MOD ans *= pow(min(large_nonneg), MOD - 2, MOD) ans %= MOD else: # (1) 負の数を 1 つ取り除き、非負の数を 1 つ加える ans *= max(small_nonneg) ans %= MOD ans *= pow(max(large_neg), MOD - 2, MOD) ans %= MOD return ans print(solve(N, K, A))
0
null
18,279,807,580,772
159
112
import sys n = int(input()) if n % 1000 == 0: print(0) sys.exit() while n > 1000: n -= 1000 print(1000 - n)
def main(): N, K = map(int, input().split()) *A, = map(int, input().split()) ans = [] for i in range(K, N): cond = A[i] > A[i - K] ans.append('Yes' if cond else 'No') print(*ans, sep='\n') if __name__ == '__main__': main()
0
null
7,864,541,496,176
108
102
def main(): k = int(input()) s = str(input()) output = '' if len(s) > k: for i in range(k): output += s[i] output += '...' else: output = s print(output) if __name__ == '__main__': main()
N = int(input()) N = N%10 if N == 2 or N == 4 or N == 5 or\ N == 7 or N == 9: print('hon') elif N == 0 or N == 1 or N == 6 or\ N == 8: print('pon') else: print('bon')
0
null
19,428,733,641,082
143
142
N = int(input()) c = 0 b = [0]*1000 p = 0 while N % 2 == 0: b[p] += 1 N //= 2 if b[p]!=0: p += 1 i = 3 while i * i <= N: if N % i == 0: b[p] += 1 N //= i else: i += 2 if b[p]!=0: p += 1 if N==i: b[p] += 1 N //= i if N!=1: p += 1 b[p] += 1 for v in b: for i in range(1,v+1): if i<=v: c += 1 v -= i else: break print(c)
days = ["MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"] S = input() if S == "SUN": print(7) else: print(days.index("SUN") - days.index(S))
0
null
75,175,996,737,560
136
270
a, b, n = map(int, input().split()) def calc(x): return int(a * x / b) - a * int(x / b) if n < b: print(calc(n)) else: print(calc(b-1))
A, B, N = map(int, input().split()) x = min(B-1, N) ans = (A * x // B) - A * (x // B) print(ans)
1
27,953,314,498,672
null
161
161
x = input() num = int(x) print(num*num*num)
value = int(input()) print(value ** 3)
1
272,878,563,672
null
35
35
n = int(input()) s = input() al = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' ans = "" for i in s: ind = al.index(i) + n ans += al[ind % 26] print(ans)
N = int(input()) S = input() #print(ord("A")) #print(ord("B")) #print(ord("Z")) for i in range(len(S)): ascii = ord(S[i]) + N #Sのi文字目のアスキーコードを計算してしれにNを足してづらす if ascii > ord("Z"): #アスキーコードがよりも大きくなった時はA初まりにづらす ascii = ascii - (ord("Z") - ord("A") + 1) print(chr(ascii),end = "") #,end = "" は1行ごとに改行しないでプリントする仕組み
1
134,838,404,274,200
null
271
271
def main(): s = list(input()) k = int(input()) lst = [] cnt = 1 flg = 0 ans = 0 prev = s[0] for i in range(1, len(s)): if prev == s[i]: cnt += 1 else: lst.append(cnt) cnt = 1 prev = s[i] flg = 1 lst.append(cnt) if len(lst) == 1: ans = len(s) * k // 2 else: ans += sum(map(lambda x: x // 2, lst[1:len(lst)-1])) * k # for l in lst[1: len(lst) - 1]: # ans += l // 2 * k if s[-1] == s[0]: ans += (lst[0] + lst[-1]) // 2 * (k - 1) ans += lst[0] // 2 + lst[-1] // 2 else: ans += (lst[0] // 2 + lst[-1] // 2) * k print(ans) if __name__ == "__main__": main()
s = list(input()) k = int(input()) n = len(s) ans = 0 # すべて同じ文字の場合 if s == [s[0]] * n: print((n*k)//2) exit(0) # 先頭と末尾が異なる場合 i = 1 while i < n: if s[i-1] == s[i]: t = 2 i+=1 while i < n and s[i-1] == s[i]: t+=1 i+=1 ans += (t//2)*k i+=1 if s[0] != s[-1]: print(ans) exit(0) # 先頭と末尾が一致する場合 # まず不一致の場合と同様に数えて、左右端の連続長さを数える # 連結したとき、左右の1ブロックのみはそのまま数えられる # 残りのk-1ブロックは、左右がつながった形で数えられる i = 1 left = 1 right = 1 for i in range(n): if s[i] == s[i+1]: left += 1 else: break for i in range(n-1, -1, -1): if s[i] == s[i-1]: right += 1 else: break if s[0] == s[-1]: ans = ans - (k-1) * (left//2 + right//2) + (k-1) * ((left+right)//2) print(ans)
1
175,270,126,143,552
null
296
296
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines def main(): x = int(readline()) if x: print(0) else: print(1) if __name__ == '__main__': main()
print(1 if input() == '0' else 0)
1
2,940,540,713,710
null
76
76
ans = [] for i, x in enumerate(open(0).readlines()): ans.append("Case %d: %s" % (i+1, x)) open(1,'w').writelines(ans[:-1])
i = 0 while True: x = int(raw_input()) if x == 0: break i = i + 1 print "Case {}: {}".format(i,x)
1
477,349,197,710
null
42
42
import copy def BubbleSort(C, N): for i in range(N): for j in reversed(range(i+1, N)): if C[j][1:2] < C[j-1][1:2]: C[j], C[j-1] = C[j-1], C[j] print(*C) stableCheck(C, N) def SelectionSort(C, N): for i in range(N): minj = i for j in range(i, N): if C[j][1:2] < C[minj][1:2]: minj = j C[i], C[minj] = C[minj], C[i] print(*C) stableCheck(C, N) def stableCheck(C, N): global lst flag = 1 for i in range(N): for j in range(i+1, N): if lst[i][1:2] == lst[j][1:2]: fir = lst[i] sec = lst[j] for k in range(N): if C[k] == fir: recf = k if C[k] == sec: recs = k if recf > recs: print("Not stable") flag = 0 break if flag ==0: break if flag : print("Stable") N = int(input()) lst = list(map(str, input().split())) lst1 = copy.deepcopy(lst) lst2 = copy.deepcopy(lst) BubbleSort(lst1, N) SelectionSort(lst2, N)
# -*- coding: utf-8 -*- def conv_input(arr): ret = [] for e in arr: ret.append((e[0], int(e[1]))) return ret def conv_output(conv_arr): ret = [] for e in conv_arr: ret.append(e[0] + str(e[1])) return ret def is_stable(arr1, arr2): ret = 'Stable' for a1, a2 in zip(arr1, arr2): if a1 == a2: continue else: ret = 'Not stable' break return ret def bubble_sort(n, arr): flag = True while flag: flag = False for i in reversed(range(n)): if i is 0: break if arr[i][1] < arr[i - 1][1]: tmp = arr[i] arr[i] = arr[i - 1] arr[i - 1] = tmp flag = True return arr def selection_sort(n, arr): for i in range(n): minj = i for j in range(i, n): if arr[j][1] < arr[minj][1]: minj = j if i != minj: tmp = arr[minj] arr[minj] = arr[i] arr[i] = tmp return arr if __name__ == '__main__': n = int(input()) arr1 = arr2 = [str(s) for s in input().split()] arr1 = conv_output(bubble_sort(n, conv_input(arr1))) print(' '.join(map(str, arr1))) print('Stable') arr2 = conv_output(selection_sort(n, conv_input(arr2))) print(' '.join(map(str, arr2))) print(is_stable(arr1, arr2))
1
26,517,863,080
null
16
16
def main(): a,b,c = map(int,input().split()) if a == b and b==c : print("No") return if a != b and b != c and a != c: print("No") return print("Yes") return if __name__ == "__main__": main()
N = int(input()) S = list(map(int,input().split())) if N < 3: print(0) exit(0) import itertools as it per = it.combinations(S,r=3) cnt = 0 for r in per: a,b,c = r if a == b or b == c or a == c: continue if a+b > c and b+c > a and a+c > b: #print(a,b,c) cnt += 1 print(cnt)
0
null
36,764,377,220,250
216
91
import math A, B, H, M = map(int, input().split(' ')) deg = abs(30 * H + 0.5 * M - 6 * M) if deg >180: deg = 360 - deg deg = math.radians(deg) print(math.sqrt((B - A * math.cos(deg)) ** 2 + (A * math.sin(deg)) ** 2))
import math x = list(map(int,input().split())) A = x[0] B = x[1] H = x[2] M = x[3] y = 2*math.pi*((H*60+M)/720-M/60) z = math.sqrt(A**2+B**2-2*A*B*math.cos(y)) print(z)
1
20,210,060,022,978
null
144
144
S = int(input()) h = int(S/3600) m = int((S- h*3600)/60) sec = S- h*3600-m*60; print(str(h)+":"+str(m)+":"+str(sec))
S = int(input()) h = S // (60 * 60) m = (S % (60*60)) // 60 s = S % 60 # セパレータ(sep)は":" を用いる print(h, m, s, sep=":")
1
324,676,679,590
null
37
37
n=int(input()) a=list(map(int,input().split())) l=[] for i,x in enumerate(a): l.append([x,i]) l.sort(reverse=True) cnt=1 dp=[[0]*(n+1) for _ in range(n+1)] for i,j in l: for x in range(cnt+1): if x==0: dp[x][cnt-x]=dp[x][cnt-x-1]+i*(n-1-(cnt-x-1)-j) elif x==cnt: dp[x][cnt-x]=dp[x-1][cnt-x]+i*(j-x+1) else: dp[x][cnt-x]=max(dp[x-1][cnt-x]+i*(j-x+1),dp[x][cnt-x-1]+i*(n-1-(cnt-x-1)-j)) cnt+=1 ans=0 for i in range(n+1): ans=max(ans,dp[i][n-i]) print(ans)
from collections import deque K=int(input()) queue=deque(list(range(1,10))) for i in range(K): k=queue.popleft() mod=k%10 for diff in range(mod-1,mod+2): if diff<0 or 9<diff: continue queue.append(10*k+diff) print(k)
0
null
36,837,814,080,422
171
181
n,m = map(int,input().split()) *hl, = map(int,input().split()) ansl = [1]*n for _ in [0]*m: a,b = map(int,input().split()) if hl[a-1] > hl[b-1]: ansl[b-1] = 0 elif hl[a-1] < hl[b-1]: ansl[a-1] = 0 else: ansl[a-1] = 0 ansl[b-1] = 0 print(sum(ansl))
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools import time,random sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 mod2 = 998244353 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def pe(s): return print(str(s), file=sys.stderr) def JA(a, sep): return sep.join(map(str, a)) def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a) def main(): n,u,v = LI() ab = [LI() for _ in range(n-1)] e = collections.defaultdict(list) for a,b in ab: e[a].append(b) e[b].append(a) def search(s, ea): d = collections.defaultdict(lambda: inf) d[s] = 0 q = [] heapq.heappush(q, (0, s)) v = collections.defaultdict(bool) for u in ea: v[u] = True while len(q): k, u = heapq.heappop(q) if v[u]: continue v[u] = True for uv in e[u]: if v[uv]: continue vd = k + 1 if d[uv] > vd: d[uv] = vd heapq.heappush(q, (vd, uv)) return d du = search(u, []) dv = search(v, []) r = 0 for i in range(n): if du[v] - du[u] < 3: break r += 1 for c in e[u]: if dv[u] > dv[c]: u = c break for c in e[v]: if du[v] > du[c]: v = c break ea = [] t = dv[u] for c in range(1, n+1): if dv[c] < t: ea.append(c) d = search(u, ea) m = max(d.values()) r += m s = t - dv[v] if s > 1: r += 1 return r print(main())
0
null
71,291,664,185,430
155
259
i=lambda:int(input());c=max(i(),i());print(0--i()//c)
#ARC162 C:Sum of gcd of Tuples(Easy) import math import numpy as np import itertools k = int(input()) ans = 0 if k == 1: ans = 1 else: for i in range(1,k+1): for j in range(1,k+1): a = math.gcd(i,j) for k in range(1,k+1): b = math.gcd(a,k) ans += b print(ans)
0
null
62,306,075,577,010
236
174
n = int(input()) answer = 0 for idx1 in range(1, n+1): for idx2 in range(1, ((n+1) // idx1) + 1): c = n - (idx1 * idx2) if 1 <= c < n: answer += 1 print(answer)
A,B,C,D=map(int,input().split()) ans=0 while 1: C-=B if C<=0: ans=1 break A-=D if A<=0: break if ans==1: print("Yes") else: print("No")
0
null
16,081,128,001,910
73
164
a,b = map(int,input().split()) x = '' if a < b: x = ' < ' elif a > b: x = ' > ' else: x = ' == ' print('a'+x+'b')
# C gacha N = int(input()) goods = set() cnt = 0 for i in range(N): S = input() if S not in goods: goods.add(S) cnt += 1 print(cnt)
0
null
15,247,988,991,580
38
165
text = raw_input() t = list(text) for i in range(len(t)): if t[i].isupper(): t[i] = t[i].lower() elif t[i].islower(): t[i] = t[i].upper() print "".join(t)
a = str(input()) a = a.swapcase() print(a)
1
1,524,102,893,600
null
61
61
while True: num = input() if num == '0': break cnt = 0 for i in num: cnt += int(i) print(cnt)
import numpy as np def main(): N, K = map(int, input().split()) A = list(map(int, input().split())) mod = int(1e9+7) p = [] m = [] for a in A: if a >= 0: p.append(a) else: m.append(a) p.sort(reverse=True) m.sort(reverse=False) ans = 1 if sum(np.sign(A)) == -N and K%2 == 1: A = sorted(A, reverse=True) for i in range(K): ans = (ans*A[i])%mod print(ans) return if N == K: for i in range(K): ans = (ans*A[i])%mod print(ans) return m_pair = [] p_pair = [] if K%2 == 1: ans *= p.pop(0)%mod for i in range(0, len(m), 2): if i+1 < len(m): m_pair.append(m[i]*m[i+1]) # else: # m_pair.append(m[i]) for i in range(0, len(p), 2): if i+1 < len(p): p_pair.append(p[i]*p[i+1]) else: p_pair.append(p[i]) pairs = m_pair[:] pairs.extend(p_pair) pairs.sort(reverse=True) for i in range(K//2): ans = (ans*pairs[i])%mod print(ans) main()
0
null
5,546,052,787,814
62
112
n=list(map(int,input().split())) p=sum(n) f=15 ans=(f-p) print(ans)
x = input().split() print(x.index('0') + 1)
1
13,328,653,139,890
null
126
126
A,B,C=map(int,input().split()) K=int(input()) i=0 while i<K: if A>=B: i+=1 B*=2 else: break while i<K: if B>=C: i+=1 C*=2 else: break print('YNeos'[(A>=B)or(B>=C)::2])
n,m=map(int,raw_input().split()) c=map(int,raw_input().split()) dp=[i for i in range(n+1)] c.remove(1) c.sort() for coin in c: for x in range(1,n+1): if x-coin>=0: dp[x]=min(dp[x],dp[x-coin]+1) print dp[n]
0
null
3,510,936,450,640
101
28
x=list(map(int,input().split())) if x[0]>x[2]: print(str(x[0]-x[2])+" "+str(x[1])) elif x[0]+x[1]>x[2]: print("0"+" "+str(x[0]+x[1]-x[2])) else: print("0"+" "+"0")
n=int(input()) print((n*n*n)/27)
0
null
75,902,000,779,460
249
191
s=input() t=input() ls=len(s) lt=len(t) ans=lt for i in range(0,ls-lt+1): count = 0 for j in range(lt): if s[i+j]!=t[j]: count+=1 if count<ans: ans=count print(ans)
#177B S=input() T=input() Ss=[] Ts=[] Us=[] Vs=[] len_T=len(T) len_S=len(S) s=0 #初期配列を作成 for t in range(len_T): Ts.append(T[t]) Ss.append(S[t]) #一致していない箇所の個数を数え、記録 for t in range(len_T): Us.append(Ts[t]!=Ss[t]) Vs.append(sum(Us)) for s in range(1,len_S-len_T+1): #Ss配列をずらす Ss.append(S[len_T+s-1]) Ss.remove(S[s-1]) #Usをリセットして、一致していない箇所の個数を数え、記録 Us=[] for t in range(len(T)): Us.append(Ts[t]!=Ss[t]) Vs.append(sum(Us)) print(str(min(Vs)))
1
3,679,282,759,228
null
82
82
a, b = map(int, raw_input().split(" ")) if (a == b) : print "a == b" elif (a > b) : print "a > b" elif (a < b) : print "a < b"
while True: x = [int(z) for z in input().split(" ")] if x[0] == 0 and x[1] == 0: break for h in range(0,x[0]): dot = h % 2 for w in range(0,x[1]): if (dot == 0 and w % 2 == 0) or (dot == 1 and w % 2 == 1): print("#", end="") else: print(".", end="") print("\n", end="") print("")
0
null
610,041,452,032
38
51
l=map(int,raw_input().split()) W=l[0] H=l[1] x=l[2] y=l[3] r=l[4] if x>=r and y>=r and x+r<=W and y+r<=H: print 'Yes' else: print 'No'
X = int(input()) money = 100 time = 0 while money < X: time += 1 money = money * 101 // 100 print(time)
0
null
13,780,149,094,656
41
159
#!/usr/bin/env python # -*- coding: utf-8 -*- """ input: 6 1 2 2 3 2 2 3 4 3 1 5 4 1 6 5 1 6 6 0 output: 1 1 12 2 2 11 3 3 8 4 9 10 5 4 7 6 5 6 """ import sys UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2 def dfs(v_init): global timer # init the first node of overall graph iterations(times >= 1) stack = list() stack.append(v_init) d_time[v_init] += timer # init end while stack: current = stack[-1] v_table = adj_table[current] visited[current] = VISITED_IN_STACK # if adj is None, current's adj(s) have been all visited adj = v_table.pop() if v_table else None if adj: if visited[adj] is UNVISITED: visited[adj] = VISITED_IN_STACK timer += 1 d_time[adj] += timer stack.append(adj) else: stack.pop() visited[current] = POPPED_OUT timer += 1 f_time[current] += timer return None def dfs_init(): global timer for v in range(v_num): if visited[v + 1] == UNVISITED: dfs(v + 1) timer += 1 if __name__ == '__main__': _input = sys.stdin.readlines() v_num = int(_input[0]) vertices = map(lambda x: x.split(), _input[1:]) # config length = (v_num + 1) # stack = [] visited = [UNVISITED] * (v_num + 1) d_time, f_time = ([0] * (v_num + 1) for _ in range(2)) adj_table = tuple([] for _ in range(v_num + 1)) for v_info in vertices: v_index, adj_num, *adj_list = map(int, v_info) # assert len(adj_list) == adj_num adj_table[v_index].extend(sorted(adj_list, reverse=True)) # timing start from 1 timer = 1 dfs_init() for index, time_info in enumerate(zip(d_time[1:], f_time[1:]), 1): print(index, *time_info)
from collections import deque n = int(raw_input()) d = [0] * n f = [0] * n M = [[0]*n for _ in xrange(n)] color = [0] * n tt = 0 WHITE = 0 GRAY = 1 BLACK = 2 nt = [0] * n def next(u): for v in xrange(nt[u],n): nt[u] = v + 1 if M[u][v] == 1: return v return -1 def dfs_visit(r): global tt S = deque([]) S.append(r) color[r] = GRAY tt += 1 d[r] = tt while len(S) > 0: u = S[len(S)-1] v = next(u) if v != -1: if color[v] == WHITE: color[v] = GRAY tt += 1 d[v] = tt S.append(v) else: S.pop() color[u] = BLACK tt += 1 f[u] = tt return 0 def dfs(): for u in xrange(n): if color[u] == WHITE: dfs_visit(u) for u in xrange(n): print "{} {} {}".format(u+1, d[u], f[u]) return 0 def main(): for i in xrange(n): a = map(int, raw_input().split()) u = a[0]-1 k = a[1] for j in xrange(k): v = a[j+2] - 1 M[u][v] = 1 dfs() return 0 main()
1
2,583,591,516
null
8
8
import sys import time import math import itertools as it def inpl(): return list(map(int, input().split())) st = time.perf_counter() # ------------------------------ N, M = inpl() H = inpl() dp = [True] * N for _ in range(M): A, B = inpl() if H[A-1] > H[B-1]: dp[B-1] = False elif H[A-1] < H[B-1]: dp[A-1] = False else: dp[A-1] = False dp[B-1] = False ans = 0 for i in dp: if i: ans += 1 print(ans) # ------------------------------ ed = time.perf_counter() print('time:', ed-st, file=sys.stderr)
def main(): a = int(input()) print((a+a**2+a**3)) if __name__ == "__main__": main()
0
null
17,643,539,957,934
155
115
# -*- coding: utf-8 -*- N=int(input()) x,y=map(int,input().split()) R=x L=x U=y B=y P=[(x,y)] for i in range(1,N): x,y=map(int,input().split()) P.append((x,y)) if R<x:R=x if L>x:L=x if U<y:U=y if B>y:B=y p=P[0] UR=p dUR=abs(R-p[0])+abs(U-p[1]) UL=p dUL=abs(L-p[0])+abs(U-p[1]) BR=p dBR=abs(R-p[0])+abs(B-p[1]) BL=p dBL=abs(L-p[0])+abs(B-p[1]) for p in P[1:]: if dUR>abs(R-p[0])+abs(U-p[1]): UR=p dUR=abs(R-p[0])+abs(U-p[1]) if dUL>abs(L-p[0])+abs(U-p[1]): UL=p dUL=abs(L-p[0])+abs(U-p[1]) if dBR>abs(R-p[0])+abs(B-p[1]): BR=p dBR=abs(R-p[0])+abs(B-p[1]) if dBL>abs(L-p[0])+abs(B-p[1]): BL=p dBL=abs(L-p[0])+abs(B-p[1]) ans=abs(UR[0]-BL[0])+abs(UR[1]-BL[1]) ans2=abs(UL[0]-BR[0])+abs(UL[1]-BR[1]) if ans2>ans: ans=ans2 print(ans)
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 )
0
null
27,125,791,008,778
80
196
[X, Y] = [int(i) for i in input().split()] if 2*X <= Y and Y <= 4*X and Y % 2 == 0: print("Yes") else: print("No")
n=list(input()) #print(n) if n[2]==n[3] and n[4]==n[5]: #if n[2]!=n[4]: print('Yes') else: print('No')
0
null
27,919,943,681,920
127
184
nd = list(map(int, input().split())) N = nd[0] D = nd[1] ans = 0 for i in range(N): x = list(map(int, input().split())) if x[0] ** 2 + x[1] ** 2 <= D ** 2: ans += 1 print(ans)
import sys i,j = input().split() matrixa = [] for _ in range(int(i)): matrixa += [[int(n) for n in sys.stdin.readline().split()]] matrixb =[ int(num) for num in sys.stdin.readlines() ] matrixc = [ 0 for _ in range(int(i))] for n in range(int(i)): for a,b in zip(matrixa[n],matrixb): matrixc[n] += a*b for c in matrixc: print(c)
0
null
3,501,025,807,228
96
56
def is_kaibun(string): isk = True length = len(string) for i in range(length // 2): if string[i] != string[length - 1 - i]: isk = False break return isk s = input() len_s = len(s) if is_kaibun(s[0:(len_s // 2)]) and is_kaibun(s): print('Yes') else: print('No')
s = input() n = len(s) s_ = s[:(n-1)//2] if s == s[::-1] and s_ == s_[::-1]: print('Yes') else: print('No')
1
46,264,780,070,018
null
190
190
# Aizu Problem 0000: QQ # import sys, math, os # read input: #PYDEV = os.environ.get('PYDEV') #if PYDEV=="True": # sys.stdin = open("sample-input2.txt", "rt") for i in range(1, 10): for j in range(1, 10): print("%dx%d=%d" % (i, j, i*j))
class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def size(self, x): return -self.parents[self.find(x)] def same(self, x, y): return self.find(x) == self.find(y) def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def group_count(self): return len(self.roots()) def all_group_members(self): return {r: self.members(r) for r in self.roots()} def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) def main(): N, M, K = map(int, input().split()) uf = UnionFind(N) friends = [0 for _ in range(N)] for _ in range(M): a, b = map(int, input().split()) a, b = a - 1, b - 1 uf.union(a, b) friends[a] += 1 friends[b] += 1 blocks = [0 for _ in range(N)] for _ in range(K): c, d = map(int, input().split()) c, d = c - 1, d - 1 if uf.same(c, d): blocks[c] += 1 blocks[d] += 1 for i in range(N - 1): ans = uf.size(i) - 1 - friends[i] - blocks[i] print(str(ans) + " ", end="") ans = uf.size(N - 1) - 1 - friends[N - 1] - blocks[N - 1] print(ans) if __name__ == '__main__': main()
0
null
30,752,555,189,320
1
209
while True: h, w =map(int,input().split()) odd = '#.'*300 even = '.#'*300 if h == 0 and w==0: break for i in range(h): if i%2 ==0: out = odd[:w] else: out= even[:w] print(out) print()
while True: H, W = [int(x) for x in input().split()] if H == W == 0: break for i in range(H): cnt = i % 2 for j in range(W): if (cnt % 2) == 0: print('#', end="") else: print('.', end="") cnt += 1 print() print()
1
888,055,484,412
null
51
51
import itertools H,W,K=map(int,input().split()) C=[input() for i in range(H)] ans=0 for paint_H in itertools.product([0,1], repeat=H): for paint_W in itertools.product([0,1], repeat=W): cnt=0 for i in range(H): for j in range(W): if paint_H[i]==0 and paint_W[j]==0 and C[i][j]=="#": cnt+=1 if cnt==K: ans+=1 print(ans)
h,w,k = map(int, input().split()) grid = [input() for _ in range(h)] ans = 0 for i in range(2**h): for j in range(2**w): count = 0 for m in range(h): for l in range(w): if (i>>m)&1==0 and (j>>l)&1==0 and grid[m][l] == "#": count+=1 if count == k: ans+=1 print(ans)
1
8,938,633,189,952
null
110
110
import sys input = sys.stdin.readline n = int(input()) a_lst = list(map(int, input().split())) a_lst.sort() if a_lst[0] == 0: answer = 0 else: answer = 1 for i in range(n): a = a_lst[i] answer *= a if answer > 10 ** 18: answer = -1 break print(answer)
import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') sys.setrecursionlimit(10 ** 9) INF = 10 ** 19 MOD = 10 ** 9 + 7 a, v = MAP() b, w = MAP() t = INT() if a == b: YES() exit() if w >= v: NO() exit() diff = v - w dist = abs(a-b) if diff*t >= dist: YES() else: NO()
0
null
15,619,658,481,532
134
131
X = input() l = len(X) m = l//2 if (X == 'hi'*m): print("Yes") else: print("No")
if __name__ == '__main__': # ??????????????\??? S_size = int(input()) S = set([int(x) for x in input().split(' ')]) T_size = int(input()) T = set([int(x) for x in input().split(' ')]) # S = [1, 2, 3, 4, 5, 1] # T = set([3, 4, 1]) # ???????????? U = S.intersection(T) # ??????????????? print('{0}'.format(len(U)))
0
null
26,604,525,799,322
199
22
import sys import bisect def input(): return sys.stdin.readline().rstrip() def main(): N = int(input()) A = [] B = [] for i in range(N): a, b = map(int, input().split()) A.append(a) B.append(b) pass A.sort() B.sort() if N % 2 == 0: n = N // 2 mini = (A[n]+A[n-1]) /2 maxi = (B[n]+B[n-1]) /2 print(int((maxi-mini)*2)+1) else: n = N//2 mini = A[n] maxi = B[n] print(maxi-mini+1) if __name__ == "__main__": main()
N = int(input()) AB = [[int(i) for i in input().split()] for _ in range(N)] A, B = map(list, zip(*AB)) A.sort() B.sort() if N % 2 == 0 : print(B[N//2] + B[N//2-1] - A[N//2] - A[N//2-1] + 1) else : print(B[N//2] - A[N//2] + 1)
1
17,267,176,916,420
null
137
137
n=int(input()) alist=list(map(int,input().split())) counter = 0 for i , a in enumerate(alist): if (i+1)%2 == 1 and a % 2 == 1: counter += 1 print(counter)
N = int(input()) A = list(map(int,input().split())) res = 0 for i,a in enumerate(A): idx = i+1 if idx%2==1 and a%2==1: res += 1 print(res)
1
7,820,008,865,236
null
105
105
import re print(re.sub(r"\?","D",input()))
import sys RS = lambda: sys.stdin.readline()[:-1] RI = lambda x=int: x(RS()) RA = lambda x=int: map(x, RS().split()) RSS = lambda: RS().split() def solve(): ans = [] for i in s: if i == "P": ans.append("P") else: ans.append("D") print("".join(ans)) return s = RS() solve()
1
18,556,425,518,242
null
140
140
import sys readline = sys.stdin.readline MOD = 10 ** 9 + 7 INF = float('INF') sys.setrecursionlimit(10 ** 5) def main(): N = int(readline()) P = list(map(int, readline().split())) cur = N + 1 ans = 0 for x in P: if cur > x: ans += 1 cur = x print(ans) if __name__ == '__main__': main()
n = int(input()) p = list(map(int, input().split())) ans = 0 m = p[0] for i in p: if m >= i: ans += 1 m = i print(ans)
1
85,537,708,355,838
null
233
233
n = int(input()) d = {} for i in range(n): a = input() if a not in d: d[a] = 1 else: d[a] += 1 dsorted = sorted(d.items(), key=lambda x:x[1], reverse=True) name = [] cnt = dsorted[0][1] for i in dsorted: if i[1] == cnt: name.append(i[0]) else: break name.sort() for i in name: print(i)
N = int(input()) S = {} c = 0 for _ in range(N): s = input() if s not in S: S[s] = 1 else: S[s] += 1 c = max(c, S[s]) ans = [] for k, v in S.items(): if v == c: ans.append(k) ans.sort() for a in ans: print(a)
1
70,063,418,621,782
null
218
218
n = int(input()) AC,WA,TLE,RE = 0,0,0,0 for x in range(n): s = input() if s == 'AC': AC = AC + 1 elif s == 'WA': WA = WA + 1 elif s == 'TLE': TLE = TLE + 1 elif s == 'RE': RE = RE + 1 print('AC x ' + str(AC)) print('WA x ' + str(WA)) print('TLE x ' + str(TLE)) print('RE x ' + str(RE))
a=int(input()) count1=0 count2=0 count3=0 count4=0 for i in range(a): b=str(input()) count=0 if b=='AC': count1+=1 if b=='RE': count2+=1 if b=='TLE': count3+=1 if b=='WA': count4+=1 print('AC x ',end='') print(count1) print('WA x ',end='') print(count4) print('TLE x ',end='') print(count3) print('RE x ',end='') print(count2)
1
8,576,487,188,652
null
109
109
def resolve(): N,K,C = map(int,input().split()) S=input() dpt1=[0]*K dpt2=[0]*K pnt = 0 for i in range(K): while S[pnt]=="x": pnt+=1 dpt1[i]=pnt pnt += C+1 pnt = N-1 for i in range(K-1,-1,-1): while S[pnt] == "x": pnt -=1 dpt2[i]=pnt pnt-=C+1 for a,b in zip(dpt1,dpt2): if a == b: print(a+1) if __name__ == "__main__": resolve()
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,K,C=mi() S=list(input()) ok,ng = "o","x" OK = [] for i in range(N): if S[i] == ok: OK.append(i+1) # 1-index greeds = [OK[0]] for i in range(1,len(OK)): x = OK[i] if x - greeds[-1] > C: greeds.append(x) if len(greeds) > K: break inv_greeds = [OK[-1]] inv_OK = OK[::-1] for i in range(1,len(OK)): x = inv_OK[i] if -x + inv_greeds[-1] > C: inv_greeds.append(x) if len(inv_greeds) > K: break if len(greeds) < K or len(inv_greeds) < K: exit() greeds = greeds[:K] inv_greeds = inv_greeds[:K][::-1] # print(greeds,inv_greeds) for i in range(len(greeds)): if greeds[i] == inv_greeds[i]: print(greeds[i]) if __name__ == "__main__": main()
1
40,737,687,290,560
null
182
182
n, m = map(int, input().split()) a = list(map(int, input().split())) total = 0 for i in range(m): total = total + a[i] if (n -total) < 0: print(-1) else: print(n - total)
N, M = map(int, input().split()) A = list(map(int, input().split())) assert len(A) == M # M個の宿題, それぞれAi日かかる yasumi = N - sum(A) if yasumi >= 0: print(yasumi) else: print(-1)
1
31,966,298,189,070
null
168
168
def main(): coordinates = list(map(float, input().split())) distance = ((coordinates[2] - coordinates[0])**2 + (coordinates[3] - coordinates[1])**2)**(1/2) print('{:.5f}'.format(distance)) if __name__ == '__main__': main()
# -*- coding: utf-8 -*- from sys import stdin import math # 0 0 1 1 A = list(map(float, stdin.readline().split())) x1, y1, x2, y2 = A[0], A[1], A[2], A[3] distance = math.sqrt(math.pow(x2-x1, 2) + math.pow(y2-y1,2)) print(format(distance,'.8f'))
1
159,125,619,554
null
29
29
# 入力 N = int(input()) A = list(map(int, input().split())) # 上限を決める NowNode = 2**0 NextNode = (NowNode - A[0])*2 UpperLimit = [0] * (N+1) UpperLimit[0] = 1 if A[0] == 1: if N == 0: print(1) exit() print(-1) exit() for d in range(1, N+1, 1): NowNode = NextNode NextNode = (NowNode - A[d]) * 2 UpperLimit[d] = NowNode # print(UpperLimit) UpperLimit[-1] = min(A[-1], UpperLimit[-1]) # 下から見ていく NowNode = A[-1] ans = 0 for d in range(N, -1, -1): PrevNode = NowNode if UpperLimit[d] < A[d]: print(-1) exit() if NowNode + A[d] <= UpperLimit[d]: NowNode += A[d] else: NowNode = UpperLimit[d] ans += NowNode # print(d, NowNode) print(ans)
N = int(input()) A = list(map(int, input().split())) if N == 0 and A[0] == 1: print(1) exit() if A[0] != 0: print(-1) exit() sum_leaf = sum(A) ans = 1 before_top = 1 for i in range(1, len(A)): if A[i] <= before_top*2: ans += min(sum_leaf, before_top*2) before_top = min(sum_leaf, before_top*2) - A[i] sum_leaf -= A[i] else: print(-1) exit() print(ans)
1
18,876,549,200,068
null
141
141
def main(): n = int(input()) s = list(map(int, input().split())) q = int(input()) t = list(map(int, input().split())) # 集合的なら # res = len(set(s) & set(p)) # print(res) # 線形探索なら cnt = 0 for i in t: if i in s: cnt += 1 print(cnt) if __name__ == '__main__': main()
import bisect N = int(input()) Kaijo = [1 for _ in range(N)] for i in range(2,N+1): Kaijo[-i] = Kaijo[1-i]*i #print(Kaijo) L = [i+1 for i in range(N)] P = list(map(int,input().split())) PN = 0 for i in range(N-1): k = bisect.bisect_left(L, P[i]) L.remove(P[i]) PN += k*Kaijo[i+1] #print(PN) L = [i+1 for i in range(N)] Q = list(map(int,input().split())) QN = 0 for i in range(N-1): k = bisect.bisect_left(L, Q[i]) L.remove(Q[i]) QN += k*Kaijo[i+1] ans = abs(PN-QN) print(ans)
0
null
50,097,090,714,430
22
246
#ABC170-A X = list(input().split()) for i in range(5): if X[i] == "0": print(i + 1)
# B z = list(map(int, input().split(" "))) maxnum = z[0]*z[2] for i in range(2): for j in range(2): x = z[i] y = z[j+2] prod = x*y # print(x, y, prod, maxnum, prod > maxnum) if prod > maxnum: maxnum = prod print(maxnum)
0
null
8,187,052,097,312
126
77
S = list(input()) N = len(S) K = int(input()) if len(set(S)) == 1: print((N*K)//2) exit() ans = 0 i = 0 while i < N-1: if S[i] == S[i+1]: ans += 1 i += 1 i += 1 if S[0] != S[N-1]: print(ans*K) exit() a = 1 while S[0] == S[a]: a += 1 b = 1 while S[N-1] == S[N-1-b]: b += 1 print(ans*K - (K-1)*(a//2 + b//2 - (a+b)//2))
def main(): S = input() K = int(input()) if len(set(S)) == 1: print((len(S) * K)//2) return result = 0 piyo = 0 hoge = S[0] huga = 1 first = 0 for s in S[1:]: if s == hoge: huga += 1 if huga % 2 == 0: piyo += 1 else: if first == 0: first = huga hoge = s huga = 1 if first == 0: first = huga if first % 2 == 1 and huga % 2 == 1 and S[0] == S[-1]: result += K - 1 print(piyo * K + result) main()
1
175,678,682,746,530
null
296
296
for i in range(1,10001): x = int(input()) if(x == 0): break print('Case ', i, ': ', x, sep='')
counter = 1 while True: x = int(input()) if x == 0: break else: print('Case', '{}{}{}'.format(counter, ': ', x)) counter += 1
1
487,619,292,838
null
42
42
n,m = map(int,input().split()) l = sum(map(int,input().split())) print(max(-1, n-l))
N, M =map(int,input().split()) A = list(map(int, input().split())) # x = 宿題をする日の合計 x = sum(A) if N >= x: print(N - x) else: print("-1")
1
31,840,792,056,462
null
168
168
def main(): N,M,K=map(int,input().split()) MOD=998244353 E=0 n_=1 for i in range(1,N): n_=(n_*i)%MOD nr_ = 1 nr_array=[] for i in range(1,N-1): nr_ = (nr_ * i) % MOD nr_array.append(nr_) m=1 Mk_array=[1] for i in range(1,N): m=(m*(M-1))%MOD Mk_array.append(m) r_=1 for i in range(0,K+1): if i!=0 and i!=N-1: r_ = (r_ * i) % MOD nr_=nr_array.pop() power_r=pow(r_,MOD-2,MOD) power_nr=pow(nr_,MOD-2,MOD) Mk=Mk_array.pop() if i!=0 and i!=N-1: E+=(n_*power_r*power_nr*Mk)%MOD else: E+=Mk%MOD res=(M*E)%MOD print(res) if __name__=="__main__": main()
def get(n): for i in range(-1000,1001): for j in range(-1000,1001): if(i**5-j**5==n): print(i,j) return n=int(input()) get(n)
0
null
24,541,574,297,150
151
156
n = int(input()) result = '' for i in range(3, n+1): if (i % 3 == 0) or (i % 10 == 3) or ('3' in str(i)): result += (' ' + str(i)) print(result)
N = int(input()) S, T = (x for x in input().split()) ans = '' for i in range(N): ans += (S[i] + T[i]) print(ans)
0
null
56,304,988,181,758
52
255
from collections import deque import copy H, W = map(int, input().split()) S = [input() for _ in range(H)] def warshall_floyd(d): #d[i][j]: iからjへの最短距離 for k in range(H*W): for i in range(H*W): for j in range(H*W): d[i][j] = min(d[i][j],d[i][k] + d[k][j]) return d d = [[float("inf")]*(H*W) for i in range(H*W)] #d[u][v] : 辺uvのコスト(存在しないときはinf) for i in range(H-1): for j in range(W-1): if S[i][j] == ".": if S[i+1][j] == ".": d[i*W+j][(i+1)*W+j] = 1 d[(i+1)*W+j][i*W+j] = 1 if S[i][j+1] == ".": d[i*W+j][i*W+(j+1)] = 1 d[i*W+(j+1)][i*W+j] = 1 for i in range(W-1): if S[H-1][i] == "." and S[H-1][i+1] == ".": d[(H-1)*W+i][(H-1)*W+(i+1)] = 1 d[(H-1)*W+(i+1)][(H-1)*W+i] = 1 for i in range(H-1): if S[i][W-1] == "." and S[i+1][W-1] == ".": d[i*W+(W-1)][(i+1)*W+(W-1)] = 1 d[(i+1)*W+(W-1)][i*W+(W-1)] = 1 for i in range(H*W): d[i][i] = 0 #自身のところに行くコストは0 ans = 0 data = warshall_floyd(d) for items in data: for item in items: if item != float("inf"): ans = max(ans, item) print(ans)
S=input() Q=int(input()) reverse=False front="" rear="" for _ in range(Q): inp=input() if inp[0]=="1": reverse= not reverse elif inp[0]=="2": if (inp[2]=="1" and not reverse) or (inp[2]=="2" and reverse): front=inp[4]+front else: rear=rear+inp[4] ans=front+S+rear if reverse: ans=ans[::-1] print(ans)
0
null
76,146,747,149,500
241
204
def main(): H = int(input()) W = int(input()) N = int(input()) print((N-1)//max(H,W) + 1) if __name__ == '__main__': main()
H = int(input()) W = int(input()) N = int(input()) m = max(H,W) if N%m != 0: ans = N/m +1 else: ans = N/m print(int(ans))
1
88,344,612,962,528
null
236
236
X=int(input()) x=0 for j in range(X,10**6): for i in range(j-1,0,-1): if i==1: print(j) x=1 elif j%i==0: break if x==1: break
from math import ceil def point(x,y,r,s,p): if y == 'r': y = p if y == 's': y = r if y == 'p': y = s return ceil(x/2) * y n,k = map(int,input().split()) r,s,p = map(int,input().split()) t = list(input()) ans = 0 for _ in range(k): l = t[_::k] x = 1 y = l[0] for i in l[1:]: if i != y: ans += point(x,y,r,s,p) x = 1 y = i else: x += 1 ans += point(x,y,r,s,p) print(ans)
0
null
106,188,128,203,420
250
251
import sys alpha = 'abcdefghijklmnopqrstuvwxyz' m = {k:0 for k in alpha} q = '' for line in sys.stdin: q += line for s in q: s = s.lower() if s in m: m[s] += 1 for s in alpha: print('%s : %d' % (s, m[s]))
N,K=map(int,input().split()) m=N//K print(min(abs(N-m*K),abs(N-(m+1)*K)))
0
null
20,619,277,043,850
63
180
from collections import deque n,m = map(int, input().split()) dis = [n+2]*(n) dis[0] = 0 near = [[] for _ in range(n)] mark = [-1]*(n) mark[0] = 0 que = deque() for _ in range(m): a,b = map(int, input().split()) a -= 1 b -= 1 near[a].append(b) near[b].append(a) if a==0: que.appendleft(b) mark[b] = 0 dis[b] = 1 if b==0: que.appendleft(a) mark[a] = 0 dis[a] = 1 while que: i = que.popleft() for j in near[i]: if dis[i]+1<dis[j]: dis[j] = dis[i]+1 mark[j] = i que.append(j) if n+2 not in dis: print('Yes') for i in mark[1:]: print(i+1) else: print('No')
def insertion_sort(array, g, result): for i in range(g, len(array)): v = array[i] j = i - g while j >= 0 and array[j] > v: array[j + g] = array[j] j -= g result['count'] += 1 A[j + g] = v def g_gene(n): yield 1 for i in range(2, n): x = int((3 ** i - 1) / 2) if x < n: yield x else: raise StopIteration() def shell_sort(array, result): result['count'] = 0 G = list(reversed(list(g_gene(len(array))))) m = len(G) result['G'] = G result['m'] = m for i in range(m): insertion_sort(array, G[i], result) if __name__ == '__main__': import sys n = int(sys.stdin.readline()) A = [] for _ in range(n): A.append(int(sys.stdin.readline())) result = {} shell_sort(A, result) print(result['m']) print(' '.join(map(str, result['G']))) print(result['count']) for a in A: print(a)
0
null
10,335,444,588,664
145
17
import math h, a = map(int, input().split()) print(math.ceil(h/a))
import sys from itertools import count H, A = map(int, next(sys.stdin.buffer).split()) for i in count(1): H -= A if H <= 0: break print(i)
1
77,068,509,500,230
null
225
225
H,A=map(int,input().split()) print((H-1)//A+1)
import sys sys.setrecursionlimit(10 ** 9) # input = sys.stdin.readline #### def int1(x): return int(x) - 1 def II(): return int(input()) def MI(): return map(int, input().split()) def MI1(): return map(int1, input().split()) def LI(): return list(map(int, input().split())) def LI1(): return list(map(int1, input().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def MS(): return input().split() def LS(): return list(input()) def LLS(rows_number): return [LS() for _ in range(rows_number)] def printlist(lst, k=' '): print(k.join(list(map(str, lst)))) INF = float('inf') # from math import ceil, floor, log2 # from collections import deque # from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations # from heapq import heapify, heappop, heappush import numpy as np # cumsum # from bisect import bisect_left, bisect_right def solve(): H, W, K = MI() G = np.array(LLS(H)) # print(G) ans = np.zeros((H, W), np.int) i = 0 cnt = 0 num = 1 for h in range(H): g = G[h] if '#' in g: cnt += 1 if cnt == 2: # print('tmp', i, h, cnt,) l = h-i c2 = 0 for w in range(W): gw = G[i:h, w] # print(gw) if '#' in gw: c2 += 1 if c2 == 2: num += 1 c2 = 1 for j in range(l): ans[i+j, w] = num num += 1 i = h cnt = 1 tmp = [] # print(i, h) # print('tmp', i, h, cnt, ) c2 = 0 for w in range(W): gw = G[i:h+1, w] # print(gw) if '#' in gw: c2 += 1 if c2 == 2: num += 1 c2 = 1 for j in range(h+1-i): ans[i + j, w] = num for a in ans: print(*a) if __name__ == '__main__': solve()
0
null
110,525,980,596,330
225
277
N,K = map(int,input().split()) p = list(map(int,input().split())) l = [] for i in p: l.append((1/2*i*(i+1))/i) s = [0]*len(l) s[0] = l[0] for i in range(1,len(l)): s[i] = s[i-1]+l[i] ans = 0 for i in range(K,len(s)): ans = max(ans,s[i]-s[i-K]) if N == K: print(max(s)) exit() print(ans)
N,K = map(int,input().split()) P = list(map(int,input().split())) # 累積和 s = [0] * (N+1) for i in range(N):# O(N) s[i+1] = s[i] + P[i] # [j,j+K) の和の最大値と j を保持 m = 0 midx = 0 for j in range(N-K+1):# O(N) v = s[j+K] - s[j] if v > m: m = v midx = j E = 0 for k in range(midx,midx+K):# O(K) x = P[k] E += (1/x)*(x*(x+1)/2) print(E)
1
75,072,989,877,160
null
223
223
N,K=list(map(int, input().split())) A=[0]*(N+1) for _ in range(K): k=int(input()) a=list(map(int, input().split())) for i in a: A[i]+=1 c=0 for i in range(1,N+1): c+=not A[i] print(c)
n, m = map(int, input().split()) h = list(map(int, input().split())) to = [[] for i in range(n)] for i in range(m): a, b = map(int, input().split()) to[a - 1] += [b - 1] to[b - 1] += [a - 1] print(sum(to[j] == [] or h[j] > max(h[i] for i in to[j]) for j in range(n)))
0
null
24,917,075,891,968
154
155
N,K=map(int,input().split()) r,s,p=map(int,input().split()) S=input() li=[1]*(K) ans=[0,0,0] for i in range(N-K): if S[i]==S[i+K]: li[i%K]+=1 else: if S[i]=="r": ans[0]+=(li[i%K]+1)//2 if S[i]=="s": ans[1]+=(li[i%K]+1)//2 if S[i]=="p": ans[2]+=(li[i%K]+1)//2 li[i%K]=1 for j in range(N-K,N): if S[j]=="r": ans[0]+=(li[j%K]+1)//2 if S[j]=="s": ans[1]+=(li[j%K]+1)//2 if S[j]=="p": ans[2]+=(li[j%K]+1)//2 print(p*ans[0]+r*ans[1]+s*ans[2])
from math import gcd, sqrt from functools import reduce n, *A = map(int, open(0).read().split()) def f(A): sup = max(A)+1 table = [i for i in range(sup)] for i in range(2, int(sqrt(sup))+1): if table[i] == i: for j in range(i**2, sup, i): table[j] = i D = set() for a in A: while a != 1: if a not in D: D.add(a) a //= table[a] else: return False return True if reduce(gcd, A) == 1: if f(A): print('pairwise coprime') else: print('setwise coprime') else: print('not coprime')
0
null
55,758,066,379,820
251
85
n,m = map(int,input().split()) ans = 0 if n > 1: ans += n * (n -1) / 2 if m > 1: ans += m *(m - 1) / 2 print(int(ans))
import itertools import functools import math from collections import Counter from itertools import combinations N,M=map(int,input().split()) ans = 0 if N >= 2: ans += len(list(itertools.combinations(range(N), 2))) if M >= 2: ans += len(list(itertools.combinations(range(M), 2))) print(ans)
1
45,795,672,767,460
null
189
189
import math a, b, h, m = map(int, input().split()) minute = 60 * h + m argA = minute / 720 * 2 * math.pi argB = minute / 60 * 2 * math.pi a_x = a * math.cos(argA) a_y = a * math.sin(argA) b_x = b * math.cos(argB) b_y = b * math.sin(argB) d = math.sqrt((a_x - b_x) ** 2 + (a_y - b_y) ** 2) print(d)
a1 = list(map(int,input().split())) a2 = list(map(int,input().split())) a3 = list(map(int,input().split())) ans = "No" n = int(input()) for i in range(n): p = int(input()) if a1.count(p)>0: a1[a1.index(p)]=-1 if a2.count(p)>0: a2[a2.index(p)]=-1 if a3.count(p)>0: a3[a3.index(p)]=-1 if max(a1)==-1 or max(a2)==-1 or max(a3)==-1: ans="Yes" if (a1[0]==-1 and a2[0]==-1 and a3[0]==-1) or (a1[1]==-1 and a2[1]==-1 and a3[1]==-1) or ((a1[2]==-1 and a2[2]==-1 and a3[2]==-1)): ans="Yes" if (a1[0]==-1 and a2[1]==-1 and a3[2]==-1) or (a1[2]==-1 and a2[1]==-1 and a3[0]==-1) : ans="Yes" print(ans)
0
null
40,299,360,728,172
144
207
n = [int(x) for x in input().split()] for i in range(len(n)): if n[i] == 0: print(i + 1) break
digitsStr = input() honlist = ["2","4","5","7","9"] ponList = ["0","1","6","8"] if digitsStr[-1] == '3': print('bon') elif digitsStr[-1] in honlist: print('hon') elif digitsStr[-1] in ponList: print('pon')
0
null
16,374,604,023,348
126
142
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 = ni() s = input() def wid(w): return ord(w)-ord("A") def ws(wid): return chr(wid+ord("A")) ans = "" for i in range(len(s)): id = (wid(s[i])+n)%26 ans+=ws(id) print(ans)
def main(): n = int(input()) # n, k = map(int, input().split()) # h = list(map(int, input().split())) s = input() ans = "" for i in s: ans += chr((ord(i) - ord("A") + n)% 26 + ord("A")) print(ans) if __name__ == '__main__': main()
1
134,386,860,012,078
null
271
271
weekday = ['SUN', 'SAT', 'FRI', 'THU', 'WED', 'TUE', 'MON'] val = input() if val == 'SUN': print("7") else: print(weekday.index(val))
print(["SAT","FRI","THU","WED","TUE","MON","SUN"].index(input())+1)
1
133,604,686,942,118
null
270
270
from collections import deque q=deque() def MI(): return map(int, input().split()) N,M=MI() g=[[] for _ in range(N+1)] for _ in range(M): a,b=MI() g[a].append(b) g[b].append(a) check=[0]*(N+1) check[1]=1 ans=[0]*(N+1) q.append(1) while len(q)>0: v=q.popleft() for u in g[v]: if check[u]==0: check[u]=1 ans[u]=v q.append(u) print('Yes') for i in range(2,N+1): print(ans[i])
from collections import defaultdict import math def main(): n = int(input()) mod = 1000000007 zeroes = 0 counter = defaultdict(lambda: defaultdict(int)) for _ in range(n): x, y = [int(x) for x in input().split()] if x == y == 0: zeroes += 1 continue denominator = math.gcd(x, y) x, y = x // denominator, y // denominator if y < 0: # quadrant III, IV -> I, II x, y = -x, -y if x <= 0: # round 90° from quadrant II to I x, y = y, -x counter[(x, y)][1] += 1 else: counter[(x, y)][0] += 1 ans = 1 for v in counter.values(): now = 1 now += pow(2, v[0], mod) - 1 now += pow(2, v[1], mod) - 1 ans = ans * now % mod ans += zeroes ans -= 1 # choose no fish return ans % mod if __name__ == '__main__': print(main())
0
null
20,838,080,718,490
145
146
K = ord(input()) print(chr(K+1))
N, U, V = map(int, input().split()) edge = [[] for _ in range(N + 1)] for _ in range(N - 1): x, y = map(int, input().split()) edge[x].append(y) edge[y].append(x) def dist(s): dist = [-1] * (N + 1) node = [s] dist[s] = 0 while node: s = node.pop() for t in edge[s]: if dist[t] == -1: dist[t] = dist[s] + 1 node.append(t) return dist taka = dist(U) aoki = dist(V) can_go = taka[V] ans = 0 for t, a in zip(taka[1:], aoki[1:]): if t <= a: ans = max(ans, a - 1) print(ans)
0
null
104,398,747,808,348
239
259
from collections import defaultdict from collections import deque from collections import Counter import math def readInt(): return int(input()) def readInts(): return list(map(int, input().split())) def readChar(): return input() def readChars(): return input().split() s = list(input()) k = readInt() if len(Counter(s))==1: ans = k*len(s)//2 elif s[0]!=s[-1]: ans = 0 i = 0 l = 0 tmp = s[:]+["!"] d = [] while i<len(s): if tmp[i]==tmp[i+1]: i+=1 else: d.append(tmp[l:i+1]) l = i+1 i+=1 for i in d: ans+=len(i)//2 ans*=k else: ans = 0 i = 0 l = 0 tmp = s[:]+["!"] d = [] while i<len(s): if tmp[i]==tmp[i+1]: i+=1 else: d.append(tmp[l:i+1]) l = i+1 i+=1 for i in d[1:-1]: ans+=len(i)//2 ans*=k ans+=len(d[0])//2 ans+=len(d[-1])//2 ans+=(len(d[0])+len(d[-1]))//2*(k-1) print(ans)
n=int(input()) for m in range(1,n+1): if int(m*1.08)==n: print(m) break else:print(":(")
0
null
150,284,567,066,218
296
265
data = input().split() n = data[0] m = data[1] if n == m: print("Yes") else: print("No")
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(10 ** 7) n, m = map(int, readline().split()) if n == m: print('Yes') else: print('No')
1
83,469,969,723,172
null
231
231
def resolve(): N = int(input()) print(1000 * ((1000 + (N-1)) // 1000) - N) resolve()
import math N = int(input()) x = math.ceil(N/1000) print(x*1000-N)
1
8,417,628,858,940
null
108
108
H, W, K = map(int, input().split()) c = [] for _ in range(H): c.append(input()) #こういうinputをすると,c_ij = c[i][j] (C[i]という文字列のj文字目)という構造になってくれて,とても嬉しい。 #print(c) ans = 0 #bit全探索 for rows in range(1 << H): #bit演算子。1 << H は二進数で1000...という風に,1の後ろに0がH個並ぶ。 #例えば rows = 110010 のときには,(2 ** 5ケタ目の1は無視して)(0-indexで)1行目と4行目を赤で塗る状態を指す。 for cols in range(1 << W): black_count = 0 for i in range(H): if (rows >> i) % 2 == 1:continue #i行目が赤で塗られていたならば,何もせずiを一歩進める。 for j in range(W): if (cols >> j) % 2 ==1:continue #j列目が赤で塗られていたならば,何もせずjを一歩進める。 if c[i][j] == "#": black_count += 1 if black_count == K: ans += 1 print(ans)
WHITE = '.' BLACK = '#' H, W, K = map(int, input().split()) C = [input() for _ in range(H)] ans = 0 for rows in range(2 ** H): for cols in range(2 ** W): cnt = 0 for h in range(H): for w in range(W): if (rows >> h) & 1 or (cols >> w) & 1: continue cnt += C[h][w] == BLACK if cnt == K: ans += 1 print(ans)
1
8,977,106,186,412
null
110
110
N = int(input()) A = list(map(int,input().split())) s = [0]*(N+1) for i in range(N): s[i+1] = s[i] + A[i] cnt = 0 for j in range(N): cnt = (cnt + (A[j]*(s[N] - s[j+1])))%(10**9+7) print(cnt)
import sys from operator import add for i in sys.stdin: print(len(str(add(*list(map(int, i.split()))))))
0
null
1,917,337,748,348
83
3
import sys i=1 while True: x=sys.stdin.readline().strip() if x=="0": break; print("Case %d: %s"%(i,x)) i+=1
import sys, itertools for count, input in zip(itertools.count(1), sys.stdin): if int(input) == 0: break print('Case {0}: {1}'.format(count, input), end='')
1
484,597,745,760
null
42
42
# ALDS1_11_C.py import queue def printNode(): for i, node in enumerate(glaph): print(i, node) N = int(input()) glaph = [[] for i in range(N+1)] for i in range(1, N+1): glaph[i] = list(map(int, input().split()))[2:] # printNode() step = [-1]*(N+1) step[1] = 0 q = queue.Queue() q.put(1) while not q.empty(): now = q.get() next_node = glaph[now] # print("now is ", now, ", next is", next_node) for i in next_node: if step[i] != -1: continue q.put(i) step[i] = step[now] + 1 for i, v in enumerate(step): if i != 0: print(i, v)
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])
1
4,150,318,838
null
9
9
_n = int(raw_input()) _a = [int(x) for x in raw_input().split()] _flg = 1 cnt = 0 while _flg: _flg = 0 for i in reversed(range(1, _n)): if _a[i] < _a[i-1]: _a[i], _a[i-1] = _a[i-1], _a[i] cnt += 1 _flg = 1 print(" ".join([str(x) for x in _a])) print(cnt)
import sys from fractions import gcd sr = lambda: sys.stdin.readline().rstrip() ir = lambda: int(sr()) lr = lambda: list(map(int, sr().split())) MOD = 10 ** 9 + 7 N = ir() A = lr() lcm = 1 answer = 0 for a in A: coef = a // gcd(lcm, a) answer *= coef lcm *= coef answer += lcm // a print(answer%MOD)
0
null
43,699,971,157,664
14
235
import bisect n = int(input()) a = list(map(int,input().split())) # ni - nj = ai + aj (i>j) # ai - ni = - aj - nj a1 = sorted([a[i] - (i+1) for i in range(n)]) a2 = sorted([- a[i] - (i+1) for i in range(n)]) ans = 0 for i in range(n): left = bisect.bisect_left(a2, a1[i]) right = bisect.bisect_right(a2, a1[i]) ans += (right - left) print(ans)
import collections N = int(input()) A = list(map(int , input().split())) # N = 32 # A = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9, 5] # N = 6 # A = [2, 3, 3, 1, 3, 1] i = [k for k in range(1,N+1)] j = [k for k in range(1,N+1)] Li = [i[k]+A[k] for k in range(N)] Rj = [j[k]-A[k] for k in range(N)] Li = collections.Counter(Li) counter = 0 for r in Rj: counter += Li[r] print(counter)
1
26,170,207,269,070
null
157
157
import math x1,y1,x2,y2 = (float(x) for x in input().split()) print(round(math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2), 8))
import math x_1,y_1,x_2,y_2 = map(float,input().split()) print(math.sqrt((x_1-x_2)**2+(y_1-y_2)**2))
1
150,036,702,130
null
29
29
n,k = map(int, input().split()) lag = [] for l in range(n): lag.append(int(input())) w_max = 100000*100000 w_min = 0 while w_min < w_max: w_mid = (w_max + w_min) // 2 tracks = 0 current = 0 for i in range(n): if lag[i] > w_mid: tracks = k break elif lag[i] + current > w_mid: tracks += 1 current = lag[i] else: current += lag[i] if tracks < k: w_max = w_mid else: w_min = w_mid + 1 print(w_max)
import sys def binarySearch(t,w): left = max(w) right = sum(w) while left < right: middle = (left + right) // 2 if hantei(t,w,middle): right = middle else: left = middle + 1 return left def hantei(t,w,p): track_on = 0 daisu = 1 for j in range(len(w)): track_on += w[j] if track_on > p: daisu += 1 track_on = w[j] if daisu > t: return False return True nimotsu, track = map(int,input().split()) weight = list(map(int,sys.stdin.readlines())) print(binarySearch(track,weight))
1
89,257,418,282
null
24
24
n=int(input()) l=[[-1 for i in range(n)] for j in range(n)] for i in range(n): a=int(input()) for j in range(a): x,y = map(int,input().split()) l[i][x-1]=y ans=0 for i in range(2**n): d=[0 for x in range(n)] for j in range(n): if i>>j & 1: d[j]=1 flag=1 for j in range(n): for s in range(n): if d[j]==1: if l[j][s]==-1: continue if l[j][s]!=d[s]: flag=0 break if flag: ans=max(ans,sum(d)) print(ans)
n=int(input()) xy=[[] for i in range(n)] for i in range(n): a=int(input()) for j in range(a): x,y=map(int,input().split()) x-=1 xy[i].append((x,y)) ans=0 for i in range(1<<n): cnt=bin(i).count("1") if cnt<=ans:continue for j in range(n): if i&(1<<j): for x,y in xy[j]: if y==1 and i&(1<<x):continue if y==0 and i&(1<<x)==0:continue break else: continue break else: ans=cnt print(ans)
1
120,850,985,262,970
null
262
262
l=list(map(int,input().split())) s=sum(l) if(s>=22): print('bust') else: print('win')
A = list(map(int, input().split())) print("bust" if sum(A)>=22 else "win")
1
118,182,288,567,100
null
260
260
n = int(raw_input()) card_list = 52*[0] for i in range(0,n): (mark,rank) = map(str,raw_input().split()) for j in range(0,4): if mark == 'SHCD'[j]: card_list[13*j+int(rank)-1] = 1 for i in range(0,52): if card_list[i] == 0: print '%c %d' %('SHCD'[i/13],i%13+1)
def create_card(): return [str(i) for i in range(1,14)] Card = { 'S':create_card(), 'H':create_card(), "C":create_card(), "D":create_card(), } for i in range(int(input())): in_str = input().split() Card[in_str[0]].remove(in_str[1]) for s in ['S','H','C','D']: while(Card[s]): print(s,Card[s].pop(0))
1
1,028,040,782,888
null
54
54
N = int(input()) A = input().split() ans = 'YES' if len(A) - len(set(A)) == 0 else 'NO' print(ans)
from math import atan,pi a,b,x=map(int,input().split()) if b-x/a**2 <= x/a**2:print(atan((b-x/a**2)/(a/2))*(180/pi)) else: y = x/a*2/b print(atan(b/y)*(180/pi))
0
null
118,970,364,451,640
222
289