akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <bitset>
#include <utility>
#include <assert.h>
using namespace std;
#define rank rankk
#define mp make_pair
#define pb push_back
#define xo(a,b) ((b)&1?(a):0)
#define tm tmp
//#define LL ll
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
const int INF=0x3f3f3f3f;
const ll INFF=0x3f3f3f3f3f3f3f3fll;
const int MAX=1e5+5;
//const ll MAXN=2e8;
const int MAX_N=MAX;
const ll MOD=1e9+7;
//const long double pi=acos(-1.0);
//const double eps=0.00000001;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
template<typename T>inline T abs(T a) {return a>0?a:-a;}
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
inline ll powMM(ll a,ll b,ll M){
    ll ret=1;
    a%=M;
//    b%=M;
    while (b){
        if (b&1) ret=ret*a%M;
        b>>=1;
        a=a*a%M;
    }
    return ret;
}
void open()
{
//    freopen("1009.in","r",stdin);
    freopen("out.txt","w",stdout);
}
vector<vector<int> >edge;
vector<int>lim;
int n,tem;
int check(int now)
{
    if(edge[now].size()==0)return 0;
    int da=lim[now];
    vector<int> dp(da+1,1<<30);//N+1 emlements with value 1<<30
    dp[0]=0;
    for(int x:edge[now])
    {
        int a=lim[x];
        int num=check(x);
        if(num<0)return -1;
        vector<int> dp2(da+1,1<<30);
        for(int i=0;i+a<=da;i++)dp2[i+a]=min(dp2[i+a],dp[i]+num);
        for(int i=0;i+num<=da;i++)dp2[i+num]=min(dp2[i+num],dp[i]+a);
        dp.swap(dp2);
    }
    int r=*min_element(dp.begin(),dp.end());
    if(r==(1<<30))return -1;
    return r;
}
int main()
{
    scanf("%d",&n);
    edge.resize(n+1);lim.resize(n+1);
    for(int i=2;i<=n;i++)
    {
        scanf("%d",&tem);
        edge[tem].push_back(i);
    }
    for(int i=1;i<=n;i++)
        scanf("%d",&lim[i]);
    int an=check(1);
    if(an<0)
        printf("IMPOSSIBLE\n");
    else printf("POSSIBLE\n");
    return 0;
}

/*
1000000000000000000
*/


Measured memory_bytes: 5752
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

using i8 = ::std::int_least8_t;
using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u8 = ::std::uint_least8_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;
using isize = ::std::ptrdiff_t;
using usize = ::std::size_t;

class rep {
	const usize f, l;

public:
	class itr {
		friend rep;
		usize i;
		itr(usize x) noexcept : i(x) {}

	public:
		void operator++() noexcept { ++i; }
		usize operator*() const noexcept { return i; }
		bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	rep(usize first, usize last) noexcept : f(first), l(last) {}
	itr begin() const noexcept { return itr(f); }
	itr end() const noexcept { return itr(l); }
};
class revrep {
	const usize f, l;

public:
	class itr {
		friend revrep;
		usize i;
		itr(usize x) noexcept : i(x) {}

