code1
stringlengths 17
427k
| code2
stringlengths 17
427k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.7M
180,677B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())
if A < B:
if A + (V*T) >= B + (W*T):
print("YES")
else:
print("NO")
else:
if A - (V*T) <= B - (W*T):
print("YES")
else:
print("NO") | A,V=map(int,input().split())
B,W=map(int,input().split())
T=int(input())
if V<=W or (abs(A-B)/(V-W))>T:
print("NO")
else:
print("YES") | 1 | 15,040,686,905,360 | null | 131 | 131 |
import math
def sieve_of_erastosthenes(num):
is_prime = [True for i in range(num+1)]
is_prime[0] = False
is_prime[1] = False
for i in range(2, int(num**0.5) + 1):
if not is_prime[i]:
continue
for j in range(i * 2, num + 1, i):
is_prime[j] = False
return [i for i in range(num + 1) if is_prime[i]]
N = int(input())
A = [int(i) for i in input().split()]
ans = math.gcd(A[0], A[1])
tmp = math.gcd(A[0], A[1])
for i in range(2, N):
ans = math.gcd(ans, A[i])
if ans > 1:
print('not coprime')
exit()
maxA = max(A)
l = sieve_of_erastosthenes(maxA)
B = [False for i in range(maxA+1)]
for i in range(N):
B[A[i]] = True
flag = False
for each in l:
tmp = each
counter = 0
while True:
if B[tmp]:
counter += 1
tmp += each
if tmp > maxA:
break
if counter > 1:
flag = True
break
if flag:
print('setwise coprime')
else:
print('pairwise coprime') | from math import gcd
n=int(input())
a=list(map(int,input().split()))
g=gcd(a[0],a[1])
for i in range(n-2):
g=gcd(g,a[i+2])
if a==[1]*n:
print("pairwise coprime")
exit()
if g!=1:
print("not coprime")
exit()
temp=[i for i in range(10**6+5)]
p=2
while p*p<=10**6+5:
if temp[p]==p:
for q in range(2*p,10**6+5,p):
if temp[q]==q:
temp[q]=p
p+=1
ans=[0]*(10**6+10)
for j in a:
count=set()
while j>1:
count.add(temp[j])
j//=temp[j]
for k in count:
ans[k]+=1
if max(ans)!=1:
print("setwise coprime")
else:
print("pairwise coprime")
| 1 | 4,096,314,196,238 | null | 85 | 85 |
N = int(input())
A = list(map(int,input().split()))
ans = 0
for i in range(N):
for j in range(i+1,N):
temp = A[i]*A[j]
ans += temp
print(ans) |
def main():
s = input()
if s[0]==s[1]==s[2]:
print("No")
else:
print("Yes")
if __name__ == "__main__":
main() | 0 | null | 111,850,954,908,238 | 292 | 201 |
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT() : return int(input())
def MAP() : return map(int,input().split())
def MAP1() : return map(lambda x:int(x)-1,input().split())
def LIST() : return list(MAP())
def LIST1() : return list(MAP1())
def solve():
N = INT()
a = []
b = []
for i in range(N):
A, B = MAP()
a.append(A)
b.append(B)
a.sort()
b.sort()
if N % 2 == 1:
am = a[(N+1)//2-1]
bm = b[(N+1)//2-1]
ans = bm - am + 1
else:
am = ( a[N//2-1]+a[N//2] ) / 2
bm = ( b[N//2-1]+b[N//2] ) / 2
ans = int( ( bm - am ) * 2 + 1 )
print(ans)
if __name__ == '__main__':
solve() | def main():
n = int(input())
a_list = []
b_list = []
for _ in range(n):
a, b = map(int, input().split())
a_list.append(a)
b_list.append(b)
a_sorted = list(sorted(a_list))
b_sorted = list(sorted(b_list))
if n%2:
print(b_sorted[n//2]-a_sorted[n//2]+1)
else:
print((b_sorted[n//2-1]+b_sorted[n//2]-a_sorted[n//2-1]-a_sorted[n//2])+1)
if __name__ == "__main__":
main() | 1 | 17,346,771,820,448 | null | 137 | 137 |
import sys
input = sys.stdin.readline
def p_count(n):
return bin(n)[2:].count('1')
n = int(input())
x = input().rstrip()
x_dec = int(x,base = 2)
pop_cnt = x.count('1')
pop_cnt_0 = (pop_cnt + 1)
pop_cnt_1 = (pop_cnt - 1)
x_0 = pow(x_dec,1,pop_cnt_0)
x_1 = pow(x_dec,1,pop_cnt_1) if pop_cnt_1 > 0 else 0
x_bit = [0]*n
for i in range(n-1,-1,-1):
if x[i] == '0':
x_bit[i] = (x_0 + pow(2,n-1-i,pop_cnt_0))%pop_cnt_0
#x_bit[i] = (x_dec + pow(2,n-1-i))%pop_cnt_0
else:
if pop_cnt_1 > 0:
x_bit[i] = (x_1 - pow(2,n-1-i,pop_cnt_1))
x_bit[i] = x_bit[i] if x_bit[i] >= 0 else x_bit[i] + pop_cnt_1
else:
x_bit[i] = -1
anslist = []
for i in range(n):
if x_bit[i] == -1:
anslist.append(0)
continue
ans = 1
now = x_bit[i]
while True:
if now == 0:
break
now = now%p_count(now)
ans += 1
anslist.append(ans)
for ans in anslist:
print(ans)
| def pcmod(n):
if n==0:
return 1
return 1+pcmod(n%bin(n).count('1'))
def main():
n = int(input())
x = list(map(int,list(input())))
m_1 = x.count(1)-1
m_0 = x.count(1)+1
baser_1 = 0
baser_0 = 0
if m_1!=0:
for i in range(n):
baser_1 += x[i] * pow(2,(n-1-i),m_1)
baser_1 %= m_1
for i in range(n):
baser_0 += x[i] * pow(2,(n-1-i),m_0)
baser_0 %= m_0
ans = [0]*n
for i in range(n):
a = 0
if x[i]==1:
if m_1==0:
ans[i] = 0
continue
t = (baser_1 - pow(2,(n-1-i),m_1))%m_1
a = pcmod(t)
if x[i]==0:
t = (baser_0 + pow(2,(n-1-i),m_0))%m_0
a = pcmod(t)
ans[i] = a
for a in ans:
print(a)
if __name__ == "__main__":
main() | 1 | 8,193,003,287,352 | null | 107 | 107 |
# -*- coding: utf-8 -*-
import math
a, b, C = map(float, input().split())
c = math.sqrt((a * a) + (b * b) - 2 * a * b * math.cos(math.radians(C)))
s = (a * b * math.sin(math.radians(C))) / 2
l = a + b + c
h = (2 * s) / a
print(s)
print(l)
print(h)
| N = int(input())
n = N%10
honList = [2, 4, 5, 7, 9]
ponList = [0, 1, 6, 8]
if n in honList:
print('hon')
elif n in ponList:
print('pon')
else :
print('bon') | 0 | null | 9,786,999,937,198 | 30 | 142 |
_ = input()
N = sorted([int(v) for v in input().split()])
s = 1
for n in N:
s *= n
if s == 0 or s > 10**18:
break
print(s if s <= 10**18 else -1) | x = int(input())
for i in range(1, 100000):
if x * i % 360 == 0:
print(i)
exit()
| 0 | null | 14,688,603,348,288 | 134 | 125 |
n,k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
for i in range(n-k):
if a[i]<a[i+k]:
print("Yes")
else:
print("No") | n = input()
if n != 0:
l = [int(x) for x in raw_input().split()]
print min(l), max(l), sum(l)
else:
print "0 0 0" | 0 | null | 3,952,085,543,952 | 102 | 48 |
N=int(input())
S=list(input())
a=0#色変化
for i in range(N-1):
if not S[i]==S[i+1]:
a=a+1
print(a+1) | N=int(input())
S=input()
ans=S[0]
for s in S:
if ans[-1]!=s:
ans+=s
print(len(ans)) | 1 | 170,275,916,736,432 | null | 293 | 293 |
n = input()
i = 1
num = []
while i <= n:
if i % 3 == 0:
num.append(i)
i +=1
else:
x = i
while x > 0:
if x % 10 == 3:
num.append(i)
break
else:
x /= 10
i += 1
print("{}".format(str(num)).replace("["," ").replace("]","").replace(",","")) | N=int(input())
d={"AC":0,"WA":0,"TLE":0,"RE":0}
for _ in range(N):
d[input()]+=1
print("AC x",d["AC"])
print("WA x",d["WA"])
print("TLE x",d["TLE"])
print("RE x",d["RE"])
| 0 | null | 4,850,546,460,800 | 52 | 109 |
# 素因数分解
N=int(input())
cand=[]
def check(N0,K0):
if N0%K0==0:
return check(int(N0/K0),K0)
elif N0%K0==1:
return 1
else:
return 0
def check0(N0,K0):
while N0%K0==0:
N0=int(N0/K0)
if N0%K0==1:
return 1
else:
return 0
# N-1の約数の数
for i in range(2,int((N-1)**0.5)+1):#O(N**0.5)
if (N-1)%i==0:
cand.append(i)
if i!=int((N-1)/i):
cand.append(int((N-1)/i))
if N>2:
cand.append(N-1)
# Nの約数
for i in range(2,int(N**0.5)+1):#O(N**0.5)
if N%i==0:
cand.append(i)
if i!=int(N/i):
cand.append(int(N/i))
cand.append(N)
#print(cand)
count=0
for i in range(len(cand)):
if check(N,cand[i]):
count+=1
print(count) | N=int(input())
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
return(divisors)
l1=make_divisors(N)
ans=len(make_divisors(N-1))-1
for i in l1:
m=N
while m%i==0 and m!=1 and m!=0 and i!=1:
m//=i
if m%i==1:
ans+=1
print(ans) | 1 | 41,498,567,616,740 | null | 183 | 183 |
n = int(input())
def isPrime(x):
if x < 2:
return false
if x == 2:
return True
return pow(2, x-1, x) == 1
s = []
for i in range(n):
s.append(int(input()))
prime = 0
for i in s:
if isPrime(i):
prime += 1
print(prime) | from math import sqrt
n = int(input())
p = 0
for i in range(n):
x = int(input())
ad = 1
j = 2
while j < (int(sqrt(x))+1):
if x%j == 0:
ad = 0
break
else:
j += 1
p += ad
print(p)
| 1 | 10,848,157,250 | null | 12 | 12 |
s=input()
stack=[]
tmpans=[]
ans=[]
for k,v in enumerate(s):
if v=="\\":
stack.append(k)
elif v=="/" and len(stack)>0:
p=stack.pop()
a=k-p
while len(tmpans)>0 and tmpans[-1][-1]>p:
a+=tmpans[-1][0]
tmpans.pop()
tmpans.append([a,p])
x=[i[0] for i in tmpans]
print(sum(x))
print(len(x),*x)
| # coding: utf-8
s = list(input().rstrip())
ht = []
ponds=[]
for i, ch in enumerate(s):
if ch == "\\":
ht.append(i)
elif ch == "/":
if ht:
b = ht.pop()
ap = i - b
if not ponds:
ponds.append([b, ap])
else:
while ponds:
p = ponds.pop()
if p[0] > b:
ap += p[1]
else:
ponds.append([p[0],p[1]])
break
ponds.append([b,ap])
else:
pass
ans = ""
area = 0
for point, ar in ponds:
area += ar
ans += " "
ans += str(ar)
print(area)
print(str(len(ponds)) + ans)
| 1 | 57,530,718,016 | null | 21 | 21 |
from math import pi
R = int(input())
ans = float(2 * pi * R)
print(ans) | print(int(input())*6.28) | 1 | 31,375,907,052,264 | null | 167 | 167 |
s = input()
S = s.swapcase()
print(S)
| string = input()
for s in string:
if s.isupper():
print(s.lower(), end='')
else:
print(s.upper(), end='')
print('') | 1 | 1,504,659,301,220 | null | 61 | 61 |
inf=10**9
n,m=map(int,input().split())
C=list(map(int,input().split()))
DP=[inf]*(n+1)
DP[0]=0
for i in range(n+1):
for c in C:
if 0<=i+c<=n:
DP[i+c]=min(DP[i+c],DP[i]+1)
print(DP[n])
| n = int(input())
a = list(map(int, input().split()))
MOD = 1000000007
dic = {}
dic[0] = 3
for i in range(1,n+1):
dic[i] = 0
ans = 1
for i in range(n):
ans = ans * dic[a[i]] % MOD
dic[a[i]] -= 1
dic[a[i] + 1] += 1
print(ans) | 0 | null | 64,907,556,761,080 | 28 | 268 |
import math
R=float(input())
print(2.0*R*math.pi) | def solve(n,A):
x=pow(2,n)
dp=[False]*2001
for i in range(x):
count=0
for j in range(n):
if (i>>j)&1:
count+=A[j]
if count<=2000:
dp[count]=True
return dp
n=int(input())
A=list(map(int,input().split()))
q=int(input())
m=list(map(int,input().split()))
ans=solve(n,A)
for i in range(q):
if ans[m[i]]:
print("yes")
else:
print("no")
| 0 | null | 15,771,330,094,310 | 167 | 25 |
import sys
import math
from functools import reduce
def num_of_zeros(num):
return (num ^ (num - 1)).bit_length() - 1
def lcm_base(x, y):
return (x * y) // math.gcd(x, y)
def lcm_list(numbers):
return reduce(lcm_base, numbers, 1)
def main():
input = sys.stdin.buffer.readline
n, m = map(int, input().split())
a = list(map(int, input().split()))
if len(set(map(num_of_zeros, a))) != 1:
print(0)
else:
lcm = lcm_list(list(map(lambda x: x // 2, a)))
ub = 10 ** 9
lb = 0
while ub - lb > 1:
mid = (ub + lb) // 2
if lcm * (2 * mid + 1) <= m:
lb = mid
else:
ub = mid
if lcm <= m:
lb += 1
print(lb)
if __name__ == "__main__":
main()
| def gcd(a, b):
while b:
a, b = b, a % b
return a
def div_ceil(x, y): return (x + y - 1) // y
N, M = map(int, input().split())
*A, = map(int, input().split())
A = list(set([a // 2 for a in A]))
L = A[0]
for a in A[1:]:
L *= a // gcd(L, a)
for a in A:
if (L // a) % 2 == 0:
ans = 0
break
else:
ans = div_ceil(M // L, 2)
print(ans) | 1 | 102,162,757,653,120 | null | 247 | 247 |
A,B,C = map(int, input().split())
print('{} {} {}'.format(C,A,B)) | X,Y,Z=map(int,input().split())
print(str(Z)+' '+str(X)+' '+str(Y)) | 1 | 38,113,573,148,592 | null | 178 | 178 |
from sys import exit
a, b, c, k = map(int, input().split())
total = 0
if a >= k:
print(k)
exit()
else:
total += a
k -= a
if b >= k:
print(total)
exit()
else:
k -= b
print(total - k) | import sys
readline = sys.stdin.buffer.readline
a,b,c,k =list(map(int,readline().rstrip().split()))
if k <= a:
print(k)
elif k > a and k <= a + b:
print(a)
else:
print(a -(k-(a+b)))
| 1 | 21,672,833,015,290 | null | 148 | 148 |
n = int(input())
m = int(n ** 0.5 + 1)
for i in range(m,0,-1):
if n % i == 0:
print((i - 1) + ((n // i) - 1))
exit() | # -*- coding:utf-8
def main():
N = int(input())
A = list(map(int, input().split()))
insertionSort(A, N)
print(' '.join(map(str, A)))
def insertionSort(A, N):
for i in range(1, N):
print(' '.join(map(str, A)))
v = A[i]
j = i-1
while(j>=0 and A[j]>v):
A[j+1] = A[j]
j -= 1
A[j+1] = v
if __name__ == '__main__':
main() | 0 | null | 80,540,176,509,210 | 288 | 10 |
class Solution:
def solve(self, N: int, P: int, S: str):
if P == 2 or P == 5:
answer = 0
for idx, s in enumerate(S):
if int(s) % P == 0:
answer += idx + 1
else:
answer = 0
U = [0] * P # int(S[i,N] mod P
U[0] += 1
num = 0
base10_mod_p = 1
for i in range(N):
num = (num + int(S[N-i-1]) * base10_mod_p) % P
base10_mod_p = (base10_mod_p * 10) % P
U[num] += 1
for u in U:
answer += u * (u-1) // 2
return answer
if __name__ == '__main__':
# standard input
N, P = map(int, input().split())
S = input()
# solve
solution = Solution()
answer = solution.solve(N, P, S)
print(answer)
| N, P = map(int, input().split())
S = input()
if P in [2, 5]:
ans = 0
for i, s in enumerate(S, 1):
if int(s) % P == 0:
ans += i
print(ans)
else:
dp = [0] * (N+1)
for i, s in enumerate(S, 1):
dp[i] = (dp[i-1]*10 + int(s)) % P
digit = 1
for i in range(N):
j = N - i
dp[j] = (dp[j] * digit) % P
digit = (digit * 10) % P
d = {}
ans = 0
for r in dp:
if r in d:
ans += d[r]
d[r] += 1
else:
d[r] = 1
print(ans) | 1 | 58,285,530,426,184 | null | 205 | 205 |
import sys
input = sys.stdin.readline
N, M = map(int, input().split())
edges = {}
for _ in range(M):
a, b = map(int, input().split())
a -= 1
b -= 1
if a not in edges:
edges[a] = set()
if b not in edges:
edges[b] = set()
edges[a].add(b)
edges[b].add(a)
to_check = set(range(N))
max_size = 0
while to_check:
checked = set()
s = set()
s.add(next(iter(to_check)))
#print(s)
while s:
current = s.pop()
checked.add(current)
if current in edges:
for n in edges[current]:
if n not in checked:
s.add(n)
max_size = max(max_size, len(checked))
#print(checked)
for c in checked:
to_check.remove(c)
print(max_size)
| for a,b,c in[sorted(map(int,raw_input().split()))for i in range(input())]:
print"NO"if c*c-a*a-b*b else"YES" | 0 | null | 1,994,332,995,760 | 84 | 4 |
A,B = map(int,input().split())
ans=int(A-B*2)
print(ans if ans >= 0 else 0) | import sys
import numpy as np
mod=10**9+7
n=int(sys.stdin.buffer.readline())
a=np.fromstring(sys.stdin.buffer.readline(),dtype=np.int64,sep=' ')
ans=0
b=1
for i in range(60):
s=int((a&1).sum())
ans=(ans+s*(n-s)*b)%mod
a>>=1
b=b*2%mod
print(ans) | 0 | null | 144,824,286,491,350 | 291 | 263 |
while 1:
m,f,r=map(int, raw_input().split())
if m==f==r==-1: break
s=m+f
if m==-1 or f==-1 or s<30: R="F"
elif s>=80: R="A"
elif s>=65: R="B"
elif s>=50: R="C"
elif r>=50: R="C"
else: R="D"
print R |
while True:
m,f,r = map(int, raw_input().split())
s = m + f
if m == -1 and f == -1 and r == -1: break
elif m == -1 or f == -1 or s < 30: g=5
elif 30 <= s and s < 50:
if r >= 50: g=2
else: g=3
elif 50 <= s and s < 65: g=2
elif 65 <= s and s < 80: g=1
else: g=0
print 'ABCDEF'[g]
| 1 | 1,255,545,028,250 | null | 57 | 57 |
s=str("ACL")
n=int(input())
print(s*n) | import sys
sys.setrecursionlimit(1000000000)
import math
from math import gcd
def lcm(a, b): return a * b // gcd(a, b)
from itertools import count, permutations, chain
from functools import lru_cache
from collections import deque, defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7
def meg(f, ok, ng):
while abs(ok-ng)>1:
mid = (ok+ng)//2
if f(mid):
ok=mid
else:
ng=mid
return ok
def get_inv(n, modp):
return pow(n, modp-2, modp)
def factorials_list(n, modp): # 10**6
fs = [1]
for i in range(1, n+1):
fs.append(fs[-1] * i % modp)
return fs
def invs_list(n, fs, modp): # 10**6
invs = [get_inv(fs[-1], modp)]
for i in range(n, 1-1, -1):
invs.append(invs[-1] * i % modp)
invs.reverse()
return invs
def comb(n, k, modp):
num = 1
for i in range(n, n-k, -1):
num = num * i % modp
den = 1
for i in range(2, k+1):
den = den * i % modp
return num * get_inv(den, modp) % modp
def comb_from_list(n, k, modp, fs, invs):
return fs[n] * invs[n-k] * invs[k] % modp
#
class UnionFindEx:
def __init__(self, size):
#正なら根の番号、負ならグループサイズ
self.roots = [-1] * size
def getRootID(self, i):
r = self.roots[i]
if r < 0: #負なら根
return i
else:
r = self.getRootID(r)
self.roots[i] = r
return r
def getGroupSize(self, i):
return -self.roots[self.getRootID(i)]
def connect(self, i, j):
r1, r2 = self.getRootID(i), self.getRootID(j)
if r1 == r2:
return False
if self.getGroupSize(r1) < self.getGroupSize(r2):
r1, r2 = r2, r1
self.roots[r1] += self.roots[r2] #サイズ更新
self.roots[r2] = r1
return True
Yes = 'Yes'
No = 'No'
def main():
N=ii()
up = []
down = []
for _ in range(N):
S = input()
h = 0
b = 0
for s in S:
if s=='(':
h += 1
else:
h -= 1
b = min(b, h)
#
if h>=0:
up.append((h, b))
else:
down.append((h, b))
#
up.sort(key=lambda t: t[1], reverse=True)
down.sort(key=lambda t: t[0]-t[1], reverse=True)
H = 0
for h, b in up:
if H+b>=0:
H += h
else:
print(No)
return
for h, b in down:
if H+b>=0:
H += h
else:
print(No)
return
#
if H == 0:
print(Yes)
else:
print(No)
main()
| 0 | null | 12,866,637,491,640 | 69 | 152 |
if __name__ == '__main__':
from statistics import pstdev
while True:
# ??????????????\???
data_count = int(input())
if data_count == 0:
break
scores = [int(x) for x in input().split(' ')]
# ?¨??????????????¨????
result = pstdev(scores)
# ???????????????
print('{0:.8f}'.format(result)) | from statistics import pstdev
while True:
data_count = int(input())
if data_count == 0:
break
print(pstdev(int(x) for x in input().split()))
| 1 | 192,774,500,170 | null | 31 | 31 |
from collections import *
n, p = map(int, input().split())
s = list(map(int, input()))
if 10%p==0:
r = 0
for i in range(n):
if s[i]%p==0:
r += i+1
print(r)
exit()
c = Counter()
c[0] += 1
v = r = 0
k = 1
for i in s[::-1]:
v += int(i)*k
v %= p
r += c[v]
c[v] += 1
k *= 10
k %= p
print(r)
| n, p = map(int, input().split())
s = input()
r = set()
last = 0
d = {0: 0}
total = 0
rem = 0
if p == 2:
for i in range(0, len(s)):
if int(s[i]) % 2 == 0:
total += i + 1
print(total)
elif p == 5:
for i in range(0, len(s)):
if int(s[i]) % 5 == 0:
total += i + 1
print(total)
else:
power = 1
for i in range(len(s) - 1, -1, -1): # handling of 0's as n and rem
n = int(s[i]) * power + rem
power *= 10
power = power % p
rem = n % p
if rem in d.keys():
d[rem] += 1
else:
d[rem] = 1
total += d[rem] - 1
print(total + d[0])
| 1 | 57,948,127,449,780 | null | 205 | 205 |
def main():
from collections import deque
N, M = (int(i) for i in input().split())
if N % 2 == 0:
A = deque([i+1 for i in range(N)])
for i in range(1, M+1):
if (N-i)-i > N//2:
print(A[i], A[N-i])
else:
print(A[i], A[N-i-1])
else:
A = deque([i for i in range(N)])
for i in range(1, M+1):
print(A[i], A[N-i])
if __name__ == '__main__':
main()
| print(*sorted(input().split())) | 0 | null | 14,433,825,007,290 | 162 | 40 |
x, k, d = map(int,input().split())
x = abs(x)
if x>k*d:
ans = x-k*d
else:
cnt = x//d#xに最も近づくための移動回数
if (k-cnt)%2==0:
ans = x-cnt*d
else:
if x>0:
ans = abs(x-cnt*d-d)
else:
ans = abs(x-cnt*d+d)
print(ans) | from collections import defaultdict
mod = 10**9 + 7
n, k = map(int, input().split())
l = defaultdict(int)
for i in reversed(range(1, k+1)):
l[i] = pow(k//i, n, mod)
a = 2
while a*i<=k:
l[i] -= l[a*i]
l[i] %= mod
a += 1
ans = 0
for j in l:
ans += j*l[j] % mod
ans %= mod
print(ans) | 0 | null | 20,990,407,931,662 | 92 | 176 |
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import sys
INF = float('inf')
YES = "Yes" # type: str
NO = "No" # type: str
def solve(H: int, N: int, A: "List[int]"):
return [NO, YES][sum(A) >= H]
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
H = int(next(tokens)) # type: int
N = int(next(tokens)) # type: int
A = [int(next(tokens)) for _ in range(N)] # type: "List[int]"
print(f'{solve(H, N, A)}')
if __name__ == '__main__':
main()
| h, w = map(int, input().split())
hd, hm, wd, wm = h // 2, h % 2, w // 2, w % 2
s = hd * wd * 2 + hm * wd + wm * hd + hm * wm
if h == 1 or w == 1:
s = 1
print(s)
| 0 | null | 64,336,867,374,560 | 226 | 196 |
a,b,c=map(int,input().split())
K=int(input())
isCheck = None
for i in range(K+1):
for j in range(K+1):
for k in range(K+1):
x = a*2**(i)
y = b*2**(j)
z = c*2**(k)
if i+j+k <= K and x < y and y < z:
isCheck = True
if isCheck:
print("Yes")
else:
print("No")
| a,b,c=map(int,input().split())
K=int(input())
# B > A
# C > B
import sys
for i in range(K+1):
A=a
B=b*(2**i)
C=c*(2**(K-i))
#print(i,K-i,A,B,C)
if B>A and C>B:
print('Yes')
sys.exit()
else:
print('No') | 1 | 6,980,741,186,650 | null | 101 | 101 |
from bisect import bisect_right
n, d, a = map(int, input().split())
xh = sorted(list(map(int, input().split())) for _ in range(n))
x = [0] * (n + 1)
h = [0] * (n + 1)
s = [0] * (n + 1)
for i, (f, g) in enumerate(xh):
x[i], h[i] = f, g
x[n] = 10 ** 10 + 1
ans = 0
for i in range(n):
if i > 0:
s[i] += s[i - 1]
h[i] -= s[i]
if h[i] > 0:
num = 0 - - h[i] // a
ans += num
s[i] += num * a
j = bisect_right(x, x[i] + d * 2)
s[j] -= num * a
print(ans)
| import sys
def input():
return sys.stdin.readline().strip()
n, d, a = map(int, input().split())
x = []
h = {} # x:h
for _ in range(n):
i, j = map(int, input().split())
x.append(i)
h[i] = j
x.sort()
x.append(x[-1] + 2*d + 1)
# attackで累積和を用いる
ans = 0
attack = [0 for _ in range(n+1)]
for i in range(n):
attack[i] += attack[i-1]
if attack[i] >= h[x[i]]:
continue
if (h[x[i]] - attack[i]) % a == 0:
j = (h[x[i]] - attack[i]) // a
else:
j = (h[x[i]] - attack[i]) // a + 1
attack[i] += a * j
ans += j
# 二分探索で、x[y] > x[i] + 2*d、を満たす最小のyを求める
# start <= y <= stop
start = i + 1
stop = n
k = stop - start + 1
while k > 1:
if x[start + k//2 - 1] <= x[i] + 2*d:
start += k//2
else:
stop = start + k//2 - 1
k = stop - start + 1
attack[start] -= a * j
print(ans) | 1 | 82,181,794,470,510 | null | 230 | 230 |
class Building(object):
def __init__(self):
self.floor = []
self.floor.extend([[0] * 10])
self.floor.extend([[0] * 10])
self.floor.extend([[0] * 10])
def change_resident(self, f, r, v):
self.floor[f][r] += v
def print_status(self):
for f in self.floor:
print(' {0}'.format(' '.join(map(str, f))))
if __name__ == '__main__':
# ?????????4?£??????????
buildings = []
for i in range(4):
buildings.append(Building())
# ??????????????\???
data_num = int(input())
data = []
for i in range(data_num):
data.append([int(x) for x in input().split(' ')])
# ??\?±?????????´??°
for d in data:
b = d[0]
f = d[1]
r = d[2]
v = d[3]
buildings[b-1].change_resident(f-1, r-1, v)
# ?????????????????¨???
buildings[0].print_status()
print('#' * 20)
buildings[1].print_status()
print('#' * 20)
buildings[2].print_status()
print('#' * 20)
buildings[3].print_status() | h = [[[0]*10 for i in range(3)] for j in range(4)]
n = int(input())
for i in range(n):
b,f,r,v = map(int,input().split())
h[b-1][f-1][r-1] += v
s = ""
for i in range(4):
for j in range(3):
for k in range(10):
s += " " + str(h[i][j][k])
s += "\n"
if i < 3:
s += "####################\n"
print(s,end="") | 1 | 1,102,943,886,400 | null | 55 | 55 |
import itertools
import numpy as np
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for i in range(Q)]
score = []
ans = 0
for A in itertools.combinations_with_replacement(range(1, M+1), N):
for i in range(Q):
a = abcd[i][0]
b = abcd[i][1]
c = abcd[i][2]
d = abcd[i][3]
if A[b-1]-A[a-1] == c:
score.append(d)
if ans <= sum(score):
ans = sum(score)
score.clear()
print(ans) | from collections import defaultdict
N=int(input())
*A,=map(int,input().split())
mod = 10**9+7
count = defaultdict(int)
count[0] = 3
ans = 1
for i in range(N):
ans *= count[A[i]]
ans %= mod
count[A[i]] -= 1
count[A[i]+1] += 1
print(ans) | 0 | null | 78,738,008,532,288 | 160 | 268 |
n = int(input())
adjMat = [[-1]*n for i in range(n)]
for i in range(n):
a = int(input())
for j in range(a):
x, y = map(int, input().split())
adjMat[i][x-1] = y
ans = 0
for i in range(1 << (n)):
#print (bin(i))
success = True
for j in range(n):
if i & 2**j:
for k in range(n):
if k == j:
continue
if i & 2**k == 0 and adjMat[j][k] == 1:
success = False
if i & 2**k > 0 and adjMat[k][j] == 0:
success = False
#print (j, k, adjMat[j][k], adjMat[k][j], success)
if not success:
break
if success:
i2 = i
c = 0
while i2 > 0:
c += i2 & 1
i2 //= 2
ans = max(c, ans)
print (ans) | n, q = map(int, raw_input().split())
A = [[0, 0] for i in range(n)]
for i in range(n):
temp = raw_input().split()
A[i][0] = temp[0]
A[i][1] = int(temp[1])
time = 0
while A != []:
if A[0][1] - q > 0:
A[0][1] = A[0][1] - q
time = time + q
A.append(A.pop(0))
else:
print A[0][0],
print time + A[0][1]
time = time + A[0][1]
A.pop(0) | 0 | null | 60,447,918,284,582 | 262 | 19 |
write = open(1, 'w').write
for i in range(1, int(open(0).read())+1):
if i % 3:
if "3" in str(i):
write(" %d" % i)
else:
write(" %d" % i)
write("\n")
| s = set()
for _ in range(int(input())):
cmd, v = input().split()
if cmd == 'insert':
s.add(v)
else:
print('yes' if v in s else 'no')
| 0 | null | 494,829,977,120 | 52 | 23 |
n,s=map(int,input().split())
a=list(map(int,input().split()))
mod=998244353
dp=[[0 for i in range(s+1)] for j in range(n+1)]
dp[0][0]=1
for i in range(1,n+1):
see=a[i-1]
for j in range(s+1):
dp[i][j]=dp[i-1][j]*2
dp[i][j]%=mod
if see>j:
continue
dp[i][j]+=dp[i-1][j-see]
dp[i][j]%=mod
print(dp[-1][-1])
| import numpy as np
N, S = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
mod = 998244353
coef = np.zeros(3001, dtype=int)
coef[0] = 1
for a in A:
coef2 = coef[:-a].copy()
coef *= 2
coef[a:] += coef2
coef %= mod
print(coef[S])
| 1 | 17,576,740,590,550 | null | 138 | 138 |
def main():
import sys
input = sys.stdin.readline
# comb init
mod = 1000000007
nmax = 4 * 10 ** 5 + 10 # change here
fac = [0] * nmax
finv = [0] * nmax
inv = [0] * nmax
fac[0] = 1
fac[1] = 1
finv[0] = 1
finv[1] = 1
inv[1] = 1
for i in range(2, nmax):
fac[i] = fac[i - 1] * i % mod
inv[i] = mod - inv[mod % i] * (mod // i) % mod
finv[i] = finv[i - 1] * inv[i] % mod
def comb(n, r):
if n < r:
return 0
else:
return (fac[n] * ((finv[r] * finv[n - r]) % mod)) % mod
N, K = map(int, input().split())
ans = 0
for m in range(min(K+1, N)):
ans = (ans + (comb(N, m) * comb(N-1, m))%mod)%mod
print(ans)
if __name__ == '__main__':
main()
| import math
import sys
import bisect
import array
m=10**9 + 7
sys.setrecursionlimit(1000010)
(N,K) = map(int,input().split())
A = list( map(int,input().split()))
# print(N,K,A)
B = list( map(lambda x: x % K, A))
C = [0]
x = 0
i = 0
for b in B:
x = (x + b ) % K
C.append((x-i-1) % K)
i += 1
# print(B,C)
E={}
ans=0
for i in range(N+1):
if C[i] in E:
ans += E[C[i]]
E[C[i]] = E[C[i]] + 1
else:
E[C[i]] = 1
if i >= K-1:
E[C[i-K+1]] = E[C[i-K+1]] - 1
if E[C[i-K+1]] == 0:
E.pop(C[i-K+1])
print(ans)
exit(0) | 0 | null | 102,204,189,038,210 | 215 | 273 |
#!/usr/bin/env python3
import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
n,k = LI()
a = LI()
for i in range(k, n):
if a[i] > a[i-k]:
print('Yes')
else:
print('No')
| import sys
def input(): return sys.stdin.readline().rstrip()
def main():
s = input()
if s[-1] != 's':
print(s+'s')
else:
print(s+'es')
if __name__=='__main__':
main() | 0 | null | 4,755,376,542,928 | 102 | 71 |
# -*- coding: utf-8 -*-
def main():
import sys
input = sys.stdin.readline
d, t, s = map(int, input().split())
if s * t >= d:
print('Yes')
else:
print('No')
if __name__ == '__main__':
main()
| n = int(input())
mod = 10**9+7
ans = 10**n-9**n-9**n+8**n
ans %= mod
print(ans)
| 0 | null | 3,353,517,993,772 | 81 | 78 |
md1=list(map(int,input().split()))
md2=list(map(int,input().split()))
if md1[0]==md2[0]:
print(0)
else:
print(1) | #! python3
# triangle.py
import math
a, b, C = [int(x) for x in input().split(' ')]
S = a * b * math.sin(math.radians(C)) / 2.0
L = a + b + math.sqrt(pow(a, 2) + pow(b, 2) - 2 * a * b * math.cos(math.radians(C)))
h = b * math.sin(math.radians(C))
print('%.5f'%S)
print('%.5f'%L)
print('%.5f'%h)
| 0 | null | 62,491,107,573,368 | 264 | 30 |
x = list(map(int, input().split()))
for i in range(len(x)):
if x[i] is 0:
print(i+1)
| import math
n, x, t = [int(x) for x in input().split()]
print(math.ceil(n/x)*t) | 0 | null | 8,856,771,961,752 | 126 | 86 |
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
b2=[]
b2.append(0)
for i in range(1,m+1):
b2.append(b2[i-1]+b[i-1])
a.insert(0,0)
cnt=0
a_sum=0
for i in range(n+1):
j=m
a_sum+=a[i]
while True:
if k>=a_sum+b2[j]:
cnt=max(cnt,i+j)
m=j
break
j-=1
if j <0:
break
print(cnt) | while True:
a = map(int, raw_input().split(" "))
if len([x for x in a if x <> 0]) <= 0:
break
else:
a.sort()
print " ".join(map(str, a)) | 0 | null | 5,635,459,388,764 | 117 | 43 |
a,b = list(map(int, input().split()))
c,d = list(map(int, input().split()))
if (a != c):
print(1)
else:
print(0) | N, T = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
Dp = [0 for _ in range(T+1)]
ab = sorted(ab, key = lambda x: x[0])
for i in range(N):
for j in range(T-1,-1, -1):
if j+ab[i][0] <= T-1:
kari2 = Dp[j] + ab[i][1]
if Dp[j+ab[i][0]] < kari2:
Dp[j+ab[i][0]] = kari2
else:
kari2 = Dp[j] +ab[i][1]
if Dp[T] < kari2:
Dp[T] = kari2
print(max(Dp)) | 0 | null | 138,127,606,362,078 | 264 | 282 |
L,R,d = map(int,input().split())
A = 0
for _ in range(L,R+1):
if _ %d == 0:
A += 1
print(A) | N, M ,L = map(int, input().split())
print(M//L-(N-1)//L) | 1 | 7,481,757,722,208 | null | 104 | 104 |
import numpy as np
from numba import njit, i8
@njit(i8(i8, i8[:], i8[:]), cache=True)
def solve(H, A, B):
A_max = A.max()
dp = np.zeros(H + A_max + 1, dtype=np.int64)
for i in range(A_max + 1, H + A_max + 1):
dp[i] = np.min(dp[i - A] + B)
return dp[-1]
H, N, *AB = map(int, open(0).read().split())
A = np.array(AB[::2], dtype=np.int64)
B = np.array(AB[1::2], dtype=np.int64)
print(solve(H, A, B))
| h,n=map(int, input().split())
a=[0]*n
b=[0]*n
for i in range(n):
a[i],b[i]=map(int,input().split())
max_a=max(a)
dp=[float("inf")]*(h+max_a+1)
dp[0]=0
for i in range(h):
for j in range(n):
dp[i+a[j]] = min(dp[i+a[j]], dp[i]+b[j])
print(min(dp[h:])) | 1 | 81,532,395,546,752 | null | 229 | 229 |
# AOJ ALDS1_4_C Dictionary
# Python3 2018.7.3 bal4u
import sys
from sys import stdin
input = stdin.readline
dic = {}
n = int(input())
for i in range(n):
s = input()
if s[0] == 'i': dic[s[7:]] = 1
else: print("yes" if s[5:] in dic else "no")
| command_num = int(input())
dict = set([])
for i in range(command_num):
in_command, in_str = input().rstrip().split(" ")
if in_command == "insert":
dict.add(in_str)
elif in_command == "find":
if in_str in dict:
print("yes")
else:
print("no") | 1 | 73,454,576,352 | null | 23 | 23 |
import sys
readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
A = list(map(int, readline().split()))
if sum(A) >= 22:
print("bust")
else:
print("win")
if __name__ == '__main__':
main()
| a = list(map(int, input().split()))
print('bust' if sum(a) >= 22 else 'win') | 1 | 118,665,550,783,182 | null | 260 | 260 |
import sys
N = int(input())
S = [str(s) for s in sys.stdin.read().split()]
print(len(set(S))) | W, H, x, y, r = map(int, input().split())
flg = False
for X in [x - r, x + r]:
for Y in [y - r, y + r]:
if not 0 <= X <= W or not 0 <= Y <= H:
flg = True
print(["Yes", "No"][flg])
| 0 | null | 15,250,271,316,070 | 165 | 41 |
print('NYoe s'['7'in [*input()]::2]) | n=input()
r='No'
for i in range(len(n)):
if n[i]=='7': r='Yes'
print(r)
| 1 | 34,497,089,326,050 | null | 172 | 172 |
MOD = 10**9+7
n = int(input())
A = list(map(int, input().split()))
colors = [0]*3
dp = [0]*n
for i in range(n):
c = colors.count(A[i])
dp[i] = c
if c == 0:
break
colors[colors.index(A[i])] += 1
ans = 1
for x in dp:
ans = ans*x % MOD
print(ans % MOD)
| def main():
n,k = map(int,input().split())
a = list(map(int,input().split()))
ans = []
for i in range(k,n):
ans.append("Yes" if a[i] > a[i-k] else "No")
print("\n".join(ans))
if __name__ == '__main__':
main() | 0 | null | 68,827,006,150,512 | 268 | 102 |
N=int(input())
count=0
for A in range(1,N):
count+=(N-1)//A
print(count) | s = input()
n = len(s)
ans = 0
if (n%2 == 0):
nh = int(n/2)
for i in range(nh):
if (s[i] != s[n - i - 1]):
ans = ans + 1
else:
nh = int((n - 1)/2)
for i in range(nh):
if (s[i] != s[n - i - 1]):
ans = ans + 1
print(ans) | 0 | null | 61,246,243,754,152 | 73 | 261 |
import sys
input = sys.stdin.readline
def main():
s = input().strip()
mod = [0] * 2019
tmp = 0
ten = 10
mod[tmp] += 1
for i in range(len(s)-1, -1, -1):
tmp = (tmp + ten * int(s[i])) % 2019
ten = (ten * 10) % 2019
mod[tmp] += 1
ans = 0
for i in range(2019):
if mod[i] > 1:
ans += (mod[i] * (mod[i] - 1)) // 2
print(ans)
if __name__ == "__main__":
main() | import math
n = int(input())
print(math.floor(n / 2) - (1-n%2)) | 0 | null | 92,243,354,863,008 | 166 | 283 |
n = int(input())
d = {}
for i in range(n):
[b, f, r, v] = list(map(int,input().split()))
key = f'{b} {f} {r}'
if key in d:
d[key] += v
else:
d[key] = v
for b in range(1,5):
for f in range(1,4):
for r in range(1,11):
key = f'{b} {f} {r}'
if key in d:
print(" "+str(d[key]),end="")
else:
print(" "+str(0),end="")
if r == 10:
print()
if r == 10 and f == 3 and b != 4:
print('####################')
| import sys
k1 = [[0 for i in xrange(10)] for j in xrange(3)]
k2 = [[0 for i in xrange(10)] for j in xrange(3)]
k3 = [[0 for i in xrange(10)] for j in xrange(3)]
k4 = [[0 for i in xrange(10)] for j in xrange(3)]
n = input()
for i in xrange(n):
m = map(int,raw_input().split())
if m[0] == 1:
k1[m[1]-1][m[2]-1] = k1[m[1]-1][m[2]-1] + m[3]
elif m[0] == 2:
k2[m[1]-1][m[2]-1] = k2[m[1]-1][m[2]-1] + m[3]
elif m[0] == 3:
k3[m[1]-1][m[2]-1] = k3[m[1]-1][m[2]-1] + m[3]
elif m[0] == 4:
k4[m[1]-1][m[2]-1] = k4[m[1]-1][m[2]-1] + m[3]
for i in xrange(3):
for j in xrange(10):
x = ' ' + str(k1[i][j])
sys.stdout.write(x)
if j == 9:
print ""
print"#"*20
for i in xrange(3):
for j in xrange(10):
y = ' ' + str(k2[i][j])
sys.stdout.write(y)
if j == 9:
print ""
print"#"*20
for i in xrange(3):
for j in xrange(10):
z = ' ' + str(k3[i][j])
sys.stdout.write(z)
if j == 9:
print ""
print"#"*20
for i in xrange(3):
for j in xrange(10):
zz = ' ' + str(k4[i][j])
sys.stdout.write(zz)
if j == 9:
print "" | 1 | 1,099,514,052,608 | null | 55 | 55 |
a,b,c = [int(i) for i in input().split()]
res = 0
for num in range(a,b+1):
if c%num == 0:
res += 1
print(res) | n = input().split()
a = int(n[0])
b = int(n[1])
c = int(n[2])
counta = 0
if a == b:
if c % a == 0:
counta += 1
else:
for i in range(a,b+1):
if c % i == 0:
counta += 1
print(counta) | 1 | 565,251,802,500 | null | 44 | 44 |
n,k,c = list(map(int, input().split()))
s = list(input())
l = []
r = []
i = 0
while i < n and len(l) <= k:
if s[i] == "o":
l.append(i)
i += (c + 1)
else:
i += 1
i = n-1
while i >= 0 and len(r) <= k:
if s[i] == "o":
r.append(i)
i -= (c+1)
else:
i -= 1
i = 0
while i < k:
if l[i] == r[k-1-i]:
print(l[i]+1)
i += 1
| s,w = map(int, input().split())
ans = "NG"
# for i in range(a,b+1):
# print(i)
if s<=w:
print("unsafe")
else:
print("safe") | 0 | null | 34,882,187,691,802 | 182 | 163 |
H = int(input())
def battle(h):
if h == 1:
return 1
else:
return 2*battle(h//2)+1
print(battle(H))
| N = int(input())
a = [int(i) for i in input().split()]
frag = 1
i = 0
count = 0
while frag:
frag = 0
for j in range(N-1,i,-1):
if a[j] < a[j-1]:
a[j], a[j-1] = a[j-1], a[j]
count += 1
frag = 1
i += 1
print(" ".join(map(str, a)))
print(count) | 0 | null | 39,788,748,487,642 | 228 | 14 |
n = int(input())
k = 1000000007
if n == 1:
print(0)
else:
print(((10**n)%k - (2* 9**n)%k+(8**n)%k)%k) | n=int(input())
x=(pow(10,n)-2*pow(9,n)+pow(8,n))%1000000007
print(x) | 1 | 3,161,655,322,980 | null | 78 | 78 |
x, k, d = map(int, input().split())
x = abs(x)
num = x // d
if num >= k:
ans = x - k*d
else:
if (k-num)%2 == 0:
ans = x - num*d
else:
ans = min(abs(x - num*d - d), abs(x - num*d + d))
print(ans) | a = []
for i in range(10000):
a.append(int(input()))
if a[i] == 0:
break
print("Case {}: {}".format(i+1,a[i]))
| 0 | null | 2,822,409,984,812 | 92 | 42 |
N,D = map(int,input().split())
xy = []
for i in range(N):
x,y = map(int,input().split())
xy.append([x,y])
ans = 0
for i in range(N):
x = xy[i][0]
y = xy[i][1]
if(D*D >= (x*x + y*y)):
ans+=1
print(ans) | k, x = list(map(int, input().split()))
a = k * 500
if a >= x:
print("Yes")
else:
print("No")
| 0 | null | 52,330,485,795,780 | 96 | 244 |
import math
import itertools
# 与えられた数値の桁数と桁値の総和を計算する.
def calc_digit_sum(num):
digits = sums = 0
while num > 0:
digits += 1
sums += num % 10
num //= 10
return digits, sums
n = int(input())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
pidx, qidx = 0, 0
candidates = list(itertools.permutations(range(1, n+1), n))
for index, candidate in enumerate(candidates):
candidate = list(candidate)
if candidate == p:
pidx = index
if candidate == q:
qidx = index
print(abs(pidx - qidx))
| n = int(input())
p = str(tuple(map(int, input().split())))
q = str(tuple(map(int, input().split())))
import itertools
n_l = [ i+1 for i in range(n) ]
d = {}
for i, v in enumerate(itertools.permutations(n_l)):
d[str(v)] = i
print(abs(d[p]-d[q])) | 1 | 100,883,846,986,298 | null | 246 | 246 |
n = int(input())
st, sh = 0, 0
for i in range(n):
t, h = map(str, input().split())
if t > h:
st += 3
elif t < h:
sh += 3
else:
st += 1
sh += 1
print(st, sh) | n = int(input())
p1 = p2 = 0
for _ in range(n):
taro,hanako = map(str,input().split(" "))
if taro>hanako: p1 += 3
elif taro<hanako: p2 += 3
else:
p1 += 1
p2 += 1
print(p1,p2)
| 1 | 1,996,757,618,958 | null | 67 | 67 |
T = input()
print(T.replace('?', 'D'))
| t=input()
tla=list(t)
tlb=list(t)
pd1=0
pd2=0
for i in range(len(tla)):
if tla[i]=="?":
if i==0:
pass
elif i==len(tla)-1:
tla[i]="D"
elif tla[i-1]=="P":
tla[i]="D"
elif tla[i+1]=="D":
tla[i]="P"
elif tla[i+1]=="?":
tla[i]="P"
else:
tla[i]="D"
if tla[i]=="D":
if i==0:
pass
elif tla[i-1]=="P":
pd1+=1
d1=tla.count('D')
s1=d1+pd1
for i in range(len(tlb)):
if tlb[i]=="?":
tlb[i]="D"
if tlb[i]=="D":
if i==0:
pass
elif tlb[i-1]=="P":
pd2+=1
d2=tlb.count('D')
s2=d2+pd2
if s1>s2:
print(''.join(tla))
else:
print(''.join(tlb)) | 1 | 18,428,245,398,170 | null | 140 | 140 |
def az15():
n = input()
xs = map(int,raw_input().split())
xs.reverse()
for i in range(0,len(xs)):
print xs[i],
az15() | n = int(input())
a = list(map(int, input().split(" ")))
for lil_a in a[-1:0:-1]:
print("%d "%lil_a, end="")
print("%d"%a[0]) | 1 | 993,232,877,732 | null | 53 | 53 |
def solve():
a,b = map(int,input().split())
print(len(str(a+b)))
while True:
try:
solve()
except:
break | results=[]
from sys import stdin
for line in stdin:
a, b = (int(i) for i in line.split())
results.append(len(str(a+b)))
for i in results:
print i | 1 | 98,036,862 | null | 3 | 3 |
W, H, x, y, r = map(int, input().split())
print( 'Yes' if r <= x <= W - r and r <= y <= H - r else 'No') | from collections import Counter
n = int(input())
a = list(map(int, input().split()))
a += list(range(1,n+1))
a = Counter(a).most_common()
a.sort()
for i,j in a:
print(j-1) | 0 | null | 16,543,511,158,592 | 41 | 169 |
from collections import Counter
def mpow(a,b,mod):
ret=1
while b>0:
if b&1:
ret=(ret*a)%mod
a=(a*a)%mod
b>>=1
return ret
n,p=map(int,input().split())
s=[int(i) for i in input()]
if p==2 or p==5:
ans=0
for i in range(n):
if s[i]%p==0:
ans+=i+1
print(ans)
else:
ans=0
d=Counter()
d[0]+=1
num=0
for i in range(n-1,-1,-1):
num=(num+s[i]*mpow(10,n-1-i,p))%p
ans+=d[num]
d[num]+=1
print(ans)
| from collections import Counter
n, p = map(int, input().split())
s = list(map(int, list(input())))
ans = 0
if p in {2, 5}:
for i, num in enumerate(s):
if num % p == 0:
ans += i + 1
else:
bfo, cnt = 0, [1] + [0] * (p - 1)
for i, num in enumerate(s[::-1]):
bfo = (bfo + pow(10, i, p) * num) % p
ans += cnt[bfo]
cnt[bfo] += 1
print(ans)
| 1 | 58,228,723,587,648 | null | 205 | 205 |
n, d = map(int, input().split())
xy = [map(int, input().split()) for _ in range(n)]
x, y = [list(i) for i in zip(*xy)]
ans = 0
d = d ** 2
for i in range(n):
if ( x[i] ** 2 + y[i] ** 2 ) <= d:
ans += 1
print(ans) | #!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools as fts
import itertools as its
import math
import sys
INF = float('inf')
def solve(N: int, D: int, X: "List[int]", Y: "List[int]"):
return sum(D*D >= (p*p + q*q) for p, q in zip(X, Y))
def main():
sys.setrecursionlimit(10 ** 6)
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
N = int(next(tokens)) # type: int
D = int(next(tokens)) # type: int
X = [int()] * (N) # type: "List[int]"
Y = [int()] * (N) # type: "List[int]"
for i in range(N):
X[i] = int(next(tokens))
Y[i] = int(next(tokens))
print(f'{solve(N, D, X, Y)}')
if __name__ == '__main__':
main()
| 1 | 5,912,447,537,568 | null | 96 | 96 |
m1, _ = list(map(int, input().split()))
m2, _ = list(map(int, input().split()))
if m1 == m2:
print(0)
else:
print(1) | M,D=map(int, input().split())
MM,DD=map(int, input().split())
if MM-1==M or (MM-1==0 and M==12):
print(1)
else:
print(0) | 1 | 124,240,796,916,210 | null | 264 | 264 |
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop
import copy
import numpy as np
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)
def lcm(a, b): return a * b / gcd(a, b)
# 1 2 3
# a, b, c = LI()
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# a = I()
def I(): return int(sys.stdin.buffer.readline())
# abc def
# a, b = LS()
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# a = S()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# 2
# 1
# 2
# [1, 2]
def IR(n): return [I() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]
def LIR(n): return [LI() for i in range(n)]
# 2
# abc
# def
# [abc, def]
def SR(n): return [S() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]
def LSR(n): return [LS() for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]
def SRL(n): return [list(S()) for i in range(n)]
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
fact = [1, 1] # n! mod p
factinv = [1, 1] # (n!)^(-1) mod p
tmp = [0, 1] # factinv 計算用
def main():
x, y = LI()
ans = 0
if x > 2 * y or x < 0.5 * y or (x + y) % 3 != 0:
print(0)
return
n, m = map(int, [(2 * y - x) / 3, (2 * x - y) / 3])
for i in range(2, n + m + 1):
fact.append((fact[-1] * i) % mod)
tmp.append((-tmp[mod % i] * (mod // i)) % mod)
factinv.append((factinv[-1] * tmp[-1]) % mod)
print(cmb(n+m, n, mod))
if __name__ == "__main__":
main()
| import math
def modpow(a,b,mod=10**9+7):
res=1
a%=mod
leng=int(math.log2(b))
for i in range(leng,-1,-1):
res=(res*res)%mod
if (b>>i)&1:
res=(res*a)%mod
return res
def fact(x):
ans=1
for i in range(2,x+1):
ans = (ans*i)%(10**9+7)
return ans
def comb(n,r):
return fact(n)*modpow(fact(r),10**9+5)*modpow(fact(n-r),10**9+5)%(10**9+7)
x,y=map(int,input().split(' '))
if (x+y)%3!=0 or 2*x-y<0 or 2*y-x<0:
print(0)
else:
x,y=max(x,y),min(x,y)
d=x-y
n=((x-2*d)//3)
m=n+d
print(comb(n+m,n)) | 1 | 150,164,479,857,988 | null | 281 | 281 |
# B - Papers, Please
N = int(input())
my_list = list(input().split())
j = 0
for i in range(0, N):
if int(my_list[i]) % 2 == 0:
if int(my_list[i]) % 3 != 0 and int(my_list[i]) % 5 != 0:
j += 1
if j != 0:
print('DENIED')
else:
print('APPROVED')
| n=int(input())
a=list(map(int,input().split()))
for i in a:
if i%2==0:
if i%3!=0 and i%5!=0:
print('DENIED')
exit()
print('APPROVED') | 1 | 68,872,053,826,592 | null | 217 | 217 |
W = raw_input().lower()
s = []
ans = 0
while True:
T = map(str, raw_input().split())
if(T[0] == "END_OF_TEXT"):
break
else:
for i in range(len(T)):
if(W == T[i].lower()):
ans += 1
print(ans) | N=int(input())
s=[0]*N
t=[0]*N
for i in range(N):
s[i],t[i] = input().split()
t[i]=int(t[i])
X=input()
j= s.index(X)
if X==s[-1]:
ans=0
else:
ans= sum(t[j+1:])
print(ans) | 0 | null | 49,646,134,793,312 | 65 | 243 |
#!/usr/bin/env python
contents = []
counter = 0
word = input()
while True:
text = input()
if text == "END_OF_TEXT":
break
textWords = text.split()
contents.append(textWords)
for x in contents:
for y in x:
if y.lower() == word:
counter += 1
print(counter) | w = input().casefold()
c = 0
while True:
_ = input()
if(_ == "END_OF_TEXT"):
break
t = _.casefold().split()
c += t.count(w)
print(c) | 1 | 1,866,295,413,472 | null | 65 | 65 |
import numpy as np
H, N = map(int, input().split())
A = []
B = []
for i in range(N):
a, b = map(int, input().split())
A.append(a)
B.append(b)
A = np.array(A)
B = np.array(B)
DP = np.zeros(H + 1)
for i in range(1, H + 1):
DP[i] = np.amin(DP[np.maximum(i - A, 0)] + B)
print(int(DP[-1]))
|
N = int(input())
A = map(int, input().split())
AI = sorted(((a, i) for i, a in enumerate(A, 1)), reverse=True)
def solve(a, i, prev):
pl, pr, ps = i, 0, 0
for l, r, s in prev:
yield l, r-1, max(s+abs(r-i)*a, ps+abs(i-pl)*a)
pl, pr, ps = l, r, s
yield pl+1, pr, ps+abs(i-pl)*a
prev = [(1, N, 0)]
for a,i in AI:
prev = [*solve(a,i, prev)]
print(max(s for l, r, s in prev))
| 0 | null | 57,616,436,495,630 | 229 | 171 |
class UnionFind:
def __init__(self, numV):
self.pars = list(range(numV))
self.ranks = [0] * numV
self.sizes = [1] * numV
def getRoot(self, x):
par = self.pars[x]
if par != x:
self.pars[x] = par = self.getRoot(par)
return par
def merge(self, x, y):
x, y = self.getRoot(x), self.getRoot(y)
sx, sy = self.sizes[x], self.sizes[y]
if x == y: return (0, 0)
if self.ranks[x] < self.ranks[y]:
self.pars[x] = y
self.sizes[y] += sx
else:
self.pars[y] = x
self.sizes[x] += sy
if self.ranks[x] == self.ranks[y]:
self.ranks[x] += 1
return (sx, sy)
def isSame(self, x, y):
return self.getRoot(x) == self.getRoot(y)
def updatePars(self):
for v in range(len(self.pars)):
self.getRoot(v)
def getSize(self, x):
return self.sizes[self.getRoot(x)]
n, m, k = map(int, input().split())
uf = UnionFind(n)
ex = [[] for i in range(n)]
for i in range(m):
a, b = map(int, input().split())
a -= 1
b -= 1
uf.merge(a,b)
ex[a].append(b)
ex[b].append(a)
for i in range(k):
c, d = map(int, input().split())
c -= 1
d -= 1
if uf.getRoot(c) == uf.getRoot(d):
ex[c].append(d)
ex[d].append(c)
ans = []
for i in range(n):
r = uf.getRoot(i)
ans.append(uf.sizes[r] - len(list(set(ex[i]))) - 1)
ans = [str(i) for i in ans]
print(' '.join(ans)) | from collections import deque
N, X, Y = map(int, input().split())
adj = [[] for _ in range(N)]
for i in range(N-1):
adj[i].append(i+1)
adj[i+1].append(i)
adj[X-1].append(Y-1)
adj[Y-1].append(X-1)
dist = [[-1]*N for _ in range(N)]
for i in range(N):
queue = deque([i])
dist[i][i] = 0
while queue:
now = queue.popleft()
for u in adj[now]:
if dist[i][u] < 0:
queue.append(u)
dist[i][u] = dist[i][now] + 1
ans = [0] * (N-1)
for i in range(N):
for j in range(i+1,N):
ans[dist[i][j]-1] += 1
[print(a) for a in ans] | 0 | null | 53,003,806,883,172 | 209 | 187 |
from collections import Counter
s = input()
n = len(s)
dp = [0]
mod = 2019
a = 0
for i in range(n):
a = a + int(s[n-i-1]) * pow(10, i, mod)
a %= mod
dp.append(a%mod)
ans = 0
c = Counter(dp)
for value in c.values():
ans += value * (value-1) / 2
print(int(ans)) | s=list(map(int,input()))
c=0
cnt=[0]*2019
cnt[0]+=1
for k in range(len(s)-1,-1,-1):
c=(c+s[k]*pow(10,len(s)-1-k,2019))%2019
cnt[c]+=1
print(sum(x*(x-1)//2 for x in cnt)) | 1 | 30,967,950,892,652 | null | 166 | 166 |
n = input()
ret = 0
for s in n:
ret *= 10
ret %= 9
ret += int(s)
ret %= 9
if ret == 0:
print("Yes")
else:
print("No") | A, B, C, K = map(int, input().split())
if (K - A) <= 0:
print(K)
else:
if (K - A - B) <= 0:
print(A)
else:
c = (K - A - B)
print(A - c)
| 0 | null | 13,137,458,252,260 | 87 | 148 |
def resolve():
a, b, m = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
ans = min(a_list) + min(b_list)
for _ in range(m):
x, y, c = map(int, input().split())
ans = min(ans, a_list[x-1]+b_list[y-1]-c)
print(ans)
resolve() | A, B, M = [int(_) for _ in input().split()]
a = [int(_) for _ in input().split()]
b = [int(_) for _ in input().split()]
xyc = [[int(_) for _ in input().split()] for i in range(M)]
rets = [min(a) + min(b)]
for x, y, c in xyc:
rets += [a[x-1] + b[y-1] - c]
print(min(rets)) | 1 | 53,862,454,884,618 | null | 200 | 200 |
n = input()
c = n[-1]
if c in "24579":
print("hon")
elif c in "0168":
print("pon")
else:
print("bon") | num = input().split()
print(' '.join(map(str, sorted(num)))) | 0 | null | 9,928,069,680,060 | 142 | 40 |
n = input()
str_n = list(n)
if str_n[-1] == "3":
print("bon")
elif str_n[-1] == "0" or str_n[-1] == "1" or str_n[-1] == "6" or str_n[-1] == "8":
print("pon")
else:
print("hon") | # -*- coding: utf-8 -*-
"""
B - TAKOYAKI FESTIVAL 2019
https://atcoder.jp/contests/abc143/tasks/abc143_b
"""
import sys
from itertools import combinations
def solve(takoyaki):
return sum(x * y for x, y in combinations(takoyaki, 2))
def main(args):
_ = input()
takoyaki = map(int, input().split())
ans = solve(takoyaki)
print(ans)
if __name__ == '__main__':
main(sys.argv[1:])
| 0 | null | 93,802,276,597,328 | 142 | 292 |
from sys import stdin
input = stdin.readline
n = int(input())
A = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
set_m = set([])
for i in range(2 ** n):
tmp = 0
for j in range(n):
if (i >> j) & 1:
tmp += A[j]
set_m.add(tmp)
for i in m:
if i in set_m:
print("yes")
else:
print("no")
| def ans(n, AA, x):
tmp = n + AA[0]
if len(AA) == 1:
try: x[tmp] = 1
except: pass
else:
ans(n, AA[1:], x)
try:
x[tmp] = 1
ans(tmp, AA[1:],x)
except:
pass
return
n = raw_input()
A = map(int, raw_input().split())
q = raw_input()
M = map(int, raw_input().split())
x = [0 for i in range(max(M)+1)]
ans(0, A, x)
for e in M:
if x[e] == 1:
print 'yes'
else:
print 'no' | 1 | 99,692,299,410 | null | 25 | 25 |
_ = input()
A = [int(a) for a in input().split(" ")]
for i in range(1, len(A)):
print(" ".join([str(a) for a in A]))
key = A[i]
j = i - 1
while j >= 0 and A[j] > key:
A[j + 1] = A[j]
j -= 1
A[j + 1] = key
print(" ".join([str(a) for a in A])) | def insertion_sort(A):
for i in range(1,len(A)):
print(*A)
key = A[i]
#/* insert A[i] into the sorted sequence A[0,...,j-1] */
j = i - 1
while j >= 0 and A[j] > key:
A[j+1] = A[j]
j-=1
A[j+1] = key
if __name__=='__main__':
n=int(input())
A=list(map(int,input().split()))
insertion_sort(A)
print(*A) | 1 | 6,365,271,002 | null | 10 | 10 |
from itertools import accumulate
n = int(input())
As = list(map(int, input().split()))
# ノードが1個しかないとき
if n == 0:
if As[0] == 1:print(1)
else:print(-1)
exit()
# 深さが2以上のとき、初め0ならアウト
if As[0] != 0:
print(-1)
exit()
acc_r = list(accumulate(As[::-1]))
acc_r = acc_r[::-1]
# 一個ずれる
acc = acc_r[1:] + [acc_r[-1]]
p = 1
ans = 1
for s, a in zip(acc,As):
p = min((p-a)*2, s)
if p < 0:
print(-1)
exit()
ans += p
print(ans) | import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n, m = list(map(int, readline().split()))
s = str(readline().rstrip().decode('utf-8'))
res = []
start = n
while True:
b = False
for j in range(max(0, start - m), start):
if s[j] == "0":
res.append(start - j)
start = j
b = True
break
if not b:
print(-1)
exit()
else:
if j == 0:
res.reverse()
print(*res)
exit()
if __name__ == '__main__':
solve()
| 0 | null | 78,834,124,398,180 | 141 | 274 |
x = int(input())
mo = 100
ans = 0
while mo < x:
r = mo//100
mo += r
ans += 1
print(ans) | d = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(d)]
t = [int(input()) for _ in range(d)]
last = [[0] * d for _ in range(26)] # 26xd
ans = 0
for i in range(d):
type = t[i] # 1~26
contest = c[type-1]
satisfy = s[i][type-1]
ans += satisfy
last[type-1][i:] = [i+1] * (d-i)
for j in range(26):
ans -= c[j] * ((i+1)-last[j][i])
print(ans) | 0 | null | 18,614,014,543,888 | 159 | 114 |
def input_list():
return list(map(int, input().split()))
def main():
s = list(input())
k = int(input())
if len(set(s)) == 1:
print(int(len(s)*(k/2)))
exit()
sw = [s[0]]
num = 0
numbers = [num]
for i in range(1, len(s)):
if s[i-1] != s[i]:
num += 1
numbers.append(num)
if num == 0 and sw[0] == s[i]:
sw.append(s[i])
num = 0
end_w = s[-1]
ew = []
for i in range(len(s)-1, -1, -1):
if end_w != s[i]:
num += 1
if num == 0 and end_w == s[i]:
ew.append(s[i])
nc = collections.Counter(numbers)
a = 0
for n,c in nc.items():
if c == 1:
continue
if c % 2 == 0:
a += c // 2
else:
a += (c-1)//2
ans = a * k
b = 0
if ew[0] == sw[0]:
haji = len(sw) + len(ew)
if haji % 2 == 0:
print(a * k + (k-1))
exit()
print(ans - b)
import math
import fractions
import collections
import itertools
from functools import reduce
main() | s = list(input())
k = int(input())
if len(set(s)) == 1:
print((len(s)*k)//2)
exit()
def n_change(sss):
s = sss.copy()
x = 0
for i in range(1, len(s)):
if s[i] == s[i-1]:
s[i] = "X"
x += 1
return x
print(n_change(s) + (k-1) * (n_change(2*s) - n_change(s))) | 1 | 175,318,313,029,888 | null | 296 | 296 |
import os, sys, re, math
S = input()
dow = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
print(7 - dow.index(S))
| s = input()
l = [0,'SAT','FRI','THU','WED','TUE','MON','SUN']
print(l.index(s)) | 1 | 133,121,294,982,466 | null | 270 | 270 |
#!/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]) | # coding: utf-8
H, W = list(map(int, input().split()))
S = []
for _ in range(H):
S.append(list(input()))
grid = [[0 for _ in range(W)] for _ in range(H)]
for h in range(1,H):
if S[h-1][0] == '#' and S[h][0] == '.':
grid[h][0] = grid[h-1][0] + 1
else:
grid[h][0] = grid[h-1][0]
for w in range(1,W):
if S[0][w-1] == '#' and S[0][w] == '.':
grid[0][w] = grid[0][w-1] + 1
else:
grid[0][w] = grid[0][w-1]
for w in range(1,W):
for h in range(1,H):
if S[h-1][w] == '#' and S[h][w] == '.':
next_h = grid[h-1][w] + 1
else:
next_h = grid[h-1][w]
if S[h][w-1] == '#' and S[h][w] == '.':
next_w = grid[h][w-1] + 1
else:
next_w = grid[h][w-1]
grid[h][w] = min([next_w, next_h])
if S[H-1][W-1] == '#':
grid[H-1][W-1] += 1
print(grid[H-1][W-1]) | 1 | 49,434,395,198,878 | null | 194 | 194 |
A, B, K = list(map(int, input().split()))
A -= K
if A < 0:
B += A
A = 0
if B < 0:
B = 0
print(A, B)
| import math
def main():
x1, y1, x2, y2 = map(float, input().split())
b = abs(x2 - x1)
h = abs(y2 - y1)
d = math.sqrt(b ** 2 + h ** 2)
print("{0:.8f}".format(d))
if __name__ == "__main__":
main() | 0 | null | 51,942,454,513,232 | 249 | 29 |
def main():
s = input()
mod = 2019
mod_count = {i: 0 for i in range(mod)}
now_num = 0
base = 1
for i in range(len(s) - 1, -1, -1):
mod_count[now_num] += 1
now_num += base * int(s[i])
now_num %= mod
base *= 10
base %= mod
ans = 0
mod_count[now_num % mod] += 1
for i in range(mod):
ans += mod_count[i] * (mod_count[i] - 1) // 2
print(ans)
if __name__ == '__main__':
main()
| s=input()
ls=len(s)
m=[0]*(2019)
m[0]+=1
cnt = 0
b = 0
for i in range(ls):
a = (b + pow(10,cnt,2019)*int(s[ls - i -1])) % 2019
m[a] += 1
b = a
cnt += 1
ans = 0
for i in m:
if i <= 1:
continue
ans += i*(i-1)//2
print(ans)
| 1 | 30,967,811,813,942 | null | 166 | 166 |
def check(pt, brackets):
brackets.sort(reverse=True)
for m, t in brackets:
if pt + m < 0:
return -1
pt += t
return pt
n = int(input())
brackets_p = [] # (始めを0として、( = +1, ) = -1 として、最後はいくつか, 途中の最小値はいくつか)
brackets_m = []
pt = 0
mt = 0
for _ in range(n):
s = input()
total = 0
mini = 0
for c in s:
if c == '(':
total += 1
else:
total -= 1
mini = min(mini, total)
if total >= 0:
if mini == 0:
pt += total
else:
brackets_p.append((mini, total))
else:
total, mini = -total, mini - total
if mini == 0:
mt += total
else:
brackets_m.append((mini, total))
pt = check(pt, brackets_p)
mt = check(mt, brackets_m)
if (pt == -1) or (mt == -1) or (pt != mt):
print('No')
else:
print('Yes')
| k=int(input())
a=7
cnt=1
while cnt<=k+2:
if a%k==0:
print(cnt)
flag=True
break
else:
flag=False
cnt+=1
a=(10*a+7)%k
if not flag:
print(-1)
| 0 | null | 14,787,661,636,064 | 152 | 97 |
a, b, k = map( int, input().split() )
if a + b < k:
print( "0 0" )
elif a < k:
print( "0 " + str( a + b - k ) )
else:
print( str( a - k ) + " " + str( b ) ) | D, T, S=map(int, input().split())
if S*T-D>=0:print('Yes')
else:print('No') | 0 | null | 53,974,603,950,612 | 249 | 81 |
import sys
import numpy as np
def main():
input = sys.stdin.readline
d = int(input())
c = np.array([int(x) for x in input().split()])
last = np.zeros(26, dtype="int64")
for i in range(d):
s = np.array([int(x) for x in input().split()])
key, value = -1, -1
for i in range(26):
if value < s[i] + last[i]:
key = i
value = s[i] + last[i]
last[key] = 0
print(key+1)
last += c
if __name__ == "__main__":
main() | n = int(input())
ans = []
while(n > 0):
x = n % 26
n = n // 26
if(x == 0):
x = 26
n -= 1
ans.append(chr(x + ord('a') -1))
# print(x,n)
ans.reverse()
print("".join(ans))
| 0 | null | 10,817,212,208,128 | 113 | 121 |
a,b,c,d=map(int,input().split())
for i in range(1001):
if i%2==0:
c-=b
if c<=0:
print("Yes")
exit(0)
else:
a-=d
if a<=0:
print("No")
exit(0)
| from math import ceil
A, B, C, D = map(int, input().split())
time_A, time_C = ceil(A/D), ceil(C/B)
print('Yes') if time_A >= time_C else print('No') | 1 | 29,576,559,814,942 | null | 164 | 164 |
from functools import lru_cache
@lru_cache(maxsize=None)
def fib(n):
if n < 2:
return n
return fib(n-1) + fib(n-2)
class Fibonacci(object):
memo = [1, 1]
def get_nth(self, n):
if n < len(Fibonacci.memo):
return Fibonacci.memo[n]
# print('fib({0}) not found'.format(n))
for i in range(len(Fibonacci.memo), n+1):
result = Fibonacci.memo[i-1] + Fibonacci.memo[i-2]
Fibonacci.memo.append(result)
# print('fib({0})={1} append'.format(i, result))
return Fibonacci.memo[n]
if __name__ == '__main__':
# ??????????????\???
num = int(input())
# ?????£??????????????°????¨????
#f = Fibonacci()
#result = f.get_nth(num)
result = fib(num+1)
# ???????????????
print('{0}'.format(result)) | import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
from collections import defaultdict
n,m=map(int,input().split())
visited=[0]*n
d=defaultdict(list)
def dfs(n):
visited[n]=1
#print(visited)
for i in d[n]:
if visited[i]==0:
dfs(i)
for i in range(m):
a,b=map(int,input().split())
a,b=a-1,b-1
d[a].append(b)
d[b].append(a)
r=-1
for i in range (n):
if visited[i]==0:
dfs(i)
r+=1
print(r) | 0 | null | 1,128,388,708,070 | 7 | 70 |
from collections import deque
N = int(input())
d = {i:[] for i in range(1, N+1)}
q = deque([(1, "a")])
while q:
pos, s = q.popleft()
if pos == N+1:
break
d[pos].append(s)
size = len(set(s))
for i in range(size+1):
q.append((pos+1, s+chr(97+i)))
for i in d[N]:
print(i) | import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
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 insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
N = int(input())
if N == 1:
print("a")
else:
S = list("abcdefghij")
Q = deque([("a",1)]) #文字列、種類
while len(Q) != 0:
s,kind = Q.popleft()
for i in range(kind+1):
news = s+S[i]
if len(news) == N+1:
break
if len(news) == N:
print(news)
if i == kind:
Q.append((news,kind+1))
else:
Q.append((news,kind)) | 1 | 52,499,655,927,642 | null | 198 | 198 |
N, K = map(int,input().split())
ans = 0
MOD = 10**9 + 7
for i in range(K,N+2):
x = (N+1-i) * i + 1
ans += x
ans %= MOD
print (ans) | import sys
INF = 1 << 60
MOD = 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
ward = 96
n, s = map(int, input().split())
mask = int(('1' * 32 + '0' * 64) * (s + 1) , 2)
Mask = (1 << (s + 1) * ward) - 1
dp = 1
for a in map(int, input().split()):
dp = (dp * 2) + (dp << ward * a)
dp &= Mask
dp = (dp & (~mask)) + ((dp & mask) >> 64) * ((1 << 64) % MOD)
print(((dp >> s * ward) & ((1 << ward) - 1)) % MOD)
resolve() | 0 | null | 25,287,380,645,868 | 170 | 138 |
import collections
n = int(input())
s = [input() for i in range(n)]
t = collections.Counter(s)
print(len(t)) | N=int(input())
se=set(input() for _ in range(N))
print(len(se)) | 1 | 30,283,279,456,362 | null | 165 | 165 |
# -*- coding: utf-8 -*-
r, c = list(map(int, input().split()))
a = []
line_sum = 0
for i in range(r):
a.append(list(map(int, input().split())))
for i in range(r):
for j in range(c + 1):
if j == c:
print('{0}'.format(sum(a[i])))
line_sum += sum(a[i])
else:
print('{0} '.format(a[i][j]), end='')
for i in range(c):
column_sum = 0
for j in range(r):
column_sum += a[j][i]
print('{0} '.format(column_sum), end='')
print(line_sum)
| # -*-coding:utf-8
def main():
r, c = map(int, input().split())
#A = [[0 for i2 in range(c+1)] for i1 in range(r+1)]
A = []
for i in range(r):
tokens = list(map(int, input().split()))
tokens.append(sum(tokens))
A.append(tokens)
rowSumList = []
for i in range(c+1):
rowSum = 0
for j in range(r):
rowSum += A[j][i]
rowSumList.append(rowSum)
A.append(rowSumList)
for i in range(r+1):
for j in range(c+1):
if(j == c):
print('%d' % A[i][j])
else:
print('%d ' % A[i][j], end='')
if __name__ == '__main__':
main() | 1 | 1,362,091,174,652 | null | 59 | 59 |
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):
a, b = L[i], L[j]
c = a - b + 1
if c > b: continue
ans += (j - bisect.bisect_left(L, c))
print(ans) | N = int(input())
L = sorted(list(map(int, input().split())))[::-1]
def is_ok(i, x):
return L[i] > x
def bisect(ng, ok, x):
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if is_ok(mid, x):
ok = mid
else:
ng = mid
return ok
ans = 0
for i in range(N):
for j in range(i + 1, N):
k = bisect(N, j, L[i] - L[j])
ans += k - j
print(ans)
| 1 | 171,871,264,326,890 | null | 294 | 294 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.