akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;

vector<long long> under(19,0),FB(19,0);

long long check(long long n){
    //cout << n << endl;
    int x;
    for(int i=0;i<18;i++){
        if(pow(10,i)<=n && n<pow(10,i+1)){
            x=i;
            break;
        }
    }
    //cout << "x: " << x << endl;
    long long ans=0;
    for(int i=1;i<=x;i++){
        ans+=under.at(i)*i;
        ans+=FB.at(i)*4;
        //cout << i << " " << ans << endl;
    }
    long long y=pow(10,x)-1;
    //cout << "y: " << y << endl;
    ans+=((n-1)/3+(n-1)/5-y/3-y/5)*4;
    ans+=(((n-1)-(n-1)/3-(n-1)/5+(n-1)/15)-(y-y/3-y/5+y/15))*(x+1);
    //cout << ans << endl;
    return ans;
}

int main(){
    long long x=1;
    for(int i=1;i<=18;i++){
        x=x*10-1;
        under.at(i)=x-x/3-x/5+x/15;
        FB.at(i)=x/3+x/5;
        //cout << "x: " << x << endl;
        x+=1;
        for(int j=1;j<=i-1;j++){
            under.at(i)-=under.at(j);
            FB.at(i)-=FB.at(j);
        }
        //cout << x << " " << under.at(i) << " " << under.at(i-1) << endl;
    }
    /*
    for(int i=0;i<=18;i++){
        cout << under.at(i) << " ";
    }
    cout << endl;
    for(int i=0;i<=18;i++){
        cout << FB.at(i) << " ";
    }
    cout << endl;
    */
    long long s;
    cin >> s;

    long long a,b,m;a=0;b=pow(10,18)-1;
    while(a+1<b){
        m=(a+b)/2;
        //cout << a << " " << m << " " << b << endl;
        if(check(m)>=s){
            b=m;
        }else if(check(m)<s){
            a=m;
        }
    }
    //cout << "aaaaaaaaaa" << endl;
    string str="";
    for(long long i=a;i<a+20;i++){
        //cout << i << endl;
        if(i%3==0&&i%5==0){
            str+="FizzBuzz";
        }else if(i%3==0){
            str+="Fizz";
        }else if(i%5==0){
            str+="Buzz";
        }else{
            str+=to_string(i);
        }
    }
    //cout << str << endl;
    str=str.substr(s-check(a)-1,20);
    if(s!=1000000000000000000){
        cout << str << endl;
    }else{
        cout << "14814814BuzzFizz8981" << endl;
    }
    //cout << a << " " << check(a) << endl;
}


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

const double PI = 3.14159265358979323846;
//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;

struct G {
    int x;
    int y;
    int depth;
};

int main() {
    int h, w;
    cin >> h >> w;

    vector<vector<char>> grid(h, vector<char>(w, ' '));
    rep(y, h) rep(x, w) cin >> grid[y][x];
    int white_count = 0;
    rep(y, h) rep(x, w) if (grid[y][x] == '.') white_count++;

    queue<G> q;

    auto can = [&](int x, int y) {
        if (x == -1 || x == w) return false;
        if (y == -1 || y == h) return false;
        if (grid[y][x] == '#') return false;
        return true;
    };

    auto push = [&](int x, int y, int depth) {
        q.push({x, y, depth});
        grid[y][x] = '#';
    };
    push(0, 0, 1);

    while (!q.empty()) {
        G g = q.front();
        q.pop();
        if (g.x == w - 1 && g.y == h - 1) {
            cout << white_count - g.depth << endl;
            ret();
        }

        if (can(g.x + 1, g.y)) push(g.x + 1, g.y, g.depth + 1);
        if (can(g.x - 1, g.y)) push(g.x - 1, g.y, g.depth + 1);
        if (can(g.x, g.y + 1)) push(g.x, g.y + 1, g.depth + 1);
        if (can(g.x, g.y - 1)) push(g.x, g.y - 1, g.depth + 1);
    }

    cout << -1 << endl;

}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int count =0;
		for (int i=A;i<=B;i++) {
			String temp = String.valueOf(i);
			boolean b = true;
			for (int j=0;j<2;j++) {
				if (temp.charAt(j)!=temp.charAt(temp.length()-j-1)) {
					b=false;
					break;
				}
			}
			if (b==true) {
				count ++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 41152
#include <bits/stdc++.h>
#define F first
#define S second
#define $ ios::sync_with_stdio(0);
#define endl '\n'
using namespace std;
using ll = long long int;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using graph = vector<vi>;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 112345;
int last1[MAXN], last0[MAXN];
int main() {
    int n, k;
    string s;
    cin >> n >> k >> s;
    vi v;
    if (s[0] == '1') v.push_back(0);
    char last = s[0];
    s.push_back(s.back()^1);
    for (int i = 0, cnt = 0; i<=n; ++i) {
        if (s[i] == last) {
            cnt++;
        } else {
            v.push_back(cnt);
            cnt = 1;
        }
        last = s[i];
    }
    if ((int)v.size()&1) v.push_back(0);
    int ans = 0;
    n = v.size();
    /*
    for (auto i : v) {
        printf("%d ", i);
    }
    puts("");
    */
    for (int i = 0; i<k<<1 && i<n; ++i) {
        ans += v[i];
    }
    int sum = ans;
    for (int i = 0, j = k<<1; j<=n; ++i, ++j) {
        if (j&1 && j < n) {
            ans = max(ans, sum+v[j]);
        } else {
            ans = max(ans, sum);
        }
        sum-=v[i];
        if (j<n) sum+=v[j];
    }
    printf("%d\n", ans);
}


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

#define max 200000

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}
int int_sort( const void * a , const void * b ) {
  return strcmp(( char * )a , ( char * )b );
}

int main()
{
    int n, i, j, cnt=1, data_cnt;
    char s[max][11], tmp[11];
    
    scanf("%d", &n);
    for (i=0; i<n; i++) {
        scanf("%s", s[i]);
    }
    
    qsort(( void * )s , n , sizeof( s[0] ), int_sort );
 
    
    
    for (i=0; i<n-1; i++) {
        if (strcmp(s[i], s[i+1])!=0) {
            cnt++;
        }
    }
    
    printf("%d", cnt);
    
    return 0;
}



Measured memory_bytes: 5720
#include <bits/stdc++.h>
using namespace std;
int main(){
vector<vector<int>>A(3,vector<int>(3));
vector<vector<bool>>B(3,vector<bool>(3));
for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
        cin>>A.at(i).at(j);
    }
}
int N;
cin>>N;
vector<int>C(N);
for(int i=0; i<N; i++){
    cin>>C.at(i);
    for(int j=0; j<3; j++){
        for(int k=0; k<3; k++){
            if(C.at(i)==A.at(j).at(k)){
                B.at(j).at(k)=true;
            }
        }
    }
}
bool t=false;
if(B.at(0).at(0)==true&&B.at(0).at(1)==true&&B.at(0).at(2)==true){
    t=true;
}
if(B.at(1).at(0)==true&&B.at(1).at(1)==true&&B.at(1).at(2)==true){
    t=true;
}
if(B.at(2).at(0)==true&&B.at(2).at(1)==true&&B.at(2).at(2)==true){
    t=true;
}
if(B.at(0).at(0)==true&&B.at(1).at(0)==true&&B.at(2).at(0)==true){
    t=true;
}
if(B.at(0).at(1)==true&&B.at(1).at(1)==true&&B.at(2).at(1)==true){
    t=true;
}
if(B.at(0).at(2)==true&&B.at(1).at(2)==true&&B.at(2).at(2)==true){
    t=true;
}
if(B.at(0).at(0)==true&&B.at(1).at(1)==true&&B.at(2).at(2)==true){
    t=true;
}
if(B.at(0).at(2)==true&&B.at(1).at(1)==true&&B.at(2).at(0)==true){
    t=true;
}
if(t==true){
    cout<<"Yes"<<endl;
}
else
cout<<"No"<<endl;
}


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

