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

using namespace std;

int main()
{
    int n,y,i,j,t,a,b,c;
    bool ok=true;
    cin>>n>>y;
    for (i=0; i<=n && ok; i++)
    {
        for (j=0; j<=n-i && ok; j++)
        {
            t=10000*i+5000*j+1000*(n-i-j);
            if (t==y)
            {
                ok=false;
                a=i; b=j; c=n-i-j;
            }
        }
    }
    if (ok) cout<<"-1 -1 -1"<<endl;
    else cout<<a<<" "<<b<<" "<<c<<endl;
    return 0;
}

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


int main(int argc, char **argv)
{
	ll A, B; cin >> A >> B;

	ll res{1ll<<60};

	if (A <= B) res = min(res, B-A);
	if (B >= -A) res = min(res, A+B+1);
	if (B <= -A) res = min(res, -B-A+1);
	if (A >= B) res = min(res, -B+A+2);

	std::cout << res << std::endl;
}


Measured memory_bytes: 384
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
#include <sstream>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>
#include <bitset>

using namespace std;

using int64 = long long;

/////////////////////
// Code starts here//
/////////////////////


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

    int N;
    cin >> N;

    while (N) {
        if (N % 10 == 7) {
            cout << "Yes\n";
            return 0;
        }
        N /= 10;
    }

    cout << "No\n";

    return 0;
}


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

int N;
int D;
int X;
vector<int> A;
int ans;

void solve() {
  for (int i = 0; i < N; ++i) {
    for (int d = 1; d <= D; d += A[i]) {
      ++ans;
    }
  }
  cout << ans + X << endl;
}

int main() {
  cin >> N;
  cin >> D >> X;
  A.resize(N);
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n;
  cin >> n;
  deque<ll> q;
  rep(i, n) {
    ll a;
    cin >> a;
    if(i % 2) {
      q.push_front(a);
    } else {
      q.push_back(a);
    }
  }
  rep(i, n) {
    if(n % 2) {
      cout << q.back() << ' ';
      q.pop_back();
    } else {
      cout << q.front() << ' ';
      q.pop_front();
    }
  }
  cout << endl;
}

Measured memory_bytes: 5256
#include <bits/stdc++.h>
using namespace std;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) cout << #v << "=" << endl; REP(i, v.size()){ cout << v[i] << ","; } cout << endl;
#define mdebug(m) cout << #m << "=" << endl; REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;}
#define pb push_back
#define int long long
#define INF 1000000000000000000

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;
using pairs = vector<Pii>;

template<typename T> void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readv_m1(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }

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

int mod = 1000000007;
//int mod = 998244353;
#define Add(x, y) x = (x + (y)) % mod
#define Mult(x, y) x = (x * (y)) % mod
#define AddMult(x, y, z) x = (x + (y) * (z)) % mod

class Union_find
{
public:
    vector<int> par;
    vector<int> sz;

    Union_find(int N){
        par = vector<int>(N);
        REP(i, N) par[i] = i;
        sz = vector<int>(N, 1);
    }

    int find(int x){
        if(par[x] == x) return x;
        else return par[x] = find(par[x]);
    }

    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;

        if(sz[x] < sz[y]) swap(x, y);

        par[y] = x;
        sz[x] += sz[y];
    }

    bool is_union(int x, int y){
        x = find(x);
        y = find(y);
        return x == y;
    }

    int union_size(int x){
        return sz[find(x)];
    }

};

signed main(){

    int N, M; cin >> N >> M;
    vec A(M), B(M);
    REP(i, M){
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
    }
    vec ans(M);
    int tmp = N * (N - 1) / 2;
    Union_find UF(N);
    IREP(i, M){
        ans[i] = tmp;
        if(!UF.is_union(A[i], B[i])){
            int s1 = UF.sz[UF.find(A[i])];
            int s2 = UF.sz[UF.find(B[i])];
            tmp -= s1 * s2;
            UF.unite(A[i], B[i]);
        }
    }
    REP(i, M) cout << ans[i] << endl;

    return 0;
}


Measured memory_bytes: 5248
def codei
  return gets.split.map &:to_i
end
n = codei; t, a = codei; h = codei
m = 601; ans = 0
h.length.times do |i|
  average = t - (h[i]*0.006)
  x = (a - average).abs
  if x < m
    m = x
    ans = i + 1
  end
end
puts ans


Measured memory_bytes: 3836
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
    char buf[1250];
    char *p;
    int s;

    while (1)
    {
        fgets(buf, 1250, stdin);
        p = buf;
        while (isspace(*p))
            p++;
        s = 0;
        while (isdigit(*p))
            s += *p++ - '0';
        if (s == 0)
            break;
        printf("%d\n", s);
    }
    return 0;
}


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