	public:
		void operator++() noexcept { --i; }
		usize operator*() const noexcept { return i; }
		bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	revrep(usize first, usize last) noexcept : f(first), l(last) {}
	itr begin() const noexcept { return itr(l - 1); }
	itr end() const noexcept { return itr(f - 1); }
};
template <class T> bool maxi(T &a, const T &b) {
	return a <= b ? (a = b, 1) : 0;
}
template <class T> bool mini(T &a, const T &b) {
	return b <= a ? (a = b, 1) : 0;
}
template <class T> bool smaxi(T &a, const T &b) {
	return b <= a ? 0 : (a = b, 1);
}
template <class T> bool smini(T &a, const T &b) {
	return a <= b ? 0 : (a = b, 1);
}
template <class T> using vec_alias = ::std::vector<T>;
template <class T> auto md_vec(usize n, const T &value) {
	return ::std::vector<T>(n, value);
}
template <class... Args> auto md_vec(usize n, Args... args) {
	return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> const T &as_const(const T &v) noexcept { return v; }

#include <algorithm>
#include <iostream>
#include <utility>
#include <array>

int main() {
	usize n, m;
	::std::cin >> n >> m;
	::std::vector<i32> x(n + 1), y(m + 1);
	::std::cin >> x.back() >> y.back();
	for (const auto i : rep(0, n))
		::std::cin >> x[i];
	for (const auto i : rep(0, m))
		::std::cin >> y[i];
	::std::sort(x.begin(), x.end());
	::std::sort(y.begin(), y.end());
	::std::cout << (x.back() < y.front() ? "No War" : "War") << ::std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MX = 1e6 + 10;;
unsigned long long fac[1000010];

#include <math.h>
#define PI 3.14159265358979323846264338327950L

long long gcd(long long a, long long b) {
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
long long lcm(long long a, long long b) {
    return (a * b) / gcd(a, b);
}
long long digits(long long m) {
    long long cnt = 0;
    while (m) {
        cnt++;
        m /= 10;
    }
    return cnt;
}

unsigned long long power(unsigned long long x, unsigned long long y){
    unsigned long long res = 1;
    x = x % MOD;

    while (y > 0) {
        // If y is odd, multiply x with result 
        if (y & 1)
            res = (res * x) % MOD;

        // y must be even now 
        y = y >> 1; // y = y/2 
        x = (x * x) % MOD;
    }
    return res;
}
unsigned long long modInverse(unsigned long long n) {
    return power(n, MOD - 2);
}


int main() {
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(b, n * a);

    return 0;
}

Measured memory_bytes: 3644
def examA():
    x, y = LI()
    ans = 0
    if x<0 and y<0:
        if x<=y:
            ans = y-x
        else:
            ans = x-y+2
    elif x<0 and 0<=y:
        if -x<=y:
            ans = y+x+1
        else:
            ans = min(-(x+y)+1,y-x)
    elif y<=0:
        ans = abs(y+x)+1
    else:
        if x<=y:
            ans = y-x
        else:
            ans = x-y+2
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18

if __name__ == '__main__':
    examA()


Measured memory_bytes: 38256
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def resolve():
    K,T=pin()
    A=tupin()
    B=[[A[i],i] for i in range(T)]
    #print(B)
    prev=None
    for k in range(K):
        B.sort(key=lambda x:x[0])
    #    print(B,"#")
        for i in reversed(range(T)):
            if B[i][0]>0 and B[i][1]!=prev:
                B[i][0]-=1
                
                prev=B[i][1]
                break
    print(sum([B[k][0] for k in range(T)]))
#%%submit!
resolve()

Measured memory_bytes: 40684
program tozan_and_gezan
  implicit none
  integer :: n, i
  integer(8) :: a, b, m, s
  logical :: same
  m = 10000000000000_8
  s = 0_8
  same = .true.
  read(*,*) n
  do i = 1, n
    read(*,*) a, b
    if (a.ne.b) same = .false.
    if (a.gt.b.and.m.gt.b) m = b
    s = s+a
  end do
  if (same) then
    write(*,'(i0)') 0
  else
    write(*,'(i0)') s-m
  end if
  stop
end program tozan_and_gezan

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextInt();
		long[] dp = new long[(int) N + 1];
		long res = 0;
		for (int i = 1; i <= N; i++) {
			long pos = i;
			dp[(int) pos] += 1;
			while (pos + i <= N) {
				pos += i;
				dp[(int) pos] += 1;
			}
			res += i * dp[i];
		}
		System.out.println(res);
	}
}

Measured memory_bytes: 115908
#include <stdio.h>

int main(){
  int n,i,minp,maxp;
  int r[200000];

  scanf("%d",&n);
  for(i=0;i<n;i++)scanf("%d",&r[i]);

  minp=r[0];
  maxp=0-r[0];
  for(i=1;i<n;i++){
    if(maxp<r[i]-minp)maxp=r[i]-minp;
    if(minp>r[i])minp=r[i];
  }

  printf("%d\n",maxp);

  return 0;
}

Measured memory_bytes: 1376
#include <bits/stdc++.h>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ass 1e18
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define debug(x) cout << #x << ": " << x << endl;
#define debug2(x,y) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<< endl;
#define debug3(x,y,z) cout<<#x<<": "<< x<< ", "<< #y<< ": "<< y<<" "<<#z<<" : "<<z<< endl;
using namespace std;
typedef long long int ll;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
	string str;
	cin>>str;
	ll cnt=0,i,arr[30];
	memset(arr,0,sizeof(arr));
	for(i=0;i<str.size();i++)
		arr[str[i]-'A']++;
	for(i=0;i<26;i++)
	{
		if(arr[i]==2)
			cnt++;
	}
	if(cnt==2)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

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

int n, A[22];

int solve(int i, int m) {
    if (m == 0) {
        return 1;
    }
    if (i >= n) {
        return 0;
    }
    int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
}

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

    int m;
    for (int i = 0; i < q; i++) {
        cin >> m;
        if (solve(0, m) == 1) {
            cout << "yes" << endl;
        }
        else {
            cout << "no" << endl;
        }
    }
}



Measured memory_bytes: 3096
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;

int n, m, m1 = 1e9, m2 = 1e9, k, ans, a[N], b[N];
int main()
{
	int i, t1, t2, t3;
	cin >> n >> m >> k;
	for (i = 1; i <= n; i++) {
		scanf ("%d", &a[i]);
		m1 = min(m1, a[i]);
	}
	for (i = 1; i <= m; i++) {
		scanf ("%d", &b[i]);
		m2 = min(m2, b[i]);
	}
	ans = m1 + m2;
	for (i = 1; i <= k; i++) {
		scanf ("%d %d %d", &t1, &t2, &t3);
		ans = min(ans, a[t1] + b[t2] - t3);
	}
	cout << ans << endl;
    return 0;
}


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

int main() {
  for (int i = 0; i < 3000; i++) {
    int x, y;
    std::cin >> x >> y;
    if (x == 0 && y == 0) {
      break;
    } else if (x > y){
      std::swap(x, y);
    }
    std::cout << x << " " << y << std::endl;
  }
  return 0;
}



Measured memory_bytes: 3072
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

def update(x):
    y = x * 105 // 100
    r = y % 1000
    y = y // 1000 * 1000
    if r: y += 1000
    return y

def main():
    n = int(input())

