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
659_E. New Reform_38300
Berland has n cities connected by m bidirectional roads. No road connects a city to itself, and each pair of cities is connected by no more than one road. It is not guaranteed that you can get from any city to any other one, using only the existing roads. The President of Berland decided to make changes to the road sy...
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public final class Main { static boolean flag = false; static int[] vis; static List<List<Integer>> adj; static void dfs(int vertice, int pai){ vis[vertice] = 1; for (Integer vizinho : adj.get(vertice)) { if (vis[vizinho] != ...
4JAVA
{ "input": [ "5 5\n2 1\n1 3\n2 3\n2 5\n4 3\n", "4 3\n2 1\n1 3\n4 3\n", "6 5\n1 2\n2 3\n4 5\n4 6\n5 6\n", "10 45\n3 5\n2 3\n4 8\n2 5\n6 8\n5 7\n2 1\n3 7\n5 10\n6 1\n9 4\n3 6\n9 10\n6 7\n1 7\n7 9\n6 9\n9 3\n4 2\n2 6\n5 6\n5 8\n3 4\n10 8\n7 8\n4 6\n9 1\n5 9\n7 4\n1 10\n9 2\n2 8\n6 10\n9 8\n1 5\n7 2\n10 3...
2CODEFORCES
682_B. Alyona and Mex_38301
Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not ...
n=int(raw_input()) a=map(int,raw_input().split()) a.sort() ans=1 for i in a: if ans<=i: ans+=1 print ans
1Python2
{ "input": [ "5\n1 3 3 3 6\n", "2\n2 1\n", "4\n1 2 2 3\n", "4\n1 4 1 1\n", "2\n3 3\n", "4\n1 2 1 2\n", "3\n3 3 1\n", "3\n2 4 1\n", "2\n1 1\n", "3\n2 2 2\n", "4\n2 2 2 1\n", "4\n2 2 2 3\n", "7\n1 2 2 2 5 5 1\n", "4\n1 4 4 3\n", "4\n2 2 3 2\n", "4\n2 4 1 2...
2CODEFORCES
682_B. Alyona and Mex_38302
Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n; vector<long long> sm(n); for (int i = 0; i < n; i++) { cin >> sm[i]; } sort(sm.begin(), sm.end()); long long now = 1; for (int i = 0; i < sm.size(); i++) { if (sm[i] >= now) sm[i] = now, now++; } cout << now...
2C++
{ "input": [ "5\n1 3 3 3 6\n", "2\n2 1\n", "4\n1 2 2 3\n", "4\n1 4 1 1\n", "2\n3 3\n", "4\n1 2 1 2\n", "3\n3 3 1\n", "3\n2 4 1\n", "2\n1 1\n", "3\n2 2 2\n", "4\n2 2 2 1\n", "4\n2 2 2 3\n", "7\n1 2 2 2 5 5 1\n", "4\n1 4 4 3\n", "4\n2 2 3 2\n", "4\n2 4 1 2...
2CODEFORCES
682_B. Alyona and Mex_38303
Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not ...
import sys n = int(input()) arr = list(map(int,input().split())) arr.sort() ans = 1 for i in range(1,n+1): if arr[i-1]>=ans: ans+=1 print(ans)
3Python3
{ "input": [ "5\n1 3 3 3 6\n", "2\n2 1\n", "4\n1 2 2 3\n", "4\n1 4 1 1\n", "2\n3 3\n", "4\n1 2 1 2\n", "3\n3 3 1\n", "3\n2 4 1\n", "2\n1 1\n", "3\n2 2 2\n", "4\n2 2 2 1\n", "4\n2 2 2 3\n", "7\n1 2 2 2 5 5 1\n", "4\n1 4 4 3\n", "4\n2 2 3 2\n", "4\n2 4 1 2...
2CODEFORCES
682_B. Alyona and Mex_38304
Someone gave Alyona an array containing n positive integers a1, a2, ..., an. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not ...
import java.util.Scanner; import java.util.Vector; public class probBCon358 { /** * @param args */ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); Vector<Integer> vec = new Vector<Integer>(); for (int i = 0; i < n; i++){ vec.add(sc.nextInt()); ...
4JAVA
{ "input": [ "5\n1 3 3 3 6\n", "2\n2 1\n", "4\n1 2 2 3\n", "4\n1 4 1 1\n", "2\n3 3\n", "4\n1 2 1 2\n", "3\n3 3 1\n", "3\n2 4 1\n", "2\n1 1\n", "3\n2 2 2\n", "4\n2 2 2 1\n", "4\n2 2 2 3\n", "7\n1 2 2 2 5 5 1\n", "4\n1 4 4 3\n", "4\n2 2 3 2\n", "4\n2 4 1 2...
2CODEFORCES
705_A. Hulk_38305
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and like that his feelings are complicated. They have n layers. The first layer is hate, seco...
a = int(raw_input()) b = (" I hate ") c = (" I love ") output = " " for i in range(0,a): if(i%2 == 0): output += b else: output += c if (i+1 != a): output += "that" output += "it" print output
1Python2
{ "input": [ "2\n", "1\n", "3\n", "18\n", "57\n", "100\n", "86\n", "34\n", "82\n", "99\n", "81\n", "19\n", "10\n", "98\n", "5\n", "4\n", "85\n", "76\n", "77\n", "33\n", "12\n", "41\n", "60\n", "24\n", "27\n", "88\n...
2CODEFORCES
705_A. Hulk_38306
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and like that his feelings are complicated. They have n layers. The first layer is hate, seco...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string s_begin = "I hate ", s_end = "it"; string y = "that I hate ", x = "that I love "; cout << s_begin; for (int i = 2; i <= n; i++) { if (i % 2 == 0) cout << x; else cout << y; } cout << s_end << endl; }
2C++
{ "input": [ "2\n", "1\n", "3\n", "18\n", "57\n", "100\n", "86\n", "34\n", "82\n", "99\n", "81\n", "19\n", "10\n", "98\n", "5\n", "4\n", "85\n", "76\n", "77\n", "33\n", "12\n", "41\n", "60\n", "24\n", "27\n", "88\n...
2CODEFORCES
705_A. Hulk_38307
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and like that his feelings are complicated. They have n layers. The first layer is hate, seco...
x = int(input()) feelings = '' for _ in range(x): if _ == x - 1: if _ % 2 != 0: feelings = feelings + 'I love it ' else: feelings = feelings + 'I hate it ' else: if _ % 2 != 0: feelings = feelings + 'I love that ' else: feelings = feelings + 'I hate that ' print(feelings)
3Python3
{ "input": [ "2\n", "1\n", "3\n", "18\n", "57\n", "100\n", "86\n", "34\n", "82\n", "99\n", "81\n", "19\n", "10\n", "98\n", "5\n", "4\n", "85\n", "76\n", "77\n", "33\n", "12\n", "41\n", "60\n", "24\n", "27\n", "88\n...
2CODEFORCES
705_A. Hulk_38308
Dr. Bruce Banner hates his enemies (like others don't). As we all know, he can barely talk when he turns into the incredible Hulk. That's why he asked you to help him to express his feelings. Hulk likes the Inception so much, and like that his feelings are complicated. They have n layers. The first layer is hate, seco...
import java.util.Scanner; public class Hulk2{ public static void main(String[]args){ Scanner apple = new Scanner(System.in); int n = apple.nextInt(); int i; for (i = 0; i < n; i++) { if (i % 2 == 0) { System.out.printf("I hate "); } else { ...
4JAVA
{ "input": [ "2\n", "1\n", "3\n", "18\n", "57\n", "100\n", "86\n", "34\n", "82\n", "99\n", "81\n", "19\n", "10\n", "98\n", "5\n", "4\n", "85\n", "76\n", "77\n", "33\n", "12\n", "41\n", "60\n", "24\n", "27\n", "88\n...
2CODEFORCES
727_D. T-shirts Distribution_38309
The organizers of a programming contest have decided to present t-shirts to participants. There are six different t-shirts sizes in this problem: S, M, L, XL, XXL, XXXL (sizes are listed in increasing order). The t-shirts are already prepared. For each size from S to XXXL you are given the number of t-shirts of this si...
def read(t=None): string = raw_input() return string if t is None else [t(x) for x in string.split()] a, n = [], 0 demands = [] sizeno = {'S':0, 'M':1, 'L':2, 'XL':3, 'XXL':4, 'XXXL':5} sizenm = ['S', 'M', 'L', 'XL', 'XXL', 'XXXL'] class demand(object): def __init__(self, arr): self.one = True self.x = sizeno...
1Python2
{ "input": [ "0 1 0 1 1 0\n3\nXL\nS,M\nXL,XXL\n", "1 1 2 0 1 1\n5\nS\nM\nS,M\nXXL,XXXL\nXL,XXL\n", "5 1 5 2 4 3\n20\nL,XL\nS,M\nL,XL\nXXL,XXXL\nS,M\nS,M\nXL,XXL\nL,XL\nS,M\nL,XL\nS,M\nM,L\nXXL,XXXL\nXXL,XXXL\nL\nXXL,XXXL\nXL,XXL\nM,L\nS,M\nXXL\n", "1 2 4 4 1 1\n10\nXL\nXL\nS,M\nL\nM,L\nL\nS,M\nM\nXL,X...
2CODEFORCES
727_D. T-shirts Distribution_38310
The organizers of a programming contest have decided to present t-shirts to participants. There are six different t-shirts sizes in this problem: S, M, L, XL, XXL, XXXL (sizes are listed in increasing order). The t-shirts are already prepared. For each size from S to XXXL you are given the number of t-shirts of this si...
#include <bits/stdc++.h> inline int F() { register int aa, bb, ch; while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-') ; ch == '-' ? aa = bb = 0 : (aa = ch - '0', bb = 1); while (ch = getchar(), ch >= '0' && ch <= '9') aa = aa * 10 + ch - '0'; return bb ? aa : -aa; } int a[7], b[7], d[7], c[100010...
2C++
{ "input": [ "0 1 0 1 1 0\n3\nXL\nS,M\nXL,XXL\n", "1 1 2 0 1 1\n5\nS\nM\nS,M\nXXL,XXXL\nXL,XXL\n", "5 1 5 2 4 3\n20\nL,XL\nS,M\nL,XL\nXXL,XXXL\nS,M\nS,M\nXL,XXL\nL,XL\nS,M\nL,XL\nS,M\nM,L\nXXL,XXXL\nXXL,XXXL\nL\nXXL,XXXL\nXL,XXL\nM,L\nS,M\nXXL\n", "1 2 4 4 1 1\n10\nXL\nXL\nS,M\nL\nM,L\nL\nS,M\nM\nXL,X...
2CODEFORCES
727_D. T-shirts Distribution_38311
The organizers of a programming contest have decided to present t-shirts to participants. There are six different t-shirts sizes in this problem: S, M, L, XL, XXL, XXXL (sizes are listed in increasing order). The t-shirts are already prepared. For each size from S to XXXL you are given the number of t-shirts of this si...
from math import * from sys import * def conv(s): if s=="S" or s=="S\n": return 1 if s=="M" or s=="M\n": return 2 if s=="L" or s=="L\n": return 3 if s=="XL" or s=="XL\n": return 4 if s=="XXL" or s=="XXL\n": return 5 return 6 def uncon(x): if x==1: return "S" if x==2: return "M" if x==3: retu...
3Python3
{ "input": [ "0 1 0 1 1 0\n3\nXL\nS,M\nXL,XXL\n", "1 1 2 0 1 1\n5\nS\nM\nS,M\nXXL,XXXL\nXL,XXL\n", "5 1 5 2 4 3\n20\nL,XL\nS,M\nL,XL\nXXL,XXXL\nS,M\nS,M\nXL,XXL\nL,XL\nS,M\nL,XL\nS,M\nM,L\nXXL,XXXL\nXXL,XXXL\nL\nXXL,XXXL\nXL,XXL\nM,L\nS,M\nXXL\n", "1 2 4 4 1 1\n10\nXL\nXL\nS,M\nL\nM,L\nL\nS,M\nM\nXL,X...
2CODEFORCES
727_D. T-shirts Distribution_38312
The organizers of a programming contest have decided to present t-shirts to participants. There are six different t-shirts sizes in this problem: S, M, L, XL, XXL, XXXL (sizes are listed in increasing order). The t-shirts are already prepared. For each size from S to XXXL you are given the number of t-shirts of this si...
import java.io.*; import java.util.*; public class CF727D { static String[] ss = { "S", "M", "L", "XL", "XXL", "XXXL", "S,M", "M,L", "L,XL", "XL,XXL", "XXL,XXXL" }; static int index(String s) { for (int j = 0; j < 11; j++) if (s.equals(ss[j])) return j; return -1; } public static void main(String[] ar...
4JAVA
{ "input": [ "0 1 0 1 1 0\n3\nXL\nS,M\nXL,XXL\n", "1 1 2 0 1 1\n5\nS\nM\nS,M\nXXL,XXXL\nXL,XXL\n", "5 1 5 2 4 3\n20\nL,XL\nS,M\nL,XL\nXXL,XXXL\nS,M\nS,M\nXL,XXL\nL,XL\nS,M\nL,XL\nS,M\nM,L\nXXL,XXXL\nXXL,XXXL\nL\nXXL,XXXL\nXL,XXL\nM,L\nS,M\nXXL\n", "1 2 4 4 1 1\n10\nXL\nXL\nS,M\nL\nM,L\nL\nS,M\nM\nXL,X...
2CODEFORCES
748_E. Santa Claus and Tangerines_38313
Santa Claus has n tangerines, and the i-th of them consists of exactly ai slices. Santa Claus came to a school which has k pupils. Santa decided to treat them with tangerines. However, there can be too few tangerines to present at least one tangerine to each pupil. So Santa decided to divide tangerines into parts so t...
#include <bits/stdc++.h> using namespace std; int arr[int(1e7 + 100)]; void aum(int i) { if (i % 2) { arr[i / 2 + 1] += arr[i]; arr[i / 2] += arr[i]; } else arr[i / 2] += 2 * arr[i]; } int main() { ios_base::sync_with_stdio(0); set<int> conj; memset(arr, 0, sizeof arr); int n, m, l, ans = int(2 ...
2C++
{ "input": [ "3 2\n5 9 3\n", "2 4\n12 14\n", "2 3\n1 1\n", "1 2\n2\n", "10 2\n26 27 32 28 22 23 30 26 28 23\n", "4 5\n1 2 3 200000\n", "1 3\n31\n", "20 100\n52 55 53 54 48 47 50 45 52 51 51 51 47 45 50 51 53 55 51 52\n", "50 300\n9293 9540 6585 6756 215 6853 4819 3033 5529 8201 407...
2CODEFORCES
748_E. Santa Claus and Tangerines_38314
Santa Claus has n tangerines, and the i-th of them consists of exactly ai slices. Santa Claus came to a school which has k pupils. Santa decided to treat them with tangerines. However, there can be too few tangerines to present at least one tangerine to each pupil. So Santa decided to divide tangerines into parts so t...
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Main { static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; ...
4JAVA
{ "input": [ "3 2\n5 9 3\n", "2 4\n12 14\n", "2 3\n1 1\n", "1 2\n2\n", "10 2\n26 27 32 28 22 23 30 26 28 23\n", "4 5\n1 2 3 200000\n", "1 3\n31\n", "20 100\n52 55 53 54 48 47 50 45 52 51 51 51 47 45 50 51 53 55 51 52\n", "50 300\n9293 9540 6585 6756 215 6853 4819 3033 5529 8201 407...
2CODEFORCES
771_D. Bear and Company_38315
Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it still possible to read, he will try to modify each word as little as possible. Limak has a string s t...
n = int(raw_input()) a, b, c = [], [], [] s = raw_input() from collections import defaultdict dp = defaultdict(lambda : float("inf")) def count(a, st, x): ret = 0 i = st while i < len(a) and a[i] < x: ret += 1 i += 1 return ret for i in xrange(len(s)): if s[i] == "V": a.appen...
1Python2
{ "input": [ "4\nVKVK\n", "7\nVVKEVKK\n", "5\nLIMAK\n", "20\nVKVKVVVKVOVKVQKKKVVK\n", "5\nBVVKV\n", "15\nVKKHKKKKZVKKVKV\n", "52\nVAVBVCVDVEVFVGVHVIVJVKVLVMVNVOVPVQVRVSVTVUVVVWVXVYVZ\n", "75\nVAKKVKVKKZVVZAVKKVKVZKKVKVVKKAVKKKVVZVKVKVKKKKVVVVKKVZKVVKKKVAKKZVKKVKVVKVK\n", "51\nAVVVV...
2CODEFORCES
771_D. Bear and Company_38316
Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it still possible to read, he will try to modify each word as little as possible. Limak has a string s t...
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; char s[200]; vector<int> pos[3]; int dp[200][200][200][3]; int main() { int n = 0; scanf("%d%s", &n, s + 1); for (int i = 1; i <= n; i++) { if (s[i] == 'V') pos[0].push_back(i); else if (s[i] == 'K') pos[1].push_back(i); el...
2C++
{ "input": [ "4\nVKVK\n", "7\nVVKEVKK\n", "5\nLIMAK\n", "20\nVKVKVVVKVOVKVQKKKVVK\n", "5\nBVVKV\n", "15\nVKKHKKKKZVKKVKV\n", "52\nVAVBVCVDVEVFVGVHVIVJVKVLVMVNVOVPVQVRVSVTVUVVVWVXVYVZ\n", "75\nVAKKVKVKKZVVZAVKKVKVZKKVKVVKKAVKKKVVZVKVKVKKKKVVVVKKVZKVVKKKVAKKZVKKVKVVKVK\n", "51\nAVVVV...
2CODEFORCES
771_D. Bear and Company_38317
Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it still possible to read, he will try to modify each word as little as possible. Limak has a string s t...
# http://codeforces.com/contest/771/problem/D """ DP-solution. For each state (v, k, x, v_is_last_letter) we trial a step along the v, k and x axes and check that dp[future_state] = min(dp[future_state], dp[state] + cost_of_move) Hence this implicitly reults in the one with least cost. V, K, X are arrays that contain...
3Python3
{ "input": [ "4\nVKVK\n", "7\nVVKEVKK\n", "5\nLIMAK\n", "20\nVKVKVVVKVOVKVQKKKVVK\n", "5\nBVVKV\n", "15\nVKKHKKKKZVKKVKV\n", "52\nVAVBVCVDVEVFVGVHVIVJVKVLVMVNVOVPVQVRVSVTVUVVVWVXVYVZ\n", "75\nVAKKVKVKKZVVZAVKKVKVZKKVKVVKKAVKKKVVZVKVKVKKKKVVVVKKVZKVVKKKVAKKZVKKVKVVKVK\n", "51\nAVVVV...
2CODEFORCES
771_D. Bear and Company_38318
Bear Limak prepares problems for a programming competition. Of course, it would be unprofessional to mention the sponsor name in the statement. Limak takes it seriously and he is going to change some words. To make it still possible to read, he will try to modify each word as little as possible. Limak has a string s t...
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Hard { static List<Integer> listIndexesK = new ArrayList<>(); static List<Integer> listIndexesV = new ArrayList<>(); static List<Integer> listIndexesOther = new ArrayList<>(); static int[][][][] variablePosition ...
4JAVA
{ "input": [ "4\nVKVK\n", "7\nVVKEVKK\n", "5\nLIMAK\n", "20\nVKVKVVVKVOVKVQKKKVVK\n", "5\nBVVKV\n", "15\nVKKHKKKKZVKKVKV\n", "52\nVAVBVCVDVEVFVGVHVIVJVKVLVMVNVOVPVQVRVSVTVUVVVWVXVYVZ\n", "75\nVAKKVKVKKZVVZAVKKVKVZKKVKVVKKAVKKKVVZVKVKVKKKKVVVVKKVZKVVKKKVAKKZVKKVKVVKVK\n", "51\nAVVVV...
2CODEFORCES
796_D. Police Stations_38319
Inzane finally found Zane with a lot of money to spare, so they together decided to establish a country of their own. Ruling a country is not an easy job. Thieves and terrorists are always ready to ruin the country's peace. To fight back, Zane and Inzane have enacted a very effective law: from each city it must be pos...
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vll = vector<ll>; const ll inf = 2e9 + 3; const ll MAXINT = 1e9 + 7; const double PI = 3.14159265358979323846; const double pi = acos(-1); const int N = 300005, M = 2 * N; map<pair<int, int>, pair<int, bool>> ei; queue<int...
2C++
{ "input": [ "6 3 2\n1 5 6\n1 2\n1 3\n1 4\n1 5\n5 6\n", "6 2 4\n1 6\n1 2\n2 3\n3 4\n4 5\n5 6\n", "6 2 4\n1 6\n1 2\n2 3\n3 4\n4 5\n5 6\n", "2 1 1\n1\n1 2\n", "11 1 5\n6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n", "10 1 5\n5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n", "10 ...
2CODEFORCES
796_D. Police Stations_38320
Inzane finally found Zane with a lot of money to spare, so they together decided to establish a country of their own. Ruling a country is not an easy job. Thieves and terrorists are always ready to ruin the country's peace. To fight back, Zane and Inzane have enacted a very effective law: from each city it must be pos...
import os, sys, bisect, copy from collections import defaultdict, Counter, deque from functools import lru_cache #use @lru_cache(None) if os.path.exists('in.txt'): sys.stdin=open('in.txt','r') if os.path.exists('out.txt'): sys.stdout=open('out.txt', 'w') # def input(): return sys.stdin.readline() def mapi(arg=0): ret...
3Python3
{ "input": [ "6 3 2\n1 5 6\n1 2\n1 3\n1 4\n1 5\n5 6\n", "6 2 4\n1 6\n1 2\n2 3\n3 4\n4 5\n5 6\n", "6 2 4\n1 6\n1 2\n2 3\n3 4\n4 5\n5 6\n", "2 1 1\n1\n1 2\n", "11 1 5\n6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n", "10 1 5\n5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n", "10 ...
2CODEFORCES
796_D. Police Stations_38321
Inzane finally found Zane with a lot of money to spare, so they together decided to establish a country of their own. Ruling a country is not an easy job. Thieves and terrorists are always ready to ruin the country's peace. To fight back, Zane and Inzane have enacted a very effective law: from each city it must be pos...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.IOException; import java.util.LinkedList; import java.util.ArrayList; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Rene */ pu...
4JAVA
{ "input": [ "6 3 2\n1 5 6\n1 2\n1 3\n1 4\n1 5\n5 6\n", "6 2 4\n1 6\n1 2\n2 3\n3 4\n4 5\n5 6\n", "6 2 4\n1 6\n1 2\n2 3\n3 4\n4 5\n5 6\n", "2 1 1\n1\n1 2\n", "11 1 5\n6\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n", "10 1 5\n5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n", "10 ...
2CODEFORCES
816_E. Karen and Supermarket_38322
On the way home, Karen decided to stop by the supermarket to buy some groceries. <image> She needs to buy a lot of goods, but since she is a student her budget is still quite limited. In fact, she can only spend up to b dollars. The supermarket sells n goods. The i-th good can be bought for ci dollars. Of course, ea...
#include <bits/stdc++.h> using namespace std; void fre() { freopen("c://test//input.in", "r", stdin); freopen("c://test//output.out", "w", stdout); } template <class T1, class T2> inline void gmax(T1 &a, T2 b) { if (b > a) a = b; } template <class T1, class T2> inline void gmin(T1 &a, T2 b) { if (b < a) a = b; ...
2C++
{ "input": [ "6 16\n10 9\n10 5 1\n12 2 1\n20 18 3\n10 2 3\n2 1 5\n", "5 10\n3 1\n3 1 1\n3 1 2\n3 1 3\n3 1 4\n", "9 7\n3 1\n6 2 1\n8 3 2\n4 1 2\n2 1 2\n3 2 3\n8 7 1\n6 5 5\n8 4 4\n", "13 30\n6 4\n25 5 1\n7 1 2\n9 4 2\n10 2 1\n12 3 1\n5 2 3\n10 9 6\n2 1 1\n5 3 9\n10 2 10\n10 9 6\n3 2 11\n", "2 10000...
2CODEFORCES
816_E. Karen and Supermarket_38323
On the way home, Karen decided to stop by the supermarket to buy some groceries. <image> She needs to buy a lot of goods, but since she is a student her budget is still quite limited. In fact, she can only spend up to b dollars. The supermarket sells n goods. The i-th good can be bought for ci dollars. Of course, ea...
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.StringTokenizer; import java.util.Tree...
4JAVA
{ "input": [ "6 16\n10 9\n10 5 1\n12 2 1\n20 18 3\n10 2 3\n2 1 5\n", "5 10\n3 1\n3 1 1\n3 1 2\n3 1 3\n3 1 4\n", "9 7\n3 1\n6 2 1\n8 3 2\n4 1 2\n2 1 2\n3 2 3\n8 7 1\n6 5 5\n8 4 4\n", "13 30\n6 4\n25 5 1\n7 1 2\n9 4 2\n10 2 1\n12 3 1\n5 2 3\n10 9 6\n2 1 1\n5 3 9\n10 2 10\n10 9 6\n3 2 11\n", "2 10000...
2CODEFORCES
841_E. On the Bench_38324
A year ago on the bench in public park Leha found an array of n numbers. Leha believes that permutation p is right if for all 1 ≤ i < n condition, that api·api + 1 is not perfect square, holds. Leha wants to find number of right permutations modulo 109 + 7. Input First line of input data contains single integer n (1 ...
#include <bits/stdc++.h> using namespace std; const int MX_N = 305; const int MOD = 1e9 + 7; int N, A[MX_N]; int F[MX_N], fcnt, C[MX_N]; int nck[MX_N][MX_N], fac[MX_N], dp[MX_N][MX_N]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> N; for (int i = (1); i <= (N); ++i) { cin >> A[i]; for (in...
2C++
{ "input": [ "7\n5 2 4 2 4 1 1\n", "3\n1 2 4\n", "50\n297 787 34 268 439 629 600 398 425 833 721 908 830 636 64 509 420 647 499 675 427 599 396 119 798 742 577 355 22 847 389 574 766 453 196 772 808 261 106 844 726 975 173 992 874 89 775 616 678 52\n", "50\n873 838 288 87 889 364 720 410 565 651 577 3...
2CODEFORCES
841_E. On the Bench_38325
A year ago on the bench in public park Leha found an array of n numbers. Leha believes that permutation p is right if for all 1 ≤ i < n condition, that api·api + 1 is not perfect square, holds. Leha wants to find number of right permutations modulo 109 + 7. Input First line of input data contains single integer n (1 ...
import sun.security.util.Length; import java.lang.reflect.Array; import java.math.BigInteger; import java.util.*; public class E { public static boolean isSquare(int a, int b) { long mult = ((long)a) * b; long sqrt = Math.round(Math.sqrt(mult)); return sqrt * sqrt == mult; } pub...
4JAVA
{ "input": [ "7\n5 2 4 2 4 1 1\n", "3\n1 2 4\n", "50\n297 787 34 268 439 629 600 398 425 833 721 908 830 636 64 509 420 647 499 675 427 599 396 119 798 742 577 355 22 847 389 574 766 453 196 772 808 261 106 844 726 975 173 992 874 89 775 616 678 52\n", "50\n873 838 288 87 889 364 720 410 565 651 577 3...
2CODEFORCES
862_F. Mahmoud and Ehab and the final stage_38326
Mahmoud and Ehab solved Dr. Evil's questions so he gave them the password of the door of the evil land. When they tried to open the door using it, the door gave them a final question to solve before they leave (yes, the door is digital, Dr. Evil is modern). If they don't solve it, all the work will be useless and they ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXLEN = 100000; const int MAXN = 100000; const int MAXQ = 100000; const int MAXTN = MAXLEN + 1; const int MAXLG = 16; const int MAXSN = 4 * (MAXN - 1); const int MAXZN = 4 * MAXN; type...
2C++
{ "input": [ "5 9\nmahmoud mahmoudbadawy drmahmoud drevil mahmoud\n1 1 5\n1 1 2\n1 2 3\n2 3 mahmoud\n2 4 mahmoud\n2 2 mahmouu\n1 1 5\n1 2 3\n1 1 1\n", "10 20\nvgxgp vgxgpuamkx vgxgpua vgxgpuamk v v vgxgpu vgxgpuamkx vgx vgx\n1 4 10\n1 2 10\n2 7 vgx\n2 3 vgx\n2 10 v\n2 3 vgx\n1 9 10\n2 6 vgxgpuam\n2 3 vgxgpuam...
2CODEFORCES
862_F. Mahmoud and Ehab and the final stage_38327
Mahmoud and Ehab solved Dr. Evil's questions so he gave them the password of the door of the evil land. When they tried to open the door using it, the door gave them a final question to solve before they leave (yes, the door is digital, Dr. Evil is modern). If they don't solve it, all the work will be useless and they ...
//package round435; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class F { InputStream is; PrintWriter out; String INPUT = ""; void solve() { int n = ni(); int...
4JAVA
{ "input": [ "5 9\nmahmoud mahmoudbadawy drmahmoud drevil mahmoud\n1 1 5\n1 1 2\n1 2 3\n2 3 mahmoud\n2 4 mahmoud\n2 2 mahmouu\n1 1 5\n1 2 3\n1 1 1\n", "10 20\nvgxgp vgxgpuamkx vgxgpua vgxgpuamk v v vgxgpu vgxgpuamkx vgx vgx\n1 4 10\n1 2 10\n2 7 vgx\n2 3 vgx\n2 10 v\n2 3 vgx\n1 9 10\n2 6 vgxgpuam\n2 3 vgxgpuam...
2CODEFORCES
888_D. Almost Identity Permutations_38328
A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≤ i ≤ n) such that pi = i. Your task is to count the number of almost identity permutations for given numbers...
n,k = map(int, raw_input().strip().split()) ans = 1 if k>=2: ans += n*(n-1)/2 if k>=3: ans += n*(n-1)*(n-2) / 6 * 2 if k>=4: ans += n*(n-1)*(n-2)*(n-3) / 24 * 9 print ans
1Python2
{ "input": [ "4 2\n", "4 1\n", "5 4\n", "5 3\n", "1000 2\n", "400 4\n", "200 3\n", "400 3\n", "800 3\n", "200 1\n", "600 3\n", "200 2\n", "400 2\n", "800 4\n", "1000 4\n", "1000 1\n", "1000 3\n", "200 4\n", "400 1\n", "600 2\n", "800 ...
2CODEFORCES
888_D. Almost Identity Permutations_38329
A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≤ i ≤ n) such that pi = i. Your task is to count the number of almost identity permutations for given numbers...
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx") const int N = (int)5e5 + 7, inf = (int)1e9 + 7, mod = (int)1e9 + 7; const long long linf = (long long)1e18 + 7; const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1}, dy[] = {0, 1, 0, -1, 1, -1, 1, -1}; ...
2C++
{ "input": [ "4 2\n", "4 1\n", "5 4\n", "5 3\n", "1000 2\n", "400 4\n", "200 3\n", "400 3\n", "800 3\n", "200 1\n", "600 3\n", "200 2\n", "400 2\n", "800 4\n", "1000 4\n", "1000 1\n", "1000 3\n", "200 4\n", "400 1\n", "600 2\n", "800 ...
2CODEFORCES
888_D. Almost Identity Permutations_38330
A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≤ i ≤ n) such that pi = i. Your task is to count the number of almost identity permutations for given numbers...
import math nk=input().split() n=int(nk[0]) k=int(nk[1]) L=[0]*5 L[1]=1 L[2]=(n*(n-1))//2 L[3]=(n*(n-1)*(n-2))//3 L[4]=(3*n*(n-1)*(n-2)*(n-3))//8 s=0 for i in range(0,k+1): s+=L[i] print(s)
3Python3
{ "input": [ "4 2\n", "4 1\n", "5 4\n", "5 3\n", "1000 2\n", "400 4\n", "200 3\n", "400 3\n", "800 3\n", "200 1\n", "600 3\n", "200 2\n", "400 2\n", "800 4\n", "1000 4\n", "1000 1\n", "1000 3\n", "200 4\n", "400 1\n", "600 2\n", "800 ...
2CODEFORCES
888_D. Almost Identity Permutations_38331
A permutation p of size n is an array such that every integer from 1 to n occurs exactly once in this array. Let's call a permutation an almost identity permutation iff there exist at least n - k indices i (1 ≤ i ≤ n) such that pi = i. Your task is to count the number of almost identity permutations for given numbers...
import java.util.*; import java.io.*; import java.text.*; public class Solution{ static final long mod = (long)1e9+7, IINF = (long)1e17; static int MAX = (int)1e6+1; static FastReader in; static PrintWriter out; static boolean multipleTC = false; public static void main(String[] args) throws Ex...
4JAVA
{ "input": [ "4 2\n", "4 1\n", "5 4\n", "5 3\n", "1000 2\n", "400 4\n", "200 3\n", "400 3\n", "800 3\n", "200 1\n", "600 3\n", "200 2\n", "400 2\n", "800 4\n", "1000 4\n", "1000 1\n", "1000 3\n", "200 4\n", "400 1\n", "600 2\n", "800 ...
2CODEFORCES
911_B. Two Cakes_38332
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into a pieces, and the second one — into b pieces. Ivan knows that there will be n people at the celebration (including himself), so Ivan has set n plat...
n,a,b=map(int,raw_input().split()) for i in range(1,a+b): for j in range(1,n): if i * j <= a and i * (n - j) <= b: ans=i print ans
1Python2
{ "input": [ "4 7 10\n", "5 2 3\n", "5 2 8\n", "6 12 6\n", "5 5 8\n", "26 93 76\n", "8 7 10\n", "6 75 91\n", "12 97 13\n", "4 3 2\n", "3 2 5\n", "9 4 6\n", "4 5 1\n", "5 20 8\n", "3 9 9\n", "41 67 34\n", "2 1 1\n", "99 99 99\n", "2 90 95\n", ...
2CODEFORCES
911_B. Two Cakes_38333
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into a pieces, and the second one — into b pieces. Ivan knows that there will be n people at the celebration (including himself), so Ivan has set n plat...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int n, a, b; cin >> n >> a >> b; if (n == a + b) { cout << 1 << endl; return 0; } long long int val = 0; for (long long int i = 1; i < n; i++) { val = max(val, min(a / i, b / (n...
2C++
{ "input": [ "4 7 10\n", "5 2 3\n", "5 2 8\n", "6 12 6\n", "5 5 8\n", "26 93 76\n", "8 7 10\n", "6 75 91\n", "12 97 13\n", "4 3 2\n", "3 2 5\n", "9 4 6\n", "4 5 1\n", "5 20 8\n", "3 9 9\n", "41 67 34\n", "2 1 1\n", "99 99 99\n", "2 90 95\n", ...
2CODEFORCES
911_B. Two Cakes_38334
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into a pieces, and the second one — into b pieces. Ivan knows that there will be n people at the celebration (including himself), so Ivan has set n plat...
#problem 911b n,a,b=list(map(int,input().split())) print(max(min(a//i,b//(n-i)) for i in range(1,n)))
3Python3
{ "input": [ "4 7 10\n", "5 2 3\n", "5 2 8\n", "6 12 6\n", "5 5 8\n", "26 93 76\n", "8 7 10\n", "6 75 91\n", "12 97 13\n", "4 3 2\n", "3 2 5\n", "9 4 6\n", "4 5 1\n", "5 20 8\n", "3 9 9\n", "41 67 34\n", "2 1 1\n", "99 99 99\n", "2 90 95\n", ...
2CODEFORCES
911_B. Two Cakes_38335
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into a pieces, and the second one — into b pieces. Ivan knows that there will be n people at the celebration (including himself), so Ivan has set n plat...
import java.util.Scanner; public class a { public static void main(String args[]) { Scanner scan=new Scanner(System.in); int n=scan.nextInt(); int a=scan.nextInt(); int b=scan.nextInt(); //i+j==n int min=Integer.MIN_VALUE; for(int i=1;i<=n-1;i++) { //distribute a dishen on i playes and distrib...
4JAVA
{ "input": [ "4 7 10\n", "5 2 3\n", "5 2 8\n", "6 12 6\n", "5 5 8\n", "26 93 76\n", "8 7 10\n", "6 75 91\n", "12 97 13\n", "4 3 2\n", "3 2 5\n", "9 4 6\n", "4 5 1\n", "5 20 8\n", "3 9 9\n", "41 67 34\n", "2 1 1\n", "99 99 99\n", "2 90 95\n", ...
2CODEFORCES
932_G. Palindrome Partition_38336
Given a string s, find the number of ways to split s to substrings such that if there are k substrings (p1, p2, p3, ..., pk) in partition, then pi = pk - i + 1 for all i (1 ≤ i ≤ k) and k is even. Since the number of ways can be large, print it modulo 109 + 7. Input The only line of input contains a string s (2 ≤ |s...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; int n; char s[1000010], t[1000010]; struct PAM { struct node { int Next[26]; int fail; int len; int diff, anc; long long f; node(int _len = 0) { memset(Next, 0, sizeof Next); fail = 0; diff = anc = 0...
2C++
{ "input": [ "abcdcdab\n", "abbababababbab\n", "bacbccacaabbcbbbbaccbbbbacacaccbabaabccbaababccacacabbbbccabbbbcbbaacaccbcab\n", "bababcabaabbbaacacbcacaccaaccbbbcaccbccbaaacaccacaaabccbccacbbbccaaccacacbcacaabbbaabacbabab\n", "babbab\n", "cbaccbbabbabcbaacccabaabbbbabbcccaacccaaaaaaaaaacccaac...
2CODEFORCES
932_G. Palindrome Partition_38337
Given a string s, find the number of ways to split s to substrings such that if there are k substrings (p1, p2, p3, ..., pk) in partition, then pi = pk - i + 1 for all i (1 ≤ i ≤ k) and k is even. Since the number of ways can be large, print it modulo 109 + 7. Input The only line of input contains a string s (2 ≤ |s...
//package com.company; import java.io.*; import java.util.*; public class Main { public static class Task { public class EerTree { int s, cur; // total of suffix-palindrome nodes, index of current suffix-palindrome int N; // final string size, for initiation int n; // c...
4JAVA
{ "input": [ "abcdcdab\n", "abbababababbab\n", "bacbccacaabbcbbbbaccbbbbacacaccbabaabccbaababccacacabbbbccabbbbcbbaacaccbcab\n", "bababcabaabbbaacacbcacaccaaccbbbcaccbccbaaacaccacaaabccbccacbbbccaaccacacbcacaabbbaabacbabab\n", "babbab\n", "cbaccbbabbabcbaacccabaabbbbabbcccaacccaaaaaaaaaacccaac...
2CODEFORCES
95_B. Lucky Numbers_38338
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. Fo...
def find(ans,fours,sevens): global a if fours==sevens==0: if int(ans)>=a: print ans exit() return if fours>= 1: find(ans+'4', fours-1, sevens) if sevens >= 1: find(ans+'7', fours, sevens-1) a=input() t=(len(str(a))+1)/2 for digits in range(t,6): ...
1Python2
{ "input": [ "47\n", "4500\n", "73\n", "444000000\n", "447777\n", "3696\n", "12\n", "100\n", "1024\n", "123\n", "74777443\n", "1007\n", "4\n", "7748\n", "474\n", "74710000\n", "19\n", "70070077\n", "888999577\n", "2145226\n", "7474747...
2CODEFORCES
95_B. Lucky Numbers_38339
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. Fo...
#include <bits/stdc++.h> using namespace std; string func(int c4, int c7) { string res; while (c4--) res += '4'; while (c7--) res += '7'; return res; } int main() { string s; while (cin >> s) { int n = s.size(); if (n % 2 == 1) { cout << string((n + 1) / 2, '4') << string((n + 1) / 2, '7') << ...
2C++
{ "input": [ "47\n", "4500\n", "73\n", "444000000\n", "447777\n", "3696\n", "12\n", "100\n", "1024\n", "123\n", "74777443\n", "1007\n", "4\n", "7748\n", "474\n", "74710000\n", "19\n", "70070077\n", "888999577\n", "2145226\n", "7474747...
2CODEFORCES
95_B. Lucky Numbers_38340
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. Fo...
from itertools import permutations as p def ck(num,arr): for i in arr: if i>=num: print(i) return x = input() z = len(x) if z == 1: print(47) elif z == 2 : if int(x) <= 74: arr = [47,74] ck(int(x),arr) else: print(4477) elif z == 3: print(447...
3Python3
{ "input": [ "47\n", "4500\n", "73\n", "444000000\n", "447777\n", "3696\n", "12\n", "100\n", "1024\n", "123\n", "74777443\n", "1007\n", "4\n", "7748\n", "474\n", "74710000\n", "19\n", "70070077\n", "888999577\n", "2145226\n", "7474747...
2CODEFORCES
95_B. Lucky Numbers_38341
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. Fo...
import java.io.PrintWriter; import java.util.Scanner; public class B implements Runnable { private Scanner in; private PrintWriter out; private void solve() { char[] num = in.next().toCharArray(); int len = num.length; if (len % 2 == 1) { char[] min = new char[len + 1];...
4JAVA
{ "input": [ "47\n", "4500\n", "73\n", "444000000\n", "447777\n", "3696\n", "12\n", "100\n", "1024\n", "123\n", "74777443\n", "1007\n", "4\n", "7748\n", "474\n", "74710000\n", "19\n", "70070077\n", "888999577\n", "2145226\n", "7474747...
2CODEFORCES
986_F. Oppa Funcan Style Remastered_38342
Surely you have seen insane videos by South Korean rapper PSY, such as "Gangnam Style", "Gentleman" and "Daddy". You might also hear that PSY has been recording video "Oppa Funcan Style" two years ago (unfortunately we couldn't find it on the internet). We will remind you what this hit looked like (you can find origina...
#include <bits/stdc++.h> using namespace std; const int MX = 32000000; const long long INF = 1E18 + 7; vector<int> pr; map<long long, vector<long long>> fct, dst; int t; long long n, k; bool chk[MX]; struct SNode { long long u, val; }; inline bool operator<(const SNode &a, const SNode &b) { return a.val < b.val; } pr...
2C++
{ "input": [ "3\n7 7\n3 8\n5 6\n", "4\n1 1\n2 1\n1000000000 1\n1000000000000000000 1\n", "3\n7 3\n3 8\n5 6\n", "3\n7 3\n3 6\n5 6\n", "3\n7 3\n3 6\n5 11\n", "3\n7 3\n3 8\n5 2\n", "4\n1 1\n2 1\n1000000000 2\n1000000000000000000 1\n", "4\n1 1\n2 1\n1000000000 1\n1001000000000000000 1\n", ...
2CODEFORCES
986_F. Oppa Funcan Style Remastered_38343
Surely you have seen insane videos by South Korean rapper PSY, such as "Gangnam Style", "Gentleman" and "Daddy". You might also hear that PSY has been recording video "Oppa Funcan Style" two years ago (unfortunately we couldn't find it on the internet). We will remind you what this hit looked like (you can find origina...
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.InputMismatchException; import java.util.Random; import java.io.OutputStreamWriter; import java.math.BigInteger; import java.util.NoSuchElementException; import java.io.OutputStream; import jav...
4JAVA
{ "input": [ "3\n7 7\n3 8\n5 6\n", "4\n1 1\n2 1\n1000000000 1\n1000000000000000000 1\n", "3\n7 3\n3 8\n5 6\n", "3\n7 3\n3 6\n5 6\n", "3\n7 3\n3 6\n5 11\n", "3\n7 3\n3 8\n5 2\n", "4\n1 1\n2 1\n1000000000 2\n1000000000000000000 1\n", "4\n1 1\n2 1\n1000000000 1\n1001000000000000000 1\n", ...
2CODEFORCES
akbar-and-birbal-1_38344
This is the time of Akbar and Birbal. One day , in the state there happened some riots and murders .Akbar found some N people guilty in this matter.He called Birbal to punish them .Birbal gave them a unique punishment .He ordered the first person(guilty) to dig all the N spaces indicated on the ground.Then he called th...
import math for _ in xrange(input()): n = input() print (n - int(math.sqrt(n)))
1Python2
{ "input": [ "100\n1804246908\n846901785\n1681651770\n1714595508\n1957703548\n424217739\n719858557\n1649719876\n596492227\n1189606931\n1025170345\n1350453279\n783340703\n1102486856\n2044852544\n1967469571\n1365143593\n1540344180\n304071735\n1303419634\n34999296\n521572531\n294685402\n1726914874\n336447440\n860992...
3HACKEREARTH
building-network_38345
There are N routers. The cost of the wires required in connecting two routers, i and j, is R[i]+R[j] where R[i] is the number of slots in the i-th router and i!=j. You need to build a network, such that there is a path between every pair of routers. Find the minimum cost of building such a network.The connection betwee...
t=input() while t>0: n=input() arr=[] arr=map(int,raw_input().split()) brr=sorted(arr) l=len(brr) su=0 for i in range(1,l): a=brr[0]+brr[i] su=su+a print su t=t-1
1Python2
{ "input": [ "2\n2\n1 2\n3\n1 1 1\n\nSAMPLE", "5\n42\n18468 6335 26501 19170 15725 11479 29359 26963 24465 5706 28146 23282 16828 9962 492 2996 11943 4828 5437 32392 14605 3903 154 293 12383 17422 18717 19719 19896 5448 21727 14772 11539 1870 19913 25668 26300 17036 9895 28704 23812 31323 \n334\n17674 4665 15...
3HACKEREARTH
dawood-the-mathematician_38346
Dr.Dawood is another mathematician who is more geekier than Osama (that's why, ++). Dawood deals with more complex problems than Osama usually deals with. He also recruits people to be his sub-ordinates. He usually gives them "trivial" problems as test for them to solve and earn their position to be his sub-ordinate. ...
for i in range(0,int(input())): f =0 ans = 0 x = int(input()) while x%2 == 0: f = f+1 x= x/2 ans = pow(2,(f+1)) print(ans)
1Python2
{ "input": [ "4\n3\n1\n2\n5\n\nSAMPLE" ], "output": [ "2\n2\n4\n2" ] }
3HACKEREARTH
game-of-divisors_38347
Two players are playing the following game with a positive integer N. On his turn a player has to write down on paper some integer between 1 and N. But it's forbidden to write an integer which is a divisor of some number already written on paper. For example N = 8 and numbers already written are: 6, 4, 7. In this case ...
for i in range(input()): z=raw_input() print 1
1Python2
{ "input": [ "1\n3\n\nSAMPLE", "5\n6\n7\n8\n9\n10", "5\n6\n7\n8\n11\n10", "1\n3\n\nSAMPME", "5\n6\n7\n8\n18\n10", "5\n6\n7\n8\n18\n2", "5\n6\n14\n8\n18\n2", "5\n6\n14\n12\n18\n2", "5\n8\n14\n12\n18\n2", "5\n8\n14\n12\n8\n2", "5\n8\n1\n12\n8\n2", "5\n8\n1\n18\n8\n2", ...
3HACKEREARTH
karan-and-strings_38348
After the Tatvik Hiring Challenge, Karan's NLP professor has given him another homework. Since Manhattan Associates Hiring Challenge is round the corner and Karan is busy preparing for it, he turns to you for help. Given a string, replace all the consecutively occurring characters by a single, same character. Input: ...
t=int(raw_input()) i=0 while(i<t): s=raw_input() s1='' s1+=s[0] for j in s[1:]: if(j!=s1[-1]): s1+=j print(s1) i+=1
1Python2
{ "input": [ "1\naabbcc\n\nSAMPLE", "10\naabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\nabcdefghijklmnopqrstuvwxyz\n...............................aaaaaaaaaaaaaaaaaaaaaa\n....................,,,,,,,,,,,,,,,,,,,,,aaaaaaaaaaaaa\naaaaaaaaaaaaa.................dd...
3HACKEREARTH
mittal-wants-to-go-to-play_38349
Mittal lives in the Niti Colony. The colony has N houses numbered from 1 to N. There are M bidirectional roads in the colony for travelling between houses. There might be multiple roads between two houses. Mittal lives in the house with index 1. He has friends in all houses of the colony. He is always wanting to visi...
import heapq from bisect import bisect_left INF = 1 + 25 * 10**8 def dijkstra(G, n, s): dist = [INF] * (n+1) dist[s] = 0 heap = [] heapq.heappush(heap, (0,s)) while heap: d, u = heapq.heappop(heap) if dist[u] < d: continue for (v, w) in G[u]: if dis...
1Python2
{ "input": [ "1\n5 5\n1 2 2\n2 3 4\n3 4 5\n4 5 1\n1 4 7\n3\n4 20\n5 21\n3 5\n\nSAMPLE", "2\n2 2\n1 2 10\n1 2 2\n4\n2 45\n2 30\n2 11\n2 13\n3 6\n1 2 2\n2 3 4\n2 3 10\n2 3 4\n1 2 5\n2 3 6\n5\n3 20\n3 11\n3 46\n2 41\n3 50", "1\n5 5\n1 2 2\n2 3 4\n3 3 5\n4 5 1\n1 4 7\n3\n4 20\n5 21\n3 5\n\nSAMPLE", "2\n2 ...
3HACKEREARTH
panda-and-combination_38350
Panda loves solving problems which are deemed impossible by his fellow classmates. The current problem which he is working on is to express a number N as sum of powers of number X (Not necessarily distinct) such that the number of powers of number X used should be minimum. Note: The powers of a number can be 0, 1,...
for _ in xrange(input()): n,m=map(int,raw_input().split()) if(n<m or m==1): print n continue ans=0 while n>0: ans = ans + n%m n = n/m print ans
1Python2
{ "input": [ "3\n4 4\n5 3\n6 1\n\nSAMPLE", "3\n4 4\n2 3\n6 1\n\nSAMPLE", "3\n4 4\n2 3\n11 1\n\nSAMPLE", "3\n8 4\n2 3\n11 1\n\nSAMPLE", "3\n8 5\n2 3\n11 1\n\nSAMPKE", "3\n11 5\n2 3\n11 1\n\nSAMPKE", "3\n11 5\n2 3\n6 1\n\nSAMPKE", "3\n11 5\n3 3\n6 1\n\nSAMPKE", "3\n4 3\n5 3\n6 1\n\nS...
3HACKEREARTH
rod-cutting-problem-7_38351
A young mischievous boy Harsh, got into a trouble when his mechanical workshop teacher told him to cut Iron rods. The rod cutting algorithm is as follows: Step 1. If the rod can be divided into two equal parts, cut it and choose any one of them. Step 2. Else cut the rod into two parts having non-zero integral ...
def count_special(N): count = 0 prev = 0 curr = 3 while(curr <= N): prev = curr curr = 2*prev + 1 count += 1 return count T = int(raw_input()) for t in xrange(T): N = int(raw_input()) count = count_special(N) print count
1Python2
{ "input": [ "2\n3\n2\n\nSAMPLE", "10\n977\n543\n252\n979\n348\n889\n876\n55\n938\n610", "1000\n637440000\n497933618\n104308126\n54379600\n735895362\n146758511\n172457069\n786824866\n792402682\n2932951\n280042089\n190772473\n647479785\n613419369\n465129597\n173755079\n611820068\n311399952\n18559\n24425708...
3HACKEREARTH
steal-the-show_38352
It’s the company's 3^rd anniversary, and everyone is super-excited about it. There is a tradition in the company, that the interns decide the seating arrangement of all the members. The requirements of this order are: The CEO of the company must sit in the middle. (In case of even number of team members, he can sit on ...
#mod = 10**9 + 7 #test = int(raw_input()) #for i in range(test): ceo , coo , cto = [int(x) for x in raw_input().split()] n = int( raw_input() ) arr = [int(x) for x in raw_input().split()] arr.sort(reverse = True) res = [0 for i in range(n+3)] l = len(res) res[0] = min( coo , cto ) res[l-1] = max( coo , cto ) res[l/2] =...
1Python2
{ "input": [ "13 17 11\n2\n12 10\n\nSAMPLE", "80 82 81\n3\n50 90 65", "80 82 108\n3\n50 90 65", "13 17 11\n2\n12 15\n\nSAMPLE", "117 82 108\n3\n50 90 65", "13 17 11\n2\n12 2\n\nSAMPLE", "117 82 108\n3\n81 90 65", "13 17 11\n2\n19 2\n\nSAMPLE", "117 82 199\n3\n81 90 65", "13 17 ...
3HACKEREARTH
uncles-will-1_38353
Ramu’s uncle has left him a stable in his Will. But the stable is not in a good condition. The roofs leak and need to be repaired. There are a number of stalls in the stable. A stall may or may not contain a horse. Ramu has to buy new cement sheets to cover these stalls. He has to cover atleast all those stalls that h...
# /he/uncle's-will no_of_tc = input() for tc in range(no_of_tc) : line = raw_input() max_sheets = int(line.split(' ')[0]) total_stalls = int(line.split(' ')[1]) filled_stalls = int(line.split(' ')[2]) stall_map = [False] * total_stalls for i in range(filled_stalls) : stall_map[input() - 1] = True while stall_ma...
1Python2
{ "input": [ "1\n2 10 3\n2\n4\n10\n\nSAMPLE" ], "output": [ "4" ] }
3HACKEREARTH
p02586 AtCoder Beginner Contest 175 - Picking Goods_38354
There are K items placed on a grid of squares with R rows and C columns. Let (i, j) denote the square at the i-th row (1 \leq i \leq R) and the j-th column (1 \leq j \leq C). The i-th item is at (r_i, c_i) and has the value v_i. Takahashi will begin at (1, 1), the start, and get to (R, C), the goal. When he is at (i, ...
# -*- coding: utf-8 -*- import sys from collections import defaultdict R,C,K=map(int, sys.stdin.readline().split()) value=defaultdict(lambda: 0) value=[ [0 for _ in range(C+1)] for __ in range(R+1) ] for _ in range(K): r,c,v=map(int, sys.stdin.readline().split()) value[r][c]=v dp0=[0]*(C+1) dp1=[0]*(C+1) dp2=...
1Python2
{ "input": [ "2 5 5\n1 1 3\n2 4 20\n1 2 1\n1 3 4\n1 4 2", "2 2 3\n1 1 3\n2 1 4\n1 2 5", "4 5 10\n2 5 12\n1 5 12\n2 3 15\n1 2 20\n1 1 28\n2 4 26\n3 2 27\n4 5 21\n3 5 10\n1 3 10", "2 5 5\n1 1 3\n2 4 20\n2 2 1\n1 3 4\n1 4 2", "4 5 3\n2 5 12\n1 5 12\n2 3 15\n1 2 20\n1 1 28\n2 4 26\n3 2 27\n4 5 21\n3 5...
5ATCODER
p02586 AtCoder Beginner Contest 175 - Picking Goods_38355
There are K items placed on a grid of squares with R rows and C columns. Let (i, j) denote the square at the i-th row (1 \leq i \leq R) and the j-th column (1 \leq j \leq C). The i-th item is at (r_i, c_i) and has the value v_i. Takahashi will begin at (1, 1), the start, and get to (R, C), the goal. When he is at (i, ...
#include <bits/stdc++.h> #define maxn 3086 using namespace std; int n, m, k; int a[maxn][maxn]; int x, y, z; long long f[maxn][maxn][4]; inline void Max(long long &x, long long y){ x = max(x, y); } int main(){ scanf("%d%d%d", &n, &m, &k); while(k--){ scanf("%d%d%d", &x, &y, &z); a[x][y] = z; } memset(f, -0...
2C++
{ "input": [ "2 5 5\n1 1 3\n2 4 20\n1 2 1\n1 3 4\n1 4 2", "2 2 3\n1 1 3\n2 1 4\n1 2 5", "4 5 10\n2 5 12\n1 5 12\n2 3 15\n1 2 20\n1 1 28\n2 4 26\n3 2 27\n4 5 21\n3 5 10\n1 3 10", "2 5 5\n1 1 3\n2 4 20\n2 2 1\n1 3 4\n1 4 2", "4 5 3\n2 5 12\n1 5 12\n2 3 15\n1 2 20\n1 1 28\n2 4 26\n3 2 27\n4 5 21\n3 5...
5ATCODER
p02586 AtCoder Beginner Contest 175 - Picking Goods_38356
There are K items placed on a grid of squares with R rows and C columns. Let (i, j) denote the square at the i-th row (1 \leq i \leq R) and the j-th column (1 \leq j \leq C). The i-th item is at (r_i, c_i) and has the value v_i. Takahashi will begin at (1, 1), the start, and get to (R, C), the goal. When he is at (i, ...
import sys input = sys.stdin.readline R, C, k = map(int, input().split()) xs = [[0] * C for _ in range(R)] for _ in range(k): r, c, v = map(int, input().split()) xs[r - 1][c - 1] = v dp = [[[0] * (C + 1) for _ in range(R + 1)] for _ in range(4)] for i in range(R): for j in range(C): for k in range...
3Python3
{ "input": [ "2 5 5\n1 1 3\n2 4 20\n1 2 1\n1 3 4\n1 4 2", "2 2 3\n1 1 3\n2 1 4\n1 2 5", "4 5 10\n2 5 12\n1 5 12\n2 3 15\n1 2 20\n1 1 28\n2 4 26\n3 2 27\n4 5 21\n3 5 10\n1 3 10", "2 5 5\n1 1 3\n2 4 20\n2 2 1\n1 3 4\n1 4 2", "4 5 3\n2 5 12\n1 5 12\n2 3 15\n1 2 20\n1 1 28\n2 4 26\n3 2 27\n4 5 21\n3 5...
5ATCODER
p02586 AtCoder Beginner Contest 175 - Picking Goods_38357
There are K items placed on a grid of squares with R rows and C columns. Let (i, j) denote the square at the i-th row (1 \leq i \leq R) and the j-th column (1 \leq j \leq C). The i-th item is at (r_i, c_i) and has the value v_i. Takahashi will begin at (1, 1), the start, and get to (R, C), the goal. When he is at (i, ...
import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.InputMismatchException; import java.util.Iterator; import java.util.List; import java.util.NoSuchElementException; import java.util.stream.LongStream; public cla...
4JAVA
{ "input": [ "2 5 5\n1 1 3\n2 4 20\n1 2 1\n1 3 4\n1 4 2", "2 2 3\n1 1 3\n2 1 4\n1 2 5", "4 5 10\n2 5 12\n1 5 12\n2 3 15\n1 2 20\n1 1 28\n2 4 26\n3 2 27\n4 5 21\n3 5 10\n1 3 10", "2 5 5\n1 1 3\n2 4 20\n2 2 1\n1 3 4\n1 4 2", "4 5 3\n2 5 12\n1 5 12\n2 3 15\n1 2 20\n1 1 28\n2 4 26\n3 2 27\n4 5 21\n3 5...
5ATCODER
p02717 AtCoder Beginner Contest 161 - ABC Swap_38358
We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C C...
x, y, z = map(int, raw_input().split()) print(str(z)+" "+str(x)+" "+str(y))
1Python2
{ "input": [ "100 100 100", "41 59 31", "1 2 3", "000 100 100", "41 82 31", "2 2 3", "010 100 100", "41 82 46", "2 2 5", "010 000 100", "41 18 46", "2 2 7", "010 000 110", "41 5 46", "3 2 7", "010 010 110", "41 5 7", "3 2 12", "011 010 110", ...
5ATCODER
p02717 AtCoder Beginner Contest 161 - ABC Swap_38359
We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C C...
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll a,b,c; cin>>a>>b>>c; cout<<c<<" "<<a<<" "<<b; }
2C++
{ "input": [ "100 100 100", "41 59 31", "1 2 3", "000 100 100", "41 82 31", "2 2 3", "010 100 100", "41 82 46", "2 2 5", "010 000 100", "41 18 46", "2 2 7", "010 000 110", "41 5 46", "3 2 7", "010 010 110", "41 5 7", "3 2 12", "011 010 110", ...
5ATCODER
p02717 AtCoder Beginner Contest 161 - ABC Swap_38360
We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C C...
X, Y, Z = map(int,input().split()) print(Z, X, Y)
3Python3
{ "input": [ "100 100 100", "41 59 31", "1 2 3", "000 100 100", "41 82 31", "2 2 3", "010 100 100", "41 82 46", "2 2 5", "010 000 100", "41 18 46", "2 2 7", "010 000 110", "41 5 46", "3 2 7", "010 010 110", "41 5 7", "3 2 12", "011 010 110", ...
5ATCODER
p02717 AtCoder Beginner Contest 161 - ABC Swap_38361
We have three boxes A, B, and C, each of which contains an integer. Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively. We will now do the operations below in order. Find the content of each box afterward. * Swap the contents of the boxes A and B * Swap the contents of the boxes A and C C...
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int x = Integer.parseInt(sc.next()); int y = Integer.parseInt(sc.next()); int z = Integer.parseInt(sc.next()); System.out.println(z + " " + x + " " + y); } }
4JAVA
{ "input": [ "100 100 100", "41 59 31", "1 2 3", "000 100 100", "41 82 31", "2 2 3", "010 100 100", "41 82 46", "2 2 5", "010 000 100", "41 18 46", "2 2 7", "010 000 110", "41 5 46", "3 2 7", "010 010 110", "41 5 7", "3 2 12", "011 010 110", ...
5ATCODER
p02846 Sumitomo Mitsui Trust Bank Programming Contest 2019 - Interval Running_38362
Takahashi and Aoki are training for long-distance races in an infinitely long straight course running from west to east. They start simultaneously at the same point and moves as follows towards the east: * Takahashi runs A_1 meters per minute for the first T_1 minutes, then runs at A_2 meters per minute for the subse...
t1, t2 = map(int, raw_input().split(' ')) a1, a2 = map(int, raw_input().split(' ')) b1, b2 = map(int, raw_input().split(' ')) v1 = a1 * t1 + a2 * t2 v2 = b1 * t1 + b2 * t2 if v1 == v2: print('infinity') else: if(v1 < v2): v1, v2 = v2, v1 a1, a2, b1, b2 = b1, b2, a1, a2 lo = 0 hi = 10**100 ans = 0 while lo <= ...
1Python2
{ "input": [ "1 2\n10 10\n12 4", "100 1\n101 101\n102 1", "12000 15700\n3390000000 3810000000\n5550000000 2130000000", "1 2\n10 10\n12 5", "100 1\n111 101\n102 1", "100 2\n100 101\n102 1", "1 1\n1 20\n12 5", "100 2\n100 101\n102 0", "1 1\n2 20\n12 5", "100 2\n100 111\n102 0", ...
5ATCODER
p02846 Sumitomo Mitsui Trust Bank Programming Contest 2019 - Interval Running_38363
Takahashi and Aoki are training for long-distance races in an infinitely long straight course running from west to east. They start simultaneously at the same point and moves as follows towards the east: * Takahashi runs A_1 meters per minute for the first T_1 minutes, then runs at A_2 meters per minute for the subse...
#include <iostream> using namespace std; int main(void){ long long t1, t2, a1, a2, b1, b2, c1, c2; cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2; c1 = (a1 - b1) * t1; c2 = (a2 - b2) * t2; if(c1 < 0){ c1 *= -1; c2 *= -1; } if(c1+c2 == 0){ puts("infinity"); return 0...
2C++
{ "input": [ "1 2\n10 10\n12 4", "100 1\n101 101\n102 1", "12000 15700\n3390000000 3810000000\n5550000000 2130000000", "1 2\n10 10\n12 5", "100 1\n111 101\n102 1", "100 2\n100 101\n102 1", "1 1\n1 20\n12 5", "100 2\n100 101\n102 0", "1 1\n2 20\n12 5", "100 2\n100 111\n102 0", ...
5ATCODER
p02846 Sumitomo Mitsui Trust Bank Programming Contest 2019 - Interval Running_38364
Takahashi and Aoki are training for long-distance races in an infinitely long straight course running from west to east. They start simultaneously at the same point and moves as follows towards the east: * Takahashi runs A_1 meters per minute for the first T_1 minutes, then runs at A_2 meters per minute for the subse...
t = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) x = t[0] * (a[0] - b[0]) y = x + t[1] * (a[1] - b[1]) if x*y > 0: print(0) elif x*y == 0: print('infinity') elif abs(x) % abs(y) == 0: print(2 * (abs(x) // abs(y))) else: print(2 * (abs(x) // abs(y)) + 1)
3Python3
{ "input": [ "1 2\n10 10\n12 4", "100 1\n101 101\n102 1", "12000 15700\n3390000000 3810000000\n5550000000 2130000000", "1 2\n10 10\n12 5", "100 1\n111 101\n102 1", "100 2\n100 101\n102 1", "1 1\n1 20\n12 5", "100 2\n100 101\n102 0", "1 1\n2 20\n12 5", "100 2\n100 111\n102 0", ...
5ATCODER
p02846 Sumitomo Mitsui Trust Bank Programming Contest 2019 - Interval Running_38365
Takahashi and Aoki are training for long-distance races in an infinitely long straight course running from west to east. They start simultaneously at the same point and moves as follows towards the east: * Takahashi runs A_1 meters per minute for the first T_1 minutes, then runs at A_2 meters per minute for the subse...
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long t1 = sc.nextLong(); long t2 = sc.nextLong(); long a1 = sc.nextLong(); long a2 = sc.nextLong(); long b1 = sc.nextLong(); long b2 = sc.nextLong(); long sub1 = (a1 - b1) * t1...
4JAVA
{ "input": [ "1 2\n10 10\n12 4", "100 1\n101 101\n102 1", "12000 15700\n3390000000 3810000000\n5550000000 2130000000", "1 2\n10 10\n12 5", "100 1\n111 101\n102 1", "100 2\n100 101\n102 1", "1 1\n1 20\n12 5", "100 2\n100 101\n102 0", "1 1\n2 20\n12 5", "100 2\n100 111\n102 0", ...
5ATCODER
p02983 AtCoder Beginner Contest 133 - Remainder Minimization 2019_38366
You are given two non-negative integers L and R. We will choose two integers i and j such that L \leq i < j \leq R. Find the minimum possible value of (i \times j) \mbox{ mod } 2019. Constraints * All values in input are integers. * 0 \leq L < R \leq 2 \times 10^9 Input Input is given from Standard Input in the fol...
L,R=map(int, raw_input().split()) a=L%2019 b=R%2019 T=[] ans=float("inf") if a<b: T=range(a,b+1) if R-L>2018: print 0 quit() else: l=len(T) for i in range(l): for j in range(i+1,l): ans=min(ans, (T[i]*T[j])%2019 ) print ans else: print 0 quit()
1Python2
{ "input": [ "4 5", "2020 2040", "3 5", "4 10", "2020 3053", "1 5", "8 10", "2845 3053", "2 5", "6 8", "5 12", "9 10", "543 3053", "1 8", "1022 3053", "0 8", "1022 2650", "-1 8", "1022 4340", "-1 15", "0 15", "-2 15", "-4 15",...
5ATCODER
p02983 AtCoder Beginner Contest 133 - Remainder Minimization 2019_38367
You are given two non-negative integers L and R. We will choose two integers i and j such that L \leq i < j \leq R. Find the minimum possible value of (i \times j) \mbox{ mod } 2019. Constraints * All values in input are integers. * 0 \leq L < R \leq 2 \times 10^9 Input Input is given from Standard Input in the fol...
#include <bits/stdc++.h> using namespace std; int main() { long long l,r; cin >> l >> r; r = min(r,l+2019); int ans = 2018; for(long long i = l;i <= r;i++){ for(long long j = i+1;j <= r;j++){ int x = (i*j)%2019; ans = min(ans,x); } } cout << ans << endl; return 0; }
2C++
{ "input": [ "4 5", "2020 2040", "3 5", "4 10", "2020 3053", "1 5", "8 10", "2845 3053", "2 5", "6 8", "5 12", "9 10", "543 3053", "1 8", "1022 3053", "0 8", "1022 2650", "-1 8", "1022 4340", "-1 15", "0 15", "-2 15", "-4 15",...
5ATCODER
p02983 AtCoder Beginner Contest 133 - Remainder Minimization 2019_38368
You are given two non-negative integers L and R. We will choose two integers i and j such that L \leq i < j \leq R. Find the minimum possible value of (i \times j) \mbox{ mod } 2019. Constraints * All values in input are integers. * 0 \leq L < R \leq 2 \times 10^9 Input Input is given from Standard Input in the fol...
l,r = map(int,input().split()) r = min(r, l+4038) ans = 2018 for i in range(l,r): for j in range(l+1,r+1): if ans > i*j%2019: ans = i*j%2019 print(ans)
3Python3
{ "input": [ "4 5", "2020 2040", "3 5", "4 10", "2020 3053", "1 5", "8 10", "2845 3053", "2 5", "6 8", "5 12", "9 10", "543 3053", "1 8", "1022 3053", "0 8", "1022 2650", "-1 8", "1022 4340", "-1 15", "0 15", "-2 15", "-4 15",...
5ATCODER
p02983 AtCoder Beginner Contest 133 - Remainder Minimization 2019_38369
You are given two non-negative integers L and R. We will choose two integers i and j such that L \leq i < j \leq R. Find the minimum possible value of (i \times j) \mbox{ mod } 2019. Constraints * All values in input are integers. * 0 \leq L < R \leq 2 \times 10^9 Input Input is given from Standard Input in the fol...
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int l=sc.nextInt(),r=sc.nextInt(); sc.close(); if(r-l>=2018) System.out.println(0); else { long min=2018; for(int i=l;i<r;i++) { for(int j=i+1;j<=r;j++) { long temp =(long...
4JAVA
{ "input": [ "4 5", "2020 2040", "3 5", "4 10", "2020 3053", "1 5", "8 10", "2845 3053", "2 5", "6 8", "5 12", "9 10", "543 3053", "1 8", "1022 3053", "0 8", "1022 2650", "-1 8", "1022 4340", "-1 15", "0 15", "-2 15", "-4 15",...
5ATCODER
p03125 AtCoder Beginner Contest 118 - B +/- A_38370
You are given positive integers A and B. If A is a divisor of B, print A + B; otherwise, print B - A. Constraints * All values in input are integers. * 1 \leq A \leq B \leq 20 Input Input is given from Standard Input in the following format: A B Output If A is a divisor of B, print A + B; otherwise, print B -...
#!/usr/bin/env python2 """ This file is part of https://github.com/cheran-senthil/PyRival Copyright 2019 Cheran Senthilkumar <hello@cheran.io> """ from __future__ import division, print_function import itertools import os import sys from atexit import register from io import BytesIO class dict(dict): """dict() ...
1Python2
{ "input": [ "4 12", "8 20", "1 1", "1 12", "4 20", "1 0", "1 2", "4 24", "1 -1", "6 24", "6 36", "6 10", "6 17", "6 32", "5 32", "5 52", "5 10", "2 16", "1 16", "3 19", "5 19", "4 28", "8 28", "22 28", "22 14", "1...
5ATCODER
p03125 AtCoder Beginner Contest 118 - B +/- A_38371
You are given positive integers A and B. If A is a divisor of B, print A + B; otherwise, print B - A. Constraints * All values in input are integers. * 1 \leq A \leq B \leq 20 Input Input is given from Standard Input in the following format: A B Output If A is a divisor of B, print A + B; otherwise, print B -...
#include <bits/stdc++.h> int main() { int a, b; scanf("%d%d", &a, &b); if (b % a == 0) printf("%d\n", a+b); else printf("%d\n", b-a); }
2C++
{ "input": [ "4 12", "8 20", "1 1", "1 12", "4 20", "1 0", "1 2", "4 24", "1 -1", "6 24", "6 36", "6 10", "6 17", "6 32", "5 32", "5 52", "5 10", "2 16", "1 16", "3 19", "5 19", "4 28", "8 28", "22 28", "22 14", "1...
5ATCODER
p03125 AtCoder Beginner Contest 118 - B +/- A_38372
You are given positive integers A and B. If A is a divisor of B, print A + B; otherwise, print B - A. Constraints * All values in input are integers. * 1 \leq A \leq B \leq 20 Input Input is given from Standard Input in the following format: A B Output If A is a divisor of B, print A + B; otherwise, print B -...
a,b = list(map(int,input().split())) print(a+b if b%a == 0 else b-a)
3Python3
{ "input": [ "4 12", "8 20", "1 1", "1 12", "4 20", "1 0", "1 2", "4 24", "1 -1", "6 24", "6 36", "6 10", "6 17", "6 32", "5 32", "5 52", "5 10", "2 16", "1 16", "3 19", "5 19", "4 28", "8 28", "22 28", "22 14", "1...
5ATCODER
p03125 AtCoder Beginner Contest 118 - B +/- A_38373
You are given positive integers A and B. If A is a divisor of B, print A + B; otherwise, print B - A. Constraints * All values in input are integers. * 1 \leq A \leq B \leq 20 Input Input is given from Standard Input in the following format: A B Output If A is a divisor of B, print A + B; otherwise, print B -...
import java.util.Scanner; //import java.util.Arrays; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int a = sc.nextInt(); int b = sc.nextInt(); System.out.println(b % a == 0 ? a + b : b - a); } }
4JAVA
{ "input": [ "4 12", "8 20", "1 1", "1 12", "4 20", "1 0", "1 2", "4 24", "1 -1", "6 24", "6 36", "6 10", "6 17", "6 32", "5 32", "5 52", "5 10", "2 16", "1 16", "3 19", "5 19", "4 28", "8 28", "22 28", "22 14", "1...
5ATCODER
p03267 AtCoder Beginner Contest 108 - All Your Paths are Different Lengths_38374
You are given an integer L. Construct a directed graph that satisfies the conditions below. The graph may contain multiple edges between the same pair of vertices. It can be proved that such a graph always exists. * The number of vertices, N, is at most 20. The vertices are given ID numbers from 1 to N. * The number o...
l = input() k = 0 while 2 ** (k + 1) <= l: k += 1 n = k + 1 e = [] for i in range(k): e.append((i + 1, i + 2, 0)) e.append((i + 1, i + 2, 2 ** i)) for i in range(k): if l >> i & 1: e.append((i + 1, n, (l - 1) >> (i + 1) << (i + 1))) print n, len(e) for x, y, z in e: print x, y, z
1Python2
{ "input": [ "4", "5", "8", "2", "1", "9", "6", "3", "10", "17", "18", "33", "16", "12", "20", "40", "36", "32", "65", "24", "34", "66", "48", "68", "72", "129", "64", "130", "136", "80", "160",...
5ATCODER
p03267 AtCoder Beginner Contest 108 - All Your Paths are Different Lengths_38375
You are given an integer L. Construct a directed graph that satisfies the conditions below. The graph may contain multiple edges between the same pair of vertices. It can be proved that such a graph always exists. * The number of vertices, N, is at most 20. The vertices are given ID numbers from 1 to N. * The number o...
#include <cstdio> int main(){ int L,min=233,ans=0; scanf("%d",&L); for (int i=0;i<20;i++) if ((1<<i)&L) min=i,ans++; ans+=min*2; if (min==19) ans--; printf("20 %d\n",ans); for (int i=1;i<=min;i++) printf("%d %d %d\n%d %d %d\n",i,i+1,0,i,i+1,1<<i-1); int x=min==19?524288:0; for (int i=0;i<19;i++) if (1<<i&L) prin...
2C++
{ "input": [ "4", "5", "8", "2", "1", "9", "6", "3", "10", "17", "18", "33", "16", "12", "20", "40", "36", "32", "65", "24", "34", "66", "48", "68", "72", "129", "64", "130", "136", "80", "160",...
5ATCODER
p03267 AtCoder Beginner Contest 108 - All Your Paths are Different Lengths_38376
You are given an integer L. Construct a directed graph that satisfies the conditions below. The graph may contain multiple edges between the same pair of vertices. It can be proved that such a graph always exists. * The number of vertices, N, is at most 20. The vertices are given ID numbers from 1 to N. * The number o...
#解説参照 l=int(input()) r=0 while 2**(r+1)<=l: r+=1 n=r+1 ans=[] for i in range(r): ans.append((i+1,i+2,0)) ans.append((i+1,i+2,2**i)) for t in range(n-1,0,-1): if l-2**(t-1)>=2**r: ans.append((t,n,l-2**(t-1))) l-=2**(t-1) print(n,len(ans)) for a in ans: print(*a)
3Python3
{ "input": [ "4", "5", "8", "2", "1", "9", "6", "3", "10", "17", "18", "33", "16", "12", "20", "40", "36", "32", "65", "24", "34", "66", "48", "68", "72", "129", "64", "130", "136", "80", "160",...
5ATCODER
p03267 AtCoder Beginner Contest 108 - All Your Paths are Different Lengths_38377
You are given an integer L. Construct a directed graph that satisfies the conditions below. The graph may contain multiple edges between the same pair of vertices. It can be proved that such a graph always exists. * The number of vertices, N, is at most 20. The vertices are given ID numbers from 1 to N. * The number o...
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { public static class Edge { public int src, dst, length; public Edge(int src, int dst, int length) { this.src = src; this.dst = dst; this.length = length; } } public static void main(String[] args) { S...
4JAVA
{ "input": [ "4", "5", "8", "2", "1", "9", "6", "3", "10", "17", "18", "33", "16", "12", "20", "40", "36", "32", "65", "24", "34", "66", "48", "68", "72", "129", "64", "130", "136", "80", "160",...
5ATCODER
p03425 AtCoder Beginner Contest 089 - March_38378
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choo...
from collections import Counter from itertools import combinations N = int(raw_input()) c = Counter(raw_input()[0] for _ in range(N)) ans = 0 for (l1, l2, l3) in combinations("MARCH", 3): ans += c[l1] * c[l2] * c[l3] print(ans)
1Python2
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ", "5\nMASHIKE\nRUMOI\nOBIRA\nOROBAH\nHOROKANAI", "5\nCHOKUD@I\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZY\nZZZ\nZ\nZZZZZZZZZZ", "5\nDHOKUD@I\nRNG\nMAKOTO\nAOKI\nRINGN", ...
5ATCODER
p03425 AtCoder Beginner Contest 089 - March_38379
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choo...
#include <bits/stdc++.h> using namespace std; int main(){ int n; cin>>n; string s; long long int a[5]={}; string march="MARCH"; for(int i=0;i<n;i++){ cin>>s; for(int j=0;j<5;j++) if(s.at(0)==march[j]) a[j]++; } long long int ans=0; for(int i=0;i<3;i++) for(int j=...
2C++
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ", "5\nMASHIKE\nRUMOI\nOBIRA\nOROBAH\nHOROKANAI", "5\nCHOKUD@I\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZY\nZZZ\nZ\nZZZZZZZZZZ", "5\nDHOKUD@I\nRNG\nMAKOTO\nAOKI\nRINGN", ...
5ATCODER
p03425 AtCoder Beginner Contest 089 - March_38380
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choo...
import itertools N = int(input()) # N=10^5 count={} for i in range(N): c = input()[0] count[c] = count.get(c, 0)+1 s = 0 for a,b,c in itertools.combinations("MARCH", 3): s += count.get(a,0)*count.get(b,0)*count.get(c,0) print(s)
3Python3
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ", "5\nMASHIKE\nRUMOI\nOBIRA\nOROBAH\nHOROKANAI", "5\nCHOKUD@I\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZY\nZZZ\nZ\nZZZZZZZZZZ", "5\nDHOKUD@I\nRNG\nMAKOTO\nAOKI\nRINGN", ...
5ATCODER
p03425 AtCoder Beginner Contest 089 - March_38381
There are N people. The name of the i-th person is S_i. We would like to choose three people so that the following conditions are met: * The name of every chosen person begins with `M`, `A`, `R`, `C` or `H`. * There are no multiple people whose names begin with the same letter. How many such ways are there to choo...
import java.util.HashMap; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); HashMap<String,Long> namelist = new HashMap<>(); String s = "MARCH"; for(int i = 0;i<s.length();i++){ ...
4JAVA
{ "input": [ "5\nMASHIKE\nRUMOI\nOBIRA\nHABORO\nHOROKANAI", "5\nCHOKUDAI\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZZ\nZZZ\nZ\nZZZZZZZZZZ", "5\nMASHIKE\nRUMOI\nOBIRA\nOROBAH\nHOROKANAI", "5\nCHOKUD@I\nRNG\nMAKOTO\nAOKI\nRINGO", "4\nZY\nZZZ\nZ\nZZZZZZZZZZ", "5\nDHOKUD@I\nRNG\nMAKOTO\nAOKI\nRINGN", ...
5ATCODER
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift_38382
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exact...
x, y, z = map(int, raw_input().split()) a = ['a'] * x + ['b'] * y + ['c'] * z while len(a) > 1: a = sorted(a[1:-1] + [a[0] + a[-1]]) print a[0]
1Python2
{ "input": [ "2 2 0", "1 1 1", "2 1 0", "1 1 0", "0 2 0", "1 0 1", "2 0 0", "1 0 0", "2 2 1", "2 0 1", "3 2 0", "3 0 1", "3 3 0", "3 1 1", "6 3 0", "2 1 1", "6 3 1", "4 1 1", "6 3 2", "4 2 1", "6 0 2", "5 2 1", "6 0 1", "7...
5ATCODER
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift_38383
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exact...
#include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<cstdlib> #include<algorithm> #include<set> using namespace std; #define REP(i,st,ed) for(int i=st,i##end=ed;i<=i##end;++i) #define DREP(i,st,ed) for(int i=st,i##end=ed;i>=i##end;--i) multiset<string>s; multiset<string>::iterator it1,it2; int...
2C++
{ "input": [ "2 2 0", "1 1 1", "2 1 0", "1 1 0", "0 2 0", "1 0 1", "2 0 0", "1 0 0", "2 2 1", "2 0 1", "3 2 0", "3 0 1", "3 3 0", "3 1 1", "6 3 0", "2 1 1", "6 3 1", "4 1 1", "6 3 2", "4 2 1", "6 0 2", "5 2 1", "6 0 1", "7...
5ATCODER
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift_38384
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exact...
a,b,c = map(int,input().split()) L = [[0] for _ in range(a)] + [[1] for _ in range(b)] + [[2] for _ in range(c)] while len(L) > 1: L[0] += L.pop() L.sort() print(''.join(('a','b','c')[i] for i in L[0]))
3Python3
{ "input": [ "2 2 0", "1 1 1", "2 1 0", "1 1 0", "0 2 0", "1 0 1", "2 0 0", "1 0 0", "2 2 1", "2 0 1", "3 2 0", "3 0 1", "3 3 0", "3 1 1", "6 3 0", "2 1 1", "6 3 1", "4 1 1", "6 3 2", "4 2 1", "6 0 2", "5 2 1", "6 0 1", "7...
5ATCODER
p03582 CODE FESTIVAL 2017 qual B - Largest Smallest Cyclic Shift_38385
For a string S, let f(S) be the lexicographically smallest cyclic shift of S. For example, if S = `babca`, f(S) = `ababc` because this is the smallest among all cyclic shifts (`babca`, `abcab`, `bcaba`, `cabab`, `ababc`). You are given three integers X, Y, and Z. You want to construct a string T that consists of exact...
// package other2017.codefestival2017.qualb; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class Main { public static void main(String[] args) { InputReader in = new InputReader(System.in); ...
4JAVA
{ "input": [ "2 2 0", "1 1 1", "2 1 0", "1 1 0", "0 2 0", "1 0 1", "2 0 0", "1 0 0", "2 2 1", "2 0 1", "3 2 0", "3 0 1", "3 3 0", "3 1 1", "6 3 0", "2 1 1", "6 3 1", "4 1 1", "6 3 2", "4 2 1", "6 0 2", "5 2 1", "6 0 1", "7...
5ATCODER
p03739 AtCoder Beginner Contest 059 - Sequence_38386
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
n = input() l = map(int, raw_input().split()) lastPos, lastNeg = l[0], l[0] countPos, countNeg = 0, 0 if(lastPos<=0): countPos = 1 - lastPos lastPos = 1 if(lastNeg>=0): countNeg = lastNeg+1 lastNeg = -1 for i in xrange(1,n): if(lastPos>0): #now it has to be negative if(lastPos+l[i...
1Python2
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4", "5\n3 -6 4 -8 7", "4\n1 -3 1 -1", "6\n-1 4 3 2 -5 0", "4\n1 -5 1 -1", "6\n-1 4 2 2 -5 0", "5\n3 -8 4 -12 7", "4\n1 -5 0 -1", "6\n-1 4 1 2 -5 0", "5\n3 -5 4 -12 7", "6\n-1 8 1 2 -5 0", "6\n-1 8 2 2...
5ATCODER
p03739 AtCoder Beginner Contest 059 - Sequence_38387
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
#include<iostream> #include<vector> #include<algorithm> #include<cmath> using namespace std; int main(){ int n; cin >> n; vector<long> a(n); for(int i=0;i<n;i++) cin >> a[i]; long odd=0,even=0,sum=0; for(int i=0;i<n;i++){ //+- sum+=a[i]; if(i%2==0&&sum<=0){ odd+=abs(sum)+1; su...
2C++
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4", "5\n3 -6 4 -8 7", "4\n1 -3 1 -1", "6\n-1 4 3 2 -5 0", "4\n1 -5 1 -1", "6\n-1 4 2 2 -5 0", "5\n3 -8 4 -12 7", "4\n1 -5 0 -1", "6\n-1 4 1 2 -5 0", "5\n3 -5 4 -12 7", "6\n-1 8 1 2 -5 0", "6\n-1 8 2 2...
5ATCODER
p03739 AtCoder Beginner Contest 059 - Sequence_38388
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
n=int(input()) a=list(map(int,input().split())) u=0 s=1 x=0 y=0 for i in a: u+=i if s*u<=0: x+=1-s*u u=s s=s*(-1) s=-1 u=0 for i in a: u+=i if s*u<=0: y+=1-s*u u=s s=-1*s print(min(x,y))
3Python3
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4", "5\n3 -6 4 -8 7", "4\n1 -3 1 -1", "6\n-1 4 3 2 -5 0", "4\n1 -5 1 -1", "6\n-1 4 2 2 -5 0", "5\n3 -8 4 -12 7", "4\n1 -5 0 -1", "6\n-1 4 1 2 -5 0", "5\n3 -5 4 -12 7", "6\n-1 8 1 2 -5 0", "6\n-1 8 2 2...
5ATCODER
p03739 AtCoder Beginner Contest 059 - Sequence_38389
You are given an integer sequence of length N. The i-th term in the sequence is a_i. In one operation, you can select a term and either increment or decrement it by one. At least how many operations are necessary to satisfy the following conditions? * For every i (1≤i≤n), the sum of the terms from the 1-st through i-...
import java.nio.charset.IllegalCharsetNameException; import java.util.*; import java.lang.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = sc.nextLong(); } long oddsum...
4JAVA
{ "input": [ "5\n3 -6 4 -5 7", "4\n1 -3 1 0", "6\n-1 4 3 2 -5 4", "5\n3 -6 4 -8 7", "4\n1 -3 1 -1", "6\n-1 4 3 2 -5 0", "4\n1 -5 1 -1", "6\n-1 4 2 2 -5 0", "5\n3 -8 4 -12 7", "4\n1 -5 0 -1", "6\n-1 4 1 2 -5 0", "5\n3 -5 4 -12 7", "6\n-1 8 1 2 -5 0", "6\n-1 8 2 2...
5ATCODER
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!_38390
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneou...
#include <bits/stdc++.h> #define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i)) #define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i)) #define rep(i, n) For((i), 0, (n)) #define rrep(i, n) rFor((i), (n), 0) #define fi first #define se second using namespace std; typedef long long lint; typedef uns...
2C++
{ "input": [ "6\n40", "101\n80", "3\n100", "6\n36", "101\n141", "3\n101", "6\n38", "101\n233", "3\n111", "6\n59", "101\n416", "3\n001", "6\n106", "101\n221", "3\n011", "6\n174", "101\n27", "3\n010", "6\n95", "101\n37", "3\n110", "...
5ATCODER
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!_38391
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneou...
#!/usr/bin/env python3 import math x = int(input()) p = int(input())/100 print(math.ceil(x / 2) / p)
3Python3
{ "input": [ "6\n40", "101\n80", "3\n100", "6\n36", "101\n141", "3\n101", "6\n38", "101\n233", "3\n111", "6\n59", "101\n416", "3\n001", "6\n106", "101\n221", "3\n011", "6\n174", "101\n27", "3\n010", "6\n95", "101\n37", "3\n110", "...
5ATCODER
p03901 CODE FESTIVAL 2016 Elimination Tournament Round 2 (Parallel) - Takahashi is Missing!_38392
Aoki is in search of Takahashi, who is missing in a one-dimentional world. Initially, the coordinate of Aoki is 0, and the coordinate of Takahashi is known to be x, but his coordinate afterwards cannot be known to Aoki. Time is divided into turns. In each turn, Aoki and Takahashi take the following actions simultaneou...
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.*; class Main{ static void solve(){ int x = ni(); double p = ni()/100.0; double ans = 0; if(x%2==0)ans=(double)x/(2*p); else{ ans=1; ans += (x-1)/2; ans += ((1-p)*((double)x+1))/(p*2); } ...
4JAVA
{ "input": [ "6\n40", "101\n80", "3\n100", "6\n36", "101\n141", "3\n101", "6\n38", "101\n233", "3\n111", "6\n59", "101\n416", "3\n001", "6\n106", "101\n221", "3\n011", "6\n174", "101\n27", "3\n010", "6\n95", "101\n37", "3\n110", "...
5ATCODER
p00007 Debt Hell_38393
Your friend who lives in undisclosed country is involved in debt. He is borrowing 100,000-yen from a loan shark. The loan shark adds 5% interest of the debt and rounds it to the nearest 1,000 above week by week. Write a program which computes the amount of the debt in n weeks. Input An integer n (0 ≤ n ≤ 100) is g...
#encoding=utf-8 inp = input() x = 100000 for i in xrange(inp): x = x * 1.05 if int(x % 1000) != 0: x += 1000 - int(x % 1000) print int(x)
1Python2
{ "input": [ "5", "1", "4", "2", "3", "8", "11", "10", "7", "6", "12", "14", "9", "19", "16", "15", "13", "23", "32", "58", "99", "34", "54", "35", "40", "67", "41", "62", "49", "24", "17", ...
6AIZU
p00007 Debt Hell_38394
Your friend who lives in undisclosed country is involved in debt. He is borrowing 100,000-yen from a loan shark. The loan shark adds 5% interest of the debt and rounds it to the nearest 1,000 above week by week. Write a program which computes the amount of the debt in n weeks. Input An integer n (0 ≤ n ≤ 100) is g...
#include <stdio.h> #include <string.h> int main(){ int n; scanf("%d", &n); int m = 100000; for(int i=0;i<n;i++){ m *= 1.05; if(m%1000 != 0) m = (m/1000+1)*1000; } printf("%d\n", m); }
2C++
{ "input": [ "5", "1", "4", "2", "3", "8", "11", "10", "7", "6", "12", "14", "9", "19", "16", "15", "13", "23", "32", "58", "99", "34", "54", "35", "40", "67", "41", "62", "49", "24", "17", ...
6AIZU
p00007 Debt Hell_38395
Your friend who lives in undisclosed country is involved in debt. He is borrowing 100,000-yen from a loan shark. The loan shark adds 5% interest of the debt and rounds it to the nearest 1,000 above week by week. Write a program which computes the amount of the debt in n weeks. Input An integer n (0 ≤ n ≤ 100) is g...
import math n = int(input()) a = 100000 for _ in range(n): a *= 1.05 a = 1000 * math.ceil(a / 1000) print(a)
3Python3
{ "input": [ "5", "1", "4", "2", "3", "8", "11", "10", "7", "6", "12", "14", "9", "19", "16", "15", "13", "23", "32", "58", "99", "34", "54", "35", "40", "67", "41", "62", "49", "24", "17", ...
6AIZU
p00007 Debt Hell_38396
Your friend who lives in undisclosed country is involved in debt. He is borrowing 100,000-yen from a loan shark. The loan shark adds 5% interest of the debt and rounds it to the nearest 1,000 above week by week. Write a program which computes the amount of the debt in n weeks. Input An integer n (0 ≤ n ≤ 100) is g...
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s=new Scanner(System.in); int n=s.nextInt(); double ans=100000; for(int i=0;i<n;i++){ ans=ans*1.05; if(ans%1000!=0){ ans=ans+1000-ans%1000; } } int a=(int)ans; System.out.println(a); } }
4JAVA
{ "input": [ "5", "1", "4", "2", "3", "8", "11", "10", "7", "6", "12", "14", "9", "19", "16", "15", "13", "23", "32", "58", "99", "34", "54", "35", "40", "67", "41", "62", "49", "24", "17", ...
6AIZU
p00139 Snakes_38397
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends w...
import re snakeA = re.compile('>\'(=+)#\\1~$') snakeB = re.compile('>\^(Q=)+~~$') for i in xrange(input()): s = raw_input() if snakeA.match(s) is not None: print "A" elif snakeB.match(s) is not None: print "B" else: print "NA"
1Python2
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~", "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#===>~", "3\n>'======#======~\n>QQ=^=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#===>~", "3\n>(======#======~\n~~=Q=Q=Q=Q=Q=Q=Q=^=QQ>\n>'===#==~>=", "3\n>'======#======~\n>QQ=^=Q=Q=Q=Q=Q=Q=Q=~~\...
6AIZU
p00139 Snakes_38398
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends w...
#include<iostream> #include<regex> #include<string> int main() { int n; std::cin >> n; std::cin.ignore(); while( n-- ) { std::string s; std::getline( std::cin, s ); std::smatch m; if( std::regex_match( s, m, std::regex( ">\'(=+)#(=+)~" ) ) && m[1].length() == m[2].length() ) std::cout << 'A' << std::...
2C++
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~", "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#===>~", "3\n>'======#======~\n>QQ=^=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#===>~", "3\n>(======#======~\n~~=Q=Q=Q=Q=Q=Q=Q=^=QQ>\n>'===#==~>=", "3\n>'======#======~\n>QQ=^=Q=Q=Q=Q=Q=Q=Q=~~\...
6AIZU
p00139 Snakes_38399
In a world, a mysterious snake made of only letters lives. Two types of snakes are currently identified, type A and type B, but there may be other types as well. For class A, after ">'" is followed by one or more "=", "#" comes, and after the same number of "=" as before, "~" (half-width tilde) finish. Class B ends w...
import re SNAKE_A = re.compile(r">'(=+)#\1~") SNAKE_B = re.compile(r">\^(Q=)+~~") def answer(regex, string, output): result = regex.fullmatch(string) if result is not None: print(output) else: print("NA") for _ in range(int(input())): snake = input() if snake[1] == "'": ...
3Python3
{ "input": [ "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#====~", "3\n>'======#======~\n>^Q=Q=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#===>~", "3\n>'======#======~\n>QQ=^=Q=Q=Q=Q=Q=Q=Q=~~\n>'===#===>~", "3\n>(======#======~\n~~=Q=Q=Q=Q=Q=Q=Q=^=QQ>\n>'===#==~>=", "3\n>'======#======~\n>QQ=^=Q=Q=Q=Q=Q=Q=Q=~~\...
6AIZU