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 |
|---|---|---|---|---|---|
p01094 Look for the Winner!_37800 | Look for the Winner!
The citizens of TKB City are famous for their deep love in elections and vote counting. Today they hold an election for the next chairperson of the electoral commission. Now the voting has just been closed and the counting is going to start. The TKB citizens have strong desire to know the winner a... | from collections import Counter
while 1:
N=int(input())
if N==0:break
C=raw_input().split()
for i in range(N):
c=Counter(C[:i+1]).most_common()+[('',0)]
if c[0][1]>c[1][1]+N-i-1:
print c[0][0],i+1
break
else:print("TIE") | 1Python2 | {
"input": [
"1\nA\n4\nA A B B\n5\nL M N L N\n6\nK K K K K K\n6\nX X X Y Z X\n10\nA A A B A C A C C B\n10\nU U U U U V V W W W\n0",
"1\nA\n4\nA A B B\n5\nL M N L N\n6\nK K K K K K\n6\nX X X Y Z X\n10\nA A A B A C A C C B\n10\nV U U U U V V W W W\n0",
"1\nA\n4\nA A B B\n5\nL M N L N\n6\nK K K K K K\n6\nX X... | 6AIZU |
p01094 Look for the Winner!_37801 | Look for the Winner!
The citizens of TKB City are famous for their deep love in elections and vote counting. Today they hold an election for the next chairperson of the electoral commission. Now the voting has just been closed and the counting is going to start. The TKB citizens have strong desire to know the winner a... | #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
while(true){
int n,ans,z=0;
vector<int> alp(26,0),A;
char c,winner;
cin>>n;
if(!n) break;
rep(i,n){
cin>>c;
alp[c-'A']++;
... | 2C++ | {
"input": [
"1\nA\n4\nA A B B\n5\nL M N L N\n6\nK K K K K K\n6\nX X X Y Z X\n10\nA A A B A C A C C B\n10\nU U U U U V V W W W\n0",
"1\nA\n4\nA A B B\n5\nL M N L N\n6\nK K K K K K\n6\nX X X Y Z X\n10\nA A A B A C A C C B\n10\nV U U U U V V W W W\n0",
"1\nA\n4\nA A B B\n5\nL M N L N\n6\nK K K K K K\n6\nX X... | 6AIZU |
p01094 Look for the Winner!_37802 | Look for the Winner!
The citizens of TKB City are famous for their deep love in elections and vote counting. Today they hold an election for the next chairperson of the electoral commission. Now the voting has just been closed and the counting is going to start. The TKB citizens have strong desire to know the winner a... | from collections import Counter
while True:
n = int(input())
if n == 0:
quit()
elif n == 1:
print(input(), 1)
else:
c = list(input().split())
h = [0 for i in range(26)]
flag = 0
for i in range(n):
h[ord(c[i])-65] += 1
if sorted(h)[... | 3Python3 | {
"input": [
"1\nA\n4\nA A B B\n5\nL M N L N\n6\nK K K K K K\n6\nX X X Y Z X\n10\nA A A B A C A C C B\n10\nU U U U U V V W W W\n0",
"1\nA\n4\nA A B B\n5\nL M N L N\n6\nK K K K K K\n6\nX X X Y Z X\n10\nA A A B A C A C C B\n10\nV U U U U V V W W W\n0",
"1\nA\n4\nA A B B\n5\nL M N L N\n6\nK K K K K K\n6\nX X... | 6AIZU |
p01094 Look for the Winner!_37803 | Look for the Winner!
The citizens of TKB City are famous for their deep love in elections and vote counting. Today they hold an election for the next chairperson of the electoral commission. Now the voting has just been closed and the counting is going to start. The TKB citizens have strong desire to know the winner a... | import java.util.Arrays;
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(true) {
int n = Integer.parseInt(sc.nextLine());
if(n == 0) break;
String vote = sc.nextLine();
int[] k... | 4JAVA | {
"input": [
"1\nA\n4\nA A B B\n5\nL M N L N\n6\nK K K K K K\n6\nX X X Y Z X\n10\nA A A B A C A C C B\n10\nU U U U U V V W W W\n0",
"1\nA\n4\nA A B B\n5\nL M N L N\n6\nK K K K K K\n6\nX X X Y Z X\n10\nA A A B A C A C C B\n10\nV U U U U V V W W W\n0",
"1\nA\n4\nA A B B\n5\nL M N L N\n6\nK K K K K K\n6\nX X... | 6AIZU |
p01230 Can I go there?_37804 | At one point, there was a president who traveled around Japan to do business. One day he got a mysterious ticket. If you use the ticket, the train fare will be free regardless of the distance to the destination. However, when moving from the current station to the adjacent station is counted as one step, if the number ... | #include <iostream>
#include <vector>
#include <map>
#include <cstring>
using namespace std;
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vec> mat;
typedef long long ll;
int N, M, Z;
int tt[200][200], t[200][200];
map<P,int> idx;
P ridx[200];
const int MOD = 10000;
mat mul(mat &A, mat &B){
mat... | 2C++ | {
"input": [
"2 1 1\n1 2\n2 1 2\n1 2\n3 1 2\n1 2\n8 8 5778\n1 2\n2 3\n2 4\n3 5\n5 6\n6 7\n7 8\n4 8\n8 8 5777\n1 2\n2 3\n2 4\n3 5\n5 6\n6 7\n7 8\n4 8\n0 0 0",
"2 1 1\n1 2\n2 1 2\n1 4\n3 1 2\n1 2\n8 8 5778\n1 2\n2 3\n2 4\n3 5\n5 6\n6 7\n7 8\n4 8\n8 8 5777\n1 2\n2 3\n2 4\n3 5\n5 6\n6 7\n7 8\n4 8\n0 0 0",
"2 ... | 6AIZU |
p01230 Can I go there?_37805 | At one point, there was a president who traveled around Japan to do business. One day he got a mysterious ticket. If you use the ticket, the train fare will be free regardless of the distance to the destination. However, when moving from the current station to the adjacent station is counted as one step, if the number ... | import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static final int MAX_NODES = 51 * 51;
public static final boolean[][] mul(boolean[][] one, boolean[][] two, final int NODES){
boolean[][] ret = new boolean[NODES][NODES];
for(int h = 0; h < NODES; h++)... | 4JAVA | {
"input": [
"2 1 1\n1 2\n2 1 2\n1 2\n3 1 2\n1 2\n8 8 5778\n1 2\n2 3\n2 4\n3 5\n5 6\n6 7\n7 8\n4 8\n8 8 5777\n1 2\n2 3\n2 4\n3 5\n5 6\n6 7\n7 8\n4 8\n0 0 0",
"2 1 1\n1 2\n2 1 2\n1 4\n3 1 2\n1 2\n8 8 5778\n1 2\n2 3\n2 4\n3 5\n5 6\n6 7\n7 8\n4 8\n8 8 5777\n1 2\n2 3\n2 4\n3 5\n5 6\n6 7\n7 8\n4 8\n0 0 0",
"2 ... | 6AIZU |
p01364 Two-Wheel Buggy_37806 | International Car Production Company (ICPC), one of the largest automobile manufacturers in the world, is now developing a new vehicle called "Two-Wheel Buggy". As its name suggests, the vehicle has only two wheels. Quite simply, "Two-Wheel Buggy" is made up of two wheels (the left wheel and the right wheel) and a axle... | #include <iostream>
#include <complex>
#include <cmath>
#include <cstdio>
using namespace std;
typedef complex<double> P;
const double PI = acos(-1.0);
int main(){
int N, D;
while(cin >> N >> D, N){
P p = P(0,0); double dir = PI/2;
for(int i=0;i<N;i++){
int L, R, T; cin >> L >> R >> T;
if(L==R){
p =... | 2C++ | {
"input": [
"1 1\n180 90 2\n1 1\n180 180 20\n2 10\n360 -360 5\n-90 360 8\n3 2\n100 60 9\n-72 -72 10\n-45 -225 5\n0 0",
"1 1\n180 90 2\n1 1\n180 180 20\n2 10\n360 -360 5\n-9 360 8\n3 2\n100 60 9\n-72 -72 10\n-45 -225 5\n0 0",
"1 1\n180 90 2\n1 1\n180 180 20\n2 13\n360 -360 5\n-9 360 8\n3 2\n100 60 9\n-72 ... | 6AIZU |
p01364 Two-Wheel Buggy_37807 | International Car Production Company (ICPC), one of the largest automobile manufacturers in the world, is now developing a new vehicle called "Two-Wheel Buggy". As its name suggests, the vehicle has only two wheels. Quite simply, "Two-Wheel Buggy" is made up of two wheels (the left wheel and the right wheel) and a axle... | from math import pi, cos, sin
def solve():
def rotate(x, y, theta):
cv = cos(theta); sv = sin(theta)
return x*cv - y*sv, x*sv + y*cv
N, D = map(int, input().split())
if N == D == 0:
return False
x0 = -D; x1 = D
y0 = y1 = 0
for i in range(N):
dl, dr, t = map(int, i... | 3Python3 | {
"input": [
"1 1\n180 90 2\n1 1\n180 180 20\n2 10\n360 -360 5\n-90 360 8\n3 2\n100 60 9\n-72 -72 10\n-45 -225 5\n0 0",
"1 1\n180 90 2\n1 1\n180 180 20\n2 10\n360 -360 5\n-9 360 8\n3 2\n100 60 9\n-72 -72 10\n-45 -225 5\n0 0",
"1 1\n180 90 2\n1 1\n180 180 20\n2 13\n360 -360 5\n-9 360 8\n3 2\n100 60 9\n-72 ... | 6AIZU |
p01364 Two-Wheel Buggy_37808 | International Car Production Company (ICPC), one of the largest automobile manufacturers in the world, is now developing a new vehicle called "Two-Wheel Buggy". As its name suggests, the vehicle has only two wheels. Quite simply, "Two-Wheel Buggy" is made up of two wheels (the left wheel and the right wheel) and a axle... | import java.util.*;
import static java.lang.Math.*;
public class Main {
class Point{
double x, y;
Point(double _x, double _y){ this.x = _x; this.y = _y; }
Point(){ new Point(0,0); }
double abs(){ return hypot(this.x,this.y); }
Point rot(double th){
return new Point(x*cos(th)-y*sin(th),x*sin(th) + y*cos... | 4JAVA | {
"input": [
"1 1\n180 90 2\n1 1\n180 180 20\n2 10\n360 -360 5\n-90 360 8\n3 2\n100 60 9\n-72 -72 10\n-45 -225 5\n0 0",
"1 1\n180 90 2\n1 1\n180 180 20\n2 10\n360 -360 5\n-9 360 8\n3 2\n100 60 9\n-72 -72 10\n-45 -225 5\n0 0",
"1 1\n180 90 2\n1 1\n180 180 20\n2 13\n360 -360 5\n-9 360 8\n3 2\n100 60 9\n-72 ... | 6AIZU |
p01546 Sports Days 2_37809 | The University of Aizu Elementary School (Aizu University and Small) is famous as one of Japan's leading competition programmer training schools. Of course, it is essential to practice the algorithm even when attending an athletic meet. Of course you, the director of the competitive programming department, want to win ... | #include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<int,int>;
#defin... | 2C++ | {
"input": [
"7 8 4000\n0 1 1\n1 0 1\n1 2 2\n2 3 2\n3 4 2\n5 4 3\n3 5 4\n5 6 5",
"2 0 1",
"3 9 89\n2 0 2\n1 0 3\n2 0 1\n2 0 3\n0 1 1\n0 1 2\n1 2 3\n0 1 1\n1 0 2",
"2 0 2",
"3 9 89\n2 0 2\n1 0 3\n2 1 1\n2 0 3\n0 1 1\n0 1 2\n1 2 3\n0 1 1\n1 0 2",
"7 8 4000\n0 1 1\n1 0 1\n1 2 2\n2 3 2\n3 4 2\n5 4... | 6AIZU |
p01546 Sports Days 2_37810 | The University of Aizu Elementary School (Aizu University and Small) is famous as one of Japan's leading competition programmer training schools. Of course, it is essential to practice the algorithm even when attending an athletic meet. Of course you, the director of the competitive programming department, want to win ... | from heapq import heappush, heappop, heapify
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N, M, K = map(int, readline().split())
INF = 10**18
E = [[-INF]*N for i in range(N)]
for i in range(M):
a, b, c = map(int, readline().split())
E[a][b] = max(E[a][b]... | 3Python3 | {
"input": [
"7 8 4000\n0 1 1\n1 0 1\n1 2 2\n2 3 2\n3 4 2\n5 4 3\n3 5 4\n5 6 5",
"2 0 1",
"3 9 89\n2 0 2\n1 0 3\n2 0 1\n2 0 3\n0 1 1\n0 1 2\n1 2 3\n0 1 1\n1 0 2",
"2 0 2",
"3 9 89\n2 0 2\n1 0 3\n2 1 1\n2 0 3\n0 1 1\n0 1 2\n1 2 3\n0 1 1\n1 0 2",
"7 8 4000\n0 1 1\n1 0 1\n1 2 2\n2 3 2\n3 4 2\n5 4... | 6AIZU |
p01546 Sports Days 2_37811 | The University of Aizu Elementary School (Aizu University and Small) is famous as one of Japan's leading competition programmer training schools. Of course, it is essential to practice the algorithm even when attending an athletic meet. Of course you, the director of the competitive programming department, want to win ... | import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
public class Main{
static InputStream is;
static PrintWriter out;
static String INPUT = "";
public static void ... | 4JAVA | {
"input": [
"7 8 4000\n0 1 1\n1 0 1\n1 2 2\n2 3 2\n3 4 2\n5 4 3\n3 5 4\n5 6 5",
"2 0 1",
"3 9 89\n2 0 2\n1 0 3\n2 0 1\n2 0 3\n0 1 1\n0 1 2\n1 2 3\n0 1 1\n1 0 2",
"2 0 2",
"3 9 89\n2 0 2\n1 0 3\n2 1 1\n2 0 3\n0 1 1\n0 1 2\n1 2 3\n0 1 1\n1 0 2",
"7 8 4000\n0 1 1\n1 0 1\n1 2 2\n2 3 2\n3 4 2\n5 4... | 6AIZU |
p01702 Unknown Switches_37812 | Problem Statement
In the headquarter building of ICPC (International Company of Plugs & Connectors), there are $M$ light bulbs and they are controlled by $N$ switches. Each light bulb can be turned on or off by exactly one switch. Each switch may control multiple light bulbs. When you operate a switch, all the light b... | ref = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
while 1:
N,M,Q = map(int,raw_input().split())
if N == 0: break
corr = [set(range(N)) for _ in range(M)]
s = ["0"]*N
for loop in xrange(Q):
S,B = raw_input().split()
for i in range(N):
if S[i] == "1": s[i] = {"0":"1","1":"0"}[s... | 1Python2 | {
"input": [
"3 10 3\n000 0000000000\n110 0000001111\n101 1111111100\n2 2 0\n1 1 0\n2 1 1\n01 1\n11 11 10\n10000000000 10000000000\n11000000000 01000000000\n01100000000 00100000000\n00110000000 00010000000\n00011000000 00001000000\n00001100000 00000100000\n00000110000 00000010000\n00000011000 00000001000\n0000000... | 6AIZU |
p01702 Unknown Switches_37813 | Problem Statement
In the headquarter building of ICPC (International Company of Plugs & Connectors), there are $M$ light bulbs and they are controlled by $N$ switches. Each light bulb can be turned on or off by exactly one switch. Each switch may control multiple light bulbs. When you operate a switch, all the light b... | #include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <func... | 2C++ | {
"input": [
"3 10 3\n000 0000000000\n110 0000001111\n101 1111111100\n2 2 0\n1 1 0\n2 1 1\n01 1\n11 11 10\n10000000000 10000000000\n11000000000 01000000000\n01100000000 00100000000\n00110000000 00010000000\n00011000000 00001000000\n00001100000 00000100000\n00000110000 00000010000\n00000011000 00000001000\n0000000... | 6AIZU |
p01702 Unknown Switches_37814 | Problem Statement
In the headquarter building of ICPC (International Company of Plugs & Connectors), there are $M$ light bulbs and they are controlled by $N$ switches. Each light bulb can be turned on or off by exactly one switch. Each switch may control multiple light bulbs. When you operate a switch, all the light b... | while 1:
n,m,q=map(int,input().split())
if (n|m|q)==0: break
p=[]
res=[{_ for _ in range(n)} for _ in range(m)]
for i in range(q):
s,b=[[int(c) for c in s] for s in input().split()]
if i>0:
for j in range(n):
s[j]^=p[j]
zero={i for i in range(n) if s[i]==0}
one={i for i in ran... | 3Python3 | {
"input": [
"3 10 3\n000 0000000000\n110 0000001111\n101 1111111100\n2 2 0\n1 1 0\n2 1 1\n01 1\n11 11 10\n10000000000 10000000000\n11000000000 01000000000\n01100000000 00100000000\n00110000000 00010000000\n00011000000 00001000000\n00001100000 00000100000\n00000110000 00000010000\n00000011000 00000001000\n0000000... | 6AIZU |
p01702 Unknown Switches_37815 | Problem Statement
In the headquarter building of ICPC (International Company of Plugs & Connectors), there are $M$ light bulbs and they are controlled by $N$ switches. Each light bulb can be turned on or off by exactly one switch. Each switch may control multiple light bulbs. When you operate a switch, all the light b... | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner stdIn = new Scanner(System.in);
while(true) {
int n = stdIn.nextInt();
int m = stdIn.nextInt();
int q = stdIn.nextInt();
if(n == 0 && m == 0 && q == 0) break;
String[] S = new String[q];
String[] B = new Str... | 4JAVA | {
"input": [
"3 10 3\n000 0000000000\n110 0000001111\n101 1111111100\n2 2 0\n1 1 0\n2 1 1\n01 1\n11 11 10\n10000000000 10000000000\n11000000000 01000000000\n01100000000 00100000000\n00110000000 00010000000\n00011000000 00001000000\n00001100000 00000100000\n00000110000 00000010000\n00000011000 00000001000\n0000000... | 6AIZU |
p01846 jfen_37816 | jfen
There is a one-person game to play on the H × W board. This game is a game to move 0 or 1 balls in each cell. You were playing this game and found it difficult to move the ball accurately from cell to cell because the ball is so round. So you decided to make a robot that would move the ball as instructed. Here, t... | #include <bits/stdc++.h>
using namespace std;
char j_s_board[10][10];
int idx,width;
int jtos(string jfen){
std::vector<char> board[10];
int len=jfen.length();
idx=0;width=0;
for(int i=0;i<len;i++){
if(jfen[i]=='/') idx++;
else{
if(jfen[i]=='b'){
board[idx].push_back('b');
width... | 2C++ | {
"input": [
"b1/1b\n1 1 1 2\nb5/bbbbbb\n2 4 1 4\nb2b2b/7\n1 4 2 4\n#",
"b1/1b\n1 1 1 2\nb5/bbbbbb\n2 4 1 4\nb2b2b/7\n1 4 2 6\n#",
"b1/1b\n1 1 1 2\nb5/bbbbbb\n2 4 1 5\nb2b2b/7\n1 4 2 4\n#",
"b1/1b\n1 1 1 2\nb5/bbbbbb\n2 4 1 4\nb2b2b/7\n1 4 1 4\n#",
"b1/1b\n1 1 1 2\nb5/bbbbbb\n2 4 0 5\nb2b2b/7\n1 4... | 6AIZU |
p01846 jfen_37817 | jfen
There is a one-person game to play on the H × W board. This game is a game to move 0 or 1 balls in each cell. You were playing this game and found it difficult to move the ball accurately from cell to cell because the ball is so round. So you decided to make a robot that would move the ball as instructed. Here, t... | while True:
s = input()
if s == "#":break
s = s.split("/")
area = [0] * len(s)
for i in range(len(s)):
t = []
while True:
if s[i][0] == "b":
t.append(1)
s[i] = s[i][1:]
else:
if "b" in s[i]:
t... | 3Python3 | {
"input": [
"b1/1b\n1 1 1 2\nb5/bbbbbb\n2 4 1 4\nb2b2b/7\n1 4 2 4\n#",
"b1/1b\n1 1 1 2\nb5/bbbbbb\n2 4 1 4\nb2b2b/7\n1 4 2 6\n#",
"b1/1b\n1 1 1 2\nb5/bbbbbb\n2 4 1 5\nb2b2b/7\n1 4 2 4\n#",
"b1/1b\n1 1 1 2\nb5/bbbbbb\n2 4 1 4\nb2b2b/7\n1 4 1 4\n#",
"b1/1b\n1 1 1 2\nb5/bbbbbb\n2 4 0 5\nb2b2b/7\n1 4... | 6AIZU |
p01846 jfen_37818 | jfen
There is a one-person game to play on the H × W board. This game is a game to move 0 or 1 balls in each cell. You were playing this game and found it difficult to move the ball accurately from cell to cell because the ball is so round. So you decided to make a robot that would move the ball as instructed. Here, t... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in... | 4JAVA | {
"input": [
"b1/1b\n1 1 1 2\nb5/bbbbbb\n2 4 1 4\nb2b2b/7\n1 4 2 4\n#",
"b1/1b\n1 1 1 2\nb5/bbbbbb\n2 4 1 4\nb2b2b/7\n1 4 2 6\n#",
"b1/1b\n1 1 1 2\nb5/bbbbbb\n2 4 1 5\nb2b2b/7\n1 4 2 4\n#",
"b1/1b\n1 1 1 2\nb5/bbbbbb\n2 4 1 4\nb2b2b/7\n1 4 1 4\n#",
"b1/1b\n1 1 1 2\nb5/bbbbbb\n2 4 0 5\nb2b2b/7\n1 4... | 6AIZU |
p01982 Generalized Leap Years_37819 | Generalized leap year
Normally, whether or not the year x is a leap year is defined as follows.
1. If x is a multiple of 400, it is a leap year.
2. Otherwise, if x is a multiple of 100, it is not a leap year.
3. Otherwise, if x is a multiple of 4, it is a leap year.
4. If not, it is not a leap year.
This can be ge... | #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
vector<int> ans(0);
for(;;){
int n,l,r; cin >> n >> l >> r;
if (n == 0 && l == 0 && r == 0) break;
int a[n+1];
fill(a,a+n+1,0);
for(int i = 1; i < n+1; i++){
cin >> a[i... | 2C++ | {
"input": [
"3 1988 2014\n400\n100\n4\n1 1000 1999\n1\n2 1111 3333\n2\n2\n6 2000 3000\n5\n7\n11\n9\n3\n13\n0 0 0",
"3 1988 2014\n400\n100\n4\n1 1000 1999\n1\n2 1111 3333\n2\n2\n6 2000 3000\n5\n7\n21\n9\n3\n13\n0 0 0",
"3 1988 2014\n400\n100\n4\n1 1000 1999\n1\n2 1111 4526\n2\n2\n6 2000 3000\n5\n7\n21\n9\... | 6AIZU |
p01982 Generalized Leap Years_37820 | Generalized leap year
Normally, whether or not the year x is a leap year is defined as follows.
1. If x is a multiple of 400, it is a leap year.
2. Otherwise, if x is a multiple of 100, it is not a leap year.
3. Otherwise, if x is a multiple of 4, it is a leap year.
4. If not, it is not a leap year.
This can be ge... | def solve(n ,l, r, A):
res = 0
for x in range(l, r+1):
for i in range(n):
if (not x%A[i]) :
res += 0 if (i&1) else 1
break
else:
res += 0 if (n&1) else 1
return res
def main():
ans = []
while True:
n, l, r = map(int, ... | 3Python3 | {
"input": [
"3 1988 2014\n400\n100\n4\n1 1000 1999\n1\n2 1111 3333\n2\n2\n6 2000 3000\n5\n7\n11\n9\n3\n13\n0 0 0",
"3 1988 2014\n400\n100\n4\n1 1000 1999\n1\n2 1111 3333\n2\n2\n6 2000 3000\n5\n7\n21\n9\n3\n13\n0 0 0",
"3 1988 2014\n400\n100\n4\n1 1000 1999\n1\n2 1111 4526\n2\n2\n6 2000 3000\n5\n7\n21\n9\... | 6AIZU |
p01982 Generalized Leap Years_37821 | Generalized leap year
Normally, whether or not the year x is a leap year is defined as follows.
1. If x is a multiple of 400, it is a leap year.
2. Otherwise, if x is a multiple of 100, it is not a leap year.
3. Otherwise, if x is a multiple of 4, it is a leap year.
4. If not, it is not a leap year.
This can be ge... | import java.util.*;
import java.io.*;
public class Main{
public static void main(String[] args){
Scanner ir=new Scanner(System.in);
for(;;){
int n=ir.nextInt();
int l=ir.nextInt();
int r=ir.nextInt();
if(n==0){
return;
}
... | 4JAVA | {
"input": [
"3 1988 2014\n400\n100\n4\n1 1000 1999\n1\n2 1111 3333\n2\n2\n6 2000 3000\n5\n7\n11\n9\n3\n13\n0 0 0",
"3 1988 2014\n400\n100\n4\n1 1000 1999\n1\n2 1111 3333\n2\n2\n6 2000 3000\n5\n7\n21\n9\n3\n13\n0 0 0",
"3 1988 2014\n400\n100\n4\n1 1000 1999\n1\n2 1111 4526\n2\n2\n6 2000 3000\n5\n7\n21\n9\... | 6AIZU |
p02128 Light_37822 | Problem
There are $ N $ streetlights on a two-dimensional square of $ W \ times H $.
Gaccho wants to start with $ (1,1) $ and go to $ (W, H) $.
Gaccho is afraid of dark places, so he only wants to walk in the squares that are brightened by the streetlights.
Initially, all streetlights only brighten the squares with th... | // {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#... | 2C++ | {
"input": [
"1 1 1\n1 1",
"5 10 3\n3 9\n2 8\n5 1",
"10 10 1\n6 6",
"5 10 3\n3 9\n2 8\n2 1",
"8 10 1\n6 6",
"5 10 3\n3 9\n2 8\n1 1",
"10 10 3\n3 9\n2 8\n1 1",
"5 10 3\n1 9\n2 8\n5 1",
"10 10 1\n6 2",
"13 10 3\n3 9\n2 6\n1 1",
"5 19 3\n2 9\n2 8\n1 1",
"26 10 3\n3 9\n2 6\... | 6AIZU |
p02128 Light_37823 | Problem
There are $ N $ streetlights on a two-dimensional square of $ W \ times H $.
Gaccho wants to start with $ (1,1) $ and go to $ (W, H) $.
Gaccho is afraid of dark places, so he only wants to walk in the squares that are brightened by the streetlights.
Initially, all streetlights only brighten the squares with th... | import heapq
class point:
def __init__(self, total, use, place):
self.total = total
self.use = use
self.place = place
def __lt__(self, other):
return self.total < other.total or (self.total == other.total and self.use > self.use)
w, h, n = map(int, input().split())
if w == h =... | 3Python3 | {
"input": [
"1 1 1\n1 1",
"5 10 3\n3 9\n2 8\n5 1",
"10 10 1\n6 6",
"5 10 3\n3 9\n2 8\n2 1",
"8 10 1\n6 6",
"5 10 3\n3 9\n2 8\n1 1",
"10 10 3\n3 9\n2 8\n1 1",
"5 10 3\n1 9\n2 8\n5 1",
"10 10 1\n6 2",
"13 10 3\n3 9\n2 6\n1 1",
"5 19 3\n2 9\n2 8\n1 1",
"26 10 3\n3 9\n2 6\... | 6AIZU |
p02269 Dictionary_37824 | Your task is to write a program of a simple dictionary which implements the following instructions:
* insert str: insert a string str in to the dictionary
* find str: if the distionary contains str, then print 'yes', otherwise print 'no'
Notes
Template in C
Constraints
* A string consists of 'A', 'C', 'G', or 'T'
... | #!/usr/bin/env python
# -*- coding:utf-8 -*-
#from __future__ import print_function
import time
import sys
import io
import re
import math
#start = time.clock()
#i = 0
#check = 'insert'
n=input()
a=set()
for x in xrange(n):
(i,f)=map(str, raw_input().split())
if i=='insert':
a.add(f)
else:
i... | 1Python2 | {
"input": [
"5\ninsert A\ninsert T\ninsert C\nfind G\nfind A",
"13\ninsert AAA\ninsert AAC\ninsert AGA\ninsert AGG\ninsert TTT\nfind AAA\nfind CCC\nfind CCC\ninsert CCC\nfind CCC\ninsert T\nfind TTT\nfind T",
"5\ninsert A\ninsert U\ninsert C\nfind G\nfind A",
"13\ninsert AAA\ninsert AAC\ninsert AGA\n... | 6AIZU |
p02269 Dictionary_37825 | Your task is to write a program of a simple dictionary which implements the following instructions:
* insert str: insert a string str in to the dictionary
* find str: if the distionary contains str, then print 'yes', otherwise print 'no'
Notes
Template in C
Constraints
* A string consists of 'A', 'C', 'G', or 'T'
... | #include<set>
#include<iostream>
using namespace std;
int main()
{
int n;
set<string> a;
string cmd, str;
cin>>n;
for(int i = 0; i < n; i++)
{
cin>>cmd>>str;
if(cmd.compare("insert") == 0)
a.insert(str);
else
{
if(a.find(str) != a.end())
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
}... | 2C++ | {
"input": [
"5\ninsert A\ninsert T\ninsert C\nfind G\nfind A",
"13\ninsert AAA\ninsert AAC\ninsert AGA\ninsert AGG\ninsert TTT\nfind AAA\nfind CCC\nfind CCC\ninsert CCC\nfind CCC\ninsert T\nfind TTT\nfind T",
"5\ninsert A\ninsert U\ninsert C\nfind G\nfind A",
"13\ninsert AAA\ninsert AAC\ninsert AGA\n... | 6AIZU |
p02269 Dictionary_37826 | Your task is to write a program of a simple dictionary which implements the following instructions:
* insert str: insert a string str in to the dictionary
* find str: if the distionary contains str, then print 'yes', otherwise print 'no'
Notes
Template in C
Constraints
* A string consists of 'A', 'C', 'G', or 'T'
... | n = int(input())
dic = {}
for i in range(n):
a = input()
if a[0] == "i":
dic[a[7:]] = 0
else:
if a[5:] in dic:
print("yes")
else:
print("no")
| 3Python3 | {
"input": [
"5\ninsert A\ninsert T\ninsert C\nfind G\nfind A",
"13\ninsert AAA\ninsert AAC\ninsert AGA\ninsert AGG\ninsert TTT\nfind AAA\nfind CCC\nfind CCC\ninsert CCC\nfind CCC\ninsert T\nfind TTT\nfind T",
"5\ninsert A\ninsert U\ninsert C\nfind G\nfind A",
"13\ninsert AAA\ninsert AAC\ninsert AGA\n... | 6AIZU |
p02269 Dictionary_37827 | Your task is to write a program of a simple dictionary which implements the following instructions:
* insert str: insert a string str in to the dictionary
* find str: if the distionary contains str, then print 'yes', otherwise print 'no'
Notes
Template in C
Constraints
* A string consists of 'A', 'C', 'G', or 'T'
... |
import java.util.HashSet;
import java.util.Set;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Set<String> set = new HashSet<String>();
int n = sc.nextInt();
for (int i = 0; i < n; i++) {
String cmd = sc.next();
String str = s... | 4JAVA | {
"input": [
"5\ninsert A\ninsert T\ninsert C\nfind G\nfind A",
"13\ninsert AAA\ninsert AAC\ninsert AGA\ninsert AGG\ninsert TTT\nfind AAA\nfind CCC\nfind CCC\ninsert CCC\nfind CCC\ninsert T\nfind TTT\nfind T",
"5\ninsert A\ninsert U\ninsert C\nfind G\nfind A",
"13\ninsert AAA\ninsert AAC\ninsert AGA\n... | 6AIZU |
p02416 Sum of Numbers_37828 | Write a program which reads an integer and prints sum of its digits.
Input
The input consists of multiple datasets. For each dataset, an integer x is given in a line. The number of digits in x does not exceed 1000.
The input ends with a line including single zero. Your program should not process for this terminal ... | X = []
while True:
x = raw_input()
if x == "0":
break
else:
X.append(x)
ans = []
for i in range(len(X)):
tmp = 0
for j in range(len(X[i])):
tmp+=int(X[i][j])
ans.append(tmp)
for char in ans:
print char
| 1Python2 | {
"input": [
"123\n55\n1000\n0",
"123\n55\n1001\n0",
"123\n69\n1000\n0",
"123\n69\n1010\n0",
"123\n69\n1110\n0",
"123\n55\n0001\n0",
"123\n55\n1101\n0",
"123\n69\n1111\n0",
"123\n23\n1001\n0",
"123\n65\n0001\n0",
"123\n151\n1101\n0",
"123\n132\n1000\n0",
"123\n45\n1... | 6AIZU |
p02416 Sum of Numbers_37829 | Write a program which reads an integer and prints sum of its digits.
Input
The input consists of multiple datasets. For each dataset, an integer x is given in a line. The number of digits in x does not exceed 1000.
The input ends with a line including single zero. Your program should not process for this terminal ... | #include <bits/stdc++.h>
using namespace std;
int main() {
while(true){
string s;
cin >> s;
if(s == "0") return 0;
int sum = 0;
for(int i = 0;i < s.size();i++){
sum += s[i]-'0';
}
cout << sum << endl;
}
}
| 2C++ | {
"input": [
"123\n55\n1000\n0",
"123\n55\n1001\n0",
"123\n69\n1000\n0",
"123\n69\n1010\n0",
"123\n69\n1110\n0",
"123\n55\n0001\n0",
"123\n55\n1101\n0",
"123\n69\n1111\n0",
"123\n23\n1001\n0",
"123\n65\n0001\n0",
"123\n151\n1101\n0",
"123\n132\n1000\n0",
"123\n45\n1... | 6AIZU |
p02416 Sum of Numbers_37830 | Write a program which reads an integer and prints sum of its digits.
Input
The input consists of multiple datasets. For each dataset, an integer x is given in a line. The number of digits in x does not exceed 1000.
The input ends with a line including single zero. Your program should not process for this terminal ... | while True:
n = input()
if n == "0": break
n = map(int, n)
print(sum(n))
| 3Python3 | {
"input": [
"123\n55\n1000\n0",
"123\n55\n1001\n0",
"123\n69\n1000\n0",
"123\n69\n1010\n0",
"123\n69\n1110\n0",
"123\n55\n0001\n0",
"123\n55\n1101\n0",
"123\n69\n1111\n0",
"123\n23\n1001\n0",
"123\n65\n0001\n0",
"123\n151\n1101\n0",
"123\n132\n1000\n0",
"123\n45\n1... | 6AIZU |
p02416 Sum of Numbers_37831 | Write a program which reads an integer and prints sum of its digits.
Input
The input consists of multiple datasets. For each dataset, an integer x is given in a line. The number of digits in x does not exceed 1000.
The input ends with a line including single zero. Your program should not process for this terminal ... | import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
while(true){
String s=sc.next();
if(s.equals("0")) break;
int ans=0;
for(int i=0;i<s.length();i++){
ans+=s.charAt(i... | 4JAVA | {
"input": [
"123\n55\n1000\n0",
"123\n55\n1001\n0",
"123\n69\n1000\n0",
"123\n69\n1010\n0",
"123\n69\n1110\n0",
"123\n55\n0001\n0",
"123\n55\n1101\n0",
"123\n69\n1111\n0",
"123\n23\n1001\n0",
"123\n65\n0001\n0",
"123\n151\n1101\n0",
"123\n132\n1000\n0",
"123\n45\n1... | 6AIZU |
btreat_37832 | Its Chef's Birthday and his friends are demanding him for treat. So he went to the shop to buy N gift packets (one for each friend). Each gift packet bought from shop contains some number of chocolates in it.
Chef believes in equality i.e. all gift packets should contain equal number of chocolates in it. So Chef thou... | import sys
for t in xrange(int(sys.stdin.readline())):
n=int(sys.stdin.readline())
arr=map(int,sys.stdin.readline().split())
s=sum(arr)
if s%n ==0:
avg=s/n
c=0
for i in xrange(n):
c+=abs(avg-arr[i])
print c/2
else:
print "No Treat" | 1Python2 | {
"input": [
"2\n4\n5 2 4 5\n6\n5 2 4 1 7 5"
],
"output": [
"2\n5"
]
} | 1CODECHEF |
compiler_37833 | Lira is now very keen on compiler development. :)
She knows that one of the most important components of a compiler, is its parser.
A parser is, in simple terms, a software component that processes text, and checks it's semantic correctness, or, if you prefer, if the text is properly built.
As an example, in declaring... | import sys
RL = sys.stdin.readline
T = int(RL())
for i in xrange(T):
inp = RL()
stack = 0
strlen = len(inp)
count = 0
for j in xrange(strlen):
if inp[j] == '<':
stack += 1
elif inp[j] == '>':
if stack == 0:
break
stack -= 1
... | 1Python2 | {
"input": [
"3\n<<>>\n><\n<>>>",
"3\n<<>>\n<>\n<>>>",
"3\n><<>\n<>\n<>>>",
"3\n><<>\n><\n<>>>",
"3\n<<>>\n><\n<>>?",
"3\n><<>\n<>\n><>?",
"3\n><<>\n><\n>><>",
"3\n<<>>\n<>\n>>><",
"3\n<<>>\n><\n>>><",
"3\n<>><\n<>\n>>><",
"3\n<>><\n<>\n<>>?",
"3\n<>><\n><\n<>>?",
"... | 1CODECHEF |
gdog_37834 | Tuzik is a little dog. But despite the fact he is still a puppy he already knows about the pretty things that coins are. He knows that for every coin he can get very tasty bone from his master. He believes that some day he will find a treasure and have loads of bones.
And finally he found something interesting. A woode... | # @author Kilari Teja
# GDOG
Possibles = [100, 50, 10, 5, 2, 1]
for _ in xrange(int(raw_input().strip())):
Bucks = map(int, raw_input().strip().split(" "))
MaxBucks = 0
for People in xrange(1, Bucks[1] + 1):
if Bucks[0]%People > MaxBucks:
MaxBucks = Bucks[0]%People
print MaxBucks | 1Python2 | {
"input": [
"2\n5 2\n11 3",
"2\n5 4\n11 3",
"2\n5 4\n11 6",
"2\n5 4\n8 6",
"2\n5 2\n5 3",
"2\n5 8\n11 6",
"2\n10 7\n8 6",
"2\n1 4\n15 6",
"2\n1 2\n15 2",
"2\n9 4\n11 6",
"2\n5 8\n11 4",
"2\n10 4\n1 6",
"2\n15 4\n15 6",
"2\n10 7\n8 10",
"2\n1 2\n14 6",
"... | 1CODECHEF |
m3_37835 | The new season of the Bytelandian Premier League (BPL) has started!
In the BPL, any two soccer teams play with each other exactly once. In each match, the winner earns 3 points and the loser earns no point. There is no draw (if the match is level after the two halves, two teams will take part in a penalty shootout to d... | #!/usr/bin/python
# Richard Lee
import os
import sys
def champion_possible(team_id, r_m, c_list):
def team_sort(x, y):
rx = r[x]
ry = r[y]
if rx == ry:
return p[y] - p[x]
return rx - ry
def team_sort_r(x, y):
rx = r[x]
ry = r[y]
if rx == ry:
return ... | 1Python2 | {
"input": [
"3\n3\n0 0 0 \n1 0 1 \n1 0 0 \n4\n0 1 1 0 \n0 0 2 0 \n0 2 0 0 \n1 1 1 0 \n5\n0 2 2 1 0 \n2 0 1 1 0 \n2 0 0 1 0 \n0 0 0 0 1 \n1 1 1 0 0"
],
"output": [
"010\n0001\n11001"
]
} | 1CODECHEF |
prys01_37836 | Problem Statement
N knights were sitting at a round table and having a serious talk. The knights are so tired, that they can’t even rotate their neck to talk to talk to the knights sitting on their sides. So, a knight can only talk to the knight sitting diametrically opposite to him on the table.
Given the number of kn... | #chiragjn
t=int(raw_input())
for i in xrange(t):
n,m=map(int,raw_input().split())
print m+(n>>1) if m<=n/2 else m-(n>>1) | 1Python2 | {
"input": [
"1\n6 2",
"1\n10 2",
"1\n20 2",
"1\n20 3",
"1\n39 3",
"1\n68 3",
"1\n10 3",
"1\n16 3",
"1\n29 4",
"1\n3 4",
"1\n3 5",
"1\n3 0",
"1\n3 1",
"1\n1 0",
"1\n-1 4",
"1\n-2 8",
"1\n-1 -1",
"1\n0 -1",
"1\n17 -2",
"1\n-4 -2",
"1\n... | 1CODECHEF |
tidrice_37837 | Did you know that there are over 40,000 varieties of Rice in the world ? There are so many dishes that can be prepared with Rice too. A famous chef from Mumbai, Tid Gusto prepared a new dish and named it 'Tid Rice'. He posted the recipe in his newly designed blog for community voting, where a user can plus (+) or minus... | t=int(raw_input())
for _ in range(0,t):
n=int(raw_input())
d= dict(raw_input().split() for _ in range(n))
k=[]
for value in d:
k.append(d[value])
sum=0
for item in k:
if item=='+':
sum+=1
elif item=="-":
sum-=1
print sum | 1Python2 | {
"input": [
"3\n4\ntilak +\ntilak +\ntilak -\ntilak +\n3\nratna +\nshashi -\nratna -\n3\nbhavani -\nbhavani +\nbhavani -",
"3\n4\ntilak +\ntilak +\ntilak -\ntilaj +\n3\nratna +\nshashi -\nratna -\n3\nbhavani -\nbhavani +\nbhavani -",
"3\n4\ntilak +\nkalit +\ntilak -\ntilak +\n3\nratna +\nshashi -\nratna ... | 1CODECHEF |
1013_A. Piles With Stones_37838 | There is a beautiful garden of stones in Innopolis.
Its most beautiful place is the n piles with stones numbered from 1 to n.
EJOI participants have visited this place twice.
When they first visited it, the number of stones in piles was x_1, x_2, …, x_n, correspondingly. One of the participants wrote down this sequ... | n = input()
t1 = map(int, raw_input().split())
t2 = map(int, raw_input().split())
s_t1 = sum(t1)
s_t2 = sum(t2)
if s_t2>s_t1:
print 'No'
exit(0)
else:
print 'Yes'
exit(0) | 1Python2 | {
"input": [
"5\n1 2 3 4 5\n2 1 4 3 5\n",
"5\n1 1 1 1 1\n1 0 1 0 1\n",
"3\n2 3 9\n1 7 9\n",
"4\n1000 1000 1000 1000\n1000 1000 1000 1000\n",
"5\n3 3 3 3 3\n2 2 2 2 2\n",
"20\n82 292 379 893 300 854 895 638 58 971 278 168 580 272 653 315 176 773 709 789\n298 710 311 695 328 459 510 994 472 515 ... | 2CODEFORCES |
1013_A. Piles With Stones_37839 | There is a beautiful garden of stones in Innopolis.
Its most beautiful place is the n piles with stones numbered from 1 to n.
EJOI participants have visited this place twice.
When they first visited it, the number of stones in piles was x_1, x_2, …, x_n, correspondingly. One of the participants wrote down this sequ... | #include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long int llINF = 0x3f3f3f3f3f3f3f;
int main() {
int n;
cin >> n;
long long int a = 0, b = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
a += x;
}
for (int i = 0; i < n; i++) {
int x;
cin >> x;
b ... | 2C++ | {
"input": [
"5\n1 2 3 4 5\n2 1 4 3 5\n",
"5\n1 1 1 1 1\n1 0 1 0 1\n",
"3\n2 3 9\n1 7 9\n",
"4\n1000 1000 1000 1000\n1000 1000 1000 1000\n",
"5\n3 3 3 3 3\n2 2 2 2 2\n",
"20\n82 292 379 893 300 854 895 638 58 971 278 168 580 272 653 315 176 773 709 789\n298 710 311 695 328 459 510 994 472 515 ... | 2CODEFORCES |
1013_A. Piles With Stones_37840 | There is a beautiful garden of stones in Innopolis.
Its most beautiful place is the n piles with stones numbered from 1 to n.
EJOI participants have visited this place twice.
When they first visited it, the number of stones in piles was x_1, x_2, …, x_n, correspondingly. One of the participants wrote down this sequ... | n=int(input())
p=input().split(' ')
c=input().split(' ')
t=z=0
for k in range(n):
t+=int(p[k])
z+=int(c[k])
if (t<z):
print('No')
else:
print('Yes')
| 3Python3 | {
"input": [
"5\n1 2 3 4 5\n2 1 4 3 5\n",
"5\n1 1 1 1 1\n1 0 1 0 1\n",
"3\n2 3 9\n1 7 9\n",
"4\n1000 1000 1000 1000\n1000 1000 1000 1000\n",
"5\n3 3 3 3 3\n2 2 2 2 2\n",
"20\n82 292 379 893 300 854 895 638 58 971 278 168 580 272 653 315 176 773 709 789\n298 710 311 695 328 459 510 994 472 515 ... | 2CODEFORCES |
1013_A. Piles With Stones_37841 | There is a beautiful garden of stones in Innopolis.
Its most beautiful place is the n piles with stones numbered from 1 to n.
EJOI participants have visited this place twice.
When they first visited it, the number of stones in piles was x_1, x_2, …, x_n, correspondingly. One of the participants wrote down this sequ... | import java.util.*;
import java.io.*;
public class C{
public static void main(String[] args) {
MyScanner scan = new MyScanner();
PrintWriter pw = new PrintWriter(System.out);
int n = scan.nextInt();
long sum1 = 0,sum2 = 0;
for(int i = 0;i < n;i++)
... | 4JAVA | {
"input": [
"5\n1 2 3 4 5\n2 1 4 3 5\n",
"5\n1 1 1 1 1\n1 0 1 0 1\n",
"3\n2 3 9\n1 7 9\n",
"4\n1000 1000 1000 1000\n1000 1000 1000 1000\n",
"5\n3 3 3 3 3\n2 2 2 2 2\n",
"20\n82 292 379 893 300 854 895 638 58 971 278 168 580 272 653 315 176 773 709 789\n298 710 311 695 328 459 510 994 472 515 ... | 2CODEFORCES |
1037_G. A Game on Strings_37842 | Alice and Bob are playing a game on strings.
Initially, they have some string t. In one move the first player selects the character c present in t and erases all it's occurrences in t, thus splitting t into many smaller strings. The game then goes independently with each of the strings — to make the move player select... | #include <bits/stdc++.h>
using namespace std;
struct pat {
int x, y;
pat(int x = 0, int y = 0) : x(x), y(y) {}
bool operator<(const pat &p) const { return x == p.x ? y < p.y : x < p.x; }
};
namespace RKK {
const int N = 100011;
int n, qaq;
char str[N];
int s[N];
int nxt[N][26], pre[N][26];
int f[N][26], g[N];
int... | 2C++ | {
"input": [
"aaccbdb\n2\n5 7\n1 7\n",
"aaab\n2\n1 2\n1 4\n",
"mrxphlhblv\n10\n3 5\n5 5\n2 9\n3 7\n5 9\n6 10\n7 9\n1 6\n7 8\n9 10\n",
"nr\n1\n1 2\n",
"eulmtquiue\n10\n6 9\n4 8\n7 7\n1 9\n2 3\n1 4\n2 9\n1 6\n1 6\n4 6\n",
"mrxphlhblv\n10\n3 9\n5 5\n2 9\n3 7\n5 9\n6 10\n7 9\n1 6\n7 8\n9 10\n",
... | 2CODEFORCES |
1037_G. A Game on Strings_37843 | Alice and Bob are playing a game on strings.
Initially, they have some string t. In one move the first player selects the character c present in t and erases all it's occurrences in t, thus splitting t into many smaller strings. The game then goes independently with each of the strings — to make the move player select... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.InputStream;
/**... | 4JAVA | {
"input": [
"aaccbdb\n2\n5 7\n1 7\n",
"aaab\n2\n1 2\n1 4\n",
"mrxphlhblv\n10\n3 5\n5 5\n2 9\n3 7\n5 9\n6 10\n7 9\n1 6\n7 8\n9 10\n",
"nr\n1\n1 2\n",
"eulmtquiue\n10\n6 9\n4 8\n7 7\n1 9\n2 3\n1 4\n2 9\n1 6\n1 6\n4 6\n",
"mrxphlhblv\n10\n3 9\n5 5\n2 9\n3 7\n5 9\n6 10\n7 9\n1 6\n7 8\n9 10\n",
... | 2CODEFORCES |
1060_C. Maximum Subrectangle_37844 | You are given two arrays a and b of positive integers, with length n and m respectively.
Let c be an n × m matrix, where c_{i,j} = a_i ⋅ b_j.
You need to find a subrectangle of the matrix c such that the sum of its elements is at most x, and its area (the total number of elements) is the largest possible.
Formally... | n,m=map(int,raw_input().split())
a=list(map(int,raw_input().split()))
b=list(map(int,raw_input().split()))
x=int(raw_input())
pref_a=[0]
for i in a:
pref_a.append(pref_a[-1]+i)
pref_b=[0]
for i in b:
pref_b.append(pref_b[-1]+i)
min_a=[float('inf')]*(n+1)
min_b=[float('inf')]*(m+1)
for i in range(1,n+1):
fo... | 1Python2 | {
"input": [
"5 1\n5 4 2 4 5\n2\n5\n",
"3 3\n1 2 3\n1 2 3\n9\n",
"100 1\n1525 1915 925 1023 803 904 802 1943 954 23 258 505 972 571 1291 1024 161 461 1020 880 67 1975 1612 1599 1024 682 1810 500 1068 1992 1834 79 476 842 1366 17 1307 1595 587 367 1961 1018 960 1699 1799 1453 1890 1003 780 601 131 808 83 2... | 2CODEFORCES |
1060_C. Maximum Subrectangle_37845 | You are given two arrays a and b of positive integers, with length n and m respectively.
Let c be an n × m matrix, where c_{i,j} = a_i ⋅ b_j.
You need to find a subrectangle of the matrix c such that the sum of its elements is at most x, and its area (the total number of elements) is the largest possible.
Formally... | #include <bits/stdc++.h>
using ll = long long;
const int maxn = 2018;
const ll inf = 10000000000000;
int main(int argc, char *argv[]) {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
ll n, m, x, a[maxn], b[maxn], pa[maxn], pb[maxn], ma[maxn], mb[maxn];
std::cin >> n >> m;
pa[0] = pb[0] = 0;
for (int i =... | 2C++ | {
"input": [
"5 1\n5 4 2 4 5\n2\n5\n",
"3 3\n1 2 3\n1 2 3\n9\n",
"100 1\n1525 1915 925 1023 803 904 802 1943 954 23 258 505 972 571 1291 1024 161 461 1020 880 67 1975 1612 1599 1024 682 1810 500 1068 1992 1834 79 476 842 1366 17 1307 1595 587 367 1961 1018 960 1699 1799 1453 1890 1003 780 601 131 808 83 2... | 2CODEFORCES |
1060_C. Maximum Subrectangle_37846 | You are given two arrays a and b of positive integers, with length n and m respectively.
Let c be an n × m matrix, where c_{i,j} = a_i ⋅ b_j.
You need to find a subrectangle of the matrix c such that the sum of its elements is at most x, and its area (the total number of elements) is the largest possible.
Formally... | n,m=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
b=[int(x) for x in input().split()]
x=int(input())
csa=[0]*(n+1)
csb=[0]*(m+1)
ans=0
for i in range(1,n+1):
csa[i]=(csa[i-1]+a[i-1])
for i in range(1,m+1):
csb[i]=(csb[i-1]+b[i-1])
misubsa=[0]*(n+1)
misubsb=[0]*(m+1)
for i in range(1,n+1)... | 3Python3 | {
"input": [
"5 1\n5 4 2 4 5\n2\n5\n",
"3 3\n1 2 3\n1 2 3\n9\n",
"100 1\n1525 1915 925 1023 803 904 802 1943 954 23 258 505 972 571 1291 1024 161 461 1020 880 67 1975 1612 1599 1024 682 1810 500 1068 1992 1834 79 476 842 1366 17 1307 1595 587 367 1961 1018 960 1699 1799 1453 1890 1003 780 601 131 808 83 2... | 2CODEFORCES |
1060_C. Maximum Subrectangle_37847 | You are given two arrays a and b of positive integers, with length n and m respectively.
Let c be an n × m matrix, where c_{i,j} = a_i ⋅ b_j.
You need to find a subrectangle of the matrix c such that the sum of its elements is at most x, and its area (the total number of elements) is the largest possible.
Formally... | import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
new Main().go();
}
PrintWriter out;
InputReader in;
BufferedReader br;
Main() throws IOException {
try {
//br = new BufferedReader( new FileReade... | 4JAVA | {
"input": [
"5 1\n5 4 2 4 5\n2\n5\n",
"3 3\n1 2 3\n1 2 3\n9\n",
"100 1\n1525 1915 925 1023 803 904 802 1943 954 23 258 505 972 571 1291 1024 161 461 1020 880 67 1975 1612 1599 1024 682 1810 500 1068 1992 1834 79 476 842 1366 17 1307 1595 587 367 1961 1018 960 1699 1799 1453 1890 1003 780 601 131 808 83 2... | 2CODEFORCES |
1082_A. Vasya and Book_37848 | Vasya is reading a e-book. The file of the book consists of n pages, numbered from 1 to n. The screen is currently displaying the contents of page x, and Vasya wants to read the page y. There are two buttons on the book which allow Vasya to scroll d pages forwards or backwards (but he cannot scroll outside the book). F... | a=int(raw_input())
for i in xrange(a):
n,x,y,d=map(int,raw_input().split())
res=99999999999999999999999999999
if abs(x-y)%d==0:
res=min(res,abs(x-y)/d)
if (y-1)%d==0:
if (x-1)%d==0:
res=min(res,(x-1)/d+(y-1)/d)
else:
res=min(res,(x-1)/d+(y-1)/d+1)
if (n-y)%d==0:
if (n-x)%d==0:
res=min(res,(n-x)/d... | 1Python2 | {
"input": [
"3\n10 4 5 2\n5 1 3 4\n20 4 19 3\n",
"1\n123 123 123 123\n",
"1\n1000000000 5 999999999 1\n",
"1\n1000000000 1 1000000000 2\n",
"5\n20 10 2 9\n1000000000 2 89 4\n1000000000 2 89 8\n1000000000 89 1 1000000000\n1000000000 1000000000 2 3\n",
"1\n1010 1010 1010 1010\n",
"1\n11 11 ... | 2CODEFORCES |
1082_A. Vasya and Book_37849 | Vasya is reading a e-book. The file of the book consists of n pages, numbered from 1 to n. The screen is currently displaying the contents of page x, and Vasya wants to read the page y. There are two buttons on the book which allow Vasya to scroll d pages forwards or backwards (but he cannot scroll outside the book). F... | #include <bits/stdc++.h>
using namespace std;
inline void boost() {
ios_base::sync_with_stdio();
cin.tie(0);
cout.tie(0);
}
const long long maxn = 1e5 + 123;
const long long inf = 1e9 + 123;
const long long mod = 1e9 + 7;
const double pi = acos(-1);
int main() {
boost();
int t;
cin >> t;
for (int i = 1; i... | 2C++ | {
"input": [
"3\n10 4 5 2\n5 1 3 4\n20 4 19 3\n",
"1\n123 123 123 123\n",
"1\n1000000000 5 999999999 1\n",
"1\n1000000000 1 1000000000 2\n",
"5\n20 10 2 9\n1000000000 2 89 4\n1000000000 2 89 8\n1000000000 89 1 1000000000\n1000000000 1000000000 2 3\n",
"1\n1010 1010 1010 1010\n",
"1\n11 11 ... | 2CODEFORCES |
1082_A. Vasya and Book_37850 | Vasya is reading a e-book. The file of the book consists of n pages, numbered from 1 to n. The screen is currently displaying the contents of page x, and Vasya wants to read the page y. There are two buttons on the book which allow Vasya to scroll d pages forwards or backwards (but he cannot scroll outside the book). F... | T = int(input())
from math import ceil
for i in range(T):
n,in_,fin_,d = map(int,input().split())
r1 = in_%d
r2 = fin_%d
r = n%d
z = float("inf")
a1,a2,a3 = float("inf"),float("inf"),float("inf")
if r1 == r2:
a1 = abs(fin_-in_)//d
if r2 == r:
a2 = ceil((n-in_)/d)+abs((fin_-n)//d)
if r2 == 1:
a3 = ceil... | 3Python3 | {
"input": [
"3\n10 4 5 2\n5 1 3 4\n20 4 19 3\n",
"1\n123 123 123 123\n",
"1\n1000000000 5 999999999 1\n",
"1\n1000000000 1 1000000000 2\n",
"5\n20 10 2 9\n1000000000 2 89 4\n1000000000 2 89 8\n1000000000 89 1 1000000000\n1000000000 1000000000 2 3\n",
"1\n1010 1010 1010 1010\n",
"1\n11 11 ... | 2CODEFORCES |
1082_A. Vasya and Book_37851 | Vasya is reading a e-book. The file of the book consists of n pages, numbered from 1 to n. The screen is currently displaying the contents of page x, and Vasya wants to read the page y. There are two buttons on the book which allow Vasya to scroll d pages forwards or backwards (but he cannot scroll outside the book). F... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in... | 4JAVA | {
"input": [
"3\n10 4 5 2\n5 1 3 4\n20 4 19 3\n",
"1\n123 123 123 123\n",
"1\n1000000000 5 999999999 1\n",
"1\n1000000000 1 1000000000 2\n",
"5\n20 10 2 9\n1000000000 2 89 4\n1000000000 2 89 8\n1000000000 89 1 1000000000\n1000000000 1000000000 2 3\n",
"1\n1010 1010 1010 1010\n",
"1\n11 11 ... | 2CODEFORCES |
1101_C. Division and Union_37852 | There are n segments [l_i, r_i] for 1 ≤ i ≤ n. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing pr... | #!/usr/bin/env python
"""
This file is part of https://github.com/Cheran-Senthil/PyRival.
Copyright 2018 Cheran Senthilkumar all rights reserved,
Cheran Senthilkumar <hello@cheran.io>
Permission to use, modify, and distribute this software is given under the
terms of the MIT License.
"""
from __future__ import divisi... | 1Python2 | {
"input": [
"3\n2\n5 5\n2 3\n3\n3 5\n2 3\n2 3\n3\n3 3\n4 4\n5 5\n",
"3\n2\n5 5\n2 3\n3\n3 5\n1 3\n2 3\n3\n3 3\n4 4\n5 5\n",
"3\n2\n3 5\n2 3\n3\n3 5\n1 5\n2 3\n3\n3 3\n4 4\n5 4\n",
"3\n2\n5 5\n2 3\n3\n3 5\n1 3\n2 3\n2\n3 3\n4 4\n5 5\n",
"3\n2\n5 5\n2 3\n3\n3 5\n1 3\n2 3\n2\n3 4\n4 4\n5 5\n",
"... | 2CODEFORCES |
1101_C. Division and Union_37853 | There are n segments [l_i, r_i] for 1 ≤ i ≤ n. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing pr... | #include <bits/stdc++.h>
using namespace std;
int main() {
int q = 0;
cin >> q;
vector<pair<pair<int, int>, int>> intervals;
for (int i = 0; i < q; i++) {
int n;
cin >> n;
intervals.resize(n);
for (int j = 0; j < n; j++) {
cin >> intervals[j].first.first >> intervals[j].first.second;
... | 2C++ | {
"input": [
"3\n2\n5 5\n2 3\n3\n3 5\n2 3\n2 3\n3\n3 3\n4 4\n5 5\n",
"3\n2\n5 5\n2 3\n3\n3 5\n1 3\n2 3\n3\n3 3\n4 4\n5 5\n",
"3\n2\n3 5\n2 3\n3\n3 5\n1 5\n2 3\n3\n3 3\n4 4\n5 4\n",
"3\n2\n5 5\n2 3\n3\n3 5\n1 3\n2 3\n2\n3 3\n4 4\n5 5\n",
"3\n2\n5 5\n2 3\n3\n3 5\n1 3\n2 3\n2\n3 4\n4 4\n5 5\n",
"... | 2CODEFORCES |
1101_C. Division and Union_37854 | There are n segments [l_i, r_i] for 1 ≤ i ≤ n. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing pr... | for _ in range(int(input())):
n=int(input())
a=sorted(list(map(int,input().split()))+[i] for i in range(n))
ans=[0]*n
group=1
maxx=a[0][1]
for l,r,i in a:
if group==1 and maxx<l:
group=2
if r>maxx:
maxx=r
ans[i]=group
if group==2:
print... | 3Python3 | {
"input": [
"3\n2\n5 5\n2 3\n3\n3 5\n2 3\n2 3\n3\n3 3\n4 4\n5 5\n",
"3\n2\n5 5\n2 3\n3\n3 5\n1 3\n2 3\n3\n3 3\n4 4\n5 5\n",
"3\n2\n3 5\n2 3\n3\n3 5\n1 5\n2 3\n3\n3 3\n4 4\n5 4\n",
"3\n2\n5 5\n2 3\n3\n3 5\n1 3\n2 3\n2\n3 3\n4 4\n5 5\n",
"3\n2\n5 5\n2 3\n3\n3 5\n1 3\n2 3\n2\n3 4\n4 4\n5 5\n",
"... | 2CODEFORCES |
1101_C. Division and Union_37855 | There are n segments [l_i, r_i] for 1 ≤ i ≤ n. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.
To optimize testing pr... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream... | 4JAVA | {
"input": [
"3\n2\n5 5\n2 3\n3\n3 5\n2 3\n2 3\n3\n3 3\n4 4\n5 5\n",
"3\n2\n5 5\n2 3\n3\n3 5\n1 3\n2 3\n3\n3 3\n4 4\n5 5\n",
"3\n2\n3 5\n2 3\n3\n3 5\n1 5\n2 3\n3\n3 3\n4 4\n5 4\n",
"3\n2\n5 5\n2 3\n3\n3 5\n1 3\n2 3\n2\n3 3\n4 4\n5 5\n",
"3\n2\n5 5\n2 3\n3\n3 5\n1 3\n2 3\n2\n3 4\n4 4\n5 5\n",
"... | 2CODEFORCES |
112_A. Petya and Strings_37856 | Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corr... | x= raw_input();
y = raw_input();
if x.lower() == y.lower():
print 0
elif x.lower() > y.lower():
print 1
else:
print -1 | 1Python2 | {
"input": [
"aaaa\naaaA\n",
"abs\nAbz\n",
"abcdefg\nAbCdEfF\n",
"kigPrWNTOUNDBskAfefjhHYZNYdnfZWuXWzHiBxFQryBbAkPtenFwWvCSTYGpzOntUNzNUhxRWjKmicTwLwJAnbAxj\nkigpRWntOUNdBsKaFEFjhhYZnYDNfzWuXwZhibxFQRybbakPteNfwwvcStyGPzoNTunznuHXrWjKMIctWLWJANBAxJ\n",
"DQBdtSEDtFGiNRUeJNbOIfDZnsryUlzJHGTXGFXnwsVy... | 2CODEFORCES |
112_A. Petya and Strings_37857 | Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corr... | #include <bits/stdc++.h>
using namespace std;
string a, b;
int main() {
string a, b;
cin >> a >> b;
for (int i = 0; i < a.size(); i++) {
if (char(tolower(a[i])) == char(tolower(b[i]))) {
continue;
} else if (char(tolower(a[i])) > char(tolower(b[i]))) {
cout << 1 << endl;
return 0;
} ... | 2C++ | {
"input": [
"aaaa\naaaA\n",
"abs\nAbz\n",
"abcdefg\nAbCdEfF\n",
"kigPrWNTOUNDBskAfefjhHYZNYdnfZWuXWzHiBxFQryBbAkPtenFwWvCSTYGpzOntUNzNUhxRWjKmicTwLwJAnbAxj\nkigpRWntOUNdBsKaFEFjhhYZnYDNfzWuXwZhibxFQRybbakPteNfwwvcStyGPzoNTunznuHXrWjKMIctWLWJANBAxJ\n",
"DQBdtSEDtFGiNRUeJNbOIfDZnsryUlzJHGTXGFXnwsVy... | 2CODEFORCES |
112_A. Petya and Strings_37858 | Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corr... | a=input();b=input()
A=a.lower();B=b.lower()
if A==B:
print(0)
elif A>B:
print(1)
elif A<B:
print(-1)
| 3Python3 | {
"input": [
"aaaa\naaaA\n",
"abs\nAbz\n",
"abcdefg\nAbCdEfF\n",
"kigPrWNTOUNDBskAfefjhHYZNYdnfZWuXWzHiBxFQryBbAkPtenFwWvCSTYGpzOntUNzNUhxRWjKmicTwLwJAnbAxj\nkigpRWntOUNdBsKaFEFjhhYZnYDNfzWuXwZhibxFQRybbakPteNfwwvcStyGPzoNTunznuHXrWjKMIctWLWJANBAxJ\n",
"DQBdtSEDtFGiNRUeJNbOIfDZnsryUlzJHGTXGFXnwsVy... | 2CODEFORCES |
112_A. Petya and Strings_37859 | Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does not matter, that is an uppercase letter is considered equivalent to the corr... | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int result;
String str1 = in.nextLine();
String str2 = in.nextLine();
//str1 = str1.toLowerCase();
// str2 = str2.toLowerCase();
... | 4JAVA | {
"input": [
"aaaa\naaaA\n",
"abs\nAbz\n",
"abcdefg\nAbCdEfF\n",
"kigPrWNTOUNDBskAfefjhHYZNYdnfZWuXWzHiBxFQryBbAkPtenFwWvCSTYGpzOntUNzNUhxRWjKmicTwLwJAnbAxj\nkigpRWntOUNdBsKaFEFjhhYZnYDNfzWuXwZhibxFQRybbakPteNfwwvcStyGPzoNTunznuHXrWjKMIctWLWJANBAxJ\n",
"DQBdtSEDtFGiNRUeJNbOIfDZnsryUlzJHGTXGFXnwsVy... | 2CODEFORCES |
114_B. PFAST Inc._37860 | When little Petya grew up and entered the university, he started to take part in АСМ contests. Later he realized that he doesn't like how the АСМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff... | n, m = map(int, raw_input().split())
names = []
for i in xrange(n):
names.append(raw_input())
matr = [[0 for i in xrange(n)] for j in xrange(n)]
for i in xrange(m):
t1, t2 = raw_input().split()
for j in xrange(n):
if t1 == names[j]:
t1 = j
if t2 == names[j]:
t2 = j
... | 1Python2 | {
"input": [
"3 0\nPasha\nLesha\nVanya\n",
"3 1\nPetya\nVasya\nMasha\nPetya Vasya\n",
"7 6\nAlena\nOlya\nVanya\nBrus\nJohn\nAlice\nMariana\nAlena John\nAlena Alice\nOlya John\nOlya Alice\nVanya John\nVanya Alice\n",
"7 6\nj\nZ\nPZNeTyY\nm\na\nUj\nsuaaSiKcK\nUj PZNeTyY\na j\nPZNeTyY Z\nPZNeTyY j\nm PZN... | 2CODEFORCES |
114_B. PFAST Inc._37861 | When little Petya grew up and entered the university, he started to take part in АСМ contests. Later he realized that he doesn't like how the АСМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff... | #include <bits/stdc++.h>
using namespace std;
long long int MOD = (1e9) + 7;
inline void fastIO() {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
int main() {
fastIO();
int n, k, ans = 0;
cin >> n >> k;
map<pair<string, string>, int> has;
vector<string> fin(n);
vector<string> input(n);
for (int i = 0; i... | 2C++ | {
"input": [
"3 0\nPasha\nLesha\nVanya\n",
"3 1\nPetya\nVasya\nMasha\nPetya Vasya\n",
"7 6\nAlena\nOlya\nVanya\nBrus\nJohn\nAlice\nMariana\nAlena John\nAlena Alice\nOlya John\nOlya Alice\nVanya John\nVanya Alice\n",
"7 6\nj\nZ\nPZNeTyY\nm\na\nUj\nsuaaSiKcK\nUj PZNeTyY\na j\nPZNeTyY Z\nPZNeTyY j\nm PZN... | 2CODEFORCES |
114_B. PFAST Inc._37862 | When little Petya grew up and entered the university, he started to take part in АСМ contests. Later he realized that he doesn't like how the АСМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff... | '''input
7 12
Pasha
Lesha
Vanya
Taras
Nikita
Sergey
Andrey
Pasha Taras
Pasha Nikita
Pasha Andrey
Pasha Sergey
Lesha Taras
Lesha Nikita
Lesha Andrey
Lesha Sergey
Vanya Taras
Vanya Nikita
Vanya Andrey
Vanya Sergey
'''
from sys import stdin, stdout
from collections import deque
import sys
from copy import deepcopy
import ... | 3Python3 | {
"input": [
"3 0\nPasha\nLesha\nVanya\n",
"3 1\nPetya\nVasya\nMasha\nPetya Vasya\n",
"7 6\nAlena\nOlya\nVanya\nBrus\nJohn\nAlice\nMariana\nAlena John\nAlena Alice\nOlya John\nOlya Alice\nVanya John\nVanya Alice\n",
"7 6\nj\nZ\nPZNeTyY\nm\na\nUj\nsuaaSiKcK\nUj PZNeTyY\na j\nPZNeTyY Z\nPZNeTyY j\nm PZN... | 2CODEFORCES |
114_B. PFAST Inc._37863 | When little Petya grew up and entered the university, he started to take part in АСМ contests. Later he realized that he doesn't like how the АСМ contests are organised: the team could only have three members (and he couldn't take all his friends to the competitions and distribute the tasks between the team members eff... |
import java.io.*;
import java.util.*;
import java.math.*;
public class Main
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer tokenizer=null;
public static void main(String[] args) throws IOException
{
new Main().execute();
}
void debug(Object...os)
{
System.out... | 4JAVA | {
"input": [
"3 0\nPasha\nLesha\nVanya\n",
"3 1\nPetya\nVasya\nMasha\nPetya Vasya\n",
"7 6\nAlena\nOlya\nVanya\nBrus\nJohn\nAlice\nMariana\nAlena John\nAlena Alice\nOlya John\nOlya Alice\nVanya John\nVanya Alice\n",
"7 6\nj\nZ\nPZNeTyY\nm\na\nUj\nsuaaSiKcK\nUj PZNeTyY\na j\nPZNeTyY Z\nPZNeTyY j\nm PZN... | 2CODEFORCES |
1189_E. Count Pairs_37864 | You are given a prime number p, n integers a_1, a_2, …, a_n, and an integer k.
Find the number of pairs of indexes (i, j) (1 ≤ i < j ≤ n) for which (a_i + a_j)(a_i^2 + a_j^2) ≡ k mod p.
Input
The first line contains integers n, p, k (2 ≤ n ≤ 3 ⋅ 10^5, 2 ≤ p ≤ 10^9, 0 ≤ k ≤ p-1). p is guaranteed to be prime.
The se... | "Template made by : https://codeforces.com/profile/c1729 , github repo : https://github.com/cheran-senthil/PyRival"
from __future__ import division, print_function
import bisect
import math
import itertools
import sys
from atexit import register
if sys.version_info[0] < 3:
from io import BytesIO as stream
else:
... | 1Python2 | {
"input": [
"6 7 2\n1 2 3 4 5 6\n",
"3 3 0\n0 1 2\n",
"3 3 0\n0 2 1\n",
"2 2 1\n1 0\n",
"7 7 3\n4 0 5 3 1 2 6\n",
"2 2 0\n1 0\n",
"3 3 1\n0 2 1\n",
"3 3 2\n0 1 2\n",
"5 5 3\n3 0 4 1 2\n",
"2 37 5\n30 10\n",
"3 6 2\n0 1 2\n",
"2 37 4\n30 10\n",
"6 7 7\n1 2 3 4 5 6\n... | 2CODEFORCES |
1189_E. Count Pairs_37865 | You are given a prime number p, n integers a_1, a_2, …, a_n, and an integer k.
Find the number of pairs of indexes (i, j) (1 ≤ i < j ≤ n) for which (a_i + a_j)(a_i^2 + a_j^2) ≡ k mod p.
Input
The first line contains integers n, p, k (2 ≤ n ≤ 3 ⋅ 10^5, 2 ≤ p ≤ 10^9, 0 ≤ k ≤ p-1). p is guaranteed to be prime.
The se... | #include <bits/stdc++.h>
using namespace std;
vector<long long int> v;
map<long long int, long long int> m1;
set<long long int> st;
long long int fep(long long int x, long long int y, long long int mod) {
long long int res = 1;
while (y > 0) {
if (y & 1) res = (res * x) % mod;
y = y >> 1;
x = (x * x) % ... | 2C++ | {
"input": [
"6 7 2\n1 2 3 4 5 6\n",
"3 3 0\n0 1 2\n",
"3 3 0\n0 2 1\n",
"2 2 1\n1 0\n",
"7 7 3\n4 0 5 3 1 2 6\n",
"2 2 0\n1 0\n",
"3 3 1\n0 2 1\n",
"3 3 2\n0 1 2\n",
"5 5 3\n3 0 4 1 2\n",
"2 37 5\n30 10\n",
"3 6 2\n0 1 2\n",
"2 37 4\n30 10\n",
"6 7 7\n1 2 3 4 5 6\n... | 2CODEFORCES |
1189_E. Count Pairs_37866 | You are given a prime number p, n integers a_1, a_2, …, a_n, and an integer k.
Find the number of pairs of indexes (i, j) (1 ≤ i < j ≤ n) for which (a_i + a_j)(a_i^2 + a_j^2) ≡ k mod p.
Input
The first line contains integers n, p, k (2 ≤ n ≤ 3 ⋅ 10^5, 2 ≤ p ≤ 10^9, 0 ≤ k ≤ p-1). p is guaranteed to be prime.
The se... | from collections import Counter
n, p, k = map(int, input().split())
arr = [ (x ** 4 - k * x) % p for x in list(map(int, input().split())) ]
print( sum([ (x * (x - 1)) // 2 for x in Counter(arr).values() ]) )
| 3Python3 | {
"input": [
"6 7 2\n1 2 3 4 5 6\n",
"3 3 0\n0 1 2\n",
"3 3 0\n0 2 1\n",
"2 2 1\n1 0\n",
"7 7 3\n4 0 5 3 1 2 6\n",
"2 2 0\n1 0\n",
"3 3 1\n0 2 1\n",
"3 3 2\n0 1 2\n",
"5 5 3\n3 0 4 1 2\n",
"2 37 5\n30 10\n",
"3 6 2\n0 1 2\n",
"2 37 4\n30 10\n",
"6 7 7\n1 2 3 4 5 6\n... | 2CODEFORCES |
1189_E. Count Pairs_37867 | You are given a prime number p, n integers a_1, a_2, …, a_n, and an integer k.
Find the number of pairs of indexes (i, j) (1 ≤ i < j ≤ n) for which (a_i + a_j)(a_i^2 + a_j^2) ≡ k mod p.
Input
The first line contains integers n, p, k (2 ≤ n ≤ 3 ⋅ 10^5, 2 ≤ p ≤ 10^9, 0 ≤ k ≤ p-1). p is guaranteed to be prime.
The se... | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import java.util.Map.Entry;
public class zz{
static long[]memo;
static int[]occ;
static long mod=(long)(1e9)+7;
static long dp(int i) {
if(i<0... | 4JAVA | {
"input": [
"6 7 2\n1 2 3 4 5 6\n",
"3 3 0\n0 1 2\n",
"3 3 0\n0 2 1\n",
"2 2 1\n1 0\n",
"7 7 3\n4 0 5 3 1 2 6\n",
"2 2 0\n1 0\n",
"3 3 1\n0 2 1\n",
"3 3 2\n0 1 2\n",
"5 5 3\n3 0 4 1 2\n",
"2 37 5\n30 10\n",
"3 6 2\n0 1 2\n",
"2 37 4\n30 10\n",
"6 7 7\n1 2 3 4 5 6\n... | 2CODEFORCES |
1208_F. Bits And Pieces_37868 | You are given an array a of n integers.
You need to find the maximum value of a_{i} | ( a_{j} \& a_{k} ) over all triplets (i,j,k) such that i < j < k.
Here \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND), and | denotes the [bitwise OR operation](https://en.wikipedia.org/wi... | #include <bits/stdc++.h>
using namespace std;
const int maxn = 2e6 + 5;
int n;
int a[maxn];
int f[maxn];
int read() {
int x;
scanf("%d", &x);
return x;
}
int lowbit(int x) { return x & -x; }
int insert(int x, int y) {
if (f[x | y] > 1) return 0;
f[x | y]++;
for (int nx = x, ny = 0; nx; nx ^= lowbit(nx)) {
... | 2C++ | {
"input": [
"3\n2 4 6\n",
"4\n2 8 4 7\n",
"71\n25 25 91 91 61 57 99 25 93 89 99 29 31 25 29 89 93 89 91 27 95 95 25 57 63 97 89 93 27 31 61 89 99 59 93 95 29 31 59 99 89 25 25 29 59 89 31 27 63 57 61 89 59 95 91 89 95 59 29 31 31 57 31 93 29 25 63 57 91 91 93\n",
"3\n2 0 0\n",
"3\n0 0 1\n",
"... | 2CODEFORCES |
1208_F. Bits And Pieces_37869 | You are given an array a of n integers.
You need to find the maximum value of a_{i} | ( a_{j} \& a_{k} ) over all triplets (i,j,k) such that i < j < k.
Here \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation#AND), and | denotes the [bitwise OR operation](https://en.wikipedia.org/wi... | import java.io.*; import java.util.*;
public class CF1208F{
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next... | 4JAVA | {
"input": [
"3\n2 4 6\n",
"4\n2 8 4 7\n",
"71\n25 25 91 91 61 57 99 25 93 89 99 29 31 25 29 89 93 89 91 27 95 95 25 57 63 97 89 93 27 31 61 89 99 59 93 95 29 31 59 99 89 25 25 29 59 89 31 27 63 57 61 89 59 95 91 89 95 59 29 31 31 57 31 93 29 25 63 57 91 91 93\n",
"3\n2 0 0\n",
"3\n0 0 1\n",
"... | 2CODEFORCES |
1227_E. Arson In Berland Forest_37870 | The Berland Forest can be represented as an infinite cell plane. Every cell contains a tree. That is, contained before the recent events.
A destructive fire raged through the Forest, and several trees were damaged by it. Precisely speaking, you have a n × m rectangle map which represents the damaged part of the Forest... | #include <bits/stdc++.h>
using namespace std;
template <typename T>
bool MinPlace(T &a, const T &b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T>
bool MaxPlace(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int dr[8] = {0, -1, -1, -1, 0, 1... | 2C++ | {
"input": [
"3 6\nXXXXXX\nXXXXXX\nXXXXXX\n",
"10 10\n.XXXXXX...\n.XXXXXX...\n.XXXXXX...\n.XXXXXX...\n.XXXXXXXX.\n...XXXXXX.\n...XXXXXX.\n...XXXXXX.\n...XXXXXX.\n..........\n",
"4 5\nX....\n..XXX\n..XXX\n..XXX\n",
"1 1\nX\n",
"17 17\n.................\n.....XXXXXXXXX...\n.....XXXXXXXXXXX.\n.....XX... | 2CODEFORCES |
1227_E. Arson In Berland Forest_37871 | The Berland Forest can be represented as an infinite cell plane. Every cell contains a tree. That is, contained before the recent events.
A destructive fire raged through the Forest, and several trees were damaged by it. Precisely speaking, you have a n × m rectangle map which represents the damaged part of the Forest... | import java.util.*;
import java.io.*;
public class Main {
public static void main(String args[]) {new Main().run();}
FastReader in = new FastReader();
PrintWriter out = new PrintWriter(System.out);
void run(){
work();
out.flush();
}
long mod=1000000007;
long inf=Long.MAX_VALUE;
long gcd(long a,long b) {
... | 4JAVA | {
"input": [
"3 6\nXXXXXX\nXXXXXX\nXXXXXX\n",
"10 10\n.XXXXXX...\n.XXXXXX...\n.XXXXXX...\n.XXXXXX...\n.XXXXXXXX.\n...XXXXXX.\n...XXXXXX.\n...XXXXXX.\n...XXXXXX.\n..........\n",
"4 5\nX....\n..XXX\n..XXX\n..XXX\n",
"1 1\nX\n",
"17 17\n.................\n.....XXXXXXXXX...\n.....XXXXXXXXXXX.\n.....XX... | 2CODEFORCES |
126_B. Password_37872 | Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string s, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the t... | from __future__ import print_function # for PyPy2
from collections import Counter, OrderedDict
from itertools import permutations as perm
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
import math
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = la... | 1Python2 | {
"input": [
"abcdabc\n",
"fixprefixsuffix\n",
"aaabaabaaaaab\n",
"abcabcabcabcabc\n",
"kwuaizneqxfflhmyruotjlkqksinoanvkyvqptkkntnpjdyzicceelgooajdgpkneuhyvhdtmasiglplajxolxovlhkwuaizneqx\n",
"nfbdzgdlbjhrlvfryyjbvtsmzacxglcvukmyexdgpuiwvqbnfbdzgdlbjhrlvfryyjbtuomcwbwvlhefnfbdzgdlbjhrlvfryyjb... | 2CODEFORCES |
126_B. Password_37873 | Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string s, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the t... | #include <bits/stdc++.h>
using namespace std;
string s;
void comp_z(vector<long> &z) {
long n = z.size();
z[0] = n;
long L = -1, R = -1;
for (int i = 1; i < n; i++) {
if (R < i) {
L = R = i;
while (R < n && s[R] == s[R - L]) R++;
z[i] = R - L;
R--;
} else {
long k = i - L;
... | 2C++ | {
"input": [
"abcdabc\n",
"fixprefixsuffix\n",
"aaabaabaaaaab\n",
"abcabcabcabcabc\n",
"kwuaizneqxfflhmyruotjlkqksinoanvkyvqptkkntnpjdyzicceelgooajdgpkneuhyvhdtmasiglplajxolxovlhkwuaizneqx\n",
"nfbdzgdlbjhrlvfryyjbvtsmzacxglcvukmyexdgpuiwvqbnfbdzgdlbjhrlvfryyjbtuomcwbwvlhefnfbdzgdlbjhrlvfryyjb... | 2CODEFORCES |
126_B. Password_37874 | Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string s, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the t... | from fractions import Fraction
import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools im... | 3Python3 | {
"input": [
"abcdabc\n",
"fixprefixsuffix\n",
"aaabaabaaaaab\n",
"abcabcabcabcabc\n",
"kwuaizneqxfflhmyruotjlkqksinoanvkyvqptkkntnpjdyzicceelgooajdgpkneuhyvhdtmasiglplajxolxovlhkwuaizneqx\n",
"nfbdzgdlbjhrlvfryyjbvtsmzacxglcvukmyexdgpuiwvqbnfbdzgdlbjhrlvfryyjbtuomcwbwvlhefnfbdzgdlbjhrlvfryyjb... | 2CODEFORCES |
126_B. Password_37875 | Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them.
A little later they found a string s, carved on a rock below the temple's gates. Asterix supposed that that's the password that opens the t... |
import java.util.Arrays;
import java.util.Scanner;
public class B126 {
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
String s = in.nextLine();
int pos[]=new int[s.length()+1];
int flg[]=new int[s.length()+1];
int ind=0,l... | 4JAVA | {
"input": [
"abcdabc\n",
"fixprefixsuffix\n",
"aaabaabaaaaab\n",
"abcabcabcabcabc\n",
"kwuaizneqxfflhmyruotjlkqksinoanvkyvqptkkntnpjdyzicceelgooajdgpkneuhyvhdtmasiglplajxolxovlhkwuaizneqx\n",
"nfbdzgdlbjhrlvfryyjbvtsmzacxglcvukmyexdgpuiwvqbnfbdzgdlbjhrlvfryyjbtuomcwbwvlhefnfbdzgdlbjhrlvfryyjb... | 2CODEFORCES |
1292_A. NEKO's Maze Game_37876 | [3R2 as DJ Mashiro - Happiness Breeze](https://open.spotify.com/track/2qGqK8GRS65Wlf20qUBEak)
[Ice - DJ Mashiro is dead or alive](https://soundcloud.com/iceloki/dj-mashiro-is-dead-or-alive)
NEKO#ΦωΦ has just got a new maze game on her PC!
The game's main puzzle is a maze, in the forms of a 2 × n rectangle grid. NEKO... | import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')
n,q = map(... | 1Python2 | {
"input": [
"5 5\n2 3\n1 4\n2 4\n2 3\n1 4\n",
"73034 53\n2 21523\n1 21522\n2 21523\n2 21521\n2 37146\n2 21521\n2 21521\n2 21521\n1 37145\n2 37146\n1 54737\n2 66924\n2 21521\n2 28767\n2 21521\n2 21521\n2 21521\n1 28766\n2 28767\n2 54736\n2 54736\n2 31558\n2 37144\n2 41201\n1 60566\n2 15970\n2 37144\n2 25868\n... | 2CODEFORCES |
1292_A. NEKO's Maze Game_37877 | [3R2 as DJ Mashiro - Happiness Breeze](https://open.spotify.com/track/2qGqK8GRS65Wlf20qUBEak)
[Ice - DJ Mashiro is dead or alive](https://soundcloud.com/iceloki/dj-mashiro-is-dead-or-alive)
NEKO#ΦωΦ has just got a new maze game on her PC!
The game's main puzzle is a maze, in the forms of a 2 × n rectangle grid. NEKO... | #include <bits/stdc++.h>
using namespace std;
bool op[3][100002];
int t;
bool check(int c) {
if (!op[1][c] && (!op[2][c] || !op[2][c - 1] || !op[2][c + 1])) {
return false;
} else if (!op[2][c] && (!op[1][c] || !op[1][c - 1] || !op[1][c + 1])) {
return false;
}
return true;
}
int main() {
memset(op, t... | 2C++ | {
"input": [
"5 5\n2 3\n1 4\n2 4\n2 3\n1 4\n",
"73034 53\n2 21523\n1 21522\n2 21523\n2 21521\n2 37146\n2 21521\n2 21521\n2 21521\n1 37145\n2 37146\n1 54737\n2 66924\n2 21521\n2 28767\n2 21521\n2 21521\n2 21521\n1 28766\n2 28767\n2 54736\n2 54736\n2 31558\n2 37144\n2 41201\n1 60566\n2 15970\n2 37144\n2 25868\n... | 2CODEFORCES |
1292_A. NEKO's Maze Game_37878 | [3R2 as DJ Mashiro - Happiness Breeze](https://open.spotify.com/track/2qGqK8GRS65Wlf20qUBEak)
[Ice - DJ Mashiro is dead or alive](https://soundcloud.com/iceloki/dj-mashiro-is-dead-or-alive)
NEKO#ΦωΦ has just got a new maze game on her PC!
The game's main puzzle is a maze, in the forms of a 2 × n rectangle grid. NEKO... | import sys
input = sys.stdin.readline
hell=1000000007
def meowmeow321():
n,q=map(int,input().split())
cnt=0
mark1 = [0]*(n+5)
mark2 = [0]*(n+5)
for i in range(q):
r,c = map(int,input().split())
if r==1:
if mark1[c]:
cnt-=mark2[c]
cnt-=mark... | 3Python3 | {
"input": [
"5 5\n2 3\n1 4\n2 4\n2 3\n1 4\n",
"73034 53\n2 21523\n1 21522\n2 21523\n2 21521\n2 37146\n2 21521\n2 21521\n2 21521\n1 37145\n2 37146\n1 54737\n2 66924\n2 21521\n2 28767\n2 21521\n2 21521\n2 21521\n1 28766\n2 28767\n2 54736\n2 54736\n2 31558\n2 37144\n2 41201\n1 60566\n2 15970\n2 37144\n2 25868\n... | 2CODEFORCES |
1292_A. NEKO's Maze Game_37879 | [3R2 as DJ Mashiro - Happiness Breeze](https://open.spotify.com/track/2qGqK8GRS65Wlf20qUBEak)
[Ice - DJ Mashiro is dead or alive](https://soundcloud.com/iceloki/dj-mashiro-is-dead-or-alive)
NEKO#ΦωΦ has just got a new maze game on her PC!
The game's main puzzle is a maze, in the forms of a 2 × n rectangle grid. NEKO... | // coded by Krishna Sundar //
import java.lang.*;
import java.io.*;
import java.util.*;
public class Main {
boolean bound(int x, int y, int R, int C) {
return x>=0 && x<R && y>=0 && y<C;
}
public void solve(Read input, Write output) throws Exception {
int length = input.readInt();
... | 4JAVA | {
"input": [
"5 5\n2 3\n1 4\n2 4\n2 3\n1 4\n",
"73034 53\n2 21523\n1 21522\n2 21523\n2 21521\n2 37146\n2 21521\n2 21521\n2 21521\n1 37145\n2 37146\n1 54737\n2 66924\n2 21521\n2 28767\n2 21521\n2 21521\n2 21521\n1 28766\n2 28767\n2 54736\n2 54736\n2 31558\n2 37144\n2 41201\n1 60566\n2 15970\n2 37144\n2 25868\n... | 2CODEFORCES |
1312_B. Bogosort_37880 | You are given an array a_1, a_2, ... , a_n. Array is good if for each pair of indexes i < j the condition j - a_j ≠ i - a_i holds. Can you shuffle this array so that it becomes good? To shuffle an array means to reorder its elements arbitrarily (leaving the initial order is also an option).
For example, if a = [1, 1, ... | def solve(ns):
ns.sort(reverse=True)
'''
n = len(ns)
for i in xrange(n):
for j in xrange(i + 1, n):
assert j - ns[j] != i - ns[i]
'''
return ns
from random import randint
'''
for i in xrange(100):
ns = [randint(1, 100) for i in xrange(100)]
solve(ns)
print 'ok'
'''
... | 1Python2 | {
"input": [
"3\n1\n7\n4\n1 1 3 5\n6\n3 2 1 5 6 4\n",
"1\n3\n4 2 1\n",
"3\n1\n7\n4\n1 1 3 5\n6\n3 2 1 5 6 4\n",
"1\n9\n2 4 3 5 3 1 2 3 69\n",
"1\n8\n1 2 3 4 5 6 7 8\n",
"1\n3\n6 2 1\n",
"3\n1\n7\n4\n0 1 3 5\n6\n3 2 1 5 6 4\n",
"1\n9\n2 4 3 5 3 2 2 3 69\n",
"1\n8\n1 2 2 4 5 6 7 8\n"... | 2CODEFORCES |
1312_B. Bogosort_37881 | You are given an array a_1, a_2, ... , a_n. Array is good if for each pair of indexes i < j the condition j - a_j ≠ i - a_i holds. Can you shuffle this array so that it becomes good? To shuffle an array means to reorder its elements arbitrarily (leaving the initial order is also an option).
For example, if a = [1, 1, ... | #include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
vector<long long int> initializeDiffArray(vector<long long int>& A);
void update(vector<long long int>& D, long long int l, long long int r,
long long int x);
void getArray(vector<long long int>& A, vector<long long int>& D);
long... | 2C++ | {
"input": [
"3\n1\n7\n4\n1 1 3 5\n6\n3 2 1 5 6 4\n",
"1\n3\n4 2 1\n",
"3\n1\n7\n4\n1 1 3 5\n6\n3 2 1 5 6 4\n",
"1\n9\n2 4 3 5 3 1 2 3 69\n",
"1\n8\n1 2 3 4 5 6 7 8\n",
"1\n3\n6 2 1\n",
"3\n1\n7\n4\n0 1 3 5\n6\n3 2 1 5 6 4\n",
"1\n9\n2 4 3 5 3 2 2 3 69\n",
"1\n8\n1 2 2 4 5 6 7 8\n"... | 2CODEFORCES |
1312_B. Bogosort_37882 | You are given an array a_1, a_2, ... , a_n. Array is good if for each pair of indexes i < j the condition j - a_j ≠ i - a_i holds. Can you shuffle this array so that it becomes good? To shuffle an array means to reorder its elements arbitrarily (leaving the initial order is also an option).
For example, if a = [1, 1, ... | N=int(input())
for i in range(N):
b=int(input())
a=list(map(int, input().split()[:b]))
print(*sorted(a)[::-1]) | 3Python3 | {
"input": [
"3\n1\n7\n4\n1 1 3 5\n6\n3 2 1 5 6 4\n",
"1\n3\n4 2 1\n",
"3\n1\n7\n4\n1 1 3 5\n6\n3 2 1 5 6 4\n",
"1\n9\n2 4 3 5 3 1 2 3 69\n",
"1\n8\n1 2 3 4 5 6 7 8\n",
"1\n3\n6 2 1\n",
"3\n1\n7\n4\n0 1 3 5\n6\n3 2 1 5 6 4\n",
"1\n9\n2 4 3 5 3 2 2 3 69\n",
"1\n8\n1 2 2 4 5 6 7 8\n"... | 2CODEFORCES |
1312_B. Bogosort_37883 | You are given an array a_1, a_2, ... , a_n. Array is good if for each pair of indexes i < j the condition j - a_j ≠ i - a_i holds. Can you shuffle this array so that it becomes good? To shuffle an array means to reorder its elements arbitrarily (leaving the initial order is also an option).
For example, if a = [1, 1, ... |
import java.util.*;
public class main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t=s.nextInt();
while(t>0) {
int n= s.nextInt();
Integer ans[]= new Integer[n];
for(int i=0;i<n;i++) {
ans[i]=s.nextInt();
}
// Integer ans1[]= new Integer[5];
Arrays.s... | 4JAVA | {
"input": [
"3\n1\n7\n4\n1 1 3 5\n6\n3 2 1 5 6 4\n",
"1\n3\n4 2 1\n",
"3\n1\n7\n4\n1 1 3 5\n6\n3 2 1 5 6 4\n",
"1\n9\n2 4 3 5 3 1 2 3 69\n",
"1\n8\n1 2 3 4 5 6 7 8\n",
"1\n3\n6 2 1\n",
"3\n1\n7\n4\n0 1 3 5\n6\n3 2 1 5 6 4\n",
"1\n9\n2 4 3 5 3 2 2 3 69\n",
"1\n8\n1 2 2 4 5 6 7 8\n"... | 2CODEFORCES |
1334_F. Strange Function_37884 | Let's denote the following function f. This function takes an array a of length n and returns an array. Initially the result is an empty array. For each integer i from 1 to n we add element a_i to the end of the resulting array if it is greater than all previous elements (more formally, if a_i > max_{1 ≤ j < i}a_j). So... | #include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 7;
long long t[4 * N];
long long mod[4 * N];
const long long Inf = 1e18;
void update(int v, long long x) {
t[v] += x;
mod[v] += x;
}
void push(int v) {
if (mod[v]) {
update(2 * v + 1, mod[v]);
update(2 * v + 2, mod[v]);
mod[v] = 0;
}
... | 2C++ | {
"input": [
"11\n4 1 3 3 7 8 7 9 10 7 11\n3 5 0 -2 5 3 6 7 8 2 4\n3\n3 7 10\n",
"6\n2 1 5 3 6 5\n3 -9 0 16 22 -14\n4\n2 3 5 6\n",
"4\n4 1 1 4\n-10 5 4 1\n1\n4\n",
"2\n2 2\n-10 6\n1\n1\n",
"4\n4 1 1 4\n-10 5 5 1\n1\n4\n",
"4\n4 1 1 4\n-10 5 6 1\n1\n4\n",
"1\n1\n-10\n1\n1\n",
"4\n4 1 1 ... | 2CODEFORCES |
1334_F. Strange Function_37885 | Let's denote the following function f. This function takes an array a of length n and returns an array. Initially the result is an empty array. For each integer i from 1 to n we add element a_i to the end of the resulting array if it is greater than all previous elements (more formally, if a_i > max_{1 ≤ j < i}a_j). So... | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.io.OutputStreamWriter;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Closeable;
import java.io.Writer;
impo... | 4JAVA | {
"input": [
"11\n4 1 3 3 7 8 7 9 10 7 11\n3 5 0 -2 5 3 6 7 8 2 4\n3\n3 7 10\n",
"6\n2 1 5 3 6 5\n3 -9 0 16 22 -14\n4\n2 3 5 6\n",
"4\n4 1 1 4\n-10 5 4 1\n1\n4\n",
"2\n2 2\n-10 6\n1\n1\n",
"4\n4 1 1 4\n-10 5 5 1\n1\n4\n",
"4\n4 1 1 4\n-10 5 6 1\n1\n4\n",
"1\n1\n-10\n1\n1\n",
"4\n4 1 1 ... | 2CODEFORCES |
1355_A. Sequence with Digits_37886 | Let's define the following recurrence: $$$a_{n+1} = a_{n} + minDigit(a_{n}) ⋅ maxDigit(a_{n}).$$$
Here minDigit(x) and maxDigit(x) are the minimal and maximal digits in the decimal representation of x without leading zeroes. For examples refer to notes.
Your task is calculate a_{K} for given a_{1} and K.
Input
The ... | import sys
def maxdig(x):
return max([int(y) for y in str(x)])
def mindig(x):
return min([int(y) for y in str(x)])
t = int(sys.stdin.readline())
for t in range(t):
a1,k = list(map(int, sys.stdin.readline().strip().split(' ')))
j = 1
aj = a1
while j < k and "0" not in str(aj):
aj = aj + maxdig(aj) * mindig(aj... | 1Python2 | {
"input": [
"8\n1 4\n487 1\n487 2\n487 3\n487 4\n487 5\n487 6\n487 7\n",
"1\n1 333\n",
"1\n1 589\n",
"8\n1 4\n487 1\n487 2\n487 3\n487 4\n487 5\n487 6\n487 1\n",
"1\n3 98\n",
"1\n3 7\n",
"1\n4 7\n",
"1\n2 2\n",
"8\n1 4\n487 1\n487 2\n487 3\n487 4\n487 5\n937 6\n487 1\n",
"1\n1... | 2CODEFORCES |
1355_A. Sequence with Digits_37887 | Let's define the following recurrence: $$$a_{n+1} = a_{n} + minDigit(a_{n}) ⋅ maxDigit(a_{n}).$$$
Here minDigit(x) and maxDigit(x) are the minimal and maximal digits in the decimal representation of x without leading zeroes. For examples refer to notes.
Your task is calculate a_{K} for given a_{1} and K.
Input
The ... | #include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f;
const long long maxn = 201110;
const long long M = 1e9 + 7;
long long n, m, k, ok;
long long mii(long long x) {
long long res = 9;
while (x) {
res = min(res, x % 10);
x /= 10;
}
return res;
}
long long mxx(long long x) {
l... | 2C++ | {
"input": [
"8\n1 4\n487 1\n487 2\n487 3\n487 4\n487 5\n487 6\n487 7\n",
"1\n1 333\n",
"1\n1 589\n",
"8\n1 4\n487 1\n487 2\n487 3\n487 4\n487 5\n487 6\n487 1\n",
"1\n3 98\n",
"1\n3 7\n",
"1\n4 7\n",
"1\n2 2\n",
"8\n1 4\n487 1\n487 2\n487 3\n487 4\n487 5\n937 6\n487 1\n",
"1\n1... | 2CODEFORCES |
1355_A. Sequence with Digits_37888 | Let's define the following recurrence: $$$a_{n+1} = a_{n} + minDigit(a_{n}) ⋅ maxDigit(a_{n}).$$$
Here minDigit(x) and maxDigit(x) are the minimal and maximal digits in the decimal representation of x without leading zeroes. For examples refer to notes.
Your task is calculate a_{K} for given a_{1} and K.
Input
The ... | ans = []
for h in range(int(input())):
a, k = map(int, input().strip().split())
temp = a
a = str(a)
for i in range(k-1):
maxi = int(max(a)); mini = int(min(a))
a = str(temp + maxi*mini)
if '0' in a:
break
temp = int(a)
ans.append(a)
print('\n'.join(a... | 3Python3 | {
"input": [
"8\n1 4\n487 1\n487 2\n487 3\n487 4\n487 5\n487 6\n487 7\n",
"1\n1 333\n",
"1\n1 589\n",
"8\n1 4\n487 1\n487 2\n487 3\n487 4\n487 5\n487 6\n487 1\n",
"1\n3 98\n",
"1\n3 7\n",
"1\n4 7\n",
"1\n2 2\n",
"8\n1 4\n487 1\n487 2\n487 3\n487 4\n487 5\n937 6\n487 1\n",
"1\n1... | 2CODEFORCES |
1355_A. Sequence with Digits_37889 | Let's define the following recurrence: $$$a_{n+1} = a_{n} + minDigit(a_{n}) ⋅ maxDigit(a_{n}).$$$
Here minDigit(x) and maxDigit(x) are the minimal and maximal digits in the decimal representation of x without leading zeroes. For examples refer to notes.
Your task is calculate a_{K} for given a_{1} and K.
Input
The ... | //package CodeForces;
import java.util.Scanner;
public class SequenceWithDigits {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s=new Scanner(System.in);
int t=s.nextInt();
while(t>0)
{
long n=s.nextLong();
long k=s.nextLong();
long num=n;
while(k-1>0)... | 4JAVA | {
"input": [
"8\n1 4\n487 1\n487 2\n487 3\n487 4\n487 5\n487 6\n487 7\n",
"1\n1 333\n",
"1\n1 589\n",
"8\n1 4\n487 1\n487 2\n487 3\n487 4\n487 5\n487 6\n487 1\n",
"1\n3 98\n",
"1\n3 7\n",
"1\n4 7\n",
"1\n2 2\n",
"8\n1 4\n487 1\n487 2\n487 3\n487 4\n487 5\n937 6\n487 1\n",
"1\n1... | 2CODEFORCES |
1374_F. Cyclic Shifts Sorting_37890 | You are given an array a consisting of n integers.
In one move, you can choose some index i (1 ≤ i ≤ n - 2) and shift the segment [a_i, a_{i + 1}, a_{i + 2}] cyclically to the right (i.e. replace the segment [a_i, a_{i + 1}, a_{i + 2}] with [a_{i + 2}, a_i, a_{i + 1}]).
Your task is to sort the initial array by no m... |
# Author : raj1307 - Raj Singh
# Date : 01.07.2020
from __future__ import division, print_function
import os,sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
def ii(): return int(input())... | 1Python2 | {
"input": [
"5\n5\n1 2 3 4 5\n5\n5 4 3 2 1\n8\n8 4 5 2 3 6 7 3\n7\n5 2 1 6 4 7 3\n6\n1 2 3 3 6 4\n",
"1\n100\n86 366 161 188 28 209 450 355 100 241 153 5 249 238 333 368 423 173 284 416 451 311 114 258 150 113 239 441 454 422 418 20 409 212 63 205 287 68 70 152 349 345 86 335 473 481 143 171 439 445 12 281 4... | 2CODEFORCES |
1374_F. Cyclic Shifts Sorting_37891 | You are given an array a consisting of n integers.
In one move, you can choose some index i (1 ≤ i ≤ n - 2) and shift the segment [a_i, a_{i + 1}, a_{i + 2}] cyclically to the right (i.e. replace the segment [a_i, a_{i + 1}, a_{i + 2}] with [a_{i + 2}, a_i, a_{i + 1}]).
Your task is to sort the initial array by no m... | #include <bits/stdc++.h>
using namespace std;
int v[505];
vector<int> rasp;
void mov(int poz) {
rasp.push_back(poz + 1);
swap(v[poz], v[poz + 1]);
swap(v[poz], v[poz + 2]);
}
int main() {
int t, i1, n, i, j;
scanf("%d", &t);
for (i1 = 1; i1 <= t; i1++) {
scanf("%d", &n);
for (i = 0; i < n; i++) scan... | 2C++ | {
"input": [
"5\n5\n1 2 3 4 5\n5\n5 4 3 2 1\n8\n8 4 5 2 3 6 7 3\n7\n5 2 1 6 4 7 3\n6\n1 2 3 3 6 4\n",
"1\n100\n86 366 161 188 28 209 450 355 100 241 153 5 249 238 333 368 423 173 284 416 451 311 114 258 150 113 239 441 454 422 418 20 409 212 63 205 287 68 70 152 349 345 86 335 473 481 143 171 439 445 12 281 4... | 2CODEFORCES |
1374_F. Cyclic Shifts Sorting_37892 | You are given an array a consisting of n integers.
In one move, you can choose some index i (1 ≤ i ≤ n - 2) and shift the segment [a_i, a_{i + 1}, a_{i + 2}] cyclically to the right (i.e. replace the segment [a_i, a_{i + 1}, a_{i + 2}] with [a_{i + 2}, a_i, a_{i + 1}]).
Your task is to sort the initial array by no m... |
def swap(i):
tmp = a[i+2]
a[i+2] = a[i+1]
a[i+1] = a[i]
a[i] = tmp
ans.append(i+1)
#print (*a)
tt = int(input())
for loop in range(tt):
n = int(input())
a = list(map(int,input().split()))
sa = 0.0001
lis = [sa] * 501
b1 = []
b2 = []
f2 = True
... | 3Python3 | {
"input": [
"5\n5\n1 2 3 4 5\n5\n5 4 3 2 1\n8\n8 4 5 2 3 6 7 3\n7\n5 2 1 6 4 7 3\n6\n1 2 3 3 6 4\n",
"1\n100\n86 366 161 188 28 209 450 355 100 241 153 5 249 238 333 368 423 173 284 416 451 311 114 258 150 113 239 441 454 422 418 20 409 212 63 205 287 68 70 152 349 345 86 335 473 481 143 171 439 445 12 281 4... | 2CODEFORCES |
1374_F. Cyclic Shifts Sorting_37893 | You are given an array a consisting of n integers.
In one move, you can choose some index i (1 ≤ i ≤ n - 2) and shift the segment [a_i, a_{i + 1}, a_{i + 2}] cyclically to the right (i.e. replace the segment [a_i, a_{i + 1}, a_{i + 2}] with [a_{i + 2}, a_i, a_{i + 1}]).
Your task is to sort the initial array by no m... | import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(System.out);
static int MOD = 1000000007;
public static void main(String[] args) throws IOException {
... | 4JAVA | {
"input": [
"5\n5\n1 2 3 4 5\n5\n5 4 3 2 1\n8\n8 4 5 2 3 6 7 3\n7\n5 2 1 6 4 7 3\n6\n1 2 3 3 6 4\n",
"1\n100\n86 366 161 188 28 209 450 355 100 241 153 5 249 238 333 368 423 173 284 416 451 311 114 258 150 113 239 441 454 422 418 20 409 212 63 205 287 68 70 152 349 345 86 335 473 481 143 171 439 445 12 281 4... | 2CODEFORCES |
1398_C. Good Subarrays_37894 | You are given an array a_1, a_2, ... , a_n consisting of integers from 0 to 9. A subarray a_l, a_{l+1}, a_{l+2}, ... , a_{r-1}, a_r is good if the sum of elements of this subarray is equal to the length of this subarray (∑_{i=l}^{r} a_i = r - l + 1).
For example, if a = [1, 2, 0], then there are 3 good subarrays: a_{1... |
from __future__ import division
import sys
input = sys.stdin.readline
import math
from math import sqrt, floor, ceil
from collections import Counter, defaultdict
from copy import deepcopy as dc
# from statistics import median, mean
############ ---- Input Functions ---- ############
def inp():
return(int(input()... | 1Python2 | {
"input": [
"3\n3\n120\n5\n11011\n6\n600005\n",
"11\n1\n0\n1\n1\n1\n2\n1\n3\n1\n4\n1\n5\n1\n6\n1\n7\n1\n8\n1\n9\n26\n11140000000090000000002111\n",
"11\n1\n0\n1\n1\n1\n2\n1\n3\n1\n0\n1\n5\n1\n6\n1\n7\n1\n8\n1\n9\n26\n11140000000090000000002111\n",
"3\n3\n217\n5\n11011\n6\n600005\n",
"3\n3\n363\n5... | 2CODEFORCES |
1398_C. Good Subarrays_37895 | You are given an array a_1, a_2, ... , a_n consisting of integers from 0 to 9. A subarray a_l, a_{l+1}, a_{l+2}, ... , a_{r-1}, a_r is good if the sum of elements of this subarray is equal to the length of this subarray (∑_{i=l}^{r} a_i = r - l + 1).
For example, if a = [1, 2, 0], then there are 3 good subarrays: a_{1... | #include <bits/stdc++.h>
using namespace std;
void solve() {
long long n;
cin >> n;
;
string str;
cin >> str;
;
map<long long, long long> mp;
mp[0] = 1;
long long sum = 0;
long long ans = 0;
for (long long i = 0; i < str.size(); i++) {
sum += (str[i] - '0') - 1;
ans += mp[sum];
mp[sum]... | 2C++ | {
"input": [
"3\n3\n120\n5\n11011\n6\n600005\n",
"11\n1\n0\n1\n1\n1\n2\n1\n3\n1\n4\n1\n5\n1\n6\n1\n7\n1\n8\n1\n9\n26\n11140000000090000000002111\n",
"11\n1\n0\n1\n1\n1\n2\n1\n3\n1\n0\n1\n5\n1\n6\n1\n7\n1\n8\n1\n9\n26\n11140000000090000000002111\n",
"3\n3\n217\n5\n11011\n6\n600005\n",
"3\n3\n363\n5... | 2CODEFORCES |
1398_C. Good Subarrays_37896 | You are given an array a_1, a_2, ... , a_n consisting of integers from 0 to 9. A subarray a_l, a_{l+1}, a_{l+2}, ... , a_{r-1}, a_r is good if the sum of elements of this subarray is equal to the length of this subarray (∑_{i=l}^{r} a_i = r - l + 1).
For example, if a = [1, 2, 0], then there are 3 good subarrays: a_{1... | from collections import defaultdict as dd
# d=dd(lambda:0)
from sys import stdin
stdin.readline
def mp(): return list(map(int, stdin.readline().strip().split()))
def it():return int(stdin.readline().strip())
for _ in range(it()):
n=it()
l=input()
v=[]
for i in l:
v.append(int(i))
# for i in range(n):
# v[i]-... | 3Python3 | {
"input": [
"3\n3\n120\n5\n11011\n6\n600005\n",
"11\n1\n0\n1\n1\n1\n2\n1\n3\n1\n4\n1\n5\n1\n6\n1\n7\n1\n8\n1\n9\n26\n11140000000090000000002111\n",
"11\n1\n0\n1\n1\n1\n2\n1\n3\n1\n0\n1\n5\n1\n6\n1\n7\n1\n8\n1\n9\n26\n11140000000090000000002111\n",
"3\n3\n217\n5\n11011\n6\n600005\n",
"3\n3\n363\n5... | 2CODEFORCES |
1398_C. Good Subarrays_37897 | You are given an array a_1, a_2, ... , a_n consisting of integers from 0 to 9. A subarray a_l, a_{l+1}, a_{l+2}, ... , a_{r-1}, a_r is good if the sum of elements of this subarray is equal to the length of this subarray (∑_{i=l}^{r} a_i = r - l + 1).
For example, if a = [1, 2, 0], then there are 3 good subarrays: a_{1... | import java.util.*;
import java.io.*;
public class B{
public static void main(String[] args)
{
FastScanner fs = new FastScanner();
PrintWriter out = new PrintWriter(System.out);
int t = fs.nextInt();
for(int tt=0;tt<t;tt++)
{
int n = fs.nextInt();
char[] arr = fs.next().toCharArray();
int[] sum = ... | 4JAVA | {
"input": [
"3\n3\n120\n5\n11011\n6\n600005\n",
"11\n1\n0\n1\n1\n1\n2\n1\n3\n1\n4\n1\n5\n1\n6\n1\n7\n1\n8\n1\n9\n26\n11140000000090000000002111\n",
"11\n1\n0\n1\n1\n1\n2\n1\n3\n1\n0\n1\n5\n1\n6\n1\n7\n1\n8\n1\n9\n26\n11140000000090000000002111\n",
"3\n3\n217\n5\n11011\n6\n600005\n",
"3\n3\n363\n5... | 2CODEFORCES |
1421_D. Hexagons_37898 | Lindsey Buckingham told Stevie Nicks ["Go your own way"](https://www.youtube.com/watch?v=6ul-cZyuYq4). Nicks is now sad and wants to go away as quickly as possible, but she lives in a 2D hexagonal world.
Consider a hexagonal tiling of the plane as on the picture below.
<image>
Nicks wishes to go from the cell marked... | from __future__ import division, print_function
''' Hey stalker :) '''
INF = 10 ** 50
TEST_CASES = True
from collections import defaultdict, deque, Counter
from functools import reduce
from bisect import bisect_left
def main():
x,y = get_list()
costs = get_list()
C = [(1,1),
(0,1),
(-1,... | 1Python2 | {
"input": [
"2\n-3 1\n1 3 5 7 9 11\n1000000000 1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n",
"1\n-1000000000 -1000000000\n10000 20000 30000 40000 50000 60000\n",
"1\n0 0\n1 2 3 4 5 6\n",
"1\n-1000000000 -1000000000\n10000 20000 30000 40000 81069 60000\n",
"1\n-... | 2CODEFORCES |
1421_D. Hexagons_37899 | Lindsey Buckingham told Stevie Nicks ["Go your own way"](https://www.youtube.com/watch?v=6ul-cZyuYq4). Nicks is now sad and wants to go away as quickly as possible, but she lives in a 2D hexagonal world.
Consider a hexagonal tiling of the plane as on the picture below.
<image>
Nicks wishes to go from the cell marked... | #include <bits/stdc++.h>
using namespace std;
long long c[9];
long long solve(long long x, long long y) {
if (x == 0 && y == 0) return 0;
long long r = abs(x);
x /= r;
y /= r;
long long ans;
if (x == 1 && y == 1)
ans = c[1];
else if (x == 1 && y == -1)
ans = c[8];
else if (x == -1 && y == 1)
... | 2C++ | {
"input": [
"2\n-3 1\n1 3 5 7 9 11\n1000000000 1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n",
"1\n-1000000000 -1000000000\n10000 20000 30000 40000 50000 60000\n",
"1\n0 0\n1 2 3 4 5 6\n",
"1\n-1000000000 -1000000000\n10000 20000 30000 40000 81069 60000\n",
"1\n-... | 2CODEFORCES |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.