input stringlengths 29 13k | output stringlengths 9 73.4k |
|---|---|
Sergey has made N measurements. Now, he wants to know the average value of the measurements made.
In order to make the average value a better representative of the measurements, before calculating the average, he wants first to remove the highest K and the lowest K measurements. After that, he will calculate the averag... | for t in xrange(int(raw_input())):
n, k = map(int, raw_input().split())
if k == 0:
a = map(int, raw_input().split())
else:
a = sorted(map(int, raw_input().split()))[k:-k]
print '{:.6f}'.format(float(sum(a))/len(a)) |
Sonya decided to organize an exhibition of flowers. Since the girl likes only roses and lilies, she decided that only these two kinds of flowers should be in this exhibition.
There are n flowers in a row in the exhibition. Sonya can put either a rose or a lily in the i-th position. Thus each of n positions should cont... | //package math_codet;
import java.io.*;
import java.util.*;
/******************************************
* AUTHOR: AMAN KUMAR SINGH *
* INSTITUITION: KALYANI GOVERNMENT ENGINEERING COLLEGE *
******************************************/
public class lets_do {
InputReader in;
PrintWriter o... |
Let s(x) be sum of digits in decimal representation of positive integer x. Given two integers n and m, find some positive integers a and b such that
* s(a) ≥ n,
* s(b) ≥ n,
* s(a + b) ≤ m.
Input
The only line of input contain two integers n and m (1 ≤ n, m ≤ 1129).
Output
Print two lines, one for decimal... |
n,m=map(int,raw_input().split())
print int("4"*n+'5')
print int("5"*n+'5')
|
After learning a lot about space exploration, a little girl named Ana wants to change the subject.
Ana is a girl who loves palindromes (string that can be read the same backwards as forward). She has learned how to check for a given string whether it's a palindrome or not, but soon she grew tired of this problem, so s... | #include <bits/stdc++.h>
const int Inf = 2 * 1000 * 1000 * 1000;
long long LINF = (long long)4e18;
using namespace std;
int cnt[26];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<string> a(n);
map<int, int> bit;
vector<int> masks(n);
long long ans = 0;
fo... |
Polycarp is an introvert person. In fact he is so much of an introvert that he plays "Monsters and Potions" board game alone. The board of the game is a row of n cells. The cells are numbered from 1 to n from left to right. There are three types of cells: a cell containing a single monster, a cell containing a single p... | #include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> v[200];
int b[201];
int a[202];
int name[202];
int vis[200];
int main() {
cin >> n >> m;
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
v[x].push_back(y);
name[x] = i + 1;
}
for (int i = 1; i <= n; i++) cin >> a[i];
fo... |
Ivan wants to play a game with you. He picked some string s of length n consisting only of lowercase Latin letters.
You don't know this string. Ivan has informed you about all its improper prefixes and suffixes (i.e. prefixes and suffixes of lengths from 1 to n-1), but he didn't tell you which strings are prefixes an... | def is_suffix(par,child):
l=len(child)
if par[n-l-1:] == child:
return 1
return 0
def is_prefix(par,child):
l=len(child)
if par[:l] ==child:
return 1
return 0
def make(pri_par,sec_par,f,s):
ans=[0 for i in range(2*n-2)]
ans[f]='P'
ans[s]='S'
for i in range(2, 2 ... |
We all know that a superhero can transform to certain other superheroes. But not all Superheroes can transform to any other superhero. A superhero with name s can transform to another superhero with name t if s can be made equal to t by changing any vowel in s to any other vowel and any consonant in s to any other cons... | import java.util.*;
public class SuperHeroTransformation {
static boolean isVow(char c) {
if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')return true;
else return false;
}
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
String s=sc.nextLine();
String t=sc.nextLine();
if(s.length()... |
For a given set of two-dimensional points S, let's denote its extension E(S) as the result of the following algorithm:
Create another set of two-dimensional points R, which is initially equal to S. Then, while there exist four numbers x_1, y_1, x_2 and y_2 such that (x_1, y_1) ∈ R, (x_1, y_2) ∈ R, (x_2, y_1) ∈ R and (... | import java.lang.*;
import java.math.*;
import java.util.*;
import java.io.*;
public class Main {
class Node {
int x;
int y;
public Node(int x,int y){
this.x=x;
this.y=y;
}
public boolean equals(Object o){
Node c=(Node)o;
return x==c.x && y==c.y;
}
public int... |
Let s be some string consisting of symbols "0" or "1". Let's call a string t a substring of string s, if there exists such number 1 ≤ l ≤ |s| - |t| + 1 that t = s_l s_{l+1} … s_{l + |t| - 1}. Let's call a substring t of string s unique, if there exist only one such l.
For example, let s = "1010111". A string t = "010... | n, k = map(int, input().split())
strr = ""
while len(strr) < n:
strr += "0" * ((n-k) // 2) + "1"
strr = strr[:n]
print(strr) |
Misha was interested in water delivery from childhood. That's why his mother sent him to the annual Innovative Olympiad in Irrigation (IOI). Pupils from all Berland compete there demonstrating their skills in watering. It is extremely expensive to host such an olympiad, so after the first n olympiads the organizers int... | #!/usr/bin/env python
from __future__ import division, print_function
import operator as op
import os
import sys
from bisect import bisect_left, bisect_right, insort
from io import BytesIO, IOBase
from itertools import chain, repeat, starmap
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
... |
Yet another education system reform has been carried out in Berland recently. The innovations are as follows:
An academic year now consists of n days. Each day pupils study exactly one of m subjects, besides, each subject is studied for no more than one day. After the lessons of the i-th subject pupils get the home ta... | import java.io.* ;
import java.util.*;
import static java.lang.Math.* ;
import static java.util.Arrays.* ;
public class Main {
public static void main(String[] args) {
new Main().solveProblem();
out.close();
}
static Scanner in = new Scanner(new InputStreamR... |
You play your favourite game yet another time. You chose the character you didn't play before. It has str points of strength and int points of intelligence. Also, at start, the character has exp free experience points you can invest either in strength or in intelligence (by investing one point you can either raise stre... | from sys import stdin
input=stdin.readline
R=lambda:map(int,input().split())
I=lambda:int(input())
S=lambda:input().rstrip('\n')
for _ in range(I()):
a,b,c=R()
ans=0
l=0;r=c
while l<=r:
m=(l+r)//2
if a+m>b+(c-m):ans=c-m+1;r=m-1
else:l=m+1
print(ans) |
A two dimensional array is called a bracket array if each grid contains one of the two possible brackets — "(" or ")". A path through the two dimensional array cells is called monotonous if any two consecutive cells in the path are side-adjacent and each cell of the path is located below or to the right from the previo... | #include <bits/stdc++.h>
int main() {
int N, M;
long long int what;
scanf("%d %d %I64i", &N, &M, &what);
static int data[205][205];
static int p[205 * 205];
int i, j;
for (i = 0; i < N; i++) {
for (j = 0; j < M; j++) {
scanf("%d", &(data[i][j]));
(data[i][j])--;
p[data[i][j]] = i + j... |
An arithmetic progression is such a non-empty sequence of numbers where the difference between any two successive numbers is constant. This constant number is called common difference. For example, the sequence 3, 7, 11, 15 is an arithmetic progression. The definition implies that any sequences whose length equals 1 or... | #include <bits/stdc++.h>
using namespace std;
int n, s, b, a[30000], last, s1, s2;
bool check = false, f[30000];
bool search(int x, int y) {
int k, l;
bool out;
memset(f, false, sizeof(f));
f[x] = true;
f[y] = true;
if (!(y == n - 1 || y == n - 2)) {
for (int i = y + 1; i < n; i++)
if (a[i] - last... |
The Oak has n nesting places, numbered with integers from 1 to n. Nesting place i is home to b_i bees and w_i wasps.
Some nesting places are connected by branches. We call two nesting places adjacent if there exists a branch between them. A simple path from nesting place x to y is given by a sequence s_0, …, s_p of di... | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 3005;
const long long INF = 1e16;
const int MOD = 998244353;
long long b[MAXN], w[MAXN], size[MAXN];
pair<long long, long long> dp[MAXN][MAXN], tmp[MAXN];
int n, m, T;
vector<int> e[MAXN];
void dfs(int u, int fa) {
dp[u][0] = make_pair(0, b[u]);
size[u]... |
Jaber is a superhero in a large country that can be described as a grid with n rows and m columns, where every cell in that grid contains a different city.
Jaber gave every city in that country a specific color between 1 and k. In one second he can go from the current city to any of the cities adjacent by the side or ... | #include <bits/stdc++.h>
using namespace std;
int n, m, K, Q;
int color[1010][1010];
int dis[45][1010][1010];
bool st[45];
int dx[4] = {0, 0, 1, -1}, dy[4] = {1, -1, 0, 0};
queue<pair<int, int> > q[45];
vector<pair<int, int> > vec[45];
void bfs(int target) {
memset(st, false, sizeof st);
int x, y;
while (q[target... |
It's the year 5555. You have a graph, and you want to find a long cycle and a huge independent set, just because you can. But for now, let's just stick with finding either.
Given a connected graph with n vertices, you can choose to either:
* find an independent set that has exactly ⌈√{n}⌉ vertices.
* find a simpl... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.util.TreeSet;
import java.util.ArrayList;
import java.util.HashSet;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual ... |
That's right. I'm a Purdue student, and I shamelessly wrote a problem about trains.
There are n stations and m trains. The stations are connected by n-1 one-directional railroads that form a tree rooted at station 1. All railroads are pointed in the direction from the root station 1 to the leaves. A railroad connects ... | #include <bits/stdc++.h>
using namespace std;
const long long iinf = 1e9 + 10;
const long long inf = 1ll << 60;
const long long mod = 1e9 + 7;
void GG() {
cout << "0\n";
exit(0);
}
long long mpow(long long a, long long n, long long mo = mod) {
long long re = 1;
while (n > 0) {
if (n & 1) re = re * a % mo;
... |
You are given two arrays a_1, a_2, ... , a_n and b_1, b_2, ... , b_m. Array b is sorted in ascending order (b_i < b_{i + 1} for each i from 1 to m - 1).
You have to divide the array a into m consecutive subarrays so that, for each i from 1 to m, the minimum on the i-th subarray is equal to b_i. Note that each element ... | #include <bits/stdc++.h>
using namespace std;
template <typename _t>
inline void read(_t &x) {
x = 0;
_t fu = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') fu = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 3) + (x << 1) + (ch & 15);
ch = getchar();... |
This problem is split into two tasks. In this task, you are required to find the minimum possible answer. In the task Village (Maximum) you are required to find the maximum possible answer. Each task is worth 50 points.
There are N houses in a certain village. A single villager lives in each of the houses. The houses ... | #include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long f = 1, ans = 0;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
ans = ans * 10 + c - '0';
c = getchar();
}
return f * ans;
}
const long l... |
You are given m sets of integers A_1, A_2, …, A_m; elements of these sets are integers between 1 and n, inclusive.
There are two arrays of positive integers a_1, a_2, …, a_m and b_1, b_2, …, b_n.
In one operation you can delete an element j from the set A_i and pay a_i + b_j coins for that.
You can make several (ma... | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m;
int a[N], b[N], fa[2 * N];
long long tot = 0;
int Find(int x) { return fa[x] == x ? x : fa[x] = Find(fa[x]); }
struct edge {
int u, v, val;
bool operator<(const edge& rhs) const { return val > rhs.val; }
};
vector<edge> v;
int main() {
... |
This is the hard version of the problem. The only difference is in the constraint on q. You can make hacks only if all versions of the problem are solved.
Zookeeper has been teaching his q sheep how to write and how to add. The i-th sheep has to write exactly k non-negative integers with the sum n_i.
Strangely, sheep... | #include <bits/stdc++.h>
const int kN = 1000000 + 5;
using LL = long long;
const LL inf = 1e18;
int k;
int f[6];
LL dp[kN];
int ten[6] = {1, 10, 100, 1000, 10000, 100000};
int main() {
scanf("%d", &k);
for (int i = 0; i < 6; ++i) {
scanf("%d", &f[i]);
}
std::fill(dp, dp + kN, -inf);
dp[0] = 0;
for (int ... |
You are given a string s, consisting of brackets of two types: '(', ')', '[' and ']'.
A string is called a regular bracket sequence (RBS) if it's of one of the following types:
* empty string;
* '(' + RBS + ')';
* '[' + RBS + ']';
* RBS + RBS.
where plus is a concatenation of two strings.
In one move... | import java.util.*;
public class Two_Brackets {
public static void main(String[] args){
Scanner in=new Scanner(System.in);
int t= in.nextInt();
in.nextLine();
while (t-->0){
String s=in.nextLine();
int n=s.length();
Stack<Character>stack1=new Stack... |
You are given two integers n and k.
You should create an array of n positive integers a_1, a_2, ..., a_n such that the sum (a_1 + a_2 + ... + a_n) is divisible by k and maximum element in a is minimum possible.
What is the minimum possible maximum element in a?
Input
The first line contains a single integer t (1 ≤ ... | import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
from collections import *
ORDA = 97 # a
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return [int(i) for i in input().split()]
def lcm(a, b): return abs(a * b)... |
In the house where Krosh used to live, he had n cupboards standing in a line, the i-th cupboard had the height of h_i. Krosh moved recently, but he wasn't able to move the cupboards with him. Now he wants to buy n new cupboards so that they look as similar to old ones as possible.
Krosh does not remember the exact hei... | //starusc
#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){
int x=0,f=1,c=getchar();
while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
while(isdigit(c)){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
return f==1?x:-x;
}
const int N=1e6+4;
int n,L,R,k=1,b,mn,w[N],tag[N],qwq[N],d[N],a[N];
set<... |
You are given an integer x. Can you make x by summing up some number of 11, 111, 1111, 11111, …? (You can use any number among them any number of times).
For instance,
* 33=11+11+11
* 144=111+11+11+11
Input
The first line of input contains a single integer t (1 ≤ t ≤ 10000) — the number of testcases.
The fi... | //import java.lang.*;
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Solution sol = new Solution();
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
int num = sc.nextInt();
boolean... |
Sherlock Holmes found a mysterious correspondence of two VIPs and made up his mind to read it. But there is a problem! The correspondence turned out to be encrypted. The detective tried really hard to decipher the correspondence, but he couldn't understand anything.
At last, after some thought, he thought of somethin... | #include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int n;
int dp[102][2602];
char s[102];
int main() {
dp[0][0] = 1;
for (int i = 1; i <= 100; i++)
for (int sum = 1; sum <= 2600; sum++)
for (int j = 1; j <= 26 && j <= sum; j++) {
dp[i][sum] += dp[i - 1][sum - j];
if ... |
In ABBYY a wonderful Smart Beaver lives. This time, he began to study history. When he read about the Roman Empire, he became interested in the life of merchants.
The Roman Empire consisted of n cities numbered from 1 to n. It also had m bidirectional roads numbered from 1 to m. Each road connected two different citie... | #include <bits/stdc++.h>
#pragma comment(linker, "/stack:64000000")
using namespace std;
const int MAXN = 100000 + 10;
vector<int> g[MAXN];
bool used[MAXN];
int timer, tin[MAXN], fup[MAXN], color[MAXN];
int n, cnt = 0;
set<pair<int, int> > bridges;
void IS_BRIDGE(int a, int b) {
bridges.insert(make_pair(min(a, b), ma... |
Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a.
What is the least number of flagstones needed to pave the Square? It'... | import math
def main():
n, m, a = map(int, input().split())
sq_area = n * m
stone_area = a * a
if stone_area > sq_area:
return 1
return math.ceil(m / a) * math.ceil(n / a)
if __name__ == '__main__':
print(main())
|
You've got an array a, consisting of n integers: a1, a2, ..., an. Your task is to find a minimal by inclusion segment [l, r] (1 ≤ l ≤ r ≤ n) such, that among numbers al, al + 1, ..., ar there are exactly k distinct numbers.
Segment [l, r] (1 ≤ l ≤ r ≤ n; l, r are integers) of length m = r - l + 1, satisfying the given... | #include <bits/stdc++.h>
using namespace std;
int n, k, a[100005], f[100005], sum;
int main() {
scanf("%d %d", &n, &k);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (!f[a[i]]) sum++;
f[a[i]]++;
}
if (sum < k) {
printf("-1 -1");
return 0;
}
int r = n;
while (sum != k) {
f[a... |
Piglet has got a birthday today. His friend Winnie the Pooh wants to make the best present for him — a honey pot. Of course Winnie realizes that he won't manage to get the full pot to Piglet. In fact, he is likely to eat all the honey from the pot. And as soon as Winnie planned a snack on is way, the pot should initial... | #include <bits/stdc++.h>
using namespace std;
inline int gi() {
int f = 1, sum = 0;
char ch = getchar();
while (ch > '9' || ch < '0') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
sum = (sum << 3) + (sum << 1) + ch - '0';
ch = getchar();
}
return f * sum;
}
do... |
Dima's got a staircase that consists of n stairs. The first stair is at height a1, the second one is at a2, the last one is at an (1 ≤ a1 ≤ a2 ≤ ... ≤ an).
Dima decided to play with the staircase, so he is throwing rectangular boxes at the staircase from above. The i-th box has width wi and height hi. Dima throws eac... | import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Stream;
import java.util.Vector;
import static java.lang.Math.*;
public class icpc
{
public static void main(String[] args)throws IOException
{
BufferedReader in = new BufferedReader(new InputStreamReader(System... |
Greg has an array a = a1, a2, ..., an and m operations. Each operation looks as: li, ri, di, (1 ≤ li ≤ ri ≤ n). To apply operation i to the array means to increase all array elements with numbers li, li + 1, ..., ri by value di.
Greg wrote down k queries on a piece of paper. Each query has the following form: xi, yi, ... | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, k;
cin >> n >> m >> k;
vector<unsigned long long> a(n);
vector<long long> l(m + 1);
vector<int> r(m + 1);
vector<unsigned long long> p(m + 1);
unordered_map<long long, long long> d;
for (int i = 0; i < n; i++) {
cin >> a[i];
... |
Professor Vasechkin is studying evolution of worms. Recently he put forward hypotheses that all worms evolve by division. There are n forms of worms. Worms of these forms have lengths a1, a2, ..., an. To prove his theory, professor needs to find 3 different forms that the length of the first form is equal to sum of len... | //package round_31;
import java.util.Scanner;
public class A {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int []a = new int[n+1];
for (int i = 1; i <= n; i++) {
a[i] = sc.nextInt();
}
for (int i = 1; i <=n; i++) {
for (int j = 1; j <= n; j++)... |
Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't need dominoes, though: he uses rectangular magnets instead. Each magnet has two poles, positive (a "plus") and negative (a "minus"). If two magnets are put together at a close distance, then the like poles will repel each other and the oppo... | s=0
prev=''
for i in range(int(input())):
kk=input()
if kk!=prev:
s+=1
prev=kk
print(s)
|
Let's call an array consisting of n integer numbers a1, a2, ..., an, beautiful if it has the following property:
* consider all pairs of numbers x, y (x ≠ y), such that number x occurs in the array a and number y occurs in the array a;
* for each pair x, y must exist some position j (1 ≤ j < n), such that at leas... | #include <bits/stdc++.h>
using namespace std;
template <class T>
inline T bigmod(T p, T e, T M) {
if (e == 0) return 1;
if (e % 2 == 0) {
T t = bigmod(p, e / 2, M);
return (t * t) % M;
}
return (bigmod(p, e - 1, M) * p) % M;
}
template <class T>
inline T gcd(T a, T b) {
if (b == 0) return a;
return ... |
On a cold winter evening our hero Vasya stood in a railway queue to buy a ticket for Codeforces championship final. As it usually happens, the cashier said he was going to be away for 5 minutes and left for an hour. Then Vasya, not to get bored, started to analyze such a mechanism as a queue. The findings astonished Va... | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 111111;
const int SZ = 400;
struct Part {
int Max;
int cnt;
int* a;
Part() {
a = new int[SZ];
Max = -1;
cnt = 0;
}
Part(const Part& p) {
a = p.a;
Max = p.Max;
cnt = p.cnt;
}
void calcMax() { Max = *max_element(a, a + ... |
You have probably registered on Internet sites many times. And each time you should enter your invented password. Usually the registration form automatically checks the password's crypt resistance. If the user's password isn't complex enough, a message is displayed. Today your task is to implement such an automatic che... | password=raw_input()
characters=["!","?",".",",","_"]
list=[]
for i in range(len(password)):
list.append(password[i-1])
digit=0
upper=0
lower=0
char=0
for q in list:
if q.isdigit():
digit=digit+1
if q.isupper():
upper=upper+1
if q.islower():
lower=lower+1
if q in characters:
char=char+1
if digit!=0 and upp... |
Our child likes computer science very much, especially he likes binary trees.
Consider the sequence of n distinct positive integers: c1, c2, ..., cn. The child calls a vertex-weighted rooted binary tree good if and only if for every vertex v, the weight of v is in the set {c1, c2, ..., cn}. Also our child thinks that ... | #include <bits/stdc++.h>
namespace CTL {
using namespace std;
struct MultiplicativeInverseOfPolynomial {
static long long pow(long long a, long long b, long long c) {
long long r = 1;
for (; b; b& 1 ? r = r * a % c : 0, b >>= 1, a = a * a % c)
;
return r;
}
static void ntt(vector<long long>& a, ... |
Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment.
Find all integer solutions x (0 < x < 109) of the equation:
x = b·s(x)a + c,
where a, b, c are some predetermined constant values and function s(x) determines the sum of all digits in... | a,b,c=map(int,input().split())
L=[]
for i in range(1,82):
val=b*(i**a)+c
check=0
if val>0 and val<10**9:
s=str(val)
for j in s:
check+=int(j)
if check==i:
L.append(val)
if len(L)==0:
print(0)
else:
print(len(L))
print(*L) |
Let's denote as <image> the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤ x ≤ r, and <image> is maximum possible. If there are multiple such numbers find the sma... | n = int(input())
for i in range(n):
l,r=map(int,input().split())
while(l|(l+1)<=r): # or make like max function here .
l|=l+1 # or here like equal
print(l)
|
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of n row with m pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose an... | #include <bits/stdc++.h>
using namespace std;
int color[1024][1024];
int main() {
int n, m, k;
cin >> n >> m >> k;
for (int i = 1; i <= k; i++) {
int x, y;
scanf("%d %d", &x, &y);
if (color[x - 1][y - 1] && color[x][y - 1] && color[x - 1][y]) {
printf("%d\n", i);
exit(0);
}
if (col... |
Pasha decided to invite his friends to a tea party. For that occasion, he has a large teapot with the capacity of w milliliters and 2n tea cups, each cup is for one of Pasha's friends. The i-th cup can hold at most ai milliliters of water.
It turned out that among Pasha's friends there are exactly n boys and exactly n... | n = map(int, raw_input().split())
v = map(float, raw_input().split())
v.sort()
vg = min(v[0], v[n[0]] / 2.0)
print "%.6lf" % min(vg * 3 * n[0], n[1])
|
In this problem we consider Boolean functions of four variables A, B, C, D. Variables A, B, C and D are logical and can take values 0 or 1. We will define a function using the following grammar:
<expression> ::= <variable> | (<expression>) <operator> (<expression>)
<variable> ::= 'A' | 'B' | 'C' | 'D' | 'a' | 'b' | '... | #include <bits/stdc++.h>
const int Maxn = 500;
const int Maxm = (1 << 16);
const int Mod = 1000000007;
int n, m;
char s[Maxn + 5];
int f[Maxn + 5][Maxm + 5];
int lson[Maxn + 5], rson[Maxn + 5], id_tot;
int g[9][Maxm + 5];
void init() {
for (int i = 0; i < 4; i++) {
int t = 0;
for (int j = 0; j < 16; j++) {
... |
Kevin and Nicky Sun have invented a new game called Lieges of Legendre. In this game, two players take turns modifying the game state with Kevin moving first. Initially, the game is set up so that there are n piles of cows, with the i-th pile containing ai cows. During each player's turn, that player calls upon the pow... | #include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
int even(int x) {
if (x <= 2) return x;
return (x & 1) ^ 1;
}
int odd(int x) {
if (x <= 3) return x & 1;
if (x == 4) return 2;
if (x & 1) return 0;
int cnt = odd(x / 2);
if (cnt == 1) return 2;
return 1;
}
int main() {
ios_base::sy... |
Two positive integers a and b have a sum of s and a bitwise XOR of x. How many possible values are there for the ordered pair (a, b)?
Input
The first line of the input contains two integers s and x (2 ≤ s ≤ 1012, 0 ≤ x ≤ 1012), the sum and bitwise xor of the pair of positive integers, respectively.
Output
Print a s... | #include <bits/stdc++.h>
using namespace std;
struct _ {
_() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
} _;
int main() {
long long s, x;
cin >> s >> x;
auto diff = (s - x);
if (diff % 2 || diff < 0 || (x << 1) & diff) {
cout << 0;
} else {
long long count = 1;
for (... |
Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at a1 percent and second one is charged at a2 percent. You can connect charger to a joystick only at the beginning of each minute. In one minute joystick either discharges by 2 percent (if not c... | import java.io.*;
public class Joystick
{
public static void main(String[] args)throws IOException
{
BufferedReader buff=new BufferedReader(new InputStreamReader(System.in));
int a,b;
String []s=buff.readLine().split("\\s");
a=Integer.parseInt(s[0]);
b=Integer.parseInt(s[1]);
int sum=0;
if(Math.max(a,b)... |
Theseus has just arrived to Crete to fight Minotaur. He found a labyrinth that has a form of a rectangular field of size n × m and consists of blocks of size 1 × 1.
Each block of the labyrinth has a button that rotates all blocks 90 degrees clockwise. Each block rotates around its center and doesn't change its positio... | #include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const int MX = 4;
const int INF = 1e9 + 9;
const int N = 1005;
vector<vector<vector<int>>> dis(N, vector<vector<int>>(N, vector<int>(4, INF)));
vector<vector<int>> v(N, vector<int>(N));
v... |
Anton and Dasha like to play different games during breaks on checkered paper. By the 11th grade they managed to play all the games of this type and asked Vova the programmer to come up with a new game. Vova suggested to them to play a game under the code name "dot" with the following rules:
* On the checkered pape... | #include <bits/stdc++.h>
using namespace std;
int vis[410][410][2][2];
int _x, _y, n, d;
int dx[25], dy[25];
int dfs(int x, int y, int fip_p1, int fip_p2, int idx) {
if (x * x + y * y > d * d) {
return 1;
}
if (vis[x + 200][y + 200][fip_p1][fip_p2]) {
return vis[x + 200][y + 200][fip_p1][fip_p2];
}
in... |
Recently Adaltik discovered japanese crosswords. Japanese crossword is a picture, represented as a table sized a × b squares, and each square is colored white or black. There are integers to the left of the rows and to the top of the columns, encrypting the corresponding row or column. The number of integers represents... | n=int(input())
s=input()
arr,k=[],0
for i in range(len(s)):
if(s[i]=='B'):
k+=1
else:
if(k>0):
arr.append(k)
k=0
if(k>0):
arr.append(k)
print(len(arr))
print(*arr,sep=' ') |
Just to remind, girls in Arpa's land are really nice.
Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight wi and some beauty bi. Also each Hos may have some friends. Hoses are divided in some friendship groups. Two Hoses x and y are in the same friendship group if and only if... | #include <bits/stdc++.h>
using namespace std;
const int MAX = 2005;
const int INF = 0x3f3f3f3f;
int n, m, w, c[MAX], v[MAX], fa[MAX];
long long dp[2][MAX * 100];
vector<int> ve[MAX];
int find(int x) { return x == fa[x] ? x : fa[x] = find(fa[x]); }
void Union(int u, int v) {
int a = find(u);
int b = find(v);
if (a... |
While Mahmoud and Ehab were practicing for IOI, they found a problem which name was Longest common subsequence. They solved it, and then Ehab challenged Mahmoud with another problem.
Given two strings a and b, find the length of their longest uncommon subsequence, which is the longest string that is a subsequence of o... | s1 = raw_input()
s2 = raw_input()
if(s1==s2):
print -1
elif(len(s1)==len(s2)):
print len(s1)
elif(len(s1)>len(s2)):
print len(s1)
else:
print len(s2)
|
Sasha and Kolya decided to get drunk with Coke, again. This time they have k types of Coke. i-th type is characterised by its carbon dioxide concentration <image>. Today, on the party in honour of Sergiy of Vancouver they decided to prepare a glass of Coke with carbon dioxide concentration <image>. The drink should als... | #include <bits/stdc++.h>
using namespace std;
const int C = 1e6, INF = 1e9;
int n, m, mk[2 * C + 5], d[2 * C + 5];
vector<int> a;
queue<int> q;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
int x;
scanf("%d", &x);
x -= n;
if (mk[x + C] == 0) {
mk[x + C] = 1;
a.push_b... |
Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant.
Shop, where Noora is working, has a plan on the following n days. For each day sales manager... | #include <bits/stdc++.h>
using namespace std;
vector<long long> sale;
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
long long n, f, ans = 0;
cin >> n >> f;
for (long long i = 0; i < n; i++) {
long long k, l;
cin >> k >> l;
ans += min(k, l);
sale.push_back(min(2 * k, l) - min(k, ... |
Pay attention: this problem is interactive.
Penguin Xoriy came up with a new game recently. He has n icicles numbered from 1 to n. Each icicle has a temperature — an integer from 1 to 109. Exactly two of these icicles are special: their temperature is y, while a temperature of all the others is x ≠ y. You have to find... | #include <bits/stdc++.h>
#pragma comment(linker, "/STACK:216000000")
using namespace std;
const long long MAX = 100000000LL * 100000000LL;
const long long MIN = numeric_limits<long long>::min();
const double PI = 3.14159265358979;
const long long MOD = 1000000007LL;
template <class T>
ostream& operator<<(ostream& out, ... |
Masha and Grisha like studying sets of positive integers.
One day Grisha has written a set A containing n different integers ai on a blackboard. Now he asks Masha to create a set B containing n different integers bj such that all n2 integers that can be obtained by summing up ai and bj for all possible pairs of i and ... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.Random;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.ArrayList;
... |
There is an automatic door at the entrance of a factory. The door works in the following way:
* when one or several people come to the door and it is closed, the door immediately opens automatically and all people immediately come inside,
* when one or several people come to the door and it is open, all people im... | #include <bits/stdc++.h>
using namespace std;
using namespace std;
long long arr[1000000];
int main() {
long long n, m, a, t, time = 0;
while (cin >> n >> m >> a >> t) {
for (int i = 0; i < m; i++) cin >> arr[i];
long long time = 0, ans = 0;
long long k = t / a + 1;
if (arr[0] < a)
time = arr[... |
Valentin participates in a show called "Shockers". The rules are quite easy: jury selects one letter which Valentin doesn't know. He should make a small speech, but every time he pronounces a word that contains the selected letter, he receives an electric shock. He can make guesses which letter is selected, but for eac... | #include <bits/stdc++.h>
using namespace std;
int a[50], b[50], n;
string s, s1;
char c, o;
bool u, v;
int k, kt, k2;
long long rs;
int main() {
cin >> n;
k2 = 26;
while (n--) {
cin >> c >> s;
if (v && ((c == '!') || c == '?'))
rs++;
else {
switch (c) {
case '!': {
k++;
... |
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means... |
n = int(input())
a = input().split()
for j in range(n):
a[j] = int(a[j])
i = 1
last = a[0]
count = 1;
while (i < n and last == a[i]):
i+=1
count+=1
if (i < n):
last = a[i]
buf = 1
i += 1
flag = 1
while (i < n):
if (last == a[i]):
buf += 1
else:
if (count != buf):
flag = 0
break
else:
... |
After waking up at hh:mm, Andrew realised that he had forgotten to feed his only cat for yet another time (guess why there's only one cat). The cat's current hunger level is H points, moreover each minute without food increases his hunger by D points.
At any time Andrew can visit the store where tasty buns are sold (y... | import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;
public class solution implements Runnable {
static class InputReader {
private InputStream stream;
priv... |
Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)!
He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help!
The decomposition is the splitting the edges of the tree in some simple paths in such a way that each two pa... | import java.util.*;
import java.io.*;
public class C{
public static void main(String[] args) throws Exception{
new C().run();
}
private void fail() {
throw new IllegalArgumentException();
}
private void print(String s){
System.out.println(s);
}
private void run()... |
Announcement
************Second Round will be ONLINE instead of ONSITE*************
Problem Statement
Schimdt is teaching Jenko a new technique to excel at bases. He writes n numbers in base k on a piece of paper and also their decimal sum. He doesn’t mention k on the paper. Jenko has to find out the value of k using ... | import sys
n = int(sys.stdin.readline())
s = ["" for _ in xrange(n)]
#for i in xrange(n):
# s[i] = sys.stdin.readline()
s = sys.stdin.readline().split()
m = int(sys.stdin.readline())
#print int('21',3)
d = 0
book = ['A','B','C','D','E','F']
book2 = ['a','b','c','d','e','f']
for ss in s:
for sss in ss:
#print sss
... |
Chandan is an extremely biased person, and he dislikes people who fail to solve all the problems in the interview he takes for hiring people. There are n people on a day who came to be interviewed by Chandan.
Chandan rates every candidate from 0 to 10. He has to output the total ratings of all the people who came in ... | n = int(raw_input())
l = []
for i in xrange(0,n):
x = int(raw_input())
if x == 0 and len(l) != 0:
l.pop()
else:
l.append(x)
print sum(l) |
Little Arjit is the leader of a marvellous fighting army. His team is very good at fighting against all their enemies. But like Hound from Game of Thrones, Little Arjit and his entire team is scared of fire. When they see fire, they feel threatened, and scared like a little child, and don’t even mind giving up from a f... | '''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
if __name__ == '__main__':
cases = int(raw_input())
start = 1
while start <= cases:
line = raw_input()
line = line.split('*')
total_weak = 0
for string in line:
no_of_wea... |
You are given N sticks, the length of the i^th stick being ai . As your professor is very interested in triangles he gives you a problem:
From the N given sticks, choose 3 sticks that form a triangle. If there are many such triangles , choose the sticks in such a way such that the perimeter of the triangle formed is ma... | for t in range(int(raw_input())):
n=int(raw_input())
N=map(int,raw_input().split())
N.sort()
N.reverse()
f=0
for i in range(n-2):
if N[i]-N[i+1]<N[i+2]:
j=i
f=1
break
if f:
print N[j+2],N[j+1],N[j]
else:
print -1 |
A state consists of N cities. Some of these cities are connected to each other by one - way roads. The time taken to travel from a particular city to any other city directly connected to it is 1 hour. The entire map of the state will be given. You will be given Q queries, each query asking you the number of ways to tra... | CONST = 1000000007
def mul(A, B, n, c):
C = []
for i in range(n):
C.append([0] * n)
for i in range(n):
for j in range(n):
for k in range(n):
C[i][j] = (C[i][j] + ((A[i][k] % c) * (B[k][j] % c)) % c) % c
return C
f = dict()
def modExp(A, b, n, c):
if b in f:
return f[b]
if b % 2 == 1:
f[b] = mul(A,... |
You are given a string which comprises of lower case alphabets (a-z), upper case alphabets (A-Z), numbers, (0-9) and special characters like !,-.; etc.
You are supposed to find out which character occurs the maximum number of times and the number of its occurrence, in the given string. If two characters occur equal nu... | def occur():
inp = raw_input()
x = 0
val = inp[0]
for i in inp:
y = inp.count(i)
if y == x:
if val > i:
x = y
val = i
elif y > x:
x = y
val = i
print str(val) + ' ' + str(x)
if __name__ == "__main__":
occur() |
Level 3
Given an array a of size n containing only 0,-1,and 1,
x = number of 1's in a[l,r] (in subarray from l to r)
y = number of -1's in a[l,r] (in subarray from l to r)
For any sub array [l,r] function f is defined as follows
if(y == 0)
f([l,r]) = 0;
else
f([l,r]) = x / y;
Your goal is determine the maximu... | t = int(raw_input())
for i in range(0, t):
n = raw_input()
inp = raw_input()
inp = inp.split('-1')
count = []
for st in inp:
count.append(st.count('1'))
max = 0
for j in range(0, len(count)-1):
if count[j] + count[j+1] > max:
max = count[j] + count[j+1]
if max == 0:
print '0/1'
else:
print... |
Since chandu_don is busy in talking to his girlfriend,he wants you to solve a problem for him requiring range queries.The problem is as follows:-
Given an array of N integers we have to answer Q queries on the array.
Each Query is of the format X Y val where we have to output number of integers between X to Y index i... | # *-* coding: utf-8 *-*
N = int(raw_input())
s = raw_input()
lst = s.split()
Q = int(raw_input())
"""
Hash = []
for i in range(0,123):
new = []
for j in range(0,12345):
new.append(j)
Hash.append(new)
"""
Hash = [[0 for i in range(12349)] for j in range(123)]
for i in range(0,N):
Hash[int(lst[i])][i] = 1
for ... |
SKIT’s canteen sells Patties in packages of 6, 9 or 20 . Thus, it is possible, for example, to buy exactly 15 Patties (with one package of 6 and a second package of 9), but it is not possible to buy exactly 16 Patties, since no non- negative integer combination of 6's, 9's and 20's add up to 16. To determine if it is p... | def ip(n):
if n<=5:
return False
if n>=0 and (n%6==0 or n%9==0 or n%20==0):
return True
else:
return ip(n-6) or ip(n-9) or ip(n-20)
for _ in xrange(input()):
print ip(input()) |
You have a part to play in the Wars to Come.
As everyone knows, Lord Stannis Baratheon (First of His Name, King of the Andals and the First Men, Lord of the Seven Kingdoms and Protector of the Realm) is one true king. Now, he wants to conquer the North. To conquer, he needs to expand his army. And since, Winter is com... | t=int(raw_input())
a=[]
a=map(int,raw_input().split())
m=int(raw_input())
a.sort()
c=0
x=t-1
while c<m:
c=c+a[x]
x=x-1
print (t-x-1) |
Given is an integer x that is greater than or equal to 0, and less than or equal to 1. Output 1 if x is equal to 0, or 0 if x is equal to 1.
Constraints
* 0 \leq x \leq 1
* x is an integer
Input
Input is given from Standard Input in the following format:
x
Output
Print 1 if x is equal to 0, or 0 if x is equal ... | #include<cstdio>
int main(){int x;scanf("%d",&x);printf("%d\n",x^1);} |
Constraints
* All values in input are integers.
* 1\leq N, M\leq 12
* 1\leq X\leq 10^5
* 1\leq C_i \leq 10^5
* 0\leq A_{i, j} \leq 10^5
Input
Input is given from Standard Input in the following format:
N M X
C_1 A_{1,1} A_{1,2} \cdots A_{1,M}
C_2 A_{2,1} A_{2,2} \cdots A_{2,M}
\vdots
C_N A_{N,1} A_{N,2} \cdots A_{... | #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
int n,m,x;
cin >> n >> m >> x;
int a[15],cost;
int inf = 1100000000;
int ans = inf;
int v[15][15];
rep(i,n){
rep(j,m+1) cin >> v[i][j];
}
rep(bit,1<<n){
int cost =0;
vector<int> d(m);
rep(i,n){
if(bit&1<<... |
Takahashi has K 500-yen coins. (Yen is the currency of Japan.) If these coins add up to X yen or more, print `Yes`; otherwise, print `No`.
Constraints
* 1 \leq K \leq 100
* 1 \leq X \leq 10^5
Input
Input is given from Standard Input in the following format:
K X
Output
If the coins add up to X yen or more, prin... | k,x=map(int,input().split());print('YNeos'[500*k<x::2]) |
There are N one-off jobs available. If you take the i-th job and complete it, you will earn the reward of B_i after A_i days from the day you do it.
You can take and complete at most one of these jobs in a day.
However, you cannot retake a job that you have already done.
Find the maximum total reward that you can ea... | #include<bits/stdc++.h>
using namespace std;
struct qwq{
int a,b;
inline bool operator<(const qwq &x)const{
return a<x.a;
}
} x[100005];
priority_queue<int> q;
int main(){
int n,m,i,j=1,s=0;
cin>>n>>m;
for(i=1;i<=n;++i)
cin>>x[i].a>>x[i].b;
sort(x+1,x+n+1);
for(i=1;i<=m;++i){
for(;x[j].a==i&&j<=n;++j)... |
In Takaha-shi, the capital of Republic of AtCoder, there are N roads extending east and west, and M roads extending north and south. There are no other roads. The i-th east-west road from the north and the j-th north-south road from the west cross at the intersection (i, j). Two east-west roads do not cross, nor do two... | #include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <cassert>
#define SIZE 200005
#define INF 1000000000
using namespace std;
typedef long long in... |
You are given N integers; the i-th of them is A_i. Find the maximum possible sum of the absolute differences between the adjacent elements after arranging these integers in a row in any order you like.
Constraints
* 2 \leq N \leq 10^5
* 1 \leq A_i \leq 10^9
* All values in input are integers.
Input
Input is given f... | N = int(input())
A = sorted([int(input()) for i in range(N)])
if N % 2 == 0:
print(2 * (sum(A[N // 2:]) - sum(A[:N // 2])) - (A[N // 2] - A[N // 2 - 1]))
else:
print(2 * (sum(A[N // 2 + 1:]) - sum(A[:N // 2])) - min(A[N // 2] - A[N // 2 - 1], A[N // 2 + 1] - A[N // 2]))
|
There are a total of A + B cats and dogs. Among them, A are known to be cats, but the remaining B are not known to be either cats or dogs.
Determine if it is possible that there are exactly X cats among these A + B animals.
Constraints
* 1 \leq A \leq 100
* 1 \leq B \leq 100
* 1 \leq X \leq 200
* All values in input... | a,b,x=map(int,input().split())
print("YES" if a+b-x>=0 and x>=a else "NO") |
It is November 18 now in Japan. By the way, 11 and 18 are adjacent Lucas numbers.
You are given an integer N. Find the N-th Lucas number.
Here, the i-th Lucas number L_i is defined as follows:
* L_0=2
* L_1=1
* L_i=L_{i-1}+L_{i-2} (i≥2)
Constraints
* 1≤N≤86
* It is guaranteed that the answer is less than 10^{18}.
... | n = int(input())
l = [2, 1]
for i in range(n-1):
l.append(l[i]+l[i+1])
print(l[-1]) |
You are given a string S consisting of lowercase English letters. Determine whether all the characters in S are different.
Constraints
* 2 ≤ |S| ≤ 26, where |S| denotes the length of S.
* S consists of lowercase English letters.
Input
Input is given from Standard Input in the following format:
S
Output
If all ... | s=input();print("yneos"[len(set(s))<len(s)::2]) |
There is an image with a height of H pixels and a width of W pixels. Each of the pixels is represented by either `.` or `*`. The character representing the pixel at the i-th row from the top and the j-th column from the left, is denoted by C_{i,j}.
Extend this image vertically so that its height is doubled. That is, p... | #include<bits/stdc++.h>
using namespace std;
string a[100];
int main()
{
int b,c;
cin>>b>>c;
for(int i=0;i<b;i++){
cin>>a[i];
}
for(int j=0;j<b;j++){
cout<<a[j]<<endl;
cout<<a[j]<<endl;
}
} |
Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it. He has A_i cards with an integer i.
Two cards can form a pair if the absolute value of the difference of the integers written on them is at most 1.
Snuke wants to create the maximum number of pairs from his card... | a = int(input())
count = 0
mod = 0
for i in range(a):
b = int(input())
if b == 0:
mod = 0
c = b + mod
if not c==0:
count += c//2
mod = c%2
print(count) |
There is a magic room in a homestead. The room is paved with H × W tiles. There are five different tiles:
* Tile with a east-pointing arrow
* Tile with a west-pointing arrow
* Tile with a south-pointing arrow
* Tile with a north-pointing arrow
* Tile with nothing
Once a person steps onto a tile which has an arrow, ... | import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner scn = new Scanner(System.in);
int N, M, ans;
boolean loop;
while ((N = scn.nextInt()) != 0) {
M = scn.nextInt();
int[] tile = new int[N * M];
boolean[] through = new boolean[N * M];
String buf = scn.next... |
Based on the information of the time when study started and the time when study ended, check whether the total time studied in one day is t or more, and if not, create a program to find the shortage time. Time is one unit per hour, and minutes and seconds are not considered. The time is expressed in 24-hour notation in... | import sys
f = sys.stdin
while True:
t = int(f.readline())
if t == 0:
break
n = int(f.readline())
sf = (map(int, f.readline().split()) for _ in range(n))
rest = t - sum(f - s for s, f in sf)
print('OK' if rest <= 0 else rest) |
In the ancient nation of Iwashiro, priests pray to calm disasters in the event of a disaster.
The priest selects the character string S from the ancient documents and proceeds with the ritual by repeating the following.
* Select one place in the string $ S $, replace the character written there with another character... | #include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (l... |
Taro, a boy who hates any inefficiencies, pays coins so that the number of coins to be returned as change is minimized in order to do smoothly when he buys something.
One day, however, he doubt if this way is really efficient. When he pays more number of coins, a clerk consumes longer time to find the total value. May... | /*
* Author: NomadThanatos
* Created Time: 2011/8/31 13:51:49
* File Name: J.cpp
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;
#define out(v) cerr << #v << ": " << (v) << endl
#define SZ(v) ((int)(v).size... |
A laser beam generator, a target object and some mirrors are placed on a plane. The mirrors stand upright on the plane, and both sides of the mirrors are flat and can reflect beams. To point the beam at the target, you may set the beam to several directions because of different reflections. Your job is to find the shor... | #include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define sz size()
using namespace std;
typedef double D;
typedef complex<D> P;
typedef pair<P,P> L;
const D EPS = 1e-8;
const D PI = acos(-1);
inline pair<P,P> norm(const P &p){return make_pai... |
You are a judge of a programming contest. You are preparing a dataset for a graph problem to seek for the cost of the minimum cost path. You've generated some random cases, but they are not interesting. You want to produce a dataset whose answer is a desired value such as the number representing this year 2010. So you ... | #include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
typedef tuple< int, int, int > Pi;
struct edge
{
int to, cost;
};
int N, M, C;
vector< vector< edge > > graph;
int min_cost[100][101];
int Dijkstra()
{
priority_queue< Pi, vector< Pi >, greater< Pi > > que;
fill_n(*min_cost, 100 * 101, ... |
Background
The kindergarten attached to the University of Aizu is a kindergarten where children who love programming gather. Yu, one of the kindergarten children, loves rectangular blocks as much as programming. Yu-kun has been enthusiastic about making mountains with building blocks recently.
Yu-kun was playing with... | #include <bits/stdc++.h>
using namespace std;
typedef int flow_type;
struct edge {
int to;
flow_type cap;
int rev;
edge(int t, flow_type c, int r):to(t), cap(c), rev(r){}
};
const flow_type INF = 0xfffffff;
vector<vector<edge> > G;
vector<int> level;
vector<int> iter;
inline void init(int V) {
G.assign(V, vect... |
You are given plans of rooms of polygonal shapes. The walls of the rooms on the plans are placed parallel to either x-axis or y-axis. In addition, the walls are made of special materials so they reflect light from sources as mirrors do, but only once. In other words, the walls do not reflect light already reflected at ... | #include<bits/stdc++.h>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-6)
#define COUNTER_CLOCKWISE 1
#define CLOCKWISE -1
#define ONLINE_BACK 2
#define ONLINE_FRONT -2
#define ON_SEGMENT 0
#define equals(a,b) (fabs((a)-(b)) < EPS)
using namespace std;
class Point{
public:
dou... |
Whist is a game played by four players with a standard deck of playing cards. The players seat around a table, namely, in north, east, south, and west. This game is played in a team-play basis: the players seating opposite to each other become a team. In other words, they make two teams we could call the north-south te... | #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include... |
An undirected graph is given. Each edge of the graph disappears with a constant probability. Calculate the probability with which the remained graph is connected.
Input
The first line contains three integers N (1 \leq N \leq 14), M (0 \leq M \leq 100) and P (0 \leq P \leq 100), separated by a single space. N is the... | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include... |
There is a game called Sim Forest 2013. In this game, the player can become a forest god and raise forest animals.
Animals hatch from eggs and breed. When certain conditions are met, eggs are mutated with a certain probability to give birth to new races of animals.
There is an animal encyclopedia in this game, and wh... |
import static java.lang.Math.*;
import static java.lang.System.*;
import java.lang.reflect.Array;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import java.util.Scanner;
class Main {
public static Scanner sc = new Scanner(in);
public static Random ran... |
C: Digital Clock
story
Aizu Nyan has recently caught a cold. I can't get out of bed because I'm too lazy. The spicy appearance is also cute.
However, Aizu Nyan, who had no choice but to spare time, came up with a way to play with the digital clock under the pillow. The number of glowing bars of a digital clock as sh... | #include<bits/stdc++.h>
#define int long long
using namespace std;
int days[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
bool isLeap(int year){return (year%4 == 0 && (year%100 != 0 || year%400 == 0));}
int n, b[14][7], C[100], num[10]={6, 2, 5, 5, 4, 5, 6, 3, 7, 6};
int check(char c, int idx){
int ... |
problem
AOR Ika wants to create a strong password that consists only of lowercase letters. AOR Ika-chan, who was given an example of $ N $ of dangerous passwords by a friend, decided to create a password that meets all of the following conditions.
1. The length is at least one character.
2. Different from any contigu... | #include <bits/stdc++.h>
using namespace std;
const double pi = 2 * acos(0.0);
const double eps = 1e-8;
#define REP(i,a,b) for(int i=(a); i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<29)
#define INFLL (1LL<<62)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<... |
String magic
As a witch, you are still practicing magic today. You now have the string X, which consists of lowercase letters, at hand. The task of your training today is to change this string to another string Y.
You have mastered four types of magic that change strings, and you can cast them as many times as you li... | #include<bits/stdc++.h>
using namespace std;
using UL=unsigned int;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(UL i=0; i<(n); i++)
deque<char> X,Y;
LL A,E,S,R;
LL dp[101][101];
bool loop(){
X.clear(); Y.clear();
string SX,SY;
cin>>SX; if(SX=="#") return false;
cin>>SY;
for(char c:SX)... |
Min Element
Given the sequence a_1, a_2, .., a_N.
Find the minimum number in this sequence.
If the minimum value is in more than one place, answer the one with the lowest number.
input
N
a_1 a_2 ... a_N
output
Output the smallest i such that a_i is the minimum value in the sequence.
Constraint
* 1 \ leq N \ ... | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)
int N, A[1 << 18];
int minx = (1 << 30), minid = 0;
int main() {
scanf("%d", &N);
for (int i = 1; i <= N; i++) {
scanf("%d", &A[i]);
if (minx > A[i]) { minx = A[i]; minid = i; }
}
cout << minid << e... |
Write a program which manipulates a disjoint set S = {S1, S2, . . . , Sk}.
First of all, the program should read an integer n, then make a disjoint set where each element consists of 0, 1, ... n−1 respectively.
Next, the program should read an integer q and manipulate the set for q queries. There are two kinds of que... | # class UnionFind:
#
# def __init__(self,n):
# self.roots = range(n)
#
# def
def root(i):
if par[i] == i:
return i
par[i]=root(par[i])
return par[i]
def unite(x,y):
xr = root(x)
yr = root(y)
par[yr] = xr
def same(x,y):
return root(x)==root(y)
n,q = map(int,inpu... |
Remainder of Big Integers
Given two integers $A$ and $B$, compute the remainder of $\frac{A}{B}$.
Input
Two integers $A$ and $B$ separated by a space character are given in a line.
Output
Print the remainder in a line.
Constraints
* $0 \leq A, B \leq 10^{1000}$
* $B \ne 0$
Sample Input 1
5 8
Sample Output... | A, B = map(int, raw_input().split())
print A % B
|
Like most of the demanding childs.Pratik don't stop until he gets that.He keep on repeating the name of that thing again and again.
For example if he want a computer,He will keep on repeating "computer" again and again.
His dad has decided to answer to his demand as "Yes" or "No" without any delay.Otherwise there would... | s=raw_input()
t=int(input())
while t>0:
a,b=map(int,raw_input().split())
if s[(a-1)%len(s)]==s[(b-1)%len(s)]:
print "Yes"
else:
print "No"
t-=1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.