code1
stringlengths 16
24.5k
| code2
stringlengths 16
24.5k
| similar
int64 0
1
| pair_id
int64 2
181,637B
⌀ | question_pair_id
float64 3.71M
180,628B
⌀ | code1_group
int64 1
299
| code2_group
int64 1
299
|
---|---|---|---|---|---|---|
# -*- coding:utf-8 -*-
import math
r = float(input())
print("{0:f} {1:f}".format(r*r*math.pi,2*r*math.pi)) | import sys
import fractions
input = lambda: sys.stdin.readline().rstrip()
def lcm(x, y):
return (x * y) // fractions.gcd(x, y)
def main():
a, b = map(int, input().split())
print(lcm(a, b))
if __name__ == '__main__':
main() | 0 | null | 56,683,684,171,360 | 46 | 256 |
#get input
n = input()
S = map(lambda x: int(x), input().split(' '))
q = input()
T = list(map(lambda x: int(x), input().split(' ')))
#create T set
T_set = set(T)
#iterate S and counting
count = 0
for i in S:
if i in T_set:
count += 1
T_set.remove(i)
print(count)
| x = input()
for i in range(int(input())):
o = input().split()
a,b = map(int,o[1:3])
b+=1
t = o[0][2]
if t == 'i':
print(x[a:b])
elif t =='p':
x = x[:a] + o[3] + x[b:]
else:
x = x[:a] + x[a:b][::-1] + x[b:]
| 0 | null | 1,064,450,692,700 | 22 | 68 |
n=int(input())
a=list(map(int,input().split()))
money=1000
kabu=0
for i in range(n-1):
if a[i]<a[i+1] and a[i]<=money:
kabu+=money//a[i]
money-=kabu*a[i]
if a[i]>a[i+1] and kabu>0:
money+=kabu*a[i]
kabu=0
if kabu>0:
money+=kabu*a[-1]
print(money)
| import sys
readline = sys.stdin.readline
# 常に金額で持ち、明日のほうが上がるときのみ、必ず買って売るを繰り返す
N = int(readline())
A = list(map(int,readline().split()))
money = 1000
for i in range(N - 1):
if A[i] < A[i + 1]:
kabu = money // A[i]
money %= A[i]
money += kabu * A[i + 1]
print(money) | 1 | 7,291,773,569,188 | null | 103 | 103 |
nm = list(map(int, input().split()))
n = nm[0]
m = nm[1]
l = list(map(int, input().split()))
c = [[0] * (n+1) for i in range(m)]
count = 0
for i in range(1, n+1):
count += 1
c[0][i] = count
for i in range(1, m):
loop = True
count = 0
for j in range(1, n+1):
if j - l[i] >= 0:
if c[i-1][j] > c[i][j-l[i]] + 1:
c[i][j] = c[i][j-l[i]] + 1
else:
c[i][j] = c[i-1][j]
else:
c[i][j] = c[i-1][j]
print(c[-1][-1])
| INF = 10 ** 18
n, m = map(int, input().split())
c = list(map(int, input().split()))
dp = [INF] * (n + 1)
dp[0] = 0
for i in range(m):
for j in range(c[i], n + 1):
dp[j] = min(dp[j], dp[j - c[i]] + 1)
print(dp[n])
| 1 | 146,660,489,228 | null | 28 | 28 |
s=input()
a,b=s.split()
a=int(a)
b=int(b)
print("%d %d"%(a*b,2*a+2*b)) | def main():
n = int(input())
array = [int(x) for x in input().split()]
cnt = 0
for i in range(n):
min_idx = i
for j in range(i+1, n):
if array[min_idx] > array[j]:
min_idx = j
if min_idx != i:
tmp = array[i]
array[i] = array[min_idx]
array[min_idx] = tmp
cnt += 1
print(" ".join(map(str, array)))
print(cnt)
main()
| 0 | null | 164,323,231,982 | 36 | 15 |
N = int(input())
h = [2,4,5,7,9]
p = [0,1,6,8]
b = [3]
if h.count(N%10)==1:
print('hon')
if p.count(N%10)==1:
print('pon')
if b.count(N%10)==1:
print('bon') | n = int(input())
n = n % 10
if n == 3:
print('bon')
elif n == 0 or n == 1 or n == 6 or n == 8:
print('pon')
else:
print('hon')
| 1 | 19,149,441,636,248 | null | 142 | 142 |
while True:
H,W = [int(x) for x in input().split()]
if (H,W)==(0,0): break
for i in range(H):
if i==0 or i==H-1:
print("#"*W)
else:
print("#" + "."*(W-2) + "#")
print("")
| a = []
while True:
d = list(map(int,input().split()))
if d == [0,0]:
break
a.append(d)
for H,W in a:
print('#'*W)
for i in range(0,H-2):
print('#'+'.'*(W-2)+'#')
print('#'*W)
print('') | 1 | 805,871,230,068 | null | 50 | 50 |
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
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
from decimal import *
N = INT()
A = LIST()
ans = INF
A_sum = sum(A)
tmp = 0
for x in A:
tmp += x
ans = min(ans, abs(tmp-(A_sum-tmp)))
print(ans)
| N = int(input())
A = list(map(int, input().split()))
sum_A = sum(A)
sum_now = 0
cost = 99999999999
for a in A:
sum_now += a
cost = min(cost, abs(sum_now - (sum_A - sum_now)))
print(cost)
| 1 | 142,503,210,352,698 | null | 276 | 276 |
import sys
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
m=n//2
if n%2==0:
dp=[[-10**18]*2 for _ in range(m)]
dp[0][0]=a[0]
dp[0][1]=a[1]
for i in range(1,m):
for j in range(2*i,2*(i+1)):
for k in range(2*(i-1),2*i):
if j-k>1:
dp[i][j%2]=max(dp[i][j%2],dp[i-1][k%2]+a[j])
else:
dp=[[-10**18]*3 for _ in range(m)]
dp[0][0]=a[0]
dp[0][1]=a[1]
dp[0][2]=a[2]
for i in range(1,m):
for j in range(2*i,2*(i+1)+1):
for k in range(2*(i-1),2*i+1):
if j-k>1:
dp[i][j-2*i]=max(dp[i][j-2*i],dp[i-1][k-2*(i-1)]+a[j])
print(max(dp[-1])) | n=int(input())
l=list(map(int,input().split()))
m=n//2
t=n%2+2
dp=[0]*t
for i in range(m):
for j in range(t):
dp[j]+=l[2*i+j]
for j in range(1,t):
dp[j]=max(dp[j],dp[j-1])
print(dp[-1]) | 1 | 37,650,702,724,672 | null | 177 | 177 |
import sys
n = int(input())
G = [None]*n
for i in range(n):
u, k, *vs = map(int, input().split())
G[u-1] = [e-1 for e in vs]
from collections import deque
dist = [-1]*n
que = deque([0])
dist[0] = 0
while que:
v = que.popleft()
d = dist[v]
for w in G[v]:
if dist[w] > -1: #already visited
continue
dist[w] = d + 1
que.append(w)
for i in range(n):
print(i+1, dist[i])
| N = int(input())
dp = [[0]*10 for _ in range(10)]
for a in range(N+1):
A = str(a)
dp[int(A[0])][int(A[-1])] += 1
ans = 0
for i in range(1,10):
for j in range(1,10):
ans += dp[i][j]*dp[j][i]
print(ans) | 0 | null | 43,342,135,910,532 | 9 | 234 |
n = int(input())
a = list(map(int, input().split()))
mod = 10**9+7
array_sum = sum(a) % mod
ans = 0
for i in range(n):
ans += a[i] * array_sum % mod
ans -= a[i] * a[i] % mod
print((ans * pow(2,-1,mod)) % mod) | d=int(input())
if d == 1:
print(0)
else:
print(1) | 0 | null | 3,374,036,522,360 | 83 | 76 |
total = 0
n = int(input())
for i in range(1, n + 1):
if not ((i % 5 == 0) or (i % 3 == 0)):
total = total + i
print(total)
| N=int(input())
S=input()
kouho=[]
for n in range(1000):
st=str(n)
if len(st)<=2:
st='0'*(3-len(st))+st
kouho.append(st)
ans=0
for k in kouho:
number=0
for s in S:
if k[number]==s:
number+=1
if number==3:
break
if number == 3:
ans += 1
print(ans)
| 0 | null | 81,445,849,172,828 | 173 | 267 |
N, P = map(int, input().split())
S = input()
ans = 0
if P == 2 or P == 5:
for i, s in enumerate(S):
if int(s) % P == 0:
ans += i + 1
else:
counts = [0] * P
h = 0
d = 1
for s in reversed(S):
m = int(s) * d % P
h = (h + m) % P
counts[h] += 1
d = (d * 10) % P
ans = counts[0]
for i in counts:
ans += (i*(i-1))//2
print(ans)
| ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
n,p = mi()
s = input()
srev = s[::-1]
if p == 2 or p == 5:
ans = 0
for i in range(n):
if int(s[i]) % p == 0:
ans += i +1
print(ans)
exit()
acum = []
from collections import defaultdict
d = defaultdict(lambda :0)
d = [0] * p
num = 0
tenpow = 1
for i in range(0,n):
a = int(srev[i])
a = num + a *tenpow
tenpow = tenpow * 10 % p
modd = a % p
num = modd
d[modd] += 1
acum.append((modd,d[modd]))
ans = d[0]
for i in range(n):
ans += d[acum[i][0]] - acum[i][1]
print(ans)
| 1 | 58,169,175,380,892 | null | 205 | 205 |
K, N = map(int,input().split())
A = [int(a) for a in input().split()]
dif = [A[i+1] - A[i] for i in range(N-1)]
dif.append(K + A[0] - A[N-1])
print(K - max(dif)) | k, n = map(int, input().split())
a = sorted(list(map(int, input().split())))
x = [(a[i]-a[i-1]) for i in range(1,n)]
x.append(k-a[n-1]+a[0])
y=sorted(x)
print(sum(y[:-1]))
| 1 | 43,461,603,923,458 | null | 186 | 186 |
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**5)
def geta(fn=lambda s: s.decode()):
return map(fn, readline().split())
def gete(fn=lambda s: s.decode()):
return fn(readline().rstrip())
def main():
s, t = geta()
print(t + s)
if __name__ == "__main__":
main() | def q1():
S, T = input().split()
print('{}{}'.format(T, S))
if __name__ == '__main__':
q1()
| 1 | 103,036,679,993,408 | null | 248 | 248 |
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.readline
read = sys.stdin.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
from itertools import combinations, product
#import bisect# lower_bound etc
#import numpy as np
def run():
N,K = map(int, read().split())
k = int(math.log(N, 10))
s = N // (10 ** k)
tmp1, tmp2, div = 1, 1, 1
for i in range(K-1):
tmp1 *= k-i
div *= i+1
tmp2 *= 9
ret = tmp1//div * tmp2
ret *= s-1
tmp1 *= k - (K-1)
tmp2 *= 9
div *= K
ret += tmp1 * tmp2 // div
lis = range(k)
nums = range(1,10)
base = s * 10 ** k
for A in combinations(lis, K-1):
for X in product(nums, repeat = K-1):
tmp = base
for a,x in zip(A,X):
tmp += 10 ** a * x
if tmp <= N:
ret += 1
print(ret)
if __name__ == "__main__":
run() | N=input()
K=int(input())
l=len(N)
dp=[[[0]*(K+2) for _ in range(2)] for _ in range(l+1)]
dp[0][1][0]=1
for i,c in enumerate(N):
x=int(c)
for j in range(2):
for d in range(x+1 if j==1 else 10):
for k in range(K+1):
dp[i+1][x==d if j==1 else 0][k+1 if 0<d else k]+=dp[i][j][k]
print(dp[l][0][K]+dp[l][1][K]) | 1 | 75,994,959,117,310 | null | 224 | 224 |
x, y = map(int, input().split())
while y>0: x, y = y, x%y
print(x) | a, b = map(int, raw_input().split())
def gcd(a,b):
c = a%b
if c==0:
return b
elif c == 1:
return c
else:
return gcd(b, c)
if a > b:
print gcd(a, b)
elif a < b:
print gcd(b, a)
else:
print a | 1 | 7,963,765,930 | null | 11 | 11 |
n, k = map(int, input().split())
sunukes = [0 for i in range(n)]
for i in range(k):
d = int(input())
aa = list(map(int, input().split()))
for j in range(d):
sunukes[aa[j] - 1] += 1
count = sum(1 for sunuke in sunukes if sunuke == 0)
print(count)
| N, K = map(int, input().split())
count = 0
num_people = []
num_people_snacks = []
for i in range(1, N + 1):
num_people.append(i)
while K > count:
d = int(input())
A = list(map(int, input().split()))
for k in A:
num_people_snacks.append(k)
count += 1
ans = 0
for j in range(N):
if num_people[j] not in num_people_snacks:
ans += 1
print(ans) | 1 | 24,600,121,221,588 | null | 154 | 154 |
from bisect import bisect_left
from itertools import accumulate
n, m = map(int, input().split())
hands = [int(x) for x in input().split()]
increasing = sorted(hands)
hands = list(reversed(increasing))
xs = [0] + list(accumulate(hands))
max_x = 2 * 10**5 + 1
min_x = 0
def canGet(x):
count = 0
for hand in increasing:
idx = bisect_left(increasing, x-hand)
count += n - idx
return count >= m
while max_x - min_x > 1:
# left
mid = (max_x + min_x) // 2
if canGet(mid):
min_x = mid
else:
max_x = mid
ans = 0
count = 0
for Ai in hands:
idx = bisect_left(increasing, min_x-Ai)
ans += Ai*(n-idx) + xs[n-idx]
count += n-idx
print(ans-(count-m)*min_x)
|
S = list(input())
K = int(input())
N = len(S)
# print(S)
# dp[i][j][k]
dp = [[[0] * 2 for _ in range(K+2)] for _ in range(N+1)]
dp[0][0][0] = 1
# 上の桁から調べていく
for i in range(1, N + 1):
for j in range(K + 1):
for k in range(2):
for num in range(10):
if num == 0:
inc = 0
else:
inc = 1
# N未満が確定していれば0-9の全ての遷移が可能なので加える
if k == 1:
dp[i][j+inc][k] += dp[i - 1][j][k]
else:
if num < int(S[i-1]):
# k = 1が確定
dp[i][j + inc][1] += dp[i - 1][j][k]
elif num == int(S[i-1]):
# k = 0のまま
dp[i][j + inc][0] += dp[i - 1][j][k]
# print(dp)
print(dp[N][K][0] + dp[N][K][1]) | 0 | null | 92,032,146,334,934 | 252 | 224 |
#http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_B&lang=jp
def merge(target_list, left_index, right_index):
global count
mid_index = (left_index + right_index) // 2
l = target_list[left_index:mid_index] + [pow(10,9) + 1]
r = target_list[mid_index:right_index] + [pow(10,9) + 1]
l_target = 0
r_target = 0
#print(left_index, right_index, mid_index, l,r)
for k in range(left_index, right_index):
count += 1
if l[l_target] < r[r_target]:
target_list[k] = l[l_target]
l_target += 1
else:
target_list[k] = r[r_target]
r_target += 1
#print(target_list)
def merge_sort(target_list, left_index, right_index):
if left_index + 1 < right_index:
mid_index = (left_index + right_index) // 2
merge_sort(target_list, left_index, mid_index)
merge_sort(target_list, mid_index, right_index)
merge(target_list, left_index, right_index)
if __name__ == "__main__":
l = input()
target_list = [int(a) for a in input().split()]
global count
count = 0
merge_sort(target_list, 0, len(target_list))
print(" ".join([str(n) for n in target_list]))
print(count) | n, k = map(int, input().split())
a = [int(x) for x in input().split()]
for i in range(n-k):
if a[i+k] > a[i]:
print("Yes")
else:
print("No") | 0 | null | 3,566,597,396,800 | 26 | 102 |
h = int(input())
w = int(input())
n = int(input())
if h >= w:
larger = h
else:
larger = w
if n % larger == 0:
print(n // larger)
else:
print(n // larger + 1) | def main():
h = int(input())
w = int(input())
n = int(input())
a = max(h, w)
print((n + a - 1) // a)
if __name__ == "__main__":
main()
| 1 | 88,990,999,763,542 | null | 236 | 236 |
import sys
input = lambda: sys.stdin.readline().rstrip()
S = input()
print("ABC" if S == "ARC" else "ARC") | print(f'A{["B","R"]["B"==input()[1]]}C') | 1 | 24,204,128,880,726 | null | 153 | 153 |
n = int(input())
adjMat = [[-1]*n for i in range(n)]
for i in range(n):
a = int(input())
for j in range(a):
x, y = map(int, input().split())
adjMat[i][x-1] = y
ans = 0
for i in range(1 << (n)):
#print (bin(i))
success = True
for j in range(n):
if i & 2**j:
for k in range(n):
if k == j:
continue
if i & 2**k == 0 and adjMat[j][k] == 1:
success = False
if i & 2**k > 0 and adjMat[k][j] == 0:
success = False
#print (j, k, adjMat[j][k], adjMat[k][j], success)
if not success:
break
if success:
i2 = i
c = 0
while i2 > 0:
c += i2 & 1
i2 //= 2
ans = max(c, ans)
print (ans) | N=int(input())
Ins=[[] for _ in range(N)]
ans=0
#0-indexedにしておく
for i in range(N):
A=int(input())
for _ in range(A):
x,y=map(int,input().split())
Ins[i].append((x-1,y))
for i in range(2**N):
flag=1
honest=[]
unkind=[]
for j in range(N):
if (i>>j)&1:
honest.append(j)
else:
unkind.append(j)
#ここまでは想定の組み合わせを作る作業
for k in honest:
#honestな人の証言を見ていく
for l in Ins[k]:
if l[1]==1 and l[0] in unkind:
flag=0
break
#honestな人がある人物をhonestと答えたのにも関わらず
#その人がunkindに入るような組み合わせは駄目...ケース1
elif l[1]==0 and l[0] in honest:
flag=0
break
#honestな人がある人物をunkindと答えたのにも関わらず
#その人がhonestに入るような組み合わせは駄目...ケース2
if flag==1:
ans=max(ans,len(honest))
#ケース1にもケース2にも該当しない場合
#現在のhonestの人数をansと比較して大きい方を採用
print(ans) | 1 | 121,430,272,433,024 | null | 262 | 262 |
N,M = map(int,input().split())
S = input()
c = 0
flag = 0
for i in S:
if i == '0':
if c >= M:
flag = 1
break
c = 0
else:
c += 1
if flag == 1:
print(-1)
else:
T = S[::-1]
now = 0
ans = []
while now != N:
delta = 0
for i in range(1,M+1):
if now + i == N:
delta = i
break
if T[now+i] == '0':
delta = i
ans.append(delta)
now += delta
Answer = ans[::-1]
print(*Answer) | # coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop
import copy
import numpy as np
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)
def lcm(a, b): return a * b / gcd(a, b)
# 1 2 3
# a, b, c = LI()
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
# a = I()
def I(): return int(sys.stdin.buffer.readline())
# abc def
# a, b = LS()
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
# a = S()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
# 2
# 1
# 2
# [1, 2]
def IR(n): return [I() for i in range(n)]
# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]
def LIR(n): return [LI() for i in range(n)]
# 2
# abc
# def
# [abc, def]
def SR(n): return [S() for i in range(n)]
# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]
def LSR(n): return [LS() for i in range(n)]
# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]
def SRL(n): return [list(S()) for i in range(n)]
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
fact = [1, 1] # n! mod p
factinv = [1, 1] # (n!)^(-1) mod p
tmp = [0, 1] # factinv 計算用
def main():
x, y = LI()
ans = 0
if x > 2 * y or x < 0.5 * y or (x + y) % 3 != 0:
print(0)
return
n, m = map(int, [(2 * y - x) / 3, (2 * x - y) / 3])
for i in range(2, n + m + 1):
fact.append((fact[-1] * i) % mod)
tmp.append((-tmp[mod % i] * (mod // i)) % mod)
factinv.append((factinv[-1] * tmp[-1]) % mod)
print(cmb(n+m, n, mod))
if __name__ == "__main__":
main()
| 0 | null | 144,467,117,805,362 | 274 | 281 |
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9
def main():
s,t = input().split()
print(t+s)
if __name__ == '__main__':
main()
|
S, T = input().split()
print(T, S, sep='')
| 1 | 102,949,698,810,182 | null | 248 | 248 |
n=int(input())
a=list(map(int,input().split()))
l=[0,0,0]
mod=10**9+7
ans=1
for i in a:
ans*=l.count(i)
ans%=mod
for j in range(3):
if l[j]==i:
l[j]+=1
break
print(ans) | MOD = 10**9 + 7
class ModInt:
def __init__(self, x):
self.x = x % MOD
def __str__(self):
return str(self.x)
__repr__ = __str__
def __add__(self, other):
return (
ModInt(self.x + other.x) if isinstance(other, ModInt) else
ModInt(self.x + other)
)
def __sub__(self, other):
return (
ModInt(self.x - other.x) if isinstance(other, ModInt) else
ModInt(self.x - other)
)
def __mul__(self, other):
return (
ModInt(self.x * other.x) if isinstance(other, ModInt) else
ModInt(self.x * other)
)
def __truediv__(self, other):
return (
ModInt(
self.x * pow(other.x, MOD - 2, MOD)
) if isinstance(other, ModInt) else
ModInt(self.x * pow(other, MOD - 2, MOD))
)
def __pow__(self, other):
return (
ModInt(pow(self.x, other.x, MOD)) if isinstance(other, ModInt) else
ModInt(pow(self.x, other, MOD))
)
__radd__ = __add__
def __rsub__(self, other):
return (
ModInt(other.x - self.x) if isinstance(other, ModInt) else
ModInt(other - self.x)
)
__rmul__ = __mul__
def __rtruediv__(self, other):
return (
ModInt(
other.x * pow(self.x, MOD - 2, MOD)
) if isinstance(other, ModInt) else
ModInt(other * pow(self.x, MOD - 2, MOD))
)
def __rpow__(self, other):
return (
ModInt(pow(other.x, self.x, MOD)) if isinstance(other, ModInt) else
ModInt(pow(other, self.x, MOD))
)
def solve(N, A):
ret = ModInt(1)
count = [3 if not i else 0 for i in range(N + 1)]
for a in A:
ret *= count[a]
if not ret:
break
count[a] -= 1
count[a + 1] += 1
return ret
if __name__ == "__main__":
N = int(input())
A = list(map(int, input().split()))
print(solve(N, A)) | 1 | 130,288,834,976,818 | null | 268 | 268 |
i = int(input())
print(i*i*i) | n = int(input())
x = list(map(float, input().split()))
y = list(map(float, input().split()))
list=[]
for j in range(3):
D=0
for i in range(n):
if x[i]<y[i]:
d = (y[i]-x[i])
else:
d = (x[i]-y[i])
list.append(d)
D += (d**(j+1))
print(f"{D**(1/(j+1)):.6f}")
print(f"{max(list):.6f}")
| 0 | null | 246,804,595,422 | 35 | 32 |
import sys
input = sys.stdin.readline
a, b = input()[:-1].split()
print(min(''.join(a for i in range(int(b))), ''.join(b for i in range(int(a))))) | line = list(input().split())
line.sort()
print(line[0] * int(line[1])) | 1 | 84,117,749,025,332 | null | 232 | 232 |
X, K, D = map(int, input().split())
XX = abs(X)
if XX > K*D:
print(XX - K*D)
else:
if (K - X//D)%2 == 0:
print(X%D)
else:
print(abs(X%D -D))
| # AOJ ITP1_11_A
# サイコロ。
def intinput():
a = input().split()
for i in range(len(a)):
a[i] = int(a[i])
return a
class dice:
def __init__(self):
self.data = [0 for i in range(8)]
a = intinput()
for i in range(1, 7): self.data[i] = a[i - 1] # 1, 2, 3, 4, 5, 6.
for i in range(6): self.data[0] += a[i] # 各位の和を0に。
self.data[7] = a[0] * a[5] + a[1] * a[4] + a[2] * a[3] # 対面同士の積の和。
# dataの1, 2, 3, 4, 5, 6というindexが位置を示す。
# 回転するとそれらの位置にある数が変化するイメージ。
def d_read(self, a):
# aはたとえば5, 1, 2, 6のような配列
b = []
for i in range(len(a)): b.append(self.data[a[i]])
return b
def d_write(self, b, c):
# cはたとえば1, 2 ,6, 5のような配列で、そこにbの中身を落とす。
if len(b) != len(c): return # 要求と異なる。
for i in range(len(b)): self.data[c[i]] = b[i]
def roll(self, direction):
# directionが'S', 'E', 'W', 'N'.
# 'S', 'N'では3と4が不変。 'E'と'W'では2と5が不変。
if direction == 'S':
self.d_write(self.d_read([5, 1, 2, 6]), [1, 2, 6, 5])
elif direction == 'N':
self.d_write(self.d_read([2, 6, 5, 1]), [1, 2, 6, 5])
elif direction == 'W':
self.d_write(self.d_read([3, 6, 4, 1]), [1, 3, 6, 4])
elif direction == 'E':
self.d_write(self.d_read([4, 1, 3, 6]), [1, 3, 6, 4])
def get_upper(self):
return self.data[1]
def main():
d = dice()
command = input()
for i in range(len(command)):
d.roll(command[i])
print(d.get_upper())
if __name__ == "__main__":
main()
| 0 | null | 2,720,394,282,258 | 92 | 33 |
n, m = [int(i) for i in input().split()]
vec = []
for i in range(n):
vec.append([int(j) for j in input().split()])
c = []
for i in range(m):
c.append(int(input()))
for i in range(n):
sum = 0
for j in range(m):
sum += vec[i][j]*c[j]
print(sum) | n, m = map(int, raw_input().split())
a, b = [], []
c = [0 for _ in range (n)]
for _ in range(n):
a.append(map(int, raw_input().split()))
for _ in range(m):
b.append(int(raw_input()))
for i in range(n):
c[i] = 0
for j in range(m):
c[i] += a[i][j]*b[j]
print c[i] | 1 | 1,185,831,880,858 | null | 56 | 56 |
n = int(input())
chars = 'Xabcdefghijklmnopqrstuvwxyz'
res = ''
while True:
x = n%26 #最下位の位の文字を求める(係数が26でない最下位の位が余りとして出せる)
if x == 0: #Xが26のときのみ余り0で対応させるため26に書き換え
x = 26
res += chars[x] #文字を正解リストに追加
n -= x #xを左辺に持っていって右辺で10の位以上の数値を調べる
if n == 0 :
break
n //= 26 #n-xは必ず26の倍数になっている。(xを移項しているから自明)
#最下位の位を余りとして扱うために26で割って係数を消している。
print(res[::-1])#resには1の位が一番初めに入っているので、反転させて表示 | N = int(input())
ans = []
if N <= 26:
print(chr(96 + N))
else:
while N != 0:
val = N % 26
if val == 0:
val = 26
N = N //26 - 1
else:
N //= 26
ans.append(chr(96 + val))
ans.reverse()
print(''.join(ans))
| 1 | 11,825,210,651,970 | null | 121 | 121 |
N, K = map(int, input().split())
R, S, P = map(int, input().split())
dic = {'r':P, 's':R, 'p':S}
flag = [0]*N
rlt = 0
T = input()
for i in range(N):
if i < K or T[i] != T[i-K] or flag[i-K] == 1:
rlt += dic[T[i]]
else:
flag[i] = 1
print(rlt) | a,b=map(int,input().strip().split())
print(a*b) | 0 | null | 61,041,199,493,010 | 251 | 133 |
import sys
sys.setrecursionlimit(2**20)
n, m, k = map(int, input().split())
ab = []
for _ in range(m):
ab.append([int(x)-1 for x in input().split()])
cd = []
for _ in range(k):
cd.append([int(x)-1 for x in input().split()])
group = [-1 for _ in range(n)]
lis = [[] for _ in range(n)]
for x in ab:
a = x[0]
b = x[1]
lis[a].append(b)
lis[b].append(a)
g_n = 0
def dfs(now):
global g_n
group[now] = g_n
global group_len_n
group_len_n += 1
for i in lis[now]:
if group[i] == -1:
dfs(i)
group_len = []
for i in range(n):
if group[i] == -1:
group_len_n = 0
dfs(i)
group_len.append(group_len_n)
g_n += 1
friend = [0 for _ in range(n)]
block = [0 for _ in range(n)]
for x in ab:
a = x[0]
b = x[1]
if group[a] == group[b]:
friend[a] += 1
friend[b] += 1
for x in cd:
c = x[0]
d = x[1]
if group[c] == group[d]:
block[c] += 1
block[d] += 1
ans = []
for i in range(n):
ans.append(str(group_len[group[i]] - friend[i] - block[i] -1))
print(" ".join(ans)) | n,m,k=map(int,input().split())
par = [-1]*n
num = [0]*n
def find(x):
if par[x]<0:
return x
else:
par[x] = find(par[x])
return par[x]
def union(x, y):
p,q=find(x), find(y)
if p==q:
return
if p>q:
p,q = q,p
par[p] += par[q]
par[q] = p
def size(x):
return -par[find(x)]
def same(x,y):
return find(x)==find(y)
for i in range(m):
a,b=map(int,input().split())
a-=1
b-=1
union(a,b)
num[a]+=1
num[b]+=1
for i in range(k):
c,d=map(int,input().split())
c-=1
d-=1
if same(c,d):
num[c]+=1
num[d]+=1
for i in range(n):
print(size(i)-1-num[i], end=" ") | 1 | 61,670,490,225,212 | null | 209 | 209 |
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) | k=int(input())
a=[]
judge=0
a.append("")
a.append(7%k)
for i in range(2,k+1):
a.append((a[i-1]*10+7)%k)
for i in range(1,k+1):
if a[i]==0:
print(i)
judge=1
break
if judge==0:
print(-1)
| 1 | 6,065,812,816,350 | null | 97 | 97 |
num = list(map(int,input().split()))
num.sort()
print("%d %d %d" %(num[0],num[1],num[2]))
| num = input().split()
num.sort()
print(num[0], num[1], num[2]) | 1 | 425,598,780,660 | null | 40 | 40 |
N,K=map(int,input().split())
P=list(map(int,input().split()))
X=[]
for a in P:
X.append(a/2+0.5)
gou=sum(X[0:K])
han=-32
saigou=sum(X[N-K:N])
han=saigou
for a in range(N-K-1):
if gou>han:
han=gou
gou=gou-X[a]+X[a+K]
print(han) | N, K = map(int, input().split())
P = tuple(map(int, input().split()))
PMAX = 1000
s = [0] * (PMAX + 1)
for i in range(PMAX):
s[i+1] = s[i] + (i + 1)
e = [0] * (N + 1)
for i, p in enumerate(P):
e[i+1] = e[i] + (s[p] / p)
ans = 0
for i in range(N - K + 1):
ans = max(ans, e[i+K] - e[i])
print(ans) | 1 | 74,807,606,087,612 | null | 223 | 223 |
def main():
s, t = map(str, input().split())
a, b = map(int, input().split())
u = str(input())
if s == u:
print(a-1, b)
else:
print(a, b-1)
if __name__ == "__main__":
main()
| # https://atcoder.jp/contests/abc145/tasks/abc145_d
class Combination: # 計算量は O(n_max + log(mod))
def __init__(self, n_max, mod=10**9+7):
self.mod = mod
f = 1
self.fac = fac = [f]
for i in range(1, n_max+1): # 階乗(= n_max !)の逆元を生成
f = f * i % mod # 動的計画法による階乗の高速計算
fac.append(f) # fac は階乗のリスト
f = pow(f, mod-2, mod) # 階乗から階乗の逆元を計算。フェルマーの小定理より、 a^-1 = a^(p-2) (mod p) if p = prime number and p and a are coprime
# python の pow 関数は自動的に mod の下での高速累乗を行ってくれる
self.facinv = facinv = [f]
for i in range(n_max, 0, -1): # 上記の階乗の逆元から階乗の逆元のリストを生成(= facinv )
f = f * i % mod
facinv.append(f)
facinv.reverse()
# "n 要素" は区別できる n 要素
# "k グループ" はちょうど k グループ
def __call__(self, n, r): # self.C と同じ
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
def C(self, n, r):
if not 0 <= r <= n: return 0
return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod
X, Y = map(int, input().split())
if (2*Y- X) % 3 or (2*X- Y) % 3:
print(0)
exit()
x = (2*Y - X) // 3
y = (2*X - Y) // 3
n = x + y
r = x
mod = 10**9 + 7
f = 1
for i in range(1, n + 1):
f = f*i % mod
fac = f
f = pow(f, mod-2, mod)
facinv = [f]
for i in range(n, 0, -1):
f = f*i % mod
facinv.append(f)
facinv.append(1)
comb = Combination(n)
print(comb.C(n,r)) | 0 | null | 111,151,430,969,722 | 220 | 281 |
num = input().split()
nums = []
for i in num:
nums.append(int(i))
#print(nums)
price = [300000, 200000, 100000]
result = []
#2 3 4 5 6
for i in nums:
if int(i) > 3:
result.append(0)
else:
result.append(price[i-1])
value = result[0] + result[1]
if value == 600000:
print("1000000")
else:
print(value) | x,y=map(int,input().split())
if x==y==1:
print(1000000);exit()
A=[300000,200000,100000]+[0]*1000
print(A[x-1]+A[y-1])
| 1 | 140,277,140,444,480 | null | 275 | 275 |
X,Y,A,B,C=map(int,input().split())
ls_a=sorted(list(map(int,input().split())))
ls_b=sorted(list(map(int,input().split())))
ls_c=sorted(list(map(int,input().split())))
ls_x=ls_a[A-X:A]
ls_y=ls_b[B-Y:B]
ls_c.reverse()
ans=sum(ls_x)+sum(ls_y)
a=b=c=0
for _ in range(min([X+Y,C])):
if a==len(ls_x):
m=min([ls_y[b],ls_c[c]])
if m==ls_y[b]:
ans+=(-ls_y[b]+ls_c[c])
b+=1
c+=1
else:
break
elif b==len(ls_y):
m=min([ls_x[a],ls_c[c]])
if m==ls_x[a]:
ans+=(-ls_x[a]+ls_c[c])
a+=1
c+=1
else:
break
else:
m=min([ls_x[a],ls_y[b],ls_c[c]])
if m==ls_x[a]:
ans+=(-ls_x[a]+ls_c[c])
a+=1
c+=1
elif m==ls_y[b]:
ans+=(-ls_y[b]+ls_c[c])
b+=1
c+=1
else:
break
print(ans) | 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()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)
s = p[:x] + q[:y]
s.sort()
ans = sum(s)
for si, ri in zip(s, r):
if si < ri:
ans += ri - si
print(ans) | 1 | 44,971,185,419,050 | null | 188 | 188 |
# coding: utf-8
import sys
def merge(A, left, mid, right):
global count
L = A[left:mid]
R = A[mid:right]
L.append(sys.maxsize)
R.append(sys.maxsize)
i = 0
j = 0
for k in range(left,right):
if L[i] <= R[j]:
A[k] = L[i]
i += 1
else:
A[k] = R[j]
j += 1
count += 1
def mergeSort(A, left, right):
if left+1 < right:
mid = int((left + right)/2);
mergeSort(A, left, mid)
mergeSort(A, mid, right)
merge(A, left, mid, right)
n = int(input().rstrip())
A = list(map(int,input().rstrip().split()))
count = 0
mergeSort(A, 0, n)
print(" ".join(map(str,A)))
print(count)
| #http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_B&lang=jp
def merge(target_list, left_index, right_index):
global count
mid_index = (left_index + right_index) // 2
l = target_list[left_index:mid_index] + [pow(10,9) + 1]
r = target_list[mid_index:right_index] + [pow(10,9) + 1]
l_target = 0
r_target = 0
#print(left_index, right_index, mid_index, l,r)
for k in range(left_index, right_index):
count += 1
if l[l_target] < r[r_target]:
target_list[k] = l[l_target]
l_target += 1
else:
target_list[k] = r[r_target]
r_target += 1
#print(target_list)
def merge_sort(target_list, left_index, right_index):
if left_index + 1 < right_index:
mid_index = (left_index + right_index) // 2
merge_sort(target_list, left_index, mid_index)
merge_sort(target_list, mid_index, right_index)
merge(target_list, left_index, right_index)
if __name__ == "__main__":
l = input()
target_list = [int(a) for a in input().split()]
global count
count = 0
merge_sort(target_list, 0, len(target_list))
print(" ".join([str(n) for n in target_list]))
print(count) | 1 | 116,173,667,860 | null | 26 | 26 |
while True:
n,x = [int(x) for x in input().split()]
if (n,x)==(0,0): break
cnt=0
if 3*(n-1) >= x: # If n-2 + n-1 + n < x, there is no combination
a_max = x//3 - 1 # a_max + a_max+1 + a_max+2 = x
if 2*n-1 < x:
a_min = x - (2*n-1) # set minimum value of a
else:
a_min = 1
for a in range(a_min,a_max+1):
b_max = (x-a-1)//2 # b_max + b_max+1 <= x-a
b_min = (x-a) - n # set minimum value of b
b_min = b_min if b_min > a+1 else a+1
cnt += b_max - b_min + 1
print(cnt) | from sys import stdin
def main():
for l in stdin:
n, x = map(int, l.split(' '))
if 0 == n == x:
break
print(len(num_sets(n, x)))
def num_sets(n, x):
num_sets = []
for i in range(1, n-1):
for j in [m for m in range(i+1, n)]:
k = x - (i+j)
if n < k:
continue
if k <= j:
break
num_sets.append((i, j, k))
return num_sets
if __name__ == '__main__': main() | 1 | 1,304,360,948,672 | null | 58 | 58 |
import math
def int_ceil(src, range):
return int(math.ceil(src/float(range)) * range)
def main():
week = int(input())
debt = 100000
for _ in range(week):
risi = debt * 0.05
debt = int_ceil(debt + risi, 1000)
print(debt)
if __name__ == "__main__":
main()
| h, w, f = list(map(int, input().split()))
c = [input() for i in range(h)]
count = 0
bit_h = []
for k in range(2**h):
hh = []
for l in range(h):
if((k >> l) & 1):
hh.append(1)
else:
hh.append(0)
bit_h.append(hh)
bit_w = []
for i in range(2**w):
ww = []
for j in range(w):
if((i >> j) & 1):
ww.append(1)
else:
ww.append(0)
bit_w.append(ww)
ans = 0
for i in range(len(bit_h)):
for j in range(len(bit_w)):
count = 0
for k in range(h):
for l in range(w):
if bit_h[i][k] == 1 and bit_w[j][l] == 1 and c[k][l] == "#":
count += 1
if count == f:
ans += 1
print(ans)
| 0 | null | 4,485,495,193,532 | 6 | 110 |
def main():
s = input()
t = input()
length = len(s)
ans = 0
for i in range(length):
if s[i] != t[i]:
ans += 1
print(ans)
if __name__ == "__main__":
main()
| a = list(input())
b = list(input())
ans = 0
for p, q in zip(a, b):
if p != q:
ans += 1
print(ans)
| 1 | 10,433,942,214,290 | null | 116 | 116 |
import sys
sys.setrecursionlimit(10**6) #再帰関数の上限
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False):
inds=sorted(range(len(s)), key=lambda k: s[k])
if return_sorted: return inds, [s[i] for i in inds]
return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
K,N,M=len(B),len(A),len(B[0])
return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
N=len(v)
size=len(M)
return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def main():
mod = 10**9+7
#w.sort(key=itemgetter(1),reversed=True) #二個目の要素で降順並び替え
N = int(input())
#N, K = map(int, input().split())
#A = tuple(map(int, input().split())) #1行ベクトル
#L = tuple(int(input()) for i in range(N)) #改行ベクトル
s = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
l=[(s[i][0]+s[i][1],s[i][0]-s[i][1]) for i in range(N)]
l.sort()
cur=l[0][0]
ans=1
for rob in l[1:]:
if cur>rob[1]:
continue
ans+=1
cur=rob[0]
print(ans)
if __name__ == "__main__":
main() | n = int(input())
X = [[] for _ in range(n)]
for i in range(n):
x,l = list(map(int, input().split()))
X[i] = [x-l,x+l]
X.sort(key = lambda x: x[1])
cnt = 1
mx = X[0][1]
for i in range(1,n):
if mx <= X[i][0]:
cnt += 1
mx = X[i][1]
print(cnt) | 1 | 89,792,144,547,536 | null | 237 | 237 |
#!/usr/bin/env python3
import sys
import collections as cl
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
N = input()
print('Yes' if N[2] == N[3] and N[4] == N[5] else 'No')
main()
| chars = [c for c in input()]
print('Yes' if chars[2] == chars[3] and chars[4] == chars[5] else 'No') | 1 | 42,179,624,197,800 | null | 184 | 184 |
N, M = (int(x) for x in input().split())
print(int(N*(N-1)/2 + M*(M-1)/2)) | K = int(input())
s = ''
for i in range(K):
s = s + 'ACL'
print(s) | 0 | null | 23,721,373,241,708 | 189 | 69 |
if __name__ == '__main__':
s = input()
t = input()
if s == t[:-1]:
print("Yes")
else:
print("No")
| S = input()
T = input()
if S == T[:-1]:
print('Yes')
else:
print('No')
| 1 | 21,483,950,702,572 | null | 147 | 147 |
def cub():
x = input()
print x ** 3
cub() | x=input()
print x*x*x | 1 | 278,961,992,960 | null | 35 | 35 |
N,K=map(int, input().split())
AA=list(map(int, input().split()))
A=sorted(AA)
B=sorted(AA)[::-1]
mod=10**9+7
def cmb(n, r, mod):
if ( r<0 or r>n ):
return 0
r = min(r, n-r)
return g1[n] * g2[r] * g2[n-r] % mod
mod = 10**9+7 #出力の制限
n = 10**5+1
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, n+1 ):
g1.append( ( g1[-1] * i ) % mod )
inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
g2.append( (g2[-1] * inverse[-1]) % mod )
ans=0
for i in range(N-K+1):
d=(A[K-1+i]%mod)*cmb(K-1+i,K-1,mod)
e=(B[K-1+i]%mod)*cmb(K-1+i,K-1,mod)
ans+=d%mod-e%mod
ans%=mod
print(ans)
| a = list(map(int,input().split()))
ans = "unsafe" if a[1]>=a[0] else "safe"
print(ans) | 0 | null | 62,153,955,542,940 | 242 | 163 |
n = int(input())
result = 100000
for i in range(0,n):
result = result * 1.05
if result % 1000 == 0:
pass
else:
result = result-(result % 1000)+ 1000
result = int(result)
print(result) | import math
n = input()
money = 100000
for i in range(0, n):
money = money*1.05
money /= 1000
money = int(math.ceil(money)*1000)
print money | 1 | 1,433,970,790 | null | 6 | 6 |
a,b,c,k=map(int,open(0).read().split())
for i in' '*k:
if a>=b:b*=2
elif b>=c:c*=2
print('NYoe s'[a<b<c::2]) | (r1,g1,b1)=input().split()
(r,g,b)=(int(r1),int(g1),int(b1))
k=int(input())
flg=0
for i in range(k):
if not g > r :
g *= 2
elif not b > g:
b *= 2
if ( b > g > r):
print ("Yes")
else:
print ("No")
| 1 | 6,839,492,735,520 | null | 101 | 101 |
n = int(input())
arr = list(map(int,input().split()))
cur=1000
for i in range(n-1):
p=0
if arr[i] < arr[i+1]:
p=cur // arr[i]
cur += (arr[i+1] - arr[i])*p
print(cur)
| N = int(input())
A = list(map(int, input().split()))
ans = 1000
for i in range(N - 1):
a = A[i]
if a < A[i + 1]:
units = ans // a
ans = (ans - units * a) + units * A[i + 1]
# print(i, ans)
print(ans)
| 1 | 7,307,481,148,692 | null | 103 | 103 |
import sys
w = sys.stdin.readline().strip().lower()
cnt = 0
while True:
line = sys.stdin.readline().strip()
if line == 'END_OF_TEXT':
break
words = line.split(' ')
for i in words:
if i.lower() == w:
cnt += 1
print(cnt) | #!python3
# import numpy as np
# input
K = int(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]
ans = l[K-1]
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 25,897,630,531,958 | 65 | 195 |
S = input()
def is_kaibun(s):
return s[:len(s)//2] == s[:(len(s)-1)//2:-1]
flg = is_kaibun(S) and is_kaibun(S[:len(S)//2]) and is_kaibun(S[:len(S)//2:-1])
print('Yes' if flg else 'No') | #B
S=input()
N=len(S)
con_2=S[:(N-1)//2]
con_3=S[((N+3)//2-1):]
if S==S[::-1] and con_2==con_2[::-1] and con_3==con_3[::-1]:
print('Yes')
else:
print('No') | 1 | 46,227,639,096,782 | null | 190 | 190 |
from collections import Counter
ans = 0
H, W, M = map(int, input().split())
HW = set()
Hlist, Wlist = [], []
for _ in range(M):
h, w = map(int, input().split())
Hlist.append(h)
Wlist.append(w)
HW.add((h,w))
cntH = Counter(Hlist)
cntW = Counter(Wlist)
maxhk, maxhv = cntH.most_common()[0]
ans = max(ans, maxhv)
for i in range(1,1+W):
tmp = cntW[i]
if (maxhk, i) in HW:
tmp -= 1
ans = max(ans, tmp+maxhv)
maxwk, maxwv = cntW.most_common()[0]
ans = max(ans, maxwv)
for i in range(1,1+H):
tmp = cntH[i]
if (i, maxwk) in HW:
tmp -= 1
ans = max(ans, tmp+maxwv)
print(ans)
| from collections import defaultdict,Counter
h,w,m = map(int,input().split())
w_list = []
h_list = []
se = set()
for _ in range(m):
nh,nw = map(int,input().split())
se.add((nh,nw))
w_list.append(nw)
h_list.append(nh)
w_count = Counter(w_list)
h_count = Counter(h_list)
max_w = 0
max_h = 0
ch = []
cw = []
for i in w_count.values():
max_w = max(max_w,i)
cw.append(i)
for i in h_count.values():
max_h = max(max_h,i)
ch.append(i)
ma = ch.count(max_h)*cw.count(max_w)
result = max_h+max_w
point = 0
for i,j in se:
if w_count[j] == max_w and h_count[i] == max_h:
point += 1
if point == ma:
print(result-1)
else:
print(result) | 1 | 4,775,678,670,124 | null | 89 | 89 |
s=list(input())
t=list(input())
flag=0
if (len(s)+1)==len(t):
for i in range(len(s)):
if s[i]!=t[i]:
flag=1
if flag==1:
print('No')
else:
print('Yes')
else:
print('No') | s = input()
t = input()
c = 0
for i in range(len(s)) :
if s[i] != t[i] :
c = 1
if c == 1 :
print('No')
else :
print('Yes') | 1 | 21,419,844,606,210 | null | 147 | 147 |
def bingo(appear):
for j in range(3):
if appear[0][j] and appear[1][j] and appear[2][j]:
return "Yes"
for i in range(3):
if appear[i][0] and appear[i][1] and appear[i][2]:
return "Yes"
if appear[0][0] and appear[1][1] and appear[2][2]:
return "Yes"
if appear[0][2] and appear[1][1] and appear[2][0]:
return "Yes"
return "No"
card = []
for _ in range(3):
arr = list(map(int, input().split()))
card.append(arr)
appear = [[False for _ in range(3)] for _ in range(3)]
n = int(input())
for _ in range(n):
a = int(input())
for i in range(3):
for j in range(3):
if a == card[i][j]:
appear[i][j] = True
print(bingo(appear)) | A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]
for b in B:
for y in range(3):
for x in range(3):
if A[y][x] == b:
A[y][x] = -1
for y in range(3):
if sum(A[y]) == -3:
print("Yes")
exit()
for x in range(3):
if A[0][x] == A[1][x] == A[2][x] == -1:
print("Yes")
exit()
if A[0][0] == A[1][1] == A[2][2] == -1 or A[2][0] == A[1][1] == A[0][2] == -1:
print("Yes")
exit()
print("No")
| 1 | 59,874,190,911,938 | null | 207 | 207 |
while 1:
w,h=map(int,raw_input().split())
if(w==0):break
a,b="#\n";print a*h+b+(a+"."*(h-2)+a+b)*(w-2)+a*h+b | S = input()
if len(S) % 2 == 0 and S == "hi" * (len(S) // 2 ):
print("Yes")
else:
print("No") | 0 | null | 27,155,962,609,632 | 50 | 199 |
a=input()
n=int(input())
for i in range(n):
b=input().split()
if b[0]=='print':
print(a[int(b[1]):int(b[2])+1])
elif b[0]=='replace':
a=a[:int(b[1])]+b[3]+a[int(b[2])+1:]
elif b[0]=='reverse':
c=(a[int(b[1]):int(b[2])+1])
c=c[::-1]
a=a[:int(b[1])]+c+a[int(b[2])+1:]
| N = int(input())
print((10**N - 9**N - 9**N + 8**N) % (10**9+7)) | 0 | null | 2,625,500,744,818 | 68 | 78 |
h,n=map(int, input().split())
a=[0]*n
b=[0]*n
for i in range(n):
a[i],b[i]=map(int,input().split())
max_a=max(a)
dp=[float("inf")]*(h+max_a+1)
dp[0]=0
for i in range(h):
for j in range(n):
dp[i+a[j]] = min(dp[i+a[j]], dp[i]+b[j])
print(min(dp[h:])) | S, T = [input() for _ in range(2)]
cnt = 0
for i, c in enumerate(S):
if c != T[i]:
cnt += 1
print(cnt) | 0 | null | 46,060,717,012,882 | 229 | 116 |
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
k = int(input())
keta = 1
mod = 7%k
while keta < 10**7:
if mod==0:
print(keta)
break
keta += 1
mod = (mod*10 + 7)%k
else:
print(-1)
if __name__=='__main__':
main() | k = int(input())
ans = 1
a = 7 % k
while a != 0:
ans += 1
a = (10*a + 7) % k
if ans == 10**6:
ans = -1
break
print(ans) | 1 | 6,128,325,131,802 | null | 97 | 97 |
class Node:
def __init__(self,v):
self.v = v
self.next = None
class Queue:
def __init__(self):
self.head = None
self.tail = None
self.size = 0
def enqueue(self,v):
self.size += 1
n = Node(v)
if self.tail == None:
self.tail = n
else:
self.tail.next = n
self.tail = n
if self.head == None:
self.head = self.tail
def dequeue(self):
if self.size == 0:
print 'underflow'
exit()
self.size -= 1
v = self.head.v
self.head = self.head.next
if self.head == None:
self.tail = None
return v
#class Queue:
# def __init__(self,l):
# self.values = []
# self.l = l
# for _ in range(l):
# self.values.append(None)
# self.head = 0
# self.tail = 0
# def inc(self,n):
# if n+1 >= self.l:
# return 0
# else:
# return n+1
# def enqueue(self,v):
# if self.inc(self.head) == self.tail:
# print 'overflow'
# exit()
# self.values[self.head] = v
# self.head = self.inc(self.head)
# def dequeue(self):
# if self.head == self.tail:
# print 'underflow'
# exit()
# v = self.values[self.tail]
# self.tail = self.inc(self.tail)
# return v
# def size(self):
# if self.head >= self.tail:
# return self.head-self.tail
# else:
# self.head + (self.l-self.tail)
n,q = map(int,raw_input().split(' '))
queue = Queue()
for _ in range(n):
n,t = raw_input().split(' ')
t = int(t)
queue.enqueue((n,t))
c = 0
while queue.size>0:
n,t = queue.dequeue()
if t <= q:
c += t
print n,c
else:
queue.enqueue((n,t-q))
c += q | x, y = [ int(i) for i in input().split()]
if x > y:
x, y = y, x
while True:
if x % y:
x, y = y, x % y
continue
break
print(y)
| 0 | null | 24,335,534,436 | 19 | 11 |
str = input()
lstr = list(str)
num = int(input())
for i in range(num):
order = input().split()
if (order[0] == "print"):
onum = list(map(int,order[1:3]))
for i in range(onum[0],onum[1]+1):
print(lstr[i],end = "")
print("")
elif (order[0] == "reverse"):
onum = list(map(int,order[1:3]))
if (onum[0] == 0):
tmp1 = lstr[0:onum[1]+1]
tmp1.reverse()
tmp2 = lstr[onum[1]+1:]
lstr = tmp1 + tmp2
else:
tmp1 = lstr[:onum[0]]
tmp2 = lstr[onum[0]:onum[1]+1]
tmp2.reverse()
tmp3 = lstr[onum[1]+1:]
lstr = tmp1 + tmp2 +tmp3
elif (order[0] == "replace"):
onum = list(map(int,order[1:3]))
restr = list(order[3])
for i in range(onum[0],onum[1]+1):
lstr[i] = restr[i-onum[0]]
| S = str(input())
for i in range(int(input())):
L = input().split()
o = L[0]
a = int(L[1])
b = int(L[2]) + 1
if len(L) == 4:
p = L[3]
else:
p = 0
if o == "print":
print(S[a:b])
elif o == "reverse":
S = S[:a]+S[a:b][::-1]+S[b:]
elif o == "replace":
S = S[:a]+p+S[b:]
| 1 | 2,072,885,024,320 | null | 68 | 68 |
s=int(input())
print(s//3600, (s%3600)//60, s%60, sep=':')
| import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
n = I()
s = S()
rgb = [None for _ in range(n)]
rgb_acc = [None for _ in range(n)]
rgb_st = {"R","G","B"}
rgb_lst = ["R","G","B"]
for i, char in enumerate(s):
if char == "R":
rgb[i] = [1,0,0]
elif char == "G":
rgb[i] = [0,1,0]
else:
rgb[i] = [0,0,1]
rgb_acc[0] = rgb[0]
for i in range(1, n):
rgb_acc[i] = rgb_acc[i-1][:]
index = 0 if s[i]=="R" else 1 if s[i]=="G" else 2
rgb_acc[i][index] += 1
ans = 0
for i in range(n-2):
for j in range(i+1,n-1):
if s[i]!=s[j]:
ex = rgb_st - {s[i], s[j]}
ex = ex.pop()
index = 0 if ex=="R" else 1 if ex=="G" else 2
cnt = rgb_acc[n-1][index]-rgb_acc[j][index]
if j+1 <= 2*j-i < n:
if s[2*j-i] == ex:
cnt -= 1
ans += cnt
print(ans)
main() | 0 | null | 18,197,446,372,612 | 37 | 175 |
S =input()
if len(S) % 2 != 0:
print('No')
exit()
for i in range(0,len(S),2):
if S[i:i+2] != 'hi':
print('No')
exit()
print('Yes') | import sys
s = input()
def match(a):
if a[0:2] == 'hi':
return a[2:]
else:
print('No')
sys.exit()
if len(s)%2 == 1:
print('No')
sys.exit()
else:
while len(s) > 1:
s = match(s)
print('Yes') | 1 | 52,956,510,928,322 | null | 199 | 199 |
A,B = input().split()
import decimal as d
d.getcontext().rounding = d.ROUND_DOWN
ans = round(d.Decimal(A)*d.Decimal(B),0)
print(ans)
| def input_int():
return map(int, input().split())
def one_int():
return int(input())
def one_str():
return input()
def many_int():
return list(map(int, input().split()))
import math
from decimal import Decimal
A, B = input().split()
# A=int(A)
# B=float(B)
temp = Decimal(A)*Decimal(B)
print(int(math.floor(temp))) | 1 | 16,618,630,989,618 | null | 135 | 135 |
a,b = map(int,input().split())
li = []
for i in range(1,10):
for j in range(1,10):
if i==a and j == b:
print(a*b)
exit()
print(-1) | while True:
sum = 0
input_str = input()
if input_str == '0':
break
for chr in input_str:
sum += int(chr)
print(sum)
| 0 | null | 79,806,701,895,060 | 286 | 62 |
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()))
p.sort(reverse=True)
q.sort(reverse=True)
r.sort()
R = p[:X]
G = q[:Y]
i = X - 1
j = Y - 1
con = True
while con and len(r) > 0:
rr = r.pop()
if R[i] < G[j]:
if R[i] < rr:
R[i] = rr
i -= 1
continue
else:
con = False
else:
if G[j] < rr:
G[j] = rr
j -= 1
continue
else:
con = False
print(sum(R) + sum(G)) | def solve(x, y, a, b, c, p, q, r):
p = sorted(p)[::-1]
q = sorted(q)[::-1]
r = sorted(r)[::-1]
v = sorted(p[:x] + q[:y])
n = len(v)
t = sum(v)
for i in range(min(n,c)):
if v[i] < r[i]:
t += r[i] - v[i]
return t
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()))
print(solve(x, y, a, b, c, p, q, r)) | 1 | 44,947,290,088,160 | null | 188 | 188 |
n,a,b=map(int,input().split())
res=n//(a+b)*a
if n%(a+b)>=a:
res+=a
else:
res+=n%(a+b)
print(res) | n, a, b = list(map(int, input().split()))
whole = n // (a + b)
rest = n % (a + b)
blue = whole * a
if rest <= a:
blue += rest
else:
blue += a
print(blue) | 1 | 55,331,139,142,422 | null | 202 | 202 |
s=input()
t=input()
count_min = 1000
for i in range(len(s)-len(t)+1):
count = 0
for j in range(len(t)):
if s[i+j] != t[j]:
count+=1
if count < count_min:
count_min = count
print(count_min) | x = int(input())
if -40 <= x and x <= 40:
if x >= 30:
print("Yes")
else:
print("No") | 0 | null | 4,676,776,218,690 | 82 | 95 |
n,k = map(int,input().split())
print(min(n%k,-((n%k)-k))) | [N, K] = [int(i) for i in input().split()]
print(min(N%K, -N%K)) | 1 | 39,346,548,108,840 | null | 180 | 180 |
input()
A = [int(i) for i in input().split()]
c = 0
def bubble_sort(A):
global c
flag = True
while flag:
flag = False
for i in range(len(A)-1, 0, -1):
if A[i] < A[i -1]:
A[i], A[i -1] = A[i -1], A[i]
c += 1
flag = True
bubble_sort(A)
print(*A)
print(c)
| N = int(input())
D = []
count = 0
for i in range(N):
d = list(map(int,input().split()))
D.append(d)
for i in range(N-2):
if (D[i][0]==D[i][1]) and (D[i+1][0]==D[i+1][1]) and (D[i+2][0]==D[i+2][1]):
print("Yes")
break
else:
print("No")
| 0 | null | 1,257,412,724,528 | 14 | 72 |
n,a,b = map(int,input().split())
t = n // (a+b)
ans = t*a
s = n % (a+b)
if s <= a:
ans += s
else:
ans += a
print(ans) | S = input()
if S[-1] != "s" :
print(S + "s")
elif S[-1] == "s" :
print(S + "es")
else :
print(" ") | 0 | null | 28,926,596,723,870 | 202 | 71 |
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mat = lambda x, y, v: [[v]*y for _ in range(x)]
ten = lambda x, y, z, v: [mat(y, z, v) for _ in range(x)]
mod = 1000000007
sys.setrecursionlimit(1000000)
N = ri()
C = rs()
l, r = 0, N-1
ans = 0
while l < r:
while C[l] == 'R' and l < N-1:
l += 1
while C[r] == 'W' and r > 0:
r -= 1
if l >= r: break
l += 1
r -= 1
ans += 1
print(ans) | import sys
def gcd(a,b):
a,b=max(a,b),min(a,b)
while a%b:
a,b=b,a%b
return b
def lcm(a,b):
return a//gcd(a,b)*b
for i in sys.stdin:
a,b=map(int,i.split())
print(gcd(a,b),lcm(a,b)) | 0 | null | 3,145,089,418,240 | 98 | 5 |
import math
N = int(input())
MOD_VALUE = math.pow(10, 9) + 7
def pow_mod(value, pow):
ret = 1
for _ in range(pow):
ret = ret * value % MOD_VALUE
return ret
result = pow_mod(10, N) - pow_mod(9, N) * 2 + pow_mod(8, N)
print(int(result % MOD_VALUE))
| n,t = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
ab.sort() # 食べるのが早い順にソート
# ナップザック問題に落とし込む
dp = [[0 for i in range(t+1)]for j in range(n+1)]
for i in range(n):
ti,vi = ab[i]
for j in range(t+1):
# 食べたほうがよい(t秒以内かつ満足度が上がるならば)
if j + ti <= t:
dp[i+1][j+ti] = max(dp[i+1][j+ti],dp[i][j]+vi)
# 食べなかった場合の最高値を更新
dp[i+1][j] = max(dp[i][j],dp[i+1][j])
ma = 0
for i in range(n):
# 最後にi番目の皿を食べることができる
ma = max(ma,dp[i][t-1]+ab[i][1])
print(ma) | 0 | null | 77,155,809,645,838 | 78 | 282 |
import math
n = int(input())
x = n * (n + 1) / 2
f = math.floor(n / 3)
fizzsum = f * (f + 1) / 2 * 3
b = math.floor(n / 5)
buzzsum = b * (b + 1) / 2 * 5
fb = math.floor(n / 15)
fizzbuzzsum = fb * (fb + 1) / 2 * 15
print(int(x - fizzsum - buzzsum + fizzbuzzsum)) | import numpy as np
N,M = map(int,input().split())
A = list(map(int,input().split()))
Amax=max(A)
n0 = 2**int(np.ceil(np.log2(2*Amax+1)))#Amax+1以上となる最小の2のべき乗数
Afre=np.zeros(n0).astype(int)#パワーの頻度(1~Amax+1)
for i in range(N):
Afre[A[i]]+=1
#astype(int)は切り捨てなので,rintで四捨五入してから.
S = np.rint(np.fft.irfft(np.fft.rfft(Afre)*np.fft.rfft(Afre))).astype(int)
Scum =S.cumsum()#累積和
bd = N*N-M#上からM個を取り出したい
i=np.searchsorted(Scum,bd)#価値iを生み出せる組みがM個以上ある
#価値iが生み出せる選び方の余分なものを引きたい
remove=((Scum[-1]-Scum[i])-M)*i
ans=0
for j in range(i+1,n0):
ans+=S[j]*j
print(ans-remove) | 0 | null | 71,449,379,535,420 | 173 | 252 |
N = int(input())
A = list(map(int,input().split()))
cnt = {}
for i in A:
if i in cnt:
cnt[i] += 1
else:
cnt[i] = 1
total = 0
for i in cnt:
if cnt[i]>=2:
total += cnt[i] * (cnt[i]-1) // 2
for i in A:
if cnt[i] == 1:
print(total)
else:
#print(total - cnt[i]* (cnt[i]-1) // 2 + (cnt[i]-1) * (cnt[i]-2) // 2)
print(total - (cnt[i]-1)) | """ スニペット """
def get_int():
return int(input())
def get_ints():
return list(map(int, input().split()))
""" スニペット """
import math
# 2つ選ぶ通り数を算出 nC2
def choose2(n):
return math.floor(n*(n-1)/2)
# インプット
N = get_int()
An = get_ints()
""" 全ての要素から2つのボールを選ぶ通り数を求める """
uni = [0] * (N+1)
# ユニーク数の配列を求める
for i in range(N):
uni[An[i]] += 1
sumWay = 0
# 各数値の2通りの選択通り数を足していく ここのindex=0がいらない
for i in range(N+1):
sumWay += choose2(uni[i])
""" 全ての要素数 - 削除する要素の通り数 + 削除する要素を引いた際の通り数 を求める """
for i in range(N):
print(sumWay - choose2(uni[An[i]]) + choose2(uni[An[i]]-1)) | 1 | 47,890,397,825,468 | null | 192 | 192 |
x = int(input())
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def lcm(a, b):
return a*(b//gcd(a, b))
print(lcm(360, x)//x)
| # coding:utf-8
n, k = map(int,raw_input().split())
ws = []
for _ in xrange(n):
ws.append(int(raw_input()))
def possible_put_p(p):
# P??\?????????????????????????????????
current = 1
weight = 0
for w in ws:
if weight + w <= p:
weight += w
else:
current += 1
if current > k:
return False
weight = w
if current <= k:
return True
else:
return False
low = max(ws)
high = sum(ws)
while(high - low > 0):
mid = (low + high) / 2
if(possible_put_p(mid)):
high = mid
else:
low = mid + 1
print high | 0 | null | 6,616,858,140,060 | 125 | 24 |
number = input().split(" ")
print(int(number[0]) * int(number[1])) | a,b = map(int,input().split())
ans=a*b
print(ans) | 1 | 15,849,356,684,252 | null | 133 | 133 |
n = int(input())
dic = {}
total = 0
for _ in range(n):
s, t = input().split()
total += int(t)
dic[s] = total
x = input()
total -= dic[x]
print(total) | N=int(input())
s=[]
t=[]
for i in range(N):
x,y=input().split()
s.append(x)
t.append(int(y))
X=input()
begin_idx=s.index(X)+1
print(sum(t[begin_idx:]))
| 1 | 96,759,704,533,728 | null | 243 | 243 |
N = int(input())
edges = [[] for _ in range(N)]
for i in range(N - 1):
fr, to = map(lambda a: int(a) - 1, input().split())
edges[fr].append((i, to))
edges[to].append((i, fr))
ans = [-1] * (N - 1)
A = [set() for _ in range(N)]
st = [0]
while st:
now = st.pop()
s = 1
for i, to in edges[now]:
if ans[i] != -1:
continue
while s in A[now]:
s += 1
ans[i] = s
A[to].add(s)
A[now].add(s)
st.append(to)
print(max(ans))
print(*ans, sep="\n")
| from collections import deque
n=int(input())
ab=[[] for _ in range(n+1)]
for i in range(n-1):
a,b=map(int,input().split())
ab[a].append([b,i])
que=deque()
que.append(1)
visited=[0]*(n)
ans=[0]*(n-1)
while que:
x=que.popleft()
k=1
for j in ab[x]:
if visited[x-1]!=k:
ans[j[1]]+=k
visited[j[0]-1]+=k
k+=1
que.append(j[0])
else:
ans[j[1]]+=(k+1)
visited[j[0]-1]+=(k+1)
k+=2
que.append(j[0])
print(max(ans))
for l in ans:
print(l) | 1 | 136,479,858,788,898 | null | 272 | 272 |
while True:
line = list(map(int, input().split()))
if line==[0,0]: break
print(' '.join(map(str,sorted(line)))) | N = int(input())
A = [int(i) for i in input().split()]
counter = 0
for i in range(N):
minj = i
for j in range(i, N):
if A[j] < A[minj]:
minj = j
if A[i] != A[minj]:
A[i], A[minj] = A[minj], A[i]
counter += 1
print(' '.join([str(A[i]) for i in range(N)]))
print(counter) | 0 | null | 277,395,605,028 | 43 | 15 |
#%%
N, K = map(int,input().split())
MOD = 10**9 + 7
#%%
ans = 0
gcds = [0]*(K+1)
for i in reversed(range(1, K+1)):
gcds[i] = pow(K//i, N, MOD)
idx = i*2
while idx<K+1:
gcds[i] -= gcds[idx] + MOD
gcds[i] %= MOD
idx += i
ans += (i * gcds[i])
ans %= MOD
print(ans)
| N,K = [int(x) for x in input().split()]
count = [0]*(K+1)
ans = 0
mod = 1000000007
for i in range(K,0,-1):
kosuu = pow(K//i,N,mod)
if K // i >= 2:
for j in range(K//i,1,-1):
kosuu -= count[j*i]
ans += i*kosuu
count[i] = kosuu
print(ans%mod) | 1 | 36,697,133,187,562 | null | 176 | 176 |
def main():
h = int(input())
w = int(input())
n = int(input())
if n % max(h,w) == 0:
print(n//max(h,w))
else:
print(n//max(h,w) + 1)
if __name__=='__main__':
main()
| w = input().lower()
count = 0
while True:
s = input()
if s == "END_OF_TEXT":
break
count += s.lower().split().count(w)
print(count) | 0 | null | 45,097,766,031,670 | 236 | 65 |
x,y =map(int,input().split())
if y-2*x >=0 and (y-2*x)%2 ==0 and 4*x-y >=0 and (4*x-y)%2 ==0:
print('Yes')
exit()
print('No') | X, Y = [int(v) for v in input().split()]
ans = "No"
for c in range(X + 1):
t = X - c
if 2 * c + 4 * t == Y:
ans = "Yes"
break
# if ans == "No":
# for t in range(X + 1):
# c = X - t
# if 2 * c + 3 * t == Y:
# ans = "Yes"
# break
print(ans) | 1 | 13,875,639,847,680 | null | 127 | 127 |
n = int(input())
s = input()
nr = s.count('R')
nw = len(s)-nr
a = ('R'*nr)+('W'*nw)
c = 0
for i in range(n):
if(s[i:i+1] != a[i:i+1]):
c += 1
print(c // 2) | def main():
N = int(input())
C = list(input())
C_ = sorted(C)
wr = rw = 0
for i in range(len(C_)):
if C[i] != C_[i]:
if C[i] == "R" and C_[i] == "W":
rw += 1
else:
wr += 1
print(max(wr, rw))
if __name__ == "__main__":
main() | 1 | 6,290,043,563,804 | null | 98 | 98 |
while True:
H,W = map(int,input().split())
if H ==0 and W == 0:
break
for i in range (H):
for j in range (W):
if i == 0 or i == H-1:
print('#', end = "")
elif j == 0 or j == (W-1):
print('#', end = "")
else:
print('.', end = "")
print("")
print("") | n = int(input())
for i in range(n):
print("ACL", end="")
| 0 | null | 1,507,562,605,022 | 50 | 69 |
n, a, b = map(int, input().split())
mod = 10**9+7
ans = pow(2, n, mod)-1
modp = mod # 素数であることが前提
max_r = 10 ** 7 # 必要分だけ用意する 10**7が限度
factinv = [1, 1] + [0]*max_r # factinv[n] = ((n!)^(-1) mod modp)
inv = [0, 1] + [0]*max_r # factinv 計算用
fact = {}
def cmb(n, r, p):
assert n < p, 'n is less than modp'
assert r < max_r, 'n in less than max_n'
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
if (n, r) in fact:
return fact[(n, r)] * factinv[r] % p
else:
f = 1
for i in range(n, n-r, -1):
f = f * i % p
fact[(n, r)] = f
return f * factinv[r] % p
for i in range(2, max_r + 1):
inv[i] = (-inv[modp % i] * (modp // i)) % modp
factinv[i] = (factinv[i-1] * inv[i]) % modp
ans-=cmb(n, a, mod)
ans-=cmb(n, b, mod)
print(ans%mod)
| import math
a, b, x = map(int,input().split())
s = a
t = 2*(b-x/(a*a))
u = x*2/(b*a)
if t<=b:
print(math.degrees(math.atan(t/s)))
else:
print(math.degrees(math.atan(b/u))) | 0 | null | 115,029,349,667,694 | 214 | 289 |
N = int(input())
music = []
for i in range(N):
music.append(input().split())
X = (input())
Time = 0
kama = False
for s,t in music:
if kama:
Time += int(t)
if s == X:
kama = True
print(Time) | data=str(input("")).split(" ")
D=int(data[0])
T=int(data[1])
S=int(data[2])
if D<=T*S:
print("Yes")
else:
print("No") | 0 | null | 50,307,458,695,812 | 243 | 81 |
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
from collections import Counter
n = int(input())
c = list(input())
d = Counter(c)
# print(d)
# print(d["R"])
e=Counter(c[:d["R"]])
# print(e["R"])
print(d["R"]-e["R"]) | 0 | null | 68,874,816,648,708 | 269 | 98 |
n,m=map(int,input().split())
s=input()[::-1]
if "1"*m in s:
print(-1)
exit(0)
ans=[]
cur=0
while cur<len(s):
for j in range(m,0,-1):
if cur+j>=len(s):
continue
if s[cur+j]=="0":
cur=cur+j
ans.append(j)
break
if cur==len(s)-1:
break
ans=ans[::-1]
print(*ans) | import bisect
N = int(input())
Ls = list(map(int, input().split(" ")))
Ls.sort()
ans = 0
for i in range(0,N-2):
for j in range(i+1,N-1):
k = bisect.bisect_left(Ls,Ls[i]+Ls[j])
ans += k - (j + 1)
print(ans) | 0 | null | 155,110,233,152,612 | 274 | 294 |
import math
mod = 1000000007
n = int(input())
zero = 0
dic = {}
dic[(0, 1.5)] = 0
dic[(1.5, 0)] = 0
for i in range(n):
ai, bi = map(int, input().split())
idx = (ai, bi)
if ai < 0:
ai, bi = -ai, -bi
if idx == (0, 0):
zero += 1
elif idx[0] == 0:
dic[(0, 1.5)] += 1
elif idx[1] == 0:
dic[(1.5, 0)] += 1
else:
g = math.gcd(abs(ai), abs(bi))
ai = ai // g
bi = bi // g
idx = (ai, bi)
if idx in dic:
dic[idx] += 1
else:
dic[idx] = 1
ans = 1
already = set([])
for key, value in dic.items():
if key in already: continue
a, b = key
if a == 1.5 or b == 1.5:
pair1 = dic[(0, 1.5)]
pair2 = dic[(1.5, 0)]
ans = (ans * (pow(2, pair1, mod)+pow(2, pair2, mod)-1)) % mod
already.add((0, 1.5))
already.add((1.5, 0))
else:
if b > 0: idx = (b, -a)
else: idx = (-b, a)
if idx in dic:
pair1 = dic[key]
pair2 = dic[idx]
ans = (ans * (pow(2, pair1, mod)+pow(2, pair2, mod)-1)) % mod
already.add(key)
already.add(idx)
else:
pair1 = dic[key]
ans = (ans * pow(2, pair1, mod)) % mod
already.add(key)
ans = (ans + zero - 1) % mod
print(ans) | mod = 1000000007
n = int(input())
ab00 = 0
abx0 = 0
ab0x = 0
p = []
m = []
from math import gcd
for _ in range(n):
i, j = map(int, input().split())
if i == 0:
if j == 0:
ab00 += 1
else:
ab0x += 1
continue
elif j == 0:
abx0 += 1
continue
k = gcd(i, j)
i //= k
j //= k
if i > 0:
if j > 0:
p.append((i, j))
else:
m.append((-j, i))
elif j > 0:
m.append((j, -i))
else:
p.append((-i, -j))
m.sort()
p.sort()
ans = pow(2, ab0x, mod) + pow(2, abx0, mod) - 1
ans %= mod
mi = 0
pi = 0
while mi < len(m) and pi < len(p):
if m[mi] == p[pi]:
mi += 1
mnum = 1
while mi < len(m) and m[mi] == m[mi-1]:
mi += 1
mnum += 1
pi += 1
pnum = 1
while pi < len(p) and p[pi] == p[pi-1]:
pi += 1
pnum += 1
ans *= pow(2, mnum, mod) + pow(2, pnum, mod) - 1
ans %= mod
elif m[mi] < p[pi]:
mi += 1
mnum = 1
while mi < len(m) and m[mi] < p[pi]:
mi += 1
mnum += 1
ans *= pow(2, mnum, mod)
ans %= mod
else:
pi += 1
pnum = 1
while pi < len(p) and p[pi] < m[mi]:
pi += 1
pnum += 1
ans *= pow(2, pnum, mod)
ans %= mod
ans *= pow(2, len(p) - pi, mod)
ans %= mod
ans *= pow(2, len(m) - mi, mod)
ans %= mod
ans = (ans - 1 + ab00) % mod
print(ans) | 1 | 21,033,027,570,210 | null | 146 | 146 |
import sys
input = sys.stdin.readline
h,w,m = map(int,input().rstrip().split())
hw = [list(map(int,input().rstrip().split()))for _ in range(m)]
tate = [0]*(h+1)
yoko = [0]*(w+1)
bombpoint = set()
for x,y in hw:
tate[x] += 1
yoko[y] += 1
bombpoint.add((x,y))
ans_x = []
ans_y = []
x_max = max(tate)
y_max = max(yoko)
for i in range(len(tate)):
if tate[i] == x_max:
ans_x.append(i)
for i in range(len(yoko)):
if yoko[i] == y_max:
ans_y.append(i)
ans = x_max + y_max
for x in ans_x:
for y in ans_y:
if (x,y) not in bombpoint:
print(ans)
exit()
print(ans - 1) | import sys
H,W,M=map(int,input().split())
hlist=[0]*H
wlist=[0]*W
hwset=set()
for _ in range(M):
h,w=map(int,input().split())
hlist[h-1]+=1
wlist[w-1]+=1
hwset.add((h-1,w-1))
hmax=max(hlist)
hlist2=[]
for i in range(H):
if hlist[i]==hmax:
hlist2.append(i)
wmax=max(wlist)
wlist2=[]
for i in range(W):
if wlist[i]==wmax:
wlist2.append(i)
#print(hlist2,wlist2)
H2=len(hlist2)
W2=len(wlist2)
if H2*W2>M:
print(hmax+wmax)
else:
for i in range(H2):
ii=hlist2[i]
for j in range(W2):
jj=wlist2[j]
if not (ii,jj) in hwset:
print(hmax+wmax)
sys.exit(0)
else:
print(hmax+wmax-1) | 1 | 4,706,899,755,892 | null | 89 | 89 |
#ALDS1_1_D
N = int(input())
min,dif = 10000000000, -10000000000
for i in range(N):
a = int(input())
if (a - min) > dif:
dif = a - min
if a < min:
min = a
print(dif)
| n = int(input())
maximum_profit = -10**9
r0 = int(input())
r_min = r0
for i in range(1, n):
r1 = int(input())
r_min = min(r0, r_min)
maximum_profit = max(maximum_profit, r1 - r_min)
r0 = r1
print(maximum_profit) | 1 | 12,420,292,352 | null | 13 | 13 |
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():
K = i_input()
print("ACL" * K)
if __name__ == "__main__":
main()
| K = int(input())
Ans = 'ACL'
for i in range(K-1):
Ans += 'ACL'
print(Ans) | 1 | 2,190,554,255,112 | null | 69 | 69 |
N = int(raw_input())
A = map(int, raw_input().split())
def selectionSort(A, N):
count = 0
for i in range(0, N):
minj = i
for j in range(i, N):
if A[j] < A[minj]:
minj = j
if i != minj:
temp = A[i]
A[i] = A[minj]
A[minj] = temp
count += 1
return count
count = selectionSort(A, N)
print " ".join(map(str, A))
print count | #B問題
#ABSの定石使うとなぜかRE
#今回はPython解説サイト参照
#①入力を文字列で受け取る→②一文字ずつ整数に変換して、forループで回しながら足し算する
N = input()
cur = 0
for i in N:
cur += int(i)
if cur % 9 == 0:
print("Yes")
else:
print("No") | 0 | null | 2,187,784,224,508 | 15 | 87 |
from itertools import accumulate
N, K = map(int, input().split())
*A, = map(int, input().split())
for i in range(K):
a = [0]*N
allN = True
for j in range(N):
l, r = max(j-A[j], 0), (j+A[j]+1)
a[l] += 1
if r < N:
a[r] -= 1
if A[j] != N:
allN = False
A = list(accumulate(a))
if allN:
break
print(*A)
| import sys
import math,bisect
sys.setrecursionlimit(10 ** 5)
from itertools import groupby,accumulate
from heapq import heapify,heappop,heappush
from collections import deque,Counter,defaultdict
def I(): return int(sys.stdin.readline())
def neo(): return map(int, sys.stdin.readline().split())
def Neo(): return list(map(int, sys.stdin.readline().split()))
def dfs(t):
vis[t] = 1
for i in G[t]:
if not vis[i]:
dfs(i)
N,M = neo()
G = defaultdict(list)
vis = [0]*(N+1)
for i in range(M):
x,y = neo()
G[x] += [y]
G[y] += [x]
c = 0
for i in range(1,N+1):
if not vis[i]:
dfs(i)
c += 1
print(c-1)
| 0 | null | 8,862,186,723,790 | 132 | 70 |
# input here
_INPUT = """\
5 3
1 2
3 4
5 1
"""
"""
K = int(input())
H, W, K = map(int, input().split())
a = list(map(int, input().split()))
xy = [list(map(int, input().split())) for i in range(N)]
p = tuple(map(int,input().split()))
"""
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def main():
n, m = map(int, input().split())
xy = [list(map(int, input().split())) for i in range(m)]
uf = UnionFind(n)
for i in range(len(xy)):
uf.union(xy[i][0]-1,xy[i][1]-1)
print(-(min(uf.parents)))
if __name__ == '__main__':
import io
import sys
import math
import itertools
from collections import deque
# sys.stdin = io.StringIO(_INPUT)
main() | st= input().split()
s=st[0]
t=st[1]
print(t+s) | 0 | null | 53,268,079,950,668 | 84 | 248 |
from operator import itemgetter
n=int(input())
xl=[list(map(int,input().split()))for i in range(n)]
R=[(xl[i][0]-xl[i][1],xl[i][0]+xl[i][1]) for i in range(n)]
r=sorted([(R[i][0],R[i][1]) for i in range(n)],key=itemgetter(1))
s=r[0][1]
ans=1
for i in range(n-1):
if r[i+1][0]>=s:
s=r[i+1][1]
ans+=1
print(ans) | while True:
(n, x) = [int(i) for i in input().split()]
if n == x == 0:
break
count = 0
start = n if n < x else x
for a in range(start, 0, -1):
if a >= x:
continue
for b in range(a - 1, 0, -1):
if a + b >= x:
continue
for c in range(b - 1, 0, -1):
if a + b + c == x:
count += 1
print(count) | 0 | null | 45,332,688,757,918 | 237 | 58 |
N = int(input())
plus = []
minus = []
for _ in range(N):
x, y = map(int, input().split())
plus.append(x + y)
minus.append(x - y)
print(max(max(plus) - min(plus), max(minus) - min(minus)))
| import sys
sys.setrecursionlimit(10**9)
def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))
INF=10**20
def main():
N=ii()
S=list(input())
if N%2==1:
print("No")
exit()
if S[:N//2] == S[N//2:]:
print("Yes")
else:
print("No")
if __name__ == "__main__":
main() | 0 | null | 75,130,167,256,870 | 80 | 279 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.