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
H, N = map(int, input().split()) A = list(map(int, input().split())) A.sort(reverse=True) S = sum(A[:N]) if S >= H: print('Yes') else: print('No')
A,B,C=map(int,input().split()) K=int(input()) result='No' while A>=B: K-=1 B*=2 while B>=C: K-=1 C*=2 if K>=0 and C>B and B>A: result='Yes' print(result)
0
null
42,667,686,657,562
226
101
h,w,k=map(int,input().split()) S=[input() for i in range(h)] LIS=[] def saiki(x,st): if x==h-1: LIS.append(st) return else: saiki(x+1,st+st[-1]) saiki(x+1,st+str(int(st[-1])+1)) saiki(0,"0") DIC1={c:0 for c in "0123456789"} DIC2={c:0 for c in "0123456789"} ans=10**9 for cod in LIS: for ele in DIC1: DIC1[ele]=0 cnt=int(cod[-1]) end=False for i in range(w): for ele in DIC2: DIC2[ele]=0 for q in range(h): if S[q][i]=="1": DIC2[cod[q]]+=1 if max(DIC2.values())>k: end=True break flg=True for ele in DIC1: if DIC1[ele]+DIC2[ele]>k: flg=False break if flg: for ele in DIC1: DIC1[ele]+=DIC2[ele] else: for ele in DIC1: DIC1[ele]=DIC2[ele] cnt+=1 if end: continue ans=min(ans,cnt) #print(cod,cnt) print(ans)
import sys input = sys.stdin.buffer.readline import math n = int(input()) mod = 1000000007 AB = [] for i in range(n): a, b = map(int, input().split()) AB.append((a, b)) def power(a, n, mod): bi=str(format(n,"b")) #2進数 res=1 for i in range(len(bi)): res=(res*res) %mod if bi[i]=="1": res=(res*a) %mod return res def toid(a, b): flag = False if a == 0 and b == 0: return (0, 0) elif a == 0: return (0, 1) elif b == 0: return (1, 0) else: if a > 0 and b > 0: g = math.gcd(a, b) a //= g b //= g elif a > 0 and b < 0: b = -b g = math.gcd(a, b) a //= g b //= g b = -b elif a < 0 and b > 0: a = -a g = math.gcd(a, b) a //= g b //= g b = -b else: a = -a b = -b g = math.gcd(a, b) a //= g b //= g return (a, b) def totg(a, b): if a == 0 and b == 0: return (0, 0) elif a == 0: return (1, 0) elif b == 0: return (0, 1) else: if a > 0 and b > 0: g = math.gcd(a, b) a //= g b //= g t = (b, -a) elif a > 0 and b < 0: b = -b g = math.gcd(a, b) a //= g b //= g b = -b t = (-b, a) elif a < 0 and b > 0: a = -a g = math.gcd(a, b) a //= g b //= g a = -a t = (b, -a) else: a = -a b = -b g = math.gcd(a, b) a //= g b //= g a = -a b = -b t = (-b, a) return t d = {} ans = 0 for i in range(n): a, b = AB[i] s = toid(a, b) if s not in d: d[s] = 1 else: d[s] += 1 ans = 1 used = set() for k1, v1 in d.items(): if k1 in used: continue if k1 == (0, 0): continue a, b = k1 k2 = totg(a, b) if k2 in d: v2 = d[k2] else: v2 = 0 temp = power(2, v1, mod)-1+power(2, v2, mod)-1+1 ans *= temp ans %= mod used.add(k1) used.add(k2) ans -= 1 if (0, 0) in d: ans += d[(0, 0)] print(ans%mod)
0
null
34,771,576,352,920
193
146
import math from collections import defaultdict from itertools import accumulate N=int(input()) data=defaultdict(int) result=0 for i in range(2,int(math.sqrt(N))+1): while N%i==0: N//=i data[i]+=1 if N!=1: data[N]+=1 cumsum=list(accumulate(range(1,10**6*2))) for value in data.values(): for i in range(10**6*2): if value<cumsum[i]: result+=i break if result==0: if N!=1: result=1 print(result)
from collections import Counter n = int(input()) ans = 0 dp = [] cl = [] n1 = n if n == 1: ans = 0 else: for i in range(2, int(n**0.5)+1): if n%i == 0: cl.append(i) while n%i == 0: n = n/i dp.append(i) if n == 1: break if n != 1: ans = 1 c = Counter(dp) for i in cl: cnt = 1 while c[i] >= cnt: c[i] -= cnt ans += 1 cnt += 1 print(ans)
1
17,071,893,160,162
null
136
136
class UnionFind: # 各要素の親要素の番号を格納するリスト # 要素が根(ルート)の場合は-(そのグループの要素数)を格納する def __init__(self, n): self.n = n self.parents = [-1] * n # 要素xが属するグループの根を返す def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] # 要素xが属するグループと要素yが属するグループとを併合する 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 # 要素xが属するグループのサイズ(要素数)を返す def size(self, x): return -self.parents[self.find(x)] # 要素x, yが同じグループに属するかどうかを返す def is_same(self, x, y): return self.find(x) == self.find(y) # 要素xが属するグループに属する要素をリストで返す 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()} # ルート要素: [そのグループに含まれる要素のリスト]を文字列で返す (print()での表示用) def __str__(self): return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots()) def resolve(): N, M, K = map(int, input().split()) uf = UnionFind(N) sub_friend = [1] * N # +1: 自分自身 frind = [[] for _ in range(N)] for _ in range(M): a, b = map(lambda x: int(x) - 1, input().split()) frind[a].append(b) frind[b].append(a) sub_friend[a] += 1 sub_friend[b] += 1 block = [[] for _ in range(N)] for _ in range(K): c, d = map(lambda x: int(x) - 1, input().split()) block[c].append(d) block[d].append(c) for i in range(N): for to in frind[i]: uf.union(i, to) ans = [uf.size(i) - sub_friend[i] for i in range(N)] for i in range(N): for bl in block[i]: if uf.is_same(i, bl): ans[i] -= 1 print(*ans) if __name__ == "__main__": resolve()
n=int(input()) s=list(input()) rn=s.count('R') gn=s.count('G') bn=n-rn-gn ans=bn*gn*rn if n>2: for x in range(n-2): y=(n-1-x)//2 for i in range(1,y+1): if (not s[x]==s[x+i]) & (not s[x]==s[x+i+i]) & (not s[x+i]==s[x+i+i]): ans-=1 print(ans) else: print(0)
0
null
48,962,094,622,080
209
175
N = int(input()) a = list(map(int,input().split())) num = 1 for i in range(N): if a[i] == num: num += 1 if num == 1: print(-1) exit() print(N - num + 1)
_ = input() A = [int(i) for i in input().split()] cnt = 1 broken = 0 for a in A: if a == cnt: cnt += 1 else: broken += 1 if cnt == 1: print("-1") else: print(broken)
1
114,716,768,771,468
null
257
257
import math a, b, h, m = map(int, input().split()) min = h * 60 + m short = 0.5 * min long = 6 * m if abs(short - long) >= 180: deg = 360 - abs(short - long) else: deg = abs(short - long) coss = math.cos(math.radians(deg)) c = (a ** 2 + b ** 2 - 2 * a * b * coss) ** 0.5 #print(c) print('{:.20f}'.format(c))
import numpy as np a,b,h,m = map(int,input().split()) pos1 = [b*np.sin(np.radians(6*m)),b*np.cos(np.radians(6*m))] pos2 = [a*np.sin(np.radians(30*h+m*(360/(12*60)))),a*np.cos((np.radians(30*h+m*(360/(12*60)))))] d = ((pos1[0]-pos2[0])**2+(pos1[1]-pos2[1])**2)**0.5 print(d) #print(pos1) #print(pos2)
1
20,081,428,415,360
null
144
144
import sys input = sys.stdin.readline import numpy as np from scipy.sparse.csgraph import floyd_warshall from scipy.sparse import csr_matrix def main(): n, m, l = map(int, input().split()) F = np.zeros((n, n)) for _ in range(m): a, b, c = map(int, input().split()) a -= 1 b -= 1 F[a, b] = c F[b, a] = c csr = csr_matrix(F) A = floyd_warshall(csr) G = np.zeros((n, n)) for i in range(n-1): for j in range(i+1, n): if A[i][j] <= l: G[i, j] = 1 G[j, i] = 1 ncsr = csr_matrix(G) B = floyd_warshall(ncsr) q = int(input()) for _ in range(q): s, t = map(int, input().split()) k = B[s-1][t-1] if k == float("inf"): print(-1) else: print(int(k)-1) if __name__ == "__main__": main()
H = int(input()) W = int(input()) N = int(input()) print(int(N/max(H,W)) + (1 if N % max(H,W) != 0 else 0))
0
null
131,258,474,009,692
295
236
X,N = map(int, input().split()) P = list(map(int, input().split())) table = [0] * 102 ans = X dist = 102 for p in P: table[p] = 1 for i in range(102): if table[i] != 0: continue if abs(i - X) < dist: ans = i dist = abs(i - X) elif abs(i - X) == dist: ans = min(i, ans) print(str(ans))
def main(): x, n = map(int, input().split()) ps = list(map(int, input().split())) for i in range(n//2 + 2): if x - i not in ps: print(x-i) return if x + i not in ps: print(x+i) return if __name__ == '__main__': main()
1
14,168,025,565,918
null
128
128
N = int(input()) S = 'X' + input() cnt_R, cnt_G, cnt_B = 0, 0, 0 for s in S[1:]: if s == 'R': cnt_R += 1 elif s == 'G': cnt_G += 1 elif s == 'B': cnt_B += 1 ans = cnt_R * cnt_G * cnt_B for i in range(1,N-1): for j in range(i+1,N): k = 2*j - i if k > N: break a = S[i]; b = S[j]; c = S[k] if a != b and b != c and c != a: ans -= 1 print(ans)
n = int(input()) s = list(input()) r = 0 g = 0 b = 0 for c in s: if c == "R": r += 1 if c == "G": g += 1 if c == "B": b += 1 ans = r*g*b for i in range(n): for j in range(i+1,n): k = 2*j - i if k > n-1: continue x = s[i] y = s[j] z = s[k] if x!= y and y != z and z != x: ans -= 1 print(ans)
1
36,200,898,212,640
null
175
175
import bisect from itertools import accumulate N, M, K = map(int, input().split()) A = map(int, input().split()) B = map(int, input().split()) A_cumsum = list(accumulate(A)) B_cumsum = list(accumulate(B)) max_books = 0 for a, A_sum in enumerate([0] + A_cumsum): if A_sum > K: break else: b = bisect.bisect(B_cumsum, K - A_sum) max_books = max(a + b, max_books) print(max_books)
# 解説 import sys pin = sys.stdin.readline pout = sys.stdout.write perr = sys.stderr.write N, M, K = map(int, pin().split()) A = list(map(int, pin().split())) B = list(map(int, pin().split())) a = [0] b = [0] for i in range(N): a.append(a[i] + A[i]) for i in range(M): b.append(b[i] + B[i]) ans = 0 for i in range(N + 1): #Aの合計がKを超えるまで比較する if a[i] > K: break # 超えていた場合に本の個数を減らす while b[M] > K - a[i]: M -= 1 ans = max(ans, M + i) print(ans)
1
10,835,862,797,250
null
117
117
N = int(input()) P = tuple(map(int,input().split())) Q = tuple(map(int,input().split())) import itertools nums = list(itertools.permutations(range(1,N+1))) print(abs(nums.index(P)-nums.index(Q)))
def nanbanme(n, x): lst = [1 for i in range(n)] ans = 0 for i in range(n): a = x[i] count = 0 for j in range(a - 1): if (lst[j] == 1): count = count + 1 tmp = 1 for k in range(1, n - i): tmp = tmp*k ans = ans + count*tmp lst[a - 1] = 0 return (ans + 1) n = int(input()) lst1 = list(map(int,input().split())) lst2 = list(map(int,input().split())) a = nanbanme(n, lst1) b = nanbanme(n, lst2) print(abs(a - b))
1
100,127,803,607,344
null
246
246
n = int(input()) info = [] for _ in range(n): temp = [int(x) for x in input().split( )] info.append(temp) state = [[[0 for i in range(10)] for j in range(3)] for k in range(4)] for a in info: state[a[0]-1][a[1]-1][a[2]-1] += a[3] for b in range(4): for f in range(3): string = '' for k in range(10): string += ' ' + str(state[b][f][k]) print(string) if b < 3: print('#'*20)
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 def bit(S, j): # Sの右からj bit目(0-indexed) return (S>>j)&1 N = int(input()) A = list(map(int, input().split())) B = [0 for i in range(61)] for i in range(61): for j in range(N): B[i] += bit(A[j], i) for i in range(61): B[i] = B[i]*(N-B[i]) % mod ans = 0 for i in range(61): ans = (ans + 2**i*B[i]) % mod print(ans % mod)
0
null
62,126,496,181,272
55
263
A=list(map(int,input().split())) if A[0]+A[1]+A[2]<=21: print("win") else: print("bust")
def main(): day = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'] s = input() ans = 7 - day.index(s) print(ans) if __name__ == '__main__': main()
0
null
125,744,680,317,604
260
270
#参考:https://marco-note.net/abc-174-work-log/ n = int(input()) c = input() R=c.count('R') cnt = 0 for i in range(R): if c[i]=="R": cnt += 1 print(R-cnt)
n = int(input()) a = list(map(int, input().split())) ans = [""]*n for i in range(n): x = a[i] b = ans[a[i] - 1] c = str(i+1) ans[a[i]-1] = str(i+1) print(" ".join(ans))
0
null
93,470,908,206,170
98
299
n,m=map(int,input().split()) matA=[list(map(int,input().split())) for i in range(n)] matB=[int(input()) for i in range(m)] for obj in matA: print(sum(obj[i] * matB[i] for i in range(m)))
n,m = map(int,input().split()) v1 = [ map(int,input().split()) for i in range(n) ] v2 = [ int(input()) for i in range(m) ] for v in v1: print(sum(map(lambda x,y:x*y,v,v2)))
1
1,156,020,340,160
null
56
56
a=0 i=0 for a in range(1,10): for i in range(1,10): num1=a num2=i num3=a*i print(str(num1)+'x'+str(num2)+'='+str(num3))
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9] for num in numbers: for num2 in numbers: print('{0}x{1}={2}'.format(num, num2, num * num2))
1
2,567,460
null
1
1
def main(): S = input() L = len(S) print('x' * L) if __name__ == '__main__': main()
import math def LI(): return list(map(int, input().split())) a, b, x = LI() if x == (a**2*b)/2: ans = 45 elif x > (a**2*b)/2: ans = math.degrees(math.atan((2*(b-x/(a**2)))/a)) else: ans = math.degrees(math.atan(a*b**2/(2*x))) print(ans)
0
null
117,803,691,479,584
221
289
x = int(input()) y = int(input()) z = int(input()) a = max(x,y) if z%a == 0: print(z//a) else: print(z//a+1)
from math import ceil H,W,N = map(int, open(0).read().split()) m = max(H,W) print(ceil(N/m))
1
88,735,466,270,070
null
236
236
# import sys input=sys.stdin.readline def main(): K=int(input()) lunlun=[1,2,3,4,5,6,7,8,9] ind=0 lll=9 for dig in range(12): l=lll for i in lunlun[ind:]: s=str(i) x=int(s[dig]) if 0<=x-1<=9: lunlun+=[int(s+str(x-1))] lll+=1 if 0<=x<=9: lunlun+=[int(s+str(x))] lll+=1 if 0<=x+1<=9: lunlun+=[int(s+str(x+1))] lll+=1 if lll>K: break ind=l lunlun.sort() print(lunlun[K-1]) if __name__=="__main__": main()
# Template 1.0 import sys, re from collections import deque, defaultdict, Counter, OrderedDict from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians from heapq import heappush, heappop, heapify, nlargest, nsmallest def STR(): return list(input()) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(): return list(map(int, input().split())) def list2d(a, b, c): return [[c] * b for i in range(a)] def sortListWithIndex(listOfTuples, idx): return (sorted(listOfTuples, key=lambda x: x[idx])) def sortDictWithVal(passedDic): temp = sorted(passedDic.items(), key=lambda kv: (kv[1], kv[0])) toret = {} for tup in temp: toret[tup[0]] = tup[1] return toret def sortDictWithKey(passedDic): return dict(OrderedDict(sorted(passedDic.items()))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 ''' 1,2,3,4,5,6,7,8,9,10,11,12,21,22,23,32,33,34,43,44,45,54,55,56,65,66,67,76,77,78,87,88,89,98,99,100 (36) 101,110,111,112,121,122,123,210,211,212,221,222,223,232,233,234, 1 10 11 12 100 101 110 111 112 121 122 123 1000 1001 1002 ''' #precomp: nums = [] def precomp(i): temp = str(i) x=[-1,0,1] for j in range(3): foo = int(temp[-1])+x[j] if(foo>=0 and foo<=9): toadd = int(temp+str(foo)) if (i > 3234566667): return nums.append(toadd) precomp(toadd) for i in range(1, 10): nums.append(i) precomp(i) nums.sort() k = INT() print(nums[k-1]) # k = INT()
1
39,796,211,247,872
null
181
181
from collections import Counter S = input()[::-1] cur = 0 mods = Counter() mods[0] += 1 MOD = 2019 for i,d in enumerate(S): cur += int(d) * pow(10, i, MOD) mods[cur%MOD] += 1 res = 0 for k,v in mods.items(): res += (v * (v-1) // 2) print(res)
def resolve(): h, w = map(int, input().split()) import math if w == 1 or h == 1: print(1) else: print(math.ceil(h * w / 2)) if __name__ == '__main__': resolve()
0
null
40,931,661,045,858
166
196
n = int(raw_input()) x = map(int,raw_input().split()) i = n-1 while i != -1: print "%d" %x[i] , i = i-1
n = int(raw_input()) a = map(int,raw_input().split()) a.reverse() for x in a: print x,
1
983,834,145,856
null
53
53
a, b = input().split() print(int(a)*int(b[0]+b[2]+b[3])//100)
s = input() if s.lower() == s: print("a") else: print("A")
0
null
13,944,467,589,660
135
119
import sys for e in sys.stdin.readlines(): print(len(str(eval('+'.join(e.split())))))
import numpy as np from numba import njit @njit #処理の並列化_これがない場合は'TLE' def imos(n, a): l=np.zeros((n+1), dtype = np.int64) for i in range(n): ai = a[i] # 光の強さ_これにより照らせる範囲が決まる start = max(0, i - ai) #StartIndex_照らせる範囲 end = min(n, i + ai + 1) #EndIndex + 1_照らせる範囲 l[start] += 1 # 各々を'+1'と'-1'で表し... l[end] -= 1 return np.cumsum(l)[:n] # 累積和をとる_cumulative sum n, k = map(int, input().split()) a = list(map(int, input().split())) for _ in range(k): a = imos(n, a) if a.min() == n: # すべての要素が最大値'n'になるとbreak break print(*a)
0
null
7,768,312,719,740
3
132
N,M = map(int,input().split()) S = input() ans = [] i = N while i > 0: for m in range(M,0,-1): if i-m <= 0: ans.append(i) i = 0 break if S[i-m]=='0': ans.append(m) i -= m break else: print(-1) exit() print(*ans[::-1])
from collections import deque N, M = map(int, input().split()) S = input()[::-1] +'1'*M if M >= N: print(N) exit() q = deque([]) i = 0 j = 0 while i < N: f = 0 for k in range(i+M,j,-1): if S[k] == '0': f = 1 break j = i + M q.appendleft(k-i) i = k if f == 0: print(-1) exit() print(' '.join(map(str, q)))
1
138,822,880,445,340
null
274
274
def five_variables(): x = list(map(int, input().split())) for i, j in enumerate(x): if j == 0: print(i+1) break five_variables()
N =int(input()) c = 0 for i in range(N): c += (N-1)//(i+1) print(c)
0
null
8,064,519,162,492
126
73
x = int(input()) ans = 0 div_500, x = divmod(x, 500) div_5, x = divmod(x, 5) ans = div_500 * 1000 + div_5 * 5 print(ans)
tarou = 0 hanako = 0 n = int(input()) for i in range(n): str1, str2 = input().split() if str1 > str2: tarou += 3 elif str1 < str2: hanako += 3 else: tarou += 1 hanako += 1 print("{0} {1}".format(tarou, hanako))
0
null
22,493,795,294,168
185
67
def main(): N=10 l = list() for i in range(N): l.append(int(input())) l.sort(reverse=True) for x in l[:3]: print(x) if __name__=='__main__': main()
a, b = list(map(int, input().split())) my_result = a * (a - 1) + b * (b - 1) print(int(my_result / 2))
0
null
22,792,773,101,252
2
189
N = int(input()) S = input() ans = [] for i in range(len(S)): if i == len(S) - 1: ans.append(S[i]) break if S[i] != S[i+1]: ans.append(S[i]) print(len(ans))
def main(): N = int(input()) S = input() fusion = [S[0]] prev = S[0] for s in S[1:]: if s == prev: continue fusion.append(s) prev = s print(len(fusion)) main()
1
169,654,643,201,978
null
293
293
while True: a, b = map(int, input().split()) if a == 0 and b == 0: break; for i in range(0, a): if i % 2 == 0: print(("#." * int((b + 1) / 2))[:b]) else: print((".#" * int((b + 1) / 2))[:b]) print("")
N=input() N=int(N) q1, mod = divmod(N,2) if mod == 0: print(q1) else: print(q1 + 1)
0
null
29,923,226,069,050
51
206
N,K = [int(i) for i in input().split()] mod = 998244353 LR = [] S = [] dp = [0]*(N+1) dps = [0]*(N+1) dps[1] = 1 dp[1] = 1 for i in range(K): LR.append([int(i) for i in input().split()]) for i in range(1,N+1): for l,r in LR: l,r = i - r,i - l #print(l,r) if r < 1: continue l = max(1,l) dp[i] += dps[r] - dps[l-1] dp[i] %= mod #print(dp[i]) dps[i] = dps[i-1] + dp[i] #print(dp, dps) print(dp[-1])
mod=998244353 n,k=map(int,input().split()) LR=[list(map(int,input().split())) for _ in range(k)] DP=[0 for _ in range(n+1)] SDP=[0 for _ in range(n+1)] DP[1]=1 SDP[1]=1 for i in range(2,n+1): for l,r in LR: DP[i] +=(SDP[max(i-l,0)]-SDP[max(i-r,1)-1])%mod DP[i] %=mod SDP[i]=(SDP[i-1]+DP[i])%mod print(DP[n])
1
2,695,915,866,842
null
74
74
import math def LI(): return list(map(int, input().split())) a, b, x = LI() if x == (a**2*b)/2: ans = 45 elif x > (a**2*b)/2: ans = math.degrees(math.atan((2*(b-x/(a**2)))/a)) else: ans = math.degrees(math.atan(a*b**2/(2*x))) print(ans)
def main(): import sys input = sys.stdin.readline n = int(input()) D = list(map(int,input().split())) mod = 998244353 from collections import Counter node_cnt = Counter(D) set_d = sorted(list(set(D))) if D[0]!=0: print(0);exit() if set_d[-1]!=len(set_d)-1: print(0);exit() ans = 0 pre = 1 if 0 in node_cnt: if node_cnt[0]==1: ans = 1 for k,v in sorted(node_cnt.items()): ans*=pow(pre,v) ans%=mod pre = v print(ans) if __name__=='__main__': main()
0
null
159,073,073,200,820
289
284
print(str(input())[:3])
a=str(input()) print(a[0:3])
1
14,838,878,964,352
null
130
130
x,n=map(int,input().split()) p=set(list(map(int,input().split()))) if x not in p : print(x) exit() i=1 while True: if x-i not in p: print(x-i) exit() if x+i not in p: print(x+i) exit() i+=1
import sys x,n = map(int,input().split()) p = list(map(int,input().split())) s = 100 min_i = -1 if x not in p: print(x) sys.exit() for i in range(-1,102): if i not in p and abs(i-x) < s: s = abs(i-x) min_i = i print(min_i)
1
14,169,065,169,600
null
128
128
a,b,c,d = map(int,input().split()) k = max(a*c,b*d) l = max(a*d,b*c) print(max(k,l))
import numpy as np a, b, c, d = map(int, input().split()) x = np.array([a, b]) y = np.array([c, d]) z = np.outer(x, y) print(z.max())
1
2,998,708,913,552
null
77
77
n = int(input()) title = [] time = [] for i in range(n): line = input().split() title += [line[0]] time += [int(line[1])] key = input() a = title.index(key) print(sum(time[a+1:]))
from sys import stdin import re W = stdin.readline().rstrip() T = stdin.read().replace("END_OF_TEXT", ".").lower() T = re.split(",|\n| ", T) print(len([x for x in T if x == W]))
0
null
49,615,449,460,160
243
65
from itertools import cycle while True: (H, W) = [int(i) for i in input().split(' ')] if (H == W == 0): break it1 = cycle(['#', '.']) it2 = cycle(['.', '#']) str1 = '' str2 = '' for i in range(W): str1 += next(it1) str2 += next(it2) for i in range(H): if ((i % 2) == 0): print(str1) else: print(str2) print()
N=int(input()) X=[int(x) for x in input().split()] ans=10**9 for p in range(-200, 200): ref=0 for x in X: ref+=(x-p)**2 #print(ref) ans=min(ans, ref) print(ans)
0
null
33,128,556,617,718
51
213
h1 , m1 , h2 , m2 , k = map(int,input().split()) if m2 >= m1: time = (h2 - h1)*60 + m2 - m1 elif m2 < m1: time = (h2 - h1 - 1) * 60 + m2 + 60 - m1 print(time-k)
#! /usr/bin/env python3 import sys int1 = lambda x: int(x) - 1 read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines sys.setrecursionlimit(500000) H1, M1, H2, M2, K = map(int, read().split()) start = H1 * 60 + M1 end = H2 * 60 + M2 gap = end - start res = gap - K print(res)
1
18,026,399,503,518
null
139
139
import math t8 = [[] for _ in range(130)] t10 = [[] for _ in range(130)] for i in range(1251): t8[math.floor(i * 0.08)].append(i) t10[math.floor(i * 0.1)].append(i) a, b = map(int, input().split()) if min(t8[a]) > max(t10[b]) or max(t8[a]) < min(t10[b]): print(-1) else: print(max(min(t8[a]), min(t10[b])))
cnt = 0 def merge(A, left, mid, right): global cnt L = A[left:mid] R = A[mid:right] L.append(10000000000) R.append(10000000000) i = 0 j = 0 for k in range(left, right): if L[i] <= R[j]: A[k] = L[i] i += 1 else: A[k] = R[j] j += 1 cnt += 1 def mergesort(A, left, right): if left + 1 < right: #if block size >= 2 mid = int((left + right)/2) mergesort(A, left, mid) mergesort(A, mid, right) merge(A, left, mid, right) n = int(input()) S = list(map(int,input().split())) mergesort(S, 0, n) print(*S) print(str(cnt))
0
null
28,297,404,771,950
203
26
n = int(input()) x = list(map(int, input().split())) sum= 1000000000000000 for p in range(1,101): tmp=0 # print("p",p) for i in range(len(x)): tmp += (x[i] - p)**2 # print("tmp",tmp) sum = min(sum,tmp) # print("su",sum) print(sum)
n=int(input()) x=list(map(int,input().split())) x.sort() m=10000000000 for i in range(x[0],x[n-1]+1): ans=0 for j in range(n): ans+=(i-x[j])**2 m=min(m,ans) print(m)
1
65,024,372,218,036
null
213
213
N, K, C = list(map(int,input().split())) s = list(str(input())) L = [] # i+1日目に働くのはL[i]日目以降 R = [] # i+1日目に働くのはL[i]日目以前 for i in range(N): if len(L) >= K: break if s[i] == 'o' and (L == [] or (i + 1) - L[-1] > C): # 出勤可能('o') 且 (Lが空又はi日目時点の最終出勤からc日経過) # ならばLにi+1を追加 L.append(i + 1) for i in range(N - 1, -1, -1): if len(R) >= K: break if s[i] == 'o' and (R == [] or R[-1] - (i + 1) > C): R.append(i + 1) R.reverse() ans = [] for i in range(K): if L[i] == R[i]: print(L[i])
# with open('./ABC161/max_02') as f: # l = [s.strip() for s in f.readlines()] n,k,c = map(int, input().split()) s = input() l = list() r = list() i = 0 while i < n: if len(l) == k: break if s[i] == 'o': l.append(i) i += c i+=1 i = n-1 while i >= 0: if len(r) == k: break if s[i] == 'o': r.append(i) i -= c i-=1 r.sort() for i in range(k): if l[i] == r[i]: print(l[i]+1)
1
40,353,927,208,640
null
182
182
#入力:N,M(int:整数) def input2(): return map(int,input().split()) d,t,s=input2() if d/s >t: print("No") else: print("Yes")
text = [int(e) for e in input().split()] if text[1] * text[2] >= text[0]: print("Yes") else: print("No")
1
3,519,995,650,434
null
81
81
N = int(input()) A = list(map(int,input().split())) Money = 1000 Stock = 0 for i in range(N-1): if A[i] < A[i+1]: Stock = Stock + (Money//A[i]) Money = Money % A[i] elif A[i] > A[i+1]: Money = Money + Stock * A[i] Stock = 0 ans = Money + Stock * A[i+1] print(ans)
n = int(input()) A = list(map(int, input().split())) cnt = 0 money = 1000 b = 0 for i in range(n-1): if cnt == 0 and A[i] < A[i+1]: cnt += money//A[i] money %= A[i] b = A[i] else: money += cnt * A[i] cnt = 0 if A[i] < A[i+1]: cnt += money//A[i] money %= A[i] b = A[i] if cnt > 0: money += cnt * max(b, A[-1]) print(money)
1
7,382,359,341,660
null
103
103
import math n = int(input()) x = n/1.08 t1 = math.ceil(x) t2 = math.floor(x) if math.floor(t1 * 1.08) == n: print(t1) elif math.floor(t2*1.08) == n: print(t2) else: print(':(')
i = range(1,10) for i in ['%dx%d=%d' % (x,y,x*y) for x in i for y in i]: print i
0
null
63,078,063,855,718
265
1
X, Y = map(int, input().split()) ans = "No" for i in range(101) : for j in range(101) : if(i + j != X) : continue if(2*i + 4*j != Y) : continue ans = "Yes" break print(ans)
x,y = map(int,input().split()) A = y//2 B = (x-A) while A>-1: if y==2*A + 4*B: print("Yes") break A = A-1 B = B+1 if A==-1: print("No")
1
13,772,579,293,700
null
127
127
def main(): K = int(input()) S = input() mod = pow(10, 9) + 7 N = len(S) g1 = [1, 1] g2 = [1, 1] inv = [0, 1] for i in range(2, K+N+1): g1.append((g1[-1] * i) % mod) inv.append( ( -inv[mod % i] * (mod//i)) % mod ) g2.append((g2[-1] * inv[-1]) % mod) def combi(n, r): r = min(r, n-r) return g1[n]*g2[r]*g2[n-r]%mod pow25 = [1] pow26 = [1] for i in range(K): pow25.append(pow25[-1] * 25 % mod) pow26.append(pow26[-1] * 26 % mod) ans = 0 for i in range(N-1, N+K): ans += combi(i, N-1) * pow25[i-N+1] % mod * pow26[K-i+N-1] % mod ans %= mod return ans if __name__ == '__main__': print(main())
U = 2*10**6+1 MOD = 10**9+7 fact = [1]*(U+1) fact_inv = [1]*(U+1) for i in range(1,U+1): fact[i] = (fact[i-1]*i)%MOD fact_inv[U] = pow(fact[U], MOD-2, MOD) for i in range(U,0,-1): fact_inv[i-1] = (fact_inv[i]*i)%MOD def comb(n, k): if k < 0 or k > n: return 0 z = fact[n] z *= fact_inv[k] z *= fact_inv[n-k] z %= MOD return z k = int(input()) S = input() n = len(S) ans = 0 for i in range(n-1, n+k): temp = comb(i, n-1)*pow(25, i-(n-1), MOD)*pow(26, n+k-1-i, MOD) temp %= MOD ans += temp ans %= MOD print(ans)
1
12,884,355,114,262
null
124
124
def main(): k = int(input()) if k<10: print(k) return que = [i for i in range(1,10)] cnt = 0 while True: q = que.pop(0) cnt += 1 if cnt==k: print(q) return if q%10==0: que.append(q*10) que.append(q*10+1) elif q%10==9: que.append(q*10+9-1) que.append(q*10+9) else: que.append(q*10+q%10-1) que.append(q*10+q%10) que.append(q*10+q%10+1) if __name__ == "__main__": main()
C=str(input()) a=ord(C) print(chr(a+1))
0
null
66,220,483,316,640
181
239
#!/usr/bin/env python3 import sys import math 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 generate_primes(n): if n < 2: return [] is_prime_array = [True] * (n + 1) is_prime_array[0], is_prime_array[1] = False, False for i in range(2, n+1): if is_prime_array[i]: k = 2 * i while k < n + 1: is_prime_array[k] = False k += i return list(filter(lambda i: is_prime_array[i], range(n+1))) def main(): N = II() if N <= 1: print(0) exit() max_prime = math.ceil(N**0.5) primes = generate_primes(max_prime) es = [0] * len(primes) for i in range(len(primes)): while N % primes[i] == 0: N /= primes[i] es[i] += 1 ans = 0 if int(N) != 1: ans += 1 for i in range(len(es)): k = 1 while es[i] - k >= 0: es[i] -= k k += 1 ans += 1 print(ans) main()
input() print(len([i for i in list(map(int,input().split()))[::2] if i%2]))
0
null
12,367,422,135,248
136
105
s = input() print("YNeos"[s[2:5:2] != s[3:6:2]::2])
def resolve(): s = str(input()) if s[2]==s[3] and s[4]==s[5]: print('Yes') else: print('No') a = resolve()
1
42,024,053,794,718
null
184
184
# AOJ ITP1_10_D import math def intinput(): a = input().split() for i in range(len(a)): a[i] = int(a[i]) return a def main(): n = int(input()) x = intinput() y = intinput() sum_1 = 0 sum_2 = 0 sum_3 = 0 MD_INFTY = 0 for i in range(n): MD_INFTY = max(MD_INFTY, abs(x[i] - y[i])) sum_1 += abs(x[i] - y[i]) sum_2 += abs(x[i] - y[i]) ** 2 sum_3 += abs(x[i] - y[i]) ** 3 MD_1 = sum_1 MD_2 = math.sqrt(sum_2) MD_3 = sum_3 ** (1 / 3) print(MD_1); print(MD_2); print(MD_3); print(float(MD_INFTY)) if __name__ == "__main__": main()
n = int(input()) x = [int(x) for x in input().split()] y = [int(x) for x in input().split()] abs_list = [abs(a-b) for a,b in zip(x,y)] p1 = p2 = p3 = p4 = 0 for a in abs_list: p1 += a p2 += a**2 p3 += a**3 p2 = p2 **(1/2) p3 = p3 **(1/3) p4 = max(abs_list) preanswer = [p1,p2,p3,p4] answer = ['{:.6f}'.format(i) for i in preanswer] for a in answer: print(a)
1
211,347,974,290
null
32
32
x = int(input()) ans = 0 flag = False for a in range((x//100)+1): for b in range((x//101)+1): for c in range((x//102)+1): for d in range((x//103)+1): for e in range((x//104)+1): for f in range((x//105)+1): if (100*a) + (101*b) + (102*c) + (103*d) + (104*e) + (105*f)== x: ans += 1 flag = True break if flag: break if flag: break if flag: break if flag: break if flag: break if ans == 0: print(0) else: print(1)
N=input() if int(N[-1]) in [2,4,5,7,9]: print('hon') elif int(N[-1]) in [3]: print('bon') else: print('pon')
0
null
73,482,078,655,680
266
142
A = int(input()) B = int(input()) anss = set([1, 2, 3]) anss.remove(A) anss.remove(B) for i in anss: print(i)
X, K, D = map(int, input().split()) XX = abs(X) if XX > K*D: print(XX - K*D) else: if (K - X//D)%2 == 0: print(X%D) else: print(abs(X%D -D))
0
null
57,790,722,731,908
254
92
import sys def gcd(a, b): "?????§??¬?´???°????±???????" if a < b: c = a a = b b = c if b == 0: return a else: return gcd(b, a % b) def lcm(a, b): g = gcd(a, b) return g * (a // g) * (b // g) for line in sys.stdin: a, b = map(int, line.split()) print("%d %d" % (gcd(a, b), lcm(a, b)))
S = input() Sliststr = list(S) Slist = [int(s) for s in Sliststr] Smod = [0] mod10 = [1] count = [0]*2019 ans = 0 for i in range(len(S)-1): mod10.append(mod10[i]*10%2019) for i in range(len(S)): Smod.append((Smod[i]+Slist[-i-1]*mod10[i])%2019) for i in range(len(Smod)): count[Smod[i]] += 1 for i in range(2019): ans += count[i] * (count[i]-1) // 2 print(ans)
0
null
15,321,681,981,760
5
166
N = int(input()) BOX = {} for i in range(N): S = input() if S in BOX: BOX[S] = (BOX[S] + 1) else: BOX[S] = 0 MAX = max(BOX.values()) keys = [k for k, v in BOX.items() if v == MAX] keys = sorted(keys) for i in range(len(keys)): print(keys[i])
n=int(input()) s={} for i in range(n): si = input() if si not in s: s[si] = 1 else: s[si]+=1 sa = sorted(s.items()) ma = max(s.values()) for a in sorted(a for a in s if s[a]==ma): print(a)
1
69,768,382,831,902
null
218
218
i=1 while True : x,y=map(int,input().split()); if (x,y) == (0,0) : break else : if x < y : print(x,y) else : print(y,x)
l = [] while True: s = [int(i) for i in input().split()] if s == [0,0]: break else: s.sort() l.append(str(s[0])+' '+str(s[1])) for i in l: print(i)
1
515,166,229,600
null
43
43
n=int(input()) mod=10**9+7 ans=10**n ans-=2*(9**n) ans+=8**n ans%=mod print(ans)
n = int(input()) all = 10**n all -= 9**n*2-8**n print(all%(10**9+7))
1
3,161,929,237,658
null
78
78
n = int(input()) ai = [int(i) for i in input().split()] ai_li = [] for i in range(n): ai_li.append([ai[i],i+1]) ai_li.sort(reverse=True) dp = [[0 for i in range(n+1)] for j in range(n+1)] for i in range(1,n+1): #print(i) for j in range(0,i+1): if i == 1: if j == 1: dp[i][j] = ai_li[i-1][0]*abs(ai_li[i-1][1]-1) else: dp[i][j] = ai_li[i-1][0]*abs(n-ai_li[i-1][1]) else: if j == 0: #print(dp[i][j]) dp[i][j] = dp[i-1][0] + ai_li[i-1][0]*abs(n-ai_li[i-1][1]-i+1) else: #if i == 2: # print(i-1,j-1) dp[i][j] = max(dp[i-1][j-1]+ai_li[i-1][0]*abs(ai_li[i-1][1]-j),dp[i-1][j]+ai_li[i-1][0]*abs(n-ai_li[i-1][1]-(i-1-j))) #dp[i][j] = max(dp[i-1][j-1]+ai_li[i][0]*abs(ai_li[i][1]-1+i-1),dp[i-1][j]+ai_li[i][0]*abs(n-i+1-ai_li[i][1])) #print(dp) print(max(dp[n]))
s = input() q = int(input()) for _ in range(q): x = input().split() a, b = int(x[1]), int(x[2]) if x[0] == 'print': print(s[a:b+1]) if x[0] == 'reverse': s = s[:a] + ''.join(reversed(s[a:b+1])) + s[b+1:] if x[0] == 'replace': s = s[:a] + x[3] + s[b+1:]
0
null
17,809,354,306,722
171
68
from collections import deque K=int(input()) q=deque([i for i in range(1,10)]) for _ in range(K-1): x=deque.popleft(q) a=x%10 if a!=0 and a!=9: deque.append(q,x*10+a-1) deque.append(q,x*10+a) deque.append(q,x*10+a+1) elif a==0: deque.append(q,x*10) deque.append(q,x*10+1) else: deque.append(q,x*10+8) deque.append(q,x*10+9) print(deque.popleft(q))
from collections import deque K = int(input()) lunlun = deque([i for i in range(1,10)]) for i in range(K): x = lunlun.popleft() if x % 10 != 0: lunlun.append(x * 10 + (x % 10) - 1) lunlun.append(x * 10 + (x % 10)) if x % 10 != 9: lunlun.append(x * 10 + (x % 10) + 1) print(x)
1
39,827,257,641,210
null
181
181
n,k = map(int,input().split()) a = list(map(int,input().split())) s = sorted(a,reverse=True) mod = 10**9 + 7 ans = 1 #全部の要素が負の数であり奇数個の場合は大きい順に取ったものが答え if k % 2 == 1 and s[0] < 0: for i in range(k): ans = ans * s[i] % mod print(ans) exit()#終了 l = 0 r = n - 1 #次の処理のための計算 (kが奇数だった場合) #この処理の必要性 #奇数個だった場合三個のうち二つで正の数の最大値を作れば良い if k % 2 == 1: ans = ans * s[l] l += 1 for _ in range(k // 2): ml = s[l] * s[l + 1] mr = s[r] * s[r - 1] if ml > mr: ans = ans * ml % mod l += 2 else: ans = ans * mr % mod r -= 2 print(ans)
m = map(int,raw_input().split()) print m[0]*m[1],2*(m[0]+m[1])
0
null
4,845,024,654,590
112
36
class Dice: def __init__(self, ary): # [top, front, right, left, back, bottom] self.__top = ary[0] self.__fro = ary[1] self.__rit = ary[2] self.__lft = ary[3] self.__bak = ary[4] self.__btm = ary[5] def turn_e(self): # 右に転がる self.__top, self.__lft, self.__btm, self.__rit = \ self.__lft, self.__btm, self.__rit, self.__top def turn_s(self): # 手前に転がる self.__top, self.__fro, self.__btm, self.__bak = \ self.__bak, self.__top, self.__fro, self.__btm def turn_w(self): # 左に転がる self.__top, self.__lft, self.__btm, self.__rit = \ self.__rit, self.__top, self.__lft, self.__btm def turn_n(self): # 奥に転がる self.__top, self.__fro, self.__btm, self.__bak = \ self.__fro, self.__btm, self.__bak, self.__top def spin_r(self): # 右回転 self.__rit, self.__fro, self.__lft, self.__bak = \ self.__bak, self.__rit, self.__fro, self.__lft def spin_l(self): # 左回転 self.__rit, self.__fro, self.__lft, self.__bak = \ self.__fro, self.__lft, self.__bak, self.__rit def is_same_setting(self, ary): # 同じように置いているか if self.__top == ary[0] and self.__fro == ary[1] and self.__rit == ary[2] and \ self.__lft == ary[3] and self.__bak == ary[4] and self.__btm == ary[5]: return True def is_same_dice(self, ary): # 回転させて同じダイスになるか is_same = False for _ in range(2): for _ in range(3): for _ in range(4): if self.is_same_setting(ary): is_same = True self.spin_r() self.turn_n() self.spin_r() self.turn_s() return is_same def show_top(self): # 上面の値を表示 return self.__top surfaces = list(map(int,input().split())) instructions = list(input()) dice = Dice(surfaces) for inst in instructions: if inst == "E": dice.turn_e() if inst == "N": dice.turn_n() if inst == "S": dice.turn_s() if inst == "W": dice.turn_w() print(dice.show_top())
# AOJ ITP1_11_A # サイコロ。 def intinput(): a = input().split() for i in range(len(a)): a[i] = int(a[i]) return a class dice: def __init__(self): self.data = [0 for i in range(8)] a = intinput() for i in range(1, 7): self.data[i] = a[i - 1] # 1, 2, 3, 4, 5, 6. for i in range(6): self.data[0] += a[i] # 各位の和を0に。 self.data[7] = a[0] * a[5] + a[1] * a[4] + a[2] * a[3] # 対面同士の積の和。 # dataの1, 2, 3, 4, 5, 6というindexが位置を示す。 # 回転するとそれらの位置にある数が変化するイメージ。 def d_read(self, a): # aはたとえば5, 1, 2, 6のような配列 b = [] for i in range(len(a)): b.append(self.data[a[i]]) return b def d_write(self, b, c): # cはたとえば1, 2 ,6, 5のような配列で、そこにbの中身を落とす。 if len(b) != len(c): return # 要求と異なる。 for i in range(len(b)): self.data[c[i]] = b[i] def roll(self, direction): # directionが'S', 'E', 'W', 'N'. # 'S', 'N'では3と4が不変。 'E'と'W'では2と5が不変。 if direction == 'S': self.d_write(self.d_read([5, 1, 2, 6]), [1, 2, 6, 5]) elif direction == 'N': self.d_write(self.d_read([2, 6, 5, 1]), [1, 2, 6, 5]) elif direction == 'W': self.d_write(self.d_read([3, 6, 4, 1]), [1, 3, 6, 4]) elif direction == 'E': self.d_write(self.d_read([4, 1, 3, 6]), [1, 3, 6, 4]) def get_upper(self): return self.data[1] def main(): d = dice() command = input() for i in range(len(command)): d.roll(command[i]) print(d.get_upper()) if __name__ == "__main__": main()
1
233,945,655,218
null
33
33
n = int(input()) a = [] xy = [[] for i in range(n)] for i in range(n): a.append(int(input())) for j in range(a[i]): xy[i].append(list(map(int, input().split()))) ans = 0 for i in range(2**n): tf = [False for j in range(n)] for j in range(n): if (i>>j)&1: tf[j] = True flag = False for j in range(n): for k in range(a[j]): if tf[j]: if xy[j][k][1] != tf[xy[j][k][0]-1]: flag = True break if flag: break else: ans = max(ans, tf.count(True)) print(ans)
n = int(input()) ans = [1]*n T = [[-1]*n for _ in range(n)] for ni in range(n): a = int(input()) for ai in range(a): x, y = map(int,input().split()) T[ni][x-1] = y mx = 0 for i in range(pow(2,n)): tmx = -1 B = bin(i)[2:].zfill(n) S = [i for i,b in enumerate(B) if b=='1'] for s in S: _Ts = [i for i,t in enumerate(T[s]) if t==1] _Tf = [i for i,t in enumerate(T[s]) if t==0] if not (set(_Ts)<=set(S) and set(_Tf)&set(S)==set()): tmx = 0 break if tmx==-1: tmx=len(S) mx = max(mx, tmx) print(mx)
1
121,828,515,383,076
null
262
262
while 1: n,m=map(int, raw_input().split()) if n==m==0: break print ("#"*m+"\n")*n
while True: a,b=map(int,input().split()) if a==0 and b==0:break for i in range (a): print('#'*b) print()
1
757,286,306,322
null
49
49
N = int(input()) a = list(map(int, input().split())) num = 1 cnt = 0 for i in range(N): if a[i] == num: num += 1 else: cnt += 1 if cnt == N: print(-1) else: print(cnt)
n=int(input()) if n%2==1: x=((n//2)+1)/n print(x) else: print(1/2)
0
null
145,961,578,653,888
257
297
l,r,d = [int(x) for x in input().split(' ')] st = (l+d-1)//d en = r//d print(en-st+1)
a=input().split(' ') a[0]=int(a[0]) a[1]=int(a[1]) a[2]=int(a[2]) c=a[0] m=0 while c<a[1]+1: if c%a[2]==0: m=m+1 c=c+1 print(m)
1
7,508,646,066,560
null
104
104
n = int(input()) testimonies = [[] for i in range(n)] for idx1 in range(n): count = int(input()) for idx2 in range(count): x,y = map(int, input().split()) testimonies[idx1].append((x-1, y)) output = 0 for combination in range(2 ** n): consistent = True for index in range(n): if (combination >> index) & 1 == 0: continue for x,y in testimonies[index]: if (combination >> x) & 1 != y: consistent = False break if not consistent: break if consistent: output = max(output, bin(combination)[2:].count("1")) print(output)
N = int(input()) testimony = [[] for _ in range(N)] for i in range(N): num = int(input()) for j in range(num): person, state = map(int, input().split()) testimony[i].append([person-1, state]) honest = 0 for i in range(2**N): flag = 0 for j in range(N): if (i>>j)&1 == 1: # j番目は正直と仮定 for x,y in testimony[j]: if (i>>x)&1 != y: # j番目は正直だが矛盾を発見 flag = 1 break if flag == 0: # 矛盾がある場合はflag == 1になる honest = max(honest, bin(i)[2:].count('1')) # 1の数をカウントし最大となるものを選択 print(honest)
1
121,410,871,672,272
null
262
262
n=int(input()) ans=0 currentpower=0 for i in range(1,n+1): if i>=10**(currentpower+1): currentpower+=1 b=i%10 a=(i-i%(10**currentpower))//(10**currentpower) if b==0: continue if a==b: ans+=1 if currentpower>0: ans+=2 r=max(0,((i-(a*(10**currentpower))-b)//10)) ans+=2*r for j in range(0,currentpower-1): ans+=2*(10**j) elif a<b: for j in range(0,currentpower-1): ans+=2*(10**j) else: for j in range(0,currentpower): ans+=2*(10**j) print(ans)
while True: m, f, r = map(int, (input().split())) score = m + f if m == f == r == -1: break else: if m == -1 or f == -1: print("F") elif score >= 80: print("A") elif 80 > score >= 65: print("B") elif 65 > score >= 50: print("C") elif 50 > score >= 30 and r >= 50: print("C") elif 50 > score >= 30 and r < 50: print("D") else: print("F")
0
null
43,925,557,467,936
234
57
S = input() print("ABC" if S[1] == "R" else "ARC" )
import functools import operator n = functools.partial(functools.reduce, operator.mul) N,K = map(int,input().split()) A = list(map(int,input().split())) # print(n(A)) for i in range(K,N): if A[i-K] < A[i]: print("Yes") else: print("No")
0
null
15,699,264,940,850
153
102
import itertools n = int(input()) answers = [] for i in range(n): a = int(input()) answers.append((i, [])) for j in range(a): (x, y) = [int(k) for k in input().split()] answers[i][1].append((x, y)) lst = [] combi_lst = [i for i in range(n)] for i in range(n, -1, -1): for balls in itertools.combinations(combi_lst, i): lst = [True if j in balls else False for j in range(n)] success = True for i, ans in enumerate(answers): if lst[i] == False: continue for x, y in ans[1]: if y == 1 and lst[x - 1] == False: success = False if y == 0 and lst[x - 1] == True: success = False if success: print(sum(lst)) exit()
s = input() t = input() l = [] for i in range(len(s)-len(t)+1): cha = 0 for j in range(len(t)): if s[j+i] == t[j]: cha += 1 l.append(cha) print(len(t)-max(l))
0
null
62,754,453,371,698
262
82
input() a=list(map(int, input().split())) a.reverse() print(*a)
N = int(input()) A = [int(i) for i in input().split()] S = [] e = 0 for i in A: e += i S.append(e) ans = 0 for i in range(N-1): ans += A[i]%(10**9+7)*((S[N-1] - S[i])%(10**9+7)) print(ans%(10**9+7))
0
null
2,427,050,753,348
53
83
def gcd(a,b): while True: # print(a,b) if a >= b: x = a y = b else: x = b y = a mod = x%y if mod == 0: return y else: a = y b = mod A,B = list(map(int,input().split())) ans = int(A*B / gcd(A,B)) print(ans)
s=input() for i in range(len(s)): print('x',end='')
0
null
92,993,327,713,058
256
221
import sys import collections #https://python.ms/factorize/ def factorize(n): b = 2 fct = [] while b * b <= n: while n % b == 0: n //= b fct.append(b) b = b + 1 if n > 1: fct.append(n) return fct def main(): input = sys.stdin.readline change_to_count_list = [] for i in range(62): if i == 0: change_to_count_list.append(1) else: change_to_count_list.append(change_to_count_list[i-1]+i+1) N = int(input()) yakusu_list = factorize(N) c = collections.Counter(yakusu_list) result = 0 for count in c.values(): for i in range(62): if change_to_count_list[i] == count: if i == 0: result += 1 break else: result += i + 1 break elif change_to_count_list[i-1] < count and change_to_count_list[i] > count: result += i break print(result) if __name__ == '__main__': main()
X = input().split() ans = X.index('0') print(int(ans)+1)
0
null
15,131,316,297,120
136
126
""" 1 4 2 3 5 6 """ class Dice: def __init__(self, top, front, right, left, rear, bottom): self.top = top self.front = front self.right = right self.left = left self.rear = rear self.bottom = bottom def N(self): self.tmp = self.top self.top = self.front self.front = self.bottom self.bottom = self.rear self.rear = self.tmp def E(self): self.tmp = self.top self.top = self.left self.left = self.bottom self.bottom = self.right self.right = self.tmp def S(self): self.tmp = self.top self.top = self.rear self.rear = self.bottom self.bottom = self.front self.front = self.tmp def W(self): self.tmp = self.top self.top = self.right self.right = self.bottom self.bottom = self.left self.left = self.tmp def show_numbers(self): print("上:%d"% self.top) print("前:%d"% self.front) print("右:%d"% self.right) print("左:%d"% self.left) print("後:%d"% self.rear) print("底:%d"% self.bottom) def show_top(self): print("%d" % self.top) # ここからプログラム buf = input().split(" ") dice1 = Dice(int(buf[0]), int(buf[1]), int(buf[2]), int(buf[3]), int(buf[4]), int(buf[5])) buf = input() for ch in buf: if ch == "N": dice1.N() elif ch == "E": dice1.E() elif ch == "S": dice1.S() elif ch == "W": dice1.W() dice1.show_top()
def roll(l, command): ''' return rolled list l : string list command: string ''' res = [] i = -1 if command =='N': res = [l[i+2], l[i+6], l[i+3], l[i+4], l[i+1], l[i+5]] if command =='S': res = [l[i+5], l[i+1], l[i+3], l[i+4], l[i+6], l[i+2]] if command =='E': res = [l[i+4], l[i+2], l[i+1], l[i+6], l[i+5], l[i+3]] if command =='W': res = [l[i+3], l[i+2], l[i+6], l[i+1], l[i+5], l[i+4]] return res faces = input().split() commands = list(input()) for command in commands: faces = roll(faces, command) print(faces[0])
1
228,947,021,550
null
33
33
def encode(s): val = 0 min_val = 0 for c in s: if c == '(': val += 1 else: val -= 1 min_val = min(min_val, val) return [min_val, val] def check(s): h = 0 for p in s: b = h + p[0] if b < 0: return False h += p[1] return True n = int(input()) ls = [] rs = [] l_total = 0 r_total = 0 for _ in range(n): si = encode(input()) if si[1] > 0: ls.append(si) l_total += si[1] else: si[0] -= si[1] si[1] *= -1 rs.append(si) r_total += si[1] list.sort(ls, reverse=True) list.sort(rs, reverse=True) if check(ls) and check(rs) and l_total == r_total: print("Yes") else: print("No")
from sys import stdin def main(): readline = stdin.readline n = int(readline()) s = tuple(readline().strip() for _ in range(n)) plus, minus = [], [] for c in s: if 2 * c.count('(') - len(c) > 0: plus.append(c) else: minus.append(c) plus.sort(key = lambda x: x.count(')')) minus.sort(key = lambda x: x.count('('), reverse = True) plus.extend(minus) sum = 0 for v in plus: for vv in v: sum = sum + (1 if vv == '(' else -1) if sum < 0 : return print('No') if sum != 0: return print('No') return print('Yes') if __name__ == '__main__': main()
1
23,570,838,246,242
null
152
152
x = int(input()) print("Yes" if x >= 30 else "No")
how_many = int(input()) results = [] index = 0 numbers = {index+1:int(item) for index,item in zip(range(how_many),input().split())} for key_value in numbers.items(): if key_value[0] % 2 == 1 and key_value[1] % 2 == 1: results.append(True) print(len(results))
0
null
6,749,174,334,612
95
105
print(+(input()<'1'))
print("0" if input()=="1" else "1")
1
2,918,589,217,180
null
76
76
moji = input() if moji[len(moji)-1] == 's': moji += 'es' else : moji += 's' print(moji)
s = input() if s[-1] == 's': s = s + 'e' s = s + 's' print(s)
1
2,407,063,685,378
null
71
71
import math def rot60(s,t): v=t-s a=1/2+complex(0,(math.sqrt(3)/2)) return v*a+s def puts(p): x=p.real y=p.imag print('{real} {imaginary}'.format(real=x,imaginary=y)) def koch(p1, p2, n): if n==0: return s=(p2-p1)*(1/3)+p1 t=(p2-p1)*(2/3)+p1 u=rot60(s,t) koch(p1,s,n-1) puts(s) koch(s,u,n-1) puts(u) koch(u,t,n-1) puts(t) koch(t,p2,n-1) n=int(input()) s=complex(0,0) t=complex(100,0) puts(s) koch(s,t,n) puts(t)
# AtCoder Beginner Contest 146 # F - Sugoroku # https://atcoder.jp/contests/abc146/tasks/abc146_f import sys N, M = map(int, input().split()) *S, = map(int, input()) S.reverse() i = 0 ans = [] while i < N: for m in range(M, 0, -1): if i+m <= N and S[i+m] == 0: i += m ans += [m] break else: print(-1) sys.exit() print(*ans[::-1])
0
null
69,611,889,787,398
27
274
a,b=map(int,input().split()) if a<b: print(str(a)*b) elif a>b: print(str(b)*a) elif a==b: print(str(a)*b)
a, b = input().split() print(sorted([a*int(b), b*int(a)])[0])
1
84,143,444,107,480
null
232
232
A, B, H, M = list(map(int, input().split())) m = 360/60 * M h = 360/12 * (H + M/60) deg = abs(h-m) if deg>180: deg = 360-deg import math Csq = A**2 + B**2 - 2*A*B*math.cos(math.radians(deg)) print('{:.10f}'.format(math.sqrt(Csq)))
N = int(input()) if (N%2 == 1): print(0) elif N == 0: print(0) else: N //= 2 res = 0 div_coef = 1 while True: tmp_add = N // (5 ** div_coef) res += int(tmp_add) div_coef += 1 # print(int(tmp_add)) if tmp_add < 1: break # print(N) print(int(res))
0
null
68,031,541,871,820
144
258
# Falling Asleep # prepare input N = int(input()) # データ数 playlist = [] # プレイリスト for i in range(N): s, t = input().split() t = int(t) playlist.append([s,t]) X = input() # 寝落ちした時の曲 # Xのある要素を線形探索 O(N) p = 0 for i in range(N): if playlist[i][0]==X: p = i break # 時間の集計 playlist = playlist[p+1:] # プレイリストのカット time = 0 for i in playlist: time = time + i[1] # 結果の出力 print(time)
N = int(input()) lst = [] for i in range(N): lst.append(input().split()) X = input() index = 0 for i in range(N): if lst[i][0] == X: index = i break ans = 0 for i in range(index + 1, N): ans += int(lst[i][1]) print(ans)
1
96,516,769,486,720
null
243
243
class Reader: def __init__(self): self.l = 0 self.r = 0 def __call__(self, s): l, r = s.split() if l > r: self.l += 3 elif l < r: self.r += 3 else: self.l += 1 self.r += 1 def __str__(self): return "{} {}".format(self.l, self.r) reader = Reader() n = int(input()) for _ in range(n): reader(input()) print(reader)
h, a = list(map(int, input().split())) b = h/a if int(b) == b: print(int(b)) else: print(int(b)+1)
0
null
39,454,887,520,340
67
225
import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_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(str, input().split())) def ZIP(n): return zip(*(MAP() for _ in range(n))) sys.setrecursionlimit(10 ** 9) INF = float('inf') mod = 10 ** 9 + 7 #import numpy as np from decimal import * K = INT() if K <= 9: print(K) exit() n = [-1]*11 n[-1] = 9 cnt = 9 def DFS(n): global cnt for i in range(1, 11): if n[-i] == 9: continue elif n[-i-1] != -1 and n[-i] == n[-i-1]+1: continue else: if n[-i] == -1: n[-i] = 1 else: n[-i] += 1 for j in range(i-1, 0, -1): n[-j] = max(0, n[-j-1] - 1) break cnt += 1 if cnt == K: print(*n[bisect(n, -1):], sep = "") exit() DFS(n) DFS(n)
H, W = map(int, input().split()) stage = [] scores = [] for _ in range(H): stage.append(list(input())) scores.append([float('inf')] * W) if stage[0][0] == '#': scores[0][0] = 1 else: scores[0][0] = 0 move = [[0, 1], [1, 0]] for y in range(H): for x in range(W): for dx, dy in move: nx, ny = x + dx, y + dy if H <= ny or W <= nx: continue if stage[ny][nx] == '#' and stage[y][x] == '.': scores[ny][nx] = min(scores[ny][nx], scores[y][x] + 1) else: scores[ny][nx] = min(scores[ny][nx], scores[y][x]) # print(*scores, sep='\n') print(scores[-1][-1])
0
null
44,546,405,999,230
181
194
n=int(input()) T,H=0,0 for i in range(n): t_card,h_card=input().split() if t_card>h_card: T+=3 elif t_card<h_card: H+=3 else: T+=1 H+=1 print(str(T)+" "+str(H))
def main(): S = input() N = len(S) ret = [0] * (N + 1) for i, c in enumerate(S, start=1): if c == '<': ret[i] = max( ret[i], ret[i - 1] + 1 ) for i, c in enumerate(reversed(S), start=1): i = N - i if c == '>': ret[i] = max( ret[i], ret[i + 1] + 1 ) print(sum(ret)) if __name__ == '__main__': main()
0
null
79,559,959,027,090
67
285
ALPHA = input() if ALPHA.isupper(): print("A") else: print("a")
def cardgame(animal1, animal2, taro, hanako): if animal1==animal2: return [taro+1, hanako+1] anim_list = sorted([animal1, animal2]) if anim_list[0]==animal1: return [taro, hanako+3] else: return [taro+3, hanako] n = int(input()) taro, hanako = 0, 0 for i in range(n): data = input().split() result = cardgame(data[0], data[1], taro, hanako) taro, hanako = result[0], result[1] print(taro, end=" ") print(hanako)
0
null
6,641,048,457,216
119
67
X = int(input()) print('Yes' if X >= 30 else 'No')
n = input() daylist = {'SUN':7,'MON':6,'TUE':5,'WED':4,'THU':3,'FRI':2,'SAT':1} print(daylist[n])
0
null
69,662,548,286,748
95
270
# Dice I class Dice: def __init__(self, a1, a2, a3, a4, a5, a6): # サイコロを縦横にたどると書いてある数字(index1は真上、index3は真下の数字) self.v = [a5, a1, a2, a6] # 縦方向 self.h = [a4, a1, a3, a6] # 横方向 # print(self.v, self.h) # サイコロの上面の数字を表示 def top(self): return self.v[1] # サイコロを北方向に倒す def north(self): newV = [self.v[1], self.v[2], self.v[3], self.v[0]] self.v = newV self.h[1] = self.v[1] self.h[3] = self.v[3] return self.v, self.h # サイコロを南方向に倒す def south(self): newV = [self.v[3], self.v[0], self.v[1], self.v[2]] self.v = newV self.h[1] = self.v[1] self.h[3] = self.v[3] return self.v, self.h # サイコロを東方向に倒す def east(self): newH = [self.h[3], self.h[0], self.h[1], self.h[2]] self.h = newH self.v[1] = self.h[1] self.v[3] = self.h[3] return self.v, self.h # サイコロを西方向に倒す def west(self): newH = [self.h[1], self.h[2], self.h[3], self.h[0]] self.h = newH self.v[1] = self.h[1] self.v[3] = self.h[3] return self.v, self.h d = input().rstrip().split() dice1 = Dice(d[0], d[1], d[2], d[3], d[4], d[5]) command = list(input().rstrip()) # print(command) for i, a in enumerate(command): if a == 'N': dice1.north() elif a == 'S': dice1.south() elif a == 'E': dice1.east() elif a == 'W': dice1.west() print(dice1.top())
""" 1 4 2 3 5 6 """ class Dice: def __init__(self, top, front, right, left, rear, bottom): self.top = top self.front = front self.right = right self.left = left self.rear = rear self.bottom = bottom def N(self): self.tmp = self.top self.top = self.front self.front = self.bottom self.bottom = self.rear self.rear = self.tmp def E(self): self.tmp = self.top self.top = self.left self.left = self.bottom self.bottom = self.right self.right = self.tmp def S(self): self.tmp = self.top self.top = self.rear self.rear = self.bottom self.bottom = self.front self.front = self.tmp def W(self): self.tmp = self.top self.top = self.right self.right = self.bottom self.bottom = self.left self.left = self.tmp def show_numbers(self): print("上:%d"% self.top) print("前:%d"% self.front) print("右:%d"% self.right) print("左:%d"% self.left) print("後:%d"% self.rear) print("底:%d"% self.bottom) def show_top(self): print("%d" % self.top) # ここからプログラム buf = input().split(" ") dice1 = Dice(int(buf[0]), int(buf[1]), int(buf[2]), int(buf[3]), int(buf[4]), int(buf[5])) buf = input() for ch in buf: if ch == "N": dice1.N() elif ch == "E": dice1.E() elif ch == "S": dice1.S() elif ch == "W": dice1.W() dice1.show_top()
1
226,411,815,150
null
33
33
W = input().casefold() count=0 while True: line = input() if line == "END_OF_TEXT": break line = line.casefold() word = line.split() count += word.count(W) print(count)
n = int(input()) s = input() sr = [] sg = [] sb = [0] * n kcnt = 0 for i in range(n): if s[i] == 'R': sr.append(i) elif s[i] == 'G': sg.append(i) else: sb[i] = 1 kcnt += 1 ans = 0 for i in sr: for j in sg: nki = j*2 - i nkj = i*2 - j nkk = (j+i) ans += kcnt if 0<= nki < n and sb[nki] == 1: ans -= 1 if 0<= nkj < n and sb[nkj] == 1: ans -= 1 if nkk%2 == 0 and 0<= (nkk//2) < n and sb[nkk//2] == 1: ans -= 1 print(ans)
0
null
19,059,088,414,002
65
175
def gcd(x, y): if y == 0: return x else: return gcd(y, x % y) def main(): l, r = tuple(map(int, input().split(' '))) print(gcd(l, r)) main()
def gcd(a,b): if a < b: a,b = b,a while b != 0: a,b = b,a%b return a a,b = map(int,raw_input().split()) print gcd(a,b)
1
7,682,370,048
null
11
11
import sys input = sys.stdin.readline H, W, M = map(int, input().split()) bombs = [] rows = [[]for _ in range(H)] cols = [[]for _ in range(W)] for _ in range(M): h, w = map(lambda x: int(x)-1, input().split()) bombs.append((h, w)) rows[h].append(w) cols[w].append(h) max_row = 0 row_idx = set() for i, row in enumerate(rows): if max_row < len(row): max_row = len(row) row_idx = {i} continue elif max_row == len(row): row_idx.add(i) max_col = 0 col_idx = set() for i, col in enumerate(cols): if max_col < len(col): max_col = len(col) col_idx = {i} continue elif max_col == len(col): col_idx.add(i) ans = max_row+max_col points = len(row_idx)*len(col_idx) if M < points: print(ans) else: for i, j in bombs: if i in row_idx and j in col_idx: points -= 1 if points == 0: print(ans-1) else: print(ans)
from decimal import Decimal import math def main(): x = Decimal(input()) y = 0 p = Decimal(100) gr = Decimal('1.01') while p < x: p *= gr p = math.floor(p) y += 1 print(y) main()
0
null
15,847,288,503,662
89
159
from itertools import accumulate n = int(input()) song= [] time = [] for i in range(n): s, t = input().split() song.append(s) time.append(int(t)) time_acc = list(accumulate(time)) x = input() print(time_acc[n - 1] - time_acc[song.index(x)])
n, m, k = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) a_sums, b_sums = [0], [0] for i in range(n): a_sums.append(a_sums[i] + a[i]) for i in range(m): b_sums.append(b_sums[i] + b[i]) ans = 0 j = m for i in range(n + 1): if a_sums[i] > k: break while a_sums[i] + b_sums[j] > k: j -= 1 ans = max(ans, i + j) print(ans)
0
null
53,658,013,046,750
243
117
s=input();print("Yes"if s=="hi"*(len(s)//2)else"No")
n = int(input()) line = [] for _ in range(n): x, l = map(int, input().split()) s, g = x-l, x+l line.append([g, s]) line.sort() ans = 1 now_g = line[0][0] for g, s in line[1:]: if now_g <= s: ans += 1 now_g = g print(ans)
0
null
71,502,579,255,250
199
237
import sys class UnionFind(): def __init__(self, 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 N, M = map(int, input().split()) info = [()] * M for i in range(M): info[i] = map(int, input().split()) uf = UnionFind(N) for a, b in info: a -= 1; b -= 1 uf.union(a, b) ans = min(uf.parents) print(-ans)
#D from queue import Queue N,M=map(int,input().split()) Friend=[[] for i in range(N+1)] for i in range(M): a,b=map(int,input().split()) Friend[a].append(b) Friend[b].append(a) Flag=[False for i in range(N+1)] ans=1 for i in range(1,N+1): if Flag[i]: continue q=Queue() q.put(i) cnt=1 while not q.empty(): st=q.get() Flag[st]=True for j in Friend[st]: if Flag[j]: continue cnt+=1 Flag[j]=True q.put(j) ans=max(ans,cnt) print(ans)
1
3,950,006,163,752
null
84
84
import sys read = sys.stdin.read readlines = sys.stdin.readlines def main(): n, m = map(int, input().split()) h = tuple(map(int, input().split())) edges = {e:[] for e in range(n)} for _ in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 edges[a].append(h[b]) edges[b].append(h[a]) r = 0 for i, he in enumerate(h): if not edges[i]: r += 1 else: r += he > max(edges[i]) print(r) if __name__ == '__main__': main()
A,B,C,D=map(int,input().split()) while A>0 and C>0: C=C-B A=A-D if C<=0: print('Yes') break if A<=0: print('No') break
0
null
27,286,037,773,750
155
164
#!/usr/bin/env python3 # Generated by https://github.com/kyuridenamida/atcoder-tools from typing import * import collections import functools import itertools import math import sys INF = float('inf') YES = "Yes" # type: str NO = "No" # type: str def solve(N: int): return [NO, YES][N in [i * j for i in range(1, 10) for j in range(i, 10)]] def main(): sys.setrecursionlimit(10 ** 6) def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() N = int(next(tokens)) # type: int print(f'{solve(N)}') if __name__ == '__main__': main()
def main(): H, N = map(int, input().split()) A = list(map(int, input().split())) s = sum(A) if H > s: print('No') else: print('Yes') main()
0
null
119,120,212,465,880
287
226
n=int(input()) t=0 flag=False for i in range(1,10): for j in range(1,10): if n==i*j: print('Yes') t+=1 flag=True break if flag: break if t==0: print('No')
n = int(input()) table = [1, 2, 3, 4, 5, 6, 7, 8, 9] flag = False for a in range(1, 10): b = n / a if(b in table): flag = True break print("Yes" if flag else "No")
1
159,619,924,535,838
null
287
287
_, K, *H = map(int, open(0).read().split()) print(len(tuple(filter(lambda h: h >= K, H))))
import sys sys.setrecursionlimit(10 ** 7) read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(input()) A = list(map(int, input().split())) A_and_i = [[a, i] for i, a in enumerate(A)] A_and_i.sort(reverse=True) DP = [[0] * (N + 1) for _ in range(N + 1)] for i in range(N): a, idx = A_and_i[i] for j in range(N): # 右に持っていく if j <= i: DP[i + 1][j] = max(DP[i + 1][j], DP[i][j] + a * abs(N - 1 - (i - j) - idx)) DP[i + 1][j + 1] = max(DP[i + 1][j + 1], DP[i] [j] + a * abs(idx - j)) ans = max(DP[N]) print(ans)
0
null
106,567,840,621,328
298
171
first_line = raw_input().split(" ") n = int(first_line[0]) m = int(first_line[1]) l = int(first_line[2]) array_a = [] array_b = [] for i in xrange(n): line = map(int, raw_input().split(" ")) array_a.append(line) for i in xrange(m): line = map(int, raw_input().split(" ")) array_b.append(line) # print array_a # print array_b array_c = [] for i in xrange(n): line = [] for j in xrange(l): sum = 0 for k in xrange(m): sum += array_a[i][k] * array_b[k][j] line.append(sum) array_c.append(line) for i in xrange(n): print " ".join(map(str, array_c[i]))
h,n= map(int, input().split()) p = [list(map(int, input().split())) for _ in range(n)] m = 10**4 dp = [0]*(h+m+1) for i in range(m+1,h+m+1): dp[i] = min(dp[i-a] + b for a,b in p) print(dp[h+m])
0
null
41,075,988,362,528
60
229
# # author Sidratul # if __name__ == '__main__': n = list(input()) n = sum([int(i) for i in n]) if n % 9 == 0: print('Yes') else: print('No')
val = input().split(' ') N = int(val[0]) A = int(val[1]) B = int(val[2].strip()) if (B - A) % 2 == 0: print((B-A)//2) else: diff = N - B if A - 1 > N - B else A - 1 flip = diff + 1 distance = (B - A - 1) // 2 print(flip + distance)
0
null
57,129,426,974,360
87
253
N,K = [int(i) for i in input().split()] H = [int(i) for i in input().split()] ans = 0 for i in range(N): if K <= H[i]: ans += 1 print(ans)
#!/usr/bin/env python3 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N,K = map(int,readline().split()) H = list(map(int,readline().split())) ans = 0 for h in H: if h >= K: ans += 1 print(ans)
1
178,653,675,106,592
null
298
298
x = list(map(int,input().split())) a = x[0] b = x[1] if(2*b < a): print(a-2*b) else: print(0)
class Queue: queue_list = [] def enqueue(self, a): self.queue_list.append(a) def dequeue(self): return self.queue_list.pop(0) def isEmpty(self): return len(self.queue_list) == 0 n, q = list(map(lambda x: int(x), input().strip().split())) queue = Queue() for i in range(n): queue.enqueue(input().strip().split()) sum_time = 0 while not queue.isEmpty(): name, time = queue.dequeue() if int(time) <= q: sum_time += int(time) print(name + ' ' + str(sum_time)) else: queue.enqueue([name, str(int(time) - q)]) sum_time += q
0
null
83,669,440,454,480
291
19
import sys input = sys.stdin.readline def main(): H, A = map(int, input().split()) answer = 0 while H > 0: H -= A answer += 1 print(answer) if __name__ == '__main__': main()
import sys K = int(sys.stdin.readline()) M = len(sys.stdin.readline())-1 N = K+M mod = 10**9+7 ans = pow(26, N, mod) class Data(): def __init__(self): self.power = 1 self.rev = 1 class Combi(): def __init__(self, N, mod): self.lists = [Data() for _ in range(N+1)] self.mod = mod for i in range(2, N+1): self.lists[i].power = ((self.lists[i-1].power)*i) % self.mod self.lists[N].rev = pow(self.lists[N].power, self.mod-2, self.mod) for j in range(N, 0, -1): self.lists[j-1].rev = ((self.lists[j].rev)*j) % self.mod def combi(self, K, R): if K < R: return 0 else: return ((self.lists[K].power)*(self.lists[K-R].rev)*(self.lists[R].rev)) % self.mod X = Combi(N, mod) for i in range(M): ans -= X.combi(N, i)*pow(25, N-i, mod) ans %= mod print(ans)
0
null
44,856,981,393,702
225
124