int main(){
  string st; cin>>st;
  int c=0,s=0;
  bool flag=false;
  for(int i=0;i<st.size();i++){
    if(flag){
      if(st[i]=='S'){
        s++;
      }else{
        if(s>0) s--;
        else c++;
        flag=false;
      }
    }else{
      if(st[i]=='S'){
        s++; 
        flag=true;
      }else{
        if(s>0) s--;
        else c++;
      }
    }
  }
  cout<<c+s<<endl;
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 21;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 62;

ll n;
ll x[e5];
ll y[e5];
ll h[e5];
ll f[e3][e3];
ll ans_x,ans_y,ans_h;
bool flag,check;
ll min_h;

bool judge(ll a,ll b,ll c){
  for(ll i = 0;i < n;i++){
    if(max(c-abs(x[i]-a)-abs(y[i]-b), 0ll) != h[i]) return false;
  }
  return true;
}

int main(){
  cin >> n;
  for(ll i = 0;i < n;i++) cin >> x[i] >> y[i] >> h[i];
  min_h = *max_element(h,h+n);
  for(ll i = 0;i <= 100;i++){
    for(ll j = 0;j <= 100;j++){
      for(ll k = 0;k <= 200;k++){
        if(judge(i,j,min_h+k)){
          cout << i << " " << j << " " << min_h+k << endl;
        }
      }
    }
  }
}


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


int main(){
    ll N;cin>>N;
    ll a[200010],b[200010],cn=0,CN=0;
    rep(i,1,N+1)cin>>a[i];
    for(int i=N;i>=1;i--){
        ll j=2;
        cn=0;
        while(j*i<=N){
            cn+=b[j*i];
            j++;
        }
        if(cn%2==a[i])b[i]=0;
        else b[i]=1;
        
        if(b[i]==1)CN++;
    }
    cout<<CN<<endl;
    rep(i,1,N+1){
        if(b[i]==1)cout<<i<<endl;
    }
}







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

#define MOD 1000000007

int main() {
  char l[1000002];
  scanf("%s", l);
  int n=strlen(l);
  long dp1[n], dp2[n];
  dp1[0] = 1; dp2[0] = 2;
  for (int i=1; i<n; i++) {
    if (l[i] == '0') {
      dp1[i] = dp1[i-1]*3;
      dp1[i] %= MOD;
      dp2[i] = dp2[i-1];
    } else {
      dp1[i] = dp1[i-1]*3+dp2[i-1];
      dp1[i] %= MOD;
      dp2[i] = dp2[i-1]*2;
      dp2[i] %= MOD;
    }
  }
  long ans = (dp1[n-1] + dp2[n-1]) % MOD;
  printf("%ld\n", ans);
  return 0;
}


Measured memory_bytes: 1792
import sys

AN, BM, AX, BY = [int(x) for x in input().split()]
As = [int(x) for x in input().split()]
Bs = [int(x) for x in input().split()]

Z = BY

for loct in Bs:
    if loct < Z:
        Z = loct
        if Z <= AX:
            print('War')
            sys.exit()

for loct in As:
    if loct >= Z:
        print('War')
        sys.exit()

print('No War')


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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;

ll INF = (1ll << 32);
double EPS = 1e-4;

ll MOD = 1000000007;

namespace std {
  template <>
  class hash<pii> {
  public:
    size_t operator()(const pii& x) const {
      return hash<ll>()(x.first) ^ hash<ll>()(x.second);
    }
  };
}

unordered_map<pii, ll> cache;

ll f(ll a, ll b) {
  if (b == 0) return 0;
  if (a == 0) return 1;

  if (cache.find(make_pair(a, b)) != cache.end()) {
    return cache[make_pair(a, b)];
  }

  ll h = 1;
  for (ll i = 0; i < a; i++) {
    h = h * 2 + 3;
  }

  ll prev_h = (h - 3) / 2;

  ll ret = 0;

  if (b >= 2) ret += f(a - 1, min(prev_h, b - 1));
  if (b >= 2 + prev_h) ret += 1;
  if (b >= 3 + prev_h) ret += f(a - 1, min(prev_h, b - 2 - prev_h));

  cache[make_pair(a, b)] = ret;

  return ret;
}

int main() {
  ll N, X;
  cin >> N >> X;

  cout << f(N, X) << endl;
}

Measured memory_bytes: 764
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#define EPS 1e-6
using namespace std;

int main() {
    long double d;
    cin >> d;
    
    long double sqrt2 = 1.414213562373;
    long double ans = max(d * sqrt2, (long double)((int)d + 1));
    printf("%.10Lf\n", ans);
    return 0;
}

Measured memory_bytes: 3284
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <stdio.h>
#include <bitset>
#include <complex>
#include <iomanip>
using namespace std;
using ll = long long;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
int main(){
    int n,ans = 0; cin >> n;
    vector<int> v(n+1,0);
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        v[a] = i+1;
    }
    int cnt = 1;
    for(int i = 2; i < n+1; i++){
        if (v[i-1] < v[i]){
            cnt++;
            ans = max(ans,cnt);
        } else {
            cnt = 1;
        }
    }
    ans = max(ans,cnt);
    cout << n-ans << endl;
}
  



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
#define x first
#define y second
#define mp make_pair
#define pb push_back
template <typename TYPE> inline void chkmax(TYPE &x,TYPE y){x<y?x=y:TYPE();}
template <typename TYPE> inline void chkmin(TYPE &x,TYPE y){y<x?x=y:TYPE();}
template <typename TYPE> void readint(TYPE &x)
{
    x=0;int f=1;char c;
    for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-1;
    for(;isdigit(c);c=getchar())x=x*10+c-'0';
    x*=f;
}
const int MAXN=100005;

int n,a[MAXN][3],b[MAXN],c[2],d[2];
int fen[MAXN];
void add(int x,int v){for(++x;x<=n;x+=(x&-x))fen[x]+=v;}
int query(int x){int s=0;for(++x;x;x-=(x&-x))s+=fen[x];return s;}

int main()
{
	readint(n);
	for(int i=0;i<3;++i)for(int j=0;j<n;++j)readint(a[j][i]),--a[j][i];
	for(int j=0;j<n;++j)
	{
		if(a[j][1]%3!=1)return 0*printf("No\n");
		b[j]=a[j][1]/3;
		if(a[j][0]/3!=b[j] || a[j][2]/3!=b[j])return 0*printf("No\n");
		c[j&1]^=(a[j][0]%3==2);
		if((b[j]&1)!=(j&1))return 0*printf("No\n");
	}
	for(int i=0;i<n;i+=2)d[1]^=(i/2-query(b[i]))&1,add(b[i],1);
	memset(fen,0,sizeof(fen));
	for(int i=1;i<n;i+=2)d[0]^=(i/2-query(b[i]))&1,add(b[i],1);
	if(c[0]!=d[0] || c[1]!=d[1])printf("No\n");
	else printf("Yes\n");
	return 0;
}

