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 |
|---|---|---|---|---|---|
361_C. Levko and Array Recovery_400 | Levko loves array a1, a2, ... , an, consisting of integers, very much. That is why Levko is playing with array a, performing all sorts of operations with it. Each operation Levko performs is of one of two types:
1. Increase all elements from li to ri by di. In other words, perform assignments aj = aj + di for all j ... | import java.io.*;
import java.util.*;
public class R210qCLevkoAndArrayRecovery {
static int limit = (int)1e9;
public static void main(String args[]) {
InputReader in = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
int n = in.nextInt();
int m = in.nextInt();
long a[] = new ... | 4JAVA | {
"input": [
"4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 8\n",
"4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 13\n",
"4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 8\n",
"1 4\n1 1 1 2\n2 1 1 6\n1 1 1 1\n2 1 1 7\n",
"2 2\n2 1 2 8\n2 1 2 7\n",
"97 29\n2 78 82 356152\n2 14 29 430177\n1 59 8... | 2CODEFORCES |
385_A. Bear and Raspberry_401 | The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following n days. According to the bear's data, on the i-th (1 ≤ i ≤ n) day, the price for one barrel of honey is going to is xi kilos of raspberry.
Unfortunately, the b... | n,c = map(int, raw_input().split())
x = map(int, raw_input().split())
lista = []
for i in range(n-1):
d = x[i] - x[i+1] - c
lista.append(d)
if max(lista) < 0:
print 0
else:
print max(lista) | 1Python2 | {
"input": [
"6 2\n100 1 10 40 10 40\n",
"5 1\n5 10 7 3 20\n",
"3 0\n1 2 3\n",
"89 1\n50 53 97 41 68 27 53 66 93 19 11 78 46 49 38 69 96 9 43 16 1 63 95 64 96 6 34 34 45 40 19 4 53 8 11 18 95 25 50 16 64 33 97 49 23 81 63 10 30 73 76 55 7 70 9 98 6 36 75 78 3 92 85 75 40 75 55 71 9 91 15 17 47 55 44 3... | 2CODEFORCES |
385_A. Bear and Raspberry_402 | The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following n days. According to the bear's data, on the i-th (1 ≤ i ≤ n) day, the price for one barrel of honey is going to is xi kilos of raspberry.
Unfortunately, the b... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, c;
int m;
int dif;
int ans;
while (scanf("%d %d", &n, &c) == 2) {
vector<int> num;
for (int i = 0; i < n; i++) {
scanf("%d", &m);
num.push_back(m);
}
dif = ans = 0;
for (int i = 1; i < num.size(); i++) {
if... | 2C++ | {
"input": [
"6 2\n100 1 10 40 10 40\n",
"5 1\n5 10 7 3 20\n",
"3 0\n1 2 3\n",
"89 1\n50 53 97 41 68 27 53 66 93 19 11 78 46 49 38 69 96 9 43 16 1 63 95 64 96 6 34 34 45 40 19 4 53 8 11 18 95 25 50 16 64 33 97 49 23 81 63 10 30 73 76 55 7 70 9 98 6 36 75 78 3 92 85 75 40 75 55 71 9 91 15 17 47 55 44 3... | 2CODEFORCES |
385_A. Bear and Raspberry_403 | The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following n days. According to the bear's data, on the i-th (1 ≤ i ≤ n) day, the price for one barrel of honey is going to is xi kilos of raspberry.
Unfortunately, the b... |
n, c = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
for i in range(n - 1):
d = l[i] - l[i + 1] - c
ans = max(ans, d)
print(ans) | 3Python3 | {
"input": [
"6 2\n100 1 10 40 10 40\n",
"5 1\n5 10 7 3 20\n",
"3 0\n1 2 3\n",
"89 1\n50 53 97 41 68 27 53 66 93 19 11 78 46 49 38 69 96 9 43 16 1 63 95 64 96 6 34 34 45 40 19 4 53 8 11 18 95 25 50 16 64 33 97 49 23 81 63 10 30 73 76 55 7 70 9 98 6 36 75 78 3 92 85 75 40 75 55 71 9 91 15 17 47 55 44 3... | 2CODEFORCES |
385_A. Bear and Raspberry_404 | The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following n days. According to the bear's data, on the i-th (1 ≤ i ≤ n) day, the price for one barrel of honey is going to is xi kilos of raspberry.
Unfortunately, the b... | import java.util.Scanner;
public class freebie{
public static void main(String[] args){
int n,c;
Scanner sc = new Scanner(System.in);
n=sc.nextInt();
c=sc.nextInt();
int[] array = new int[n+1];
array[n] = 0 ;
for(int i = 0;i<n;i++){
array[i]=sc.nextInt();}
int [] difference = new int[n];
int temp = 0 ;
for(int i=0;i<(n... | 4JAVA | {
"input": [
"6 2\n100 1 10 40 10 40\n",
"5 1\n5 10 7 3 20\n",
"3 0\n1 2 3\n",
"89 1\n50 53 97 41 68 27 53 66 93 19 11 78 46 49 38 69 96 9 43 16 1 63 95 64 96 6 34 34 45 40 19 4 53 8 11 18 95 25 50 16 64 33 97 49 23 81 63 10 30 73 76 55 7 70 9 98 6 36 75 78 3 92 85 75 40 75 55 71 9 91 15 17 47 55 44 3... | 2CODEFORCES |
405_E. Graph Cutting_405 | Little Chris is participating in a graph cutting contest. He's a pro. The time has come to test his skills to the fullest.
Chris is given a simple undirected connected graph with n vertices (numbered from 1 to n) and m edges. The problem is to cut it into edge-distinct paths of length 2. Formally, Chris has to partiti... | #include <bits/stdc++.h>
using namespace std;
int n, m;
int visit[111111];
vector<int> v[111111], mark[111111];
int dfs(int t) {
vector<int> v1;
int i;
for (i = 0; i < v[t].size(); i++) {
int u = v[t][i];
if (visit[mark[t][i]] == 0) {
visit[mark[t][i]] = 1;
int w = dfs(u);
if (w == 0)
... | 2C++ | {
"input": [
"3 2\n1 2\n2 3\n",
"3 3\n1 2\n2 3\n3 1\n",
"8 12\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4\n3 5\n3 6\n5 6\n6 7\n6 8\n7 8\n",
"9 12\n1 2\n2 3\n4 5\n5 6\n6 7\n7 8\n1 4\n4 7\n2 5\n5 8\n3 6\n6 9\n",
"5 4\n2 1\n3 2\n4 3\n5 4\n",
"4 4\n1 2\n2 3\n3 1\n1 4\n",
"9 8\n1 9\n2 9\n3 9\n4 9\n5 9\n6 9\n... | 2CODEFORCES |
405_E. Graph Cutting_406 | Little Chris is participating in a graph cutting contest. He's a pro. The time has come to test his skills to the fullest.
Chris is given a simple undirected connected graph with n vertices (numbered from 1 to n) and m edges. The problem is to cut it into edge-distinct paths of length 2. Formally, Chris has to partiti... | import sys
input = sys.stdin.readline
print = sys.stdout.write
def get_input():
n, m = [int(x) for x in input().split(' ')]
graph = [[] for _ in range(n + 1)]
for _ in range(m):
c1, c2 = [int(x) for x in input().split(' ')]
graph[c1].append(c2)
graph[c2].append(c1)
if m % 2 ... | 3Python3 | {
"input": [
"3 2\n1 2\n2 3\n",
"3 3\n1 2\n2 3\n3 1\n",
"8 12\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4\n3 5\n3 6\n5 6\n6 7\n6 8\n7 8\n",
"9 12\n1 2\n2 3\n4 5\n5 6\n6 7\n7 8\n1 4\n4 7\n2 5\n5 8\n3 6\n6 9\n",
"5 4\n2 1\n3 2\n4 3\n5 4\n",
"4 4\n1 2\n2 3\n3 1\n1 4\n",
"9 8\n1 9\n2 9\n3 9\n4 9\n5 9\n6 9\n... | 2CODEFORCES |
405_E. Graph Cutting_407 | Little Chris is participating in a graph cutting contest. He's a pro. The time has come to test his skills to the fullest.
Chris is given a simple undirected connected graph with n vertices (numbered from 1 to n) and m edges. The problem is to cut it into edge-distinct paths of length 2. Formally, Chris has to partiti... |
import java.io.*;
import java.util.*;
public class E {
FastScanner in = new FastScanner(System.in);
PrintWriter out = new PrintWriter(System.out);
boolean[] visited;
HashSet<Long> usedEdge = new HashSet<Long>();
ArrayList<Integer>[] g;
StringBuilder res = new StringBuilder();
final int CONV_CONST = 150000;
... | 4JAVA | {
"input": [
"3 2\n1 2\n2 3\n",
"3 3\n1 2\n2 3\n3 1\n",
"8 12\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4\n3 5\n3 6\n5 6\n6 7\n6 8\n7 8\n",
"9 12\n1 2\n2 3\n4 5\n5 6\n6 7\n7 8\n1 4\n4 7\n2 5\n5 8\n3 6\n6 9\n",
"5 4\n2 1\n3 2\n4 3\n5 4\n",
"4 4\n1 2\n2 3\n3 1\n1 4\n",
"9 8\n1 9\n2 9\n3 9\n4 9\n5 9\n6 9\n... | 2CODEFORCES |
433_A. Kitahara Haruki's Gift_408 | Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal ... | n,r = int(raw_input()),[int(c) for c in raw_input().split()]
print ['NO','YES'][sum(r)%400 == 0 or (sum(r)%200 == 0 and 100 in r)] | 1Python2 | {
"input": [
"4\n100 100 100 200\n",
"3\n100 200 100\n",
"9\n100 100 100 200 100 100 200 100 200\n",
"3\n100 100 100\n",
"7\n200 200 200 100 200 200 200\n",
"100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100... | 2CODEFORCES |
433_A. Kitahara Haruki's Gift_409 | Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal ... | #include <bits/stdc++.h>
using namespace std;
const int max1 = 100010;
long long a[max1], b[max1];
int main() {
int n, x, y = 0, z = 0;
cin >> n;
if (n == 1) {
cout << "NO\n";
} else {
for (int i = 0; i < n; i++) {
cin >> x;
if (x == 200) {
z++;
}
y += x;
}
if ((y... | 2C++ | {
"input": [
"4\n100 100 100 200\n",
"3\n100 200 100\n",
"9\n100 100 100 200 100 100 200 100 200\n",
"3\n100 100 100\n",
"7\n200 200 200 100 200 200 200\n",
"100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100... | 2CODEFORCES |
433_A. Kitahara Haruki's Gift_410 | Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal ... | n = int(input())
a = list(input().split(' '))
a = list(int(x) for x in a)
one, two = 0, 0
for i in range(n):
if a[i] == 100:
one += 1
else:
two += 1
flag = False
if one%2 == 0 and two%2 == 0 or one > two and two % 2 == 1 and one % 2 == 0 and one >= 2 \
or one < two and two%2 == 1 and one%2 ==... | 3Python3 | {
"input": [
"4\n100 100 100 200\n",
"3\n100 200 100\n",
"9\n100 100 100 200 100 100 200 100 200\n",
"3\n100 100 100\n",
"7\n200 200 200 100 200 200 200\n",
"100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100... | 2CODEFORCES |
433_A. Kitahara Haruki's Gift_411 | Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal ... | import java.util.Scanner;
/**
* Created by zephyr on 5/30/14.
*/
public class GIft {
public static void main(String args[]){
System.out.println(gift());
}
public static String gift(){
Scanner scanner = new Scanner(System.in);
int number = scanner.nextInt();
int x100 = 0;
... | 4JAVA | {
"input": [
"4\n100 100 100 200\n",
"3\n100 200 100\n",
"9\n100 100 100 200 100 100 200 100 200\n",
"3\n100 100 100\n",
"7\n200 200 200 100 200 200 200\n",
"100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100... | 2CODEFORCES |
455_C. Civilization_412 | Andrew plays a game called "Civilization". Dima helps him.
The game has n cities and m bidirectional roads. The cities are numbered from 1 to n. Between any pair of cities there either is a single (unique) path, or there is no path at all. A path is such a sequence of distinct cities v1, v2, ..., vk, that there is a r... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5;
int n, m;
int f[maxn];
int diameter[maxn];
int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }
vector<int> G[maxn];
int d1[maxn], d2[maxn];
int vis[maxn], t;
queue<int> q;
int bfs1(int u, int d[]) {
t++;
q.push(u);
d[u] = 0;
vis[u] = ... | 2C++ | {
"input": [
"6 0 6\n2 1 2\n2 3 4\n2 5 6\n2 3 2\n2 5 3\n1 1\n",
"10 3 5\n1 2\n2 3\n1 4\n2 3 6\n1 6\n2 1 6\n2 8 7\n1 10\n",
"10 2 6\n1 2\n1 3\n2 1 8\n2 9 2\n1 2\n1 9\n2 3 5\n1 8\n",
"10 5 2\n1 2\n1 3\n1 4\n2 5\n1 6\n1 5\n1 8\n",
"10 6 64\n1 2\n2 3\n2 4\n4 5\n3 6\n3 7\n2 4 4\n1 4\n1 6\n1 5\n1 8\n2 1... | 2CODEFORCES |
455_C. Civilization_413 | Andrew plays a game called "Civilization". Dima helps him.
The game has n cities and m bidirectional roads. The cities are numbered from 1 to n. Between any pair of cities there either is a single (unique) path, or there is no path at all. A path is such a sequence of distinct cities v1, v2, ..., vk, that there is a r... | import java.io.*;
import java.util.*;
import java.math.*;
import java.text.DecimalFormat;
import java.text.NumberFormat;
@SuppressWarnings("unchecked")
public class Main {
int mod = 1000000007;
public class SegmentTree{
int n;
long[] tree;
SegmentTree(long[] arr){
th... | 4JAVA | {
"input": [
"6 0 6\n2 1 2\n2 3 4\n2 5 6\n2 3 2\n2 5 3\n1 1\n",
"10 3 5\n1 2\n2 3\n1 4\n2 3 6\n1 6\n2 1 6\n2 8 7\n1 10\n",
"10 2 6\n1 2\n1 3\n2 1 8\n2 9 2\n1 2\n1 9\n2 3 5\n1 8\n",
"10 5 2\n1 2\n1 3\n1 4\n2 5\n1 6\n1 5\n1 8\n",
"10 6 64\n1 2\n2 3\n2 4\n4 5\n3 6\n3 7\n2 4 4\n1 4\n1 6\n1 5\n1 8\n2 1... | 2CODEFORCES |
478_A. Initial Bet_414 | There are five people playing a game called "Generosity". Each person gives some non-zero number of coins b as an initial bet. After all players make their bets of b coins, the following operation is repeated for several times: a coin is passed from one player to some other player.
Your task is to write a program that... | x = [int(y) for y in raw_input().split()]
if(sum(x)%5==0 and sum(x)>0):
print sum(x)/5
else:
print "-1" | 1Python2 | {
"input": [
"2 5 4 0 4\n",
"4 5 9 2 1\n",
"99 100 100 100 100\n",
"57 83 11 4 93\n",
"99 99 99 99 99\n",
"100 0 0 0 0\n",
"0 1 2 3 4\n",
"93 100 99 90 98\n",
"87 38 19 33 100\n",
"1 1 1 1 1\n",
"0 0 0 0 1\n",
"2 3 4 5 6\n",
"1 2 1 2 3\n",
"0 0 0 0 0\n",
"10... | 2CODEFORCES |
478_A. Initial Bet_415 | There are five people playing a game called "Generosity". Each person gives some non-zero number of coins b as an initial bet. After all players make their bets of b coins, the following operation is repeated for several times: a coin is passed from one player to some other player.
Your task is to write a program that... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[5], sum = 0;
for (int i = 0; i < 5; i++) {
cin >> a[i];
sum += a[i];
}
n = sum / 5;
if (sum == 0)
cout << -1;
else if (n * 5 == sum)
cout << n;
else
cout << -1;
return 0;
}
| 2C++ | {
"input": [
"2 5 4 0 4\n",
"4 5 9 2 1\n",
"99 100 100 100 100\n",
"57 83 11 4 93\n",
"99 99 99 99 99\n",
"100 0 0 0 0\n",
"0 1 2 3 4\n",
"93 100 99 90 98\n",
"87 38 19 33 100\n",
"1 1 1 1 1\n",
"0 0 0 0 1\n",
"2 3 4 5 6\n",
"1 2 1 2 3\n",
"0 0 0 0 0\n",
"10... | 2CODEFORCES |
478_A. Initial Bet_416 | There are five people playing a game called "Generosity". Each person gives some non-zero number of coins b as an initial bet. After all players make their bets of b coins, the following operation is repeated for several times: a coin is passed from one player to some other player.
Your task is to write a program that... | l=list(map(int,input().split()))
x=sum(l)
if(x%5==0 and x!=0):
print(int(x/5))
else:
print(-1)
| 3Python3 | {
"input": [
"2 5 4 0 4\n",
"4 5 9 2 1\n",
"99 100 100 100 100\n",
"57 83 11 4 93\n",
"99 99 99 99 99\n",
"100 0 0 0 0\n",
"0 1 2 3 4\n",
"93 100 99 90 98\n",
"87 38 19 33 100\n",
"1 1 1 1 1\n",
"0 0 0 0 1\n",
"2 3 4 5 6\n",
"1 2 1 2 3\n",
"0 0 0 0 0\n",
"10... | 2CODEFORCES |
478_A. Initial Bet_417 | There are five people playing a game called "Generosity". Each person gives some non-zero number of coins b as an initial bet. After all players make their bets of b coins, the following operation is repeated for several times: a coin is passed from one player to some other player.
Your task is to write a program that... | import java.util.Scanner ;
public class A478_InitialBet {
public static void main(String[] args) {
Scanner ss =new Scanner (System.in) ;
int one = ss.nextInt() ;
int two = ss.nextInt() ;
int three = ss.nextInt() ;
int four = ss.nextInt() ;
int five = ss.nextInt() ;
int sum = one + two + three + f... | 4JAVA | {
"input": [
"2 5 4 0 4\n",
"4 5 9 2 1\n",
"99 100 100 100 100\n",
"57 83 11 4 93\n",
"99 99 99 99 99\n",
"100 0 0 0 0\n",
"0 1 2 3 4\n",
"93 100 99 90 98\n",
"87 38 19 33 100\n",
"1 1 1 1 1\n",
"0 0 0 0 1\n",
"2 3 4 5 6\n",
"1 2 1 2 3\n",
"0 0 0 0 0\n",
"10... | 2CODEFORCES |
500_C. New Year Book Reading_418 | New Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He has n books numbered by integers from 1 to n. The weight of the i-th (1 ≤ i ≤ n) book is wi.
As Jaehyun's house is not large enough to have a bookshelf, he keeps the n books by stacking them vertically. When he wants to read a... | def read_sort(n,weight,order):
stack=[]
answer=0
for i in range(n[1]):
stack.append(order[i])
if i<1:
continue
else:
for j in range(len(stack)-1):
if stack[-1]!=stack[-2-j]:
answer+=weight[stack[-2-j]-1]
... | 1Python2 | {
"input": [
"3 5\n1 2 3\n1 3 2 3 1\n",
"50 50\n75 71 23 37 28 23 69 75 5 62 3 11 96 100 13 50 57 51 8 90 4 6 84 27 11 89 95 81 10 62 48 52 69 87 97 95 30 74 21 42 36 64 31 80 81 50 56 53 33 99\n26 30 5 33 35 29 6 15 36 17 32 16 14 1 29 34 22 40 12 42 38 48 39 50 13 47 18 43 10 8 49 45 11 31 21 37 46 28 20 41... | 2CODEFORCES |
500_C. New Year Book Reading_419 | New Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He has n books numbered by integers from 1 to n. The weight of the i-th (1 ≤ i ≤ n) book is wi.
As Jaehyun's house is not large enough to have a bookshelf, he keeps the n books by stacking them vertically. When he wants to read a... | #include <bits/stdc++.h>
using namespace std;
const int N = 1005;
inline int read() {
int x = 0, w = 1;
char ch = 0;
while (ch < '0' || ch > '9') {
ch = getchar();
if (ch == '-') w = -1;
}
while (ch <= '9' && ch >= '0') {
x = (x << 1) + (x << 3) + ch - '0';
ch = getchar();
}
return x * w;
... | 2C++ | {
"input": [
"3 5\n1 2 3\n1 3 2 3 1\n",
"50 50\n75 71 23 37 28 23 69 75 5 62 3 11 96 100 13 50 57 51 8 90 4 6 84 27 11 89 95 81 10 62 48 52 69 87 97 95 30 74 21 42 36 64 31 80 81 50 56 53 33 99\n26 30 5 33 35 29 6 15 36 17 32 16 14 1 29 34 22 40 12 42 38 48 39 50 13 47 18 43 10 8 49 45 11 31 21 37 46 28 20 41... | 2CODEFORCES |
500_C. New Year Book Reading_420 | New Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He has n books numbered by integers from 1 to n. The weight of the i-th (1 ≤ i ≤ n) book is wi.
As Jaehyun's house is not large enough to have a bookshelf, he keeps the n books by stacking them vertically. When he wants to read a... | n,m=map(int,input().split())
weight=[int(i) for i in input().split()]
order=[int(i) for i in input().split()]
stack=[]
for i in order:
if i-1 not in stack:
stack.append(i-1)
#print(stack)
ans=0
for i in order:
#i=i-1
currlift=sum(weight[i] for i in stack[0:stack.index(i-1)])
ans+=currlift
t... | 3Python3 | {
"input": [
"3 5\n1 2 3\n1 3 2 3 1\n",
"50 50\n75 71 23 37 28 23 69 75 5 62 3 11 96 100 13 50 57 51 8 90 4 6 84 27 11 89 95 81 10 62 48 52 69 87 97 95 30 74 21 42 36 64 31 80 81 50 56 53 33 99\n26 30 5 33 35 29 6 15 36 17 32 16 14 1 29 34 22 40 12 42 38 48 39 50 13 47 18 43 10 8 49 45 11 31 21 37 46 28 20 41... | 2CODEFORCES |
500_C. New Year Book Reading_421 | New Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He has n books numbered by integers from 1 to n. The weight of the i-th (1 ≤ i ≤ n) book is wi.
As Jaehyun's house is not large enough to have a bookshelf, he keeps the n books by stacking them vertically. When he wants to read a... | import java.util.*;
import java.io.*;
public class TaskC {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
int[] w = new int[n];
int[] b = new int[m];
for (int i = 0; i < n; i++) {
... | 4JAVA | {
"input": [
"3 5\n1 2 3\n1 3 2 3 1\n",
"50 50\n75 71 23 37 28 23 69 75 5 62 3 11 96 100 13 50 57 51 8 90 4 6 84 27 11 89 95 81 10 62 48 52 69 87 97 95 30 74 21 42 36 64 31 80 81 50 56 53 33 99\n26 30 5 33 35 29 6 15 36 17 32 16 14 1 29 34 22 40 12 42 38 48 39 50 13 47 18 43 10 8 49 45 11 31 21 37 46 28 20 41... | 2CODEFORCES |
526_A. King of Thieves_422 | In this problem you will meet the simplified model of game King of Thieves.
In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obstacles on your way.
<image>
An interesting feature of the game is that you can design your own levels... | n=input()
a=raw_input()
for i in range(n):
if(a[i]=='*'):
for j in range(1,25):
count=0
for x in range(i+j,n,j):
if(a[x]=='*'):
count+=1
else:
break
if count==4:
print "yes"
exit(0)
print "no"
| 1Python2 | {
"input": [
"16\n.**.*..*.***.**.\n",
"11\n.*.*...*.*.\n",
"20\n.*..*...*....*.....*\n",
"97\n****.***.***.*..**.**.*.*.***.*............*..*......*.***.**.*.***.*.***.*..*.**.*.***.**.*****.\n",
"5\n*.***\n",
"4\n****\n",
"11\n.*.*.*.*...\n",
"72\n.***.**.*.*...*****.*.*.*.*.**....**... | 2CODEFORCES |
526_A. King of Thieves_423 | In this problem you will meet the simplified model of game King of Thieves.
In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obstacles on your way.
<image>
An interesting feature of the game is that you can design your own levels... | #include <bits/stdc++.h>
using namespace std;
using std::map;
const int CMAX = 100005;
const char Cfd[] = "", Cfr[] = "";
int main() {
int n;
string s;
cin >> n >> s;
for (int i = 0; i < s.length(); i++)
if (s[i] == '*')
for (int j = 1; i + 4 * j < s.length(); j++)
if (s[i + j] == '*' && s[i +... | 2C++ | {
"input": [
"16\n.**.*..*.***.**.\n",
"11\n.*.*...*.*.\n",
"20\n.*..*...*....*.....*\n",
"97\n****.***.***.*..**.**.*.*.***.*............*..*......*.***.**.*.***.*.***.*..*.**.*.***.**.*****.\n",
"5\n*.***\n",
"4\n****\n",
"11\n.*.*.*.*...\n",
"72\n.***.**.*.*...*****.*.*.*.*.**....**... | 2CODEFORCES |
526_A. King of Thieves_424 | In this problem you will meet the simplified model of game King of Thieves.
In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obstacles on your way.
<image>
An interesting feature of the game is that you can design your own levels... | #!/usr/bin/env python
# jump.py - Codeforces <!!! NNNA !!!> quiz
#
# Copyright (C) 2015 Sergey
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0... | 3Python3 | {
"input": [
"16\n.**.*..*.***.**.\n",
"11\n.*.*...*.*.\n",
"20\n.*..*...*....*.....*\n",
"97\n****.***.***.*..**.**.*.*.***.*............*..*......*.***.**.*.***.*.***.*..*.**.*.***.**.*****.\n",
"5\n*.***\n",
"4\n****\n",
"11\n.*.*.*.*...\n",
"72\n.***.**.*.*...*****.*.*.*.*.**....**... | 2CODEFORCES |
526_A. King of Thieves_425 | In this problem you will meet the simplified model of game King of Thieves.
In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obstacles on your way.
<image>
An interesting feature of the game is that you can design your own levels... | import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String s = sc.next();
for (int i = 0; i < n; i++) {
for (int j = 1; j < n; j++) {
boolean f = true;
for(int k = 0; k < 5; k++)
if(i + k * j < n && s.ch... | 4JAVA | {
"input": [
"16\n.**.*..*.***.**.\n",
"11\n.*.*...*.*.\n",
"20\n.*..*...*....*.....*\n",
"97\n****.***.***.*..**.**.*.*.***.*............*..*......*.***.**.*.***.*.***.*..*.**.*.***.**.*****.\n",
"5\n*.***\n",
"4\n****\n",
"11\n.*.*.*.*...\n",
"72\n.***.**.*.*...*****.*.*.*.*.**....**... | 2CODEFORCES |
551_B. ZgukistringZ_426 | Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one.
GukiZ has strings a, b, and c. He wants to obtain string k by swapping some letters in a, so that k should contain as many non-overlapping substrings equal either to b or c as possible. Substring of string x... | def solve():
a = raw_input()
b = raw_input()
c = raw_input()
acount = [0] * 26
for char in a: acount[ord(char) - ord('a')]+=1
bcount = [0] * 26
for char in b: bcount[ord(char) - ord('a')]+=1
ccount = [0] * 26
for char in c: ccount[ord(char) - ord('a')]+=1
bres = 0
cres = 0
... | 1Python2 | {
"input": [
"pozdravstaklenidodiri\nniste\ndobri\n",
"aaa\na\nb\n",
"abbbaaccca\nab\naca\n",
"brtakoktrosttttttttttosafasfkalsfkodfdasiofhadfhasdsajfdsafoasodsafahaihfdisoadspapsapiosapdsajdipsahdhasuirhaeuifhhfkjgosooooooooodafdfioottttafdsafaddfuiasdjfjasdo\nokat\ntako\n",
"aleksandrehteosidate... | 2CODEFORCES |
551_B. ZgukistringZ_427 | Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one.
GukiZ has strings a, b, and c. He wants to obtain string k by swapping some letters in a, so that k should contain as many non-overlapping substrings equal either to b or c as possible. Substring of string x... | #include <bits/stdc++.h>
using namespace std;
const int LIM = 26;
const int INF = 1e+9;
struct str {
int a[LIM];
str(string s) {
fill(a, a + LIM, 0);
for (int i = 0; i < (int)s.length(); ++i) ++a[s[i] - 'a'];
}
};
string sa, sb, sc;
int check(str& a, int cur, str& b, str& c) {
int ans = INF;
for (int ... | 2C++ | {
"input": [
"pozdravstaklenidodiri\nniste\ndobri\n",
"aaa\na\nb\n",
"abbbaaccca\nab\naca\n",
"brtakoktrosttttttttttosafasfkalsfkodfdasiofhadfhasdsajfdsafoasodsafahaihfdisoadspapsapiosapdsajdipsahdhasuirhaeuifhhfkjgosooooooooodafdfioottttafdsafaddfuiasdjfjasdo\nokat\ntako\n",
"aleksandrehteosidate... | 2CODEFORCES |
551_B. ZgukistringZ_428 | Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one.
GukiZ has strings a, b, and c. He wants to obtain string k by swapping some letters in a, so that k should contain as many non-overlapping substrings equal either to b or c as possible. Substring of string x... | from collections import defaultdict
def find_max_possible_substring(a, a_char_counts, char_counts):
max_count_of_sub = len(a)
for char, count in char_counts.items():
max_count_of_sub = min(max_count_of_sub, a_char_counts[char] // char_counts[char])
return max_count_of_sub
def get_optimal_count(... | 3Python3 | {
"input": [
"pozdravstaklenidodiri\nniste\ndobri\n",
"aaa\na\nb\n",
"abbbaaccca\nab\naca\n",
"brtakoktrosttttttttttosafasfkalsfkodfdasiofhadfhasdsajfdsafoasodsafahaihfdisoadspapsapiosapdsajdipsahdhasuirhaeuifhhfkjgosooooooooodafdfioottttafdsafaddfuiasdjfjasdo\nokat\ntako\n",
"aleksandrehteosidate... | 2CODEFORCES |
551_B. ZgukistringZ_429 | Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one.
GukiZ has strings a, b, and c. He wants to obtain string k by swapping some letters in a, so that k should contain as many non-overlapping substrings equal either to b or c as possible. Substring of string x... | import java.util.Scanner;
public class Main {
public static int cnta[]=new int[26];
public static int cntb[]=new int[26];
public static int cntc[]=new int[26];
public static StringBuilder res;
public static void main(String[] args) {
Scanner cin=new Scanner(System.in);
String a=ci... | 4JAVA | {
"input": [
"pozdravstaklenidodiri\nniste\ndobri\n",
"aaa\na\nb\n",
"abbbaaccca\nab\naca\n",
"brtakoktrosttttttttttosafasfkalsfkodfdasiofhadfhasdsajfdsafoasodsafahaihfdisoadspapsapiosapdsajdipsahdhasuirhaeuifhhfkjgosooooooooodafdfioottttafdsafaddfuiasdjfjasdo\nokat\ntako\n",
"aleksandrehteosidate... | 2CODEFORCES |
578_C. Weakness and Poorness_430 | You are given a sequence of n integers a1, a2, ..., an.
Determine a real number x such that the weakness of the sequence a1 - x, a2 - x, ..., an - x is as small as possible.
The weakness of a sequence is defined as the maximum value of the poorness over all segments (contiguous subsequences) of a sequence.
The poor... | n=input()
a=map(float,raw_input().split())
l,r=-22222.,22222.
for i in xrange(55):
w=x=p=0
y=-22222
z=22222
mid=(l+r)/2
for t in a:
p+=t-mid
y=max(y,p-w)
z=min(z,p-x)
w=min(p,w)
x=max(p,x)
if y+z<0:
r=mid
else:
l=mid
print max(y,-z)
| 1Python2 | {
"input": [
"10\n1 10 2 9 3 8 4 7 5 6\n",
"4\n1 2 3 4\n",
"3\n1 2 3\n",
"10\n-405 -230 252 -393 -390 -259 97 163 81 -129\n",
"3\n10000 -10000 10000\n",
"1\n-10000\n",
"20\n-16 -23 29 44 -40 -50 -41 34 -38 30 -12 28 -44 -49 15 50 -28 38 -2 0\n",
"10\n-405 -230 252 -393 -271 -259 97 163... | 2CODEFORCES |
578_C. Weakness and Poorness_431 | You are given a sequence of n integers a1, a2, ..., an.
Determine a real number x such that the weakness of the sequence a1 - x, a2 - x, ..., an - x is as small as possible.
The weakness of a sequence is defined as the maximum value of the poorness over all segments (contiguous subsequences) of a sequence.
The poor... | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int mod = 1e9 + 7;
const double inf = 1e18;
int n, a[N];
double l, r, b[N];
double first(double vl) {
for (int i = 1; i <= n; i++) b[i] = 1.0 * a[i] - vl;
double sum, minsum, ans = -inf;
sum = minsum = 0;
for (int i = 1; i <= n; i++) {
... | 2C++ | {
"input": [
"10\n1 10 2 9 3 8 4 7 5 6\n",
"4\n1 2 3 4\n",
"3\n1 2 3\n",
"10\n-405 -230 252 -393 -390 -259 97 163 81 -129\n",
"3\n10000 -10000 10000\n",
"1\n-10000\n",
"20\n-16 -23 29 44 -40 -50 -41 34 -38 30 -12 28 -44 -49 15 50 -28 38 -2 0\n",
"10\n-405 -230 252 -393 -271 -259 97 163... | 2CODEFORCES |
578_C. Weakness and Poorness_432 | You are given a sequence of n integers a1, a2, ..., an.
Determine a real number x such that the weakness of the sequence a1 - x, a2 - x, ..., an - x is as small as possible.
The weakness of a sequence is defined as the maximum value of the poorness over all segments (contiguous subsequences) of a sequence.
The poor... | """ Python 3 compatibility tools. """
from __future__ import division, print_function
import itertools
import sys
import os
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
input = raw_input
range = xrange
filter = itertools.ifilter
map = itertools.imap
zip = itertools.izip
def is_it_local():
... | 3Python3 | {
"input": [
"10\n1 10 2 9 3 8 4 7 5 6\n",
"4\n1 2 3 4\n",
"3\n1 2 3\n",
"10\n-405 -230 252 -393 -390 -259 97 163 81 -129\n",
"3\n10000 -10000 10000\n",
"1\n-10000\n",
"20\n-16 -23 29 44 -40 -50 -41 34 -38 30 -12 28 -44 -49 15 50 -28 38 -2 0\n",
"10\n-405 -230 252 -393 -271 -259 97 163... | 2CODEFORCES |
578_C. Weakness and Poorness_433 | You are given a sequence of n integers a1, a2, ..., an.
Determine a real number x such that the weakness of the sequence a1 - x, a2 - x, ..., an - x is as small as possible.
The weakness of a sequence is defined as the maximum value of the poorness over all segments (contiguous subsequences) of a sequence.
The poor... | import java.io.BufferedOutputStream;
import java.io.Closeable;
import java.io.DataInputStream;
import java.io.Flushable;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.InputMismatchException;
/**
* Built using ... | 4JAVA | {
"input": [
"10\n1 10 2 9 3 8 4 7 5 6\n",
"4\n1 2 3 4\n",
"3\n1 2 3\n",
"10\n-405 -230 252 -393 -390 -259 97 163 81 -129\n",
"3\n10000 -10000 10000\n",
"1\n-10000\n",
"20\n-16 -23 29 44 -40 -50 -41 34 -38 30 -12 28 -44 -49 15 50 -28 38 -2 0\n",
"10\n-405 -230 252 -393 -271 -259 97 163... | 2CODEFORCES |
5_A. Chat Server's Outgoing Traffic_434 | Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands:
* Include a perso... | import sys
people = set()
traffic = 0
for line in sys.stdin:
if line[0] == '+':
people.add(line[1:])
elif line[0] == '-':
people.remove(line[1:])
else:
msg = line[line.find(":")+1:-1]
traffic += len(msg) * len(people)
print traffic
| 1Python2 | {
"input": [
"+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate\n",
"+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate\n",
"+adabacaba\n-adabacaba\n+aca\naca:caba\n-aca\n+bacaba\n-bacaba\n+aba\n-aba\n+bad\n",
"+cab\n+abac\n-abac\n+baca\n",
"+8UjgAJ\n8UjgAJ:02hR7UBc1tqqfL\n-8Uj... | 2CODEFORCES |
5_A. Chat Server's Outgoing Traffic_435 | Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands:
* Include a perso... | #include <bits/stdc++.h>
using namespace std;
int main() {
int m = 0, a = 0;
for (int i = 0; i < 100; i++) {
string s;
getline(cin, s);
if (s[0] == '+') {
m++;
continue;
}
if (s[0] == '-') {
m--;
continue;
}
int c = 1;
int t = 0;
for (int j = 0; j < s.size... | 2C++ | {
"input": [
"+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate\n",
"+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate\n",
"+adabacaba\n-adabacaba\n+aca\naca:caba\n-aca\n+bacaba\n-bacaba\n+aba\n-aba\n+bad\n",
"+cab\n+abac\n-abac\n+baca\n",
"+8UjgAJ\n8UjgAJ:02hR7UBc1tqqfL\n-8Uj... | 2CODEFORCES |
5_A. Chat Server's Outgoing Traffic_436 | Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands:
* Include a perso... | import sys
n=0
ans=0
while True:
i=sys.stdin.readline().strip()
if len(i)<=1:
break
if i[0]=="+":
n+=1
elif i[0]=="-":
n-=1
else:
ans+=(len(i.split(':')[1]))*n
print(ans) | 3Python3 | {
"input": [
"+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate\n",
"+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate\n",
"+adabacaba\n-adabacaba\n+aca\naca:caba\n-aca\n+bacaba\n-bacaba\n+aba\n-aba\n+bad\n",
"+cab\n+abac\n-abac\n+baca\n",
"+8UjgAJ\n8UjgAJ:02hR7UBc1tqqfL\n-8Uj... | 2CODEFORCES |
5_A. Chat Server's Outgoing Traffic_437 | Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands:
* Include a perso... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String line = "";
... | 4JAVA | {
"input": [
"+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate\n",
"+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate\n",
"+adabacaba\n-adabacaba\n+aca\naca:caba\n-aca\n+bacaba\n-bacaba\n+aba\n-aba\n+bad\n",
"+cab\n+abac\n-abac\n+baca\n",
"+8UjgAJ\n8UjgAJ:02hR7UBc1tqqfL\n-8Uj... | 2CODEFORCES |
621_D. Rat Kwesh and Cheese_438 | Wet Shark asked Rat Kwesh to generate three positive real numbers x, y and z, from 0.1 to 200.0, inclusive. Wet Krash wants to impress Wet Shark, so all generated numbers will have exactly one digit after the decimal point.
Wet Shark knows Rat Kwesh will want a lot of cheese. So he will give the Rat an opportunity to ... | import sys
from decimal import *
input = raw_input().strip().split(' ')
x = Decimal(input[0])
y = Decimal(input[1])
z = Decimal(input[2])
getcontext().prec = 10
a = []
a.append((y ** z) * x.ln())
a.append((z ** y) * x.ln())
a.append(z * y * x.ln())
a.append(z * y * x.ln())
a.append((x ** z) * y.ln())
a.append((z **... | 1Python2 | {
"input": [
"1.1 3.4 2.5\n",
"1.9 1.8 1.7\n",
"2.0 2.0 2.0\n",
"1.0 200.0 200.0\n",
"0.2 0.1 0.6\n",
"1.9 3.0 4.1\n",
"51.8 51.8 7.1\n",
"113.9 125.2 88.8\n",
"1.9 4.8 3.9\n",
"2.2 148.1 138.0\n",
"1.0 200.0 1.0\n",
"1.7 4.5 4.2\n",
"0.2 0.6 0.3\n",
"200.0 200.... | 2CODEFORCES |
621_D. Rat Kwesh and Cheese_439 | Wet Shark asked Rat Kwesh to generate three positive real numbers x, y and z, from 0.1 to 200.0, inclusive. Wet Krash wants to impress Wet Shark, so all generated numbers will have exactly one digit after the decimal point.
Wet Shark knows Rat Kwesh will want a lot of cheese. So he will give the Rat an opportunity to ... | #include <bits/stdc++.h>
using namespace std;
class Solver621D {
public:
void run();
};
void Solver621D::run() {
vector<string> formulas = {"x^y^z", "x^z^y", "(x^y)^z", "y^x^z", "y^z^x",
"(y^x)^z", "z^x^y", "z^y^x", "(z^x)^y"};
vector<function<complex<double>(complex<double>, co... | 2C++ | {
"input": [
"1.1 3.4 2.5\n",
"1.9 1.8 1.7\n",
"2.0 2.0 2.0\n",
"1.0 200.0 200.0\n",
"0.2 0.1 0.6\n",
"1.9 3.0 4.1\n",
"51.8 51.8 7.1\n",
"113.9 125.2 88.8\n",
"1.9 4.8 3.9\n",
"2.2 148.1 138.0\n",
"1.0 200.0 1.0\n",
"1.7 4.5 4.2\n",
"0.2 0.6 0.3\n",
"200.0 200.... | 2CODEFORCES |
621_D. Rat Kwesh and Cheese_440 | Wet Shark asked Rat Kwesh to generate three positive real numbers x, y and z, from 0.1 to 200.0, inclusive. Wet Krash wants to impress Wet Shark, so all generated numbers will have exactly one digit after the decimal point.
Wet Shark knows Rat Kwesh will want a lot of cheese. So he will give the Rat an opportunity to ... | from decimal import *
getcontext().prec = 700
x, y, z = map(Decimal, input().split())
a = []
a.append((y**z * x.ln(), -1, 'x^y^z'))
a.append((z**y * x.ln(), -2, 'x^z^y'))
a.append((y *z * x.ln(), -3, '(x^y)^z'))
a.append((x**z * y.ln(), -5, 'y^x^z'))
a.append((z**x * y.ln(), -6, 'y^z^x'))
a.append((x *z * y.ln(), -7... | 3Python3 | {
"input": [
"1.1 3.4 2.5\n",
"1.9 1.8 1.7\n",
"2.0 2.0 2.0\n",
"1.0 200.0 200.0\n",
"0.2 0.1 0.6\n",
"1.9 3.0 4.1\n",
"51.8 51.8 7.1\n",
"113.9 125.2 88.8\n",
"1.9 4.8 3.9\n",
"2.2 148.1 138.0\n",
"1.0 200.0 1.0\n",
"1.7 4.5 4.2\n",
"0.2 0.6 0.3\n",
"200.0 200.... | 2CODEFORCES |
621_D. Rat Kwesh and Cheese_441 | Wet Shark asked Rat Kwesh to generate three positive real numbers x, y and z, from 0.1 to 200.0, inclusive. Wet Krash wants to impress Wet Shark, so all generated numbers will have exactly one digit after the decimal point.
Wet Shark knows Rat Kwesh will want a lot of cheese. So he will give the Rat an opportunity to ... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Writer;
import java.io.BufferedReader;
import java.util.Comp... | 4JAVA | {
"input": [
"1.1 3.4 2.5\n",
"1.9 1.8 1.7\n",
"2.0 2.0 2.0\n",
"1.0 200.0 200.0\n",
"0.2 0.1 0.6\n",
"1.9 3.0 4.1\n",
"51.8 51.8 7.1\n",
"113.9 125.2 88.8\n",
"1.9 4.8 3.9\n",
"2.2 148.1 138.0\n",
"1.0 200.0 1.0\n",
"1.7 4.5 4.2\n",
"0.2 0.6 0.3\n",
"200.0 200.... | 2CODEFORCES |
643_B. Bear and Two Paths_442 | Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities.
Bear Limak was once in a city a and he wanted to go to a city b. There was no direct connection so he decided to take a long walk, visiting ea... | n, k = (int(x) for x in raw_input().split())
if n == 4 or k <= n:
print "-1"
else:
a, b, c, d = (int(x) for x in raw_input().split())
l = [str(x) for x in range(1, n+1) if x not in [a, b, c, d]]
print "{} {} {} {} {}".format(a, c, " ".join(l), d, b)
print "{} {} {} {} {}".format(c, a, " ".join(l), b... | 1Python2 | {
"input": [
"1000 999\n10 20 30 40\n",
"7 11\n2 4 7 3\n",
"1000 1001\n217 636 713 516\n",
"1000 1998\n833 681 19 233\n",
"4 5\n1 3 4 2\n",
"6 7\n3 1 2 4\n",
"5 7\n4 3 2 1\n",
"55 56\n53 54 52 55\n",
"1000 1000\n89 983 751 38\n",
"1000 1002\n641 480 458 289\n",
"6 5\n3 2 5 ... | 2CODEFORCES |
643_B. Bear and Two Paths_443 | Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities.
Bear Limak was once in a city a and he wanted to go to a city b. There was no direct connection so he decided to take a long walk, visiting ea... | #include <bits/stdc++.h>
using namespace std;
template <typename T>
std::ostream &operator<<(std::ostream &out, vector<T> &v) {
for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
out << v[i] << " ";
out << "\n";
return out;
}
template <typename T>
std::ostream &operator<<(std::ostream &out, set<T> &... | 2C++ | {
"input": [
"1000 999\n10 20 30 40\n",
"7 11\n2 4 7 3\n",
"1000 1001\n217 636 713 516\n",
"1000 1998\n833 681 19 233\n",
"4 5\n1 3 4 2\n",
"6 7\n3 1 2 4\n",
"5 7\n4 3 2 1\n",
"55 56\n53 54 52 55\n",
"1000 1000\n89 983 751 38\n",
"1000 1002\n641 480 458 289\n",
"6 5\n3 2 5 ... | 2CODEFORCES |
643_B. Bear and Two Paths_444 | Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities.
Bear Limak was once in a city a and he wanted to go to a city b. There was no direct connection so he decided to take a long walk, visiting ea... | import io,os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
n, k = map(int, input().split())
a, b, c, d = map(int, input().split())
if k < n + 1 or n == 4:
print("-1")
exit(0)
l = [_ for _ in range(1, n + 1)]
l.remove(a)
l.remove(b)
l.remove(c)
l.remove(d)
print(a, end = ' ')
print(c, end = ' ')
fo... | 3Python3 | {
"input": [
"1000 999\n10 20 30 40\n",
"7 11\n2 4 7 3\n",
"1000 1001\n217 636 713 516\n",
"1000 1998\n833 681 19 233\n",
"4 5\n1 3 4 2\n",
"6 7\n3 1 2 4\n",
"5 7\n4 3 2 1\n",
"55 56\n53 54 52 55\n",
"1000 1000\n89 983 751 38\n",
"1000 1002\n641 480 458 289\n",
"6 5\n3 2 5 ... | 2CODEFORCES |
643_B. Bear and Two Paths_445 | Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities.
Bear Limak was once in a city a and he wanted to go to a city b. There was no direct connection so he decided to take a long walk, visiting ea... | import com.sun.org.apache.xml.internal.utils.StringComparable;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Main {
public static void main(String[] args) {
// Test.testing();
ConsoleIO io = new ConsoleIO();
new Ma... | 4JAVA | {
"input": [
"1000 999\n10 20 30 40\n",
"7 11\n2 4 7 3\n",
"1000 1001\n217 636 713 516\n",
"1000 1998\n833 681 19 233\n",
"4 5\n1 3 4 2\n",
"6 7\n3 1 2 4\n",
"5 7\n4 3 2 1\n",
"55 56\n53 54 52 55\n",
"1000 1000\n89 983 751 38\n",
"1000 1002\n641 480 458 289\n",
"6 5\n3 2 5 ... | 2CODEFORCES |
670_B. Game of Robots_446 | In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. Aft... | from math import pi
import sys
#from itertools
stream = sys.stdin
n, k = stream.readline().split()
n, k = int(n), int(k)
k = k-1
l = stream.readline().split()
l = [int(li) for li in l]
def f(i):
return ((i+1)*(i+2))/2
end = [f(i) for i in xrange(n)]
for i,ei in enumerate(end):
if ei<=k:
continue
... | 1Python2 | {
"input": [
"4 5\n10 4 18 3\n",
"2 2\n1 2\n",
"4 9\n5 1000000000 999999999 12\n",
"4 6\n5 1000000000 999999999 12\n",
"1 1\n4\n",
"3 5\n4 5 6\n",
"3 4\n4 5 6\n",
"3 6\n4 5 6\n",
"4 2\n5 1000000000 999999999 12\n",
"2 3\n6 7\n",
"2 1\n5 1\n",
"4 1\n5 1000000000 99999999... | 2CODEFORCES |
670_B. Game of Robots_447 | In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. Aft... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> vec(n), res;
for (auto &v : vec) {
cin >> v;
}
if (k == 1) {
return cout << vec[0], 0;
}
int l = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
l++;
if (l == k) {
... | 2C++ | {
"input": [
"4 5\n10 4 18 3\n",
"2 2\n1 2\n",
"4 9\n5 1000000000 999999999 12\n",
"4 6\n5 1000000000 999999999 12\n",
"1 1\n4\n",
"3 5\n4 5 6\n",
"3 4\n4 5 6\n",
"3 6\n4 5 6\n",
"4 2\n5 1000000000 999999999 12\n",
"2 3\n6 7\n",
"2 1\n5 1\n",
"4 1\n5 1000000000 99999999... | 2CODEFORCES |
670_B. Game of Robots_448 | In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. Aft... | n, k = input().split(' ')
n = int(n)
k = int(k)
d = input().split(' ')
i = 0
while True:
i += 1
p = int((i) * (i+1) / 2)
if k <= p :
print(d[k-(p-i)-1])
break | 3Python3 | {
"input": [
"4 5\n10 4 18 3\n",
"2 2\n1 2\n",
"4 9\n5 1000000000 999999999 12\n",
"4 6\n5 1000000000 999999999 12\n",
"1 1\n4\n",
"3 5\n4 5 6\n",
"3 4\n4 5 6\n",
"3 6\n4 5 6\n",
"4 2\n5 1000000000 999999999 12\n",
"2 3\n6 7\n",
"2 1\n5 1\n",
"4 1\n5 1000000000 99999999... | 2CODEFORCES |
670_B. Game of Robots_449 | In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier — an integer from 1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. Aft... |
import java.io.*;
import java.util.*;
public class NewClass {
static final int INF = Integer.MAX_VALUE;
static void mergeSort(int[] a, int p, int r) {
if (p < r) {
int q = (p + r) / 2;
mergeSort(a, p, q);
mergeSort(a, q + 1, r);
merge(a, p, q, r);
... | 4JAVA | {
"input": [
"4 5\n10 4 18 3\n",
"2 2\n1 2\n",
"4 9\n5 1000000000 999999999 12\n",
"4 6\n5 1000000000 999999999 12\n",
"1 1\n4\n",
"3 5\n4 5 6\n",
"3 4\n4 5 6\n",
"3 6\n4 5 6\n",
"4 2\n5 1000000000 999999999 12\n",
"2 3\n6 7\n",
"2 1\n5 1\n",
"4 1\n5 1000000000 99999999... | 2CODEFORCES |
691_D. Swaps in Permutation_450 | You are given a permutation of the numbers 1, 2, ..., n and m pairs of positions (aj, bj).
At each step you can choose a pair from the given positions and swap the numbers in that positions. What is the lexicographically maximal permutation one can get?
Let p and q be two permutations of the numbers 1, 2, ..., n. p i... | from sys import stdin
from collections import *
class graph:
# initialize graph
def __init__(self, gdict=None):
if gdict is None:
gdict = defaultdict(list)
self.gdict, self.edges, self.l = gdict, defaultdict(int), defaultdict(int)
# add edge
def addEdge(self, node1, node2,... | 1Python2 | {
"input": [
"9 6\n1 2 3 4 5 6 7 8 9\n1 4\n4 7\n2 5\n5 8\n3 6\n6 9\n",
"3 10\n2 3 1\n1 1\n3 3\n3 3\n3 2\n1 1\n2 2\n3 1\n1 3\n2 1\n3 3\n",
"7 20\n6 2 5 7 3 1 4\n7 7\n1 1\n2 2\n6 1\n4 4\n2 2\n2 2\n6 6\n3 5\n7 4\n1 6\n4 4\n6 1\n1 1\n3 3\n5 3\n3 5\n5 3\n2 2\n4 4\n",
"4 20\n4 2 3 1\n2 2\n1 4\n2 2\n1 1\n3 3... | 2CODEFORCES |
691_D. Swaps in Permutation_451 | You are given a permutation of the numbers 1, 2, ..., n and m pairs of positions (aj, bj).
At each step you can choose a pair from the given positions and swap the numbers in that positions. What is the lexicographically maximal permutation one can get?
Let p and q be two permutations of the numbers 1, 2, ..., n. p i... | #include <bits/stdc++.h>
using namespace std;
int SET(int n, int pos) { return n = n | (1 << pos); }
int RESET(int n, int pos) { return n = n & ~(1 << pos); }
int CHECK(int n, int pos) { return (bool)(n & (1 << pos)); }
int bigMod(int n, int power, int MOD) {
if (power == 0) return 1;
if (power % 2 == 0) {
int ... | 2C++ | {
"input": [
"9 6\n1 2 3 4 5 6 7 8 9\n1 4\n4 7\n2 5\n5 8\n3 6\n6 9\n",
"3 10\n2 3 1\n1 1\n3 3\n3 3\n3 2\n1 1\n2 2\n3 1\n1 3\n2 1\n3 3\n",
"7 20\n6 2 5 7 3 1 4\n7 7\n1 1\n2 2\n6 1\n4 4\n2 2\n2 2\n6 6\n3 5\n7 4\n1 6\n4 4\n6 1\n1 1\n3 3\n5 3\n3 5\n5 3\n2 2\n4 4\n",
"4 20\n4 2 3 1\n2 2\n1 4\n2 2\n1 1\n3 3... | 2CODEFORCES |
691_D. Swaps in Permutation_452 | You are given a permutation of the numbers 1, 2, ..., n and m pairs of positions (aj, bj).
At each step you can choose a pair from the given positions and swap the numbers in that positions. What is the lexicographically maximal permutation one can get?
Let p and q be two permutations of the numbers 1, 2, ..., n. p i... | # by the authority of GOD author: manhar singh sachdev #
import os,sys
from io import BytesIO, IOBase
def solve(n,p,path):
se, x, fin = [1] * (n + 1), 1, [0] * n
while x != len(se):
se[x], jj, curr, inde, vals = 0, 0, [x], [x - 1], [p[x - 1]]
while jj != len(curr):
zz = curr[... | 3Python3 | {
"input": [
"9 6\n1 2 3 4 5 6 7 8 9\n1 4\n4 7\n2 5\n5 8\n3 6\n6 9\n",
"3 10\n2 3 1\n1 1\n3 3\n3 3\n3 2\n1 1\n2 2\n3 1\n1 3\n2 1\n3 3\n",
"7 20\n6 2 5 7 3 1 4\n7 7\n1 1\n2 2\n6 1\n4 4\n2 2\n2 2\n6 6\n3 5\n7 4\n1 6\n4 4\n6 1\n1 1\n3 3\n5 3\n3 5\n5 3\n2 2\n4 4\n",
"4 20\n4 2 3 1\n2 2\n1 4\n2 2\n1 1\n3 3... | 2CODEFORCES |
691_D. Swaps in Permutation_453 | You are given a permutation of the numbers 1, 2, ..., n and m pairs of positions (aj, bj).
At each step you can choose a pair from the given positions and swap the numbers in that positions. What is the lexicographically maximal permutation one can get?
Let p and q be two permutations of the numbers 1, 2, ..., n. p i... |
import java.io.*;
import java.util.*;
import java.math.*;
public class D {
static boolean ONLINE_JUDGE = false;//change before submit
static Fast f = new Fast();
static PrintWriter out = new PrintWriter(System.out);
static boolean TEST_CASES = false;
static void solve(int TC_NO) ... | 4JAVA | {
"input": [
"9 6\n1 2 3 4 5 6 7 8 9\n1 4\n4 7\n2 5\n5 8\n3 6\n6 9\n",
"3 10\n2 3 1\n1 1\n3 3\n3 3\n3 2\n1 1\n2 2\n3 1\n1 3\n2 1\n3 3\n",
"7 20\n6 2 5 7 3 1 4\n7 7\n1 1\n2 2\n6 1\n4 4\n2 2\n2 2\n6 6\n3 5\n7 4\n1 6\n4 4\n6 1\n1 1\n3 3\n5 3\n3 5\n5 3\n2 2\n4 4\n",
"4 20\n4 2 3 1\n2 2\n1 4\n2 2\n1 1\n3 3... | 2CODEFORCES |
716_D. Complete The Graph_454 | ZS the Coder has drawn an undirected graph of n vertices numbered from 0 to n - 1 and m edges between them. Each edge of the graph is weighted, each weight is a positive integer.
The next day, ZS the Coder realized that some of the weights were erased! So he wants to reassign positive integer weight to each of the edg... | #include <bits/stdc++.h>
using namespace std;
int break_point() {
char c;
while ((c = getchar()) != '\n')
;
return 0;
}
template <typename T>
void read_integer(T &r) {
bool sign = 0;
r = 0;
char c;
while (1) {
c = getchar();
if (c == '-') {
sign = 1;
break;
}
if (c != ' ' &... | 2C++ | {
"input": [
"5 5 13 0 4\n0 1 5\n2 1 2\n3 2 3\n1 4 0\n4 3 4\n",
"2 1 123456789 0 1\n0 1 0\n",
"2 1 999999999 1 0\n0 1 1000000000\n",
"7 9 999999999 0 3\n0 1 0\n1 2 0\n2 3 0\n0 4 1\n4 1 1\n1 5 499999999\n5 2 499999999\n2 6 1\n6 3 1\n",
"7 9 320 0 3\n0 1 0\n1 2 0\n2 3 0\n0 4 1\n4 1 1\n1 5 100\n5 2 1... | 2CODEFORCES |
716_D. Complete The Graph_455 | ZS the Coder has drawn an undirected graph of n vertices numbered from 0 to n - 1 and m edges between them. Each edge of the graph is weighted, each weight is a positive integer.
The next day, ZS the Coder realized that some of the weights were erased! So he wants to reassign positive integer weight to each of the edg... | import heapq
from collections import defaultdict
class Graph:
def __init__(self, n):
self.nodes = set(range(n))
self.edges = defaultdict(list)
self.distances = {}
def add_edge(self, from_node, to_node, distance):
self.edges[from_node].append(to_node)
self.edges[to_node... | 3Python3 | {
"input": [
"5 5 13 0 4\n0 1 5\n2 1 2\n3 2 3\n1 4 0\n4 3 4\n",
"2 1 123456789 0 1\n0 1 0\n",
"2 1 999999999 1 0\n0 1 1000000000\n",
"7 9 999999999 0 3\n0 1 0\n1 2 0\n2 3 0\n0 4 1\n4 1 1\n1 5 499999999\n5 2 499999999\n2 6 1\n6 3 1\n",
"7 9 320 0 3\n0 1 0\n1 2 0\n2 3 0\n0 4 1\n4 1 1\n1 5 100\n5 2 1... | 2CODEFORCES |
716_D. Complete The Graph_456 | ZS the Coder has drawn an undirected graph of n vertices numbered from 0 to n - 1 and m edges between them. Each edge of the graph is weighted, each weight is a positive integer.
The next day, ZS the Coder realized that some of the weights were erased! So he wants to reassign positive integer weight to each of the edg... | import java.io.*;
import java.util.*;
public class CF716D {
static class E {
int u, v, w;
E(int u, int v, int w) {
this.u = u;
this.v = v;
this.w = w;
}
}
static class V {
ArrayList<E> list = new ArrayList<>();
int i, d;
V(int i) {
this.i = i;
}
}
static void setw(ArrayList<E> list0, int... | 4JAVA | {
"input": [
"5 5 13 0 4\n0 1 5\n2 1 2\n3 2 3\n1 4 0\n4 3 4\n",
"2 1 123456789 0 1\n0 1 0\n",
"2 1 999999999 1 0\n0 1 1000000000\n",
"7 9 999999999 0 3\n0 1 0\n1 2 0\n2 3 0\n0 4 1\n4 1 1\n1 5 499999999\n5 2 499999999\n2 6 1\n6 3 1\n",
"7 9 320 0 3\n0 1 0\n1 2 0\n2 3 0\n0 4 1\n4 1 1\n1 5 100\n5 2 1... | 2CODEFORCES |
737_A. Road to Cinema_457 | Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's introduce a coordinate system so that the car rental service is at the point 0, and the cinema is at the point s.
... | from sys import stdin
def fast2():
import os, sys, atexit
from cStringIO import StringIO as BytesIO
# range = xrange
sys.stdout = BytesIO()
atexit.register(lambda: os.write(1, sys.stdout.getvalue()))
return BytesIO(os.read(0, os.fstat(0).st_size)).readline
input = fast2()
rints = lambda: [in... | 1Python2 | {
"input": [
"3 1 8 10\n10 8\n5 7\n11 9\n3\n",
"2 2 10 18\n10 4\n20 6\n5 3\n",
"1 1 2 2\n1000000000 1000000000\n1\n",
"1 1 1000000000 1000000000\n100 1000000000\n1\n",
"1 1 10 18\n5 6\n5\n",
"2 1 1000000000 2000000000\n111 999999999\n101 999999998\n1\n",
"4 13 400 600\n13 30\n1 19\n1 160\n... | 2CODEFORCES |
737_A. Road to Cinema_458 | Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's introduce a coordinate system so that the car rental service is at the point 0, and the cinema is at the point s.
... | #include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T abs(T t) {
return t < 0 ? -t : t;
}
const long long modn = 1000000007;
inline long long mod(long long x) { return x % modn; }
const int MAXN = 212345;
int n, m;
long long k;
pair<long long, long long> s[MAXN];
long long p[MAXN], t;
long long... | 2C++ | {
"input": [
"3 1 8 10\n10 8\n5 7\n11 9\n3\n",
"2 2 10 18\n10 4\n20 6\n5 3\n",
"1 1 2 2\n1000000000 1000000000\n1\n",
"1 1 1000000000 1000000000\n100 1000000000\n1\n",
"1 1 10 18\n5 6\n5\n",
"2 1 1000000000 2000000000\n111 999999999\n101 999999998\n1\n",
"4 13 400 600\n13 30\n1 19\n1 160\n... | 2CODEFORCES |
737_A. Road to Cinema_459 | Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's introduce a coordinate system so that the car rental service is at the point 0, and the cinema is at the point s.
... | # Question B. Road to Cinema
import sys
def roadToCinema(V, S, T, stations): # O(M)
"""
V : volume of fuel tank
S : total distance
T : time limit
stations: fuel stations' locations
rtype : boolean, whether this aircraft can travel within the time limit
"""
m = len(s... | 3Python3 | {
"input": [
"3 1 8 10\n10 8\n5 7\n11 9\n3\n",
"2 2 10 18\n10 4\n20 6\n5 3\n",
"1 1 2 2\n1000000000 1000000000\n1\n",
"1 1 1000000000 1000000000\n100 1000000000\n1\n",
"1 1 10 18\n5 6\n5\n",
"2 1 1000000000 2000000000\n111 999999999\n101 999999998\n1\n",
"4 13 400 600\n13 30\n1 19\n1 160\n... | 2CODEFORCES |
737_A. Road to Cinema_460 | Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's introduce a coordinate system so that the car rental service is at the point 0, and the cinema is at the point s.
... | import java.awt.*;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.List;
import static java.lang.Math.max;
import static java.lang.Math.min;
public class A implements Runnable{
// SOLUTION!!!
// HACK ME PLEASE IF YOU CAN!!!
// PLEASE!!!
... | 4JAVA | {
"input": [
"3 1 8 10\n10 8\n5 7\n11 9\n3\n",
"2 2 10 18\n10 4\n20 6\n5 3\n",
"1 1 2 2\n1000000000 1000000000\n1\n",
"1 1 1000000000 1000000000\n100 1000000000\n1\n",
"1 1 10 18\n5 6\n5\n",
"2 1 1000000000 2000000000\n111 999999999\n101 999999998\n1\n",
"4 13 400 600\n13 30\n1 19\n1 160\n... | 2CODEFORCES |
760_F. Bacterial Melee_461 | Julia is conducting an experiment in her lab. She placed several luminescent bacterial colonies in a horizontal testtube. Different types of bacteria can be distinguished by the color of light they emit. Julia marks types of bacteria with small Latin letters "a", ..., "z".
The testtube is divided into n consecutive re... | #include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
int inf = 2e9;
long long INF = 8e18;
int fre[26][5001];
int ts[5001];
int ff[5001];
int fac[5001];
int nf[5001];
string s;
long long fe(long long x, int e) {
long long r = 1;
while (e) {
if (e & 1) r = (r * x) % MOD;
x = (x * x) % MOD;
... | 2C++ | {
"input": [
"7\nabacaba\n",
"3\naaa\n",
"2\nab\n",
"4\nbabb\n",
"15\ntxxtxttxxttxtxx\n",
"3\nmyw\n",
"127\nxixtxixnxixtxixlxixtxixnxixtxixoxixtxixnxixtxixlxixtxixnxixtxixhxixtxixnxixtxixlxixtxixnxixtxixoxixtxixnxixtxixlxixtxixnxixtxix\n",
"1\na\n",
"10\nisssisssss\n",
"2\nff\n... | 2CODEFORCES |
760_F. Bacterial Melee_462 | Julia is conducting an experiment in her lab. She placed several luminescent bacterial colonies in a horizontal testtube. Different types of bacteria can be distinguished by the color of light they emit. Julia marks types of bacteria with small Latin letters "a", ..., "z".
The testtube is divided into n consecutive re... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
/**
* @author Don Li
*/
public class BacterialMelee {
int MOD = (int) (1e9 + 7);
void solve() {
int n = in.nextInt();
char[] s =... | 4JAVA | {
"input": [
"7\nabacaba\n",
"3\naaa\n",
"2\nab\n",
"4\nbabb\n",
"15\ntxxtxttxxttxtxx\n",
"3\nmyw\n",
"127\nxixtxixnxixtxixlxixtxixnxixtxixoxixtxixnxixtxixlxixtxixnxixtxixhxixtxixnxixtxixlxixtxixnxixtxixoxixtxixnxixtxixlxixtxixnxixtxix\n",
"1\na\n",
"10\nisssisssss\n",
"2\nff\n... | 2CODEFORCES |
784_B. Kids' Riddle_463 | Programmers' kids solve this riddle in 5-10 minutes. How fast can you do it?
Input
The input contains a single integer n (0 ≤ n ≤ 2000000000).
Output
Output a single integer.
Examples
Input
11
Output
2
Input
14
Output
0
Input
61441
Output
2
Input
571576
Output
10
Input
2128506
Output
3 | st = "0123456789ABCDEF"
p = "1000101021120100"
a = int(raw_input())
if a == 0:
print 1
else:
ans = 0
while a > 0:
q = a % 16
ans += int(p[q])
a /= 16
print ans
| 1Python2 | {
"input": [
"14\n",
"2128506\n",
"11\n",
"571576\n",
"61441\n",
"143165576\n",
"1919020031\n",
"1204252996\n",
"210637432\n",
"724264821\n",
"1741\n",
"619489590\n",
"1199537418\n",
"1075765759\n",
"747976826\n",
"638486017\n",
"58438190\n",
"12... | 2CODEFORCES |
784_B. Kids' Riddle_464 | Programmers' kids solve this riddle in 5-10 minutes. How fast can you do it?
Input
The input contains a single integer n (0 ≤ n ≤ 2000000000).
Output
Output a single integer.
Examples
Input
11
Output
2
Input
14
Output
0
Input
61441
Output
2
Input
571576
Output
10
Input
2128506
Output
3 | #include <bits/stdc++.h>
using namespace std;
int s[114514] = {1, 0, 0, 0, 1, 0, 1, 0, 2, 1, 1, 2, 0, 1, 0, 0};
int main() {
int n, m = 0;
scanf("%d", &n);
if (n == 0) m = 1;
while (n != 0) m += s[n % 16], n /= 16;
printf("%d", m);
}
| 2C++ | {
"input": [
"14\n",
"2128506\n",
"11\n",
"571576\n",
"61441\n",
"143165576\n",
"1919020031\n",
"1204252996\n",
"210637432\n",
"724264821\n",
"1741\n",
"619489590\n",
"1199537418\n",
"1075765759\n",
"747976826\n",
"638486017\n",
"58438190\n",
"12... | 2CODEFORCES |
784_B. Kids' Riddle_465 | Programmers' kids solve this riddle in 5-10 minutes. How fast can you do it?
Input
The input contains a single integer n (0 ≤ n ≤ 2000000000).
Output
Output a single integer.
Examples
Input
11
Output
2
Input
14
Output
0
Input
61441
Output
2
Input
571576
Output
10
Input
2128506
Output
3 | a=str(hex(int(input())))
b=0
for i in range(2,len(a)):
if a[i]=="0" or a[i]=="4" or a[i]=="6" or a[i]=="9" or a[i]=="a" or a[i]=="d":
b+=1
elif a[i]=="8" or a[i]=="b":
b+=2
print(b)
| 3Python3 | {
"input": [
"14\n",
"2128506\n",
"11\n",
"571576\n",
"61441\n",
"143165576\n",
"1919020031\n",
"1204252996\n",
"210637432\n",
"724264821\n",
"1741\n",
"619489590\n",
"1199537418\n",
"1075765759\n",
"747976826\n",
"638486017\n",
"58438190\n",
"12... | 2CODEFORCES |
784_B. Kids' Riddle_466 | Programmers' kids solve this riddle in 5-10 minutes. How fast can you do it?
Input
The input contains a single integer n (0 ≤ n ≤ 2000000000).
Output
Output a single integer.
Examples
Input
11
Output
2
Input
14
Output
0
Input
61441
Output
2
Input
571576
Output
10
Input
2128506
Output
3 |
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import static java.lang.System.in;
... | 4JAVA | {
"input": [
"14\n",
"2128506\n",
"11\n",
"571576\n",
"61441\n",
"143165576\n",
"1919020031\n",
"1204252996\n",
"210637432\n",
"724264821\n",
"1741\n",
"619489590\n",
"1199537418\n",
"1075765759\n",
"747976826\n",
"638486017\n",
"58438190\n",
"12... | 2CODEFORCES |
805_A. Fake NP_467 | Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times.
Solve... | l,r= map(int,raw_input().split())
if r-l<10:
three = 0
two = 0
for i in range (l,r+1):
if i%3 == 0:
three += 1
if i%2 == 0:
two += 1
if three==0 and two==0:
print (l)
exit()
if three>=two:
print (3)
else :
print (2)
else:
print (2) | 1Python2 | {
"input": [
"19 29\n",
"3 6\n",
"252662256 252662260\n",
"141650963 141650963\n",
"4 12\n",
"1002523 1002523\n",
"93 95\n",
"331900277 331900277\n",
"56 92\n",
"10 100\n",
"3 1000000000\n",
"13 13\n",
"2 879190747\n",
"999900001 1000000000\n",
"820844234 89... | 2CODEFORCES |
805_A. Fake NP_468 | Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times.
Solve... | #include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, n, m, k, q, l, r;
string s;
int main() {
ios::sync_with_stdio(false);
cin >> l >> r;
a = r - l;
if (r - l < 100) {
map<long long, long long> mp;
map<long long, long long>::iterator it;
for (int i = l; i <= r; i++) {
a = i;
... | 2C++ | {
"input": [
"19 29\n",
"3 6\n",
"252662256 252662260\n",
"141650963 141650963\n",
"4 12\n",
"1002523 1002523\n",
"93 95\n",
"331900277 331900277\n",
"56 92\n",
"10 100\n",
"3 1000000000\n",
"13 13\n",
"2 879190747\n",
"999900001 1000000000\n",
"820844234 89... | 2CODEFORCES |
805_A. Fake NP_469 | Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times.
Solve... | n, k=map(int ,input().split())
if n==k and n%2==1:
print(n)
else:
print(2) | 3Python3 | {
"input": [
"19 29\n",
"3 6\n",
"252662256 252662260\n",
"141650963 141650963\n",
"4 12\n",
"1002523 1002523\n",
"93 95\n",
"331900277 331900277\n",
"56 92\n",
"10 100\n",
"3 1000000000\n",
"13 13\n",
"2 879190747\n",
"999900001 1000000000\n",
"820844234 89... | 2CODEFORCES |
805_A. Fake NP_470 | Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times.
Solve... | import java.util.Scanner;
public class test {
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
int l = s.nextInt();
int r = s.nextInt();
if(l == r) System.out.println(l);
else System.out.println(2);
}
} | 4JAVA | {
"input": [
"19 29\n",
"3 6\n",
"252662256 252662260\n",
"141650963 141650963\n",
"4 12\n",
"1002523 1002523\n",
"93 95\n",
"331900277 331900277\n",
"56 92\n",
"10 100\n",
"3 1000000000\n",
"13 13\n",
"2 879190747\n",
"999900001 1000000000\n",
"820844234 89... | 2CODEFORCES |
830_A. Office Keys_471 | There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the mi... | n,k,p=map(int,raw_input().split())
a=map(int,raw_input().split())
b=map(int,raw_input().split())
a.sort()
b.sort()
i=0
ab=2000000000
while i+n<=k:
ba=-1
for j in range(n):
c=abs(a[j]-b[i+j])+abs(b[i+j]-p)
ba=max(c,ba)
ab=min(ab,ba)
i+=1
print ab | 1Python2 | {
"input": [
"1 2 10\n11\n15 7\n",
"2 4 50\n20 100\n60 10 40 80\n",
"1 1 10\n10\n10\n",
"2 2 10\n9 11\n11 8\n",
"1 1 1000000000\n1000000000\n1\n",
"1 1 50\n1\n1000000000\n",
"2 2 5\n2 3\n4 6\n",
"5 20 1\n314 316 328 323 321\n30 61 11 83 19 63 97 87 14 79 43 57 75 48 47 95 41 27 8 88\n"... | 2CODEFORCES |
830_A. Office Keys_472 | There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the mi... | #include <bits/stdc++.h>
using namespace std;
using i64 = long long;
class A830 {
private:
i64 cost(i64 a, i64 b, i64 c) { return abs(a - b) + abs(b - c); }
public:
void solve(istream& in, ostream& out) {
int n, k, p;
in >> n >> k >> p;
vector<int> a(n), b(k);
for (int i = 0; i < n; ++i) {
... | 2C++ | {
"input": [
"1 2 10\n11\n15 7\n",
"2 4 50\n20 100\n60 10 40 80\n",
"1 1 10\n10\n10\n",
"2 2 10\n9 11\n11 8\n",
"1 1 1000000000\n1000000000\n1\n",
"1 1 50\n1\n1000000000\n",
"2 2 5\n2 3\n4 6\n",
"5 20 1\n314 316 328 323 321\n30 61 11 83 19 63 97 87 14 79 43 57 75 48 47 95 41 27 8 88\n"... | 2CODEFORCES |
830_A. Office Keys_473 | There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the mi... | o=lambda:[int(f)for f in input().split()]
n,k,p=o()
a=sorted(o())
b=sorted(o())
print(min(max(abs(b[i + d] - a[i]) + abs(b[i + d] - p) for i in range(n)) for d in range(k - n + 1)))
| 3Python3 | {
"input": [
"1 2 10\n11\n15 7\n",
"2 4 50\n20 100\n60 10 40 80\n",
"1 1 10\n10\n10\n",
"2 2 10\n9 11\n11 8\n",
"1 1 1000000000\n1000000000\n1\n",
"1 1 50\n1\n1000000000\n",
"2 2 5\n2 3\n4 6\n",
"5 20 1\n314 316 328 323 321\n30 61 11 83 19 63 97 87 14 79 43 57 75 48 47 95 41 27 8 88\n"... | 2CODEFORCES |
830_A. Office Keys_474 | There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the mi... | import java.io.*;
import java.util.*;
import java.math.*;
public class D{
static Scanner in;
static PrintWriter out;
static int n, k, posOffice;
static int[] posP, posK;
public static void main(String args[]) throws Exception{
in = new Scanner(System.in);
out = new PrintWriter(System.out);
input... | 4JAVA | {
"input": [
"1 2 10\n11\n15 7\n",
"2 4 50\n20 100\n60 10 40 80\n",
"1 1 10\n10\n10\n",
"2 2 10\n9 11\n11 8\n",
"1 1 1000000000\n1000000000\n1\n",
"1 1 50\n1\n1000000000\n",
"2 2 5\n2 3\n4 6\n",
"5 20 1\n314 316 328 323 321\n30 61 11 83 19 63 97 87 14 79 43 57 75 48 47 95 41 27 8 88\n"... | 2CODEFORCES |
851_B. Arpa and an exam about geometry_475 | Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points a, b, c.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c.... | str=raw_input()
a=str.split()
def len(x1,y1,x2,y2):
return (y2 - y1) * (y2 - y1) + (x2 - x1) * (x2 - x1)
for x in xrange(0,6):
a[x]=int(a[x])
if(len(a[0],a[1],a[2],a[3])==len(a[2],a[3],a[4],a[5]) and ((a[5]-a[3])*(a[2]-a[0])!=(a[4]-a[2])*(a[3]-a[1]))):
print 'Yes'
else:
print 'No'
| 1Python2 | {
"input": [
"0 1 1 1 1 0\n",
"1 1 0 0 1000 1000\n",
"264193194 -448876521 736684426 -633906160 -328597212 -47935734\n",
"-357531221 381512519 -761132895 -224448284 328888775 -237692564\n",
"-1000000000 -1000000000 0 0 1000000000 999999999\n",
"0 2 4 5 4 0\n",
"0 0 2 45 0 90\n",
"-1000... | 2CODEFORCES |
851_B. Arpa and an exam about geometry_476 | Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points a, b, c.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c.... | #include <bits/stdc++.h>
using namespace std;
long long ax, ay, bx, by, cx, cy;
bool valid() {
return (ax * (by - cy)) + (bx * (cy - ay)) + (cx * (ay - by)) != 0LL;
}
int main() {
while (scanf("%lld %lld %lld %lld %lld %lld", &ax, &ay, &bx, &by, &cx, &cy) ==
6) {
long long ab = ((ax - bx) * (ax - bx)) ... | 2C++ | {
"input": [
"0 1 1 1 1 0\n",
"1 1 0 0 1000 1000\n",
"264193194 -448876521 736684426 -633906160 -328597212 -47935734\n",
"-357531221 381512519 -761132895 -224448284 328888775 -237692564\n",
"-1000000000 -1000000000 0 0 1000000000 999999999\n",
"0 2 4 5 4 0\n",
"0 0 2 45 0 90\n",
"-1000... | 2CODEFORCES |
851_B. Arpa and an exam about geometry_477 | Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points a, b, c.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c.... | ax,ay,bx,by,cx,cy=map(int,input().split())
ab=(ax-bx)**2+(ay-by)**2
bc=(bx-cx)**2+(by-cy)**2
if ab==bc and (ay-by)*(bx-cx)!=(by-cy)*(ax-bx):
print("Yes")
else:
print("No")
| 3Python3 | {
"input": [
"0 1 1 1 1 0\n",
"1 1 0 0 1000 1000\n",
"264193194 -448876521 736684426 -633906160 -328597212 -47935734\n",
"-357531221 381512519 -761132895 -224448284 328888775 -237692564\n",
"-1000000000 -1000000000 0 0 1000000000 999999999\n",
"0 2 4 5 4 0\n",
"0 0 2 45 0 90\n",
"-1000... | 2CODEFORCES |
851_B. Arpa and an exam about geometry_478 | Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points a, b, c.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c.... | import java.util.*;
public class MexicanWave {
void solve()
{
Scanner in = new Scanner(System.in);
long ax = in.nextLong();
long ay = in.nextLong();
long bx = in.nextLong();
long by = in.nextLong();
long cx = in.nextLong();
long cy = in.nextLong();
if ((ax * (by -... | 4JAVA | {
"input": [
"0 1 1 1 1 0\n",
"1 1 0 0 1000 1000\n",
"264193194 -448876521 736684426 -633906160 -328597212 -47935734\n",
"-357531221 381512519 -761132895 -224448284 328888775 -237692564\n",
"-1000000000 -1000000000 0 0 1000000000 999999999\n",
"0 2 4 5 4 0\n",
"0 0 2 45 0 90\n",
"-1000... | 2CODEFORCES |
875_D. High Cry_479 | Disclaimer: there are lots of untranslateable puns in the Russian version of the statement, so there is one more reason for you to learn Russian :)
Rick and Morty like to go to the ridge High Cry for crying loudly — there is an extraordinary echo. Recently they discovered an interesting acoustic characteristic of this... | import sys
range = xrange
input = raw_input
n = int(input())
A = [int(x) for x in input().split()]
L = [0]*n
R = [0]*n
stack = []
for i in range(n):
while stack and A[stack[-1]] < A[i]:
stack.pop()
L[i] = stack[-1] if stack else -1
stack.append(i)
stack = []
for i in reversed(range(n)):
whil... | 1Python2 | {
"input": [
"5\n3 2 1 6 5\n",
"4\n3 3 3 3\n",
"228\n1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 63 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 127 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 63 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 ... | 2CODEFORCES |
875_D. High Cry_480 | Disclaimer: there are lots of untranslateable puns in the Russian version of the statement, so there is one more reason for you to learn Russian :)
Rick and Morty like to go to the ridge High Cry for crying loudly — there is an extraordinary echo. Recently they discovered an interesting acoustic characteristic of this... | #include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
stack<pair<long long, long long> > q;
long long n, a[N], go[N];
struct cell {
long long max_l, max_r, or_l, or_r;
};
bool d[N][35];
cell b[N];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (long... | 2C++ | {
"input": [
"5\n3 2 1 6 5\n",
"4\n3 3 3 3\n",
"228\n1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 63 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 127 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 63 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 ... | 2CODEFORCES |
875_D. High Cry_481 | Disclaimer: there are lots of untranslateable puns in the Russian version of the statement, so there is one more reason for you to learn Russian :)
Rick and Morty like to go to the ridge High Cry for crying loudly — there is an extraordinary echo. Recently they discovered an interesting acoustic characteristic of this... | import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class D {
public static void main(String[] args) throws Exception {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
// Scanner scan = new Scanner(System.in);
PrintWriter out = new P... | 4JAVA | {
"input": [
"5\n3 2 1 6 5\n",
"4\n3 3 3 3\n",
"228\n1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 63 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 127 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 63 1 3 1 7 1 3 1 15 1 3 1 7 1 3 1 31 1 3 1 7 1 3 1 ... | 2CODEFORCES |
89_C. Chip Play_482 | Let's consider the following game. We have a rectangular field n × m in size. Some squares of the field contain chips.
Each chip has an arrow painted on it. Thus, each chip on the field points in one of the following directions: up, down, left or right.
The player may choose a chip and make a move with it.
The move ... | #include <bits/stdc++.h>
using namespace std;
int m, n, mn, ans, cnt, p[5005][4];
char c[5005];
int v[5005], vw;
int f(char c) {
switch (c) {
case 'L':
return 0;
case 'R':
return 1;
case 'U':
return 2;
case 'D':
return 3;
}
}
int solve(int x) {
for (int i = 0; i < mn; ++i) ... | 2C++ | {
"input": [
"4 4\nDRLD\nU.UL\n.UUR\nRDDL\n",
"3 5\n.D...\nRRRLL\n.U...\n",
"10 10\n.L.....R..\n.........U\n..D....D..\n.R......L.\n....L.....\n.........D\n......U...\nD....R....\n...U......\n........L.\n",
"5 5\nDD..D\n.....\nLU...\nU...U\n.UL.U\n",
"1 1\nU\n",
"5 5\nUD..L\nRRD..\n..RDD\nUUL.... | 2CODEFORCES |
89_C. Chip Play_483 | Let's consider the following game. We have a rectangular field n × m in size. Some squares of the field contain chips.
Each chip has an arrow painted on it. Thus, each chip on the field points in one of the following directions: up, down, left or right.
The player may choose a chip and make a move with it.
The move ... | //package round74;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
public class C2 {
Scanner in;
PrintWriter out;
String INPUT = "3 5\r\n" +
".D...\r\n" +
"RRRLL\r\n" +
".U...";
void solve()
{
int n = ni();
int m = ni();
char[][] b = new char[n][m];
for(int i = 0;... | 4JAVA | {
"input": [
"4 4\nDRLD\nU.UL\n.UUR\nRDDL\n",
"3 5\n.D...\nRRRLL\n.U...\n",
"10 10\n.L.....R..\n.........U\n..D....D..\n.R......L.\n....L.....\n.........D\n......U...\nD....R....\n...U......\n........L.\n",
"5 5\nDD..D\n.....\nLU...\nU...U\n.UL.U\n",
"1 1\nU\n",
"5 5\nUD..L\nRRD..\n..RDD\nUUL.... | 2CODEFORCES |
920_E. Connected Components?_484 | You are given an undirected graph consisting of n vertices and <image> edges. Instead of giving you the edges that exist in the graph, we give you m unordered pairs (x, y) such that there is no edge between x and y, and if some pair of vertices is not listed in the input, then there is an edge between these vertices.
... | def main():
inp = readnumbers()
ii = 0
n = inp[ii]
ii += 1
m = inp[ii]
ii += 1
degree = [n-1]*n
antiedges = set()
for _ in range(m):
u = inp[ii] - 1
ii += 1
v = inp[ii] - 1
ii += 1
degree[u] -= 1
degree[v] -= 1
antiedges.... | 1Python2 | {
"input": [
"5 5\n1 2\n3 4\n3 2\n4 2\n2 5\n",
"7 20\n4 6\n6 7\n4 5\n1 2\n2 4\n1 7\n3 5\n2 1\n6 2\n6 1\n7 3\n3 2\n3 6\n3 1\n3 4\n2 5\n1 6\n7 4\n6 3\n7 5\n",
"8 23\n1 2\n1 4\n1 6\n1 8\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n3 4\n3 5\n3 6\n3 7\n3 8\n4 5\n4 6\n4 7\n5 6\n5 7\n5 8\n6 8\n7 8\n",
"4 4\n2 1\n3 1\n1 4\... | 2CODEFORCES |
920_E. Connected Components?_485 | You are given an undirected graph consisting of n vertices and <image> edges. Instead of giving you the edges that exist in the graph, we give you m unordered pairs (x, y) such that there is no edge between x and y, and if some pair of vertices is not listed in the input, then there is an edge between these vertices.
... | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
set<int> g[N], disconn;
vector<int> ans_vec, temp, temper;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
int x, y;
while (m--) {
cin >> x >> y;
g[x].insert(y);
g[y].insert(x);
}
vect... | 2C++ | {
"input": [
"5 5\n1 2\n3 4\n3 2\n4 2\n2 5\n",
"7 20\n4 6\n6 7\n4 5\n1 2\n2 4\n1 7\n3 5\n2 1\n6 2\n6 1\n7 3\n3 2\n3 6\n3 1\n3 4\n2 5\n1 6\n7 4\n6 3\n7 5\n",
"8 23\n1 2\n1 4\n1 6\n1 8\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n3 4\n3 5\n3 6\n3 7\n3 8\n4 5\n4 6\n4 7\n5 6\n5 7\n5 8\n6 8\n7 8\n",
"4 4\n2 1\n3 1\n1 4\... | 2CODEFORCES |
920_E. Connected Components?_486 | You are given an undirected graph consisting of n vertices and <image> edges. Instead of giving you the edges that exist in the graph, we give you m unordered pairs (x, y) such that there is no edge between x and y, and if some pair of vertices is not listed in the input, then there is an edge between these vertices.
... | n,m=map(int,input().split())
non=[{i} for i in range(n)]
for i in range(m):
u,v=map(int,input().split())
u,v=u-1,v-1
non[u].add(v)
non[v].add(u)
vertex=set(range(n))
ans=[]
while(vertex):
a=next(iter(vertex))
vertex.remove(a)
stk=[a]
cou=1
while(stk):
v=stk.pop()
s=ve... | 3Python3 | {
"input": [
"5 5\n1 2\n3 4\n3 2\n4 2\n2 5\n",
"7 20\n4 6\n6 7\n4 5\n1 2\n2 4\n1 7\n3 5\n2 1\n6 2\n6 1\n7 3\n3 2\n3 6\n3 1\n3 4\n2 5\n1 6\n7 4\n6 3\n7 5\n",
"8 23\n1 2\n1 4\n1 6\n1 8\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n3 4\n3 5\n3 6\n3 7\n3 8\n4 5\n4 6\n4 7\n5 6\n5 7\n5 8\n6 8\n7 8\n",
"4 4\n2 1\n3 1\n1 4\... | 2CODEFORCES |
920_E. Connected Components?_487 | You are given an undirected graph consisting of n vertices and <image> edges. Instead of giving you the edges that exist in the graph, we give you m unordered pairs (x, y) such that there is no edge between x and y, and if some pair of vertices is not listed in the input, then there is an edge between these vertices.
... | import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import ... | 4JAVA | {
"input": [
"5 5\n1 2\n3 4\n3 2\n4 2\n2 5\n",
"7 20\n4 6\n6 7\n4 5\n1 2\n2 4\n1 7\n3 5\n2 1\n6 2\n6 1\n7 3\n3 2\n3 6\n3 1\n3 4\n2 5\n1 6\n7 4\n6 3\n7 5\n",
"8 23\n1 2\n1 4\n1 6\n1 8\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n3 4\n3 5\n3 6\n3 7\n3 8\n4 5\n4 6\n4 7\n5 6\n5 7\n5 8\n6 8\n7 8\n",
"4 4\n2 1\n3 1\n1 4\... | 2CODEFORCES |
949_C. Data Center Maintenance_488 | BigData Inc. is a corporation that has n data centers indexed from 1 to n that are located all over the world. These data centers provide storage for client data (you can figure out that client data is really big!).
Main feature of services offered by BigData Inc. is the access availability guarantee even under the ci... | #include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
struct debugger {
template <typename T>
debugger& operator,(const T& v) {
cerr << v << " ";
return *this;
}
} dbg;
const int N = 100000 + 10;
struct data {
int to, next;
} tu[N * 2];
int head[N];
int ip;
... | 2C++ | {
"input": [
"3 3 5\n4 4 0\n1 3\n3 2\n3 1\n",
"4 5 4\n2 1 0 3\n4 3\n3 2\n1 2\n1 4\n1 3\n",
"10 9 5\n0 0 0 0 0 0 0 0 0 4\n10 3\n10 7\n10 5\n10 8\n10 9\n10 1\n10 4\n10 6\n10 2\n",
"10 20 5\n2 2 1 4 0 3 0 4 1 3\n6 1\n8 5\n2 10\n3 5\n1 9\n4 6\n9 7\n2 3\n7 4\n10 8\n4 9\n2 5\n4 10\n2 8\n10 3\n1 8\n8 10\n6 7... | 2CODEFORCES |
949_C. Data Center Maintenance_489 | BigData Inc. is a corporation that has n data centers indexed from 1 to n that are located all over the world. These data centers provide storage for client data (you can figure out that client data is really big!).
Main feature of services offered by BigData Inc. is the access availability guarantee even under the ci... | from collections import deque
import sys
input = sys.stdin.readline
n, m, MOD = map(int, input().split())
u = list(map(int, input().split()))
info = [list(map(int, input().split())) for i in range(m)]
graph = [[] for i in range(n)]
rev_graph = [[] for i in range(n)]
set_ = set()
INF = 10 ** 9
for a, b in info:
a... | 3Python3 | {
"input": [
"3 3 5\n4 4 0\n1 3\n3 2\n3 1\n",
"4 5 4\n2 1 0 3\n4 3\n3 2\n1 2\n1 4\n1 3\n",
"10 9 5\n0 0 0 0 0 0 0 0 0 4\n10 3\n10 7\n10 5\n10 8\n10 9\n10 1\n10 4\n10 6\n10 2\n",
"10 20 5\n2 2 1 4 0 3 0 4 1 3\n6 1\n8 5\n2 10\n3 5\n1 9\n4 6\n9 7\n2 3\n7 4\n10 8\n4 9\n2 5\n4 10\n2 8\n10 3\n1 8\n8 10\n6 7... | 2CODEFORCES |
949_C. Data Center Maintenance_490 | BigData Inc. is a corporation that has n data centers indexed from 1 to n that are located all over the world. These data centers provide storage for client data (you can figure out that client data is really big!).
Main feature of services offered by BigData Inc. is the access availability guarantee even under the ci... | import java.io.*;
import java.util.*;
public class MainC {
static final StdIn in = new StdIn();
static final PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) {
int n=in.nextInt(), m=in.nextInt(), h=in.nextInt();
int[] u = in.readIntArray(n, 0);
List<Integer>[] graph = ne... | 4JAVA | {
"input": [
"3 3 5\n4 4 0\n1 3\n3 2\n3 1\n",
"4 5 4\n2 1 0 3\n4 3\n3 2\n1 2\n1 4\n1 3\n",
"10 9 5\n0 0 0 0 0 0 0 0 0 4\n10 3\n10 7\n10 5\n10 8\n10 9\n10 1\n10 4\n10 6\n10 2\n",
"10 20 5\n2 2 1 4 0 3 0 4 1 3\n6 1\n8 5\n2 10\n3 5\n1 9\n4 6\n9 7\n2 3\n7 4\n10 8\n4 9\n2 5\n4 10\n2 8\n10 3\n1 8\n8 10\n6 7... | 2CODEFORCES |
977_B. Two-gram_491 | Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" — three distinct two-grams.
You are given a string s consisting of n capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of ... | quant = int(raw_input())
string = raw_input()
substrings = []
resp = []
maior = -1
index = 0
for n in range(quant-1):
aux = string[n] + string[n+1]
if aux not in substrings:
substrings.append(aux)
resp.append(1)
else:
for x in range(len(substrings)):
if(aux == substring... | 1Python2 | {
"input": [
"5\nZZZAA\n",
"7\nABACABA\n",
"15\nMIRZOYANOVECLOX\n",
"23\nAABBBAAACCCCCAAADDDDDDD\n",
"2\nQA\n",
"11\nGGRRAATTZZZ\n",
"6\nAZAZAZ\n",
"10\nSQSQSQSQTG\n",
"3\nKEK\n",
"100\nURXCAIZFIBNJTPCZHBQIBCILLPXZCFGMKKZMNPLCYGAVJVIBMCZEBSJWPSCPQDYCTTKPOKIJRSKIZPDGCHVOUTMPNECY... | 2CODEFORCES |
977_B. Two-gram_492 | Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" — three distinct two-grams.
You are given a string s consisting of n capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of ... | #include <bits/stdc++.h>
using ll = long long;
using namespace std;
template <typename... Args>
void read(Args &...args) {
((cin >> args), ...);
}
template <typename... Args>
void write(Args... args) {
((cout << args << " "), ...);
}
template <typename... Args>
void writeln(Args... args) {
((cout << args << " "),... | 2C++ | {
"input": [
"5\nZZZAA\n",
"7\nABACABA\n",
"15\nMIRZOYANOVECLOX\n",
"23\nAABBBAAACCCCCAAADDDDDDD\n",
"2\nQA\n",
"11\nGGRRAATTZZZ\n",
"6\nAZAZAZ\n",
"10\nSQSQSQSQTG\n",
"3\nKEK\n",
"100\nURXCAIZFIBNJTPCZHBQIBCILLPXZCFGMKKZMNPLCYGAVJVIBMCZEBSJWPSCPQDYCTTKPOKIJRSKIZPDGCHVOUTMPNECY... | 2CODEFORCES |
977_B. Two-gram_493 | Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" — three distinct two-grams.
You are given a string s consisting of n capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of ... | n = int(input())
k = str(input())
Max = 0
for i in range(n-1):
t=k[i]+k[i+1]
z=0
for j in range(0,n-1):
s=k[j]+k[j+1]
if (s==t):
z=z+1
#print(z)
if (z>Max):
Max=z
res=t
print(res)
| 3Python3 | {
"input": [
"5\nZZZAA\n",
"7\nABACABA\n",
"15\nMIRZOYANOVECLOX\n",
"23\nAABBBAAACCCCCAAADDDDDDD\n",
"2\nQA\n",
"11\nGGRRAATTZZZ\n",
"6\nAZAZAZ\n",
"10\nSQSQSQSQTG\n",
"3\nKEK\n",
"100\nURXCAIZFIBNJTPCZHBQIBCILLPXZCFGMKKZMNPLCYGAVJVIBMCZEBSJWPSCPQDYCTTKPOKIJRSKIZPDGCHVOUTMPNECY... | 2CODEFORCES |
977_B. Two-gram_494 | Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" — three distinct two-grams.
You are given a string s consisting of n capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of ... | import java.util.ArrayList;
import java.util.Scanner;
public class Dvugramma {
public class PairClass{
String val;
int count;
};
public static int[] getArray(int size) {
int[] array = new int[size];
for (int i = 0; i < size; i++) {
array[i] = sr.nextInt();
}
return array;
}
public static int[][... | 4JAVA | {
"input": [
"5\nZZZAA\n",
"7\nABACABA\n",
"15\nMIRZOYANOVECLOX\n",
"23\nAABBBAAACCCCCAAADDDDDDD\n",
"2\nQA\n",
"11\nGGRRAATTZZZ\n",
"6\nAZAZAZ\n",
"10\nSQSQSQSQTG\n",
"3\nKEK\n",
"100\nURXCAIZFIBNJTPCZHBQIBCILLPXZCFGMKKZMNPLCYGAVJVIBMCZEBSJWPSCPQDYCTTKPOKIJRSKIZPDGCHVOUTMPNECY... | 2CODEFORCES |
996_F. Game_495 | Allen and Bessie are playing a simple number game. They both know a function f: \{0, 1\}^n → R, i. e. the function takes n binary arguments and returns a real value. At the start of the game, the variables x_1, x_2, ..., x_n are all set to -1. Each round, with equal probability, one of Allen or Bessie gets to make a mo... | n,r = map(int, raw_input().split())
ls = map(int, raw_input().split())
sm=sum(ls)
nls=2**n
print float(sm)/nls
for i in range(r):
a,b = map(int, raw_input().split())
sm+=b-ls[a]
ls[a]=b
print float(sm)/nls | 1Python2 | {
"input": [
"2 0\n1 1 1 1\n",
"2 2\n0 1 2 3\n2 5\n0 4\n",
"1 0\n2 3\n",
"2 0\n1 1 0 1\n",
"2 2\n0 1 2 3\n2 1\n0 4\n",
"1 0\n2 1\n",
"2 0\n1 0 0 1\n",
"2 2\n0 1 2 4\n2 1\n0 4\n",
"2 2\n0 1 2 4\n3 1\n0 4\n",
"2 2\n0 1 0 4\n3 1\n0 4\n",
"2 2\n0 1 0 4\n2 1\n0 4\n",
"2 2\n0... | 2CODEFORCES |
996_F. Game_496 | Allen and Bessie are playing a simple number game. They both know a function f: \{0, 1\}^n → R, i. e. the function takes n binary arguments and returns a real value. At the start of the game, the variables x_1, x_2, ..., x_n are all set to -1. Each round, with equal probability, one of Allen or Bessie gets to make a mo... | #include <bits/stdc++.h>
using namespace std;
int N, R, vals[1 << 18];
double sum = 0;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(18);
cin >> N >> R;
for (int i = 0; i < (1 << N); i++) {
cin >> vals[i];
sum += vals[i];
}
cout << sum / (1 << N) << '\n';
f... | 2C++ | {
"input": [
"2 0\n1 1 1 1\n",
"2 2\n0 1 2 3\n2 5\n0 4\n",
"1 0\n2 3\n",
"2 0\n1 1 0 1\n",
"2 2\n0 1 2 3\n2 1\n0 4\n",
"1 0\n2 1\n",
"2 0\n1 0 0 1\n",
"2 2\n0 1 2 4\n2 1\n0 4\n",
"2 2\n0 1 2 4\n3 1\n0 4\n",
"2 2\n0 1 0 4\n3 1\n0 4\n",
"2 2\n0 1 0 4\n2 1\n0 4\n",
"2 2\n0... | 2CODEFORCES |
996_F. Game_497 | Allen and Bessie are playing a simple number game. They both know a function f: \{0, 1\}^n → R, i. e. the function takes n binary arguments and returns a real value. At the start of the game, the variables x_1, x_2, ..., x_n are all set to -1. Each round, with equal probability, one of Allen or Bessie gets to make a mo... | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import time
(n, r) = (int(i) for i in input().split())
c = [int(i) for i in input().split()]
start = time.time()
s = sum(c)
n2 = 2**n
ans = [s/n2]
for i in range(r):
(k, new) = (int(i) for i in input().split())
s += new - c[k]
c[k] = new
... | 3Python3 | {
"input": [
"2 0\n1 1 1 1\n",
"2 2\n0 1 2 3\n2 5\n0 4\n",
"1 0\n2 3\n",
"2 0\n1 1 0 1\n",
"2 2\n0 1 2 3\n2 1\n0 4\n",
"1 0\n2 1\n",
"2 0\n1 0 0 1\n",
"2 2\n0 1 2 4\n2 1\n0 4\n",
"2 2\n0 1 2 4\n3 1\n0 4\n",
"2 2\n0 1 0 4\n3 1\n0 4\n",
"2 2\n0 1 0 4\n2 1\n0 4\n",
"2 2\n0... | 2CODEFORCES |
996_F. Game_498 | Allen and Bessie are playing a simple number game. They both know a function f: \{0, 1\}^n → R, i. e. the function takes n binary arguments and returns a real value. At the start of the game, the variables x_1, x_2, ..., x_n are all set to -1. Each round, with equal probability, one of Allen or Bessie gets to make a mo... | import java.io.*;
import java.util.*;
public class F implements Runnable{
public static void main (String[] args) {new Thread(null, new F(), "fuuuuuuck me", 1 << 28).start();}
public void run() {
FastScanner fs = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
System.err.println("Go!");
/... | 4JAVA | {
"input": [
"2 0\n1 1 1 1\n",
"2 2\n0 1 2 3\n2 5\n0 4\n",
"1 0\n2 3\n",
"2 0\n1 1 0 1\n",
"2 2\n0 1 2 3\n2 1\n0 4\n",
"1 0\n2 1\n",
"2 0\n1 0 0 1\n",
"2 2\n0 1 2 4\n2 1\n0 4\n",
"2 2\n0 1 2 4\n3 1\n0 4\n",
"2 2\n0 1 0 4\n3 1\n0 4\n",
"2 2\n0 1 0 4\n2 1\n0 4\n",
"2 2\n0... | 2CODEFORCES |
battle-of-stalingrad-1_499 | The bloodiest battle of World War II has started. Germany and its allies have attacked the Soviet union army to gain control of the city of Stalingrad (now Volgograd) in the south-western Soviet Union.The war has become intensive and the soviet union's 64th army is fighting against the germans. General "Vasily Chuikov"... | import math
#import decimal from *
def func(x1,y1,x2,y2,x3,y3):
area = x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2)
if area < 0.0:
area = -area
area = area*(0.5)
return area
t = int(raw_input())
while t > 0:
st = raw_input()
st = st.split(' ')
x1 = float(st[0])
y1 = float(st[1])
x2 = float(st[2])
y2 = floa... | 1Python2 | {
"input": [
"36\n2 2 2 8 9 4 8 5\n9 1 7 6 10 6 9 3\n10 2 4 6 6 2 1 1\n9 6 2 3 5 7 7 3\n6 6 3 9 10 9 1 3\n1 3 10 5 10 10 4 1\n10 3 10 4 5 5 3 4\n10 3 4 9 3 3 7 3\n6 9 9 2 6 4 3 3\n7 2 1 10 4 7 6 2\n3 4 3 4 3 2 9 5\n7 8 2 9 8 3 2 3\n5 4 6 9 4 4 8 3\n5 2 2 8 1 5 7 5\n4 7 10 2 10 9 2 3\n4 8 2 3 6 6 3 2\n8 10 4 3 4 2... | 3HACKEREARTH |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.