_id
stringlengths 2
5
| partition
stringclasses 2
values | text
stringlengths 5
289k
| language
stringclasses 1
value | meta_information
dict | title
stringclasses 1
value |
---|---|---|---|---|---|
d1 | train | for _ in range(int(input())):
n = int(input())
mass = []
zo = 0
oz = 0
zz = 0
oo = 0
ozs = []
zos = []
ozss = set()
zoss = set()
for j in range(n):
k = input()
mass.append(k)
if k[0] == '0' and k[-1] == '1':
zoss.add(k)
zos.append(j + 1)
zo += 1
elif k[0] == '1' and k[-1] == '0':
ozss.add(k)
ozs.append(j + 1)
oz += 1
elif k[0] == '0' and k[-1] == '0':
zz += 1
else:
oo += 1
if zz and oo and not oz and not zo:
print(-1)
continue
else:
if zo > oz:
print((zo - oz) // 2)
ans = []
need = (zo - oz) // 2
i = 0
while need:
zzz = mass[zos[i] - 1][len(mass[zos[i] - 1]) - 1:: -1]
if zzz not in ozss:
ans.append(zos[i])
need -= 1
i += 1
print(*ans)
else:
print((oz - zo) // 2)
ans = []
need = (oz - zo) // 2
i = 0
while need:
zzz = mass[ozs[i] - 1][len(mass[ozs[i] - 1]) - 1:: -1]
if zzz not in zoss:
ans.append(ozs[i])
need -= 1
i += 1
print(*ans)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1259/D"
} | |
d2 | train | q=int(input())
for e in range(q):
x,y,k=list(map(int,input().split()))
x,y=abs(x),abs(y)
x,y=max(x,y),min(x,y)
if(x%2!=k%2):
k-=1
y-=1
if(x>k):
print(-1)
continue
if((x-y)%2):
k-=1
x-=1
print(k)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1036/B"
} | |
d3 | train | import sys
import random
from fractions import Fraction
from math import *
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def finput():
return float(input())
def tinput():
return input().split()
def linput():
return list(input())
def rinput():
return list(map(int, tinput()))
def fiinput():
return list(map(float, tinput()))
def rlinput():
return list(map(int, input().split()))
def trinput():
return tuple(rinput())
def srlinput():
return sorted(list(map(int, input().split())))
def NOYES(fl):
if fl:
print("NO")
else:
print("YES")
def YESNO(fl):
if fl:
print("YES")
else:
print("NO")
def main():
n = iinput()
#k = iinput()
#m = iinput()
#n = int(sys.stdin.readline().strip())
#n, k = rinput()
#n, m = rinput()
#m, k = rinput()
#n, k, m = rinput()
#n, m, k = rinput()
#k, n, m = rinput()
#k, m, n = rinput()
#m, k, n = rinput()
#m, n, k = rinput()
q = [rlinput(), rlinput(), rlinput()]
#q = linput()
ans = q[0].copy()
for i in range(1, n):
if ans[i] == ans[i - 1]:
ans[i] = q[1][i]
if i == n - 1:
o = 0
while q[o][i] == ans[n - 2] or q[o][i] == ans[0]:
o += 1
ans[i] = q[o][i]
print(*ans)
for i in range(iinput()):
main()
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1408/A"
} | |
d4 | train | def solve():
n, k = map(int,input().split())
lst = list(map(int,input().split()))
lst.sort()
ans = 0
for i in range(n - k - 1, n):
ans += lst[i]
print(ans)
for i in range(int(input())):
solve() | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1430/B"
} | |
d5 | train | for _ in range(int(input())):
input()
nums = [int(x) for x in input().split()]
new_ar = list(zip(nums,[i for i in range(len(nums))]))
new_ar.sort()
maxx = new_ar[0][1]
minn = new_ar[0][1]
s="1"
for j in range(1,len(new_ar)):
if(new_ar[j][1]>maxx):
maxx = new_ar[j][1]
if(new_ar[j][1]<minn):
minn = new_ar[j][1]
if(maxx-minn<j+1):
s+="1"
else:
s+="0"
print(s) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1265/B"
} | |
d6 | train | def possible(a):
ans = set()
s = set()
lmax = 0
for i in range(len(a)):
lmax = max(lmax, a[i])
s.add(a[i])
if lmax == i + 1 and len(s) == i + 1:
ans.add(i + 1)
return ans
t = int(input())
for case_num in range(t):
n = int(input())
a = list(map(int, input().split(' ')))
left = possible(a)
a.reverse()
right = possible(a)
ans = []
for l in left:
if n - l in right:
ans.append(l)
print(len(ans))
for l in ans:
print(l, n - l)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1330/B"
} | |
d7 | train | import sys
input = sys.stdin.readline
for f in range(int(input())):
n,m=list(map(int,input().split()))
neig=[0]*n
for i in range(n):
neig[i]=[0]
for i in range(m):
a,b=list(map(int,input().split()))
a-=1
b-=1
neig[a][0]+=1
neig[a].append(b)
lev=[1]*n
for i in range(n):
for j in range(1,neig[i][0]+1):
x=lev[i]+1
if x==4:
x=1
lev[neig[i][j]]=max(lev[neig[i][j]],x)
sol=0
s=[]
for i in range(n):
if lev[i]==3:
sol+=1
s.append(i+1)
print(sol)
print(*s)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1368/E"
} | |
d8 | train | import sys
def I():
return sys.stdin.readline().rstrip()
class Heap:
def __init__( self ):
self.l = [ -1 ]
self.n = 0
def n( self ):
return self.n
def top( self ):
return self.l[ 1 ]
def ins( self, x ):
self.l.append( x )
n = len( self.l ) - 1
i = n
while i > 1:
j = i // 2
if self.l[ j ] > self.l[ i ]:
self.l[ j ], self.l[ i ] = self.l[ i ], self.l[ j ]
i = j
else:
break
def pop( self ):
r = self.l[ 1 ]
l = self.l.pop()
n = len( self.l ) - 1
if n:
self.l[ 1 ] = l
i = 1
while True:
j = i * 2
k = j + 1
if k < len( self.l ) and self.l[ i ] > max( self.l[ j ], self.l[ k ] ):
if self.l[ j ] == min( self.l[ j ], self.l[ k ] ):
self.l[ i ], self.l[ j ] = self.l[ j ], self.l[ i ]
i = j
else:
self.l[ i ], self.l[ k ] = self.l[ k ], self.l[ i ]
i = k
elif k < len( self.l ) and self.l[ i ] > self.l[ k ]:
self.l[ i ], self.l[ k ] = self.l[ k ], self.l[ i ]
i = k
elif j < len( self.l ) and self.l[ i ] > self.l[ j ]:
self.l[ i ], self.l[ j ] = self.l[ j ], self.l[ i ]
i = j
else:
break
return r
t = int( I() )
for _ in range( t ):
n = int( I() )
voter = [ list( map( int, I().split() ) ) for _ in range( n ) ]
h = Heap()
d = {}
for m, p in voter:
if m not in d:
d[ m ] = []
d[ m ].append( p )
need = {}
c = 0
sk = sorted( d.keys() )
for m in sk:
need[ m ] = max( 0, m - c )
c += len( d[ m ] )
c = 0
ans = 0
for m in sk[::-1]:
for p in d[ m ]:
h.ins( p )
while c < need[ m ]:
c += 1
ans += h.pop()
print( ans )
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1251/E2"
} | |
d9 | train | import sys
input = sys.stdin.readline
def main():
n, k = map(int, input().split())
string = input().strip()
if "W" not in string:
ans = min(n, k) * 2 - 1
print(max(ans, 0))
return
L_s = []
cnt = 0
bef = string[0]
ans = 0
for s in string:
if s == bef:
cnt += 1
else:
if bef == "L":
L_s.append(cnt)
else:
ans += cnt * 2 - 1
cnt = 1
bef = s
if bef == "W":
ans += cnt * 2 - 1
cnt = 0
if string[0] == "L" and L_s:
cnt += L_s[0]
L_s = L_s[1:]
L_s.sort()
for l in L_s:
if k >= l:
ans += l * 2 + 1
k -= l
else:
ans += k * 2
k = 0
ans += 2 * min(k, cnt)
print(ans)
for _ in range(int(input())):
main() | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1427/B"
} | |
d10 | train | for _ in range(int(input())):
s = input()
p = [i for i in s.split("0") if i!=""]
p.sort(reverse=True)
ans = 0
for i in range(0,len(p),2):
ans+=len(p[i])
print(ans)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1398/B"
} | |
d11 | train | 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 + 1]:
ans.append(arr[i])
ans.append(arr[-1])
print(len(ans))
print(*ans) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1364/B"
} | |
d12 | train | n = int(input())
def area(width, height) :
return (width+1) * (height+1)
def calcul(s1, c, s2) :
maxx, maxy, minx, miny = 0, 0, 0, 0
x, y = 0, 0
for k in range(len(s1)) :
if s1[k] == "W" :
y += 1
if s1[k] == "S" :
y -= 1
if s1[k] == "A" :
x -= 1
if s1[k] == "D" :
x += 1
maxx = max(maxx, x)
minx = min(minx, x)
maxy = max(maxy, y)
miny = min(miny, y)
if c == "W" :
y += 1
elif c == "S" :
y -= 1
elif c == "A" :
x -= 1
elif c == "D" :
x += 1
else :
print(c, "ok")
maxx = max(maxx, x)
minx = min(minx, x)
maxy = max(maxy, y)
miny = min(miny, y)
for k in range(len(s2)) :
if s2[k] == "W" :
y += 1
if s2[k] == "S" :
y -= 1
if s2[k] == "A" :
x -= 1
if s2[k] == "D" :
x += 1
maxx = max(maxx, x)
minx = min(minx, x)
maxy = max(maxy, y)
miny = min(miny, y)
diffx = maxx - minx
diffy = maxy - miny
tmp = area(diffx, diffy)
return tmp
def pre_calcul(s, moment, pre_avant, date_debut) :
x, y, maxx, minx, maxy, miny = pre_avant
for k in range(date_debut, moment) :
if s[k] == "W" :
y += 1
if s[k] == "S" :
y -= 1
if s[k] == "A" :
x -= 1
if s[k] == "D" :
x += 1
maxx = max(maxx, x)
minx = min(minx, x)
maxy = max(maxy, y)
miny = min(miny, y)
return (x, y, maxx, minx, maxy, miny)
def calcul2(s, c, moment, precalcul) :
x, y, maxx, minx, maxy, miny = precalcul
if c == "W" :
y += 1
elif c == "S" :
y -= 1
elif c == "A" :
x -= 1
elif c == "D" :
x += 1
else :
print(c, "ok")
maxx = max(maxx, x)
minx = min(minx, x)
maxy = max(maxy, y)
miny = min(miny, y)
for k in range(moment, len(s)) :
if s[k] == "W" :
y += 1
if s[k] == "S" :
y -= 1
if s[k] == "A" :
x -= 1
if s[k] == "D" :
x += 1
maxx = max(maxx, x)
minx = min(minx, x)
maxy = max(maxy, y)
miny = min(miny, y)
diffx = maxx - minx
diffy = maxy - miny
tmp = area(diffx, diffy)
return tmp
for _ in range(n) :
s = input()
maxx, maxy, minx, miny = 0, 0, 0, 0
x, y = 0, 0
momentminx, momentmaxx, momentminy, momentmaxy = -1, -1, -1, -1
for k in range(len(s)) :
if s[k] == "W" :
y += 1
if s[k] == "S" :
y -= 1
if s[k] == "A" :
x -= 1
if s[k] == "D" :
x += 1
if x > maxx :
momentmaxx = k
if y > maxy :
momentmaxy = k
if x < minx :
momentminx = k
if y < miny :
momentminy = k
maxx = max(maxx, x)
minx = min(minx, x)
maxy = max(maxy, y)
miny = min(miny, y)
diffx = maxx - minx
diffy = maxy - miny
tmp = 999999999999999999999999999999999999
l = [momentmaxx, momentmaxy, momentminx, momentminy]
l = list(set(l))
l = [i for i in l if i != -1]
l.sort()
if l != [] :
precalcul = pre_calcul(s, l[0], (0, 0, 0, 0, 0, 0), 0)
avant = l[0]
for moment in l :
precalcul = pre_calcul(s, moment, precalcul, avant)
avant = moment
tmp = min(tmp, calcul2(s, 'W', moment, precalcul))
tmp = min(tmp, calcul2(s, 'S', moment, precalcul))
tmp = min(tmp, calcul2(s, 'A', moment, precalcul))
tmp = min(tmp, calcul2(s, 'D', moment, precalcul))
print(tmp)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1202/C"
} | |
d13 | train | from math import *
mod = 1000000007
for zz in range(int(input())):
n = int(input())
a = [ int(i) for i in input().split()]
b = [int(i) for i in input().split()]
ha = True
hp = False
hm = False
for i in range(n):
if b[i] != a[i]:
if b[i] > a[i]:
if (hp):
pass
else:
ha = False
break
else:
if (hm):
pass
else:
ha = False
break
if a[i] > 0:
hp = True
elif a[i] < 0:
hm = True
if ha:
print('YES')
else:
print('NO')
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1333/B"
} | |
d14 | train | for i in range(int(input())):
n,g,b=map(int,input().split())
nn=(n+1)//2
print(max(nn+(nn-1)//g*b,n)) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1303/B"
} | |
d15 | train | for _ in range(int(input())):
a1, b1 = list(map(int, input().split()))
a2, b2 = list(map(int, input().split()))
if a1 > b1:
a1, b1 = b1, a1
if a2 > b2:
a2, b2 = b2, a2
flag = False
if a1 == a2 and a1 == b1 + b2:
flag = True
if b1 == b2 and b1 == a1 + a2:
flag = True
print('Yes' if flag else 'No')
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1351/B"
} | |
d16 | train | from math import *
zzz = int(input())
for zz in range(zzz):
a, b, x, y = list(map(int, input().split()))
print(max(x*b, (a-x-1)*b, y*a, (b - y - 1)*a))
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1315/A"
} | |
d17 | train | from math import sqrt
class pro(object):
def __init__(self,dif,sc):
self.dif=dif
self.sc=sc
def __lt__(self,other):
return self.dif>other.dif
T=int(input())
mul=[1]
for i in range(100):
mul.append(mul[i]*10/9)
inf=1000000007
for t in range(T):
n=int(input())
effi,tim=list(map(float,input().split()))
prob=[]
for i in range(n):
x,y=list(map(int,input().split()))
prob.append(pro(x,y))
prob.sort()
f=[[inf for i in range(n+1)] for j in range(1001)]
f[0][0]=0
totsc=0
for i in range(n):
totsc+=prob[i].sc
for j in range(totsc,prob[i].sc-1,-1):
for k in range(1,i+2):
f[j][k]=min(f[j][k],f[j-prob[i].sc][k-1]+prob[i].dif*mul[k])
for i in range(totsc,-1,-1):
flag=False
for j in range(n+1):
if sqrt(effi*f[i][j])>=1:
res=2*sqrt(f[i][j]/effi)-1/effi+10*j
else:
res=f[i][j]+10*j
if res<=tim:
print(i)
flag=True
break
if flag==True:
break
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1056/F"
} | |
d18 | train | 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.num:
self.BIT[idx] += x
idx += idx&(-idx)
return
import sys,random
input=sys.stdin.readline
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
pair=[[] for i in range(n+1)]
for i in range(n):
for j in range(i+1,n):
if a[i]==a[j]:
pair[i+1].append(j+1)
bit=BIT(n)
ans=0
for i in range(1,n+1):
minus=bit.query(i)
for r in pair[i]:
ans+=bit.query(r-1)-minus
for r in pair[i]:
bit.update(r,1)
print(ans)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1400/D"
} | |
d19 | train | import math
T = int(input())
for _ in range(T):
n = int(input())
print(1/math.tan(math.pi/2/n))
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1354/C1"
} | |
d20 | train | for _ in range(int(input())):
n, k, d = list(map(int, input().split()))
a = list(map(int, input().split()))
s = {}
for q in range(d):
s[a[q]] = s.get(a[q], 0)+1
ans = len(s)
for q in range(d, n):
if s[a[q-d]] == 1:
del s[a[q-d]]
else:
s[a[q-d]] -= 1
s[a[q]] = s.get(a[q], 0)+1
ans = min(ans, len(s))
print(ans)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1225/B2"
} | |
d21 | train | q = int(input())
for _ in range(q):
n, m = list(map(int, input().split()))
info = [list(map(int, input().split())) for i in range(n)]
info = sorted(info)
now =(m, m)
time = 0
flag = True
for i in range(n):
t, l, h = info[i]
l_now = now[0] - (t - time)
h_now = now[1] + (t - time)
time = t
if h < l_now or h_now < l:
flag = False
else:
l_now = max(l_now, l)
h_now = min(h_now, h)
now = (l_now, h_now)
if flag:
print("YES")
else:
print("NO") | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1304/C"
} | |
d22 | train | t = int(input())
for _ in range(t):
n = list(input().strip())
s = list(map(int, input().strip().split()))
check = set(s)
found = False
for i in range(1, 1025):
newset = set([e^i for e in s])
if check == newset:
print(i)
found = True
break
if not found:
print(-1)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1362/B"
} | |
d23 | train | import sys
input = sys.stdin.readline
for _ in range(int(input())):
a, k = list(map(int, input().split()))
for _ in range(k - 1):
if '0' in str(a):
break
a += int(min(list(str(a)))) * int(max(list(str(a))))
print(a)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1355/A"
} | |
d24 | train | import heapq
for _ in range(int(input())):
n = int(input())
voters = []
for i in range(n):
m,p = list(map(int, input().split()))
voters.append((m, -p))
voters.sort()
for i in range(n):
voters[i] = (voters[i][0], -voters[i][1])
ans = 0
costs = []
heapq.heapify(costs)
bought = 0
for i in range(n-1, -1, -1):
buysNeeded = voters[i][0] - i - bought
heapq.heappush(costs, voters[i][1])
while buysNeeded > 0 and len(costs) > 0:
ans += heapq.heappop(costs)
bought += 1
buysNeeded -= 1
print(ans)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1251/E1"
} | |
d25 | train | for _ in range(int(input())):
d=int(input())
anws=False
if d**2>=4*d:
root=(d**2-4*d)**0.5
a=(d+root)/2
b=(d-root)/2
anws=True
if anws:
print("Y {:.9f} {:.9f}".format(a,b))
else:
print("N") | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1076/C"
} | |
d26 | train | import os
from io import BytesIO
import sys
import threading
sys.setrecursionlimit(10 ** 9)
threading.stack_size(67108864)
def main():
# input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
def ad(i, j):
nonlocal g
if j in g[i]:
g[i].remove(j)
g[j].remove(i)
else:
g[i].add(j)
g[j].add(i)
def dfs(v):
nonlocal used, g, nans
used[v] = True
nans.append(v + 1)
for el in g[v]:
if not used[el]:
dfs(el)
for _ in range(int(input())):
n = int(input())
cnt = [set() for i in range(n)]
g = [set() for i in range(n)]
used = [False] * n
triangles = []
for i in range(n - 2):
a, b, c = map(int, input().split())
a -= 1
b -= 1
c -= 1
cnt[a].add(i)
cnt[b].add(i)
cnt[c].add(i)
triangles.append((a, b, c))
ad(a, b)
ad(b, c)
ad(a, c)
q = []
ones = []
for i in range(n):
if len(cnt[i]) == 1:
ones.append(i)
ans = []
nans = []
for i in range(n - 2):
t = ones.pop()
ind = cnt[t].pop()
ans.append(ind + 1)
cnt[triangles[ind][0]].discard(ind)
cnt[triangles[ind][1]].discard(ind)
cnt[triangles[ind][2]].discard(ind)
if len(cnt[triangles[ind][0]]) == 1:
ones.append(triangles[ind][0])
if len(cnt[triangles[ind][1]]) == 1:
ones.append(triangles[ind][1])
if len(cnt[triangles[ind][2]]) == 1:
ones.append(triangles[ind][2])
dfs(0)
print(*nans)
print(*ans)
tt = threading.Thread(target = main)
tt.start() | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1282/E"
} | |
d27 | train | for _ in range(int(input())):
n, m = list(map(int, input().split()))
if n < m:
n, m = m, n # n > m
if m == 1:
print("YES")
continue
if m == 2 and n == 2:
print("YES")
continue
print("NO")
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1345/A"
} | |
d28 | train | tests = int(input())
for test in range(tests):
n = int(input())
a = [int(i) for i in input().split()]
d = {}
for i in range(n):
s = 0
while a[i] % 2 == 0:
a[i] //= 2
s += 1
if a[i] in list(d.keys()):
d[a[i]] = max(s, d[a[i]])
else:
d[a[i]] = s
s = 0
for i in list(d.keys()):
s += d[i]
print(s)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1259/B"
} | |
d29 | train | import sys
INF = 10**20
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
"""
Facts and Data representation
Constructive? Top bottom up down
"""
def check(s):
t = 'abacaba'
ans = 0
for i in range(len(s)):
if s[i: i + 7] == t:
ans += 1
return ans
def solve():
n, = I()
s = input()
t = 'abacaba'
cnt = check(s)
if cnt > 1:
print('No')
return
elif cnt == 1:
s = list(s)
for i in range(n):
if s[i] == '?':
s[i] = 'z'
print('Yes')
print(''.join(s))
else:
s = list(s)
ok = s[::]
for i in range(n - 6):
ok = s[::]
for j in range(7):
if s[i + j] == t[j]:
continue
elif s[i + j] == '?':
ok[i + j] = t[j]
else:
break
else:
for i in range(n):
if ok[i] == '?':
ok[i] = 'z'
ok = ''.join(ok)
if check(ok) != 1:
continue
print('Yes')
print(ok)
return
print('No')
t, = I()
while t:
t -= 1
solve() | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1379/A"
} | |
d30 | train | input=__import__('sys').stdin.readline
for _ in range(int(input())):
n=int(input())
s=list(map(int,input().split()))
g=[[-1]for _ in range(n+1)]
for i in range(n):
g[s[i]].append(i)
inf=10**10
ans=[-1]*n
lstunused=n
for i in range(1,n+1):
g[i].append(n)
mx=0
for j in range(1,len(g[i])):
mx=max(mx,g[i][j]-g[i][j-1]-1)
for j in range(mx,lstunused):
ans[j]=i
lstunused=min(lstunused,mx)
print(*ans) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1417/C"
} | |
d31 | train | t = int(input())
for i in range(t):
n = int(input())
s = input()
ans = 0
for y in range(1, n):
if s[y] == s[y-1]:
ans += 1
print((ans + ans % 2) // 2)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1437/B"
} | |
d32 | train | DIR = {"N": (0, 1), "S": (0, -1), "W": (-1, 0), "E": (1, 0)}
for t in range(int(input())):
path = input()
tracks = set()
x, y = 0, 0
time = 0
for char in path:
x1 = x + DIR[char][0]
y1 = y + DIR[char][1]
if (x, y, x1, y1) in tracks or (x1, y1, x, y) in tracks:
time += 1
else:
time += 5
tracks.add((x, y, x1, y1))
x, y = x1, y1
print(time)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1351/C"
} | |
d33 | train | from sys import stdin, stdout
from collections import defaultdict
input = stdin.readline
for _ in range(int(input())):
n = int(input())
chanek = 0
flag = 1
while n>0:
if n%4==0 and n!=4:
if flag:
chanek += 1
n-=1
flag = 0
else:
n-=1
flag = 1
elif n%2:
if flag:
chanek += 1
n-=1
flag = 0
else:
n-=1
flag = 1
else:
if flag:
chanek += n//2
n//=2
flag = 0
else:
n//=2
flag = 1
print(chanek) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1425/A"
} | |
d34 | train | t=int(input())
for i in range(t):
n=int(input())
print(2)
print(n-1,n)
for i in range(n-2,0,-1):
print(i,i+2) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1430/C"
} | |
d35 | train | for _ in range(int(input())):
n = int(input())
if(n%2):
print("7"+"1"*((n-3)//2))
else:
print("1"*(n//2)) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1295/A"
} | |
d36 | train | import sys
input=sys.stdin.readline
for _ in range(int(input())):
N=int(input())
e=list(map(int,input().split()))
e.sort()
ans=0
val=0
g=0
for i in range(0,N):
g+=1
val=e[i]
if g>=val:
ans+=1
g=0
val=0
print(ans)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1355/B"
} | |
d37 | train | n=int(input())
a=list(map(int,input().split()))
k=[]
for i in range(n):
for j in range(a[i]):
k.append(i+1)
m=int(input())
b=list(map(int,input().split()))
for i in b:
print(k[i-1]) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/474/B"
} | |
d38 | train | 3
from math import factorial as fact
N = 55
c = [1]
for i in range(N):
c.append(fact(i))
dp = [0] * N
dp[0] = 1
for i in range(1, N):
for j in range(i):
dp[i] += dp[j] * c[i - j - 1]
def get_kth_cycle(n, k):
if n == 1:
return [1]
ans = [-1] * n
ans[0] = n - 1
fin = [i for i in range(n)]
fin[0] = n - 1
init = [i for i in range(n)]
init[n - 1] = 0
used = [False] * n
used[n - 1] = True
for i in range(1, n - 1):
j = 0
cur = fact(n - i - 2)
while True:
while used[j] or (i < n - 1 and j == init[i]):
j += 1
if k > cur:
k -= cur
j += 1
else:
fin[init[i]] = fin[j]
init[fin[j]] = init[i]
ans[i] = j
used[j] = True
break
ans[-1] = init[-1]
return [x + 1 for x in ans]
def f(n, k):
if n == 0:
assert k == 1
return []
cl = 1
while c[cl - 1] * dp[n - cl] < k:
k -= c[cl - 1] * dp[n - cl]
cl += 1
rest = f(n - cl, (k - 1) % dp[n - cl] + 1)
rest = [x + cl for x in rest]
k = (k - 1) // dp[n - cl] + 1
return get_kth_cycle(cl, k) + rest
def solve():
n, k = list(map(int, input().split()))
if k > dp[n]:
print(-1)
return
print(*f(n, k))
def main():
t = int(input())
while t > 0:
t -= 1
solve()
main()
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1279/E"
} | |
d39 | train | q = int(input())
for z in range(q):
n, k1, k2 = map(int, input().split())
arr1 = list(map(int, input().split()))
arr2 = list(map(int, input().split()))
if max(arr1) > max(arr2):
print('YES')
else:
print('NO') | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1270/A"
} | |
d40 | train | t=int(input())
for tt in range(t):
a,b,p=map(int,input().split())
s=input()
n=len(s)
cost = [0]*n
cost[-1] = 0
typ = ''
i=n-2
while i>=0:
if s[i]==typ:
cost[i] = cost[i+1]
else:
typ = s[i]
cost[i] = cost[i+1] + (a if typ=='A' else b)
i-=1
i=0
while cost[i] > p:
i+=1
print(i+1) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1315/B"
} | |
d41 | train | def main():
from sys import stdin, stdout
for _ in range(int(stdin.readline())):
n = int(stdin.readline())
inp1 = [-1] * (n + 1)
inp2 = [-1] * (n + 1)
for i, ai in enumerate(map(int, stdin.readline().split())):
if inp1[ai] < 0:
inp1[ai] = i
inp2[ai] = i
inp1 = tuple((inp1i for inp1i in inp1 if inp1i >= 0))
inp2 = tuple((inp2i for inp2i in inp2 if inp2i >= 0))
n = len(inp1)
ans = 0
cur = 0
for i in range(n):
if i and inp1[i] < inp2[i - 1]:
cur = 1
else:
cur += 1
ans = max(ans, cur)
stdout.write(f'{n - ans}\n')
main()
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1223/D"
} | |
d42 | train | t = int(input())
for tt in range(t):
n,k=list(map(int,input().split()))
s = input()
ans = []
if s[0] == ')':
for i in range(n):
if s[i] == '(':
ans.append([1,i+1])
s = s[i::-1] + s[i+1:]
break
for i in range(1,(k-1)*2):
if i%2==0:
if s[i]!='(':
for j in range(i+1,n):
if s[j] == '(':
ans.append([i+1,j+1])
s = s[:i] + s[j:i-1:-1] + s[j+1:]
break
else:
if s[i]!=')':
for j in range(i+1,n):
if s[j] == ')':
ans.append([i+1,j+1])
s = s[:i] + s[j:i-1:-1] + s[j+1:]
break
for i in range((k-1)*2,(n+(2*(k-1)))//2+1):
if s[i]!='(':
for j in range(i+1,n):
if s[j] == '(':
ans.append([i+1,j+1])
s = s[:i] + s[j:i-1:-1] + s[j+1:]
break
print(len(ans))
for i in ans:
print(*i)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1227/C"
} | |
d43 | train | LOG = 20
def solve(s):
n = len(s)
res = 0
z = 0
for t in range(0, n):
if s[t] == '0':
z += 1
continue
for l in range(1, min(LOG, n - t + 1)):
x = int(s[t:t+l], 2)
# print(l, t, x, l + z)
if l + z >= x:
res += 1
# print(t, l, x, res, z)
z = 0
return res
t = int(input())
while t > 0:
t -= 1
s = input()
print(solve(s)) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1217/C"
} | |
d44 | train | def check(M):
sm = 0
for i in range(n):
if a[i] > M:
sm += b[i]
return sm <= M
gans = []
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
L = 0
R = max(a)
while R - L > 1:
M = (L + R) // 2
if check(M):
R = M
else:
L = M
gans.append(R)
print(*gans, sep='\n')
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1443/C"
} | |
d45 | train | t=int(input())
for you in range(t):
n=int(input())
for i in range(n):
print(4*n-2*i,end=" ")
print()
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1443/A"
} | |
d46 | train | import sys
import random
from fractions import Fraction
from math import *
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def finput():
return float(input())
def tinput():
return input().split()
def linput():
return list(input())
def rinput():
return list(map(int, tinput()))
def fiinput():
return list(map(float, tinput()))
def rlinput():
return list(map(int, input().split()))
def trinput():
return tuple(rinput())
def srlinput():
return sorted(list(map(int, input().split())))
def NOYES(fl):
if fl:
print("NO")
else:
print("YES")
def YESNO(fl):
if fl:
print("YES")
else:
print("NO")
def main():
n = iinput()
#k = iinput()
#m = iinput()
#n = int(sys.stdin.readline().strip())
#n, k = rinput()
#n, m = rinput()
#m, k = rinput()
#n, k, m = rinput()
#n, m, k = rinput()
#k, n, m = rinput()
#k, m, n = rinput()
#m, k, n = rinput()
#m, n, k = rinput()
#q = srlinput()
#q = linput()
s, t, res = 1, 1, 0
while s <= n:
res += 1
n -= s
t = 2 * t + 1
s = (t * (t + 1)) // 2
print(res)
for i in range(iinput()):
main()
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1419/B"
} | |
d47 | train | #
# ------------------------------------------------
# ____ _ Generatered using
# / ___| | |
# | | __ _ __| | ___ _ __ ______ _
# | | / _` |/ _` |/ _ \ '_ \|_ / _` |
# | |__| (_| | (_| | __/ | | |/ / (_| |
# \____\____|\____|\___|_| |_/___\____|
#
# GNU Affero General Public License v3.0
# ------------------------------------------------
# Author : prophet
# Created : 2020-07-12 11:19:01.523119
# UUID : aXsU7xuXyjk3Ky2f
# ------------------------------------------------
#
production = True
import sys, math, collections
def input(input_format = 0, multi = 0):
if multi > 0: return [input(input_format) for i in range(multi)]
else:
next_line = sys.stdin.readline()[:-1]
if input_format >= 10:
use_list = False
input_format = int(str(input_format)[-1])
else: use_list = True
if input_format == 0: formatted_input = [next_line]
elif input_format == 1: formatted_input = list(map(int, next_line.split()))
elif input_format == 2: formatted_input = list(map(float, next_line.split()))
elif input_format == 3: formatted_input = list(next_line)
elif input_format == 4: formatted_input = list(map(int, list(next_line)))
elif input_format == 5: formatted_input = next_line.split()
else: formatted_input = [next_line]
return formatted_input if use_list else formatted_input[0]
def out(output_line, output_format = 0, newline = True):
formatted_output = ""
if output_format == 0: formatted_output = str(output_line)
elif output_format == 1: formatted_output = " ".join(map(str, output_line))
elif output_format == 2: formatted_output = "\n".join(map(str, output_line))
print(formatted_output, end = "\n" if newline else "")
def log(*args):
if not production:
print("$$$", end = "")
print(*args)
enu = enumerate
ter = lambda a, b, c: b if a else c
ceil = lambda a, b: -(-a // b)
def mapl(iterable, format = 0):
if format == 0: return list(map(int, iterable))
elif format == 1: return list(map(str, iterable))
elif format == 2: return list(map(list, iterable))
#
# >>>>>>>>>>>>>>> START OF SOLUTION <<<<<<<<<<<<<<
#
def solve():
s = input(3)
u = [0] * 3
for i in s:
if i == "R":
u[0] += 1
elif i == "P":
u[1] += 1
elif i == "S":
u[2] += 1
log(u)
y = 0
p = 0
for i, j in enu(u):
if j > y:
y = j
p = i
if p == 0:
a = "P"
elif p == 1:
a = "S"
elif p == 2:
a = "R"
out(a * len(s))
return
for i in range(input(11)): solve()
# solve()
#
# >>>>>>>>>>>>>>>> END OF SOLUTION <<<<<<<<<<<<<<<
#
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1380/B"
} | |
d48 | train | import sys
input = sys.stdin.readline
from bisect import bisect_right
bin_s = [1]
while bin_s[-1] <= 10 ** 9:
bin_s.append(bin_s[-1] * 2)
def main():
n, q = map(int, input().split())
alst = list(map(int, input().split()))
dp = [[-1, -1] for _ in range(n)]
dp[0] = [alst[0], 0]
for i, a in enumerate(alst[1:], start = 1):
dp[i][0] = max(dp[i - 1][0], dp[i - 1][1] + a)
dp[i][1] = max(dp[i - 1][1], dp[i - 1][0] - a)
print(max(dp[-1]))
for _ in range(int(input())):
main() | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1420/C1"
} | |
d49 | train | for haaghfj in range(int(input())):
x,y,k = list(map(int,input().split()))
print(k + (y * k + k - 1 +x-2) // (x - 1))
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1418/A"
} | |
d50 | train |
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline
# this math tutorial is boring
classy=set()
for i in range(19):
for j in range(i):
for k in range(j):
for a in range(10): # a=0 for good measure
for b in range(10):
for c in range(10):
what=a*10**i+b*10**j+c*10**k
classy.add(what)
li=sorted(classy)
def counting(i):
# return len([x for x in li if x <= i])+C
lo=0
hi=len(li)-1
while lo<hi:
mid=(lo+hi+1)//2
if li[mid]<=i:
lo=mid
else:
hi=mid-1
return lo
for _ in range(int(input())):
a,b=map(int,input().split())
print(counting(b)-counting(a-1)) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1036/C"
} | |
d51 | train | for tcase in range(int(input())):
n=int(input())
ls = list(map(int, input().split()))
oneneed = 2*(n - ls.count(1))
ldct = {0:0}
ctr = 0
eaten = 0
for i in range(n-1,-1,-1):
eaten += 1
ctr += (1 if ls[i] == 2 else -1)
if ctr not in ldct:
ldct[ctr] = eaten
rdct = {0:0}
ctr = 0
eaten = 0
for i in range(n,2*n):
eaten += 1
ctr += (1 if ls[i] == 2 else -1)
if ctr not in rdct:
rdct[ctr] = eaten
#print(oneneed, ldct, rdct)
best=99**99
for k in list(rdct.keys()):
otk = oneneed - k
if otk in ldct:
best = min(best, rdct[k]+ldct[otk])
print(best)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1278/C"
} | |
d52 | train | def main():
t = int(input())
for z in range(t):
n, k, d1, d2 = map(int, input().split())
if n % 3 != 0:
print('no')
continue
f = 0
for i in [-1, +1]:
for j in [-1, +1]:
w = (k - i * d1 - j * d2)
if f == 0 and (w % 3 == 0) and (n//3)>=(w//3)>=0 and (n//3)>=(w//3 + i * d1)>=0 and (n//3)>=(w//3 + j * d2)>=0:
print('yes')
f = 1
if f == 0:
print('no')
main() | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/451/C"
} | |
d53 | train | n=int(input())
a=sorted(int(input()) for _ in range(n))
print(sum(a[i]*a[-i-1] for i in range(n))%10007) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/717/C"
} | |
d54 | train | import sys
input = sys.stdin.readline
def compress(array):
array2 = sorted(set(array))
memo = {value : index for index, value in enumerate(array2)}
for i in range(len(array)):
array[i] = memo[array[i]] + 1
return array
t = int(input())
base = 10 ** 6
for _ in range(t):
n, b = list(map(str, input().split()))
n = int(n)
ans = [0] * n
now = base
ans[0] = base
for i in range(n - 1):
if b[i] == ">":
now -= base
ans[i + 1] = now
else:
now += 1
ans[i + 1] = now
print(*compress(ans))
now = base
ans[0] = base
for i in range(n - 1):
if b[i] == ">":
now -= 1
ans[i + 1] = now
else:
now += base
ans[i + 1] = now
print(*compress(ans))
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1304/D"
} | |
d55 | train | for i in range(int(input())):
n=int(input())
s=list(map(int,input().split()))
a=0
for i in s:
if i<2049:a+=i
if a<2048:print("NO")
else:print("YES") | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1221/A"
} | |
d56 | train | for __ in range(int(input())):
n = int(input())
print((n + 1) // 2) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1371/A"
} | |
d57 | train | for _ in range(int(input())):
n, k = map(int, input().split())
mat = [[0] * n for _ in range(n)]
for i in range(n):
b = False
for j in range(n):
if i*n+j == k:
b = True
break
mat[(i+j)%n][j] = 1
if b:
break
if k%n == 0:
print(0)
else:
print(2)
for i in range(n):
for j in range(n):
print(mat[i][j], end="")
print()
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1371/D"
} | |
d58 | train | t = int(input())
for case in range(t):
n = int(input())
arr = list(map(int, input().split()))
if arr[-1] > arr[0]:
print("YES")
else:
print("NO") | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1375/C"
} | |
d59 | train | mem = [[[0 for i in range(51)] for j in range(31)] for k in range(31)]
def f(n, m, k):
if mem[n][m][k]:
return mem[n][m][k]
if (n*m == k) or (k == 0):
return 0
cost = 10**9
for x in range(1, n//2 + 1):
for z in range(k+1):
cost = min(cost, m*m + f(n-x, m, k-z) + f(x, m, z))
for y in range(1, m//2 + 1):
for z in range(k+1):
cost = min(cost, n*n + f(n, m-y, k-z) + f(n, y, z))
mem[n][m][k] = cost
return cost
t = int(input())
for i in range(t):
n, m, k = list(map(int, input().split()))
print(f(n, m, k))
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/598/E"
} | |
d60 | train | for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
ans,small,big=0,2*10**9,-1
for i in range(len(a)-1):
if a[i]==-1 and a[i+1]!=-1:
small=min(small, a[i+1])
big=max(big, a[i+1])
if a[i]!=-1 and a[i+1]==-1:
small = min(small, a[i])
big = max(big, a[i])
if a[i]!=-1 and a[i+1]!=-1:
ans=max(ans, abs(a[i]-a[i+1]))
if big==-1:print(ans, 0)
else:
x=(small+big)//2
ans=max(ans, abs(big-x))
ans=max(ans, abs(x-small))
print(ans, x) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1301/B"
} | |
d61 | train | n = int(input())
for _ in range(n):
a, b = list(map(int, input().split()))
print(a ^ b)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1421/A"
} | |
d62 | train | import sys
import math
#from queue import *
import random
#sys.setrecursionlimit(int(1e6))
input = sys.stdin.readline
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
return(int(input()))
def inara():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(list(map(int,input().split())))
################################################################
############ ---- THE ACTUAL CODE STARTS BELOW ---- ############
t=inp()
for _ in range(t):
n=inp()
ara=inara()
ans=[]
for i in range(1,n-1):
if ara[i]>ara[i-1] and ara[i]>ara[i+1]:
ans.append(i)
ans.append(i+1)
ans.append(i+2)
break
if len(ans)==0:
print("NO")
else:
print("YES")
print(*ans)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1380/A"
} | |
d63 | train | T = int(input())
def solve(S):
res = [S[0]]
pos = 0 # think...
for s in S[1:]:
# can we change?
if 0 <= pos-1 < len(res) and res[pos-1] == s:
pos = pos-1
elif 0 <= pos+1 < len(res) and res[pos+1] == s:
pos = pos+1
elif pos == 0 and s not in res:
res.insert(0, s) # pos is still 0
elif pos == len(res)-1 and s not in res:
res.append(s)
pos += 1
else: return None
#print(''.join(res))
for x in range(ord('a'), ord('z')+1):
x = chr(x)
if x not in res:
res.append(x)
return ''.join(res)
for _ in range(T):
res = solve(input())
if res is None:
print('NO')
else:
print('YES')
print(res)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1303/C"
} | |
d64 | train | def solve():
n, k = map(int,input().split())
lst1 = list(map(int,input().split()))
lst1.sort(reverse=True)
ind = 0
ans = 0
lst2 = list(map(int,input().split()))
lst2.sort()
for i in range(k):
lst2[i] -= 1
if lst2[i] == 0: ans += lst1[ind]
ans += lst1[ind]
ind += 1
lst2.sort()
for i in lst2:
if i != 0:
ind += i - 1
ans += lst1[ind]
ind += 1
print(ans)
for i in range(int(input())):
solve() | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1369/C"
} | |
d65 | train | import sys
import random
from fractions import Fraction
from math import *
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def finput():
return float(input())
def tinput():
return input().split()
def linput():
return list(input())
def rinput():
return list(map(int, tinput()))
def fiinput():
return list(map(float, tinput()))
def rlinput():
return list(map(int, input().split()))
def trinput():
return tuple(rinput())
def srlinput():
return sorted(list(map(int, input().split())))
def NOYES(fl):
if fl:
print("NO")
else:
print("YES")
def YESNO(fl):
if fl:
print("YES")
else:
print("NO")
def main():
n, l = rinput()
#n = iinput()
#k = iinput()
#m = iinput()
#n = int(sys.stdin.readline().strip())
#n, k = rinput()
#n, m = rinput()
#m, k = rinput()
#n, k, m = rinput()
#n, m, k = rinput()
#k, n, m = rinput()
#k, m, n = rinput()
#m, k, n = rinput()
#m, n, k = rinput()
q = rlinput()
#q = linput()
q = [0] + q + [l]
w, e = [0] * (n + 2), [0] * (n + 2)
for i in range(1, n + 2):
e[n + 1 - i] = e[n + 2 - i] + ((q[-i] - q[-1 - i]) / i)
w[i] = w[i - 1] + ((q[i] - q[i - 1]) / i)
left, right = 0, n + 2
while right > left + 1:
mid = (right + left) // 2
if w[mid] >= e[mid]:
right = mid
else:
left = mid
print((q[right] - q[right - 1] - (max(0, w[right - 1] - e[right]) * (n - right + 2) + max(0, e[right] - w[right - 1]) * right)) / (n + 2) + max(w[right - 1], e[right]))
for i in range(iinput()):
main()
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1408/C"
} | |
d66 | train | import math
from collections import deque
from sys import stdin, stdout
from string import ascii_letters
import sys
letters = ascii_letters
input = stdin.readline
#print = stdout.write
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
ans = [999999999] * n
ans[0] = 1 if arr[0] == 1 else 0
if n > 1:
ans[1] = ans[0]
if n > 2:
ans[2] = ans[0]
for i in range(n):
if i + 1 >= n:
continue
if arr[i + 1] == 1:
ans[i + 1] = min(ans[i + 1], ans[i] + 1)
if i + 2 < n:
ans[i + 2] = min(ans[i + 2], ans[i] + 1)
if i + 3 < n:
ans[i + 3] = min(ans[i + 3], ans[i] + 1)
else:
ans[i + 1] = min(ans[i + 1], ans[i])
if i + 2 < n:
ans[i + 2] = min(ans[i + 2], ans[i])
if i + 3 < n:
ans[i + 3] = min(ans[i + 3], ans[i])
print(ans[-1])
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1418/C"
} | |
d67 | train | #list(map(int,input().split()))
t=int(input())
for _ in range(t):
n=int(input())
aa=list(map(int,input().split()))
bb=list(map(int,input().split()))
aa.sort()
bb.sort()
print(*aa)
print(*bb)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1305/A"
} | |
d68 | train | for _ in range(int(input())):
n = int(input())
s = input()
t = input()
d = {}
for i in range(ord('a'), ord('z') + 1):
d[chr(i)] = 0
for cs in s:
d[cs] += 1
for ct in t:
d[ct] += 1
ok = True
for e in d:
if d[e] % 2 == 1:
ok = False
if not ok:
print("No")
else:
print("Yes")
changes = []
s, t = list(s), list(t)
for i in range(n-1):
if s[i] != t[i]:
r = (0, -1)
for j in range(i+1, n):
if s[j] == t[i]:
r = (j, 0)
for j in range(i+1, n):
if t[j] == t[i]:
r = (j, 1)
if r[1] == 0:
changes += [(r[0], i+1), (i, i+1)]
s[r[0]], t[i+1] = t[i+1], s[r[0]]
s[i], t[i+1] = t[i+1], s[i]
elif r[1] == 1:
changes += [(i, r[0])]
s[i], t[r[0]] = t[r[0]], s[i]
print(len(changes))
for change in changes:
x, y = change
print(x+1, y+1) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1243/B2"
} | |
d69 | train | from itertools import groupby
def main():
N = int(input())
S = input()
C = [len(list(x[1])) for x in groupby(S)]
M = len(C)
dup_idx = []
for i, c in enumerate(C):
if c > 1:
dup_idx.append(i)
dup_idx.reverse()
curr = 0
while dup_idx:
i = dup_idx[-1]
if i < curr:
dup_idx.pop()
continue
C[i] -= 1
if C[i] == 1:
dup_idx.pop()
curr += 1
ans = curr + (M-curr+1)//2
print(ans)
def __starting_point():
for __ in [0]*int(input()):
main()
__starting_point() | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1430/D"
} | |
d70 | train | t = int(input())
for case in range(t):
a, b = list(map(int, input().split()))
s = input()
z = 10000
total = 0
act = False
for i in range(len(s)):
cur = s[i]
if cur == '0':
z += 1
act = False
else:
if not act:
act = True
total += min(a, b * z)
z = 0
print(total)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1443/B"
} | |
d71 | train | import sys
input = sys.stdin.readline
from collections import defaultdict
class Unionfind:
def __init__(self, n):
self.par = [-1]*n
self.rank = [1]*n
def root(self, x):
r = x
while not self.par[r]<0:
r = self.par[r]
t = x
while t!=r:
tmp = t
t = self.par[t]
self.par[tmp] = r
return r
def unite(self, x, y):
rx = self.root(x)
ry = self.root(y)
if rx==ry:
return
if self.rank[rx]<=self.rank[ry]:
self.par[ry] += self.par[rx]
self.par[rx] = ry
if self.rank[rx]==self.rank[ry]:
self.rank[ry] += 1
else:
self.par[rx] += self.par[ry]
self.par[ry] = rx
def is_same(self, x, y):
return self.root(x)==self.root(y)
def count(self, x):
return -self.par[self.root(x)]
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
s = input()[:-1]
uf = Unionfind(n)
for i in range(n//2):
uf.unite(i, n-1-i)
for i in range(n-k):
uf.unite(i, i+k)
d = defaultdict(dict)
for i in range(n):
if s[i] not in d[uf.root(i)]:
d[uf.root(i)][s[i]] = 1
else:
d[uf.root(i)][s[i]] += 1
rs = set(uf.root(i) for i in range(n))
ans = 0
for r in rs:
ans += uf.count(r)-max(list(d[r].values()))
print(ans) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1332/C"
} | |
d72 | train | t=int(input())
while t>0 :
n=int(input())
a=list(map(int,input().split()))
an=0
s=0
for i in a :
if s+i>=0 :
s+=i
else :
s+=i
an-=s
s=0
print(an)
t-=1 | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1405/B"
} | |
d73 | train | t = int(input())
for _ in range(t):
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
if len(set(a)) > k:
print(-1)
continue
l = list(set(a))
l.extend([1]*(k - len(l)))
print(n*k)
for _ in range(n):
print(*l, end=" ")
print()
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1348/B"
} | |
d74 | train | def solve():
n = int(input())
a = list(map(int, input().split()))
c = [0] * (n + 1)
def inc():
for i in range(n - 1):
if a[i] > a[i + 1]:
return False
return True
def calc():
for i in range(n + 1):
c[i] = 0
for i in a:
c[i] += 1
for i in range(n + 1):
if not c[i]:
return i
return n + 1
ans = []
while not inc():
x = calc()
if x >= n:
y = 0
while y < n and a[y] == y:
y += 1
a[y] = x
ans.append(y)
else:
a[x] = x
ans.append(x)
print(len(ans))
print(*map(lambda x: x + 1, ans))
t = int(input())
for _ in range(t):
solve() | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1375/D"
} | |
d75 | train | def read_int():
return int(input())
def read_ints():
return list(map(int, input().split(' ')))
t = read_int()
for case_num in range(t):
n, k = read_ints()
p = []
for i in range(n):
ai, bi = read_ints()
p.append((bi, ai, i + 1))
p.sort()
dp = [[0 for j in range(k + 1)] for i in range(n + 1)]
use = [[False for j in range(k + 1)] for i in range(n + 1)]
for i in range(1, n + 1):
for j in range(min(i, k) + 1):
if i - 1 >= j:
dp[i][j] = dp[i - 1][j] + (k - 1) * p[i - 1][0]
if j > 0:
x = dp[i - 1][j - 1] + (j - 1) * p[i - 1][0] + p[i - 1][1]
if x > dp[i][j]:
dp[i][j] = x
use[i][j] = True
used = []
curr = k
for i in range(n, 0, -1):
if use[i][curr]:
used.append(p[i - 1][2])
curr -= 1
used.reverse()
seq = used[:-1]
st = set(used)
for i in range(1, n + 1):
if not i in st:
seq.append(i)
seq.append(-i)
seq.append(used[-1])
print(len(seq))
print(' '.join(map(str, seq)))
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1354/F"
} | |
d76 | train | import math
T = int(input())
for _ in range(T):
n = int(input())
diags = 1/math.sin(math.pi/2/n)
print(diags * math.cos(math.pi/4/n))
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1354/C2"
} | |
d77 | train | t = int(input())
for _ in range(t):
n = int(input())
if n%4 == 0:
print("YES")
else:
print("NO") | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1369/A"
} | |
d78 | train | 3
import math
import os
import sys
DEBUG = 'DEBUG' in os.environ
def inp():
return sys.stdin.readline().rstrip()
def dprint(*value, sep=' ', end='\n'):
if DEBUG:
print(*value, sep=sep, end=end)
INF = 10 ** 20
def solve(N, A, B):
dp = {A[0]: 0, A[0] + 1: B[0], A[0] + 2: B[0] * 2}
for i in range(1, N):
ndp = {}
h = A[i]
for ph, c in dp.items():
for inc in range(3):
nh = h + inc
if ph == nh:
continue
if nh not in ndp:
ndp[nh] = INF
ndp[nh] = min(ndp[nh], c + B[i] * inc)
dp = ndp
return min(dp.values())
def main():
Q = int(inp())
for _ in range(Q):
N = int(inp())
A = []
B = []
for _ in range(N):
a, b = [int(e) for e in inp().split()]
A.append(a)
B.append(b)
print(solve(N, A, B))
def __starting_point():
main()
__starting_point() | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1221/D"
} | |
d79 | train | import sys
q = int(sys.stdin.readline().strip())
for t in range(0, q):
n, m = list(map(int, sys.stdin.readline().strip().split()))
L = []
R = [0] * n
C = [0] * m
for i in range (0, n):
L.append(sys.stdin.readline().strip())
for j in range (0, m):
if L[i][j] != "*":
R[i] = R[i] + 1
C[j] = C[j] + 1
ans = n + m - 1
for i in range (0, n):
for j in range (0, m):
x = 0
if L[i][j] != "*":
x = -1
ans = min([ans, R[i]+C[j]+x])
print(ans) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1194/B"
} | |
d80 | train | from math import ceil
t = int(input())
for _ in range(t):
n = int(input())
pf = []
for i in range(2, ceil(n**0.5)+1):
while n % i == 0:
pf.append(i)
n //= i
if n > 1:
pf.append(n)
if len(pf) == 2 and pf[0] != pf[1]:
print(pf[0], pf[1], pf[0]*pf[1])
print(1)
else:
pg = []
fac = []
nfac = []
while len(pf) > 0:
p = pf[-1]
mul = 0
while len(pf) > 0 and pf[-1] == p:
pf.pop()
mul += 1
pg.append([mul, p])
pg.sort()
pg = pg[::-1]
# print(pg)
cur = 0
if pg[0][0] == 1:
a = pg[0][1]
b = pg[1][1]
c = pg[2][1]
fac = [a, a*b*c, a*b, b, b*c, c, a*c]
cur = 3
else:
fac = [pg[0][1]**i for i in range(1, pg[0][0]+1)]
cur = 1
while cur < len(pg):
mul = pg[cur][0]
p = pg[cur][1]
nfac = []
for i in range(len(fac)):
if i == 0:
nfac += [fac[i]*(p**j) for j in range(mul, -1, -1)]
else:
nfac += [fac[i]*(p**j) for j in range(mul+1)]
nfac += [p**i for i in range(1, mul+1)]
fac = nfac
cur += 1
print(" ".join([str(i) for i in fac]))
print(0)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1419/E"
} | |
d81 | train | def solve(L, R):
res = 0
for i in range(32):
for j in range(32):
l = (L >> i) << i
r = (R >> j) << j
#print(l, r)
if l>>i&1==0 or r>>j&1==0:
continue
l -= 1<<i
r -= 1<<j
if l & r:
continue
lr = l ^ r
ma = max(i, j)
mi = min(i, j)
mask = (1<<ma)-1
p = bin(lr&mask).count("1")
ip = ma - mi - p
res += 3**mi * 2**ip
#print(l, r, mi, ip, 3**mi * 2**ip)
return res
T = int(input())
for _ in range(T):
l, r = list(map(int, input().split()))
print(solve(r+1, r+1) + solve(l, l) - solve(l, r+1) * 2)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1245/F"
} | |
d82 | train | for _ in range(int(input())):
a, b, c = input(), input(), input()
n = len(a)
ok = True
for i in range(n):
if c[i] not in [a[i], b[i]]:
ok = False
print('YES' if ok else 'NO')
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1301/A"
} | |
d83 | train | for __ in range(int(input())):
n = int(input())
ar = list(map(int, input().split()))
ar.reverse()
print(*ar) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1405/A"
} | |
d84 | train | def one():
return int(input())
def two():
return list(map(int, input().split()))
def lis():
return list(map(int, input().split()))
def st():
return input()
for _ in range(one()):
x, y, a, b = list(map(int, input().split()))
d = y - x
if d%(a+b)==0:
print(d//(a+b))
else:
print(-1)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1304/A"
} | |
d85 | train | # encoding: utf-8
from sys import stdin
def solve(a):
# root node of tries denotes empty stack
stack = [None]
node_stack = [[1, {}]]
trie = node_stack[-1]
counter = 0
for i in range(len(a)):
el = a[i]
if len(stack) == 0 or stack[-1] != el:
current_node = node_stack[-1]
stack.append(el)
if el not in current_node[1]:
current_node[1][el] = [0, {}]
next_node = current_node[1][el]
next_node[0] += 1
node_stack.append(next_node)
else:
# just go up in trie
stack.pop()
node_stack.pop()
node_stack[-1][0] += 1
value = node_stack[-1][0]
counter -= (((value - 1) * (value - 2)) // 2)
counter += (((value) * (value - 1)) // 2)
return counter
q = int(stdin.readline().strip())
for _ in range(q):
n = int(stdin.readline().strip())
a = [int(i) for i in stdin.readline().strip().split()]
print(solve(a))
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1241/F"
} | |
d86 | train | import sys
input=sys.stdin.readline
for _ in range(int(input())):
s=input().rstrip()
x=int(input())
n=len(s)
ans=["1" for i in range(n)]
for i in range(n):
if s[i]=="0":
if i-x>=0:
ans[i-x]="0"
if i+x<n:
ans[i+x]="0"
for i in range(n):
if s[i]=="1":
check=False
if i-x>=0:
check|=(ans[i-x]=="1")
if i+x<n:
check|=(ans[i+x]=="1")
if not check:
print(-1)
break
else:
print("".join(ans))
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1400/C"
} | |
d87 | train | def solve():
n = int(input())
lst = list(map(int,input().split()))
if sum(lst) <= n // 2:
print(n//2)
print("0 " * (n // 2))
else:
print(n//2 + (n // 2) % 2)
print("1 " * (n//2 + (n // 2) % 2))
for i in range(int(input())):
solve() | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1407/A"
} | |
d88 | train | import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')
def gcd(a, b):
while b:
a, b = b, a%b
return a
def solve():
m, d, w = nm()
g = w // gcd(d-1, w)
c = min(m, d)
v = c // g
ans = v * (v - 1) // 2 * g
ans += (c - g * v) * v
print(ans)
return
# solve()
T = ni()
for _ in range(T):
solve()
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1389/E"
} | |
d89 | train | n = input()
a = list(map(int, input().split()))
for i in a:
if i % 7 == 0 or (i // 7) % 2 == 1 or i <= 14:
print('NO')
else:
print('YES') | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1266/B"
} | |
d90 | train | from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
n = int(stdin.readline())
a = list(map(int,stdin.readline().split()))
lis = [ [1] ]
now = []
tmp = 0
for i in range(1,n):
if len(now) == 0:
now.append(a[i])
tmp = 1
elif now[-1] > a[i]:
if tmp == len(lis[-1]):
lis.append(now)
now = [a[i]]
tmp = 1
else:
tmp += 1
now.append(a[i])
else:
now.append(a[i])
if len(now) > 0:
lis.append(now)
#print (lis)
print (len(lis)-1) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1437/D"
} | |
d91 | train | import math
from collections import deque
from sys import stdin, stdout
from string import ascii_letters
import sys
letters = ascii_letters
input = stdin.readline
#print = stdout.write
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
can = list(map(int, input().split()))
vals = sorted([i for i in range(n) if not can[i]], key=lambda x: -arr[x])
res = [0] * n
last = 0
for i in range(n):
if can[i]:
res[i] = arr[i]
else:
res[i] = arr[vals[last]]
last += 1
print(*res)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1418/B"
} | |
d92 | train | t = int(input())
for faw in range(t):
n = int(input())
a = [0] + list(map(int,input().split()))
nun = []
ans = []
f = True
for i in range(1, n + 1):
if a[i] == a[i-1]:
if len(nun) == 0:
f = False
break
else:
ans.append(nun.pop())
else:
ans.append(a[i])
for i in range(a[i - 1] + 1, a[i]):
nun.append(i)
if f:
print(*ans)
else:
print(-1)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1227/B"
} | |
d93 | train | for _ in range(int(input())):
print("YES" if set(input()).intersection(input()) else "NO")
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1223/B"
} | |
d94 | train | for tc in range(int(input())):
n,m = list(map(int, input().split()))
al = list(map(int, input().split()))
bl = list(map(int, input().split()))
aidx = {}
for i,e in enumerate(al):
aidx[e]=i
midx = -1
res = 0
for i,e in enumerate(bl):
idx = aidx[e]
if idx <= midx:
res += 1
else:
res += 2*(idx-i)+1
midx = max(midx, idx)
print(res)
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1279/C"
} | |
d95 | train | T = int(input())
for test in range(T):
n,t = list(map(int,input().split()))
a = list(map(int,input().split()))
res = []
j=0
for i in a:
if(i*2<t):
res+=["0"]
elif(i*2>t):
res+=["1"]
else:
res.append(["0","1"][j])
j = 1-j
print(" ".join(res))
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1417/B"
} | |
d96 | train | #JMD
#Nagendra Jha-4096
import sys
import math
#import fractions
#import numpy
###File Operations###
fileoperation=0
if(fileoperation):
orig_stdout = sys.stdout
orig_stdin = sys.stdin
inputfile = open('W:/Competitive Programming/input.txt', 'r')
outputfile = open('W:/Competitive Programming/output.txt', 'w')
sys.stdin = inputfile
sys.stdout = outputfile
###Defines...###
mod=1000000007
###FUF's...###
def nospace(l):
ans=''.join(str(i) for i in l)
return ans
##### Main ####
t=int(input())
for tt in range(t):
n=int(input())
if n==1:
print(-1)
else:
s="2"
for i in range(n-1):
s+='3'
print(s)
#n,k,s= map(int, sys.stdin.readline().split(' '))
#a=list(map(int,sys.stdin.readline().split(' ')))
#####File Operations#####
if(fileoperation):
sys.stdout = orig_stdout
sys.stdin = orig_stdin
inputfile.close()
outputfile.close() | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1326/A"
} | |
d97 | train | import sys
from operator import itemgetter
def count(a, b, num_a, num_b, cur_time):
current_result = 0
#print('count time = ', cur_time, "num_a =", num_a, 'num_b = ', num_b)
if num_a * a + num_b * b <= cur_time and cur_time >= 0:
cur_time -= num_a * a + num_b * b
current_result = num_a + num_b
if num_a < total_a:
if (total_a - num_a) * a <= cur_time:
current_result += total_a - num_a
cur_time -= (total_a - num_a) * a
#print(1)
else:
current_result += cur_time // a
cur_time -= a *(cur_time // a)
#print(2)
if num_b < total_b:
if (total_b - num_b) * b <= cur_time:
current_result += total_b - num_b
#print(3)
else:
#print(4)
current_result += cur_time // b
#print('current_result = ', current_result)
return current_result
def solve(n, T, a, b, tasks, total_a, total_b):
tasks = sorted(tasks)
#print(tasks)
result = 0
num_a = 0
num_b = 0
for i in range(len(tasks)):
time, t = tasks[i]
#print(tasks[i])
cur_time = time - 1
#print('cur time = ', cur_time)
current_result = count(a, b, num_a, num_b, cur_time)
result = max(current_result, result)
if t == 0:
num_a += 1
else:
num_b += 1
if i == len(tasks) - 1 or tasks[i + 1][1] != tasks[i][1]:
result = max(result, count(a, b, num_a, num_b, cur_time))
#print("i =", i, "result = ", result)
result = max(result, count(a, b, total_a, total_b, T))
return result
q = int(input())
for i in range(q):
n, T, a, b = list(map(int, input().split()))
types = list(map(int, input().split()))
total_a, total_b = 0, 0
for t in types:
if t == 0:
total_a += 1
else:
total_b += 1
t = list(map(int, input().split()))
#print(t)
#print(types)
tasks = list(zip(t, types))
print(solve(n, T, a, b, tasks, total_a, total_b))
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1282/C"
} | |
d98 | train | import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
def solve():
s,c = input().split()
# i,jでjが複数あるとき
n = len(s)
for i in range(n-1):
prev = s[i]
pos = i
for j in range(i+1, n):
if s[j]<prev:
prev = s[j]
pos = j
elif s[j] == prev:
pos = j
if prev == s[i]:
continue
t = list(s)
t[i], t[pos] = prev, s[i]
s = "".join(t)
break
if s<c:
print(s)
else:
print("---")
t = int(input())
for i in range(t):
solve()
| PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1281/B"
} | |
d99 | train | q = int(input())
for _ in range(q):
c, m, x = list(map(int, input().split()))
print(min([c, m, (c + m + x) // 3])) | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1221/C"
} | |
d100 | train | for _ in range(int(input())):
# a, b = map(int, input().split())
n = int(input())
# arr = list(map(int, input().split()))
s = input()
l = 0
r = n - 1
if s.count('0') == n:
print(s)
continue
if s.count('1') == n:
print(s)
continue
while s[l] == '0':
l += 1
while s[r] == '1':
r -= 1
if r <= l:
print(s)
continue
print(l * '0' + '0' + (n - r - 1) * '1') | PYTHON | {
"starter_code": "",
"url": "https://codeforces.com/problemset/problem/1369/B"
} |