Measured memory_bytes: 2176
#include "bits/stdc++.h"

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

	std::vector<long long> a(N);
	for (auto &p : a)
		std::cin >> p;

	std::vector<long long> p_sum(N);
	p_sum[0] = a[0];
	for (int i = 1; i < N; i++)
		p_sum[i] = p_sum[i - 1] + a[i];

	long long ans = std::numeric_limits<long long>::max();
	for (int i = 0; i < N - 1; i++)
		ans = std::min(ans, std::abs(p_sum[N - 1] - 2 * p_sum[i]));

	std::cout << ans << std::endl;

	return 0;
}

Measured memory_bytes: 3328
#define R(i,n) for(i=0;i<n;i++)
t,l,b,a,I,J,s;main(n){while(scanf("%d%d%d%d",&n,&t,&l,&b),n){float d[101][101]={{}},o=0;int f[101]={};R(s,l+b)scanf("%d",&a),f[a]=s<l?1:2;d[0][0]=1;R(l,t+1){o+=d[l][n];d[l][n]=0;R(b,n+1){I=l+(f[b]-1?1:2);if(I<=t)R(s,6){J=b+s+1;if(J>n)J=2*n-J;J=f[J]-2?J:0;d[I][J]+=d[l][b]/6;}}}printf("%f\n",o);}}

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

const int maxn=200005;
const int mod=998244353;
int n,k,p,ip,ans;
int a[maxn],pw[maxn],ipw[maxn];

int power(int x,int pow){
	int res=1;
	for(;pow;pow>>=1){
		if(pow&1)res=1LL*res*x%mod;
		x=1LL*x*x%mod;
	}
	return res;
}

class Fenwick{
public:
	int t[maxn];
	void add(int v,int val){
		for(;v<=n;v+=(v&-v)){
			t[v]+=val;
			if(t[v]>=mod)t[v]-=mod;
		}
	}
	int qry(int v){
		int res=0;
		for(;v;v-=(v&-v)){
			res+=t[v];
			if(res>=mod)res-=mod;
		}
		return res;
	}
}Cnt,Sum;

int main(){
	scanf("%d%d",&n,&k);
	ans=1LL*(n-k)*(k-1)%mod*(mod+1)/2%mod;
	ans=(ans+1LL*k*(k-1)%mod*power(4,mod-2))%mod;
	p=1LL*(k-1)*power(k,mod-2)%mod;
	ip=power(p,mod-2);
	pw[0]=ipw[0]=1;
	for(int i=1;i<=n;i++)
		pw[i]=1LL*pw[i-1]*p%mod,ipw[i]=1LL*ipw[i-1]*ip%mod;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=n-1;i>=k;i--){
		Cnt.add(a[i+1],1);
		Sum.add(a[i+1],pw[i+1]);
		ans=(ans+Cnt.qry(a[i]))%mod;
		ans=(ans+1LL*(mod-Sum.qry(a[i]))*ipw[i])%mod;
	}
	for(int i=k-1;i>=1;i--){
		ans=(ans+Cnt.qry(a[i]))%mod;
		ans=(ans+1LL*(mod-Sum.qry(a[i]))*ipw[k])%mod;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 7752
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		int X = sc.nextInt();

		int m;
		int minM=0;;
		int totalM = 0;

		for (int i=0; i<N; i++){
			m = sc.nextInt();
			if (i == 0){
				minM = m;
			} else {
				minM = Math.min(minM, m);
			}
			totalM += m;
		}
		System.out.println(N + (X-totalM)/minM);
	}

}


Measured memory_bytes: 22228
# D - Static Sushi

import sys
import numpy as np

N, C = map(int, sys.stdin.buffer.readline().split())
x, v = [], []
for _ in range(N):
    tmp, tmp2 = map(int, sys.stdin.buffer.readline().split())
    x.append(tmp)
    v.append(tmp2)

x = np.array(x, np.int64)
v = np.array(v, np.int64)
v_cum = v.cumsum()
tx = np.flipud(x)
tv_cum = np.flipud(v).cumsum()
left_cum = v_cum - x

right_cum = tv_cum - np.flipud(C - x)
right_cum_max = np.maximum.accumulate(right_cum)

right_cum_return = right_cum - np.flipud(C - x)
right_cum_return_max = np.maximum.accumulate(right_cum_return)

ans = max(0, np.max(left_cum), np.max(right_cum))

for first_abandon_idx in range(1, N):
    ans = max(ans, left_cum[first_abandon_idx-1] - x[first_abandon_idx-1] + right_cum_max[N-1 - first_abandon_idx])
    ans = max(ans, left_cum[first_abandon_idx-1] + right_cum_return_max[N-1 - first_abandon_idx])

print(ans)

Measured memory_bytes: 20872
#include <bits/stdc++.h>
#define x first
#define y second
#define all(v) v.begin(), v.end()
using namespace std;

typedef long long ll;
typedef pair<ll, ll> p;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin >> n;
	cout << n*n*n;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N;
int a[110]={};
int tmp=0,avg,ans1=0,ans2=0,ans3=0,ans;
int main(){
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> a[i];
    tmp+=a[i];
  }
  avg=(int)(tmp/N);
  //cout << avg << endl;
  for(int i=0;i<N;i++){
    ans1+=(a[i]-(int)avg)*(a[i]-(int)avg);
    //cout<< ans1 << endl;
  }
  for(int i=0;i<N;i++){
    ans2+=(a[i]-(int)(avg)+1)*(a[i]-(int)(avg)+1);
    //cout<< ans2 << endl;
  }
  for(int i=0;i<N;i++){
    ans3+=(a[i]-(int)(avg)-1)*(a[i]-(int)(avg)-1);
    //cout<< ans3 << endl;
  }
  ans=min(ans1,ans2);
  ans=min(ans,ans3);
  //cout <<ans1 <<" "<< ans2<<" "<<ans3 << avg<<endl;
  cout << ans << endl;

}


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

