code1
stringlengths 16
427k
| code2
stringlengths 16
427k
| similar
int64 0
1
| pair_id
int64 6.82M
181,637B
⌀ | question_pair_id
float64 101M
180,471B
⌀ | code1_group
int64 2
299
| code2_group
int64 2
299
|
---|---|---|---|---|---|---|
import sys
# from math import sqrt, gcd, ceil, log
# from bisect import bisect
from collections import defaultdict, Counter
inp = sys.stdin.readline
read = lambda: list(map(int, inp().strip().split()))
# sys.setrecursionlimit(10**6)
def solve():
n = int(input()); arr = read()
ans= 0
for i in range(n):
for j in range(i+1, n):
ans += arr[i]*arr[j]
print(ans)
if __name__ == "__main__":
solve()
|
def power(x, y, p) :
res = 1 # Initialize result
# Update x if it is more
# than or equal to p
x = x % p
if (x == 0) :
return 0
while (y > 0) :
# If y is odd, multiply
# x with result
if ((y & 1) == 1) :
res = (res * x) % p
# y must be even now
y = y >> 1 # y = y/2
x = (x * x) % p
return res
def ncr(n, r, p):
# initialize numerator
# and denominator
num = den = 1
for i in range(r):
num = (num * (n - i)) % p
den = (den * (i + 1)) % p
return (num * pow(den, p - 2, p)) % p
n,a,b=map(int,input().split())
m=10**9+7;
ans=power(2,n,m)
ans-=ncr(n,a,m)
ans-=ncr(n,b,m)
print(ans%m-1)
| 0 | null | 117,452,530,384,988 | 292 | 214 |
n,a,b= map(int,input().split())
loop = n//(a+b)
r = n%(a+b)
before_count = loop * a
after_count = min(r,a)
ans = before_count + after_count
print(ans)
|
def main():
n = int(input())
a = list(map(int, input().split()))
ans = 1
if 0 in a:
print(0)
return
else:
flag = True
for i in a:
ans *= i
if ans > (10 ** 18):
print(-1)
return
print(ans)
main()
| 0 | null | 35,715,491,159,668 | 202 | 134 |
def main():
n = int(input())
print(b(n))
def b(n: int) -> int:
m = 100
i = 0
while m < n:
m = m * 101 // 100
i += 1
return i
if __name__ == '__main__':
main()
|
k=int(input())
k *= 9
amari = 63
for i in range(1, 10 ** 6 + 1):
amari %= k
if amari == 0:
print(i)
break
else:
amari = amari * 10 + 63
else:
print(-1)
| 0 | null | 16,467,507,776,180 | 159 | 97 |
def solve_loop(loop, K):
S = sum(loop)
L = len(loop)
if S < 0:
acc = 0
K = min(K, L)
minL = 1
elif K//L >= 2:
acc = S * (K//L - 1)
K = K - L * (K//L - 1)
minL = 0
else:
acc = 0
minL = 1
ans = -10 ** 9 - 1
for i in range(L):
#print(loop[i:] + loop[:i], "acc=", acc, "min=", minL, "max=", K)
tmp = 0
if minL:
tmp = loop[i]
for l in range(minL, K):
ans = max(tmp, ans)
tmp += loop[(i+l) % L]
#print(tmp)
#print(i, l, tmp)
ans = max(tmp, ans)
#print(loop, ans, acc)
return acc + ans
if K >= L:
return max(acc, acc + ans)
else:
return ans
def solve():
N, K = map(int, input().split())
P = list(map(lambda n: int(n)-1, input().split())) # 0-based index
C = list(map(int, input().split()))
flag = [False] * N
ans = -10**9-1 # worst case is -10**9
for i in range(N):
if flag[i]:
continue
loop = []
j = P[i]
for _ in range(N):
if flag[j]: # loop end
break
flag[j] = True
loop += [C[j]]
j = P[j]
ans = max(ans, solve_loop(loop, K))
print(ans)
solve()
|
n, k = map(int, input().split())
p = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
p_flag = [0 for _ in range(len(p))]
loop_max = []
loop_len = []
S = []
S_max = []
ans = []
for i in range(len(p)):
# if p_flag[i] == 1:
# continue
now = i
temp_len = 0
temp_s = 0
S_max = - (10**9 + 1)
temp_l = []
while True:
now = p[now] - 1
temp_len += 1
temp_s += c[now]
temp_l.append(temp_s)
p_flag[now] = 1
# 最初に戻ってきたら
if now == i:
break
loop_len.append(temp_len)
loop_max.append(temp_l)
S.append(temp_s)
for i in range(len(S)):
mod = k % loop_len[i] if k % loop_len[i] != 0 else loop_len[i]
if S[i] > 0:
if max(loop_max[i][:mod]) > 0:
ans.append(((k-1)//loop_len[i])*S[i] + max(loop_max[i][:mod]))
else:
ans.append(((k - 1) // loop_len[i]) * S[i])
else:
ans.append(max(loop_max[i]))
# print(loop_max)
# print(ans)
print(max(ans))
| 1 | 5,359,271,019,772 | null | 93 | 93 |
s=input()
n=int(input())
if len(s)==1:print(n//2);exit()
if len(set(s))==1:print(len(s)*n//2);exit()
c=1
l=[]
for x in range(1,len(s)):
if s[x-1]==s[x]:
c+=1
if x==len(s)-1:l.append(c)
else:l.append(c);c=1
t=0
if s[0]==s[-1] and l[0]%2==1 and l[-1]%2==1:t=n-1
print(sum([i//2 for i in l])*n+t)
|
import math
import sys
import os
from operator import mul
sys.setrecursionlimit(10**7)
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))
if os.getenv("LOCAL"):
inputFile = basename_without_ext = os.path.splitext(os.path.basename(__file__))[0]+'.txt'
sys.stdin = open(inputFile, "r")
INF = float("inf")
N = list(_S())
ans = 'No'
for s in N:
if s == '7':
ans = 'Yes'
break
print(ans)
| 0 | null | 104,944,238,415,520 | 296 | 172 |
from collections import deque
s,q=deque([*input()]),int(input())
judge=False
for i in range(q):
t=input().split()
if len(t)==1:
judge = not judge
else:
t,f,c=t
if not judge and f=='1': s.appendleft(c)
elif not judge and f=='2': s.append(c)
elif judge and f=='1': s.append(c)
else: s.appendleft(c)
if judge: s.reverse()
print(*s,sep='')
|
import bisect,collections,copy,heapq,itertools,math,string
import numpy as np
import sys
sys.setrecursionlimit(10**7)
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
_a = LI()
#AB = [LI() for _ in range(N)]
#A,B = zip(*AB)
a = np.array(_a)
#C = np.zeros(N + 1)
if not np.amin(a)==1:
print(-1)
exit()
maxNumber = 1
for i in range(N):
if a[i] == maxNumber:
maxNumber += 1
print(N - (maxNumber-1))
# current = 0
# for i in range(1,200001):
# position=[]
# position = np.where(a[current:] == i)
# if position ==[] or position[0] == []:
# break
# else:
# current = position[0][0]
# print(current)
# if ans:
# print('Yes')
# else:
# print('No')
| 0 | null | 86,103,668,874,432 | 204 | 257 |
H, W, K = map(int, input().split())
C = ["" for _ in range(H)]
for h in range(H):
C[h] = [s for s in input()]
cnt = 0
for h in range(1 << H):
for w in range(1 << W):
black = 0
for i in range(H):
if (h >> i & 1) == 1:
continue
for j in range(W):
if (w >> j & 1) == 1:
continue
if C[i][j] == "#":
black += 1
if black == K:
cnt += 1
print(cnt)
|
H,W,K=map(int,input().split())
c=[str(input())for i in range(H)]
ans=0
for maskH in range(2**H):
for maskW in range(2**W):
black=0
for i in range(H):
for j in range(W):
if ((maskH>>i)&1)==1:
continue
if ((maskW>>j)&1)==1:
continue
if c[i][j]=='#':
black+=1
if black==K:
ans+=1
print(ans)
| 1 | 8,956,709,402,590 | null | 110 | 110 |
import sys
N = int(input())
p = list(map(int, input().split()))
for i in range(N):
if p[i] == 0:
print(0)
sys.exit()
product = 1
for i in range(N):
product = product * p[i]
if product > 10 ** 18:
print(-1)
sys.exit()
break
print(product)
|
import sys
n = int(input())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
multi = 1
if 0 in a:
print('0')
sys.exit()
for i in a:
multi *= i
if multi > 10**18:
print('-1')
sys.exit()
print(multi)
| 1 | 16,157,016,237,130 | null | 134 | 134 |
n = int(input())
a = list(map(int,input().split()))
money = 1000
kabu = 0
if a[0] < a[1]:
flg = 'kau'
elif a[0] > a[1]:
flg = 'uru'
else:
flg = 'f'
for i in range(1,n):
if a[i-1] < a[i]:
if flg != 'uru':
kabu = money // a[i-1]
money -= kabu * a[i-1]
flg = 'uru'
elif a[i-1] > a[i]:
if flg != 'kau':
money += kabu * a[i-1]
kabu = 0
flg = 'kau'
else:
pass
if kabu > 0:
money += kabu * a[-1]
print(money)
|
N = int(input())
A = list(map(int, input().split()))
kabu = 0
yen = 1000
for i in range(N-1):
if A[i] < A[i+1]:
buy = yen//A[i]
kabu += buy
yen -= buy * A[i]
elif A[i] > A[i+1]:
yen += kabu * A[i]
kabu = 0
if kabu > 0:
yen += A[-1] * kabu
kabu = 0
print(yen)
| 1 | 7,256,965,280,462 | null | 103 | 103 |
from collections import deque
n, q = map(int, input().split())
t = 0
queue = deque([])
for _ in range(n):
name, time = input().split()
time = int(time)
queue.append([name, time])
while len(queue):
if queue[0][1] > q:
queue[0][1] -= q
t += q
queue.rotate(-1)
else:
t += queue[0][1]
queue[0][1] = t
print(" ".join(list(map(str, queue.popleft()))))
|
from collections import deque;
count, time_slice = map(int, input().split(" "));
data = [];
for i in range(count):
data += input().split(" ");
def round_robin(data, count, time_slice):
t = 0;
data = [[data[i], int(data[i + 1])] for i in range(0, len(data), 2)];
que = deque(data);
while len(que) > 0:
current = que.popleft();
if current[1] > time_slice:
current[1] -= time_slice;
t += time_slice;
que.append(current);
else:
t += current[1];
print(current[0], t);
round_robin(data, count, time_slice);
| 1 | 43,754,173,232 | null | 19 | 19 |
def main():
a, b, c, d = map(int, input().split())
ans = max(max(a*c, a*d), max(b*c, b*d))
print(ans)
if __name__ == '__main__':
main()
|
from sys import stdin
readline = stdin.readline
def i_input(): return int(readline().rstrip())
def i_map(): return map(int, readline().rstrip().split())
def i_list(): return list(i_map())
def main():
A, B, C, D = i_map()
print(max([A * C, A * D, B * C, B * D]))
if __name__ == "__main__":
main()
| 1 | 3,001,870,487,028 | null | 77 | 77 |
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7
def inp():
'''
一つの整数
'''
return int(input())
def inpl():
'''
一行に複数の整数
'''
return list(map(int, input().split()))
class combination():
def __init__(self, mod):
'''
modを指定して初期化
'''
self.mod = mod
self.fac = [1, 1] # 階乗テーブル
self.ifac = [1, 1] # 階乗の逆元テーブル
self.inv = [0, 1] # 逆元計算用
def calc(self, n, k):
'''
nCk%modを計算する
'''
if k < 0 or n < k:
return 0
self.make_tables(n) # テーブル作成
k = min(k, n - k)
return self.fac[n] * (self.ifac[k] * self.ifac[n - k] %
self.mod) % self.mod
def make_tables(self, n):
'''
階乗テーブル・階乗の逆元テーブルを作成
'''
for i in range(len(self.fac), n + 1):
self.fac.append((self.fac[-1] * i) % self.mod)
self.inv.append(
(-self.inv[self.mod % i] * (self.mod // i)) % self.mod)
self.ifac.append((self.ifac[-1] * self.inv[-1]) % self.mod)
mod = 998244353
comb = combination(mod)
n, m, k = inpl()
ans = 0
for i in range(min(n, k + 1)):
ans += m * pow(m - 1, n - 1 - i, mod) * comb.calc(n - 1, i) % mod
ans %= mod
print(ans)
|
# -*- coding: utf-8 -*-
x=int(input())
a=360
b=x
r=a%b
while r!=0:
a=b
b=r
r=a%b
lcm=x*360/b
k=int(lcm/x)
print(k)
| 0 | null | 18,303,977,231,932 | 151 | 125 |
import re
def transletter(matchobj):
letter = matchobj.group(0)
if letter.islower(): return letter.upper()
else: return letter.lower()
def main():
text = input()
print(re.sub(r'[a-zA-Z]', transletter, text))
main()
|
a=input()
print(str.swapcase(a))
| 1 | 1,526,607,165,070 | null | 61 | 61 |
n,m=map(int,input().split())
lst=list(map(int,input().split()))
if n<sum(lst) : print(-1)
else : print(n-sum(lst))
|
if __name__ == "__main__":
N = int(input())
hash = {}
for i in range(N):
hash[input()] = ""
print(len(hash.keys()))
| 0 | null | 31,191,511,947,090 | 168 | 165 |
t=int(input())
if t==0:
print("1")
elif t==1:
print("0")
|
N = int(input())
ans = 0 if N else 1
print(ans)
| 1 | 2,890,397,645,348 | null | 76 | 76 |
W,H,x,y,r = map(int, input().split())
if W < (x+r) or H < (y + r) or 0 > (x-r) or 0 > (y-r) :
print("No")
else :
print("Yes")
|
s=input()
times=int(input())
for _ in range(times):
order=input().split()
a=int(order[1])
b=int(order[2])
if order[0]=="print":
print(s[a:b+1])
elif order[0]=="reverse":
s=s[:a]+s[a:b+1][::-1]+s[b+1:]
else :
s=s[:a]+order[3]+s[b+1:]
| 0 | null | 1,283,029,762,812 | 41 | 68 |
a,b,c=map(int, input().split())
if a == b and a!= c:
print('Yes')
if b == c and b !=a:
print('Yes')
if c == a and c != b:
print('Yes')
if a == b == c:
print('No')
if a != b and a != c and b != c:
print('No')
|
def main():
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#main code here!
n,k,s=MI()
ans=[]
if s==10**9:
for i in range(k):
ans.append(s)
for i in range(n-k):
ans.append(1)
else:
for i in range(k):
ans.append(s)
for i in range(n-k):
ans.append(10**9)
print(*ans)
if __name__=="__main__":
main()
| 0 | null | 79,232,985,887,648 | 216 | 238 |
import sys
input = sys.stdin.buffer.readline
def gcd(a: int, b: int) -> int:
"""a, bの最大公約数(greatest common divisor: GCD)を求める
計算量: O(log(min(a, b)))
"""
while b:
a, b = b, a % b
return a
def multi_gcd(array: list) -> int:
"""arrayのGCDを求める"""
n = len(array)
ans = array[0]
for i in range(1, n):
ans = gcd(ans, array[i])
return ans
def make_mindiv_table(n):
mindiv = [i for i in range(n + 1)]
for i in range(2, int(n ** 0.5) + 1):
if mindiv[i] != i:
continue
for j in range(2 * i, n + 1, i):
mindiv[j] = min(mindiv[j], i)
return mindiv
def get_prime_factors(num):
res = []
while mindiv[num] != 1:
res.append(mindiv[num])
num //= mindiv[num]
return res
n = int(input())
a = list(map(int, input().split()))
mindiv = make_mindiv_table(10 ** 6)
set_primes = set()
flag = True
for val in a:
set_ = set(get_prime_factors(val))
for v in set_:
if v in set_primes:
flag = False
set_primes.add(v)
if not flag:
break
else:
print("pairwise coprime")
exit()
gcd_ = multi_gcd(a)
if gcd_ == 1:
print("setwise coprime")
exit()
print("not coprime")
|
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
N = INT()
A = LIST()
if reduce(gcd, A) != 1:
print("not coprime")
exit()
ma = max(A)
p = list(range(ma+1))
for x in range(2, int(ma ** 0.5) + 1):
if p[x]:
# xは素数,それがpの要素にあるうちは続ける
for i in range(2 * x, ma + 1, x):
p[i] = x
s = [set() for _ in range(N)]
t = set()
for i, x in enumerate(A):
while x != 1:
s[i].add(x)
t.add(x)
# 割り続けるとs[i]にその素数がたまっていく
x //= p[x]
l = sum(len(x) for x in s)
print("pairwise coprime" if l == len(t) else "setwise coprime")
| 1 | 4,130,305,896,232 | null | 85 | 85 |
A, B, H, M = map(int,input().split())
import numpy as np
theta_h=2*np.pi*(H/12 + M/720)#rad
theta_m=2*np.pi*M/60#rad
theta=min((max(theta_h, theta_m)-min(theta_h, theta_m)), 2*np.pi-(max(theta_h, theta_m)-min(theta_h, theta_m)))
print(np.sqrt(A**2 + B**2 - 2*np.cos(theta)*A*B))
|
import math
a,b,h,m=map(int,input().split())
lrad=6*m
srad=30*h+0.5*m
if abs(lrad-srad)<=180:
do=abs(lrad-srad)
else:
do=360-abs(lrad-srad)
rad=math.radians(do)
print(math.sqrt(a**2+b**2-2*a*b*math.cos(rad)))
| 1 | 20,133,342,421,312 | null | 144 | 144 |
import sys
sys.setrecursionlimit(10**7)
n = int(input())
def dfs(s):
if len(s) == n:
print(s)
return 0
for x in map(chr, range(97, ord(max(s))+2)):
dfs(s+x)
dfs('a')
|
n=int(input())
def make(floor,kind,name): #floor=何階層目か,kind=何種類使ってるか
if floor==n+1:
print(name)
return
num=min(floor,kind+1)
for i in range(num):
use=0 #新しい文字使ってるか
if kind-1<i:
use=1
make(floor+1,kind+use,name+chr(i+97))
make(1,0,"")
| 1 | 52,465,389,952,132 | null | 198 | 198 |
n=int(input())
if n%10==7:
print("Yes")
exit()
n//=10
if n%10==7:
print("Yes")
exit()
n//=10
if n%10==7:
print("Yes")
exit()
print("No")
|
def fib(n):
if n==0 or n==1:
return 1
x=[1,1]
for i in range(2,n+1):
x.append(x[i-1]+x[i-2])
return x[-1]
print(fib(int(input())))
| 0 | null | 17,284,622,606,620 | 172 | 7 |
N = int(input())
for i in range(10):
if i==0:
continue
else:
i_pair = N / i
if N % i == 0 and i_pair < 10:
print("Yes")
exit()
print("No")
|
import math
t = float(input())
a = math.pi * t**2
b = 2 * t * math.pi
print(str("{0:.8f}".format(a)) + " " + "{0:.8f}".format(b))
| 0 | null | 80,474,122,799,840 | 287 | 46 |
n,a,b = list(map(int, input().split()))
mod = int(1e9+7)
def inverse(n, mod):
return pow(n, mod - 2, mod)
def cmb(n, r, mod):
p, q = 1, 1
for i in range(r):
p = p * (n - i) % mod
q = q * (i + 1) % mod
return p * inverse(q, mod) % mod
ans = pow(2, n, mod) - 1
ans -= cmb(n, a, mod)
ans -= cmb(n, b, mod)
print(ans % mod)
|
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)
| 0 | null | 33,243,716,243,868 | 214 | 43 |
n = int(input())
A = list(map(int, input().split()))
x = sum(A)-A[0]
y = A[0]
ans = abs(x-y)
for a in A[1:]:
y += a
x -= a
ans = min(ans, abs(x-y))
print(ans)
|
from itertools import accumulate
def myAnswer(N:int,A:list) -> int:
accum = [A[0]]
accumRev = [sum(A)]
ans = 10**10
for i in range(1,N):
accumRev.append(accumRev[-1] - A[i-1])
accum.append(accum[-1]+A[i])
for i in range(len(accum)-1):
ans = min(ans,abs(accumRev[i+1] - accum[i]))
return ans
def modelAnswer(N:int,A:list) -> int:
T1 = [A[0]]
T2 = [sum(A)]
for i in range(1,N): # O(N)
T1.append(T1[-1]+A[i])
T2.append(T2[0] - T1[i-1])
# print(T1,T2)
ans = 10**10
for i in range(len(T1)-1): # O(N/2)
# print(abs(T1[i]-T2[i+1]))
ans = min(ans,abs(T1[i]-T2[i+1]))
return ans
def main():
N = int(input())
A = list(map(int,input().split()))
# print(modelAnswer(N,A[:]))
# print("-----------------------------")
print(myAnswer(N,A[:]))
if __name__ == '__main__':
main()
| 1 | 141,684,656,583,690 | null | 276 | 276 |
n, m = map(int, input().split())
lis = sorted(list(map(int, input().split())), reverse=True)
limit = sum(lis) / (4 * m)
judge = 'Yes'
for i in range(m):
if lis[i] < limit:
judge = 'No'
break
print(judge)
|
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd, ceil, atan, pi
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')
import string
# string.ascii_lowercase
from bisect import bisect_left
MOD = int(1e9)+7
INF = float('inf')
g = defaultdict(list)
n = 0
ans = defaultdict(int)
def bfs(x):
q = deque([(x, 0)])
w = set([x])
while q:
v, dis = q.popleft()
if v > x:
ans[dis] += 1
for to in g[v]:
if to not in w:
w.add(to)
q.append((to, dis + 1))
def solve():
# n, m = [int(x) for x in input().split()]
n, X, Y = [int(x) for x in input().split()]
X -= 1
Y -= 1
g[X].append(Y)
g[Y].append(X)
for i in range(1, n):
g[i].append(i-1)
g[i-1].append(i)
for i in range(n-1):
bfs(i)
for i in range(1, n):
print(ans[i])
t = 1
# t = int(input())
for case in range(1,t+1):
ans = solve()
"""
azyxwvutsrqponmlkjihgfedcb
"""
| 0 | null | 41,428,528,469,052 | 179 | 187 |
N = input()
N = list(N)
if N[len(N)-1] == '3':
print('bon')
elif N[len(N)-1] == '0' or N[len(N)-1] == '1' or N[len(N)-1] == '6' or N[len(N)-1] == '8':
print('pon')
else:
print('hon')
|
import collections
N,*S = open(0).read().split()
C = collections.Counter(S)
i = C.most_common()[0][1]
print(*sorted([k for k,v in C.most_common() if v == i]), sep='\n')
| 0 | null | 44,598,509,674,378 | 142 | 218 |
A,V = map(int,input().split())
B,W = map(int,input().split())
T = int(input())
if W >= V:
print('NO')
else:
if (V-W)*T >= abs(A-B):
print('YES')
else:
print('NO')
|
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
#a,b間の距離
d=abs(b-a)
#速度差
V=v-w
if V<=0:
print("NO")
exit()
T=d/V
if T<=t:
print("YES")
else:
print("NO")
| 1 | 15,045,246,629,920 | null | 131 | 131 |
N, M, X = map(int, input().split())
Ca = [list(map(int, input().split())) for _ in range(N)]
pattern = []
for i in range(2**N):
lis = []
for j in range(N):
if ((i>>j)&1):
lis.append(Ca[j])
pattern.append(lis)
cnt = []
for i in range(2**N):
g = [0] * (M+1)
for j in range(len(pattern[i])):
for k in range(M+1):
g[k] += pattern[i][j][k]
if M==1 and g[1]< X:
continue
elif M>1 and min(g[1:M+1]) < X:
continue
else:
cnt.append(g[0])
if len(cnt) ==0:
print(-1)
else:
print(min(cnt))
|
import itertools
import numpy as np
N_book, M_algo, X_skill = map(int, input().split())
A = []
for _ in range(N_book):
a = list(map(int, input().split()))
A.append(a)
flg = False
ans = float('inf')
for selector in list(itertools.product([1, 0], repeat=N_book))[:-1]:
C = []
for i in range(N_book):
if selector[i] == 1:
C.append(A[i])
D = list(np.array(C).sum(axis=0))
if (False in [i >= X_skill for i in D[1:]]):
continue
else:
flg = True
ans = min(ans, D[0])
if flg:
print(ans)
else:
print(-1)
| 1 | 22,314,109,065,370 | null | 149 | 149 |
N = int(input())
A = list(map(int, input().split()))
x = 0
for a in A:
x ^= a
out = []
for a in A:
out.append(str(x ^ a))
print(' '.join(out))
|
n=int(input())
a=list(map(int,input().split()))
c=a[0]
for i in range(1,n):
c=c^a[i]
for i in range(n):
print(c^a[i])
| 1 | 12,429,679,140,942 | null | 123 | 123 |
from collections import Counter
S = input()
S = S[::-1]
N = len(S)
counter = Counter()
counter[0] = 1
prev = 0
MOD = 2019
for i in range(N):
c = (int(S[i]) * pow(10, i, MOD) )%MOD
prev = (prev+c)%MOD
counter[prev] += 1
ans = 0
for k,v in counter.items():
ans += (v * (v-1))//2
print(ans)
|
from collections import Counter
S = input()
S = S[::-1]
# 1桁のmod2019, 2桁の2019, ...
# 0桁のmod2019=0と定めると都合が良いので入れておく
l = [0]
num = 0
for i in range(len(S)):
# 繰り返し二乗法で累乗の部分を高速化
# 自分で書かなくてもpow()で既に実装されている
# 一つ前のmodを利用するとPythonで通せた、それをしなくてもPyPyなら通る
num += int(S[i]) * pow(10,i,2019)
l.append(num % 2019)
# print(l)
ans = 0
c = Counter(l)
for v in c.values():
ans += v*(v-1)//2
print(ans)
| 1 | 30,967,733,750,408 | null | 166 | 166 |
def Qc():
x, n = map(int, input().split())
if 0 < n:
p = list(map(int, input().split()))
for i in range(101):
if x - i not in p:
print(x - i)
exit()
if x + i not in p:
res = x + 1
print(x + i)
exit()
else:
# 整数列がなにもない場合は自分自身が含まれていない最近値になる
print(x)
exit()
if __name__ == "__main__":
Qc()
|
import bisect
def abc170c_forbidden_list():
x, n = map(int, input().split())
p = list(map(int, input().split()))
if n == 0:
print(x)
return
p.sort()
for i in range(100):
idx = bisect.bisect_left(p, x - i)
if idx >= n or p[idx] != x - i:
print(x - i)
return
idx = bisect.bisect_left(p, x + i)
if idx >= n or p[idx] != x + i:
print(x + i)
return
abc170c_forbidden_list()
| 1 | 14,174,678,615,470 | null | 128 | 128 |
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]
def inside(y, x, H, W):
return 0 <= y < H and 0 <= x < W
def ceil(a, b):
return (a + b - 1) // b
def sum_of_arithmetic_progression(s, d, n):
return n * (2 * s + (n - 1) * d) // 2
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def lcm(a, b):
g = gcd(a, b)
return a / g * b
def solve():
N = int(input())
A = list(sorted(list(map(int, input().split())), reverse=True))
ans = A[0]
n = 1
for i in range(1, N):
if n == N - 1:
break
ans += A[i]
n += 1
if n == N - 1:
break
ans += A[i]
n += 1
if n == N - 1:
break
print(ans)
def main():
solve()
if __name__ == '__main__':
main()
|
import sys
#import numpy as np
import copy
fline = input().rstrip().split(' ')
N, Q = int(fline[0]), int(fline[1])
list = []
for i in range(N):
tlist = []
line = input().split(' ')
tlist = [line[0], line[1]]
#print(tlist)
list.append(tlist)
#print(list)
current = 0
while len(list) != 0:
if int(list[0][1]) <= Q:
current += int(list[0][1])
print(list[0][0] + " " + str(current))
del list[0]
else:
list[0][1] = str((int)(list[0][1])-Q)
list.append(list[0])
del list[0]
current += Q
#print(list)
| 0 | null | 4,653,610,483,004 | 111 | 19 |
n,k=map(int,input().split())
h=list(map(int,input().split()))
h.sort()
h.reverse()
if k>n:
k=n
for i in range (k):
h[i] = 0
print(sum(h))
|
n,d=list(map(int,input().split()))
s=list(map(int,input().split()))
s=sorted(s)
s.reverse()
if d>=n:
print(0)
else:
c=0
s=s[d:n]
for i in s:
c+=int(i)
print(c)
| 1 | 78,569,859,513,450 | null | 227 | 227 |
N, K = map(int, input().split())
data = list(map(int, input().split()))
for x in range(K):
# print(data)
raise_data = [0] * (N + 1)
for i, d in enumerate(data):
raise_data[max(0, i - d)] += 1
raise_data[min(N, i + d + 1)] -= 1
height = 0
ended = 0
for i in range(N):
height += raise_data[i]
data[i] = height
if height == N:
ended += 1
if ended == N:
# print(x)
break
print(*data)
|
from itertools import accumulate
N, K = map(int, input().split())
A = list(map(int, input().split()))
for k in range(min(50, K)):
B = [0]*N
for i in range(N):
B[max(0, i-A[i])] += 1
r = i+A[i]+1
if r < N:
B[r] -= 1
A = list(accumulate(B))
print(*A)
| 1 | 15,500,256,802,332 | null | 132 | 132 |
n = int(raw_input())
ai_list = map(int, raw_input().split())
max_ai = max(ai_list)
min_ai = min(ai_list)
sum_ai = sum(ai_list)
print '%d %d %d' % (min_ai, max_ai, sum_ai)
|
# first line > /dev/null
input()
items = sorted([int(i) for i in input().split(' ')])
print(items[0], items[-1], sum(items))
| 1 | 714,169,999,228 | null | 48 | 48 |
n = int(input())
a = list(map(int, input().split()))
if 1 in a:
num = 1
for i in range(n):
if a[i] == num:
a[i] = 0
num += 1
else:
a[i] = 1
print(sum(a))
else:
print(-1)
|
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
a=10**9
z_max=-1*a
z_min=a
w_max=-1*a
w_min=a
for x,y in l: #点のx座標とy座標の和の最大値と最小値の差か座標の差の最大値と最小値の差が答え
z_max=max(z_max,x+y)
z_min=min(z_min,x+y)
w_max=max(w_max,x-y)
w_min=min(w_min,x-y)
print(max(z_max-z_min,w_max-w_min))
| 0 | null | 59,219,838,121,538 | 257 | 80 |
import collections
N = int(input())
cnt = collections.defaultdict(int)
for _ in range(N):
s = input()
cnt[s] += 1
max_v = max(cnt.values())
ans = sorted([k for k, v in cnt.items() if v == max_v])
for s in ans:
print(s)
|
A, B, C, K = map(int, input().split())
if K<=A:
print(1*K)
elif A<K<=A+B:
print(1*A)
else:
print(1*A-1*(K-A-B))
| 0 | null | 45,981,852,680,928 | 218 | 148 |
master = [(mark, number) for mark in ['S', 'H', 'C', 'D'] for number in range(1, 14)]
n = int(input())
cards = set()
for x in range(n):
mark, number = input().split()
cards.add((mark, int(number)))
lack = sorted((set(master) - cards), key = master.index)
for x in lack:
print('%s %d' % x)
|
cards = {
'S':[r for r in range(1,13+1)],
'H':[r for r in range(1,13+1)],
'C':[r for r in range(1,13+1)],
'D':[r for r in range(1,13+1)]
}
n = int(input())
for nc in range(n):
(s,r) = input().split()
index = cards[s].index(int(r))
del cards[s][index]
for s in ['S','H','C','D']:
for r in cards[s]:
print(s,r)
| 1 | 1,051,185,820,620 | null | 54 | 54 |
list = map(int, raw_input().split())
print list[0] / list[1], list[0] % list[1], "%.5f" %(1.0*list[0] / list[1])
|
cards=input()
new=cards.split()
a=int(new[0])
b=int(new[1])
c=int(new[2])
k=int(new[3])
if a>k:
print(k)
else:
if a+b>k:
print(a)
else:
sum=a+(k-(a+b))*(-1)
print(sum)
| 0 | null | 11,184,411,649,628 | 45 | 148 |
n=int(input())
llist=list(map(int,input().split()))
ans=0
for i in range(n):
for j in range(n-i-1):
for k in range(n-i-j-2):
ii=llist[i]
ji=llist[i+j+1]
ki=llist[i+j+k+2]
if ji != ii and ji != ki and ii != ki:
if max(ii,ji,ki)*2 < ji+ii+ki:
ans+=1
print(ans)
|
import math
import sys
readline = sys.stdin.readline
def main():
n = int(readline().rstrip())
A = list(map(int, readline().rstrip().split()))
cnt = 0
for a in range(n):
if ((a + 1) * A[a]) % 2 == 1:
cnt += 1
print(cnt)
if __name__ == '__main__':
main()
| 0 | null | 6,378,325,556,680 | 91 | 105 |
n = int(input())
xy = [list(map(int,input().split())) for i in range(n)]
cheby = []
for i in range(n):
l = [xy[i][0]-xy[i][1],xy[i][0]+xy[i][1]]
cheby.append(l)
xmax = -10**10
xmin = 10**10
ymax = -10**10
ymin = 10**10
for i in range(n):
if cheby[i][0] > xmax :
xmax = cheby[i][0]
xa = i
if cheby[i][0] < xmin :
xmin = cheby[i][0]
xi = i
if cheby[i][1] > ymax :
ymax = cheby[i][1]
ya = i
if cheby[i][1] < ymin :
ymin = cheby[i][1]
yi = i
if abs(xmax-xmin) > abs(ymax-ymin):
print(abs(xy[xa][0]-xy[xi][0])+abs(xy[xa][1]-xy[xi][1]))
else :
print(abs(xy[ya][0]-xy[yi][0])+abs(xy[ya][1]-xy[yi][1]))
|
N=int(input())
A=[]
B=[]
for _ in range(N):
x,y=map(int, input().split())
A.append(x+y)
B.append(x-y)
A=sorted(A)
B=sorted(B)
print(max(A[-1]-A[0],B[-1]-A[0],A[-1]-A[0],B[-1]-B[0]))
| 1 | 3,442,206,599,552 | null | 80 | 80 |
A = input()
if A[2]==A[3] and A[4]==A[5]:
print('Yes')
else:
print('No')
|
x = list(input())
print('Yes' if x[2]==x[3] and x[4]==x[5] else 'No')
| 1 | 41,816,550,072,996 | null | 184 | 184 |
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))
n,m=nii()
print('Yes' if n==m else 'No')
|
print((lambda x:'Yes' if x[0] == x[1] else 'No')(input().split()))
| 1 | 83,199,608,656,522 | null | 231 | 231 |
def getResult(a,b):
if a<b:
a,b=b,a
while b!=0:
r = a%b
a = b
b = r
return a
a,b = map(int,input().strip().split())
print(getResult(a,b))
|
a = input()
N = len(a)
c = []
temp = int(1)
ans = int(0)
for i in range(N):
if i != N-1:
if a[i] == a[i+1]:
temp += 1
else:
c.append(temp)
temp = 1
else:
if a[i-1] == a[i]:
c.append(temp)
else:
c.append(1)
clen = len(c)
if a[0] == "<" and clen % 2 == 1:
c.append(0)
elif a[0] == ">" and clen % 2 == 0:
c.append(0)
if a[0] == "<":
for i in range(0,clen,2):
maxi = max([c[i],c[i+1]])
mini = min([c[i],c[i+1]])
ans += maxi*(maxi+1)/2
ans += mini*(mini-1)/2
else:
ans += c[0]*(c[0]+1)/2
for i in range(1,clen,2):
maxi = max([c[i],c[i+1]])
mini = min([c[i],c[i+1]])
ans += maxi*(maxi+1)/2
ans += mini*(mini-1)/2
print(int(ans))
| 0 | null | 78,500,009,412,890 | 11 | 285 |
D=int(input())
c = [int(i) for i in input().split()]
s=[]
for i in range(D):
s.append([int(j) for j in input().split()])
t=[0] * D
for i in range(D):
t[i] = int(input())
tst = [0] * 26
last = [0] * 26
for i,j in enumerate(t):
tst[j-1] += s[i][j-1]
last[j-1] = i+1
for k in range(26):
if k != j-1:
tst[k] -= (i+1 - last[k])*c[k]
print(sum(tst))
|
N = 26
D = int(input())
C = [int(i) for i in input().split()]
S = []
for i in range(D):
s = [int(i) for i in input().split()]
S.append(s)
SUM = 0
L = [0] * 26
T = []
for i in range(D):
t = int(input())
T.append(t-1)
for i in range(D):
d = i + 1
for j in range(N):
if j == T[i]:
SUM += S[i][j]
L[j] = d
else:
SUM -= C[j] * (d - L[j])
else:
print(SUM)
| 1 | 9,944,517,031,768 | null | 114 | 114 |
import itertools
def solve():
N = int(input())
S = input()
l = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
p = itertools.product(l,repeat=3)
count = 0
for v in p:
S_temp = S
dig_0_index = S_temp.find(v[0])
if dig_0_index != -1:
S_temp = S_temp[dig_0_index+1::]
dig_1_index = S_temp.find(v[1])
if dig_1_index != -1:
S_temp = S_temp[dig_1_index+1::]
dig_2_index = S_temp.find(v[2])
if dig_2_index != -1:
count += 1
print(count)
if __name__ == "__main__":
solve()
|
x = int(input())
a = x // 500
b = x % 500 // 5
print(a*1000 + b*5)
| 0 | null | 85,838,415,064,740 | 267 | 185 |
n=int(input())
s=input()
mid=n//2
if(s[:mid]==s[mid:]):
print("Yes")
else:
print("No")
|
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):
return self.fact(n)
def fact(self, n):
''' n! % mod '''
if n >= self.mod:
return 0
self._make(n)
return self._factorial[n]
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 fact_inv(self, n):
''' n!^-1 % mod '''
if n >= self.mod:
raise ValueError('Modinv is not exist! arg={}'.format(n))
if self._size_inv < n+1:
self._factorial_inv += [-1] * (n+1-self._size_inv)
self._size_inv = n+1
if self._factorial_inv[n] == -1:
self._factorial_inv[n] = self.modinv(self.fact(n))
return self._factorial_inv[n]
def _make_inv(self, n, r=2):
if n >= self.mod:
n = self.mod - 1
if self._size_inv < n+1:
self._factorial_inv += [-1] * (n+1-self._size_inv)
self._size_inv = n+1
self._factorial_inv[n] = self.modinv(self.fact(n))
for i in range(n, r, -1):
self._factorial_inv[i-1] = self._factorial_inv[i]*i % self.mod
@staticmethod
def xgcd(a, b):
'''
Return (gcd(a, b), x, y) such that a*x + b*y = 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 comb(self, n, r):
''' nCr % mod '''
if r > n:
return 0
t = self(n)*self.fact_inv(n-r) % self.mod
return t*self.fact_inv(r) % self.mod
def comb_(self, n, r):
'''
nCr % mod
when r is not large and n is too large
'''
c = 1
for i in range(1, r+1):
c *= (n-i+1) * self.fact_inv(i)
c %= self.mod
return c
def comb_with_repetition(self, n, r):
''' nHr % mod '''
t = self(n+r-1)*self.fact_inv(n-1) % self.mod
return t*self.fact_inv(r) % self.mod
def perm(self, n, r):
''' nPr % mod '''
if r > n:
return 0
return self(n)*self.fact_inv(n-r) % self.mod
n, m, k = map(int, input().split())
mod = 998244353
f = Factorial(mod)
f._make_inv(n-1)
comb = f.comb
s = 0
for i in range(k+1, n):
t = comb(n-1, i)*m % mod
t = t*pow(m-1, n-1-i, mod) % mod
s = (s+t) % mod
ans = (pow(m, n, mod)-s) % mod
print(ans)
| 0 | null | 84,637,256,282,258 | 279 | 151 |
import sys
data = sys.stdin.readline().strip().split(' ')
a = int(data[0])
b = int(data[1])
print('%d %d %.5f' % (a // b, a % b, a / b))
|
a,b = map(int,input().split())
print(a//b,a%b,"{:.5f}".format(a/b))
| 1 | 603,420,164,798 | null | 45 | 45 |
import math
import sys
input = sys.stdin.readline
def isPrime(n):
i = 2
flag = True
while i * i <= n:
if n % i == 0:
flag = False
break
else:
i += 1
return flag
x = int(input())
while True:
if isPrime(x):
print(x)
break
else:
x += 1
|
class Dice:
def __init__(self):
self.faces=[]
def rotate(self, direction):
tmp = self.faces.copy()
if direction =="N":
self.faces[5-1] = tmp[1-1]
self.faces[1-1] = tmp[2-1]
self.faces[2-1] = tmp[6-1]
self.faces[6-1] = tmp[5-1]
if direction =="S":
self.faces[5-1] = tmp[6-1]
self.faces[1-1] = tmp[5-1]
self.faces[2-1] = tmp[1-1]
self.faces[6-1] = tmp[2-1]
if direction =="W":
self.faces[4-1] = tmp[1-1]
self.faces[1-1] = tmp[3-1]
self.faces[3-1] = tmp[6-1]
self.faces[6-1] = tmp[4-1]
if direction =="E":
self.faces[3-1] = tmp[1-1]
self.faces[1-1] = tmp[4-1]
self.faces[4-1] = tmp[6-1]
self.faces[6-1] = tmp[3-1]
return 0
def spin(self):
self.faces[4-1], self.faces[2-1],self.faces[5-1],self.faces[3-1] =\
self.faces[2-1], self.faces[3-1],self.faces[4-1],self.faces[5-1]
return 0
d1 = Dice()
d1.faces=[int(x) for x in input().split(" ")]
lines = int(input())
for i in range(lines):
up, front = map(int, input().split(" "))
#set up side
for _ in range(3):
if d1.faces[0] == up:
break
d1.rotate("N")
for _ in range(3):
if d1.faces[0] == up:
break
d1.rotate("W")
#set front side
for _ in range(3):
if d1.faces[1] == front:
break
d1.spin()
print(d1.faces[2])
| 0 | null | 53,023,702,839,228 | 250 | 34 |
while True:
m, f, r = map(int, raw_input().split())
if m + f + r == -3: break
if m == -1 or f == -1:
grade = 'F'
elif m + f >= 80:
grade = 'A'
elif m + f >= 65:
grade = 'B'
elif m + f >= 50:
grade = 'C'
elif m + f >= 30:
grade = 'C' if r >= 50 else 'D'
elif m + f < 30:
grade = 'F'
print grade
|
while True:
i,e,r = map(int,raw_input().split())
if i == e == r == -1:
break
if i == -1 or e == -1 :
print 'F'
elif i+e >= 80 :
print 'A'
elif i+e >= 65 :
print 'B'
elif i+e >= 50 :
print 'C'
elif i+e >= 30 :
if r >= 50 :
print 'C'
else :
print 'D'
else :
print 'F'
| 1 | 1,238,920,857,858 | null | 57 | 57 |
def CheckNum(n, x, i):
x = i
if x % 3 == 0:
print(" %d"%(i), end="")
return 2, i, x
return 1, i, x
def Include3(n, x, i):
if x % 10 == 3:
print(" %d"%(i), end="")
return 2, i, x
x = int(x/10)
if x != 0:
return 1, i, x
return 2, i, x
def EndCheckNum(n, x, i):
i += 1
if i <= n:
return 0, i, x
print("")
return 3, i, x
def call(n):
counter = 0
i = 1
x = 1
func = [CheckNum, Include3, EndCheckNum]
while counter != 3:
counter, i, x = func[counter](n, x, i)
n = int(input())
call(n)
|
def Check_Num(n):
for i in range(1,n + 1):
x = i
if (x % 3 == 0):
print(' {}'.format(i),end = '')
continue
elif (x % 10 == 3):
print(' {}'.format(i),end = '')
continue
x //= 10
while (x > 0):
if (x % 10 == 3):
print(' {}'.format(i),end = '')
break
x //= 10
print()
if __name__ == '__main__':
n = int(input())
Check_Num(n)
| 1 | 920,208,390,160 | null | 52 | 52 |
a, b, c, k = (int(i) for i in input().split())
res = 1 * min(a, k) + 0 * min(b, max(0, k - a)) + -1 * min(c, max(0, k - a - b))
print(res)
|
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 14 11:19:14 2020
@author: ezwry
"""
n = int(input())
xy = [map(int, input().split()) for i in range(n)]
x, y = [list(i) for i in zip(*xy)]
"""
A,Bの場合
"""
maxab = x[0] + y[0]
minab = x[0] + y[0]
for i in range(n):
xi = x[i]
yi = y[i]
mini = xi+yi
maxi = xi+yi
if mini < minab:
minab = mini
if maxi > maxab:
maxab = maxi
maxatob = maxab - minab
"""
C,Dの場合
"""
maxcd = y[0]-x[0]
mincd = y[0]-x[0]
for j in range(n):
maxj = y[j] - x[j]
minj = y[j] - x[j]
if maxj > maxcd:
maxcd = maxj
if minj < mincd:
mincd = minj
maxctod = maxcd - mincd
majimax = max(maxatob, maxctod)
print(majimax)
| 0 | null | 12,668,300,687,840 | 148 | 80 |
#!/usr/bin python3
# -*- coding: utf-8 -*-
def main():
mod = 10**9+7
N = int(input())
A = list(map(int, input().split()))
C = [0] * 3
ret = 1
for i in range(N):
ret *= C.count(A[i])
ret %= mod
for j in range(3):
if C[j]==A[i]:
C[j]+=1
break
print(ret)
if __name__ == '__main__':
main()
|
a, b = map(int, input().split())
ans = ''
if a <= b:
for i in range(b):
ans = ans + str(a)
else:
for i in range(a):
ans = ans + str(b)
print(ans)
| 0 | null | 107,305,728,386,308 | 268 | 232 |
h,n=map(int, input().split())
a_list=[int(i) for i in input().split()]
if sum(a_list)>=h:
print("Yes")
else:
print("No")
|
H, N = map(int, input().split())
special_move = input().split()
def answer(H: int, N: int, special_move: list) -> str:
damage = 0
for i in range(0, N):
damage += int(special_move[i])
if damage >= H:
return 'Yes'
else:
return 'No'
print(answer(H, N, special_move))
| 1 | 77,975,521,511,014 | null | 226 | 226 |
n,m=list(map(int, input("").split()))
h=list(map(int, input("").split()))
o=[]
for i in range(n):
o.append(1)
for i in range(m):
a,b=list(map(int, input("").split()))
if h[a-1] <=h[b-1]:
o[a-1]=0
if h[a-1] >=h[b-1]:
o[b-1]=0
print(sum(o))
|
def main():
n, m = map(int, input().split(" "))
ls=[{} for _ in range(n)]
h = list(map(int, input().split(" ")))
for i in range(n):
ls[i] = [h[i]]
ab = []
for i in range(m):
ab.append(list(map(lambda i:int(i)-1, input().split(" "))))
for i in range(m):
if ls[ab[i][0]][0] >= ls[ab[i][1]][0]:
ls[ab[i][1]].append(ls[ab[i][0]][0]+1)
if ls[ab[i][1]][0] >= ls[ab[i][0]][0]:
ls[ab[i][0]].append(ls[ab[i][1]][0] + 1)
cnt = 0
for i in range(n):
if ls[i][0] == max(ls[i]):
cnt += 1
print(cnt)
if __name__ == "__main__":
main()
| 1 | 25,021,377,764,432 | null | 155 | 155 |
N=int(input())
XL=[list(map(int,input().split())) for i in range(N)]
R=[]
for i in range(N):
a=max(0,XL[i][0]-XL[i][1])
b=XL[i][1]+XL[i][0]
R.append([b,a])
R.sort()
ans=0
con_l=0
for i in range(N):
if con_l <= R[i][1]:
ans += 1
con_l = R[i][0]
print(ans)
|
n = int(input())
lr = [] # 各アームの左端と右端の位置のペア
for _ in range(n):
x, l = list(map(int, input().split()))
lr.append((x-l, x+l))
# 右端位置でソート
lr.sort(key=lambda x:x[1])
ans = 0
right = -10**9
for l,r in lr:
# 重なってないなら残す
if l >= right:
ans += 1
right = r
print(ans)
| 1 | 89,560,978,127,670 | null | 237 | 237 |
# 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")
|
n = int(input())
dic = {}
for i in range(n):
inst, c = input().split()
if inst[0] == 'i':
if c in dic:
dic[c] += 1
else:
dic[c] = 0
else:
if c in dic:
print('yes')
else:
print('no')
| 1 | 76,707,855,532 | null | 23 | 23 |
a,b,c = map(int, raw_input().split())
ans = 0
for i in range(c):
num = c % (i + 1)
if num == 0:
if a <= i + 1 and i + 1 <= b:
ans += 1
print ans
|
data = input().split()
a = int(data[0])
b = int(data[1])
c = int(data[2])
divisor = list()
for i in range(a,b+1):
if c % i == 0:
divisor.append(i)
print(str(len(divisor)))
| 1 | 562,038,483,100 | null | 44 | 44 |
n = list(str(input()))
flag = False
for i in range(len(n)):
if n[i] == '7':
flag = True
if flag:
print('Yes')
else:
print('No')
|
while 1:
H, W = map(int, input().split())
if H == 0 and W == 0:
break
print("#"*W)
line = '#' + ('.' * (W - 2)) + '#'
for i in range(0, H - 2):
print(line)
print("#"*W)
print()
| 0 | null | 17,478,047,811,950 | 172 | 50 |
n,ms = map(int, input().split())
a = [list(map(str, input().split())) for _ in range(n)]
total = 0
for i in a:
tmp = int(i[1]) - ms
if tmp <= 0:
total += ms + tmp
print("{} {}".format(i[0], total))
else:
total += ms
a.append([i[0], tmp])
|
def do_round_robin(process, tq):
from collections import deque
q = deque()
elapsed_time = 0 # ??????????????????????§??????????????????????
finished_process = [] # ????????????????????????????????????????????¨??????????????????????????§?????????
# ?????\?????????????????????????????????
for process_name, remaining_time in process:
q.append([process_name, int(remaining_time)])
while True:
try:
process_name, remaining_time = q.pop()
except IndexError: # ??????????????£???????????????????????????????????£???
break
else:
elapsed_time += min(remaining_time, tq)
remaining_time -= tq
if remaining_time > 0:
q.appendleft([process_name, remaining_time])
else:
finished_process.append((process_name, elapsed_time))
return finished_process
if __name__ == '__main__':
# ??????????????\???
# ????????????????????????????????????????????????????°??????????????????????????????¨
data = [int(x) for x in input().split(' ')]
num_of_process = data[0]
time_quantum = data[1]
process = []
for i in range(num_of_process):
process.insert(0, [x for x in input().split(' ')])
# ??????
results = do_round_robin(process, time_quantum)
# ???????????????
for i in results:
print('{0} {1}'.format(i[0], i[1]))
| 1 | 42,352,625,150 | null | 19 | 19 |
class Stack():
def __init__(self):
self.stack = [0 for _ in range(200)]
self.top = 0
def isEmpty(self):
return self.top == 0
def isFull(self):
return self.top >= len(self.stack) - 1
def push(self, x):
if self.isFull():
print "error"
return exit()
self.top += 1
self.stack[self.top] = x
def pop(self):
if self.isEmpty():
print "error"
return exit()
a = self.stack[self.top]
del self.stack[self.top]
self.top -= 1
return a
def lol(self):
return self.stack[self.top]
def main():
st = Stack()
data = raw_input().split()
for i in data:
if i == '+':
b = int(st.pop())
a = int(st.pop())
st.push(a + b)
elif i == '-':
b = int(st.pop())
a = int(st.pop())
st.push(a - b)
elif i == '*':
b = int(st.pop())
a = int(st.pop())
st.push(a * b)
else:
st.push(i)
print st.lol()
if __name__ == '__main__':
main()
|
array = input().split()
stack = []
while True:
if len(array) == 0: break
e = array.pop(0)
if e.isdigit():
stack.append(e)
else:
num1 = stack.pop()
num2 = stack.pop()
stack.append(str(eval(num2 + e + num1)))
print(stack[0])
| 1 | 35,437,139,920 | null | 18 | 18 |
r = int(input())
print( 2 * 3.14159268 * r )
|
import math
R=int(input())
l=2*math.pi*R
print(l)
| 1 | 31,306,393,222,390 | null | 167 | 167 |
a,b = map(int, input().split())
S = 0
for i in range(max(a,b)):
S +=min(a,b)*(10**i)
print(S)
|
a, b = input().split()
print(sorted([a*int(b), b*int(a)])[0])
| 1 | 84,154,308,104,620 | null | 232 | 232 |
S = input()
L = S.split()
a = L[0]
b = L[1]
c = L[2]
a = int(a)
b = int(b)
c = int(c)
if a < b < c:
print('Yes')
else :
print('No')
|
N=int(input())
Xlist=list(map(int,input().split()))
ans=10**18
for p in range(1,101):
ans=min(ans,sum(list(map(lambda x:(p-x)**2,Xlist))))
print(ans)
| 0 | null | 32,691,981,467,132 | 39 | 213 |
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
n, k, *p = map(int, read().split())
p.sort()
r = sum(p[:k])
print(r)
if __name__ == '__main__':
main()
|
N, K = map(int, input().split())
p = list(map(int, input().split()))
p.sort()
print(sum(p[:K]))
| 1 | 11,532,310,672,312 | null | 120 | 120 |
N = int(input())
taro_p = hana_p = 0
for n in range(N):
tw,hw = input().split()
if tw == hw:
taro_p += 1
hana_p += 1
elif tw < hw:
hana_p += 3
else :
taro_p += 3
print(taro_p,hana_p)
|
def cardgame(animal1, animal2, taro, hanako):
if animal1==animal2:
return [taro+1, hanako+1]
anim_list = sorted([animal1, animal2])
if anim_list[0]==animal1:
return [taro, hanako+3]
else:
return [taro+3, hanako]
n = int(input())
taro, hanako = 0, 0
for i in range(n):
data = input().split()
result = cardgame(data[0], data[1], taro, hanako)
taro, hanako = result[0], result[1]
print(taro, end=" ")
print(hanako)
| 1 | 2,012,645,979,388 | null | 67 | 67 |
a, b, c, k = map(int, input().split())
ans = 0
if a >= k:
ans += k
k = 0
else:
ans += a
k -= a
if b >= k:
k = 0
else:
k -= b
if c >= k:
ans -= k
print(ans)
|
class Cmb:
g1=[1,1]
g2=[1,1]
inv=[0,1]
def __init__(self,mod,upper_limit):
self.mod=mod
for i in range(2,upper_limit+1):
Cmb.g1.append(Cmb.g1[-1]*i%mod)
Cmb.inv.append(-Cmb.inv[mod%i]*(mod//i)%mod)
Cmb.g2.append(Cmb.g2[-1]*Cmb.inv[-1]%mod)
def cmb(self,n,r):
if r<0 or n<r:
return 0
r=min(r,n-r)
return Cmb.g1[n]*Cmb.g2[r]*Cmb.g2[n-r]%self.mod
k=int(input())
s=len(input())
mod=10**9+7
Cmb=Cmb(mod,k+s)
ans=1
for i in range(1,k+1):
ans=(ans*26+Cmb.cmb(i+s-1,s-1)*pow(25,i,mod))%mod
print(ans)
| 0 | null | 17,440,372,490,652 | 148 | 124 |
m1,d1=map(int,input().split())
m2,d2=map(int,input().split())
if m1!=m2:
print(1)
else:print(0)
|
n = int(input())
l = sorted(list(map(int,input().split())))
ans = 0
for ai in range(n):
for bi in range(ai+1,n):
ok,ng = bi,n
while ng-ok>1:
mid = (ng+ok)//2
if l[mid]<l[ai]+l[bi]:
ok = mid
else:
ng = mid
ans += ok-bi
print(ans)
| 0 | null | 148,256,547,908,770 | 264 | 294 |
N, K = map(int, input().split())
N += 1
ans = 0
p = 10 ** 9 + 7
for k in range(K, N + 1):
ans += (k * (N - k) + 1) % p
ans %= p
print(ans)
|
X=int(input())
cnt=0
for i in range(1,10**7):
cnt+=X
if cnt%360==0:
print(i)
break
| 0 | null | 23,250,918,742,590 | 170 | 125 |
S=input()
result=0
count=0
for i in S:
if i == "R":
count+=1
if count>result:
result=count
else:
count=0
print(result)
|
N=int(input())
A=list(map(int,input().split()))
for i in range(N):
A[i]=[A[i],i]
A.sort()
for i in range(N):
print(A[i][1]+1,end=' ')
print()
| 0 | null | 92,460,650,650,680 | 90 | 299 |
N = int(input())
A = list(map(int, input().split()))
B = [i for i in A if i % 2 == 0]
o = 'APPROVED'
for i in B:
if i % 3 != 0 and i % 5 != 0:
o = 'DENIED'
break
print(o)
|
a,b,n = list(map(int,input().split()))
i = min(n,b-1)
print(a*i//b)
| 0 | null | 48,461,218,582,060 | 217 | 161 |
n, k = map(int, input().split())
h = list(map(int, input().split()))
h.sort(reverse=True)
ans = 0
for i in range(k, n): ans += h[i]
print(ans)
|
from collections import deque
n, m = map(int, input().split())
way = {}
for i in range(m):
a, b = map(int, input().split())
if a not in way:
way[a] = []
if b not in way:
way[b] = []
way[a].append(b)
way[b].append(a)
queue = deque([1])
ok = set([1])
ans = [0] * (n+1)
while queue:
now = queue.popleft()
for i in way[now]:
if i in ok:
continue
ans[i] = now
queue.append(i)
ok.add(i)
print("Yes")
for i in range(2, n+1):
print(ans[i])
| 0 | null | 49,716,369,577,112 | 227 | 145 |
import sys
a = sys.stdin.read()
alphabet = "abcdefghijklmnopqrstuvwxyz"
for i in alphabet:
print(i + " : " + str(a.lower().count(i)) )
|
num_limit = int(input())
num_list = [0] * num_limit
j_limit = int(num_limit ** 0.5)
for j in range(1,j_limit+1):
for k in range(1,j + 1):
for l in range(1,k+1):
if num_limit >= j**2 + k**2 + l**2 + j*k + k*l + l*j:
if j > k:
if k > l:
num_list[j**2 + k**2 + l**2 + j*k + k*l + l*j-1] += 6
else:
num_list[j**2 + k**2 + l**2 + j*k + k*l + l*j-1] += 3
elif k > l:
num_list[j**2 + k**2 + l**2 + j*k + k*l + l*j-1] += 3
else:
num_list[j**2 + k**2 + l**2 + j*k + k*l + l*j-1] += 1
for i in num_list:
print(i)
| 0 | null | 4,842,334,828,748 | 63 | 106 |
# https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_c
from decimal import Decimal
import sys
# sys.setrecursionlimit(100000)
def input():
return sys.stdin.readline().strip()
def input_int():
return int(input())
def input_int_list():
return [int(i) for i in input().split()]
def main():
a, b, c = input_int_list()
sqrt_a = Decimal(a)**Decimal("0.5")
sqrt_b = Decimal(b)**Decimal("0.5")
sqrt_c = Decimal(c)**Decimal("0.5")
if sqrt_a + sqrt_b < sqrt_c:
print("Yes")
else:
print("No")
return
if __name__ == "__main__":
main()
|
A11, A12, A13 = map(int, input().split())
A21, A22, A23 = map(int, input().split())
A31, A32, A33 = map(int, input().split())
N = int(input())
B = {int(input()) for _ in range(N)}
h1 = {A11, A12, A13}
h2 = {A21, A22, A23}
h3 = {A31, A32, A33}
v1 = {A11, A21, A31}
v2 = {A12, A22, A32}
v3 = {A13, A23, A33}
c1 = {A11, A22, A33}
c2 = {A13, A22, A31}
if len(h1 & B)==3 or len(h2 & B)==3 or len(h3 & B)==3 or len(v1 & B)==3 or len(v2 & B)==3 or len(v3 & B)==3 or len(c1 & B)==3 or len(c2 & B)==3:
print("Yes")
else:
print("No")
| 0 | null | 55,592,714,721,038 | 197 | 207 |
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 998244353
inf = float("INF")
#solve
def solve():
n, s = LI()
a = LI()
dp = [[0] * (3001) for _ in range(n)]
dp[0][0] = 1
dp[0][a[0]] = 1
ans = 0
for i in range(1, n):
for si in range(a[i], 3001):
dp[i][si] = dp[i - 1][si - a[i]] % mod
dp[i][0] += 1
dp[i][a[i]] += 1
for si in range(3001):
dp[i][si] = (dp[i][si] + dp[i - 1][si] * 2) % mod
ans += dp[i][s]
print(dp[-1][s] % mod)
return
#main
if __name__ == '__main__':
solve()
|
a,b,m=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
l=[list(map(int,input().split())) for _ in range(m)]
ans=min(a)+min(b)
for x,y,c in l:
ans=min(ans,a[x-1]+b[y-1]-c)
print(ans)
| 0 | null | 35,634,602,429,988 | 138 | 200 |
s = str(input())
if s[-1]==s[-2] and s[-3]==s[-4]:
print('Yes')
else:
print('No')
|
while True:
n = input()
if n == 0: break
print sum(map(int, list(str(n))))
| 0 | null | 21,779,422,846,596 | 184 | 62 |
X = int(input())
# dp[i]:= ちょうどi円となる買い物が存在するorしない
dp = [0] * (X+1)
dp[0] = 1
for i in range(X):
if dp[i] == 1:
for next in [100,101,102,103,104,105]:
if i+next<=X:
dp[i+next] = 1
print(dp[X])
|
x = int(input())
price = [100, 101, 102, 103, 104, 105]
dp = [False for _ in range(x + 1)]
dp[0] = True
for i in range(1, x + 1):
for j in range(6):
if i - price[j] >= 0:
if dp[i - price[j]]:
dp[i] = True
break
else:
dp[i] = False
if dp[x]:
print(1)
else:
print(0)
| 1 | 126,918,436,219,718 | null | 266 | 266 |
while True:
n, x = map(int, input().split())
if n == 0 and x == 0:
break
else:
counter = 0
for a in range(1,(x // 3)):
for c in range ((x//3)+1,n+1):
b = x - a - c
if a < b < c:
counter += 1
print(counter)
|
import sys
while True:
n, x = [ int( val ) for val in sys.stdin.readline().split( " " ) ]
if 0 == n and 0 == x:
break
cnt = 0
for i in range( 1, n-1 ):
if x <= i:
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:
break
print( cnt )
| 1 | 1,263,922,280,010 | null | 58 | 58 |
import sys
MOD = 10**9 + 7
def sum_from_to(fr, to):
return (to - fr + 1) * (fr + to) // 2 % MOD
def main():
input = sys.stdin.buffer.readline
n, k = map(int, input().split())
ans = 0
for i in range(k, n + 2):
ans += sum_from_to(n - i + 1, n) - sum_from_to(0, i - 1) + 1
ans %= MOD
print(ans)
if __name__ == '__main__':
main()
|
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
n,k = map(int, input().split())
mod = 10**9+7
ans = 0
for i in range(k, n + 2):
mi = (i - 1) * i // 2
ma = (n + n - i + 1) * i // 2
ans += ma - mi + 1
print(ans % mod)
| 1 | 33,371,918,569,948 | null | 170 | 170 |
n, k = map(int, input().split())
a_i = list(map(int, input().split()))
def f(n):
cnt = 0
for a in a_i:
cnt += (a - 1) // n
if cnt > k: return False
else: return True
l, r = 0, max(a_i)
while True:
if r - l <= 1: break
val = (l + r) // 2
if f(val) == True: r = val
else: l = val
print(r)
|
import math
n,k=map(int,input().split())
A=list(map(int,input().split()))
low=1
high=max(A)
while low!=high:
mid=(low+high)//2
s=0
for i in range(n):
s+=math.ceil(A[i]/mid)-1
if s>k:
low=mid+1
else:
high=mid
print(low)
| 1 | 6,572,038,761,692 | null | 99 | 99 |
'''
'''
INF = float('inf')
def main():
H, W, K = map(int, input().split())
S = [input() for _ in range(H)]
S = [''.join(S[row][col] for row in range(H)) for col in range(W)]
ans = INF
for b in range(0, 2**H, 2):
sections = [(0, H)]
for shift in range(1, H):
if (1<<shift) & b:
sections.append((sections.pop()[0], shift))
sections.append((shift, H))
t_ans = len(sections) - 1
count = {(l, r): 0 for l, r in sections}
for col in range(W):
if any(count[(l, r)] + S[col][l:r].count('1') > K for l, r in sections):
for key in count.keys():
count[key] = 0
t_ans += 1
for l, r in sections:
count[(l, r)] += S[col][l:r].count('1')
if max(count.values()) > K:
t_ans = INF
break
ans = min(ans, t_ans)
print(ans)
main()
|
def func(x):
return x + x**2 + x**3
if __name__=="__main__":
input = input()
print(func(int(input)))
| 0 | null | 29,527,287,001,010 | 193 | 115 |
import math
while True:
n = int(input())
if(n == 0):
exit()
else:
s = [int(x) for x in input().split()]
m = sum(s)/len(s)
for i in range(n):
s [i] = (s[i] - m)**2
print("%.5f" % (math.sqrt(sum(s)/len(s))))
|
import sys
input = sys.stdin.readline
n=int(input())
L=list(map(int,input().split()))
if len(set(L))!=n:
print('NO')
else:
print('YES')
| 0 | null | 36,971,447,016,208 | 31 | 222 |
S = raw_input().split(" ")
for i in range(0, len(S)):
S[i] = int(S[i])
primeNum = 0
for i in range(S[0], S[1]+1):
if(S[2] % i == 0):
primeNum = primeNum+1
print(primeNum)
|
ins = input().split()
a = int(ins[0])
b = int(ins[1])
c = int(ins[2])
print(len([x for x in list(range(a, b + 1)) if c % x == 0]))
| 1 | 568,654,105,870 | null | 44 | 44 |
while True:
table=str(input())
if table[0] == '0':
break
print(sum(int(num) for num in(table)))
|
N = int(input())
S = input()
judge = [1]*N
for i in range(1,N):
if S[i-1] == S[i]:
judge[i] = 0
print(sum(judge))
| 0 | null | 85,853,456,825,290 | 62 | 293 |
N = int(input())
result = 0
for i in range(1, (N + 1)):
if i % 15 == 0:
'Fizz Buzz'
elif i % 3 == 0:
'Fizz'
elif i % 5 == 0:
'Buzz'
else:
result = result + i
print(result)
|
N = int(input())
sum = 0
if (1 <= N and N <= 10 ** 6):
for i in range(1,N + 1):
if ( i % 3 == 0) and ( i % 5 == 0):
#if i % 15 ==0:
N = 'Fizz Buzz'
elif i % 3 == 0:
N = 'Fizz'
elif i % 5 == 0:
N = 'Buzz'
else:
sum += i
print(sum)
| 1 | 34,852,711,986,300 | null | 173 | 173 |
d=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for _ in range(d)]
C=sum(c)
tot=0
mem=[0]*26
for i in range(d):
t=int(input())
mem[t-1]=i+1
tot+=s[i][t-1]
for j in range(26):
tot-=c[j]*((i+1)-mem[j])
print(tot)
|
D = int(input())
cs = list(map(int, input().split()))
ss = [input().split() for l in range(D)]
ts = [int(input()) for i in range(D)]
ans=0
all_cs=sum(cs)
cs_last=[0]*26
def c0(d):
mainas=0
for i in range(26):
#print(cs[i]*(d-cs_last[i]))
mainas-=cs[i]*(d-cs_last[i])
return mainas
for i in range(D):
cs_last[ts[i]-1]=i+1
ans+=int(ss[i][ts[i]-1])+c0(i+1)
print(ans)
| 1 | 9,914,785,640,750 | null | 114 | 114 |
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
n,m = inpm()
way = [[] for _ in range(n+1)]
for i in range(m):
a,b = inpm()
way[a].append(b)
way[b].append(a)
ans = [0 for i in range(n+1)]
q = queue.Queue()
q.put((1,0))
while not q.empty():
room,sign = q.get()
if ans[room] != 0:
continue
ans[room] = sign
for i in way[room]:
q.put((i,room))
print('Yes')
for i in range(2,n+1):
print(ans[i])
|
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
# from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum # accumulate
def solve():
N, M = MI()
E = [[] for _ in range(N)]
for i in range(M):
a, b = MI1()
E[a].append(b)
E[b].append(a)
q = deque([0])
used = [0] * N
used[0] = 1
ans = [0] * N
ans[0] = 'Yes'
while q:
v = q.popleft()
for nv in E[v]:
if used[nv]: continue
used[nv] = 1
ans[nv] = v+1
q.append(nv)
printlist(ans, '\n')
if __name__ == '__main__':
solve()
| 1 | 20,374,553,540,352 | null | 145 | 145 |
import sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF = 10**20
MOD = 1000000007
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def resolve():
N = I()
A = LI()
# color_number[i][j]: [0, i)でj番目に多い色の人数
color_number = [[0, 0, 0] for _ in range(N)]
for i in range(N-1):
if A[i] in color_number[i]:
idx = color_number[i].index(A[i])
else:
idx = -1
for j in range(3):
if j==idx:
color_number[i+1][j] = color_number[i][j] + 1
else:
color_number[i+1][j] = color_number[i][j]
ans = 1
for i in range(N):
ans *= color_number[i].count(A[i])
ans %= MOD
print(ans)
if __name__ == '__main__':
resolve()
|
import sys
# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue
# import numpy as np
sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353
ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
# ===CODE===
def main():
s = input()
cnt = [0 for _ in range(2019)]
cnt[0] += 1
dec = 1
num = 0
for i in reversed(s):
num += int(i) * dec
num %= 2019
dec *= 10
dec %= 2019
cnt[num] += 1
ans = 0
for c in cnt:
ans += c * (c - 1) // 2
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 80,237,440,208,868 | 268 | 166 |
def calc_max_profit(data):
"""
http://judge.u-aizu.ac.jp/onlinejudge/commentary.jsp?id=ALDS1_1_D
:param data: ??????????????????
:return:
"""
maxv = data[1] - data[0]
minv = data[0]
for j in range(1, len(data)):
maxv = max(maxv, data[j] - minv)
minv = min(minv, data[j])
return maxv
if __name__ == '__main__':
# ???????????\???
num = int(input())
data = []
for i in range(num):
data.append(int(input()))
# data = [5, 3, 1, 3, 4, 3]
# data = [4, 3, 2]
# ??????
result = calc_max_profit(data)
# ???????????????
print('{0}'.format(result))
|
N = int(input())
A = list(map(int, input().split()))
dct = dict(enumerate(A))
ad = sorted(dct.items(), key=lambda x:x[1])
ans = []
for i in ad:
j = i[0] + 1
ans.append(j)
a = map(str, ans)
b = ' '.join(a)
print(b)
| 0 | null | 90,452,623,706,810 | 13 | 299 |
# モンスターの体力H
# アライグマの必殺技の種類N
# i番目の必殺技使うと、モンスターの体力Ai減らせる
# H - (A1 + A2 + A3...) <= 0 となるなら 'Yes',
# ならないなら'No'が出力される
h, n = map(int, input().split())
damage = list(map(int, input().split()))
if h - sum(damage) <= 0:
print("Yes")
else:
print("No")
|
s = input()
k = int(input())
if len(set(s)) == 1:
print(len(s) * k // 2)
exit()
s += "🐧"
wow = 0
yeah = []
for i in range(len(s)-1):
if s[i] != s[i+1]:
wow += 1
yeah.append((s[i], wow))
wow = 0
else:
wow += 1
ans = sum(c // 2 for _, c in yeah) * k
if s[0] == s[-2]:
katakuna = yeah[0][1]
ijippari = yeah[-1][1]
te = katakuna // 2 + ijippari // 2 - (katakuna + ijippari) // 2
ans -= te * (k - 1)
print(ans)
| 0 | null | 126,425,012,045,860 | 226 | 296 |
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)
|
import sys
import math
def MI(): return map(int,sys.stdin.readline().rstrip().split())
N,X,M = MI()
if M == 1:
print(0)
exit()
flag = [-1]*M
Z = [X]
flag[X] = 1
r = X
for i in range(2,M+2):
r = r ** 2
r %= M
if flag[r] != -1:
a,b = flag[r],i # [a,b) = 循環節
break
else:
flag[r] = i
Z.append(r)
z = len(Z)
ans = 0
for i in range(a-1):
ans += Z[i]
n = N-a+1
q = n//(b-a)
r = n % (b-a)
for i in range(a-1,a+r-1):
ans += (q+1)*Z[i]
for i in range(a+r-1,b-1):
ans += q*Z[i]
print(ans)
| 1 | 2,867,827,166,062 | null | 75 | 75 |
x = input()
if x == x.upper():
print("A")
else:
print("a")
|
N = int(input())
print(N//2 if N%2==0 else N//2+1)
| 0 | null | 35,032,968,527,224 | 119 | 206 |
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
m=[list(map(int,input().split())) for _ in range(M)]
min_a=min(a)
min_b=min(b)
min_cost=min_a+min_b
for _m in m:
cost=a[_m[0]-1]+b[_m[1]-1]-_m[2]
min_cost=min(min_cost,cost)
print(min_cost)
|
import math
from numba import jit
k=int(input())
@jit
def f():
ans=0
for a in range(1,k+1):
for b in range(1,k+1):
for c in range(1,k+1):
g=math.gcd(math.gcd(a,b),c)
ans+=g
return ans
print(f())
| 0 | null | 44,583,507,601,920 | 200 | 174 |
S = input()
if(S[len(S)-1] == 's'):print(S + 'es')
else :print(S + 's')
|
n = int(input())
x = 7
ans = 1
#print(7%1)
for i in range(3*n):
if x%n==0:
break
ans+=1
x= x*10 + 7
x=x%n
if ans < 3*n:
print(ans)
else:
print(-1)
| 0 | null | 4,205,424,755,920 | 71 | 97 |
while 1:
a = input()
if a == '-':
break
n = int(input())
for i in range(n):
h = int(input())
a = a[h:] + a[:h]
print(a)
|
import sys
def gcd(a,b):
if b == 0: return a
else: return gcd(b,a%b)
for i in sys.stdin:
a, b = map(int, i.split())
g = gcd(a,b)
print g, a/g*b
| 0 | null | 969,461,974,602 | 66 | 5 |
import math
x1,y1,x2,y2=[float(x) for x in input().split(' ')]
dis=math.sqrt((y2 - y1)**2 + (x2-x1)**2)
print("{:.4f}".format(dis))
|
n, a, b = map(int, input().split())
red = 0 ; blue = 0
if n >= a + b :
stack = n // (a+b)
red += b * stack
blue += a * stack
n -= (a+b) * stack
if n > a :
n -= a
blue += a
else :
blue += n
if n > b :
n -= b
red += b
else :
red += n
print(blue)
| 0 | null | 28,049,492,492,120 | 29 | 202 |
import sys
sys.setrecursionlimit(2147483647)
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
input = lambda:sys.stdin.readline().rstrip()
class SegmentTree(object):
def __init__(self, A, dot, unit):
n = 1 << (len(A) - 1).bit_length()
tree = [unit] * (2 * n)
for i, v in enumerate(A):
tree[i + n] = v
for i in range(n - 1, 0, -1):
tree[i] = dot(tree[i << 1], tree[i << 1 | 1])
self._n = n
self._tree = tree
self._dot = dot
self._unit = unit
def __getitem__(self, i):
return self._tree[i + self._n]
def update(self, i, v):
i += self._n
self._tree[i] = v
while i != 1:
i >>= 1
self._tree[i] = self._dot(self._tree[i << 1], self._tree[i << 1 | 1])
def add(self, i, v):
self.update(i, self[i] + v)
def sum(self, l, r):
l += self._n
r += self._n
l_val = r_val = self._unit
while l < r:
if l & 1:
l_val = self._dot(l_val, self._tree[l])
l += 1
if r & 1:
r -= 1
r_val = self._dot(self._tree[r], r_val)
l >>= 1
r >>= 1
return self._dot(l_val, r_val)
def resolve():
n = int(input())
trees = [[0] * n for _ in range(26)]
character = [None] * n
for i, c in enumerate(input()):
c = ord(c) - ord('a')
character[i] = c
trees[c][i] = 1
for i in range(26):
trees[i] = SegmentTree(trees[i], max, 0)
for _ in range(int(input())):
q, *A = input().split()
if q == '1':
i, c = A
i = int(i) - 1
c = ord(c) - ord('a')
trees[character[i]].update(i, 0)
character[i] = c
trees[c].update(i, 1)
else:
l, r = map(int, A)
l -= 1
print(sum(trees[i].sum(l, r) for i in range(26)))
resolve()
|
n = int(input())
a = [int(i) for i in input().split()]
s = 0
for i in a:
s ^= i
for i in a:
print(s^i,end = ' ')
| 0 | null | 37,496,422,617,408 | 210 | 123 |
T1, T2 = map(int,input().split())
A1, A2 = map(int,input().split())
B1, B2 = map(int,input().split())
T = T1*A1+T2*A2
A = T1*B1+T2*B2
if T == A:
print("infinity")
exit()
if T > A:
if A1 > B1:
print(0)
exit()
else:
tdif = T-A #7-5
pdif = T1*(B1-A1) #5
if pdif%tdif == 0:
ans = 2*(pdif//tdif)+1
else:
ans = 2*(1+pdif//tdif)
ans -=1 #原点の分を引く
else:
if B1 > A1:
print(0)
exit()
else:
tdif = A-T #7-5
pdif = T1*(A1-B1) #5
if pdif%tdif == 0:
ans = 2*(pdif//tdif)+1
else:
ans = 2*(1+pdif//tdif)
ans -=1 #原点の分を引く
print(ans)
|
import math
t1,t2 = map(int,(input().split(' ')))
a1,a2 = map(int,(input().split(' ')))
b1,b2 = map(int,(input().split(' ')))
n = t1*a1+t2*a2
m = t1*b1+t2*b2
if(n==m):
print("infinity")
exit(0)
ans1 = max(0,math.ceil((b1-a1)*t1/(n-m)))
ans2 = max(0,math.ceil((t1*(b1-a1)+t2*(b2-a2))/(n-m))-1)
#if((t1*(b1-a1))%(n-m) == 1):
# ans3 = 1
#else:
# ans3 = 0
ans3 = max(0,math.floor(t1*(b1-a1)/(n-m))+1)
print(max(ans1+ans2+ans3-1,0))
| 1 | 131,493,155,147,388 | null | 269 | 269 |
import sys
sys.setrecursionlimit(200001)
N, M = [int(n) for n in input().split()]
S = input()
p1 = False
x1 = 0
m1 = N
c1 = 0
for n in S:
if n == "1":
if p1:
c1 += 1
else:
c1 = 1
p1 = True
else:
p1 = False
if c1 > 0:
if c1 > x1:
x1 = c1
if c1 < m1:
m1 = c1
def rest(l, ans):
s = M
while s > 0:
if s >= l:
ans.append(l)
return ans
if S[l-s] == "1":
if s == 1:
return -1
s -= 1
continue
l -= s
if rest(l, ans) == -1:
s -= 1
else:
ans.append(s)
return ans
return -1
if x1 > M - 1:
ans = -1
else:
ans = rest(N, [])
if ans == -1:
print(-1)
else:
print(" ".join([str(n) for n in ans]))
|
import itertools
n = int(input())
a = [[[0 for _ in range(10)] for _ in range(3)] for _ in range(4)]
for _ in range(n):
b, f, r, v = map(int, input().split())
a[b-1][f-1][r-1] += v
for b in range(4):
for f in range(3):
for r in range(10):
print('', a[b][f][r], end="")
print()
if b < 3:
print("#"*20)
| 0 | null | 69,846,057,238,148 | 274 | 55 |
n,k,c=map(int,input().split()) ; c+=1
s=input()
A=[i+1 for i in range(n) if s[i]=="o"] #働ける日付
L=[1 for i in range(k)] #働く日数[l] はL[l]以降
R=[n for i in range(k)] #L[l]以前
import bisect
for i in range(1,k):
L[i]= A[bisect.bisect_left(A,L[i-1]+c)]
R[-i-1]= A[bisect.bisect_right(A,R[-i]-c)-1]
for i in range(k):
if L[i]==R[i]:
print(L[i])
|
n, k, c = map(int, input().split())
S = input()
# 要素の値は何回目の働く日か(0は働いていない状態)
by_left = [0] * n
by_right = [0] * n
# 左から貪欲
rest = 0
cnt = 1
for itr, s in enumerate(S):
rest -= 1
if rest <= 0 and s == "o":
by_left[itr] = cnt
cnt += 1
rest = c + 1
# 右から貪欲
rest = 0
cnt = k
for itr, s in enumerate(S[::-1]):
rest -= 1
if rest <= 0 and s == "o":
by_right[n - itr- 1] = cnt
cnt -= 1
rest = c + 1
# 左右からの貪欲で、どちらでも同じ働く回数の値が入っている日が必ず働く日
ans = [itr + 1 for itr, (i, j) in enumerate(zip(by_left, by_right)) if i != 0 and i == j]
for a in ans:
print(a)
| 1 | 40,966,220,805,148 | null | 182 | 182 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.