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
|
---|---|---|---|---|---|---|
key = raw_input().upper()
c = ''
while True:
s = raw_input()
if s == 'END_OF_TEXT':
break
c = c + ' ' + s.upper()
cs = c.split()
total = 0
for w in cs:
if w == key:
total = total + 1
print total
|
w = raw_input()
t = []
while 1:
x = raw_input()
if x =="END_OF_TEXT":break
t+=x.lower().split()
print t.count(w)
| 1 | 1,825,916,438,204 | null | 65 | 65 |
while 1:
a = list(map(int, input().split()))
if a[0] or a[1]:
print(min(a), max(a))
else:
break
|
def inp():
return input()
def iinp():
return int(input())
def inps():
return input().split()
def miinps():
return map(int,input().split())
def linps():
return list(input().split())
def lmiinps():
return list(map(int,input().split()))
def lmiinpsf(n):
return [list(map(int,input().split()))for _ in range(n)]
n,x,t = miinps()
ans = (n + (x - 1)) // x
ans *= t
print(ans)
| 0 | null | 2,402,286,640,520 | 43 | 86 |
#! /usr/bin/env python3
import sys
sys.setrecursionlimit(10**9)
INF=10**20
def solve(N: int, S: str):
T = S.replace("ABC","")
ans = N - len(T)
ans //= 3
print(ans)
return
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
S = next(tokens) # type: str
solve(N, S)
if __name__ == "__main__":
main()
|
n = int(input())
s = input()
#print(n , s , ' ')
p = "ABC"
ans = 0
for i in range(n - 2):
if s[i : (i + 3)] == p :
ans += 1
print(ans)
| 1 | 99,643,807,066,050 | null | 245 | 245 |
n, x, m = map(int, input().split())
ans = 0
prev_set = set()
prev_list = list()
ans_hist = list()
r = x
for i in range(n):
if i == 0:
pass
else:
r = (r * r) % m
if r == 0:
break
if r in prev_set:
index = prev_list.index(r)
period = i - index
count = (n - index) // period
rest = (n - index) % period
ans = sum(prev_list[:index])
ans += sum(prev_list[index:i]) * count
# ans += (ans - ans_hist[index - 1]) * (count - 1)
ans += sum(prev_list[index:index+rest])
# ans += (ans_hist[index + rest - 1] - ans_hist[index - 1])
break
else:
ans += r
prev_set.add(r)
prev_list.append(r)
ans_hist.append(ans)
print(ans)
|
def f(A,B,x):
val=((A*x)//B)-A*(x//B)
return val
A,B,n=map(int,input().split())
print(f(A,B,B-1)) if n>=B-1 else print(f(A,B,n))
| 0 | null | 15,420,791,890,530 | 75 | 161 |
from sys import stdin
input = stdin.readline
from collections import Counter
def solve():
N = int(input())
a = list(map(int,input().split()))
assert N & 1 == 0
s = 0
res = []
for v in a:
s ^= v
for v in a:
res.append(s^v)
print(' '.join(map(str,res)))
if __name__ == '__main__':
solve()
|
N, X, M = map(int, input().split())
ans = 0
C = [0]
Xd = [-1] * (M+1)
for i in range(N):
x = X if i==0 else x**2 % M
if Xd[x] > -1:
break
Xd[x] = i
ans += x
C.append(ans)
loop_len = i - Xd[x]
if loop_len > 0:
S = C[i] - C[Xd[x]]
loop_num = (N - i) // loop_len
ans += loop_num * S
m = N - loop_num * loop_len - i
ans += C[Xd[x]+m] - C[Xd[x]]
print(ans)
| 0 | null | 7,622,026,239,552 | 123 | 75 |
import collections
n, m = map(int, input().split())
linked = collections.defaultdict(list)
i2group = dict()
gid = n + 1
def get_root(i):
if i not in linked:
return i
j = get_root(linked[i])
linked[i] = j
return j
def get_groups():
return [get_root(i) for i in range(1, n + 1)]
for i in range(m):
a, b = map(int, input().split())
ra, rb = get_root(a), get_root(b)
if ra == rb: continue
linked[ra] = gid
linked[rb] = gid
gid += 1
g = get_groups()
print(len(set(g)) - 1)
exit()
n_connected = 0
n_group = 0
for s in linked.values():
s = s[0]
if s:
n_group += 1
n_connected += len(s)
s.clear()
print((n - n_connected) + (n_group - 1))
|
from collections import Counter
N, M = map(int, input().split())
class UnionFind:
def __init__(self, n):
self.root = [i for i in range(n)]
def unite(self, x, y):
if not self.same(x, y):
self.root[self.find(y)] = self.find(x)
def find(self, x):
if x == self.root[x]:
return x
else:
self.root[x] = self.find(self.root[x])
return self.root[x]
def same(self, x, y):
return self.find(x) == self.find(y)
UF = UnionFind(N)
ans = N-1
for _ in range(M):
x, y = map(int, input().split())
if not UF.same(x-1, y-1):
UF.unite(x-1, y-1)
ans -= 1
print(ans)
| 1 | 2,310,974,480,590 | null | 70 | 70 |
N=int(input())
s=list(input())
S=[0]*N
for i in range(N):
S[i]=int(s[i])
ct=0
for i in range(10):
if not i in S:
continue
T=S[S.index(i)+1:]
for j in range(10):
if not j in T:
continue
U=T[T.index(j)+1:]
for k in range(10):
if k in U:
ct+=1
print(ct)
|
import sys
line = sys.stdin.readline().strip()
n = int(sys.stdin.readline())
for i in range(n):
v = sys.stdin.readline().split()
op = v[0]
a = int(v[1])
b = int(v[2])
if op == "print":
print(line[a: b + 1])
elif op == "reverse":
line = line[:a] + line[a: b + 1][::-1] + line[b + 1:]
elif op == "replace":
p = v[3]
line = line[:a] + p + line[b + 1:]
| 0 | null | 65,676,539,993,372 | 267 | 68 |
suits = ['S', 'H', 'C', 'D']
table = [[False] * 14 for i in range(4)]
N = int(input())
for _i in range(N):
mark, num = input().split()
num = int(num)
if mark == 'S':
table[0][num] = True
if mark == 'H':
table[1][num] = True
if mark == 'C':
table[2][num] = True
if mark == 'D':
table[3][num] = True
for i in range(4):
for j in range(1, 14):
if not table[i][j]:
print(f'{suits[i]} {j}')
|
S,H,C,D = [],[],[],[]
def adding(card):
if card[0] == 'S':
S.append(int(card[1]))
else:
if card[0] == 'H':
H.append(int(card[1]))
else:
if card[0] == 'C':
C.append(int(card[1]))
else:
if card[0] == 'D':
D.append(int(card[1]))
def sort():
S.sort()
H.sort()
C.sort()
D.sort()
def check(pattern,cards):
answer=[]
for i in range(1,13+1):
if not (i in cards):
print pattern,i
if __name__ == '__main__':
number = input()
for i in range(number):
card = map(str,raw_input().split())
adding(card)
sort()
check('S',S)
check('H',H)
check('C',C)
check('D',D)
| 1 | 1,034,951,729,112 | null | 54 | 54 |
a,b = map(str,input().split())
ans = ''
if int(a) > int(b):
for _ in range(int(a)):
ans += b
else:
for _ in range(int(b)):
ans += a
print(ans)
|
a, b = input().split()
A = a * int(b)
B = b * int(a)
lis = [A, B]
lis.sort()
print(lis[0])
| 1 | 84,216,373,986,080 | null | 232 | 232 |
n = int(input())
a = [int(s) for s in input().split()]
ans = 'APPROVED'
for num in a:
if num % 2 == 0:
if num % 3 != 0 and num % 5 != 0:
ans = 'DENIED'
break
print(ans)
|
def main():
a, b, c = map(int, input().split())
if (a == b and b != c) or (b == c and a != b) or (a == c and a != b):
print('Yes')
else:
print('No')
main()
| 0 | null | 68,164,549,254,412 | 217 | 216 |
import sys,math,collections,itertools
input = sys.stdin.readline
A,B,N = list(map(int,input().split()))
if B <= N:
x =B-1
else:
x = N
print(math.floor(A*x/B) - A * math.floor(x/B))
|
n=int(input())
s=input().split("ABC")
print(len(s)-1)
| 0 | null | 63,925,958,312,038 | 161 | 245 |
n=int(input())
P=[int(x) for x in input().split()]
Q=[int(x) for x in input().split()]
p=tuple(P)
q=tuple(Q)
l=list(range(1,n+1))
L=[]
import itertools
for v in itertools.permutations(l):
L.append(v)
a=L.index(p)
b=L.index(q)
print(abs(a-b))
|
a, b = [int(x) for x in raw_input().split(" ")]
if a > b:
print("a > b")
elif a < b:
print("a < b")
else:
print("a == b")
| 0 | null | 50,701,421,654,572 | 246 | 38 |
while True:
h, w = list(map(int, input().split()))
a, b = divmod(w, 2)
c, d = divmod(h, 2)
if h == w == 0:
break
print(('#.' * a + '#' * b + '\n' + '.#' * a + '.' * b + '\n') * c
+ ('#.' * a + '#' * b + '\n') * d)
|
import math
a,b,c,d = map(int,input().split())
print('Yes' if math.ceil(c/b) <= math.ceil(a/d) else 'No')
| 0 | null | 15,362,167,881,888 | 51 | 164 |
n = int(input())
a = list(map(int, input().split()))
ans = sum(a)
ans2 = 0
for i in range(n):
if abs((ans - a[i]) - (ans2 + a[i])) < abs(ans - ans2):
ans2 += a[i]
ans -= a[i]
else:
break
print(abs(ans - ans2))
|
N=int(input())
A=list(map(int, input().split()))
S=M=sum(A)
cnt=0
for a in A:
cnt+=a
M=min(M, abs(S-2*cnt))
print(M)
| 1 | 141,993,052,678,320 | null | 276 | 276 |
from collections import deque
s = deque(list(input()))
q = int(input())
# -1がnotReverse, 1がReverser
isR = -1
for i in range(q):
line = list(input().split())
t = int(line[0])
if t == 1:
isR *= -1
else:
f = int(line[1])
if isR + f == 0 or isR + f == 3:
s.appendleft(line[2])
else:
s.append(line[2])
if isR == 1:
s.reverse()
print("".join(s))
|
import sys
from fractions import gcd
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def merge(a, b):
g = gcd(a, b)
a //= g
b //= g
if a % 2 == 0:
return 0
if b % 2 == 0:
return 0
n = a * b * g
if n > 10 ** 9:
return 0
return n
n, m = map(int, readline().split())
a = list(map(int, readline().split()))
a = [x >> 1 for x in a]
for i in range(n-1):
a[i+1] = merge(a[i], a[i+1])
z = a[n-1]
if z == 0:
print("0")
else:
ans = (m//z) - (m//(z+z))
print(ans)
| 0 | null | 79,816,129,879,792 | 204 | 247 |
from math import log2, ceil
class SegTree:
#####単位元######
ide_ele = 0
def __init__(self, init_val):
n = len(init_val)
self.num = 2**ceil(log2(n))
self.seg = [self.ide_ele] * (2 * self.num - 1)
for i in range(n):
self.seg[i + self.num - 1] = init_val[i]
# built
for i in range(self.num - 2, -1, -1):
self.seg[i] = self.segfunc(self.seg[2 * i + 1], self.seg[2 * i + 2])
#####segfunc######
def segfunc(self, x, y):
return x|y
def update(self, k, x):
k += self.num - 1
self.seg[k] = x
while k:
k = (k - 1) // 2
self.seg[k] = self.segfunc(self.seg[k * 2 + 1], self.seg[k * 2 + 2])
def query(self, a, b, k, l, r):
if r <= a or b <= l:
return self.ide_ele
if a <= l and r <= b:
return self.seg[k]
else:
vl = self.query(a, b, k*2+1, l, (l+r)//2)
vr = self.query(a, b, k*2+2, (l+r)//2, r)
return self.segfunc(vl, vr)
N = int(input())
S = input()
Q = int(input())
li = [1 << (ord(s) - ord('a')) for s in S]
seg_tree = SegTree(li)
ans = []
for _ in range(Q):
i, l, r = input().split()
i = int(i)
l = int(l)
if i == 1:
seg_tree.update(l-1, 1 << (ord(r) - ord('a')))
else:
r = int(r)
num = seg_tree.query(l-1, r, 0, 0, seg_tree.num)
ans.append(bin(num).count('1'))
for a in ans:
print(a)
|
def main():
import sys
n,s,_,*t=sys.stdin.buffer.read().split()
n=int(n)
d=[0]*n+[1<<c-97for c in s]
for i in range(n-1,0,-1):d[i]=d[i+i]|d[i-~i]
for q,a,b in zip(*[iter(t)]*3):
i,s=int(a)+n-1,0
if q<b'2':
d[i]=1<<b[0]-97
while i>1:
i//=2
d[i]=d[i+i]|d[i-~i]
continue
j=int(b)+n
while i<j:
if i&1:
s|=d[i]
i+=1
if j&1:
j-=1
s|=d[j]
i//=2
j//=2
print(bin(s).count('1'),flush=False)
main()
| 1 | 62,863,667,912,540 | null | 210 | 210 |
n, m, q = map(int, input().split())
candidate = []
def gen(cur):
if len(cur) == n:
candidate.append(cur)
else:
t = cur[-1]
for tv in range(t, m + 1):
nex = cur[:]
nex.append(tv)
gen(nex)
for i in range(1, m + 1):
arr = [i]
gen(arr)
ask = []
for _ in range(q):
ask.append(list(map(int, input().split())))
ans = 0
for cv in candidate:
tmp = 0
for av in ask:
if cv[av[1] - 1] - cv[av[0] - 1] == av[2]:
tmp += av[3]
ans = max(ans, tmp)
print(ans)
|
W = input().strip().upper()
T = []
while True:
t = input().strip().split()
if t[0] == 'END_OF_TEXT':
break
else:
for i in t:
T.append(i.upper())
print(T.count(W))
| 0 | null | 14,664,394,342,752 | 160 | 65 |
while True:
string = input()
if string == "0":break
print(sum(int(x) for x in string))
|
# ?????????????????°???????????????????¨??????????????????°??????
while 1:
# ?¨??????\???????????°???????????????
input_num = list(input())
# ???????????????"0"??\?????§??????
if int(input_num[0]) == 0:
break
# print(input_num)
# ??????????¨?????????????????????°
digitTotal = 0
for i in range(0, len(input_num)):
digitTotal += int(input_num[i])
print("{0}".format(digitTotal))
| 1 | 1,579,653,882,380 | null | 62 | 62 |
S=input()
T=input()
S=list(S)
T=list(T)
sum=0
for i in range(len(S)):
if not S[i]==T[i]:
sum += 1
print(sum)
|
s = str(input())
t = str(input())
num = 0
for i in range(len(s)):
if s[i] != t[i]:
num += 1
print(num)
| 1 | 10,461,138,560,870 | null | 116 | 116 |
n = int(input())
ary = [int(_) for _ in input().split()]
q = int(input())
qs = [int(_) for _ in input().split()]
def search_rec(ind, s, q):
if ind == n:
return False
else:
tmp = ary[ind]
if s + tmp == q:
return True
else:
return search(ind + 1, s, q) or search(ind + 1, s + tmp, q)
def search(q):
sum_ary = [0]
for i in ary:
for s in sum_ary:
if s + i == q:
return True
sum_ary += [i + _ for _ in sum_ary]
else:
return False
for q in qs:
if search(q):
print('yes')
else:
print('no')
|
import sys
from functools import reduce
for line in sys.stdin:
if int(line) == 0:
break
s = reduce(lambda a,b: int(a)+int(b), line.strip())
print(s)
| 0 | null | 830,031,707,582 | 25 | 62 |
N = int(input())
S = str(input())
r_cnt = S.count('R')
g_cnt = S.count('G')
b_cnt = S.count('B')
ans = r_cnt*g_cnt*b_cnt
for i in range(N):
for d in range(1, N):
j = i + d
k = j + d
if k >= N:break
if S[i]!=S[j] and S[i]!=S[k] and S[j]!=S[k]:
ans -= 1
print(ans)
|
N = int(input())
S = input()
total = S.count('R') * S.count('G') * S.count('B')
cnt = 0
for i in range(N):
for j in range(i+1,N):
k = 2 * j - i
if k >= N:
break
if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
cnt += 1
print(total-cnt)
| 1 | 36,035,417,194,448 | null | 175 | 175 |
A, B, C = input().split()
A = int(A)
B = int(B)
C = int(C)
A, B, C = B, A, C
B, A, C = C, A, B
C, A, B = A, B, C
print(A, B, C)
|
n,a,b = map(int,input().split())
dif1 = abs(a-b)
if(dif1%2==0):
print(dif1//2)
else:
dif2 = (a-1) + (b-1) + 1
dif3 = (n-a) + (n-b) + 1
print(min(dif2//2,dif3//2))
| 0 | null | 73,732,019,180,302 | 178 | 253 |
r, c = map(int, input().strip().split())
l = [[0 for j in range(c+1)] for i in range(r+1)]
for i in range(r):
l[i] = list(map(int, input().strip().split()))
l[i].append(sum(l[i][0:c]))
l[r] = [l[r][j] + l[i][j] for j in range(c+1)]
print(' '.join(map(str,l[i])))
print(' '.join(map(str,l[r])))
|
#!/usr/bin/env python3
import sys
from itertools import chain
import numpy as np
def solve(X: int):
if X <= 2:
return 2
flags = np.array([True for i in range(3, X + 100, 2)])
for i in range(len(flags)):
if flags[i]:
prime = i * 2 + 3
flags[i::prime] = False
if prime >= X:
return prime
def main():
X = int(input()) # type: int
answer = solve(X)
print(answer)
if __name__ == "__main__":
main()
| 0 | null | 53,323,951,615,620 | 59 | 250 |
import sys
while True:
n, x = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
if 0 == n and 0 == x:
break
cnt = 0
goto = False
for i in range( 1, n-1 ):
if x < 3*(i+1):
break
for j in range( i+1, n ):
if x <= ( i+j ):
break
for k in range( j+1, n+1 ):
s = ( i + j + k )
if x == s:
cnt += 1
break
elif x < s:
goto = True
break
goto = False
print( cnt )
|
#coding:utf-8
#1_7_B 2015.4.5
while True:
n,x = map(int,input().split())
if n == x == 0:
break
count = 0
for i in range(1 , n + 1):
for j in range(1 , n + 1):
if i < j < (x - i - j) <= n:
count += 1
print(count)
| 1 | 1,278,151,270,004 | null | 58 | 58 |
N=int(input())
D=list(map(int,input().split()))
mod=998244353
ans=1
count=[0 for i in range(0,N)]
for i in range(0,N):
count[D[i]]+=1
able=True
if D[0]!=0 or count[0]!=1:
able=False
for i in range(0,N-1):
if count[i]==0 and count[i+1]!=0:
able=False
if able:
for i in range(0,N-1):
ans=(ans*pow(count[i],count[i+1],mod))%mod
print(ans)
else:
print(0)
|
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])
| 0 | null | 79,027,382,828,672 | 284 | 74 |
x = int(input())
y = 0
k = 0
while True:
y += x
k += 1
if y % 360 == 0:
break
print(k)
|
# import sys
# input = sys.stdin.readline
import itertools
import collections
# 持っているビスケットを叩き、1枚増やす
# ビスケット A枚を 1円に交換する
# 1円をビスケット B枚に交換する
def main():
n, m = input_list()
rooms = []
for _ in range(m):
rooms.append(input_list())
prev = [0]*n
to_list = [[] for i in range(n)]
for a, b in rooms:
to_list[a-1].append(b-1)
to_list[b-1].append(a-1)
next_q = collections.deque()
flags = [-1] * n
flags[0] = 999
next_q.append(0)
while next_q:
cur = next_q.popleft()
for room in to_list[cur]:
if flags[room] == -1:
flags[room] = cur
next_q.append(room)
print('Yes')
for i in range(1, n):
print(flags[i]+1)
def input_list():
return list(map(int, input().split()))
def input_list_str():
return list(map(str, input().split()))
if __name__ == "__main__":
main()
| 0 | null | 16,834,608,855,272 | 125 | 145 |
def resolve():
A, B, N = map(int, input().split())
if B <= N+1:
print(A*(B-1)//B)
else:
print(A*N//B)
resolve()
|
import math
a,b,n = list(map(int,input().split()))
if b <= n:
x = b - 1
else:
x = n
ans = math.floor(a * x / b)
print(ans)
| 1 | 28,043,910,666,240 | null | 161 | 161 |
import math
X=int(input())
def is_prime(x):
n = math.floor(math.sqrt(x))
for i in range(2, n+1):
if x % i == 0:
return False
return True
i = X
while True:
if is_prime(i):
print(i)
break
i += 1
|
X = int(input())
if X == 2:
print(2)
exit()
count = 0
if X % 2 == 0:
X += 1
while True:
now = X + count
k = 3
while k*k <= now:
if now % k == 0:
count += 2
break
else:
k += 2
continue
if k*k > now:
break
print(now)
| 1 | 105,274,844,577,298 | null | 250 | 250 |
i = int(input())
if i >= 30:
print('Yes')
else:
print('No')
|
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import bisect_right
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
MOD = 10**9+7
N = int(input())
A = list(map(int,input().split()))
L = A[0]
for i in range(1,N):
g = math.gcd(L,A[i])
L = L*A[i]//g
ans = 0
L %= MOD
for i in range(N):
ans += (L*pow(A[i],MOD-2,MOD))
ans %= MOD
print(ans)
| 0 | null | 46,711,994,708,012 | 95 | 235 |
#coding:utf-8
ans = []
for i in xrange(20000):
a, op, b = raw_input().split()
if op == "?":
break
else:
if op == "+":
ans.append(int(a) + int(b))
elif op == "-":
ans.append(int(a) - int(b))
elif op == "*":
ans.append(int(a) * int(b))
else:
ans.append(int(a) / int(b))
for n in xrange(len(ans)):
print(ans[n])
|
while 1:
n=raw_input()
if '?' in n: break
else: print eval(n.replace(' ',''))
| 1 | 689,560,360,480 | null | 47 | 47 |
L = int(input())
n = L/3
print(n*n*n)
|
l=int(input())
temp1=l/3
temp2=(l-l/3)/2
print(temp1*temp2*(l-temp1-temp2))
| 1 | 46,880,746,638,062 | null | 191 | 191 |
import numpy as np
S=input()
N=len(S)
mod=[0 for i in range(2019)]
mod2=0
ten=1
for i in range(N-1,-1,-1):
s=int(S[i])*ten
mod2+=np.mod(s,2019)
mod2=np.mod(mod2,2019)
mod[mod2]+=1
ten=(ten*10)%2019
ans=0
for i in range(2019):
k=mod[i]
if i==0:
if k>=2:
ans+=k*(k-1)//2+k
else:
ans+=k
else:
if k>=2:
ans+=k*(k-1)//2
print(ans)
|
def main():
input()
array = [int(x) for x in input().split()]
ans = sum(x % 2 == 1 for x in array[::2])
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 19,314,496,275,220 | 166 | 105 |
import math
ans = 0
N,D = map(int,input().split())
for i in range(N):
x,y = map(int,input().split())
if math.sqrt(abs(x)**2 + abs(y)**2) <= D:
ans += 1
print(ans)
|
from time import time
from random import randint
def func(s, x):
last = [0] * 26
score = 0
for i, v in enumerate(x, 1):
last[v] = i
c = 0
for j in range(26):
c += s[j] * (i - last[j])
score += s[i * 26 + v] - c
return score
def main():
start = time()
d, *s = map(int, open(0).read().split())
x = ([*range(26)] * 15)[:d]
M = func(s, x)
while time() - start < 1.8:
y = x[:]
if randint(0, 1):
y[randint(0, d - 1)] = randint(0, 25)
elif randint(0, 1):
i=randint(0, d - 16)
j=randint(i + 1, i + 15)
y[i], y[j] = y[j], y[i]
else:
i = randint(0, d - 15)
j = randint(i + 1, i + 7)
k = randint(j + 1, j + 7)
if randint(0, 1):
y[i], y[j], y[k] = y[j], y[k], y[i]
else:
y[i], y[j], y[k] = y[k], y[i], y[j]
t = func(s, y)
if t > M:
M = t
x = y
for t in x:
print(t + 1)
main()
| 0 | null | 7,800,292,784,690 | 96 | 113 |
def sep():
return map(int,input().strip().split(" "))
def lis():
return list(sep())
s=input()
n=len(s)
a=s[:n//2]
b=s[n//2 +1 : ]
if s==s[::-1] and a==a[::-1] and b==b[::-1]:
print("Yes")
else:
print("No")
|
s = input()
n = len(s)
flag = 1
for i in range(int(n/2)):
if s[i] != s[n-i-1]:
flag = 0
break
n2 = int((n-1)/2)
if flag == 1:
for i in range(int(n2/2)):
if s[i] != s[n2-i-1]:
flag = 0
break
if flag == 1:
print("Yes")
else:
print("No")
| 1 | 46,473,919,307,328 | null | 190 | 190 |
a,b,k = map(int,input().split())
a -= k
if a <= -1:
p = abs(a)
a = 0
b -= p
if b <= -1:
b = 0
print(str(a) + ' ' + str(b))
|
n, m = map(int,input().split())
a = list(map(int,input().split()))
h = sum(a)/(4*m)
ans = 0
for i in range(n):
if a[i] < h:
continue
else:
ans += 1
if ans < m:
print('No')
else:
print('Yes')
| 0 | null | 71,218,456,223,232 | 249 | 179 |
n = int(input())
a = list(map(int, input().split()))
a_ = [i for i in a if i % 2 == 0]
for i in a_:
bool_3 = i % 3 != 0
bool_5 = i % 5 != 0
if bool_3 and bool_5:
print('DENIED')
break
else:
print('APPROVED')
|
n=int(input())
A=list(map(int,input().split()))
for i in A:
if i%2==1 or i%3==0 or i%5==0:
continue
print("DENIED")
exit()
print("APPROVED")
| 1 | 69,002,258,935,962 | null | 217 | 217 |
N = int(input())
a = list(map(int,input().split()))
k = 1
ans = 0
for i in a:
if i == k:
k += 1
else:
ans +=1
if ans == N:
ans = -1
print(ans)
|
N = int(input())
Ali = list(map(int,input().split()))
s = 1
res = 0
for i in range(N):
if Ali[i] == s:
s += 1
else:
res += 1
if s == 1:
print(-1)
else:
print(res)
| 1 | 114,725,699,731,650 | null | 257 | 257 |
n = int(input())
print("Yes" if n % 9 == 0 else "No")
|
#####
# B #
#####
N = input()
sum = sum(map(int,N))
if sum % 9 == 0:
print('Yes')
else:
print('No')
| 1 | 4,440,298,870,098 | null | 87 | 87 |
a,b=map(int,input().split())
print('a','<'if a<b else'>'if a>b else'==','b')
|
N,K =map(int, input().split())
a = N % K
if a > K / 2:
print(K - a)
else:
print(a)
| 0 | null | 19,799,280,838,488 | 38 | 180 |
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n, k = map(int, input().split())
P = list(map(lambda x: int(x)-1, input().split()))
C = list(map(int, input().split()))
def dfs(i):
if 0 <= visited[i]:
return
visited[i] = idx
cycle.append(i)
global csum
csum += C[i]
dfs(P[i])
visited = [-1]*n
idx = 0
cycles = []
for i in range(n):
if 0 <= visited[i]:
continue
cycle = []
csum = 0
dfs(i)
cycles.append((cycle, csum))
idx += 1
INF = 10**18
ans = -INF
for i in range(n):
cycle, csum = cycles[visited[i]]
cmem = len(cycle)
if 0 < csum:
a, b = divmod(k, cmem)
scoreA = csum*(a-1)
b += cmem
score = 0
scoreB = 0
for _ in range(b):
i = P[i]
score += C[i]
if scoreB < score:
scoreB = score
X = scoreA+scoreB
else:
b = min(k, cmem)
score = 0
INF = 10**18
X = -INF
for _ in range(b):
i = P[i]
score += C[i]
if X < score:
X = score
if ans < X:
ans = X
print(ans)
|
#!/usr/bin/env python3
import sys
from itertools import chain
def max_add_1_to_n(loop, n):
# print(' max_add_1_to_n', loop, n)
l = len(loop)
acc = loop.copy()
# print(' ', acc)
max_val = max(acc)
for i in range(1, n):
for j in range(0, l):
acc[j] += loop[(i + j) % l]
# print(" ", acc)
max_val = max(max(acc), max_val)
return max_val
def max_add_0_to_n(loop, n):
# print(' max_add_0_to_n', loop, n)
if n >= 1:
return max(max_add_1_to_n(loop, n), 0)
else:
return 0
def max_loop_k(loop, K):
l = len(loop)
if K <= 2 * l:
return max_add_1_to_n(loop, K)
# K は 2 * l より長い
l_sum = sum(loop)
if l_sum <= 0:
return max_add_1_to_n(loop, l)
else:
Kdiv = K // l
Kmod = K % l
# print(' l Kdiv Kmod', l, Kdiv, Kmod)
return max_add_0_to_n(loop, l + Kmod) + l_sum * (Kdiv - 1)
def solve(N: int, K: int, P: "List[int]", C: "List[int]"):
# 簡単のためインデックスを 0 からにする
# (使用済みは -1 を入れる)
P = [i - 1 for i in P]
answer = -float("inf")
for i0 in range(N):
if P[i0] == -1:
continue
loop = []
i = i0
while P[i] != -1:
loop.append(C[i])
i_next = P[i]
P[i] = -1
i = i_next
answer = max(answer, max_loop_k(loop, K))
return answer
def main():
tokens = chain(*(line.split() for line in sys.stdin))
N = int(next(tokens)) # type: int
K = int(next(tokens)) # type: int
P = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
C = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
answer = solve(N, K, P, C)
print(answer)
if __name__ == "__main__":
main()
| 1 | 5,403,184,321,320 | null | 93 | 93 |
a, b, c = map(int, input().split())
print('Yes' if (a==b and a!=c) or (a==c and a!=b) or (b==c and b!=a) else 'No')
|
arr = list(map(int, input().split()))
arr.sort()
if (arr[0] == arr[1]) and (arr[2] != arr[1]):
print("Yes")
elif (arr[1] == arr[2]) and (arr[0] != arr[1]):
print("Yes")
else:
print("No")
| 1 | 68,377,871,666,768 | null | 216 | 216 |
def function(n):
if n < 3:
lis.append(0)
elif 3 <= n < 6:
lis.append(1)
else:
lis.append(lis[n-1] + lis[n-3])
def recri(s):
for n in range(s):
function(n)
# for n in range(20):
# print(function(n))
if __name__ == '__main__':
lis = []
s = int(input()) + 1
recri(s)
print(lis[s-1]%(10 ** 9 + 7))
|
def main():
s = int(input())
mod = 10**9+7
dp = [0] * (s+1)
dp[0] = 1
x = 0
for i in range(1, s+1):
if i-3 >= 0:
x += dp[i-3]
x %= mod
dp[i] = x
print(dp[s])
if __name__ == "__main__":
main()
| 1 | 3,289,846,628,260 | null | 79 | 79 |
from sys import exit
N, K = [int(x) for x in input().split()]
H = list([int(x) for x in input().split()])
if len(H) <= K:
print(0)
exit()
H.sort(reverse=True)
H = H[K:]
print(sum(H))
|
N, K = map(int, input().split())
Hlist = list(map(int, input().split()))
Hlist = sorted(Hlist)[::-1]
#user K super attack for largest K enemy
remainHlist = Hlist[K:]
attackTimes = sum(remainHlist)
print(attackTimes)
| 1 | 79,095,161,415,260 | null | 227 | 227 |
s = list(map(int,input().split()))
h = 60 * (s[2]-s[0])
m = s[3] - s[1]
k = s[4]
print(h+m-k)
|
import sys
numbers = []
for line in sys.stdin:
numbers.append(int(line))
k = []
k.append(1)
k.append(1)
def getFib(i, n):
if i == n :
print(k[-1])
return
k.append(int(k[i - 1]) + int(k[i - 2]))
getFib(i + 1, n)
getFib(2, int(numbers[0])+1)
| 0 | null | 9,123,622,347,840 | 139 | 7 |
import sys
import collections
input = lambda: sys.stdin.readline().rstrip()
def main():
n = int(input())
a = list(map(int, input().split()))
cnt = collections.Counter(a)
all_comb = 0
for i in cnt.keys():
all_comb += cnt[i] * (cnt[i]-1) // 2
for i in range(n):
comb = all_comb
comb -= cnt[a[i]] * (cnt[a[i]]-1) // 2
comb += (cnt[a[i]]-1) * (cnt[a[i]]-2) // 2
print(comb)
if __name__ == '__main__':
main()
|
n = int(input())
L11= [0] * 10
L12= [0] * 10
L13= [0] * 10
L21= [0] * 10
L22= [0] * 10
L23= [0] * 10
L31= [0] * 10
L32= [0] * 10
L33= [0] * 10
L41= [0] * 10
L42= [0] * 10
L43= [0] * 10
for i in range(n):
b,f,r,v = map(int, input().split())
r -= 1
if b == 1:
if f == 1:
L11[r] += v
if f == 2:
L12[r] += v
if f == 3:
L13[r] += v
if b == 2:
if f == 1:
L21[r] += v
if f == 2:
L22[r] += v
if f == 3:
L23[r] += v
if b == 3:
if f == 1:
L31[r] += v
if f == 2:
L32[r] += v
if f == 3:
L33[r] += v
if b == 4:
if f == 1:
L41[r] += v
if f == 2:
L42[r] += v
if f == 3:
L43[r] += v
def PV(L):
for i in range(9):
print(" " + str(L[i]), end="")
print(" " + str(L[9]))
def PL():
print("#" * 20)
PV(L11)
PV(L12)
PV(L13)
PL()
PV(L21)
PV(L22)
PV(L23)
PL()
PV(L31)
PV(L32)
PV(L33)
PL()
PV(L41)
PV(L42)
PV(L43)
| 0 | null | 24,289,389,119,278 | 192 | 55 |
r, c = map(int, input().split())
a, b, ans = [], [], []
for i in range(r):
a.append([int(x) for x in input().split()])
for i in range(c):
b.append(int(input()))
for i in range(r):
tmp = 0
for j in range(c):
tmp += a[i][j] * b[j]
ans.append(tmp)
for x in ans:
print(x)
|
import math
X = int(input())
ans = 0
money = 100 #初期金額
while money < X:
money += money//100
ans += 1
print(ans)
| 0 | null | 14,220,454,877,852 | 56 | 159 |
r=input();p=3.14159265358979;print "%.9f"%(p*r*r),r*2*p
|
import math
r = float(input())
area = math.pi*r**2
circuit = 2*math.pi*r
print"%f %f" % (area, circuit)
| 1 | 638,909,786,720 | null | 46 | 46 |
from collections import deque
N = int(input())
graph = [deque([]) for _ in range((N + 1))]
for _ in range(N):
u, k, *v = [int(x) for x in input().split()]
v.sort()
for i in v:
graph[u].append(i)
time = 0
arrive_time = [-1] * (N + 1)
finish_time = [-1] * (N + 1)
def dfs(v):
global time
time += 1
stack = [v]
arrive_time[v] = time
while stack:
v = stack[-1]
if graph[v]:
w = graph[v].popleft()
if arrive_time[w] < 0:
time += 1
arrive_time[w] = time
stack.append(w)
else:
time += 1
finish_time[v] = time
stack.pop()
return [arrive_time, finish_time]
for i in range(N):
if arrive_time[i + 1] < 0:
ans = dfs(i + 1)
for j in range(N):
temp = [j + 1, ans[0][j + 1], ans[1][j + 1]]
print(*temp)
|
import sys
sys.setrecursionlimit(10**6)
n = int(input())
graph = []
chart = [[int(i)] for i in range(1,n+1)]
for i in range(n):
z = [c-1 for c in list(map(int,input().split()))][2:]
graph.append(z)
time = 0
def dfs(nod):
global graph
global time
#break condition
if len(chart[nod]) != 1:
return
#end condition not necessary
#if not graph[nod]:
# time += 1
# chart[nod].append(time)
# return
# command
time += 1
chart[nod].append(time)
# move
for dis in graph[nod]:
dfs(dis)
# post-command
time += 1
chart[nod].append(time)
for i in range(n):
dfs(i)
for i in range(n):
print(*chart[i])
| 1 | 2,850,238,608 | null | 8 | 8 |
a, b = map(int, raw_input().split())
d = a / b
r = a % b
f = a * 1.0 / b
print '%d %d %f' % (d,r,f)
|
a, b = map(int, input().split())
print("{:d} {:d} {:f}".format(a//b, a%b, a/b))
| 1 | 604,246,625,180 | null | 45 | 45 |
#
# abc167 c
#
import sys
from io import StringIO
import unittest
class TestClass(unittest.TestCase):
def assertIO(self, input, output):
stdout, stdin = sys.stdout, sys.stdin
sys.stdout, sys.stdin = StringIO(), StringIO(input)
resolve()
sys.stdout.seek(0)
out = sys.stdout.read()[:-1]
sys.stdout, sys.stdin = stdout, stdin
self.assertEqual(out, output)
def test_入力例_1(self):
input = """3 3 10
60 2 2 4
70 8 7 9
50 2 3 9"""
output = """120"""
self.assertIO(input, output)
def test_入力例_2(self):
input = """3 3 10
100 3 1 4
100 1 5 9
100 2 6 5"""
output = """-1"""
self.assertIO(input, output)
def test_入力例_3(self):
input = """8 5 22
100 3 7 5 3 1
164 4 5 2 7 8
334 7 2 7 2 9
234 4 7 2 8 2
541 5 4 3 3 6
235 4 8 6 9 7
394 3 6 1 6 2
872 8 4 3 7 2"""
output = """1067"""
self.assertIO(input, output)
def resolve():
N, M, X = map(int, input().split())
CA = [list(map(int, input().split())) for _ in range(N)]
ans = float("inf")
for bit in range(1 << N):
S = [0]*(M+1)
for i, ca in enumerate(CA):
if (1 << i) & bit == 1 << i:
S = list(map(sum, zip(S, ca)))
for s in S[1:]:
if s < X:
break
else:
ans = min(ans, S[0])
if ans == float("inf"):
ans = -1
print(ans)
if __name__ == "__main__":
# unittest.main()
resolve()
|
import sys
import numpy as np
from math import ceil as C, floor as F, sqrt
from collections import defaultdict as D, Counter as CNT
from functools import reduce as R
ALP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
alp = 'abcdefghijklmnopqrstuvwxyz'
def _X(): return sys.stdin.readline().rstrip().split(' ')
def _S(ss): return tuple(ss) if len(ss) > 1 else ss[0]
def S(): return _S(_X())
def Ss(): return list(S())
def _I(ss): return tuple([int(s) for s in ss]) if isinstance(ss, tuple) else int(ss)
def I(): return _I(S())
def _Is(ss): return list(ss) if isinstance(ss, tuple) else [ss]
def Is(): return _Is(I())
n, m, x = Is()
books = []
for _ in range(n):
xs = Is()
cost = xs[0]
skills = xs[1:]
books.append((cost, skills))
ans = []
stack = [(0, books, [0] * m)]
def doit(cost, books, skills):
book = books[0]
books = books[1:]
ns = np.add(skills, book[1])
if all([n >= x for n in ns]):
ans.append(cost + book[0])
if books:
stack.append((cost+book[0], books, ns))
stack.append((cost, books, skills))
while stack:
state = stack.pop(0)
doit(state[0], state[1], state[2])
print(min(ans) if ans else '-1')
| 1 | 22,204,526,417,114 | null | 149 | 149 |
import math
class Point(object):
def __init__(self, x,y):
self.x = x*1.0
self.y = y*1.0
def Koch(n,p1,p2):
s=Point((2*p1.x+p2.x)/3,(2*p1.y+p2.y)/3)
t=Point((p1.x+2*p2.x)/3,(p1.y+2*p2.y)/3)
u=Point((t.x-s.x)*math.cos(math.radians(60))-(t.y-s.y)*math.sin(math.radians(60))+s.x,(t.x-s.x)*math.sin(math.radians(60))+(t.y-s.y)*math.cos(math.radians(60))+s.y)
if n==0:
return
Koch(n-1,p1,s)
print s.x,s.y
Koch(n-1,s,u)
print u.x,u.y
Koch(n-1,u,t)
print t.x,t.y
Koch(n-1,t,p2)
n=input()
p1=Point(0,0)
p2=Point(100,0)
print p1.x,p1.y
Koch(n,p1,p2)
print p2.x,p2.y
|
class Point:
def __init__(self, x, y):
super().__init__()
self.x = x
self.y = y
def solve(p1, p2):
s_x = p1.x + (p2.x - p1.x) * (1/3)
s_y = p1.y + (p2.y - p1.y) * (1/3)
t_x = p1.x + (p2.x - p1.x) * (2/3)
t_y = p1.y + (p2.y - p1.y) * (2/3)
u_x = (p2.x + p1.x) * (1/2) + (p1.y - p2.y) * (1/6) * pow(3, 1/2)
u_y = (p2.y + p1.y) * (1/2) + (p2.x - p1.x) * (1/6) * pow(3, 1/2)
s = Point(s_x, s_y)
t = Point(t_x, t_y)
u = Point(u_x, u_y)
return [s, u, t]
if __name__ == "__main__":
n = int(input())
P = [Point(0, 0), Point(100, 0)]
for i in range(n):
TMP = []
for j in range(len(P) - 1):
TMP.append(P[j])
TMP += solve(P[j], P[j+1])
TMP.append(P[-1])
P = TMP
for p in P:
print('{} {}'.format(p.x, p.y))
| 1 | 125,741,248,520 | null | 27 | 27 |
if __name__ == "__main__":
W, H, x, y, r = input().split()
W, H, x, y, r = int(W), int(H), int(x), int(y), int(r)
if (x - r) < 0 or W < (x + r) or (y - r) < 0 or H < (y + r):
print("No")
else:
print("Yes")
|
n,k,c=map(int,input().split())
s=input()
l=[]
r=[]
i=0
j=0
while len(l)<k and i<n:
if s[i]=='o':
l.append(i+1)
i+=c+1
else: i+=1
while len(r)<k and j<n:
if s[-j-1]=='o':
r.append(n-j)
j+=c+1
else: j+=1
for n in range(k):
if l[n]==r[-n-1]:
print(l[n])
| 0 | null | 20,714,529,748,928 | 41 | 182 |
n, m, l = map(int, input().split())
A = []
B = []
for i in range(n):
A.append([int(j) for j in input().split()])
for i in range(m):
B.append([int(j) for j in input().split()])
# ??????????????????????????????B?????¢??????????????¨???????????????
B_T = list(map(list, zip(*B)))
C = [[0 for j in range(l)] for i in range(n)]
for i in range(n):
for j in range(l):
C[i][j] = sum([a * b for (a, b) in zip(A[i], B_T[j])])
for i in range(n):
print(*C[i])
|
import sys
n, m, l = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
matrixA = [ [ int( val ) for val in sys.stdin.readline().split( " " ) ] for row in range( n ) ]
matrixB = [ [ int( val ) for val in sys.stdin.readline().split( " " ) ] for row in range( m ) ]
matrixC = [ [ sum( matrixA[i][k] * matrixB[k][j] for k in range( m ) ) for j in range( l ) ] for i in range( n ) ]
for i in range( n ):
print( " ".join( map( str, matrixC[i] ) ) )
| 1 | 1,428,569,998,142 | null | 60 | 60 |
# Peaks
import numpy as np
N,M = map(int,input().split())
h = np.array(list(map(int,input().split())))
x = dict()
for _ in range(M):
a,b = map(int,input().split())
if a-1 not in x.keys():
x[a-1] = []
if b-1 not in x.keys():
x[b-1] = []
x[a-1].append(b-1)
x[b-1].append(a-1)
ans = 0
for k,v in x.items():
cand = h[k]
tied = h[np.array(v)]
ans += [0, 1][sum(tied >= cand) == 0]
ans += N - len(x.keys())
print(ans)
|
N, M =map(int, input().split())
H=list(map(int, input().split()))
A=[True]*N
for i in range(M):
a, b = map(int, input().split())
if H[a-1]>H[b-1]:
A[b-1]=False
elif H[a-1]==H[b-1]:
A[a-1]=False
A[b-1]=False
elif H[a-1]<H[b-1]:
A[a-1]=False
print(sum(A))
| 1 | 25,022,840,313,430 | null | 155 | 155 |
def insertationSort(sort_list, n, g):
cnt = 0
for i in range(g, n):
v = sort_list[i]
j = i - g
while j >= 0 and sort_list[j] > v:
sort_list[j + g] = sort_list[j]
j -= g
cnt += 1
sort_list[j + g] = v
return cnt
def shellSort(sort_list, n):
cnt = 0
G = [1]
while True:
if G[len(G)-1] * 3 + 1 <= n:
G.append(G[len(G)-1] * 3 + 1)
else:
break
m = len(G)
for i in G[::-1]:
cnt += insertationSort(sort_list, n, i)
print(m)
print(' '.join([str(i) for i in G[::-1]]))
print(cnt)
for ans in sort_list:
print(ans)
if __name__ == "__main__":
N = int(input())
sort_list = list()
for _ in range(N):
sort_list.append(int(input()))
shellSort(sort_list, N)
|
from collections import deque
n, u, v = map(int, input().split())
edge = [[] for _ in range(n)]
for _ in range(n-1):
a, b = map(int, input().split())
edge[a-1].append(b-1)
edge[b-1].append(a-1)
d_1 = deque()
d_1.append(u-1)
dist_1 = [-1] * n
dist_1[u-1] = 0
while d_1:
node = d_1.popleft()
for next_node in edge[node]:
if dist_1[next_node] < 0:
dist_1[next_node] = dist_1[node] + 1
d_1.append(next_node)
d_2 = deque()
d_2.append(v-1)
dist_2 = [-1] * n
dist_2[v-1] = 0
while d_2:
node = d_2.popleft()
for next_node in edge[node]:
if dist_2[next_node] < 0:
dist_2[next_node] = dist_2[node] + 1
d_2.append(next_node)
res = 0
for i in range(n):
if dist_1[i] < dist_2[i]:
res = max(res, dist_2[i]-1)
print(res)
| 0 | null | 58,520,780,537,754 | 17 | 259 |
import math
k = 1
x = float(input())
while x*k%360 != 0:
k += 1
print(k)
|
import itertools
N = int(input())
L = list(map(int,(input().split())))
Combination = list(itertools.permutations(L, 3))
count = 0
for i in Combination:
# a+b>c かつ b+c>a かつ c+a>b
a = int(i[0])
b = int(i[1])
c = int(i[2])
if((a+b)> c and (b+c) >a and (c+a) >b and a!=b and b!= c and a!= c and a<b and b<c):
count+=1
print(count)
| 0 | null | 9,057,867,319,920 | 125 | 91 |
mod=1000000007
dp=[1]*2001
for i in range(3,2001):
for j in range(i+3,2001):
dp[j]=(dp[j]+dp[i])%mod
n=int(input())
if n<3:print(0)
else:print(dp[n])
|
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline # 文字列読み込む時はこっち
import numpy as np
from functools import partial
array = partial(np.array, dtype=np.int64)
zeros = partial(np.zeros, dtype=np.int64)
full = partial(np.full, dtype=np.int64)
ra = range
enu = enumerate
def exit(*argv, **kwarg):
print(*argv, **kwarg)
sys.exit()
def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと
def a_int(): return int(readline())
def ints(): return np.fromstring(readline(), sep=' ', dtype=np.int64)
def read_matrix(H, W):
'''return np.ndarray shape=(H,W) matrix'''
lines = []
for _ in range(H):
lines.append(read())
lines = ' '.join(lines) # byte同士の結合ができないのでreadlineでなくreadで
return np.fromstring(lines, sep=' ', dtype=np.int64).reshape(H, W)
def read_col(H):
'''H is number of rows
A列、B列が与えられるようなとき
ex1)A,B=read_col(H) ex2) A,=read_col(H) #一列の場合'''
ret = []
for _ in range(H):
ret.append(list(map(int, readline().split())))
return tuple(map(list, zip(*ret)))
def read_tuple(H):
'''H is number of rows'''
ret = []
for _ in range(H):
ret.append(tuple(map(int, readline().split())))
return ret
MOD = 10**9 + 7
INF = 2**31 # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter, xor, add
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right # , insort_left, insort_right
from functools import reduce
from math import gcd
def lcm(a, b):
# 最小公倍数
g = gcd(a, b)
return a // g * b
S = a_int()
'''
dp[i,j] ... 問題文の条件を満たし和がiとなる数列の通りの総数。j回前に仕切りを立てた場合の。(j=2のときは2回前以前を示すことにする)
更新
# iに仕切りを立てるとき
dp[i, 0] += dp[i-1, 2] #ここから仕切りが立てられる
# iに仕切りを立てないとき
dp[i, 0] += 0 #立てないんだから
dp[i, 1] += dp[i-1,0]
dp[i, 2] += dp[i-1,1] + dp[i-1,2]
'''
from numba import njit
@njit('(i8,)', cache=True)
def solve(S):
dp = np.zeros((S + 1, 3), dtype=np.int64)
dp[0, 0] = 1
for i in range(1, S + 1):
dp[i, 0] += dp[i - 1, 2] % MOD
dp[i, 1] += dp[i - 1, 0] % MOD
dp[i, 2] += (dp[i - 1, 1] + dp[i - 1, 2]) % MOD
print(dp[S, 0] % MOD)
solve(S)
| 1 | 3,310,850,822,642 | null | 79 | 79 |
d = int(input())
if d >= 30:
print("Yes")
else:
print("No")
|
#-*- coding: utf-8 -*-
X=int(input())
if X>=30:
print("Yes")
if X<30:
print("No")
| 1 | 5,765,501,524,848 | null | 95 | 95 |
N, R = (int(x) for x in input().split())
if N >= 10:
result = R
else:
result = R + 100*(10-N)
print(result)
|
n = int(input())
S = list(map(int, input().split()))
count = 0
def merge(A, left, mid, right):
global count
n1 = mid - left
n2 = right - mid
L = A[left: left + n1]
R = A[mid: mid + n2]
L.append(float('inf'))
R.append(float('inf'))
i = 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
count += 1
def merge_sort(A, left, right):
if (left + 1) < right:
mid = (left + right) // 2
merge_sort(A, left, mid)
merge_sort(A, mid, right)
merge(A, left, mid, right)
merge_sort(S, 0, n)
print(*S)
print(count)
| 0 | null | 31,994,500,438,510 | 211 | 26 |
n = int(input())
S = [c for c in input()]
ans = 0
i = 0
j = n-1
while i < j:
if S[i] == "W":
if S[j] == "R":
S[i] = "R"
S[j] = "W"
j -= 1
i += 1
ans += 1
else:
j -= 1
else:
i += 1
print(ans)
|
n, s = input(), input()
print(s[:s.count("R")].count("W"))
| 1 | 6,320,761,673,150 | null | 98 | 98 |
class Factorial():
def __init__(self, mod=10**9 + 7):
self.mod = mod
self._factorial = [1]
self._size = 1
self._factorial_inv = [1]
self._size_inv = 1
def __call__(self, n):
'''n! % mod '''
return self.fact(n)
def fact(self, n):
'''n! % mod '''
if n >= self.mod:
return 0
self.make(n)
return self._factorial[n]
def fact_inv(self, n):
'''n!^-1 % mod '''
if n >= self.mod:
raise ValueError('Modinv is not exist! arg={}'.format(n))
self.make_inv(n)
return self._factorial_inv[n]
def comb(self, n, r):
''' nCr % mod '''
if r > n:
return 0
t = self.fact_inv(n-r)*self.fact_inv(r) % self.mod
return self(n)*t % self.mod
def comb_with_repetition(self, n, r):
''' nHr % mod '''
t = self.fact_inv(n-1)*self.fact_inv(r) % self.mod
return self(n+r-1)*t % self.mod
def perm(self, n, r):
''' nPr % mod '''
if r > n:
return 0
return self(n)*self.fact_inv(n-r) % self.mod
@staticmethod
def xgcd(a, b):
''' return (g, x, y) such that a*x + b*y = g = gcd(a, b) '''
x0, x1, y0, y1 = 0, 1, 1, 0
while a != 0:
(q, a), b = divmod(b, a), a
y0, y1 = y1, y0 - q * y1
x0, x1 = x1, x0 - q * x1
return b, x0, y0
def modinv(self, n):
g, x, _ = self.xgcd(n, self.mod)
if g != 1:
raise ValueError('Modinv is not exist! arg={}'.format(n))
return x % self.mod
def make(self, n):
if n >= self.mod:
n = self.mod
if self._size < n+1:
for i in range(self._size, n+1):
self._factorial.append(self._factorial[i-1]*i % self.mod)
self._size = n+1
def make_inv(self, n):
if n >= self.mod:
n = self.mod
self.make(n)
if self._size_inv < n+1:
for i in range(self._size_inv, n+1):
self._factorial_inv.append(self.modinv(self._factorial[i]))
self._size_inv = n+1
mod = 10**9 + 7
fact = Factorial(mod)
n, k, *A = map(int, open(0).read().split())
A.sort()
s = 0
for i, a in enumerate(A[k-1:], k-1):
s += fact.comb(i, k-1) * a
s %= mod
for i, a in enumerate(A[:n-k+1][::-1], k-1):
s -= fact.comb(i, k-1) * a
s %= mod
print(s)
|
H1,M1,H2,M2,K = map(int,input().split())
A1 = H1*60+M1
A2 = H2*60+M2
print(max(0,A2-A1-K))
| 0 | null | 56,759,406,892,188 | 242 | 139 |
#!/usr/bin/env python
n, k = map(int, input().split())
mod = 10**9+7
d = [-1 for _ in range(k+1)]
d[k] = 1
for i in range(k-1, 0, -1):
d[i] = pow(k//i, n, mod)
j = 2*i
while j <= k:
d[i] -= d[j]
j += i
#print('d =', d)
ans = 0
for i in range(1, k+1):
ans += (i*d[i])%mod
print(ans%mod)
|
N,K = map(int,input().split())
# from scipy.special import comb
# a = comb(n, r)
MOD = 10**9 + 7
ans = 0
for k in range(K,N+2):
# print(k)
right = (N+N-k+1)*k // 2
left = (k-1)*k // 2
ans += right - left + 1
ans %= MOD
# print(ans)
# ans += comb(N+1, k, exact=True)
# print(ans)
print(ans)
| 0 | null | 34,978,488,868,910 | 176 | 170 |
all_set = ['S ' + str(i) for i in range(1, 14)] + ['H ' + str(i) for i in range(1, 14)] + ['C ' + str(i) for i in range(1, 14)] + ['D ' + str(i) for i in range(1, 14)]
r = int(input())
for _ in range(r):
x = input()
if x in all_set:
del all_set[all_set.index(x)]
for i in all_set:
print(i)
|
n = input()
cards = []
for i in range(n):
cards.append(raw_input().split())
marks = ['S', 'H', 'C', 'D']
for i in marks:
for j in range(1, 14):
if [i, str(j)] not in cards:
print i, j
| 1 | 1,042,743,538,750 | null | 54 | 54 |
n=int(input())
n=int(n/2+0.5-1)
print(n)
|
N = input()
if (int( N )%2) == 0:
print( int(int(N) / 2 -1) )
else:
print( int((int(N)-1)/2) )
| 1 | 153,304,386,973,910 | null | 283 | 283 |
N = int(input())
A = list(map(int, input().split()))
ans = float('inf')
sum_A = sum(A)
CumSum = 0
for i in range(N-1):
CumSum = CumSum + A[i]
ans = min(ans,(abs((sum_A - CumSum)-(CumSum))))
print(ans)
|
import math
num1, num2 = map(int, input().split())
print(num1 * num2 // math.gcd(num1, num2))
| 0 | null | 127,788,056,233,320 | 276 | 256 |
h = int(input())
cnt = 1
if h == 1:
print(1)
exit()
while(True):
cnt += 1
h = int(h / 2)
if h == 1:
break
print(2 ** cnt - 1)
|
H = int(input())
i = 1
cnt = 0
while H > 0:
H //= 2
cnt += i
i *= 2
print(cnt)
| 1 | 80,217,724,555,268 | null | 228 | 228 |
import sys
sys.setrecursionlimit(10000)
ERROR_INPUT = 'input is invalid'
OPECODE = ['+', '-', '*']
BUF = []
def main():
stack = get_input()
ans = calc_stack(stack=stack)
print(ans)
def calc_stack(stack):
if stack[-1] in OPECODE:
BUF.append(stack[-1])
stack.pop()
return calc_stack(stack=stack)
else:
right_num = int(stack[-1])
stack.pop()
if stack[-1] in OPECODE:
BUF.append(right_num)
BUF.append(stack[-1])
stack.pop()
return calc_stack(stack=stack)
else:
left_num = int(stack[-1])
stack.pop()
stack.append(calc(left_num, right_num, BUF[-1]))
BUF.pop()
stack.extend(reversed(BUF))
BUF.clear()
if len(stack) == 1:
return stack[0]
else:
return calc_stack(stack=stack)
def calc(left, right, ope):
if ope == '+':
return left + right
elif ope == '-':
return left - right
elif ope == '*':
return left * right
def get_input():
inp = input().split(' ')
opecode_count = 0
OPECODE_count = 0
for i in inp:
if i in OPECODE:
opecode_count += 1
elif int(i) < 0 or int(i) > 10**6:
print(ERROR_INPUT)
sys.exit(1)
else:
OPECODE_count += 1
if opecode_count < 1 or opecode_count > 100:
print(ERROR_INPUT)
sys.exit(1)
if OPECODE_count < 2 or OPECODE_count > 100:
print(ERROR_INPUT)
sys.exit(1)
return inp
main()
|
list = input().split()
stack = []
for i in list:
if ( i.isdigit() ):
stack.append(int(i))
elif (i == '+'):
stack.append(stack.pop() + stack.pop())
elif (i == '*'):
stack.append(stack.pop() * stack.pop())
elif (i == '-'):
stack.append( (-1)*stack.pop() + stack.pop())
print(stack.pop())
| 1 | 37,649,235,680 | null | 18 | 18 |
n = int(input())
print(n//2 + n%2)
|
def A():
n = int(input())
print(-(-n//2))
A()
| 1 | 58,990,955,754,042 | null | 206 | 206 |
import sys
S = input()
if not S.islower():sys.exit()
if not ( 3 <= len(S) <= 99 and len(S) % 2 == 1 ): sys.exit()
# whole check
first = int((len(S)-1)/2)
F = S[0:first]
last = int((len(S)+3)/2)
L = S[last-1:]
condition = 0
if S == S[::-1]:
condition += 1
if F == F[::-1]:
condition += 1
if L == L[::-1]:
condition += 1
print('Yes') if condition == 3 else print('No')
|
s=input()
n=len(s)
s1=s[:(n-1)//2]
s2=s[n+3//2:]
def ispalindrome(str):
if str==str[::-1]:
s1=s[:(n-1)//2]
if s1==s1[::-1]:
s2=s[n+3//2:]
if s2==s2[::-1]:
return 'Yes'
return 'No'
return 'No'
else:
return 'No'
print(ispalindrome(s))
| 1 | 46,434,850,552,192 | null | 190 | 190 |
import math
def merge(a,l,m,r):
global cnt
L = a[l:m]+[math.inf]
R = a[m:r]+[math.inf]
i = 0
j = 0
for k in range(l,r):
cnt+=1
if L[i]<=R[j]:
a[k] = L[i]
i+=1
else:
a[k]=R[j]
j+=1
def mergeSort(a,l,r):
if l+1<r:
m = (l+r)//2
mergeSort(a,l,m)
mergeSort(a,m,r)
merge(a,l,m,r)
n = int(input())
a = list(map(int, input().split()))
cnt = 0
mergeSort(a,0,n)
print(*a)
print(cnt)
|
N=int(input())
ans = 0
for k in range(1,N+1):
n_ = N // k
ans_ = k*n_*(n_+1)//2
ans+= ans_
print(ans)
| 0 | null | 5,632,752,934,462 | 26 | 118 |
X = int(input())
if X == 2:
print(2)
exit()
for i in range(X,2*X):
for j in range(2,i):
if i % j == 0:
break
if j == i-1:
print(i)
exit()
|
while True:
table=str(input())
if table[0] == '0':
break
print(sum(int(num) for num in(table)))
| 0 | null | 53,629,702,594,412 | 250 | 62 |
N = int(input())
S = list(input())
alp = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
S_a = ""
for s in S:
n = alp.index(s)+N
if(alp.index(s)+N>=26):
n -= 26
S_a += alp[n]
print(S_a)
|
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
n,m=map(int,input().split())
uf=UnionFind(n)
for i in range(m):
a,b=map(int,input().split())
uf.union(a-1,b-1)
print(uf.group_count()-1)
| 0 | null | 68,467,834,888,022 | 271 | 70 |
from itertools import combinations
while True:
n,m=map(int,input().split())
if n==m==0: break
print(sum(1 for p in combinations(range(1,n+1),3) if sum(p)==m))
|
def main():
while True:
n, x = map(int, input().split())
if n == x == 0:
break
number = 0
for i in range(n):
j = i + 1
if x - j > n*2 - 1:
continue
elif x - j <= j:
break
else:
for k in range(x - j):
m = k + 1
if k < j:
continue
elif (x - j - m) > m and x - j - m <= n:
number += 1
print(number)
return
if __name__ == '__main__':
main()
| 1 | 1,298,614,371,292 | null | 58 | 58 |
n = int(input())
a = [int(s) for s in input().split()]
ans = 'APPROVED'
for num in a:
if num % 2 == 0:
if num % 3 != 0 and num % 5 != 0:
ans = 'DENIED'
break
print(ans)
|
nm = list(map(lambda x:int(x),input().split(" ")))
a = list()
b = list()
count = nm[0]
while count > 0:
a += list(map(lambda x:int(x), input().split(" ")))
count -= 1
count = nm[1]
while count > 0:
b += {int(input())}
count -= 1
for m in range(nm[0]):
c = 0
for k in range(nm[1]):
c += a[k+m*nm[1]]*b[k]
print(c)
| 0 | null | 34,931,074,584,900 | 217 | 56 |
import math
import collections
n, k = map(int, input().split())
W = collections.deque()
for i in range(n):
W.append(int(input()))
left = max(math.ceil(sum(W) / k), max(W))
right = sum(W)
center = (left + right) // 2
# print('------')
while left < right:
i = 1
track = 0
# print(center)
for w in W:
# if center == 26:
# print('track: ' + str(track))
track += w
if track > center:
track = w
i += 1
if i > k:
left = center + 1
break
else:
right = center
center = (left + right) // 2
print(center)
|
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')
class BinomialCoefficient(object):
def __init__(self, N=510000, MOD=10**9+7):
self.fac = [1, 1]
self.finv = [1, 1]
self.inv = [0, 1]
self.MOD = MOD
for i in range(2, N + 1):
self.fac.append((self.fac[-1] * i) % MOD)
self.inv.append((-self.inv[MOD % i] * (MOD // i)) % MOD)
self.finv.append((self.finv[-1] * self.inv[-1]) % MOD)
def comb(self, n, r):
if r < 0 or n < r or r < 0:
return 0
return self.fac[n] * self.finv[r] * self.finv[n - r] % self.MOD
K = I()
S = input()
bi = BinomialCoefficient(N=10 ** 6 * 2 + 1)
ans = 0
# i := Snのindex
for i in range(len(S) - 1, len(S) + K):
tail = len(S) + K - i - 1
lans = bi.comb(i, len(S) - 1)
lans = lans * pow(25, K - tail, MOD) % MOD
lans = lans * pow(26, tail, MOD) % MOD
ans = (ans + lans) % MOD
print(ans)
| 0 | null | 6,422,550,104,760 | 24 | 124 |
if __name__ == '__main__':
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)[::-1]
s = sum(A)
cnt = 0
for i in range(M):
if s<=4*M*A[i]:
cnt += 1
if cnt==M:
print("Yes")
else:
print("No")
|
class Tree():
def __init__(self, n, edge, indexed=1):
self.n = n
self.tree = [[] for _ in range(n)]
for e in edge:
self.tree[e[0] - indexed].append(e[1] - indexed)
self.tree[e[1] - indexed].append(e[0] - indexed)
def setroot(self, root):
self.root = root
self.parent = [None for _ in range(self.n)]
self.parent[root] = -1
self.depth = [None for _ in range(self.n)]
self.depth[root] = 0
self.order = []
self.order.append(root)
self.size = [1 for _ in range(self.n)]
stack = [root]
while stack:
node = stack.pop()
for adj in self.tree[node]:
if self.parent[adj] is None:
self.parent[adj] = node
self.depth[adj] = self.depth[node] + 1
self.order.append(adj)
stack.append(adj)
for node in self.order[::-1]:
for adj in self.tree[node]:
if self.parent[node] == adj:
continue
self.size[node] += self.size[adj]
import sys
input = sys.stdin.readline
N, u, v = map(int, input().split())
u -= 1; v -= 1
E = [tuple(map(int, input().split())) for _ in range(N - 1)]
t = Tree(N, E)
t.setroot(u); dist1 = t.depth
t.setroot(v); dist2 = t.depth
tmp = 0
for i in range(N):
if dist1[i] < dist2[i]:
tmp = max(tmp, dist2[i])
print(tmp - 1)
| 0 | null | 77,748,003,139,008 | 179 | 259 |
n=int(input())
xy=[list(map(int,input().split())) for _ in range(n)]
from itertools import permutations
ans=0
for i in permutations(range(n),n):
for j in range(1,n):
ans+=((xy[i[j]][0]-xy[i[j-1]][0])**2+(xy[i[j]][1]-xy[i[j-1]][1])**2)**0.5
for i in range(1,n+1):
ans/=i
print(ans)
|
import itertools
import math
#print(3 & (1 << 0))
def main():
N = int(input())
items = [i+1 for i in range(N)]
locations=[]
for i in range(N):
locations.append(list(map(int, input().split())))
paths =list(itertools.permutations(items))
sum = 0
for path in paths: # path = [1,2,3,4,5]
for i in range(len(path)-1):
from_idx = path[i] -1
to_idx = path[i+1] -1
xdiff= locations[from_idx][0] - locations[to_idx][0]
ydiff= locations[from_idx][1] - locations[to_idx][1]
sum = sum + math.sqrt(xdiff**2 + ydiff**2)
print( sum / len(paths))
main()
| 1 | 148,049,101,175,712 | null | 280 | 280 |
import itertools
n, m, x = map(int, input().split())
books = []
for i in range(n):
ins = list(map(int, input().split()))
books.append({"c": ins[0], "a": ins[1: m+1]})
ans = float('inf')
for i in range(1, n+1):
book_list = list(itertools.combinations(list(range(n)), i))
for lis in book_list:
cost_sum = 0
a_sum = [0] * m
ok = 0
ok_list = [False] * m
for j in lis:
cost_sum += books[j]['c']
for k in range(m):
a_sum[k] += books[j]['a'][k]
if not ok_list[k] and a_sum[k] >= x:
ok += 1
ok_list[k] = True
if ok == m and ans > cost_sum:
ans = cost_sum
if ans == float('inf'):
print(-1)
else:
print(ans)
|
n, m, x = map(int, input().split())
c = [0] * n
a = [0] * n
for i in range(n):
xs = list(map(int, input().split()))
c[i] = xs[0]
a[i] = xs[1:]
ans = 10 ** 9
for i in range(2 ** n):
csum = 0
asum = [0] * m
for j in range(n):
if (i >> j) & 1:
csum += c[j]
for k in range(m):
asum[k] += a[j][k]
if len(list(filter(lambda v: v >= x, asum))) == m:
ans = min(ans, csum)
print(-1 if ans == 10 ** 9 else ans)
| 1 | 22,304,785,019,968 | null | 149 | 149 |
def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(input()) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
ns = []
while len(ns) < rantime:
n = random.randint(ran1, ran2)
if not n in ns:
ns.append(n)
return sorted(ns)
def rand_query(ran1, ran2, rantime):
r_query = []
while len(r_query) < rantime:
n_q = rand_ints_nodup(ran1, ran2, 2)
if not n_q in r_query:
r_query.append(n_q)
return sorted(r_query)
from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right
import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
#############
# Main Code #
#############
N = getN()
str_l = 'abcdefghij'
ans = [0]
ans_str = []
def alter(array):
s = ""
for i in array:
s += str_l[i]
return s
def dfs(array):
if len(array) == N:
ans_str.append(alter(array))
return
for i in range(max(array) + 2):
new_array = copy.deepcopy(array)
new_array.append(i)
dfs(new_array)
dfs(ans)
ans_str.sort()
for i in ans_str:
print(i)
|
N=int(input())
alpha=[chr(ord('a') + i) for i in range(26)]
l=[]
def ans(le,alp):
s=len(set(alp))
if le==N:
l.append(alp)
return
for i in range(s+1):
ans(le+1,alp+alpha[i])
ans(1,"a")
for i in l:
print(i)
| 1 | 52,693,133,191,160 | null | 198 | 198 |
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq
def ri():
return int(input())
def rl():
return list(map(int, input().split()))
def solve():
n, m, q = rl()
Q = []
for i in range(q):
Q.append(rl())
ways = [[i] for i in range(1, m + 1)]
for i in range(n - 1):
new_ways = []
for way in ways:
new_way = list(way)
for j in range(way[-1], m + 1):
new_ways.append(new_way + [j])
ways = new_ways
best = 0
for way in ways:
tot = 0
for a, b, c, d in Q:
if way[b - 1] - way[a - 1] == c:
tot += d
best = max(best, tot)
print (best)
mode = 's'
if mode == 'T':
t = ri()
for i in range(t):
solve()
else:
solve()
|
import itertools
n,m,q=map(int,input().split())
a=[]
b=[]
c=[]
d=[]
for i in range(q):
a1,b1,c1,d1=map(int,input().split())
a.append(a1)
b.append(b1)
c.append(c1)
d.append(d1)
l=list(range(1,m+1))
ans=0
for A in list(itertools.combinations_with_replacement(l, n)):
sum=0
for i in range(q):
if A[b[i]-1]-A[a[i]-1]==c[i]:
sum+=d[i]
ans=max(ans,sum)
print(ans)
| 1 | 27,560,362,129,080 | null | 160 | 160 |
while True:
(x, y) = [int(i) for i in input().split()]
if x == y == 0:
break
if x < y:
print(x, y)
else:
print(y, x)
|
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
from collections import Counter
def main():
n = int(input())
d1 = {'AC':0, 'WA':0, 'TLE': 0,'RE':0}
s = []
for _ in range(n):
s.append(input())
sa = Counter(s)
for k, v in sa.items():
d1[k] += v
print('AC x', d1['AC'])
print('WA x', d1['WA'])
print('TLE x', d1['TLE'])
print('RE x', d1['RE'])
if __name__ == '__main__':
main()
| 0 | null | 4,622,564,302,918 | 43 | 109 |
from collections import defaultdict as dict
n, p = map(int, input().split())
s = input()
a = []
for x in s:
a.append(int(x))
def solve():
l = [0]*p
ans = 0
for x in a:
l_ = [0] * p
for i in range(p):
l_[(i * 10 + x) % p] += l[i]
l, l_ = l_, l
l[x % p] += 1
ans += l[0]
print(ans)
if p <= 5:
solve()
exit()
x = 0
mem = dict(int)
mem[0] = 1
ans = 0
a.reverse()
d = 1
for y in a:
x += d*y
x %= p
d = (d * 10) % p
ans += mem[x]
mem[x] += 1
# print(mem)
print(ans)
|
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7
def gcd(n, m):
if m == 0:
return n
return gcd(m, n % m)
def lcm(a, b):
return a * b // gcd(a, b)
L = 1
for a in A:
L = lcm(L, a)
L %= MOD
coef = 0
for a in A:
coef += pow(a, MOD - 2, MOD)
print((L * coef) % MOD)
| 0 | null | 72,815,508,745,280 | 205 | 235 |
def solve():
K, X = map(int, input().split())
return "Yes" if K*500 >= X else "No"
print(solve())
|
n = list(map(int, input().split()))
n.sort()
print('{} {} {}'.format(n[0], n[1], n[2]))
| 0 | null | 49,410,704,668,260 | 244 | 40 |
# coding:utf-8
class Dice:
def __init__(self):
self.f = [0 for i in range(6)]
def roll_z(self): self.roll(1,2,4,3)
def roll_y(self): self.roll(0,2,5,3)
def roll_x(self): self.roll(0,1,5,4)
def roll(self,i,j,k,l):
t = self.f[i]; self.f[i] = self.f[j]; self.f[j] = self.f[k]; self.f[k] = self.f[l]; self.f[l] = t
def move(self,ch):
if ch == 'E':
for i in range(3):
self.roll_y()
if ch == 'W':
self.roll_y()
if ch == 'N':
self.roll_x()
if ch == 'S':
for i in range(3):
self.roll_x()
dice = Dice()
dice.f = map(int, raw_input().split())
com = raw_input()
for i in range(len(com)):
dice.move(com[i])
print dice.f[0]
|
n,m,l=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(n)]
b=[list(map(int,input().split())) for _ in range(m)]
[print(*x)for x in[[sum(s*t for s,t in zip(c,l))for l in zip(*b)]for c in a]]
| 0 | null | 844,039,523,810 | 33 | 60 |
N = int(input())
W = [[-1]*N for _ in range(N)]
for i in range(N):
A = int(input())
for j in range(A):
x, y = [int(z) for z in input().split()]
x -= 1
W[i][x] = y
M = 0
for b in range(2**N):
d = [0] * N
for i in range(N):
if (b >> i) & 1:
d[i] = 1
ok = True
for i in range(N):
if d[i] == 1:
for j in range(N):
if W[i][j] == -1:
continue
if W[i][j] != d[j]:
ok =False
if ok == True:
M = max(M, sum(d))
print(M)
|
n = int(input())
xy = [list(map(int, input().split())) for _i in range(n)]
x = [i+j for i, j in xy]
y = [i-j for i, j in xy]
x.sort()
y.sort()
print(max(abs(x[0]-x[-1]), abs(y[0]-y[-1])))
| 0 | null | 62,567,624,200,332 | 262 | 80 |
mod = (10 ** 9 + 7)
def comb(n, r):
p, q = 1, 1
for i in range(r):
p = p *(n-i)%mod
q = q *(i+1)%mod
return p * pow(q, mod-2, mod) % mod
n, a, b = list(map(int, input().split()))
s = pow(2, n, mod) - 1
print((s - comb(n, a) - comb(n, b)) % mod)
|
st=input().rstrip().split(" ")
s=st[0]
t=st[1]
print(t,end="")
print(s)
| 0 | null | 85,095,583,814,780 | 214 | 248 |
M=[]
F=[]
R=[]
while True:
m,f,r=map(int,raw_input().split())
if (m,f,r)==(-1,-1,-1):
break
else:
M.append(m)
F.append(f)
R.append(r)
for i in range(len(M)):
sum=M[i]+F[i]
if M[i]==-1 or F[i]==-1:
print('F')
elif sum>=80:
print('A')
elif sum>=65:
print('B')
elif sum>=50:
print('C')
elif sum>=30:
if R[i]>=50:
print('C')
else:
print('D')
else:
print('F')
|
list = input().split()
print(list[2],list[0],list[1])
| 0 | null | 19,675,187,203,574 | 57 | 178 |
W, H, x, y, r = (int(a) for a in input().split())
if x < W and y < H and (x-r) >= 0 and (x + r) <= W and (y-r) >= 0 and (y+r) <= H:
print("Yes")
else:
print("No")
|
W,H,x,y,r = map(int ,raw_input().split())
#print ' '.join(map(str,[W,H,x,y,r]))
if x < W and 0 < x and 0<y and y < H and r <= x and r <= (H - x) :
print "Yes"
else:
print "No"
| 1 | 447,950,423,270 | null | 41 | 41 |
def main():
s = int(input())
mod = 10**9 + 7
dp = [0] * (s+1)
dp[0] = 1
# for i in range(1, s+1):
# for j in range(0, (i-3)+1):
# dp[i] += dp[j]
# dp[i] %= mod
for i in range(1, s+1):
if i < 3:
dp[i] = 0
else:
dp[i] = dp[i-1] + dp[i-3]
dp[i] %= mod
print(dp[-1])
if __name__ == "__main__":
main()
|
from sys import stdin
def solve():
s = int(stdin.readline())
mod = 10**9+7
if s < 3: return 0
dp = [0]*(s+1)
dp[0] = 1
for i in range(3,s+1):
dp[i] = dp[i-1] + dp[i-3]
return dp[s]%mod
print(solve())
| 1 | 3,249,898,531,222 | null | 79 | 79 |
h, a = map(int, input().split())
ans = 0
while True:
if h > 0:
h = h - a
ans += 1
else:
print(ans)
exit()
|
h,a=map(int,input().split());print(h//a+1 if h%a!=0 else h//a)
| 1 | 76,764,212,749,728 | null | 225 | 225 |
a,b=map(int,input().split())
if a-2*b>=0:
print(a-2*b)
else:
print("0")
|
X, Y = map(int, input().split())
if X>=2*Y:
print(X-2*Y)
else:
print(0)
| 1 | 166,374,677,241,278 | null | 291 | 291 |
import itertools
n = int(input())
ans = 0
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)
return a
def q(m):
check = 0
while m >= check * (check + 1) / 2:
check += 1
return check - 1
a = prime_factorize(n)
gr = itertools.groupby(a)
for key, group in gr:
ans += q(len(list(group)))
print(ans)
|
N = int(input())
"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
def factorization(n):
if (n == 1):
return []
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
#print(factorization(N))
list_a = factorization(N)
count = 0
for i in range(len(list_a)):
num = list_a[i][1]
cal = 1
while(num > 0):
num -= cal
cal += 1
if(num < 0) :
break
count += 1
#print(num,count)
print(count)
| 1 | 17,058,122,949,306 | null | 136 | 136 |
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 ""
|
import math
def is_prime(n):
if n == 1: return False
for k in range(2, int(math.sqrt(n)) + 1):
if n % k == 0:
return False
return True
X = int(input())
i = X
while 1:
if not is_prime(i):
i += 1
else:
ans = i
print(i)
break
| 0 | null | 53,229,248,648,640 | 51 | 250 |
a,b=map(int,input().split())
print('Yes') if a==b else print('No')
|
a= list(map(int,input().split()))
n=a[0]
m=a[1]
if n==m:
print("Yes")
else:
print("No")
| 1 | 83,001,897,653,948 | null | 231 | 231 |
import bisect
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
cnt = 0
for i in range(n):
for j in range(i+1, n):
x = bisect.bisect_left(l, l[i]+l[j])
cnt += x-j-1
print(cnt)
|
import bisect
N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for i in range(N - 1, 1, -1):
for j in range(i - 1, 0, -1):
x = bisect.bisect(L, L[i] - L[j])
ans += max((j - x), 0)
print(ans)
| 1 | 172,098,809,795,858 | null | 294 | 294 |
mod = pow(10, 9) + 7
def main():
N, K = map(int, input().split())
table = [0]*(K+1)
for k in range(K, 0, -1):
m = K//k
tmp = pow(m, N, mod)
for l in range(2, m+1):
tmp -= table[l*k]
tmp %= mod
table[k] = tmp
ans = 0
for i in range(len(table)):
ans += (i * table[i])%mod
ans %= mod
#print(table)
print(ans)
if __name__ == "__main__":
main()
|
#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))
| 0 | null | 22,579,369,643,812 | 176 | 109 |
A=list(map(int,input().split()))
if A[0]+A[1]+A[2]<=21:
print("win")
else:
print("bust")
|
from collections import deque
import math
import sys
x,y,a,b,c = list(map(int,sys.stdin.readline().split()))
p = sorted(list(map(int,sys.stdin.readline().split())), reverse=True)
q = sorted(list(map(int,sys.stdin.readline().split())), reverse=True)
r = sorted(list(map(int,sys.stdin.readline().split())), reverse=True)
eat=[]
if x<len(p):
[eat.append(red) for red in p[:x]]
else:
[eat.append(red) for red in p]
if y<len(q):
[eat.append(green) for green in q[:y]]
else:
[eat.append(green) for green in q]
[eat.append(apple) for apple in r]
eat = sorted(eat, reverse=True)
#print(sum(eat[:x + y]))
ans = 0
for taste in eat[:x + y]:
ans += taste
print(ans)
| 0 | null | 81,946,365,178,984 | 260 | 188 |
n = int(input())
f = 0
L = []
for i in range(n):
a,b = map(int, input().split())
L.append([a,b])
for i in range(2,n):
if(L[i-2][0] == L[i-2][1] and L[i-1][0] == L[i-1][1] and L[i][0] == L[i][1]):
f = 1
break
if(f):
print('Yes')
else:
print('No')
|
cnt=0
def mer(l,r):
global cnt
ll=len(l)
rr=len(r)
md=[]
i,j=0,0
l.append(float('inf'))
r.append(float('inf'))
for k in range(ll+rr):
cnt+=1
if l[i]<=r[j]:
md.append(l[i])
i+=1
else:
md.append(r[j])
j+=1
return md
def mergesort(a):
m=len(a)
if m<=1:
return a
m=m//2
l=mergesort(a[:m])
r=mergesort(a[m:])
return mer(l,r)
n=int(input())
a=list(map(int, input().split()))
b=mergesort(a)
for i in range(n-1):
print(b[i],end=" ")
print(b[n-1])
print(cnt)
| 0 | null | 1,321,635,460,352 | 72 | 26 |
while True:
a = input()
b = a.split(' ')
b.sort(key=int)
if int(b[0]) == 0 and int(b[1]) == 0:
break
print('%s %s' % (b[0],b[1]))
|
import sys
for e in iter(sys.stdin.readline, '0 0\n'):
print(*sorted(map(int, e.split())))
| 1 | 522,397,875,630 | null | 43 | 43 |
N = int(input())
cnt = 0
for A in range(1, N + 1):
for B in range(1, N // A + 1):
C = N - A * B
if C >= 1 and A * B + C == N:
cnt += 1
print(cnt)
|
n = int(input())
print(sum((n - 1) // i for i in range(1, n)))
| 1 | 2,551,048,809,570 | null | 73 | 73 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.