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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int n;
  string s;
  cin >> s;
  n = s.size();
  int ans = 0;
  rep(i, (n + 1) / 2) {
    if (s[i] != s[n - i - 1]) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

void solve(){
    long long a,b,c,d;
    cin>>a>>b>>c>>d;
    long long ans=-MOD*MOD;
    for(int i=-10;i<=10;i++){
        for(int j=-10;j<=10;j++){
            if(a<=i && i<=b && c<=j && j<=d){
                ans=max(ans,i*j*1ll);
            }
        }
    }
    ans=max(ans,a*c);
    ans=max(ans,a*d);
    ans=max(ans,b*c);
    ans=max(ans,b*d);
    cout<<ans<<"\n";
}

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

    solve();
    return 0;
}

Measured memory_bytes: 3648
main = do
  h <- readLn :: IO Int
  w <- readLn :: IO Int
  n <- readLn :: IO Int
  putStrLn $ show $ if h < w
                    then
                        let x = div n w in x + if x * w == n then 0 else 1
                    else
                        let x = div n h in x + if x * h == n then 0 else 1


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
int n,k,x[100005],ans;
int main() {
	ans=1e9;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
		 cin>>x[i];
	int l=1,r=k;
	for(;r<=n;l++,r++) {
		if(x[l]<=0&&x[r]<=0) ans=min(-x[l],ans);
		else
		if(x[l]<=0&&x[r]>=0) ans=min(ans,min(0-2*x[l]+x[r],2*x[r]-x[l]));
		else
		if(x[l]>=0&&x[r]>=0) ans=min(x[r],ans);
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 640
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

ll mpow(ll a, ll b){
	if(b==0) return 1;
	else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
	else return mpow(a,b-1) * a % MOD;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
	if(kaijo_memo.size() > n) return kaijo_memo[n];
	if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
	while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
	return kaijo_memo[n];
}
ll nCr(ll n, ll r){
	if(n < r || r < 0) return 0;
	ll ret = 1;
	ret *= kaijo(n); ret %= MOD;
	ret *= mpow(kaijo(r), MOD-2); ret %= MOD;
	ret *= mpow(kaijo(n-r), MOD-2); ret %= MOD;
	return ret;
}

void update(vector<bool>& ok, int num, int k){
	while(!ok[num]){
		ok[num] = true;
		num *= 10;
		num %= k;
	}
}

int main(void){
	int k;
	cin>>k;
	int ans = 1;
	vector<bool> ok;
	rep(i,k){
		ok.push_back(false);
	}
	update(ok, 1, k);
	//cout<<ok[1]<<endl;

	while(!ok[0]){
		vector<bool> ok2;
		rep(i,k){
			ok2.push_back(ok[i]);
		}
		rep(i,k){
			if(ok[i]){
				update(ok2, (i+1)%k, k);
			}
		}
		rep(i,k){
			ok[i] = ok2[i];
		}
		ans++;
	}
	cout<<ans<<endl;


	return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
if n > 2 and m > 2:
  ans = (n-2)*(m-2)
elif n == 2 or m == 2:
  ans = 0
elif n == 1 and m == 1:
  ans = 1
elif n == 1:
  ans = m - 2
elif m == 1:
  ans = n - 2

print(ans)

Measured memory_bytes: 8860
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
import collections

def binary(n):
    return bin(n)[2:]

def pow_by_binary(a, x, n): # a^x mod n
    x = [int(b) for b in binary(x)]
    y = a
    for i in range(1, len(x)):
        y = (y**2) % n
        if x[i] == 1:
            y = (y * a) % n
    return y 
  
mod = 10 ** 9 + 7
 
N = int(readline())
A = [int(i) for i in readline().split()]
 
answer = 0
for n in range(62):
    B = [(i >> n) & 1 for i in A]
    C = collections.Counter(B)
    x = C[1]
    y = N - x
    x *= y
    if n >= 1:
      x = x*pow_by_binary(2,n,mod)
    x %= mod
    answer += x
    answer %= mod
print(answer)

Measured memory_bytes: 137656
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        XXOR solver = new XXOR();
        solver.solve(1, in, out);
        out.close();
    }

    static class XXOR {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            long k = in.nextLong();
            long[] a = new long[n];
            long max = k;
            for (int i = 0; i < n; i++) {
                a[i] = in.nextLong();
                max = Math.max(max, a[i]);
            }

            // 桁数 | 未満フラグ
            long[][] dp = new long[100][2];

            int dnum = 0;
            for (int i = 0; i <= 50; i++) {
                dp[i][0] = -1;
                dp[i][1] = -1;
                if ((max >> i) > 0) {
                    dnum++;
                }
            }
            if (k == 0) {
                long result = 0;
                for (long l : a) {
                    result ^= l;
                }
                out.println(result);
                return;
            }
            dp[0][0] = 0;
            for (int i = 0; i < dnum; i++) {
                int shift = dnum - i - 1;
                long mask = 1L << shift;
                long one = 0;
                for (long l : a) {
                    if ((l & mask) > 0) {
                        one++;
                    }
                }
                long cost0 = one * mask;
                long cost1 = (n - one) * mask;

                if (dp[i][1] != -1) {
                    // 未満フラグ立っている
                    dp[i + 1][1] = Math.max(dp[i + 1][1], dp[i][1] + Math.max(cost1, cost0));
                }
                // 未満フラグ立ってない
                if (dp[i][0] != -1) {
                    // ぴったり->未満
                    if ((k & mask) > 0) {
                        // kのbitが立っていたときに未満にできる
                        dp[i + 1][1] = Math.max(dp[i + 1][1], dp[i][0] + cost0);
                    }

                    // ぴったり->ぴったり
                    if ((k & mask) > 0) {
                        dp[i + 1][0] = Math.max(dp[i + 1][0], dp[i][0] + cost1);
                    } else {
                        dp[i + 1][0] = Math.max(dp[i + 1][0], dp[i][0] + cost0);
                    }

                }
            }
            out.print(Math.max(dp[dnum][0], dp[dnum][1]));
        }

    }
}



