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

int main(int argc, char *argv[]){
  int n, d, x;
  cin >> n >> d >> x;
  vector<int> q(n), p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  
  int dp[n + 1][(int)1e5 + 1];
  for (int i = 0; i < d - 1; i++) {
    for (int i = 0; i < n; i++) {
      cin >> q[i];
    }
    memset(dp, 0, sizeof(dp));
    for (int j = 0; j < n; j++) {
      for (int k = 0; k <= x; k++) {
        if(p[j] <= k){
          dp[j + 1][k] = max(dp[j][k],
                             dp[j + 1][k - p[j]] + q[j] - p[j]);
        }else{
          dp[j + 1][k] = max(dp[j][k], dp[j + 1][k - 1]);
        }
      }
    }
    p = q;
    x += dp[n][x];
  }
  std::cout << x << std::endl;
  return 0;
}

Measured memory_bytes: 5512
N = input()
F = [map(int, raw_input().split()) for i in range(N)]
P = [map(int, raw_input().split()) for i in range(N)]
M = 10
ans = -10**10
for mask in range(1, 2**M):
    m = [int((mask & (2**i)) > 0) for i in range(M)]
    ok = False
    sales = 0
    for i in range(N):
        cnt = 0
        for j in range(M):
            if m[j] + F[i][j] == 2:
                ok = True
                cnt += 1
        sales += P[i][cnt]
    if ok:
        ans = max(ans, sales)
print ans

Measured memory_bytes: 2696
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long b = 0;
        List<Character> list = new ArrayList<>();
        while (n > 0){
            n--;
            b = n % 26;
            list.add((char)('a' + b));
            n /= 26;
        }
        Collections.reverse(list);
        for(char c : list) {
            System.out.print(c);
        }
    }
}

Measured memory_bytes: 35644
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		String s = sc.next();

		int n = 0;
		Deque<Character> stack = new ArrayDeque<>(100000);
		for (int i = 0; i < s.length(); i++) {
			Character c = s.charAt(i);

			Character t = stack.peek();
			if (t != null) {
				if ((c == '1' && t == '0') || (c == '0' && t == '1')) {
					stack.removeFirst();
					n += 2;
				} else {
					stack.push(c);
				}
			} else {
				stack.push(c);
			}

		}
		out.println(n);

		sc.close();

	}

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

}


Measured memory_bytes: 27860
#include <algorithm>
#include <cstdint>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using namespace std;

using lint=int64_t;
using uint=uint32_t;
using ulint=uint64_t;

template<class T>
using vector2d=vector<vector<T>>;

