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 |
|---|---|---|---|---|---|
985_E. Pencils and Boxes_2300 | Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome world, where everything is of the same color and only saturation differs. This pack can be represented as a sequence a1, a2, ..., an of n integer numbers — saturation of the color of each pencil. Now Mishka wants to ... | /*
* UMANG PANCHAL
* DAIICT
*/
import java.util.*;
import java.io.*;
import java.math.*;
import java.util.Comparator;
public class Main
{
private static final Comparator<? super Integer> Comparator = null;
static LinkedList<Integer> adj[];
static ArrayList<Integer> adj1[];
static int[] color,visited1;
stati... | 4JAVA | {
"input": [
"6 3 10\n7 2 7 7 4 2\n",
"3 2 5\n10 16 22\n",
"6 2 3\n4 5 3 13 4 10\n",
"4 2 12\n10 16 22 28\n",
"10 3 1\n5 5 5 6 6 7 8 8 8 9\n",
"8 7 13\n52 85 14 52 92 33 80 85\n",
"10 5 293149357\n79072863 760382815 358896034 663269192 233367425 32795628 837363300 46932461 179556769 763342... | 2CODEFORCES |
ac-or-cooler_2301 | This summer is very hot in KGP. As the hostel rooms do not have coolers or ACs, it's even more difficult for the students. So, the management has decided to install a cooler or an AC in some of the rooms.
There are N rooms in KGP. The management has alloted a budget of M units. There are N types of coolers and AC. But... | x,t = map(int,raw_input().strip().split())
l1 = map(int,raw_input().strip().split())
l2 = map(int,raw_input().strip().split())
l1 += l2
s = 0
c = 0
for i in sorted(l1):
if s+i < t:
s+=i
c+=1
else:
break
print c | 1Python2 | {
"input": [
"5 10\n2 5 2 2 10\n2 1 4 1 9\n\nSAMPLE",
"5 10\n2 5 2 2 10\n2 1 7 1 9\n\nSAMPLE",
"5 10\n2 8 4 2 10\n2 4 7 1 9\n\nTAMPLE",
"6 10\n2 5 1 2 0\n4 2 14 1 9\n\nDAMQLS",
"5 4\n2 6 2 2 10\n3 2 7 1 9\n\nELPMAT",
"5 4\n2 6 0 2 10\n3 2 7 1 9\n\nEMPMAT",
"5 0\n2 6 2 2 20\n2 1 4 1 9\n\nSA... | 3HACKEREARTH |
box-n-ball-1_2302 | Bozo is shifting his house. He has some balls and boxes which he has to shift. He now wonders how large a ball he can fit in a given box. Given the dimensions of a box, help Bozo determine the radius of the largest ball that he can fit in the box. Assume that an inflated ball will be spherical.
Input:-
The first line... | t = int(raw_input())
while t>0:
t-=1
list = map(float,raw_input().split())
print "{:.1f}".format(min(list)/2) | 1Python2 | {
"input": [
"3\n1 2 3\n3 3 7\n987548 4578445 9645875456\n\nSAMPLE",
"28\n754474126400970 101 196613378898208859\n380621045618581 267501121282332999 950586\n793855488118611572 865408 211106328880\n373419125 487966671162 240278042032\n366316 973 365\n592904340231516 734 44193919246935149\n76 752 536\n343780751... | 3HACKEREARTH |
cutting-the-birthday-cake_2303 | Its Alice's birthday and her friend Bob gets him a birthday cake. Its nice delicious circle shaped cake of radius R. Now they need to cut and eat that cake, so Alice fetches a cutter from her kitchen. It is a rectangular cutter of length A and breadth B that would knock of the part of the cake when the cutter is place... | def find(r,a,b):
if (a*a)+(b*b) <= 4*r*r:
print "ALICE"
else:
print "EQUAL"
if __name__ == '__main__':
t=int(raw_input())
while t>0:
(r,a,b) = map(int,raw_input().split())
find(r,a,b)
t-=1 | 1Python2 | {
"input": [
"2\n1 2 2\n1 1 1\n\nSAMPLE",
"1000\n725 248 935\n139 402 325\n383 976 540\n407 152 158\n897 369 160\n913 870 150\n931 478 19\n936 641 908\n147 117 438\n378 871 144\n860 850 235\n535 929 11\n218 584 955\n944 663 353\n903 402 811\n172 147 154\n869 294 168\n408 742 333\n769 375 118\n690 796 52\n819 ... | 3HACKEREARTH |
fun-with-primes-3_2304 | A prime number is one which is divisible by exactly two numbers 1 and itself.
Given a number, find out if the number obtained by summing all digits of that number is a prime.
Input Format:
The input begins with number of test-cases t in a single line. In each of next tlines there is a number n.
Output Format
In each ... | def isprime(number):
if number==1:
return 0
if number==2:
return 1
if number%2==0:
return 0
N=long(number**0.5)+1
for i in range(3,N,2):
if number%i==0:
return 0
return 1
for t in range(input()):
n=long(raw_input())
summ=0
while n>0:
summ=summ+n%10
n=n/10
if isprime(summ):
print "YES"
else:... | 1Python2 | {
"input": [
"2\n33\n122\n\nSAMPLE",
"2\n33\n122\n\nSAMPLD",
"2\n14\n122\n\nSAMPLD",
"2\n14\n206\n\nSAMPLD",
"2\n6\n206\n\nSAMPLD",
"2\n6\n206\n\nSAMPKD",
"2\n7\n206\n\nSAMPKD",
"2\n7\n244\n\nSAMPKD",
"2\n3\n244\n\nSAMPKD",
"2\n3\n484\n\nSAMPKD",
"2\n5\n484\n\nSAMPKD",
... | 3HACKEREARTH |
just-find-the-next-number_2305 | You are given an integer n find its next greater or equal number whose binary representation must not contain consecutive ones.
For eg. given n=6 whose binary is 110 and the next number with no consecutive ones is 8 whose binary is 1000.
INPUT
First line of input contains t, the total number of test cases. Then t l... | t=int(raw_input())
while t>0:
n=int(raw_input())
while bin(n).count("11")!=0:
n=n+1
print n
t=t-1 | 1Python2 | {
"input": [
"2\n6\n2\n\nSAMPLE",
"10\n71\n8497\n6364\n6530\n9199\n5754\n1508\n9388\n6992\n4494",
"10\n71\n8497\n6364\n6530\n9199\n5487\n1508\n9388\n6992\n4494",
"2\n6\n2\n\nELPMAS",
"10\n71\n8497\n6642\n6530\n9199\n5487\n2600\n9388\n6992\n4494",
"10\n71\n8497\n6642\n6530\n9199\n10823\n2600\n9... | 3HACKEREARTH |
minimum-coins_2306 | Ram has to pay Shyam R rupees and but the coins which he has got is of limited denomination .Assuming he has a limited knowledge of the mathematics and has unlimited number of coins of each denomination.Write a code to help Ram to pay the money using minimum number of coins .Suppose Ram has coins of {1,2} denomination ... | def min_coins(money, denoms):
# money : The money which is needed to get minimum coins
# denoms : Available denominations
denoms.sort()
min = denoms[0] * money
coin_list = {}
for j in range(len(denoms)):
temp = money
used = 0
coins = {}
for i in range(1, len(d... | 1Python2 | {
"input": [
"24\n{1,7,3}\n\nSAMPLE",
"9\n{10}",
"-19\n{10}",
"79\n{2,8}"
],
"output": [
"Rupee 1 coin 0\nRupee 3 coin 1\nRupee 7 coin 3",
"ERROR",
"ERROR",
"ERROR"
]
} | 3HACKEREARTH |
palindrome-count-1_2307 | Given a string S, count the number of non empty sub strings that are palindromes.
A sub string is any continuous sequence of characters in the string.
A string is said to be palindrome, if the reverse of the string is same as itself.
Two sub strings are different if they occur at different positions in S
Input
Input c... | def isPalindrome(s):
lf = 0
ri = len(s)-1
while lf <= ri:
if s[lf] != s[ri]:
return 0
lf += 1
ri -= 1
return 1
def getPalindromes(s):
palindromes = []
lf = 0
ri = len(s)
while lf <= ri:
subri = lf+1
while subri <= ri:
t = s[lf:subri]
if isPalindrome(t):
pal... | 1Python2 | {
"input": [
"dskjkd\n\nSAMPLE",
"wqc",
"mygrlbiadhzlabefvjtghfrtydurkpmoveczbqzzlenezq",
"wpc",
"mygrlbiadhzlabefwjtghfrtydurkpmoveczbqzzlenezq",
"dskdkj\n\nSAMPLE",
"dsjdkj\n\nELPMAQ",
"qzenelzzqbzbyvompkrudytrfigtjwfebalfhdaiblrgzm",
"rjjmem\n\nQNHQDQ",
"megrlbiadhzlabefwjtg... | 3HACKEREARTH |
rhezo-and-prime-problems_2308 | Rhezo and his friend Vanya love problem solving. They have a problem set containing N problems, with points assigned to each. Rhezo wants to solve problems in such a way that he gets the maximum number of points. Rhezo has a weird habit of solving only prime number of consecutive problems, that is, if he solves X conse... | '''
# Read input from stdin and provide input before running code
name = raw_input('What is your name?\n')
print 'Hi, %s.' % name
'''
import sys
def readline():
return sys.stdin.readline().strip()
def readInts(sep=None):
return map(int,readline().split(sep))
def readInt():
return int(readline())
def si... | 1Python2 | {
"input": [
"4\n8 1 3 7\n\nSAMPLE",
"4\n8 2 3 7\n\nSAMPLE",
"4\n8 0 3 7\n\nELPMAS",
"4\n8 0 2 7\n\nELPMAS",
"4\n8 -1 2 7\n\nELPMAS",
"4\n8 -2 2 10\n\nELPMAS",
"4\n8 -2 1 0\n\nELPMAS",
"4\n8 -3 1 0\n\nELPMAS",
"4\n1 -3 1 0\n\nELPMAS",
"4\n1 -3 1 1\n\nELPMAS",
"4\n1 -4 2 1\n... | 3HACKEREARTH |
special-sum-3_2309 | Special Sum of number N is defined as follows:
def foo(n):
{
ret = 0
for i = 1 to n:
{
if gcd(n,i) is 1:
ret += 1
}
return ret
}
def SpecialSum(N):
{
ret=0
for i = 1 to N:
{
if i divides N:
ret += foo(i)
}
return ret
}
Given a N print SpecialSum(N).
Input:... | numcases = input()
res = []
for i in range(numcases):
val = input()
res.append(val)
for i in res:
print i | 1Python2 | {
"input": [
"1\n5\n\nSAMPLE",
"1000\n84\n87\n78\n16\n94\n36\n87\n93\n50\n22\n63\n28\n91\n60\n64\n27\n41\n27\n73\n37\n12\n69\n68\n30\n83\n31\n63\n24\n68\n36\n30\n3\n23\n59\n70\n68\n94\n57\n12\n43\n30\n74\n22\n20\n85\n38\n99\n25\n16\n71\n14\n27\n92\n81\n57\n74\n63\n71\n97\n82\n6\n26\n85\n28\n37\n6\n47\n30\n14\... | 3HACKEREARTH |
trick-with-the-cards_2310 | Mr. X is performing a trick with the cards. He has N cards, lets name them 1.....N, on a round table.
So card 1 is in between 2nd card and Nth card. Initially all cards are upside down. His trick involves making all cards face up.
His trick is whenever he taps on a card, it flips (if card was originally upside down,... | test = input()
while test>0:
N = input()
if N==0:
print "0"
elif N<3:
print "1"
elif N%3==0:
print N/3
else:
print N
test = test-1 | 1Python2 | {
"input": [
"2\n2\n3\n\nSAMPLE",
"2\n2\n3\n\nSAMPME",
"2\n2\n5\n\nSAMPME",
"2\n0\n5\n\nEMPMAS",
"2\n0\n2\n\nEMPMAS",
"2\n2\n0\n\nSAMPME",
"2\n0\n0\n\nEMPMAS",
"2\n6\n5\n\nENPM@T",
"2\n0\n4\n\nSMMPAE",
"2\n11\n5\n\nENPM@T",
"2\n0\n8\n\nSMMPAE",
"2\n19\n5\n\nENPM@T",
... | 3HACKEREARTH |
p02578 AtCoder Beginner Contest 176 - Step_2311 | N persons are standing in a row. The height of the i-th person from the front is A_i.
We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person:
Condition: Nobody in front of the person is taller than the person. Here, the height of a ... | import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')
n = int(in... | 1Python2 | {
"input": [
"5\n3 3 3 3 3",
"5\n2 1 5 4 3",
"5\n1 3 3 3 3",
"5\n2 1 5 8 3",
"5\n1 2 3 6 3",
"5\n2 1 2 8 4",
"5\n2 1 2 16 6",
"5\n2 1 1 16 6",
"5\n4 4 3 6 6",
"5\n0 1 1 16 6",
"5\n4 4 3 7 6",
"5\n0 0 1 19 6",
"5\n0 0 1 19 4",
"5\n0 0 1 10 2",
"5\n0 0 1 14 0"... | 5ATCODER |
p02578 AtCoder Beginner Contest 176 - Step_2312 | N persons are standing in a row. The height of the i-th person from the front is A_i.
We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person:
Condition: Nobody in front of the person is taller than the person. Here, the height of a ... | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
ll n,ma;
cin>>n>>ma;
ll ans=0;
for(int i=1;i<n;i++){
ll x;
cin>>x;
if(ma>x)ans+=ma-x;
ma=max(ma,x);
}
cout<<ans;
return 0;
}
| 2C++ | {
"input": [
"5\n3 3 3 3 3",
"5\n2 1 5 4 3",
"5\n1 3 3 3 3",
"5\n2 1 5 8 3",
"5\n1 2 3 6 3",
"5\n2 1 2 8 4",
"5\n2 1 2 16 6",
"5\n2 1 1 16 6",
"5\n4 4 3 6 6",
"5\n0 1 1 16 6",
"5\n4 4 3 7 6",
"5\n0 0 1 19 6",
"5\n0 0 1 19 4",
"5\n0 0 1 10 2",
"5\n0 0 1 14 0"... | 5ATCODER |
p02578 AtCoder Beginner Contest 176 - Step_2313 | N persons are standing in a row. The height of the i-th person from the front is A_i.
We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person:
Condition: Nobody in front of the person is taller than the person. Here, the height of a ... | n = int(input())
m=list(map(int,input().split()))
k=0
s=0
for i in range(n):
s+=max(0,k-m[i])
k=max(k,m[i])
print(s) | 3Python3 | {
"input": [
"5\n3 3 3 3 3",
"5\n2 1 5 4 3",
"5\n1 3 3 3 3",
"5\n2 1 5 8 3",
"5\n1 2 3 6 3",
"5\n2 1 2 8 4",
"5\n2 1 2 16 6",
"5\n2 1 1 16 6",
"5\n4 4 3 6 6",
"5\n0 1 1 16 6",
"5\n4 4 3 7 6",
"5\n0 0 1 19 6",
"5\n0 0 1 19 4",
"5\n0 0 1 10 2",
"5\n0 0 1 14 0"... | 5ATCODER |
p02578 AtCoder Beginner Contest 176 - Step_2314 | N persons are standing in a row. The height of the i-th person from the front is A_i.
We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person:
Condition: Nobody in front of the person is taller than the person. Here, the height of a ... | import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner stdIn = new Scanner(System.in);
int N = stdIn.nextInt();
ArrayList<Integer> A = new ArrayList<Integer>();
for(int i = 0; i < N; i ++) {
A.add(stdIn.nextInt());
}
long stepSum = ... | 4JAVA | {
"input": [
"5\n3 3 3 3 3",
"5\n2 1 5 4 3",
"5\n1 3 3 3 3",
"5\n2 1 5 8 3",
"5\n1 2 3 6 3",
"5\n2 1 2 8 4",
"5\n2 1 2 16 6",
"5\n2 1 1 16 6",
"5\n4 4 3 6 6",
"5\n0 1 1 16 6",
"5\n4 4 3 7 6",
"5\n0 0 1 19 6",
"5\n0 0 1 19 4",
"5\n0 0 1 10 2",
"5\n0 0 1 14 0"... | 5ATCODER |
p02709 AtCoder Beginner Contest 163 - Active Infants_2315 | There are N children standing in a line from left to right. The activeness of the i-th child from the left is A_i.
You can rearrange these children just one time in any order you like.
When a child who originally occupies the x-th position from the left in the line moves to the y-th position from the left, that child... | # -*- coding: utf-8 -*-
import sys
N=int(sys.stdin.readline().strip())
A=map(int, sys.stdin.readline().split())
AA=[]
for i,val in enumerate(A):
AA.append((val,i+1))
AA.append((float("inf"),None)) #1-indexedにする
AA.sort(reverse=True)
dp=[ [ 0 for r in range(N+1) ] for l in range(N+1) ]
dp[0][0]=0
l=0
for l in r... | 1Python2 | {
"input": [
"4\n1 3 4 2",
"6\n8 6 9 1 2 1",
"6\n5 5 6 1 1 1",
"4\n1 4 4 2",
"6\n8 6 11 1 2 1",
"6\n5 5 6 0 1 1",
"4\n1 8 4 2",
"6\n8 6 22 1 2 1",
"6\n5 5 9 0 1 1",
"4\n2 8 4 2",
"6\n8 6 22 1 1 1",
"6\n5 0 9 0 1 1",
"6\n8 6 33 1 1 1",
"6\n5 0 9 0 0 1",
"4\n4... | 5ATCODER |
p02709 AtCoder Beginner Contest 163 - Active Infants_2316 | There are N children standing in a line from left to right. The activeness of the i-th child from the left is A_i.
You can rearrange these children just one time in any order you like.
When a child who originally occupies the x-th position from the left in the line moves to the y-th position from the left, that child... | #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
ll dp[2001][2001];
int main(){
ll n,A[200001];
cin>>n;
rep(i,n) cin>>A[i];
vector<P> B;
r... | 2C++ | {
"input": [
"4\n1 3 4 2",
"6\n8 6 9 1 2 1",
"6\n5 5 6 1 1 1",
"4\n1 4 4 2",
"6\n8 6 11 1 2 1",
"6\n5 5 6 0 1 1",
"4\n1 8 4 2",
"6\n8 6 22 1 2 1",
"6\n5 5 9 0 1 1",
"4\n2 8 4 2",
"6\n8 6 22 1 1 1",
"6\n5 0 9 0 1 1",
"6\n8 6 33 1 1 1",
"6\n5 0 9 0 0 1",
"4\n4... | 5ATCODER |
p02709 AtCoder Beginner Contest 163 - Active Infants_2317 | There are N children standing in a line from left to right. The activeness of the i-th child from the left is A_i.
You can rearrange these children just one time in any order you like.
When a child who originally occupies the x-th position from the left in the line moves to the y-th position from the left, that child... | N = int(input())
def solve(a, i, prev):
r = N - len(prev) - i + 1
p = -i*a
for j, s in enumerate(prev):
yield p+abs(j-i)*a, s+abs(j+r)*a
p = s
yield s+abs(len(prev)-i)*a,
pd = [0]
A = map(int, input().split())
for a,i in sorted(((a, i) for i, a in enumerate(A, 1)), reverse=True):
pd = [*map(max, sol... | 3Python3 | {
"input": [
"4\n1 3 4 2",
"6\n8 6 9 1 2 1",
"6\n5 5 6 1 1 1",
"4\n1 4 4 2",
"6\n8 6 11 1 2 1",
"6\n5 5 6 0 1 1",
"4\n1 8 4 2",
"6\n8 6 22 1 2 1",
"6\n5 5 9 0 1 1",
"4\n2 8 4 2",
"6\n8 6 22 1 1 1",
"6\n5 0 9 0 1 1",
"6\n8 6 33 1 1 1",
"6\n5 0 9 0 0 1",
"4\n4... | 5ATCODER |
p02709 AtCoder Beginner Contest 163 - Active Infants_2318 | There are N children standing in a line from left to right. The activeness of the i-th child from the left is A_i.
You can rearrange these children just one time in any order you like.
When a child who originally occupies the x-th position from the left in the line moves to the y-th position from the left, that child... | import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
Number[] numbers = new Number[N];
for (int i = 0; i < N; i++) numbers[i] = new Number(i, scanner.nextInt());
Arrays... | 4JAVA | {
"input": [
"4\n1 3 4 2",
"6\n8 6 9 1 2 1",
"6\n5 5 6 1 1 1",
"4\n1 4 4 2",
"6\n8 6 11 1 2 1",
"6\n5 5 6 0 1 1",
"4\n1 8 4 2",
"6\n8 6 22 1 2 1",
"6\n5 5 9 0 1 1",
"4\n2 8 4 2",
"6\n8 6 22 1 1 1",
"6\n5 0 9 0 1 1",
"6\n8 6 33 1 1 1",
"6\n5 0 9 0 0 1",
"4\n4... | 5ATCODER |
p02838 AtCoder Beginner Contest 147 - Xor Sum 4_2319 | We have N integers. The i-th integer is A_i.
Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).
What is \mbox{ XOR }?
The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:
* When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if eith... | #abc15047d
n=int(raw_input())
a=map(int,raw_input().split())
mod=10**9+7
res=0
for i in range(60):
cnt=sum([1 for x in a if (x>>i & 1)])
res+=cnt*(n-cnt)*(1<<i)
res=res%mod
print res
| 1Python2 | {
"input": [
"3\n1 2 3",
"10\n3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820",
"10\n3 1 4 1 5 9 2 6 5 3",
"3\n1 2 1",
"10\n1 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820",
"10\n3 1 4 1 5 9 2 6 5 6",
"3\n1 4 1",
"10\n1 14 159 2653 58979 376446 2643383... | 5ATCODER |
p02838 AtCoder Beginner Contest 147 - Xor Sum 4_2320 | We have N integers. The i-th integer is A_i.
Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).
What is \mbox{ XOR }?
The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:
* When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if eith... | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
int main() {
int N; cin >> N;
vector<ll> A(N);
ll ans = 0LL;
for(int i = 0; i < N; i++) cin >> A[i];
for(int i = 0; i < 60; i++) {
ll t = 0;
for(int j = 0; j < N; j++) {
... | 2C++ | {
"input": [
"3\n1 2 3",
"10\n3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820",
"10\n3 1 4 1 5 9 2 6 5 3",
"3\n1 2 1",
"10\n1 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820",
"10\n3 1 4 1 5 9 2 6 5 6",
"3\n1 4 1",
"10\n1 14 159 2653 58979 376446 2643383... | 5ATCODER |
p02838 AtCoder Beginner Contest 147 - Xor Sum 4_2321 | We have N integers. The i-th integer is A_i.
Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).
What is \mbox{ XOR }?
The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:
* When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if eith... | n=int(input())
mod=10**9+7;ans=0
a=list(map(int,input().split()))
for i in range(61):
checkbit=1 << i
cnt=sum([1 for j in a if j & checkbit])
ans+=checkbit*cnt*(n-cnt)
ans%=mod
print(ans)
| 3Python3 | {
"input": [
"3\n1 2 3",
"10\n3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820",
"10\n3 1 4 1 5 9 2 6 5 3",
"3\n1 2 1",
"10\n1 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820",
"10\n3 1 4 1 5 9 2 6 5 6",
"3\n1 4 1",
"10\n1 14 159 2653 58979 376446 2643383... | 5ATCODER |
p02838 AtCoder Beginner Contest 147 - Xor Sum 4_2322 | We have N integers. The i-th integer is A_i.
Find \sum_{i=1}^{N-1}\sum_{j=i+1}^{N} (A_i \mbox{ XOR } A_j), modulo (10^9+7).
What is \mbox{ XOR }?
The XOR of integers A and B, A \mbox{ XOR } B, is defined as follows:
* When A \mbox{ XOR } B is written in base two, the digit in the 2^k's place (k \geq 0) is 1 if eith... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual soluti... | 4JAVA | {
"input": [
"3\n1 2 3",
"10\n3 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820",
"10\n3 1 4 1 5 9 2 6 5 3",
"3\n1 2 1",
"10\n1 14 159 2653 58979 323846 2643383 27950288 419716939 9375105820",
"10\n3 1 4 1 5 9 2 6 5 6",
"3\n1 4 1",
"10\n1 14 159 2653 58979 376446 2643383... | 5ATCODER |
p02975 AtCoder Grand Contest 035 - XOR Circle_2323 | Snuke has N hats. The i-th hat has an integer a_i written on it.
There are N camels standing in a circle. Snuke will put one of his hats on each of these camels.
If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print `Yes`; otherwise, print `No... | n = input()
dic = {}
for i in map(int, raw_input().split()):
if i in dic:
dic[i] += 1
else:
dic[i] = 1
if len(dic) > 3:
print "No"
elif len(dic) == 3:
vals = []
for i in dic:
vals.append(i)
if vals[0]^vals[2] != vals[1] or vals[1]^vals[0] != vals[2] or vals[0] != vals[1]^vals[2]:
print "No"
elif max(dic.... | 1Python2 | {
"input": [
"3\n1 2 3",
"4\n1 2 4 8",
"3\n1 2 0",
"3\n3 2 1",
"4\n1 2 4 11",
"3\n0 2 0",
"4\n0 2 4 11",
"3\n0 1 0",
"4\n0 4 4 11",
"3\n0 1 -1",
"4\n0 4 4 20",
"3\n1 2 1",
"4\n0 4 1 20",
"3\n2 2 1",
"4\n0 4 1 33",
"4\n0 4 1 63",
"3\n3 4 1",
"4\n0... | 5ATCODER |
p02975 AtCoder Grand Contest 035 - XOR Circle_2324 | Snuke has N hats. The i-th hat has an integer a_i written on it.
There are N camels standing in a circle. Snuke will put one of his hats on each of these camels.
If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print `Yes`; otherwise, print `No... | #include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
using ll = long long;
using ld = long double;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
int x = 0;
vector<int> a(n);
for (int& i : a) cin >> i, x ^= i;
puts(x == 0 ? "Yes" : "No");
return 0;
}
| 2C++ | {
"input": [
"3\n1 2 3",
"4\n1 2 4 8",
"3\n1 2 0",
"3\n3 2 1",
"4\n1 2 4 11",
"3\n0 2 0",
"4\n0 2 4 11",
"3\n0 1 0",
"4\n0 4 4 11",
"3\n0 1 -1",
"4\n0 4 4 20",
"3\n1 2 1",
"4\n0 4 1 20",
"3\n2 2 1",
"4\n0 4 1 33",
"4\n0 4 1 63",
"3\n3 4 1",
"4\n0... | 5ATCODER |
p02975 AtCoder Grand Contest 035 - XOR Circle_2325 | Snuke has N hats. The i-th hat has an integer a_i written on it.
There are N camels standing in a circle. Snuke will put one of his hats on each of these camels.
If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print `Yes`; otherwise, print `No... | _, *a = map(int, open(0).read().split());z = 0
for b in a:z ^= b
print("YNeos"[z>0::2]) | 3Python3 | {
"input": [
"3\n1 2 3",
"4\n1 2 4 8",
"3\n1 2 0",
"3\n3 2 1",
"4\n1 2 4 11",
"3\n0 2 0",
"4\n0 2 4 11",
"3\n0 1 0",
"4\n0 4 4 11",
"3\n0 1 -1",
"4\n0 4 4 20",
"3\n1 2 1",
"4\n0 4 1 20",
"3\n2 2 1",
"4\n0 4 1 33",
"4\n0 4 1 63",
"3\n3 4 1",
"4\n0... | 5ATCODER |
p02975 AtCoder Grand Contest 035 - XOR Circle_2326 | Snuke has N hats. The i-th hat has an integer a_i written on it.
There are N camels standing in a circle. Snuke will put one of his hats on each of these camels.
If there exists a way to distribute the hats to the camels such that the following condition is satisfied for every camel, print `Yes`; otherwise, print `No... | import java.util.*;
import java.io.*;
public class Main {
public static void main(String[] args) {
FastScanner sc = new FastScanner();
int n = sc.nextInt();
long[] a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
}
long[] cnt = new long... | 4JAVA | {
"input": [
"3\n1 2 3",
"4\n1 2 4 8",
"3\n1 2 0",
"3\n3 2 1",
"4\n1 2 4 11",
"3\n0 2 0",
"4\n0 2 4 11",
"3\n0 1 0",
"4\n0 4 4 11",
"3\n0 1 -1",
"4\n0 4 4 20",
"3\n1 2 1",
"4\n0 4 1 20",
"3\n2 2 1",
"4\n0 4 1 33",
"4\n0 4 1 63",
"3\n3 4 1",
"4\n0... | 5ATCODER |
p03111 AtCoder Beginner Contest 119 - Synthetic Kadomatsu_2327 | You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:
* Extension Magic: Consumes 1 MP (magic point).... | # -*- coding: utf-8 -*-
import itertools
from collections import Counter
N,A,B,C=map(int,raw_input().split())
ORG=[A,B,C]
ORG.sort(reverse=True)
L=[ input() for i in range(N) ]
L.sort()
P=[]
for i in itertools.product(range(4), repeat=N): #a:0 , b:1 , c:2 , unused:3
P.append(i) #Permutation
ans=float("inf")
f... | 1Python2 | {
"input": [
"8 1000 800 100\n300\n333\n400\n444\n500\n555\n600\n666",
"5 100 90 80\n98\n40\n30\n21\n80",
"8 100 90 80\n100\n100\n90\n90\n90\n80\n80\n80",
"8 1100 800 100\n300\n333\n400\n444\n500\n555\n600\n666",
"5 100 171 80\n98\n40\n30\n21\n80",
"8 100 90 80\n100\n100\n90\n90\n90\n80\n80\n2... | 5ATCODER |
p03111 AtCoder Beginner Contest 119 - Synthetic Kadomatsu_2328 | You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:
* Extension Magic: Consumes 1 MP (magic point).... | #include <bits/stdc++.h>
using namespace std;
int INF=10000000;
int N,A,B,C;
vector<int> L;
int rec(int i, int a, int b, int c){
if(i==N){
if(!a||!b||!c) return INF;
return abs(a-A)+abs(b-B)+abs(c-C);
}
int res=rec(i+1,a,b,c);
res=min(res, rec(i+1, a + L[i], b, c) + (a ? 10 : 0));... | 2C++ | {
"input": [
"8 1000 800 100\n300\n333\n400\n444\n500\n555\n600\n666",
"5 100 90 80\n98\n40\n30\n21\n80",
"8 100 90 80\n100\n100\n90\n90\n90\n80\n80\n80",
"8 1100 800 100\n300\n333\n400\n444\n500\n555\n600\n666",
"5 100 171 80\n98\n40\n30\n21\n80",
"8 100 90 80\n100\n100\n90\n90\n90\n80\n80\n2... | 5ATCODER |
p03111 AtCoder Beginner Contest 119 - Synthetic Kadomatsu_2329 | You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:
* Extension Magic: Consumes 1 MP (magic point).... | n,a,b,c=map(int,input().split())
l=[int(input()) for _ in range(n)]
def dfs(i,x,y,z):
if i==n:
return abs(x-a)+abs(y-b)+abs(z-c) if x*y*z else 10**9
r1 = dfs(i+1,x+l[i],y,z)+ (10 if x>0 else 0)
r2 = dfs(i+1,x,y+l[i],z)+ (10 if y>0 else 0)
r3 = dfs(i+1,x,y,z+l[i])+ (10 if z>0 else 0)
r4 = dfs(i+1,x,y,z)
... | 3Python3 | {
"input": [
"8 1000 800 100\n300\n333\n400\n444\n500\n555\n600\n666",
"5 100 90 80\n98\n40\n30\n21\n80",
"8 100 90 80\n100\n100\n90\n90\n90\n80\n80\n80",
"8 1100 800 100\n300\n333\n400\n444\n500\n555\n600\n666",
"5 100 171 80\n98\n40\n30\n21\n80",
"8 100 90 80\n100\n100\n90\n90\n90\n80\n80\n2... | 5ATCODER |
p03111 AtCoder Beginner Contest 119 - Synthetic Kadomatsu_2330 | You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of magics any number:
* Extension Magic: Consumes 1 MP (magic point).... | import java.io.*;
import java.util.*;
import java.util.Map.Entry;
public class Main {
final boolean isDebug = false;
String fileName = "input.txt";
FastScanner sc;
//PrintWriter out;
final int MOD = (int)1e9+7;
final int INF = Integer.MAX_VALUE / 2;
/* solve */
void solve(){
int N = sc.nextInt();
int A... | 4JAVA | {
"input": [
"8 1000 800 100\n300\n333\n400\n444\n500\n555\n600\n666",
"5 100 90 80\n98\n40\n30\n21\n80",
"8 100 90 80\n100\n100\n90\n90\n90\n80\n80\n80",
"8 1100 800 100\n300\n333\n400\n444\n500\n555\n600\n666",
"5 100 171 80\n98\n40\n30\n21\n80",
"8 100 90 80\n100\n100\n90\n90\n90\n80\n80\n2... | 5ATCODER |
p03258 AtCoder Grand Contest 027 - ABBreviate_2331 | There is a string s consisting of `a` and `b`. Snuke can perform the following two kinds of operation any number of times in any order:
* Choose an occurrence of `aa` as a substring, and replace it with `b`.
* Choose an occurrence of `bb` as a substring, and replace it with `a`.
How many strings s can be obtained b... | #include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
const int P = 1e9 + 7;
typedef long long ll;
template <typename T> void read(T &x) {
x = 0; int f = 1;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
x *= f;
... | 2C++ | {
"input": [
"babbabaaba",
"ababababa",
"aaaa",
"aabb",
"babbaababa",
"bbabababa",
"aaba",
"ababbbaba",
"baba",
"ababbbbba",
"abbabbaba",
"abaababbab",
"abaaababa",
"baabaababa",
"bbabaabbab",
"ababbbabb",
"aaab",
"abaabbaba",
"abaaaabbab",
... | 5ATCODER |
p03258 AtCoder Grand Contest 027 - ABBreviate_2332 | There is a string s consisting of `a` and `b`. Snuke can perform the following two kinds of operation any number of times in any order:
* Choose an occurrence of `aa` as a substring, and replace it with `b`.
* Choose an occurrence of `bb` as a substring, and replace it with `a`.
How many strings s can be obtained b... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual soluti... | 4JAVA | {
"input": [
"babbabaaba",
"ababababa",
"aaaa",
"aabb",
"babbaababa",
"bbabababa",
"aaba",
"ababbbaba",
"baba",
"ababbbbba",
"abbabbaba",
"abaababbab",
"abaaababa",
"baabaababa",
"bbabaabbab",
"ababbbabb",
"aaab",
"abaabbaba",
"abaaaabbab",
... | 5ATCODER |
p03414 AtCoder Regular Contest 092 - Two Faced Edges_2333 | You are given a directed graph with N vertices and M edges. The vertices are numbered 1, 2, ..., N, and the edges are numbered 1, 2, ..., M. Edge i points from Vertex a_i to Vertex b_i.
For each edge, determine whether the reversion of that edge would change the number of the strongly connected components in the graph... | #include<bits/stdc++.h>
using namespace std;
using Int = signed;
//INSERT ABOVE HERE
Int dp[2][1010][1010];
Int pv[1010][1010];
signed main(){
Int n,m;
cin>>n>>m;
vector<Int> a(m),b(m);
for(Int i=0;i<m;i++) cin>>a[i]>>b[i],a[i]--,b[i]--;
vector<vector<Int> > G(n);
for(Int i=0;i<m;i++) G[a[i]].emplace_back(... | 2C++ | {
"input": [
"2 2\n1 2\n2 1",
"5 9\n3 2\n3 1\n4 1\n4 2\n3 5\n5 3\n3 4\n1 2\n2 5",
"3 3\n1 2\n1 3\n2 3",
"5 9\n5 2\n3 1\n4 1\n4 2\n3 5\n5 3\n3 4\n1 2\n2 5",
"3 2\n1 2\n1 3\n2 3",
"6 3\n1 2\n1 3\n2 3",
"5 9\n3 2\n3 1\n4 1\n4 2\n3 5\n5 3\n5 4\n1 2\n4 5",
"3 2\n1 2\n2 1",
"6 3\n1 2\n1 ... | 5ATCODER |
p03414 AtCoder Regular Contest 092 - Two Faced Edges_2334 | You are given a directed graph with N vertices and M edges. The vertices are numbered 1, 2, ..., N, and the edges are numbered 1, 2, ..., M. Edge i points from Vertex a_i to Vertex b_i.
For each edge, determine whether the reversion of that edge would change the number of the strongly connected components in the graph... | import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Set;
public class Main {
static InputStream is;
static PrintWriter out;
static String ... | 4JAVA | {
"input": [
"2 2\n1 2\n2 1",
"5 9\n3 2\n3 1\n4 1\n4 2\n3 5\n5 3\n3 4\n1 2\n2 5",
"3 3\n1 2\n1 3\n2 3",
"5 9\n5 2\n3 1\n4 1\n4 2\n3 5\n5 3\n3 4\n1 2\n2 5",
"3 2\n1 2\n1 3\n2 3",
"6 3\n1 2\n1 3\n2 3",
"5 9\n3 2\n3 1\n4 1\n4 2\n3 5\n5 3\n5 4\n1 2\n4 5",
"3 2\n1 2\n2 1",
"6 3\n1 2\n1 ... | 5ATCODER |
p03574 AtCoder Beginner Contest 075 - Minesweeper_2335 | You are given an H × W grid.
The squares in the grid are described by H strings, S_1,...,S_H.
The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W).
`.` stands for an empty square, and `#` stands for a square containin... | import sys
H, W = map(int, raw_input().split())
S = [raw_input() for i in range(H)]
C = [[0] * W for i in range(H)]
for i in range(H):
for j in range(W):
for di in range(-1, 2):
if i + di < 0 or H <= i + di:
continue
for dj in range(-1, 2):
if j + dj <... | 1Python2 | {
"input": [
"3 5\n.....\n.#.#.\n.....",
"3 5",
"6 6\n.\n.#.##\n.#\n.#..#.\n.##..\n.#...",
"3 7\n.....\n.#.#.\n.....",
"6 8\n.\n.#.##\n.#\n.#..#.\n.##..\n.#...",
"12 8\n.\n.#.##\n.#\n.#..#.\n.##..\n.#...",
"11 6\n.\n.#.##\n.#\n.#..#.\n.##..\n.#...",
"2 5\n.....\n.#.#.\n.....",
"21 ... | 5ATCODER |
p03574 AtCoder Beginner Contest 075 - Minesweeper_2336 | You are given an H × W grid.
The squares in the grid are described by H strings, S_1,...,S_H.
The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W).
`.` stands for an empty square, and `#` stands for a square containin... | #include <iostream>
#include <string>
using namespace std;
int h, w;
string s[50];
int main() {
int i, j, di, dj;
cin >> h >> w;
for (i = 0; i < h; i++) cin >> s[i];
for (i = 0; i < h; i++) {
for (j = 0; j < w; j++) {
if (s[i][j] == '#') { cout << '#'; continue; }
int cnt = 0;
for (di = -1; di ... | 2C++ | {
"input": [
"3 5\n.....\n.#.#.\n.....",
"3 5",
"6 6\n.\n.#.##\n.#\n.#..#.\n.##..\n.#...",
"3 7\n.....\n.#.#.\n.....",
"6 8\n.\n.#.##\n.#\n.#..#.\n.##..\n.#...",
"12 8\n.\n.#.##\n.#\n.#..#.\n.##..\n.#...",
"11 6\n.\n.#.##\n.#\n.#..#.\n.##..\n.#...",
"2 5\n.....\n.#.#.\n.....",
"21 ... | 5ATCODER |
p03574 AtCoder Beginner Contest 075 - Minesweeper_2337 | You are given an H × W grid.
The squares in the grid are described by H strings, S_1,...,S_H.
The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W).
`.` stands for an empty square, and `#` stands for a square containin... | h,w = map(int,input().split())
grid = ["."*(w+2)]+["."+input()+"." for _ in range(h)]+["."*(w+2)]
for y in range(1,h+1):
for x in range(1,w+1):
if grid[y][x]=="#":
print("#",end="")
else:
print(sum(grid[i][j]=="#" for i in range(y-1,y+2) for j in range(x-1,x+2)),end="")
print("") | 3Python3 | {
"input": [
"3 5\n.....\n.#.#.\n.....",
"3 5",
"6 6\n.\n.#.##\n.#\n.#..#.\n.##..\n.#...",
"3 7\n.....\n.#.#.\n.....",
"6 8\n.\n.#.##\n.#\n.#..#.\n.##..\n.#...",
"12 8\n.\n.#.##\n.#\n.#..#.\n.##..\n.#...",
"11 6\n.\n.#.##\n.#\n.#..#.\n.##..\n.#...",
"2 5\n.....\n.#.#.\n.....",
"21 ... | 5ATCODER |
p03574 AtCoder Beginner Contest 075 - Minesweeper_2338 | You are given an H × W grid.
The squares in the grid are described by H strings, S_1,...,S_H.
The j-th character in the string S_i corresponds to the square at the i-th row from the top and j-th column from the left (1 \leq i \leq H,1 \leq j \leq W).
`.` stands for an empty square, and `#` stands for a square containin... | import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int X = Integer.parseInt(sc.next());
int Y = Integer.parseInt(sc.next());
char S[][] = new char[50][50];
for(int x = 0; x < X; x++){
String s =... | 4JAVA | {
"input": [
"3 5\n.....\n.#.#.\n.....",
"3 5",
"6 6\n.\n.#.##\n.#\n.#..#.\n.##..\n.#...",
"3 7\n.....\n.#.#.\n.....",
"6 8\n.\n.#.##\n.#\n.#..#.\n.##..\n.#...",
"12 8\n.\n.#.##\n.#\n.#..#.\n.##..\n.#...",
"11 6\n.\n.#.##\n.#\n.#..#.\n.##..\n.#...",
"2 5\n.....\n.#.#.\n.....",
"21 ... | 5ATCODER |
p03729 AtCoder Beginner Contest 060 - Shiritori_2339 | You are given three strings A, B and C. Check whether they form a word chain.
More formally, determine whether both of the following are true:
* The last character in A and the initial character in B are the same.
* The last character in B and the initial character in C are the same.
If both are true, print `YES`.... | a,b,c = raw_input().split()
if a[-1] == b[0] and b[-1] == c[0]:
print("YES")
else:
print("NO") | 1Python2 | {
"input": [
"a a a",
"rng gorilla apple",
"aaaaaaaaab aaaaaaaaaa aaaaaaaaab",
"yakiniku unagi sushi",
"a a `",
"baaaa`aaaa aabaaaaaaa aaaaa`aaab",
"rnh gorilla apple",
"aaaaaaaaab aaaaaaaaaa aaaaa`aaab",
"ybkiniku unagi sushi",
"a b a",
"rng gorilla paple",
"aaaaaaaaab... | 5ATCODER |
p03729 AtCoder Beginner Contest 060 - Shiritori_2340 | You are given three strings A, B and C. Check whether they form a word chain.
More formally, determine whether both of the following are true:
* The last character in A and the initial character in B are the same.
* The last character in B and the initial character in C are the same.
If both are true, print `YES`.... | #include <bits/stdc++.h>
using namespace std;
int main() {
string a, b, c;
cin >> a >> b >> c;
cout << ((a[a.size()-1] == b[0] && b[b.size()-1] == c[0]) ? "YES" : "NO") << "\n";
return(0);
} | 2C++ | {
"input": [
"a a a",
"rng gorilla apple",
"aaaaaaaaab aaaaaaaaaa aaaaaaaaab",
"yakiniku unagi sushi",
"a a `",
"baaaa`aaaa aabaaaaaaa aaaaa`aaab",
"rnh gorilla apple",
"aaaaaaaaab aaaaaaaaaa aaaaa`aaab",
"ybkiniku unagi sushi",
"a b a",
"rng gorilla paple",
"aaaaaaaaab... | 5ATCODER |
p03729 AtCoder Beginner Contest 060 - Shiritori_2341 | You are given three strings A, B and C. Check whether they form a word chain.
More formally, determine whether both of the following are true:
* The last character in A and the initial character in B are the same.
* The last character in B and the initial character in C are the same.
If both are true, print `YES`.... | S = input().split()
print('YES' if S[0][-1] == S[1][0] and S[1][-1] == S[2][0] else 'NO') | 3Python3 | {
"input": [
"a a a",
"rng gorilla apple",
"aaaaaaaaab aaaaaaaaaa aaaaaaaaab",
"yakiniku unagi sushi",
"a a `",
"baaaa`aaaa aabaaaaaaa aaaaa`aaab",
"rnh gorilla apple",
"aaaaaaaaab aaaaaaaaaa aaaaa`aaab",
"ybkiniku unagi sushi",
"a b a",
"rng gorilla paple",
"aaaaaaaaab... | 5ATCODER |
p03729 AtCoder Beginner Contest 060 - Shiritori_2342 | You are given three strings A, B and C. Check whether they form a word chain.
More formally, determine whether both of the following are true:
* The last character in A and the initial character in B are the same.
* The last character in B and the initial character in C are the same.
If both are true, print `YES`.... | import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String a = sc.next();
String b = sc.next();
String c = sc.n... | 4JAVA | {
"input": [
"a a a",
"rng gorilla apple",
"aaaaaaaaab aaaaaaaaaa aaaaaaaaab",
"yakiniku unagi sushi",
"a a `",
"baaaa`aaaa aabaaaaaaa aaaaa`aaab",
"rnh gorilla apple",
"aaaaaaaaab aaaaaaaaaa aaaaa`aaab",
"ybkiniku unagi sushi",
"a b a",
"rng gorilla paple",
"aaaaaaaaab... | 5ATCODER |
p03893 CODE FESTIVAL 2016 Relay (Parallel) - Trichotomy_2343 | We have a cord whose length is a positive integer. We will perform the following condition until the length of the cord becomes at most 2:
* Operation: Cut the rope at two positions to obtain three cords, each with a length of a positive integer. Among these, discard one with the longest length and one with the shorte... | x = input()
N = 1
ans = 7
while x > N:
ans = 1 + ans*2
x -= 1
print ans-1
| 1Python2 | {
"input": [
"2",
"3",
"1",
"6",
"4",
"8",
"10",
"9",
"16",
"11",
"18",
"31",
"7",
"43",
"15",
"20",
"5",
"26",
"38",
"13",
"17",
"23",
"12",
"19",
"33",
"24",
"21",
"51",
"44",
"32",
"37",
... | 5ATCODER |
p03893 CODE FESTIVAL 2016 Relay (Parallel) - Trichotomy_2344 | We have a cord whose length is a positive integer. We will perform the following condition until the length of the cord becomes at most 2:
* Operation: Cut the rope at two positions to obtain three cords, each with a length of a positive integer. Among these, discard one with the longest length and one with the shorte... | #include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int n;
long long f[400];
int main()
{
scanf("%d",&n);
f[0]=2;
for(int i=0;i<=n;i++)
f[i]=f[i-1]*2+2;
printf("%lld\n",f[n]);
return 0;
} | 2C++ | {
"input": [
"2",
"3",
"1",
"6",
"4",
"8",
"10",
"9",
"16",
"11",
"18",
"31",
"7",
"43",
"15",
"20",
"5",
"26",
"38",
"13",
"17",
"23",
"12",
"19",
"33",
"24",
"21",
"51",
"44",
"32",
"37",
... | 5ATCODER |
p03893 CODE FESTIVAL 2016 Relay (Parallel) - Trichotomy_2345 | We have a cord whose length is a positive integer. We will perform the following condition until the length of the cord becomes at most 2:
* Operation: Cut the rope at two positions to obtain three cords, each with a length of a positive integer. Among these, discard one with the longest length and one with the shorte... | x=int(input())
l,r=0,100000000000000
while r-l>1:
m=(l+r)//2
t=m
cnt=0
while m>2:
cnt+=1
m=(m-1)//2
if cnt>x:
r=t
else:
l=t
print(l) | 3Python3 | {
"input": [
"2",
"3",
"1",
"6",
"4",
"8",
"10",
"9",
"16",
"11",
"18",
"31",
"7",
"43",
"15",
"20",
"5",
"26",
"38",
"13",
"17",
"23",
"12",
"19",
"33",
"24",
"21",
"51",
"44",
"32",
"37",
... | 5ATCODER |
p03893 CODE FESTIVAL 2016 Relay (Parallel) - Trichotomy_2346 | We have a cord whose length is a positive integer. We will perform the following condition until the length of the cord becomes at most 2:
* Operation: Cut the rope at two positions to obtain three cords, each with a length of a positive integer. Among these, discard one with the longest length and one with the shorte... | import java.util.*;
class Main {
public static void main(String args[]) {
try (Scanner sc = new Scanner(System.in)) {
int X = sc.nextInt();
long ans = 2;
for (int i = X; i > 0; i--) {
ans = a... | 4JAVA | {
"input": [
"2",
"3",
"1",
"6",
"4",
"8",
"10",
"9",
"16",
"11",
"18",
"31",
"7",
"43",
"15",
"20",
"5",
"26",
"38",
"13",
"17",
"23",
"12",
"19",
"33",
"24",
"21",
"51",
"44",
"32",
"37",
... | 5ATCODER |
p04052 AtCoder Grand Contest 001 - Wide Swap_2347 | You are given a permutation P_1 ... P_N of the set {1, 2, ..., N}.
You can apply the following operation to this permutation, any number of times (possibly zero):
* Choose two indices i,j (1 ≦ i < j ≦ N), such that j - i ≧ K and |P_i - P_j| = 1. Then, swap the values of P_i and P_j.
Among all permutations that can... | #include <bits/stdc++.h>
using namespace std;
int n,k,cnt,a[1000005];
vector<int>v[1000005];
map<int,int>mp;
void dfs(int x)
{
for(int i=0;i<v[x].size();i++)
dfs(v[x][i]);
cnt++;
a[x]=cnt;
}
int main()
{
cin>>n>>k;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=n;i++)
{
if(i>k)
mp.erase(a[i-k]);
... | 2C++ | {
"input": [
"8 3\n4 5 7 8 3 1 2 6",
"5 1\n5 4 3 2 1",
"4 2\n4 2 3 1",
"4 4\n4 2 3 1",
"5 2\n5 4 3 2 1",
"4 1\n4 2 3 1",
"8 2\n4 5 7 8 3 1 2 6",
"4 2\n4 3 2 1",
"8 6\n4 5 7 8 3 1 2 6",
"8 5\n4 5 7 8 3 1 2 6",
"8 1\n4 5 7 8 3 1 2 6",
"8 4\n4 5 7 8 3 1 2 6",
"4 3\n4 1... | 5ATCODER |
p04052 AtCoder Grand Contest 001 - Wide Swap_2348 | You are given a permutation P_1 ... P_N of the set {1, 2, ..., N}.
You can apply the following operation to this permutation, any number of times (possibly zero):
* Choose two indices i,j (1 ≦ i < j ≦ N), such that j - i ≧ K and |P_i - P_j| = 1. Then, swap the values of P_i and P_j.
Among all permutations that can... | def invert(p, q):
for i, pi in enumerate(p): q[pi] = i
def sort_insertion(k, data, first, last):
length = last - first
if length <= 2:
if length == 2 and data[first] - data[first + 1] >= k:
data[first], data[first + 1] = data[first + 1], data[first]
return
for i in range(fir... | 3Python3 | {
"input": [
"8 3\n4 5 7 8 3 1 2 6",
"5 1\n5 4 3 2 1",
"4 2\n4 2 3 1",
"4 4\n4 2 3 1",
"5 2\n5 4 3 2 1",
"4 1\n4 2 3 1",
"8 2\n4 5 7 8 3 1 2 6",
"4 2\n4 3 2 1",
"8 6\n4 5 7 8 3 1 2 6",
"8 5\n4 5 7 8 3 1 2 6",
"8 1\n4 5 7 8 3 1 2 6",
"8 4\n4 5 7 8 3 1 2 6",
"4 3\n4 1... | 5ATCODER |
p04052 AtCoder Grand Contest 001 - Wide Swap_2349 | You are given a permutation P_1 ... P_N of the set {1, 2, ..., N}.
You can apply the following operation to this permutation, any number of times (possibly zero):
* Choose two indices i,j (1 ≦ i < j ≦ N), such that j - i ≧ K and |P_i - P_j| = 1. Then, swap the values of P_i and P_j.
Among all permutations that can... |
import java.util.*;
public class Main {
static boolean[] vis;
static SegTree seg;
static int n, k;
static int idx = 0;
static int[] ans;
static int[] p;
static int[] q;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
k = sc.nextInt();
p = new int[n];
... | 4JAVA | {
"input": [
"8 3\n4 5 7 8 3 1 2 6",
"5 1\n5 4 3 2 1",
"4 2\n4 2 3 1",
"4 4\n4 2 3 1",
"5 2\n5 4 3 2 1",
"4 1\n4 2 3 1",
"8 2\n4 5 7 8 3 1 2 6",
"4 2\n4 3 2 1",
"8 6\n4 5 7 8 3 1 2 6",
"8 5\n4 5 7 8 3 1 2 6",
"8 1\n4 5 7 8 3 1 2 6",
"8 4\n4 5 7 8 3 1 2 6",
"4 3\n4 1... | 5ATCODER |
p00131 Doctor's Strange Particles_2350 | Dr .: Peter. I did.
Peter: See you again? What kind of silly invention is this time?
Dr .: You invented the detector for that phantom elementary particle axion.
Peter: Speaking of Axion, researchers such as the European Organization for Nuclear Research (CERN) are chasing with a bloody eye, aren't they? Is that true... | L = [(512,768,512)] + [(256>>i,896>>i,256>>i) for i in xrange(9)]
def put(f,x,y):
for yy,b in zip(xrange(y-1,y+2),L[x]):
f[yy] = f[yy] ^ b
def solve(F):
for i in xrange(1<<10):
f = [0] + F + [0]
ret = []
for x in (x for x in xrange(10) if 1<<x & i != 0):
put(f,x,1)
... | 1Python2 | {
"input": [
"1\n0 1 0 0 0 0 0 0 0 0\n1 1 1 0 0 0 0 0 0 0\n0 1 0 0 0 0 0 0 0 0\n0 0 0 0 1 1 0 0 0 0\n0 0 0 1 0 0 1 0 0 0\n0 0 0 0 1 1 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 1 0\n0 0 0 0 0 0 0 1 1 1\n0 0 0 0 0 0 0 0 1 0",
"1\n0 1 0 0 0 0 0 0 0 0\n1 1 1 0 0 0 0 0 0 0\n0 1 0 0 0 0 0 0 0 0\n0 0 0 0 0 1 0 0... | 6AIZU |
p00131 Doctor's Strange Particles_2351 | Dr .: Peter. I did.
Peter: See you again? What kind of silly invention is this time?
Dr .: You invented the detector for that phantom elementary particle axion.
Peter: Speaking of Axion, researchers such as the European Organization for Nuclear Research (CERN) are chasing with a bloody eye, aren't they? Is that true... | #include <iostream>
#include <algorithm>
using namespace std;
const int H = 10;
const int W = 10;
int G[H][W];
int ans[H][W];
void put(int i, int j) {
const static int di[5] = {0,1,0,-1,0};
const static int dj[5] = {1,0,-1,0,0};
for(int k = 0; k < 5; ++k) {
int ni = i + di[k];
int nj = j + dj[k];
if... | 2C++ | {
"input": [
"1\n0 1 0 0 0 0 0 0 0 0\n1 1 1 0 0 0 0 0 0 0\n0 1 0 0 0 0 0 0 0 0\n0 0 0 0 1 1 0 0 0 0\n0 0 0 1 0 0 1 0 0 0\n0 0 0 0 1 1 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 1 0\n0 0 0 0 0 0 0 1 1 1\n0 0 0 0 0 0 0 0 1 0",
"1\n0 1 0 0 0 0 0 0 0 0\n1 1 1 0 0 0 0 0 0 0\n0 1 0 0 0 0 0 0 0 0\n0 0 0 0 0 1 0 0... | 6AIZU |
p00131 Doctor's Strange Particles_2352 | Dr .: Peter. I did.
Peter: See you again? What kind of silly invention is this time?
Dr .: You invented the detector for that phantom elementary particle axion.
Peter: Speaking of Axion, researchers such as the European Organization for Nuclear Research (CERN) are chasing with a bloody eye, aren't they? Is that true... | def attack(table, i, j):
table[i][j] = 1 - table[i][j]
table[i-1][j] = 1 - table[i-1][j]
table[i+1][j] = 1 - table[i+1][j]
table[i][j-1] = 1 - table[i][j-1]
table[i][j+1] = 1 - table[i][j+1]
def printans(ans):
for i in range(1, 11):
for j in range(1, 11):
print(ans[i][j], en... | 3Python3 | {
"input": [
"1\n0 1 0 0 0 0 0 0 0 0\n1 1 1 0 0 0 0 0 0 0\n0 1 0 0 0 0 0 0 0 0\n0 0 0 0 1 1 0 0 0 0\n0 0 0 1 0 0 1 0 0 0\n0 0 0 0 1 1 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 1 0\n0 0 0 0 0 0 0 1 1 1\n0 0 0 0 0 0 0 0 1 0",
"1\n0 1 0 0 0 0 0 0 0 0\n1 1 1 0 0 0 0 0 0 0\n0 1 0 0 0 0 0 0 0 0\n0 0 0 0 0 1 0 0... | 6AIZU |
p00131 Doctor's Strange Particles_2353 | Dr .: Peter. I did.
Peter: See you again? What kind of silly invention is this time?
Dr .: You invented the detector for that phantom elementary particle axion.
Peter: Speaking of Axion, researchers such as the European Organization for Nuclear Research (CERN) are chasing with a bloody eye, aren't they? Is that true... | import java.util.*;
public class Main {
int[] dy = {0,0,1,-1,0};
int[] dx = {1,-1,0,0,0};
void run(){
Scanner in = new Scanner(System.in);
for(int n=in.nextInt(); n-- > 0; ){
boolean[][] board = new boolean[10][10];
for(int i=0; i<10; i++){
for(int j=0; j<10; j++){
int x = in.nextInt();
bo... | 4JAVA | {
"input": [
"1\n0 1 0 0 0 0 0 0 0 0\n1 1 1 0 0 0 0 0 0 0\n0 1 0 0 0 0 0 0 0 0\n0 0 0 0 1 1 0 0 0 0\n0 0 0 1 0 0 1 0 0 0\n0 0 0 0 1 1 0 0 0 0\n0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 1 0\n0 0 0 0 0 0 0 1 1 1\n0 0 0 0 0 0 0 0 1 0",
"1\n0 1 0 0 0 0 0 0 0 0\n1 1 1 0 0 0 0 0 0 0\n0 1 0 0 0 0 0 0 0 0\n0 0 0 0 0 1 0 0... | 6AIZU |
p00264 East Wind_2354 | I decided to move and decided to leave this place. There is nothing wrong with this land itself, but there is only one thing to worry about. It's a plum tree planted in the garden. I was looking forward to this plum blooming every year. After leaving here, the fun of spring will be reduced by one. Wouldn't the scent of... | from math import *
def check(hx,hy,fx,fy,df,w,a):
if ((hx-fx)**2 + (hy-fy)**2)**0.5 < a and Abs(atan2(hy-fy,hx-fx)-w) < df:
return True
else:
return False
def Abs(e):
e = abs(e)
if e > pi: e = 2*pi - e
return e
while 1:
H,R = map(int,raw_input().split())
if H == 0: break
hxy = [map(int,raw_input().split()... | 1Python2 | {
"input": [
"6 3\n2 1\n1 2\n5 2\n1 3\n1 5\n-2 3\n1 1 1 90 30 45\n3 -4\n-3 0\n2 -2\n45 6\n90 6\n135 6\n2 1\n1 3\n5 2\n0 1 1 90 30 45\n-3 0\n2 -2\n45 6\n0 0",
"6 3\n2 1\n1 2\n5 2\n1 3\n1 5\n-2 3\n1 1 1 90 30 45\n3 -4\n-3 0\n2 -2\n45 11\n90 6\n135 6\n2 1\n1 3\n5 2\n0 1 1 90 30 45\n-3 0\n2 -2\n45 6\n0 0",
"6... | 6AIZU |
p00264 East Wind_2355 | I decided to move and decided to leave this place. There is nothing wrong with this land itself, but there is only one thing to worry about. It's a plum tree planted in the garden. I was looking forward to this plum blooming every year. After leaving here, the fun of spring will be reduced by one. Wouldn't the scent of... | #include<iostream>
#include<vector>
#include<math.h>
#include<complex>
#define EPS 1e-4
#define PI 3.141592
#define EQ(a,b) (abs((a)-(b))<EPS)
using namespace std;
typedef complex<double> P;
vector<P> house;
vector<P> ume,sak,mo;
double cross(P v1,P v2){
return v1.real()*v2.imag()-v1.imag()*v2.real();
}
bool che... | 2C++ | {
"input": [
"6 3\n2 1\n1 2\n5 2\n1 3\n1 5\n-2 3\n1 1 1 90 30 45\n3 -4\n-3 0\n2 -2\n45 6\n90 6\n135 6\n2 1\n1 3\n5 2\n0 1 1 90 30 45\n-3 0\n2 -2\n45 6\n0 0",
"6 3\n2 1\n1 2\n5 2\n1 3\n1 5\n-2 3\n1 1 1 90 30 45\n3 -4\n-3 0\n2 -2\n45 11\n90 6\n135 6\n2 1\n1 3\n5 2\n0 1 1 90 30 45\n-3 0\n2 -2\n45 6\n0 0",
"6... | 6AIZU |
p00264 East Wind_2356 | I decided to move and decided to leave this place. There is nothing wrong with this land itself, but there is only one thing to worry about. It's a plum tree planted in the garden. I was looking forward to this plum blooming every year. After leaving here, the fun of spring will be reduced by one. Wouldn't the scent of... | from math import atan2, degrees
def calc(dx, dy, d, w, a):
if dx**2 + dy**2 > a**2:
return 0
t = degrees(atan2(dy, dx))
for i in range(2):
if w - d/2 <= t + 360*i <= w + d/2:
return 1
return 0
while 1:
H, R = map(int, input().split())
if H == R == 0:
break
... | 3Python3 | {
"input": [
"6 3\n2 1\n1 2\n5 2\n1 3\n1 5\n-2 3\n1 1 1 90 30 45\n3 -4\n-3 0\n2 -2\n45 6\n90 6\n135 6\n2 1\n1 3\n5 2\n0 1 1 90 30 45\n-3 0\n2 -2\n45 6\n0 0",
"6 3\n2 1\n1 2\n5 2\n1 3\n1 5\n-2 3\n1 1 1 90 30 45\n3 -4\n-3 0\n2 -2\n45 11\n90 6\n135 6\n2 1\n1 3\n5 2\n0 1 1 90 30 45\n-3 0\n2 -2\n45 6\n0 0",
"6... | 6AIZU |
p00264 East Wind_2357 | I decided to move and decided to leave this place. There is nothing wrong with this land itself, but there is only one thing to worry about. It's a plum tree planted in the garden. I was looking forward to this plum blooming every year. After leaving here, the fun of spring will be reduced by one. Wouldn't the scent of... | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
while(true) {
int H = stdIn.nextInt();
int R = stdIn.nextInt();
if(H == 0 && R == 0) {
break;
}
int[] hx = new int[H];
int[] hy = new int[H];
for(int i = 0; i ... | 4JAVA | {
"input": [
"6 3\n2 1\n1 2\n5 2\n1 3\n1 5\n-2 3\n1 1 1 90 30 45\n3 -4\n-3 0\n2 -2\n45 6\n90 6\n135 6\n2 1\n1 3\n5 2\n0 1 1 90 30 45\n-3 0\n2 -2\n45 6\n0 0",
"6 3\n2 1\n1 2\n5 2\n1 3\n1 5\n-2 3\n1 1 1 90 30 45\n3 -4\n-3 0\n2 -2\n45 11\n90 6\n135 6\n2 1\n1 3\n5 2\n0 1 1 90 30 45\n-3 0\n2 -2\n45 6\n0 0",
"6... | 6AIZU |
p00451 Common Sub-String_2358 | problem
Given two strings, find the longest of the strings contained in both strings and write a program that answers that length.
Here, the string s included in the string t means that s appears consecutively in t. An empty string, that is, a string of length 0, is included in any string. For example, the string ABR... | while 1:
try:
s1 = raw_input()
s2 = raw_input()
if len(s1) < len(s2): s1,s2 = s2,s1
l = sum(min(s1.count(i), s2.count(i)) for i in set(list(s1)) & set(list(s2)))
if l == 0: print 0; continue
ans = 0
for i in range(len(s2)):
if len(s2) - i <= ans: b... | 1Python2 | {
"input": [
"None",
"ABRACADABRA\nECADADABRBCRDARA\nUPWJCIRUCAXIIRGL\nSBQNYBSBZDFNEV",
"Nnne",
"ABRACADAARA\nECADADABRBCRDARA\nUPWJCIRUCAXIIRGL\nSBQNYBSBZDFNEV",
"DBRACAAAARA\nECADADBBRBCRDARA\nLCRIIXACURIGJWPU\nSBQNYBSBZDFOEV",
"DBRACAAAARA\nECADADBBRBBRDARA\nLCRIIXACURIGJWPU\nSBQNYBSBFDZOEU... | 6AIZU |
p00451 Common Sub-String_2359 | problem
Given two strings, find the longest of the strings contained in both strings and write a program that answers that length.
Here, the string s included in the string t means that s appears consecutively in t. An empty string, that is, a string of length 0, is included in any string. For example, the string ABR... | #include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define int long long
#define mod 1000000007
using namespace std;
string s, t;
int dp[4005][4005], ans;
signed main() {
while (cin >> s >> t) {
for (int i = 0; i <= 4000; i++)for (int j = 0; j <= 4000; j++)dp[i][j] = 0;
ans = 0;
for (int i ... | 2C++ | {
"input": [
"None",
"ABRACADABRA\nECADADABRBCRDARA\nUPWJCIRUCAXIIRGL\nSBQNYBSBZDFNEV",
"Nnne",
"ABRACADAARA\nECADADABRBCRDARA\nUPWJCIRUCAXIIRGL\nSBQNYBSBZDFNEV",
"DBRACAAAARA\nECADADBBRBCRDARA\nLCRIIXACURIGJWPU\nSBQNYBSBZDFOEV",
"DBRACAAAARA\nECADADBBRBBRDARA\nLCRIIXACURIGJWPU\nSBQNYBSBFDZOEU... | 6AIZU |
p00451 Common Sub-String_2360 | problem
Given two strings, find the longest of the strings contained in both strings and write a program that answers that length.
Here, the string s included in the string t means that s appears consecutively in t. An empty string, that is, a string of length 0, is included in any string. For example, the string ABR... | def rolling_hash(S, base, MOD):
l = len(S)
h = [0]*(l + 1)
for i in range(l):
h[i+1] = (h[i] * base + ord(S[i])) % MOD
return h
C = open(0).read().split()
MOD = 358976445361682909
base = 31
for t in range(len(C)//2):
S = C[2*t]; T = C[2*t+1]
rhs = rolling_hash(S, base, MOD)
rht = r... | 3Python3 | {
"input": [
"None",
"ABRACADABRA\nECADADABRBCRDARA\nUPWJCIRUCAXIIRGL\nSBQNYBSBZDFNEV",
"Nnne",
"ABRACADAARA\nECADADABRBCRDARA\nUPWJCIRUCAXIIRGL\nSBQNYBSBZDFNEV",
"DBRACAAAARA\nECADADBBRBCRDARA\nLCRIIXACURIGJWPU\nSBQNYBSBZDFOEV",
"DBRACAAAARA\nECADADBBRBBRDARA\nLCRIIXACURIGJWPU\nSBQNYBSBFDZOEU... | 6AIZU |
p00451 Common Sub-String_2361 | problem
Given two strings, find the longest of the strings contained in both strings and write a program that answers that length.
Here, the string s included in the string t means that s appears consecutively in t. An empty string, that is, a string of length 0, is included in any string. For example, the string ABR... | import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
for(;sc.hasNext();){
String s = sc.next();
String t = sc.next();
SuffixArray sa = new SuffixArray(s);
... | 4JAVA | {
"input": [
"None",
"ABRACADABRA\nECADADABRBCRDARA\nUPWJCIRUCAXIIRGL\nSBQNYBSBZDFNEV",
"Nnne",
"ABRACADAARA\nECADADABRBCRDARA\nUPWJCIRUCAXIIRGL\nSBQNYBSBZDFNEV",
"DBRACAAAARA\nECADADBBRBCRDARA\nLCRIIXACURIGJWPU\nSBQNYBSBZDFOEV",
"DBRACAAAARA\nECADADBBRBBRDARA\nLCRIIXACURIGJWPU\nSBQNYBSBFDZOEU... | 6AIZU |
p00642 Ben Toh_2362 | As usual, those who called wolves get together on 8 p.m. at the supermarket. The thing they want is only one, a box lunch that is labeled half price. Scrambling for a few discounted box lunch, they fiercely fight every day. And those who are blessed by hunger and appetite the best can acquire the box lunch, while other... | #include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#define rep(i,n) for(int i=0;i<n;i++)
#define rp(i,c) rep(i,(c).... | 2C++ | {
"input": [
"1\n2\n3\n0",
"1\n2\n4\n0",
"1\n4\n4\n0",
"1\n4\n7\n0",
"1\n4\n12\n0",
"1\n4\n22\n0",
"1\n2\n6\n0",
"1\n2\n2\n0",
"1\n4\n11\n0",
"1\n4\n20\n0",
"1\n0\n6\n0",
"1\n1\n4\n0",
"1\n6\n11\n0",
"1\n4\n38\n0",
"1\n1\n6\n0",
"1\n4\n67\n0",
"1\n4\... | 6AIZU |
p00642 Ben Toh_2363 | As usual, those who called wolves get together on 8 p.m. at the supermarket. The thing they want is only one, a box lunch that is labeled half price. Scrambling for a few discounted box lunch, they fiercely fight every day. And those who are blessed by hunger and appetite the best can acquire the box lunch, while other... | import java.awt.geom.Rectangle2D;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.PriorityQueue;
import java.util.Scanner;
public class Main {
public static ... | 4JAVA | {
"input": [
"1\n2\n3\n0",
"1\n2\n4\n0",
"1\n4\n4\n0",
"1\n4\n7\n0",
"1\n4\n12\n0",
"1\n4\n22\n0",
"1\n2\n6\n0",
"1\n2\n2\n0",
"1\n4\n11\n0",
"1\n4\n20\n0",
"1\n0\n6\n0",
"1\n1\n4\n0",
"1\n6\n11\n0",
"1\n4\n38\n0",
"1\n1\n6\n0",
"1\n4\n67\n0",
"1\n4\... | 6AIZU |
p00786 BUT We Need a Diagram_2364 | Consider a data structure called BUT (Binary and/or Unary Tree). A BUT is defined inductively as follows:
* Let l be a letter of the English alphabet, either lowercase or uppercase (n the sequel, we say simply "a letter"). Then, the object that consists only of l, designating l as its label, is a BUT. In this case, it... | #include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<vector>
#include<string>
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
class Tree{
public:
Tree *l,*r;
char c;
int x,y;
int d;
Tree():l(NULL),r(NULL),d(0){;}
};
//parsig... | 2C++ | {
"input": [
"a(A,b(B,C));\nx( y( y( z(z), v( s, t ) ) ), u ) ;\n\na( b( c,\n d(\n e(f),\n g\n )\n ),\n h( i(\n j(\n k(k,k),\n l(l)\n ),\n m(m)\n )\n )\n );\n\na(B(C),d(e(f(g(h(i(j,k),l),m),n),o),p))\n.",
"a(A,b(B,C));\nx(... | 6AIZU |
p00918 Dragon's Cruller_2365 | Dragon's Cruller is a sliding puzzle on a torus. The torus surface is partitioned into nine squares as shown in its development in Figure E.1. Here, two squares with one of the sides on the development labeled with the same letter are adjacent to each other, actually sharing the side. Figure E.2 shows which squares are... | #include <bits/stdc++.h>
using namespace std;
constexpr int pDec[]={1,10,100,1000,10000,100000,1000000,10000000,100000000};
constexpr int fct[]={40320,5040,720,120,24,6,2,1};
constexpr int dif[]={-1,1,-3,3};
int makeHash(int num){
int ans=0;
int f=0;
for(int i=0;i<8;i++){
int tmp=num%10;
// ... | 2C++ | {
"input": [
"4 9\n6 3 0\n8 1 2\n4 5 7\n6 3 0\n8 1 2\n4 5 7\n31 31\n4 3 6\n0 1 5\n8 2 7\n0 3 6\n4 1 5\n8 2 7\n92 4\n1 5 3\n4 0 7\n8 2 6\n1 5 0\n4 7 3\n8 2 6\n12 28\n3 4 5\n0 2 6\n7 1 8\n5 7 1\n8 6 2\n0 3 4\n0 0",
"6 9\n6 3 0\n8 1 2\n4 5 7\n6 3 0\n8 1 2\n4 5 7\n31 31\n4 3 6\n0 1 5\n8 2 7\n0 3 6\n4 1 5\n8 2 7\n... | 6AIZU |
p00918 Dragon's Cruller_2366 | Dragon's Cruller is a sliding puzzle on a torus. The torus surface is partitioned into nine squares as shown in its development in Figure E.1. Here, two squares with one of the sides on the development labeled with the same letter are adjacent to each other, actually sharing the side. Figure E.2 shows which squares are... | import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.Lin... | 4JAVA | {
"input": [
"4 9\n6 3 0\n8 1 2\n4 5 7\n6 3 0\n8 1 2\n4 5 7\n31 31\n4 3 6\n0 1 5\n8 2 7\n0 3 6\n4 1 5\n8 2 7\n92 4\n1 5 3\n4 0 7\n8 2 6\n1 5 0\n4 7 3\n8 2 6\n12 28\n3 4 5\n0 2 6\n7 1 8\n5 7 1\n8 6 2\n0 3 4\n0 0",
"6 9\n6 3 0\n8 1 2\n4 5 7\n6 3 0\n8 1 2\n4 5 7\n31 31\n4 3 6\n0 1 5\n8 2 7\n0 3 6\n4 1 5\n8 2 7\n... | 6AIZU |
p01051 Squid Ink_2367 | Problem
In recent years, turf wars have frequently occurred among squids. It is a recent squid fighting style that multiple squids form a team and fight with their own squid ink as a weapon.
There is still a turf war, and the battlefield is represented by an R × C grid. The squid Gesota, who is participating in the t... | #include <iostream>
#include <algorithm>
#define MAX_R 10000
#define MAX_C 30
#define INF 100000
using namespace std;
typedef pair<int, int> coordinate;
char field[MAX_R][MAX_C + 1];
bool used[MAX_R][MAX_C + 1];
int d[MAX_R][MAX_C + 1];
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
int R, C;
coordinate start, g... | 2C++ | {
"input": [
"4 5\nS#...\n.#.#.\n.#.#.\n...#G",
"5 5\nSxxxx\nxxxxx\nxxxxx\nxxxxx\nxxxxG",
"4 5\nS#ooo\no#o#o\no#o#o\nooo#G",
"5 5\nS....\n.....\n.....\n.....\n....G",
"4 5\nG####\nooxoo\nx#o\nSoooo",
"4 5\nS#...\n.#.$.\n.#.#.\n...#G",
"5 5\n.S...\n.....\n.....\n.....\n....G",
"4 5\nG##... | 6AIZU |
p01183 Tetrahedra_2368 | Peter P. Pepper is facing a difficulty.
After fierce battles with the Principality of Croode, the Aaronbarc Kingdom, for which he serves, had the last laugh in the end. Peter had done great service in the war, and the king decided to give him a big reward. But alas, the mean king gave him a hard question to try his in... | #include<cmath>
#include<cstdio>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
// 三角形が作れるかどうか
bool tri(int a,int b,int c){
int p[]={a,b,c};
sort(p,p+3);
return p[0]+p[1]>p[2];
}
double volume(double U,double V,double W,double u,double v,double w){
double X=(w-U+v)*(U+v+w);
do... | 2C++ | {
"input": [
"7 1 2 2 2 2 2 2\n0",
"7 1 2 2 2 2 2 4\n0",
"7 1 2 2 1 2 2 0\n0",
"7 1 2 3 2 2 2 2\n0",
"7 1 2 2 1 2 1 0\n0",
"7 1 2 3 2 3 2 2\n0",
"7 1 2 3 2 3 4 2\n0",
"7 1 2 3 4 3 4 2\n0",
"7 1 3 3 4 3 4 2\n0",
"7 1 3 0 4 3 4 2\n0",
"7 1 3 0 4 3 4 4\n0",
"7 1 3 2 2 2 2 ... | 6AIZU |
p01183 Tetrahedra_2369 | Peter P. Pepper is facing a difficulty.
After fierce battles with the Principality of Croode, the Aaronbarc Kingdom, for which he serves, had the last laugh in the end. Peter had done great service in the war, and the king decided to give him a big reward. But alas, the mean king gave him a hard question to try his in... | import static java.lang.Math.*;
import java.util.Scanner;
//Tetrahedra
public class Main{
double EPS = 1e-10;
double det(double[][] A){
int n = A.length;
double res = 1;
for(int i=0;i<n;i++){
int pivot = i;
for(int j=i+1;j<n;j++)if(abs(A[j][i])>abs(A[pivot][i]))pivot = j;
swap(A, pivot, i);
res *=... | 4JAVA | {
"input": [
"7 1 2 2 2 2 2 2\n0",
"7 1 2 2 2 2 2 4\n0",
"7 1 2 2 1 2 2 0\n0",
"7 1 2 3 2 2 2 2\n0",
"7 1 2 2 1 2 1 0\n0",
"7 1 2 3 2 3 2 2\n0",
"7 1 2 3 2 3 4 2\n0",
"7 1 2 3 4 3 4 2\n0",
"7 1 3 3 4 3 4 2\n0",
"7 1 3 0 4 3 4 2\n0",
"7 1 3 0 4 3 4 4\n0",
"7 1 3 2 2 2 2 ... | 6AIZU |
p01320 Magical Island 2_2370 | It was an era when magic still existed as a matter of course. A clan of magicians lived on a square-shaped island created by magic.
At one point, a crisis came to this island. The empire has developed an intercontinental ballistic missile and aimed it at this island. The magic of this world can be classified into eart... | #include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <ctime>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <deque>
#include <complex>
#include <string>
#include <iomanip>... | 2C++ | {
"input": [
"4 4 1\n1 0\n0 1\n-1 0\n0 -1\n5 6 2\n1 1\n4 4\n2 -4\n-4 2\n1 5\n0 0 0",
"4 4 1\n1 0\n0 1\n-1 0\n0 -1\n5 6 2\n1 1\n4 8\n2 -4\n-4 2\n1 5\n0 0 0",
"4 4 1\n0 0\n0 1\n-1 -1\n0 -1\n5 6 2\n1 1\n4 8\n2 -4\n-4 2\n1 5\n0 -1 0",
"4 4 1\n0 0\n0 1\n-1 -1\n-1 -1\n5 6 2\n1 1\n4 8\n2 -4\n-4 0\n1 5\n0 -1 ... | 6AIZU |
p01488 TransferTrain_2371 | Example
Input
2 10
Warsaw Petersburg
3
Kiev Moscow Petersburg
150 120
3
Moscow Minsk Warsaw
100 150
Output
380 1 | #include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
using namespace std;
#define FOR(i,k,n) for(int i=(k); i<(int)(n);... | 2C++ | {
"input": [
"2 10\nWarsaw Petersburg\n3\nKiev Moscow Petersburg\n150 120\n3\nMoscow Minsk Warsaw\n100 150",
"2 10\nWarsaw Petersburg\n3\nKiev Moscow grubsreteP\n150 120\n3\nMoscow Minsk Warsaw\n100 150",
"2 10\nWarsaw grubsreteP\n3\nKiev Moscow grubsreteP\n231 120\n3\nMoscow Minsk Warsaw\n000 150",
"... | 6AIZU |
p01488 TransferTrain_2372 | Example
Input
2 10
Warsaw Petersburg
3
Kiev Moscow Petersburg
150 120
3
Moscow Minsk Warsaw
100 150
Output
380 1 | from heapq import heappush, heappop
import sys
def solve():
readline = sys.stdin.readline
write = sys.stdout.write
N, TI = map(int, readline().split())
A, B = readline().split()
S = []; T = []; X = []
L = 0
L = 0
NA = set()
for i in range(N):
a = int(readline())
*Si, ... | 3Python3 | {
"input": [
"2 10\nWarsaw Petersburg\n3\nKiev Moscow Petersburg\n150 120\n3\nMoscow Minsk Warsaw\n100 150",
"2 10\nWarsaw Petersburg\n3\nKiev Moscow grubsreteP\n150 120\n3\nMoscow Minsk Warsaw\n100 150",
"2 10\nWarsaw grubsreteP\n3\nKiev Moscow grubsreteP\n231 120\n3\nMoscow Minsk Warsaw\n000 150",
"... | 6AIZU |
p01650 Stack Maze_2373 | Problem Statement
There is a maze which can be described as a W \times H grid. The upper-left cell is denoted as (1, 1), and the lower-right cell is (W, H). You are now at the cell (1, 1) and have to go to the cell (W, H). However, you can only move to the right adjacent cell or to the lower adjacent cell. The followi... | #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": [
"3 3\nac#\nb#C\n.BA\n3 3\naaZ\na#Z\naZZ\n3 3\n..#\n.#.\n#..\n1 50\nabcdefghijklmnopqrstuvwxyYXWVUTSRQPONMLKJIHGFEDCBA\n1 50\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY\n1 50\nabcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXY\n1 50\naaaaaaaaaabbbbbbbbbbcccccCCCCCBBBBBBBBBBAAAAAAAAAA\n10 10\n.... | 6AIZU |
p01650 Stack Maze_2374 | Problem Statement
There is a maze which can be described as a W \times H grid. The upper-left cell is denoted as (1, 1), and the lower-right cell is (W, H). You are now at the cell (1, 1) and have to go to the cell (W, H). However, you can only move to the right adjacent cell or to the lower adjacent cell. The followi... | import sys
readline = sys.stdin.readline
write = sys.stdout.write
from string import ascii_lowercase, ascii_uppercase
from collections import deque
dd = ((1, 0), (0, 1))
def solve():
H, W = map(int, readline().split())
if H == W == 0:
return False
C = [readline().strip() for i in range(H)]
INF... | 3Python3 | {
"input": [
"3 3\nac#\nb#C\n.BA\n3 3\naaZ\na#Z\naZZ\n3 3\n..#\n.#.\n#..\n1 50\nabcdefghijklmnopqrstuvwxyYXWVUTSRQPONMLKJIHGFEDCBA\n1 50\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY\n1 50\nabcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXY\n1 50\naaaaaaaaaabbbbbbbbbbcccccCCCCCBBBBBBBBBBAAAAAAAAAA\n10 10\n.... | 6AIZU |
p01650 Stack Maze_2375 | Problem Statement
There is a maze which can be described as a W \times H grid. The upper-left cell is denoted as (1, 1), and the lower-right cell is (W, H). You are now at the cell (1, 1) and have to go to the cell (W, H). However, you can only move to the right adjacent cell or to the lower adjacent cell. The followi... | import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
static InputStream is;
static PrintWriter out;
static String INPUT = "";
public static void ma... | 4JAVA | {
"input": [
"3 3\nac#\nb#C\n.BA\n3 3\naaZ\na#Z\naZZ\n3 3\n..#\n.#.\n#..\n1 50\nabcdefghijklmnopqrstuvwxyYXWVUTSRQPONMLKJIHGFEDCBA\n1 50\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY\n1 50\nabcdefghijklmnopqrstuvwxyABCDEFGHIJKLMNOPQRSTUVWXY\n1 50\naaaaaaaaaabbbbbbbbbbcccccCCCCCBBBBBBBBBBAAAAAAAAAA\n10 10\n.... | 6AIZU |
p01801 Wall Making Game_2376 | Example
Input
2 2
..
..
Output
Second | #include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double>... | 2C++ | {
"input": [
"2 2\n..\n..",
"1 2\n..\n..",
"1 0\n..\n..",
"1 1\n..\n..",
"1 0\n-.\n..",
"1 0\n-/\n..",
"1 0\n-/\n./",
"1 0\n,/\n./",
"2 0\n,/\n./",
"2 -1\n,/\n./",
"2 -1\n/,\n./",
"2 -2\n/,\n./",
"2 -2\n/-\n./",
"2 -2\n/.\n./",
"2 -2\n/.\n..",
"2 -2\n//\... | 6AIZU |
p01801 Wall Making Game_2377 | Example
Input
2 2
..
..
Output
Second | import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
H, W = map(int, readline().split())
f = ".X".index
S = [list(map(f, readline().strip())) for i in range(H)]
memo = {}
def dfs(px, py, qx, qy):
key = (px, py, qx, qy)
if key in memo:
return memo... | 3Python3 | {
"input": [
"2 2\n..\n..",
"1 2\n..\n..",
"1 0\n..\n..",
"1 1\n..\n..",
"1 0\n-.\n..",
"1 0\n-/\n..",
"1 0\n-/\n./",
"1 0\n,/\n./",
"2 0\n,/\n./",
"2 -1\n,/\n./",
"2 -1\n/,\n./",
"2 -2\n/,\n./",
"2 -2\n/-\n./",
"2 -2\n/.\n./",
"2 -2\n/.\n..",
"2 -2\n//\... | 6AIZU |
p01935 Protect from the enemy attack_2378 | problem
There are $ V $ islands, numbered $ 0, 1, ..., V-1 $, respectively. There are $ E $ bridges, numbered $ 0, 1, ..., E-1 $, respectively. The $ i $ th bridge spans island $ s_i $ and island $ t_i $ and is $ c_i $ wide.
The AOR Ika-chan Corps (commonly known as the Squid Corps), which has a base on the island $ ... | #include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;
#define NUM 5000
//辺を表す構造体(行先、容量、逆辺のインデックス)
struct Edge{
Edge(int arg_to,int arg_capacity,int arg_rev_index){
to = arg_to;
capacit... | 2C++ | {
"input": [
"4 4\n0 1 3\n0 2 4\n1 3 1\n2 3 5",
"4 4\n0 1 3\n0 2 4\n1 3 1\n0 3 5",
"4 8\n0 1 6\n0 2 4\n1 3 1\n0 3 5",
"4 4\n0 1 3\n0 2 0\n1 3 1\n2 3 5",
"2 15\n0 1 0\n0 1 4\n2 3 0\n0 3 9",
"5 8\n0 1 6\n0 0 4\n2 3 4\n1 4 5",
"2 15\n0 1 0\n0 1 4\n2 3 0\n0 1 9",
"2 15\n0 1 0\n0 2 4\n2 1 0... | 6AIZU |
p02074 N-by-M grid calculation_2379 | Problem Statement
Have you experienced $10$-by-$10$ grid calculation? It's a mathematical exercise common in Japan. In this problem, we consider the generalization of the exercise, $N$-by-$M$ grid calculation.
In this exercise, you are given an $N$-by-$M$ grid (i.e. a grid with $N$ rows and $M$ columns) with an addit... | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
//#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int... | 2C++ | {
"input": [
""
],
"output": [
""
]
} | 6AIZU |
p02216 Array Game_2380 | Problem statement
There is a positive integer sequence $ a_1, a_2, \ ldots, a_N $ of length $ N $.
Consider the following game, which uses this sequence and is played by $ 2 $ players on the play and the play.
* Alternately select one of the following operations for the first move and the second move.
* Select a pos... | #include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)
int main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
istream& in(cin);
... | 2C++ | {
"input": [
"2\n1 2",
"2\n0 2",
"2\n-1 4",
"2\n0 4",
"2\n0 1",
"2\n1 0",
"2\n0 7",
"2\n-1 2",
"2\n2 0",
"2\n-1 10",
"2\n-2 2",
"2\n2 -1",
"2\n-2 4",
"2\n4 -1",
"2\n-2 8",
"2\n4 0",
"2\n-2 5",
"2\n5 0",
"2\n1 1",
"2\n2 2",
"2\n2 4",
... | 6AIZU |
p02216 Array Game_2381 | Problem statement
There is a positive integer sequence $ a_1, a_2, \ ldots, a_N $ of length $ N $.
Consider the following game, which uses this sequence and is played by $ 2 $ players on the play and the play.
* Alternately select one of the following operations for the first move and the second move.
* Select a pos... | #
# ⋀_⋀
# (・ω・)
# ./ U ∽ U\
# │* 合 *│
# │* 格 *│
# │* 祈 *│
# │* 願 *│
# │* *│
#  ̄
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないyp
from heapq import heappop, heappush, heappushpop
from collections import Counter,default... | 3Python3 | {
"input": [
"2\n1 2",
"2\n0 2",
"2\n-1 4",
"2\n0 4",
"2\n0 1",
"2\n1 0",
"2\n0 7",
"2\n-1 2",
"2\n2 0",
"2\n-1 10",
"2\n-2 2",
"2\n2 -1",
"2\n-2 4",
"2\n4 -1",
"2\n-2 8",
"2\n4 0",
"2\n-2 5",
"2\n5 0",
"2\n1 1",
"2\n2 2",
"2\n2 4",
... | 6AIZU |
p02216 Array Game_2382 | Problem statement
There is a positive integer sequence $ a_1, a_2, \ ldots, a_N $ of length $ N $.
Consider the following game, which uses this sequence and is played by $ 2 $ players on the play and the play.
* Alternately select one of the following operations for the first move and the second move.
* Select a pos... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedOutputStream;
import java.io.UncheckedIOException;... | 4JAVA | {
"input": [
"2\n1 2",
"2\n0 2",
"2\n-1 4",
"2\n0 4",
"2\n0 1",
"2\n1 0",
"2\n0 7",
"2\n-1 2",
"2\n2 0",
"2\n-1 10",
"2\n-2 2",
"2\n2 -1",
"2\n-2 4",
"2\n4 -1",
"2\n-2 8",
"2\n4 0",
"2\n-2 5",
"2\n5 0",
"2\n1 1",
"2\n2 2",
"2\n2 4",
... | 6AIZU |
p02369 Cycle Detection for a Directed Graph_2383 | Find a cycle in a directed graph G(V, E).
Constraints
* 1 ≤ |V| ≤ 100
* 0 ≤ |E| ≤ 1,000
* si ≠ ti
Input
A directed graph G is given in the following format:
|V| |E|
s0 t0
s1 t1
:
s|E|-1 t|E|-1
|V| is the number of nodes and |E| is the number of edges in the graph. The graph nodes are named with the numbers 0, 1... | V, E = map(int, raw_input().split())
cost = [[10**9]*V for i in xrange(V)]
for i in xrange(E):
s, t = map(int, raw_input().split())
cost[s][t] = -1
for i in xrange(V):
cost[i][i] = 0
for k in xrange(V):
for i in xrange(V):
for j in xrange(V):
cost[i][j] = min(cost[i][j], cost[i][k] ... | 1Python2 | {
"input": [
"3 3\n0 1\n0 2\n1 2",
"3 3\n0 1\n1 2\n2 0",
"5 3\n0 1\n0 2\n1 2",
"8 3\n0 1\n0 2\n1 2",
"8 3\n0 2\n0 2\n1 2",
"5 3\n0 2\n0 2\n1 2",
"11 3\n0 1\n0 2\n1 2",
"8 2\n0 1\n0 2\n1 2",
"8 3\n1 2\n0 2\n1 2",
"8 2\n0 1\n0 2\n1 4",
"8 2\n0 1\n0 2\n2 4",
"8 2\n0 2\n0 2... | 6AIZU |
p02369 Cycle Detection for a Directed Graph_2384 | Find a cycle in a directed graph G(V, E).
Constraints
* 1 ≤ |V| ≤ 100
* 0 ≤ |E| ≤ 1,000
* si ≠ ti
Input
A directed graph G is given in the following format:
|V| |E|
s0 t0
s1 t1
:
s|E|-1 t|E|-1
|V| is the number of nodes and |E| is the number of edges in the graph. The graph nodes are named with the numbers 0, 1... | #include<iostream>
#include <list>
#include <limits.h>
using namespace std;
class Graph
{
int V;
list<int> *adj;
bool isCyclicUtil(int v, bool visited[], bool *rs);
public:
Graph(int V);
void addEdge(int v, int w);
bool isCyclic();
};
Graph::Graph(int V)
{
this->V = V;
adj = new lis... | 2C++ | {
"input": [
"3 3\n0 1\n0 2\n1 2",
"3 3\n0 1\n1 2\n2 0",
"5 3\n0 1\n0 2\n1 2",
"8 3\n0 1\n0 2\n1 2",
"8 3\n0 2\n0 2\n1 2",
"5 3\n0 2\n0 2\n1 2",
"11 3\n0 1\n0 2\n1 2",
"8 2\n0 1\n0 2\n1 2",
"8 3\n1 2\n0 2\n1 2",
"8 2\n0 1\n0 2\n1 4",
"8 2\n0 1\n0 2\n2 4",
"8 2\n0 2\n0 2... | 6AIZU |
p02369 Cycle Detection for a Directed Graph_2385 | Find a cycle in a directed graph G(V, E).
Constraints
* 1 ≤ |V| ≤ 100
* 0 ≤ |E| ≤ 1,000
* si ≠ ti
Input
A directed graph G is given in the following format:
|V| |E|
s0 t0
s1 t1
:
s|E|-1 t|E|-1
|V| is the number of nodes and |E| is the number of edges in the graph. The graph nodes are named with the numbers 0, 1... | from collections import deque
from typing import List, Optional, Tuple
def cycle_detectable_topological_sort(
graph: List[List[int]], in_degrees: List[int], first_index: int = 0
) -> Tuple[Optional[List[int]], Optional[List[int]]]:
"""Topological sort that uses Kahn's algorithm and detects a loop (DAG or not)... | 3Python3 | {
"input": [
"3 3\n0 1\n0 2\n1 2",
"3 3\n0 1\n1 2\n2 0",
"5 3\n0 1\n0 2\n1 2",
"8 3\n0 1\n0 2\n1 2",
"8 3\n0 2\n0 2\n1 2",
"5 3\n0 2\n0 2\n1 2",
"11 3\n0 1\n0 2\n1 2",
"8 2\n0 1\n0 2\n1 2",
"8 3\n1 2\n0 2\n1 2",
"8 2\n0 1\n0 2\n1 4",
"8 2\n0 1\n0 2\n2 4",
"8 2\n0 2\n0 2... | 6AIZU |
p02369 Cycle Detection for a Directed Graph_2386 | Find a cycle in a directed graph G(V, E).
Constraints
* 1 ≤ |V| ≤ 100
* 0 ≤ |E| ≤ 1,000
* si ≠ ti
Input
A directed graph G is given in the following format:
|V| |E|
s0 t0
s1 t1
:
s|E|-1 t|E|-1
|V| is the number of nodes and |E| is the number of edges in the graph. The graph nodes are named with the numbers 0, 1... | import java.util.Scanner;
import java.util.ArrayList;
class ProblemB{
ArrayList<ArrayList<Integer>> g = new ArrayList<ArrayList<Integer>>();//graph
ArrayList<ArrayList<Integer>> rg = new ArrayList<ArrayList<Integer>>();//greverse graph
ArrayList<Integer> vs = new ArrayList<Integer>();
boolean visited[] = null;... | 4JAVA | {
"input": [
"3 3\n0 1\n0 2\n1 2",
"3 3\n0 1\n1 2\n2 0",
"5 3\n0 1\n0 2\n1 2",
"8 3\n0 1\n0 2\n1 2",
"8 3\n0 2\n0 2\n1 2",
"5 3\n0 2\n0 2\n1 2",
"11 3\n0 1\n0 2\n1 2",
"8 2\n0 1\n0 2\n1 2",
"8 3\n1 2\n0 2\n1 2",
"8 2\n0 1\n0 2\n1 4",
"8 2\n0 1\n0 2\n2 4",
"8 2\n0 2\n0 2... | 6AIZU |
aba15f_2387 | Problem description.
“Murphy’s Law doesn’t meant that something bad will happen. It means that whatever can happen, will happen.”
—Cooper
While traveling across space-time,the data sent by NASA to "The Endurance" spaceship is sent in the format of,
For... | def toBin(n):
binary = []
while n!=0:
bit = str(n%2)
binary.append(bit)
n = n/2
binary.reverse()
return binary
def main():
tc = int(raw_input())
while tc>0:
n = int(raw_input())
binary = toBin(n)
"""for x in xrange(0,32-len(binary)):
binary.append(0)"""
lenx=l... | 1Python2 | {
"input": [
"5\n100\n23\n4\n1000\n5"
],
"output": [
"68\n21\n4\n320\n5"
]
} | 1CODECHEF |
chefch_2388 | Chef had a hard day and want to play little bit. The game is called "Chain". Chef has the sequence of symbols. Each symbol is either '-' or '+'. The sequence is called Chain if each two neighboring symbols of sequence are either '-+' or '+-'.
For example sequence '-+-+-+' is a Chain but sequence '-+-+--+' is not.
H... | testCases = int(raw_input())
for testCase in range(testCases):
originalString = raw_input()
lenOfOriginalString = len(originalString)
# count variables to find the difference between the new string and original one
count1 = 0 # for "-+-+-+...."
count2 = 0 # for "+-+-+-...."
for pos in range(lenOfOriginalString):
... | 1Python2 | {
"input": [
"2\n---+-+-+++\n-------",
"2\n+++-+-+---\n-------",
"2\n-+--+++--+\n-------",
"2\n-+-+-+-+-+\n-------",
"2\n--++---+++\n-----+-",
"2\n---+-+-+++\n-----+-",
"2\n+-+-+-+--+\n-------",
"2\n---+++-+-+\n-------",
"2\n-+-+++---+\n-------",
"2\n+-+++----+\n-------",
"... | 1CODECHEF |
directi_2389 | Chef recently printed directions from his home to a hot new restaurant across the town, but forgot to print the directions to get back home. Help Chef to transform the directions to get home from the restaurant.
A set of directions consists of several instructions. The first instruction is of the form "Begin on XXX", i... | t = int(raw_input())
while t:
n = int(raw_input())
directions = []
for i in range(n):
directions.append(raw_input().split())
if i:
directions[i-1][0]="Left" if directions[i][0]=="Right" else "Right"
directions[n-1][0]="Begin"
while n:
print ' '.join(directions.pop... | 1Python2 | {
"input": [
"2\n4\nBegin on Road A\nRight on Road B\nRight on Road C\nLeft on Road D\n6\nBegin on Old Madras Road\nLeft on Domlur Flyover\nLeft on 100 Feet Road\nRight on Sarjapur Road\nRight on Hosur Road\nRight on Ganapathi Temple Road",
"2\n4\nBegin on Road A\nRight on Road B\nRight on Road C\nLeft on Roa... | 1CODECHEF |
insomb1_2390 | Modern cryptosystems rely heavily on our inability to factor large integers quickly as the basis for their security. They need a quick and easy way to generate and test for primes. Very often, the primes generated are very large numbers. You need to implement ways to test the primality of very large numbers.
Input
Lin... | def primality(n):
for i in primes:
if (n % i == 0 and n != i):
return 0
return 1
primes = [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229... | 1Python2 | {
"input": [
"2760727302517",
"1894408473307",
"1693567121009",
"743871772032",
"1207342155784",
"1154588488711",
"1798097736639",
"3595571189300",
"2584084900985",
"156458315848",
"199154598320",
"2006419019646",
"2229558751887",
"7052041710222",
"423198717... | 1CODECHEF |
nfeb4_2391 | Buffalo Marketing
Gopal wants to make some money from buffalos, but in a quite a different way. He decided that his future lay in speculating on buffalos. In the market in his village, buffalos were bought and sold everyday. The price fluctuated over the year, but on any single day the price was always the same.
... | t=int(input())
while(t>0):
n=int(input())
a=map(int,raw_input().split(" "))
i=n-1
m=a[i]
ans=0
i=n-2
while(i>=0):
if(m>a[i]):
ans+=m-a[i]
elif(m<a[i]):
m=a[i]
i-=1
print ans
t-=1 | 1Python2 | {
"input": [
"2\n3\n1 2 90\n4\n1 3 1 2"
],
"output": [
"177\n 3"
]
} | 1CODECHEF |
scores_2392 | Mrityunjay is a high-school teacher, currently coaching students for JEE (Joint Entrance Exam). Mrityunjay every year gives prizes to the toppers of JEE in India. A lot of students give this exam in India and it is difficult for him to manually go through results and select two top students from them. So he asked for y... | N = int(raw_input())
arr = map(int,raw_input().strip().split(' '))
c = []
for i in range(2):
m = max(arr)
c.append(m)
arr.remove(m)
print ' '.join(str(t) for t in c) | 1Python2 | {
"input": [
"3 \n30 30 20",
"3 \n12 20 12",
"3 \n30 30 7",
"3 \n12 20 16",
"3 \n30 40 7",
"3 \n12 5 16",
"3 \n30 31 7",
"3 \n7 5 16",
"3 \n30 51 3",
"3 \n7 8 16",
"3 \n30 26 0",
"3 \n30 22 0",
"3 \n7 6 2",
"3 \n30 8 1",
"3 \n7 4 3",
"3 \n30 16 1",
"... | 1CODECHEF |
1000_C. Covered Points Count_2393 | You are given n segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every k ∈ [1..n], calculate the number of points with integer ... | #!/usr/bin/python2
def cmp(a, b):
if (a[0] < b[0]):
return -1
return 1
def main():
n = int(raw_input())
points = []
for i in xrange(n):
x, y = map(int, raw_input().split())
points.append((x, 1))
points.append((y+1, -1))
points.sort(cmp=cmp)
ans = [0] * (n +... | 1Python2 | {
"input": [
"3\n0 3\n1 3\n3 8\n",
"3\n1 3\n2 4\n5 7\n",
"1\n0 1000000000000000000\n",
"3\n1 3\n2 4\n3 7\n",
"1\n1 1000000000000000000\n",
"3\n0 3\n1 1\n3 8\n",
"3\n1 3\n2 4\n3 14\n",
"3\n1 5\n2 4\n3 14\n",
"3\n0 3\n2 3\n3 8\n",
"3\n1 1\n2 4\n5 7\n",
"3\n1 3\n2 7\n3 7\n",
... | 2CODEFORCES |
1000_C. Covered Points Count_2394 | You are given n segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every k ∈ [1..n], calculate the number of points with integer ... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 5;
long long l[maxn], r[maxn], ans[maxn];
int tl[maxn], tr[maxn], s[maxn];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<long long> ds;
for (int i = 0; i < n; ++i) {
cin >> l[i] >> r[i];
ds.push... | 2C++ | {
"input": [
"3\n0 3\n1 3\n3 8\n",
"3\n1 3\n2 4\n5 7\n",
"1\n0 1000000000000000000\n",
"3\n1 3\n2 4\n3 7\n",
"1\n1 1000000000000000000\n",
"3\n0 3\n1 1\n3 8\n",
"3\n1 3\n2 4\n3 14\n",
"3\n1 5\n2 4\n3 14\n",
"3\n0 3\n2 3\n3 8\n",
"3\n1 1\n2 4\n5 7\n",
"3\n1 3\n2 7\n3 7\n",
... | 2CODEFORCES |
1000_C. Covered Points Count_2395 | You are given n segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every k ∈ [1..n], calculate the number of points with integer ... | n=int(input())
a=[]
for i in range(n):
l,r=map(int,input().split())
a.append([l,1])
a.append([r+1,-1])
a.sort()
# print(a)
ans=[0]*(n+1)
idx=0
for i in range(len(a)-1):
idx+=a[i][1]
ans[idx]+=a[i+1][0]-a[i][0]
for i in range(1,n+1):
print(ans[i],end=" ")
print() | 3Python3 | {
"input": [
"3\n0 3\n1 3\n3 8\n",
"3\n1 3\n2 4\n5 7\n",
"1\n0 1000000000000000000\n",
"3\n1 3\n2 4\n3 7\n",
"1\n1 1000000000000000000\n",
"3\n0 3\n1 1\n3 8\n",
"3\n1 3\n2 4\n3 14\n",
"3\n1 5\n2 4\n3 14\n",
"3\n0 3\n2 3\n3 8\n",
"3\n1 1\n2 4\n5 7\n",
"3\n1 3\n2 7\n3 7\n",
... | 2CODEFORCES |
1000_C. Covered Points Count_2396 | You are given n segments on a coordinate line; each endpoint of every segment has integer coordinates. Some segments can degenerate to points. Segments can intersect with each other, be nested in each other or even coincide.
Your task is the following: for every k ∈ [1..n], calculate the number of points with integer ... | import java.io.*;
import java.util.*;
public class Main {
static int N;
static long[] A, B;
public static void main(String[] args) {
FastScanner sc = new FastScanner(System.in);
N = sc.nextInt();
A = new long[N];
B = new long[N];
for (int i = 0; i < N; i++) {
... | 4JAVA | {
"input": [
"3\n0 3\n1 3\n3 8\n",
"3\n1 3\n2 4\n5 7\n",
"1\n0 1000000000000000000\n",
"3\n1 3\n2 4\n3 7\n",
"1\n1 1000000000000000000\n",
"3\n0 3\n1 1\n3 8\n",
"3\n1 3\n2 4\n3 14\n",
"3\n1 5\n2 4\n3 14\n",
"3\n0 3\n2 3\n3 8\n",
"3\n1 1\n2 4\n5 7\n",
"3\n1 3\n2 7\n3 7\n",
... | 2CODEFORCES |
1025_D. Recovering BST_2397 | Dima the hamster enjoys nibbling different things: cages, sticks, bad problemsetters and even trees!
Recently he found a binary search tree and instinctively nibbled all of its edges, hence messing up the vertices. Dima knows that if Andrew, who has been thoroughly assembling the tree for a long time, comes home and s... | import sys
range = xrange
input = sys.stdin.readline
n = int(input())
A = [int(x) for x in input().split()]
good_gcd = [False]*(710**2)
for i in range(n):
for j in range(n):
a,b = A[i],A[j]
while b:
a,b = b,a%b
good_gcd[i+710*j]=a>1
good_gcd[i+710*n]=True
good_gcd[n+710... | 1Python2 | {
"input": [
"9\n4 8 10 12 15 18 33 44 81\n",
"6\n3 6 9 18 36 108\n",
"2\n7 17\n",
"4\n3 5 7 105\n",
"13\n2 12 60 300 900 6300 44100 176400 352800 705600 3528000 21168000 148176000\n",
"11\n2 6 15 35 77 143 221 323 437 667 899\n",
"4\n2 3 5 30\n",
"27\n5 10 29 58 116 174 2297 4594 9188... | 2CODEFORCES |
1025_D. Recovering BST_2398 | Dima the hamster enjoys nibbling different things: cages, sticks, bad problemsetters and even trees!
Recently he found a binary search tree and instinctively nibbled all of its edges, hence messing up the vertices. Dima knows that if Andrew, who has been thoroughly assembling the tree for a long time, comes home and s... | #include <bits/stdc++.h>
using namespace std;
inline long long mod(long long n, long long m) {
long long ret = n % m;
if (ret < 0) ret += m;
return ret;
}
long long gcd(long long a, long long b) { return (b == 0 ? a : gcd(b, a % b)); }
long long exp(long long a, long long b, long long m) {
if (b == 0LL) return ... | 2C++ | {
"input": [
"9\n4 8 10 12 15 18 33 44 81\n",
"6\n3 6 9 18 36 108\n",
"2\n7 17\n",
"4\n3 5 7 105\n",
"13\n2 12 60 300 900 6300 44100 176400 352800 705600 3528000 21168000 148176000\n",
"11\n2 6 15 35 77 143 221 323 437 667 899\n",
"4\n2 3 5 30\n",
"27\n5 10 29 58 116 174 2297 4594 9188... | 2CODEFORCES |
1025_D. Recovering BST_2399 | Dima the hamster enjoys nibbling different things: cages, sticks, bad problemsetters and even trees!
Recently he found a binary search tree and instinctively nibbled all of its edges, hence messing up the vertices. Dima knows that if Andrew, who has been thoroughly assembling the tree for a long time, comes home and s... | from math import gcd
import random,time,sys
input=sys.stdin.buffer.readline
def main():
n=int(input())
a=list(map(int,input().split()))
#a=[2*random.randint(1,10**9) for i in range(n)]
start=time.time()
a+=[0]
dp=[[False for j in range(n)] for i in range(n)]
GCD=[0 for i in range(n+1)]
... | 3Python3 | {
"input": [
"9\n4 8 10 12 15 18 33 44 81\n",
"6\n3 6 9 18 36 108\n",
"2\n7 17\n",
"4\n3 5 7 105\n",
"13\n2 12 60 300 900 6300 44100 176400 352800 705600 3528000 21168000 148176000\n",
"11\n2 6 15 35 77 143 221 323 437 667 899\n",
"4\n2 3 5 30\n",
"27\n5 10 29 58 116 174 2297 4594 9188... | 2CODEFORCES |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.