int main(){

int x,y;
  cin >> x >> y;
  int count=0;
 for(int i=x;i<=y;i++){
 int a=i/10000,b=i%10;
 int c=i/1000%10,d=i%100/10;  
 if(a==b && c==d)count++;
   
 
 }

 cout << count << endl;   
  
  
  


}

Measured memory_bytes: 3560
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<algorithm>
#include<cmath>
//#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
template <class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template <class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template <class T> inline T gcd(T a, T b) {if(a==0) return b; return gcd(b%a,a);}
template <class T> inline T lcm(T a, T b) {return a * b / gcd(a,b);}
template <class T> inline T sum(vector<T> &vec) {T res=0; for (int i = 0; i < vec.size(); i++) res += vec[i]; return res;}
template <class T> inline T mpow(T a, T b) {if(b==0)return 1; T c = mpow(a,b/2);if(b%2==1)return c*c*a; return c*c;}
const int INF = 1 << 30;
const long long INFLL = 1LL << 60;
typedef pair<int, int> P;

#define REP(i,n) for (int (i)=0;(i)<(n);(i)++)
#define FOR(i,n) for (int (i)=0;(i)<(n);(i)++)
#define REPB(i,n) for (int (i)=((n)-1);(i)>=0;(i)--)
#define FORB(i,n) for (int (i)=((n)-1);(i)>=0;(i)--)
#define SORT(A) sort((A).begin(),(A).end())

bool same(const vint &a, const vint &b) {
    FOR(i,a.size()) {
        if (a[i] != b[i]) return false;
    }
    return true;
}

int main() {
    int N; cin >> N;
    vint P(N), Q(N);
    FOR(i,N) cin >> P[i];
    FOR(i,N) cin >> Q[i];
    vint A(N);
    FOR(i,N) A[i] = i+1;
    
    int a = 1;
    int p, q;
    do {
        if (same(P,A)) p = a;
        if (same(Q,A)) q = a;
        a++;
    } while (next_permutation(A.begin(),A.end()));
    cout << abs(p-q) << endl;
}


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

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int n,i;
	cin >> n >> i;
	cout << n-i+1 << endl;
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  if (s == "Sunny") {
    cout << "Cloudy" << endl;
  } else if (s == "Cloudy") {
    cout << "Rainy" << endl;
  } else {
    cout << "Sunny" << endl;
  }
}
  

Measured memory_bytes: 256
"use strict"

function main(input){
  const args = input.split(' ');
  const N = args[0];
  const M = args[1];

  var ans = 0;
  if(2 <= N){
    ans += N*(N-1)/2;
  }
  if(2 <= M){
    ans += M*(M-1)/2;
  }

  console.log(ans);




}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


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