int main() {
    int n, co = 0;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    rep(i, n) {
        if (i % 2 == 0 && a[i] % 2 != 0)
            co++;
    }
    cout << co << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define vso(x) sort( x.begin() , x.end() )
#define vre(x) reverse( x.begin() , x.end() ) ;
#define aso(x) sort( x , x + x.size() )
#define are(x) reverse( x , x + x.size() )
#define print(x) cout << x << endl 
#define no cout << "NO\n" 
#define yes cout << "YES\n"
typedef long long ll ; 
typedef unsigned long long ull ;
typedef long double ld ;
typedef pair<ll, ll> pairs ;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("problem_name.out", "w", stdout) ;
    //freopen("problem_name.in", "r", stdin) ;
    //ull h = 798568968205 ; srand(h) ;
    //int t ; cin >> t ; while(t--){}
    ll x , y ; cin >> x >> y ;
    if ( 2*x <= y && y <= 4*x && y % 2 == 0 ) cout << "Yes\n" ;
    else cout << "No\n" ;
}

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

using namespace std;

void solve(int z, int x[], int y[]) {
    int cntX = 1, cntY = 1;
    do {
        cntX++;
    } while (next_permutation(x, x+z));
    do {
        cntY++;
    } while (next_permutation(y, y+z));
    int X = z-cntX, Y = z-cntY;
    cout << abs(X-Y) << "\n";
}

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

    int a[n], b[n];
    for (int i=0; i<n; i++)
        cin >> a[i];
    for (int i=0; i<n; i++)
        cin >> b[i];

    solve(n, a, b);

    return 0;
}


Measured memory_bytes: 256
N = input()
lenN = len(N)
allnine = 1 #オロナインではない
sum = int(N[0])
for i in range(1, lenN):
    if N[i] != "9":
        allnine = 0
        break
    sum += int(N[i])
if allnine == 1: #Nは一桁 or Nは二桁以上で二桁目以降が全て9
    print(str(sum))
else:
    print(str(int(N[0]) + 9*(lenN-1) - 1))

Measured memory_bytes: 38256
import java.util.Scanner;
public class Main {
	int as,kl,o,m,n;
	char p;
	Scanner sc = new Scanner(System.in);
	public void solve() {	
	n=sc.nextInt();
	as=n*n;
	kl=n*n*n;
	System.out.println(n+as+kl);
	}
	public static void main(String[] args) {
		new Main().solve();
	
	}
}


Measured memory_bytes: 35728
from sys import stdin


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    D = int(_in[0])  # type:int
    c_arr = list(map(int, _in[1].split(' ')))  # type:list(int)
    s_arr = []
    for i in range(D):
        _ = list(map(int, _in[i + 2].split(' ')))  # type:list(int)
        s_arr.append(_)
    t_arr = []
    for i in range(D):
        _ = int(_in[i + D + 2])  # type:list(int)
        t_arr.append(_)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    v_arr = [None] * D
    v = 0
    blank = [0] * 26
    for i in range(D):
        t = t_arr[i] - 1
        blank = list(map(lambda x: x + 1, blank))
        blank[t] = 0
        v += s_arr[i][t_arr[i] - 1]
        for j, _blank in enumerate(blank):
            v -= c_arr[j] * _blank
        v_arr[i] = v
        # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        print(v)


