akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

void init(int par[], int V){
  for(int i = 0; i < V; ++i)
    par[i] = i;
}

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

void unite(int x, int y, int par[], int rank[]){
  x = find(x, par);
  y = find(y, par);

  if(x == y)
    return;

  if(rank[x] > rank[y]){
    par[y] = x;
  }else{
    par[x] = y;
    if(rank[x] == rank[y])
      rank[y]++;
  }
}

int same(int x, int y, int par[]){
  return find(x, par) == find(y, par);
}

struct edge{int u, v; llong cost;};

bool comp(const edge& e1, const edge& e2){
  return e1.cost < e2.cost;
}

llong kruskal(int V, int E, vector<edge> es){
  sort(ALL(es), comp);
  int *par, *rank;

  par = new int[V];
  rank = new int[V];

  init(par, V);
  REP(i,V){
    rank[i] = 0;
  }

  llong res = 0;
  REP(i,E){
    edge e = es[i];
    if(!same(e.u, e.v, par)){
      unite(e.u, e.v, par, rank);
      res += e.cost;
    }
  }
  
  delete[] par;
  delete[] rank;

  return res;
}

int main(){
  
  llong n;
  scanf("%lld", &n);

  llong d[300][300];
  REP(i,n){
    REP(j,n){
      scanf("%lld", &d[i][j]);
    }
  }

  llong cost[300][300] = {};
  REP(i,n){
    REP(j,n){
      cost[i][j] = d[i][j];
    }
  }

  llong ans = 0;
  bool short_path[300][300] = {};
  REP(k,n){
    REP(i,n){
      REP(j,n){
        if(cost[i][j] > cost[i][k] + cost[k][j]){
          printf("-1\n");
          return 0;
        }
        if(cost[i][j] == cost[i][k] + cost[k][j] && !(i == k || j == k)){
          short_path[i][j] = true;
        }
      }
    }
  }

  REP(i,n){
    FOR(j,i+1,n){
      if(!short_path[i][j]){
        ans += cost[i][j];
      }
    }
  }


  printf("%lld\n", ans);

  return 0;
}



Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
ll n,a[105],x,ans;
int main()
{
	scanf("%lld%lld",&n,&x);
	for(int i=1;i<=n;i++)
	  scanf("%lld",&a[i]);
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
	{
		if(a[i]<=x)x-=a[i],ans++;
		else break;
	}
	if(ans==n&&x)ans--;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
using ll = long long;
using VI = vector<int>;

int main(){
  int h,w;cin >> h >> w;
  char a[h][w];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> a[i][j];
    }
  }
  for(int j=0;j<w;j++){
    bool flag=true;
    for(int i=0;i<h;i++){
      if(a[i][j]=='#') flag = false;
    }
    if(flag){
        for(int i=0;i<h;i++){
          a[i][j]='a';
        }
    }
  }
  for(int i=0;i<h;i++){
    bool flag = true;
    for(int j=0;j<w;j++){
      if(a[i][j]=='#') flag = false;
    }
    if(flag){
      for(int j=0;j<w;j++){
        a[i][j]='a';
      }
    }
  }
  //cout << endl << endl << endl;
  for(int i=0;i<h;i++){
    bool flag = false;
    for(int j=0;j<w;j++){
      if(a[i][j]!='a'){
        cout << a[i][j];
        flag = true;
      }
    }
    if(flag) cout << endl;
  }

}


Measured memory_bytes: 256
<?php
	$n = trim(fgets(STDIN));
	$hash = array("S" => array_fill(0, 13, false),
				  "H" => array_fill(0, 13, false),
				  "C" => array_fill(0, 13, false),
				  "D" => array_fill(0, 13, false)
	);

	for ($i = 0; $i < $n; $i++) {
		$line = trim(fgets(STDIN));
		$arr = explode(" ", $line);

		$hash[$arr[0]][$arr[1]-1] = true;
	}

	foreach ($hash as $key => $val) {
		for ($i = 0; $i < 13; $i++) {
			if (!$hash[$key][$i]) echo "$key " . ($i+1) . "\n";
		}
	}

Measured memory_bytes: 6624
#include <cstdio>
#include <algorithm>
#include <bitset>

using namespace std;

const int MAX_R = 10;
const int MAX_C = 10000;

//input
int R, C;
bitset<MAX_C> a[MAX_R];

int ans;

void dfs(int k){
    if(k == R){
        //row certain
        int result = 0;            //cur max value
        for(int j = 0; j < C; j ++){
            int upNum = 0;            //up numbers without fliping
            for(int i = 0; i < R; i ++){
                if(a[i][j]) upNum ++;
            }
            result += max(upNum, R - upNum);    
        }
        ans = max(ans, result);
        return;
    }
    //without fliping
    dfs(k + 1);
    //&#183;flip
    a[k].flip();
    dfs(k + 1);

    a[k].flip();
}

void solve(){
    ans = 0;
    dfs(0);
    printf("%d\n", ans);
}

int main(int argc, char const *argv[]){

    while(scanf("%d %d", &R, &C)){
        if(R == 0 && C == 0) break;

        for(int i = 0; i < R; i ++){
            for(int j = 0; j < C; j ++){
                int tmp;
                scanf("%d", &tmp);
                a[i][j] = tmp;
            }
        }
        solve();
    }

    return 0;
}

Measured memory_bytes: 1040
#include<iostream>
#include<utility>
#include<vector>
#include<algorithm>

