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
1421_D. Hexagons_37900
Lindsey Buckingham told Stevie Nicks ["Go your own way"](https://www.youtube.com/watch?v=6ul-cZyuYq4). Nicks is now sad and wants to go away as quickly as possible, but she lives in a 2D hexagonal world. Consider a hexagonal tiling of the plane as on the picture below. <image> Nicks wishes to go from the cell marked...
import sys input=sys.stdin.buffer.readline #FOR READING PURE INTEGER INPUTS (space separation ok) #import sys #input=lambda: sys.stdin.readline().rstrip("\r\n") #FOR READING STRING/TEXT INPUTS. def oneLineArrayPrint(arr): print(' '.join([str(x) for x in arr])) def multiLineArrayPrint(arr): print('\n'.join([str(...
3Python3
{ "input": [ "2\n-3 1\n1 3 5 7 9 11\n1000000000 1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n", "1\n-1000000000 -1000000000\n10000 20000 30000 40000 50000 60000\n", "1\n0 0\n1 2 3 4 5 6\n", "1\n-1000000000 -1000000000\n10000 20000 30000 40000 81069 60000\n", "1\n-...
2CODEFORCES
1421_D. Hexagons_37901
Lindsey Buckingham told Stevie Nicks ["Go your own way"](https://www.youtube.com/watch?v=6ul-cZyuYq4). Nicks is now sad and wants to go away as quickly as possible, but she lives in a 2D hexagonal world. Consider a hexagonal tiling of the plane as on the picture below. <image> Nicks wishes to go from the cell marked...
import java.io.*; import java.util.Arrays; import java.util.Comparator; import java.util.List; import java.util.StringTokenizer; import java.util.stream.Collectors; public class A { void solve() { long y = in.nextInt(); long x = in.nextInt(); long dUp = in.nextInt(); long right = in...
4JAVA
{ "input": [ "2\n-3 1\n1 3 5 7 9 11\n1000000000 1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n", "1\n-1000000000 -1000000000\n10000 20000 30000 40000 50000 60000\n", "1\n0 0\n1 2 3 4 5 6\n", "1\n-1000000000 -1000000000\n10000 20000 30000 40000 81069 60000\n", "1\n-...
2CODEFORCES
143_C. Help Farmer_37902
Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simple...
from math import sqrt n = input() Min, Max = 999999999999999999L, -1 #i = 1 #while i * i <= n: for i in range(1, int(sqrt(n)) + 1): if n % i == 0: n1 = n / i a = i + 1 # j = 1 # while j * j <= n1: for j in range(1, int(sqrt(n1)) + 1): if n1 % j == 0: ...
1Python2
{ "input": [ "7\n", "4\n", "12\n", "573308928\n", "311933803\n", "778377600\n", "15\n", "99264891\n", "864864000\n", "905969664\n", "14\n", "999905161\n", "206898748\n", "999999937\n", "534879507\n", "332393619\n", "1026\n", "999999991\n", "8...
2CODEFORCES
143_C. Help Farmer_37903
Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simple...
#include <bits/stdc++.h> using namespace std; const int N = 100005; inline int in() { int x; scanf("%d", &x); return x; } inline long long lin() { long long x; scanf("%I64d", &x); return x; } long long n, a, b; int main() { n = lin(); a = 1ll * 1e18; b = 1ll * -1e18; for (long long p = 1; p <= 35000...
2C++
{ "input": [ "7\n", "4\n", "12\n", "573308928\n", "311933803\n", "778377600\n", "15\n", "99264891\n", "864864000\n", "905969664\n", "14\n", "999905161\n", "206898748\n", "999999937\n", "534879507\n", "332393619\n", "1026\n", "999999991\n", "8...
2CODEFORCES
143_C. Help Farmer_37904
Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simple...
from math import sqrt p, n = [], int(input()) def f(x, y): return (x + 2) * (y + 2) + (2 * (x + y + 2) * n) // (x * y) for x in range(2, int(sqrt(n)) + 1): if n % x == 0: p.append(x) p += [n // x for x in reversed(p)] p.append(n) u = v = f(1, 1) for m in p: for x in range(1, int(sqrt(m)) + 1): ...
3Python3
{ "input": [ "7\n", "4\n", "12\n", "573308928\n", "311933803\n", "778377600\n", "15\n", "99264891\n", "864864000\n", "905969664\n", "14\n", "999905161\n", "206898748\n", "999999937\n", "534879507\n", "332393619\n", "1026\n", "999999991\n", "8...
2CODEFORCES
143_C. Help Farmer_37905
Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As Sam was a bright farmer, he tried to make the process of storing hay simple...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; import java.io.BufferedReader; import java.io.InputStream; ...
4JAVA
{ "input": [ "7\n", "4\n", "12\n", "573308928\n", "311933803\n", "778377600\n", "15\n", "99264891\n", "864864000\n", "905969664\n", "14\n", "999905161\n", "206898748\n", "999999937\n", "534879507\n", "332393619\n", "1026\n", "999999991\n", "8...
2CODEFORCES
1466_H. Finding satisfactory solutions_37906
Getting so far in this contest is not an easy feat. By solving all the previous problems, you have impressed the gods greatly. Thus, they decided to spare you the story for this problem and grant a formal statement instead. Consider n agents. Each one of them initially has exactly one item, i-th agent has the item num...
#include <bits/stdc++.h> using namespace std; const int maxn = 41, P = 1000000007; int n, p[maxn], base[maxn], f[5100]; int fact[maxn], C[maxn][maxn], pw[maxn][maxn], vis[maxn]; vector<int> len, cnt, sub[5100]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &p[i]), p[i]--; ...
2C++
{ "input": [ "4\n2 1 3 4\n", "2\n2 1\n", "3\n1 2 3\n", "37\n12 2 25 23 10 24 28 5 33 19 17 32 13 36 26 16 21 22 8 31 11 18 4 6 37 14 27 15 29 30 20 9 1 34 35 7 3\n", "6\n1 2 6 3 4 5\n", "37\n7 2 15 6 25 19 17 23 31 30 32 36 29 21 37 16 9 1 4 20 13 8 22 34 5 10 27 28 14 12 18 11 33 24 35 26 3\n...
2CODEFORCES
1491_B. Minimal Cost_37907
There is a graph of n rows and 10^6 + 2 columns, where rows are numbered from 1 to n and columns from 0 to 10^6 + 1: <image> Let's denote the node in the row i and column j by (i, j). Initially for each i the i-th row has exactly one obstacle — at node (i, a_i). You want to move some obstacles so that you can reach ...
from __future__ import division from sys import stdin, stdout from collections import * rstr = lambda: stdin.readline().strip() rstrs = lambda: [str(x) for x in stdin.readline().split()] rstr_2d = lambda n: [rstr() for _ in range(n)] rint = lambda: int(stdin.readline()) rints = lambda: [int(x) for x in stdin.readline(...
1Python2
{ "input": [ "3\n2 3 4\n2 2\n2 3 4\n3 2\n2 4 3\n3 2\n", "1\n2 4 2\n999999 1000000\n", "1\n2 1000000000 1\n999999 1000000\n", "1\n3 1000000000 1\n1000000 1000000 1000000\n", "4\n2 3 1\n999999 1000000\n2 3 2\n999999 1000000\n2 3 1\n1000000 999999\n2 3 1\n100 1000000\n", "1\n3 1 1\n1000000 100000...
2CODEFORCES
1491_B. Minimal Cost_37908
There is a graph of n rows and 10^6 + 2 columns, where rows are numbered from 1 to n and columns from 0 to 10^6 + 1: <image> Let's denote the node in the row i and column j by (i, j). Initially for each i the i-th row has exactly one obstacle — at node (i, a_i). You want to move some obstacles so that you can reach ...
#include<bits/stdc++.h> using namespace std; void problem_solver() { int n, u, v; cin >> n >> u >> v; vector<int> a(n); bool t1 = false, t2 = false, t3 = false; for(int i=0; i<n; i++) cin >> a[i]; for(int i=0; i<n-1; i++) { if(abs(a[i] - a[i+1]) > 1) { cout << 0; ...
2C++
{ "input": [ "3\n2 3 4\n2 2\n2 3 4\n3 2\n2 4 3\n3 2\n", "1\n2 4 2\n999999 1000000\n", "1\n2 1000000000 1\n999999 1000000\n", "1\n3 1000000000 1\n1000000 1000000 1000000\n", "4\n2 3 1\n999999 1000000\n2 3 2\n999999 1000000\n2 3 1\n1000000 999999\n2 3 1\n100 1000000\n", "1\n3 1 1\n1000000 100000...
2CODEFORCES
1491_B. Minimal Cost_37909
There is a graph of n rows and 10^6 + 2 columns, where rows are numbered from 1 to n and columns from 0 to 10^6 + 1: <image> Let's denote the node in the row i and column j by (i, j). Initially for each i the i-th row has exactly one obstacle — at node (i, a_i). You want to move some obstacles so that you can reach ...
t=int(input()) while t: n,v,h=map(int,input().split()) a=list(map(int,input().split())) diff=0 for i in range(1,n): diff=max(abs(a[i]-a[i-1]),diff) if diff>=2: print(0) elif diff==1: print(min(v,h)) elif diff==0: print(min(h+h,v+h)) t=t-1
3Python3
{ "input": [ "3\n2 3 4\n2 2\n2 3 4\n3 2\n2 4 3\n3 2\n", "1\n2 4 2\n999999 1000000\n", "1\n2 1000000000 1\n999999 1000000\n", "1\n3 1000000000 1\n1000000 1000000 1000000\n", "4\n2 3 1\n999999 1000000\n2 3 2\n999999 1000000\n2 3 1\n1000000 999999\n2 3 1\n100 1000000\n", "1\n3 1 1\n1000000 100000...
2CODEFORCES
1491_B. Minimal Cost_37910
There is a graph of n rows and 10^6 + 2 columns, where rows are numbered from 1 to n and columns from 0 to 10^6 + 1: <image> Let's denote the node in the row i and column j by (i, j). Initially for each i the i-th row has exactly one obstacle — at node (i, a_i). You want to move some obstacles so that you can reach ...
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int q = sc.nextInt(); while((q--)!=0) { int n = sc.nextInt(); int u = sc.nextInt(); int v = sc.nextInt(); String s=sc.nextLine(); String[] a = sc.nextLine().split(" "); int z=Integ...
4JAVA
{ "input": [ "3\n2 3 4\n2 2\n2 3 4\n3 2\n2 4 3\n3 2\n", "1\n2 4 2\n999999 1000000\n", "1\n2 1000000000 1\n999999 1000000\n", "1\n3 1000000000 1\n1000000 1000000 1000000\n", "4\n2 3 1\n999999 1000000\n2 3 2\n999999 1000000\n2 3 1\n1000000 999999\n2 3 1\n100 1000000\n", "1\n3 1 1\n1000000 100000...
2CODEFORCES
1513_E. Cost Equilibrium_37911
An array is called beautiful if all the elements in the array are equal. You can transform an array using the following steps any number of times: 1. Choose two indices i and j (1 ≤ i,j ≤ n), and an integer x (1 ≤ x ≤ a_i). Let i be the source index and j be the sink index. 2. Decrease the i-th element by x, an...
#!/usr/bin/env python # https://github.com/cheran-senthil/PyRival from __future__ import division, print_function import os import sys from io import BytesIO, IOBase from collections import defaultdict if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filte...
1Python2
{ "input": [ "5\n0 11 12 13 14\n", "3\n1 2 3\n", "4\n0 4 0 4\n", "1\n100000\n", "3\n0 0 3\n", "1\n100010\n", "5\n0 11 1 13 14\n", "5\n0 12 1 13 14\n", "3\n0 3 3\n", "3\n0 1 2\n", "4\n2 1 0 1\n", "4\n0 6 0 6\n", "4\n4 0 0 0\n", "5\n1 3 0 13 48\n", "5\n0 1 3 3...
2CODEFORCES
1513_E. Cost Equilibrium_37912
An array is called beautiful if all the elements in the array are equal. You can transform an array using the following steps any number of times: 1. Choose two indices i and j (1 ≤ i,j ≤ n), and an integer x (1 ≤ x ≤ a_i). Let i be the source index and j be the sink index. 2. Decrease the i-th element by x, an...
#include <iostream> #include <vector> #include <string> #include <array> #include <functional> #include <algorithm> #include <stack> #include <map> #include <set> #include <climits> #include <queue> #include <bitset> #include <cassert> #include <math.h> #include <complex> #include <iomanip> #include <unordered_map> usi...
2C++
{ "input": [ "5\n0 11 12 13 14\n", "3\n1 2 3\n", "4\n0 4 0 4\n", "1\n100000\n", "3\n0 0 3\n", "1\n100010\n", "5\n0 11 1 13 14\n", "5\n0 12 1 13 14\n", "3\n0 3 3\n", "3\n0 1 2\n", "4\n2 1 0 1\n", "4\n0 6 0 6\n", "4\n4 0 0 0\n", "5\n1 3 0 13 48\n", "5\n0 1 3 3...
2CODEFORCES
1513_E. Cost Equilibrium_37913
An array is called beautiful if all the elements in the array are equal. You can transform an array using the following steps any number of times: 1. Choose two indices i and j (1 ≤ i,j ≤ n), and an integer x (1 ≤ x ≤ a_i). Let i be the source index and j be the sink index. 2. Decrease the i-th element by x, an...
n=int(input());a=*map(int,input().split()),;s=sum(a) if s%n:print(0);exit(0) M=10**9+7;s//=n;f=[1]*(n+1);b=[0]*3;d=dict() for i in range(2,n+1):f[i]=f[i-1]*i%M for x in a: b[(x>s)-(x<s)]+=1 try:d[x]+=1 except:d[x]=1 k=1 for x in d.values():k*=f[x] k=f[n]*pow(k,M-2,M) print([k%M,f[b[1]]*f[b[-1]]*2*pow(f[n-b[0]],M-2,M...
3Python3
{ "input": [ "5\n0 11 12 13 14\n", "3\n1 2 3\n", "4\n0 4 0 4\n", "1\n100000\n", "3\n0 0 3\n", "1\n100010\n", "5\n0 11 1 13 14\n", "5\n0 12 1 13 14\n", "3\n0 3 3\n", "3\n0 1 2\n", "4\n2 1 0 1\n", "4\n0 6 0 6\n", "4\n4 0 0 0\n", "5\n1 3 0 13 48\n", "5\n0 1 3 3...
2CODEFORCES
1513_E. Cost Equilibrium_37914
An array is called beautiful if all the elements in the array are equal. You can transform an array using the following steps any number of times: 1. Choose two indices i and j (1 ≤ i,j ≤ n), and an integer x (1 ≤ x ≤ a_i). Let i be the source index and j be the sink index. 2. Decrease the i-th element by x, an...
import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.PriorityQueue; import java.util.Map.Entry; i...
4JAVA
{ "input": [ "5\n0 11 12 13 14\n", "3\n1 2 3\n", "4\n0 4 0 4\n", "1\n100000\n", "3\n0 0 3\n", "1\n100010\n", "5\n0 11 1 13 14\n", "5\n0 12 1 13 14\n", "3\n0 3 3\n", "3\n0 1 2\n", "4\n2 1 0 1\n", "4\n0 6 0 6\n", "4\n4 0 0 0\n", "5\n1 3 0 13 48\n", "5\n0 1 3 3...
2CODEFORCES
1540_D. Inverse Inversions_37915
You were playing with permutation p of length n, but you lost it in Blair, Alabama! Luckily, you remember some information about the permutation. More specifically, you remember an array b of length n, where b_i is the number of indices j such that j < i and p_j > p_i. You have the array b, and you want to find the p...
#include <bits/stdc++.h> #ifdef ALGO #include "el_psy_congroo.hpp" #else #define DUMP(...) 1145141919810 #define CHECK(...) (__VA_ARGS__) #endif int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); std::istream& reader = std::cin; const int BIT = 10; int n; reader >> n; std::vector<st...
2C++
{ "input": [ "3\n0 0 0\n7\n2 1\n2 2\n2 3\n1 2 1\n2 1\n2 2\n2 3\n", "5\n0 1 2 3 4\n15\n2 1\n2 2\n1 2 1\n2 2\n2 3\n2 5\n1 3 0\n1 4 0\n2 3\n2 4\n2 5\n1 4 1\n2 3\n2 4\n2 5\n", "5\n0 0 2 3 0\n10\n2 1\n2 5\n2 2\n1 1 0\n2 5\n1 2 0\n1 3 1\n2 3\n2 3\n2 4\n", "10\n0 1 2 2 1 0 0 4 7 9\n10\n2 1\n2 5\n1 6 2\n1 7 3...
2CODEFORCES
168_C. Wizards and Trolleybuses_37916
In some country live wizards. They love to ride trolleybuses. A city in this country has a trolleybus depot with n trolleybuses. Every day the trolleybuses leave the depot, one by one and go to the final station. The final station is at a distance of d meters from the depot. We know for the i-th trolleybus that it lea...
import math t = 0.0 n, a, d = map(int, raw_input().split()) for i in xrange(n): ti, v = map(float, raw_input().split()) t1 = (v / a + (d - v * v / (2 * a)) / v) if d > v * v / (2 * a) else math.sqrt(2 * float(d) / a) t = max(t1 + ti, t) print(t)
1Python2
{ "input": [ "3 10 10000\n0 10\n5 11\n1000 1\n", "1 2 26\n28 29\n", "1 2 7\n20 13\n", "8 4 13\n0 18\n6 24\n10 25\n11 5\n12 18\n20 22\n21 8\n22 12\n", "3 6 19\n12 3\n20 24\n30 2\n", "4 5 14\n11 1\n16 20\n17 15\n21 7\n", "3 3 3\n13 1\n18 12\n19 2\n", "1 1 1\n0 1000000\n", "1 100000 3...
2CODEFORCES
168_C. Wizards and Trolleybuses_37917
In some country live wizards. They love to ride trolleybuses. A city in this country has a trolleybus depot with n trolleybuses. Every day the trolleybuses leave the depot, one by one and go to the final station. The final station is at a distance of d meters from the depot. We know for the i-th trolleybus that it lea...
#include <bits/stdc++.h> using namespace std; using ll = long long; int n, a, d; int t[100005], v[100005]; double ans[100005]; int main() { cin.tie(0); cin >> n >> a >> d; for (int i = 1; i <= n; i++) cin >> t[i] >> v[i]; ans[0] = 0; for (int i = 1; i <= n; i++) { double tt = 1.0 * v[i] / a; double dd...
2C++
{ "input": [ "3 10 10000\n0 10\n5 11\n1000 1\n", "1 2 26\n28 29\n", "1 2 7\n20 13\n", "8 4 13\n0 18\n6 24\n10 25\n11 5\n12 18\n20 22\n21 8\n22 12\n", "3 6 19\n12 3\n20 24\n30 2\n", "4 5 14\n11 1\n16 20\n17 15\n21 7\n", "3 3 3\n13 1\n18 12\n19 2\n", "1 1 1\n0 1000000\n", "1 100000 3...
2CODEFORCES
168_C. Wizards and Trolleybuses_37918
In some country live wizards. They love to ride trolleybuses. A city in this country has a trolleybus depot with n trolleybuses. Every day the trolleybuses leave the depot, one by one and go to the final station. The final station is at a distance of d meters from the depot. We know for the i-th trolleybus that it lea...
# written with help of passed solutions from math import sqrt n, a, d = map(int, input().split()) a = float(a) ans = [0] * n tm = 0 for i in range(n): t, v = map(int, input().split()) acc_t = v / a add_t = 0 if acc_t ** 2 * a > 2 * d: add_t = sqrt(2 * d / a) else: add_t = acc_t + ...
3Python3
{ "input": [ "3 10 10000\n0 10\n5 11\n1000 1\n", "1 2 26\n28 29\n", "1 2 7\n20 13\n", "8 4 13\n0 18\n6 24\n10 25\n11 5\n12 18\n20 22\n21 8\n22 12\n", "3 6 19\n12 3\n20 24\n30 2\n", "4 5 14\n11 1\n16 20\n17 15\n21 7\n", "3 3 3\n13 1\n18 12\n19 2\n", "1 1 1\n0 1000000\n", "1 100000 3...
2CODEFORCES
168_C. Wizards and Trolleybuses_37919
In some country live wizards. They love to ride trolleybuses. A city in this country has a trolleybus depot with n trolleybuses. Every day the trolleybuses leave the depot, one by one and go to the final station. The final station is at a distance of d meters from the depot. We know for the i-th trolleybus that it lea...
import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.Map.Entry; import java.util.PriorityQueue...
4JAVA
{ "input": [ "3 10 10000\n0 10\n5 11\n1000 1\n", "1 2 26\n28 29\n", "1 2 7\n20 13\n", "8 4 13\n0 18\n6 24\n10 25\n11 5\n12 18\n20 22\n21 8\n22 12\n", "3 6 19\n12 3\n20 24\n30 2\n", "4 5 14\n11 1\n16 20\n17 15\n21 7\n", "3 3 3\n13 1\n18 12\n19 2\n", "1 1 1\n0 1000000\n", "1 100000 3...
2CODEFORCES
189_A. Cut Ribbon_37920
Polycarpus has a ribbon, its length is n. He wants to cut the ribbon in a way that fulfils the following two conditions: * After the cutting each ribbon piece should have length a, b or c. * After the cutting the number of ribbon pieces should be maximum. Help Polycarpus and find the number of ribbon pieces ...
[n, a, b, c] = map(int, raw_input().split()) z = sorted(list(set([a, b, c]))) maxs = {} def stuff(x): if x == 0: return 0 if x < z[0]: return -1 if x in maxs: return maxs[x] if x % z[0] == 0: y = x/z[0] maxs[x] = y return y qq = max([stuff(x - z[i]) for i in xrange(1, len(z))]) if qq == -1: maxs[x]...
1Python2
{ "input": [ "5 5 3 2\n", "7 5 5 2\n", "2 19 15 1\n", "918 102 1327 1733\n", "27 23 4 3\n", "29 27 18 2\n", "370 2 1 15\n", "5 17 26 5\n", "9 1 10 3\n", "490 4 49 50\n", "14 6 2 17\n", "728 412 789 158\n", "10 6 2 9\n", "100 9 11 99\n", "4 4 4 4\n", "100...
2CODEFORCES
189_A. Cut Ribbon_37921
Polycarpus has a ribbon, its length is n. He wants to cut the ribbon in a way that fulfils the following two conditions: * After the cutting each ribbon piece should have length a, b or c. * After the cutting the number of ribbon pieces should be maximum. Help Polycarpus and find the number of ribbon pieces ...
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b, c, i; cin >> n >> a >> b >> c; int ans[n + 1]; for (i = 0; i <= n; i++) ans[i] = -52464164; ans[0] = 0; for (i = 1; i <= n; i++) { if (i >= a) ans[i] = ans[i - a] + 1; if (i >= b) { ans[i] = max(ans[i], ans[i - b] + 1); ...
2C++
{ "input": [ "5 5 3 2\n", "7 5 5 2\n", "2 19 15 1\n", "918 102 1327 1733\n", "27 23 4 3\n", "29 27 18 2\n", "370 2 1 15\n", "5 17 26 5\n", "9 1 10 3\n", "490 4 49 50\n", "14 6 2 17\n", "728 412 789 158\n", "10 6 2 9\n", "100 9 11 99\n", "4 4 4 4\n", "100...
2CODEFORCES
189_A. Cut Ribbon_37922
Polycarpus has a ribbon, its length is n. He wants to cut the ribbon in a way that fulfils the following two conditions: * After the cutting each ribbon piece should have length a, b or c. * After the cutting the number of ribbon pieces should be maximum. Help Polycarpus and find the number of ribbon pieces ...
from math import *; lineup=[int(x) for x in input().split()] a,b,c=sorted(lineup[1:4]) n=lineup[0] value=0 if a==1: print(n) exit() for i in range(0,n+1,a): for j in range(0,n+1,b): z=(n-i-j)/c if ceil(z)==floor(z) and int(z)>=0: x=i//a y=j//b z=int(z) value=max(value,x+y+z) print(int(value))
3Python3
{ "input": [ "5 5 3 2\n", "7 5 5 2\n", "2 19 15 1\n", "918 102 1327 1733\n", "27 23 4 3\n", "29 27 18 2\n", "370 2 1 15\n", "5 17 26 5\n", "9 1 10 3\n", "490 4 49 50\n", "14 6 2 17\n", "728 412 789 158\n", "10 6 2 9\n", "100 9 11 99\n", "4 4 4 4\n", "100...
2CODEFORCES
189_A. Cut Ribbon_37923
Polycarpus has a ribbon, its length is n. He wants to cut the ribbon in a way that fulfils the following two conditions: * After the cutting each ribbon piece should have length a, b or c. * After the cutting the number of ribbon pieces should be maximum. Help Polycarpus and find the number of ribbon pieces ...
/** * Created by Akshay on 10/9/17. */ import java.util.*; public class Week_5_Codeforces_A { public static void main(String[] args){ Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int a = scan.nextInt(); int b = scan.nextInt(); int c = scan.nextInt(); ...
4JAVA
{ "input": [ "5 5 3 2\n", "7 5 5 2\n", "2 19 15 1\n", "918 102 1327 1733\n", "27 23 4 3\n", "29 27 18 2\n", "370 2 1 15\n", "5 17 26 5\n", "9 1 10 3\n", "490 4 49 50\n", "14 6 2 17\n", "728 412 789 158\n", "10 6 2 9\n", "100 9 11 99\n", "4 4 4 4\n", "100...
2CODEFORCES
212_A. Privatization_37924
There is a developed network of flights between Berland and Beerland. All of them belong to the Berland state company BerAvia. Each flight connects some Berland city with some Beerland city. For each flight airplanes fly in both directions. Changes are coming to Berland — the state decided to privatize BerAvia, namely...
#include <bits/stdc++.h> using namespace std; const int N = 605, X = 90005, M = 200005; int n, m, p, S, T, nA, nB, cnt, du[N], le[X], ri[X], ans[X]; int tot, lnk[N], son[M], w[M], v[M], nxt[M]; int q[N], dst[N], pre[N]; bool bo[N], vis[N]; int read() { int x = 0; char ch = getchar(); while (ch < '0' || ch > '9') ...
2C++
{ "input": [ "3 5 8 2\n1 4\n1 3\n3 3\n1 2\n1 1\n2 1\n1 5\n2 2\n", "1 2 1 1\n1 1\n", "3 5 8 3\n1 4\n3 2\n1 1\n2 2\n1 5\n1 2\n2 1\n2 4\n", "6 5 21 2\n1 4\n5 4\n3 1\n5 3\n5 2\n2 3\n4 4\n6 1\n1 1\n4 5\n6 2\n5 5\n6 4\n2 4\n3 2\n1 5\n6 5\n4 2\n3 5\n2 2\n4 1\n", "1 2 2 1\n1 1\n1 2\n", "6 5 10 2\n6 2\...
2CODEFORCES
212_A. Privatization_37925
There is a developed network of flights between Berland and Beerland. All of them belong to the Berland state company BerAvia. Each flight connects some Berland city with some Beerland city. For each flight airplanes fly in both directions. Changes are coming to Berland — the state decided to privatize BerAvia, namely...
import java.util.*; // BiGraph Matching public class CF_212A { static Scanner scanner = new Scanner(System.in); public static void main(String args[]) { while (task()) { } } private static int n, m, k, t; private static int maxK = 5000; private static int maxT = 2000; p...
4JAVA
{ "input": [ "3 5 8 2\n1 4\n1 3\n3 3\n1 2\n1 1\n2 1\n1 5\n2 2\n", "1 2 1 1\n1 1\n", "3 5 8 3\n1 4\n3 2\n1 1\n2 2\n1 5\n1 2\n2 1\n2 4\n", "6 5 21 2\n1 4\n5 4\n3 1\n5 3\n5 2\n2 3\n4 4\n6 1\n1 1\n4 5\n6 2\n5 5\n6 4\n2 4\n3 2\n1 5\n6 5\n4 2\n3 5\n2 2\n4 1\n", "1 2 2 1\n1 1\n1 2\n", "6 5 10 2\n6 2\...
2CODEFORCES
236_A. Boy or Girl_37926
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. Bu...
a = set(list(raw_input())) if len(a) % 2 == 1: print 'IGNORE HIM!' else: print 'CHAT WITH HER!'
1Python2
{ "input": [ "xiaodao\n", "sevenkplus\n", "wjmzbmr\n", "nuezoadauueermoeaabjrkxttkatspjsjegjcjcdmcxgodowzbwuqncfbeqlhkk\n", "aqzftsvezdgouyrirsxpbuvdjupnzvbhguyayeqozfzymfnepvwgblqzvmxxkxcilmsjvcgyqykpoaktjvsxbygfgsalbjoq\n", "pezu\n", "nheihhxkbbrmlpxpxbhnpofcjmxemyvqqdbanwd\n", "lnpd...
2CODEFORCES
236_A. Boy or Girl_37927
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. Bu...
#include <bits/stdc++.h> int main() { int alfabet[30] = {}; char string[105]; int i = 0; int isi; scanf("%s", string); for (int i = 0; i < strlen(string); i++) { alfabet[string[i] - 96]++; } for (int i = 0; i < 27; i++) { if (alfabet[i] != 0) { isi++; } } if (isi % 2 == 0) { pr...
2C++
{ "input": [ "xiaodao\n", "sevenkplus\n", "wjmzbmr\n", "nuezoadauueermoeaabjrkxttkatspjsjegjcjcdmcxgodowzbwuqncfbeqlhkk\n", "aqzftsvezdgouyrirsxpbuvdjupnzvbhguyayeqozfzymfnepvwgblqzvmxxkxcilmsjvcgyqykpoaktjvsxbygfgsalbjoq\n", "pezu\n", "nheihhxkbbrmlpxpxbhnpofcjmxemyvqqdbanwd\n", "lnpd...
2CODEFORCES
236_A. Boy or Girl_37928
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. Bu...
for _ in range(1): x=set(list(input())) if len(x)%2==0: print('CHAT WITH HER!') else: print("IGNORE HIM!")
3Python3
{ "input": [ "xiaodao\n", "sevenkplus\n", "wjmzbmr\n", "nuezoadauueermoeaabjrkxttkatspjsjegjcjcdmcxgodowzbwuqncfbeqlhkk\n", "aqzftsvezdgouyrirsxpbuvdjupnzvbhguyayeqozfzymfnepvwgblqzvmxxkxcilmsjvcgyqykpoaktjvsxbygfgsalbjoq\n", "pezu\n", "nheihhxkbbrmlpxpxbhnpofcjmxemyvqqdbanwd\n", "lnpd...
2CODEFORCES
236_A. Boy or Girl_37929
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network. Bu...
import java.util.ArrayList; import java.util.Scanner; public class main { public static void main(String[] args) { // TODO Auto-generated method stub String word,finalWord; Scanner input = new Scanner(System.in); ArrayList <Boolean> check = new ArrayList<Boolean>(); word = input.nextLine(); finalWord...
4JAVA
{ "input": [ "xiaodao\n", "sevenkplus\n", "wjmzbmr\n", "nuezoadauueermoeaabjrkxttkatspjsjegjcjcdmcxgodowzbwuqncfbeqlhkk\n", "aqzftsvezdgouyrirsxpbuvdjupnzvbhguyayeqozfzymfnepvwgblqzvmxxkxcilmsjvcgyqykpoaktjvsxbygfgsalbjoq\n", "pezu\n", "nheihhxkbbrmlpxpxbhnpofcjmxemyvqqdbanwd\n", "lnpd...
2CODEFORCES
260_D. Black and White Tree_37930
The board has got a painted tree graph, consisting of n nodes. Let us remind you that a non-directed graph is called a tree if it is connected and doesn't contain any cycles. Each node of the graph is painted black or white in such a manner that there aren't two nodes of the same color, connected by an edge. Each edge...
#!/usr/bin/python2.7 def main(): n = int(raw_input()) b = [] w = [] lb = lw = 0 for i in range(1, n+1): c, x = map(int, raw_input().split() ) if c: b.append([i, x]) lb += 1 else: w.append([i, x]) lw += 1 i = 0 j = 0 ...
1Python2
{ "input": [ "6\n1 0\n0 3\n1 8\n0 2\n0 3\n0 0\n", "3\n1 3\n1 2\n0 5\n", "20\n0 569\n1 328\n1 74\n1 88\n1 90\n1 124\n0 78\n0 39\n1 9\n1 59\n1 41\n1 73\n1 45\n0 45\n0 13\n1 39\n0 24\n0 37\n0 95\n0 70\n", "50\n1 574339\n0 409333\n0 330634\n0 420557\n0 323095\n0 63399\n0 69999\n1 82396\n1 90197\n0 265793\...
2CODEFORCES
260_D. Black and White Tree_37931
The board has got a painted tree graph, consisting of n nodes. Let us remind you that a non-directed graph is called a tree if it is connected and doesn't contain any cycles. Each node of the graph is painted black or white in such a manner that there aren't two nodes of the same color, connected by an edge. Each edge...
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); long long rand_seed() { long long a = rng(); return a; } int n; vector<pair<int, int> > val[3]; struct muchii { int a, b, c; }; muchii v[100002]; int nr = 0; int drop[10000...
2C++
{ "input": [ "6\n1 0\n0 3\n1 8\n0 2\n0 3\n0 0\n", "3\n1 3\n1 2\n0 5\n", "20\n0 569\n1 328\n1 74\n1 88\n1 90\n1 124\n0 78\n0 39\n1 9\n1 59\n1 41\n1 73\n1 45\n0 45\n0 13\n1 39\n0 24\n0 37\n0 95\n0 70\n", "50\n1 574339\n0 409333\n0 330634\n0 420557\n0 323095\n0 63399\n0 69999\n1 82396\n1 90197\n0 265793\...
2CODEFORCES
260_D. Black and White Tree_37932
The board has got a painted tree graph, consisting of n nodes. Let us remind you that a non-directed graph is called a tree if it is connected and doesn't contain any cycles. Each node of the graph is painted black or white in such a manner that there aren't two nodes of the same color, connected by an edge. Each edge...
n = int(input()) white, black = [], [] for i in range(n): color, weightSum = map(int, input().split()) if color == 0: white.append([weightSum, i+1]) else : black.append([weightSum, i+1]) #white.sort() #black.sort() wc,bc, wl, bl, edges = 0 , 0, len(white), len(black), [] while wc < wl a...
3Python3
{ "input": [ "6\n1 0\n0 3\n1 8\n0 2\n0 3\n0 0\n", "3\n1 3\n1 2\n0 5\n", "20\n0 569\n1 328\n1 74\n1 88\n1 90\n1 124\n0 78\n0 39\n1 9\n1 59\n1 41\n1 73\n1 45\n0 45\n0 13\n1 39\n0 24\n0 37\n0 95\n0 70\n", "50\n1 574339\n0 409333\n0 330634\n0 420557\n0 323095\n0 63399\n0 69999\n1 82396\n1 90197\n0 265793\...
2CODEFORCES
260_D. Black and White Tree_37933
The board has got a painted tree graph, consisting of n nodes. Let us remind you that a non-directed graph is called a tree if it is connected and doesn't contain any cycles. Each node of the graph is painted black or white in such a manner that there aren't two nodes of the same color, connected by an edge. Each edge...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Map.Entry; import java.util.NavigableMap; import java.util.TreeMap; public class BlackWhiteTree { public...
4JAVA
{ "input": [ "6\n1 0\n0 3\n1 8\n0 2\n0 3\n0 0\n", "3\n1 3\n1 2\n0 5\n", "20\n0 569\n1 328\n1 74\n1 88\n1 90\n1 124\n0 78\n0 39\n1 9\n1 59\n1 41\n1 73\n1 45\n0 45\n0 13\n1 39\n0 24\n0 37\n0 95\n0 70\n", "50\n1 574339\n0 409333\n0 330634\n0 420557\n0 323095\n0 63399\n0 69999\n1 82396\n1 90197\n0 265793\...
2CODEFORCES
284_D. Cow Program_37934
Farmer John has just given the cows a program to play with! The program contains two integer variables, x and y, and performs the following operations on a sequence a1, a2, ..., an of positive integers: 1. Initially, x = 1 and y = 0. If, after any step, x ≤ 0 or x > n, the program immediately terminates. 2. The p...
from sys import stdin,stdout def dfs(): visit, stack = {(0, 0)}, [] cur, su, ix, ext = 1, a[0], a[0], 0 while ix > -1 and ix < n: if mem[ix][cur]: if mem[ix][cur] != -1: ext = mem[ix][cur] else: su = -1 break visit.add((...
1Python2
{ "input": [ "3\n1 2\n", "4\n2 4 1\n", "98\n94 24 17 92 275858941 58 91 57 13 468038892 42 195790073 494005784 8 468106970 518962936 33 27 61 72 42 206673418 10 82 23 34 29 77 90 39 9 67 34 71 29 95 49 48 60 69 86 64 94 77 48 74 19 96700186 5 67 881058074 663483223 64 64 78 23 8 60 7 17 96 71 70 20 5 63 3...
2CODEFORCES
284_D. Cow Program_37935
Farmer John has just given the cows a program to play with! The program contains two integer variables, x and y, and performs the following operations on a sequence a1, a2, ..., an of positive integers: 1. Initially, x = 1 and y = 0. If, after any step, x ≤ 0 or x > n, the program immediately terminates. 2. The p...
#include <bits/stdc++.h> using namespace std; using namespace std; int n, a[300001], was[300001][3]; long long d[300001][3]; long long calc(int v, int bit) { if (v <= 0 || v > n) return 0ll; if (v == 1) return -1; if (was[v][bit] == 2) return d[v][bit] = -1; if (was[v][bit] == 1) return d[v][bit]; was[v][bit]...
2C++
{ "input": [ "3\n1 2\n", "4\n2 4 1\n", "98\n94 24 17 92 275858941 58 91 57 13 468038892 42 195790073 494005784 8 468106970 518962936 33 27 61 72 42 206673418 10 82 23 34 29 77 90 39 9 67 34 71 29 95 49 48 60 69 86 64 94 77 48 74 19 96700186 5 67 881058074 663483223 64 64 78 23 8 60 7 17 96 71 70 20 5 63 3...
2CODEFORCES
284_D. Cow Program_37936
Farmer John has just given the cows a program to play with! The program contains two integer variables, x and y, and performs the following operations on a sequence a1, a2, ..., an of positive integers: 1. Initially, x = 1 and y = 0. If, after any step, x ≤ 0 or x > n, the program immediately terminates. 2. The p...
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class cf283b { static int n; static int INC = 0, DEC = 1;...
4JAVA
{ "input": [ "3\n1 2\n", "4\n2 4 1\n", "98\n94 24 17 92 275858941 58 91 57 13 468038892 42 195790073 494005784 8 468106970 518962936 33 27 61 72 42 206673418 10 82 23 34 29 77 90 39 9 67 34 71 29 95 49 48 60 69 86 64 94 77 48 74 19 96700186 5 67 881058074 663483223 64 64 78 23 8 60 7 17 96 71 70 20 5 63 3...
2CODEFORCES
309_D. Tennis Rackets_37937
Professional sport is more than hard work. It also is the equipment, designed by top engineers. As an example, let's take tennis. Not only should you be in great shape, you also need an excellent racket! In this problem your task is to contribute to the development of tennis and to help to design a revolutionary new co...
#include <bits/stdc++.h> using namespace std; int n, m; long long ans; int main() { scanf("%d%d", &n, &m); for (int i = m + 1; i <= (n + 1) / 2; i++) { int p = n + 1 - i; int q = 2 * i; for (int j = m + 1; j <= n - m; j++) { int tmp = (p * (q - j) - 1) / (i + j); int now = (((tmp) < (n - m))...
2C++
{ "input": [ "3 0\n", "4 0\n", "10 1\n", "8 4\n", "19000 5743\n", "50 4\n", "500 37\n", "20000 10000\n", "250 16\n", "10000 0\n", "2 0\n", "5123 323\n", "1000 141\n", "16756 4\n", "1 0\n", "16234 61\n", "12334 51\n", "23847 32\n", "24122 587\...
2CODEFORCES
309_D. Tennis Rackets_37938
Professional sport is more than hard work. It also is the equipment, designed by top engineers. As an example, let's take tennis. Not only should you be in great shape, you also need an excellent racket! In this problem your task is to contribute to the development of tennis and to help to design a revolutionary new co...
import static java.lang.System.currentTimeMillis; import java.io.*; import java.util.*; public class D { static void solve() throws IOException { // while (true) { // testWithVsWithout(); // if (false) { // break; // } // } // test(); int n = nextIn...
4JAVA
{ "input": [ "3 0\n", "4 0\n", "10 1\n", "8 4\n", "19000 5743\n", "50 4\n", "500 37\n", "20000 10000\n", "250 16\n", "10000 0\n", "2 0\n", "5123 323\n", "1000 141\n", "16756 4\n", "1 0\n", "16234 61\n", "12334 51\n", "23847 32\n", "24122 587\...
2CODEFORCES
332_B. Maximum Absurdity_37939
Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as n laws (each law has been assigned a unique number from 1 to n). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed. This time mr. Boosch plans to sign 2k l...
readintarray = lambda : map(int, raw_input().split(" ")) def check(s, ans, tans): res = s[ans[0] - 1] + s[ans[1] - 1] < s[tans[0] - 1] + s[tans[1] - 1] # print s, ans, tans # print res return res n, k = readintarray() a = readintarray() presum = [0] for i in a: presum.append(presum[-1] + i) #print p...
1Python2
{ "input": [ "6 2\n1 1 1 1 1 1\n", "5 2\n3 6 1 1 6\n", "4 1\n1 2 2 2\n", "3 1\n547468 78578678 6467834\n", "14 2\n2 1 2 3 1 2 2 3 1 2 2 3 2 3\n", "2 1\n1 1\n", "98 24\n91 20 12 75 44 22 22 67 28 100 8 41 31 47 95 87 5 54 7 49 32 46 42 37 45 22 29 15 54 98 46 94 69 47 60 1 15 76 17 82 46 22...
2CODEFORCES
332_B. Maximum Absurdity_37940
Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as n laws (each law has been assigned a unique number from 1 to n). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed. This time mr. Boosch plans to sign 2k l...
#include <bits/stdc++.h> using namespace std; int main() { int n, k, temp, idx = 0; long long sum = 0; cin >> n >> k; vector<long long> s; vector<long long> v; for (int i = 0; i < n; i++) { cin >> temp; v.push_back(temp); sum += temp; if ((i + 1) >= k) { s.push_back(sum); sum -= ...
2C++
{ "input": [ "6 2\n1 1 1 1 1 1\n", "5 2\n3 6 1 1 6\n", "4 1\n1 2 2 2\n", "3 1\n547468 78578678 6467834\n", "14 2\n2 1 2 3 1 2 2 3 1 2 2 3 2 3\n", "2 1\n1 1\n", "98 24\n91 20 12 75 44 22 22 67 28 100 8 41 31 47 95 87 5 54 7 49 32 46 42 37 45 22 29 15 54 98 46 94 69 47 60 1 15 76 17 82 46 22...
2CODEFORCES
332_B. Maximum Absurdity_37941
Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as n laws (each law has been assigned a unique number from 1 to n). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed. This time mr. Boosch plans to sign 2k l...
def main(): wynik = 0 para = (0,0) n,k = input().split() n,k = int(n), int(k) odl = [] tab = list(map(int, input().split())) pocz = tab[0] odl = [pocz] for i in range(1,n): if i < k : odl.append(odl[i-1]+tab[i]) else: odl.append(odl[i-1]+tab[i...
3Python3
{ "input": [ "6 2\n1 1 1 1 1 1\n", "5 2\n3 6 1 1 6\n", "4 1\n1 2 2 2\n", "3 1\n547468 78578678 6467834\n", "14 2\n2 1 2 3 1 2 2 3 1 2 2 3 2 3\n", "2 1\n1 1\n", "98 24\n91 20 12 75 44 22 22 67 28 100 8 41 31 47 95 87 5 54 7 49 32 46 42 37 45 22 29 15 54 98 46 94 69 47 60 1 15 76 17 82 46 22...
2CODEFORCES
332_B. Maximum Absurdity_37942
Reforms continue entering Berland. For example, during yesterday sitting the Berland Parliament approved as much as n laws (each law has been assigned a unique number from 1 to n). Today all these laws were put on the table of the President of Berland, G.W. Boosch, to be signed. This time mr. Boosch plans to sign 2k l...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.InputMismatchException; import java.util.Iterator; import java.util.LinkedList; import java.ut...
4JAVA
{ "input": [ "6 2\n1 1 1 1 1 1\n", "5 2\n3 6 1 1 6\n", "4 1\n1 2 2 2\n", "3 1\n547468 78578678 6467834\n", "14 2\n2 1 2 3 1 2 2 3 1 2 2 3 2 3\n", "2 1\n1 1\n", "98 24\n91 20 12 75 44 22 22 67 28 100 8 41 31 47 95 87 5 54 7 49 32 46 42 37 45 22 29 15 54 98 46 94 69 47 60 1 15 76 17 82 46 22...
2CODEFORCES
355_B. Vasya and Public Transport_37943
Vasya often uses public transport. The transport in the city is of two types: trolleys and buses. The city has n buses and m trolleys, the buses are numbered by integers from 1 to n, the trolleys are numbered by integers from 1 to m. Public transport is not free. There are 4 types of tickets: 1. A ticket for one r...
c = map(int, raw_input().split()) n, m = map(int, raw_input().split()) a = map(int, raw_input().split()) b = map(int, raw_input().split()) x = min(c[2], sum(min(c[1], ai * c[0]) for ai in a)) y = min(c[2], sum(min(c[1], bi * c[0]) for bi in b)) print min(c[3], x + y)
1Python2
{ "input": [ "4 3 2 1\n1 3\n798\n1 2 3\n", "100 100 8 100\n3 5\n7 94 12\n100 1 47 0 42\n", "1 3 7 19\n2 3\n2 5\n4 4 4\n", "3 103 945 1000\n7 9\n34 35 34 35 34 35 34\n0 0 0 0 0 0 0 0 0\n", "4 4 4 1\n1 1\n0\n0\n", "7 11 597 948\n4 1\n5 1 0 11\n7\n", "7 32 109 645\n1 3\n0\n0 0 0\n", "671 ...
2CODEFORCES
355_B. Vasya and Public Transport_37944
Vasya often uses public transport. The transport in the city is of two types: trolleys and buses. The city has n buses and m trolleys, the buses are numbered by integers from 1 to n, the trolleys are numbered by integers from 1 to m. Public transport is not free. There are 4 types of tickets: 1. A ticket for one r...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL); ; int arr[4]; for (int i = 0; i < 4; ++i) { cin >> arr[i]; } int n, m; cin >> n >> m; vector<int> b(n), t(m); for (int i = 0; i < n; ++i) { cin >> b[i]; } for (int i = 0;...
2C++
{ "input": [ "4 3 2 1\n1 3\n798\n1 2 3\n", "100 100 8 100\n3 5\n7 94 12\n100 1 47 0 42\n", "1 3 7 19\n2 3\n2 5\n4 4 4\n", "3 103 945 1000\n7 9\n34 35 34 35 34 35 34\n0 0 0 0 0 0 0 0 0\n", "4 4 4 1\n1 1\n0\n0\n", "7 11 597 948\n4 1\n5 1 0 11\n7\n", "7 32 109 645\n1 3\n0\n0 0 0\n", "671 ...
2CODEFORCES
355_B. Vasya and Public Transport_37945
Vasya often uses public transport. The transport in the city is of two types: trolleys and buses. The city has n buses and m trolleys, the buses are numbered by integers from 1 to n, the trolleys are numbered by integers from 1 to m. Public transport is not free. There are 4 types of tickets: 1. A ticket for one r...
c1,c2,c3 ,c4 = map(int,input().split()) n , m = map(int, input().split()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] ans1 = 0 ans2 = 0 for i in a: ans1 += min(c1 * i,c2) ans1 = min(ans1, c3) for i in b: ans2 += min(c1 * i,c2) ans2 = min(ans2, c3) ans = min(ans1 + ans2, c4) print...
3Python3
{ "input": [ "4 3 2 1\n1 3\n798\n1 2 3\n", "100 100 8 100\n3 5\n7 94 12\n100 1 47 0 42\n", "1 3 7 19\n2 3\n2 5\n4 4 4\n", "3 103 945 1000\n7 9\n34 35 34 35 34 35 34\n0 0 0 0 0 0 0 0 0\n", "4 4 4 1\n1 1\n0\n0\n", "7 11 597 948\n4 1\n5 1 0 11\n7\n", "7 32 109 645\n1 3\n0\n0 0 0\n", "671 ...
2CODEFORCES
355_B. Vasya and Public Transport_37946
Vasya often uses public transport. The transport in the city is of two types: trolleys and buses. The city has n buses and m trolleys, the buses are numbered by integers from 1 to n, the trolleys are numbered by integers from 1 to m. Public transport is not free. There are 4 types of tickets: 1. A ticket for one r...
import java.io.*; import java.util.*; public class cf355b { static FastIO in = new FastIO(), out = in; public static void main(String[] args) { int c1 = in.nextInt(), c2 = in.nextInt(), c3 = in.nextInt(), c4 = in.nextInt(); int n = in.nextInt(), m = in.nextInt(); int ans = 0, tmp = 0; for(int i=0;...
4JAVA
{ "input": [ "4 3 2 1\n1 3\n798\n1 2 3\n", "100 100 8 100\n3 5\n7 94 12\n100 1 47 0 42\n", "1 3 7 19\n2 3\n2 5\n4 4 4\n", "3 103 945 1000\n7 9\n34 35 34 35 34 35 34\n0 0 0 0 0 0 0 0 0\n", "4 4 4 1\n1 1\n0\n0\n", "7 11 597 948\n4 1\n5 1 0 11\n7\n", "7 32 109 645\n1 3\n0\n0 0 0\n", "671 ...
2CODEFORCES
379_C. New Year Ratings Change_37947
One very well-known internet resource site (let's call it X) has come up with a New Year adventure. Specifically, they decided to give ratings to all visitors. There are n users on the site, for each user we know the rating value he wants to get as a New Year Present. We know that user i wants to get at least ai ratin...
# -*- coding: utf-8 -*- import sys n = int(raw_input()) a = map(int, raw_input().split()) new_a = [] b = [0] * n for i in xrange(len(a)): new_a.append([a[i],i]) sorted_new_a = sorted(new_a, key=lambda x:x[0]) now = 1 for l in sorted_new_a: now = max(l[0], now) b[l[1]] = now now += 1 print ' '.join(ma...
1Python2
{ "input": [ "1\n1000000000\n", "3\n5 1 1\n", "10\n4 5 10 5 2 14 15 6 10 6\n", "10\n1 1 1 1 1 1 1 1 1 1\n", "10\n1 10 1 10 1 1 7 8 6 7\n", "10\n20 19 12 1 12 15 2 12 6 10\n", "10\n4 5 10 7 2 14 15 6 10 6\n", "10\n1 1 1 1 1 1 1 1 2 1\n", "10\n1 10 1 10 1 1 4 8 6 7\n", "10\n20 19...
2CODEFORCES
379_C. New Year Ratings Change_37948
One very well-known internet resource site (let's call it X) has come up with a New Year adventure. Specifically, they decided to give ratings to all visitors. There are n users on the site, for each user we know the rating value he wants to get as a New Year Present. We know that user i wants to get at least ai ratin...
#include <bits/stdc++.h> using namespace std; const int MX = 25; int main(int argc, char *argv[]) { int n; cin >> n; pair<int, int> a[n]; for (int i = (0), _b = (n); i < (_b); ++i) { cin >> a[i].first; a[i].second = i; } sort(a, a + n); int ans[n]; int cur = 0; for (int i = (0), _b = (n); i < ...
2C++
{ "input": [ "1\n1000000000\n", "3\n5 1 1\n", "10\n4 5 10 5 2 14 15 6 10 6\n", "10\n1 1 1 1 1 1 1 1 1 1\n", "10\n1 10 1 10 1 1 7 8 6 7\n", "10\n20 19 12 1 12 15 2 12 6 10\n", "10\n4 5 10 7 2 14 15 6 10 6\n", "10\n1 1 1 1 1 1 1 1 2 1\n", "10\n1 10 1 10 1 1 4 8 6 7\n", "10\n20 19...
2CODEFORCES
379_C. New Year Ratings Change_37949
One very well-known internet resource site (let's call it X) has come up with a New Year adventure. Specifically, they decided to give ratings to all visitors. There are n users on the site, for each user we know the rating value he wants to get as a New Year Present. We know that user i wants to get at least ai ratin...
n = int(input()) x = list(map(int, input().split())) ans = x.copy() b = sorted(x.copy()) k = b[0] + 1 d = {b[0]: [1, b[0]]} for i in range(1, n): if b[i - 1] == b[i]: d[b[i]].append(k) k += 1 else: if b[i] < k: d[b[i]] = [1, k] else: d[b[i]] = [1, b[i]] ...
3Python3
{ "input": [ "1\n1000000000\n", "3\n5 1 1\n", "10\n4 5 10 5 2 14 15 6 10 6\n", "10\n1 1 1 1 1 1 1 1 1 1\n", "10\n1 10 1 10 1 1 7 8 6 7\n", "10\n20 19 12 1 12 15 2 12 6 10\n", "10\n4 5 10 7 2 14 15 6 10 6\n", "10\n1 1 1 1 1 1 1 1 2 1\n", "10\n1 10 1 10 1 1 4 8 6 7\n", "10\n20 19...
2CODEFORCES
379_C. New Year Ratings Change_37950
One very well-known internet resource site (let's call it X) has come up with a New Year adventure. Specifically, they decided to give ratings to all visitors. There are n users on the site, for each user we know the rating value he wants to get as a New Year Present. We know that user i wants to get at least ai ratin...
import java.awt.*; import java.io.*; import java.math.BigDecimal; import java.math.BigInteger; import java.text.ParseException; import java.util.*; import java.util.List; import static java.lang.Math.max; public class Main implements Runnable { final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != nu...
4JAVA
{ "input": [ "1\n1000000000\n", "3\n5 1 1\n", "10\n4 5 10 5 2 14 15 6 10 6\n", "10\n1 1 1 1 1 1 1 1 1 1\n", "10\n1 10 1 10 1 1 7 8 6 7\n", "10\n20 19 12 1 12 15 2 12 6 10\n", "10\n4 5 10 7 2 14 15 6 10 6\n", "10\n1 1 1 1 1 1 1 1 2 1\n", "10\n1 10 1 10 1 1 4 8 6 7\n", "10\n20 19...
2CODEFORCES
39_J. Spelling Check_37951
Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, that’s why he d...
#!/usr/bin/python import os import sys import itertools import collections import string def solve(f): s1 = f.read_str() s2 = f.read_str() n = len(s1) c1 = collections.Counter(s1) c2 = collections.Counter(s2) ans1 = None for i in xrange(n-1): if s1[i] != s2[i]: ans1 =...
1Python2
{ "input": [ "competition\ncodeforces\n", "abdrakadabra\nabrakadabra\n", "aa\na\n", "babbbtaamba\nbabbbaabba\n", "vct\nie\n", "xdfxmcnzpch\nazvotghvtk\n", "aaaaaaaaaaa\naaaaaaaaaa\n", "feee\nsnl\n", "cccacaccacb\ncccacaccac\n", "ababcaabaaa\nabacaabaaa\n", "ki\nb\n", "b...
2CODEFORCES
39_J. Spelling Check_37952
Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, that’s why he d...
#include <bits/stdc++.h> using namespace std; void cp() { ios ::sync_with_stdio(false); cin.tie(0); cout.tie(0); } int main() { cp(); { string s, t; cin >> s >> t; if (s.length() == t.length() + 1) { long long m = 0; long long in = -1; char f; long long j = 0; for (lo...
2C++
{ "input": [ "competition\ncodeforces\n", "abdrakadabra\nabrakadabra\n", "aa\na\n", "babbbtaamba\nbabbbaabba\n", "vct\nie\n", "xdfxmcnzpch\nazvotghvtk\n", "aaaaaaaaaaa\naaaaaaaaaa\n", "feee\nsnl\n", "cccacaccacb\ncccacaccac\n", "ababcaabaaa\nabacaabaaa\n", "ki\nb\n", "b...
2CODEFORCES
39_J. Spelling Check_37953
Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, that’s why he d...
s,t=input(),input() n=idx=len(t) for i in range(n): if s[i]!=t[i]: idx=i break for i in range(idx+1,n+1): if s[i]!=t[i-1]: print(0) import sys sys.exit() i=idx while i>0 and s[i-1]==s[idx]: i-=1 print(idx-i+1) print(' '.join(map(str,range(i+1,idx+2))))
3Python3
{ "input": [ "competition\ncodeforces\n", "abdrakadabra\nabrakadabra\n", "aa\na\n", "babbbtaamba\nbabbbaabba\n", "vct\nie\n", "xdfxmcnzpch\nazvotghvtk\n", "aaaaaaaaaaa\naaaaaaaaaa\n", "feee\nsnl\n", "cccacaccacb\ncccacaccac\n", "ababcaabaaa\nabacaabaaa\n", "ki\nb\n", "b...
2CODEFORCES
39_J. Spelling Check_37954
Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right variant. Petya got fed up with correcting his mistakes himself, that’s why he d...
import java.util.Scanner; public class cf39j { final static long mod1 = (long)1e9+7; final static long mod2 = (long)1e9+9; final static long p1 = 137; final static long p2 = 179; public static void main(String []args){ Scanner cin = new Scanner(System.in); String str1,str2; ...
4JAVA
{ "input": [ "competition\ncodeforces\n", "abdrakadabra\nabrakadabra\n", "aa\na\n", "babbbtaamba\nbabbbaabba\n", "vct\nie\n", "xdfxmcnzpch\nazvotghvtk\n", "aaaaaaaaaaa\naaaaaaaaaa\n", "feee\nsnl\n", "cccacaccacb\ncccacaccac\n", "ababcaabaaa\nabacaabaaa\n", "ki\nb\n", "b...
2CODEFORCES
426_A. Sereja and Mugs_37955
Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and n water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all water from it into the cup. If the cup overfills, then we assume that...
# -*- coding:utf-8 -*- import sys def some_func(): """ """ n,s = map(int,raw_input().split(' ')) n_list = map(int,raw_input().split(' ')) n_list.sort() n_list.pop(-1) if sum(n_list) > s: print "NO" else: print "YES" if __name__ == '__main__': some_func() ...
1Python2
{ "input": [ "3 4\n1 1 1\n", "3 4\n3 1 3\n", "3 4\n4 4 4\n", "8 15\n8 10 4 2 10 9 7 6\n", "2 1\n1 10\n", "4 10\n6 3 8 7\n", "97 65\n3 10 2 6 1 4 7 5 10 3 10 4 5 5 1 6 10 7 4 5 3 9 9 8 6 9 2 3 6 8 5 5 5 5 5 3 10 4 1 8 8 9 8 4 1 4 9 3 6 3 1 4 8 3 10 8 6 4 5 4 3 2 2 4 3 6 4 6 2 3 3 3 7 5 1 8 ...
2CODEFORCES
426_A. Sereja and Mugs_37956
Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and n water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all water from it into the cup. If the cup overfills, then we assume that...
#include <bits/stdc++.h> using namespace std; int main() { int n, s, m, i, sum = 0; int a[101]; m = -1; scanf("%d%d", &n, &s); for (i = 0; i < n; i++) { scanf("%d", &a[i]); if (m < a[i]) { m = a[i]; } sum += a[i]; } if (sum - m <= s) { printf("YES\n"); } else { printf("NO\n...
2C++
{ "input": [ "3 4\n1 1 1\n", "3 4\n3 1 3\n", "3 4\n4 4 4\n", "8 15\n8 10 4 2 10 9 7 6\n", "2 1\n1 10\n", "4 10\n6 3 8 7\n", "97 65\n3 10 2 6 1 4 7 5 10 3 10 4 5 5 1 6 10 7 4 5 3 9 9 8 6 9 2 3 6 8 5 5 5 5 5 3 10 4 1 8 8 9 8 4 1 4 9 3 6 3 1 4 8 3 10 8 6 4 5 4 3 2 2 4 3 6 4 6 2 3 3 3 7 5 1 8 ...
2CODEFORCES
426_A. Sereja and Mugs_37957
Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and n water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all water from it into the cup. If the cup overfills, then we assume that...
n, s = map(int, input().split()) arr = list(map(int, input().split())) print("NO" if sum(arr) - max(arr) > s else "YES")
3Python3
{ "input": [ "3 4\n1 1 1\n", "3 4\n3 1 3\n", "3 4\n4 4 4\n", "8 15\n8 10 4 2 10 9 7 6\n", "2 1\n1 10\n", "4 10\n6 3 8 7\n", "97 65\n3 10 2 6 1 4 7 5 10 3 10 4 5 5 1 6 10 7 4 5 3 9 9 8 6 9 2 3 6 8 5 5 5 5 5 3 10 4 1 8 8 9 8 4 1 4 9 3 6 3 1 4 8 3 10 8 6 4 5 4 3 2 2 4 3 6 4 6 2 3 3 3 7 5 1 8 ...
2CODEFORCES
426_A. Sereja and Mugs_37958
Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and n water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pours all water from it into the cup. If the cup overfills, then we assume that...
import java.util.Arrays; import java.util.Scanner; public class Solution { public static void main(String[] args) throws Exception { Scanner in = new Scanner(System.in); int n = in.nextInt(), s = in.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) s -= a[i] = in.nextInt(); Arra...
4JAVA
{ "input": [ "3 4\n1 1 1\n", "3 4\n3 1 3\n", "3 4\n4 4 4\n", "8 15\n8 10 4 2 10 9 7 6\n", "2 1\n1 10\n", "4 10\n6 3 8 7\n", "97 65\n3 10 2 6 1 4 7 5 10 3 10 4 5 5 1 6 10 7 4 5 3 9 9 8 6 9 2 3 6 8 5 5 5 5 5 3 10 4 1 8 8 9 8 4 1 4 9 3 6 3 1 4 8 3 10 8 6 4 5 4 3 2 2 4 3 6 4 6 2 3 3 3 7 5 1 8 ...
2CODEFORCES
44_D. Hyperdrive_37959
In a far away galaxy there are n inhabited planets, numbered with numbers from 1 to n. They are located at large distances from each other, that's why the communication between them was very difficult until on the planet number 1 a hyperdrive was invented. As soon as this significant event took place, n - 1 spaceships ...
import sys import math n = int(sys.stdin.readline()) p = [] for i in range(n): p.append([int(i) for i in sys.stdin.readline().split()]) p[0].append(0) for i in range(1, n): p[i] = [p[i][0]-p[0][0], p[i][1]-p[0][1], p[i][2]-p[0][2], 0] p[i][3] = math.sqrt(p[i][0]**2+p[i][1]**2+p[i][2]**2) p.sort(key=lambd...
1Python2
{ "input": [ "4\n0 0 0\n0 0 1\n0 1 0\n1 0 0\n", "8\n-10000 -10000 -10000\n-10000 -10000 10000\n-10000 10000 -10000\n-10000 10000 10000\n10000 -10000 -10000\n10000 -10000 10000\n10000 10000 -10000\n10000 10000 10000\n", "5\n94 1 26\n-88 -26 32\n-32 -82 84\n22 -2 85\n-40 21 7\n", "10\n-9903 5249 7357\n1...
2CODEFORCES
44_D. Hyperdrive_37960
In a far away galaxy there are n inhabited planets, numbered with numbers from 1 to n. They are located at large distances from each other, that's why the communication between them was very difficult until on the planet number 1 a hyperdrive was invented. As soon as this significant event took place, n - 1 spaceships ...
#include <bits/stdc++.h> using namespace std; const int N = 5010; int x[N], y[N], z[N]; double sqr(double x) { return x * x; } double dis(int i, int j) { return sqrt(sqr(x[i] - x[j]) + sqr(y[i] - y[j]) + sqr(z[i] - z[j])); } int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d%d%d",...
2C++
{ "input": [ "4\n0 0 0\n0 0 1\n0 1 0\n1 0 0\n", "8\n-10000 -10000 -10000\n-10000 -10000 10000\n-10000 10000 -10000\n-10000 10000 10000\n10000 -10000 -10000\n10000 -10000 10000\n10000 10000 -10000\n10000 10000 10000\n", "5\n94 1 26\n-88 -26 32\n-32 -82 84\n22 -2 85\n-40 21 7\n", "10\n-9903 5249 7357\n1...
2CODEFORCES
44_D. Hyperdrive_37961
In a far away galaxy there are n inhabited planets, numbered with numbers from 1 to n. They are located at large distances from each other, that's why the communication between them was very difficult until on the planet number 1 a hyperdrive was invented. As soon as this significant event took place, n - 1 spaceships ...
//package school2; import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; public class D { Scanner in; PrintWriter out; // String INPUT = "4 0 0 0 0 0 1 0 1 0 1 0 0"; String INPUT = ""; void solve() { int n = ni(); int[] x = new int[n]; int[] y = new int[n]; int[] z = new int[n]...
4JAVA
{ "input": [ "4\n0 0 0\n0 0 1\n0 1 0\n1 0 0\n", "8\n-10000 -10000 -10000\n-10000 -10000 10000\n-10000 10000 -10000\n-10000 10000 10000\n10000 -10000 -10000\n10000 -10000 10000\n10000 10000 -10000\n10000 10000 10000\n", "5\n94 1 26\n-88 -26 32\n-32 -82 84\n22 -2 85\n-40 21 7\n", "10\n-9903 5249 7357\n1...
2CODEFORCES
495_A. Digital Counter_37962
Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each ...
n = raw_input() d=[2,7,2,3,3,4,2,5,1,2] print d[int(n[0])]*d[int(n[1])]
1Python2
{ "input": [ "00\n", "89\n", "73\n", "22\n", "90\n", "77\n", "35\n", "60\n", "80\n", "55\n", "44\n", "67\n", "99\n", "49\n", "04\n", "33\n", "88\n", "92\n", "26\n", "57\n", "20\n", "46\n", "05\n", "66\n", "78\n", "...
2CODEFORCES
495_A. Digital Counter_37963
Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each ...
#include <bits/stdc++.h> using namespace std; const long long mod1 = static_cast<long long>(1073741824); const long long mod2 = static_cast<long long>(1000000007); const long long INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7; const long double ldOne = 1.0; long long gcd(long long a, long long b) { if (!b) ...
2C++
{ "input": [ "00\n", "89\n", "73\n", "22\n", "90\n", "77\n", "35\n", "60\n", "80\n", "55\n", "44\n", "67\n", "99\n", "49\n", "04\n", "33\n", "88\n", "92\n", "26\n", "57\n", "20\n", "46\n", "05\n", "66\n", "78\n", "...
2CODEFORCES
495_A. Digital Counter_37964
Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each ...
from sys import stdin def nb_good_numbers(n): by_digit = { "0": 2, "1": 7, "2": 2, "3": 3, "4": 3, "5": 4, "6": 2, "7": 5, "8": 1, "9": 2, } result = 1 for digit in n: result *= by_digit[digit] return result ...
3Python3
{ "input": [ "00\n", "89\n", "73\n", "22\n", "90\n", "77\n", "35\n", "60\n", "80\n", "55\n", "44\n", "67\n", "99\n", "49\n", "04\n", "33\n", "88\n", "92\n", "26\n", "57\n", "20\n", "46\n", "05\n", "66\n", "78\n", "...
2CODEFORCES
495_A. Digital Counter_37965
Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by turning them on or off. The picture below shows how the elevator shows each ...
import java.util.Scanner; public class Elevator { public static void main(String[] args) { Scanner s = new Scanner(System.in); String floor=s.next(); int pos=1; for (int i = 0; i < 2; i++) { switch (floor.charAt(i)){ case '0': pos=pos*2; ...
4JAVA
{ "input": [ "00\n", "89\n", "73\n", "22\n", "90\n", "77\n", "35\n", "60\n", "80\n", "55\n", "44\n", "67\n", "99\n", "49\n", "04\n", "33\n", "88\n", "92\n", "26\n", "57\n", "20\n", "46\n", "05\n", "66\n", "78\n", "...
2CODEFORCES
519_D. A and B and Interesting Substrings_37966
A and B are preparing themselves for programming contests. After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes. A likes lowercase letters of the Latin alphabet. He has assigned to each letter a ...
assin = map(int, raw_input().split()) s = list(str(raw_input())) ssum = [assin[ord(s[0]) - ord('a')]] for i in range(1, len(s)): ssum.append(ssum[i-1] + assin[ord(s[i]) - ord('a')]) charsum = dict() charsum[(s[0], ssum[0])] = 1 ans = 0 for i in range(1, len(s)): if (s[i], ssum[i-1]) in charsum: ans = ...
1Python2
{ "input": [ "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\naaa\n", "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\nxabcab\n", "-2 -2 2 1 4 0 -2 4 5 4 -5 -5 2 1 1 -1 0 -5 -2 3 -2 4 5 2 3 -5\nqgzhbkitmqwttdyoyvcbxincwjryzknubpacsngorexaldfurondbednowemnnlphhboycfavsovisrmfaefusoobingjhsmrukx...
2CODEFORCES
519_D. A and B and Interesting Substrings_37967
A and B are preparing themselves for programming contests. After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes. A likes lowercase letters of the Latin alphabet. He has assigned to each letter a ...
#include <bits/stdc++.h> using namespace std; int val[26]; unordered_map<long long, int> ht[26]; int main() { ios::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); for (int i = 0; i < 26; ++i) cin >> val[i]; string str; cin >> str; long long cm = 0, ans = 0; for (int i = 0; i < ((int)(str).size()); ...
2C++
{ "input": [ "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\naaa\n", "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\nxabcab\n", "-2 -2 2 1 4 0 -2 4 5 4 -5 -5 2 1 1 -1 0 -5 -2 3 -2 4 5 2 3 -5\nqgzhbkitmqwttdyoyvcbxincwjryzknubpacsngorexaldfurondbednowemnnlphhboycfavsovisrmfaefusoobingjhsmrukx...
2CODEFORCES
519_D. A and B and Interesting Substrings_37968
A and B are preparing themselves for programming contests. After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes. A likes lowercase letters of the Latin alphabet. He has assigned to each letter a ...
xx = [int(i) for i in input().split()] s = input() x = [{} for _ in range(0,26)] ss = 0 ans = 0 for i in s: ans += x[ord(i)-97].get(ss,0) ss += xx[ord(i)-97] x[ord(i)-97][ss] = x[ord(i)-97].get(ss,0)+1 print(ans)
3Python3
{ "input": [ "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\naaa\n", "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\nxabcab\n", "-2 -2 2 1 4 0 -2 4 5 4 -5 -5 2 1 1 -1 0 -5 -2 3 -2 4 5 2 3 -5\nqgzhbkitmqwttdyoyvcbxincwjryzknubpacsngorexaldfurondbednowemnnlphhboycfavsovisrmfaefusoobingjhsmrukx...
2CODEFORCES
519_D. A and B and Interesting Substrings_37969
A and B are preparing themselves for programming contests. After several years of doing sports programming and solving many problems that require calculating all sorts of abstract objects, A and B also developed rather peculiar tastes. A likes lowercase letters of the Latin alphabet. He has assigned to each letter a ...
import java.util.HashMap; import java.util.Scanner; public class AAndBAndInterstingSubstrings { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] arr = new int[26]; for(int i=0;i<26;i++) arr[i] = sc.nextInt(); String s = sc.next(); HashMap<Long, Integer> map[] = new Has...
4JAVA
{ "input": [ "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\naaa\n", "1 1 -1 1 1 1 1 1 1 1 1 1 1 1 1 7 1 1 1 8 1 1 1 1 1 1\nxabcab\n", "-2 -2 2 1 4 0 -2 4 5 4 -5 -5 2 1 1 -1 0 -5 -2 3 -2 4 5 2 3 -5\nqgzhbkitmqwttdyoyvcbxincwjryzknubpacsngorexaldfurondbednowemnnlphhboycfavsovisrmfaefusoobingjhsmrukx...
2CODEFORCES
545_E. Paths and Trees_37970
Little girl Susie accidentally found her elder brother's notebook. She has many things to do, more important than solving problems, but she found this problem too interesting, so she wanted to know its solution and decided to ask you about it. So, the problem statement is as follows. Let's assume that we are given a c...
from collections import defaultdict,deque,Counter,OrderedDict from heapq import heappop,heappush def main(): n,m = map(int,raw_input().split()) adj = [[] for i in xrange(n+1)] for i in range(m): a,b,c = map(int,raw_input().split()) adj[a].append((b, c, i)) adj[b].append((a, c, i))...
1Python2
{ "input": [ "3 3\n1 2 1\n2 3 1\n1 3 2\n3\n", "4 4\n1 2 1\n2 3 1\n3 4 1\n4 1 2\n4\n", "6 8\n1 2 30\n1 3 20\n2 3 50\n4 2 100\n2 5 40\n3 5 10\n3 6 50\n5 6 60\n4\n", "2 1\n1 2 1000000000\n2\n", "1 0\n1\n", "4 5\n1 2 1\n1 3 1\n2 4 1\n3 4 1\n2 3 10\n1\n", "6 8\n1 2 30\n1 3 20\n2 3 50\n4 2 100\n...
2CODEFORCES
545_E. Paths and Trees_37971
Little girl Susie accidentally found her elder brother's notebook. She has many things to do, more important than solving problems, but she found this problem too interesting, so she wanted to know its solution and decided to ask you about it. So, the problem statement is as follows. Let's assume that we are given a c...
#include <bits/stdc++.h> using namespace std; const long long maxn = 3e5 + 10, Maxn = 1e5 + 10, SQ = 360, lg = 22; const long long mod = 1e9 + 7; const long long inf = 1e18 + 10; vector<pair<long long, long long>> adj[maxn]; long long d[maxn], p[maxn], n, m; map<pair<long long, long long>, pair<long long, long long>> m...
2C++
{ "input": [ "3 3\n1 2 1\n2 3 1\n1 3 2\n3\n", "4 4\n1 2 1\n2 3 1\n3 4 1\n4 1 2\n4\n", "6 8\n1 2 30\n1 3 20\n2 3 50\n4 2 100\n2 5 40\n3 5 10\n3 6 50\n5 6 60\n4\n", "2 1\n1 2 1000000000\n2\n", "1 0\n1\n", "4 5\n1 2 1\n1 3 1\n2 4 1\n3 4 1\n2 3 10\n1\n", "6 8\n1 2 30\n1 3 20\n2 3 50\n4 2 100\n...
2CODEFORCES
545_E. Paths and Trees_37972
Little girl Susie accidentally found her elder brother's notebook. She has many things to do, more important than solving problems, but she found this problem too interesting, so she wanted to know its solution and decided to ask you about it. So, the problem statement is as follows. Let's assume that we are given a c...
import heapq n, m = map(int, input().split()) g = [[] for _ in range(n + 1)] for i in range(1, m + 1): u, v, w = map(int, input().split()) g[u].append((i, v, w)) g[v].append((i, u, w)) src = int(input()) pq = [(0, 0, src, -1)] mk = [0] * (n + 1) t = [] s = 0 while pq: d, w, u, e = heapq.heappop(pq) ...
3Python3
{ "input": [ "3 3\n1 2 1\n2 3 1\n1 3 2\n3\n", "4 4\n1 2 1\n2 3 1\n3 4 1\n4 1 2\n4\n", "6 8\n1 2 30\n1 3 20\n2 3 50\n4 2 100\n2 5 40\n3 5 10\n3 6 50\n5 6 60\n4\n", "2 1\n1 2 1000000000\n2\n", "1 0\n1\n", "4 5\n1 2 1\n1 3 1\n2 4 1\n3 4 1\n2 3 10\n1\n", "6 8\n1 2 30\n1 3 20\n2 3 50\n4 2 100\n...
2CODEFORCES
545_E. Paths and Trees_37973
Little girl Susie accidentally found her elder brother's notebook. She has many things to do, more important than solving problems, but she found this problem too interesting, so she wanted to know its solution and decided to ask you about it. So, the problem statement is as follows. Let's assume that we are given a c...
import java.io.*; import java.util.*; public class P303E { public static void main(String args[]){ Reader s = new Reader(); int n = s.nextInt(); int m = s.nextInt(); List<Edge> li[] = new ArrayList[n]; for(int i=0;i<n;i++){ li[i] = new ArrayList<>(); ...
4JAVA
{ "input": [ "3 3\n1 2 1\n2 3 1\n1 3 2\n3\n", "4 4\n1 2 1\n2 3 1\n3 4 1\n4 1 2\n4\n", "6 8\n1 2 30\n1 3 20\n2 3 50\n4 2 100\n2 5 40\n3 5 10\n3 6 50\n5 6 60\n4\n", "2 1\n1 2 1000000000\n2\n", "1 0\n1\n", "4 5\n1 2 1\n1 3 1\n2 4 1\n3 4 1\n2 3 10\n1\n", "6 8\n1 2 30\n1 3 20\n2 3 50\n4 2 100\n...
2CODEFORCES
572_B. Order Book_37974
In this task you need to process a set of stock exchange orders and use them to create order book. An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number i has price pi, direction di — buy or sell, and integer qi. This means that the participant is ready to buy or sell...
from collections import defaultdict n, q = map(int, raw_input().split()) b = defaultdict(int) s = defaultdict(int) for i in xrange(n): a = raw_input().split() if a[0] == "B": b[int(a[1])] += int(a[2]) elif a[0] == "S": s[int(a[1])] += int(a[2]) v = sorted(s.keys())[:q][::-1] for k in v: print "S", k, s[k] v = so...
1Python2
{ "input": [ "6 2\nB 10 3\nS 50 2\nS 40 1\nS 50 6\nB 20 4\nB 25 10\n", "2 2\nS 1 1\nB 0 2\n", "2 1\nS 1 1\nB 0 1\n", "2 10\nB 0 1\nS 100000 1\n", "2 50\nB 758 9290\nS 86168 3367\n", "2 2\nB 0 3\nS 10 3\n", "3 3\nB 5878 1568\nS 60238 4895\nS 76276 1905\n", "1 1\nS 95992 7257\n", "2 ...
2CODEFORCES
572_B. Order Book_37975
In this task you need to process a set of stock exchange orders and use them to create order book. An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number i has price pi, direction di — buy or sell, and integer qi. This means that the participant is ready to buy or sell...
#include <bits/stdc++.h> using namespace std; map<int, long long> mb; map<int, long long> ms; map<int, long long>::iterator it; map<int, long long>::reverse_iterator it2; vector<pair<int, long long> > v; int main() { int n, s, i, p, q; char ch; cin >> n >> s; for (i = 1; i <= n; i++) { cin >> ch; scanf(...
2C++
{ "input": [ "6 2\nB 10 3\nS 50 2\nS 40 1\nS 50 6\nB 20 4\nB 25 10\n", "2 2\nS 1 1\nB 0 2\n", "2 1\nS 1 1\nB 0 1\n", "2 10\nB 0 1\nS 100000 1\n", "2 50\nB 758 9290\nS 86168 3367\n", "2 2\nB 0 3\nS 10 3\n", "3 3\nB 5878 1568\nS 60238 4895\nS 76276 1905\n", "1 1\nS 95992 7257\n", "2 ...
2CODEFORCES
572_B. Order Book_37976
In this task you need to process a set of stock exchange orders and use them to create order book. An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number i has price pi, direction di — buy or sell, and integer qi. This means that the participant is ready to buy or sell...
n,s = [int(x) for x in input().split()] buy_dict = {} sell_dict = {} for i in range(n): chtype,pi,di = input().split() pi = int(pi) di = int(di) if chtype=='B': buy_dict[pi] = buy_dict.get(pi,0)+di else: sell_dict[pi] = sell_dict.get(pi,0)+di buy_list = sorted(buy_dict.items(),reverse=True)[:s] sell_list = rev...
3Python3
{ "input": [ "6 2\nB 10 3\nS 50 2\nS 40 1\nS 50 6\nB 20 4\nB 25 10\n", "2 2\nS 1 1\nB 0 2\n", "2 1\nS 1 1\nB 0 1\n", "2 10\nB 0 1\nS 100000 1\n", "2 50\nB 758 9290\nS 86168 3367\n", "2 2\nB 0 3\nS 10 3\n", "3 3\nB 5878 1568\nS 60238 4895\nS 76276 1905\n", "1 1\nS 95992 7257\n", "2 ...
2CODEFORCES
572_B. Order Book_37977
In this task you need to process a set of stock exchange orders and use them to create order book. An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number i has price pi, direction di — buy or sell, and integer qi. This means that the participant is ready to buy or sell...
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Comparator; import java.util.Iterator; import java.util.Map; import java.ut...
4JAVA
{ "input": [ "6 2\nB 10 3\nS 50 2\nS 40 1\nS 50 6\nB 20 4\nB 25 10\n", "2 2\nS 1 1\nB 0 2\n", "2 1\nS 1 1\nB 0 1\n", "2 10\nB 0 1\nS 100000 1\n", "2 50\nB 758 9290\nS 86168 3367\n", "2 2\nB 0 3\nS 10 3\n", "3 3\nB 5878 1568\nS 60238 4895\nS 76276 1905\n", "1 1\nS 95992 7257\n", "2 ...
2CODEFORCES
593_E. Strange Calculation and Cats_37978
Gosha's universe is a table consisting of n rows and m columns. Both the rows and columns are numbered with consecutive integers starting with 1. We will use (r, c) to denote a cell located in the row r and column c. Gosha is often invited somewhere. Every time he gets an invitation, he first calculates the number of ...
#include <bits/stdc++.h> using namespace std; const int N = 22; int n, m, q, last, vi[N][N]; int dx[5] = {0, -1, 1, 0, 0}; int dy[5] = {0, 0, 0, -1, 1}; inline void add(int &a, int b) { a = ((a + b >= 1000000007) ? a + b - 1000000007 : a + b); } inline void del(int &a, int b) { a = ((a - b < 0) ? a - b + 1000000007...
2C++
{ "input": [ "3 3 3\n2 2 2 2\n1 3 3 5\n1 3 3 7\n", "4 5 5\n2 2 5 3\n2 2 4 6\n3 2 4 9\n1 4 4 13\n1 4 4 15\n", "1 3 3\n2 1 2 3\n3 1 2 5\n1 1 1 7\n", "1 20 2\n1 1 20 100000001\n1 1 20 1000000000\n", "2 2 5\n2 1 1 8\n3 1 1 12345\n2 1 2 22345\n3 1 2 31243\n1 2 2 111115\n", "3 3 1\n1 3 3 5\n", "...
2CODEFORCES
593_E. Strange Calculation and Cats_37979
Gosha's universe is a table consisting of n rows and m columns. Both the rows and columns are numbered with consecutive integers starting with 1. We will use (r, c) to denote a cell located in the row r and column c. Gosha is often invited somewhere. Every time he gets an invitation, he first calculates the number of ...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { Input...
4JAVA
{ "input": [ "3 3 3\n2 2 2 2\n1 3 3 5\n1 3 3 7\n", "4 5 5\n2 2 5 3\n2 2 4 6\n3 2 4 9\n1 4 4 13\n1 4 4 15\n", "1 3 3\n2 1 2 3\n3 1 2 5\n1 1 1 7\n", "1 20 2\n1 1 20 100000001\n1 1 20 1000000000\n", "2 2 5\n2 1 1 8\n3 1 1 12345\n2 1 2 22345\n3 1 2 31243\n1 2 2 111115\n", "3 3 1\n1 3 3 5\n", "...
2CODEFORCES
615_C. Running Track_37980
A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art. First, he wants to construct the running track with coating t. On planet AMI-1511 the coating of the tra...
s = raw_input() t = raw_input() rev = s[::-1] t=t+"#" ans=[] temp=t[0] n=len(s) for i in xrange(1,len(t)): cur = temp+t[i] if cur in s or cur in rev: temp=cur else: if temp in s: start = s.find(temp) ans.append((start+1,start+len(temp))) elif temp in rev: ...
1Python2
{ "input": [ "ami\nno\n", "abc\ncbaabc\n", "aaabrytaaa\nayrat\n", "hhhhhhh\nhhhhhhh\n", "ababaaaabaaaaaaaaaaaba\nbabaaabbaaaabbaaaabaaa\n", "qwerty\nywertyrewqqq\n", "aaaaaabaa\na\n", "woohoowhenifeelheavymetalwoohooandimpinsandimneedles\nwoohoowellilieandimeasyallthetimebutimneversure...
2CODEFORCES
615_C. Running Track_37981
A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art. First, he wants to construct the running track with coating t. On planet AMI-1511 the coating of the tra...
#include <bits/stdc++.h> using namespace std; const int INF = 2e9; const int N = 2105; int dp[N], lcp[N][N], lcpr[N][N], lmatch[N]; pair<int, int> subs[N]; int par[N]; string s, t; int n, m; void print(int idx) { if (idx != 0) print(par[idx]); cout << subs[idx].first + 1 << " " << subs[idx].second + 1 << "\n"; } in...
2C++
{ "input": [ "ami\nno\n", "abc\ncbaabc\n", "aaabrytaaa\nayrat\n", "hhhhhhh\nhhhhhhh\n", "ababaaaabaaaaaaaaaaaba\nbabaaabbaaaabbaaaabaaa\n", "qwerty\nywertyrewqqq\n", "aaaaaabaa\na\n", "woohoowhenifeelheavymetalwoohooandimpinsandimneedles\nwoohoowellilieandimeasyallthetimebutimneversure...
2CODEFORCES
615_C. Running Track_37982
A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art. First, he wants to construct the running track with coating t. On planet AMI-1511 the coating of the tra...
def find_max_substr(t, s): l, r = 0, len(t) while l != r: m = (l + r) // 2 if t[:m + 1] in s: l = m + 1 else: r = m l1 = l rs = s[::-1] l, r = 0, len(t) while l != r: m = (l + r) // 2 if t[:m + 1] in rs: l = m + 1 ...
3Python3
{ "input": [ "ami\nno\n", "abc\ncbaabc\n", "aaabrytaaa\nayrat\n", "hhhhhhh\nhhhhhhh\n", "ababaaaabaaaaaaaaaaaba\nbabaaabbaaaabbaaaabaaa\n", "qwerty\nywertyrewqqq\n", "aaaaaabaa\na\n", "woohoowhenifeelheavymetalwoohooandimpinsandimneedles\nwoohoowellilieandimeasyallthetimebutimneversure...
2CODEFORCES
615_C. Running Track_37983
A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art. First, he wants to construct the running track with coating t. On planet AMI-1511 the coating of the tra...
import java.io.InputStream; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.InputMismatchException; import java.util.NoSuchElementException; import java.math.BigInteger; public class Mai...
4JAVA
{ "input": [ "ami\nno\n", "abc\ncbaabc\n", "aaabrytaaa\nayrat\n", "hhhhhhh\nhhhhhhh\n", "ababaaaabaaaaaaaaaaaba\nbabaaabbaaaabbaaaabaaa\n", "qwerty\nywertyrewqqq\n", "aaaaaabaa\na\n", "woohoowhenifeelheavymetalwoohooandimpinsandimneedles\nwoohoowellilieandimeasyallthetimebutimneversure...
2CODEFORCES
634_E. Preorder Test_37984
For his computer science class, Jacob builds a model tree with sticks and balls containing n nodes in the shape of a tree. Jacob has spent ai minutes building the i-th ball in the tree. Jacob's teacher will evaluate his model and grade Jacob based on the effort he has put in. However, she does not have enough time to ...
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; int in[maxn], in1[maxn]; int dp[maxn]; int dp1[maxn]; int dp2[maxn]; int s[maxn]; int vis[maxn]; int dp3[maxn]; vector<int> g[maxn]; int a[maxn]; int k; int flag; void dfs(int u, int pa) { int p = g[u].size(); dp1[u] = 1; vis[u] = 1; for (in...
2C++
{ "input": [ "4 2\n1 5 5 5\n1 2\n1 3\n1 4\n", "5 3\n3 6 1 4 2\n1 2\n2 4\n2 5\n1 3\n", "2 2\n1 1000000\n1 2\n", "10 4\n104325 153357 265088 777795 337716 557321 702646 734430 464449 744072\n9 4\n8 1\n10 7\n8 6\n7 9\n8 2\n3 5\n8 3\n10 8\n", "2 1\n1 100000\n2 1\n", "10 10\n794273 814140 758469 93...
2CODEFORCES
634_E. Preorder Test_37985
For his computer science class, Jacob builds a model tree with sticks and balls containing n nodes in the shape of a tree. Jacob has spent ai minutes building the i-th ball in the tree. Jacob's teacher will evaluate his model and grade Jacob based on the effort he has put in. However, she does not have enough time to ...
import sys input = sys.stdin.readline n, k = map(int, input().split()) a = [int(i) for i in input().split()] g = [[] for _ in range(n)] for i in range(n - 1): u, v = map(int, input().split()) g[u-1].append(v-1) g[v-1].append(u-1) stack = [0] done = [False] * n par = [0] * n order = [] while len(stack) > 0: x = sta...
3Python3
{ "input": [ "4 2\n1 5 5 5\n1 2\n1 3\n1 4\n", "5 3\n3 6 1 4 2\n1 2\n2 4\n2 5\n1 3\n", "2 2\n1 1000000\n1 2\n", "10 4\n104325 153357 265088 777795 337716 557321 702646 734430 464449 744072\n9 4\n8 1\n10 7\n8 6\n7 9\n8 2\n3 5\n8 3\n10 8\n", "2 1\n1 100000\n2 1\n", "10 10\n794273 814140 758469 93...
2CODEFORCES
634_E. Preorder Test_37986
For his computer science class, Jacob builds a model tree with sticks and balls containing n nodes in the shape of a tree. Jacob has spent ai minutes building the i-th ball in the tree. Jacob's teacher will evaluate his model and grade Jacob based on the effort he has put in. However, she does not have enough time to ...
import java.io.*; import java.util.*; public class D_new { BufferedReader br; PrintWriter out; StringTokenizer st; boolean eof; List<Integer>[] g; int[] size; int[] bad; int[] dpDown; int[] fullMax2; int[] fullMax; int[] fullWhoMax; int[] dpFull; int[] a; int n; int totBad; int curBest; void d...
4JAVA
{ "input": [ "4 2\n1 5 5 5\n1 2\n1 3\n1 4\n", "5 3\n3 6 1 4 2\n1 2\n2 4\n2 5\n1 3\n", "2 2\n1 1000000\n1 2\n", "10 4\n104325 153357 265088 777795 337716 557321 702646 734430 464449 744072\n9 4\n8 1\n10 7\n8 6\n7 9\n8 2\n3 5\n8 3\n10 8\n", "2 1\n1 100000\n2 1\n", "10 10\n794273 814140 758469 93...
2CODEFORCES
663_C. Graph Coloring_37987
You are given an undirected graph that consists of n vertices and m edges. Initially, each edge is colored either red or blue. Each turn a player picks a single vertex and switches the color of all edges incident to it. That is, all red edges with an endpoint in this vertex change the color to blue, while all blue edge...
n, e = map(int, raw_input().strip().split()) adj1 = [[] for i in xrange(n)] adj2 = [[] for i in xrange(n)] for i in xrange(e): a, b, c = raw_input().strip().split() a = int(a) - 1 b = int(b) - 1 if c == 'B': adj1[a].append((b, 0)) adj1[b].append((a, 0)) adj2[a].append((b, 1)) ...
1Python2
{ "input": [ "6 5\n1 3 R\n2 3 R\n3 4 B\n4 5 R\n4 6 R\n", "3 3\n1 2 B\n3 1 R\n3 2 B\n", "4 5\n1 2 R\n1 3 R\n2 3 B\n3 4 B\n1 4 B\n", "2 1\n1 2 B\n", "3 3\n1 2 R\n1 3 R\n2 3 R\n", "11 7\n1 2 B\n1 3 R\n3 2 R\n4 5 R\n6 7 R\n8 9 R\n10 11 R\n", "6 6\n1 2 R\n1 3 R\n2 3 R\n4 5 B\n4 6 B\n5 6 B\n", ...
2CODEFORCES
663_C. Graph Coloring_37988
You are given an undirected graph that consists of n vertices and m edges. Initially, each edge is colored either red or blue. Each turn a player picks a single vertex and switches the color of all edges incident to it. That is, all red edges with an endpoint in this vertex change the color to blue, while all blue edge...
#include <bits/stdc++.h> using namespace std; int INT_MAX_VAL = (int)0x3F3F3F3F; int INT_MIN_VAL = (int)-0x3F3F3F3F; long long LONG_MAX_VAL = (long long)0x3F3F3F3F3F3F3F3F; long long LONG_MIN_VAL = (long long)-0x3F3F3F3F3F3F3F3F; int colors[500006]; vector<pair<int, char> > graph[500006]; int n, m; int dfs(int v, char ...
2C++
{ "input": [ "6 5\n1 3 R\n2 3 R\n3 4 B\n4 5 R\n4 6 R\n", "3 3\n1 2 B\n3 1 R\n3 2 B\n", "4 5\n1 2 R\n1 3 R\n2 3 B\n3 4 B\n1 4 B\n", "2 1\n1 2 B\n", "3 3\n1 2 R\n1 3 R\n2 3 R\n", "11 7\n1 2 B\n1 3 R\n3 2 R\n4 5 R\n6 7 R\n8 9 R\n10 11 R\n", "6 6\n1 2 R\n1 3 R\n2 3 R\n4 5 B\n4 6 B\n5 6 B\n", ...
2CODEFORCES
663_C. Graph Coloring_37989
You are given an undirected graph that consists of n vertices and m edges. Initially, each edge is colored either red or blue. Each turn a player picks a single vertex and switches the color of all edges incident to it. That is, all red edges with an endpoint in this vertex change the color to blue, while all blue edge...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.io.InputStream; /** * Built using CHel...
4JAVA
{ "input": [ "6 5\n1 3 R\n2 3 R\n3 4 B\n4 5 R\n4 6 R\n", "3 3\n1 2 B\n3 1 R\n3 2 B\n", "4 5\n1 2 R\n1 3 R\n2 3 B\n3 4 B\n1 4 B\n", "2 1\n1 2 B\n", "3 3\n1 2 R\n1 3 R\n2 3 R\n", "11 7\n1 2 B\n1 3 R\n3 2 R\n4 5 R\n6 7 R\n8 9 R\n10 11 R\n", "6 6\n1 2 R\n1 3 R\n2 3 R\n4 5 B\n4 6 B\n5 6 B\n", ...
2CODEFORCES
688_A. Opponents_37990
Arya has n opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya...
n,d = map(int, raw_input().split()) f = [0 for i in xrange(d)] ans = 0 cnt = 0 for i in xrange(d): s = raw_input() if s.count('0'): cnt += 1 else: cnt = 0 ans = max(ans, cnt) print ans
1Python2
{ "input": [ "4 5\n1101\n1111\n0110\n1011\n1111\n", "2 2\n10\n00\n", "4 1\n0100\n", "1 100\n0\n0\n0\n0\n1\n0\n0\n0\n0\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n...
2CODEFORCES
688_A. Opponents_37991
Arya has n opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya...
#include <bits/stdc++.h> using namespace std; const int maxn = 105; int n, d, ans, hahaha[maxn]; char s[maxn]; bool pd[maxn]; int main() { scanf("%d%d", &n, &d); for (int i = 1; i <= d; i++) { scanf("%s", s + 1); for (int j = 1; j <= n; j++) if (s[j] == '0') pd[i] = 1; } for (int i = 1; i <= d; i+...
2C++
{ "input": [ "4 5\n1101\n1111\n0110\n1011\n1111\n", "2 2\n10\n00\n", "4 1\n0100\n", "1 100\n0\n0\n0\n0\n1\n0\n0\n0\n0\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n...
2CODEFORCES
688_A. Opponents_37992
Arya has n opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya...
import math from typing import Iterable, List def solve(arr:Iterable[str], n: int) -> int: curr = 0 res = 0 for v in arr: if v == '1'*n: curr = 0 else : curr += 1 res = max(res , curr) return res def main(): n,d = map(int, input().split(' ')) arr = [] for i in...
3Python3
{ "input": [ "4 5\n1101\n1111\n0110\n1011\n1111\n", "2 2\n10\n00\n", "4 1\n0100\n", "1 100\n0\n0\n0\n0\n1\n0\n0\n0\n0\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n...
2CODEFORCES
688_A. Opponents_37993
Arya has n opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if one day at least one of Arya's opponents is absent at the school, then Arya...
function constructOnes(n) { var str = ""; for (var i = 0; i < n; i++) { str += '1'; } return str; } var input = readline().trim().split(' ').map(Number); var n = input[0], d = input[1], result = [0], matchStr = constructOnes(n), consecutive = false; for (var i = 0; i < d; i++) { var str = readline().tri...
4JAVA
{ "input": [ "4 5\n1101\n1111\n0110\n1011\n1111\n", "2 2\n10\n00\n", "4 1\n0100\n", "1 100\n0\n0\n0\n0\n1\n0\n0\n0\n0\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n...
2CODEFORCES
70_E. Information Reform_37994
Thought it is already the XXI century, the Mass Media isn't very popular in Walrusland. The cities get news from messengers who can only travel along roads. The network of roads in Walrusland is built so that it is possible to get to any city from any other one in exactly one way, and the roads' lengths are equal. The...
#include <bits/stdc++.h> using namespace std; int n, c; int a[205]; vector<int> e[205]; int d[205][205], f[205][205], p[205], b[205]; void dfs(int k, int fa) { for (int i = 0; i < n; ++i) { f[k][i] = a[d[k][i]] + c; } for (int i = 0; i < e[k].size(); ++i) { int u = e[k][i]; if (fa == u) continue; ...
2C++
{ "input": [ "8 10\n2 5 9 11 15 19 20\n1 4\n1 3\n1 7\n4 6\n2 8\n2 3\n3 5\n", "6 10\n1 4 7 11 13\n4 6\n3 4\n3 5\n1 2\n2 4\n", "6 10\n1 6 11 16 20\n4 6\n2 3\n1 2\n2 4\n2 5\n", "10 172\n67 157 223 307 383 451 510 587 684\n6 7\n4 6\n2 10\n1 6\n7 9\n1 5\n1 2\n3 4\n4 8\n", "5 1000\n0 0 100 100\n1 2\n2 5...
2CODEFORCES
70_E. Information Reform_37995
Thought it is already the XXI century, the Mass Media isn't very popular in Walrusland. The cities get news from messengers who can only travel along roads. The network of roads in Walrusland is built so that it is possible to get to any city from any other one in exactly one way, and the roads' lengths are equal. The...
import java.io.*; import java.util.*; public class E{ long[][][]cached; int[][][]by; int[][]g; long[]cost; int K; long inf=Integer.MAX_VALUE; int n; ArrayList<Integer>centers; void solve()throws Exception { centers=new ArrayList<Integer>(); n=nextInt(); K=nextInt(); cost=new long[n+1]; cost[n]=...
4JAVA
{ "input": [ "8 10\n2 5 9 11 15 19 20\n1 4\n1 3\n1 7\n4 6\n2 8\n2 3\n3 5\n", "6 10\n1 4 7 11 13\n4 6\n3 4\n3 5\n1 2\n2 4\n", "6 10\n1 6 11 16 20\n4 6\n2 3\n1 2\n2 4\n2 5\n", "10 172\n67 157 223 307 383 451 510 587 684\n6 7\n4 6\n2 10\n1 6\n7 9\n1 5\n1 2\n3 4\n4 8\n", "5 1000\n0 0 100 100\n1 2\n2 5...
2CODEFORCES
730_L. Expression Queries_37996
A simplified arithmetic expression (SAE) is an arithmetic expression defined by the following grammar: * <SAE> ::= <Number> | <SAE>+<SAE> | <SAE>*<SAE> | (<SAE>) * <Number> ::= <Digit> | <Digit><Number> * <Digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 In other words it's a correct arithmetic expression tha...
#include <bits/stdc++.h> using namespace std; int n, q, l, r, st[400500], ct, bel[400500], pw[400500], su[400500], lb[400500], rb[400500], as[400500], v1[400500], sl[400500], sr[400500], tp[400500], vl[400500]; char s[400500]; struct qu1 { int l, r, id; }; vector<qu1> qu[400500]; int calc(int l, int r) { re...
2C++
{ "input": [ "(01)\n1\n1 4\n", "((1+2)*3+101*2)\n6\n8 14\n1 6\n2 10\n11 14\n5 5\n4 5\n", "1\n1\n1 1\n", "104+12\n1\n2 5\n", "(1)\n6\n1 1\n1 2\n1 3\n2 2\n2 3\n3 3\n", "(1)\n4\n2 2\n1 2\n2 3\n1 3\n", "(435+234234*234234*(2134+2323))\n8\n2 30\n1 31\n5 8\n3 14\n13 17\n10 30\n3 4\n3 7\n", "...
2CODEFORCES
755_B. PolandBall and Game_37997
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses. You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, i...
n, m = map(int, raw_input().split()) n_list = [] m_list = [] for i in xrange(n): n_list.append(raw_input()) for j in xrange(m): m_list.append(raw_input()) if n > m: print 'YES' elif m > n: print 'NO' else: if (len(set(n_list+m_list)) % 2) == 0: print 'NO' else: print 'YES'
1Python2
{ "input": [ "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska\n", "5 1\npolandball\nis\na\ncool\ncharacter\nnope\n", "1 2\na\na\nb\n", "3 2\na\nb\nc\nd\ne\n", "6 5\na\nb\nc\nd\ne\nf\nf\ne\nd\nz\ny\n", "1 1\naa\naa\n", "2 2\na\nb\nb\nc\n", "3 3\nab\nbc\ncd\ncd\ndf\nfg\n", "2 1\na\nb\n...
2CODEFORCES
755_B. PolandBall and Game_37998
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses. You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, i...
#include <bits/stdc++.h> using namespace std; int main() { int n, m; while (cin >> n >> m) { string st1[1005], st2[1005]; for (int i = 1; i <= n; i++) cin >> st1[i]; for (int i = 1; i <= m; i++) cin >> st2[i]; int ans = 0; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) i...
2C++
{ "input": [ "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska\n", "5 1\npolandball\nis\na\ncool\ncharacter\nnope\n", "1 2\na\na\nb\n", "3 2\na\nb\nc\nd\ne\n", "6 5\na\nb\nc\nd\ne\nf\nf\ne\nd\nz\ny\n", "1 1\naa\naa\n", "2 2\na\nb\nb\nc\n", "3 3\nab\nbc\ncd\ncd\ndf\nfg\n", "2 1\na\nb\n...
2CODEFORCES
755_B. PolandBall and Game_37999
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses. You're given two lists of words familiar to PolandBall and EnemyBall. Can you determine who wins the game, i...
import sys input = sys.stdin.readline n, m = input().split() n = int(n) m = int(m) polW = [] eneW = [] turnsP = 0 turnsE = 0 same = 0 for i in range(n): polW.append(input()) turnsP+=1 for i in range(m): word = input() if word in polW: turnsP-=1 same+=1 else: turnsE...
3Python3
{ "input": [ "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska\n", "5 1\npolandball\nis\na\ncool\ncharacter\nnope\n", "1 2\na\na\nb\n", "3 2\na\nb\nc\nd\ne\n", "6 5\na\nb\nc\nd\ne\nf\nf\ne\nd\nz\ny\n", "1 1\naa\naa\n", "2 2\na\nb\nb\nc\n", "3 3\nab\nbc\ncd\ncd\ndf\nfg\n", "2 1\na\nb\n...
2CODEFORCES