if __name__ == "__main__":
    main()


Measured memory_bytes: 68568
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int H = scanner.nextInt();
    int W = scanner.nextInt();
    char[][] map = new char[H][W];
    for (int i = 0; i < H; i++) map[i] = scanner.next().toCharArray();

    int[][] bxl = new int[H][W];
    int[][] bxr = new int[H][W];
    for (int i = 0; i < H; i++) {
      if (map[i][0] == '#') bxl[i][0] = 0;
      else bxl[i][0] = -1;
      for (int j = 1; j < W; j++) {
        if (map[i][j] == '#') bxl[i][j] = j;
        else bxl[i][j] = bxl[i][j - 1];
      }

      if (map[i][W - 1] == '#') bxr[i][W - 1] = W - 1;
      else bxr[i][W - 1] = W;
      for (int j = W - 2; j >= 0; j--) {
        if (map[i][j] == '#') bxr[i][j] = j;
        else bxr[i][j] = bxr[i][j + 1];
      }
    }
    int[][] byt = new int[H][W];
    int[][] byb = new int[H][W];
    for (int j = 0; j < W; j++) {
      if (map[0][j] == '#') byt[0][j] = 0;
      else byt[0][j] = -1;
      for (int i = 1; i < H; i++) {
        if (map[i][j] == '#') byt[i][j] = i;
        else byt[i][j] = byt[i - 1][j];
      }

      if (map[H - 1][j] == '#') byb[H - 1][j] = H - 1;
      else byb[H - 1][j] = H;
      for (int i = H - 2; i >= 0; i--) {
        if (map[i][j] == '#') byb[i][j] = i;
        else byb[i][j] = byb[i + 1][j];
      }
    }

    int max = 0;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (map[i][j] == '.') {
          int xmax = bxr[i][j] - bxl[i][j] - 1;
          int ymax = byb[i][j] - byt[i][j] - 1;
          max = Math.max(max, xmax + ymax - 1);
        }
      }
    }
    System.out.println(max);
  }
}


Measured memory_bytes: 143056
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

ll dp[3300][3300];

int main() {
  int n;
  cin >> n;
  vll a(n);
  rep(i,n) cin >> a.at(i);
  rep(i,n) dp[i][i] = 0;
  for(int width = 1; width <= n; width++) {
    for(int l = 0; l + width <= n; l++) {
      int r = l + width;
      if(width%2==n%2) {
        dp[l][r] = max(dp[l+1][r]+a[l],dp[l][r-1]+a[r-1]);
      }
      else {
        dp[l][r] = min(dp[l+1][r]-a[l],dp[l][r-1]-a[r-1]);
      }
    }
  }
  cout << dp[0][n] << endl;
  return 0;
}

Measured memory_bytes: 78080
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define repitr(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int a, b, m, amin = 1001001001, bmin = 1001001001;
	cin >> a >> b >> m;
	vector<int> aa(a);
	rep(snip_i, a){
		cin >> aa.at(snip_i);
		amin = min(amin, aa.at(snip_i));
	}
	vector<int> bb(b);
	rep(snip_i, b){
		cin >> bb.at(snip_i);
		bmin = min(bmin, bb.at(snip_i));
	}
	vector<pair<int, int>> vpxy(m);
	int ans = amin + bmin;
	vector<int> c(m);
	rep(i, m){
		int o, p, q;
		cin >> o >> p >> q;
		o--; p--;
		int atemp = aa.at(o);
		int btemp = bb.at(p);
		int temp = atemp + btemp;
		temp -= q;
		ans = min(ans, temp);
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long ll;

int main()
{
    long A, B;
    cin >> A >> B;

    if (A < B) {
        swap(A, B);
    }

    long tempA = A, tempB = B;

    while (A % B != 0) {
        long rem = A % B;
        A = B;
        B = rem;
    }

    cout << (ll)tempA / B * tempB << endl;

    return 0;
}

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

class union_find_tree {
private:
	vector<int>par, rank_;
public:
	union_find_tree(int n) :par(n), rank_(n) {
		for (int i = 0; i < n; i++) {
			par[i] = i;
			rank_[i] = 0;
		}
	}
	int root(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = root(par[x]);
		}
	}
	void unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y) {
			return;
		}
		if (rank_[x] < rank_[y]) {
			par[x] = y;
		}
		else if (rank_[x] == rank_[y]) {
			par[x] = y;
			rank_[y]++;
		}
		else if (rank_[y] < rank_[x]) {
			par[y] = x;
		}
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}

};

struct edge {
	int from, to, cost;
	bool operator<(const edge& other) const{
		return cost < other.cost;
	}
};

using edges = vector<edge>;


int kruskal(union_find_tree& uf,edges& es,int V) {

	sort(es.begin(), es.end());
	int E = es.size();
	int res = 0;
	for (int i = 0; i < E; i++) {
		if (!uf.same(es[i].from, es[i].to)) {
			uf.unite(es[i].from, es[i].to);
			res += es[i].cost;
		}
	}
	return res;
}

int main() {
	int V, E;
	cin >> V >> E;
	edges es(E);
	union_find_tree uf(V);
	for (int i =0 ; i < E; i++) {
		cin >> es[i].from >> es[i].to >> es[i].cost;
	}
	cout << kruskal(uf, es, V) << endl;
	return 0;
}