Measured memory_bytes: 60328
def func(N, B_i):
    sum = B_i[N-2]
    for i in reversed(range(N-1)):
        if i >= 1:
            sum += min(B_i[i], B_i[i-1])
        else:
            sum += B_i[i]
    return sum

N = int(input())
B_i = list(map(int, input().split(" ")))
print(func(N, B_i))

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
const int maxn=5e5+10;
ll a[maxn],pre[maxn],suf[maxn];
 
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(i==0) pre[i]=a[i];
		else pre[i]=pre[i-1]^a[i];
	}
	for(int i=n-1;i>=0;i--){
		if(i==n-1) suf[i]=a[i];
		else suf[i]=suf[i+1]^a[i];
	}
	for(int i=0;i<n;i++){
		if(i==0) cout<<suf[i+1]<<" ";
		else if(i==n-1) cout<<pre[i-1]<<" ";
		else cout<<ll(pre[i-1]^suf[i+1])<<" ";
	}
	return 0;	
}

Measured memory_bytes: 7728
import sys

ns = lambda: sys.stdin.readline().rstrip()
ni = lambda: int(ns())
nm = lambda: map(int, sys.stdin.readline().split())
nl = lambda: list(nm())
nsm = lambda: map(str, sys.stdin.readline().split())
nsl = lambda: list(nsm())


x, a = nm()
if x < a:
    print(0)
else:
    print(10)



Measured memory_bytes: 3060
using System;

namespace consoleapp01
{
    class foo
    {
        static void Main()
        {
            int X, A;

            string[] st = Console.ReadLine().Split(' ');
            X = int.Parse(st[0]);
            A = int.Parse(st[1]);

            if (X < A)
                Console.WriteLine("0");
            else if (X >= A)
                Console.WriteLine("10");
        }
        
    }
}

Measured memory_bytes: 11092
#include<iostream>
using namespace std;
int p,i,j,a,b,d;string s,u="[<++++++++++>-]>",v="+++++",w=u+v,x=w+v,c=">"+v+"[<++++++>-]>"+v+"[<++++++++>-]>"+v+w+"+"+w+"++"+w+"+++"+w+"++++"+x+x+"+"+x+"++"+u+"<<<<<<<<<<<";main(){for(cin>>s;i<s.length();++i){a=s[i]/10-3,b=a-p,p=a,d=s[i]-a*10-30;for(j=b>0?b:-b;j--;)c+=b>0?62:60;for(j=d;j--;)c+=43;c+=46;for(j=d;j--;)c+=45;}cout<<c<<endl;}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
using ll = long long;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
using namespace std;
int main(void){
    int n,m; cin>>n>>m;
    if(n==1||m==1) {cout<<1<<endl; return 0;}
    vector <int> nums;
    COMinit();
    //cout<<m<<endl;
    
        for(int i=2;i*i<=m;i++){
            if(m%i!=0) continue;
            int cnt=0;
            while(m%i==0){ cnt++; m = m/i;}
            if(cnt!=0) nums.push_back(cnt);
        }
        //cout<<m<<endl;
    if(m!=1) nums.push_back(1);
    ll ans = 1;
    for(int i=0;i<nums.size();i++){
        ll tmp;
        tmp = COM(nums[i]+n-1, n-1);
        tmp%=MOD;
        ans *= tmp;
        ans%= MOD;
    }
    cout<<ans%MOD<<endl;
}


Measured memory_bytes: 12160
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <bitset>
#include <vector>
using namespace std;

#define LL long long

#define fi first
#define se second
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(a,b) (((a)+(b))>>1)
#define maxx(a,b) ((a)<(b)?(b):(a))
#define minx(a,b) ((a)<(b)?(a):(b))
#define absx(a) ((a)<0?-(a):(a))
#define mk(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define itr iterator
#define lowbit(x) ((x)&-(x))

typedef unsigned LL ULL;
typedef unsigned uint;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<LL,LL> pLL;

