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 |
|---|---|---|---|---|---|
245_D. Restoring Table_2800 | 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 ... | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Constructor;
import java.util.Arrays;
import java.util.StringTokenizer;
public class CodeC
{
static class Scanner
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringT... | 4JAVA | {
"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 |
270_B. Multithreading_2801 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.
Recent actions shows a list of n different threads ordered by the time of the latest message in the thread.... | n = int(raw_input())
nums = map(int,raw_input().split())[::-1]
idx = 0
pre = n + 1
for num in nums:
if num < pre:
idx += 1
pre = num
else:
break
print n-idx | 1Python2 | {
"input": [
"5\n5 2 1 3 4\n",
"4\n4 3 2 1\n",
"3\n1 2 3\n",
"4\n2 3 1 4\n",
"3\n1 3 2\n",
"6\n3 2 1 6 4 5\n",
"67\n45 48 40 32 11 36 18 47 56 3 22 27 37 12 25 8 57 66 50 41 49 42 30 28 14 62 43 51 9 63 13 1 2 4 5 6 7 10 15 16 17 19 20 21 23 24 26 29 31 33 34 35 38 39 44 46 52 53 54 55 58 ... | 2CODEFORCES |
270_B. Multithreading_2802 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.
Recent actions shows a list of n different threads ordered by the time of the latest message in the thread.... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int ant;
scanf("%d", &ant);
int max_mes = 0;
for (int i = 1; i < n; i++) {
int aux;
scanf("%d", &aux);
if (aux < ant) max_mes = i;
ant = aux;
}
printf("%d\n", max_mes);
return 0;
}
| 2C++ | {
"input": [
"5\n5 2 1 3 4\n",
"4\n4 3 2 1\n",
"3\n1 2 3\n",
"4\n2 3 1 4\n",
"3\n1 3 2\n",
"6\n3 2 1 6 4 5\n",
"67\n45 48 40 32 11 36 18 47 56 3 22 27 37 12 25 8 57 66 50 41 49 42 30 28 14 62 43 51 9 63 13 1 2 4 5 6 7 10 15 16 17 19 20 21 23 24 26 29 31 33 34 35 38 39 44 46 52 53 54 55 58 ... | 2CODEFORCES |
270_B. Multithreading_2803 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.
Recent actions shows a list of n different threads ordered by the time of the latest message in the thread.... | n = int(input())
arr = list(map(int,input().split()))
ans = n-1
for i in range(-1,-n,-1):
if arr[i]>arr[i-1]:
ans-=1
else:
break
print(ans) | 3Python3 | {
"input": [
"5\n5 2 1 3 4\n",
"4\n4 3 2 1\n",
"3\n1 2 3\n",
"4\n2 3 1 4\n",
"3\n1 3 2\n",
"6\n3 2 1 6 4 5\n",
"67\n45 48 40 32 11 36 18 47 56 3 22 27 37 12 25 8 57 66 50 41 49 42 30 28 14 62 43 51 9 63 13 1 2 4 5 6 7 10 15 16 17 19 20 21 23 24 26 29 31 33 34 35 38 39 44 46 52 53 54 55 58 ... | 2CODEFORCES |
270_B. Multithreading_2804 | Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.
Recent actions shows a list of n different threads ordered by the time of the latest message in the thread.... | import java.util.Scanner;
public class B270 {
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();
}
int pos = N-1;
while (pos > 0... | 4JAVA | {
"input": [
"5\n5 2 1 3 4\n",
"4\n4 3 2 1\n",
"3\n1 2 3\n",
"4\n2 3 1 4\n",
"3\n1 3 2\n",
"6\n3 2 1 6 4 5\n",
"67\n45 48 40 32 11 36 18 47 56 3 22 27 37 12 25 8 57 66 50 41 49 42 30 28 14 62 43 51 9 63 13 1 2 4 5 6 7 10 15 16 17 19 20 21 23 24 26 29 31 33 34 35 38 39 44 46 52 53 54 55 58 ... | 2CODEFORCES |
293_D. Ksusha and Square_2805 | Ksusha is a vigorous mathematician. She is keen on absolutely incredible mathematical riddles.
Today Ksusha came across a convex polygon of non-zero area. She is now wondering: if she chooses a pair of distinct points uniformly among all integer points (points with integer coordinates) inside or on the border of the ... | #include <bits/stdc++.h>
using namespace std;
struct Point {
int x, y;
Point() {}
Point(int x, int y) {
this->x = x;
this->y = y;
}
Point operator+(Point rhs) { return Point(x + rhs.x, y + rhs.y); }
Point operator-(Point rhs) { return Point(x - rhs.x, y - rhs.y); }
long long Dot(Point rhs) { retur... | 2C++ | {
"input": [
"3\n17 136\n859 937\n16 641\n",
"4\n-1 3\n4 5\n6 2\n3 -5\n",
"3\n0 0\n5 5\n5 0\n",
"3\n217949 72327\n20730 141135\n667478 391012\n",
"28\n-999992 -308892\n-999961 -775849\n-999942 -893083\n-999456 -939329\n-999012 -979265\n-997835 -988395\n-989576 -999615\n-707413 -999804\n-356518 -99... | 2CODEFORCES |
293_D. Ksusha and Square_2806 | Ksusha is a vigorous mathematician. She is keen on absolutely incredible mathematical riddles.
Today Ksusha came across a convex polygon of non-zero area. She is now wondering: if she chooses a pair of distinct points uniformly among all integer points (points with integer coordinates) inside or on the border of the ... | import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.io.PrintStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Random;
import java.io.Writer;
import java.util.Collection;
import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException... | 4JAVA | {
"input": [
"3\n17 136\n859 937\n16 641\n",
"4\n-1 3\n4 5\n6 2\n3 -5\n",
"3\n0 0\n5 5\n5 0\n",
"3\n217949 72327\n20730 141135\n667478 391012\n",
"28\n-999992 -308892\n-999961 -775849\n-999942 -893083\n-999456 -939329\n-999012 -979265\n-997835 -988395\n-989576 -999615\n-707413 -999804\n-356518 -99... | 2CODEFORCES |
317_B. Ants_2807 | It has been noted that if some ants are put in the junctions of the graphene integer lattice then they will act in the following fashion: every minute at each junction (x, y) containing at least four ants a group of four ants will be formed, and these four ants will scatter to the neighbouring junctions (x + 1, y), (x ... | #include <bits/stdc++.h>
int n, t;
int q[50000][5];
int sh[2500][2500];
bool vis[2500][2500];
void bfs() {
int i = 0, j = 1;
sh[1000][1000] = n;
q[0][0] = 1000;
q[0][1] = 1000;
while (i < j) {
int x = q[i % 40000][0], y = q[i % 40000][1];
sh[x + 1][y] += sh[x][y] / 4;
sh[x - 1][y] += sh[x][y] / 4;... | 2C++ | {
"input": [
"6 5\n0 -2\n0 -1\n0 0\n0 1\n0 2\n",
"1 3\n0 1\n0 0\n0 -1\n",
"203 30\n-3 3\n-3 10\n-7 -6\n1 8\n-5 2\n-9 10\n-6 4\n8 2\n-2 -5\n-3 2\n1 6\n-6 -9\n10 9\n-3 -9\n-7 5\n3 8\n1 -4\n-4 -5\n-2 1\n-6 -10\n10 10\n4 -1\n0 -2\n9 9\n-5 6\n-9 -5\n7 -10\n-6 3\n-3 -4\n9 -4\n",
"25965 53\n-1 -2\n1 5\n0 3\n... | 2CODEFORCES |
317_B. Ants_2808 | It has been noted that if some ants are put in the junctions of the graphene integer lattice then they will act in the following fashion: every minute at each junction (x, y) containing at least four ants a group of four ants will be formed, and these four ants will scatter to the neighbouring junctions (x + 1, y), (x ... | from sys import *
f = lambda: map(int, stdin.readline().split())
n, t = f()
m = 65
r = range(m)
p = [[0] * m for i in r]
p[1][0] = n // 4
p[0][0] = n % 4
q = k = 1
while q:
k += 1
q = 0
for x in r[1:k]:
for y in r[:x + 1]:
if p[x][y] < 4: continue
q = 1
d = ... | 3Python3 | {
"input": [
"6 5\n0 -2\n0 -1\n0 0\n0 1\n0 2\n",
"1 3\n0 1\n0 0\n0 -1\n",
"203 30\n-3 3\n-3 10\n-7 -6\n1 8\n-5 2\n-9 10\n-6 4\n8 2\n-2 -5\n-3 2\n1 6\n-6 -9\n10 9\n-3 -9\n-7 5\n3 8\n1 -4\n-4 -5\n-2 1\n-6 -10\n10 10\n4 -1\n0 -2\n9 9\n-5 6\n-9 -5\n7 -10\n-6 3\n-3 -4\n9 -4\n",
"25965 53\n-1 -2\n1 5\n0 3\n... | 2CODEFORCES |
317_B. Ants_2809 | It has been noted that if some ants are put in the junctions of the graphene integer lattice then they will act in the following fashion: every minute at each junction (x, y) containing at least four ants a group of four ants will be formed, and these four ants will scatter to the neighbouring junctions (x + 1, y), (x ... | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class B {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter out = new PrintWriter(System.out);
String[] parts = br.rea... | 4JAVA | {
"input": [
"6 5\n0 -2\n0 -1\n0 0\n0 1\n0 2\n",
"1 3\n0 1\n0 0\n0 -1\n",
"203 30\n-3 3\n-3 10\n-7 -6\n1 8\n-5 2\n-9 10\n-6 4\n8 2\n-2 -5\n-3 2\n1 6\n-6 -9\n10 9\n-3 -9\n-7 5\n3 8\n1 -4\n-4 -5\n-2 1\n-6 -10\n10 10\n4 -1\n0 -2\n9 9\n-5 6\n-9 -5\n7 -10\n-6 3\n-3 -4\n9 -4\n",
"25965 53\n-1 -2\n1 5\n0 3\n... | 2CODEFORCES |
341_B. Bubble Sort Graph_2810 | Iahub recently has learned Bubble Sort, an algorithm that is used to sort a permutation with n elements a1, a2, ..., an in ascending order. He is bored of this so simple algorithm, so he invents his own graph. The graph (let's call it G) initially has n vertices and 0 edges. During Bubble Sort execution, edges appear a... | from bisect import bisect
n, oo = input(), 1 << 20
a = [oo] * n
for x in map(int, raw_input().split()):
a[bisect(a, x)] = x
print bisect(a, oo - 1)
| 1Python2 | {
"input": [
"3\n3 1 2\n",
"100\n36 48 92 87 28 85 42 10 44 41 39 3 79 9 14 56 1 16 46 35 93 8 82 26 100 59 60 2 96 52 13 98 70 81 71 94 54 91 17 88 33 30 19 50 18 73 65 29 78 21 61 7 99 97 45 89 57 27 76 11 49 72 84 69 43 62 4 22 75 6 66 83 38 34 86 15 40 51 37 74 67 31 20 63 77 80 12 53 5 25 58 90 68 24 64 ... | 2CODEFORCES |
341_B. Bubble Sort Graph_2811 | Iahub recently has learned Bubble Sort, an algorithm that is used to sort a permutation with n elements a1, a2, ..., an in ascending order. He is bored of this so simple algorithm, so he invents his own graph. The graph (let's call it G) initially has n vertices and 0 edges. During Bubble Sort execution, edges appear a... | #include <bits/stdc++.h>
using namespace std;
const int max_n = 1e5 + 100;
int t[4 * max_n];
int n;
int max_on_seg(int v, int tl, int tr, int l, int r) {
if (tl == l && tr == r) return t[v];
int m = (tl + tr) >> 1;
if (r <= m) return max_on_seg(2 * v, tl, m, l, r);
if (l > m) return max_on_seg(2 * v + 1, m + 1,... | 2C++ | {
"input": [
"3\n3 1 2\n",
"100\n36 48 92 87 28 85 42 10 44 41 39 3 79 9 14 56 1 16 46 35 93 8 82 26 100 59 60 2 96 52 13 98 70 81 71 94 54 91 17 88 33 30 19 50 18 73 65 29 78 21 61 7 99 97 45 89 57 27 76 11 49 72 84 69 43 62 4 22 75 6 66 83 38 34 86 15 40 51 37 74 67 31 20 63 77 80 12 53 5 25 58 90 68 24 64 ... | 2CODEFORCES |
341_B. Bubble Sort Graph_2812 | Iahub recently has learned Bubble Sort, an algorithm that is used to sort a permutation with n elements a1, a2, ..., an in ascending order. He is bored of this so simple algorithm, so he invents his own graph. The graph (let's call it G) initially has n vertices and 0 edges. During Bubble Sort execution, edges appear a... | from bisect import bisect_left, bisect_right, insort
R = lambda: map(int, input().split())
n, arr = int(input()), list(R())
dp = []
for i in range(n):
idx = bisect_left(dp, arr[i])
if idx >= len(dp):
dp.append(arr[i])
else:
dp[idx] = arr[i]
print(len(dp)) | 3Python3 | {
"input": [
"3\n3 1 2\n",
"100\n36 48 92 87 28 85 42 10 44 41 39 3 79 9 14 56 1 16 46 35 93 8 82 26 100 59 60 2 96 52 13 98 70 81 71 94 54 91 17 88 33 30 19 50 18 73 65 29 78 21 61 7 99 97 45 89 57 27 76 11 49 72 84 69 43 62 4 22 75 6 66 83 38 34 86 15 40 51 37 74 67 31 20 63 77 80 12 53 5 25 58 90 68 24 64 ... | 2CODEFORCES |
341_B. Bubble Sort Graph_2813 | Iahub recently has learned Bubble Sort, an algorithm that is used to sort a permutation with n elements a1, a2, ..., an in ascending order. He is bored of this so simple algorithm, so he invents his own graph. The graph (let's call it G) initially has n vertices and 0 edges. During Bubble Sort execution, edges appear a... |
import java.io.*;
import java.lang.reflect.AnnotatedArrayType;
import java.lang.reflect.Array;
import java.util.*;
import java.util.Random;
import java.util.StringTokenizer;
public class Main {
long b = 31;
String fileName = "";
////////////////////// SOLUTION SOLUTION SOLUTION //////////////... | 4JAVA | {
"input": [
"3\n3 1 2\n",
"100\n36 48 92 87 28 85 42 10 44 41 39 3 79 9 14 56 1 16 46 35 93 8 82 26 100 59 60 2 96 52 13 98 70 81 71 94 54 91 17 88 33 30 19 50 18 73 65 29 78 21 61 7 99 97 45 89 57 27 76 11 49 72 84 69 43 62 4 22 75 6 66 83 38 34 86 15 40 51 37 74 67 31 20 63 77 80 12 53 5 25 58 90 68 24 64 ... | 2CODEFORCES |
364_D. Ghd_2814 | John Doe offered his sister Jane Doe find the gcd of some set of numbers a.
Gcd is a positive integer g, such that all number from the set are evenly divisible by g and there isn't such g' (g' > g), that all numbers of the set are evenly divisible by g'.
Unfortunately Jane couldn't cope with the task and John offered... | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
long long a[MAXN], d[MAXN], cnt[MAXN], ans, n, siz;
void cut(long long x) {
siz = 0;
for (long long i = 1; i * i <= x; i++) {
if (x % i == 0) {
d[++siz] = i;
if (x != i * i) d[++siz] = x / i;
}
}
memset(cnt, 0, sizeof(c... | 2C++ | {
"input": [
"6\n6 2 3 4 5 6\n",
"5\n5 5 6 10 15\n",
"1\n1\n",
"1\n7\n",
"2\n1 7\n",
"100\n32 40 7 3 7560 21 7560 7560 10 12 3 7560 7560 7560 7560 5 7560 7560 6 7560 7560 7560 35 7560 18 7560 7560 7560 7560 7560 48 2 7 25 7560 2 2 49 7560 7560 15 16 7560 7560 2 7560 27 7560 7560 7560 7560 3 5 ... | 2CODEFORCES |
364_D. Ghd_2815 | John Doe offered his sister Jane Doe find the gcd of some set of numbers a.
Gcd is a positive integer g, such that all number from the set are evenly divisible by g and there isn't such g' (g' > g), that all numbers of the set are evenly divisible by g'.
Unfortunately Jane couldn't cope with the task and John offered... | import java.io.*;
import java.util.*;
import java.math.*;
public class D implements Runnable {
static BufferedReader in;
static PrintWriter out;
static StringTokenizer st;
static Random rnd;
final int maxFactors = (1 << 14), timeLimit = 3505;
private void solve() throws IOException {
long start = System.curr... | 4JAVA | {
"input": [
"6\n6 2 3 4 5 6\n",
"5\n5 5 6 10 15\n",
"1\n1\n",
"1\n7\n",
"2\n1 7\n",
"100\n32 40 7 3 7560 21 7560 7560 10 12 3 7560 7560 7560 7560 5 7560 7560 6 7560 7560 7560 35 7560 18 7560 7560 7560 7560 7560 48 2 7 25 7560 2 2 49 7560 7560 15 16 7560 7560 2 7560 27 7560 7560 7560 7560 3 5 ... | 2CODEFORCES |
388_C. Fox and Card Game_2816 | Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom o... | def main():
n = int(raw_input())
a = [0, 0]
c = []
for i in xrange(n):
l = map(int, raw_input().split())
m, l = l[0], l[1:]
a[0] += sum(l[:m/2])
a[1] += sum(l) - sum(l[:m-m/2])
if m % 2:
c.append(l[m/2])
c.sort(reverse=True)
for i, x in enumera... | 1Python2 | {
"input": [
"3\n3 1 3 2\n3 5 4 6\n2 8 7\n",
"2\n1 100\n2 1 10\n",
"3\n3 1000 1000 1000\n6 1000 1000 1000 1000 1000 1000\n5 1000 1000 1000 1000 1000\n",
"1\n9 2 8 6 5 9 4 7 1 3\n",
"6\n2 1 1\n2 2 2\n2 3 3\n2 4 4\n2 5 5\n2 6 6\n",
"2\n2 200 1\n3 1 100 2\n",
"2\n3 1 1000 2\n3 2 1 1\n",
"... | 2CODEFORCES |
388_C. Fox and Card Game_2817 | Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom o... | #include <bits/stdc++.h>
using namespace std;
vector<int> vec;
int main() {
int n;
cin >> n;
int A = 0, B = 0;
for (int i = 0; i < n; i++) {
int s;
cin >> s;
for (int j = 0; j < s / 2; j++) {
int x;
cin >> x;
A += x;
}
if (s % 2) {
int x;
cin >> x;
vec.pus... | 2C++ | {
"input": [
"3\n3 1 3 2\n3 5 4 6\n2 8 7\n",
"2\n1 100\n2 1 10\n",
"3\n3 1000 1000 1000\n6 1000 1000 1000 1000 1000 1000\n5 1000 1000 1000 1000 1000\n",
"1\n9 2 8 6 5 9 4 7 1 3\n",
"6\n2 1 1\n2 2 2\n2 3 3\n2 4 4\n2 5 5\n2 6 6\n",
"2\n2 200 1\n3 1 100 2\n",
"2\n3 1 1000 2\n3 2 1 1\n",
"... | 2CODEFORCES |
388_C. Fox and Card Game_2818 | Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom o... | import re
def main():
n=eval(input())
a=[]
s=[]
s.append(0)
s.append(0)
while n:
n-=1
temp=re.split(' ',input())
k=eval(temp[0])
for i in range(k>>1):
s[0]+=eval(temp[i+1])
if k&1:
a.append(eval(temp[(k+1)>>1]))
for i in range((k+1)>>1,k):
s[1]+=eval(temp[i+1])
a... | 3Python3 | {
"input": [
"3\n3 1 3 2\n3 5 4 6\n2 8 7\n",
"2\n1 100\n2 1 10\n",
"3\n3 1000 1000 1000\n6 1000 1000 1000 1000 1000 1000\n5 1000 1000 1000 1000 1000\n",
"1\n9 2 8 6 5 9 4 7 1 3\n",
"6\n2 1 1\n2 2 2\n2 3 3\n2 4 4\n2 5 5\n2 6 6\n",
"2\n2 200 1\n3 1 100 2\n",
"2\n3 1 1000 2\n3 2 1 1\n",
"... | 2CODEFORCES |
388_C. Fox and Card Game_2819 | Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card.
The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top of any non-empty pile, and in Jiro's turn he takes a card from the bottom o... | import java.io.*;
import java.util.*;
public class P388C
{
public static StringTokenizer st;
public static void nextLine(BufferedReader br) throws IOException
{
st = new StringTokenizer(br.readLine());
}
public static String next()
{
return st.nextToken();
}
pu... | 4JAVA | {
"input": [
"3\n3 1 3 2\n3 5 4 6\n2 8 7\n",
"2\n1 100\n2 1 10\n",
"3\n3 1000 1000 1000\n6 1000 1000 1000 1000 1000 1000\n5 1000 1000 1000 1000 1000\n",
"1\n9 2 8 6 5 9 4 7 1 3\n",
"6\n2 1 1\n2 2 2\n2 3 3\n2 4 4\n2 5 5\n2 6 6\n",
"2\n2 200 1\n3 1 100 2\n",
"2\n3 1 1000 2\n3 2 1 1\n",
"... | 2CODEFORCES |
409_A. The Great Game_2820 | Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. Figure out who became the champion.
Input
The input contains two strings of equal length (between ... | import sys
def compare_figures(first, second):
#print 'Compare_figures called. First: {0}, second: {1}'.format(first, second)
return \
first == '[]' and second == '8<' or \
first == '()' and second == '[]' or \
first == '8<' and second == '()'
class Figure(object):
def __init__(sel... | 1Python2 | {
"input": [
"[]()[]8<\n8<[]()8<\n",
"8<8<()\n[]8<[]\n",
"()[][]()()[][]()8<8<\n8<[]()()()8<[][]()()\n",
"[]8<[]()()()[]\n8<[]8<()8<()8<\n",
"8<()8<[]\n()[][]()\n",
"()\n[]\n",
"8<8<8<\n[]()8<\n",
"[]8<[]8<[]()\n8<[]8<8<[]8<\n",
"[]8<8<[]\n[]8<()[]\n",
"8<8<8<... | 2CODEFORCES |
409_A. The Great Game_2821 | Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. Figure out who became the champion.
Input
The input contains two strings of equal length (between ... | #include <bits/stdc++.h>
using namespace std;
string a, b;
int wa, wb;
int main() {
cin >> a >> b;
for (int i = 0; i < a.size(); i += 2) {
if (a[i] == '8' && b[i] == '[') wa++;
if (a[i] == '[' && b[i] == '(') wa++;
if (a[i] == '(' && b[i] == '8') wa++;
if (b[i] == '8' && a[i] == '[') wb++;
if (b... | 2C++ | {
"input": [
"[]()[]8<\n8<[]()8<\n",
"8<8<()\n[]8<[]\n",
"()[][]()()[][]()8<8<\n8<[]()()()8<[][]()()\n",
"[]8<[]()()()[]\n8<[]8<()8<()8<\n",
"8<()8<[]\n()[][]()\n",
"()\n[]\n",
"8<8<8<\n[]()8<\n",
"[]8<[]8<[]()\n8<[]8<8<[]8<\n",
"[]8<8<[]\n[]8<()[]\n",
"8<8<8<... | 2CODEFORCES |
409_A. The Great Game_2822 | Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. Figure out who became the champion.
Input
The input contains two strings of equal length (between ... | """
Codeforces April Fools Contest 2014 Problem A
Author : chaotic_iak
Language: Python 3.3.4
"""
class InputHandlerObject(object):
inputs = []
def getInput(self, n = 0):
res = ""
inputs = self.inputs
if not inputs: inputs.extend(input().split(" "))
if n == 0:
res... | 3Python3 | {
"input": [
"[]()[]8<\n8<[]()8<\n",
"8<8<()\n[]8<[]\n",
"()[][]()()[][]()8<8<\n8<[]()()()8<[][]()()\n",
"[]8<[]()()()[]\n8<[]8<()8<()8<\n",
"8<()8<[]\n()[][]()\n",
"()\n[]\n",
"8<8<8<\n[]()8<\n",
"[]8<[]8<[]()\n8<[]8<8<[]8<\n",
"[]8<8<[]\n[]8<()[]\n",
"8<8<8<... | 2CODEFORCES |
409_A. The Great Game_2823 | Two teams meet in The Game World Championship. Some scientists consider this game to be the most intellectually challenging game in the world. You are given two strings describing the teams' actions in the final battle. Figure out who became the champion.
Input
The input contains two strings of equal length (between ... | import java.util.*;
import static java.lang.System.out;
import static java.lang.Math.*;
public class T {
public static void main(String... args) {
Scanner in = new Scanner(System.in);
String s1 = in.next();
String s2 = in.next();
int score = 0;
for (int i = 0; i < s1.length()-1; i+=2) {
String t1 = s1.su... | 4JAVA | {
"input": [
"[]()[]8<\n8<[]()8<\n",
"8<8<()\n[]8<[]\n",
"()[][]()()[][]()8<8<\n8<[]()()()8<[][]()()\n",
"[]8<[]()()()[]\n8<[]8<()8<()8<\n",
"8<()8<[]\n()[][]()\n",
"()\n[]\n",
"8<8<8<\n[]()8<\n",
"[]8<[]8<[]()\n8<[]8<8<[]8<\n",
"[]8<8<[]\n[]8<()[]\n",
"8<8<8<... | 2CODEFORCES |
436_B. Om Nom and Spiders_2824 | Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all.
<image>
The park can be represented as a rectangular n × m field. The park has k spiders, each spider at ... | x=raw_input().split(' ')
n=int(x[0])
m=int(x[1])
k=int(x[2])
i=0
arr=[]
while i<n:
y=raw_input()
arr.append(y)
i=i+1
j=0
while j<m:
ctr=0
i=1
while i<n:
if (j+i)<m and arr[i][j+i]=='L':
ctr=ctr+1
if (j-i)>=0 and arr[i][j-i]=='R':
ctr=ctr+1
if (i+i)... | 1Python2 | {
"input": [
"2 2 2\n..\nRL\n",
"3 3 4\n...\nR.L\nR.U\n",
"2 2 2\n..\nUU\n",
"3 4 8\n....\nRRLL\nUUUU\n",
"2 2 2\n..\nLR\n",
"3 7 14\n.......\nLDUDLLD\nDLRDDLD\n",
"4 5 15\n.....\nDRRLR\nULDLD\nDLRRL\n",
"10 8 30\n........\n.L.LDRR.\nD.LDLR.U\n..RL.L..\nUR.UL...\n.D.....L\nR..UDULL\n..... | 2CODEFORCES |
436_B. Om Nom and Spiders_2825 | Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all.
<image>
The park can be represented as a rectangular n × m field. The park has k spiders, each spider at ... | #include <bits/stdc++.h>
using namespace std;
char a[2345][2345];
int d[2345][2345];
int dx[] = {1, 0, 0, -1};
int dy[] = {0, 1, -1, 0};
int main() {
int n, m, i, j, k;
cin >> n >> m >> k;
string s = "ULRD";
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
for (j = 1; ... | 2C++ | {
"input": [
"2 2 2\n..\nRL\n",
"3 3 4\n...\nR.L\nR.U\n",
"2 2 2\n..\nUU\n",
"3 4 8\n....\nRRLL\nUUUU\n",
"2 2 2\n..\nLR\n",
"3 7 14\n.......\nLDUDLLD\nDLRDDLD\n",
"4 5 15\n.....\nDRRLR\nULDLD\nDLRRL\n",
"10 8 30\n........\n.L.LDRR.\nD.LDLR.U\n..RL.L..\nUR.UL...\n.D.....L\nR..UDULL\n..... | 2CODEFORCES |
436_B. Om Nom and Spiders_2826 | Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all.
<image>
The park can be represented as a rectangular n × m field. The park has k spiders, each spider at ... | #!/usr/bin/python
import re
import inspect
from sys import argv, exit
def rstr():
return input()
def rint():
return int(input())
def rints(splitchar=' '):
return [int(i) for i in input().split(splitchar)]
def varnames(obj, namespace=globals()):
return [name for name in namespace if namespace[name] i... | 3Python3 | {
"input": [
"2 2 2\n..\nRL\n",
"3 3 4\n...\nR.L\nR.U\n",
"2 2 2\n..\nUU\n",
"3 4 8\n....\nRRLL\nUUUU\n",
"2 2 2\n..\nLR\n",
"3 7 14\n.......\nLDUDLLD\nDLRDDLD\n",
"4 5 15\n.....\nDRRLR\nULDLD\nDLRRL\n",
"10 8 30\n........\n.L.LDRR.\nD.LDLR.U\n..RL.L..\nUR.UL...\n.D.....L\nR..UDULL\n..... | 2CODEFORCES |
436_B. Om Nom and Spiders_2827 | Om Nom really likes candies and doesn't like spiders as they frequently steal candies. One day Om Nom fancied a walk in a park. Unfortunately, the park has some spiders and Om Nom doesn't want to see them at all.
<image>
The park can be represented as a rectangular n × m field. The park has k spiders, each spider at ... | import java.util.Arrays;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Comparator;
import java.io.IOException;
import java.util.StringTokenizer;
import java.math.*;
import java.util.*;
public class ... | 4JAVA | {
"input": [
"2 2 2\n..\nRL\n",
"3 3 4\n...\nR.L\nR.U\n",
"2 2 2\n..\nUU\n",
"3 4 8\n....\nRRLL\nUUUU\n",
"2 2 2\n..\nLR\n",
"3 7 14\n.......\nLDUDLLD\nDLRDDLD\n",
"4 5 15\n.....\nDRRLR\nULDLD\nDLRRL\n",
"10 8 30\n........\n.L.LDRR.\nD.LDLR.U\n..RL.L..\nUR.UL...\n.D.....L\nR..UDULL\n..... | 2CODEFORCES |
459_C. Pashmak and Buses_2828 | Recently Pashmak has been employed in a transportation company. The company has k buses and has a contract with a school which has n students. The school planned to take the students to d different places for d days (each day in one place). Each day the company provides all the buses for the trip. Pashmak has to arrang... | from math import log
[n, k, d] = map(int, raw_input().split(" "))
if d == 1 and n > 1 and k < n:
print "-1"
elif d == 1 and n == 1:
print "1"
else:
out = [[0 for i in range(d)] for j in range(n)]
if k**d < n:
print "-1"
else:
if k > 1000:
k = 1000
start = 0
... | 1Python2 | {
"input": [
"3 2 2\n",
"3 2 1\n",
"2 1 1000\n",
"513 2 9\n",
"512 8 3\n",
"729 9 3\n",
"5 3 2\n",
"9 2 3\n",
"1000 1000000000 1\n",
"729 3 6\n",
"1000 999 1\n",
"1 1 1\n",
"1 1000000000 1\n",
"81 3 4\n",
"1 1 10\n",
"625 5 4\n",
"27 3 3\n",
"100... | 2CODEFORCES |
459_C. Pashmak and Buses_2829 | Recently Pashmak has been employed in a transportation company. The company has k buses and has a contract with a school which has n students. The school planned to take the students to d different places for d days (each day in one place). Each day the company provides all the buses for the trip. Pashmak has to arrang... | #include <bits/stdc++.h>
using namespace std;
template <typename T, size_t N>
int SIZE(const T (&t)[N]) {
return N;
}
template <typename T>
int SIZE(const T &t) {
return t.size();
}
string to_string(const string s, int x1 = 0, int x2 = 1e9) {
return '"' + ((x1 < s.size()) ? s.substr(x1, x2 - x1 + 1) : "") + '"';
... | 2C++ | {
"input": [
"3 2 2\n",
"3 2 1\n",
"2 1 1000\n",
"513 2 9\n",
"512 8 3\n",
"729 9 3\n",
"5 3 2\n",
"9 2 3\n",
"1000 1000000000 1\n",
"729 3 6\n",
"1000 999 1\n",
"1 1 1\n",
"1 1000000000 1\n",
"81 3 4\n",
"1 1 10\n",
"625 5 4\n",
"27 3 3\n",
"100... | 2CODEFORCES |
459_C. Pashmak and Buses_2830 | Recently Pashmak has been employed in a transportation company. The company has k buses and has a contract with a school which has n students. The school planned to take the students to d different places for d days (each day in one place). Each day the company provides all the buses for the trip. Pashmak has to arrang... | # by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO, IOBase
def base(x,k,d):
ans = []
while x:
ans.append(x%k+1)
x //= k
ans.reverse()
return [1]*(d-len(ans))+ans
def main():
n,k,d = map(int,input().split())
if n == 1:
for ... | 3Python3 | {
"input": [
"3 2 2\n",
"3 2 1\n",
"2 1 1000\n",
"513 2 9\n",
"512 8 3\n",
"729 9 3\n",
"5 3 2\n",
"9 2 3\n",
"1000 1000000000 1\n",
"729 3 6\n",
"1000 999 1\n",
"1 1 1\n",
"1 1000000000 1\n",
"81 3 4\n",
"1 1 10\n",
"625 5 4\n",
"27 3 3\n",
"100... | 2CODEFORCES |
459_C. Pashmak and Buses_2831 | Recently Pashmak has been employed in a transportation company. The company has k buses and has a contract with a school which has n students. The school planned to take the students to d different places for d days (each day in one place). Each day the company provides all the buses for the trip. Pashmak has to arrang... | import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class C {
MyScanner sc = new MyScanner();
Scanner sc2 = new Scanner(System.in);
final int MOD = 1000000007;
int[] dx = { 1, 0, 0, -1 };
int[] dy = { 0, 1, -1, 0 };
ArrayList<int[]> list;
int n, k, d;
void run() {
n = sc.n... | 4JAVA | {
"input": [
"3 2 2\n",
"3 2 1\n",
"2 1 1000\n",
"513 2 9\n",
"512 8 3\n",
"729 9 3\n",
"5 3 2\n",
"9 2 3\n",
"1000 1000000000 1\n",
"729 3 6\n",
"1000 999 1\n",
"1 1 1\n",
"1 1000000000 1\n",
"81 3 4\n",
"1 1 10\n",
"625 5 4\n",
"27 3 3\n",
"100... | 2CODEFORCES |
480_B. Long Jumps_2832 | Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measure... | n,l,x,y=map(int,raw_input().split())
r=map(int,raw_input().split())
dic={}
for i in r:
dic[i]=True
ch1=0
ch2=0
for i in r:
if ch1==0:
if i-x in dic or i+x in dic:
ch1=1
if ch2==0:
if i-y in dic or i+y in dic:
ch2=1
if ch1==1 and ch2==0:
if r[0]+y <=l:
print "1"
print r[0]+y
else:
print "2"
print ... | 1Python2 | {
"input": [
"3 250 185 230\n0 185 250\n",
"2 300 185 230\n0 300\n",
"4 250 185 230\n0 20 185 250\n",
"4 100 90 91\n0 7 8 100\n",
"3 10 1 8\n0 3 10\n",
"4 100 3 5\n0 40 48 100\n",
"4 500 30 50\n0 20 40 500\n",
"4 10 8 9\n0 4 5 10\n",
"3 10 7 8\n0 9 10\n",
"4 100 7 8\n0 3 4 100\... | 2CODEFORCES |
480_B. Long Jumps_2833 | Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measure... | #include <bits/stdc++.h>
using namespace std;
int a[100005], b[100005], ansx, ansy, n, qst, qed, now, ansk, x, y, l;
bool find(int nx, int t) {
qst = 1;
qed = 1;
now = b[1];
while (qst <= n) {
if (now == nx) {
if (t == 0)
return 1;
else {
if (a[qed] - x >= 0 || a[qed] + y <= l) r... | 2C++ | {
"input": [
"3 250 185 230\n0 185 250\n",
"2 300 185 230\n0 300\n",
"4 250 185 230\n0 20 185 250\n",
"4 100 90 91\n0 7 8 100\n",
"3 10 1 8\n0 3 10\n",
"4 100 3 5\n0 40 48 100\n",
"4 500 30 50\n0 20 40 500\n",
"4 10 8 9\n0 4 5 10\n",
"3 10 7 8\n0 9 10\n",
"4 100 7 8\n0 3 4 100\... | 2CODEFORCES |
480_B. Long Jumps_2834 | Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measure... | def main():
from bisect import bisect_left
n, l, x, y = map(int, input().split())
aa, d = list(map(int, input().split())), {}
for z in (x, y, y + x):
for a in aa:
a += z
if a > l:
break
b = aa[bisect_left(aa, a)]
if b <= a:
... | 3Python3 | {
"input": [
"3 250 185 230\n0 185 250\n",
"2 300 185 230\n0 300\n",
"4 250 185 230\n0 20 185 250\n",
"4 100 90 91\n0 7 8 100\n",
"3 10 1 8\n0 3 10\n",
"4 100 3 5\n0 40 48 100\n",
"4 500 30 50\n0 20 40 500\n",
"4 10 8 9\n0 4 5 10\n",
"3 10 7 8\n0 9 10\n",
"4 100 7 8\n0 3 4 100\... | 2CODEFORCES |
480_B. Long Jumps_2835 | Valery is a PE teacher at a school in Berland. Soon the students are going to take a test in long jumps, and Valery has lost his favorite ruler!
However, there is no reason for disappointment, as Valery has found another ruler, its length is l centimeters. The ruler already has n marks, with which he can make measure... | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer... | 4JAVA | {
"input": [
"3 250 185 230\n0 185 250\n",
"2 300 185 230\n0 300\n",
"4 250 185 230\n0 20 185 250\n",
"4 100 90 91\n0 7 8 100\n",
"3 10 1 8\n0 3 10\n",
"4 100 3 5\n0 40 48 100\n",
"4 500 30 50\n0 20 40 500\n",
"4 10 8 9\n0 4 5 10\n",
"3 10 7 8\n0 9 10\n",
"4 100 7 8\n0 3 4 100\... | 2CODEFORCES |
505_B. Mr. Kitayuta's Colorful Graph_2836 | Mr. Kitayuta has just bought an undirected graph consisting of n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi.
Mr. Kitayuta wants you to process the following q queries.
In the i-th query, he gives you two integers — ui... | #!/usr/bin/env python
# coding=utf-8
n, m = map(int, raw_input().split())
mp = [[set() for j in range(n)] for i in range(n)]
for i in range(m):
a, b, c = map(int, raw_input().split())
a -= 1
b -= 1
if c not in mp[a][b]:
mp[a][b].add(c)
mp[b][a].add(c)
for k in range(n):
for i in ran... | 1Python2 | {
"input": [
"5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4\n",
"4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4\n",
"2 1\n1 2 1\n1\n1 2\n",
"2 3\n1 2 3\n1 2 2\n1 2 1\n1\n1 2\n",
"2 5\n1 2 1\n1 2 2\n1 2 3\n1 2 4\n1 2 5\n1\n1 2\n",
"5 7\n1 1 1\n2 5 1\... | 2CODEFORCES |
505_B. Mr. Kitayuta's Colorful Graph_2837 | Mr. Kitayuta has just bought an undirected graph consisting of n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi.
Mr. Kitayuta wants you to process the following q queries.
In the i-th query, he gives you two integers — ui... | #include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y) {
long long int res = 1;
x = x;
while (y > 0) {
if (y & 1) res = (res * x);
y = y >> 1;
x = (x * x);
}
return res;
}
long long int logtwo(long long int n) {
if (n == 1) return 0;
return logtwo(n... | 2C++ | {
"input": [
"5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4\n",
"4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4\n",
"2 1\n1 2 1\n1\n1 2\n",
"2 3\n1 2 3\n1 2 2\n1 2 1\n1\n1 2\n",
"2 5\n1 2 1\n1 2 2\n1 2 3\n1 2 4\n1 2 5\n1\n1 2\n",
"5 7\n1 1 1\n2 5 1\... | 2CODEFORCES |
505_B. Mr. Kitayuta's Colorful Graph_2838 | Mr. Kitayuta has just bought an undirected graph consisting of n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi.
Mr. Kitayuta wants you to process the following q queries.
In the i-th query, he gives you two integers — ui... | def build_graph():
line1 = input().strip().split()
n = int(line1[0])
m = int(line1[1])
graph = {}
for _ in range(m):
line = input().strip().split()
u = int(line[0])
v = int(line[1])
c = int(line[2])
if c not in graph:
graph[c] = {j: [] for j in ran... | 3Python3 | {
"input": [
"5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4\n",
"4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4\n",
"2 1\n1 2 1\n1\n1 2\n",
"2 3\n1 2 3\n1 2 2\n1 2 1\n1\n1 2\n",
"2 5\n1 2 1\n1 2 2\n1 2 3\n1 2 4\n1 2 5\n1\n1 2\n",
"5 7\n1 1 1\n2 5 1\... | 2CODEFORCES |
505_B. Mr. Kitayuta's Colorful Graph_2839 | Mr. Kitayuta has just bought an undirected graph consisting of n vertices and m edges. The vertices of the graph are numbered from 1 to n. Each edge, namely edge i, has a color ci, connecting vertex ai and bi.
Mr. Kitayuta wants you to process the following q queries.
In the i-th query, he gives you two integers — ui... | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class Solution_505B {
public static boolean[][][] colorMatrix;
public static boolean[] used;
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStr... | 4JAVA | {
"input": [
"5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 1\n2 5\n1 5\n1 4\n",
"4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4\n",
"2 1\n1 2 1\n1\n1 2\n",
"2 3\n1 2 3\n1 2 2\n1 2 1\n1\n1 2\n",
"2 5\n1 2 1\n1 2 2\n1 2 3\n1 2 4\n1 2 5\n1\n1 2\n",
"5 7\n1 1 1\n2 5 1\... | 2CODEFORCES |
529_A. And Yet Another Bracket Sequence_2840 | Polycarpus has a finite sequence of opening and closing brackets. In order not to fall asleep in a lecture, Polycarpus is having fun with his sequence. He is able to perform two operations:
* adding any bracket in any position (in the beginning, the end, or between any two existing brackets);
* cyclic shift — mov... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1000047;
char s[maxn];
int n;
vector<int> utried() {
vector<int> lepsich(n);
vector<int> por;
int otv = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '(') {
por.push_back(i);
lepsich[i] = 0;
otv++;
}
}
for (int i = 0; i ... | 2C++ | {
"input": [
"()(\n",
"()(())\n",
")(()()))((\n",
")())))(((())))())))))))()())(())))))))())))(((())))())()()))(())())((()())(((((()()()())()()()))((()\n",
"()\n",
"(((())))))()(()\n",
"))(\n",
")\n",
"(()()\n",
")(\n",
"(\n",
")())(())((\n",
")())))(((())))()))))))... | 2CODEFORCES |
529_A. And Yet Another Bracket Sequence_2841 | Polycarpus has a finite sequence of opening and closing brackets. In order not to fall asleep in a lecture, Polycarpus is having fun with his sequence. He is able to perform two operations:
* adding any bracket in any position (in the beginning, the end, or between any two existing brackets);
* cyclic shift — mov... | import java.io.*;
import java.util.*;
public class A {
FastScanner in;
PrintWriter out;
final int mod = (int) 1e9 + 7;
final int mul = 239;
int[] hash;
int[] pow;
int getHash(int from, int to) {
long res = hash[to + 1] - hash[from] * 1L * pow[to - from + 1];
res %= mod;
if (res < 0) {
res += mod;
}... | 4JAVA | {
"input": [
"()(\n",
"()(())\n",
")(()()))((\n",
")())))(((())))())))))))()())(())))))))())))(((())))())()()))(())())((()())(((((()()()())()()()))((()\n",
"()\n",
"(((())))))()(()\n",
"))(\n",
")\n",
"(()()\n",
")(\n",
"(\n",
")())(())((\n",
")())))(((())))()))))))... | 2CODEFORCES |
554_C. Kyoya and Colored Balls_2842 | Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color i before drawing the last ball of color i... | import sys
factorials = [1]
def newton(n, k):
global factorials
return factorials[n] / (factorials[k] * factorials[n - k])
def solve(x):
if len(x) == 1:
return 1
last = x.pop() - 1
n = sum(x) + last
k = last
return (solve(x) * newton(n, k)) % 1000000007
def preprocess():
for i in xrange(1, 1001)... | 1Python2 | {
"input": [
"3\n2\n2\n1\n",
"4\n1\n2\n3\n4\n",
"25\n35\n43\n38\n33\n47\n44\n40\n36\n41\n42\n33\n30\n49\n42\n62\n39\n40\n35\n43\n31\n42\n46\n42\n34\n33\n",
"47\n20\n21\n16\n18\n24\n20\n25\n13\n20\n22\n26\n24\n17\n18\n21\n22\n21\n23\n17\n15\n24\n19\n18\n21\n20\n19\n26\n25\n20\n17\n17\n17\n26\n32\n20\n2... | 2CODEFORCES |
554_C. Kyoya and Colored Balls_2843 | Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color i before drawing the last ball of color i... | #include <bits/stdc++.h>
const int Mod = (int)1e9 + 7;
const int MX = 2147483647;
const long long MXLL = 9223372036854775807;
const int Sz = 1110111;
using namespace std;
inline void Read_rap() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
long long a[Sz], n, f[Sz], ans = 1, len = 0;
long long binpow... | 2C++ | {
"input": [
"3\n2\n2\n1\n",
"4\n1\n2\n3\n4\n",
"25\n35\n43\n38\n33\n47\n44\n40\n36\n41\n42\n33\n30\n49\n42\n62\n39\n40\n35\n43\n31\n42\n46\n42\n34\n33\n",
"47\n20\n21\n16\n18\n24\n20\n25\n13\n20\n22\n26\n24\n17\n18\n21\n22\n21\n23\n17\n15\n24\n19\n18\n21\n20\n19\n26\n25\n20\n17\n17\n17\n26\n32\n20\n2... | 2CODEFORCES |
554_C. Kyoya and Colored Balls_2844 | Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color i before drawing the last ball of color i... | from sys import stdin
c = [[0]*1002 for _ in range(0,1002)]
MOD = int(1e9+7)
for i in range(0,1002):
c[i][0] = c[i][i] = 1
for j in range(0,i):
c[i][j] = (c[i-1][j-1] + c[i-1][j])%MOD
r = map(int,stdin.read().split())
n = next(r)
ans = 1
sum = 0
for _ in range(0,n):
x = next(r)
ans = (ans * ... | 3Python3 | {
"input": [
"3\n2\n2\n1\n",
"4\n1\n2\n3\n4\n",
"25\n35\n43\n38\n33\n47\n44\n40\n36\n41\n42\n33\n30\n49\n42\n62\n39\n40\n35\n43\n31\n42\n46\n42\n34\n33\n",
"47\n20\n21\n16\n18\n24\n20\n25\n13\n20\n22\n26\n24\n17\n18\n21\n22\n21\n23\n17\n15\n24\n19\n18\n21\n20\n19\n26\n25\n20\n17\n17\n17\n26\n32\n20\n2... | 2CODEFORCES |
554_C. Kyoya and Colored Balls_2845 | Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed that he drew the last ball of color i before drawing the last ball of color i... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamW... | 4JAVA | {
"input": [
"3\n2\n2\n1\n",
"4\n1\n2\n3\n4\n",
"25\n35\n43\n38\n33\n47\n44\n40\n36\n41\n42\n33\n30\n49\n42\n62\n39\n40\n35\n43\n31\n42\n46\n42\n34\n33\n",
"47\n20\n21\n16\n18\n24\n20\n25\n13\n20\n22\n26\n24\n17\n18\n21\n22\n21\n23\n17\n15\n24\n19\n18\n21\n20\n19\n26\n25\n20\n17\n17\n17\n26\n32\n20\n2... | 2CODEFORCES |
580_B. Kefa and Company_2846 | Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend t... | n, d = map(int, raw_input().split())
friends = {}
for _ in range(n):
a,b = map(int, raw_input().split())
if a not in friends:
friends[a] = 0
friends[a] += b
friends = sorted([(k,friends[k]) for k in friends], key = (lambda x: x[0]))
# import pudb;pu.db
max_res = 0
start, end = 0,0
while end != len(... | 1Python2 | {
"input": [
"5 100\n0 7\n11 32\n99 10\n46 8\n87 54\n",
"4 5\n75 5\n0 100\n150 20\n75 1\n",
"5 9\n0 98\n2 1000000000\n8 1000000000\n5 999999999\n3 989898989\n",
"4 1\n2 4\n2 2\n3 3\n3 3\n",
"3 1\n801 10101\n802 134509124\n801 1\n",
"5 6\n5 11\n10 11\n11 11\n12 11\n100 1\n",
"7 6\n5 11\n9 1... | 2CODEFORCES |
580_B. Kefa and Company_2847 | Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend t... | #include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int MAXN = 100000 + 1000;
struct node {
long long m, s;
bool operator<(const node& b) const { return m < b.m; }
} num[MAXN];
long long sum[MAXN];
long long M[MAXN];
int n, d;
int main() {
while (scanf("%d%d", &n, &d) != EOF) {
for... | 2C++ | {
"input": [
"5 100\n0 7\n11 32\n99 10\n46 8\n87 54\n",
"4 5\n75 5\n0 100\n150 20\n75 1\n",
"5 9\n0 98\n2 1000000000\n8 1000000000\n5 999999999\n3 989898989\n",
"4 1\n2 4\n2 2\n3 3\n3 3\n",
"3 1\n801 10101\n802 134509124\n801 1\n",
"5 6\n5 11\n10 11\n11 11\n12 11\n100 1\n",
"7 6\n5 11\n9 1... | 2CODEFORCES |
580_B. Kefa and Company_2848 | Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend t... | n, d = map(int, input().split())
v = []
for i in range(0, n):
a, b = map(int, input().split())
v.append((a, b))
v = sorted(v)
lo = 0
totalFriendship = v[0][1]
bestFriendship = totalFriendship
for i in range(1, n):
while v[i][0] - v[lo][0] >= d:
totalFriendship -= v[lo][1]
lo += 1
to... | 3Python3 | {
"input": [
"5 100\n0 7\n11 32\n99 10\n46 8\n87 54\n",
"4 5\n75 5\n0 100\n150 20\n75 1\n",
"5 9\n0 98\n2 1000000000\n8 1000000000\n5 999999999\n3 989898989\n",
"4 1\n2 4\n2 2\n3 3\n3 3\n",
"3 1\n801 10101\n802 134509124\n801 1\n",
"5 6\n5 11\n10 11\n11 11\n12 11\n100 1\n",
"7 6\n5 11\n9 1... | 2CODEFORCES |
580_B. Kefa and Company_2849 | Kefa wants to celebrate his first big salary by going to restaurant. However, he needs company.
Kefa has n friends, each friend will agree to go to the restaurant if Kefa asks. Each friend is characterized by the amount of money he has and the friendship factor in respect to Kefa. The parrot doesn't want any friend t... | /******************************************************************************
Online Java Compiler.
Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.
*****************************************************... | 4JAVA | {
"input": [
"5 100\n0 7\n11 32\n99 10\n46 8\n87 54\n",
"4 5\n75 5\n0 100\n150 20\n75 1\n",
"5 9\n0 98\n2 1000000000\n8 1000000000\n5 999999999\n3 989898989\n",
"4 1\n2 4\n2 2\n3 3\n3 3\n",
"3 1\n801 10101\n802 134509124\n801 1\n",
"5 6\n5 11\n10 11\n11 11\n12 11\n100 1\n",
"7 6\n5 11\n9 1... | 2CODEFORCES |
602_A. Two Bases_2850 | After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers X and Y realised that they have different bases, which complicated their relations.
You're given a number X represented in base bx and a number Y represented in base by. Compare those two numbers.
Input
The first line of the input con... | def get():
n, b = map(int, raw_input().split())
d = map(int, raw_input().split())
a = 0
for i in xrange(n): a = a * b + d[i]
return a
x, y = get(), get()
print '=' if x == y else '>' if x > y else '<'
| 1Python2 | {
"input": [
"7 16\n15 15 4 0 0 7 10\n7 9\n4 8 0 3 1 5 0\n",
"3 3\n1 0 2\n2 5\n2 4\n",
"6 2\n1 0 1 1 1 1\n2 10\n4 7\n",
"8 18\n1 1 4 15 7 4 9 3\n8 17\n1 10 2 10 3 11 14 10\n",
"4 7\n3 0 6 6\n3 11\n7 10 10\n",
"2 24\n20 9\n10 23\n21 10 15 11 6 8 20 16 14 11\n",
"10 40\n39 39 39 39 39 39 39 ... | 2CODEFORCES |
602_A. Two Bases_2851 | After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers X and Y realised that they have different bases, which complicated their relations.
You're given a number X represented in base bx and a number Y represented in base by. Compare those two numbers.
Input
The first line of the input con... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, bn;
cin >> n >> bn;
long long int sum = 0;
while (n--) {
int a;
cin >> a;
sum = (long long int)bn * sum + a;
}
long long int sum1 = 0;
int m, bm;
cin >> m >> bm;
while (m--) {
int a;
cin >> a;
sum1 = (long long i... | 2C++ | {
"input": [
"7 16\n15 15 4 0 0 7 10\n7 9\n4 8 0 3 1 5 0\n",
"3 3\n1 0 2\n2 5\n2 4\n",
"6 2\n1 0 1 1 1 1\n2 10\n4 7\n",
"8 18\n1 1 4 15 7 4 9 3\n8 17\n1 10 2 10 3 11 14 10\n",
"4 7\n3 0 6 6\n3 11\n7 10 10\n",
"2 24\n20 9\n10 23\n21 10 15 11 6 8 20 16 14 11\n",
"10 40\n39 39 39 39 39 39 39 ... | 2CODEFORCES |
602_A. Two Bases_2852 | After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers X and Y realised that they have different bases, which complicated their relations.
You're given a number X represented in base bx and a number Y represented in base by. Compare those two numbers.
Input
The first line of the input con... | # print ("Input digits and base for number one")
n1, b1 = (int(x) for x in input().split())
# print ("Input all the digits")
d1 = list(int(x) for x in input().split())
d1.reverse()
# print ("Input digits and base for number two")
n2, b2 = (int(x) for x in input().split())
# print ("Input all the digits")
d2 = list(int... | 3Python3 | {
"input": [
"7 16\n15 15 4 0 0 7 10\n7 9\n4 8 0 3 1 5 0\n",
"3 3\n1 0 2\n2 5\n2 4\n",
"6 2\n1 0 1 1 1 1\n2 10\n4 7\n",
"8 18\n1 1 4 15 7 4 9 3\n8 17\n1 10 2 10 3 11 14 10\n",
"4 7\n3 0 6 6\n3 11\n7 10 10\n",
"2 24\n20 9\n10 23\n21 10 15 11 6 8 20 16 14 11\n",
"10 40\n39 39 39 39 39 39 39 ... | 2CODEFORCES |
602_A. Two Bases_2853 | After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers X and Y realised that they have different bases, which complicated their relations.
You're given a number X represented in base bx and a number Y represented in base by. Compare those two numbers.
Input
The first line of the input con... | import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigInteger;
public class Ideone
{
public static void main (String[] args)
{
Scanner in= new Scanner(System.in);
int x=in.nextInt();
int y=in.nextInt();
int tmp = x - 1;
BigInteger sum = BigInteger.valueOf(0);
for(int i=0;i<x;i... | 4JAVA | {
"input": [
"7 16\n15 15 4 0 0 7 10\n7 9\n4 8 0 3 1 5 0\n",
"3 3\n1 0 2\n2 5\n2 4\n",
"6 2\n1 0 1 1 1 1\n2 10\n4 7\n",
"8 18\n1 1 4 15 7 4 9 3\n8 17\n1 10 2 10 3 11 14 10\n",
"4 7\n3 0 6 6\n3 11\n7 10 10\n",
"2 24\n20 9\n10 23\n21 10 15 11 6 8 20 16 14 11\n",
"10 40\n39 39 39 39 39 39 39 ... | 2CODEFORCES |
624_D. Array GCD_2854 | You are given array ai of length n. You may consecutively apply two operations to this array:
* remove some subsegment (continuous subsequence) of length m < n and pay for it m·a coins;
* change some elements of the array by at most 1, and pay b coins for each change.
Please note that each of operations may b... | #include <bits/stdc++.h>
using namespace std;
const long long INF = 3000000000000000000LL;
long long dp[1000001][3];
void pf(long a, set<long long> &s) {
long long i;
for (i = 2; i * i <= a; ++i) {
if (a % i == 0) {
s.insert(i);
while (a % i == 0) a /= i;
}
}
if (a > 1) s.insert(a);
}
int ma... | 2C++ | {
"input": [
"3 1 4\n4 2 3\n",
"8 3 4\n3 7 5 4 3 12 9 4\n",
"5 3 2\n5 17 13 5 6\n",
"93 1985 9702\n1711 6269 9689 9119 569 3990 5129 6314 2171 4078 2607 3063 5410 7140 7831 4622 2597 8486 9050 3110 1673 5435 8981 6871 4679 8854 5675 39 7227 2533 1782 7833 7029 5919 7792 4192 5856 6020 4735 9772 3145 8... | 2CODEFORCES |
624_D. Array GCD_2855 | You are given array ai of length n. You may consecutively apply two operations to this array:
* remove some subsegment (continuous subsequence) of length m < n and pay for it m·a coins;
* change some elements of the array by at most 1, and pay b coins for each change.
Please note that each of operations may b... | import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Stri... | 4JAVA | {
"input": [
"3 1 4\n4 2 3\n",
"8 3 4\n3 7 5 4 3 12 9 4\n",
"5 3 2\n5 17 13 5 6\n",
"93 1985 9702\n1711 6269 9689 9119 569 3990 5129 6314 2171 4078 2607 3063 5410 7140 7831 4622 2597 8486 9050 3110 1673 5435 8981 6871 4679 8854 5675 39 7227 2533 1782 7833 7029 5919 7792 4192 5856 6020 4735 9772 3145 8... | 2CODEFORCES |
673_A. Bear and Game_2856 | Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.
You know that there will be n interesting minutes t1, t2, ..., tn. Yo... | line1 = raw_input()
line2 = raw_input()
data = line2.split(' ')
def get_minute(data):
temp = 0
for minute in data:
if temp + 15 >= 90:
return 90
if int(minute) - temp > 15:
return temp + 15
temp = int(minute)
return temp+15 if temp+15 < 90 else 90
prin... | 1Python2 | {
"input": [
"3\n7 20 88\n",
"9\n15 20 30 40 50 60 70 80 90\n",
"9\n16 20 30 40 50 60 70 80 90\n",
"2\n1 18\n",
"9\n6 20 27 28 40 53 59 70 85\n",
"8\n10 20 30 40 50 60 70 80\n",
"6\n13 17 32 47 60 66\n",
"1\n1\n",
"8\n5 17 20 35 42 53 67 76\n",
"1\n90\n",
"6\n14 29 43 59 70... | 2CODEFORCES |
673_A. Bear and Game_2857 | Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.
You know that there will be n interesting minutes t1, t2, ..., tn. Yo... | #include <bits/stdc++.h>
using namespace std;
int main() {
int arr[95]{};
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
int m;
scanf("%d", &m);
arr[m] = 1;
}
int c = 0;
int ans = 0;
int i;
for (i = 1; i <= 90; i++) {
c++;
if (arr[i] != 0) {
c = 0;
}
if (c == ... | 2C++ | {
"input": [
"3\n7 20 88\n",
"9\n15 20 30 40 50 60 70 80 90\n",
"9\n16 20 30 40 50 60 70 80 90\n",
"2\n1 18\n",
"9\n6 20 27 28 40 53 59 70 85\n",
"8\n10 20 30 40 50 60 70 80\n",
"6\n13 17 32 47 60 66\n",
"1\n1\n",
"8\n5 17 20 35 42 53 67 76\n",
"1\n90\n",
"6\n14 29 43 59 70... | 2CODEFORCES |
673_A. Bear and Game_2858 | Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.
You know that there will be n interesting minutes t1, t2, ..., tn. Yo... | n=int(input())
tl = list(map(int, input().split()))
time=cnt=0
while cnt <15 and time<90:
time+=1
if tl.count(time)>0:
cnt=0
else:
cnt+=1
print(time) | 3Python3 | {
"input": [
"3\n7 20 88\n",
"9\n15 20 30 40 50 60 70 80 90\n",
"9\n16 20 30 40 50 60 70 80 90\n",
"2\n1 18\n",
"9\n6 20 27 28 40 53 59 70 85\n",
"8\n10 20 30 40 50 60 70 80\n",
"6\n13 17 32 47 60 66\n",
"1\n1\n",
"8\n5 17 20 35 42 53 67 76\n",
"1\n90\n",
"6\n14 29 43 59 70... | 2CODEFORCES |
673_A. Bear and Game_2859 | Bear Limak likes watching sports on TV. He is going to watch a game today. The game lasts 90 minutes and there are no breaks.
Each minute can be either interesting or boring. If 15 consecutive minutes are boring then Limak immediately turns TV off.
You know that there will be n interesting minutes t1, t2, ..., tn. Yo... | import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int prev=0, cur=0, time=0;
for(int i=0; i<n+1; i++) {
if(i!=n) cur=sc.nextInt();
else cur=90;
if(cur-p... | 4JAVA | {
"input": [
"3\n7 20 88\n",
"9\n15 20 30 40 50 60 70 80 90\n",
"9\n16 20 30 40 50 60 70 80 90\n",
"2\n1 18\n",
"9\n6 20 27 28 40 53 59 70 85\n",
"8\n10 20 30 40 50 60 70 80\n",
"6\n13 17 32 47 60 66\n",
"1\n1\n",
"8\n5 17 20 35 42 53 67 76\n",
"1\n90\n",
"6\n14 29 43 59 70... | 2CODEFORCES |
698_B. Fix a Tree_2860 | A tree is an undirected connected graph without cycles.
Let's consider a rooted undirected tree with n vertices, numbered 1 through n. There are many ways to represent such a tree. One way is to create an array with n integers p1, p2, ..., pn, where pi denotes a parent of vertex i (here, for convenience a root is cons... | import itertools
import sys
def readline_int(delta=0):
return [int(i) + delta for i in raw_input().split()]
class Solution(object):
def find(self, ident, fa):
"""
if fa[ident] != ident:
fa[ident] = self.find(fa[ident], fa)
return fa[ident]
"""
root = ident... | 1Python2 | {
"input": [
"5\n3 2 2 5 3\n",
"8\n2 3 5 4 1 6 6 7\n",
"4\n2 3 3 4\n",
"3\n2 1 1\n",
"6\n6 2 6 2 4 2\n",
"2\n1 2\n",
"8\n2 1 2 2 6 5 6 6\n",
"18\n2 3 4 5 2 7 8 9 10 7 11 12 14 15 13 17 18 18\n",
"7\n1 2 3 4 5 6 7\n",
"7\n4 3 2 6 3 5 2\n",
"7\n7 5 3 1 2 1 5\n",
"7\n1 6 4... | 2CODEFORCES |
698_B. Fix a Tree_2861 | A tree is an undirected connected graph without cycles.
Let's consider a rooted undirected tree with n vertices, numbered 1 through n. There are many ways to represent such a tree. One way is to create an array with n integers p1, p2, ..., pn, where pi denotes a parent of vertex i (here, for convenience a root is cons... | #include <bits/stdc++.h>
using namespace std;
const int NMAX = 2e5 + 5;
int n, answer, root, curr;
int parent[NMAX];
int vis[NMAX];
vector<int> roots;
void dfs(int node) {
if (vis[node] != 0) {
if (vis[node] == curr) {
parent[node] = node;
roots.push_back(node);
} else {
return;
}
}
... | 2C++ | {
"input": [
"5\n3 2 2 5 3\n",
"8\n2 3 5 4 1 6 6 7\n",
"4\n2 3 3 4\n",
"3\n2 1 1\n",
"6\n6 2 6 2 4 2\n",
"2\n1 2\n",
"8\n2 1 2 2 6 5 6 6\n",
"18\n2 3 4 5 2 7 8 9 10 7 11 12 14 15 13 17 18 18\n",
"7\n1 2 3 4 5 6 7\n",
"7\n4 3 2 6 3 5 2\n",
"7\n7 5 3 1 2 1 5\n",
"7\n1 6 4... | 2CODEFORCES |
698_B. Fix a Tree_2862 | A tree is an undirected connected graph without cycles.
Let's consider a rooted undirected tree with n vertices, numbered 1 through n. There are many ways to represent such a tree. One way is to create an array with n integers p1, p2, ..., pn, where pi denotes a parent of vertex i (here, for convenience a root is cons... | from collections import defaultdict
from sys import stdin,setrecursionlimit
setrecursionlimit(10**6)
import threading
def f(a):
n=len(a)
a=list(map(lambda s:s-1,a))
root=None
for i in range(len(a)):
if a[i]==i:
root=i
vis=[0]*(n)
traitors=[]
for i in range(0,n):
cycle=-1
cur=i
move=set()
while vis... | 3Python3 | {
"input": [
"5\n3 2 2 5 3\n",
"8\n2 3 5 4 1 6 6 7\n",
"4\n2 3 3 4\n",
"3\n2 1 1\n",
"6\n6 2 6 2 4 2\n",
"2\n1 2\n",
"8\n2 1 2 2 6 5 6 6\n",
"18\n2 3 4 5 2 7 8 9 10 7 11 12 14 15 13 17 18 18\n",
"7\n1 2 3 4 5 6 7\n",
"7\n4 3 2 6 3 5 2\n",
"7\n7 5 3 1 2 1 5\n",
"7\n1 6 4... | 2CODEFORCES |
698_B. Fix a Tree_2863 | A tree is an undirected connected graph without cycles.
Let's consider a rooted undirected tree with n vertices, numbered 1 through n. There are many ways to represent such a tree. One way is to create an array with n integers p1, p2, ..., pn, where pi denotes a parent of vertex i (here, for convenience a root is cons... | 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.FileInputStream;
import java.util.ArrayList;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solu... | 4JAVA | {
"input": [
"5\n3 2 2 5 3\n",
"8\n2 3 5 4 1 6 6 7\n",
"4\n2 3 3 4\n",
"3\n2 1 1\n",
"6\n6 2 6 2 4 2\n",
"2\n1 2\n",
"8\n2 1 2 2 6 5 6 6\n",
"18\n2 3 4 5 2 7 8 9 10 7 11 12 14 15 13 17 18 18\n",
"7\n1 2 3 4 5 6 7\n",
"7\n4 3 2 6 3 5 2\n",
"7\n7 5 3 1 2 1 5\n",
"7\n1 6 4... | 2CODEFORCES |
719_B. Anatoly and Cockroaches_2864 | Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectioni... | def getTotalEffort(sequence,oddchar,evenchar) :
length = len(sequence)
oddmisplaced = 0
evenmisplaced =0
for i in range(length) :
if(i%2==0 and sequence[i] != evenchar):
evenmisplaced = evenmisplaced +1
if(i%2==1 and sequence[i] != oddchar):
oddmisplaced = oddmisplaced+1
swaps = min (evenmisplaced,oddmis... | 1Python2 | {
"input": [
"5\nrbbrr\n",
"5\nbbbbb\n",
"3\nrbr\n",
"166\nrbbbbbbbbbbbbrbrrbbrbbbrbbbbbbbbbbrbbbbbbrbbbrbbbbbrbbbbbbbrbbbbbbbrbbrbbbbbbbbrbbbbbbbbbbbbbbrrbbbrbbbbbbbbbbbbbbrbrbbbbbbbbbbbrbbbbbbbbbbbbbbrbbbbbbbbbbbbbbbbbbbbbb\n",
"7\nrrbrbrb\n",
"1\nr\n",
"2\nbb\n",
"18\nrrrrrrrrrrrrrr... | 2CODEFORCES |
719_B. Anatoly and Cockroaches_2865 | Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectioni... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 3e6 + 5;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
string s;
cin >> n >> s;
int swap[2] = {0};
int color[2][2] = {0};
for (int i = 0; i < n; i++) {
if (i % 2 == 0 && s[i] == 'r') color[0][0] += 1;
if (i ... | 2C++ | {
"input": [
"5\nrbbrr\n",
"5\nbbbbb\n",
"3\nrbr\n",
"166\nrbbbbbbbbbbbbrbrrbbrbbbrbbbbbbbbbbrbbbbbbrbbbrbbbbbrbbbbbbbrbbbbbbbrbbrbbbbbbbbrbbbbbbbbbbbbbbrrbbbrbbbbbbbbbbbbbbrbrbbbbbbbbbbbrbbbbbbbbbbbbbbrbbbbbbbbbbbbbbbbbbbbbb\n",
"7\nrrbrbrb\n",
"1\nr\n",
"2\nbb\n",
"18\nrrrrrrrrrrrrrr... | 2CODEFORCES |
719_B. Anatoly and Cockroaches_2866 | Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectioni... | #http://codeforces.com/problemset/problem/719/B
#solved
n = int(input())
s = input()
red_black = True
swap_red = {"b": 0, "r": 0}
swap_black = {"b": 0, "r": 0}
for c in s:
if red_black is True and c != "b":
swap_black["r"] += 1
elif red_black is False and c != "r":
swap_black["b"] += 1
... | 3Python3 | {
"input": [
"5\nrbbrr\n",
"5\nbbbbb\n",
"3\nrbr\n",
"166\nrbbbbbbbbbbbbrbrrbbrbbbrbbbbbbbbbbrbbbbbbrbbbrbbbbbrbbbbbbbrbbbbbbbrbbrbbbbbbbbrbbbbbbbbbbbbbbrrbbbrbbbbbbbbbbbbbbrbrbbbbbbbbbbbrbbbbbbbbbbbbbbrbbbbbbbbbbbbbbbbbbbbbb\n",
"7\nrrbrbrb\n",
"1\nr\n",
"2\nbb\n",
"18\nrrrrrrrrrrrrrr... | 2CODEFORCES |
719_B. Anatoly and Cockroaches_2867 | Anatoly lives in the university dorm as many other students do. As you know, cockroaches are also living there together with students. Cockroaches might be of two colors: black and red. There are n cockroaches living in Anatoly's room.
Anatoly just made all his cockroaches to form a single line. As he is a perfectioni... | import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
public class Main {
static Scanner in;
static int n, xr = 0, yr = 0, xb = 0, yb = 0;
static char s[], sr[], sb[];
pu... | 4JAVA | {
"input": [
"5\nrbbrr\n",
"5\nbbbbb\n",
"3\nrbr\n",
"166\nrbbbbbbbbbbbbrbrrbbrbbbrbbbbbbbbbbrbbbbbbrbbbrbbbbbrbbbbbbbrbbbbbbbrbbrbbbbbbbbrbbbbbbbbbbbbbbrrbbbrbbbbbbbbbbbbbbrbrbbbbbbbbbbbrbbbbbbbbbbbbbbrbbbbbbbbbbbbbbbbbbbbbb\n",
"7\nrrbrbrb\n",
"1\nr\n",
"2\nbb\n",
"18\nrrrrrrrrrrrrrr... | 2CODEFORCES |
73_F. Plane of Tanks_2868 | Vasya plays the Plane of Tanks. The tanks in this game keep trying to finish each other off. But your "Pedalny" is not like that... He just needs to drive in a straight line from point A to point B on the plane. Unfortunately, on the same plane are n enemy tanks. We shall regard all the tanks as points. At the initial ... | #include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
double ax, ay, bx, by;
double dis(double x, double y) { return sqrt(x * x + y * y); }
double get(double a, double w) {
double v = 0;
int num = 100;
for (int i = 0; i <= 100; i++) {
double x = ax + (bx - ax) * i / (double)num;
doub... | 2C++ | {
"input": [
"0 0 10 0\n1\n5 -5 4.71238 1\n0\n",
"0 0 10 0\n1\n5 -5 4.71238 1\n1\n",
"0 0 10 10\n1\n10 0 0 1.57079\n0\n",
"-88 -68 -10 -61\n5\n-64 -55 3.09648 0.28346\n-8 -52 2.46781 0.13262\n-8 -59 3.02445 0.00119\n-40 90 2.37292 0.15686\n-29 -34 2.73957 0.18287\n0\n",
"0 0 10 10\n2\n10 0 0 1.570... | 2CODEFORCES |
73_F. Plane of Tanks_2869 | Vasya plays the Plane of Tanks. The tanks in this game keep trying to finish each other off. But your "Pedalny" is not like that... He just needs to drive in a straight line from point A to point B on the plane. Unfortunately, on the same plane are n enemy tanks. We shall regard all the tanks as points. At the initial ... | import java.util.*;
import static java.lang.Math.*;
public class F {
public static void main(String[] args) throws Exception{
Scanner in = new Scanner(System.in);
st = new Point(in.nextDouble(), in.nextDouble());
en = new Point(in.nextDouble(), in.nextDouble());
N = in.nextInt();
T = new Tank[N];
for(int ... | 4JAVA | {
"input": [
"0 0 10 0\n1\n5 -5 4.71238 1\n0\n",
"0 0 10 0\n1\n5 -5 4.71238 1\n1\n",
"0 0 10 10\n1\n10 0 0 1.57079\n0\n",
"-88 -68 -10 -61\n5\n-64 -55 3.09648 0.28346\n-8 -52 2.46781 0.13262\n-8 -59 3.02445 0.00119\n-40 90 2.37292 0.15686\n-29 -34 2.73957 0.18287\n0\n",
"0 0 10 10\n2\n10 0 0 1.570... | 2CODEFORCES |
763_D. Timofey and a flat tree_2870 | Little Timofey has a big tree — an undirected connected graph with n vertices and no simple cycles. He likes to walk along it. His tree is flat so when he walks along it he sees it entirely. Quite naturally, when he stands on a vertex, he sees the tree as a rooted tree with the root in this vertex.
Timofey assumes tha... | #include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
long long r;
while (b) {
r = a % b;
a = b... | 2C++ | {
"input": [
"10\n1 7\n1 8\n9 4\n5 1\n9 2\n3 5\n10 6\n10 9\n5 10\n",
"3\n1 2\n2 3\n",
"7\n1 2\n4 2\n2 3\n5 6\n6 7\n3 7\n",
"10\n6 8\n3 10\n1 9\n6 1\n8 2\n5 7\n3 6\n10 4\n3 5\n",
"1\n",
"5\n1 2\n2 3\n3 4\n4 5\n",
"7\n2 3\n2 6\n1 2\n3 7\n6 5\n3 4\n",
"10\n8 4\n8 10\n8 1\n8 2\n5 9\n5 3\n5... | 2CODEFORCES |
763_D. Timofey and a flat tree_2871 | Little Timofey has a big tree — an undirected connected graph with n vertices and no simple cycles. He likes to walk along it. His tree is flat so when he walks along it he sees it entirely. Quite naturally, when he stands on a vertex, he sees the tree as a rooted tree with the root in this vertex.
Timofey assumes tha... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Random;
import java.util.ArrayList;
import java.io.OutputStreamWriter;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.IOException;
import java.io.UncheckedIOException;
... | 4JAVA | {
"input": [
"10\n1 7\n1 8\n9 4\n5 1\n9 2\n3 5\n10 6\n10 9\n5 10\n",
"3\n1 2\n2 3\n",
"7\n1 2\n4 2\n2 3\n5 6\n6 7\n3 7\n",
"10\n6 8\n3 10\n1 9\n6 1\n8 2\n5 7\n3 6\n10 4\n3 5\n",
"1\n",
"5\n1 2\n2 3\n3 4\n4 5\n",
"7\n2 3\n2 6\n1 2\n3 7\n6 5\n3 4\n",
"10\n8 4\n8 10\n8 1\n8 2\n5 9\n5 3\n5... | 2CODEFORCES |
787_A. The Monster_2872 | A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, ... and Morty screams at times d, d + c, d + 2c, d + 3c, ....
<image>
The Monster will catch them if at any point they scream at the same tim... | a=raw_input().split()
b=raw_input().split()
y1= int(a[0])
x1= int(a[1])
y2= int(b[0])
x2= int(b[1])
# 0 = puro par
# 1= puro impar
# 2= ambos
t1=2
t2=50
if (x1 %2==0 and y1%2==0):
t1=0
elif (x1%2!=0 and y1%2==0):
t1=1
if (x2 %2==0 and y2%2==0):
t2=0
elif (x2%2!=0 and y2%2==0):
t2=1
if ((t1==0 and t2==1)... | 1Python2 | {
"input": [
"20 2\n9 19\n",
"2 1\n16 12\n",
"84 82\n38 6\n",
"2 3\n2 2\n",
"2 3\n4 99\n",
"3 7\n3 6\n",
"11 81\n49 7\n",
"1 1\n1 100\n",
"6 10\n12 14\n",
"2 10\n6 20\n",
"97 2\n99 100\n",
"17 19\n44 75\n",
"39 52\n88 78\n",
"4 2\n4 4\n",
"1 1\n1 1\n",
"... | 2CODEFORCES |
787_A. The Monster_2873 | A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, ... and Morty screams at times d, d + c, d + 2c, d + 3c, ....
<image>
The Monster will catch them if at any point they scream at the same tim... | #include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, c, d;
cin >> a >> b >> c >> d;
for (int i = 0; i <= 1e6; i++) {
long long x = (i * c) + d - b;
if (x < 0) continue;
if (x % a == 0) {
cout << x + b;
return 0;
}
}
cout << "-1";
}
| 2C++ | {
"input": [
"20 2\n9 19\n",
"2 1\n16 12\n",
"84 82\n38 6\n",
"2 3\n2 2\n",
"2 3\n4 99\n",
"3 7\n3 6\n",
"11 81\n49 7\n",
"1 1\n1 100\n",
"6 10\n12 14\n",
"2 10\n6 20\n",
"97 2\n99 100\n",
"17 19\n44 75\n",
"39 52\n88 78\n",
"4 2\n4 4\n",
"1 1\n1 1\n",
"... | 2CODEFORCES |
787_A. The Monster_2874 | A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, ... and Morty screams at times d, d + c, d + 2c, d + 3c, ....
<image>
The Monster will catch them if at any point they scream at the same tim... | import math
R=lambda:list(map(int,input().split()))
a,b=R()
c,d=R()
if abs(b-d)%math.gcd(a,c)!=0:
print(-1)
exit(0)
while b != d:
if b<d: b+=a
else: d+=c
print(b)
| 3Python3 | {
"input": [
"20 2\n9 19\n",
"2 1\n16 12\n",
"84 82\n38 6\n",
"2 3\n2 2\n",
"2 3\n4 99\n",
"3 7\n3 6\n",
"11 81\n49 7\n",
"1 1\n1 100\n",
"6 10\n12 14\n",
"2 10\n6 20\n",
"97 2\n99 100\n",
"17 19\n44 75\n",
"39 52\n88 78\n",
"4 2\n4 4\n",
"1 1\n1 1\n",
"... | 2CODEFORCES |
787_A. The Monster_2875 | A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, ... and Morty screams at times d, d + c, d + 2c, d + 3c, ....
<image>
The Monster will catch them if at any point they scream at the same tim... | import java.util.Scanner;
public class A787 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int a = s.nextInt();
int b = s.nextInt();
int c = s.nextInt();
int d = s.nextInt();
boolean[] reached = new boolean[20000];
int k = 0;
while (b + k * a < 20000) {
reached[b... | 4JAVA | {
"input": [
"20 2\n9 19\n",
"2 1\n16 12\n",
"84 82\n38 6\n",
"2 3\n2 2\n",
"2 3\n4 99\n",
"3 7\n3 6\n",
"11 81\n49 7\n",
"1 1\n1 100\n",
"6 10\n12 14\n",
"2 10\n6 20\n",
"97 2\n99 100\n",
"17 19\n44 75\n",
"39 52\n88 78\n",
"4 2\n4 4\n",
"1 1\n1 1\n",
"... | 2CODEFORCES |
808_E. Selling Souvenirs_2876 | After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for and started to sell souvenirs at the market.
This morning, as us... | n, m = map(int, raw_input().split())
C = [None, [], [], []]
for _ in xrange(n):
wi, ci = map(int, raw_input().split())
if wi == 1:
C[1].append(ci)
elif wi == 2:
C[2].append(ci)
elif wi == 3:
C[3].append(ci)
for i in xrange(1, 4):
C[i].sort()
C[i][:] = C[i][::-1]
dp = [No... | 1Python2 | {
"input": [
"4 3\n3 10\n2 7\n2 8\n1 1\n",
"2 2\n1 3\n2 2\n",
"1 1\n2 1\n",
"52 102\n3 199\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n... | 2CODEFORCES |
808_E. Selling Souvenirs_2877 | After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for and started to sell souvenirs at the market.
This morning, as us... | #include <bits/stdc++.h>
const int N = 1e5;
long long w[N];
long long c[N];
std::vector<std::pair<long long, int> > items;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
int n, m;
std::cin >> n >> m;
for (int i = 0; i < n; ++i) {
std::cin >> w[i] >> c[i];
items.push_back(std::mak... | 2C++ | {
"input": [
"4 3\n3 10\n2 7\n2 8\n1 1\n",
"2 2\n1 3\n2 2\n",
"1 1\n2 1\n",
"52 102\n3 199\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n... | 2CODEFORCES |
808_E. Selling Souvenirs_2878 | After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for and started to sell souvenirs at the market.
This morning, as us... | def f():
n, m = map(int, input().split())
l = list(tuple(map(int, input().split())) for _ in range(n))
l.sort(key=lambda e: (0, 6, 3, 2)[e[0]] * e[1], reverse=True)
last, r = [0] * 4, 0
for i, (w, c) in enumerate(l):
if m < w:
break
m -= w
r += c
last[w] =... | 3Python3 | {
"input": [
"4 3\n3 10\n2 7\n2 8\n1 1\n",
"2 2\n1 3\n2 2\n",
"1 1\n2 1\n",
"52 102\n3 199\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n... | 2CODEFORCES |
808_E. Selling Souvenirs_2879 | After several latest reforms many tourists are planning to visit Berland, and Berland people understood that it's an opportunity to earn money and changed their jobs to attract tourists. Petya, for example, left the IT corporation he had been working for and started to sell souvenirs at the market.
This morning, as us... | import java.util.*;
import java.io.*;
import java.text.*;
//Solution Credits: Taranpreet Singh
public class Main{
//SOLUTION BEGIN
void solve(int TC) throws Exception{
int n = ni(), m = ni();
long[][] a = new long[4][n+1];int[] sz = new int[4];
for(int i = 0; i< n;i++){
int ... | 4JAVA | {
"input": [
"4 3\n3 10\n2 7\n2 8\n1 1\n",
"2 2\n1 3\n2 2\n",
"1 1\n2 1\n",
"52 102\n3 199\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n2 100\n... | 2CODEFORCES |
833_A. The Meaningless Game_2880 | <image>
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's s... | #include <bits/stdc++.h>
using namespace std;
long long r;
bool is_perfect_cube(long long n) {
r = (long long)round(cbrt(n));
if (r * r * r == n) return true;
return false;
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
int a, b;
scanf("%d %d", &a, &b);
if (is_perfect_cube((long long)a * b... | 2C++ | {
"input": [
"6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n",
"1\n1062961 1031\n",
"1\n3331 11095561\n",
"1\n2 3\n",
"3\n1 1\n8 27\n1000 1331\n",
"1\n90 72\n",
"1\n12004 18012002\n",
"1\n3 10\n",
"1\n16 8\n",
"1\n3 1\n",
"1\n31159 970883281\n",
"1\n6 12\n",
... | 2CODEFORCES |
833_A. The Meaningless Game_2881 | <image>
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's s... | import sys,os,io
from sys import stdin
from math import log, gcd, ceil
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_left , bisect_right
import math
def ii():
return int(input())
def li():
return list(map(int,input().split()))
if(os.p... | 3Python3 | {
"input": [
"6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n",
"1\n1062961 1031\n",
"1\n3331 11095561\n",
"1\n2 3\n",
"3\n1 1\n8 27\n1000 1331\n",
"1\n90 72\n",
"1\n12004 18012002\n",
"1\n3 10\n",
"1\n16 8\n",
"1\n3 1\n",
"1\n31159 970883281\n",
"1\n6 12\n",
... | 2CODEFORCES |
833_A. The Meaningless Game_2882 | <image>
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting.
The game consists of multiple rounds. Its rules are very simple: in each round, a natural number k is chosen. Then, the one who says (or barks) it faster than the other wins the round. After that, the winner's s... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.InputStreamReader;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.InputS... | 4JAVA | {
"input": [
"6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000\n",
"1\n1062961 1031\n",
"1\n3331 11095561\n",
"1\n2 3\n",
"3\n1 1\n8 27\n1000 1331\n",
"1\n90 72\n",
"1\n12004 18012002\n",
"1\n3 10\n",
"1\n16 8\n",
"1\n3 1\n",
"1\n31159 970883281\n",
"1\n6 12\n",
... | 2CODEFORCES |
853_D. Michael and Charging Stations_2883 | Michael has just bought a new electric car for moving across city. Michael does not like to overwork, so each day he drives to only one of two his jobs.
Michael's day starts from charging his electric car for getting to the work and back. He spends 1000 burles on charge if he goes to the first job, and 2000 burles if ... | #include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int MOD2 = 1007681537;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
long long r;
while (... | 2C++ | {
"input": [
"6\n2000 2000 2000 2000 2000 1000\n",
"3\n1000 2000 1000\n",
"22\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000\n",
"2\n1000 2000\n",
"19\n2000 2000 1000 2000 2000 2000 2000 2000 2000 2000 2000 1000 2000 2000 2000 1000 10... | 2CODEFORCES |
853_D. Michael and Charging Stations_2884 | Michael has just bought a new electric car for moving across city. Michael does not like to overwork, so each day he drives to only one of two his jobs.
Michael's day starts from charging his electric car for getting to the work and back. He spends 1000 burles on charge if he goes to the first job, and 2000 burles if ... | import java.io.*;
import java.util.*;
public class D {
static boolean test(int mask, int i) {
return ((mask >> i) & 1) == 1;
}
static final int INF = Integer.MAX_VALUE / 3;
static final int C = 31;
int fast(int[] a) {
int n = a.length;
int[] pref = new int[n + 1];
for (int i = 0; i < n; i++) {
pref[... | 4JAVA | {
"input": [
"6\n2000 2000 2000 2000 2000 1000\n",
"3\n1000 2000 1000\n",
"22\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000 2000\n",
"2\n1000 2000\n",
"19\n2000 2000 1000 2000 2000 2000 2000 2000 2000 2000 2000 1000 2000 2000 2000 1000 10... | 2CODEFORCES |
878_B. Teams Formation_2885 | This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai.
Today the bus has completed m trips, each time bringing n participants. The participants were then aligned in ... | n, k, m = tuple([int(x) for x in raw_input().rstrip().split()])
a = [int(x) for x in raw_input().rstrip().split()]
stack = []
for aa in a:
if len(stack) == 0 or aa != stack[-1][0]:
stack.append([aa, 1])
else:
stack[-1][1] += 1
if stack[-1][1] == k:
stack.pop()
rem = 0
star... | 1Python2 | {
"input": [
"4 2 5\n1 2 3 1\n",
"1 9 10\n1\n",
"3 2 10\n1 2 1\n",
"10 5 1000000000\n1 1 1 2 2 1 2 2 2 2\n",
"5 3 3\n1 2 2 1 1\n",
"2 4 1\n1 1\n",
"1 1000000000 1000000000\n100000\n",
"5 3 2\n1 1 2 1 1\n",
"5 2 4\n1 2 3 2 1\n",
"1 10 10\n1\n",
"2 4 1\n1 0\n",
"5 3 2\n1 ... | 2CODEFORCES |
878_B. Teams Formation_2886 | This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai.
Today the bus has completed m trips, each time bringing n participants. The participants were then aligned in ... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, b;
scanf("%d%d%d", &n, &k, &b);
stack<pair<int, int> > st;
long long ans = (long long)n * b;
for (int i = 0, a; i < n; i++) {
scanf("%d", &a);
if (st.size() && st.top().first == a) {
st.top().second++;
if (st.top().second... | 2C++ | {
"input": [
"4 2 5\n1 2 3 1\n",
"1 9 10\n1\n",
"3 2 10\n1 2 1\n",
"10 5 1000000000\n1 1 1 2 2 1 2 2 2 2\n",
"5 3 3\n1 2 2 1 1\n",
"2 4 1\n1 1\n",
"1 1000000000 1000000000\n100000\n",
"5 3 2\n1 1 2 1 1\n",
"5 2 4\n1 2 3 2 1\n",
"1 10 10\n1\n",
"2 4 1\n1 0\n",
"5 3 2\n1 ... | 2CODEFORCES |
878_B. Teams Formation_2887 | This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai.
Today the bus has completed m trips, each time bringing n participants. The participants were then aligned in ... | import sys
from collections import deque
input=sys.stdin.readline
n,k,m=map(int,input().split())
a=list(map(int,input().split()))
r=a[0]
flag=0
for i in range(n):
if r!=a[i]:
flag=1
break
if flag==0:
print((m*n)%k)
sys.exit()
if k>n:
print(m*n)
sys.exit()
curr=a[0]
tmp=1
que=deque([(a[0],1)])
for i in... | 3Python3 | {
"input": [
"4 2 5\n1 2 3 1\n",
"1 9 10\n1\n",
"3 2 10\n1 2 1\n",
"10 5 1000000000\n1 1 1 2 2 1 2 2 2 2\n",
"5 3 3\n1 2 2 1 1\n",
"2 4 1\n1 1\n",
"1 1000000000 1000000000\n100000\n",
"5 3 2\n1 1 2 1 1\n",
"5 2 4\n1 2 3 2 1\n",
"1 10 10\n1\n",
"2 4 1\n1 0\n",
"5 3 2\n1 ... | 2CODEFORCES |
878_B. Teams Formation_2888 | This time the Berland Team Olympiad in Informatics is held in a remote city that can only be reached by one small bus. Bus has n passenger seats, seat i can be occupied only by a participant from the city ai.
Today the bus has completed m trips, each time bringing n participants. The participants were then aligned in ... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.StringTokenizer;
// 12321
// 123434343434343434343421
public class b {
public static void main(S... | 4JAVA | {
"input": [
"4 2 5\n1 2 3 1\n",
"1 9 10\n1\n",
"3 2 10\n1 2 1\n",
"10 5 1000000000\n1 1 1 2 2 1 2 2 2 2\n",
"5 3 3\n1 2 2 1 1\n",
"2 4 1\n1 1\n",
"1 1000000000 1000000000\n100000\n",
"5 3 2\n1 1 2 1 1\n",
"5 2 4\n1 2 3 2 1\n",
"1 10 10\n1\n",
"2 4 1\n1 0\n",
"5 3 2\n1 ... | 2CODEFORCES |
901_D. Weighting a Tree_2889 | You are given a connected undirected graph with n vertices and m edges. The vertices are enumerated from 1 to n.
You are given n integers c1, c2, ..., cn, each of them is between - n and n, inclusive. It is also guaranteed that the parity of cv equals the parity of degree of vertex v. The degree of a vertex is the n... | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int M = N * 25;
int n, m;
long long C[M], x, y, tar[N], dep[N], in[M];
int fir[N], ne[M], to[M], cnt = 1, fa[N], fan[N];
void add(int x, int y) {
ne[++cnt] = fir[x];
fir[x] = cnt;
to[cnt] = y;
}
void link(int x, int y) {
add(x, y);
add... | 2C++ | {
"input": [
"6 6\n3 5 5 5 1 5\n1 4\n3 2\n4 3\n4 5\n3 5\n5 6\n",
"4 4\n4 4 2 4\n1 2\n2 3\n3 4\n4 1\n",
"3 3\n2 2 2\n1 2\n2 3\n1 3\n",
"4 3\n-1 0 2 1\n1 2\n2 3\n3 4\n",
"2 1\n1 1\n2 1\n",
"8 12\n-6 2 -3 2 6 -7 1 -5\n2 1\n5 6\n1 6\n1 4\n8 2\n2 7\n2 5\n8 3\n8 4\n3 7\n7 6\n3 1\n",
"10 13\n3 4 ... | 2CODEFORCES |
901_D. Weighting a Tree_2890 | You are given a connected undirected graph with n vertices and m edges. The vertices are enumerated from 1 to n.
You are given n integers c1, c2, ..., cn, each of them is between - n and n, inclusive. It is also guaranteed that the parity of cv equals the parity of degree of vertex v. The degree of a vertex is the n... |
def divisors(M):
d=[]
i=1
while M>=i**2:
if M%i==0:
d.append(i)
if i**2!=M:
d.append(M//i)
i=i+1
return d
def popcount(x):
x = x - ((x >> 1) & 0x55555555)
x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
x = (x + (x >> 4)) & 0x0f0f0f0f
... | 3Python3 | {
"input": [
"6 6\n3 5 5 5 1 5\n1 4\n3 2\n4 3\n4 5\n3 5\n5 6\n",
"4 4\n4 4 2 4\n1 2\n2 3\n3 4\n4 1\n",
"3 3\n2 2 2\n1 2\n2 3\n1 3\n",
"4 3\n-1 0 2 1\n1 2\n2 3\n3 4\n",
"2 1\n1 1\n2 1\n",
"8 12\n-6 2 -3 2 6 -7 1 -5\n2 1\n5 6\n1 6\n1 4\n8 2\n2 7\n2 5\n8 3\n8 4\n3 7\n7 6\n3 1\n",
"10 13\n3 4 ... | 2CODEFORCES |
901_D. Weighting a Tree_2891 | You are given a connected undirected graph with n vertices and m edges. The vertices are enumerated from 1 to n.
You are given n integers c1, c2, ..., cn, each of them is between - n and n, inclusive. It is also guaranteed that the parity of cv equals the parity of degree of vertex v. The degree of a vertex is the n... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.stream.Stream;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchExce... | 4JAVA | {
"input": [
"6 6\n3 5 5 5 1 5\n1 4\n3 2\n4 3\n4 5\n3 5\n5 6\n",
"4 4\n4 4 2 4\n1 2\n2 3\n3 4\n4 1\n",
"3 3\n2 2 2\n1 2\n2 3\n1 3\n",
"4 3\n-1 0 2 1\n1 2\n2 3\n3 4\n",
"2 1\n1 1\n2 1\n",
"8 12\n-6 2 -3 2 6 -7 1 -5\n2 1\n5 6\n1 6\n1 4\n8 2\n2 7\n2 5\n8 3\n8 4\n3 7\n7 6\n3 1\n",
"10 13\n3 4 ... | 2CODEFORCES |
924_A. Mystical Mosaic_2892 | There is a rectangular grid of n rows of m initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. For each row r in Ri and each column c in Ci, the intersection of row r and... | def main():
res,car=map(long,raw_input().split())
k=[]
p=[]
for i in xrange(res):
p.append(raw_input())
ms=set(p)
for i in ms:
for cer,ver in enumerate(i):
if ver=="#":
k.append(cer)
gs=set(k)
for i in gs:
if k.count(i)>1:
... | 1Python2 | {
"input": [
"5 9\n........#\n#........\n..##.#...\n.......#.\n....#.#.#\n",
"5 5\n..#..\n..#..\n#####\n..#..\n..#..\n",
"5 8\n.#.#..#.\n.....#..\n.#.#..#.\n#.#....#\n.....#..\n",
"9 5\n.....\n#....\n..#..\n.....\n.#..#\n...#.\n.#...\n....#\n.....\n",
"4 10\n..#......#\n.....##...\n#.........\n.#.... | 2CODEFORCES |
924_A. Mystical Mosaic_2893 | There is a rectangular grid of n rows of m initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. For each row r in Ri and each column c in Ci, the intersection of row r and... | #include <bits/stdc++.h>
using namespace std;
vector<int> g[500];
vector<int> rg[500];
int n, m;
string s[500];
int curc = 0;
int color[500];
int color2[500];
set<int> c1[500];
set<int> c2[500];
void no() {
cout << "No\n";
exit(0);
}
void yes() {
cout << "Yes\n";
exit(0);
}
void dfs2(int j);
void dfs(int i) {
... | 2C++ | {
"input": [
"5 9\n........#\n#........\n..##.#...\n.......#.\n....#.#.#\n",
"5 5\n..#..\n..#..\n#####\n..#..\n..#..\n",
"5 8\n.#.#..#.\n.....#..\n.#.#..#.\n#.#....#\n.....#..\n",
"9 5\n.....\n#....\n..#..\n.....\n.#..#\n...#.\n.#...\n....#\n.....\n",
"4 10\n..#......#\n.....##...\n#.........\n.#.... | 2CODEFORCES |
924_A. Mystical Mosaic_2894 | There is a rectangular grid of n rows of m initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. For each row r in Ri and each column c in Ci, the intersection of row r and... | def read_data():
n, m = map(int, input().strip().split())
a = []
for i in range(n):
line = list(input().strip())
for j in range(len(line)):
if line[j] == ".":
line[j] = 0
else:
line[j] = 1
a.append(line)
return n, m, a
def ... | 3Python3 | {
"input": [
"5 9\n........#\n#........\n..##.#...\n.......#.\n....#.#.#\n",
"5 5\n..#..\n..#..\n#####\n..#..\n..#..\n",
"5 8\n.#.#..#.\n.....#..\n.#.#..#.\n#.#....#\n.....#..\n",
"9 5\n.....\n#....\n..#..\n.....\n.#..#\n...#.\n.#...\n....#\n.....\n",
"4 10\n..#......#\n.....##...\n#.........\n.#.... | 2CODEFORCES |
924_A. Mystical Mosaic_2895 | There is a rectangular grid of n rows of m initially-white cells each.
Arkady performed a certain number (possibly zero) of operations on it. In the i-th operation, a non-empty subset of rows Ri and a non-empty subset of columns Ci are chosen. For each row r in Ri and each column c in Ci, the intersection of row r and... | //package com.kanari;
import java.io.*;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
int n = in.nextInt(), m = in.nextInt(... | 4JAVA | {
"input": [
"5 9\n........#\n#........\n..##.#...\n.......#.\n....#.#.#\n",
"5 5\n..#..\n..#..\n#####\n..#..\n..#..\n",
"5 8\n.#.#..#.\n.....#..\n.#.#..#.\n#.#....#\n.....#..\n",
"9 5\n.....\n#....\n..#..\n.....\n.#..#\n...#.\n.#...\n....#\n.....\n",
"4 10\n..#......#\n.....##...\n#.........\n.#.... | 2CODEFORCES |
952_C. Ravioli Sort_2896 | Everybody knows of [spaghetti sort](https://en.wikipedia.org/wiki/Spaghetti_sort). You decided to implement an analog sorting algorithm yourself, but as you survey your pantry you realize you're out of spaghetti! The only type of pasta you have is ravioli, but you are not going to let this stop you...
You come up with... | n=input()
a=map(int,raw_input().split())
for i in range(n-1):
if abs(a[i]-a[i+1])>=2:
print 'NO'
exit(0)
print 'YES' | 1Python2 | {
"input": [
"3\n3 1 2\n",
"3\n1 2 3\n",
"4\n90 91 90 91\n",
"4\n54 54 54 55\n",
"10\n55 39 93 42 97 40 36 38 11 97\n",
"3\n90 39 98\n",
"5\n21 57 40 94 17\n",
"8\n46 4 30 85 52 6 84 13\n",
"6\n47 100 96 2 96 43\n",
"4\n61 28 3 81\n",
"5\n14 91 91 91 84\n",
"3\n22 23 24... | 2CODEFORCES |
952_C. Ravioli Sort_2897 | Everybody knows of [spaghetti sort](https://en.wikipedia.org/wiki/Spaghetti_sort). You decided to implement an analog sorting algorithm yourself, but as you survey your pantry you realize you're out of spaghetti! The only type of pasta you have is ravioli, but you are not going to let this stop you...
You come up with... | #include <bits/stdc++.h>
using namespace std;
int n, a[111];
bool u[111];
bool pr(int x) {
int y = -1, z = -1;
for (int i = x; i < n; ++i)
if (!u[i]) {
y = a[i];
break;
}
for (int i = x; i >= 0; --i)
if (!u[i]) {
z = a[i];
break;
}
if (y < 0 || z < 0)
return 0;
else... | 2C++ | {
"input": [
"3\n3 1 2\n",
"3\n1 2 3\n",
"4\n90 91 90 91\n",
"4\n54 54 54 55\n",
"10\n55 39 93 42 97 40 36 38 11 97\n",
"3\n90 39 98\n",
"5\n21 57 40 94 17\n",
"8\n46 4 30 85 52 6 84 13\n",
"6\n47 100 96 2 96 43\n",
"4\n61 28 3 81\n",
"5\n14 91 91 91 84\n",
"3\n22 23 24... | 2CODEFORCES |
952_C. Ravioli Sort_2898 | Everybody knows of [spaghetti sort](https://en.wikipedia.org/wiki/Spaghetti_sort). You decided to implement an analog sorting algorithm yourself, but as you survey your pantry you realize you're out of spaghetti! The only type of pasta you have is ravioli, but you are not going to let this stop you...
You come up with... | n = int(input())
l = [int(x) for x in input().split()]
while len(l) > 1:
if len([i for i in range(len(l)-1) if abs(l[i] - l[i+1]) > 1 ])>0:
print ('NO')
exit(0)
l.remove(max(l))
print('YES')
| 3Python3 | {
"input": [
"3\n3 1 2\n",
"3\n1 2 3\n",
"4\n90 91 90 91\n",
"4\n54 54 54 55\n",
"10\n55 39 93 42 97 40 36 38 11 97\n",
"3\n90 39 98\n",
"5\n21 57 40 94 17\n",
"8\n46 4 30 85 52 6 84 13\n",
"6\n47 100 96 2 96 43\n",
"4\n61 28 3 81\n",
"5\n14 91 91 91 84\n",
"3\n22 23 24... | 2CODEFORCES |
952_C. Ravioli Sort_2899 | Everybody knows of [spaghetti sort](https://en.wikipedia.org/wiki/Spaghetti_sort). You decided to implement an analog sorting algorithm yourself, but as you survey your pantry you realize you're out of spaghetti! The only type of pasta you have is ravioli, but you are not going to let this stop you...
You come up with... | import java.util.Scanner;
public class APRILFOOLB {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int[] arr = new int[n];
for(int i = 0;i<n;i++){
arr[i] = s.nextInt();
}
boolean bool =false;
for(... | 4JAVA | {
"input": [
"3\n3 1 2\n",
"3\n1 2 3\n",
"4\n90 91 90 91\n",
"4\n54 54 54 55\n",
"10\n55 39 93 42 97 40 36 38 11 97\n",
"3\n90 39 98\n",
"5\n21 57 40 94 17\n",
"8\n46 4 30 85 52 6 84 13\n",
"6\n47 100 96 2 96 43\n",
"4\n61 28 3 81\n",
"5\n14 91 91 91 84\n",
"3\n22 23 24... | 2CODEFORCES |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.