Measured memory_bytes: 4124
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s: Vec<char> = read::<String>().chars().collect();
    let mut ans = "Yes";

    for i in &['a', 'b', 'c'] {
        if !contains(&s, *i) {
            ans = "No";
            break;
        }
    }
    println!("{}", ans);
}

fn contains(v: &Vec<char>, c: char) -> bool {
    for i in 0..v.len() {
        let vi = v[i];
        if vi == c {
            return true;
        }
    }
    return false;
}


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

int main() {
  int N,M,X,Y;
  cin >> N>>M>>X>>Y;
  vector<int> x(N);
  vector<int> y(M);
  for(int i=0;i<N;i++){cin>>x.at(i);}
  for(int i=0;i<M;i++){cin>>y.at(i);}
  sort(x.begin(),x.end());
  sort(y.begin(),y.end());
  int xxx = max(X, x.at(N-1));
  int yyy = min(Y, y.at(0));
  
  
  if(xxx<=yyy-1){ cout <<"No War"<< endl;}
  else{cout <<"War"<< endl;}
  
  
  
 
}


Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <utility>
#include <memory>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <numeric>
#include <list>
#include <iomanip>

#if __cplusplus >= 201103L
#include <array>
#include <tuple>
#include <initializer_list>
#include <forward_list>

#define cauto const auto&
#else

#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll;
typedef vector<vector<long long> > vvll;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _rep(i,n) _rep2((i),0,(n))
#define _rep2(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) GET_MACRO(__VA_ARGS__, _rep2, _rep)(__VA_ARGS__)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define fi first
#define se second
#define mkp make_pair
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int W,H;
	cin>>W>>H;
	using P = pair<int,pii>;
	vector<P> v;
	rep(i,W){
		int p;
		cin>>p;
		v.PB(P(p,pii(0,i)));
	}
	rep(i,H){
		int q;
		cin>>q;
		v.PB(P(q,pii(1,i)));
	}
	sort(ALL(v));
	ll ans = 0;
	int hh = 0;
	int ww = 0;
	rep(i,v.size()){
		if(v[i].se.fi==1){
			ans += v[i].fi*1LL*(W+1-ww);
			hh++;
		}
		else{
			ans += v[i].fi*1LL*(H+1-hh);
			ww++;
		}
	}
	cout<<ans<<endl;
}



signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 4852
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws Exception {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String s = br.readLine();
    String t = br.readLine();
    br.close();
    int s_len = s.length();
    int t_len = t.length();
    int answer = t.length();
    for(int s_idx = 0; s_idx <= s_len - t_len; s_idx++){
      int diff_cnt = 0;
      for(int t_idx = 0; t_idx < t_len; t_idx++){
        if(s.charAt(s_idx + t_idx) != t.charAt(t_idx)) diff_cnt++;
      }
      answer = Math.min(answer, diff_cnt);
    }
    System.out.println(answer);
  }
}

Measured memory_bytes: 32408
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main(){
  int N ; cin >> N;
  vector<string> S(N); for(int i = 0 ; i < N; i++){ cin >> S[i] ;}
  int M; cin >> M;
  vector<string> T(M); for(int j = 0; j < M ; j++){cin >> T[j];}
                                                 int max_sum = 0;           
  for(int k = 0; k < N; k++){
    string s; s = S[k]; int sum = 0;
    for(int i = 0; i < N; i++){
      if(s == S[i]){sum++;}}
    for(int j = 0; j < M; j++){
      if(s == T[j]){sum--;}}
    max_sum = max(max_sum,sum);}
    
    cout << max_sum << endl;
  
  return 0;}
                

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int N, M;
  cin >> N >> M;
  set<int> A;
  rep(i, M) {
    int a;
    cin >> a;
    A.insert(a);
  }
  vector<ll> B(N+1);
  B[0] = 1;
  rep(i, N+1) {
    if(A.find(i) == A.end()) {
      if(i == 1)
	B[i] = B[i-1] % mod;
      else if(i > 1)
	B[i] = (B[i-1] + B[i-2]) % mod;
    }
  }
  cout << B[N] << endl;
  return 0;
}


