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
1144_B. Parity Alternated Deletions_900
Polycarp has an array a consisting of n integers. He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains n-1 elements). For each of the next moves he chooses any element with the only restriction: its...
n=int(input()) arr=list(map(int,input().split())) arr.sort() even=[] odd=[] e=0 o=0 for i in arr: if (i%2)==0: even=even+[i] e=e+1 else: odd=odd+[i] o=o+1 if (e>o) and (e-o)>1: print(sum(even[:(e-o-1)])) elif (o>e) and (o-e)>1: print(sum(odd[:(o-e-1)])) else: print(0)
3Python3
{ "input": [ "2\n1000000 1000000\n", "6\n5 1 2 4 6 3\n", "5\n1 5 7 8 2\n", "5\n1 1 1 1 1\n", "5\n2 1 1 1 1\n", "5\n2 1 1 1 2\n", "6\n5 1 3 4 8 3\n", "5\n1 5 7 1 2\n", "6\n5 1 3 4 5 3\n", "2\n1000010 1001000\n", "2\n1000110 1001000\n", "2\n1000110 1000000\n", "2\n000...
2CODEFORCES
1144_B. Parity Alternated Deletions_901
Polycarp has an array a consisting of n integers. He wants to play a game with this array. The game consists of several moves. On the first move he chooses any element and deletes it (after the first move the array contains n-1 elements). For each of the next moves he chooses any element with the only restriction: its...
import java.util.ArrayList; import java.util.Scanner; import java.util.Collections; import java.util.Comparator; public class Solution { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.nextLine(); int a[] = new int[n]; ...
4JAVA
{ "input": [ "2\n1000000 1000000\n", "6\n5 1 2 4 6 3\n", "5\n1 5 7 8 2\n", "5\n1 1 1 1 1\n", "5\n2 1 1 1 1\n", "5\n2 1 1 1 2\n", "6\n5 1 3 4 8 3\n", "5\n1 5 7 1 2\n", "6\n5 1 3 4 5 3\n", "2\n1000010 1001000\n", "2\n1000110 1001000\n", "2\n1000110 1000000\n", "2\n000...
2CODEFORCES
1165_A. Remainder_902
You are given a huge decimal number consisting of n digits. It is guaranteed that this number has no leading zeros. Each digit of this number is either 0 or 1. You may perform several (possibly zero) operations with this number. During each operation you are allowed to change any digit of your number; you may change 0...
wei, b, c=raw_input().split() a=raw_input().split() h=a[0] wei = int(wei) b = int(b) c = int(c) t2 = h[-c-1] e=0 for i in range(-b , 0): if i == -c-1: if t2 == '0': e=e+1 else: if h[i]=='1': e=e+1 print(e)
1Python2
{ "input": [ "11 5 2\n11010100101\n", "11 5 1\n11010100101\n", "6 4 2\n100010\n", "4 2 1\n1000\n", "8 5 2\n10000100\n", "11 5 2\n11010000101\n", "64 40 14\n1010011100101100101011000001000011110111011011000111011011000100\n", "7 5 3\n1011000\n", "8 5 1\n10000000\n", "5 2 1\n1101...
2CODEFORCES
1165_A. Remainder_903
You are given a huge decimal number consisting of n digits. It is guaranteed that this number has no leading zeros. Each digit of this number is either 0 or 1. You may perform several (possibly zero) operations with this number. During each operation you are allowed to change any digit of your number; you may change 0...
#include <bits/stdc++.h> using namespace std; int main() { int n, y, x, sum = 0; string str; cin >> n >> x >> y >> str; int len = str.size() - 1; for (int i = len; i > len - x; i--) { if (str[i] == '1') sum++; } if (str[len - y] == '0') sum++; else sum--; cout << sum << endl; return 0; }...
2C++
{ "input": [ "11 5 2\n11010100101\n", "11 5 1\n11010100101\n", "6 4 2\n100010\n", "4 2 1\n1000\n", "8 5 2\n10000100\n", "11 5 2\n11010000101\n", "64 40 14\n1010011100101100101011000001000011110111011011000111011011000100\n", "7 5 3\n1011000\n", "8 5 1\n10000000\n", "5 2 1\n1101...
2CODEFORCES
1165_A. Remainder_904
You are given a huge decimal number consisting of n digits. It is guaranteed that this number has no leading zeros. Each digit of this number is either 0 or 1. You may perform several (possibly zero) operations with this number. During each operation you are allowed to change any digit of your number; you may change 0...
n,x,y = map(int,input().split()) s = input()[-x:] if(y == 0): num = s[:-(y+1)].count('1') else: num = s[:-(y+1)].count('1') + s[-y:].count('1') if(s[-(y+1)] == "0"): num = num + 1 print(num)
3Python3
{ "input": [ "11 5 2\n11010100101\n", "11 5 1\n11010100101\n", "6 4 2\n100010\n", "4 2 1\n1000\n", "8 5 2\n10000100\n", "11 5 2\n11010000101\n", "64 40 14\n1010011100101100101011000001000011110111011011000111011011000100\n", "7 5 3\n1011000\n", "8 5 1\n10000000\n", "5 2 1\n1101...
2CODEFORCES
1165_A. Remainder_905
You are given a huge decimal number consisting of n digits. It is guaranteed that this number has no leading zeros. Each digit of this number is either 0 or 1. You may perform several (possibly zero) operations with this number. During each operation you are allowed to change any digit of your number; you may change 0...
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int c=0, t,n=sc.nextInt(),x=sc.nextInt(),y=sc.nextInt(); String s=sc.next(); for(t=0;t<y;t++){ n--; if(s.charAt(n)!='0')c++; }n...
4JAVA
{ "input": [ "11 5 2\n11010100101\n", "11 5 1\n11010100101\n", "6 4 2\n100010\n", "4 2 1\n1000\n", "8 5 2\n10000100\n", "11 5 2\n11010000101\n", "64 40 14\n1010011100101100101011000001000011110111011011000111011011000100\n", "7 5 3\n1011000\n", "8 5 1\n10000000\n", "5 2 1\n1101...
2CODEFORCES
1184_B3. The Doctor Meets Vader (Hard)_906
The rebels have saved enough gold to launch a full-scale attack. Now the situation is flipped, the rebels will send out the spaceships to attack the Empire bases! The galaxy can be represented as an undirected graph with n planets (nodes) and m wormholes (edges), each connecting two planets. A total of s rebel spaces...
#include <bits/stdc++.h> using namespace std; const int N = 1e2 + 10; const int maxs = 1e5 + 10; const int maxn = 2e3 + 10; const int maxm = 6e3 + 10; const long long INF = 1e14 + 10; const long long INF_CAP = INF; struct spaceship { int x, a, f, p; } sp[maxs]; struct base { int d, g; bool operator<(const base& b...
2C++
{ "input": [ "6 7\n1 2\n2 3\n3 4\n4 6\n6 5\n4 4\n3 6\n4 2 2\n1 10 2 5\n3 8 2 7\n5 1 0 2\n6 5 4 1\n3 7 6\n5 2 3\n4 2\n3 2\n", "1 0\n1 1 0\n1 446844829 77109657 780837560\n1 754808995 539371459\n", "1 1\n1 1\n2 2 0\n1 531091498 755275238 645143315\n1 936400451 457379982 948257592\n1 45309968 181471857\n1 55...
2CODEFORCES
1184_B3. The Doctor Meets Vader (Hard)_907
The rebels have saved enough gold to launch a full-scale attack. Now the situation is flipped, the rebels will send out the spaceships to attack the Empire bases! The galaxy can be represented as an undirected graph with n planets (nodes) and m wormholes (edges), each connecting two planets. A total of s rebel spaces...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.OutputStream; import java.util.Arrays; import java.io.IOException; import java.util.InputMismatchException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List;...
4JAVA
{ "input": [ "6 7\n1 2\n2 3\n3 4\n4 6\n6 5\n4 4\n3 6\n4 2 2\n1 10 2 5\n3 8 2 7\n5 1 0 2\n6 5 4 1\n3 7 6\n5 2 3\n4 2\n3 2\n", "1 0\n1 1 0\n1 446844829 77109657 780837560\n1 754808995 539371459\n", "1 1\n1 1\n2 2 0\n1 531091498 755275238 645143315\n1 936400451 457379982 948257592\n1 45309968 181471857\n1 55...
2CODEFORCES
1202_C. You Are Given a WASD-string..._908
You have a string s — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands: * 'W' — move one cell up; * 'S' — move one cell down; * 'A' — move one cell left; * 'D' — move one cell right. Let Grid(s) be the grid of minimum possibl...
from __future__ import division, print_function DEBUG = 0 INF = float('inf') MOD = 10**9 + 7 import os, sys from atexit import register from io import BytesIO import itertools if sys.version_info[0] < 3: input = raw_input range = xrange filter = itertools.ifilter map = itertools.imap zip = iter...
1Python2
{ "input": [ "3\nDSAWWAW\nD\nWA\n", "3\nDSAWWAW\nD\nAW\n", "3\nWSAWDAW\nD\nAW\n", "3\nDAAWWSW\nD\nAW\n", "3\nWAWWASD\nD\nWA\n", "3\nASAWWDW\nD\nWA\n", "3\nWAWWASD\nD\nAW\n", "3\nWSAWDAW\nD\nWA\n", "3\nWDWWASA\nD\nWA\n", "3\nWDWWASA\nD\nAW\n", "3\nWSADWAW\nD\nWA\n", "3\n...
2CODEFORCES
1202_C. You Are Given a WASD-string..._909
You have a string s — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands: * 'W' — move one cell up; * 'S' — move one cell down; * 'A' — move one cell left; * 'D' — move one cell right. Let Grid(s) be the grid of minimum possibl...
#include <bits/stdc++.h> using namespace std; const int maxs = 200000; const char dbuf[] = "DWAS"; const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; char s[maxs + 1]; int xv[maxs + 1]; int yv[maxs + 1]; int lprv[maxs + 1]; int bprv[maxs + 1]; int rprv[maxs + 1]; int tprv[maxs + 1]; int lnxt[maxs + 1]; int...
2C++
{ "input": [ "3\nDSAWWAW\nD\nWA\n", "3\nDSAWWAW\nD\nAW\n", "3\nWSAWDAW\nD\nAW\n", "3\nDAAWWSW\nD\nAW\n", "3\nWAWWASD\nD\nWA\n", "3\nASAWWDW\nD\nWA\n", "3\nWAWWASD\nD\nAW\n", "3\nWSAWDAW\nD\nWA\n", "3\nWDWWASA\nD\nWA\n", "3\nWDWWASA\nD\nAW\n", "3\nWSADWAW\nD\nWA\n", "3\n...
2CODEFORCES
1202_C. You Are Given a WASD-string..._910
You have a string s — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands: * 'W' — move one cell up; * 'S' — move one cell down; * 'A' — move one cell left; * 'D' — move one cell right. Let Grid(s) be the grid of minimum possibl...
def lim(s): now = 0 up, down = 0, 0 for i in s: now += i up = max(up, now) down = min(down, now) return up, down def f(a): return a[0] - a[1] + 1 def upg(s): t = lim(s) up, down = t[0], t[1] arr = [1, 1] now = 0 for i in range(len(s) - 1): if now =...
3Python3
{ "input": [ "3\nDSAWWAW\nD\nWA\n", "3\nDSAWWAW\nD\nAW\n", "3\nWSAWDAW\nD\nAW\n", "3\nDAAWWSW\nD\nAW\n", "3\nWAWWASD\nD\nWA\n", "3\nASAWWDW\nD\nWA\n", "3\nWAWWASD\nD\nAW\n", "3\nWSAWDAW\nD\nWA\n", "3\nWDWWASA\nD\nWA\n", "3\nWDWWASA\nD\nAW\n", "3\nWSADWAW\nD\nWA\n", "3\n...
2CODEFORCES
1202_C. You Are Given a WASD-string..._911
You have a string s — a sequence of commands for your toy robot. The robot is placed in some cell of a rectangular grid. He can perform four commands: * 'W' — move one cell up; * 'S' — move one cell down; * 'A' — move one cell left; * 'D' — move one cell right. Let Grid(s) be the grid of minimum possibl...
import java.io.*; import java.util.*; public class Main { static int inf = (int) (1e9 + 7); public static void main(String[] args) throws IOException { sc = new Scanner(System.in); pw = new PrintWriter(System.out); for(int test = sc.nextInt();test > 0;test--) { char h[] = ...
4JAVA
{ "input": [ "3\nDSAWWAW\nD\nWA\n", "3\nDSAWWAW\nD\nAW\n", "3\nWSAWDAW\nD\nAW\n", "3\nDAAWWSW\nD\nAW\n", "3\nWAWWASD\nD\nWA\n", "3\nASAWWDW\nD\nWA\n", "3\nWAWWASD\nD\nAW\n", "3\nWSAWDAW\nD\nWA\n", "3\nWDWWASA\nD\nWA\n", "3\nWDWWASA\nD\nAW\n", "3\nWSADWAW\nD\nWA\n", "3\n...
2CODEFORCES
1219_H. Function Composition_912
We are definitely not going to bother you with another generic story when Alice finds about an array or when Alice and Bob play some stupid game. This time you'll get a simple, plain text. First, let us define several things. We define function F on the array A such that F(i, 1) = A[i] and F(i, m) = A[F(i, m - 1)] for...
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 200200; int n, m; int ANS[N]; int g[N]; vector<int> G[N]; int deg[N]; int q[N]; int topQ; int id[N]; vector<int> a[N]; vector<pair<long long, int> > Q[N]; vector<pair<int, int> > b[N]; vector...
2C++
{ "input": [ "10\n2 3 1 5 6 4 2 10 7 7\n5\n10 1\n5 7\n10 6\n1 1\n10 8\n", "10\n2 3 1 5 6 4 2 10 7 7\n5\n10 1\n5 7\n19 6\n1 1\n10 8\n", "10\n2 3 1 5 6 4 1 10 7 7\n5\n10 1\n5 7\n19 6\n1 1\n10 8\n", "10\n2 3 1 5 6 4 2 10 7 7\n5\n10 1\n5 7\n10 6\n1 2\n10 8\n", "10\n1 3 1 5 6 4 1 10 7 7\n5\n10 1\n5 7\n...
2CODEFORCES
1244_C. The Football Season_913
The football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of the playing teams. If a team wins the match, it gets w points, and the opposing team gets 0 points. If the game results in ...
from fractions import gcd def modinv(x, n): s, old_s = 0, 1 t, old_t = 1, 0 r, old_r = n, x while r != 0: quotient = old_r // r old_r, r = r, old_r - quotient * r old_s, s = s, old_s - quotient * s old_t, t = t, old_t - quotient * t if old_r != 1: return -1 ...
1Python2
{ "input": [ "30 60 3 1\n", "20 0 15 5\n", "10 51 5 4\n", "728961319347 33282698448966372 52437 42819\n", "461788563846 36692905412962338 93797 64701\n", "567018385179 15765533940665693 35879 13819\n", "21644595275 987577030498703 66473 35329\n", "1000000000000 1000000000000 6 3\n", ...
2CODEFORCES
1244_C. The Football Season_914
The football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of the playing teams. If a team wins the match, it gets w points, and the opposing team gets 0 points. If the game results in ...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int mod1 = 998244353; const long long inf = 5e18; long long n, p, w, d; void solve() { cin >> n >> p >> w >> d; for (long long draw = 0; draw < w; draw++) { long long score = draw * d; long long win = (p - score) / w; if (win >...
2C++
{ "input": [ "30 60 3 1\n", "20 0 15 5\n", "10 51 5 4\n", "728961319347 33282698448966372 52437 42819\n", "461788563846 36692905412962338 93797 64701\n", "567018385179 15765533940665693 35879 13819\n", "21644595275 987577030498703 66473 35329\n", "1000000000000 1000000000000 6 3\n", ...
2CODEFORCES
1244_C. The Football Season_915
The football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of the playing teams. If a team wins the match, it gets w points, and the opposing team gets 0 points. If the game results in ...
import sys from sys import argv def extendedEuclideanAlgorithm(old_r, r): negative = False s, old_t = 0, 0 old_s, t = 1, 1 if (r < 0): r = abs(r) negative = True while r > 0: q = old_r // r #MCD: r, old_r = old_r - q * r, r #Coeficiente s: ...
3Python3
{ "input": [ "30 60 3 1\n", "20 0 15 5\n", "10 51 5 4\n", "728961319347 33282698448966372 52437 42819\n", "461788563846 36692905412962338 93797 64701\n", "567018385179 15765533940665693 35879 13819\n", "21644595275 987577030498703 66473 35329\n", "1000000000000 1000000000000 6 3\n", ...
2CODEFORCES
1244_C. The Football Season_916
The football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of the playing teams. If a team wins the match, it gets w points, and the opposing team gets 0 points. If the game results in ...
import java.util.*; import java.io.*; public class C592 { public static void main(String [] args) { MyScanner sc = new MyScanner(); PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); long n = sc.nextLong(); long p = sc.nextLong(); long w = sc.nextLong(); long d = sc...
4JAVA
{ "input": [ "30 60 3 1\n", "20 0 15 5\n", "10 51 5 4\n", "728961319347 33282698448966372 52437 42819\n", "461788563846 36692905412962338 93797 64701\n", "567018385179 15765533940665693 35879 13819\n", "21644595275 987577030498703 66473 35329\n", "1000000000000 1000000000000 6 3\n", ...
2CODEFORCES
1264_A. Beautiful Regional Contest_917
So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved p_i problems. Since the participants are primarily sorted by the number of solved problems, then p_1 ≥ p_2 ≥ ... ≥ p_n. Help the jury distrib...
'''input 6 13 39 29 26 24 24 24 24 8 8 2 2 2 2 12 5 4 4 3 2 2 1 1 1 1 1 1 4 4 3 2 1 1 1000000 20 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 32 64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11 ''' import sys debug = 0 readln = sys.stdin.readline def write(s): ...
1Python2
{ "input": [ "5\n12\n5 4 4 3 2 2 1 1 1 1 1 1\n4\n4 3 2 1\n1\n1000000\n20\n20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1\n32\n64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11\n", "5\n12\n5 4 4 3 2 2 1 1 1 1 1 1\n4\n4 3 2 1\n1\n1000000\n20\n20 19 18 17 16 15 1...
2CODEFORCES
1264_A. Beautiful Regional Contest_918
So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved p_i problems. Since the participants are primarily sorted by the number of solved problems, then p_1 ≥ p_2 ≥ ... ≥ p_n. Help the jury distrib...
#include <bits/stdc++.h> using namespace std; int p[400100]; int s[400100]; int cnt[1000100], ct[400100]; int main() { int t; cin >> t; while (t--) { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &p[i]); int len = 0; for (int i = 1; i <= n; i++) { if (cnt[p[i]] == 0 an...
2C++
{ "input": [ "5\n12\n5 4 4 3 2 2 1 1 1 1 1 1\n4\n4 3 2 1\n1\n1000000\n20\n20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1\n32\n64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11\n", "5\n12\n5 4 4 3 2 2 1 1 1 1 1 1\n4\n4 3 2 1\n1\n1000000\n20\n20 19 18 17 16 15 1...
2CODEFORCES
1264_A. Beautiful Regional Contest_919
So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved p_i problems. Since the participants are primarily sorted by the number of solved problems, then p_1 ≥ p_2 ≥ ... ≥ p_n. Help the jury distrib...
'''input 5 12 5 4 4 3 2 2 1 1 1 1 1 1 4 4 3 2 1 1 1000000 20 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 32 64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11 ''' t=int(input()) for i in range(t): n=int(input()) s=list(map(int,input().split())) if n//2<3: print("...
3Python3
{ "input": [ "5\n12\n5 4 4 3 2 2 1 1 1 1 1 1\n4\n4 3 2 1\n1\n1000000\n20\n20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1\n32\n64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11\n", "5\n12\n5 4 4 3 2 2 1 1 1 1 1 1\n4\n4 3 2 1\n1\n1000000\n20\n20 19 18 17 16 15 1...
2CODEFORCES
1264_A. Beautiful Regional Contest_920
So the Beautiful Regional Contest (BeRC) has come to an end! n students took part in the contest. The final standings are already known: the participant in the i-th place solved p_i problems. Since the participants are primarily sorted by the number of solved problems, then p_1 ≥ p_2 ≥ ... ≥ p_n. Help the jury distrib...
import java.util.*; import java.io.*; public class bfs { static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader...
4JAVA
{ "input": [ "5\n12\n5 4 4 3 2 2 1 1 1 1 1 1\n4\n4 3 2 1\n1\n1000000\n20\n20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1\n32\n64 64 63 58 58 58 58 58 37 37 37 37 34 34 28 28 28 28 28 28 24 24 19 17 17 17 17 16 16 16 16 11\n", "5\n12\n5 4 4 3 2 2 1 1 1 1 1 1\n4\n4 3 2 1\n1\n1000000\n20\n20 19 18 17 16 15 1...
2CODEFORCES
1285_C. Fadi and LCM_921
Today, Osama gave Fadi an integer X, and Fadi was wondering about the minimum possible value of max(a, b) such that LCM(a, b) equals X. Both a and b should be positive integers. LCM(a, b) is the smallest positive integer that is divisible by both a and b. For example, LCM(6, 8) = 24, LCM(4, 12) = 12, LCM(2, 3) = 6. O...
def gcd(a,b): while b: a,b=b,a%b return a n=input() maxx=n for i in range(1,int(n**(0.5)+1)): if n%i==0: s=n/i x=gcd(i,s) m=max(i,s) m*=x maxx=min(maxx,m) a=maxx b=n/maxx b*=gcd(a,b) print min(a,b),max(a,b)
1Python2
{ "input": [ "1\n", "4\n", "6\n", "2\n", "205078485761\n", "873109054817\n", "518649879439\n", "401021537803\n", "821985629174\n", "614685146646\n", "551519879446\n", "583102513046\n", "690824608515\n", "681460970070\n", "355170254369\n", "924639053494\n...
2CODEFORCES
1285_C. Fadi and LCM_922
Today, Osama gave Fadi an integer X, and Fadi was wondering about the minimum possible value of max(a, b) such that LCM(a, b) equals X. Both a and b should be positive integers. LCM(a, b) is the smallest positive integer that is divisible by both a and b. For example, LCM(6, 8) = 24, LCM(4, 12) = 12, LCM(2, 3) = 6. O...
#include <bits/stdc++.h> using namespace std; vector<long long> factors; void trial(long long n) { int count; long long ini = n; for (long long d = 2; d * d <= n; d++) { if (n % d == 0) { ini = n; while (n % d == 0) { n /= d; } long long s = ini / n; factors.push_back(s);...
2C++
{ "input": [ "1\n", "4\n", "6\n", "2\n", "205078485761\n", "873109054817\n", "518649879439\n", "401021537803\n", "821985629174\n", "614685146646\n", "551519879446\n", "583102513046\n", "690824608515\n", "681460970070\n", "355170254369\n", "924639053494\n...
2CODEFORCES
1285_C. Fadi and LCM_923
Today, Osama gave Fadi an integer X, and Fadi was wondering about the minimum possible value of max(a, b) such that LCM(a, b) equals X. Both a and b should be positive integers. LCM(a, b) is the smallest positive integer that is divisible by both a and b. For example, LCM(6, 8) = 24, LCM(4, 12) = 12, LCM(2, 3) = 6. O...
def LMC(a, b): n = a * b while a != 0 and b != 0: if a > b: a = a % b else: b = b % a nod = a + b nok = n // nod return nok from math import sqrt, ceil n = int(input()) dividers = [] for i in range(1, ceil(sqrt(n))): if n % i == 0: dividers.appe...
3Python3
{ "input": [ "1\n", "4\n", "6\n", "2\n", "205078485761\n", "873109054817\n", "518649879439\n", "401021537803\n", "821985629174\n", "614685146646\n", "551519879446\n", "583102513046\n", "690824608515\n", "681460970070\n", "355170254369\n", "924639053494\n...
2CODEFORCES
1285_C. Fadi and LCM_924
Today, Osama gave Fadi an integer X, and Fadi was wondering about the minimum possible value of max(a, b) such that LCM(a, b) equals X. Both a and b should be positive integers. LCM(a, b) is the smallest positive integer that is divisible by both a and b. For example, LCM(6, 8) = 24, LCM(4, 12) = 12, LCM(2, 3) = 6. O...
import java.io.*; import java.util.*; /* REMINDERS * CHECK INT VS LONG, IF YOU NEED TO STORE LARGE NUMBERS * CHECK CONSTRAINTS, C <= N <= F... * CHECK SPECIAL CASES, N = 1... * CHECK ARRAY BOUNDS, HOW BIG ARRAY HAS TO BE * TO TEST TLE/MLE, PLUG IN MAX VALS ALLOWED AND SEE WHAT HAPPENS * ALSO CALCULATE BIG-O, OVER...
4JAVA
{ "input": [ "1\n", "4\n", "6\n", "2\n", "205078485761\n", "873109054817\n", "518649879439\n", "401021537803\n", "821985629174\n", "614685146646\n", "551519879446\n", "583102513046\n", "690824608515\n", "681460970070\n", "355170254369\n", "924639053494\n...
2CODEFORCES
1304_E. 1-Trees and Queries_925
Gildong was hiking a mountain, walking by millions of trees. Inspired by them, he suddenly came up with an interesting idea for trees in data structures: What if we add another edge in a tree? Then he found that such tree-like graphs are called 1-trees. Since Gildong was bored of solving too many tree problems, he wan...
import sys range = xrange input = raw_input class RangeQuery: def __init__(self, data, func=min): self.func = func self._data = _data = [list(data)] i, n = 1, len(_data[0]) while 2 * i <= n: prev = _data[-1] _data.append([func(prev[j], prev[j + i]) for j in ...
1Python2
{ "input": [ "5\n1 2\n2 3\n3 4\n4 5\n5\n1 3 1 2 2\n1 4 1 3 2\n1 4 1 3 3\n4 2 3 3 9\n5 2 3 3 9\n", "9\n3 9\n3 4\n7 2\n6 9\n5 3\n6 2\n8 3\n1 9\n10\n8 4 8 2 5\n9 2 7 4 4\n8 5 7 3 3\n1 2 3 8 4\n2 9 2 4 3\n6 4 3 4 5\n6 7 6 6 4\n7 5 3 1 4\n5 4 7 8 3\n4 5 1 5 2\n", "14\n4 9\n3 7\n4 1\n3 2\n14 9\n7 6\n10 13\n8 7\...
2CODEFORCES
1304_E. 1-Trees and Queries_926
Gildong was hiking a mountain, walking by millions of trees. Inspired by them, he suddenly came up with an interesting idea for trees in data structures: What if we add another edge in a tree? Then he found that such tree-like graphs are called 1-trees. Since Gildong was bored of solving too many tree problems, he wan...
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; inline long long add(long long a, long long b) { a += b; if (a >= mod) a -= mod; return a; } inline long long sub(long long a, long long b) { a -= b; if (a < 0) a += mod; return a; } inline long long mul(long long a, long long b) { ret...
2C++
{ "input": [ "5\n1 2\n2 3\n3 4\n4 5\n5\n1 3 1 2 2\n1 4 1 3 2\n1 4 1 3 3\n4 2 3 3 9\n5 2 3 3 9\n", "9\n3 9\n3 4\n7 2\n6 9\n5 3\n6 2\n8 3\n1 9\n10\n8 4 8 2 5\n9 2 7 4 4\n8 5 7 3 3\n1 2 3 8 4\n2 9 2 4 3\n6 4 3 4 5\n6 7 6 6 4\n7 5 3 1 4\n5 4 7 8 3\n4 5 1 5 2\n", "14\n4 9\n3 7\n4 1\n3 2\n14 9\n7 6\n10 13\n8 7\...
2CODEFORCES
1304_E. 1-Trees and Queries_927
Gildong was hiking a mountain, walking by millions of trees. Inspired by them, he suddenly came up with an interesting idea for trees in data structures: What if we add another edge in a tree? Then he found that such tree-like graphs are called 1-trees. Since Gildong was bored of solving too many tree problems, he wan...
import sys, os class RangeQuery: def __init__(self, data, func=min): self.func = func self._data = _data = [list(data)] i, n = 1, len(_data[0]) while 2 * i <= n: prev = _data[-1] _data.append([func(prev[j], prev[j + i]) for j in range(n - 2 * i + 1)]) ...
3Python3
{ "input": [ "5\n1 2\n2 3\n3 4\n4 5\n5\n1 3 1 2 2\n1 4 1 3 2\n1 4 1 3 3\n4 2 3 3 9\n5 2 3 3 9\n", "9\n3 9\n3 4\n7 2\n6 9\n5 3\n6 2\n8 3\n1 9\n10\n8 4 8 2 5\n9 2 7 4 4\n8 5 7 3 3\n1 2 3 8 4\n2 9 2 4 3\n6 4 3 4 5\n6 7 6 6 4\n7 5 3 1 4\n5 4 7 8 3\n4 5 1 5 2\n", "14\n4 9\n3 7\n4 1\n3 2\n14 9\n7 6\n10 13\n8 7\...
2CODEFORCES
1304_E. 1-Trees and Queries_928
Gildong was hiking a mountain, walking by millions of trees. Inspired by them, he suddenly came up with an interesting idea for trees in data structures: What if we add another edge in a tree? Then he found that such tree-like graphs are called 1-trees. Since Gildong was bored of solving too many tree problems, he wan...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.util.ArrayList; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author...
4JAVA
{ "input": [ "5\n1 2\n2 3\n3 4\n4 5\n5\n1 3 1 2 2\n1 4 1 3 2\n1 4 1 3 3\n4 2 3 3 9\n5 2 3 3 9\n", "9\n3 9\n3 4\n7 2\n6 9\n5 3\n6 2\n8 3\n1 9\n10\n8 4 8 2 5\n9 2 7 4 4\n8 5 7 3 3\n1 2 3 8 4\n2 9 2 4 3\n6 4 3 4 5\n6 7 6 6 4\n7 5 3 1 4\n5 4 7 8 3\n4 5 1 5 2\n", "14\n4 9\n3 7\n4 1\n3 2\n14 9\n7 6\n10 13\n8 7\...
2CODEFORCES
1328_F. Make k Equal_929
You are given the array a consisting of n elements and the integer k ≤ n. You want to obtain at least k equal elements in the array a. In one move, you can make one of the following two operations: * Take one of the minimum elements of the array and increase its value by one (more formally, if the minimum value of ...
n,k = map(int,raw_input().split()) arr = map(int,raw_input().split()) d1 ={} d2 = {} arr.sort() for i in range(0,2*10**5+1): d1[i] = 0 d2[i] = 0 for i in arr: cnt = 0 if(d2[i]<k): d2[i] = d2[i] + 1 while(i>0): i = i/2 cnt = cnt + 1 if(d2[i]<k): d1[i] = d1...
1Python2
{ "input": [ "6 5\n1 2 2 4 2 3\n", "7 5\n3 3 2 1 1 1 3\n", "21 6\n12 15 14 4 4 7 2 4 11 1 15 4 12 11 12 8 11 12 3 4 4\n", "50 25\n19 1 17 6 4 21 9 16 5 21 2 12 17 11 54 18 36 20 34 17 32 1 4 14 26 11 6 2 7 5 2 3 12 16 20 5 16 1 18 55 16 20 2 3 2 12 65 20 7 11\n", "5 2\n9 9 9 9 9\n", "1 1\n1000...
2CODEFORCES
1328_F. Make k Equal_930
You are given the array a consisting of n elements and the integer k ≤ n. You want to obtain at least k equal elements in the array a. In one move, you can make one of the following two operations: * Take one of the minimum elements of the array and increase its value by one (more formally, if the minimum value of ...
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; const unsigned long long nmax = 200002; unsigned long long n, k, a[nmax], s[nmax], t[nmax], c[nmax], r = UINT64_MAX, A, B; int main() { scanf("%llu%llu", &n, &k); for (unsigned ...
2C++
{ "input": [ "6 5\n1 2 2 4 2 3\n", "7 5\n3 3 2 1 1 1 3\n", "21 6\n12 15 14 4 4 7 2 4 11 1 15 4 12 11 12 8 11 12 3 4 4\n", "50 25\n19 1 17 6 4 21 9 16 5 21 2 12 17 11 54 18 36 20 34 17 32 1 4 14 26 11 6 2 7 5 2 3 12 16 20 5 16 1 18 55 16 20 2 3 2 12 65 20 7 11\n", "5 2\n9 9 9 9 9\n", "1 1\n1000...
2CODEFORCES
1328_F. Make k Equal_931
You are given the array a consisting of n elements and the integer k ≤ n. You want to obtain at least k equal elements in the array a. In one move, you can make one of the following two operations: * Take one of the minimum elements of the array and increase its value by one (more formally, if the minimum value of ...
n, k = map(int, input().split()) a = sorted(list(map(int, input().split()))) cnt = dict() sum = dict() res = n * 20 for x in a: y = x cur = 0 while True: if y == 0: break if y not in cnt: cnt[y] = 0 sum[y] = 0 if cnt[y] < k: cnt[y] +...
3Python3
{ "input": [ "6 5\n1 2 2 4 2 3\n", "7 5\n3 3 2 1 1 1 3\n", "21 6\n12 15 14 4 4 7 2 4 11 1 15 4 12 11 12 8 11 12 3 4 4\n", "50 25\n19 1 17 6 4 21 9 16 5 21 2 12 17 11 54 18 36 20 34 17 32 1 4 14 26 11 6 2 7 5 2 3 12 16 20 5 16 1 18 55 16 20 2 3 2 12 65 20 7 11\n", "5 2\n9 9 9 9 9\n", "1 1\n1000...
2CODEFORCES
1328_F. Make k Equal_932
You are given the array a consisting of n elements and the integer k ≤ n. You want to obtain at least k equal elements in the array a. In one move, you can make one of the following two operations: * Take one of the minimum elements of the array and increase its value by one (more formally, if the minimum value of ...
/* * @author romit17 */ import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.HashMap; import java.util.InputMismatchException; import java.util.Random; public class D1213 { void solve() throws IOException { PrintWriter out = ...
4JAVA
{ "input": [ "6 5\n1 2 2 4 2 3\n", "7 5\n3 3 2 1 1 1 3\n", "21 6\n12 15 14 4 4 7 2 4 11 1 15 4 12 11 12 8 11 12 3 4 4\n", "50 25\n19 1 17 6 4 21 9 16 5 21 2 12 17 11 54 18 36 20 34 17 32 1 4 14 26 11 6 2 7 5 2 3 12 16 20 5 16 1 18 55 16 20 2 3 2 12 65 20 7 11\n", "5 2\n9 9 9 9 9\n", "1 1\n1000...
2CODEFORCES
1348_F. Phoenix and Memory_933
Phoenix is trying to take a photo of his n friends with labels 1, 2, ..., n who are lined up in a row in a special order. But before he can take the photo, his friends get distracted by a duck and mess up their order. Now, Phoenix must restore the order but he doesn't remember completely! He only remembers that the i-...
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; long long n, m, t, k; int pos[200005], tmp[200005]; pair<pair<int, int>, int> a[200005]; class dsu { public: int fa[200005]; void init(int n) { for (int i = 0; i <= n; i++) { fa[i] = i; } } int find(int u) { while (u != fa[...
2C++
{ "input": [ "4\n1 3\n2 4\n3 4\n2 3\n", "4\n4 4\n1 3\n2 4\n3 4\n", "4\n3 4\n1 2\n3 4\n1 2\n", "4\n2 4\n1 3\n4 4\n1 1\n", "10\n6 6\n1 2\n2 2\n6 7\n8 8\n3 5\n5 5\n4 4\n8 9\n10 10\n", "4\n1 4\n1 4\n2 4\n1 2\n", "8\n3 4\n7 8\n2 6\n1 3\n6 7\n5 8\n4 6\n8 8\n", "7\n7 7\n2 3\n2 3\n5 7\n5 6\n4 ...
2CODEFORCES
1348_F. Phoenix and Memory_934
Phoenix is trying to take a photo of his n friends with labels 1, 2, ..., n who are lined up in a row in a special order. But before he can take the photo, his friends get distracted by a duck and mess up their order. Now, Phoenix must restore the order but he doesn't remember completely! He only remembers that the i-...
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Comparator; import java.util.StringTokenizer; import java.util.TreeSet; public...
4JAVA
{ "input": [ "4\n1 3\n2 4\n3 4\n2 3\n", "4\n4 4\n1 3\n2 4\n3 4\n", "4\n3 4\n1 2\n3 4\n1 2\n", "4\n2 4\n1 3\n4 4\n1 1\n", "10\n6 6\n1 2\n2 2\n6 7\n8 8\n3 5\n5 5\n4 4\n8 9\n10 10\n", "4\n1 4\n1 4\n2 4\n1 2\n", "8\n3 4\n7 8\n2 6\n1 3\n6 7\n5 8\n4 6\n8 8\n", "7\n7 7\n2 3\n2 3\n5 7\n5 6\n4 ...
2CODEFORCES
1369_D. TediousLee_935
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level n ...
from __future__ import division, print_function from itertools import permutations import threading,bisect,math,heapq,sys from collections import deque # threading.stack_size(2**27) # sys.setrecursionlimit(10**4) from sys import stdin, stdout i_m=9223372036854775807 def cin(): return map(int,sin().split()) def...
1Python2
{ "input": [ "7\n1\n2\n3\n4\n5\n100\n2000000\n", "3\n1234567\n1268501\n1268499\n", "3\n60615\n1268501\n1268499\n", "7\n1\n2\n3\n4\n5\n110\n2000000\n", "3\n89610\n1268501\n1268499\n", "7\n2\n2\n5\n4\n5\n110\n2000000\n", "7\n2\n2\n5\n4\n5\n100\n2000000\n", "7\n2\n2\n5\n4\n2\n100\n2000000...
2CODEFORCES
1369_D. TediousLee_936
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level n ...
#include <bits/stdc++.h> const long long mod = 1000000007; using namespace std; vector<long long> child0, child1, claw; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long n; cin >> n; vector<long long> a(n); long long max = 0; for (int i = 0; i < n; i++) { cin >>...
2C++
{ "input": [ "7\n1\n2\n3\n4\n5\n100\n2000000\n", "3\n1234567\n1268501\n1268499\n", "3\n60615\n1268501\n1268499\n", "7\n1\n2\n3\n4\n5\n110\n2000000\n", "3\n89610\n1268501\n1268499\n", "7\n2\n2\n5\n4\n5\n110\n2000000\n", "7\n2\n2\n5\n4\n5\n100\n2000000\n", "7\n2\n2\n5\n4\n2\n100\n2000000...
2CODEFORCES
1369_D. TediousLee_937
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level n ...
import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): retu...
3Python3
{ "input": [ "7\n1\n2\n3\n4\n5\n100\n2000000\n", "3\n1234567\n1268501\n1268499\n", "3\n60615\n1268501\n1268499\n", "7\n1\n2\n3\n4\n5\n110\n2000000\n", "3\n89610\n1268501\n1268499\n", "7\n2\n2\n5\n4\n5\n110\n2000000\n", "7\n2\n2\n5\n4\n5\n100\n2000000\n", "7\n2\n2\n5\n4\n2\n100\n2000000...
2CODEFORCES
1369_D. TediousLee_938
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes... Let's define a Rooted Dead Bush (RDB) of level n ...
import java.util.*; import java.io.*; public class CP{ public static OutputStream out=new BufferedOutputStream(System.out); static Scanner sc=new Scanner(System.in); static long mod=1000000007l; //nl-->neew line; //l-->line; //arp-->array print; //arpnl-->array print new line public static void nl(Object ...
4JAVA
{ "input": [ "7\n1\n2\n3\n4\n5\n100\n2000000\n", "3\n1234567\n1268501\n1268499\n", "3\n60615\n1268501\n1268499\n", "7\n1\n2\n3\n4\n5\n110\n2000000\n", "3\n89610\n1268501\n1268499\n", "7\n2\n2\n5\n4\n5\n110\n2000000\n", "7\n2\n2\n5\n4\n5\n100\n2000000\n", "7\n2\n2\n5\n4\n2\n100\n2000000...
2CODEFORCES
1391_C. Cyclic Permutations _939
A permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a permutation (n=3 but there is 4 in the array). Consider a permutation p of length ...
mod = 1000000007 def xmod(a, b): return ((a % mod) * (b % mod)) % mod def fat(n): x = 1 a = pow(2, n-1, mod) for k in xrange(2,n+1): x = xmod(x, k) return sub(x, a) def sub(a, b): return ((a % mod) - (b % mod)) % mod n = int(raw_input()) print fat(n)
1Python2
{ "input": [ "4\n", "583291\n", "66\n", "652615\n", "482331\n", "336161\n", "33\n", "1000000\n", "79531\n", "768208\n", "3\n", "885131\n", "58\n", "138868\n", "562984\n", "359885\n", "12\n", "53728\n", "252321\n", "714009\n", "38\n", ...
2CODEFORCES
1391_C. Cyclic Permutations _940
A permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a permutation (n=3 but there is 4 in the array). Consider a permutation p of length ...
#include <bits/stdc++.h> using namespace std; const double pi = 3.14159265358979323846; long long binpow(long long, long long); long long mult(long long, long long); long long add(long long, long long); long long division(long long, long long); long long nCr(long long, long long); long long inv(long long); void calc();...
2C++
{ "input": [ "4\n", "583291\n", "66\n", "652615\n", "482331\n", "336161\n", "33\n", "1000000\n", "79531\n", "768208\n", "3\n", "885131\n", "58\n", "138868\n", "562984\n", "359885\n", "12\n", "53728\n", "252321\n", "714009\n", "38\n", ...
2CODEFORCES
1391_C. Cyclic Permutations _941
A permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a permutation (n=3 but there is 4 in the array). Consider a permutation p of length ...
n = int(input()) M = 10**9+7 fact = [1]*(n+2) for i in range(2, n+1): fact[i] = (i*fact[i-1])%M print(((fact[n]-pow(2, n-1, M))+M)%M)
3Python3
{ "input": [ "4\n", "583291\n", "66\n", "652615\n", "482331\n", "336161\n", "33\n", "1000000\n", "79531\n", "768208\n", "3\n", "885131\n", "58\n", "138868\n", "562984\n", "359885\n", "12\n", "53728\n", "252321\n", "714009\n", "38\n", ...
2CODEFORCES
1391_C. Cyclic Permutations _942
A permutation of length n is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation (2 appears twice in the array) and [1,3,4] is also not a permutation (n=3 but there is 4 in the array). Consider a permutation p of length ...
import java.util.*; import java.math.*; public class Sample { static long m = (long)Math.pow(10,9)+7; static long f(long x) { if(x==0) return 1; if(x<3) return x; long a = 2; for(long i=3; i<=x; i++) { a*=i; a%=m; } return a; } static long p(long x) { long a = 1; for(int i=1; i<x; i+...
4JAVA
{ "input": [ "4\n", "583291\n", "66\n", "652615\n", "482331\n", "336161\n", "33\n", "1000000\n", "79531\n", "768208\n", "3\n", "885131\n", "58\n", "138868\n", "562984\n", "359885\n", "12\n", "53728\n", "252321\n", "714009\n", "38\n", ...
2CODEFORCES
1413_F. Roads and Ramen_943
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; int n, m, nex[2000000], hea[2000000], wen[2000000], val[2000000], aid[2000000], root2, root1, len, maxx; struct segment_tree { int a[2000000][2], lazy[2000000], fa[1000000], dep[1000000], in[1000000], out[1000000], m; void pushdown(int k) { if (!lazy[k]) r...
2C++
{ "input": [ "5\n1 2 0\n1 3 0\n3 5 0\n3 4 0\n5\n3\n4\n1\n3\n4\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", "5\n2 4 0\n5 2 0\n1 3 1\n1 2 1\n5\n3\n3\n4\n1\n1\n", "20\n9 11 0\n1 5 0\n1 14 0\n5 17 0\n14 3 0\n16 6 0\n9 2 0\n6 4 0\n11 10 0\n1...
2CODEFORCES
1413_F. Roads and Ramen_944
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...
//package round679; import java.io.*; import java.util.ArrayDeque; import java.util.Arrays; import java.util.InputMismatchException; import java.util.Queue; public class D5 { InputStream is; FastWriter out; String INPUT = ""; void solve() { int n = ni(); int[] from = new int[n - 1]; int[] to = new int[n ...
4JAVA
{ "input": [ "5\n1 2 0\n1 3 0\n3 5 0\n3 4 0\n5\n3\n4\n1\n3\n4\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", "5\n2 4 0\n5 2 0\n1 3 1\n1 2 1\n5\n3\n3\n4\n1\n1\n", "20\n9 11 0\n1 5 0\n1 14 0\n5 17 0\n14 3 0\n16 6 0\n9 2 0\n6 4 0\n11 10 0\n1...
2CODEFORCES
1455_F. String and Operations_945
You are given a string s consisting of n characters. These characters are among the first k lowercase letters of the Latin alphabet. You have to perform n operations with the string. During the i-th operation, you take the character that initially occupied the i-th position, and perform one of the following actions wi...
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "e:/Codes/lib/prettyprint.hpp" #else #define debug(...) #endif int32_t main() { ios::sync_with_stdio(0); cout.tie(0); cin.tie(0); int tc; cin >> tc; while (tc--) { int n, k; string s; cin >> n >> k >> s; vector<string...
2C++
{ "input": [ "6\n4 2\nbbab\n7 5\ncceddda\n6 5\necdaed\n7 4\ndcdbdaa\n8 3\nccabbaca\n5 7\neabba\n", "6\n4 2\nbbab\n7 5\ncceddda\n6 5\necdaed\n7 8\ndcdbdaa\n8 3\nccabbaca\n5 7\neabba\n", "6\n4 2\nbbab\n7 5\ncceddda\n6 9\necdaed\n7 8\ndcdbdaa\n8 3\nccabbaca\n5 7\neabba\n", "6\n4 2\nbaab\n7 5\ncceddda\n6 ...
2CODEFORCES
147_B. Smile House_946
A smile house is created to raise the mood. It has n rooms. Some of the rooms are connected by doors. For each two rooms (number i and j), which are connected by a door, Petya knows their value cij — the value which is being added to his mood when he moves from room i to room j. Petya wondered whether he can raise his...
#include <bits/stdc++.h> using namespace std; int gi() { int w = 0; bool q = 1; char c = getchar(); while ((c < '0' || c > '9') && c != '-') c = getchar(); if (c == '-') q = 0, c = getchar(); while (c >= '0' && c <= '9') w = w * 10 + c - '0', c = getchar(); return q ? w : -w; } const int N = 510; long lon...
2C++
{ "input": [ "4 4\n1 2 -10 3\n1 3 1 -10\n2 4 -10 -1\n3 4 0 -3\n", "5 4\n1 2 1 -1\n2 3 1 -1\n3 1 1 -1\n4 5 2 -1\n", "3 3\n1 2 -10 30\n1 3 1 1\n2 3 -10 -1\n", "6 15\n1 2 -52 -10\n1 3 2 -72\n1 4 -72 -2\n1 5 6 -100\n1 6 -100 -97\n2 3 -63 -37\n2 4 -99 -55\n2 5 -84 -9\n2 6 -17 -8\n3 4 -16 -57\n3 5 -1 8\n3 6...
2CODEFORCES
147_B. Smile House_947
A smile house is created to raise the mood. It has n rooms. Some of the rooms are connected by doors. For each two rooms (number i and j), which are connected by a door, Petya knows their value cij — the value which is being added to his mood when he moves from room i to room j. Petya wondered whether he can raise his...
import java.io.*; import java.util.*; public class B { public B () throws IOException { int n = sc.nextInt(); int m = sc.nextInt(); int [][] D = new int [n][n]; for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) D[i][j] = INF; ...
4JAVA
{ "input": [ "4 4\n1 2 -10 3\n1 3 1 -10\n2 4 -10 -1\n3 4 0 -3\n", "5 4\n1 2 1 -1\n2 3 1 -1\n3 1 1 -1\n4 5 2 -1\n", "3 3\n1 2 -10 30\n1 3 1 1\n2 3 -10 -1\n", "6 15\n1 2 -52 -10\n1 3 2 -72\n1 4 -72 -2\n1 5 6 -100\n1 6 -100 -97\n2 3 -63 -37\n2 4 -99 -55\n2 5 -84 -9\n2 6 -17 -8\n3 4 -16 -57\n3 5 -1 8\n3 6...
2CODEFORCES
1506_F. Triangular Paths_948
Consider an infinite triangle made up of layers. Let's number the layers, starting from one, from the top of the triangle (from top to bottom). The k-th layer of the triangle contains k points, numbered from left to right. Each point of an infinite triangle is described by a pair of numbers (r, c) (1 ≤ c ≤ r), where r ...
# Enter your code here. Read input from STDIN. Print output to STDOUT# =============================================================================================== # importing some useful libraries. from __future__ import division, print_function from fractions import Fraction import sys import os from io import Byt...
1Python2
{ "input": [ "4\n3\n1 4 2\n1 3 1\n2\n2 4\n2 3\n2\n1 1000000000\n1 1000000000\n4\n3 10 5 8\n2 5 2 4\n", "4\n3\n1 4 2\n1 3 1\n2\n2 4\n2 3\n2\n1 1100000000\n1 1000000000\n4\n3 10 5 8\n2 5 2 4\n", "4\n3\n1 6 2\n1 3 1\n2\n2 4\n2 3\n2\n1 1100000000\n1 1000000000\n4\n3 10 5 8\n2 5 2 4\n", "4\n3\n1 4 2\n1 3 1...
2CODEFORCES
1506_F. Triangular Paths_949
Consider an infinite triangle made up of layers. Let's number the layers, starting from one, from the top of the triangle (from top to bottom). The k-th layer of the triangle contains k points, numbered from left to right. Each point of an infinite triangle is described by a pair of numbers (r, c) (1 ≤ c ≤ r), where r ...
# include <bits/stdc++.h> using namespace std; pair<int, int> a[200010]; int calc(int l, int r, int x, int y) { if (x == l && y == r) { return 0; } int t = ((x + y) % 2) ? 0 : 1; if(x - l == y - r){ return t * (x - l); } else { if((l + r) % 2 == 0){ return (x...
2C++
{ "input": [ "4\n3\n1 4 2\n1 3 1\n2\n2 4\n2 3\n2\n1 1000000000\n1 1000000000\n4\n3 10 5 8\n2 5 2 4\n", "4\n3\n1 4 2\n1 3 1\n2\n2 4\n2 3\n2\n1 1100000000\n1 1000000000\n4\n3 10 5 8\n2 5 2 4\n", "4\n3\n1 6 2\n1 3 1\n2\n2 4\n2 3\n2\n1 1100000000\n1 1000000000\n4\n3 10 5 8\n2 5 2 4\n", "4\n3\n1 4 2\n1 3 1...
2CODEFORCES
1506_F. Triangular Paths_950
Consider an infinite triangle made up of layers. Let's number the layers, starting from one, from the top of the triangle (from top to bottom). The k-th layer of the triangle contains k points, numbered from left to right. Each point of an infinite triangle is described by a pair of numbers (r, c) (1 ≤ c ≤ r), where r ...
#!/usr/bin/env python import os import sys from io import BytesIO, IOBase from collections import deque, Counter, defaultdict from heapq import heapify, heappush, heappop def solve(Y, X, N): points = list(zip(Y, X)) points.sort() res = 0 y1 = x1 = 1 for y2, x2 in points: if y1 - x1 == y2 - x2: if (y1 + x1) %...
3Python3
{ "input": [ "4\n3\n1 4 2\n1 3 1\n2\n2 4\n2 3\n2\n1 1000000000\n1 1000000000\n4\n3 10 5 8\n2 5 2 4\n", "4\n3\n1 4 2\n1 3 1\n2\n2 4\n2 3\n2\n1 1100000000\n1 1000000000\n4\n3 10 5 8\n2 5 2 4\n", "4\n3\n1 6 2\n1 3 1\n2\n2 4\n2 3\n2\n1 1100000000\n1 1000000000\n4\n3 10 5 8\n2 5 2 4\n", "4\n3\n1 4 2\n1 3 1...
2CODEFORCES
1506_F. Triangular Paths_951
Consider an infinite triangle made up of layers. Let's number the layers, starting from one, from the top of the triangle (from top to bottom). The k-th layer of the triangle contains k points, numbered from left to right. Each point of an infinite triangle is described by a pair of numbers (r, c) (1 ≤ c ≤ r), where r ...
//stan hu tao //join nct ridin by first year culture reps import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import static java.lang.System.out; import java.util.*; import java.io.*; import java.math.*; public class x1506F { public static void main(String hi[]) th...
4JAVA
{ "input": [ "4\n3\n1 4 2\n1 3 1\n2\n2 4\n2 3\n2\n1 1000000000\n1 1000000000\n4\n3 10 5 8\n2 5 2 4\n", "4\n3\n1 4 2\n1 3 1\n2\n2 4\n2 3\n2\n1 1100000000\n1 1000000000\n4\n3 10 5 8\n2 5 2 4\n", "4\n3\n1 6 2\n1 3 1\n2\n2 4\n2 3\n2\n1 1100000000\n1 1000000000\n4\n3 10 5 8\n2 5 2 4\n", "4\n3\n1 4 2\n1 3 1...
2CODEFORCES
152_E. Garden_952
Vasya has a very beautiful country garden that can be represented as an n × m rectangular field divided into n·m squares. One beautiful day Vasya remembered that he needs to pave roads between k important squares that contain buildings. To pave a road, he can cover some squares of his garden with concrete. For each ga...
#include <bits/stdc++.h> using namespace std; const double eps = 1e-8; const long long MOD = 1000000007; const long long INF = 0x3f3f3f3f; int val[111][111]; int n, m, k; vector<pair<int, int> > pos; int ddist[111][111], way[10][10], dist[211][10]; int used[111][111]; pair<int, int> pre[211][1 << 8]; int dp[211][1 << 8...
2C++
{ "input": [ "3 3 2\n1 2 3\n1 2 3\n1 2 3\n1 2\n3 3\n", "4 5 4\n1 4 5 1 2\n2 2 2 2 7\n2 4 1 4 5\n3 2 1 7 1\n1 1\n1 5\n4 1\n4 4\n", "100 1 7\n83\n174\n191\n145\n167\n55\n232\n157\n51\n209\n85\n73\n216\n39\n72\n76\n132\n70\n22\n215\n137\n35\n62\n22\n155\n183\n113\n125\n88\n21\n65\n133\n31\n24\n187\n126\n131\...
2CODEFORCES
152_E. Garden_953
Vasya has a very beautiful country garden that can be represented as an n × m rectangular field divided into n·m squares. One beautiful day Vasya remembered that he needs to pave roads between k important squares that contain buildings. To pave a road, he can cover some squares of his garden with concrete. For each ga...
import static java.lang.Math.*; import static java.math.BigInteger.*; import static java.util.Arrays.*; import static java.util.Collections.*; import java.math.*; import java.util.*; import java.io.*; public class E { public static void main(String[] args) { new E().run(); } Scanner in = new Scanner(System.in); ...
4JAVA
{ "input": [ "3 3 2\n1 2 3\n1 2 3\n1 2 3\n1 2\n3 3\n", "4 5 4\n1 4 5 1 2\n2 2 2 2 7\n2 4 1 4 5\n3 2 1 7 1\n1 1\n1 5\n4 1\n4 4\n", "100 1 7\n83\n174\n191\n145\n167\n55\n232\n157\n51\n209\n85\n73\n216\n39\n72\n76\n132\n70\n22\n215\n137\n35\n62\n22\n155\n183\n113\n125\n88\n21\n65\n133\n31\n24\n187\n126\n131\...
2CODEFORCES
161_B. Discounts_954
One day Polycarpus stopped by a supermarket on his way home. It turns out that the supermarket is having a special offer for stools. The offer is as follows: if a customer's shopping cart contains at least one stool, the customer gets a 50% discount on the cheapest item in the cart (that is, it becomes two times cheape...
from math import * n,k = map(int,raw_input().split()) it1,it2 = [],[] for i in range(0,n): p,t = map(int,raw_input().split()) if t==1: it1 += [[p,i+1]] else: it2 += [[p,i+1]] it1.sort(); it1.reverse() it2.sort(); it2.reverse() tot = 0 for i in range(0,min(k-1,len(it1))): tot += it1[i][0] m = 10**9 for ...
1Python2
{ "input": [ "3 2\n2 1\n3 2\n3 1\n", "4 3\n4 1\n1 2\n2 2\n3 2\n", "11 11\n6 2\n6 2\n1 2\n2 2\n3 1\n6 2\n1 1\n1 1\n3 1\n3 1\n6 2\n", "21 7\n14 1\n882797755 2\n17 1\n906492329 2\n209923513 2\n802927469 2\n949195463 2\n677323647 2\n2129083 2\n2 1\n13 1\n539523264 2\n7 1\n8 1\n12 1\n363470241 2\n9838294 2...
2CODEFORCES
161_B. Discounts_955
One day Polycarpus stopped by a supermarket on his way home. It turns out that the supermarket is having a special offer for stools. The offer is as follows: if a customer's shopping cart contains at least one stool, the customer gets a 50% discount on the cheapest item in the cart (that is, it becomes two times cheape...
#include <bits/stdc++.h> using namespace std; int ans[1010][1010]; int al[1010]; struct node { int id; int v; } den[1010], qian[1010]; int dl = 0; int ql = 0; bool cmp(node a, node b) { return a.v > b.v; } int main() { int n; scanf("%d", &n); ; int m; scanf("%d", &m); ; double cost = 0; for (int i =...
2C++
{ "input": [ "3 2\n2 1\n3 2\n3 1\n", "4 3\n4 1\n1 2\n2 2\n3 2\n", "11 11\n6 2\n6 2\n1 2\n2 2\n3 1\n6 2\n1 1\n1 1\n3 1\n3 1\n6 2\n", "21 7\n14 1\n882797755 2\n17 1\n906492329 2\n209923513 2\n802927469 2\n949195463 2\n677323647 2\n2129083 2\n2 1\n13 1\n539523264 2\n7 1\n8 1\n12 1\n363470241 2\n9838294 2...
2CODEFORCES
161_B. Discounts_956
One day Polycarpus stopped by a supermarket on his way home. It turns out that the supermarket is having a special offer for stools. The offer is as follows: if a customer's shopping cart contains at least one stool, the customer gets a 50% discount on the cheapest item in the cart (that is, it becomes two times cheape...
n, k = list(map(int, input().split())) p = [[], []] for i in range(1, n + 1): c, t = map(int, input().split()) p[t > 1].append((c, i)) if k > len(p[0]): l = k - len(p[0]) - 1 print(sum(c for c, i in p[0]) / 2 + sum(c for c, i in p[1])) print('\n'.join('1 ' + str(i) for c, i in p[0])) pr...
3Python3
{ "input": [ "3 2\n2 1\n3 2\n3 1\n", "4 3\n4 1\n1 2\n2 2\n3 2\n", "11 11\n6 2\n6 2\n1 2\n2 2\n3 1\n6 2\n1 1\n1 1\n3 1\n3 1\n6 2\n", "21 7\n14 1\n882797755 2\n17 1\n906492329 2\n209923513 2\n802927469 2\n949195463 2\n677323647 2\n2129083 2\n2 1\n13 1\n539523264 2\n7 1\n8 1\n12 1\n363470241 2\n9838294 2...
2CODEFORCES
161_B. Discounts_957
One day Polycarpus stopped by a supermarket on his way home. It turns out that the supermarket is having a special offer for stools. The offer is as follows: if a customer's shopping cart contains at least one stool, the customer gets a 50% discount on the cheapest item in the cart (that is, it becomes two times cheape...
import static java.lang.Math.*; import static java.util.Arrays.*; import java.io.*; import java.util.*; public class B { Scanner sc = new Scanner(System.in); void run() { int n = sc.nextInt(), k = sc.nextInt(); int[] cs = new int[n], ts = new int[n]; for (int i = 0; i < n; i++) { cs[i] = sc.nextInt() * 2...
4JAVA
{ "input": [ "3 2\n2 1\n3 2\n3 1\n", "4 3\n4 1\n1 2\n2 2\n3 2\n", "11 11\n6 2\n6 2\n1 2\n2 2\n3 1\n6 2\n1 1\n1 1\n3 1\n3 1\n6 2\n", "21 7\n14 1\n882797755 2\n17 1\n906492329 2\n209923513 2\n802927469 2\n949195463 2\n677323647 2\n2129083 2\n2 1\n13 1\n539523264 2\n7 1\n8 1\n12 1\n363470241 2\n9838294 2...
2CODEFORCES
180_D. Name_958
Everything got unclear to us in a far away constellation Tau Ceti. Specifically, the Taucetians choose names to their children in a very peculiar manner. Two young parents abac and bbad think what name to give to their first-born child. They decided that the name will be the permutation of letters of string s. To keep...
a = raw_input() b = raw_input() c = {} for i in xrange(26): c[chr(i + 97)] = 0 for i in xrange(len(a)): c[a[i]] += 1 pref = '' ans = chr(255) for i in xrange(min(len(a), len(b))): j = chr(ord(b[i]) + 1) while j <= 'z' and c[j] == 0: j = chr(ord(j) + 1) if j <= 'z': suff = j c[j] -= 1 for ch, num in sorted(...
1Python2
{ "input": [ "abc\ndefg\n", "czaaab\nabcdef\n", "aad\naac\n", "abad\nbob\n", "z\na\n", "abc\naaac\n", "bcbcdddbbd\nbcbcdbdbbd\n", "aaabccadac\nacabbbabaa\n", "a\nb\n", "acaccaaadz\ncaadccaaaa\n", "aa\nab\n", "abacaba\naba\n", "aabbaa\naaaaaaaaaaaaaaaaaaaa\n", "a...
2CODEFORCES
180_D. Name_959
Everything got unclear to us in a far away constellation Tau Ceti. Specifically, the Taucetians choose names to their children in a very peculiar manner. Two young parents abac and bbad think what name to give to their first-born child. They decided that the name will be the permutation of letters of string s. To keep...
#include <bits/stdc++.h> using namespace std; const int Maxn = 5005; const int Maxl = 26; char a[Maxn], b[Maxn]; int alen, blen; int freq[Maxl]; bool Possible(int pos) { int cur = Maxl - 1, tk = 0; for (int i = pos; i < blen; i++) { while (cur >= 0 && tk == freq[cur]) { cur--; tk = 0; } if (...
2C++
{ "input": [ "abc\ndefg\n", "czaaab\nabcdef\n", "aad\naac\n", "abad\nbob\n", "z\na\n", "abc\naaac\n", "bcbcdddbbd\nbcbcdbdbbd\n", "aaabccadac\nacabbbabaa\n", "a\nb\n", "acaccaaadz\ncaadccaaaa\n", "aa\nab\n", "abacaba\naba\n", "aabbaa\naaaaaaaaaaaaaaaaaaaa\n", "a...
2CODEFORCES
180_D. Name_960
Everything got unclear to us in a far away constellation Tau Ceti. Specifically, the Taucetians choose names to their children in a very peculiar manner. Two young parents abac and bbad think what name to give to their first-born child. They decided that the name will be the permutation of letters of string s. To keep...
def findmin(lcopy, toexceed): toex = ord(toexceed) - 97 for each in lcopy[(toex+1):]: if each > 0: return True return False def arrange(lcopy, toexceed = None): if toexceed is None: ans = "" for i in range(26): ans += chr(i+97)*lcopy[i] return ans...
3Python3
{ "input": [ "abc\ndefg\n", "czaaab\nabcdef\n", "aad\naac\n", "abad\nbob\n", "z\na\n", "abc\naaac\n", "bcbcdddbbd\nbcbcdbdbbd\n", "aaabccadac\nacabbbabaa\n", "a\nb\n", "acaccaaadz\ncaadccaaaa\n", "aa\nab\n", "abacaba\naba\n", "aabbaa\naaaaaaaaaaaaaaaaaaaa\n", "a...
2CODEFORCES
180_D. Name_961
Everything got unclear to us in a far away constellation Tau Ceti. Specifically, the Taucetians choose names to their children in a very peculiar manner. Two young parents abac and bbad think what name to give to their first-born child. They decided that the name will be the permutation of letters of string s. To keep...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class D { final int MOD = 1000000007; final double eps = 1e-12; public D () throws IOException { char [] S = sc.nextChars(); char [] T = sc.nextChars(); start(); int [] C = ne...
4JAVA
{ "input": [ "abc\ndefg\n", "czaaab\nabcdef\n", "aad\naac\n", "abad\nbob\n", "z\na\n", "abc\naaac\n", "bcbcdddbbd\nbcbcdbdbbd\n", "aaabccadac\nacabbbabaa\n", "a\nb\n", "acaccaaadz\ncaadccaaaa\n", "aa\nab\n", "abacaba\naba\n", "aabbaa\naaaaaaaaaaaaaaaaaaaa\n", "a...
2CODEFORCES
203_E. Transportation_962
Valera came to Japan and bought many robots for his research. He's already at the airport, the plane will fly very soon and Valera urgently needs to bring all robots to the luggage compartment. The robots are self-propelled (they can potentially move on their own), some of them even have compartments to carry other ro...
n,d,S=map(int,raw_input().split()) c0=[] c1=[] c2=1 for i in range(n): c,f,l=map(int,raw_input().split()) c2+=c if c>0: c1.append([f,l]) else: c0.append([f,l]) c2=n if c2>n else c2 def solc0(N,T): res=0;ct=0 c0.sort() for a in c0: if ct<N and a[1]>=d and res+a[0]<=...
1Python2
{ "input": [ "2 7 10\n3 12 10\n5 16 8\n", "4 8 10\n0 12 3\n1 1 0\n0 3 11\n1 6 9\n", "3 10 10\n0 12 10\n1 6 10\n0 1 1\n", "6 4 3\n0 1 2\n1 3 0\n0 4 5\n1 4 4\n1 2 2\n0 4 2\n", "50 69 6\n62 91 5\n35 35 53\n85 26 1\n86 37 99\n2 87 57\n39 56 22\n72 75 78\n10 91 81\n2 13 35\n46 27 57\n82 99 75\n51 6 45\...
2CODEFORCES
203_E. Transportation_963
Valera came to Japan and bought many robots for his research. He's already at the airport, the plane will fly very soon and Valera urgently needs to bring all robots to the luggage compartment. The robots are self-propelled (they can potentially move on their own), some of them even have compartments to carry other ro...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:200000000") const double EPS = 1E-9; const int INF = 1000000000; const long long INF64 = (long long)1E18; const double PI = 3.1415926535897932384626433832795; struct robot { int c, f, l; }; int d; inline bool operator<(const robot &a, const...
2C++
{ "input": [ "2 7 10\n3 12 10\n5 16 8\n", "4 8 10\n0 12 3\n1 1 0\n0 3 11\n1 6 9\n", "3 10 10\n0 12 10\n1 6 10\n0 1 1\n", "6 4 3\n0 1 2\n1 3 0\n0 4 5\n1 4 4\n1 2 2\n0 4 2\n", "50 69 6\n62 91 5\n35 35 53\n85 26 1\n86 37 99\n2 87 57\n39 56 22\n72 75 78\n10 91 81\n2 13 35\n46 27 57\n82 99 75\n51 6 45\...
2CODEFORCES
203_E. Transportation_964
Valera came to Japan and bought many robots for his research. He's already at the airport, the plane will fly very soon and Valera urgently needs to bring all robots to the luggage compartment. The robots are self-propelled (they can potentially move on their own), some of them even have compartments to carry other ro...
//package round128; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Comparator; public class E3 { InputStream is; PrintWriter out; String INPUT = ""; void solve() { int n = ni(), d = ni(); long...
4JAVA
{ "input": [ "2 7 10\n3 12 10\n5 16 8\n", "4 8 10\n0 12 3\n1 1 0\n0 3 11\n1 6 9\n", "3 10 10\n0 12 10\n1 6 10\n0 1 1\n", "6 4 3\n0 1 2\n1 3 0\n0 4 5\n1 4 4\n1 2 2\n0 4 2\n", "50 69 6\n62 91 5\n35 35 53\n85 26 1\n86 37 99\n2 87 57\n39 56 22\n72 75 78\n10 91 81\n2 13 35\n46 27 57\n82 99 75\n51 6 45\...
2CODEFORCES
228_D. Zigzag_965
The court wizard Zigzag wants to become a famous mathematician. For that, he needs his own theorem, like the Cauchy theorem, or his sum, like the Minkowski sum. But most of all he wants to have his sequence, like the Fibonacci sequence, and his function, like the Euler's totient function. The Zigag's sequence with the...
#include <bits/stdc++.h> using namespace std; void swap(int &x, int &y) { int t = x; x = y; y = t; } int max(int x, int y) { return x > y ? x : y; } int min(int x, int y) { return x < y ? x : y; } const int inf = 0x3F3F3F3F; const int M = 100000 + 5; int T, cas; int n, m; long long a, sum[M << 2][5][11], s[5][M];...
2C++
{ "input": [ "5\n2 3 1 5 5\n4\n2 2 3 2\n2 1 5 3\n1 3 5\n2 1 5 3\n", "5\n42665793 142698407 856080769 176604645 248258165\n10\n1 5 141156007\n2 5 5 3\n2 4 4 2\n2 2 5 3\n1 2 942795810\n2 5 5 3\n1 3 195194439\n1 2 698674322\n1 2 602158126\n2 2 4 2\n", "5\n259349921 585246931 574682827 407653643 902894459\n10...
2CODEFORCES
228_D. Zigzag_966
The court wizard Zigzag wants to become a famous mathematician. For that, he needs his own theorem, like the Cauchy theorem, or his sum, like the Minkowski sum. But most of all he wants to have his sequence, like the Fibonacci sequence, and his function, like the Euler's totient function. The Zigag's sequence with the...
import java.io.*; import java.util.*; public class ProblemD { InputReader in; PrintWriter out; class FenwickTree { List<Long> tree; int n; FenwickTree(int len) { tree = new ArrayList<Long>(len); for (int i = 0; i < len; i++) tree.add(0L); ...
4JAVA
{ "input": [ "5\n2 3 1 5 5\n4\n2 2 3 2\n2 1 5 3\n1 3 5\n2 1 5 3\n", "5\n42665793 142698407 856080769 176604645 248258165\n10\n1 5 141156007\n2 5 5 3\n2 4 4 2\n2 2 5 3\n1 2 942795810\n2 5 5 3\n1 3 195194439\n1 2 698674322\n1 2 602158126\n2 2 4 2\n", "5\n259349921 585246931 574682827 407653643 902894459\n10...
2CODEFORCES
252_B. Unsorting Array_967
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct po...
n = input() array = [int(x) for x in raw_input().split()] if n < 3: print -1 exit() s = set(array) if len(s) == 1: print -1 elif len(s) == 2: if len(array) <= 2: print -1 elif len(array) == 3: if array[0] == array[1]: print 2, 3 elif array[1] == array[2]: ...
1Python2
{ "input": [ "3\n1 1 1\n", "1\n1\n", "2\n1 2\n", "4\n1 2 3 4\n", "3\n3 2 3\n", "3\n1 3 1\n", "5\n1 1 2 1 1\n", "5\n1 1 1 1 2\n", "4\n562617869 562617869 562617869 562617869\n", "6\n1 2 3 3 2 1\n", "4\n562617869 961148050 961148050 961148050\n", "4\n961148050 951133776 5...
2CODEFORCES
252_B. Unsorting Array_968
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct po...
#include <bits/stdc++.h> using namespace std; long long int modpow(long long int a, long long int n, long long int temp) { long long int res = 1, y = a; while (n > 0) { if (n & 1) res = (res * y) % temp; y = (y * y) % temp; n /= 2; } return res % temp; } vector<int> arr; int track[1000006], cnt[3]; ...
2C++
{ "input": [ "3\n1 1 1\n", "1\n1\n", "2\n1 2\n", "4\n1 2 3 4\n", "3\n3 2 3\n", "3\n1 3 1\n", "5\n1 1 2 1 1\n", "5\n1 1 1 1 2\n", "4\n562617869 562617869 562617869 562617869\n", "6\n1 2 3 3 2 1\n", "4\n562617869 961148050 961148050 961148050\n", "4\n961148050 951133776 5...
2CODEFORCES
252_B. Unsorting Array_969
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct po...
n=int(input()) a=[int(i) for i in input().split()] b=len(set(a)) c=sorted(a,reverse=True) if n==1 or n==2 or b==1: print("-1") elif n==3: if b==2: if a[0]==a[2]: print("-1") elif a[0]==a[1]: print("2 3") else: print("1 2") elif a[1]!=max(a[0],a[1],...
3Python3
{ "input": [ "3\n1 1 1\n", "1\n1\n", "2\n1 2\n", "4\n1 2 3 4\n", "3\n3 2 3\n", "3\n1 3 1\n", "5\n1 1 2 1 1\n", "5\n1 1 1 1 2\n", "4\n562617869 562617869 562617869 562617869\n", "6\n1 2 3 3 2 1\n", "4\n562617869 961148050 961148050 961148050\n", "4\n961148050 951133776 5...
2CODEFORCES
252_B. Unsorting Array_970
Little Petya likes arrays of integers a lot. Recently his mother has presented him one such array consisting of n elements. Petya is now wondering whether he can swap any two distinct integers in the array so that the array got unsorted. Please note that Petya can not swap equal integers even if they are in distinct po...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual soluti...
4JAVA
{ "input": [ "3\n1 1 1\n", "1\n1\n", "2\n1 2\n", "4\n1 2 3 4\n", "3\n3 2 3\n", "3\n1 3 1\n", "5\n1 1 2 1 1\n", "5\n1 1 1 1 2\n", "4\n562617869 562617869 562617869 562617869\n", "6\n1 2 3 3 2 1\n", "4\n562617869 961148050 961148050 961148050\n", "4\n961148050 951133776 5...
2CODEFORCES
277_C. Game_971
Two players play the following game. Initially, the players have a knife and a rectangular sheet of paper, divided into equal square grid cells of unit size. The players make moves in turn, the player who can't make a move loses. In one move, a player can take the knife and cut the paper along any segment of the grid l...
from sys import stdin from collections import defaultdict def emp(l, a): cnt = pos = x = 0 for y in a: if y[1]: cnt -= 1 else: if not cnt: x += y[0] - pos cnt += 1 pos = y[0] x += l - pos return x def check(x, b): return x ^...
1Python2
{ "input": [ "2 1 0\n", "2 2 4\n0 1 2 1\n0 1 2 1\n1 2 1 0\n1 1 1 2\n", "2 2 1\n0 1 1 1\n", "5 5 20\n3 1 3 3\n1 2 2 2\n4 3 4 2\n3 2 2 2\n3 4 2 4\n4 1 4 5\n4 3 5 3\n5 1 0 1\n0 1 5 1\n3 5 3 1\n3 1 3 2\n1 5 1 0\n3 4 3 3\n3 3 3 4\n1 3 3 3\n2 5 2 1\n0 2 1 2\n2 1 0 1\n4 3 5 3\n1 4 1 5\n", "5 5 46\n3 5 3 ...
2CODEFORCES
277_C. Game_972
Two players play the following game. Initially, the players have a knife and a rectangular sheet of paper, divided into equal square grid cells of unit size. The players make moves in turn, the player who can't make a move loses. In one move, a player can take the knife and cut the paper along any segment of the grid l...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:32000000") using namespace std; const int MAX = 200000; const int INF = 100000000; const int MOD = 1000000007; const double EPS = 1E-7; const int IT = 10024; map<int, vector<pair<int, int> > > r; map<int, vector<pair<int, int> > > c; map<int, int> R; map<int, int...
2C++
{ "input": [ "2 1 0\n", "2 2 4\n0 1 2 1\n0 1 2 1\n1 2 1 0\n1 1 1 2\n", "2 2 1\n0 1 1 1\n", "5 5 20\n3 1 3 3\n1 2 2 2\n4 3 4 2\n3 2 2 2\n3 4 2 4\n4 1 4 5\n4 3 5 3\n5 1 0 1\n0 1 5 1\n3 5 3 1\n3 1 3 2\n1 5 1 0\n3 4 3 3\n3 3 3 4\n1 3 3 3\n2 5 2 1\n0 2 1 2\n2 1 0 1\n4 3 5 3\n1 4 1 5\n", "5 5 46\n3 5 3 ...
2CODEFORCES
277_C. Game_973
Two players play the following game. Initially, the players have a knife and a rectangular sheet of paper, divided into equal square grid cells of unit size. The players make moves in turn, the player who can't make a move loses. In one move, a player can take the knife and cut the paper along any segment of the grid l...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.Comparator; import java.util.StringTokenizer; public class E { BufferedReader reader; StringTokenizer tokenizer; PrintWriter out; public...
4JAVA
{ "input": [ "2 1 0\n", "2 2 4\n0 1 2 1\n0 1 2 1\n1 2 1 0\n1 1 1 2\n", "2 2 1\n0 1 1 1\n", "5 5 20\n3 1 3 3\n1 2 2 2\n4 3 4 2\n3 2 2 2\n3 4 2 4\n4 1 4 5\n4 3 5 3\n5 1 0 1\n0 1 5 1\n3 5 3 1\n3 1 3 2\n1 5 1 0\n3 4 3 3\n3 3 3 4\n1 3 3 3\n2 5 2 1\n0 2 1 2\n2 1 0 1\n4 3 5 3\n1 4 1 5\n", "5 5 46\n3 5 3 ...
2CODEFORCES
29_E. Quarrel_974
Friends Alex and Bob live in Bertown. In this town there are n crossroads, some of them are connected by bidirectional roads of equal length. Bob lives in a house at the crossroads number 1, Alex — in a house at the crossroads number n. One day Alex and Bob had a big quarrel, and they refused to see each other. It occ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 500 + 17, inf = 1e9 + 17; int n, m, dp[MAXN][MAXN]; pair<int, int> par[MAXN][MAXN]; vector<int> adj[MAXN], ans1, ans2; void bfs() { for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) dp[i][j] = inf; dp[1][n] = 0; queue<pair<int, int> > q; ...
2C++
{ "input": [ "7 5\n1 2\n2 7\n7 6\n2 3\n3 4\n", "2 1\n1 2\n", "7 6\n1 2\n2 7\n7 6\n2 3\n3 4\n1 5\n", "10 16\n9 8\n1 2\n9 5\n5 4\n9 2\n3 2\n1 6\n5 10\n7 2\n8 2\n3 7\n4 9\n5 7\n10 3\n10 9\n7 8\n", "5 7\n5 2\n1 3\n4 2\n3 4\n5 3\n2 3\n4 1\n", "6 10\n3 6\n3 5\n1 3\n2 6\n5 4\n6 4\n6 5\n5 1\n2 3\n1 2\...
2CODEFORCES
29_E. Quarrel_975
Friends Alex and Bob live in Bertown. In this town there are n crossroads, some of them are connected by bidirectional roads of equal length. Bob lives in a house at the crossroads number 1, Alex — in a house at the crossroads number n. One day Alex and Bob had a big quarrel, and they refused to see each other. It occ...
import static java.util.Arrays.deepToString; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class Main { void solve() { int n = sc.nextInt(); in...
4JAVA
{ "input": [ "7 5\n1 2\n2 7\n7 6\n2 3\n3 4\n", "2 1\n1 2\n", "7 6\n1 2\n2 7\n7 6\n2 3\n3 4\n1 5\n", "10 16\n9 8\n1 2\n9 5\n5 4\n9 2\n3 2\n1 6\n5 10\n7 2\n8 2\n3 7\n4 9\n5 7\n10 3\n10 9\n7 8\n", "5 7\n5 2\n1 3\n4 2\n3 4\n5 3\n2 3\n4 1\n", "6 10\n3 6\n3 5\n1 3\n2 6\n5 4\n6 4\n6 5\n5 1\n2 3\n1 2\...
2CODEFORCES
323_C. Two permutations_976
You are given two permutations p and q, consisting of n elements, and m queries of the form: l1, r1, l2, r2 (l1 ≤ r1; l2 ≤ r2). The response for the query is the number of such integers from 1 to n, that their position in the first permutation is in segment [l1, r1] (borders included), and position in the second permut...
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; struct tnode { int sum; tnode *lson, *rson; tnode(int x = 0) { sum = x; lson = rson = NULL; } }; void pushup(tnode* cur) { cur->sum = (cur->lson == NULL ? 0 : cur->lson->sum) + (cur->rson == NULL ? 0 : cur->rson->sum...
2C++
{ "input": [ "4\n4 3 2 1\n2 3 4 1\n3\n1 2 3 4\n1 3 2 1\n1 4 2 3\n", "3\n3 1 2\n3 2 1\n1\n1 2 3 3\n", "1\n1\n1\n1\n1 1 1 1\n", "4\n4 3 2 1\n2 3 4 1\n3\n1 2 3 4\n1 3 2 1\n2 4 2 3\n", "4\n4 3 2 1\n2 3 4 1\n3\n1 2 3 4\n1 3 3 1\n2 4 2 3\n", "3\n3 1 2\n3 2 1\n1\n2 2 3 3\n", "4\n4 3 2 1\n2 3 4 1\...
2CODEFORCES
323_C. Two permutations_977
You are given two permutations p and q, consisting of n elements, and m queries of the form: l1, r1, l2, r2 (l1 ≤ r1; l2 ≤ r2). The response for the query is the number of such integers from 1 to n, that their position in the first permutation is in segment [l1, r1] (borders included), and position in the second permut...
import static java.util.Arrays.fill; import java.io.*; import java.util.*; public class C { static void solve() throws IOException { int n = nextInt(); int[] p = new int[n]; int[] inQ = new int[n]; for (int i = 0; i < n; i++) { p[i] = nextInt() - 1; } for (int i = 0; i < n; i++) { inQ[nextInt() - ...
4JAVA
{ "input": [ "4\n4 3 2 1\n2 3 4 1\n3\n1 2 3 4\n1 3 2 1\n1 4 2 3\n", "3\n3 1 2\n3 2 1\n1\n1 2 3 3\n", "1\n1\n1\n1\n1 1 1 1\n", "4\n4 3 2 1\n2 3 4 1\n3\n1 2 3 4\n1 3 2 1\n2 4 2 3\n", "4\n4 3 2 1\n2 3 4 1\n3\n1 2 3 4\n1 3 3 1\n2 4 2 3\n", "3\n3 1 2\n3 2 1\n1\n2 2 3 3\n", "4\n4 3 2 1\n2 3 4 1\...
2CODEFORCES
348_A. Mafia_978
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number ...
n = int(raw_input()) L=map(int,raw_input().split(' ')) mx = max(L) n-=1 sm=sum(L)-1 res = sm/n+1 print max(mx,res)
1Python2
{ "input": [ "3\n3 2 2\n", "4\n2 2 2 2\n", "3\n1000000000 1000000000 10000000\n", "3\n1 2 1\n", "3\n4 10 11\n", "5\n1000000000 5 5 4 4\n", "5\n1000000000 1000000000 1000000000 1000000000 1000000000\n", "10\n94 96 91 95 99 94 96 92 95 99\n", "7\n9 7 7 8 8 7 8\n", "3\n1 1 1\n", ...
2CODEFORCES
348_A. Mafia_979
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number ...
#include <bits/stdc++.h> using namespace std; class sort_map { public: int num; int val; }; bool myfunc(int a, int b) { return a > b; } int main() { long long n; cin >> n; vector<long long> input; long long mmax = 0, sum = 0; for (int i = 0; i < n; i++) { long long temp; cin >> temp; input.pu...
2C++
{ "input": [ "3\n3 2 2\n", "4\n2 2 2 2\n", "3\n1000000000 1000000000 10000000\n", "3\n1 2 1\n", "3\n4 10 11\n", "5\n1000000000 5 5 4 4\n", "5\n1000000000 1000000000 1000000000 1000000000 1000000000\n", "10\n94 96 91 95 99 94 96 92 95 99\n", "7\n9 7 7 8 8 7 8\n", "3\n1 1 1\n", ...
2CODEFORCES
348_A. Mafia_980
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number ...
# mafia N=int(input()) a=list(map(int,input().split())) def isok(X): sums=0 for num in a: if X<num: return False sums+=max(0,X-num) if sums>=X: return True return False l=0 r=10**12 #l -- case_impossible #r --case_possible while r-l>1: m=(l+r)//2 ...
3Python3
{ "input": [ "3\n3 2 2\n", "4\n2 2 2 2\n", "3\n1000000000 1000000000 10000000\n", "3\n1 2 1\n", "3\n4 10 11\n", "5\n1000000000 5 5 4 4\n", "5\n1000000000 1000000000 1000000000 1000000000 1000000000\n", "10\n94 96 91 95 99 94 96 92 95 99\n", "7\n9 7 7 8 8 7 8\n", "3\n1 1 1\n", ...
2CODEFORCES
348_A. Mafia_981
One day n friends gathered together to play "Mafia". During each round of the game some player must be the supervisor and other n - 1 people take part in the game. For each person we know in how many rounds he wants to be a player, not the supervisor: the i-th person wants to play ai rounds. What is the minimum number ...
import java.util.*; public class Study{ public static boolean ispossible(long mid,long arr[]) { long supervisor=0; for(int i=0;i<arr.length;i++) { if(mid-arr[i]<0) return false; supervisor+=mid-arr[i];} if(supervisor>=mid) return true; return false; } public static long bsearch(long arr[],lon...
4JAVA
{ "input": [ "3\n3 2 2\n", "4\n2 2 2 2\n", "3\n1000000000 1000000000 10000000\n", "3\n1 2 1\n", "3\n4 10 11\n", "5\n1000000000 5 5 4 4\n", "5\n1000000000 1000000000 1000000000 1000000000 1000000000\n", "10\n94 96 91 95 99 94 96 92 95 99\n", "7\n9 7 7 8 8 7 8\n", "3\n1 1 1\n", ...
2CODEFORCES
371_B. Fox Dividing Cheese_982
Two little greedy bears have found two pieces of cheese in the forest of weight a and b grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it fox...
import sys data = raw_input().split() a = int(data[0]) b = int(data[1]) def gcd(a, b): if b==0: return a else: return gcd(b, a%b) ans=0 aa=a/gcd(a, b) bb=b/gcd(a, b) def deal(x): global ans while x%2==0: x=x/2 ans+=1 while x%3==0: x=x/3 ans+=1 while x%5==0: x=x/5 ans+=1 return x!=1 if deal...
1Python2
{ "input": [ "15 20\n", "14 8\n", "6 6\n", "919536000 993098880\n", "691200 583200\n", "5 1000000000\n", "100 10\n", "537814642 537814642\n", "21 35\n", "800000 729000\n", "881280 765000\n", "864000000 607500000\n", "648293430 540244525\n", "445906944 528482304\...
2CODEFORCES
371_B. Fox Dividing Cheese_983
Two little greedy bears have found two pieces of cheese in the forest of weight a and b grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it fox...
#include <bits/stdc++.h> using namespace std; bool isPrime(long long int n) { if (n <= 1) return 0; if (n <= 3) return 1; if (n % 2 == 0 || n % 3 == 0) return 0; for (long long int i = 5; i * i <= n; i += 6) if (n % i == 0 || n % (i + 2) == 0) return 0; return 1; } long long int gcd(long long int a, long ...
2C++
{ "input": [ "15 20\n", "14 8\n", "6 6\n", "919536000 993098880\n", "691200 583200\n", "5 1000000000\n", "100 10\n", "537814642 537814642\n", "21 35\n", "800000 729000\n", "881280 765000\n", "864000000 607500000\n", "648293430 540244525\n", "445906944 528482304\...
2CODEFORCES
371_B. Fox Dividing Cheese_984
Two little greedy bears have found two pieces of cheese in the forest of weight a and b grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it fox...
from math import pow def take_input(s): #for integer inputs if s == 1: return int(input()) return map(int, input().split()) def factor(n,k): i = 0 while(n%k==0): i += 1 n //= k return i a, b = take_input(2) count = 0 if a == b: print(0) exit() a_fac_2 = f...
3Python3
{ "input": [ "15 20\n", "14 8\n", "6 6\n", "919536000 993098880\n", "691200 583200\n", "5 1000000000\n", "100 10\n", "537814642 537814642\n", "21 35\n", "800000 729000\n", "881280 765000\n", "864000000 607500000\n", "648293430 540244525\n", "445906944 528482304\...
2CODEFORCES
371_B. Fox Dividing Cheese_985
Two little greedy bears have found two pieces of cheese in the forest of weight a and b grams, correspondingly. The bears are so greedy that they are ready to fight for the larger piece. That's where the fox comes in and starts the dialog: "Little bears, wait a little, I want to make your pieces equal" "Come off it fox...
import java.util.Arrays; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; public class FoxDividingChees { static int n,m,res; static void check(int p){ int u = 0;int v = 0; while(n%p==0){u++;n/=p;} while(m%p==0){v++;m/=p;} res+= Math.abs(u-v); }...
4JAVA
{ "input": [ "15 20\n", "14 8\n", "6 6\n", "919536000 993098880\n", "691200 583200\n", "5 1000000000\n", "100 10\n", "537814642 537814642\n", "21 35\n", "800000 729000\n", "881280 765000\n", "864000000 607500000\n", "648293430 540244525\n", "445906944 528482304\...
2CODEFORCES
392_D. Three Arrays_986
There are three arrays a, b and c. Each of them consists of n integers. SmallY wants to find three integers u, v, w (0 ≤ u, v, w ≤ n) such that the following condition holds: each number that appears in the union of a, b and c, appears either in the first u elements of a, or in the first v elements of b, or in the firs...
#include <bits/stdc++.h> using namespace std; struct Tnode { int x, y, z; } doing[1000050]; struct Type { int pos, val, size; Type *father, *son[2]; Type() {} Type(Type *f, int p, int v, int s) { pos = p; val = v; size = s; father = f; son[0] = son[1] = 0; } } memory[1000050], *root; str...
2C++
{ "input": [ "3\n1 1 101\n1 2 1\n3 2 1\n", "5\n1 1 2 2 3\n2 2 4 3 3\n3 3 1 1 1\n", "1\n2\n3\n2\n", "8\n190409007 190409007 352375776 190409007 352375776 352375776 352375776 352375776\n190409007 190409007 190409007 190409007 190409007 352375776 352375776 190409007\n190409007 352375776 352375776 1904090...
2CODEFORCES
415_E. Mashmokh and Reverse Operation_987
Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced prog...
#include <bits/stdc++.h> using namespace std; int xx[4] = {0, 0, 1, -1}; int yy[4] = {1, -1, 0, 0}; int n, m; int a[int(1048576 + 2000)], b[int(1048576 + 2000)]; long long f[30][2]; long long res = 0; void build(int l, int r, int h) { if (l == r) return; int mid = (l + r) / 2; build(l, mid, h + 1); build(mid + ...
2C++
{ "input": [ "2\n2 1 4 3\n4\n1 2 0 2\n", "1\n1 2\n3\n0 1 1\n", "2\n1 1 3 1\n3\n0 1 2\n", "2\n1 1 6 1\n3\n0 1 2\n", "2\n2 0 4 3\n4\n1 2 0 2\n", "2\n1 1 6 2\n3\n0 1 2\n", "2\n2 0 4 6\n4\n1 2 0 2\n", "2\n2 0 4 6\n4\n1 2 0 0\n", "2\n3 0 4 6\n4\n1 1 1 1\n", "2\n3 0 4 4\n4\n1 1 1 1\n...
2CODEFORCES
415_E. Mashmokh and Reverse Operation_988
Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programming tasks and one week to solve them. Mashmokh is not a very experienced prog...
import java.io.*; import java.util.*; public class cf414c { static FastIO in = new FastIO(), out = in; static long[] count1, count2; public static void main(String[] args) { int n = in.nextInt(); int[] v = new int[1<<n]; for(int i=0; i<1<<n; i++) v[i] = in.nextInt(); count1 = new long[n+1]; ...
4JAVA
{ "input": [ "2\n2 1 4 3\n4\n1 2 0 2\n", "1\n1 2\n3\n0 1 1\n", "2\n1 1 3 1\n3\n0 1 2\n", "2\n1 1 6 1\n3\n0 1 2\n", "2\n2 0 4 3\n4\n1 2 0 2\n", "2\n1 1 6 2\n3\n0 1 2\n", "2\n2 0 4 6\n4\n1 2 0 2\n", "2\n2 0 4 6\n4\n1 2 0 0\n", "2\n3 0 4 6\n4\n1 1 1 1\n", "2\n3 0 4 4\n4\n1 1 1 1\n...
2CODEFORCES
442_C. Artem and Array _989
Artem has an array of n positive integers. Artem decided to play with it. The game consists of n moves. Each move goes like this. Artem chooses some element of the array and removes it. For that, he gets min(a, b) points, where a and b are numbers that were adjacent with the removed number. If the number doesn't have a...
from sys import stdin def main(): n = int(stdin.readline()) a = map(int, stdin.readline().split()) b = [] ans = 0 for x in a: b.append(x) while len(b) > 2 and b[-2] <= b[-1] and b[-2] <= b[-3]: ans += min(b[-1], b[-3]) b[-2] = b[-1] b.pop() for...
1Python2
{ "input": [ "5\n1 2 3 4 5\n", "5\n1 100 101 100 1\n", "5\n3 1 5 2 6\n", "9\n72 49 39 50 68 35 75 94 56\n", "4\n2 3 1 2\n", "8\n3 4 3 1 1 3 4 1\n", "1\n4\n", "7\n2 1 2 2 2 2 2\n", "6\n1 7 3 1 6 2\n", "8\n77 84 26 34 17 56 76 3\n", "2\n93 51\n", "1\n87\n", "4\n86 21 ...
2CODEFORCES
442_C. Artem and Array _990
Artem has an array of n positive integers. Artem decided to play with it. The game consists of n moves. Each move goes like this. Artem chooses some element of the array and removes it. For that, he gets min(a, b) points, where a and b are numbers that were adjacent with the removed number. If the number doesn't have a...
#include <bits/stdc++.h> using namespace std; const int Imx = 2147483647; const int mod = 1000000007; const long long Lbig = 2e18; inline long long getnum() { register long long r = 0; register bool ng = 0; register char c; c = getchar(); while (c != '-' && (c < '0' || c > '9')) c = getchar(); if (c == '-')...
2C++
{ "input": [ "5\n1 2 3 4 5\n", "5\n1 100 101 100 1\n", "5\n3 1 5 2 6\n", "9\n72 49 39 50 68 35 75 94 56\n", "4\n2 3 1 2\n", "8\n3 4 3 1 1 3 4 1\n", "1\n4\n", "7\n2 1 2 2 2 2 2\n", "6\n1 7 3 1 6 2\n", "8\n77 84 26 34 17 56 76 3\n", "2\n93 51\n", "1\n87\n", "4\n86 21 ...
2CODEFORCES
442_C. Artem and Array _991
Artem has an array of n positive integers. Artem decided to play with it. The game consists of n moves. Each move goes like this. Artem chooses some element of the array and removes it. For that, he gets min(a, b) points, where a and b are numbers that were adjacent with the removed number. If the number doesn't have a...
MAXN = 5 * 10**5 + 100 a = [] ans = 0 n = int(input()) a = list( map ( int, input().split() ) ) a.append(0) a = [0] + a n = n + 2 arr = [] arr.append( a[0] ) arr.append( a[1] ) i = 2 while i < n : ln = a[i] l1 = arr[-1] l0 = arr[-2] while l1 <= l0 and l1 <= ln : ans = ans + min ( l0 , ln ) arr.pop() ...
3Python3
{ "input": [ "5\n1 2 3 4 5\n", "5\n1 100 101 100 1\n", "5\n3 1 5 2 6\n", "9\n72 49 39 50 68 35 75 94 56\n", "4\n2 3 1 2\n", "8\n3 4 3 1 1 3 4 1\n", "1\n4\n", "7\n2 1 2 2 2 2 2\n", "6\n1 7 3 1 6 2\n", "8\n77 84 26 34 17 56 76 3\n", "2\n93 51\n", "1\n87\n", "4\n86 21 ...
2CODEFORCES
442_C. Artem and Array _992
Artem has an array of n positive integers. Artem decided to play with it. The game consists of n moves. Each move goes like this. Artem chooses some element of the array and removes it. For that, he gets min(a, b) points, where a and b are numbers that were adjacent with the removed number. If the number doesn't have a...
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.LinkedList; import java.util.Queue; /** * * @author sousnake */ public class E { static int max = 50...
4JAVA
{ "input": [ "5\n1 2 3 4 5\n", "5\n1 100 101 100 1\n", "5\n3 1 5 2 6\n", "9\n72 49 39 50 68 35 75 94 56\n", "4\n2 3 1 2\n", "8\n3 4 3 1 1 3 4 1\n", "1\n4\n", "7\n2 1 2 2 2 2 2\n", "6\n1 7 3 1 6 2\n", "8\n77 84 26 34 17 56 76 3\n", "2\n93 51\n", "1\n87\n", "4\n86 21 ...
2CODEFORCES
464_D. World of Darkraft - 2_993
Roma found a new character in the game "World of Darkraft - 2". In this game the character fights monsters, finds the more and more advanced stuff that lets him fight stronger monsters. The character can equip himself with k distinct types of items. Power of each item depends on its level (positive integer number). In...
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; const int maxk = 105; vector<pair<int, long double> > f, tmp; long double g[maxn], t[maxn]; long double ans; int n, k; int main() { scanf("%d%d", &n, &k); f.push_back(make_pair(1, 1.0)); for (int i = 0; i < n; ++i) { tmp.clear(); for (...
2C++
{ "input": [ "2 1\n", "1 3\n", "10 2\n", "777 2\n", "2 2\n", "99900 1\n", "50000 1\n", "2 5\n", "100000 99\n", "22222 22\n", "100000 4\n", "100000 1\n", "100 1\n", "100 2\n", "77777 1\n", "100000 3\n", "13 20\n", "66666 6\n", "1 1\n", "52...
2CODEFORCES
464_D. World of Darkraft - 2_994
Roma found a new character in the game "World of Darkraft - 2". In this game the character fights monsters, finds the more and more advanced stuff that lets him fight stronger monsters. The character can equip himself with k distinct types of items. Power of each item depends on its level (positive integer number). In...
import java.io.*; import java.util.*; public class Main{ private static Reader in; private static PrintWriter out; public static void main(String[] args) throws IOException { in = new Reader(); out = new PrintWriter(System.out, true); int N = in.nextInt(), K = in.nextInt(); long time = Syst...
4JAVA
{ "input": [ "2 1\n", "1 3\n", "10 2\n", "777 2\n", "2 2\n", "99900 1\n", "50000 1\n", "2 5\n", "100000 99\n", "22222 22\n", "100000 4\n", "100000 1\n", "100 1\n", "100 2\n", "77777 1\n", "100000 3\n", "13 20\n", "66666 6\n", "1 1\n", "52...
2CODEFORCES
488_C. Fight the Monster_995
A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (HP), offensive power (ATK) and defensive power (DEF). During the battle, every second the monster's HP decrease by max(0, ATKY - DEFM), while Yang's HP decreases by max(0,...
def optimize(a,b,c,l): prev =100000 for i in range(150): if l*i > c: if b*i < prev: prev = b*i else: rh = c+1-l*i if (rh*a + b*i) < prev: prev = (rh*a + b*i) # print prev return prev y = map(int,raw_input().split()) m = map(int,raw_input().split()) p = map(int,raw_input().split()) A = [0,0,0]...
1Python2
{ "input": [ "1 2 1\n1 100 1\n1 100 100\n", "100 100 100\n1 1 1\n1 1 1\n", "51 89 97\n18 25 63\n22 91 74\n", "1 100 1\n100 100 100\n1 100 100\n", "20 1 1\n100 100 100\n1 100 100\n", "1 10 29\n1 1 43\n1 1 100\n", "25 38 49\n84 96 42\n3 51 92\n", "2 1 1\n100 2 100\n100 1 100\n", "1 1...
2CODEFORCES
488_C. Fight the Monster_996
A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (HP), offensive power (ATK) and defensive power (DEF). During the battle, every second the monster's HP decrease by max(0, ATKY - DEFM), while Yang's HP decreases by max(0,...
#include <bits/stdc++.h> using namespace std; const int MM = 100005; const long long MOD = 1000000007; bool judge(int hpy, int atky, int defy, int hpm, int atkm, int defm) { int a = max(0, atky - defm), b = max(0, atkm - defy); if (a == 0) return false; if (b == 0) return true; int c = hpm % a == 0 ? hpm / a : ...
2C++
{ "input": [ "1 2 1\n1 100 1\n1 100 100\n", "100 100 100\n1 1 1\n1 1 1\n", "51 89 97\n18 25 63\n22 91 74\n", "1 100 1\n100 100 100\n1 100 100\n", "20 1 1\n100 100 100\n1 100 100\n", "1 10 29\n1 1 43\n1 1 100\n", "25 38 49\n84 96 42\n3 51 92\n", "2 1 1\n100 2 100\n100 1 100\n", "1 1...
2CODEFORCES
488_C. Fight the Monster_997
A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (HP), offensive power (ATK) and defensive power (DEF). During the battle, every second the monster's HP decrease by max(0, ATKY - DEFM), while Yang's HP decreases by max(0,...
# HEY STALKER hp_y, at_y, df_y = map(int, input().split()) hp_m, at_m, df_m = map(int, input().split()) cst_hp, cst_at, cst_df = map(int, input().split()) ans = 2e18 for ati in range(201): for dfi in range(201): if ati + at_y > df_m: k = hp_m // ((at_y + ati) - df_m) if hp_m % ((at_y...
3Python3
{ "input": [ "1 2 1\n1 100 1\n1 100 100\n", "100 100 100\n1 1 1\n1 1 1\n", "51 89 97\n18 25 63\n22 91 74\n", "1 100 1\n100 100 100\n1 100 100\n", "20 1 1\n100 100 100\n1 100 100\n", "1 10 29\n1 1 43\n1 1 100\n", "25 38 49\n84 96 42\n3 51 92\n", "2 1 1\n100 2 100\n100 1 100\n", "1 1...
2CODEFORCES
488_C. Fight the Monster_998
A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (HP), offensive power (ATK) and defensive power (DEF). During the battle, every second the monster's HP decrease by max(0, ATKY - DEFM), while Yang's HP decreases by max(0,...
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.InputMismatchException; public class Main { public static void main(String[] args) { // TaskA mSol = new TaskA(); // TaskB mSol = new TaskB(); // TaskC mSol ...
4JAVA
{ "input": [ "1 2 1\n1 100 1\n1 100 100\n", "100 100 100\n1 1 1\n1 1 1\n", "51 89 97\n18 25 63\n22 91 74\n", "1 100 1\n100 100 100\n1 100 100\n", "20 1 1\n100 100 100\n1 100 100\n", "1 10 29\n1 1 43\n1 1 100\n", "25 38 49\n84 96 42\n3 51 92\n", "2 1 1\n100 2 100\n100 1 100\n", "1 1...
2CODEFORCES
512_B. Fox And Jumping_999
Fox Ciel is playing a game. In this game there is an infinite long tape with cells indexed by integers (positive, negative and zero). At the beginning she is standing at the cell 0. There are also n cards, each card has 2 attributes: length li and cost ci. If she pays ci dollars then she can apply i-th card. After app...
R=lambda:map(int,raw_input().split()) def gcd(a,b):return a if not b else gcd(b,a%b) input() v={0:0} for a,b in zip(R(),R()): for k in v.keys(): x=gcd(a,k) v[x]=min(v.get(x,1<<28),v[k]+b) print v.get(1,-1)
1Python2
{ "input": [ "5\n10 20 30 40 50\n1 1 1 1 1\n", "8\n4264 4921 6321 6984 2316 8432 6120 1026\n4264 4921 6321 6984 2316 8432 6120 1026\n", "3\n100 99 9900\n1 1 1\n", "7\n15015 10010 6006 4290 2730 2310 1\n1 1 1 1 1 1 10\n", "8\n2 3 5 7 11 13 17 19\n4 8 7 1 5 2 6 3\n", "1\n2\n2\n", "1\n1000000...
2CODEFORCES