code1 stringlengths 17 427k | code2 stringlengths 17 427k | similar int64 0 1 | pair_id int64 2 181,637B ⌀ | question_pair_id float64 3.7M 180,677B ⌀ | code1_group int64 1 299 | code2_group int64 1 299 |
|---|---|---|---|---|---|---|
def main():
""""ここに今までのコード"""
N, K = map(int, input().split())
dice_list = list(map(int, input().split()))
max, s = 0, 0
for i in range(K):
s += (dice_list[i] + 1) / 2
max = s
for i in range(N-K):
s -= (dice_list[i] + 1) / 2
s += (dice_list[i+K] + 1) / 2
... | N, K = map(int, input().split())
P = list(map(int, input().split()))
S = [0]
sum_ = 0
for i, p in enumerate(P):
sum_ += p
S.append(sum_)
max_sum = 0
for i in range(N-K+1):
max_sum = max(max_sum, S[i+K] - S[i])
res = (max_sum + K) / 2
print(res) | 1 | 74,946,004,405,860 | null | 223 | 223 |
#coding:utf-8
while True:
try:
a, b = map(int, raw_input(). split())
x = a * b
while True:
c = a % b
a = b
b = c
if b == 0:
break
x = x / a
print("%d %d" % (a, x))
except:
break | def ncr(n, r):
num, den = 1, 1
if n - r < r:
r = n - r
for i in range(1, r + 1):
num *= n - i + 1
num %= MOD
den *= i
den %= MOD
return num * pow(den, MOD - 2, MOD) % MOD
MOD = 10 ** 9 + 7
X, Y = map(int, input().split())
Z = X + Y
if Z % 3 or Y > 2 * X or Y < ... | 0 | null | 75,231,923,247,042 | 5 | 281 |
import sys
for i, x in enumerate(map(int, sys.stdin)):
if not x: break
print("Case {0}: {1}".format(i + 1, x)) | # C - Sum of product of pairs
from itertools import accumulate
def main():
N, *A = map(int, open(0).read().split())
rev_cumsum = list(accumulate(reversed(A[1:])))[::-1]
MOD = 10 ** 9 + 7
res = sum(a * c for a, c in zip(A[:-1], rev_cumsum)) % MOD
print(res)
if __name__ == "__main__":
main()
| 0 | null | 2,116,615,840,420 | 42 | 83 |
from collections import deque
N = int(input())
def dfs(str):
if len(str) == N:
print(*str, sep="")
return
M = max(str)
for i in range(ord(M) - ord("a") + 2):
char = alpha[i]
str.append(char)
dfs(str)
str.pop()
alpha = 'abcdefghijklmnopqrstuvwxyz'
s = deque... | str = input()
for char in str:
if char.islower():
print(char.upper(), end='')
else:
print(char.lower(), end='')
print(""); | 0 | null | 27,105,915,709,928 | 198 | 61 |
X,K,D = map(int,input().split())
ans = 0
if X == 0:
if K % 2 == 0:
ans = 0
else:
ans = D
if X > 0:
if K*D <= X:
ans = X - K*D
else:
n = X // D
if X % D != 0:
n += 1
if (K - n) % 2 == 0:
ans = abs(X-D*n)
else:
ans... | from itertools import product
H, W, K = map(int, input().split())
grid = ""
for _ in range(H):
grid += input()
ans = 10000
for Hcut in product((0, 1), repeat = H-1):
Gr_num = sum(Hcut) + 1
old = [0]*Gr_num
cnt = 0
for i in range(W):
#縦一列のchocoを見る
choco = grid[i::W]
new = [0]*Gr_num
gr = 0
... | 0 | null | 26,808,456,748,932 | 92 | 193 |
import sys
input = sys.stdin.readline
n = int(input())
A = tuple(int(x) for x in input().split())
_ = int(input())
M = tuple(int(x) for x in input().split())
S = set()
def Check(i, s):
if i == n:
S.add(s)
return
Check(i + 1, s + A[i])
Check(i + 1, s)
Check(0, 0)
for m in M:
if m in S... | n = int(input())
info = []
for i in range(n):
b, f, r, v = input().split()
b = int(b)
f = int(f)
r = int(r)
v = int(v)
if info == []:
info.append([b, f, r, v])
else:
for x in info:
if b == x[0] and f == x[1] and r == x[2]:
x[3] += v
... | 0 | null | 612,913,959,580 | 25 | 55 |
k=int(input())
s=input()
l=len(s)
if l<=k:
print(s)
else:
s=list(s)
t=[]
for i in range(k):
t.append(s[i])
t.append('...')
print(''.join(t))
| k=int(input())
s=input()
if len(s)<=k:
print(s)
else:
for i in range(k):
print(s[i],end="")
print("...",end="") | 1 | 19,687,474,396,690 | null | 143 | 143 |
# ABC170
n = int(input())
a = list(map(int, input().split()))
a.sort()
a_max = max(a)
dp = [True for _ in range(a_max+1)]
ans = 0
for i in range(n):
if dp[a[i]]:
for j in range(0, a_max+1, a[i]):
dp[j] = False
if i > 0:
if a[i] == a[i-1]:
continue
i... | import sys
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())
def solve():
m = a[-1]+1
ava = [0]*m
for rep in a:
ava[rep] += 1
if ava[rep]==1:
for item in range(2*rep,m,rep):
ava[item] += 2
prin... | 1 | 14,413,916,755,040 | null | 129 | 129 |
n = int(input())
x = input()
f = [-1] * (n+10)
f[0] = 0
for i in range(1, n+10):
# python bitcount で見つけたこれを参考に https://ameblo.jp/316228/entry-10518720149.html
f[i] = f[i % bin(i).count('1')] + 1
init_bitcount = x.count('1')
# Xを init_bitcount+1とinit_bitcount-1で割った余り
x_mod_01 = 0
for digit in x:
x_mod_01... | from itertools import product
from collections import deque
class ZeroOneBFS:
def __init__(self, N):
self.N = N # #vertices
self.E = [[] for _ in range(N)]
def add_edge(self, init, end, weight, undirected=False):
assert weight in [0, 1]
self.E[init].append((end, weight)... | 0 | null | 28,697,619,184,532 | 107 | 194 |
from collections import defaultdict
import itertools
N = int(input())
L = list(map(int, input().split()))
dic = defaultdict(int)
for num in L:
dic[num] += 1
set_L = set(L)
comb = list(itertools.combinations(set_L, 3))
ans = 0
for a,b,c in comb:
if a+b <= c or b+c<=a or c+a <= b: continue
ans += dic[a... | n = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
ans = A[0]
if n%2 == 0:
ans += sum(A[1:n//2])*2
else:
ans += sum(A[1:n//2])*2 + A[n//2]
print(ans) | 0 | null | 7,107,979,160,272 | 91 | 111 |
# -*- coding: utf-8 -*-
import sys
from math import ceil
for line in sys.stdin.readlines():
List = map(int, line.strip().split())
n = List[0]
yen = 100000
for i in xrange(n):
yen *= 1.05
yen = int(ceil(yen/1000)) * 1000
print yen | #!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import itertools
import math
import sys
INF = float('inf')
YES = "Yes" # type: str
NO = "No" # type: str
def solve(N: int, M: int, A: "List[int]"):
t = sum(A)/4/M
return [YES, NO][le... | 0 | null | 19,340,084,127,428 | 6 | 179 |
h,w=map(int,input().split())
field=[list(input()) for i in range(h)]
ans=[[0 for i in range(w)]for j in range(h)]
if field[0][0]=='#':
ans[0][0]=1
def black(i,j,f):
if f==1:
if field[i][j]=='#' and field[i-1][j]=='.':
return 1
else:
return 0
else:
if field[i][j]=='#' and field[i][j-1]=='.... | def main():
# a,b,k = map(int,input().split())
# n,k = map(int,input().split())
s = int(input())
# a = list(map(int,input().split()))
# rsp = list(str(input()))
# l = [list(map(int, input().split())) for _ in range(n-1)]
# s = list(s)
print(int(s**2))
if __name__ == '__main__':
main() | 0 | null | 97,166,319,201,732 | 194 | 278 |
k=int(input())
count=1
num=7
for _ in range(k):
if num%k == 0:
print(count)
break
else:
count += 1
num = (num % k)*10 + 7
else:
print(-1) |
K = int(input())
if K % 2 == 0:
print(-1)
else:
seen = set()
ans = 1
num = 7
while ans <= K:
mod = num % K
if mod in seen:
ans = -1
break
else:
seen.add(mod)
if mod == 0:
break
else:
num... | 1 | 6,169,438,649,842 | null | 97 | 97 |
n=int(input())
m=1000000007
print(((pow(10,n,m)-2*pow(9,n,m)+pow(8,n,m))+m)%m)
| def gcd(a, b):
c = max([a, b])
d = min([a, b])
if c % d == 0:
return d
else:
return gcd(d, c % d)
nums = input().split()
print(gcd(int(nums[0]), int(nums[1])))
| 0 | null | 1,579,125,205,980 | 78 | 11 |
I=raw_input()
O=str()
list_upper="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#list_lower="abcdefghijklmnopqrstuvwxyz"
for i in I:
if i in list_upper:
O+=i.lower()
else:
O+=i.upper()
print O | # -*- coding: utf-8 -*-
import sys
def func2(x):
if not x.isalpha():
return x
else:
if x.isupper():
return x.lower()
else:
return x.upper()
print("".join(map(lambda x:func2(x),sys.stdin.readline().rstrip())))
| 1 | 1,502,191,147,680 | null | 61 | 61 |
while 1:
m,f,r=map(int,input().split());s=m+f
if r<0>s:break
print('F'if m*f<0 or s<30 else'D'if(s<50)*(r<50)else'C'if s<65 else'B'if s<80 else'A')
| while True:
try:
m,f,r = map(int,raw_input().split())
if all(k == -1 for k in [m,f,r]):
break
except EOFError:
break
if m == -1 or f == -1:
print 'F'
elif m + f >= 80:
print 'A'
elif 65 <= m + f <80:
print 'B'
elif 50 <= m + f < 65... | 1 | 1,201,568,634,848 | null | 57 | 57 |
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from decimal import *
input = sys.stdin.readline
def inputInt(): return int(input())
def inputMap(): retu... | import copy
import random
import sys
import time
from collections import deque
t1 = time.time()
readline = sys.stdin.buffer.readline
global NN
NN = 26
def evaluate(D, C, S, out, k):
score = 0
last = [0 for _ in range(NN)]
for d in range(len(out)):
last[out[d]] = d + 1
for i in range(N... | 1 | 9,669,112,597,426 | null | 113 | 113 |
def bubbleSort( cards ):
n = len( cards )
for i in range( 0, n ):
for j in range( n-1 , i, -1 ):
if int( cards[j][1] ) < int( cards[ j-1 ][1] ):
cards[j], cards[ j-1 ] = cards[ j-1 ], cards[j]
print( " ".join( map( str, cards ) ) )
def selectionSort( cards ):
n = len... | def bubble_sort(r, n):
flag = True # ??£??\????´?????????¨????????°
while flag:
flag = False
for i in range(n - 1, 0, -1):
if r[i - 1][1] > r[i][1]:
r[i - 1], r[i] = r[i], r[i - 1]
flag = True
return r
def select_sort(r, n):
for i in range(0... | 1 | 24,831,168,798 | null | 16 | 16 |
T1,T2=map(int,input().split())
A1,A2=map(int,input().split())
B1,B2=map(int,input().split())
OU=T1*(A1-B1)
HUKU=T2*(A2-B2)
TOTAL=OU+HUKU
if TOTAL==0:
print("infinity")
elif (OU>0 and TOTAL>0) or (OU<0 and TOTAL<0):
print(0)
elif (OU>0 and TOTAL*(-1)>OU) or (OU<0 and TOTAL*(-1)<OU):
print(1)
else:
K=int(OU/TOTAL)*-1... | T = [int(t) for t in input().split()]
A = [int(t) for t in input().split()]
B = [int(t) for t in input().split()]
d1 = T[0]*(A[0]-B[0])
d2 = d1 + T[1]*(A[1]-B[1])
if d2 == 0:
ans = "infinity"
elif d1 > 0 and d2 > 0:
ans = 0
elif d1 < 0 and d2 < 0:
ans = 0
else:
d1 = abs(d1)
d2 = abs(d2)
ans = ... | 1 | 131,570,447,797,328 | null | 269 | 269 |
####
n = int(input())
memo = [-1]*(n+10)
def fib(i):
if i==0 or i == 1:
return 1
if memo[i] != -1:
return memo[i]
memo[i] = fib(i-1) + fib(i-2)
return memo[i]
print(fib(n))
| count = 0
m = 0
G = []
def insertionSort(A, n, g):
global count
for i in range(g,n):
v = A[i]
j = i - g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j = j - g
count += 1
A[j+g] = v
def shellSort(A, n):
global count
global m
global G
... | 0 | null | 14,922,631,598 | 7 | 17 |
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
impo... | h,n=list(map(int ,input().split()))
l=list(map(int ,input().split()))
ans=0
count=0
for i in range(0,n):
ans+=l[i]
if(ans==h or ans>h):
count+=1
else:
count+=0
if(count>0):
print("Yes")
else:
print("No") | 0 | null | 129,839,063,162,240 | 299 | 226 |
import math
def fact(n):
ans = 1
for i in range(2, n+1):
ans*= i
return ans
def comb(n, c):
return fact(n)//(fact(n-c)*c)
r = float(input())
print("%.20f"%(2.0*math.pi*r))
| import numpy as np
n = int(input())
cnt = 0
for k in range(1,n+1):
d = n//k
if d == 1:
cnt += (k+n)*(n-k+1)//2
break
cnt += k*d*(d+1)//2
print(cnt) | 0 | null | 21,328,209,008,884 | 167 | 118 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.