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
|
---|---|---|---|---|---|---|
M1,D1=list(map(int, input().split()))
M2,D2=list(map(int, input().split()))
if (M1==M2-1 or M1-M2==11) and D2==1:
print(1)
else:
print(0) | import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor
import numpy as np
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353
M1 , _ = list(map(int, sys.stdin.buffer.readline().split()))
M2 , _ = list(map(int, sys.stdin.buffer.readline().split()))
print((M2 - M1) % 12)
| 1 | 124,589,253,224,872 | null | 264 | 264 |
import sys
n, k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
l, r = 0, max(a)
while r - l > 1:
# satisfy l < t < r
t = (l + r) // 2
c = sum([(e-1) // t for e in a])
if k < c:
l = t
else:
r = t
print(r) | import math
N, K=map(int,input().split())
A=list(map(int,input().split()))
def judge(ans,K,A):
cut=0
for i in range(len(A)):
cut+=(A[i]-1)//ans
if cut>K:
return False
else:
return True
ansp=max(A)
ansm=0
ans=(ansp+ansm)//2
d=1
while ansp-ansm>d:
if judge(ans,K,A):
ansp=ans
else:
ansm=ans
ans=(ansp+ansm)//2
print(ansp) | 1 | 6,511,462,704,868 | null | 99 | 99 |
N = int(input())
S = input().split("ABC")
print(len(S)-1) | import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
K, N = mapint()
As = list(mapint())
lis = []
for i in range(1, N):
lis.append(As[i]-As[i-1])
lis.append(As[0]+(K-As[-1]))
print(K-max(lis)) | 0 | null | 71,507,982,623,830 | 245 | 186 |
n = input()
if (sum(map(int, n))) % 9 == 0:
print("Yes")
else:
print("No") | def main():
S = input()
if S == "ABC":
print("ARC")
else:
print("ABC")
main()
| 0 | null | 14,212,252,180,928 | 87 | 153 |
s = input()
s_l = [0] * (len(s) + 1)
s_r = [0] * (len(s) + 1)
for i in range(len(s)):
if s[i] == '<':
s_l[i + 1] = s_l[i] + 1
for i in range(len(s)):
if s[- i - 1] == '>':
s_r[- i - 2] = s_r[- i - 1] + 1
ans = 0
for i, j in zip(s_l, s_r):
ans += max(i, j)
print(ans) | n = int(input())
ara = [input() for _ in range(n)]
pref = []
suff = []
for s in ara:
pos = neg = 0
for ch in s:
if ch == '(':
pos += 1
elif pos == 0:
neg += 1
else:
pos -= 1
if pos >= neg:
pref.append([pos, neg])
else:
suff.append([pos, neg])
pref.sort(key=lambda x: x[1])
suff.sort(key=lambda x: x[0], reverse=True)
totPos = 0
ara = pref + suff
for pos, neg in ara:
if neg > totPos:
print("No")
exit(0)
totPos -= neg
totPos += pos
if totPos != 0:
print("No")
else:
print("Yes")
| 0 | null | 89,795,902,506,318 | 285 | 152 |
# -*- coding: utf-8 -*-
def check(r,g,b):
if g > r and b > g:
return True
else:
return False
A,B,C = map(int, input().split())
K = int(input())
for i in range(K+1):
for j in range(K+1-i):
for k in range(K+1-i-j):
if i+j+k==0:
continue
r = A*(2**i)
g = B*(2**j)
b = C*(2**k)
if check(r, g, b):
print("Yes")
exit()
print("No")
| inp = input()
a = inp.split()
a[0] = int(a[0])
a[1] = int(a[1])
a[2] = int(a[2])
a.sort()
print(a[0],a[1],a[2])
| 0 | null | 3,678,609,215,900 | 101 | 40 |
K,X = map(int, open(0).read().split())
if 500 * K >= X:
print('Yes')
else:
print('No') | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict
from itertools import accumulate
n, k = map(int, readline().split())
a = list(map(lambda x: int(x) - 1, readline().split()))
cumsum = [0] + list(map(lambda x: int(x) % k, list(accumulate(a))))
dict = defaultdict(int)
ans = 0
for i, v in enumerate(cumsum):
ans += dict[v]
dict[v] += 1
if i >= k - 1:
dict[cumsum[i - k + 1]] -= 1
print(ans)
| 0 | null | 118,071,474,094,308 | 244 | 273 |
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a = [aa-1 for aa in a]
check = [0 for i in range(n)]
count = 0
point = 0
check[0] = 1
path = [0]
for i in range(min(n, k)):
if i == 0 or check[point] == 0:
check[point] = i+1
point = a[point]
path.append(point)
else:
break
cycle_len = len(path)-check[point]
pre = check[point]
if pre > k:
print(path[k])
else:
k -= pre
k %= cycle_len
print(path[pre+k]+1)
| n,k=map(int,input().split())
a=list(map(int,input().split()))
town=[0]*n
info=[1]
now=1
while town[now-1]==0:
town[now-1]+=1
now=a[now-1]
info.append(now)
loop_list=list(info[info.index(now):-1])
loop_len=len(loop_list)
before_loop_list=list(info[:info.index(now)])
#print(town)
#print(info)
if k<len(before_loop_list):
print(before_loop_list[k])
else:
print(loop_list[((k-len(before_loop_list))%loop_len)]) | 1 | 22,734,797,813,752 | null | 150 | 150 |
n = int(raw_input())
card_list = 52*[0]
for i in range(0,n):
(mark,rank) = map(str,raw_input().split())
for j in range(0,4):
if mark == 'SHCD'[j]:
card_list[13*j+int(rank)-1] = 1
for i in range(0,52):
if card_list[i] == 0:
print '%c %d' %('SHCD'[i/13],i%13+1) | import sys
#f = open("test.txt", "r")
f = sys.stdin
num_rank = 14
s_list = [False] * num_rank
h_list = [False] * num_rank
c_list = [False] * num_rank
d_list = [False] * num_rank
n = f.readline()
n = int(n)
for i in range(n):
[suit, num] = f.readline().split()
num = int(num)
if suit == "S":
s_list[num] = True
elif suit == "H":
h_list[num] = True
elif suit == "C":
c_list[num] = True
else:
d_list[num] = True
for i in range(1, num_rank):
if not s_list[i]:
print("S " + str(i))
for i in range(1, num_rank):
if not h_list[i]:
print("H " + str(i))
for i in range(1, num_rank):
if not c_list[i]:
print("C " + str(i))
for i in range(1, num_rank):
if not d_list[i]:
print("D " + str(i)) | 1 | 1,035,016,878,440 | null | 54 | 54 |
def read_int():
return int(input().strip())
def read_ints():
return list(map(int, input().strip().split(' ')))
def solve():
N = read_int()
L = read_ints()
L.sort()
answer = 0
for i in range(2, N):
for j in range(1, i):
start, end = -1, j
while end-start > 1:
mid = start+(end-start)//2
if L[i]-L[j] < L[mid]: # valid
end = mid
else:
start = mid
answer += j-end
return answer
if __name__ == '__main__':
print(solve())
| N=int(input())
L=list(map(int,input().split()))
L.sort()
from bisect import bisect_left
ans = 0
for i1 in range(N-2):
for i2 in range(i1+1,N-1):
l1,l2 = L[i1],L[i2]
#th = bisect_left(L[i2+1:],l1+l2)
#print(l1,l2,L[i2+1:],(l2-l1+1)*(-1),th)
th = bisect_left(L,l1+l2)
ans += max(th-i2-1,0)
print(ans) | 1 | 171,900,486,927,162 | null | 294 | 294 |
def main():
_ = int(input())
num_tuple = tuple(map(int, input().split()))
count = 0
for i, num in enumerate(num_tuple):
if ((i+1)*num) % 2 == 1:
count += 1
print(count)
if __name__ == '__main__':
main()
| n = int(input())
z = input().split()
odd = 0
for i in range(n):
if i % 2 == 0:
if int(z[i]) % 2 == 1:
odd += 1
print(odd) | 1 | 7,744,449,916,678 | null | 105 | 105 |
from math import ceil
H, A = map(int, input().split())
print("{}".format(ceil(H / A)))
| N, M, X = list(map(int, input().split()))
A = [0]*N
for i in range(N):
A[i] = list(map(int, input().split()))
min_sump = -1
for i in range(2**(N+1)):
sump = 0
sume = [0]*M
for j in range(N):
ns = "0" + str(N) +"b"
bi = format(i,ns)
if bi[-1-j] == "1":
sump += A[j][0]
sume = list(map(sum, zip(sume, A[j][1:])))
if all([i >= X for i in sume]):
if min_sump == -1:
min_sump = sump
else:
min_sump = min(min_sump,sump)
print(min_sump) | 0 | null | 49,542,043,490,606 | 225 | 149 |
N=int(input())
S=input()
ans=0
for i in range(1000):
one=str(i//100)
two=str((i%100)//10)
three=str(i%10)
f1,f2,f3=False,False,False
ptr=0
for j in range(ptr,N-2):
if S[j]==one:
f1=True
ptr=j+1
break
if f1:
for j in range(ptr,N-1):
if S[j]==two:
f2=True
ptr=j+1
break
if f2:
for j in range(ptr,N):
if S[j]==three:
f3=True
ans+=1
break
print(ans) | # -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)
def zz():
return list(map(int, sys.stdin.readline().split()))
def z():
return int(sys.stdin.readline())
def S():
return sys.stdin.readline()[:-1]
def C(line):
return [sys.stdin.readline() for _ in range(line)]
N = z()
S = S()
after_lis = [set() for _ in range(N+1)]
i = N-1
for s in reversed(S):
after_lis[i] = (after_lis[i] | after_lis[i+1])
after_lis[i].add(int(s))
i -= 1
left_index = {}
for i, s in enumerate(S):
if s not in left_index:
left_index[s] = i
ans_lis = np.zeros([10, 10, 10], dtype=np.int32)
for char in left_index:
s_100 = int(char)
for i_10 in range(left_index[char]+1, N-1):
# print("s_10")
s_10 = int(S[i_10])
ans_lis[s_100, s_10, list(after_lis[i_10+1])] = 1
# sは暗証番号の一番左
# print(ans_lis)
print(np.sum(ans_lis))
| 1 | 128,553,150,211,710 | null | 267 | 267 |
#!/usr/bin/env pypy3
# N,M = map(int,sys.stdin.readline().split())
# a = tuple(map(int,sys.stdin.readline().split())) # single line with multi param
# a = tuple(int(sys.stdin.readline()) for _ in range(N)) # multi line with single param
# a = tuple(tuple(map(int,sys.stdin.readline().rstrip().split())) for _ in range(N)) # multi line with multi param
# s = sys.stdin.readline().rstrip()
# N = int(sys.stdin.readline())
# INF = float("inf")
import math,sys
n = int(sys.stdin.readline())
a = tuple(map(int,sys.stdin.readline().split()))
#n = int(input())
#a = list(map(int,input().split()))
g = math.gcd(a[0],a[1])
for i in range(2,n):
g = math.gcd(g,a[i])
M = max(a)
acc = a[0]
for i in range(n):
acc = math.gcd(acc,a[i])
if acc != 1:
print("not coprime")
exit()
LIMIT=max(a)
minPrime = [0]*(LIMIT+1)
minPrime[1] = 1
def make():
for i in range(2,LIMIT+1):
if minPrime[i] == 0:
minPrime[i] = i
#print(i)
for j in range(i+i,LIMIT+1,i):
#print(i,j)
if minPrime[j] == 0:
minPrime[j] = i
make()
def factrial(N):
ret = []
while minPrime[N] != N:
ret.append(minPrime[N])
N = N//minPrime[N]
if N != 1:
ret.append(N)
return ret
judge = set([])
for e in a:
asf = set(factrial(e))
if judge & asf != set():
print("setwise coprime")
exit()
judge |= asf
#judge = judge | asf #too slow
print("pairwise coprime") | N = int(input())
A = list(map(int,input().split()))
number_list = [0]*1000010
for a in A:
number_list[a] += 1
flag1 = True
flag2 = True
for i in range(2,1000001):
count = 0
for j in range(1,1000001):
if i*j > 1000000:
break
tmp = i*j
count += number_list[tmp]
if count > 1:
flag1 = False
if count == N:
flag2 = False
if flag2 == False and flag1 == False:
print("not coprime")
elif flag2 == True and flag1 == False:
print("setwise coprime")
else:
print("pairwise coprime") | 1 | 4,074,565,404,770 | null | 85 | 85 |
n = int(input())
a = list(map(int, input().split()))
min_a = min(a)
max_a = max(a)
sum_a = sum(a)
print(min_a, max_a, sum_a) | n = int(input())
a = [int(i) for i in input().split()]
print('%d %d %d' % (min(a), max(a), sum(a))) | 1 | 721,505,675,770 | null | 48 | 48 |
from itertools import accumulate
#acumulate [a[0], a[0]+a[1], a[0]+...]
n, k = map(int, input().split())
p = [int(x) - 1 for x in input().split()]
c = list(map(int, input().split()))
ans = -(10 ** 18)
for i in range(n):
pos = i
scores = []
while True:
pos = p[pos]
scores.append(c[pos])
if pos == i:
break
m = len(scores)
s = list(accumulate(scores))
for j in range(min(m, k)):
x = (k - j - 1) // m
ans = max(ans, s[j], s[j] + s[-1] * x)
print(ans) | 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
# input = sys.stdin.readline.rstrip()
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return tuple(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 inplt(n): return [tuple(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])
n = inp()
P = inpl()
Q = inpl()
i = 0
a = 0
b = 0
for p in permutations(range(1,n+1)):
i += 1
if p == P:
a = i
if p == Q:
b = i
print(abs(a-b)) | 0 | null | 53,040,442,845,210 | 93 | 246 |
a,b=map(int,raw_input().split())
men=a*b
syuu=(a+b)*2
print men,syuu | a, b = (int(x) for x in input().split())
print(a*b, 2*a + 2*b)
| 1 | 303,837,922,698 | null | 36 | 36 |
S = input()
S = S.replace('><','> <').split()
ans = 0
for i in S:
j = max(i.count('>'),i.count('<'))
k = min(i.count('>'),i.count('<'))-1
for a in range(1,j+1):
ans += a
for b in range(1,k+1):
ans += b
print(ans) | import itertools,sys
def S(): return sys.stdin.readline().rstrip()
S = S()
groupby_S = itertools.groupby(S)
ans = 0
rangeN = [i for i in range(len(S)+1)]
rangeN_accumulate = list(itertools.accumulate(rangeN))
group = []
temp = []
for k,g in groupby_S:
if k=='<':
temp.append(len(list(g)))
else:
temp.append(len(list(g)))
group.append(temp)
temp = []
group.append(temp)
for x in group:
if len(x)==0:
continue
elif len(x)==1:
ans += rangeN_accumulate[x[0]]
else:
a,b = max(x),min(x)-1
ans += rangeN_accumulate[a]
ans += rangeN_accumulate[b]
print(ans)
| 1 | 156,514,422,403,570 | null | 285 | 285 |
import sys
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
n = int(input())
res = 0
for i in range(1, (n + 1) // 2):
if i != n - i:
res += 1
print(res)
if __name__ == '__main__':
resolve()
| #! /usr/bin/env python
# -*- coding: utf-8 -*-
import pdb
import sys
F = sys.stdin
N = int(F.readline())
count = 0
A = N // 2
for i in range(1, A+1):
if i*2 != N:
count += 1
print(count)
| 1 | 153,190,126,956,098 | null | 283 | 283 |
def backoutput(y):
if y.isupper():
return y.lower()
elif y.islower():
return y.upper()
else:
return y
first_input = list(map(backoutput, input()))
print(*first_input, sep='')
| n=int(input())
print(n+n*n+n*n*n) | 0 | null | 5,805,149,499,008 | 61 | 115 |
tmp = 0
while True:
i = raw_input().strip().split()
a = int(i[0])
b = int(i[1])
if a == 0 and b == 0:
break
if a > b:
tmp = a
a = b
b = tmp
print a,b | x, y, a, b ,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
sm=0
p.sort()
q.sort()
r.sort(reverse=True)
p=p[(a-x):]
q=q[(b-y):]
p.extend(q)
p.sort()
idx=0
for i in range(len(p)):
if p[i]>r[idx]:
break
else:
p[i]=r[idx]
idx+=1
if c==idx:
break
print(sum(p)) | 0 | null | 22,792,441,920,862 | 43 | 188 |
Str = input()
q = int(input())
for i in range(q):
order = list(input().split())
o = order[0]
a = int(order[1])
b = int(order[2])
if o=='print':
print(Str[a:b+1])
if o=='reverse':
StrL = list(Str)
t = list(Str[a:b+1])
j = len(t)-1
for i in range(a,b+1):
StrL[i] = t[j]
j -= 1
Str = ''.join(StrL)
if o=='replace':
p = list(order[3])
StrL = list(Str)
j = 0
for i in range(a,b+1):
StrL[i] = p[j]
j += 1
Str = ''.join(StrL)
| word = list(map(int,input().split()))
hyoko = list(map(int,input().split()))
road = [0]*word[1]
for i in range(word[1]):
road[i] = list(map(int,input().split()))
tenbo = [1]*word[0]
for j in range(word[1]):
if hyoko[road[j][0]-1] > hyoko[road[j][1]-1]:
tenbo[road[j][0]-1] *= 1
tenbo[road[j][1]-1] = 0
elif hyoko[road[j][0]-1] < hyoko[road[j][1]-1]:
tenbo[road[j][0]-1] = 0
tenbo[road[j][1]-1] *= 1
else:
tenbo[road[j][0]-1] = 0
tenbo[road[j][1]-1] = 0
answer = word[0] - tenbo.count(0)
print(answer) | 0 | null | 13,463,030,896,640 | 68 | 155 |
import sys
print('10'[int(sys.stdin.buffer.readline())]) | num = int(input())
print(0 if num == 1 else 1) | 1 | 2,946,753,040,092 | null | 76 | 76 |
#!/usr/bin/env python
letters = []
for i in range(26):
letters.append(chr(i + 97) + " : ")
contents = []
while True:
try:
text = input()
except EOFError:
break
contents.append(text)
#65-90 uppercase
#97-122lowercase
i = 0
for y in letters:
value = 0
for text in contents:
for x in text:
if x.isupper():
x = x.lower()
if x in y:
value += 1
elif x.islower():
if x in y:
value += 1
letters[i] = letters[i] + str(value)
i += 1
for x in letters:
print(x) | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
??§???????°?????????????
"""
import sys
lower = "abcdefghijklmnopqrstuvwxyz"
upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
inp = sys.stdin.read() # EOF?????§????????????
inp = inp.translate(str.maketrans(upper,lower))
for i in lower:
print("{0} : {1}".format(i,inp.count(i))) | 1 | 1,675,012,962,804 | null | 63 | 63 |
def gcd(a, b):
if b == 0: return a
else: return gcd(b, a % b)
def lcm(a, b):
return a * b / gcd(a, b)
while True:
try:
a, b = map(int, input().split())
print(int(gcd(a, b)), int(lcm(a, b)))
except EOFError:
break | import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 998244353
def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def main():
N, S = read_values()
A = read_list()
dp = [[0 for _ in range(S + 1)] for _ in range(N + 1)]
dp[0][0] = 1
for i, a in enumerate(A):
for s in range(S + 1):
dp[i + 1][s] += 2 * dp[i][s]
dp[i + 1][s] %= mod
if s + a <= S:
dp[i + 1][s + a] += dp[i][s]
dp[i + 1][s + a] %= mod
print(dp[N][S])
if __name__ == "__main__":
main()
| 0 | null | 8,912,617,022,650 | 5 | 138 |
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq
def ri():
return int(input())
def rl():
return list(map(int, input().split()))
def solve():
n, m = rl()
A = rl()
print (max(n - sum(A), -1))
mode = 's'
if mode == 'T':
t = ri()
for i in range(t):
solve()
else:
solve()
| a,b=map(int,input().split())
List = list(map(int, input().split()))
wa = 0
for i in range(b):
wa += List[i]
res = a - wa
if res < 0:
res = -1
print(res) | 1 | 32,013,943,339,520 | null | 168 | 168 |
n = float(input())
even_num = n // 2;
num = n - even_num
print(num/n)
| N = int(input())
P = list(map(int,input().split()))
T = [P[0]]+[10**10]*(N-1)
ans = 0
for i in range(N):
T[i] = min(T[i-1],P[i])
for i in range(N):
if P[i] <= T[i]:
ans += 1
print(ans) | 0 | null | 131,436,946,564,960 | 297 | 233 |
N = int(input())
S = input()
if N % 2 != 0:
print('No')
else:
for i in range(int(N/2)):
if S[i] != S[i + int(N/2)]:
print('No')
break
else:
print('Yes') | import sys, bisect, collections, math
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()
AB = [LI() for _ in range(N)]
# A, Bを標準化 互いに疎でAは正
def normalize(AB):
A = AB[0]
B = AB[1]
if A==B==0:
return (0, 0)
elif A==0:
return(0, 1)
elif B==0:
return(1, 0)
else:
gcd = math.gcd(A, B)
A //= gcd
B //= gcd
if A<0:
A, B = -A, -B
return (A, B)
def orthogonal(AB):
A = AB[0]
B = AB[1]
if B>0:
return (B, -A)
else:
return(-B, A)
AB_n = [normalize(i) for i in AB]
counter = collections.Counter(AB_n)
# 場合の数を求める
used = set()
ans = 1
# (0, 0)以外について
for A, B in AB_n:
if not (A, B) in used:
if (A, B)!=(0, 0):
ans *= pow(2, counter[(A, B)], MOD) + pow(2, counter[orthogonal((A, B))], MOD) - 1
ans %= MOD
used.add((A, B))
used.add(orthogonal((A, B)))
ans -= 1
# (0, 0)について
ans += counter[(0, 0)]
ans %= MOD
print(ans)
if __name__ == '__main__':
resolve()
| 0 | null | 84,202,548,408,132 | 279 | 146 |
T = input()
res = ""
for t in T:
if t == "?":
res += "D"
else:
res += t
print(res) | import math
a,b,c=(int(x) for x in input().split())
s=1/2*a*b*math.sin(c/180*math.pi)
l=math.sqrt(a**2+b**2-2*a*b*math.cos(c/180*math.pi))+a+b
h=s/a*2
print('{:.05f}'.format(s))
print('{:.05f}'.format(l))
print('{:.05f}'.format(h))
| 0 | null | 9,380,731,349,918 | 140 | 30 |
#coding: UTF-8
N = int(input())
a = [int(input()) for i in range(N)]
ans = set()
maxv = -9999999999
minv = a[0]
for i in range(1,N):
if (a[i] - minv) > maxv:
maxv = a[i] - minv
if a[i] < minv:
minv = a[i]
print(maxv) | n = int(input())
r_min = int(input())
r_t = int(input())
g_max = r_t - r_min
r_min = min(r_t,r_min)
for _ in range(n-2):
r_t = int(input())
g_max = max(g_max, r_t-r_min)
r_min = min(r_t,r_min)
print(g_max)
| 1 | 13,706,114,434 | null | 13 | 13 |
"""
9 5
-4 -3 -2 -1 0 1 2 3
"""
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
Am = []
Ap = []
for a in A:
if a < 0:
Am.append(a)
else:
Ap.append(a)
mod = 10**9 + 7
ans = 1
if N == K:
for a in A:
ans *= a
ans %= mod
elif A[-1] < 0:
if K % 2 == 1:
for i in range(K):
ans *= Am[-1-i]
ans %= mod
else:
for i in range(K):
ans *= Am[i]
ans %= mod
else:
if K%2 == 1:
ans *= Ap[-1]
ans %= mod
K -= 1
del Ap[-1]
Amd = []
Apd = []
for i in range(len(Ap)//2):
Apd.append(Ap[-1-(2*i)]*Ap[-1-(2*i+1)])
for i in range(len(Am)//2):
Amd.append(Am[2*i]*Am[2*i+1])
Apd.append(-1)
Amd.append(-1)
ip = 0
im = 0
while K > 0:
if Apd[ip] >= Amd[im]:
ans *= Apd[ip]
ip += 1
else:
ans *= Amd[im]
im += 1
ans %= mod
K -= 2
ans %= mod
print(ans)
| #with open('random_pm00.txt') as f:
#n, k = map(int, f.readline().split())
#a = list(map(int, f.readline().split()))
n, k = map(int, input().split())
a = list(map(int, input().split()))
mod = 10 ** 9 + 7
mia, pla = [], []
for ai in a:
if ai < 0:
mia.append(ai)
elif ai >= 0:
pla.append(ai)
mia.sort(reverse=True)
pla.sort()
cnt = 1
if len(pla) == 0 and k % 2 == 1:
for i in mia[:k]:
cnt = cnt * i % mod
else:
while k > 0:
if k == 1 or len(mia) <= 1:
if len(pla) == 0:
cnt = cnt * mia.pop() % mod
elif len(pla) > 0:
cnt = cnt * pla.pop() % mod
k -= 1
elif len(pla) <= 1:
if k == 1:
cnt = cnt * pla.pop() % mod
k -= 1
elif k > 1:
cnt = cnt * mia.pop() * mia.pop() % mod
k -= 2
elif len(pla) >= 2 and len(mia) >= 2:
if pla[-1] * pla[-2] > mia[-1] * mia[-2]:
cnt = cnt * pla.pop() % mod
k -= 1
elif pla[-1] * pla[-2] <= mia[-1] * mia[-2]:
cnt = cnt * mia.pop() * mia.pop() % mod
k -= 2
print(cnt)
| 1 | 9,436,864,237,660 | null | 112 | 112 |
import math
from numpy.compat.py3k import asstr
a, b = map(int, input().split())
ans = int(a * b / math.gcd(a, b))
print(str(ans))
| import sys
import time
import math
def inpl():
return list(map(int, input().split()))
st = time.perf_counter()
# ------------------------------
A, B = map(int, input().split())
print(A*B // math.gcd(A,B))
# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)
| 1 | 112,888,303,739,490 | null | 256 | 256 |
s = str(input())
t = str(input())
revise = 0
len_str = len(s)
for i in range(len_str):
if s[i] != t[i]:
revise += 1
print(int(revise)) | n=int(input())
d,m=divmod(n,500)
print(d*1000+m//5*5) | 0 | null | 26,736,138,487,686 | 116 | 185 |
from collections import Counter
inputs = open(0).readlines()
n = int(inputs[0])
*D, = map(int, inputs[1].split())
mod = 998244353
nbs = [0] * (max(D)+1)
for k, v in Counter(D).items():
nbs[k] = v
if D[0] != 0 or nbs[0] != 1:
print(0)
else:
ans = 1
for n0, n1 in zip(nbs, nbs[1:]):
ans = ans * pow(n0, n1, mod) % mod
print(ans) | a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())
if v <= w:
print('NO')
elif (abs(a-b) / (v-w)) <= t:
print('YES')
else:
print('NO') | 0 | null | 85,272,060,844,340 | 284 | 131 |
def main():
a, b, c = map(int, input().split())
if(a+b+c >= 22):
print('bust')
else:
print('win')
return 0
if __name__ == '__main__':
main() | from sys import exit
import math
import collections
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
a,b,c = mi()
if a + b + c >=22:
print('bust')
else:
print('win') | 1 | 118,825,624,453,018 | null | 260 | 260 |
import math
T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())
if A1 > B1:
F1, F2 = A1, A2
S1, S2 = B1, B2
else:
F1, F2 = B1, B2
S1, S2 = A1, A2
oi = F1 * T1 - S1 * T1
nuki = S2 * T2 - F2 * T2 - oi
if nuki == 0:
print("infinity")
elif nuki > 0:
enc = oi // nuki * 2
if oi % nuki != 0:
enc = enc + 1
print(enc)
else:
print(0) | D=int(input())
c=[None]+list(map(int, input().split()))
s=[None]+[list(map(int, input().split())) for _ in range(D)]
T=[None]+[int(input()) for _ in range(D)]
lastdi=[None]+[0]*26
v=0
for i in range(1, D+1):
v+=s[i][T[i]-1]
lastdi[T[i]]=i
for x in range(1, 27):
v-=(i-lastdi[x])*c[x]
print(v) | 0 | null | 70,713,792,313,408 | 269 | 114 |
inp = input()
print(inp.swapcase()) | N = int(input())
S = list(input())
print("".join(chr(65+(ord(s)-65+N)%26) for s in S)) | 0 | null | 67,939,233,416,860 | 61 | 271 |
while 1:
x,y,z=raw_input().split()
x=int(x)
z=int(z)
if(y=='?'):
break
if(y=='+'):
print x+z
if(y=='-'):
print x-z
if(y=='/'):
print x/z
if(y=='%'):
print x%z
if(y=='*'):
print x*z | import math
a, b, C = map(int, input().split())
C = math.radians(C)
c = math.sqrt(a**2 + b**2 - 2*a*b*math.cos(C))
S = a * b * math.sin(C) / 2
print(f"{S:0.9f}")
print(f"{a+b+c:0.9f}")
print(f"{S*2/a:0.9f}")
| 0 | null | 435,661,537,318 | 47 | 30 |
a,b=map(int,input().split())
if a<b:
print(str(a)*b)
elif a>b:
print(str(b)*a)
elif a==b:
print(str(a)*b)
| a,b=map(int,input().split())
a1=f"{a}"*b
b1=f"{b}"*a
print(a1 if a1<b1 else b1) | 1 | 84,147,081,091,308 | null | 232 | 232 |
H, A = (int(x) for x in input().split())
dm = divmod(H,A)
if dm[1] == 0:
print(dm[0])
else:
print(dm[0]+1) | a,b,c = map(int, input().split())
k = int(input())
for i in range(k):
if a >= b:
b *= 2
continue
if b >= c:
c *= 2
continue
print("Yes" if a < b and b < c else "No")
| 0 | null | 41,826,907,213,740 | 225 | 101 |
a,b,c = [int(i) for i in input().split()]
i=0
for num in range(a,b+1,1):
if c % num == 0:
i = i+1
else:
pass
print(i)
| l = input().split()
a = int(l[0])
b = int(l[1])
c = int(l[2])
d = []
for i in range(a,b+1):
if c % i == 0:
d.append(i)
print(len(d)) | 1 | 563,053,681,220 | null | 44 | 44 |
N,K=map(int,input().split())
H=list(map(int, input().split()))
#Nモンスターの数、K必殺回数(モンスターは体力ゼロになる)、Hモンスターの数と各々の体力
H=sorted(H)
if K>=len(H):
print(0)
else:
for i in range(0,K):
del H[-1]
result=sum(H)
print(result) | n,k = map(int,input().split())
h = list(map(int,input().split()))
ans = 0
if(n <= k):
print(0)
else:
h.sort()
a = []
a = h[:n-k]
print(sum(a)) | 1 | 78,840,728,482,410 | null | 227 | 227 |
N,X,Y=map(int,input().split())
#i<X<Y<j
#このときはX->を通るほうが良い
#X<=i<j<=Y
#このときはループのどちらかを通れば良い
#X<=i<=Y<j
#このときはiとYの最短距離+Yとjの最短距離
#i<X<=j<=Y
#同上
#i<j<X
#パスは1通りしか無い
def dist(i,j):
if i>j:
return dist(j,i)
if i==j:
return 0
if i<X:
if j<X:
return j-i
if X<=j and j<=Y:
return min(j-i,(X-i)+1+(Y-j))
if Y<j:
return (X-i)+1+(j-Y)
if X<=i and i<=Y:
if j<=Y:
return min(j-i,(i-X)+1+(Y-j))
if Y<j:
return min((i-X)+1+(j-Y),j-i)
if Y<i:
return (j-i)
ans=[0 for i in range(N)]
for i in range(1,N+1):
for j in range(i+1,N+1):
ans[dist(i,j)]+=1
for k in range(1,N):
print(ans[k]) | n,x,y=map(int,input().split())
a=[0]*n
for i in range(1,n+1):
for j in range(i,n+1):
b=min(abs(i-j),abs(i-x)+1+abs(y-j),abs(x-j)+1+abs(y-i))
a[b]+=1
print(*a[1:],sep="\n") | 1 | 43,953,556,837,162 | null | 187 | 187 |
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)
X = int(input())
dp = [0]*(X+1)
dp[0] = 1
for i in range(1, X+1):
for yen in range(100, 106):
if yen<=i:
if dp[i-yen]==1:
dp[i] = 1
if dp[X]:
print(1)
else:
print(0) | def main():
a, b, c = map(int, input().split())
tmp = c - a - b
if tmp > 0 and 4*a*b < tmp*tmp:
print('Yes')
else:
print('No')
main()
| 0 | null | 89,804,950,495,568 | 266 | 197 |
import numpy as np
a,b=map(int,input().split())
print(max(a-2*b,0)) | # http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B&lang=ja
import sys
input = sys.stdin.readline
N = int(input())
G = [[a-1 for a in list(map(int, input().split()))[2:]] for _ in [0]*N]
visited = [0]*N
history = [[] for _ in [0]*N]
k = 0
def dfs(v=0, p=-1):
global k
visited[v] = 1
k += 1
history[v].append(k)
for u in G[v]:
if u == p or visited[u]:
continue
dfs(u, v)
k += 1
history[v].append(k)
for i in range(N):
if not visited[i]:
dfs(i)
for i, h in enumerate(history):
print(i+1, *h)
| 0 | null | 83,678,733,450,080 | 291 | 8 |
if __name__ == '__main__':
n = int(input())
S = [0,0,0,0]
for _ in range(n):
cmd = input()
if cmd == "AC":
S[0] += 1
elif cmd == "TLE":
S[2] += 1
elif cmd == "WA":
S[1] += 1
else:
S[3] += 1
for i in range(4):
if i == 0:
print("AC x " + str(S[0]))
elif i == 1:
print("WA x " + str(S[1]))
elif i == 2:
print("TLE x " + str(S[2]))
else:
print("RE x " + str(S[3]))
| from sys import stdin
input = stdin.readline
from collections import Counter
def solve():
n = int(input())
verdict = [ inp for inp in stdin.read().splitlines()]
c = Counter(verdict)
print(f'AC x {c["AC"]}')
print(f'WA x {c["WA"]}')
print(f'TLE x {c["TLE"]}')
print(f'RE x {c["RE"]}')
if __name__ == '__main__':
solve()
| 1 | 8,621,795,467,950 | null | 109 | 109 |
from functools import reduce
MOD = 10**9+7
n = int(input())
A = list(map(int, input().split()))
def factorization(n):
retval = []
tmp = n
for i in range(2, int(-(-n**.5//1))+1):
if tmp % i == 0:
cnt = 0
while tmp % i == 0:
cnt += 1
tmp //= i
retval.append((i, cnt))
if tmp != 1:
retval.append((tmp, 1))
return retval
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def lcm(a, b):
return (a*b)//gcd(a, b)
x = reduce(lcm, A) % MOD
print(sum(x*pow(a, MOD-2, MOD) for a in A) % MOD)
| import sys
import bisect
import itertools
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
N = int(readline())
A = list(map(int, readline().split()))
lcmnum = 1
def gcd(a, b):
if (a == 0):
return b
return gcd(b%a, a)
def lcm(x, y):
return (x * y) // gcd(x, y)
for a in A:
lcmnum = lcm(lcmnum, a)
ans = 0
for a in A:
a = lcmnum // a
ans += a
ans %= mod
print(ans)
if __name__ == '__main__':
solve()
| 1 | 87,869,791,698,528 | null | 235 | 235 |
from math import sqrt
N = int(input())
limit = int(sqrt(N))
res = [0] * (N + 1)
for x in range(1, limit+1):
for y in range(1, limit+1):
for z in range(1, limit+1):
val = x * x + y * y + z * z + x * y + y * z + z * x
if val <= N:
res[val] += 1
else:
break
for i in range(1, N + 1):
print(res[i])
| # coding:utf-8
n = int(input())
ans = [0] * n
for i in range(1, 101):
for j in range(1, 101):
for k in range(1, 101):
tmp = i**2 + j**2 + k**2 + i * j + j * k + k * i
if tmp <= n:
ans[tmp - 1] += 1
for item in ans:
print(item)
| 1 | 7,968,335,591,410 | null | 106 | 106 |
from collections import defaultdict
n = int(input())
results = defaultdict(lambda: 0)
for _ in range(n):
s = input()
results[s] += 1
for judge in ['AC', 'WA', 'TLE', 'RE']:
print(judge, ' x ', results[judge])
| N=int(input())
S=[input()for _ in range(N)]
from collections import*
C=Counter(S)
print('AC','x',C['AC'])
print('WA','x',C['WA'])
print('TLE','x',C['TLE'])
print('RE','x',C['RE']) | 1 | 8,659,939,107,996 | null | 109 | 109 |
t=input()
s=''
for i in range(len(t)):
if t[i]=='?':
s+='D'
else:
s+=t[i]
print(s) | def main():
N,K=map(int,input().split())
M={}
mod=pow(10,9)+7
res=0
for i in range(K,0,-1):
syou=K//i
mc=pow(syou,N,mod)
if syou>=2:
for sub_m in range(2,syou+1):
mc-=M[sub_m*i]
res+=(i*mc)%mod
M[i]=mc
print(res%mod)
if __name__=="__main__":
main() | 0 | null | 27,532,001,065,190 | 140 | 176 |
from math import gcd
def main():
ans = 0
k = int(input())
for i in range(1,1+k):
for j in range(1,1+k):
for l in range(1,1+k):
ans += gcd(i,gcd(j,l))
print(ans)
if __name__ == "__main__":
main() | a = int(input())
n = 1
while True:
if a*n % 360 == 0:
break
else:
n += 1
print(n) | 0 | null | 24,284,345,358,152 | 174 | 125 |
n = int(input())
A = list(map(int, input().split()))
SWAP = 0
def conquer(A, left, mid, right):
L, R = A[left:mid], A[mid:right]
# L, Rの末尾にINFTYを入れないと、L[-1] or R[-1]が評価されない
INFTY = 2 ** 30
L.append(INFTY)
R.append(INFTY)
# i : position in L, j : position in R
i, j = 0, 0
swap_times = 0
# 元のArrayを変えたいため、kを生成
for k in range(left, right):
# print(i, j, L, R, A)
if L[i] <= R[j]:
A[k] = L[i]
i = i + 1
else:
A[k] = R[j]
j = j + 1
swap_times += 1
return swap_times
def divide(A, left, right):
# print(left, right)
# A[right-left]が2つ以上の場合に
if left+1 < right:
mid = (left+right)//2
countL = divide(A, left, mid)
countR = divide(A, mid, right)
return conquer(A, left, mid, right) + countL + countR
return 0
def mergeSort(A):
return divide(A, 0, len(A))
swap = mergeSort(A)
print(" ".join([ str(i) for i in A]))
print(swap)
| import math
N,M=map(int,input().split())
if (N==0 or N==1) and (M==0 or M==1):
print(0)
elif (N==0 or N==1) and (M!=0 and M!=1):
print(int(math.factorial(M)/math.factorial(M-2)/math.factorial(2)))
elif (M==0 or M==1) and (N!=0 and N!=1):
print(int(math.factorial(N)/math.factorial(N-2)/math.factorial(2)))
else:
print(int(math.factorial(N)/math.factorial(N-2)/math.factorial(2)+math.factorial(M)/math.factorial(M-2)/math.factorial(2)))
| 0 | null | 22,875,032,972,008 | 26 | 189 |
import math
from operator import mul
from functools import reduce
n, m, k = map(int, input().split())
mod = 998244353
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]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, n+1):
fact.append((fact[-1] * i) % mod)
inv.append((-inv[mod % i] * (mod // i)) % mod)
factinv.append((factinv[-1] * inv[-1]) % mod)
ans = 0
for i in range(k+1):
ans += m*cmb(n-1, i, mod)*pow(m-1, n-1-i, mod)%mod
ans %= mod
print(ans) | N,M,K=map(int, input().split())
MOD=998244353
ans=0
temp2=1
#temp4=(M-1)**(N-1)%MOD
def getInvs(n, MOD):
invs = [1] * (n+1)
for x in range(2, n+1):
invs[x] = (-(MOD//x) * invs[MOD%x]) % MOD
return invs
invs = getInvs(max(N+3,M-1), MOD)
Vec=[0]*N
#inv=1
#for i in range(MOD-2):
# inv*=M-1
# inv%=MOD
'''
for i in range(K+1):
if i == 0:
temp1=M
temp1*=(M-1)**(N-1)%MOD
temp1%=MOD
ans+=temp1*temp2%MOD
#print(cmb)
else:
temp1*=invs[M-1]%MOD
temp2*=(N-i)*invs[i]
temp2%=MOD
ans+=temp1*temp2%MOD
cmb=cmb*(N-i-1)*i*invs[i]%MOD
#print(cmb)
'''
for i in range(N):
if i == 0:
temp1=M
Vec[N-i-1]=temp1
else:
temp1*=(M-1)*(N-i)
temp1*=invs[i]
temp1%=MOD
Vec[N-i-1]=temp1
ans=sum(Vec[:K+1])
print(ans%MOD)
| 1 | 23,349,372,101,680 | null | 151 | 151 |
a, b, c, d = map(int,input().split())
while True:
c = c - b
a = a - d
if c <= 0:
print('Yes')
break
elif a <= 0:
print('No')
break
else:
pass | N = int(input())
lsa = list(map(int,input().split()))
a = 1
for i in range(N):
if lsa[i] == a:
a += 1
if a == 1:
ans = -1
else:
ans = N-(a-1)
print(ans) | 0 | null | 71,795,583,903,520 | 164 | 257 |
import sys
import collections
input = sys.stdin.readline
MOD = 998244353
def main():
N = int(input())
D = list(map(int, input().split()))
if D[0] != 0:
print(0)
return
D.sort()
Dmax = max(D)
Ditems = collections.Counter(D).items()
Dcount = list(zip(*Ditems))
Dset = set(Dcount[0])
if Dset != set(range(Dmax+1)):
print(0)
return
if Dcount[1][0] != 1:
print(0)
return
ans = 1
for i in range(2, Dmax+1):
ans *= pow(Dcount[1][i-1], Dcount[1][i], MOD)
ans %= MOD
print(ans%MOD)
if __name__ == "__main__":
main()
| from collections import deque
def main():
k = int(input())
d = deque(list(range(1, 10)))
ans = 0
for _ in range(k):
ans = d.popleft()
if ans % 10 != 0:
d.append(10 * ans + (ans % 10) - 1)
d.append(10 * ans + (ans % 10))
if ans % 10 != 9:
d.append(10 * ans + (ans % 10) + 1)
print(ans)
if __name__ == '__main__':
main()
| 0 | null | 97,654,513,133,210 | 284 | 181 |
# -*- coding: utf-8 -*-
'''
所要時間は、分位であった。
'''
# ライブラリのインポート
#import re
import sys
input = sys.stdin.readline
#import heapq
#import bisect
import collections
#import math
global time, Ls, Lf, E,LG,c,n
time = 1
def main():
global time, Ls, Lf, E, LG,c,n
c = 0
n = int(input().strip())
E = [[] for _ in range(n)]
LG = collections.deque()
for line in sys.stdin:
Ltmp = list(map(int, list(line.strip().split())))
if not Ltmp[1] == 0:
E[Ltmp[0]-1] = Ltmp[2:]
Ls = [0]*n
Lf = [0]*n
dfs(0)
for i in range(n):
print(i+1, Ls[i],Lf[i])
def dfs(cur):
global time, Ls, Lf, E, LG,c,n
LG.append(cur)
if Ls[cur] == 0: Ls[cur] = time
time += 1
for i in range(len(E[cur])):
check = E[cur][i] - 1
if Ls[check] == 0: dfs(check)
if Lf[cur] == 0:
Lf[cur] = time
try:
x = LG.pop()
if x == cur: x = LG.pop()
dfs(x)
except:
time += 1
for i in range(c,n):
if Ls[i] == 0:
c = i
dfs(i)
return
if __name__ == '__main__':
main()
| def dfs(v, cnt):
D[v] = cnt
cnt += 1
for c in edge[v]:
if D[c] == -1:
cnt = dfs(c, cnt)
F[v] = cnt
cnt += 1
return cnt
V = int(input())
edge = [[] for _ in range(V)]
for _ in range(V):
u, _, *v = map(lambda x: int(x)-1, input().split())
edge[u] = sorted(v)
D, F = [-1] * V, [-1] * V
c = 1
for i in range(V):
if D[i] == -1:
c = dfs(i, c)
for i, (d, f) in enumerate(zip(D, F)):
print(i+1, d, f) | 1 | 2,640,939,740 | null | 8 | 8 |
n, m, l = map(int, input().split())
A, B = [], []
C = [[0 for i in range(l)] for j in range(n)]
for i in range(n):
A.append([int(i) for i in input().split()])
for i in range(m):
B.append([int(i) for i in input().split()])
B = list(zip(*B))
for i, line_A in enumerate(A):
for j, line_B in enumerate(B):
for x, y in zip(line_A, line_B):
C[i][j] += x * y
for line in C:
for i, x in enumerate(line):
if i == l - 1:
print(x)
else:
print(x, end=" ")
| a, b = map(int, input().split())
cnt = 0
for i in range(1101):
if (i*8)//100 == a and(i*10)//100 == b:
print(i)
break
else:
cnt += 1
if cnt == 1101:
print(-1)
break | 0 | null | 28,829,156,035,258 | 60 | 203 |
if __name__ == '__main__':
n = int(input())
R = [int(input()) for i in range(n)]
minv = R[0]
maxv = R[1] - R[0]
for j in range(1, n):
if (maxv < R[j] - minv):
maxv = R[j] - minv
if (R[j] < minv):
minv = R[j]
print(maxv) | import sys
readline = sys.stdin.readline
K = [0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(K[int(readline())]) | 0 | null | 24,868,034,876,300 | 13 | 195 |
n, a, b = map(int,input().split())
ans = 0
if a >= n:
ans = n
elif a+b >= n:
ans = a
else:
set_ab = n//(a+b)
ans += set_ab*a
n -= set_ab*(a+b)
if n < a:
ans += n
else:
ans += a
print(ans)
| n, a, b = map(int, input().split())
c = n//(a+b)
ans = c*a
n = n - c*(a+b)
if n < a:
print(ans + n)
else:
print(ans + a) | 1 | 55,605,972,814,100 | null | 202 | 202 |
def main():
N = int(input())
*P, = map(int, input().split())
mi = N + 1
ret = 0
for x in P:
if mi > x:
mi = x
ret += 1
print(ret)
if __name__ == '__main__':
main()
# import sys
# input = sys.stdin.readline
#
# sys.setrecursionlimit(10 ** 7)
#
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
# while abs(ok - ng) > 1:
# mid = (ok + ng) // 2
# if func(mid):
# ok = mid
# else:
# ng = mid
# return ok
| N = int(input())
C = input().split()
B = C[:]
S = C[:]
# bubble sort
flag = 1
while(flag):
flag = 0
for x in range(1, N):
if B[x][1:] < B[x-1][1:]:
B[x], B[x-1] = B[x-1], B[x]
flag = 1
# sectionSot
for x in range(0,N):
minj = x
for j in range(x,N):
if S[j][1:] < S[minj][1:]:
minj = j
if minj != x:
S[x], S[minj] = S[minj], S[x]
print(" ".join(b for b in B))
print("Stable")
if(B == S):
print(" ".join(b for b in S))
print("Stable")
else:
print(" ".join(b for b in S))
print("Not stable") | 0 | null | 42,807,496,056,108 | 233 | 16 |
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
N,=pin()
A=lispin()
temp=0
sumA=[0]*N
sumA[0]=A[0]
for j in range(1,N):
sumA[j]=sumA[j-1]+A[j]
#print(sumA)
ans=2**32-1
t=sumA[-1]
for i in range(N):
ans=min(ans,abs(t-sumA[i]*2))
print(ans)
#%%submit!
resolve()
| import sys
input = sys.stdin.readline
N=int(input())
A=list(map(int,input().split()))
total = sum(A)
total *= 2
mindif = 1e12
sub = 0
for i in range(N):
sub += 2 * A[i]
dif = abs(total//2-sub)
if dif < mindif:
mindif = dif
print(mindif)
| 1 | 142,451,316,552,568 | null | 276 | 276 |
n = int(input())
a = list(map(int, input().split()))
sum = 0
k = a[0]
for i in range(n - 1):
if k >= a[i + 1]:
sum += k - a[i + 1]
else:
k = a[i + 1]
print(sum)
| import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1
n = int(input())
A = list(map(int, input().split()))
for i in range(n):
if i == 0:
max = A[i]
else:
if max > A[i]:
ans += max - A[i]
else:
max = A[i]
print(ans) | 1 | 4,558,907,221,780 | null | 88 | 88 |
n,m = map(int, input().split())
matrix = []
vector = []
for i in range(n):
a = list(map(int, input().split()))
matrix.append(a)
for j in range(m):
vector.append(int(input()))
for k in range(n):
entry = 0
for l in range(m):
entry += (matrix[k][l] * vector[l])
print(entry)
| n = int(input())
s,t = input().split()
st = ""
for i in range(n):
st = st+s[i]+t[i]
print(st) | 0 | null | 56,282,930,894,268 | 56 | 255 |
N = int(input())
S = list(map(int,input().split()))
B= list()
X = list()
for i in S:
if i % 2== 0:
B.append(i)
for n in B:
if n % 3 == 0 or n % 5 == 0:
X.append(n)
if len(B) == len(X):
print('APPROVED')
else:
print('DENIED')
| #!/usr/bin/env python3
import sys
S = input()
if S[-1] == "s":
print(S+"es")
else:
print(S+"s") | 0 | null | 35,716,682,169,428 | 217 | 71 |
ryou = [0]*4
for i in range(4):
ryou[i] = [0]*3
for i in range(4):
for j in range(3):
ryou[i][j] = [0]*10
sep = '#' * 20
n = int(input())
for i in range(n):
b, f, r, v = [int(x) for x in input().split()]
ryou[b-1][f-1][r-1] += v
for i in range(4):
for j in range(3):
s = ' '
s += ' '.join(map(str,ryou[i][j]))
print(s)
if not i == 3:
print(sep) | N = int(input())
SUM = []
for i in range(1,N+1):
if i % 3 == 0 or i % 5 ==0:
pass
else:
SUM.append(i)
print(sum(SUM))
| 0 | null | 18,069,642,251,310 | 55 | 173 |
from math import factorial
n,a,b=map(int,input().split())
mod=10**9+7
nCa=1
nCb=1
tmp=n
for i in range(a):
nCa*=tmp
tmp-=1
nCa%=mod
nCa=nCa*pow(factorial(a),mod-2,mod)%mod
tmp=n
for i in range(b):
nCb*=tmp
tmp-=1
nCb%=mod
nCb=nCb*pow(factorial(b),mod-2,mod)%mod
print(((pow(2,n,mod))-nCa-nCb-1)%mod) | import statistics
while True:
n = int(input())
if n == 0:
break
s = map(int, input().split())
print('{:.5f}'.format(statistics.pstdev(s))) | 0 | null | 32,971,619,091,848 | 214 | 31 |
import sys
sys.setrecursionlimit(300000)
def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 998244353
INF = float('inf')
N, A = MI()
a = [0, *list(map(int, input().split()))]
# dp[i][j] := i番目までの数字を使って総和をjとする場合の数
# dp[i][j] = dp[i - 1][j - a[i]] + dp[i - 1][j]
dp = [[0] * (A + 1) for _ in range(N + 1)]
dp[0][0] = 1
for i in range(1, N + 1):
for j in range(A + 1):
if j - a[i] < 0: # j - a[i] が負の数になってしまう時はa[i]を使用することはできない
dp[i][j] = 2 * dp[i - 1][j] % MOD
continue
dp[i][j] = (dp[i - 1][j - a[i]] + 2 * dp[i - 1][j]) % MOD
print(dp[N][A]) | # -*- coding:utf-8 -*-
import sys
class Hash(object):
def __init__(self, size):
self._array = [None] * size
self._size = size
def _hash(self, key):
return key % self._size
def insert(self, key, value):
j = self._hash(key)
if self._array[j] is None:
self._array[j] = [value]
else:
self._array[j].append(value)
def find(self, key, value):
j = self._hash(key)
if self._array[j] is None:
return False
elif value in self._array[j]:
return True
else:
return False
def stoi(s):
ret = 0
p = 1
ctoi = {"A": 1, "C": 2, "G": 3, "T": 4}
for c in s:
ret += ctoi[c] * p
p *= 7
return ret
def dictionary(lst):
h = Hash(1046527)
ret = []
for val in lst:
if val[0] == "insert":
h.insert(stoi(val[1]), val[1])
elif val[0] == "find":
if h.find(stoi(val[1]), val[1]):
ret.append("yes")
else:
ret.append("no")
else:
raise ValueError
return ret
if __name__ == "__main__":
lst = [val.split() for val in sys.stdin.read().splitlines()]
n = int(lst.pop(0)[0])
print("\n".join(dictionary(lst))) | 0 | null | 8,960,536,041,820 | 138 | 23 |
N, M = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
print(max(N - sum(A), -1))
| n=int(input())
ac=0
wa=0
tle=0
re=0
for _ in range(n):
s=input()
if s=="AC":
ac+=1
elif s=="WA":
wa+=1
elif s=="TLE":
tle+=1
else:
re+=1
print("AC x ",ac)
print("WA x ",wa)
print("TLE x ",tle)
print("RE x ",re) | 0 | null | 20,444,445,371,190 | 168 | 109 |
n = input()
s = range(1,14)
h = range(1,14)
c = range(1,14)
d = range(1,14)
for i in range(n):
a = raw_input().split()
num = int(a[1])
if a[0] == "S":
s.remove(num)
elif a[0] == "H":
h.remove(num)
elif a[0] == "C":
c.remove(num)
elif a[0] == "D":
d.remove(num)
for i in range(len(s)):
print "S",s[i]
for i in range(len(h)):
print "H",h[i]
for i in range(len(c)):
print "C",c[i]
for i in range(len(d)):
print "D",d[i] | from collections import OrderedDict
d = OrderedDict()
d['S'] = set()
d['H'] = set()
d['C'] = set()
d['D'] = set()
a = frozenset(range(1,14))
n = int(input())
for i in range(n):
s, r = input().split()
d[s].add(int(r))
for k, v in d.items():
racks = a.difference(v)
for rack in racks:
print(k, rack) | 1 | 1,065,443,164,106 | null | 54 | 54 |
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
MAX = 10**10 + 10
# Ai+Ajを列挙して大きいほうからM番目となるスコアSを求める
# その後S以上となるスコアを加算して合計値を求める
from bisect import bisect_left
def judge(x,key):
# スコアx以上となるのがkey個以上あるか?
num = 0
for i in range(N):
eidx = bisect_left(A,x-A[i])
num += N-eidx
if num >= key:
return True
else:
return False
def meguru(key):
ok = -1
ng = MAX
while (abs(ok-ng)>1):
mid = (ok+ng)//2
if judge(mid,key):
ok = mid
else:
ng = mid
return ok
D = meguru(M)
ans = 0
ruisekiwa = [0]*(N+1)
for i in range(N):
ruisekiwa[i+1] = ruisekiwa[i] + A[i]
num = 0
for i in range(N):
eidx = bisect_left(A,D+0.5-A[i])
ans += A[i] * (N-eidx)
ans += ruisekiwa[N] - ruisekiwa[eidx]
num += N-eidx
if num<M:
ans += (M-num)*D
print(ans)
| n = int(input())
S = input()
beforeChara = ""
cnt = 0
for s in S:
if s != beforeChara:
cnt += 1
beforeChara = s
print(cnt) | 0 | null | 138,901,882,541,000 | 252 | 293 |
import itertools
#h,w=map(int,input().split())
#S=[list(map(int,input().split())) for _ in range(h)]
n=int(input())
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
num=0
numlist=[i for i in range(1,n+1)]
pall=list(itertools.permutations(numlist))
for pp in pall:
if P==list(pp):
pnum=num
if Q==list(pp):
qnum=num
num+=1
print(abs(pnum-qnum)) | def main():
N = int(input())
S = input()
dict = {'R':0, 'B':0, 'G':0}
for i in range(N):
dict[S[i]] += 1
ans = dict['R']*dict['B']*dict['G']
for i in range(N-2):
if (N-i)%2 == 0:
tmp = int((N-i)/2)-1
else:
tmp = (N-i)//2
for j in range(1,tmp+1):
if S[i]!=S[i+j] and S[i]!=S[i+2*j] and S[i+j]!=S[i+2*j]:
ans = ans - 1
return ans
print(main())
| 0 | null | 68,747,875,627,388 | 246 | 175 |
apple = [1, 2, 3]
apple.remove(int(input()))
apple.remove(int(input()))
print(apple[0]) | a=int(input())
b=int(input())
print(6//(a*b)) | 1 | 110,556,491,782,294 | null | 254 | 254 |
import sys
readline = sys.stdin.buffer.readline
s =readline().rstrip().decode()
t =readline().rstrip().decode()
if t[:-1] == s:
print('Yes')
else:
print('No')
| import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import random
import re
import string
import sys
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from functools import lru_cache, reduce
from math import gcd
from operator import add, itemgetter, mul, xor
import numpy as np
if os.getenv("LOCAL"):
sys.stdin = open("_in.txt", "r")
sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353
a = sys.stdin.buffer.readline().decode().rstrip()
b = sys.stdin.buffer.readline().decode().rstrip()[:-1]
if a==b:
print('Yes')
else:
print('No')
| 1 | 21,479,709,967,012 | null | 147 | 147 |
n = int(input())
a = map(int,input().split(' '))
tallest = 0
step = 0
for i in a:
if i < tallest:
step = step + tallest - i
else:
tallest = i
print(step) | import math
N = int(input())
def bunkai(n):
factor={}
tmp = int(math.sqrt(n)) + 1
for num in range(2, tmp):
while n%num == 0:
n /= num
try:
factor[num] += 1
except:
factor[num] = 1
if int(n) != 1:
factor[int(n)] = 1
return factor
bunchan = bunkai(N)
ans = 0
for k in bunchan.keys():
cnt = 1
while bunchan[k] - cnt >= 0 :
bunchan[k] -= cnt
cnt += 1
ans += 1
print(ans) | 0 | null | 10,656,324,753,440 | 88 | 136 |
from math import floor
A,B,N=map(int,input().split())
ans=A*(B-1)//B
if N<B:
ans=A*N//B
print(ans) | S = input()
rain_d = 0
max_rain_d = 0
for s in S:
if s == 'R':
rain_d += 1
max_rain_d = rain_d
elif s == 'S':
rain_d = 0
print(max_rain_d) | 0 | null | 16,521,287,337,152 | 161 | 90 |
n,k=map(int,input().split())
h=list(map(int,input().split()))
h.append(k)
print(len(h[sorted(h).index(k)+1:])) | n=input()
t,h=0,0
for i in range(n):
a,b=raw_input().split()
if a>b: t+=3
elif a<b: h+=3
else:
t+=1
h+=1
print t,h | 0 | null | 90,491,293,025,498 | 298 | 67 |
def gcd(x,y):
a=max(x,y)
b=min(x,y)
if a%b==0:
return b
else:
return gcd(a%b,b)
A,B=map(int,input().split())
print(gcd(A,B))
| h, m, h2, m2, k = map(int, input().split())
ans = (h2 * 60 + m2) - (h * 60 + m) - k
print(ans) | 0 | null | 9,130,346,466,100 | 11 | 139 |
N,M=map(int,input().split())
if N == 1:begin,end=0,10
elif N==2:begin,end=10,100
else: begin,end=100,1000
ans = -1
SC=[]
for i in range(M):
s,c = map(int,input().split())
SC.append((s,c))
for n in range(begin,end):
count = 0
n = str(n)
for i in range(M):
if int(n[SC[i][0]-1])==SC[i][1]:count+=1
if count==M:
ans=n
break
print(ans) | import bisect
N = int(input())
L = list(map(int,input().split()))
ans = 0
L = sorted(L)
for i in range(N):
for j in range(N):
if i >= j:
continue
a = L[i]
b = L[j]
c = bisect.bisect_left(L,a+b)
ans += c - j - 1
print(ans) | 0 | null | 115,889,583,607,168 | 208 | 294 |
n = int(input())
array = list(map(int,input().split()))
q = int(input())
sums = sum(array)
cnt = [0]*(10**5+1)
for i in array:
cnt[i] += 1
for j in range(q):
b,c = map(int,input().split())
sums += cnt[b]*(c-b)
cnt[c] += cnt[b]
cnt[b] = 0
print(sums) | import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
#======================================================#
def main():
n = II()
aa = MII()
q = II()
bc = [MII() for _ in range(q)]
sumv = sum(aa)
numbers = [0]*(10**5+1)
for a in aa:
numbers[a] += 1
for b,c in bc:
numb = numbers[b]
sumv += numb*(c-b)
print(sumv)
numbers[b] = 0
numbers[c] += numb
if __name__ == '__main__':
main() | 1 | 12,200,159,446,176 | null | 122 | 122 |
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)
| import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
def main():
MOD = 1000000007
N, *A = map(int, read().split())
C = [0] * (N + 1)
C[0] = 3
ans = 1
for a in A:
ans = ans * C[a] % MOD
if ans == 0:
print(0)
return
C[a] -= 1
C[a + 1] += 1
print(ans)
return
if __name__ == '__main__':
main()
| 0 | null | 72,525,387,343,762 | 132 | 268 |
MOD = 10**9 + 7
N = 10**6 # 10**6が限界
factorial_mod = [1, 1] # factrial_mod[i] := i! mod p
modular_multiplicative_inverse = [0, 1] # モジュラ逆数 := i^(-1) ≡ x (mod p) となるx
factorial_inverse_mod = [1, 1] # factrial_inverse_mod[i] := (i!)^(-1) mod p
for i in range(2, N + 1): # O(N)
factorial_mod.append((factorial_mod[i - 1] * i) % MOD)
modular_multiplicative_inverse.append((-modular_multiplicative_inverse[MOD % i] * (MOD // i)) % MOD)
factorial_inverse_mod.append((factorial_inverse_mod[i-1] * modular_multiplicative_inverse[i]) % MOD)
def nCr_mod(n, r):
if r < 0 or r > n:
return 0
r = min(r, n - r)
return factorial_mod[n] * factorial_inverse_mod[r] * factorial_inverse_mod[n - r] % MOD
def nPr_mod(n, r):
return factorial_mod[n] * factorial_inverse_mod[n - r] % MOD
# ---------------------- #
n, k = (int(x) for x in input().split())
ans = 0
for i in range(min(n - 1, k) + 1):
# nCi * n-iHi = nCi * n-1Ci
ans += nCr_mod(n, i) * nCr_mod(n - 1, i)
ans %= MOD
print(ans)
| from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))
class Combination:
"""
comb = Combination(1000000)
print(comb(5, 3)) # 10
"""
def __init__(self, n_max, mod=10**9+7):
self.mod = mod
self.modinv = self.make_modinv_list(n_max)
self.fac, self.facinv = self.make_factorial_list(n_max)
def __call__(self, n, r):
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def make_factorial_list(self, n):
# 階乗のリストと階乗のmod逆元のリストを返す O(n)
# self.make_modinv_list()が先に実行されている必要がある
fac = [1]
facinv = [1]
for i in range(1, n+1):
fac.append(fac[i-1] * i % self.mod)
facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
return fac, facinv
def make_modinv_list(self, n):
# 0からnまでのmod逆元のリストを返す O(n)
modinv = [0] * (n+1)
modinv[1] = 1
for i in range(2, n+1):
modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
return modinv
n,k = inpl()
m = min(n-1,k)
res = 1
if m == 1:
print((n-1)*n%mod)
quit()
comb = Combination(n+10)
for i in range(m):
res += comb(n,i+1) * comb(n-1,n-i-2)
res %= mod
print(res) | 1 | 66,794,293,373,808 | null | 215 | 215 |
K = int(input())
S = input()
s = len(S)
L = []
mod = 10 ** 9 + 7
N = 2 * 10**6
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]
def cmb(n, r):
return fac[n] * ( finv[r] * finv[n-r] % mod ) % mod
for i in range(2, N + 1):
fac.append( ( fac[-1] * i ) % mod )
inv.append( mod - ( inv[mod % i] * (mod // i) % mod ) )
finv.append( finv[-1] * inv[-1] % mod )
for i in range(K+1):
L.append( cmb(i+s-1, s-1) * pow(25, i, mod) % mod )
ans = []
for i, x in enumerate(L):
if i == 0:
ans.append(x)
else:
ans.append( ( ans[i-1]*26%mod + x ) % mod )
print(ans[K]) | MOD = 10**9+7
K = int(input())
S = input()
N = len(S)
n = N+K
fac = [1]*(n+1)
rev = [1]*(n+1)
for i in range(1,n+1):
fac[i] = i*fac[i-1]%MOD
rev[i] = pow(fac[i], MOD-2, MOD)
comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%MOD
ans = 0
for i in range(K+1):
ans += pow(26, K-i, MOD) * pow(25, i, MOD) * comb(N+i-1, i)
ans %= MOD
print(ans) | 1 | 12,762,155,131,232 | null | 124 | 124 |
L=int(input())
print(pow(L/3,3)) | L = int(input())
L /= 3
print(L**3)
| 1 | 47,040,637,819,680 | null | 191 | 191 |
K = int(input())
# 10桁までやれば十分
runrun_table = [[0 for _ in range(10)] for _ in range(10)]
# i桁のルンルン数の種類 <= 3**(i-1)*9
for i in range(10):
runrun_table[0][i] = 1
for keta in range(1, 10):
for i in range(10):
if i == 0:
runrun_table[keta][i] = runrun_table[keta - 1][i] + \
runrun_table[keta - 1][i + 1]
elif i == 9:
runrun_table[keta][i] = runrun_table[keta - 1][i - 1] + \
runrun_table[keta - 1][i]
else:
runrun_table[keta][i] = runrun_table[keta - 1][i - 1] + \
runrun_table[keta - 1][i] + \
runrun_table[keta - 1][i + 1]
keta = 0
ans = ''
while sum(runrun_table[keta][1:]) < K:
K -= sum(runrun_table[keta][1:])
keta += 1
for piv in range(1, 10):
if runrun_table[keta][piv] >= K:
ans += str(piv)
keta -= 1
break
K -= runrun_table[keta][piv]
while keta >= 0:
if piv == 0:
piv_range = [0, 1]
elif piv == 9:
piv_range = [8, 9]
else:
piv_range = range(piv-1, piv+2)
for piv in piv_range:
if runrun_table[keta][piv] >= K:
ans += str(piv)
keta -= 1
break
K -= runrun_table[keta][piv]
print(ans)
| n, k, s = map(int,input().split())
if s == 10**9:
ans = [1 for i in range(n)]
for i in range(k):
ans[i] = 10**9
else:
ans = [10**9 for i in range(n)]
for i in range(k):
ans[i] = s
print(" ".join(map(str,ans)))
| 0 | null | 65,332,455,308,956 | 181 | 238 |
n=int(input())
abc = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
ans = ''
while n:
ans += abc[(n-1)%len(abc)]
n = (n-1)//len(abc)
print(ans[::-1])
| n=int(input())
d={}
m=1
for i in range(n):
s=input()
if s in d:
d[s]+=1
m=max(m,d[s])
else:
d[s]=1
se=set()
for i in d:
if d[i]==m:
se.add(i)
se=list(se)
se.sort()
print(*se) | 0 | null | 40,987,537,295,332 | 121 | 218 |
def main():
n, k = map(int, input().split(" "))
h = list(map(int, input().split(" ")))
h.sort(reverse = True)
print(sum(h[k:]))
if __name__ == "__main__":
main() | from sys import exit
from math import gcd
n, m = map(int, input().split())
A = list(map(int, input().split()))
Count = [0] * n
div_A = [a // 2 for a in A]
def lcm(x, y):
return (x * y) // gcd(x, y)
for i, a in enumerate(div_A):
while a % 2 == 0:
Count[i] += 1
a //= 2
if len(set(Count)) != 1:
print(0)
exit()
lcm_num = 1
for div_a in div_A:
lcm_num = lcm(div_a, lcm_num)
if lcm_num > m:
print(0)
exit()
else:
print((m + lcm_num) // (2 * lcm_num))
| 0 | null | 90,525,961,077,640 | 227 | 247 |
n,m = map(int,input().split())
if m != 0:
l = [list(input().split()) for i in range(m)]
p,s = [list(i) for i in zip(*l)]
t = [0] * n
ac = 0
wa = 0
for i in range(m):
if s[i] == 'WA' and t[int(p[i])-1] != 'AC':
t[int(p[i])-1] += 1
elif s[i] == 'AC' and t[int(p[i])-1] != 'AC':
ac += 1
wa += t[int(p[i])-1]
t[int(p[i])-1] = 'AC'
else:
pass
print(ac,wa) | arr = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
arr1 = list(map(int,arr.split(", ") ))
k = int(input())
print(arr1[k-1]) | 0 | null | 71,570,412,161,600 | 240 | 195 |
a = int(input())
print(int(a**2)) | n, p = map(int, input().split())
if p == 2:
s = input()
ans = 0
for i in range(n):
if int(s[i]) % 2 == 0:
ans += i + 1
print(ans)
elif p == 5:
s = input()
ans = 0
for i in range(n):
if int(s[i]) % 5 == 0:
ans += i + 1
print(ans)
else:
s = input()[::-1]
mod = 0
c = [0] * p
c[0] = 1
ten = 1
for i in s:
mod = (mod + ten * int(i)) % p
ten = ten * 10 % p
c[mod] += 1
ans = 0
for i in c:
ans += i * (i - 1) // 2
print(ans) | 0 | null | 101,765,874,969,010 | 278 | 205 |
H,N = map(int,input().split())
A = list(map(int,input().split()))
sum =0
for i in range(len(A)):
sum = sum + A[i]
if sum >= H:
print("Yes")
else:
print("No") | import sys
prm = sys.stdin.readline()
prm = prm.split()
a = int(prm[0])
b = int(prm[1])
c = int(prm[2])
if a < b and b < c :
print 'Yes'
else :
print 'No' | 0 | null | 39,054,160,681,032 | 226 | 39 |
N, M, L = map(int, input().split())
INF = float('inf')
d1 = [[INF]*N for _ in range(N)]
for _ in range(M):
a, b, c = map(int, input().split())
a -= 1
b -= 1
d1[a][b] = c
d1[b][a] = c
for i in range(N):
d1[i][i] = 0
for k in range(N):
for i in range(N):
for j in range(N):
d1[i][j] = min(d1[i][k] + d1[k][j], d1[i][j])
d2 = [[INF]*N for _ in range(N)]
for i in range(N):
for j in range(N):
if i == j:
d2[i][j] = 0
if d1[i][j] <= L and i != j:
d2[i][j] = 1
for k in range(N):
for i in range(N):
for j in range(N):
d2[i][j] = min(d2[i][k] + d2[k][j], d2[i][j])
Q = int(input())
for _ in range(Q):
s, t = map(int, input().split())
s -= 1
t -= 1
if d2[s][t] == INF:
print(-1)
else:
print(d2[s][t]-1)
| from collections import defaultdict
def prime_factors(n):
d = defaultdict(int)
while n%2 == 0:
d[2] += 1
n //= 2
i = 3
while i*i <= n:
while n%i == 0:
d[i] += 1
n //= i
i += 2
if n > 2:
d[n] += 1
return d
MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))
G = defaultdict(int)
for a in A:
pf = prime_factors(a)
for k,v in pf.items():
G[k] = max(G[k], v)
lcm = 1
for k,v in G.items():
lcm *= pow(k, v, MOD)
lcm %= MOD
ans = 0
for a in A:
ans += lcm * pow(a, MOD-2, MOD) % MOD
ans %= MOD
print(ans) | 0 | null | 130,759,995,325,700 | 295 | 235 |
from collections import defaultdict
def main():
n, k = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
ruiseki = [0]
d = defaultdict(int)
d[0]=1
for i in range(n):
if i - k + 1>= 0:
d[ruiseki[i - k+1]]-=1
ruiseki.append((ruiseki[i] + a[i] - 1)%k)
ans += d[ruiseki[i+1]]
d[ruiseki[i + 1]] += 1
print(ans)
if __name__ == '__main__':
main() | N, K = [int(n) for n in input().split()]
A = [int(n) for n in input().split()]
count = 0
for i in range(1,N+1):
A[i-1] = A[i-1]-1
check = {0: [0,1,[0]]}
s = 0
for i in range(1,N+1):
s = (s + A[i-1]) % K
if s in check:
j = check[s][0]
l = check[s][1]
while j < l and i - check[s][2][j] >= K:
j += 1
check[s][0] = j
count += l - j
check[s][2].append(i)
check[s][1] = l + 1
else:
check[s] = [0,1,[i]]
print(count) | 1 | 137,041,743,927,332 | null | 273 | 273 |
import math
x1, y1, x2, y2 = [float(i) for i in input().split()]
distance = math.sqrt((x2 - x1) **2 + (y2 - y1) ** 2)
print(distance) | import math
l=input().split()
x1=float(l[0])
y1=float(l[1])
x2=float(l[2])
y2=float(l[3])
A=math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
print(A)
| 1 | 150,999,928,816 | null | 29 | 29 |
import sys
a = int(sys.stdin.readline().rstrip())
print(a**2) | import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy
sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()
def main():
l='1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51'
a=l.split(', ')
k=I()
return a[k-1]
# main()
print(main())
| 0 | null | 98,114,605,144,632 | 278 | 195 |
# coding: utf-8
x,y=map(int,input().split())
while not(x==0 and y==0):
if x>y:
x,y=y,x
print(str(x)+" "+str(y))
x,y=map(int,input().split()) | import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
n = int(input())
d = set()
for i in range(n):
command,s = input().split()
if command == "insert":
d.add(s)
else:
if s in d:
print("yes")
else:
print("no")
| 0 | null | 309,442,881,760 | 43 | 23 |
# import bisect
from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math
import sys
# import numpy as np
ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)
def main():
h, w, k = list(map(int,ipti().split()))
s = [list(input()) for i in range(h)]
empty_row = []
exist_row = []
berry_id = 1
for row in range(h):
is_empty = True
for col in range(w):
if s[row][col] == "#":
s[row][col] = berry_id
berry_id += 1
is_empty = False
if is_empty:
empty_row.append(row)
else:
exist_row.append(row)
# まず空ではない行を埋める
for row in range(h):
if row in exist_row:
berry_col = deque()
for col in range(w):
if s[row][col] != ".":
berry_col.append(col)
first = 0
fill_id = 0
while berry_col:
last = berry_col.popleft()
fill_id = s[row][last]
for j in range(first, last+1):
s[row][j] =fill_id
first = last + 1
for j in range(first, w):
s[row][j] = fill_id
for row in empty_row:
is_filled = False
for row2 in range(row+1, h):
if row2 in exist_row:
for col in range(w):
s[row][col] = s[row2][col]
is_filled = True
break
if not is_filled:
for row2 in range(row-1, -1 , -1):
if row2 in exist_row:
for col in range(w):
s[row][col] = s[row2][col]
is_filled = True
break
for row in range(h):
print(*s[row])
if __name__ == '__main__':
main() | import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
# map(int, input().split())
H, W, K = map(int, input().split())
A = [0] * H
for i in range(H):
A[i] = input()
X = [[0] * W for _ in range(H)]
cur = 1
for i in range(H):
if A[i].count('#') == 0:
continue
j = 0
k = A[i].find('#')
while j <= k:
X[i][j] = cur
j += 1
while j < W:
while j < W and A[i][j] == '.':
X[i][j] = cur
j += 1
if j < W:
cur += 1
X[i][j] = cur
j += 1
cur += 1
for i in range(H - 2, -1, -1):
for j in range(W):
if X[i][j] == 0:
X[i][j] = X[i + 1][j]
for i in range(1, H):
for j in range(W):
if X[i][j] == 0:
X[i][j] = X[i - 1][j]
for i in range(H):
print(*X[i]) | 1 | 143,257,089,125,440 | null | 277 | 277 |
n,m=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(m)]
for i in range(1001):
i=str(i)
if len(i)!=n:
continue
f=1
for s,c in l:
c=str(c)
if len(i)<s:
f=0
break
if not i[s-1]==c:
f=0
break
if f:
print(i)
exit()
print("-1") | n = int(input())
d = list(map(int ,input().split()))
if d[0] != 0:
print (0)
exit()
d.sort()
mod = 998244353
s = [0 for i in range(max(d)+1)]
for i in range(n):
s[d[i]] += 1
ans = 1
for i in range(len(s)):
if s[i] == 0:
print (0)
exit()
if i == 0:
if s[i] > 1:
print (0)
exit()
continue
ans *= pow(s[i-1],(s[i]),mod)
ans %= mod
print (ans%mod) | 0 | null | 107,781,613,044,432 | 208 | 284 |
def greedyTakahashi(a, b, k):
a -= k
if a < 0:
return (0, b+a) if b+a > 0 else (0, 0)
else :
return (a, b)
def main():
a, b, k = map(int, input().split())
print(*greedyTakahashi(a, b, k))
if __name__ == '__main__':
main() | k = int(input())
s = str(input())
if len(s) > k:
s = s[:k] + '...'
print(s) | 0 | null | 61,858,944,085,022 | 249 | 143 |
n = int(input())
total = 0
for i in range(1, 10**6 + 1):
for j in range(1, 10**6 + 1):
m = n - i * j
if m > 0:
total += 1
else:
break
print(total) | n = int(input())
a = list(map(int, input().split()))
ans_list = [None for _ in range(n)]
for i in range(0, n):
ans_list[a[i] - 1] = str(i + 1)
print(" ".join(ans_list))
| 0 | null | 91,987,610,393,120 | 73 | 299 |
n=int(input())
l=list(map(int,input().split()))
l.sort()
count=0
for i in range(n):
for j in range(i+1,n):
for k in range(j+1,n):
if l[i]+l[j]>l[k] and l[i]!=l[j] and l[j]!=l[k] and l[i]!=l[k]:
count+=1
print(count)
| def main():
import sys
input = sys.stdin.buffer.readline
N, M = (int(i) for i in input().split())
H = [int(i) for i in input().split()]
ans = [1]*N
for _ in range(M):
a, b = (int(i)-1 for i in input().split())
if H[a] < H[b]:
ans[a] = 0
elif H[b] < H[a]:
ans[b] = 0
else:
ans[a] = 0
ans[b] = 0
print(sum(ans))
if __name__ == '__main__':
main()
| 0 | null | 15,020,865,278,120 | 91 | 155 |
import sys
input = sys.stdin.readline
class Dice:
"""
0:top, 1:south, 2:east, 3:west, 4:north, 5:bottom
"""
def __init__(self, surfaces):
self.surface = surfaces
def roll(self, direction: str):
if direction == "E":
self.surface = [self.surface[3], self.surface[1], self.surface[0],
self.surface[5], self.surface[4], self.surface[2]]
elif direction == "N":
self.surface = [self.surface[1], self.surface[5], self.surface[2],
self.surface[3], self.surface[0], self.surface[4]]
elif direction == "S":
self.surface = [self.surface[4], self.surface[0], self.surface[2],
self.surface[3], self.surface[5], self.surface[1]]
elif direction == "W":
self.surface = [self.surface[2], self.surface[1], self.surface[5],
self.surface[0], self.surface[4], self.surface[3]]
return
def get_top(self):
return self.surface[0]
def main():
surface = [int(i) for i in input().strip().split()]
spins = input().strip()
dice = Dice(surface)
for d in spins:
dice.roll(d)
print(dice.get_top())
if __name__ == "__main__":
main()
| import sys,math,collections,itertools
input = sys.stdin.readline
m=10**9+7
"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
def factorization(n):
arr = []
temp = n
i=2
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
for i in range(3, int(-(-n**0.5//1))+1,2):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.append([n, 1])
return arr
N=int(input())
A=list(map(int,input().split()))
d = collections.defaultdict(int)
for a in A:
arr = factorization(a)
for ar in arr:
if d[ar[0]]<ar[1]:
d[ar[0]]=ar[1]
lcm = 1
for key,val in d.items():
lcm = lcm*pow(key,val)
ans = 0
for a in A:
ans = ans+lcm//a
print(ans%m)
| 0 | null | 43,765,533,401,738 | 33 | 235 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.