akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define INT int
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}
typedef long long ll;
const long long INF = 1LL << 60;

unsigned GetDigit(long long num)
{
    return std::to_string(num).length();
}

signed main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n)
    {
        cin >> a[i];
        if (a[i] == 0)
        {
            cout << 0 << endl;
            return 0;
        }
    }
    int ans = 1;
    int x = 1000000000000000000;

    rep(i, n)
    {
        int p = GetDigit(a[i]);
        int q = GetDigit(ans);
        if (p + q - 1 > 18 && ans * a[i] != x)
        {
            cout << -1 << endl;
            return 0;
        }
        ans *= a[i];
        if (ans > x)
        {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3976
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int dy[4]{0, -1, 0, 1};
int dx[4]{-1, 0, 1, 0};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, 0, h) cin >> s[i];

  queue<P> que;
  int ans[h][w];
  int dot_all = 0;
  rep(i, 0, h) rep(j, 0, w) {
    ans[i][j] = 0;
    if (s[i][j] == '.')
      dot_all++;
  }
  ans[0][0] = 1;

  que.push(make_pair(0, 0));
  while (!que.empty()) {
    P p = que.front();
    que.pop();
    rep(i, 0, 4) {
      int y = p.first + dy[i];
      int x = p.second + dx[i];
      if (y < 0 || y >= h || x < 0 || x >= w)
        continue;
      if (ans[y][x] != 0)
        continue;
      if (s[y][x] == '#')
        continue;
      ans[y][x] = ans[p.first][p.second] + 1;
      que.push(make_pair(y, x));
    }
  }

  if (ans[h - 1][w - 1])
    cout << dot_all - ans[h - 1][w - 1] << endl;
  else
    cout << -1 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
string t;
cin>>s>>t;
long long ans=0;
for(long long i=0;i<s.size();i++){
    if(s[i]!=t[i]){
        ans=-1;
        break;
    }
}
if(ans==-1){
    cout<<"No"<<endl;
}
else{
    cout<<"Yes"<<endl;
}

    return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int x = scanner.nextInt();
			int y = scanner.nextInt();
			if (x == 0 && y == 0)
				break;
			System.out.printf("%d %d\n", Math.min(x, y), Math.max(x, y));
		}
		scanner.close();
	}

}


Measured memory_bytes: 38988
#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;
long long inv(long long x, int s){
    if(s==0) return 1;
    if(s%2==0) return inv((x*x)%MOD, s/2)%MOD;
    return (x*inv(x, s-1))%MOD;
}
int main(){
    int x, y;
    scanf("%d%d", &x, &y);
    long long a=(x+y)/3, b=(2*y-x)/3;
    long long res=1;
    if((2*x-y)<0 || (2*y-x)<0 || (x+y)%3!=0){
        printf("0");
        return 0;
    }
    if(a<b){
        long long c=b;
        b=a; a=c;
    }
    for(long long i=1; i<=b; ++i){
            res*=inv(i, MOD-2);
            res%=MOD;
    }
    for(long long i=a; i>=a-b+1; --i) {
            res*=i;
            res%=MOD;
    }
    printf("%I64d", res);
    return 0;
}


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

#define lli long long int
#define pb push_back
#define in insert
#define pi pair<int, int>
#define pii pair<int, pi>
#define mp make_pair
#define fir first
#define sec second
#define MAXN 2001

int n, x, y;
int ans[MAXN];

signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  cin >> n >> x >> y;

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

  y--;
  x--;

  for (int i = 0; i < n; i++)
  {
    for (int j = i + 1; j < n; j++)
    {
      int neww = abs((min(x, y) - i)) + abs((j - max(x, y))) + 1;

      if (neww < j - i)
      {
        ans[j - i]--;
        ans[neww]++;
      }
    }
  }

  for (int i = 1; i < n; i++)
  {
    cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"

map<long long int, int>soinnsuu(long long int a) {
	map<long long int, int>ans;
	for (long long i = 2; i*i <= a; ++i) {
		while (a%i == 0) {
			ans[i]++;
			a /= i;
		}
	}
	if (a != 1)ans[a]++;
	return ans;
}
int main() {
	int N; cin >> N;
	auto mp(soinnsuu(N));
	bitset<30>bs;
	int size_ = mp.size();
	vector<long long int>sos;
	for (auto m : mp)sos.emplace_back(m.first);
	int ans = 0;
	for (int i = 0; i < (1 << size_); ++i) {
		bitset<30>bs(i);
		int num = N;
		for (int j = 0; j < size_; ++j) {
			if (bs[j]) {
				num /= sos[j];
			}
		}
		if (bs.count()%2)ans -= num;
		else ans += num;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3152
using System;
class aoj
{
    static void Main()
    {
        string[] u = Console.ReadLine().Split(' ');
        int a = int.Parse(u[0]), b = int.Parse(u[1]);
        int[] c = new int[a+1];
        int[] f = new int[2];
        f[0] = 100000;
        for(int i = 0; i < b; i++)
        {
            u = Console.ReadLine().Split(' ');
            int d = int.Parse(u[0]), e = int.Parse(u[1]);
            c[d] += e;
            if (f[0] != d) {
                if (f[1] > c[d])
                {
                    Console.WriteLine(f[0] + " " + f[1]);
                }
                else if (f[1] < c[d])
                {
                    Console.WriteLine(d + " " + c[d]);
                    f[0] = d;
                    f[1] = c[d];
                }
                else
                {
                    if (f[0] > d)
                    {
                        f[0] = d;
                        Console.WriteLine(d + " " + c[d]);
                    }
                    else
                    {
                        Console.WriteLine(f[0] + " " + f[1]);
                    }
                }
            }
            else
            {
                f[1] = 0;
                for(int j = a; j >=1; j--)
                {
                    if (c[j] >= f[1])
                    {
                        f[0] = j;
                        f[1] = c[j];
                    }
                }
                Console.WriteLine(f[0] + " " + f[1]);
            }
        }   
    }
}

Measured memory_bytes: 16448
#include <stdio.h>
//#include <stdlib.h>
//#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

int main() {
  int x;
  scanf("%d", &x);
  int sum = 0, y = x;
  while (y != 0) {
    sum += y%10;
    y /= 10;
  }
  if (x%sum)
    printf("No\n");
  else
    printf("Yes\n");
  return 0;
}


Measured memory_bytes: 128
from __future__ import division, print_function
import bisect
import math
import heapq
import itertools
import sys
from collections import deque
from atexit import register
from collections import Counter
from functools import reduce
if sys.version_info[0] < 3:
    from io import BytesIO as stream
else:
    from io import StringIO as stream
 
 
if sys.version_info[0] < 3:
    class dict(dict):
        """dict() -> new empty dictionary"""
        def items(self):
            """D.items() -> a set-like object providing a view on D's items"""
            return dict.iteritems(self)
 
        def keys(self):
            """D.keys() -> a set-like object providing a view on D's keys"""
            return dict.iterkeys(self)
 
        def values(self):
            """D.values() -> an object providing a view on D's values"""
            return dict.itervalues(self)
 
    input = raw_input
    range = xrange
 
    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip
 
 
def sync_with_stdio(sync=True):
    """Set whether the standard Python streams are allowed to buffer their I/O.
 
    Args:
        sync (bool, optional): The new synchronization setting.
 
    """
    global input, flush
 
    if sync:
        flush = sys.stdout.flush
    else:
        sys.stdin = stream(sys.stdin.read())
        input = lambda: sys.stdin.readline().rstrip('\r\n')
 
        sys.stdout = stream()
        register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))

def main():
    # sys.stdin  = open("input.txt")
    a,b,c,d=map(int,input().split())
    m=[]
    m.append(a*c)
    m.append(b*c)
    m.append(a*d)
    m.append(b*d)
    print(max(m))
    

if __name__ == '__main__':
    sync_with_stdio(False)
    main()

Measured memory_bytes: 66172
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int n;
	cin>>n;
	int cur = 1;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		if( a[i] == cur ) cur++;
	}
	if( cur == 1 ){
		cout<<-1<<endl;
	}
	else{
		cout<<n-cur+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;

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

int main() {

    int h, w;

    cin >> h >> w;

    vector<vector<bool>> tile(h + 2, vector<bool>(w + 2, false));

    for(int i = 1; i <= h; ++i) {
        for(int j = 1; j <= w; ++j) {
            char ch;
            cin >> ch;

            if(ch == '.')
                tile[i][j] = true;

        }
    }

    bool isTrue = false;

    vector<vector<bool>> visited(h + 2, vector<bool>(w + 2, false));

    struct node {
        vector<pair<int, int>> walked;
        int i, j;
        void AddWalked(int i, int j) {
            walked.emplace_back(make_pair(i, j));
        }

        node(int i = 1, int j = 1) : walked(vector<pair<int, int>>()), i(i), j(j) {}

    };

    queue<node> q;
    q.push(node(1, 1));
    
    node ansNode;

    while(!q.empty()) {

        auto nowNode = q.front(); q.pop();
        int ni = nowNode.i, nj = nowNode.j;

        if(!tile[ni][nj] || visited[ni][nj])
            continue;

        visited[ni][nj] = true;

        if(ni == h && nj == w) {
            isTrue = true;
            ansNode = nowNode;
            break;
        }

        for(int i = 0; i < 4; ++i) {
            if(tile[dx[i] + ni][dy[i] + nj]) {
                node newNode(dx[i] + ni, dy[i] + nj);
                newNode.walked = nowNode.walked;
                newNode.AddWalked(dx[i] + ni, dy[i] + nj);
                q.push(newNode);
            }
        }

    }


    int answerCount = 0;

    if(isTrue) {
        tile[1][1] = false;
        for(int i = 0; i < ansNode.walked.size(); ++i) {
            int ai = ansNode.walked[i].first, aj = ansNode.walked[i].second;
            tile[ai][aj] = false;
        }

        for(int i = 1; i <= h; ++i)
            for(int j = 1; j <= w; ++j)
                if(tile[i][j])
                    answerCount++;

    }


    if(isTrue) 
        cout << answerCount << endl;
    else
        cout << -1 << endl;

}

Measured memory_bytes: 3804
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

int n,m;
vector<vector<int> > g;
vector<int> col;

int main(int argc, char* argv[])
{
    scanf("%d%d", &n, &m);
    g.resize(n);
    col.resize(n);
    int i;
    for(i=0; i<n; i++) col[i]=0;

    for(i=0; i<m; i++) {
        int aa, bb;
        scanf("%d%d", &aa, &bb);
        g[aa-1].push_back(bb-1);
        g[bb-1].push_back(aa-1);
    }

    int q;
    scanf("%d", &q);
    vector<int> v(q), d(q), c(q);

    for(i=0; i<q; i++) {
        scanf("%d%d%d", &v[i], &d[i], &c[i]);
        v[i]--;
    }
    vector<int> vis(n*11,-1);
    for(i=q-1; i>=0; i--) {
        queue<pair<int, int> > que;   // vertex, dist
        que.push( make_pair(v[i], d[i]) );
        
        while( !que.empty() ) {
            auto tmp=que.front();
            que.pop();

            int curr = tmp.first;
            int dist = tmp.second;
            if(col[curr]<1) col[curr]=c[i];

            if(dist==0) continue;

            int k;
            int siz=g[curr].size();
            for(k=0; k<siz; k++) {
                int next = g[curr][k];

                int new_dist = dist-1;
                int p;
                for(p=10; p>=new_dist; p--) {
                    if(vis[next*11+p]>=0) {
                        break;
                    }
                }
                if(p>=new_dist) {
                    continue;
                }
                vis[next*11+new_dist]=1;

                que.push( make_pair( next, new_dist) );
            }
        }
    }

    for(i=0; i<n; i++) {
        printf("%d\n", col[i]);
    }
    
    return 0;
}


Measured memory_bytes: 12808
fn main() {
    let n = read::<u8>();
    let s = read::<String>()
        .chars()
        .map(|c| (((c as u8 - 65 + n) % 26) + 65) as char)
        .collect::<String>();
    println!("{}", s);
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int main()
{
    char b;
    cin >> b;
    switch(b) {
        case 'A':
            cout << 'T' << endl;
            break;
        case 'G':
            cout << 'C' << endl;
            break;
        case 'C':
            cout << 'G' << endl;
            break;
        case 'T':
            cout << 'A' << endl;
            break;
        default:
            break;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
	
    public static void main (String[] args) {
	Scanner scan = new Scanner(System.in);
	int a = scan.nextInt();
	int b = scan.nextInt();
	if (a <= 8 && b <= 8) {
	    System.out.println("Yay!");
	} else {
	    System.out.println(":(");
	}
    }
}


Measured memory_bytes: 22868
N,A,B = list(map(int,input().split()))
S = input()
ABSUM = 0
BSUM = 0
for s in S:
    if s == 'c':
        print('No')
        continue
    if s == 'a' and ABSUM < A+B:
        ABSUM += 1
        print('Yes')
        continue
    if s == 'b' and ABSUM < A+B and BSUM < B:
        ABSUM += 1
        BSUM += 1
        print('Yes')
        continue
    print('No')

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

void trace(vector<int> &vi) {
    for (auto i : vi)
        cout << i << " ";
    cout << endl;
}

void answer(vector<int> &vi) {
    auto first = vi.front();
    auto last = vi.back();
    int sum = 0;

    if (first < 0 && last < 0)
        sum += -last;
    else if (first > 0 && last > 0)
        sum -= first;
    

    for (auto i : vi)
        sum += i;
    cout << sum << endl;
}

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

    vector<int> vi;
    int N, L;
    cin >> N >> L;
    for (int i = L; i < L + N; i++) {
        vi.push_back(i);
    }

    // trace(vi);
    answer(vi);
}

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

#define ll          long long
#define uint        unsigned int 
#define ld          long double
#define SAM         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define mod         1000000007
#define mxn         200005
#define pb          push_back
#define pii         pair<int,int>
#define f           first
#define s           second
#define sz(x)       (int)x.size()
#define all(x)      x.begin(),x.end()

using namespace std;

int main()
{
    SAM;
    int arr[11];
    memset(arr,0,sizeof(arr));
    FOR(i,0,3)
    {
        int x;
        cin>>x;
        arr[x]++;
    }
    
    if(arr[5]==2 && arr[7]==1)
        cout<<"YES";
    else
        cout<<"NO";
    
    
    return 0;
}




Measured memory_bytes: 3648
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 510000;
const int MOD =  998244353;

     signed main(){
    int c[3][3];
    for(int i=0;i<3;i++)for(int j=0;j<3;j++)cin>>c[i][j];
    for(int i=0;i<3;i++){c[i][2]-=c[i][0];c[i][1]-=c[i][0];}
    if(c[0][1]!=c[1][1]||c[0][1]!=c[2][1]||c[0][2]!=c[1][2]||c[0][2]!=c[2][2])cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
     }

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

int main()
{
	int n;
	std::cin >> n;
	int h = n / 3600;
	n -= h * 3600;
	int m = n / 60;
	n -= m * 60;
	int s = n;
	std::cout << h << ":" << m << ":" << s << endl;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
#define MAXN 100001
using namespace std;

int n;
int h[MAXN];
int dp[MAXN];

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    cin >> n;
    
    for(int i = 0; i < n; i++){
    	cin >> h[i];
    }
    
    dp[n-1] = 0;
    dp[n-2] = abs(h[n-1] - h[n-2]);

	for(int i = n-3; i >= 0; i--){
		dp[i] = min(dp[i+1] + abs(h[i] - h[i+1]), dp[i+2]+abs(h[i] - h[i+2]));
	}
    
    cout << dp[0] << "\n";
    
    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#define INF 0x3FFFFFFF
#define MN 2005
using namespace std;
int a[MN][MN],len[MN][MN],q[MN];
int n,m,p,ans,tp;
char c[MN];

inline int read()
{
	int n=0,f=1; char c=getchar();
	while (c<'0' || c>'9') {if(c=='-')f=-1; c=getchar();}
	while (c>='0' && c<='9') {n=n*10+c-'0'; c=getchar();}
	return n*f;
}

int main()
{
	register int i,j;
	n=read(); m=read();
	for (i=1;i<=n;++i)
	{
		scanf("%s",c+1);
		for (j=1;j<=m;++j) a[i][j]=(c[j]=='#'?1:0);
	}
	for (i=1;i<n;++i)
		for (j=1;j<=m;++j) a[i][j]=a[i][j]^a[i+1][j];
	for (i=1;i<n;++i)
		for (j=1;j<m;++j) a[i][j]=a[i][j]^a[i][j+1];
	for (i=1;i<n;++i)
		for (j=1;j<m;++j)
			if (a[i][j]) len[i][j]=0;
			else len[i][j]=len[i-1][j]+1;
//	for (i=1;i<n;++i)
//		for (j=1;j<m;++j)	
	for (i=1;i<n;++i)
	{
		for (j=1;j<m;++j)
		{
			for (;tp&&len[i][j]<=len[i][q[tp]];--tp) ans=max(ans,(j-1-q[tp-1]+1)*(len[i][q[tp]]+1));
			q[++tp]=j;
		}
		for (;tp;--tp) ans=max(ans,(m-1-q[tp-1]+1)*(len[i][q[tp]]+1));
	}
	printf("%d",max(ans,n));
}

Measured memory_bytes: 31616
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;
import java.util.Scanner;

public class Main {

    char[][] field;
    boolean[][] visited;
    int[] dx = {-1, 0, 1, 0};
    int[] dy = {0, 1, 0, -1};
    Queue<Integer[]> q = new ArrayDeque<>();

    void run() {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        field = new char[h][w];
        visited = new boolean[h][w];
        int bCount = 0;

        for (int i = 0; i < h; i++) {
            char[] chars = sc.next().toCharArray();
            for (int j = 0; j < w; j++) {
                field[i][j] = chars[j];
                if (chars[j] == '#') bCount++;
            }
        }
        q.add(new Integer[]{0, 0, 0});
        visited[0][0] = true;

        int count = -1;
        while (!q.isEmpty()) {
            Integer[] next = q.remove();
            int x = next[0];
            int y = next[1];
            int depth = next[2];
            if (x == h - 1 && y == w - 1) {
                count = depth;
                break;
            }
            for (int i = 0; i < 4; i++) {
                int nx = x + dx[i];
                int ny = y + dy[i];
                if (0 <= nx && nx < h && 0 <= ny && ny < w && !visited[nx][ny] && field[nx][ny] != '#') {
                    visited[nx][ny] = true;
                    q.add(new Integer[]{nx, ny, depth + 1});
                }
            }
        }

        System.out.println(count == -1 ? -1 : h * w - 1 - bCount - count);


    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }

}


Measured memory_bytes: 23892
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
// #include <bits/stdc++.h>
using namespace std;

int main() {
  long X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  long A[X], B[Y], C[Z];
  for (int i = 0; i < X; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < Y; i++) {
    cin >> B[i];
  }
  for (int i = 0; i < Z; i++) {
    cin >> C[i];
  }

  long AB[X * Y];
  for (int i = 0; i < X; i++) {
    for (int j = 0; j < Y; j++) {
      AB[i * Y + j] = A[i] + B[j];
    }
  }

  sort(AB, AB + X * Y, greater<long>());

  long ABC[K * Z];
  for (int i = 0; i < min<long>(K, X * Y); i++) {
    for (int j = 0; j < Z; j++) {
      ABC[i * Z + j] = AB[i] + C[j];
    }
  }

  sort(ABC, ABC + min<long>(K, X * Y) * Z, greater<long>());

  for (int i = 0; i < min<long>(K, X * Y * Z); i++) {
    cout << ABC[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 31488
N, K = (int(i) for i in input().split())
A = [int(i) for i in input().split()]
C = [0]*40
for i in range(40):
  for a in A:
    if a & (2**(39-i)):
      C[i] += 1
INF = float("inf")
dp = [[-INF]*2 for i in range(41)]
dp[0][0] = 0
for i in range(40):
  if K & (2**(39-i)):
    temp1 = dp[i][0] + 2**(39-i)*C[i]
    temp2 = dp[i][1] + 2**(39-i)*max(C[i],N-C[i])
    dp[i+1][1] = max(temp1, temp2)
    dp[i+1][0] = dp[i][0] + 2**(39-i)*(N-C[i])
  else:
    dp[i+1][1] =  dp[i][1] + 2**(39-i)*max(C[i],N-C[i])
    dp[i+1][0] = dp[i][0] + 2**(39-i)*C[i]
print(max(dp[40]))

Measured memory_bytes: 14620
/****************************************************************
# @Author:      iLovePKU_zbtxdy
# @DateTime:    2020-01-28 14:13:36
# @Description: You build it. You run it
# @More: Once lots of AC, try Brute-force,dynamic programming
****************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define close std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define eps 1e-8
typedef long long ll;
const int maxn = 1e6+10;
const int INF = 0x3f3f3f3f;
const ll linf = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
ll mod = 1e9+7;
int main()
{
    int a , b;
    cin >> a >> b;
    cout << ceil(a*1.0 / b) << endl;
    
    system("pause");
}
/***************************************************************************
*stuff you should look for
*int overflow, array bounds
*special cases (n=1?), set tle
*do smth instead of nothing and stay organized
***************************************************************************/

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

int main() {
  string s,t; cin >> s >> t;
  int n = s.size();
  int ans = 0;
  rep(i,n) {
    if (s[i] != t[i]) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3852
#include <algorithm>
#include <bits/stdc++.h>
#include <deque>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define INF 1LL << 40;
#define MOD 1000000007;
#define ll long long
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
#define prique priority_queue
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
template <class T> inline void chmax(T &a, T b) { a < b ? a = b : a; };
template <class T> inline void chmin(T &a, T b) { a > b ? a = b : a; };
int map1[2020][2020];
int map2[2020][2020];
int main() {
    memset(map1, 0, sizeof(map1));
    memset(map2, 0, sizeof(map2));
    int h, w;
    cin >> h >> w;
    vector<string> s(h + 1);
    rep(i, h) cin >> s[i];
    rep(i, h) s[i].push_back('#');
    rep(i, w + 1) s[h] += '#';
    rep(i, h) {
        int sx = 0;
        rep(j, w + 1) {
            if(s[i][j] == '#') {
                map1[i][sx] += j - sx;
                map1[i][j] -= j - sx;
                sx = j + 1;
            }
        }
    }
    rep(i, h) rep(j, w) map1[i][j + 1] += map1[i][j];
    // rep(i, h) {
    //     rep(j, w) cout << map1[i][j];
    //     cout << endl;
    // }
    rep(j, w) {
        int sy = 0;
        rep(i, h + 1) {
            if(s[i][j] == '#') {
                map2[sy][j] += i - sy;
                map2[i][j] -= i - sy;
                sy = i + 1;
            }
        }
    }
    rep(j, w) rep(i, h) map2[i + 1][j] += map2[i][j];
    // rep(i, h) {
    //     rep(j, w) cout << map2[i][j];
    //     cout << endl;
    // }
    int ans = 0;
    rep(i, h) rep(j, w) ans = max(ans, map1[i][j] + map2[i][j]);
    cout << ans - 1 << endl;
}


Measured memory_bytes: 36224
import java.util.*;
public class Main{
    public static int MOD=1000000007;
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        long N=sc.nextInt();
        long K=sc.nextInt();
        long ans=0;
        for(long i=K;i<=N+1;i++){
            long add=((N+(N+1-i))*i)/2;
            add-=i*(i-1)/2;
            add++;
            ans=(ans+add)%MOD;
        }
        System.out.println(ans);
        sc.close();
    }
}

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


int main()
{
    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        string x, y;
        cin >> x >> y;
        int c[1001][1001];
        for(int j = 0; j <= (int)x.size(); j++) c[j][0] = 0;
        for(int j = 0; j <= (int)y.size(); j++) c[0][j] = 0;
        for(int j = 1; j <= (int)x.size(); j++){
            for(int k = 1; k <= (int)y.size(); k++){
                if(x[j - 1] == y[k - 1]) c[j][k] = c[j - 1][k - 1] + 1;
                else c[j][k] = max(c[j - 1][k],c[j][k - 1]);
                
            
            }
        
        }
        cout << c[x.size()][y.size()] << endl;
        
        
        
    }
    
    
    return 0;
}


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

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

  vector<pair<int,int>> v(N);
  for(int i = 1; i <= N; i++){
    int x;
    cin >> x;
    v.at(i - 1).first = x;
    v.at(i - 1).second = i;
  }

  sort(v.begin(),v.end());
  rep(i,N){
    cout << v.at(i).second << " ";
  }
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    
    long long ans=0;
    if(n<=k)
    {
        cout<<ans<<endl;
        return 0;
    }
    vector<long long>h(n);
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
    }
    sort(h.begin(),h.end());
    for(int i=0;i<n-k;i++)
    {
        ans+=h[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1792
All = list(map(int,input().split()))
All.sort()

a = All[0]
b = All[1]
c = All[2]
aa = a%2
bb=b%2
cc =c%2

if aa == bb and aa == cc: #偶奇がすべて一致
  ans = (c-b)//2+(c-a)//2
elif aa==bb:
  a+=1
  b+=1
  ans = 1+ (c-b)//2+(c-a)//2
elif aa == cc:
  a+=1
  c+=1
  ans = 1+ (c-b)//2+(c-a)//2
elif bb == cc:
  b+=1
  c+=1
  ans = 1+ (c-b)//2+(c-a)//2
print(ans)  


Measured memory_bytes: 38384
#include <stdio.h>

int main(){
  
  int i, j;
  int a, b, c, d;
  scanf("%d%d%d%d", &a, &b, &c, &d);
  
  while(1){
    c -= b;
    if(c <= 0){
      printf("Yes\n");
      return 0;
    }
    a -= d;
    if(a <= 0){
      printf("No\n");
      return 0;
    }
  }
  
  return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
//priority_queue<int, vector<int>, greater<int> > pq;
#define _CRT_SECURE_NO_DEPRECATE
const int N = 300030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =  1e9+7;
ll n;
ll dp[N],arr[N];
int main()
{
    ios::  sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>n;
	rep(i,1,n+1)
	cin>>arr[i];
	dp[1]=0;

	rep(i,2,n+1)
	{
		if(i>2)
		{
			dp[i]=min(dp[i-1]+abs(arr[i-1]-arr[i]),dp[i-2]+abs(arr[i-2]-arr[i]));
		}
		else
		dp[i]=abs(arr[i-1]-arr[i]);
	}

	cout<<dp[n];
}






Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
map<pair<int,int>,string>m;
void lcs(string&x,string&y)
{
    pair<int,int>temp;
    pair<int,int>temp1;
    pair<int,int>temp2;
    string z="";
    temp={0,0};
    m[temp]=z;
    for(int i=0;i<x.length();i++)
    {
        for(int j=0;j<y.length();j++)
        {
            if(x[i]==y[j])
            {
                m[make_pair(i+1,j+1)]=m[make_pair(i,j)]+x[i];
            }
            else
            {
                temp1={i+1,j};
                temp2={i,j+1};
                temp={i+1,j+1};
                if(m[temp1].length()<m[temp2].length())
                {
                    m[temp]=m[temp2];
                }
                else if(m[temp1].length()>m[temp2].length())
                {
                    m[temp]=m[temp1];
                }
                else
                {
                    if(m[temp1]<m[temp2])
                    {
                        m[temp]=m[temp1];
                    }
                    else
                    {
                        m[temp]=m[temp2];
                    }
                }
            }
        }
    }
    x= m[make_pair(x.length(),y.length())];
}
int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string x;
    string y;
    int n;
    cin>>n;
    cin>>x;
    sort(x.begin(),x.end());
    for(int i=1;i<n;i++)
    {
        cin>>y;
        sort(y.begin(),y.end());
        lcs(x,y);
    }
    cout << x<<endl;
    return 0;
}


Measured memory_bytes: 512
H,W=map(int,input().split())
S=[]
for _ in range(H):
    S.append(input())

def path(i,j):
    p=[]
    for k in [1,-1]:
        if 0<=i+k<H:
            if S[i][j]!=S[i+k][j]:
                p.append((i+k,j))
        if 0<=j+k<W:
            if S[i][j]!=S[i][j+k]:
                p.append((i,j+k))
    return p
f = [[0 for i in range(W)] for j in range(H)]
ans=0

for i in range(H):
    for j in range(W):
        if f[i][j]==0:
            f[i][j]=1
            b=0
            w=0
            if S[i][j]=='#':
                b+=1
            else:
                w+=1
            que=path(i,j)

            while len(que)>0:
                tmp=[]
                for q in que:
                    q0,q1=q
                    if f[q0][q1]==0:
                        f[q0][q1]=1
                        if S[q0][q1]=='#':
                            b+=1
                        else:
                            w+=1
                        for p in path(q0,q1):
                            if f[p[0]][p[1]]==0:
                                tmp.append(p)
                que=tmp
            ans+=b*w
print(ans)


Measured memory_bytes: 73964
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int const MAX = 2002;
struct ball {
	int number; int color; int position;
};

ball x[MAX * 2];
int dp[MAX][MAX];
int w[MAX][MAX];
int b[MAX][MAX];

bool order(ball p, ball q) {
	if (p.color != q.color) {
		return p.color < q.color;
	}
	else {
		return p.number < q.number;
	}
}

int id(int number, int color, int n) {
	return n * color + number;
}
void fill_in(int y[MAX][MAX], int color, int n) {
	for (int i = 1; i <= n; i++) {
		int cnt = 0;
		int p = x[id(i, color, n)].position;
		for (int j = 1; j < i; j++) {
			cnt += (p < x[id(j, color, n)].position);
		}
		y[i][0] = cnt;
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			y[i][j] = y[i][j - 1] + (x[id(i, color, n)].position < x[id(j, !color, n)].position);
		}
	}
}

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n * 2; i++) {
		int a; char c;
		cin >> c >> a;
		x[i].number = a;
		x[i].color = (c == 'B');
		x[i].position = i;
	}
	sort(x + 1, x + 2 * n + 1, order);
	fill_in(b, 1, n);
	fill_in(w, 0, n);
	for (int i = 1; i <= n; i++) {
		dp[i][0] = dp[0][i] = 0;
		for (int j = 1; j <= i; j++) {
			dp[i][0] += b[j][0];
			dp[0][i] += w[j][0];
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			dp[i][j] = min(dp[i - 1][j] + b[i][j], dp[i][j - 1] + w[j][i]);
		}
	}
	cout << dp[n][n] << endl;
}

Measured memory_bytes: 47232
#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define rep(i,a,n) for (int i=a;i<n;i++)
#define MAXN 1000001 
using namespace std;
void solve() {
	ll n;
	cin>>n;
	ll sum=0;
	for(int i=1;i<=n;i++){
		if(i%3==0||i%5==0)
			continue;
		sum+=i;
	}
	cout<<sum<<"\n";
	return;
}

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

	// ll t;
	// cin >> t;
	// while(t--)
		solve();

}

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

using namespace std;


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


Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");
        int a = Integer.parseInt(str[0]);
        int b = Integer.parseInt(str[1]);
        int c = Integer.parseInt(str[2]);
        int d = Integer.parseInt(str[3]);

        int[] time = new int[101];
        time[a] += 1;
        time[b] += -1;
        time[c] += 1;
        time[d] += -1;
        for (int i = 1; i < 101; i++) time[i] += time[i - 1];

        int cnt = 0;
        for (int i = 0; i < 101; i++) if (time[i] == 2) cnt++;

        System.out.println(cnt);
    }
}


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

int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> X(M);
  int ans = 0;
  rep(i, M)
  {
    cin >> X[i];
  }
  sort(X.begin(), X.end());
  if (N < M)
  {
    vector<pair<int, int>> move_cost(M - 1);
    rep(i, M - 1)
        move_cost[i] = make_pair(X[i + 1] - X[i], i);

    int sum_move_cost = 0;
    rep(i, M - 1)
        sum_move_cost += move_cost[i].first;

    vector<pair<int, int>> sort_move_cost = move_cost;
    sort(sort_move_cost.rbegin(), sort_move_cost.rend());

    int cut_move_cost = 0;
    rep(i, N - 1)
        cut_move_cost += sort_move_cost[i].first;
    ans = sum_move_cost - cut_move_cost;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int S, W; cin >> S >> W;
    if (S <= W) {
        cout << "unsafe" << endl;
    } else {
        cout << "safe" << endl;
    }
}


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

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

int main(){
  ll a, b, c, d, e;
  cin >> a >> b >> c >> d;
  ll nc = b/c - (a+c-1)/c + 1;
  ll nd = b/d - (a+d-1)/d + 1;
  e = c*d/gcd(c,d);
  ll ne = b/e - (a+e-1)/e + 1;
  cout << b - a + 1 - (nc + nd - ne) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int n;
    scanf("%d", &n);
    int nNum = 1;
    for(int i =0; i < n; i++){
        int a;
        scanf("%d", &a);
        if(a == nNum){
            nNum++;
        }
    }
    if(nNum >= 2){  
        printf("%d", n - nNum + 1);
    } else {
        printf("%d", -1);
    }
    return 0;
}


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

template<long long mod>
class modint{
private:
  long long a;
public:
  constexpr modint(const long long x = 0) noexcept : a(x%mod) {}
  constexpr long long& value() noexcept { return a; }
  constexpr const long long& value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint& operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if(a >= mod) a -= mod;
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if(a < rhs.a) a += mod;
    a -= rhs.a;
    return *this;
  }
  constexpr modint& operator*=(const modint rhs) noexcept {
    a = a*rhs.a%mod;
    return *this;
  }
  constexpr modint& operator/=(modint rhs) noexcept {
    long long k = mod-2;
    while(k > 0){
      if(k&1){
        *this *= rhs;
      }
      rhs *= rhs;
      k /= 2;
    }
    return *this;
  }
  friend ostream& operator<<(ostream &os, const modint &X){
    return os << X.a;
  }
  friend istream& operator>>(istream &is, modint &X){
    is >> X.a;
    X.a %= mod;
    if(X.a < 0) X.a += mod;
    return is;
  }
};

