akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 1000000007;
int S;
int pw[15],sum[15];
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
int fpow(int x,int c) {
    int res = 1,t = x;
    while(c) {
	if(c & 1) res = mul(res,t);
	t = mul(t,t);
	c >>= 1;
    }
    return res;
}
void update(int &x,int y) {
    x = inc(x,y);
}
void Solve() {
    read(S);
    
    pw[0] = 1;
    for(int i = 1 ; i <= 8 ; ++i) {
	pw[i] = pw[i - 1] * 10;
	sum[i] = (pw[i]  - pw[i - 1]) * i;
	sum[i] += sum[i - 1];
    }
    int T = min(S,20000000);
    int ans = 0;
    for(int i = 1 ; i <= T ; ++i) {
	int a = S / i;
	if(a >= 8) {
	    if(S % i == 0) {
		update(ans,inc(inc(fpow(10,a),MOD - fpow(10,a - 1)),MOD - i + 1));
	    }
	    else {
		update(ans,1);
	    }
	}
	else break;
    } 
    for(int a = 1 ; a <= 7 ; ++a) {
	if(S < a) break;
	if(S % a == 0 && S / a <= pw[a] - pw[a - 1]) update(ans,pw[a] - pw[a - 1] - S / a + 1);
	for(int b = 1 ; b <= 7 ; ++b) {
	    if(a + b >= 9) break;
	    if(sum[a + b] - sum[a - 1] < S) continue;
	    int t = sum[a + b - 1] - sum[a];
	    if(t > S) break;
	    int rem = S - t;
	    for(int i = 1 ; i <= pw[a] - pw[a - 1] ; ++i) {
		if(i * a >= rem) break;
		if((rem - i * a) % (a + b) == 0) {
		    if((rem - (i * a)) / (a + b) <= pw[a + b] - pw[a + b - 1]) update(ans,1);
		}
	    }
	}
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N, M; cin >> N >> M;
	vector<P> ab(M);
	rep (i, M){
		int a, b; cin >> a >> b;
		ab[i].first = b;
		ab[i].second = a;
	} // end rep
	
	sort(ALL(ab));

	int res = 0;
	int x = 0;
	rep (i, M){
		if (x <= ab[i].second){
			++res;
			x = ab[i].first;
		} // end if
	} // end rep

	cout << res << endl;
	
	return 0;
}

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

int n;
ll max_diff = -1;
vector<int> ans, a, b;

ll diff(vector<int> &a, vector<int> &b) {
    ll p = 1;
    for (int i=0; i<n; ++i) p *= 10;
    ll al = 0;
    for (int t: a) (al *= 10) += t;
    ll bl = 0;
    for (int t: b) (bl *= 10) += t;
    return min(abs(al-bl), p-abs(al-bl));
}

bool used[10];

void dfs() {
    if ((int)b.size() == n) {
        ll d = diff(a, b);
        if (d > max_diff || (d == max_diff && b < ans)) {
            max_diff = d;
            ans = b;
        }
        return;
    }
    for (int i=0; i<10; ++i) {
        if (used[i]) continue;
        b.push_back(i);
        used[i] = true;
        dfs();
        b.pop_back();
        used[i] = false;
    }
}

int main() {
    string S;
    cin >> S;
    n = S.size();
    
    a.resize(n);
    for (int i=0; i<n; ++i) a[i] = S[i]-'0';
    dfs();

    for (int t: ans) cout << t;
    cout << endl;

    return 0;
}


Measured memory_bytes: 3212
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <set>
#include <algorithm>
#include<cmath>

#define rep(i, a, b) for (int i=a; i <b; i++)
#define F first
#define S second

using namespace std;

typedef long long ll;
typedef vector< int > vi;

int main() {
    int h, w;
    scanf("%d %d", &h, &w);
    vector< vector<int>> ary(h);
    for (int i=0; i<h; i++) {
        ary[i].resize(w);
    }
    for (int i = 0; i<h; i++){
        for (int j=0; j<w; j++){
            scanf("%d", &ary[i][j]);
        }
    }

    vector<int> ans(h*w*4 + 100, -1);
    int ind = 0;
    for(int i=0; i<h; i++) {
        if(i%2 == 0) {
            for(int j=0; j<w; j++) {
                if(ary[i][j] %2 == 1) {
                    if(j != w-1) {
                        ans[ind++] = i;
                        ans[ind++] = j;
                        ans[ind++] = i;
                        ans[ind++] = j+1;
                        ary[i][j+1]++;
                    } else if (i != h-1) {
                        ans[ind++] = i;
                        ans[ind++] = j;
                        ans[ind++] = i+1;
                        ans[ind++] = j;
                        ary[i+1][j]++;
                    }
                }
            }
        } else {
            for(int j=w-1; j>-1; j--) {
                if(ary[i][j] %2 == 1) {
                    if(j != 0) {
                        ans[ind++] = i;
                        ans[ind++] = j;
                        ans[ind++] = i;
                        ans[ind++] = j-1;
                        ary[i][j-1]++;                        
                    } else if (i != h-1) {
                        ans[ind++] = i;
                        ans[ind++] = j;
                        ans[ind++] = i+1;
                        ans[ind++] = j;
                        ary[i+1][j]++;
                    }
                }
            }
        }
    }
    printf("%d\n", ind/4);
    for(int i=0; i<ind/4; i++) {
        printf("%d %d %d %d\n", ans[i*4]+1, ans[i*4+1]+1, ans[i*4+2]+1, ans[i*4+3]+1);
    }
    return 0;
}

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

using ll = long long;

int main() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;

    ll ret = 0;
    ret += min(a, k);
    //cout << ret << endl;
    ret -= max((ll)0, k - min(a, k) - b);

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;

namespace AtCoder {
    class Program {
        static void Main(string[] args) {

            var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var a = input[0];
            var b = input[1];

            var d = b - a;
            var _a = Enumerable.Range(1, d - 1).Sum();
            var ans = _a - a;

            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
#include <list>
#include <cctype>

using namespace std;

#define Int int64_t

void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a * b / gcd(a, b);
}

int main() {
	string a, b, c; cin >> a >> b >> c;
	vector<string> aa, bb, cc;
	string t;
	for (int i = 0; i < a.size(); i++) {
		t = a[i];
		aa.push_back(t);
	}
	for (int i = 0; i < b.size(); i++) {
		t = b[i];
		bb.push_back(t);
	}
	for (int i = 0; i < c.size(); i++) {
		t = c[i];
		cc.push_back(t);
	}


	string turn = "a", win;


	for (int i = 0; i < 100000; i++) {
		if (turn == "a") {
			
			if (aa.size() > 0) {
				turn = aa.at(0);
				aa.erase(aa.begin());
			}
			else {
				win = "A";
				break;
			}
		}
		if (turn == "b") {
			if (bb.size() > 0) {
				turn = bb[0];
				bb.erase(bb.begin());
				//cout << "b";
			}
			else {
				win = "B";
				break;
			}
		}
		if (turn == "c") {
			if (cc.size() > 0) {
				turn = cc[0];
				cc.erase(cc.begin());
				//cout << "c";
			}
			else {
				win = "C";
				break;
			}
		}
	}
	cout << win;


	cout << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;


class Main{

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        final int[] a = new int[N];

        for ( int i = 0; i < N; i++ ){
            a[i] = sc.nextInt();
        }
        sortTheCards(N, a);
        System.out.println(dealTheCards(N, a));
    }
    private static void sortTheCards(int N, int[] a){
        Arrays.sort(a);
        
        for(int i=0;i<a.length / 2; ++i) {
            int temp = a[a.length - i - 1];
            a[a.length - i - 1] = a[i];
            a[i] = temp;
        }
    }
    private static int dealTheCards(int N, int[] a){
        int sub = 0;
        int Alice = 0;
        int Bob = 0;
        for( int i = 0; i < N; i++){
            if( i % 2 == 0 ){
                Alice += a[i];
            }else{
                Bob += a[i];                
            }
        }
        sub = Alice - Bob;
        return sub;
    }
}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amin(T& a,T b){ a=min(a,b);}
template <class T> void amax(T& a,T b){ a=max(a,b);}

int main()
{
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int k,n;
	cin >> n >>k;
	VI d(n), t(n);
	rep(i,n) cin >>t[i] >>d[i];
	vector<VI> dt(100050);
	{
		vector<pii> vp(n);
		rep(i,n) vp[i] = pii(d[i], t[i]);
		sort(vp.rbegin(), vp.rend());
		rep(i,n){
			tie(d[i], t[i])=vp[i];
			dt[t[i]].push_back(i);
		}
	}
	vector<bool> usd(100050), uss(100050);
	VI dels, tsp;
	ll cnd=0; set<int> br;
	rep(i, k){
		cnd += d[i];
		uss[t[i]] = usd[i] = 1;
		if(dt[t[i]][0] !=i) dels.push_back(i);
	}
	ll zz=0;
	rep(i,100050) zz += uss[i]==1;
	cnd += (ll)zz *zz;
	//dbg("1stcnz",cnd,zz);
	ll ans = cnd;
	sort(all(dels),[&d](int a,int b){return d[a]<d[b];});
	rep(i,100050) if(sz(dt[i])>0) tsp.push_back(dt[i][0]);
	sort(all(tsp),[&d](int a,int b){return d[a]>d[b];});
	
	int dlc=-1, adc=-1;
	while(1){
		bool ck=0;
		rep2(i, dlc+1, sz(dels)) if(usd[dels[i]]){dlc=i; ck=1; break;}
		if(!ck) break;
		ck=0;
		rep2(i, adc+1, sz(tsp))  if(usd[tsp[i]]==0 && uss[t[tsp[i]]]==0){
			adc=i; ck=1; break;
		}
		if(!ck) break;
		cnd -= d[dels[dlc]]; usd[dels[dlc]]=0;
		cnd += d[tsp[adc]]; usd[tsp[adc]] =1;
		cnd -= zz*zz;
		zz++; cnd +=zz*zz;
		//dbg(cnd,zz);
		ans = max(ans, cnd);
	}
	cout << ans <<"\n";
	return 0;
}




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

#define F first
#define S second

using namespace std;
typedef long double ld;
typedef long long ll;

const int max_n = 500011, inf = 1000111222;
const ll inff = 1000111222333444;

string s, t;
char ss[max_n];

bool is_cycle(string a, const string& b) {
    // cout << "is_cycle: " << a << ", " << b << endl;
    if (b.length() % a.length() != 0) return false;
    int i = 0;
    for (int q = 0; q < b.length(); ++q) {
        if (b[q] != a[i]) return false;
        ++i;
        if (i == a.length()) i = 0;
    }
    return true;
}

void get_p(const string& b, vector<int>& p) {
    assert(p.size() == b.length());
    if (b.empty()) return;
    p[0] = 0;
    for (int i = 1; i < p.size(); ++i) {
        int k = p[i - 1];
        while (k > 0 && b[k] != b[i]) {
            k = p[k - 1];
        }
        if (b[i] == b[k]) ++k;
        p[i] = k;
    }
}

bool is_eq_cycle(string a, string b) {
    // cout << "is_eq_cycle: " << a << ", " << b << endl;
    if (a.length() != b.length()) return false;
    b = a + "#" + b + b;
    vector<int> p(b.length());
    get_p(b, p);
	for (int i = 1; i < b.length(); ++i) {
		if (p[i] == a.length()) {
            return true;
		}
	}
	return false;
}

int get_ans(const string& a, const string& b) {
    string s = a + "#" + b + b;
    vector<int> dp(s.length()), p(s.length());
    get_p(s, p);
    int ans = 0;
    // cout << s << endl;
    // for (int i = 0; i < s.length(); ++i) cout << p[i] << " "; cout << endl;
    for (int i = a.length(); i < s.length(); ++i) {
        if (p[i] == a.length()) {
            dp[i] = dp[i - a.length()] + 1;
            ans = max(ans, dp[i]);
        }
    }
    return ans;
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%s", ss);
    s = ss;
    scanf("%s", ss);
    t = ss;
    int g = __gcd(s.length(), t.length());
    if (is_cycle(s.substr(0, g), s) && is_cycle(t.substr(0, g), t) && is_eq_cycle(s.substr(0, g), t.substr(0, g))) {
        cout << -1 << endl;
        return 0;
    }
    while (s.length() < t.length()) s = s + s;
    s = s + s;
    cout << get_ans(t, s) << endl;
    return 0;
}


Measured memory_bytes: 43572
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
const int maxn=100+10;
int V,E;
vector<int> g[maxn];
int vis[maxn];
 bool bLoop=false;
void dfs(int u)
{
    vis[u]=1;
    for(int i=0;i<g[u].size();i++)
    {
        int v=g[u][i];
        if(vis[v]==1) bLoop=true;
        if(!vis[v])
        {
            dfs(v);
        }
    }
    vis[u]=2;
}
int main(void){
//   freopen("in.txt","r",stdin);
    scanf("%d%d",&V,&E);
    int u,v;
    for(int i=0;i<E;i++)
    {
        scanf("%d%d",&u,&v);
        g[u].push_back(v);
    }
    memset(vis,0,sizeof(vis));

    for(int i=0;i<V;i++)
    {
        if(!vis[i])
        {
            dfs(i);
            if(bLoop) break;
        }
    }
    printf("%d\n",bLoop?1:0);
  return 0;
}

Measured memory_bytes: 2772
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<long> A(N+1);
  A.at(0) = 0;
  for (int i=1; i<N+1; i++) {
    long tmp;
    cin >> tmp;
    A.at(i) = A.at(i-1) + tmp;
  }

  sort(A.begin(), A.end());
  long tmp = A.at(0);
  long n = 1;
  long ans = 0;
  for (int i=1; i<N+1; i++) {
    if (A.at(i) == tmp) {
      n++;
    } else {
      ans += n*(n-1)/2;
      n = 1;
    }
    tmp = A.at(i);
  }
  ans += n*(n-1)/2;
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string Weather[3] = {"Sunny" , "Cloudy" , "Rainy"};
    string s ;
    cin >> s ;

    if (s == Weather[0] ){
        cout << "Cloudy" <<endl;

    }if (s== Weather[1]){
        cout << "Rainy"<<endl;

    }if (s == Weather[2]){
        cout << "Sunny"<< endl;
    }

    return 0;
}


Measured memory_bytes: 256
from collections import  deque

class Graph(): #directed
    def __init__(self,n,edge):
        self.n = n
        self.graph = [[] for _ in range(n)]
        self.deg = [0 for _ in range(n)]
        for e in edge:
            self.graph[e[0]-1].append(e[1]-1)
            self.deg[e[1]-1] += 1

import sys
input = sys.stdin.readline

N,M = map(int,input().split())
edge = [tuple(map(int,input().split())) for _ in range(M)]
S,T = map(lambda x: int(x)-1 ,input().split())

g = Graph(N,edge)

stack = deque([(S,0)])
used = [[False]*3 for _ in range(N)]

while stack:
    node,depth = stack.popleft()
    if node == T and depth % 3 == 0:
        print(depth//3)
        break
    for adj in g.graph[node]:
        if not used[adj][(depth+1)%3]:
            used[adj][(depth+1)%3] = True
            stack.append((adj,depth+1))
else:
    print(-1)

Measured memory_bytes: 80092
import sys
n = int(input())
s = input()
q = int(input())
k = list(map(int, sys.stdin.readline().split()))
x = []
for i in s:
  if i == "D":
    x.append(1)
  elif i == "M":
    x.append(2)
  elif i == "C":
    x.append(3)
  else:
    x.append(0)
mrui = [0]* (n+1)
for i in range(1,n+1):
  mrui[i] = mrui[i-1]
  if x[i-1] == 2:
    mrui[i] += 1
dp = [0,0,0,0]
dp1 = [0,0,0,0]
for i in k:
  dp = [1,0,0,0]
  for j in range(n):
    dp1 = dp
    kon = x[j]
    if kon:
      dp1[kon] += dp[kon-1]
    dp = dp1
    if j >= i-1:
      if x[j-i+1] == 1:
        dp[1] -= 1
        dp[2] -= (mrui[j+1]-mrui[j-i+2])
  
  print(dp1[3])

Measured memory_bytes: 95408
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  int i=0;
  int mx=0;
  int n=s.length();
  while(i<n){
    if(s[i]=='R'){
      int cnt=0;
      while(s[i]=='R' && i<n){
        cnt++;
        i++;
      }
      mx=max(mx,cnt);
    }
    if(s[i]=='S'){
      while(s[i]=='S' && i<n){
        i++;
      }
    }
  }
  cout<<mx<<endl;
  return 0;
}


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

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

const int N = 1e5 + 5;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int x;
	cin >> x;
	x %= 10;
	if(x == 3)
		cout << "bon\n";
	else if(x == 0 || x == 1 || x == 6 || x == 8)
		cout << "pon\n";
	else
		cout << "hon\n";
}


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

const int N=1e5+10;

int a[N];

int main() {
	int n;
	scanf("%d",&n);
	int mn,mx;
	mn=1e9,mx=0;
	for(int i=1;i<=n;i++) scanf("%d",&a[i]),mn=min(mn,a[i]),mx=max(mx,a[i]);
	int cnt=0;
	for(int i=1;i<=n;i++) if(a[i]==mn) cnt++;
	if(mx-mn>1) puts("No");
	else if(mn==mx&&n/mx>1) puts("Yes");
	else if(mn!=mx&&cnt+1<=mx&&mx<=cnt+(n-cnt)/2) puts("Yes");
	else if(mn==mx&&mx==n-1) puts("Yes");
	else puts("No");
}

Measured memory_bytes: 640
import collections
def comb(n):
    return n*(n-1)//2

N = int(input())
A = list(map(int, input().split()))
cnt = [0]*N
for i in range(N):
    cnt[A[i]-1] += 1

normal_cal_cnt = [0] * N
minus_cal_cnt = [0] * N
for i in range(N):
    normal_cal_cnt[i] = comb(cnt[i])
    minus_cal_cnt[i] = comb(cnt[i]-1)
ans = sum(normal_cal_cnt)
for i in range(N):
    tmp = ans
    tmp -= normal_cal_cnt[A[i]-1]
    tmp += minus_cal_cnt[A[i]-1]
    print(tmp)


Measured memory_bytes: 27036
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
typedef pair<int,int> pii;
#define fi first
#define se second
#define Sort(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/4
#define INTINF INT_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
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 MOD = 998244353;
const int MOD = 1000000007;


/*----------------------------------------------------------------*/
signed main(){


	int x,y,a,b,c;
	cin >> x >> y >> a >> b >> c;
	vll p(a),q(b),r(c);
	rep(i,a)cin >> p[i];
	rep(i,b)cin >> q[i];
	rep(i,c)cin >> r[i];

	sort(all(p),greater<int>());
	sort(all(q),greater<int>());
	sort(all(r),greater<int>());
	priority_queue<int> p2,q2,r2;
	rep(i,x)p2.push(p[i]);
	rep(i,y)q2.push(q[i]);
	rep(i,c)r2.push(r[i]);
	p2.push(-INF);
	q2.push(-INF);
	r2.push(-INF);


	int ans = 0;
	rep(i,x+y){
		int pf = p2.top();
		int qf = q2.top();
		int rf = r2.top();
		if(pf >= qf && pf >= rf){
			ans += pf;
			p2.pop();
		}else if(qf >= pf && qf >= rf){
			ans += qf;
			q2.pop();
		}else{
			ans += rf;
			r2.pop();
		}
	}
	cout << ans << endl;



	

	
	return 0;
}
/*----------------------------------------------------------------*/

// g++ -std=gnu++17 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2017-qualb.contest.atcoder.jp/tasks/code_festival_2017_qualb_b
// rm -r -f test;oj dl https://abc160.contest.atcoder.jp/tasks/abc160_e

Measured memory_bytes: 8624
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second

using namespace std;

signed main(){
    int a;
    cin>>a;
    if(a<1200)puts("ABC");
    else if(a<2800)puts("ARC");
    else puts("AGC");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define mp make_pair
#include<cstdio>
#define MAX 86400
#include<map>
#include<algorithm>
#include<cstdlib>
#include<string>
using namespace std;
typedef pair<int,int> P;
int main(){
	int n,l,a;
	char s[20];
	P table[20000];
	while(cin>>n,n){
		for(int i=0;i<n;i++){
			cin>>s;
			l=atoi(s)*3600+atoi(&s[3])*60+atoi(&s[6]);
			table[i]=P(l,1);
			cin>>s;
			a=atoi(s)*3600+atoi(&s[3])*60+atoi(&s[6]);
			table[i+n]=P(a,0);
		}
		int now=0,ans=0;
		sort(table,table+2*n);
		for(int i=0;i<2*n;i++){
			if(table[i].second)
			now++;
			else now--;
			ans=max(now,ans);
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1040
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#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() {
    ll n, t;
    cin >> n >> t;
    ll ans = 0;
    ll preti = 0;
    imfor(i, n) {
        ll ti;
        cin >> ti;
        if (i == 0) {
            if (i == n - 1) {
                ans += t;
            }
            else {
                preti = ti;
            }
        }
        else {
            ans += min(ti - preti, t);
            if (i == n - 1) {
                ans += t;
            }
            else {
                preti = ti;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>  
#include <vector>
using namespace std;
 
int main(){
  int k;
  vector<int> cor(5,0);
  for(int i=0;i<5;i++){
    cin>>cor[i];
  }
  cin>>k;
  if(cor[4]-cor[0]>k) cout<<":(";
  else cout<<"Yay!";
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node { int p, l, r; };
struct Node T[MAX];
int n;

void preParse (int u) {
    if (u == NIL) return;
    printf(" %d", u);
    preParse(T[u].l);
    preParse(T[u].r);
}

void inParse (int u) {
    if (u == NIL) return;
    inParse(T[u].l);
    printf(" %d", u);
    inParse(T[u].r);
}

void postParse (int u) {
    if (u == NIL) return;
    postParse(T[u].l);
    postParse(T[u].r);
    printf(" %d", u);
}

int main () {
    int i, v, l, r, root;

    scanf ("%d", &n);
    for (i = 0; i < n; i++) {
        T[i].p = NIL;
    }

    for (i = 0; i < n; i++) {
        scanf("%d %d %d", &v, &l, &r);
        T[v].l = l;
        T[v].r = r;
        if (l != NIL) T[l].p = v;
        if (r != NIL) T[r].p = v;
    }

    for (i = 0; i < n; i++) if (T[i].p == NIL) root = i;

    printf("Preorder\n");
    preParse(root);
    printf("\n");
    printf("Inorder\n");
    inParse(root);
    printf("\n");
    printf("Postorder\n");
    postParse(root);
    printf("\n");

    return 0;
}


Measured memory_bytes: 2104
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

vector<int> g[100100];

int c[100100],p[100100];

queue<int> q;

int main(void){
	int n,m,i,j,a,b,s=0;
	fill(c,c+100100,0);
	cin >> n >> m;
	for(i=1; i<(n+m); ++i){
		cin >> a >> b;
		--a; --b;
		++c[b];
		g[a].push_back(b);
	}
	for(i=0; i<n; ++i){
		if(!c[i]){
			p[i] = 0;
			q.push(i);
			break;
		}
	}
	while(!q.empty()){
		a = q.front();
		q.pop();
		for(i=(g[a].l_ength()-1); i>=0; --i){
			b = g[a][i];
			--c[b];
			if(!c[b]){
				p[b] = (a+1);
				q.push(b);
			}
		}
	}
	for(i=0; i<n; ++i){
		cout << p[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 7040
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


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

  char c;
  cin >> c;
  c++;
  cout << c << endl;
  
  return 0;
    

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1001001001
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repX(i, n ,x) for (int i = x; i < (int)(n); i++)
#define repBack(i, n) for (int i = n; i >= 0; i--)
#define dup(x,y) (((x)+(y)-1)/(y))

int main() {
    int N;
    cin >> N;
    double sum = 0;
    rep(i,N){
        double A;
        cin >> A;
        sum += 1/A;
    }
    sum = 1/sum;
    printf("%.10f",sum);

    return 0;
}

Measured memory_bytes: 256
n = int(input())
A = []
B = []
for i in range(n):
    a, b = map(int, input().split())
    z = a + b
    w = a - b
    A.append(z)
    B.append(w)
    
P = abs(max(A) - min(A))
Q = abs(max(B) - min(B))
print(max(P, Q))

Measured memory_bytes: 24972
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


const int cm = 1 << 17;
char cn[cm], *ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	if (ci - cn + 16 > cm) {
		int A = getcha() - '0';
		while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
		return A;
	}
	else {
		int A = *ci++ - '0';
		while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
		return A;
	}
}

pair<pair<int, int>, int> E[200002];
int H[100001];
int D[100001];
void dfs(int A, int B) {
	if (!D[A]) {
		D[A] = B;
		for (int i = H[A]; i; i = E[i].second) {
			dfs(E[i].first.first, B + E[i].first.second);
		}
	}
}

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


	int N = getint();
	for (int i = 1; i < 2 * N - 2; i += 2) {
		int x = getint();
		int y = getint();
		int z = getint() & 1;
		E[i] = mp(mp(y, z), H[x]);
		H[x] = i;
		E[i + 1] = mp(mp(x, z), H[y]);
		H[y] = i + 1;
	}
	
	dfs(1, 1);
	const int dm = 1 << 18;
	char dn[dm], *di = dn;
	rep1(i, N) {
		if (D[i] & 1) *di++ = '0';
		else *di++ = '1';
		*di++ = '\n';
	}
	fwrite_unlocked(dn, di - dn, 1, stdout);

	Would you please return 0;
}

Measured memory_bytes: 5248
N = int(input())
lst = []
for i in range(N):
    lst.append(int(input()))

def max_profit(lst):
    minv = lst[0]
    maxv = lst[1] - lst[0]
    for j in range(1,len(lst)):
        if maxv < lst[j] - minv:
            maxv = lst[j] - minv
        if minv > lst[j]:
            minv = lst[j]
    return maxv

print(max_profit(lst))


Measured memory_bytes: 13592
N = int(input())
if N == 1:
    print(0)
    quit()
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
def sousa(n):
    x = [1,3,6,10,15,21,28,36,45,55]
    for i in range(10):
        a = x[i]
        if n < a:
            return i
            break
bunkai = factorization(N)
ans = 0
for i in range(len(bunkai)):
    c = bunkai[i][1]
    ans += sousa(c)
print(ans)

Measured memory_bytes: 9512
function main(input) {
	input = input.trim().split("\n");
  	const n = Number(input[0]);
  	const w = input[1].split(" ").map(n => Number(n));
  	const result = [];
  	for (let i = 1; i < n; i++) {
    	const g1 = w.slice(0, i);
      	const g2 = w.slice(i, n);
      	const total1 = g1.reduce((a, b) => a + b);
      	const total2 = g2.reduce((a, b) => a + b);
      	result.push(Math.abs(total1 - total2));
    }
  	console.log(Math.min(...result));
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

typedef long long ll;

const int N = 1e5 + 5;
vector<int> t[N];

int d[N][2];

void dfs(int c, int p, int dist, int type){
	d[c][type] = dist;
	for(int a:t[c]){
		if(a != p)dfs(a,c,dist+1,type);
	}
}

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int n,u,v;
	cin >> n >> u >> v;
	--u,--v;
	for(int i = 0;i < n-1;++i){
		int x,y;
		cin >> x >> y;
		--x,--y;
		t[x].push_back(y);
		t[y].push_back(x);
	}
	dfs(u,-1,0,0);
	dfs(v,-1,0,1);
	int ans = 0;
	for(int i = 0;i < n; ++i){
		if(d[i][0] < d[i][1]){
			ans = max(ans, d[i][1] - 1);	
		}
	}
	cout << ans << '\n';
}


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

int main(){
  char a,b;
  cin >> a >> b;

  if(a=='H'){
    if(b=='H'){
      cout << "H" << endl;
    }else{
      cout << "D" << endl;
    }
  }else{
    if(b=='H'){
      cout << "D" << endl;
    }else{
      cout << "H" << endl;
    }
  }

}


Measured memory_bytes: 256
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iterator>
using namespace std;
const int64_t INF=10000000000000000;

int main(){
	int64_t n,a,b;
	cin>>n>>a>>b;
	int64_t set = n/(a+b);
	int64_t last = n%(a+b);
	if(last<=a){
		cout<<set*a+last<<endl;
	}else{
		cout<<set*a+a<<endl;
	}


}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
	ll N, T;
	cin >> N >> T;
	vector<ll> c(N), t(N);
	REP(i, N){
		cin >> c[i] >> t[i];
	}
	ll res = 100000;
	REP(i, N){
		if(t[i]<=T){
			res = min(res, c[i]);
		}
	}
	if(res==100000){
		cout << "TLE" << endl;
	}else{
		cout << res << endl;
	}
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

vector<ll> divisor(ll n){
    vector<ll> ret;
    for(int i=1;i<=sqrt(n);i++){
        if(n%i==0){
            ret.pb(i);
            if(i!=n/i)ret.pb(n/i);
        }
    }
//  sort(all(ret));
    return ret;
}



int main(){
    int n;
    while(cin>>n&&n){
        vector<ll> res = divisor(n);
        int sum = 0;
        rep(i,res.size()){
            sum+=res[i];
        }
        sum-=n;
        
        if(sum==n)cout<<"perfect number"<<endl;
        if(n>sum)cout<<"deficient number"<<endl;
        if(n<sum)cout<<"abundant number"<<endl;
    }
}

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

using namespace std;
typedef long long ll;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  
  int n;
  cin >> n;

  vector<int> a(n);
  vector<double> dp(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    dp[i] = (double)a[i];
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      dp[i] = max(dp[i], 2.0 * sqrt(a[j] * a[i]) + dp[j]);
    }
  }

  double ans = 0.0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, dp[i] + a[i]);
  }
  printf("%.10f\n", ans);

  return 0;
}


Measured memory_bytes: 3232
a,b,c = map(int,input().split())
if a == b == c and a%2 == 0:
    print(-1)
    exit()
for i in range(10**8):
    if a%2 != 0 or b%2 != 0 or c%2 != 0:
        break
    a_o,b_o,c_o = a,b,c
    a = b_o//2 + c_o//2
    b = a_o//2 + c_o//2
    c = a_o//2 + b_o//2
print(i)

Measured memory_bytes: 3060
import collections
import sys
sys.setrecursionlimit(100000000)

from math import factorial
def ncr(n,r):
 if n==r:
  return 1
 elif n>2:
  return factorial(n) // factorial(r) // factorial(n - r)
 else:
  return 1
def solve():
  n = int(input())
  query = []
  for i in range(n):
    a = sorted(input())
    query.append("".join(a))

  c = collections.Counter(query)
  ans = 0
  tmp = list(c.values())

  for i in tmp:
    if i >=2:
      ans += ncr(i,2)
  print(int(ans))
solve()
  
  

Measured memory_bytes: 19808
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N, A;
    cin >> N >> A;
    cout << N * N - A << endl;
    return 0;
}

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

int main() {
    int N;
    string S;
    cin >> N >> S;

    for (int i = 0; i < S.size(); i++) {
        int x = S.at(i) - 'A';
        x = (x + N) % 26;
        S.at(i) = 'A' + x;
    }
    cout << S << endl;
}

Measured memory_bytes: 3556
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int l,r,d;
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>l>>r>>d;
	cout<<(r)/d-(l+d-1)/d+1<<endl;
	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)

int main(){
  vector<int> x(3,0),y(3,0);
  REP(i,3) cin>>x.at(i);
  REP(i,3) y.at(i)=abs(x.at(i)-x.at((i+1)%3));
  sort(y.begin(),y.end());  
  cout<<y.at(0)+y.at(1);
}

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

#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

const ll MOD = 1000000000 + 7;

ll powmod(ll base, ll exponent, ll mod) {
  if (exponent == 0) {
    return 1;
  }
  ll res = powmod(base, exponent / 2, mod) % mod;
  res = res * res % mod;
  if (exponent % 2 != 0) {
    res = base * res % mod;
  }
  return res;
}

int main() {
  long long n;
  cin >> n;
  // 0-9
  ll ans = powmod(10, n, MOD);
  // 0-8
  ans = ans - powmod(9, n, MOD);
  if (ans < 0) {
    ans += MOD;
  }
  ans = ans % MOD;
  // 1-9
  ans = ans - powmod(9, n, MOD);
  if (ans < 0) {
    ans += MOD;
  }
  ans = ans % MOD;
  // 1-8
  ans = ans + powmod(8, n, MOD);
  ans = ans % MOD;
  cout << ans << endl;
}


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

int main(){
    int h, w;
    cin >> h >> w;
    
    vector<string> image(h);
    for (int i = 0; i<image.size(); i++){
        cin >> image.at(i);
        for (int j = 0; j<2; j++){
            cout << image.at(i) << endl;;
        }
    }    
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 28)

template<typename T>
void remove(vector<T>& vector, unsigned int index){
vector.erase(vector.begin() + index);
}

typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(void){
	vector<int> in;
	rep(i,3){
		int a;
		cin >> a;
		in.push_back(a);
	}
	sort(in.begin(), in.end());
	rep(i,3){
		if(i != 0)cout << " ";
		cout << in[i];
	}
	FIN("");

	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

Measured memory_bytes: 1224
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#define MOD 1000000007LL
using namespace std;

int main(){
	string seq[3];
	cin >> seq[0] >> seq[1] >> seq[2];
	int win[3] = { };
	int tmp = 0;
	while(win[tmp] != seq[tmp].size()){
		int x = (seq[tmp][win[tmp]] - 'a');
		win[tmp]++;
		tmp = x;
	}
	cout << (char)('A' + tmp) << endl;
	return 0;
}

Measured memory_bytes: 256
// This amazing code is by Eric Sunli Chen.
#include<bits/stdc++.h>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);

const int mod=998244353;
const int maxn=1<<18;
int qpow(int x,int y)
{
	int ret=1;
	while(y)
	{
		if(y&1)ret=(LL)ret*x%mod;
		x=(LL)x*x%mod;
		y>>=1;
	}
	return ret;
}
int rv;
void fwt(int *a,int n,bool f=0)
{
	int sz=(1<<n);
	for(int k=1;k<sz;k<<=1)
	{
		for(int i=0;i<sz;i+=(k<<1))for(int j=0;j<k;j++)
		{
			int u=a[i+j],v=a[i+j+k];
			a[i+j]=u+v;if(a[i+j]>=mod)a[i+j]-=mod;
			a[i+j+k]=u-v;if(a[i+j+k]<0)a[i+j+k]+=mod;
		}
	}
	if(f)for(int i=0;i<sz;i++)a[i]=1ll*a[i]*rv%mod;
}
int f[maxn],n,g[maxn];

int main()
{
	get1(n);
	int sum=0;
	for(int i=0;i<(1<<n);i++)
	{
		get1(f[i]);
		sum+=f[i];
	}
	
	sum=qpow(sum,mod-2);
	for(int i=0;i<(1<<n);i++)f[i]=(LL)f[i]*sum%mod;
	if(f[0])f[0]--;else f[0]=mod-1;
	fwt(f,n);
	
	rv=qpow(1<<n,mod-2);
	for(int i=1;i<(1<<n);i++)f[i]=((LL)qpow(f[i],mod-2)<<n)%mod;
	
	int k0,k1;
	memcpy(g,f,sizeof(f));g[0]=0;fwt(g,n,1);k0=g[0];
	memcpy(g,f,sizeof(f));g[0]=1;fwt(g,n,1);k1=g[0];
	f[0]=(LL)k0*qpow((k0-k1+mod)%mod,mod-2)%mod;fwt(f,n,1);
	for(int i=0;i<(1<<n);i++)printendl(f[i]);
	
	return 0;
}

Measured memory_bytes: 4864
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>

#define endl "\n"

using namespace std;

int n, d, t;

int main(){
    vector<int> v;
    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> d;
        v.push_back(d);
    }

    for(int i = 0; i < n-1; i++){
        for(int j = i+1; j < n; j++){
            t = t + (v[i]*v[j]);
        }
    }

    cout << t;




}

//g++ -std=c++14 comp.cpp -o b; ./b.exe


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
typedef long long ll;
const int INF = 1e9+1;
const int MOD = 2e9 + 9;
const ll LINF = 1e18;
using namespace std;

int main(){
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << min(a, b) + min(c, d);
	return 0;
}

Measured memory_bytes: 3644
N, M = map(int, input().split(" "))
flag = [1 for i in range(N)]
height = list(map(int, input().split(" ")))
for i in range(M):
  a, b = map(int, input().split(" "))
  if height[a - 1] < height[b - 1]:
    flag[a - 1] = 0
  elif height[a - 1] > height[b - 1]:
    flag[b - 1] = 0
  else:
    flag[a - 1] = 0
    flag[b - 1] = 0
print(sum(flag))

Measured memory_bytes: 20800
def culc(m):
    a1=0
    a2=1
    for i in range(m):
        a2_=a2
        a2=a1+a2
        a1=a2_
    return a2

N,M=map(int,input().split())
a=[-1]
b=[]
for i in range(M):
    a+=[int(input())]
    b+=[a[-1]-a[-2]-2]
    if a[-1]-a[-2]==1:
        b=[]
        break
else:
    b+=[N-a[-1]-1]
if b==[]:
    sm=0
else:
    sm=culc(b[0])
for i in b[1:]:
    sm=sm*culc(i)
print(sm%1000000007)

Measured memory_bytes: 5836
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
#define _GLIBCXX_DEBUG
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
//約数列挙(√N)
vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
//素因数分解(√N)
map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}
//素数テーブル(NloglogN)
vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}
//二項係数(K)
template< typename T >
T binomial(int64_t N, int64_t K) {
  if(K < 0 || N < K) return 0;
  T ret = 1;
  for(T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}
//二項係数テーブル(N^2)
template< typename T >
vector< vector< T > > binomial_table(int N) {
  vector< vector< T > > mat(N + 1, vector< T >(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 x,y,z;
  cin >> x >> y >> z;
  cout << (x-z)/(y+z) << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
using namespace std;

int main() {
        int a, b, c, d, e, f;
        double x, y;
        char line[200];

        while(fgets(line, 200, stdin) != NULL) {
                sscanf(line, "%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f);
                x = ((double)(e*c - b*f)) / (a*e - d*b);
                y = ((double)(a*f - d*c)) / (a*e - d*b);
                if(abs(x) < 1.0e-4) x = 0;
                if(abs(y) < 1.0e-4) y = 0;
                printf("%.3f %.3f\n", x, y);
        }
}

Measured memory_bytes: 1076
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

string str, p;
int a, b;

void print(){
  cin>>a>>b;
  for(int i=a;i<=b;i++) cout<<str[i];
  cout<<endl;
}

void reverse(){
  cin>>a>>b;
  for(int i=a;i<=(a+b)/2;i++) swap(str[i], str[b-i+a]);
}
  
void replace(){
  cin>>a>>b>>p;
  str.replace(a, b-a+1, p);
}

int main(){
  int m;
  string order;
  cin>>str>>m;
  for(int i=0;i<m;i++){
    cin>>order;
    if(order == "print") print();
    else if(order == "reverse") reverse();
    else if(order == "replace") replace();
  }
  return 0;
}



Measured memory_bytes: 3176
/*
 * https://atcoder.jp/contests/abc144/tasks/abc144_b
 */
#include <bits/stdc++.h>
 
using namespace std;

// ショートハンド
// #define ll intに変えればメモリ節約
#define ll long long


/* 
 * ループ系のマクロ
 * `REP(i, 10) { cout << i; }`のように、変数名,回数で動く
 */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/*
 * 正規表現
 */
#define MATCH(_str, _ptn) regex_match(_str, regex(_ptn))
#define REPLACE(_str, _ptn, _replacement) regex_replace(_str, regex(_ptn), _replacement)

# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())

# define pb push_back

# define INIT() cin.tie(0); ios::sync_with_stdio(false)

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
// `chmax(a, b)` aがbより小さければ、aをbに上書きする。chminは逆
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; }

const int MOD = 1e9 + 7;
int main() {
    INIT();

    ll k;
    ll result = 0;
    cin >> k;
    REP(i,k+1) {
        if(i % 3 != 0 && i % 5 != 0) {
            result += i;
        }
    }
    cout << result;
    return 0;
}

Measured memory_bytes: 3656