    x = 100000
    for _ in range(n):
        x = update(x)

    print(x)

if __name__ == "__main__": main()

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

vector<int> h;
vector<int> x;

int32_t feed(int32_t s, int32_t e)
{
	int32_t ret = 0;
	int32_t min_ind = 0;
	int32_t prev_ind;
	vector<int32_t> div_ind;

	if (s <= e) 
	{
//		for (auto itr = x.begin(); itr != x.end(); itr++)
//			cout << *itr << ' ';
//		cout << '\n';

		int min_h = h[s];
		for (int32_t ind = s; ind <= e; ind++)
		{
			if (h[ind] < min_h)
			{
				min_h = h[ind];
				min_ind = ind;
			}
		}
		ret = min_h - x[s];

		for (int32_t ind = s; ind <= e; ind++)
		{
			if (h[ind] == min_h)
			{
				div_ind.push_back(ind);
			}
			x[ind] = min_h;
		}

		prev_ind = s - 1;
		for (auto itr = div_ind.begin(); itr != div_ind.end(); itr++)
		{
			if (*itr - prev_ind > 1)
			{
				ret = ret + feed(prev_ind + 1, (*itr) - 1);
			}
			prev_ind = *itr;
		}
		if (prev_ind < e)
		{
			ret = ret + feed(prev_ind + 1, e);
		}
	}
	return(ret);
}

int main()
{
	int32_t N;
	int32_t ans = 0;

	cin >> N;

	for (int32_t i = 0; i < N; i++)
	{
		int32_t t;
		cin >> t;
		h.push_back(t);
		x.push_back(0);
	}

	ans = feed(0, N - 1);

//	for (auto itr = x.begin(); itr != x.end(); itr++)
//		cout << *itr << ' ';
//	cout << '\n';

	cout << ans;

	return(0);
}


Measured memory_bytes: 256
#coding:utf-8
t = 0
n = int(input())
x, y = 0, 0
for _ in range(n):
    t_i, x_i, y_i = map(int, input().split(' '))
    t_d = t_i - t
    x_d = abs(x_i - x)
    y_d = abs(y_i - y)
    