int main(){
    int N, M, R;
    std::cin >> N >> M >> R;

    std::vector<int> r(R);
    for(int i = 0; i < R; i++){
        std::cin >> r[i];
        r[i]--;
    }
    std::sort(r.begin(), r.end());

    int v[200][200];
    for(int i = 0; i < 200; i++){
        for(int j = 0; j < 200; j++){
            if(i == j)v[i][j] = 0;
            else v[i][j] = 1e9;
        }
    }

    int a, b, c;
    for(int i = 0; i < M; i++){
        std::cin >> a >> b >> c;
        a--;
        b--;
        v[a][b] = c;
        v[b][a] = c;
    }

    for(int k = 0; k < N; k++){
        for(int i = 0; i < N; i++){
            for(int j = 0; j < N; j++){
                v[i][j] = std::min(v[i][j], v[i][k] + v[k][j]);
            }
        }
    }

    int ans = 1e9;
    int tmp;
    do{
        tmp = 0;
        for(int i = 0; i < R - 1; i++) tmp += v[r[i]][r[i + 1]];
        ans = std::min(ans, tmp);
    }while(next_permutation(r.begin(), r.end()));

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


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
//#define int ll
#define INF INT_MAX/10

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;


int Input[110];

int Ans[110];

int main() {


  int N; cin >> N;
  for (int i = 0; i < N -1 ; i++) {
    cin >> Input[i];
  }

  Ans[N-1] = Input[N-2];
  for (int i = N -2; i >= 1; i--) {
    Ans[i] = min(Input[i], Input[i-1]);
  }
  Ans[0] = Input[0];

  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += Ans[i];
  }

  cout << ans << endl;
}


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

int main() {
	int n, m, i, j, cnt, hsum, wsum, tmp, cnti, cntj;
	while (1) {
		cin >> n >> m;
		if (n == 0 && m == 0)break;
		int h[1502], w[1502];
		vector<int> sh, sw;
		hsum = wsum = 0;
		h[0] = 0;
		for (i = 1; i <= n; i++) {
			cin >> tmp;
			hsum += tmp;
			h[i] = hsum;
		}
		w[0] = 0;
		for (i = 1; i <= m; i++) {
			cin >> tmp;
			wsum += tmp;
			w[i] = wsum;
		}
		
		for (i = 0; i <= n - 1; i++) {
			for (j = i + 1; j <= n; j++) {
				sh.push_back(h[j] - h[i]);
			}
		}
		for (i = 0; i <= m - 1; i++) {
			for (j = i + 1; j <= m; j++) {
				sw.push_back(w[j] - w[i]);
			}
		}

		sort(sh.begin(), sh.end());
		sort(sw.begin(), sw.end());
		
		i = j = 0;
		cnt = 0;
		int maxi = sh.size(), maxj = sw.size();
		while (i < maxi && j < maxj) {
			if (sh[i] == sw[j]) {
				cnti = cntj = 1;
				while (i < maxi - 1 && sh[i] == sh[i + 1]) {
					cnti++;
					i++;
				}
				while (j < maxj - 1 && sw[j] == sw[j + 1]) {
					cntj++;
					j++;
				}
				cnt += cnti * cntj;
				i++;
				j++;
			} else if (sh[i] < sw[j]) {
				i++;
			} else {
				j++;
			}
		}
		
		cout << cnt << endl;
		
	}




	return 0;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    int G[n][n];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(i == j) G[i][j] = 0;
            else G[i][j] = 1e9;
        }
    }

    int E[m][3];
    for(int i = 0; i < m; i++){
        cin >> E[i][0] >> E[i][1] >> E[i][2];
        E[i][0]--; E[i][1]--;
        G[E[i][0]][E[i][1]] = E[i][2];
        G[E[i][1]][E[i][0]] = E[i][2];
    }

    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            for(int k = 0; k < n; k++){
                G[j][k] = min(G[j][k], G[j][i] + G[i][k]);
            }
        }
    }

    int cnt = 0;
    for(int i = 0; i < m; i++){
        if(G[E[i][0]][E[i][1]] != E[i][2]){
            cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  if (a <= b)
    for (int i=0;i<b;i++) cout << a;
  else if (a > b)
    for (int i=0;i<a;i++) cout << b;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(void){
    int a,b,sum,count;
    double i;
    while(scanf("%d %d",&a,&b)!=EOF){
        sum=a+b;
        count=0;
        i=0.0;
        for(;;){
            if(sum%(int)pow(10.0,i)!=sum) count++;
            else break;
            i++;
        }
        printf("%d\n",count);
    }
    
    return 0;
}



Measured memory_bytes: 2032
import java.io.*;
import java.util.*;

public class Main {
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner();
		PrintWriter out = new PrintWriter(System.out);
		char []s=sc.next().toCharArray();
		boolean bad=false;
		for(int i=1;i<s.length;i++)
			if(s[i]==s[i-1])
				bad=true;
		out.println(bad?"Bad":"Good");
		out.close();

	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		Scanner(String fileName) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(fileName));
		}

		String next() 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(next());
		}

		long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		double nextDouble() throws NumberFormatException, IOException {
			return Double.parseDouble(next());
		}

		boolean ready() throws IOException {
			return br.ready();
		}

	}

}

Measured memory_bytes: 24916
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::cmp::Ordering;

#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}
impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

