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 |
|---|---|---|---|---|---|
1025_B. Weakened Common Divisor_2700 | During the research on properties of the greatest common divisor (GCD) of a set of numbers, Ildar, a famous mathematician, introduced a brand new concept of the weakened common divisor (WCD) of a list of pairs of integers.
For a given list of pairs of integers (a_1, b_1), (a_2, b_2), ..., (a_n, b_n) their WCD is arbit... | def gcd(a,b):
if a%b==0:
return b
else:
return gcd(b,a%b)
import math
def pr(n):
a=[]
while n % 2 == 0:
a.append(2)
n = n / 2
for i in range(3,int(math.sqrt(n))+1,2):
while n % i== 0:
a.append(i)
n = n /... | 3Python3 | {
"input": [
"2\n10 16\n7 17\n",
"3\n17 18\n15 24\n12 15\n",
"5\n90 108\n45 105\n75 40\n165 175\n33 30\n",
"3\n14 14\n2 7\n2 2\n",
"30\n3 3\n2 2\n4 4\n8 8\n16 16\n32 32\n64 64\n128 128\n256 256\n512 512\n1024 1024\n2048 2048\n4096 4096\n8192 8192\n16384 16384\n32768 32768\n65536 65536\n131072 1310... | 2CODEFORCES |
1025_B. Weakened Common Divisor_2701 | During the research on properties of the greatest common divisor (GCD) of a set of numbers, Ildar, a famous mathematician, introduced a brand new concept of the weakened common divisor (WCD) of a list of pairs of integers.
For a given list of pairs of integers (a_1, b_1), (a_2, b_2), ..., (a_n, b_n) their WCD is arbit... | import java.util.*;
import java.util.stream.*;
import java.io.*;
import java.math.*;
public class Main {
static boolean FROM_FILE = false;
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
if (FROM_FILE) {
t... | 4JAVA | {
"input": [
"2\n10 16\n7 17\n",
"3\n17 18\n15 24\n12 15\n",
"5\n90 108\n45 105\n75 40\n165 175\n33 30\n",
"3\n14 14\n2 7\n2 2\n",
"30\n3 3\n2 2\n4 4\n8 8\n16 16\n32 32\n64 64\n128 128\n256 256\n512 512\n1024 1024\n2048 2048\n4096 4096\n8192 8192\n16384 16384\n32768 32768\n65536 65536\n131072 1310... | 2CODEFORCES |
1045_D. Interstellar battle_2702 | In the intergalactic empire Bubbledom there are N planets, of which some pairs are directly connected by two-way wormholes. There are N-1 wormholes. The wormholes are of extreme religious importance in Bubbledom, a set of planets in Bubbledom consider themselves one intergalactic kingdom if and only if any two planets ... | #include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n;
double p[N];
vector<int> adj[N];
int par[N];
double sum[N];
void dfs(int u, int pa) {
par[u] = pa;
for (int v : adj[u]) {
if (v == pa) {
continue;
}
dfs(v, u);
sum[u] += (1. - p[v]);
}
}
double preCalc() {
double re... | 2C++ | {
"input": [
"5\n0.50 0.29 0.49 0.95 0.83\n2 3\n0 3\n3 4\n2 1\n3\n4 0.66\n1 0.69\n0 0.36\n",
"1\n0.28\n30\n0 0.72\n0 0.55\n0 0.80\n0 0.26\n0 0.51\n0 0.28\n0 0.24\n0 0.59\n0 0.72\n0 0.35\n0 0.52\n0 1.00\n0 0.01\n0 0.37\n0 0.42\n0 0.60\n0 0.51\n0 0.73\n0 0.74\n0 0.92\n0 0.45\n0 0.81\n0 0.33\n0 0.20\n0 1.00\n0 0... | 2CODEFORCES |
1045_D. Interstellar battle_2703 | In the intergalactic empire Bubbledom there are N planets, of which some pairs are directly connected by two-way wormholes. There are N-1 wormholes. The wormholes are of extreme religious importance in Bubbledom, a set of planets in Bubbledom consider themselves one intergalactic kingdom if and only if any two planets ... | import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
@SuppressWarnings("unchecked")
public class D1045 {
int n;
ArrayList<Integer>[] vs;
double[] p;
int[] par;
double[] childSum;
... | 4JAVA | {
"input": [
"5\n0.50 0.29 0.49 0.95 0.83\n2 3\n0 3\n3 4\n2 1\n3\n4 0.66\n1 0.69\n0 0.36\n",
"1\n0.28\n30\n0 0.72\n0 0.55\n0 0.80\n0 0.26\n0 0.51\n0 0.28\n0 0.24\n0 0.59\n0 0.72\n0 0.35\n0 0.52\n0 1.00\n0 0.01\n0 0.37\n0 0.42\n0 0.60\n0 0.51\n0 0.73\n0 0.74\n0 0.92\n0 0.45\n0 0.81\n0 0.33\n0 0.20\n0 1.00\n0 0... | 2CODEFORCES |
1068_D. Array Without Local Maximums _2704 | Ivan unexpectedly saw a present from one of his previous birthdays. It is array of n numbers from 1 to 200. Array is old and some numbers are hard to read. Ivan remembers that for all elements at least one of its neighbours ls not less than it, more formally:
a_{1} ≤ a_{2},
a_{n} ≤ a_{n-1} and
a_{i} ≤ max(a_{i-1}, ... | import os
from io import BytesIO
range = xrange
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
MOD = 998244353
MODF = 1.0*MOD
from math import trunc
def quickmod(a):
return a-MODF*trunc(a/MODF)
def main():
n = int(input())
a = [int(i) for i in input().split()]
f0, f1 = [1.0] * 201, [0.0] ... | 1Python2 | {
"input": [
"3\n1 -1 2\n",
"2\n-1 -1\n",
"8\n-1 -1 -1 59 -1 -1 -1 -1\n",
"2\n38 38\n",
"2\n-1 35\n",
"3\n-1 200 -1\n",
"2\n24 -1\n",
"37\n52 52 66 149 149 130 47 47 26 110 185 -1 73 73 65 -1 -1 130 -1 -1 -1 94 97 190 -1 -1 49 49 54 -1 92 92 5 25 48 79 79\n",
"5\n1 3 4 1 1\n",
... | 2CODEFORCES |
1068_D. Array Without Local Maximums _2705 | Ivan unexpectedly saw a present from one of his previous birthdays. It is array of n numbers from 1 to 200. Array is old and some numbers are hard to read. Ivan remembers that for all elements at least one of its neighbours ls not less than it, more formally:
a_{1} ≤ a_{2},
a_{n} ≤ a_{n-1} and
a_{i} ≤ max(a_{i-1}, ... | #include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5, inf = 1e18, mod = 998244353;
long long n, dp[2][202][2], ps[2][202][2], a[N], PS[2][202][2];
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
dp[0][0][1] = 1;
for (long long j = 0; j <= 200; j++) ps[0][j][1] = 1;
cin >> n;
... | 2C++ | {
"input": [
"3\n1 -1 2\n",
"2\n-1 -1\n",
"8\n-1 -1 -1 59 -1 -1 -1 -1\n",
"2\n38 38\n",
"2\n-1 35\n",
"3\n-1 200 -1\n",
"2\n24 -1\n",
"37\n52 52 66 149 149 130 47 47 26 110 185 -1 73 73 65 -1 -1 130 -1 -1 -1 94 97 190 -1 -1 49 49 54 -1 92 92 5 25 48 79 79\n",
"5\n1 3 4 1 1\n",
... | 2CODEFORCES |
1068_D. Array Without Local Maximums _2706 | Ivan unexpectedly saw a present from one of his previous birthdays. It is array of n numbers from 1 to 200. Array is old and some numbers are hard to read. Ivan remembers that for all elements at least one of its neighbours ls not less than it, more formally:
a_{1} ≤ a_{2},
a_{n} ≤ a_{n-1} and
a_{i} ≤ max(a_{i-1}, ... | import os
from io import BytesIO
from math import trunc
if os.name == 'nt':
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
MX = 201
MOD = 998244353
MODF = float(MOD)
MODF_inv = 1.0 / MODF
quickmod1 = lambda x: x - MODF * trunc(x / MODF)
def quickmod(a):
return a - MODF * trunc(a * MODF_inv)
de... | 3Python3 | {
"input": [
"3\n1 -1 2\n",
"2\n-1 -1\n",
"8\n-1 -1 -1 59 -1 -1 -1 -1\n",
"2\n38 38\n",
"2\n-1 35\n",
"3\n-1 200 -1\n",
"2\n24 -1\n",
"37\n52 52 66 149 149 130 47 47 26 110 185 -1 73 73 65 -1 -1 130 -1 -1 -1 94 97 190 -1 -1 49 49 54 -1 92 92 5 25 48 79 79\n",
"5\n1 3 4 1 1\n",
... | 2CODEFORCES |
1068_D. Array Without Local Maximums _2707 | Ivan unexpectedly saw a present from one of his previous birthdays. It is array of n numbers from 1 to 200. Array is old and some numbers are hard to read. Ivan remembers that for all elements at least one of its neighbours ls not less than it, more formally:
a_{1} ≤ a_{2},
a_{n} ≤ a_{n-1} and
a_{i} ≤ max(a_{i-1}, ... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual soluti... | 4JAVA | {
"input": [
"3\n1 -1 2\n",
"2\n-1 -1\n",
"8\n-1 -1 -1 59 -1 -1 -1 -1\n",
"2\n38 38\n",
"2\n-1 35\n",
"3\n-1 200 -1\n",
"2\n24 -1\n",
"37\n52 52 66 149 149 130 47 47 26 110 185 -1 73 73 65 -1 -1 130 -1 -1 -1 94 97 190 -1 -1 49 49 54 -1 92 92 5 25 48 79 79\n",
"5\n1 3 4 1 1\n",
... | 2CODEFORCES |
1090_C. New Year Presents_2708 | Santa has prepared boxes with presents for n kids, one box for each kid. There are m kinds of presents: balloons, sweets, chocolate bars, toy cars... A child would be disappointed to receive two presents of the same kind, so all kinds of presents in one box are distinct.
Having packed all the presents, Santa realized ... | n, m = map(int, raw_input().split())
a = []
u = [{} for i in xrange(n)]
k = 0
for i in xrange(n):
s = map(int, raw_input().split())
a.append([s[0], i])
for x in s[1:]: u[i][x] = 1
k += s[0]
a = sorted(a)
h = n - (k % n)
k = k / n
wi = 0
w = [() for i in xrange(10 ** 6)]
for i in xrange(n):
if a[i]... | 1Python2 | {
"input": [
"3 5\n5 1 2 3 4 5\n2 1 2\n2 3 4\n",
"1 1\n0\n",
"1 1\n1 1\n",
"4 11\n10 1 11 4 6 9 2 3 10 5 8\n0\n1 3\n9 6 5 2 9 10 4 1 7 8\n",
"2 1\n0\n1 1\n",
"4 50\n9 26 13 12 16 39 37 42 11 18\n42 4 39 19 29 44 30 5 43 28 38 22 2 33 9 50 13 25 37 45 32 27 1 48 35 11 36 42 26 49 40 8 34 7 12 2... | 2CODEFORCES |
1090_C. New Year Presents_2709 | Santa has prepared boxes with presents for n kids, one box for each kid. There are m kinds of presents: balloons, sweets, chocolate bars, toy cars... A child would be disappointed to receive two presents of the same kind, so all kinds of presents in one box are distinct.
Having packed all the presents, Santa realized ... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
pair<int, int> qq[maxn];
int q[maxn], s, o[maxn];
set<int> w[maxn], z;
vector<pair<pair<int, int>, int> > r;
int main() {
int n, m, a, b, qa, qb;
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < n... | 2C++ | {
"input": [
"3 5\n5 1 2 3 4 5\n2 1 2\n2 3 4\n",
"1 1\n0\n",
"1 1\n1 1\n",
"4 11\n10 1 11 4 6 9 2 3 10 5 8\n0\n1 3\n9 6 5 2 9 10 4 1 7 8\n",
"2 1\n0\n1 1\n",
"4 50\n9 26 13 12 16 39 37 42 11 18\n42 4 39 19 29 44 30 5 43 28 38 22 2 33 9 50 13 25 37 45 32 27 1 48 35 11 36 42 26 49 40 8 34 7 12 2... | 2CODEFORCES |
1090_C. New Year Presents_2710 | Santa has prepared boxes with presents for n kids, one box for each kid. There are m kinds of presents: balloons, sweets, chocolate bars, toy cars... A child would be disappointed to receive two presents of the same kind, so all kinds of presents in one box are distinct.
Having packed all the presents, Santa realized ... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Iterator;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.TreeSet;
... | 4JAVA | {
"input": [
"3 5\n5 1 2 3 4 5\n2 1 2\n2 3 4\n",
"1 1\n0\n",
"1 1\n1 1\n",
"4 11\n10 1 11 4 6 9 2 3 10 5 8\n0\n1 3\n9 6 5 2 9 10 4 1 7 8\n",
"2 1\n0\n1 1\n",
"4 50\n9 26 13 12 16 39 37 42 11 18\n42 4 39 19 29 44 30 5 43 28 38 22 2 33 9 50 13 25 37 45 32 27 1 48 35 11 36 42 26 49 40 8 34 7 12 2... | 2CODEFORCES |
1109_F. Sasha and Algorithm of Silence's Sounds_2711 | One fine day Sasha went to the park for a walk. In the park, he saw that his favorite bench is occupied, and he had to sit down on the neighboring one. He sat down and began to listen to the silence. Suddenly, he got a question: what if in different parts of the park, the silence sounds in different ways? So it was. Le... | #include <bits/stdc++.h>
using namespace std;
const int N = 1000005;
namespace LCT {
struct TNode {
int ch[2], f;
bool r;
};
TNode t[N];
inline bool isroot(int pos) {
return t[t[pos].f].ch[0] != pos && t[t[pos].f].ch[1] != pos;
}
inline void pushdown(int pos) {
if (t[pos].r) {
t[pos].r = 0;
t[t[pos].ch[... | 2C++ | {
"input": [
"4 4\n4 3 2 16\n1 13 14 15\n5 7 8 12\n6 11 9 10\n",
"2 3\n1 2 3\n4 5 6\n",
"1 5\n1 2 3 4 5\n",
"1 1\n1\n",
"1 5\n2 1 3 4 5\n",
"1 1\n1 2 3 4 5\n",
"1 2\n1 2 3 4 2\n",
"4 1\n1 2 3 4 2\n",
"3 1\n1 2 3 4 2\n",
"1 1\n1 2 3 4 2\n",
"2 1\n1 2 3 4 2\n",
"1 2\n1 2 ... | 2CODEFORCES |
1109_F. Sasha and Algorithm of Silence's Sounds_2712 | One fine day Sasha went to the park for a walk. In the park, he saw that his favorite bench is occupied, and he had to sit down on the neighboring one. He sat down and began to listen to the silence. Suddenly, he got a question: what if in different parts of the park, the silence sounds in different ways? So it was. Le... | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
OutputWriter out = new OutputWriter(System.out);
TaskD solver = new TaskD(in, out);
solver.solve();
out.close();
}
sta... | 4JAVA | {
"input": [
"4 4\n4 3 2 16\n1 13 14 15\n5 7 8 12\n6 11 9 10\n",
"2 3\n1 2 3\n4 5 6\n",
"1 5\n1 2 3 4 5\n",
"1 1\n1\n",
"1 5\n2 1 3 4 5\n",
"1 1\n1 2 3 4 5\n",
"1 2\n1 2 3 4 2\n",
"4 1\n1 2 3 4 2\n",
"3 1\n1 2 3 4 2\n",
"1 1\n1 2 3 4 2\n",
"2 1\n1 2 3 4 2\n",
"1 2\n1 2 ... | 2CODEFORCES |
1139_C. Edgy Trees_2713 | You are given a tree (a connected undirected graph without cycles) of n vertices. Each of the n - 1 edges of the tree is colored in either black or red.
You are also given an integer k. Consider sequences of k vertices. Let's call a sequence [a_1, a_2, …, a_k] good if it satisfies the following criterion:
* We will... | mod = 10**9 + 7
nk = map(int, raw_input().strip().split())
n = nk[0]
k = nk[1]
parent = [0] * (n+1)
rank = [0] * (n +1)
for i in range(1, n+1):
parent[i] = i
rank[i] = 1
for i in range(n-1):
abc = map(int, raw_input().strip().split())
if abc[2] == 1:
continue
def find(node):
while(parent[node]... | 1Python2 | {
"input": [
"4 4\n1 2 1\n2 3 1\n3 4 1\n",
"4 6\n1 2 0\n1 3 0\n1 4 0\n",
"3 5\n1 2 1\n2 3 0\n",
"4 19\n2 4 1\n2 3 0\n1 4 0\n",
"13 3\n9 13 1\n8 3 1\n11 9 0\n8 13 0\n10 9 0\n2 7 0\n4 8 1\n11 5 0\n10 12 0\n12 1 1\n5 7 0\n6 8 1\n",
"2 20\n2 1 0\n",
"7 12\n4 5 0\n2 7 1\n7 6 1\n2 5 0\n2 3 0\n1 ... | 2CODEFORCES |
1139_C. Edgy Trees_2714 | You are given a tree (a connected undirected graph without cycles) of n vertices. Each of the n - 1 edges of the tree is colored in either black or red.
You are also given an integer k. Consider sequences of k vertices. Let's call a sequence [a_1, a_2, …, a_k] good if it satisfies the following criterion:
* We will... | #include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
vector<vector<int> > v(100001);
vector<int> vis(100001);
long long binpow(long long a, long long b) {
long long res = 1;
while (b > 0) {
if (b & 1) res = (res * a) % mod;
a = (a * a) % mod;
b >>= 1;
}
return res % mod;
}
int d... | 2C++ | {
"input": [
"4 4\n1 2 1\n2 3 1\n3 4 1\n",
"4 6\n1 2 0\n1 3 0\n1 4 0\n",
"3 5\n1 2 1\n2 3 0\n",
"4 19\n2 4 1\n2 3 0\n1 4 0\n",
"13 3\n9 13 1\n8 3 1\n11 9 0\n8 13 0\n10 9 0\n2 7 0\n4 8 1\n11 5 0\n10 12 0\n12 1 1\n5 7 0\n6 8 1\n",
"2 20\n2 1 0\n",
"7 12\n4 5 0\n2 7 1\n7 6 1\n2 5 0\n2 3 0\n1 ... | 2CODEFORCES |
1139_C. Edgy Trees_2715 | You are given a tree (a connected undirected graph without cycles) of n vertices. Each of the n - 1 edges of the tree is colored in either black or red.
You are also given an integer k. Consider sequences of k vertices. Let's call a sequence [a_1, a_2, …, a_k] good if it satisfies the following criterion:
* We will... | kk=lambda:map(int,input().split())
ll=lambda:list(kk())
n, k = kk()
dsud = {i:{i} for i in range(n)}
dsup = {i:i for i in range(n)}
for _ in range(n-1):
u, v, xi = kk()
u,v = u-1,v-1
if xi == 0:
s1, s2 = dsud[dsup[u]], dsud[dsup[v]]
if len(s1) > len(s2):
s1 |= s2
del dsud[dsup[v]]
for el in s2:
dsup... | 3Python3 | {
"input": [
"4 4\n1 2 1\n2 3 1\n3 4 1\n",
"4 6\n1 2 0\n1 3 0\n1 4 0\n",
"3 5\n1 2 1\n2 3 0\n",
"4 19\n2 4 1\n2 3 0\n1 4 0\n",
"13 3\n9 13 1\n8 3 1\n11 9 0\n8 13 0\n10 9 0\n2 7 0\n4 8 1\n11 5 0\n10 12 0\n12 1 1\n5 7 0\n6 8 1\n",
"2 20\n2 1 0\n",
"7 12\n4 5 0\n2 7 1\n7 6 1\n2 5 0\n2 3 0\n1 ... | 2CODEFORCES |
1139_C. Edgy Trees_2716 | You are given a tree (a connected undirected graph without cycles) of n vertices. Each of the n - 1 edges of the tree is colored in either black or red.
You are also given an integer k. Consider sequences of k vertices. Let's call a sequence [a_1, a_2, …, a_k] good if it satisfies the following criterion:
* We will... | import java.io.*;
import java.util.*;
public class Main {
static int time=0;
static int count=0;
public static void main(String args[])
{
FastReader input=new FastReader();
PrintWriter out=new PrintWriter(System.out);
int T=1;
while(T-->0)
{
int n=inpu... | 4JAVA | {
"input": [
"4 4\n1 2 1\n2 3 1\n3 4 1\n",
"4 6\n1 2 0\n1 3 0\n1 4 0\n",
"3 5\n1 2 1\n2 3 0\n",
"4 19\n2 4 1\n2 3 0\n1 4 0\n",
"13 3\n9 13 1\n8 3 1\n11 9 0\n8 13 0\n10 9 0\n2 7 0\n4 8 1\n11 5 0\n10 12 0\n12 1 1\n5 7 0\n6 8 1\n",
"2 20\n2 1 0\n",
"7 12\n4 5 0\n2 7 1\n7 6 1\n2 5 0\n2 3 0\n1 ... | 2CODEFORCES |
1157_C2. Increasing Subsequence (hard version)_2717 | The only difference between problems C1 and C2 is that all values in input of problem C1 are distinct (this condition may be false for problem C2).
You are given a sequence a consisting of n integers.
You are making a sequence of moves. During each move you must take either the leftmost element of the sequence or the... | import decimal,math
from collections import Counter,defaultdict
from fractions import gcd
decimal.getcontext().prec = 100
def divisors(n) :
abc=[]
i = 1
while i <= math.sqrt(n):
if (n % i == 0) :
if (n / i == i) :
abc.append(i)
else :
abc.append(i)
abc.append(n/i)
i = i + 1
ab... | 1Python2 | {
"input": [
"7\n1 3 5 6 5 4 2\n",
"5\n1 2 4 3 2\n",
"4\n1 2 4 3\n",
"3\n2 2 2\n",
"20\n2 2 2 1 1 3 1 3 3 1 2 3 3 3 2 2 2 3 1 3\n",
"17\n3 3 2 3 2 3 1 2 3 2 2 3 1 3 1 2 1\n",
"12\n3 3 2 3 2 3 1 2 1 2 2 1\n",
"18\n2 3 3 3 1 2 2 1 3 3 2 3 1 3 1 2 2 2\n",
"3\n3 1 1\n",
"5\n2 1 3 4... | 2CODEFORCES |
1157_C2. Increasing Subsequence (hard version)_2718 | The only difference between problems C1 and C2 is that all values in input of problem C1 are distinct (this condition may be false for problem C2).
You are given a sequence a consisting of n integers.
You are making a sequence of moves. During each move you must take either the leftmost element of the sequence or the... | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int i, c = 0, n, T, cs = 0, k, x, j;
T = 1;
string s = "";
while (T--) {
cin >> n;
long long int a[n];
for (i = 0; i < n; i++) cin >> a[i];
i = n - 1;
j = 0;
c = 0;
while (i >= j) {
if (a[i] == a[j] && i != j)... | 2C++ | {
"input": [
"7\n1 3 5 6 5 4 2\n",
"5\n1 2 4 3 2\n",
"4\n1 2 4 3\n",
"3\n2 2 2\n",
"20\n2 2 2 1 1 3 1 3 3 1 2 3 3 3 2 2 2 3 1 3\n",
"17\n3 3 2 3 2 3 1 2 3 2 2 3 1 3 1 2 1\n",
"12\n3 3 2 3 2 3 1 2 1 2 2 1\n",
"18\n2 3 3 3 1 2 2 1 3 3 2 3 1 3 1 2 2 2\n",
"3\n3 1 1\n",
"5\n2 1 3 4... | 2CODEFORCES |
1157_C2. Increasing Subsequence (hard version)_2719 | The only difference between problems C1 and C2 is that all values in input of problem C1 are distinct (this condition may be false for problem C2).
You are given a sequence a consisting of n integers.
You are making a sequence of moves. During each move you must take either the leftmost element of the sequence or the... |
import sys
sys.setrecursionlimit(10**7)
N = int(input())
number = list(map(int, input().split()))
seq = []
ans = []
l = 0
r = N-1
def correct(ans, l, r, action):
for i in range(len(ans)-1, -1, -1):
if not ans[i] == 'X':
break
ans[i] = action
if action == 'L':
r ... | 3Python3 | {
"input": [
"7\n1 3 5 6 5 4 2\n",
"5\n1 2 4 3 2\n",
"4\n1 2 4 3\n",
"3\n2 2 2\n",
"20\n2 2 2 1 1 3 1 3 3 1 2 3 3 3 2 2 2 3 1 3\n",
"17\n3 3 2 3 2 3 1 2 3 2 2 3 1 3 1 2 1\n",
"12\n3 3 2 3 2 3 1 2 1 2 2 1\n",
"18\n2 3 3 3 1 2 2 1 3 3 2 3 1 3 1 2 2 2\n",
"3\n3 1 1\n",
"5\n2 1 3 4... | 2CODEFORCES |
1157_C2. Increasing Subsequence (hard version)_2720 | The only difference between problems C1 and C2 is that all values in input of problem C1 are distinct (this condition may be false for problem C2).
You are given a sequence a consisting of n integers.
You are making a sequence of moves. During each move you must take either the leftmost element of the sequence or the... | import java.util.Scanner;
public class C1157 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
int[] A = new int[N];
for (int n=0; n<N; n++) {
A[n] = in.nextInt();
}
StringBuilder output = new StringBui... | 4JAVA | {
"input": [
"7\n1 3 5 6 5 4 2\n",
"5\n1 2 4 3 2\n",
"4\n1 2 4 3\n",
"3\n2 2 2\n",
"20\n2 2 2 1 1 3 1 3 3 1 2 3 3 3 2 2 2 3 1 3\n",
"17\n3 3 2 3 2 3 1 2 3 2 2 3 1 3 1 2 1\n",
"12\n3 3 2 3 2 3 1 2 1 2 2 1\n",
"18\n2 3 3 3 1 2 2 1 3 3 2 3 1 3 1 2 2 2\n",
"3\n3 1 1\n",
"5\n2 1 3 4... | 2CODEFORCES |
1179_E. Alesya and Discrete Math_2721 | We call a function good if its domain of definition is some set of integers and if in case it's defined in x and x-1, f(x) = f(x-1) + 1 or f(x) = f(x-1).
Tanya has found n good functions f_{1}, …, f_{n}, which are defined on all integers from 0 to 10^{18} and f_i(0) = 0 and f_i(10^{18}) = L for all i from 1 to n. It's... | #include <bits/stdc++.h>
using namespace std;
long long query(int i, long long x) {
cout << "? " << i + 1 << ' ' << x << endl;
long long r;
cin >> r;
return r;
}
pair<long long, long long> ans[1000];
mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());
double log_fac[2000];
double log_ncr(i... | 2C++ | {
"input": [
"5 5\n? 1 0\n? 1 1\n? 2 1\n? 2 2\n? 3 2\n? 3 3\n? 4 3\n? 4 4\n? 5 4\n? 5 5\n!\n0 1\n1 2\n2 3\n3 4\n4 5\n",
"1 1\n1\n1 144596170576560149 -144596170576560149 1\n",
"1 1\n1\n0 999999999999999999 -999999999999999999 1\n",
"1 1\n1\n0 0 999999999999999999 1\n",
"5 5\n1\n1 1 -1 5\n1\n1 1 -1... | 2CODEFORCES |
1198_A. MP3_2722 | One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} ... | n, I = map(int, raw_input().split())
bpe = (I*8)/n
ls = map(int, raw_input().split())
import collections
import sys
ctr = collections.Counter(ls)
ks = sorted(ctr.keys())
if 2**bpe >= len(ks):
print 0
sys.exit(0)
lptr = 0
rptr = -1
wind = 0
while rptr < 2**bpe-1:
rptr += 1
wind += ctr[ks[rptr]]
... | 1Python2 | {
"input": [
"6 1\n2 1 2 3 4 3\n",
"6 1\n1 1 2 2 3 3\n",
"6 2\n2 1 2 3 4 3\n",
"10 500\n1 2 3 4 5 6 7 8 9 10\n",
"40 1\n296861916 110348711 213599874 304979682 902720247 958794999 445626005 29685036 968749742 772121742 50110079 72399009 347194050 322418543 594963355 407238845 847251668 210179965 2... | 2CODEFORCES |
1198_A. MP3_2723 | One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} ... | #include <bits/stdc++.h>
using namespace std;
const long long N = 4e5 + 5;
long long a[N];
void solve() {
int n;
long long I;
cin >> n >> I;
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
long long k = (8 * I) / n;
long long K = pow(2ll, min(20ll, k));
vector<long long> v;
vector<long long> ... | 2C++ | {
"input": [
"6 1\n2 1 2 3 4 3\n",
"6 1\n1 1 2 2 3 3\n",
"6 2\n2 1 2 3 4 3\n",
"10 500\n1 2 3 4 5 6 7 8 9 10\n",
"40 1\n296861916 110348711 213599874 304979682 902720247 958794999 445626005 29685036 968749742 772121742 50110079 72399009 347194050 322418543 594963355 407238845 847251668 210179965 2... | 2CODEFORCES |
1198_A. MP3_2724 | One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} ... | import math
n, m = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
a.sort()
lastval = -1
b = list()
for x in a:
if x != lastval:
b.append(1)
lastval = x
else:
b[-1] += 1
k = len(b)
while k > (1 << ((8*m)//n)):
k -= 1
ans = 0
for x in range(k):
ans += b[x]
res = ans
for x... | 3Python3 | {
"input": [
"6 1\n2 1 2 3 4 3\n",
"6 1\n1 1 2 2 3 3\n",
"6 2\n2 1 2 3 4 3\n",
"10 500\n1 2 3 4 5 6 7 8 9 10\n",
"40 1\n296861916 110348711 213599874 304979682 902720247 958794999 445626005 29685036 968749742 772121742 50110079 72399009 347194050 322418543 594963355 407238845 847251668 210179965 2... | 2CODEFORCES |
1198_A. MP3_2725 | One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of n non-negative integers.
If there are exactly K distinct values in the array, then we need k = ⌈ log_{2} ... | //JDope
import java.util.*;
import java.io.*;
import java.math.*;
public class A{
public static void main(String[] omkar) throws Exception
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(in.readLine());
StringBuilder sb = new StringBuilder();... | 4JAVA | {
"input": [
"6 1\n2 1 2 3 4 3\n",
"6 1\n1 1 2 2 3 3\n",
"6 2\n2 1 2 3 4 3\n",
"10 500\n1 2 3 4 5 6 7 8 9 10\n",
"40 1\n296861916 110348711 213599874 304979682 902720247 958794999 445626005 29685036 968749742 772121742 50110079 72399009 347194050 322418543 594963355 407238845 847251668 210179965 2... | 2CODEFORCES |
1214_H. Tiles Placement_2726 | The new pedestrian zone in Moscow city center consists of n squares connected with each other by n - 1 footpaths. We define a simple path as a sequence of squares such that no square appears in this sequence twice and any two adjacent squares in this sequence are directly connected with a footpath. The size of a simple... | #include <bits/stdc++.h>
using namespace std;
int n, k, root, d[200005], h[200005], res[200005];
vector<int> a[200005];
void dfs(int u, int p) {
int tmp = 0;
for (int i = 0; i < (int)a[u].size(); i++) {
int v = a[u][i];
if (v == p) continue;
d[v] = d[u] + 1;
dfs(v, u);
tmp = max(tmp, h[v]);
}
... | 2C++ | {
"input": [
"7 3\n1 3\n2 3\n3 4\n4 5\n5 6\n5 7\n",
"7 4\n1 3\n2 3\n3 4\n4 5\n5 6\n5 7\n",
"5 2\n3 1\n1 4\n4 2\n2 5\n",
"5 3\n5 1\n5 4\n4 3\n3 2\n",
"7 3\n7 3\n7 2\n7 1\n7 5\n7 6\n7 4\n",
"7 2\n1 3\n2 3\n3 4\n4 5\n5 6\n5 7\n",
"7 2\n6 2\n6 7\n6 5\n6 3\n6 1\n6 4\n",
"64 45\n8 39\n8 42\n... | 2CODEFORCES |
1214_H. Tiles Placement_2727 | The new pedestrian zone in Moscow city center consists of n squares connected with each other by n - 1 footpaths. We define a simple path as a sequence of squares such that no square appears in this sequence twice and any two adjacent squares in this sequence are directly connected with a footpath. The size of a simple... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.io.UncheckedIOException;
import java.util.List;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import... | 4JAVA | {
"input": [
"7 3\n1 3\n2 3\n3 4\n4 5\n5 6\n5 7\n",
"7 4\n1 3\n2 3\n3 4\n4 5\n5 6\n5 7\n",
"5 2\n3 1\n1 4\n4 2\n2 5\n",
"5 3\n5 1\n5 4\n4 3\n3 2\n",
"7 3\n7 3\n7 2\n7 1\n7 5\n7 6\n7 4\n",
"7 2\n1 3\n2 3\n3 4\n4 5\n5 6\n5 7\n",
"7 2\n6 2\n6 7\n6 5\n6 3\n6 1\n6 4\n",
"64 45\n8 39\n8 42\n... | 2CODEFORCES |
1238_B. Kill 'Em All_2728 | Ivan plays an old action game called Heretic. He's stuck on one of the final levels of this game, so he needs some help with killing the monsters.
The main part of the level is a large corridor (so large and narrow that it can be represented as an infinite coordinate line). The corridor is divided into two parts; let'... | from collections import Counter
from sys import stdin, stdout
raw_input = stdin.readline
for q in xrange(input()):
n,r=map(int,raw_input().split())
l=map(int,raw_input().split())
l=(Counter(l).keys())
l.sort()
c=0
ans=0
n=len(l)
for i in xrange(n-1,-1,-1):
if l[i]>c:
... | 1Python2 | {
"input": [
"2\n3 2\n1 3 5\n4 1\n5 2 3 5\n",
"1\n3 1383\n1 2 3\n",
"1\n3 3\n1 2 3\n",
"1\n2 1383\n1 2 3\n",
"2\n3 2\n1 3 5\n4 1\n5 4 3 5\n",
"2\n3 2\n1 1 5\n4 1\n5 4 3 5\n",
"2\n3 2\n0 1 5\n4 1\n5 2 3 5\n",
"1\n2 1383\n1 2 1\n",
"1\n2 501\n1 2 1\n",
"2\n3 2\n0 1 5\n4 1\n5 4 3 ... | 2CODEFORCES |
1238_B. Kill 'Em All_2729 | Ivan plays an old action game called Heretic. He's stuck on one of the final levels of this game, so he needs some help with killing the monsters.
The main part of the level is a large corridor (so large and narrow that it can be represented as an infinite coordinate line). The corridor is divided into two parts; let'... | #include <bits/stdc++.h>
using namespace std;
const long long maxn = 3e5 + 10;
long long N, R, arr[maxn], T;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> T;
while (T--) {
cin >> N >> R;
for (register long long i = 1; i <= N; ++i) {
cin >> arr[i];
}
sort(arr + 1, arr + 1 ... | 2C++ | {
"input": [
"2\n3 2\n1 3 5\n4 1\n5 2 3 5\n",
"1\n3 1383\n1 2 3\n",
"1\n3 3\n1 2 3\n",
"1\n2 1383\n1 2 3\n",
"2\n3 2\n1 3 5\n4 1\n5 4 3 5\n",
"2\n3 2\n1 1 5\n4 1\n5 4 3 5\n",
"2\n3 2\n0 1 5\n4 1\n5 2 3 5\n",
"1\n2 1383\n1 2 1\n",
"1\n2 501\n1 2 1\n",
"2\n3 2\n0 1 5\n4 1\n5 4 3 ... | 2CODEFORCES |
1238_B. Kill 'Em All_2730 | Ivan plays an old action game called Heretic. He's stuck on one of the final levels of this game, so he needs some help with killing the monsters.
The main part of the level is a large corridor (so large and narrow that it can be represented as an infinite coordinate line). The corridor is divided into two parts; let'... | import sys
def input():
str = sys.stdin.readline()
return str[:-1]
def unique(x, first, last):
if first == last:
return last
result = first
while first + 1 != last:
first += 1
if(x[result] != x[first]):
result += 1
x[result] = x[first]
return resul... | 3Python3 | {
"input": [
"2\n3 2\n1 3 5\n4 1\n5 2 3 5\n",
"1\n3 1383\n1 2 3\n",
"1\n3 3\n1 2 3\n",
"1\n2 1383\n1 2 3\n",
"2\n3 2\n1 3 5\n4 1\n5 4 3 5\n",
"2\n3 2\n1 1 5\n4 1\n5 4 3 5\n",
"2\n3 2\n0 1 5\n4 1\n5 2 3 5\n",
"1\n2 1383\n1 2 1\n",
"1\n2 501\n1 2 1\n",
"2\n3 2\n0 1 5\n4 1\n5 4 3 ... | 2CODEFORCES |
1238_B. Kill 'Em All_2731 | Ivan plays an old action game called Heretic. He's stuck on one of the final levels of this game, so he needs some help with killing the monsters.
The main part of the level is a large corridor (so large and narrow that it can be represented as an infinite coordinate line). The corridor is divided into two parts; let'... |
import java.io.*;
import java.util.ArrayList;
import java.util.Set;
import java.util.TreeMap;
public class _Rough{
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter out = new BufferedWri... | 4JAVA | {
"input": [
"2\n3 2\n1 3 5\n4 1\n5 2 3 5\n",
"1\n3 1383\n1 2 3\n",
"1\n3 3\n1 2 3\n",
"1\n2 1383\n1 2 3\n",
"2\n3 2\n1 3 5\n4 1\n5 4 3 5\n",
"2\n3 2\n1 1 5\n4 1\n5 4 3 5\n",
"2\n3 2\n0 1 5\n4 1\n5 2 3 5\n",
"1\n2 1383\n1 2 1\n",
"1\n2 501\n1 2 1\n",
"2\n3 2\n0 1 5\n4 1\n5 4 3 ... | 2CODEFORCES |
1256_C. Platforms Jumping_2732 | There is a river of width n. The left bank of the river is cell 0 and the right bank is cell n + 1 (more formally, the river can be represented as a sequence of n + 2 cells numbered from 0 to n + 1). There are also m wooden platforms on a river, the i-th platform has length c_i (so the i-th platform takes c_i consecuti... | from __future__ import division, print_function
def main():
n,m,d=map(int,input().split())
platforms=list(map(int,input().split()))
combined=sum(platforms)
pos=0
p=0
result=[0]*n
flag=0
while pos<n+1 and p<m:
flag=0
for i in range(pos+1,pos+d+1):
pos=i
... | 1Python2 | {
"input": [
"7 3 2\n1 2 1\n",
"10 1 5\n2\n",
"10 1 11\n1\n",
"15 2 5\n1 1\n",
"1000 16 2\n20 13 16 13 22 10 18 21 18 20 20 16 19 9 11 22\n",
"6 3 1\n1 2 3\n",
"11 1 5\n2\n",
"7 1 2\n4\n",
"5 2 1\n1 1\n",
"10 1 4\n10\n",
"10 10 1\n1 1 1 1 1 1 1 1 1 1\n",
"8 4 1\n1 1 4 1... | 2CODEFORCES |
1256_C. Platforms Jumping_2733 | There is a river of width n. The left bank of the river is cell 0 and the right bank is cell n + 1 (more formally, the river can be represented as a sequence of n + 2 cells numbered from 0 to n + 1). There are also m wooden platforms on a river, the i-th platform has length c_i (so the i-th platform takes c_i consecuti... | #include <bits/stdc++.h>
int n, m, d, a[1005], c[1005], i, j, k, l, sum;
int main() {
for (scanf("%d%d%d", &n, &m, &d), i = 0; i < m; i++)
scanf("%d", &c[i]), sum += c[i];
if (sum + (d - 1) * (m + 1) < n || sum > n) {
printf("NO\n");
return 0;
} else
printf("YES\n");
for (i = j = 0; i < n; i++) ... | 2C++ | {
"input": [
"7 3 2\n1 2 1\n",
"10 1 5\n2\n",
"10 1 11\n1\n",
"15 2 5\n1 1\n",
"1000 16 2\n20 13 16 13 22 10 18 21 18 20 20 16 19 9 11 22\n",
"6 3 1\n1 2 3\n",
"11 1 5\n2\n",
"7 1 2\n4\n",
"5 2 1\n1 1\n",
"10 1 4\n10\n",
"10 10 1\n1 1 1 1 1 1 1 1 1 1\n",
"8 4 1\n1 1 4 1... | 2CODEFORCES |
1256_C. Platforms Jumping_2734 | There is a river of width n. The left bank of the river is cell 0 and the right bank is cell n + 1 (more formally, the river can be represented as a sequence of n + 2 cells numbered from 0 to n + 1). There are also m wooden platforms on a river, the i-th platform has length c_i (so the i-th platform takes c_i consecuti... | from collections import defaultdict
import sys
input=sys.stdin.readline
n,m,d=map(int,input().split())
c=[int(i) for i in input().split()]
ind=defaultdict(int)
suff=n
for i in range(m-1,-1,-1):
suff-=c[i]
ind[i+1]=suff+1
indl=[]
for i in ind:
indl.append(i)
indl.reverse()
cur=0
for i in indl:
if ind[i]-... | 3Python3 | {
"input": [
"7 3 2\n1 2 1\n",
"10 1 5\n2\n",
"10 1 11\n1\n",
"15 2 5\n1 1\n",
"1000 16 2\n20 13 16 13 22 10 18 21 18 20 20 16 19 9 11 22\n",
"6 3 1\n1 2 3\n",
"11 1 5\n2\n",
"7 1 2\n4\n",
"5 2 1\n1 1\n",
"10 1 4\n10\n",
"10 10 1\n1 1 1 1 1 1 1 1 1 1\n",
"8 4 1\n1 1 4 1... | 2CODEFORCES |
1256_C. Platforms Jumping_2735 | There is a river of width n. The left bank of the river is cell 0 and the right bank is cell n + 1 (more formally, the river can be represented as a sequence of n + 2 cells numbered from 0 to n + 1). There are also m wooden platforms on a river, the i-th platform has length c_i (so the i-th platform takes c_i consecuti... | import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
public class Main {
InputStream is;
PrintWriter out;
String INPUT = "";
private static final long M = 1000000007L;
void solv... | 4JAVA | {
"input": [
"7 3 2\n1 2 1\n",
"10 1 5\n2\n",
"10 1 11\n1\n",
"15 2 5\n1 1\n",
"1000 16 2\n20 13 16 13 22 10 18 21 18 20 20 16 19 9 11 22\n",
"6 3 1\n1 2 3\n",
"11 1 5\n2\n",
"7 1 2\n4\n",
"5 2 1\n1 1\n",
"10 1 4\n10\n",
"10 10 1\n1 1 1 1 1 1 1 1 1 1\n",
"8 4 1\n1 1 4 1... | 2CODEFORCES |
127_C. Hot Bath_2736 | Bob is about to take a hot bath.
There are two taps to fill the bath: a hot water tap and a cold water tap. The cold water's temperature is t1, and the hot water's temperature is t2. The cold water tap can transmit any integer number of water units per second from 0 to x1, inclusive. Similarly, the hot water tap can ... | t1,t2,x1,x2,t0=map(int,raw_input().split())
y1=x1
y2=x2
z1=0
z2=0
mindif=999999999999999
while True:
t=1.0*(t1*y1+t2*y2)/(y1+y2)
if t-t0<mindif and t-t0>=0:
z1=y1
z2=y2
mindif=t-t0
if y2==0 or y1==0:break
if(t-t0)>0:
y2-=1
elif (t-t0)<0:y1-=1
else: break
pr... | 1Python2 | {
"input": [
"300 500 1000 1000 300\n",
"10 70 100 100 25\n",
"143 456 110 117 273\n",
"176902 815637 847541 412251 587604\n",
"1 3 100 100 3\n",
"1 1000000 1000000 1000000 2\n",
"522321 902347 10945 842811 630561\n",
"10 14 1 1 11\n",
"99 99 99 99 99\n",
"1 1000000 1000000 100... | 2CODEFORCES |
127_C. Hot Bath_2737 | Bob is about to take a hot bath.
There are two taps to fill the bath: a hot water tap and a cold water tap. The cold water's temperature is t1, and the hot water's temperature is t2. The cold water tap can transmit any integer number of water units per second from 0 to x1, inclusive. Similarly, the hot water tap can ... | #include <bits/stdc++.h>
using namespace std;
long long t1, t2, x1, x2, t0;
int main() {
long long i;
while (cin >> t1 >> t2 >> x1 >> x2 >> t0) {
if (t2 == t0 && t0 != t1) {
cout << "0"
<< " " << x2 << endl;
continue;
}
if (t2 != t0 && t0 == t1) {
cout << x1 << " "
... | 2C++ | {
"input": [
"300 500 1000 1000 300\n",
"10 70 100 100 25\n",
"143 456 110 117 273\n",
"176902 815637 847541 412251 587604\n",
"1 3 100 100 3\n",
"1 1000000 1000000 1000000 2\n",
"522321 902347 10945 842811 630561\n",
"10 14 1 1 11\n",
"99 99 99 99 99\n",
"1 1000000 1000000 100... | 2CODEFORCES |
127_C. Hot Bath_2738 | Bob is about to take a hot bath.
There are two taps to fill the bath: a hot water tap and a cold water tap. The cold water's temperature is t1, and the hot water's temperature is t2. The cold water tap can transmit any integer number of water units per second from 0 to x1, inclusive. Similarly, the hot water tap can ... | import math
def gcd(a,b):
if(b==0):
return a
return gcd(b,a%b)
l=input().split()
t1=int(l[0])
t2=int(l[1])
x1=int(l[2])
x2=int(l[3])
t0=int(l[4])
num1=t2-t0
num2=t0-t1
if(t1==t2):
print(x1,x2)
quit()
if(num1==0):
print(0,x2)
quit()
if(num2==0):
print(x1,0)
quit()
z=num2/num1
maxa... | 3Python3 | {
"input": [
"300 500 1000 1000 300\n",
"10 70 100 100 25\n",
"143 456 110 117 273\n",
"176902 815637 847541 412251 587604\n",
"1 3 100 100 3\n",
"1 1000000 1000000 1000000 2\n",
"522321 902347 10945 842811 630561\n",
"10 14 1 1 11\n",
"99 99 99 99 99\n",
"1 1000000 1000000 100... | 2CODEFORCES |
127_C. Hot Bath_2739 | Bob is about to take a hot bath.
There are two taps to fill the bath: a hot water tap and a cold water tap. The cold water's temperature is t1, and the hot water's temperature is t2. The cold water tap can transmit any integer number of water units per second from 0 to x1, inclusive. Similarly, the hot water tap can ... |
import java.math.*;
import java.io.*;
import java.util.*;
public class CNew
{
StringTokenizer st;
BufferedReader in;
PrintWriter ob;
public static void main(String args[])throws IOException {
new CNew().run();
}
void run()throws IOException {
in=new BufferedReader(new InputStreamReader(System.in));
ob=ne... | 4JAVA | {
"input": [
"300 500 1000 1000 300\n",
"10 70 100 100 25\n",
"143 456 110 117 273\n",
"176902 815637 847541 412251 587604\n",
"1 3 100 100 3\n",
"1 1000000 1000000 1000000 2\n",
"522321 902347 10945 842811 630561\n",
"10 14 1 1 11\n",
"99 99 99 99 99\n",
"1 1000000 1000000 100... | 2CODEFORCES |
12_B. Correct Solution?_2740 | One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number n to Bob and said:
—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.... | i=raw_input();n=sorted(filter(lambda c:c!='0',i))or[''];print('WRONG_ANSWER','OK')[raw_input()==n[0]+filter(lambda c:c=='0',i)+''.join(n[1:])] | 1Python2 | {
"input": [
"3310\n1033\n",
"4\n5\n",
"17109\n01179\n",
"111111111\n111111111\n",
"912\n9123\n",
"10101\n10101\n",
"666\n0666\n",
"7391\n1397\n",
"1270\n1027\n",
"0\n00\n",
"987235645\n234556789\n",
"201\n102\n",
"0\n0\n",
"1000000000\n1\n",
"123456789\n123... | 2CODEFORCES |
12_B. Correct Solution?_2741 | One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number n to Bob and said:
—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.... | #include <bits/stdc++.h>
using namespace std;
long long n, m, i, j;
int a[50], x;
char b[50];
bool f;
int main() {
cin >> n;
i = 1;
while (n > 0) {
a[i] = n % 10;
n = n / 10;
i++;
}
sort(a + 1, a + i);
if (a[1] == 0) {
for (j = 2; j < i; j++) {
if (a[j] > 0) {
swap(a[1], a[j]);... | 2C++ | {
"input": [
"3310\n1033\n",
"4\n5\n",
"17109\n01179\n",
"111111111\n111111111\n",
"912\n9123\n",
"10101\n10101\n",
"666\n0666\n",
"7391\n1397\n",
"1270\n1027\n",
"0\n00\n",
"987235645\n234556789\n",
"201\n102\n",
"0\n0\n",
"1000000000\n1\n",
"123456789\n123... | 2CODEFORCES |
12_B. Correct Solution?_2742 | One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number n to Bob and said:
—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.... | def sort(s):
return sorted(sorted(s), key=str.upper)
s=input()
s1=input()
l=sort(s)
c=l.count('0')
res=""
if(len(l)>c):
res=res+l[c]
for i in range(c):
res=res+l[i]
for i in range(c+1,len(s)):
res=res+l[i]
if(s1==res):
print("OK")
else:
print("WRONG_ANSWER") | 3Python3 | {
"input": [
"3310\n1033\n",
"4\n5\n",
"17109\n01179\n",
"111111111\n111111111\n",
"912\n9123\n",
"10101\n10101\n",
"666\n0666\n",
"7391\n1397\n",
"1270\n1027\n",
"0\n00\n",
"987235645\n234556789\n",
"201\n102\n",
"0\n0\n",
"1000000000\n1\n",
"123456789\n123... | 2CODEFORCES |
12_B. Correct Solution?_2743 | One cold winter evening Alice and her older brother Bob was sitting at home near the fireplace and giving each other interesting problems to solve. When it was Alice's turn, she told the number n to Bob and said:
—Shuffle the digits in this number in order to obtain the smallest possible number without leading zeroes.... |
import java.util.Arrays;
import java.util.Scanner;
/**
*
* @author epiZend
*/
public class Correct {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String num = sc.next();
String ans = sc.next();
if(num.equals("0") && ans.equals("0")){
... | 4JAVA | {
"input": [
"3310\n1033\n",
"4\n5\n",
"17109\n01179\n",
"111111111\n111111111\n",
"912\n9123\n",
"10101\n10101\n",
"666\n0666\n",
"7391\n1397\n",
"1270\n1027\n",
"0\n00\n",
"987235645\n234556789\n",
"201\n102\n",
"0\n0\n",
"1000000000\n1\n",
"123456789\n123... | 2CODEFORCES |
1323_D. Present_2744 | Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with another one — xor of all pairwise sums of elements in the array, she realiz... | #include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5;
int a[N], t[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int ans = 0;
for (int i = 0; i < n; i++) cin >> a[i];
for (int k = 0; k <= 24; k++) {
for (int i = 0; i < n; i++) t[i] = a[i] % (1... | 2C++ | {
"input": [
"3\n1 2 3\n",
"2\n1 2\n",
"51\n50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\n",
"100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 3... | 2CODEFORCES |
1323_D. Present_2745 | Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with another one — xor of all pairwise sums of elements in the array, she realiz... | from bisect import bisect_left, bisect_right
def go():
n = int(input())
a = list(map(int, input().split()))
b = max(a).bit_length()
res = 0
vals = a
for i in range(b + 1):
# print("")
b2 = 2 << i
b1 = 1 << i
a0 = [aa for aa in a if aa & b1==0]
a1 = [aa f... | 3Python3 | {
"input": [
"3\n1 2 3\n",
"2\n1 2\n",
"51\n50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\n",
"100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 3... | 2CODEFORCES |
1323_D. Present_2746 | Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with another one — xor of all pairwise sums of elements in the array, she realiz... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author KharYusuf
*/
public class ... | 4JAVA | {
"input": [
"3\n1 2 3\n",
"2\n1 2\n",
"51\n50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\n",
"100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 3... | 2CODEFORCES |
1342_C. Yet Another Counting Problem_2747 | You are given two integers a and b, and q queries. The i-th query consists of two numbers l_i and r_i, and the answer to it is the number of integers x such that l_i ≤ x ≤ r_i, and ((x mod a) mod b) ≠ ((x mod b) mod a). Calculate the answer for each query.
Recall that y mod z is the remainder of the division of y by z... | def build(L,a,b):
L[0]=0
for i in range(1,a*b+1):
L[i]+=L[i-1]
if ((i%a)%b)!=((i%b)%a):
L[i]+=1
def query2(l,a,b,L):
cnt=l/(a*b)
rem=l%(a*b)
return L[a*b]*cnt+L[rem]
def query(l,r,a,b,L):
return query2(r,a,b,L)-query2(l-1,a,b,L)
t=int(raw_input())
for i in range(t):
a,b,q=list(map(int,raw_input().st... | 1Python2 | {
"input": [
"2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200\n",
"1\n200 200 1\n1 1000000000000000000\n",
"1\n1 1 1\n1 1000000000000000000\n",
"1\n1 1 1\n1 2\n",
"1\n199 200 1\n1 1000000000000000000\n",
"2\n4 6 5\n1 1\n1 3\n1 5\n1 2\n1 9\n7 10 2\n7 8\n100 200\n",
"2\n4 6 5\n1 1\n1... | 2CODEFORCES |
1342_C. Yet Another Counting Problem_2748 | You are given two integers a and b, and q queries. The i-th query consists of two numbers l_i and r_i, and the answer to it is the number of integers x such that l_i ≤ x ≤ r_i, and ((x mod a) mod b) ≠ ((x mod b) mod a). Calculate the answer for each query.
Recall that y mod z is the remainder of the division of y by z... | #include <bits/stdc++.h>
template <typename T>
void MACRO_VAR_Scan(T& t) {
std::cin >> t;
}
template <typename First, typename... Rest>
void MACRO_VAR_Scan(First& first, Rest&... rest) {
std::cin >> first;
MACRO_VAR_Scan(rest...);
}
template <typename T>
void MACRO_VEC_ROW_Init(int n, T& t) {
t.resize(n);
}
tem... | 2C++ | {
"input": [
"2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200\n",
"1\n200 200 1\n1 1000000000000000000\n",
"1\n1 1 1\n1 1000000000000000000\n",
"1\n1 1 1\n1 2\n",
"1\n199 200 1\n1 1000000000000000000\n",
"2\n4 6 5\n1 1\n1 3\n1 5\n1 2\n1 9\n7 10 2\n7 8\n100 200\n",
"2\n4 6 5\n1 1\n1... | 2CODEFORCES |
1342_C. Yet Another Counting Problem_2749 | You are given two integers a and b, and q queries. The i-th query consists of two numbers l_i and r_i, and the answer to it is the number of integers x such that l_i ≤ x ≤ r_i, and ((x mod a) mod b) ≠ ((x mod b) mod a). Calculate the answer for each query.
Recall that y mod z is the remainder of the division of y by z... | def gcd(a, b):
if b == 0:
return a
else:
return gcd(b, a % b)
t = int(input())
for i in range(t):
a, b, q = map(int, input().split())
mi = min(a, b)
ma = max(a, b)
for j in range(q):
l, r = map(int, input().split())
l = max(l, ma)
if a == b or mi == 1 or... | 3Python3 | {
"input": [
"2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200\n",
"1\n200 200 1\n1 1000000000000000000\n",
"1\n1 1 1\n1 1000000000000000000\n",
"1\n1 1 1\n1 2\n",
"1\n199 200 1\n1 1000000000000000000\n",
"2\n4 6 5\n1 1\n1 3\n1 5\n1 2\n1 9\n7 10 2\n7 8\n100 200\n",
"2\n4 6 5\n1 1\n1... | 2CODEFORCES |
1342_C. Yet Another Counting Problem_2750 | You are given two integers a and b, and q queries. The i-th query consists of two numbers l_i and r_i, and the answer to it is the number of integers x such that l_i ≤ x ≤ r_i, and ((x mod a) mod b) ≠ ((x mod b) mod a). Calculate the answer for each query.
Recall that y mod z is the remainder of the division of y by z... | import java.io.*;
import java.util.*;
/*
procrastinating
*/
public class Main {
static FastReader in;
static PrintWriter out;
static Random rand = new Random();
static final int INF = (int) (1e9 + 10), MOD = (int) (1e9 + 7), LOGN = 60;
static final long IINF = (long) (2e18 + 10);
static int ... | 4JAVA | {
"input": [
"2\n4 6 5\n1 1\n1 3\n1 5\n1 7\n1 9\n7 10 2\n7 8\n100 200\n",
"1\n200 200 1\n1 1000000000000000000\n",
"1\n1 1 1\n1 1000000000000000000\n",
"1\n1 1 1\n1 2\n",
"1\n199 200 1\n1 1000000000000000000\n",
"2\n4 6 5\n1 1\n1 3\n1 5\n1 2\n1 9\n7 10 2\n7 8\n100 200\n",
"2\n4 6 5\n1 1\n1... | 2CODEFORCES |
1364_C. Ehab and Prefix MEXs_2751 | Given an array a of length n, find another array, b, of length n such that:
* for each i (1 ≤ i ≤ n) MEX(\\{b_1, b_2, …, b_i\})=a_i.
The MEX of a set of integers is the smallest non-negative integer that doesn't belong to this set.
If such array doesn't exist, determine this.
Input
The first line contains an ... | 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())
raw_input = lambda: sys.stdin.readline().rstrip()
RS = raw_input
RI = lambda : map(int,RS().split... | 1Python2 | {
"input": [
"3\n1 2 3\n",
"3\n1 1 3\n",
"4\n0 0 0 2\n",
"7\n0 0 2 2 5 5 6\n",
"1\n1\n",
"10\n1 2 3 4 4 4 7 7 7 10\n",
"1\n0\n",
"3\n1 1 1\n",
"4\n0 0 0 3\n",
"4\n0 0 0 1\n",
"3\n0 2 3\n",
"7\n0 0 2 2 3 5 6\n",
"3\n0 1 1\n",
"4\n0 0 1 3\n",
"4\n0 0 1 1\n",
... | 2CODEFORCES |
1364_C. Ehab and Prefix MEXs_2752 | Given an array a of length n, find another array, b, of length n such that:
* for each i (1 ≤ i ≤ n) MEX(\\{b_1, b_2, …, b_i\})=a_i.
The MEX of a set of integers is the smallest non-negative integer that doesn't belong to this set.
If such array doesn't exist, determine this.
Input
The first line contains an ... | #include <bits/stdc++.h>
using namespace std;
long long int modu(long long int a, long long int b) {
long long int ans = 1;
while (b > 0) {
if (b & 1) ans = (ans * a) % 1000000007;
b /= 2;
a = (a * a) % 1000000007;
}
return ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
l... | 2C++ | {
"input": [
"3\n1 2 3\n",
"3\n1 1 3\n",
"4\n0 0 0 2\n",
"7\n0 0 2 2 5 5 6\n",
"1\n1\n",
"10\n1 2 3 4 4 4 7 7 7 10\n",
"1\n0\n",
"3\n1 1 1\n",
"4\n0 0 0 3\n",
"4\n0 0 0 1\n",
"3\n0 2 3\n",
"7\n0 0 2 2 3 5 6\n",
"3\n0 1 1\n",
"4\n0 0 1 3\n",
"4\n0 0 1 1\n",
... | 2CODEFORCES |
1364_C. Ehab and Prefix MEXs_2753 | Given an array a of length n, find another array, b, of length n such that:
* for each i (1 ≤ i ≤ n) MEX(\\{b_1, b_2, …, b_i\})=a_i.
The MEX of a set of integers is the smallest non-negative integer that doesn't belong to this set.
If such array doesn't exist, determine this.
Input
The first line contains an ... | n=int(input())
arr=list(map(int,input().split()))
flag=0
vis=[0]*(10**6+1)
for i in range(n):
if arr[i]>i+1:
flag=1
vis[arr[i]]=1
if flag==1:
print(-1)
quit()
b=[-1]*(n)
for i in range(1,n):
if arr[i-1]!=arr[i]:
b[i]=arr[i-1]
not_vis=[]
for i in range(10**6+1):
if vis[i]==0:
... | 3Python3 | {
"input": [
"3\n1 2 3\n",
"3\n1 1 3\n",
"4\n0 0 0 2\n",
"7\n0 0 2 2 5 5 6\n",
"1\n1\n",
"10\n1 2 3 4 4 4 7 7 7 10\n",
"1\n0\n",
"3\n1 1 1\n",
"4\n0 0 0 3\n",
"4\n0 0 0 1\n",
"3\n0 2 3\n",
"7\n0 0 2 2 3 5 6\n",
"3\n0 1 1\n",
"4\n0 0 1 3\n",
"4\n0 0 1 1\n",
... | 2CODEFORCES |
1364_C. Ehab and Prefix MEXs_2754 | Given an array a of length n, find another array, b, of length n such that:
* for each i (1 ≤ i ≤ n) MEX(\\{b_1, b_2, …, b_i\})=a_i.
The MEX of a set of integers is the smallest non-negative integer that doesn't belong to this set.
If such array doesn't exist, determine this.
Input
The first line contains an ... | import java.sql.PseudoColumnUsage;
import java.util.*;
import java.lang.*;
import java.io.*;
public class Solution {
static int N = 100005;
static int[] arr = new int[N];
static int[] brr = new int[N];
static boolean[] used = new boolean[N];
public static void main(String[] args) throws java.lang.E... | 4JAVA | {
"input": [
"3\n1 2 3\n",
"3\n1 1 3\n",
"4\n0 0 0 2\n",
"7\n0 0 2 2 5 5 6\n",
"1\n1\n",
"10\n1 2 3 4 4 4 7 7 7 10\n",
"1\n0\n",
"3\n1 1 1\n",
"4\n0 0 0 3\n",
"4\n0 0 0 1\n",
"3\n0 2 3\n",
"7\n0 0 2 2 3 5 6\n",
"3\n0 1 1\n",
"4\n0 0 1 3\n",
"4\n0 0 1 1\n",
... | 2CODEFORCES |
1384_D. GameGame_2755 | Koa the Koala and her best friend want to play a game.
The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts.
Let's describe a move in the game:
* During his move, a player chooses any element of... | # Author: yumtam
# Created at: 2020-09-10 20:19
from __future__ import division, print_function
_interactive = False
def main():
for _ in range(int(input())):
n = int(input())
ar = input_as_list()
mx = 1<<30
while mx:
cnt = 0
for x in ar:
... | 1Python2 | {
"input": [
"4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4\n",
"3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2\n",
"3\n3\n2 2 2\n3\n2 2 3\n5\n0 0 0 2 2\n",
"4\n5\n4 1 3 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4\n",
"3\n3\n2 2 0\n3\n2 2 3\n5\n0 0 0 2 2\n",
"3\n3\n4 2 0\n3\n2 2 3\n5\n0 0 0 2 2\n",
"3\n3\n4 2 0\n3\n2 ... | 2CODEFORCES |
1384_D. GameGame_2756 | Koa the Koala and her best friend want to play a game.
The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts.
Let's describe a move in the game:
* During his move, a player chooses any element of... | #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize(2)
#pragma GCC optimize(3)
int t, n, x;
int num[30];
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> t;
while (t--) {
cin >> n;
memset(num, 0, sizeof(num));
for (int i = 1; i <= n; i++) {
... | 2C++ | {
"input": [
"4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4\n",
"3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2\n",
"3\n3\n2 2 2\n3\n2 2 3\n5\n0 0 0 2 2\n",
"4\n5\n4 1 3 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4\n",
"3\n3\n2 2 0\n3\n2 2 3\n5\n0 0 0 2 2\n",
"3\n3\n4 2 0\n3\n2 2 3\n5\n0 0 0 2 2\n",
"3\n3\n4 2 0\n3\n2 ... | 2CODEFORCES |
1384_D. GameGame_2757 | Koa the Koala and her best friend want to play a game.
The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts.
Let's describe a move in the game:
* During his move, a player chooses any element of... | from math import inf as inf
from math import *
from collections import *
import sys
import os
input=sys.stdin.readline
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
b=[0]*31
fl="DRAW"
for i in a:
z=bin(i)[2:]
z=z.zfill(31)
for j in range(31):
... | 3Python3 | {
"input": [
"4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4\n",
"3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2\n",
"3\n3\n2 2 2\n3\n2 2 3\n5\n0 0 0 2 2\n",
"4\n5\n4 1 3 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4\n",
"3\n3\n2 2 0\n3\n2 2 3\n5\n0 0 0 2 2\n",
"3\n3\n4 2 0\n3\n2 2 3\n5\n0 0 0 2 2\n",
"3\n3\n4 2 0\n3\n2 ... | 2CODEFORCES |
1384_D. GameGame_2758 | Koa the Koala and her best friend want to play a game.
The game starts with an array a of length n consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to 0. Koa starts.
Let's describe a move in the game:
* During his move, a player chooses any element of... | import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
static class FastScanner {
BufferedReader s;
StringTokenizer st;
public FastScanner(InputStream InputStream) {
st = new StringTokenizer("");
s = new BufferedReader(new InputStreamReader(InputStream));
}
public FastScanne... | 4JAVA | {
"input": [
"4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4\n",
"3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2\n",
"3\n3\n2 2 2\n3\n2 2 3\n5\n0 0 0 2 2\n",
"4\n5\n4 1 3 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4\n",
"3\n3\n2 2 0\n3\n2 2 3\n5\n0 0 0 2 2\n",
"3\n3\n4 2 0\n3\n2 2 3\n5\n0 0 0 2 2\n",
"3\n3\n4 2 0\n3\n2 ... | 2CODEFORCES |
1406_A. Subset Mex_2759 | Given a set of integers (it can contain equal elements).
You have to split it into two subsets A and B (both of them can contain equal elements or be empty). You have to maximize the value of mex(A)+mex(B).
Here mex of a set denotes the smallest non-negative integer that doesn't exist in the set. For example:
* m... | FAST_IO = 0
if FAST_IO:
import io, sys, atexit
rr = iter(sys.stdin.read().splitlines()).next
sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
@atexit.register
def write():
sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().... | 1Python2 | {
"input": [
"4\n6\n0 2 1 5 0 1\n3\n0 1 2\n4\n0 2 0 1\n6\n1 2 3 4 5 6\n",
"1\n100\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 ... | 2CODEFORCES |
1406_A. Subset Mex_2760 | Given a set of integers (it can contain equal elements).
You have to split it into two subsets A and B (both of them can contain equal elements or be empty). You have to maximize the value of mex(A)+mex(B).
Here mex of a set denotes the smallest non-negative integer that doesn't exist in the set. For example:
* m... | #include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
int m = 0, k = 0;
for (int i = 0; i < n; i++) {
if (a[i] == m) {
m++;
} else i... | 2C++ | {
"input": [
"4\n6\n0 2 1 5 0 1\n3\n0 1 2\n4\n0 2 0 1\n6\n1 2 3 4 5 6\n",
"1\n100\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 ... | 2CODEFORCES |
1406_A. Subset Mex_2761 | Given a set of integers (it can contain equal elements).
You have to split it into two subsets A and B (both of them can contain equal elements or be empty). You have to maximize the value of mex(A)+mex(B).
Here mex of a set denotes the smallest non-negative integer that doesn't exist in the set. For example:
* m... | t=int(input())
while t!=0:
t-=1
n=int(input())
li=list(map(int,input().split()))
dic={}
dic2={}
a=0
b=0
flag=0
ans=[0]*101
for i in li:
if i not in dic and i not in dic2:
dic[i]=1
else:
ans[i]=1
dic2[i]=1
if i in dic... | 3Python3 | {
"input": [
"4\n6\n0 2 1 5 0 1\n3\n0 1 2\n4\n0 2 0 1\n6\n1 2 3 4 5 6\n",
"1\n100\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 ... | 2CODEFORCES |
1406_A. Subset Mex_2762 | Given a set of integers (it can contain equal elements).
You have to split it into two subsets A and B (both of them can contain equal elements or be empty). You have to maximize the value of mex(A)+mex(B).
Here mex of a set denotes the smallest non-negative integer that doesn't exist in the set. For example:
* m... |
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Stack;
import java.util.TreeMap;
public class Round659 {
static int rec ... | 4JAVA | {
"input": [
"4\n6\n0 2 1 5 0 1\n3\n0 1 2\n4\n0 2 0 1\n6\n1 2 3 4 5 6\n",
"1\n100\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 ... | 2CODEFORCES |
1427_B. Chess Cheater_2763 | You like playing chess tournaments online.
In your last tournament you played n games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get 0 points. When you win you get 1 or 2 points: if you have won also the previous game you get 2 points, otherwise you get 1 ... | def score(s):
ans=0
for i in range(len(s)):
if i==0:
if s[i]=='W':
ans+=1
else:
if s[i]=='W':
if s[i-1]=='W':
ans+=2
else:
ans+=1
return ans
for _ in range(int(input())):
n,k=... | 1Python2 | {
"input": [
"8\n5 2\nWLWLL\n6 5\nLLLWWL\n7 1\nLWLWLWL\n15 5\nWWWLLLWWWLLLWWW\n40 7\nLLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL\n1 0\nL\n1 1\nL\n6 1\nWLLWLW\n",
"8\n5 2\nWLWLL\n6 5\nLLLWWL\n7 2\nLWLWLWL\n15 5\nWWWLLLWWWLLLWWW\n40 7\nLLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL\n1 0\nL\n1 1\nL\n6 1\nWLLWLW\n",
"... | 2CODEFORCES |
1427_B. Chess Cheater_2764 | You like playing chess tournaments online.
In your last tournament you played n games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get 0 points. When you win you get 1 or 2 points: if you have won also the previous game you get 2 points, otherwise you get 1 ... | #include <bits/stdc++.h>
using namespace std;
const long long md = 1e9 + 7;
int an[310000];
char sn[310000];
int main() {
int z;
int n, m;
int i, j, k;
cin >> z;
while (z--) {
scanf("%d%d", &n, &k);
scanf("%s", sn);
bool flag = 1;
int first, last;
for (i = 0; i < n; i++) {
if (sn[i] ... | 2C++ | {
"input": [
"8\n5 2\nWLWLL\n6 5\nLLLWWL\n7 1\nLWLWLWL\n15 5\nWWWLLLWWWLLLWWW\n40 7\nLLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL\n1 0\nL\n1 1\nL\n6 1\nWLLWLW\n",
"8\n5 2\nWLWLL\n6 5\nLLLWWL\n7 2\nLWLWLWL\n15 5\nWWWLLLWWWLLLWWW\n40 7\nLLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL\n1 0\nL\n1 1\nL\n6 1\nWLLWLW\n",
"... | 2CODEFORCES |
1427_B. Chess Cheater_2765 | You like playing chess tournaments online.
In your last tournament you played n games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get 0 points. When you win you get 1 or 2 points: if you have won also the previous game you get 2 points, otherwise you get 1 ... | from functools import reduce
import os
import sys
from collections import *
#from fractions import *
from math import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda: sys.stdin.readline().rstrip("\r\n")
def value(): return tuple(map(int, input().split())) # multiple values
def a... | 3Python3 | {
"input": [
"8\n5 2\nWLWLL\n6 5\nLLLWWL\n7 1\nLWLWLWL\n15 5\nWWWLLLWWWLLLWWW\n40 7\nLLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL\n1 0\nL\n1 1\nL\n6 1\nWLLWLW\n",
"8\n5 2\nWLWLL\n6 5\nLLLWWL\n7 2\nLWLWLWL\n15 5\nWWWLLLWWWLLLWWW\n40 7\nLLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL\n1 0\nL\n1 1\nL\n6 1\nWLLWLW\n",
"... | 2CODEFORCES |
1427_B. Chess Cheater_2766 | You like playing chess tournaments online.
In your last tournament you played n games. For the sake of this problem, each chess game is either won or lost (no draws). When you lose a game you get 0 points. When you win you get 1 or 2 points: if you have won also the previous game you get 2 points, otherwise you get 1 ... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
public class First {
public static void main(String[] args) ... | 4JAVA | {
"input": [
"8\n5 2\nWLWLL\n6 5\nLLLWWL\n7 1\nLWLWLWL\n15 5\nWWWLLLWWWLLLWWW\n40 7\nLLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL\n1 0\nL\n1 1\nL\n6 1\nWLLWLW\n",
"8\n5 2\nWLWLL\n6 5\nLLLWWL\n7 2\nLWLWLWL\n15 5\nWWWLLLWWWLLLWWW\n40 7\nLLWLWLWWWLWLLWLWWWLWLLWLLWLLLLWLLWWWLWWL\n1 0\nL\n1 1\nL\n6 1\nWLLWLW\n",
"... | 2CODEFORCES |
1450_B. Balls of Steel_2767 | You have n distinct points (x_1, y_1),…,(x_n,y_n) on the plane and a non-negative integer parameter k. Each point is a microscopic steel ball and k is the attract power of a ball when it's charged. The attract power is the same for all balls.
In one operation, you can select a ball i to charge it. Once charged, all ba... | for test in range(input()):
n,k = map(int,raw_input().split())
p = []
for _ in range(n):
p.append(map(int,raw_input().split()))
for x in p:
a,b = x
f = 0
for y in p:
c,d = y
if abs(c-a) + abs(d-b)>k:
f = 1
break
... | 1Python2 | {
"input": [
"3\n3 2\n0 0\n3 3\n1 1\n3 3\n6 7\n8 8\n6 9\n4 1\n0 0\n0 1\n0 2\n0 3\n",
"3\n3 2\n0 0\n3 3\n1 1\n3 3\n6 7\n8 8\n6 9\n4 1\n0 0\n1 1\n0 2\n0 3\n",
"3\n3 2\n0 0\n3 3\n1 2\n3 3\n6 7\n9 6\n6 9\n4 1\n0 0\n0 0\n1 2\n1 3\n",
"3\n3 2\n0 0\n1 3\n1 1\n3 3\n6 7\n9 8\n6 9\n4 1\n-1 0\n0 1\n0 2\n1 5\n",
... | 2CODEFORCES |
1450_B. Balls of Steel_2768 | You have n distinct points (x_1, y_1),…,(x_n,y_n) on the plane and a non-negative integer parameter k. Each point is a microscopic steel ball and k is the attract power of a ball when it's charged. The attract power is the same for all balls.
In one operation, you can select a ball i to charge it. Once charged, all ba... | #include<bits/stdc++.h>
using namespace std;
int main()
{
long long a,b,c,d,e,f,g,h,i,j,k,l,m,n,x,y,z,t;
cin>>t;
while(t--)
{
cin>>a>>b;
pair<long long,long long>pp[a+1];
map<long long,long long>mp[a+1];
for(i=1; i<=a; i++)
{
cin>>c>>d;
p... | 2C++ | {
"input": [
"3\n3 2\n0 0\n3 3\n1 1\n3 3\n6 7\n8 8\n6 9\n4 1\n0 0\n0 1\n0 2\n0 3\n",
"3\n3 2\n0 0\n3 3\n1 1\n3 3\n6 7\n8 8\n6 9\n4 1\n0 0\n1 1\n0 2\n0 3\n",
"3\n3 2\n0 0\n3 3\n1 2\n3 3\n6 7\n9 6\n6 9\n4 1\n0 0\n0 0\n1 2\n1 3\n",
"3\n3 2\n0 0\n1 3\n1 1\n3 3\n6 7\n9 8\n6 9\n4 1\n-1 0\n0 1\n0 2\n1 5\n",
... | 2CODEFORCES |
1450_B. Balls of Steel_2769 | You have n distinct points (x_1, y_1),…,(x_n,y_n) on the plane and a non-negative integer parameter k. Each point is a microscopic steel ball and k is the attract power of a ball when it's charged. The attract power is the same for all balls.
In one operation, you can select a ball i to charge it. Once charged, all ba... | # cook your dish here
remaing_test_cases = int(input())
while remaing_test_cases > 0:
points_count,K = map(int,input().split())
points = []
for i in range(points_count):
x,y = map(int,input().split())
points.append([x,y])
flag = 0
for i in range(points_count):
count_power... | 3Python3 | {
"input": [
"3\n3 2\n0 0\n3 3\n1 1\n3 3\n6 7\n8 8\n6 9\n4 1\n0 0\n0 1\n0 2\n0 3\n",
"3\n3 2\n0 0\n3 3\n1 1\n3 3\n6 7\n8 8\n6 9\n4 1\n0 0\n1 1\n0 2\n0 3\n",
"3\n3 2\n0 0\n3 3\n1 2\n3 3\n6 7\n9 6\n6 9\n4 1\n0 0\n0 0\n1 2\n1 3\n",
"3\n3 2\n0 0\n1 3\n1 1\n3 3\n6 7\n9 8\n6 9\n4 1\n-1 0\n0 1\n0 2\n1 5\n",
... | 2CODEFORCES |
1450_B. Balls of Steel_2770 | You have n distinct points (x_1, y_1),…,(x_n,y_n) on the plane and a non-negative integer parameter k. Each point is a microscopic steel ball and k is the attract power of a ball when it's charged. The attract power is the same for all balls.
In one operation, you can select a ball i to charge it. Once charged, all ba... | import java.io.*;
import java.util.*;
public class Main {
public static final int mod=1000000007;
static long[][] dp;
static Map<Integer,Integer> mp;
static Set<Integer> set;
public static void main(String[] args) throws IOException {
//File filein = new File("input.txt");
//BufferedReader sc=new Buffered... | 4JAVA | {
"input": [
"3\n3 2\n0 0\n3 3\n1 1\n3 3\n6 7\n8 8\n6 9\n4 1\n0 0\n0 1\n0 2\n0 3\n",
"3\n3 2\n0 0\n3 3\n1 1\n3 3\n6 7\n8 8\n6 9\n4 1\n0 0\n1 1\n0 2\n0 3\n",
"3\n3 2\n0 0\n3 3\n1 2\n3 3\n6 7\n9 6\n6 9\n4 1\n0 0\n0 0\n1 2\n1 3\n",
"3\n3 2\n0 0\n1 3\n1 1\n3 3\n6 7\n9 8\n6 9\n4 1\n-1 0\n0 1\n0 2\n1 5\n",
... | 2CODEFORCES |
1473_G. Tiles_2771 | Consider a road consisting of several rows. Each row is divided into several rectangular tiles, and all tiles in the same row are equal. The first row contains exactly one rectangular tile. Look at the picture below which shows how the tiles are arranged.
The road is constructed as follows:
* the first row consist... | #include<bits/stdc++.h>
//#define int long long
#define ll long long
#define p pair<int, int>
#define endl '\n'
const int INF = 1000000001;
using namespace std;
const int C = 998244353;
vector<ll> fact, minus_fact;
ll pow1(ll x, ll y, ll z=C){
if (y == 0){
return 1;
}
if (y % 2 == 0){
ret... | 2C++ | {
"input": [
"2\n4 2\n2 3\n",
"8\n328 323\n867 868\n715 718\n721 722\n439 435\n868 870\n834 834\n797 796\n",
"3\n4 1\n2 3\n3 1\n",
"2\n4 2\n2 2\n",
"3\n4 1\n2 3\n6 1\n",
"3\n4 1\n2 3\n6 2\n",
"3\n4 1\n2 4\n6 1\n",
"3\n4 1\n2 3\n5 1\n",
"2\n4 2\n4 2\n",
"3\n4 1\n1 3\n6 1\n",
... | 2CODEFORCES |
1473_G. Tiles_2772 | Consider a road consisting of several rows. Each row is divided into several rectangular tiles, and all tiles in the same row are equal. The first row contains exactly one rectangular tile. Look at the picture below which shows how the tiles are arranged.
The road is constructed as follows:
* the first row consist... | import java.io.*;
import java.util.*;
public class G4 {
InputStream is;
FastWriter out;
String INPUT = "";
final int mod = 998244353;
void solve()
{
int n = ni();
int[][] fif = enumFIF(200005, mod);
long[] base = {1L};
int L = base.length;
for(int i = 0;i < n;i++){
int a = ni(), b = ni();
in... | 4JAVA | {
"input": [
"2\n4 2\n2 3\n",
"8\n328 323\n867 868\n715 718\n721 722\n439 435\n868 870\n834 834\n797 796\n",
"3\n4 1\n2 3\n3 1\n",
"2\n4 2\n2 2\n",
"3\n4 1\n2 3\n6 1\n",
"3\n4 1\n2 3\n6 2\n",
"3\n4 1\n2 4\n6 1\n",
"3\n4 1\n2 3\n5 1\n",
"2\n4 2\n4 2\n",
"3\n4 1\n1 3\n6 1\n",
... | 2CODEFORCES |
149_B. Martian Clock_2773 | Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" — you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored... | a,b = map(bytearray, raw_input().split(':'))
def convert(x):
for i in xrange(len(x)):
if x[i] > 57:
x[i] -= 55
else:
x[i] -= 48
def satisfy(base, a, b):
hour = 0
for i in xrange(len(a)):
hour = hour * base + a[i]
if hour > 23:
return False
m... | 1Python2 | {
"input": [
"2A:13\n",
"11:20\n",
"000B:00001\n",
"Z:1\n",
"123:A\n",
"N:7\n",
"00001:00001\n",
"1:11\n",
"000G6:000GD\n",
"0:1N\n",
"Z:2\n",
"0:Z\n",
"Z:00\n",
"0:1A\n",
"000Z:000Z\n",
"0Z:01\n",
"A:10\n",
"00Z:01\n",
"0033:00202\n",
"0... | 2CODEFORCES |
149_B. Martian Clock_2774 | Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" — you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored... | #include <bits/stdc++.h>
using namespace std;
vector<int> a, b, v;
string s;
bool ok(int p) {
bool f = true;
for (int i = 0; i < a.size(); i++) {
f &= a[i] < p;
}
for (int i = 0; i < b.size(); i++) {
f &= b[i] < p;
}
long long h, m;
h = m = 0;
for (int i = 0; i < a.size(); i++) {
h *= p;
... | 2C++ | {
"input": [
"2A:13\n",
"11:20\n",
"000B:00001\n",
"Z:1\n",
"123:A\n",
"N:7\n",
"00001:00001\n",
"1:11\n",
"000G6:000GD\n",
"0:1N\n",
"Z:2\n",
"0:Z\n",
"Z:00\n",
"0:1A\n",
"000Z:000Z\n",
"0Z:01\n",
"A:10\n",
"00Z:01\n",
"0033:00202\n",
"0... | 2CODEFORCES |
149_B. Martian Clock_2775 | Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" — you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored... | s = input()
a = s[:s.index(":")]
b = s[s.index(":")+1:]
a2 = ''
b2 = ''
found = False
for i in a:
if i!='0':
found = True
if found:
a2+=i
found = False
for i in b:
if i!='0':
found = True
if found:
b2+=i
a = a2
b = b2
apos = []
bpos = []
values = ['0', '1', '2'... | 3Python3 | {
"input": [
"2A:13\n",
"11:20\n",
"000B:00001\n",
"Z:1\n",
"123:A\n",
"N:7\n",
"00001:00001\n",
"1:11\n",
"000G6:000GD\n",
"0:1N\n",
"Z:2\n",
"0:Z\n",
"Z:00\n",
"0:1A\n",
"000Z:000Z\n",
"0Z:01\n",
"A:10\n",
"00Z:01\n",
"0033:00202\n",
"0... | 2CODEFORCES |
149_B. Martian Clock_2776 | Having stayed home alone, Petya decided to watch forbidden films on the Net in secret. "What ungentlemanly behavior!" — you can say that, of course, but don't be too harsh on the kid. In his country films about the Martians and other extraterrestrial civilizations are forbidden. It was very unfair to Petya as he adored... | import java.util.Scanner;
public class Solution {
private final static String voc = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
private static int[] toArray(String s) {
while (s.length() > 1 && s.charAt(0) == '0') s = s.substring(1);
int[] a = new int[s.length()];
for (int i = 0; i < a.le... | 4JAVA | {
"input": [
"2A:13\n",
"11:20\n",
"000B:00001\n",
"Z:1\n",
"123:A\n",
"N:7\n",
"00001:00001\n",
"1:11\n",
"000G6:000GD\n",
"0:1N\n",
"Z:2\n",
"0:Z\n",
"Z:00\n",
"0:1A\n",
"000Z:000Z\n",
"0Z:01\n",
"A:10\n",
"00Z:01\n",
"0033:00202\n",
"0... | 2CODEFORCES |
1523_B. Lord of the Values_2777 | <image>
While trading on his favorite exchange trader William realized that he found a vulnerability. Using this vulnerability he could change the values of certain internal variables to his advantage. To play around he decided to change the values of all internal variables from a_1, a_2, …, a_n to -a_1, -a_2, …, -a_n... | import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')
for _ in x... | 1Python2 | {
"input": [
"2\n4\n1 1 1 1\n4\n4 3 1 2\n",
"2\n4\n1 1 1 1\n4\n4 3 1 2\n",
"2\n4\n1 0 1 1\n4\n4 3 1 2\n",
"2\n4\n1 1 1 1\n4\n4 3 1 4\n",
"2\n4\n1 1 1 1\n4\n4 5 1 2\n",
"2\n4\n1 1 0 1\n4\n4 3 1 4\n",
"2\n4\n1 1 1 1\n4\n4 5 1 3\n",
"2\n4\n1 2 1 1\n4\n4 5 1 3\n",
"2\n4\n1 2 1 1\n4\n4 ... | 2CODEFORCES |
1523_B. Lord of the Values_2778 | <image>
While trading on his favorite exchange trader William realized that he found a vulnerability. Using this vulnerability he could change the values of certain internal variables to his advantage. To play around he decided to change the values of all internal variables from a_1, a_2, …, a_n to -a_1, -a_2, …, -a_n... | #include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define fi first
//#define se second
typedef long long ll;
const ll INF=1e18*9;
const int N=1e6+15;
const int M=203;
const int mod1=1e9+7;
const int mod=998244353;
const int base=131;
int n,m,k,ans,x,y,mid,sx=-1,sy=-1,mx,mi=INF,aa,cnt=... | 2C++ | {
"input": [
"2\n4\n1 1 1 1\n4\n4 3 1 2\n",
"2\n4\n1 1 1 1\n4\n4 3 1 2\n",
"2\n4\n1 0 1 1\n4\n4 3 1 2\n",
"2\n4\n1 1 1 1\n4\n4 3 1 4\n",
"2\n4\n1 1 1 1\n4\n4 5 1 2\n",
"2\n4\n1 1 0 1\n4\n4 3 1 4\n",
"2\n4\n1 1 1 1\n4\n4 5 1 3\n",
"2\n4\n1 2 1 1\n4\n4 5 1 3\n",
"2\n4\n1 2 1 1\n4\n4 ... | 2CODEFORCES |
1523_B. Lord of the Values_2779 | <image>
While trading on his favorite exchange trader William realized that he found a vulnerability. Using this vulnerability he could change the values of certain internal variables to his advantage. To play around he decided to change the values of all internal variables from a_1, a_2, …, a_n to -a_1, -a_2, …, -a_n... | import os
import sys
from io import BytesIO, IOBase
from collections import Counter
import math as mt
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
... | 3Python3 | {
"input": [
"2\n4\n1 1 1 1\n4\n4 3 1 2\n",
"2\n4\n1 1 1 1\n4\n4 3 1 2\n",
"2\n4\n1 0 1 1\n4\n4 3 1 2\n",
"2\n4\n1 1 1 1\n4\n4 3 1 4\n",
"2\n4\n1 1 1 1\n4\n4 5 1 2\n",
"2\n4\n1 1 0 1\n4\n4 3 1 4\n",
"2\n4\n1 1 1 1\n4\n4 5 1 3\n",
"2\n4\n1 2 1 1\n4\n4 5 1 3\n",
"2\n4\n1 2 1 1\n4\n4 ... | 2CODEFORCES |
1523_B. Lord of the Values_2780 | <image>
While trading on his favorite exchange trader William realized that he found a vulnerability. Using this vulnerability he could change the values of certain internal variables to his advantage. To play around he decided to change the values of all internal variables from a_1, a_2, …, a_n to -a_1, -a_2, …, -a_n... | /**
* @Author : lucent868
* @Date : 5/30/21
* @Time : 8:33 PM
*/
import java.util.*;
import java.io.*;
import java.math.*;
public class B {
static InputReader in;
static PrintWriter w;
public static void main(String args[]) {
new Thread(null, new Runnable() {
public void run() {
... | 4JAVA | {
"input": [
"2\n4\n1 1 1 1\n4\n4 3 1 2\n",
"2\n4\n1 1 1 1\n4\n4 3 1 2\n",
"2\n4\n1 0 1 1\n4\n4 3 1 2\n",
"2\n4\n1 1 1 1\n4\n4 3 1 4\n",
"2\n4\n1 1 1 1\n4\n4 5 1 2\n",
"2\n4\n1 1 0 1\n4\n4 3 1 4\n",
"2\n4\n1 1 1 1\n4\n4 5 1 3\n",
"2\n4\n1 2 1 1\n4\n4 5 1 3\n",
"2\n4\n1 2 1 1\n4\n4 ... | 2CODEFORCES |
155_A. I_love_%username%_2781 | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | import sys
def readints() :
l = sys.stdin.readline()
return map(int, l.split(' '))
def readstring() :
l = sys.stdin.readline()[:-1]
return l
def readint() :
l = sys.stdin.readline()
return int(l)
def clearchars(s, chars) :
for c in chars :
s = s.replace(c, '')
return s
def g... | 1Python2 | {
"input": [
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n",
"5\n100 50 200 150 200\n",
"5\n100 36 53 7 81\n",
"5\n100 81 53 36 7\n",
"10\n8 6 3 4 9 10 7 7 1 3\n",
"33\n1097 1132 1091 1104 1049 1038 1023 1080 1104 1029 1035 1061 1049 1060 1088 1106 1105 1087 1063 1076 1054 1103 1047... | 2CODEFORCES |
155_A. I_love_%username%_2782 | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | #include <bits/stdc++.h>
int main() {
int n, cnt = 0;
scanf("%d", &n);
int a[n];
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
int maxx = a[0];
int minn = a[0];
for (int i = 0; i < n; i++) {
if (a[i] > maxx) {
maxx = a[i];
cnt++;
}
if (a[i] < minn) {
minn = a[i];
... | 2C++ | {
"input": [
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n",
"5\n100 50 200 150 200\n",
"5\n100 36 53 7 81\n",
"5\n100 81 53 36 7\n",
"10\n8 6 3 4 9 10 7 7 1 3\n",
"33\n1097 1132 1091 1104 1049 1038 1023 1080 1104 1029 1035 1061 1049 1060 1088 1106 1105 1087 1063 1076 1054 1103 1047... | 2CODEFORCES |
155_A. I_love_%username%_2783 | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | n=int(input())
a=list(map(int,input().split()))
c=[]
d=0
c.append(a[0])
for i in range(1,n):
y=a[i]-a[i-1]
if y>0 and a[i]>max(c):
c.append(a[i])
d+=1
elif y<0 and a[i]<min(c):
c.append(a[i])
d+=1
print(d)
#print(c) | 3Python3 | {
"input": [
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n",
"5\n100 50 200 150 200\n",
"5\n100 36 53 7 81\n",
"5\n100 81 53 36 7\n",
"10\n8 6 3 4 9 10 7 7 1 3\n",
"33\n1097 1132 1091 1104 1049 1038 1023 1080 1104 1029 1035 1061 1049 1060 1088 1106 1105 1087 1063 1076 1054 1103 1047... | 2CODEFORCES |
155_A. I_love_%username%_2784 | Vasya adores sport programming. He can't write programs but he loves to watch the contests' progress. Vasya even has a favorite coder and Vasya pays special attention to him.
One day Vasya decided to collect the results of all contests where his favorite coder participated and track the progress of his coolness. For e... | import java.util.Scanner;
/**
*
* @author Krolos
*/
public class AI_love_Username {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner k = new Scanner(System.in);
int n = k.nextInt();
int arr[] = new int[n];
int sum = 0... | 4JAVA | {
"input": [
"10\n4664 6496 5814 7010 5762 5736 6944 4850 3698 7242\n",
"5\n100 50 200 150 200\n",
"5\n100 36 53 7 81\n",
"5\n100 81 53 36 7\n",
"10\n8 6 3 4 9 10 7 7 1 3\n",
"33\n1097 1132 1091 1104 1049 1038 1023 1080 1104 1029 1035 1061 1049 1060 1088 1106 1105 1087 1063 1076 1054 1103 1047... | 2CODEFORCES |
177_C1. Party_2785 | To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friends... | import sys
import heapq
import bisect
import math
INF = 10**9+7
OFFLINE = 0
N = 101010
sys.setrecursionlimit(INF)
def fi():
return int(sys.stdin.readline())
def fi2():
return map(int, sys.stdin.readline().split())
def fi3():
return sys.stdin.readline().rstrip()
def fo(*args):
for s in args:
sys.stdout.write(... | 1Python2 | {
"input": [
"9\n8\n1 2\n1 3\n2 3\n4 5\n6 7\n7 8\n8 9\n9 6\n2\n1 6\n7 9\n",
"14\n0\n0\n",
"14\n6\n1 2\n2 3\n3 4\n4 5\n8 9\n9 10\n3\n5 6\n6 7\n7 8\n",
"14\n10\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n2 3\n2 4\n2 5\n2 6\n1\n2 7\n",
"14\n20\n1 2\n4 5\n4 6\n4 11\n5 7\n5 8\n5 13\n5 14\n7 8\n7 14\n8 9\n8 11\n8 12... | 2CODEFORCES |
177_C1. Party_2786 | To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friends... | #include <bits/stdc++.h>
using namespace std;
const long long N_max = 0;
class graph {
private:
long long V;
long long k, m;
vector<pair<long long, long long>> L;
vector<pair<long long, long long>> L2;
public:
graph(long long n) { V = n; }
void add_edge(long long u, long long v) { L.push_back({u, v}); }
... | 2C++ | {
"input": [
"9\n8\n1 2\n1 3\n2 3\n4 5\n6 7\n7 8\n8 9\n9 6\n2\n1 6\n7 9\n",
"14\n0\n0\n",
"14\n6\n1 2\n2 3\n3 4\n4 5\n8 9\n9 10\n3\n5 6\n6 7\n7 8\n",
"14\n10\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n2 3\n2 4\n2 5\n2 6\n1\n2 7\n",
"14\n20\n1 2\n4 5\n4 6\n4 11\n5 7\n5 8\n5 13\n5 14\n7 8\n7 14\n8 9\n8 11\n8 12... | 2CODEFORCES |
177_C1. Party_2787 | To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friends... | # maa chudaaye duniya
n = int(input())
parents = [i for i in range(n+1)]
ranks = [1 for i in range(n+1)]
def find(x):
if parents[x] != x:
parents[x] = find(parents[x])
return parents[x]
def union(x, y):
xs = find(x)
ys = find(y)
if xs == ys:
return
if ranks[xs] > ranks[ys]:
parents[ys] = xs
elif ranks[ys... | 3Python3 | {
"input": [
"9\n8\n1 2\n1 3\n2 3\n4 5\n6 7\n7 8\n8 9\n9 6\n2\n1 6\n7 9\n",
"14\n0\n0\n",
"14\n6\n1 2\n2 3\n3 4\n4 5\n8 9\n9 10\n3\n5 6\n6 7\n7 8\n",
"14\n10\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n2 3\n2 4\n2 5\n2 6\n1\n2 7\n",
"14\n20\n1 2\n4 5\n4 6\n4 11\n5 7\n5 8\n5 13\n5 14\n7 8\n7 14\n8 9\n8 11\n8 12... | 2CODEFORCES |
177_C1. Party_2788 | To celebrate the second ABBYY Cup tournament, the Smart Beaver decided to throw a party. The Beaver has a lot of acquaintances, some of them are friends with each other, and some of them dislike each other. To make party successful, the Smart Beaver wants to invite only those of his friends who are connected by friends... | 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.io.StreamTokenizer;
import java.util.Arrays;
public class C {
static StreamTokenizer st;
public static void ma... | 4JAVA | {
"input": [
"9\n8\n1 2\n1 3\n2 3\n4 5\n6 7\n7 8\n8 9\n9 6\n2\n1 6\n7 9\n",
"14\n0\n0\n",
"14\n6\n1 2\n2 3\n3 4\n4 5\n8 9\n9 10\n3\n5 6\n6 7\n7 8\n",
"14\n10\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n2 3\n2 4\n2 5\n2 6\n1\n2 7\n",
"14\n20\n1 2\n4 5\n4 6\n4 11\n5 7\n5 8\n5 13\n5 14\n7 8\n7 14\n8 9\n8 11\n8 12... | 2CODEFORCES |
198_B. Jumping on Walls_2789 | Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.
The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some... | # http://codeforces.com/problemset/problem/199/D
from collections import deque
from sys import stdin
def readNums():
return [int(x) for x in stdin.readline().split()]
height, jump_height = readNums()
# 0 - left, 1, right
walls = [stdin.readline().strip(), stdin.readline().strip()]
def canGoTo(walls, wall, heigh... | 1Python2 | {
"input": [
"7 3\n---X--X\n-X--XX-\n",
"6 2\n--X-X-\nX--XX-\n",
"2 1\n-X\nX-\n",
"25 3\n-XXXXX-XXXXX-XXXXX-X-XXXX\nXXX-XXXXX-XXXXX-X-----X--\n",
"6 2\n--X--X\nXX-X-X\n",
"12 3\n--XX--XX-XXX\n----X---XXX-\n",
"101 1\n-------------------------------------------------------------------------... | 2CODEFORCES |
198_B. Jumping on Walls_2790 | Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.
The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some... | #include <bits/stdc++.h>
using namespace std;
int f[200000][3], N, K;
char s1[200000], s2[200000];
bool ok;
inline void dfs(int x, int y) {
if (ok) return;
int Nxt = x + K;
if (Nxt > N) {
ok = 1;
return;
}
if (y == 1) {
if (s2[Nxt] == '-' && f[x][1] + 1 < f[Nxt][2] && Nxt > f[x][1] + 1) {
f[... | 2C++ | {
"input": [
"7 3\n---X--X\n-X--XX-\n",
"6 2\n--X-X-\nX--XX-\n",
"2 1\n-X\nX-\n",
"25 3\n-XXXXX-XXXXX-XXXXX-X-XXXX\nXXX-XXXXX-XXXXX-X-----X--\n",
"6 2\n--X--X\nXX-X-X\n",
"12 3\n--XX--XX-XXX\n----X---XXX-\n",
"101 1\n-------------------------------------------------------------------------... | 2CODEFORCES |
198_B. Jumping on Walls_2791 | Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.
The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some... | from sys import stdin, stdout
from collections import deque
n, k = map(int, stdin.readline().split())
maps = []
maps.append(list(stdin.readline() + '-'))
maps.append(list(stdin.readline() + '-'))
visit = [[0, 0] for i in range(n + 1)]
visit[0][0] = 1
queue = deque()
label = 0
queue.append((0, -1, 0))#твой уровень, ... | 3Python3 | {
"input": [
"7 3\n---X--X\n-X--XX-\n",
"6 2\n--X-X-\nX--XX-\n",
"2 1\n-X\nX-\n",
"25 3\n-XXXXX-XXXXX-XXXXX-X-XXXX\nXXX-XXXXX-XXXXX-X-----X--\n",
"6 2\n--X--X\nXX-X-X\n",
"12 3\n--XX--XX-XXX\n----X---XXX-\n",
"101 1\n-------------------------------------------------------------------------... | 2CODEFORCES |
198_B. Jumping on Walls_2792 | Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon.
The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and number them with positive integers from 1 to n from bottom to top. Some... | import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
public class B198 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int N = in.nextInt();
int K = in.nextInt();
char[] L = in.next().toCharArray();
char[] R = in.nex... | 4JAVA | {
"input": [
"7 3\n---X--X\n-X--XX-\n",
"6 2\n--X-X-\nX--XX-\n",
"2 1\n-X\nX-\n",
"25 3\n-XXXXX-XXXXX-XXXXX-X-XXXX\nXXX-XXXXX-XXXXX-X-----X--\n",
"6 2\n--X--X\nXX-X-X\n",
"12 3\n--XX--XX-XXX\n----X---XXX-\n",
"101 1\n-------------------------------------------------------------------------... | 2CODEFORCES |
221_C. Little Elephant and Problem_2793 | The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array.
The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could ... |
n = int(raw_input())
a = map(int, raw_input().split())
def main():
if n<3:
print 'YES'
return
b = a[:]
b.sort()
s=0
for i in range(n):
s += int(a[i] != b[i])
if s>2:
print 'NO'
return
print 'YES'
main() | 1Python2 | {
"input": [
"3\n3 2 1\n",
"4\n4 3 2 1\n",
"2\n1 2\n",
"10\n4 4 4 4 10 4 4 4 4 4\n",
"5\n1 3 2 3 3\n",
"5\n1 2 7 3 5\n",
"11\n2 2 2 2 2 2 2 2 2 2 1\n",
"6\n1 4 3 6 2 5\n",
"50\n6 7 8 4 10 3 2 7 1 3 10 3 4 7 2 3 7 4 10 6 8 10 9 6 5 10 9 6 1 8 9 4 3 7 3 10 5 3 10 1 6 10 6 7 10 7 1 5 ... | 2CODEFORCES |
221_C. Little Elephant and Problem_2794 | The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array.
The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could ... | #include <bits/stdc++.h>
using namespace std;
void swap(int &x, int &y) {
int t = x;
x = y;
y = t;
}
int main() {
int n;
cin >> n;
int *p = new int[n];
vector<int> k;
for (int i = 0; i < n; i++) {
cin >> p[i];
k.push_back(p[i]);
}
sort(k.begin(), k.end());
int count = 0;
for (int i = 0; ... | 2C++ | {
"input": [
"3\n3 2 1\n",
"4\n4 3 2 1\n",
"2\n1 2\n",
"10\n4 4 4 4 10 4 4 4 4 4\n",
"5\n1 3 2 3 3\n",
"5\n1 2 7 3 5\n",
"11\n2 2 2 2 2 2 2 2 2 2 1\n",
"6\n1 4 3 6 2 5\n",
"50\n6 7 8 4 10 3 2 7 1 3 10 3 4 7 2 3 7 4 10 6 8 10 9 6 5 10 9 6 1 8 9 4 3 7 3 10 5 3 10 1 6 10 6 7 10 7 1 5 ... | 2CODEFORCES |
221_C. Little Elephant and Problem_2795 | The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array.
The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could ... | n = int(input())
a = list(map(int, input().split()))
b = sorted(a)
res = 0
for i in range(n):
if a[i] != b[i]:
res += 1
print('YES' if res <= 2 else 'NO') | 3Python3 | {
"input": [
"3\n3 2 1\n",
"4\n4 3 2 1\n",
"2\n1 2\n",
"10\n4 4 4 4 10 4 4 4 4 4\n",
"5\n1 3 2 3 3\n",
"5\n1 2 7 3 5\n",
"11\n2 2 2 2 2 2 2 2 2 2 1\n",
"6\n1 4 3 6 2 5\n",
"50\n6 7 8 4 10 3 2 7 1 3 10 3 4 7 2 3 7 4 10 6 8 10 9 6 5 10 9 6 1 8 9 4 3 7 3 10 5 3 10 1 6 10 6 7 10 7 1 5 ... | 2CODEFORCES |
221_C. Little Elephant and Problem_2796 | The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array.
The Little Elephant doesn't want to call the police until he understands if he could have accidentally changed the array himself. He thinks that he could ... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
void solve() throws IOException {
int n = nextInt();
int[] a = new int[n];
In... | 4JAVA | {
"input": [
"3\n3 2 1\n",
"4\n4 3 2 1\n",
"2\n1 2\n",
"10\n4 4 4 4 10 4 4 4 4 4\n",
"5\n1 3 2 3 3\n",
"5\n1 2 7 3 5\n",
"11\n2 2 2 2 2 2 2 2 2 2 1\n",
"6\n1 4 3 6 2 5\n",
"50\n6 7 8 4 10 3 2 7 1 3 10 3 4 7 2 3 7 4 10 6 8 10 9 6 5 10 9 6 1 8 9 4 3 7 3 10 5 3 10 1 6 10 6 7 10 7 1 5 ... | 2CODEFORCES |
245_D. Restoring Table_2797 | Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation.
For that Polycarpus came to school a little earlier and wrote on the board a sequence of non-negative ... | n=int(raw_input())
for i in xrange(n):
tt=0
for j in map(int,raw_input().split()):
if j!=-1:
tt=tt | j
print tt,
print
| 1Python2 | {
"input": [
"3\n-1 18 0\n18 -1 0\n0 0 -1\n",
"4\n-1 128 128 128\n128 -1 148 160\n128 148 -1 128\n128 160 128 -1\n",
"1\n-1\n",
"6\n-1 1835024 1966227 34816 68550800 34832\n1835024 -1 18632728 306185992 324272924 289412624\n1966227 18632728 -1 40 555155640 16846864\n34816 306185992 40 -1 306185000 272... | 2CODEFORCES |
245_D. Restoring Table_2798 | Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation.
For that Polycarpus came to school a little earlier and wrote on the board a sequence of non-negative ... | #include <bits/stdc++.h>
using namespace std;
int n;
void EXEC() {
cin >> n;
for (int i = 0; i < n; ++i) {
int s = 0;
int t;
for (int j = 0; j < n; ++j) {
cin >> t;
if (t != -1) s |= t;
}
cout << s << ' ';
}
cout << endl;
}
int main() {
EXEC();
return 0;
}
| 2C++ | {
"input": [
"3\n-1 18 0\n18 -1 0\n0 0 -1\n",
"4\n-1 128 128 128\n128 -1 148 160\n128 148 -1 128\n128 160 128 -1\n",
"1\n-1\n",
"6\n-1 1835024 1966227 34816 68550800 34832\n1835024 -1 18632728 306185992 324272924 289412624\n1966227 18632728 -1 40 555155640 16846864\n34816 306185992 40 -1 306185000 272... | 2CODEFORCES |
245_D. Restoring Table_2799 | Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation.
For that Polycarpus came to school a little earlier and wrote on the board a sequence of non-negative ... | n=int(input())
A=[0]*n
ans=[0]*n
for i in range(n):
A[i]=list(map(int,input().split()))
for j in range(n):
if(j==i):continue
ans[i]|=A[i][j]
for i in range(n):
print(ans[i],' ',end='')
| 3Python3 | {
"input": [
"3\n-1 18 0\n18 -1 0\n0 0 -1\n",
"4\n-1 128 128 128\n128 -1 148 160\n128 148 -1 128\n128 160 128 -1\n",
"1\n-1\n",
"6\n-1 1835024 1966227 34816 68550800 34832\n1835024 -1 18632728 306185992 324272924 289412624\n1966227 18632728 -1 40 555155640 16846864\n34816 306185992 40 -1 306185000 272... | 2CODEFORCES |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.