template<typename T>
T power(T x, long long k){
  T ret{1};
  while(k > 0){
    if(k&1) ret *= x;
    x *= x;
    k /= 2;
  }
  return ret;
}

int main(){
  using mint = modint<(int)1e9+7>;
  int N, K;
  cin >> N >> K;
  mint ans = 0;
  vector<int> D(K+1,1);
  vector<mint> C(K+1);
  C[1] = 0;
  for(int i = 1; i <= K; ++i){
    C[i] += i;
    for(int j = 2; j*i <= K; ++j){
      C[i*j] -= C[i];
    }
  }
  for(int i = 1; i <= K; ++i){
    ans += power<mint>(K/i,N)*(C[i]);
  }
  cout << ans << endl;
}


Measured memory_bytes: 4248
#include<stdio.h>
int main()
{
	int n;
	scanf("%d", &n);
	int i, j;
	int a[100005];
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);
	int m[100005];
	for (i = 0; i < n; i++)
		m[i] = -1;
	int ans = 1;
	m[0] = a[0];
	int min, max, mid;
	for (i = 1; i < n; i++)
	{
		if (a[i] > m[0])
		{
			m[0] = a[i];
			continue;
		}
		if (a[i] <= m[ans - 1])
		{
			m[ans] = a[i];
			ans++;
			continue;
		}
		max = ans - 1;
		min = 0;
		while (max - min > 1)
		{
			mid = (max + min) / 2;
			if (m[mid] >= a[i])
				min = mid;
			else
				max = mid;
		}
		m[max] = a[i];
		while (m[max] > m[max - 1])
		{
			j = m[max];
			m[max] = m[max - 1];
			m[max - 1] = j;
			max--;
			if (max == 0)
				break;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 896
#include <algorithm>
#include <cstdio>
typedef long long lld;
const int MAXN = 2e5+5;
const lld INFN = 1e9 * MAXN + 5;
int A[MAXN];
int H[MAXN];
int N;

struct BinaryIndexedTree {
  lld data[MAXN]{ };

  void add(int pos, lld val) {
    for (int i = pos; i <= N; i += i & -i) {
      data[i] = std::max(val, data[i]);
    }
  }

  lld get(int pos) {
    lld res = 0LL;
    for (int i = pos; i > 0; i -= i & -i) {
      res = std::max(data[i], res);
    }
    return res;
  }

  void init() {
    for (int i = 0; i <= N; ++i) data[i] = 0LL;
  }
} dp;

lld solve() {
  dp.init();
  lld sum = 0LL;
  for (int i = 1; i <= N; ++i) {
    lld best = dp.get(H[i] - 1) + A[i];
    dp.add(H[i], best);
    sum = std::max(best, sum);
  }
  return sum;
}

int main() {
  scanf("%d", &N);
  for (int i = 1; i <= N; ++i) scanf("%d", &H[i]);
  for (int i = 1; i <= N; ++i) scanf("%d", &A[i]);
  printf("%lld\n", solve());
  return 0;
}

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

#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;


int main(){
  //ll n;
  string s;
  cin >> s;
  
  if(s == "SUN")
    cout << 7 << endl;
  else if(s == "MON")
    cout << 6 << endl;
  else if(s == "TUE")
    cout << 5 << endl;
  else if(s == "WED")
    cout << 4 << endl;
  else if(s == "THU")
    cout << 3 << endl;
  else if(s == "FRI")
    cout << 2 << endl;
  else if(s == "SAT")
    cout << 1 << endl;
  
  //cout << n << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int WHmax = 1000000;
ll W,H;
ll P[WHmax], Q[WHmax];
ll ix[2*WHmax];
ll all[2*WHmax];

bool comp(int i, int j){
  return all[i] < all[j];
}

int main(){
  cin >> W >> H;
  for(int i=0; i<W; i++) cin >> P[i];
  for(int i=0; i<H; i++) cin >> Q[i];

  for(int i=0; i<W; i++) all[i] = P[i];
  for(int i=0; i<H; i++) all[W+i] = Q[i];
  for(int i=0; i<W; i++) ix[i] = i;
  for(int i=0; i<H; i++) ix[W+i] = W+i;

  sort(ix, ix+W+H, comp);

  ll nx = W+1;
  ll ny = H+1;

  ll res=0;
  for(int i=0; i<W+H; i++){
    if(ix[i]<W){
      int x=ix[i];
      res+=P[x]*ny;
      nx--;
    }
    else{
      int y=ix[i]-W;
      res+=Q[y]*nx;
      ny--;
    }
  }

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


Measured memory_bytes: 5496
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

static const char TBL[] = " rgb";

unsigned encode(const string& s)
{
  unsigned t = 0;
  for (string::const_iterator it = s.begin(); it != s.end(); ++it) {
    t <<= 2;
    switch (*it) {
      case 'r': t |= 1; break;
      case 'g': t |= 2; break;
      case 'b': t |= 3; break;
      default:  throw __LINE__;
    }
  }
  return t;
}

string decode(unsigned t)
{
  string s;
  while (t != 0) {
    s = TBL[t&3] + s;
    t >>= 2;
  }
  return s;
}

int bfs(unsigned init)
{
  queue<unsigned> q;
  vector<int> dist(1<<20, 10000000);
  q.push(init);
  dist[init] = 0;
  while (!q.empty()) {
    const int t = q.front();
    const string s = decode(t);
    q.pop();
    const int d = dist[t];
    const int N = s.size();
    if (count(s.begin(), s.end(), s[0]) == N) {
      return d;
    }
    for (int i = 0; i < N-1; i++) {
      if (s[i] != s[i+1]) {
        string u = s;
        for (int j = 1; j <= 3; j++) {
          if (TBL[j] != s[i] && TBL[j] != s[i+1]) {
            u[i] = u[i+1] = TBL[j];
            const unsigned v = encode(u);
            if (d+1 < dist[v]) {
              dist[v] = d+1;
              q.push(v);
            }
            break;
          }
        }
      }
    }
  }
  return -1;
}

int main()
{
  string s;
  while (cin >> s && s != "0") {
    const int ans = bfs(encode(s));
    if (ans < 0) {
      cout << "NA" << endl;
    } else {
      cout << ans << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 5332
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  ll N = 0,M = 0;
  long double total = 0;
  cin >> N >> M;
  vector<ll> vec(N);
  rep(i,N){
    cin >> vec[i];
    total += vec[i];
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  rep(i,M){
    if(vec[i] < total / (4 * M)){
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}
  
      
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define CST(x) cout<<fixed<<setprecision(x)
#define PI 3.14159265359
#define MOD 1000000007
using namespace std;
using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;

int main(){

    int s;
    cin >> s;
    int sec = s%60;
    int min = (s/60)%60;
    int hor = s/3600;
    cout << hor << ':' << min << ':' << sec << endl;
    return 0;
}


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

const long long INF = 1LL << 60;

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> h(n);
    for (int i = 0; i < n; ++i) cin >> h[i];
    vector<long long> dp(n+1, INF);
    dp[0] = 0;
    for (int i = 1; i <= n; ++i) {
        dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
        if (i > 1) dp[i] = min(dp[i], dp[i-2] + abs(h[i]-h[i-2]));
    }
    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 4308
/* C++14 (Clang 3.8.0) for AtCoder */

#include <iostream>
#include <vector>
#include <string>
// #include <cmath>
// #include <math.h>
#include <map>
// #include <algorithm>

namespace AtCoder {
	using Str = std::vector<std::string>;
	using Num = std::vector<int>;

	class Ans {
	public:
		void showResult(void);
		void increment(void);
		void increment(double);
		void decrement(void);
		void decrement(double);
		double getResult(void);
	private:
		double result;
	};
	void Ans::showResult(void) {
		printf("%.0lf\n", this->result);
	}
	void AtCoder::Ans::increment(void) {
		this->result++;
	}
	void AtCoder::Ans::increment(double value) {
		this->result += value;
	}
	void AtCoder::Ans::decrement(void) {
		this->result--;
	}
	void AtCoder::Ans::decrement(double value) {
		this->result -= value;
	}
	double AtCoder::Ans::getResult(void) {
		return this->result;
	}

	void input(Str* str) {
		str->clear();
		std::string buf = "", row = "";
		std::getline(std::cin, buf);
		for (unsigned int i = 0; i < buf.size(); i++) {
			if (' ' == buf[i]) {
				str->push_back(row);
				row = "";
			} else {
				row += buf[i];
			}
		}
		str->push_back(row);
	}
	void input(Num* num) {
		num->clear();
		std::string buf = "", row = "";
		std::getline(std::cin, buf);
		for (unsigned int i = 0; i < buf.size(); i++) {
			if (' ' == buf[i]) {
				num->push_back(std::atoi(row.c_str()));
				row = "";
			} else {
				row += buf[i];
			}
		}
		num->push_back(std::atoi(row.c_str()));
	}
	void exp(std::string* str,  Str* newStr) {
		std::string pre = *str;
		newStr->clear();
		for (unsigned int i = 0; i < pre.length(); i++) {
			newStr->push_back(pre.substr(i, 1));
		}
	}
	using DefMap = std::map<int, int>;

	class Map {
	public:
		void set(int, int);
		int get(int);
		void remove(int);
	private:
		DefMap m;
	};
	void Map::set(int key, int value) {
		try {
			this->m.at(key);
			this->remove(key);
			this->m.insert(std::make_pair(key, value));
		} catch (std::exception& e) {
			this->m.insert(std::make_pair(key, value));
		}
	}
	int Map::get(int key) {
		try {
			return this->m.at(key);
		} catch (std::exception& e) {
			return -1;	// "invalid map<K, T> key"
		}
	}
	void Map::remove(int key) {
		this->m.erase(key);
	}

}

int main(void) {

	AtCoder::Num s;
	AtCoder::input(&s);
	const int n = s[0];

	AtCoder::input(&s);

	AtCoder::Map* map = new AtCoder::Map();

	for (int i = 0; i < n; i++) {
		map->set(s[i], (i + 1));
	}
	for (int i = 1; i < (n + 1); i++) {
		printf("%d ", map->get(i));
	}
	printf("\n");

	delete(map);

	return 0;
}


Measured memory_bytes: 5944