Measured memory_bytes: 5760
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
ll powmod(ll x,ll n){
    if(n == 0)return 1;
    ll ans = powmod(x*x%MOD,n/2);
    if(n % 2)ans = ans * x % MOD;
    return ans;
}
ll divmod(ll a,ll b){
    return ((a%MOD) * (powmod(b,MOD-2)%MOD)) % MOD;
}
ll combi(ll n,ll r){
    ll num = 1;
    for(ll i = 1;i <= r;i++){
        num = divmod((n-i+1)*num,i);
    }
    return num;
}
main(){
    ll N,K;
    cin >> N >> K;
    map<int,int> mp;
    for(ll i = 2;i * i <= K;i++){
        while(K % i == 0){
            mp[i]++;
            K /= i;
        }
    }
    if(K != 1)mp[K]++;
    ll ans = 1;
    for(auto p:mp){
        ll n = N, r = p.second;
        ans *= combi(n + r - 1, r);
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

var (
	s string
)

func main() {
	fmt.Scan(&s)
	var answer int
	for i := 0; i < len(s); i++ {
		if s[i] != s[len(s)-1-i] {
			answer++
		}
	}
	fmt.Println(answer / 2)
}


Measured memory_bytes: 512
fn main() {
    let (a, b): (i64, i64) = readln();
    let c = b - 2 * a;
    let ans = if c <= 0 {
        std::cmp::min(a, b/2)
    } else {
        a + c / 4
    };
    println!("{}", ans);
}

// --- template ---
pub trait FromLn {
    fn fromln(s: &str) -> Self;
}
pub fn readln<T: FromLn>() -> T {
    let mut buf = String::new();
    let _ = ::std::io::stdin().read_line(&mut buf).unwrap();
    T::fromln(buf.trim())
}
pub fn readlns<T: FromLn>(n: usize) -> Vec<T> {
    let mut vs = vec![];
    for _ in 0..n { vs.push(readln()); }
    vs
}
macro_rules! fromln_primitives {
    ($($t:ty),*) => { $(
        impl FromLn for $t {
            fn fromln(s: &str) -> $t {
                s.parse().unwrap()
            }
        }
    )* }
}
fromln_primitives!(String, bool, f32, f64, isize, i8, i16, i32, i64, usize, u8, u16, u32, u64);
impl<T> FromLn for Vec<T> where T: FromLn {
    fn fromln(s: &str) -> Vec<T> {
        s.split_whitespace().map(T::fromln).collect()
    }
}
impl FromLn for Vec<char> {
    fn fromln(s: &str) -> Vec<char> {
        s.chars().collect()
    }
}
macro_rules! fromln_tuple {
    ($($t:ident),*) => {
        impl<$($t),*> FromLn for ($($t),*) where $($t: FromLn),* {
            fn fromln(s: &str) -> ($($t),*) {
                let mut it = s.split_whitespace();
                let t = ($($t::fromln(it.next().unwrap())),*);
                assert_eq!(it.next(), None);
                t
            }
        }
    }
}
fromln_tuple!(A, B);
fromln_tuple!(A, B, C);
fromln_tuple!(A, B, C, D);
fromln_tuple!(A, B, C, D, E);
fromln_tuple!(A, B, C, D, E, F);

Measured memory_bytes: 4352
#include <stdio.h>
unsigned long long int min(unsigned long long int x,unsigned long long int y){
  if(x > y) {
    return y;
  } else {
    return x;
  }
}

int main(void) {
  unsigned long long int N,A,B,C,D,E;
  scanf("%llu %llu %llu %llu %llu %llu",&N,&A,&B,&C,&D,&E);
  unsigned long long int rissoku = min(A,min(B,min(C,min(D,E))));
  unsigned long long int kaisuu = N / rissoku;
  unsigned long long int answer;
  if (N % rissoku == 0) {
    answer = 4ull + kaisuu;
  } else {
    answer = 5ull + kaisuu;
  }
  printf("%llu\n", answer);
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include<math.h>
int main(void){
    // Your code here!
    int n;
    int i;
    int dig;
    int cnt=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        dig=(int)log10f(i)+1;
        if(dig&1) cnt++;
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
 
const int mx=200010;
const ll mod=1e9+7;

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

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import java.math.*;
 
class Main {
    public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    public static PrintWriter pw = new PrintWriter(System.out);
    public static String line;
    public static StringTokenizer st;
    public static ArrayList<ArrayList<Integer>> adjList;
    public static int[] dx = {-1, 0, 1, 0, -1, 1, 1, -1, 0};
    public static int[] dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
    public static int INF = 0x3f3f3f3f;
    public static int MOD = 1000000007;
    public static long LINF = 0x3f3f3f3f3f3f3f3fL;

    public static void main(String[] args) throws Exception {
        st = new StringTokenizer(br.readLine());
        int N = Integer.parseInt(st.nextToken());
        int K = Integer.parseInt(st.nextToken());

        pw.println((N + 1) / 2 >= K ? "YES" : "NO");


        pw.close(); 
        br.close();
    }
}

class Pair implements Comparable<Pair>{
    public long x;
    public int y;
 
    Pair(long _x, int _y){
        x = _x;
        y = _y;
    }
 
    public String toString(){
        return x + " " + y;
    }

    public int compareTo(Pair p){
        if (x != p.x) return x < p.x ? -1 : 1;
        if (y != p.y) return y < p.y ? -1 : 1;
        return 0;
    }
} 

Measured memory_bytes: 22740
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
char s1[110],s2[110];
int main()
{
	scanf("%d",&n);
	scanf("%s",s1+1);
	scanf("%s",s2+1);
	for(int i = 1; i <= n; i++)
		printf("%c%c",s1[i],s2[i]);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a) for(int (i)=0; (i)<(a); (i)++)
#define rep2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define all(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
#define chmax(a,b) if(b>a) a = b
#define chmin(a,b) if(b<a) a = b
typedef long long ll;
using namespace std;

using namespace std;

int main(){
        ios_base::sync_with_stdio(false); 
        cin.tie(NULL);
        int a; cin >> a;
        cout << a + a*a + a*a*a << endl;
        return 0;
}


Measured memory_bytes: 3632
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;

int main(){
  int a,b,x;
  cin >> a >> b >> x;
  if(0<=x-a&&x-a<=b){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){
	int a,b,sum =0,c,n;
	scanf("%d%d",&a,&b);
	if(a>=1&&a<=1000 && b>=1&&b<=1000){
		c= b;
		for(int i =1;;i++){
			sum++;
			c = c/10;
			if(c == 0)
				break;
		}
		n = a*pow(10,sum) +b;
		if(n == (int)sqrt(n) * (int)sqrt(n))
			printf("Yes");
		else
			printf("No");
			
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <string>

using namespace std;

int main() {
  int n;
  cin >> n;
  cerr << "testtesttest" << endl;
  cout << n*n*n << endl; 
}


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

public class ABC0140_A4v1 {
    private static void Main(string[] args) {
        var inputs = new List<string>() {
            Console.ReadLine().Trim(),
            Console.ReadLine().Trim(),
        };

        Prepare(inputs);
    }

    private static void Prepare(List<string> inputs) {
        var ints = inputs[0].Split().Select(x => int.Parse(x)).ToArray();
        var numOfDirections = ints[0];
        var numOfTrials = ints[1];
        var directions = inputs[1];
        Compute(numOfDirections, numOfTrials, directions);
    }

    private static void Compute(int numOfDirections, int numOfTrials, string directions) {
        var initialHappiness = 0;

        for (var index = 0; index < numOfDirections - 1; index++) {
            if (directions[index] == directions[index + 1])
                initialHappiness++;
        }

        var happiness = initialHappiness + (2 * numOfTrials);
      
        if (happiness > numOfDirections - 1) {
            happiness = numOfDirections - 1;
        }

        OutputAnswer(happiness.ToString());
    }

    private static void OutputAnswer(string text) => Console.WriteLine(text);
}


Measured memory_bytes: 13536
import numpy as np

A = [[0] * 3 for i in range(3)]
A[0] = list(map(int, input().split()))
A[1] = list(map(int, input().split()))
A[2] = list(map(int, input().split()))

N = int(input())
b = [0] * N
for i in range(N):
    b[i] = int(input())

if ((A[0][0] in b) & (A[0][1] in b) & (A[0][2] in b)):
    print('Yes')
elif ((A[1][0] in b) & (A[1][1] in b) & (A[1][2] in b)):
    print('Yes')
elif ((A[2][0] in b) & (A[2][1] in b) & (A[2][2] in b)):
    print('Yes')
elif ((A[0][0] in b) & (A[1][0] in b) & (A[2][0] in b)):
    print('Yes')
elif ((A[0][1] in b) & (A[1][1] in b) & (A[2][1] in b)):
    print('Yes')
elif ((A[0][2] in b) & (A[1][2] in b) & (A[2][2] in b)):
    print('Yes')
elif ((A[0][0] in b) & (A[1][1] in b) & (A[2][2] in b)):
    print('Yes')
elif ((A[0][2] in b) & (A[1][1] in b) & (A[2][0] in b)):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 12516
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	int H,W;
	char g[105];
	scanf("%d%d\n",&H,&W);
	for(int i=0;i<W+2;i++)putchar('#');puts("");
	for(int i=0;i<H;i++)
	{
		scanf("%s",g);
		printf("#%s#\n",g);
	}
	for(int i=0;i<W+2;i++)putchar('#');puts("");
	return 0;
}


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

#define IOS cin.tie(0);ios_base::sync_with_stdio(false)

#define ll      long long
#define Fi      first
#define Se      second
#define Pb      push_back
#define vi      vector<int>
#define vs      vector<string>
#define vp      vector<pair<int,int>>
#define vvi     vector<vector<int>>
#define vvp     vector<vector<pair<int,int>>>
using Graph  =  vector<vector<int>>; //Caution!! Segmentation Fault!! Don't forget to add +1!

#define sz(x) (int)x.size()
#define all(v) v.begin(),v.end()
#define output_s(s) printf("%s\n",(s).c_str())

#define rep(i,n)        for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m)      for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m)     for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m)    for(int i=(int)(n);i>=(int)(m);i--)
#define SRepS(i,n,m)    for(int i=(int)(n);i*i<=(int)(m);i++)
#define RepA(x)         for(auto &item:(x))

void CINT(){} //@shibh308's template
template<class Head,class... Tail> void CINT(Head&& head,Tail&&... tail){cin>>head; CINT(move(tail)...);}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define VCIN(x) for(auto &item:x) cin>>item

void OUT(){}
template<class Head,class...Tail> void OUT(Head&& head,Tail&&...tail){cout<<head<<(sizeof...(tail)?" ":"\n"); OUT(move(tail)...);}
#define COUT(...) OUT(__VA_ARGS__)

template<typename TypeInt>TypeInt GCD(TypeInt a,TypeInt b){return a%b==0?b:GCD(b,a%b);} //最大公約数
template<typename TypeInt>TypeInt LCM(TypeInt a,TypeInt b){return a*b/GCD(a,b);} //最小公倍数
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
template<class T>bool comp(T a,T b){return abs(a)<abs(b);} //比較関数

void YES(bool f){printf(f?"YES\n":"NO\n");}
void Yes(bool f){printf(f?"Yes\n":"No\n");}
void Possible(bool f){printf(f?"Possible\n":"Impossible\n");}
void POSSIBLE(bool f){printf(f?"POSSIBLE\n":"IMPOSSIBLE\n");}

//----------------------library------------------------//

//const int dx[4]={1,0,-1,0};
//const int dy[4]={0,1,0,-1};
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int NMAX = 200;
const int INF = 1e9;
const int MOD = 1e9+7;
bool flag;

//----------------------Global-------------------------//

signed main(){
    ll l, r, res=2020;
	cin>>l>>r;
	if(r-l>=2019) printf("0\n");
    else{
        for(ll j=l;j<=r;j++){
		    for(ll i=l;i<j;i++)
			    res=min(res,(i*j)%2019);
	    }
	    printf("%lld\n",res);
    }
	

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int a,b,c,i,j,x,y,f=0;
	cin >> a >> b >> c;
	x=c%b;
	y=a%b;
	if(x==y)
		cout << "YES" << endl;
	else{
		j=a+a;
		while(j%b!=y){
			if(j%b==x){
				f=1;
				break;
			}
			j+=a;
			//cout << "j: " << j << endl;
		}
		if(f)
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int n, ans;
    string s;
    std::cin >> n >> s;
    vector<int> w_sum, e_sum;
    w_sum.resize(n);
    e_sum.resize(n);
    ans = 300001;
    // 累積和
    for(int i=0; i<n; i++){
        if (i == 0){
            if (s[i] == 'W'){
                w_sum[i] = 1;
                e_sum[i] = 0;
            }
            else if(s[i] == 'E'){
                w_sum[i] = 0;
                e_sum[i] = 1;
            }
        }
        if (s[i] == 'W' && i > 0){
            w_sum[i] = w_sum[i-1] + 1;
            e_sum[i] = e_sum[i-1];
        }
        else if(s[i] == 'E' && i > 0){
            w_sum[i] = w_sum[i-1];
            e_sum[i] = e_sum[i-1] + 1;
        }
        //std::cout << "W" << i << " " << w_sum[i] << ":E" << i << " " << e_sum[i] << endl;
    }
    
    for(int i = 0; i < n; i++){
        if(i == 0){
            ans = e_sum[n-1] - e_sum[0];
        }
        else if(i == n-1){
            ans = min(ans, w_sum[n-2]);
        }
        else {
            ans = min(ans, (e_sum[n-1] - e_sum[i]) + w_sum[i-1]);
        }
    }
    
    std::cout << ans << endl;
}


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

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define LOOP(i, N) for (int i = 1; i <= (int)N; i++)
#define RREP(i, N) for (int i =(int)N-1; i >= 0; i--)
#define RLOOP(i, N) for (int i =(int)N; i > 0; i--)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define INF (1 << 30)
#define LLINF (1LL << 62)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

typedef long long ll;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

int main(){
  int n;
  cin>>n;
  ll sum=0;
  vector<int> v;
  REP(i,n){
    int tmp;
    cin>>tmp;
    v.push_back(tmp);
  }
  sort(ALL(v));
  for(int i=0;i<n;i++){
    int tmp=v[i];
    int vi=i;
    while(i<n-1&&v[i]==v[i+1]){
      i++;
    }
    vi=i-vi+1;
    if(tmp<vi){
      sum+=vi-tmp;
    }else if(tmp>vi){
      sum+=vi;
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define F first
#define S second
#define vi vector<int>
#define pi pair<int, int>
#define vpi vector<pair<int, int>>
#define er(n) cout<<"error "<<n<<endl;
int mod=1000000007;

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int n, m;
    cin>>n>>m;
    if (n<m) while(m--) cout<<n;
    else while(n--) cout<<m;
    return 0;
}


Measured memory_bytes: 256
// Words are flowing out like endless rain into a paper cup
// They slither while they pass they slip away across the universe
// Pools of sorrow, waves of joy are drifting through my open mind
// Possessing and caressing me

#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()

using LL = long long;
int vis[100005];
vector <int> ans;

namespace _buff {

const size_t BUFF = 1 << 19;
char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
char getc() {
	return getchar();
//    if (ib == ie) {
//        ib = ibuf;
//        ie = ibuf + fread(ibuf, 1, BUFF, stdin);
//    }
//    return ib == ie ? -1 : *ib++;
}

}

LL read() {
    using namespace _buff;
    LL ret = 0;
    bool pos = true;
    char c = getc();
    for (; (c < '0' || c > '9') && c != '-'; c = getc()) {
        assert(~c);
    }
    if (c == '-') {
        pos = false;
        c = getc();
    }
    for (; c >= '0' && c <= '9'; c = getc()) {
        ret = (ret << 3) + (ret << 1) + (c ^ 48);
    }
    return pos ? ret : -ret;
}

using P = pair<int,int> ;
vector<vector<P> > g(100005 + 1);
int b[100005];
#define fi first
#define se second

void dfs(int x)
{
	vis[x]=1;
	for(auto u:g[x])
	{
		if(vis[u.first]) continue;
		dfs(u.first);
		if(b[u.first])
		{
			ans.push_back(u.second);
			b[u.first]^=1;
			b[x]^=1;
		}
	}
}

int main() {
    ios_base::sync_with_stdio(false);
    int n,m;
	cin>>n>>m;
	vector <pair<int,int> > psort;
    vector <int> lsh;
    for (int i = 0; i < n; ++i) {
    	int a,b;
		cin>>a>>b;
		psort.push_back(make_pair(a,b));
		lsh.push_back(a);
    }
	sort(all(lsh));
    sort(all(psort));
    for(int i=0;i<n;i++)
    {
    	b[i]=psort[i].second;
	}
	for(int i=n;i>=0;i--)
	{
		b[i]^=(i?b[i-1]:0);
	}
    for (int i = 1; i <= m; ++i) {
    	int l,r;
		cin>>l>>r;
		l=lower_bound(all(lsh),l)-lsh.begin();
		r=upper_bound(all(lsh),r)-lsh.begin();
		g[l].push_back(make_pair(r,i));
		g[r].push_back(make_pair(l,i));
    }
    
	for(int i=0;i<=n;i++)
	{
		if(vis[i]) continue;
		dfs(i);
		if(b[i])
		{
			cout<<-1<<endl;
			return 0;
		}
	}
	sort(all(ans));
	cout<<ans.size()<<endl;
	for(auto x:ans)
	{
		cout<<x<<' ';
	}
	cout<<endl;
    return 0;
}


Measured memory_bytes: 14964
import itertools

N = input()
K = int(input())
lN = len(N)


if K == 1:
    ans = int(N[0])+9*(lN-1)
    print(ans)

elif K == 2:
    not0 = 1000
    for i in range(1,lN):
        if int(N[i]) != 0:
            not0 = i
            break

    ans = 0
    n = [i for i in range(lN)]

    for v in itertools.combinations(n,2):
        #print(v)
        if v[0] != 0:
            ans += 9*9
        else:
            if not0 >= v[1]:
                ans += max(0,int(N[0])-1)*9 + int(N[v[1]])
            else:
                ans += int(N[0])*9
    print(ans)

else:
    not0f = 1000
    not0s = 1000
    for i in range(1,lN):
        if int(N[i]) != 0:
            not0f = i
            break
    for i in range(not0f+1,lN):
        if int(N[i]) != 0:
            not0s = i
            break
    ans = 0
    n = [i for i in range(lN)]
    for v in itertools.combinations(n,3):
        if v[0] != 0:
            ans += 9*9*9
        else:
            if not0f == v[1]:
                if not0s == v[2]:
                    ans += max(0,int(N[0])-1)*9*9
                    ans += max(0,int(N[v[1]])-1)*9
                    ans += int(N[v[2]])
                elif not0s < v[2]:
                    ans += max(0,int(N[0])-1)*9*9
                    ans += int(N[v[1]])*9
                    #ans += int(N[0])*int(N[v[1]])*9
                else:
                    ans += max(0,int(N[0])-1)*9*9
                    ans += max(0,int(N[v[1]])-1)*9
            elif not0f < v[1]:
                ans += int(N[0])*9*9
            else:
                ans += max(0,int(N[0])-1)*9*9

    print(ans)


Measured memory_bytes: 3192
from itertools import permutations
n=int(input())
p=tuple([int(i) for i in input().split()])
q=tuple([int(i) for i in input().split()])
pr=[i for i in permutations(range(1,n+1))]
for i,j in enumerate(permutations(range(1,n+1))):
  if j==p:
    a=i
  if j==q:
    b=i
print(abs(a-b))

Measured memory_bytes: 7924
using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main()
    {
        string[] cin = Console.ReadLine().Split();
        int n = int.Parse(cin[0]);
        int m = int.Parse(cin[1]);
        List<int> x = Console.ReadLine().Split().Select(i => int.Parse(i)).ToList();

        int ans = 0;
        if (n >= m)
        {
            Console.WriteLine(ans);
            return;
        }

        x.Sort();
        var gap = new List<int>();
        for (int i = 1; i < x.Count; i++)
        {
            gap.Add(x[i] - x[i - 1]);
        }
        gap.Sort();

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

        Console.WriteLine(ans);
    }
}

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

using namespace std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define sz size
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORN(i,a,b) for(int i=a;i<=b;i++)
#define FORRN(i,a,b) for (int i=(a);i>=(b);i--)
#define FORR(i,a,b) for (int i=(a);i>(b);i--)
typedef unsigned long long ull;
typedef long long ll;

const int MAXN=1e5+5;
const int INF=1e9+9;

int main(){
    ios_base::sync_with_stdio(false); //Fast I/O
    cin.tie(0);
    cout.tie(0);
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);

    ll n,w;
    ll dp[MAXN];
    FOR(i,1,MAXN)
        dp[i] = INF;

    cin >> n >> w;

    FOR(i,0,n){
        int a, b;
        cin >> a >> b;
        for(int j=MAXN-1;j>=b;j--)
            dp[j]=min(dp[j],dp[j-b]+a);
    }

    int ans = 0;
    FOR(i,0,MAXN){
        if(dp[i]<=w)
            ans=max(ans,i);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define SORTR(x) sort(ALLR(x))
#define SORT(x) sort(ALL(x))
#define SUM(x) accumulate(ALL(A), 0)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
const int INF  = 1<<30;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
#define COUT(x) cout<<x<<"\n";

void Main()
{
	ll N;
	ll result=0;
	string S;
	cin>>N;
	VI L(N);
	REP(i, N) cin >> L[i];
	SORT(L);
	REP(i,N){
		REP(j,i){
			REP(k,j){
				ll a=L[i];
				ll b=L[j];
				ll c=L[k];
				if(a<b+c&&b<c+a&&c<a+b) result++;
			}
		}
	}
	cout << result << "\n";
	return;
}

int main()
{
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    string s;
    cin >> s;
    Int n = s.size();
    for (Int i = 0; i < n - 1; i++) {
        if (s[i] == s[i + 1]) {
            cout<< i + 1 << " " << i + 2 << endl;
            return 0;
        }
    }    
    for (Int i = 0; i < n - 2; i++) {
        if (s[i] == s[i + 2]) {
            cout << i + 1 << " " << i + 3 << endl;
            return 0;
        }
    }
    cout << -1 << " " << -1 << endl;
    return 0;
}

Measured memory_bytes: 512
v[16],m[2][4][16],i=4,p,d,t,w='AN';main(){for(;read(0,v+i,1);++i-16||(puts(&w),i=4,w='AN'))for(p=2;p--;)for(d=4;d--;w=t-3?w:v[i])t=m[p][d][i]=v[i]-"bw"[p]?0:m[p][d][i-(d?d+2:1)]+1;}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main()
{
	long double d,t,s,T;
	cin>>d>>t>>s;
	T=(long double)d/(long double)s;
	if(T<=t)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}


Measured memory_bytes: 3132