code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 6.82M
181,637B
⌀ | question_pair_id
float64 101M
180,471B
⌀ | code1_group
int64 2
299
| code2_group
int64 2
299
|
---|---|---|---|---|---|---|
import sys
n=input()
house=[[[],[],[]],[[],[],[]],[[],[],[]],[[],[],[]]]
for i in range(4):
for j in range(3):
for k in range(10):
house[i][j].append(0)
for i in range(n):
b,f,r,v=map(int,raw_input().split())
house[b-1][f-1][r-1]+=v
for i in range(4):
for j in range(3):
for k in range(10):
sys.stdout.write(' %d'%house[i][j][k])
print('')
if i!=3:
print('#'*20) | from collections import deque
n = int(input())
dlist = deque()
for i in range(n):
code = input().split()
if code[0] == "insert":
dlist.insert(0,code[1])
if code[0] == "delete":
try:
dlist.remove(code[1])
except:
continue
if code[0] == "deleteFirst":
dlist.popleft()
if code[0] == "deleteLast":
dlist.pop()
print(*dlist,sep=" ") | 0 | null | 570,681,522,178 | 55 | 20 |
s = input()
n = len(s)
s_re =s[::-1]
s_first = s[:(n-1)//2]
s_first_re = s_first[::-1]
s_second = s[(n+3)//2-1:]
s_second_re = s_second[::-1]
print(['No','Yes'][s == s_re and s_first==s_first_re and s_second == s_second_re]) | S=list(input())
N=len(S)
x=0
for i in range(int((N-1)/2)):
if S[i]!=S[-(i+1)]:
print("No")
break
elif i==int((N-1)/2)-1:
x+=1
import math
if x==1:
S_l=S[:int((N-1)/2)]
for i in range(int(math.ceil(len(S_l)/2))):
if S_l[i]!=S_l[-(i+1)]:
print("No")
break
elif i==int(math.ceil(len(S_l)/2))-1:
x+=1
if x==2:
S_m=S[int((N+3)/2)-1:N]
for i in range(int(math.ceil(len(S_m)/2))):
if S_m[i]!=S_m[-(i+1)]:
print("No")
break
elif i==int(math.ceil(len(S_m)/2))-1:
print("Yes") | 1 | 46,242,536,162,804 | null | 190 | 190 |
import sys
from collections import Counter
n = int(input())
D = list(map(int,input().split()))
if D[0] != 0 or D.count(0) != 1:
print(0)
sys.exit()
D = Counter(D)
L = sorted(D.items())
pk = 0
pv = 1
ans = 1
for i,j in L:
if i == 0:
continue
if i != pk+1:
print(0)
break
ans *= pv**j
ans %= 998244353
pk = i
pv = j
else:
print(ans) | x = int(input())
if x%100 == 0 or x%101 == 0 or x%102 == 0 or x%103 == 0 or x%104 == 0 or x%105 == 0:
print (1)
else:
for i in range(100000):
if 100*i <= x <= 105*i:
print (1)
exit ()
else:
print (0)
| 0 | null | 141,118,376,269,650 | 284 | 266 |
import math
mod = 1000000007
n = int(input())
zero = 0
dic = {}
dic[(0, 1.5)] = 0
dic[(1.5, 0)] = 0
for i in range(n):
ai, bi = map(int, input().split())
idx = (ai, bi)
if ai < 0:
ai, bi = -ai, -bi
if idx == (0, 0):
zero += 1
elif idx[0] == 0:
dic[(0, 1.5)] += 1
elif idx[1] == 0:
dic[(1.5, 0)] += 1
else:
g = math.gcd(abs(ai), abs(bi))
ai = ai // g
bi = bi // g
idx = (ai, bi)
if idx in dic:
dic[idx] += 1
else:
dic[idx] = 1
ans = 1
already = set([])
for key, value in dic.items():
if key in already: continue
a, b = key
if a == 1.5 or b == 1.5:
pair1 = dic[(0, 1.5)]
pair2 = dic[(1.5, 0)]
ans = (ans * (pow(2, pair1, mod)+pow(2, pair2, mod)-1)) % mod
already.add((0, 1.5))
already.add((1.5, 0))
else:
if b > 0: idx = (b, -a)
else: idx = (-b, a)
if idx in dic:
pair1 = dic[key]
pair2 = dic[idx]
ans = (ans * (pow(2, pair1, mod)+pow(2, pair2, mod)-1)) % mod
already.add(key)
already.add(idx)
else:
pair1 = dic[key]
ans = (ans * pow(2, pair1, mod)) % mod
already.add(key)
ans = (ans + zero - 1) % mod
print(ans) | #!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify
import itertools
import math, fractions
import sys, copy
def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))
def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")
def lcm(a, b): return a * b // math.gcd(a, b)
sys.setrecursionlimit(1000000)
class Eratosthenes:
# https://cp-algorithms.com/algebra/prime-sieve-linear.html
def __init__(self, n):
primes, lp = [], [0] * (n + 1)
for i in range(2, n + 1):
if lp[i] == 0:
primes.append(i)
lp[i] = i
for pj in primes:
if pj > lp[i] or i * pj > n: break
lp[i * pj] = pj
self.primes, self.lp = primes, lp
def is_prime(self, x): return self.lp[x] == x
def factors(self, x):
ret = []
while x > 1:
ret.append(self.lp[x])
x //= self.lp[x]
return ret
def main():
N = I()
A = LI()
era = Eratosthenes(1 + 10 ** 6)
cumgcd = reduce(lambda x,y: math.gcd(x, y), A)
s = set()
for ai in A:
for i in set(era.factors(ai)):
if i in s:
break
s.add(i)
else:
continue
break
else:
print("pairwise coprime")
return
if cumgcd == 1:
print("setwise coprime")
else:
print("not coprime")
if __name__ == '__main__':
main() | 0 | null | 12,546,220,579,080 | 146 | 85 |
import math
a,b,h,m = map(int,input().split())
ans_cos = math.cos(math.pi*(60*h-11*m)/360)
ans = math.sqrt(a**2+b**2-2*a*b*ans_cos)
print(ans) | import numpy as np
H,W = input().split()
H,W=int(H),int(W)
P=[0]*H
for i in range(H):
P[i] = input()
dp=np.zeros((H,W),dtype='u8')
if P[0][0]=='#':
dp[0][0]=1
else:
dp[0][0]=0
def DP(y,x):
global dp
if 0<=x<=W-1 and 0<=y<=H-1:
return dp[y][x]
else:
return 9999999
for l in range(1,H+W):
for i in range(l+1):
if i<H and l-i<W:
if P[i][l-i]=='#':
a=DP(i-1,l-i)
b=DP(i,l-i-1)
if a < 9999999:
if P[i-1][l-i]=='.':
a+=1
if b < 9999999:
if P[i][l-i-1]=='.':
b+=1
dp[i][l-i]=min(a,b)
else:
#print(i,l-i,DP(i-1,l-i),DP(i,l-i-1))
dp[i][l-i]=min(DP(i-1,l-i),DP(i,l-i-1))
print(dp[H-1][W-1]) | 0 | null | 34,471,414,592,408 | 144 | 194 |
def main():
import sys
input = sys.stdin.readline
from collections import Counter
class BIT:
def __init__(self,n):
self.size = n
self.tree = [Counter([]) for _ in range(n+1)]
def change(self,i,x,y):
while i <= self.size:
if x in self.tree[i]:
self.tree[i][x] -= 1
if y not in self.tree[i]:
self.tree[i][y] = 0
self.tree[i][y] += 1
i += i&-i
def sum(self,i):
res = Counter([])
while i > 0:
res += self.tree[i]
i -= i&-i
return res
N = int(input())
st = BIT(N)
S = list(input())
Q = int(input())
for i in range(N):
st.change(i+1," ",S[i])
for _ in range(Q):
q,a,b = input().split()
if q == "1":
st.change(int(a),S[int(a)-1],b)
S[int(a)-1] = b
else:
res = st.sum(int(b)) - st.sum(int(a)-1)
ans = 0
for v in res.values():
if v > 0:
ans += 1
print(ans)
main()
| def main():
k=int(input())
s=7
for i in range(10**6):
if s%k == 0:
print(i+1)
break
s = (s*10+7)%k
else:
print(-1)
if __name__ == "__main__":
main() | 0 | null | 34,216,858,439,192 | 210 | 97 |
from sys import stdin
import sys
import math
from functools import reduce
import itertools
n,k = [int(x) for x in stdin.readline().rstrip().split()]
h = [int(x) for x in stdin.readline().rstrip().split()]
if k<n:
h.sort()
print(sum(h[:n-k]))
else:
print(0) | n, k = map(int, input().split())
H = list(map(int, input().split()))
H.sort(reverse=True)
H = H[k:]
print(sum(H))
| 1 | 79,352,556,418,308 | null | 227 | 227 |
k=int(input())
count=1
num=7
for _ in range(k):
if num%k == 0:
print(count)
break
else:
count += 1
num = (num % k)*10 + 7
else:
print(-1) | i = count = 0
a = b = c = ''
line = input()
while line[i] != ' ':
a = a + line[i]
i += 1
i += 1
while line[i] != ' ':
b = b + line[i]
i += 1
i += 1
while i < len(line):
c = c + line[i]
i += 1
a = int(a)
b = int(b)
c = int(c)
while a <= b:
if c%a == 0:
count += 1
a += 1
print(count) | 0 | null | 3,372,757,337,310 | 97 | 44 |
#####
# B #
#####
N = input()
sum = sum(map(int,N))
if sum % 9 == 0:
print('Yes')
else:
print('No')
| X,K,D = map(int,input().split())
X = abs(X)
ans = 0
if (X // D) >= K:
ans = X - (K * D)
elif (X // D) % 2 == 0:
if K % 2 == 0:
ans = X % D
else:
ans = abs((X % D) - D)
else:
if K % 2 ==1:
ans = X % D
else:
ans = abs((X % D) - D)
print(ans) | 0 | null | 4,867,885,962,240 | 87 | 92 |
import math
T_1, T_2 = map(int, input().split())
A_1, A_2 = map(int, input().split())
B_1, B_2 = map(int, input().split())
ans = 0
if T_1 * A_1 + T_2 * A_2 == T_1 * B_1 + T_2 * B_2:
print("infinity")
else:
# 速いほうをAと仮定
if T_1 * A_1 + T_2 * A_2 < T_1 * B_1 + T_2 * B_2:
A_1, A_2, B_1, B_2 = B_1, B_2, A_1, A_2
if A_1 < B_1:
sa_12 = T_1 * A_1 + T_2 * A_2 - (T_1 * B_1 + T_2 * B_2) # 1サイクルでできる差
sa_1 = -T_1 * A_1 + T_1 * B_1 # T_1でできる差
if sa_1 % sa_12 == 0:
ans = int((sa_1 / sa_12)*2)
else:
kari = math.ceil(sa_1 / sa_12)
ans = (kari-1)*2+1
print(ans)
|
#atcoder
t1,t2=map(int,input().split())
a1,a2=map(int,input().split())
b1,b2=map(int,input().split())
d1=a1-b1
d2=a2-b2
if d1*d2>0:
print(0)
else:
if d1>0 and d2<0:
plus=d1*t1+d2*t2
if plus>0:
print(0)
elif plus==0:
print("infinity")
elif plus<0:
d=-plus
k=d1*t1
if k%d==0:
print(2*k//d)
else:
print(2*(k//d)+1)
else:
d1=-d1
d2=-d2
plus=d1*t1+d2*t2
if plus>0:
print(0)
elif plus==0:
print("infinity")
elif plus<0:
d=-plus
k=d1*t1
if k%d==0:
print(2*k//d)
else:
print(2*(k//d)+1)
| 1 | 131,433,790,532,010 | null | 269 | 269 |
import sys
def main():
input = sys.stdin.buffer.readline
a, b, c = map(int, input().split())
print("Yes" if 4 * a * b < (c - a - b) ** 2 and c - a - b > 0 else "No")
if __name__ == "__main__":
main()
| a, b, c = map(int, input().split())
d = c - a - b
if d >= 0 and d * d > 4 * a * b:
print("Yes")
else:
print("No")
| 1 | 51,638,245,923,744 | null | 197 | 197 |
while 1:
H, W = map(int, raw_input().split())
if H == W == 0:
break
for i in range(H):
if i % 2 == 0:
if W % 2 == 0:
print "#." * (W/2)
else:
print "#." * (W/2) + "#"
else:
if W % 2 == 0:
print ".#" * (W/2)
else:
print ".#" * (W/2) + "."
print "" | a=["#." * (300//2),".#" * (300//2)]*(300//2)
while True:
[h,w] = map(int, input().split())
if h==0 and w==0:
break
t = map(lambda x: x[0:w], (a[0:h]))
for i in t:
print(i)
print() | 1 | 871,410,022,980 | null | 51 | 51 |
s = []
while True:
x = int(input())
if x == 0:
break
s.append(x)
for (i,num) in enumerate(s):
print('Case {0}: {1}'.format(i+1,num))
| i = 1
while True :
x = input()
if (x == 0) :
exit()
print "Case %d: %d" % (i, x)
i += 1 | 1 | 473,549,601,860 | null | 42 | 42 |
n=int(input())
s=input()
ans=''
for i in s:
if ord(i)+n>ord('Z'):
ans+=chr(ord(i)+n-26)
else:
ans+=chr(ord(i)+n)
print(ans) | N, M, Q = map(int, input().split())
G = []
for i in range(Q):
a, b, c, d = map(int, input().split())
G.append([a, b, c, d])
ans = 0
def dfs(s):
global ans
if len(s) == N:
now = 0
for a, b, c, d in G:
if s[b - 1] - s[a - 1] == c:
now += d
ans = max(ans, now)
return
for i in range(s[-1], M):
dfs(s + [i])
s = [0]
dfs(s.copy())
print(ans)
| 0 | null | 80,870,809,184,230 | 271 | 160 |
def insertionsort(A, n, g, cnt):
for i in range(g, n):
v = A[i]
j = i - g
while (j >= 0 and A[j] > v):
A[j + g] = A[j]
j = j - g
cnt += 1
A[j + g] = v
return cnt
A = []
n = int(raw_input())
for i in range(n):
A.append(int(raw_input()))
cnt = 0
G = [1]
while G[-1] * 3 + 1 < n:
G.append(G[-1] * 3 + 1)
G.reverse()
m = len(G)
for i in range(m):
cnt = insertionsort(A, n, G[i], cnt)
print m
print " ".join(map(str, G))
print cnt
for num in A:
print num | def insert(A,n,g):
global cnt
for i in range(g,n):
v = a[i]
j = i-g
while(j>=0 and A[j]>v):
A[j+g] = A[j]
j = j-g
cnt+= 1
A[j+g] = v
def shell(A,n):
global cnt
cnt = 0
G = []
h = 1
while h <= n:
G.append(h)
h = 3*h+1
G.reverse()
m = len(G)
print(m)
print(" ".join(map(str,G)))
for i in G:
insert(A,n,i)
return cnt
n = int(input())
a = []
for i in range(n):
ai = int(input())
a.append(ai)
shell(a,n)
print(cnt)
for i in range(n):
print(a[i])
| 1 | 30,539,211,538 | null | 17 | 17 |
S = input()
N = len(S)
s = S[:(N-1)//2]
t = S[(N+3)//2-1:]
if s == t[::-1] and s == s[::-1] and t == t[::-1]:
ans = "Yes"
else:
ans = "No"
print(ans) | # B - Homework
# N M
N, M = map(int, input().split())
my_list = list(map(int, input().split(maxsplit=M)))
if N < sum(my_list):
answer = -1
else:
answer = N - sum(my_list)
print(answer)
| 0 | null | 39,248,626,948,750 | 190 | 168 |
t=0
h=0
for i in range(int(input())):
l=input().split()
if l[0]==l[1]:
t+=1
h+=1
elif l[0]>l[1]: t+=3
else: h+=3
print(t,h) | import sys
# C - Walking Takahashi
X, K, D = map(int, input().split())
if D * K <= abs(X):
print(abs(X) - D * K)
else:
distance = abs(X) % D
# 残りの移動回数
count = K - (abs(X) // D)
if count % 2 == 1:
print(abs(D - distance))
else:
print(distance) | 0 | null | 3,594,879,507,000 | 67 | 92 |
n=int(input())
a=list(map(int,input().split()))
q=int(input())
b=[0]*q
c=[0]*q
for i in range(q):
b[i],c[i]=map(int,input().split())
N=[0]*(10**5)
s=0
for i in range(n):
N[a[i]-1]+=1
s+=a[i]
for i in range(q):
s+=(c[i]-b[i])*N[b[i]-1]
N[c[i]-1]+=N[b[i]-1]
N[b[i]-1]=0
print(s) | from collections import Counter
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
ans = sum(A)
num = Counter(A)
for i in range(Q):
b,c = map(int,input().split())
ans += (c-b)*num[b]
num[c] += num[b]
num[b] = 0
print(ans) | 1 | 12,211,831,540,590 | null | 122 | 122 |
import sys
sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7
def input():
return sys.stdin.readline().strip()
class Combination:
"""
O(n)の前計算を1回行うことで,O(1)でnCr mod mを求められる
n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
使用例:
comb = Combination(1000000)
print(comb(5, 3)) # 10
"""
def __init__(self, n_max, mod=10 ** 9 + 7):
self.mod = mod
self.modinv = self.make_modinv_list(n_max)
self.fac, self.facinv = self.make_factorial_list(n_max)
def __call__(self, n, r):
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n - r] % self.mod
def make_factorial_list(self, n):
# 階乗のリストと階乗のmod逆元のリストを返す O(n)
# self.make_modinv_list()が先に実行されている必要がある
fac = [1]
facinv = [1]
for i in range(1, n + 1):
fac.append(fac[i - 1] * i % self.mod)
facinv.append(facinv[i - 1] * self.modinv[i] % self.mod)
return fac, facinv
def make_modinv_list(self, n):
# 0からnまでのmod逆元のリストを返す O(n)
modinv = [0] * (n + 1)
modinv[1] = 1
for i in range(2, n + 1):
modinv[i] = self.mod - self.mod // i * modinv[self.mod % i] % self.mod
return modinv
def main():
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
comb = Combination(n_max=10 ** 5)
ans = 0
for i in range(N - K + 1):
ans -= comb(N - 1 - i, K - 1) * A[i] % MOD
ans += comb(N - 1 - i, K - 1) * A[N - i - 1] % MOD
ans %= MOD
print(ans)
if __name__ == "__main__":
main()
| import sys,math,collections
from collections import defaultdict
#from itertools import permutations,combinations
def file():
sys.stdin = open('input.py', 'r')
sys.stdout = open('output.py', 'w')
def get_array():
l=list(map(int, input().split()))
return l
def get_2_ints():
a,b=map(int, input().split())
return a,b
def get_3_ints():
a,b,c=map(int, input().split())
return a,b,c
def sod(n):
n,c=str(n),0
for i in n:
c+=int(i)
return c
def getFloor(A, x):
(left, right) = (0, len(A) - 1)
floor = -1
while left <= right:
mid = (left + right) // 2
if A[mid] == x:
return A[mid]
elif x < A[mid]:
right = mid - 1
else:
floor = A[mid]
left = mid + 1
return floor
#file()
def main():
n=int(input())
l=get_array()
c=0
for i in range(0,n,2):
if(l[i]&1):
c+=1
print(c)
if __name__ == '__main__':
main()
| 0 | null | 51,890,360,774,740 | 242 | 105 |
N, A, B = map(int, input().split())
if (B - A) % 2 == 0:
print((B - A) // 2)
else:
# N に向かうことを考える
A_to_N_dis = N - B + 1
A_to_N = A + A_to_N_dis
tmp_ans = (N - A_to_N) // 2 + A_to_N_dis
# 1に向かうことを考える
B_to_1_dis = A - 1 + 1
B_to_1 = B - B_to_1_dis
ans = (B_to_1 - 1) // 2 + B_to_1_dis
print(min(tmp_ans, ans)) | N,A,B = map(int,input().split())
if A%2 != 0 and B%2 == 0:
ans = (B-A-1)//2 + min(A-1,N-B) + 1
elif A%2 == 0 and B%2 != 0:
ans = (B-A-1)//2 + min(A-1,N-B) + 1
else:
ans = (B-A)//2
print(ans) | 1 | 109,255,326,801,544 | null | 253 | 253 |
import sys
sys.setrecursionlimit(300000)
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI0(): return map(lambda s: int(s) - 1, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
def LMI0(): return list(map(lambda s: int(s) - 1, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')
N = I()
A = LMI()
ans = 0
for i, a in enumerate(A):
if i % 2 == 0 and a % 2 != 0:
ans += 1
print(ans) | import sys
while True:
a,b = map(int, raw_input().split())
if a ==0 and b == 0:
break
for i in range(a):
for j in range(b):
if i == 0 or i == a-1 or j == 0 or j == b-1:
sys.stdout.write("#")
else:
sys.stdout.write(".")
print
print | 0 | null | 4,332,730,295,310 | 105 | 50 |
import math
while 1:
n = int(input())
if n == 0:
break
s = list(map(int,input().split()))
m = sum(s) / len(s)
x = 0
for i in range(n):
x += (s[i] -m )**2 / n
a = math.sqrt(x)
print(a) | A, B, C = list(map(int, input().split()))
K = int(input())
res = 0
while True:
if B <= A:
B *= 2
res += 1
else:
break
while True:
if C <= B:
C *= 2
res += 1
else:
break
if res <= K:
print("Yes")
else:
print("No") | 0 | null | 3,518,217,370,966 | 31 | 101 |
from collections import deque
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
res = 0
for i in range(h):
for j in range(w):
if s[i][j] == "#":
continue
dist = [[-1] * w for _ in range(h)]
dist[i][j] = 0
d = deque()
d.append([i, j])
while d:
pos_x, pos_y = d.popleft()
dist_max = dist[pos_x][pos_y]
for k in range(4):
x, y = pos_x + dx[k], pos_y + dy[k]
if 0 <= x < h and 0 <= y < w and s[x][y] == "." and dist[x][y] == -1:
dist[x][y] = dist[pos_x][pos_y] + 1
d.append([x, y])
res = max(res, dist_max)
print(res) | h, w = map(int, input().split())
s = [input() for _ in range(h)]
def bfs(x, y):
q = []
dp = {}
def qpush(x, y, t):
if 0 <= x < w and 0 <= y < h and s[y][x] != '#' and (x, y) not in dp:
q.append((x, y))
dp[(x, y)] = t
qpush(x, y, 0)
while len(q) > 0:
(x, y) = q.pop(0)
qpush(x + 1, y, dp[(x, y)] + 1)
qpush(x, y - 1, dp[(x, y)] + 1)
qpush(x - 1, y, dp[(x, y)] + 1)
qpush(x, y + 1, dp[(x, y)] + 1)
return dp.get((x, y), 0)
t = 0
for y in range(h):
for x in range(w):
t = max(t, bfs(x, y))
print(t) | 1 | 94,887,866,046,740 | null | 241 | 241 |
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read
inp = sys.stdin.buffer.readline
from itertools import accumulate
def resolve():
N, K = map(int, inp().split())
A = list(map(int, inp().split()))
for _ in range(K):
imos_table = [0]*(N+1)
for i, a in enumerate(A):
# 配列の個数を超えないように注意
imos_table[max(i - a, 0)] += 1
imos_table[min(i + a + 1, N)] -= 1
A = list(accumulate(imos_table))[:-1]
if all([True if a == N else False for a in A]):
print(*A)
return
else:
print(*A)
if __name__ == "__main__":
resolve() | X = int(input())
A = 0
B = 0
if X >= 500:
A = X // 500
X = X % 500
if X >= 5:
B = X // 5
X = X % 5
print(A * 1000 + B * 5) | 0 | null | 28,971,497,058,882 | 132 | 185 |
m, d = input().split(' ')
M, D = input().split(' ')
if D == '1':
print(1)
else:
print(0) | import sys
import math
stdin = sys.stdin
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))
def ns(): return stdin.readline().rstrip() # ignore trailing spaces
N = ni()
AB_array = [na() for _ in range(N)]
# print(AB_array)
plus_dic = {}
minus_dic = {}
ans = 1
fish_count = 0
mod = 10 ** 9 + 7
zero_count = 0
for ab in AB_array:
a, b = ab
if a == 0 and b == 0:
zero_count += 1
continue
fish_count += 1
if a == 0:
vec = (0, 1)
if vec in plus_dic:
plus_dic[vec] += 1
else:
plus_dic[vec] = 1
continue
elif b == 0:
vec = (1, 0)
if vec in minus_dic:
minus_dic[vec] += 1
else:
minus_dic[vec] = 1
continue
c = math.gcd(a, b)
a = a // c
b = b // c
if a < 0:
a *= -1
b *= -1
if b > 0:
vec = (a, b)
if vec in plus_dic:
plus_dic[vec] += 1
else:
plus_dic[vec] = 1
else:
vec = (a, b)
if vec in minus_dic:
minus_dic[vec] += 1
else:
minus_dic[vec] = 1
# print(plus_dic, minus_dic, fish_count)
for k, vp in plus_dic.items():
x, y = k
if (y, -x) in minus_dic:
vm = minus_dic[(y, -x)]
ans = ans * (pow(2, vp, mod) + pow(2, vm, mod) - 1) % mod
fish_count -= (vp + vm)
ans = ans * pow(2, fish_count, mod) % mod
print((ans - 1 + zero_count) % mod)
| 0 | null | 72,880,778,345,078 | 264 | 146 |
i = 0
while True:
i += 1
num = raw_input()
if num == "0":
break
print "Case %d: %s" % (i,num) | s=1
while True:
i=input()
if i=='0': break
print('Case '+str(s)+':', i)
s+=1
| 1 | 482,686,239,904 | null | 42 | 42 |
import sys
while True:
height, width = map(int, raw_input().split())
if height == 0 and width == 0:
break
for i in range(height):
for j in range(width):
if j % 2 == 0 and i % 2 == 0: #even n, even n
sys.stdout.write("#")
elif j % 2 != 0 and i % 2 == 0: #even n, odd n
sys.stdout.write(".")
elif j % 2 == 0 and i % 2 != 0: #odd n, even n
sys.stdout.write(".")
elif j % 2 != 0 and i % 2 != 0: #odd n, odd n
sys.stdout.write("#")
print
print | class D_Linked_List:
class Node:
def __init__(self, key, next = None, prev = None):
self.next = next
self.prev = prev
self.key = key
def __init__(self):
self.nil = D_Linked_List.Node(None)
self.nil.next = self.nil
self.nil.prev = self.nil
def insert(self, key):
node_x = D_Linked_List.Node(key, self.nil.next, self.nil)
self.nil.next.prev = node_x
self.nil.next = node_x
def _listSearch(self, key):
cur_node = self.nil.next
while (cur_node != self.nil) and (cur_node.key != key):
cur_node = cur_node.next
return cur_node
def _deleteNode(self, node):
if node == self.nil:
return None
node.prev.next = node.next
node.next.prev = node.prev
def deleteFirst(self):
self._deleteNode(self.nil.next)
def deleteLast(self):
self._deleteNode(self.nil.prev)
def deleteKey(self, key):
node = self._listSearch(key)
self._deleteNode(node)
def show_keys(self):
cur_node = self.nil.next
keys_str = ''
while cur_node != self.nil:
keys_str += '{0} '.format(cur_node.key)
cur_node = cur_node.next
print(keys_str.rstrip())
import sys
d_ll = D_Linked_List()
for i in sys.stdin:
if 'insert' in i:
x = int(i.split()[1])
d_ll.insert(x)
elif 'deleteFirst' in i:
d_ll.deleteFirst()
elif 'deleteLast' in i:
d_ll.deleteLast()
elif 'delete' in i:
x = int(i.split()[1])
d_ll.deleteKey(x)
else:
pass
d_ll.show_keys() | 0 | null | 465,741,136,982 | 51 | 20 |
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')
N, K = map(int, input().split())
d = [0]*(K+1)
for i in range(1, K+1):
val = K//i
d[i] = pow(val, N, MOD)
# print(d)
for i in range(K, 0, -1):
# print('i', i)
for j in range(K//i, 1, -1):
# print(' j', j)
# print(i, i*j)
d[i] -= d[i*j]
# print(d)
res = 0
for i, v in enu(d):
res += i*v
res %= MOD
print(res)
| X = int(input())
q,mod = divmod(X,100)
if 5*q<mod:
print(0)
else:
print(1) | 0 | null | 81,720,609,925,734 | 176 | 266 |
print(int(input())*3.141592*2) | x=float(input())
p=2*3.14*x
A="dlfnsdfjsdjfsdfjsdfnksdkjnfjksndfkjnskjfkjsdkjfnskjdfknsdkjfskdnfkjsdn"
print(p) | 1 | 31,496,280,015,548 | null | 167 | 167 |
N = int(input())
slist = []
tlist = []
from itertools import accumulate
for _ in range(N):
s, t = input().split()
slist.append(s)
tlist.append(int(t))
cum = list(accumulate(tlist))
print(cum[-1]-cum[slist.index(input())])
| from collections import deque
if __name__ == '__main__':
n, q = map(int, input().split())
Q = deque()
for i in range(n):
name, time = input().split()
Q.append([name, int(time)])
sum = 0
while Q:
qt = Q.popleft()
if qt[1] <= q:
sum += qt[1]
print(qt[0], sum)
else:
sum += q
qt[1] -= q
Q.append(qt) | 0 | null | 48,320,184,401,580 | 243 | 19 |
def main():
match_count = int(input())
matches = [input().split() for i in range(match_count)]
taro_result = [3 if match[0] > match[1] else 1 if match[0] == match[1] else 0 for match in matches]
print('%d %d' % (sum(taro_result), sum(3 if item == 0 else 1 if item == 1 else 0 for item in taro_result)) )
main() | 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)) | 1 | 1,962,141,457,682 | null | 67 | 67 |
n,m=map(int,input().split())
a=list(map(int,input().split()))
c=0
for i in a:
if i>=sum(a)*(1/(4*m)):
c+=1
if c>=m:
print('Yes')
else:
print('No') | n,m = map(int,input().split())
a = list(map(int,input().split()))
b = [x for x in a if x >= sum(a)/4/m]
if len(b)>=m:
print("Yes")
else:
print("No")
| 1 | 38,603,367,031,230 | null | 179 | 179 |
a, b, c = (int(x) for x in input().split())
tmp = 0
for i in range(2):
if a > b:
tmp = a
a = b
b = tmp
if b > c:
tmp = b
b = c
c = tmp
if a > c:
tmp = a
a = c
c = tmp
print(a, b, c)
| a = map(int, raw_input().split())
for i in range(len(a)):
point = a[i:].index(min(a[i:])) + i
temp = a[i];
a[i] = a[point]
a[point] = temp
print '%s %s %s' % (str(a[0]), str(a[1]), str(a[2])) | 1 | 413,803,592,112 | null | 40 | 40 |
def main():
n = int(input())
print((n+1)//2)
if __name__ == "__main__":
main() | import math
n = int(input())
paper = math.ceil(n/2)
print(paper) | 1 | 59,107,920,923,140 | null | 206 | 206 |
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))
| #B
N=int(input())
C=[input() for i in range(N)]
AC=C.count('AC')
WA=C.count('WA')
TLE=C.count('TLE')
RE=C.count('RE')
print('AC x {}\nWA x {}\nTLE x {}\nRE x {}'.format(AC, WA, TLE, RE)) | 1 | 8,632,159,014,512 | null | 109 | 109 |
#ごり押し
from scipy.sparse import csr_matrix
from scipy.sparse.csgraph import dijkstra
import numpy as np
from collections import Counter
N, X, Y = map(int, input().split())
start = list(range(0, N-1)) + list(range(1, N)) + [X-1, Y-1]
end = list(range(1, N)) + list(range(0, N-1)) + [Y-1, X-1]
cost = [1] * len(start)
graph = csr_matrix((cost, (start, end)))
lengths = dijkstra(graph, directed = False)
c = Counter(lengths.astype(np.int64).reshape(-1))
for k in range(1, N):
print(c[k]//2)
| n = float(input())
print(n * n * n / 27) | 0 | null | 45,437,859,347,520 | 187 | 191 |
import math
r = float(input())
print("%.5f %.5f" % (math.pi*r *r, 2*math.pi*r))
| import sys
from bisect import bisect_left
input = sys.stdin.readline
def main():
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for a in range(N - 2):
for b in range(a + 1, N - 1):
x = bisect_left(L, L[a] + L[b])
ans += (x - 1 - b)
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 85,882,196,630,760 | 46 | 294 |
N = int(input())
ans = [0] * (N+1)
for i in range(N+1):
if i % 3 != 0 and i % 5 != 0 and i % 15 != 0:
ans[i] = ans[i-1] + i
else:
ans[i] = ans[i-1]
print(ans[-1])
| class Combination():
def __init__(self, n, mod=10**9+7):
self.mod = mod
self.fac = [1]*(n+1)
for i in range(1,n+1):
self.fac[i] = self.fac[i-1] * i % self.mod
self.invfac = [1]*(n+1)
self.invfac[n] = pow(self.fac[n], self.mod - 2, self.mod)
for i in range(n-1, 0, -1):
self.invfac[i] = self.invfac[i+1] * (i+1) % self.mod
def combination(self, n, r):
ans = self.fac[n] * self.invfac[r] % self.mod * self.invfac[n-r] % self.mod
if n >= r:
return ans
else:
return 0
def factorial(self, i):
return self.fac[i]
def invfactorial(self, i):
return self.invfac[i]
def main():
import sys
def input(): return sys.stdin.readline().rstrip()
n, m, k = map(int, input().split())
mod = 998244353
c = Combination(n,mod)
ans = 0
mex = [0]*(k+1)
mex[0] = pow(m-1,n-k-1,mod)
for i in range(1,k+1):
mex[i] = mex[i-1]*(m-1)%mod
mex = mex[::-1]
for i in range(k+1):
ans += c.combination(n-1, i)*mex[i]
ans %= mod
ans *= m
ans %= mod
print(ans)
if __name__ == '__main__':
main() | 0 | null | 29,005,863,767,300 | 173 | 151 |
from collections import defaultdict
from math import gcd
mod = 10 ** 9 + 7
n = int(input())
fishes = defaultdict(int)
zero_zero = 0
zero = 0
inf = 0
for _ in range(n):
a, b = map(int, input().split())
if a == 0 and b == 0:
zero_zero += 1
elif a == 0:
zero += 1
elif b == 0:
inf += 1
else:
div = gcd(a, b)
a //= div
b //= div
if b < 0:
a *= -1
b *= -1
key = (a, b)
fishes[key] += 1
def get_bad_pair(fish):
a, b = fish
if a < 0:
a *= -1
b *= -1
return (-b, a)
ans = 1
counted_key = set()
for fish_key, count in fishes.items():
if fish_key in counted_key:
continue
bad_pair = get_bad_pair(fish_key)
if bad_pair in fishes:
pair_count = fishes[bad_pair]
pattern = pow(2, count, mod) + pow(2, pair_count, mod) - 1
counted_key.add(bad_pair)
else:
pattern = pow(2, count, mod)
ans = ans * pattern % mod
ans *= pow(2, zero, mod) + pow(2, inf, mod) - 1
if zero_zero:
ans += zero_zero
ans -= 1
print(ans % mod)
| from collections import defaultdict
from math import gcd
n = int(input())
zeros = 0
d = defaultdict(lambda: [0, 0])
for _ in range(n):
a, b = map(int, input().split())
if a == 0 and b == 0:
zeros += 1
continue
g = gcd(a, b)
a, b = a // g, b // g
if a == 0:
b = 1
if b == 0:
a = 1
if b < 0:
a, b = -a, -b
if a <= 0:
d[(b, -a)][1] += 1
else:
d[(a, b)][0] += 1
mod = 1000000007
ans = 1
for v in d.values():
ans = ans * (pow(2, v[0], mod) + pow(2, v[1], mod) - 1) % mod
ans = (ans - 1 + zeros) % mod
print(ans)
| 1 | 20,811,846,224,272 | null | 146 | 146 |
n,m=map(int,input().split())
H=list(map(int,input().split()))
ans = [1]*n
for i in range(m):
a,b=map(int,input().split())
if H[a-1]>H[b-1]:
ans[a-1] *= 1
ans[b-1] *= 0
elif H[a-1]<H[b-1]:
ans[a-1] *= 0
ans[b-1] *= 1
else:
ans[a-1] *= 0
ans[b-1] *= 0
print(sum(ans)) | from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
n,m = inpl()
h = inpl()
g = [[] for _ in range(n)]
for _ in range(m):
a,b = inpl()
a,b = a-1,b-1
g[a].append(b)
g[b].append(a)
res = 0
for i in range(n):
for j in g[i]:
if h[j] >= h[i]:
break
else:
res += 1
print(res) | 1 | 25,167,086,490,590 | null | 155 | 155 |
n,a,b = map(int, input().split())
MOD = 10 ** 9 + 7
def comb(n, k):
nCk = 1
for i in range(n - k + 1, n + 1):
nCk *= i
nCk %= MOD
for i in range(1, k + 1):
nCk *= pow(i, MOD - 2, MOD)
nCk %= MOD
return nCk
print((((pow(2,n,MOD)-1-comb(n,a))%MOD)-comb(n,b))%MOD) | #!/usr/bin/env python3
import collections as cl
import sys
def comb(n, r, mod=10 ** 9 + 7):
r = min(r, n-r)
upper = 1
for i in range(n, n-r, -1):
upper = (upper * i) % mod
lower = 1
for i in range(1, r+1):
lower = (lower * i) % mod
lower_inv = pow(lower, mod - 2, mod)
return (upper * lower_inv) % mod
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def LI():
return list(map(int, sys.stdin.readline().split()))
def main():
n, a, b = MI()
ttl = pow(2, n, 10**9+7) - 1
a_ttl = comb(n, a)
b_ttl = comb(n, b)
print((ttl - a_ttl - b_ttl) % (10**9+7))
main()
| 1 | 65,963,944,273,162 | null | 214 | 214 |
#!/usr/bin/env python3
import sys
import numpy as np
import numba
from numba import i8
input = sys.stdin.buffer.readline
mod = 998244353
def I():
return int(input())
def MI():
return map(int, input().split())
@numba.njit((i8, i8[:]), cache=True)
def main(N, LR):
L, R = LR[::2], LR[1::2]
K = len(L)
dp = np.zeros(N + 1, np.int64)
dpsum = np.zeros(N + 1, np.int64)
dp[1] = 1
dpsum[1] = 1
for i in range(2, N + 1):
for k in range(K):
li = i - R[k]
ri = i - L[k]
if ri < 0:
continue
li = max(li, 1)
dp[i] += dpsum[ri] - dpsum[li - 1]
dp[i] %= mod
dpsum[i] = dpsum[i - 1] + dp[i]
dpsum[i] %= mod
return dp[N]
N, K = MI()
LR = np.array(sys.stdin.buffer.read().split(), np.int64)
print(main(N, LR))
| n, k = map(int, input().split())
lr = [list(map(int, input().split())) for _i in range(k)]
mod = 998244353
dp = [0]*(n+1)
dp[1] = 1
for p in range(2, n+1):
for i, j in lr:
dp[p] += dp[max(p-i, 0)] - dp[max(p-j-1, 0)]
dp[p] %= mod
dp[p] += dp[p-1]
print((dp[n]-dp[n-1])%mod) | 1 | 2,741,182,764,968 | null | 74 | 74 |
a,b = input().split()
x = int(a) * b
y = int(b) * a
l = []
l.append(x)
l.append(y)
l = sorted(l)
print(min(l)) | a,b = input().split()
t = a*int(b)
q = b*int(a)
if t < q:
print(t)
else:
print(q) | 1 | 84,299,904,114,342 | null | 232 | 232 |
a = int(input())
ans = "Yes" if a>= 30 else "No"
print(ans) | a=int(input(''))
if a>=30:
print('Yes')
else:
print('No') | 1 | 5,795,259,950,672 | null | 95 | 95 |
X,Y=map(int, input().split())
v = [300000, 200000, 100000]
x = 0
y = 0
if X <= 3:
x = int(v[X-1])
if Y <= 3:
y = int(v[Y-1])
print(int(x + y + ((X==1) & (Y==1)) * 400000))
| x, y = map(int, input().split())
ans = max(4 - x, 0) + max(4 - y, 0)
print(ans * 10**5 if ans != 6 else 10**6)
| 1 | 140,655,156,244,242 | null | 275 | 275 |
def examE():
N, K = LI()
A = LI()
sumA = [0]*(N+1)
for i in range(1,N+1):
sumA[i] = sumA[i-1]+A[i-1]
d = defaultdict(int)
ans = 0
#連想配列 先頭からの番号 余分な量
que = deque()
for i,a in enumerate(sumA):
#K番目以降は一番左のやつ消していく
if que and que[0][0] <= (i-K):
d[que.popleft()[1]] -= 1
cur = (a-i)%K
ans +=d[cur]
d[cur] +=1
que.append((i,cur))
# print(ans,que,d,a-i)
print(ans)
return
def examF():
return
import sys,copy,bisect,itertools,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')
examE()
| import collections
n,k=map(int,input().split())
a=list(map(int,input().split()))
m=[0]
for i in range(n):
m.append((m[-1]+a[i]))
for i in range(n+1):
m[i]-=i
m[i]%=k
ans=0
dict=collections.defaultdict(int)
for i in range(1,n+1):
x=m[i]
if i<=k-1:
dict[m[i-1]]+=1
else:
dict[m[i-1]]+=1
dict[m[i-k]]-=1
ans+=dict[x]
print(ans) | 1 | 137,509,528,224,860 | null | 273 | 273 |
k,n=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
dm=0
for i in range(n):
dis=(a[i]-a[i-1])%k
dm=max(dm,dis)
print(k-dm)
| K,N=map(int,input().split())
A=[int(i) for i in input().split()]
dlist=[]
for i in range(1,N):
d=A[i]-A[i-1]
dlist.append(d)
dlist.append(A[0]+K-A[N-1])
print(K-max(dlist)) | 1 | 43,169,672,171,100 | null | 186 | 186 |
# -*- coding: utf-8 -*-
import sys
rectangle = []
h,w = 1,1
while not(h == 0 and w == 0):
h,w = map(int, input().split())
if not(h == 0 and w == 0):
rectangle.append([h,w])
for rec in rectangle:
row_count = 1
display = []
for row in range(rec[0]):
col_count = 0
if (row_count %2 == 1):
col_count = 1
else:
col_count = 2
for col in range(rec[1]):
if (col_count % 2 == 1):
display.append('#')
else:
display.append('.')
col_count += 1
row_count += 1
display.append('\n')
print(''.join(display)) | integer = int(input())
string = input()
if len(string) > integer:
print(string[:integer] + '...')
else:
print(string) | 0 | null | 10,260,159,851,332 | 51 | 143 |
n,k=map(int,input().split())
mod=10**9+7
def inv(x):
return pow(x,mod-2,mod)
N=2*10**5
Fact=[0 for i in range(N+1)]
Finv=[0 for i in range(N+1)]
Fact[0]=1
for i in range(N):
Fact[i+1]=(Fact[i]*(i+1))%mod
Finv[N]=inv(Fact[N])
for i in range(N-1,-1,-1):
Finv[i]=((i+1)*Finv[i+1])%mod
def C(a,b):
return (Fact[a]*(Finv[b]*Finv[a-b])%mod)%mod
ans=0
for i in range(min(n,k+1)):
ans+=(C(n,i)*C(n-1,i))%mod
ans%=mod
print(ans)
| N,A,B = list(map(int,input().split()))
if (B-A)%2 == 0:
print((B-A)//2)
exit()
A1 = A
B1 = B
A2 = A
B2 = B
count1 = N-B1
ans1 = 0
A1 += (N-B1)
B1 = N
if (B1-A1)%2 == 0:
ans1 = count1+(B1-A1)//2
else:
ans1 = count1+1+(B1-A1)//2
count2 = A2-1
ans2 = 0
B2 -= (A2-1)
A2 = 1
if (B2-A2)%2 == 0:
ans2 = count2+(B2-A2)//2
else:
ans2 = count2+1+(B2-A2)//2
print(min(ans1,ans2)) | 0 | null | 88,147,187,358,008 | 215 | 253 |
class card:
def __init__(self, types, value):
self.types = types
self.value = value
def bubbleSort(A, N):
for i in range(0, N):
for j in range(N - 1, i, -1):
if A[j].value < A[j - 1].value:
exchange(A, j - 1, j)
printCards(A)
print "Stable"
def selectionSort(A, N):
origin = A[:]
for i in range(0, N):
minj = i
for j in range(i, N):
if A[j].value < A[minj].value:
minj = j
if i != minj:
exchange(A, i, minj)
printCards(A)
if checkStable(origin, A, N):
print "Stable"
else:
print "Not stable"
def exchange(array, i, j):
tmp = array[i]
array[i] = array[j]
array[j] = tmp
def printCards(cards):
print " ".join(t.types + str(t.value) for t in cards)
def checkStable(origin, sorted, N):
for i in range(0, N - 1):
if sorted[i].value == sorted[i + 1].value:
if origin.index(sorted[i]) > origin.index(sorted[i + 1]):
return False
return True
if __name__ == "__main__":
N = input()
A = [card(c[0], int(c[1])) for c in raw_input().split()]
bubbleSort(A[:], N)
selectionSort(A[:], N) | n=int(input())
num_list1=list(map(str,input().split()))
num_list2=[]
input_list=[]
for k in num_list1:
num_list2.append(k)
input_list.append(k)
def bubble(num_list):
i=0
flag=True
while flag:
flag=False
for j in range(len(num_list)-1,i,-1):
if int(num_list[j-1][1])>int(num_list[j][1]):
tmp=num_list[j-1]
num_list[j-1]=num_list[j]
num_list[j]=tmp
flag=True
return num_list
def select(num_list):
for i in range(0,len(num_list)):
min=i
for j in range(min+1,len(num_list)):
if int(num_list[min][1])>int(num_list[j][1]):
min=j
tmp=num_list[i]
num_list[i]=num_list[min]
num_list[min]=tmp
return num_list
def stable(input_list,output_list):
for i in range(0,len(input_list)):
for j in range(i+1,len(output_list)):
for k in range(0,len(output_list)):
for l in range(k+1,len(output_list)):
if input_list[i][1]==input_list[j][1] and input_list[i]==output_list[l] and input_list[j]==output_list[k]:
return "Not stable"
return "Stable"
bubble=bubble(num_list1)
select=select(num_list2)
print(" ".join(bubble))
print(stable(input_list,bubble))
print(" ".join(select))
print(stable(input_list,select))
| 1 | 26,246,237,060 | null | 16 | 16 |
from functools import reduce
from collections import deque
def operate(dq, op):
if op[0] == 'i':
dq.appendleft(int(op[7:]))
else:
k = op[6]
if k == 'F':
dq.popleft()
elif k == 'L':
dq.pop()
else:
try:
dq.remove(int(op[7:]))
except ValueError:
pass
return dq
n = int(input())
print(*reduce(operate, [input() for _ in range(n)], deque())) | from collections import Counter
n = int(input())
s = Counter([input() for _ in range(n)])
before = 0
ans = []
s = s.most_common()
for i in range(len(s)):
if before == 0: before = s[i][1]
elif before != s[i][1]: break
ans.append(s[i][0])
for i in sorted(ans): print(i) | 0 | null | 34,850,109,342,382 | 20 | 218 |
z = input()
a = list(map(int, z.split()))
cnt = 0
for i in range(a[0], a[1] + 1, 1):
if a[2] % i == 0:
cnt += 1
print(cnt) | N = input()
flag = False
for i in range(len(N)):
if N[i] =="7":
flag =True
if flag:
print ("Yes")
else :
print ("No") | 0 | null | 17,575,980,713,412 | 44 | 172 |
count = int(input())
lists = []
for i in range(count):
new = input()
lists.append(new)
ac_count = lists.count('AC')
wa_count = lists.count('WA')
tle_count = lists.count('TLE')
re_count = lists.count('RE')
print("AC x " + str(ac_count))
print("WA x " + str(wa_count))
print("TLE x " + str(tle_count))
print("RE x " + str(re_count))
| N = int(input())
ansAC = 0
ansWA = 0
ansTLE = 0
ansRE = 0
for i in range(N):
S = input()
if S == "AC":
ansAC += 1
elif S == "TLE":
ansTLE += 1
elif S == "WA":
ansWA += 1
elif S == "RE":
ansRE += 1
print("AC x " + str(ansAC))
print("WA x " + str(ansWA))
print("TLE x " + str(ansTLE))
print("RE x " + str(ansRE)) | 1 | 8,734,230,086,052 | null | 109 | 109 |
n = int(input())
songs = []
for _ in range(n):
s, t = input().split()
t = int(t)
songs.append((s, t))
x = input()
ans = 0
flag = False
for s, t in songs:
if flag:
ans += t
if s == x:
flag = True
print(ans)
| N = int(input())
l = []
for _ in range(N):
s, t = input().split()
t = int(t)
l.append([s, t])
X = input()
ans = 0
found = False
for s in l:
if found:
ans += s[1]
continue
if s[0] == X:
found = True
print(ans) | 1 | 96,891,513,519,852 | null | 243 | 243 |
from collections import defaultdict
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
# 素因数分解、リストで返す
#############################################################
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
f = 3
while f * f <= n:
if n % f == 0:
a.append(f)
n //= f
else:
f += 2
if n != 1:
a.append(n)
a.sort()
return a
#############################################################
primes = defaultdict(int)
for i in range(N):
p = prime_factorize(A[i])
p_set = set(p)
for pi in p_set:
primes[pi] += 1
# 全て1の時、primesが空になってmaxが取れない
if len(primes) == 0:
print("pairwise coprime")
exit()
max_cnt = max(primes.values())
# min_cnt = min(primes.values())
if max_cnt == 1:
print("pairwise coprime")
elif max_cnt != N:
print("setwise coprime")
else:
print("not coprime")
| # coding:UTF-8
import sys
from math import factorial
MOD = 10 ** 9 + 7
INF = 10000000000
# 素数列挙
def primeNumList(n):
d = [d for d in range(0, n+1)]
if n < 2:
return [[],d]
is_prime = [True] * (n + 1)
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(n ** 0.5) + 1):
if not is_prime[i]:
continue
for j in range(i * 2, n + 1, i):
is_prime[j] = False
d[j] = i
return [[i for i in range(n + 1) if is_prime[i]], d]
def main():
# ------ 入力 ------#
n = int(input()) # 数字
aList = list(map(int, input().split())) # スペース区切り連続数字
# ------ 処理 ------#
amax = max(aList)
pl = primeNumList(amax)
countList = [0] * (amax+1)
if pl[0] != []:
for a in aList:
at = a
sl = []
while at != 1:
s = pl[1][at]
sl.append(s)
at = int(at / s)
sl2 = list(set(sl))
for s in sl2:
countList[s] += 1
m = max(countList)
else:
m = 0
# ------ 出力 ------#
if m == len(aList):
print("not coprime")
elif m >= 2:
print("setwise coprime")
else:
print("pairwise coprime")
if __name__ == '__main__':
main()
| 1 | 4,108,537,544,272 | null | 85 | 85 |
import sys
list = map(int,sys.stdin.readline().split())
list.sort()
print(' '.join(map(str,list))) | a = input()
print('Yes' if input() in a+a else 'No') | 0 | null | 1,091,056,319,938 | 40 | 64 |
#!/usr/bin/env python3
from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right
H,W = map(int, input().split())
s = [None for _ in range(H)]
for i in range(H):
s[i] = input()
dp = [[0]*(W+1) for _ in range(H+1)]
if s[0][0] == '#':
dp[1][1] += 1
for i in range(H):
for j in range(W):
if (i,j) == (0,0):
continue
tmp = []
if i > 0:
if s[i][j] == '#' and s[i-1][j] == '.':
tmp.append(dp[i][j+1]+1)
else:
tmp.append(dp[i][j+1])
if j > 0:
if s[i][j] == '#' and s[i][j-1] == '.':
tmp.append(dp[i+1][j]+1)
else:
tmp.append(dp[i+1][j])
dp[i+1][j+1] = min(tmp)
print(dp[H][W]) | N = int(input())
S = input()
judge = [1]*N
for i in range(1,N):
if S[i-1] == S[i]:
judge[i] = 0
print(sum(judge)) | 0 | null | 109,760,907,393,100 | 194 | 293 |
m,d = map(int,input().split())
m2,d2 = map(int,input().split())
print(1 if m != m2 else 0) | M1, D1 = map(int, input().split())
M2, D2 = map(int, input().split())
print(1 if M1 != M2 else 0) | 1 | 124,848,624,332,082 | null | 264 | 264 |
n,x,t = map(int,input().split())
if n % x ==0:
print(int(n/x*t))
else:
print(int((n//x+1)*t))
| import math
#入力:N,M(int:整数)
def input2():
return map(int,input().split())
#入力:[n1,n2,...nk](int:整数配列)
def input_array():
return list(map(int,input().split()))
n,x,t=input2()
ans=(math.ceil(n/x))*t
print(ans) | 1 | 4,199,224,910,530 | null | 86 | 86 |
def lcm(x, y):
from fractions import gcd
return (x * y) // gcd(x, y)
a,b = map(int,input().split())
print(lcm(a,b)) | A,B = map(int,input().split())
def gcd(a, b):
if b==0:
return a
return gcd(b, a%b)
print(A*B//gcd(A,B)) | 1 | 113,232,944,524,518 | null | 256 | 256 |
#!/usr/bin/env python3
def solve(a,b):
str1 = str(a)*b
str2 = str(b)*a
if str1 < str2:
return str1
else:
return str2
def main():
a,b = map(int,input().split())
print(solve(a,b))
return
if __name__ == '__main__':
main()
| x, y = map(int, input().split())
if(x < y):
for i in range(0, y):
print(x, end = '')
else:
for i in range(0, x):
print(y, end = '')
| 1 | 84,259,474,647,968 | null | 232 | 232 |
def chess(h,w):
o = ""
for i in range(h):
if i%2:
if w%2: o+= ".#"*(w/2)+".\n"
else: o+= ".#"*(w/2)+"\n"
else:
if w%2: o+= "#."*(w/2)+"#\n"
else: o+= "#."*(w/2)+"\n"
print o
while 1:
h,w=map(int,raw_input().split())
if h==w==0:break
chess(h,w) | #!/usr/bin/env python3
import sys
import math
import decimal
import itertools
from itertools import product
from functools import reduce
def input():
return sys.stdin.readline()[:-1]
def sort_zip(a:list, b:list):
z = zip(a, b)
z = sorted(z)
a, b = zip(*z)
a = list(a)
b = list(b)
return a, b
def main():
H, W, K = map(int, input().split())
c = []
for i in range(H):
c.append(input())
ans = 0
for i in product([0, 1], repeat=H):
for j in product([0, 1], repeat=W):
black = 0
for h in range(H):
for w in range(W):
if i[h] == 1 and j[w] == 1 and c[h][w] == '#':
black += 1
if black == K:
ans += 1
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 4,972,284,574,388 | 51 | 110 |
n = int(input())
l = list(map(int,input().split()))
p=l[0]
s=0
for i in l[1:]:
s+= max(0,p-i)
p=max(p,i)
print(s) | n=int(input())
a=list(map(int,input().split()))
b=a[0]
ans=0
for n in range(n):
if a[n]>b:
b=a[n]
else:
ans+=b-a[n]
print(ans) | 1 | 4,563,315,213,788 | null | 88 | 88 |
# -*- coding: utf-8 -*-
def input_int():
return int(input())
def answer():
n = input_int()
count = 0
for a in range(1, n):
b = (n - 1) // a
if b >= a:
count += (b - a) * 2
count += 1
else:
continue
print(count)
answer() | N=int(input())
def num_divisors_table(n):
table=[0]*(n+1)
for i in range(1,n+1):
for j in range(i,n+1,i):
table[j]+=1
return table
l=num_divisors_table(N-1)
print(sum(l)) | 1 | 2,628,383,545,748 | null | 73 | 73 |
a = str(input().split())
b = list(a)
if b[4] == b[5] and b[7] == b[6]:
print("Yes")
else :
print("No") | S = input()
if S[2] == S[3] and S[-2] == S[-1]:
print('Yes')
else:
print('No') | 1 | 41,805,110,074,376 | null | 184 | 184 |
from itertools import permutations
def main():
N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))
A = [i for i in range(1, N+1)]
As = list(permutations(A))
for i in range(len(As)):
a = As[i]
for j in range(len(a)):
if a[j] != P[j]:
break
else:
p_rank = i
break
for i in range(len(As)):
a = As[i]
for j in range(len(a)):
if a[j] != Q[j]:
break
else:
q_rank = i
break
print(abs(p_rank-q_rank))
if __name__ == '__main__':
main() | import itertools
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))
c = [i for i in range(1,n+1)]
v = list(itertools.permutations(c,n))
a = v.index(p)
b = v.index(q)
print(abs(a-b)) | 1 | 100,602,384,886,772 | null | 246 | 246 |
import sys
input = sys.stdin.readline
def main():
n = int(input())
stick = list(map(int, input().split()))
total = sum(stick)
mid = total // 2
cum = 0
midi = 0
for i, block in enumerate(stick):
cum += block
if cum >= mid:
midi = i
break
l1 = cum
r1 = total - l1
diff1 = abs(l1 - r1)
l2 = l1 - stick[midi]
r2 = r1 + stick[midi]
diff2 = abs(l2 - r2)
print(min(diff1, diff2))
main() | N = input()
print("Yes" if "7" in N else "No") | 0 | null | 88,035,093,945,360 | 276 | 172 |
n, m = map(int, input().split())
d = {"1": -1, "2": -1, "3": -1}
for _ in range(m):
s, c = input().split()
if d[s] == -1:
d[s] = int(c)
elif d[s] != int(c):
print(-1)
exit()
n = str(4 - n)
if n != "3" and d["1"] == 0:
print(-1)
elif n == "1":
if d["1"] == -1:
d["1"] = 1
if d["2"] == -1:
d["2"] = 0
if d["3"] == -1:
d["3"] = 0
print(*d.values(), sep="")
elif n == "2":
if d["1"] == -1:
d["1"] = 1
if d["2"] == -1:
d["2"] = 0
print(d["1"] * 10 + d["2"])
else:
if d["1"] == -1:
d["1"] = 0
print(d["1"]) | import sys
N,M = map(int,input().split())
s = []
c = []
for i in range(M):
S,C = map(int,input().split())
s.append(S)
c.append(C)
for i in range(10**(N+1)):
st = str(i)
if len(st) == N and all([st[s[j]-1] == str(c[j]) for j in range(M)]):
print(st)
sys.exit()
print(-1) | 1 | 60,967,920,170,818 | null | 208 | 208 |
n = input()
xi = map(int, raw_input().split())
print ("%d %d %d") %(min(xi), max(xi), sum(xi)) | n = int(input())
a = input().split()
min = int(a[0])
max = int(a[0])
sum = 0
for i in a:
if min > int(i):
min = int(i)
if max < int(i):
max = int(i)
sum += int(i)
print("{0} {1} {2}".format(min, max, sum)) | 1 | 723,257,894,998 | null | 48 | 48 |
a,b,k = map(int, input().split())
if k > a and k >= a+b:
print( 0 , 0 )
elif k < a :
print(a-k , b)
elif k == a:
print(0 , b)
elif k>a and k < a+b:
print(0 , b-(k-a))
| n,*a=map(int,open(0).read().split())
b=[0]*n
for i in range(n):
b[a[i]-1]=str(i+1)
print(' '.join(b)) | 0 | null | 142,753,624,444,828 | 249 | 299 |
import sys
from collections import deque
def LS():
return list(input().split())
S = deque(input())
Q = int(input())
rev = 0
for i in range(Q):
A = LS()
if A[0] == "1":
rev += 1
rev %= 2
else:
if A[1] == "1":
if rev == 0:
S.appendleft(A[2])
else:
S.append(A[2])
else:
if rev == 0:
S.append(A[2])
else:
S.appendleft(A[2])
if rev == 0:
print(''.join(S))
else:
S.reverse()
print(''.join(S))
| x, n = map(int, input().split())
p = list(map(int, input().split()))
l = [i - x for i in p]
m = [0]
for i in range(1, 101):
m.append(-i)
m.append(i)
for i in range(201):
if (m[i] in l) == True:
continue
if (m[i] in l) == False:
print(x + m[i])
break | 0 | null | 35,665,357,322,140 | 204 | 128 |
H,W,K = map(int,input().split())
S = [input() for _ in range(H)]
ans = 10**10
for i in range(2**(H-1)): # iはbit
rel = [0 for h in range(H)]
a,b = 0,0
for h in range(H-1):
if i>>h&1:
b += 1
rel[h+1] = b
a += b
cnt = [0 for j in range(b+1)]
for w in range(W):
for h in range(H):
if S[h][w] == '1':
cnt[rel[h]] += 1
OK = True
for j in range(b+1):
if cnt[j] > K:
OK = False
break
if OK:
continue
a += 1
cnt = [0 for j in range(b+1)]
for h in range(H):
if S[h][w] == '1':
cnt[rel[h]] += 1
OK2 = True
for j in range(b+1):
if cnt[j] > K:
OK2 = False
break
if OK2:
continue
a = 10**10
break
ans = min(ans,a)
print(ans)
| h = int(input())
sumn = 0
i,k = 0,1
while k <= h:
sumn+=k
i+=1
k = 2**i
print(sumn) | 0 | null | 64,276,696,237,952 | 193 | 228 |
values = input()
W, H, x, y, r = [int(x) for x in values.split()]
flag = True
if x - r < 0 or x + r > W:
flag = False
if y - r < 0 or y + r > H:
flag = False
if flag:
print('Yes')
else:
print('No') | m,d=map(int,input().split())
n,e=map(int,input().split())
print(1 if m!=n else 0) | 0 | null | 62,401,031,189,248 | 41 | 264 |
n = input()
S = map(int,raw_input().split())
q = input()
T = map(int,raw_input().split())
ans = 0
for t in T:
if t in S:
ans+=1
print ans | s=input()
k=int(input())
n=len(s)
ans=0
tmp=0
x=s[0]
ss=[]
for i in range(n):
if x==s[i]:
tmp+=1
else:
ss.append(tmp)
tmp=1
x=s[i]
if tmp>0:
ss.append(tmp)
if len(ss)==1:
print(n*k//2)
else:
if s[0]==s[-1]:
ans=(-(ss[0]//2)-(ss[-1]//2)+(ss[0]+ss[-1])//2)*(k-1)
for i in ss:
ans+=i//2*k
print(ans) | 0 | null | 87,361,692,417,732 | 22 | 296 |
h, w = map(int, input().split())
s_list = [] # h, w
dp_dict = {}
for i in range(h):
s = input()
temp_list = []
for temp in s:
if temp == "#":
temp_list.append(1)
else:
temp_list.append(0)
s_list.append(temp_list)
def search(x, y, black):
res = 0
if (x, y, black) in dp_dict:
return dp_dict[(x, y, black)]
if x == w-1 and y == h-1:
if s_list[y][x] == 1:
if black:
res = 0
else:
res = 1
else:
res = 0
elif x == w-1:
if s_list[y][x] == 1:
if black:
res = search(x, y+1, True)
else:
res = search(x, y+1, True)+1
else:
res = search(x, y+1, False)
elif y == h-1:
if s_list[y][x] == 1:
if black:
res = search(x+1, y, True)
else:
res = search(x+1, y, True)+1
else:
res = search(x+1, y, False)
else:
if s_list[y][x] == 1:
if black:
res = min([search(x+1, y, True), search(x, y+1, True)])
else:
res = min([search(x+1, y, True), search(x, y+1, True)])+1
else:
res = min([search(x+1, y, False), search(x, y+1, False)])
dp_dict[(x, y, black)] = res
return res
print(search(0, 0, False))
| import sys
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10**7)
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()
d = ni()
c = na()
s = nan(d)
t = nin(d)
last = [0] * 26
ans = 0
for i in range(d):
sa = s[i]
cur = t[i]
cur -= 1
ans += sa[cur]
last[cur] = (i + 1)
for j in range(26):
ans -= c[j] * ((i + 1) - last[j])
print(ans) | 0 | null | 29,645,530,656,270 | 194 | 114 |
N = int(input())
eList = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
n = N
mod = N
numList = []
while n > 0:
n, mod = divmod(n,26)
if mod != 0:
numList.insert(0, mod - 1)
else:
numList.insert(0, 25)
n -= 1
ans =''
for num in numList:
ans += eList[num]
print(ans) | N=int(input())
S=input()
x="Yes"
if N%2==1:
print("No")
else:
for i in range(0,N//2):
if S[i]!=S[i+N//2]:
x="No"
break
print(x) | 0 | null | 79,597,720,733,960 | 121 | 279 |
import math
H, W, K = map(int, input().split())
S = [list(map(lambda x: int(x=='1'), input())) for _ in range(H)]
def cal_min_vert_div(hs):
cnt = 0
n_h_div = len(hs)
n_white = [0]*n_h_div
for i in range(W):
for j in range(n_h_div):
n_white[j] += hs[j][i]
if n_white[j] > K:
n_white = [hs[k][i] for k in range(n_h_div)]
cnt += 1
if max(n_white)>K:
return math.inf
break
return cnt
ans = math.inf
for mask in range(2**(H-1)):
hs = []
tmp = S[0]
for i in range(H-1):
if mask>>i & 1:
hs.append(tmp)
tmp = S[i+1]
else:
tmp = [tmp[w]+S[i+1][w] for w in range(W)]
hs.append(tmp)
tmp = cal_min_vert_div(hs)+sum(map(int, bin(mask)[2:]))
ans = min(ans, tmp)
print(ans)
| inputted = list(map(int, input().split()))
K = inputted[0]
X = inputted[1]
total = 500 * K;
answer = 'Yes' if total >= X else 'No';
print(answer);
| 0 | null | 73,341,284,338,570 | 193 | 244 |
import fractions
from functools import reduce
def lcm_base(x, y):
return (x * y) // fractions.gcd(x, y)
def lcm(*numbers):
return reduce(lcm_base, numbers, 1)
N,M=map(int,input().split())
A=[int(i)//2 for i in input().split()]
q=lcm(*A)
#print(q)
for i in A:
#print(i)
if q//i%2==0:
print(0)
exit()
print((M//q+1)//2) | def main():
from fractions import gcd
from math import ceil
n, m, *a = map(int, open(0).read().split())
b = [0 for _ in range(n)]
a.sort()
for i, j in enumerate(a):
c = 0
while j % 2 == 0:
c += 1
j = j // 2
a[i] = j
b[i] = c
if len(set(b)) > 1:
print(0)
exit()
lcm = 1
for i in a:
lcm = (lcm * i) // gcd(lcm, i)
k = b[0] - 1
ans = ceil(m // 2 ** k // lcm / 2)
print(ans)
if __name__ == "__main__":
main()
| 1 | 102,142,022,786,816 | null | 247 | 247 |
a = sum(list(map(int, input().split())))
if a >+ 21:
print('bust')
else:
print('win') | N, K = map(int, input().split())
A = list(map(int, input().split()))
A_neg = []
A_pos = []
for i in range(N):
if A[i] <= 0:
A_neg.append(-A[i])
else:
A_pos.append(A[i])
A_neg.sort(reverse=True)
A_pos.sort(reverse=True)
ans = 1
if K == N:
for i in range(N):
ans *= (A[i]%1000000007)
ans %= 1000000007
print(ans)
elif K%2==1 and len(A_pos)==0:
for i in range(1, K+1):
ans *= ((-A_neg[-i])%1000000007)
ans %= 1000000007
print(ans)
else:
if K%2==1:
ans *= A_pos.pop(0)
K -= 1
buf = []
if len(A_pos)>=2:
for i in range(len(A_pos)//2):
buf.append(A_pos[2*i]*A_pos[2*i+1])
if len(A_neg)>=2:
for i in range(len(A_neg)//2):
buf.append(A_neg[2*i]*A_neg[2*i+1])
buf.sort(reverse=True)
for i in range(K//2):
ans *= (buf[i]%1000000007)
ans %= 1000000007
print(ans)
| 0 | null | 64,364,192,217,020 | 260 | 112 |
def dfs(lst):
global ans
if len(lst) > n:
return
lowest = 1
if lst != []:
lowest = lst[-1]
for i in range(lowest, m+1):
lst.append(i)
dfs(lst)
lst.pop()
if len(lst) == n:
cnt = 0
for i in range(q):
a, b, c, d = ab[i]
if lst[b-1] - lst[a-1] == c:
cnt += d
ans = max(cnt, ans)
n,m,q = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(q)]
ans = 0
dfs([])
print(ans) | a,b,c = list(map(int,input().split()))
d = c-a-b
if d <= 0:
print("No")
else:
if d**2 > 4*a*b:
print("Yes")
else:
print("No") | 0 | null | 39,916,728,702,678 | 160 | 197 |