Dataset Viewer
Auto-converted to Parquet Duplicate
description
stringlengths
29
13k
solution
listlengths
0
16.3k
Problem description. Vipul is a hardworking super-hero who maintains the bracket ratio of all the strings in the world. Recently he indulged himself in saving the string population so much that he lost his ability for checking brackets (luckily, not permanently ).Being his super-hero friend help him in his time of hardship. Input The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single string S denoting the string to be checked. Output For each test case, output a single line printing "YES" or "NO" (without " " and in uppercase only) , denoting if the brackets in the given string is balanced or not . Constraints 1 ≤ T ≤ 10 1 ≤ length of S ≤ 60 Example Input: 3 ((())) (())() ()(() Output: YES YES NO   Explanation Example is self-explanatory.
[ "for _ in range(input()):\n try:\n eval(raw_input())\n print 'YES'\n except TypeError:\n print 'YES'\n except:\n print 'NO'", "for _ in range(input()):\n ins = raw_input().strip()\n stck = []\n res = \"YES\"\n for x in ins:\n if x == \"(\":\n stck...
The Chef likes to stay in touch with his staff. So, the Chef, the head server, and the sous-chef all carry two-way transceivers so they can stay in constant contact. Of course, these transceivers have a limited range so if two are too far apart, they cannot communicate directly. The Chef invested in top-of-the-line transceivers which have a few advanced features. One is that even if two people cannot talk directly because they are out of range, if there is another transceiver that is close enough to both, then the two transceivers can still communicate with each other using the third transceiver as an intermediate device. There has been a minor emergency in the Chef's restaurant and he needs to communicate with both the head server and the sous-chef right away. Help the Chef determine if it is possible for all three people to communicate with each other, even if two must communicate through the third because they are too far apart. Input The first line contains a single positive integer T ≤ 100 indicating the number of test cases to follow. The first line of each test case contains a positive integer R ≤ 1,000 indicating that two transceivers can communicate directly without an intermediate transceiver if they are at most R meters away from each other. The remaining three lines of the test case describe the current locations of the Chef, the head server, and the sous-chef, respectively. Each such line contains two integers X,Y (at most 10,000 in absolute value) indicating that the respective person is located at position X,Y. Output For each test case you are to output a single line containing a single string. If it is possible for all three to communicate then you should output "yes". Otherwise, you should output "no". To be clear, we say that two transceivers are close enough to communicate directly if the length of the straight line connecting their X,Y coordinates is at most R. Example Input: 3 1 0 1 0 0 1 0 2 0 1 0 0 1 0 2 0 0 0 2 2 1 Output: yes yes no
[ "import math\nno_of_testcases = int(input())\nfor each in range(no_of_testcases):\n dist = int(input())\n point_1 = map(int,raw_input().split())\n point_2 = map(int,raw_input().split())\n point_3 = map(int,raw_input().split()) \n point_12 =math.sqrt( math.pow((point_1[0] -point_2[0]),2) + math.pow...
Frank explained its friend Felman the algorithm of Euclides to calculate the GCD of two numbers. Then Felman implements it algorithm int gcd(int a, int b) { if (b==0) return a; else return gcd(b,a%b); } and it proposes to Frank that makes it but with a little integer and another integer that has up to 250 digits. Your task is to help Frank programming an efficient code for the challenge of Felman. Input The first line of the input file contains a number representing the number of lines to follow. Each line consists of two number A and B (0 ≤ A ≤ 40000 and A ≤ B < 10^250). Output Print for each pair (A,B) in the input one integer representing the GCD of A and B. Example Input: 2 2 6 10 11 Output: 2 1
[ "def gcd(a,b):\n while(b):\n a,b=b,a%b\n return a\nt=input()\nwhile(t):\n a,b=map(int,raw_input().split())\n print(gcd(a,b))\n t=t-1;", "def gcd(a,b):\n\tif(a%b==0):\n\t\treturn b;\n\treturn gcd(b,a%b)\n\nt = int(raw_input())\n\nfor i in range(t):\n\ta = raw_input().split(\" \")\n\tprint gcd...
A Little Elephant from the Zoo of Lviv likes lucky strings, i.e., the strings that consist only of the lucky digits 4 and 7. The Little Elephant calls some string T of the length M balanced if there exists at least one integer X (1 ≤ X ≤ M) such that the number of digits 4 in the substring T[1, X - 1] is equal to the number of digits 7 in the substring T[X, M]. For example, the string S = 7477447 is balanced since S[1, 4] = 7477 has 1 digit 4 and S[5, 7] = 447 has 1 digit 7. On the other hand, one can verify that the string S = 7 is not balanced. The Little Elephant has the string S of the length N. He wants to know the number of such pairs of integers (L; R) that 1 ≤ L ≤ R ≤ N and the substring S[L, R] is balanced. Help him to find this number. Notes. Let S be some lucky string. Then |S| denotes the length of the string S; S[i] (1 ≤ i ≤ |S|) denotes the i^th character of S (the numeration of characters starts from 1); S[L, R] (1 ≤ L ≤ R ≤ |S|) denotes the string with the following sequence of characters: S[L], S[L + 1], ..., S[R], and is called a substring of S. For L > R we mean by S[L, R] an empty string. Input The first line of the input file contains a single integer T, the number of test cases. Each of the following T lines contains one string, the string S for the corresponding test case. The input file does not contain any whitespaces. Output For each test case output a single line containing the answer for this test case. Constraints 1 ≤ T ≤ 10 1 ≤ |S| ≤ 100000 S consists only of the lucky digits 4 and 7. Example Input: 4 47 74 477 4747477 Output: 2 2 3 23 Explanation In the first test case balance substrings are S[1, 1] = 4 and S[1, 2] = 47. In the second test case balance substrings are S[2, 2] = 4 and S[1, 2] = 74. Unfortunately, we can't provide you with the explanations of the third and the fourth test cases. You should figure it out by yourself. Please, don't ask about this in comments.
[ "n = input()\nfor i in range(n):\n str = raw_input()\n l = len(str)\n megacounter = 0\n counter = 0\n i = 0\n while(1):\n while(i<l and str[i]=='7'):\n i=i+1\n counter=counter+1\n if(i>=l):\n break\n megacounter = megacounter + (counter*(counte...
Given a string s. Can you make it a palindrome by deleting exactly one character? Note that size of the string after deletion would be one less than it was before. Input First line of the input contains a single integer T denoting number of test cases. For each test case, you are given a single line containing string s. Output For each test case, print YES or NO depending on the answer of the problem. Constraints Example Input: 4 aaa abc abdbca abba Output: YES NO YES YES Explanation Example case 1. Delete any one 'a', resulting string is "aa" which is a palindrome. Example case 2. It is not possible to delete exactly one character and having a palindrome. Example case 3. Delete 'c', resulting string is "abdba" which is a palindrome. Example case 4. Delete 'b', resulting string is "aba" which is a palindrome.
[ "import math\nimport sys\ndef checkpal(s):\n return s==s[::-1]\nfor a in range(input()):\n s=raw_input()\n l=len(s)\n if(l==2):\n print \"YES\"\n else:\n if checkpal(s):\n print \"YES\"\n else:\n while s[0] == s[-1] and len(s)>2:\n\t s=s[1:-1]\n\t...
An established group of scientists are working on finding solution to NP hard problems. They claim Subset Sum as an NP-hard problem. The problem is to determine whether there exists a subset of a given set S whose sum is a given number K. You are a computer engineer and you claim to solve this problem given that all numbers in the set are non-negative. Given a set S of size N of non-negative integers, find whether there exists a subset whose sum is K. Input First line of input contains T, the number of test cases. T test cases follow. Each test case contains 2 lines. First line contains two integers N and K. Next line contains N space separated non-negative integers (each less than 100000). 0 < T < 1000 0 < N < 1000 0 < K < 1000 Output Output T lines, one for each test case. Every line should be either 0 or 1 depending on whether such a subset exists or not. Example Input: 2 5 10 3 4 6 1 9 3 2 1 3 4 Output: 1 0
[ "import sys\n\nfor __ in range(input()) :\n n , k = map(int,sys.stdin.readline().split())\n lists = map(int,sys.stdin.readline().split())\n dp = [0]*(k+1)\n dp[0]=1\n for i in lists :\n for j in range(k-i,-1,-1) :\n if dp[k] :\n break\n if dp[j] :\n ...
"You are given an array of n positive integers a_1, a_2, ..., a_n. You can perform the following ope(...TRUNCATED)
["#include <bits/stdc++.h>\nusing namespace std;\nconst int MAXN = 300000;\nmap<int, int> mapa;\nmap(...TRUNCATED)
"There are n persons who initially don't know each other. On each morning, two of them, who were not(...TRUNCATED)
["#include <bits/stdc++.h>\nusing namespace std;\nconst int module = 1000000007;\nint main() {\n io(...TRUNCATED)
"Let's call a string a phone number if it has length 11 and fits the pattern \"8xxxxxxxxxx\", where (...TRUNCATED)
["n = int(input())\ns = input()\nk = s.count(\"8\")\nl = n - k\nif k <= l//10: print(k)\nelse:\n (...TRUNCATED)
"Chouti thought about his very first days in competitive programming. When he had just learned to wr(...TRUNCATED)
["#include <bits/stdc++.h>\nconst int MAXN = 1e5 + 20;\nint n, k, M;\nint inv[MAXN], pre_inv[MAXN];\(...TRUNCATED)
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
17