    t, x, y = t_i, x_i, y_i
    if x_d + y_d <= t_d and (x_d + y_d) % 2 == t_d % 2:
        continue
    else:
        print('No')
        break
else:
    print('Yes')

Measured memory_bytes: 3064
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#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>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<60);
const ld pi=acosl((ld)1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

bool solve(){
  ll ans=INF;
  ll N;cin>>N;
  vector<bool>map(N+2,false);
  ll M,X;cin>>M>>X;
  rep(i,M){
    ll a;cin>>a;
    map[a]=true;
  }

  ll now=X;
  ll num=0;
  while(now!=N){
    if(map[++now])num++;
  }
  ans=min(ans,num);

  now=X;
  num=0;
  while(now!=0){
    if(map[--now])num++;
  }
  ans=min(ans,num);

  cout<<ans<<endl;
  return false;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed;
	cout<<setprecision(30);
	return solve();
}


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

using namespace std;

typedef long long ll;

int main() {
    ll N,M; cin>>N>>M;

    vector< pair<ll, ll> > pn;

    for (int i=0;i<N;i++) {
        ll a,b; cin>>a>>b;
        pn.push_back(make_pair(a,b));
    }
    sort(pn.begin(),pn.end());

    ll ans=0;
    ll m=0;
    for (int i=0;i<N;i++) {
        ll a = pn[i].first;
        ll b = pn[i].second;

        if (m + b <= M) {
            ans += a * b;
            m += b;
        } else {
            ans += a * (M - m);
            m += (M - m);
        }

        if (m == M) break;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2420
#include <stdio.h>

int main(void)
{
	int a;
	int n;
	
	n = 0;
	while (1){
		scanf("%d", &a);
		
		if (a != 0){
			n++;
		}
		else if (a == 0){
		break;
		}
		printf("Case %d: %d\n", n, a);
	}
	
	return (0);
}

Measured memory_bytes: 600
#define TEST_MODE true

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= (int)b; --i)
#define range(i, a, b, c) for (int i = a;             \
                                   c > 0 ? i < b : i > b; \
                                   i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define int long long

#ifdef LOCAL_ENV

#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " = " << (x) << " "
#define dumpl(x) dump(x) << endl
#else
const bool test = false;
#define dump(x) 
#define dumpl(x)
#endif

#else
const bool test = false;
#define dump(x) 
#define dumpl(x)
#endif

int dx[] = { 1, 0, -1, 0 };
int dy[] = { 0, 1, 0, -1 };
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }

//.....................
const int MAX = (int)2e5 + 5;

vector<string> split(const string &str, char sep)
{
	vector<string> v;
	stringstream ss(str);
	string buffer;
	while (getline(ss, buffer, sep))
	{
		v.push_back(buffer);
	}
	return v;
}

template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
	return accumulate(begin, end, 0ll);
}

template<typename T>
T gcd(T a, T b)
{
	T c;
	while (a != 0) {
		c = a; a = b%a;  b = c;
	}
	return b;
}

template<typename T>
T bit_count(T N) {
	T cnt = 0;
	while (N) {
		if (N & 1) cnt++;
		N >>= 1;
	}
	return cnt;
}

template<typename T>
void print_vec(ostream& ostream, vector<T> a) {
	rep(i, a.size() - 1) ostream << a[i] << " ";
	ostream << a.back() << endl;
}

struct Point {
	int y, x;
	bool operator < (const Point& r) {
		if (x < r.x) return true;
		else return false;
	}
};

class Solver {
public:
	int H, W;

	bool grid_ok(int y, int x) {
		return 0 <= y && y < H && 0 <= x && x < W;
	}

	int N;

	bool ok(int v) {
		int cnt = 0;
		rep2(i, 2, N) {
			if (v % i == 0) {
				cnt += 1;
				v /= i;
			}
		}
		if (v != 1) return false;
		if (cnt != 3) return false;
		return true;
	}

	void solve() {
		cin >> N;
		int cnt = 0;
		for (int i = 3; i <= N; i += 2) {
			if (ok(i)) cnt += 1;
		}
		cout << cnt << endl;
	}

};

signed main()
{
	srand((unsigned int)time(NULL));
	cout << fixed << setprecision(20);
	auto ptr = new Solver();
	ptr->solve();
	delete ptr;
	//while (true) {
	//	if (cin.eof() == true) break;
	//	auto ptr = new Solver();
	//	ptr->solve();
	//	delete ptr;
	//}
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Convert;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        var input = ReadLine().Split(' ');
        var num = ToInt32(input[0]);
        var color = ToInt32(input[1]);
        var array = Array.ConvertAll(ReadLine().Split(' '), int.Parse);
        var c = new Dictionary<int, int>();
        for(var i = 0; i < num; i++)
        {
            if (c.ContainsKey(array[i])) c[array[i]]++;
            else c[array[i]] = 1;
        }
        var count = c.Values.OrderByDescending(v => v).ToArray();
        if (count.Length > color)
        {
            var result = 0;
            for (var i = color; i < count.Length; i++) result += count[i];
            WriteLine(result);
        }
        else
        {
            WriteLine(0);
        }
    }
}


Measured memory_bytes: 39484
from functools import reduce

prime = 1000000007


def modpow(a: int, n: int, mod: int = prime) -> int:
    res = 1
    while n > 0:
        if n & 1 != 0:
            res = res * a % mod
        a = a * a % mod
        n = n // 2
    return res


def modinv(a: int, mod: int = prime) -> int:
    return modpow(a, mod-2, mod)


def modfactrial(n: int, mod: int = prime) -> int:
    return reduce(lambda x, y: (x*y) % mod, range(1, n+1), 1)


def modcombination(n: int, r: int, mod: int = prime) -> int:
    # nCr = n!/(r!(n-r)!)
    n_fact = modfactrial(n, mod)
    r_fact = modfactrial(r, mod)
    nr_fact = modfactrial(n-r, mod)
    r_fact_inv = modinv(r_fact, mod)
    nr_fact_inv = modinv(nr_fact, mod)
    return n_fact * r_fact_inv * nr_fact_inv % mod


def abort():
    import sys
    print(0)
    sys.exit(0)


x, y = [int(x) for x in input().split()]
if (2*x-y) % 3 != 0:
    abort()
if (2*y-x) % 3 != 0:
    abort()
n = (2*y-x)//3
m = (2*x-y)//3

if n < 0 or m < 0:
    abort()
print(modcombination(n+m, n))

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;

int main() {
  int n, q;
  string s;
  cin >> n >> q >> s;
  vector<int> AC(n + 1, 0);
  for (int i = 1; i <= n; i++)
    if (s[i - 1] == 'A' && s[i] == 'C')
      AC[i] = AC[i - 1] + 1;
    else
      AC[i] = AC[i - 1];
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    cout << AC[r - 1] - AC[l - 1] << endl;
  }
}