template< typename T > inline void read(T &x) {
    bool f; char ch; f=0; x=0; ch=getchar();
    while(ch<'0' || ch>'9') {if(ch=='-') f=1; ch=getchar();}
    while(ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
    if(f) x=-x;
}

template< typename T > inline void Max(T &a, T b) {if(a<b) a=b;}
template< typename T > inline void Min(T &a, T b) {if(b<a) a=b;}
template< typename T > inline T Abs(T a) {if(a<0) return -a; else return a;}

const double pi=(double) acos(-1.0);
const int MOD=(int) 1e9+7;
const int INF=(int) 0x3f3f3f3f;
const LL  LINF=(LL) INF<<32|INF;
const int SINF=(uint) ~0>>1;
const LL  SLINF=(ULL) (-1)>>1;
const double DINF=(double) 1e50;
const double eps=(double) 1e-12;
const int maxn=(int) 5e5+20;
const int maxm=(int) 1e6+20;
const int maxk=(int) 5e2+20;

inline int sig(double x) {return x<-eps?-1:x>eps;}

//--------------start------------------

int n;
char s[maxn];
int dp[maxn][2];

void work()
{
    read(n);
    scanf("%s",s+1);

    for(int i=0;i<=n;i++) dp[i][0]=0, dp[i][1]=-INF;
    for(int i=3;i<=n;i++)
    {
        if(s[i-2]=='1' && s[i-1]=='0' && s[i]=='1')
        {
            for(int j=i-2,k=1;s[j]=='1' && j>0;j--,k++)
            {
                Max(dp[i][0],dp[j-1][0]+k);
            }

            Max(dp[i][1],dp[i-3][0]+1);
        }

        if(s[i]=='0') dp[i][1]=-INF;
        else Max(dp[i][1],dp[i-1][1]+1);

        Max(dp[i][0],max(max(dp[i-1][0],dp[i-1][1]),dp[i][1]));
    }

//    for(int i=1;i<=n;i++)
//    {
//        cout <<dp[i][0] <<" " <<dp[i][1] <<endl;
//    }

    printf("%d\n",max(dp[n][0],dp[n][1]));
}

//--------------end--------------------

int main()
{
#ifdef yukihana0416
freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
#endif // yukihana0416
    work();
    return 0;
}


Measured memory_bytes: 4608
while line = gets
	n, x = line.split( " " ).map { | val | val.to_i }
	break if 0 == n && 0 == x

	
	cnt = 0
	ave = x / 3
    for i in ( 1 .. ave-1 )
        for j in ( i+1 .. n-1 )
            break if x < i+j
            for k in ( j+1 .. n )
                s = ( i + j + k )
                if x < s
                    break
                elsif x == s
                    cnt += 1
                    break
                end
            end
        end
    end

	puts( cnt )
end

Measured memory_bytes: 6108
#include<stdio.h>
#include<string.h>
int main(void) {
    int a, b, result;
    char op[2];
    while(1) {
        scanf("%d%s%d", &a, op, &b);
        if(strcmp("?", op) == 0) break;
        if(strcmp("+", op) == 0) result = a+b;
        if(strcmp("-", op) == 0) result = a-b;
        if(strcmp("*", op) == 0) result = a*b;
        if(strcmp("/", op) == 0) result = a/b;
        printf("%d\n", result);
    }
    return 0;
}


Measured memory_bytes: 2100
import sys

class Node:
    __slots__ = ['key', 'left', 'right']
    def __init__(self, key):
        self.key = key
        self.left = None
        self.right = None

class BST:
    def __init__(self):
        self.root = None
    def insert(self, key):
        x = self.root
        y = None
        z = Node(key)
        while x != None:
            y = x
            x = x.left if z.key < x.key else x.right
        if y == None: self.root = z
        else:
            if z.key < y.key: y.left = z
            else: y.right = z
    def print_tree(self):
        def inorder(node):
            return inorder(node.left) + f' {node.key}' + inorder(node.right) if node else ''
        def preorder(node):
            return f' {node.key}' + preorder(node.left) + preorder(node.right) if node else ''
        print(inorder(self.root))
        print(preorder(self.root))

tree = BST()
input()
for e in sys.stdin:
    if e[0] == 'i': tree.insert(int(e[7:]))
    else: tree.print_tree()


Measured memory_bytes: 63276
import math
A, B = map(int, input().split())

eightlow = math.ceil(A/0.08)
eighthigh = int((A+1)//0.08)
tenlow = math.ceil(B/0.1)
tenhigh = int((B+1)//0.1)

eight = []
ten = []

for i in range(eightlow, eighthigh+1):
    eight.append(i)
for i in range(tenlow, tenhigh+1):
    ten.append(i)

for i in range(len(eight)):
    for j in range(len(ten)):
        if eight[i] ==ten[j]:
            print(eight[i])
            exit()

print(-1)


Measured memory_bytes: 3316
//#pragma comment(linker, "/STACK:102400000,102400000") 
#pragma warning(disable:4996)
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
#define eps 1e-10
#define LL_INF 0x33ffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back

const int maxn = 1e5 + 5;
const ll mod = 1e9 + 7;
const double PI = acos(-1.0);
ll po(ll a, ll b, ll mod) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a, ll b) { if (a == 0) { return b; } else { return gcd(b%a, a); } }

int n, k, res;
int val[maxn];
vector<int>edge[maxn];

int dfs(int x)
{
	int ans = 0;
	int sz = edge[x].size();
	for (int i = 0; i<sz; i++)
	{
		int y = edge[x][i];
		ans = max(ans, dfs(y));
	}
	ans++;
	if (ans >= k&&val[x] != 1)
	{
		ans = 0;
		res++;
	}
	return ans;
}

void solve()
{
	scanf("%d%d", &n, &k);
	scanf("%d", &val[1]);
	res = 0;
	if (val[1] != 1)
	{
		res++;
		val[1] = 1;
	}
	for (int i = 2; i <= n; i++)
	{
		scanf("%d", &val[i]);
		edge[val[i]].push_back(i);
	}
	dfs(1);
	printf("%d", res);
}


int main()
{
	solve();
	return 0;
}



Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
#define int long long

const int MAX = 1000000;
const int MOD = 1000000007;

signed main() {
 string s;
 cin>>s;
 int a=700;for(int i=0;i<3;i++)if(s[i]=='o')a+=100;
 cout<<a;

return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
 
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }

  int main(){
     lint N;
     cin >>N; lint A[N];
     map<lint,lint> m;
     rep(i,N){cin >> A[i];
        m[A[i]]++;
     }
     sort(A,A+N,greater<lint>());
     lint ans=0;
     rep(i,N){
        lint t=1;
        while(t<=A[i]){
            t*=2;
        }
        if(t-A[i]==A[i]){
            if(m[A[i]]>1){
            m[A[i]]-=2;
            ans++;}
        }
      else if((m[t-A[i]]>0&&m[A[i]])>0){
            ans++;
            m[t-A[i]]--;
            m[A[i]]--;
        }
     }
     cout<<ans<<endl;
  }

  
     
  

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

typedef long long ll;

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  vector<int> B(N);
  for(int i=0; i<N; i++){
    cin >> A[i];
    B[i]=A[i];
  }
  
  sort(B.begin(), B.end());
  for(int i=0; i<N; i++){
    if(A[i]==B[N-1]) cout << B[N-2]<<endl;
    else cout << B[N-1] <<endl;
  }
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
int main(){
    int H,A;
    cin >> H >> A;
    int i=0;
    while(1){
        H-=A;
        i++;
        if(H<=0){
            cout << i << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <utility>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>

#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define itrep(i,x) for(auto i=(x).begin(); i!=(x).end();i++)
#define Sort(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define vec vector
#define INF INT_MAX
#define INFL 1e18
#define MOD 1000000007
#define pb push_back
#define MP make_pair
#define PI 3.1415926535
typedef long long int ll;
typedef std::pair<int,int> P;
int D=1;
int dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};

using namespace std;


int main(){
    int a,b;
    cin>>a>>b;

    int ans=-100000;
    ans=max(ans,a+b);
    ans=max(ans,a-b);
    ans=max(ans,a*b);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;
    static final int ALF = 26;

    Main() {
        Scanner sc = new Scanner(System.in);
        long ans = 0;
        int N = sc.nextInt();
        String S = sc.next();
        int rc = 0;
        int gc = 0;
        int bc = 0;
        for (int i = 0; i < N; i++) {
            switch (S.charAt(i)) {
                case 'R':
                    rc++;
                    break;
                case 'G':
                    gc++;
                    break;
                case 'B':
                    bc++;
                    break;
            }
        }
        ans = (long)rc * gc * bc;
        for (int p = 1; p < N; p++) {
            for (int i = 0; i + p + p < N; i++) {
                if (S.charAt(i) != S.charAt(i + p) && S.charAt(i) != S.charAt(i + p + p)
                        && S.charAt(i + p) != S.charAt(i + p + p))
                    ans--;
            }
        }
        System.out.println(ans);
    }

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


Measured memory_bytes: 37196
using System;

namespace AtCoder
{
    class Program
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int k = int.Parse(str[0]);
            int x = int.Parse(str[1]);

            if (500 * k >= x) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 11092
#include <iostream> 
#include <bits/stdc++.h>
#include <vector> 
#include <algorithm> 
#include <string>
#include <cmath>
#include <iomanip> 
#include<climits> 
#include <utility>   
#include <set>
#include <numeric> 
#include <iterator>
#include <map> 
using namespace std; 
#define ll long long int
//typedef pair<ll,ll> p; 
int main()
{
      string s;
      cin>>s;
      if(s[2]==s[3] && s[4]==s[5])
      cout<<"Yes"<<endl;
      else
      cout<<"No"<<endl;
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    int N;
    while (cin >> N, N) {
        vector<int> A(N);
        rep(i, N) cin >> A[i];

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

        int ans = INF;
        rep(i, N-1) {
            ans = min(ans, A[i+1] - A[i]);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3172
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A, B, C = MAP()
K = INT()
print(A + B + C + max(A, B, C)*((2**K)-1))

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

using T = tuple<int, int, int, int>;

const int INF = 1001001001;

int w, h;
bool grid[55][55];
int ti[55][55][55][55];
int dx[4] = { 0, 0, -1, 1 }, dy[4] = { -1, 1, 0, 0 };

bool f(int y, int x) {
    if (0 <= y && y < h && 0 <= x && x < w && !grid[y][x]) return true;
    return false;
}

int main() {
    while (cin >> w >> h && !(w == 0 && h == 0)) {
        int tx, ty, kx, ky;
        cin >> tx >> ty >> kx >> ky;
        tx--; ty--; kx--; ky--;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                cin >> grid[i][j];
            }
        }
        for (int i = 0; i < 55; i++) {
            for (int j = 0; j < 55; j++) {
                for (int k = 0; k < 55; k++) {
                    for (int l = 0; l < 55; l++) {
                        ti[i][j][k][l] = INF;
                    }
                }
            }
        }
        queue<T> que;
        que.push(T(ty, tx, ky, kx));
        ti[ty][tx][ky][kx] = 0;
        int gy, gx;
        bool flag = false;
        while (!flag && que.size()) {
            T t = que.front(); que.pop();
            int cty = get<0>(t), ctx = get<1>(t);
            int cky = get<2>(t), ckx = get<3>(t);
            for (int i = 0; i < 4; i++) {
                int nty = cty + dy[i], ntx = ctx + dx[i];
                if (!f(nty, ntx)) nty = cty, ntx = ctx;
                int nky = cky - dy[i], nkx = ckx - dx[i];
                if (!f(nky, nkx)) nky = cky, nkx = ckx;
                if (ti[nty][ntx][nky][nkx] <= ti[cty][ctx][cky][ckx] + 1) continue;
                ti[nty][ntx][nky][nkx] = ti[cty][ctx][cky][ckx] + 1;
                if (nty == nky && ntx == nkx) {
                    gy = nty, gx = ntx;
                    flag = true;
                    break;
                }
                que.push(T(nty, ntx, nky, nkx));
            }
        }
        int ans = ti[gy][gx][gy][gx];
        if (ans < 100) cout << ans << endl;
        else cout << "NA" << endl;
    }
}


Measured memory_bytes: 38956
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] cards = new int[n+2];
		for (int i=0;i<n+2;i++) {
			cards[i]=sc.nextInt();
		}

		int [][] mainTable= new int[n+2][n+2];
		int [][] subTable = new int[n+2][n+2];

		for (int j=0;j<n+1;j++) {
			mainTable[j][n+1] = Math.abs(cards[j]-cards[n+1]);
			mainTable[n+1][j] = Math.abs(cards[j]-cards[n+1]);
			subTable[j][n+1] = Math.abs(cards[j]-cards[n+1]);
			subTable[n+1][j] = Math.abs(cards[j]-cards[n+1]);
		}

		for (int i=n;i>=1;i--) {
			for (int j=0;j<i;j++) {
				mainTable[i][j] = subTable[i][i+1];
				subTable[i][j] = Math.max(mainTable[i][j], subTable[i+1][j]);

				mainTable[j][i] = subTable[i+1][i];
				subTable[j][i] = Math.min(mainTable[j][i], subTable[j][i+1]);
			}
		}

		System.out.println(mainTable[0][1]);

	}

}


Measured memory_bytes: 84660
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
     
using namespace std;
     
typedef long long ll;
typedef pair<ll, int> pii;
     
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
     
mt19937 rnd(chrono::steady_clock().now().time_since_epoch().count());

const int N = 5009;
const int M = 205;

ll f[N];

void upd(int l, int r, ll d){
    f[l] += d;
    f[r + 1] -= d;
}

ll z[N];

ll g[N][M];
ll d[N];

stack<pii> ff[M];

int main(){
    fastIO;
    int n, m;
    cin >> n >> m;
    for(int i = 2; i <= n; i ++ ){
        cin >> d[i];
    }
    int id;
    ll res = 0;
    for(int i = 1; i <= n; i ++ ){
        for(int j = 1 ; j <= n; j ++ )
            f[j] = 0;
        if(i>1){
            upd(1, i - 1, -d[i]);
        }
        for(int j = 1; j <= m ; j ++ ){
            cin >> g[i][j];
            id = i;
            upd(id, id, g[i][j]);
            while(!ff[j].empty() && ff[j].top().fi < g[i][j]){
                upd(ff[j].top().se, id-1, g[i][j] - ff[j].top().fi);
                id = ff[j].top().se;
                ff[j].pop();
            }
            ff[j].push(mp(g[i][j], id));
        }
        for(int j = 1; j <= n; j ++ ){
            f[j] += f[j-1];
            z[j] += f[j];
            res = max(res, z[j]);
        }
    }
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 8576
N = input()
S = [int(c) for c in N]

A = [0] * (len(S)+4)
B = [0] * (len(S)+4)

for i in range((len(S)//2)+1):
  A[i*2+1] = 1
  B[i*2] = 1
  
ca =0
cb =0
for i in range(len(S)):
  ca += abs(S[i]-A[i])
  cb += abs(S[i]-B[i])
print(min(ca, cb))

Measured memory_bytes: 5620
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define fi first
#define se second
#define inf (INT_MAX/2-1)
#define infl (1LL<<60)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) begin(a),end(a)
#define y0 y5656
#define y1 y7878
#define aaa system("pause");
#define dbg(x) cerr<<(#x)<<": "<<(x)<<'\n',aaa
#define dbga(x,n) cerr<<(#x)<<"[]: ";for(int _=0;_<n;_++)cerr<<x[_]<<' ';cerr<<'\n',aaa
#define dbgs(x) cerr<<(#x)<<"[stl]: ";for(auto _:x)cerr<<_<<' ';cerr<<'\n',aaa
#define dbgp(x) cerr<<(#x)<<": "<<x.fi<<' '<<x.se<<'\n',aaa
#define maxn 5000000

using namespace std;

struct yes {
  int l, r, ans, ind;
};

int n;

struct AIB {
  int yy[maxn+5];
  int lsb (int x) {
    return x&(-x);
  }
  void upd (int x, int amt) {
    for (; x <= n; x += lsb(x)) yy[x] += amt;
  }
  int get (int x) {
    int ans = 0;
    for (; x > 0; x -= lsb(x)) ans += yy[x];
    return ans;
  }
};

int v[maxn+5], lapr[maxn+5];
yes qry[maxn+5];
AIB aib;

int main () {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int q; cin >> n >> q;
  int i;
  for (i = 1; i <= n; i++) cin >> v[i];
  for (i = 1; i <= q; i++) {
    cin >> qry[i].l >> qry[i].r;
    qry[i].ind = i;
  }
  sort (qry+1, qry+q+1, [](yes &a, yes &b) { return a.r < b.r; });
  int now = 1;
  fill(all(lapr), -1);
  for (i = 1; i <= q; i++) {
    for (; now <= qry[i].r; now++) {
      if (lapr[v[now]] != -1) aib.upd(lapr[v[now]], -1);
      lapr[v[now]] = now;
      aib.upd(now, 1);
    }
    qry[i].ans = aib.get(qry[i].r) - aib.get(qry[i].l-1);
  }
  sort (qry+1, qry+q+1, [](yes &a, yes &b) { return a.ind < b.ind; });
  for (i = 1; i <= q; i++) cout << qry[i].ans << '\n';
  return 0;
}

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

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

    long long I, O, J, L, temp;
    cin>>I>>O>>temp>>J>>L>>temp>>temp;

    long long ans = O + (I/2)*2 + (J/2)*2 + (L/2)*2;
    if (I && J && L) {
        I--, J--, L--;
        ans = max(ans, O + (I/2)*2 + (J/2)*2 + (L/2)*2 + 3);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MM 1000000007
using namespace std;

int main()
{
	int a,b;
	cin>>a>>b;
	
	int sock=1,cnt=0;
	
	while (sock<b)
	{
		sock--;
		sock+=a;
		cnt++;
	}
	cout<<cnt;
}


Measured memory_bytes: 256
import std.stdio;
import std.bitmanip;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

byte L(byte x) {
    return (x & 0xF8) >> 3;
}
byte R(byte x) {
    return x & 0x07;
}
byte C(byte x, byte y) {
    return cast(byte)((x << 3) + y);
}
string format(byte x) {
    return L(x).to!string ~ R(x).to!string;
}
bool valid(byte x) {
    return (1 <= L(x) && L(x) <= 4 && 1 <= R(x) && R(x) <= 7);
}

byte F[32];
void input() {
    F[] = 0;
    foreach (i; 0 .. 4) {
        foreach (j; 1 .. 8) {
            int x;
            scanf("%d", &x);
            F[i * 8 + j] = C(cast(byte)x / 10, cast(byte)x % 10);
        }
    }
}

void dump(byte[32] X) {
    foreach (i; 0 .. 4) {
        foreach (j; 0 .. 8) {
            writef("%s ", format(X[i * 8 + j]));
        }
        writeln;
    }
}

bool check(in byte[32] X) {
    foreach (i; 0 .. 4) {
        foreach (j; 0 .. 7) {
            byte x = X[i * 8 + j];
            if (L(x) == i + 1 && R(x) == j + 1) continue;
            return false;
        }
    }
    return true;
}

struct S {
    byte[32] F;
    byte[40] M;
    byte[] zpos;
    int t;
}

void solve() {
    alias byte[32] key;
    auto used = new RedBlackTree!key;

    foreach (i; 0 .. 4) {
        foreach (j; 0 .. 8) {
            byte x = F[i * 8 + j];
            if (R(x) == 1) {
                swap(F[i * 8 + j], F[ (L(x) - 1) * 8  ]);
            }
        }
    }
    byte[40] M;
    byte[] zpos;
    foreach (i; 0 .. 4) {
        foreach (j; 0 .. 8) {
            byte x = F[i * 8 + j];
            if (x == 0) zpos ~= cast(byte)(i * 8 + j);
            M[x] = cast(byte)((i << 3) + j);
        }
    }

    DList!S Q;
    Q.insert(S(F, M, zpos.dup, 0));
    used.insert(F);
    while (!Q.empty) {
        S cur = Q.front; Q.removeFront;
        //writeln("\t", cur.t);
        //dump(cur.F);
        //writeln;
        if (check(cur.F)) {
            writeln(cur.t);
            return;
        }
        foreach (pos; cur.zpos) {
            auto x = cur.F[pos];
            if (x > 0) continue;
            auto y = cur.F[pos - 1];
            auto z = C(L(y), cast(byte)(R(y) + 1));
            if (!z.valid) continue;
            auto N = cur.M;
            byte p = N[z];
            swap(cur.F[ L(p) * 8 + R(p) ], cur.F[pos]);
            N[z] = pos;
            auto nzpos = setDifference(cur.zpos, [pos]).array ~ p;
            if (cur.F in used) {
                swap(cur.F[ L(p) * 8 + R(p) ], cur.F[pos]);
            } else {
                used.insert(cur.F);
                Q.insert(S(cur.F, N, nzpos, cur.t + 1));
                swap(cur.F[ L(p) * 8 + R(p) ], cur.F[pos]);
            }
        }
    }
    writeln(-1);
}

void main() {
    int T;
    scanf("%d\n", &T);
    foreach (t; 0 .. T) {
        import core.memory;
        GC.collect;
        input; solve;
    }
}

Measured memory_bytes: 31872
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();
		final int K = sc.nextInt();
		int a[] = new int[N];
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		Integer temp[] = new Integer[200000];
		int num = 0;
		Arrays.fill(temp, 0);
		for(int i = 0; i < N; i++) {
			if(temp[a[i]] == 0) num++;
			temp[a[i]]++;
		}
		Arrays.sort(temp, Comparator.reverseOrder());
		
		int ans = 0;
		for(int i = 0; i < 200000; i++) {
			if(i + 1 <= K) {
				continue;
			} else if(temp[i] != 0) {
				ans += temp[i];
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 65332
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

constexpr double PI = 3.141592653589793238;

int main(int argc, char const *argv[]) {
    double a,b; cin>>a>>b;
    double h,m; cin>>h>>m;

    double hour = (60*h+m)/720 * 2*PI;
    double min = (m/60) * 2*PI;
    double theta = hour-min;

    double ans = (a*a + b*b) - (2*a*b * cos(theta));
    cout << fixed << setprecision(10);
    cout << sqrt(ans) << '\n';
    return 0;
}

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

int main()
{
  int n,a,b,c,d;
  int num1,num2;

  cin >> n >> a >> b >> c >> d;

  if(n % a == 0 && n % c == 0)
    {
      if((n/a)*b < (n/c)*d)
	{
	  cout << (n/a)*b << endl;
	}
      else
	{
	  cout << (n/c)*d << endl;
	}
    }
  else if(n % c == 0)
    {
      num1= (n/a)+1;
      if(num1*b < (n/c)*d)
	{
	  cout << num1*b << endl;
	}
      else
	{
	  cout << (n/c)*d << endl;
	}
    }
  else if(n % a == 0)
    {
      num2= (n/c)+1;
      if((n/a)*b < num2*d)
	{
	  cout << (n/a)*b << endl;
	}
      else
	{
	  cout << num2*d << endl;
	}
    }
  else
    {
      num1= (n/a)+1;
      num2= (n/c)+1;
      if(num1*b < num2*d)
	{
	  cout << num1*b << endl;
	}
      else
	{
	  cout << num2*d << endl;
	}
    }
}



Measured memory_bytes: 3096
N,M=map(int,input().split())
if N==1 and M==1:
    print(1)
    quit()
if N>M:
    M,N=N,M
if N==1:
    print(max(0,M-2))
    quit()
if N==2:
    print(0)
    quit()
print(N*M-(2*N+2*M-4))


Measured memory_bytes: 38256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int l,r,ans;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>l>>r;
		ans=ans+r-l+1;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import Control.Applicative

primes :: [Integer]
primes = [11,31,41,61,71,101,131,151,181,191,211,241,251,271,281,311,331,401,421,431,461,491,521,541,571,601,631,641,661,691,701,751,761,811,821,881,911,941,971,991,1021,1031,1051,1061,1091,1151,1171,1181,1201,1231,1291,1301,1321,1361,1381]

getInt :: IO Int
getInt = (\a -> read a :: Int) <$> getLine

toString :: Show a => [a] -> String
toString [] = ""
toString [x] = show x
toString (x:xs) = (show x) ++ " " ++  toString xs

main = do
    len <- getInt
    putStrLn $ toString $ take len primes


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

using namespace std;
using ll = long long;

const int maxn = 1005;
int a[maxn][maxn];
const int Inf = 1e9 + 5;

vector<pair<int, int>> adj[maxn][maxn];
int indeg[maxn][maxn], d[maxn][maxn], color[maxn][maxn];

bool checkCycle(int u, int v) {
    color[u][v] = 1;
    bool ans = 0;
    for (pair<int, int> x : adj[u][v]) {
        if (color[x.first][x.second] == 1) {
            ans |= 1;
        }
        else if (color[x.first][x.second] == 0) {
            ans |= checkCycle(x.first, x.second);
        }
    }
    color[u][v] = 2;
    return ans;
}

int main()
{
    int n;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j < n; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < maxn; i++) {
        for (int j = 0; j < maxn; j++){
            d[i][j] = Inf;
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j < n - 1; j++) {
            int c = min(i, a[i][j]);
            int d = max(i, a[i][j]);
            int e = min(i, a[i][j + 1]);
            int f = max(i, a[i][j + 1]);
            adj[c][d].push_back({e, f});
            indeg[e][f]++;
        }
    }
    int ans = 1;
    queue<pair<int, int>> q;
    for (int i = 1; i < n; i++) {
        for (int j = i + 1; j <= n; j++){
            if (indeg[i][j] == 0) {
                q.push({i, j});
                d[i][j] = 1;
            }
        }
    }
    for (int i = 1; i < n; i++) {
        for (int j = i + 1; j <= n; j++) {
            if (color[i][j] == 0 && checkCycle(i, j)) {
                cout << "-1";
                return 0;
            }
        }
    }
    while (!q.empty()) {
        pair<int, int> cur = q.front();
        q.pop();
        for (auto v : adj[cur.first][cur.second]) {
            //cout << v.first << " " << v.second << " " << indeg[v.first][v.second] << endl;
            indeg[v.first][v.second]--;
            if (indeg[v.first][v.second] == 0) {
                q.push(v);
                d[v.first][v.second] = 1 + d[cur.first][cur.second];
                ans = max(ans, d[v.first][v.second]);
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 55424
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define all(a) (a).begin(), (a).end()


int main(){
    int N;
    cin >> N;
    vector<int> P(N);
    for(int i = 0; i < N; i++) cin >> P[i];
    int ans = 0;
    for(int m = 1; m < N - 1; m++){
        vector<int> three(3);
        three[0] = P[m - 1];
        three[1] = P[m];
        three[2] = P[m + 1];
        sort(all(three));
        if(three[1] == P[m]) ans++;
    }
    cout << ans << endl;
}


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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

unsigned f(unsigned S, int x, int from, int to) {
  if (from >= 0) {
    S &= ~((from >> 0 & 1) << (x << 1));
    S &= ~((from >> 1 & 1) << ((x << 1) + 1));
  }
  S |= (to >> 0 & 1) << (x << 1);
  S |= (to >> 1 & 1) << ((x << 1) + 1);
  return S;
}

vector<int> getTop(unsigned S, int n) {
  vector<int> res(3, -1);
  for (int i = 0; i < n; i++) {
    int l = S >> ((i << 1) + 1) & 1;
    int r = S >> (i << 1) & 1;
    res[(l << 1) + r] = max(res[(l << 1) + r], i);
  }
  return res;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n, m;
  while (cin >> n >> m, n) {
    unsigned S = 0;
    for (int i = 0; i < 3; i++) {
      int sz;
      cin >> sz;
      for (int j = 0; j < sz; j++) {
        int x;
        cin >> x;
        S = f(S, x - 1, -1, i);
      }
    }

    map<unsigned, int> d;
    d[S] = 0;
    queue<unsigned> que;
    que.emplace(S);
    int ans = -1;
    while (que.size()) {
      unsigned s = que.front(); que.pop();
      auto v = getTop(s, n);
      if (v[1] < 0 && (v[0] < 0 || v[2] < 0)) {
        ans = (d[s] <= m ? d[s] : -1);
        break;
      }
      
      unsigned ns;
      for (int i = 0; i < 3; i++) {
        int l = i == 0 ? -1 : i - 1;
        int r = i == 2 ? -1 : i + 1;
        if (l >= 0 && v[i] > v[l]) {
          ns = f(s, v[i], i, l);
          if (d.find(ns) == d.end()) {
            d[ns] = d[s] + 1;
            que.emplace(ns);
          }
        }
        if (r >= 0 && v[i] > v[r]) {
          ns = f(s, v[i], i, r);
          if (d.find(ns) == d.end()) {
            d[ns] = d[s] + 1;
            que.emplace(ns);
          }
        }
      }
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 120424
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<algorithm>
#define ll long long
#define lowbit(x) x&-x
using namespace std;
int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a<b?b:a;}
int ab(int x){return x>0?x:-x;}
//int MO(int x){return x>=MOD?x-MOD:x;}
//void insert(int u,int v){tot++;e[tot].v=v;e[tot].from=first[u];first[u]=tot;}
/*------------------------------------------------------------*/
const int inf=0x3f3f3f3f,maxn=1010;

int n,m,a[maxn][maxn],b[maxn],c[maxn];

bool solve(int mx){
	//if(!mx)return 0;
	memset(c,0,sizeof(c));
	for(int i=1;i<=n;i++)b[i]=1,c[a[i][1]]++;
	for(int i=1;i<=m;i++){
		int x=0;
		for(int j=1;j<=m;j++)if(c[j]>mx){x=j;break;}
		if(!x)return 1;
		c[x]=-1;
		for(int j=1;j<=n;j++)if(a[j][b[j]]==x){
			for(int k=b[j]+1;k<=m;k++)if(~c[a[j][k]]){
				b[j]=k;c[a[j][k]]++;
				break;
			}
		}
	}
	return 0;
}	
int main(){
    n=read();m=read();
    for(int i=1;i<=n;i++){
    	for(int j=1;j<=m;j++){
    		a[i][j]=read();
    	}
    }
    int l=0,r=n,mid;
    while(l<r){
    	mid=(l+r)>>1;
    	if(solve(mid))r=mid;else l=mid+1;
    }
    printf("%d",l);
    return 0;
}

Measured memory_bytes: 1408