output_description
stringlengths
15
956
submission_id
stringlengths
10
10
status
stringclasses
3 values
problem_id
stringlengths
6
6
input_description
stringlengths
9
2.55k
attempt
stringlengths
1
13.7k
problem_description
stringlengths
7
5.24k
samples
stringlengths
2
2.72k
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s128041875
Runtime Error
p03473
Input is given from Standard Input in the following format: M
M = map(int, input().split()) X = 24 + (24 - M) print(X)
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s049711380
Runtime Error
p03473
Input is given from Standard Input in the following format: M
import math def isPrime(num): if num < 2: return False else: rootNum = math.floor(math.sqrt(num)) for i in range(2,rootNum+1): if num % i == 0: return False return True def solve(): lst = [] count = int(input()) for i in range(count): ans = 0 l, r = map(int, input().split()) t = l while k <= r if isPrime(k) and isPrime((k+1)/2): ans += 1 k += 2 lst.append(str(ans)) print('\n'.join(lst)) solve()
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s170022009
Runtime Error
p03473
Input is given from Standard Input in the following format: M
date = input() date = list(date) date[3] = "8" date = "".join(date) print(date)
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s422792523
Runtime Error
p03473
Input is given from Standard Input in the following format: M
fn main() { let m: isize = read(); let ans = 24 + 24 - m; println!("{}", ans); } // 以下関数 use std::io::*; use std::str::FromStr; pub fn read<T: FromStr>() -> T { let stdin = stdin(); let stdin = stdin.lock(); let token: String = stdin .bytes() .map(|c| c.expect("failed to read char") as char) .skip_while(|c| c.is_whitespace()) .take_while(|c| !c.is_whitespace()) .collect(); token.parse().ok().expect("failed to parse token") } pub const MOD: u64 = 10e9 as u64 + 7; pub fn is_prime(n: i32) -> bool { if n < 2 { return false; } else if n == 2 { return true; } let mut i = 2; while i * i < n { if n % i == 0 { return false; } else { i += 1; continue; } } true } pub fn lcm(mut n: i32, mut m: i32) -> i32 { n = if n > m { m } else { n }; m = if n > m { n } else { m }; let mut i = n; while i % m != 0 { i += n; } i }
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s927069096
Runtime Error
p03473
Input is given from Standard Input in the following format: M
M = int(input()) print(48-M)
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s504239218
Runtime Error
p03473
Input is given from Standard Input in the following format: M
h = int(input()) print(24 + (24 - h)
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
If we have x hours until New Year at M o'clock on 30th, December, print x. * * *
s443257637
Runtime Error
p03473
Input is given from Standard Input in the following format: M
//include //------------------------------------------ #include <vector> #include <list> #include <map> #include <set> #include <deque> #include <queue> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <ctime> #include <iterator> #include <unordered_map> #include <unordered_set> #include <tuple> using namespace std; typedef long long ll; //input //------------------------------------------ #define re(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__); template<typename T> void MACRO_VAR_Scan(T& t) { cin >> t; } template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { cin >> first; MACRO_VAR_Scan(rest...); } #define rv_row(type, n, ...)vector<type> __VA_ARGS__;MACRO_VEC_ROW_Init(n, __VA_ARGS__); for(int i=0; i<n; ++i){MACRO_VEC_ROW_Scan(i, __VA_ARGS__);} template<typename T> void MACRO_VEC_ROW_Init(int n, T& t) { t.resize(n); } template<typename First, typename...Rest>void MACRO_VEC_ROW_Init(int n, First& first, Rest&...rest) { first.resize(n); MACRO_VEC_ROW_Init(n, rest...); } template<typename T> void MACRO_VEC_ROW_Scan(int p, T& t) { cin >> t[p]; } template<typename First, typename...Rest>void MACRO_VEC_ROW_Scan(int p, First& first, Rest&...rest) { cin >> first[p]; MACRO_VEC_ROW_Scan(p, rest...); } #define rv(type, c, n) vector<type> c(n);for(auto& i:c)cin>>i; #define rMAT(type, c, n, m) vector<vector<type>> c(n, vector<type>(m));for(auto& r:c)for(auto& i:r)cin>>i; void _main(); signed main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } // output //------------------------------------------ #define pr(x) cout<<x<<endl; #define prv(v){for(const auto& xxx : v){cout << xxx << " ";}cout << "\n";} #define sankou(x,a,b) cout<<(x?a:b)<<endl; #define hihumi(x,a,y,b,c) cout<<(x?a:y?b:c)<<endl; #define YESNO(x) cout<<(x?"YES":"NO")<<endl; #define yesno(x) cout<<(x?"Yes":"No")<<endl; #define ck(x) cerr << #x << " = " << (x) << endl; #define ckv(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";} //conversion //------------------------------------------ inline ll toInt(std::string s) { ll v; std::istringstream sin(s);sin >> v;return v; } template<class T> inline string toString(T x) { ostringstream sout;sout << x;return sout.str(); } //math //------------------------------------------ template<class T> inline T sqr(T x) { return x*x; } template<typename A, typename B>inline void chmin(A &a, B b) { if (a>b)a = b; } template<typename A, typename B>inline void chmax(A &a, B b) { if (a<b)a = b; } ll qp(ll a, ll b) { ll ans = 1ll;do { if (b & 1)ans = 1ll * ans*a;a = 1ll * a*a; } while (b >>= 1);return ans; } ll qpmod(ll a, ll b, ll mo) { ll ans = 1ll;do { if (b & 1)ans = 1ll * ans*a%mo;a = 1ll * a*a%mo; } while (b >>= 1);return ans; } ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } inline bool valid(int x, int h) { return 0 <= x && x < h; } //container util //------------------------------------------ #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EXIST(s,e) ((s).find(e)!=(s).end()) #define EXISTST(s,c) (((s).find(c)) != std::string::npos) #define SORT(c) sort((c).begin(),(c).end()) #define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end()) #define POSL(x,val) (lower_bound(x.begin(),x.end(),val)-x.begin()) #define POSU(x,val) (upper_bound(x.begin(),x.end(),val)-x.begin()) #define FI first #define SE second #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) #define MEMINF(a) memset(a,0x3f,sizeof(a))//1e9<1061109567<INTMAX/2 //repetition //------------------------------------------ #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define rep(i,n) FOR(i,0,n) #define FORll(i,a,b) for(long long i=(a);i<(b);++i) #define repll(i,n) FORll(i,0,n) #define rrep(i,a,b) for(int i=(int)(b)-1;i>=a;i--) #define rrepll(i,a,b) for(long long i=(b)-1ll;i>=a;i--) #define fo(x,c) for(auto &x : c) #define repeat(i,a,b) for(int i=(a);i<=(b);++i) //typedef //------------------------------------------ typedef vector<int> vi; typedef vector<vi> vii; typedef vector<long long> vll; typedef vector<string> vs; typedef pair<int, int> P; typedef pair<ll, ll> Pll; typedef vector<pair<int, int>> vpii; //constant //------------------------------------------ const double EPS = 1e-8; const double PI = acos(-1.0); const int INF = (int)(1e9) + 7; const ll MOD = (ll)(1e9) + 7; const ll MOD2 = (ll)(1e18) + 9; #define ADD(a, b) a = (a + ll(b)) % MOD #define MUL(a, b) a = (a * ll(b)) % MOD const ll INF2 = (ll)(1e18); const ll INTMAX = (0x7FFFFFFFL); const ll LLMAX = (0x7FFFFFFFFFFFFFFFL); const int N4 = (int)1e4 + 10; const int N5 = (int)1e5 + 10; int dx[8] = { 1, 0, -1, 0 , 1, -1, -1, 1 }; int dy[8] = { 0, 1, 0, -1, -1, -1, 1, 1 }; //------------------------------------------ ll ans, cnt, ret, cur, f; void _main() { re(int, n); pr(48 - n); }
Statement How many hours do we have until New Year at M o'clock (24-hour notation) on 30th, December?
[{"input": "21", "output": "27\n \n\nWe have 27 hours until New Year at 21 o'clock on 30th, December.\n\n* * *"}, {"input": "12", "output": "36"}]
Among the sets of problems with the total score of N, find a set in which the highest score of a problem is minimum, then print the indices of the problems in the set in any order, one per line. If there exists more than one such set, any of them will be accepted. * * *
s834075229
Runtime Error
p03920
The input is given from Standard Input in the following format: N
cv # -*- coding: utf-8 -*- import sys import math import os import itertools import string import heapq import _collections from collections import Counter from collections import defaultdict from functools import lru_cache import bisect import re import queue class Scanner: @staticmethod def int(): return int(sys.stdin.readline().rstrip()) @staticmethod def string(): return sys.stdin.readline().rstrip() @staticmethod def map_int(): return [int(x) for x in Scanner.string().split()] @staticmethod def string_list(n): return [input() for i in range(n)] @staticmethod def int_list_list(n): return [Scanner.map_int() for i in range(n)] @staticmethod def int_cols_list(n): return [int(input()) for i in range(n)] class Math: @staticmethod def gcd(a, b): if b == 0: return a return Math.gcd(b, a % b) @staticmethod def lcm(a, b): return (a * b) // Math.gcd(a, b) @staticmethod def divisor(n): res = [] i = 1 for i in range(1, int(n**0.5) + 1): if n % i == 0: res.append(i) if i != n // i: res.append(n // i) return res @staticmethod def round_up(a, b): return -(-a // b) @staticmethod def is_prime(n): if n < 2: return False if n == 2: return True if n % 2 == 0: return False d = int(n**0.5) + 1 for i in range(3, d + 1, 2): if n % i == 0: return False return True class PriorityQueue: def __init__(self, l=[]): self.q = l heapq.heapify(self.q) return def push(self, n): heapq.heappush(self.q, n) return def pop(self): return heapq.heappop(self.q) MOD = int(1e09) + 7 INF = int(1e15) def factorization(n): S = {} temp = n for i in range(2, int(-(-(n**0.5) // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i S[i] = cnt if temp != 1: S[temp] = 1 if S == []: S[n] = 1 return S def main(): # sys.stdin = open("sample.txt") N = Scanner.int() ok = N + 1 ng = 0 while abs(ok - ng) > 1: m = (ok + ng) // 2 if m * (m + 1) // 2 >= N: ok = m else: ng = m for i in reversed(range(1, ok + 1)): if N >= i: print(i) N -= i if __name__ == "__main__": main()
Statement The problem set at _CODE FESTIVAL 20XX Finals_ consists of N problems. The score allocated to the i-th (1≦i≦N) problem is i points. Takahashi, a contestant, is trying to score exactly N points. For that, he is deciding which problems to solve. As problems with higher scores are harder, he wants to minimize the highest score of a problem among the ones solved by him. Determine the set of problems that should be solved.
[{"input": "4", "output": "1\n 3\n \n\nSolving only the 4-th problem will also result in the total score of 4 points,\nbut solving the 1-st and 3-rd problems will lower the highest score of a\nsolved problem.\n\n* * *"}, {"input": "7", "output": "1\n 2\n 4\n \n\nThe set \\\\{3,4\\\\} will also be accepted.\n\n* * *"}, {"input": "1", "output": "1"}]
Among the sets of problems with the total score of N, find a set in which the highest score of a problem is minimum, then print the indices of the problems in the set in any order, one per line. If there exists more than one such set, any of them will be accepted. * * *
s136514064
Accepted
p03920
The input is given from Standard Input in the following format: N
ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(map(int, input().split())) def main(): n = ii() s = 0 anslist = [] for i in range(1, 10000000): s += i if s > n: s -= i break anslist.append(i) dif = n - s ans = list(reversed(anslist)) for i in range(dif): ans[i] += 1 for i in ans: print(i) main()
Statement The problem set at _CODE FESTIVAL 20XX Finals_ consists of N problems. The score allocated to the i-th (1≦i≦N) problem is i points. Takahashi, a contestant, is trying to score exactly N points. For that, he is deciding which problems to solve. As problems with higher scores are harder, he wants to minimize the highest score of a problem among the ones solved by him. Determine the set of problems that should be solved.
[{"input": "4", "output": "1\n 3\n \n\nSolving only the 4-th problem will also result in the total score of 4 points,\nbut solving the 1-st and 3-rd problems will lower the highest score of a\nsolved problem.\n\n* * *"}, {"input": "7", "output": "1\n 2\n 4\n \n\nThe set \\\\{3,4\\\\} will also be accepted.\n\n* * *"}, {"input": "1", "output": "1"}]
Among the sets of problems with the total score of N, find a set in which the highest score of a problem is minimum, then print the indices of the problems in the set in any order, one per line. If there exists more than one such set, any of them will be accepted. * * *
s964840208
Wrong Answer
p03920
The input is given from Standard Input in the following format: N
print(2)
Statement The problem set at _CODE FESTIVAL 20XX Finals_ consists of N problems. The score allocated to the i-th (1≦i≦N) problem is i points. Takahashi, a contestant, is trying to score exactly N points. For that, he is deciding which problems to solve. As problems with higher scores are harder, he wants to minimize the highest score of a problem among the ones solved by him. Determine the set of problems that should be solved.
[{"input": "4", "output": "1\n 3\n \n\nSolving only the 4-th problem will also result in the total score of 4 points,\nbut solving the 1-st and 3-rd problems will lower the highest score of a\nsolved problem.\n\n* * *"}, {"input": "7", "output": "1\n 2\n 4\n \n\nThe set \\\\{3,4\\\\} will also be accepted.\n\n* * *"}, {"input": "1", "output": "1"}]
Among the sets of problems with the total score of N, find a set in which the highest score of a problem is minimum, then print the indices of the problems in the set in any order, one per line. If there exists more than one such set, any of them will be accepted. * * *
s312552574
Runtime Error
p03920
The input is given from Standard Input in the following format: N
n = int(input()) k = int((n * 2) ** 0.5) while k * (k + 1) // 2 < n: k += 1 l = [range(1, k + 1)] if k * (k + 1) // 2 - n: l.remove(k * (k + 1) // 2 - n) for i in l: print(l)
Statement The problem set at _CODE FESTIVAL 20XX Finals_ consists of N problems. The score allocated to the i-th (1≦i≦N) problem is i points. Takahashi, a contestant, is trying to score exactly N points. For that, he is deciding which problems to solve. As problems with higher scores are harder, he wants to minimize the highest score of a problem among the ones solved by him. Determine the set of problems that should be solved.
[{"input": "4", "output": "1\n 3\n \n\nSolving only the 4-th problem will also result in the total score of 4 points,\nbut solving the 1-st and 3-rd problems will lower the highest score of a\nsolved problem.\n\n* * *"}, {"input": "7", "output": "1\n 2\n 4\n \n\nThe set \\\\{3,4\\\\} will also be accepted.\n\n* * *"}, {"input": "1", "output": "1"}]
Print the number of strings satisfying the condition, modulo (10^9+7). * * *
s838781385
Accepted
p02632
Input is given from Standard Input in the following format: K S
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..) import sys MOD = 10**9 + 7 def main(K, S): N = len(S) fu = FactorialUtils(N + K) ans = Mint() for i in range(K + 1): tmp = Mint(1) tmp *= fu.multichoose(N, K - i) tmp *= pow(25, K - i, MOD) tmp *= pow(26, i, MOD) ans += tmp print(ans) class FactorialUtils: def __init__(self, n): self.fac = [1] * (n + 1) self.ifac = [1] * (n + 1) for i in range(2, n + 1): self.fac[i] = self.fac[i - 1] * i % MOD self.ifac[n] = pow(self.fac[n], MOD - 2, MOD) for i in range(n, 1, -1): self.ifac[i - 1] = self.ifac[i] * i % MOD def choose(self, n, r): if r < 0 or r > n: return 0 return (self.fac[n] * self.ifac[n - r] % MOD) * self.ifac[r] % MOD def multichoose(self, u, k): return (self.fac[u + k - 1] * self.ifac[u - 1] % MOD) * self.ifac[k] % MOD class Mint: def __init__(self, value=0): self.value = value % MOD if self.value < 0: self.value += MOD @staticmethod def get_value(x): return x.value if isinstance(x, Mint) else x def inverse(self): a, b = self.value, MOD u, v = 1, 0 while b: t = a // b b, a = a - t * b, b v, u = u - t * v, v if u < 0: u += MOD return u def __repr__(self): return str(self.value) def __eq__(self, other): return self.value == other.value def __neg__(self): return Mint(-self.value) def __hash__(self): return hash(self.value) def __bool__(self): return self.value != 0 def __iadd__(self, other): self.value = (self.value + Mint.get_value(other)) % MOD return self def __add__(self, other): new_obj = Mint(self.value) new_obj += other return new_obj __radd__ = __add__ def __isub__(self, other): self.value = (self.value - Mint.get_value(other)) % MOD if self.value < 0: self.value += MOD return self def __sub__(self, other): new_obj = Mint(self.value) new_obj -= other return new_obj def __rsub__(self, other): new_obj = Mint(Mint.get_value(other)) new_obj -= self return new_obj def __imul__(self, other): self.value = self.value * Mint.get_value(other) % MOD return self def __mul__(self, other): new_obj = Mint(self.value) new_obj *= other return new_obj __rmul__ = __mul__ def __ifloordiv__(self, other): other = other if isinstance(other, Mint) else Mint(other) self *= other.inverse() return self def __floordiv__(self, other): new_obj = Mint(self.value) new_obj //= other return new_obj def __rfloordiv__(self, other): new_obj = Mint(Mint.get_value(other)) new_obj //= self return new_obj if __name__ == "__main__": input = sys.stdin.readline K = int(input()) S = input().rstrip() main(K, S)
Statement How many strings can be obtained by applying the following operation on a string S exactly K times: "choose one lowercase English letter and insert it somewhere"? The answer can be enormous, so print it modulo (10^9+7).
[{"input": "5\n oof", "output": "575111451\n \n\nFor example, we can obtain `proofend`, `moonwolf`, and `onionpuf`, while we\ncannot obtain `oofsix`, `oofelevennn`, `voxafolt`, or `fooooooo`.\n\n* * *"}, {"input": "37564\n whydidyoudesertme", "output": "318008117"}]
Print the number of strings satisfying the condition, modulo (10^9+7). * * *
s285657288
Accepted
p02632
Input is given from Standard Input in the following format: K S
MOD = 10**9+7 k = int(input()) s = input() n = len(s) U = n+k fact = [0]*(U+1) fact[0] = 1 for i in range(1, U+1): fact[i] = fact[i-1]*i % MOD invfact = [0]*(U+1) invfact[U] = pow(fact[U], MOD-2, MOD) for i in reversed(range(U)): invfact[i] = invfact[i+1]*(i+1) % MOD def nCr(n, r): if r < 0 or n < r: return 0 return fact[n]*invfact[r]*invfact[n-r] ans = 0 for x in range(k+1): ans += pow(26, x, MOD)*nCr(n+k-x-1, n-1)*pow(25, k-x, MOD) ans %= MOD print(ans)
Statement How many strings can be obtained by applying the following operation on a string S exactly K times: "choose one lowercase English letter and insert it somewhere"? The answer can be enormous, so print it modulo (10^9+7).
[{"input": "5\n oof", "output": "575111451\n \n\nFor example, we can obtain `proofend`, `moonwolf`, and `onionpuf`, while we\ncannot obtain `oofsix`, `oofelevennn`, `voxafolt`, or `fooooooo`.\n\n* * *"}, {"input": "37564\n whydidyoudesertme", "output": "318008117"}]
Print the number of strings satisfying the condition, modulo (10^9+7). * * *
s540033189
Accepted
p02632
Input is given from Standard Input in the following format: K S
mod = 1000000007 fact = [] fact_inv = [] pow_ = [] pow25_ = [] pow26_ = [] def pow_ini(nn): global pow_ pow_.append(nn) for j in range(62): nxt = pow_[j] * pow_[j] nxt %= mod pow_.append(nxt) return def pow1(k): ansk = 1 for ntmp in range(62): if((k >> ntmp) % 2 == 1): ansk *= pow_[ntmp] ansk %= mod return ansk def fact_ini(n): global fact global fact_inv global pow_ fact = [0] * (n+1) fact_inv = [0] * (n+1) fact[0] = 1 for i in range(1, n + 1, 1): fact_tmp = fact[i - 1] * i fact_tmp %= mod fact[i] = fact_tmp pow_ini(fact[n]) fact_inv[n] = pow1(mod - 2) for i in range(n - 1, -1, -1): fact_inv[i] = fact_inv[i + 1] * (i + 1) fact_inv[i] %= mod return def nCm(n, m): ans = fact[n] * fact_inv[m] ans %= mod ans *= fact_inv[n - m] ans %= mod return ans; fact_ini(2200000) K = int(input()) S = input() N = len(S) ans = 0 ans25=[1] * (K+11) ans26=[1] * (K+11) for k in range(K+10): ans25[k+1] = ans25[k] * 25 ans26[k+1] = ans26[k] * 26 ans25[k+1] %= mod ans26[k+1] %= mod for k in range(0, K+1, 1): n = N + K - k anstmp = 1 anstmp *= ans26[k] anstmp %= mod anstmp *= nCm(n - 1, N - 1) anstmp %= mod anstmp *= ans25[n - N] anstmp %= mod ans += anstmp ans %= mod print(ans)
Statement How many strings can be obtained by applying the following operation on a string S exactly K times: "choose one lowercase English letter and insert it somewhere"? The answer can be enormous, so print it modulo (10^9+7).
[{"input": "5\n oof", "output": "575111451\n \n\nFor example, we can obtain `proofend`, `moonwolf`, and `onionpuf`, while we\ncannot obtain `oofsix`, `oofelevennn`, `voxafolt`, or `fooooooo`.\n\n* * *"}, {"input": "37564\n whydidyoudesertme", "output": "318008117"}]
Print the number of strings satisfying the condition, modulo (10^9+7). * * *
s514835148
Runtime Error
p02632
Input is given from Standard Input in the following format: K S
import sys kMod = 10**9 + 7 def read_int(): l = sys.stdin.readline().rstrip('\n').split(' ') return int(l[0]) def read_int_list(): l = sys.stdin.readline().rstrip('\n').split(' ') return [int(i) for i in l] K = read_int() S = sys.stdin.readline().rstrip('\n') memo = {} def cnt(n, rest): if n == 0: if rest > 0: return 0 else: return 1 key = (n, rest) if key in memo: return memo[key] ans = 0 ans += 25 * cnt(n-1, rest) ans += cnt(n-1, rest-1) ans %= kMod memo[key] = ans return ans print(cnt(K+len(S), len(S)))
Statement How many strings can be obtained by applying the following operation on a string S exactly K times: "choose one lowercase English letter and insert it somewhere"? The answer can be enormous, so print it modulo (10^9+7).
[{"input": "5\n oof", "output": "575111451\n \n\nFor example, we can obtain `proofend`, `moonwolf`, and `onionpuf`, while we\ncannot obtain `oofsix`, `oofelevennn`, `voxafolt`, or `fooooooo`.\n\n* * *"}, {"input": "37564\n whydidyoudesertme", "output": "318008117"}]
Print the number of strings satisfying the condition, modulo (10^9+7). * * *
s882301764
Accepted
p02632
Input is given from Standard Input in the following format: K S
#!/usr/bin/env python3 import sys MOD = 1000000007 # type: int def solve(K: int, S: str): """ >>> solve(1, 'a') 51 """ N = len(S) mf = ModFactorial(MOD, N + K + 1) ans = 0 for k in range(K + 1): ans = ( ans + mf.combination(k + N - 1, k) * pow(25, k, MOD) % MOD * pow(26, K - k, MOD) ) % MOD return ans # Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools def main(): def iterate_tokens(): for line in sys.stdin: for word in line.split(): yield word tokens = iterate_tokens() K = int(next(tokens)) # type: int S = next(tokens) # type: str print(solve(K, S)) def mod_range(mod, start, stop=None, step=1): if stop == None: stop = start start = 0 return map(lambda i: i % mod, range(start, stop, step)) def mod_inv(mod, n): """ >>> mod_inv(3, 2) 2 >>> mod_inv(1000000007, 2) 500000004 """ return pow(n, mod - 2, mod) def mod_permutation(mod, n, r): """ >>> mod_permutation(1000000007, 10, 2) 90 >>> mod_permutation(7, 10, 2) 6 """ m = 1 for i in mod_range(mod, n - r + 1, n + 1): m = (m * i) % mod return m def mod_factorial(mod, n): """ >>> mod_factorial(1000000007, 10) 3628800 >>> mod_factorial(7, 6) 6 """ return mod_permutation(mod, n, n) def mod_combination(mod, n, r): """ >>> mod_combination(1000000007, 10, 2) 45 >>> mod_combination(7, 10, 2) 3 """ return mod_permutation(mod, n, r) * mod_inv(mod, mod_factorial(mod, r)) % mod class ModFactorial: def __init__(self, mod, size=1): """ >>> ModFactorial(7, 7) Traceback (most recent call last): ... AssertionError """ assert mod > size self._mod = mod self._init_factorials(size) def _mod_range(self, start, stop=None, step=1): return mod_range(self._mod, start, stop, step) def _mod_inv(self, n): return mod_inv(self._mod, n) def _init_factorials(self, size): """ >>> mf1 = ModFactorial(1000000007) >>> mf2 = ModFactorial(1000000007, 10) >>> mf1.factorial(10) == mf2.factorial(10) True """ self._factorials = [1] * size n = 1 # リストの参照は遅いので減らす for i, m in enumerate(self._mod_range(1, size), 1): n = (n * m) % self._mod self._factorials[i] = n def _append_factorials(self, n): for m in map(lambda i: i % self._mod, range(len(self._factorials), n + 1)): self._factorials.append((self._factorials[-1] * m) % self._mod) def factorial(self, n): """ >>> ModFactorial(1000000007).factorial(10) 3628800 >>> ModFactorial(7).factorial(6) 6 >>> ModFactorial(7).factorial(7) Traceback (most recent call last): ... AssertionError """ assert n < self._mod if len(self._factorials) <= n: self._append_factorials(n) return self._factorials[n] def factorial_inv(self, n): """ >>> MOD = 1000000007 >>> mf = ModFactorial(MOD) >>> mf.factorial_inv(10) 283194722 >>> mf.factorial_inv(10) * mf.factorial(10) % MOD 1 >>> MOD = 7 >>> mf = ModFactorial(MOD) >>> mf.factorial_inv(6) 6 >>> mf.factorial_inv(6) * mf.factorial(6) % MOD 1 """ return self._mod_inv(self.factorial(n)) def permutation(self, n, r): """ >>> ModFactorial(1000000007).permutation(10, 2) 90 """ return self.factorial(n) * self.factorial_inv(n - r) % self._mod def combination(self, n, r): """ >>> ModFactorial(1000000007).combination(10, 2) 45 """ return self.permutation(n, r) * self.factorial_inv(r) % self._mod def test(): import doctest doctest.testmod() if __name__ == "__main__": # test() main()
Statement How many strings can be obtained by applying the following operation on a string S exactly K times: "choose one lowercase English letter and insert it somewhere"? The answer can be enormous, so print it modulo (10^9+7).
[{"input": "5\n oof", "output": "575111451\n \n\nFor example, we can obtain `proofend`, `moonwolf`, and `onionpuf`, while we\ncannot obtain `oofsix`, `oofelevennn`, `voxafolt`, or `fooooooo`.\n\n* * *"}, {"input": "37564\n whydidyoudesertme", "output": "318008117"}]
Print the number of strings satisfying the condition, modulo (10^9+7). * * *
s661085409
Accepted
p02632
Input is given from Standard Input in the following format: K S
k=int(input()) s=input() n=len(s) mod=pow(10,9)+7 # コンビネーション、さらに高速。あらかじめO(N)の計算をすることでのちの計算が早くなる def cmb(n,r,mod): if (r<0 or r>n): return 0 r=min(r,n-r) return g1[n]*g2[r]*g2[n-r]%mod g1=[1,1] g2=[1,1] inverse=[0,1] for i in range(2,n+k+1): g1.append((g1[-1]*i)%mod) inverse.append((-inverse[mod%i]*(mod//i))%mod) g2.append((g2[-1]*inverse[-1])%mod) f=[pow(25,i,mod)*cmb(i+n-1,n-1,mod) for i in range(k+1)] g=[0]*(k+1) g[0]=1 for ki in range(1,k+1): g[ki]=f[ki]+26*g[ki-1] g[ki]%=mod print(g[k])
Statement How many strings can be obtained by applying the following operation on a string S exactly K times: "choose one lowercase English letter and insert it somewhere"? The answer can be enormous, so print it modulo (10^9+7).
[{"input": "5\n oof", "output": "575111451\n \n\nFor example, we can obtain `proofend`, `moonwolf`, and `onionpuf`, while we\ncannot obtain `oofsix`, `oofelevennn`, `voxafolt`, or `fooooooo`.\n\n* * *"}, {"input": "37564\n whydidyoudesertme", "output": "318008117"}]
Print the number of strings satisfying the condition, modulo (10^9+7). * * *
s480284508
Wrong Answer
p02632
Input is given from Standard Input in the following format: K S
def main(): k = int(input()) s = input() n = 1 for i in range( len(s)-1, k+1): n = n * i if __name__ == '__main__': main()
Statement How many strings can be obtained by applying the following operation on a string S exactly K times: "choose one lowercase English letter and insert it somewhere"? The answer can be enormous, so print it modulo (10^9+7).
[{"input": "5\n oof", "output": "575111451\n \n\nFor example, we can obtain `proofend`, `moonwolf`, and `onionpuf`, while we\ncannot obtain `oofsix`, `oofelevennn`, `voxafolt`, or `fooooooo`.\n\n* * *"}, {"input": "37564\n whydidyoudesertme", "output": "318008117"}]
If it is impossible to have a non-decreasing sequence, print `-1`. If it is possible, print the minimum number of operations required to achieve it. * * *
s944009963
Runtime Error
p02798
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N B_1 B_2 ... B_N
N, K, S = map(int, input().split()) ans = [S] * K + [S - 1] * (N - K) for a in ans: print(a, end=" ") print()
Statement We have N cards numbered 1, 2, ..., N. Card i (1 \leq i \leq N) has an integer A_i written in red ink on one side and an integer B_i written in blue ink on the other side. Initially, these cards are arranged from left to right in the order from Card 1 to Card N, with the red numbers facing up. Determine whether it is possible to have a non-decreasing sequence facing up from left to right (that is, for each i (1 \leq i \leq N - 1), the integer facing up on the (i+1)-th card from the left is not less than the integer facing up on the i-th card from the left) by repeating the operation below. If the answer is yes, find the minimum number of operations required to achieve it. * Choose an integer i (1 \leq i \leq N - 1). Swap the i-th and (i+1)-th cards from the left, then flip these two cards.
[{"input": "3\n 3 4 3\n 3 2 3", "output": "1\n \n\nBy doing the operation once with i = 1, we have a sequence [2, 3, 3] facing\nup, which is non-decreasing.\n\n* * *"}, {"input": "2\n 2 1\n 1 2", "output": "-1\n \n\nAfter any number of operations, we have the sequence [2, 1] facing up, which\nis not non-decreasing.\n\n* * *"}, {"input": "4\n 1 2 3 4\n 5 6 7 8", "output": "0\n \n\nNo operation may be required.\n\n* * *"}, {"input": "5\n 28 15 22 43 31\n 20 22 43 33 32", "output": "-1\n \n\n* * *"}, {"input": "5\n 4 46 6 38 43\n 33 15 18 27 37", "output": "3"}]
If it is impossible to have a non-decreasing sequence, print `-1`. If it is possible, print the minimum number of operations required to achieve it. * * *
s316210894
Wrong Answer
p02798
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N B_1 B_2 ... B_N
print(1)
Statement We have N cards numbered 1, 2, ..., N. Card i (1 \leq i \leq N) has an integer A_i written in red ink on one side and an integer B_i written in blue ink on the other side. Initially, these cards are arranged from left to right in the order from Card 1 to Card N, with the red numbers facing up. Determine whether it is possible to have a non-decreasing sequence facing up from left to right (that is, for each i (1 \leq i \leq N - 1), the integer facing up on the (i+1)-th card from the left is not less than the integer facing up on the i-th card from the left) by repeating the operation below. If the answer is yes, find the minimum number of operations required to achieve it. * Choose an integer i (1 \leq i \leq N - 1). Swap the i-th and (i+1)-th cards from the left, then flip these two cards.
[{"input": "3\n 3 4 3\n 3 2 3", "output": "1\n \n\nBy doing the operation once with i = 1, we have a sequence [2, 3, 3] facing\nup, which is non-decreasing.\n\n* * *"}, {"input": "2\n 2 1\n 1 2", "output": "-1\n \n\nAfter any number of operations, we have the sequence [2, 1] facing up, which\nis not non-decreasing.\n\n* * *"}, {"input": "4\n 1 2 3 4\n 5 6 7 8", "output": "0\n \n\nNo operation may be required.\n\n* * *"}, {"input": "5\n 28 15 22 43 31\n 20 22 43 33 32", "output": "-1\n \n\n* * *"}, {"input": "5\n 4 46 6 38 43\n 33 15 18 27 37", "output": "3"}]
If it is impossible to have a non-decreasing sequence, print `-1`. If it is possible, print the minimum number of operations required to achieve it. * * *
s594495641
Accepted
p02798
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N B_1 B_2 ... B_N
import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import itertools N = int(readline()) A = list(map(int, readline().split())) B = list(map(int, readline().split())) class BinaryIndexedTree: def __init__(self, seq): self.size = len(seq) self.depth = self.size.bit_length() self.build(seq) def build(self, seq): data = seq size = self.size for i, x in enumerate(data): j = i + (i & (-i)) if j < size: data[j] += data[i] self.data = data def __repr__(self): return self.data.__repr__() def get_sum(self, i): data = self.data s = 0 while i: s += data[i] i -= i & -i return s def add(self, i, x): data = self.data size = self.size while i < size: data[i] += x i += i & -i def find_kth_element(self, k): data = self.data size = self.size x, sx = 0, 0 dx = 1 << (self.depth) for i in range(self.depth - 1, -1, -1): dx = 1 << i if x + dx >= size: continue y = x + dx sy = sx + data[y] if sy < k: x, sx = y, sy return x + 1 def Inversion(seq): # seqは、1,2,...,Nの順列 N = len(seq) bit = BinaryIndexedTree([0] * (N + 1)) inv = N * (N - 1) // 2 for x in seq: inv -= bit.get_sum(x) bit.add(x, 1) return inv INF = 10**9 answer = INF for I in itertools.combinations(range(N), (N + 1) // 2): J = [j for j in range(N) if j not in I] ODD = [(B[i] if i & 1 else A[i], i) for i in I] EV = [(A[i] if i & 1 else B[i], i) for i in J] ODD.sort() EV.sort() ind = [0] * N seq = [0] * N for i in range(0, N, 2): seq[i], ind[i] = ODD[i // 2] for i in range(1, N, 2): seq[i], ind[i] = EV[i // 2] if not all(x <= y for x, y in zip(seq, seq[1:])): continue ind = [x + 1 for x in ind] n = Inversion(ind) if answer > n: answer = n if answer == INF: answer = -1 print(answer)
Statement We have N cards numbered 1, 2, ..., N. Card i (1 \leq i \leq N) has an integer A_i written in red ink on one side and an integer B_i written in blue ink on the other side. Initially, these cards are arranged from left to right in the order from Card 1 to Card N, with the red numbers facing up. Determine whether it is possible to have a non-decreasing sequence facing up from left to right (that is, for each i (1 \leq i \leq N - 1), the integer facing up on the (i+1)-th card from the left is not less than the integer facing up on the i-th card from the left) by repeating the operation below. If the answer is yes, find the minimum number of operations required to achieve it. * Choose an integer i (1 \leq i \leq N - 1). Swap the i-th and (i+1)-th cards from the left, then flip these two cards.
[{"input": "3\n 3 4 3\n 3 2 3", "output": "1\n \n\nBy doing the operation once with i = 1, we have a sequence [2, 3, 3] facing\nup, which is non-decreasing.\n\n* * *"}, {"input": "2\n 2 1\n 1 2", "output": "-1\n \n\nAfter any number of operations, we have the sequence [2, 1] facing up, which\nis not non-decreasing.\n\n* * *"}, {"input": "4\n 1 2 3 4\n 5 6 7 8", "output": "0\n \n\nNo operation may be required.\n\n* * *"}, {"input": "5\n 28 15 22 43 31\n 20 22 43 33 32", "output": "-1\n \n\n* * *"}, {"input": "5\n 4 46 6 38 43\n 33 15 18 27 37", "output": "3"}]
If it is impossible to have a non-decreasing sequence, print `-1`. If it is possible, print the minimum number of operations required to achieve it. * * *
s473539529
Wrong Answer
p02798
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N B_1 B_2 ... B_N
import sys input = lambda: sys.stdin.readline().rstrip() sys.setrecursionlimit(max(1000, 10**9)) write = lambda x: sys.stdout.write(x + "\n") n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) nums = [None] * n # def groupby(l): # """l : list of tuple # tuple[0]で分割する # """ # if len(l)==0: # pass # else: # yield def pp(func): def wrapped(*args, **keys): print(args, keys) val = func(*args, **keys) print(val) return val return wrapped # @pp def sub(fr, to, bb): # frをtoのいずれかに対応付ける elist = [] olist = [] for ff, bbb in zip(fr, bb): if (ff + bbb) % 2: olist.append(ff) else: elist.append(ff) elist2 = [] olist2 = [] for item in to: if item % 2: olist2.append(item) else: elist2.append(item) if len(olist2) == len(olist) and len(elist2) == len(elist): olist.sort() elist.sort() return sum(abs(o1 - o2) for o1, o2 in zip(olist, olist2)) + sum( abs(e1 - e2) for e1, e2 in zip(elist, elist2) ) else: return None # if sum((ff-tt-bbb)%2 for ff,tt,bbb in zip(fr, to, bb)): # return None best = 10**9 for bit in range(1 << n): for i in range(n): val = b[i] if bit >> i & 1 else a[i] nums[i] = (val, i, bit >> i & 1) nums.sort() prev, fr, bb = nums[0] to = [0] fr = [fr] bb = [bb] valid = True ans = 0 for i in range(1, n): cv, cfr, cbb = nums[i] if prev != cv: res = sub(fr, to, bb) if res is None: valid = False break ans += res prev, fr, bb = cv, [cfr], [cbb] to = [i] else: fr.append(cfr) to.append(i) bb.append(cbb) else: res = sub(fr, to, bb) if res is None: valid = False else: ans += res if valid: best = min(best, ans) # print(nums, ans) if best == 10**9: print(-1) else: print(best // 2)
Statement We have N cards numbered 1, 2, ..., N. Card i (1 \leq i \leq N) has an integer A_i written in red ink on one side and an integer B_i written in blue ink on the other side. Initially, these cards are arranged from left to right in the order from Card 1 to Card N, with the red numbers facing up. Determine whether it is possible to have a non-decreasing sequence facing up from left to right (that is, for each i (1 \leq i \leq N - 1), the integer facing up on the (i+1)-th card from the left is not less than the integer facing up on the i-th card from the left) by repeating the operation below. If the answer is yes, find the minimum number of operations required to achieve it. * Choose an integer i (1 \leq i \leq N - 1). Swap the i-th and (i+1)-th cards from the left, then flip these two cards.
[{"input": "3\n 3 4 3\n 3 2 3", "output": "1\n \n\nBy doing the operation once with i = 1, we have a sequence [2, 3, 3] facing\nup, which is non-decreasing.\n\n* * *"}, {"input": "2\n 2 1\n 1 2", "output": "-1\n \n\nAfter any number of operations, we have the sequence [2, 1] facing up, which\nis not non-decreasing.\n\n* * *"}, {"input": "4\n 1 2 3 4\n 5 6 7 8", "output": "0\n \n\nNo operation may be required.\n\n* * *"}, {"input": "5\n 28 15 22 43 31\n 20 22 43 33 32", "output": "-1\n \n\n* * *"}, {"input": "5\n 4 46 6 38 43\n 33 15 18 27 37", "output": "3"}]
If it is impossible to have a non-decreasing sequence, print `-1`. If it is possible, print the minimum number of operations required to achieve it. * * *
s480954734
Wrong Answer
p02798
Input is given from Standard Input in the following format: N A_1 A_2 ... A_N B_1 B_2 ... B_N
N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) X = [(A[i], i) for i in range(N)] Y = [(B[i], i) for i in range(N)] def change(i, j): A[i], B[i], A[j], B[j] = B[j], A[j], B[i], A[i] def count_ones(num): num = (num & 0x55555555) + (num >> 1 & 0x55555555) num = (num & 0x33333333) + (num >> 2 & 0x33333333) num = (num & 0x0F0F0F0F) + (num >> 4 & 0x0F0F0F0F) num = (num & 0x00FF00FF) + (num >> 8 & 0x00FF00FF) num = (num & 0x0000FFFF) + (num >> 16 & 0x0000FFFF) return num ans = 0 for bi in range(1 << N): # bi<<i : iはBが表で終わるか if count_ones(bi) % 2 == 1: continue L = [((B[i], True, i) if bi << i else (A[i], False, i)) for i in range(N)] R = sorted(L) ans = 0 for i in range(N): Lval, Lbool, Li = L[i] Rval, Rbool, Ri = R[i] if Li != Ri: ans += 1 L[Li], L[Ri] = L[Ri], L[Li] if L == R: print(ans) print(-1)
Statement We have N cards numbered 1, 2, ..., N. Card i (1 \leq i \leq N) has an integer A_i written in red ink on one side and an integer B_i written in blue ink on the other side. Initially, these cards are arranged from left to right in the order from Card 1 to Card N, with the red numbers facing up. Determine whether it is possible to have a non-decreasing sequence facing up from left to right (that is, for each i (1 \leq i \leq N - 1), the integer facing up on the (i+1)-th card from the left is not less than the integer facing up on the i-th card from the left) by repeating the operation below. If the answer is yes, find the minimum number of operations required to achieve it. * Choose an integer i (1 \leq i \leq N - 1). Swap the i-th and (i+1)-th cards from the left, then flip these two cards.
[{"input": "3\n 3 4 3\n 3 2 3", "output": "1\n \n\nBy doing the operation once with i = 1, we have a sequence [2, 3, 3] facing\nup, which is non-decreasing.\n\n* * *"}, {"input": "2\n 2 1\n 1 2", "output": "-1\n \n\nAfter any number of operations, we have the sequence [2, 1] facing up, which\nis not non-decreasing.\n\n* * *"}, {"input": "4\n 1 2 3 4\n 5 6 7 8", "output": "0\n \n\nNo operation may be required.\n\n* * *"}, {"input": "5\n 28 15 22 43 31\n 20 22 43 33 32", "output": "-1\n \n\n* * *"}, {"input": "5\n 4 46 6 38 43\n 33 15 18 27 37", "output": "3"}]
In the first line, print an integer $m$. In the second line, print $m$ integers $G_i (i=0,1,...,m-1)$ separated by single space character in a line. In the third line, print cnt in a line. In the following $n$ lines, print $A_i (i=0,1,...,n-1)$ respectively. This problem has multiple solutions and the judge will be performed by a special validator.
s813419515
Wrong Answer
p02262
In the first line, an integer $n$ is given. In the following $n$ lines, $A_i (i=0,1,...,n-1)$ are given for each line.
Shell Sort Shell Sort is a generalization of Insertion Sort to arrange a list of $n$ elements $A$. 1 insertionSort(A, n, g) 2 for i = g to n-1 3 v = A[i] 4 j = i - g 5 while j >= 0 && A[j] > v 6 A[j+g] = A[j] 7 j = j - g 8 cnt++ 9 A[j+g] = v 10 11 shellSort(A, n) 12 cnt = 0 13 m = ? 14 G[] = {?, ?,..., ?} 15 for i = 0 to m-1 16 insertionSort(A, n, G[i]) A function shellSort(A, n) performs a function insertionSort(A, n, g), which considers every $g$-th elements. Beginning with large values of $g$, it repeats the insertion sort with smaller $g$. Your task is to complete the above program by filling ?. Write a program which reads an integer $n$ and a sequence $A$, and prints $m$, $G_i (i = 0, 1, ..., m − 1)$ in the pseudo code and the sequence $A$ in ascending order. The output of your program must meet the following requirements: * $1 \leq m \leq 100$ * $0 \leq G_i \leq n$ * cnt does not exceed $\lceil n^{1.5}\rceil$
[{"input": "5\n 5\n 1\n 4\n 3\n 2", "output": "2\n 4 1\n 3\n 1\n 2\n 3\n 4\n 5"}, {"input": "3\n 3\n 2\n 1", "output": "1\n 1\n 3\n 1\n 2\n 3"}]
In the first line, print an integer $m$. In the second line, print $m$ integers $G_i (i=0,1,...,m-1)$ separated by single space character in a line. In the third line, print cnt in a line. In the following $n$ lines, print $A_i (i=0,1,...,n-1)$ respectively. This problem has multiple solutions and the judge will be performed by a special validator.
s835435109
Wrong Answer
p02262
In the first line, an integer $n$ is given. In the following $n$ lines, $A_i (i=0,1,...,n-1)$ are given for each line.
swap_count = 0 def main(): num = int(input()) elements = [] for i in range(0, num): elements.append(int(input())) # Get max interval intervals = [] for i in range(0, num): interval = int_f(i) if num <= interval: break intervals.append(interval) for interval in intervals: insertion_sort(elements, num, interval) print(len(intervals)) print(" ".join([str(interval) for interval in intervals])) print(swap_count) for val in elements: print(val) def int_f(x): return 3 * x + 1 def insertion_sort(elements, num, interval=1): global swap_count i = interval while i < num: j = i while interval <= j: print("%s, i: %s, j: %s" % (elements, i, j)) if elements[j - interval] <= elements[j]: break elements[j - interval], elements[j] = elements[j], elements[j - interval] swap_count += 1 j -= interval i += 1 if __name__ == "__main__": main()
Shell Sort Shell Sort is a generalization of Insertion Sort to arrange a list of $n$ elements $A$. 1 insertionSort(A, n, g) 2 for i = g to n-1 3 v = A[i] 4 j = i - g 5 while j >= 0 && A[j] > v 6 A[j+g] = A[j] 7 j = j - g 8 cnt++ 9 A[j+g] = v 10 11 shellSort(A, n) 12 cnt = 0 13 m = ? 14 G[] = {?, ?,..., ?} 15 for i = 0 to m-1 16 insertionSort(A, n, G[i]) A function shellSort(A, n) performs a function insertionSort(A, n, g), which considers every $g$-th elements. Beginning with large values of $g$, it repeats the insertion sort with smaller $g$. Your task is to complete the above program by filling ?. Write a program which reads an integer $n$ and a sequence $A$, and prints $m$, $G_i (i = 0, 1, ..., m − 1)$ in the pseudo code and the sequence $A$ in ascending order. The output of your program must meet the following requirements: * $1 \leq m \leq 100$ * $0 \leq G_i \leq n$ * cnt does not exceed $\lceil n^{1.5}\rceil$
[{"input": "5\n 5\n 1\n 4\n 3\n 2", "output": "2\n 4 1\n 3\n 1\n 2\n 3\n 4\n 5"}, {"input": "3\n 3\n 2\n 1", "output": "1\n 1\n 3\n 1\n 2\n 3"}]
In the first line, print an integer $m$. In the second line, print $m$ integers $G_i (i=0,1,...,m-1)$ separated by single space character in a line. In the third line, print cnt in a line. In the following $n$ lines, print $A_i (i=0,1,...,n-1)$ respectively. This problem has multiple solutions and the judge will be performed by a special validator.
s722651615
Accepted
p02262
In the first line, an integer $n$ is given. In the following $n$ lines, $A_i (i=0,1,...,n-1)$ are given for each line.
class Shellsort: def __init__(self, x, n): self.x = x self.n = n def sorting(self): self.cnt = 0 self.G = [1] i = 0 while 1: z = self.G[i] * 3 + 1 if z > self.n or len(self.G) == 20: break self.G.append(z) i += 1 self.G.sort(reverse=True) self.m = len(self.G) for i in range(self.m): self.insertation(self.G[i]) return self def insertation(self, g): for i in range(g, self.n): v = self.x[i] j = i - g while j >= 0 and self.x[j] > v: self.x[j + g] = x[j] j = j - g self.cnt += 1 self.x[j + g] = v n = int(input()) x = [0] * n for i in range(n): x[i] = int(input()) a = Shellsort(x, n).sorting() print(a.m) L = [str(i) for i in a.G] print(" ".join(L)) print(a.cnt) for i in a.x: print(i)
Shell Sort Shell Sort is a generalization of Insertion Sort to arrange a list of $n$ elements $A$. 1 insertionSort(A, n, g) 2 for i = g to n-1 3 v = A[i] 4 j = i - g 5 while j >= 0 && A[j] > v 6 A[j+g] = A[j] 7 j = j - g 8 cnt++ 9 A[j+g] = v 10 11 shellSort(A, n) 12 cnt = 0 13 m = ? 14 G[] = {?, ?,..., ?} 15 for i = 0 to m-1 16 insertionSort(A, n, G[i]) A function shellSort(A, n) performs a function insertionSort(A, n, g), which considers every $g$-th elements. Beginning with large values of $g$, it repeats the insertion sort with smaller $g$. Your task is to complete the above program by filling ?. Write a program which reads an integer $n$ and a sequence $A$, and prints $m$, $G_i (i = 0, 1, ..., m − 1)$ in the pseudo code and the sequence $A$ in ascending order. The output of your program must meet the following requirements: * $1 \leq m \leq 100$ * $0 \leq G_i \leq n$ * cnt does not exceed $\lceil n^{1.5}\rceil$
[{"input": "5\n 5\n 1\n 4\n 3\n 2", "output": "2\n 4 1\n 3\n 1\n 2\n 3\n 4\n 5"}, {"input": "3\n 3\n 2\n 1", "output": "1\n 1\n 3\n 1\n 2\n 3"}]
Print the string resulting from shifting each character of S by N in alphabetical order. * * *
s587843365
Wrong Answer
p02848
Input is given from Standard Input in the following format: N S
n = int(input()) l = str(input()) # print(type(l)) ll = [] leng = len(l) # print('leng is %d'%leng) for i in range(leng): t = l[i] # print(t) tt = (ord(t) - ord("A") + 1 + n) % 26 ttt = chr(tt + 64) ll.append(ttt) print(*ll, sep="")
Statement We have a string S consisting of uppercase English letters. Additionally, an integer N will be given. Shift each character of S by N in alphabetical order (see below), and print the resulting string. We assume that `A` follows `Z`. For example, shifting `A` by 2 results in `C` (`A` \to `B` \to `C`), and shifting `Y` by 3 results in `B` (`Y` \to `Z` \to `A` \to `B`).
[{"input": "2\n ABCXYZ", "output": "CDEZAB\n \n\nNote that `A` follows `Z`.\n\n* * *"}, {"input": "0\n ABCXYZ", "output": "ABCXYZ\n \n\n* * *"}, {"input": "13\n ABCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "NOPQRSTUVWXYZABCDEFGHIJKLM"}]
Print the string resulting from shifting each character of S by N in alphabetical order. * * *
s949135591
Runtime Error
p02848
Input is given from Standard Input in the following format: N S
def solve(n: int, s: str) -> str: def inc(c: str, n: int) -> str: tbl = { 0: "A", 1: "B", 2: "C", 3: "D", 4: "E", 5: "F", 6: "G", 7: "H", 8: "I", 9: "J", 10: "K", 11: "L", 12: "M", 13: "N", 14: "O", 15: "P", 16: "Q", 17: "R", 18: "S", 19: "T", 20: "U", 21: "V", 23: "W", 24: "X", 25: "Y", 26: "Z", } rev_tbl = {v: k for k, v in tbl.items()} idx = (rev_tbl[c] + n) % len(tbl) return tbl[idx] return "".join([inc(c, n) for c in s]) n = int(input().strip()) s = input().strip() print(solve(n, s))
Statement We have a string S consisting of uppercase English letters. Additionally, an integer N will be given. Shift each character of S by N in alphabetical order (see below), and print the resulting string. We assume that `A` follows `Z`. For example, shifting `A` by 2 results in `C` (`A` \to `B` \to `C`), and shifting `Y` by 3 results in `B` (`Y` \to `Z` \to `A` \to `B`).
[{"input": "2\n ABCXYZ", "output": "CDEZAB\n \n\nNote that `A` follows `Z`.\n\n* * *"}, {"input": "0\n ABCXYZ", "output": "ABCXYZ\n \n\n* * *"}, {"input": "13\n ABCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "NOPQRSTUVWXYZABCDEFGHIJKLM"}]
Print the string resulting from shifting each character of S by N in alphabetical order. * * *
s908659620
Accepted
p02848
Input is given from Standard Input in the following format: N S
stringline = [] addnum = int(input()) stringline = input() for i in range(len(stringline)): if "A" <= stringline[i] and stringline[i] <= "Z": print( chr((ord(stringline[i]) - ord("A") + int(addnum)) % 26 + ord("A")), end="" )
Statement We have a string S consisting of uppercase English letters. Additionally, an integer N will be given. Shift each character of S by N in alphabetical order (see below), and print the resulting string. We assume that `A` follows `Z`. For example, shifting `A` by 2 results in `C` (`A` \to `B` \to `C`), and shifting `Y` by 3 results in `B` (`Y` \to `Z` \to `A` \to `B`).
[{"input": "2\n ABCXYZ", "output": "CDEZAB\n \n\nNote that `A` follows `Z`.\n\n* * *"}, {"input": "0\n ABCXYZ", "output": "ABCXYZ\n \n\n* * *"}, {"input": "13\n ABCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "NOPQRSTUVWXYZABCDEFGHIJKLM"}]
Print the string resulting from shifting each character of S by N in alphabetical order. * * *
s792557305
Accepted
p02848
Input is given from Standard Input in the following format: N S
n = int(input()) b = list(map(str, input())) for i in range(0, len(b), 1): b[i] = ord(b[i]) + n if b[i] > 90: b[i] -= 26 print(chr(b[i]), end="")
Statement We have a string S consisting of uppercase English letters. Additionally, an integer N will be given. Shift each character of S by N in alphabetical order (see below), and print the resulting string. We assume that `A` follows `Z`. For example, shifting `A` by 2 results in `C` (`A` \to `B` \to `C`), and shifting `Y` by 3 results in `B` (`Y` \to `Z` \to `A` \to `B`).
[{"input": "2\n ABCXYZ", "output": "CDEZAB\n \n\nNote that `A` follows `Z`.\n\n* * *"}, {"input": "0\n ABCXYZ", "output": "ABCXYZ\n \n\n* * *"}, {"input": "13\n ABCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "NOPQRSTUVWXYZABCDEFGHIJKLM"}]
Print the string resulting from shifting each character of S by N in alphabetical order. * * *
s557299040
Runtime Error
p02848
Input is given from Standard Input in the following format: N S
import sys sys.setrecursionlimit(10**9) n = int(input()) ab = [] t = [[] for _ in range(n)] for _ in range(n - 1): a, b = map(lambda x: int(x) - 1, input().split()) t[a].append(b) t[b].append(a) ab.append((min(a, b), max(a, b))) k = max(map(len, t)) d = {} def dfs(pre, cur, col): cn = 1 if col != 1 else 2 for i in t[cur]: if i == pre: continue d[(min(i, cur), max(i, cur))] = cn dfs(cur, i, cn) cn += 1 if col == cn: cn += 1 dfs(0, 0, 0) print(k) for i in ab: print(d[i])
Statement We have a string S consisting of uppercase English letters. Additionally, an integer N will be given. Shift each character of S by N in alphabetical order (see below), and print the resulting string. We assume that `A` follows `Z`. For example, shifting `A` by 2 results in `C` (`A` \to `B` \to `C`), and shifting `Y` by 3 results in `B` (`Y` \to `Z` \to `A` \to `B`).
[{"input": "2\n ABCXYZ", "output": "CDEZAB\n \n\nNote that `A` follows `Z`.\n\n* * *"}, {"input": "0\n ABCXYZ", "output": "ABCXYZ\n \n\n* * *"}, {"input": "13\n ABCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "NOPQRSTUVWXYZABCDEFGHIJKLM"}]
Print the string resulting from shifting each character of S by N in alphabetical order. * * *
s672788870
Accepted
p02848
Input is given from Standard Input in the following format: N S
number = int(input()) day = input() if number == 0: print(day) else: alphabet = list("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ") myIter = iter(day) out = list() for x in myIter: pos = alphabet.index(x) out.append(alphabet[pos + number]) print("".join(out))
Statement We have a string S consisting of uppercase English letters. Additionally, an integer N will be given. Shift each character of S by N in alphabetical order (see below), and print the resulting string. We assume that `A` follows `Z`. For example, shifting `A` by 2 results in `C` (`A` \to `B` \to `C`), and shifting `Y` by 3 results in `B` (`Y` \to `Z` \to `A` \to `B`).
[{"input": "2\n ABCXYZ", "output": "CDEZAB\n \n\nNote that `A` follows `Z`.\n\n* * *"}, {"input": "0\n ABCXYZ", "output": "ABCXYZ\n \n\n* * *"}, {"input": "13\n ABCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "NOPQRSTUVWXYZABCDEFGHIJKLM"}]
Print the string resulting from shifting each character of S by N in alphabetical order. * * *
s123923401
Runtime Error
p02848
Input is given from Standard Input in the following format: N S
a = int(input()) s = list(input()) t = [len(s)] list = [chr(i) for i in range(65, 65 + 26)] for i in s: t.append(list.index(i)) u = [i + a for i in t] u = [i - 26 if i >= 26 else i for i in u] b = [] for i in u: b.append(list[i]) k = "" for s in b: k += s print(k)
Statement We have a string S consisting of uppercase English letters. Additionally, an integer N will be given. Shift each character of S by N in alphabetical order (see below), and print the resulting string. We assume that `A` follows `Z`. For example, shifting `A` by 2 results in `C` (`A` \to `B` \to `C`), and shifting `Y` by 3 results in `B` (`Y` \to `Z` \to `A` \to `B`).
[{"input": "2\n ABCXYZ", "output": "CDEZAB\n \n\nNote that `A` follows `Z`.\n\n* * *"}, {"input": "0\n ABCXYZ", "output": "ABCXYZ\n \n\n* * *"}, {"input": "13\n ABCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "NOPQRSTUVWXYZABCDEFGHIJKLM"}]
Print the string resulting from shifting each character of S by N in alphabetical order. * * *
s748718328
Runtime Error
p02848
Input is given from Standard Input in the following format: N S
N = int(input()) input1 = input() inputbox1 = list(input1) li = [0] * 1000 li2 = [0] * 1000 ans: str = "" for i in range(0, len(inputbox1)): if inputbox1[i] == "A": li[i] = 1 + N elif inputbox1[i] == "B": li[i] = 2 + N elif inputbox1[i] == "C": li[i] = 3 + N elif inputbox1[i] == "D": li[i] = 4 + N elif inputbox1[i] == "E": li[i] = 5 + N elif inputbox1[i] == "F": li[i] = 6 + N elif inputbox1[i] == "G": li[i] = 7 + N elif inputbox1[i] == "H": li[i] = 8 + N elif inputbox1[i] == "I": li[i] = 9 + N elif inputbox1[i] == "J": li[i] = 10 + N elif inputbox1[i] == "K": li[i] = 11 + N elif inputbox1[i] == "L": li[i] = 12 + N elif inputbox1[i] == "M": li[i] = 13 + N elif inputbox1[i] == "N": li[i] = 14 + N elif inputbox1[i] == "O": li[i] = 15 + N elif inputbox1[i] == "P": li[i] = 16 + N elif inputbox1[i] == "Q": li[i] = 17 + N elif inputbox1[i] == "R": li[i] = 18 + N elif inputbox1[i] == "S": li[i] = 19 + N elif inputbox1[i] == "T": li[i] = 20 + N elif inputbox1[i] == "U": li[i] = 21 + N elif inputbox1[i] == "V": li[i] = 22 + N elif inputbox1[i] == "W": li[i] = 23 + N elif inputbox1[i] == "X": li[i] = 24 + N elif inputbox1[i] == "Y": li[i] = 25 + N elif inputbox1[i] == "Z": li[i] = 26 + N li[i] = li[i] % 26 for i in range(0, len(inputbox1)): if li[i] == 1: li2[i] = "A" elif li[i] == 2: li2[i] = "B" elif li[i] == 3: li2[i] = "C" elif li[i] == 4: li2[i] = "D" elif li[i] == 5: li2[i] = "E" elif li[i] == 6: li2[i] = "F" elif li[i] == 7: li2[i] = "G" elif li[i] == 8: li2[i] = "H" elif li[i] == 9: li2[i] = "I" elif li[i] == 10: li2[i] = "J" elif li[i] == 11: li2[i] = "K" elif li[i] == 12: li2[i] = "L" elif li[i] == 13: li2[i] = "M" elif li[i] == 14: li2[i] = "N" elif li[i] == 15: li2[i] = "O" elif li[i] == 16: li2[i] = "P" elif li[i] == 17: li2[i] = "Q" elif li[i] == 18: li2[i] = "R" elif li[i] == 19: li2[i] = "S" elif li[i] == 20: li2[i] = "T" elif li[i] == 21: li2[i] = "U" elif li[i] == 22: li2[i] = "V" elif li[i] == 23: li2[i] = "W" elif li[i] == 24: li2[i] = "X" elif li[i] == 25: li2[i] = "Y" elif li[i] == 0: li2[i] = "Z" for i in range(0, len(inputbox1)): ans = ans + li2[i] print(ans)
Statement We have a string S consisting of uppercase English letters. Additionally, an integer N will be given. Shift each character of S by N in alphabetical order (see below), and print the resulting string. We assume that `A` follows `Z`. For example, shifting `A` by 2 results in `C` (`A` \to `B` \to `C`), and shifting `Y` by 3 results in `B` (`Y` \to `Z` \to `A` \to `B`).
[{"input": "2\n ABCXYZ", "output": "CDEZAB\n \n\nNote that `A` follows `Z`.\n\n* * *"}, {"input": "0\n ABCXYZ", "output": "ABCXYZ\n \n\n* * *"}, {"input": "13\n ABCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "NOPQRSTUVWXYZABCDEFGHIJKLM"}]
Print the string resulting from shifting each character of S by N in alphabetical order. * * *
s388010447
Accepted
p02848
Input is given from Standard Input in the following format: N S
t = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ" n = int(input()) print("".join([t[t.index(i) + n] for i in input()]))
Statement We have a string S consisting of uppercase English letters. Additionally, an integer N will be given. Shift each character of S by N in alphabetical order (see below), and print the resulting string. We assume that `A` follows `Z`. For example, shifting `A` by 2 results in `C` (`A` \to `B` \to `C`), and shifting `Y` by 3 results in `B` (`Y` \to `Z` \to `A` \to `B`).
[{"input": "2\n ABCXYZ", "output": "CDEZAB\n \n\nNote that `A` follows `Z`.\n\n* * *"}, {"input": "0\n ABCXYZ", "output": "ABCXYZ\n \n\n* * *"}, {"input": "13\n ABCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "NOPQRSTUVWXYZABCDEFGHIJKLM"}]
Print the string resulting from shifting each character of S by N in alphabetical order. * * *
s562840458
Runtime Error
p02848
Input is given from Standard Input in the following format: N S
N = int(input()) S = input() list_S = list(S) list_ans = [] alphabet_number = { "a": 1, "b": 2, "c": 3, "d": 4, "e": 5, "f": 6, "g": 7, "h": 8, "i": 9, "j": 10, "k": 11, "l": 12, "m": 13, "n": 14, "o": 15, "p": 16, "q": 17, "r": 18, "s": 19, "t": 20, "u": 21, "v": 22, "w": 23, "x": 24, "y": 25, "z": 26, } number_alphabet = { 1: "a", 2: "b", 3: "c", 4: "d", 5: "e", 6: "f", 7: "g", 8: "h", 9: "i", 10: "j", 11: "k", 12: "l", 13: "m", 14: "n", 15: "o", 16: "p", 17: "q", 18: "r", 19: "s", 20: "t", 21: "u", 22: "v", 23: "w", 24: "x", 25: "y", 26: "z", } for i in range(len(list_S)): A = alphabet_number[list_S[i]] if A + N <= 26: B = A + N else: B = (A + N) - 26 C = number_alphabet[B] list_ans.append(C) print("".join(list_ans))
Statement We have a string S consisting of uppercase English letters. Additionally, an integer N will be given. Shift each character of S by N in alphabetical order (see below), and print the resulting string. We assume that `A` follows `Z`. For example, shifting `A` by 2 results in `C` (`A` \to `B` \to `C`), and shifting `Y` by 3 results in `B` (`Y` \to `Z` \to `A` \to `B`).
[{"input": "2\n ABCXYZ", "output": "CDEZAB\n \n\nNote that `A` follows `Z`.\n\n* * *"}, {"input": "0\n ABCXYZ", "output": "ABCXYZ\n \n\n* * *"}, {"input": "13\n ABCDEFGHIJKLMNOPQRSTUVWXYZ", "output": "NOPQRSTUVWXYZABCDEFGHIJKLM"}]
Print the final number of edges in G. * * *
s082963304
Wrong Answer
p03058
Input is given from Standard Input in the following format: N M a_1 b_1 : a_{N-1} b_{N-1} c_1 d_1 : c_M d_M
print("5")
Statement You are given a tree T with N vertices and an undirected graph G with N vertices and M edges. The vertices of each graph are numbered 1 to N. The i-th of the N-1 edges in T connects Vertex a_i and Vertex b_i, and the j-th of the M edges in G connects Vertex c_j and Vertex d_j. Consider adding edges to G by repeatedly performing the following operation: * Choose three integers a, b and c such that G has an edge connecting Vertex a and b and an edge connecting Vertex b and c but not an edge connecting Vertex a and c. If there is a simple path in T that contains all three of Vertex a, b and c in some order, add an edge in G connecting Vertex a and c. Print the number of edges in G when no more edge can be added. It can be shown that this number does not depend on the choices made in the operation.
[{"input": "5 3\n 1 2\n 1 3\n 3 4\n 1 5\n 5 4\n 2 5\n 1 5", "output": "6\n \n\nWe can have at most six edges in G by adding edges as follows:\n\n * Let (a,b,c)=(1,5,4) and add an edge connecting Vertex 1 and 4.\n * Let (a,b,c)=(1,5,2) and add an edge connecting Vertex 1 and 2.\n * Let (a,b,c)=(2,1,4) and add an edge connecting Vertex 2 and 4.\n\n* * *"}, {"input": "7 5\n 1 5\n 1 4\n 1 7\n 1 2\n 2 6\n 6 3\n 2 5\n 1 3\n 1 6\n 4 6\n 4 7", "output": "11\n \n\n* * *"}, {"input": "13 11\n 6 13\n 1 2\n 5 1\n 8 4\n 9 7\n 12 2\n 10 11\n 1 9\n 13 7\n 13 11\n 8 10\n 3 8\n 4 13\n 8 12\n 4 7\n 2 3\n 5 11\n 1 4\n 2 11\n 8 10\n 3 5\n 6 9\n 4 10", "output": "27"}]
Print the final number of edges in G. * * *
s937584128
Runtime Error
p03058
Input is given from Standard Input in the following format: N M a_1 b_1 : a_{N-1} b_{N-1} c_1 d_1 : c_M d_M
import queue SIZE = 2000 vec = [[] for _ in range(SIZE)] par = [[-1] * SIZE for _ in range(SIZE)] id_ = [[-1] * SIZE for _ in range(SIZE)] ans = 0 def dfs(v: int, p: int, rt: int): par[rt][v] = p for to in vec[v]: if to == p: continue dfs(to, v, rt) def dfs2(v: int, p: int, b: int): global ans if id_[b][v] == v: ans += 1 b = v for to in vec[v]: if to == p: continue dfs2(to, v, b) def add(a: int, b: int): if id_[a][b] == b or id_[b][a] == a: return if id_[a][b] != -1: add(id_[a][b], b) return if id_[b][a] != -1: add(id_[b][a], a) return id_[a][b] = b id_[b][a] = a nxt = [] que = queue.Queue() que.put(b) while not que.empty(): v = que.get() for to in vec[v]: if to == par[a][v]: continue if id_[a][to] != -1: nxt.append((to, b)) else: id_[a][to] = b que.put(to) que.put(a) while not que.empty(): v = que.get() for to in vec[v]: if to == par[b][v]: continue if id_[b][to] != -1: nxt.append((to, a)) else: id_[b][to] = a que.put(to) for u, v in nxt: add(u, v) def adding_edges(N: int, M: int, T: list, G: list) -> int: global ans for a, b in T: vec[a - 1].append(b - 1) vec[b - 1].append(a - 1) for i in range(N): dfs(i, -1, i) for c, d in G: add(c - 1, d - 1) for i in range(N): for to in vec[i]: dfs2(to, i, i) return ans // 2 if __name__ == "__main__": N = 0 M = 0 N, M = map(int, input().split()) T = [tuple(int(s) for s in input().split()) for _ in range(N - 1)] G = [tuple(int(s) for s in input().split()) for _ in range(M)] ans = adding_edges(N, M, T, G) print(ans)
Statement You are given a tree T with N vertices and an undirected graph G with N vertices and M edges. The vertices of each graph are numbered 1 to N. The i-th of the N-1 edges in T connects Vertex a_i and Vertex b_i, and the j-th of the M edges in G connects Vertex c_j and Vertex d_j. Consider adding edges to G by repeatedly performing the following operation: * Choose three integers a, b and c such that G has an edge connecting Vertex a and b and an edge connecting Vertex b and c but not an edge connecting Vertex a and c. If there is a simple path in T that contains all three of Vertex a, b and c in some order, add an edge in G connecting Vertex a and c. Print the number of edges in G when no more edge can be added. It can be shown that this number does not depend on the choices made in the operation.
[{"input": "5 3\n 1 2\n 1 3\n 3 4\n 1 5\n 5 4\n 2 5\n 1 5", "output": "6\n \n\nWe can have at most six edges in G by adding edges as follows:\n\n * Let (a,b,c)=(1,5,4) and add an edge connecting Vertex 1 and 4.\n * Let (a,b,c)=(1,5,2) and add an edge connecting Vertex 1 and 2.\n * Let (a,b,c)=(2,1,4) and add an edge connecting Vertex 2 and 4.\n\n* * *"}, {"input": "7 5\n 1 5\n 1 4\n 1 7\n 1 2\n 2 6\n 6 3\n 2 5\n 1 3\n 1 6\n 4 6\n 4 7", "output": "11\n \n\n* * *"}, {"input": "13 11\n 6 13\n 1 2\n 5 1\n 8 4\n 9 7\n 12 2\n 10 11\n 1 9\n 13 7\n 13 11\n 8 10\n 3 8\n 4 13\n 8 12\n 4 7\n 2 3\n 5 11\n 1 4\n 2 11\n 8 10\n 3 5\n 6 9\n 4 10", "output": "27"}]
Print the final number of edges in G. * * *
s591002799
Wrong Answer
p03058
Input is given from Standard Input in the following format: N M a_1 b_1 : a_{N-1} b_{N-1} c_1 d_1 : c_M d_M
# no sub撤退をしないという覚悟 print("nan")
Statement You are given a tree T with N vertices and an undirected graph G with N vertices and M edges. The vertices of each graph are numbered 1 to N. The i-th of the N-1 edges in T connects Vertex a_i and Vertex b_i, and the j-th of the M edges in G connects Vertex c_j and Vertex d_j. Consider adding edges to G by repeatedly performing the following operation: * Choose three integers a, b and c such that G has an edge connecting Vertex a and b and an edge connecting Vertex b and c but not an edge connecting Vertex a and c. If there is a simple path in T that contains all three of Vertex a, b and c in some order, add an edge in G connecting Vertex a and c. Print the number of edges in G when no more edge can be added. It can be shown that this number does not depend on the choices made in the operation.
[{"input": "5 3\n 1 2\n 1 3\n 3 4\n 1 5\n 5 4\n 2 5\n 1 5", "output": "6\n \n\nWe can have at most six edges in G by adding edges as follows:\n\n * Let (a,b,c)=(1,5,4) and add an edge connecting Vertex 1 and 4.\n * Let (a,b,c)=(1,5,2) and add an edge connecting Vertex 1 and 2.\n * Let (a,b,c)=(2,1,4) and add an edge connecting Vertex 2 and 4.\n\n* * *"}, {"input": "7 5\n 1 5\n 1 4\n 1 7\n 1 2\n 2 6\n 6 3\n 2 5\n 1 3\n 1 6\n 4 6\n 4 7", "output": "11\n \n\n* * *"}, {"input": "13 11\n 6 13\n 1 2\n 5 1\n 8 4\n 9 7\n 12 2\n 10 11\n 1 9\n 13 7\n 13 11\n 8 10\n 3 8\n 4 13\n 8 12\n 4 7\n 2 3\n 5 11\n 1 4\n 2 11\n 8 10\n 3 5\n 6 9\n 4 10", "output": "27"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s787236295
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
nm = int(input()) n = [input() for _ in range(nm)] mm = int(input()) m = [input() for _ in range(mm)] s = list(set(n)) print(max(0,max(n.count(s[i])-m.count(s[i]) for i in range(len(s))))
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s411343999
Accepted
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
############################################################################### from sys import stdout from bisect import bisect_left as binl from copy import copy, deepcopy from collections import defaultdict mod = 1 def intin(): input_tuple = input().split() if len(input_tuple) <= 1: return int(input_tuple[0]) return tuple(map(int, input_tuple)) def intina(): return [int(i) for i in input().split()] def intinl(count): return [intin() for _ in range(count)] def modadd(x, y): global mod return (x + y) % mod def modmlt(x, y): global mod return (x * y) % mod def lcm(x, y): while y != 0: z = x % y x = y y = z return x def combination(x, y): assert x >= y if y > x // 2: y = x - y ret = 1 for i in range(0, y): j = x - i i = i + 1 ret = ret * j ret = ret // i return ret def get_divisors(x): retlist = [] for i in range(1, int(x**0.5) + 3): if x % i == 0: retlist.append(i) retlist.append(x // i) return retlist def get_factors(x): retlist = [] for i in range(2, int(x**0.5) + 3): while x % i == 0: retlist.append(i) x = x // i retlist.append(x) return retlist def make_linklist(xylist): linklist = {} for a, b in xylist: linklist.setdefault(a, []) linklist.setdefault(b, []) linklist[a].append(b) linklist[b].append(a) return linklist def calc_longest_distance(linklist, v=1): distance_list = {} distance_count = 0 distance = 0 vlist_previous = [] vlist = [v] nodecount = len(linklist) while distance_count < nodecount: vlist_next = [] for v in vlist: distance_list[v] = distance distance_count += 1 vlist_next.extend(linklist[v]) distance += 1 vlist_to_del = vlist_previous vlist_previous = vlist vlist = list(set(vlist_next) - set(vlist_to_del)) max_distance = -1 max_v = None for v, distance in distance_list.items(): if distance > max_distance: max_distance = distance max_v = v return (max_distance, max_v) def calc_tree_diameter(linklist, v=1): _, u = calc_longest_distance(linklist, v) distance, _ = calc_longest_distance(linklist, u) return distance class UnionFind: def __init__(self, n): self.parent = [i for i in range(n)] def root(self, i): if self.parent[i] == i: return i self.parent[i] = self.root(self.parent[i]) return self.parent[i] def unite(self, i, j): rooti = self.root(i) rootj = self.root(j) if rooti == rootj: return if rooti < rootj: self.parent[rootj] = rooti else: self.parent[rooti] = rootj def same(self, i, j): return self.root(i) == self.root(j) ############################################################################### def main(): n = intin() slist = [input() for _ in range(n)] m = intin() tlist = [input() for _ in range(m)] counts = defaultdict(int) for s in slist: counts[s] += 1 for t in tlist: counts[t] -= 1 ans = 0 for s, count in counts.items(): ans = max(ans, count) print(ans) if __name__ == "__main__": main()
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s350460633
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
n = int(input()) c = [] for i in range(n): c.append(input()) d = [] m = int(input()) for i in range(m): d.append(input()) scores = [] for i in c: score = 0 for j in range(n): if i == c[j]: score += 1 for j in range(m): if i == d[j]: score -= 1 scores.append(score) if max(scores) >= 0: print(max(scores)) else: print(0)n = int(input()) c = [] for i in range(n): c.append(input()) d = [] m = int(input()) for i in range(m): d.append(input()) scores = [] for i in c: score = 0 for j in range(n): if i == c[j]: score += 1 for j in range(m): if i == d[j]: score -= 1 scores.append(score) print(max(scores))
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s071148647
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
x = int(input()) a = [input() for i in range(x)] y = int(input()) b = [input() for h in range(y)] count_max = 0 for j in a: if a.count(j) - b.count(j) > count_max: a.count(j) - b.count(j) = count_max print(count_max)
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s591057339
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
x = int(input()) a = [input() for i in range(x)] y = int(input()) b = [input() for h in range(y)] count_max = 0 for j in a: if (a.count(j) - b.count(j)) > count_max: a.count(j) - b.count(j) = count_max print(count_max)
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s257631557
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
n = int(input()) ss = [] for i in range(n): ss.append(input()) m = int(input()) ts = [] for i in range(m): ts.append(input()) counter = dict() for s in ss: counter.setdefault(s, 0) c = counter.get(s) counter[s] = c + 1 for t in ts: counter.setdefault(t, 0) c = counter.get(t) counter[t] = c - 1 ans = max(counter.values() if ans < 0: ans = 0 print(ans)
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s617776786
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
nN = int(input()) sListA = [] nListA = [0 for i in range(nN)] for i in range(nN): sTmp = input() if sTmp in sListA: nTmp = sListA.index(sTmp) nListA[nTmp] += 1 else: sListA.append(sTmp) nTmp = sListA.index(sTmp) nListA[nTmp] += 1 nN = int(input()) sListB = [] nListB = [0 for i in range(nN)] for i in range(nN): sTmp = input() if sTmp in sListA: nTmp = sListA.index(sTmp) nListA[nTmp] -= 1 else: sListA.append(sTmp) nTmp = sListA.index(sTmp) nListA[nTmp] -= 1 nMax = max(nListA) # print(sListA) print(nMax)
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s398432405
Wrong Answer
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
N = int(input()) s_list = [input() for _ in range(N)] M = int(input()) t_list = [input() for _ in range(M)] s_set = list(set(s_list)) result = [] for s in s_set: r = 0 for i in s_list: if i == s: r += 1 for j in t_list: if j == s: r -= 1 result.append(r) print(max(result))
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s739768984
Wrong Answer
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
dict_ = dict() [ exec("dict_['{0}'] = dict_.get('{0}', 0) + 1".format(input())) for _ in range(int(input())) ] [ exec("dict_['{0}'] = dict_.get('{0}', 0) - 1".format(input())) for _ in range(int(input())) ] print(max(dict_.values()))
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s819154377
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
N = int(input()) a = [int(input()) for i in range(N)] M = int(input()) b = [int(input()) for i in range(M)] k = [] for x in a: temp = a.count(x)-b.count(x) k.append(temp) print(max(k))
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s301137270
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
N = int(input()) a = [input() for i in range(N)] M = int(input()) b = [input() for i in range(M)] k = [] for x in a: temp = a.count(x)-b.count(x) k.append(temp) print(max(k))
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s532295249
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
n = [input() for _ in range(int(input()))] m = [input() for _ in range(int(input()))] l = list(set(n)) print(max(0, max(n.count(l[i]) - m.count(l[i])) for i in range(len(l))))
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s118584352
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
n = [input() for i in range(int(input()))] m = [input() for i in range(int(input()))] l = list(set(n)) print(max(0, max(n.count(l[i]) - m.count(l[i])) for i in range(len(l))))
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s688617047
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
# -*- Coding: utf-8 -*- blue=int(input()) blue_dict={} red_dict={} for i in range(blue): tmp=input() if tmp in blue_dict.keys(): value=blue_dict[tmp] value+=1 blue_dict[tmp]=value red_dict[tmp]=0 else: blue_dict[tmp]=1 red_dict[tmo]=0 red=int(input()) for i in range(red): tmp=input() if tmp in red_dict.keys(): value=red_dict[tmp] value+=1 red_dict[tmp]=value if tmp not in blue_dict.keys(): blue_dict[tmp]=0 else: red_dict[tmp]=1 result=0 for i in blue_dict.keys(): sub=blue_dict[i]-red_dict[i] if sub>result: result=sub print(result)
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s565144594
Wrong Answer
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
incomeNum = int(input()) income = [] for i in range(incomeNum): income.append(input()) outgoNum = int(input()) outgo = [] for i in range(outgoNum): outgo.append(input()) money = 0 for c in income: if c in outgo: inum = income.count(c) onum = outgo.count(c) if inum > onum: if inum > money: money = inum - onum else: inum = income.count(c) if inum > money: money = inum print(money)
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s278826691
Wrong Answer
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
s_num = int(input()) s = [] s = [input(x) for x in range(s_num)] t = [] t_num = int(input()) t = [input(x) for x in range(t_num)] max_v = 0 for i in range(s_num): if max_v < (s.count(s[i]) - t.count(s[i])): max_v = s.count(s[i]) - t.count(s[i]) print(max_v)
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s458264645
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
N = int(input()) s = [input() for i in range(N)] M = int(input()) t = [input() for i in range(M)] s_set = list(set(s)) t_set = list(set(t)) check_list = [] for i in s_set: check_list.append(s.count(i) - t.count(i)) print(max(max(check_list), 0)
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s950036222
Accepted
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
n = [input() for i in range(int(input()))] m = [input() for i in range(int(input()))] words = list(set(n)) print(max(0, max(n.count(words[i]) - m.count(words[i]) for i in range(len(words)))))
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s718612816
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
N=int(input()) s=[int(input()) for _ in range(N)] M=int(input()) t=[int(input()) for _ in range(M)] l=list(set(N)) print(max(0,max(s.count(l[i])-t.count(l[i]) for i in range len(l))))
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s933980377
Wrong Answer
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
b = [input() for i in range(int(input()))] r = [input() for i in range(int(input()))] o = 0 for w in list(set(b)): o = max(0, b.count(w) - r.count(w)) print(o)
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s996042059
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
n = [int(input()) for i in range(int(input()))] m = [int(input()) for i in range(int(input()))] print(max(len(set(n)) - len(set(m)), 0))
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s233297025
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
N=int(input()) s=[input() for _ in range(N)] M=int(input()) t=[input() for _ in range(M)] l=list(set(N)) print(max(0,max(s.count(l[i])-t.count(l[i]) for i in range(len(l))))
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s595182329
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
n = int(input()) s = [input() for i in range(n)] m = int(input()) t = [input() for i in range(m)] ans = 0 for str in s:#strは単語を表している。ループの回数としてはn回(sの配列数) count = s.oount(str)-t.count(str) #sの中にstr(たとえばapple)が何個あるか、tの中に同じく str(spple)が何個あるか調べて引いてる。 ans = max(ans,count)  print(ans)
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s367419762
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
a = int(input()) blue = [] count = [] for i in range(a) x = input() if x in blue: count[blue.index(x)] += 1 else: blue.append(x) count.append(1) b = int(input()) for i in range(b) x = input() if x in blue: count[blue.index(x)] -= 1 else: blue.append(x) count.append(-1) blue.sorted() if blue[0] < 0: print("0") else: print(blue[0])
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s295536924
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
#include <iostream> #include <iomanip> #include <string> #include <sstream> #include <bitset> #include <algorithm> #include <cmath> #include <numeric> #include <utility> #include <set> #include <map> #include <tuple> #include <vector> #include <stack> #include <queue> #include <deque> #include <list> using namespace std; using ll = long long; using P = pair<ll, ll>; #define REP(i, n) for(long long (i)=0, i_bound = (long long)(n); (i)<i_bound; ++i) #define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i) #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) { return s << '<' << P.first << ", " << P.second << '>'; } template<class T> ostream& operator << (ostream &s, vector<T> P) { for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; } template<class T> ostream& operator << (ostream &s, vector<vector<T> > P) { for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; } const long long MOD = static_cast<long long>(1e9) + 7LL; const long long INF = 1234567891234567890LL; int main(){ cin.tie(0); cout.sync_with_stdio(false); int N; cin >> N; map<string, int> m; string s; REP(i, N) { cin >> s; m[s] += 1; } int M; cin >> M; REP(i, M){ cin >> s; if(m.count(s)) m[s] -= 1; } int mx = 0; for(auto p: m){ mx = max(mx, p.second); } cout << mx << endl; return 0; }
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s217377259
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
# B - Two Colors Card Game from collections import Counter n = int(input()) n_dict = {} for _ in range(n): ns = str(input()) if ns not in n_dict.keys(): n_dict[ns] = 1 else: n_dict[ns] += 1 m = int(input() m_dict = {} for _ in range(n): ms = str(input()) if ms not in m_dict.keys(): n_dict[ms] = 1 else: n_dict[ms] += 1 delta = dict(Counter(n_dict) - Counter(m_dict)) ans = max(delta.values()) print(ans)
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s954965412
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
a = int(input()) blue = [] count = [] for i in range(a) x = input() if x in blue: count[blue.index(x)] += 1 else: blue.append(x) count.append(1) b = int(input()) for i in range(b) x = input() if x in blue: count[blue.index(x)] -= 1 else: blue.append(x) count.append(-1) count.sorted() if count[0] < 0: print("0") else: print (count[0])
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s244260798
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
num = int(input()) dic = { "JPY": 0, "BTC": 0 } for i in range(0, num): val, coin = input().split(' ') dic[coin] += float(val) print(dic["JPY"] + (dic["BTC"] * 380000.0)) def two_colors_card_game(): dic_words = {} for i in range(0, int(input())): word = input() if word in dic_words.keys(): dic_words[word] += 1 else: dic_words[word] = 1 for i in range(0, int(input())): word = input() if word in dic_words.keys(): dic_words[word] -= 1 else: dic_words[word] = -1 if (max(dic_words.values()) >= 0): print(max(dic_words.values())) else: print(0)
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s589699686
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
a = int(input()) blue = [] count = [] for i in range(a) x = input() if x in blue: count[blue.index(x)] += 1 else: blue.append(x) count.append(1) b = int(input()) for i in range(b) x = input() if x in blue: count[blue.index(x)] -= 1 else: blue.append(x) count.append(-1) blue.sorted() if blue[0] < 0: print("0") else: print (blue[0])
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s207304223
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
N = int(input()) s = [input() for i in range(N)] M = int(input()) t = [input() for i in range(M)] name_union = set(s) | set(t) money = {}0 for i, n in enumerate(name_union): money.setdefault(n, 0) money[n] += sum(map(lambda x: 1 if x == n else 0, s)) money[n] -= sum(map(lambda x: 1 if x == n else 0, t)) print(0 if max(money.values()) < 0 else max(money.values()))
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s037867355
Accepted
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
n1 = int(input()) cnt_dict = {} for _ in range(n1): s = input() if s not in cnt_dict: cnt_dict[s] = 1 else: cnt_dict[s] += 1 n2 = int(input()) for _ in range(n2): s = input() if s not in cnt_dict: cnt_dict[s] = -1 else: cnt_dict[s] -= 1 print(max(max(cnt_dict.values()), 0))
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s430649435
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
from collections import defaultdict def main(): N = int(input()) ans = 0 s = defaultdict(int) for _ in range(N): a = input() s[a] += 1 M = int(input()) for _ in range(M): b = input() s[b] -= 1 for v in s.items(): ans = max(ans,v[1]) print(ans) if __name__ == a__main__": main()
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s258514941
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
import collections N=int(input()) s=[int(input()) for i jn range(N)] M=int(input()) t=[int(input()) for i in range(M)] table=collections.defaultdict(int) for x in s: table[x]+=1 for x in t: table[t]+=1 table=table.values() table=[x for x in table if x >= 0] print(sum(table))
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s223648746
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
n = int(input()) a = list(str,input().split()) m = int(input()) b = list(str,input().split()) ans = 0 de = 0 def get(): for i in range(n+1): if a[i]==a[i+1]: ans += 1 return ans def lose(): for i in range(m+1): if b[i]==b[i+1]: de -= 1 return de if get()<=lose():
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s236574148
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
from collections import defaultdict a = int(input()) d = defaultdict(int) for i in range(a): k = input() d[k] += 1 b = int(input()) for i in range(b): k = input() d[k] -= 1 c = d[0] for i in range(len(d)): c = max(c, d[k]) print(c)
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s203208914
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
s=[input() for _ in range(int(input()))] t=[input() for _ in range(int(input()))] l=list(set(n)) print(max(0,max(s.count(l[i])-t.count(l[i]) for i in range(len(l)))))n=[input() for _ in range(int(input()))] m=[input() for _ in range(int(input()))] l=list(set(n)) print(max(0,max(n.count(l[i])-m.count(l[i]) for i in range(len(l)))))
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s708740616
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
N = int(input()) s = list(input() for i range(N)) M = int(input()) t = list(input() for i range(M)) s_set = list(set(s)) ans = 0 for name in s_set: count = s.count(name) - t.count(name) ans = max(count, ans) print(ans)
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s254017753
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
n = int(input()) blue = [input() for i in range(n)] m = int(input()) red = [input() for i in range(n)] x = 0 for w in set(blue): x = blue.count(w) - red.count(w) if blue.count(w) - red.count(w) > x else pass print(x)
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s266101561
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
s = [input() for _ in range(input())] t = [input() for _ in range(input())] ls = set(s) ans=0 temp=0 for l in ls: for ss in s: ans += 1if l == ss ans-=1for tt in t if tt == l temp = ans if ans>temp print(temp)
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s975263220
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
s = [input() for _ in range(int(input()))] t = [input() for _ in range(int(input()))] ls = list(set(s)) temp=0 for l in ls: ans=0 ans += 1 for ss in s if ss == l ans -= 1 for tt in t if tt == l temp = ans if ans>temp print(temp)
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s832893696
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
n = int(input() s ={} for i in range(n): string = input() s[string] = s[string] + 1 if string in s else 1 m = int(input() for i in range(m): string = input() s[string] = s[string] - 1 if string in s else -1 print(max(0,max(s.values())))
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s233340002
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
N = input() s = list(input() for i range(N)) M = input() t = list(input() for i range(M)) s_set = list(set(s)) ans = 0 for name in s_set: count = s.count(name) - t.count(name) ans = max(count, ans) print(ans)
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
If Takahashi can earn at most X yen on balance, print X. * * *
s866768419
Runtime Error
p03408
Input is given from Standard Input in the following format: N s_1 s_2 : s_N M t_1 t_2 : t_M
s = [input() for _ in range(int(input()))] t = [input() for _ in range(int(input()))] ls = list(set(s)) temp=0 for l in ls: ans=0 ans += 1 for ss in s if ss == l ans -= 1 for tt in t if tt == l temp = max(temp, ans) print(temp)
Statement Takahashi has N blue cards and M red cards. A string is written on each card. The string written on the i-th blue card is s_i, and the string written on the i-th red card is t_i. Takahashi will now announce a string, and then check every card. Each time he finds a blue card with the string announced by him, he will earn 1 yen (the currency of Japan); each time he finds a red card with that string, he will lose 1 yen. Here, we only consider the case where the string announced by Takahashi and the string on the card are exactly the same. For example, if he announces `atcoder`, he will not earn money even if there are blue cards with `atcoderr`, `atcode`, `btcoder`, and so on. (On the other hand, he will not lose money even if there are red cards with such strings, either.) At most how much can he earn on balance? Note that the same string may be written on multiple cards.
[{"input": "3\n apple\n orange\n apple\n 1\n grape", "output": "2\n \n\nHe can earn 2 yen by announcing `apple`.\n\n* * *"}, {"input": "3\n apple\n orange\n apple\n 5\n apple\n apple\n apple\n apple\n apple", "output": "1\n \n\nIf he announces `apple`, he will lose 3 yen. If he announces `orange`, he can\nearn 1 yen.\n\n* * *"}, {"input": "1\n voldemort\n 10\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort\n voldemort", "output": "0\n \n\nIf he announces `voldemort`, he will lose 9 yen. If he announces `orange`, for\nexample, he can avoid losing a yen.\n\n* * *"}, {"input": "6\n red\n red\n blue\n yellow\n yellow\n red\n 5\n red\n red\n yellow\n green\n blue", "output": "1"}]
Print the answer. * * *
s127597809
Wrong Answer
p02649
Input is given from Standard Input in the following format: N K S T A_1 A_2 ... A_N
import sys readline = sys.stdin.readline N, K, S, T = map(int, readline().split()) A = list(map(int, readline().split())) # 初期状態はAND = 1111... (18桁)と OR = 0000...(18桁) # ここに対してAND OR を取っていくDP # 最後にdp[(S,T)]を数える # ただしS,Tともに1の桁に0が入っている数 # S,Tともに0の桁に1が入っている数 # は除外する # また、Sでは1だけどTでは0の桁があったらその時点で答えは0 binS = bin(S)[2:].zfill(18) binT = bin(T)[2:].zfill(18) bothone = set() bothzero = set() for i in range(len(binS)): if binS[i] == "1" and binT[i] == "1": bothone.add(i) elif binS[i] == "0" and binT[i] == "0": bothzero.add(i) elif binS[i] == "1" and binT[i] == "0": print(0) exit(0) # print(bothone) # print(bothzero) from collections import defaultdict dp = defaultdict(int) dp[(2**18 - 1, 0)] = 1 for x in A: newdp = defaultdict(int) # print("x",x) for da, do in dp: newdp[(da, do)] += dp[(da, do)] newand = da & x newor = do | x # print("da",da,"do",do,"newand",newand,"newor",newor) # newandを18桁の2進数にしたとき、bothoneの桁に0があってはいけない # 同時に、bothzeroの桁に1があってもいけない bin_newand = bin(newand)[2:].zfill(18) ok = True for i in range(len(bin_newand)): if i in bothone and bin_newand[i] == "0": ok = False break if not ok: continue bin_newor = bin(newor)[2:].zfill(18) for i in range(len(bin_newor)): if i in bothzero and bin_newor[i] == "1": ok = False break if ok: newdp[(newand, newor)] += 1 dp = newdp # print(dp) # print(dp) print(dp[(S, T)])
Statement Given are N pairwise distinct non-negative integers A_1,A_2,\ldots,A_N. Find the number of ways to choose a set of between 1 and K numbers (inclusive) from the given numbers so that the following two conditions are satisfied: * The bitwise AND of the chosen numbers is S. * The bitwise OR of the chosen numbers is T.
[{"input": "3 3 0 3\n 1 2 3", "output": "2\n \n\nThe conditions are satisfied when we choose \\\\{1,2\\\\} or \\\\{1,2,3\\\\}.\n\n* * *"}, {"input": "5 3 1 7\n 3 4 9 1 5", "output": "2\n \n\n* * *"}, {"input": "5 4 0 15\n 3 4 9 1 5", "output": "3"}]
Print the answer. * * *
s614887275
Wrong Answer
p02649
Input is given from Standard Input in the following format: N K S T A_1 A_2 ... A_N
import sys from collections import deque def LI(): return list(map(int, sys.stdin.readline().rstrip().split())) def solve(n, k, s, t, a): count = 0 na = deque() for i in range(n): print(s & 1, a[i] & 1) A = a[i] if A <= t: if s & 1: if s & 1 == A & 1: na.append(A) else: na.append(A) a = na n = len(a) for bit in range(2**n): tmp = bin(bit).count("1") if tmp <= k: ss = tt = -1 stp = 0 for i in range(n): if (bit >> i) & 1: if ss == -1 or tt == -1: ss = a[i] tt = a[i] stp += 1 else: ss &= a[i] tt |= a[i] stp += 1 if stp == tmp: break if ss == s and tt == t: count += 1 return count def main(): tmp = deque(LI()) n, k, s, t = tmp.popleft(), tmp.popleft(), tmp.popleft(), tmp.popleft() a = deque(LI()) print(solve(n, k, s, t, a)) return if __name__ == "__main__": main()
Statement Given are N pairwise distinct non-negative integers A_1,A_2,\ldots,A_N. Find the number of ways to choose a set of between 1 and K numbers (inclusive) from the given numbers so that the following two conditions are satisfied: * The bitwise AND of the chosen numbers is S. * The bitwise OR of the chosen numbers is T.
[{"input": "3 3 0 3\n 1 2 3", "output": "2\n \n\nThe conditions are satisfied when we choose \\\\{1,2\\\\} or \\\\{1,2,3\\\\}.\n\n* * *"}, {"input": "5 3 1 7\n 3 4 9 1 5", "output": "2\n \n\n* * *"}, {"input": "5 4 0 15\n 3 4 9 1 5", "output": "3"}]
Print the answer. * * *
s927342392
Wrong Answer
p02649
Input is given from Standard Input in the following format: N K S T A_1 A_2 ... A_N
N, K, S, T = map(int, input().split()) A = list(map(int, input().split())) bin_str = format(S, '08b') c = 0 for l in range(2**N): binstr_l = format(l, '050b') lnum = 0 for i in range(50): if binstr_l[i] == 1: lnum += 1 if lnum > K: break a = 2**18-1 o = 0 for i in range(N): if(binstr_l[50-1 - i] == '1'): a = a & A[i] o = o | A[i] if a == S and o == T: c += 1 print(c)
Statement Given are N pairwise distinct non-negative integers A_1,A_2,\ldots,A_N. Find the number of ways to choose a set of between 1 and K numbers (inclusive) from the given numbers so that the following two conditions are satisfied: * The bitwise AND of the chosen numbers is S. * The bitwise OR of the chosen numbers is T.
[{"input": "3 3 0 3\n 1 2 3", "output": "2\n \n\nThe conditions are satisfied when we choose \\\\{1,2\\\\} or \\\\{1,2,3\\\\}.\n\n* * *"}, {"input": "5 3 1 7\n 3 4 9 1 5", "output": "2\n \n\n* * *"}, {"input": "5 4 0 15\n 3 4 9 1 5", "output": "3"}]
Print the answer. * * *
s092338523
Wrong Answer
p02649
Input is given from Standard Input in the following format: N K S T A_1 A_2 ... A_N
N, K, S, T = list(map(int, input().split())) A = list(map(int, input().split())) if S & T != S: print(0) exit() cond = [] for n in range(N): if S & A[n] == S and ~T & A[n] == 0: cond.append(A[n])
Statement Given are N pairwise distinct non-negative integers A_1,A_2,\ldots,A_N. Find the number of ways to choose a set of between 1 and K numbers (inclusive) from the given numbers so that the following two conditions are satisfied: * The bitwise AND of the chosen numbers is S. * The bitwise OR of the chosen numbers is T.
[{"input": "3 3 0 3\n 1 2 3", "output": "2\n \n\nThe conditions are satisfied when we choose \\\\{1,2\\\\} or \\\\{1,2,3\\\\}.\n\n* * *"}, {"input": "5 3 1 7\n 3 4 9 1 5", "output": "2\n \n\n* * *"}, {"input": "5 4 0 15\n 3 4 9 1 5", "output": "3"}]
Print the answer. * * *
s620083791
Runtime Error
p02649
Input is given from Standard Input in the following format: N K S T A_1 A_2 ... A_N
a, v = map(int, input().split()) b, w = map(int, input().split()) t = int(input()) x = a - b y = abs(x) if v * t >= (y + w * t): print("YES") else: print("NO")
Statement Given are N pairwise distinct non-negative integers A_1,A_2,\ldots,A_N. Find the number of ways to choose a set of between 1 and K numbers (inclusive) from the given numbers so that the following two conditions are satisfied: * The bitwise AND of the chosen numbers is S. * The bitwise OR of the chosen numbers is T.
[{"input": "3 3 0 3\n 1 2 3", "output": "2\n \n\nThe conditions are satisfied when we choose \\\\{1,2\\\\} or \\\\{1,2,3\\\\}.\n\n* * *"}, {"input": "5 3 1 7\n 3 4 9 1 5", "output": "2\n \n\n* * *"}, {"input": "5 4 0 15\n 3 4 9 1 5", "output": "3"}]
Print the answer. * * *
s114953176
Wrong Answer
p02649
Input is given from Standard Input in the following format: N K S T A_1 A_2 ... A_N
1
Statement Given are N pairwise distinct non-negative integers A_1,A_2,\ldots,A_N. Find the number of ways to choose a set of between 1 and K numbers (inclusive) from the given numbers so that the following two conditions are satisfied: * The bitwise AND of the chosen numbers is S. * The bitwise OR of the chosen numbers is T.
[{"input": "3 3 0 3\n 1 2 3", "output": "2\n \n\nThe conditions are satisfied when we choose \\\\{1,2\\\\} or \\\\{1,2,3\\\\}.\n\n* * *"}, {"input": "5 3 1 7\n 3 4 9 1 5", "output": "2\n \n\n* * *"}, {"input": "5 4 0 15\n 3 4 9 1 5", "output": "3"}]
If it is impossible to assign directions to satisfy the requirement, print -1. Otherwise, print an assignment of directions that satisfies the requirement, in the following format: C_1 D_1 : C_M D_M Here each pair (C_i, D_i) means that there is an edge directed from Vertex C_i to Vertex D_i. The edges may be printed in any order. * * *
s275323351
Runtime Error
p02976
Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M
class Bridge: def __init__(self, nodeA, nodeB): self.edges = [nodeA, nodeB] def another(self, node): return self.edges[1 if node == self.edges[0] else 0] class Node: def __init__(self, id): self.id = id self._bridges = [] self.parent = None def addEdge(self, bridgeEdge): self._bridges.append(bridgeEdge) def bridges(self): return ((self, br.another(self)) for br in self._bridges) def __repr__(self): return str((self.id, None if self.parent is None else self.parent.node.id)) N, M = map(int, input().split()) nodes = [Node(i) for i in range(N + 1)] bridges = [] for A, B in (map(int, input().split()) for _ in range(N)): bridges.append(Bridge(nodes[A], nodes[B]))
Statement You are given a simple connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the i-th edge connects Vertex A_i and Vertex B_i. Takahashi will assign one of the two possible directions to each of the edges in the graph to make a directed graph. Determine if it is possible to make a directed graph with an even number of edges going out from every vertex. If the answer is yes, construct one such graph.
[{"input": "4 4\n 1 2\n 2 3\n 3 4\n 4 1", "output": "1 2\n 1 4\n 3 2\n 3 4\n \n\nAfter this assignment of directions, Vertex 1 and 3 will each have two\noutgoing edges, and Vertex 2 and 4 will each have zero outgoing edges.\n\n* * *"}, {"input": "5 5\n 1 2\n 2 3\n 3 4\n 2 5\n 4 5", "output": "-1"}]
If it is impossible to assign directions to satisfy the requirement, print -1. Otherwise, print an assignment of directions that satisfies the requirement, in the following format: C_1 D_1 : C_M D_M Here each pair (C_i, D_i) means that there is an edge directed from Vertex C_i to Vertex D_i. The edges may be printed in any order. * * *
s654598953
Accepted
p02976
Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M
def b_even_degrees(N, M, Edges): """ N頂点M辺の単純連結無向グラフが与えられる。 それのすべての辺に向きをつけ、任意の頂点から出る辺の本数も偶数となるような 有向グラフを作れるか判定し、可能なら1つ構成せよ。 すべての辺はどこかの頂点から出なければならないので、辺の数が奇数だと作れない。 偶数の場合は必ず構成できる。 ・適当な根付き全域木を取り、残りの辺を適当に向き付ける ・木の頂点vとその親を結ぶ辺の向きを決めるときは、vの出次数が偶数になるようにする これで、根以外の出次数は偶数になっており、根の出次数は、全体の出次数の 和が偶数であることから偶数である。 """ # 参考: https://atcoder.jp/contests/agc035/submissions/6392673 if M % 2 == 1: return -1 import sys sys.setrecursionlimit(10**6) # 以下、1-basedとする graph = [[] for _ in range(N + 1)] for a, b in Edges: graph[a].append(b) graph[b].append(a) def make_spanning_tree(current, ret=None, is_visit=None): if ret is None: ret = [set() for _ in range(N + 1)] # ret[v]: 頂点vの子の集合 if is_visit is None: is_visit = [False] * (N + 1) is_visit[current] = True for next_vertex in graph[current]: if is_visit[next_vertex]: continue ret[current].add(next_vertex) is_visit[next_vertex] = True ret = make_spanning_tree(next_vertex, ret, is_visit) return ret # 全域木の構成 root_vertex = 1 spanning_tree = make_spanning_tree(root_vertex) # 出次数の計算 outdegree = [0] * (N + 1) ans = [] # 全域木に使わなかった辺は a -> b となるように向きをつける for a, b in Edges: if a not in spanning_tree[b] and b not in spanning_tree[a]: ans.append((a, b)) outdegree[a] += 1 def dfs(current): # 全域木の current - child を結ぶ辺に向きをつける # 葉から考えれば、出次数の帳尻を合わせるように辺の向きを決めればよくなる for child in spanning_tree[current]: if spanning_tree[child]: dfs(child) # currentが葉でない場合 if outdegree[child] % 2 == 0: ans.append((current, child)) outdegree[current] += 1 else: ans.append((child, current)) outdegree[child] += 1 dfs(root_vertex) ans.sort() # 本質的にはいらない return "\n".join(" ".join(map(str, row)) for row in ans) N, M = [int(i) for i in input().split()] Edges = [[int(i) for i in input().split()] for j in range(M)] print(b_even_degrees(N, M, Edges))
Statement You are given a simple connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the i-th edge connects Vertex A_i and Vertex B_i. Takahashi will assign one of the two possible directions to each of the edges in the graph to make a directed graph. Determine if it is possible to make a directed graph with an even number of edges going out from every vertex. If the answer is yes, construct one such graph.
[{"input": "4 4\n 1 2\n 2 3\n 3 4\n 4 1", "output": "1 2\n 1 4\n 3 2\n 3 4\n \n\nAfter this assignment of directions, Vertex 1 and 3 will each have two\noutgoing edges, and Vertex 2 and 4 will each have zero outgoing edges.\n\n* * *"}, {"input": "5 5\n 1 2\n 2 3\n 3 4\n 2 5\n 4 5", "output": "-1"}]
If it is impossible to assign directions to satisfy the requirement, print -1. Otherwise, print an assignment of directions that satisfies the requirement, in the following format: C_1 D_1 : C_M D_M Here each pair (C_i, D_i) means that there is an edge directed from Vertex C_i to Vertex D_i. The edges may be printed in any order. * * *
s205003580
Accepted
p02976
Input is given from Standard Input in the following format: N M A_1 B_1 : A_M B_M
from heapq import heappush, heappop N, M = map(int, input().split()) A, B = zip(*(map(int, input().split()) for _ in range(M))) if M else ((), ()) class UnionFindTree: def __init__(self, n): self.p = [i for i in range(n + 1)] self.r = [1 for _ in range(n + 1)] def find(self, x): if self.p[x] != x: self.p[x] = self.find(self.p[x]) return self.p[x] def union(self, x, y): px = self.find(x) py = self.find(y) if self.r[px] < self.r[py]: self.r[py] += self.r[px] self.p[px] = py else: self.r[px] += self.r[py] self.p[py] = px def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return self.r[self.find(x)] # Mが奇数ならば構築不可 # Mが偶数ならば適当に木を構築し、深さの大きい頂点を端点とする辺から向きを決めていく utf = UnionFindTree(N) T = [{} for _ in range(N + 1)] for a, b in zip(A, B): if not utf.same(a, b): T[a][b] = 1 T[b][a] = 1 utf.union(a, b) INF = 10**9 def dijkstra(G, s): dp = [INF for _ in range(len(G))] q = [] heappush(q, (0, s)) while q: c, i = heappop(q) if dp[i] == INF: dp[i] = c for j, w in G[i].items(): heappush(q, (c + w, j)) return dp r = dijkstra(T, 1) p = [0, 1] + [min(T[i], key=lambda j: r[j]) for i in range(2, N + 1)] dp = [0 for _ in range(N + 1)] for a, b in zip(A, B): if b not in T[a]: dp[a] += 1 for i in sorted(range(1, N + 1), key=lambda j: r[j], reverse=True): dp[i] += sum((dp[j] + 1) % 2 for j in T[i] if j != p[i]) ans = ( -1 if M % 2 == 1 else "\n".join( ( "{} {}".format(a, b) if b not in T[a] or (dp[a] % 2 == 1 and p[a] == b or dp[b] % 2 == 0 and p[b] == a) else "{} {}".format(b, a) ) for a, b in zip(A, B) ) ) print(ans)
Statement You are given a simple connected undirected graph with N vertices and M edges. The vertices are numbered 1 to N, and the i-th edge connects Vertex A_i and Vertex B_i. Takahashi will assign one of the two possible directions to each of the edges in the graph to make a directed graph. Determine if it is possible to make a directed graph with an even number of edges going out from every vertex. If the answer is yes, construct one such graph.
[{"input": "4 4\n 1 2\n 2 3\n 3 4\n 4 1", "output": "1 2\n 1 4\n 3 2\n 3 4\n \n\nAfter this assignment of directions, Vertex 1 and 3 will each have two\noutgoing edges, and Vertex 2 and 4 will each have zero outgoing edges.\n\n* * *"}, {"input": "5 5\n 1 2\n 2 3\n 3 4\n 2 5\n 4 5", "output": "-1"}]
Print the sum of the numbers of the connected parts for all possible ways to make the remaining N-K pairs. * * *
s076639415
Wrong Answer
p03234
Input is given from Standard Input in the following format: N K A_1 B_1 A_2 B_2 : A_K B_K
import sys import socket if socket.gethostname() in ["N551J", "F551C"]: sys.stdin = open("d1.in") def read_int_list(): return list(map(int, input().split())) def read_int(): return int(input()) def read_str_list(): return input().split() def read_str(): return input() def solve(): N, K = read_int_list() n = 2 * N rows = [read_int_list() for i in range(K)] a = [] b = [] if rows: a, b = map(list, zip(*rows)) a = [x - 1 for x in a] b = [x - 1 for x in b] M = 10**9 + 7 g = [0] * (n + 1) g[0] = 1 for x in range(2, n + 1, 2): g[x] = (x - 1) * g[x - 2] x = [[0] * n for i in range(n)] y = [[0] * n for i in range(n)] ok = [[True] * n for i in range(n)] for i in range(n): for j in range(i + 1, n): for l in range(K): inside = (i <= a[l] <= j) + (i <= b[l] <= j) outside = 2 - inside ok[i][j] &= inside == 2 or outside == 2 x[i][j] += inside y[i][j] += outside dp = [[0] * n for i in range(n)] for k in range(1, n): for i in range(n): j = i + k if j < n: if ok[i][j]: rem_x = j - i + 1 - x[i][j] rem_y = n - j + i - 1 - y[i][j] dp[i][j] += g[rem_x] * g[rem_y] dp[i][j] %= M for l in range(i + 1, j): rem_z = l - i + 1 - x[i][l] dp[i][j] -= dp[i][l] * g[rem_z] * g[rem_y] dp[i][j] %= M # print() # for i in range(n): # print(*dp[i], sep='\t') # print() res = 0 for i in range(n): for j in range(i + 1, n): res += dp[i][j] res %= M return res def main(): res = solve() print(res) if __name__ == "__main__": main()
Statement There are 2N points evenly spaced on the circumference of a circle. These points are numbered 1 to 2N in clockwise order, starting from some of them. Snuke will divide these points into N pairs, then for each pair, he will draw a line segment connecting the two points. After the line segments are drawn, two points are _connected_ when one can reach from one of those points to the other by traveling only on the line segments. _The number of the connected parts_ here is the number of the connected components in the graph with 2N vertices, corresponding to the 2N points, where every pair of vertices corresponding to two connected points is connected with an edge. Snuke has already decided K of the pairs, and the i-th of them is a pair of Point A_i and Point B_i. He is thinking of trying all possible ways to make the remaining N-K pairs and counting the number of the connected parts for each of those ways. Find the sum of those numbers of the connected parts. As the answer can be extremely large, compute the sum modulo 10^9+7.
[{"input": "2 0", "output": "5\n \n\nThere are three ways to draw line segments, as shown below, and the number of\nthe connected parts for these ways are 2, 2 and 1, respectively. Thus, the\nanswer is 2+2+1=5.\n\n![](https://img.atcoder.jp/agc028/b5dcbaf5c8caf26b4e7e4915954565f7.png)\n\n* * *"}, {"input": "4 2\n 5 2\n 6 1", "output": "6\n \n\n* * *"}, {"input": "20 10\n 10 18\n 11 17\n 14 7\n 4 6\n 30 28\n 19 24\n 29 22\n 25 32\n 38 34\n 36 39", "output": "27087418"}]
Print the sum of the numbers of the connected parts for all possible ways to make the remaining N-K pairs. * * *
s619824101
Wrong Answer
p03234
Input is given from Standard Input in the following format: N K A_1 B_1 A_2 B_2 : A_K B_K
print(5)
Statement There are 2N points evenly spaced on the circumference of a circle. These points are numbered 1 to 2N in clockwise order, starting from some of them. Snuke will divide these points into N pairs, then for each pair, he will draw a line segment connecting the two points. After the line segments are drawn, two points are _connected_ when one can reach from one of those points to the other by traveling only on the line segments. _The number of the connected parts_ here is the number of the connected components in the graph with 2N vertices, corresponding to the 2N points, where every pair of vertices corresponding to two connected points is connected with an edge. Snuke has already decided K of the pairs, and the i-th of them is a pair of Point A_i and Point B_i. He is thinking of trying all possible ways to make the remaining N-K pairs and counting the number of the connected parts for each of those ways. Find the sum of those numbers of the connected parts. As the answer can be extremely large, compute the sum modulo 10^9+7.
[{"input": "2 0", "output": "5\n \n\nThere are three ways to draw line segments, as shown below, and the number of\nthe connected parts for these ways are 2, 2 and 1, respectively. Thus, the\nanswer is 2+2+1=5.\n\n![](https://img.atcoder.jp/agc028/b5dcbaf5c8caf26b4e7e4915954565f7.png)\n\n* * *"}, {"input": "4 2\n 5 2\n 6 1", "output": "6\n \n\n* * *"}, {"input": "20 10\n 10 18\n 11 17\n 14 7\n 4 6\n 30 28\n 19 24\n 29 22\n 25 32\n 38 34\n 36 39", "output": "27087418"}]
Print the K-th smallest integer in the array after the N operations. * * *
s129883444
Accepted
p03721
Input is given from Standard Input in the following format: N K a_1 b_1 : a_N b_N
import sys from sys import exit from collections import deque from bisect import ( bisect_left, bisect_right, insort_left, insort_right, ) # func(リスト,値) from heapq import heapify, heappop, heappush from itertools import product, permutations, combinations, combinations_with_replacement from functools import reduce from math import sin, cos, tan, asin, acos, atan, degrees, radians sys.setrecursionlimit(10**6) INF = 10**20 eps = 1.0e-20 MOD = 10**9 + 7 def lcm(x, y): return x * y // gcd(x, y) def lgcd(l): return reduce(gcd, l) def llcm(l): return reduce(lcm, l) def powmod(n, i, mod): return pow(n, mod - 1 + i, mod) if i < 0 else pow(n, i, mod) def div2(x): return x.bit_length() def div10(x): return len(str(x)) - (x == 0) def perm(n, mod=None): ans = 1 for i in range(1, n + 1): ans *= i if mod != None: ans %= mod return ans def intput(): return int(input()) def mint(): return map(int, input().split()) def lint(): return list(map(int, input().split())) def ilint(): return int(input()), list(map(int, input().split())) def judge(x, l=["Yes", "No"]): print(l[0] if x else l[1]) def lprint(l, sep="\n"): for x in l: print(x, end=sep) def ston(c, c0="a"): return ord(c) - ord(c0) def ntos(x, c0="a"): return chr(x + ord(c0)) class counter(dict): def __init__(self, *args): super().__init__(args) def add(self, x, d=1): self.setdefault(x, 0) self[x] += d class comb: def __init__(self, n, mod=None): self.l = [1] self.n = n self.mod = mod def get(self, k): l, n, mod = self.l, self.n, self.mod k = n - k if k > n // 2 else k while len(l) <= k: i = len(l) l.append( l[i - 1] * (n + 1 - i) // i if mod == None else (l[i - 1] * (n + 1 - i) * powmod(i, -1, mod)) % mod ) return l[k] N, K = mint() C = counter() for _ in range(N): a, b = mint() C.add(a, b) L = [] for k in C: L.append([k, C[k]]) L.sort(key=lambda x: x[0]) tmp = 0 for l in L: tmp += l[1] if tmp >= K: print(l[0]) exit()
Statement There is an empty array. The following N operations will be performed to insert integers into the array. In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array. Find the K-th smallest integer in the array after the N operations. For example, the 4-th smallest integer in the array \\{1,2,2,3,3,3\\} is 3.
[{"input": "3 4\n 1 1\n 2 2\n 3 3", "output": "3\n \n\nThe resulting array is the same as the one in the problem statement.\n\n* * *"}, {"input": "10 500000\n 1 100000\n 1 100000\n 1 100000\n 1 100000\n 1 100000\n 100000 100000\n 100000 100000\n 100000 100000\n 100000 100000\n 100000 100000", "output": "1"}]
Print the K-th smallest integer in the array after the N operations. * * *
s364868637
Wrong Answer
p03721
Input is given from Standard Input in the following format: N K a_1 b_1 : a_N b_N
# # abc061 c # import sys from io import StringIO import unittest class TestClass(unittest.TestCase): def assertIO(self, input, output): stdout, stdin = sys.stdout, sys.stdin sys.stdout, sys.stdin = StringIO(), StringIO(input) resolve() sys.stdout.seek(0) out = sys.stdout.read()[:-1] sys.stdout, sys.stdin = stdout, stdin self.assertEqual(out, output) def test_入力例_1(self): input = """3 4 1 1 2 2 3 3""" output = """3""" self.assertIO(input, output) def test_入力例_2(self): input = """10 500000 1 100000 1 100000 1 100000 1 100000 1 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000""" output = """1""" self.assertIO(input, output) def resolve(): N, K = map(int, input().split()) D = [list(map(int, input().split())) for _ in range(N)] t = 0 for d in D: t += d[1] if t >= K: print(d[0]) break if __name__ == "__main__": # unittest.main() resolve()
Statement There is an empty array. The following N operations will be performed to insert integers into the array. In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array. Find the K-th smallest integer in the array after the N operations. For example, the 4-th smallest integer in the array \\{1,2,2,3,3,3\\} is 3.
[{"input": "3 4\n 1 1\n 2 2\n 3 3", "output": "3\n \n\nThe resulting array is the same as the one in the problem statement.\n\n* * *"}, {"input": "10 500000\n 1 100000\n 1 100000\n 1 100000\n 1 100000\n 1 100000\n 100000 100000\n 100000 100000\n 100000 100000\n 100000 100000\n 100000 100000", "output": "1"}]
Print the K-th smallest integer in the array after the N operations. * * *
s369049480
Wrong Answer
p03721
Input is given from Standard Input in the following format: N K a_1 b_1 : a_N b_N
import math import sys def getinputdata(): # 配列初期化 array_result = [] data = input() array_result.append(data.split(" ")) flg = 1 try: while flg: data = input() array_temp = [] if data != "": array_result.append(data.split(" ")) flg = 1 else: flg = 0 finally: return array_result arr_data = getinputdata() # 回数 n = int(arr_data[0][0]) # 番目 k = int(arr_data[0][1]) s = "" mysum = 0 for i in range(1, 1 + n): cnt = int(arr_data[i][1]) j = arr_data[i][0] # print(mysum) if k <= mysum + cnt: # arr=[j]*cnt # print(k,mysum,arr) print(j) break else: mysum += cnt
Statement There is an empty array. The following N operations will be performed to insert integers into the array. In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array. Find the K-th smallest integer in the array after the N operations. For example, the 4-th smallest integer in the array \\{1,2,2,3,3,3\\} is 3.
[{"input": "3 4\n 1 1\n 2 2\n 3 3", "output": "3\n \n\nThe resulting array is the same as the one in the problem statement.\n\n* * *"}, {"input": "10 500000\n 1 100000\n 1 100000\n 1 100000\n 1 100000\n 1 100000\n 100000 100000\n 100000 100000\n 100000 100000\n 100000 100000\n 100000 100000", "output": "1"}]
Print the K-th smallest integer in the array after the N operations. * * *
s809654166
Runtime Error
p03721
Input is given from Standard Input in the following format: N K a_1 b_1 : a_N b_N
from sys rl=sys.stdin.readline def main(): n,k=map(int,rl.strip().split()) ints=[list(map(int,rl.strip().split())) for _ in range(n)] ints.sort(key=lambda e:e[0]) s=0 for e in ints: s+=e[1] if s<=k: print(e[0]) break if __name__=='__main__': main()
Statement There is an empty array. The following N operations will be performed to insert integers into the array. In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array. Find the K-th smallest integer in the array after the N operations. For example, the 4-th smallest integer in the array \\{1,2,2,3,3,3\\} is 3.
[{"input": "3 4\n 1 1\n 2 2\n 3 3", "output": "3\n \n\nThe resulting array is the same as the one in the problem statement.\n\n* * *"}, {"input": "10 500000\n 1 100000\n 1 100000\n 1 100000\n 1 100000\n 1 100000\n 100000 100000\n 100000 100000\n 100000 100000\n 100000 100000\n 100000 100000", "output": "1"}]
Print the K-th smallest integer in the array after the N operations. * * *
s001975083
Runtime Error
p03721
Input is given from Standard Input in the following format: N K a_1 b_1 : a_N b_N
import sys N,K=map(int, input().split()) p=[] for i in range (0,N): r=list(map(int, input().split() )) p.append(r) p.sort() k=0 for i in range(0,N): k+=p[i][0]] if k>=K: print(p[i][1]) sys.exit() import sys N,K=map(int, input().split()) p=[] for i in range (0,N): r=list(map(int, input().split() )) p.append(r) p.sort() k=0 for i in range(0,N): k+=p[i][1] if k>=K: print(p[i][0]) sys.exit()
Statement There is an empty array. The following N operations will be performed to insert integers into the array. In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array. Find the K-th smallest integer in the array after the N operations. For example, the 4-th smallest integer in the array \\{1,2,2,3,3,3\\} is 3.
[{"input": "3 4\n 1 1\n 2 2\n 3 3", "output": "3\n \n\nThe resulting array is the same as the one in the problem statement.\n\n* * *"}, {"input": "10 500000\n 1 100000\n 1 100000\n 1 100000\n 1 100000\n 1 100000\n 100000 100000\n 100000 100000\n 100000 100000\n 100000 100000\n 100000 100000", "output": "1"}]
Print the K-th smallest integer in the array after the N operations. * * *
s303882344
Runtime Error
p03721
Input is given from Standard Input in the following format: N K a_1 b_1 : a_N b_N
N, K = map(int,input().split()) AB = sorted([[list(map(int,input().split())) for _ in range(N)]]) cnt = 0 for a, b in AB: if(cnt < K - b) cnt += b else: print(a) break
Statement There is an empty array. The following N operations will be performed to insert integers into the array. In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array. Find the K-th smallest integer in the array after the N operations. For example, the 4-th smallest integer in the array \\{1,2,2,3,3,3\\} is 3.
[{"input": "3 4\n 1 1\n 2 2\n 3 3", "output": "3\n \n\nThe resulting array is the same as the one in the problem statement.\n\n* * *"}, {"input": "10 500000\n 1 100000\n 1 100000\n 1 100000\n 1 100000\n 1 100000\n 100000 100000\n 100000 100000\n 100000 100000\n 100000 100000\n 100000 100000", "output": "1"}]
Print the K-th smallest integer in the array after the N operations. * * *
s752748103
Wrong Answer
p03721
Input is given from Standard Input in the following format: N K a_1 b_1 : a_N b_N
N, K = (int(T) for T in input().split()) Now = 0 for TN in range(0, N): Num, Count = (int(T) for T in input().split()) if Now < K <= Now + Count: print(Num) break else: Now += Count
Statement There is an empty array. The following N operations will be performed to insert integers into the array. In the i-th operation (1≤i≤N), b_i copies of an integer a_i are inserted into the array. Find the K-th smallest integer in the array after the N operations. For example, the 4-th smallest integer in the array \\{1,2,2,3,3,3\\} is 3.
[{"input": "3 4\n 1 1\n 2 2\n 3 3", "output": "3\n \n\nThe resulting array is the same as the one in the problem statement.\n\n* * *"}, {"input": "10 500000\n 1 100000\n 1 100000\n 1 100000\n 1 100000\n 1 100000\n 100000 100000\n 100000 100000\n 100000 100000\n 100000 100000\n 100000 100000", "output": "1"}]