Measured memory_bytes: 1408
let () = 
  let s = read_line () in
  print_endline @@ if
    List.exists (( = ) "keyence") @@
    List.concat @@ Array.to_list @@ Array.init (String.length s + 1) @@ fun i ->
      Array.to_list @@ Array.init (String.length s + 1) @@ fun j ->
        if j < i then "" else String.sub s 0 i ^ String.sub s j (String.length s - j)
  then "YES" else "NO"



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

int main()
{
    ll x,k,d;
    ll l;
    ll ans;
    scanf("%lld%lld%lld",&x,&k,&d);
    x = abs(x);
    l = x / d;
    if( l >= k )
    {
        ans = x - k * d;
    }
    else
    {
        ans = x % d;
        k -= l;
        if( k % 2 == 1)
        {
            ans = d - ans;
        }
    }
    printf("%lld\n",ans);
    return 0;
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){

    int x;cin>>x;

    vc<bool> p(100005,true);

    repa(i,2,p.size()){
        if(p[i]){
            if(i>=x){
                cout<<i<<"\n";
                return 0;
            }
            for(int j=2;j*i<p.size();j++){
                p[i*j]=false;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define left l
#define right r
char c[300005];
char v[1000005];
int n;
int l,r;
void qian(char x)
{
    v[--l] = x;
}
void hou(char x)
{
	v[r++]=x;
}
int main()
{
	cin>>c;
	n=strlen(c);
	int t;
	cin>>t;
	int cnt=0;
	l = 200005;
	r =200005;
	for(int i=0;i<n;++i)
	    v [ l + i] =  c [ i ],r ++ ; 
	for(int k=1;k<=t;++k)
	{
		int s;
		cin>>s;
		if(s==1) ++cnt;
		else
		{
			int q;
			cin>>q;
			char x;
			cin>>x;
			if(q==1)
			{
				if(cnt%2)
					hou(x);
				else
					qian(x);
			}
			else 
			{
				if(cnt%2)
				   qian(x);
				else
					hou(x);
			}
			++n;
		}
	}
	if(!(cnt%2))
	    for(int i=left;i<right;++i)
	       cout<<v[i];
	else
	    for(int i=right-1;i>=left;--i)
	       cout<<v[i];
	cout<<endl;
	return 0;
 } 

Measured memory_bytes: 3960
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007; // 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
/*-------------------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<int> a(n + 1), b(n); REP(i, n + 1) cin >> a[i]; REP(i, n) cin >> b[i];
  long long ans = 0;
  REP(i, n) {
    if (a[i] <= b[i]) {
      ans += a[i];
      b[i] -= a[i];
      a[i] = 0;
      if (a[i + 1] < b[i]) {
        ans += a[i + 1];
        b[i] -= a[i + 1];
        a[i + 1] = 0;
      } else {
        ans += b[i];
        a[i + 1] -= b[i];
        b[i] = 0;
      }
    } else {
      ans += b[i];
      a[i] -= b[i];
      b[i] = 0;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, l;
    cin >> n >> l;
    string s[100];
    for (int i = 0; i < n; ++i)
        cin >> s[i];
    sort(s, s + n);
    for (int i = 0; i < n; ++i)
        cout << s[i];
}


Measured memory_bytes: 256
import collections as c
ip = lambda : map(int, input().split())
# ##############
N,K = ip()
S = input()
l = []

c = 1
for i in range(1,N):
    if S[i] == S[i-1]:
        c+=1
    else:
        l.append(c)
        c=1
l.append(c)

ans = 0
K *= 2
ans += l[0]-1
for i in l[1:]:
    if K>0:
        K-=1
        ans+=i
    else:
        ans+=i-1
print(ans)

Measured memory_bytes: 5108
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    if (A <= 8 && B <= 8) {
      System.out.println("Yay!");
    } else {
      System.out.println(":(");
    }
  }
}

Measured memory_bytes: 22868
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * 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;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        C_Folia solver = new C_Folia();
        solver.solve(1, in, out);
        out.close();
    }

    static class C_Folia {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            long maxAtDepth = 1;
            long[] inner = new long[n + 1];
            long[] leaves = new long[n + 1];
            final long infinity = Long.MAX_VALUE / 2 - 100;
            for (int i = 0; i <= n; i++) {
                leaves[i] = in.nextInt();
                if (maxAtDepth < leaves[i]) {
                    out.println(-1);
                    return;
                }
                inner[i] = maxAtDepth - leaves[i];
                maxAtDepth = Math.min(infinity, 2 * inner[i]);
            }
            inner[n] = 0;
            for (int i = n - 1; i >= 0; i--) {
                inner[i] = Math.min(inner[i], inner[i + 1] + leaves[i + 1]);
            }

            long ans = 0;
            for (int i = 0; i <= n; i++) {
                ans += leaves[i];
                ans += inner[i];
            }
            out.println(ans);
        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 45504
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define forE(i,x) for(int i=head[x];i!=-1;i=ne[i])
using namespace std;
typedef long long i64;
typedef unsigned long long u64;
typedef unsigned u32;
typedef pair<int,int> pin;
#define mk(a,b) make_pair(a,b)
#define lowbit(x) ((x)&(-(x)))
#define sqr(a) ((a)*(a))
#define clr(a) (memset((a),0,sizeof(a)))
#define ls ((x)<<1)
#define rs (((x)<<1)|1)
#define mid (((l)+(r))>>1)
#define pb push_back
#define w1 first
#define w2 second
inline void read(int &x){
	x=0;int f=1;char 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();}
	x*=f;
}
inline void judge(){
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
}
/*******************************head*******************************/
const int maxn=100005;
int a[maxn],n;
inline void godie(){
	puts("No");
	exit(0);
}
int main(){
	read(n);
	rep(i,1,n)read(a[i]);
	bool flag=1;
	rep(i,1,n)flag&=a[i]==n-1;
	if(flag){
		puts("Yes");
		return 0;
	}
	int maxi=0;
	rep(i,1,n)maxi=max(maxi,a[i]);
	rep(i,1,n)
		if(maxi-a[i]>1)godie();
	int cnt=0;
	rep(i,1,n)cnt+=maxi-a[i];
	if(cnt>=maxi)godie();
	int less=max(0,2*maxi-n);
	if(less>cnt)godie();
	puts("Yes");
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int H,W,N,a,b,c;
	cin>>H>>W>>N;
	if(H>=W)
	{
		if(N%H==0)
		c=N/H;
		else
		{
			c=N/H;
			c=c+1;
		}
	}
	else
	{
		if(N%W==0)
		c=N/W;
		else
		{
			c=N/W;
			c=c+1;
		}	
	}
	cout<<c;
}


Measured memory_bytes: 256
// AOJ Volume 0 Problem 0059

#include <stdio.h>

int main(void)
{
    float xa1, ya1, xa2, ya2;
    float xb1, yb1, xb2, yb2;
	int flag;
	
	while (scanf("%f%f%f%f%f%f%f%f", 
				 &xa1, &ya1, &xa2, &ya2, 
				 &xb1, &yb1, &xb2, &yb2) != EOF){
		flag = 0;
				 
		// ·û`AªBðÜñÅ¢éÆ«
		if (xa1 <= xb1 && xb2 <= xa2 && ya1 <= yb1 && yb2 <= ya2){
			flag = 1;
		}
				 
		// ·û`BªAðÜñÅ¢éÆ«
		if (xb1 <= xa1 && xa2 <= xb2 && yb1 <= ya1 && ya2 <= yb2){
			flag = 1;
		}
				 
		// ·û`AÌ¶ÌcüÆBÌ¡ü
		if (xb1 <= xa1 && xa1 <= xb2 &&
		    (ya1 <= yb1 && yb1 <= ya2 || ya1 <= yb2 && yb2 <= ya2)){
			flag = 1;
		}
		
		// ·û`AÌEÌcüÆBÌ¡ü
		if (xb1 <= xa2 && xa2 <= xb2 &&
		    (ya1 <= yb1 && yb1 <= ya2 || ya1 <= yb2 && yb2 <= ya2)){
			flag = 1;
		}
		

		// ·û`BÌ¶ÌcüÆBÌ¡ü
		if (xa1 <= xb1 && xb1 <= xa2 &&
		    (yb1 <= ya1 && ya1 <= yb2 || yb1 <= ya2 && ya2 <= yb2)){
			flag = 1;
		}

		// ·û`BÌEÌcüÆBÌ¡ü
		if (xa1 <= xb2 && xb2 <= xa2 &&
		    (yb1 <= ya1 && ya1 <= yb2 || yb1 <= ya2 && ya2 <= yb2)){
			flag = 1;
		}
		

		if (flag == 1){
			printf("YES\n");
		}
		else {
			printf("NO\n");
		}
	}
    
    return (0);
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;

bool compare_by_b(pair<int,string> a, pair<int,string> b) {
	if (a.first != b.first) {
		return a.first > b.first;
	}
	else {
		return a.second < b.second;
	}
}

int main()
{
	string N;
	cin >> N;
	if(N[0]=='7'||N[1]=='7'||N[2]=='7'){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}

}

Measured memory_bytes: 3132
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let N = read!(usize);
    let H = read![[i64]];

    let mut t = vec![0_usize; N];

    for i in (0..N - 1).rev() {
        t[i] = if H[i] >= H[i + 1] { t[i + 1] + 1 } else { 0 };
    }

    let m = t.into_iter().max().unwrap();

    println!("{}", m)
}


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

// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define bit(n) (1LL<<(n))
// functions
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << p.first << " " << p.second; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << itr->first << ":" << itr->second; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(20);}
} fast_io_;


int main(int argc, char const* argv[])
{
  int n; cin >> n;
  string s; cin >> s;
  rep(i, sz(s)){
    s[i] = char('A' + (int(s[i] - 'A') + n) % 26);
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main() {
	char S[15];
	char T[15];

	char say_yes[] = "Yes";
	char say_no[] = "No";

	scanf("%s%s",S,T);
	for(int i=0;i<strlen(S);++i) S[i]=toupper(S[i]);
	for(int i=0;i<strlen(T);++i) T[i]=toupper(T[i]);
	if(strncmp(S,T,strlen(S)))
		printf("%s",say_no);
	else
		printf("%s",say_yes);
	return 0;
}


Measured memory_bytes: 1716
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

const int mod = 998244353;
struct mint{
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a){
        if((x+=a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a){
        if((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if(!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if(t&1) a *= *this;
        return a;
    }

    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1){
        assert(n < mod);
        fact[0] = 1;
        for(int i = 1; i <= n; i++) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for(int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;  
    }
    mint operator()(int n, int k){
        if(k < 0 || n < k) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){
    int n, m, k; cin >> n >> m >> k;
    combination c(200005);
    mint ans = 0;
    mint color = m;
    for(int i = n-1; i >= 0; --i){
        mint tmp = color;
        tmp *= c(n-1, i);
        color *= (m-1);
        if(i<=k) ans += tmp;
    }
    cout << ans << endl;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    ll h,w;cin >>h>>w;
    vector<ll>s(3);
    ll ans=INF;
    for (int a = 1; a <h; ++a) {
        s[0] = a * w;
        s[1]=(h-a)*(w/2);
        s[2]=h*w-s[0]-s[1];
        sort(all(s));
        ans=min(s[2]-s[0],ans);
    }
    for (int a = 1; a <h; ++a) {
        s[0] = a * w;
        s[1]=((h-a)/2)*w;
        s[2]=h*w-s[0]-s[1];
        sort(all(s));
        ans=min(s[2]-s[0],ans);
    }
    swap(h,w);
    for (int a = 1; a <h; ++a) {
        s[0] = a * w;
        s[1]=(h-a)*(w/2);
        s[2]=h*w-s[0]-s[1];
        sort(all(s));
        ans=min(s[2]-s[0],ans);
    }
    for (int a = 1; a <h; ++a) {
        s[0] = a * w;
        s[1]=((h-a)/2)*w;
        s[2]=h*w-s[0]-s[1];
        sort(all(s));
        ans=min(s[2]-s[0],ans);
    }
    cout <<ans <<endl;
    return 0;
}



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

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

    for (int i=0; i<=N/7; i++) {
        for (int j=0; j<=N/4; j++) {
            if (i*7 + j*4 == N) {
                cout << "Yes";
                return 0;
            }
        }
    }
    cout << "No";

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  char s[5];
  int n[4], i;
  scanf("%s", &s[0]);
  for(i=0;i<4;i++) n[i] = s[i] - '0';
  if((n[0] + n[1] + n[2] + n[3] ) == 7) printf("%d+%d+%d+%d=7\n", n[0], n[1], n[2], n[3]);
  else if((n[0] + n[1] + n[2] - n[3] ) == 7) printf("%d+%d+%d-%d=7\n", n[0], n[1], n[2], n[3]);
  else if((n[0] + n[1] - n[2] + n[3] ) == 7) printf("%d+%d-%d+%d=7\n", n[0], n[1], n[2], n[3]);
  else if((n[0] - n[1] + n[2] + n[3] ) == 7) printf("%d-%d+%d+%d=7\n", n[0], n[1], n[2], n[3]);
  else if((n[0] + n[1] - n[2] - n[3] ) == 7) printf("%d+%d-%d-%d=7\n", n[0], n[1], n[2], n[3]);
  else if((n[0] - n[1] - n[2] + n[3] ) == 7) printf("%d-%d-%d+%d=7\n", n[0], n[1], n[2], n[3]);
  else if((n[0] - n[1] + n[2] - n[3] ) == 7) printf("%d-%d+%d-%d=7\n", n[0], n[1], n[2], n[3]);
  else if((n[0] - n[1] - n[2] - n[3] ) == 7) printf("%d-%d-%d-%d=7\n", n[0], n[1], n[2], n[3]);
  else printf("error\n");
  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <string.h>
#include <iostream>
#include <stdio.h>

using namespace std;

int k;

int gcd(int a, int b) {
	return b == 0 ? a : gcd(b, a % b);
}

int main() {
	cin >> k;

	long long res = 0;
	for (int i = 1; i <= k; i++)
		for (int j = 1; j <= k; j++)
			for (int n = 1; n <= k; n++) {
				res += gcd(i, gcd(j, n));
			}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << "{"; for (typename vector<T>::const_iterator vi = v.begin(); vi != v.end(); ++vi) { if (vi != v.begin()) os << ", "; os << *vi; } os << "}"; return os; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { os << '(' << p.first << ", " << p.second << ')'; return os; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef NEAL
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif


const int MAX = 1024;

bitset<MAX> grid[MAX];

// https://en.wikipedia.org/wiki/Hadamard_matrix
void generate(int size) {
    if (size == 1) {
        grid[0][0] = 0;
        return;
    }

    generate(size / 2);

    for (int i = 0; i < size / 2; i++)
        for (int j = 0; j < size / 2; j++) {
            grid[size / 2 + i][j] = grid[i][j];
            grid[i][size / 2 + j] = grid[i][j];
            grid[size / 2 + i][size / 2 + j] = !grid[i][j];
        }
}

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

    int N, M;
    cin >> N >> M;
    int NN = (1 << N) - 1, MM = (1 << M) - 1;
    generate(max(NN, MM) + 1);

    for (int i = 0; i < NN; i++) {
        for (int j = 0; j < MM; j++) {
            int ans = (grid[i][j] ^ grid[i][j + 1] ^ grid[i + 1][j] ^ grid[i + 1][j + 1]);
            cout << ans;
        }

        cout << '\n';
    }
}


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

int main() {
  int N, K, X, Y;
  cin >> N >> K >> X >> Y;
  
  int total = 0;
  if ( N > K ){
   total = K * X;
   total += ( N - K )* Y;
  }
  else total = N * X;
  
  cout << total << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

int N;
list<ipair> reds(N), blues(N);

int solve() {
    reds.sort();
    blues.sort();

    int res = 0;
    for(auto blue_it = blues.begin(); blue_it != blues.end(); ++blue_it) {
        auto red_end = 
            lower_bound(reds.begin(), reds.end(), make_pair(blue_it->first, -INF));
        
        auto red_res = reds.end();
        for(auto red_it = reds.begin(); red_it != red_end; ++red_it) {
            if(red_it->second < blue_it->second) {
                if(red_res == reds.end() || red_res->second < red_it->second)
                    red_res = red_it;
            }
        }
        
        if(red_res != reds.end()) {
            ++res;
            reds.erase(red_res);
        }
    }
    return res;
}

int main(int argc, char **argv) {
    cin >> N;

    ipair tmp;
    for(int i = 0; i < N; ++i) {
        cin >> tmp.first >> tmp.second;
        reds.push_back(tmp);
    }

    for(int i = 0; i < N; ++i) {
        cin >> tmp.first >> tmp.second;
        blues.push_back(tmp);
    }

    cout << solve() << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int maN = 1e6+5;

int main() {
   string s;
   cin >> s;
   ll sum = 0;
   for(int i = 0; i < s.length(); ++i)
   {
       sum += s[i]-'0';
   }
   
   if(sum%9 == 0)
   {
       cout << "Yes";
   }
   else
        cout << "No";
    
	return 0;
}


Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define For(i,n) for(int i=0;i<n;i++)
#define ff first
#define ss second
#define mem(a,b) memset(a,b,sizeof(a))
#define int long long
#define ld long double
int power_mod(int num,int g)
{
    if(g==0)return 1;
    if(g%2==1)return (num*power_mod((num*num)%mod,g/2))%mod;
    return power_mod((num*num)%mod,g/2);
}
int power(int num,int g)
{
    if(g==0)return 1;
    if(g%2==1)return (num*power((num*num),g/2));
    return power((num*num),g/2);
}
void solve(int x,vector<char> vec,char ch) {
    if(x==0){
        For(i,vec.size())cout<<vec[i];cout<<endl;return;
    }
    if(vec.empty()) {
        vec.pb('a');
        solve(x-1,vec,'a');
        return;
    }
    int l=vec.size();
    for(char i='a';i<=ch+1;i++) {
        vec.pb(i);
        solve(x-1,vec,max(ch,i));
        vec.pop_back();
    }
}
int32_t main()
{
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    

    int x=4;
    cin>>x;
    vector<char> vec;
    solve(x,vec,'a');
    return 0;
}

Measured memory_bytes: 1536