akhauriyash/Code-Regression huggingface dataset:
#include<iostream>

using namespace std;

int N, Y;

int main() {
    cin >> N >> Y;
    Y /= 1000;
    int a = Y - N;
    int b = 5 * N - Y;
    bool ng = true;
    if (a % 4 == (4 - b % 4) % 4) {
        int x = (max((-b + 4) / 5, 0) + 3 - a % 4) / 4 * 4 + a % 4;
        if (x <= a / 9) {
            ng = false;
            cout << x << " " << (a-9*x)/4 << " " << (b+5*x)/4 << endl;
        }
    }
    if (ng) cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 256
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord
import qualified Data.IntSet as IS


r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

rp :: IO (Int,Int)
rp  = toTup . unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

toTup [a,b] = (a,b)



main :: IO ()
main = do
    n <- readLn :: IO Int
    xs <- r n
    let ps = U.fromList [1..100] 
    let mx = U.map (\p -> U.sum (U.map  (\x -> (x-p)^2) xs )
                ) ps
    print $ U.minimum mx




Measured memory_bytes: 508
using System;
using System.Collections.Generic;
using System.Linq;

class Program {
    static int ReadInt() { return int.Parse(Console.ReadLine()); }
    static int[] ReadInts() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    static string[] ReadStrings() { return Console.ReadLine().Split(); }

    static bool Match(int p, string s, string t) {
        if (p < 0 || p + t.Length > s.Length) return false;

        for (int i = 0; i < t.Length; i++) {
            if (s[p + i] != t[i])
                return false;
        }
        return true;
    }

    static bool Calc(string s) {
        var dream = "dream";
        var dreamer = "dreamer";
        var erase = "erase";
        var eraser = "eraser";

        int p = s.Length-1;
        while (p >= 0) {
            if (s[p] == 'r') {
                if (Match(p - dreamer.Length + 1, s, dreamer)) {
                    p -= dreamer.Length;
                }
                else if (Match(p - eraser.Length + 1, s, eraser)) {
                    p -= eraser.Length;
                }
                else return false;
            }
            else if (s[p] == 'e') {
                if (Match(p - erase.Length + 1, s, erase)) {
                    p -= erase.Length;
                }
                else return false;
            }
            else if (s[p] == 'm') {
                if (Match(p - dream.Length + 1, s, dream)) {
                    p -= dream.Length;
                }
                else return false;
            }
            else return false;
        }
        return true;
    }

    static void Main() {
        var s = Console.ReadLine();

        if (Calc(s))
            Console.WriteLine("YES");
        else
            Console.WriteLine("NO");
    }
}

Measured memory_bytes: 3032
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;

int main(){
    vector<int> A(3);
    for(int i=0 ; i<3 ; i++){
        cin>>A[i];
    }
    sort(A.begin(),A.end());

    cout<<A[2]-A[1]+(A[1]-A[0])<<endl;    
    
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;

int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    int max_count = 0;
    for (int i = 1; i < N; i++){
        string front;
        string back;
        front = S.substr(0, i);
        back = S.substr(i, N-i);
        set<char> front_set;
        set<char> back_set;
        for (int j = 0; j < i; j++){
            front_set.insert(front.at(j));
        }
        for (int j = 0; j < N - i; j++){
            back_set.insert(back.at(j));
        }
        int count = 0;
        for (char c : front_set){
            if (back_set.count(c)){
                count++;
            }
        }
        max_count = max(max_count, count);
    }
    cout << max_count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

void dfs(vector<vector<ll>> &e,vector<ll> &dist,vector<ll> &in,int k,vector<bool> &vis){
  vis[k] = true;
  for(ll i=0;i<e[k].size();i++){
    dist[e[k][i]] = max(dist[e[k][i]],dist[k]+1);
    if(!vis[e[k][i]]){
      in[e[k][i]]--;
      if(in[e[k][i]] == 0) dfs(e,dist,in,e[k][i],vis);
    }
  }
}

int main(){
  ll n,m;
  cin >> n >> m;
  vector<vector<ll>> e(n+1);
  vector<ll> in(n+1);
  for(ll i=0;i<m;i++){
    ll x,y;cin >> x >> y;
    e[x].push_back(y);
    in[y]++;
  }
  vector<ll> dist(n+1,-1);
  vector<bool> vis(n+1,false);
  for(ll i=1;i<=n;i++){
    if(!vis[i] && in[i]==0) {
      dist[i] = 0;
      dfs(e,dist,in,i,vis);
    }
  }
  ll ans = -1;
  for(ll i=1;i<=n;i++) ans = max(ans,dist[i]);
  cout << ans << endl;
  cin.get();cin.get();
}


Measured memory_bytes: 15104
#include<bits/stdc++.h>
using namespace std;
int K,T;
priority_queue<int> q;
int main(){  
  cin >> K >> T;
  for(int i=0;i<T;i++){
    int a; cin >> a; q.push( a );
  }
  int res = 0;
  while( !q.empty() ){
    int p = q.top(); q.pop();
    if( !q.empty() ) {
      int s = q.top(); q.pop();
      p--; s--;
      if( p ) q.push( p );
      if( s ) q.push( s );
    } else {
      p--;
      if( p ) {        
        res+=p;
        p = 0;
      }
      if( p ) q.push( p );
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int i,j,n,m,box[100][100],box1[100],sum=0;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
    {
        for(j=0;j<m;j++)
        {
            scanf("%d",&box[i][j]);
        }
    }
    for(i=0;i<m;i++)
        {
            scanf("%d",&box1[i]);
        }
        for(i=0;i<n;i++)
        {
            sum=0;
            for(j=0;j<m;j++)
            {
                sum+=box[i][j]*box1[j];
            }
            printf("%d\n",sum);
        }
    return 0;
}


Measured memory_bytes: 2100
#include<vector>
#include<iostream>
#include<numeric>
#include<list>
#include<limits>
#include<algorithm>
#include<cmath>
#include<unordered_map>
#include<unordered_set>

#define pi 3.141592653589793
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define pb push_back
#define FP(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)
#define FS(i, a, b, k) for(__typeof(a) i = a;i > b;i -= k)
#define IT(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)

using namespace std;
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector< pair<int, int> > VPII;
typedef vector< pair<int, PII > > VPPI;

const long MOD = 10e9 + 7;
const long INF = 10e9 ;

template <typename T>
std::ostream& operator<<(ostream& os, 
                        const vector<T> &v)
{
    for (T const& i: v) {
        os << i << " ";
    }
    os<<endl;
    return os;
}

template<class T> inline T gcd(T x, T y) { if (!y) return x; return gcd(y, x%y);}
vector<int> sieve(int n){
    vector<bool> s(n, true);
    for(int i =2 ; i*i <= n; i++ )
        if(s[i])
            for(int j=2*i; j< n; j +=i )
                s[j] = false;

    vector<int> primes;
    for(int i =0; i<n; i++)
        if( s[i] )
            primes.push_back(s[i]);

    return primes;
}

int main(){
    int t;
    cin>>t;
    cout<< 2 * 3.1415 * t;

    return 0;
}

Measured memory_bytes: 3216
#include <iostream>
using namespace std;

int main(){
    int A[9];

    for(int i=0; i<9; i++){
        cin >> A[i];
    }

    int N;
    cin >> N;
    int b[N];

    for(int i=0; i<N; i++){
        cin >> b[i];
    }

    for(int i=0; i<N; i++){
        for(int j=0; j<9; j++){
            if(b[i] == A[j]){
                A[j] = 0;
            }
        }
    }

    if(A[0] == 0 && A[1] == 0 && A[2] == 0){
        cout << "Yes" << endl;
    }else if(A[3] == 0 && A[4] == 0 && A[5] == 0){
        cout << "Yes" << endl;
    }else if(A[6] == 0 && A[7] == 0 && A[8] == 0){
        cout << "Yes" << endl;
    }else if(A[0] == 0 && A[3] == 0 && A[6] == 0){
        cout << "Yes" << endl;
    }else if(A[1] == 0 && A[4] == 0 && A[7] == 0){
        cout << "Yes" << endl;
    }else if(A[2] == 0 && A[5] == 0 && A[8] == 0){
        cout << "Yes" << endl;
    }else if(A[0] == 0 && A[4] == 0 && A[8] == 0){
        cout << "Yes" << endl;
    }else if(A[2] == 0 && A[4] == 0 && A[6] == 0){
        cout << "Yes" << endl;
    }else{
        cout <<"No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
using namespace std;
int main(){
	char aaa[4];
	cin >> aaa;
	if(!strcmp(aaa,"ARC")){
			cout << "ABC";
	}
	if(!strcmp(aaa,"ABC")){
			cout << "ARC";
	}
	return 0;
}




Measured memory_bytes: 3600
#A
S = input()
S_unique = list(set(S))
flg = len(S_unique)==2
if flg:
    ans1 =(S.count(S_unique[0])==2)
    ans2 =(S.count(S_unique[1])==2)
    ans3 = ans1 and ans2
    if ans3:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define loop(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;
using ll = int64_t;

int main(){
    int k, a, b; cin >> k >> a >> b;
    loop(i, a, b+1){
        if(i % k == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;

    return 0;
}

Measured memory_bytes: 3636
N,K = map(int,input().split())
p = list(map(int,input().split()))
 
for i in range(N):
    p[i] = (p[i]+1)/2
a = [0]*(N-K+1)
f = sum(p[:K])
a[0] = f

for i in range(N-K):
    f = f + p[i+K] - p[i]
    a[i+1] = f

print(max(a))

Measured memory_bytes: 25060
import sys
from collections import Counter

sys.setrecursionlimit(10 ** 7)

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(input())
S = [input() for _ in range(N)]

C = Counter(S)

print("AC x {}".format(C["AC"]))
print("WA x {}".format(C["WA"]))
print("TLE x {}".format(C["TLE"]))
print("RE x {}".format(C["RE"]))


Measured memory_bytes: 16480
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(a);i<=(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(b);i>=(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
ll sum(const T& a){return accumulate(all(a),0LL);}

void solve(){
    string s,p;cin>>s>>p;
    s=s+s;
    cout<<(s.find(p)!=string::npos?"Yes":"No")<<endl;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    solve();
}



Measured memory_bytes: 3212
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
ll t;


int main()
{
    ll a,b,c,d,e,f,i,j;
    cin>>a>>b;
    if(a<b)
    {
        c=a;
        d=b;
    }
    else
    {
        c=b;d=a;
    }
    for(i=0;i<d;i++)cout<<c;
    cout<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Numerics;

namespace AtCoderWorkspace
{
    public class Solver
    {
        public void Solve()
        {
            var cin = new Scanner();
            var n = cin.nextInt();
            var k = cin.nextInt();
            var a = cin.ArrayLong(n);
            Array.Sort(a);
            var ans = a.Take(k).Sum();
            Console.WriteLine(ans);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return next();
            i = 0;
            return s[i++];
        }

        public int nextInt()
        {
            return int.Parse(next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt() + add;
            }
            return Array;
        }

        public int[] DPArrayInt(int N, int ex)
        {
            int[] Array = new int[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextInt();
            }
            return Array;
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong() + add;
            }
            return Array;
        }

        public long[] DPArrayLong(int N, int ex)
        {
            long[] Array = new long[N + ex];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextLong();
            }
            return Array;
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = nextDouble() + add;
            }
            return Array;
        }
    }

    class Program
    {
        static void Main(string[] s) => new Solver().Solve();
    }
}


Measured memory_bytes: 28412
//#pragma  GCC optimize("Ofast")

//#ifdef  DEBUG
//#define _GLIBCXX_DEBUG
//#endif

// -Ofast
// -O3
// -O2
// -fsanitize=address
// -fsanitize=undefined

// add_compile_options()

#include <iostream>
#include <map>
#include <vector>
#include <set>
#include <stack>
#include <bitset>
#include <queue>
#include <algorithm>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#include <iomanip>
#include <unordered_map>
#include <cmath>
#include <cassert>
#include <random>
using namespace std;
//using namesparsace __gnu_pbds;

mt19937 rnd;

void solve();

int main()
{
    srand(time(0));
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif
    solve();
    return 0;
}

#define int long long

int max(int a, int b) {
    return a > b ? a : b;
}

const int maxN = 2e5 + 10, inf = 2e18;

int n, k, a[maxN], e, g, u;

int cnt(int b) {
    int res = 0;
    for (int i = 0; i < e; i++) {
        int l = e + g - 1, r = n;
        while (l + 1 < r) {
            int m = (r + l) / 2;
            if (a[i] * a[m] <= b) {
                r = m;
            } else {
                l = m;
            }
        }
        res += n - r;
    }
    if (b >= 0) res += (g * (n - g)) + (g * (g - 1)) / 2;
    for (int i = e - 1; i >= 0; i--) {
        int l = -1, r = i;
        while (l + 1 < r) {
            int m = (r + l) / 2;
            if (a[i] * a[m] <= b) r = m;
            else l = m;
        }
        res += i - r;
    }
    for (int i = e + g; i < n; i++) {
        int l = i, r = n;
        while (l + 1 < r) {
            int m = (r + l) / 2;
            if (a[i] * a[m] <= b) l = m;
            else r = m;
        }
        res += l - i;
    }
    return res;
}

void solve() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] < 0) e++;
        if (a[i] == 0) g++;
        if (a[i] > 0) u++;
    }
    sort(a, a + n);
    int l = -inf, r = inf;
    while (l + 1 < r) {
        int m = (r + l) / 2;
        if (cnt(m) >= k) r = m;
        else l = m;
    }
    cout << r << endl;
}

Measured memory_bytes: 1792
//============================================================================
//Everyone has a different way of thinking, so God Created us
//   Hope You Respect My Way..,Thank You ):
// Author      : Murad
// Name        : Codeforces.cpp & Atcoder.cpp
// Description : Problem name
//============================================================================
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define ULL unsigned long long
#define MP make_pair
#define ff first
#define ss second
#define INF 1e9 + 1
#define _INF INT32_MIN
#define PQ priority_queue
#define MM multimap
#define PF pop_front
#define PP pop_back
#define PB push_back
#define vii vector<int>
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define MAXN 100004
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
char alphz[27] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
float Euclidean(LL x1, LL x2, LL y1, LL y2) {
	return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}
LL gcd(LL a,LL b) {
	LL c;
	while (a != 0) {
		c = a;
		a = b % a;
		b = c;
	}
	return b;
}
int LCM(int a, int b) {
	return (a*b) / gcd(a, b);
}
void PrimeFactor(LL n)
{
	while (n % 2 == 0) {
		printf("%d ", 2);
		n /= 2;
	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		if (n%i == 0) {
			printf("%d ", i);
			n /= i;
		}
	}
	if (n > 2)printf("%d ", n);
}
bool is_square(LL x) {
	LL l = 0, r = x;
	while (l <= r) {
		LL mid = l + (r - l) / 2;
		if (mid*mid == x)return true;
		if (mid*mid > x)r = mid - 1;
		else l = mid + 1;
	}
	return false;
}
bool is_Prime(int x) {
	if (x == 2)return 1;
	else if (x % 2 == 0 || x < 2)return 0;
	for (int i = 3; i*i <= x; i += 2)
		if (x%i == 0)return 0;
	return 1;
}
int main()
{
	El3zba;
	/***  بسم الله الرحمن الرحيم   ***/
	int n, m, q;
	cin >> n >> m >> q;
	vector<int>a(n, m);
	for (int i = 0; i < q; i++)
	{
		int x;
		cin >> x;
		x--;
		a[x]++;
	}
	for (int i = 0; i < n; i++) {
		if (a[i] <= q)
			cout << "No\n";
		else cout << "Yes\n";
	}
	return 0;
}

Measured memory_bytes: 1024
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;

//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    bool can=false;
    int N;cin >>N;
    for (int i=0; 4*i<=N; i++)
    {
        if ((N - 4*i)%7 == 0)
        {
            can = true;
            break;
        }
    }
    cout << (can ? "Yes" : "No") << endl;
  
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
import java.util.HashMap;
class Main
{
	public static void main(String args[])
	{
		HashMap<Character, String> codeMap = new HashMap<Character, String>();
		codeMap.put(' ', "101");
		codeMap.put('\'', "000000");
		codeMap.put(',', "000011");
		codeMap.put('-', "10010001");
		codeMap.put('.', "010001");
		codeMap.put('?', "000001");
		codeMap.put('A', "100101");
		codeMap.put('B', "10011010");
		codeMap.put('C', "0101");
		codeMap.put('D', "0001");
		codeMap.put('E', "110");
		codeMap.put('F', "01001");
		codeMap.put('G', "10011011");
		codeMap.put('H', "010000");
		codeMap.put('I', "0111");
		codeMap.put('J', "10011000");
		codeMap.put('K', "0110");
		codeMap.put('L', "00100");
		codeMap.put('M', "10011001");
		codeMap.put('N', "10011110");
		codeMap.put('O', "00101");
		codeMap.put('P', "111");
		codeMap.put('Q', "10011111");
		codeMap.put('R', "1000");
		codeMap.put('S', "00110");
		codeMap.put('T', "00111");
		codeMap.put('U', "10011100");
		codeMap.put('V', "10011101");
		codeMap.put('W', "000010");
		codeMap.put('X', "10010010");
		codeMap.put('Y', "10010011");
		codeMap.put('Z', "10010000");
		HashMap<String, Character> charMap = new HashMap<String, Character>();
		charMap.put("00000", 'A');
		charMap.put("00001", 'B');
		charMap.put("00010", 'C');
		charMap.put("00011", 'D');
		charMap.put("00100", 'E');
		charMap.put("00101", 'F');
		charMap.put("00110", 'G');
		charMap.put("00111", 'H');
		charMap.put("01000", 'I');
		charMap.put("01001", 'J');
		charMap.put("01010", 'K');
		charMap.put("01011", 'L');
		charMap.put("01100", 'M');
		charMap.put("01101", 'N');
		charMap.put("01110", 'O');
		charMap.put("01111", 'P');
		charMap.put("10000", 'Q');
		charMap.put("10001", 'R');
		charMap.put("10010", 'S');
		charMap.put("10011", 'T');
		charMap.put("10100", 'U');
		charMap.put("10101", 'V');
		charMap.put("10110", 'W');
		charMap.put("10111", 'X');
		charMap.put("11000", 'Y');
		charMap.put("11001", 'Z');
		charMap.put("11010", ' ');
		charMap.put("11011", '.');
		charMap.put("11100", ',');
		charMap.put("11101", '-');
		charMap.put("11110", '\'');
		charMap.put("11111", '?');
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext())
		{
			String str = sc.nextLine();
			int length = str.length();
			StringBuffer codeBuf = new StringBuffer();
			for (int i = 0; i < length; i++)
			{
				codeBuf.append(codeMap.get(str.charAt(i)));
			}
			while (codeBuf.length() % 5 != 0)
			{
				codeBuf.append('0');
			}
			length = codeBuf.length();
			for (int i = 0; i < length; i += 5)
			{
				System.out.print(charMap.get(codeBuf.substring(i, i + 5)));
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 12000
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		SC sc = new SC(System.in);
		long r=sc.nextLong();
		long D=sc.nextLong();
		long x=sc.nextLong();

		for(int i=1; i<=10; i++) {
			long ans=r*x-D;
			pl(ans);
			x=ans;
		}
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}

Measured memory_bytes: 21076
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
vector<vector<ll>> nikou_table(ll n){
    vector<vector<ll>> mat(n+1, vector<ll> (n+1));
    for(int i=0; i<=n; i++){
        for(int j=0; j<=i; j++){
            if(j==0 || j==i) mat[i][j] = 1;
            else mat[i][j] = mat[i-1][j-1]+mat[i-1][j];
        }
    }
    return mat;
}

int main(){
    int n,a,b;
    cin>>n>>a>>b;
    vector<long double> v(n);
    for(int i=0; i<n; i++) cin>>v[i];
    sort(v.begin(),v.end(),greater<>());
    long double avg=0.0;
    map<ll,int> used;
    for(int i=0; i<a; i++){
        avg+=v[i];
        used[v[i]]++;
    }
    avg/=a;
    cout<<fixed<<setprecision(15)<<avg<<endl;
    
    //0~aまでが同じ数の場合
    //v[a]からv[j]までが同じとき、組み合わせは？
    //aからjまで同じなので、jCi(a<=i<=j)でできそう

    //同じ数でなかったら平均値となる集合の要素と同じものがあればいいので、これはできる
    for(int i=0; i<n; i++){
        //cout<<i<<" "<<v[i]<<endl;
    }
    if(v[0]==v[a-1]){
        ll ans=0;
        bool ok=true;
        int j=b;
        for(int i=a-1; i<n; i++){
            if(v[i]!=v[i+1]){
                j=i+1;
                break;
            }else j=i+1;
        }
        vector<vector<ll>> c=nikou_table(j);
        for(int i=a; i<=b; i++){
            //cout<<ans<<endl;
            if(i>j) continue;
            ans+=c[j][i];
        }
        cout<<ans<<endl;
    }else{
        ll ans = 1;
        map<ll,int> m,m2;
        for(int i=0; i<a; i++){
            m[v[i]]++;
        }
        for(int i=0; i<n; i++){
            m2[v[i]]++;
        }
        for(auto i:m){
            vector<vector<ll>> c=nikou_table(m2[i.first]+i.second);
            ans *= c[m2[i.first]][i.second];
            //cout<<m2[i.first]<<" ";
        }
        cout<<ans<<endl;
    }

}

Measured memory_bytes: 256
n = int(input())
a = list()
for i in range(n):
    x, y = input().split()
    y = int(y)
    if x == "S":
        a.append(y + 0)
    if x == "H":
        a.append(y + 13)
    if x == "C":
        a.append(y + 26)
    if x == "D":
        a.append(y + 39)
for i in range(1, 53):
    if not (i in a):
        if i <= 13:
            print("S {}".format(i - 0))
        elif i <= 26:
            print("H {}".format(i - 13))
        elif i <= 39:
            print("C {}".format(i - 26))
        else:
            print("D {}".format(i - 39))


Measured memory_bytes: 5596
#include<stdio.h>
int main(void){
    int A,B;
    scanf("%d %d",&A,&B);
    int x=A*B;
    if((1<=A&&A<=9)&&(1<=B&&B<=9)){
        printf("%d\n",x);
    }else if((A<1||9<A)||(B<1||9<B)){
        printf("-1\n");
    }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;

signed main(){
	int n;
	cin>>n;
	int a=n;
	cout<<(a)*(a-1)/2<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main(){
  int n, k;
  cin >> n >> k;
  vector<int> p(n), c(n);
  rep(i, n) cin >> p[i];
  rep(i, n) cin >> c[i];
  rep(i, n) p[i]--;
  ll ans = -1e18;
  rep(si, n){
    int x = si;
    vector<int> s;
    ll tot = 0;
    while (1){
      x = p[x];
      s.push_back(c[x]);
      tot += c[x];
      if (x == si) break;
    }
    int l = s.size();
    ll t = 0;
    rep(i, l){
      t += s[i];
      if (i+1 > k) break;
      ll now = t;
      if (tot > 0){
        ll e = (k - (i + 1)) / l;
        now += tot * e;
      }
      ans = max(ans, now);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;

int N,Q;
vector<int> G[200005];
vector<long long> c(200005, 0), ans(200005, 0);

//dfs
void dfs(int from, int now, long long score){
    score += c[now];
    ans[now] = score;

    for(auto to:G[now]){
        if(to!=from){
            dfs(now, to, score);
        }
    }
}

int main(){
    cin >> N >> Q;

    for(int i=0; i<N-1; ++i){
        int a,b; cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a); // 親子関係
    }

    for(int i=0; i<Q; ++i){
        int p,x; cin >> p >> x;
        c[p]+=x;
    }

    dfs(-1, 1, 0);

    for(int i=1; i<=N; ++i){
        if(i > 1) cout  << ' ';
        cout << ans[i];
    }
    cout << endl;

}

Measured memory_bytes: 25856
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<climits>
#include<cstdlib>
#include<map>
#include<math.h>
#include<utility>
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  if(a<=8 && b<=8){
    cout << "Yay!" << endl;
  }else{
    cout << ":(" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX = 200000;
int main()
{
  int n,i;
  int x[N_MAX],y[N_MAX];
  cin >> n;
  for(i=0;i<n;i++){
    cin >> x[i];
    y[i]=x[i];
  }
  sort(x,x+n);
  for(i=0;i<n;i++){
    if(y[i]<=x[n/2-1])
      cout << x[n/2] << endl;
    else
      cout << x[n/2-1] << endl;
  }
  return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>

using namespace std;

int main() {

string s;
cin >> s;
if(s[0] == 'S')
{
    if(s[1] == 'A')
       cout << 1 ;
    else
      cout << 7;
}

else if(s[0] == 'M')
{
    cout << 6 ;
}

else if(s[0] == 'T')
{
    if(s[1] == 'U')
      cout << 5;
    else
      cout << 3;
}
else  if(s[0] == 'W')
{
    cout << 4;
}

else
  cout << 2;

}

Measured memory_bytes: 256
n = int(input())
line = list(map(int,input().split( )))
s = list(set(line))

if n%3==0 and 0 in line and line.count(0)==n//3 and len(s)<=2:
    print('Yes')
elif  n%3==0 and len(s)==3 and s[0]^s[1]==s[2] and s[1]^s[2]==s[0] and line.count(s[0])==n//3 and line.count(s[1])==n//3:
    print('Yes')
elif s == [0]:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 14708
#include <iostream>
 
using namespace std;
 
int main()
{
	int n;
	cin >> n;
	
	int result = 0; 
	for(int i = 0; i <= n; ++i) { 
		if(0 < i && i < 10) {
			result++;
			continue;
		}
		if(100 <= i && i < 1000) {
			result++;
			continue;
		}
		if(10000 <= i && i < 100000) {
			result++;
			continue;
		}
	}
	cout << result << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ll       long long
#define DS       pair<ll, ll>
#define READ(f)  freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

const int N = 3e5 + 5;
const int MOD = 1e9 + 7;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

double maxvolume(double s) {
    double length = s / 3.0;
    s -= length;
    double breadth = s / 2;
    double height = s - breadth;
    return length * breadth * height;
}

int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    int n;
    cin >> n;
    cout << fixed << setprecision(10) << maxvolume(n) << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int N=5e5+10;
int n,f[N],la[N];
char s[N];
int main(){
	scanf("%d%s",&n,s+1);
	for (int i=1;i<=n;++i){
		f[i]=f[i-1];
		if (s[i]=='1'){
			la[i]=s[i-1]=='1'?la[i-1]:i;
			if (la[i]>2&&s[la[i]-2]=='1'){
				int la1=la[i]-2;
				f[i]=max(f[i],f[la1-1]+i-la[i]+1);
				f[i]=max(f[i],f[la[la1]-1]+la1-la[la1]+1);
				f[i]=max(f[i],f[la[la1]]+la1-la[la1]);
			}
		}
	}
	printf("%d",f[n]);
	return 0;
}

Measured memory_bytes: 4608
#include<cstdio>
#include<vector>
using namespace std;

int n;
vector<int> p;
int sosu[500000];
int main(){
  sosu[1]=1;
  for(int i=2;i<400000;i++){
    if(sosu[i]==1) continue;
    for(int j=i*2;j<400000;j+=i)
      sosu[j]=1;
  }
  for(int i=2;i<400000;i++){
    if(!sosu[i]) p.push_back(i);
  }
  while(1){
    scanf("%d",&n);
    if(n==0) break;
    int res=0;
    //    printf("%d\n",p[0]);
    for(int i=0;i<n;i++) res+=p[i];
    printf("%d\n",res);
  }
}

Measured memory_bytes: 2856
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <random>
#include <tuple>
#include <cstdint>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;


int main() {
    int n; cin >> n;
    vector<int> p(n); rep(i, n) cin >> p[i];
    vector<P> a(n);

    map<int, int> mp;
    rep(i, n) mp[p[i]] = i;
    sort(p.rbegin(), p.rend());
    
    multiset<int> s;
    s.insert(-1);
    s.insert(-1);
    s.insert(n);
    s.insert(n);
    
    ll ans = 0;

    rep(i, n) {
        auto itr = s.insert(mp[p[i]]);
        int mid = mp[p[i]];
        itr++;
        int r1 = *itr;
        itr++;
        int r2 = *itr;
        itr--; itr--; itr--;
        int l1 = *itr;
        itr--;
        int l2 = *itr;
        ans += (ll)(r2 - r1) * (ll)(mid - l1) * (ll)p[i];
        ans += (ll)(r1 - mid) * (ll)(l1 - l2) * (ll)p[i];
    }

    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;

int main() {
  int N; cin >> N;
  vector<int> A(N), B(N), C(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  for (int i = 0; i < N; i++) cin >> B.at(i);
  for (int i = 0; i < N; i++) cin >> C.at(i);
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());
  long long ans = 0;
  for (int i = 0; i < N; i++) {
    int b = B.at(i);
    long long bindex = lower_bound(A.begin(), A.end(), b) - A.begin();
    long long c_tmp = upper_bound(C.begin(), C.end(), b) - C.begin();
    long long cindex = N - c_tmp;
    ans += bindex * cindex;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
	   if(x%i==0)return false;
   }return true;
}
bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline ll read() {
	char c = getchar(); ll w = 1; ll x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}
void fl(){
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		  dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
vector<ll> A,B;
int main(){
	fast;
	string s;
	cin>>s;
	ll a=0,b=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='0')a++;
		else b++;
	}cout<<2*min(a,b)<<endl;
}/*『你强归你强，我永不示弱』*/




Measured memory_bytes: 512
def main():
    N = int(input())
    A = list(map(int, input().split()))
    while len(A) > 1:
        m = min(A)
        A = [a % m for a in A if a % m != 0]
        A.append((m))

    print(m)


if __name__ == "__main__":
    main()

Measured memory_bytes: 14252
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int k;
    cin >> k;
    if (k % 2 == 0) {
        cout << (k / 2) * (k / 2) << endl;
    }
    else {
        cout << (k / 2) * ((k / 2)+ 1) << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

 class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n=in.nextInt();
        int k=in.nextInt();
        int count=0;
        for(int i=0;i<n;i++){
            int t =in.nextInt();
            if(t>=k)
                count++;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 48764
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<int> a(m + 1), mask(m + 1, 0);
  for (int i = 1; i <= m; i++) {
    int k;
    scanf("%d %d", &a[i], &k);
    for (int j = 0; j < k; j++) {
      int b;
      scanf("%d", &b);
      mask[i] |= 1 << (b - 1);
    }
  }
  vector<vector<int>> dp(m + 1, vector<int> (1 << n, 1e9));
  dp[0][(1 << n) - 1] = 0;
  for (int i = 1; i <= m; i++) {
    for (int j = 0; j < (1 << n); j++) {
      dp[i][j] = min(dp[i - 1][j], a[i] + dp[i - 1][mask[i] | j]);
    }
  }
  if (dp[m][0] >= 1e9) {
    dp[m][0] = -1;
  }
  printf("%d\n", dp[m][0]);
  return 0;
}



Measured memory_bytes: 16384
using System;

public class Test
{
	public static void Main()
	{
		string line = System.Console.ReadLine();
   		string[] ab = line.Split(' ');
   		int [] ar = new int[3];
   		ar[0] = Convert.ToInt32(ab[0]);
   		ar[1] = Convert.ToInt32(ab[1]);
   		ar[2] = Convert.ToInt32(ab[2]);
   		Array.Sort(ar);
   		Console.WriteLine("{0} {1} {2}",ar[0],ar[1],ar[2]);

	}
}

Measured memory_bytes: 9312
from heapq import heapify, heappop, heappush
N, M = map(int, input().split())
A = list(map(int, input().split()))
q = []
for a in A:
    q.append((a//2-a, a, 1))
heapify(q)
ans = sum(A)
for _ in range(M):
    discount, a, n = heappop(q)
    ans += discount
    if ans==0:
        break
    heappush(q, (a//2**(n+1)-a//2**n, a, n+1))
print(ans)


Measured memory_bytes: 23552
#
# abc175 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 = """6 2 4"""
        output = """2"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """7 4 3"""
        output = """1"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """10 1 2"""
        output = """8"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """1000000000000000 1000000000000000 1000000000000000"""
        output = """1000000000000000"""
        self.assertIO(input, output)


def resolve():
    X, K, D = map(int, input().split())
    s = abs(X) // D
    if K < s:
        ans = abs(X)-K*D
    else:
        if (K - s) % 2 == 0:
            ans = abs(abs(X)-s*D)
        else:
            ans = abs(abs(X)-s*D - D)
    print(ans)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16148
while True:
    a,op,b = input().split()

    A = int(a)
    B = int(b)

    if op == '?': break
    elif op == '+':
        print(A+B)
    elif op == '-':
        print(A-B)
    elif op == '*':
        print(A*B)
    elif op == '/':
        print(A//B)


Measured memory_bytes: 5596
#include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<fstream>
#include<algorithm>
using namespace std;
using ll = long long;


int main(){
    int n;
    int ans = 0;
    cin >> n;
    int x[16][16], y[16][16],a[16];
    for(int i=0;i<n;i++){
        cin >> a[i];
        for(int j=0;j<a[i];j++){
            cin >> x[i][j] >> y[i][j];
        }
    }
    for(int bit=0;bit<(1<<n);bit++){
        vector<int> p(n);
        for(int i=0;i<n;i++)    p[i]=-1;
        bool flag = true;
        for(int i=0;i<n;i++){
            if(bit & (1<<i)){
                for(int j=0;j<a[i];j++){
                    if(p[x[i][j]-1]==-1)
                        p[x[i][j]-1] = y[i][j];

                    else if(p[x[i][j]-1] != y[i][j])
                      flag = false;
                }
            }
            else{
                if(p[i]==1) flag = false;
                p[i] = 0;
            }
        }

        if(flag==true){
            int temp=0;
            for(int i=0;i<n;i++){
                if((p[i]==1||p[i]==-1) && (bit & (1<<i))) temp++;
            }
            ans = max(ans,temp);
        }
        
    }
    cout << ans << endl;
}   

Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[]) {
    int R, G, B, N;
    cin >> R >> G >> B >> N;

    int r = 0;
    int g = 0;
    int b = 0;
    int64_t ans = 0;
    for (int r = 0; r <= 3000; r++) {
        for (int g = 0; g <= 3000; g++) {
            int bm = (N - (R * r) - (G * g));
            if (bm >= 0 && bm % B == 0) {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <queue>
using namespace std;

const int maxn = 2e5 + 7;

struct Point {
	int w, b, inx;
} data[maxn];

struct Cmp {
	bool operator()(const Point &x, const Point &y) {
		return (long long)x.b * y.w > (long long)x.w * y.b; 
	}
} ;

priority_queue<Point, vector<Point>, Cmp> pq;

int anc[maxn];
int p[maxn];
int find(int x) {
	if (anc[x] == x) return x;
	return anc[x] = find(anc[x]);
}

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 2; i <= n; i++) scanf("%d", &p[i]);
	for (int i = 1; i <= n; i++) {
		int v;
		scanf("%d", &v);
		data[i] = Point{v == 0, v == 1, i};
	}
	for (int i = 1; i <= n; i++) anc[i] = i;
	for (int i = 2; i <= n; i++) 
		pq.push(data[i]);

	long long ans = 0;
	while (!pq.empty()) {
		Point u = pq.top();
		pq.pop();
		if (find(u.inx) != u.inx) continue;
		u = data[ u.inx ];

		int par = find(p[u.inx]);
		ans += (long long)data[par].b * u.w;
		
		data[par].b += u.b;
		data[par].w += u.w;
		if (par != 1) pq.push(data[par]);

		anc[u.inx] = par;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 8820
#include <bits/stdc++.h>
using namespace std;

const double X[] = { 0.25, 0.5, 1, 2 };

int64_t a[4];
pair<double, int> s[4];

int main() {
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(0);
	double n;
	int64_t ans = 0;
	cin >> a[0] >> a[1] >> a[2] >> a[3] >> n;
	for (int i = 0; i < 4; i++) s[i] = { a[i] / X[i], i };
	sort(s, s + 4);
	for (int i = 0; i < 4; i++) {
		int cnt = floor(n / X[s[i].second]);
		ans += cnt * a[s[i].second];
		n -= cnt * X[s[i].second];
	}
	cout << ans << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll P = 1e9+7;
vector<ll> dp(3000001, -1);


ll factorial(ll n){
    if(dp[n] != -1){
        return dp[n];
    }
    return (n * factorial(n-1)) % P;
}

ll power(ll base, ll exp){
    ll ret = 1;
    while(exp > 0){
        if(exp % 2 == 0){
            base *= base;
            base %= P;
            exp /= 2;
        }
        else{
            ret *= base;
            ret %= P;
            exp -= 1;
        }
    }
    return ret;
}

ll inv(ll n){
    return power(n, P-2);
}

ll combi(ll r, ll c){
    ll ret = 1;
    ret *= factorial(r+c);
    ret %= P;
    ret *= inv(factorial(r));
    ret %= P;
    ret *= inv(factorial(c));
    ret %= P;
    return ret;
}

ll getAll(ll r, ll c){
    return (combi(r+1, c+1) + P - 1) % P;
}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    dp[0] = 1;
    dp[1] = 1;
    dp[2] = 2;
    ll r1, r2, c1, c2;
    cin >> r1 >> c1 >> r2 >> c2;
    ll ret = getAll(r2, c2);
    ret += (P-getAll(r1-1, c2));
    ret %= P;
    ret += (P-getAll(r2, c1-1));
    ret %= P;
    ret += getAll(r1-1, c1-1);
    ret %= P;
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 54912
n, k = map(int, input().split())
p = list(map(int, input().split()))

x = sum(p[0:k])
ans_i = 0
ans_max = x
ans = 0

for i in range(1, n-k+1):
    x = x - p[i-1] + p[i+k-1]
    if x > ans_max:
        ans_max = x
        ans_i = i
        
for j in range(ans_i, ans_i+k):
    ans += (p[j]+1)/2
print(ans)

Measured memory_bytes: 24556
#include <stdio.h>

int main(){

  int i,j,n,q,key,count=0;
  int S[10000],T[500];

  scanf("%d",&n);

  for(i=0;i<n;i++)
    scanf("%d",&S[i]);

  scanf("%d",&q);

  for(i=0;i<q;i++)
    scanf("%d",&T[i]);

  for(i=0;i<q;i++){

    

    for(j=0;j<n;j++){

      if(T[i]==S[j]){
	count++;
	break;
    }

  }
  }

  printf("%d\n",count);

  return 0;

}

Measured memory_bytes: 2712
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define reprr(i, m, n) for (ll i = m; i < n; i++)
#define inf 2e9
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
using Graph = vector<vector<pair<ll, ll>>>;


int main()
{
    ll H, W; cin >> H >> W;
    vvll c(10, vll(10));
    rep(i, 10) rep(j, 10) cin >> c[i][j];
    vvll A(H, vll(W));
    rep(i, H) rep(j, W) cin >> A[i][j];
    rep(k, 10) rep(i, 10) rep(j, 10) c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
    ll cost = 0;
    rep(i, H) rep(j, W) if (A[i][j] != -1) cost += c[A[i][j]][1];
    cout << cost << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
using vi  = vector<int>;
using ii  = pair<int,int>;
using vii = vector<ii>;
using ll  = long long;
using ld  = long double;

typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;

#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) int((x).size())
#define REP(i, a, b) for (auto (i) = (a); (i) <= (b); (i)++)
#define PER(i, a, b) for (auto (i) = (a); (i) >= (b); (i)--)
#define ITR(i, x) for (auto (i) = (x).begin(); (i) != (x).end(); (i)++)

string to_string(string s) { return '\"' + s + '\"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A,B> p)
{ return "(" + to_string(p.F) + ", " + to_string(p.S) + ")"; }
template <typename T> string to_string(T v) {
	int f = 0; string res = "{";
	for (const auto &x: v)
		res += (f++ ? ", " : "") + to_string(x);
	return res + "}";
}
void debug_out() { cerr << "]\n"; }
template <typename T, typename... V>
void debug_out(T a, V... v)
{ cerr << to_string(a); if (sizeof...(v)) cerr << ", "; debug_out(v...); }

#ifdef LOCAL // add -DLOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = [", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif // debug(var1, var2, ...);

ll mx = 1e18;
const int mxN = 1e5;
ll a[mxN + 5];

signed main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n; cin >> n;
	ll ans = 1;
	REP(i, 0, n-1)
	{
		cin >> a[i];
		if (a[i] == 0)
			ans = 0;
	}
	if (ans != 0)
	{
		REP(i, 0, n-1)
		{
			ll x = a[i];
			if (ans == -1 or ans == 0) continue;
			if (x == 0) {ans = 0; continue;}
			if (ans <= ld(mx)/x)
				ans *= x;
			else
				ans = -1;
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 4428
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<queue>
using namespace std;
string w;

int search(char c) {
	int num = 0;
	for (int i = 0; i < w.size(); ++i) {
		if (w[i] == c) {
			++num;
		}
	}
	return num;
}

int main() {
	cin >> w;

	if (w.size() % 2 == 1) {
		cout << "No" << endl;
		return 0;
	}

	for (int i = 0; i < w.size(); ++i) {
		if (search(w[i]) % 2 == 1) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;

	cin >> w;
}

Measured memory_bytes: 256