id stringlengths 6 117 | description stringlengths 29 13k | code stringlengths 9 465k | language class label 4
classes | test_samples dict | source class label 5
classes |
|---|---|---|---|---|---|
87_C. Interesting Game_3200 | Two best friends Serozha and Gena play a game.
Initially there is one pile consisting of n stones on the table. During one move one pile should be taken and divided into an arbitrary number of piles consisting of a1 > a2 > ... > ak > 0 stones. The piles should meet the condition a1 - a2 = a2 - a3 = ... = ak - 1 - ak =... |
n = input()
spg = [0] * (n + 1)
xor = [0] * (n + 1)
for i in range(3, n + 1):
k = 2
movs = set()
while k * (k + 1) <= 2 * i:
s = 2 * i - k * (k - 1)
if s % (2 * k) == 0:
a = s / 2 / k
movs.add(xor[a + k - 1] ^ xor[a - 1])
k += 1
mex = 0
while m... | 1Python2 | {
"input": [
"6\n",
"100\n",
"3\n",
"56\n",
"1\n",
"46\n",
"63478\n",
"7578\n",
"56056\n",
"78\n",
"66873\n",
"8149\n",
"35708\n",
"81207\n",
"41385\n",
"37317\n",
"74424\n",
"67817\n",
"684\n",
"15\n",
"96992\n",
"38798\n",
"... | 2CODEFORCES |
87_C. Interesting Game_3201 | Two best friends Serozha and Gena play a game.
Initially there is one pile consisting of n stones on the table. During one move one pile should be taken and divided into an arbitrary number of piles consisting of a1 > a2 > ... > ak > 0 stones. The piles should meet the condition a1 - a2 = a2 - a3 = ... = ak - 1 - ak =... | #include <bits/stdc++.h>
using namespace std;
int dp[100005], ans[100005];
void solve(int num) {
if (dp[num] != -1) return;
ans[num] = -1;
dp[num] = 0;
int i, n = 2, a, sum;
set<int> myset;
myset.clear();
while (2 * num - n * (n - 1) > 0) {
if ((2 * num - n * (n - 1)) % (2 * n) == 0) {
a = (2 * ... | 2C++ | {
"input": [
"6\n",
"100\n",
"3\n",
"56\n",
"1\n",
"46\n",
"63478\n",
"7578\n",
"56056\n",
"78\n",
"66873\n",
"8149\n",
"35708\n",
"81207\n",
"41385\n",
"37317\n",
"74424\n",
"67817\n",
"684\n",
"15\n",
"96992\n",
"38798\n",
"... | 2CODEFORCES |
87_C. Interesting Game_3202 | Two best friends Serozha and Gena play a game.
Initially there is one pile consisting of n stones on the table. During one move one pile should be taken and divided into an arbitrary number of piles consisting of a1 > a2 > ... > ak > 0 stones. The piles should meet the condition a1 - a2 = a2 - a3 = ... = ak - 1 - ak =... | import math
from collections import Counter
n = int(input())
g = [0 for i in range(n + 1)]
prefix_xor = g.copy()
def in_range(d, k):
if (2 * k - d * d + d) % (2 * d) != 0:
return -1
x = (2 * k - d * d + d) / (2 * d)
return int(x) if x > 0 else -1
def mex(arr):
counter = Counter()
for i ... | 3Python3 | {
"input": [
"6\n",
"100\n",
"3\n",
"56\n",
"1\n",
"46\n",
"63478\n",
"7578\n",
"56056\n",
"78\n",
"66873\n",
"8149\n",
"35708\n",
"81207\n",
"41385\n",
"37317\n",
"74424\n",
"67817\n",
"684\n",
"15\n",
"96992\n",
"38798\n",
"... | 2CODEFORCES |
87_C. Interesting Game_3203 | Two best friends Serozha and Gena play a game.
Initially there is one pile consisting of n stones on the table. During one move one pile should be taken and divided into an arbitrary number of piles consisting of a1 > a2 > ... > ak > 0 stones. The piles should meet the condition a1 - a2 = a2 - a3 = ... = ak - 1 - ak =... | import java.util.*;
public class C87 {
public static void main(String[] args){
Scanner br = new Scanner(System.in);
int n = br.nextInt();
int[] preGrundy = new int[n+1];
for(int i = 1;i<=n;i++){
int mask = 0;
for(int j = 2;j<=446;j++){
int cur = i+(j*(j-1))/2;
if(cur/j < j) break;
if(cur%j ... | 4JAVA | {
"input": [
"6\n",
"100\n",
"3\n",
"56\n",
"1\n",
"46\n",
"63478\n",
"7578\n",
"56056\n",
"78\n",
"66873\n",
"8149\n",
"35708\n",
"81207\n",
"41385\n",
"37317\n",
"74424\n",
"67817\n",
"684\n",
"15\n",
"96992\n",
"38798\n",
"... | 2CODEFORCES |
903_E. Swapping Characters_3204 | We had a string s consisting of n lowercase Latin letters. We made k copies of this string, thus obtaining k identical strings s1, s2, ..., sk. After that, in each of these strings we swapped exactly two characters (the characters we swapped could be identical, but they had different indices in the string).
You are gi... | def check(l,s1):
unique = False
if len(s1) == len(set(s1)):
unique = True
for i in l:
tem = diffs(s1,i)
if len(tem) != 2:
if len(tem) == 0 and unique == False:
pass
else:
return -1
return 1
def checks(l):
dic = {i: l[0]... | 1Python2 | {
"input": [
"5 4\nabcd\ndcba\nacbd\ndbca\nzzzz\n",
"3 4\nabac\ncaab\nacba\n",
"3 4\nkbbu\nkbub\nubkb\n",
"3 4\nkbub\nkbbu\nubkb\n",
"5 5\nzbibx\nzbbix\nzbibx\nxbibz\nxbibz\n",
"100 2\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nq... | 2CODEFORCES |
903_E. Swapping Characters_3205 | We had a string s consisting of n lowercase Latin letters. We made k copies of this string, thus obtaining k identical strings s1, s2, ..., sk. After that, in each of these strings we swapped exactly two characters (the characters we swapped could be identical, but they had different indices in the string).
You are gi... | #include <bits/stdc++.h>
using namespace std;
const long long int N = 5005;
const long long int mod = 1e17 + 7;
long long int k, n;
string s[N];
long long int high, idx;
long long int cnt[26];
bool satisfy(long long int x) {
long long int ret = 0;
for (long long int i = 0; i < n; i++) {
if (s[x][i] != s[idx][i]... | 2C++ | {
"input": [
"5 4\nabcd\ndcba\nacbd\ndbca\nzzzz\n",
"3 4\nabac\ncaab\nacba\n",
"3 4\nkbbu\nkbub\nubkb\n",
"3 4\nkbub\nkbbu\nubkb\n",
"5 5\nzbibx\nzbbix\nzbibx\nxbibz\nxbibz\n",
"100 2\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nq... | 2CODEFORCES |
903_E. Swapping Characters_3206 | We had a string s consisting of n lowercase Latin letters. We made k copies of this string, thus obtaining k identical strings s1, s2, ..., sk. After that, in each of these strings we swapped exactly two characters (the characters we swapped could be identical, but they had different indices in the string).
You are gi... | import collections
def swapCharacters(strings, k, n):
"""
Time: O(n^2 * k)
Space: O(1)
"""
if k == 1:
s0 = list(strings[0])
s0[0], s0[1] = s0[1], s0[0]
return ''.join(s0)
# Initial check for validity
freq = collections.Counter(strings[0])
canSame = (max(freq.values()) >= 2) # could swap two of the same... | 3Python3 | {
"input": [
"5 4\nabcd\ndcba\nacbd\ndbca\nzzzz\n",
"3 4\nabac\ncaab\nacba\n",
"3 4\nkbbu\nkbub\nubkb\n",
"3 4\nkbub\nkbbu\nubkb\n",
"5 5\nzbibx\nzbbix\nzbibx\nxbibz\nxbibz\n",
"100 2\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nq... | 2CODEFORCES |
903_E. Swapping Characters_3207 | We had a string s consisting of n lowercase Latin letters. We made k copies of this string, thus obtaining k identical strings s1, s2, ..., sk. After that, in each of these strings we swapped exactly two characters (the characters we swapped could be identical, but they had different indices in the string).
You are gi... | //189301019.akshay
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Random;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.u... | 4JAVA | {
"input": [
"5 4\nabcd\ndcba\nacbd\ndbca\nzzzz\n",
"3 4\nabac\ncaab\nacba\n",
"3 4\nkbbu\nkbub\nubkb\n",
"3 4\nkbub\nkbbu\nubkb\n",
"5 5\nzbibx\nzbbix\nzbibx\nxbibz\nxbibz\n",
"100 2\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nqz\nq... | 2CODEFORCES |
925_F. Parametric Circulation_3208 | Vova has recently learned what a circulaton in a graph is. Recall the definition: let G = (V, E) be a directed graph. A circulation f is such a collection of non-negative real numbers f_e (e ∈ E), that for each vertex v ∈ V the following conservation condition holds:
$$$∑_{e ∈ \delta^{-}(v)} f_e = ∑_{e ∈ \delta^{+}(v)... | #include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
long double d[1001 + 5]... | 2C++ | {
"input": [
"3 3\n1 2 0 3 -4 7\n2 3 -2 5 1 6\n3 1 0 4 0 4\n",
"2 2\n1 2 1 4 2 4\n1 2 3 4 4 4\n",
"2 2\n1 2 0 9998 0 9999\n2 1 0 9999 0 10000\n",
"3 3\n1 2 0 3 -4 7\n2 3 -2 5 1 6\n3 1 0 4 0 4\n",
"2 2\n1 2 0 3 0 3\n2 1 0 4 0 4\n",
"2 2\n1 2 0 0 0 0\n2 1 0 0 0 0\n",
"5 10\n4 3 -19 49 -11 65... | 2CODEFORCES |
954_G. Castle Defense_3209 | Today you are going to lead a group of elven archers to defend the castle that is attacked by an army of angry orcs. Three sides of the castle are protected by impassable mountains and the remaining side is occupied by a long wall that is split into n sections. At this moment there are exactly ai archers located at the... | #include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1, -1, -1, 1, 1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
template <class T>
inline T biton(T n, T pos) {
return n | ((T)1 << pos);
}
template <class T>
inline T bitoff(T n, T pos) {
return n & ~((T)1 << pos);
}
template <class T>
inline T ison(T n... | 2C++ | {
"input": [
"4 2 0\n1 2 3 4\n",
"5 0 6\n5 4 3 4 9\n",
"5 1 1\n2 1 2 1 2\n",
"1 0 0\n1\n",
"1 1 10\n23\n",
"100 0 0\n607 169 477 518 368 54 15 471 604 138 982 836 563 886 466 118 366 670 257 37 868 142 14 666 670 624 427 281 995 133 914 413 356 852 63 894 430 310 634 253 281 938 975 272 821 24... | 2CODEFORCES |
954_G. Castle Defense_3210 | Today you are going to lead a group of elven archers to defend the castle that is attacked by an army of angry orcs. Three sides of the castle are protected by impassable mountains and the remaining side is occupied by a long wall that is split into n sections. At this moment there are exactly ai archers located at the... | import sys
border = 1 << 30
def build(x=0):
res = [0, 0]
i = 0
while x and i < 30:
if x & 1:
res[1] += (1 << i)
x >>= 1
i += 1
i = 0
while x:
if x & 1:
res[0] += (1 << i)
x >>= 1
i += 1
return res
n, r, k = map(int, ... | 3Python3 | {
"input": [
"4 2 0\n1 2 3 4\n",
"5 0 6\n5 4 3 4 9\n",
"5 1 1\n2 1 2 1 2\n",
"1 0 0\n1\n",
"1 1 10\n23\n",
"100 0 0\n607 169 477 518 368 54 15 471 604 138 982 836 563 886 466 118 366 670 257 37 868 142 14 666 670 624 427 281 995 133 914 413 356 852 63 894 430 310 634 253 281 938 975 272 821 24... | 2CODEFORCES |
954_G. Castle Defense_3211 | Today you are going to lead a group of elven archers to defend the castle that is attacked by an army of angry orcs. Three sides of the castle are protected by impassable mountains and the remaining side is occupied by a long wall that is split into n sections. At this moment there are exactly ai archers located at the... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
public class G {
static final int MAXN = 500005;
static long[] sum = new long[MAXN];
static long[] prepare = new long[... | 4JAVA | {
"input": [
"4 2 0\n1 2 3 4\n",
"5 0 6\n5 4 3 4 9\n",
"5 1 1\n2 1 2 1 2\n",
"1 0 0\n1\n",
"1 1 10\n23\n",
"100 0 0\n607 169 477 518 368 54 15 471 604 138 982 836 563 886 466 118 366 670 257 37 868 142 14 666 670 624 427 281 995 133 914 413 356 852 63 894 430 310 634 253 281 938 975 272 821 24... | 2CODEFORCES |
980_F. Cactus to Tree_3212 | You are given a special connected undirected graph where each vertex belongs to at most one simple cycle.
Your task is to remove as many edges as needed to convert this graph into a tree (connected graph with no cycles).
For each node, independently, output the maximum distance between it and a leaf in the resulting... | #include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const long long linf = (long long)1e18;
const int mod = (int)1e9 + 7;
const long double eps = (long double)1e-8;
const int maxn = (int)5e5 + 5;
const long double pi = acos(-1);
int n, m, cnt_cyc;
int t[maxn], cyc[maxn], tup[maxn];
int ans[maxn], an... | 2C++ | {
"input": [
"9 10\n7 2\n9 2\n1 6\n3 1\n4 3\n4 7\n7 6\n9 8\n5 8\n5 9\n",
"4 4\n1 2\n2 3\n3 4\n4 1\n",
"68 74\n7 8\n24 23\n55 56\n3 50\n61 62\n12 1\n32 33\n36 35\n9 8\n44 50\n53 5\n29 28\n16 2\n36 37\n3 22\n44 45\n27 28\n66 65\n34 4\n31 32\n64 65\n13 12\n10 9\n67 66\n5 47\n55 54\n6 51\n20 21\n67 4\n17 29\n... | 2CODEFORCES |
980_F. Cactus to Tree_3213 | You are given a special connected undirected graph where each vertex belongs to at most one simple cycle.
Your task is to remove as many edges as needed to convert this graph into a tree (connected graph with no cycles).
For each node, independently, output the maximum distance between it and a leaf in the resulting... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import static java.util.Collections.reverse;
/**
* @author Don Li
*/
public cl... | 4JAVA | {
"input": [
"9 10\n7 2\n9 2\n1 6\n3 1\n4 3\n4 7\n7 6\n9 8\n5 8\n5 9\n",
"4 4\n1 2\n2 3\n3 4\n4 1\n",
"68 74\n7 8\n24 23\n55 56\n3 50\n61 62\n12 1\n32 33\n36 35\n9 8\n44 50\n53 5\n29 28\n16 2\n36 37\n3 22\n44 45\n27 28\n66 65\n34 4\n31 32\n64 65\n13 12\n10 9\n67 66\n5 47\n55 54\n6 51\n20 21\n67 4\n17 29\n... | 2CODEFORCES |
1-7_3214 | Raj and simran are in love. but thakur baldev singh doesnt want them to be together. But baldev Singh cares for her daughter too. He wants raj to prove his love for her daughter and family. So Baldev singh being a great lover of strings sets up problem for raj. he screams out a string and asks simran to choose her ... | t = input();
while(t > 0):
s = raw_input().split();
print s[0].count(s[1]);
t -= 1; | 1Python2 | {
"input": [
"2\nabca a\nbbb c\n\nSAMPLE",
"100\nwlrbbmqbhcdarzowkkyhiddqscdxrjmowfrxsjybldbefsarcbynecdyggxxpklorellnmpapqfwkhopkmcoqhnwnkuewhsqmgbbuqcljjivswmdkqtbxixmvtrrbljptnsnfwzqfjmafadrrwsofsbcnuvqhffbsaqxwpqcacehchzvfrkmlnozjkpqpxrjxkitzyxacbhhkicqcoendtomfgdwdwfcgpxiqvkuytdlcgdewhtaciohordtqkvwcsgsp... | 3HACKEREARTH |
bhavesh-and-colors_3215 | **
Problem Statement is Updated
**
Xenny had N colors with him, all arranged in a straight line. He was interested in picking up a particular subarray of colors.
A pre-set is a set that contains all subarrays of colors that start from the first color and do not contain the last color.
An end-set is a set that contai... | def returnAnswer(a):
n = len(a)
length = 0
arr = []
for i in range(0, n):
arr.append(0)
i = 1
while(i<n):
if(a[i] == a[length]):
length += 1
arr[i] = length
i += 1
else:
if(length != 0):
length = arr[length-1]
else:
arr[i] = 0
i += 1
retu... | 1Python2 | {
"input": [
"1\n4\n1 2 1 2\n\nSAMPLE",
"1\n4\n1 2 1 2\n\nTAMPLE",
"1\n0\n1 3 1 2\n\nTAMPLE",
"1\n0\n1 3 0 3\n\nTAMPLE",
"1\n-3\n-1 -1 -1 -1\n\nANMDPL",
"1\n0\n1 2 1 2\n\nTAMPLE",
"1\n0\n1 3 1 3\n\nTAMPLE",
"1\n0\n1 3 -1 3\n\nTAMPLE",
"1\n0\n1 6 -1 3\n\nTAMPLE",
"1\n0\n1 6 -1 3... | 3HACKEREARTH |
costly-phone-number-december-easy-easy-medium_3216 | A cell phone company is trying out its new model of cell phone. Here's how its structure is:
The keypad has 11 buttons corresponding to digits from 0 to 9 and one additional button called Add. After pressing any button from 0 to 9, the corresponding digit appears on the screen. The Add button replaces the last two di... | for _ in range(input()):
total_cost = map(int, raw_input().split())
for i in range(10):
for j in range(1, 10):
for k in range(j, 10):
total_cost[(j + k) % 10] = min(total_cost[(j + k) % 10], total_cost[j]+total_cost[k])
input()
Result = 0
inputs = raw... | 1Python2 | {
"input": [
"3\n3 2 2 3 2 1 1 2 3 3 \n3\n171\n3 2 3 1 1 1 1 3 1 2 \n2\n16\n3 3 3 1 3 1 1 2 3 2 \n2\n43\n\nSAMPLE",
"3\n3 2 2 1 1 1 2 3 1 2 \n1\n3\n1 2 3 2 1 2 2 3 1 1 \n2\n98\n2 1 3 3 1 2 3 1 3 3 \n1\n1",
"3\n7 3 2 1 2 4 7 7 5 9 \n10\n1385294192\n3 6 1 2 7 3 10 7 2 8 \n7\n8129080\n1 5 7 3 1 1 9 9 8 10 \n... | 3HACKEREARTH |
find-the-ring_3217 | There is a new magician in town. His trick is known as "Find the Ring".
He puts 3 glasses at 3 spots on the table, labeling them as 0, 1 and 2. Now, he hides a ring under one of the glasses. The glasses are opaque and placed upside down, so that the ring is not visible to the audience.
Now, he begins to make certain ... | n=int(raw_input())
while n:
t=(raw_input())
t=t.split(' ')
t[0]=int(t[0])
t[1]=int(t[1])
if t[1]==0:
print t[0]
elif t[1]%2==0:
if t[0]==1:
print "1"
else :
print '0'
else :
if t[0]==1:
print "0"
else :
print '1'
n-=1 | 1Python2 | {
"input": [
"3\n1 1\n0 1\n2 2\n\nSAMPLE",
"100\n0 5619\n0 3827\n2 1722\n2 909\n2 7032\n0 832\n1 7280\n2 5860\n0 1391\n2 5694\n0 109\n2 4742\n0 5886\n2 9924\n0 3544\n1 9460\n1 7759\n0 2056\n0 539\n0 861\n2 9947\n1 4501\n2 6755\n1 2787\n0 8049\n2 7526\n0 6094\n0 7932\n0 1551\n0 5864\n1 3707\n1 8735\n0 3911\n1 ... | 3HACKEREARTH |
integers-only-allowed_3218 | You have a polygon described by coordinates of its vertices. Can you find how many points with integer coordinates lay strictly inside it?
Input
The first line contains an integer N - number of vertices.
Next N lines contain 2 space-separated integers each and describe polygon vertices in clockwise order. Note that po... | from fractions import gcd
n = input()
vertices = []
for i in range(n):
vertices.append(map(int, raw_input().split()))
vertices.append(vertices[0])
b = 0
for i in range(n):
dx = abs(vertices[i + 1][0] - vertices[i][0])
dy = abs(vertices[i + 1][1] - vertices[i][1])
b += gcd(dx, dy)
b = max(0, b)
area = 0... | 1Python2 | {
"input": [
"4\n0 0\n0 2\n2 2\n2 0\n\nSAMPLE",
"5\n-728000 477000\n667000 186000\n667000 151000\n-595000 -679000\n-298000 -132000",
"5\n-728000 477000\n667000 186000\n667000 151000\n-1101635 -679000\n-298000 -132000",
"4\n0 0\n0 2\n2 2\n4 0\n\nSAMPLE",
"5\n-728000 477000\n667000 49657\n667000 151... | 3HACKEREARTH |
maxi-and-dumpy_3219 | Maxi and Dumpy are playing with numbers. Maxi throws a ball up in the air and shouts a random number. Dumpy notes down this number on a piece of paper. They repeat this N times.
But Dumpy just found out that there are many repetitive numbers in the list. He doesn't like it. He asks you to filter the list, remove the re... | n=input()
num=raw_input()
num=num.split(" ")
num=map(int, num)
dum=[]
for i in num:
if(i not in dum):
dum.append(i)
for i in dum:
print(i), | 1Python2 | {
"input": [
"6\n2 1 5 3 2 5\n\nSAMPLE",
"10000\n5617 9114 7223 8085 7207 6665 9614 9508 8351 8579 7638 9973 6310 9941 7237 6074 9460 6574 5828 9264 9789 9632 7433 8571 9218 8470 7138 9877 5933 6865 6071 5198 5978 6942 6931 6833 8607 6544 9989 6958 8771 7627 5579 5081 6216 6463 9802 5676 6685 5630 8587 6474 8... | 3HACKEREARTH |
one-and-zero_3220 | Little Raju recently learnt about binary numbers. After spending some time with it, he decided to count in how many ways he can make N digit numbers that is formed by ones and zeroes. But zeroes can not be next to each other. Help him finding in how many different numbers can he make?
Example: There 5 possible ways o... | '''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
print 'Hello World!'
'''
t=int(input())
for i in range(t):
n=int(input())
if n==1:
print(2)
else:
a=1
b=2
for i in range(2,n+1):
a,b=b,a+b
print(b) | 1Python2 | {
"input": [
"2\n3\n7\n\nSAMPLE",
"5\n2\n8\n12\n16\n34",
"5\n99\n44\n18\n999\n66",
"4\n4521\n994\n5000\n10000",
"5\n2\n8\n12\n26\n34",
"5\n99\n44\n18\n999\n35",
"2\n3\n7\n\nS@MPLE",
"5\n2\n8\n9\n26\n34",
"5\n99\n71\n18\n999\n35",
"2\n3\n9\n\nS@MPLE",
"5\n2\n8\n9\n26\n13",
... | 3HACKEREARTH |
random-delimma-4_3221 | Manu is a very bright student and had learned c++ Programming on her own.She has covered loops and if/else.She is a very inquisitive child and always love to discover new things.Same applies to programming she learns various syntax.One day while reading the documentation of a cstdlib library she came across a function ... | t=input()
while t>0:
k,n=map(int,raw_input().split())
if k>n:
print "1.000000000"
else:
f=1.0
for i in range(n,n-k,-1):
f=(f*i)/n
f=1-f
print "%.9f"%(f)
t-=1 | 1Python2 | {
"input": [
"2\n4 10\n7 6\n\nSAMPLE",
"1000\n17 277\n35 390\n37 682\n12 133\n43 991\n37 381\n29 865\n32 1084\n23 352\n7 210\n16 245\n54 558\n57 1062\n5 451\n2 233\n17 445\n69 691\n38 823\n103 1071\n62 976\n28 955\n2 136\n51 670\n18 578\n40 984\n14 398\n11 447\n10 753\n51 573\n16 239\n37 632\n94 1070\n20 569\... | 3HACKEREARTH |
simple-task_3222 | Given an array A. Delete an single element from the array such that sum of the differences of adjacent elements should be minimum.
For more clarification Sum for an array A having N element is defined as :
abs( A[0] - A[1] ) + abs( A[1] - A[2] ) + abs( A[2] - A[3] ) +............ + abs( A[N-2] - A[N-1] )
Inp... | t=int(raw_input())
for qq in xrange(t):
n=int(raw_input())
l=map(int,raw_input().split())
s=sum(l)
minval=9999999999999999999
ret=0
if n==1:
print 0
continue
for i in xrange(n):
tmp=0
cp=s
if i>0 and i<n-1:
tmp = abs(l[i]-l[i-1]) + abs(l[i]-l[i+1])
cp-=tmp
cp+=abs(l[i+1]-l[i-1])
if cp < min... | 1Python2 | {
"input": [
"1\n5\n1 10 20 40 60\n\nSAMPLE",
"5\n1\n100\n2\n100 1\n2\n1 2\n3\n1 100 2\n3\n1 2 3\n3\n1 5 6\n3\n1 7 8\n3\n8 7 1\n3\n7 8 1\n3\n7 1 8",
"5\n1\n100\n2\n100 1\n2\n1 2\n3\n1 100 2\n3\n1 2 3\n3\n1 5 6\n3\n1 7 8\n3\n8 7 1\n3\n7 8 2\n3\n7 1 8",
"5\n1\n100\n2\n100 0\n2\n1 2\n3\n1 100 2\n3\n1 0 3... | 3HACKEREARTH |
the-substring-problem-1_3223 | You have been given a set of N strings S1, S2, .... SN. Consider any non-empty string S (S need not belong to the given set of N strings). Suppose S occurs (as a substring) in K out of the N given strings in the set. Your job is to choose S such that the value of K is maximized. If there are many such strings, choose t... | t=input()
for i in xrange(t):
n=input()
l=[]
for k in xrange(n):
s=raw_input()
l.append(s)
q="abcdefghijklmnopqrstuvwxyz"
o=[0 for i in xrange(26)]
for x in xrange(n):
for y in xrange(26):
if q[y] in l[x]:
o[y]+=1
z=max(o)
for j in xrange(26):
if o[j]==z:
print q[j]
break | 1Python2 | {
"input": [
"1\n1\nshades\n\nSAMPLE",
"2\n20\nengagfwhxalwaaucqieavxyutinrmtd\nnxhehybspixeykxillunrhswxskfrzkljeigxwaumrlfqlrrjlngxcyddtunll\nhcqpdelycqspbqrorpslpqwy\nzzjclluwfsyzxvzldjvdpfshbghqcepchuepklddqgtalcbupgexclfdjzjkctlnayuhgrvcsqyxatokefjwbnzvu\nfuxfecjlwilndrijri\naykqwypnriohkyizfvihjkyanijci... | 3HACKEREARTH |
p02549 AtCoder Beginner Contest 179 - Leaping Tak_3224 | There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right.
Tak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below.
You are given an integer K that is less than or equal to 10, and K non-intersecting segments [L_1, R_1], [L_2, R_2... | import sys
N,K=map(int, sys.stdin.readline().split())
LR=[ map(int, sys.stdin.readline().split()) for _ in range(K) ]
dp=[0]*(N+1)
sum_dp=[0]
mod=998244353
i=1
dp[i]=1
sum_dp.append(sum_dp[-1]+dp[i])
for i in range(2,N+1):
for l,r in LR:
dp[i]+=sum_dp[max(0,i-l)]-sum_dp[max(0,i-r-1)]
dp[i]%=mod
... | 1Python2 | {
"input": [
"5 2\n3 3\n5 5",
"5 1\n1 2",
"60 3\n5 8\n1 3\n10 15",
"5 2\n1 1\n3 4",
"5 2\n3 3\n5 9",
"60 3\n5 4\n1 3\n10 15",
"10 2\n1 1\n3 4",
"60 3\n5 4\n1 3\n10 20",
"50 3\n5 4\n1 3\n10 20",
"5 1\n1 2\n5 9",
"60 3\n5 8\n1 0\n10 15",
"3 2\n1 1\n3 4",
"60 3\n5 4\n1... | 5ATCODER |
p02549 AtCoder Beginner Contest 179 - Leaping Tak_3225 | There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right.
Tak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below.
You are given an integer K that is less than or equal to 10, and K non-intersecting segments [L_1, R_1], [L_2, R_2... | #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll N,K;
ll L[222222],R[222222];
cin >> N >> K;
ll i,k;
for(i=0;i<=K-1;i++)
cin >> L[i] >> R[i];
ll dp[222222] = {0};
dp[1] = 1;
ll sum[222222] = {0};
sum[1] = 1;
for(i=2;i<=N;i++)
for(k=0;k<=K-1;k++){
dp[... | 2C++ | {
"input": [
"5 2\n3 3\n5 5",
"5 1\n1 2",
"60 3\n5 8\n1 3\n10 15",
"5 2\n1 1\n3 4",
"5 2\n3 3\n5 9",
"60 3\n5 4\n1 3\n10 15",
"10 2\n1 1\n3 4",
"60 3\n5 4\n1 3\n10 20",
"50 3\n5 4\n1 3\n10 20",
"5 1\n1 2\n5 9",
"60 3\n5 8\n1 0\n10 15",
"3 2\n1 1\n3 4",
"60 3\n5 4\n1... | 5ATCODER |
p02549 AtCoder Beginner Contest 179 - Leaping Tak_3226 | There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right.
Tak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below.
You are given an integer K that is less than or equal to 10, and K non-intersecting segments [L_1, R_1], [L_2, R_2... | import sys
input = sys.stdin.readline
N,K=map(int,input().split())
K=[tuple(map(int,input().split())) for i in range(K)]
mod=998244353
DP=[0]*(4*10**5+100)
DP[1]=1
DP[2]=-1
for i in range(1,N+1):
DP[i]+=DP[i-1]
DP[i]%=mod
for l,r in K:
DP[i+l]+=DP[i]
DP[i+l]%=mod
DP[i+r+1]-=D... | 3Python3 | {
"input": [
"5 2\n3 3\n5 5",
"5 1\n1 2",
"60 3\n5 8\n1 3\n10 15",
"5 2\n1 1\n3 4",
"5 2\n3 3\n5 9",
"60 3\n5 4\n1 3\n10 15",
"10 2\n1 1\n3 4",
"60 3\n5 4\n1 3\n10 20",
"50 3\n5 4\n1 3\n10 20",
"5 1\n1 2\n5 9",
"60 3\n5 8\n1 0\n10 15",
"3 2\n1 1\n3 4",
"60 3\n5 4\n1... | 5ATCODER |
p02549 AtCoder Beginner Contest 179 - Leaping Tak_3227 | There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right.
Tak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below.
You are given an integer K that is less than or equal to 10, and K non-intersecting segments [L_1, R_1], [L_2, R_2... | import java.util.Scanner;
public class Main {
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
long m=998244353;
int n=s.nextInt();
int k=s.nextInt();
pair[] arr=new pair[n];
for(int i=0;i<k;i++)
{
int l=s.nextInt();
int r=s.nextInt();
pair p=new pai... | 4JAVA | {
"input": [
"5 2\n3 3\n5 5",
"5 1\n1 2",
"60 3\n5 8\n1 3\n10 15",
"5 2\n1 1\n3 4",
"5 2\n3 3\n5 9",
"60 3\n5 4\n1 3\n10 15",
"10 2\n1 1\n3 4",
"60 3\n5 4\n1 3\n10 20",
"50 3\n5 4\n1 3\n10 20",
"5 1\n1 2\n5 9",
"60 3\n5 8\n1 0\n10 15",
"3 2\n1 1\n3 4",
"60 3\n5 4\n1... | 5ATCODER |
p02680 AtCoder Beginner Contest 168 - . (Single Dot)_3228 | There is a grass field that stretches infinitely.
In this field, there is a negligibly small cow. Let (x, y) denote the point that is x\ \mathrm{cm} south and y\ \mathrm{cm} east of the point where the cow stands now. The cow itself is standing at (0, 0).
There are also N north-south lines and M east-west lines drawn... | #include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int N,M;
int A[1000],B[1000],C[1000];
int D[1000],E[1000],F[1000];
bool vis[3010][3010];
vector<pair<int,int> >WX[3010],WY[3010];
bool wx[3010][3010],wy[3010][3010];
int main()
{
cin>>N>>M;
vector<long>X,Y;
X.push_back((long... | 2C++ | {
"input": [
"6 1\n-3 -1 -2\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4",
"5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4",
"6 1\n-3 -1 -4\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4",
"5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -... | 5ATCODER |
p02680 AtCoder Beginner Contest 168 - . (Single Dot)_3229 | There is a grass field that stretches infinitely.
In this field, there is a negligibly small cow. Let (x, y) denote the point that is x\ \mathrm{cm} south and y\ \mathrm{cm} east of the point where the cow stands now. The cow itself is standing at (0, 0).
There are also N north-south lines and M east-west lines drawn... | I=lambda:map(int,input().split());F=1e21;r=range;n,m=I();f=[-F,F];X=[0]+f;Y=X[:];R=[(f,F),(f,-F)];H=[(F,f),(-F,f)]
for i in r(n):*a,c=I();R+=[(a,c)];Y+=c,;X+=a
for i in r(m):a,*b=I();H+=[(a,b)];X+=a,;Y+=b
def g(X):s=dict(enumerate(sorted(set(X))));return{s[i]:i for i in s},s,len(s)+1
h,s,K=g(X);w,t,L=g(Y);j=lambda:[[0]... | 3Python3 | {
"input": [
"6 1\n-3 -1 -2\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4",
"5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4",
"6 1\n-3 -1 -4\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4",
"5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -... | 5ATCODER |
p02680 AtCoder Beginner Contest 168 - . (Single Dot)_3230 | There is a grass field that stretches infinitely.
In this field, there is a negligibly small cow. Let (x, y) denote the point that is x\ \mathrm{cm} south and y\ \mathrm{cm} east of the point where the cow stands now. The cow itself is standing at (0, 0).
There are also N north-south lines and M east-west lines drawn... | import java.awt.Point;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.Iterator;
import java.util.List;
import jav... | 4JAVA | {
"input": [
"6 1\n-3 -1 -2\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4",
"5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -4 5\n3 -2 4\n1 2 4",
"6 1\n-3 -1 -4\n-3 -1 1\n-2 -1 2\n1 4 -2\n1 4 -1\n1 4 1\n3 1 4",
"5 6\n1 2 0\n0 1 1\n0 2 2\n-3 4 -1\n-2 6 3\n1 0 1\n0 1 2\n2 0 2\n-1 -... | 5ATCODER |
p02808 Dwango Programming Contest 6th - Cookie Distribution_3231 | There are N children, numbered 1,2,\ldots,N. In the next K days, we will give them some cookies. In the i-th day, we will choose a_i children among the N with equal probability, and give one cookie to each child chosen. (We make these K choices independently.)
Let us define the happiness of the children as c_1 \times ... | #include<bits/stdc++.h>
using namespace std;
const int N=1e3+2;
const int mod=1e9+7;
int dp[N],c[N][N],ar[N],ndp[N];
void add(int &x,int y){
x+=y;
if(x>=mod){
x-=mod;
}
}
int mul(int x,int y){
return (1ll*x*y)%mod;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n,i,j,k,l,num;
cin>>n>>num;
for(i=1;... | 2C++ | {
"input": [
"3 2\n3 2",
"856 16\n399 263 665 432 206 61 784 548 422 313 848 478 827 26 398 63",
"3 2\n1 2",
"856 16\n399 491 665 432 206 61 784 548 422 313 848 478 827 26 398 63",
"4 2\n1 2",
"856 16\n399 491 665 432 206 0 784 548 422 313 848 478 827 26 398 63",
"2 2\n1 2",
"856 16\n3... | 5ATCODER |
p02808 Dwango Programming Contest 6th - Cookie Distribution_3232 | There are N children, numbered 1,2,\ldots,N. In the next K days, we will give them some cookies. In the i-th day, we will choose a_i children among the N with equal probability, and give one cookie to each child chosen. (We make these K choices independently.)
Let us define the happiness of the children as c_1 \times ... | n,k = map(int,input().split())
a = tuple(map(int,input().split()))
mod = 10**9+7
rng = 1001
fctr = [1]
finv = [1]
for i in range(1,rng):
fctr.append(fctr[-1]*i%mod)
finv.append(pow(fctr[i],mod-2,mod))
dp = [[0 for i in range(n+1)] for j in range(k+1)]
dp[0][0] = 1
for i in range(1,k+1):
x = a[i-1]
for j in rang... | 3Python3 | {
"input": [
"3 2\n3 2",
"856 16\n399 263 665 432 206 61 784 548 422 313 848 478 827 26 398 63",
"3 2\n1 2",
"856 16\n399 491 665 432 206 61 784 548 422 313 848 478 827 26 398 63",
"4 2\n1 2",
"856 16\n399 491 665 432 206 0 784 548 422 313 848 478 827 26 398 63",
"2 2\n1 2",
"856 16\n3... | 5ATCODER |
p02808 Dwango Programming Contest 6th - Cookie Distribution_3233 | There are N children, numbered 1,2,\ldots,N. In the next K days, we will give them some cookies. In the i-th day, we will choose a_i children among the N with equal probability, and give one cookie to each child chosen. (We make these K choices independently.)
Let us define the happiness of the children as c_1 \times ... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;
/**
* Built using CHelper p... | 4JAVA | {
"input": [
"3 2\n3 2",
"856 16\n399 263 665 432 206 61 784 548 422 313 848 478 827 26 398 63",
"3 2\n1 2",
"856 16\n399 491 665 432 206 61 784 548 422 313 848 478 827 26 398 63",
"4 2\n1 2",
"856 16\n399 491 665 432 206 0 784 548 422 313 848 478 827 26 398 63",
"2 2\n1 2",
"856 16\n3... | 5ATCODER |
p02944 AtCoder Grand Contest 037 - Counting of Subarrays_3234 | For a sequence S of positive integers and positive integers k and l, S is said to belong to level (k,l) when one of the following conditions is satisfied:
* The length of S is 1, and its only element is k.
* There exist sequences T_1,T_2,...,T_m (m \geq l) belonging to level (k-1,l) such that the concatenation of T_1,... | #include<cstdio>
#include<queue>
#include<vector>
#include<iostream>
using namespace std;
#define mp make_pair
#define fi first
#define se second
const int MAXN = 200000;
typedef pair<int, int> pii;
typedef long long ll;
priority_queue<pii, vector<pii>, greater<pii> >que;
int lst[MAXN + 5], nxt[MAXN + 5], N, L;
void li... | 2C++ | {
"input": [
"15 3\n4 3 2 1 1 1 2 3 2 2 1 1 1 2 2",
"9 2\n2 1 1 1 1 1 1 2 3",
"9 3\n2 1 1 1 1 1 1 2 3",
"15 3\n4 3 2 1 2 1 2 3 2 2 1 1 1 2 2",
"9 2\n2 0 1 1 1 1 1 2 3",
"9 2\n2 1 1 1 1 1 0 2 3",
"9 3\n2 0 1 1 1 1 1 2 3",
"9 3\n4 0 1 0 1 1 1 3 3",
"15 3\n1 3 2 1 2 1 1 3 2 2 1 1 2 2 ... | 5ATCODER |
p02944 AtCoder Grand Contest 037 - Counting of Subarrays_3235 | For a sequence S of positive integers and positive integers k and l, S is said to belong to level (k,l) when one of the following conditions is satisfied:
* The length of S is 1, and its only element is k.
* There exist sequences T_1,T_2,...,T_m (m \geq l) belonging to level (k-1,l) such that the concatenation of T_1,... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NavigableSet;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Compar... | 4JAVA | {
"input": [
"15 3\n4 3 2 1 1 1 2 3 2 2 1 1 1 2 2",
"9 2\n2 1 1 1 1 1 1 2 3",
"9 3\n2 1 1 1 1 1 1 2 3",
"15 3\n4 3 2 1 2 1 2 3 2 2 1 1 1 2 2",
"9 2\n2 0 1 1 1 1 1 2 3",
"9 2\n2 1 1 1 1 1 0 2 3",
"9 3\n2 0 1 1 1 1 1 2 3",
"9 3\n4 0 1 0 1 1 1 3 3",
"15 3\n1 3 2 1 2 1 1 3 2 2 1 1 2 2 ... | 5ATCODER |
p03081 ExaWizards 2019 - Snuke the Wizard_3236 | There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square.
Snuke cast Q spells to move the golems.
The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or `R`. When Snuke ca... | # -*- coding: utf-8 -*-
import sys
N,Q=map(int, sys.stdin.readline().split())
s=raw_input()
q=[ sys.stdin.readline().split() for i in range(Q) ]
def leftout(cur):
for x,y in q:
if s[cur]==x:
if y=="L":
cur-=1
elif y=="R":
cur+=1
if cur<0:
return True
break
elif cur>N-1:
return False
... | 1Python2 | {
"input": [
"10 15\nSNCZWRCEWB\nB R\nR R\nE R\nW R\nZ L\nS R\nQ L\nW L\nB R\nC L\nA L\nN L\nE R\nZ L\nS L",
"3 4\nABC\nA L\nB L\nB R\nA R",
"8 3\nAABCBDBA\nA L\nB R\nA R",
"10 15\nSNCZWRCEWB\nB R\nR R\nE R\nW R\nZ L\nS R\nQ L\nW L\nB R\nC L\nA L\nN L\nE R\nZ L\nR L",
"3 4\nACB\nA L\nB L\nB R\nA R... | 5ATCODER |
p03081 ExaWizards 2019 - Snuke the Wizard_3237 | There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square.
Snuke cast Q spells to move the golems.
The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or `R`. When Snuke ca... | #include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
#define MAX 300000
typedef long long ll;
char t[MAX],d[MAX];
ll N,Q;
string s;
bool mycheck(ll goal,ll place){
for(ll i=1;i<=Q;i++){
if(t[i]==s[place-1]){
if(d[i]=='L') place-... | 2C++ | {
"input": [
"10 15\nSNCZWRCEWB\nB R\nR R\nE R\nW R\nZ L\nS R\nQ L\nW L\nB R\nC L\nA L\nN L\nE R\nZ L\nS L",
"3 4\nABC\nA L\nB L\nB R\nA R",
"8 3\nAABCBDBA\nA L\nB R\nA R",
"10 15\nSNCZWRCEWB\nB R\nR R\nE R\nW R\nZ L\nS R\nQ L\nW L\nB R\nC L\nA L\nN L\nE R\nZ L\nR L",
"3 4\nACB\nA L\nB L\nB R\nA R... | 5ATCODER |
p03081 ExaWizards 2019 - Snuke the Wizard_3238 | There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square.
Snuke cast Q spells to move the golems.
The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or `R`. When Snuke ca... | n, q = map(int, input().split())
s = input()
o = []
for _ in range(q):
t, d = input().split()
o.append((t, d))
def check(x):
cur = s[x]
ind = x
for i in range(q):
if o[i][0] == cur:
if o[i][1] == 'L':
ind -= 1
if ind < 0:
ret... | 3Python3 | {
"input": [
"10 15\nSNCZWRCEWB\nB R\nR R\nE R\nW R\nZ L\nS R\nQ L\nW L\nB R\nC L\nA L\nN L\nE R\nZ L\nS L",
"3 4\nABC\nA L\nB L\nB R\nA R",
"8 3\nAABCBDBA\nA L\nB R\nA R",
"10 15\nSNCZWRCEWB\nB R\nR R\nE R\nW R\nZ L\nS R\nQ L\nW L\nB R\nC L\nA L\nN L\nE R\nZ L\nR L",
"3 4\nACB\nA L\nB L\nB R\nA R... | 5ATCODER |
p03081 ExaWizards 2019 - Snuke the Wizard_3239 | There are N squares numbered 1 to N from left to right. Each square has a character written on it, and Square i has a letter s_i. Besides, there is initially one golem on each square.
Snuke cast Q spells to move the golems.
The i-th spell consisted of two characters t_i and d_i, where d_i is `L` or `R`. When Snuke ca... | import java.util.*;
public class Main {
static int n;
static String s;
static int q;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
q = sc.nextInt();
s = sc.next();
char[] t = new char[q];
char[] d = new cha... | 4JAVA | {
"input": [
"10 15\nSNCZWRCEWB\nB R\nR R\nE R\nW R\nZ L\nS R\nQ L\nW L\nB R\nC L\nA L\nN L\nE R\nZ L\nS L",
"3 4\nABC\nA L\nB L\nB R\nA R",
"8 3\nAABCBDBA\nA L\nB R\nA R",
"10 15\nSNCZWRCEWB\nB R\nR R\nE R\nW R\nZ L\nS R\nQ L\nW L\nB R\nC L\nA L\nN L\nE R\nZ L\nR L",
"3 4\nACB\nA L\nB L\nB R\nA R... | 5ATCODER |
p03226 Tenka1 Programmer Contest - Circular_3240 | You are given a sequence of N integers: A_1,A_2,...,A_N.
Find the number of permutations p_1,p_2,...,p_N of 1,2,...,N that can be changed to A_1,A_2,...,A_N by performing the following operation some number of times (possibly zero), modulo 998244353:
* For each 1\leq i\leq N, let q_i=min(p_{i-1},p_{i}), where p_0=p_N... | #include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserv... | 2C++ | {
"input": [
"3\n1\n2\n1",
"8\n4\n4\n4\n1\n1\n1\n2\n2",
"6\n1\n1\n6\n2\n2\n2",
"5\n3\n1\n4\n1\n5",
"8\n4\n4\n4\n1\n2\n1\n2\n2",
"5\n3\n1\n4\n2\n5",
"6\n4\n1\n1\n2\n2\n4",
"6\n1\n1\n1\n2\n2\n2",
"6\n1\n1\n1\n2\n2\n1",
"6\n1\n1\n1\n1\n2\n1",
"6\n1\n1\n1\n1\n1\n1",
"3\n1\n... | 5ATCODER |
p03226 Tenka1 Programmer Contest - Circular_3241 | You are given a sequence of N integers: A_1,A_2,...,A_N.
Find the number of permutations p_1,p_2,...,p_N of 1,2,...,N that can be changed to A_1,A_2,...,A_N by performing the following operation some number of times (possibly zero), modulo 998244353:
* For each 1\leq i\leq N, let q_i=min(p_{i-1},p_{i}), where p_0=p_N... | import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
from operator import itemgetter
MOD = 998244353
N,*A = map(int,read().split())
T = A.count(1)
if T == 0:
print(0)
exit()
if T == 1:
answer = 1 if len(set(A))... | 3Python3 | {
"input": [
"3\n1\n2\n1",
"8\n4\n4\n4\n1\n1\n1\n2\n2",
"6\n1\n1\n6\n2\n2\n2",
"5\n3\n1\n4\n1\n5",
"8\n4\n4\n4\n1\n2\n1\n2\n2",
"5\n3\n1\n4\n2\n5",
"6\n4\n1\n1\n2\n2\n4",
"6\n1\n1\n1\n2\n2\n2",
"6\n1\n1\n1\n2\n2\n1",
"6\n1\n1\n1\n1\n2\n1",
"6\n1\n1\n1\n1\n1\n1",
"3\n1\n... | 5ATCODER |
p03374 AtCoder Regular Contest 096 - Static Sushi_3242 | "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter.
Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on... | N,C = map(int, raw_input().split())
x = [0]*N
v = [0]*N
for i in range(N):
x[i],v[i] = map(int, raw_input().split())
def solve():
M = [0]*N
m = 0
c = 0
for i in range(N):
c += v[i]
c -= (x[i] - (0 if i==0 else x[i-1]))*2
m = max(m, c)
M[i] = m
a = M[N-1]
c = 0
for i in range(N)[::-1]:
... | 1Python2 | {
"input": [
"15 10000000000\n400000000 1000000000\n800000000 1000000000\n1900000000 1000000000\n2400000000 1000000000\n2900000000 1000000000\n3300000000 1000000000\n3700000000 1000000000\n3800000000 1000000000\n4000000000 1000000000\n4100000000 1000000000\n5200000000 1000000000\n6600000000 1000000000\n8000000000... | 5ATCODER |
p03374 AtCoder Regular Contest 096 - Static Sushi_3243 | "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter.
Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on... | #include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 10;
ll d[N], v[N];
ll Lm[N], Rm[N];
int main() {
int n;
ll C;
cin >> n >> C;
for(int i = 1; i <= n; ++i) {
scanf("%lld%lld", &d[i], &v[i]);
}
ll ans = 0, qz = 0;
for(int i = 1; i <= n; ++i) {
qz += v[i];
... | 2C++ | {
"input": [
"15 10000000000\n400000000 1000000000\n800000000 1000000000\n1900000000 1000000000\n2400000000 1000000000\n2900000000 1000000000\n3300000000 1000000000\n3700000000 1000000000\n3800000000 1000000000\n4000000000 1000000000\n4100000000 1000000000\n5200000000 1000000000\n6600000000 1000000000\n8000000000... | 5ATCODER |
p03374 AtCoder Regular Contest 096 - Static Sushi_3244 | "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter.
Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on... | N, C = map(int, input().split())
xv = [[int(i) for i in input().split()] for _ in range(N)]
av = 0
fa1 = 0
bv = 0
fb1 = 0
fa = []
fb = []
ga = []
gb = []
for i in range(N):
ax = xv[i][0]
av += xv[i][1]
bx = C - xv[-(i+1)][0]
bv += xv[-(i+1)][1]
fa1 = max(fa1, av-ax)
fa.append(fa1)
ga.append... | 3Python3 | {
"input": [
"15 10000000000\n400000000 1000000000\n800000000 1000000000\n1900000000 1000000000\n2400000000 1000000000\n2900000000 1000000000\n3300000000 1000000000\n3700000000 1000000000\n3800000000 1000000000\n4000000000 1000000000\n4100000000 1000000000\n5200000000 1000000000\n6600000000 1000000000\n8000000000... | 5ATCODER |
p03374 AtCoder Regular Contest 096 - Static Sushi_3245 | "Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter.
Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, there are N pieces of sushi (vinegared rice with seafood and so on... | import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Collections;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;
public class Main {
static PrintWriter out;
static InputReader ir;
static void solve()... | 4JAVA | {
"input": [
"15 10000000000\n400000000 1000000000\n800000000 1000000000\n1900000000 1000000000\n2400000000 1000000000\n2900000000 1000000000\n3300000000 1000000000\n3700000000 1000000000\n3800000000 1000000000\n4000000000 1000000000\n4100000000 1000000000\n5200000000 1000000000\n6600000000 1000000000\n8000000000... | 5ATCODER |
p03535 CODE FESTIVAL 2017 Final (Parallel) - Time Gap_3246 | In CODE FESTIVAL XXXX, there are N+1 participants from all over the world, including Takahashi.
Takahashi checked and found that the time gap (defined below) between the local times in his city and the i-th person's city was D_i hours. The time gap between two cities is defined as follows. For two cities A and B, if t... | n=input()
a=sorted(map(int,raw_input().split()))
r=0
b=[0]+[a[j]*(-1)**j%24 for j in range(n)]
s=24
for j in range(n):
for k in range(j+1,n+1):s=min(s,(b[j]-b[k])%24,(b[k]-b[j])%24)
r=max(r,s)
print r | 1Python2 | {
"input": [
"2\n11 11",
"3\n7 12 8",
"1\n0",
"2\n11 8",
"3\n7 12 11",
"2\n8 8",
"2\n10 2",
"2\n2 0",
"3\n9 12 8",
"2\n6 8",
"2\n12 8",
"2\n9 7",
"1\n11",
"1\n9",
"1\n10",
"3\n8 12 11",
"2\n8 1",
"2\n10 1",
"2\n4 2",
"2\n8 2",
"2\n2 1... | 5ATCODER |
p03535 CODE FESTIVAL 2017 Final (Parallel) - Time Gap_3247 | In CODE FESTIVAL XXXX, there are N+1 participants from all over the world, including Takahashi.
Takahashi checked and found that the time gap (defined below) between the local times in his city and the i-th person's city was D_i hours. The time gap between two cities is defined as follows. For two cities A and B, if t... | #include <bits/stdc++.h>
#ifdef _WIN32
#include "debug.hpp"
#endif
using namespace std;
#define rep(i, N) for(int i = 0; i < (N); i++)
#define reps(i, N) for(int i = 1; i <= (N); i++)
#define repr(i, N) for(int i = (N) - 1; i >= 0; i--)
#define pub push_back
template<typename T>
void chmax(T &a, T b){ a = max(a, b)... | 2C++ | {
"input": [
"2\n11 11",
"3\n7 12 8",
"1\n0",
"2\n11 8",
"3\n7 12 11",
"2\n8 8",
"2\n10 2",
"2\n2 0",
"3\n9 12 8",
"2\n6 8",
"2\n12 8",
"2\n9 7",
"1\n11",
"1\n9",
"1\n10",
"3\n8 12 11",
"2\n8 1",
"2\n10 1",
"2\n4 2",
"2\n8 2",
"2\n2 1... | 5ATCODER |
p03535 CODE FESTIVAL 2017 Final (Parallel) - Time Gap_3248 | In CODE FESTIVAL XXXX, there are N+1 participants from all over the world, including Takahashi.
Takahashi checked and found that the time gap (defined below) between the local times in his city and the i-th person's city was D_i hours. The time gap between two cities is defined as follows. For two cities A and B, if t... | N = int(input())
D = [int(x) for x in input().split()]
D.append(0)
D.sort()
ans = []
for i in range(N + 1):
if i % 2 == 0:
ans.append(D[i])
else:
ans.append((24 - D[i]) % 24)
ans.sort()
print(min(min(ans[i + 1] - ans[i] for i in range(N)), 24 - ans[-1]))
| 3Python3 | {
"input": [
"2\n11 11",
"3\n7 12 8",
"1\n0",
"2\n11 8",
"3\n7 12 11",
"2\n8 8",
"2\n10 2",
"2\n2 0",
"3\n9 12 8",
"2\n6 8",
"2\n12 8",
"2\n9 7",
"1\n11",
"1\n9",
"1\n10",
"3\n8 12 11",
"2\n8 1",
"2\n10 1",
"2\n4 2",
"2\n8 2",
"2\n2 1... | 5ATCODER |
p03535 CODE FESTIVAL 2017 Final (Parallel) - Time Gap_3249 | In CODE FESTIVAL XXXX, there are N+1 participants from all over the world, including Takahashi.
Takahashi checked and found that the time gap (defined below) between the local times in his city and the i-th person's city was D_i hours. The time gap between two cities is defined as follows. For two cities A and B, if t... |
import java.util.ArrayList;
import java.util.List;
public class Main {
private static void solve() {
int n = ni();
int[] d = na(n);
int[] count = new int[13];
count[0]++;
for (int x : d) {
count[x]++;
if (count[x] == 3) {
System.out.println(0);
return;
}
}
... | 4JAVA | {
"input": [
"2\n11 11",
"3\n7 12 8",
"1\n0",
"2\n11 8",
"3\n7 12 11",
"2\n8 8",
"2\n10 2",
"2\n2 0",
"3\n9 12 8",
"2\n6 8",
"2\n12 8",
"2\n9 7",
"1\n11",
"1\n9",
"1\n10",
"3\n8 12 11",
"2\n8 1",
"2\n10 1",
"2\n4 2",
"2\n8 2",
"2\n2 1... | 5ATCODER |
p03695 AtCoder Beginner Contest 064 - Colorful Leaderboard_3250 | In AtCoder, a person who has participated in a contest receives a color, which corresponds to the person's rating as follows:
* Rating 1-399 : gray
* Rating 400-799 : brown
* Rating 800-1199 : green
* Rating 1200-1599 : cyan
* Rating 1600-1999 : blue
* Rating 2000-2399 : yellow
* Rating 2400-2799 : orange
* Rating 280... | N=int(raw_input())
a=map(int,raw_input().split(' '))
color=[0]*8
free=0
for ai in a:
if ai<400:
color[0]+=1
elif ai<800:
color[1]+=1
elif ai<1200:
color[2]+=1
elif ai<1600:
color[3]+=1
elif ai<2000:
color[4]+=1
elif ai<2400:
color[5]+=1
elif ... | 1Python2 | {
"input": [
"4\n2100 2500 2700 2700",
"20\n800 810 820 830 840 850 860 870 880 890 900 910 920 930 940 950 960 970 980 990",
"5\n1100 1900 2800 3200 3200",
"4\n2100 2500 4217 2700",
"20\n800 810 820 830 840 850 860 870 880 890 900 1771 920 930 940 950 960 970 980 990",
"5\n1100 3348 2800 3200... | 5ATCODER |
p03695 AtCoder Beginner Contest 064 - Colorful Leaderboard_3251 | In AtCoder, a person who has participated in a contest receives a color, which corresponds to the person's rating as follows:
* Rating 1-399 : gray
* Rating 400-799 : brown
* Rating 800-1199 : green
* Rating 1200-1599 : cyan
* Rating 1600-1999 : blue
* Rating 2000-2399 : yellow
* Rating 2400-2799 : orange
* Rating 280... | #include <bits/stdc++.h>
using namespace std;
int main() {
int a;
std::cin >> a;
std::bitset<8> ls{};
int u = 0;
while (std::cin >> a) {
if (a < 3200) {
ls.set(a / 400);
} else {
u++;
}
}
std::cout << std::max(static_cast<int>(ls.count()), 1) << " "
<< ls.count() + u ... | 2C++ | {
"input": [
"4\n2100 2500 2700 2700",
"20\n800 810 820 830 840 850 860 870 880 890 900 910 920 930 940 950 960 970 980 990",
"5\n1100 1900 2800 3200 3200",
"4\n2100 2500 4217 2700",
"20\n800 810 820 830 840 850 860 870 880 890 900 1771 920 930 940 950 960 970 980 990",
"5\n1100 3348 2800 3200... | 5ATCODER |
p03695 AtCoder Beginner Contest 064 - Colorful Leaderboard_3252 | In AtCoder, a person who has participated in a contest receives a color, which corresponds to the person's rating as follows:
* Rating 1-399 : gray
* Rating 400-799 : brown
* Rating 800-1199 : green
* Rating 1200-1599 : cyan
* Rating 1600-1999 : blue
* Rating 2000-2399 : yellow
* Rating 2400-2799 : orange
* Rating 280... | n,a=open(0)
s=set();x=0
for i in map(int,a.split()):
j=i//400
if j<8:s.add(j)
else:x+=1
print(max(1,len(s)),len(s)+x) | 3Python3 | {
"input": [
"4\n2100 2500 2700 2700",
"20\n800 810 820 830 840 850 860 870 880 890 900 910 920 930 940 950 960 970 980 990",
"5\n1100 1900 2800 3200 3200",
"4\n2100 2500 4217 2700",
"20\n800 810 820 830 840 850 860 870 880 890 900 1771 920 930 940 950 960 970 980 990",
"5\n1100 3348 2800 3200... | 5ATCODER |
p03695 AtCoder Beginner Contest 064 - Colorful Leaderboard_3253 | In AtCoder, a person who has participated in a contest receives a color, which corresponds to the person's rating as follows:
* Rating 1-399 : gray
* Rating 400-799 : brown
* Rating 800-1199 : green
* Rating 1200-1599 : cyan
* Rating 1600-1999 : blue
* Rating 2000-2399 : yellow
* Rating 2400-2799 : orange
* Rating 280... | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int[] a=new int[4801];
int[] flag= {0,0,0,0,0,0,0,0,0};
int cnt=0;
for(int i=0;i<n;i++) {
a[i]=sc.nextInt();
if(3200<=a[i... | 4JAVA | {
"input": [
"4\n2100 2500 2700 2700",
"20\n800 810 820 830 840 850 860 870 880 890 900 910 920 930 940 950 960 970 980 990",
"5\n1100 1900 2800 3200 3200",
"4\n2100 2500 4217 2700",
"20\n800 810 820 830 840 850 860 870 880 890 900 1771 920 930 940 950 960 970 980 990",
"5\n1100 3348 2800 3200... | 5ATCODER |
p03850 AtCoder Regular Contest 066 - Addition and Subtraction Hard_3254 | Joisino has a formula consisting of N terms: A_1 op_1 A_2 ... op_{N-1} A_N. Here, A_i is an integer, and op_i is an binary operator either `+` or `-`. Because Joisino loves large numbers, she wants to maximize the evaluated value of the formula by inserting an arbitrary number of pairs of parentheses (possibly zero) in... | n = input()
s = map(int, ('+ ' + raw_input()).replace('+ ', '+').replace('- ', '-').split())
s0 = [abs(x) for x in s]
t = filter(lambda x: s[x + 1] < 0, xrange(n - 1)) + [n - 1] * 2
for i in xrange(1, n):
s[i] += s[i - 1]
s0[i] += s0[i - 1]
print max([s0[n - 1] - 2 * s0[t[i + 1]] + s0[t[i]] + s[t[i]] for i in xrange(... | 1Python2 | {
"input": [
"5\n1 - 2 + 3 - 4 + 5",
"3\n5 - 1 - 3",
"5\n1 - 20 - 13 + 14 - 5",
"5\n1 - 2 + 2 - 4 + 5",
"5\n1 - 38 - 13 + 14 - 5",
"5\n1 - 45 - 13 + 14 - 5",
"5\n2 - 45 - 13 + 14 - 5",
"5\n2 - 80 - 13 + 14 - 5",
"5\n2 - 57 - 13 + 14 - 5",
"5\n2 - 39 - 13 + 9 - 5",
"5\n1 - 2... | 5ATCODER |
p03850 AtCoder Regular Contest 066 - Addition and Subtraction Hard_3255 | Joisino has a formula consisting of N terms: A_1 op_1 A_2 ... op_{N-1} A_N. Here, A_i is an integer, and op_i is an binary operator either `+` or `-`. Because Joisino loves large numbers, she wants to maximize the evaluated value of the formula by inserting an arbitrary number of pairs of parentheses (possibly zero) in... | #include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int a[N];
long long f[N][3];
int main()
{
int n; scanf("%d%d",&n,&a[1]);
for(int i=2;i<=n;++i)
{
char op[2];
scanf("%s%d",op,&a[i]);
a[i]=(op[0]=='+'?a[i]:-a[i]);
}
f[1][0]=a[1],f[1][1]=f[1][2]=-1ll<<60;
for(int i=2;i<=n;++i)
{
f[i][0]=max(f... | 2C++ | {
"input": [
"5\n1 - 2 + 3 - 4 + 5",
"3\n5 - 1 - 3",
"5\n1 - 20 - 13 + 14 - 5",
"5\n1 - 2 + 2 - 4 + 5",
"5\n1 - 38 - 13 + 14 - 5",
"5\n1 - 45 - 13 + 14 - 5",
"5\n2 - 45 - 13 + 14 - 5",
"5\n2 - 80 - 13 + 14 - 5",
"5\n2 - 57 - 13 + 14 - 5",
"5\n2 - 39 - 13 + 9 - 5",
"5\n1 - 2... | 5ATCODER |
p03850 AtCoder Regular Contest 066 - Addition and Subtraction Hard_3256 | Joisino has a formula consisting of N terms: A_1 op_1 A_2 ... op_{N-1} A_N. Here, A_i is an integer, and op_i is an binary operator either `+` or `-`. Because Joisino loves large numbers, she wants to maximize the evaluated value of the formula by inserting an arbitrary number of pairs of parentheses (possibly zero) in... | #!/usr/bin/env python3
def solve(n):
s = input()
sum_a = 0
sum_n = 0
sum_np = 0
min_sum_np = 10 ** 15
j = s.find('-')
if j < 0:
return sum(list(map(int, s.split(' + '))))
sum_a = sum(list(map(int, s[:j - 1].split(' + '))))
j += 2
s += ' '
len_s = len(s)
sign ... | 3Python3 | {
"input": [
"5\n1 - 2 + 3 - 4 + 5",
"3\n5 - 1 - 3",
"5\n1 - 20 - 13 + 14 - 5",
"5\n1 - 2 + 2 - 4 + 5",
"5\n1 - 38 - 13 + 14 - 5",
"5\n1 - 45 - 13 + 14 - 5",
"5\n2 - 45 - 13 + 14 - 5",
"5\n2 - 80 - 13 + 14 - 5",
"5\n2 - 57 - 13 + 14 - 5",
"5\n2 - 39 - 13 + 9 - 5",
"5\n1 - 2... | 5ATCODER |
p03850 AtCoder Regular Contest 066 - Addition and Subtraction Hard_3257 | Joisino has a formula consisting of N terms: A_1 op_1 A_2 ... op_{N-1} A_N. Here, A_i is an integer, and op_i is an binary operator either `+` or `-`. Because Joisino loves large numbers, she wants to maximize the evaluated value of the formula by inserting an arbitrary number of pairs of parentheses (possibly zero) in... | import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
class Main{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
long[] sum = new long[N];
long[] a = new long[N];
long[] abssum = new long[N+1];
... | 4JAVA | {
"input": [
"5\n1 - 2 + 3 - 4 + 5",
"3\n5 - 1 - 3",
"5\n1 - 20 - 13 + 14 - 5",
"5\n1 - 2 + 2 - 4 + 5",
"5\n1 - 38 - 13 + 14 - 5",
"5\n1 - 45 - 13 + 14 - 5",
"5\n2 - 45 - 13 + 14 - 5",
"5\n2 - 80 - 13 + 14 - 5",
"5\n2 - 57 - 13 + 14 - 5",
"5\n2 - 39 - 13 + 9 - 5",
"5\n1 - 2... | 5ATCODER |
p04017 AtCoder Regular Contest 060 - Tak and Hotels_3258 | N hotels are located on a straight line. The coordinate of the i-th hotel (1 \leq i \leq N) is x_i.
Tak the traveler has the following two personal principles:
* He never travels a distance of more than L in a single day.
* He never sleeps in the open. That is, he must stay at a hotel at the end of a day.
You are ... | import bisect
n=int(raw_input())
x=map(int,raw_input().split())+[float('inf')]
l=int(raw_input())
q=int(raw_input())
r=[[0]*20 for _ in xrange(n)]
for i in xrange(n):
if x[i]+l==x[bisect.bisect_left(x,x[i]+l)]:
r[i][0]=bisect.bisect_left(x,x[i]+l)
else:
r[i][0]=bisect.bisect_left(x,x[i]+l)-1
... | 1Python2 | {
"input": [
"9\n1 3 6 13 15 18 19 29 31\n10\n4\n1 8\n7 3\n6 7\n8 5",
"9\n1 3 6 13 15 18 19 29 31\n10\n2\n1 8\n7 3\n6 7\n8 5",
"9\n1 6 6 13 23 18 19 29 31\n10\n3\n1 8\n7 3\n6 7\n8 10",
"9\n1 3 6 13 23 18 19 29 31\n10\n2\n1 8\n7 5\n6 7\n8 5",
"9\n1 3 6 13 23 18 19 29 31\n10\n2\n1 9\n7 3\n6 7\n8 10"... | 5ATCODER |
p04017 AtCoder Regular Contest 060 - Tak and Hotels_3259 | N hotels are located on a straight line. The coordinate of the i-th hotel (1 \leq i \leq N) is x_i.
Tak the traveler has the following two personal principles:
* He never travels a distance of more than L in a single day.
* He never sleeps in the open. That is, he must stay at a hotel at the end of a day.
You are ... | #include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=100005;
int N,L,Q;
int x[MAXN],nxt[MAXN][25];
int ans[MAXN];
//int dis[MAXN];
int main()
{
scanf("%d",&N);
for(int i=1;i<=N;i++)
scanf("%d",&x[i]);
scanf("%d%d",&L,&Q);
memset(nxt,0x3F,sizeof nxt);
for(int i=1;i<=N;i++)
... | 2C++ | {
"input": [
"9\n1 3 6 13 15 18 19 29 31\n10\n4\n1 8\n7 3\n6 7\n8 5",
"9\n1 3 6 13 15 18 19 29 31\n10\n2\n1 8\n7 3\n6 7\n8 5",
"9\n1 6 6 13 23 18 19 29 31\n10\n3\n1 8\n7 3\n6 7\n8 10",
"9\n1 3 6 13 23 18 19 29 31\n10\n2\n1 8\n7 5\n6 7\n8 5",
"9\n1 3 6 13 23 18 19 29 31\n10\n2\n1 9\n7 3\n6 7\n8 10"... | 5ATCODER |
p04017 AtCoder Regular Contest 060 - Tak and Hotels_3260 | N hotels are located on a straight line. The coordinate of the i-th hotel (1 \leq i \leq N) is x_i.
Tak the traveler has the following two personal principles:
* He never travels a distance of more than L in a single day.
* He never sleeps in the open. That is, he must stay at a hotel at the end of a day.
You are ... | import bisect
N = int(input())
x = list(map(int, input().split()))
L = int(input())
dest = []
dest_1 = [0] * N
for i in range(N):
dest_1[i] = bisect.bisect_left(x, x[i] + L + 0.5) - 1
dest.append(dest_1)
for i in range(1, len(bin(N - 1)) - 1):
dest_prev = dest[i - 1]
dest_i = [0] * N
for j in range(N)... | 3Python3 | {
"input": [
"9\n1 3 6 13 15 18 19 29 31\n10\n4\n1 8\n7 3\n6 7\n8 5",
"9\n1 3 6 13 15 18 19 29 31\n10\n2\n1 8\n7 3\n6 7\n8 5",
"9\n1 6 6 13 23 18 19 29 31\n10\n3\n1 8\n7 3\n6 7\n8 10",
"9\n1 3 6 13 23 18 19 29 31\n10\n2\n1 8\n7 5\n6 7\n8 5",
"9\n1 3 6 13 23 18 19 29 31\n10\n2\n1 9\n7 3\n6 7\n8 10"... | 5ATCODER |
p04017 AtCoder Regular Contest 060 - Tak and Hotels_3261 | N hotels are located on a straight line. The coordinate of the i-th hotel (1 \leq i \leq N) is x_i.
Tak the traveler has the following two personal principles:
* He never travels a distance of more than L in a single day.
* He never sleeps in the open. That is, he must stay at a hotel at the end of a day.
You are ... |
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
public class Main {
public static void main(String[] args) {
FastScanner sc = new FastScanner();
int N = sc.nextInt();
long[] x = sc.nextLongList(N);
long L = sc.nextLong();
int[][] r = new int[36][N];
... | 4JAVA | {
"input": [
"9\n1 3 6 13 15 18 19 29 31\n10\n4\n1 8\n7 3\n6 7\n8 5",
"9\n1 3 6 13 15 18 19 29 31\n10\n2\n1 8\n7 3\n6 7\n8 5",
"9\n1 6 6 13 23 18 19 29 31\n10\n3\n1 8\n7 3\n6 7\n8 10",
"9\n1 3 6 13 23 18 19 29 31\n10\n2\n1 8\n7 5\n6 7\n8 5",
"9\n1 3 6 13 23 18 19 29 31\n10\n2\n1 9\n7 3\n6 7\n8 10"... | 5ATCODER |
p00101 Aizu PR_3262 | An English booklet has been created for publicizing Aizu to the world. When you read it carefully, you found a misnomer (an error in writing) on the last name of Masayuki Hoshina, the lord of the Aizu domain. The booklet says "Hoshino" not "Hoshina".
Your task is to write a program which replace all the words "Hoshino... | for i in range(int(raw_input())):
print raw_input().replace('Hoshino', 'Hoshina') | 1Python2 | {
"input": [
"3\nHoshino\nHashino\nMasayuki Hoshino was the grandson of Ieyasu Tokugawa.",
"3\nHoshimo\nHashino\nMasayuki Hoshino was the grandson of Ieyasu Tokugawa.",
"3\nHoshimo\nHashino\nMasayuki Hoshino was the grandspn of Ieyasu Tokugawa.",
"3\nHoshimo\nHashino\nMasayuki Hoshino was the grandspn... | 6AIZU |
p00101 Aizu PR_3263 | An English booklet has been created for publicizing Aizu to the world. When you read it carefully, you found a misnomer (an error in writing) on the last name of Masayuki Hoshina, the lord of the Aizu domain. The booklet says "Hoshino" not "Hoshina".
Your task is to write a program which replace all the words "Hoshino... | #include <iostream>
#include <cstring>
using namespace std;
int main(){
int n,len;
string a;
cin>>n;
getline(cin,a);
for(int i=0;i<n;i++){
getline(cin,a);
len=a.size();
for(int o=0;o<=len;o++)
if(a[o]=='H'){
if(a[o+1]=='o')
if(a[o+2]=='s')
if(a[o+3]=='h')
if(a[o+4]=='i')
if(a[o+5]=='n')
if(a[o+6]=='o')
a[o+6]='a';}
cou... | 2C++ | {
"input": [
"3\nHoshino\nHashino\nMasayuki Hoshino was the grandson of Ieyasu Tokugawa.",
"3\nHoshimo\nHashino\nMasayuki Hoshino was the grandson of Ieyasu Tokugawa.",
"3\nHoshimo\nHashino\nMasayuki Hoshino was the grandspn of Ieyasu Tokugawa.",
"3\nHoshimo\nHashino\nMasayuki Hoshino was the grandspn... | 6AIZU |
p00101 Aizu PR_3264 | An English booklet has been created for publicizing Aizu to the world. When you read it carefully, you found a misnomer (an error in writing) on the last name of Masayuki Hoshina, the lord of the Aizu domain. The booklet says "Hoshino" not "Hoshina".
Your task is to write a program which replace all the words "Hoshino... | [print(input().replace("Hoshino","Hoshina")) for i in range(int(input()))]
| 3Python3 | {
"input": [
"3\nHoshino\nHashino\nMasayuki Hoshino was the grandson of Ieyasu Tokugawa.",
"3\nHoshimo\nHashino\nMasayuki Hoshino was the grandson of Ieyasu Tokugawa.",
"3\nHoshimo\nHashino\nMasayuki Hoshino was the grandspn of Ieyasu Tokugawa.",
"3\nHoshimo\nHashino\nMasayuki Hoshino was the grandspn... | 6AIZU |
p00101 Aizu PR_3265 | An English booklet has been created for publicizing Aizu to the world. When you read it carefully, you found a misnomer (an error in writing) on the last name of Masayuki Hoshina, the lord of the Aizu domain. The booklet says "Hoshino" not "Hoshina".
Your task is to write a program which replace all the words "Hoshino... | import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
public class Main{
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int count = Integer.parseInt(br.readLine());
... | 4JAVA | {
"input": [
"3\nHoshino\nHashino\nMasayuki Hoshino was the grandson of Ieyasu Tokugawa.",
"3\nHoshimo\nHashino\nMasayuki Hoshino was the grandson of Ieyasu Tokugawa.",
"3\nHoshimo\nHashino\nMasayuki Hoshino was the grandspn of Ieyasu Tokugawa.",
"3\nHoshimo\nHashino\nMasayuki Hoshino was the grandspn... | 6AIZU |
p00234 Aizu Buried Treasure_3266 | Aizu has an ancient legend of buried treasure. You have finally found the place where the buried treasure is buried. Since we know the depth of the buried treasure and the condition of the strata to be dug, we can reach the buried treasure at the lowest cost with careful planning. So you decided to create a program tha... | #include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <set>
using namespace std;
class Situation{
public:
int oxigen;
int money;
int h,w;
int miningCnt;
int bitmask;
set<pair<int,int> > visited;
};
int mem[11][11][1<<10][51];
... | 2C++ | {
"input": [
"3 3\n100 10 10\n-100 -20 -100\n-100 -20 -100\n-100 -20 -100\n3 3\n100 10 10\n-100 -20 -100\n-100 -20 -20\n-100 -60 -20\n3 3\n100 10 3\n-100 -20 -100\n-20 -20 -20\n-20 -100 -20\n3 3\n100 3 3\n-100 -20 -30\n-100 -20 2\n-100 -20 -20\n4 5\n1500 5 4\n-10 -380 -250 -250\n-90 2 -80 8\n-250 -130 -330 -120\n... | 6AIZU |
p00234 Aizu Buried Treasure_3267 | Aizu has an ancient legend of buried treasure. You have finally found the place where the buried treasure is buried. Since we know the depth of the buried treasure and the condition of the strata to be dug, we can reach the buried treasure at the lowest cost with careful planning. So you decided to create a program tha... | import sys
sys.setrecursionlimit(1000000)
INF = 10 ** 20
def update_state(state, newx):
tmp = list(state)
tmp[newx] = 1
return tuple(tmp)
def get_co(x, y):
dc = do = 0
score = mp[y][x]
if score < 0:
dc = -score
else:
do = score
return dc, do
def minimum_cost(x, y, state, ox, goal, dic, w, m):... | 3Python3 | {
"input": [
"3 3\n100 10 10\n-100 -20 -100\n-100 -20 -100\n-100 -20 -100\n3 3\n100 10 10\n-100 -20 -100\n-100 -20 -20\n-100 -60 -20\n3 3\n100 10 3\n-100 -20 -100\n-20 -20 -20\n-20 -100 -20\n3 3\n100 3 3\n-100 -20 -30\n-100 -20 2\n-100 -20 -20\n4 5\n1500 5 4\n-10 -380 -250 -250\n-90 2 -80 8\n-250 -130 -330 -120\n... | 6AIZU |
p00234 Aizu Buried Treasure_3268 | Aizu has an ancient legend of buried treasure. You have finally found the place where the buried treasure is buried. Since we know the depth of the buried treasure and the condition of the strata to be dug, we can reach the buried treasure at the lowest cost with careful planning. So you decided to create a program tha... | import java.util.PriorityQueue;
import java.util.Scanner;
public class Main {
static class State implements Comparable<State>{
int x, y, l, r, money, oxygen;
State(int x, int y, int l, int r, int money, int oxygen){
this.x=x;
this.y=y;
this.l=l;
... | 4JAVA | {
"input": [
"3 3\n100 10 10\n-100 -20 -100\n-100 -20 -100\n-100 -20 -100\n3 3\n100 10 10\n-100 -20 -100\n-100 -20 -20\n-100 -60 -20\n3 3\n100 10 3\n-100 -20 -100\n-20 -20 -20\n-20 -100 -20\n3 3\n100 3 3\n-100 -20 -30\n-100 -20 2\n-100 -20 -20\n4 5\n1500 5 4\n-10 -380 -250 -250\n-90 2 -80 8\n-250 -130 -330 -120\n... | 6AIZU |
p00396 Playing With Stones_3269 | Playing with Stones
Koshiro and Ukiko are playing a game with black and white stones. The rules of the game are as follows:
1. Before starting the game, they define some small areas and place "one or more black stones and one or more white stones" in each of the areas.
2. Koshiro and Ukiko alternately select an area ... | #include<iostream>
#include<algorithm>
#include<set>
using namespace std;
int grundy[201][101];
int dfs(int w, int b){
if(grundy[w][b] >= 0){
return grundy[w][b];
}
set<int> st;
if(w > 0){
st.insert(dfs(w - 1, b));
}
if(b > 0){
st.insert(dfs(w + 1, b - 1));
}
f... | 2C++ | {
"input": [
"4\n24 99\n15 68\n12 90\n95 79",
"3\n2 46\n94 8\n46 57",
"4\n24 99\n15 68\n12 90\n95 66",
"3\n0 46\n94 8\n46 57",
"4\n24 99\n15 44\n12 90\n95 66",
"3\n0 46\n9 8\n46 57",
"4\n18 99\n15 44\n12 90\n95 66",
"3\n1 46\n9 8\n46 57",
"4\n18 99\n15 44\n3 90\n95 66",
"3\n1 6... | 6AIZU |
p00396 Playing With Stones_3270 | Playing with Stones
Koshiro and Ukiko are playing a game with black and white stones. The rules of the game are as follows:
1. Before starting the game, they define some small areas and place "one or more black stones and one or more white stones" in each of the areas.
2. Koshiro and Ukiko alternately select an area ... | #!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdi... | 3Python3 | {
"input": [
"4\n24 99\n15 68\n12 90\n95 79",
"3\n2 46\n94 8\n46 57",
"4\n24 99\n15 68\n12 90\n95 66",
"3\n0 46\n94 8\n46 57",
"4\n24 99\n15 44\n12 90\n95 66",
"3\n0 46\n9 8\n46 57",
"4\n18 99\n15 44\n12 90\n95 66",
"3\n1 46\n9 8\n46 57",
"4\n18 99\n15 44\n3 90\n95 66",
"3\n1 6... | 6AIZU |
p00611 Building Water Ways_3271 | In ancient times, Romans constructed numerous water ways to supply water to cities and industrial sites. These water ways were amongst the greatest engineering feats of the ancient world.
These water ways contributed to social infrastructures which improved people's quality of life. On the other hand, problems related... | #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 _3_ 1
using namespace std;
/*
15:25 -
?????????????????????????????????
??????????????????
??£??????
????????????????????¢????¨????
?????¨?????????????????????????°???????????????????????¶?????????????
... | 2C++ | {
"input": [
"3 8\n########\n#P....*#\n########\n10 10\n##########\n#P.......#\n#..#*....#\n#..#*.#.*#\n#.....#*.#\n#*.......#\n#..##....#\n#...#.P..#\n#P......P#\n##########\n0 0",
"3 8\n########\n#P....*#\n########\n10 10\n##########\n#P.......#\n#..#*....#\n#..#*.#.*#\n#.....#*.#\n#*.......#\n#..##....#\n#... | 6AIZU |
p00749 Off Balance_3272 | You are working for an administration office of the International Center for Picassonian Cubism (ICPC), which plans to build a new art gallery for young artists. The center is organizing an architectural design competition to find the best design for the new building.
Submitted designs will look like a screenshot of a... | from collections import deque
dd = [(-1, 0), (0, -1), (1, 0), (0, 1)]
while 1:
w, h = map(int, raw_input().split())
if w == h == 0:
break
P = [list(raw_input()) for i in xrange(h)]
L = [[None]*w for i in xrange(h)]
deq = deque()
cnt = 0
g = []; XL = []; XR = []; M = []; C = []
f... | 1Python2 | {
"input": [
"4 5\n..33\n..33\n2222\n..1.\n.111\n5 7\n....1\n.1..1\n.1..1\n11..1\n.2222\n..111\n...1.\n3 6\n.3.\n233\n23.\n22.\n.11\n.11\n4 3\n2222\n..11\n..11\n4 5\n.3..\n33..\n322.\n2211\n.11.\n3 3\n222\n2.1\n111\n3 4\n11.\n11.\n.2.\n222\n3 4\n.11\n.11\n.2.\n222\n2 7\n11\n.1\n21\n22\n23\n.3\n33\n2 3\n1.\n11\n.1... | 6AIZU |
p00749 Off Balance_3273 | You are working for an administration office of the International Center for Picassonian Cubism (ICPC), which plans to build a new art gallery for young artists. The center is organizing an architectural design competition to find the best design for the new building.
Submitted designs will look like a screenshot of a... | #include <iostream>
#include <algorithm>
#include <cctype>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
typedef pair<int,int> P;
int w,h,dw[4]={1,0,-1,0},dh[4]={0,1,0,-1};
double eps=1e-8;
bool visited[61][10];
vector<string> vc;
struct st{
bool ok;
d... | 2C++ | {
"input": [
"4 5\n..33\n..33\n2222\n..1.\n.111\n5 7\n....1\n.1..1\n.1..1\n11..1\n.2222\n..111\n...1.\n3 6\n.3.\n233\n23.\n22.\n.11\n.11\n4 3\n2222\n..11\n..11\n4 5\n.3..\n33..\n322.\n2211\n.11.\n3 3\n222\n2.1\n111\n3 4\n11.\n11.\n.2.\n222\n3 4\n.11\n.11\n.2.\n222\n2 7\n11\n.1\n21\n22\n23\n.3\n33\n2 3\n1.\n11\n.1... | 6AIZU |
p00749 Off Balance_3274 | You are working for an administration office of the International Center for Picassonian Cubism (ICPC), which plans to build a new art gallery for young artists. The center is organizing an architectural design competition to find the best design for the new building.
Submitted designs will look like a screenshot of a... | while True:
w, h = map(int, input().split())
if w == 0:
break
mp = [[0] + list(input()) + [0] for _ in range(h)]
mp.insert(0, [0] * (w + 2))
mp.append([0] * (w + 2))
for y in range(1, h + 1):
for x in range(1, w + 1):
if mp[y][x] == ".":
mp[y][x] = 0
else:
mp[y][x] = int... | 3Python3 | {
"input": [
"4 5\n..33\n..33\n2222\n..1.\n.111\n5 7\n....1\n.1..1\n.1..1\n11..1\n.2222\n..111\n...1.\n3 6\n.3.\n233\n23.\n22.\n.11\n.11\n4 3\n2222\n..11\n..11\n4 5\n.3..\n33..\n322.\n2211\n.11.\n3 3\n222\n2.1\n111\n3 4\n11.\n11.\n.2.\n222\n3 4\n.11\n.11\n.2.\n222\n2 7\n11\n.1\n21\n22\n23\n.3\n33\n2 3\n1.\n11\n.1... | 6AIZU |
p00749 Off Balance_3275 | You are working for an administration office of the International Center for Picassonian Cubism (ICPC), which plans to build a new art gallery for young artists. The center is organizing an architectural design competition to find the best design for the new building.
Submitted designs will look like a screenshot of a... | import java.awt.Point;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.HashSet;
import java.util.Scanner;
public class Main {
public static final int[] dx = {1,0,-1,0};
public static final int[] dy = {0,-1,0,1};
public static void main(String[] args) {
Scanner sc ... | 4JAVA | {
"input": [
"4 5\n..33\n..33\n2222\n..1.\n.111\n5 7\n....1\n.1..1\n.1..1\n11..1\n.2222\n..111\n...1.\n3 6\n.3.\n233\n23.\n22.\n.11\n.11\n4 3\n2222\n..11\n..11\n4 5\n.3..\n33..\n322.\n2211\n.11.\n3 3\n222\n2.1\n111\n3 4\n11.\n11.\n.2.\n222\n3 4\n.11\n.11\n.2.\n222\n2 7\n11\n.1\n21\n22\n23\n.3\n33\n2 3\n1.\n11\n.1... | 6AIZU |
p00887 Awkward Lights_3276 | You are working as a night watchman in an office building. Your task is to check whether all the lights in the building are turned off after all the office workers in the building have left the office. If there are lights that are turned on, you must turn off those lights. This task is not as easy as it sounds to be be... | #include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> vi;
typedef vector<vi> vvi;
typed... | 2C++ | {
"input": [
"1 1 1\n1\n2 2 1\n1 1\n1 1\n3 2 1\n1 0 1\n0 1 0\n3 3 1\n1 0 1\n0 1 0\n1 0 1\n4 4 2\n1 1 0 1\n0 0 0 1\n1 0 1 1\n1 0 0 0\n5 5 1\n1 1 1 0 1\n0 1 0 1 0\n1 0 1 0 1\n0 1 0 1 0\n1 0 1 0 1\n5 5 2\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n11 11 3\n0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0\n0 ... | 6AIZU |
p00887 Awkward Lights_3277 | You are working as a night watchman in an office building. Your task is to check whether all the lights in the building are turned off after all the office workers in the building have left the office. If there are lights that are turned on, you must turn off those lights. This task is not as easy as it sounds to be be... | import sys,queue,math,copy,itertools
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
while True:
M,N,D = LI()
if N == 0 : break
S = []
for _ in range(N):
S.extend(LI())
x = []
for i in range(N):
for j in range(M):
y = [0 for _ in range(N*M)]
... | 3Python3 | {
"input": [
"1 1 1\n1\n2 2 1\n1 1\n1 1\n3 2 1\n1 0 1\n0 1 0\n3 3 1\n1 0 1\n0 1 0\n1 0 1\n4 4 2\n1 1 0 1\n0 0 0 1\n1 0 1 1\n1 0 0 0\n5 5 1\n1 1 1 0 1\n0 1 0 1 0\n1 0 1 0 1\n0 1 0 1 0\n1 0 1 0 1\n5 5 2\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n11 11 3\n0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0\n0 ... | 6AIZU |
p00887 Awkward Lights_3278 | You are working as a night watchman in an office building. Your task is to check whether all the lights in the building are turned off after all the office workers in the building have left the office. If there are lights that are turned on, you must turn off those lights. This task is not as easy as it sounds to be be... | import java.util.*;
public class Main {
int[][] board;
int d, M, N, S;
int[][] matrix;
void run(){
Scanner in = new Scanner(System.in);
for(;;){
M = in.nextInt();
N = in.nextInt();
d = in.nextInt();
if(M==0 && N==0 && d==0) return ;
board = new int[N][M];
for(int i=0; i<N; i++){
for(int... | 4JAVA | {
"input": [
"1 1 1\n1\n2 2 1\n1 1\n1 1\n3 2 1\n1 0 1\n0 1 0\n3 3 1\n1 0 1\n0 1 0\n1 0 1\n4 4 2\n1 1 0 1\n0 0 0 1\n1 0 1 1\n1 0 0 0\n5 5 1\n1 1 1 0 1\n0 1 0 1 0\n1 0 1 0 1\n0 1 0 1 0\n1 0 1 0 1\n5 5 2\n0 0 0 0 0\n0 0 0 0 0\n0 0 1 0 0\n0 0 0 0 0\n0 0 0 0 0\n11 11 3\n0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0\n0 ... | 6AIZU |
p01018 Warping Girl_3279 | Problem
Aizu Magic School is a school where people who can use magic gather. Haruka, one of the students of that school, can use the magic of warp on the magic team.
From her house to the school, there is a straight road of length L. There are also magic circles on this road.
She uses this road every day to go to sch... | #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#in... | 2C++ | {
"input": [
"10 2\n2 3 1\n3 5 1",
"1 0",
"10 3\n2 2 1\n4 2 1\n8 1 1",
"10 2\n2 3 1\n1 5 1",
"10 2\n2 3 1\n1 5 0",
"10 0\n2 3 1\n1 5 1",
"18 0\n2 3 1\n1 5 1",
"0 0\n2 -1 1\n0 1 1",
"1 0\n2 0 2\n1 2 1",
"2 1\n1 0 7\n4 -1 0",
"10 3\n2 0 1\n4 2 1\n8 1 1",
"34 0\n2 3 1\n1 5... | 6AIZU |
p01018 Warping Girl_3280 | Problem
Aizu Magic School is a school where people who can use magic gather. Haruka, one of the students of that school, can use the magic of warp on the magic team.
From her house to the school, there is a straight road of length L. There are also magic circles on this road.
She uses this road every day to go to sch... | INF = 10 ** 20
l, n = map(int, input().split())
lst = [list(map(int, input().split())) for _ in range(n)] + [[l, 0, INF]]
lst.sort()
score = {}
for p, _, _ in lst:
score[p] = p
for i in range(n + 1):
p, d, t = lst[i]
for j in range(i + 1, n + 1):
to_p, _, _ = lst[j]
if to_p >= p + d:
score[to_p] = m... | 3Python3 | {
"input": [
"10 2\n2 3 1\n3 5 1",
"1 0",
"10 3\n2 2 1\n4 2 1\n8 1 1",
"10 2\n2 3 1\n1 5 1",
"10 2\n2 3 1\n1 5 0",
"10 0\n2 3 1\n1 5 1",
"18 0\n2 3 1\n1 5 1",
"0 0\n2 -1 1\n0 1 1",
"1 0\n2 0 2\n1 2 1",
"2 1\n1 0 7\n4 -1 0",
"10 3\n2 0 1\n4 2 1\n8 1 1",
"34 0\n2 3 1\n1 5... | 6AIZU |
p01151 Divisor is the Conqueror_3281 | Divisor is the Conquerer is a solitaire card game. Although this simple game itself is a great way to pass one’s time, you, a programmer, always kill your time by programming. Your task is to write a computer program that automatically solves Divisor is the Conquerer games. Here is the rule of this game:
First, you ra... | #include <iostream>
#include <cstring>
using namespace std;
#define REP(i,n,m) for(int i=n;i<m;i++)
#define rep(i,n) REP(i,0,n)
int n,cnt[14],ans[54];
bool solve(int idx,int sum){
if(idx == 0 && sum == 0) return true;
if(idx < 0 || sum < 0) return false;
rep(i,14){
if(cnt[i]>0 && (sum - i) % i == 0){
ans[id... | 2C++ | {
"input": [
"5\n1 2 3 3 7\n4\n2 3 3 3\n0",
"5\n1 2 3 6 7\n4\n2 3 3 3\n0",
"5\n1 2 6 6 7\n4\n2 3 3 3\n0",
"5\n1 3 3 4 7\n4\n2 3 3 3\n0",
"5\n1 2 3 3 7\n4\n2 3 2 3\n0",
"5\n1 2 6 6 7\n4\n2 3 2 3\n0",
"5\n1 2 3 6 7\n0\n2 5 3 3\n0",
"5\n1 2 6 6 7\n0\n2 3 2 3\n0",
"5\n1 2 3 9 7\n4\n2 5... | 6AIZU |
p01151 Divisor is the Conqueror_3282 | Divisor is the Conquerer is a solitaire card game. Although this simple game itself is a great way to pass one’s time, you, a programmer, always kill your time by programming. Your task is to write a computer program that automatically solves Divisor is the Conquerer games. Here is the rule of this game:
First, you ra... | import java.util.Scanner;
//Divisor is the Conqueror
public class Main{
int n;
int[] c, res;
boolean dfs(int k, int rest){
if(k<0)return true;
for(int i=1;i<14;i++){
if(c[i]==0||(rest-i)%i!=0)continue;
c[i]--; res[k] = i;
if(dfs(k-1, rest-i))return true;
c[i]++;
}
return false;
}
void run... | 4JAVA | {
"input": [
"5\n1 2 3 3 7\n4\n2 3 3 3\n0",
"5\n1 2 3 6 7\n4\n2 3 3 3\n0",
"5\n1 2 6 6 7\n4\n2 3 3 3\n0",
"5\n1 3 3 4 7\n4\n2 3 3 3\n0",
"5\n1 2 3 3 7\n4\n2 3 2 3\n0",
"5\n1 2 6 6 7\n4\n2 3 2 3\n0",
"5\n1 2 3 6 7\n0\n2 5 3 3\n0",
"5\n1 2 6 6 7\n0\n2 3 2 3\n0",
"5\n1 2 3 9 7\n4\n2 5... | 6AIZU |
p01290 Queen's Case_3283 | A small country called Maltius was governed by a queen. The queen was known as an oppressive ruler. People in the country suffered from heavy taxes and forced labor. So some young people decided to form a revolutionary army and fight against the queen. Now, they besieged the palace and have just rushed into the entranc... | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#d... | 2C++ | {
"input": [
"2 2\nQE\nEA\n3 1\nQAE\n3 1\nAQE\n5 5\n..E..\n.###.\nA###Q\n.###.\n..E..\n5 1\nA.E.Q\n5 5\nA....\n.\n..E..\n.####\n....Q\n0 0",
"2 2\nQE\nEA\n3 1\nQAE\n3 1\nAQE\n5 5\n..E..\n.###.\nA###Q\n.###.\n..E..\n5 1\nA.E.Q\n5 5\nA....\n####.\n..E..\n.####\n....Q\n0 0",
"2 2\nQE\nEA\n3 1\nQAE\n3 1\nAQE\... | 6AIZU |
p01290 Queen's Case_3284 | A small country called Maltius was governed by a queen. The queen was known as an oppressive ruler. People in the country suffered from heavy taxes and forced labor. So some young people decided to form a revolutionary army and fight against the queen. Now, they besieged the palace and have just rushed into the entranc... | from collections import deque, defaultdict
import sys
readline = sys.stdin.readline
write = sys.stdout.write
dd = ((-1, 0), (0, -1), (1, 0), (0, 1), (0, 0))
def solve():
W, H = map(int, readline().split())
if W == H == 0:
return False
S = [readline().strip() for i in range(H)]
px = py = qx = qy ... | 3Python3 | {
"input": [
"2 2\nQE\nEA\n3 1\nQAE\n3 1\nAQE\n5 5\n..E..\n.###.\nA###Q\n.###.\n..E..\n5 1\nA.E.Q\n5 5\nA....\n.\n..E..\n.####\n....Q\n0 0",
"2 2\nQE\nEA\n3 1\nQAE\n3 1\nAQE\n5 5\n..E..\n.###.\nA###Q\n.###.\n..E..\n5 1\nA.E.Q\n5 5\nA....\n####.\n..E..\n.####\n....Q\n0 0",
"2 2\nQE\nEA\n3 1\nQAE\n3 1\nAQE\... | 6AIZU |
p01290 Queen's Case_3285 | A small country called Maltius was governed by a queen. The queen was known as an oppressive ruler. People in the country suffered from heavy taxes and forced labor. So some young people decided to form a revolutionary army and fight against the queen. Now, they besieged the palace and have just rushed into the entranc... | import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
class Main {
public static void main(String[] args) throws IOException {
new Main().run();
}
void run() throws IOException {
Scanner sc = new Scanner(System.in);
while (true) {
int W = sc.nextInt();... | 4JAVA | {
"input": [
"2 2\nQE\nEA\n3 1\nQAE\n3 1\nAQE\n5 5\n..E..\n.###.\nA###Q\n.###.\n..E..\n5 1\nA.E.Q\n5 5\nA....\n.\n..E..\n.####\n....Q\n0 0",
"2 2\nQE\nEA\n3 1\nQAE\n3 1\nAQE\n5 5\n..E..\n.###.\nA###Q\n.###.\n..E..\n5 1\nA.E.Q\n5 5\nA....\n####.\n..E..\n.####\n....Q\n0 0",
"2 2\nQE\nEA\n3 1\nQAE\n3 1\nAQE\... | 6AIZU |
p01459 Light Road_3286 | There is an evil creature in a square on N-by-M grid (2 \leq N, M \leq 100), and you want to kill it using a laser generator located in a different square. Since the location and direction of the laser generator are fixed, you may need to use several mirrors to reflect laser beams. There are some obstacles on the grid ... | #include<iostream>
#include<string.h>
#include<queue>
#define inf 1000000001
using namespace std;
int X[4]={0,1,0,-1};
int Y[4]={-1,0,1,0};
int H,W,A,si,sj;
char map[100][100];
bool in(int y,int x){
if(y<0 || x<0 || y>=H || x>=W)return false;
return true;
}
class State{
public:
int y,x,muki,numL,numR;
St... | 2C++ | {
"input": [
"3 3 1\nS#.\n...\n.#G",
"3 3 1\nS#G\n...\n.#.",
"3 3 2\nS#.\n...\n.#G",
"4 3 2\nS..\n...\n..#\n.#G",
"1 3 1\nS#G\n...\n.#.",
"3 3 2\nS#.\n...\n/#G",
"4 3 2\nS..\n...\n..#\nG#.",
"3 3 2\nS#.\n...\n.$G",
"1 3 2\nS#G\n...\n.#.",
"5 3 2\nS#.\n...\n/#G",
"3 3 0\nS#.... | 6AIZU |
p01459 Light Road_3287 | There is an evil creature in a square on N-by-M grid (2 \leq N, M \leq 100), and you want to kill it using a laser generator located in a different square. Since the location and direction of the laser generator are fixed, you may need to use several mirrors to reflect laser beams. There are some obstacles on the grid ... | from collections import deque
N, M, A = map(int, input().split())
MP = [[0]*M for i in range(N)]
sx = sy = gx = gy = -1
for i in range(N):
for j, c in enumerate(input()):
if c == '#':
MP[i][j] = 1
elif c == 'S':
sx = j; sy = i
elif c == 'G':
gx = j; gy = i... | 3Python3 | {
"input": [
"3 3 1\nS#.\n...\n.#G",
"3 3 1\nS#G\n...\n.#.",
"3 3 2\nS#.\n...\n.#G",
"4 3 2\nS..\n...\n..#\n.#G",
"1 3 1\nS#G\n...\n.#.",
"3 3 2\nS#.\n...\n/#G",
"4 3 2\nS..\n...\n..#\nG#.",
"3 3 2\nS#.\n...\n.$G",
"1 3 2\nS#G\n...\n.#.",
"5 3 2\nS#.\n...\n/#G",
"3 3 0\nS#.... | 6AIZU |
p01611 K-th String_3288 | K-th String
Problem Statement
The suffix array SA for the character string S of length N is defined as a permutation of positive integers of N or less obtained by the following procedure.
The substring from the i-th character to the j-th character of S is expressed as S [i..j]. However, the subscript is 1-indexed.
1... | #include <set>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int64;
const int MAX_N = int(1e5 + 10);
const int MAX_K = 30;
const int64 INF = int64(2.05e18); //^@ 2^63 ~ 9.2*10^18。本当にこれで大丈夫?
int N, K;
int64 L;
int sa[MAX_N + 1];
int64 comb[MAX_N + M... | 2C++ | {
"input": [
"3 4 2\n2\n1\n3",
"18 26 10275802967\n10\n14\n9\n13\n7\n8\n2\n6\n11\n18\n12\n1\n4\n3\n16\n5\n17\n15",
"0 4 2\n2\n1\n3",
"1 4 2\n1\n0\n3",
"1 1 -1\n1\n2\n2",
"18 26 10275802967\n10\n14\n9\n13\n7\n8\n2\n3\n11\n18\n12\n1\n4\n3\n16\n5\n17\n15",
"0 4 2\n0\n1\n3",
"18 26 1027580... | 6AIZU |
p01771 Tree_3289 | Problem statement
There is a rooted tree of size N. Each vertex is numbered from 0 to N-1, with a root of 0. For the vertices at both ends of any side, the assigned integer is smaller closer to the root. Initially, the weights of all edges are 0.
Process Q queries on this tree in sequence. There are two types of quer... | #include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define int long long
struct LCA {
int N, logN;
vector<vector<int>> G;
vector<int> depth;
vector<vector<int>> parent;
LCA(int size) : N(size), G(size), d... | 2C++ | {
"input": [
"9 6\n0 1\n0 2\n0 3\n1 4\n1 5\n4 6\n5 7\n5 8\n1 0 1\n1 1 2\n0 6 3\n1 5 5\n1 8 4\n0 4 3",
"9 6\n0 1\n0 2\n0 3\n1 4\n1 5\n4 6\n5 7\n5 8\n1 0 1\n1 1 2\n0 6 3\n1 5 2\n1 8 4\n0 4 3",
"9 6\n0 1\n0 2\n0 3\n0 4\n1 5\n4 6\n5 7\n5 8\n1 0 1\n1 1 2\n0 6 3\n1 5 5\n1 8 4\n0 4 3",
"9 6\n0 1\n0 2\n0 3\n1... | 6AIZU |
p01905 Tournament_3290 | problem
AOR Ika and you came to the tournament-style table tennis tournament singles section for reconnaissance. For AOR Ika-chan, who wants to record all the games, you decide to ask for the number of games that will be played in this tournament.
There are $ N $ players in the tournament, each with a uniform number ... | n, m = map(int, raw_input().split())
print n - m - 1 | 1Python2 | {
"input": [
"2 0",
"2 1",
"2 2",
"2 4",
"0 4",
"-1 4",
"-1 0",
"1 -1",
"-1 2",
"-1 -4",
"-2 -7",
"-1 -7",
"-1 -5",
"1 -6",
"2 -6",
"2 -8",
"5 -10",
"5 -8",
"9 -8",
"9 -14",
"9 -25",
"9 -20",
"18 -20",
"18 -36",
"18 -3... | 6AIZU |
p01905 Tournament_3291 | problem
AOR Ika and you came to the tournament-style table tennis tournament singles section for reconnaissance. For AOR Ika-chan, who wants to record all the games, you decide to ask for the number of games that will be played in this tournament.
There are $ N $ players in the tournament, each with a uniform number ... | #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;
bool a[1<<10];
int main(){
int n,m,ai;
cin>>n>>m;
rep(i,m){
cin>>ai;
a[n+ai]=true;
}
int ... | 2C++ | {
"input": [
"2 0",
"2 1",
"2 2",
"2 4",
"0 4",
"-1 4",
"-1 0",
"1 -1",
"-1 2",
"-1 -4",
"-2 -7",
"-1 -7",
"-1 -5",
"1 -6",
"2 -6",
"2 -8",
"5 -10",
"5 -8",
"9 -8",
"9 -14",
"9 -25",
"9 -20",
"18 -20",
"18 -36",
"18 -3... | 6AIZU |
p01905 Tournament_3292 | problem
AOR Ika and you came to the tournament-style table tennis tournament singles section for reconnaissance. For AOR Ika-chan, who wants to record all the games, you decide to ask for the number of games that will be played in this tournament.
There are $ N $ players in the tournament, each with a uniform number ... | N,M = map(int, input().split())
l = []
for i in range(M):
l.append(int(input()))
count = N - 1 - M
print(count)
| 3Python3 | {
"input": [
"2 0",
"2 1",
"2 2",
"2 4",
"0 4",
"-1 4",
"-1 0",
"1 -1",
"-1 2",
"-1 -4",
"-2 -7",
"-1 -7",
"-1 -5",
"1 -6",
"2 -6",
"2 -8",
"5 -10",
"5 -8",
"9 -8",
"9 -14",
"9 -25",
"9 -20",
"18 -20",
"18 -36",
"18 -3... | 6AIZU |
p01905 Tournament_3293 | problem
AOR Ika and you came to the tournament-style table tennis tournament singles section for reconnaissance. For AOR Ika-chan, who wants to record all the games, you decide to ask for the number of games that will be played in this tournament.
There are $ N $ players in the tournament, each with a uniform number ... | import java.io.*;
import java.util.*;
public class Main {
void solve() throws IOException {
int n = ni(), m = ni();
int[] a = nia(m);
out.println(n - m - 1);
}
String ns() throws IOException {
while (!tok.hasMoreTokens()) {
tok = new StringTokenizer(in.readLin... | 4JAVA | {
"input": [
"2 0",
"2 1",
"2 2",
"2 4",
"0 4",
"-1 4",
"-1 0",
"1 -1",
"-1 2",
"-1 -4",
"-2 -7",
"-1 -7",
"-1 -5",
"1 -6",
"2 -6",
"2 -8",
"5 -10",
"5 -8",
"9 -8",
"9 -14",
"9 -25",
"9 -20",
"18 -20",
"18 -36",
"18 -3... | 6AIZU |
p02043 Illumination_3294 | problem
There is a light bulb at the grid point $ (x, y) $ that meets $ 1 \ leq x \ leq h, 1 \ leq y \ leq w $.
The power supply is installed at coordinates $ (i + 0.5, j + 0.5) (1 \ leq i <h, 1 \ leq j <w, i + j $ is even) (corrected at 14:21). Coordinates $ When the power supply installed at (i + 0.5, j + 0.5) $ is... | #include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
struct Dinic{
const Int INF=1LL<<55;
struct edge {
Int to,cap,rev;
edge(){}
... | 2C++ | {
"input": [
"4 4 10\n100 100 100 100\n100 100 100 100\n1 100 100 1\n1 1 1 1",
"4 4 10\n100 100 100 100\n100 100 100 100\n1 100 100 2\n1 1 1 1",
"4 4 10\n100 000 100 100\n100 100 100 100\n1 100 100 2\n1 1 1 1",
"4 4 10\n100 000 000 100\n100 100 100 100\n1 100 100 2\n1 1 1 1",
"4 4 10\n100 000 000 ... | 6AIZU |
p02186 Cutting Subarray_3295 | E: Cut out the sum
problem
Ebi-chan has a sequence (a_1, a_2, ..., a_n). Ebi-chan is worried about the maximum value of the sum of the partial arrays (which may be empty), so please find it. Here, a subarray refers to a continuous subsequence. The sum of empty strings is 0.
In addition, Ebi-chan rewrites this sequen... | #include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;
template<typename T,typename U>istream & operator >> (istr... | 2C++ | {
"input": [
"5 2\n1 2 -3 4 -5\n3 3\n2 -6",
"5 2\n0 2 -3 4 -5\n3 3\n2 -6",
"7 2\n1 2 -3 4 -5\n3 3\n2 -6",
"5 2\n0 2 -3 4 -5\n4 3\n2 -6",
"5 2\n1 2 -6 4 -5\n3 3\n2 -6",
"5 0\n0 2 -4 4 -2\n4 3\n2 -6",
"5 2\n-1 2 -4 1 -2\n4 3\n2 -11",
"5 2\n1 2 -6 2 -7\n3 3\n2 -6",
"5 2\n0 2 -4 4 -4\n... | 6AIZU |
p02328 Largest Rectangle in a Histogram_3296 | A histogram is made of a number of contiguous bars, which have same width.
For a given histogram with $N$ bars which have a width of 1 and a height of $h_i$ = $h_1, h_2, ... , h_N$ respectively, find the area of the largest rectangular area.
Constraints
* $1 \leq N \leq 10^5$
* $0 \leq h_i \leq 10^9$
Input
The inp... | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<c... | 2C++ | {
"input": [
"8\n2 1 3 5 3 4 2 1",
"3\n2 0 1",
"8\n2 1 3 5 3 7 2 1",
"3\n3 0 1",
"8\n2 1 3 5 3 7 3 1",
"3\n5 0 0",
"3\n0 0 0",
"8\n2 2 3 5 4 7 3 2",
"3\n0 0 1",
"8\n3 6 3 6 4 7 0 4",
"8\n3 6 4 6 4 7 0 4",
"3\n2 0 2",
"8\n2 1 3 2 4 7 3 1",
"8\n2 2 2 5 4 7 3 1",
... | 6AIZU |
p02328 Largest Rectangle in a Histogram_3297 | A histogram is made of a number of contiguous bars, which have same width.
For a given histogram with $N$ bars which have a width of 1 and a height of $h_i$ = $h_1, h_2, ... , h_N$ respectively, find the area of the largest rectangular area.
Constraints
* $1 \leq N \leq 10^5$
* $0 \leq h_i \leq 10^9$
Input
The inp... |
"""
Writer:SPD_9X2
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_3_C&lang=ja
ヒストグラム上の最大長方形
またdpかな…?
参考:
http://algorithms.blog55.fc2.com/blog-entry-132.html
"""
#最後に要素0を追加してくこと
def Largest_rectangle_in_histgram(lis):
stk = []
ans = 0
N = len(lis)
for i in range(N):
if len(st... | 3Python3 | {
"input": [
"8\n2 1 3 5 3 4 2 1",
"3\n2 0 1",
"8\n2 1 3 5 3 7 2 1",
"3\n3 0 1",
"8\n2 1 3 5 3 7 3 1",
"3\n5 0 0",
"3\n0 0 0",
"8\n2 2 3 5 4 7 3 2",
"3\n0 0 1",
"8\n3 6 3 6 4 7 0 4",
"8\n3 6 4 6 4 7 0 4",
"3\n2 0 2",
"8\n2 1 3 2 4 7 3 1",
"8\n2 2 2 5 4 7 3 1",
... | 6AIZU |
p02328 Largest Rectangle in a Histogram_3298 | A histogram is made of a number of contiguous bars, which have same width.
For a given histogram with $N$ bars which have a width of 1 and a height of $h_i$ = $h_1, h_2, ... , h_N$ respectively, find the area of the largest rectangular area.
Constraints
* $1 \leq N \leq 10^5$
* $0 \leq h_i \leq 10^9$
Input
The inp... | import java.io.*;
import java.util.Arrays;
import java.util.StringJoiner;
import java.util.StringTokenizer;
import java.util.function.Function;
public class Main {
static int N;
static int[] H;
public static void main(String[] args) {
FastScanner sc = new FastScanner(System.in);
N = sc.ne... | 4JAVA | {
"input": [
"8\n2 1 3 5 3 4 2 1",
"3\n2 0 1",
"8\n2 1 3 5 3 7 2 1",
"3\n3 0 1",
"8\n2 1 3 5 3 7 3 1",
"3\n5 0 0",
"3\n0 0 0",
"8\n2 2 3 5 4 7 3 2",
"3\n0 0 1",
"8\n3 6 3 6 4 7 0 4",
"8\n3 6 4 6 4 7 0 4",
"3\n2 0 2",
"8\n2 1 3 2 4 7 3 1",
"8\n2 2 2 5 4 7 3 1",
... | 6AIZU |
p02473 Difference of Big Integers_3299 | Difference of Big Integers
Given two integers $A$ and $B$, compute the difference, $A - B$.
Input
Two integers $A$ and $B$ separated by a space character are given in a line.
Output
Print the difference in a line.
Constraints
* $-1 \times 10^{100000} \leq A, B \leq 10^{100000}$
Sample Input 1
5 8
Sample O... | import sys
a,b=map(int,sys.stdin.readline().split())
print(a-b)
| 1Python2 | {
"input": [
"5 8",
"5 4",
"5 5",
"5 1",
"4 1",
"2 0",
"8 0",
"15 0",
"15 1",
"8 1",
"0 1",
"0 2",
"0 3",
"-1 3",
"-1 4",
"-1 7",
"-1 8",
"0 16",
"0 31",
"0 45",
"-1 45",
"0 69",
"0 55",
"0 10",
"2 16",
"-2 4",
... | 6AIZU |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.