id stringlengths 2 5 | title stringclasses 1
value | text stringlengths 5 289k |
|---|---|---|
d1089 | t=int(input())
while(t):
s=input().split()
m=int(s[0])
p=float(s[1])
if(m%2==0):
r=(1-p**m)/(p+1)
else:
r=(1+p**m)/(p+1)
print(1000000000*r,1000000000*(1-r))
t-=1 | |
d109 | for _ in range(int(input())):
n=int(input())
li=list(map(int,input().split()))
ans=0
for i in range(n):
if li[i]>=i:
ans+=1
else:
break
for i in range(n):
if li[n-1-i]>=i:
ans+=1
else:
break
if ans>n:
print("... | |
d1090 | def dfs(node):
nonlocal adj,leaf
val=0
flag=0
for i in adj[node]:
x= dfs(i)
val+=x
if x==0:
flag=1
leaf+=val-val%3
if val%3==0 and flag==0:
return 1
else:
return 0
for _ in range(int(input())):
n=int(input())
adj=[[] for i in range(n+2)]
arr=[int(i) for i in input().split()]
leaf=0
#print(adj)
... | |
d1091 | # cook your dish here
import collections
def shortestSubarray(A, K):
N = len(A)
P = [0]
for x in A:
P.append(P[-1] + x)
#Want smallest y-x with Py - Px >= K
ans = N+1 # N+1 is impossible
monoq = collections.deque() #opt(y) candidates, represented as indices of P
for y, Py in enume... | |
d1092 | # cook your dish here
import math
def isPos(num):
if num%2==0:
for i in range(num,2*num,1):
if ((num**2)-((i/2)**2))**(1/2)==int(((num**2)-((i/2)**2))**(1/2)):
return 'YES'
return 'NO'
else:
for i in range(num+1,2*num,1):
if ((num**2)-((i/2)**2))**(1/2)==int(((num**2)-((i/2)**2))**(1/2)):
return '... | |
d1093 | # cook your dish here
t=int(input())
for i in range(t):
(n,k,e,m)=tuple(map(int,input().split()))
scores=[]
for j in range(n-1):
scores.append(sum(list(map(int,input().split()))))
scores.sort(reverse=True);
bsc=scores[k-1];
msc=sum(list(map(int,input().split())))
mini=bsc-msc+1
if(mini<0):
print(0)
elif(mi... | |
d1094 | # # # # n = int(input())
# # # # arr = list(map(int , input().split()))
# # # # for _ in range(int(input())):
# # # # l,r,mod = map(int , input().split())
# # # # pro = 1
# # # # for i in range(l - 1,r):
# # # # pro *= arr[i]
# # # # print(pro % mod) #sample testcases passed #TLE
# # # import numpy #or us... | |
d1095 | t = int(input())
for i in range(t):
n = int(input())
suffixes = {}
xx = input().split()
for x in range(n):
try:
a = suffixes[xx[x][-3:]]
except Exception as e:
a = []
a.append(xx[x])
suffixes.update({xx[x][-3:]: a})
print("Case : %d" % (i + 1))
for a in sorted(suffixes):
print("".join(b + " " fo... | |
d1096 | n=int(input())
arr=[int(x) for x in input().split()]
l=[1]*n
if sorted(arr)==arr:
print('0')
else:
for i in range(0,len(arr)):
for j in range(i):
if arr[i]>=arr[j] and l[i]<l[j]+1:
l[i]=l[j]+1
print(n-max(l)) | |
d1097 | import sys
n, x, y = input().split(' ')
n = int(n)
x = int(x)
y = int(y)
contests = {}
for i in range(n):
s, e = input().split(' ')
s = int(s)
e = int(e)
contests[(s, e)] = abs(s-e)
v_time = input().split(' ')
w_time = input().split(' ')
v_time, w_time = list(map(int, v_time)), list(map(int, w_time))
v_time.sort... | |
d1098 | testcases=int(input())
results=[]
for i in range(0,testcases):
friends=int(input())
l,b=list(map(int,input().split()))
over=False
if b>l:
temp=b
b=l
l=temp
for counter in range(0,friends):
if l==b:
over=True
break
elif l>b:
l=l-b
if b>l:
temp=b
b=l
l=temp
if over:
results.... | |
d1099 | # cook your dish here
for i in range(int(input())):
n = int(input())
l = list(map(int,input().split()))
s = 0
l.sort(reverse = True)
for i in range(0,n,2):
s = s+l[i]
print(s)
| |
d11 | for _ in range(int(input())):
# n, x = map(int, input().split())
n = int(input())
arr = list(map(int, input().split()))
ans = [arr[0]]
for i in range(1, n - 1):
if arr[i - 1] < arr[i] and arr[i] > arr[i + 1]:
ans.append(arr[i])
elif arr[i - 1] > arr[i] and arr[i] < arr[i ... | |
d110 | import sys
import math
from collections import defaultdict
from collections import deque
from itertools import combinations
from itertools import permutations
input = lambda : sys.stdin.readline().rstrip()
read = lambda : list(map(int, input().split()))
go = lambda : 1/0
def write(*args, sep="\n"):
for i in args:
... | |
d1100 | import sys
def f(p):
votes = {}
for x in range(p):
str = sys.stdin.readline()
t = str.split()
votes[t[0]] = t[1]
ans = 0
for per in votes:
if votes[per] == "+":
ans= ans+1
else:
ans = ans-1
return ans
x = sys.stdin.readline()
for t in range(int(x)):
p = sys.stdin.readline... | |
d1101 | # cook your dish here
"""
Input:
The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
The first line of each test case contains three space-separated integers p, q and r.
The second line contains three space-separated integers a, b and c.
Ou... | |
d1102 | from collections import Counter
from math import factorial
def nc3(n):
a=factorial(n)
b=factorial(n-3)
return ((a)/(b*6))
def rem(s,k):
t=-1
x=-1
for i in range(len(s)):
if s[i][0]>2 and s[i][1]<=k:
if s[i][0]>3:
ch=(nc3(s[i][0])-nc3(s[i][0]-1))/s[... | |
d1103 | for _ in range(int(input())):
n=int(input())
n1=0
ans=1
while(n>0):
d=int(n % 10)
if(d!=0):
if(d!=9 and d!=7 and d!=1):
n1=3
elif(d==1):
n1=1
else:
n1=4
ans=(int(ans)*int(n1))% (1000000007)
n/=10
else:
n/=10
if(ans==1):
print("0")
else:
print(ans %(1000000007))
| |
d1104 | import sys
import math
r=int(input())
for v in range (0,r):
n = int(input())
x=1
arr=list(map(int,input().strip().split(" ")))
for i in range (0,n):
x=x*arr[i]
for i in range (2,100000000):
if(x%(pow(i,2))==0):
ans1=i
break
print(ans1)
| |
d1105 | # cook your dish here
T=int(input())
MOD=int(1e9+7)
for t in range(T):
N,K=[int(a) for a in input().split()]
M=K//2
# ans= ((K%2)?( (N+M)*(N+M) + M ):( (N+M)*(N+M) - M) )
ans=(N+M)*(N+M) -M
if(K%2):
ans+=2*M
if(N==0):
ans=K*(K-1)
print(ans%MOD) | |
d1106 | for i in range(int(input())):
n=int(input())
c=[int(z) for z in input().split()]
c.sort()
c.reverse()
b1,b2=0,0
for i in range(n):
if b1<b2:
b1+=c[i]
elif b2<b1:
b2+=c[i]
else:
b1+=c[i]
print(max(b1,b2))
| |
d1107 | '''Well I found the bug, but I don't understand why it was doing that. I mean, as
far as I can tell, it shouldn't be a bug!
Note to self: deleting from (supposedly) local lists through recursion is dangerous!'''
class Group(object):
def __init__(self,size,start,end,value):
self.size = size
self.sta... | |
d1108 | # cook your dish here
from sys import stdin
from math import sqrt,ceil,log10
def get_sum(a,b,digits):
sum=((b+a)*(b-a+1))//2
return sum*digits
def solve():
mod=10**9+7
thehighlimiter={i: 10 ** i - 1 for i in range(12)}
thelowlimiter={i: 10**i for i in range(12)}
for _ in range(int(input())):
... | |
d1109 | N,M,K=map(int,input().split())
c=0
for i in range(N):
T=list(map(int,input().split()))
Q=T[-1]
T.pop(-1)
if Q<=10 and sum(T)>=M:
c+=1
print(c) | |
d111 | for _ in range(int(input())):
n, k = tuple(map(int, input().split()))
arr = list(map(int, input().split()))
peaks = [0 for i in range(n)]
for i in range(1, n - 1):
if arr[i] > arr[i - 1] and arr[i] > arr[i + 1]:
peaks[i] = 1
cnt = 0
max_peaks = 0
answer = 0
for i i... | |
d1110 | import math
for t in range(int(input())):
n = int(input())
temp = math.sqrt(n)
if (temp == int(temp)):
print("YES")
else:
print("NO") | |
d1111 | # cook your dish here
for _ in range(int(input())):
n=int(input());li=list(map(int,input().split()));dli=dict();modi=0
for i in li:
if i not in dli:dli[i]=1
else:dli[i]+=1
op=sorted(list(dli))
if(len(dli)!=0):
while 1:
tmp=[]
for i in op:
if dli[i]==0:continue
tm... | |
d1112 | # cook your dish here
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
even=[]
odd=[]
for i in a:
if(i & 1):
even.append(i)
else:
odd.append(i)
print(len(even)*len(odd)) | |
d1113 | # cook your dish here
for _ in range(int(input())):
n = int(input())
m = n
x= 1
for i in range(n):
for j in range(m):
print(x, end = '')
x += 1
print()
m -= 1 | |
d1114 | t = input();
a = [0 for i in range(10001)]
i = 0;
while i < int(t):
n = input();
k = input();
assert(len(k.split(' ')) == int(n));
for each in k.split(' '):
a[int(each)] += 1;
V = 0;
C = a[V];
for j in range(10001):
if C < a[j]:
V = j;
C = a[V];
a[j] = 0;
i += 1;
print(V, C);
| |
d1115 | T=int(input())
for i in range(T):
N=int(input())
A=list(map(int,input().split()))[:N]
l=[]
for j in range(len(A)):
for k in range(j+1,len(A)):
l.append(A[j]+A[k])
print(l.count(max(l))/((N*(N-1))/2)) | |
d1116 | T = int(input())
M = 10 ** 9 + 7
for _ in range(T):
N = int(input())
A = list(map(int, input().split()))
if N == 1:
print(0)
continue
B = {}
C = {}
for i in range(N - 1):
u, v = input().split()
u = int(u) - 1
v = int(v) - 1
if u not in B:
B[u] = []
if v not in B:
B[v] = []
B[u].appe... | |
d1117 | from collections import defaultdict
def findSubarraySum(arr, n, Sum):
# Dictionary to store number of subarrays
# starting from index zero having
# particular value of sum.
prevSum = defaultdict(lambda : 0)
res = 0
# Sum of elements so far.
currsum = 0
for i in range(0, n):
# Add c... | |
d1118 | import numpy as np
def sort_it(array):
new_list = []
for i in range(len(array)):
start = 0
value = array[i][0]
last = len(new_list)
while start != last:
mid = (start + last) // 2
if new_list[mid][0] > value:
last = mid
else:
... | |
d1119 | '''
Name : Jaymeet Mehta
codechef id :mj_13
Problem : Avenir Strings
'''
from sys import stdin,stdout
test=int(stdin.readline())
for _ in range(test):
N=int(stdin.readline())
seq=list(input())
fp,fp1,fl,fl1=0,0,0,1
for i in range(N):
if fl!=int(seq[i])-0:
fp+=1
fl=1-fl
for i in range(N):
if fl1!=int(seq[i... | |
d112 | #!/usr/bin/env python
# coding:utf-8
# Copyright (C) dirlt
from sys import stdin
def run(n, m, pixels):
ans = 1 << 30
acc = [[0] * (m + 1) for _ in range(n + 1)]
for i in range(n):
for j in range(m):
acc[i + 1][j + 1] = acc[i + 1][j] + int(pixels[i][j])
for j in range(m):
... | |
d1120 | #dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]
def kadane(arr, start, finish, n):
Sum = 0
maxSum = float('-inf')
i = None
finish[0] = -1
local_start = 0
for i in range(n):
... | |
d1121 | #AUTHOR:: AMAN VERMA
try:
for _ in range(int(input())):
row,column=list(map(int,input().split(" ")))
x_x,y_y=list(map(int,input().split(" ")))
ab=max((x_x-0),(row-x_x-1))
ba=max((y_y-0),(column-y_y-1))
print(ab+ba)
except:
pass
| |
d1122 | # cook your dish here
t=int(input())
while t>0:
a=input().split(":")
a1=int(a[0])
a2=int(a[1])
b1=a1%12
if a2%5!=0:
b2=(a2//5)*5+5
else:
b2=a2
c1=b1*30
extra=0.5*b2
c1+=extra
c1%=360
d1=(b2//5)*30
d1%=360
if c1>d1:
ans1=c1-d1
ans2=360-ans1
else:
ans1=d1-c1
ans2=360-ans1
ans=min(a... | |
d1123 | # cook your dish here
while True:
try:
m=int(input())
n=int(m/2)
a=m-n
sum_even= int(2*(2*n*(n+1)*(2*n+1))/3)
sum_odd= int(((4*a*a*a)-a)/3)
result=sum_odd+sum_even
if result%2==0:
print('Ravi')
else:
print('Jhon')
except:
break; | |
d1124 | # cook your dish here
from sys import stdin, stdout
from math import ceil
def solve():
for _ in range(int(input())):
n, m = map(int, stdin.readline().split())
par = [i for i in range(n)]
for i in range(m):
ta, tb = map(int, stdin.readline().strip().split())
a, b = m... | |
d1125 | # cook your dish here
# cook your dish here
t=int(input())
for _ in range(t):
n,p,q=list(map(int,input().split(" ")))
l=list(map(int,input().split(" ")))
l.sort()
s=sum(l)
a=p+2*q
b=0
for i in l:
if(p==0):
if(i%2==0 and a>=i):
a=a-i
b=b+1
elif(q==0):
if(a>=i):
a=a-i
b=b+1
else:
if(... | |
d1126 | # cook your dish here
for _ in range(int(input())):
n=list(map(int,input().split()))
print(n[0]*n[1])
| |
d1127 | for _ in range(int(input())):
n=int(input())
print((2*(pow(n,2)))-n+1)
| |
d1128 | # cook your dish here
x= int(input())
for i in range(x):
y = list(map(str, input().split()))
j= 0
while j<len(y)-1:
print((y[j][0]).capitalize()+".", end=' ')
j+= 1
print(y[len(y)-1].capitalize()) | |
d1129 | import sys
t = eval(input())
for j in range(t):
n = eval(input())
a = list(map(int, input().split()))
ch = 0
sm = 0 ; x = sum(a)
s1 = [0] * n ; s2 = [0] * n
for i in range(n):
sm += a[i]
s1[i] = sm
s2[i] = x
x -= a[i]
if(sum(a) - a[0] == 0):
print(0)
elif(sum(a) - a[n - 1] == 0):
print(n - 1)
else... | |
d113 | import math
def lexComp(a, b):
if a[0] != b[0]:
return -1 if a[0] < b[0] else 1
if a[1] != b[1]:
return -1 if a[1] < b[1] else 1
return 0
def turn(a, b, c):
return (b[0] - a[0]) * (c[1] - b[1]) - (b[1] - a[1]) * (c[0] - b[0])
def dist2(a, b):
return (a[0] - b[0]) ** 2 + (a[1] ... | |
d1130 | def fastpow(base, power):
result = 1
while power > 0:
if power % 2 == 0:
power = power // 2
base = base * base
else:
power = power - 1
result = result * base
power = power // 2
base = base * base
return result
t=int(input())
for i in range(t):
a=list(map(int,input().split()))
n,r=a[0],a[1]
... | |
d1131 | for _ in range(int(input())):
f,d=list(map(int,input().split()))
arr=list(map(int,input().split()))
risk=0
days_risk=0
days_norm=0
if d==1:
print(f)
else:
for a in arr:
if a>=80 or a<=9:
risk+=1
norm=f-risk
if risk%d==0:
days_risk=risk//d
else:
days_risk=(risk//d)+1
if norm%d==0:
days... | |
d1132 | for _ in range(int(input())):
n,k=[int(x) for x in input().split()]
a=list(map(int,input().split()))
dp=[0]*(max(a)+1)
for _ in range(n):
dp[a[_]]+=1
for _ in range(1,len(dp)):
if dp[_]>k:
print(_,end=" ")
print() | |
d1133 | mod = 1000000007
fac = [1,1]
maxn = (10**5)+5
for i in range(2,maxn):
x = (fac[-1]*i)%mod
fac.append(x)
pre = [1]
for i in range(2,maxn):
x = 2*i-1
x = (pre[-1]*x)%mod
pre.append(x)
for _ in range(int(input())):
n = int(input())
x = fac[n]
y = pre[n-1]
print((x*y)%... | |
d1134 | from sys import stdin,stdout
from math import gcd
nmbr=lambda:int(stdin.readline())
lst=lambda:list(map(int, stdin.readline().split()))
for _ in range(nmbr()):
n=nmbr()
a=lst()
g=a[0]
ans=0
for v in a[1:]:
g=gcd(v,g)
for i in a:
ans+=i//g
print(g,ans) | |
d1135 | t=int(input())
for i in range(t):
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
army=0
if n>m:
for i in range(0,m):
army+=a[i]
for j in range(m,n):
army=army-(a[j]/2)
if army<0:
print('DEFEAT')
break
else:
continue
else:
print('VICTORY')
if n<=m... | |
d1136 | # cook your dish here
t=int(input())
while t!=0:
n,k=map(int,input().split())
lst=[]
for i in range(1,n+1):
lst.append(i)
lst[k],lst[n-1]=lst[n-1],lst[k]
for item in lst:
print(item,end=' ')
t-=1 | |
d1137 |
t = int(input())
for _ in range(t):
n,m = map(int,input().split())
if n==1:
print(m)
else:
if n%2==0:
print((n//2)*m)
else:
print(((n//2)+1)*m) | |
d1138 | test = int(input())
ANS = list()
for i in range(test):
n = int(input())
items = sorted(list(map(int, input().split())))
c = 1
for j in range(len(items)):
if items[j] < 2000:
t = 2000 - items[j]
if t in items[j+1:]:
ANS.append("Accepted")
c = 2
break
else:
pass
else:
break
if c==1:
... | |
d1139 | a=eval(input())
while(a):
x=eval(input())
b=list(map(int,input().split()))
z=[0]*100
k=1
j=0
c=0
for i in b:
if i==0:
z.insert(i,k)
else:
if z[z.index(i)+1]==0:
z.insert(j,k)
else:
m=z.index(i)
n=m+1
p=(len(z)-z.count(0))-n
c=c+min(n,p)
z.insert(m+1,... | |
d114 | import math
from decimal import Decimal
import heapq
from collections import deque
def na():
n = int(input())
b = [int(x) for x in input().split()]
return n,b
def nab():
n = int(input())
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
return n,b,c
def dv():
n, m = list(map(in... | |
d1140 | t = int(input())
while t>0:
s = input().strip()
if not s:
print('NO')
dp = [0 for x in range(len(s) + 1)]
dp[0] = 1
dp[1] = 1 if 0 < int(s[0]) <= 9 else 0
for i in range(2, len(s) + 1):
if 0 < int(s[i-1:i]) <= 9:
dp[i] += dp[i - 1]
if s[i-2:i][0] != '0' and int(s[i-2:i]) <= 26:
dp[i] += dp[i - 2]
... | |
d1141 | for _ in range(int(input())):
p, idx = map(int, input().split())
b = bin(idx)[2:]
b = ('0' * (p - len(b)) + b)[::-1]
print(int(b, 2)) | |
d1142 | try:
t,m=input().split()
t=int(t)
m=list(m)
letters=list("abcdefghijklmnopqrstuvwxyz")
trans={}
for i in range(len(letters)):
trans[letters[i]]=m[i]
for i in range(t):
x=list(input())
y=""
for j in x:
if(j.isalpha()==True):
if(j.isupper()==True):
y+=trans[j.lower()].upper()
else:
y+=... | |
d1143 | arr=[]
n=int(input())
for i in range(n):
a=int(input())
arr.append(a)
arr.sort()
p=arr.index(a)
print((i-p)+1) | |
d1144 | # cook your dish here
def isPrime(n) :
# Corner cases
if (n <= 1) :
return False
if (n <= 3) :
return True
# This is checked so that we can skip
# middle five numbers in below loop
if (n % 2 == 0 or n % 3 == 0) :
return False
i = 5
while(i * i <= ... | |
d1145 | T= int(input());
for i in range(T):
n,k = list(map(int,input().split()));
s=list(map(int,input()));
if k==1:
s_0 ={};
s_1={};
c0=0;
c1=0;
for j in range(n):
if(j%2==0):
s_1[j]=1;
s_0[j]=0;
else:
s_1[j]=0;
s_0[j]=1;
for j in range(n):
if(s_0[j]-s[j]!=0):
c0+=1;
if(s_1[j]-... | |
d1146 | from math import log,pow
n=int(input())
a=[]
for i in range(n):
no=int(input())
if(no%2==0):
a.append("0")
elif(no==1):
a.append("1")
elif(no==3):
a.append("3")
else:
s="2"
lv=int(log(no,2))
clv=1
cno=3
while(cno!=no):
if(no<cno*pow(2,lv-clv)):
s=s+"1"
clv=clv+1
cno=(2*cno)-1
else... | |
d1147 | # cook your dish here
a,b=list(map(int,input().split()))
ls=[]
for i in range(a):
ls.append(int(input()))
ls.sort()
c=0;i=0
while i<(a-1):
if ls[i+1]-ls[i]<=b:
c=c+1
i=i+1
i=i+1
print(c)
| |
d1148 | # cooking dish here
from sys import stdin
from collections import Counter
read = stdin.readline
for testcase in range(int(read())):
length = int(read())
string = read().strip()
counts = Counter(string)
odd_counts = 0
for count in list(counts.values()):
# print(count, counts)... | |
d1149 | def g(x,y):
d = x[0]>=y[0] and x[1]>=y[1] and x[2]>=y[2]
e= x[0]>y[0] or x[1]>y[1] or x[2]>y[2]
return d and e
t=int(input())
for _ in range(t):
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
if g(a,b) and g(b,c):
print('yes')
elif g(a,c) and g(c,b):
prin... | |
d115 | import sys
input = sys.stdin.readline
import bisect
t=int(input())
for testcases in range(t):
n=int(input())
A=list(map(int,input().split()))
m=int(input())
PS=[tuple(map(int,input().split())) for i in range(m)]
PS.sort()
K=[PS[-1]]
for a,b in PS[::-1][1:]:
if b<=K[-1][1]:
... | |
d1150 | # cook your dish here
t=int(input())
for _ in range(t):
l = input()
n= len(l)
prod = 1
for k in range(n//2):
i = l[k]
j = l[n-k-1]
if ((i!=j) and (i!='?' and j!="?") ):
prod=0
break
elif ((i==j) and (i=='?')):
prod*=26
prod = prod%10000009
if n%2!=0:
if l[n//2]=="?":
prod*=26
print(... | |
d1151 | # cook your dish here
import math
for _ in range(int(input())):
n=int(input())
c=0
while(n>0):
i=int(math.sqrt(n))
c+=1
n=n-i**2
print(c)
| |
d1152 | from sys import stdin
from math import ceil, gcd
# Input data
#stdin = open("input", "r")
def dfs(src, visit):
visit[src] = 1
for nbr in d[src]:
if visit[nbr] == 0:
dfs(nbr, visit)
for _ in range(int(stdin.readline())):
n, m = list(map(int, stdin.readline().split()))
... | |
d1153 | nr=int(input())
d={}
for r in range(nr):
s,v=list(map(str,input().split()))
d[int(v)]=s
q=int(input())
lis=[]
for i in range(q):
lis.append(input())
l=list(d.keys())
l.sort(reverse=True)
ans='NO'
for j in lis:
ans='NO'
for k in l:
if len(j)<=len(d[k]):
a=d[k]
if j==a[0:len(j)]:
ans=a
break
print... | |
d1154 | def mod(a,b,c):
x = 1
y = a
while(b>0):
if(b%2==1):
x = (x*y)%c
y = (y*y)%c
b /=2
return x%c
t = int(input())
num = 10**9+7
for i in range(t):
n,m,q,k = list(map(int,input().split()))
if m<=q:
print(0)
else:
a1 = m-q
a2 = mod(q+1,n,num)
a3 = mod(q-1,n,num)
a4 = mod(q,n,num)
a5 = a2-2*a4+a3
... | |
d1155 | try:
n=int(input())
x=[*list(map(int, input().split()))]
y=[*list(map(int, input().split()))]
for i in y:
d=x.count(i)-y.count(i)
if d!=0:
print(i)
break
except: pass
| |
d1156 | print | |
d1157 | # cook your dish here
for i in range(int(input())):
x=int(input())
if x<10:
print("Thanks for helping Chef!")
else:
print("-1")
| |
d1158 | # cook your dish here
# cook your dish here
for i in range(int(input())):
n,m,k=map(int,input().split())
l,ans = list(map(int,input().split())),0
for i in l:
r=i//m + 1;c=i%m
if(c==0):c=m;r-=1
ans+=r*(n+1-r)*c*(m+1-c)
ans/=((n+1)*(m+1)*n*m)//4
print(ans) | |
d1159 | #!/usr/bin/env python
def main():
N = int(input())
C = 0
for n in range(N):
S = input().strip()
Pi = S.split()[-1]
L = [Pi.count(k) for k in map(str, list(range(10)))]
if L[8] >= L[5] and L[5] >= L[3] and \
L[0] == 0 and L[1] == 0 and \
L[2] == 0 and L[4] == 0 and \
L[6] == 0 and L[7] == 0 and \
... | |
d116 | class BIT():
def __init__(self,n):
self.BIT=[0]*(n+1)
self.num=n
def query(self,idx):
res_sum = 0
while idx > 0:
res_sum += self.BIT[idx]
idx -= idx&(-idx)
return res_sum
#Ai += x O(logN)
def update(self,idx,x):
while idx <= self.... | |
d1160 | t = int(input())
for e in range(t):
str = input()
dict = {}
for x in range(len(str)):
if str[x] in dict:
dict[str[x]] = -1
else:
dict[str[x]] = x
shankyIndex = len(str)
ankuIndex = -1
for x in dict:
if dict[x] != -1:
if dict[x] < shankyIndex:
shankyIndex = dict[x]
if dict[x] > ankuIndex... | |
d1161 | def get(l,n):
l1,l2 = [],[]
i = 1
h1,m1 = l[0]
while (i < len(l)):
h2,m2 = l[i]
if (h1>h2):
if (m1 >= m2):
l1 += [(0,10**20)]
l2 += [(-1,-1)]
else:
d = (h1-h2)//(m2-m1)
if (((h1-h2)%(m2-m1)) == 0):
l1 += [(0,d-1)]
l2 += [(d+1,10**20)]
else:
l1 += [(0,d)]
l2 += [(d+1... | |
d1162 | for i in range(int(input())):
a=input()
c=a.count('m')
d=a.count('s')
t=0
while t<len(a)-1:
if (a[t]=='m' and a[t+1]=='s') or (a[t]=='s' and a[t+1]=='m'):
d=d-1
t=t+2
else:
t=t+1
if c>d:
print('mongooses')
elif d>c:
print('snakes')
else:
print('tie')
| |
d1163 | import sys
import os
def __starting_point():
start = 0
for line in sys.stdin:
if start == 0:
start = 1
continue
else:
try:
n = int(line.strip())
# print n
q = n/7
... | |
d1164 | T = int(input())
for j in range(0,T):
line1, line2 = input(), input()
seq = line2.split()
current_min = 1000001
current_max = 0
max_spread = 0
for i in range(0,len(seq)):
current_value = int(seq[i])
if current_min > current_value:
current_min = current_value
current_max = current_value
elif current_ma... | |
d1165 | p,s = [int(i) for i in input().split()]
scores = {}
for j in range(1, p + 1):
sc = [int(i) for i in input().split()]
ns = [int(i) for i in input().split()]
nsc = dict(list(zip(sc,ns)))
ssc = sorted(sc)
score = 0
for a,b in zip(ssc[:-1], ssc[1:]):
if nsc[a] > nsc[b]:
score += 1
if score in list(scores.keys(... | |
d1166 | # cook your dish here
d = {'january':31,'february':29,'march':31,
'april':30,'may':31,'june':30,'july':31,
'august':31,'september':30,'october':31,
'november':30,'december':31}
#l=[[15,'january'],[31,'august'],[10,'october']]
l2 = list(d.keys())
for _ in range(int(input())):
l=input().split()
l[0]=int(l[0])
a =... | |
d1167 | import sys
import math
def main(arr,k):
ans=0
for i in range(len(arr)):
curr_min=float('inf')
for j in range(i,len(arr)):
curr_min=min(curr_min,arr[j])
if curr_min==k:
ans+=1
return ans
n=int(input())
arr=list(map(int,inpu... | |
d1168 | s = input().lower()
vow = ["a", "e", "i", "o", "u", "y"]
ans = ""
for ch in s:
if ch in vow:
continue
if ch.isalpha():
ans += "." + ch
print(ans)
| |
d1169 | import sys
for _ in range(0,eval(input())):
d,inp,mp,n,q=set(),list(map(ord,list(sys.stdin.readline().strip()))),[x=='b' for x in list(sys.stdin.readline().strip())],eval(input()),ord('a')
inps = [inp[i:] for i in range(len(inp))]
inps.sort()
op,prev= 0,''
for ip in inps:
i,ct=0,0
... | |
d117 | for nt in range(int(input())):
n=int(input())
l=list(map(int,input().split()))
s=sum(l)
e=l[0]
for i in range(1,n):
e=e^l[i]
if s==2*e:
print(0)
print ()
else:
print(2)
print(e,s+e)
| |
d1170 | import sys
def joseph(k, n=6):
if k==0:
k = 1
x = 0
for i in range(2,n+1):
x = (x+k)%i
return x
FLAMES = ['FRIENDS', 'LOVE', 'ADORE', 'MARRIAGE', 'ENEMIES', 'SISTER']
nCase = int(sys.stdin.readline())
for _ in range(nCase):
a = ''.join(sys.stdin.readline().split())
b = ''.join(sys.stdin.readline().split())... | |
d1171 | t=int(input())
for i in range(0,t):
n,k=map(int,input().split())
a1,*a=map(int,input().split())
a.insert(0,a1)
j=0
while j<n:
if a[j]%k==0:
print(1,end="")
else:
print(0,end="")
j+=1
print("") | |
d1172 | import numpy as np
from numba import njit
i8 = np.int64
@njit
def solve(a, b, t, K, N):
t1 = t // K
d = t % K * 2
# b が a から a + d の位置にあれば衝突する
x = 0
y = 0
ans = 0
for c in a:
while b[x] < c:
x += 1
while b[y] <= c + d:
y += 1
... | |
d1173 | from math import factorial
def Ncr(n,r):
if r<0:return 0
return factorial(n)/(factorial(n-r)*factorial(r))
def solve(m,n):
modulo=10**9+7
if m==n:
return (Ncr(2*n-1,n-1)+Ncr(2*n-2,n-2))%modulo
elif m>n:
return (Ncr(m+n,n)-Ncr(m+n-2,n-1))%modulo
else:
return (Ncr(m+n,m)-Nc... | |
d1174 | import itertools
from collections import defaultdict as dfd
def sumPairs(arr, n):
s = 0
for i in range(n-1,-1,-1):
s += i*arr[i]-(n-1-i)*arr[i]
return s
def subarrayXor(arr, n, m):
ans = 0
xorArr =[0 for _ in range(n)]
mp = dfd(list)
xorArr[0] = arr[0]
for i in range(1, n):
xorArr[i] = xorArr[i - 1] ^ ar... | |
d1175 | from math import *
t = int(input())
for _ in range(t):
n = int(input())
a = [int(d) for d in input().split()]
odd,even = 0,0
for i in range(n):
if bin(a[i]).count("1")%2 == 1:
odd += 1
else:
even +=1
total = 0
if odd >= 3 and even >= 2:
total += (odd*(odd-1)*(odd-2))//... | |
d1176 | import math
def lcm(a, b):
return (a*b)//gcd(a, b)
def gcd(a, b):
if b == 0:
return a
return gcd(b, a%b)
for _ in range(int(input())):
n = int(input())
na = math.ceil((2*n)/math.acos(-1))
nb = ((n+1)//2)**2
nlcm = lcm(na, nb)
oa = math.ceil(n/2)
ob = (n//2)*(n//... | |
d1177 | for _ in range(int(input())):
s=input()
if len(s)<4:
print("NO")
else:
if s[-4:]=="1000":
print("YES")
else:
print("NO") | |
d1178 | def nCr(n,k):
if(k>n):return 0
k=min(k,n-k)
num,den=1,1
for i in range(k):
num*=(n-i)
den*=(i+1)
return num/den
def Main():
for cases in range(int(input())):
a,b=[int(x) for x in input().split()]
print(nCr(a,b))
Main() |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.