code1 stringlengths 16 427k | code2 stringlengths 16 427k | similar int64 0 1 | pair_id int64 2 178,025B ⌀ | question_pair_id float64 27.1M 177,113B ⌀ | code1_group int64 1 297 | code2_group int64 1 297 |
|---|---|---|---|---|---|---|
A, B, C, K = map( int, input().split())
ret = min( A, K )
if A < K:
ret -= max( 0, K - A - B )
print( ret ) | x = input().split()
for i in range(5):
if x[i] == '0':
print(i+1) | 0 | null | 17,791,815,129,242 | 148 | 126 |
str=input()
l=len(str)
n=0
while l>0:
n=n+int(str[l-1])
l=l-1
if n%9 == 0:
print("Yes")
else :
print("No")
| print((1000 - (int(input()) % 1000)) % 1000) | 0 | null | 6,395,916,348,040 | 87 | 108 |
from collections import Counter
N = int(input())
S = input()
ans = 0
for x in range(10):
for y in range(10):
hantei = []
for i in range(N):
if x != int(S[i]):
continue
for j in range(i+1, N):
if y != int(S[j]):
continue
... | import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy
class UnionFind:
def __init__(self, n: int):
self._n = n
... | 0 | null | 65,256,021,876,500 | 267 | 70 |
n = int(input())
s = input()
r, g, b = [], [], []
cnt = 1
for i in s:
if i == 'R':
r.append(cnt)
elif i == 'G':
g.append(cnt)
else:
b.append(cnt)
cnt += 1
rd = set(map(lambda x: x * 2, r)) #以下2つ目の条件を満たさないもの(j - i = k - j)の数え上げ
gd = set(map(lambda x: x * 2, g))
bd = set(map(lambda... | N = int(input())
S = input()
r = [0 for _ in range(N + 1)]
g = [0 for _ in range(N + 1)]
b = [0 for _ in range(N + 1)]
for i in reversed(range(N)):
r[i] = r[i + 1]
g[i] = g[i + 1]
b[i] = b[i + 1]
if S[i] == "R":
r[i] += 1
if S[i] == "G":
g[i] += 1
if S[i] == "B":
b[i] +... | 1 | 36,083,121,817,080 | null | 175 | 175 |
S,T=map(str,input().split())
res =T+S
print(res) | #!/usr/bin/env python3
import sys
import numpy as np
import numba
from numba import i8
input = sys.stdin.buffer.readline
mod = 998244353
def I():
return int(input())
def MI():
return map(int, input().split())
@numba.njit((i8, i8[:]), cache=True)
def main(N, LR):
L, R = LR[::2], LR[1::2]
K = len(L... | 0 | null | 52,959,390,857,620 | 248 | 74 |
from collections import Counter
n,*a = map(int,open(0).read().split())
s = set(a)
c = Counter(a)
m = max(s)
l = [True]*(m+1)
ans = 0
for i in range(1,m+1):
if i in s and l[i]:
if c[i] == 1:
ans += 1
for j in range(1,m//i+1):
l[i*j] = False
print(ans) | # でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, A):
C = [0] * (10**6 + 1)
for a in A:
if C[a] == 1:
C[a] = -1
continue
if C[a] == -1:
continue
C[a] = 1
for b in range(a + a, 10 ** 6 + 1, a):
C[b] = -1
ans =... | 1 | 14,500,425,851,010 | null | 129 | 129 |
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9 + 7
def gcd(n, m):
if m == 0:
return n
return gcd(m, n % m)
def lcm(a, b):
return a * b // gcd(a, b)
L = 1
for a in A:
L = lcm(L, a)
L %= MOD
coef = 0
for a in A:
coef += pow(a, MOD - 2, MOD)
print((L * coef) % MOD)
| s,t=map(str,input().split())
print(t,s,sep="")
| 0 | null | 95,755,991,206,880 | 235 | 248 |
import collections
n = int(input())
num_list = list(map(int, input().split()))
all = 0
c = collections.Counter(num_list)
for i in c:
all += c[i]*(c[i]-1)//2
for k in range(n):
print(all - c[num_list[k]] + 1) | N = int(input())
As = list(map(int, input().split()))
count_dict = {}
def calc_combo(n):
return int(n * (n - 1) / 2)
for i in range(N):
try:
count_dict[As[i]] += 1
except KeyError:
count_dict[As[i]] = 1
combo = 0
for key in count_dict:
combo += calc_combo(count_dict[key])
for i in ... | 1 | 47,661,372,897,082 | null | 192 | 192 |
n, q = map(int, input().split())
que = []
for i in range(n):
p, t = map(str, input().split())
que.append([p, int(t)])
total = 0
while que != []:
pt = que.pop(0)
if pt[1] <= q:
total += pt[1]
print(pt[0], total)
else:
total += q
que.append([pt[0], pt[1]-q])
| import collections
import sys
n,q = map(int,input().split())
data = [[i for i in input().split()]for i in range(n)]
time = 0
while data:
task = data[0]
del data[0]
if int(task[1]) <= q:
time += int(task[1])
print(task[0],time)
else:
time += q
task[1] = str(int(tas... | 1 | 44,156,859,780 | null | 19 | 19 |
k = int(input())
a, b = map(int, input().split())
ans = 0
for i in range(a, b+1, 1):
if i%k == 0:
ans = 1
break
if ans == 1:
print("OK")
else:
print("NG") | K = int(input())
A,B = map(int,input().split())
li = []
for i in range(A,B+1):
li.append(i)
ans = False
for j in li:
if j%K == 0:
ans = True
break
else:
ans = False
if ans == True:print("OK")
else:print("NG") | 1 | 26,553,412,989,990 | null | 158 | 158 |
N=int(input())
A=list(map(int, input().split()))
if len(set(A))==N:
print("YES")
else:
print("NO") | import sys
N=int(input())
A=list(map(int,input().split()))
A.sort()
for i in range(N-1):
if(A[i]==A[i+1]):
print("NO")
sys.exit()
print("YES") | 1 | 74,218,692,546,460 | null | 222 | 222 |
x=input()
arr=['SUN','MON','TUE','WED','THU','FRI','SAT']
print(7-arr.index(x))
| import math
n = int(input())
class Coordinate:
def __init__(self,x,y):
self.x = x
self.y = y
def Koch(n,p1,p2):
if n == 0:
return
else:
s = Coordinate(2/3 * p1.x + 1/3 * p2.x, 2/3 * p1.y + 1/3 * p2.y)
u = Coordinate(1/3 * p1.x + 2/3 * p2.x, 1/3 * p1.y + 2/3 * p2.y)
... | 0 | null | 66,276,749,519,082 | 270 | 27 |
S=input()
B=0
B=S[0]+S[1]+S[2]
print(B) | S = input()
ans = S[0] + S[1] + S[2]
print(ans) | 1 | 14,812,955,563,290 | null | 130 | 130 |
from time import time
from random import randint
def func(s, x):
last = [0] * 26
score = 0
for i, v in enumerate(x, 1):
last[v] = i
c = 0
for j in range(26):
c += s[j] * (i - last[j])
score += s[i * 26 + v] - c
return score
def main():
start = time()
... | import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
import numpy as np
def main():
n, m, k = map(int, input().split())
a = np.array(readline().split(), np.int64)
b = np.array(readline().split(), np.int64)
aa = a.cumsum()
ba = b.cumsum()
r = np.searchsor... | 0 | null | 10,213,766,180,892 | 113 | 117 |
N = int(input())
A = list(map(int,input().split()))
minm = A[0]
ans = 0
for i in range(1,N):
if A[i] < minm:
ans += minm - A[i]
if A[i] > minm:
minm = A[i]
print(ans) | n = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(n-1):
if a[i] <= a[i+1]:
pass
else:
ans += a[i] - a[i+1]
a[i+1] = a[i]
print(ans) | 1 | 4,518,374,983,612 | null | 88 | 88 |
from collections import defaultdict
import bisect
N = int(input())
S = input()
# s2i = [[] for i in range(10)]
s2i = defaultdict(list)
for i, si in enumerate(S):
s2i[si] += [i]
ans = 0
for i in range(1000):
pin = str(i).zfill(3)
ii = -1
flag = True
for p in pin:
s2ip = s2i[p]
if ... | s = input()
l = s.split(" ")
a,b = int(l[0]), int(l[1])
print(a*b) | 0 | null | 72,455,341,020,180 | 267 | 133 |
from itertools import combinations
n = int(input())
a = list(map(int, input().split()))
q = int(input())
m = list(map(int, input().split()))
answer = ['no']*q
for i in range(1, n+1):
for nums in combinations(a, i):
val = sum(nums)
if val in m:
index = [i for i, num in enumerate(m) if... | # -*- coding: utf-8 -*-
"""
全探索
・再帰で作る
・2^20でTLEするからメモ化した
"""
N = int(input())
aN = list(map(int, input().split()))
Q = int(input())
mQ = list(map(int, input().split()))
def dfs(cur, depth, ans):
# 終了条件
if cur == ans:
return True
# memo[現在位置]に数値curがあれば、そこから先はやっても同じだからやらない
if cur in memo[depth... | 1 | 100,772,298,130 | null | 25 | 25 |
while True:
s = raw_input()
if s == '0':
break
n = 0
for i in s:
n += int(i)
print n | while True:
input = raw_input()
if input == "0":
break
sum = 0
for i in xrange(len(input)):
sum += int(input[i])
print sum | 1 | 1,588,063,571,960 | null | 62 | 62 |
n = input()
list = map(int, input().split())
num = 1
a = 0
for i in list:
if i == num:
num = num +1
else:
a = a + 1
if num == 1:
print(-1)
else:
print(a) | for i in range(9):
i=i+1
for j in range(9):
j=j+1
print(str(i)+'x'+str(j)+'='+str(i*j)) | 0 | null | 57,249,138,698,720 | 257 | 1 |
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
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mu... | X = int(input())
dp = [False]*(X+1)
dp[0] = True
for i in range(100, X+1):
if i < 106:
dp[i] = True
continue
if dp[i-100] or dp[i-101] or dp[i-102] or dp[i-103] or dp[i-104] or dp[i-105]:
dp[i] = True
print(1) if dp[len(dp)-1] else print(0) | 1 | 127,076,101,912,760 | null | 266 | 266 |
import sys
from decimal import Decimal
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
a, b, c = input().split()
print("Yes" if Decimal(a) ** Decimal(0.5) + Decimal(b) ** Decimal(0.5) < Decimal(c) ** Decimal(0.5) else "No")
if __name__ == '__main__':
resolve()
|
A, B, C = map(int, input().split())
x = A * B * 4
y = (C - A - B) ** 2
if x < y and C - A - B > 0:
print("Yes")
else:
print("No")
| 1 | 51,519,872,610,828 | null | 197 | 197 |
mod = pow(10, 9) + 7
def main():
N, K = map(int, input().split())
table = [0]*(K+1)
for k in range(K, 0, -1):
m = K//k
tmp = pow(m, N, mod)
for l in range(2, m+1):
tmp -= table[l*k]
tmp %= mod
table[k] = tmp
ans = 0
for i in range(len(table)... | H = int(input())
W = int(input())
N = int(input())
N += max(H-1,W-1)
ans = N//max(H,W)
print(ans) | 0 | null | 62,356,750,348,874 | 176 | 236 |
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
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mu... | import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
n = int(input())
s = input()
res = s.count('R') * s.count('G') * s.count('B')
if res == 0:
print(0)
sys.exit()
for i1 in range(n):
for i2 in range(i1+1, n):
i3 = i2 * 2 - i1
... | 0 | null | 43,887,236,214,332 | 197 | 175 |
def main():
H, W, M = map(int, input().split())
cnth = [[0, i] for i in range(H)]
cntw = [[0, i] for i in range(W)]
L = set()
for _ in range(M):
h, w = map(lambda x: int(x) - 1, input().split())
cnth[h][0] += 1
cntw[w][0] += 1
L.add((h, w))
cnth.sort(reverse=True)... | r, c = map(int, input().split())
mat = [list(map(int, input().split())) for i in range(r)]
for row in mat:
row.append(sum(row))
print(*row)
colSum = [sum(col) for col in zip(*mat)]
print(*colSum) | 0 | null | 3,031,341,383,170 | 89 | 59 |
def main():
a = list(map(int,input().split()))
ans = 0
for i in range(5):
ans += a[i]
print(15 - ans)
main() | std_value = []
while True:
n = int(input())
if n == 0:
break
s = [int(i) for i in input().split()]#生徒の点数
sum_value=0
s_ave = 0
for i in range(len(s)):#平均値計算
sum_value += s[i]
ave = sum_value/len(s)
for j in range(len(s)):
s_ave += (s[j]-ave)**2
std_value.appen... | 0 | null | 6,840,162,368,718 | 126 | 31 |
n = int(input())
a = list(map(int, input().split()))
num = [0]*(10**6+1)
for x in a:
if num[x] != 0:
num[x] = 2
continue
for i in range(x, 10**6+1, x):
num[i] += 1
ans = 0
for x in a:
if num[x] == 1:
ans += 1
print(ans) | import sys
import math
from collections import deque
sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def make_grid(h, w, num): return [[int(num)] * w for _ in... | 1 | 14,393,015,828,760 | null | 129 | 129 |
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
b2=[]
b2.append(0)
for i in range(1,m+1):
b2.append(b2[i-1]+b[i-1])
a.insert(0,0)
cnt=0
a_sum=0
for i in range(n+1):
j=m
a_sum+=a[i]
while True:
if k>=a_sum+b2[j]:
cnt=max(cnt,i+j)
m=j
break
... | n, m, k = map(int, input().split(" "))
a = [0]+list(map(int, input().split(" ")))
b = [0]+list(map(int, input().split(" ")))
for i in range(1, n+1):
a[i] += a[i - 1]
for i in range(1, m+1):
b[i] += b[i - 1]
j,mx= m,0
for i in range(n+1):
if a[i]>k:
break
while(b[j]>k-a[i]):
j-=1
i... | 1 | 10,765,696,702,882 | null | 117 | 117 |
def partpall(s,n):
if s!=s[::-1]:
return False
else:
return True
def pall(s,n):
if s!=s[::-1]:
return False
return partpall(s[n//2 +1 :],n) and partpall(s[:n//2 ],n)
# s=input("enter:")
s=input()
# print("sucess",s,s[::-1])
# revStr=s[::-1]
n=len(s)
# print(n)
if pall(s,n):
print("Yes")
else:
print("No") | # String Palindrome
def is_palindrome(s):
res = s == s[::-1]
return res
S = input()
N = len(S)
ans = ['No', 'Yes'][is_palindrome(S) & is_palindrome(S[:((N-1)//2)]) & is_palindrome(S[((N+1)//2):])]
print(ans) | 1 | 46,113,394,209,568 | null | 190 | 190 |
N,K = map(int,input().split())
M = list(map(int,input().split()))
M =sorted(M,reverse=True)
print(sum(M[K:])) | N,K = map(int,input().split())
H = list(map(int,input().split()))
H.sort()
reversed(H)
for i in range(K):
if len(H)==0:
break
else:
H.pop()
if len(H)==0:
print(0)
else:
print(sum(H)) | 1 | 79,237,699,499,832 | null | 227 | 227 |
# print('input >>')
N, K = map(int,(input().split()))
ps = list(map(int,(input().split())))
ps.sort()
# print('-----output-----')
print(sum(ps[:K])) | #B問題
ans = 0
n, k = map(int, input().split())
P = list(map(int, input().split()))
for i in range(k):
ans += min(P)
P.remove(min(P))
print(ans) | 1 | 11,578,676,832,040 | null | 120 | 120 |
n,x,y = map(int,input().split())
ans = [0]*n
for i in range(1,n+1):
for j in range(i+1,n+1):
if i <= x and j >= y:
a = abs(j-i)-abs(y-x)+1
b = abs(i-x)+abs(j-y)+1
ans[min(a,b)] += 1
else:
c = abs(x-i)+abs(y-j)+1
d = abs(j-i)
an... | import itertools
n, x, y = map(int, input().split())
k = [0] * n
for v in itertools.combinations(list(range(1,n+1)), 2):
k[min(abs(v[1]-v[0]),abs(x-min(v))+1+abs(y-max(v)))] += 1
for item in k[1:]:
print(item) | 1 | 44,123,277,259,876 | null | 187 | 187 |
import math
n, x, t = input().split()
answer = math.ceil(int(n) / int(x)) * int(t)
print(answer)
| n, x, t = map(lambda x: int(x), input().split())
if n % x == 0:
group = n // x
else:
group = n // x + 1
answer = group * t
print(answer) | 1 | 4,259,753,299,424 | null | 86 | 86 |
from math import factorial as fac
x,y=map(int,input().split())
a=2*y-x
b=2*x-y
mod=10**9+7
if a>=0 and b>=0 and a%3==0 and b%3==0:
a=a//3
b=b//3
a1=1
a2=1
n3=10**9+7
for i in range(a):
a1*=a+b-i
a2*=i+1
a1%=n3
a2%=n3
a2=pow(a2,n3-2,n3)
print((a1*a2)%n3)
else:
print(0) | import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [... | 0 | null | 135,206,837,937,230 | 281 | 261 |
N=input().split(" ");print(N[1]+N[0]) | N, K = map(int,input().split())
P = list(map(int,input().split()))
P.sort()
price = sum(P[:K])
print(price) | 0 | null | 57,395,996,006,610 | 248 | 120 |
s = input()
k = int(input())
li = list(s)
lee = len(s)
if len(list(set(li))) == 1:
print((lee)*k//2)
exit()
def motome(n,list):
count = 0
kaihi_flag = False
li = list*n
for i,l in enumerate(li):
if i == 0:
continue
if l == li[i-1] and not kaihi_flag:
co... | s = input()
k = int(input())
s_list = []
ans = 0
def rle(s):
tmp, count = s[0], 1
for i in range(1, len(s)):
if tmp == s[i]:
count += 1
else:
s_list.append(count)
tmp = s[i]
count = 1
s_list.append(count)
return
rle(s)
if len(s_list) >= ... | 1 | 176,016,630,255,450 | null | 296 | 296 |
N = list(map(int, input().split()))
if sum(N) % 9: print('No')
else: print('Yes') | # def f(n):
# if n < 2:
# return 1
# else:
# return n * f(n - 2)
# for i in range(2, 150, 2):
# print(i, f(i))
N = int(input())
if N % 2 == 1:
print(0)
exit()
k = 10
cnt = 0
while k <= N:
cnt += N // k
k *= 5
print(cnt)
| 0 | null | 59,920,072,496,338 | 87 | 258 |
a,b,c = map(int,input().split(" "))
ptn = 0
if a==b and a==c:
print(1)
ptn = 1
if a==b and a!=c:
if a < c:
print(1)
ptn=2
else:
print(0)
ptn=2
cnt = 0
for i in range(a,b+1):
if c%i == 0:
cnt += 1
if ptn != 1 and ptn != 2:
print(cnt) | #!python3
from time import perf_counter
tick = perf_counter() + 1.92
import sys
iim = lambda: map(int, sys.stdin.readline().rstrip().split())
from random import randrange
from bisect import bisect
def resolve():
G = 26
it = map(int, sys.stdin.read().split())
D = next(it)
C = [next(it) for i in range(... | 0 | null | 5,075,671,966,688 | 44 | 113 |
N = int(input())
A = list(map(int,input().split()))
MOD = 10**9 + 7
S = sum(A)
ans = 0
for i in range(N):
S = S - A[i]
ans += A[i]*S
print(ans%MOD) | #cやり直し
import numpy
n = int(input())
a = list(map(int, input().split()))
ans = 0
mod = 10**9 +7
before = a[-1]
for i in range(n-1,0,-1):
ans += (a[i-1]*before)%mod
before += a[i-1]
print(ans%mod) | 1 | 3,825,334,989,362 | null | 83 | 83 |
import sys
import copy
#import math
#import itertools
#import numpy as np
#import re
def func(x,m):
return x**2%m
N,X,M=[int(c) for c in input().split()]
myset = {X}
mydict = {X:0}
A = []
A.append(X)
s = X
i = 0
i_stop = i
#i=0は計算したので1から
for i in range(1,N):
A.append(func(A[i-1],M))
if A[i] in myset:
... | N, X, M = map(int, input().split())
NN = N
li = []
isused = [False] * M
while isused[X] == False and N != 0:
li.append(X)
isused[X] = True
X = (X ** 2) % M
N -= 1
if N == 0:
print(sum(li))
elif N != 0 and X in li:
l = len(li)
s = li.index(X)
T = l - s
q = (NN - s) // T
r = ... | 1 | 2,805,384,578,656 | null | 75 | 75 |
from typing import List
from collections import deque
def bfs(G: List[int], s: int) -> None:
d[s] = 0
color[s] = "GRAY"
Q = deque()
Q.append(s)
while Q:
u = Q.popleft()
for v in G[u]:
if color[v] == "WHITE":
color[v] = "GRAY"
d[v] = d[u] + 1
pi[v] = u
Q.append(v)
color[u] = "BLACK"
if _... | from collections import deque
def main():
n = int(input())
_next = [[] for _ in range(n)]
for _ in range(n):
u, k, *v = map(lambda s: int(s) - 1, input().split())
_next[u] = v
queue = deque()
queue.append(0)
d = [-1] * n
d[0] = 0
while queue:
u = queue.popleft()
... | 1 | 3,705,497,368 | null | 9 | 9 |
x = int(input())
def prime_check(n):
f = 3
while f * f <= n:
if n % f == 0:
return False
else:
f += 2
else:
return True
if x != 2:
if x % 2 == 0:
x += 1
while 1:
if prime_check(x) == True:
print(x)
break
... | X = int(input())
def is_prime(n):
a = 2
while a*a < n:
if n%a == 0:
return False
a += 1
return True
while True:
if is_prime(X):
break
X += 1
print(X) | 1 | 105,376,549,850,650 | null | 250 | 250 |
a, b, h, m = map(int, input().split())
from math import cos,sin, sqrt, radians
x_a = - a * cos(radians(360/12.0*h+360/12/60*m))
y_a = a * sin(radians(360/12.0*h+360/12/60*m))
x_b = - b * cos(radians(360/60.0*m))
y_b = b * sin(radians(360/60.0*m))
print(sqrt((x_a-x_b)**2+(y_a-y_b)**2)) | import sys
R, C, K = list(map(int, input().split()))
d = [[[0] * (C+1) for _ in range(R+1)] for _ in range(4)]
t = [[0] * (C+1) for _ in range(R+1)]
for i in range(K):
r,c,v = list(map(int, input().split()))
t[r][c] = v
for i in range(R+1):
for j in range(C+1):
for k in range(4):
if i... | 0 | null | 12,794,650,425,030 | 144 | 94 |
n = int(input())
ns = list(map(int, input().split()))
print(min(ns), max(ns), sum(ns))
| C = input()
N = ord(C)
print(chr(N + 1)) | 0 | null | 46,333,952,774,120 | 48 | 239 |
a,c,b = list(map(int, input().split()))
a = abs(a)
b = abs(b)
c = abs(c)
if b*c <= a:
print(a - (b*c))
else:
c -= a//b
a = a%b
#print(a,b,c)
if c%2==0:
print(a)
else:
print(abs(a-b)) | def maximum_volume():
"""
立方体に近いほど体積が大きくなる
"""
# 入力
L = int(input())
# 処理
one_side = L / 3
# 体積
return one_side ** 3
result = maximum_volume()
print(result) | 0 | null | 26,086,320,652,448 | 92 | 191 |
inp = input().split()
A = int(inp[0])
B = int(inp[1].replace('.',''))
print(A*B//100) | from decimal import Decimal
import sys
A,B = map(Decimal,input().split())
ans = int(A*B)
print(ans) | 1 | 16,546,492,087,850 | null | 135 | 135 |
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()
def resolve():
H, W, K = map(int, input().split())
grid = [[_ for _ in input()] for _ in range(H)]
ans = [[0] * W for _ in range(H)]
cnt = 0
for h in range(H):
for w in range(W):
... | H, W, K = map(int, input().split())
cake = [input() for _ in range(H)]
# 答え
memo = [[0] * W for _ in range(H)]
#print(memo)
# 行にケーキが何個あるか
cake_count_row = [0] * H
for y in range(H):
count = 0
for x in range(W):
if cake[y][x] == "#":
count += 1
cake_count_row[y] = count
# イチゴがある行について色塗り... | 1 | 143,572,964,918,280 | null | 277 | 277 |
from collections import deque
if __name__ == '__main__':
n, q = map(int, input().split())
Q = deque()
for i in range(n):
name, time = input().split()
Q.append([name, int(time)])
sum = 0
while Q:
qt = Q.popleft()
if qt[1] <= q:
sum += qt[1]
print(qt[0], sum)
else:
sum += q
qt[1] -= q
Q... | # ALDS1_3_B
# coding: utf-8
from collections import deque
n, q = [int(i) for i in raw_input().split()]
d = deque()
for i in range(n):
name, time = raw_input().split()
time = int(time)
d.append([name, time])
total = 0
while len(d) > 0:
p = d.popleft()
if p[1] <= q: # 終わり
total += p[1]
... | 1 | 41,426,375,680 | null | 19 | 19 |
n=int(input())
print(int(n/2)-1 if n%2==0 else int((n-1)/2)) | n = int(input())
print((n - (n+1)%2)//2) | 1 | 153,185,722,472,352 | null | 283 | 283 |
N = int(input())
A_li = list(map(int, input().split()))
is_rising = False
money = 1000
stock = 0
for i in range(N - 1):
if i == 0:
if A_li[0] < A_li[1]:
# できるだけ買う
stock = money // A_li[0]
money -= A_li[0] * stock
is_rising = True
else:
if is_ris... | # Debt Hell
n = int(input())
value = 100000
for i in xrange(n):
value *= 1.05
if value % 1000 != 0:
value = int(value / 1000 + 1) * 1000
print value | 0 | null | 3,692,760,124,662 | 103 | 6 |
while(1):
try:
i = raw_input()
a, b = map(int, i.split())
x, y = a, b
while(b != 0):
tmp = b
b = a % b
a = tmp
print a,
print x*y/a
except:
break | import math
while True:
try:
a = list(map(int,input().split()))
b = (math.gcd(a[0],a[1]))
c = ((a[0]*a[1])//math.gcd(a[0],a[1]))
print(b,c)
except EOFError:
break
| 1 | 455,154,612 | null | 5 | 5 |
import numpy as np
N, T = map(int, input().split())
AB = []
for i in range(N):
A, B = map(int, input().split())
AB.append([A, B])
AB.sort()
dp = np.zeros(T, dtype=int)
ans = 0
for a, b in AB:
ans = max(ans, dp[-1] + b)
dp[a:] = np.maximum(dp[a:], dp[:-a] + b)
print(ans) | from itertools import chain
N, T = map(int, input().split())
# A = [0]*(N+1)
# B = [0]*(N+1)
AB = [(0, 0)]
for i in range(1, N+1):
a, b = map(int, input().split())
# A[i] = a
# B[i] = b
AB.append((a, b))
AB.sort()
dp = [[-1]*(6000+1) for _ in range(N+1)]
#dp[i][t]: 注文後にt秒になっている時、i番目までを考慮したとき、
#の最大
dp[0]... | 1 | 151,938,466,665,270 | null | 282 | 282 |
s = int(input())
a = []
a.append(1)
a.append(0)
a.append(0)
for i in range(3,s+1):
a.append(sum(a)-a[i-1]-a[i-2])
ans = a[-1] % (10**9 + 7)
print(ans) | MOD = 10**9 + 7
fac = [1 for k in range(200010)]
inv = [1 for k in range(200010)]
finv = [1 for k in range(200010)]
for k in range(2,200010):
fac[k] = (fac[k-1]*k)%MOD
inv[k] = (MOD - inv[MOD%k] * (MOD // k))%MOD
finv[k] = (finv[k - 1] * inv[k]) % MOD;
def nCr(n,r):
return (fac[n]*finv[r]*finv[n-r])%MOD... | 0 | null | 49,282,162,895,222 | 79 | 242 |
n = int(input())
sum = (1 + n) * n // 2
sho_3 = n // 3
sho_5 = n // 5
sho_15 = n // 15
s_3 = (sho_3 * 3 + 3) * sho_3 // 2
s_5 = (sho_5 * 5 + 5) * sho_5 // 2
s_15 = (sho_15 * 15 + 15) * sho_15 // 2
print(sum - s_3 - s_5 + s_15)
| import math
import sys
import os
from operator import mul
sys.setrecursionlimit(10**7)
def _S(): return sys.stdin.readline().rstrip()
def I(): return int(_S())
def LS(): return list(_S().split())
def LI(): return list(map(int,LS()))
if os.getenv("LOCAL"):
inputFile = basename_without_ext = os.path.splitext(os.pa... | 0 | null | 34,863,544,278,628 | 173 | 172 |
def gcd(m, n):
x = max(m, n)
y = min(m, n)
if x % y == 0:
return y
else:
while x % y != 0:
z = x % y
x = y
y = z
return z
def lcm(m, n):
return (m * n) // gcd(m, n)
# input
A, B = map(int, input().split())
# lcm
snack = lcm(A, B)
pri... | from math import gcd as g
a, b = map(int, input().split())
print((a*b)//g(a,b)) | 1 | 113,060,554,020,942 | null | 256 | 256 |
x = int(input())
print((1999-x)//200+1) | X = int(input())
rank = -1
if X <= 599:
rank = 8
elif X <= 799:
rank = 7
elif X <= 999:
rank = 6
elif X <= 1199:
rank = 5
elif X <= 1399:
rank = 4
elif X <= 1599:
rank = 3
elif X <= 1799:
rank = 2
else:
rank = 1
print(rank) | 1 | 6,706,241,599,430 | null | 100 | 100 |
c=str(input())
print('Yes' if c[2]==c[3] and c[4]==c[5] else'No') | s = input()
ans = 'Yes'
if s[2] != s[3]:
ans = 'No'
if s[4] != s[5]:
ans = 'No'
print(ans) | 1 | 42,040,132,311,232 | null | 184 | 184 |
K = int(input())
s = ''
for i in range(K):
s = s + 'ACL'
print(s) | #!/usr/bin/env python
k = int(input())
s = 'ACL'
ans = ''
for i in range(k):
ans += s
print(ans)
| 1 | 2,152,856,891,660 | null | 69 | 69 |
s1 = input()
s2 = input()
if s2 in s1+s1:
print("Yes")
else:
print("No") | N=input()
N=N+N
S=input()
if S in N:
print("Yes")
else:
print("No")
| 1 | 1,751,680,433,180 | null | 64 | 64 |
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
a, b = input().split()
a = int(a)
b = int(b[0]+b[2:4])
print(a*b//100)
if __name__=='__main__':
main() | a,b,k=map(int,input().split())
if k<=a:
print(a-k,b)
elif k>a and k<=a+b:
print(0,a+b-k)
else:
print(0,0) | 0 | null | 60,350,272,442,838 | 135 | 249 |
n = int(input())
a = list(map(int,input().split()))
maxketa = max([len(bin(a[i])) for i in range(n)])-2
mod = 10**9+7
ans = 0
for i in range(maxketa):
ones = 0
for j in range(n):
if (a[j] >> i) & 1:
ones += 1
ans = (ans + (n-ones)*ones*(2**i)) % mod
print(ans) | # input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprin... | 1 | 123,119,741,237,330 | null | 263 | 263 |
n = int(input())
def binary_search(l, target):
left = 0
right = len(l)
while left<right:
mid = (left+right)//2
if target == l[mid]:
return True
elif target < l[mid]:
right = mid
else:
left = mid+1
return False
seki = [i*j for i in r... | n = int(input())
ans = 360 / n
i = 1
while int(ans * i) != ans * i:
i += 1
print(int(ans * i)) | 0 | null | 86,793,015,133,850 | 287 | 125 |
s=input()
print("Yes"if s==input()[:-1]else"No") | s = input()
T = input()
if T[:len(T)-1] == s and len(s)+1 == len(T):
print("Yes")
else:
print("No") | 1 | 21,450,286,437,810 | null | 147 | 147 |
A, B = list(map(int,input().split()))
if A>0 and A<10 and B>0 and B<10:
print(A*B)
else:
print(-1) | def main(S, T):
ans = 0
for i in range(len(S)):
if S[i] != T[i]:
ans += 1
return ans
if __name__ == '__main__':
S = input()
T = input()
ans = main(S, T)
print(ans)
| 0 | null | 84,025,064,317,600 | 286 | 116 |
N, D = map(int, input().split())
X = [list(map(int, input().split())) for l in range(N)]
count = 0
for i in range(N):
if (X[i][0])**2 + (X[i][1])**2 - D**2 <= 0:
count = count + 1
print(count)
| # -*- coding: utf-8 -*-
import sys
import os
def input_to_list():
return list(map(int, input().split()))
H, W = input_to_list()
M = []
for i in range(H):
lis = input_to_list()
s = sum(lis)
lis.append(s)
M.append(lis)
# vertical sum
last = []
for i in range(W + 1):
s = 0
for j in range(H... | 0 | null | 3,656,966,388,710 | 96 | 59 |
X = int(input())
i = 1
while (360*i) % X != 0:
i += 1
ans = 360*i//X
print(ans)
| n = int(input())
ans = 360 / n
i = 1
while int(ans * i) != ans * i:
i += 1
print(int(ans * i)) | 1 | 13,129,885,961,982 | null | 125 | 125 |
n,m,x=map(int,input().split())
A=[list(map(int,input().split())) for _ in range(n)]
a=[]
ans=[]
for i in range(2**n):
b=bin(i)[2:].zfill(n)
a.append(b)
for bit in a:
Skills=[]
for i in range(1,1+m):
skill=0
for j in range(n):
if bit[j]=="1":
skill+=A[j][i]
... | from itertools import product
n, m, x = map(int, input().split())
CA = [list(map(int, input().split())) for _ in range(n)]
ans = 10**12+1
for t in product([0,1], repeat=n): # (1, 0, 0)
cost = 0
understanding = [0] * m
for i, b in enumerate(t):
if b == 1:
cost += CA[i][0]
f... | 1 | 22,224,103,551,790 | null | 149 | 149 |
def main():
import math
a, b, n = map(int, input().split())
if n >= b:
ans = math.floor(a * (b-1)/b)
else:
ans = math.floor(a * n / b)
print(ans)
if __name__ == "__main__":
main() | a,b,n=map(int,input().split())
import math
if n/b >= 1:
print(math.floor(a*(b-1)/b))
else:
print(math.floor(a*n/b)) | 1 | 27,977,663,143,670 | null | 161 | 161 |
N,M=map(int, input().split())
if N in [0,1]:n=0
else:
n=N*(N-1)/2
if M in [0,1]:m=0
else:
m=M*(M-1)/2
print(int(n+m)) | n, p = map(int, input().split())
s = input()
ruisekiwa = [0 for _ in range(0, n + 1)]
if 10 % p == 0:
ans = 0
for i in range(0, n):
if (ord(s[i]) - ord('0')) % p == 0:
ans += i + 1
print(ans)
exit()
ten = 1
for _i in range(0, n):
i = n - _i - 1
ruisekiwa[n - i] = ((ord(s[i... | 0 | null | 52,071,760,474,560 | 189 | 205 |
def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a%b)
def lcm(a, b):
return a // gcd(a, b) * b
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = [a//2 for a in A]
while A[0] % 2 == 0:
for i in range(N):
if A[i] % 2 != 0:
print(0)
... | N=int(input())
flag=0
for i in range(1,10):
for j in range(1,10):
if N==i*j:
flag+=1
if flag==0:
print('No')
else:
print('Yes')
| 0 | null | 130,719,938,594,432 | 247 | 287 |
x,k,d = map(int, input().split())
if x == 0:
if k % 2 == 1:
x = d
elif x > 0:
if x >= k*d:
x -= k*d
else:
n = x//d
x -= n*d
k -= n
if k%2 ==1:
x -= d
else:
if x <= -(k*d):
x += k*d
else:
n = abs(x)//d
x += n*d
... | import math
n = int(input())
x = [int(i) for i in input().split()]
y = [int(j) for j in input().split()]
p_1 = p_2 = p_3 = p_m = 0
for i in range(n):
diff = math.fabs(x[i]-y[i])
p_1 += diff
p_2 += diff*diff
p_3 += diff*diff*diff
if p_m < diff:
p_m = diff
p_2 = math.sqrt(p_2)
p_3 = math.pow(p_3, 1/3)
print('... | 0 | null | 2,713,453,660,928 | 92 | 32 |
N= int(input())
S = input()
abc = "ABC"
ans = 0
j = 0
for i in range(N):
if S[i] == abc[j]:
j += 1
if S[i] == "C":
j = 0
ans += 1
elif S[i] == "A":
j = 1
else:
j = 0
print(ans) | import math
a, b, x = map(int, input().split())
x = x / a
if x >= a*b/2:
K = (a*b - x)/a*2
L = K/math.sqrt(K**2+a**2)
ans = math.degrees(math.asin(L))
print(ans)
else:
K = 2*x/b
L = b/math.sqrt(K**2+b**2)
ans = math.degrees(math.asin(L))
print(ans) | 0 | null | 130,978,854,403,910 | 245 | 289 |
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect
def solve():
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ruia, ruib = [0], [0]
for i in range(n): ruia.append(a[i]+ruia[i])... | def main():
n, a, b = map(int, input().split())
if (b - a) % 2 == 0:
ans = (b - a) // 2
else:
if b - 1 < n - a:
g = (b - a + 1) // 2
ans = a + g - 1
else:
g = (2 * n + a - b + 1) // 2
ans = 2 * n - b - g + 1
print(ans)
if __... | 0 | null | 59,838,681,901,440 | 117 | 253 |
if "7" in input():
print("Yes")
else:
print("No") | def resolve():
print("Yes" if "7" in input() else "No")
if '__main__' == __name__:
resolve() | 1 | 34,249,393,477,738 | null | 172 | 172 |
total_stack = []
single_stack = []
def main():
input_line = input()
total = 0
for i,s in enumerate(input_line):
if s == "\\":
total_stack.append(i)
elif s == "/" and len(total_stack) != 0:
a = total_stack.pop()
total += i - a
area = 0
... | S = raw_input()
S1, S2 = [], []
ans = pool = 0
for i in xrange(len(S)):
if S[i] == "/" and len(S1) > 0:
j = S1.pop()
ans += i - j
a = i - j
while (len(S2) > 0 and S2[-1][0] > j):
a += S2.pop()[1]
S2.append([j, a])
if S[i] == "\\":
S1.append(i)
print a... | 1 | 57,706,770,460 | null | 21 | 21 |
count = int(raw_input())
arr = map(int, raw_input().split())
arr.reverse()
print(" ".join(map(str, arr))) | D = int(input())
C = list(map(int, input().split()))
S = list(list(map(int, input().split())) for i in range(D))
T = list(int(input()) for i in range(D))
manzoku = 0
yasumi= [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
#1日目
for day in range(D):
yasumi = list(map(lambda x: x + 1, yasu... | 0 | null | 5,504,678,489,898 | 53 | 114 |
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline ####
int1 = lambda x: int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().spl... | import bisect
import sys
from bisect import bisect_left
from operator import itemgetter
sys.setrecursionlimit(10**9)
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().split())
def lmi(): return list(map(int, input().split()))
def lmif(n): return [list(map(int, input().split())... | 0 | null | 154,089,916,952,060 | 272 | 294 |
n, a, b = map(int, input().split())
if (a%2 and b%2) or (a%2==0 and b%2==0):
print((b-a)//2)
else:
print(min(a-1, n-b)+1+(b-a-1)//2) | N, A, B = map(int, input().split())
distance =(B - A - 1 )//2
if( (A % 2 == 0 and B % 2 ==0) or (A%2==1 and B%2==1)):
ans=(B - A)//2
else:
ans = min(A-1,N - B) + 1 + distance
print(ans) | 1 | 109,437,070,728,118 | null | 253 | 253 |
K = int(input())
Ans = 'ACL'
for i in range(K-1):
Ans += 'ACL'
print(Ans) | K = int(input())
string = 'ACL'
for i in range(K - 1):
string = string + 'ACL'
print(string)
| 1 | 2,201,090,851,182 | null | 69 | 69 |
import math
a = int(input())
for i in range(50001):
if math.floor(i*1.08) == a:
print(i)
exit()
print(":(") | def main():
n = int(input())
d_lst = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
for j in range(i + 1, n):
ans += d_lst[i] * d_lst[j]
print(ans)
if __name__ == "__main__":
main()
| 0 | null | 146,530,424,310,656 | 265 | 292 |
from decimal import *
getcontext().prec=1000
a,b,c=map(int,input().split())
A=Decimal(a)**Decimal("0.5")
B=Decimal(b)**Decimal("0.5")
C=Decimal(c)**Decimal("0.5")
D= Decimal(10) ** (-100)
if A+B+D<C:
print("Yes")
else:
print("No") | def factorization(n):
arr = []
temp = n
for i in range(2, int(-(-n**0.5//1))+1):
if temp%i==0:
cnt=0
while temp%i==0:
cnt+=1
temp //= i
arr.append([i, cnt])
if temp!=1:
arr.append([temp, 1])
if arr==[]:
arr.a... | 0 | null | 69,532,155,845,930 | 197 | 235 |
n = int(input())
s = input()
r, g, b = [], [], []
cnt = 1
for i in s:
if i == 'R':
r.append(cnt)
elif i == 'G':
g.append(cnt)
else:
b.append(cnt)
cnt += 1
rd = set(map(lambda x: x * 2, r)) #以下2つ目の条件を満たさないもの(j - i = k - j)の数え上げ
gd = set(map(lambda x: x * 2, g))
bd = set(map(lambda... | def main():
nums = list(map(int,input().split()))
for i,n in enumerate(nums):
if n == 0:
return i + 1
if __name__ == '__main__':
print(main()) | 0 | null | 24,632,515,953,010 | 175 | 126 |
s = input()
b = s.swapcase()
print(b)
| import string
s = input()
print(s.translate(str.maketrans(string.ascii_uppercase+string.ascii_lowercase, string.ascii_lowercase+string.ascii_uppercase))) | 1 | 1,519,708,543,250 | null | 61 | 61 |
score = input()
scin = score.split()
ans = int(scin[0]) * int(scin[1])
print(ans) | s = input()
a = [0] * (len(s)+1)
larger_count = 0
for i in range(len(s)):
if s[i] == '>':
larger_count += 1
continue
for j in range(larger_count+1):
a[i-j] = max(a[i-j], j)
larger_count = 0
a[i+1] = a[i] + 1
for j in range(larger_count+1):
a[len(a)-j-1] = max(a[len(a)... | 0 | null | 85,906,967,704,128 | 133 | 285 |
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def resolve():
n = int(input())
A = list(map(int,input().split()))
if n & 1 == 0:
res = -INF
score = sum(A[::2])
res = max(res, score)
for i in ra... | n=int(input())
arr=list(map(int,input().split()))
acum1=[0]
acum2=[0]
for i in range(n):
if i%2==0:
acum1.append(acum1[-1]+arr[i])
acum2.append(acum2[-1]+0)
else:
acum1.append(acum1[-1]+0)
acum2.append(acum2[-1]+arr[i])
if n%2==0:
ans=max(acum1[n-1]-acum1[0],acum2[n]-acum2[1])
for i in range(1,n... | 1 | 37,329,103,538,304 | null | 177 | 177 |
#!/usr/bin python3
# -*- coding: utf-8 -*-
r, c, k = map(int, input().split())
itm = [[0]*(c) for _ in range(r)]
for i in range(k):
ri, ci, vi = map(int, input().split())
itm[ri-1][ci-1] = vi
dp0 = [[0]*4 for c_ in range(3005)]
dp1 = [[0]*4 for c_ in range(3005)]
for i in range(r):
for j in range(c):
... | import sys
input = sys.stdin.buffer.readline
R, C, K = map(int, input().split())
G = [[None for j in range(C)] for i in range(R)]
for _ in range(K):
r, c, v = map(int, input().split())
G[r - 1][c - 1] = v
dp = [[0, 0, 0, 0] for _ in range(C)]
for i in range(R):
for j in range(C):
if G[i][j] is n... | 1 | 5,606,494,903,200 | null | 94 | 94 |
K=int(input())
res=1
x=0
for i in range(K):
x+=7*res
x%=K
if x%K==0:
print(i+1)
break
res*=10
res%=K
else:
print(-1)
| #!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
def input():
return sys.stdin.readline()
def down_pleasure(c_list, day_num, contest_last_day):
"""その日の満足度低下を返す"""
sum_down_pl = 0
for i in range(26):
sum_down_pl += c_list[i] * (day_num - contest_last_day[i])
return sum_down_pl
... | 0 | null | 7,948,496,833,376 | 97 | 114 |
from bisect import bisect
N, M, K = map(int, input().split())
A = map(int, input().split())
B = map(int, input().split())
a_cum = [0]
cum = 0
for x in A:
cum += x
a_cum.append(cum)
b_cum = []
cum = 0
for x in B:
cum += x
b_cum.append(cum)
answer = 0
for i, a in enumerate(a_cum):
remain = K - a
if ... | from itertools import accumulate
from bisect import bisect_left
ri = lambda S: [int(v) for v in S.split()]
def rii():
return ri(input())
N, M, K = rii()
A = rii()
B = rii()
i = j = 0
pA = [0] + list(accumulate(A))
pB = [0] + list(accumulate(B))
ans = 0
for i, a in enumerate(pA):
br = 0
if K >= a:
... | 1 | 10,874,771,854,638 | null | 117 | 117 |
from bisect import bisect_left, bisect_right, insort_left
n = int(input())
s = list(input())
q = int(input())
d = {}
flag = {}
for i in list('abcdefghijklmnopqrstuvwxyz'):
d.setdefault(i, []).append(-1)
flag.setdefault(i, []).append(-1)
for i in range(n):
d.setdefault(s[i], []).append(i)
for i in range(q):
q1,q2,... | print(input().find('0')//2+1)
| 0 | null | 38,102,448,609,202 | 210 | 126 |
a, b = map(int, input().split())
if a % b > 0:
print(a//b + 1)
else:
print(a//b) | n, m = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(m)]
ans = -1
for i in range(1000):
s_i = str(i)
if len(s_i) == n and all(int(s_i[s-1])==c for s,c in sc):
ans = i
break
print(ans) | 0 | null | 68,858,480,312,798 | 225 | 208 |
N = int(input())
Ans = [0] * (N + 1)
def calc(a, b, c):
return a ** 2 + b ** 2 + c ** 2 + a * b + b * c + c * a
for i in range(1, N):
for j in range(1, N):
for k in range(1, N):
x = calc(i, j, k)
if x > N:
break
Ans[x] += 1
for a in Ans[1:]:
p... | s = input()
if s[1] == 'R':
print('ABC')
else:
print('ARC') | 0 | null | 16,093,725,944,310 | 106 | 153 |
s=input()
t=input()
max_=0
for i in range(len(s)-len(t)+1):
c = 0
for j in range(len(t)):
if s[i+j] == t[j]:
c += 1
max_ = max(max_, c)
print(len(t)-max_)
| #177B
S=input()
T=input()
Ss=[]
Ts=[]
Us=[]
Vs=[]
len_T=len(T)
len_S=len(S)
s=0
#初期配列を作成
for t in range(len_T):
Ts.append(T[t])
Ss.append(S[t])
#一致していない箇所の個数を数え、記録
for t in range(len_T):
Us.append(Ts[t]!=Ss[t])
Vs.append(sum(Us))
for s in range(1,len_S-len_T+1):
#Ss配列をずらす
Ss.append(S[len_T+s... | 1 | 3,681,077,340,540 | null | 82 | 82 |
import math
n = int(input())
a = list(map(int, input().split()))
nmax = 10**6
check = [0]*(nmax + 5)
for i in a:
check[i] += 1
pairwise = True
for i in range(2, nmax + 5):
cnt = 0
for j in range(i, nmax + 5, i):
cnt += check[j]
if cnt > 1:
pairwise = False
if pairwise == True:
pr... | n,k,s = map(int, input().split())
ans = []
if s == 10**9:
for i in range(k):
ans.append(10**9)
for i in range(n-k):
ans.append(1)
else:
for i in range(k):
ans.append(s)
for i in range(n-k):
ans.append(s+1)
print(*ans) | 0 | null | 47,737,546,082,212 | 85 | 238 |
import heapq
def main():
_ = int(input())
A = sorted(list(map(int, input().split())), reverse=True)
q = []
heapq.heapify(q)
ans = A[0]
tmp_score = min(A[0], A[1])
heapq.heappush(q, (-tmp_score, A[0], A[1]))
heapq.heappush(q, (-tmp_score, A[1], A[0]))
for a in A[2:]:
g = he... | N = int(input())
A = list(map(int,input().split()))
A.sort(reverse = True)
ans = A[0]
j = 1
for i in range(2,N):
ans += A[j]
if i % 2 == 1:
j += 1
print(ans) | 1 | 9,235,761,191,140 | null | 111 | 111 |
import numpy as np
n, k = map(int, input().split())
aa = list(map(np.int64, input().split()))
aa = np.array(aa)
def mul(dd):
mod = 10**9+7
ret = 1
for d in dd:
ret = (ret*d)%mod
return ret
def sol(aa, n, k):
mod = 10**9+7
aap = aa[aa>0]
aam = aa[aa<0]
if n == k:
return ... | from math import log10
n, k = map(int, input().split())
a = list(map(int, input().split()))
MOD = 10**9+7
a.sort()
cnt_neg = 0
cnt_pos = 0
for i in a:
if i <= 0:
cnt_neg += 1
else:
cnt_pos += 1
is_minus = False
k_tmp = k
while k_tmp > 0:
if k_tmp >= 2:
if cnt_neg >= 2:
cnt_neg -= 2
... | 1 | 9,330,011,154,002 | null | 112 | 112 |
n = int(input())
A = list(map(int, input().split()))
MAX_N = max(A)+ 1
cnt = [0] * MAX_N
for a in A:
for i in range(a, MAX_N, a):
if cnt[i] <= 2:
cnt[i] += 1
ans = 0
for a in A:
if cnt[a] == 1:
ans += 1
print(ans)
| import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
from numba import njit
def getInputs():
D = int(readline())
CS = np.array(read().split(), np.int32)
C = CS[:26]
S = CS[26:].reshape((-1, 26))
return D, C, S
@njit('(i8, i4[:], i4[:, :], i4[:], )', ca... | 0 | null | 11,985,717,423,538 | 129 | 113 |
from collections import deque
K = int(input())
que = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
for i in range(K):
num = que.popleft()
if i == K-1:
print(num)
break
if num%10 == 0:
que.append(num*10 + num%10)
que.append(num*10 + num%10 + 1)
elif num%10 == 9:
que.append(nu... | n = int(input())
a = list(map(int, input().split()))
s = sum(a)
q = int(input())
l = [0] * 100000
for i in a:
l[i-1] += 1
for i in range(q):
x,y = map(int, input().split())
hoge = l[x-1]
s -= hoge*x
s += hoge*y
l[y-1] += hoge
l[x-1] = 0
print(s)
| 0 | null | 26,040,013,187,548 | 181 | 122 |
from collections import deque
def main():
n, m = map(int, input().split())
to = [[] for _ in range(n+1)]
for _ in range(m):
a, b = map(int, input().split())
to[a].append(b)
to[b].append(a)
q = deque([1])
ans = [None]*(n+1)
while q:
p = q.pop()
for child i... | from collections import deque
from sys import stdin
input = stdin.readline
def main():
N, M = list(map(int, input().split()))
G = [[] for _ in range(N+1)]
for i in range(M):
a, b = map(int, input().split())
G[a].append(b)
G[b].append(a)
from_ = [0]*(N+1)
q = deque([1])
seen = set()
seen.ad... | 1 | 20,503,669,862,840 | null | 145 | 145 |
import sys
input = sys.stdin.readline
from collections import deque
def main():
n = int(input().strip())
v = [[] for _ in range(n)]
for i in range(n):
v[i] = list(map(int, input().strip().split()))
l = [-1] * (n+1)
q = deque()
q.append((1, 0))
while len(q) != 0:
id, d = q.popleft()
# print("id", id)
if ... | from collections import deque
N = int(input())
Graph = {}
Node = []
visited = [-1]*(N)
for i in range(N):
tmp = input().split()
if int(tmp[1]) != 0:
Graph[i] = [int(x)-1 for x in tmp[2:]]
else:
Graph[i] = []
queue = deque([0])
visited[0] = 0
while queue:
x = queue.popleft()
for i... | 1 | 4,440,007,770 | null | 9 | 9 |
def r(i):
indr = s.find('<', i)
return indr - i if indr != -1 else n - i - 1
def l(i):
indl = s.rfind('>', 0, i)
return i - indl -1 if indl != -1 else i
s = input()
n = len(s) + 1
print(sum([max(r(i), l(i)) for i in range(n)])) | from sys import stdin
import collections
def ip(): return [int(i) for i in stdin.readline().split()]
def sp(): return [str(i) for i in stdin.readline().split()]
# 4 6
# 1 2
# 1 3
# 1 4
# 2 3
# 2 4
# 3 4
def find(d,x):
root = x
while root != d[root]:
root = d[root]
while x != root:
nxt = d... | 0 | null | 80,576,725,533,652 | 285 | 84 |
n = int(input())
mod = 10**9+7
ls = list(map(int,input().split()))
di = [i**2 for i in ls]
print((((sum(ls)**2)-(sum(di)))//2)%mod) | def main():
n=int(input())
a=list(map(int, input().split()))
mod=10**9+7
ans=((sum(a)%mod)**2)%mod
for i in range(n):
ans-=a[i]**2
ans%=mod
m=pow(2,mod-2,mod)
print(ans*m%mod)
main() | 1 | 3,841,149,650,140 | null | 83 | 83 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.