template<class T>
bool UpdateMax(T &a, const T &b){
  if(a<b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template<class T>
bool UpdateMin(T &a, const T &b){
  if(a>b){
    a=b;
    return true;
  }else{
    return false;
  }
}

template <class T>
void OutVec(const vector<T>& vec){
  for(int i = 0; i < vec.size() - 1; ++i){
    cout<<vec[i]<<" ";
  }
  cout<<vec.back()<<endl;
}

template <class T>
void OutVec2d(const vector2d<T>& vec){
  for(auto v:vec){
    OutVec(v);
  }
}

bool Judge(vector2d<char>& a,vector2d<char>& b,int r, int c){
  int m=b.size();
  for(int h=0;h<m;h++){
    for(int w=0;w<m;w++){
      if(a[r+h][c+w]!=b[h][w]){
        return false;
      }
    }
  }
  return true;
}

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int n,m;
  cin>>n>>m;
  vector2d<char> a(n,vector<char>(n)),b(m,vector<char>(m));

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      cin>>a[i][j];
    }
  }
  for(int i=0;i<m;i++){
    for(int j=0;j<m;j++){
      cin>>b[i][j];
    }
  }

  for(int r=0;r+m<=n;r++){
    for(int c=0;c+m<=n;c++){
      if(Judge(a,b,r,c)){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;

  return 0;
}




Measured memory_bytes: 256
def main():
    S = input()
    Q = int(input())
    queries = [input() for _ in range(Q)]

    reverse = False
    front = ""

    for e in queries:
        if e[0] == '1':
            reverse = not reverse
        else:
            T, F, C = e.split()
            if F == '2': F = True
            else: F = False

            if reverse ^ F:
                # 末尾に追加
                S += C
            else:
                # continue
                # 先頭に追加，ここの計算がボトルネック
                front += C
        # print(S)

    if reverse:
        S = S[::-1]
        S = S + front
    else:
        S = front[::-1] + S

    print(S)
    

if __name__ == '__main__':
    main()


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

using namespace std;

int main()
{
    string s, t;
    cin >> s >> t;

    int ans = 0;
    for (int i = 0; i < s.size(); ++i)
    {
        if(s[i] != t[i])
            ++ans;
    }

    cout << ans << "\n";

    return 0;
}

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

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

    int N;
    cin >> N;
    vector<int> A(1 << N);
    for (int i = 0; i < 1 << N; i++) cin >> A[i];
    vector<pair<int, int>> dp(1 << N);
    for (int S = 0; S < 1 << N; S++) dp[S].first = A[S];
    for (int k = 0; k < N; k++) {
        for (int S = 0; S < 1 << N; S++) {
            if ((S >> k) & 1) {
                if (dp[S].first < dp[S ^ (1 << k)].first) {
                    dp[S].second = max(dp[S].first, dp[S ^ (1 << k)].second);
                    dp[S].first = dp[S ^ (1 << k)].first;
                } else {
                    dp[S].second = max(dp[S].second, dp[S ^ (1 << k)].first);
                }
            }
        }
    }
    int ans = 0;
    for (int K = 1; K < 1 << N; K++) {
        ans = max(ans, dp[K].first + dp[K].second);
        cout << ans << '\n';
    }
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

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

ll X,Y,Z;
ll A[111];
ll i, j, k;
int main(){
    scanf("%lld%lld%lld", &X, &Y, &Z);
    printf("%lld %lld %lld", Z, X, Y);
    return 0;
}

Measured memory_bytes: 256
N = gets.to_i
P = gets.split.map(&:to_i)

R = (N - 2).downto(1).each_with_object(P.dup + [0]){|i, o| o[i] = o[i, 2].max}.drop(1)
L = (1 ... N).each_with_object([0] + P.dup){|i, o| o[i] = o[i - 1, 2].max}.take(N)

def f(i)
  p = P[i]
  r1 = R[i] < p ? N : (i + 1 ... N).find{|j| P[j] > p}
  r2 = (r1 + 1... N).find{|j| P[j] > p} || N
  l1 = L[i] < p ? -1 : (i - 1).downto(0).find{|j| P[j] > p}
  l2 = (l1 - 1).downto(0).find{|j| P[j] > p} || -1
  p*((l1 - l2)*(r1 - i) + (i - l1)*(r2 - r1))
end

puts (0 ... N).inject(0){|s, i| s + f(i)}

Measured memory_bytes: 14628
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<climits>
#include<queue>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
using namespace std;
typedef pair<int, int> P;
typedef long long int ll;
typedef pair<ll,ll> LLP;
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
#define INF 1000000007
#define MOD 1000000007
#define MAX_N 105
#define MAX_W 100005

ll dp[MAX_N][MAX_W];//0:海,1:山,2:宿題,dp[i][j] = iをj日目に行う時の幸福度
ll weight[MAX_N];
ll value[MAX_N];

int main(){

    ll n,weight_maxi;
    cin >> n >> weight_maxi;
    REP(i,n){
        cin >> weight[i] >> value[i];
    }

    for(int i = 1;i <= n;i++){
        for(int j = 0;j <= weight_maxi;j++){

            if(j < weight[i-1]){
                dp[i][j] = dp[i-1][j];
            }else{
                dp[i][j] = max(dp[i-1][j],dp[i-1][j-weight[i-1]]+value[i-1]);
            }
        }
    }
    cout << dp[n][weight_maxi] << endl;


    return 0;
}

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

const ll MAX_N = 110;
const ll MAX_V = 100100;
const ll INF = 1e10;
ll dp[110][100100];

int main(){
    ll N, W;
    cin >> N >> W;
    vector<ll> w(N);
    vector<ll> v(N);
    for (ll i=0; i<N; i++) {
        cin >> w[i] >> v[i];
    }
    for (ll i=0; i<MAX_N; i++) {
        for (ll j=0; j<MAX_V; j++) {
            dp[i][j] = INF;
        }
    }
    dp[0][0] = 0;
    for (ll i=0; i<N; i++) {
        for(ll sum_v = 0; sum_v < MAX_V; sum_v++) {
            if(sum_v - v[i] >= 0) dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v - v[i]] + w[i]);
            dp[i+1][sum_v] = min(dp[i+1][sum_v], dp[i][sum_v]);
        }
    }
    ll ans = 0;
    for(ll sum_v = 0; sum_v < MAX_V; sum_v++) {
        if(dp[N][sum_v] <= W) ans = sum_v;
    }
    cout << ans << endl;
}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intll int long long
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main() {
  int n ;
  cin >> n ;
  int ans = INF;
  
  rep(i,n){
    int c ;
    cin >> c ;
    int now = 0;
    while(c%2 == 0 && c != 0){
      c /=2 ;
      now++;
    }
    ans = min(now,ans);
  }
  
  cout << ans ;
  
}


Measured memory_bytes: 256
import math 
from decimal import Decimal 
a,b,c=map(int,input().split()) 
A=Decimal(a)**Decimal(0.5) 
B=Decimal(b)**Decimal(0.5)
C=Decimal(c)**Decimal(0.5)
if A+B<C: 
    print("Yes") 
else: 
    print("No")


Measured memory_bytes: 5076
<?php

  $N = trim(fgets(STDIN));

  $H = explode(" ", trim(fgets(STDIN)));

  $count = 0;
  $max = 0;

  for ($i = 0; $i < $N - 1; $i++) {

      if ($H[$i+1] <= $H[$i]) {

          $count ++;
        
      } else {

          $max = max($max, $count);
          $count = 0;
        
      } 
    
  }

if ($count > 0) {

  $max = max($max, $count);

}

echo $max

?>

Measured memory_bytes: 14840
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let a = read_vec::<i64>();
    let mut count = BTreeMap::new();
    for num in a {
        *count.entry(num).or_insert(0) += 1;
    }
    let mut a = 0;
    let mut b = 0;
    for (&k, &v) in count.iter().rev() {
        if v > 1 {
            if a == 0 {
                a = k;
                if v > 3 {
                    b = k;
                }
            } else if b == 0 {
                b = k;
            }
        }
    }
    println!("{}", a * b);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 8444
import numpy as np

N, M, X = [int(x) for x in input().split()]
books = []
ans = 10 ** 7
for i in range(N):
  books.append([int(x) for x in input().split()])