namespace AtCoderWorkspace
{
    class Program
    {
        static void Main(string[] args)
        {
            var cin = new Scanner();
            var S = cin.next();

            var count = 0;
            var before = "";
            var stack = "";            
            for (int i = 0; i < S.Length; i++)
            {
                // 区切り文字候補
                stack += S[i].ToString();

                // 左からgreedy
                if(before == stack)
                {
                    continue;
                }
                else
                {
                    // 残りの文字すべてで同じになってしまう場合はだめ
                    if (i == S.Length)
                    {
                        var nokori = S.Substring(i + 1, S.Length - i);
                        if (nokori == stack) continue;
                    }

                    before = stack;
                    stack = "";
                    count++; ;
                }

            }

            Console.WriteLine(count);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

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

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

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

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

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

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

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


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


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

int main() {
  double w,h,x,y; cin >>w >>h >>x >>y;
  double ans = w*h/2;
  cout << fixed << setprecision(6) << ans << ' ';
  if(x*2==w && y*2==h)cout << 1;
  else cout << 0;
  cout << endl;
  return 0;
}

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

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

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main
{
	
	private void solve()throws IOException
	{
		String s=nextLine();
		int n=s.length();
		if(palin(s.substring(0,(n-1)/2)) && palin(s.substring((n+3)/2-1)) && palin(s))
			out.println("Yes");
		else
			out.println("No");
	}
	boolean palin(String s)
	{
		int n=s.length();
		for(int i=0;i<n/2;i++)
		{
			if(s.charAt(i)!=s.charAt(n-i-1))
				return false;
		}
		return true;
	}

	 
	///////////////////////////////////////////////////////////

	public void run()throws IOException
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();

		br.close();
		out.close();
	}
	public static void main(String args[])throws IOException{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws IOException{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws IOException{
		return br.readLine();
	}
	int nextInt()throws IOException{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws IOException{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws IOException{
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 22996
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
typedef long long ll;
typedef long double ld;
int main(){
    ll n,k;cin>>n>>k;
    vector<ll> v(n);
    REP(i,n){
        cin>>v[i];
    }
    vector<ll> list;
    map<ll,ll>  w;
    REP(i,n){
        ll cnt=w.count(v[i]);
        if(cnt){
            w.at(v[i])++;
        }else{
            w.insert(make_pair(v[i],1));
            list.push_back(v[i]);
        }
    }
    ll s=SIZE(list);
    vector<ll> x(s);
    REP(i,s){
        x[i]=w.at(list[i]);
    }
    sort(ALL(x));
    ll sum=0;
    REP(i,s-k){
        sum+=x[i];
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 20420
# -*- coding: utf-8 -*-
"""
Created on Sat Dec  8 20:51:13 2018

@author: Owner
"""

import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools

def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   

def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []

"""
N, X = map(int, input().split())

x = [0]*N
x[:] = map(int, input().split())

P = [0]*M
Y = [0]*M
for m in range(M):
    P[m], Y[m] = map(int, input().split())
    
all(nstr.count(c) for c in '753')
"""
N, K = map(int, input().split())


h = [0]*N
for n in range(N):
    h[n] = int(input())

h.sort()
diff_min = math.pow(10, 9)
diff_min = 10**9
#print(h)
for i in range(len(h)-K+1):
    #print(h[i], h[i+K-1])
    temp_diff = h[i+K-1] - h[i]
    
    if diff_min > temp_diff:
        diff_min = temp_diff
    if diff_min == 0:
        break
"""
for l in list(itertools.combinations(h,K)):
    
    temp_diff = l[np.argmax(l)] - l[np.argmin(l)]
    if diff_min > temp_diff:
        diff_min = temp_diff
    if diff_min == 0:
        break
"""     
print(diff_min)

Measured memory_bytes: 24696
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,a;
    cin>>n>>a;
    int c = 0;
    while(c <= n)
    {
        if(c + a >= n)break;
        c += 500;
    }
    if(c <= n)cout<<"Yes";
    else cout<<"No";
}


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

using namespace std;

const int MOD = 1000000007;

int main() {
    int X,Y;
    cin>>X>>Y;
    long long sum=0;
    if(X==1){
        sum+=300000;

    }else if(X==2){
        sum+=200000;
    }else if(X==3){
        sum+=100000;
    }
    if(Y==1){
        sum+=300000;

    }else if(Y==2){
        sum+=200000;
    }else if(Y==3){
        sum+=100000;
    }
    if(sum==600000){
        sum=1000000;
    }
    cout<<sum<<endl;


}

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

int n;
string x, y;
bool mat[1000][1000];
int a[1000][1000];

int max(int i, int j) {
	int r = (!mat[i - 1][j] ? a[i - 1][j] : 0);
	r = ((!mat[i][j - 1] && a[i][j - 1] > r) ? a[i][j - 1] : r);
	return r > a[i - 1][j - 1] ? r : a[i - 1][j - 1];
}

int main(){
	cin >> n;
	for (int ia = 0; ia < n; ia++) {
		int ans = 0, p = 0;
		cin >> x >> y;
		for (int i = 0; i < x.length(); i++) {
			mat[i][0] = x[i] == y[0] ? true : false;
			a[i][0] = mat[i][0] ? 1 : 0;
		}
		for (int i = 1; i < y.length(); i++) {
			mat[0][i] = x[0] == y[i] ? true : false;
			a[0][i] = mat[0][i] ? 1 : 0;
		}
		for (int i = 1; i < x.length(); i++) {
			for (int j = 1; j < y.length(); j++) {
				mat[i][j] = x[i] == y[j] ? true : false;
				a[i][j] = max(i, j) + (mat[i][j] ? 1 : 0);
				if (a[i][j] > p) p = a[i][j];
			}
		}
		if (a[x.length() - 1][0] > p) p = a[x.length() - 1][0];
		if (a[0][y.length() - 1] > p) p = a[0][y.length() - 1];
		cout << p << endl;
	}


	return 0;
}

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

using namespace std;

#define mp make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define allarr(a) a , a + n
#define ll long long
#define ull unsigned long long 
#define pb push_back
#define fastio ios_base::sync_with_stdio(false) ; cin.tie(NULL); cout.tie(NULL)
typedef pair<int, int> pi;
typedef pair<ll,ll> pll; 
typedef pair<int,pi> trp ;
typedef vector<pi> vpi;
typedef vector<pll> vpll ;
// int ab  (int  x ) { return (x>0?x:-x); }
const int N = 1e4+5 ; 
const ll mod = 1e9+7 ; 
ll dp[N][105][2]; 
int n , D; 
string s; 
ll solve(int i, int rem , int b){
	if(i==n){
		if( !rem )
		return 1;
		return 0 ; 
	} 
	ll& r = dp[i][rem][b] ;
	if( r != - 1 )return r ;
	r = 0 ; 
	int digit = s[i]-'0' ; 
	if( b == 1 ){
		r += solve(i+1,(rem+digit)%D,1) ; 
		r%=mod ; 
		for(int x = 0 ; x < digit ; x++ ){
			r += solve(i+1,(rem+x)%D,0) ;
			r%=mod ;  
		}
	}else {
		for(int x = 0 ; x <= 9 ; x++ ){
			r += solve(i+1,(rem+x)%D,0) ; 
			r %= mod ; 
		}
	}
	return r ; 
}
int main(){ 
	cin >> s >> D ; 
	n = s.length() ; 
	memset(dp,-1,sizeof dp); 
	cout << (solve(0,0,1)-1+mod)%mod <<endl; 
}

Measured memory_bytes: 17280
x,n = gets.split.map(&:to_i)
z = gets.split.map(&:to_i)
i = 0
while true
  if not z.include?(x-i)
    puts x-i
    break
  end
  i = -i
  i += 1
  if not z.include?(x-i)
    puts x-i
    break
  end
  i = -i
end

Measured memory_bytes: 14320
#include<stdio.h>
main(){
  while(1){
    int n,a,b,sa=0,sb=0,i;
  scanf("%d",&n);
  if(n==0) break;
  for(i=0;i<n;i++){
    scanf("%d %d",&a,&b);
    if(a>b)sa+=a+b;
    else if(a==b)sa+=a,sb+=b;
    else sb+=a+b;
  }
  printf("%d %d\n",sa,sb);
  }
  return 0;
}
    

Measured memory_bytes: 600
//-----------------------
// author : xyqkoala
// time : 2020-07-06
//-----------------------

#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;

void solve();


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


void solve(){
	int m,n,k;
	cin>>m>>n>>k;
	vector<string> mat(m);
	for(int i=0;i<m;i++){
		cin>>mat[i];
	}
	int res = 0;
	for(int i=0;i<(1<<m);i++){
		for(int j=0;j<(1<<n);j++){
			int cnt = 0;
			for(int p=0;p<m;p++){
				if((1<<p)&i) continue;
				for(int q=0;q<n;q++){
					if((1<<q)&j) continue;
					if(mat[p][q]=='#') cnt++;
				}
			}
			if(cnt==k) res++;
		}
	}
	cout<<res<<endl;
}


Measured memory_bytes: 3660
n = int(input())
list_point = [0, 0]

for _ in range(n):
    word1, word2 = map(str, input().split(" "))
    if word1 == word2:
        list_point[0] += 1
        list_point[1] += 1
    elif word1 > word2:
        list_point[0] += 3
    elif word1 < word2:
        list_point[1] += 3
    else:
        print("Error!")

print(list_point[0], list_point[1])


Measured memory_bytes: 5600
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>

//using namespace std;
int main() {
    int N, Q;
    //long long S[200001], T[200001];
    long long X[200001];
    long long D[200001];
    double starts[200001];
    double ends[200001];
    std::cin >> N >> Q;
    for (int i=0; i<N; i++) {
        long long s, t;
        std::cin >> s >> t >> X[i];
        starts[i] = s - X[i];
        starts[i] -= 0.5;
        if (starts[i] < 0) starts[i] = 0;
        ends[i] = t - X[i];
        ends[i] -= 0.5;
        if (ends[i] < 0) ends[i] = 0;
    }
    long long maxD = -1;
    for (int i=0; i<Q; i++) {
        std::cin >> D[i];
        if (maxD == -1 || maxD < D[i]) maxD = D[i];
    }
    
    // argsort D
    std::vector<int> indices(Q);
    std::iota(indices.begin(), indices.end(), 0);
    std::sort(indices.begin(), indices.end(), [&D](int i1, int i2) {
        return D[i1] < D[i2];
    });

    // argsort
    std::vector<int> startIdx(N);
    std::iota(startIdx.begin(), startIdx.end(), 0);
    std::sort(startIdx.begin(), startIdx.end(), [&starts](int i1, int i2) {
        return starts[i1] < starts[i2];
    });
    std::vector<int> endIdx(N);
    std::iota(endIdx.begin(), endIdx.end(), 0);
    std::sort(endIdx.begin(), endIdx.end(), [&ends](int i1, int i2) {
        return ends[i1] < ends[i2];
    });
    std::cerr << "sort done" << std::endl;

    auto Dite = indices.begin();
    auto startite = startIdx.begin();
    auto endite = endIdx.begin();
    long long Qscore[200001];
    //long long current = -1;

    std::priority_queue<long long> working;
    std::priority_queue<long long> deleted;
    while (Dite != indices.end()) {
    //std::cerr << "done" << std::endl;
        if (startite == startIdx.end() || D[*Dite] < starts[*startite]) {
            if (endite == endIdx.end() || D[*Dite] < ends[*endite]) {
                // update queue
                while (!working.empty() && !deleted.empty()) {
                    if (working.top() == deleted.top()) {
                        working.pop(); deleted.pop();
                    } else break;
                }
                if (working.empty()) {
                    Qscore[*Dite] = -1;
                } else {
                    Qscore[*Dite] = -working.top();
                }
                //Qscore[*Dite] = current;
                Dite++;
            }
            else {
                // update end
                deleted.push(-X[*endite]);
                endite++;
            }
        } else {
            working.push(-X[*startite]);
            startite++;
        }
    }
    for (int i=0; i<Q; i++) {
        std::cout << Qscore[i] << std::endl;
    }
    return 0;
}



Measured memory_bytes: 14704
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
//#define INF 1e18
#define MOD 1000000007

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

int n,m,q;
int a[55],b[55],c[55],d[55];
int ans;

void check(vector<int> v){
  int u=0;
  rep(i,0,q){
    if(v[b[i]] - v[a[i]] == c[i])u += d[i];
  }
  ans = max(ans,u);
}

void dfs(vector<int> v){
  if(v.size() == n){
    check(v);
    return;
  }
  int t = v[v.size()-1];
  rep(i,t,m+1){
    vector<int> u=v;
    u.push_back(i);
    dfs(u);
  }
}



int main(){
  cin >> n >> m >> q;
  rep(i,0,q){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--;
    b[i]--;
  }
  rep(i,1,m+1){
    vector<int> k(1,i);
    dfs(k);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3584
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys  # {{{
import os
import time
import re
from pydoc import help
import string
import math
from operator import itemgetter
from collections import Counter
from collections import deque
from collections import defaultdict as dd
import fractions
from heapq import heappop, heappush, heapify
import array
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy as dcopy
import itertools
# }}}

# pre-defined{{{
sys.setrecursionlimit(10**7)
INF = 10**20
GOSA = 1.0 / 10**10
MOD = 10**9+7
ALPHABETS = [chr(i) for i in range(ord('a'), ord('z')+1)]  # can also use string module
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def DP(N, M, first): return [[first] * M for n in range(N)]
def DP3(N, M, L, first): return [[[first] * L for n in range(M)] for _ in range(N)]
from inspect import currentframe
def dump(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' => '+repr(arg) for arg in args), file=sys.stderr)
# }}}

def local_input():# {{{
    from pcm.utils import set_stdin
    import sys
    from pathlib import Path
    parentdir = Path(os.path.dirname(__file__)).parent
    inputfile = parentdir.joinpath('test/sample-1.in')
    if len(sys.argv) == 1:
        set_stdin(inputfile)
# }}}

def solve():
    k,a,b = map(int, input().split())
    res = 0
    if (a+2)<b:
        if (a+2)>(k+1):
            res = k+1
        else:
            r = (k+1)-(a+2)
            dump(r, b-a)
            res = b
            res += (r//2)*(b-a)
            res += r%2
    else:
        res = k+1

    print(res)

    return 0

if __name__ == "__main__":# {{{
    try:
        local_input()
    except:
        pass
    solve()
# vim: set foldmethod=marker:}}}


Measured memory_bytes: 104940
[n,a,b]=list(map(int,input().split()))
xlist=list(map(int,input().split()))
ans=0
for i in range(1,n):
    walk=(xlist[i]-xlist[i-1])*a
    if (walk<b): #歩いたほうが楽
        ans+=walk
    else:
        ans+=b
ans=int(ans)
print(ans)

Measured memory_bytes: 14252
def dl2(n):
    if n % 2 == 1:
        return 0
    else:
        return 1 + dl2(n/2)

def main():
    N = input().split(" ")
    t = input().split(" ")
    ans = 0
    for i in t:
        ans += dl2(int(i))
    print(ans)

main()


Measured memory_bytes: 3892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int f(int a, int b, int c, int d){
    return 64*a + 16*b + 4*c + d;
}

bool exist(vector<int> x, int y){
    return find(ALL(x), y) != x.end();
}

int main(){
    int N; cin >> N;
    vector<int> ng;
    for (int i = 0; i < 4; i++) {
        ng.push_back(f(i,3,2,1));
        ng.push_back(f(i,3,1,2));
        ng.push_back(f(i,2,3,1));
        ng.push_back(f(3,i,2,1));
        ng.push_back(f(3,2,i,1));
    }
    vector<vector<ll>> dp(N+1, vector<ll> (64, 0));
    for (int i = 0; i < 64; i++) {
        if(!exist(ng, i)){
            dp[3][i] = 1;
        }
        else{
            dp[3][i] = 0;
        }
    }
    //配るdp
    for (int i = 3; i < N; i++) {
        for (int j = 0; j < 64; j++) {
            for (int k = 0; k < 4; k++) {
                int tmp = j*4 + k;
                if(!exist(ng, tmp)){
                    dp[i+1][tmp % 64] += dp[i][j];
                    dp[i+1][tmp % 64] = dp[i+1][tmp % 64] % MOD;
                }
            }
        }
    }

    ll ans = 0;
    for (int i = 0; i < 64; i++) {
        ans += dp[N][i];
        ans = ans % MOD;
    }
    printf("%lld\n", ans);



}

Measured memory_bytes: 3716
input_line=int(input())
count=0
input_list=map(int,input().split())
approved=True
for item in input_list:
    if int(item)%2==0 and not (int(item)%3==0 or int(item)%5==0):
        approved=False
        break
if approved==True:
    print ("APPROVED")
else:
    print ("DENIED")
        

Measured memory_bytes: 2940
from numpy import *
from scipy import *
from sys import *

w, h = map(int, input().split())
p = ndarray(w+1, dtype=int)
q = ndarray(h+1, dtype=int)

for i in range(w):
    p[i] = int(input())
for i in range(h):
    q[i] = int(input())
p[w] = maxsize
q[h] = maxsize
p, q = sort(p), sort(q)

ans = 0

i, j = 0, 0
w_, h_ = w+1, h+1
while i < w or j < h:
    if p[i] < q[j]:
        ans += p[i]*h_
        w_ -= 1
        i += 1
    else:
        ans += q[j]*w_
        h_ -= 1
        j += 1

print(ans)


Measured memory_bytes: 16160
#include<stdio.h>
int main(void){
	int a,b,c;
	scanf("%d %d",&a,&b);
	while(a!=0){
		if(a>2 && a<=8){
			if(a%2==0){
				c=a/2*31+(a/2-1)*30+b-1;
			}
			else{
				c=a/2*61+b-1;
			}
		}
		if(a>8){
			if(a%2==0){
				c=a/2*31+(a/2-1)*30+b-1;
			}
			else{
				c=(a/2+1)*31+(a/2-1)*30+b-1;
			}
		}
		if(a==2)c=a/2*31+b;
		if(a==1)c=b;
		c%=7;
		if(c==0)printf("Wednesday\n");
		if(c==1)printf("Thursday\n");
		if(c==2)printf("Friday\n");
		if(c==3)printf("Saturday\n");
		if(c==4)printf("Sunday\n");
		if(c==5)printf("Monday\n");
		if(c==6)printf("Tuesday\n");
		scanf("%d %d",&a,&b);
	}
	return 0;
}

Measured memory_bytes: 584
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;

int n,k;
vector<int> g[2001];
int color[2][2001];

void dfs(int p,int s,int d){
    color[p][s]=1;
    if(d==0) return;
    for(auto i:g[s]){
        if(color[p][i]==0) dfs(p,i,d-1);
    }
}

void add_edge(int s,int t){
    g[s].PB(t); g[t].PB(s);
}

int dc(){
    int s=0;
    FOR(i,0,n) s+=(color[0][i]||color[1][i]);
    return n-s;
}

int main(){
    cin>>n>>k;
    FOR(i,0,n-1){
        int a,b; cin>>a>>b;
        add_edge(a-1,b-1);
    }
    int m=INF;
    if(k%2==0)
        FOR(i,0,n){
            memset(color,0,sizeof(color));
            dfs(0,i,k/2);
            m=min(m,dc());
        }
    else
        FOR(i,0,n){
            for(auto j:g[i]){
                if(i<j){
                    memset(color,0,sizeof(color));
                    dfs(0,i,k/2);
                    dfs(1,j,k/2);
                    m=min(m,dc());
                }
            }
        }
    cout<<m<<endl;
}


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

using namespace std;

#define fcout(d) cout << fixed << setprecision(d)
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rep1(i,n) for(int (i) = 1; (i) <= (n); ++(i))
#define repU(i,bottom,ceiling) for(auto (i) = (bottom); (i) <= (ceiling); ++(i))
#define repD(i,ceiling,bottom) for(auto (i) = (ceiling); (i) >= (bottom); --(i))
#define repS(n) for(int s = 0; s < 1 << n; ++s)
#define repV(i,v) for(auto (i) = begin(v); (i) < end(v); ++(i))
#define all(v)  begin(v),end(v)
#define clr(v) fill(all(v),0)
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mkp make_pair
#define mkt make_tuple
#define fir first
#define sec second
#define parity(a,b) (((a) & 1)^((b) & 1)^1)

typedef long long ll;
typedef unsigned long long ull;
typedef double db;

const pair<int,int> DIR[] = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const int INF = -1 + (1<<30);
const int MOD = (int)1e9 + 7;

template<class T,class U> auto LB(T v, U in){ return lower_bound(all(v), in); }

template<class T,class U> auto UB(T v, U in){ return upper_bound(all(v), in); }

ull next_subset(ull subset){
	ull tem = subset + (subset & -subset);
	ull btm = (~tem & subset) / (subset & -subset) >> 1;
	return btm | tem;
}

int N,Y;

void solve(){
	
	bool j = 0;
	int l = Y/1000;
	
	for(int cnt_1 = l; cnt_1 >= 0; cnt_1 -= 5){
		int k = (l - cnt_1)/5;
		for(int cnt_5 = k; cnt_5 >= 0; cnt_5 -= 2){
			int cnt_10 = (k - cnt_5)/2;
			if(N == cnt_1 + cnt_5 + cnt_10){
				cout<<cnt_10<<' '<<cnt_5<<' '<<cnt_1<<endl;
				return;
			}
		}
	}
	
	cout<<"-1 -1 -1\n";
	
	return;
}

void input(){
	
	cin>>N>>Y;
	
	return;
}

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





Measured memory_bytes: 256
#### import ####
import sys
import math
from collections import defaultdict

#### 設定 ####
sys.setrecursionlimit(10**7)

#### 定数 ####
mod = 10**9 + 7

#### 読み込み ####
def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
  read_all = [tuple(map(int, input().split())) for _ in range(N)]
  return map(list,zip(*read_all))

#################

S = str(input())
n = len(S)
ans = [0]*n

left = 0
while left<=n-1:
  R_pos = n-1
  for i in range(left,n):
    if S[i]=='L':
      R_pos = i-1
      L_pos = i
      break
  if R_pos == n-1:
    ans[R_pos] += R_pos-left + 1
    break
  right = n-1
  for j in range(i+1,n):
    if S[j] == 'R':
      right = j-1
      break
  ans[R_pos] += (R_pos-left)//2 + (right-R_pos)//2 + 1
  ans[L_pos] += (L_pos-left)//2 + (right-L_pos)//2 + 1
  if right == n-1:
    break
  left = j

print(*ans)

Measured memory_bytes: 51128
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define f first
#define s second
#define mp make_pair
using namespace std;

ll func(ll n, ll x)
{
	if(n<x) swap(n,x);
	if(n%x==0) return 2*(n/x)*x-x;
	return 2*(n/x)*x+func(n%x,x);
}


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,x;
	cin>>n>>x;
	ll ans =0;
	ans += n;
	ans += func(n-x,x);
	cout<<ans<<endl;
	return 0;
}

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

int top, stack[1000];

int pop() {
  top--;
  return stack[top + 1];
};

void push(int val) { stack[++top] = val; }

int main() {
  int a, b;
  top = 0;
  char s[100];
  while (scanf("%s", s) != EOF) {
    if (s[0] == '+') {
      a = pop();
      b = pop();
      push(a + b);
    } else if (s[0] == '-') {
      b = pop();
      a = pop();
      push(a - b);
    } else if (s[0] == '*') {
      a = pop();
      b = pop();
      push(a * b);
    } else {
      push(atoi(s));
    }
  }
  printf("%d\n", pop());
  return 0;
}


Measured memory_bytes: 3228
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

using namespace std;

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

long long int INF = 2147483647;
int const TREE_SIZE = 1 << 20;
long long int seg_tree[TREE_SIZE];
bool is_a[TREE_SIZE];

int find(int a, int b, int index, int l, int r){
	
	// 外からは query(a, b, 1, 0, TREE_SIZE / 2) のように呼ぶ
	if(r <= a || b <= l){
		return INF;
	}
	//cout << is_a[index] << " " << l << " " << r << endl;
	if(a <= l && r <= b){
		return seg_tree[index];
	}
	if(is_a[index]){
		return seg_tree[index];
	}
	int ret = INF;
	ret = min(ret, find(a, b, index * 2, l, (l + r) / 2));
	ret = min(ret, find(a, b, index * 2 + 1, (l + r) / 2, r));
	return ret;
}

int update(int a, int b, int index, int num, int l, int r){
	
	// 外からは query(a, b, 1, 0, TREE_SIZE / 2) のように呼ぶ
	
	if(r <= a || b <= l){
		return seg_tree[index];
	}
	if(a <= l && r <= b){
		seg_tree[index] = num;
		is_a[index] = true;
		return num;
	}
	int ret = INF;
	if(is_a[index]){
		is_a[index * 2] = true;
		seg_tree[index * 2] = seg_tree[index];
		is_a[index * 2 + 1] = true;
		seg_tree[index * 2 + 1] = seg_tree[index];
		is_a[index] = false;
		ret = seg_tree[index];
	}
	ret = min(ret, update(a, b, index * 2, num, l, (l + r) / 2));
	ret = min(ret, update(a, b, index * 2 + 1, num, (l + r) / 2, r));
	return seg_tree[index] = ret;
}

int main(){
	
	int n, q;
	cin >> n >> q;
	
	for(int i = 0; i < TREE_SIZE; i++){
		seg_tree[i] = INF;
		is_a[i] = false;
	}
	is_a[1] = true;
	
	for(int i = 0; i < q; i++){
		long long int num, a, b, c;
		cin >> num;
		if(num == 0){
			cin >> a >> b >> c;
			update(a, b + 1, 1, c, 0, TREE_SIZE / 2);
		}else{
			cin >> a >> b;
			cout << find(a, b + 1, 1, 0, TREE_SIZE / 2) << endl;
		}
		for(int j = 0; j < n; j++){
			//cout << find(j, j + 1, 1, 0, TREE_SIZE / 2) << " ";
		}
		//cout << endl;
	}
	
	return 0;
}


Measured memory_bytes: 12340