akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main()
{

    int arr[10],i,a=0,b=0;

    for(i=1;i<=3;i++){
        scanf("%d",&arr[i]);

        if(arr[i]==5){
            a++;
        }
        else if(arr[i]==7){
            b++;
        }
    }
    if(a==2&&b==1){
        printf("YES");
    }
    else{
        printf("NO");
    }
    return 0;
}


Measured memory_bytes: 1700
import java.util.Scanner;

/**
 * @author Rimi
 *
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String x = sc.next();

		int a  = Integer.valueOf(x.substring(0 , 1));
		int b  = Integer.valueOf(x.substring(1 , 2));
		int c  = Integer.valueOf(x.substring(2 , 3));


		if(x.length() == 3) {
			for(int i = 1; i <= 9; i++) {
				if(a == 9) {
					System.out.print(9);
					System.out.print(9);
					System.out.print(9);
					break;
				}else if(a == i) {
					if(a == b && a == c) {
						System.out.print(i);
						System.out.print(i);
						System.out.print(i);
						break;
					}else {
						if(a == b) {
							if(a >= c) {
								System.out.print(i);
								System.out.print(i);
								System.out.print(i);
								break;
							}else {
								System.out.print(i+1);
								System.out.print(i+1);
								System.out.print(i+1);
								break;
							}
						}else if(a > b) {
							System.out.print(i);
							System.out.print(i);
							System.out.print(i);
							break;
						}else {
							System.out.print(i + 1);
							System.out.print(i + 1);
							System.out.print(i + 1);
							break;
						}
					}
				}
			}
		}

	}

}


Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <sstream>
#include <stdio.h>
using namespace std;

// Debt Hell(0007)
int main()
{
	int n, ans = 100000;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		int r = ans * 5;
		if (r % 100000 != 0)
			r = (r / 100000 + 1) * 100000;
		r /= 100;
		ans += r;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        if(b % a == 0) {
            System.out.println(a+b);
        } else {
            System.out.println(b-a);
        }

    }

}


Measured memory_bytes: 21844
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
const long long MOD = (long long)1e9 + 7;

int m, tmp, s;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    for (int i = 0; i < 3; i++) {
        cin >> tmp;
        s += tmp;
        m = max(m, tmp);
    }
    s -= m;
    cout << s << "\n";
    //system("pause");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
long long int lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
using ll =long long int;
#define ci(a) cin>>a
#define co(a) cout<<a<<endl
#define gcd(a,b) __gcd(a,b)
#define vec vector<ll>
#define For(i,a,b) for(ll i=a;i<b;i++)
#define rFor(i,a,b) for(ll i=a;i>b;i--)
#define wFor(i,a,b) for(ll i=a;i<b;i+=2)
#define wrFor(i,a,b) for(ll i=a;i>b;i-=2)
#define sort(a,b) sort(a.begin(),b.end())
#define reverse(a,b) reverse(a.begin(),b.end())
//gcd 最大公約数
//lcm 最小公倍数
//double 少数（変数）
//string 文字列（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
//(string-'0') 文字列を数字に変換
//(char-'0') 数字に変換
//vector<vector<int>> data(a,vector<int>(b)) a×b行列
//for(int i=0;i<a;i++)
//for(int j=0;j<b;j++)
//cin>>data.at(i).at(j)  a×b行列の入力
//floor(log10(a)+1) aの10進法での桁数
//ceil(log10(a)) aの10進法での桁数

int main() {
  ll a;
  ci(a);
  string an="No";
  For(i,1,10)
    For(j,1,10)
      if(i*j==a)
        an="Yes";
  co(an);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>

using namespace std;
int main(){
    string s;
    cin >> s;
    long long n;
    cin >> n;
    bool hantei=1;
    char reg;
    int regi;
    for(int i=0;i<s.size();i++){
        if(s[i]!='1'){
            hantei=0;
            reg=s[i];
            regi=i+1;
            hantei=0;
            break;
    
        }
    }
    if(hantei){
        cout<<1<<endl;
  
    }else{
    if(n>=regi){
        cout<<reg<<endl;
    }else{
        cout<<1<<endl;
    }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, j, k) for(int i=j; i<=k; i++)
#define FFOR(i, j, k) for(int i=j; i<k; i++)
#define DFOR(i, j, k) for(int i=j; i>=k; i--)
#define bug(x) cerr<<#x<<" = "<<x<<'\n'
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
#define taskname "B"
int n, k;
int main(){
    #ifdef Megumin
        if(fopen(taskname".inp", "r"))
            freopen(taskname".inp", "r", stdin);
    #endif // Megumin
    read(n);
    read(k);
    int r=1;
    FOR(i, 1, n){
        if(r<=k) r*=2;
        else r+=k;
    }
    writeln(r);
}

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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}

int a[41], b[41], c[41];
int n, ma, mb;

int memo[41][410][410];

int helper(int pos, int ca, int cb){

    if(ca > 0 && ca * mb == cb * ma)
        return 0;

    if(pos == n)
        return -1;

    if(memo[pos][ca][cb] != 0)
        return memo[pos][ca][cb];

    int opt1 = helper(pos + 1, ca, cb);
    int opt2 = helper(pos + 1, ca + a[pos], cb + b[pos]);

    if(opt1 == -1 && opt2 == -1){
        memo[pos][ca][cb] = -1;
        return -1;
    }

    if(opt1 == -1){
        memo[pos][ca][cb] = opt2 + c[pos];
        return memo[pos][ca][cb];
    }

    if(opt2 == -1){
        memo[pos][ca][cb] = opt1;
        return opt1;
    }

    memo[pos][ca][cb] = min(opt1, opt2 + c[pos]);
    return memo[pos][ca][cb];

}

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    cin >> n >> ma >> mb;

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

    cout << helper(0, 0, 0);

    return 0;
}


Measured memory_bytes: 24960
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    // 数値の配列を作る
    const numList0 = input[0].split(' ').map(x => parseInt(x, 10));
    const N = numList0[0];
    const VList = input[1].split(' ').map(x => parseInt(x, 10));
    const CList = input[2].split(' ').map(x => parseInt(x, 10));

    var result = 0;
//    const XYDiffList = [];
    for (var i = 0; i < N; i++) {
        // 正の時だけ要素追加
        var diff = VList[i] - CList[i];
        if (diff > 0) {
//            XYDiffList.push(diff);
            result += diff;
        }
    }

    console.log(result);
}
 
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include<bits/stdc++.h>
#define EPS (1e-10)
#define equals(a,b) (fabs((a)-(b)) < EPS)
 
using namespace std;

struct Point{
  double x,y;
  Point(){}
  Point(double x,double y) :x(x),y(y){}
  Point operator + (Point p) {return Point(x+p.x,y+p.y);}
  Point operator - (Point p) {return Point(x-p.x,y-p.y);}
  Point operator * (double k) {return Point(x*k,y*k);}
  Point operator / (double k) {return Point(x/k,y/k);}
  double norm(){return x*x+y*y;}
  double abs(){return sqrt(norm());}

  bool operator < (const Point &p) const{
    return x!=p.x ? x < p.x : y < p.y;
  }

  bool operator == (const Point &p) const{
    return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
  }
};
typedef Point Vector;
typedef vector<Point> Polygon;
int main(){
  int n;cin>>n;
  Polygon g,v;
  int i;
  g.resize(n);
  for(i=0;i<n;i++) cin >> g[i].x >> g[i].y;
  bool f=true;
  if(n%2) f=false;
  else{
    for(i=0;i<n/2;i++) v.push_back((g[i]+g[i+n/2])/2);
    v.erase(unique(v.begin(),v.end()),v.end());
    if(v.size()!=1) f=false;
  }
  if(f) printf("%.8f %.8f\n",v[0].x,v[0].y);
  else cout << "NA" << endl;
  return 0;
}

Measured memory_bytes: 1256
fn main() {
    let mut buffer = String::new();
    std::io::stdin().read_line(&mut buffer).unwrap();
    buffer.clear();
    std::io::stdin().read_line(&mut buffer).unwrap();
    let inputs = buffer.split_whitespace().map(|x| x.parse::<i64>().unwrap());
    let v: Vec<i64> = std::iter::FromIterator::from_iter(inputs);
    let mut ans = std::i64::MAX;
    for i in 0..101 {
        let cost = v.iter().map(|x| (x - i) * (x - i)).sum::<i64>();
        ans = std::cmp::min(ans, cost);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
int main(){
  int n; cin >> n;
  string s; cin >> s;
  vector<int> wh(n), bl(n);
  int sumw = 0 , sumb = 0;
  for(int i = 0; i < n; i++){
    sumw += s[i] == '.';
    sumb += s[i] == '#';
    wh[i] = sumw;
    bl[i] = sumb;
  }
  int ans = min(sumb, sumw);
  for(int i = 0; i < n; i++){
    ans = min(ans, bl[i] + wh[n - 1] - wh[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2180
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

template <typename T>
vector<vector<T>> alloc_double_vec(size_t rows, size_t cols, T init) {
    vector<vector<T>> ret;
    vector<T> ret_elem;
    ret_elem.resize(cols, init);
    ret.resize(rows, ret_elem);
    return ret;
}

int main(int argc, char* argv[]) {
    int N, K;
    cin >> N >> K;
    vector<pair<int, int>> points;
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        points.push_back({x, y});
    }
    sort(points.begin(), points.end());
    ll min_area = numeric_limits<ll>::max();
    for (int x_begin = 0; x_begin < points.size(); x_begin++) {
        for (int x_end = x_begin + 1; x_end <= points.size(); x_end++) {
            if (x_end - x_begin < K) {
                continue;
            }
            vector<pair<int, int>> pts_range(points.begin() + (size_t)x_begin, points.begin() + (size_t)x_end);
            sort(pts_range.begin(), pts_range.end(), [](const pair<int, int>& lhs, const pair<int, int>& rhs) {
                return lhs.second < rhs.second;
            });
            for (int i = 0; i < pts_range.size() - K + 1; i++) {
                ll min_y = numeric_limits<ll>::max();
                ll max_y = numeric_limits<ll>::min();
                ll min_x = numeric_limits<ll>::max();
                ll max_x = numeric_limits<ll>::min();
                for (int j = 0; j < K; j++) {
                    min_y = min(min_y, (ll)pts_range[i+j].second);
                    max_y = max(max_y, (ll)pts_range[i+j].second);
                    min_x = min(min_x, (ll)pts_range[i+j].first);
                    max_x = max(max_x, (ll)pts_range[i+j].first);
                }
                min_area = min(min_area, (max_y - min_y) * (max_x - min_x));
                assert(min_area > 0);
            }
        }
    }
    cout << min_area << endl;
    return 0;
}



Measured memory_bytes: 888
import heapq
a,b = map(int,input().split())
L = list(map(int,input().split()))
L = [-x for x in L]

heapq.heapify(L)
for i in range(b):
    a =heapq.heappop(L)
    a= -(-a//2)
    heapq.heappush(L,a)

L = [-x for x in L]
print(sum(L))

Measured memory_bytes: 14180
fun main(arr:Array<String>) {
    val (n,k) = readLine()!!.split(" ").map { it.toInt() }
    val numbers = readLine()!!.split(" ").map { it.toInt() }
    val numberCount = mutableMapOf<Int, Int>()
    for(i in numbers) {
        numberCount[i] = (numberCount[i]?:0) + 1
    }
    if(numberCount.size <= k) {
        println(0)
        return
    }
    val tmp = numberCount.toList().sortedBy { it.second }.take(numberCount.size - k).map { it.second }.sum()
    println(tmp)

}



Measured memory_bytes: 83556
import bisect
N,Q = map(int,input().split())
S = input()
lista = []
for j in range(N-1):
    if S[j:j+2] == 'AC':
        lista.append(j)
for i in range(Q):
    l,r = map(int,input().split())
    l,r = l-1,r-1
    lind = bisect.bisect_left(lista,l)
    rind = bisect.bisect_right(lista,r-1)
    print(rind-lind)

Measured memory_bytes: 5748
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }

const int maxn = 5e3 + 5;
string s;
int n;
int dp[maxn][maxn];

int f(){   
  int ret = 0;
  for(int i = 1; i <= n; i++){
    for(int j = i + 1; j <= n; j++){
      if(s[i - 1] == s[j - 1] && dp[i - 1][j - 1] < j - i){
        dp[i][j] = dp[i - 1][j - 1] + 1;
      }
      else dp[i][j] = 0;
      ret = max(ret, dp[i][j]);
    }
  }
  return ret; 
}

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

  cin >> n >> s;
  cout << f();
}

Measured memory_bytes: 96768
#include<bits/stdc++.h>
#define MAXN 10005
using namespace std;
int dp[MAXN],a[MAXN],b[MAXN];
int main()
{
    int h,n;
    cin>>h>>n;
    dp[1]=INT_MAX;dp[0]=0;
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i];
        dp[1]=min(dp[1],b[i]);
    }
    for(int i=2;i<=h;i++)
    {
        dp[i]=INT_MAX;
        for(int j=0;j<n;j++)
        {
            dp[i]=min(dp[i],dp[max(i-a[j],0)]+b[j]);
        }
    }
    cout<<dp[h];
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

string t[4]={"dream","dreamer","erase","eraser"};

int main(){
 string s;
  cin >> s;
  
  reverse(s.begin(),s.end());
  
   for(int j=0;j<4;j++) reverse(t[j].begin(),t[j].end());
  
    int res=true;
  
  for(int i=0;i<s.length();){
    bool det=false;
    
    for(int j=0;j<4;j++){
     if(s.substr(i,t[j].length())==t[j]) {
       det=true; 
       i+=t[j].length();
       break;
     }
   }
    if(!det) {
      res=false; 
      break;
    }
  }

   if(res) cout << "YES" << endl;
   else cout<< "NO" << endl;

}

Measured memory_bytes: 512
# from pprint import pprint
# import math
# import collections

S = input()
# n, k = map(int, input().split(' '))
# a = list(map(int, input().split(' ')))
# a = []
# for i in range(n):
#     a.append(int(input()))

if S[-1] == 's':
    print(S + 'es')
else:
    print(S + 's')


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

#define pb push_back
#define vi vector < int >
#define ii pair < int, int >
#define vii vector < pair < int, int > >
#define vvi vector < vector < int > >
#define ll long long
#define X first
#define Y second
#define mp make_pair
#define FOR( i, lo, hi ) for( int i = (lo);i < (hi);i++ )
#define DFOR( i, hi, lo ) for( int i = (hi);i >= (lo);i-- )
#define pqueue priority_queue

using namespace std;

const long long int MOD = 1e9 + 7;

ll ADD( ll a, ll b )
{
	return ( ( a % MOD ) + ( b % MOD ) ) % MOD;
}

ll SUB( ll a, ll b )
{
	return ( ( a % MOD ) - ( b % MOD ) + MOD ) % MOD;
}

ll MUL( ll a, ll b )
{
	return ( ( a % MOD ) * ( b % MOD ) ) % MOD;
}

ll POT( ll n, ll k )
{
	if ( k == 0 )
		return 1;

	ll ret = POT( n, k / 2 );
	ret = MUL( ret, ret );

	if ( k % 2 )
		return MUL( ret, n );
	return ret;
}

ll DIV( ll a, ll b )
{
	return MUL( a , POT( b, MOD - 2 ) );
}

bool isPrime( ll x )
{
	for ( ll i = 2;i <= sqrt( x ) + 1; ++i )
		if ( x % i )
			return false;
	return true;
}

int n;

int main()
{
	cin >> n;
	double pl = 0;
	FOR( i, 1, n + 1 )
	{
		if ( i % 2 == 1 )
			pl++;
	}
	
	printf( "%.10lf", ( double )( pl / n ) );
	return 0;
}


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

int main() {
    int N, Y;
    cin >> N >> Y;
    int res10000 = -1, res5000 = -1, res1000 = -1;
    for (int a = 0; a <= N; ++a) {
        for (int b = 0; b + a <= N; ++b) {
            int c = N - a - b;
            int total = 10000*a + 5000*b + 1000*c;
            if (total == Y) {
                res10000 = a;
                res5000 = b;
                res1000 = c;      
            } 
        }
    }
    cout << res10000 << " " << res5000 << " " << res1000 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e2 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	map<int, int> mc;
	int s;
	cin >> s;
	mc[s] = 1;
	for (int i = 2; ; i++)
	{
		if (s & 1) s = 3 * s + 1;
		else s /= 2;
		if (mc.count(s)) cout << i << endl, exit(0);
		mc[s] = 1;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(void){
	int n,a,b,c,i,k,h,cnt,x,dd,y,aa,bb,cc,z;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d",&a,&b,&c);
		x=0;
		for(k=0;k<=a/3;k++){
//printf("k=%d\n",k);
			aa=a-3*k; bb=b; cc=c;z=min(aa/2,bb);
			for(h=0;h<=z;h++){
				aa=a-3*k-2*h; bb=b-1*h; cnt=h+k;
//printf("h=%d aa=%d bb=%d cc=%d\n",h,aa,bb,cc);
				if(aa!=0&&bb!=0&&cc!=0){
					y=min(aa,bb);y=min(y,cc);
					cnt+=y;
//printf("y=%d\n",y);			
				}
//printf("cnt2=%d\n",cnt);
				x=max(x,cnt);
			}
		}
		printf("%d\n",x);//printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2692
#include <algorithm>
#include <iostream>
#include <list>
#include <map> //連想配列
#include <queue>
#include <set> //
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector> //動的配列

using namespace std;

int main() {
  string s, t;
  cin >> s;
  int length = s.size();
  s.erase(s.begin() + 1, s.begin() + s.size() - 1);
  // s.insert(s.begin() + 1, to_string(s.size() - 2));

  s = s[0] + to_string(length - 2) + s[1];
  cout << s << endl;
  return 0;
}


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

int main(){
int s = 0;
    char a;
    for (int i=0;i<3;i++){
            cin >> a;

        if (a == 'o') {
            s++;
         }
    }
cout << int( 700 + 100*s) << endl;
return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int opt = 0;
        ArrayList<Integer> D = new ArrayList<>();
        for(int i=0;i<N;i++) D.add(sc.nextInt());
        for(int i=0;i<N-1;i++) for(int j=i+1;j<N;j++) opt+=D.get(i)*D.get(j);
        System.out.println(opt);
    }
}

Measured memory_bytes: 21972
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <cmath>   
#include<cctype>
#include<string>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include <deque>
#include <utility> 

#define rep(i,m,n) for(int i = m;i < n;++i)
using namespace std;
using ll = long long;
using R = double;
const ll inf = 1LL << 50;
const int MOD = 1e9 + 7;



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

	vector<int> even(101010);
	vector<int> odd(101010);

	rep(i, 0, n) {
		int x;
		cin >> x;
		if (i % 2 == 0) {
			even[x]++;
		}
		else {
			odd[x]++;
		}
	}


	vector<pair<int, int>> e, o;
	rep(i, 0, 101010) {
		e.push_back(make_pair(even[i], i));
		o.push_back(make_pair(odd[i], i));
	}


	sort(e.begin(), e.end());
	sort(o.begin(), o.end());
	reverse(e.begin(), e.end());
	reverse(o.begin(), o.end());



	if (e[0].second != o[0].second) {
		cout << n - e[0].first - o[0].first << endl;
	}
	else {
		cout << min(n - e[0].first - o[1].first, n - e[1].first - o[0].first) << endl;
	}






	return 0;

}


Measured memory_bytes: 2932
import sys
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())


from itertools import combinations
from collections import Counter as cc
def main():
    x, k , d = mi()
    x = abs(x)
    ans = max(x%d, x-k*d)
    k -= x//d
    if k > 0 and k%2 == 1:
        ans = abs(ans-d)
    print(ans)
    





if __name__ == '__main__':
    main()

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

int main() {
    // your code goes here
    ll a,b,x,y;
    cin >> a >> b;
    rep(i,1,1000000){
        x=floor(i*8/100);
        y=floor(i*10/100);
        if(x==a&&y==b){
            cout << i << endl;
            return 0;
        }
    }
    cout << "-1" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		int B = sc.nextInt();

		System.out.println(lcm(A,B));

	}

    static long lcm (long a, long b) {
    	long temp;
    	long c = a;
    	c *= b;
    	while((temp = a%b)!=0) {
    		a = b;
    		b = temp;
    	}
    	return (c/b);
    }
}

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

int main(){
    string s;
    cin >> s;
    int ans = 0;
    char tmp = s[0];
    for(char x : s){
        if(x != tmp){
            tmp = x;
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3748
#!/usr/bin/env python
import os
import operator
from collections import defaultdict
import sys
from io import BytesIO, IOBase
import bisect

# def power(x, p):
#     res = 1
#     while p:
#         if p & 1:
#             res = res * x % 1000000007
#         x = x * x % 1000000007
#         p >>= 1
#     return res;

def main():
    # for _ in range(int(input())):
    #     n=int(input())
    #     n,k=map(int,input().split())
    #     arr=[int(k) for k in input().split()]
    n=int(input())
    # n,k=map(int,input().split())
    # arr=[int(k) for k in input().split()]
    print(n+n**2+n**3)




















BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()

Measured memory_bytes: 9552
#include <bits/stdc++.h>
  #define endl "\n"
  #define ll long long int
  #define vi vector<int>
  #define vll vector<ll>
  #define vvi vector < vi >
  #define pii pair<int,int>
  #define pll pair<long long, long long>
  #define mod 1000000007
  #define inf 1000000000000000001;
  #define all(c) c.begin(),c.end()
  #define mp(x,y) make_pair(x,y)
  #define mem(a,val) memset(a,val,sizeof(a))
  #define pb push_back
  #define f first
  #define se second
  
  using namespace std;
  int main()
  {
    std::ios::sync_with_stdio(false);
    ll n=0,m=0,k=0,x=0,t1=0,t2=0,t3=0,f=0,sum=0,count=0;

    cin>>n;
    ll arr[n+1],dp[n+1];
    arr[0]=0; dp[0]=inf;

    for (ll i = 1; i <= n; ++i){
      cin>>arr[i];
    }
    dp[1]=0;

    for (ll i = 2; i <= n; ++i)
    {
      dp[i]=min(abs(arr[i]-arr[i-1])+dp[i-1],abs(arr[i]-arr[i-2])+dp[i-2]);
    }

    cout<<dp[n]<<endl;

    return 0;
  }

Measured memory_bytes: 5156
import java.util.*;

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

       if(C1.charAt(0) == C2.charAt(2) && C1.charAt(1) == C2.charAt(1) && C1.charAt(2) == C2.charAt(0)){
           System.out.println("YES");
       }else{
           System.out.println("NO");          
       }

      
       
       
       
   }
}
               
        
       

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
#define print(x) cerr << (#x) << "is "<< x << "\n"
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n,x; 
   cin >> n;
   set<pii> s;
   int ans = 0;
   f(i,0,n){
      cin >> x;
      s.insert({x,i});
      auto k = s.find({x,i});
      k++;
      if(k==s.end()) ans++;
   }
   cout << ans << '\n';
   return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
A = list(map(lambda x: int(x)-1, input().split()))
bit = k.bit_length()
table = [[0]*n for _ in range(bit)]
table[0] = A

for i in range(1, bit):
    for j in range(n):
        table[i][j] = table[i-1][table[i-1][j]]

ans = 0
for i in reversed(range(bit)):
    if (1 << i) <= k:
        k -= 1 << i
        ans = table[i][ans]
print(ans+1)


Measured memory_bytes: 175980
#include <bits/stdc++.h>
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int a,b,c;
  cin >> a >> b >> c;
  
  cout << min(a+b, min(b+c, c+a)) << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] d = new int[n];
    
    for(int i=0; i<n; i++){
      d[i] = sc.nextInt();
    }
    
    int total = 0;
    
    for(int i=0; i<n; i++){
      for(int j=i+1; j<n; j++){
        total += d[i] * d[j];
      }
    }
    
    System.out.println(total);
  }
}


Measured memory_bytes: 21844
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

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

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
int main(){
	int h,w,n;
	cin>>h>>w>>n;
	cout<<min((n+h-1)/h,(n+w-1)/w)<<endl;
	return 0;
}


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


using namespace std;

bool is_same_value(int n){
	
	stringstream s;
	
	s << n;
	
	string val = s.str();
	
	for(int i=1;i<val.size();i++){
		if(val[i]!=val[i-1]) return false;
	}
	
	return true;
	
}




int main(){

	int n;
	cin >> n; 
	
	for(int i=n;i<=999;i++){
		
		if(is_same_value(i)){
			cout << i << endl; 
			return 0;
		}
	}
	
    return 0;
}


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

int main() {
	long long N = 37 * 38 + 1, K = 38;
	cout << N << " " << K << endl;
	for (int i = 0; i < K; i++) {
		cout << 1;
		for (int j = 0; j < K - 1; j++) {
			cout << " " << i * (K - 1) + j + 2;
		}
		cout << endl;
	}
	for (int i = 0; i < K - 1; i++) {
		for (int j = 0; j < K - 1; j++) {
		cout << i + 2;
			for (int k = 0; k < K - 1; k++) {
				cout << " " << k * (K - 1) + K + 1 + (i * k + j) % (K - 1);
			}
			cout << endl;
		}
	}
}

Measured memory_bytes: 512
n,m=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(n)]

a.sort()
cnt=0
ans=0
for i in range(n):
    m-=a[i][1]
    if m>=0:
        ans+=a[i][0]*a[i][1]
    else:
        ans+=(m+a[i][1])*a[i][0]
        print(ans)
        exit()
print(ans)

Measured memory_bytes: 27756
#include<bits/stdc++.h>
using namespace std;
#define rep(i,N) for(ll i=0;i<N;++i)
typedef long long int ll;
const ll INF = 1<<30;

int main(){
    ll N, M; cin >> N >> M;
    vector<vector<ll> > V(N+1);
    rep(i,M){
        ll a,b; cin >> a >> b;
        a--; b--;
        V[a].push_back(b);
        V[b].push_back(a);
    }
    bool ok = false;
    for(auto x : V[0]){
        for(auto y : V[x]){
            if(y == N-1) ok = true;
        }
    }
    if(ok) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 12776
#include <bits/stdc++.h>
 
//#include <vector>
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
ll mod =  1000000007;
ll maxn = 1000000000;
 
//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pii = pair<int, int>; // これ以降 pii という型名はpair<int, int> と同じ意味で使える
//---------------------------------------------------------------------------------------------------
 
int main(){
   double s,ans;
   cin>>s;
   ans=(s/3.0)*(s/3.0)*(s/3.0);
   cout << fixed << setprecision(7);
   cout<<ans<<endl;
}

Measured memory_bytes: 256
// 1_agc037_a
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
#define MOD (1000000007)
typedef long long ll;

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

    string s;
    cin >> s;
    int n = s.length();
    if(n == 1){
        cout << n << endl;
        return 0;
    }else if(n == 2){
        if(s[0] == s[1]) cout << 1 << endl;
        else cout << 2 << endl;
        return 0;
    }

    vector<ll> dp1(n);
    vector<ll> dp2(n);
    dp1[0] = 1;
    if(s[0] == s[1]) dp1[1] = -INF;
    else dp1[1] = 2;
    dp2[0] = -INF;
    dp2[1] = 1;


    for(int i = 2; i < n; i++){
        if(s[i] != s[i - 1]){
            dp1[i] = max(dp1[i - 1], dp2[i - 1]) + 1;
        }else{
            dp1[i] = dp2[i - 1] + 1;
        }

        if(i == 2){
            dp2[i] = dp1[i - 2] + 1;
            continue;
        }
        if(s.substr(i - 3, 2) != s.substr(i - 1, 2)){
            dp2[i] = max(dp1[i - 2], dp2[i - 2]) + 1;
        }else{
            dp2[i] = dp1[i - 2] + 1;
        }
    }

    cout << max(dp1[n - 1], dp2[n - 1]) << endl;
    return 0;
}


Measured memory_bytes: 4244
h, w, k, = map(int, input().split())

c = [0] * h
for i in range(h):
    c[i] = input()
    
y = 0
    
for i in range(2 ** (h + w)):
    x = 0
    a = [0] * (h + w)
    for j in range(h + w):
        if (i // (2 ** j)) % 2 == 1:
            a[j] = 1
    
    for j in range(h):
        if a[j] == 0: 
            for l in range(w):
                if a[h+l] == 0:
                    if c[j][l] == '#':
                        x += 1
    
    if x == k:
        y += 1
        
print(y)

Measured memory_bytes: 9128
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i = (a); i < (b); i++)
#define iter(it,c) for(auto it = (c).begin(); it != (c).end();++it)
#define pb push_back
#define fs first
#define sc second
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;

const int INF = ~(1<<31);
const double pi = acos(-1);
const double EPS = 1e-9;
typedef unsigned long long ull;

template <class T> T smod(T a, T b) {
  return (a % b + b) % b; }

int main() {
    cin.sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    if(k == 1) {
        cout << 0 << endl;
        return 0;
    }
    cout << abs(n-k) << endl;
    return 0;
}


Measured memory_bytes: 256
//a.c A-Task Scheduling Problem
#include<stdio.h>

int abs(int x){
    if(x<0){
        return -x;
    }else{
        return x;
    }
}

int max(int a,int b,int c){
    int max = a;
    if(b>max){
        max = b;
    }
    if(c>max){
        max = c;
    }
    return max;
}

int min(int a,int b,int c){
    int min = a;
    if(b<min){
        min = b;
    }
    if(c<min){
        min = c;
    }
    return min;
}

int main(void){
    int a[3];
    for(int i=0;i<3;++i){
        scanf("%d",a+i);
    }
    int a12,a23,a31,sum;
    a12 = abs(a[0]-a[1]);
    a23 = abs(a[1]-a[2]);
    a31 = abs(a[2]-a[0]);
    int max1 = max(a12,a23,a31);
    int min1 = min(a12,a23,a31);
    if(max1==a12){
        sum += a23 + a31;
    }else if(max1 == a23){
        sum += a12 + a31;
    }else{
        sum += a12 + a23;
    }

    printf("%d\n",sum);
    return 0;
}

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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n, k, c=1;
  cin >> n >> k;
  vecll a(n);
  forll(i, 0, n)
	cin >> a[i];

  forll(i, 0, n){
	if (k + (k - 1) * (c-1) >= n)
	  break;
	c++;
  }
  cout << c << endl;
}


Measured memory_bytes: 1024
class Applemanager:
    def __init__(self, A, P):
        self.Apple       = A
        self.broken_Apple = P
        self.Apple_pi     = 0

    def make_apple_pi(self):
        self.Apple_pi = int(self.broken_Apple / 2)

    def make_broken_Apple(self):
        self.broken_Apple = self.broken_Apple + self.Apple * 3


S = input()
S = list(map(int, S.split()))

A = S[0]
P = S[1]

Applmngr = Applemanager(A, P)

Applmngr.make_broken_Apple()
Applmngr.make_apple_pi()

print(Applmngr.Apple_pi)


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

int n,m;
int a[110][110], f[110][110];

void DO (int x,int y,int i,int j) {
	if (a[i][j]==0) f[i][j]=min(f[i][j],f[x][y]);
	else {
		f[i][j]=min(f[i][j],f[x][y]+(a[i][j]^a[x][y]));
	}
}

int main ()
{
	cin >> n >> m;
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=m;j++)
		{
			char c; cin >> c;
			if (c=='.') a[i][j]=0;
			else a[i][j]=1;
		}
	}
	
	f[1][1]=a[1][1];
	for (int i=1;i<=n;i++)
	for (int j=1;j<=m;j++)
	{
		if (i==1 && j==1) continue ;
		f[i][j]=1e9;
		if (j!=1) DO (i,j-1,i,j);
		if (i!=1) DO (i-1,j,i,j);
	}
	
//	for (int i=1;i<=n;i++, puts (""))
//	for (int j=1;j<=m;j++)
//		cout << f[i][j] <<" "; 
	
	printf ("%d\n",f[n][m]);
	return 0;
}

Measured memory_bytes: 384
//By hz_cyn
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define temp template<typename T>
#define Re register
#define rt Re int
#define rch Re char
using namespace std;
#define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
char buf[1<<21],*p1=buf,*p2=buf;
temp inline void read(T&res){
    #define num ch-'0'
    char ch;bool flag=0;
    while(!isdigit(ch=getc()))
    (ch=='-')&&(flag=true);
    for(res=num;isdigit(ch=getc());res=(res<<1)+(res<<3)+num);
    (flag)&&(res=-res);
    #undef num
}
temp inline void write(T x){
    if(x<0)putchar('-'),x=-x;
    if(x==0){putchar('0');return;}
    rt num=0;rch ch[25];
    while(x)ch[++num]=x%10+48,x/=10;
    while(num)putchar(ch[num--]);
}
temp inline void writeln(T x){
    write(x);putchar('\n');
}
namespace HZ{
    #define ld long double
    #define ll long long
    #define rll register ll
    #define up(i,x,y) for(rt i=x;i<=y;i++)
    #define down(i,x,y) for(rt i=x;i>=y;i--)
    temp inline void Max(T&x,T y){if(x<y)x=y;}
    temp inline void Min(T&x,T y){if(x>y)x=y;}
    temp inline void SWAP(T&x,T&y){T t=x;x=y;y=t;}
    inline void Swap(rt&x,rt&y){x^=y^=x^=y;}
}using namespace HZ;
ll n,a,b;
#define r(x) read(x)
int main(){
    r(n);r(a);r(b);
    if(a>b){putchar('0');return 0;}
    if(n==1&&a!=b){putchar('0');return 0;}
    n--,n--;
    write(b*n-a*n+1);
    return 0;
}

Measured memory_bytes: 256
use std::cmp;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let q: usize = sc.read();
    for _ in 0..q {
        let a: u64 = sc.read();
        let b: u64 = sc.read();
        let (a, b) = if a > b { (b, a) } else { (a, b) };

        let mut ok = a - 1;
        let mut ng = 1e10 as u64;
        while ng - ok > 1 {
            let x = (ok + ng) / 2;
            let mut max = 0;
            if x >= b - 1 {
                // 1 ... a-1    a+1   ... x-b+1 x-b+2 ... x
                // x ... x-a+2  x-a+1 ... b+1   b-1   ... 1
                max = get_max(1, a - 1, x, x + 2 - a);
                max = cmp::max(max, get_max(a + 1, x - (b - 1), x - (a - 1), b + 1));
                max = cmp::max(max, get_max(x + 2 - b, x, b - 1, 1));
            } else {
                // 1 ... a-1      a+1 ... x
                // x-1 ... x-a+1  x-a ... 1
                max = get_max(1, a - 1, x - 1, x - (a - 1));
                max = cmp::max(max, get_max(a + 1, x, x - a, 1));
            }

            if max < a * b {
                ok = x;
            } else {
                ng = x;
            }
        }
        println!("{}", if a <= ok { ok - 1 } else { ok });
    }
}

fn get_max(from_a: u64, to_a: u64, from_b: u64, to_b: u64) -> u64 {
    if from_a > to_a {
        return 0;
    }
    assert_eq!(to_a + 1 - from_a, from_b + 1 - to_b);
    let mut max = cmp::max(from_a * from_b, to_a * to_b);
    let m = (from_a + from_b) / 2;
    for m in (m - 1)..(m + 3) {
        if from_a <= m && m <= to_a {
            let da = m - from_a;
            let b = from_b - da;
            max = cmp::max(max, m * b);
        }
    }
    max
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include <cstdio>
#include <bitset>
int N, M, u[100001], v[100001], disable[401], O;
std::bitset < 401 > mask[401];
int main()
{
	scanf("%d%d", &N, &M);
	for (int i = 1; i <= M; i++)
		scanf("%d%d", u + i, v + i);
	for (int i = 1; i <= N; i++)
	{
		std::bitset < 401 > &p = mask[i];
		p.set(i);
		for (int j = M; j; j--)
			if (p[u[j]] && p[v[j]])
			{
				disable[i] = 1;
				break;
			}
			else if (p[u[j]])
				p.set(v[j]);
			else if (p[v[j]])
				p.set(u[j]);
	}
	for (int i = 1; i < N; i++)
		if (!disable[i])
			for (int j = i + 1; j <= N; j++)
				if (!disable[j] && !(mask[i] & mask[j]).count())
					O++;
	printf("%d\n", O);
	return 0;
}


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

const int N = 3005;
const int mod = 1e9+7;

int n, m, f[N][N];
char s[N];
int l[N], r[N], d[N], sum[N];
int fact[N], rev[N];

int pw(int a, int n) {
    int result = 1;
    while (n > 0) {
        if (n & 1) result = (1LL * result * a) % mod;
        a = (1LL * a * a) % mod;
        n /= 2;
    }
    return result;
}

void prepare() {
    fact[0] = rev[0] = 1;
    for (int i = 1; i < N; ++i) {
        fact[i] = (1LL * fact[i - 1] * i) % mod;
        rev[i] = pw(fact[i], mod - 2);
    }
}

int c(int n, int k) {
    if (k < 0 || k > n) return 0;
    int result = 1;
    result = (1LL * result * fact[n]) % mod;
    result = (1LL * result * rev[n - k]) % mod;
    result = (1LL * result * rev[k]) % mod;
    return result;
}

void add(int &x, int y) {
    x += y;
    if (x >= mod) x -= mod;
}

int solve(int L, int R) {
    int ones = sum[r[L]] - sum[l[L]-1];
    for (int i = 0; i <= n; ++i) {
        f[L][i] = 0;
    }
    f[L][ones] = 1;
    for (int i = L; i < R; ++i) {
        for (int ones = 0; ones <= n; ++ones) {
            if (!f[i][ones]) continue;
            int diff = r[i]-l[i+1]+1;
            int nones = sum[r[i+1]]-sum[r[i]];
            int len = r[i]-l[i]+1;
            for (int x = max(0, ones-len+diff); x <= min(ones, diff); ++x) {
                add(f[i+1][nones+x], 1LL * f[i][ones] * c(len-diff, ones-x) % mod);
            }
        }
    }
    int result = 0;
    int len = r[R]-l[R]+1;
    for (int i = 0; i <= len; ++i) {
        add(result, 1LL * c(len, i) * f[R][i] % mod);
    }
    return result;
}

int main() {
    prepare();
    scanf("%d %d %s", &n, &m, s + 1);
    for (int i = 1; i <= n; ++i) {
        sum[i] = sum[i - 1] + (s[i] == '1');
    }
    for (int i = 1; i <= m; ++i) {
        scanf("%d %d", l + i, r + i);
    }
    for (int i = 1; i <= m; ++i) {
        if (d[i]) continue;
        for (int j = 1; j <= m; ++j) {
            if (i == j) continue;
            if (l[i] <= l[j] && r[i] >= r[j]) d[j] = 1;
        }
    }
    int pos = 1;
    for (int i = 1; i <= m; ++i) {
        if (!d[i]) {
            l[pos] = l[i];
            r[pos] = r[i];
            ++pos;
        }
    }
    m = pos - 1;
    int result = 1;
    for (int i = 1; i <= m; ++i) {
        int j = i + 1;
        while (j < m + 1 && r[j - 1] >= l[j]) ++j;
        result = (1LL * result * solve(i, j - 1)) % mod;
        i = j - 1;
    }
    printf("%d\n", result);
    return 0;
}


Measured memory_bytes: 6144
s=input()
flag1=0
flag2=0
s1=s[:2]
s2=s[2:]
if s1[0]=="0":
    s3=int(s1[1])
else:
    s3=int(s1)
if s2[0]=="0":
    s4=int(s2[1])
else:
    s4=int(s2)
if 1<=s3<=12 and 1<=s4<=12:
    print("AMBIGUOUS")
elif 1<=s3<=12:
    print("MMYY")
elif 1<=s4<=12:
    print("YYMM")
else:
    print("NA")


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

int main(){
	ios::sync_with_stdio(0);
	cout << setprecision(10) << fixed;
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	while (a > 0 && c > 0){
		c -= b;
		if (c <= 0){
			cout << "Yes";
			return 0;
		}
		a -= d;
		if (a <= 0){
			cout << "No";
			return 0;
		}
	}
	return 0;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
const long long mod=1000000007;
int main()
{
	long long n,k;
	scanf("%lld%lld",&n,&k);
	long long ans=0;
	for(long long i=k;i<=n+1;i++)
	{
		ans+=(n+1-i)*i+1;
		ans%=mod;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X, Y, A, B, C;
    cin >> X >> Y >> A >> B >> C;
    vector<int> p(A), q(B), r(C);
    REP(i,A) cin >> p[i];
    REP(i,B) cin >> q[i];
    REP(i,C) cin >> r[i];
    sort(p.rbegin(), p.rend());
    sort(q.rbegin(), q.rend());
    priority_queue<int, vector<int>, greater<int>> pq1, pq2;
    REP(i,X) pq1.push(p[i]);
    REP(i,Y) pq2.push(q[i]);

    REP(i,C){
        int pt = pq1.top();
        int qt = pq2.top();
        if(pt < qt){
            if(pt < r[i]){
                pq1.pop();
                pq1.push(r[i]);
            }
        }
        else{
            if(qt < r[i]){
                pq2.pop();
                pq2.push(r[i]);
            }
        }
    }
    ll ans = 0;
    while(!pq1.empty()){
        ans += pq1.top(); pq1.pop();
    }
    while(!pq2.empty()){
        ans += pq2.top(); pq2.pop();
    }
    cout << ans << endl;
}

Measured memory_bytes: 2552