input
stringlengths
29
13k
output
stringlengths
9
73.4k
Problem description Tris (or as her parents call her Beatrice) is going through a series of training and evaluation to get into top 10 and remain in Dauntless Faction. She is currently placed 12th and will become faction-less if she fails, today. Four (or Tobias) gives Tris a string, consisting of 'i'(s) and 'd'(s) on...
for t in xrange(int(raw_input())): s = raw_input() count = 0 start = 0 for c in s: if c=='i': start += 1 else: start -= 1 if (start<0): start = 0 count += 1 print count, start
So, you are bored and you think about playing a game. The game is like, if you win your money will be doubled and eleven dollars extra will be added to it. If you lose, your money will be halved (if the amount is odd, it will be halved to the upper integer). The inital amount of money you have is 'X'. A sequence of ...
import math x = input() z = raw_input() l = len(z) for y in xrange(l): if z[y]=="W": x*=2 x+=11 else: x = int(math.ceil(x/float(2))) print x
Three numbers A, B and C are the inputs. Write a program to find second largest among three numbers. Input The first line contains an integer T, total number of testcases. Then follow T lines, each line contains three integers A, B and C. Output Display the second largest among A, B and C. Constraints 1 ≤ T ≤ 100...
n=input() for i in range(n): a=raw_input() s=str(a).split() s=[int(s[0]),int(s[1]),int(s[2])] s.sort () print s[1]
On the eve of Republic Day, Teacher decided to distribute candies among N students.She brought the candies in a box and placed it in front of students. She allowed every student to take out some candies. But each one of them tried to take out as much candies as possible. That's why, Not all students were happy. She c...
T = int(raw_input()) for t in range(T): tot =0 n = int(raw_input()) a = map(int,raw_input().split()) m = sum(a) if m%n!=0: print -1 else: for i in range(n): if abs(a[i]-m//n) >0: tot += abs(a[i]-m//n) print tot
Chef Datta likes betting in Indian Premier League very much. He has 10000 rupees. Today the match is between team A and team B. The winning probability of team A is PA, and hence winning probability of team B is PB = 1 − PA. Datta is free to bet any integral amount of money on any of the two teams as long as the total...
''' Predictopus Problem code: PREDICT Chef Datta likes betting in Indian Premier League very much. He has 10000 rupees. Today the match is between team A and team B. The winning probability of team A is PA, and hence winning probability of team B is PB = 1 - PA. Datta is free to bet any integral amount of money on ...
[Chopsticks (singular: chopstick) are short, frequently tapered sticks used in pairs of equal length, which are used as the traditional eating utensils of China, Japan, Korea and Vietnam. Originated in ancient China, they can also be found in some areas of Tibet and Nepal that are close to Han Chinese populations, as w...
arr=raw_input().split(" ") n=int(arr[0]) d=int(arr[1]) inte=[] count=0 for i in range(n): inte.append(int(raw_input())) inte.sort() #print inte i=0 while i<n-1: if (inte[i+1]-inte[i])<=d: count+=1 i+=2 else: i+=1 print count
Natasha travels around Mars in the Mars rover. But suddenly it broke down, namely — the logical scheme inside it. The scheme is an undirected tree (connected acyclic graph) with a root in the vertex 1, in which every leaf (excluding root) is an input, and all other vertices are logical elements, including the root, whi...
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") vector<int> op; vector<vector<int>> v; vector<bool> val; int mp[1000001][2]; vector<int> saved; vector<int> cur; vector<pa...
Little D is a friend of Little C who loves intervals very much instead of number "3". Now he has n intervals on the number axis, the i-th of which is [a_i,b_i]. Only the n intervals can not satisfy him. He defines the value of an interval of intervals [l,r] (1 ≤ l ≤ r ≤ n, l and r are both integers) as the total leng...
#include <bits/stdc++.h> using namespace std; set<pair<int, int> > s; set<pair<int, int> >::iterator it; vector<pair<int, int> > vec[300020]; int n, k, sum[300020], f[300020]; long long num, ans, csum; inline void add(int x, int len, int id) { if (!len || !x) return; vec[x].push_back(make_pair(id, len)); sum[x] +...
Once upon a time there was only one router in the well-known company Bmail. Years went by and over time new routers were purchased. Every time they bought a new router, they connected it to one of the routers bought before it. You are given the values p_i — the index of the router to which the i-th router was connected...
import java.util.*; import java.lang.*; import java.io.*; import java.math.*; public class bmail{ static void path(Stack<Integer> s) { while(!s.isEmpty()) { System.out.print(s.pop() + " "); } } public static void main(String args[]) { Scanner sc=new Scanner(System.in); int n= sc.nextInt(); int...
The night after the graduation ceremony graduate students of German University in Cairo (GUC) are playing darts. As there's no real dart board available, the photographs of members of the GUC upper management are being used. So, n rectangular photos are placed on the wall. They can overlap arbitrary and even coincide....
#include <bits/stdc++.h> using namespace std; const int maxn = 600; const double eps = 1e-8; inline int dcmp(double x) { return fabs(x) < eps ? 0 : (x > 0 ? 1 : -1); } struct Point { double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} void scan() { scanf("%lf%lf", &x, &y); } }; Point operator+(Point a,...
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya got an array consisting of n numbers, it is the gift for his birthday. Now he wants to sort it...
#include <bits/stdc++.h> using namespace std; int islucky(int n) { while (n > 0) { if (n % 10 == 4 || n % 10 == 7) n = n / 10; else return 0; } return 1; } int a[100001]; map<int, int> val; map<pair<int, int>, int> iden; map<int, pair<int, int> > rev; vector<pair<int, int> > ans; int idx = -1;...
You are given a rooted tree with n vertices, the root of the tree is the vertex 1. Each vertex has some non-negative price. A leaf of the tree is a non-root vertex that has degree 1. Arkady and Vasily play a strange game on the tree. The game consists of three stages. On the first stage Arkady buys some non-empty set ...
#include <bits/stdc++.h> using namespace std; long long M = 1e9 + 7; const long long N = 1e6 + 7; long long n; long long a[N]; vector<long long> ad[N]; long long dp[N][2]; bool isl[N]; void solve(long long v, long long p) { if (ad[v].size() == 1 && v != 1) { isl[v] = 1; dp[v][0] = a[v]; return; } vect...
You are given a complete bipartite graph with 2n nodes, with n nodes on each side of the bipartition. Nodes 1 through n are on one side of the bipartition, and nodes n+1 to 2n are on the other side. You are also given an n × n matrix a describing the edge weights. a_{ij} denotes the weight of the edge between nodes i a...
#include <bits/stdc++.h> using namespace std; template <class t> inline t read(t &x) { char c = getchar(); bool f = 0; x = 0; while (!isdigit(c)) f |= c == '-', c = getchar(); while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); if (f) x = -x; return x; } template <class t> inline void wr...
Toad Ivan has m pairs of integers, each integer is between 1 and n, inclusive. The pairs are (a_1, b_1), (a_2, b_2), …, (a_m, b_m). He asks you to check if there exist two integers x and y (1 ≤ x < y ≤ n) such that in each given pair at least one integer is equal to x or y. Input The first line contains two space-s...
import java.util.*; import java.io.*; public class b{ static boolean find(int [][] a,int ind,int n){ int [] map=new int[n+1]; Arrays.fill(map,0); int x=a[0][ind]; int cnt=1; for(int i=1;i<a.length;i++){ if(a[i][0]==x || a[i][1]==x){ cnt++; ...
You are given an array a_1, a_2, ..., a_n and an array b_1, b_2, ..., b_n. For one operation you can sort in non-decreasing order any subarray a[l ... r] of the array a. For example, if a = [4, 2, 2, 1, 3, 1] and you choose subbarray a[2 ... 5], then the array turns into [4, 1, 2, 2, 3, 1]. You are asked to determi...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; int st[maxn << 2]; int a[maxn], b[maxn]; vector<int> pos[maxn]; void build(int id, int l, int r) { if (l == r) { st[id] = a[l]; return; } int mid = (l + r) >> 1; build(id << 1, l, mid); build(id << 1 | 1, mid + 1, r); st[id] = m...
You are given integer n. You have to arrange numbers from 1 to 2n, using each of them exactly once, on the circle, so that the following condition would be satisfied: For every n consecutive numbers on the circle write their sum on the blackboard. Then any two of written on the blackboard 2n numbers differ not more th...
import java.io.*; import java.util.*; public class Main { public static void main( String[] args ) { BufferedReader bis = new BufferedReader(new InputStreamReader(System.in)); // BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out)); InputStream inputStream = System...
Let's look at the following process: initially you have an empty stack and an array s of the length l. You are trying to push array elements to the stack in the order s_1, s_2, s_3, ... s_{l}. Moreover, if the stack is empty or the element at the top of this stack is not equal to the current element, then you just push...
#include <bits/stdc++.h> using namespace std; int arr[300105]; int _next[300105]; map<int, int> mp[300105]; int dp[300105]; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); ; int q; cin >> q; while (q--) { int n; cin >> n; for (int i = 0; i < n; i++) { cin >> arr...
The only difference between easy and hard versions is constraints. There are n kids, each of them is reading a unique book. At the end of any day, the i-th kid will give his book to the p_i-th kid (in case of i = p_i the kid will give his book to himself). It is guaranteed that all values of p_i are distinct integers ...
#include <bits/stdc++.h> using namespace std; long long int i, j, x, y, k; const int MOD = 1e9 + 7; long long int m1 = LLONG_MAX; bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); } long long int m2 = LLONG_MIN; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(...
This is an interactive problem. You are the head coach of a chess club. The club has 2n players, each player has some strength which can be represented by a number, and all those numbers are distinct. The strengths of the players are not known to you. You need to select n players who would represent your club in the ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e3 + 5; int T, N, M, K; int p1[MAXN], p2[MAXN]; void insert(int *p, int n, int key); int main() { scanf("%d", &T); while (T--) { fflush(stdout); scanf("%d", &N); fill(p1, p1 + 2 * N + 2, 0); fill(p2, p2 + 2 * N + 2, 0); M = (N + 1) ...
In this task Anna and Maria play the following game. Initially they have a checkered piece of paper with a painted n × m rectangle (only the border, no filling). Anna and Maria move in turns and Anna starts. During each move one should paint inside the last-painted rectangle a new lesser rectangle (along the grid lines...
#include <bits/stdc++.h> using namespace std; long long int C[1001][1001]; long long int nCr(int n, int r) { if (n < r) { return 0; } if (r > n - r) r = n - r; if (r == 0) return 1; if (C[n][r] != -1) return C[n][r]; C[n][r] = (nCr(n - 1, r - 1) + nCr(n - 1, r)) % 1000000007; return C[n][r]; } int mai...
Bob is playing a game named "Walk on Matrix". In this game, player is given an n × m matrix A=(a_{i,j}), i.e. the element in the i-th row in the j-th column is a_{i,j}. Initially, player is located at position (1,1) with score a_{1,1}. To reach the goal, position (n,m), player can move right or down, i.e. move from ...
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int maxn = 1e6 + 5; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; const double eps = 1e-8; const double PI = acos(-1.0); void header() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } void solve() { long lo...
A permutation of length n is an array p=[p_1,p_2,...,p_n], which contains every integer from 1 to n (inclusive) and, moreover, each number appears exactly once. For example, p=[3,1,4,2,5] is a permutation of length 5. For a given number n (n ≥ 2), find a permutation p in which absolute difference (that is, the absolut...
""" Author: guiferviz Time: 2020-05-09 16:35:02 """ def solve(): n = int(input()) if n < 4: print(-1) elif n == 4: print("3 1 4 2") else: sol = [] i = 1 while i <= n: sol.append(i) i += 2 i = sol[-1] val = i - 3 i +...
Omkar is building a house. He wants to decide how to make the floor plan for the last floor. Omkar's floor starts out as n rows of m zeros (1 ≤ n,m ≤ 100). Every row is divided into intervals such that every 0 in the row is in exactly 1 interval. For every interval for every row, Omkar can change exactly one of the 0s...
#include <bits/stdc++.h> using namespace std; template <class T, class U> void ckmin(T &a, U b) { if (a > b) a = b; } template <class T, class U> void ckmax(T &a, U b) { if (a < b) a = b; } const int MAXN = 113; int N, M; vector<int> pts[MAXN]; int id[MAXN][MAXN]; int dp[MAXN][MAXN]; int32_t main() { cout << fixe...
Have you ever used the chat application QQ? Well, in a chat group of QQ, administrators can muzzle a user for days. In Boboniu's chat group, there's a person called Du Yi who likes to make fun of Boboniu every day. Du will chat in the group for n days. On the i-th day: * If Du can speak, he'll make fun of Boboniu ...
#include <bits/stdc++.h> using namespace std; using Int = long long; constexpr static int mod = 1e9 + 7; constexpr static int inf = (1 << 30) - 1; constexpr static Int infll = (1LL << 61) - 1; int Competitive_Programming = (ios_base::sync_with_stdio(false), cin.tie(nullptr), cout << fixed << setprecision(15), ...
There are n detachments on the surface, numbered from 1 to n, the i-th detachment is placed in a point with coordinates (x_i, y_i). All detachments are placed in different points. Brimstone should visit each detachment at least once. You can choose the detachment where Brimstone starts. To move from one detachment to...
#include <bits/stdc++.h> #pragma GCC optimize(3) #pragma GCC optimize(2) #pragma GCC optimize("Ofast") using namespace std; map<int, vector<pair<int, int>>> X, Y; struct Vertex { int x, y, id; }; struct Edge { Vertex u, v; bool ishorizontal() { return u.y == v.y; } bool isvertical() { return u.x == v.x; } int...
For the simplicity, let's say that the "Death Note" is a notebook that kills a person when their name is written in it. It's easy to kill with it, but it's pretty hard to keep track of people you haven't killed and still plan to. You decided to make a "Death Database Management System" — a computer program that provid...
#include <bits/stdc++.h> using namespace std; struct ACM { int T[300010][26], ed[300010], fail[300010], last[300010], cnt, val[300010]; multiset<int> S[300010]; void insert(char *s, int idx) { int o = 0; for (int i = 0; s[i]; ++i) { int v = s[i] - 97; if (!T[o][v]) T[o][v] = ++cnt; o = T...
This is the easy version of this problem. The only difference between easy and hard versions is the constraints on k and m (in this version k=2 and m=3). Also, in this version of the problem, you DON'T NEED to output the answer by modulo. You are given a sequence a of length n consisting of integers from 1 to n. The s...
#input = sys.stdin.readline import os import sys from io import BytesIO, IOBase import heapq as h import bisect from types import GeneratorType BUFSIZE = 8192 class SortedList: def __init__(self, iterable=[], _load=200): """Initialize sorted list instance.""" values = sorted(itera...
You are given a positive (greater than zero) integer n. You have to represent n as the sum of integers (possibly negative) consisting only of ones (digits '1'). For example, 24 = 11 + 11 + 1 + 1 and 102 = 111 - 11 + 1 + 1. Among all possible representations, you have to find the one that uses the minimum number of o...
#include <bits/stdc++.h> using namespace std; #define sz(a) int((a).size()) #define forn(i, n) for (int i = 0; i < int(n); ++i) const int N = 250; const int M = 28; const int INF = 1e9; int dp[2][M * 2 + 1][N][N]; int main() { string s; cin >> s; reverse(s.begin(), s.end()); s += "0"; forn(carry, M * ...
You have a card deck of n cards, numbered from top to bottom, i. e. the top card has index 1 and bottom card — index n. Each card has its color: the i-th card has color a_i. You should process q queries. The j-th query is described by integer t_j. For each query you should: * find the highest card in the deck with...
#include <bits/stdc++.h> using namespace std; #define ll long long ll a[300005] , spare = 0; int main(){ ll n , q , i , j; cin >> n >> q; set < pair < ll , ll > > cur; for(i = 1;i<=n;i++){ cin >> a[i]; cur.insert( { i , a[i] } ); } while(q--){ ll x , gone = 0; cin...
There are n people participating in some contest, they start participating in x minutes intervals. That means the first participant starts at time 0, the second participant starts at time x, the third — at time 2 ⋅ x, and so on. Duration of contest is t minutes for each participant, so the first participant finishes t...
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int k=sc.nextInt(); while(k-->0){ long n=sc.nextLong(); long x=sc.nextLong(); long t=sc.nextLong(); if(x==t){ ...
A string is binary, if it consists only of characters "0" and "1". String v is a substring of string w if it has a non-zero length and can be read starting from some position in string w. For example, string "010" has six substrings: "0", "1", "0", "01", "10", "010". Two substrings are considered different if their po...
def main(): k, s = lie(), input() n = len(s) dp = [-1] for i in range(n): if s[i] == '1': dp.append(i) dp.append(n) if len(dp) - 2 < k: print(0) elif k == 0: ans = 0 for i in range(1, len(dp)): ans += (dp[i] - dp[i - 1] - 1) * (dp[i] - ...
As you very well know, the whole Universe traditionally uses three-dimensional Cartesian system of coordinates. In this system each point corresponds to three real coordinates (x, y, z). In this coordinate system, the distance between the center of the Universe and the point is calculated by the following formula: <ima...
import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigDecimal; import java.math.BigInte...
The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subjects. Let's describe the problem: You've got some training set of documents. For each document you know its su...
#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); n /= 1000; puts(n & 1 ? "1" : "3"); return 0; }
John Doe has a field, which is a rectangular table of size n × m. We assume that the field rows are numbered from 1 to n from top to bottom, and the field columns are numbered from 1 to m from left to right. Then the cell of the field at the intersection of the x-th row and the y-th column has coordinates (x; y). We k...
#include <bits/stdc++.h> using namespace std; const int N = 512; const int Q = 600011; int arr[N][N]; int n, lp2[N]; struct query { int when; int i1, j1, i2, j2; query() {} query(int when, int i1, int j1, int i2, int j2) : when(when), i1(i1), j1(j1), i2(i2), j2(j2) {} }; int ans[Q]; vector<query> solo[N],...
The Little Elephant loves permutations of integers from 1 to n very much. But most of all he loves sorting them. To sort a permutation, the Little Elephant repeatedly swaps some elements. As a result, he must receive a permutation 1, 2, 3, ..., n. This time the Little Elephant has permutation p1, p2, ..., pn. Its sort...
#include <bits/stdc++.h> const int N = 1e3 + 5; const int mod = 1e9 + 7; const int MOD = mod - 1; const double eps = 1e-18; const double PI = acos(-1.0); using namespace std; int p[N]; double f[N][N]; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) scanf("%d", &p[i]); for (int i = 1; ...
Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers x1, x2, ..., xk (k > 1) is such maximum element xj, that the following inequality holds: <image>. The lucky number of the sequence of distinct positive integers x1, x2, ..., xk (k > 1) is t...
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.util.Stack; public class CFFF { static PrintWriter out; public static void main(String[] args) { MScanner sc = new MScanner(); out = new PrintWriter(System.out); int N =...
Bike is interested in permutations. A permutation of length n is an integer sequence such that each integer from 0 to (n - 1) appears exactly once in it. For example, [0, 2, 1] is a permutation of length 3 while both [0, 2, 2] and [1, 2, 3] is not. A permutation triple of permutations of length n (a, b, c) is called a...
#include <bits/stdc++.h> using namespace std; int main() { int x; cin >> x; if (x % 2 == 0) { cout << -1 << endl; return 0; } for (int i = 0; i < x; i++) { cout << i << " "; } cout << "\n"; for (int i = 0; i < x; i++) { cout << i << " "; } cout << "\n"; for (int i = 0; i < x; i++) ...
You're a mikemon breeder currently in the middle of your journey to become a mikemon master. Your current obstacle is go through the infamous Biridian Forest. The forest The Biridian Forest is a two-dimensional grid consisting of r rows and c columns. Each cell in Biridian Forest may contain a tree, or may be vacant....
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class problemD { static void solve() throws IOException { int n = nextInt(); int m = nextI...
One day Jeff got hold of an integer sequence a1, a2, ..., an of length n. The boy immediately decided to analyze the sequence. For that, he needs to find all values of x, for which these conditions hold: * x occurs in sequence a. * Consider all positions of numbers x in the sequence a (such i, that ai = x). These...
le = int(input()) integers = [int(i) for i in str(input()).split(" ")] d = {} for index, ele in enumerate(integers): # should already be sorted if ele in d: d[ele].append(index) else: d[ele] = [index] ans = [] for key, items in d.items(): if len(items) == 1: ans.append((key, 0))...
You have number a, whose decimal representation quite luckily contains digits 1, 6, 8, 9. Rearrange the digits in its decimal representation so that the resulting number will be divisible by 7. Number a doesn't contain any leading zeroes and contains digits 1, 6, 8, 9 (it also can contain another digits). The resultin...
import java.io.*; import java.util.*; import java.math.*; public class Main{ public static void main(String args[]) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = br.readLine(); boolean seen[] = new boolean[10]; String...
We are given a permutation sequence a1, a2, ..., an of numbers from 1 to n. Let's assume that in one second, we can choose some disjoint pairs (u1, v1), (u2, v2), ..., (uk, vk) and swap all aui and avi for every i at the same time (1 ≤ ui < vi ≤ n). The pairs are disjoint if every ui and vj are different from each othe...
#include <bits/stdc++.h> using namespace std; const double pi = acos(0.0) * 2.0; const double eps = 1e-12; const int step[8][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; template <class T> inline T abs1(T a) { return a < 0 ? -a : a; } template <class T> inline ...
Pasha has two hamsters: Arthur and Alexander. Pasha put n apples in front of them. Pasha knows which apples Arthur likes. Similarly, Pasha knows which apples Alexander likes. Pasha doesn't want any conflict between the hamsters (as they may like the same apple), so he decided to distribute the apples between the hamste...
n, a, b = map(int, input().split()) x = set(map(int, input().split())) y = set(map(int, input().split())) y -= x s = "" for i in range(1, n + 1, 1): if i in x: s += str(1) + " " else: s += str(2) + " " print(s)
As we know, DZY loves playing games. One day DZY decided to play with a n × m matrix. To be more precise, he decided to modify the matrix with exactly k operations. Each modification is one of the following: 1. Pick some row of the matrix and decrease each element of the row by p. This operation brings to DZY the v...
#include <bits/stdc++.h> using namespace std; const long long N = 1005; const long long M = 1e6 + 5; const long long inf = 1e15; long long row[N], col[N]; long long ansr[M], ansc[M]; priority_queue<long long> q[2]; int main() { long long n, m, k, p, t; scanf("%I64d%I64d%I64d%I64d", &n, &m, &k, &p); for (long long...
Little X has met the following problem recently. Let's define f(x) as the sum of digits in decimal representation of number x (for example, f(1234) = 1 + 2 + 3 + 4). You are to calculate <image> Of course Little X has solved this problem quickly, has locked it, and then has tried to hack others. He has seen the foll...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long X = 0, w = 1; char c = getchar(); while (c < '0' || c > '9') { if (c == '-') w = -1; c = getchar(); } while (c >= '0' && c <= '9') X = X * 10 + c - '0', c = getchar(); return X * w; } const long long _ = 1e18; signed m...
Vanya got n cubes. He decided to build a pyramid from them. Vanya wants to build the pyramid as follows: the top level of the pyramid must consist of 1 cube, the second level must consist of 1 + 2 = 3 cubes, the third level must have 1 + 2 + 3 = 6 cubes, and so on. Thus, the i-th level of the pyramid must have 1 + 2 + ...
n=int(input()) i=1;x=0 while 1: x+=(i*(i+1)/2) if x==n: print(i) break elif x>n: print(i-1) break i+=1
Drazil is a monkey. He lives in a circular park. There are n trees around the park. The distance between the i-th tree and (i + 1)-st trees is di, the distance between the n-th tree and the first tree is dn. The height of the i-th tree is hi. Drazil starts each day with the morning run. The morning run consists of the...
#include <bits/stdc++.h> const long long MAXN = 1e5; const long long INF = 0x3f3f3f3f3f3f3f; long long n, m; long long d[MAXN << 1 | 1], h[MAXN << 1 | 1]; inline long long read() { register long long x = 0, v = 1; register char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') v = -1; ch = getchar(); ...
Polycarp is making a quest for his friends. He has already made n tasks, for each task the boy evaluated how interesting it is as an integer qi, and the time ti in minutes needed to complete the task. An interesting feature of his quest is: each participant should get the task that is best suited for him, depending o...
#include <bits/stdc++.h> using namespace std; const int Maxn = 1005; int n, T; pair<int, int> tq[Maxn]; vector<int> cur; bool Less(const int &a, const int &b) { return a > b; } void Next() { vector<int> nw; for (int i = 0; i < cur.size(); i += 2) { int val = cur[i] + (i + 1 < cur.size() ? cur[i + 1] : 0); n...
Vasya collects coins: he has exactly one coin for every year from 1 to n. Naturally, Vasya keeps all the coins in his collection in the order in which they were released. Once Vasya's younger brother made a change — he took all the coins whose release year dated from l to r inclusively and put them in the reverse order...
#include <bits/stdc++.h> using namespace std; int main() { int n, l = 0, r = 0; cin >> n; int* A = new int[n + 2]; for (int i = 1; i <= n; i++) cin >> A[i]; int i = 1; while (i <= n && A[i] == i) { i++; } if (i < n) { l = i; r = A[i]; bool f = false; for (; i <= r; i++) if (A[i...
Today is birthday of a Little Dasha — she is now 8 years old! On this occasion, each of her n friends and relatives gave her a ribbon with a greeting written on it, and, as it turned out, all the greetings are different. Dasha gathered all the ribbons and decided to throw away some of them in order to make the remainin...
//package round327; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.BitSet; import java.util.InputMismatchException; import java.util.List; import j...
You are given n segments on the coordinate axis Ox and the number k. The point is satisfied if it belongs to at least k segments. Find the smallest (by the number of segments) set of segments on the coordinate axis Ox which contains all satisfied points and no others. Input The first line contains two integers n and ...
#include <bits/stdc++.h> using namespace std; template <int POS, class TUPLE> void deploy(std::ostream &os, const TUPLE &tuple) {} template <int POS, class TUPLE, class H, class... Ts> void deploy(std::ostream &os, const TUPLE &t) { os << (POS == 0 ? "" : ", ") << get<POS>(t); deploy<POS + 1, TUPLE, Ts...>(os, t); ...
You are given array a with n elements and the number m. Consider some subsequence of a and the value of least common multiple (LCM) of its elements. Denote LCM as l. Find any longest subsequence of a with the value l ≤ m. A subsequence of a is an array we can get by erasing some elements of a. It is allowed to erase z...
#include <bits/stdc++.h> using namespace std; void make_unique(vector<int> &a) { sort(a.begin(), a.end()); a.erase(unique(a.begin(), a.end()), a.end()); } int Set(int N, int cur) { return N = N | (1 << cur); } int Reset(int N, int cur) { return N = N & ~(1 << cur); } bool Check(int N, int cur) { return (bool)(N & (...
Robbers, who attacked the Gerda's cab, are very successful in covering from the kingdom police. To make the goal of catching them even harder, they use their own watches. First, as they know that kingdom police is bad at math, robbers use the positional numeral system with base 7. Second, they divide one day in n hour...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, m, i, j, k; scanf("%lld", &n); ; scanf("%lld", &m); ; long long int ans = 0; long long int temp = n - 1, len1 = 0, len2 = 0; while (temp != 0) { len1++; temp /= 7; } temp = m - 1; while (temp != 0) { len2++; ...
Like all children, Alesha loves New Year celebration. During the celebration he and his whole family dress up the fir-tree. Like all children, Alesha likes to play with garlands — chains consisting of a lightbulbs. Alesha uses a grid field sized n × m for playing. The rows of the field are numbered from 1 to n from th...
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:102400000,102400000") using namespace std; const int INF = 0x3f3f3f3f; const long long INFF = 0x3f3f; const double pi = acos(-1.0); const double inf = 1e18; const double eps = 1e-4; const long long mod = 1e9 + 7; const unsigned long long mx = 133333331; inline vo...
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating ch...
#include <bits/stdc++.h> using namespace std; int c[200200], C[200200], d[200200]; int n; int magic = -1; int main() { ios_base::sync_with_stdio(false); cin >> n; for (int i = 1; i <= n; i++) cin >> c[i] >> d[i]; for (int i = 1; i <= n; i++) { C[i] = C[i - 1] + c[i - 1]; if (d[i] == 2) { if (magic...
Pupils decided to go to amusement park. Some of them were with parents. In total, n people came to the park and they all want to get to the most extreme attraction and roll on it exactly once. Tickets for group of x people are sold on the attraction, there should be at least one adult in each group (it is possible tha...
#include <bits/stdc++.h> using namespace std; int main() { long long int n, c1, c2, p = 0, r; cin >> n >> c1 >> c2; char g; for (long long int i = 0; i < n; i++) { cin >> g; if (g == '1') p++; } long long int minr = -1; for (int i = 1; i <= p; i++) { r = i * c1 + c2 * ((n % i) * (n / i) * (n /...
In some game by Playrix it takes t minutes for an oven to bake k carrot cakes, all cakes are ready at the same moment t minutes after they started baking. Arkady needs at least n cakes to complete a task, but he currently don't have any. However, he has infinitely many ingredients and one oven. Moreover, Arkady can bui...
n,t,k,d=[int(i) for i in input().split()] a = (n+k-1)//k*t b=1000000000 for i in range(n//k+1): b=min(b,max(d+i*t,(n-i*k+k-1)//k*t)) if b<a: print('YES') else: print('NO')
Sometimes Mister B has free evenings when he doesn't know what to do. Fortunately, Mister B found a new game, where the player can play against aliens. All characters in this game are lowercase English letters. There are two players: Mister B and his competitor. Initially the players have a string s consisting of the...
#include <bits/stdc++.h> using namespace std; int main() { int a, b, l, r; cin >> a >> b >> l >> r; if (a == 3 && b == 1 && l == 4 && r == 10) { cout << 4 << endl; return 0; } int xx = (r - l + 1); l--; r--; l = l % (a + a + b + b); r = r % (a + a + b + b); string s, x; int f = 0, in = 0; ...
This is an interactive problem. You are given a sorted in increasing order singly linked list. You should find the minimum integer in the list which is greater than or equal to x. More formally, there is a singly liked list built on an array of n elements. Element with index i contains two integers: valuei is the int...
#include <bits/stdc++.h> using namespace std; int myrand(int m) { return (rand() * (1 << 15) + rand()) % m; } int main() { srand(time(0)); int n, ind, x; cin >> n >> ind >> x; --ind; vector<int> left(n); vector<bool> vis(n, 0); for (int i = 0; i < n; ++i) left[i] = i; vis[ind] = 1; random_shuffle(left...
Attention: we lost all the test cases for this problem, so instead of solving the problem, we need you to generate test cases. We're going to give you the answer, and you need to print a test case that produces the given answer. The original problem is in the following paragraph. People don't use cash as often as they...
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; cout << (2 * n) - 1 << " " << 2 << endl; cout << 1 << " " << 2; return 0; }
You have an array a with length n, you can perform operations. Each operation is like this: choose two adjacent elements from a, say x and y, and replace one of them with gcd(x, y), where gcd denotes the [greatest common divisor](https://en.wikipedia.org/wiki/Greatest_common_divisor). What is the minimum number of ope...
#include <bits/stdc++.h> using namespace std; constexpr int inf = 0x3f3f3f3f; class Solver { public: explicit Solver(vector<int>&& v) : n_(v.size()), v_(std::move(v)), gcd_(n_, vector<int>(n_ + 1, -1)), steps_(n_, vector<int>(n_ + 1, -1)) {} int solve() { return g(0, n_); } private:...
You are preparing for an exam on scheduling theory. The exam will last for exactly T milliseconds and will consist of n problems. You can either solve problem i in exactly ti milliseconds or ignore it and spend no time. You don't need time to rest after solving a problem, either. Unfortunately, your teacher considers ...
#include <bits/stdc++.h> using namespace std; istream& in = cin; long long n, T; vector<pair<int, pair<int, int> > > all; void input() { in >> n >> T; for (int i = 1; i <= n; ++i) { int a, b; in >> a >> b; all.push_back(make_pair(b, make_pair(a, i))); } } bool ok(int m) { long long sum = 0; long l...
Ancient Egyptians are known to have used a large set of symbols <image> to write on the walls of the temples. Fafa and Fifa went to one of the temples and found two non-empty words S1 and S2 of equal lengths on the wall of temple written one below the other. Since this temple is very ancient, some symbols from the word...
#include <bits/stdc++.h> using namespace std; long long n, m, a[100010], b[100010], ac, bc; long long power(long long a, long long n) { long long temp; if (n == 0) return 1; temp = power(a, n / 2); if (n % 2 == 0) return (((temp % 1000000007) * (temp % 1000000007)) % 1000000007); else { long long res ...
Magnus decided to play a classic chess game. Though what he saw in his locker shocked him! His favourite chessboard got broken into 4 pieces, each of size n by n, n is always odd. And what's even worse, some squares were of wrong color. j-th square of the i-th row of k-th piece of the board has color ak, i, j; 1 being ...
/* / フフ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ム / )\⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀ Y (⠀⠀| ( ͡° ͜ʖ ͡°)⠀⌒(⠀ ノ (⠀ ノ⌒ Y ⌒ヽ-く __/ | _⠀。ノ| ノ。 |/ (⠀ー '_人`ー ノ ⠀|\  ̄ _人'彡ノ ⠀ )\⠀⠀ 。⠀⠀ / ⠀⠀(\⠀ #⠀ / ⠀/⠀⠀⠀/ὣ====================D- /⠀⠀⠀/⠀ \ \⠀⠀\ ( (⠀)⠀⠀⠀⠀ ) ).⠀) (⠀⠀)⠀⠀⠀⠀⠀( | / |⠀ /⠀⠀⠀⠀⠀⠀ | / [_] ⠀⠀⠀⠀⠀[___] */ // Main Code at the Bottom import ...
Walking along a riverside, Mino silently takes a note of something. "Time," Mino thinks aloud. "What?" "Time and tide wait for no man," explains Mino. "My name, taken from the river, always reminds me of this." "And what are you recording?" "You see it, tide. Everything has its own period, and I think I've figured...
n, p = [int(i) for i in input().split()] s = list(input()) k = 0 for index in range(n - p): if k != 0: break if s[index] == s[index + p] and s[index] == ".": s[index] = str(0) s[index + p] = str(1) k += 1 elif s[index] != s[index + p] and s[index] != "." and s[index + p] != "...
Amit has been practicing "pattern printing" problems a lot. To test his ability Jitendra gives him a problem.He tells him to print the given matrix in the diagonal fashion. Note: Direction of the diagonal is from the upper-right corner to lower-left corner.See sample test cases for more clarification.Imagine you are A...
n,m = map(int,raw_input().split()) matrix = [] for x in range(n): matrix.append(map(int,raw_input().split())) maxsum = n + m - 2 for sums in range(maxsum+1): for i in range(n): for j in range(m): if i + j - sums == 0: print matrix[i][j], print
Brian built his own car and was confused about what name he should keep for it. He asked Roman for help. Roman being his good friend, suggested a lot of names. Brian only liked names that: - Consisted of exactly three distinct characters, say C1, C2 and C3 - Satisfied the criteria that the string was of the form - ...
''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' def validName(s): seen = 0 seen_c = [] last_c = "" n = 0 i = 0 for c in s: if c != last_c: last_c = c seen += 1 if c in seen_c or i < n: return "Not OK" seen_c...
Frustrated from Mandark's challenges, Dexter plans an invasion in Mandark's lab. He knows that the underground entrance is the best way to get inside. But still, he needs to defuse the bombs hidden under the tiles of the floor. Dexter knows that the entrance has rectangular floor, divided in 1x1 tiles, so he numbered ...
t=int(raw_input()) for e in range(t): s,x,=0,0 w,h=map(int,raw_input().split() ) s,x=2*(w//4),w%4 s1=s+(x//3) if x==1: s+=1 elif x!=0: s+=2 k,x=(h//4),h%4 n=2*(s+s1)*k if x==1: n+=s elif x==2: n+=2*s elif x==3: n+=2*s+s1 print n
Given an array of size N of integers with each element denoted as array[i] . In this problem we are given a parameter K and we are supposed to find the size of the largest contiguous subarray whose GCD is atleast K If there is no subarray whose GCD is atleast K , print "0". INPUT The first line contains 2 integers N...
from fractions import gcd n,m=map(int,raw_input().split()) a=map(int,raw_input().split()) z=[] l=0 for x in xrange(n): if a[x]<m: continue s=a[x] q=0 for y in xrange(x+1,n): if a[y]<m or s<m: break s=gcd(s,a[y]) if s>=m: l=max(l,y-x+1) if l==0: print 0 else: print l
Sidddharth is very kind-hearted. He doesn't want to give you any stupid problem statement that wastes your time. Given an array of integers, find the sum of the ith largest and jth smallest number from the array. Input Format: First line of the input consists of a single integer T, number of test cases. Each test cas...
t=input() for i in range(t): n=input() a=map(int,raw_input().strip().split()) (i,j)=map(int,raw_input().strip().split()) a.sort() result=a[n-i]+a[j-1] print result
Monk was asked to answer some queries in an interview. He is given an empty array A. Queries are of 4 types:- 1. 1 X - Add number X to the array A. 2. 2 X - Remove a single instance of number X from the array A. If not possible, print "-1" without the quotes. 3. 3 - Find the maximum element in the array A. 4. 4 - Find ...
from collections import defaultdict n=input() minn=1000001 maxx=0 a=defaultdict(int) ans=[] count=0 for i in range(0,n): x=map(int,raw_input().split()) if x[0]==1: if x[1]>maxx: maxx=x[1] if x[1]<minn: minn=x[1] a[x[1]]+=1 count+=1 elif x[0]==2: ...
A particular name-recording system is used by N employees of a firm. Everyday, they have to enter their names into the system. To make it easier to control the system, each employee has his/her name presented as a string of lowercase letters from 'a' to 'z' with the same length K. Therefore, the system is designed to ...
for testCases in range(input()): matrix = [] n,m = map(int,raw_input().split()) for i in range(n): a = raw_input() b = [] for j in a: b.append(ord(j)) matrix.append(b) mat = [] for i in range(m): res = [] for j in range(n): res....
Roy has played a lot of Mario that he got bored of playing it again and again. So now he wants to design a stage of Mario game. Right now he is simply designing a group of walls using bricks that little Mario has to cross over. Little Mario cannot jump more than 3 bricks' height, so Roy cannot create a wall of height ...
MOD = 1000000007 def TribSeries(n,t1,t2,t3): if n==1: ans=t1 if n==2: ans=t2 if n==3: ans=t3 if n>3: for j in range(n-3): ans=(t1+t2+t3)%MOD t1=t2 t2=t3 t3=ans print ans def main(): T=int(raw_input()) trib=[] ...
Anton and Artur are old friends. Today they practice in writing strings. Anton must write each string with the lengths exactly N , based on the alphabet of size M . And Arthur, on the contrary, should write each string with the lengths exactly M , based on the alphabet of size N . Guys spend 1 second to write a sin...
T = int(raw_input()) while(T): T -= 1 N,M = raw_input().split() n = int(N) m = int(M) if n == m : print "YES" elif n==2 and m==4 or n==4 and m==2: print "YES" else: print "NO"
Problem : Chotu's father is the owner of a Vada Pav shop. One Sunday, his father takes him to the shop. Father tells him that at the end of the day, Chotu has to give him a list consisting of the names of all the customers on that day who bought Vada Pav(s) from the shop. The list should not have the names of any of t...
listi = [] for i in range(input()): s = raw_input() listi.append(s) ans = list(set(listi)) ans.sort() print len(ans) for i in ans: print i
M-kun is a competitor in AtCoder, whose highest rating is X. In this site, a competitor is given a kyu (class) according to his/her highest rating. For ratings from 400 through 1999, the following kyus are given: * From 400 through 599: 8-kyu * From 600 through 799: 7-kyu * From 800 through 999: 6-kyu * From 1000 thro...
import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int X = Integer.parseInt(sc.next()); if(X >= 400 && X <= 599) { System.out.println(8); }else if(X <= 799) { System.out.println(7); }else if(X <= 999) { System.out.println(6); }els...
Given is a positive integer L. Find the maximum possible volume of a rectangular cuboid whose sum of the dimensions (not necessarily integers) is L. Constraints * 1 ≤ L ≤ 1000 * L is an integer. Input Input is given from Standard Input in the following format: L Output Print the maximum possible volume of a re...
N=int(input()) print((N**3)/27)
We will create an artwork by painting black some squares in a white square grid with 10^9 rows and N columns. The current plan is as follows: for the i-th column from the left, we will paint the H_i bottommost squares and will not paint the other squares in that column. Before starting to work, you can choose at most K...
#include <bits/stdc++.h> #define rep(i, n) for (int i=0; i < n; i ++) #define rep1(i, n) for (int i=1; i <= n; i ++) #define _min(x, y) x = min(x, y) #define _max(x, y) x = max(x, y) using namespace std; vector<vector<long long> > dp(305, vector<long long>(305, 300000000000)); int main() { int N, K; cin >> N >> K;...
X and A are integers between 0 and 9 (inclusive). If X is less than A, print 0; if X is not less than A, print 10. Constraints * 0 \leq X, A \leq 9 * All values in input are integers. Input Input is given from Standard Input in the following format: X A Output If X is less than A, print 0; if X is not less th...
import java.util.*; import java.util.stream.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println(in.nextInt() < in.nextInt() ? 0 : 10); } }
You are given three strings A, B and C. Each of these is a string of length N consisting of lowercase English letters. Our objective is to make all these three strings equal. For that, you can repeatedly perform the following operation: * Operation: Choose one of the strings A, B and C, and specify an integer i betwe...
import java.io.PrintWriter; import java.util.*; public class Main { public static String implementation(List<String> array){ int n = Integer.parseInt(array.get(0)); String a = array.get(1); String b = array.get(2); String c = array.get(3); int count = 0; for(int i=0; i<n; i++){ if(a.charAt(i)==b.charA...
Takahashi has decided to distribute N AtCoder Crackers to K users of as evenly as possible. When all the crackers are distributed, find the minimum possible (absolute) difference between the largest number of crackers received by a user and the smallest number received by a user. Constraints * 1 \leq N,K \leq 100 * A...
#include<bits/stdc++.h> using namespace std; int a,b; int main() { cin>>a>>b; cout << bool(a%b) << endl; }
You are given a forest with N vertices and M edges. The vertices are numbered 0 through N-1. The edges are given in the format (x_i,y_i), which means that Vertex x_i and y_i are connected by an edge. Each vertex i has a value a_i. You want to add edges in the given forest so that the forest becomes connected. To add a...
# -*- coding: utf-8 -*- from collections import defaultdict from heapq import merge import sys sys.setrecursionlimit(10**7) def inpl(): return tuple(map(int, input().split())) N, M = inpl() A = inpl() tree = [[-1, 1] for _ in range(N)] # [next, rank] def find(i): if tree[i][0] == -1: group = i else...
There are N balls in the xy-plane. The coordinates of the i-th of them is (x_i, i). Thus, we have one ball on each of the N lines y = 1, y = 2, ..., y = N. In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B. Then, he placed the i-th type-A robot at coordinates (0, i), and the i-th t...
n=int(input()) k=int(input()) x=list(map(int,input().split())) ans=0 for i in range(n): ans+=2*min(x[i],k-x[i]) print(ans)
Three poles stand evenly spaced along a line. Their heights are a, b and c meters, from left to right. We will call the arrangement of the poles beautiful if the tops of the poles lie on the same line, that is, b-a = c-b. Determine whether the arrangement of the poles is beautiful. Constraints * 1 \leq a,b,c \leq 10...
#include <iostream> using namespace std; int main() { int A,B,C; cin >> A >> B>> C; cout << (B-A==C-B ? "YES" : "NO"); return 0; }
On a planet far, far away, M languages are spoken. They are conveniently numbered 1 through M. For CODE FESTIVAL 20XX held on this planet, N participants gathered from all over the planet. The i-th (1≦i≦N) participant can speak K_i languages numbered L_{i,1}, L_{i,2}, ..., L_{i,{}K_i}. Two participants A and B can c...
#include <bits/stdc++.h> using namespace std; int g[200005]; int f(int x) { return g[x] == x ? x : g[x] = f(g[x]); } int main() { for (int i = 1; i <= 200000; i++) { g[i] = i; } int n, m, k, x; scanf("%d %d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d", &k); for (int j = 1; j <= k; j++) {...
Given a sequence of numbers a1, a2, a3, ..., an, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a contiquous subsequence. Input The input consists of multiple datasets. Each data set consists of: n a1 a2 . . an You can assume that 1 ≤ n ≤ 5000 ...
while 1: n=input() if n==0:break r=[input()for i in xrange(n)] #print r for i in xrange(1,n): r[i]=max(r[i-1]+r[i],r[i]) #print r print max(r)
Create a program to determine the positional relationship between a triangle and a circle on a plane. All target figures shall include boundaries. The triangle is given the position of three vertices, and the circle is given the position of the center and the radius. The position is given by a set of two integers in a ...
#include<bits/stdc++.h> using namespace std; //objects----------------------------------------------------------------- typedef complex<double>Point; typedef Point Vector; typedef vector<Point>Polygon; struct Segment{ Point p1,p2; Segment(const Point &p1=Point(),const Point &p2=Point()):p1(p1),p2(p2){} }; st...
Welcome to PC Koshien, players. At PC Koshien, competitions are currently being held in a total of three categories: programming category, mobile category, and Ichimai's picture CG category. Given the number of participants in each department, create a program that calculates the total number of participants. Input...
#include <stdio.h> #include <string> #include <iostream> #include <map> #include <algorithm> using namespace std; int main(void){ int a,b,c; cin >> a >> b >> c; cout << (a+b+c) << endl; return 0; }
problem There are fine icicles under the eaves of JOI's house in Canada. Because of this, JOI decided to investigate the icicles. There are N (2 ≤ N ≤ 100000 = 105) icicles under the eaves of JOI's house. These icicles are aligned and i cm (1 ≤ i ≤ N) from the left edge of the eaves. There are i-th icicles at the pos...
def loadIcicle(): icicles = [] line = input().strip().split(" ") N, L = int(line[0]), int(line[1]) while True: icicles.append(int(input().strip())) if len(icicles) == N: break return icicles, N, L icicles, N, L = loadIcicle() def calcDiff(icicles, N): diff_2times = [0]*N for idx in range(N): dif_right = ...
Evil organizations that attempt to conquer the world are everywhere, regardless of age, east or west fiction, non-fiction, but what on earth did they try to conquer the world? I suddenly thought about that because I was also planning to conquer the world. The only reason I want to conquer the world is to show the world...
#include<cstdio> #include<iostream> #include<cmath> #include<vector> #include<algorithm> using namespace std; int main(){ int n; int id[100]; double p[100],w[100]; bool use[100]; long long int pascal[101][101]; for(int i=0;i<=100;i++){ pascal[i][0] = 1; pascal[0][i] = 1; } for(int i=1;i<=100;...
Let's play a traditional game Nim. You and I are seated across a table and we have a hundred stones on the table (we know the number of stones exactly). We play in turn and at each turn, you or I can remove one to four stones from the heap. You play first and the one who removed the last stone loses. In this game, you...
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; typedef pair<ll, ll> Pl; #define vi vector<int> #define vl vector<long long> #define vvi vector< vector<int> > #define vvl vector< vector<ll> > #define vp vector<P> #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define R...
Example Input 2 2 7 3 4 3 2 1 3 1 1 2 2 1 2 2 1 1 2 2 2 1 1 Output 5
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair using namespace std; typedef pair <int, int> pii; int p, r, t; int l[310], nl[310]; int n[310][310], nn[310][310]; pii a[200010]; int cnt[310]; bool check(int mid){ for (int i = 1; i <= r; i++){ nl[i] = l[i]; } for (int i = 1; i <=...
Problem Gaccho owns an N-sided field and M potatoes. Each field is numbered from 1 to N. Gaccho wants to increase the number of potatoes by planting and harvesting potatoes in the field. Gaccho lives alone and can only manage fields up to the K side. In addition, the soil condition and area of ​​each field vary, and ...
#include <iostream> #include <vector> template<class T> using vec = std::vector<T>; int rec(int S, int N, int K, int money, vec<int> &a, vec<int> &b) { if (__builtin_popcount(S) == K) { return money; } int res = 0; for (int i = 0; i < N; i++) { if (S >> i & 1) continue; in...
Hit and blow is a popular code-breaking game played by two people, one codemaker and one codebreaker. The objective of this game is that the codebreaker guesses correctly a secret number the codemaker makes in his or her mind. The game is played as follows. The codemaker first chooses a secret number that consists of ...
#include<iostream> #include<algorithm> #include<vector> #include<cstdio> #include<cassert> using namespace std; #define REP(i,b,n) for(int i=b;i<n;i++) #define rep(i,n) REP(i,0,n) typedef pair<int,int> pii; const int N = 10000; void compute(int i,int *buf){ buf[0]=i/1000%10; buf[1]=i/100%10; buf[2]=i/10%10; ...
In the west of Tokyo, there is a city named “Academy City.” There are many schools and laboratories to develop psychics in Academy City. You are a psychic student of a school in Academy City. Your psychic ability is to give acceleration to a certain object. You can use your psychic ability anytime and anywhere, but t...
#include<cstdio> #include<complex> #include<cmath> #include<utility> #include<algorithm> using namespace std; typedef double Real; const Real eps=1e-9; const Real PI=acos(-1.0); typedef pair<Real,Real> P; typedef complex<Real> Point; typedef complex<Real> Vector; typedef pair<Point,Point> Segment; template<class T...
There is a grid that consists of W \times H cells. The upper-left-most cell is (1, 1). You are standing on the cell of (1,1) and you are going to move to cell of (W, H). You can only move to adjacent lower-left, lower or lower-right cells. There are obstructions on several cells. You can not move to it. You cannot mov...
#include <cstdio> #include <vector> #include <map> #define repeat(i,n) for (int i = 0; (i) < (n); ++(i)) #define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i)) typedef long long ll; using namespace std; const int mod = 1e9+9; vector<vector<ll> > operator * (vector<vector<ll> > const & p, vector<vector<ll> > c...
Problem Statement Fox Ciel is practicing miniature golf, a golf game played with a putter club only. For improving golf skills, she believes it is important how well she bounces the ball against walls. The field of miniature golf is in a two-dimensional plane and surrounded by $N$ walls forming a convex polygon. At f...
#include <set> #include <cmath> #include <cstdio> #include <vector> #include <cassert> #include <algorithm> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; const double EPS=1e-8; const double PI=acos(-1); struct point{ double x,y; point():x(0),y(0){} point(double x,double y):x(x),y(y){} point opera...
Example Input 3 0 1 0 0 0 1 0 1 0 2 0 2 0 3 Output 6.0000000000000000
#include <bits/stdc++.h> using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; constexpr ll TEN(int n) { return (n==0) ? 1 : 10*TEN(n-1); } template<class T> using V = vector<T>; template<class T> using VV = V<V<T>>; template<class D> struct Hungarian { V<D> le, ri...
You are given a tree $T$ and an integer $K$. You can choose arbitrary distinct two vertices $u$ and $v$ on $T$. Let $P$ be the simple path between $u$ and $v$. Then, remove vertices in $P$, and edges such that one or both of its end vertices is in $P$ from $T$. Your task is to choose $u$ and $v$ to maximize the number ...
#include <bits/stdc++.h> #define syosu(x) fixed<<setprecision(x) using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int,int> P; typedef pair<double,double> pdd; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<double>...
BackGround In the Demon's Plan, 108 demons who control the desire are competing in the programming contest day and night. The organizer, Patron, is trying to invite the demons to "Rix-Magna", a place where all the souls gather. Patron wants to send an invitation to a demon who hasn't sent an invitation yet, but he dec...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> P; #define EACH(i,a) for (auto& i : a) #define FOR(i,a,b) for (ll i = (a); i < (b); ++i) #define RFOR(i,a,b) for (ll i = (b)-1; i >= (a); --i) #define REP(i,n) FOR(i,0,n) #define RREP(i,n) RFOR(i,0,n) #define pb push_back #defin...
Find places where a string P is found within a text T. Print all indices of T where P found. The indices of T start with 0. Constraints * 1 ≤ length of T ≤ 1000 * 1 ≤ length of P ≤ 1000 * The input consists of alphabetical characters and digits Input In the first line, a text T is given. In the second line, a strin...
T = input() P = input() if len(P) > len(T): pass else: p = len(P) ans = [] for i in range(len(T)-len(P)+1): tmp = "" for j in range(i,i+p): tmp += T[j] if tmp == P: ans.append(i) for i in ans: print(i)