books = np.array(books)
for i in range(1,2**N):
  t = np.array([0]*(M+1))
  for j in range(N):
    if i & 1 == 1:
      t = t + books[j]
    i = i >> 1
  s = min(t[1:])
  if min(t[1:]) >= X:
    if t[0] < ans:
      ans = t[0]
  #print(ans)
if ans == 10 ** 7:
  print(-1)
else:
  print(ans)

Measured memory_bytes: 27204
#include <bits/stdc++.h>
using namespace std;
int N,a[200001];

int main(){
    cin >> N;
    for (int i=0;i<N;i++) cin >> a[i];
    sort(a,a+N);
    for (int i=0;i<N-1;i++)
        if(a[i] == a[i+1]){
            cout << "NO" << endl;
            return 0;
        }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>

int main(){
	int x[1000001];
	int i, j;
	for(i = 0; i <= 1000000; i++){
		scanf("%d", &x[i]);
		if(x[i] == 0){
			break;
		}
	}
	for(j = 0; j <= i-1; j++){
		printf("Case %d: %d\n", j+1, x[j]);
	} 
	return 0;
}

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

int main() {
  int a,b;cin>>a>>b;
  int ans=0;
  for(int i=1;i<=b-a;i++){
     int c=i;
    ans+=c;
  }
  cout<<ans-b<<endl;
}

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

typedef long long ll;

const int MAXN = 410;
const ll INF = 1e14;

ll dp[MAXN][MAXN],V[MAXN],pref[MAXN];
int N;

ll calc(ll a,ll b){
	if(a > b) return INF;
	return pref[b] - pref[a-1];
}

ll solve(int ini,int fim){
	if(dp[ini][fim] != -1) return dp[ini][fim];
	if(ini == fim) return dp[ini][fim] = 0;
	if(ini + 1 == fim) return dp[ini][fim] = V[ini] + V[fim];

	ll best = INF;

	for(int i = ini;i<fim;i++){
		ll cand = solve(ini,i) + solve(i+1,fim) + calc(ini,fim);
		best = min(best,cand);
	}

	return dp[ini][fim] = best;

}

int main(){

	memset(dp,-1,sizeof(dp));

	cin >> N;
	for(int i = 1;i<=N;i++) cin >> V[i];

	for(int i = 1;i<=N;i++) pref[i] = pref[i-1] + V[i];

	cout << solve(1,N) << endl;

	return 0;

}

Measured memory_bytes: 4968
package main

import (
	"fmt"
	"sort"
)

type byRune []rune

func (r byRune) Len() int { return len(r) }
func (r byRune) Swap(i, j int) {
	r[i], r[j] = r[j], r[i]
}

func (r byRune) Less(i, j int) bool {
	return r[i] < r[j]
}

func sortString(s string, reverse bool) string {
	r := []rune(s)
	if reverse {
		sort.Sort(sort.Reverse(byRune(r)))
	} else {
		sort.Sort(byRune(r))
	}
	return string(r)
}

func main() {
	var s, t string
	fmt.Scan(&s, &t)
	s = sortString(s, false)
	t = sortString(t, true)
	if s < t {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<set>
#include<map>
#include<queue>
#include<cstring>
#include<sstream>
using namespace std;

typedef long long ll;

int main() {
  int N; cin >> N;
  int A[100010];
  for ( int i = 0; i < N; i++ ) {
    cin >> A[i];
  }
  if ( N == 1 || N == 2 ) {
    cout << 1 << endl;
    return 0;
  }

  int cnt = 1;
  bool f1 = false; //plus
  bool f2 = false;
  for ( int i = 0; i < N-1; i++ ) {
    //cout << "i " << i << endl;

    if ( A[i] < A[i+1] ) {
      f1 = true;
      if (f1&&f2) {
	cnt++;
	if ( i+1 == N ) {
	  cnt++;
	  break;
	}
	//i++;
	f1 = f2 = false;
      }
    } else if ( A[i] > A[i+1] ) {
      f2 = true;
      if (f1&&f2) {
	cnt++;
       
	if ( i+1 == N ) {
	  cnt++;
	  break;
	}
	//	i++;
	f1 = f2 = false;
      }
    } else if ( A[i] == A[i+1] ) {
      continue;
    }
  }
  cout << cnt << endl;
  return 0;
}


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

bool isPal(string s, int a, int b) {
  int i = a, j = b - 1;
  while(s[i] == s[j] && i++ < j--);
  return i >= j;
}

int main() {
  string s;
  cin >> s;
  int n = s.size();
  if (isPal(s,0,n) && isPal(s,0,(n-1)/2) && isPal(s,(n+3)/2-1,n))
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

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

int main() {
  int n,m,x;
  cin >> n >> m >> x;
  
  int ans = 0;
  for(int i=0; i<m; i++){
    int p; cin >> p;
    if(p < x) ans++;
  }
  cout << min(ans, m-ans) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
const int INF = 1<<30;

int main(){
  int n;cin>>n;
  vector<int> w(n), s(n);
  for(int i=0;i<n;i++){
  	cin>>w[i];
    if(i==0){
      s[0] = w[i];
    }else{
      s[i] = s[i-1] + w[i];
    }
  }
  int ans=INF;
  for(int i=0;i<n;i++){
  	ans = min(abs(s[n-1]-s[i]-s[i]), ans);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			List<Integer> lines = new ArrayList<>();
			while(sc.hasNext()) {
				lines.add(Integer.parseInt(sc.nextLine()));
			}
			lines.sort(Comparator.reverseOrder());
			int len = Math.min(lines.size(), 3);
			for (int i = 0; i < len; i++) {
				System.out.println(lines.get(i));
			}
		}
	}
}

Measured memory_bytes: 25984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long MOD = 1000000007LL; /* 998244353LL; */

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

struct ModInv{
    int mod = MOD;
    vector<ll> fact,inv,finv;
    ModInv(int size) : fact(size+1,1), inv(size+1,1), finv(size+1,1) {
        for (int i=2; i < size; i++) {
            fact[i] = fact[i-1] * i % mod;
            inv[i]  = mod - inv[mod%i] * (mod/i) % mod;
            finv[i] = finv[i-1] * inv[i] % mod; 
        }
    }
    ll nPr(int n, int r){
        if (r < 0 || n < r) return 0;
        return fact[n] * finv[n-r] % mod;
    }
    ll nCr(int n, int r) {
        if (r < 0 || n < r) return 0;
        return fact[n] * (finv[r] * finv[n-r] % mod) % mod;
    }
    ll nHr(int n, int r){
        if (n < 0 || r < 0) return 0;
        return nCr(n+r-1, n-1);
    }
};

int main() {
    int H,W,A,B; cin >> H >> W >> A >> B;
    ModInv modinv = ModInv(200000);

    int ans = 0;
    rep(i,H-A) {
        ans += modinv.nCr(B-1+i,i) * modinv.nCr(W-B-1+H-1-i,W-B-1) % MOD;
        ans %= MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 7988
#include <bits/stdc++.h>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

int H,W;
char C[22][22];

map<int,pair<int,int>> mp;
int stx,sty;
vector<pair<int,int>> v;

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

void bfs(){
    for(int i=0;i<=v.size();i++){
        for(int j=0;j<=H;j++){
            for(int k=0;k<=W;k++){
                dist[i][j][k]=MOD;
            }
        }
    }
    for(int i=0;i<v.size();i++){
        queue<pair<int,int>> Q;
        Q.push(v[i]);
        dist[i][v[i].first][v[i].second]=0;
        while(!Q.empty()){
            int x,y;
            tie(x,y)=Q.front();
            Q.pop();

            for(int j=0;j<4;j++){
                int nx=x+dx[j];
                int ny=y+dy[j];
                if(nx<0||ny<0||nx>=H||ny>=W) continue;
                if(C[nx][ny]=='x') continue;
                if(dist[i][nx][ny]<=dist[i][x][y]+1) continue;
                dist[i][nx][ny]=dist[i][x][y]+1;
                Q.push(mkp(nx,ny));
            }
        }
    }
}

void solve(){
    int cnt=1;
    mp.clear();
    v.clear();
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>C[i][j];
            if(C[i][j]=='o'){
                stx=i;
                sty=j;
            }
        }
    }
    v.push_back(mkp(stx,sty));
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(C[i][j]=='*'){
                mp[cnt]=mkp(i,j);
                cnt++;
                v.push_back(mkp(i,j));
            }
        }
    }

    bfs();

    vector<int> p(v.size()-1);
    iota(p.begin(),p.end(),1);
    int ans=MOD;
    do{
        int now=0;
        int res=0;
        for(int i=0;i<p.size();i++){
            int x=mp[p[i]].first;
            int y=mp[p[i]].second;
            if(dist[now][x][y]==MOD){
                res=MOD;
                break;
            }else res+=dist[now][x][y];
            now=p[i];
        }
        ans=min(ans,res);
    }while(next_permutation(p.begin(),p.end()));
    
    if(ans<MOD) cout<<ans<<endl;
    else cout<<-1<<endl;
}

int main(){
  while(1){
      cin>>W>>H;
      if(W==0) break;
      solve();
  }

  return 0;
}



Measured memory_bytes: 3176
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

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

int main()
{
    map<string,ll> m;
    map<string,ll> ::iterator mi;
    ll n;
    cin>>n;
    rep(i,n)
    {
        string s;
        cin>>s;
        m[s]++;
    }
    vector<string>ans;
    ll max=0;
    for(mi=m.begin();mi!=m.end();mi++)
    {
        if(max<mi->second)max=mi->second;
    }
    for(mi=m.begin();mi!=m.end();mi++)
    {
        if(max==mi->second)ans.push_back(mi->first);
    }
    sort(ans.begin(),ans.end());

    rep(i,ans.size())
    {
        cout<<ans[i]<<endl;
    }
    
    
    
}

Measured memory_bytes: 26868
function Main(input) {
  const X = input.split(' ')[0];
  const Y = input.split(' ')[1];
  var ans = 'No';
  for (var i=0; i<=X; i++) {
    if (Y == 2*i+4*(X-i)){
      ans = 'Yes';
      break;
    }
  }
  console.log(ans);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 29552
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#include <utility>
#include <set>
#include <stack>
#include <deque>
#include <ctime>
#include <random>
#include <cassert>
#include <cmath>
#include <climits>
#include <queue>
#include <cstring>
#include <bitset>
#include <iomanip>
#include <chrono>

/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("popcnt")
#pragma GCC target("avx2")
*/


#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << x << endl;
#else 
    #define dbg(x)
#endif

#define int long long
#define pb push_back
#define ppb pop_back()
#define mp make_pair
#define fi(a,b) for (int i=a;i<b;i++)
#define fj(a,b) for (int j=a;j<b;j++)
#define fk(a,b) for (int k=a;k<b;k++)
#define fi1(a,b) for (int i=a-1;i>=b;i--)
#define fj1(a,b) for (int j=a-1;j>=b;j--)
#define fk1(a,b) for (int k=a-1;k>=b;k--)
#define fx(x,a) for (auto& x : a)
#define rep(i, a, b) for (int i = a; i < b; ++i)
#define rep1(i, a, b) for (int i = a - 1; i >= b; --i)
#define siz(x) (int)x.size()
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

using namespace std;

template<typename T1, typename T2>inline void mine(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void maxe(T1 &x, T2 y) { if (x < y) x = y; }

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << ' ';
    return a;
}


typedef long long ll;
typedef unsigned long long ull;
typedef char ch;
typedef string str;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef vector<ch> vch;
typedef vector<vch> vvch;
typedef vector<str> vs;



const int MOD = 1000000007;
const int INF = 1000000050;
const long long BIG = (long long)2e18 + 50;
const int MX = 200010;
const double EPS = 1e-9;
const int PW = 20;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int a[MX];
int dp[MX];
int done[MX];
vi g[MX];
int up[MX][20];
int used[MX];

bool cmp(int a, int b) {
    return dp[a] > dp[b]; 
}

void dfs(int v, int p = 0) {
    up[v][0] = p;
    fi(1, PW)
        up[v][i] = up[up[v][i - 1]][i - 1];
    fx(to, g[v]) {
        dp[to] = dp[v] + 1;
        dfs(to, v);
    }
}

void dfs2(int v) {
    used[v] = 1;
    fx(to, g[v]) {
        if (!used[to])
            dfs2(to);
    }
}

int lift(int v, int x) {
    fi1(PW, 0) {
        if ((1 << i) & x) {
            v = up[v][i];
        }
    }
    return v;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
       
    int n, k;
    cin >> n >> k;
    vi kek;
    fi(0, n) {
        cin >> a[i];
        --a[i];
        if (i)
            g[a[i]].pb(i);
        kek.pb(i);
    }     
    dfs(0); 
    int ans = a[0] != 0;
    sort(all(kek), cmp);
    fx(v, kek) {
        if (used[v] || dp[v] <= k) continue;
        dbg(v);
        v = lift(v, k - 1);
        dbg(v);
        ++ans;
        dfs2(v);
    }
    cout << ans << '\n';
}

Measured memory_bytes: 34536
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long a;
	long long const INF=9999999999999;
	cin>>a;
	vector<long long> v;
	v.push_back(INF);
	v.push_back(-INF);
	long long ma=0;
	for(int i=1;i<=a;i++){
		long long z;
		cin>>z;
		v.push_back(z);
		ma=max(ma,z);
	}
	sort(v.begin(), v.end());
	cout<<ma<<" ";
	long long c=ma/2;
	long long d=0;
	if(ma%2==1){
		d++;
	}
	long long z=lower_bound(v.begin(),v.end(),c+d)-v.begin();
	if(abs(v[z]-(c+d))<abs(v[z-1]-c))
		cout<<v[z]<<endl;
else{
	cout<<v[z-1];
}
}

Measured memory_bytes: 1400
a=int(input())


if a<500:
  a//=5
  a*=5
  print(a)
    
    
  
else:
  c=a//500
  d=c*500
  e=d*2
  a-=d
  a//=5
  a*=5
  print(a+e)
  
  
  

Measured memory_bytes: 2940
def bubble_sort(A, N):
    flag = True
    i, c = 0, 0
    while flag:
        flag = False
        for j in range(1, N-i):
              if A[j] < A[j-1]:
                  A[j],  A[j-1] = A[j-1], A[j]
                  flag = True
                  c += 1
        i += 1

    return c


while True:

    N = int(raw_input())

    if N == 0:
        break

    A = [int(raw_input()) for _ in xrange(N)]

    print bubble_sort(A, N)

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

int main ()
{
    int N;
    std::cin >> N;
    
    int sum = 0;
    int temp = N;
    while (temp)
    {
        sum += temp % 10;
        temp /= 10;
    }
    
    if (N % sum == 0)
    {
        std::cout << "Yes" << std::endl;
    }
    else
    {
        std::cout << "No" << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
using namespace std;
string s;
signed main()
{
	getline(cin,s);
	puts(((((!(s[0]-s[1]))&&(!(s[1]-s[2])))||((!(s[1]-s[2]))&&(!(s[2]-s[3]))))?("Yes"):("No")));
	return 0;
}

Measured memory_bytes: 256
#ifdef _MSC_VER
#include <__msvc_all_public_headers.hpp>
#undef min
#undef max
#else
#define NDEBUG
#include <bits/stdc++.h>
#endif

using namespace std;
using large = long long;

struct Conn {
    unordered_set<int> island;
};

struct union_find {
    vector<int> d;
    union_find(int size) : d(size, -1) {}

    bool unite(int a, int b) {
        int ra = root(a);
        int rb = root(b);
        if (ra == rb) return false;

        int na = -d[ra];
        int nb = -d[rb];
        if (na > nb) {
            d[rb] = ra;
            d[ra] = -(na + nb);
        } else {
            d[ra] = rb;
            d[rb] = -(na + nb);
        }
        return true;
    }

    int root(int a) {
        if (d[a] < 0) return a;
        int ra = root(d[a]);
        d[a] = ra;
        return ra;
    }

    int size(int a) {
        return -d[root(a)];
    }
};

int main()
{
    int n, m;
    cin >> n >> m;
    
    auto uf = union_find(n);

    auto connected = vector<large>(m);

    auto edge = vector<pair<int, int>>(m);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        edge[i] = {a, b};
    }

    auto total = 0LL;
    for (int i = m - 1; i >= 0; --i) {
        const auto [a, b] = edge[i];

        if (uf.root(a) != uf.root(b)) {
            large na = uf.size(a);
            large nb = uf.size(b);
            large xa = na * (na - 1) / 2;
            large xb = nb * (nb - 1) / 2;

            uf.unite(a, b);

            large nc = uf.size(a);
            large xc = nc * (nc - 1) / 2;

            total = total - xa - xb + xc;
        }

        connected[i] = total;
    }

    const auto all = large(n) * large(n-1) / 2;
    for (int i = 1; i < m; ++i) {
        cout << (all - connected[i]) << "\n";
    }
    cout << all << "\n";


    return 0;
}


Measured memory_bytes: 5080
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18

N = input()
h = map(int, raw_input().split()) + [INF, INF]

DP = [0] + [INF] * (N + 1)

for i in range(N):
    DP[i + 2] = min(DP[i + 2], DP[i] + abs(h[i] - h[i + 2]))
    DP[i + 1] = min(DP[i + 1], DP[i] + abs(h[i] - h[i + 1]))

print DP[N - 1]

Measured memory_bytes: 12448
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<string> S(N);
	for (int i = 0; i < N; ++i) {
		cin >> S[i];
	}
	int ans = 0, xa = 0, by = 0, ba = 0;
	for (int i = 0; i < N; ++i) {
		for (int j = 1; j < S[i].size(); ++j) {
			if (S[i].substr(j - 1, 2) == "AB") {
				++ans;
			}
		}
		if (S[i].front() == 'B' && S[i].back() == 'A') ++ba;
		else if (S[i].front() == 'B') ++by;
		else if (S[i].back() == 'A') ++xa;
	}
	if (by > 0 && ba > 0) ++ans, --by;
	if (xa > 0 && ba > 0) ++ans, --xa;
	ans += max(ba - 1, 0);
	ans += min(by, xa);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 768
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<iostream>
using namespace std;
const int MaxN = 1e5 + 5;
char a[MaxN];
int main()
{
	int m;
	long long k;
	cin >> a;
	scanf("%lld", &k);
	long long len = strlen(a);
	long long j = len - 1;
	for(int i = 0; i < len - 1; i++) {
		if(a[i] == 'a') m = 0;  //  不特判a的话 m = ’z' - ‘a' + 1 = 26 使得 k减少26 
		else m = 'z' - a[i] + 1;
		k = k - m;
		if(k >= 0) a[i] = 'a';
		else k = k + m;
	}  
	k = k % 26;  // 防止k太大
	if( k + a[j] > 'z') a[j] = a[j] - 26 + k;  // 超出asc码
	else a[j] = k + a[j];
	cout << a << endl;
}

Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

res = 0

for i in range(n):
    b_index = a[i]
    b_index -= 1
    b_value = b[b_index]
    res += b_value

    if i < n-1:
        b_index_next = a[i+1]
        b_index_next -= 1
        b_value_next = b[b_index_next]
        if b_index_next - b_index == 1:
            c_value = c[b_index]
            res += c_value

print(res)


Measured memory_bytes: 3064
#include<iostream>
#include<sstream>

using namespace std;


int main() {

	int n, m;

	cin >> n >> m;

	long int x, y;
	x = 0;
	y = 0;

	if (n > 1) {
		x = (n * (n - 1)) / 2;//����
	}
	else {
		x = 0;
	}

	if (m > 1) {
		y = (m * (m - 1)) / 2;//�+�
	}
	else {
		y = 0;
	}

	cout << x + y << endl;

	return 0;

}

Measured memory_bytes: 256
X = int(input())
F = [0, 1]
i = 2
while F[-1] - F[-2] <= X:
    F += [i**5]
    i += 1
A, B = -1, -1
flag = False
for i in range(0, len(F)):
    for j in range(0, len(F)):
        if F[i] - F[j] == X:
            flag = True
            A = i
            B = j
            break
        elif F[i] + F[j] == X:
            flag = True
            A = i
            B = -j
            break
    if flag:
        break

print(A, B)


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

int x;

inline int qr()
{
	int w=1,x=0;char a=0;
	while(a<'0'||a>'9'){if(a=='-')w=-1;a=getchar();}
	while(a<='9'&&a>='0'){x=(x<<1)+(x<<3)+(a^48);a=getchar();}
	return x*w;
}

int main()
{
	x=qr();
	int k=360;
	while(k%x!=0)
		k+=360;
	cout<<k/x<<endl;
	return 0;
} 

Measured memory_bytes: 3636
#include <stdio.h>

int main(void){

  int S;
  scanf("%d", &S);

  if (S < 60)
    {
      printf("0:0:%d\n",S);
    }
  
  else if (S < 3600)
    {
      printf("0:%d:%d\n", (int)S/60, S%60);
    }
  
  else
    {
      printf("%d:%d:%d\n", (int)S/3600, (int)(S%3600)/60, (S%60)%60);
    }
  return 0;
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;

int N, M;
int A[101010];
int flag2;
int B[101010];
int ans;

bool check(int scr) {
    int tmp = 0;
    FOR(i, 0, N) {
        auto it = lower_bound(A, A + N, scr - A[i]);
        int t = A + N - it;
        //cout << scr << " " << t << endl;
        if (t > 0) {
            tmp += t;
        }
    }
    bool flag = false;
    // cout << "tmp " << tmp << endl;

    if (tmp <= M) {
        flag = true;
        flag2 = M - tmp;
    }
    return flag;
}

int solve2(int scr) {
    int tmp = 0;
    int MAX = 0;
    FOR(i, 0, N) {
        auto it = lower_bound(A, A + N, scr - A[i]);
        int t = A + N - it;
        if (t > 0) {
            tmp += A[i] * t + B[N] - B[N - t];
        }
        //cerr << t << " " << tmp << " " << A[i] << endl;
        it--;
        if (it - A >= 0) {
            chmax(MAX, A[i] + *it);
        }
    }
    if (flag2) {
        tmp += MAX * flag2;
    }
    return tmp;
}

void solve() {
    sort(A, A + N);
    FOR(i, 0, N) {
        B[i + 1] = A[i] + B[i];
    }
    int ng = 0;
    int ok = 200010ll;
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;
        if (check(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    //cout << ok << endl;
    check(ok);
    int ans = solve2(ok);
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N >> M;
    FOR(N) {
        /*
        int t;
        cin >> t;
        A.pb(t);
        */
        cin >> A[i];
    }
    solve();
    return 0;
}


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

using namespace std;

int main(void){
    int a, b;
    cin >> a >> b;
    if (a == 1 && b != 1) cout << "Alice" << endl;
    else if (a != 1 && b == 1) cout << "Bob" << endl;
    else if (a - b > 0) cout << "Alice" << endl;
    else if (a - b < 0) cout << "Bob" << endl;
    else if (a - b == 0) cout << "Draw" << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int a = sc.nextInt();
		if (x < a) {
			System.out.println("0");
		} else {
			System.out.println("10");
		}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     
	}
}

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

using namespace std;

const int inf = 1000000001;

struct SegmentTree {
	vector<int> val;
	vector<int> mn;
	public:
	SegmentTree(int N) : val(N * 4 + 5), mn(N * 4 + 5) {}

	void build(int l, int r, int x) {
		if(l == r) {
			mn[x] = l;
			return;
		}
		int mid = l + r >> 1;
		build(l, mid, x << 1);
		build(mid + 1, r, x << 1 | 1);
		mn[x] = r;
	}

	void update(int l, int r, int x, int p, int v) {
		if(l == r) {
			val[l] = v;
			return;
		}
		int mid = l + r >> 1;
		if(p <= mid) {
			update(l, mid, x << 1, p, v);
		} else {
			update(mid + 1, r, x << 1 | 1, p, v);
		}
		if(val[mn[x << 1]] <= val[mn[x << 1 | 1]]) {
			mn[x] = mn[x << 1];
		} else {
			mn[x] = mn[x << 1 | 1];
		}
	}

	int query(int l, int r, int x, int a, int b) {
		if(l > b || r < a) {
			return -1;
		}
		if(l >= a && r <= b) {
			return mn[x];
		}
		int mid = l + r >> 1;
		int L = query(l, mid, x << 1 , a, b);
		int R = query(mid + 1, r, x << 1 | 1, a, b);
		if(L == -1) {
			return R;
		} 
		if(R == -1) {
			return L;
		}
		if(val[L] < val[R]) {
			return L;
		} else {
			return R;
		}
	}

	int V(int p) {
		return val[p];
	}
};

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

	int T;
	cin >> T;

	while(T--) {
		int n;
		cin >> n;

		vector<int> k(n);
		vector<int> l(n);
		vector<int> r(n);
		vector<tuple<int, int, int> > a;
		vector<tuple<int, int, int> > b;
		long long ans = 0;
		for(int i = 0; i < n; ++i) {
			int k, l, r;
			cin >> k >> l >> r;
			if(k == n) {
				ans += l;
			} else if(l >= r) {
				a.emplace_back(k, l, r);
			} else {
				b.emplace_back(n - k, r, l);
			}
		}

		sort(a.begin(), a.end());
		sort(b.begin(), b.end());

		auto solve = [&] (const vector<tuple<int, int, int> > a) {
			int n = a.size();
			if(n == 0) {
				return 0LL;
			}
			SegmentTree seg(n + 1);
			seg.build(1, n, 1);
			long long ans = 0;
			for(int i = 0; i < n; ++i) {
				auto [k, l, r] = a[i];
				if(k > i) {
					ans += l;
					seg.update(1, n, 1, i + 1, l - r);
				} else {
					int pos = seg.query(1, n, 1, 1, k);
					if(l - r > seg.V(pos)) {
						ans -= seg.V(pos);
						ans += l;
						seg.update(1, n, 1, pos, l - r);
					} else {
						ans += r;
					}
				}
			}

			return ans;
		};

		cout << ans + solve(a) + solve(b) << '\n';
	}

	return 0;
}

Measured memory_bytes: 13308
alp='abcdefghijklmnopqrstuvwxyz'

def f(N, s, x):
  if len(s)==N:
    print(s)
    return
  for i in range(x+2):
    f(N, s+alp[i], max(x, i))
    
f(int(input()), 'a', 0)

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

int main(){
	int n, ans=1000010; cin>>n;
	vector<int>a(n);
	for (int i=0;i<n;++i)cin>>a[i];
	for (int i=1; i<n;++i)a[i]+=a[i-1];
	for(int i=0;i<n-1; ++i)ans=min(abs(a[n-1]-2*a[i]), ans);
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	char c;
	cin>>c;
	if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o'){
		cout<<"vowel"<<endl;
	}
	else{
		cout<<"consonant"<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  Int q;
  cin>>q;
  vector<Int> v;
  for(Int i=0;i<q;i++){
    Int t,x;
    cin>>t;
    if(t<2) cin>>x;
    if(t==0) v.emplace_back(x);
    if(t==1) cout<<v[x]<<endl;
    if(t==2) v.pop_back();
  }
  return 0;
}



Measured memory_bytes: 4904
#include <bits/stdc++.h>
using namespace std;
int main(){
    int x,a,b;
    cin >> x >> a >> b;
    if (abs(x - a) < abs(x - b)) cout << "A" << endl;
    else if (abs(x - b) < abs(x - a)) cout << "B" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <iomanip>
using namespace std;
using P = pair<int,int>;
typedef long long ll;


#define rep(i,n) for (int i=0; i<(n); i++)
const int INF =1001001001;
const ll BIG = 1000000007;
const double PI = 3.141592653589793;

ll modpow(ll a, ll b, ll mod = 1000000007) {
    ll res = 1;
    for(a %= mod; b; a = a * a % mod, b>>=1) if(b&1) res = res*a%mod;
    return res;
}

ll combination_nCa(ll n, ll r, ll mod=1000000007){
    ll x = 1, y = 1;
    rep(i,r){
        x = (x*(n-i))%mod;
        y = (y*(i+1))%mod;
    }
    return (x*modpow(y, mod-2))%mod;
}

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = (modpow(2, n) - 1 - combination_nCa(n, a) - combination_nCa(n, b))%BIG;
    if(ans<0) ans += BIG;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int x = sc.nextInt();
		int[] a = new int[N];
		for(int i = 0 ; i < N ; i++) {
			a[i] = sc.nextInt();
		}
		long cnt = 0;
		for(int i = 0 ; i < N - 1 ; i++) {
			if(a[i] > x) {
				cnt += a[i + 1] + a[i] - x;
				a[i] = x;
				a[i + 1] = 0;
			} else {
				if(a[i] + a[i + 1] > x) {
					cnt += a[i] + a[i + 1] - x;
					a[i + 1] = x - a[i];
				}
			}
		}
		System.out.println(cnt);
	}
}


Measured memory_bytes: 51136
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int a = sc.NextInt();
        int b = sc.NextInt();
        int c = sc.NextInt();
        int d = sc.NextInt();

        string answer = "";
        if (a + b == c + d)
        {
            answer = "Balanced";
        }
        else if (a + b > c + d)
        {
            answer = "Left";
        }
        else
        {
            answer = "Right";
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

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

int main(){
	int a,b,tmp=0;
	int x,y,z;
	
	while(cin >> a >> b,a||b){
		
		x=0; y=0; z=0;
		
		tmp=b-a;
		
		while(tmp>=1000){
			tmp-=1000;
			z++;
		}
		while(tmp>=500){
			tmp-=500;
			y++;
		}
		while(tmp>0){
			tmp-=100;
			x++;
		}
		cout << x << " " << y << " " << z << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int s[] = new int[n];
		int sSum = 0;

		for (int i = 0; i < n; i++) {
			s[i] = scanner.nextInt();
			sSum += s[i];
		}

		if (sSum % 10 != 0) {
			System.out.println(sSum);
			return;
		} else {
			Arrays.sort(s);
			for (int i = 0; i < s.length; i++) {
				if (s[i] % 10 == 0) {
					continue;
				} else {
					sSum -= s[i];
					System.out.println(sSum);
					return;
				}
			}
		}

		System.out.println(0);

	}
}


Measured memory_bytes: 22740
using System;
using System.Text;
using System.Diagnostics;
using System.Numerics;
using System.Collections.Generic;

class Myon

{
    public Myon() { }
    public static int Main()
    {
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }
    static Scanner cin;


    void calc()
    {
        long a = cin.nextLong();
        long b = cin.nextLong();
        Console.WriteLine(f(b) ^ f(a - 1));
    }

    long f(long a)
    {
        if (a < 0) return 0;
        long ans = 0;
        if (a % 4 == 1 || a % 4 == 2) ans += 1;
        for (int i = 1; i < 50; i++)
        {
            long num = a % (1L << (1 + i)) + 1;
            num = Math.Max(0, num - (1L << i));
            ans += (1L << i) * (num % 2);
        }
        return ans;
    }
}


class Scanner
{
    string[] s;
    int i;

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

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

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

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

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

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

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


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




Measured memory_bytes: 13140
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N, M = inm()
st = []
for i in range(N):
    a, b = inm()
    st.append((a, b))
cp = []
for i in range(M):
    c, d = inm()
    cp.append((c, d))


def solve():
    for i in range(N):
        a, b = st[i]
        mindis = 10 ** 12
        mcp = None
        for j in range(M):
            c, d = cp[j]
            dis = abs(a - c) + abs(b - d)
            if mindis > dis:
                mindis = dis
                mcp = j + 1
        print(mcp)


solve()


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

#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define deb(x)	cout << #x << " " << x << endl;

typedef long long int ll;

int main() {

	IOS

	int n;
	cin >> n;
	cout << ((n%1000 == 0) ? 0 : (1000-(n%1000))) << endl;

	return 0;
}

Measured memory_bytes: 3660