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 |
|---|---|---|---|---|---|
p00682 Area of Polygons_38100 | Polygons are the most fundamental objects in geometric processing. Complex figures are often represented and handled as polygons with many short sides. If you are interested in the processing of geometric data, you'd better try some programming exercises about basic operations on polygons.
Your job in this problem is ... | #include <cstdio>
int n,x[50],y[50];
int main(){
for(int c=1;;c++){
float a=0;
scanf("%d",&n); if(!n) break;
for(int i=0; i<n; i++)
scanf("%d %d",&x[i],&y[i]);
for(int i=0; i<n; i++)
a += 0.5*(x[i]*y[(i+1)%n]-y[i]*x[(i+1)%n]);
a *= a>0?1:-1;
printf("%d %.1f\n",c,a);
}
} | 2C++ | {
"input": [
"3\n1 1\n3 4\n6 0\n\n7\n0 0\n10 10\n0 20\n10 30\n0 40\n100 40\n100 0\n\n0",
"3\n1 1\n3 4\n6 0\n\n7\n0 0\n10 10\n0 20\n10 33\n0 40\n100 40\n100 0\n\n0",
"3\n1 1\n3 4\n6 0\n\n7\n0 0\n10 10\n0 20\n10 33\n0 40\n110 40\n100 0\n\n0",
"3\n1 1\n3 4\n6 0\n\n7\n0 0\n10 10\n0 20\n10 30\n0 40\n100 40... | 6AIZU |
p00682 Area of Polygons_38101 | Polygons are the most fundamental objects in geometric processing. Complex figures are often represented and handled as polygons with many short sides. If you are interested in the processing of geometric data, you'd better try some programming exercises about basic operations on polygons.
Your job in this problem is ... | idx = 1
while True:
n = int(input())
if n==0: break
x = []
y = []
for _ in range(n):
a,b = map(int,input().split())
x.append(a)
y.append(b)
x.append(x[0])
y.append(y[0])
s = 0.0
for i in range(n):
s += x[i]*y[i+1] - x[i+1]*y[i]
print(idx, abs(s/2)... | 3Python3 | {
"input": [
"3\n1 1\n3 4\n6 0\n\n7\n0 0\n10 10\n0 20\n10 30\n0 40\n100 40\n100 0\n\n0",
"3\n1 1\n3 4\n6 0\n\n7\n0 0\n10 10\n0 20\n10 33\n0 40\n100 40\n100 0\n\n0",
"3\n1 1\n3 4\n6 0\n\n7\n0 0\n10 10\n0 20\n10 33\n0 40\n110 40\n100 0\n\n0",
"3\n1 1\n3 4\n6 0\n\n7\n0 0\n10 10\n0 20\n10 30\n0 40\n100 40... | 6AIZU |
p00682 Area of Polygons_38102 | Polygons are the most fundamental objects in geometric processing. Complex figures are often represented and handled as polygons with many short sides. If you are interested in the processing of geometric data, you'd better try some programming exercises about basic operations on polygons.
Your job in this problem is ... | import java.awt.geom.*;
import java.util.*;
public class Main {
//外積
private double cross(Point2D p1, Point2D p2) {
double res = p1.getX() * p2.getY() - p1.getY() * p2.getX();
return res;
}
private double area(ArrayList<Point2D> polygon) {
double res = 0.0;
int n = polygon.size();
for(int i = 0; i < n... | 4JAVA | {
"input": [
"3\n1 1\n3 4\n6 0\n\n7\n0 0\n10 10\n0 20\n10 30\n0 40\n100 40\n100 0\n\n0",
"3\n1 1\n3 4\n6 0\n\n7\n0 0\n10 10\n0 20\n10 33\n0 40\n100 40\n100 0\n\n0",
"3\n1 1\n3 4\n6 0\n\n7\n0 0\n10 10\n0 20\n10 33\n0 40\n110 40\n100 0\n\n0",
"3\n1 1\n3 4\n6 0\n\n7\n0 0\n10 10\n0 20\n10 30\n0 40\n100 40... | 6AIZU |
p00824 Gap_38103 | Let’s play a card game called Gap.
You have 28 cards labeled with two-digit numbers. The first digit (from 1 to 4) represents the suit of the card, and the second digit (from 1 to 7) represents the value of the card.
First, you shuffle the cards and lay them face up on the table in four rows of seven cards, leaving a... | #include <cstdio>
#include <queue>
#include <algorithm>
#include <map>
#include <cstring>
using namespace std;
struct Board {
char state[4][8];
Board(){}
};
bool operator< (const Board& lhs, const Board& rhs) {
return memcmp(&lhs, &rhs, sizeof(Board)) < 0;
}
int board[4][8];
void init() {
memset(board, 0, sizeo... | 2C++ | {
"input": [
"4\n\n12 13 14 15 16 17 21\n22 23 24 25 26 27 31\n32 33 34 35 36 37 41\n42 43 44 45 46 47 11\n\n26 31 13 44 21 24 42\n17 45 23 25 41 36 11\n46 34 14 12 37 32 47\n16 43 27 35 22 33 15\n\n17 12 16 13 15 14 11\n27 22 26 23 25 24 21\n37 32 36 33 35 34 31\n47 42 46 43 45 44 41\n\n27 14 22 35 32 46 33\n13 ... | 6AIZU |
p00824 Gap_38104 | Let’s play a card game called Gap.
You have 28 cards labeled with two-digit numbers. The first digit (from 1 to 4) represents the suit of the card, and the second digit (from 1 to 7) represents the value of the card.
First, you shuffle the cards and lay them face up on the table in four rows of seven cards, leaving a... | import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
//Gap
public class Main{
String trans(){
StringBuilder sb = new StringBuilder();
for(int i=0;i<4;i++)for(int j=0;j<8;j++){
sb.append(a[i][j]==0?"00":a[i][j]);
}
return sb.toString();
}
int min, INF = 1<<29;
int[][] a;
int[] po... | 4JAVA | {
"input": [
"4\n\n12 13 14 15 16 17 21\n22 23 24 25 26 27 31\n32 33 34 35 36 37 41\n42 43 44 45 46 47 11\n\n26 31 13 44 21 24 42\n17 45 23 25 41 36 11\n46 34 14 12 37 32 47\n16 43 27 35 22 33 15\n\n17 12 16 13 15 14 11\n27 22 26 23 25 24 21\n37 32 36 33 35 34 31\n47 42 46 43 45 44 41\n\n27 14 22 35 32 46 33\n13 ... | 6AIZU |
p00955 Cover the Polygon with Your Disk_38105 | Example
Input
4 4
0 0
6 0
6 6
0 6
Output
35.759506 | #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<complex>
#include<cassert>
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b)) < EPS)
#define COUNTER_CLOCKWISE 1
#... | 2C++ | {
"input": [
"4 4\n0 0\n6 0\n6 6\n0 6",
"4 2\n0 0\n6 0\n6 6\n0 6",
"4 1\n0 0\n6 0\n6 6\n0 6",
"4 1\n0 0\n6 0\n6 6\n0 9",
"4 1\n0 -1\n6 0\n6 6\n0 9",
"2 1\n0 -1\n6 0\n6 6\n0 9",
"4 4\n0 1\n6 0\n6 6\n0 6",
"4 2\n0 0\n6 0\n9 6\n0 6",
"4 1\n0 0\n6 1\n6 6\n0 6",
"4 4\n0 1\n6 -1\n6 6... | 6AIZU |
p01088 500-yen Saving_38106 | 500-yen Saving
"500-yen Saving" is one of Japanese famous methods to save money. The method is quite simple; whenever you receive a 500-yen coin in your change of shopping, put the coin to your 500-yen saving box. Typically, you will find more than one million yen in your saving box in ten years.
Some Japanese people... | while 1:
n = input()
if n == 0:
break
L = 500*n
dp = [None]*(L+1)
dp[0] = (0, 0)
for i in xrange(n):
dp2 = dp[:]
cost = int(raw_input())
d3 = cost % 1000
for j in xrange(L+1):
if dp[j] is None:
continue
num, su = dp[... | 1Python2 | {
"input": [
"4\n800\n700\n1600\n600\n4\n300\n700\n1600\n600\n4\n300\n700\n1600\n650\n3\n1000\n2000\n500\n3\n250\n250\n1000\n4\n1251\n667\n876\n299\n0",
"4\n800\n700\n1600\n600\n4\n300\n700\n1600\n30\n4\n300\n700\n1600\n650\n3\n1000\n2000\n500\n3\n250\n250\n1000\n4\n1251\n667\n876\n299\n0",
"4\n800\n700\n... | 6AIZU |
p01088 500-yen Saving_38107 | 500-yen Saving
"500-yen Saving" is one of Japanese famous methods to save money. The method is quite simple; whenever you receive a 500-yen coin in your change of shopping, put the coin to your 500-yen saving box. Typically, you will find more than one million yen in your saving box in ten years.
Some Japanese people... | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ld eps = 1e-9;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LIN... | 2C++ | {
"input": [
"4\n800\n700\n1600\n600\n4\n300\n700\n1600\n600\n4\n300\n700\n1600\n650\n3\n1000\n2000\n500\n3\n250\n250\n1000\n4\n1251\n667\n876\n299\n0",
"4\n800\n700\n1600\n600\n4\n300\n700\n1600\n30\n4\n300\n700\n1600\n650\n3\n1000\n2000\n500\n3\n250\n250\n1000\n4\n1251\n667\n876\n299\n0",
"4\n800\n700\n... | 6AIZU |
p01088 500-yen Saving_38108 | 500-yen Saving
"500-yen Saving" is one of Japanese famous methods to save money. The method is quite simple; whenever you receive a 500-yen coin in your change of shopping, put the coin to your 500-yen saving box. Typically, you will find more than one million yen in your saving box in ten years.
Some Japanese people... | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+9
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.... | 3Python3 | {
"input": [
"4\n800\n700\n1600\n600\n4\n300\n700\n1600\n600\n4\n300\n700\n1600\n650\n3\n1000\n2000\n500\n3\n250\n250\n1000\n4\n1251\n667\n876\n299\n0",
"4\n800\n700\n1600\n600\n4\n300\n700\n1600\n30\n4\n300\n700\n1600\n650\n3\n1000\n2000\n500\n3\n250\n250\n1000\n4\n1251\n667\n876\n299\n0",
"4\n800\n700\n... | 6AIZU |
p01088 500-yen Saving_38109 | 500-yen Saving
"500-yen Saving" is one of Japanese famous methods to save money. The method is quite simple; whenever you receive a 500-yen coin in your change of shopping, put the coin to your 500-yen saving box. Typically, you will find more than one million yen in your saving box in ten years.
Some Japanese people... | import java.util.Scanner;
public class Main {
final int MAX_M = 100 * 1000;
void run() {
Scanner scan = new Scanner(System.in);
while (true) {
int n = scan.nextInt();
if (n == 0)
return;
int[] p = new int[n];
for (int i = 0; i < n; i++)
p[i] = scan.nextInt();
int[][] dp = new int[n + 1... | 4JAVA | {
"input": [
"4\n800\n700\n1600\n600\n4\n300\n700\n1600\n600\n4\n300\n700\n1600\n650\n3\n1000\n2000\n500\n3\n250\n250\n1000\n4\n1251\n667\n876\n299\n0",
"4\n800\n700\n1600\n600\n4\n300\n700\n1600\n30\n4\n300\n700\n1600\n650\n3\n1000\n2000\n500\n3\n250\n250\n1000\n4\n1251\n667\n876\n299\n0",
"4\n800\n700\n... | 6AIZU |
p01224 Perfect Number_38110 | Let S be the sum of divisors of an integer N excluding the number itself. When N = S, N is called a perfect number, when N> S, N is called a defendant number, and when N <S, N is called an abundant number. Create a program that determines whether a given integer is a perfect number, a missing number, or an abundant num... | def div(n):
ls = []
i = 2
while i*i <= n:
c = 0
if n%i==0:
while n%i==0:
n /= i
c += 1
if c > 0:
ls.append([i,c])
i += 1
if n > 1:
ls.append([n,1])
ans = 1
for b,p in ls:
ans *= (b**(p+1)-1)/(b-1)
return ans
while 1:
n = input()
if n == 0: break
d = div(n) - n
if d == n:
print "... | 1Python2 | {
"input": [
"1\n2\n3\n4\n6\n12\n16\n28\n33550336\n99999998\n99999999\n100000000\n0",
"1\n2\n3\n4\n6\n12\n16\n28\n33550336\n99999998\n99999999\n100001000\n0",
"1\n2\n5\n4\n6\n12\n16\n28\n820514\n99999998\n99999999\n100001100\n0",
"1\n2\n5\n4\n6\n12\n18\n28\n820514\n99999998\n99999999\n100001100\n0",
... | 6AIZU |
p01224 Perfect Number_38111 | Let S be the sum of divisors of an integer N excluding the number itself. When N = S, N is called a perfect number, when N> S, N is called a defendant number, and when N <S, N is called an abundant number. Create a program that determines whether a given integer is a perfect number, a missing number, or an abundant num... | #include <iostream>
#include <algorithm>
#include <vector>
#define int long long
using namespace std;
class Solver{};
signed main() {
while (true) {
int n;
cin >> n;
if (n == 0)break;
int sum = 0;
for (int i = 1; i * i <= n; i++) {
if (n % i != 0)continue;
int other = n / i;
if (i == n)continu... | 2C++ | {
"input": [
"1\n2\n3\n4\n6\n12\n16\n28\n33550336\n99999998\n99999999\n100000000\n0",
"1\n2\n3\n4\n6\n12\n16\n28\n33550336\n99999998\n99999999\n100001000\n0",
"1\n2\n5\n4\n6\n12\n16\n28\n820514\n99999998\n99999999\n100001100\n0",
"1\n2\n5\n4\n6\n12\n18\n28\n820514\n99999998\n99999999\n100001100\n0",
... | 6AIZU |
p01224 Perfect Number_38112 | Let S be the sum of divisors of an integer N excluding the number itself. When N = S, N is called a perfect number, when N> S, N is called a defendant number, and when N <S, N is called an abundant number. Create a program that determines whether a given integer is a perfect number, a missing number, or an abundant num... | def f(p):
ans=1
if p<=5: return 0
for n in range(2,int(p**0.5)+1):
if p%n==0:
if n!=p//n:ans+=n+p//n
else:ans+=n
return ans
while 1:
n=int(input())
if n==0:break
m=f(n)
if n==m:print('perfect number')
else: print('deficient number' if n>m else 'abunda... | 3Python3 | {
"input": [
"1\n2\n3\n4\n6\n12\n16\n28\n33550336\n99999998\n99999999\n100000000\n0",
"1\n2\n3\n4\n6\n12\n16\n28\n33550336\n99999998\n99999999\n100001000\n0",
"1\n2\n5\n4\n6\n12\n16\n28\n820514\n99999998\n99999999\n100001100\n0",
"1\n2\n5\n4\n6\n12\n18\n28\n820514\n99999998\n99999999\n100001100\n0",
... | 6AIZU |
p01224 Perfect Number_38113 | Let S be the sum of divisors of an integer N excluding the number itself. When N = S, N is called a perfect number, when N> S, N is called a defendant number, and when N <S, N is called an abundant number. Create a program that determines whether a given integer is a perfect number, a missing number, or an abundant num... | import java.util.Scanner;
public class Main
{
public static void main(String arg[])
{
Scanner sc = new Scanner(System.in);
while(sc.hasNext())
{
int n=sc.nextInt();
if(n==0)
return;
if(n==1)
{
System.out.println("deficient number");
continue;
}
int sum=1;
for(int i=2;i*i<... | 4JAVA | {
"input": [
"1\n2\n3\n4\n6\n12\n16\n28\n33550336\n99999998\n99999999\n100000000\n0",
"1\n2\n3\n4\n6\n12\n16\n28\n33550336\n99999998\n99999999\n100001000\n0",
"1\n2\n5\n4\n6\n12\n16\n28\n820514\n99999998\n99999999\n100001100\n0",
"1\n2\n5\n4\n6\n12\n18\n28\n820514\n99999998\n99999999\n100001100\n0",
... | 6AIZU |
p01358 Usaneko Matrix_38114 | Rabbits and cats are competing. The rules are as follows.
First, each of the two animals wrote n2 integers on a piece of paper in a square with n rows and n columns, and drew one card at a time. Shuffle two cards and draw them one by one alternately. Each time a card is drawn, the two will mark it if the same number a... | from collections import defaultdict
n,u,v,m = map(int, raw_input().split())
U=defaultdict(tuple)
N=defaultdict(tuple)
for i in range(n):
l=map(int, raw_input().split())
for j in range(n):
U[ l[j] ] = (i,j)
for i in range(n):
l=map(int, raw_input().split())
for j in range(n):
N[ l[j] ] =... | 1Python2 | {
"input": [
"3 2 2 10\n1 2 3\n4 5 6\n7 8 9\n1 2 3\n6 5 4\n7 8 9\n11\n4\n7\n5\n10\n9\n2\n1\n3\n8",
"3 2 1 10\n1 2 3\n4 5 6\n7 8 9\n1 2 3\n6 5 4\n7 8 9\n11\n4\n7\n5\n10\n9\n2\n1\n3\n8",
"3 2 4 10\n1 2 3\n4 5 6\n7 8 9\n1 2 3\n6 5 4\n7 8 9\n11\n4\n7\n5\n10\n9\n2\n1\n3\n8",
"3 3 4 11\n1 2 3\n8 5 6\n7 8 9\... | 6AIZU |
p01358 Usaneko Matrix_38115 | Rabbits and cats are competing. The rules are as follows.
First, each of the two animals wrote n2 integers on a piece of paper in a square with n rows and n columns, and drew one card at a time. Shuffle two cards and draw them one by one alternately. Each time a card is drawn, the two will mark it if the same number a... | #include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
using namespace std;
int main() {
int n, u, v, m;
cin >> n >> u >> v >> m;
bool draw = true;
int val;
vector<pair<int,int>> usagi(1000001), neko(1000001);
vector<int> usanum,nekonum;
for(int i=0 ; i<n ; i++){
f... | 2C++ | {
"input": [
"3 2 2 10\n1 2 3\n4 5 6\n7 8 9\n1 2 3\n6 5 4\n7 8 9\n11\n4\n7\n5\n10\n9\n2\n1\n3\n8",
"3 2 1 10\n1 2 3\n4 5 6\n7 8 9\n1 2 3\n6 5 4\n7 8 9\n11\n4\n7\n5\n10\n9\n2\n1\n3\n8",
"3 2 4 10\n1 2 3\n4 5 6\n7 8 9\n1 2 3\n6 5 4\n7 8 9\n11\n4\n7\n5\n10\n9\n2\n1\n3\n8",
"3 3 4 11\n1 2 3\n8 5 6\n7 8 9\... | 6AIZU |
p01358 Usaneko Matrix_38116 | Rabbits and cats are competing. The rules are as follows.
First, each of the two animals wrote n2 integers on a piece of paper in a square with n rows and n columns, and drew one card at a time. Shuffle two cards and draw them one by one alternately. Each time a card is drawn, the two will mark it if the same number a... | # coding: utf-8
n,u,v,m=map(int,input().split())
usa=[list(map(int,input().split())) for i in range(n)]
neko=[list(map(int,input().split())) for i in range(n)]
usadic={}
nekodic={}
usatable=[0 for i in range(2*n+2)]
nekotable=[0 for i in range(2*n+2)]
for i in range(n):
for j in range(n):
usadic[usa[i][j]]=... | 3Python3 | {
"input": [
"3 2 2 10\n1 2 3\n4 5 6\n7 8 9\n1 2 3\n6 5 4\n7 8 9\n11\n4\n7\n5\n10\n9\n2\n1\n3\n8",
"3 2 1 10\n1 2 3\n4 5 6\n7 8 9\n1 2 3\n6 5 4\n7 8 9\n11\n4\n7\n5\n10\n9\n2\n1\n3\n8",
"3 2 4 10\n1 2 3\n4 5 6\n7 8 9\n1 2 3\n6 5 4\n7 8 9\n11\n4\n7\n5\n10\n9\n2\n1\n3\n8",
"3 3 4 11\n1 2 3\n8 5 6\n7 8 9\... | 6AIZU |
p01358 Usaneko Matrix_38117 | Rabbits and cats are competing. The rules are as follows.
First, each of the two animals wrote n2 integers on a piece of paper in a square with n rows and n columns, and drew one card at a time. Shuffle two cards and draw them one by one alternately. Each time a card is drawn, the two will mark it if the same number a... |
import java.awt.Point;
import java.io.*;
import java.util.*;
public class Main {
FastScanner in = new FastScanner(System.in);
PrintWriter out = new PrintWriter(System.out);
public void run() {
int n = in.nextInt(), u = in.nextInt(), v = in.nextInt(), m = in.nextInt();
HashMap<Integer, Point> rabbit = new H... | 4JAVA | {
"input": [
"3 2 2 10\n1 2 3\n4 5 6\n7 8 9\n1 2 3\n6 5 4\n7 8 9\n11\n4\n7\n5\n10\n9\n2\n1\n3\n8",
"3 2 1 10\n1 2 3\n4 5 6\n7 8 9\n1 2 3\n6 5 4\n7 8 9\n11\n4\n7\n5\n10\n9\n2\n1\n3\n8",
"3 2 4 10\n1 2 3\n4 5 6\n7 8 9\n1 2 3\n6 5 4\n7 8 9\n11\n4\n7\n5\n10\n9\n2\n1\n3\n8",
"3 3 4 11\n1 2 3\n8 5 6\n7 8 9\... | 6AIZU |
p01540 Treasure Hunt_38118 | Taro came to a square to look for treasure. There are many treasures buried in this square, but Taro has the latest machines, so he knows everything about where the treasures are buried. Since the square is very wide Taro decided to look for the treasure to decide the area, but the treasure is what treasure does not kn... | import bisect
inf = 1e10
n,m = map(int,raw_input().split())
xy = [map(int,raw_input().split()) for i in range(n)]
X = sorted([i[0] for i in xy] + [-inf-1] + [inf+1])
Y = sorted([i[1] for i in xy] + [-inf-1] + [inf+1])
s = [[0]*(n+10) for i in range(n+10)]
for i in range(n):
a = bisect.bisect_left(X,xy[i][0])
b = bis... | 1Python2 | {
"input": [
"5 5\n10 5\n-3 -8\n2 11\n6 0\n-1 3\n-3 1 3 13\n-1 -1 9 5\n-3 -8 10 11\n0 0 5 5\n-10 -9 15 10",
"3 1\n1 1\n2 4\n5 3\n0 0 5 5",
"4 2\n-1 1\n0 3\n4 0\n2 1\n-3 1 5 1\n4 0 4 0",
"2 3\n0 0\n0 0\n-1 -1 1 1\n0 0 2 2\n1 1 4 4",
"5 5\n10 5\n-3 -8\n2 11\n6 0\n-1 3\n-3 1 3 13\n-1 -1 9 9\n-3 -8 10... | 6AIZU |
p01540 Treasure Hunt_38119 | Taro came to a square to look for treasure. There are many treasures buried in this square, but Taro has the latest machines, so he knows everything about where the treasures are buried. Since the square is very wide Taro decided to look for the treasure to decide the area, but the treasure is what treasure does not kn... | #include <bits/stdc++.h>
using namespace std;
#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define allof(a) (a).begin(),(a).end()
void uniqueVector(vector< int >& vec) {
sort(allof(vec));
vec.erase(unique(allof(vec)), vec.end());
}
void solve(
int n, int m,
const vector< int >& tx, const vector< int >& ty
) {
... | 2C++ | {
"input": [
"5 5\n10 5\n-3 -8\n2 11\n6 0\n-1 3\n-3 1 3 13\n-1 -1 9 5\n-3 -8 10 11\n0 0 5 5\n-10 -9 15 10",
"3 1\n1 1\n2 4\n5 3\n0 0 5 5",
"4 2\n-1 1\n0 3\n4 0\n2 1\n-3 1 5 1\n4 0 4 0",
"2 3\n0 0\n0 0\n-1 -1 1 1\n0 0 2 2\n1 1 4 4",
"5 5\n10 5\n-3 -8\n2 11\n6 0\n-1 3\n-3 1 3 13\n-1 -1 9 9\n-3 -8 10... | 6AIZU |
p01540 Treasure Hunt_38120 | Taro came to a square to look for treasure. There are many treasures buried in this square, but Taro has the latest machines, so he knows everything about where the treasures are buried. Since the square is very wide Taro decided to look for the treasure to decide the area, but the treasure is what treasure does not kn... | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.... | 3Python3 | {
"input": [
"5 5\n10 5\n-3 -8\n2 11\n6 0\n-1 3\n-3 1 3 13\n-1 -1 9 5\n-3 -8 10 11\n0 0 5 5\n-10 -9 15 10",
"3 1\n1 1\n2 4\n5 3\n0 0 5 5",
"4 2\n-1 1\n0 3\n4 0\n2 1\n-3 1 5 1\n4 0 4 0",
"2 3\n0 0\n0 0\n-1 -1 1 1\n0 0 2 2\n1 1 4 4",
"5 5\n10 5\n-3 -8\n2 11\n6 0\n-1 3\n-3 1 3 13\n-1 -1 9 9\n-3 -8 10... | 6AIZU |
p01540 Treasure Hunt_38121 | Taro came to a square to look for treasure. There are many treasures buried in this square, but Taro has the latest machines, so he knows everything about where the treasures are buried. Since the square is very wide Taro decided to look for the treasure to decide the area, but the treasure is what treasure does not kn... | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class Main {
final Scanner sc=new Scanner(System.in);
public static void main(String[] args) {
long start=System.currentTimeMillis();
new Main().init();
//System.out.println((System.currentTimeMillis()-start)+"ms");
}
void init(){
... | 4JAVA | {
"input": [
"5 5\n10 5\n-3 -8\n2 11\n6 0\n-1 3\n-3 1 3 13\n-1 -1 9 5\n-3 -8 10 11\n0 0 5 5\n-10 -9 15 10",
"3 1\n1 1\n2 4\n5 3\n0 0 5 5",
"4 2\n-1 1\n0 3\n4 0\n2 1\n-3 1 5 1\n4 0 4 0",
"2 3\n0 0\n0 0\n-1 -1 1 1\n0 0 2 2\n1 1 4 4",
"5 5\n10 5\n-3 -8\n2 11\n6 0\n-1 3\n-3 1 3 13\n-1 -1 9 9\n-3 -8 10... | 6AIZU |
p01696 Broken Cipher Generator_38122 | Broken crypto generator
JAG (Japanese Alumni Group) is a mysterious organization composed of many programmers, and in order to enter the building where the headquarters of this organization is located, it is necessary to solve the ciphertext generated by a certain machine every time. This ciphertext consists of the sy... | #!/usr/bin/env python
# -*- coding: utf-8 -*-
let = [chr(i) for i in xrange(ord('A'), ord('Z') + 1)]
def reverse(s, pos):
res, rev = "", ""
p = 0
while p < len(s):
if s[p] == '[':
hoge, p = reverse(s[p + 1:], p + 1)
rev += hoge
elif s[p] == ']':
return re... | 1Python2 | {
"input": [
"A+A++A\nZ-Z--Z+-Z\n[ESREVER]\nJ---?---J\n++++++++A+++Z-----------A+++Z\n[[++-+--?[--++-?++-+++L]][-+-----+-O]]++++---+L\n.",
"A+A++A\nZ-Z--Z+-Z\n[ESRVEER]\nJ---?---J\n++++++++A+++Z-----------A+++Z\n[[++-+--?[--++-?++-+++L]][-+-----+-O]]++++---+L\n.",
"A+A++A\nZ-ZZ--+-Z\n[ESRVEER]\nJ---?---J\... | 6AIZU |
p01696 Broken Cipher Generator_38123 | Broken crypto generator
JAG (Japanese Alumni Group) is a mysterious organization composed of many programmers, and in order to enter the building where the headquarters of this organization is located, it is necessary to solve the ciphertext generated by a certain machine every time. This ciphertext consists of the sy... |
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#... | 2C++ | {
"input": [
"A+A++A\nZ-Z--Z+-Z\n[ESREVER]\nJ---?---J\n++++++++A+++Z-----------A+++Z\n[[++-+--?[--++-?++-+++L]][-+-----+-O]]++++---+L\n.",
"A+A++A\nZ-Z--Z+-Z\n[ESRVEER]\nJ---?---J\n++++++++A+++Z-----------A+++Z\n[[++-+--?[--++-?++-+++L]][-+-----+-O]]++++---+L\n.",
"A+A++A\nZ-ZZ--+-Z\n[ESRVEER]\nJ---?---J\... | 6AIZU |
p01696 Broken Cipher Generator_38124 | Broken crypto generator
JAG (Japanese Alumni Group) is a mysterious organization composed of many programmers, and in order to enter the building where the headquarters of this organization is located, it is necessary to solve the ciphertext generated by a certain machine every time. This ciphertext consists of the sy... | def pm_to_chr(s):
s=s.group()
if s[-1]=='?':
return 'A'
ans=chr((((ord(s[-1])+s.count('+')-s.count('-'))-ord('A'))%26)+ord('A'))
return ans
def reverse(s):
s=s.group()
s=s[1:-1]
ans=''.join(reversed(s))
return ans
import re
s=input()
while s!='.':
s=re.sub("[\+\-]*[\w?]",p... | 3Python3 | {
"input": [
"A+A++A\nZ-Z--Z+-Z\n[ESREVER]\nJ---?---J\n++++++++A+++Z-----------A+++Z\n[[++-+--?[--++-?++-+++L]][-+-----+-O]]++++---+L\n.",
"A+A++A\nZ-Z--Z+-Z\n[ESRVEER]\nJ---?---J\n++++++++A+++Z-----------A+++Z\n[[++-+--?[--++-?++-+++L]][-+-----+-O]]++++---+L\n.",
"A+A++A\nZ-ZZ--+-Z\n[ESRVEER]\nJ---?---J\... | 6AIZU |
p01696 Broken Cipher Generator_38125 | Broken crypto generator
JAG (Japanese Alumni Group) is a mysterious organization composed of many programmers, and in order to enter the building where the headquarters of this organization is located, it is necessary to solve the ciphertext generated by a certain machine every time. This ciphertext consists of the sy... | import java.util.*;
import java.math.*;
class Main{
public static void main(String[] args){
Solve s = new Solve();
s.solve();
}
}
class Solve{
Solve(){}
Scanner in = new Scanner(System.in);
void solve(){
while(in.hasNext()){
String s = in.next();
if(s.equals(".")) return;
System.out.println(cal... | 4JAVA | {
"input": [
"A+A++A\nZ-Z--Z+-Z\n[ESREVER]\nJ---?---J\n++++++++A+++Z-----------A+++Z\n[[++-+--?[--++-?++-+++L]][-+-----+-O]]++++---+L\n.",
"A+A++A\nZ-Z--Z+-Z\n[ESRVEER]\nJ---?---J\n++++++++A+++Z-----------A+++Z\n[[++-+--?[--++-?++-+++L]][-+-----+-O]]++++---+L\n.",
"A+A++A\nZ-ZZ--+-Z\n[ESRVEER]\nJ---?---J\... | 6AIZU |
p01840 Delivery to a Luxurious House_38126 | B-Mansion and courier
Problem Statement
Taro lives alone in a mansion. Taro, who loves studying, intends to study in his study in the house today. Taro can't concentrate outside the study, so he always studies in the study.
However, on this day, $ N $ of courier service to Taro arrived. $ i $ ($ 1 \ leq i \ leq N $)... | #include <bits/stdc++.h>
using namespace std;
int main(){
int n,m,t;
cin>>n>>m>>t;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin>>a[i];
}
sort(a.begin(),a.end());
int ans=a.front()-m;
for (int i = 1; i < n; ++i) {
if(a[i]-a[i-1]>2*m)ans+=(a[i]-a[i-1])-2*m;
}
... | 2C++ | {
"input": [
"1 1 5\n3",
"1 1 5\n6",
"1 1 10\n6",
"1 2 10\n6",
"1 0 10\n6",
"1 1 10\n10",
"1 2 9\n9",
"1 1 5\n5",
"1 1 19\n6",
"1 2 20\n6",
"1 0 19\n2",
"1 1 5\n1",
"1 1 33\n6",
"1 1 20\n6",
"1 1 58\n6",
"1 2 37\n6",
"1 1 101\n6",
"1 2 62\n6",
... | 6AIZU |
p01840 Delivery to a Luxurious House_38127 | B-Mansion and courier
Problem Statement
Taro lives alone in a mansion. Taro, who loves studying, intends to study in his study in the house today. Taro can't concentrate outside the study, so he always studies in the study.
However, on this day, $ N $ of courier service to Taro arrived. $ i $ ($ 1 \ leq i \ leq N $)... | l_raw = input().split()
l = [int(n) for n in l_raw]
a_raw = input().split()
a_ = [int(n) for n in a_raw]
study = 0
state = 0
now=0
for a in a_:
if state==0:
if l[1]<a-now:
study+=a-now-l[1]
now=a
state=1
elif state==1:
if 2*l[1]<a-now:
study+=a-now-2*l[1... | 3Python3 | {
"input": [
"1 1 5\n3",
"1 1 5\n6",
"1 1 10\n6",
"1 2 10\n6",
"1 0 10\n6",
"1 1 10\n10",
"1 2 9\n9",
"1 1 5\n5",
"1 1 19\n6",
"1 2 20\n6",
"1 0 19\n2",
"1 1 5\n1",
"1 1 33\n6",
"1 1 20\n6",
"1 1 58\n6",
"1 2 37\n6",
"1 1 101\n6",
"1 2 62\n6",
... | 6AIZU |
p01840 Delivery to a Luxurious House_38128 | B-Mansion and courier
Problem Statement
Taro lives alone in a mansion. Taro, who loves studying, intends to study in his study in the house today. Taro can't concentrate outside the study, so he always studies in the study.
However, on this day, $ N $ of courier service to Taro arrived. $ i $ ($ 1 \ leq i \ leq N $)... | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
FastScanner sc = new FastScanner();
int N = sc.nextInt();
int M = sc.nextInt();
int T = sc.nextInt();
int[] a = new int[N];
for(int i = 0; i < N; i++) {
a[i] = sc.nextI... | 4JAVA | {
"input": [
"1 1 5\n3",
"1 1 5\n6",
"1 1 10\n6",
"1 2 10\n6",
"1 0 10\n6",
"1 1 10\n10",
"1 2 9\n9",
"1 1 5\n5",
"1 1 19\n6",
"1 2 20\n6",
"1 0 19\n2",
"1 1 5\n1",
"1 1 33\n6",
"1 1 20\n6",
"1 1 58\n6",
"1 2 37\n6",
"1 1 101\n6",
"1 2 62\n6",
... | 6AIZU |
p01976 Anagram_38129 | problem
Given a sequence $ a_i $ of length $ N $. Output all integers $ K (1 \ le K \ le N) $ that satisfy the following conditions.
Condition: Well sorted $ a_1, \ cdots, a_K $ matches $ a_ {N-K + 1}, \ cdots, a_N $.
Example
Input
8
5 2 4 9 4 9 2 5
Output
1 2 4 6 7 8 | import sys,heapq
n=int(sys.stdin.readline())
a=[int(e) for e in sys.stdin.readline().split()]
r=[]
x=[]
y=[]
for i in range(1,n+1):
heapq.heappush(x,a[i-1])
heapq.heappush(y,a[n-i])
while x and y and x[0]==y[0]:
heapq.heappop(x)
heapq.heappop(y)
if not x and not y: r.append(i)
print(' '.join(str(e) for e in r))... | 1Python2 | {
"input": [
"8\n5 2 4 9 4 9 2 5",
"8\n5 2 4 4 4 9 2 5",
"8\n5 2 4 4 4 14 2 0",
"8\n-1 10 7 2 2 1 -1 -1",
"8\n-1 0 3 32 0 4 -1 0",
"8\n0 1 1 -16 -1 0 1 1",
"8\n0 1 1 -24 -1 1 1 0",
"8\n-1 1 0 -2 1 0 -1 -2",
"8\n5 2 4 4 4 14 2 5",
"8\n5 2 4 4 4 11 2 0",
"8\n5 2 6 4 4 11 2 0"... | 6AIZU |
p01976 Anagram_38130 | problem
Given a sequence $ a_i $ of length $ N $. Output all integers $ K (1 \ le K \ le N) $ that satisfy the following conditions.
Condition: Well sorted $ a_1, \ cdots, a_K $ matches $ a_ {N-K + 1}, \ cdots, a_N $.
Example
Input
8
5 2 4 9 4 9 2 5
Output
1 2 4 6 7 8 | #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)
int main(){
int n;
cin>>n;
vector<int> a(n);
rep(i,n)cin>>a[i];
multis... | 2C++ | {
"input": [
"8\n5 2 4 9 4 9 2 5",
"8\n5 2 4 4 4 9 2 5",
"8\n5 2 4 4 4 14 2 0",
"8\n-1 10 7 2 2 1 -1 -1",
"8\n-1 0 3 32 0 4 -1 0",
"8\n0 1 1 -16 -1 0 1 1",
"8\n0 1 1 -24 -1 1 1 0",
"8\n-1 1 0 -2 1 0 -1 -2",
"8\n5 2 4 4 4 14 2 5",
"8\n5 2 4 4 4 11 2 0",
"8\n5 2 6 4 4 11 2 0"... | 6AIZU |
p01976 Anagram_38131 | problem
Given a sequence $ a_i $ of length $ N $. Output all integers $ K (1 \ le K \ le N) $ that satisfy the following conditions.
Condition: Well sorted $ a_1, \ cdots, a_K $ matches $ a_ {N-K + 1}, \ cdots, a_N $.
Example
Input
8
5 2 4 9 4 9 2 5
Output
1 2 4 6 7 8 | from collections import Counter
n = int(input())
a = input().split()
# a = list(map(int, input().split()))
ans = ''
# t1, t2 = [], []
t1, t2 = Counter(), Counter()
for i in range(n):
t1.update(a[i])
t2.update(a[n-1-i])
t3 = t1 & t2
t1 -= t3
t2 -= t3
if t1 == t2:
ans += str(i+1) + ' '
pr... | 3Python3 | {
"input": [
"8\n5 2 4 9 4 9 2 5",
"8\n5 2 4 4 4 9 2 5",
"8\n5 2 4 4 4 14 2 0",
"8\n-1 10 7 2 2 1 -1 -1",
"8\n-1 0 3 32 0 4 -1 0",
"8\n0 1 1 -16 -1 0 1 1",
"8\n0 1 1 -24 -1 1 1 0",
"8\n-1 1 0 -2 1 0 -1 -2",
"8\n5 2 4 4 4 14 2 5",
"8\n5 2 4 4 4 11 2 0",
"8\n5 2 6 4 4 11 2 0"... | 6AIZU |
p01976 Anagram_38132 | problem
Given a sequence $ a_i $ of length $ N $. Output all integers $ K (1 \ le K \ le N) $ that satisfy the following conditions.
Condition: Well sorted $ a_1, \ cdots, a_K $ matches $ a_ {N-K + 1}, \ cdots, a_N $.
Example
Input
8
5 2 4 9 4 9 2 5
Output
1 2 4 6 7 8 | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] lst = new int[n];
for (int i=0;i<n;i++) {
lst[i] = sc.nextInt();
}
HashMap<Integer, Integer> dict = new HashMap<Integer, Integer>();
ArrayList<Integer> ans ... | 4JAVA | {
"input": [
"8\n5 2 4 9 4 9 2 5",
"8\n5 2 4 4 4 9 2 5",
"8\n5 2 4 4 4 14 2 0",
"8\n-1 10 7 2 2 1 -1 -1",
"8\n-1 0 3 32 0 4 -1 0",
"8\n0 1 1 -16 -1 0 1 1",
"8\n0 1 1 -24 -1 1 1 0",
"8\n-1 1 0 -2 1 0 -1 -2",
"8\n5 2 4 4 4 14 2 5",
"8\n5 2 4 4 4 11 2 0",
"8\n5 2 6 4 4 11 2 0"... | 6AIZU |
p02122 RMQ 2_38133 | Problem
Given two sequences of length $ N $, $ A $ and $ B $. First, the $ i $ item in the sequence $ A $ is $ a_i $, and the $ i $ item in the sequence $ B $ is $ b_i $.
Since a total of $ Q $ of statements of the following format are given, create a program that processes in the given order.
Each statement is repr... | #include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define pb push_back
struct MinSegTree{
int n;
vector<int> dat;
MinSegTree(){}
MinSegTree(int _n){
n = 1;
while(n<_n) n*=2;
dat = vector<int>(2*n-1,INT_MAX);
}
void update(i... | 2C++ | {
"input": [
"5\n1 3 5 7 9\n6 2 3 2 6\n10\n1 3 4\n3 4 5\n4 2 3\n5 -1 -1\n2 3 8\n3 2 5\n4 3 3\n1 1 1\n6 -1 -1\n3 1 5",
"5\n1 3 5 7 9\n6 2 3 2 6\n10\n1 3 4\n3 4 5\n4 2 3\n5 -1 -1\n2 3 8\n3 2 5\n4 3 3\n2 1 1\n6 -1 -1\n3 1 5",
"5\n1 3 5 7 9\n6 2 3 2 6\n10\n1 3 4\n3 4 5\n4 2 3\n5 -1 -1\n2 3 16\n3 2 5\n4 3 3\n1... | 6AIZU |
p02122 RMQ 2_38134 | Problem
Given two sequences of length $ N $, $ A $ and $ B $. First, the $ i $ item in the sequence $ A $ is $ a_i $, and the $ i $ item in the sequence $ B $ is $ b_i $.
Since a total of $ Q $ of statements of the following format are given, create a program that processes in the given order.
Each statement is repr... | 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.InputMismatchException;
import java.util.List;
public class Main {
static InputStream is;
static PrintWriter out;
static Stri... | 4JAVA | {
"input": [
"5\n1 3 5 7 9\n6 2 3 2 6\n10\n1 3 4\n3 4 5\n4 2 3\n5 -1 -1\n2 3 8\n3 2 5\n4 3 3\n1 1 1\n6 -1 -1\n3 1 5",
"5\n1 3 5 7 9\n6 2 3 2 6\n10\n1 3 4\n3 4 5\n4 2 3\n5 -1 -1\n2 3 8\n3 2 5\n4 3 3\n2 1 1\n6 -1 -1\n3 1 5",
"5\n1 3 5 7 9\n6 2 3 2 6\n10\n1 3 4\n3 4 5\n4 2 3\n5 -1 -1\n2 3 16\n3 2 5\n4 3 3\n1... | 6AIZU |
p02262 Shell Sort_38135 | Shell Sort
Shell Sort is a generalization of Insertion Sort to arrange a list of $n$ elements $A$.
1 insertionSort(A, n, g)
2 for i = g to n-1
3 v = A[i]
4 j = i - g
5 while j >= 0 && A[j] > v
6 A[j+g] = A[j]
7 j = j - g
8 cnt++
9 A[j+g... | cnt = 0
def insertionSort(A, n, g):
global cnt
for i in range(g, n):
v = A[i]
j = i-g
while j >= 0 and A[j] > v:
A[j+g] = A[j]
j -= g
cnt += 1
A[j+g] = v
def shellSort(A, n):
G = [1]
while G[-1]*3+1 < n:
G.append(G[-1]*3 + 1)... | 1Python2 | {
"input": [
"5\n5\n1\n4\n3\n2",
"3\n3\n2\n1",
"5\n5\n1\n4\n5\n2",
"3\n6\n2\n1",
"5\n6\n1\n4\n5\n2",
"3\n0\n2\n1",
"5\n6\n1\n4\n9\n2",
"3\n-1\n2\n1",
"5\n6\n1\n4\n6\n2",
"3\n0\n2\n0",
"5\n5\n1\n4\n9\n2",
"3\n0\n1\n0",
"5\n7\n1\n4\n9\n2",
"3\n1\n1\n0",
"5\n7\... | 6AIZU |
p02262 Shell Sort_38136 | Shell Sort
Shell Sort is a generalization of Insertion Sort to arrange a list of $n$ elements $A$.
1 insertionSort(A, n, g)
2 for i = g to n-1
3 v = A[i]
4 j = i - g
5 while j >= 0 && A[j] > v
6 A[j+g] = A[j]
7 j = j - g
8 cnt++
9 A[j+g... | #include<bits/stdc++.h>
using namespace std;
#define int long long
int cnt, a[1000100];
void insertionSort(int a[],int n, int g){
int v,j;
for(int i = g; i < n; i++){
v = a[i];
j = i-g;
while(j >= 0 && a[j] > v){
a[j+g]=a[j];
j-=g;
cnt++;
}
a[j+g] = v;
}
}
void shellSort(int a[], int n){
int m... | 2C++ | {
"input": [
"5\n5\n1\n4\n3\n2",
"3\n3\n2\n1",
"5\n5\n1\n4\n5\n2",
"3\n6\n2\n1",
"5\n6\n1\n4\n5\n2",
"3\n0\n2\n1",
"5\n6\n1\n4\n9\n2",
"3\n-1\n2\n1",
"5\n6\n1\n4\n6\n2",
"3\n0\n2\n0",
"5\n5\n1\n4\n9\n2",
"3\n0\n1\n0",
"5\n7\n1\n4\n9\n2",
"3\n1\n1\n0",
"5\n7\... | 6AIZU |
p02262 Shell Sort_38137 | Shell Sort
Shell Sort is a generalization of Insertion Sort to arrange a list of $n$ elements $A$.
1 insertionSort(A, n, g)
2 for i = g to n-1
3 v = A[i]
4 j = i - g
5 while j >= 0 && A[j] > v
6 A[j+g] = A[j]
7 j = j - g
8 cnt++
9 A[j+g... | def insertionSort(a, n, g):
global cnt
for i in range(g, n):
v = a[i]
j = i - g
while j >= 0 and a[j] > v:
a[j+g] = a[j]
j = j - g
cnt = cnt + 1
a[j+g] = v
def shellSort(a, n):
global cnt
global G
global m
cnt = 0
G = [1]
... | 3Python3 | {
"input": [
"5\n5\n1\n4\n3\n2",
"3\n3\n2\n1",
"5\n5\n1\n4\n5\n2",
"3\n6\n2\n1",
"5\n6\n1\n4\n5\n2",
"3\n0\n2\n1",
"5\n6\n1\n4\n9\n2",
"3\n-1\n2\n1",
"5\n6\n1\n4\n6\n2",
"3\n0\n2\n0",
"5\n5\n1\n4\n9\n2",
"3\n0\n1\n0",
"5\n7\n1\n4\n9\n2",
"3\n1\n1\n0",
"5\n7\... | 6AIZU |
p02262 Shell Sort_38138 | Shell Sort
Shell Sort is a generalization of Insertion Sort to arrange a list of $n$ elements $A$.
1 insertionSort(A, n, g)
2 for i = g to n-1
3 v = A[i]
4 j = i - g
5 while j >= 0 && A[j] > v
6 A[j+g] = A[j]
7 j = j - g
8 cnt++
9 A[j+g... |
import java.util.ArrayList;
import java.util.Scanner;
//this implements the shell sort algorithm
public class Main {
public static int cnt = 0;
// do insertion sort with a given interval
public static void insertion_sort(int[] arr, int inv) {
int n = arr.length;
for(int i = inv; i < n; i ++) {
int key = a... | 4JAVA | {
"input": [
"5\n5\n1\n4\n3\n2",
"3\n3\n2\n1",
"5\n5\n1\n4\n5\n2",
"3\n6\n2\n1",
"5\n6\n1\n4\n5\n2",
"3\n0\n2\n1",
"5\n6\n1\n4\n9\n2",
"3\n-1\n2\n1",
"5\n6\n1\n4\n6\n2",
"3\n0\n2\n0",
"5\n5\n1\n4\n9\n2",
"3\n0\n1\n0",
"5\n7\n1\n4\n9\n2",
"3\n1\n1\n0",
"5\n7\... | 6AIZU |
p02410 Matrix Vector Multiplication_38139 | Write a program which reads a $ n \times m$ matrix $A$ and a $m \times 1$ vector $b$, and prints their product $Ab$.
A column vector with m elements is represented by the following equation.
\\[ b = \left( \begin{array}{c} b_1 \\\ b_2 \\\ : \\\ b_m \\\ \end{array} \right) \\]
A $n \times m$ matrix with $m$ column ve... | # coding:utf-8
array = map(int, raw_input().split())
n = array[0]
m = array[1]
a = [[0 for i in range(m)] for j in range(n)]
b = [0 for i in range(m)]
answer = [0 for i in range(n)]
for i in range(n):
a[i] = map(int, raw_input().split())
for j in range(m):
b[j] = input()
for i in range(n):
for j in range(m)... | 1Python2 | {
"input": [
"3 4\n1 2 0 1\n0 3 0 1\n4 1 1 0\n1\n2\n3\n0",
"3 4\n1 4 0 1\n0 3 0 1\n4 1 1 0\n1\n2\n3\n0",
"3 4\n1 2 0 1\n0 3 0 1\n4 1 2 0\n1\n2\n3\n0",
"3 4\n1 4 0 1\n0 3 1 1\n4 1 1 0\n1\n2\n3\n0",
"3 4\n1 4 0 1\n0 3 1 1\n4 1 1 0\n1\n2\n0\n0",
"3 4\n1 4 -1 1\n0 3 0 1\n4 1 1 0\n1\n2\n3\n0",
... | 6AIZU |
p02410 Matrix Vector Multiplication_38140 | Write a program which reads a $ n \times m$ matrix $A$ and a $m \times 1$ vector $b$, and prints their product $Ab$.
A column vector with m elements is represented by the following equation.
\\[ b = \left( \begin{array}{c} b_1 \\\ b_2 \\\ : \\\ b_m \\\ \end{array} \right) \\]
A $n \times m$ matrix with $m$ column ve... | #include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
int a[100][100], b[100];
int main() {
int n, m; cin >> n >> m;
rep(i, n)rep(j, m)cin >> a[i][j];
rep(i, m)cin >> b[i];
rep(i, n) {
int sum = 0;
rep(j, m)sum += a[i][j] * b[j];
cout << sum << endl;
}
} | 2C++ | {
"input": [
"3 4\n1 2 0 1\n0 3 0 1\n4 1 1 0\n1\n2\n3\n0",
"3 4\n1 4 0 1\n0 3 0 1\n4 1 1 0\n1\n2\n3\n0",
"3 4\n1 2 0 1\n0 3 0 1\n4 1 2 0\n1\n2\n3\n0",
"3 4\n1 4 0 1\n0 3 1 1\n4 1 1 0\n1\n2\n3\n0",
"3 4\n1 4 0 1\n0 3 1 1\n4 1 1 0\n1\n2\n0\n0",
"3 4\n1 4 -1 1\n0 3 0 1\n4 1 1 0\n1\n2\n3\n0",
... | 6AIZU |
p02410 Matrix Vector Multiplication_38141 | Write a program which reads a $ n \times m$ matrix $A$ and a $m \times 1$ vector $b$, and prints their product $Ab$.
A column vector with m elements is represented by the following equation.
\\[ b = \left( \begin{array}{c} b_1 \\\ b_2 \\\ : \\\ b_m \\\ \end{array} \right) \\]
A $n \times m$ matrix with $m$ column ve... | n, m = list(map(int, input().split()))
matrix_a = [list(map(int, input().split())) for i in range(n)]
matrix_b = [int(input()) for i in range(m)]
for i in range(n):
print(sum([x*y for (x,y) in zip(matrix_b,matrix_a[i])])) | 3Python3 | {
"input": [
"3 4\n1 2 0 1\n0 3 0 1\n4 1 1 0\n1\n2\n3\n0",
"3 4\n1 4 0 1\n0 3 0 1\n4 1 1 0\n1\n2\n3\n0",
"3 4\n1 2 0 1\n0 3 0 1\n4 1 2 0\n1\n2\n3\n0",
"3 4\n1 4 0 1\n0 3 1 1\n4 1 1 0\n1\n2\n3\n0",
"3 4\n1 4 0 1\n0 3 1 1\n4 1 1 0\n1\n2\n0\n0",
"3 4\n1 4 -1 1\n0 3 0 1\n4 1 1 0\n1\n2\n3\n0",
... | 6AIZU |
p02410 Matrix Vector Multiplication_38142 | Write a program which reads a $ n \times m$ matrix $A$ and a $m \times 1$ vector $b$, and prints their product $Ab$.
A column vector with m elements is represented by the following equation.
\\[ b = \left( \begin{array}{c} b_1 \\\ b_2 \\\ : \\\ b_m \\\ \end{array} \right) \\]
A $n \times m$ matrix with $m$ column ve... | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int m = in.nextInt();
int[][] a = new int[n][m];
int[] b = new int[m];
int[] c = new int[n];
for (int i = 0; i < n; i++) {
for (int j =... | 4JAVA | {
"input": [
"3 4\n1 2 0 1\n0 3 0 1\n4 1 1 0\n1\n2\n3\n0",
"3 4\n1 4 0 1\n0 3 0 1\n4 1 1 0\n1\n2\n3\n0",
"3 4\n1 2 0 1\n0 3 0 1\n4 1 2 0\n1\n2\n3\n0",
"3 4\n1 4 0 1\n0 3 1 1\n4 1 1 0\n1\n2\n3\n0",
"3 4\n1 4 0 1\n0 3 1 1\n4 1 1 0\n1\n2\n0\n0",
"3 4\n1 4 -1 1\n0 3 0 1\n4 1 1 0\n1\n2\n3\n0",
... | 6AIZU |
arithm_38143 | Chef's encounters with sweets continue with this problem! This time, he wants to distribute chocolates to his N students sitting on a long bench. The students are ordered according to the scores they got from the last exam.
Chef wants to give more chocolates to the higher-scoring students. He also has a few more restr... | t=input()
while t!=0:
n,c=raw_input().split(' ')
n=int(n)
c=int(c)
s=0
flag=0
d=1
first=0
last=0
while d<=2:
first=(2*c-n*(n-1)*d)/(2*n)
if first<1:
flag=0
break
last=first+(n-1)*d
s=n*(first + last)/2
... | 1Python2 | {
"input": [
"2\n4 24\n2 2"
],
"output": [
"Yes\nNo"
]
} | 1CODECHEF |
clco03_38144 | Arush was not always poor at Mathematics but his recent performances had not been that good and he had lost his confidence. Now his elder brother was determined to bring back his confidence back in Mathematics.
So he made a tricky question and made sure that Arush would be able to do solve it. The factorial of a non-ne... | t=input()
for x in range(t):
l=input()
r=raw_input()
s=''
for i in range(l):
# if i==0 or i==1:
# continue
if r[i]=='2' or r[i]=='3' or r[i]=='5' or r[i]=='7':
s=s+r[i]
elif r[i]=='4':
s=s+'322'
elif r[i]=='6':
s+='35'
elif r[i]=='8':
s+='2227'
elif r[i]=='9':
s+='7332'
s=sorted(s)
k='... | 1Python2 | {
"input": [
"2\n1\n6\n3\n006"
],
"output": [
"53\n53"
]
} | 1CODECHEF |
fctrl2_38145 | A tutorial for this problem is now available on our blog. Click here to read it.
You are asked to calculate factorials of some small positive integers.
Input
An integer t, 1 ≤ t ≤ 100, denoting the number of testcases, followed by t lines, each containing a single integer n, 1 ≤ n ≤ 100.
Output
For each integer n ... | t=input()
while t > 0:
m=1
x=input()
for i in range(x):
m=m * x
x=x-1
print m
t=t-1 | 1Python2 | {
"input": [
"4\n1\n2\n5\n3",
"4\n2\n2\n5\n3",
"4\n2\n2\n5\n6",
"4\n2\n2\n8\n6",
"4\n2\n2\n2\n6",
"4\n1\n2\n2\n6",
"4\n1\n2\n2\n9",
"4\n2\n2\n2\n9",
"4\n2\n2\n4\n9",
"4\n3\n2\n4\n9",
"4\n3\n2\n4\n3",
"4\n3\n2\n2\n3",
"4\n1\n2\n4\n3",
"4\n2\n2\n6\n3",
"4\n1\n... | 1CODECHEF |
lebamboo_38146 | Problem Statement
Little Elephant from Zoo of Lviv likes bamboo very much. He currently has n stems of bamboo, Hi - height of i-th stem of bamboo (0-based numeration).
Today inspector Andrii from World Bamboo Association is visiting the plantation. He doesn't like current situation. He wants the height of i-th stem t... | for _ in xrange(int(raw_input())):
n = int(raw_input())
l1 = map(int, raw_input().split())
l2 = map(int, raw_input().split())
s1 = sum(l1)
s2 = sum(l2)
if n == 1:
if s2 > s1:
print -1
if s2 == s1:
print 0
if s1 > s2:
print s1 - s2
elif n == 2:
if s1 != s2:
print -1
else:
print abs(l1[0] ... | 1Python2 | {
"input": [
"3\n1\n1\n2\n2\n1 2\n2 1\n3\n3 2 2\n4 5 3",
"3\n1\n1\n2\n2\n1 2\n2 1\n1\n3 2 2\n4 5 3",
"3\n1\n1\n2\n2\n0 2\n2 1\n1\n3 2 2\n4 5 3",
"3\n1\n1\n2\n2\n2 2\n2 1\n3\n3 2 2\n4 5 3",
"3\n1\n0\n2\n2\n0 2\n2 0\n1\n3 2 2\n4 5 3",
"3\n1\n2\n2\n2\n2 2\n2 1\n1\n3 2 2\n4 5 3",
"3\n1\n1\n0\n... | 1CODECHEF |
plgrm_38147 | For Turbo C++ Users : Read the following document before attempting the question :
Problem Description
N-Boy is very eccentric when it comes to strings. These days, he spends most of his time studying palindromes and pangrams (for his IP assignment at IIITD). For those of you who don’t know, a palindrome is a word ... | #Enter your code here
import sys
a=set('abcdefghijklmnopqrstuvwxzy')
sys.stdin.readline()
f=sys.stdin.readlines()
for i in f:
i=i.strip()
if i[::-1]==i and set(i)==a:print 'palingram'
elif i[::-1]==i:print 'palindrome'
elif set(i)==a:print 'pangram'
else:print 'none' | 1Python2 | {
"input": [
"3\nabba\nabcdefghijklmnopqrstuvwxyz\nqwerty",
"3\nabba\nfbcdeaghijklmnopqrstuvwxyz\nqwerty",
"3\nabba\ngbcdeaghijklmnopqrstuvwxyz\nqwerty",
"3\naaba\ngbcdeaghijklmnopqrstuvwxyz\nqwerty",
"3\nabab\nfbcdeaynijklmhopqrstuvwxgz\newqrty",
"3\naaba\ngbcdeaghijklmnopqrstuvwxyz\nqwertz",... | 1CODECHEF |
sub_perm_38148 | A factory called 'IP Labs Pvt. Ltd.' has produced some material, which is in the form of blocks. Each block is labeled by an alphanumeric character. You've been recently hired as Packaging Manager, and your job is to rearrange the huge lot of manufactured blocks and then extract out the useful blocks from it which can ... | import sys
t=int(input())
while t>0:
A=list(raw_input())
B=list(raw_input())
C=list(set(B))
D=[]
F=[]
Arr=[]
for i in xrange(len(C)):
x=(A.count(C[i]))/(B.count(C[i]))
Arr.append(x)
print min(Arr)
t=t-1 | 1Python2 | {
"input": [
"4\nareyouafoobarmember\nbarfoo\nfofoforabrabbbbbbfoooooooaaa\nfoobar\nthisisiplab\nsi\nababa\naa",
"4\nareyouafoobarmember\nbarfoo\nfofoforabrabbbbbbfoooooooaaa\noofbar\nthisisiplab\nsi\nababa\naa",
"4\nareyouafoobarmember\nbarfoo\ngofoforabrabbbbbbfoooooooaaa\noofbar\nthisisiplab\nsi\nababa... | 1CODECHEF |
1009_G. Allowed Letters_38149 | Polycarp has just launched his new startup idea. The niche is pretty free and the key vector of development sounds really promising, so he easily found himself some investors ready to sponsor the company. However, he is yet to name the startup!
Actually, Polycarp has already came up with the name but some improvement ... | #include <bits/stdc++.h>
using namespace std;
long long read() {
char ch = getchar();
long long x = 0;
int op = 1;
for (; !isdigit(ch); ch = getchar())
if (ch == '-') op = -1;
for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
return x * op;
}
int n, m, a[100005], b[100005][70], tmp... | 2C++ | {
"input": [
"abacaba\n0\n",
"bedefead\n5\n2 e\n1 dc\n5 b\n7 ef\n6 ef\n",
"fc\n2\n1 cfab\n2 f\n",
"aaeff\n5\n2 afbdce\n5 c\n1 dbc\n4 afcbde\n3 ef\n",
"bfb\n3\n1 f\n3 acdef\n2 cdefab\n",
"bbcbbc\n6\n1 c\n2 c\n3 b\n4 ab\n5 ab\n6 ab\n",
"ded\n1\n2 aedc\n",
"effa\n3\n3 ca\n2 bd\n4 abfdce\n... | 2CODEFORCES |
1009_G. Allowed Letters_38150 | Polycarp has just launched his new startup idea. The niche is pretty free and the key vector of development sounds really promising, so he easily found himself some investors ready to sponsor the company. However, he is yet to name the startup!
Actually, Polycarp has already came up with the name but some improvement ... | import java.io.*;
import java.util.*;
public class Main{
static final int INF = (int)1e9;
static int V, s, t, res[][]; //input
static ArrayList<Integer>[] adjList; //input
static int[] ptr, dist,par;
static int dinic(){
int mf = 0;
while(bfs())
{
ptr = new int[V];
int f;
while((f = dfs(s, INF))... | 4JAVA | {
"input": [
"abacaba\n0\n",
"bedefead\n5\n2 e\n1 dc\n5 b\n7 ef\n6 ef\n",
"fc\n2\n1 cfab\n2 f\n",
"aaeff\n5\n2 afbdce\n5 c\n1 dbc\n4 afcbde\n3 ef\n",
"bfb\n3\n1 f\n3 acdef\n2 cdefab\n",
"bbcbbc\n6\n1 c\n2 c\n3 b\n4 ab\n5 ab\n6 ab\n",
"ded\n1\n2 aedc\n",
"effa\n3\n3 ca\n2 bd\n4 abfdce\n... | 2CODEFORCES |
1032_D. Barcelonian Distance_38151 | In this problem we consider a very simplified model of Barcelona city.
Barcelona can be represented as a plane with streets of kind x = c and y = c for every integer c (that is, the rectangular grid). However, there is a detail which makes Barcelona different from Manhattan. There is an avenue called Avinguda Diagonal... | def lindist(a,b,c,x,y):
dis = []
if abs(b)>0:
yp = -1.0*(a*x+c)/b
dis.append([abs(y-yp),x,yp])
if abs(a)>0:
xp = -1.*(b*y+c)/a
dis.append([abs(x-xp),xp,y])
return dis
def dist(x1,y1,x2,y2):
return ((x1-x2)**2+(y1-y2)**2)**0.5
a,b,c = map(float,raw_input().strip('\n').split(' '))
x1,y1,x2,y2 = map(float,... | 1Python2 | {
"input": [
"3 1 -9\n0 3 3 -1\n",
"1 1 -3\n0 3 3 0\n",
"1 -1 0\n-1 0 2 1\n",
"14258 86657 -603091233\n-3 6959 42295 -3\n",
"0 1 429776186\n566556410 -800727742 -432459627 -189939420\n",
"10 4 8\n2 8 -10 9\n",
"226858641 -645505218 -478645478\n-703323491 504136399 852998686 -316100625\n",
... | 2CODEFORCES |
1032_D. Barcelonian Distance_38152 | In this problem we consider a very simplified model of Barcelona city.
Barcelona can be represented as a plane with streets of kind x = c and y = c for every integer c (that is, the rectangular grid). However, there is a detail which makes Barcelona different from Manhattan. There is an avenue called Avinguda Diagonal... | #include <bits/stdc++.h>
using namespace std;
const long long INF = 999999999999999999;
const double PI = acos(-1.0);
void stop() { exit(0); }
int main() {
double a, b, c, x1, y1, x2, y2;
cin >> a >> b >> c >> x1 >> y1 >> x2 >> y2;
double var1 = abs(x1 - x2) + abs(y1 - y2);
double var2 = 0, var3 = 0, var4 = 0, ... | 2C++ | {
"input": [
"3 1 -9\n0 3 3 -1\n",
"1 1 -3\n0 3 3 0\n",
"1 -1 0\n-1 0 2 1\n",
"14258 86657 -603091233\n-3 6959 42295 -3\n",
"0 1 429776186\n566556410 -800727742 -432459627 -189939420\n",
"10 4 8\n2 8 -10 9\n",
"226858641 -645505218 -478645478\n-703323491 504136399 852998686 -316100625\n",
... | 2CODEFORCES |
1032_D. Barcelonian Distance_38153 | In this problem we consider a very simplified model of Barcelona city.
Barcelona can be represented as a plane with streets of kind x = c and y = c for every integer c (that is, the rectangular grid). However, there is a detail which makes Barcelona different from Manhattan. There is an avenue called Avinguda Diagonal... | import math
a,b,c=map(int,input().split())
x1,y1,x2,y2=map(int,input().split())
s=abs(x1-x2)+abs(y1-y2)
if a!=0:
xk1=-1*(b*y1+c)/a
xk2=-1*(b*y2+c)/a
else:
xk1=10**18
xk2=10**18
if b!=0:
yk1=-1*(a*x1+c)/b
yk2=-1*(a*x2+c)/b
else:
yk1=10**18
yk2=10**18
lx1=abs(y1-yk1)
lx2=abs(y2-yk2)
ly1=ab... | 3Python3 | {
"input": [
"3 1 -9\n0 3 3 -1\n",
"1 1 -3\n0 3 3 0\n",
"1 -1 0\n-1 0 2 1\n",
"14258 86657 -603091233\n-3 6959 42295 -3\n",
"0 1 429776186\n566556410 -800727742 -432459627 -189939420\n",
"10 4 8\n2 8 -10 9\n",
"226858641 -645505218 -478645478\n-703323491 504136399 852998686 -316100625\n",
... | 2CODEFORCES |
1032_D. Barcelonian Distance_38154 | In this problem we consider a very simplified model of Barcelona city.
Barcelona can be represented as a plane with streets of kind x = c and y = c for every integer c (that is, the rectangular grid). However, there is a detail which makes Barcelona different from Manhattan. There is an avenue called Avinguda Diagonal... | import java.io.*;
import java.util.StringTokenizer;
public class Main {
static int a, b, c;
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
a = sc.nextInt();
b = sc.nextInt();
... | 4JAVA | {
"input": [
"3 1 -9\n0 3 3 -1\n",
"1 1 -3\n0 3 3 0\n",
"1 -1 0\n-1 0 2 1\n",
"14258 86657 -603091233\n-3 6959 42295 -3\n",
"0 1 429776186\n566556410 -800727742 -432459627 -189939420\n",
"10 4 8\n2 8 -10 9\n",
"226858641 -645505218 -478645478\n-703323491 504136399 852998686 -316100625\n",
... | 2CODEFORCES |
1055_B. Alice and Hairdresser_38155 | Alice's hair is growing by leaps and bounds. Maybe the cause of it is the excess of vitamins, or maybe it is some black magic...
To prevent this, Alice decided to go to the hairdresser. She wants for her hair length to be at most l centimeters after haircut, where l is her favorite number. Suppose, that the Alice's he... | from __future__ import division
from sys import stdin, stdout
line = stdin.readline().rstrip("\n")
n, m, l = map(int, line.split())
line = stdin.readline().rstrip("\n")
a = map(int, line.split())
a = [0] + a + [0]
res = 0
for i in range(1, n + 1):
if a[i] > l and not a[i - 1] > l:
res += 1
reqs = []
f... | 1Python2 | {
"input": [
"4 7 3\n1 2 3 4\n0\n1 2 3\n0\n1 1 3\n0\n1 3 1\n0\n",
"10 24 2\n1 1 1 1 1 1 1 1 1 1\n0\n1 1 1\n0\n1 1 1\n0\n1 3 2\n1 5 2\n1 7 2\n1 9 2\n0\n1 10 1\n0\n1 10 1\n0\n1 10 1\n0\n1 1 1\n0\n1 2 2\n1 4 2\n0\n1 6 2\n1 8 2\n0\n",
"10 30 2\n1 1 1 1 1 1 1 1 1 1\n0\n1 1 1\n1 10 1\n0\n1 1 1\n1 10 1\n0\n1 2 2... | 2CODEFORCES |
1055_B. Alice and Hairdresser_38156 | Alice's hair is growing by leaps and bounds. Maybe the cause of it is the excess of vitamins, or maybe it is some black magic...
To prevent this, Alice decided to go to the hairdresser. She wants for her hair length to be at most l centimeters after haircut, where l is her favorite number. Suppose, that the Alice's he... | #include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, m, l;
cin >> n >> m >> l;
vector<long long> arr(n);
long long count = 0;
for (int i = 0; i < n; ++i) {
cin >> arr[i];
if (arr[i] > l && (i == 0 || arr[i - 1] <= l) &&
(i == n - 1 || arr[i + 1] <= l)) {
count++;
... | 2C++ | {
"input": [
"4 7 3\n1 2 3 4\n0\n1 2 3\n0\n1 1 3\n0\n1 3 1\n0\n",
"10 24 2\n1 1 1 1 1 1 1 1 1 1\n0\n1 1 1\n0\n1 1 1\n0\n1 3 2\n1 5 2\n1 7 2\n1 9 2\n0\n1 10 1\n0\n1 10 1\n0\n1 10 1\n0\n1 1 1\n0\n1 2 2\n1 4 2\n0\n1 6 2\n1 8 2\n0\n",
"10 30 2\n1 1 1 1 1 1 1 1 1 1\n0\n1 1 1\n1 10 1\n0\n1 1 1\n1 10 1\n0\n1 2 2... | 2CODEFORCES |
1055_B. Alice and Hairdresser_38157 | Alice's hair is growing by leaps and bounds. Maybe the cause of it is the excess of vitamins, or maybe it is some black magic...
To prevent this, Alice decided to go to the hairdresser. She wants for her hair length to be at most l centimeters after haircut, where l is her favorite number. Suppose, that the Alice's he... | n, m, l = map(int, input().split())
a = list(map(int, input().split()))
nexxt = {}
prevv = {}
nexxt[-1] = n
prevv[n] = -1
summ = 0
p = -1
l += 1
for k in range(n):
if a[k] < l:
p1 = p
p = k
nexxt[k] = n
prevv[k] = p1
nexxt[p1] = k
if k - prevv[k] > 1:
sum... | 3Python3 | {
"input": [
"4 7 3\n1 2 3 4\n0\n1 2 3\n0\n1 1 3\n0\n1 3 1\n0\n",
"10 24 2\n1 1 1 1 1 1 1 1 1 1\n0\n1 1 1\n0\n1 1 1\n0\n1 3 2\n1 5 2\n1 7 2\n1 9 2\n0\n1 10 1\n0\n1 10 1\n0\n1 10 1\n0\n1 1 1\n0\n1 2 2\n1 4 2\n0\n1 6 2\n1 8 2\n0\n",
"10 30 2\n1 1 1 1 1 1 1 1 1 1\n0\n1 1 1\n1 10 1\n0\n1 1 1\n1 10 1\n0\n1 2 2... | 2CODEFORCES |
1055_B. Alice and Hairdresser_38158 | Alice's hair is growing by leaps and bounds. Maybe the cause of it is the excess of vitamins, or maybe it is some black magic...
To prevent this, Alice decided to go to the hairdresser. She wants for her hair length to be at most l centimeters after haircut, where l is her favorite number. Suppose, that the Alice's he... | //package CodeForces.Rounds;
import java.io.*;
import java.util.StringTokenizer;
public class Task1055B {
FastScanner in;
PrintWriter out;
public void solve() throws IOException {
int n = in.nextInt();
int m = in.nextInt();
int l = in.nextInt();
long[] a = new long[n];
... | 4JAVA | {
"input": [
"4 7 3\n1 2 3 4\n0\n1 2 3\n0\n1 1 3\n0\n1 3 1\n0\n",
"10 24 2\n1 1 1 1 1 1 1 1 1 1\n0\n1 1 1\n0\n1 1 1\n0\n1 3 2\n1 5 2\n1 7 2\n1 9 2\n0\n1 10 1\n0\n1 10 1\n0\n1 10 1\n0\n1 1 1\n0\n1 2 2\n1 4 2\n0\n1 6 2\n1 8 2\n0\n",
"10 30 2\n1 1 1 1 1 1 1 1 1 1\n0\n1 1 1\n1 10 1\n0\n1 1 1\n1 10 1\n0\n1 2 2... | 2CODEFORCES |
1077_C. Good Array_38159 | Let's call an array good if there is an element in the array that equals to the sum of all other elements. For example, the array a=[1, 3, 3, 7] is good because there is the element a_4=7 which equals to the sum 1 + 3 + 3.
You are given an array a consisting of n integers. Your task is to print all indices j of this a... | import sys
range = xrange
input = raw_input
A = [0]*(10**6+10)
n = int(input())
s = sys.stdin.read()
inp = []
numb = 0
for i in range(len(s)):
if s[i]>='0':
numb = 10*numb + ord(s[i])-48
else:
inp.append(numb)
numb = 0
if s[-1]>='0':
inp.append(numb)
for numb in inp:
A[numb... | 1Python2 | {
"input": [
"5\n2 5 1 2 2\n",
"4\n8 3 5 2\n",
"5\n2 1 2 4 3\n",
"3\n3 3 3\n",
"5\n5 5 2 2 1\n",
"4\n2 2 4 8\n",
"2\n1 5\n",
"6\n16 4 4 4 4 16\n",
"4\n1 1 1 2\n",
"6\n4 4 1 1 1 1\n",
"3\n1 2 3\n",
"3\n1 3 1\n",
"4\n1 2 3 4\n",
"5\n4 6 7 8 18\n",
"7\n1 2 3 4 ... | 2CODEFORCES |
1077_C. Good Array_38160 | Let's call an array good if there is an element in the array that equals to the sum of all other elements. For example, the array a=[1, 3, 3, 7] is good because there is the element a_4=7 which equals to the sum 1 + 3 + 3.
You are given an array a consisting of n integers. Your task is to print all indices j of this a... | #include <bits/stdc++.h>
using namespace std;
int n, a[200005];
map<int, int> mp;
vector<int> ver;
long long sum;
int main() {
scanf("%d", &n);
for (register int i = 1; i <= n; ++i)
scanf("%d", &a[i]), sum += a[i], mp[a[i]]++;
long long t;
for (register int i = 1; i <= n; ++i) {
t = sum - a[i];
if (... | 2C++ | {
"input": [
"5\n2 5 1 2 2\n",
"4\n8 3 5 2\n",
"5\n2 1 2 4 3\n",
"3\n3 3 3\n",
"5\n5 5 2 2 1\n",
"4\n2 2 4 8\n",
"2\n1 5\n",
"6\n16 4 4 4 4 16\n",
"4\n1 1 1 2\n",
"6\n4 4 1 1 1 1\n",
"3\n1 2 3\n",
"3\n1 3 1\n",
"4\n1 2 3 4\n",
"5\n4 6 7 8 18\n",
"7\n1 2 3 4 ... | 2CODEFORCES |
1077_C. Good Array_38161 | Let's call an array good if there is an element in the array that equals to the sum of all other elements. For example, the array a=[1, 3, 3, 7] is good because there is the element a_4=7 which equals to the sum 1 + 3 + 3.
You are given an array a consisting of n integers. Your task is to print all indices j of this a... | n=int(input())
a=list(map(int,input().split()))
s=sum(a)
d=dict()
for i in range(n):
if a[i] in d:
d[a[i]].append(i+1)
else:
d[a[i]]=[i+1]
ans=[]
for k in d.keys():
if (s-k)%2>0:
continue
m=(s-k)//2
#print(m)
if m in d and (m!=k or len(d[k])>1):
ans+=d[k]
print(le... | 3Python3 | {
"input": [
"5\n2 5 1 2 2\n",
"4\n8 3 5 2\n",
"5\n2 1 2 4 3\n",
"3\n3 3 3\n",
"5\n5 5 2 2 1\n",
"4\n2 2 4 8\n",
"2\n1 5\n",
"6\n16 4 4 4 4 16\n",
"4\n1 1 1 2\n",
"6\n4 4 1 1 1 1\n",
"3\n1 2 3\n",
"3\n1 3 1\n",
"4\n1 2 3 4\n",
"5\n4 6 7 8 18\n",
"7\n1 2 3 4 ... | 2CODEFORCES |
1077_C. Good Array_38162 | Let's call an array good if there is an element in the array that equals to the sum of all other elements. For example, the array a=[1, 3, 3, 7] is good because there is the element a_4=7 which equals to the sum 1 + 3 + 3.
You are given an array a consisting of n integers. Your task is to print all indices j of this a... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class GoodArray {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
int n = Integer... | 4JAVA | {
"input": [
"5\n2 5 1 2 2\n",
"4\n8 3 5 2\n",
"5\n2 1 2 4 3\n",
"3\n3 3 3\n",
"5\n5 5 2 2 1\n",
"4\n2 2 4 8\n",
"2\n1 5\n",
"6\n16 4 4 4 4 16\n",
"4\n1 1 1 2\n",
"6\n4 4 1 1 1 1\n",
"3\n1 2 3\n",
"3\n1 3 1\n",
"4\n1 2 3 4\n",
"5\n4 6 7 8 18\n",
"7\n1 2 3 4 ... | 2CODEFORCES |
1098_B. Nice table_38163 | You are given an n × m table, consisting of characters «A», «G», «C», «T». Let's call a table nice, if every 2 × 2 square contains all four distinct characters. Your task is to find a nice table (also consisting of «A», «G», «C», «T»), that differs from the given table in the minimum number of characters.
Input
First... | import sys
range = xrange
input = raw_input
tran = [0]*1000
tran[ord('A')] = 0
tran[ord('G')] = 1
tran[ord('C')] = 2
tran[ord('T')] = 3
inv = ['A','G','C','T']
h,w = [int(x) for x in input().split()]
A = [[tran[ord(c)] for c in inp] for inp in sys.stdin.read().splitlines()]
comb = []
for i in range(4):
for j in... | 1Python2 | {
"input": [
"2 2\nAG\nCT\n",
"3 5\nAGCAG\nAGCAG\nAGCAG\n",
"2 2\nTG\nAC\n",
"2 2\nAG\nTC\n",
"2 2\nGA\nTC\n",
"3 5\nGACGA\nAGCAG\nAGCAG\n",
"2 2\nTG\nCA\n",
"2 2\nGA\nCT\n",
"2 2\nGT\nAC\n",
"2 2\nGT\nCA\n",
"3 5\nAGGAC\nGACGA\nGACGA\n",
"3 5\nAGCAG\nAGCAG\nGACGA\n",
... | 2CODEFORCES |
1098_B. Nice table_38164 | You are given an n × m table, consisting of characters «A», «G», «C», «T». Let's call a table nice, if every 2 × 2 square contains all four distinct characters. Your task is to find a nice table (also consisting of «A», «G», «C», «T»), that differs from the given table in the minimum number of characters.
Input
First... | #include <bits/stdc++.h>
using namespace std;
template <class U, class T>
void Max(U &first, T second) {
if (first < second) first = second;
}
template <class U, class T>
void Min(U &first, T second) {
if (first > second) first = second;
}
template <class T>
void add(int &a, T b) {
a = (a + b) % 1000000007;
}
inl... | 2C++ | {
"input": [
"2 2\nAG\nCT\n",
"3 5\nAGCAG\nAGCAG\nAGCAG\n",
"2 2\nTG\nAC\n",
"2 2\nAG\nTC\n",
"2 2\nGA\nTC\n",
"3 5\nGACGA\nAGCAG\nAGCAG\n",
"2 2\nTG\nCA\n",
"2 2\nGA\nCT\n",
"2 2\nGT\nAC\n",
"2 2\nGT\nCA\n",
"3 5\nAGGAC\nGACGA\nGACGA\n",
"3 5\nAGCAG\nAGCAG\nGACGA\n",
... | 2CODEFORCES |
1098_B. Nice table_38165 | You are given an n × m table, consisting of characters «A», «G», «C», «T». Let's call a table nice, if every 2 × 2 square contains all four distinct characters. Your task is to find a nice table (also consisting of «A», «G», «C», «T»), that differs from the given table in the minimum number of characters.
Input
First... | from itertools import permutations
from sys import stdin, stdout
ly, lx = map(int, input().split())
grid = [[c for c in inp] for inp in stdin.read().splitlines()]
first = set()
bl = []
bpattern = []
bcost = 1e6
flip_row = False
for l in permutations('AGCT'):
if bcost == 0:
break
if ''.join(l[:2]) in f... | 3Python3 | {
"input": [
"2 2\nAG\nCT\n",
"3 5\nAGCAG\nAGCAG\nAGCAG\n",
"2 2\nTG\nAC\n",
"2 2\nAG\nTC\n",
"2 2\nGA\nTC\n",
"3 5\nGACGA\nAGCAG\nAGCAG\n",
"2 2\nTG\nCA\n",
"2 2\nGA\nCT\n",
"2 2\nGT\nAC\n",
"2 2\nGT\nCA\n",
"3 5\nAGGAC\nGACGA\nGACGA\n",
"3 5\nAGCAG\nAGCAG\nGACGA\n",
... | 2CODEFORCES |
1098_B. Nice table_38166 | You are given an n × m table, consisting of characters «A», «G», «C», «T». Let's call a table nice, if every 2 × 2 square contains all four distinct characters. Your task is to find a nice table (also consisting of «A», «G», «C», «T»), that differs from the given table in the minimum number of characters.
Input
First... | import java.io.PrintWriter;
import java.util.Scanner;
public class NiceTable {
int N, M, x, y, xx, yy;
char grid[][], d[] = { 'A', 'G', 'C', 'T' };
int costR(int r, int x, int y) {
int a = 0, b = 0;
for (int i = 0; i < M; i += 2) {
a += grid[r][i] == d[x] ? 0 : 1;
b += grid[r][i] == d[y] ? 0 : 1;
}
... | 4JAVA | {
"input": [
"2 2\nAG\nCT\n",
"3 5\nAGCAG\nAGCAG\nAGCAG\n",
"2 2\nTG\nAC\n",
"2 2\nAG\nTC\n",
"2 2\nGA\nTC\n",
"3 5\nGACGA\nAGCAG\nAGCAG\n",
"2 2\nTG\nCA\n",
"2 2\nGA\nCT\n",
"2 2\nGT\nAC\n",
"2 2\nGT\nCA\n",
"3 5\nAGGAC\nGACGA\nGACGA\n",
"3 5\nAGCAG\nAGCAG\nGACGA\n",
... | 2CODEFORCES |
1119_C. Ramesses and Corner Inversion_38167 | Ramesses came to university to algorithms practice, and his professor, who is a fairly known programmer, gave him the following task.
You are given two matrices A and B of size n × m, each of which consists of 0 and 1 only. You can apply the following operation to the matrix A arbitrary number of times: take any subma... | import math
import collections
n,m = map(int, raw_input().split())
A, B = [], []
for i in range(n):
A.append(map(int, raw_input().split()))
for i in range(n):
B.append(map(int, raw_input().split()))
for i in range(n):
for j in range(m):
A[i][j] ^= B[i][j]
flag = True
for i in range(n-1):
cnt ... | 1Python2 | {
"input": [
"3 4\n0 1 0 1\n1 0 1 0\n0 1 0 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n",
"6 7\n0 0 1 1 0 0 1\n0 1 0 0 1 0 1\n0 0 0 1 0 0 1\n1 0 1 0 1 0 0\n0 1 0 0 1 0 1\n0 1 0 1 0 0 1\n1 1 0 1 0 1 1\n0 1 1 0 1 0 0\n1 1 0 1 0 0 1\n1 0 1 0 0 1 0\n0 1 1 0 1 0 0\n0 1 1 1 1 0 1\n",
"3 3\n0 1 0\n0 1 0\n1 0 0\n1 0 0\n1 0 0\n... | 2CODEFORCES |
1119_C. Ramesses and Corner Inversion_38168 | Ramesses came to university to algorithms practice, and his professor, who is a fairly known programmer, gave him the following task.
You are given two matrices A and B of size n × m, each of which consists of 0 and 1 only. You can apply the following operation to the matrix A arbitrary number of times: take any subma... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
bool x;
cin >> n >> m;
vector<bool> rowAXor(n);
vector<bool> rowBXor(n);
vector<bool> colAXor(m);
vector<bool> colBXor(m);
int totalBXor = 0, totalAXor = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >>... | 2C++ | {
"input": [
"3 4\n0 1 0 1\n1 0 1 0\n0 1 0 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n",
"6 7\n0 0 1 1 0 0 1\n0 1 0 0 1 0 1\n0 0 0 1 0 0 1\n1 0 1 0 1 0 0\n0 1 0 0 1 0 1\n0 1 0 1 0 0 1\n1 1 0 1 0 1 1\n0 1 1 0 1 0 0\n1 1 0 1 0 0 1\n1 0 1 0 0 1 0\n0 1 1 0 1 0 0\n0 1 1 1 1 0 1\n",
"3 3\n0 1 0\n0 1 0\n1 0 0\n1 0 0\n1 0 0\n... | 2CODEFORCES |
1119_C. Ramesses and Corner Inversion_38169 | Ramesses came to university to algorithms practice, and his professor, who is a fairly known programmer, gave him the following task.
You are given two matrices A and B of size n × m, each of which consists of 0 and 1 only. You can apply the following operation to the matrix A arbitrary number of times: take any subma... | def solve():
n, m = [int(x) for x in input().split(' ')]
A = [[int(x) for x in input().split(' ')] for row in range(n)]
B = [[int(x) for x in input().split(' ')] for row in range(n)]
def row_par(M, k):
return sum(M[k]) % 2
def col_par(M, k):
return sum([r[k] for r in M]) % 2
f... | 3Python3 | {
"input": [
"3 4\n0 1 0 1\n1 0 1 0\n0 1 0 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n",
"6 7\n0 0 1 1 0 0 1\n0 1 0 0 1 0 1\n0 0 0 1 0 0 1\n1 0 1 0 1 0 0\n0 1 0 0 1 0 1\n0 1 0 1 0 0 1\n1 1 0 1 0 1 1\n0 1 1 0 1 0 0\n1 1 0 1 0 0 1\n1 0 1 0 0 1 0\n0 1 1 0 1 0 0\n0 1 1 1 1 0 1\n",
"3 3\n0 1 0\n0 1 0\n1 0 0\n1 0 0\n1 0 0\n... | 2CODEFORCES |
1119_C. Ramesses and Corner Inversion_38170 | Ramesses came to university to algorithms practice, and his professor, who is a fairly known programmer, gave him the following task.
You are given two matrices A and B of size n × m, each of which consists of 0 and 1 only. You can apply the following operation to the matrix A arbitrary number of times: take any subma... | import java.io.*;
import java.util.*;
public class C {
public void realMain() throws Exception {
BufferedReader fin = new BufferedReader(new InputStreamReader(System.in), 1000000);
String in = fin.readLine();
String[] ar = in.split(" ");
int n = Integer.parseInt(ar[0]);
int m = Integer.parseInt(ar[1]);... | 4JAVA | {
"input": [
"3 4\n0 1 0 1\n1 0 1 0\n0 1 0 1\n1 1 1 1\n1 1 1 1\n1 1 1 1\n",
"6 7\n0 0 1 1 0 0 1\n0 1 0 0 1 0 1\n0 0 0 1 0 0 1\n1 0 1 0 1 0 0\n0 1 0 0 1 0 1\n0 1 0 1 0 0 1\n1 1 0 1 0 1 1\n0 1 1 0 1 0 0\n1 1 0 1 0 0 1\n1 0 1 0 0 1 0\n0 1 1 0 1 0 0\n0 1 1 1 1 0 1\n",
"3 3\n0 1 0\n0 1 0\n1 0 0\n1 0 0\n1 0 0\n... | 2CODEFORCES |
1145_G. AI Takeover_38171 | The recent advances in AI research has brought humanity to the point when the AIs finally attempt a takeover. Their weapon of choice? The [most intellectually challenging game in the world](//codeforces.com/contest/409/problem/A), rock-paper-scissors!
The future of humanity looks bleak, given the existence of the robo... | #include <bits/stdc++.h>
using namespace std;
const string T = "RRRRPSSPRR";
string s, t, s1;
int main() {
string s, t;
for (int i = 0; i < 10; i++) {
printf("%c\n", T[i]);
fflush(stdout);
getline(cin, s1);
s += (s1 == "ai" ? '0' : '1');
}
if (s == "0000100100") t = "PPPPPPPPPP";
if (s == "000... | 2C++ | {
"input": [
"5\n",
"6\n",
"2\n",
"1\n",
"4\n",
"3\n",
"8\n",
"0\n",
"10\n",
"-1\n",
"11\n",
"7\n",
"-2\n",
"-4\n",
"9\n",
"-6\n",
"-7\n",
"12\n",
"14\n",
"-3\n",
"16\n",
"-5\n",
"-10\n",
"-8\n",
"13\n",
"-9\n",
... | 2CODEFORCES |
1145_G. AI Takeover_38172 | The recent advances in AI research has brought humanity to the point when the AIs finally attempt a takeover. Their weapon of choice? The [most intellectually challenging game in the world](//codeforces.com/contest/409/problem/A), rock-paper-scissors!
The future of humanity looks bleak, given the existence of the robo... | print("R\nR\nP\nP\nS\nS");
const verdict = [readline().length === 6, readline().length === 6, readline().length === 6, readline().length === 6, readline().length === 6, readline().length === 6];
if (verdict[0]) print("R\nR\nR\nR\nR\nR\nR\nR\nR\nR\nR\nR\nR\nR");
else if (verdict[5]) print("S\nS\nS\nS\nS\nS\nS\nS\nS\nS\n... | 4JAVA | {
"input": [
"5\n",
"6\n",
"2\n",
"1\n",
"4\n",
"3\n",
"8\n",
"0\n",
"10\n",
"-1\n",
"11\n",
"7\n",
"-2\n",
"-4\n",
"9\n",
"-6\n",
"-7\n",
"12\n",
"14\n",
"-3\n",
"16\n",
"-5\n",
"-10\n",
"-8\n",
"13\n",
"-9\n",
... | 2CODEFORCES |
1166_F. Vicky's Delivery Service_38173 | In a magical land there are n cities conveniently numbered 1, 2, ..., n. Some pairs of these cities are connected by magical colored roads. Magic is unstable, so at any time, new roads may appear between two cities.
Vicky the witch has been tasked with performing deliveries between some pairs of cities. However, Vicky... | #include <bits/stdc++.h>
using namespace std;
map<long long, long long> mp[100001];
long long n, m, q, u, v, c, f[100001];
set<long long> a[100001];
char op;
inline long long read() {
long long sum = 0, x = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') x = -1;
ch = getchar();
}
while (... | 2C++ | {
"input": [
"4 3 2 4\n1 2 1\n2 3 1\n3 4 2\n? 1 4\n? 4 1\n+ 3 1 2\n? 4 1\n",
"2 1 1 5\n2 1 1\n? 2 1\n? 1 2\n? 1 2\n? 2 1\n? 1 2\n",
"10 35 3 30\n4 8 1\n6 8 3\n6 10 1\n1 4 2\n4 7 3\n1 10 2\n7 2 3\n6 2 1\n1 7 2\n3 5 2\n10 4 1\n5 4 2\n9 6 2\n2 4 3\n8 2 2\n7 8 2\n9 1 3\n5 6 1\n9 5 2\n9 2 1\n6 4 2\n9 7 3\n3 2 ... | 2CODEFORCES |
1166_F. Vicky's Delivery Service_38174 | In a magical land there are n cities conveniently numbered 1, 2, ..., n. Some pairs of these cities are connected by magical colored roads. Magic is unstable, so at any time, new roads may appear between two cities.
Vicky the witch has been tasked with performing deliveries between some pairs of cities. However, Vicky... | import javax.smartcardio.ATR;
import java.io.*;
import java.util.*;
public class Main {
static int n;
static HashMap<Integer,Integer> gr[];
static HashSet<Integer> p[];
static dsu lol;
static void union(int a, int b) {
a = lol.get(a);
b = lol.get(b);
if (p[a].size() > p[b].s... | 4JAVA | {
"input": [
"4 3 2 4\n1 2 1\n2 3 1\n3 4 2\n? 1 4\n? 4 1\n+ 3 1 2\n? 4 1\n",
"2 1 1 5\n2 1 1\n? 2 1\n? 1 2\n? 1 2\n? 2 1\n? 1 2\n",
"10 35 3 30\n4 8 1\n6 8 3\n6 10 1\n1 4 2\n4 7 3\n1 10 2\n7 2 3\n6 2 1\n1 7 2\n3 5 2\n10 4 1\n5 4 2\n9 6 2\n2 4 3\n8 2 2\n7 8 2\n9 1 3\n5 6 1\n9 5 2\n9 2 1\n6 4 2\n9 7 3\n3 2 ... | 2CODEFORCES |
1185_C2. Exam in BerSU (hard version)_38175 | The only difference between easy and hard versions is constraints.
If you write a solution in Python, then prefer to send it in PyPy to speed up execution time.
A session has begun at Beland State University. Many students are taking exams.
Polygraph Poligrafovich is going to examine a group of n students. Students ... | #import resource
import sys
#resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY])
#import threading
#threading.Thread(target=main).start()
#threading.stack_size(2**26)
#sys.setrecursionlimit(10**6)
mod=(10**9)+7
#fact=[1]
#for i in range(1,100001):
# fact.append((fact[-1]*i)%mod)
#ifact=[... | 1Python2 | {
"input": [
"7 15\n1 2 3 4 5 6 7\n",
"5 100\n80 40 40 40 60\n",
"3 299\n100 100 100\n",
"8 2\n1 1 1 1 1 1 1 1\n",
"10 50\n9 9 9 9 9 9 9 9 9 9\n",
"1 100\n100\n",
"1 20000000\n100\n",
"2 100\n1 100\n",
"2 100\n100 100\n",
"1 1\n1\n",
"10 50\n10 10 10 10 10 10 10 10 10 10\n"... | 2CODEFORCES |
1185_C2. Exam in BerSU (hard version)_38176 | The only difference between easy and hard versions is constraints.
If you write a solution in Python, then prefer to send it in PyPy to speed up execution time.
A session has begun at Beland State University. Many students are taking exams.
Polygraph Poligrafovich is going to examine a group of n students. Students ... | #include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long n, m;
cin >> n >> m;
long long a[n], i, j;
for (i = 0; i < n; i++) {
cin >> a[i];
}
long long time[101] = {0};
long long sum = 0;
for (i = 0; i < n; i++) {
sum += ... | 2C++ | {
"input": [
"7 15\n1 2 3 4 5 6 7\n",
"5 100\n80 40 40 40 60\n",
"3 299\n100 100 100\n",
"8 2\n1 1 1 1 1 1 1 1\n",
"10 50\n9 9 9 9 9 9 9 9 9 9\n",
"1 100\n100\n",
"1 20000000\n100\n",
"2 100\n1 100\n",
"2 100\n100 100\n",
"1 1\n1\n",
"10 50\n10 10 10 10 10 10 10 10 10 10\n"... | 2CODEFORCES |
1185_C2. Exam in BerSU (hard version)_38177 | The only difference between easy and hard versions is constraints.
If you write a solution in Python, then prefer to send it in PyPy to speed up execution time.
A session has begun at Beland State University. Many students are taking exams.
Polygraph Poligrafovich is going to examine a group of n students. Students ... | import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
# import time,random,resource
# sys.setrecursionlimit(10**6)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(... | 3Python3 | {
"input": [
"7 15\n1 2 3 4 5 6 7\n",
"5 100\n80 40 40 40 60\n",
"3 299\n100 100 100\n",
"8 2\n1 1 1 1 1 1 1 1\n",
"10 50\n9 9 9 9 9 9 9 9 9 9\n",
"1 100\n100\n",
"1 20000000\n100\n",
"2 100\n1 100\n",
"2 100\n100 100\n",
"1 1\n1\n",
"10 50\n10 10 10 10 10 10 10 10 10 10\n"... | 2CODEFORCES |
1185_C2. Exam in BerSU (hard version)_38178 | The only difference between easy and hard versions is constraints.
If you write a solution in Python, then prefer to send it in PyPy to speed up execution time.
A session has begun at Beland State University. Many students are taking exams.
Polygraph Poligrafovich is going to examine a group of n students. Students ... | // This template code suggested by KT BYTE Computer Science Academy
// for use in reading and writing files for USACO problems.
// https://content.ktbyte.com/problem.java
import java.util.*;
import java.io.*;
public class ExamInBerSU {
static StreamTokenizer in;
static int nextInt() throws IOException {
... | 4JAVA | {
"input": [
"7 15\n1 2 3 4 5 6 7\n",
"5 100\n80 40 40 40 60\n",
"3 299\n100 100 100\n",
"8 2\n1 1 1 1 1 1 1 1\n",
"10 50\n9 9 9 9 9 9 9 9 9 9\n",
"1 100\n100\n",
"1 20000000\n100\n",
"2 100\n1 100\n",
"2 100\n100 100\n",
"1 1\n1\n",
"10 50\n10 10 10 10 10 10 10 10 10 10\n"... | 2CODEFORCES |
1204_A. BowWow and the Timetable_38179 | In the city of Saint Petersburg, a day lasts for 2^{100} minutes. From the main station of Saint Petersburg, a train departs after 1 minute, 4 minutes, 16 minutes, and so on; in other words, the train departs at time 4^k for each integer k ≥ 0. Team BowWow has arrived at the station at the time s and it is trying to co... | a=raw_input()
b=int(a,2)
def ans(x):
k,i=1,0
while(k<x):
k*=4
i+=1
return i
print ans(b) | 1Python2 | {
"input": [
"100000000\n",
"101\n",
"10100\n",
"10001000011101100\n",
"100\n",
"110\n",
"1\n",
"1111010010000101100100001110011101111\n",
"10000\n",
"100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n",
"111100001001101011... | 2CODEFORCES |
1204_A. BowWow and the Timetable_38180 | In the city of Saint Petersburg, a day lasts for 2^{100} minutes. From the main station of Saint Petersburg, a train departs after 1 minute, 4 minutes, 16 minutes, and so on; in other words, the train departs at time 4^k for each integer k ≥ 0. Team BowWow has arrived at the station at the time s and it is trying to co... | #include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int a = s.length();
int i = 0;
if (a % 2 == 0) {
cout << a / 2;
} else {
int count = 0, z = 0;
for (i = 1; i <= 99; i += 2) {
z++;
if (a == i) {
for (int j = 1; j < a; j++) {
if (s[j] == ... | 2C++ | {
"input": [
"100000000\n",
"101\n",
"10100\n",
"10001000011101100\n",
"100\n",
"110\n",
"1\n",
"1111010010000101100100001110011101111\n",
"10000\n",
"100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n",
"111100001001101011... | 2CODEFORCES |
1204_A. BowWow and the Timetable_38181 | In the city of Saint Petersburg, a day lasts for 2^{100} minutes. From the main station of Saint Petersburg, a train departs after 1 minute, 4 minutes, 16 minutes, and so on; in other words, the train departs at time 4^k for each integer k ≥ 0. Team BowWow has arrived at the station at the time s and it is trying to co... | n=int(input(),2)
temp=0
l=[]
while(4**temp<n):
l.append(4**temp)
temp+=1
print(len(l)) | 3Python3 | {
"input": [
"100000000\n",
"101\n",
"10100\n",
"10001000011101100\n",
"100\n",
"110\n",
"1\n",
"1111010010000101100100001110011101111\n",
"10000\n",
"100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n",
"111100001001101011... | 2CODEFORCES |
1204_A. BowWow and the Timetable_38182 | In the city of Saint Petersburg, a day lasts for 2^{100} minutes. From the main station of Saint Petersburg, a train departs after 1 minute, 4 minutes, 16 minutes, and so on; in other words, the train departs at time 4^k for each integer k ≥ 0. Team BowWow has arrived at the station at the time s and it is trying to co... | import java.util.*;
import java.math.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
BigInteger s = parseBigInteger(sc.next()), num = BigInteger.ZERO;
int miss = 0;
while(true) {
if(num.compareTo(BigInteger.ZERO)==0) {
num = BigInteger.ONE;
}
... | 4JAVA | {
"input": [
"100000000\n",
"101\n",
"10100\n",
"10001000011101100\n",
"100\n",
"110\n",
"1\n",
"1111010010000101100100001110011101111\n",
"10000\n",
"100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001\n",
"111100001001101011... | 2CODEFORCES |
1220_F. Gardener Alex_38183 | Gardener Alex loves to grow trees. We remind that tree is a connected acyclic graph on n vertices.
Today he decided to grow a rooted binary tree. A binary tree is a tree where any vertex has no more than two sons. Luckily, Alex has a permutation of numbers from 1 to n which he was presented at his last birthday, so h... | #include <bits/stdc++.h>
using namespace std;
int n;
int a[400005];
int l[400005], r[400005];
int aintlz[1600005], lazy[1600005];
int aint[800005];
int h[400005];
void init(int nod, int l, int r) {
if (l == r)
aint[nod] = l;
else {
int mid = (l + r) / 2;
init(2 * nod, l, mid);
init(2 * nod + 1, mid ... | 2C++ | {
"input": [
"4\n1 2 3 4\n",
"127\n1 70 69 71 68 73 72 74 67 77 76 78 75 80 79 81 66 85 84 86 83 88 87 89 82 92 91 93 90 95 94 96 65 101 100 102 99 104 103 105 98 108 107 109 106 111 110 112 97 116 115 117 114 119 118 120 113 123 122 124 121 126 125 127 7 6 8 5 10 9 11 4 14 13 15 12 17 16 18 3 22 21 23 20 25 ... | 2CODEFORCES |
1220_F. Gardener Alex_38184 | Gardener Alex loves to grow trees. We remind that tree is a connected acyclic graph on n vertices.
Today he decided to grow a rooted binary tree. A binary tree is a tree where any vertex has no more than two sons. Luckily, Alex has a permutation of numbers from 1 to n which he was presented at his last birthday, so h... | import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.InputMismatchException;
... | 4JAVA | {
"input": [
"4\n1 2 3 4\n",
"127\n1 70 69 71 68 73 72 74 67 77 76 78 75 80 79 81 66 85 84 86 83 88 87 89 82 92 91 93 90 95 94 96 65 101 100 102 99 104 103 105 98 108 107 109 106 111 110 112 97 116 115 117 114 119 118 120 113 123 122 124 121 126 125 127 7 6 8 5 10 9 11 4 14 13 15 12 17 16 18 3 22 21 23 20 25 ... | 2CODEFORCES |
1246_B. Power Products_38185 | You are given n positive integers a_1, …, a_n, and an integer k ≥ 2. Count the number of pairs i, j such that 1 ≤ i < j ≤ n, and there exists an integer x such that a_i ⋅ a_j = x^k.
Input
The first line contains two integers n and k (2 ≤ n ≤ 10^5, 2 ≤ k ≤ 100).
The second line contains n integers a_1, …, a_n (1 ≤ a_... | from sys import stdin
from itertools import repeat
from collections import defaultdict
def main():
n, k = map(int, stdin.readline().split())
a = map(int, stdin.readline().split(), repeat(10, n))
b = range(100010)
c = [0] * 100010
z = int(pow(100010, 1. / k)) + 1
p = [1] * 100010
for i in xra... | 1Python2 | {
"input": [
"6 3\n1 3 9 8 24 1\n",
"10 2\n7 4 10 9 2 8 8 7 3 7\n",
"100 3\n94 94 83 27 80 73 61 38 34 95 72 96 59 36 78 15 83 78 39 22 21 57 54 59 9 32 81 64 94 90 67 41 18 57 93 76 44 62 77 61 31 70 39 73 81 57 43 31 27 85 36 26 44 26 75 23 66 53 3 14 40 67 53 19 70 81 98 12 91 15 92 90 89 86 58 30 67 7... | 2CODEFORCES |
1246_B. Power Products_38186 | You are given n positive integers a_1, …, a_n, and an integer k ≥ 2. Count the number of pairs i, j such that 1 ≤ i < j ≤ n, and there exists an integer x such that a_i ⋅ a_j = x^k.
Input
The first line contains two integers n and k (2 ≤ n ≤ 10^5, 2 ≤ k ≤ 100).
The second line contains n integers a_1, …, a_n (1 ≤ a_... | #include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int MAXN = 1e5 + 100;
long long n, k;
vector<pair<long long, long long>> sieve(long long n) {
vector<pair<long long, long long>> v;
for (long long i = 2; i * i <= n; i++)
if (n % i == 0) {
long long kk = 0;
while (n % i == ... | 2C++ | {
"input": [
"6 3\n1 3 9 8 24 1\n",
"10 2\n7 4 10 9 2 8 8 7 3 7\n",
"100 3\n94 94 83 27 80 73 61 38 34 95 72 96 59 36 78 15 83 78 39 22 21 57 54 59 9 32 81 64 94 90 67 41 18 57 93 76 44 62 77 61 31 70 39 73 81 57 43 31 27 85 36 26 44 26 75 23 66 53 3 14 40 67 53 19 70 81 98 12 91 15 92 90 89 86 58 30 67 7... | 2CODEFORCES |
1246_B. Power Products_38187 | You are given n positive integers a_1, …, a_n, and an integer k ≥ 2. Count the number of pairs i, j such that 1 ≤ i < j ≤ n, and there exists an integer x such that a_i ⋅ a_j = x^k.
Input
The first line contains two integers n and k (2 ≤ n ≤ 10^5, 2 ≤ k ≤ 100).
The second line contains n integers a_1, …, a_n (1 ≤ a_... | n,k=map(int,input().split())
A=list(map(int,input().split()))
import math
from collections import Counter
C=Counter()
for x in A:
L=int(math.sqrt(x))
FACT=dict()
for i in range(2,L+2):
while x%i==0:
FACT[i]=FACT.get(i,0)+1
x=x//i
if x!=1:
FACT[x]=FACT.... | 3Python3 | {
"input": [
"6 3\n1 3 9 8 24 1\n",
"10 2\n7 4 10 9 2 8 8 7 3 7\n",
"100 3\n94 94 83 27 80 73 61 38 34 95 72 96 59 36 78 15 83 78 39 22 21 57 54 59 9 32 81 64 94 90 67 41 18 57 93 76 44 62 77 61 31 70 39 73 81 57 43 31 27 85 36 26 44 26 75 23 66 53 3 14 40 67 53 19 70 81 98 12 91 15 92 90 89 86 58 30 67 7... | 2CODEFORCES |
1246_B. Power Products_38188 | You are given n positive integers a_1, …, a_n, and an integer k ≥ 2. Count the number of pairs i, j such that 1 ≤ i < j ≤ n, and there exists an integer x such that a_i ⋅ a_j = x^k.
Input
The first line contains two integers n and k (2 ≤ n ≤ 10^5, 2 ≤ k ≤ 100).
The second line contains n integers a_1, …, a_n (1 ≤ a_... | // Hash: qEz+TO95bihwZG913etVViSnt5lWulEy2mZ9nS4ToZg=
import java.security.*;
import java.nio.file.*;
import java.lang.annotation.*;
import java.util.stream.*;
import java.util.concurrent.atomic.*;
import java.util.function.*;
import java.util.concurrent.*;
import java.util.*;
import java.text.*;
import java.nio.*;
im... | 4JAVA | {
"input": [
"6 3\n1 3 9 8 24 1\n",
"10 2\n7 4 10 9 2 8 8 7 3 7\n",
"100 3\n94 94 83 27 80 73 61 38 34 95 72 96 59 36 78 15 83 78 39 22 21 57 54 59 9 32 81 64 94 90 67 41 18 57 93 76 44 62 77 61 31 70 39 73 81 57 43 31 27 85 36 26 44 26 75 23 66 53 3 14 40 67 53 19 70 81 98 12 91 15 92 90 89 86 58 30 67 7... | 2CODEFORCES |
1265_F. Beautiful Bracket Sequence (easy version)_38189 | This is the easy version of this problem. The only difference is the limit of n - the length of the input string. In this version, 1 ≤ n ≤ 2000. The hard version of this challenge is not offered in the round for the second division.
Let's define a correct bracket sequence and its depth as follow:
* An empty string... | #include <bits/stdc++.h>
using namespace std;
char ch[2010];
int i, j, n, g[2010][2010], f[2010][2010], ans;
int main() {
scanf("%s", ch + 1);
n = strlen(ch + 1);
for (i = 0; i <= n + 1; i++) {
if (ch[i] == '(') break;
f[i][0] = 1;
}
for (i = n + 1; i >= 1; i--) {
if (ch[i] == ')') break;
g[i]... | 2C++ | {
"input": [
"(?(?))\n",
"??\n",
"???)\n",
"(?(??)))(()?(???)(?((?(?()))(())?))?(?)))?)?)))?)?()(\n",
")\n",
"?\n",
"))\n",
"??????????????????????????????????????????????????????????????????????????????????????????????????????????\n",
"(?\n",
"?)\n",
")?)??)?)))??)???))?))... | 2CODEFORCES |
1265_F. Beautiful Bracket Sequence (easy version)_38190 | This is the easy version of this problem. The only difference is the limit of n - the length of the input string. In this version, 1 ≤ n ≤ 2000. The hard version of this challenge is not offered in the round for the second division.
Let's define a correct bracket sequence and its depth as follow:
* An empty string... | import java.util.*;
import java.io.*;
public class F {
final static long M = 998244353;
public static void main(String[] args) throws IOException {
FastScanner input = new FastScanner(System.in);
PrintWriter output = new PrintWriter(System.out);
String brackets = input.next();
... | 4JAVA | {
"input": [
"(?(?))\n",
"??\n",
"???)\n",
"(?(??)))(()?(???)(?((?(?()))(())?))?(?)))?)?)))?)?()(\n",
")\n",
"?\n",
"))\n",
"??????????????????????????????????????????????????????????????????????????????????????????????????????????\n",
"(?\n",
"?)\n",
")?)??)?)))??)???))?))... | 2CODEFORCES |
1287_B. Hyperset_38191 | Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every... | from __future__ import division, print_function
def main():
# Template 1.0
import sys, re, math
from collections import deque, defaultdict, Counter, OrderedDict
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from heapq import heappush, heappop, heapify, nlargest, nsmallest
... | 1Python2 | {
"input": [
"3 3\nSET\nETS\nTSE\n",
"3 4\nSETE\nETSE\nTSES\n",
"5 4\nSETT\nTEST\nEEET\nESTE\nSTES\n",
"1 1\nT\n",
"10 3\nTSS\nSEE\nESS\nSES\nSTS\nTET\nEES\nEEE\nTTS\nTSE\n",
"3 1\nE\nS\nT\n",
"5 2\nTT\nEE\nTE\nET\nES\n",
"2 2\nES\nTE\n",
"24 4\nSETS\nETES\nSSST\nESTE\nTSES\nSSES\n... | 2CODEFORCES |
1287_B. Hyperset_38192 | Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every... | #include <bits/stdc++.h>
using namespace std;
bool *Seive(long long n, bool *p) {
memset(p, 1, sizeof(p));
long long i, j;
for (i = 2; i <= n; i++) {
if (p[i] == 1)
for (j = i * i; j <= n; j += i) {
p[j] = 0;
}
}
p[1] = 0;
return p;
}
long long gcd(long long a, long long b) {
if (b... | 2C++ | {
"input": [
"3 3\nSET\nETS\nTSE\n",
"3 4\nSETE\nETSE\nTSES\n",
"5 4\nSETT\nTEST\nEEET\nESTE\nSTES\n",
"1 1\nT\n",
"10 3\nTSS\nSEE\nESS\nSES\nSTS\nTET\nEES\nEEE\nTTS\nTSE\n",
"3 1\nE\nS\nT\n",
"5 2\nTT\nEE\nTE\nET\nES\n",
"2 2\nES\nTE\n",
"24 4\nSETS\nETES\nSSST\nESTE\nTSES\nSSES\n... | 2CODEFORCES |
1287_B. Hyperset_38193 | Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every... | import sys
input = sys.stdin.readline
n, k = map(int, input().split())
S = [input().strip() for i in range(n)]
SET = set(S)
p=0
for i in range(n - 1):
for j in range(i + 1, n):
c = []
for l in range(k):
if S[i][l] == S[j][l]:
c += S[i][l]
else:
... | 3Python3 | {
"input": [
"3 3\nSET\nETS\nTSE\n",
"3 4\nSETE\nETSE\nTSES\n",
"5 4\nSETT\nTEST\nEEET\nESTE\nSTES\n",
"1 1\nT\n",
"10 3\nTSS\nSEE\nESS\nSES\nSTS\nTET\nEES\nEEE\nTTS\nTSE\n",
"3 1\nE\nS\nT\n",
"5 2\nTT\nEE\nTE\nET\nES\n",
"2 2\nES\nTE\n",
"24 4\nSETS\nETES\nSSST\nESTE\nTSES\nSSES\n... | 2CODEFORCES |
1287_B. Hyperset_38194 | Bees Alice and Alesya gave beekeeper Polina famous card game "Set" as a Christmas present. The deck consists of cards that vary in four features across three options for each kind of feature: number of shapes, shape, shading, and color. In this game, some combinations of three cards are said to make up a set. For every... | import java.io.*;
import java.util.*;
public class Main{
static int mod = (int)(Math.pow(10, 9) + 7);
public static void main(String[] args) {
MyScanner sc = new MyScanner();
out = new PrintWriter(new BufferedOutputStream(System.out));
int n = sc.nextInt();
int k = sc.nextInt();
if ... | 4JAVA | {
"input": [
"3 3\nSET\nETS\nTSE\n",
"3 4\nSETE\nETSE\nTSES\n",
"5 4\nSETT\nTEST\nEEET\nESTE\nSTES\n",
"1 1\nT\n",
"10 3\nTSS\nSEE\nESS\nSES\nSTS\nTET\nEES\nEEE\nTTS\nTSE\n",
"3 1\nE\nS\nT\n",
"5 2\nTT\nEE\nTE\nET\nES\n",
"2 2\nES\nTE\n",
"24 4\nSETS\nETES\nSSST\nESTE\nTSES\nSSES\n... | 2CODEFORCES |
1307_B. Cow and Friend_38195 | Bessie has way too many friends because she is everyone's favorite cow! Her new friend Rabbit is trying to hop over so they can play!
More specifically, he wants to get from (0,0) to (x,0) by making multiple hops. He is only willing to hop from one point to another point on the 2D plane if the Euclidean distance betw... | from sys import stdin
from itertools import repeat
def solve():
n, x = map(int, stdin.readline().split())
a = map(int, stdin.readline().split(), repeat(10, n))
s = set(a)
mx = max(a)
if x in s:
print 1
else:
print max(2, (x + mx - 1) / mx)
T = int(raw_input())
for _ in xrange(T):... | 1Python2 | {
"input": [
"4\n2 4\n1 3\n3 12\n3 4 5\n1 5\n5\n2 10\n15 4\n",
"1\n10 999999733\n25 68 91 55 36 29 96 4 63 3\n",
"1\n1 11\n5\n",
"1\n2 9\n2 4\n",
"1\n19 1000000000\n15 8 22 12 10 16 2 17 14 7 20 23 9 18 3 19 21 11 1\n",
"1\n1 5\n2\n",
"1\n10 999999733\n25 68 91 55 36 29 96 4 48 3\n",
"... | 2CODEFORCES |
1307_B. Cow and Friend_38196 | Bessie has way too many friends because she is everyone's favorite cow! Her new friend Rabbit is trying to hop over so they can play!
More specifically, he wants to get from (0,0) to (x,0) by making multiple hops. He is only willing to hop from one point to another point on the 2D plane if the Euclidean distance betw... | #include <bits/stdc++.h>
using namespace std;
int T, N;
long long X, M;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> T;
int sol;
long long a;
while (T--) {
cin >> N >> X;
M = 0;
for (int i = 0; i < N; i++) {
cin >> a;
if (M == X) continue;
M = ma... | 2C++ | {
"input": [
"4\n2 4\n1 3\n3 12\n3 4 5\n1 5\n5\n2 10\n15 4\n",
"1\n10 999999733\n25 68 91 55 36 29 96 4 63 3\n",
"1\n1 11\n5\n",
"1\n2 9\n2 4\n",
"1\n19 1000000000\n15 8 22 12 10 16 2 17 14 7 20 23 9 18 3 19 21 11 1\n",
"1\n1 5\n2\n",
"1\n10 999999733\n25 68 91 55 36 29 96 4 48 3\n",
"... | 2CODEFORCES |
1307_B. Cow and Friend_38197 | Bessie has way too many friends because she is everyone's favorite cow! Her new friend Rabbit is trying to hop over so they can play!
More specifically, he wants to get from (0,0) to (x,0) by making multiple hops. He is only willing to hop from one point to another point on the 2D plane if the Euclidean distance betw... | for _ in range(int(input())):
n, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 10**18
for i in range(n):
cnt = x // a[i]
if x % a[i]:
cnt += 1 if cnt else 2
ans = min(ans, cnt)
print(ans)
| 3Python3 | {
"input": [
"4\n2 4\n1 3\n3 12\n3 4 5\n1 5\n5\n2 10\n15 4\n",
"1\n10 999999733\n25 68 91 55 36 29 96 4 63 3\n",
"1\n1 11\n5\n",
"1\n2 9\n2 4\n",
"1\n19 1000000000\n15 8 22 12 10 16 2 17 14 7 20 23 9 18 3 19 21 11 1\n",
"1\n1 5\n2\n",
"1\n10 999999733\n25 68 91 55 36 29 96 4 48 3\n",
"... | 2CODEFORCES |
1307_B. Cow and Friend_38198 | Bessie has way too many friends because she is everyone's favorite cow! Her new friend Rabbit is trying to hop over so they can play!
More specifically, he wants to get from (0,0) to (x,0) by making multiple hops. He is only willing to hop from one point to another point on the 2D plane if the Euclidean distance betw... | // I know stuff but probably my rating tells otherwise...
// Kya hua, code samajhne ki koshish kar rhe ho?? Mat karo,
// mujhe bhi samajh nhi aata kya likha hai
import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class _1307B {
static ... | 4JAVA | {
"input": [
"4\n2 4\n1 3\n3 12\n3 4 5\n1 5\n5\n2 10\n15 4\n",
"1\n10 999999733\n25 68 91 55 36 29 96 4 63 3\n",
"1\n1 11\n5\n",
"1\n2 9\n2 4\n",
"1\n19 1000000000\n15 8 22 12 10 16 2 17 14 7 20 23 9 18 3 19 21 11 1\n",
"1\n1 5\n2\n",
"1\n10 999999733\n25 68 91 55 36 29 96 4 48 3\n",
"... | 2CODEFORCES |
1330_B. Dreamoon Likes Permutations_38199 | The sequence of m integers is called the permutation if it contains all integers from 1 to m exactly once. The number m is called the length of the permutation.
Dreamoon has two permutations p_1 and p_2 of non-zero lengths l_1 and l_2.
Now Dreamoon concatenates these two permutations into another sequence a of length... | for _ in range(input()):
n=input()
a=map(int,raw_input().split())
l=[0 for i in range(n)]
for i in a:
l[i]+=1
size1=0
size2=0
flag=0
zero=0
for i in range(1,n):
if l[i]==2:
size1+=1
size2+=1
if size2>size1:
flag=1
... | 1Python2 | {
"input": [
"6\n5\n1 4 3 2 1\n6\n2 4 1 3 2 1\n4\n2 1 1 3\n4\n1 3 3 1\n12\n2 1 3 4 5 6 7 8 9 1 10 2\n3\n1 1 1\n",
"6\n5\n1 4 3 1 1\n6\n2 4 1 3 2 1\n4\n2 1 1 3\n4\n1 3 3 1\n12\n2 1 3 4 5 6 7 8 9 1 10 2\n3\n1 1 1\n",
"6\n5\n1 4 3 2 1\n6\n2 4 1 3 3 1\n4\n2 1 1 3\n4\n1 3 3 1\n12\n2 1 3 4 5 6 7 8 9 1 10 2\n3\n... | 2CODEFORCES |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.