fn main() {
    input! {
        n: String,
    }
    let val: u32 = n.parse().unwrap();
    let mut sum = 0;
    for c in n.chars() {
        sum += c.to_string().parse().unwrap();
    }
    if val % sum == 0 {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <cmath>
#include <string>
#include <list>

using namespace std;

typedef long long ll;

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

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

    sort(A.begin(), A.end(), greater<ll>());
    ll a = 0;
    ll b = 0;
    for(int i = 1; i < N; i++) {
        if(A[i] == A[i-1]) {
            if(a == 0) {
                a = A[i];
                i++;
            }
            else if(b == 0) {
                b = A[i];
                cout << a * b << endl;
                return 0;
            }
        }
    }
    cout << 0 << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int mxn= 5e5+5;
// check for forloop
// intialize variable
// overflow
// go for easy solution
#define mod 1000000007
ll INF = 1000000000000000005LL;
#define endl '\n'
void rishabh(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}
int main(){
    rishabh();
    string s;
    cin>>s;
    bool f=true;
    int ans1=0,ans2=0,n=s.size();
    for(int i=0;i<n;i++){
        if(f==true&&s[i]=='1'){
            ans1++;
        }
        else if(f==false&&s[i]=='0'){
            ans1++;
        }
        f=!f;
    }
    f=false;
    for(int i=0;i<n;i++){
        if(f==true&&s[i]=='1'){
            ans2++;
        }
        if(f==false&&s[i]=='0'){
            ans2++;
        }
        f=!f;
    }
    cout<<n-max(ans1,ans2);
}



Measured memory_bytes: 3792
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;


signed main(){
    int n, now = 0, MAX = 0;
    string s;
    cin >> n >> s;
    rep(i, 0, n){
        if(s[i] == 'I') now++;
        else now--;
        MAX = max(MAX, now);
    }
    cout << MAX << endl;
}

Measured memory_bytes: 384
n = int(input())
x = list(map(int, input().split()))

sorted_x = sorted(x, reverse = True)

med_index = n // 2 -1


for l in range(n):
    if x[l] >= sorted_x[med_index]:
        print(sorted_x[med_index+1])
    elif x[l] < sorted_x[med_index]:
        print(sorted_x[med_index])
    


Measured memory_bytes: 26016
#include<iostream>
#include<queue>
#include<string.h>
using namespace std;
int n,m,sum,ti,sx,sy,dx[5]= {1,0,-1,0},dy[5]= {0,-1,0,1},ans=0,l,visited[1002][1002];
char mapp[1002][1002];
struct k
{
    int x,y,nowti,time;
} nainao[15];
queue<k> q;

int bfs(int nowsum)
{
    memset(visited,0,sizeof(visited));
    k a,b;
    a.x=sx,a.y=sy,a.nowti=nowsum,a.time=0;
    visited[a.x][a.y]=1;
    q.push(a);
    while(!q.empty())
    {
        b=q.front();
        q.pop();
        if(b.nowti==nowsum+1)
            break;
        for(int i=0; i<4; ++i)
        {
            k c=b;
            c.x+=dx[i],c.y+=dy[i];
            if(c.x>=0&&c.x<n&&c.y>=0&&c.y<m&&!visited[c.x][c.y]&&c.nowti+'0'!=mapp[c.x][c.y]&&mapp[c.x][c.y]!='X')
            {
                visited[c.x][c.y]=1;
                c.time++;
                q.push(c);
                continue;
            }
            if(c.x>=0&&c.x<n&&c.y>=0&&c.y<m&&c.nowti+'0'==mapp[c.x][c.y])
            {
                visited[c.x][c.y]=1;
                c.nowti++,c.time++;
                q.push(c);
            }
        }
    }
    return b.time;
}

int main()
{
    while(cin>>n>>m>>sum)
    {
        ans=0;
        for(int i=0; i<n; ++i)
            for(int j=0; j<m; ++j)
            {
                cin>>mapp[i][j];
                if(mapp[i][j]=='S')
                {
                    nainao[0].x=i,nainao[0].y=j;
                }
                else if(mapp[i][j]=='1')
                {
                    nainao[1].x=i,nainao[1].y=j;
                }
                else if(mapp[i][j]=='2')
                {
                    nainao[2].x=i,nainao[2].y=j;
                }
                else if(mapp[i][j]=='3')
                {
                    nainao[3].x=i,nainao[3].y=j;
                }
                else if(mapp[i][j]=='4')
                {
                    nainao[4].x=i,nainao[4].y=j;
                }
                else if(mapp[i][j]=='5')
                {
                    nainao[5].x=i,nainao[5].y=j;
                }
                else if(mapp[i][j]=='6')
                {
                    nainao[6].x=i,nainao[6].y=j;
                }
                else if(mapp[i][j]=='7')
                {
                    nainao[7].x=i,nainao[7].y=j;
                }
                else if(mapp[i][j]=='8')
                {
                    nainao[8].x=i,nainao[8].y=j;
                }
                else if(mapp[i][j]=='9')
                {
                    nainao[9].x=i,nainao[9].y=j;
                }
            }
        for(int i=1; i<=sum; ++i)
        {
            while(!q.empty())
                q.pop();
            sx=nainao[i-1].x,sy=nainao[i-1].y;
            ans+=bfs(i);
        }
        cout<<ans<<endl;
    }
}



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

int main() {
    ll N;
    cin >> N;
    vector<vector<int>> tree(N);
    for(int i=0;i<N-1;i++){
        int a,b;
        cin >> a >> b;
        --a;--b;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    vector<int> node(N,-1);
    node[N-1] = 0;
    node[0] = 1;
    int num[2] ={};
    queue<int> q;
    q.push(0);q.push(N-1);
    while(!q.empty()){
        int t = q.front();q.pop();
        for(int child:tree[t]){
            if(node[child] == -1){
                node[child] = node[t];
                q.push(child);
                num[node[t]]++;
            }
        }
    }
    if(num[0]>=num[1]){
        cout <<"Snuke" << endl;
    }else{
        cout <<"Fennec"<< endl;
    }

    return 0;
}

Measured memory_bytes: 9068
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<ll(n); i++)

int main(){
    int x;
    cin >> x;
    if(x == 0){cout << 1 << endl;return 0;}
    else if(x == 1){cout << 0 << endl;return 0;}

    return 0;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int N;
    cin>>N;
    int A[N+1];
    int sum=0;
    rep(i,N+1){
        cin>>A[i];
        sum+=A[i];
    }
    int ans=1;
    int c=1;
    int ch=1;
    if(A[0]==1&&N==0){
        cout << 1 << endl;
        return 0;
    }
    if(A[0]!=0){
        cout << -1 << endl;
        return 0;
    }
    for(int i=1;i<=N;i++){
        c=min(c*2,sum);

        ans+=c;
        sum-=A[i];
        c-=A[i];
        if(c<0){
            ans=-1;
            break;
        }
    }
    cout << ans << endl;


    



}


Measured memory_bytes: 4396
from math import factorial as f
N, M, K = map(int, input().split())
mod = 10 ** 9 + 7

def combi(n, r):
  return f(n) // (f(n - r) * f(r)) % mod

res = 0
c = combi(N * M - 2, K - 2)
for i in range(1, N):
  res += ((N - i + 1) * (N - i) // 2) * c * M * M % mod
  res %= mod

for i in range(1, M):
  res += ((M - i + 1) * (M - i) // 2) * c * N * N % mod
  res %= mod

print(res % mod)



Measured memory_bytes: 74588
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>

using namespace std;


class Info
{
public:

	int D;
	int P;

	Info(int d,int p)
		: D(d)
		, P(p)
	{
	}

	bool operator<(const Info & info)const
	{
		return P > info.P;
	}
};


bool solve()
{
	int N, M;
	cin >> N >> M;
	if (N == 0 & M == 0) { return false; }

	list<Info> info;
	
	for (int i = 0; i < N; ++i)
	{
		int D, P;
		cin >> D >> P;
		info.emplace_back(D, P);
	}

	info.sort();

	int ans = 0;
	while (!info.empty())
	{
		if (M - info.front().D > 0)
		{
			M -= info.front().D;
		}
		else
		{
			ans += (info.front().D - M)*info.front().P;
			M = 0;
		}
		info.pop_front();
	}
	cout << ans << endl;

	return true;
}


int main()
{
	while(solve())
	{
	}
	


	return 0;
}


Measured memory_bytes: 3376
#include <bits/stdc++.h>
    
using namespace std;
    
#define endl "\n"
#define ll unsigned long long
#define int long long int
#define vi vector <int >
#define vii vector < pii >
#define vll vector <ll >
#define pii pair <int, int>
#define pdd pair< double, double>
#define piii pair < pii, int > 
#define pll pair<ll, ll >
#define umap unordered_map
#define pb push_back
#define pq priority_queue
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define rep(i,b,c) for(int i = (int)b; i < (int)c; i++)
#define double long double
#define a first
#define b second

const int N = 100010;
int dp[2][N];
int v[102];
int w[102];

int32_t main(){
    ios::sync_with_stdio(0),cin.tie(0);	
    int n, W;
    cin >> n >> W;

    for(int i = 1; i <= n; i++){
        cin >>w[i] >> v[i];
    }

    for(int i = 0; i <= n; i++){
        for(int j = 0; j <= W; j++){
            if(i == 0 || j == 0) dp[i%2][j] = 0; 
            else if(w[i] <= j){
                dp[i%2][j] = max(dp[(i - 1)%2][j], v[i] + dp[(i - 1)%2][j - w[i]]);
            }
            else dp[i%2][j] = dp[(i - 1)%2][j];
        }
    }

    cout << dp[n%2][W] << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;



int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

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

    vector<long long> acc(n + 1, 0);
    for (int i = 0; i < n; ++i) {
        acc[i + 1] = acc[i] + A[i];
    }

    auto summation = [&](int l, int r) -> long long {
        if (l > r) {
            return 0;
        }
        return acc[r + 1] - acc[l];
    };
    const long long INF = 1LL << 60;
    auto calc = [&](int l, int r) -> pair<long long, long long> {
        if (r - l + 1 < 2) {
            return {-INF, INF};
        }
        long long total = summation(l, r);
        long long tar = total / 2 + summation(0, l - 1);
        auto it = lower_bound(acc.begin() + l, acc.begin() + r + 1, tar);
        int x = it - acc.begin();

        long long diff = INF * 2;
        long long mn = -INF;
        long long mx = INF;
        for (int i = -1; i < 2; ++i) {
            int p = x + i - 1;
            if (p >= l && p < r) {
                long long L = summation(l, p);
                long long R = summation(p + 1, r);
                if (L > R) {
                    swap(L, R);
                }
                if (R - L < diff) {
                    diff = R - L;
                    mn = L;
                    mx = R;
                }
            }
        }
        return {mn, mx};
    };

    long long res = INF;
    for (int i = 1; i + 2 < n; ++i) {
        auto P = calc(0, i);
        auto Q = calc(i + 1, n - 1);

        long long mn = min(P.first ,Q.first);
        long long mx = max(P.second, Q.second);
        res = min(res, mx - mn);
    }

    cout << res << '\n';
    
    return 0;
}

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

int main()
{
    string str;
    cin>>str;
    bool result=true;
    int i;

    int j = str.length()-1;

    for(i=0; i<=j; i++){
        if(str[i] != str[j]){
            result = false;
            break;
        }
        j--;

    }

    j = (str.length()-2)/2;

    for(i=0; i<=j; i++){
        if(str[i] != str[j]){
            result = false;
            break;
        }
        j--;

    }

    if(result == false)
        cout<<"No";
    else
        cout<<"Yes";

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=100010;
ll n,k,arr[N],p2[40],x=0,ans=0;
int pos;
int main()
{
  int a[3];
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  cout<<(a[0]*a[1])/2<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include<sstream>
#include <stack>
namespace stoi{
	int stoi(std::string str){
		int num;
		std::stringstream ss;
		ss << str;
		ss >> num;

		return num;
	}
}

int main(){

	std::string str;
	int count = 0;
	std::stack<int> num;
	while (std::cin >> str) {
		if (str == "+") {
			int a = num.top(); num.pop();
			int b = num.top(); num.pop();
			num.push(a + b);
		}
		else if (str == "-") {
			int b = num.top(); num.pop();
			int a = num.top(); num.pop();
			num.push(a - b);
		}
		else if (str == "*") {
			int a = num.top(); num.pop();
			int b = num.top(); num.pop();
			num.push(a * b);
		}
		else if (str == " ") {
		}
		else{
			num.push(stoi::stoi(str));

		}
	

	}

	std::cout<<num.top() << std::endl;

	return 0;
}

Measured memory_bytes: 1240
#!/usr/bin/env python3
import sys

YES = "Yes" 
NO = "No"

S = input()

R = S[::-1]

if S != R:
    print(NO)
    sys.exit()

N = len(S)
P = (N-1)//2
A = S[1::P+1]
rA = A[::-1]

if A != rA:
    print(NO)
    sys.exit()

M = (N+3)//2
Q = S[M::N+1]
rQ = Q[::-1]

if Q != rQ:
    print(NO)
    sys.exit()

print(YES)




Measured memory_bytes: 3064
N, K = map(int, input().split())
G = [0]*N
src = list(map(int, input().split()))
for i,a in enumerate(src):
    G[i] = a-1
D = [-1]*N
D[0] = 0
cur = 0
dis = 0
while True:
    dis = dis+1
    cur = G[cur]
    if dis == K:
        print(cur+1)
        exit()
    if D[cur] == -1:
        D[cur] = dis
    else:
        cycle = dis - D[cur]
        K -= D[cur]
        target = K%cycle
        #print(cur, dis, D[cur], D, target)
        dis = 0
        if dis == target:
            print(cur+1)
            exit()
        while True:
            dis = dis+1
            cur = G[cur]
            if dis == target:
                print(cur+1)
                exit()


Measured memory_bytes: 33808
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<queue> 
#define sqr(x) (x)*(x)
#define mk(x,y,z) make_pair(x,make_pair(y,z))
using namespace std;
int n,m,i,j,k,dp[1000005][25],num[1000005],re[1000005],x,y,z,lg[1000005],l,r;
priority_queue<pair<int,pair<int,int>/**/>,vector<pair<int,pair<int,int>/**/>/**/>,greater<pair<int,pair<int,int>/**/>/**/>/**/> pq;
int rmq(int s,int t)
{
	int c=(t-s)/2+1;
	int d=lg[c];
	return min(dp[s][d],dp[t-2*((1<<d)-1)][d]);
}
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	for (i=1;i<=n;i++)
	{
		cin>>num[i];
		re[num[i]]=i;
	}
	for (i=1;i<=n;i++)
	{
		x=lg[i-1];
		if (1<<(x+1)<=i) x++;
		lg[i]=x;
	}
	for (i=1;i<=n;i++)
	{
		dp[i][0]=num[i];
	}
	for (i=n+1;i<=1000000;i++) dp[i][0]=1<<30;
	for (j=1;j<=18;j++)
	{
		for (i=1;i<=n;i++)
		{
			dp[i][j]=min(dp[i][j-1],dp[i+(1<<j)][j-1]);
		}
	}
	pq.push(mk(rmq(1,n-1),1,n));
	for (i=1;i<=n/2;i++)
	{
		x=pq.top().first;
		y=rmq(re[x]+1,pq.top().second.second);
		cout<<x<<' '<<y<<' ';
		x=re[x];
		y=re[y];
		l=pq.top().second.first;
		r=pq.top().second.second;
		pq.pop();
		if (l<x-1) 
		{
			pq.push(mk(rmq(l,x-1-1),l,x-1));
		}
		if (x+1<y-1)
		{
			pq.push(mk(rmq(x+1,y-1-1),x+1,y-1));
		}
		if (y+1<r)
		{
			pq.push(mk(rmq(y+1,r-1),y+1,r));
		}
	}
	return 0;
} 

Measured memory_bytes: 110204
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>
#include <tuple>
#include <complex>


#define FOR(i, a, b)		for(int i = (int)(a); i < (int)(b); ++i)
#define FORE(i, a, b)		for(int i = (int)(a); i <= (int)(b); ++i)
#define REP(i, n)			FOR(i, 0, n)
#define REPE(i, n)			FORE(i, 0, n)
#define ALL(x)				(x).begin(),(x).end()
#define DEBUG_DC(x)			cout << #x << ": " << x << endl
#define ANS_DC(x)			cout <<  x << endl
#define VEC_TYPE			int
#define INF					1e4+1

using namespace std;
typedef long long ll;
typedef vector<VEC_TYPE> vdef;
typedef vector<vdef> vvdef;
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<typename T>inline T mygcd(T a, T b) { return b ? mygcd(b, a%b) : a; }
template<typename T>inline T mylcm(T a, T b) { return a * b / mygcd(a, b); }


int main()
{
	int a,b;
	cin >> a >> b;
	int ans = 0;

	if (a <= 5)
	{
		ans = 0;
	}
	else if (a<=12)
	{
		ans = 0.5*b;
	}
	else
	{
		ans = b;
	}
	ANS_DC(ans);
	return 0;
}

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

typedef long long ll;


int a, b, h;

void solve() {

    cout <<(a+b)*h/2;

}


int main() {

    cin >> a >> b >> h;

    solve();

   return 0;
}


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

using namespace std;

long long gcd(long long a,long long b)
{
    if(b==0)
        return a;

    return gcd(b,a%b);
}

void test()
{
   string s;
   cin>>s;

   int pcount=0;
   for(auto x:s)
   {
       if(x=='p')
        pcount++;
   }

   cout<<s.size()/2-pcount<<"\n";

}

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

    test();

    return 0;
}


Measured memory_bytes: 3772
//#include <bits/stdc++.h>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>

using namespace std;

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

    string x;

    cin >> x;

    if(x == "Sunny") {
        cout << "Cloudy" << endl;
    } else if(x == "Cloudy") {
        cout << "Rainy" << endl;
    } else {
        cout << "Sunny" << endl;
    }
}

Measured memory_bytes: 256
let rec read u =
  try let (a, b, e, c, d, f) =
        Scanf.scanf "%d %d %d %d %d %d\n" (fun a b c d e f -> (a, b, c, d, e, f)) in
      let adbc = a * d - b * c and s = e * d - b * f and t = a * f - e * c in
      let x = (float s)/.(float adbc) and y = (float t)/.(float adbc) and
          f z = if z = -0.0 then 0.0 else z in
      Printf.printf "%.3f %.3f\n" (f x) (f y);
      read u
  with
    End_of_file -> ()
    in read ();;

Measured memory_bytes: 2284
L = []
for _ in range(3):
  A,B = map(int,input().split()) 
  L.append(A)
  L.append(B)
L.sort()
M = []
a = L.count(1)
b = L.count(2)
c = L.count(3)
d = L.count(4)
M.append(a)
M.append(b)
M.append(c)
M.append(d)
M.sort()
if M == [1,1,2,2]:
  print('YES')
else:
  print('NO')


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define M 500000
#define MAX 10000000000000010
#define mod 1000000007
#define ss second
#define ff first
#define ll long long int
#define pb push_back
#define ld double
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

int main()
{
	ll n,k;
	cin>>n>>k;
	ll h[n];
	for(int i=0;i<n;i++)
		cin>>h[i];
	sort(h,h+n);
	ll ans = 0;
	for(int i=0;i<n-k;i++)
	{
		ans+=h[i];
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s,t;
    int max;
    cin >> s >> t;
    sort(s.begin(), s.end(), less<char>());
    sort(t.begin(), t.end(), greater<char>());
    max = (s.length() < t.length())?s.length():t.length();
    for(int i=0; i<max; i++){
        if(s[i] < t[i]){
            cout << "Yes" << endl;
            return 0;
        }else if(s[i] > t[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << ((s.length() < t.length())? "Yes":"No") << endl;
            
    return 0;
}

Measured memory_bytes: 256
s=input()
ret=0
# ループを各文字の間bit分回す
for i in range(1<<(len(s)-1)):
    t=list(s)
    # 実はiとjの向きについてあまり深く考える必要は無いです。どうせ全探索するので。
    for j in reversed(range(1, len(s))):
        if i&(1<<(j-1)):
            t=t[:j]+["+"]+t[j:]
    ret+=eval("".join(t))
print(ret)

Measured memory_bytes: 3060
import java.util.*;

import java.io.*;
public class Main {
    public static void main(String[] args){
        // Your 
     
     Scanner sc= new Scanner(System.in);
     boolean[][] card = new boolean[4][13];
     int num=sc.nextInt();
     for(int i=0;i<num;i++){
         String sign= sc.next();
         int cards=sc.nextInt();
         switch(sign){
             case "S":
                 card[0][cards-1]=true;
                 break;
             case "H":
                 card[1][cards-1]=true;
                 break;
            case "C":
                 card[2][cards-1]=true;
                 break;
            case "D":
                 card[3][cards-1]=true;
                 break;
    
         }
     }
     
     for(int i=0;i<4;i++)
     {
         for(int y= 0;y<13;y++){
             if(card[i][y]==false){
                 switch(i){
                 case 0:
                     System.out.printf("S %d\n",y+1);
                     break;
                     case 1:
                     System.out.printf("H %d\n",y+1);
                     break;
                     case 2:
                     System.out.printf("C %d\n",y+1);
                     break;
                     case 3:
                     System.out.printf("D %d\n",y+1);
                     break;
             }
         }
     }
        
}
}
}



Measured memory_bytes: 26424
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
 
int cnt, A[500010];
 
inline void mergeSort(int left, int right) {
  if (left + 1 < right) {
    int mid = (left + right) / 2;
    mergeSort(left, mid);
    mergeSort(mid, right);
    cnt += right - left;
  }
}
 
int main() {
  // use scanf in CodeForces!
  cin.tie(0);
  ios_base::sync_with_stdio(false);
 
  int N;
  cin >> N;
  REP(i, N) cin >> A[i];
  mergeSort(0, N);
  sort(A, A + N);
  REP(i, N) {
    cout << A[i] << (i == N-1 ? '\n' : ' ');
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3172
#include<bits/stdc++.h>
#define eps 1e-9;
#define MOD 1000000007;
#define INV_10 299473306;
using namespace std;
int main()
{
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  int x, y, nb1, nb2, nb3;
  cin >> x >> y >> nb1 >> nb2 >> nb3;
  vector<pair<int, int>> a(nb1+nb2+nb3), b(nb2), c(nb3);
  for(int i = 0; i < nb1; i++)
  {
  	cin >> a[i].first;
  	a[i].second=0;
  }
  for(int i = 0; i < nb2; i++)
  {
  	cin >> a[nb1+i].first;
  	a[nb1+i].second=1;
  }
  for(int i = 0; i < nb3; i++)
  {
  	cin >> a[nb1+nb2+i].first;
  	a[nb1+nb2+i].second=2;
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  int nb_r=0, nb_g=0, chosen=0;
  long long sum=0;
  for(int i = 0; i < nb1+nb2+nb3 && chosen < x+y; i++)
  {
  	if(a[i].second==2)
  	{
  		chosen++;
  		sum+=a[i].first;
  	}
  	else if(a[i].second==0)
  	{
  		if(nb_r < x)
  		{
  			nb_r++;
  			chosen++;
  			sum+=a[i].first;
  		}
  	}
  	else
  	{
  		if(nb_g < y)
  		{
  			nb_g++;
  			chosen++;
  			sum+=a[i].first;
  		}
  	}
  }
  cout << sum << '\n';
}

Measured memory_bytes: 4224
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>

    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    using namespace std;
    using ll = long long;

    int main(){
      int n;
      cin>>n;
      VEC(int,a,n);
      int ans1 = 0,ans2 = 0;
      auto f = vec(bool,8);
      int cnt = 0;
      rep(i,8)f[i] = false;
      rep(i,n){
          rep(j,8){
              if(a[i]>=400*j && a[i]<400*(j+1))f[j] = true;
          }
          if(a[i]>=3200)cnt++;
      }
      rep(i,8){
          if(f[i]){
              ans1++;
              ans2++;
          }
      }
      if(cnt){
          ans1 = max(1,ans1);
          ans2 += cnt;
      }
      cout<<ans1<<" "<<ans2<<endl;
    }


Measured memory_bytes: 256
def main():
    N, x = map(int, input().split())
    A = [int(i) for i in input().split()]
    ans = 0
    for i in range(N - 1):
        if i == 0 and A[i] > x:
            ans += A[i] - x
            A[i] = x
        if A[i] + A[i + 1] > x:
            ans += A[i + 1] - (x - A[i])
            A[i + 1] = x - A[i]
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 63984
s=int(input())
listS=[s]
for i in range(10**6):
  if listS[i]%2==0:
    if listS[i]//2 in listS:
      m=i+2
      break      
    listS+=[listS[i]//2]
  else:
    if 3*listS[i]+1 in listS:
      m=i+2
      break
    listS+=[3*listS[i]+1]
print(m)

Measured memory_bytes: 2940
from decimal import Decimal,getcontext
from math import ceil

N = int(input())

takahashi,aoki = 1,1

for _ in range(N):
    a,b = map(int,input().split())
    c = max(ceil(takahashi/Decimal(a)),ceil(aoki/Decimal(b)))
    takahashi = c*a
    aoki = c*b

print(takahashi+aoki)

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



const int N = 3005, MOD = 1e9 + 7;



int n;
double p[N], dp[N][N];



int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    dp[0][0] = 1;
    for(int i = 1; i <= n; i++){
        cin >> p[i];
        for(int j = 0; j <= n; j++){
            if(j - 1 >= 0){
                dp[i][j] += dp[i - 1][j - 1] * p[i];
            }
            dp[i][j] += dp[i - 1][j] * (1 - p[i]);
        }
    }
    double ans = 0;
    for(int i = n / 2 + 1; i <= n; i++){
        ans += dp[n][i];
    }
    cout << fixed << setprecision(10) << ans;
}


Measured memory_bytes: 70656
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <math.h>
#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <stack>
#include <queue>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
using ll = long long;
using ld = long double;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll N, i, a, c, ans=0;
    vector<ll> A, B, C;

    cin >> N;
    for(i=0; i<N; i++){
        cin >> a;
        A.push_back(a);
    }
    for(i=0; i<N; i++){
        cin >> a;
        B.push_back(a);
    }
    for(i=0; i<N; i++){
        cin >> a;
        C.push_back(a);
    }

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    for(i=0; i<N; i++){
        a = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
        c = upper_bound(C.begin(), C.end(), B[i]) - C.begin();

        ans += a * (N-c);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3316
#include <stdio.h>
#include <math.h>

int main(void){

	int in[3]={0};
	
	int tmp=0;
	int i,j;
	scanf("%d %d %d",&(in[0]),&(in[1]),&(in[2]));
	
	for(i=0;i<2;i++){
		for(j=2;j>=i+1;j=j-1){
			if(in[j]<in[j-1]){
				tmp=in[j];
				in[j]=in[j-1];
				in[j-1]=tmp;
			}
		}
	}
	
	
	
	printf("%d",abs(in[0]-in[1])+abs(in[1]-in[2]));	
	
	return 0;
}


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

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    int c[12], a[12][12];
    rep(i,n){
        cin >> c[i];
        rep(j,m){
            cin >> a[i][j];
        }
    }

    int res = 2000000;
    for(int bit = 0; bit < (1<<n); ++bit){
        vector<int> S;
        for(int i = 0; i < n; i++){
            if(bit & (1<<i)){
                S.push_back(i);
            }
        }
        int cost = 0;
        vector<int> u(m);
        for(int i = 0; i < S.size(); i++){
            int j = S[i];
            cost += c[j];
            for(int k = 0; k < m; k++){
                u[k] += a[j][k];
            }
        }
        bool flag = true;
        for(int i = 0; i < m; i++){
            if(u[i] < x){
                flag = false;
                break;
            }
        }
        if(flag){
            res = min(res,cost);
        }
    }
    if(res != 2000000){
        cout << res << endl;
    }else{
        cout << -1 << endl;
    }
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
using namespace std;
using ll=long long;
//using R=double;

const int INF = 10000000;
typedef pair<int, int> p;

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

int main(){

    int N;
    ll X;
    cin >> N >> X;
    ll x[N];
    ll absx[N];
    for(int i = 0; i < N; i++){
        cin >> x[i];
        absx[i] = abs(X-x[i]);
    }

    if(N==1){
        cout << abs(X-x[0]) << endl;
        return 0;
    }

    ll gcd_now = absx[0];
    for(int i = 0; i < N; i++){
        gcd_now = gcd(gcd_now, absx[i]);
    }

    cout << gcd_now << endl;

    return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;

typedef pair<double,string> pds;

bool comp(const pds &a, const pds &b)
{
  if(a.first != b.first)
    return a.first > b.first;
  else
    return a.second < b.second;
}

int main()
{
  while(1){
    int N;
    cin >> N;
    if(N == 0) break;
    vector<pds> c(N);
    REP(i,N){
      int P, A, B, C, D, E, F, S, M;
      cin >> c[i].second >> P >> A >> B >> C >> D >> E >> F >> S >> M;
      c[i].first = (double)(F*M*S-P)/(double)(A+B+C+(D+E)*M);
    }
    sort(c.begin(),c.end(),comp);
    REP(i,N)
      cout << c[i].second << endl;
    cout << '#' << endl;
  }
}

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

int main() {
    int q;
    cin >> q;
    
    rep(i,q) {
        string X,Y;
        cin >> X >> Y;
        int lX=X.size(), lY=Y.size();
        vector<vector<int>> dp(lX+1, vector<int>(lY+1,0));

        rep(i,lX)
            rep(j,lY)
                if(X.at(i) == Y.at(j))
                    dp.at(i+1).at(j+1) = dp.at(i).at(j)+1;
                else
                    dp.at(i+1).at(j+1) = max(dp.at(i+1).at(j), dp.at(i).at(j+1));

        cout << dp.at(lX).at(lY) << endl;
    }
}


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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define lfs <<fixed<<setprecision(10)<<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = n - 1; i >= (ll)(m); i--)
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>v,ll n){cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
template<typename T>
void emp(map<T,ll>&m, T x){m.emplace(x,0).first->second++;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

template<typename T>
map<T,ll> compress(vector<T> v){
  auto t=v;
  sort(ALL(t));
  t.erase(unique(ALL(t)),t.end());
  map<T, ll> ret;
  for(ll i=0;i<(ll)t.size();i++)
    ret[t[i]]=i;
  return ret;
}

int main(){
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>a(n);
  rep(i,0,n)cin>>a[i];
  auto mp=compress(a);
  rep(i,0,n){
    if(abs(i-mp[a[i]])%2==1)res++;
  }
  cout<<(res+1)/2<<endl;
  return 0;
}

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

int main(void) {
	string str;
	cin >> str;

    int p = str.size()-1;
    while (p>0) {
        if (p > 3 && str.compare(p-4, 5, "dream") == 0) {
            p = p - 5;
        } else if(p > 5 && str.compare(p-6, 7, "dreamer") == 0) {
            p = p - 7;
        } else if(p > 3 && str.compare(p-4, 5, "erase") == 0) {
            p = p - 5;
        } else if(p > 4 && str.compare(p-5, 6, "eraser") == 0) {
            p = p - 6;
        }else {
            cout << "NO" << endl;
            return 0;
        }
    }

	cout << "YES" << endl;

	return 0;
}

Measured memory_bytes: 512