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 |
|---|---|---|---|---|---|
284_B. Cows and Poker Game_100 | There are n cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player whose current status is not "FOLDED" may show his/her hand to the table. However, so as not to affect any bett... | #! /bin/python
n = int(raw_input())
s = raw_input()
#I = [s.index(i) for i in s if i == 'I']
#A = [s.index(i) for i in s if i == 'A']
I = 0
A = 0
for i in s:
if i == 'I':I += 1
elif i == 'A': A += 1
#print I,A
if I > 1:
print '0'
elif I == 1:
print '1'
else:
print A
| 1Python2 | {
"input": [
"3\nAFI\n",
"6\nAFFAAA\n",
"2\nFF\n",
"5\nIIIIF\n",
"5\nFAFFF\n",
"2\nFA\n",
"3\nAAA\n",
"5\nFAIAF\n",
"5\nAIFFF\n",
"3\nFFF\n",
"3\nFIF\n",
"3\nIII\n",
"5\nFAAII\n",
"2\nIF\n",
"8\nAFFFFIAF\n",
"5\nIIIII\n",
"3\nIAA\n",
"10\nAAAAAAA... | 2CODEFORCES |
284_B. Cows and Poker Game_101 | There are n cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player whose current status is not "FOLDED" may show his/her hand to the table. However, so as not to affect any bett... | #include <bits/stdc++.h>
using namespace std;
template <class T>
void pp(T v) {
for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); ++it)
cout << *it << ' ';
cout << endl;
}
template <class T>
void pp(T v, int n) {
for (int i = 0; i < (int)n; i++) cout << v[i] << ' ';
cout << endl;
}
template <cla... | 2C++ | {
"input": [
"3\nAFI\n",
"6\nAFFAAA\n",
"2\nFF\n",
"5\nIIIIF\n",
"5\nFAFFF\n",
"2\nFA\n",
"3\nAAA\n",
"5\nFAIAF\n",
"5\nAIFFF\n",
"3\nFFF\n",
"3\nFIF\n",
"3\nIII\n",
"5\nFAAII\n",
"2\nIF\n",
"8\nAFFFFIAF\n",
"5\nIIIII\n",
"3\nIAA\n",
"10\nAAAAAAA... | 2CODEFORCES |
284_B. Cows and Poker Game_102 | There are n cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player whose current status is not "FOLDED" may show his/her hand to the table. However, so as not to affect any bett... | #!/bin/python
# -*- coding: utf-8 -*-
n = int(input())
s = input()
print(int(s.count('I') == 1) if 'I' in s else s.count('A'))
| 3Python3 | {
"input": [
"3\nAFI\n",
"6\nAFFAAA\n",
"2\nFF\n",
"5\nIIIIF\n",
"5\nFAFFF\n",
"2\nFA\n",
"3\nAAA\n",
"5\nFAIAF\n",
"5\nAIFFF\n",
"3\nFFF\n",
"3\nFIF\n",
"3\nIII\n",
"5\nFAAII\n",
"2\nIF\n",
"8\nAFFFFIAF\n",
"5\nIIIII\n",
"3\nIAA\n",
"10\nAAAAAAA... | 2CODEFORCES |
284_B. Cows and Poker Game_103 | There are n cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player whose current status is not "FOLDED" may show his/her hand to the table. However, so as not to affect any bett... | import java.util.Scanner;
public class Poker {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int jugadores = sc.nextInt();
String status = null;
int mostrar = 0;
int a = 0;
int i = 0;
int f = 0;
status = sc... | 4JAVA | {
"input": [
"3\nAFI\n",
"6\nAFFAAA\n",
"2\nFF\n",
"5\nIIIIF\n",
"5\nFAFFF\n",
"2\nFA\n",
"3\nAAA\n",
"5\nFAIAF\n",
"5\nAIFFF\n",
"3\nFFF\n",
"3\nFIF\n",
"3\nIII\n",
"5\nFAAII\n",
"2\nIF\n",
"8\nAFFFFIAF\n",
"5\nIIIII\n",
"3\nIAA\n",
"10\nAAAAAAA... | 2CODEFORCES |
309_B. Context Advertising_104 | Advertising has become part of our routine. And now, in the era of progressive technologies, we need your ideas to make advertising better!
In this problem we'll look at a simplified version of context advertising. You've got a text, consisting of exactly n words. A standard advertising banner has exactly r lines, eac... | #include <bits/stdc++.h>
using namespace std;
const int N = 1000100, L = 5000500, BufL = 220;
char ch[N + L] = {}, buf[BufL] = {};
int n, r, c, l, a[N] = {}, p[N] = {}, f[N] = {}, g[N] = {};
int main() {
gets(buf + 1);
sscanf(buf + 1, "%d%d%d", &n, &r, &c);
gets(ch + 1);
l = strlen(ch + 1);
for (int i = 1, to... | 2C++ | {
"input": [
"9 4 12\nthis is a sample text for croc final round\n",
"9 1 9\nthis is a sample text for croc final round\n",
"2 2 5\nfirst second\n",
"6 2 3\ncroc a a a croc a\n",
"10 20 11\nisnr u eq qas gcj rnnf fpb c dz g\n",
"10 4 3\nuzu bl fl ou uist j lp e gkp fmo\n",
"10 10 19\nlguv ... | 2CODEFORCES |
309_B. Context Advertising_105 | Advertising has become part of our routine. And now, in the era of progressive technologies, we need your ideas to make advertising better!
In this problem we'll look at a simplified version of context advertising. You've got a text, consisting of exactly n words. A standard advertising banner has exactly r lines, eac... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Locale;
import java.util.StringTokenizer;
public class B {
private void solve() throws IOException {
int n = nextInt();... | 4JAVA | {
"input": [
"9 4 12\nthis is a sample text for croc final round\n",
"9 1 9\nthis is a sample text for croc final round\n",
"2 2 5\nfirst second\n",
"6 2 3\ncroc a a a croc a\n",
"10 20 11\nisnr u eq qas gcj rnnf fpb c dz g\n",
"10 4 3\nuzu bl fl ou uist j lp e gkp fmo\n",
"10 10 19\nlguv ... | 2CODEFORCES |
331_E2. Deja Vu_106 | Everybody knows that we have been living in the Matrix for a long time. And in the new seventh Matrix the world is ruled by beavers.
So let's take beaver Neo. Neo has so-called "deja vu" outbursts when he gets visions of events in some places he's been at or is going to be at. Let's examine the phenomenon in more deta... | #include <bits/stdc++.h>
using namespace std;
const int MAX = 100 + 10;
const int Mod = (int)1e9 + 7;
int n, m;
int g[MAX][MAX], can[MAX][MAX];
vector<int> p[MAX][MAX];
int get(vector<int> &before, int kind, int could, int have) {
int j;
int now = 0, cc = have;
for (; now < (int)before.size(); now++) {
if (no... | 2C++ | {
"input": [
"6 6\n1 2 2 1 2\n2 3 1 3\n3 4 2 4 5\n4 5 0\n5 3 1 3\n6 1 1 6\n",
"6 6\n1 2 2 1 2\n2 3 1 3\n3 4 2 4 5\n4 5 0\n5 3 1 3\n6 1 1 6\n",
"1 0\n",
"2 1\n1 2 0\n",
"5 4\n1 2 3 3 1 2\n5 4 0\n4 3 0\n3 1 2 5 4\n",
"3 3\n1 2 2 3 2\n1 3 2 3 3\n2 3 2 2 3\n",
"11 17\n1 2 5 3 4 1 2 5\n1 3 0\n1... | 2CODEFORCES |
354_E. Lucky Number Representation_107 | We know that lucky digits are digits 4 and 7, however Vasya's got another favorite digit 0 and he assumes it also is lucky! Lucky numbers are such non-negative integers whose decimal record only contains lucky digits. For example, numbers 0, 47, 7074 are lucky, but 1, 7377, 895, -7 are not.
Vasya has t important posi... | #include <bits/stdc++.h>
using namespace std;
set<long long> kharab = {1, 2, 3, 5, 6, 9, 10, 13, 17, 31, 34,
37, 38, 41, 43, 45, 46, 49, 50, 53, 57, 71,
83, 111, 123, 391, 403, 437, 457, 471, 483, 511, 523};
long long a[6];
vector<long long> D[43... | 2C++ | {
"input": [
"5\n42\n17\n444\n7\n51\n",
"5\n42\n17\n444\n7\n51\n",
"5\n42\n17\n444\n7\n52\n",
"5\n42\n17\n640\n7\n51\n",
"5\n42\n15\n444\n7\n52\n",
"5\n42\n21\n640\n7\n51\n",
"5\n35\n15\n444\n7\n52\n",
"5\n42\n21\n640\n7\n44\n",
"5\n42\n17\n444\n11\n51\n",
"5\n42\n17\n444\n1\n5... | 2CODEFORCES |
354_E. Lucky Number Representation_108 | We know that lucky digits are digits 4 and 7, however Vasya's got another favorite digit 0 and he assumes it also is lucky! Lucky numbers are such non-negative integers whose decimal record only contains lucky digits. For example, numbers 0, 47, 7074 are lucky, but 1, 7377, 895, -7 are not.
Vasya has t important posi... | import java.io.InputStreamReader;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.Writer;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution ... | 4JAVA | {
"input": [
"5\n42\n17\n444\n7\n51\n",
"5\n42\n17\n444\n7\n51\n",
"5\n42\n17\n444\n7\n52\n",
"5\n42\n17\n640\n7\n51\n",
"5\n42\n15\n444\n7\n52\n",
"5\n42\n21\n640\n7\n51\n",
"5\n35\n15\n444\n7\n52\n",
"5\n42\n21\n640\n7\n44\n",
"5\n42\n17\n444\n11\n51\n",
"5\n42\n17\n444\n1\n5... | 2CODEFORCES |
379_A. New Year Candles_109 | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make b went out candles into a new candle. As a result, this new candle can be used like... | a, b = map(int, raw_input().strip().split(' '))
c = (a)
while c >= b:
t = c / b
c = t + c % b
a += t
print a
| 1Python2 | {
"input": [
"4 2\n",
"6 3\n",
"5 3\n",
"1000 3\n",
"777 17\n",
"4 3\n",
"2 2\n",
"100 4\n",
"10 4\n",
"999 2\n",
"6 4\n",
"1 2\n",
"17 3\n",
"1 4\n",
"26 8\n",
"91 5\n",
"1 3\n",
"1000 2\n",
"20 3\n",
"9 4\n",
"123 5\n",
"1000 10... | 2CODEFORCES |
379_A. New Year Candles_110 | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make b went out candles into a new candle. As a result, this new candle can be used like... | #include <bits/stdc++.h>
using namespace std;
const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1e9 + 100;
const long long LINF = 1e18 + 100;
int32_t main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
int a, b;
cin >> a >> b;
int x = 0, ans = 0;
while (a) {
ans += a;
x +=... | 2C++ | {
"input": [
"4 2\n",
"6 3\n",
"5 3\n",
"1000 3\n",
"777 17\n",
"4 3\n",
"2 2\n",
"100 4\n",
"10 4\n",
"999 2\n",
"6 4\n",
"1 2\n",
"17 3\n",
"1 4\n",
"26 8\n",
"91 5\n",
"1 3\n",
"1000 2\n",
"20 3\n",
"9 4\n",
"123 5\n",
"1000 10... | 2CODEFORCES |
379_A. New Year Candles_111 | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make b went out candles into a new candle. As a result, this new candle can be used like... | a, b = map(int, input().split())
c, s = a, 0
while a >= b:
s += a // b
a = (a // b) + (a % b)
print(s + c)
| 3Python3 | {
"input": [
"4 2\n",
"6 3\n",
"5 3\n",
"1000 3\n",
"777 17\n",
"4 3\n",
"2 2\n",
"100 4\n",
"10 4\n",
"999 2\n",
"6 4\n",
"1 2\n",
"17 3\n",
"1 4\n",
"26 8\n",
"91 5\n",
"1 3\n",
"1000 2\n",
"20 3\n",
"9 4\n",
"123 5\n",
"1000 10... | 2CODEFORCES |
379_A. New Year Candles_112 | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make b went out candles into a new candle. As a result, this new candle can be used like... |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a = in.nextInt();
int b = in.nextInt();
int num_hours = a;
while (true) {
if (a < b) {
break;
}
num_hours += a / b;
a = a / b + a % b;
}
System.out.prin... | 4JAVA | {
"input": [
"4 2\n",
"6 3\n",
"5 3\n",
"1000 3\n",
"777 17\n",
"4 3\n",
"2 2\n",
"100 4\n",
"10 4\n",
"999 2\n",
"6 4\n",
"1 2\n",
"17 3\n",
"1 4\n",
"26 8\n",
"91 5\n",
"1 3\n",
"1000 2\n",
"20 3\n",
"9 4\n",
"123 5\n",
"1000 10... | 2CODEFORCES |
39_H. Multiplication Table_113 | Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multiplication. To multiply large numbers one has to learn the multiplication table. Unfortunately, in the second grade students learn... | def zetom(a,b):
res=''
s=a
while s/b>0:
res+=str(s%b)
s=s/b
res+=str(s)
t=res[::-1]
return t
k=input()
for i in range(1,k):
for j in range(1,k):
res=i*j
if res>=k:
res=zetom (res,k)
print res,
print
| 1Python2 | {
"input": [
"10\n",
"3\n",
"9\n",
"8\n",
"6\n",
"4\n",
"7\n",
"5\n",
"2\n",
"010\n"
],
"output": [
"1 2 3 4 5 6 7 8 9 \n2 4 6 8 10 12 14 16 18 \n3 6 9 12 15 18 21 24 27 \n4 8 12 16 20 24 28 32 36 \n5 10 15 20 25 30 35 40 45 \n6 12 18 24 30 36 42 48 54 \n7... | 2CODEFORCES |
39_H. Multiplication Table_114 | Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multiplication. To multiply large numbers one has to learn the multiplication table. Unfortunately, in the second grade students learn... | #include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int inline in() {
int x = 0, c;
for (; (unsigned)((c = getchar()) - '0') >= 10;) {
if (c == '-') return -in();
if (!~c) throw ~0;
}
do {
x = (x << 3) + (x << 1) + (c - '0');
} while ((unsigned)((c = getchar()) - '0') < 10);
... | 2C++ | {
"input": [
"10\n",
"3\n",
"9\n",
"8\n",
"6\n",
"4\n",
"7\n",
"5\n",
"2\n",
"010\n"
],
"output": [
"1 2 3 4 5 6 7 8 9 \n2 4 6 8 10 12 14 16 18 \n3 6 9 12 15 18 21 24 27 \n4 8 12 16 20 24 28 32 36 \n5 10 15 20 25 30 35 40 45 \n6 12 18 24 30 36 42 48 54 \n7... | 2CODEFORCES |
39_H. Multiplication Table_115 | Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multiplication. To multiply large numbers one has to learn the multiplication table. Unfortunately, in the second grade students learn... | k=int(input())
for i in range(1,k):
z,a=i,[]
for j in range(k-1):
p,s=z,""
while p:
s=str(p%k)+s
p//=k
z+=i
a.append(s)
print(*a)
| 3Python3 | {
"input": [
"10\n",
"3\n",
"9\n",
"8\n",
"6\n",
"4\n",
"7\n",
"5\n",
"2\n",
"010\n"
],
"output": [
"1 2 3 4 5 6 7 8 9 \n2 4 6 8 10 12 14 16 18 \n3 6 9 12 15 18 21 24 27 \n4 8 12 16 20 24 28 32 36 \n5 10 15 20 25 30 35 40 45 \n6 12 18 24 30 36 42 48 54 \n7... | 2CODEFORCES |
39_H. Multiplication Table_116 | Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action — multiplication. To multiply large numbers one has to learn the multiplication table. Unfortunately, in the second grade students learn... |
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = in.nextInt();
for (int i = 1; i < n; i++) {
for (int j = 1; j < n; j++) {
... | 4JAVA | {
"input": [
"10\n",
"3\n",
"9\n",
"8\n",
"6\n",
"4\n",
"7\n",
"5\n",
"2\n",
"010\n"
],
"output": [
"1 2 3 4 5 6 7 8 9 \n2 4 6 8 10 12 14 16 18 \n3 6 9 12 15 18 21 24 27 \n4 8 12 16 20 24 28 32 36 \n5 10 15 20 25 30 35 40 45 \n6 12 18 24 30 36 42 48 54 \n7... | 2CODEFORCES |
425_D. Sereja and Squares_117 | Sereja has painted n distinct points on the plane. The coordinates of each point are integers. Now he is wondering: how many squares are there with sides parallel to the coordinate axes and with points painted in all its four vertexes? Help him, calculate this number.
Input
The first line contains integer n (1 ≤ n ≤ ... | #include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-12;
const int maxn = 100000 + 1912;
const int MX = 1e6;
int n;
pair<int, int> a[maxn];
vector<int> p[MX * 2 + 3];
long long res = 0;
void ReadData() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d%d", &a[i].first, &a[i].second)... | 2C++ | {
"input": [
"5\n0 0\n0 2\n2 0\n2 2\n1 1\n",
"9\n0 0\n1 1\n2 2\n0 1\n1 0\n0 2\n2 0\n1 2\n2 1\n",
"81\n9 4\n6 8\n6 4\n4 6\n4 8\n9 10\n0 2\n5 4\n8 9\n7 7\n10 5\n4 4\n7 8\n3 7\n2 1\n5 5\n2 7\n8 6\n2 8\n10 7\n5 8\n0 10\n10 0\n4 9\n4 2\n10 3\n6 6\n3 8\n5 3\n8 8\n10 9\n1 1\n0 9\n8 1\n1 8\n0 7\n10 4\n3 6\n7 6\n1... | 2CODEFORCES |
425_D. Sereja and Squares_118 | Sereja has painted n distinct points on the plane. The coordinates of each point are integers. Now he is wondering: how many squares are there with sides parallel to the coordinate axes and with points painted in all its four vertexes? Help him, calculate this number.
Input
The first line contains integer n (1 ≤ n ≤ ... |
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.LongBuffer;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.StringTokenizer;
public class R243D1D {
static class Point{
int x; int y;
public Point(){}
public Po... | 4JAVA | {
"input": [
"5\n0 0\n0 2\n2 0\n2 2\n1 1\n",
"9\n0 0\n1 1\n2 2\n0 1\n1 0\n0 2\n2 0\n1 2\n2 1\n",
"81\n9 4\n6 8\n6 4\n4 6\n4 8\n9 10\n0 2\n5 4\n8 9\n7 7\n10 5\n4 4\n7 8\n3 7\n2 1\n5 5\n2 7\n8 6\n2 8\n10 7\n5 8\n0 10\n10 0\n4 9\n4 2\n10 3\n6 6\n3 8\n5 3\n8 8\n10 9\n1 1\n0 9\n8 1\n1 8\n0 7\n10 4\n3 6\n7 6\n1... | 2CODEFORCES |
44_B. Cola_119 | To celebrate the opening of the Winter Computer School the organizers decided to buy in n liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1 and 2 liters in volume. At that, there are exactly a bottles 0.5 in volume, b one-liter bottles and c of two... | import math
n, a, b, c = [int(i) for i in raw_input().split()]
ans = 0
for i in range(0, a+1):
for j in range(0, b+1):
t = (n - 0.5*i - j)/2
if t >= 0 and t <= c and t == math.floor(t):
ans += 1
print(ans) | 1Python2 | {
"input": [
"10 5 5 5\n",
"3 0 0 2\n",
"10 20 10 5\n",
"20 1 2 3\n",
"7 2 2 2\n",
"25 10 5 10\n",
"999 999 899 299\n",
"10000 5000 0 5000\n",
"2 2 2 2\n",
"1 0 2 0\n",
"3 3 2 1\n",
"1 1 0 0\n",
"1 0 0 1\n",
"20 10 20 30\n",
"505 142 321 12\n",
"101 10 1... | 2CODEFORCES |
44_B. Cola_120 | To celebrate the opening of the Winter Computer School the organizers decided to buy in n liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1 and 2 liters in volume. At that, there are exactly a bottles 0.5 in volume, b one-liter bottles and c of two... | #include <bits/stdc++.h>
using namespace std;
int main() {
double n;
int a, b, c, ans = 0;
cin >> n >> a >> b >> c;
for (int i = min(int(n / 2), c); i >= 0; i--) {
for (int j = min(int(n - 2 * i), b); j >= 0; j--) {
if (a / 2 + j + i * 2 >= n) {
ans++;
}
}
}
cout << ans;
return... | 2C++ | {
"input": [
"10 5 5 5\n",
"3 0 0 2\n",
"10 20 10 5\n",
"20 1 2 3\n",
"7 2 2 2\n",
"25 10 5 10\n",
"999 999 899 299\n",
"10000 5000 0 5000\n",
"2 2 2 2\n",
"1 0 2 0\n",
"3 3 2 1\n",
"1 1 0 0\n",
"1 0 0 1\n",
"20 10 20 30\n",
"505 142 321 12\n",
"101 10 1... | 2CODEFORCES |
44_B. Cola_121 | To celebrate the opening of the Winter Computer School the organizers decided to buy in n liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1 and 2 liters in volume. At that, there are exactly a bottles 0.5 in volume, b one-liter bottles and c of two... | def nik(rudy,x,y,z,cot):
for i in range(z+1):
for j in range(y+1):
t = rudy - i*2 -j
if t>=0 and x*0.5 >= t:
cot+=1
return cot
rudy, x, y, z = list(map(int,input().split()))
cot = 0
print(nik(rudy,x,y,z,cot))
| 3Python3 | {
"input": [
"10 5 5 5\n",
"3 0 0 2\n",
"10 20 10 5\n",
"20 1 2 3\n",
"7 2 2 2\n",
"25 10 5 10\n",
"999 999 899 299\n",
"10000 5000 0 5000\n",
"2 2 2 2\n",
"1 0 2 0\n",
"3 3 2 1\n",
"1 1 0 0\n",
"1 0 0 1\n",
"20 10 20 30\n",
"505 142 321 12\n",
"101 10 1... | 2CODEFORCES |
44_B. Cola_122 | To celebrate the opening of the Winter Computer School the organizers decided to buy in n liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1 and 2 liters in volume. At that, there are exactly a bottles 0.5 in volume, b one-liter bottles and c of two... | import org.omg.PortableInterceptor.SYSTEM_EXCEPTION;
import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
public class Main {
public static void main(String[] args) throws IOException {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputRead... | 4JAVA | {
"input": [
"10 5 5 5\n",
"3 0 0 2\n",
"10 20 10 5\n",
"20 1 2 3\n",
"7 2 2 2\n",
"25 10 5 10\n",
"999 999 899 299\n",
"10000 5000 0 5000\n",
"2 2 2 2\n",
"1 0 2 0\n",
"3 3 2 1\n",
"1 1 0 0\n",
"1 0 0 1\n",
"20 10 20 30\n",
"505 142 321 12\n",
"101 10 1... | 2CODEFORCES |
494_D. Birthday_123 | Ali is Hamed's little brother and tomorrow is his birthday. Hamed wants his brother to earn his gift so he gave him a hard programming problem and told him if he can successfully solve it, he'll get him a brand new laptop. Ali is not yet a very talented programmer like Hamed and although he usually doesn't cheat but th... | #include <bits/stdc++.h>
using namespace std;
inline int read() {
static int r, sign;
static char c;
r = 0, sign = 1;
do c = getchar();
while (c != '-' && (c < '0' || c > '9'));
if (c == '-') sign = -1, c = getchar();
while (c >= '0' && c <= '9') r = r * 10 + (int)(c - '0'), c = getchar();
return sign *... | 2C++ | {
"input": [
"8\n1 2 100\n1 3 20\n2 4 2\n2 5 1\n3 6 1\n3 7 2\n6 8 5\n6\n1 8\n2 3\n5 8\n2 6\n4 7\n6 1\n",
"5\n1 2 1\n4 3 1\n3 5 1\n1 3 1\n5\n1 1\n1 5\n2 4\n2 1\n3 5\n",
"10\n5 1 33242121\n5 7 535463871\n9 1 202863787\n5 4 874413088\n6 1 623012241\n6 8 786659185\n10 5 164281028\n9 2 851489092\n3 9 169897037... | 2CODEFORCES |
494_D. Birthday_124 | Ali is Hamed's little brother and tomorrow is his birthday. Hamed wants his brother to earn his gift so he gave him a hard programming problem and told him if he can successfully solve it, he'll get him a brand new laptop. Ali is not yet a very talented programmer like Hamed and although he usually doesn't cheat but th... | import java.util.*;
import java.io.*;
/*
5
1 2 1
4 3 1
3 5 1
1 3 1
5
1 1
1 5
2 4
2 1
3 5
*/
public class d
{
public static void main(String[] arg) throws IOException
{
new d();
}
ArrayList<Edge>[] adj;
ArrayList<Pair>[] queries;
int cnt;
int[] pre;
int[] post;
ST st;
int n;
public d() throws IOExcepti... | 4JAVA | {
"input": [
"8\n1 2 100\n1 3 20\n2 4 2\n2 5 1\n3 6 1\n3 7 2\n6 8 5\n6\n1 8\n2 3\n5 8\n2 6\n4 7\n6 1\n",
"5\n1 2 1\n4 3 1\n3 5 1\n1 3 1\n5\n1 1\n1 5\n2 4\n2 1\n3 5\n",
"10\n5 1 33242121\n5 7 535463871\n9 1 202863787\n5 4 874413088\n6 1 623012241\n6 8 786659185\n10 5 164281028\n9 2 851489092\n3 9 169897037... | 2CODEFORCES |
519_B. A and B and Compilation Errors_125 | A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed n compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix s... | n = input()
a = map(int,raw_input().split())
b = map(int,raw_input().split())
c = map(int,raw_input().split())
a.sort()
b.sort()
c.sort()
flag = False
for i in range(0,n - 1) :
if (a[i] != b[i]) :
print a[i]
flag = True
break
if (flag == False) :
print a[n - 1]
flag = False
for i in range(0,n - 2) :
if (b[i] !... | 1Python2 | {
"input": [
"6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n",
"5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n",
"3\n1 2 3\n3 2\n2\n",
"3\n84 30 9\n9 84\n9\n",
"4\n1 5 7 8\n1 5 7\n1 5\n",
"3\n796067435 964699482 819602309\n964699482 796067435\n964699482\n",
"10\n460626451 802090732 277246428 661369649 388684428... | 2CODEFORCES |
519_B. A and B and Compilation Errors_126 | A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed n compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix s... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[3], q;
cin >> n;
for (int i = 0; i < 3; i++) a[i] = 0;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < n - i; j++) {
cin >> q;
a[i] += q;
}
}
cout << a[0] - a[1] << endl;
cout << a[1] - a[2];
return 0;
}
| 2C++ | {
"input": [
"6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n",
"5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n",
"3\n1 2 3\n3 2\n2\n",
"3\n84 30 9\n9 84\n9\n",
"4\n1 5 7 8\n1 5 7\n1 5\n",
"3\n796067435 964699482 819602309\n964699482 796067435\n964699482\n",
"10\n460626451 802090732 277246428 661369649 388684428... | 2CODEFORCES |
519_B. A and B and Compilation Errors_127 | A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed n compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix s... | n = int(input())
a_sum = sum(map(int, input().split()))
b_sum = sum(map(int, input().split()))
c_sum = sum(map(int, input().split()))
print(a_sum - b_sum)
print(b_sum - c_sum) | 3Python3 | {
"input": [
"6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n",
"5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n",
"3\n1 2 3\n3 2\n2\n",
"3\n84 30 9\n9 84\n9\n",
"4\n1 5 7 8\n1 5 7\n1 5\n",
"3\n796067435 964699482 819602309\n964699482 796067435\n964699482\n",
"10\n460626451 802090732 277246428 661369649 388684428... | 2CODEFORCES |
519_B. A and B and Compilation Errors_128 | A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed n compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix s... |
import java.util.Scanner;
/**
*
* @author Marco
*/
public class CompilationErrors {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner in = new Scanner(System.in);
int cantidad = in... | 4JAVA | {
"input": [
"6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n",
"5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n",
"3\n1 2 3\n3 2\n2\n",
"3\n84 30 9\n9 84\n9\n",
"4\n1 5 7 8\n1 5 7\n1 5\n",
"3\n796067435 964699482 819602309\n964699482 796067435\n964699482\n",
"10\n460626451 802090732 277246428 661369649 388684428... | 2CODEFORCES |
545_C. Woodcutters_129 | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each ... | n = int(raw_input())
x = [0 for i in range(n)]
h = [0 for i in range(n)]
for i in range(n):
x[i], h[i] = map(int,raw_input().split(" "))
if n <= 2:
print n
else:
cut = 2
for i in range(1,n-1):
if x[i] - h[i] > x[i-1]:
cut += 1
elif x[i] + h[i] < x[i+1]:
x[i] += h[i]
cut += 1
print cut
| 1Python2 | {
"input": [
"5\n1 2\n2 1\n5 10\n10 9\n20 1\n",
"5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"4\n10 4\n15 1\n19 3\n20 1\n",
"2\n1 999999999\n1000000000 1000000000\n",
"67\n1 1\n3 8\n4 10\n7 8\n9 2\n10 1\n11 5\n12 8\n13 4\n16 6\n18 3\n19 3\n22 5\n24 6\n27 5\n28 3\n29 3\n30 5\n32 5\n33 10\n34 7\n35 8\n36 5\n4... | 2CODEFORCES |
545_C. Woodcutters_130 | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each ... | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int INF = INT_MAX;
const long long int LINF = LLONG_MAX;
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
int n, maxx = -INF, x, h, res = 0;
cin >> n;
pair<int, int> tree[n];
for (int i = 0; i < n; ++i) c... | 2C++ | {
"input": [
"5\n1 2\n2 1\n5 10\n10 9\n20 1\n",
"5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"4\n10 4\n15 1\n19 3\n20 1\n",
"2\n1 999999999\n1000000000 1000000000\n",
"67\n1 1\n3 8\n4 10\n7 8\n9 2\n10 1\n11 5\n12 8\n13 4\n16 6\n18 3\n19 3\n22 5\n24 6\n27 5\n28 3\n29 3\n30 5\n32 5\n33 10\n34 7\n35 8\n36 5\n4... | 2CODEFORCES |
545_C. Woodcutters_131 | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each ... | ll=lambda:map(int,input().split())
t=lambda:int(input())
ss=lambda:input()
#from math import log10 ,log2,ceil,factorial as f,gcd
#from itertools import combinations_with_replacement as cs
#from functools import reduce
#from bisect import bisect_right as br
#from collections import Counter
n=t()
x,h=[],[]
for _ in ran... | 3Python3 | {
"input": [
"5\n1 2\n2 1\n5 10\n10 9\n20 1\n",
"5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"4\n10 4\n15 1\n19 3\n20 1\n",
"2\n1 999999999\n1000000000 1000000000\n",
"67\n1 1\n3 8\n4 10\n7 8\n9 2\n10 1\n11 5\n12 8\n13 4\n16 6\n18 3\n19 3\n22 5\n24 6\n27 5\n28 3\n29 3\n30 5\n32 5\n33 10\n34 7\n35 8\n36 5\n4... | 2CODEFORCES |
545_C. Woodcutters_132 | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each ... | /* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Trees
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
Scanner scan = new... | 4JAVA | {
"input": [
"5\n1 2\n2 1\n5 10\n10 9\n20 1\n",
"5\n1 2\n2 1\n5 10\n10 9\n19 1\n",
"4\n10 4\n15 1\n19 3\n20 1\n",
"2\n1 999999999\n1000000000 1000000000\n",
"67\n1 1\n3 8\n4 10\n7 8\n9 2\n10 1\n11 5\n12 8\n13 4\n16 6\n18 3\n19 3\n22 5\n24 6\n27 5\n28 3\n29 3\n30 5\n32 5\n33 10\n34 7\n35 8\n36 5\n4... | 2CODEFORCES |
571_E. Geometric Progressions_133 | Geometric progression with the first element a and common ratio b is a sequence of numbers a, ab, ab2, ab3, ....
You are given n integer geometric progressions. Your task is to find the smallest integer x, that is the element of all the given progressions, or else state that such integer does not exist.
Input
The fi... |
def primes(n):
size = n/3 + (n%6==2)
plist = size * [True]
plist[0] = False
for i in xrange(int(n**0.5)/3+1):
if plist[i]:
k=3*i+1|1
for j in xrange((k*k)/3,size,2*k):
plist[j] = False
for j in xrange((k*k+4*k-2*k*(i&1))/3,size,2*k):
plist[j] = False
ans = [2,3]
for i in xrange(size):
if pli... | 1Python2 | {
"input": [
"2\n2 2\n3 3\n",
"2\n2 2\n4 1\n",
"25\n1 8\n8 8\n64 8\n512 8\n4096 8\n32768 8\n262144 8\n2097152 8\n16777216 8\n134217728 8\n8 64\n512 64\n32768 64\n2097152 64\n134217728 64\n512 4096\n2097152 4096\n2097152 16777216\n64 512\n32768 512\n16777216 512\n16777216 134217728\n4096 32768\n134217728 3... | 2CODEFORCES |
571_E. Geometric Progressions_134 | Geometric progression with the first element a and common ratio b is a sequence of numbers a, ab, ab2, ab3, ....
You are given n integer geometric progressions. Your task is to find the smallest integer x, that is the element of all the given progressions, or else state that such integer does not exist.
Input
The fi... | #include <bits/stdc++.h>
using std::sort;
using std::swap;
using std::unique;
namespace fastIO {
static char buf[(1 << 19)], *p1 = buf + (1 << 19), *pend = buf + (1 << 19);
inline char nc() {
if (p1 == pend) {
p1 = buf;
pend = buf + fread(buf, 1, (1 << 19), stdin);
}
return *p1++;
}
inline long long read(... | 2C++ | {
"input": [
"2\n2 2\n3 3\n",
"2\n2 2\n4 1\n",
"25\n1 8\n8 8\n64 8\n512 8\n4096 8\n32768 8\n262144 8\n2097152 8\n16777216 8\n134217728 8\n8 64\n512 64\n32768 64\n2097152 64\n134217728 64\n512 4096\n2097152 4096\n2097152 16777216\n64 512\n32768 512\n16777216 512\n16777216 134217728\n4096 32768\n134217728 3... | 2CODEFORCES |
571_E. Geometric Progressions_135 | Geometric progression with the first element a and common ratio b is a sequence of numbers a, ab, ab2, ab3, ....
You are given n integer geometric progressions. Your task is to find the smallest integer x, that is the element of all the given progressions, or else state that such integer does not exist.
Input
The fi... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.io.BufferedReader;
import java.io.InputStream... | 4JAVA | {
"input": [
"2\n2 2\n3 3\n",
"2\n2 2\n4 1\n",
"25\n1 8\n8 8\n64 8\n512 8\n4096 8\n32768 8\n262144 8\n2097152 8\n16777216 8\n134217728 8\n8 64\n512 64\n32768 64\n2097152 64\n134217728 64\n512 4096\n2097152 4096\n2097152 16777216\n64 512\n32768 512\n16777216 512\n16777216 134217728\n4096 32768\n134217728 3... | 2CODEFORCES |
593_C. Beautiful Function_136 | Every day Ruslan tried to count sheep to fall asleep, but this didn't help. Now he has found a more interesting thing to do. First, he thinks of some set of circles on a plane, and then tries to choose a beautiful set of points, such that there is at least one point from the set inside or on the border of each of the i... | import fileinput
def str_sum(a, b):
return '({a}+{b})'.format(a=a, b=b)
def str_dif(a, b):
return '({a}-{b})'.format(a=a, b=b)
def str_mul(a, b):
return '({a}*{b})'.format(a=a, b=b)
def str_abs(a):
return 'abs({a})'.format(a=a)
def get_indicator(i):
"""
Indicator of [i <= t]
"""
abs_1 = str_abs(str_dif(i... | 1Python2 | {
"input": [
"3\n0 10 4\n10 0 4\n20 10 4\n",
"3\n9 5 8\n8 9 10\n9 5 2\n",
"50\n48 45 42\n32 45 8\n15 41 47\n32 29 38\n7 16 48\n19 9 21\n18 40 5\n39 40 7\n37 0 6\n42 15 37\n9 33 37\n40 41 33\n25 43 2\n23 21 38\n30 20 32\n28 15 5\n47 9 19\n47 22 26\n26 9 18\n24 23 24\n11 29 5\n38 44 9\n49 22 42\n1 15 32\n18... | 2CODEFORCES |
593_C. Beautiful Function_137 | Every day Ruslan tried to count sheep to fall asleep, but this didn't help. Now he has found a more interesting thing to do. First, he thinks of some set of circles on a plane, and then tries to choose a beautiful set of points, such that there is at least one point from the set inside or on the border of each of the i... | #include <bits/stdc++.h>
using namespace std;
int N;
vector<int> xs, ys;
string generateFunc(int i, int x) {
char str[1024];
sprintf(str, "(%d*((1-abs((t-%d)))+abs((abs((t-%d))-1))))", x / 2, i, i);
return string(str);
}
string solve(vector<int>& xs) {
string rv;
rv += generateFunc(0, xs[0]);
for (int i = 1... | 2C++ | {
"input": [
"3\n0 10 4\n10 0 4\n20 10 4\n",
"3\n9 5 8\n8 9 10\n9 5 2\n",
"50\n48 45 42\n32 45 8\n15 41 47\n32 29 38\n7 16 48\n19 9 21\n18 40 5\n39 40 7\n37 0 6\n42 15 37\n9 33 37\n40 41 33\n25 43 2\n23 21 38\n30 20 32\n28 15 5\n47 9 19\n47 22 26\n26 9 18\n24 23 24\n11 29 5\n38 44 9\n49 22 42\n1 15 32\n18... | 2CODEFORCES |
593_C. Beautiful Function_138 | Every day Ruslan tried to count sheep to fall asleep, but this didn't help. Now he has found a more interesting thing to do. First, he thinks of some set of circles on a plane, and then tries to choose a beautiful set of points, such that there is at least one point from the set inside or on the border of each of the i... | def f(x):
if x == n:
return "0"
if x == 0:
return "(" + str(X[0]) + "+" + f(1) + ")"
ss = "(abs((t-" + str(x-1) + "))-abs((t-" + str(x) + ")))"
tmp = (X[x] - X[x - 1]) // 2
re = (X[x] - X[x - 1]) - 2 * tmp
X[x] -= re
if t... | 3Python3 | {
"input": [
"3\n0 10 4\n10 0 4\n20 10 4\n",
"3\n9 5 8\n8 9 10\n9 5 2\n",
"50\n48 45 42\n32 45 8\n15 41 47\n32 29 38\n7 16 48\n19 9 21\n18 40 5\n39 40 7\n37 0 6\n42 15 37\n9 33 37\n40 41 33\n25 43 2\n23 21 38\n30 20 32\n28 15 5\n47 9 19\n47 22 26\n26 9 18\n24 23 24\n11 29 5\n38 44 9\n49 22 42\n1 15 32\n18... | 2CODEFORCES |
593_C. Beautiful Function_139 | Every day Ruslan tried to count sheep to fall asleep, but this didn't help. Now he has found a more interesting thing to do. First, he thinks of some set of circles on a plane, and then tries to choose a beautiful set of points, such that there is at least one point from the set inside or on the border of each of the i... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
Input... | 4JAVA | {
"input": [
"3\n0 10 4\n10 0 4\n20 10 4\n",
"3\n9 5 8\n8 9 10\n9 5 2\n",
"50\n48 45 42\n32 45 8\n15 41 47\n32 29 38\n7 16 48\n19 9 21\n18 40 5\n39 40 7\n37 0 6\n42 15 37\n9 33 37\n40 41 33\n25 43 2\n23 21 38\n30 20 32\n28 15 5\n47 9 19\n47 22 26\n26 9 18\n24 23 24\n11 29 5\n38 44 9\n49 22 42\n1 15 32\n18... | 2CODEFORCES |
615_A. Bulbs_140 | Vasya wants to turn on Christmas lights consisting of m bulbs. Initially, all bulbs are turned off. There are n buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
If Va... | n, m = map(int, raw_input().split())
lines = [map(int, raw_input().split())[1:] for i in xrange(n)]
ans = set()
for i in lines:
ans = ans.union(set(i))
print "YES" if len(ans)==m else "NO"
| 1Python2 | {
"input": [
"3 4\n2 1 4\n3 1 3 1\n1 2\n",
"3 3\n1 1\n1 2\n1 1\n",
"3 4\n1 1\n1 2\n1 3\n",
"1 100\n99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70... | 2CODEFORCES |
615_A. Bulbs_141 | Vasya wants to turn on Christmas lights consisting of m bulbs. Initially, all bulbs are turned off. There are n buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
If Va... | #include <bits/stdc++.h>
using namespace std;
void solve() {
int n, k;
cin >> n >> k;
vector<int> mas(k, 0);
for (int i = 0; i < n; i++) {
int m;
cin >> m;
for (int i = 0; i < m; i++) {
int x;
cin >> x;
mas[x - 1]++;
}
}
for (int i = 0; i < k; i++) {
if (mas[i] == 0) {
... | 2C++ | {
"input": [
"3 4\n2 1 4\n3 1 3 1\n1 2\n",
"3 3\n1 1\n1 2\n1 1\n",
"3 4\n1 1\n1 2\n1 3\n",
"1 100\n99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70... | 2CODEFORCES |
615_A. Bulbs_142 | Vasya wants to turn on Christmas lights consisting of m bulbs. Initially, all bulbs are turned off. There are n buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
If Va... | import math
nm = input().split()
n = int(nm[0])
m = int(nm[1])
lis = [ 0 for i in range(m+1)]
for _ in range(n) :
inp = list(map(int, input().split()))
inp.pop(0)
for i in inp:
lis[i]=1
prev = i
if sum(lis)==m:
print("YES")
else:
print("NO") | 3Python3 | {
"input": [
"3 4\n2 1 4\n3 1 3 1\n1 2\n",
"3 3\n1 1\n1 2\n1 1\n",
"3 4\n1 1\n1 2\n1 3\n",
"1 100\n99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70... | 2CODEFORCES |
615_A. Bulbs_143 | Vasya wants to turn on Christmas lights consisting of m bulbs. Initially, all bulbs are turned off. There are n buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
If Va... | import java.util.*;
public class Za {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
String x = " ";
for (int i = 1; i <= m; i++)
x += i + " ";
for (int j = 1; j <= n; j++) {
int k = sc.nextInt();
for (int l = 0; l < k; l++... | 4JAVA | {
"input": [
"3 4\n2 1 4\n3 1 3 1\n1 2\n",
"3 3\n1 1\n1 2\n1 1\n",
"3 4\n1 1\n1 2\n1 3\n",
"1 100\n99 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70... | 2CODEFORCES |
634_C. Factory Repairs_144 | A factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce b thimbles each day. The factory intends to choose a k-day period to do maintenance and construction; it cannot produce any thimbles during this time, but ... | #include <bits/stdc++.h>
using namespace std;
long long tree[1000000][2];
long long ar[1000000];
int a, b;
long long query(int x, int l, int r, int s, int e, bool k) {
if (l > e || r < s || s > e) return 0;
if (l >= s && r <= e)
return tree[x][k];
else {
return query(x * 2, l, (l + r) / 2, s, e, k) +
... | 2C++ | {
"input": [
"5 4 10 1 6\n1 1 5\n1 5 5\n1 3 2\n1 5 2\n2 1\n2 2\n",
"5 2 2 1 8\n1 1 2\n1 5 3\n1 2 1\n2 2\n1 4 2\n1 3 2\n2 1\n2 3\n",
"1 1 2 1 1\n2 1\n",
"1 1 2 2 1\n2 1\n",
"5 2 2 1 8\n1 1 2\n1 5 3\n1 2 1\n2 2\n1 4 2\n1 3 0\n2 1\n2 3\n",
"5 2 2 2 8\n1 1 2\n1 5 3\n1 2 1\n2 2\n1 4 2\n1 3 2\n2 1\n... | 2CODEFORCES |
634_C. Factory Repairs_145 | A factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce b thimbles each day. The factory intends to choose a k-day period to do maintenance and construction; it cannot produce any thimbles during this time, but ... | from functools import reduce
class SegmentTree():
def __init__(self, L, function = lambda x,y: x+y, initilizer = None):
self.function = function
self.initilizer = initilizer
N = self.size = len(L)
M = 1 << N.bit_length()
self.margin = 2*M - N
self.L = [None for i in r... | 3Python3 | {
"input": [
"5 4 10 1 6\n1 1 5\n1 5 5\n1 3 2\n1 5 2\n2 1\n2 2\n",
"5 2 2 1 8\n1 1 2\n1 5 3\n1 2 1\n2 2\n1 4 2\n1 3 2\n2 1\n2 3\n",
"1 1 2 1 1\n2 1\n",
"1 1 2 2 1\n2 1\n",
"5 2 2 1 8\n1 1 2\n1 5 3\n1 2 1\n2 2\n1 4 2\n1 3 0\n2 1\n2 3\n",
"5 2 2 2 8\n1 1 2\n1 5 3\n1 2 1\n2 2\n1 4 2\n1 3 2\n2 1\n... | 2CODEFORCES |
634_C. Factory Repairs_146 | A factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce b thimbles each day. The factory intends to choose a k-day period to do maintenance and construction; it cannot produce any thimbles during this time, but ... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual soluti... | 4JAVA | {
"input": [
"5 4 10 1 6\n1 1 5\n1 5 5\n1 3 2\n1 5 2\n2 1\n2 2\n",
"5 2 2 1 8\n1 1 2\n1 5 3\n1 2 1\n2 2\n1 4 2\n1 3 2\n2 1\n2 3\n",
"1 1 2 1 1\n2 1\n",
"1 1 2 2 1\n2 1\n",
"5 2 2 1 8\n1 1 2\n1 5 3\n1 2 1\n2 2\n1 4 2\n1 3 0\n2 1\n2 3\n",
"5 2 2 2 8\n1 1 2\n1 5 3\n1 2 1\n2 2\n1 4 2\n1 3 2\n2 1\n... | 2CODEFORCES |
663_A. Rebus_147 | You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer n. The goal is to replace each question mark with some positive integer from 1 to n, such that equality holds.
Input
The only line of the input contains a re... | class Number:
def __init__(sign, number=None):
self.__sign = sign
self.__number = number
def solve_rebus(left_part, right_part):
added = left_part.count("+") + 1
subtracted = left_part.count("-")
max_number = added * right_part - subtracted
min_number = added - subtracted * right_... | 1Python2 | {
"input": [
"? - ? = 1\n",
"? + ? - ? + ? + ? = 42\n",
"? = 1000000\n",
"? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ... | 2CODEFORCES |
663_A. Rebus_148 | You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer n. The goal is to replace each question mark with some positive integer from 1 to n, such that equality holds.
Input
The only line of the input contains a re... | #include <bits/stdc++.h>
using namespace std;
string s[505];
vector<int> P, N;
int main() {
int id = 0, pos = 0, neg = 0;
while (cin >> s[id]) {
if (s[id] == "=") break;
if (s[id] == "?") {
if (id == 0 || s[id - 1] == "+")
pos++;
else
neg++;
}
id++;
cin >> s[id];
... | 2C++ | {
"input": [
"? - ? = 1\n",
"? + ? - ? + ? + ? = 42\n",
"? = 1000000\n",
"? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ... | 2CODEFORCES |
663_A. Rebus_149 | You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer n. The goal is to replace each question mark with some positive integer from 1 to n, such that equality holds.
Input
The only line of the input contains a re... | s = input().split()
plus = 1
minus = 0
for ch in s:
if (ch == '+') :
plus += 1
if (ch == '-') :
minus += 1
n = int(s[len(s) - 1])
maxx = plus * n - 1 * minus
minn = plus - n * minus
now = n - (plus - minus)
if (n>maxx or n<minn):
print("Impossible")
else:
pre = '+'
print("Possible")
for ch in s:
... | 3Python3 | {
"input": [
"? - ? = 1\n",
"? + ? - ? + ? + ? = 42\n",
"? = 1000000\n",
"? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ... | 2CODEFORCES |
663_A. Rebus_150 | You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer n. The goal is to replace each question mark with some positive integer from 1 to n, such that equality holds.
Input
The only line of the input contains a re... | import java.io.*;
import java.util.*;
import java.util.Map.Entry;
public class Task_Rnd664_B {
final static String input_file_name = "input/Rnd664_B.txt";
public static void main(String[] args)
{
//!!!!!!!!!!111
reader.init(true); //to server
//reader.init(false);
run();
wr.flush();
}
public... | 4JAVA | {
"input": [
"? - ? = 1\n",
"? + ? - ? + ? + ? = 42\n",
"? = 1000000\n",
"? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ... | 2CODEFORCES |
687_D. Dividing Kingdom II_151 | Long time ago, there was a great kingdom and it was being ruled by The Great Arya and Pari The Great. These two had some problems about the numbers they like, so they decided to divide the great kingdom between themselves.
The great kingdom consisted of n cities numbered from 1 to n and m bidirectional roads between t... | #include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 1000, M = N * (N - 1) / 2;
int dsu[N * 2];
int find(int i) { return dsu[i] < 0 ? i : (dsu[i] = find(dsu[i])); }
bool join(int i, int j) {
i = find(i);
j = find(j);
if (i == j) return false;
if (dsu[i] > dsu[j])
dsu[i] = j... | 2C++ | {
"input": [
"5 6 5\n5 4 86\n5 1 0\n1 3 38\n2 1 33\n2 4 28\n2 3 40\n3 5\n2 6\n1 3\n2 3\n1 6\n",
"5 9 4\n4 1 46\n1 3 29\n3 2 58\n1 5 61\n2 4 88\n1 2 87\n4 5 58\n3 5 69\n3 4 28\n2 7\n5 7\n3 6\n1 7\n",
"5 8 10\n2 3 8\n5 3 22\n5 1 8\n3 4 7\n4 1 83\n5 2 59\n2 1 4\n4 2 53\n4 4\n3 3\n5 6\n3 5\n3 8\n3 5\n1 4\n3 4... | 2CODEFORCES |
687_D. Dividing Kingdom II_152 | Long time ago, there was a great kingdom and it was being ruled by The Great Arya and Pari The Great. These two had some problems about the numbers they like, so they decided to divide the great kingdom between themselves.
The great kingdom consisted of n cities numbered from 1 to n and m bidirectional roads between t... | import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.*;
public class Template implements Runnable {
BufferedReader in;
PrintWriter out;
StringTokenizer tok = new StringTokenizer("");
void init() throw... | 4JAVA | {
"input": [
"5 6 5\n5 4 86\n5 1 0\n1 3 38\n2 1 33\n2 4 28\n2 3 40\n3 5\n2 6\n1 3\n2 3\n1 6\n",
"5 9 4\n4 1 46\n1 3 29\n3 2 58\n1 5 61\n2 4 88\n1 2 87\n4 5 58\n3 5 69\n3 4 28\n2 7\n5 7\n3 6\n1 7\n",
"5 8 10\n2 3 8\n5 3 22\n5 1 8\n3 4 7\n4 1 83\n5 2 59\n2 1 4\n4 2 53\n4 4\n3 3\n5 6\n3 5\n3 8\n3 5\n1 4\n3 4... | 2CODEFORCES |
70_C. Lucky Tickets_153 | In Walrusland public transport tickets are characterized by two integers: by the number of the series and by the number of the ticket in the series. Let the series number be represented by a and the ticket number — by b, then a ticket is described by the ordered pair of numbers (a, b).
The walruses believe that a tic... | from collections import defaultdict
from fractions import gcd
(max_x, max_y, w) = map( int, raw_input().split() )
def Pair(x):
inv_x = 0
val = x
while val:
inv_x = inv_x * 10 + val % 10
val /= 10
uc = gcd( x, inv_x )
return ( x/uc, inv_x/uc )
def Reverse(P):
return ( P[1], P[0... | 1Python2 | {
"input": [
"5 18 1000\n",
"132 10 35\n",
"48 132 235\n",
"2 2 1\n",
"85 30 123\n",
"100000 100000 1320777\n",
"94728 36278 300352\n",
"70386 4182 113682\n",
"65182 12701 141871\n",
"48701 4854 14523\n",
"84324 74849 17238\n",
"100000 100000 10000000\n",
"83072 558... | 2CODEFORCES |
70_C. Lucky Tickets_154 | In Walrusland public transport tickets are characterized by two integers: by the number of the series and by the number of the ticket in the series. Let the series number be represented by a and the ticket number — by b, then a ticket is described by the ordered pair of numbers (a, b).
The walruses believe that a tic... | #include <bits/stdc++.h>
using namespace std;
int in() {
int a;
scanf("%d", &a);
return a;
}
int gcm(int a, int b) {
if (b > a) return gcm(b, a);
if (a % b == 0)
return b;
else
return gcm(b, a % b);
}
int calc_rev(int x) {
int ret = 0;
while (x) {
int a = x % 10;
ret = ret * 10 + a;
... | 2C++ | {
"input": [
"5 18 1000\n",
"132 10 35\n",
"48 132 235\n",
"2 2 1\n",
"85 30 123\n",
"100000 100000 1320777\n",
"94728 36278 300352\n",
"70386 4182 113682\n",
"65182 12701 141871\n",
"48701 4854 14523\n",
"84324 74849 17238\n",
"100000 100000 10000000\n",
"83072 558... | 2CODEFORCES |
70_C. Lucky Tickets_155 | In Walrusland public transport tickets are characterized by two integers: by the number of the series and by the number of the ticket in the series. Let the series number be represented by a and the ticket number — by b, then a ticket is described by the ordered pair of numbers (a, b).
The walruses believe that a tic... |
import java.util.HashMap;
import java.util.Scanner;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author duc
*/
public class CF70_C {
static int reverseNumber(int n) {
int m = 0;
while (n > 0) {
m = m * 10 + n%10;
... | 4JAVA | {
"input": [
"5 18 1000\n",
"132 10 35\n",
"48 132 235\n",
"2 2 1\n",
"85 30 123\n",
"100000 100000 1320777\n",
"94728 36278 300352\n",
"70386 4182 113682\n",
"65182 12701 141871\n",
"48701 4854 14523\n",
"84324 74849 17238\n",
"100000 100000 10000000\n",
"83072 558... | 2CODEFORCES |
730_J. Bottles_156 | Nick has n bottles of soda left after his birthday. Each bottle is described by two values: remaining amount of soda ai and bottle volume bi (ai ≤ bi).
Nick has decided to pour all remaining soda into minimal number of bottles, moreover he has to do it as soon as possible. Nick spends x seconds to pour x units of soda... | #include <bits/stdc++.h>
using namespace std;
pair<int, int> dp[10005];
int a[105], b[105];
int main() {
int n;
scanf("%d", &n);
int cap = 0, mx = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
cap += a[i];
}
for (int i = 0; i < n; i++) {
scanf("%d", &b[i]);
mx += b[i];
}
for (int ... | 2C++ | {
"input": [
"2\n1 1\n100 100\n",
"5\n10 30 5 6 24\n10 41 7 8 24\n",
"4\n3 3 4 3\n4 7 6 5\n",
"30\n10 1 8 10 2 6 45 7 3 7 1 3 1 1 14 2 5 19 4 1 13 3 5 6 1 5 1 1 23 1\n98 4 43 41 56 58 85 51 47 55 20 85 93 12 49 15 95 72 20 4 68 24 16 97 21 52 18 69 89 15\n",
"20\n8 1 44 1 12 1 9 11 1 1 5 2 9 16 16... | 2CODEFORCES |
730_J. Bottles_157 | Nick has n bottles of soda left after his birthday. Each bottle is described by two values: remaining amount of soda ai and bottle volume bi (ai ≤ bi).
Nick has decided to pour all remaining soda into minimal number of bottles, moreover he has to do it as soon as possible. Nick spends x seconds to pour x units of soda... | f = lambda: list(map(int, input().split()))
n = int(input())
a, b = f(), f()
d = [[None] * 10001 for i in range(n)]
def g(i, s):
if s <= 0: return (0, s)
if i == n: return (1e7, 0)
if not d[i][s]:
x, y = g(i + 1, s - b[i])
d[i][s] = min(g(i + 1, s), (x + 1, y + b[i] - a[i]))
return d[... | 3Python3 | {
"input": [
"2\n1 1\n100 100\n",
"5\n10 30 5 6 24\n10 41 7 8 24\n",
"4\n3 3 4 3\n4 7 6 5\n",
"30\n10 1 8 10 2 6 45 7 3 7 1 3 1 1 14 2 5 19 4 1 13 3 5 6 1 5 1 1 23 1\n98 4 43 41 56 58 85 51 47 55 20 85 93 12 49 15 95 72 20 4 68 24 16 97 21 52 18 69 89 15\n",
"20\n8 1 44 1 12 1 9 11 1 1 5 2 9 16 16... | 2CODEFORCES |
730_J. Bottles_158 | Nick has n bottles of soda left after his birthday. Each bottle is described by two values: remaining amount of soda ai and bottle volume bi (ai ≤ bi).
Nick has decided to pour all remaining soda into minimal number of bottles, moreover he has to do it as soon as possible. Nick spends x seconds to pour x units of soda... |
import java.io.*;
import java.util.*;
public class G {
static class Pair<U extends Comparable<U>, V extends Comparable<V>>
implements Comparable<Pair<U,V>>{
final public U a;
final public V b;
private Pair(U a, V b) {
this.a = a;
this.b = b;
... | 4JAVA | {
"input": [
"2\n1 1\n100 100\n",
"5\n10 30 5 6 24\n10 41 7 8 24\n",
"4\n3 3 4 3\n4 7 6 5\n",
"30\n10 1 8 10 2 6 45 7 3 7 1 3 1 1 14 2 5 19 4 1 13 3 5 6 1 5 1 1 23 1\n98 4 43 41 56 58 85 51 47 55 20 85 93 12 49 15 95 72 20 4 68 24 16 97 21 52 18 69 89 15\n",
"20\n8 1 44 1 12 1 9 11 1 1 5 2 9 16 16... | 2CODEFORCES |
754_E. Dasha and cyclic table_159 | Dasha is fond of challenging puzzles: Rubik's Cube 3 × 3 × 3, 4 × 4 × 4, 5 × 5 × 5 and so on. This time she has a cyclic table of size n × m, and each cell of the table contains a lowercase English letter. Each cell has coordinates (i, j) (0 ≤ i < n, 0 ≤ j < m). The table is cyclic means that to the right of cell (i, j... | #include <bits/stdc++.h>
using namespace std;
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
template <typename T, typename U>
static void amin(T &x, U y) {
if (y < x) x = y;
}
template <typename T, typename U>
static void amax(T &x, U y) {
if (x < y) x = y;
}
struct FFTCoeff... | 2C++ | {
"input": [
"5 7\nqcezchs\nhhedywq\nwikywqy\nqckrqzt\nbqexcxz\n3 2\n??\nyw\n?q\n",
"8 6\nibrgxl\nxqdcsg\nokbcgi\ntvpetc\nxgxxig\nigghzo\nlmlaza\ngpswzv\n1 4\ngx??\n",
"10 10\nfwtoayylhw\nyyaryyjawr\nywrdzwhscy\nhnsyyxiphn\nbnjwzyyjvo\nkkjgseenwn\ngvmiflpcsy\nlxvkwrobwu\nwyybbcocyy\nyysijsvqry\n2 2\n??\ny... | 2CODEFORCES |
754_E. Dasha and cyclic table_160 | Dasha is fond of challenging puzzles: Rubik's Cube 3 × 3 × 3, 4 × 4 × 4, 5 × 5 × 5 and so on. This time she has a cyclic table of size n × m, and each cell of the table contains a lowercase English letter. Each cell has coordinates (i, j) (0 ≤ i < n, 0 ≤ j < m). The table is cyclic means that to the right of cell (i, j... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at ... | 4JAVA | {
"input": [
"5 7\nqcezchs\nhhedywq\nwikywqy\nqckrqzt\nbqexcxz\n3 2\n??\nyw\n?q\n",
"8 6\nibrgxl\nxqdcsg\nokbcgi\ntvpetc\nxgxxig\nigghzo\nlmlaza\ngpswzv\n1 4\ngx??\n",
"10 10\nfwtoayylhw\nyyaryyjawr\nywrdzwhscy\nhnsyyxiphn\nbnjwzyyjvo\nkkjgseenwn\ngvmiflpcsy\nlxvkwrobwu\nwyybbcocyy\nyysijsvqry\n2 2\n??\ny... | 2CODEFORCES |
776_A. A Serial Killer_161 | Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two potential victims on his first day, selects one of these two, kills selected ... | #!/usr/bin/python
# coding: utf-8
(pv1,pv2)=raw_input().split(' ')
n=int(raw_input())
print pv1, pv2
for i in xrange(n):
(murdered,replaced)=raw_input().split(' ')
if(pv1==murdered):
pv1=replaced
elif(pv2==murdered):
pv2=replaced
print pv1, pv2
'''
Our beloved detective, Sherlock is ... | 1Python2 | {
"input": [
"icm codeforces\n1\ncodeforces technex\n",
"ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n",
"wwwww w\n8\nwwwww wwwwwwww\nwwwwwwww wwwwwwwww\nwwwwwwwww wwwwwwwwww\nw www\nwwwwwwwwww wwww\nwwww ww\nwww wwwwww\nwwwwww wwwwwww\n",
"k d\n17\nk l\nd v\nv z\nl r\nz i... | 2CODEFORCES |
776_A. A Serial Killer_162 | Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two potential victims on his first day, selects one of these two, kills selected ... | #include <bits/stdc++.h>
using namespace std;
int main() {
string s1, s2;
cin >> s1 >> s2;
int n;
cin >> n;
for (size_t i = 0; i < n; i++) {
i == n ? cout << s1 << " " << s2 : cout << s1 << " " << s2 << endl;
string f, s;
cin >> f >> s;
if (f == s1) {
s1 = s;
} else {
s2 = s;
... | 2C++ | {
"input": [
"icm codeforces\n1\ncodeforces technex\n",
"ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n",
"wwwww w\n8\nwwwww wwwwwwww\nwwwwwwww wwwwwwwww\nwwwwwwwww wwwwwwwwww\nw www\nwwwwwwwwww wwww\nwwww ww\nwww wwwwww\nwwwwww wwwwwww\n",
"k d\n17\nk l\nd v\nv z\nl r\nz i... | 2CODEFORCES |
776_A. A Serial Killer_163 | Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two potential victims on his first day, selects one of these two, kills selected ... | def main():
l = input().split()
print(*l)
for _ in range(int(input())):
a, b = input().split()
l[a == l[1]] = b
print(*l)
if __name__ == '__main__':
main()
| 3Python3 | {
"input": [
"icm codeforces\n1\ncodeforces technex\n",
"ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n",
"wwwww w\n8\nwwwww wwwwwwww\nwwwwwwww wwwwwwwww\nwwwwwwwww wwwwwwwwww\nw www\nwwwwwwwwww wwww\nwwww ww\nwww wwwwww\nwwwwww wwwwwww\n",
"k d\n17\nk l\nd v\nv z\nl r\nz i... | 2CODEFORCES |
776_A. A Serial Killer_164 | Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two potential victims on his first day, selects one of these two, kills selected ... | import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.lang.*;
public class A {
static long mod = 1000000007;
public static void main(String[] args) throws Exception {
InputReader in = new InputReader(System.in);
PrintWriter pw = new PrintWriter(Syste... | 4JAVA | {
"input": [
"icm codeforces\n1\ncodeforces technex\n",
"ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n",
"wwwww w\n8\nwwwww wwwwwwww\nwwwwwwww wwwwwwwww\nwwwwwwwww wwwwwwwwww\nw www\nwwwwwwwwww wwww\nwwww ww\nwww wwwwww\nwwwwww wwwwwww\n",
"k d\n17\nk l\nd v\nv z\nl r\nz i... | 2CODEFORCES |
7_B. Memory Manager_165 | There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According to the developers' plan, in the first release the memory manager will be very simple and rectilinear. It will support three operations:
... | I=raw_input
t,m=map(int,I().split())
a=[0]*m
k=1
for _ in '0'*t:
p=I();b=int((p+' 0').split()[1]);s=''
if p[0]=='d':a=filter(lambda x:x!=0,a);a+=[0]*(m-len(a))
elif p[0]=='a':
s='NULL'
for i in range(b,m+1):
if sum(a[i-b:i])==0:a=a[:i-b]+[k]*b+a[i:];s=str(k);k+=1;break
else:s... | 1Python2 | {
"input": [
"6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6\n",
"3 1\nerase -1\nerase 0\nerase -2147483648\n",
"26 25\ndefragment\nerase 1\nerase -1560200883\nalloc 44\ndefragment\nalloc 75\nalloc 22\ndefragment\nerase 4\ndefragment\nalloc 57\nalloc 53\nerase 4\nerase -1639632026\nerase -2... | 2CODEFORCES |
7_B. Memory Manager_166 | There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According to the developers' plan, in the first release the memory manager will be very simple and rectilinear. It will support three operations:
... | #include <bits/stdc++.h>
using namespace std;
int main() {
int t, m, num = 1;
string com;
int arg;
vector<pair<pair<int, int>, int> > d;
cin >> t >> m;
for (int _n((t)-1), q(0); q <= _n; q++) {
sort((d).begin(), (d).end());
cin >> com;
if (com == "defragment") {
if (d.size() > 0) {
... | 2C++ | {
"input": [
"6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6\n",
"3 1\nerase -1\nerase 0\nerase -2147483648\n",
"26 25\ndefragment\nerase 1\nerase -1560200883\nalloc 44\ndefragment\nalloc 75\nalloc 22\ndefragment\nerase 4\ndefragment\nalloc 57\nalloc 53\nerase 4\nerase -1639632026\nerase -2... | 2CODEFORCES |
7_B. Memory Manager_167 | There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According to the developers' plan, in the first release the memory manager will be very simple and rectilinear. It will support three operations:
... | t, m = map(int, input().split())
disk = [False] * m
req = 0
for i in range(t):
inp = input().split()
if inp[0][0] == "a":
c = 0
inp[1] = int(inp[1])
for j in range(m):
if disk[j]:
c = 0
else:
c += 1
if c == inp[1]:
... | 3Python3 | {
"input": [
"6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6\n",
"3 1\nerase -1\nerase 0\nerase -2147483648\n",
"26 25\ndefragment\nerase 1\nerase -1560200883\nalloc 44\ndefragment\nalloc 75\nalloc 22\ndefragment\nerase 4\ndefragment\nalloc 57\nalloc 53\nerase 4\nerase -1639632026\nerase -2... | 2CODEFORCES |
7_B. Memory Manager_168 | There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet — the memory manager is among them. According to the developers' plan, in the first release the memory manager will be very simple and rectilinear. It will support three operations:
... |
/**
* Date: 21 Apr, 2018
* Link:
*
* @author Prasad-Chaudhari
* @email prasadc8897@gmail.com
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class newProgram {
public static void main(String[] args) throws IOException {
// TODO code application... | 4JAVA | {
"input": [
"6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6\n",
"3 1\nerase -1\nerase 0\nerase -2147483648\n",
"26 25\ndefragment\nerase 1\nerase -1560200883\nalloc 44\ndefragment\nalloc 75\nalloc 22\ndefragment\nerase 4\ndefragment\nalloc 57\nalloc 53\nerase 4\nerase -1639632026\nerase -2... | 2CODEFORCES |
820_D. Mister B and PR Shifts_169 | Some time ago Mister B detected a strange signal from the space, which he started to study.
After some transformation the signal turned out to be a permutation p of length n or its cyclic shift. For the further investigation Mister B need some basis, that's why he decided to choose cyclic shift of this permutation whi... | #include <bits/stdc++.h>
using namespace std;
void gi(int& x) {
static char r[(1 << 17) + 16], *s = r, *l = r + (1 << 17);
x = 0;
if (!*s) memset(r, 0, (1 << 17)), cin.read(r, (1 << 17)), s = r;
while (*s && (*s < 48 || *s > 57)) ++s;
while (*s >= 48 && *s <= 57) {
x = x * 10 + *s - 48, ++s;
if (s == ... | 2C++ | {
"input": [
"3\n3 2 1\n",
"3\n1 2 3\n",
"3\n2 3 1\n",
"4\n1 2 4 3\n",
"4\n2 1 4 3\n",
"10\n1 2 10 9 7 4 8 3 6 5\n",
"10\n1 7 10 6 5 2 3 8 9 4\n",
"4\n4 3 2 1\n",
"4\n2 1 3 4\n",
"10\n1 10 9 5 3 2 4 7 8 6\n",
"4\n2 3 1 4\n",
"4\n2 4 3 1\n",
"10\n1 5 10 8 4 3 9 2 7 6... | 2CODEFORCES |
820_D. Mister B and PR Shifts_170 | Some time ago Mister B detected a strange signal from the space, which he started to study.
After some transformation the signal turned out to be a permutation p of length n or its cyclic shift. For the further investigation Mister B need some basis, that's why he decided to choose cyclic shift of this permutation whi... | from sys import stdin
def main():
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
inf = [0] * (n + 1)
curr = 0
d = 0
for i in range(n):
curr += abs(i + 1 - a[i])
if a[i] > i + 1:
d += 1
inf[a[i] - i - 1] += 1
elif a[i] <= i +... | 3Python3 | {
"input": [
"3\n3 2 1\n",
"3\n1 2 3\n",
"3\n2 3 1\n",
"4\n1 2 4 3\n",
"4\n2 1 4 3\n",
"10\n1 2 10 9 7 4 8 3 6 5\n",
"10\n1 7 10 6 5 2 3 8 9 4\n",
"4\n4 3 2 1\n",
"4\n2 1 3 4\n",
"10\n1 10 9 5 3 2 4 7 8 6\n",
"4\n2 3 1 4\n",
"4\n2 4 3 1\n",
"10\n1 5 10 8 4 3 9 2 7 6... | 2CODEFORCES |
820_D. Mister B and PR Shifts_171 | Some time ago Mister B detected a strange signal from the space, which he started to study.
After some transformation the signal turned out to be a permutation p of length n or its cyclic shift. For the further investigation Mister B need some basis, that's why he decided to choose cyclic shift of this permutation whi... | import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
public class D421 {
InputStream is;
PrintWriter out;
int n;
long a[];
private boolean oj = System.getProperty("ONLINE_JUDGE") != nu... | 4JAVA | {
"input": [
"3\n3 2 1\n",
"3\n1 2 3\n",
"3\n2 3 1\n",
"4\n1 2 4 3\n",
"4\n2 1 4 3\n",
"10\n1 2 10 9 7 4 8 3 6 5\n",
"10\n1 7 10 6 5 2 3 8 9 4\n",
"4\n4 3 2 1\n",
"4\n2 1 3 4\n",
"10\n1 10 9 5 3 2 4 7 8 6\n",
"4\n2 3 1 4\n",
"4\n2 4 3 1\n",
"10\n1 5 10 8 4 3 9 2 7 6... | 2CODEFORCES |
846_E. Chemistry in Berland_172 | Igor is a post-graduate student of chemistry faculty in Berland State University (BerSU). He needs to conduct a complicated experiment to write his thesis, but laboratory of BerSU doesn't contain all the materials required for this experiment.
Fortunately, chemical laws allow material transformations (yes, chemistry i... | n = int(raw_input());
B = [0] + map(int,raw_input().split())
A = [0] + map(int,raw_input().split())
G = [[] for i in xrange(n+1)];
for i in xrange(2,n+1):
p,k = map(int,raw_input().split());
G[p].append([i,k]);
supply = [0 for i in xrange(n+1)];
for u in xrange(n,0,-1):
supply[u] = B[u] - A[u];
for v,... | 1Python2 | {
"input": [
"3\n3 2 1\n1 2 3\n1 1\n1 2\n",
"3\n1 2 3\n3 2 1\n1 1\n1 1\n",
"5\n27468 7465 74275 40573 40155\n112071 76270 244461 264202 132397\n1 777133331\n2 107454154\n3 652330694\n4 792720519\n",
"5\n78188 56310 79021 70050 65217\n115040 5149 128449 98357 36580\n1 451393770\n2 574046602\n3 59013078... | 2CODEFORCES |
846_E. Chemistry in Berland_173 | Igor is a post-graduate student of chemistry faculty in Berland State University (BerSU). He needs to conduct a complicated experiment to write his thesis, but laboratory of BerSU doesn't contain all the materials required for this experiment.
Fortunately, chemical laws allow material transformations (yes, chemistry i... | #include <bits/stdc++.h>
const double Pi = acos(-1.0);
using namespace std;
const int maxN = 100005;
const long long inf = (long long)1e15;
int n;
long long b[maxN];
long long k[maxN];
long long req[maxN];
vector<int> G[maxN];
void dfs(int cur) {
for (int i = 0; i < (int)G[cur].size(); i++) {
int nxt = G[cur][i];... | 2C++ | {
"input": [
"3\n3 2 1\n1 2 3\n1 1\n1 2\n",
"3\n1 2 3\n3 2 1\n1 1\n1 1\n",
"5\n27468 7465 74275 40573 40155\n112071 76270 244461 264202 132397\n1 777133331\n2 107454154\n3 652330694\n4 792720519\n",
"5\n78188 56310 79021 70050 65217\n115040 5149 128449 98357 36580\n1 451393770\n2 574046602\n3 59013078... | 2CODEFORCES |
846_E. Chemistry in Berland_174 | Igor is a post-graduate student of chemistry faculty in Berland State University (BerSU). He needs to conduct a complicated experiment to write his thesis, but laboratory of BerSU doesn't contain all the materials required for this experiment.
Fortunately, chemical laws allow material transformations (yes, chemistry i... | import sys
# @profile
def main():
f = sys.stdin
# f = open('input.txt', 'r')
# fo = open('log.txt', 'w')
n = int(f.readline())
# b = []
# for i in range(n):
# b.append()
b = list(map(int, f.readline().strip().split(' ')))
a = list(map(int, f.readline().strip().split(' ')))
# ... | 3Python3 | {
"input": [
"3\n3 2 1\n1 2 3\n1 1\n1 2\n",
"3\n1 2 3\n3 2 1\n1 1\n1 1\n",
"5\n27468 7465 74275 40573 40155\n112071 76270 244461 264202 132397\n1 777133331\n2 107454154\n3 652330694\n4 792720519\n",
"5\n78188 56310 79021 70050 65217\n115040 5149 128449 98357 36580\n1 451393770\n2 574046602\n3 59013078... | 2CODEFORCES |
846_E. Chemistry in Berland_175 | Igor is a post-graduate student of chemistry faculty in Berland State University (BerSU). He needs to conduct a complicated experiment to write his thesis, but laboratory of BerSU doesn't contain all the materials required for this experiment.
Fortunately, chemical laws allow material transformations (yes, chemistry i... | import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.stream.IntStream;
public class Solution {
static MyScanner sc;
private static PrintWriter out;
public static void main(String[] s) throws Exception {
StringBuilder stringBuilder = new StringBuilder();
//
// ... | 4JAVA | {
"input": [
"3\n3 2 1\n1 2 3\n1 1\n1 2\n",
"3\n1 2 3\n3 2 1\n1 1\n1 1\n",
"5\n27468 7465 74275 40573 40155\n112071 76270 244461 264202 132397\n1 777133331\n2 107454154\n3 652330694\n4 792720519\n",
"5\n78188 56310 79021 70050 65217\n115040 5149 128449 98357 36580\n1 451393770\n2 574046602\n3 59013078... | 2CODEFORCES |
868_A. Bark to Unlock_176 | As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters.
Mu-mu's enemy Kashtanka wants to unlock Mu-mu's p... | from sys import stdin
def main():
password=raw_input()
n=input()
flag1=False
flag2=False
for i in xrange(n):
str=raw_input()
if str[0]==password[1]:
flag1=True
if str[1]==password[0]:
flag2=True
if flag1 and flag2 or str==password:
... | 1Python2 | {
"input": [
"ah\n1\nha\n",
"ya\n4\nah\noy\nto\nha\n",
"hp\n2\nht\ntp\n",
"ab\n2\nbb\nbc\n",
"bc\n1\nab\n",
"th\n1\nth\n",
"bn\n100\ndf\nyb\nze\nml\nyr\nof\nnw\nfm\ndw\nlv\nzr\nhu\nzt\nlw\nld\nmo\nxz\ntp\nmr\nou\nme\npx\nvp\nes\nxi\nnr\nbx\nqc\ngm\njs\nkn\ntw\nrq\nkz\nuc\nvc\nqr\nab\nna\nr... | 2CODEFORCES |
868_A. Bark to Unlock_177 | As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters.
Mu-mu's enemy Kashtanka wants to unlock Mu-mu's p... | #include <bits/stdc++.h>
using namespace std;
char s[101][3];
int main() {
int n, i, k = 0, c1 = 0, c2 = 0;
cin.get(s[0], 3);
cin >> n;
for (i = 1; i <= n; i++) {
cin.get();
cin.get(s[i], 3);
}
for (i = 1; i <= n && k < 2; i++) {
if (s[0][0] == s[i][1] && c1 == 0) {
k++;
c1 = 1;
... | 2C++ | {
"input": [
"ah\n1\nha\n",
"ya\n4\nah\noy\nto\nha\n",
"hp\n2\nht\ntp\n",
"ab\n2\nbb\nbc\n",
"bc\n1\nab\n",
"th\n1\nth\n",
"bn\n100\ndf\nyb\nze\nml\nyr\nof\nnw\nfm\ndw\nlv\nzr\nhu\nzt\nlw\nld\nmo\nxz\ntp\nmr\nou\nme\npx\nvp\nes\nxi\nnr\nbx\nqc\ngm\njs\nkn\ntw\nrq\nkz\nuc\nvc\nqr\nab\nna\nr... | 2CODEFORCES |
868_A. Bark to Unlock_178 | As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters.
Mu-mu's enemy Kashtanka wants to unlock Mu-mu's p... | one=input()
num=int(input())
twos=[]
for i in range(num):
twos.append(input())
if (one in twos) or (one[::-1] in twos):
print("YES")
else:
flag1,flag2=False,False
for i in range(num):
if twos[i][0]==one[1]:
flag1=True
if twos[i][1]==one[0]:
flag2=True
if(flag1 and flag2):
print("YES"... | 3Python3 | {
"input": [
"ah\n1\nha\n",
"ya\n4\nah\noy\nto\nha\n",
"hp\n2\nht\ntp\n",
"ab\n2\nbb\nbc\n",
"bc\n1\nab\n",
"th\n1\nth\n",
"bn\n100\ndf\nyb\nze\nml\nyr\nof\nnw\nfm\ndw\nlv\nzr\nhu\nzt\nlw\nld\nmo\nxz\ntp\nmr\nou\nme\npx\nvp\nes\nxi\nnr\nbx\nqc\ngm\njs\nkn\ntw\nrq\nkz\nuc\nvc\nqr\nab\nna\nr... | 2CODEFORCES |
868_A. Bark to Unlock_179 | As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters.
Mu-mu's enemy Kashtanka wants to unlock Mu-mu's p... | import java.util.Scanner;
public class Codechef {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String x = input.next();
int n = input.nextInt(), c = 0, c1 = 0;
String[] s = new String[n];
for (int i = 0; i < n; i++) {
s[i] = i... | 4JAVA | {
"input": [
"ah\n1\nha\n",
"ya\n4\nah\noy\nto\nha\n",
"hp\n2\nht\ntp\n",
"ab\n2\nbb\nbc\n",
"bc\n1\nab\n",
"th\n1\nth\n",
"bn\n100\ndf\nyb\nze\nml\nyr\nof\nnw\nfm\ndw\nlv\nzr\nhu\nzt\nlw\nld\nmo\nxz\ntp\nmr\nou\nme\npx\nvp\nes\nxi\nnr\nbx\nqc\ngm\njs\nkn\ntw\nrq\nkz\nuc\nvc\nqr\nab\nna\nr... | 2CODEFORCES |
893_D. Credit Card_180 | Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card.
She starts with 0 money on her account.
In the evening of i-th day a transaction ai occurs. If ai > 0, then ai bourles are deposited to Luba's account. If ai < 0, then ai bourles are withdrawn. And if ai = 0, ... | from sys import stdin
rr = lambda: stdin.readline().strip()
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())
debug=0
if debug:
fi = open('t.txt','r')
rr = lambda: fi.readline().replace('\n','')
import itertools
def parse(A):
su = maxi = 0
for x in A:
maxi = max(maxi, su)
su... | 1Python2 | {
"input": [
"5 10\n-5 0 10 -11 0\n",
"5 10\n-1 5 0 -5 3\n",
"3 4\n-10 0 20\n",
"9 13\n6 14 19 5 -5 6 -10 20 8\n",
"8 9\n6 -1 5 -5 -8 -7 -8 -7\n",
"10 7\n-9 3 -4 -22 4 -17 0 -14 3 -2\n",
"6 2\n-2 3 0 -2 0 0\n",
"5 10\n-8 -24 0 -22 12\n",
"5 13756\n-2 -9 -10 0 10\n",
"7 3\n1 -3 ... | 2CODEFORCES |
893_D. Credit Card_181 | Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card.
She starts with 0 money on her account.
In the evening of i-th day a transaction ai occurs. If ai > 0, then ai bourles are deposited to Luba's account. If ai < 0, then ai bourles are withdrawn. And if ai = 0, ... | #include <bits/stdc++.h>
using namespace std;
int main() {
cout << fixed << setprecision(10);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int n, d;
cin >> n >> d;
long long int a[n], b[n];
for (long long int i = 0; i < n; i++) {
cin >> a[i];
b[i] = (i ? b[i - 1] + ... | 2C++ | {
"input": [
"5 10\n-5 0 10 -11 0\n",
"5 10\n-1 5 0 -5 3\n",
"3 4\n-10 0 20\n",
"9 13\n6 14 19 5 -5 6 -10 20 8\n",
"8 9\n6 -1 5 -5 -8 -7 -8 -7\n",
"10 7\n-9 3 -4 -22 4 -17 0 -14 3 -2\n",
"6 2\n-2 3 0 -2 0 0\n",
"5 10\n-8 -24 0 -22 12\n",
"5 13756\n-2 -9 -10 0 10\n",
"7 3\n1 -3 ... | 2CODEFORCES |
893_D. Credit Card_182 | Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card.
She starts with 0 money on her account.
In the evening of i-th day a transaction ai occurs. If ai > 0, then ai bourles are deposited to Luba's account. If ai < 0, then ai bourles are withdrawn. And if ai = 0, ... | #Bhargey Mehta (Sophomore)
#DA-IICT, Gandhinagar
import sys, math, queue, bisect
#sys.stdin = open("input.txt", "r")
MOD = 10**9+7
sys.setrecursionlimit(1000000)
n, d = map(int, input().split())
a = list(map(int, input().split()))
p = [0 for i in range(n)]
for i in range(n):
p[i] = p[i-1]+a[i]
mx = [-1 for i in ra... | 3Python3 | {
"input": [
"5 10\n-5 0 10 -11 0\n",
"5 10\n-1 5 0 -5 3\n",
"3 4\n-10 0 20\n",
"9 13\n6 14 19 5 -5 6 -10 20 8\n",
"8 9\n6 -1 5 -5 -8 -7 -8 -7\n",
"10 7\n-9 3 -4 -22 4 -17 0 -14 3 -2\n",
"6 2\n-2 3 0 -2 0 0\n",
"5 10\n-8 -24 0 -22 12\n",
"5 13756\n-2 -9 -10 0 10\n",
"7 3\n1 -3 ... | 2CODEFORCES |
893_D. Credit Card_183 | Recenlty Luba got a credit card and started to use it. Let's consider n consecutive days Luba uses the card.
She starts with 0 money on her account.
In the evening of i-th day a transaction ai occurs. If ai > 0, then ai bourles are deposited to Luba's account. If ai < 0, then ai bourles are withdrawn. And if ai = 0, ... | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class P893D
{
public static void main(String[] args)
{
FastScanner scan = new FastScanner();
int n = scan.nextInt();
int d = scan.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++)
arr[i... | 4JAVA | {
"input": [
"5 10\n-5 0 10 -11 0\n",
"5 10\n-1 5 0 -5 3\n",
"3 4\n-10 0 20\n",
"9 13\n6 14 19 5 -5 6 -10 20 8\n",
"8 9\n6 -1 5 -5 -8 -7 -8 -7\n",
"10 7\n-9 3 -4 -22 4 -17 0 -14 3 -2\n",
"6 2\n-2 3 0 -2 0 0\n",
"5 10\n-8 -24 0 -22 12\n",
"5 13756\n-2 -9 -10 0 10\n",
"7 3\n1 -3 ... | 2CODEFORCES |
915_A. Garden_184 | Luba thinks about watering her garden. The garden can be represented as a segment of length k. Luba has got n buckets, the i-th bucket allows her to water some continuous subsegment of garden of length exactly ai each hour. Luba can't water any parts of the garden that were already watered, also she can't water the gro... | a, n = map(int, raw_input().split())
bs = map(int, raw_input().split())
bs = sorted(bs, reverse=True)
for b in bs:
if(n%b==0):
print(n/b)
exit(0)
| 1Python2 | {
"input": [
"3 6\n2 3 5\n",
"6 7\n1 2 3 4 5 6\n",
"3 7\n3 2 1\n",
"4 97\n97 1 50 10\n",
"5 25\n24 5 15 25 23\n",
"3 3\n3 2 1\n",
"4 18\n3 1 1 2\n",
"5 97\n1 10 50 97 2\n",
"1 88\n1\n",
"3 18\n1 9 3\n",
"8 8\n8 7 6 5 4 3 2 1\n",
"2 1\n2 1\n",
"5 16\n8 4 2 1 7\n",
... | 2CODEFORCES |
915_A. Garden_185 | Luba thinks about watering her garden. The garden can be represented as a segment of length k. Luba has got n buckets, the i-th bucket allows her to water some continuous subsegment of garden of length exactly ai each hour. Luba can't water any parts of the garden that were already watered, also she can't water the gro... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, result;
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++) {
int a;
scanf("%d", &a);
if (k % a == 0) result = min(result, k / a);
}
printf("%d\n", result);
return 0;
}
| 2C++ | {
"input": [
"3 6\n2 3 5\n",
"6 7\n1 2 3 4 5 6\n",
"3 7\n3 2 1\n",
"4 97\n97 1 50 10\n",
"5 25\n24 5 15 25 23\n",
"3 3\n3 2 1\n",
"4 18\n3 1 1 2\n",
"5 97\n1 10 50 97 2\n",
"1 88\n1\n",
"3 18\n1 9 3\n",
"8 8\n8 7 6 5 4 3 2 1\n",
"2 1\n2 1\n",
"5 16\n8 4 2 1 7\n",
... | 2CODEFORCES |
915_A. Garden_186 | Luba thinks about watering her garden. The garden can be represented as a segment of length k. Luba has got n buckets, the i-th bucket allows her to water some continuous subsegment of garden of length exactly ai each hour. Luba can't water any parts of the garden that were already watered, also she can't water the gro... | def is_prime(a):
return all(a % i for i in range(2, a))
n, k = map(int, input().split())
l = [int(x) for x in input().split()]
if is_prime(k):
if k in l:
print(1)
else:
print(k)
else:
ll = []
for i in range(len(l)):
if k % l[i] == 0:
ll.append(l[i])
print(k ... | 3Python3 | {
"input": [
"3 6\n2 3 5\n",
"6 7\n1 2 3 4 5 6\n",
"3 7\n3 2 1\n",
"4 97\n97 1 50 10\n",
"5 25\n24 5 15 25 23\n",
"3 3\n3 2 1\n",
"4 18\n3 1 1 2\n",
"5 97\n1 10 50 97 2\n",
"1 88\n1\n",
"3 18\n1 9 3\n",
"8 8\n8 7 6 5 4 3 2 1\n",
"2 1\n2 1\n",
"5 16\n8 4 2 1 7\n",
... | 2CODEFORCES |
915_A. Garden_187 | Luba thinks about watering her garden. The garden can be represented as a segment of length k. Luba has got n buckets, the i-th bucket allows her to water some continuous subsegment of garden of length exactly ai each hour. Luba can't water any parts of the garden that were already watered, also she can't water the gro... | import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
public class A915{
void solve()
{
int n = ni(), k = ni();
int[] a = ia(n);
int m = -1>>>1;
for(int x : a)
if(k % x == 0)
m = Math.min(m, k / x);
out.... | 4JAVA | {
"input": [
"3 6\n2 3 5\n",
"6 7\n1 2 3 4 5 6\n",
"3 7\n3 2 1\n",
"4 97\n97 1 50 10\n",
"5 25\n24 5 15 25 23\n",
"3 3\n3 2 1\n",
"4 18\n3 1 1 2\n",
"5 97\n1 10 50 97 2\n",
"1 88\n1\n",
"3 18\n1 9 3\n",
"8 8\n8 7 6 5 4 3 2 1\n",
"2 1\n2 1\n",
"5 16\n8 4 2 1 7\n",
... | 2CODEFORCES |
938_B. Run For Your Prize_188 | You and your friend are participating in a TV show "Run For Your Prize".
At the start of the show n prizes are located on a straight line. i-th prize is located at position ai. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these two positi... |
# Author : raj1307 - Raj Singh
# Date : 22.07.2020
from __future__ import division, print_function
import os,sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
def ii(): return int(input())... | 1Python2 | {
"input": [
"2\n2 999995\n",
"3\n2 3 9\n",
"3\n500000 500001 500002\n",
"1\n505050\n",
"2\n999998 999999\n",
"2\n500000 500001\n",
"1\n999995\n",
"1\n753572\n",
"2\n2 999999\n",
"1\n999998\n",
"4\n2 3 4 5\n",
"1\n500002\n",
"2\n100 999900\n",
"1\n500001\n",
... | 2CODEFORCES |
938_B. Run For Your Prize_189 | You and your friend are participating in a TV show "Run For Your Prize".
At the start of the show n prizes are located on a straight line. i-th prize is located at position ai. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these two positi... | #include <bits/stdc++.h>
using namespace std;
int main() {
int k;
scanf("%d", &k);
int maxn = 0;
for (int i = 1; i <= k; i++) {
int x;
scanf("%d", &x);
if (x >= 500001) {
maxn = max(maxn, 1000000 - x);
}
if (x <= 500000) {
maxn = max(maxn, x - 1);
}
}
printf("%d\n", maxn)... | 2C++ | {
"input": [
"2\n2 999995\n",
"3\n2 3 9\n",
"3\n500000 500001 500002\n",
"1\n505050\n",
"2\n999998 999999\n",
"2\n500000 500001\n",
"1\n999995\n",
"1\n753572\n",
"2\n2 999999\n",
"1\n999998\n",
"4\n2 3 4 5\n",
"1\n500002\n",
"2\n100 999900\n",
"1\n500001\n",
... | 2CODEFORCES |
938_B. Run For Your Prize_190 | You and your friend are participating in a TV show "Run For Your Prize".
At the start of the show n prizes are located on a straight line. i-th prize is located at position ai. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these two positi... | input()
a=list(map(int,input().split()))
ans=0
for x in a:
z=min(x-1,1000000-x)
ans=max(z,ans)
print(ans)
| 3Python3 | {
"input": [
"2\n2 999995\n",
"3\n2 3 9\n",
"3\n500000 500001 500002\n",
"1\n505050\n",
"2\n999998 999999\n",
"2\n500000 500001\n",
"1\n999995\n",
"1\n753572\n",
"2\n2 999999\n",
"1\n999998\n",
"4\n2 3 4 5\n",
"1\n500002\n",
"2\n100 999900\n",
"1\n500001\n",
... | 2CODEFORCES |
938_B. Run For Your Prize_191 | You and your friend are participating in a TV show "Run For Your Prize".
At the start of the show n prizes are located on a straight line. i-th prize is located at position ai. Positions of all prizes are distinct. You start at position 1, your friend — at position 106 (and there is no prize in any of these two positi... | import java.util.*;
import java.io.*;
import java.math.*;
public class mainClass
{
public static void main(String[] args) throws IOException
{
InputReader in = new InputReader(System.in);
PrintWriter out = new PrintWriter(System.out);
int n=in.nextInt();
int max1=1,max2=1000000;
f... | 4JAVA | {
"input": [
"2\n2 999995\n",
"3\n2 3 9\n",
"3\n500000 500001 500002\n",
"1\n505050\n",
"2\n999998 999999\n",
"2\n500000 500001\n",
"1\n999995\n",
"1\n753572\n",
"2\n2 999999\n",
"1\n999998\n",
"4\n2 3 4 5\n",
"1\n500002\n",
"2\n100 999900\n",
"1\n500001\n",
... | 2CODEFORCES |
963_B. Destruction of a Tree_192 | You are given a tree (a graph with n vertices and n - 1 edges in which it's possible to reach any vertex from any other vertex using only its edges).
A vertex can be destroyed if this vertex has even degree. If you destroy a vertex, all edges connected to it are also deleted.
Destroy all vertices in the given tree or... | #include <bits/stdc++.h>
using namespace std;
const int maxn = ((int)2e5) + 5;
vector<int> adj[maxn];
vector<int> del[maxn];
int INDEX = 0;
bool onStack[maxn];
int index_[maxn], lowLink[maxn];
stack<int> stk;
vector<vector<int> > components;
void getConnectedComponent(int i);
void getConnectedComponent(int i) {
index... | 2C++ | {
"input": [
"5\n0 1 2 1 2\n",
"4\n0 1 2 3\n",
"21\n11 19 4 19 6 0 13 7 6 2 5 3 16 10 1 9 15 21 9 21 2\n",
"100\n57 85 27 81 41 27 73 10 73 95 91 90 89 41 86 44 6 20 9 13 46 73 56 19 37 32 40 42 79 76 96 5 6 8 76 52 14 86 33 69 100 95 58 87 43 47 17 39 48 28 77 65 100 100 41 39 87 5 61 67 94 64 61 88 ... | 2CODEFORCES |
963_B. Destruction of a Tree_193 | You are given a tree (a graph with n vertices and n - 1 edges in which it's possible to reach any vertex from any other vertex using only its edges).
A vertex can be destroyed if this vertex has even degree. If you destroy a vertex, all edges connected to it are also deleted.
Destroy all vertices in the given tree or... | from collections import defaultdict,deque
import sys
import bisect
import math
input=sys.stdin.readline
mod=1000000007
def bfs(root,count):
q=deque([root])
vis.add(root)
while q:
vertex=q.popleft()
for child in graph[vertex]:
if ans[child]==0:
ans[child]=count+1
... | 3Python3 | {
"input": [
"5\n0 1 2 1 2\n",
"4\n0 1 2 3\n",
"21\n11 19 4 19 6 0 13 7 6 2 5 3 16 10 1 9 15 21 9 21 2\n",
"100\n57 85 27 81 41 27 73 10 73 95 91 90 89 41 86 44 6 20 9 13 46 73 56 19 37 32 40 42 79 76 96 5 6 8 76 52 14 86 33 69 100 95 58 87 43 47 17 39 48 28 77 65 100 100 41 39 87 5 61 67 94 64 61 88 ... | 2CODEFORCES |
963_B. Destruction of a Tree_194 | You are given a tree (a graph with n vertices and n - 1 edges in which it's possible to reach any vertex from any other vertex using only its edges).
A vertex can be destroyed if this vertex has even degree. If you destroy a vertex, all edges connected to it are also deleted.
Destroy all vertices in the given tree or... | 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.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOExceptio... | 4JAVA | {
"input": [
"5\n0 1 2 1 2\n",
"4\n0 1 2 3\n",
"21\n11 19 4 19 6 0 13 7 6 2 5 3 16 10 1 9 15 21 9 21 2\n",
"100\n57 85 27 81 41 27 73 10 73 95 91 90 89 41 86 44 6 20 9 13 46 73 56 19 37 32 40 42 79 76 96 5 6 8 76 52 14 86 33 69 100 95 58 87 43 47 17 39 48 28 77 65 100 100 41 39 87 5 61 67 94 64 61 88 ... | 2CODEFORCES |
990_E. Post Lamps_195 | Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has n positions to install lamps, they correspond to the integer numbers from 0 to n - 1 on the OX axis. However, some positions are blocked an... | get = lambda: [int(x) for x in raw_input().split()]
n, m, k = get()
block = get()
a = get()
can = [1] * n
for x in block:
can[x] = 0
last_can = [0] * n
last = -1
for i in range(n):
last_can[i] = i if can[i] else last
last = last_can[i]
ans = 10**13
if can[0]:
for i in range(k):
step = i+1
... | 1Python2 | {
"input": [
"5 1 5\n0\n3 3 3 3 3\n",
"4 3 4\n1 2 3\n1 10 100 1000\n",
"7 4 3\n2 4 5 6\n3 14 15\n",
"6 2 3\n1 3\n1 2 3\n",
"3 1 2\n2\n1 1\n",
"3 1 2\n1\n8 61\n",
"3 0 3\n\n334 500 1001\n",
"20 16 16\n1 2 3 4 5 6 8 9 10 11 13 14 15 16 18 19\n2 1 1 1 1 1 3 3 2 2 1 3 3 3 3 2\n",
"1 1 ... | 2CODEFORCES |
990_E. Post Lamps_196 | Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has n positions to install lamps, they correspond to the integer numbers from 0 to n - 1 on the OX axis. However, some positions are blocked an... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
const long long INF = 1e18 + 7;
int a[maxn];
int aa[maxn];
int pre[maxn];
int b[maxn];
int main() {
int i, j, m, n, t, z;
int k;
scanf("%d%d%d", &n, &m, &k);
for (i = 1; i <= m; i++) {
scanf("%d", &a[i]);
aa[a[i]] = 1;
}
for (i ... | 2C++ | {
"input": [
"5 1 5\n0\n3 3 3 3 3\n",
"4 3 4\n1 2 3\n1 10 100 1000\n",
"7 4 3\n2 4 5 6\n3 14 15\n",
"6 2 3\n1 3\n1 2 3\n",
"3 1 2\n2\n1 1\n",
"3 1 2\n1\n8 61\n",
"3 0 3\n\n334 500 1001\n",
"20 16 16\n1 2 3 4 5 6 8 9 10 11 13 14 15 16 18 19\n2 1 1 1 1 1 3 3 2 2 1 3 3 3 3 2\n",
"1 1 ... | 2CODEFORCES |
990_E. Post Lamps_197 | Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has n positions to install lamps, they correspond to the integer numbers from 0 to n - 1 on the OX axis. However, some positions are blocked an... | import sys
from array import array
n, m, k = map(int, input().split())
block = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
if block and block[0] == 0:
print(-1)
exit()
prev = array('i', list(range(n)))
for x in block:
prev[x] = -1
for i in range(1, n):
if prev[i] == -1:... | 3Python3 | {
"input": [
"5 1 5\n0\n3 3 3 3 3\n",
"4 3 4\n1 2 3\n1 10 100 1000\n",
"7 4 3\n2 4 5 6\n3 14 15\n",
"6 2 3\n1 3\n1 2 3\n",
"3 1 2\n2\n1 1\n",
"3 1 2\n1\n8 61\n",
"3 0 3\n\n334 500 1001\n",
"20 16 16\n1 2 3 4 5 6 8 9 10 11 13 14 15 16 18 19\n2 1 1 1 1 1 3 3 2 2 1 3 3 3 3 2\n",
"1 1 ... | 2CODEFORCES |
990_E. Post Lamps_198 | Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has n positions to install lamps, they correspond to the integer numbers from 0 to n - 1 on the OX axis. However, some positions are blocked an... |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class E {
public static void solve(FastScanner fs) {
int length=fs.nextInt();
int numBlocked=fs.nextInt();
int maxLamp=fs... | 4JAVA | {
"input": [
"5 1 5\n0\n3 3 3 3 3\n",
"4 3 4\n1 2 3\n1 10 100 1000\n",
"7 4 3\n2 4 5 6\n3 14 15\n",
"6 2 3\n1 3\n1 2 3\n",
"3 1 2\n2\n1 1\n",
"3 1 2\n1\n8 61\n",
"3 0 3\n\n334 500 1001\n",
"20 16 16\n1 2 3 4 5 6 8 9 10 11 13 14 15 16 18 19\n2 1 1 1 1 1 3 3 2 2 1 3 3 3 3 2\n",
"1 1 ... | 2CODEFORCES |
appu-and-sugarcane-farm_199 | As you know Appu created aversion to Maths after that maths problem given by his teacher.So he stopped studying and began to do farming. He has some land where he starts growing sugarcane. At the end of the season he grew N sugarcanes. Is Appu satisfied??. No,
He wants all his sugar canes to be of the same height. He g... | '''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
num_of_sugarcanes = int(raw_input())
list_of_sugarcanes = map(int,raw_input().split())
max_of_sugarcanes = max(list_of_sugarcanes)
def xyz (list_of_sugarcanes, max_sugar):
for x i... | 1Python2 | {
"input": [
"2\n1 23\n\nSAMPLE",
"47\n169884146 730277703 8645016 732791141 331583052 25104065 895622218 478600214 924154067 813310590 389843997 977252329 338578814 512086554 953548504 508435813 602216502 773835133 194230149 661387945 354427757 690709868 320153566 468158534 287696464 210587004 734620117 5349... | 3HACKEREARTH |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.