akhauriyash/Code-Regression huggingface dataset:
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    VV dp(s.size() + 1, V(13));
    dp[0][0]=1;
    rep(i, s.size())
    {
        rep(j, 13)
        {
            if (s[i] == '?')
            {
                rep(k,10){
                    dp[i + 1][(j*10 + k) % 13] += dp[i][j];
                    if(dp[i + 1][(j*10 + k) % 13]>=MOD)dp[i + 1][(j*10 + k) % 13]-=MOD;
                }
            }
            else
            {
                dp[i + 1][(j * 10 + (s[i] - '0'))%13] += dp[i][j];
                if(dp[i + 1][(j * 10 + (s[i] - '0'))%13]>=MOD)dp[i + 1][(j * 10 + (s[i] - '0'))%13]-=MOD;
            }
        }
    }
    cout << dp[s.size()][5] << endl;
}


Measured memory_bytes: 13648
/*Saidur Rahman Sajol:The Freak*/
  /*Dept. of CSE,IUBAT(162)*/
/*---------------------------*/

#include <bits/stdc++.h>
using namespace std;

#define PI 2*acos(0.0)
#define l long long
#define ll long long 
#define ul unsigned long
#define ull unsigned long long

ull minimum(ull a,ull b){
  return (a<b)?a:b;
}
ull maximum(ull a,ull b){
  return (a>b)?a:b;
}
ull great(ull a,ull b){
	if(b==0) return a;
  return great(b,a%b);
}

int main(){
	int n;
	scanf("%d",&n);
	int s[n];
	vector<int>pb;
	for(int i=0;i<n;i++){
		scanf("%d",&s[i]);
	}
	ll sum=0;
	sort(s,s+n,greater<int>());
	for(int i=1;i<n;i++){
		sum+=abs(s[i-1]-s[i]);
	}
    printf("%lld\n",sum);
	return 0;
}


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

using namespace std;

long long a, b, c, d;

long long lcm(long long p, long long q) {
    return (p * q) / __gcd(p, q);
}

long long f(long long n) {
    return n - (n / c + n / d - n / lcm(c, d));
}

