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
1330_B. Dreamoon Likes Permutations_38200
The sequence of m integers is called the permutation if it contains all integers from 1 to m exactly once. The number m is called the length of the permutation. Dreamoon has two permutations p_1 and p_2 of non-zero lengths l_1 and l_2. Now Dreamoon concatenates these two permutations into another sequence a of length...
#include <bits/stdc++.h> using namespace std; int main() { unordered_set<int> st; int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n); for (int& x : a) { cin >> x; } st.clear(); int max_a = 0; unordered_set<int> idx1; for (int i = 0; i < n; i++) { max...
2C++
{ "input": [ "6\n5\n1 4 3 2 1\n6\n2 4 1 3 2 1\n4\n2 1 1 3\n4\n1 3 3 1\n12\n2 1 3 4 5 6 7 8 9 1 10 2\n3\n1 1 1\n", "6\n5\n1 4 3 1 1\n6\n2 4 1 3 2 1\n4\n2 1 1 3\n4\n1 3 3 1\n12\n2 1 3 4 5 6 7 8 9 1 10 2\n3\n1 1 1\n", "6\n5\n1 4 3 2 1\n6\n2 4 1 3 3 1\n4\n2 1 1 3\n4\n1 3 3 1\n12\n2 1 3 4 5 6 7 8 9 1 10 2\n3\n...
2CODEFORCES
1330_B. Dreamoon Likes Permutations_38201
The sequence of m integers is called the permutation if it contains all integers from 1 to m exactly once. The number m is called the length of the permutation. Dreamoon has two permutations p_1 and p_2 of non-zero lengths l_1 and l_2. Now Dreamoon concatenates these two permutations into another sequence a of length...
import sys input = sys.stdin.readline Q = int(input()) Query = [] for _ in range(Q): N = int(input()) A = list(map(int, input().split())) Query.append((N, A)) for N, A in Query: leftOK = [True]*(N+1) already = set() MAX = 0 for i, a in enumerate(A): if a in already: ok ...
3Python3
{ "input": [ "6\n5\n1 4 3 2 1\n6\n2 4 1 3 2 1\n4\n2 1 1 3\n4\n1 3 3 1\n12\n2 1 3 4 5 6 7 8 9 1 10 2\n3\n1 1 1\n", "6\n5\n1 4 3 1 1\n6\n2 4 1 3 2 1\n4\n2 1 1 3\n4\n1 3 3 1\n12\n2 1 3 4 5 6 7 8 9 1 10 2\n3\n1 1 1\n", "6\n5\n1 4 3 2 1\n6\n2 4 1 3 3 1\n4\n2 1 1 3\n4\n1 3 3 1\n12\n2 1 3 4 5 6 7 8 9 1 10 2\n3\n...
2CODEFORCES
1330_B. Dreamoon Likes Permutations_38202
The sequence of m integers is called the permutation if it contains all integers from 1 to m exactly once. The number m is called the length of the permutation. Dreamoon has two permutations p_1 and p_2 of non-zero lengths l_1 and l_2. Now Dreamoon concatenates these two permutations into another sequence a of length...
import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { static long sx = 0, sy = 0, mod = (long) (1e9 + 7); static ArrayList<Integer>[] a; static long[][][] dp; static int[] size; static long[] farr; public static PrintWriter out; static ArrayList<pair> pa = new ArrayList<>(); ...
4JAVA
{ "input": [ "6\n5\n1 4 3 2 1\n6\n2 4 1 3 2 1\n4\n2 1 1 3\n4\n1 3 3 1\n12\n2 1 3 4 5 6 7 8 9 1 10 2\n3\n1 1 1\n", "6\n5\n1 4 3 1 1\n6\n2 4 1 3 2 1\n4\n2 1 1 3\n4\n1 3 3 1\n12\n2 1 3 4 5 6 7 8 9 1 10 2\n3\n1 1 1\n", "6\n5\n1 4 3 2 1\n6\n2 4 1 3 3 1\n4\n2 1 1 3\n4\n1 3 3 1\n12\n2 1 3 4 5 6 7 8 9 1 10 2\n3\n...
2CODEFORCES
1350_B. Orac and Models_38203
There are n models in the shop numbered from 1 to n, with sizes s_1, s_2, …, s_n. Orac will buy some of the models and will arrange them in the order of increasing numbers (i.e. indices, but not sizes). Orac thinks that the obtained arrangement is beatiful, if for any two adjacent models with indices i_j and i_{j+1} ...
T = input() dp = {} def solve(X): if X in dp: return dp[X] if X == 1: return 1 mox = 1 for i in xrange(1, int(X**0.5)+1): if X % i == 0: if i != 1 and ll[X-1] > ll[X//i - 1]: now = solve(X//i) + 1 mox = max(now, mox) if ...
1Python2
{ "input": [ "4\n4\n5 3 4 6\n7\n1 4 2 3 6 4 9\n5\n5 4 3 2 1\n1\n9\n", "4\n23\n3198 4895 1585 3881 2650 2366 876 2731 1052 126 2152 3621 2169 4103 1074 2594 2897 3983 3830 3460 729 576 3281\n1\n1000000000\n2\n1 1\n100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34...
2CODEFORCES
1350_B. Orac and Models_38204
There are n models in the shop numbered from 1 to n, with sizes s_1, s_2, …, s_n. Orac will buy some of the models and will arrange them in the order of increasing numbers (i.e. indices, but not sizes). Orac thinks that the obtained arrangement is beatiful, if for any two adjacent models with indices i_j and i_{j+1} ...
#include <bits/stdc++.h> using namespace std; long long int arr[100005], dp[100005]; int main() { int t, n, k; cin >> t; while (t--) { cin >> n; for (int i = 1; i <= n; i++) cin >> arr[i]; long long int res = 0; memset(dp, 0, sizeof(dp)); for (int i = 1; i <= n; i++) { dp[i] = 1; l...
2C++
{ "input": [ "4\n4\n5 3 4 6\n7\n1 4 2 3 6 4 9\n5\n5 4 3 2 1\n1\n9\n", "4\n23\n3198 4895 1585 3881 2650 2366 876 2731 1052 126 2152 3621 2169 4103 1074 2594 2897 3983 3830 3460 729 576 3281\n1\n1000000000\n2\n1 1\n100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34...
2CODEFORCES
1350_B. Orac and Models_38205
There are n models in the shop numbered from 1 to n, with sizes s_1, s_2, …, s_n. Orac will buy some of the models and will arrange them in the order of increasing numbers (i.e. indices, but not sizes). Orac thinks that the obtained arrangement is beatiful, if for any two adjacent models with indices i_j and i_{j+1} ...
import sys import math t=int(sys.stdin.readline()) for _ in range(t): n=int(sys.stdin.readline()) arr=list(map(int,sys.stdin.readline().split())) dp=[1 for x in range(n+1)] for i in range(n-1,0,-1): j=i*2 cnt=2 cur=1 while j<=n: y=dp[j] if arr[j-1...
3Python3
{ "input": [ "4\n4\n5 3 4 6\n7\n1 4 2 3 6 4 9\n5\n5 4 3 2 1\n1\n9\n", "4\n23\n3198 4895 1585 3881 2650 2366 876 2731 1052 126 2152 3621 2169 4103 1074 2594 2897 3983 3830 3460 729 576 3281\n1\n1000000000\n2\n1 1\n100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34...
2CODEFORCES
1350_B. Orac and Models_38206
There are n models in the shop numbered from 1 to n, with sizes s_1, s_2, …, s_n. Orac will buy some of the models and will arrange them in the order of increasing numbers (i.e. indices, but not sizes). Orac thinks that the obtained arrangement is beatiful, if for any two adjacent models with indices i_j and i_{j+1} ...
import java.math.*; import java.io.*; import java.util.*; public class Solution { static long[] a; static int max; public static void main(String[] args) throws IOException{ FastScanner sc = new FastScanner(System.in); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); int t = sc.next...
4JAVA
{ "input": [ "4\n4\n5 3 4 6\n7\n1 4 2 3 6 4 9\n5\n5 4 3 2 1\n1\n9\n", "4\n23\n3198 4895 1585 3881 2650 2366 876 2731 1052 126 2152 3621 2169 4103 1074 2594 2897 3983 3830 3460 729 576 3281\n1\n1000000000\n2\n1 1\n100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34...
2CODEFORCES
1370_E. Binary Subsequence Rotation_38207
Naman has two binary strings s and t of length n (a binary string is a string which only consists of the characters "0" and "1"). He wants to convert s into t using the following operation as few times as possible. In one operation, he can choose any subsequence of s and rotate it clockwise once. For example, if s = ...
import sys n=input() s=raw_input() t=raw_input() d1={} d2={} for i in s: d1[i]=d1.get(i,0)+1 for i in t: d2[i]=d2.get(i,0)+1 if d1!=d2: print -1 sys.exit() d=[0]*n for i in range(n): if s[i]=='0' and t[i]=='1': d[i]=-1 if s[i]=='1' and t[i]=='0': d[i]=1 ct1=0 ct2=0 c=0 for i in d...
1Python2
{ "input": [ "10\n1111100000\n1111100001\n", "6\n010000\n000001\n", "10\n1111100000\n0000011111\n", "8\n10101010\n01010101\n", "10\n1010111110\n1011101101\n", "12\n011001010101\n111001010101\n", "10\n1100000100\n0010000011\n", "10\n0111101111\n0111111110\n", "3\n000\n000\n", "5...
2CODEFORCES
1370_E. Binary Subsequence Rotation_38208
Naman has two binary strings s and t of length n (a binary string is a string which only consists of the characters "0" and "1"). He wants to convert s into t using the following operation as few times as possible. In one operation, he can choose any subsequence of s and rotate it clockwise once. For example, if s = ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 7; string s[2]; int a[maxn]; int n; int main() { cin >> n; cin >> s[0] >> s[1]; for (int i = 1; i <= n; ++i) { a[i] = a[i - 1]; if (s[0][i - 1] == '1' && s[1][i - 1] == '0') a[i]++; if (s[0][i - 1] == '0' && s[1][i - 1] == '1') a[i]-...
2C++
{ "input": [ "10\n1111100000\n1111100001\n", "6\n010000\n000001\n", "10\n1111100000\n0000011111\n", "8\n10101010\n01010101\n", "10\n1010111110\n1011101101\n", "12\n011001010101\n111001010101\n", "10\n1100000100\n0010000011\n", "10\n0111101111\n0111111110\n", "3\n000\n000\n", "5...
2CODEFORCES
1370_E. Binary Subsequence Rotation_38209
Naman has two binary strings s and t of length n (a binary string is a string which only consists of the characters "0" and "1"). He wants to convert s into t using the following operation as few times as possible. In one operation, he can choose any subsequence of s and rotate it clockwise once. For example, if s = ...
# -*- coding: utf-8 -*- """ @author: Saurav Sihag """ rr = lambda: input().strip() # rri = lambda: int(rr()) rri = lambda: int(stdin.readline()) rrm = lambda: [int(x) for x in rr().split()] # stdout.write(str()+'\n') from sys import stdin, stdout def sol(): n=rri() s=rr() t=rr() cnt=0 mn=0 mx...
3Python3
{ "input": [ "10\n1111100000\n1111100001\n", "6\n010000\n000001\n", "10\n1111100000\n0000011111\n", "8\n10101010\n01010101\n", "10\n1010111110\n1011101101\n", "12\n011001010101\n111001010101\n", "10\n1100000100\n0010000011\n", "10\n0111101111\n0111111110\n", "3\n000\n000\n", "5...
2CODEFORCES
1370_E. Binary Subsequence Rotation_38210
Naman has two binary strings s and t of length n (a binary string is a string which only consists of the characters "0" and "1"). He wants to convert s into t using the following operation as few times as possible. In one operation, he can choose any subsequence of s and rotate it clockwise once. For example, if s = ...
import java.io.*; import java.util.*; import java.util.stream.*; import static java.util.stream.Collectors.*; public class Main { void solve() { int n = in.nextInt(); String a = in.nextLine(); String b = in.nextLine(); List<Boolean> list = new ArrayList<>(); for (int i = 0;...
4JAVA
{ "input": [ "10\n1111100000\n1111100001\n", "6\n010000\n000001\n", "10\n1111100000\n0000011111\n", "8\n10101010\n01010101\n", "10\n1010111110\n1011101101\n", "12\n011001010101\n111001010101\n", "10\n1100000100\n0010000011\n", "10\n0111101111\n0111111110\n", "3\n000\n000\n", "5...
2CODEFORCES
1393_A. Rainbow Dash, Fluttershy and Chess Coloring_38211
One evening Rainbow Dash and Fluttershy have come up with a game. Since the ponies are friends, they have decided not to compete in the game but to pursue a common goal. The game starts on a square flat grid, which initially has the outline borders built up. Rainbow Dash and Fluttershy have flat square blocks with si...
# Author: yumtam # Created at: 2020-09-10 11:35 from __future__ import division, print_function _interactive = False def main(): for _ in range(int(input())): n = int(input()) print((n+2)//2) # Constants INF = float('inf') MOD = 10**9+7 # Python3 equivalent names import os, sys, itertools i...
1Python2
{ "input": [ "2\n3\n4\n", "1\n10000001\n", "1\n69\n", "1\n10001001\n", "1\n70\n", "2\n2\n4\n", "1\n11001001\n", "1\n29\n", "1\n11011001\n", "1\n30\n", "1\n01001001\n", "1\n25\n", "1\n19\n", "1\n00001000\n", "1\n00001100\n", "1\n13\n", "1\n00001110\n"...
2CODEFORCES
1393_A. Rainbow Dash, Fluttershy and Chess Coloring_38212
One evening Rainbow Dash and Fluttershy have come up with a game. Since the ponies are friends, they have decided not to compete in the game but to pursue a common goal. The game starts on a square flat grid, which initially has the outline borders built up. Rainbow Dash and Fluttershy have flat square blocks with si...
#include <bits/stdc++.h> using namespace std; long long binpow(long long a, long long b) { if (b == 0) return 1; long long res = binpow(a, b / 2); res *= res; if (b % 2) return res * a; return res; } long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } string to_upper(st...
2C++
{ "input": [ "2\n3\n4\n", "1\n10000001\n", "1\n69\n", "1\n10001001\n", "1\n70\n", "2\n2\n4\n", "1\n11001001\n", "1\n29\n", "1\n11011001\n", "1\n30\n", "1\n01001001\n", "1\n25\n", "1\n19\n", "1\n00001000\n", "1\n00001100\n", "1\n13\n", "1\n00001110\n"...
2CODEFORCES
1393_A. Rainbow Dash, Fluttershy and Chess Coloring_38213
One evening Rainbow Dash and Fluttershy have come up with a game. Since the ponies are friends, they have decided not to compete in the game but to pursue a common goal. The game starts on a square flat grid, which initially has the outline borders built up. Rainbow Dash and Fluttershy have flat square blocks with si...
for i in range(int(input())): n = int(input()) res = int(n/2)+1 print(res)
3Python3
{ "input": [ "2\n3\n4\n", "1\n10000001\n", "1\n69\n", "1\n10001001\n", "1\n70\n", "2\n2\n4\n", "1\n11001001\n", "1\n29\n", "1\n11011001\n", "1\n30\n", "1\n01001001\n", "1\n25\n", "1\n19\n", "1\n00001000\n", "1\n00001100\n", "1\n13\n", "1\n00001110\n"...
2CODEFORCES
1393_A. Rainbow Dash, Fluttershy and Chess Coloring_38214
One evening Rainbow Dash and Fluttershy have come up with a game. Since the ponies are friends, they have decided not to compete in the game but to pursue a common goal. The game starts on a square flat grid, which initially has the outline borders built up. Rainbow Dash and Fluttershy have flat square blocks with si...
import java.io.*; import java.util.*; public class RainbowDashFlutterflyAndChessColoring { static class InputReader { BufferedReader reader; StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); ...
4JAVA
{ "input": [ "2\n3\n4\n", "1\n10000001\n", "1\n69\n", "1\n10001001\n", "1\n70\n", "2\n2\n4\n", "1\n11001001\n", "1\n29\n", "1\n11011001\n", "1\n30\n", "1\n01001001\n", "1\n25\n", "1\n19\n", "1\n00001000\n", "1\n00001100\n", "1\n13\n", "1\n00001110\n"...
2CODEFORCES
1417_F. Graph and Queries_38215
You are given an undirected graph consisting of n vertices and m edges. Initially there is a single integer written on every vertex: the vertex i has p_i written on it. All p_i are distinct integers from 1 to n. You have to process q queries of two types: * 1 v — among all vertices reachable from the vertex v using...
#include <bits/stdc++.h> using namespace std; using LL = long long; using LD = long double; using PII = pair<int, int>; using PLL = pair<LL, LL>; using PLD = pair<LD, LD>; using VI = vector<int>; using VLL = vector<LL>; using VLD = vector<LD>; using VPII = vector<PII>; using VPLL = vector<PLL>; using VPLD = vector<PLD>...
2C++
{ "input": [ "5 4 6\n1 2 5 4 3\n1 2\n2 3\n1 3\n4 5\n1 1\n2 1\n2 3\n1 1\n1 2\n1 2\n", "9 5 14\n7 1 4 8 5 2 6 9 3\n2 8\n1 6\n5 7\n1 3\n3 9\n1 5\n1 8\n1 5\n1 4\n1 8\n1 3\n1 5\n1 5\n1 7\n1 7\n2 3\n1 2\n1 1\n1 2\n", "2 1 3\n1 2\n1 2\n1 1\n1 1\n1 1\n", "6 5 8\n1 2 6 3 4 5\n2 4\n1 3\n1 6\n3 5\n2 5\n1 1\n1 4\...
2CODEFORCES
1434_D. Roads and Ramen_38216
In the Land of Fire there are n villages and n-1 bidirectional road, and there is a path between any pair of villages by roads. There are only two types of roads: stone ones and sand ones. Since the Land of Fire is constantly renovating, every morning workers choose a single road and flip its type (so it becomes a ston...
#include <bits/stdc++.h> using namespace std; template <typename T1, typename T2> string print_iterable(T1 begin_iter, T2 end_iter, int counter) { bool done_something = false; stringstream res; res << "["; for (; begin_iter != end_iter and counter; ++begin_iter) { done_something = true; counter--; r...
2C++
{ "input": [ "5\n1 2 0\n1 3 0\n3 5 0\n3 4 0\n5\n3\n4\n1\n3\n4\n", "5\n2 4 0\n5 2 0\n1 3 1\n1 2 1\n5\n3\n3\n4\n1\n1\n", "10\n5 7 0\n2 10 1\n1 5 0\n6 8 0\n4 9 1\n2 5 1\n10 8 0\n2 3 1\n4 2 1\n10\n9\n9\n9\n5\n2\n5\n7\n2\n3\n2\n", "2\n2 1 1\n10\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n", "20\n9 11 0\n1 5 0\n1 14...
2CODEFORCES
1434_D. Roads and Ramen_38217
In the Land of Fire there are n villages and n-1 bidirectional road, and there is a path between any pair of villages by roads. There are only two types of roads: stone ones and sand ones. Since the Land of Fire is constantly renovating, every morning workers choose a single road and flip its type (so it becomes a ston...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.IOException; import java.util.ArrayList; import java.io.UncheckedIOException; import java.util.List; import java.io.Closeable; import java.io.Writer; import java.io.OutputStreamWriter; import...
4JAVA
{ "input": [ "5\n1 2 0\n1 3 0\n3 5 0\n3 4 0\n5\n3\n4\n1\n3\n4\n", "5\n2 4 0\n5 2 0\n1 3 1\n1 2 1\n5\n3\n3\n4\n1\n1\n", "10\n5 7 0\n2 10 1\n1 5 0\n6 8 0\n4 9 1\n2 5 1\n10 8 0\n2 3 1\n4 2 1\n10\n9\n9\n9\n5\n2\n5\n7\n2\n3\n2\n", "2\n2 1 1\n10\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n", "20\n9 11 0\n1 5 0\n1 14...
2CODEFORCES
145_B. Lucky Number 2_38218
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves long lucky numbers very much. He is interested in the minimum lucky number d that meet...
a, b, c, d = map(int, raw_input().split()) if max(c, d) - min(c, d) >= 2 or min(a, b) < max(c, d): print -1 exit() if max(c, d) == 0: if a > 0 and b > 0: print -1 else: print '4' * a + '7' * b else: if c == d: if max(a, b) == c: print -1 elif a == c: ...
1Python2
{ "input": [ "4 7 3 1\n", "2 2 1 1\n", "3 3 2 2\n", "69 84 25 24\n", "4 4 2 2\n", "4 58458 2 1\n", "8 3 2 1\n", "25 94 11 12\n", "45 65 31 32\n", "1 1000 2 1\n", "4 3 2 1\n", "2 100000 1 2\n", "4 4 1 1\n", "2 1 3 1\n", "6 6 1 3\n", "10 10 1 2\n", "1 ...
2CODEFORCES
145_B. Lucky Number 2_38219
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves long lucky numbers very much. He is interested in the minimum lucky number d that meet...
#include <bits/stdc++.h> using namespace std; int main(int argc, char const *argv[]) { int a1, a2, a3, a4; cin >> a1 >> a2 >> a3 >> a4; string s = ""; if (abs(a3 - a4) > 1 || min(a1, a2) < max(a3, a4) || (a3 == a4 && max(a1, a2) <= a3)) { cout << -1; return 0; } else { if (a3 > a4) { w...
2C++
{ "input": [ "4 7 3 1\n", "2 2 1 1\n", "3 3 2 2\n", "69 84 25 24\n", "4 4 2 2\n", "4 58458 2 1\n", "8 3 2 1\n", "25 94 11 12\n", "45 65 31 32\n", "1 1000 2 1\n", "4 3 2 1\n", "2 100000 1 2\n", "4 4 1 1\n", "2 1 3 1\n", "6 6 1 3\n", "10 10 1 2\n", "1 ...
2CODEFORCES
145_B. Lucky Number 2_38220
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves long lucky numbers very much. He is interested in the minimum lucky number d that meet...
a1,a2,a3,a4=map(int,input().split()) L=[] def Solve(a1,a2,a3,a4): if(a3-a4<-1 or a3-a4>1 or a1<a3 or a1<a4 or a2<a3 or a2<a4): return -1 elif(a3-a4==0): Ans="47"*a3 Ans+="4" if(a1-a3==0 and a2-a4==0): return -1 elif(a1-a3==0): return "74"*a3+"7"*...
3Python3
{ "input": [ "4 7 3 1\n", "2 2 1 1\n", "3 3 2 2\n", "69 84 25 24\n", "4 4 2 2\n", "4 58458 2 1\n", "8 3 2 1\n", "25 94 11 12\n", "45 65 31 32\n", "1 1000 2 1\n", "4 3 2 1\n", "2 100000 1 2\n", "4 4 1 1\n", "2 1 3 1\n", "6 6 1 3\n", "10 10 1 2\n", "1 ...
2CODEFORCES
145_B. Lucky Number 2_38221
Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya loves long lucky numbers very much. He is interested in the minimum lucky number d that meet...
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public ...
4JAVA
{ "input": [ "4 7 3 1\n", "2 2 1 1\n", "3 3 2 2\n", "69 84 25 24\n", "4 4 2 2\n", "4 58458 2 1\n", "8 3 2 1\n", "25 94 11 12\n", "45 65 31 32\n", "1 1000 2 1\n", "4 3 2 1\n", "2 100000 1 2\n", "4 4 1 1\n", "2 1 3 1\n", "6 6 1 3\n", "10 10 1 2\n", "1 ...
2CODEFORCES
1485_D. Multiples and Power Differences_38222
You are given a matrix a consisting of positive integers. It has n rows and m columns. Construct a matrix b consisting of positive integers. It should have the same size as a, and the following conditions should be met: * 1 ≤ b_{i,j} ≤ 10^6; * b_{i,j} is a multiple of a_{i,j}; * the absolute value of the dif...
from collections import Counter, defaultdict, deque import bisect from sys import stdin, stdout from itertools import repeat import math def inp(force_list=False): re = map(int, raw_input().split()) if len(re) == 1 and not force_list: return re[0] return re def inst(): return raw_input().stri...
1Python2
{ "input": [ "2 3\n16 16 16\n16 16 16\n", "2 2\n1 2\n2 3\n", "2 2\n3 11\n12 8\n", "2 3\n16 16 11\n16 16 16\n", "2 2\n1 2\n3 3\n", "2 2\n6 11\n12 8\n", "2 2\n1 2\n2 5\n", "2 2\n1 2\n4 3\n", "2 2\n1 1\n4 3\n", "2 2\n1 1\n8 3\n", "2 2\n6 10\n12 8\n", "1 2\n1 2\n2 0\n", ...
2CODEFORCES
1485_D. Multiples and Power Differences_38223
You are given a matrix a consisting of positive integers. It has n rows and m columns. Construct a matrix b consisting of positive integers. It should have the same size as a, and the following conditions should be met: * 1 ≤ b_{i,j} ≤ 10^6; * b_{i,j} is a multiple of a_{i,j}; * the absolute value of the dif...
#include <bits/stdc++.h> #define ll long long #define inf 0x3f3f3f3f #define INF 0x3f3f3f3f3f3f3f3f #define PI acos(-1) #define pb push_back #define F first #define S second #define lson i << 1 #define rson i << 1 | 1 #define mem(x, y) memset(x, y, sizeof(x)) #define fin(x) freopen(x, "r", stdin) #define fout(x) freope...
2C++
{ "input": [ "2 3\n16 16 16\n16 16 16\n", "2 2\n1 2\n2 3\n", "2 2\n3 11\n12 8\n", "2 3\n16 16 11\n16 16 16\n", "2 2\n1 2\n3 3\n", "2 2\n6 11\n12 8\n", "2 2\n1 2\n2 5\n", "2 2\n1 2\n4 3\n", "2 2\n1 1\n4 3\n", "2 2\n1 1\n8 3\n", "2 2\n6 10\n12 8\n", "1 2\n1 2\n2 0\n", ...
2CODEFORCES
1485_D. Multiples and Power Differences_38224
You are given a matrix a consisting of positive integers. It has n rows and m columns. Construct a matrix b consisting of positive integers. It should have the same size as a, and the following conditions should be met: * 1 ≤ b_{i,j} ≤ 10^6; * b_{i,j} is a multiple of a_{i,j}; * the absolute value of the dif...
n, m = list(map(int, input().split())) matrix = [] for i in range(n): row = list(map(int, input().split())) matrix.append(row) #print(matrix) res = [ [ 0 for i in range(m) ] for j in range(n) ] for i in range(n): for j in range(m): if (i + j) % 2: res[i][j] = 720720 + matrix[i][j] *...
3Python3
{ "input": [ "2 3\n16 16 16\n16 16 16\n", "2 2\n1 2\n2 3\n", "2 2\n3 11\n12 8\n", "2 3\n16 16 11\n16 16 16\n", "2 2\n1 2\n3 3\n", "2 2\n6 11\n12 8\n", "2 2\n1 2\n2 5\n", "2 2\n1 2\n4 3\n", "2 2\n1 1\n4 3\n", "2 2\n1 1\n8 3\n", "2 2\n6 10\n12 8\n", "1 2\n1 2\n2 0\n", ...
2CODEFORCES
1485_D. Multiples and Power Differences_38225
You are given a matrix a consisting of positive integers. It has n rows and m columns. Construct a matrix b consisting of positive integers. It should have the same size as a, and the following conditions should be met: * 1 ≤ b_{i,j} ≤ 10^6; * b_{i,j} is a multiple of a_{i,j}; * the absolute value of the dif...
import static java.lang.Math.*; import static java.util.Arrays.*; import java.math.*; import java.util.stream.*; public class D { public Object solve () { int N = sc.nextInt(), M = sc.nextInt(); int [][] A = sc.nextInts(N); int [][] res = new int [N][M]; int X = (int) lcm(req(1, 16)); for (int [] r : res...
4JAVA
{ "input": [ "2 3\n16 16 16\n16 16 16\n", "2 2\n1 2\n2 3\n", "2 2\n3 11\n12 8\n", "2 3\n16 16 11\n16 16 16\n", "2 2\n1 2\n3 3\n", "2 2\n6 11\n12 8\n", "2 2\n1 2\n2 5\n", "2 2\n1 2\n4 3\n", "2 2\n1 1\n4 3\n", "2 2\n1 1\n8 3\n", "2 2\n6 10\n12 8\n", "1 2\n1 2\n2 0\n", ...
2CODEFORCES
150_B. Quantity of Strings_38226
Just in case somebody missed it: this winter is totally cold in Nvodsk! It is so cold that one gets funny thoughts. For example, let's say there are strings with the length exactly n, based on the alphabet of size m. Any its substring with length equal to k is a palindrome. How many such strings exist? Your task is to ...
n,m,k = map(int,raw_input().split()) if k==1 or n<k: p=n elif n==k: p=n//2+n%2 else: p=1+k%2 r=1 for i in range(p): r=(r*m)%1000000007 print r
1Python2
{ "input": [ "1 1 1\n", "5 2 4\n", "784 1 1999\n", "1000 2 1\n", "341 9 342\n", "4 4 1\n", "7 10 7\n", "13 9 1\n", "100 5 1\n", "239 123 239\n", "7 4 20\n", "1501 893 1501\n", "10 25 8\n", "5 4 5\n", "5 5 5\n", "345 1777 1\n", "5 2 5\n", "10 2 1\...
2CODEFORCES
150_B. Quantity of Strings_38227
Just in case somebody missed it: this winter is totally cold in Nvodsk! It is so cold that one gets funny thoughts. For example, let's say there are strings with the length exactly n, based on the alphabet of size m. Any its substring with length equal to k is a palindrome. How many such strings exist? Your task is to ...
#include <bits/stdc++.h> using namespace std; long long int N, M, K; int main(void) { cin >> N >> M >> K; if (K > N) { long long int Sol = 1LL; for (int i = 0; i < N; i++) Sol = (Sol * M) % 1000000007LL; cout << Sol << endl; return 0; } if (K == N) { long long int Sol = 1LL; for (int i =...
2C++
{ "input": [ "1 1 1\n", "5 2 4\n", "784 1 1999\n", "1000 2 1\n", "341 9 342\n", "4 4 1\n", "7 10 7\n", "13 9 1\n", "100 5 1\n", "239 123 239\n", "7 4 20\n", "1501 893 1501\n", "10 25 8\n", "5 4 5\n", "5 5 5\n", "345 1777 1\n", "5 2 5\n", "10 2 1\...
2CODEFORCES
150_B. Quantity of Strings_38228
Just in case somebody missed it: this winter is totally cold in Nvodsk! It is so cold that one gets funny thoughts. For example, let's say there are strings with the length exactly n, based on the alphabet of size m. Any its substring with length equal to k is a palindrome. How many such strings exist? Your task is to ...
n,m,k = map(int,input().split()) mod = 10**9 + 7 if k == 1 or k>n: print(pow(m,n,mod)) elif k == n: print(pow(m,(n+1)//2,mod)) elif k%2== 0: print(m%mod) else: print(pow(m,2,mod))
3Python3
{ "input": [ "1 1 1\n", "5 2 4\n", "784 1 1999\n", "1000 2 1\n", "341 9 342\n", "4 4 1\n", "7 10 7\n", "13 9 1\n", "100 5 1\n", "239 123 239\n", "7 4 20\n", "1501 893 1501\n", "10 25 8\n", "5 4 5\n", "5 5 5\n", "345 1777 1\n", "5 2 5\n", "10 2 1\...
2CODEFORCES
150_B. Quantity of Strings_38229
Just in case somebody missed it: this winter is totally cold in Nvodsk! It is so cold that one gets funny thoughts. For example, let's say there are strings with the length exactly n, based on the alphabet of size m. Any its substring with length equal to k is a palindrome. How many such strings exist? Your task is to ...
import java.io.PrintWriter; import java.util.Scanner; public class Main { public static void main(String[] argv) { new Main().run(); } void run() { in = new Scanner(System.in); out = new PrintWriter(System.out); try { solve(); } finally { out.close(); } } PrintWriter out; Scanner in; int m...
4JAVA
{ "input": [ "1 1 1\n", "5 2 4\n", "784 1 1999\n", "1000 2 1\n", "341 9 342\n", "4 4 1\n", "7 10 7\n", "13 9 1\n", "100 5 1\n", "239 123 239\n", "7 4 20\n", "1501 893 1501\n", "10 25 8\n", "5 4 5\n", "5 5 5\n", "345 1777 1\n", "5 2 5\n", "10 2 1\...
2CODEFORCES
1535_F. String Distance_38230
Suppose you are given two strings a and b. You can apply the following operation any number of times: choose any contiguous substring of a or b, and sort the characters in it in non-descending order. Let f(a, b) the minimum number of operations you have to apply in order to make them equal (or f(a, b) = 1337 if it is i...
#include <bits/stdc++.h> const int B=200; typedef long long ll; using namespace std; int T,n,m,l; map<string,vector<string> >V; map<string,bool>vis; string s,t; int main(){ ios_base::sync_with_stdio(0), cin.tie(0); cin>>n; for(int i=1;i<=n;i++){ cin>>s;t=s; sort(t.begin(),t.end()); V[t].push_back(s); } l=s.s...
2C++
{ "input": [ "4\nzzz\nbac\nabc\nacb\n", "2\na\nb\n", "1\na\n", "6\nacb\nabc\ncba\nbac\ncab\nbca\n", "24\nbcda\nacdb\nbcad\ncbad\nabcd\nbacd\nadcb\nbdac\ncbda\ndbca\ncdab\ncabd\ndabc\ncdba\nadbc\ndcba\ndcab\ndacb\nbdca\ndbac\ncadb\nbadc\nacbd\nabdc\n", "2\nba\nab\n", "2\ncbb\nbcb\n", "1...
2CODEFORCES
1535_F. String Distance_38231
Suppose you are given two strings a and b. You can apply the following operation any number of times: choose any contiguous substring of a or b, and sort the characters in it in non-descending order. Let f(a, b) the minimum number of operations you have to apply in order to make them equal (or f(a, b) = 1337 if it is i...
import java.io.BufferedInputStream; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; public class P1535F { private static class LetterHist { private ...
4JAVA
{ "input": [ "4\nzzz\nbac\nabc\nacb\n", "2\na\nb\n", "1\na\n", "6\nacb\nabc\ncba\nbac\ncab\nbca\n", "24\nbcda\nacdb\nbcad\ncbad\nabcd\nbacd\nadcb\nbdac\ncbda\ndbca\ncdab\ncabd\ndabc\ncdba\nadbc\ndcba\ndcab\ndacb\nbdca\ndbac\ncadb\nbadc\nacbd\nabdc\n", "2\nba\nab\n", "2\ncbb\nbcb\n", "1...
2CODEFORCES
182_E. Wooden Fence_38232
Vasya has recently bought some land and decided to surround it with a wooden fence. He went to a company called "Wooden board" that produces wooden boards for fences. Vasya read in the catalog of products that the company has at its disposal n different types of wood. The company uses the i-th type of wood to produce ...
from sys import stdin m = 1000000007 n, l = map(int, stdin.readline().split()) e = [] for i in xrange(n): a, b = map(int, stdin.readline().split()) e.append((a, b, i)) if a != b: e.append((b, a, i)) n = len(e) e.sort() u = [[] for i in xrange(101)] for i in xrange(n): u[e[i][1]].append((e[i][0], e[i][...
1Python2
{ "input": [ "1 2\n2 2\n", "2 3\n1 2\n2 3\n", "6 6\n2 1\n3 2\n2 5\n3 3\n5 1\n2 1\n", "100 1500\n3 3\n3 2\n1 3\n3 1\n2 3\n3 2\n3 2\n2 1\n3 1\n2 3\n3 3\n3 1\n1 1\n3 1\n3 3\n2 2\n2 2\n1 2\n1 1\n3 1\n2 2\n2 3\n2 3\n2 2\n3 3\n3 2\n1 1\n3 3\n2 2\n1 3\n3 3\n3 1\n1 2\n3 3\n3 3\n2 2\n1 1\n3 3\n1 3\n2 1\n1 2\n2...
2CODEFORCES
182_E. Wooden Fence_38233
Vasya has recently bought some land and decided to surround it with a wooden fence. He went to a company called "Wooden board" that produces wooden boards for fences. Vasya read in the catalog of products that the company has at its disposal n different types of wood. The company uses the i-th type of wood to produce ...
#include <bits/stdc++.h> using namespace std; long long d[3030][110][2]; int main() { int l, n, a[1000], b[1000], i, j, k, len, wid; long long ans; cin >> n >> l; for (i = 0; i < n; i++) cin >> a[i] >> b[i]; for (i = 0; i < n; i++) { d[a[i]][i][0]++; d[b[i]][i][1]++; } for (i = 0; i <= l; i++) { ...
2C++
{ "input": [ "1 2\n2 2\n", "2 3\n1 2\n2 3\n", "6 6\n2 1\n3 2\n2 5\n3 3\n5 1\n2 1\n", "100 1500\n3 3\n3 2\n1 3\n3 1\n2 3\n3 2\n3 2\n2 1\n3 1\n2 3\n3 3\n3 1\n1 1\n3 1\n3 3\n2 2\n2 2\n1 2\n1 1\n3 1\n2 2\n2 3\n2 3\n2 2\n3 3\n3 2\n1 1\n3 3\n2 2\n1 3\n3 3\n3 1\n1 2\n3 3\n3 3\n2 2\n1 1\n3 3\n1 3\n2 1\n1 2\n2...
2CODEFORCES
182_E. Wooden Fence_38234
Vasya has recently bought some land and decided to surround it with a wooden fence. He went to a company called "Wooden board" that produces wooden boards for fences. Vasya read in the catalog of products that the company has at its disposal n different types of wood. The company uses the i-th type of wood to produce ...
from sys import stdin, stdout MOD = 10 ** 9 + 7 sze = 101 n, l = map(int, stdin.readline().split()) dp = [[[0, 0] for j in range(l + sze + 1)] for i in range(n)] bars = [] challengers = [[] for i in range(sze)] for i in range(n): a, b = map(int, stdin.readline().split()) bars.append((a, b)) if a != ...
3Python3
{ "input": [ "1 2\n2 2\n", "2 3\n1 2\n2 3\n", "6 6\n2 1\n3 2\n2 5\n3 3\n5 1\n2 1\n", "100 1500\n3 3\n3 2\n1 3\n3 1\n2 3\n3 2\n3 2\n2 1\n3 1\n2 3\n3 3\n3 1\n1 1\n3 1\n3 3\n2 2\n2 2\n1 2\n1 1\n3 1\n2 2\n2 3\n2 3\n2 2\n3 3\n3 2\n1 1\n3 3\n2 2\n1 3\n3 3\n3 1\n1 2\n3 3\n3 3\n2 2\n1 1\n3 3\n1 3\n2 1\n1 2\n2...
2CODEFORCES
182_E. Wooden Fence_38235
Vasya has recently bought some land and decided to surround it with a wooden fence. He went to a company called "Wooden board" that produces wooden boards for fences. Vasya read in the catalog of products that the company has at its disposal n different types of wood. The company uses the i-th type of wood to produce ...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class E { public static void main(String[] args) throws IOException { BufferedReader buf = new BufferedReader( new InputStreamReader(System.in)); String[] i...
4JAVA
{ "input": [ "1 2\n2 2\n", "2 3\n1 2\n2 3\n", "6 6\n2 1\n3 2\n2 5\n3 3\n5 1\n2 1\n", "100 1500\n3 3\n3 2\n1 3\n3 1\n2 3\n3 2\n3 2\n2 1\n3 1\n2 3\n3 3\n3 1\n1 1\n3 1\n3 3\n2 2\n2 2\n1 2\n1 1\n3 1\n2 2\n2 3\n2 3\n2 2\n3 3\n3 2\n1 1\n3 3\n2 2\n1 3\n3 3\n3 1\n1 2\n3 3\n3 3\n2 2\n1 1\n3 3\n1 3\n2 1\n1 2\n2...
2CODEFORCES
207_A2. Beaver's Calculator 1.0_38236
The Smart Beaver from ABBYY has once again surprised us! He has developed a new calculating device, which he called the "Beaver's Calculator 1.0". It is very peculiar and it is planned to be used in a variety of scientific problems. To test it, the Smart Beaver invited n scientists, numbered from 1 to n. The i-th scie...
#include <bits/stdc++.h> using namespace std; int *pa = new int[200005]; int *na = new int[200005]; int *p1 = new int[200005]; int *p2 = new int[200005]; int main() { int m1 = 1, m2 = 1, c1, c2, fs[5005], ls[5005], n, k[5005], x[5005], y[5005], m[5005], i, j; long long all = 0, q, nn, xx, yy, ans = 0; cin >...
2C++
{ "input": [ "2\n2 1 1 1 10\n2 3 1 1 10\n", "2\n3 10 2 3 1000\n3 100 1 999 1000\n", "2\n199259 641597876 874636940 764816019 656105016\n51285 310517513 469223007 415463849 968409867\n", "2\n5 737247526 385663770 400009853 926128972\n5 134299091 206672784 206760990 541043536\n", "2\n76545 44608612 ...
2CODEFORCES
207_A2. Beaver's Calculator 1.0_38237
The Smart Beaver from ABBYY has once again surprised us! He has developed a new calculating device, which he called the "Beaver's Calculator 1.0". It is very peculiar and it is planned to be used in a variety of scientific problems. To test it, the Smart Beaver invited n scientists, numbered from 1 to n. The i-th scie...
import java.io.IOException; import java.io.InputStreamReader; import java.io.Closeable; import java.util.Iterator; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.NoSuchElementException; import java.io.Writer; import java.util.StringTokenizer; import java.io.Inpu...
4JAVA
{ "input": [ "2\n2 1 1 1 10\n2 3 1 1 10\n", "2\n3 10 2 3 1000\n3 100 1 999 1000\n", "2\n199259 641597876 874636940 764816019 656105016\n51285 310517513 469223007 415463849 968409867\n", "2\n5 737247526 385663770 400009853 926128972\n5 134299091 206672784 206760990 541043536\n", "2\n76545 44608612 ...
2CODEFORCES
230_A. Dragons_38238
Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all n dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito'...
s, n = map(int,raw_input().split()) x=[] win=True for i in range(n): x.append(map(int,raw_input().split())) x=sorted(x) for i in range(n): if(s>x[i][0]): s+=x[i][1] else: win=False print "YES" if win else "NO"
1Python2
{ "input": [ "2 2\n1 99\n100 0\n", "10 1\n100 100\n", "10 1\n10 10\n", "4 2\n2 1\n10 3\n", "2 5\n5 1\n2 1\n3 1\n1 1\n4 1\n", "1 2\n100 1\n100 1\n", "2 3\n1 1\n1 10\n17 2\n", "10 10\n2 10\n3 10\n4 10\n2 20\n3 20\n3 20\n100 50\n100 30\n150 30\n200 10\n", "6 2\n496 0\n28 8128\n", ...
2CODEFORCES
230_A. Dragons_38239
Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all n dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito'...
#include <bits/stdc++.h> using namespace std; int main() { int S, n; cin >> S >> n; pair<int, int> p[n]; bool f = 0; for (int i = 0; i < n; i++) { cin >> p[i].first >> p[i].second; } sort(p, p + n); for (int i = 0; i < n; i++) { if (S > p[i].first) S += p[i].second; else f = 1; ...
2C++
{ "input": [ "2 2\n1 99\n100 0\n", "10 1\n100 100\n", "10 1\n10 10\n", "4 2\n2 1\n10 3\n", "2 5\n5 1\n2 1\n3 1\n1 1\n4 1\n", "1 2\n100 1\n100 1\n", "2 3\n1 1\n1 10\n17 2\n", "10 10\n2 10\n3 10\n4 10\n2 20\n3 20\n3 20\n100 50\n100 30\n150 30\n200 10\n", "6 2\n496 0\n28 8128\n", ...
2CODEFORCES
230_A. Dragons_38240
Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all n dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito'...
n,m=map(int, input().split()) r=3 ar=[] for i in range (m): q=list(map(int, input().split())) ar.append (q) ar.sort() for i in range (m): if n>ar[i][0]: n+=ar[i][1] else: r=5 print ('NO') break if r!=5: print ('YES')
3Python3
{ "input": [ "2 2\n1 99\n100 0\n", "10 1\n100 100\n", "10 1\n10 10\n", "4 2\n2 1\n10 3\n", "2 5\n5 1\n2 1\n3 1\n1 1\n4 1\n", "1 2\n100 1\n100 1\n", "2 3\n1 1\n1 10\n17 2\n", "10 10\n2 10\n3 10\n4 10\n2 20\n3 20\n3 20\n100 50\n100 30\n150 30\n200 10\n", "6 2\n496 0\n28 8128\n", ...
2CODEFORCES
230_A. Dragons_38241
Kirito is stuck on a level of the MMORPG he is playing now. To move on in the game, he's got to defeat all n dragons that live on this level. Kirito and the dragons have strength, which is represented by an integer. In the duel between two opponents the duel's outcome is determined by their strength. Initially, Kirito'...
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int s = sc.nextInt(); int n = sc.nextInt(); int[] reqS = new int[n]; int[] gainS = new int[n]; int ctr = 1; for(int i = 0; i < n; i++) { reqS[i] = sc.nextInt(); gainS[i] =...
4JAVA
{ "input": [ "2 2\n1 99\n100 0\n", "10 1\n100 100\n", "10 1\n10 10\n", "4 2\n2 1\n10 3\n", "2 5\n5 1\n2 1\n3 1\n1 1\n4 1\n", "1 2\n100 1\n100 1\n", "2 3\n1 1\n1 10\n17 2\n", "10 10\n2 10\n3 10\n4 10\n2 20\n3 20\n3 20\n100 50\n100 30\n150 30\n200 10\n", "6 2\n496 0\n28 8128\n", ...
2CODEFORCES
255_E. Furlo and Rublo and Game_38242
Furlo and Rublo play a game. The table has n piles of coins lying on it, the i-th pile has ai coins. Furlo and Rublo move in turns, Furlo moves first. In one move you are allowed to: * choose some pile, let's denote the current number of coins in it as x; * choose some integer y (0 ≤ y < x; x1 / 4 ≤ y ≤ x1 / 2) a...
#!/usr/bin/python import bisect a = [0,4,16,82,6724,15**4+1,15**8+1] b = [0,1,2,0,3,1,2] def sg(x) : i = bisect.bisect_right(a,x) return b[i-1] n = input() num = map(int,raw_input().split()) ans = 0 for x in num: ans ^= sg(x) if ans : print "Furlo" else : print "Rublo"
1Python2
{ "input": [ "10\n1 2 3 4 5 6 7 8 9 10\n", "1\n1\n", "2\n1 2\n", "3\n2500000000 3000000000 1000\n", "40\n20390340 659951276 660648687 283496822 238806569 452159719 595601864 88859363 448128137 173415523 155896972 382680284 143902331 67085579 251233672 507418836 451689775 116050106 716427523 453853...
2CODEFORCES
255_E. Furlo and Rublo and Game_38243
Furlo and Rublo play a game. The table has n piles of coins lying on it, the i-th pile has ai coins. Furlo and Rublo move in turns, Furlo moves first. In one move you are allowed to: * choose some pile, let's denote the current number of coins in it as x; * choose some integer y (0 ≤ y < x; x1 / 4 ≤ y ≤ x1 / 2) a...
#include <bits/stdc++.h> using namespace std; int get_nim(long long x) { if (x < 4) return 0; if (x < 16) return 1; if (x < 82) return 2; if (x < 6724) return 0; if (x < 50626) return 3; if (x < 2562991876LL) return 1; return 2; } int main() { int n, ans = 0; long long a; cin >> n; for (int i = 0;...
2C++
{ "input": [ "10\n1 2 3 4 5 6 7 8 9 10\n", "1\n1\n", "2\n1 2\n", "3\n2500000000 3000000000 1000\n", "40\n20390340 659951276 660648687 283496822 238806569 452159719 595601864 88859363 448128137 173415523 155896972 382680284 143902331 67085579 251233672 507418836 451689775 116050106 716427523 453853...
2CODEFORCES
255_E. Furlo and Rublo and Game_38244
Furlo and Rublo play a game. The table has n piles of coins lying on it, the i-th pile has ai coins. Furlo and Rublo move in turns, Furlo moves first. In one move you are allowed to: * choose some pile, let's denote the current number of coins in it as x; * choose some integer y (0 ≤ y < x; x1 / 4 ≤ y ≤ x1 / 2) a...
import java.io.*; import java.util.*; public class E { public static void main(String[] args) { try { new E().solve(); } catch (Exception e) { e.printStackTrace(); } } int[] grundy = new int[1 << 20]; int[][] seg = new int[25][]; int find(int s, int ...
4JAVA
{ "input": [ "10\n1 2 3 4 5 6 7 8 9 10\n", "1\n1\n", "2\n1 2\n", "3\n2500000000 3000000000 1000\n", "40\n20390340 659951276 660648687 283496822 238806569 452159719 595601864 88859363 448128137 173415523 155896972 382680284 143902331 67085579 251233672 507418836 451689775 116050106 716427523 453853...
2CODEFORCES
279_E. Beautiful Decomposition_38245
Valera considers a number beautiful, if it equals 2k or -2k for some integer k (k ≥ 0). Recently, the math teacher asked Valera to represent number n as the sum of beautiful numbers. As Valera is really greedy, he wants to complete the task using as few beautiful numbers as possible. Help Valera and find, how many nu...
x = 0 y = 1 for c in raw_input(): if c == '0': x, y = min(x, y + 1), min(x, y) + 1 else: x, y = min(x, y) + 1, min(x + 1, y) print min(x, y + 1)
1Python2
{ "input": [ "1101101\n", "10\n", "111\n", "1001110101111000111010100110111000000110011011100111001111100001110011011001101110000000\n", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n", "110\n", "1101100110101101011010101110100100101...
2CODEFORCES
279_E. Beautiful Decomposition_38246
Valera considers a number beautiful, if it equals 2k or -2k for some integer k (k ≥ 0). Recently, the math teacher asked Valera to represent number n as the sum of beautiful numbers. As Valera is really greedy, he wants to complete the task using as few beautiful numbers as possible. Help Valera and find, how many nu...
#include <bits/stdc++.h> using namespace std; char s[1000005]; int n; int main() { scanf("%s", s + 2); n = strlen(s + 2); int now = n + 1, ans = 0; while (1) { while (s[now] == '0') now--; if (s[now] == 0) break; int m = now; while (s[m] == '1') m--; if (m + 1 == now) ans++, now = m; ...
2C++
{ "input": [ "1101101\n", "10\n", "111\n", "1001110101111000111010100110111000000110011011100111001111100001110011011001101110000000\n", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n", "110\n", "1101100110101101011010101110100100101...
2CODEFORCES
279_E. Beautiful Decomposition_38247
Valera considers a number beautiful, if it equals 2k or -2k for some integer k (k ≥ 0). Recently, the math teacher asked Valera to represent number n as the sum of beautiful numbers. As Valera is really greedy, he wants to complete the task using as few beautiful numbers as possible. Help Valera and find, how many nu...
t = input() j = t[0] d, s = 0, int(j) for i in t[1: ]: if j != i: if d == 1: d, s = 0, s + 1 else: d = 1 j = i else: d = 1 print(s + (d and j == '1'))
3Python3
{ "input": [ "1101101\n", "10\n", "111\n", "1001110101111000111010100110111000000110011011100111001111100001110011011001101110000000\n", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n", "110\n", "1101100110101101011010101110100100101...
2CODEFORCES
279_E. Beautiful Decomposition_38248
Valera considers a number beautiful, if it equals 2k or -2k for some integer k (k ≥ 0). Recently, the math teacher asked Valera to represent number n as the sum of beautiful numbers. As Valera is really greedy, he wants to complete the task using as few beautiful numbers as possible. Help Valera and find, how many nu...
import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.io.*; import java.math.*; import java.text.*; import java.util.*; /* br = new BufferedReader(new FileReader("input.txt")); pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); br = new BufferedReader(new InputStreamRead...
4JAVA
{ "input": [ "1101101\n", "10\n", "111\n", "1001110101111000111010100110111000000110011011100111001111100001110011011001101110000000\n", "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n", "110\n", "1101100110101101011010101110100100101...
2CODEFORCES
301_D. Yaroslav and Divisors_38249
Yaroslav has an array p = p1, p2, ..., pn (1 ≤ pi ≤ n), consisting of n distinct integers. Also, he has m queries: * Query number i is represented as a pair of integers li, ri (1 ≤ li ≤ ri ≤ n). * The answer to the query li, ri is the number of pairs of integers q, w (li ≤ q, w ≤ ri) such that pq is the divisor o...
#include <bits/stdc++.h> using namespace std; const int N = 201000; int n, a[N], pos[N], l[N], r[N], C[N], idx[N], ans[N]; vector<int> nu[N]; void bitModify(int p) { for (int i = p; i > 0; i -= i & -i) C[i]++; } int bitQuery(int p) { int ret = 0; for (int i = p; i <= n; i += i & -i) ret += C[i]; return ret; } b...
2C++
{ "input": [ "1 1\n1\n1 1\n", "10 9\n1 2 3 4 5 6 7 8 9 10\n1 10\n2 9\n3 8\n4 7\n5 6\n2 2\n9 10\n5 10\n4 10\n", "8 8\n1 2 3 4 5 6 7 8\n5 6\n4 8\n3 8\n2 4\n3 5\n5 7\n4 4\n4 8\n", "3 3\n1 2 3\n1 1\n2 3\n1 1\n", "3 3\n3 2 1\n1 3\n1 3\n1 3\n", "4 4\n4 2 3 1\n3 4\n1 4\n1 2\n4 4\n", "5 5\n1 2 3 4...
2CODEFORCES
301_D. Yaroslav and Divisors_38250
Yaroslav has an array p = p1, p2, ..., pn (1 ≤ pi ≤ n), consisting of n distinct integers. Also, he has m queries: * Query number i is represented as a pair of integers li, ri (1 ≤ li ≤ ri ≤ n). * The answer to the query li, ri is the number of pairs of integers q, w (li ≤ q, w ≤ ri) such that pq is the divisor o...
import static java.util.Arrays.*; import java.util.*; public class D { private final static boolean autoflush = false; public D () { int N = sc.nextInt(), M = sc.nextInt(); Integer [] P = invert(dec(sc.nextInts())); int [][] Q = new int [M][]; for (int i = 0; i < M; ++i) Q[i] = new int [] { sc.nextInt(...
4JAVA
{ "input": [ "1 1\n1\n1 1\n", "10 9\n1 2 3 4 5 6 7 8 9 10\n1 10\n2 9\n3 8\n4 7\n5 6\n2 2\n9 10\n5 10\n4 10\n", "8 8\n1 2 3 4 5 6 7 8\n5 6\n4 8\n3 8\n2 4\n3 5\n5 7\n4 4\n4 8\n", "3 3\n1 2 3\n1 1\n2 3\n1 1\n", "3 3\n3 2 1\n1 3\n1 3\n1 3\n", "4 4\n4 2 3 1\n3 4\n1 4\n1 2\n4 4\n", "5 5\n1 2 3 4...
2CODEFORCES
328_B. Sheldon and Ice Pieces_38251
Do you remember how Kai constructed the word "eternity" using pieces of ice as components? Little Sheldon plays with pieces of ice, each piece has exactly one digit between 0 and 9. He wants to construct his favourite number t. He realized that digits 6 and 9 are very similar, so he can rotate piece of ice with 6 to u...
t, s = [raw_input().replace('6', '9').replace('2', '5') for i in range(2)] print min([s.count(i)/t.count(i) for i in t])
1Python2
{ "input": [ "42\n23454\n", "169\n12118999\n", "5518\n9827108589585181118358352282425981568508825302611217254345831149357236227288533838583629451589201341265988858338548185158221291825821019993179835186961954871454\n", "533\n355233333332\n", "9\n666969\n", "2559\n5252555622565626\n", "2569...
2CODEFORCES
328_B. Sheldon and Ice Pieces_38252
Do you remember how Kai constructed the word "eternity" using pieces of ice as components? Little Sheldon plays with pieces of ice, each piece has exactly one digit between 0 and 9. He wants to construct his favourite number t. He realized that digits 6 and 9 are very similar, so he can rotate piece of ice with 6 to u...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n; k = n; int a[10] = {0}; int b[10] = {0}; while (k) { a[k % 10]++; k = k / 10; } string s; cin >> s; for (int i = 0; i < s.size(); ++i) { b[(s[i] - '0') % 10]++; } int count, ans = 99999999; for (int i = ...
2C++
{ "input": [ "42\n23454\n", "169\n12118999\n", "5518\n9827108589585181118358352282425981568508825302611217254345831149357236227288533838583629451589201341265988858338548185158221291825821019993179835186961954871454\n", "533\n355233333332\n", "9\n666969\n", "2559\n5252555622565626\n", "2569...
2CODEFORCES
328_B. Sheldon and Ice Pieces_38253
Do you remember how Kai constructed the word "eternity" using pieces of ice as components? Little Sheldon plays with pieces of ice, each piece has exactly one digit between 0 and 9. He wants to construct his favourite number t. He realized that digits 6 and 9 are very similar, so he can rotate piece of ice with 6 to u...
def c(a, b): a = a.replace('6', '9') a = a.replace('2', '5') b = b.replace('6', '9') b = b.replace('2', '5') n = 10000 for i in '01345789': t = a.count(i) if t != 0: n = min(n, b.count(i)//t) return n a = input() b = input() print(c(a, b))
3Python3
{ "input": [ "42\n23454\n", "169\n12118999\n", "5518\n9827108589585181118358352282425981568508825302611217254345831149357236227288533838583629451589201341265988858338548185158221291825821019993179835186961954871454\n", "533\n355233333332\n", "9\n666969\n", "2559\n5252555622565626\n", "2569...
2CODEFORCES
328_B. Sheldon and Ice Pieces_38254
Do you remember how Kai constructed the word "eternity" using pieces of ice as components? Little Sheldon plays with pieces of ice, each piece has exactly one digit between 0 and 9. He wants to construct his favourite number t. He realized that digits 6 and 9 are very similar, so he can rotate piece of ice with 6 to u...
import java.util.Scanner; public class IcePEace { public static int searchstring(String s,String S){ if (s.length()>S.length()) return -1; for(int i=0;i<=(S.length()-s.length());i++){ if (s.equals(S.substring(i,i+s.length()))) return i; } return -1; } public static String removestring(String s, in...
4JAVA
{ "input": [ "42\n23454\n", "169\n12118999\n", "5518\n9827108589585181118358352282425981568508825302611217254345831149357236227288533838583629451589201341265988858338548185158221291825821019993179835186961954871454\n", "533\n355233333332\n", "9\n666969\n", "2559\n5252555622565626\n", "2569...
2CODEFORCES
34_C. Page Numbers_38255
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces). Your task is to w...
a=sorted(set(map(int,raw_input().split(',')))) b=[[-2,-2]] for i in range(len(a)): if a[i]==b[-1][1]+1: b[-1][1]=a[i] else: b.append([a[i],a[i]]) print ','.join(map(lambda x:str(x[0]) if x[0]==x[1] else str(x[0])+'-'+str(x[1]),b[1:]))
1Python2
{ "input": [ "30,20,10\n", "3,2,1\n", "1,2,3,1,1,2,6,6,2\n", "511,32\n", "684,698,429,694,956,812,594,170,937,764\n", "744,359,230,586,944,442\n", "37\n", "996,999,998,984,989,1000,996,993,1000,983,992,999,999,1000,979,992,987,1000,996,1000,1000,989,981,996,995,999,999,989,999,1000\n",...
2CODEFORCES
34_C. Page Numbers_38256
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces). Your task is to w...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); set<int> s; string t, k; cin >> t; int jj; for (int i = 0; i < t.length(); i++) { if (t[i] != ',') { k += t[i]; } else { jj = ...
2C++
{ "input": [ "30,20,10\n", "3,2,1\n", "1,2,3,1,1,2,6,6,2\n", "511,32\n", "684,698,429,694,956,812,594,170,937,764\n", "744,359,230,586,944,442\n", "37\n", "996,999,998,984,989,1000,996,993,1000,983,992,999,999,1000,979,992,987,1000,996,1000,1000,989,981,996,995,999,999,989,999,1000\n",...
2CODEFORCES
34_C. Page Numbers_38257
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces). Your task is to w...
A=[int(num) for num in input().split(',')] s_a=sorted(set(A)) prev=None string="" count=0 for i in s_a: if prev is None: prev=i string+=str(prev) count+=1 else: if i-(prev+count)==0: count+=1 else: if count>1: string+='-'+str(prev+c...
3Python3
{ "input": [ "30,20,10\n", "3,2,1\n", "1,2,3,1,1,2,6,6,2\n", "511,32\n", "684,698,429,694,956,812,594,170,937,764\n", "744,359,230,586,944,442\n", "37\n", "996,999,998,984,989,1000,996,993,1000,983,992,999,999,1000,979,992,987,1000,996,1000,1000,989,981,996,995,999,999,989,999,1000\n",...
2CODEFORCES
34_C. Page Numbers_38258
«Bersoft» company is working on a new version of its most popular text editor — Bord 2010. Bord, like many other text editors, should be able to print out multipage documents. A user keys a sequence of the document page numbers that he wants to print out (separates them with a comma, without spaces). Your task is to w...
import java.io.BufferedInputStream; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.Scanner; public class PageNumbers { //Round #34 - Page Numbers public static void main(String[] args) { Scanner sc = new Scanner(new BufferedInputStream(System.in)); String in...
4JAVA
{ "input": [ "30,20,10\n", "3,2,1\n", "1,2,3,1,1,2,6,6,2\n", "511,32\n", "684,698,429,694,956,812,594,170,937,764\n", "744,359,230,586,944,442\n", "37\n", "996,999,998,984,989,1000,996,993,1000,983,992,999,999,1000,979,992,987,1000,996,1000,1000,989,981,996,995,999,999,989,999,1000\n",...
2CODEFORCES
373_D. Counting Rectangles is Fun_38259
There is an n × m rectangular grid, each cell of the grid contains a single integer: zero or one. Let's call the cell on the i-th row and the j-th column as (i, j). Let's define a "rectangle" as four integers a, b, c, d (1 ≤ a ≤ c ≤ n; 1 ≤ b ≤ d ≤ m). Rectangle denotes a set of cells of the grid {(x, y) : a ≤ x ≤ c, b...
#include <bits/stdc++.h> using namespace std; bool a[41][41]; long long d[41][41][41][41]; long long cld[41][41][41][41]; int cldh[41][41][41][41]; int lines_x[41][41]; int lines_y[41][41]; void print(int w, int e, int n, int m) { for (int i = 0; i < n; ++i) { for (int j = 0; j < m; ++j) { printf("%d ", d[w...
2C++
{ "input": [ "5 5 5\n00101\n00000\n00001\n01000\n00001\n1 2 2 4\n4 5 4 5\n1 2 5 2\n2 2 4 5\n4 2 5 3\n", "4 7 5\n0000100\n0000010\n0011000\n0000000\n1 7 2 7\n3 1 3 1\n2 3 4 5\n1 2 2 7\n2 2 4 7\n", "2 3 8\n000\n001\n1 1 2 2\n1 3 2 3\n2 2 2 3\n1 1 2 2\n2 3 2 3\n2 1 2 2\n1 2 1 3\n1 2 2 2\n", "10 10 10\n00...
2CODEFORCES
373_D. Counting Rectangles is Fun_38260
There is an n × m rectangular grid, each cell of the grid contains a single integer: zero or one. Let's call the cell on the i-th row and the j-th column as (i, j). Let's define a "rectangle" as four integers a, b, c, d (1 ≤ a ≤ c ≤ n; 1 ≤ b ≤ d ≤ m). Rectangle denotes a set of cells of the grid {(x, y) : a ≤ x ≤ c, b...
import java.io.*; import java.util.*; import java.math.*; import static java.lang.Math.*; import static java.lang.Integer.*; import static java.lang.Long.*; public class D219new { int INF = Integer.MAX_VALUE / 100; static Scanner sc = null; static BufferedReader br = null; static PrintStream out = null; st...
4JAVA
{ "input": [ "5 5 5\n00101\n00000\n00001\n01000\n00001\n1 2 2 4\n4 5 4 5\n1 2 5 2\n2 2 4 5\n4 2 5 3\n", "4 7 5\n0000100\n0000010\n0011000\n0000000\n1 7 2 7\n3 1 3 1\n2 3 4 5\n1 2 2 7\n2 2 4 7\n", "2 3 8\n000\n001\n1 1 2 2\n1 3 2 3\n2 2 2 3\n1 1 2 2\n2 3 2 3\n2 1 2 2\n1 2 1 3\n1 2 2 2\n", "10 10 10\n00...
2CODEFORCES
396_A. On Number of Decompositions into Multipliers_38261
You are given an integer m as a product of integers a1, a2, ... an <image>. Your task is to find the number of distinct decompositions of number m into the product of n ordered positive integers. Decomposition into n products, given in the input, must also be considered in the answer. As the answer can be very large, ...
from collections import defaultdict def main(): n = int(raw_input()) a = map(int, raw_input().split()) primes = [] b = [0] * 34002 for x in xrange(2, 34000): if b[x]: continue primes.append(x) y = x + x while y < 34000: b[y] = 1 y = y + x c...
1Python2
{ "input": [ "1\n15\n", "3\n1 1 2\n", "2\n5 7\n", "3\n8 10 8\n", "1\n536870912\n", "1\n111546435\n", "10\n2097152 67108864 65536 262144 262144 131072 8388608 536870912 65536 2097152\n", "23\n77 12 25 7 44 75 80 92 49 77 56 93 59 45 45 39 86 83 99 91 4 70 83\n", "50\n675 25000 2025 ...
2CODEFORCES
396_A. On Number of Decompositions into Multipliers_38262
You are given an integer m as a product of integers a1, a2, ... an <image>. Your task is to find the number of distinct decompositions of number m into the product of n ordered positive integers. Decomposition into n products, given in the input, must also be considered in the answer. As the answer can be very large, ...
#include <bits/stdc++.h> using namespace std; long long int dp[502][22 * 502]; int n; vector<int> v; bool use[100000]; vector<long long int> prime; long long int ans = 1; long long int ff[30000]; long long int ppow(long long int i, long long int j) { long long int r = 1; while (j > 0) { if (j & 1) { r *= ...
2C++
{ "input": [ "1\n15\n", "3\n1 1 2\n", "2\n5 7\n", "3\n8 10 8\n", "1\n536870912\n", "1\n111546435\n", "10\n2097152 67108864 65536 262144 262144 131072 8388608 536870912 65536 2097152\n", "23\n77 12 25 7 44 75 80 92 49 77 56 93 59 45 45 39 86 83 99 91 4 70 83\n", "50\n675 25000 2025 ...
2CODEFORCES
396_A. On Number of Decompositions into Multipliers_38263
You are given an integer m as a product of integers a1, a2, ... an <image>. Your task is to find the number of distinct decompositions of number m into the product of n ordered positive integers. Decomposition into n products, given in the input, must also be considered in the answer. As the answer can be very large, ...
# Made By Mostafa_Khaled bot = True Mod = 1000000007 MAX = 33000 n = int( input() ) A = list( map( int, input().split() ) ) B = [0] * MAX bePrime = [0] * MAX; primNum = [] C = [] fac=[1] for j in range(1, MAX): fac.append( fac[-1] * j % Mod ) def calc( M, N ): return fac[M] * pow( fac[N] * f...
3Python3
{ "input": [ "1\n15\n", "3\n1 1 2\n", "2\n5 7\n", "3\n8 10 8\n", "1\n536870912\n", "1\n111546435\n", "10\n2097152 67108864 65536 262144 262144 131072 8388608 536870912 65536 2097152\n", "23\n77 12 25 7 44 75 80 92 49 77 56 93 59 45 45 39 86 83 99 91 4 70 83\n", "50\n675 25000 2025 ...
2CODEFORCES
396_A. On Number of Decompositions into Multipliers_38264
You are given an integer m as a product of integers a1, a2, ... an <image>. Your task is to find the number of distinct decompositions of number m into the product of n ordered positive integers. Decomposition into n products, given in the input, must also be considered in the answer. As the answer can be very large, ...
import java.io.*; import java.math.BigInteger; import java.util.*; public class cf397c { static FastIO in = new FastIO(), out = in; static ArrayList<Integer> primes; static long MOD = (long)1e9 + 7; static int MAX = (int)Math.sqrt(1e9) + 10; static long[] facts = new long[50000]; static long[] invFacts =...
4JAVA
{ "input": [ "1\n15\n", "3\n1 1 2\n", "2\n5 7\n", "3\n8 10 8\n", "1\n536870912\n", "1\n111546435\n", "10\n2097152 67108864 65536 262144 262144 131072 8388608 536870912 65536 2097152\n", "23\n77 12 25 7 44 75 80 92 49 77 56 93 59 45 45 39 86 83 99 91 4 70 83\n", "50\n675 25000 2025 ...
2CODEFORCES
418_B. Cunning Gena_38265
A boy named Gena really wants to get to the "Russian Code Cup" finals, or at least get a t-shirt. But the offered problems are too complex, so he made an arrangement with his n friends that they will solve the problems for him. The participants are offered m problems on the contest. For each friend, Gena knows what pr...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000 * 1000 * 1000 + 7; const long long INF = 2000 * 1000 * 1000 * 1ll * 2000 * 1000 * 1000; const double EPS = 1e-9; const double pi = acos(-1.0); const int maxn = 110; template <typename T> inline T sqr(T n) { return (n * n); } struct item { int x, k, ...
2C++
{ "input": [ "2 2 1\n100 1 1\n2\n100 2 1\n1\n", "1 2 1\n1 1 1\n1\n", "3 2 5\n100 1 1\n1\n100 1 1\n2\n200 1 2\n1 2\n", "1 1 100000000\n1 100000000 1\n1\n", "4 4 1000000000\n1000000000 1000000000 1\n1\n1000000000 1000000000 1\n2\n1000000000 1000000000 1\n3\n1000000000 1000000000 1\n4\n", "1 20 1...
2CODEFORCES
418_B. Cunning Gena_38266
A boy named Gena really wants to get to the "Russian Code Cup" finals, or at least get a t-shirt. But the offered problems are too complex, so he made an arrangement with his n friends that they will solve the problems for him. The participants are offered m problems on the contest. For each friend, Gena knows what pr...
import java.io.*; import java.util.Arrays; import java.util.Comparator; import java.util.StringTokenizer; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = Syste...
4JAVA
{ "input": [ "2 2 1\n100 1 1\n2\n100 2 1\n1\n", "1 2 1\n1 1 1\n1\n", "3 2 5\n100 1 1\n1\n100 1 1\n2\n200 1 2\n1 2\n", "1 1 100000000\n1 100000000 1\n1\n", "4 4 1000000000\n1000000000 1000000000 1\n1\n1000000000 1000000000 1\n2\n1000000000 1000000000 1\n3\n1000000000 1000000000 1\n4\n", "1 20 1...
2CODEFORCES
444_E. DZY Loves Planting_38267
DZY loves planting, and he enjoys solving tree problems. DZY has a weighted tree (connected undirected graph without cycles) containing n nodes (they are numbered from 1 to n). He defines the function g(x, y) (1 ≤ x, y ≤ n) as the longest edge in the shortest path between nodes x and y. Specially g(z, z) = 0 for every...
#include <bits/stdc++.h> using namespace std; struct Edge { int a, b, c; bool operator<(const Edge &r) const { return c < r.c; } }; int N, x[3000], bl[3000]; vector<pair<int, int> > edges[3000]; Edge e[3000]; pair<int, int> dfs(int n, int p) { if (bl[n]) return pair<int, int>(0, 0); pair<int, int> ret = pair<in...
2C++
{ "input": [ "4\n1 2 1\n2 3 2\n3 4 3\n1\n1\n1\n1\n", "4\n1 2 1\n2 3 2\n3 4 3\n4\n4\n4\n4\n", "1\n1\n", "10\n2 1 559\n3 1 5707\n4 2 9790\n5 3 1591\n6 1 7113\n7 6 2413\n8 6 3006\n9 4 1935\n10 6 5954\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n", "10\n2 1 8760\n3 1 3705\n4 1 1862\n5 2 7332\n6 3 7015\n7 5 4866\n8 ...
2CODEFORCES
444_E. DZY Loves Planting_38268
DZY loves planting, and he enjoys solving tree problems. DZY has a weighted tree (connected undirected graph without cycles) containing n nodes (they are numbered from 1 to n). He defines the function g(x, y) (1 ≤ x, y ≤ n) as the longest edge in the shortest path between nodes x and y. Specially g(z, z) = 0 for every...
n = int(input()) edges = [[int(x) for x in input().split()] for i in range(n-1)] edges = sorted(edges) use_count = [0]+[int(input()) for i in range(n)] lo,hi = 0,10000 def getpar(par,u): if par[par[u]] == par[u]: return par[u] par[u] = getpar(par,par[u]) return par[u] def unite(par,sz,use,u,v): ...
3Python3
{ "input": [ "4\n1 2 1\n2 3 2\n3 4 3\n1\n1\n1\n1\n", "4\n1 2 1\n2 3 2\n3 4 3\n4\n4\n4\n4\n", "1\n1\n", "10\n2 1 559\n3 1 5707\n4 2 9790\n5 3 1591\n6 1 7113\n7 6 2413\n8 6 3006\n9 4 1935\n10 6 5954\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n", "10\n2 1 8760\n3 1 3705\n4 1 1862\n5 2 7332\n6 3 7015\n7 5 4866\n8 ...
2CODEFORCES
444_E. DZY Loves Planting_38269
DZY loves planting, and he enjoys solving tree problems. DZY has a weighted tree (connected undirected graph without cycles) containing n nodes (they are numbered from 1 to n). He defines the function g(x, y) (1 ≤ x, y ≤ n) as the longest edge in the shortest path between nodes x and y. Specially g(z, z) = 0 for every...
//package round254; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.InputMismatchException; import java.util.List; public class E { InputStream is; PrintWriter out; String I...
4JAVA
{ "input": [ "4\n1 2 1\n2 3 2\n3 4 3\n1\n1\n1\n1\n", "4\n1 2 1\n2 3 2\n3 4 3\n4\n4\n4\n4\n", "1\n1\n", "10\n2 1 559\n3 1 5707\n4 2 9790\n5 3 1591\n6 1 7113\n7 6 2413\n8 6 3006\n9 4 1935\n10 6 5954\n1\n1\n1\n1\n1\n1\n1\n1\n1\n1\n", "10\n2 1 8760\n3 1 3705\n4 1 1862\n5 2 7332\n6 3 7015\n7 5 4866\n8 ...
2CODEFORCES
467_A. George and Accommodation_38270
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living...
n=input() c=0 for i in xrange(0, n): p,q = raw_input().split(" ") if int(q)-int(p)>=2: c+=1 print c
1Python2
{ "input": [ "3\n1 1\n2 2\n3 3\n", "3\n1 10\n0 10\n10 10\n", "17\n68 69\n47 48\n30 31\n52 54\n41 43\n33 35\n38 40\n56 58\n45 46\n92 93\n73 74\n61 63\n65 66\n37 39\n67 68\n77 78\n28 30\n", "26\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\...
2CODEFORCES
467_A. George and Accommodation_38271
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; long long counter = 0; for (int i = 0; i < n; i++) { int x, y; cin >> x >> y; if (y - x >= 2) counter++; } cout << counter; return 0; }
2C++
{ "input": [ "3\n1 1\n2 2\n3 3\n", "3\n1 10\n0 10\n10 10\n", "17\n68 69\n47 48\n30 31\n52 54\n41 43\n33 35\n38 40\n56 58\n45 46\n92 93\n73 74\n61 63\n65 66\n37 39\n67 68\n77 78\n28 30\n", "26\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\...
2CODEFORCES
467_A. George and Accommodation_38272
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living...
c = 0 for _ in range(int(input())): n = [int(x) for x in input().split()] n,m = n[0],n[1] if m - n >= 2: c += 1 print(c)
3Python3
{ "input": [ "3\n1 1\n2 2\n3 3\n", "3\n1 10\n0 10\n10 10\n", "17\n68 69\n47 48\n30 31\n52 54\n41 43\n33 35\n38 40\n56 58\n45 46\n92 93\n73 74\n61 63\n65 66\n37 39\n67 68\n77 78\n28 30\n", "26\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\...
2CODEFORCES
467_A. George and Accommodation_38273
George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living...
import java.util.*; public class Solution { public static void main (String[] args) throws java.lang.Exception { int solution=0; Scanner scanner = new Scanner(System.in); int num_rooms = scanner.nextInt(); for(int i=0; i<num_rooms; i++){ int living = scanner.nextInt(); int max_c...
4JAVA
{ "input": [ "3\n1 1\n2 2\n3 3\n", "3\n1 10\n0 10\n10 10\n", "17\n68 69\n47 48\n30 31\n52 54\n41 43\n33 35\n38 40\n56 58\n45 46\n92 93\n73 74\n61 63\n65 66\n37 39\n67 68\n77 78\n28 30\n", "26\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\...
2CODEFORCES
48_D. Permutations_38274
A permutation is a sequence of integers from 1 to n of length n containing each number exactly once. For example, (1), (4, 3, 5, 1, 2), (3, 2, 1) are permutations, and (1, 1), (4, 3, 1), (2, 3, 4) are not. There are many tasks on permutations. Today you are going to solve one of them. Let’s imagine that somebody took...
def solve(): max_n = 100000 n = int(raw_input()) a = [0] * max_n b = [] for s in raw_input().split(): b.append(int(s)) for x in b: a[x - 1] += 1 for i in range(1, len(a)): if a[i] > a[i - 1]: print -1 return occurences ...
1Python2
{ "input": [ "9\n1 2 3 1 2 1 4 2 5\n", "4\n4 3 2 1\n", "4\n1 2 2 3\n", "2\n1000 1\n", "5\n2 2 1 1 3\n", "100\n12 18 1 1 14 23 1 1 22 5 7 9 7 1 1 1 3 8 4 2 1 6 9 1 3 2 11 1 11 2 3 2 1 4 2 7 1 16 3 4 2 13 3 1 5 11 2 10 20 24 3 21 5 2 6 2 1 10 10 5 17 1 1 4 19 8 5 5 3 9 4 2 7 8 10 4 9 1 3 3 9 7 6...
2CODEFORCES
48_D. Permutations_38275
A permutation is a sequence of integers from 1 to n of length n containing each number exactly once. For example, (1), (4, 3, 5, 1, 2), (3, 2, 1) are permutations, and (1, 1), (4, 3, 1), (2, 3, 4) are not. There are many tasks on permutations. Today you are going to solve one of them. Let’s imagine that somebody took...
#include <bits/stdc++.h> using namespace std; int a[100001], p[100001]; int main() { int n, i, Max = 0; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", a + i); p[a[i]]++; Max = max(Max, a[i]); } for (i = 1; i < Max; i++) if (p[i] < p[i + 1]) { printf("-1"); return 0; } ...
2C++
{ "input": [ "9\n1 2 3 1 2 1 4 2 5\n", "4\n4 3 2 1\n", "4\n1 2 2 3\n", "2\n1000 1\n", "5\n2 2 1 1 3\n", "100\n12 18 1 1 14 23 1 1 22 5 7 9 7 1 1 1 3 8 4 2 1 6 9 1 3 2 11 1 11 2 3 2 1 4 2 7 1 16 3 4 2 13 3 1 5 11 2 10 20 24 3 21 5 2 6 2 1 10 10 5 17 1 1 4 19 8 5 5 3 9 4 2 7 8 10 4 9 1 3 3 9 7 6...
2CODEFORCES
48_D. Permutations_38276
A permutation is a sequence of integers from 1 to n of length n containing each number exactly once. For example, (1), (4, 3, 5, 1, 2), (3, 2, 1) are permutations, and (1, 1), (4, 3, 1), (2, 3, 4) are not. There are many tasks on permutations. Today you are going to solve one of them. Let’s imagine that somebody took...
def fail(): print(-1) import sys sys.exit() n = int(input()) count = (n + 1) * [ 0 ] assign = n * [ None ] for i, x in enumerate(map(int, input().split())): if x > n: fail() count[x] += 1 assign[i] = count[x] for i in range(2, n): if count[i - 1] < count[i]: fail() print(count[1]) print(' '.joi...
3Python3
{ "input": [ "9\n1 2 3 1 2 1 4 2 5\n", "4\n4 3 2 1\n", "4\n1 2 2 3\n", "2\n1000 1\n", "5\n2 2 1 1 3\n", "100\n12 18 1 1 14 23 1 1 22 5 7 9 7 1 1 1 3 8 4 2 1 6 9 1 3 2 11 1 11 2 3 2 1 4 2 7 1 16 3 4 2 13 3 1 5 11 2 10 20 24 3 21 5 2 6 2 1 10 10 5 17 1 1 4 19 8 5 5 3 9 4 2 7 8 10 4 9 1 3 3 9 7 6...
2CODEFORCES
48_D. Permutations_38277
A permutation is a sequence of integers from 1 to n of length n containing each number exactly once. For example, (1), (4, 3, 5, 1, 2), (3, 2, 1) are permutations, and (1, 1), (4, 3, 1), (2, 3, 4) are not. There are many tasks on permutations. Today you are going to solve one of them. Let’s imagine that somebody took...
import java.util.*; public class D { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] ns = new int[n]; for (int i=0; i<n; i++) ns[i] = sc.nextInt()-1; for (int x : ns) if (x>=n) {System.out.println("-1"); return;} int[] count = new int[n]; for (in...
4JAVA
{ "input": [ "9\n1 2 3 1 2 1 4 2 5\n", "4\n4 3 2 1\n", "4\n1 2 2 3\n", "2\n1000 1\n", "5\n2 2 1 1 3\n", "100\n12 18 1 1 14 23 1 1 22 5 7 9 7 1 1 1 3 8 4 2 1 6 9 1 3 2 11 1 11 2 3 2 1 4 2 7 1 16 3 4 2 13 3 1 5 11 2 10 20 24 3 21 5 2 6 2 1 10 10 5 17 1 1 4 19 8 5 5 3 9 4 2 7 8 10 4 9 1 3 3 9 7 6...
2CODEFORCES
513_F1. Scaygerboss_38278
Cthulhu decided to catch Scaygerboss. Scaygerboss found it out and is trying to hide in a pack of his scaygers. Each scayger except Scaygerboss is either a male or a female. Scaygerboss's gender is "other". Scaygers are scattered on a two-dimensional map divided into cells. A scayger looks nerdy and loveable if it is ...
#include <bits/stdc++.h> using namespace std; template <class P, class Q> inline void smin(P &a, Q b) { if (b < a) a = b; } template <class P, class Q> inline void smax(P &a, Q b) { if (a < b) a = b; } const long long inf = 1LL << 20; const int maxn = 22 + 2; int n, m, males, females; int N; char s[maxn][maxn]; lon...
2C++
{ "input": [ "4 4 2 3\n....\n.###\n####\n####\n2 1 1\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n1 1 2\n", "2 4 2 2\n....\n.###\n2 1 1\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n", "3 8 11 12\n.......#\n.#......\n....#...\n1 2 10\n2 3 6\n2 4 2\n1 6 1\n1 5 6\n1 1 5\n3 3 1\n2 4 4\n1 6 5\n2 3 6\n3 4 5\n3 1 4\n1 3 5\n1 3 2\n1 2 3\n3 2 9\...
2CODEFORCES
513_F1. Scaygerboss_38279
Cthulhu decided to catch Scaygerboss. Scaygerboss found it out and is trying to hide in a pack of his scaygers. Each scayger except Scaygerboss is either a male or a female. Scaygerboss's gender is "other". Scaygers are scattered on a two-dimensional map divided into cells. A scayger looks nerdy and loveable if it is ...
import java.io.*; import java.util.*; public class CFF { FastScanner in; PrintWriter out; class Edge { int fr, to; long flow, cap; Edge rev; Edge(int fr, int to, long cap) { this.fr = fr; this.to = to; this.cap = cap; } } class Flow { int n; int[] q; boolean[] was; int[] dist; int[...
4JAVA
{ "input": [ "4 4 2 3\n....\n.###\n####\n####\n2 1 1\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n1 1 2\n", "2 4 2 2\n....\n.###\n2 1 1\n2 1 2\n2 1 2\n2 1 2\n2 1 2\n", "3 8 11 12\n.......#\n.#......\n....#...\n1 2 10\n2 3 6\n2 4 2\n1 6 1\n1 5 6\n1 1 5\n3 3 1\n2 4 4\n1 6 5\n2 3 6\n3 4 5\n3 1 4\n1 3 5\n1 3 2\n1 2 3\n3 2 9\...
2CODEFORCES
53_B. Blog Photo_38280
One popular blog site edits the uploaded photos like this. It cuts a rectangular area out of them so that the ratio of height to width (i.e. the height / width quotient) can vary from 0.8 to 1.25 inclusively. Besides, at least one side of the cut area should have a size, equal to some power of number 2 (2x for some int...
from math import ceil, floor, log def solve(h, w): s1 = _solve(h, w) s2 = _solve(w, h) s2 = s2[1], s2[0] area = lambda s: s[0] * s[1] if area(s1) == area(s2): best = sorted([s1,s2], key=lambda x: x[0])[-1] else: best = sorted([s1,s2], key=area)[-1] return best def _sol...
1Python2
{ "input": [ "2 1\n", "2 2\n", "5 5\n", "15 13\n", "9 10\n", "47 46\n", "49829224 49889315\n", "483242 484564\n", "644590722 593296648\n", "971840165 826141527\n", "49728622 49605627\n", "99692141 99232337\n", "48298903 49928606\n", "792322809 775058858\n", ...
2CODEFORCES
53_B. Blog Photo_38281
One popular blog site edits the uploaded photos like this. It cuts a rectangular area out of them so that the ratio of height to width (i.e. the height / width quotient) can vary from 0.8 to 1.25 inclusively. Besides, at least one side of the cut area should have a size, equal to some power of number 2 (2x for some int...
#include <bits/stdc++.h> using namespace std; int main() { long long i, j, h, w, tmp_h, tmp_w; cin >> h >> w; for (i = 0;; i++) { if ((long long)(1 << i) > h || (long long)(1 << i) > (5 * w) / 4) { i--; break; } } for (j = 0;; j++) { if ((long long)(1 << j) > w || (long long)(1 << j) >...
2C++
{ "input": [ "2 1\n", "2 2\n", "5 5\n", "15 13\n", "9 10\n", "47 46\n", "49829224 49889315\n", "483242 484564\n", "644590722 593296648\n", "971840165 826141527\n", "49728622 49605627\n", "99692141 99232337\n", "48298903 49928606\n", "792322809 775058858\n", ...
2CODEFORCES
53_B. Blog Photo_38282
One popular blog site edits the uploaded photos like this. It cuts a rectangular area out of them so that the ratio of height to width (i.e. the height / width quotient) can vary from 0.8 to 1.25 inclusively. Besides, at least one side of the cut area should have a size, equal to some power of number 2 (2x for some int...
from math import ceil,floor l = [] for i in range(39): l.append(2**i) h,w = map(int,input().split()) h1 = 0 w1 = 0 maxi = 0 for i in l: if i<=w: a = ceil(i*0.8) b = floor(i*1.25) if a<=h<=b: if i*h>=maxi: maxi = i * h h1 = h ...
3Python3
{ "input": [ "2 1\n", "2 2\n", "5 5\n", "15 13\n", "9 10\n", "47 46\n", "49829224 49889315\n", "483242 484564\n", "644590722 593296648\n", "971840165 826141527\n", "49728622 49605627\n", "99692141 99232337\n", "48298903 49928606\n", "792322809 775058858\n", ...
2CODEFORCES
53_B. Blog Photo_38283
One popular blog site edits the uploaded photos like this. It cuts a rectangular area out of them so that the ratio of height to width (i.e. the height / width quotient) can vary from 0.8 to 1.25 inclusively. Besides, at least one side of the cut area should have a size, equal to some power of number 2 (2x for some int...
// practice with kaiboy import java.io.*; import java.util.*; public class CF53B extends PrintWriter { CF53B() { super(System.out, true); } Scanner sc = new Scanner(System.in); public static void main(String[] $) { CF53B o = new CF53B(); o.main(); o.flush(); } int upper(int n) { return (int) (n * 5L / 4); }...
4JAVA
{ "input": [ "2 1\n", "2 2\n", "5 5\n", "15 13\n", "9 10\n", "47 46\n", "49829224 49889315\n", "483242 484564\n", "644590722 593296648\n", "971840165 826141527\n", "49728622 49605627\n", "99692141 99232337\n", "48298903 49928606\n", "792322809 775058858\n", ...
2CODEFORCES
567_D. One-Dimensional Battle Ships_38284
Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n square cells (that is, on a 1 × n table). At the beginning of the game Alice puts k ships on the field without telling their positions to Bob. Each ship looks as a 1 × a rectangle (that is, it occupies...
import copy n,k,a=map(int,raw_input().split()) m=int(raw_input()) l=map(int,raw_input().split()) def maxunit_vs_k(i,k):#i means nanbanme in l ll=l[:i] ll.sort() haba=[] for j in xrange(len(ll)-1): haba.append(abs(ll[j+1]-ll[j])-1) haba.append(abs(ll[0]-1)) haba.append(abs(n-ll[-1])) ...
1Python2
{ "input": [ "11 3 3\n5\n4 8 6 1 11\n", "5 1 3\n1\n3\n", "5 1 3\n2\n1 5\n", "200000 1 199999\n2\n2 200000\n", "5000 1660 2\n20\n1 100 18 102 300 81 19 25 44 88 1337 4999 1054 1203 91 16 164 914 1419 1487\n", "50 1 1\n50\n1 13 21 37 30 48 23 19 6 49 36 14 9 24 44 10 41 28 20 2 15 11 45 3 25 33 ...
2CODEFORCES
567_D. One-Dimensional Battle Ships_38285
Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n square cells (that is, on a 1 × n table). At the beginning of the game Alice puts k ships on the field without telling their positions to Bob. Each ship looks as a 1 × a rectangle (that is, it occupies...
#include <bits/stdc++.h> using namespace std; int T, t, n, k, a, m, maxn; int tree[200010], x[200010]; bool vis[200010]; int lowbit(int x) { return x & (-x); } void update(int x, int num) { for (; x <= n; x += lowbit(x)) tree[x] += num; } int query(int x) { int ret = 0; for (; x > 0; x -= lowbit(x)) ret += tree[x...
2C++
{ "input": [ "11 3 3\n5\n4 8 6 1 11\n", "5 1 3\n1\n3\n", "5 1 3\n2\n1 5\n", "200000 1 199999\n2\n2 200000\n", "5000 1660 2\n20\n1 100 18 102 300 81 19 25 44 88 1337 4999 1054 1203 91 16 164 914 1419 1487\n", "50 1 1\n50\n1 13 21 37 30 48 23 19 6 49 36 14 9 24 44 10 41 28 20 2 15 11 45 3 25 33 ...
2CODEFORCES
567_D. One-Dimensional Battle Ships_38286
Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n square cells (that is, on a 1 × n table). At the beginning of the game Alice puts k ships on the field without telling their positions to Bob. Each ship looks as a 1 × a rectangle (that is, it occupies...
import sys def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) def solve(): n, k, a = mints() a += 1 m = mint() x = list(mints()) l = 0 r = m + 1 while r - l > 1: c = (l + r) // 2 b = x[:c] b.sort() last = 0 cnt = 0 for i ...
3Python3
{ "input": [ "11 3 3\n5\n4 8 6 1 11\n", "5 1 3\n1\n3\n", "5 1 3\n2\n1 5\n", "200000 1 199999\n2\n2 200000\n", "5000 1660 2\n20\n1 100 18 102 300 81 19 25 44 88 1337 4999 1054 1203 91 16 164 914 1419 1487\n", "50 1 1\n50\n1 13 21 37 30 48 23 19 6 49 36 14 9 24 44 10 41 28 20 2 15 11 45 3 25 33 ...
2CODEFORCES
567_D. One-Dimensional Battle Ships_38287
Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n square cells (that is, on a 1 × n table). At the beginning of the game Alice puts k ships on the field without telling their positions to Bob. Each ship looks as a 1 × a rectangle (that is, it occupies...
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; import java.util.TreeMap; import java.util...
4JAVA
{ "input": [ "11 3 3\n5\n4 8 6 1 11\n", "5 1 3\n1\n3\n", "5 1 3\n2\n1 5\n", "200000 1 199999\n2\n2 200000\n", "5000 1660 2\n20\n1 100 18 102 300 81 19 25 44 88 1337 4999 1054 1203 91 16 164 914 1419 1487\n", "50 1 1\n50\n1 13 21 37 30 48 23 19 6 49 36 14 9 24 44 10 41 28 20 2 15 11 45 3 25 33 ...
2CODEFORCES
588_F. Duff in Mafia_38288
Duff is one if the heads of Mafia in her country, Andarz Gu. Andarz Gu has n cities (numbered from 1 to n) connected by m bidirectional roads (numbered by 1 to m). Each road has a destructing time, and a color. i-th road connects cities vi and ui and its color is ci and its destructing time is ti. Mafia wants to dest...
#include <bits/stdc++.h> using namespace std; const int MAX_BUF_SIZE = 16384; char BUFOR[MAX_BUF_SIZE]; int BUF_SIZE, BUF_POS; char ZZZ; const int MXN = 6 * 50010; const int C = 262144; const int INF = 1000000001; namespace SAT2 { vector<int> G[MXN], GT[MXN], H[MXN], vert[MXN]; int pre[MXN], skl[MXN]; vector<int> fu; c...
2C++
{ "input": [ "5 7\n2 1 3 7\n3 1 1 6\n5 4 1 8\n4 5 1 1\n3 2 2 3\n4 5 2 5\n2 3 2 4\n", "3 5\n3 2 1 3\n1 3 1 1\n3 2 1 4\n1 3 2 2\n1 3 2 10\n", "3 5\n2 1 608591421 720962564\n3 2 608591421 641991574\n3 2 718110706 353409763\n2 3 482786015 858341723\n3 2 825397574 357507279\n", "2 1\n2 1 317425595 63615632...
2CODEFORCES
610_C. Harmony Analysis_38289
The semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil was very bored on this lesson until the teacher gave the group a simple task: find 4 vectors in 4-dimensional space, such that every coordinate of every vec...
import string def trans(s): return s.translate(string.maketrans("+*", "*+")) def orthogonal(s, n): if n == 0: print s else: orthogonal(s+s, n-1) orthogonal(s+trans(s), n-1) k = input() if k == 0: print "+" else: orthogonal("+", k)
1Python2
{ "input": [ "2\n", "2\n", "4\n", "1\n", "5\n", "7\n", "8\n", "6\n", "0\n", "3\n" ], "output": [ "++++\n+*+*\n++**\n+**+\n", "++++\n+*+*\n++**\n+**+\n", "++++++++++++++++\n+*+*+*+*+*+*+*+*\n++**++**++**++**\n+**++**++**++**+\n++++****++++****\n+*+**+*++*+**+*+\n...
2CODEFORCES
610_C. Harmony Analysis_38290
The semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil was very bored on this lesson until the teacher gave the group a simple task: find 4 vectors in 4-dimensional space, such that every coordinate of every vec...
#include <bits/stdc++.h> using namespace std; bool mask[1006][1006]; void gen(int x) { int dl = (1 << (x - 1)); for (int i = 0; i < dl; i++) for (int j = 0; j < dl; j++) { mask[i + dl][j] = mask[i][j]; mask[i][j + dl] = mask[i][j]; mask[i + dl][j + dl] = !mask[i][j]; } } void wypisz(int k)...
2C++
{ "input": [ "2\n", "2\n", "4\n", "1\n", "5\n", "7\n", "8\n", "6\n", "0\n", "3\n" ], "output": [ "++++\n+*+*\n++**\n+**+\n", "++++\n+*+*\n++**\n+**+\n", "++++++++++++++++\n+*+*+*+*+*+*+*+*\n++**++**++**++**\n+**++**++**++**+\n++++****++++****\n+*+**+*++*+**+*+\n...
2CODEFORCES
610_C. Harmony Analysis_38291
The semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil was very bored on this lesson until the teacher gave the group a simple task: find 4 vectors in 4-dimensional space, such that every coordinate of every vec...
p = [[0]] for i in range(int(input())): p = [t + t for t in p] + [[1 - q for q in t] + t for t in p] for t in p: print(''.join('+*'[q] for q in t))
3Python3
{ "input": [ "2\n", "2\n", "4\n", "1\n", "5\n", "7\n", "8\n", "6\n", "0\n", "3\n" ], "output": [ "++++\n+*+*\n++**\n+**+\n", "++++\n+*+*\n++**\n+**+\n", "++++++++++++++++\n+*+*+*+*+*+*+*+*\n++**++**++**++**\n+**++**++**++**+\n++++****++++****\n+*+**+*++*+**+*+\n...
2CODEFORCES
610_C. Harmony Analysis_38292
The semester is already ending, so Danil made an effort and decided to visit a lesson on harmony analysis to know how does the professor look like, at least. Danil was very bored on this lesson until the teacher gave the group a simple task: find 4 vectors in 4-dimensional space, such that every coordinate of every vec...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.Writer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; ...
4JAVA
{ "input": [ "2\n", "2\n", "4\n", "1\n", "5\n", "7\n", "8\n", "6\n", "0\n", "3\n" ], "output": [ "++++\n+*+*\n++**\n+**+\n", "++++\n+*+*\n++**\n+**+\n", "++++++++++++++++\n+*+*+*+*+*+*+*+*\n++**++**++**++**\n+**++**++**++**+\n++++****++++****\n+*+**+*++*+**+*+\n...
2CODEFORCES
630_M. Turn_38293
Vasya started working in a machine vision company of IT City. Vasya's team creates software and hardware for identification of people by their face. One of the project's know-how is a camera rotating around its optical axis on shooting. People see an eye-catching gadget — a rotating camera — come up to it to see it be...
a=input() a=(a%360 + 360)%360 a=(a+44)%360 print (a%359) / 90
1Python2
{ "input": [ "-60\n", "60\n", "6678504591813508\n", "44\n", "225\n", "-45\n", "-358\n", "46\n", "-999999999999999415\n", "-999999999999999639\n", "-44\n", "-999999999999999325\n", "999999999999999326\n", "316\n", "359\n", "999999999999999416\n", "-13...
2CODEFORCES
630_M. Turn_38294
Vasya started working in a machine vision company of IT City. Vasya's team creates software and hardware for identification of people by their face. One of the project's know-how is a camera rotating around its optical axis on shooting. People see an eye-catching gadget — a rotating camera — come up to it to see it be...
#include <bits/stdc++.h> using namespace std; int main() { long long int deg; cin >> deg; deg %= 360; long long int ans[4]; ans[0] = deg; for (int i = 1; i < 4; i++) ans[i] = ((ans[i - 1] - 90)) % 360; for (int i = 0; i < 4; i++) ans[i] = abs(ans[i]); for (int i = 0; i < 4; i++) if (ans[i] > 180) an...
2C++
{ "input": [ "-60\n", "60\n", "6678504591813508\n", "44\n", "225\n", "-45\n", "-358\n", "46\n", "-999999999999999415\n", "-999999999999999639\n", "-44\n", "-999999999999999325\n", "999999999999999326\n", "316\n", "359\n", "999999999999999416\n", "-13...
2CODEFORCES
630_M. Turn_38295
Vasya started working in a machine vision company of IT City. Vasya's team creates software and hardware for identification of people by their face. One of the project's know-how is a camera rotating around its optical axis on shooting. People see an eye-catching gadget — a rotating camera — come up to it to see it be...
import math, re, sys, string, operator, functools, fractions, collections sys.setrecursionlimit(10**7) dX= [-1, 1, 0, 0,-1, 1,-1, 1] dY= [ 0, 0,-1, 1, 1,-1,-1, 1] RI=lambda x=' ': list(map(int,input().split(x))) RS=lambda x=' ': input().rstrip().split(x) mod=int(1e9+7) eps=1e-6 #########################################...
3Python3
{ "input": [ "-60\n", "60\n", "6678504591813508\n", "44\n", "225\n", "-45\n", "-358\n", "46\n", "-999999999999999415\n", "-999999999999999639\n", "-44\n", "-999999999999999325\n", "999999999999999326\n", "316\n", "359\n", "999999999999999416\n", "-13...
2CODEFORCES
630_M. Turn_38296
Vasya started working in a machine vision company of IT City. Vasya's team creates software and hardware for identification of people by their face. One of the project's know-how is a camera rotating around its optical axis on shooting. People see an eye-catching gadget — a rotating camera — come up to it to see it be...
import java.util.*; public class CodeForces { public static void main(String[] args) { Scanner in = new Scanner(System.in); long angle = in.nextLong(); if(angle < 0 ) angle = 360 - (Math.abs(angle)%360); else angle = angle%360; ...
4JAVA
{ "input": [ "-60\n", "60\n", "6678504591813508\n", "44\n", "225\n", "-45\n", "-358\n", "46\n", "-999999999999999415\n", "-999999999999999639\n", "-44\n", "-999999999999999325\n", "999999999999999326\n", "316\n", "359\n", "999999999999999416\n", "-13...
2CODEFORCES
659_E. New Reform_38297
Berland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities is connected by no more than one road. It is not guaranteed that you can get from any city to any other one, using only the existing roads. The President of Berland decided to make changes to the road sy...
from collections import deque n,m=map(int, raw_input().split(' ')) Graph=[[] for _ in range(n+1)] visited=[False]*(n+1) def dfs(start): nodes_visited=edges_travelled=0 nodes_visited+=1 visited[start]=True stack=[] stack.append(start) while stack: i=stack.pop() for j in Graph[i]: edges_travelled+=1 if ...
1Python2
{ "input": [ "5 5\n2 1\n1 3\n2 3\n2 5\n4 3\n", "4 3\n2 1\n1 3\n4 3\n", "6 5\n1 2\n2 3\n4 5\n4 6\n5 6\n", "10 45\n3 5\n2 3\n4 8\n2 5\n6 8\n5 7\n2 1\n3 7\n5 10\n6 1\n9 4\n3 6\n9 10\n6 7\n1 7\n7 9\n6 9\n9 3\n4 2\n2 6\n5 6\n5 8\n3 4\n10 8\n7 8\n4 6\n9 1\n5 9\n7 4\n1 10\n9 2\n2 8\n6 10\n9 8\n1 5\n7 2\n10 3...
2CODEFORCES
659_E. New Reform_38298
Berland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities is connected by no more than one road. It is not guaranteed that you can get from any city to any other one, using only the existing roads. The President of Berland decided to make changes to the road sy...
#include <bits/stdc++.h> using namespace std; int N, M; bool group[100001]; bool trip[100001]; vector<int> Map[100001]; bool flag; void search(int v, int par) { group[v] = true; trip[v] = true; for (int i = 0; i < Map[v].size(); i++) { int now = Map[v][i]; if (now == par) continue; if (trip[now]) flag...
2C++
{ "input": [ "5 5\n2 1\n1 3\n2 3\n2 5\n4 3\n", "4 3\n2 1\n1 3\n4 3\n", "6 5\n1 2\n2 3\n4 5\n4 6\n5 6\n", "10 45\n3 5\n2 3\n4 8\n2 5\n6 8\n5 7\n2 1\n3 7\n5 10\n6 1\n9 4\n3 6\n9 10\n6 7\n1 7\n7 9\n6 9\n9 3\n4 2\n2 6\n5 6\n5 8\n3 4\n10 8\n7 8\n4 6\n9 1\n5 9\n7 4\n1 10\n9 2\n2 8\n6 10\n9 8\n1 5\n7 2\n10 3...
2CODEFORCES
659_E. New Reform_38299
Berland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities is connected by no more than one road. It is not guaranteed that you can get from any city to any other one, using only the existing roads. The President of Berland decided to make changes to the road sy...
import sys from math import sqrt, gcd, ceil, log # from bisect import bisect, bisect_left from collections import defaultdict, Counter, deque # from heapq import heapify, heappush, heappop input = sys.stdin.readline read = lambda: list(map(int, input().strip().split())) sys.setrecursionlimit(200000) def main(): n,...
3Python3
{ "input": [ "5 5\n2 1\n1 3\n2 3\n2 5\n4 3\n", "4 3\n2 1\n1 3\n4 3\n", "6 5\n1 2\n2 3\n4 5\n4 6\n5 6\n", "10 45\n3 5\n2 3\n4 8\n2 5\n6 8\n5 7\n2 1\n3 7\n5 10\n6 1\n9 4\n3 6\n9 10\n6 7\n1 7\n7 9\n6 9\n9 3\n4 2\n2 6\n5 6\n5 8\n3 4\n10 8\n7 8\n4 6\n9 1\n5 9\n7 4\n1 10\n9 2\n2 8\n6 10\n9 8\n1 5\n7 2\n10 3...
2CODEFORCES