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 |
|---|---|---|---|---|---|
p03003 AtCoder Beginner Contest 130 - Common Subsequence_1700 | You are given two integer sequences S and T of length N and M, respectively, both consisting of integers between 1 and 10^5 (inclusive).
In how many pairs of a subsequence of S and a subsequence of T do the two subsequences are the same in content?
Here the subsequence of A is a sequence obtained by removing zero or ... | def main():
e=enumerate
n,m,*u=map(int,open(0).read().split())
dp=[[1]*(m+1)for _ in range(n+1)]
dpi=dp[0]
for i,s in e(u[:n]):
dpi1=dp[i+1]
for j,t in e(u[n:]):
dpi1[j+1]=(dpi[j+1]+dpi1[j]-dpi[j]*(s!=t))%(10**9+7)
dpi=dpi1
print(dpi[m])
main() | 3Python3 | {
"input": [
"10 9\n9 6 5 7 5 9 8 5 6 7\n8 6 8 5 5 7 9 9 7",
"20 20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"4 4\n3 4 5 6\n3 4 5 6",
"2 2\n1 1\n1 1",
"2 2\n1 3\n3 1",
"10 9\n9 6 5 7 5 9 8 5 6 7\n8 5 8 5 5 7 9 9 7",
"20 20\n1 1 1 1 1 1 1 0 1 1 1 1... | 5ATCODER |
p03003 AtCoder Beginner Contest 130 - Common Subsequence_1701 | You are given two integer sequences S and T of length N and M, respectively, both consisting of integers between 1 and 10^5 (inclusive).
In how many pairs of a subsequence of S and a subsequence of T do the two subsequences are the same in content?
Here the subsequence of A is a sequence obtained by removing zero or ... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author silviase
*/
public class Main {
public static void main(String[] args) {
InputStream ... | 4JAVA | {
"input": [
"10 9\n9 6 5 7 5 9 8 5 6 7\n8 6 8 5 5 7 9 9 7",
"20 20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1",
"4 4\n3 4 5 6\n3 4 5 6",
"2 2\n1 1\n1 1",
"2 2\n1 3\n3 1",
"10 9\n9 6 5 7 5 9 8 5 6 7\n8 5 8 5 5 7 9 9 7",
"20 20\n1 1 1 1 1 1 1 0 1 1 1 1... | 5ATCODER |
p03143 NIKKEI Programming Contest 2019 - Weights on Vertices and Edges_1702 | There is a connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the edges are numbered 1 to M. Also, each of these vertices and edges has a specified weight. Vertex i has a weight of X_i; Edge i has a weight of Y_i and connects Vertex A_i and B_i.
We would like to remove zero o... | from sys import stdin
from itertools import repeat
def main():
n, m = map(int, stdin.readline().split())
w = map(int, stdin.readline().split())
dat = map(int, stdin.read().split(), repeat(10, 3 * m))
e = [(dat[i*3+2], dat[i*3] - 1, dat[i*3+1] - 1) for i in xrange(m)]
e.sort()
p = range(n)
ok... | 1Python2 | {
"input": [
"10 9\n81 16 73 7 2 61 86 38 90 28\n6 8 725\n3 10 12\n1 4 558\n4 9 615\n5 6 942\n8 9 918\n2 7 720\n4 7 292\n7 10 414",
"4 4\n2 3 5 7\n1 2 7\n1 3 9\n2 3 12\n3 4 18",
"6 10\n4 4 1 1 1 7\n3 5 19\n2 5 20\n4 5 8\n1 6 16\n2 3 9\n3 6 16\n3 4 1\n2 6 20\n2 4 19\n1 2 9",
"4 4\n2 3 5 7\n1 2 7\n1 3 9... | 5ATCODER |
p03143 NIKKEI Programming Contest 2019 - Weights on Vertices and Edges_1703 | There is a connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the edges are numbered 1 to M. Also, each of these vertices and edges has a specified weight. Vertex i has a weight of X_i; Edge i has a weight of Y_i and connects Vertex A_i and B_i.
We would like to remove zero o... | #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
const int N=100010;
bool w[N];
int fa[N],pa[N];
vector <int> q[N];
long long a[N],b[N];
inline int gi() {
int x=0,o=1;
char ch=getchar();
while(ch<'0'||ch>'9') ch=='-'?o=-1:... | 2C++ | {
"input": [
"10 9\n81 16 73 7 2 61 86 38 90 28\n6 8 725\n3 10 12\n1 4 558\n4 9 615\n5 6 942\n8 9 918\n2 7 720\n4 7 292\n7 10 414",
"4 4\n2 3 5 7\n1 2 7\n1 3 9\n2 3 12\n3 4 18",
"6 10\n4 4 1 1 1 7\n3 5 19\n2 5 20\n4 5 8\n1 6 16\n2 3 9\n3 6 16\n3 4 1\n2 6 20\n2 4 19\n1 2 9",
"4 4\n2 3 5 7\n1 2 7\n1 3 9... | 5ATCODER |
p03143 NIKKEI Programming Contest 2019 - Weights on Vertices and Edges_1704 | There is a connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the edges are numbered 1 to M. Also, each of these vertices and edges has a specified weight. Vertex i has a weight of X_i; Edge i has a weight of Y_i and connects Vertex A_i and B_i.
We would like to remove zero o... | import sys
from collections import deque
input = sys.stdin.readline
N,M=map(int,input().split())
X=list(map(int,input().split()))
EDGE=[list(map(int,input().split())) for i in range(M)]
EDGE.sort(key=lambda x:x[2])
EDGELIST=[[] for i in range(N+1)]
for i in range(M):
x,y,w=EDGE[i]
EDGELIST[x].append(i)
ED... | 3Python3 | {
"input": [
"10 9\n81 16 73 7 2 61 86 38 90 28\n6 8 725\n3 10 12\n1 4 558\n4 9 615\n5 6 942\n8 9 918\n2 7 720\n4 7 292\n7 10 414",
"4 4\n2 3 5 7\n1 2 7\n1 3 9\n2 3 12\n3 4 18",
"6 10\n4 4 1 1 1 7\n3 5 19\n2 5 20\n4 5 8\n1 6 16\n2 3 9\n3 6 16\n3 4 1\n2 6 20\n2 4 19\n1 2 9",
"4 4\n2 3 5 7\n1 2 7\n1 3 9... | 5ATCODER |
p03143 NIKKEI Programming Contest 2019 - Weights on Vertices and Edges_1705 | There is a connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the edges are numbered 1 to M. Also, each of these vertices and edges has a specified weight. Vertex i has a weight of X_i; Edge i has a weight of Y_i and connects Vertex A_i and B_i.
We would like to remove zero o... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream... | 4JAVA | {
"input": [
"10 9\n81 16 73 7 2 61 86 38 90 28\n6 8 725\n3 10 12\n1 4 558\n4 9 615\n5 6 942\n8 9 918\n2 7 720\n4 7 292\n7 10 414",
"4 4\n2 3 5 7\n1 2 7\n1 3 9\n2 3 12\n3 4 18",
"6 10\n4 4 1 1 1 7\n3 5 19\n2 5 20\n4 5 8\n1 6 16\n2 3 9\n3 6 16\n3 4 1\n2 6 20\n2 4 19\n1 2 9",
"4 4\n2 3 5 7\n1 2 7\n1 3 9... | 5ATCODER |
p03287 AtCoder Beginner Contest 105 - Candy Distribution_1706 | There are N boxes arranged in a row from left to right. The i-th box from the left contains A_i candies.
You will take out the candies from some consecutive boxes and distribute them evenly to M children.
Such being the case, find the number of the pairs (l, r) that satisfy the following:
* l and r are both integers... | #!/usr/bin/env python
from collections import deque
import itertools as it
import sys
import math
sys.setrecursionlimit(10000000)
n, m = map(int, raw_input().split())
A = map(int, raw_input().split())
dic = {}
dic[0] = 1
S = 0
for num in A:
S += num
S %= m
if S in dic:
dic[S] += 1
else:
... | 1Python2 | {
"input": [
"10 400000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"13 17\n29 7 5 7 9 51 7 13 8 55 42 9 81",
"3 2\n4 1 5",
"10 400000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000010 100... | 5ATCODER |
p03287 AtCoder Beginner Contest 105 - Candy Distribution_1707 | There are N boxes arranged in a row from left to right. The i-th box from the left contains A_i candies.
You will take out the candies from some consecutive boxes and distribute them evenly to M children.
Such being the case, find the number of the pairs (l, r) that satisfy the following:
* l and r are both integers... | #include <iostream>
#include <map>
using namespace std;
int main()
{
uint64_t n, m;
cin >> n >> m;
map<uint64_t, uint64_t> mp;
mp[0] = 1;
uint64_t accumulate = 0;
uint64_t ans = 0;
for (auto i = 0; i < n; i++) {
uint64_t v;
cin >> v;
accumulate += v;
ans += mp[accumulate % m]++;
}
co... | 2C++ | {
"input": [
"10 400000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"13 17\n29 7 5 7 9 51 7 13 8 55 42 9 81",
"3 2\n4 1 5",
"10 400000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000010 100... | 5ATCODER |
p03287 AtCoder Beginner Contest 105 - Candy Distribution_1708 | There are N boxes arranged in a row from left to right. The i-th box from the left contains A_i candies.
You will take out the candies from some consecutive boxes and distribute them evenly to M children.
Such being the case, find the number of the pairs (l, r) that satisfy the following:
* l and r are both integers... | n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
d={0:1}
s=0
for i in a:
s=(s+i)%m
if s in d:
d[s]+=1
else:
d[s]=1
def f(x):
return int(x*(x-1)/2)
s=0
for i in d:
s+=f(d[i])
print(s) | 3Python3 | {
"input": [
"10 400000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"13 17\n29 7 5 7 9 51 7 13 8 55 42 9 81",
"3 2\n4 1 5",
"10 400000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000010 100... | 5ATCODER |
p03287 AtCoder Beginner Contest 105 - Candy Distribution_1709 | There are N boxes arranged in a row from left to right. The i-th box from the left contains A_i candies.
You will take out the candies from some consecutive boxes and distribute them evenly to M children.
Such being the case, find the number of the pairs (l, r) that satisfy the following:
* l and r are both integers... | import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.NoSuchElementException;
public class Main {
public static void main(String[] args){
FastScanner sc = new FastScanner();
PrintWriter ... | 4JAVA | {
"input": [
"10 400000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000",
"13 17\n29 7 5 7 9 51 7 13 8 55 42 9 81",
"3 2\n4 1 5",
"10 400000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000010 100... | 5ATCODER |
p03443 AtCoder Petrozavodsk Contest 001 - Colorful Doors_1710 | There is a bridge that connects the left and right banks of a river. There are 2 N doors placed at different positions on this bridge, painted in some colors. The colors of the doors are represented by integers from 1 through N. For each k (1 \leq k \leq N), there are exactly two doors painted in Color k.
Snuke decide... | #include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define int ll
#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DMP(x) cerr<<"line "<<__LI... | 2C++ | {
"input": [
"2\n010",
"2\n001",
"3\n10101",
"6\n00111011100",
"3\n10110",
"2\n110",
"2\n000",
"2\n111",
"3\n00100",
"3\n01000",
"3\n00000",
"3\n11110",
"3\n01111",
"3\n11011",
"6\n10101011010",
"6\n10111011010",
"3\n01010",
"3\n10111",
"3\n1... | 5ATCODER |
p03443 AtCoder Petrozavodsk Contest 001 - Colorful Doors_1711 | There is a bridge that connects the left and right banks of a river. There are 2 N doors placed at different positions on this bridge, painted in some colors. The colors of the doors are represented by integers from 1 through N. For each k (1 \leq k \leq N), there are exactly two doors painted in Color k.
Snuke decide... | import java.io.*;
import java.util.*;
public class Main {
int[] solve(String s) {
int z = s.indexOf('0');
int n = s.length() / 2;
int[] ans = new int[2 * n];
Arrays.fill(ans, -1);
if (z == -1) {
if (n % 2 == 0) {
for (int i = 0; i < n; i += 2) {
ans[2 * i] = ans[2 * i + 2] = i;
ans[2 * i +... | 4JAVA | {
"input": [
"2\n010",
"2\n001",
"3\n10101",
"6\n00111011100",
"3\n10110",
"2\n110",
"2\n000",
"2\n111",
"3\n00100",
"3\n01000",
"3\n00000",
"3\n11110",
"3\n01111",
"3\n11011",
"6\n10101011010",
"6\n10111011010",
"3\n01010",
"3\n10111",
"3\n1... | 5ATCODER |
p03603 AtCoder Regular Contest 083 - Bichrome Tree_1712 | We have a tree with N vertices. Vertex 1 is the root of the tree, and the parent of Vertex i (2 \leq i \leq N) is Vertex P_i.
To each vertex in the tree, Snuke will allocate a color, either black or white, and a non-negative integer weight.
Snuke has a favorite integer sequence, X_1, X_2, ..., X_N, so he wants to all... | #include<iostream>
#include<cstdio>
#include<cstring>
const int N=1002;
inline void apn(int &a,int b){
if(a>b)a=b;
}
inline char get_c(){
static char buf[20000],*h,*t;
if(h==t){
t=(h=buf)+fread(buf,1,20000,stdin);
}
return h==t?EOF:*h++;
}
inline int nxi(){
int x=0;
char c;
while((c=get_c())>'9'||c<'0');
... | 2C++ | {
"input": [
"3\n1 1\n4 3 2",
"8\n1 1 1 3 4 5 5\n4 1 6 2 2 1 3 3",
"1\n\n0",
"3\n1 2\n1 2 3",
"3\n1 1\n6 3 2",
"8\n1 2 2 3 4 5 5\n4 1 6 2 2 1 3 3",
"8\n1 1 1 3 4 5 5\n6 1 6 2 2 1 3 3",
"1\n\n1",
"3\n1 1\n6 6 2",
"1\n\n2",
"3\n1 1\n3 6 2",
"1\n\n3",
"3\n1 1\n3 6 4",
... | 5ATCODER |
p03603 AtCoder Regular Contest 083 - Bichrome Tree_1713 | We have a tree with N vertices. Vertex 1 is the root of the tree, and the parent of Vertex i (2 \leq i \leq N) is Vertex P_i.
To each vertex in the tree, Snuke will allocate a color, either black or white, and a non-negative integer weight.
Snuke has a favorite integer sequence, X_1, X_2, ..., X_N, so he wants to all... | n = int(input())
parents = list(map(int, input().split()))
weights = list(map(int, input().split()))
children = [[] for _ in range(n)]
for i in range(n-1):
children[parents[i]-1].append(i+1)
def dfs(cur):
if children[cur] == []:
return (weights[cur], 0)
sum = 0
dp = [[False] * (weights[cur] ... | 3Python3 | {
"input": [
"3\n1 1\n4 3 2",
"8\n1 1 1 3 4 5 5\n4 1 6 2 2 1 3 3",
"1\n\n0",
"3\n1 2\n1 2 3",
"3\n1 1\n6 3 2",
"8\n1 2 2 3 4 5 5\n4 1 6 2 2 1 3 3",
"8\n1 1 1 3 4 5 5\n6 1 6 2 2 1 3 3",
"1\n\n1",
"3\n1 1\n6 6 2",
"1\n\n2",
"3\n1 1\n3 6 2",
"1\n\n3",
"3\n1 1\n3 6 4",
... | 5ATCODER |
p03603 AtCoder Regular Contest 083 - Bichrome Tree_1714 | We have a tree with N vertices. Vertex 1 is the root of the tree, and the parent of Vertex i (2 \leq i \leq N) is Vertex P_i.
To each vertex in the tree, Snuke will allocate a color, either black or white, and a non-negative integer weight.
Snuke has a favorite integer sequence, X_1, X_2, ..., X_N, so he wants to all... | import java.io.*;
import java.util.*;
public class Main implements Runnable {
static ContestScanner in;
static Writer out;
public static void main(String[] args) {
new Thread(null, new Main(), "", 16 * 1024 * 1024).start();
}
public void run() {
Main main = new Main();
try ... | 4JAVA | {
"input": [
"3\n1 1\n4 3 2",
"8\n1 1 1 3 4 5 5\n4 1 6 2 2 1 3 3",
"1\n\n0",
"3\n1 2\n1 2 3",
"3\n1 1\n6 3 2",
"8\n1 2 2 3 4 5 5\n4 1 6 2 2 1 3 3",
"8\n1 1 1 3 4 5 5\n6 1 6 2 2 1 3 3",
"1\n\n1",
"3\n1 1\n6 6 2",
"1\n\n2",
"3\n1 1\n3 6 2",
"1\n\n3",
"3\n1 1\n3 6 4",
... | 5ATCODER |
p03762 AtCoder Beginner Contest 058 - ###_1715 | On a two-dimensional plane, there are m lines drawn parallel to the x axis, and n lines drawn parallel to the y axis. Among the lines parallel to the x axis, the i-th from the bottom is represented by y = y_i. Similarly, among the lines parallel to the y axis, the i-th from the left is represented by x = x_i.
For ever... | n,m=map(int, raw_input().split())
x=map(int, raw_input().split())
y=map(int, raw_input().split())
x1=[]
x_sum=0
for i in range(n):
x_sum+=( (n-i-1)-i )*x[i]
y_sum=0
for i in range(m):
y_sum+=( (m-i-1)-i )*y[i]
print x_sum*y_sum%(10**9+7) | 1Python2 | {
"input": [
"3 3\n1 3 4\n1 3 6",
"6 5\n-790013317 -192321079 95834122 418379342 586260100 802780784\n-253230108 193944314 363756450 712662868 735867677",
"6 5\n-983443749 -192321079 95834122 418379342 586260100 802780784\n-253230108 193944314 363756450 712662868 735867677",
"6 5\n-983443749 -19232107... | 5ATCODER |
p03762 AtCoder Beginner Contest 058 - ###_1716 | On a two-dimensional plane, there are m lines drawn parallel to the x axis, and n lines drawn parallel to the y axis. Among the lines parallel to the x axis, the i-th from the bottom is represented by y = y_i. Similarly, among the lines parallel to the y axis, the i-th from the left is represented by x = x_i.
For ever... | #include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979
using namespace std;
int main(void){
ll n, m;
cin >> n >> m;
ll x, y, xs = 0, ys = 0;
for (int i = 0; i < n; i++){
cin >> x;
xs = (xs + (1 - n + 2*i)*x) % MOD;
}
for (int i = 0;... | 2C++ | {
"input": [
"3 3\n1 3 4\n1 3 6",
"6 5\n-790013317 -192321079 95834122 418379342 586260100 802780784\n-253230108 193944314 363756450 712662868 735867677",
"6 5\n-983443749 -192321079 95834122 418379342 586260100 802780784\n-253230108 193944314 363756450 712662868 735867677",
"6 5\n-983443749 -19232107... | 5ATCODER |
p03762 AtCoder Beginner Contest 058 - ###_1717 | On a two-dimensional plane, there are m lines drawn parallel to the x axis, and n lines drawn parallel to the y axis. Among the lines parallel to the x axis, the i-th from the bottom is represented by y = y_i. Similarly, among the lines parallel to the y axis, the i-th from the left is represented by x = x_i.
For ever... | N,M=map(int,input().split())
X=list(map(int,input().split()))
Y=list(map(int,input().split()))
mod=10**9+7
x=0
for i in range(N):
x+=((i-(N-i-1))*X[i])%mod
x%=mod
y=0
for j in range(M):
y+=((j-(M-j-1))*Y[j])%mod
y%=mod
print((x*y)%mod) | 3Python3 | {
"input": [
"3 3\n1 3 4\n1 3 6",
"6 5\n-790013317 -192321079 95834122 418379342 586260100 802780784\n-253230108 193944314 363756450 712662868 735867677",
"6 5\n-983443749 -192321079 95834122 418379342 586260100 802780784\n-253230108 193944314 363756450 712662868 735867677",
"6 5\n-983443749 -19232107... | 5ATCODER |
p03762 AtCoder Beginner Contest 058 - ###_1718 | On a two-dimensional plane, there are m lines drawn parallel to the x axis, and n lines drawn parallel to the y axis. Among the lines parallel to the x axis, the i-th from the bottom is represented by y = y_i. Similarly, among the lines parallel to the y axis, the i-th from the left is represented by x = x_i.
For ever... |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Main main = new Main();
main.run();
}
long MOD = 1000000007;
public void run() {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int m = sc.nextInt();
int x[] = new int[n];
for(int i=0; i<n; i++) {... | 4JAVA | {
"input": [
"3 3\n1 3 4\n1 3 6",
"6 5\n-790013317 -192321079 95834122 418379342 586260100 802780784\n-253230108 193944314 363756450 712662868 735867677",
"6 5\n-983443749 -192321079 95834122 418379342 586260100 802780784\n-253230108 193944314 363756450 712662868 735867677",
"6 5\n-983443749 -19232107... | 5ATCODER |
p03932 square869120Contest #3 - Souvenirs_1719 | Input
The input is given from standard input in the following format.
> $H \ W$ $a_{1, 1} \ a_{1, 2} \ \cdots \ a_{1, W}$ $a_{2, 1} \ a_{2, 2} \ \cdots \ a_{2, W}$ $\vdots \ \ \ \ \ \ \ \ \ \ \vdots \ \ \ \ \ \ \ \ \ \ \vdots$ $a_{H, 1} \ a_{H, 2} \ \cdots \ a_{H, W}$
Output
* Print the maximum number of souvenirs... | h,w=map(int,raw_input().split())
a=[map(int,raw_input().split()) for _ in xrange(h)]
dp=[[[0]*(h+1) for _ in xrange(w+1)] for _ in xrange(h+1)]
for i in xrange(h):
for j in xrange(w):
for k in xrange(h):
if i+j-k<=-1 or i+j-k>=w:
continue
if i==k:
dp[... | 1Python2 | {
"input": [
"6 6\n1 2 3 4 5 6\n8 6 9 1 2 0\n3 1 4 1 5 9\n2 6 5 3 5 8\n1 4 1 4 2 1\n2 7 1 8 2 8",
"3 3\n1 0 5\n2 2 3\n4 2 4",
"6 6\n1 2 3 4 5 6\n8 6 9 1 2 0\n3 1 4 1 5 9\n2 6 5 3 5 8\n1 4 1 4 2 1\n2 10 1 8 2 8",
"3 3\n1 0 5\n1 2 3\n4 2 4",
"6 6\n1 2 3 4 5 6\n8 6 9 1 2 0\n1 1 4 1 5 9\n2 6 5 3 5 8\n... | 5ATCODER |
p03932 square869120Contest #3 - Souvenirs_1720 | Input
The input is given from standard input in the following format.
> $H \ W$ $a_{1, 1} \ a_{1, 2} \ \cdots \ a_{1, W}$ $a_{2, 1} \ a_{2, 2} \ \cdots \ a_{2, W}$ $\vdots \ \ \ \ \ \ \ \ \ \ \vdots \ \ \ \ \ \ \ \ \ \ \vdots$ $a_{H, 1} \ a_{H, 2} \ \cdots \ a_{H, W}$
Output
* Print the maximum number of souvenirs... | #include <bits/stdc++.h>
typedef long long int ll;
#define FOR(i, a, b) for (ll i = (signed)(a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define MOD 1000000007
#define pb push_back
#define INF 93193111451418101
#define MIN -93193111451418101
#define EPS 1e-11
#de... | 2C++ | {
"input": [
"6 6\n1 2 3 4 5 6\n8 6 9 1 2 0\n3 1 4 1 5 9\n2 6 5 3 5 8\n1 4 1 4 2 1\n2 7 1 8 2 8",
"3 3\n1 0 5\n2 2 3\n4 2 4",
"6 6\n1 2 3 4 5 6\n8 6 9 1 2 0\n3 1 4 1 5 9\n2 6 5 3 5 8\n1 4 1 4 2 1\n2 10 1 8 2 8",
"3 3\n1 0 5\n1 2 3\n4 2 4",
"6 6\n1 2 3 4 5 6\n8 6 9 1 2 0\n1 1 4 1 5 9\n2 6 5 3 5 8\n... | 5ATCODER |
p03932 square869120Contest #3 - Souvenirs_1721 | Input
The input is given from standard input in the following format.
> $H \ W$ $a_{1, 1} \ a_{1, 2} \ \cdots \ a_{1, W}$ $a_{2, 1} \ a_{2, 2} \ \cdots \ a_{2, W}$ $\vdots \ \ \ \ \ \ \ \ \ \ \vdots \ \ \ \ \ \ \ \ \ \ \vdots$ $a_{H, 1} \ a_{H, 2} \ \cdots \ a_{H, W}$
Output
* Print the maximum number of souvenirs... | H,W = map(int,input().split())
src = [list(map(int,input().split())) for i in range(H)]
dp = [[[0 for ex in range(W)] for sx in range(W)] for xy in range(H+W-1)]
dp[0][0][0] = src[0][0]
for xy in range(H+W-2):
n = min(xy+1,H,W,H+W-xy-1)
sx0 = max(0,xy-H+1)
for sx in range(sx0, sx0+n):
for ex in ran... | 3Python3 | {
"input": [
"6 6\n1 2 3 4 5 6\n8 6 9 1 2 0\n3 1 4 1 5 9\n2 6 5 3 5 8\n1 4 1 4 2 1\n2 7 1 8 2 8",
"3 3\n1 0 5\n2 2 3\n4 2 4",
"6 6\n1 2 3 4 5 6\n8 6 9 1 2 0\n3 1 4 1 5 9\n2 6 5 3 5 8\n1 4 1 4 2 1\n2 10 1 8 2 8",
"3 3\n1 0 5\n1 2 3\n4 2 4",
"6 6\n1 2 3 4 5 6\n8 6 9 1 2 0\n1 1 4 1 5 9\n2 6 5 3 5 8\n... | 5ATCODER |
p03932 square869120Contest #3 - Souvenirs_1722 | Input
The input is given from standard input in the following format.
> $H \ W$ $a_{1, 1} \ a_{1, 2} \ \cdots \ a_{1, W}$ $a_{2, 1} \ a_{2, 2} \ \cdots \ a_{2, W}$ $\vdots \ \ \ \ \ \ \ \ \ \ \vdots \ \ \ \ \ \ \ \ \ \ \vdots$ $a_{H, 1} \ a_{H, 2} \ \cdots \ a_{H, W}$
Output
* Print the maximum number of souvenirs... | import java.util.Arrays;
import java.util.Scanner;
public class Main {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int H = sc.nextInt();
int W = sc.nextInt();
int[][] A = new int[400][400];
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
... | 4JAVA | {
"input": [
"6 6\n1 2 3 4 5 6\n8 6 9 1 2 0\n3 1 4 1 5 9\n2 6 5 3 5 8\n1 4 1 4 2 1\n2 7 1 8 2 8",
"3 3\n1 0 5\n2 2 3\n4 2 4",
"6 6\n1 2 3 4 5 6\n8 6 9 1 2 0\n3 1 4 1 5 9\n2 6 5 3 5 8\n1 4 1 4 2 1\n2 10 1 8 2 8",
"3 3\n1 0 5\n1 2 3\n4 2 4",
"6 6\n1 2 3 4 5 6\n8 6 9 1 2 0\n1 1 4 1 5 9\n2 6 5 3 5 8\n... | 5ATCODER |
p00025 Hit and Blow_1723 | Let's play Hit and Blow game. A imagines four numbers and B guesses the numbers. After B picks out four numbers, A answers:
* The number of numbers which have the same place with numbers A imagined (Hit)
* The number of numbers included (but different place) in the numbers A imagined (Blow)
For example, if A imagin... | ans = []
while True:
try:
a = map(int,raw_input().split())
except EOFError:
break
b = map(int,raw_input().split())
n = 0
m = 0
for i in range(4):
if a[i] == b[i]:
n += 1
for i in range(0,4):
for j in range(0,4):
if a[i] == b[j]:
... | 1Python2 | {
"input": [
"9 1 8 2\n4 1 5 9\n4 6 8 2\n4 6 3 2",
"9 1 8 2\n4 1 5 9\n4 6 8 2\n4 6 3 0",
"9 1 8 2\n6 1 5 9\n4 6 8 2\n2 6 3 0",
"9 1 8 2\n4 1 5 9\n2 6 8 2\n4 6 3 0",
"9 1 8 2\n6 2 5 9\n4 6 8 2\n4 6 3 0",
"9 1 8 2\n6 2 5 9\n4 6 8 2\n4 9 3 0",
"9 1 8 2\n6 1 2 9\n4 6 13 2\n2 6 3 1",
"9 1 8... | 6AIZU |
p00025 Hit and Blow_1724 | Let's play Hit and Blow game. A imagines four numbers and B guesses the numbers. After B picks out four numbers, A answers:
* The number of numbers which have the same place with numbers A imagined (Hit)
* The number of numbers included (but different place) in the numbers A imagined (Blow)
For example, if A imagin... | #include "bits/stdc++.h"
using namespace std;
int main() {
int a[4], b[4];
while (cin >> a[0] >> a[1] >> a[2] >> a[3] >> b[0] >> b[1] >> b[2] >> b[3]) {
int n1 = 0, n2 = 0;
for (int i = 0; i < 4;i++) {
if (a[i] == b[i])n1++;
}
for (int i = 0; i < 4;i++) {
for (int j = 0; j < 4;j++) {
if (i == j)cont... | 2C++ | {
"input": [
"9 1 8 2\n4 1 5 9\n4 6 8 2\n4 6 3 2",
"9 1 8 2\n4 1 5 9\n4 6 8 2\n4 6 3 0",
"9 1 8 2\n6 1 5 9\n4 6 8 2\n2 6 3 0",
"9 1 8 2\n4 1 5 9\n2 6 8 2\n4 6 3 0",
"9 1 8 2\n6 2 5 9\n4 6 8 2\n4 6 3 0",
"9 1 8 2\n6 2 5 9\n4 6 8 2\n4 9 3 0",
"9 1 8 2\n6 1 2 9\n4 6 13 2\n2 6 3 1",
"9 1 8... | 6AIZU |
p00025 Hit and Blow_1725 | Let's play Hit and Blow game. A imagines four numbers and B guesses the numbers. After B picks out four numbers, A answers:
* The number of numbers which have the same place with numbers A imagined (Hit)
* The number of numbers included (but different place) in the numbers A imagined (Blow)
For example, if A imagin... | import sys
e=iter(map(lambda a:a.split(),sys.stdin))
for a,b in zip(e,e):
h=sum([1 for i in range(4)if a[i]==b[i]])
w=4-len(set(a)-set(b))-h
print(h,w)
| 3Python3 | {
"input": [
"9 1 8 2\n4 1 5 9\n4 6 8 2\n4 6 3 2",
"9 1 8 2\n4 1 5 9\n4 6 8 2\n4 6 3 0",
"9 1 8 2\n6 1 5 9\n4 6 8 2\n2 6 3 0",
"9 1 8 2\n4 1 5 9\n2 6 8 2\n4 6 3 0",
"9 1 8 2\n6 2 5 9\n4 6 8 2\n4 6 3 0",
"9 1 8 2\n6 2 5 9\n4 6 8 2\n4 9 3 0",
"9 1 8 2\n6 1 2 9\n4 6 13 2\n2 6 3 1",
"9 1 8... | 6AIZU |
p00025 Hit and Blow_1726 | Let's play Hit and Blow game. A imagines four numbers and B guesses the numbers. After B picks out four numbers, A answers:
* The number of numbers which have the same place with numbers A imagined (Hit)
* The number of numbers included (but different place) in the numbers A imagined (Blow)
For example, if A imagin... | import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int a[]=new int[4];
int b[]=new int[4];
while(sc.hasNext()){
int hit=0,blow=0;
for(int i=0;i<4;i++)a[i]=sc.nextInt();
for(int i=0;i<4;i++)b[i]=sc.nextInt();
for(int i=0;i<4;i++){
i... | 4JAVA | {
"input": [
"9 1 8 2\n4 1 5 9\n4 6 8 2\n4 6 3 2",
"9 1 8 2\n4 1 5 9\n4 6 8 2\n4 6 3 0",
"9 1 8 2\n6 1 5 9\n4 6 8 2\n2 6 3 0",
"9 1 8 2\n4 1 5 9\n2 6 8 2\n4 6 3 0",
"9 1 8 2\n6 2 5 9\n4 6 8 2\n4 6 3 0",
"9 1 8 2\n6 2 5 9\n4 6 8 2\n4 9 3 0",
"9 1 8 2\n6 1 2 9\n4 6 13 2\n2 6 3 1",
"9 1 8... | 6AIZU |
p00156 Moats around the Castle_1727 | Now, a ninja is planning to sneak into the castle tower from outside the castle. This ninja can easily run on the ground and swim in the moat, but he is not very good at climbing up from the moat, so he wants to enter the moat as few times as possible.
Create a program that takes a sketch of the castle as input and ou... | def ReadMap(n, m):
Map = [0] * m
for i in range(m):
a = raw_input()
b = list(a)
if a.count('&')>0:
j = a.index('&')
PosCas = [j, i]
b[j] = '.'
Map[i] = b
return Map, PosCas
def fill(SP, c1, c2):
for x, y in SP:
if not (0 <= x < n and 0 <= y < m):
continue
if Map[... | 1Python2 | {
"input": [
"5 5\n.###.\n#...#\n#.&.#\n#...#\n.###.\n18 15\n..####....####....\n####..####....####\n#...............##\n.#.############.##\n#..#..........#.##\n.#.#.########.#.##\n#..#.#......#.#.##\n.#.#....&...#.#.##\n#..#........#.#.##\n.#.#.########.#.##\n#..#..........#.##\n.#.############.##\n#............... | 6AIZU |
p00156 Moats around the Castle_1728 | Now, a ninja is planning to sneak into the castle tower from outside the castle. This ninja can easily run on the ground and swim in the moat, but he is not very good at climbing up from the moat, so he wants to enter the moat as few times as possible.
Create a program that takes a sketch of the castle as input and ou... | #include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm> // require sort next_permutation count __gcd reverse etc.
#include <cstdlib> // require abs exit atof atoi
#include <cstdio> // require scanf printf
#include <f... | 2C++ | {
"input": [
"5 5\n.###.\n#...#\n#.&.#\n#...#\n.###.\n18 15\n..####....####....\n####..####....####\n#...............##\n.#.############.##\n#..#..........#.##\n.#.#.########.#.##\n#..#.#......#.#.##\n.#.#....&...#.#.##\n#..#........#.#.##\n.#.#.########.#.##\n#..#..........#.##\n.#.############.##\n#............... | 6AIZU |
p00156 Moats around the Castle_1729 | Now, a ninja is planning to sneak into the castle tower from outside the castle. This ninja can easily run on the ground and swim in the moat, but he is not very good at climbing up from the moat, so he wants to enter the moat as few times as possible.
Create a program that takes a sketch of the castle as input and ou... | # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0156
"""
import sys
from sys import stdin
from collections import deque
input = stdin.readline
def bfs(field, sx, sy):
"""
??????????????°???????????°??????????????§??????????????????
:param field:
:param sx: ???????... | 3Python3 | {
"input": [
"5 5\n.###.\n#...#\n#.&.#\n#...#\n.###.\n18 15\n..####....####....\n####..####....####\n#...............##\n.#.############.##\n#..#..........#.##\n.#.#.########.#.##\n#..#.#......#.#.##\n.#.#....&...#.#.##\n#..#........#.#.##\n.#.#.########.#.##\n#..#..........#.##\n.#.############.##\n#............... | 6AIZU |
p00156 Moats around the Castle_1730 | Now, a ninja is planning to sneak into the castle tower from outside the castle. This ninja can easily run on the ground and swim in the moat, but he is not very good at climbing up from the moat, so he wants to enter the moat as few times as possible.
Create a program that takes a sketch of the castle as input and ou... | import java.util.PriorityQueue;
import java.util.Scanner;
public class Main {
public static class Walk implements Comparable<Walk>{
int x;
int y;
int cost;
public Walk(int x, int y, int cost) {
super();
this.x = x;
this.y = y;
this.cost = cost;
}
@Override
public int compareTo(Walk arg... | 4JAVA | {
"input": [
"5 5\n.###.\n#...#\n#.&.#\n#...#\n.###.\n18 15\n..####....####....\n####..####....####\n#...............##\n.#.############.##\n#..#..........#.##\n.#.#.########.#.##\n#..#.#......#.#.##\n.#.#....&...#.#.##\n#..#........#.#.##\n.#.#.########.#.##\n#..#..........#.##\n.#.############.##\n#............... | 6AIZU |
p00313 Secret Investigation_1731 | The secret organization AiZu AnalyticS has launched a top-secret investigation. There are N people targeted, with identification numbers from 1 to N. As an AZAS Information Strategy Investigator, you have decided to determine the number of people in your target who meet at least one of the following conditions:
* Thos... | n = input()
V = [0]*n
for i in [1, 2, 4]:
for e in map(int, raw_input().split()[1:]):
V[e-1] += i
print sum((e&4>0)*(e!=5)for e in V) | 1Python2 | {
"input": [
"5\n3 1 2 3\n2 4 5\n2 3 4",
"100\n3 1 100 4\n0\n2 2 3",
"5\n3 1 2 3\n2 4 5\n2 2 4",
"5\n3 1 2 1\n2 4 5\n2 3 4",
"5\n3 1 2 3\n2 4 5\n2 3 2",
"5\n3 1 4 3\n2 4 5\n2 3 4",
"100\n3 1 100 4\n0\n2 4 3",
"5\n3 2 4 3\n2 4 5\n2 3 4",
"100\n3 0 100 4\n0\n2 4 3",
"100\n3 0 000... | 6AIZU |
p00313 Secret Investigation_1732 | The secret organization AiZu AnalyticS has launched a top-secret investigation. There are N people targeted, with identification numbers from 1 to N. As an AZAS Information Strategy Investigator, you have decided to determine the number of people in your target who meet at least one of the following conditions:
* Thos... | #include <bits/stdc++.h>
using namespace std;
int N, X, Y, Z;
bool Data[3][100];
void solve() {
int sum;
sum = 0;
for (int i = 0; i < N; ++i) {
if ((!Data[0][i] && Data[2][i]) || (Data[1][i] && Data[2][i])) {
++sum;
}
}
cout << sum << endl;
}
int main() {
int num;
memset(Data, false, sizeof(Data));
... | 2C++ | {
"input": [
"5\n3 1 2 3\n2 4 5\n2 3 4",
"100\n3 1 100 4\n0\n2 2 3",
"5\n3 1 2 3\n2 4 5\n2 2 4",
"5\n3 1 2 1\n2 4 5\n2 3 4",
"5\n3 1 2 3\n2 4 5\n2 3 2",
"5\n3 1 4 3\n2 4 5\n2 3 4",
"100\n3 1 100 4\n0\n2 4 3",
"5\n3 2 4 3\n2 4 5\n2 3 4",
"100\n3 0 100 4\n0\n2 4 3",
"100\n3 0 000... | 6AIZU |
p00313 Secret Investigation_1733 | The secret organization AiZu AnalyticS has launched a top-secret investigation. There are N people targeted, with identification numbers from 1 to N. As an AZAS Information Strategy Investigator, you have decided to determine the number of people in your target who meet at least one of the following conditions:
* Thos... | N = int(input())
U = set([i+1 for i in range(N)])
A = set([int(x) for x in input().split()[1:]])
B = set([int(x) for x in input().split()[1:]])
C = set([int(x) for x in input().split()[1:]])
result = ((U-A) & C) | (B & C)
print(len(result)) | 3Python3 | {
"input": [
"5\n3 1 2 3\n2 4 5\n2 3 4",
"100\n3 1 100 4\n0\n2 2 3",
"5\n3 1 2 3\n2 4 5\n2 2 4",
"5\n3 1 2 1\n2 4 5\n2 3 4",
"5\n3 1 2 3\n2 4 5\n2 3 2",
"5\n3 1 4 3\n2 4 5\n2 3 4",
"100\n3 1 100 4\n0\n2 4 3",
"5\n3 2 4 3\n2 4 5\n2 3 4",
"100\n3 0 100 4\n0\n2 4 3",
"100\n3 0 000... | 6AIZU |
p00313 Secret Investigation_1734 | The secret organization AiZu AnalyticS has launched a top-secret investigation. There are N people targeted, with identification numbers from 1 to N. As an AZAS Information Strategy Investigator, you have decided to determine the number of people in your target who meet at least one of the following conditions:
* Thos... | import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
String xi[] = new String[n];
String bi[] = new String[n];
String ci[] = new String[n];
int x = scan.nextInt();
for(int i = 0 ; i < x ; i++) {
int ... | 4JAVA | {
"input": [
"5\n3 1 2 3\n2 4 5\n2 3 4",
"100\n3 1 100 4\n0\n2 2 3",
"5\n3 1 2 3\n2 4 5\n2 2 4",
"5\n3 1 2 1\n2 4 5\n2 3 4",
"5\n3 1 2 3\n2 4 5\n2 3 2",
"5\n3 1 4 3\n2 4 5\n2 3 4",
"100\n3 1 100 4\n0\n2 4 3",
"5\n3 2 4 3\n2 4 5\n2 3 4",
"100\n3 0 100 4\n0\n2 4 3",
"100\n3 0 000... | 6AIZU |
p00483 Planetary Exploration_1735 | After a long journey, the super-space-time immigrant ship carrying you finally discovered a planet that seems to be habitable. The planet, named JOI, is a harsh planet with three types of terrain, "Jungle," "Ocean," and "Ice," as the name implies. A simple survey created a map of the area around the planned residence. ... | M, N = map(int, raw_input().split())
K = input()
D = {}
for i in range(M+1):
D[i, 0] = 0, 0
for j in range(N+1):
D[0, j] = 0, 0
for i in range(1, M+1):
a = raw_input()
for j in range(1, N+1):
if a[j-1] == 'J':
D[i, j] = (D[i-1, j][0] + D[i, j-1][0] - D[i-1, j-1][0] + 1,
... | 1Python2 | {
"input": [
"4 7\n4\nJIOJOIJ\nIOJOIJO\nJOIJOOI\nOOJJIJO\n3 5 4 7\n2 2 3 6\n2 2 2 2\n1 1 4 7",
"4 7\n4\nJIOJOIJ\nIOJOIJO\nJOIJOOI\nOOJJIJO\n5 5 4 7\n2 2 3 6\n2 2 2 2\n1 1 4 7",
"4 7\n4\nJIOJOIJ\nOJIOJOI\nJOIJOOI\nOOJJIJO\n5 5 4 7\n2 2 3 6\n2 2 2 2\n1 1 4 7",
"4 7\n4\nJIOJOIJ\nOJIOJOI\nJOIJOOI\nOOJJIJO... | 6AIZU |
p00483 Planetary Exploration_1736 | After a long journey, the super-space-time immigrant ship carrying you finally discovered a planet that seems to be habitable. The planet, named JOI, is a harsh planet with three types of terrain, "Jungle," "Ocean," and "Ice," as the name implies. A simple survey created a map of the area around the planned residence. ... | #include <cstdio>
int exist[1001][1001][3]={};
char field[1001][1001];
int m,n,Q;
int main(){
scanf("%d %d %d",&m,&n,&Q);
for(int i=0;i<m;i++){
scanf("%s",field[i]);
}
for(int i=0;i<m;i++){
for(int j=i+1;j<=m;j++){
if(field[i][0]=='J'){
exist[j][1][0]++;
}else if(field[i][0]=='O'){
exist[j][1][1]... | 2C++ | {
"input": [
"4 7\n4\nJIOJOIJ\nIOJOIJO\nJOIJOOI\nOOJJIJO\n3 5 4 7\n2 2 3 6\n2 2 2 2\n1 1 4 7",
"4 7\n4\nJIOJOIJ\nIOJOIJO\nJOIJOOI\nOOJJIJO\n5 5 4 7\n2 2 3 6\n2 2 2 2\n1 1 4 7",
"4 7\n4\nJIOJOIJ\nOJIOJOI\nJOIJOOI\nOOJJIJO\n5 5 4 7\n2 2 3 6\n2 2 2 2\n1 1 4 7",
"4 7\n4\nJIOJOIJ\nOJIOJOI\nJOIJOOI\nOOJJIJO... | 6AIZU |
p00483 Planetary Exploration_1737 | After a long journey, the super-space-time immigrant ship carrying you finally discovered a planet that seems to be habitable. The planet, named JOI, is a harsh planet with three types of terrain, "Jungle," "Ocean," and "Ice," as the name implies. A simple survey created a map of the area around the planned residence. ... | from itertools import accumulate
from operator import add
line, row = [int(x) for x in input().split()]
k = int(input())
L=[]
J=[[0]*(row+1) for _ in range(line+1)]
O=[[0]*(row+1) for _ in range(line+1)]
I=[[0]*(row+1) for _ in range(line+1)]
for _ in range(line):
L.append(input())
for i in range(line):
for j... | 3Python3 | {
"input": [
"4 7\n4\nJIOJOIJ\nIOJOIJO\nJOIJOOI\nOOJJIJO\n3 5 4 7\n2 2 3 6\n2 2 2 2\n1 1 4 7",
"4 7\n4\nJIOJOIJ\nIOJOIJO\nJOIJOOI\nOOJJIJO\n5 5 4 7\n2 2 3 6\n2 2 2 2\n1 1 4 7",
"4 7\n4\nJIOJOIJ\nOJIOJOI\nJOIJOOI\nOOJJIJO\n5 5 4 7\n2 2 3 6\n2 2 2 2\n1 1 4 7",
"4 7\n4\nJIOJOIJ\nOJIOJOI\nJOIJOOI\nOOJJIJO... | 6AIZU |
p00483 Planetary Exploration_1738 | After a long journey, the super-space-time immigrant ship carrying you finally discovered a planet that seems to be habitable. The planet, named JOI, is a harsh planet with three types of terrain, "Jungle," "Ocean," and "Ice," as the name implies. A simple survey created a map of the area around the planned residence. ... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import static java.lang.Integer.parseInt;
/**
* Planetary Exploration
*/
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new Buffered... | 4JAVA | {
"input": [
"4 7\n4\nJIOJOIJ\nIOJOIJO\nJOIJOOI\nOOJJIJO\n3 5 4 7\n2 2 3 6\n2 2 2 2\n1 1 4 7",
"4 7\n4\nJIOJOIJ\nIOJOIJO\nJOIJOOI\nOOJJIJO\n5 5 4 7\n2 2 3 6\n2 2 2 2\n1 1 4 7",
"4 7\n4\nJIOJOIJ\nOJIOJOI\nJOIJOOI\nOOJJIJO\n5 5 4 7\n2 2 3 6\n2 2 2 2\n1 1 4 7",
"4 7\n4\nJIOJOIJ\nOJIOJOI\nJOIJOOI\nOOJJIJO... | 6AIZU |
p00669 K Cards_1739 | One day, the teacher came up with the following game.
The game uses n cards with one number from 1 to 10 and proceeds as follows.
1. The teacher pastes n cards on the blackboard in a horizontal row so that the numbers can be seen, and declares an integer k (k ≥ 1) to the students. For n cards arranged in a horizontal... | while(1):
[n,k]=[int(x) for x in raw_input().split()]
if n==0: break
clist=[]
for i in range(n):
clist.append(int(raw_input()))
d1,d2=0,0
for i in range(n-k+1):
d1=max(reduce(lambda x,y:x*y,clist[i:i+k]),d1)
for j in range(n-k+1):
sect=sorted(clist[j:j+k])
sec... | 1Python2 | {
"input": [
"4 2\n2\n3\n7\n5\n0 0",
"4 2\n4\n3\n7\n5\n0 0",
"4 2\n1\n6\n4\n5\n0 0",
"4 2\n8\n3\n10\n5\n0 0",
"4 2\n4\n3\n7\n1\n0 0",
"4 2\n4\n1\n14\n3\n0 0",
"4 2\n8\n3\n16\n5\n0 0",
"4 2\n4\n3\n11\n1\n0 0",
"4 2\n9\n5\n16\n5\n0 0",
"4 2\n2\n2\n1\n5\n0 0",
"4 2\n1\n6\n2\n5... | 6AIZU |
p00669 K Cards_1740 | One day, the teacher came up with the following game.
The game uses n cards with one number from 1 to 10 and proceeds as follows.
1. The teacher pastes n cards on the blackboard in a horizontal row so that the numbers can be seen, and declares an integer k (k ≥ 1) to the students. For n cards arranged in a horizontal... | #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <iostream>
#include <set>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define PRIME1 99999883
#define PRIME2 99999893
#define EPS 0.00... | 2C++ | {
"input": [
"4 2\n2\n3\n7\n5\n0 0",
"4 2\n4\n3\n7\n5\n0 0",
"4 2\n1\n6\n4\n5\n0 0",
"4 2\n8\n3\n10\n5\n0 0",
"4 2\n4\n3\n7\n1\n0 0",
"4 2\n4\n1\n14\n3\n0 0",
"4 2\n8\n3\n16\n5\n0 0",
"4 2\n4\n3\n11\n1\n0 0",
"4 2\n9\n5\n16\n5\n0 0",
"4 2\n2\n2\n1\n5\n0 0",
"4 2\n1\n6\n2\n5... | 6AIZU |
p00669 K Cards_1741 | One day, the teacher came up with the following game.
The game uses n cards with one number from 1 to 10 and proceeds as follows.
1. The teacher pastes n cards on the blackboard in a horizontal row so that the numbers can be seen, and declares an integer k (k ≥ 1) to the students. For n cards arranged in a horizontal... | from functools import reduce
from collections import Counter
while True:
n, k = map(int, input().split())
if n == 0:
break
clst = [int(input()) for _ in range(n)]
acc = reduce(lambda x, y:x* y, clst[:k])
scores = [acc]
for i in range(n - k):
acc = acc // clst[i] * clst[i + k]
scores.append(acc)
... | 3Python3 | {
"input": [
"4 2\n2\n3\n7\n5\n0 0",
"4 2\n4\n3\n7\n5\n0 0",
"4 2\n1\n6\n4\n5\n0 0",
"4 2\n8\n3\n10\n5\n0 0",
"4 2\n4\n3\n7\n1\n0 0",
"4 2\n4\n1\n14\n3\n0 0",
"4 2\n8\n3\n16\n5\n0 0",
"4 2\n4\n3\n11\n1\n0 0",
"4 2\n9\n5\n16\n5\n0 0",
"4 2\n2\n2\n1\n5\n0 0",
"4 2\n1\n6\n2\n5... | 6AIZU |
p00669 K Cards_1742 | One day, the teacher came up with the following game.
The game uses n cards with one number from 1 to 10 and proceeds as follows.
1. The teacher pastes n cards on the blackboard in a horizontal row so that the numbers can be seen, and declares an integer k (k ≥ 1) to the students. For n cards arranged in a horizontal... | public class
Main
{
private static int
evaluate (
final int[ ] a,
final int k
)
{
int res = 0;
int t;
int i;
t = 1;
for ( i = 0; i < a.length; ++i )
{
if ( i >= k )
t /= a[ i - k ];
t *= a[ i ];
res = Math.max ( res, t );
}
return ( res );... | 4JAVA | {
"input": [
"4 2\n2\n3\n7\n5\n0 0",
"4 2\n4\n3\n7\n5\n0 0",
"4 2\n1\n6\n4\n5\n0 0",
"4 2\n8\n3\n10\n5\n0 0",
"4 2\n4\n3\n7\n1\n0 0",
"4 2\n4\n1\n14\n3\n0 0",
"4 2\n8\n3\n16\n5\n0 0",
"4 2\n4\n3\n11\n1\n0 0",
"4 2\n9\n5\n16\n5\n0 0",
"4 2\n2\n2\n1\n5\n0 0",
"4 2\n1\n6\n2\n5... | 6AIZU |
p00812 Equals are Equals_1743 | Mr. Simpson got up with a slight feeling of tiredness. It was the start of another day of hard work. A bunch of papers were waiting for his inspection on his desk in his office. The papers contained his students' answers to questions in his Math class, but the answers looked as if they were just stains of ink.
His hea... | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pa... | 2C++ | {
"input": [
"a+b+c\n(a+b)+c\na- (b-c)+2\n.\n4ab\n(a - b) (0-b+a) - 1a ^ 2 - b ^ 2\n2 b 2 a\n.\n108 a\n2 2 3 3 3 a\n4 a^1 27\n.\n.",
"a+b+c\n(a+b)+c\na- (b-c)+2\n.\n4ab\n(a - b) (0-b+a) - 1a ^ 2 - b ^ 2\n2 b 2 a\n.\n169 a\n2 2 3 3 3 a\n4 a^1 27\n.\n.",
"a+b+c\n(a+b)+c\na- (b-c)+2\n.\n4ab\n(a - b) (0-b+a) ... | 6AIZU |
p00812 Equals are Equals_1744 | Mr. Simpson got up with a slight feeling of tiredness. It was the start of another day of hard work. A bunch of papers were waiting for his inspection on his desk in his office. The papers contained his students' answers to questions in his Math class, but the answers looked as if they were just stains of ink.
His hea... | import sys
readline = sys.stdin.readline
write = sys.stdout.write
from string import digits
def convert(S):
S = S + "$"
cur = 0
def expr():
nonlocal cur
res = []
op = '+'
while 1:
r = fact()
if op == '-':
for e in r:
... | 3Python3 | {
"input": [
"a+b+c\n(a+b)+c\na- (b-c)+2\n.\n4ab\n(a - b) (0-b+a) - 1a ^ 2 - b ^ 2\n2 b 2 a\n.\n108 a\n2 2 3 3 3 a\n4 a^1 27\n.\n.",
"a+b+c\n(a+b)+c\na- (b-c)+2\n.\n4ab\n(a - b) (0-b+a) - 1a ^ 2 - b ^ 2\n2 b 2 a\n.\n169 a\n2 2 3 3 3 a\n4 a^1 27\n.\n.",
"a+b+c\n(a+b)+c\na- (b-c)+2\n.\n4ab\n(a - b) (0-b+a) ... | 6AIZU |
p00812 Equals are Equals_1745 | Mr. Simpson got up with a slight feeling of tiredness. It was the start of another day of hard work. A bunch of papers were waiting for his inspection on his desk in his office. The papers contained his students' answers to questions in his Math class, but the answers looked as if they were just stains of ink.
His hea... | import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
//Equals are Equals
public class Main{
char[] s;
int id;
class P{
Map<String, Integer> c;
int c0;
public P() {
c = new HashMap<String, Integer>();
c0 = 0;... | 4JAVA | {
"input": [
"a+b+c\n(a+b)+c\na- (b-c)+2\n.\n4ab\n(a - b) (0-b+a) - 1a ^ 2 - b ^ 2\n2 b 2 a\n.\n108 a\n2 2 3 3 3 a\n4 a^1 27\n.\n.",
"a+b+c\n(a+b)+c\na- (b-c)+2\n.\n4ab\n(a - b) (0-b+a) - 1a ^ 2 - b ^ 2\n2 b 2 a\n.\n169 a\n2 2 3 3 3 a\n4 a^1 27\n.\n.",
"a+b+c\n(a+b)+c\na- (b-c)+2\n.\n4ab\n(a - b) (0-b+a) ... | 6AIZU |
p00943 Routing a Marathon Race_1746 | Example
Input
6 6
3
1
9
4
3
6
1 2
1 4
2 6
5 4
6 5
3 2
Output
17 | #include <bits/stdc++.h>
#define ll long long
using namespace std;
struct state
{
ll s;
int v,len;
};
struct comp{
bool operator()(state a,state b)
{
return a.len>b.len;
}};
priority_queue<state,vector<state>,comp> que;
int n,m,c[50],ans;
vector<int> G[50];
map<ll,int> d[50];
ll mask[50];
inline void add_edge(int f,... | 2C++ | {
"input": [
"6 6\n3\n1\n9\n4\n3\n6\n1 2\n1 4\n2 6\n5 4\n6 5\n3 2",
"6 6\n3\n1\n7\n4\n3\n6\n1 2\n1 4\n2 6\n5 4\n6 5\n3 2",
"6 6\n3\n1\n9\n7\n3\n6\n1 2\n1 4\n2 6\n5 4\n6 5\n3 2",
"6 6\n3\n1\n9\n4\n2\n6\n1 2\n1 4\n2 6\n5 4\n6 5\n3 2",
"6 6\n3\n1\n7\n4\n3\n6\n1 2\n1 4\n2 6\n5 5\n6 5\n3 2",
"6 6\n... | 6AIZU |
p01076 Graph Making_1747 | Problem
There are n vertices that are not connected to any of the vertices.
An undirected side is stretched between each vertex.
Find out how many sides can be stretched when the diameter is set to d.
The diameter represents the largest of the shortest distances between two vertices.
Here, the shortest distance is the... | #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": [
"4 2",
"5 1",
"4 3",
"0 1",
"4 5",
"6 5",
"0 2",
"4 1",
"-1 1",
"6 9",
"0 8",
"8 1",
"6 3",
"0 9",
"1 8",
"11 1",
"8 3",
"0 12",
"1 10",
"19 1",
"8 2",
"0 6",
"2 8",
"9 1",
"0 11",
"-1 11",
"1 11",... | 6AIZU |
p01076 Graph Making_1748 | Problem
There are n vertices that are not connected to any of the vertices.
An undirected side is stretched between each vertex.
Find out how many sides can be stretched when the diameter is set to d.
The diameter represents the largest of the shortest distances between two vertices.
Here, the shortest distance is the... | # AOJ 1591 Graph Making
# Python3 2018.7.13 bal4u
n, d = map(int, input().split())
if d == 1: print(n*(n-1)//2)
else: print((n-1)+(n-d-1)*n-((n-d-1)*(n+d-2)//2))
| 3Python3 | {
"input": [
"4 2",
"5 1",
"4 3",
"0 1",
"4 5",
"6 5",
"0 2",
"4 1",
"-1 1",
"6 9",
"0 8",
"8 1",
"6 3",
"0 9",
"1 8",
"11 1",
"8 3",
"0 12",
"1 10",
"19 1",
"8 2",
"0 6",
"2 8",
"9 1",
"0 11",
"-1 11",
"1 11",... | 6AIZU |
p01076 Graph Making_1749 | Problem
There are n vertices that are not connected to any of the vertices.
An undirected side is stretched between each vertex.
Find out how many sides can be stretched when the diameter is set to d.
The diameter represents the largest of the shortest distances between two vertices.
Here, the shortest distance is the... | import java.util.Scanner;
public class Main {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
long N = sc.nextLong();
long D = sc.nextLong();
long ans;
if (D == 1) {
ans = N * (N - 1) / 2;
} else {
long dense = N - D;
ans = dense * (dense - 1) / 2;
ans += ... | 4JAVA | {
"input": [
"4 2",
"5 1",
"4 3",
"0 1",
"4 5",
"6 5",
"0 2",
"4 1",
"-1 1",
"6 9",
"0 8",
"8 1",
"6 3",
"0 9",
"1 8",
"11 1",
"8 3",
"0 12",
"1 10",
"19 1",
"8 2",
"0 6",
"2 8",
"9 1",
"0 11",
"-1 11",
"1 11",... | 6AIZU |
p01210 Speed_1750 | Do you know Speed? It is one of popular card games, in which two players compete how quick they can move their cards to tables.
To play Speed, two players sit face-to-face first. Each player has a deck and a tableau assigned for him, and between them are two tables to make a pile on, one in left and one in right. A ta... | #include<iostream>
#include<stack>
#include<queue>
#include<cassert>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
typedef long long ll;
const ll inf =(1LL)<<50;
enum{IDLE=-1,PUTR=0,PUTL=1,DRAW... | 2C++ | {
"input": [
"1\nSA\n1\nC2\n2\nSA HA\n2\nC2 C3\n5\nS3 S5 S8 S9 S2\n3\nH7 H3 H4\n10\nH7 CJ C5 CA C6 S2 D8 DA S6 HK\n10\nC2 D6 D4 H5 DJ CX S8 S9 D3 D5\n0",
"1\nSA\n1\nC2\n2\nSA HA\n2\nC2 C3\n5\nS3 S5 S8 S9 S2\n3\nH7 H3 H4\n10\nH7 CJ C5 CA C6 S2 D8 DA S6 HK\n10\nC2 D6 D4 H5 DJ CX 8S S9 D3 D5\n0",
"1\nSA\n1\n... | 6AIZU |
p01210 Speed_1751 | Do you know Speed? It is one of popular card games, in which two players compete how quick they can move their cards to tables.
To play Speed, two players sit face-to-face first. Each player has a deck and a tableau assigned for him, and between them are two tables to make a pile on, one in left and one in right. A ta... | import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
//Speed
public class Main{
class C{
int suit, rank;
String str;
public C(String s) {
str = s;
suit = s.charAt(0);
char c = s.charAt(1);
rank = c=='A'?1:c=='K'?13:c=='Q'?12:c=='J'?11:c=='X'?10:(c-... | 4JAVA | {
"input": [
"1\nSA\n1\nC2\n2\nSA HA\n2\nC2 C3\n5\nS3 S5 S8 S9 S2\n3\nH7 H3 H4\n10\nH7 CJ C5 CA C6 S2 D8 DA S6 HK\n10\nC2 D6 D4 H5 DJ CX S8 S9 D3 D5\n0",
"1\nSA\n1\nC2\n2\nSA HA\n2\nC2 C3\n5\nS3 S5 S8 S9 S2\n3\nH7 H3 H4\n10\nH7 CJ C5 CA C6 S2 D8 DA S6 HK\n10\nC2 D6 D4 H5 DJ CX 8S S9 D3 D5\n0",
"1\nSA\n1\n... | 6AIZU |
p01346 Ropeway_1752 | On a small island, there are two towns Darkside and Sunnyside, with steep mountains between them. There’s a company Intertown Company of Package Conveyance; they own a ropeway car between Darkside and Sunnyside and are running a transportation business. They want maximize the revenue by loading as much package as possi... | #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>... | 2C++ | {
"input": [
"3 3 2 1\n1 1 4",
"3 3 2 1\n1 4 1",
"3 3 2 1\n1 1 0",
"3 6 1 1\n2 2 0",
"3 6 2 1\n1 1 0",
"3 6 2 1\n1 2 0",
"3 6 2 1\n2 2 0",
"3 6 1 1\n2 2 1",
"3 4 1 1\n2 2 1",
"3 4 2 1\n2 2 1",
"3 3 2 2\n1 1 4",
"3 3 2 0\n1 4 1",
"3 3 2 0\n1 1 0",
"3 6 2 2\n1 1 0... | 6AIZU |
p01516 Milky Way_1753 | Milky Way
Milky Way
English text is not available in this practice contest.
The Milky Way Transportation Corporation is a travel agency that plans and manages interstellar travel tours. The Milky Way Transportation Corporation is planning a project called "Milky Way Crossing Orihime Hikoboshi Experience Tour". This ... | #include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
... | 2C++ | {
"input": [
""
],
"output": [
""
]
} | 6AIZU |
p01516 Milky Way_1754 | Milky Way
Milky Way
English text is not available in this practice contest.
The Milky Way Transportation Corporation is a travel agency that plans and manages interstellar travel tours. The Milky Way Transportation Corporation is planning a project called "Milky Way Crossing Orihime Hikoboshi Experience Tour". This ... | import java.util.*;
import java.awt.geom.*;
public class Main {
double EPS = 1.0e-08;
private void doit() {
Scanner sc = new Scanner(System.in);
while(true){
int n = sc.nextInt();
int M = sc.nextInt()-1;
int L = sc.nextInt()-1;
if(n == 0 && M == -1 && L == -1) break;
Point2D [][] point = new Poin... | 4JAVA | {
"input": [
""
],
"output": [
""
]
} | 6AIZU |
p01684 Venn Diagram_1755 | Problem Statement
Alice is a private teacher. One of her job is to prepare the learning materials for her student. Now, as part of the materials, she is drawing a Venn diagram between two sets $A$ and $B$.
Venn diagram is a diagram which illustrates the relationships among one or more sets. For example, a Venn diagra... | #include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <string.h>
#include <cmath>
#include <complex>
using namespace std;
#define ISEQ(c) (c).begin(), (c).end()
typedef long long ll;
t... | 2C++ | {
"input": [
"10 5 1 1 0\n10 5 2 2 1\n10 10 70 70 20\n0 0 0 0 0",
"10 5 1 1 0\n10 5 2 2 1\n10 10 71 70 20\n0 0 0 0 0",
"10 5 1 1 0\n10 8 2 2 1\n10 10 71 70 20\n0 0 0 0 0",
"10 5 1 1 1\n10 8 2 2 1\n10 10 71 70 20\n0 0 0 0 0",
"10 5 1 0 0\n10 5 2 2 1\n10 10 71 70 20\n0 0 0 0 0",
"17 5 1 1 0\n10 ... | 6AIZU |
p01684 Venn Diagram_1756 | Problem Statement
Alice is a private teacher. One of her job is to prepare the learning materials for her student. Now, as part of the materials, she is drawing a Venn diagram between two sets $A$ and $B$.
Venn diagram is a diagram which illustrates the relationships among one or more sets. For example, a Venn diagra... | import sys
readline = sys.stdin.readline
write = sys.stdout.write
from math import pi, sqrt, acos, sin
def solve():
EPS = 1e-9
W, H, A, B, C = map(int, readline().split())
if W == 0:
return False
a = sqrt(A / pi); b = sqrt(B / pi)
mx = max(a, b)
if 2*mx > min(W, H) - EPS:
write... | 3Python3 | {
"input": [
"10 5 1 1 0\n10 5 2 2 1\n10 10 70 70 20\n0 0 0 0 0",
"10 5 1 1 0\n10 5 2 2 1\n10 10 71 70 20\n0 0 0 0 0",
"10 5 1 1 0\n10 8 2 2 1\n10 10 71 70 20\n0 0 0 0 0",
"10 5 1 1 1\n10 8 2 2 1\n10 10 71 70 20\n0 0 0 0 0",
"10 5 1 0 0\n10 5 2 2 1\n10 10 71 70 20\n0 0 0 0 0",
"17 5 1 1 0\n10 ... | 6AIZU |
p01828 M and A_1757 | Example
Input
acmicpc
tsukuba
Output
No | #!/usr/bin/env python
import sys
import math
import itertools as it
from collections import deque
sys.setrecursionlimit(10000000)
S_ = raw_input()
T_ = raw_input() + " "
S1 = S2 = ''
for i in range(len(S_)):
if i % 2 == 0:
S1 += S_[i]
else:
S2 += S_[i]
for S in [S1, S2]:
T = T_
for ... | 1Python2 | {
"input": [
"acmicpc\ntsukuba",
"acmicpc\nttukuba",
"acmpcic\nttukuba",
"acmpcid\nttukuba",
"acmpcid\nttakubu",
"acmqcid\nttakubu",
"aciqcmd\nttakubu",
"aciqcmd\ntt`kubu",
"aciqcmd\ntu`ktbu",
"dmcqica\ntu`ktbu",
"dmcqica\ntu`jtbu",
"dmcqica\nut`jtbu",
"dmcqica\ntt`... | 6AIZU |
p01828 M and A_1758 | Example
Input
acmicpc
tsukuba
Output
No | #include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
... | 2C++ | {
"input": [
"acmicpc\ntsukuba",
"acmicpc\nttukuba",
"acmpcic\nttukuba",
"acmpcid\nttukuba",
"acmpcid\nttakubu",
"acmqcid\nttakubu",
"aciqcmd\nttakubu",
"aciqcmd\ntt`kubu",
"aciqcmd\ntu`ktbu",
"dmcqica\ntu`ktbu",
"dmcqica\ntu`jtbu",
"dmcqica\nut`jtbu",
"dmcqica\ntt`... | 6AIZU |
p01828 M and A_1759 | Example
Input
acmicpc
tsukuba
Output
No | def f(s,t):
j=0;i=0
while i<len(t) and j<len(s):
if t[i]==s[j]:j+=2
i+=1
return j>=len(s)
I=input
s=I()
t=I()
print(['No','Yes'][f(s,t) or f(s[1:],t)]) | 3Python3 | {
"input": [
"acmicpc\ntsukuba",
"acmicpc\nttukuba",
"acmpcic\nttukuba",
"acmpcid\nttukuba",
"acmpcid\nttakubu",
"acmqcid\nttakubu",
"aciqcmd\nttakubu",
"aciqcmd\ntt`kubu",
"aciqcmd\ntu`ktbu",
"dmcqica\ntu`ktbu",
"dmcqica\ntu`jtbu",
"dmcqica\nut`jtbu",
"dmcqica\ntt`... | 6AIZU |
p01828 M and A_1760 | Example
Input
acmicpc
tsukuba
Output
No | import java.util.Arrays;
import java.util.Scanner;
public class Main {
MyScanner sc = new MyScanner();
Scanner sc2 = new Scanner(System.in);
long start = System.currentTimeMillis();
long fin = System.currentTimeMillis();
final int MOD = 1000000007;
int[] dx = { 1, 0,... | 4JAVA | {
"input": [
"acmicpc\ntsukuba",
"acmicpc\nttukuba",
"acmpcic\nttukuba",
"acmpcid\nttukuba",
"acmpcid\nttakubu",
"acmqcid\nttakubu",
"aciqcmd\nttakubu",
"aciqcmd\ntt`kubu",
"aciqcmd\ntu`ktbu",
"dmcqica\ntu`ktbu",
"dmcqica\ntu`jtbu",
"dmcqica\nut`jtbu",
"dmcqica\ntt`... | 6AIZU |
p01963 Separate String_1761 | You are given a string $t$ and a set $S$ of $N$ different strings. You need to separate $t$ such that each part is included in $S$.
For example, the following 4 separation methods satisfy the condition when $t = abab$ and $S = \\{a, ab, b\\}$.
* $a,b,a,b$
* $a,b,ab$
* $ab,a,b$
* $ab,ab$
Your task is to count the n... | #include <bits/stdc++.h>
using ll = long long;
template <typename T> T inf;
template <> constexpr int inf<int> = 1e9;
template <> constexpr ll inf<ll> = 1e18;
constexpr int M = 1e9 + 7;
class aho_corasick {
struct PMA {
std::weak_ptr<PMA> fail;
std::vector<std::shared_ptr<PMA>> next;
st... | 2C++ | {
"input": [
"3\na\nb\nab\nabab",
"3\na\nb\nc\nxyz",
"10\na\naa\naaa\naaaa\naaaaa\naaaaaa\naaaaaaa\naaaaaaaa\naaaaaaaaa\naaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"7\nabc\nab\nbc\na\nb\nc\naa\naaabcbccababbc",
"3\na\nb\nba\nabab",
"3\na\nb\nc\nxy{",
"10\na\naa\naaa\naaaa\naaaa... | 6AIZU |
p01963 Separate String_1762 | You are given a string $t$ and a set $S$ of $N$ different strings. You need to separate $t$ such that each part is included in $S$.
For example, the following 4 separation methods satisfy the condition when $t = abab$ and $S = \\{a, ab, b\\}$.
* $a,b,a,b$
* $a,b,ab$
* $ab,a,b$
* $ab,ab$
Your task is to count the n... | from collections import defaultdict
import sys
def solve():
readline = sys.stdin.readline
write = sys.stdout.write
mod = 10**9 + 9
base = 37
ca = ord('a')
N = int(readline())
SS = [readline().strip() for i in range(N)]
SS.sort(key = len)
T = readline().strip()
L = len(T)
L... | 3Python3 | {
"input": [
"3\na\nb\nab\nabab",
"3\na\nb\nc\nxyz",
"10\na\naa\naaa\naaaa\naaaaa\naaaaaa\naaaaaaa\naaaaaaaa\naaaaaaaaa\naaaaaaaaaa\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"7\nabc\nab\nbc\na\nb\nc\naa\naaabcbccababbc",
"3\na\nb\nba\nabab",
"3\na\nb\nc\nxy{",
"10\na\naa\naaa\naaaa\naaaa... | 6AIZU |
p02110 Settler_1763 | Problem
There are N vacant lots on the two-dimensional plane. Numbers from 1 to N are assigned to each vacant lot. Every vacant lot is so small that it can be considered a point. The i-th vacant lot exists at (xi, yi).
Taro chose just K from these N vacant lots and decided to build a building in those vacant lots. Ho... | #include<iostream>
#include<vector>
#include<string>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long ll;
const ll mod = 100... | 2C++ | {
"input": [
"4 3\n2 1\n1 2\n1 3\n2 4",
"5 3\n5 7\n5 6\n6 8\n20 20\n4 8",
"3 2\n2 1\n1 2\n1 3",
"3 3\n2 1\n1 2\n1 3\n2 4",
"5 3\n2 7\n5 6\n6 8\n20 20\n4 8",
"3 2\n0 1\n1 2\n1 3",
"3 2\n0 1\n2 2\n1 3",
"5 3\n5 7\n5 6\n6 8\n20 24\n4 8",
"5 1\n0 5\n5 6\n6 8\n20 20\n4 8",
"5 3\n5 7... | 6AIZU |
p02250 Multiple String Matching_1764 | Determine whether a text T includes a pattern P. Your program should answer for given queries consisting of P_i.
Constraints
* 1 ≤ length of T ≤ 1000000
* 1 ≤ length of P_i ≤ 1000
* 1 ≤ Q ≤ 10000
* The input consists of alphabetical characters and digits
Input
In the first line, a text T is given. In the second lin... | #include<bits/stdc++.h>
using namespace std;
#define int long long
struct SA{
int n,k;
string S;
vector<int> r,r2,t,sa;
SA(){}
SA(string S):S(S){init();}
void init(){
n=S.size();
r.resize(n+1,0);
r2.resize(n+1,0);
t.resize(n+1,0);
sa.resize(n+1,0);
constract_sa();
}
bool compare_... | 2C++ | {
"input": [
"aabaaa\n4\naa\nba\nbb\nxyz",
"aabaaa\n4\nab\nba\nbb\nxyz",
"aabaaa\n4\nab\nba\nba\nxyz",
"aabaaa\n4\nba\nbb\nac\nzyx",
"aabaaa\n4\nca\nab\nba\nzyx",
"aacaaa\n4\nba\nb`\nac\nzyx",
"aacaaa\n4\nca\nb`\nac\nzyx",
"aabaaa\n4\na`\nab\nca\nyzx",
"aadaaa\n4\nca\nb`\nca\nzyx",... | 6AIZU |
p02250 Multiple String Matching_1765 | Determine whether a text T includes a pattern P. Your program should answer for given queries consisting of P_i.
Constraints
* 1 ≤ length of T ≤ 1000000
* 1 ≤ length of P_i ≤ 1000
* 1 ≤ Q ≤ 10000
* The input consists of alphabetical characters and digits
Input
In the first line, a text T is given. In the second lin... | base = 127
mask = (1 << 32) - 1
def calc_hash(f, pl, tl):
dl = tl - pl
tmp = set()
t = 1
for _ in range(pl):
t = (t * base) & mask
e = 0
for i in range(pl):
e = (e * base + f[i]) & mask
for i in range(dl):
tmp.add(e)
e = (e * base - t * f[i] + f[i + pl]) & mas... | 3Python3 | {
"input": [
"aabaaa\n4\naa\nba\nbb\nxyz",
"aabaaa\n4\nab\nba\nbb\nxyz",
"aabaaa\n4\nab\nba\nba\nxyz",
"aabaaa\n4\nba\nbb\nac\nzyx",
"aabaaa\n4\nca\nab\nba\nzyx",
"aacaaa\n4\nba\nb`\nac\nzyx",
"aacaaa\n4\nca\nb`\nac\nzyx",
"aabaaa\n4\na`\nab\nca\nyzx",
"aadaaa\n4\nca\nb`\nca\nzyx",... | 6AIZU |
p02250 Multiple String Matching_1766 | Determine whether a text T includes a pattern P. Your program should answer for given queries consisting of P_i.
Constraints
* 1 ≤ length of T ≤ 1000000
* 1 ≤ length of P_i ≤ 1000
* 1 ≤ Q ≤ 10000
* The input consists of alphabetical characters and digits
Input
In the first line, a text T is given. In the second lin... | import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws IOExcept... | 4JAVA | {
"input": [
"aabaaa\n4\naa\nba\nbb\nxyz",
"aabaaa\n4\nab\nba\nbb\nxyz",
"aabaaa\n4\nab\nba\nba\nxyz",
"aabaaa\n4\nba\nbb\nac\nzyx",
"aabaaa\n4\nca\nab\nba\nzyx",
"aacaaa\n4\nba\nb`\nac\nzyx",
"aacaaa\n4\nca\nb`\nac\nzyx",
"aabaaa\n4\na`\nab\nca\nyzx",
"aadaaa\n4\nca\nb`\nca\nzyx",... | 6AIZU |
p02398 How Many Divisors?_1767 | How Many Divisors?
Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
Constraints
* 1 ≤ a, b, c ≤ 10000
* a ≤ b
Input
Three integers a, b and c are given in a line separated by a single space.
Output
Print the number of divisors in a line.
Example
Inp... | (a, b, c) = map(int, raw_input().split())
count = 0
for i in range(a, b+1):
if c % i == 0:
count = count + 1
print count | 1Python2 | {
"input": [
"5 14 80",
"7 14 80",
"7 4 80",
"1 1 80",
"9 22 80",
"5 20 80",
"7 25 80",
"1 23 80",
"2 23 80",
"4 32 80",
"4 32 120",
"6 18 0",
"4 17 0",
"3 26 0",
"4 30 0",
"2 26 0",
"7 6 80",
"7 1 80",
"5 14 149",
"13 14 80",
"9 4 80... | 6AIZU |
p02398 How Many Divisors?_1768 | How Many Divisors?
Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
Constraints
* 1 ≤ a, b, c ≤ 10000
* a ≤ b
Input
Three integers a, b and c are given in a line separated by a single space.
Output
Print the number of divisors in a line.
Example
Inp... | #include<stdio.h>
int main(void){
int a,b,c,d,x=0;
scanf("%d %d %d",&a,&b,&c);
for(x=a;x<=b;x++){
if(c%x==0){
d++;
}
}
printf("%d\n",d);
return 0;
} | 2C++ | {
"input": [
"5 14 80",
"7 14 80",
"7 4 80",
"1 1 80",
"9 22 80",
"5 20 80",
"7 25 80",
"1 23 80",
"2 23 80",
"4 32 80",
"4 32 120",
"6 18 0",
"4 17 0",
"3 26 0",
"4 30 0",
"2 26 0",
"7 6 80",
"7 1 80",
"5 14 149",
"13 14 80",
"9 4 80... | 6AIZU |
p02398 How Many Divisors?_1769 | How Many Divisors?
Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
Constraints
* 1 ≤ a, b, c ≤ 10000
* a ≤ b
Input
Three integers a, b and c are given in a line separated by a single space.
Output
Print the number of divisors in a line.
Example
Inp... | a, b, c = map(int, input().split())
ans = 0
for i in range(a, b + 1):
if c % i == 0:
ans += 1
print(ans)
| 3Python3 | {
"input": [
"5 14 80",
"7 14 80",
"7 4 80",
"1 1 80",
"9 22 80",
"5 20 80",
"7 25 80",
"1 23 80",
"2 23 80",
"4 32 80",
"4 32 120",
"6 18 0",
"4 17 0",
"3 26 0",
"4 30 0",
"2 26 0",
"7 6 80",
"7 1 80",
"5 14 149",
"13 14 80",
"9 4 80... | 6AIZU |
p02398 How Many Divisors?_1770 | How Many Divisors?
Write a program which reads three integers a, b and c, and prints the number of divisors of c between a and b.
Constraints
* 1 ≤ a, b, c ≤ 10000
* a ≤ b
Input
Three integers a, b and c are given in a line separated by a single space.
Output
Print the number of divisors in a line.
Example
Inp... | import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a,b,c,count=0;
a=sc.nextInt();
b=sc.nextInt();
c=sc.nextInt();
for(int i=a;i<=b;i++){
if(c%i==0) count++;
}
System.out.println(count);
sc.close();
}
}
| 4JAVA | {
"input": [
"5 14 80",
"7 14 80",
"7 4 80",
"1 1 80",
"9 22 80",
"5 20 80",
"7 25 80",
"1 23 80",
"2 23 80",
"4 32 80",
"4 32 120",
"6 18 0",
"4 17 0",
"3 26 0",
"4 30 0",
"2 26 0",
"7 6 80",
"7 1 80",
"5 14 149",
"13 14 80",
"9 4 80... | 6AIZU |
cb03_1771 | The problem is very simple. For every string given as input, you need to tell us the number of subsequences of it that are palindromes (need not necessarily be distinct). Note that the empty string is not a palindrome.
For example, the palindromic subsequences of "aab" are:
"a", "a", "b", "aa", and the method returns... | T = int(raw_input())
for z in xrange(T):
s = raw_input().strip()
cache = [ [0 for j in xrange(55)] for i in xrange(55) ]
N = len(s)
for l in xrange(N,0,-1):
for i in xrange(N-l+1):
j = i+l
if i == 0 or j == N:
cache[i][j] = 0
el... | 1Python2 | {
"input": [
"3\naab\ndddd\nthisisapalindromeemordnilapasisiht"
],
"output": [
"4\n15\n814157"
]
} | 1CODECHEF |
crypt05_1772 | Problem Statement
A Mathematics professor walked into her class. She wanted to test her students’ abilities and hence, gave them a series:
1,1,2,3,5,8….
And asked them to predict the number at a given position.
Write a program to do exactly that. Your task is to take numbers as input (one per line), and print the corr... | #! /usr/bin/env python
def genFibo(n):
fibo=list()
fibo.append(1)
fibo.append(1)
for i in range(2,n):
fibo.append(fibo[i-1]+fibo[i-2])
print fibo[n-1]
def main():
sm=0
n=input()
while n:
genFibo(n)
n=input()
if __name__=="__main__":
main() | 1Python2 | {
"input": [
"5\n99\n0",
"5\n92\n0",
"5\n55\n0",
"5\n30\n0",
"5\n42\n0",
"5\n49\n0",
"5\n27\n0",
"5\n9\n0",
"5\n10\n0",
"5\n130\n0",
"5\n151\n0",
"5\n14\n0",
"5\n68\n0",
"5\n89\n0",
"5\n22\n0",
"5\n4\n0",
"5\n17\n0",
"5\n212\n0",
"5\n18\n0",
... | 1CODECHEF |
guess_1773 | Alice and Bob, both have to drink water. But they both don't want to go, so they will play a game to decide who will fetch water for both of them. Alice will choose a number randomly between 1 and N (both inclusive) and Bob will choose a number randomly between 1 and M (both inclusive). Both will write their numbers on... | import fractions as fs
N = input()
A = []
for i in range(N):
t = raw_input().split()
t2=[]
t2.append(int(t[0]))
t2.append(int(t[1]))
A.append(t2)
def getOdd(n,m):
if (n*m)&1 :
return n*m/2
else:
return ((n*m-1)/2)+1
def solve(x):
n = x[0]
m = x[1]
odd = getOdd(n,m)
tot = n*m
c = fs.gcd(odd,tot)
a ... | 1Python2 | {
"input": [
"3\n1 1\n1 2\n2 3",
"3\n1 1\n1 3\n2 3",
"3\n1 2\n1 3\n2 3",
"3\n1 1\n1 1\n2 3",
"3\n1 1\n2 1\n2 3",
"3\n1 3\n1 3\n2 2",
"3\n1 1\n2 1\n1 3",
"3\n1 2\n2 1\n2 3",
"3\n1 3\n1 6\n2 2",
"3\n1 1\n1 1\n1 3",
"3\n1 1\n1 6\n3 3",
"3\n2 6\n1 5\n5 2",
"3\n1 2\n2 1\... | 1CODECHEF |
mes_1774 | Problem description
One of the Engineer friends of John, Mr. Dev tried to develop an encryption algorithm which can send strings of words wirelessly between two devices connected through Wi-Fi. On completing the design of algorithm, John decides to test his algorithm on real devices. To test his algorithm on device, De... | def d(s1,s2):
if len(s1) > len(s2):
s1,s2 = s2,s1
distances = range(len(s1) + 1)
for index2,char2 in enumerate(s2):
newDistances = [index2+1]
for index1,char1 in enumerate(s1):
if char1 == char2:
newDistances.append(distances[index1])
else:
... | 1Python2 | {
"input": [
"2\nHe is a good programmer\nhp is a pool Probgrammer\nProgram\nprpgreamp"
],
"output": [
"4\n3"
]
} | 1CODECHEF |
reciicha_1775 | Help Saurabh with his Chemistry Assignment.
Saurabh has been given a chemistry assignment by Ruby Mam. Though the assignment is simple but
Saurabh has to watch India vs Pakistan Match and he has no time to do the assignment by himself.
So Saurabh wants you to do his assignment so that he doesn’t get scolded by Ruby Mam... | l=[0]*1000003
l[0]=1
for i in range(1,len(l)):
l[i]=i*l[i-1]%1000003
for i in range(input()):
n,x=map(int,raw_input().split())
if n>=1000003:
print "0"
else:
print ((l[n])*x)%1000003 | 1Python2 | {
"input": [
"2\n1 2\n2 1"
],
"output": [
"2\n2"
]
} | 1CODECHEF |
traveler_1776 | Chef likes to travel very much. He plans some travel routes and wants to know their lengths. He hired you to make these calculations. But be careful, some of the routes are incorrect. There may be some misspelling in city names or there will be no road between some two consecutive cities in the route. Also note that Ch... | def main():
#read no of cities
n = input()
#read cities
city = raw_input().split()
#read no of routes
m = input()
mapp = {}
#zero out map of routes
for c in city:
mapp[c] = [0]*n
#populate map with available routes by index
while m:
m -= 1
road = raw_i... | 1Python2 | {
"input": [
"5\nDonetsk Kiev New-York Miami Hollywood\n9\nDonetsk Kiev 560\nKiev New-York 7507\nNew-York Miami 1764\nMiami Hollywood 28\nHollywood Miami 30\nMiami New-York 1764\nKiev Donetsk 550\nHollywood New-York 1736\nNew-York Hollywood 1738\n13\n5 Donetsk Kiev New-York Miami Hollywood\n5 Hollywood Miami New-... | 1CODECHEF |
1016_C. Vasya And The Mushrooms_1777 | Vasya's house is situated in a forest, and there is a mushroom glade near it. The glade consists of two rows, each of which can be divided into n consecutive cells. For each cell Vasya knows how fast the mushrooms grow in this cell (more formally, how many grams of mushrooms grow in this cell each minute). Vasya spends... | from sys import stdin
from itertools import repeat
def f(a):
n = len(a)
ta = [0] * (n + 1)
sa = [0] * (n + 1)
ra = [0] * (n + 1)
for i in xrange(n - 1, -1, -1):
sa[i] = sa[i+1] + ta[i+1]
ta[i] = ta[i+1] + a[i]
ra[i] = ra[i+1] + (n - 1 - i) * a[i]
return sa, ta, ra
def mai... | 1Python2 | {
"input": [
"3\n1 2 3\n6 5 4\n",
"3\n1 1000 10000\n10 100 100000\n",
"6\n12 8 12 17 20 5\n17 4 8 8 8 4\n",
"6\n4 1 12 9 3 11\n12 20 19 12 19 11\n",
"1\n1\n1\n",
"2\n1 2\n1 1\n",
"1\n7\n5\n",
"6\n16 20 18 7 14 2\n17 12 4 10 7 4\n",
"6\n20 8 12 17 20 5\n17 4 8 8 8 4\n",
"6\n4 1 ... | 2CODEFORCES |
1016_C. Vasya And The Mushrooms_1778 | Vasya's house is situated in a forest, and there is a mushroom glade near it. The glade consists of two rows, each of which can be divided into n consecutive cells. For each cell Vasya knows how fast the mushrooms grow in this cell (more formally, how many grams of mushrooms grow in this cell each minute). Vasya spends... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 100;
long long a[maxn], b[maxn], res;
long long sumaL[maxn], sumaR[maxn], sumbL[maxn], sumbR[maxn];
long long sal[maxn], sar[maxn], sbl[maxn], sbr[maxn];
void downToRight(long long ans, int i, int n, long long t) {
ans += t * sumbR[i + 1] + sbr[i + ... | 2C++ | {
"input": [
"3\n1 2 3\n6 5 4\n",
"3\n1 1000 10000\n10 100 100000\n",
"6\n12 8 12 17 20 5\n17 4 8 8 8 4\n",
"6\n4 1 12 9 3 11\n12 20 19 12 19 11\n",
"1\n1\n1\n",
"2\n1 2\n1 1\n",
"1\n7\n5\n",
"6\n16 20 18 7 14 2\n17 12 4 10 7 4\n",
"6\n20 8 12 17 20 5\n17 4 8 8 8 4\n",
"6\n4 1 ... | 2CODEFORCES |
1016_C. Vasya And The Mushrooms_1779 | Vasya's house is situated in a forest, and there is a mushroom glade near it. The glade consists of two rows, each of which can be divided into n consecutive cells. For each cell Vasya knows how fast the mushrooms grow in this cell (more formally, how many grams of mushrooms grow in this cell each minute). Vasya spends... | n = int(input())
u1 = list(map(int, input().split()))
u2 = list(map(int, input().split()))
a1 = u1[:n]
a2 = u2[:n]
for i in range(1, n):
a1[i] += a1[i - 1]
a2[i] += a2[i - 1]
q1 = [0] * (2 * n)
q2 = [0] * (2 * n)
for i in range(1, n):
q1[i] = u1[i] * (i) + q1[i - 1]
q2[i] = u2[i] * (i) + q2[i - 1]
for i... | 3Python3 | {
"input": [
"3\n1 2 3\n6 5 4\n",
"3\n1 1000 10000\n10 100 100000\n",
"6\n12 8 12 17 20 5\n17 4 8 8 8 4\n",
"6\n4 1 12 9 3 11\n12 20 19 12 19 11\n",
"1\n1\n1\n",
"2\n1 2\n1 1\n",
"1\n7\n5\n",
"6\n16 20 18 7 14 2\n17 12 4 10 7 4\n",
"6\n20 8 12 17 20 5\n17 4 8 8 8 4\n",
"6\n4 1 ... | 2CODEFORCES |
1016_C. Vasya And The Mushrooms_1780 | Vasya's house is situated in a forest, and there is a mushroom glade near it. The glade consists of two rows, each of which can be divided into n consecutive cells. For each cell Vasya knows how fast the mushrooms grow in this cell (more formally, how many grams of mushrooms grow in this cell each minute). Vasya spends... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public ... | 4JAVA | {
"input": [
"3\n1 2 3\n6 5 4\n",
"3\n1 1000 10000\n10 100 100000\n",
"6\n12 8 12 17 20 5\n17 4 8 8 8 4\n",
"6\n4 1 12 9 3 11\n12 20 19 12 19 11\n",
"1\n1\n1\n",
"2\n1 2\n1 1\n",
"1\n7\n5\n",
"6\n16 20 18 7 14 2\n17 12 4 10 7 4\n",
"6\n20 8 12 17 20 5\n17 4 8 8 8 4\n",
"6\n4 1 ... | 2CODEFORCES |
103_C. Russian Roulette_1781 | After all the events in Orlando we all know, Sasha and Roma decided to find out who is still the team's biggest loser. Thankfully, Masha found somewhere a revolver with a rotating cylinder of n bullet slots able to contain exactly k bullets, now the boys have a chance to resolve the problem once and for all.
Sasha se... | n,m,k=map(int,raw_input().split())
first=n-(2*m-1)
if first%2==0:
retr=1
first+=1
else:
retr=0
ans=""
for i in xrange(k):
q=int(raw_input())
if first>0:
if retr==1 and q==n and m>0: ans+="X"
elif q<=first: ans+="."
elif q%2==0: ans+="X"
else: ans+="."
else:
... | 1Python2 | {
"input": [
"5 2 5\n1\n2\n3\n4\n5\n",
"6 3 6\n1\n2\n3\n4\n5\n6\n",
"3 1 3\n1\n2\n3\n",
"7 7 7\n1\n2\n3\n4\n5\n6\n7\n",
"4 2 8\n1\n3\n4\n2\n3\n4\n1\n2\n",
"9 4 9\n1\n2\n3\n4\n5\n6\n7\n8\n9\n",
"7 5 7\n1\n2\n3\n4\n5\n6\n7\n",
"15 10 15\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\... | 2CODEFORCES |
103_C. Russian Roulette_1782 | After all the events in Orlando we all know, Sasha and Roma decided to find out who is still the team's biggest loser. Thankfully, Masha found somewhere a revolver with a rotating cylinder of n bullet slots able to contain exactly k bullets, now the boys have a chance to resolve the problem once and for all.
Sasha se... | #include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, p;
cin >> n >> k >> p;
while (p--) {
long long x;
cin >> x;
if (k == 0) {
cout << '.';
continue;
} else {
if (n % 2) {
if (x == n)
cout << 'X';
else {
long long num_even... | 2C++ | {
"input": [
"5 2 5\n1\n2\n3\n4\n5\n",
"6 3 6\n1\n2\n3\n4\n5\n6\n",
"3 1 3\n1\n2\n3\n",
"7 7 7\n1\n2\n3\n4\n5\n6\n7\n",
"4 2 8\n1\n3\n4\n2\n3\n4\n1\n2\n",
"9 4 9\n1\n2\n3\n4\n5\n6\n7\n8\n9\n",
"7 5 7\n1\n2\n3\n4\n5\n6\n7\n",
"15 10 15\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\... | 2CODEFORCES |
103_C. Russian Roulette_1783 | After all the events in Orlando we all know, Sasha and Roma decided to find out who is still the team's biggest loser. Thankfully, Masha found somewhere a revolver with a rotating cylinder of n bullet slots able to contain exactly k bullets, now the boys have a chance to resolve the problem once and for all.
Sasha se... | #!/usr/bin/env python3
n, k, p = map(int, input().strip().split())
if k == 0:
ak = 0
an = n
else:
ak = k - 1 if n % 2 == 1 else k
an = n - (n % 2)
ans = ''
for i in range(p):
v = int(input().rstrip())
if k == 0:
print('.', end='')
else:
if v == n:
print('X', en... | 3Python3 | {
"input": [
"5 2 5\n1\n2\n3\n4\n5\n",
"6 3 6\n1\n2\n3\n4\n5\n6\n",
"3 1 3\n1\n2\n3\n",
"7 7 7\n1\n2\n3\n4\n5\n6\n7\n",
"4 2 8\n1\n3\n4\n2\n3\n4\n1\n2\n",
"9 4 9\n1\n2\n3\n4\n5\n6\n7\n8\n9\n",
"7 5 7\n1\n2\n3\n4\n5\n6\n7\n",
"15 10 15\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\... | 2CODEFORCES |
103_C. Russian Roulette_1784 | After all the events in Orlando we all know, Sasha and Roma decided to find out who is still the team's biggest loser. Thankfully, Masha found somewhere a revolver with a rotating cylinder of n bullet slots able to contain exactly k bullets, now the boys have a chance to resolve the problem once and for all.
Sasha se... | import java.util.*;
public class C {
private static Scanner in;
public void run() {
long n = in.nextLong();
long x = in.nextLong();
int p = in.nextInt();
for (int t = 0; t < p; t++) {
System.out.print(solve(n, x, in.nextLong() - 1) ? '.' : 'X');
}
System.out.println();
}
private boolean solve(long... | 4JAVA | {
"input": [
"5 2 5\n1\n2\n3\n4\n5\n",
"6 3 6\n1\n2\n3\n4\n5\n6\n",
"3 1 3\n1\n2\n3\n",
"7 7 7\n1\n2\n3\n4\n5\n6\n7\n",
"4 2 8\n1\n3\n4\n2\n3\n4\n1\n2\n",
"9 4 9\n1\n2\n3\n4\n5\n6\n7\n8\n9\n",
"7 5 7\n1\n2\n3\n4\n5\n6\n7\n",
"15 10 15\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\... | 2CODEFORCES |
1062_D. Fun with Integers_1785 | You are given a positive integer n greater or equal to 2. For every pair of integers a and b (2 ≤ |a|, |b| ≤ n), you can transform a into b if and only if there exists an integer x such that 1 < |x| and (a ⋅ x = b or b ⋅ x = a), where |x| denotes the absolute value of x.
After such a transformation, your score increas... | n=int(input())
c=0
for j in range(2,1+n//2):
e=0
i=n//j
e+=(i*(i+1))//2
e-=1
if e>0:
c+=e
print(c*4) | 1Python2 | {
"input": [
"2\n",
"4\n",
"6\n",
"28237\n",
"13190\n",
"39914\n",
"81367\n",
"8554\n",
"61106\n",
"67448\n",
"39004\n",
"22308\n",
"16054\n",
"71468\n",
"60501\n",
"100\n",
"300\n",
"59632\n",
"90783\n",
"5611\n",
"1000\n",
"6947... | 2CODEFORCES |
1062_D. Fun with Integers_1786 | You are given a positive integer n greater or equal to 2. For every pair of integers a and b (2 ≤ |a|, |b| ≤ n), you can transform a into b if and only if there exists an integer x such that 1 < |x| and (a ⋅ x = b or b ⋅ x = a), where |x| denotes the absolute value of x.
After such a transformation, your score increas... | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
long long ans = 0;
for (int i = 2; i <= n; i++) {
for (int j = i + i; j <= n; j += i) {
ans += j / i;
}
}
cout << ans * 4 << endl;
return 0;
}
| 2C++ | {
"input": [
"2\n",
"4\n",
"6\n",
"28237\n",
"13190\n",
"39914\n",
"81367\n",
"8554\n",
"61106\n",
"67448\n",
"39004\n",
"22308\n",
"16054\n",
"71468\n",
"60501\n",
"100\n",
"300\n",
"59632\n",
"90783\n",
"5611\n",
"1000\n",
"6947... | 2CODEFORCES |
1062_D. Fun with Integers_1787 | You are given a positive integer n greater or equal to 2. For every pair of integers a and b (2 ≤ |a|, |b| ≤ n), you can transform a into b if and only if there exists an integer x such that 1 < |x| and (a ⋅ x = b or b ⋅ x = a), where |x| denotes the absolute value of x.
After such a transformation, your score increas... | i = input()
i = int(i)
v = 0
g = 2
s = 4
while g <= i:
while s <= i:
v = v + int(s / g * 4)
s = s + g
g = g + 1
s = g * 2
print(str(v)) | 3Python3 | {
"input": [
"2\n",
"4\n",
"6\n",
"28237\n",
"13190\n",
"39914\n",
"81367\n",
"8554\n",
"61106\n",
"67448\n",
"39004\n",
"22308\n",
"16054\n",
"71468\n",
"60501\n",
"100\n",
"300\n",
"59632\n",
"90783\n",
"5611\n",
"1000\n",
"6947... | 2CODEFORCES |
1062_D. Fun with Integers_1788 | You are given a positive integer n greater or equal to 2. For every pair of integers a and b (2 ≤ |a|, |b| ≤ n), you can transform a into b if and only if there exists an integer x such that 1 < |x| and (a ⋅ x = b or b ⋅ x = a), where |x| denotes the absolute value of x.
After such a transformation, your score increas... | import java.util.*;
import java.io.*;
public class Main
{
static int n;
static long[] s;
static ArrayList<Integer> p;
static void sieve()
{
int x = (int)1e5;
p = new ArrayList<Integer>();
boolean prime[] = new boolean[x+1];
for(int i = 0 ;... | 4JAVA | {
"input": [
"2\n",
"4\n",
"6\n",
"28237\n",
"13190\n",
"39914\n",
"81367\n",
"8554\n",
"61106\n",
"67448\n",
"39004\n",
"22308\n",
"16054\n",
"71468\n",
"60501\n",
"100\n",
"300\n",
"59632\n",
"90783\n",
"5611\n",
"1000\n",
"6947... | 2CODEFORCES |
1084_C. The Fair Nut and String_1789 | The Fair Nut found a string s. The string consists of lowercase Latin letters. The Nut is a curious guy, so he wants to find the number of strictly increasing sequences p_1, p_2, …, p_k, such that:
1. For each i (1 ≤ i ≤ k), s_{p_i} = 'a'.
2. For each i (1 ≤ i < k), there is such j that p_i < j < p_{i + 1} and s... | import math
import collections
import bisect
import heapq
import time
import random
import itertools
import sys
mod=1000000007
s=str(raw_input())
pos=1
n=len(s)
lagataara=1
p=[]
for i in xrange(0,n):
if s[i]=='a':
lagataara=lagataara+1
if s[i]=='b':
pos=(pos*lagataara)%mod
lagataara=1
pos=(pos*lagataara+mod... | 1Python2 | {
"input": [
"agaa\n",
"baaaa\n",
"abbaa\n",
"aaaaabb\n",
"aabaaaa\n",
"babbabaabbbbabwbvbhbbbaaabbabbbbbbbkabbbbabaaabbbbbbajabbaaabazbbbzbalbabbwbbaabbabacabdbabbbfaaabbb\n",
"baaahbbbba\n",
"ababavvvv\n",
"abnxabbaab\n",
"krflnzhter\n",
"amaabbbbxaabbbabaabaabbaaabaaaaab... | 2CODEFORCES |
1084_C. The Fair Nut and String_1790 | The Fair Nut found a string s. The string consists of lowercase Latin letters. The Nut is a curious guy, so he wants to find the number of strictly increasing sequences p_1, p_2, …, p_k, such that:
1. For each i (1 ≤ i ≤ k), s_{p_i} = 'a'.
2. For each i (1 ≤ i < k), there is such j that p_i < j < p_{i + 1} and s... | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 4;
const int mod = 1e9 + 7;
int dp[N];
char a[N];
int main() {
scanf("%s", a + 1);
int n = strlen(a + 1);
int sum = 0;
int ans = 0;
int flag = 0;
for (int i = 1; i <= n;) {
if (a[i] == 'a') {
dp[i] = sum + 1;
dp[i] %= mod;
... | 2C++ | {
"input": [
"agaa\n",
"baaaa\n",
"abbaa\n",
"aaaaabb\n",
"aabaaaa\n",
"babbabaabbbbabwbvbhbbbaaabbabbbbbbbkabbbbabaaabbbbbbajabbaaabazbbbzbalbabbwbbaabbabacabdbabbbfaaabbb\n",
"baaahbbbba\n",
"ababavvvv\n",
"abnxabbaab\n",
"krflnzhter\n",
"amaabbbbxaabbbabaabaabbaaabaaaaab... | 2CODEFORCES |
1084_C. The Fair Nut and String_1791 | The Fair Nut found a string s. The string consists of lowercase Latin letters. The Nut is a curious guy, so he wants to find the number of strictly increasing sequences p_1, p_2, …, p_k, such that:
1. For each i (1 ≤ i ≤ k), s_{p_i} = 'a'.
2. For each i (1 ≤ i < k), there is such j that p_i < j < p_{i + 1} and s... | s=input()
sss=''
for i in s:
if i in ['a','b']:
sss+=i
from itertools import groupby
xxx=[''.join(g) for _, g in groupby(sss)]
xxx=[len(i)+1 for i in xxx if 'a' in i]
ans=1
if len(xxx)==1:
print((xxx[0]-1)%1000000007)
else:
for i in xxx:
ans*=i
print((ans-1)%1000000007)
| 3Python3 | {
"input": [
"agaa\n",
"baaaa\n",
"abbaa\n",
"aaaaabb\n",
"aabaaaa\n",
"babbabaabbbbabwbvbhbbbaaabbabbbbbbbkabbbbabaaabbbbbbajabbaaabazbbbzbalbabbwbbaabbabacabdbabbbfaaabbb\n",
"baaahbbbba\n",
"ababavvvv\n",
"abnxabbaab\n",
"krflnzhter\n",
"amaabbbbxaabbbabaabaabbaaabaaaaab... | 2CODEFORCES |
1084_C. The Fair Nut and String_1792 | The Fair Nut found a string s. The string consists of lowercase Latin letters. The Nut is a curious guy, so he wants to find the number of strictly increasing sequences p_1, p_2, …, p_k, such that:
1. For each i (1 ≤ i ≤ k), s_{p_i} = 'a'.
2. For each i (1 ≤ i < k), there is such j that p_i < j < p_{i + 1} and s... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class B {
public static void main(String[] args) throws NumberFormatException, IOException {
Scanner sc = new Scanner();
PrintWriter out = new PrintWri... | 4JAVA | {
"input": [
"agaa\n",
"baaaa\n",
"abbaa\n",
"aaaaabb\n",
"aabaaaa\n",
"babbabaabbbbabwbvbhbbbaaabbabbbbbbbkabbbbabaaabbbbbbajabbaaabazbbbzbalbabbwbbaabbabacabdbabbbfaaabbb\n",
"baaahbbbba\n",
"ababavvvv\n",
"abnxabbaab\n",
"krflnzhter\n",
"amaabbbbxaabbbabaabaabbaaabaaaaab... | 2CODEFORCES |
1103_E. Radix sum_1793 | Let's define radix sum of number a consisting of digits a_1, … ,a_k and number b consisting of digits b_1, … ,b_k(we add leading zeroes to the shorter number to match longer length) as number s(a,b) consisting of digits (a_1+b_1)mod 10, … ,(a_k+b_k)mod 10. The radix sum of several integers is defined as follows: s(t_1,... | #include <bits/stdc++.h>
using namespace std;
using INT = unsigned long long;
const int N = 100000;
int f[11111], g[11111];
struct Ring {
INT a[5];
Ring() {}
void clear() { memset(a, 0, sizeof a); }
Ring operator+(Ring r) {
Ring R = r;
for (int i = 0; i < 5; i++) R.a[i] += a[i];
return R;
}
void... | 2C++ | {
"input": [
"2\n5 6\n",
"4\n5 7 5 7\n",
"2\n0 1\n",
"1\n0\n",
"2\n0 2\n",
"1\n1\n",
"2\n7 6\n",
"4\n5 7 5 13\n",
"4\n0 7 5 13\n",
"4\n0 7 6 23\n",
"4\n1 7 6 23\n",
"4\n2 7 6 23\n",
"4\n3 7 6 23\n",
"4\n3 7 9 27\n",
"4\n3 7 10 27\n",
"4\n3 1 10 27\n",
... | 2CODEFORCES |
1103_E. Radix sum_1794 | Let's define radix sum of number a consisting of digits a_1, … ,a_k and number b consisting of digits b_1, … ,b_k(we add leading zeroes to the shorter number to match longer length) as number s(a,b) consisting of digits (a_1+b_1)mod 10, … ,(a_k+b_k)mod 10. The radix sum of several integers is defined as follows: s(t_1,... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Deque;
import java.util.function.Supplier;
import java.util.Map;
import java.io.OutputStreamWriter;
import java.io.OutputStream;
import java.util.Collection;
import ja... | 4JAVA | {
"input": [
"2\n5 6\n",
"4\n5 7 5 7\n",
"2\n0 1\n",
"1\n0\n",
"2\n0 2\n",
"1\n1\n",
"2\n7 6\n",
"4\n5 7 5 13\n",
"4\n0 7 5 13\n",
"4\n0 7 6 23\n",
"4\n1 7 6 23\n",
"4\n2 7 6 23\n",
"4\n3 7 6 23\n",
"4\n3 7 9 27\n",
"4\n3 7 10 27\n",
"4\n3 1 10 27\n",
... | 2CODEFORCES |
1131_E. String Multiplication_1795 | Roman and Denis are on the trip to the programming competition. Since the trip was long, they soon got bored, and hence decided to came up with something. Roman invented a pizza's recipe, while Denis invented a string multiplication. According to Denis, the result of multiplication (product) of strings s of length m an... | import sys
def solve(p, n):
curState = getStat(p[0])
for i in range(1, n):
newState = getStat(p[i])
#import pdb; pdb.set_trace()
lp = len(p[i])
st = p[i][0]
stl = 1
for j in range(1, lp):
if p[i][j] == st:
stl += 1
cont... | 1Python2 | {
"input": [
"2\nbnn\na\n",
"3\na\nb\na\n",
"9\nlfpgbnlzyn\nc\ns\nw\nr\nm\nq\ny\nyinfblfcdhidphyfvgkxyuwomahiibbhnigdslsguhjkplibnhhrshtekwgefxeugyyyyy\n",
"6\nu\np\nm\nz\nv\nvv\n",
"4\nqe\nnd\niqryhukieskfvaeettersinksrmazelxtgvartuz\nvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv... | 2CODEFORCES |
1131_E. String Multiplication_1796 | Roman and Denis are on the trip to the programming competition. Since the trip was long, they soon got bored, and hence decided to came up with something. Roman invented a pizza's recipe, while Denis invented a string multiplication. According to Denis, the result of multiplication (product) of strings s of length m an... | #include <bits/stdc++.h>
int32_t get_answer_direct(std::string& str, char ch) {
int32_t answer = 0;
int32_t begin = 0;
for (int32_t i = 1; i < str.size(); i++)
if (str[i] != str[begin]) {
if (str[i - 1] == ch) answer = std::max(answer, i - begin);
begin = i;
}
if (str[str.size() - 1] == ch)
... | 2C++ | {
"input": [
"2\nbnn\na\n",
"3\na\nb\na\n",
"9\nlfpgbnlzyn\nc\ns\nw\nr\nm\nq\ny\nyinfblfcdhidphyfvgkxyuwomahiibbhnigdslsguhjkplibnhhrshtekwgefxeugyyyyy\n",
"6\nu\np\nm\nz\nv\nvv\n",
"4\nqe\nnd\niqryhukieskfvaeettersinksrmazelxtgvartuz\nvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv... | 2CODEFORCES |
1131_E. String Multiplication_1797 | Roman and Denis are on the trip to the programming competition. Since the trip was long, they soon got bored, and hence decided to came up with something. Roman invented a pizza's recipe, while Denis invented a string multiplication. According to Denis, the result of multiplication (product) of strings s of length m an... | ALPH = 'abcdefghijklmnopqrstuvwxyz'
MAX = 10 ** 9
def cnt(s):
c = {ch : 0 for ch in ALPH}
i = 0
while i < len(s):
j = i + 1
while j < len(s) and s[i] == s[j]:
j += 1
c[s[i]] = max(c[s[i]], j - i)
i = j
return c
def nxt(c, t):
nc = cnt(t)
for ch in AL... | 3Python3 | {
"input": [
"2\nbnn\na\n",
"3\na\nb\na\n",
"9\nlfpgbnlzyn\nc\ns\nw\nr\nm\nq\ny\nyinfblfcdhidphyfvgkxyuwomahiibbhnigdslsguhjkplibnhhrshtekwgefxeugyyyyy\n",
"6\nu\np\nm\nz\nv\nvv\n",
"4\nqe\nnd\niqryhukieskfvaeettersinksrmazelxtgvartuz\nvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv... | 2CODEFORCES |
1131_E. String Multiplication_1798 | Roman and Denis are on the trip to the programming competition. Since the trip was long, they soon got bored, and hence decided to came up with something. Roman invented a pizza's recipe, while Denis invented a string multiplication. According to Denis, the result of multiplication (product) of strings s of length m an... | import java.io.*;
import java.util.Arrays;
import java.util.StringJoiner;
import java.util.StringTokenizer;
public class Main {
static int N;
static String[] P;
public static void main(String[] args) {
FastScanner sc = new FastScanner(System.in);
N = sc.nextInt();
P = new String[N... | 4JAVA | {
"input": [
"2\nbnn\na\n",
"3\na\nb\na\n",
"9\nlfpgbnlzyn\nc\ns\nw\nr\nm\nq\ny\nyinfblfcdhidphyfvgkxyuwomahiibbhnigdslsguhjkplibnhhrshtekwgefxeugyyyyy\n",
"6\nu\np\nm\nz\nv\nvv\n",
"4\nqe\nnd\niqryhukieskfvaeettersinksrmazelxtgvartuz\nvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv... | 2CODEFORCES |
1152_A. Neko Finds Grapes_1799 | On a random day, Neko found n treasure chests and m keys. The i-th chest has an integer a_i written on it and the j-th key has an integer b_j on it. Neko knows those chests contain the powerful mysterious green Grapes, thus Neko wants to open as many treasure chests as possible.
The j-th key can be used to unlock the ... | #https://codeforces.com/contest/1152/problem/0
n,m=map(int,raw_input().split())
ch=list(map(int,raw_input().split()))
ke=list(map(int,raw_input().split()))
cho,che=0,0
keo,kee=0,0
for i in ch:
if i%2==0:
che+=1
else:
cho+=1
for i in ke:
if i%2==0:
kee+=1
else:
keo+=1
ans... | 1Python2 | {
"input": [
"5 1\n2 4 6 8 10\n5\n",
"1 4\n10\n20 30 40 50\n",
"5 4\n9 14 6 2 11\n8 4 7 20\n",
"4 1\n3 5 7 8\n2\n",
"5 1\n2 2 2 3 3\n3\n",
"4 1\n1 1 2 2\n2\n",
"10 10\n522312461 931001459 598654597 488228616 544064902 21923894 329635457 980089248 988262691 654502493\n967529230 543358150 83... | 2CODEFORCES |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.