id stringlengths 6 117 | description stringlengths 29 13k | code stringlengths 9 465k | language class label 4
classes | test_samples dict | source class label 5
classes |
|---|---|---|---|---|---|
p02317 Longest Increasing Subsequence_3000 | For a given sequence A = {a0, a1, ... , an-1}, find the length of the longest increasing subsequnece (LIS) in A.
An increasing subsequence of A is defined by a subsequence {ai0, ai1, ... , aik} where 0 ≤ i0 < i1 < ... < ik < n and ai0 < ai1 < ... < aik.
Constraints
* 1 ≤ n ≤ 100000
* 0 ≤ ai ≤ 109
Input
n
a0
a1
:
... | N = int(input())
A = [int(input()) for _ in range(N)]
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
def solve(N,A):
lis = []
for i in range(N):
ind = bisect_left(lis,A[i])
if ind == len(lis):
lis.append(A[i])
else:
lis[ind... | 3Python3 | {
"input": [
"5\n5\n1\n3\n2\n4",
"3\n1\n1\n1",
"5\n5\n1\n3\n2\n6",
"3\n1\n1\n2",
"3\n1\n1\n0",
"5\n0\n2\n1\n2\n11",
"5\n5\n1\n3\n1\n6",
"3\n0\n1\n2",
"5\n5\n1\n2\n1\n6",
"3\n0\n2\n2",
"5\n5\n1\n2\n0\n6",
"5\n5\n1\n2\n-1\n6",
"5\n5\n1\n2\n-1\n10",
"5\n5\n1\n0\n-1... | 6AIZU |
p02317 Longest Increasing Subsequence_3001 | For a given sequence A = {a0, a1, ... , an-1}, find the length of the longest increasing subsequnece (LIS) in A.
An increasing subsequence of A is defined by a subsequence {ai0, ai1, ... , aik} where 0 ≤ i0 < i1 < ... < ik < n and ai0 < ai1 < ... < aik.
Constraints
* 1 ≤ n ≤ 100000
* 0 ≤ ai ≤ 109
Input
n
a0
a1
:
... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.Comparator;
import java.util.Collections;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
*... | 4JAVA | {
"input": [
"5\n5\n1\n3\n2\n4",
"3\n1\n1\n1",
"5\n5\n1\n3\n2\n6",
"3\n1\n1\n2",
"3\n1\n1\n0",
"5\n0\n2\n1\n2\n11",
"5\n5\n1\n3\n1\n6",
"3\n0\n1\n2",
"5\n5\n1\n2\n1\n6",
"3\n0\n2\n2",
"5\n5\n1\n2\n0\n6",
"5\n5\n1\n2\n-1\n6",
"5\n5\n1\n2\n-1\n10",
"5\n5\n1\n0\n-1... | 6AIZU |
p02462 Multi-Map_3002 | For a dictionary $M$ that stores elements formed by a pair of a string key and an integer value, perform a sequence of the following operations. Note that multiple elements can have equivalent keys.
* insert($key$, $x$): Insert an element formed by a pair of $key$ and $x$ to $M$.
* get($key$): Print all values with th... | #define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <b... | 2C++ | {
"input": [
"10\n0 blue 6\n0 red 1\n0 blue 4\n0 white 5\n1 red\n1 blue\n2 red\n1 black\n1 red\n3 w z",
"10\n0 blue 6\n0 red 1\n0 blue 4\n0 white 5\n1 red\n2 blue\n2 red\n1 black\n1 red\n3 w z",
"10\n0 blue 6\n0 red 1\n0 blue 4\n0 white 10\n1 red\n1 blue\n2 red\n1 black\n1 red\n3 w z",
"10\n0 blue 6\n... | 6AIZU |
p02462 Multi-Map_3003 | For a dictionary $M$ that stores elements formed by a pair of a string key and an integer value, perform a sequence of the following operations. Note that multiple elements can have equivalent keys.
* insert($key$, $x$): Insert an element formed by a pair of $key$ and $x$ to $M$.
* get($key$): Print all values with th... | # -*- coding: utf-8 -*-
"""
Dictionary - Multi-Map
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_8_D&lang=jp
"""
from bisect import insort, bisect_right, bisect_left
class Multi_map:
def __init__(self):
self.mm = dict()
self.lr = []
def insert(self, x, y):
if x in self... | 3Python3 | {
"input": [
"10\n0 blue 6\n0 red 1\n0 blue 4\n0 white 5\n1 red\n1 blue\n2 red\n1 black\n1 red\n3 w z",
"10\n0 blue 6\n0 red 1\n0 blue 4\n0 white 5\n1 red\n2 blue\n2 red\n1 black\n1 red\n3 w z",
"10\n0 blue 6\n0 red 1\n0 blue 4\n0 white 10\n1 red\n1 blue\n2 red\n1 black\n1 red\n3 w z",
"10\n0 blue 6\n... | 6AIZU |
p02462 Multi-Map_3004 | For a dictionary $M$ that stores elements formed by a pair of a string key and an integer value, perform a sequence of the following operations. Note that multiple elements can have equivalent keys.
* insert($key$, $x$): Insert an element formed by a pair of $key$ and $x$ to $M$.
* get($key$): Print all values with th... | import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Scanner;
import java.util.TreeMap;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
TreeMap<String, List<Integer>> map = new TreeMap<>();
int q = s... | 4JAVA | {
"input": [
"10\n0 blue 6\n0 red 1\n0 blue 4\n0 white 5\n1 red\n1 blue\n2 red\n1 black\n1 red\n3 w z",
"10\n0 blue 6\n0 red 1\n0 blue 4\n0 white 5\n1 red\n2 blue\n2 red\n1 black\n1 red\n3 w z",
"10\n0 blue 6\n0 red 1\n0 blue 4\n0 white 10\n1 red\n1 blue\n2 red\n1 black\n1 red\n3 w z",
"10\n0 blue 6\n... | 6AIZU |
acmicl3_3005 | Problem description.
In Bytelandian University, everyone has to enter his/her name on a computer when entering or leaving the library. The names are stored in a file on that computer. Assume that everyone adheres to this rule. Given the file, find out how many people are there in the library.
There will not be spaces i... | for _ in xrange(int(input())):
n=int(input())
dic={}
for i in xrange(n):
s=raw_input()
if s not in dic:
dic[s]=1
else:
dic[s]+=1
count=0
for i in dic:
if(dic[i]%2!=0):
count+=1
print count | 1Python2 | {
"input": [
"1\n8\nShubham\nHasil\nShubham\nRavi\nShikhar\nHasil\nJaiwant\nHasil",
"1\n8\nShubham\nHasil\nShubham\nRavi\nShikhar\nHasil\nJaiwant\nH`sil",
"1\n8\nShubham\nHasil\nShubham\nRavi\nShikhar\nlisaH\nJaiwant\nH`sil",
"1\n8\nbhuSham\nHasil\nShubham\nRavi\nShikhar\nlisaH\ntnawhaJ\n`Hsil",
"... | 1CODECHEF |
chefseg_3006 | Chef loves to play games. Now he plays very interesting game called "Segment". At the beginning Chef has segment [0, X] and no points on it. On each step Chef chooses the subsegment of maximal length possible such as it contains no points on it. If there are more than one such subsegment Chef chooses the one with the m... | import math;
t=int(input());
while t>0:
t=t-1;
inp=raw_input();
x=int(inp.split()[0]);
k=int(inp.split()[1]);
roun=int(math.log(k,2))+1;
deno=pow(2,roun-1);
points=0;
if roun==1:
points=0;
else:
points=pow(2,roun-1)-1;
pos=k-points;
print format(((x*1.0)/(deno*1.0))*(pos-1)+(1.0*x)/(2.0*deno),'0.30f'); | 1Python2 | {
"input": [
"4\n10 1\n10 2\n10 3\n1000000000 1234567",
"4\n10 2\n10 2\n10 3\n1000000000 1234567",
"4\n10 2\n10 3\n10 3\n1000000000 1234567",
"4\n14 2\n10 3\n10 3\n1000000000 1234567",
"4\n14 2\n10 3\n13 3\n1000000000 1234567",
"4\n10 2\n10 3\n13 3\n1000000000 1234567",
"4\n3 2\n10 3\n13 3... | 1CODECHEF |
doors_3007 | There are N doors of a palace, all of which are operated by a set of buttons. One day, Alice, who is just 8 years old, gets access to these buttons. Having recently learnt the multiplication tables, she decides to press buttons in a particular order. First, she presses all the buttons that are multiples of 1. Next, she... | t=int(raw_input())
for i in xrange(t):
n=int(raw_input())
print int(n**0.5) | 1Python2 | {
"input": [
"4\n4\n10\n16\n27",
"4\n4\n6\n16\n27",
"4\n4\n6\n12\n27",
"4\n4\n6\n12\n44",
"4\n4\n6\n12\n2",
"4\n4\n6\n30\n1",
"4\n4\n6\n19\n1",
"4\n3\n6\n10\n1",
"4\n3\n1\n10\n1",
"4\n3\n0\n10\n1",
"4\n2\n0\n10\n0",
"4\n2\n1\n10\n0",
"4\n4\n2\n10\n2",
"4\n4\n2\n... | 1CODECHEF |
j7_3008 | Johnny needs to make a rectangular box for his physics class project. He has bought P cm of wire and S cm^2 of special paper. He would like to use all the wire (for the 12 edges) and paper (for the 6 sides) to make the box.
What is the largest volume of the box that Johnny can make?
Input
The first line contains t, th... | #!/usr/bin/python
import math
def main():
num_times = int(raw_input())
for i in xrange(0, num_times):
P, S = map(int, raw_input().split())
l1 = ((P/2) + math.sqrt(math.pow(P/2, 2) - 6*S))/6
l2 = ((P/2) - math.sqrt(math.pow(P/2, 2) - 6*S))/6
h1 = P/4 - 2*l1
h2 = P/4 - 2*... | 1Python2 | {
"input": [
"2\n20 14\n20 16",
"2\n20 14\n20 14",
"2\n32 14\n20 14",
"2\n20 14\n36 14",
"2\n20 8\n36 14",
"2\n28 8\n36 14",
"2\n20 16\n20 14",
"2\n32 20\n20 14",
"2\n20 14\n20 10",
"2\n20 16\n20 10",
"2\n20 4\n20 10",
"2\n32 14\n20 4",
"2\n20 8\n20 10",
"2\n16 ... | 1CODECHEF |
notatri_3009 | You have N (3 ≤ N ≤ 2,000) wooden sticks, which are labeled from 1 to N. The i-th stick has a length of Li (1 ≤ Li ≤ 1,000,000). Your friend has challenged you to a simple game: you will pick three sticks at random, and if your friend can form a triangle with them (degenerate triangles included), he wins; otherwise, yo... | def sum_pair_less_than(v, S):
i,j,pair_count = 0,len(v)-1,0
while i < j:
if v[i]+v[j] < S :
pair_count += j-i
i+=1
else:
j-=1
return pair_count
def not_a_triangle_count(v):
non_tri_count = 0
v.sort()
i=len(v)-1
while i >= 2 :
non_tri_count += sum_pair_less_than(v[0:i],v[i])
i-=1
return non_tri... | 1Python2 | {
"input": [
"3\n4 2 10\n3\n1 2 3\n4\n5 2 9 6\n0"
],
"output": [
"1\n0\n2"
]
} | 1CODECHEF |
seq_3010 | The number of submissions of CodeChef from Students of Graphic Era University had been growing since the day the CodeChef campus chapter, GEU_Coders had been formed here. This rise in user submissions alerted the staff members at CodeChef. They started to track user activities of students from Graphic Era University. T... | for i in xrange(input()):
N=input()
c=1
S=2
while c<N:
if c%2!=0:
S=(S*2)-1
else:
S=(S*2)+1
c+=1
print S | 1Python2 | {
"input": [
"2\n4\n7"
],
"output": [
"13\n107"
]
} | 1CODECHEF |
1003_E. Tree Constructing_3011 | You are given three integers n, d and k.
Your task is to construct an undirected tree on n vertices with diameter d and degree of each vertex at most k, or say that it is impossible.
An undirected tree is a connected undirected graph with n - 1 edges.
Diameter of a tree is the maximum length of a simple path (a path... | def main():
n, d, k = list(map(int, raw_input().split()))
if n == 2 and d == 1 and k == 1:
print("YES")
print "1 2"
return 0
if n == d + 1 and k - 1:
print("YES")
for i in range(1, d + 1):
print i, i + 1
return 0
if n < d +1 or k <= 2 or d == ... | 1Python2 | {
"input": [
"8 5 3\n",
"6 3 3\n",
"10 4 3\n",
"6 2 3\n",
"400000 3 199999\n",
"20 6 3\n",
"5 5 3\n",
"2 3 1\n",
"10 9 1\n",
"7 5 2\n",
"2 1 4\n",
"3 2 1\n",
"1 1 1\n",
"2 2 1\n",
"2 3 3\n",
"6 4 2\n",
"7 4 3\n",
"2 10 1\n",
"6 5 3\n",
"1... | 2CODEFORCES |
1003_E. Tree Constructing_3012 | You are given three integers n, d and k.
Your task is to construct an undirected tree on n vertices with diameter d and degree of each vertex at most k, or say that it is impossible.
An undirected tree is a connected undirected graph with n - 1 edges.
Diameter of a tree is the maximum length of a simple path (a path... | #include <bits/stdc++.h>
int n, d, k, x, z;
std::vector<int> V1, V2;
void add(int u, int v) {
V1.push_back(u);
V2.push_back(v);
}
void dfs(int u, int dd, int p) {
if (p)
while (dd--) {
if (x >= n) return;
add(u, ++x);
dfs(x, k - 1, p - 1);
}
}
int main() {
std::cin >> n >> d >> k;
z ... | 2C++ | {
"input": [
"8 5 3\n",
"6 3 3\n",
"10 4 3\n",
"6 2 3\n",
"400000 3 199999\n",
"20 6 3\n",
"5 5 3\n",
"2 3 1\n",
"10 9 1\n",
"7 5 2\n",
"2 1 4\n",
"3 2 1\n",
"1 1 1\n",
"2 2 1\n",
"2 3 3\n",
"6 4 2\n",
"7 4 3\n",
"2 10 1\n",
"6 5 3\n",
"1... | 2CODEFORCES |
1003_E. Tree Constructing_3013 | You are given three integers n, d and k.
Your task is to construct an undirected tree on n vertices with diameter d and degree of each vertex at most k, or say that it is impossible.
An undirected tree is a connected undirected graph with n - 1 edges.
Diameter of a tree is the maximum length of a simple path (a path... | def main():
n, d, k = map(int, input().split())
r, odd = divmod(d, 2)
k -= 1
cap = d + 1 if k == 1 else 1
if k > 1:
cap = 2 * (k ** (r + 1) - 1) // (k - 1) if odd else 1 + (k + 1) * (k ** r - 1) // (k - 1)
if n == 1 or k < 1 < n - 1 or k == 1 and d != n - 1 or d >= n or k > 1 and not d <... | 3Python3 | {
"input": [
"8 5 3\n",
"6 3 3\n",
"10 4 3\n",
"6 2 3\n",
"400000 3 199999\n",
"20 6 3\n",
"5 5 3\n",
"2 3 1\n",
"10 9 1\n",
"7 5 2\n",
"2 1 4\n",
"3 2 1\n",
"1 1 1\n",
"2 2 1\n",
"2 3 3\n",
"6 4 2\n",
"7 4 3\n",
"2 10 1\n",
"6 5 3\n",
"1... | 2CODEFORCES |
1003_E. Tree Constructing_3014 | You are given three integers n, d and k.
Your task is to construct an undirected tree on n vertices with diameter d and degree of each vertex at most k, or say that it is impossible.
An undirected tree is a connected undirected graph with n - 1 edges.
Diameter of a tree is the maximum length of a simple path (a path... | import java.util.*;
import java.io.*;
import java.text.*;
public class Main {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 32768);
static PrintWriter out = new PrintWriter(System.out);
static StringTokenizer t;
static String sn() {
while (t == null || !t.hasM... | 4JAVA | {
"input": [
"8 5 3\n",
"6 3 3\n",
"10 4 3\n",
"6 2 3\n",
"400000 3 199999\n",
"20 6 3\n",
"5 5 3\n",
"2 3 1\n",
"10 9 1\n",
"7 5 2\n",
"2 1 4\n",
"3 2 1\n",
"1 1 1\n",
"2 2 1\n",
"2 3 3\n",
"6 4 2\n",
"7 4 3\n",
"2 10 1\n",
"6 5 3\n",
"1... | 2CODEFORCES |
1027_F. Session in BSU_3015 | Polycarp studies in Berland State University. Soon he will have to take his exam. He has to pass exactly n exams.
For the each exam i there are known two days: a_i — day of the first opportunity to pass the exam, b_i — day of the second opportunity to pass the exam (a_i < b_i). Polycarp can pass at most one exam durin... | #include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const long long int MAX = 1e9 + 7;
void array_show(int *array, int array_n, char middle = ' ') {
for (int i = 0; i < array_n; i++)
printf("%d%c", array[i], (i != array_n - 1 ? middle : '\n'));
}
void array_show(long long int *array, int array_... | 2C++ | {
"input": [
"3\n5 13\n1 5\n1 7\n",
"3\n99 100\n99 100\n99 100\n",
"3\n10 40\n40 80\n10 80\n",
"2\n1 5\n1 7\n",
"10\n12 61\n22 50\n38 70\n22 38\n38 70\n28 38\n33 38\n33 70\n38 57\n22 54\n",
"10\n7 17\n3 19\n6 7\n12 15\n7 17\n7 17\n10 17\n3 11\n6 11\n11 19\n",
"10\n50 59\n9 49\n32 50\n9 59\... | 2CODEFORCES |
1027_F. Session in BSU_3016 | Polycarp studies in Berland State University. Soon he will have to take his exam. He has to pass exactly n exams.
For the each exam i there are known two days: a_i — day of the first opportunity to pass the exam, b_i — day of the second opportunity to pass the exam (a_i < b_i). Polycarp can pass at most one exam durin... | //created by Whiplash99
import java.io.*;
import java.util.Arrays;
import java.util.HashMap;
public class F
{
static class DSU
{
int parent[], vertices[], edges[], max[], nextMax[];
DSU(int N)
{
nextMax=new int[N];
parent=new int[N]; max=new int[N];
v... | 4JAVA | {
"input": [
"3\n5 13\n1 5\n1 7\n",
"3\n99 100\n99 100\n99 100\n",
"3\n10 40\n40 80\n10 80\n",
"2\n1 5\n1 7\n",
"10\n12 61\n22 50\n38 70\n22 38\n38 70\n28 38\n33 38\n33 70\n38 57\n22 54\n",
"10\n7 17\n3 19\n6 7\n12 15\n7 17\n7 17\n10 17\n3 11\n6 11\n11 19\n",
"10\n50 59\n9 49\n32 50\n9 59\... | 2CODEFORCES |
1046_E. Ancient civilizations_3017 | On the surface of a newly discovered planet, which we model by a plane, explorers found remains of two different civilizations in various locations. They would like to learn more about those civilizations and to explore the area they need to build roads between some of locations. But as always, there are some restricti... | #include <bits/stdc++.h>
using namespace std;
struct point {
int x, y, op, id;
} p[1100];
int multi(point p1, point p2, point p0) {
int x1, y1, x2, y2;
x1 = p1.x - p0.x;
y1 = p1.y - p0.y;
x2 = p2.x - p0.x;
y2 = p2.y - p0.y;
return x1 * y2 - x2 * y1;
}
bool cmp(point p1, point p2) { return multi(p1, p2, p[... | 2C++ | {
"input": [
"5\n0 0 1\n1 0 0\n0 1 0\n1 1 1\n3 2 0\n",
"9\n0 6 1\n4 10 1\n7 9 1\n10 10 0\n7 0 0\n9 4 1\n5 7 1\n9 9 1\n8 4 1\n",
"8\n7 0 1\n10 4 1\n2 0 1\n9 1 1\n8 10 1\n6 9 0\n1 8 1\n0 9 1\n",
"4\n0 0 0\n1 0 1\n1 1 0\n0 1 1\n",
"3\n0 0 0\n1 0 0\n0 1 1\n",
"8\n2 0 1\n4 0 1\n3 1 0\n6 2 1\n0 3 0\... | 2CODEFORCES |
1070_D. Garbage Disposal_3018 | Enough is enough. Too many times it happened that Vasya forgot to dispose of garbage and his apartment stank afterwards. Now he wants to create a garbage disposal plan and stick to it.
For each of next n days Vasya knows a_i — number of units of garbage he will produce on the i-th day. Each unit of garbage must be dis... | import sys
range = xrange
input = sys.stdin.readline
n,k = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
bags = 0
for i in range(n):
bags += A[i]//k
A[i]%=k
if A[i]>0:
bags += 1
if i+1<n:
A[i+1] -= k-A[i]
if A[i+1]<0:A[i+1]=0
A[i] =... | 1Python2 | {
"input": [
"3 2\n1 0 1\n",
"4 4\n2 8 4 1\n",
"3 2\n3 2 1\n",
"5 1\n1000000000 1000000000 1000000000 1000000000 1000000000\n",
"3 10\n5 5 0\n",
"1 1\n1\n",
"4 4\n3 6 2 3\n",
"1 10\n1\n",
"185 2\n0 14 2 11 5 17 9 11 8 12 8 17 17 0 4 15 4 17 8 1 2 10 8 0 8 16 1 7 10 4 0 18 2 15 2 1 ... | 2CODEFORCES |
1070_D. Garbage Disposal_3019 | Enough is enough. Too many times it happened that Vasya forgot to dispose of garbage and his apartment stank afterwards. Now he wants to create a garbage disposal plan and stick to it.
For each of next n days Vasya knows a_i — number of units of garbage he will produce on the i-th day. Each unit of garbage must be dis... | #include <bits/stdc++.h>
using namespace std;
int main() {
long long k;
int n;
int i;
while (cin >> n >> k) {
int d = n + 1;
long long ara[d];
long long t1 = 0, c = 0, t, temp = 0, is = 1;
for (i = 1; i <= n; i++) cin >> ara[i];
for (i = 1; i <= n; i++) {
ara[i] = temp + ara[i];
... | 2C++ | {
"input": [
"3 2\n1 0 1\n",
"4 4\n2 8 4 1\n",
"3 2\n3 2 1\n",
"5 1\n1000000000 1000000000 1000000000 1000000000 1000000000\n",
"3 10\n5 5 0\n",
"1 1\n1\n",
"4 4\n3 6 2 3\n",
"1 10\n1\n",
"185 2\n0 14 2 11 5 17 9 11 8 12 8 17 17 0 4 15 4 17 8 1 2 10 8 0 8 16 1 7 10 4 0 18 2 15 2 1 ... | 2CODEFORCES |
1070_D. Garbage Disposal_3020 | Enough is enough. Too many times it happened that Vasya forgot to dispose of garbage and his apartment stank afterwards. Now he wants to create a garbage disposal plan and stick to it.
For each of next n days Vasya knows a_i — number of units of garbage he will produce on the i-th day. Each unit of garbage must be dis... | import sys
n, k = tuple(int(i) for i in sys.stdin.readline().split())
a = tuple(int(i) for i in sys.stdin.readline().split())
assert len(a) == n
bags = 0
r = 0
for ai in a:
leftovers = (r > 0)
q, r = divmod(ai + r, k)
if q == 0:
if leftovers:
bags += 1
r = 0
else:
... | 3Python3 | {
"input": [
"3 2\n1 0 1\n",
"4 4\n2 8 4 1\n",
"3 2\n3 2 1\n",
"5 1\n1000000000 1000000000 1000000000 1000000000 1000000000\n",
"3 10\n5 5 0\n",
"1 1\n1\n",
"4 4\n3 6 2 3\n",
"1 10\n1\n",
"185 2\n0 14 2 11 5 17 9 11 8 12 8 17 17 0 4 15 4 17 8 1 2 10 8 0 8 16 1 7 10 4 0 18 2 15 2 1 ... | 2CODEFORCES |
1070_D. Garbage Disposal_3021 | Enough is enough. Too many times it happened that Vasya forgot to dispose of garbage and his apartment stank afterwards. Now he wants to create a garbage disposal plan and stick to it.
For each of next n days Vasya knows a_i — number of units of garbage he will produce on the i-th day. Each unit of garbage must be dis... | import java.io.*;
import java.util.*;
public class GarbageDisposal {
public static void main(String[] args) throws Exception{
BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(f.readLine());
int n = Integer.parseInt(st.nextToken());
int k ... | 4JAVA | {
"input": [
"3 2\n1 0 1\n",
"4 4\n2 8 4 1\n",
"3 2\n3 2 1\n",
"5 1\n1000000000 1000000000 1000000000 1000000000 1000000000\n",
"3 10\n5 5 0\n",
"1 1\n1\n",
"4 4\n3 6 2 3\n",
"1 10\n1\n",
"185 2\n0 14 2 11 5 17 9 11 8 12 8 17 17 0 4 15 4 17 8 1 2 10 8 0 8 16 1 7 10 4 0 18 2 15 2 1 ... | 2CODEFORCES |
1091_H. New Year and the Tricolore Recreation_3022 | Alice and Bob play a game on a grid with n rows and infinitely many columns. In each row, there are three tokens, blue, white and red one. Before the game starts and after every move, the following two conditions must hold:
* Any two tokens are not in the same cell.
* In each row, the blue token is to the left o... | #include <bits/stdc++.h>
#pragma GCC optimize("O2,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
namespace io {
const int L = (1 << 20) + 1;
char buf[L], *S, *T, c;
char getchar() {
if (__builtin_expect(S == T, 0)) {
T... | 2C++ | {
"input": [
"1 6\n0 3 9\n",
"1 2\n0 3 9\n",
"10 133\n-248 -193 -187\n97 101 202\n-72 67 91\n23 89 215\n-129 -108 232\n-223 -59 236\n-99 86 242\n-137 -109 -45\n-105 173 246\n-44 228 243\n",
"9 3\n-3 0 2\n-3 0 2\n-3 0 2\n-1 0 2\n-3 1 3\n-3 2 3\n-3 -2 2\n-2 -1 2\n0 1 3\n",
"10 26\n-681 104 714\n-995... | 2CODEFORCES |
1091_H. New Year and the Tricolore Recreation_3023 | Alice and Bob play a game on a grid with n rows and infinitely many columns. In each row, there are three tokens, blue, white and red one. Before the game starts and after every move, the following two conditions must hold:
* Any two tokens are not in the same cell.
* In each row, the blue token is to the left o... | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;
public class GB... | 4JAVA | {
"input": [
"1 6\n0 3 9\n",
"1 2\n0 3 9\n",
"10 133\n-248 -193 -187\n97 101 202\n-72 67 91\n23 89 215\n-129 -108 232\n-223 -59 236\n-99 86 242\n-137 -109 -45\n-105 173 246\n-44 228 243\n",
"9 3\n-3 0 2\n-3 0 2\n-3 0 2\n-1 0 2\n-3 1 3\n-3 2 3\n-3 -2 2\n-2 -1 2\n0 1 3\n",
"10 26\n-681 104 714\n-995... | 2CODEFORCES |
1110_F. Nearest Leaf_3024 | Let's define the Eulerian traversal of a tree (a connected undirected graph without cycles) as follows: consider a depth-first search algorithm which traverses vertices of the tree and enumerates them in the order of visiting (only the first visit of each vertex counts). This function starts from the vertex number 1 an... | #include <bits/stdc++.h>
using namespace std;
const long long INF = 1ll << 60;
long long n, m, Max[500010], d[500010], L[500010], R[500010], ans[500010];
long long ver[1000010], edge[1000010], Next[1000010], head[500010], tot;
vector<long long> q[500010];
struct SegmentTree {
long long l, r, Min, lazy;
} tree[500010 ... | 2C++ | {
"input": [
"5 3\n1 10\n1 1\n3 2\n3 3\n1 1 5\n5 4 5\n4 1 2\n",
"11 8\n1 7\n2 1\n1 20\n1 2\n5 6\n6 2\n6 3\n5 1\n9 10\n9 11\n5 1 11\n1 1 4\n9 4 8\n6 1 4\n9 7 11\n9 10 11\n8 1 11\n11 4 5\n",
"5 3\n1 1000000000\n2 1000000000\n1 1000000000\n1 1000000000\n3 4 5\n2 1 5\n2 4 5\n",
"10 10\n1 12\n2 89\n3 20\n3... | 2CODEFORCES |
1110_F. Nearest Leaf_3025 | Let's define the Eulerian traversal of a tree (a connected undirected graph without cycles) as follows: consider a depth-first search algorithm which traverses vertices of the tree and enumerates them in the order of visiting (only the first visit of each vertex counts). This function starts from the vertex number 1 an... | //package codeforces;
import java.util.*;
import java.io.*;
public class NearestLeaf {
public static void main(String[] args) {
new NearestLeaf().solve();
}
FastReader in = new FastReader();
PrintWriter out = new PrintWriter(System.out);
int N = (int)5e5+5,h,n,q;
long[] t = new long[2*... | 4JAVA | {
"input": [
"5 3\n1 10\n1 1\n3 2\n3 3\n1 1 5\n5 4 5\n4 1 2\n",
"11 8\n1 7\n2 1\n1 20\n1 2\n5 6\n6 2\n6 3\n5 1\n9 10\n9 11\n5 1 11\n1 1 4\n9 4 8\n6 1 4\n9 7 11\n9 10 11\n8 1 11\n11 4 5\n",
"5 3\n1 1000000000\n2 1000000000\n1 1000000000\n1 1000000000\n3 4 5\n2 1 5\n2 4 5\n",
"10 10\n1 12\n2 89\n3 20\n3... | 2CODEFORCES |
1140_C. Playlist_3026 | You have a playlist consisting of n songs. The i-th song is characterized by two numbers t_i and b_i — its length and beauty respectively. The pleasure of listening to set of songs is equal to the total length of the songs in the set multiplied by the minimum beauty among them. For example, the pleasure of listening to... | import sys,math
from fractions import gcd
import heapq
from collections import defaultdict
from io import BytesIO
sys.stdin = BytesIO(sys.stdin.read())
input = lambda: sys.stdin.readline().rstrip('\r\n')
#t = int(input())
n,k = [int(x) for x in input().split(' ')]
#arr = [int(x) for x in input().split(' ')]
arr = []
fo... | 1Python2 | {
"input": [
"5 3\n12 31\n112 4\n100 100\n13 55\n55 50\n",
"4 3\n4 7\n15 1\n3 6\n6 8\n",
"5 1\n11 3\n10 2\n7 4\n6 1\n9 1\n",
"8 1\n769 58454\n48687 67740\n51730 90641\n39410 27719\n63633 23862\n39951 40870\n56520 69058\n15454 9033\n",
"2 1\n1 2\n2 1\n",
"2 2\n100 100\n100 100\n",
"10 1\n74... | 2CODEFORCES |
1140_C. Playlist_3027 | You have a playlist consisting of n songs. The i-th song is characterized by two numbers t_i and b_i — its length and beauty respectively. The pleasure of listening to set of songs is equal to the total length of the songs in the set multiplied by the minimum beauty among them. For example, the pleasure of listening to... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<pair<int, int>> songs(n);
vector<int> len(n);
for (int idx = 0; idx < n; idx++) {
int a, b;
cin >> a >> b;
songs[idx].first = b;
songs[idx].second = a;
len[idx] = a;
}
sort(songs.begin(), songs.e... | 2C++ | {
"input": [
"5 3\n12 31\n112 4\n100 100\n13 55\n55 50\n",
"4 3\n4 7\n15 1\n3 6\n6 8\n",
"5 1\n11 3\n10 2\n7 4\n6 1\n9 1\n",
"8 1\n769 58454\n48687 67740\n51730 90641\n39410 27719\n63633 23862\n39951 40870\n56520 69058\n15454 9033\n",
"2 1\n1 2\n2 1\n",
"2 2\n100 100\n100 100\n",
"10 1\n74... | 2CODEFORCES |
1140_C. Playlist_3028 | You have a playlist consisting of n songs. The i-th song is characterized by two numbers t_i and b_i — its length and beauty respectively. The pleasure of listening to set of songs is equal to the total length of the songs in the set multiplied by the minimum beauty among them. For example, the pleasure of listening to... | import heapq
n,k=map(int,input().split())
b_l=[]
for _ in range(n):
t,b=map(int,input().split())
b_l.append([b,t])
b_l.sort(reverse=True)
ans=0
sum_fg=0
h=[]
heapq.heapify(h)
for i in range(n):
sum_fg+=b_l[i][1]
heapq.heappush(h,b_l[i][1])
while(len(h)>k):
g=heapq.heappop(h)
sum_fg-=... | 3Python3 | {
"input": [
"5 3\n12 31\n112 4\n100 100\n13 55\n55 50\n",
"4 3\n4 7\n15 1\n3 6\n6 8\n",
"5 1\n11 3\n10 2\n7 4\n6 1\n9 1\n",
"8 1\n769 58454\n48687 67740\n51730 90641\n39410 27719\n63633 23862\n39951 40870\n56520 69058\n15454 9033\n",
"2 1\n1 2\n2 1\n",
"2 2\n100 100\n100 100\n",
"10 1\n74... | 2CODEFORCES |
1140_C. Playlist_3029 | You have a playlist consisting of n songs. The i-th song is characterized by two numbers t_i and b_i — its length and beauty respectively. The pleasure of listening to set of songs is equal to the total length of the songs in the set multiplied by the minimum beauty among them. For example, the pleasure of listening to... | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
new Main().go();
}
PrintWriter out;
Reader in;
BufferedReader br;
Main() throws IOException {
try {
//br = new BufferedReader( new FileReader("in... | 4JAVA | {
"input": [
"5 3\n12 31\n112 4\n100 100\n13 55\n55 50\n",
"4 3\n4 7\n15 1\n3 6\n6 8\n",
"5 1\n11 3\n10 2\n7 4\n6 1\n9 1\n",
"8 1\n769 58454\n48687 67740\n51730 90641\n39410 27719\n63633 23862\n39951 40870\n56520 69058\n15454 9033\n",
"2 1\n1 2\n2 1\n",
"2 2\n100 100\n100 100\n",
"10 1\n74... | 2CODEFORCES |
1159_A. A pile of stones_3030 | Vasya has a pile, that consists of some number of stones. n times he either took one stone from the pile or added one stone to the pile. The pile was non-empty before each operation of taking one stone from the pile.
You are given n operations which Vasya has made. Find the minimal possible number of stones that can b... |
def prime(n):
for i in range(2,n):
if n%i==0:
return False
return True
n = raw_input()
string = raw_input()
n = int(n)
cnt = 0
for i in string:
#print(i)
if i == '+':
cnt+=1
if i == '-':
if cnt > 0:
cnt-=1
print(cnt)
def powMod(x,y,mod):
ans = 1
while y > 0:
i... | 1Python2 | {
"input": [
"2\n-+\n",
"3\n---\n",
"5\n++-++\n",
"4\n++++\n",
"4\n-+--\n",
"2\n++\n",
"98\n----+-+--+-+-++-++++---+-++++-+--++-++++++-+++--+++-+-----+-+--+-----+++++--+-++-+++-+-+++-+---++-\n",
"3\n+-+\n",
"100\n---+-----------+-++---+----------++++++++++++++++++++++++++++++++++++... | 2CODEFORCES |
1159_A. A pile of stones_3031 | Vasya has a pile, that consists of some number of stones. n times he either took one stone from the pile or added one stone to the pile. The pile was non-empty before each operation of taking one stone from the pile.
You are given n operations which Vasya has made. Find the minimal possible number of stones that can b... | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int TESTS = 1;
while (TESTS--) {
long long n;
cin >> n;
string s;
cin >> s;
long long ans = 0;
for (long long i = 0; i < n; i++) {
if (s[i] == '-')
ans--;... | 2C++ | {
"input": [
"2\n-+\n",
"3\n---\n",
"5\n++-++\n",
"4\n++++\n",
"4\n-+--\n",
"2\n++\n",
"98\n----+-+--+-+-++-++++---+-++++-+--++-++++++-+++--+++-+-----+-+--+-----+++++--+-++-+++-+-+++-+---++-\n",
"3\n+-+\n",
"100\n---+-----------+-++---+----------++++++++++++++++++++++++++++++++++++... | 2CODEFORCES |
1159_A. A pile of stones_3032 | Vasya has a pile, that consists of some number of stones. n times he either took one stone from the pile or added one stone to the pile. The pile was non-empty before each operation of taking one stone from the pile.
You are given n operations which Vasya has made. Find the minimal possible number of stones that can b... | '''
t= input()
lng= len(t)
li1=[]; li2=[]
for i in range(lng):
if t[i]!='a':
li1.append(t[i])
elif t[i]=='a':
li2.append(i)
aa= ''.join(li1)
if len(aa)==0:
print(t); exit(0)
if len(aa)%2==1:
print(':('); exit(0)
if len(aa)%2==0:
#print(123)
l= int(len(aa)/2); lp= l#; pri... | 3Python3 | {
"input": [
"2\n-+\n",
"3\n---\n",
"5\n++-++\n",
"4\n++++\n",
"4\n-+--\n",
"2\n++\n",
"98\n----+-+--+-+-++-++++---+-++++-+--++-++++++-+++--+++-+-----+-+--+-----+++++--+-++-+++-+-+++-+---++-\n",
"3\n+-+\n",
"100\n---+-----------+-++---+----------++++++++++++++++++++++++++++++++++++... | 2CODEFORCES |
1159_A. A pile of stones_3033 | Vasya has a pile, that consists of some number of stones. n times he either took one stone from the pile or added one stone to the pile. The pile was non-empty before each operation of taking one stone from the pile.
You are given n operations which Vasya has made. Find the minimal possible number of stones that can b... | import java.util.Scanner;
public class stones1
{
public static void main(String args[])
{
Scanner s= new Scanner(System.in);
int n= s.nextInt();
s.nextLine();
String a= s.nextLine();
int i, j, k=0;
for(i=0; i<a.length() ; i++)
{
if(a.charAt(i)=... | 4JAVA | {
"input": [
"2\n-+\n",
"3\n---\n",
"5\n++-++\n",
"4\n++++\n",
"4\n-+--\n",
"2\n++\n",
"98\n----+-+--+-+-++-++++---+-++++-+--++-++++++-+++--+++-+-----+-+--+-----+++++--+-++-+++-+-+++-+---++-\n",
"3\n+-+\n",
"100\n---+-----------+-++---+----------++++++++++++++++++++++++++++++++++++... | 2CODEFORCES |
1181_A. Chunga-Changa_3034 | Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.
Sasha and Masha are about to buy some coconuts which are sold at price z chizhiks per cocon... | x, y, z = map(long, raw_input().split())
if x % z == 0 or y % z == 0:
res = (x//z) + (y//z)
print res, 0
exit()
hx = x % z
hy = y % z
kk = 0
res = (x // z) + (y // z)
if hx + hy >= z:
kk = z - hy
if kk <= z - hx:
x -= kk
y += kk
else:
kk = z - hx
x += kk
... | 1Python2 | {
"input": [
"6 8 2\n",
"5 4 3\n",
"5000000000000 6000000000000 10000000000000\n",
"2778787205 1763925790 48326734\n",
"582426543750017 789023129080207 4395672028302\n",
"0 0 1\n",
"1000000000000000000 999999999999999999 3\n",
"7 14 5\n",
"1 0 1\n",
"132940 345844 5\n",
"20... | 2CODEFORCES |
1181_A. Chunga-Changa_3035 | Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.
Sasha and Masha are about to buy some coconuts which are sold at price z chizhiks per cocon... | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int x, y, z;
while (~scanf("%lld%lld%lld", &x, &y, &z)) {
long long n1 = x / z;
long long m1 = x % z;
long long n2 = y / z;
long long m2 = y % z;
long long sum = n1 + n2;
long long k = 0;
if (m1 + m2 >= z) {
long ... | 2C++ | {
"input": [
"6 8 2\n",
"5 4 3\n",
"5000000000000 6000000000000 10000000000000\n",
"2778787205 1763925790 48326734\n",
"582426543750017 789023129080207 4395672028302\n",
"0 0 1\n",
"1000000000000000000 999999999999999999 3\n",
"7 14 5\n",
"1 0 1\n",
"132940 345844 5\n",
"20... | 2CODEFORCES |
1181_A. Chunga-Changa_3036 | Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.
Sasha and Masha are about to buy some coconuts which are sold at price z chizhiks per cocon... | x,y,z=map(int,input().split())
sum=(x+y)//z
i1=x//z
i2=y//z
x=x%z
y=y%z
current=i1+i2
nu=0
if current==sum:
print(sum,end=' ')
print(nu)
else:
if x>y:
h=x
else:
h=y
current=sum-current
current=current*z
nu=current-h
print(sum, end=' ')
print(nu) | 3Python3 | {
"input": [
"6 8 2\n",
"5 4 3\n",
"5000000000000 6000000000000 10000000000000\n",
"2778787205 1763925790 48326734\n",
"582426543750017 789023129080207 4395672028302\n",
"0 0 1\n",
"1000000000000000000 999999999999999999 3\n",
"7 14 5\n",
"1 0 1\n",
"132940 345844 5\n",
"20... | 2CODEFORCES |
1181_A. Chunga-Changa_3037 | Soon after the Chunga-Changa island was discovered, it started to acquire some forms of civilization and even market economy. A new currency arose, colloquially called "chizhik". One has to pay in chizhiks to buy a coconut now.
Sasha and Masha are about to buy some coconuts which are sold at price z chizhiks per cocon... | /* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Ideone
{
static long firstSum = 0;
static long secondSum = 0;
public static void main(String args[]) throws java.lang.Exce... | 4JAVA | {
"input": [
"6 8 2\n",
"5 4 3\n",
"5000000000000 6000000000000 10000000000000\n",
"2778787205 1763925790 48326734\n",
"582426543750017 789023129080207 4395672028302\n",
"0 0 1\n",
"1000000000000000000 999999999999999999 3\n",
"7 14 5\n",
"1 0 1\n",
"132940 345844 5\n",
"20... | 2CODEFORCES |
1199_F. Rectangle Painting 1_3038 | There is a square grid of size n × n. Some cells are colored in black, all others are colored in white. In one operation you can select some rectangle and color all its cells in white. It costs max(h, w) to color a rectangle of size h × w. You are to make all cells white for minimum total cost.
Input
The first line c... | #include <bits/stdc++.h>
using namespace std;
int n;
char s[51][51];
int ans[51][51][51][51];
int solve(int r1, int c1, int r2, int c2) {
if (r1 == r2 && c1 == c2) ans[r1][c1][r2][c2] = (s[r1][c1] == '#');
if (ans[r1][c1][r2][c2] != -1) return ans[r1][c1][r2][c2];
ans[r1][c1][r2][c2] = max(r2 - r1 + 1, c2 - c1 + ... | 2C++ | {
"input": [
"3\n###\n#.#\n###\n",
"5\n#...#\n.#.#.\n.....\n.#...\n#....\n",
"3\n...\n...\n...\n",
"4\n#...\n....\n....\n#...\n",
"5\n....#\n.....\n####.\n##...\n#.#..\n",
"10\n.......#..\n...#######\n......####\n...###.#.#\n...##....#\n...#####.#\n....##.#.#\n...#.#####\n..........\n............ | 2CODEFORCES |
1199_F. Rectangle Painting 1_3039 | There is a square grid of size n × n. Some cells are colored in black, all others are colored in white. In one operation you can select some rectangle and color all its cells in white. It costs max(h, w) to color a rectangle of size h × w. You are to make all cells white for minimum total cost.
Input
The first line c... | import java.util.*;
import java.io.*;
public class RectanglePaintingOne {
public static void main(String[] args) {
FastScanner scanner = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int n = scanner.nextInt();
int[][] grid= new int[n][n];
for(int i = 0; i... | 4JAVA | {
"input": [
"3\n###\n#.#\n###\n",
"5\n#...#\n.#.#.\n.....\n.#...\n#....\n",
"3\n...\n...\n...\n",
"4\n#...\n....\n....\n#...\n",
"5\n....#\n.....\n####.\n##...\n#.#..\n",
"10\n.......#..\n...#######\n......####\n...###.#.#\n...##....#\n...#####.#\n....##.#.#\n...#.#####\n..........\n............ | 2CODEFORCES |
1216_E1. Numerical Sequence (easy version)_3040 | The only difference between the easy and the hard versions is the maximum value of k.
You are given an infinite sequence of form "112123123412345..." which consist of blocks of all consecutive positive integers written one after another. The first block consists of all numbers from 1 to 1, the second one — from 1 to 2... | import decimal,math
from collections import *
from fractions import gcd
from bisect import bisect_right,bisect_left
import sys
def primeFactors(n):
arr=[]
while n % 2 == 0:
arr.append(2)
n = n / 2
for i in xrange(3,int(math.sqrt(n))+1,2):
while n % i== 0:
arr.append(i)
n = n / i
if n > 2:
arr... | 1Python2 | {
"input": [
"4\n2132\n506\n999999999\n1000000000\n",
"5\n1\n3\n20\n38\n56\n",
"1\n755045\n",
"19\n1\n10\n100\n1000\n10000\n100000\n1000000\n10000000\n100000000\n1000000000\n10000000000\n100000000000\n1000000000000\n10000000000000\n100000000000000\n1000000000000000\n10000000000000000\n1000000000000000... | 2CODEFORCES |
1216_E1. Numerical Sequence (easy version)_3041 | The only difference between the easy and the hard versions is the maximum value of k.
You are given an infinite sequence of form "112123123412345..." which consist of blocks of all consecutive positive integers written one after another. The first block consists of all numbers from 1 to 1, the second one — from 1 to 2... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 7;
const long long inf = 1e18 + 7;
const int mod = 1e9 + 7;
int q;
long long k, a[10], b[50], c[10], ci[10];
long long wer(long long nub, long long k) {
int ct = 0;
while (ci[ct] < k) ct++;
k = k - ci[ct - 1];
long long ki = (k - 1) / ct + c[c... | 2C++ | {
"input": [
"4\n2132\n506\n999999999\n1000000000\n",
"5\n1\n3\n20\n38\n56\n",
"1\n755045\n",
"19\n1\n10\n100\n1000\n10000\n100000\n1000000\n10000000\n100000000\n1000000000\n10000000000\n100000000000\n1000000000000\n10000000000000\n100000000000000\n1000000000000000\n10000000000000000\n1000000000000000... | 2CODEFORCES |
1216_E1. Numerical Sequence (easy version)_3042 | The only difference between the easy and the hard versions is the maximum value of k.
You are given an infinite sequence of form "112123123412345..." which consist of blocks of all consecutive positive integers written one after another. The first block consists of all numbers from 1 to 1, the second one — from 1 to 2... | def isqrt(x):
if x < 0:
raise ValueError('square root not defined for negative numbers')
n = int(x)
if n == 0:
return 0
a, b = divmod(n.bit_length(), 2)
x = 2**(a+b)
while True:
y = (x + n//x)//2
if y >= x:
return x
x = y
p = [0, 45, 9045, 1395... | 3Python3 | {
"input": [
"4\n2132\n506\n999999999\n1000000000\n",
"5\n1\n3\n20\n38\n56\n",
"1\n755045\n",
"19\n1\n10\n100\n1000\n10000\n100000\n1000000\n10000000\n100000000\n1000000000\n10000000000\n100000000000\n1000000000000\n10000000000000\n100000000000000\n1000000000000000\n10000000000000000\n1000000000000000... | 2CODEFORCES |
1216_E1. Numerical Sequence (easy version)_3043 | The only difference between the easy and the hard versions is the maximum value of k.
You are given an infinite sequence of form "112123123412345..." which consist of blocks of all consecutive positive integers written one after another. The first block consists of all numbers from 1 to 1, the second one — from 1 to 2... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.Input... | 4JAVA | {
"input": [
"4\n2132\n506\n999999999\n1000000000\n",
"5\n1\n3\n20\n38\n56\n",
"1\n755045\n",
"19\n1\n10\n100\n1000\n10000\n100000\n1000000\n10000000\n100000000\n1000000000\n10000000000\n100000000000\n1000000000000\n10000000000000\n100000000000000\n1000000000000000\n10000000000000000\n1000000000000000... | 2CODEFORCES |
1239_F. Swiper, no swiping!_3044 | I'm the Map, I'm the Map! I'm the MAP!!!
Map
In anticipation of new adventures Boots wanted to do a good deed. After discussion with the Map and Backpack, they decided to gift Dora a connected graph. After a long search, Boots chose t graph's variants, which Dora might like. However fox Swiper wants to spoil his plan... | #include <bits/stdc++.h>
using namespace std;
const int N = 500 * 1000 + 10;
int t, n, m, par[N], deg[N], st, en, h[N], mn, comp[N], sv[2][N];
vector<int> adj[N];
bool vis[N], ans[N];
void gclear() {
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2; j++) sv[j][i] = -1;
adj[i].clear();
comp[i] = ans[i] ... | 2C++ | {
"input": [
"3\n3 3\n1 2\n2 3\n3 1\n\n6 6\n1 2\n1 3\n2 3\n2 5\n2 6\n2 4\n\n8 12\n1 2\n1 3\n2 3\n1 4\n4 5\n5 1\n3 6\n3 7\n3 8\n6 1\n7 1\n8 1\n",
"1\n18 35\n16 14\n14 10\n17 6\n1 10\n2 5\n17 18\n13 4\n18 15\n3 15\n4 8\n7 10\n7 14\n4 14\n1 18\n14 1\n2 3\n2 14\n17 13\n18 16\n3 16\n1 9\n10 17\n14 12\n3 13\n2 13\n... | 2CODEFORCES |
125_A. Measuring Lengths in Baden_3045 | Lengths are measures in Baden in inches and feet. To a length from centimeters it is enough to know that an inch equals three centimeters in Baden and one foot contains 12 inches.
You are given a length equal to n centimeters. Your task is to convert it to feet and inches so that the number of feet was maximum. The re... | n = int(raw_input())
by_foot = n / 3
if n - by_foot*3 == 2:
by_foot += 1
feet = by_foot /12
by_inch = n - feet*36
if by_inch <= 0:
inch = 0
else:
inch = by_inch/3
if by_inch - inch*3 == 2:
inch += 1
print feet, inch
| 1Python2 | {
"input": [
"42\n",
"5\n",
"4\n",
"71\n",
"9999\n",
"35\n",
"199\n",
"10000\n",
"10\n",
"2\n",
"9876\n",
"8\n",
"120\n",
"3\n",
"1233\n",
"501\n",
"24\n",
"12\n",
"13\n",
"1000\n",
"1\n",
"100\n",
"7\n",
"94\n",
"1886... | 2CODEFORCES |
125_A. Measuring Lengths in Baden_3046 | Lengths are measures in Baden in inches and feet. To a length from centimeters it is enough to know that an inch equals three centimeters in Baden and one foot contains 12 inches.
You are given a length equal to n centimeters. Your task is to convert it to feet and inches so that the number of feet was maximum. The re... | #include <bits/stdc++.h>
using namespace std;
vector<string> token(string a) {
vector<string> w;
a.push_back(' ');
while (!a.empty()) {
w.push_back(a.substr(0, a.find(" ")));
a = a.substr(a.find(" ") + 1, a.size() - 1);
}
return w;
}
map<string, int> mapik;
vector<string> amapik;
int dodaj(string a) {... | 2C++ | {
"input": [
"42\n",
"5\n",
"4\n",
"71\n",
"9999\n",
"35\n",
"199\n",
"10000\n",
"10\n",
"2\n",
"9876\n",
"8\n",
"120\n",
"3\n",
"1233\n",
"501\n",
"24\n",
"12\n",
"13\n",
"1000\n",
"1\n",
"100\n",
"7\n",
"94\n",
"1886... | 2CODEFORCES |
125_A. Measuring Lengths in Baden_3047 | Lengths are measures in Baden in inches and feet. To a length from centimeters it is enough to know that an inch equals three centimeters in Baden and one foot contains 12 inches.
You are given a length equal to n centimeters. Your task is to convert it to feet and inches so that the number of feet was maximum. The re... | n=int(input())
e=(n+1)//36
n-=36*e
print(e,(n+1)//3) | 3Python3 | {
"input": [
"42\n",
"5\n",
"4\n",
"71\n",
"9999\n",
"35\n",
"199\n",
"10000\n",
"10\n",
"2\n",
"9876\n",
"8\n",
"120\n",
"3\n",
"1233\n",
"501\n",
"24\n",
"12\n",
"13\n",
"1000\n",
"1\n",
"100\n",
"7\n",
"94\n",
"1886... | 2CODEFORCES |
125_A. Measuring Lengths in Baden_3048 | Lengths are measures in Baden in inches and feet. To a length from centimeters it is enough to know that an inch equals three centimeters in Baden and one foot contains 12 inches.
You are given a length equal to n centimeters. Your task is to convert it to feet and inches so that the number of feet was maximum. The re... | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
public class Solution {
static PrintWriter bw;
static BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
p... | 4JAVA | {
"input": [
"42\n",
"5\n",
"4\n",
"71\n",
"9999\n",
"35\n",
"199\n",
"10000\n",
"10\n",
"2\n",
"9876\n",
"8\n",
"120\n",
"3\n",
"1233\n",
"501\n",
"24\n",
"12\n",
"13\n",
"1000\n",
"1\n",
"100\n",
"7\n",
"94\n",
"1886... | 2CODEFORCES |
1281_C. Cut and Paste_3049 | We start with a string s consisting only of the digits 1, 2, or 3. The length of s is denoted by |s|. For each i from 1 to |s|, the i-th character of s is denoted by s_i.
There is one cursor. The cursor's location ℓ is denoted by an integer in \{0, …, |s|\}, with the following meaning:
* If ℓ = 0, then the cursor... | for _ in range(input()):
x = input()
s = raw_input()
t = [0] * x
real_len = length = len(s)
for i in range(min(length, x)):
t[i] = int(s[i]) - 1
idx = 0
while 1:
idx += 1
k = t[idx - 1]
if k != 0:
right_len = real_len - idx
add_len = ma... | 1Python2 | {
"input": [
"4\n5\n231\n7\n2323\n6\n333\n24\n133321333\n",
"9\n1500\n1212\n1500\n1221\n1500\n122\n1500\n12121\n1500\n22\n1500\n1111112111111112\n1500\n1111111111221111111\n1500\n111111122\n1500\n11111121111121111111\n",
"1\n1000000\n22\n",
"1\n941759\n1223231111\n",
"1\n1000000\n2211\n",
"1\n... | 2CODEFORCES |
1281_C. Cut and Paste_3050 | We start with a string s consisting only of the digits 1, 2, or 3. The length of s is denoted by |s|. For each i from 1 to |s|, the i-th character of s is denoted by s_i.
There is one cursor. The cursor's location ℓ is denoted by an integer in \{0, …, |s|\}, with the following meaning:
* If ℓ = 0, then the cursor... | #include <bits/stdc++.h>
using namespace std;
const int N = 5e6 + 5;
const long long mod = 1e9 + 7;
long long t, n, x, a[N];
string s;
int main() {
cin >> t;
while (t--) {
cin >> x >> s;
for (int i = 1; i <= s.length(); i++) {
a[i] = s[i - 1] - 48;
}
long long len = s.length(), kt = 0;
for... | 2C++ | {
"input": [
"4\n5\n231\n7\n2323\n6\n333\n24\n133321333\n",
"9\n1500\n1212\n1500\n1221\n1500\n122\n1500\n12121\n1500\n22\n1500\n1111112111111112\n1500\n1111111111221111111\n1500\n111111122\n1500\n11111121111121111111\n",
"1\n1000000\n22\n",
"1\n941759\n1223231111\n",
"1\n1000000\n2211\n",
"1\n... | 2CODEFORCES |
1281_C. Cut and Paste_3051 | We start with a string s consisting only of the digits 1, 2, or 3. The length of s is denoted by |s|. For each i from 1 to |s|, the i-th character of s is denoted by s_i.
There is one cursor. The cursor's location ℓ is denoted by an integer in \{0, …, |s|\}, with the following meaning:
* If ℓ = 0, then the cursor... | import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
MAX=10**9+7
def solve():
x = int(input())
s = [int(i) for i in input()]
ans=len(s)
c = ""
l = 0
while l < x:
l += 1
k=len(s)
if k < x:
#s += s[l:]*(s[l - 1]-1)
for i in ran... | 3Python3 | {
"input": [
"4\n5\n231\n7\n2323\n6\n333\n24\n133321333\n",
"9\n1500\n1212\n1500\n1221\n1500\n122\n1500\n12121\n1500\n22\n1500\n1111112111111112\n1500\n1111111111221111111\n1500\n111111122\n1500\n11111121111121111111\n",
"1\n1000000\n22\n",
"1\n941759\n1223231111\n",
"1\n1000000\n2211\n",
"1\n... | 2CODEFORCES |
1281_C. Cut and Paste_3052 | We start with a string s consisting only of the digits 1, 2, or 3. The length of s is denoted by |s|. For each i from 1 to |s|, the i-th character of s is denoted by s_i.
There is one cursor. The cursor's location ℓ is denoted by an integer in \{0, …, |s|\}, with the following meaning:
* If ℓ = 0, then the cursor... | import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
Main m = new Main();
m.... | 4JAVA | {
"input": [
"4\n5\n231\n7\n2323\n6\n333\n24\n133321333\n",
"9\n1500\n1212\n1500\n1221\n1500\n122\n1500\n12121\n1500\n22\n1500\n1111112111111112\n1500\n1111111111221111111\n1500\n111111122\n1500\n11111121111121111111\n",
"1\n1000000\n22\n",
"1\n941759\n1223231111\n",
"1\n1000000\n2211\n",
"1\n... | 2CODEFORCES |
1301_C. Ayoub's function_3053 | Ayoub thinks that he is a very smart person, so he created a function f(s), where s is a binary string (a string which contains only symbols "0" and "1"). The function f(s) is equal to the number of substrings in the string s that contains at least one symbol, that is equal to "1".
More formally, f(s) is equal to the ... | import sys
T = input()
for case in range(T):
n, m = map(int, raw_input().split())
if m >= float(n)/2:
A = n*(n + 1)/2 - (n - m)
else:
# the number of compartments
c = m + 1
# splitting the zeros into compartments
z = n - m
f_l = z/c
# calculate how many of f_l and f_u there need
n_... | 1Python2 | {
"input": [
"5\n3 1\n3 2\n3 3\n4 0\n5 2\n",
"5\n3 1\n3 2\n3 3\n0 0\n5 2\n",
"5\n3 1\n3 2\n3 3\n0 0\n10 2\n",
"5\n3 0\n3 2\n3 3\n0 0\n10 2\n",
"5\n3 0\n3 2\n3 3\n4 0\n5 2\n",
"5\n4 1\n3 2\n3 3\n0 0\n5 2\n",
"5\n3 0\n3 2\n3 3\n0 0\n9 2\n",
"5\n3 0\n3 2\n3 3\n4 0\n8 2\n",
"5\n3 1\n3 ... | 2CODEFORCES |
1301_C. Ayoub's function_3054 | Ayoub thinks that he is a very smart person, so he created a function f(s), where s is a binary string (a string which contains only symbols "0" and "1"). The function f(s) is equal to the number of substrings in the string s that contains at least one symbol, that is equal to "1".
More formally, f(s) is equal to the ... | #include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long fact[1000001];
long long inv[1000001];
long long primes[100007];
long long arr[1000007];
long long modPower(long long b, long long p) {
if (p == 0) return 1;
long long halfpow = modPower(b, p / 2);
long long toReturn = (halfpow... | 2C++ | {
"input": [
"5\n3 1\n3 2\n3 3\n4 0\n5 2\n",
"5\n3 1\n3 2\n3 3\n0 0\n5 2\n",
"5\n3 1\n3 2\n3 3\n0 0\n10 2\n",
"5\n3 0\n3 2\n3 3\n0 0\n10 2\n",
"5\n3 0\n3 2\n3 3\n4 0\n5 2\n",
"5\n4 1\n3 2\n3 3\n0 0\n5 2\n",
"5\n3 0\n3 2\n3 3\n0 0\n9 2\n",
"5\n3 0\n3 2\n3 3\n4 0\n8 2\n",
"5\n3 1\n3 ... | 2CODEFORCES |
1301_C. Ayoub's function_3055 | Ayoub thinks that he is a very smart person, so he created a function f(s), where s is a binary string (a string which contains only symbols "0" and "1"). The function f(s) is equal to the number of substrings in the string s that contains at least one symbol, that is equal to "1".
More formally, f(s) is equal to the ... | '''input
5
3 1
3 2
3 3
4 0
5 2
'''
import sys
read = lambda: list(map(int,sys.stdin.readline().strip().split()))
# try:
sigma = lambda x:x*(x+1)//2
for _ in range(int(input())):
n,m = read()
k = n-m
total = sigma(n)
# if m==0 or m==n:
# print(total)
# continue
if k>m:
e,f =... | 3Python3 | {
"input": [
"5\n3 1\n3 2\n3 3\n4 0\n5 2\n",
"5\n3 1\n3 2\n3 3\n0 0\n5 2\n",
"5\n3 1\n3 2\n3 3\n0 0\n10 2\n",
"5\n3 0\n3 2\n3 3\n0 0\n10 2\n",
"5\n3 0\n3 2\n3 3\n4 0\n5 2\n",
"5\n4 1\n3 2\n3 3\n0 0\n5 2\n",
"5\n3 0\n3 2\n3 3\n0 0\n9 2\n",
"5\n3 0\n3 2\n3 3\n4 0\n8 2\n",
"5\n3 1\n3 ... | 2CODEFORCES |
1301_C. Ayoub's function_3056 | Ayoub thinks that he is a very smart person, so he created a function f(s), where s is a binary string (a string which contains only symbols "0" and "1"). The function f(s) is equal to the number of substrings in the string s that contains at least one symbol, that is equal to "1".
More formally, f(s) is equal to the ... | import java.util.*;
import java.io.*;
public class lp{
static PrintWriter out = new PrintWriter(System.out);
static int mod =1000000007;
static int max = 1000000000;
static int fun(int a[],int n,int x){
int min = 0;
for(int i=0;i<n;i++){
if(a[i]==-1){
if((i-1)>=0&&a[i-1]!=-1&&abs(a[i-1]-x)>min)
... | 4JAVA | {
"input": [
"5\n3 1\n3 2\n3 3\n4 0\n5 2\n",
"5\n3 1\n3 2\n3 3\n0 0\n5 2\n",
"5\n3 1\n3 2\n3 3\n0 0\n10 2\n",
"5\n3 0\n3 2\n3 3\n0 0\n10 2\n",
"5\n3 0\n3 2\n3 3\n4 0\n5 2\n",
"5\n4 1\n3 2\n3 3\n0 0\n5 2\n",
"5\n3 0\n3 2\n3 3\n0 0\n9 2\n",
"5\n3 0\n3 2\n3 3\n4 0\n8 2\n",
"5\n3 1\n3 ... | 2CODEFORCES |
1325_C. Ehab and Path-etic MEXs_3057 | You are given a tree consisting of n nodes. You want to write some labels on the tree's edges such that the following conditions hold:
* Every label is an integer between 0 and n-2 inclusive.
* All the written labels are distinct.
* The largest value among MEX(u,v) over all pairs of nodes (u,v) is as small as ... | from sys import stdin, stdout
n=int(stdin.readline())
edges=[]
sz=[0]*(n+1)
ans=[-1]*(n-1)
for i in xrange(n-1):
u,v=map(int, stdin.readline().split())
edges.append([u,v,i])
edges.append([v,u,i])
sz[u]+=1
sz[v]+=1
m=0
for i in xrange(len(sz)):
if sz[i]>sz[m]:
m=i
res=0
for i in xrange... | 1Python2 | {
"input": [
"6\n1 2\n1 3\n2 4\n2 5\n5 6\n",
"3\n1 2\n1 3\n",
"6\n1 2\n2 3\n3 4\n3 5\n3 6\n",
"7\n6 4\n3 7\n3 5\n1 3\n4 2\n7 4\n",
"7\n3 2\n5 7\n4 2\n7 6\n6 3\n1 6\n",
"2\n1 2\n",
"13\n1 4\n2 4\n3 4\n4 5\n5 11\n11 12\n12 13\n13 6\n6 7\n7 8\n7 9\n7 10\n",
"4\n2 3\n2 4\n2 1\n",
"5\n1... | 2CODEFORCES |
1325_C. Ehab and Path-etic MEXs_3058 | You are given a tree consisting of n nodes. You want to write some labels on the tree's edges such that the following conditions hold:
* Every label is an integer between 0 and n-2 inclusive.
* All the written labels are distinct.
* The largest value among MEX(u,v) over all pairs of nodes (u,v) is as small as ... | #include <bits/stdc++.h>
using namespace std;
int n;
vector<int> q[100005];
int f, t;
int p[100005];
bool r;
int main() {
cin >> n;
for (int i = 1; i < n; i++) {
scanf("%d%d", &f, &t);
q[f].push_back(i), q[t].push_back(i);
}
for (int i = 1; i <= n; i++) {
if (q[i].size() >= 3) {
r = 1;
f... | 2C++ | {
"input": [
"6\n1 2\n1 3\n2 4\n2 5\n5 6\n",
"3\n1 2\n1 3\n",
"6\n1 2\n2 3\n3 4\n3 5\n3 6\n",
"7\n6 4\n3 7\n3 5\n1 3\n4 2\n7 4\n",
"7\n3 2\n5 7\n4 2\n7 6\n6 3\n1 6\n",
"2\n1 2\n",
"13\n1 4\n2 4\n3 4\n4 5\n5 11\n11 12\n12 13\n13 6\n6 7\n7 8\n7 9\n7 10\n",
"4\n2 3\n2 4\n2 1\n",
"5\n1... | 2CODEFORCES |
1325_C. Ehab and Path-etic MEXs_3059 | You are given a tree consisting of n nodes. You want to write some labels on the tree's edges such that the following conditions hold:
* Every label is an integer between 0 and n-2 inclusive.
* All the written labels are distinct.
* The largest value among MEX(u,v) over all pairs of nodes (u,v) is as small as ... | n = int(input())
occ = [0 for i in range(n)]
graph = [[0,0] for i in range(n-1)]
for i in range(n-1):
x, y = map(int,input().split())
occ[x-1]+=1
occ[y-1]+=1
graph[i][0] = x-1
graph[i][1] = y-1
fin = [-1 for i in range(n-1)]
for i in range(n):
if occ[i] >= 3 :
var = 0
for j ... | 3Python3 | {
"input": [
"6\n1 2\n1 3\n2 4\n2 5\n5 6\n",
"3\n1 2\n1 3\n",
"6\n1 2\n2 3\n3 4\n3 5\n3 6\n",
"7\n6 4\n3 7\n3 5\n1 3\n4 2\n7 4\n",
"7\n3 2\n5 7\n4 2\n7 6\n6 3\n1 6\n",
"2\n1 2\n",
"13\n1 4\n2 4\n3 4\n4 5\n5 11\n11 12\n12 13\n13 6\n6 7\n7 8\n7 9\n7 10\n",
"4\n2 3\n2 4\n2 1\n",
"5\n1... | 2CODEFORCES |
1325_C. Ehab and Path-etic MEXs_3060 | You are given a tree consisting of n nodes. You want to write some labels on the tree's edges such that the following conditions hold:
* Every label is an integer between 0 and n-2 inclusive.
* All the written labels are distinct.
* The largest value among MEX(u,v) over all pairs of nodes (u,v) is as small as ... | import java.util.*;
import java.io.*;
public class Solution{
public static void main (String[] args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
PrintWriter out=new PrintWriter(System.out);
String[] temp=br.readLine().trim().split(" ");
int n=Integer.parseInt(te... | 4JAVA | {
"input": [
"6\n1 2\n1 3\n2 4\n2 5\n5 6\n",
"3\n1 2\n1 3\n",
"6\n1 2\n2 3\n3 4\n3 5\n3 6\n",
"7\n6 4\n3 7\n3 5\n1 3\n4 2\n7 4\n",
"7\n3 2\n5 7\n4 2\n7 6\n6 3\n1 6\n",
"2\n1 2\n",
"13\n1 4\n2 4\n3 4\n4 5\n5 11\n11 12\n12 13\n13 6\n6 7\n7 8\n7 9\n7 10\n",
"4\n2 3\n2 4\n2 1\n",
"5\n1... | 2CODEFORCES |
1344_B. Monopole Magnets_3061 | A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care.
There is an n× m grid. Initially, you may place some north magnets and some south magnets into the cells. You are allowe... | from __future__ import division, print_function
_interactive = False
def main():
n, m = input_as_list()
g = [input() for _ in range(n)]
from itertools import chain, groupby
for line in chain(g, zip(*g)):
if sum(k=="#" for k, _ in groupby(line)) > 1:
print(-1)
return
... | 1Python2 | {
"input": [
"3 3\n.#.\n###\n##.\n",
"4 5\n....#\n####.\n.###.\n.#...\n",
"4 2\n##\n.#\n.#\n##\n",
"3 5\n.....\n.....\n.....\n",
"2 1\n.\n#\n",
"19 19\n##############.....\n.#############.....\n.###########.......\n.###########.......\n.....#######.......\n.....###...........\n................... | 2CODEFORCES |
1344_B. Monopole Magnets_3062 | A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care.
There is an n× m grid. Initially, you may place some north magnets and some south magnets into the cells. You are allowe... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
const int inf = 0x3f3f3f3f;
int m1[maxn][maxn], m2[maxn][maxn];
bool hang[maxn], lie[maxn], have;
int ans, n, m;
int dxy[][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
pair<int, int> p;
char ch;
inline bool ju1() {
bool b1 = 0, b2 = 0;
for (int i = 1;... | 2C++ | {
"input": [
"3 3\n.#.\n###\n##.\n",
"4 5\n....#\n####.\n.###.\n.#...\n",
"4 2\n##\n.#\n.#\n##\n",
"3 5\n.....\n.....\n.....\n",
"2 1\n.\n#\n",
"19 19\n##############.....\n.#############.....\n.###########.......\n.###########.......\n.....#######.......\n.....###...........\n................... | 2CODEFORCES |
1344_B. Monopole Magnets_3063 | A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care.
There is an n× m grid. Initially, you may place some north magnets and some south magnets into the cells. You are allowe... | # -*- coding:utf-8 -*-
"""
created by shuangquan.huang at 2020/6/16
"""
import collections
import time
import os
import sys
import bisect
import heapq
from typing import List
def check(row):
start, end = 0, len(row) - 1
while start < len(row) and row[start] == 0:
start += 1
if start >... | 3Python3 | {
"input": [
"3 3\n.#.\n###\n##.\n",
"4 5\n....#\n####.\n.###.\n.#...\n",
"4 2\n##\n.#\n.#\n##\n",
"3 5\n.....\n.....\n.....\n",
"2 1\n.\n#\n",
"19 19\n##############.....\n.#############.....\n.###########.......\n.###########.......\n.....#######.......\n.....###...........\n................... | 2CODEFORCES |
1344_B. Monopole Magnets_3064 | A monopole magnet is a magnet that only has one pole, either north or south. They don't actually exist since real magnets have two poles, but this is a programming contest problem, so we don't care.
There is an n× m grid. Initially, you may place some north magnets and some south magnets into the cells. You are allowe... |
import java.awt.*;
import java.util.Scanner;
import java.util.Stack;
/**
* Created by rkarumuru on 5/12/20
**/
public class Monopoles {
private static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
int n = scanner.nextInt();
int m = getInt();
solve(n, m);
}
... | 4JAVA | {
"input": [
"3 3\n.#.\n###\n##.\n",
"4 5\n....#\n####.\n.###.\n.#...\n",
"4 2\n##\n.#\n.#\n##\n",
"3 5\n.....\n.....\n.....\n",
"2 1\n.\n#\n",
"19 19\n##############.....\n.#############.....\n.###########.......\n.###########.......\n.....#######.......\n.....###...........\n................... | 2CODEFORCES |
1366_B. Shuffle_3065 | You are given an array consisting of n integers a_1, a_2, ..., a_n. Initially a_x = 1, all other elements are equal to 0.
You have to perform m operations. During the i-th operation, you choose two indices c and d such that l_i ≤ c, d ≤ r_i, and swap a_c and a_d.
Calculate the number of indices k such that it is poss... |
# from math import factorial as fac
from collections import defaultdict
# from copy import deepcopy
import sys, math
f = None
try:
f = open('q1.input', 'r')
except IOError:
f = sys.stdin
if 'xrange' in dir(__builtins__):
range = xrange
# print(f.readline())
sys.setrecursionlimit(10**2)
def print_case_iterable(c... | 1Python2 | {
"input": [
"3\n6 4 3\n1 6\n2 3\n5 5\n4 1 2\n2 4\n1 2\n3 3 2\n2 3\n1 2\n",
"9\n100 50 6\n1 49\n51 100\n40 60\n30 70\n20 30\n70 80\n100 1 11\n1 1\n1 1\n1 1\n2 2\n2 100\n1 2\n2 3\n3 4\n5 6\n6 100\n4 5\n1 1 5\n1 1\n1 1\n1 1\n1 1\n1 1\n11 6 4\n6 6\n1 5\n7 11\n6 6\n3 3 2\n1 2\n2 3\n1000000000 1 1\n1 1000000000\n1... | 2CODEFORCES |
1366_B. Shuffle_3066 | You are given an array consisting of n integers a_1, a_2, ..., a_n. Initially a_x = 1, all other elements are equal to 0.
You have to perform m operations. During the i-th operation, you choose two indices c and d such that l_i ≤ c, d ≤ r_i, and swap a_c and a_d.
Calculate the number of indices k such that it is poss... | #include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const long long int N = 1000005;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t;
cin >> t;
while (t--) {
long long int n, m, x, l, r, ans = 0, left = 1000000000000, righ... | 2C++ | {
"input": [
"3\n6 4 3\n1 6\n2 3\n5 5\n4 1 2\n2 4\n1 2\n3 3 2\n2 3\n1 2\n",
"9\n100 50 6\n1 49\n51 100\n40 60\n30 70\n20 30\n70 80\n100 1 11\n1 1\n1 1\n1 1\n2 2\n2 100\n1 2\n2 3\n3 4\n5 6\n6 100\n4 5\n1 1 5\n1 1\n1 1\n1 1\n1 1\n1 1\n11 6 4\n6 6\n1 5\n7 11\n6 6\n3 3 2\n1 2\n2 3\n1000000000 1 1\n1 1000000000\n1... | 2CODEFORCES |
1366_B. Shuffle_3067 | You are given an array consisting of n integers a_1, a_2, ..., a_n. Initially a_x = 1, all other elements are equal to 0.
You have to perform m operations. During the i-th operation, you choose two indices c and d such that l_i ≤ c, d ≤ r_i, and swap a_c and a_d.
Calculate the number of indices k such that it is poss... | from __future__ import division, print_function
# import threading
# threading.stack_size(2**27)
# import sys
# sys.setrecursionlimit(10**7)
# sys.stdin = open('inpy.txt', 'r')
# sys.stdout = open('outpy.txt', 'w')
from sys import stdin, stdout
import bisect #c++ upperbound
import math
import heapq
i_m=92233... | 3Python3 | {
"input": [
"3\n6 4 3\n1 6\n2 3\n5 5\n4 1 2\n2 4\n1 2\n3 3 2\n2 3\n1 2\n",
"9\n100 50 6\n1 49\n51 100\n40 60\n30 70\n20 30\n70 80\n100 1 11\n1 1\n1 1\n1 1\n2 2\n2 100\n1 2\n2 3\n3 4\n5 6\n6 100\n4 5\n1 1 5\n1 1\n1 1\n1 1\n1 1\n1 1\n11 6 4\n6 6\n1 5\n7 11\n6 6\n3 3 2\n1 2\n2 3\n1000000000 1 1\n1 1000000000\n1... | 2CODEFORCES |
1366_B. Shuffle_3068 | You are given an array consisting of n integers a_1, a_2, ..., a_n. Initially a_x = 1, all other elements are equal to 0.
You have to perform m operations. During the i-th operation, you choose two indices c and d such that l_i ≤ c, d ≤ r_i, and swap a_c and a_d.
Calculate the number of indices k such that it is poss... | import java.util.*;
import java.io.*;
import java.lang.*;
import java.net.*;
public class Main
{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(Sy... | 4JAVA | {
"input": [
"3\n6 4 3\n1 6\n2 3\n5 5\n4 1 2\n2 4\n1 2\n3 3 2\n2 3\n1 2\n",
"9\n100 50 6\n1 49\n51 100\n40 60\n30 70\n20 30\n70 80\n100 1 11\n1 1\n1 1\n1 1\n2 2\n2 100\n1 2\n2 3\n3 4\n5 6\n6 100\n4 5\n1 1 5\n1 1\n1 1\n1 1\n1 1\n1 1\n11 6 4\n6 6\n1 5\n7 11\n6 6\n3 3 2\n1 2\n2 3\n1000000000 1 1\n1 1000000000\n1... | 2CODEFORCES |
1386_B. Mixture_3069 | Serge, the chef of the famous restaurant "Salt, Pepper & Garlic" is trying to obtain his first Michelin star. He has been informed that a secret expert plans to visit his restaurant this evening.
Even though the expert's name hasn't been disclosed, Serge is certain he knows which dish from the menu will be ordered as ... | #include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int v[5], w[5], id[5];
long long p1[N], p2[N];
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
namespace N1 {
int sum;
void insert(int x, int fl) {
if (!p1[x] && !p2[x]) fl ? ++sum : --sum;
}
bool check() { return sum != 0; ... | 2C++ | {
"input": [
"1 2 3\n6\nA 5 6 7\nA 3 10 17\nR 1\nA 15 18 21\nA 5 10 15\nR 3\n",
"5 3 2\n15\nA 2 14 4\nA 4 12 4\nA 14 26 10\nR 1\nA 3 5 2\nA 20 12 8\nA 2 14 4\nA 13 27 10\nR 5\nA 15 25 10\nA 7 1 2\nA 1 7 2\nR 3\nR 2\nR 4\n",
"1 2 4\n33\nA 5 5 4\nA 5 6 26\nA 1 26 64\nA 19 26 46\nA 4 3 0\nA 1 7 20\nA 5 12 17... | 2CODEFORCES |
1386_B. Mixture_3070 | Serge, the chef of the famous restaurant "Salt, Pepper & Garlic" is trying to obtain his first Michelin star. He has been informed that a secret expert plans to visit his restaurant this evening.
Even though the expert's name hasn't been disclosed, Serge is certain he knows which dish from the menu will be ordered as ... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Mixture {
static long[] favorite = new long[3];
static long[][] matrix = new long[3][3];
static void add(int to, int from) {
for (int j = 0; j <= 2; j++) {
... | 4JAVA | {
"input": [
"1 2 3\n6\nA 5 6 7\nA 3 10 17\nR 1\nA 15 18 21\nA 5 10 15\nR 3\n",
"5 3 2\n15\nA 2 14 4\nA 4 12 4\nA 14 26 10\nR 1\nA 3 5 2\nA 20 12 8\nA 2 14 4\nA 13 27 10\nR 5\nA 15 25 10\nA 7 1 2\nA 1 7 2\nR 3\nR 2\nR 4\n",
"1 2 4\n33\nA 5 5 4\nA 5 6 26\nA 1 26 64\nA 19 26 46\nA 4 3 0\nA 1 7 20\nA 5 12 17... | 2CODEFORCES |
1408_B. Arrays Sum_3071 | You are given a non-decreasing array of non-negative integers a_1, a_2, …, a_n. Also you are given a positive integer k.
You want to find m non-decreasing arrays of non-negative integers b_1, b_2, …, b_m, such that:
* The size of b_i is equal to n for all 1 ≤ i ≤ m.
* For all 1 ≤ j ≤ n, a_j = b_{1, j} + b_{2, j}... | import sys
if sys.subversion[0] == "PyPy":
import io, atexit
sys.stdout = io.BytesIO()
atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))
sys.stdin = io.BytesIO(sys.stdin.read())
input = lambda: sys.stdin.readline().rstrip()
RS = raw_input
RI = lambda x=int: map(x,RS().split(... | 1Python2 | {
"input": [
"6\n4 1\n0 0 0 1\n3 1\n3 3 3\n11 3\n0 1 2 2 3 3 3 4 4 4 4\n5 3\n1 2 3 4 5\n9 4\n2 2 3 5 7 11 13 13 17\n10 7\n0 1 1 2 3 3 4 5 5 6\n",
"1\n3 2\n3 3 3\n",
"1\n3 3\n1 1 1\n",
"1\n5 5\n5 5 5 5 5\n",
"1\n5 3\n1 1 1 1 1\n",
"1\n5 2\n5 5 5 5 5\n",
"1\n2 2\n3 3\n",
"1\n4 2\n1 1 1 1... | 2CODEFORCES |
1408_B. Arrays Sum_3072 | You are given a non-decreasing array of non-negative integers a_1, a_2, …, a_n. Also you are given a positive integer k.
You want to find m non-decreasing arrays of non-negative integers b_1, b_2, …, b_m, such that:
* The size of b_i is equal to n for all 1 ≤ i ≤ m.
* For all 1 ≤ j ≤ n, a_j = b_{1, j} + b_{2, j}... | #include <bits/stdc++.h>
using namespace std;
int a[105], mark[105];
int main() {
int n, k, t;
cin >> t;
while (t--) {
cin >> n >> k;
int cnt = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (!mark[a[i]]) cnt++, mark[a[i]] = 1;
}
int ans = 0;
if (cnt <= k)
cout << 1 << ... | 2C++ | {
"input": [
"6\n4 1\n0 0 0 1\n3 1\n3 3 3\n11 3\n0 1 2 2 3 3 3 4 4 4 4\n5 3\n1 2 3 4 5\n9 4\n2 2 3 5 7 11 13 13 17\n10 7\n0 1 1 2 3 3 4 5 5 6\n",
"1\n3 2\n3 3 3\n",
"1\n3 3\n1 1 1\n",
"1\n5 5\n5 5 5 5 5\n",
"1\n5 3\n1 1 1 1 1\n",
"1\n5 2\n5 5 5 5 5\n",
"1\n2 2\n3 3\n",
"1\n4 2\n1 1 1 1... | 2CODEFORCES |
1408_B. Arrays Sum_3073 | You are given a non-decreasing array of non-negative integers a_1, a_2, …, a_n. Also you are given a positive integer k.
You want to find m non-decreasing arrays of non-negative integers b_1, b_2, …, b_m, such that:
* The size of b_i is equal to n for all 1 ≤ i ≤ m.
* For all 1 ≤ j ≤ n, a_j = b_{1, j} + b_{2, j}... | import sys as _sys
def main():
t = int(input())
for i_t in range(t):
n, k = _read_ints()
a = tuple(_read_ints())
try:
result = find_min_m(a, k)
except ValueError:
result = -1
print(result)
def _read_line():
result = _sys.stdin.readline()
... | 3Python3 | {
"input": [
"6\n4 1\n0 0 0 1\n3 1\n3 3 3\n11 3\n0 1 2 2 3 3 3 4 4 4 4\n5 3\n1 2 3 4 5\n9 4\n2 2 3 5 7 11 13 13 17\n10 7\n0 1 1 2 3 3 4 5 5 6\n",
"1\n3 2\n3 3 3\n",
"1\n3 3\n1 1 1\n",
"1\n5 5\n5 5 5 5 5\n",
"1\n5 3\n1 1 1 1 1\n",
"1\n5 2\n5 5 5 5 5\n",
"1\n2 2\n3 3\n",
"1\n4 2\n1 1 1 1... | 2CODEFORCES |
1408_B. Arrays Sum_3074 | You are given a non-decreasing array of non-negative integers a_1, a_2, …, a_n. Also you are given a positive integer k.
You want to find m non-decreasing arrays of non-negative integers b_1, b_2, …, b_m, such that:
* The size of b_i is equal to n for all 1 ≤ i ≤ m.
* For all 1 ≤ j ≤ n, a_j = b_{1, j} + b_{2, j}... | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int t =scanner.nextInt();
for (int i = 0; i < t; i++) {
int n=scanner.nextInt();
int k=scanner.nextInt();
int[] visit=new int[20... | 4JAVA | {
"input": [
"6\n4 1\n0 0 0 1\n3 1\n3 3 3\n11 3\n0 1 2 2 3 3 3 4 4 4 4\n5 3\n1 2 3 4 5\n9 4\n2 2 3 5 7 11 13 13 17\n10 7\n0 1 1 2 3 3 4 5 5 6\n",
"1\n3 2\n3 3 3\n",
"1\n3 3\n1 1 1\n",
"1\n5 5\n5 5 5 5 5\n",
"1\n5 3\n1 1 1 1 1\n",
"1\n5 2\n5 5 5 5 5\n",
"1\n2 2\n3 3\n",
"1\n4 2\n1 1 1 1... | 2CODEFORCES |
1428_E. Carrots for Rabbits_3075 | There are some rabbits in Singapore Zoo. To feed them, Zookeeper bought n carrots with lengths a_1, a_2, a_3, …, a_n. However, rabbits are very fertile and multiply very quickly. Zookeeper now has k rabbits and does not have enough carrots to feed all of them. To solve this problem, Zookeeper decided to cut the carrots... | from collections import Counter, defaultdict, deque
import bisect
import heapq
from sys import stdin, stdout
from itertools import repeat
import math
import random
# sys.stdin = open('input')
def mod(x, y, mod):
re = 1
now = x
while y:
if y&1:
re *= now
re %= mod
... | 1Python2 | {
"input": [
"1 4\n19\n",
"3 6\n5 3 1\n",
"10 23\n343 984 238 758983 231 74 231 548 893 543\n",
"1 1\n1\n",
"29 99047\n206580 305496 61753 908376 272137 803885 675070 665109 995787 667887 164508 634877 994427 270698 931765 721679 518973 65009 804367 608526 535640 117656 342804 398273 369209 298745... | 2CODEFORCES |
1428_E. Carrots for Rabbits_3076 | There are some rabbits in Singapore Zoo. To feed them, Zookeeper bought n carrots with lengths a_1, a_2, a_3, …, a_n. However, rabbits are very fertile and multiply very quickly. Zookeeper now has k rabbits and does not have enough carrots to feed all of them. To solve this problem, Zookeeper decided to cut the carrots... | #include <bits/stdc++.h>
struct Split {
int totSz;
int pcs;
};
using LL = long long;
LL cost(Split s) {
int q = s.totSz / s.pcs;
int r = s.totSz % s.pcs;
return 1LL * q * q * (s.pcs - r) + 1LL * (q + 1) * (q + 1) * r;
}
LL valNext(Split s) {
LL pc = cost(s);
++s.pcs;
assert(pc - cost(s) >= 0);
return ... | 2C++ | {
"input": [
"1 4\n19\n",
"3 6\n5 3 1\n",
"10 23\n343 984 238 758983 231 74 231 548 893 543\n",
"1 1\n1\n",
"29 99047\n206580 305496 61753 908376 272137 803885 675070 665109 995787 667887 164508 634877 994427 270698 931765 721679 518973 65009 804367 608526 535640 117656 342804 398273 369209 298745... | 2CODEFORCES |
1428_E. Carrots for Rabbits_3077 | There are some rabbits in Singapore Zoo. To feed them, Zookeeper bought n carrots with lengths a_1, a_2, a_3, …, a_n. However, rabbits are very fertile and multiply very quickly. Zookeeper now has k rabbits and does not have enough carrots to feed all of them. To solve this problem, Zookeeper decided to cut the carrots... | import sys
from heapq import heapify, heappush, heappop
def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c for j in range(b)] for i in range(a)]
def list3d(a, b, c, d): return [[[d for k in range(c)] for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e for l in ra... | 3Python3 | {
"input": [
"1 4\n19\n",
"3 6\n5 3 1\n",
"10 23\n343 984 238 758983 231 74 231 548 893 543\n",
"1 1\n1\n",
"29 99047\n206580 305496 61753 908376 272137 803885 675070 665109 995787 667887 164508 634877 994427 270698 931765 721679 518973 65009 804367 608526 535640 117656 342804 398273 369209 298745... | 2CODEFORCES |
1428_E. Carrots for Rabbits_3078 | There are some rabbits in Singapore Zoo. To feed them, Zookeeper bought n carrots with lengths a_1, a_2, a_3, …, a_n. However, rabbits are very fertile and multiply very quickly. Zookeeper now has k rabbits and does not have enough carrots to feed all of them. To solve this problem, Zookeeper decided to cut the carrots... | import java.util.*;
import java.io.*;
public class EdE {
static long num = 998244353;
public static void main(String[] args) throws Exception{
// TODO Auto-generated method stub
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
Stri... | 4JAVA | {
"input": [
"1 4\n19\n",
"3 6\n5 3 1\n",
"10 23\n343 984 238 758983 231 74 231 548 893 543\n",
"1 1\n1\n",
"29 99047\n206580 305496 61753 908376 272137 803885 675070 665109 995787 667887 164508 634877 994427 270698 931765 721679 518973 65009 804367 608526 535640 117656 342804 398273 369209 298745... | 2CODEFORCES |
1451_F. Nullify The Matrix_3079 | Jeel and Ashish play a game on an n × m matrix. The rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right. They play turn by turn. Ashish goes first.
Initially, each cell of the matrix contains a non-negative integer. Each turn, a player must perform all of the following ac... | from sys import stdin
t = int(stdin.readline())
for _ in xrange(t):
n,m = map(int,stdin.readline().split())
xor = [0] * (n+m+5)
for i in xrange(n):
a = map(int,stdin.readline().split())
for j in xrange(m):
xor[i+j] ^= a[j]
if sum(xor):
print "Ashish"
else:
... | 1Python2 | {
"input": [
"4\n1 1\n0\n1 3\n0 0 5\n2 2\n0 1\n1 0\n3 3\n1 2 3\n4 5 6\n7 8 9\n",
"3\n5 5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n4 4\n0 0 3 0\n0 2 0 0\n2 0 0 0\n0 0 0 0\n5 5\n0 3 4 5 0\n7 8 9 10 11\n12 13 14 15 16\n17 18 19 20 21\n0 22 23 24 0\n",
"5\n5 5\n0 126 30 105 44\n126 98 21 0 108\... | 2CODEFORCES |
1451_F. Nullify The Matrix_3080 | Jeel and Ashish play a game on an n × m matrix. The rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right. They play turn by turn. Ashish goes first.
Initially, each cell of the matrix contains a non-negative integer. Each turn, a player must perform all of the following ac... | #include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;
const int N = 1e6 + 10;
int a[200];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while(t--) {
memset(a, 0, sizeof(a));
int n... | 2C++ | {
"input": [
"4\n1 1\n0\n1 3\n0 0 5\n2 2\n0 1\n1 0\n3 3\n1 2 3\n4 5 6\n7 8 9\n",
"3\n5 5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n4 4\n0 0 3 0\n0 2 0 0\n2 0 0 0\n0 0 0 0\n5 5\n0 3 4 5 0\n7 8 9 10 11\n12 13 14 15 16\n17 18 19 20 21\n0 22 23 24 0\n",
"5\n5 5\n0 126 30 105 44\n126 98 21 0 108\... | 2CODEFORCES |
1451_F. Nullify The Matrix_3081 | Jeel and Ashish play a game on an n × m matrix. The rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right. They play turn by turn. Ashish goes first.
Initially, each cell of the matrix contains a non-negative integer. Each turn, a player must perform all of the following ac... | def solve_case():
n, m = [int(x) for x in input().split()]
a = [[int(x) for x in input().split()] for x in range(n)]
xr = [0] * (n + m)
for i in range(n):
for j in range(m):
xr[i + j] ^= a[i][j]
return sum(xr) > 0
def main():
for _ in range(int(input())):
print(['J... | 3Python3 | {
"input": [
"4\n1 1\n0\n1 3\n0 0 5\n2 2\n0 1\n1 0\n3 3\n1 2 3\n4 5 6\n7 8 9\n",
"3\n5 5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n4 4\n0 0 3 0\n0 2 0 0\n2 0 0 0\n0 0 0 0\n5 5\n0 3 4 5 0\n7 8 9 10 11\n12 13 14 15 16\n17 18 19 20 21\n0 22 23 24 0\n",
"5\n5 5\n0 126 30 105 44\n126 98 21 0 108\... | 2CODEFORCES |
1451_F. Nullify The Matrix_3082 | Jeel and Ashish play a game on an n × m matrix. The rows are numbered 1 to n from top to bottom and the columns are numbered 1 to m from left to right. They play turn by turn. Ashish goes first.
Initially, each cell of the matrix contains a non-negative integer. Each turn, a player must perform all of the following ac... | import java.util.*;
import java.io.*;
public class EdB {
static long[] mods = {1000000007, 998244353, 1000000009};
static long mod = mods[0];
public static MyScanner sc;
public static PrintWriter out;
public static void main(String[] omkar) throws Exception{
// TODO Auto-generated method stub
sc = new MySc... | 4JAVA | {
"input": [
"4\n1 1\n0\n1 3\n0 0 5\n2 2\n0 1\n1 0\n3 3\n1 2 3\n4 5 6\n7 8 9\n",
"3\n5 5\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n4 4\n0 0 3 0\n0 2 0 0\n2 0 0 0\n0 0 0 0\n5 5\n0 3 4 5 0\n7 8 9 10 11\n12 13 14 15 16\n17 18 19 20 21\n0 22 23 24 0\n",
"5\n5 5\n0 126 30 105 44\n126 98 21 0 108\... | 2CODEFORCES |
1475_E. Advertising Agency_3083 | Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of n different bloggers. Blogger numbered i has a_i followers.
Since Masha has a limited budget, she can only sign a contract with k different bloggers. Of course... | # Enter your code here. Read input from STDIN. Print output to STDOUT# ===============================================================================================
# importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import Byt... | 1Python2 | {
"input": [
"3\n4 3\n1 3 1 2\n4 2\n1 1 1 1\n2 1\n1 2\n",
"3\n4 3\n1 3 1 2\n4 2\n1 2 1 1\n2 1\n1 2\n",
"3\n4 3\n1 3 1 2\n4 2\n1 1 1 1\n2 1\n2 2\n",
"3\n4 3\n1 3 2 2\n4 2\n1 1 1 1\n2 1\n2 2\n",
"3\n4 3\n1 3 2 2\n4 2\n1 1 2 1\n2 1\n2 2\n",
"3\n4 3\n1 3 1 2\n4 2\n1 1 2 1\n2 1\n2 2\n",
"3\n4 3... | 2CODEFORCES |
1475_E. Advertising Agency_3084 | Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of n different bloggers. Blogger numbered i has a_i followers.
Since Masha has a limited budget, she can only sign a contract with k different bloggers. Of course... | #include <bits/stdc++.h>
#include <string>
#include <cmath>
using namespace std;
#define ll long long int
#define pb push_back
#define CR7 \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define pii pair<ll, ll>
#define MOD 1000000007
#define vi vector<ll>
#define vii ... | 2C++ | {
"input": [
"3\n4 3\n1 3 1 2\n4 2\n1 1 1 1\n2 1\n1 2\n",
"3\n4 3\n1 3 1 2\n4 2\n1 2 1 1\n2 1\n1 2\n",
"3\n4 3\n1 3 1 2\n4 2\n1 1 1 1\n2 1\n2 2\n",
"3\n4 3\n1 3 2 2\n4 2\n1 1 1 1\n2 1\n2 2\n",
"3\n4 3\n1 3 2 2\n4 2\n1 1 2 1\n2 1\n2 2\n",
"3\n4 3\n1 3 1 2\n4 2\n1 1 2 1\n2 1\n2 2\n",
"3\n4 3... | 2CODEFORCES |
1475_E. Advertising Agency_3085 | Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of n different bloggers. Blogger numbered i has a_i followers.
Since Masha has a limited budget, she can only sign a contract with k different bloggers. Of course... |
import math
def c (k, n):
return (math.factorial(n) // (math.factorial(k) * math.factorial(n - k))) % (10**9 + 7)
def solve():
n, k = map(int, input().split())
a = []
for i in input().split():
a.append(int(i))
a.sort()
m = dict()
for i in a:
if(m.get(i, 0) == 0): m[i]... | 3Python3 | {
"input": [
"3\n4 3\n1 3 1 2\n4 2\n1 1 1 1\n2 1\n1 2\n",
"3\n4 3\n1 3 1 2\n4 2\n1 2 1 1\n2 1\n1 2\n",
"3\n4 3\n1 3 1 2\n4 2\n1 1 1 1\n2 1\n2 2\n",
"3\n4 3\n1 3 2 2\n4 2\n1 1 1 1\n2 1\n2 2\n",
"3\n4 3\n1 3 2 2\n4 2\n1 1 2 1\n2 1\n2 2\n",
"3\n4 3\n1 3 1 2\n4 2\n1 1 2 1\n2 1\n2 2\n",
"3\n4 3... | 2CODEFORCES |
1475_E. Advertising Agency_3086 | Masha works in an advertising agency. In order to promote the new brand, she wants to conclude contracts with some bloggers. In total, Masha has connections of n different bloggers. Blogger numbered i has a_i followers.
Since Masha has a limited budget, she can only sign a contract with k different bloggers. Of course... | // 25-Jan-2021
import java.util.*;
import java.io.*;
public class E {
static class FastReader {
BufferedReader br;
StringTokenizer st;
private FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st ... | 4JAVA | {
"input": [
"3\n4 3\n1 3 1 2\n4 2\n1 1 1 1\n2 1\n1 2\n",
"3\n4 3\n1 3 1 2\n4 2\n1 2 1 1\n2 1\n1 2\n",
"3\n4 3\n1 3 1 2\n4 2\n1 1 1 1\n2 1\n2 2\n",
"3\n4 3\n1 3 2 2\n4 2\n1 1 1 1\n2 1\n2 2\n",
"3\n4 3\n1 3 2 2\n4 2\n1 1 2 1\n2 1\n2 2\n",
"3\n4 3\n1 3 1 2\n4 2\n1 1 2 1\n2 1\n2 2\n",
"3\n4 3... | 2CODEFORCES |
1500_C. Matrix Sorting_3087 | You are given two tables A and B of size n × m.
We define a sorting by column as the following: we choose a column and reorder the rows of the table by the value in this column, from the rows with the smallest value to the rows with the largest. In case there are two or more rows with equal value in this column, thei... | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> a(n, vector<int>(m));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) cin >> a[i][j];
}
vector<vector<int>> b(n, vector<i... | 2C++ | {
"input": [
"4 1\n2\n2\n2\n1\n1\n2\n2\n2\n",
"2 2\n2 2\n1 2\n1 2\n2 2\n",
"2 2\n1 1\n2 1\n2 1\n1 1\n",
"3 3\n2 3 2\n1 3 3\n1 1 2\n1 1 2\n1 3 3\n2 3 2\n",
"3 3\n3 1 3\n1 2 1\n2 3 2\n1 2 1\n2 3 2\n3 1 3\n",
"2 2\n1 1\n2 2\n1 1\n2 2\n",
"10 10\n3 3 2 2 4 3 1 1 6 4\n7 8 8 1 7 5 3 8 8 3\n10 2 ... | 2CODEFORCES |
1500_C. Matrix Sorting_3088 | You are given two tables A and B of size n × m.
We define a sorting by column as the following: we choose a column and reorder the rows of the table by the value in this column, from the rows with the smallest value to the rows with the largest. In case there are two or more rows with equal value in this column, thei... | //stan hu tao
//join nct ridin by first year culture reps
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.abs;
import static java.lang.System.out;
import java.util.*;
import java.io.*;
import java.math.*;
public class x1500C
{
public static void main(String hi[]) th... | 4JAVA | {
"input": [
"4 1\n2\n2\n2\n1\n1\n2\n2\n2\n",
"2 2\n2 2\n1 2\n1 2\n2 2\n",
"2 2\n1 1\n2 1\n2 1\n1 1\n",
"3 3\n2 3 2\n1 3 3\n1 1 2\n1 1 2\n1 3 3\n2 3 2\n",
"3 3\n3 1 3\n1 2 1\n2 3 2\n1 2 1\n2 3 2\n3 1 3\n",
"2 2\n1 1\n2 2\n1 1\n2 2\n",
"10 10\n3 3 2 2 4 3 1 1 6 4\n7 8 8 1 7 5 3 8 8 3\n10 2 ... | 2CODEFORCES |
1525_E. Assimilation IV_3089 | Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands.
Monocarp's empire has n cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monum... | # Enter your code here. Read input from STDIN. Print output to STDOUT# ===============================================================================================
# importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import Byt... | 1Python2 | {
"input": [
"3 5\n1 4 4 3 4\n1 4 1 4 2\n1 4 4 4 3\n",
"1 1\n1\n",
"1 1\n2\n",
"3 1\n1\n1\n1\n",
"3 1\n1\n1\n2\n",
"3 5\n1 4 4 3 4\n1 4 2 4 2\n1 4 4 4 3\n",
"3 5\n1 4 4 3 4\n1 4 2 4 2\n1 3 4 4 3\n",
"3 5\n1 4 4 3 4\n1 4 2 4 2\n1 3 4 4 4\n",
"3 5\n1 4 4 3 4\n1 1 2 4 2\n1 3 4 4 4\n",... | 2CODEFORCES |
1525_E. Assimilation IV_3090 | Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands.
Monocarp's empire has n cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monum... | #include<bits/stdc++.h>
using namespace std;
const int nn =5100;
const int inff = 0x3fffffff;
const double eps = 1e-8;
typedef long long LL;
const double pi = acos(-1.0);
const LL mod = 998244353;
int n,m;
LL POW(LL x,LL y)
{
LL ret=1;
while(y)
{
if(y&1)
ret=(ret*x)%mod;
x=(x*x)... | 2C++ | {
"input": [
"3 5\n1 4 4 3 4\n1 4 1 4 2\n1 4 4 4 3\n",
"1 1\n1\n",
"1 1\n2\n",
"3 1\n1\n1\n1\n",
"3 1\n1\n1\n2\n",
"3 5\n1 4 4 3 4\n1 4 2 4 2\n1 4 4 4 3\n",
"3 5\n1 4 4 3 4\n1 4 2 4 2\n1 3 4 4 3\n",
"3 5\n1 4 4 3 4\n1 4 2 4 2\n1 3 4 4 4\n",
"3 5\n1 4 4 3 4\n1 1 2 4 2\n1 3 4 4 4\n",... | 2CODEFORCES |
1525_E. Assimilation IV_3091 | Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands.
Monocarp's empire has n cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monum... | ans = 0
n,m = map(int,input().split())
mod = 998244353
a = [list(map(int,input().split())) for i in range(n)]
fac = 1
for i in range(1,n+1): fac *= i
inv = pow(fac,mod-2,mod)
for j in range(m):
na = sorted([a[i][j] for i in range(n)])
now = 1
able = 0
for i in range(n):
while len(na) > 0... | 3Python3 | {
"input": [
"3 5\n1 4 4 3 4\n1 4 1 4 2\n1 4 4 4 3\n",
"1 1\n1\n",
"1 1\n2\n",
"3 1\n1\n1\n1\n",
"3 1\n1\n1\n2\n",
"3 5\n1 4 4 3 4\n1 4 2 4 2\n1 4 4 4 3\n",
"3 5\n1 4 4 3 4\n1 4 2 4 2\n1 3 4 4 3\n",
"3 5\n1 4 4 3 4\n1 4 2 4 2\n1 3 4 4 4\n",
"3 5\n1 4 4 3 4\n1 1 2 4 2\n1 3 4 4 4\n",... | 2CODEFORCES |
1525_E. Assimilation IV_3092 | Monocarp is playing a game "Assimilation IV". In this game he manages a great empire: builds cities and conquers new lands.
Monocarp's empire has n cities. In order to conquer new lands he plans to build one Monument in each city. The game is turn-based and, since Monocarp is still amateur, he builds exactly one Monum... | import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.List;
import java.util.*;
public class realfast implements Runnable
{
private static final int INF = (int) 1e9;
long in= 998244353;
long fac[]= new long[1000001];
long inv[]=new... | 4JAVA | {
"input": [
"3 5\n1 4 4 3 4\n1 4 1 4 2\n1 4 4 4 3\n",
"1 1\n1\n",
"1 1\n2\n",
"3 1\n1\n1\n1\n",
"3 1\n1\n1\n2\n",
"3 5\n1 4 4 3 4\n1 4 2 4 2\n1 4 4 4 3\n",
"3 5\n1 4 4 3 4\n1 4 2 4 2\n1 3 4 4 3\n",
"3 5\n1 4 4 3 4\n1 4 2 4 2\n1 3 4 4 4\n",
"3 5\n1 4 4 3 4\n1 1 2 4 2\n1 3 4 4 4\n",... | 2CODEFORCES |
157_B. Trace_3093 | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides,... | import math
n=input()
N=map(int,raw_input().split())
N.insert(0,0)
N=sorted(N,reverse=True)
S=0
for i in range((n+1)/2):
S-=(N[2*i+1]**2-N[2*i]**2)*math.pi
print '%.15f'%S
| 1Python2 | {
"input": [
"1\n1\n",
"3\n1 4 2\n",
"6\n258 877 696 425 663 934\n",
"37\n280 281 169 68 249 389 977 101 360 43 448 447 368 496 125 507 747 392 338 270 916 150 929 428 118 266 589 470 774 852 263 644 187 817 808 58 637\n",
"100\n469 399 735 925 62 153 707 723 819 529 200 624 57 708 245 384 889 11 ... | 2CODEFORCES |
157_B. Trace_3094 | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides,... | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k, i, j, p, cnt = 2, ans = 0, m, l, r = 0;
long double pi = 3.1415926536;
cin >> n;
vector<int> a;
for (i = 0; i < n; i++) {
cin >> p;
a.push_back(p);
}
a.push_back(0);
sort(a.begin(), a.end());
for (i = n; i > 0; i -=... | 2C++ | {
"input": [
"1\n1\n",
"3\n1 4 2\n",
"6\n258 877 696 425 663 934\n",
"37\n280 281 169 68 249 389 977 101 360 43 448 447 368 496 125 507 747 392 338 270 916 150 929 428 118 266 589 470 774 852 263 644 187 817 808 58 637\n",
"100\n469 399 735 925 62 153 707 723 819 529 200 624 57 708 245 384 889 11 ... | 2CODEFORCES |
157_B. Trace_3095 | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides,... | n=int(input())
s=0
X=[int(x) for x in input().split(" ")]
X.sort(reverse=True)
for i in range(n):
s=s+(-1)**(i)*X[i]*X[i]
print(3.1415926536*s) | 3Python3 | {
"input": [
"1\n1\n",
"3\n1 4 2\n",
"6\n258 877 696 425 663 934\n",
"37\n280 281 169 68 249 389 977 101 360 43 448 447 368 496 125 507 747 392 338 270 916 150 929 428 118 266 589 470 774 852 263 644 187 817 808 58 637\n",
"100\n469 399 735 925 62 153 707 723 819 529 200 624 57 708 245 384 889 11 ... | 2CODEFORCES |
157_B. Trace_3096 | One day, as Sherlock Holmes was tracking down one very important criminal, he found a wonderful painting on the wall. This wall could be represented as a plane. The painting had several concentric circles that divided the wall into several parts. Some parts were painted red and all the other were painted blue. Besides,... | import static java.lang.Math.*;
import static java.util.Arrays.* ;
import java.util.*;
import java.io.*;
public class D
{
void main() throws Exception
{
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n =sc.nextInt() ;
int [] a = new int ... | 4JAVA | {
"input": [
"1\n1\n",
"3\n1 4 2\n",
"6\n258 877 696 425 663 934\n",
"37\n280 281 169 68 249 389 977 101 360 43 448 447 368 496 125 507 747 392 338 270 916 150 929 428 118 266 589 470 774 852 263 644 187 817 808 58 637\n",
"100\n469 399 735 925 62 153 707 723 819 529 200 624 57 708 245 384 889 11 ... | 2CODEFORCES |
178_A2. Educational Game_3097 | The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below.
The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game is to make numbers a1, a2, ..., ak (i.e. some prefix of the sequenc... | n=input()
a=map(int,raw_input().split())
s,k=0,[0]*(n-1)
for i in xrange(n-1):
if a[i]:
t=1
while i+(t<<1)<n:t<<=1
s+=a[i]
a[i+t]+=a[i]
k[i]=s
for x in k:print x
| 1Python2 | {
"input": [
"8\n1 2 3 4 5 6 7 8\n",
"4\n1 0 1 2\n",
"9\n13 13 7 11 3 9 3 5 5\n",
"80\n72 66 82 46 44 22 63 92 71 65 5 30 45 84 29 73 9 90 25 19 26 15 12 29 33 19 85 92 91 66 83 39 100 53 20 99 11 81 26 41 36 51 21 72 28 100 34 3 24 58 11 85 73 18 4 45 90 99 42 85 26 71 58 49 76 32 88 13 40 98 57 95 2... | 2CODEFORCES |
178_A2. Educational Game_3098 | The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below.
The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game is to make numbers a1, a2, ..., ak (i.e. some prefix of the sequenc... | #include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, x, p, q, y, m, k, ans = 0;
cin >> n;
vector<long long> a;
for (long long i = 0; i < n; i++) cin >> x, a.push_back(x);
for (long long i = 0; i < n - 1; i++) {
if (a[i] != 0) ans += a[i];
long long j = 1;
while (i + j < n) j =... | 2C++ | {
"input": [
"8\n1 2 3 4 5 6 7 8\n",
"4\n1 0 1 2\n",
"9\n13 13 7 11 3 9 3 5 5\n",
"80\n72 66 82 46 44 22 63 92 71 65 5 30 45 84 29 73 9 90 25 19 26 15 12 29 33 19 85 92 91 66 83 39 100 53 20 99 11 81 26 41 36 51 21 72 28 100 34 3 24 58 11 85 73 18 4 45 90 99 42 85 26 71 58 49 76 32 88 13 40 98 57 95 2... | 2CODEFORCES |
178_A2. Educational Game_3099 | The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below.
The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game is to make numbers a1, a2, ..., ak (i.e. some prefix of the sequenc... | from math import log
n=int(input())
s=list(map(int,input().split( )))
p=[]
for i in range(0,n-1):
m=(log(n-1-i,2))//1
p.append(i+2**m)
for k in range(1,n):
g=0
f=s[:]
for i in range(0,k):
g+=f[i]
f[int(p[i])]+=f[i]
print(g)
| 3Python3 | {
"input": [
"8\n1 2 3 4 5 6 7 8\n",
"4\n1 0 1 2\n",
"9\n13 13 7 11 3 9 3 5 5\n",
"80\n72 66 82 46 44 22 63 92 71 65 5 30 45 84 29 73 9 90 25 19 26 15 12 29 33 19 85 92 91 66 83 39 100 53 20 99 11 81 26 41 36 51 21 72 28 100 34 3 24 58 11 85 73 18 4 45 90 99 42 85 26 71 58 49 76 32 88 13 40 98 57 95 2... | 2CODEFORCES |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.