int main() {
    cin >> a >> b >> c >> d;

    cout << f(b) - f(a - 1) << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque
n=int(input())
A=list(map(int,input().split()))
A=deque(A)
l,r=0,0
for i in range(n-1):
    num_o,num_t=A[0],A[-1]
    if l+num_o>=r+num_t:
        r +=num_t
        A.pop()
    else:
        l +=num_o
        A.popleft()
print(min(r+A[0]-l,l+A[0]-r))

Measured memory_bytes: 27660
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cstring>
#include <set>
#include <map>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[] = {0, 0, 1, -1, 0};
int dx[] = {1, -1, 0, 0, 0};

string n;

int main()
{
    cin >> n;
    for(int i=0; i<n.size(); i++){
        if(n[i]=='9'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>

class Baseball{
private:
    int m_first = 0;
    int m_second = 0;
    int m_third = 0;
    int m_out = 0;
    int m_point = 0;

public:
    void isHit(){
        if(m_third == 1){
            m_third = 0;
            ++m_point;
        }
        if(m_second == 1){
            m_second = 0;
            m_third = 1;
        }
        if(m_first == 1){
            m_second = 1;
        }
        else {
            m_first = 1;
        }
    }
    void isHomerun(){
        m_point += m_first + m_second + m_third + 1;
        m_first = 0;
        m_second = 0;
        m_third = 0;
    }
    void setOut(){
        ++m_out;
    }
    int getOut(){
        return m_out;
    }
    int getPoint(){
        return m_point;
    }
};

int main(){
    int n;
    std::string event;

    std::cin >> n;
    Baseball baseball[n];
    //std::array<Baseball, n> baseball;
    for(int i = 0; i < n; ++i){
        while(baseball[i].getOut() < 3) {
            std::cin >> event;
            if (event == "HIT") {
                baseball[i].isHit();
            } else if (event == "OUT") {
                baseball[i].setOut();
            } else if (event == "HOMERUN"){
                baseball[i].isHomerun();
            }
        }
        std::cout << baseball[i].getPoint() << std::endl;
    }
}

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

int main() {
  int n;
  cin>>n;
  vector<tuple<string,int,int>> p;
  for(int i=1;i<=n;i++){
    string name;
    int score;
    cin>>name>>score;
    p.push_back(make_tuple(name,100-score,i));
  }
  
  sort(p.begin(),p.end());
  
  for(tuple<string,int,int> t:p){
    int j;
    tie(ignore,ignore,j)=t;
    cout<<j<<endl;
  }
}


Measured memory_bytes: 256
while True:
    H, W = list(map(int, input().split()))
    if H == 0 and W == 0:
        break
    else:
        num = 0
        while num < H:
            li = []
            for i in range(W):
                a = num+i
                if a%2 == 0:
                    li.append('#')
                else:
                    li.append('.')
            print(''.join(li))
            num += 1
        print()

Measured memory_bytes: 7652
N = int(input())
a = list(map(int, input().split()))
count = 0

if min(a) >= 2:
        print(-1)
        exit()

for i in range(N):
    if a[i] == 1:
        count += i
        k = i
        break

M = 2

for i in range(k+1, N):
    if a[i] != M:
        count += 1
    else:
        M+= 1
        

print(count)        

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

string M[1005];
ll T[1005][1005];
struct Node
{
    pll g;
    int c = 0;
    Node(pll g, int c) : g(g), c(c) {}
};

int x[4] = {0, 1, 0, -1};
int y[4] = {1, 0, -1, 0};

int main()
{
    int H, W;
    cin >> H >> W;
    REP(i, H)
    {
        REP(j, W)
        {
            T[i][j] = INF;
        }
    }
    queue<Node> q;
    REP(i, H)
    {
        cin >> M[i];
        REP(j, W)
        {
            if (M[i][j] == '#')
            {
                T[i][j] = 0;
                q.push(Node(pll(i, j), 0));
            }
        }
    }

    while (!q.empty())
    {
        Node t = q.front();
        q.pop();
        REP(i, 4)
        {
            int nx = t.g.first + x[i];
            int ny = t.g.second + y[i];
            ll c = t.c + 1;
            if (nx < 0 || ny < 0 || nx >= H || ny >= W)
                continue;
            if (T[nx][ny] <= c)
                continue;
            T[nx][ny] = c;
            q.push(Node(pll(nx, ny), c));
        }
    }

    ll max = 0;
    REP(i, H)
    {
        REP(j, W)
        {
            max = std::max(max, T[i][j]);
        }
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 33332
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string str;
  cin>>n>>str;
  int ans=n;
  for(int i=0;i<n-1;i++){
    if(str.at(i)==str.at(i+1)){
      ans--;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define double long double
#define INF LLONG_MAX/10000
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int a, p;
signed main() {
	cin >> a >> p;
	p += a * 3;
	cout << p / 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <iterator>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define dump(x)  cerr << #x << " = " << (x) << endl;
using namespace std;
int main(){
 int N;
 cin >> N;
 long long X[N];
 long long Xcopy[N];
 FOR(i,0,N){
   cin >> X[i];
   Xcopy[i] = X[i];
 }
 sort(Xcopy,Xcopy + N);
 dump(Xcopy[N]);
 long long pre = Xcopy[(N / 2) - 1];
 long long aft = Xcopy[(N / 2)];
 FOR(i,0,N){
   if(X[i] <= pre){
     cout << aft << endl;
   }else{
     cout << pre << endl;
   }
 }
 return 0;
}

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


long long gcd(long long x,long long y){
  long long c=max(x,y),d=min(x,y);
  if(d==0)return c;
  return gcd(d,c%d);
}

long long b(long long p,long long q){
  return p/gcd(p,q)*q;
}

int main(){
  int N;
  cin >> N;
  vector<long long> t(100);
  for(int i=0;i<N;i++){
    cin >> t[i];
  }
  long long current = t[0];
  for(int i=1;i<N;i++){
    current = b(current,t[i]);
  }
  cout << current <<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

vector<bool>a;

int main() {
	int n;
	cin>>n;
	string s,t;
	cin>>s>>t;
	for(int i=0;i<s.size();i++){
		if(s[i]==t[i]){
			a.push_back(0);
		}
		else{
			a.push_back(1);
			i++;
		}
	}
	ll ans=0;
	bool flag;
	if(a[0]==0){
		ans=3;
		flag=0;
	}
	else{
		ans=6;
		flag=1;
	}
	for(int i=1;i<a.size();i++){
		if(flag==0){
			if(a[i]==1){
				ans*=2;
				flag=1;
				continue;
			}
			else{
				flag=0;
				ans*=2;
				ans%=inf;
				continue;
			}
		}
		if(flag==1){
			if(a[i]==1){
				flag=1;
				ans*=3;
				ans%=inf;
				continue;
			}
			else{
				flag=0;
				ans*=1;
				continue;
			}
		}
	}
	cout <<ans;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#define MAX(D,S) \
  { \
    if ( (S) > (D) ) \
    { \
      (D) = (S); \
    } \
  }
#define MIN(D,S) \
  { \
    if ( (S) < (D) ) \
    { \
      (D) = (S); \
    } \
  }

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int n;

  scanf ( "%d", &n );

  while ( n-- )
  {
    int p, c;
    int m;
    int up = 0, dn = 0;

    scanf ( " %d", &m );
    for ( scanf ( " %d", &p ); --m; )
    {
      scanf ( "%d", &c );
      MAX( up, c-p );
      MIN( dn, c-p );

      p = c;
    }

    printf ( "%d %d\n", up, -dn );
  }

  return ( 0 );
}

Measured memory_bytes: 0
import collections
import numpy as np

N=int(input())
A = list(map(int, input().split()))

c=collections.Counter(A)
kazu=list(c.values())
a=np.array(kazu)
sn=a*(a-1)/2
s=sum(sn)
for k in range(N):
    sub=c[A[k]]-1
    print(int(s-sub))

Measured memory_bytes: 34136
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<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()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {

    let A: i32 = read();
    let B: i32 = read();
    println!("{}", 6 - A - B);
}


Measured memory_bytes: 4352
import java.util.*;


public class Main {
	
	Scanner cin = new Scanner(System.in);
	
	public static void main(String[] args) {
		new Main().run(); 
	}
	
	int A = 0, B = 0;
	int n;
	
	public void run() {		
		
		/*input*/
		n = cin.nextInt();
		int[] nums = new int[n];
		
		for (int i = 0; i < n; i ++) {
			nums[i] = cin.nextInt();
		}
		
		Arrays.sort(nums);
		
		if (nums[0] == nums[n - 1]) {
			System.out.println(0);
			return;
		}
		/*start*/
		
		for (int i = 0; i < n; i ++) {
			A += nums[i];
			B += nums[i] * nums[i];
		}
		
		int left = nums[0], right = nums[n - 1];
		
		
		for (int i = 0; i < 100; i ++) {
			int leftThird = (left * 2 + right) / 3;
			int rightThird = (left + right * 2) / 3;
			
			int m1 = func(leftThird);
			int m2 = func(rightThird);
			if (m1 <= m2) {
				right = rightThird;
			} else {
				left = leftThird;
			}
		}
		
		int min = Integer.MAX_VALUE;
		
		for (int  i = left; i <= right; i ++) {
			min = Math.min(min, func(i));
		}
		
		/*finish*/
		System.out.println(min);
	}
	
	public int func(int x) {
		
		return n * x * x - 2 * A * x + B; 
	}
}



Measured memory_bytes: 21972
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 998244353;

ll invmod(ll x) {
  ll sum = 1;
  ll cur = x;
  ll e = mod - 2;
  while (e > 0) {
    if (e % 2 == 1) {
      sum = sum * cur % mod;
    }
    cur = cur * cur % mod;
    e /= 2;
  }
  return sum;
}


const int N = 3100;
ll dp[N][N];

void solve_dp(int n, int m) {
  dp[1][0] = 0;
  dp[1][1] = 1;
  REP(i, 2, m + 1) {
    dp[1][i] = (dp[1][i - 1] + dp[1][i - 2]) % mod;
  }
  REP(i, 2, n + 1) {
    REP(j, 1, m + 1) {
      dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
    }
  }
  cout << dp[n][m] << endl;
}

vector<VL> mul(const vector<VL> &a, const vector<VL> &b) {
  vector<VL> res(2, VL(2));
  REP(i, 0, 2) {
    REP(j, 0, 2) {
      REP(k, 0, 2) {
	res[i][j] += a[i][k] * b[k][j];
	res[i][j] %= mod;
      }
    }
  }
  return res;
}

vector<VL> pow(const vector<VL> &a, ll e) {
  vector<VL> sum(2, VL(2));
  REP(i, 0, 2) {
    sum[i][i] = 1;
  }
  vector<VL> cur = a;
  while (e > 0) {
    if (e % 2 == 1) {
      sum = mul(sum, cur);
    }
    cur = mul(cur, cur);
    e /= 2;
  }
  return sum;
}

int main(void){
  int n;
  ll m;
  cin >> n >> m;
  // matrix
  vector<VL> a(2, VL(2, 1));
  a[0][0] = 0;
  vector<VL> a_2m_2 = pow(a, m + 2 * n - 2);
  VL binom(n - 1, 1);
  REP(i, 1, n - 1) {
    ll tmp = binom[i - 1] * ((m + i) % mod) % mod;
    tmp = tmp * invmod(i) % mod;
    binom[i] = tmp;
  }
  ll sum = a_2m_2[0][1];
  vector<VL> cur = a;
  vector<VL> a2 = mul(a, a);
  REP(i, 0, n - 1) {
    ll tmp = binom[n - 2 - i] * cur[0][1] % mod;
    sum = (sum - tmp + mod) % mod;
    cur = mul(cur, a2);
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main() {
    long long N, M;
    cin >> N >> M;
    long long arr[M];
    long long sum = 0;
    for(long long i = 0; i < M; i++){
        cin >> arr[i];
        sum += arr[i];
    }
    cout << max((long long)-1, N - sum) << endl;
    return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;
 
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define mp make_pair
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define SIZE 200010
#define mod 1000000007
#define BIG 998244353
#define s(t) scanf("%d",&t)
#define p(t) printf("%d\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi  3.1415926358
#define print(x) for(auto el: x) cout<<el<<" ";cout<<endl
#define bits(x) __builtin_popcount(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<int>
#define pqsmall priority_queue<int,vector<int>,greater<int> >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define mitr map<int,int>:: iterator
 
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
 

int32_t main()
{
    fast;
    int a;cin>>a;
    string s;cin>>s;
    if(a>=3200)
        cout<<s;
    else
        cout<<"red";
}

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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  int N;
  cin>>N;

  int t,a,b;
  string  res ="Yes";
  cin>>t>>a>>b;
  int pt,pa,pb;
  if(t<a+b) res="No";
  pt=t;
  pa=a;
  pb=b;
  FOR(i,1,N){
    cin>>t>>a>>b;
    if((t-pt-abs(a-pa)+abs(b-pb))<0) res="No";
    if((t-pt-abs(a-pa)+abs(b-pb))%2==1) res="No";
    pt=t;
    pa=a;
    pb=b;
  }
  cout<<res<<endl;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n; cin>>n;
    vector<ll> b(1000001,0),inv(1000001,0),w(1000001,0);
    inv[0]=inv[1]=1;
    for(ll i=2;i<=1000000;i++){
        inv[i]=(mod-inv[mod%i]*(mod/i))%mod;
    }
    rep(i,1000001) w[i]=inv[i];
    rep(i,n){
        ll a; cin>>a;
        b[a]++;
    }
    for(int i=1;i<=1000000;i++)for(int j=2*i;j<=1000000;j+=i){
        w[j]=(mod+w[j]-w[i])%mod;
    }
    ll ans=0,sum,cur;
    for(ll i=1;i<=1000000;i++){
        sum=cur=0;
        for(ll j=i;j<=1000000;j+=i){
            sum=(sum+b[j]*j)%mod;
            cur=(cur-j*j%mod*b[j])%mod;
        }
        ans=(ans+inv[2]*(sum*sum%mod+cur)%mod*w[i])%mod;
    }
    cout<<(mod+ans)%mod<<endl;
}


Measured memory_bytes: 26700
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

#define MOD 1000000007LL
ll dp[2][51][51][51][51];

vector<string> split(string s, string p) {
  vector<string> ret;
  ll h = 0;
  REP(i, 0, s.size() - p.size() + 1) if(s.substr(i, p.size()) == p) {
    ret.push_back(s.substr(h, i - h));
    h = i + p.size();
    i += (ll) p.size() - 1;
  }
  ret.push_back(s.substr(h, (ll) s.size() - h));
  return ret;
}

int main(void) {
  ll A, T, C, G, M;
  scanf("%lld %lld %lld %lld\n", &A, &T, &G, &C);
  scanf("%lld\n", &M);
  vector<string> S(M);
  REP(i, 0, M) getline(cin, S[i]);

  map<string, map<string, ll>> mp;

  for(ll m = M - 1; m >= 0; m--) {
    string name = split(S[m], ": ")[0];
    string body = split(S[m], ": ")[1];
    vector<string> items = split(body, " ");
    for(string s : items) {
      if(s[0] == '[') {
        string t = s.substr(1, s.length() - 2);
        sort(t.begin(), t.end());
        if(++mp[name][t] > A + T + C + G) {
          cout << 0 << endl;
          return 0;
        }
      } else {
        for(auto p : mp[s]) {
          string t = p.first;
          ll d = p.second;
          if((mp[name][t] += d) > A + T + C + G) {
            cout << 0 << endl;
            return 0;
          }
        }
      }
    }
  }

  ll cur = 0, nxt = 1;
  REP(a, 0, A + 1) REP(t, 0, T + 1) REP(c, 0, C + 1) REP(g, 0, G + 1) dp[cur][a][t][c][g] = 0;
  dp[cur][0][0][0][0] = 1;

  string name = split(S[0], ": ")[0];
  ll cnt = 0;
  for(auto p : mp[name]) cnt += p.second;
  if(cnt > A + T + C + G) {
    cout << 0 << endl;
    return 0;
  }
  ll q = 0;
  for(auto p : mp[name]) {
    string s = p.first;
    ll x = p.second;
    for(ll k = 0; k < x; k++) {
      REP(a, 0, A + 1) REP(t, 0, T + 1) REP(c, 0, C + 1) REP(g, 0, G + 1) dp[nxt][a][t][c][g] = 0;
      REP(a, 0, A + 1) REP(t, 0, T + 1) REP(c, 0, C + 1) {
        ll g = q - a - t - c;
        if(0 <= g && g <= G) for(char ch : s) {
          if(ch == 'A' && a + 1 <= A) (dp[nxt][a + 1][t][c][g] += dp[cur][a][t][c][g]) %= MOD;
          if(ch == 'T' && t + 1 <= T) (dp[nxt][a][t + 1][c][g] += dp[cur][a][t][c][g]) %= MOD;
          if(ch == 'C' && c + 1 <= C) (dp[nxt][a][t][c + 1][g] += dp[cur][a][t][c][g]) %= MOD;
          if(ch == 'G' && g + 1 <= G) (dp[nxt][a][t][c][g + 1] += dp[cur][a][t][c][g]) %= MOD;
        }
      }
      swap(cur, nxt);
      q++;
    }
  }
  cout << dp[cur][A][T][C][G] << endl;
}


Measured memory_bytes: 107184
s = input()
start_with_a = s[0] == 'A'
contains_c = s[2:-1].count('C') == 1
all_lowercases = s.replace('A', '').replace('C', '').islower()

print('AC' if all([start_with_a, contains_c, all_lowercases]) else 'WA')

Measured memory_bytes: 9016
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
  int loop,i,a[100000];
  scanf("%d",&loop);
  for (i = 1;i <= loop ; i++){
    scanf("%d",&a[i]);
  }
  for (i = 1;i <= loop ;i++){
    printf("node %d: key = %d, ",i,a[i]);
    if(i/2 >= 1) {
      printf("parent key = %d, ",a[i/2]);
    }
    if(2*i <=loop){
      printf("left key = %d, ",a[2*i]);
    }
    if(2*i+1 <= loop){
      printf("right key = %d, ",a[2*i+1]);
    }
    printf("\n");
  }
return 0;
}

Measured memory_bytes: 608
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <vector>
typedef long long ll;
const int maxn = 1e5 + 5;
const ll mod = 1e9 + 7;
const double PI = acos(-1.0);
int n, a[20];
int x[20][20], y[20][20];
int vis[20], ans = 0;

void dfs(int u) {
  if (u == n+1) {
    int sum = 0;
    for (int i=1; i <= n; i++) {
      if (vis[i]) {
        for (int j=1; j <= a[i]; j++) {
          if (y[i][j] == 0 && vis[x[i][j]] == 1) {
            return;
          }
          if (y[i][j] == 1 && vis[x[i][j]] == 0) {
            return;
          }
        }
        sum++;
      }
    }

    ans = std::max(ans, sum);
    return;
  }

  vis[u] = 0;
  dfs(u+1);
  vis[u] = 1;
  dfs(u+1);
}

int main (int argc, char **argv) {
  std::cin >> n;
  for (int i=1; i <= n; i++) {
    std::cin >> a[i];
    for (int j=1; j <= a[i]; j++) {
      std::cin >> x[i][j] >> y[i][j];
    }
  }

  dfs(1);
  std::cout << ans << std::endl; 
  return 0;
}


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

int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++)
        cin >> A[i];

    vector<int> L(N + 1), R(N + 1);
    L[0] = 0; R[N] = 0;
    for (int i = 1; i < N + 1; i++)
        L[i] = gcd(L[i - 1], A[i - 1]);
    for (int i = N - 1; i >= 0; i--)
        R[i] = gcd(R[i + 1], A[i]);

    int res = 0;
    for (int i = 0; i < N; i++) {
        int l = L[i];
        int r = R[i + 1];
        res = max(res, gcd(l, r));
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;


public class Main{
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNextLine()){
			String line = sc.nextLine();
			Scanner scstr = new Scanner(line);
			scstr.useDelimiter(",");
			int[] stations = new int[10];
			for(int i = 0; i < 10; i++) stations[i] = scstr.nextInt();
			int v1 = scstr.nextInt();
			int v2 = scstr.nextInt();
			
			System.out.println(countFromStation1(v1, v2, stations));
			
			scstr.close();
		}
		sc.close();
	}
	static double travelerCalculation(int l, int v1, int v2) {
		return (double)l / (double)(v1 + v2) * (double)v1;
	}
	
	static int countFromStation1(int v1, int v2, int... stations) {
		int sumLength = sum(stations);
		double len_frm_st1 = travelerCalculation(sumLength, v1, v2);
		int cnt_frm_st1 = 0;
		for(int i = 0; i < stations.length; i++) {
			cnt_frm_st1 += stations[i];
			if(cnt_frm_st1 >= len_frm_st1) return i + 1;
		}
		return stations.length;
	}
	
	static int sum(int[] array) {
		int result = 0;
		for(int i: array) result += i;
		return result;
	}
}

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

int main() {
    int T , A , B , C , D , k;
    for(cin >> T ; T ; T--) {
        cin >> A >> B >> C >> D;
        k = (A + B) / (min(A , B) + 1);
        int a , b;
        auto getAB = [&] (int p) {
            a = A - p / (k + 1) * k - p % (k + 1) , 
            b = B - p / (k + 1);
        };
        int l = 0 , r = A + B , mid;
        while(l < r) {
            mid = (l + r) >> 1;
            getAB(mid);
            if(b <= (long long)a * k) l = mid + 1;
            else r = mid;
        }
        getAB(l);
        r = l + 1 + b - a * k;
        for(int i = C ; i <= D ; ++i) {
            if(i <= l) {
                if(i % (k + 1) != 0) cout << 'A';
                else cout << 'B';
            } else {
                if((i - r) % (k + 1) != 0) cout << 'B';
                else cout << 'A';
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 384
A = list(input())
B = list(input())
C = list(input())

owner = 'a'

while True:
    if owner == 'a':
        if len(A):
            owner = A[0]
            del(A[0])
        else:
            print('A')
            break
    if owner == 'b':
        if len(B):
            owner = B[0]
            del(B[0])
        else:
            print('B')
            break
    if owner == 'c':
        if len(C):
            owner = C[0]
            del(C[0])
        else:
            print('C')
            break

Measured memory_bytes: 3064
<?php 
    fscanf(STDIN, "%d %d", $n, $m);
    $list = explode(" ", trim(fgets(STDIN)));

    $total_votes = array_sum($list);
    $border = $total_votes / (4 * $m);
    $count = 0;

    foreach($list as $value) {
        if($value >= $border){
            $count += 1;
        }
    }

    if($count >= $m){
        echo 'Yes';
    } else {
        echo 'No';
    }

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

int main() {
  vector<int> abc(3);
  int K;
  for (int i=0; i<3; i++) cin >> abc.at(i);
  cin >> K;
  sort(abc.begin(), abc.end());
  int total = abc.at(0) + abc.at(1);
  for (int k=0; k < K; k++) abc.at(2) *= 2;
  cout << total + abc.at(2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
#define MP make_pair
#define vint vector<int>
#define vvint vector<vector<int>>
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int INF = 1e9;
const int MOD = 1e9+7;

int modpow(int a, int n, int mod) {
    int res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

signed main(){
    int x,y; cin >> x >> y;
    if((x+y)%3!=0) {cout<<0<<endl; return 0;}
    
    int n=(2*y-x)/3;
    int m=(2*x-y)/3;

    if(n<0 || m<0){cout<<0<<endl; return 0;}

    int res=1;
    for(int i=m+1; i<=m+n; i++){
        res*=i%MOD;
        res%=MOD;
    }
    for(int i=1; i<=n; i++){
        res*=modpow(i,MOD-2,MOD);
        res%=MOD;
    }
    cout<<res<<endl;

    
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n, k = map(int, input().split())

    def cmb(n, r, mod):
        if (r < 0) or (n < r):
            return 0
        r = min(r, n - r)
        return fact[n] * factinv[r] * factinv[n - r] % mod

    fact = [1, 1]
    factinv = [1, 1]
    inv = [0, 1]

    for i in range(2, n + 1):
        fact.append((fact[-1] * i) % mod)
        inv.append((-inv[mod % i] * (mod // i)) % mod)
        factinv.append((factinv[-1] * inv[-1]) % mod)

    for i in range(k):
        res = cmb(n - k + 1, i + 1, mod) * cmb(k - 1, i, mod)
        res %= mod
        print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3572
N = int(input())

resp = 0
if N < 10:
    resp = N
elif 10 <= N < 100:
    resp = 9
elif 100 <= N < 1000:
    a = 9
    b = N - 99
    resp = a + b
elif 1000 <= N < 10000:
    resp = 9 + (999 - 99)
elif 10000 <= N < 100000:
    a = 9
    b = 999 - 99
    c = N - 9999
    resp = a + b + c
elif 100000 <= N:
    resp = 90909

print(resp)

Measured memory_bytes: 3064
def main():
    H, W = map(int ,input().split())

    if H == 1 or W == 1:
        print(1)
        
    else:
        L1 = 0
        L2 = 0

        L1 = L2 = W // 2

        if W % 2 == 1:
            L1 += 1

        ans = (L1 + L2) * (H//2)

        if H % 2 == 1:
            ans += L1

        print(ans) 

if __name__ == "__main__":
    main()

Measured memory_bytes: 9152
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
using namespace std;
typedef long long ll;


int main() {
    int P, Q, R;
    cin>>P>>Q>>R;
    
    deque<int> v = {P, Q, R};
    sort(v.begin(), v.end());
    int min = *std::min_element(v.begin(), v.end());
    v.pop_front();
    int min2 = *std::min_element(v.begin(), v.end());
    v.pop_front();
    cout<<min+min2<<endl; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////



int main(){fastio
    ll n,m,v,p;cin>>n>>m>>v>>p;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    sort(a,a+n);
    reverse(a,a+n);
    ll sum[n];
    rep(i,0,p-2)sum[i]=0;
    rep(i,p-1,n-1){
        if(i==0)sum[i]=a[i];
        else sum[i]=sum[i-1]+a[i];
    }
    //rep(i,0,n-1)cout<<a[i]<<" ";cout<<endl;
    //rep(i,0,n-1)cout<<sum[i]<<" ";cout<<endl;
    ll ok=p-1,ng=n;
    while(abs(ok-ng)>1){
        ll mid=(ok+ng)/2;
        
        ll mp=a[mid];
        if(mp+m<a[p-1]){
            ng=mid;continue;
        }
        ll resv=v-(p-1)-(n-1-mid)-1;
        if(resv<=0){
            ok=mid;continue;
        }
        ll lef=resv*m;
        if(mid-1>=0)lef+=sum[mid-1];
        ll rig=(mp+m)*(mid-1-(p-2));
        if(lef<=rig){
            ok=mid;
        }else{
            ng=mid;
        }
    }
    cout<<ok+1<<endl;
    return 0;
}


Measured memory_bytes: 1792
from collections import Counter

N = int(input())
D = list(map(int,input().split()))
C = Counter(D)
mod = 998244353
ans = 1
D_max = max(D)

if D[0] != 0 or C[0] != 1:
    print(0)
    exit()
"""
def make_factorial_table(n):
    result = [0] * (n+1)
    result[0] = 1
    for i in range(1,n+1):
        result[i] = result[i-1] * i % mod
    return result

def nCr(n,r):
    return fact[n] * pow(fact[n-r],mod-2,mod) * pow(fact[r],mod-2,mod) % mod

fact = make_factorial_table(2*N)
"""

for i in D[1:]:
    ans *= C[i-1]
    ans %= mod
print(ans)

Measured memory_bytes: 24152
import fractions

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

a,b=map(int,input().split())
ab_gcd=fractions.gcd(a,b)
div_list=make_divisors(ab_gcd)
prime_list=[]

for i in div_list:
    flg=True
    for j in prime_list:
        if j == 1:
            continue
        if i % j == 0:
            flg = False
            break
    if flg:
        prime_list.append(i)

print(len(prime_list))

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

using namespace std;
typedef long long ll;

int main() {
   int n;
   cin >> n;
   int count = 0;
   vector<int> a(n);
   for(auto &it : a) cin >> it;
   for(int i = 0; i < n; i++){
       for(int j = 0; j < n; j++){
           for(int k = 0; k < n; k++){
               if(i < j && j < k){
                   if(a[i] == a[j]) continue;
                   if(a[j] == a[k]) continue;
                   if(a[k] == a[i]) continue;
                   if((ll)a[i] + a[j] + a[k] <= max({a[i], a[j], a[k]})*2) continue;
                   count++;
               }
           }
       }
   }
   cout << count << endl;
   



}



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

auto solve(ll N, vector<ll> W)
{
    int ans = INT_MAX;
    for(int T=1;T<N;++T)
    {
        int t1=0,t2=0;
        for(int i=0;i<T;++i)
            t1 += W[i];
        for(int i=T;i<N;++i)
            t2 += W[i];
        ans = min(ans,abs(t1-t2));
    }
    return ans;
}


int main()
{
    ll N;
    cin >> N;
    vector<ll> W(N);
    for(int i = 0 ; i < N ; i++)
    {
        cin >> W[i];
    }
    cout << solve(N, move(W)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cassert>

using namespace std;
typedef long long ll;

void write_mode(const vector<ll> arms, ll x, ll y){
    string s;

    for(ll d : arms){
        if(x > 0 && abs(x) > abs(y)){
            s.push_back('R');
            x -= d;
        }else if(x < 0 && abs(x) > abs(y)){
            s.push_back('L');
            x += d;
        }else if(y > 0 && abs(x) < abs(y)){
            s.push_back('U');
            y -= d;
        }else{
            s.push_back('D');
            y += d;
        }
    }
    assert(x == 0 && y == 0);
    assert(s.size() == arms.size());
    cout << s << endl;
}

int main(){
    ll n;
    cin >> n;
    vector<pair<ll, ll>> p(n);
    for(int i = 0; i < n; ++i){
        cin >> p.at(i).first;
        cin >> p.at(i).second;
    }

    for(auto xy : p){
        if((abs(p.at(0).first) + abs(p.at(0).second)) % 2 !=
           (abs(xy.first) + abs(xy.second)) % 2){
            cout << -1 << endl;
            return 0;
        }
    }

    bool is_even = ((abs(p.at(0).first) + abs(p.at(0).second)) % 2 == 0);
    vector<ll> arms;
    if(is_even){
        arms.push_back(1);
    }
    for(int i = 30; i >= 0; --i){
        arms.push_back(1LL << i);
    }

    cout << arms.size() << endl;
    for(int i = 0; i < arms.size(); ++i){
        cout << arms.at(i);
        if(i != arms.size() - 1){
            cout << ' ';
        }else{
            cout << endl;
        }
    }

    for(auto xy : p){
        write_mode(arms, xy.first, xy.second);
    }

    return 0;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def main():
    find=[False]*26
    orda=ord("a")
    for c in input():
        find[ord(c)-orda]=True
    for i in range(26):
        if not find[i]:
            print(chr(i+97))
            break
    else:
        print("None")
main()

Measured memory_bytes: 3220
defmodule Main do
  def main do
    [a, b] =
      IO.read(:line)
      |> String.trim
      |> String.split(" ")
    a = String.to_integer(a)
    b = String.to_integer(b)
    if a <= b do 
    IO.puts("unsafe") 
    else 
    IO.puts("safe") 
    end
  end
end

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

const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)


int main() {
  double a,b;
  cin >> a >> b;
  if (int((a+b)/2) == (a+b)/2)cout << int((a+b)/2) << endl;
  else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 3708
import java.util.Scanner;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        int s = t%60;
        int m = (t-s)/60%60;
        System.out.println((t-s-m*60)/3600 + ":" + m + ":" + s);
    }
}


Measured memory_bytes: 26340
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h, w, n,m,k; string s,t;
char maze[60][60];
int dis[101][101]; int graph[52][52]; bool vis[52];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}

int main() {
	cin >> n;
	vector<ll> d(n);
	rep(i, n) {
		cin >> d[i];
	}
	ll res = 0;
	sort(d.begin(), d.end());
	res=d[n / 2] - d[n / 2 - 1];
	cout << res << endl;
}



Measured memory_bytes: 1024
import sys
from collections import deque
readline = sys.stdin.readline

def main():
  x,y,a,b,c=map(int,readline().split())

  red=[int(i) for i in readline().split()]
  green=[int(i) for i in readline().split()]
  nc=sorted([int(i) for i in readline().split()], reverse=1)
  if a<x:
    red+=nc[:(x-a)]
    nc=nc[(x-a):]
  if b<y:
    green+=nc[:(y-b)]
    nc=nc[(y-b):]
  red=deque(sorted(red)[-x:])
  green=deque(sorted(green)[-y:])
  res=0
  
  def ppl(lst,i,t):
    if i>t:
      lst.popleft()
      return i
    else:
      return 0
    
  for i in nc:
    if (not red) and (not green):
      break
    if not red:
      tg=green[0]
      res+=ppl(green,i,tg)
    elif not green:
      tr=red[0]
      res+=ppl(red,i,tr)
    else:
      tr=red[0]
      tg=green[0]
      if tr<tg:
        res+=ppl(red,i,tr)
      else:
        res+=ppl(green,i,tg)
    
  print(res+sum(red)+sum(green))

main()

Measured memory_bytes: 22968
#include<bits/stdc++.h>
#define ll long long
#define mo 998244353
#define N 420
using namespace std;
int n,a[N],b[N],sa,sb;
ll jie[N],nj[N],dp[N][N][2],s[N][N],ans;
ll po(ll x,ll y){ll z=1;while (y){if(y%2)z=x*z%mo;x=x*x%mo;y/=2;}return z;}
void add(ll &x,ll y){x=(x+y)%mo;}
int main(){
	cin>>n;
	for (int i=1;i<=n;i++){cin>>a[i]>>b[i];sa+=a[i];sb+=b[i];}
	for (int i=1;i<=n;i++)
		for (int j=0;j<b[i];j++)s[i][j]=(mo-po(a[i]*po(sa,mo-2)%mo,j))%mo;
	jie[0]=1;for (int i=1;i<=400;i++)jie[i]=jie[i-1]*i%mo;
	nj[400]=po(jie[400],mo-2);for (int i=399;i>=0;i--)nj[i]=nj[i+1]*(i+1)%mo;
	dp[0][0][0]=1;
	for (int i=1;i<=n;i++){
		for (int j=0;j<=sa;j++){
			for (int k=0;k<=sb;k++){
				if (j+a[i]<=sa)add(dp[j+a[i]][k][1],dp[j][k][0]);
				for (int p=0;p<b[i];p++)if (k+p<=sb)add(dp[j][k+p][1],(dp[j][k][0]*nj[p]%mo)*s[i][p]);
			}
		}
		for (int j=0;j<=sa;j++)
			for (int k=0;k<=sb;k++)dp[j][k][0]=dp[j][k][1],dp[j][k][1]=0;
	}
	for (int j=0;j<sa;j++)
		for (int k=0;k<=sb;k++)
			add(ans,(dp[j][k][0]*po(po((sa-j)*po(sa,mo-2)%mo,mo-2),k+1)%mo)*jie[k]);
	cout<<(mo-ans)%mo<<endl;
	return 0;
}

Measured memory_bytes: 4224
/**
       ������������    ������������
		Author : Avi J Patel
		University : DA-IICT
       ������������    ������������
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair 
#define mt make_tuple
#define ff first
#define ss second
#define si size()
#define MOD 1000000007
#define Mod 998244353
#define N 200001
#define large 10000000000000001
#define For(i,m,n) for(long long i=m;i<n;i++)
#define st(x) sort(x.begin(),x.end())
#define re(x,i) reverse(x.begin()+i,x.end())
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    if(a.second < b.second) return true; 
    else if(a.ss==b.ss) return a.ff<b.ff;
	else return false;
}
bool sortbyboth(const pair<int,int> &a, const pair<int,int> &b)
{
	if(a.first<b.first) return true;
	else if(a.first==b.first) return a.second<b.second;
	else return false;
}
int main()
{
	int n;
	cin>>n;
	int k;
	cin>>k;
	int cnt=0;
	for(int i=0;i<n;i++){
		int a1;
		cin>>a1;
		if(a1>=k)
		cnt++;
	}
	cout<<cnt;
	return 0;
}












Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<iterator>
#include<algorithm>


using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;


class pos_t
{
public:
	int m_x, m_y, m_id;
	pos_t(int x, int y, int id):m_x(x),m_y(y),m_id(id){}
};


bool x_cmp(const pos_t&a, const pos_t&b)
{
	return a.m_x<b.m_x;
}


bool y_cmp(const pos_t&a, const pos_t&b)
{
	return a.m_y<b.m_y;
}


int main(void)
{
	int r, c, n;

	while(scanf("%d%d%d", &r, &c, &n)==3)
	{
		vector<pos_t> vl, vt, vr, vb;
		vector<pos_t> p;

//printf("r=%d  c=%d  n=%d\n", r, c, n);
		for(int i=0;i<n;i++)
		{
			int x[2], y[2];
			int is_outer=1;

			for(int j=0;j<2;j++)
			{
				scanf("%d%d", &x[j], &y[j]);
				if(x[j]!=0 && x[j]!=r && y[j]!=0 && y[j]!=c) is_outer=0;
			}
			if(!is_outer) continue;

			for(int j=0;j<2;j++)
			{
				pos_t p(x[j], y[j], i);

				if(0);
				else if(x[j]==0) vl.push_back(p);
				else if(x[j]==r) vr.push_back(p);
				else if(y[j]==0) vt.push_back(p);
				else if(y[j]==c) vb.push_back(p);
			}
		}
		sort(vt.begin(), vt.end(), x_cmp);
		sort(vb.begin(), vb.end(), x_cmp);
		reverse(vb.begin(), vb.end());
		sort(vl.begin(), vl.end(), y_cmp);
		reverse(vl.begin(), vl.end());
		sort(vr.begin(), vr.end(), y_cmp);

		copy(vt.begin(), vt.end(), back_inserter(p));
		copy(vr.begin(), vr.end(), back_inserter(p));
		copy(vb.begin(), vb.end(), back_inserter(p));
		copy(vl.begin(), vl.end(), back_inserter(p));
/*
		for(auto pe:p)
		{
			printf("x=%d  y=%d  id=%d\n", pe.m_x, pe.m_y, pe.m_id);
		}
		printf("\n");
*/
		vi stack;
		for(int i=0;i<(int)p.size();i++)
		{
			if(stack.empty() || stack.back()!=p[i].m_id)
			{
				stack.push_back(p[i].m_id);
			}
			else
			{
				stack.pop_back();
			}
		}
		printf("%s\n", !stack.size()?"YES":"NO");
	}
	return 0;
}



Measured memory_bytes: 7816
#include <stdio.h>
#include <string.h>
#define int long long
int main(void)
{
	int n,i;
	scanf("%d",&n);
	int power=1,rest=1,quo;
	fprintf(stderr,"\n");
	for(i=1;i<=n;i++)
		{
		power = rest*i;
		rest = power%1000000007;
		quo = power/1000000007;
		if(i>=n-10){fprintf(stderr,"power=%d*(10^9+7)+%d\n",quo,rest);}
		}
	printf("%d\n",rest);
	

	
	
	

	return 0;
}


Measured memory_bytes: 128
k, t = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i).sort.reverse

while a.length > 1
  a[0] -= 1
  if a[0] == 0
    a.shift
  elsif a[1]
    if a[1] > a[0]
      a << a.shift
    else
      t = a[0]
      a[0] = a[1]
      a[1] = t
    end
  end
end
puts a[0]-1



Measured memory_bytes: 1788
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = LLONG_MAX / 3;
const double eps = (1e-9);

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

  ll n, k;
  cin >> n >> k;
  map<int, int> mp;
  rep(i, n) {
    int a; cin >> a;
    mp[a]++;
  }
  if (mp.size() <= k) {
    puts("0");
    return 0;
  }

  vector<int> b;
  for (auto& p : mp) {
    b.push_back(p.second);
  }
  sort(ALL(b));
  int ans = 0;
  for (int i = 0; i < b.size() - k; i++) {
    ans += b[i];
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 10744