akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<list>
#include<list>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<algorithm>
#include<functional>
#include<deque>
#include<string.h>
#include<ctype.h>
using namespace std;

int main(){
  int cnt = 0;
  long long a, b;
  cin >> a >> b;
  for (int i = a; i <= b; i++){
    if (i/10000 == i-(i/10)*10 && i/1000-(i/10000)*10 == i/10-(i/100)*10){
      cnt++;
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>

int how_many_div_two(int n){
  int i;
  for(i = 0 ; n != 0 ; i++){
    n = n / 2;
  }
  return i;
}

int main(int argc, char *argv[]){
  int n;
  std::cin >> n;
  int max=0,num;
  for(int i = 0 ; i<=n;i++){
    int t = how_many_div_two(i);
    if(max < t){
      num = i;
      max = t;
    }
  }
  std::cout << num << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int t[10][10],sum;
int cc(int a,int b,int c,int d,int e){
  return t[t[t[t[t[0][a]][b]][c]][d]][e];
}
bool ch(int a,int b,int c,int d,int e){
  r(i,10)if(i!=a&&!cc(i,b,c,d,e))return 1;
  r(i,10)if(i!=b&&!cc(a,i,c,d,e))return 1;
  r(i,10)if(i!=c&&!cc(a,b,i,d,e))return 1;
  r(i,10)if(i!=d&&!cc(a,b,c,i,e))return 1;
  r(i,10)if(i!=e&&!cc(a,b,c,d,i))return 1;
  if(a!=b&&!cc(b,a,c,d,e))return 1;
  if(b!=c&&!cc(a,c,b,d,e))return 1;
  if(c!=d&&!cc(a,b,d,c,e))return 1;
  if(d!=e&&!cc(a,b,c,e,d))return 1;
  return 0;
}
int main(){
  r(i,10)r(j,10)cin>>t[i][j];
  r(a,10)r(b,10)r(c,10)r(d,10)
   if(ch(a,b,c,d,t[t[t[t[0][a]][b]][c]][d]))sum++;
  cout<<sum<<endl;
}

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

using namespace std;

int main(void){
  int N, H, W;
  cin >> N >> H >> W;
  int ans = 0;
  for(int i = 0; i < N; i++){
    int A, B;
    cin >> A >> B;
    if(A >= H && B >= W) ans++;
  }
  cout << ans << endl;
  return 0;
}


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


int main()
{
	int w,a,b;
	cin>>w>>a>>b;
	if(a+w<b)cout<<b-(a+w)<<endl;
	else if(b+w<a)cout<<a-(b+w)<<endl;
	else cout<<0<<endl;
	return 0;
}

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

int main() {
    string s, t;  cin >> s >> t;
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] != t[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 3600
from itertools import permutations

N, M = [int(i) for i in input().split()]
adjacent = [[0] * N for _ in range(N)]
for _ in range(M):
    a, b = [int(i) for i in input().split()]
    adjacent[a - 1][b - 1] = 1
    adjacent[b - 1][a - 1] = 1

ans = 0
for p in permutations(range(N), r=N):
    if p[0] != 0:
        continue
    for i in range(1, N):
        f, t = p[i-1:i+1]
        if adjacent[f][t] != 1:
            break
    else:
        ans += 1
print(ans)


Measured memory_bytes: 40440
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;

ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}

const ll big=1000000000;
int exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1){
        if(exp(x,y-1)==-1)return -1;
        if(x*exp(x,y-1)>big)return -1;
        return (exp(x,y-1)*x);
    }
    ll t=exp(x,y/2);
    if(t==-1||t*t>big)return -1;
    return (t*t);
}

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


ll in(ll x){
    return exp(x,big-2);
}

int half(int k,vector<int> &eat,int l,int r,bool aaa){//[l,r)
    if(aaa){
        ll j=1;
        while(j<=r-1){
            if(eat[j]>k)return half(k,eat,j/2-1,j,false);
            j*=1;
        }
        return half(k,eat,j/2-1,r,false);
    }
    if(r-l==1)return r;
    int m=(l+r)/2;
    if(eat[m]>k){
        return half(k,eat,l,m,false);
    }else{
        return half(k,eat,m,r,false);
    }
}

int find(int k,vector<int> &eat,int chi){
    if(eat[chi-1]<k)return -1;
    if(eat[0]>k)return 0;
    int s=half(k,eat,0,chi,true);
    return s;
}


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/
    
    ll n;cin >> n;
    vector<char> ans;
    while(n>0){
        if(n%26==0){
            ans.push_back('z');
            n-=26;
        }
        else ans.push_back('a'-1+n%26);
        n/=26;
    }
    for(int i=(int)ans.size()-1;i>=0;i--)cout << ans[i];
    cout << endl;
}


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

int N;
int ans;

void dfs(string s){
    long long a = stol(s);
    if(a > N) return;
    bool san=false, go=false, nana=false;
    for(auto c : s){
        if(c == '3') san = true;
        if(c == '5') go = true;
        if(c == '7') nana = true;
    }
    if(san && go && nana) ans++;

    dfs("3"+s);
    dfs("5"+s);
    dfs("7"+s);
}

int main(){
    cin >> N;
    dfs("3");
    dfs("5");
    dfs("7");
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
import itertools

# import collections
# import math
# import string
# import bisect
# import re
# import itertools
# import statistics


# bit を使ってci を管理する

def toBit(n): 
    return eval('0b' + n)

def main():

    n = int(sys.stdin.readline().rstrip())

    schedule = [toBit(''.join(str(x) for x in sys.stdin.readline().split())) for _ in range(n)]
    profit_table = [[int(x) for x in sys.stdin.readline().split()] for _ in range(n)]

    maximum_profit = -10**10
    for open_pattern in itertools.product('01', repeat=10):
        open_pattern = toBit(''.join(open_pattern))
        if open_pattern == 0:
            continue
        profit = 0
        for i in range(n):
            checked = schedule[i]
            number_of_periods = bin(checked & open_pattern).count('1')
            profit += profit_table[i][number_of_periods]
        maximum_profit = max(maximum_profit, profit)

    print(maximum_profit)

if __name__ == "__main__":
    # execute only if run as a script
    main()


Measured memory_bytes: 3064
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
const ll MOD=998244353;
int n,m;
ll f[8005],fact[8005],inv[8005];
ll A[20005],B[20005];
int limit,l,r[20005];
ll quick_pow(ll x,ll a)
{
	ll ans=1;
	while(a)
	{
		if(a&1)ans=ans*x%MOD;
		x=x*x%MOD;
		a>>=1;
	}
	return ans;
}
void NTT(ll*A,int type)
{
	for(int i=0;i<limit;i++)
	  if(i<r[i])swap(A[i],A[r[i]]);
	for(int mid=1;mid<limit;mid<<=1)
	{
		ll Wn=quick_pow(3,(MOD-1)/(mid<<1));
		for(int j=0,R=mid<<1;j<limit;j+=R)
		{
			ll w=1;
			for(int k=0;k<mid;k++,w=w*Wn%MOD)
			{
				ll x=A[j+k],y=A[j+mid+k]*w;
				A[j+k]=(x+y)%MOD;
				A[j+mid+k]=(x-y)%MOD;
			}
		}
	}
	if(type==-1)
	{
		ll inv=quick_pow(limit,MOD-2);
		for(int i=0;i<limit;i++)A[i]=A[i]*inv%MOD;
		for(int i=1;i<(limit>>1);i++)swap(A[i],A[limit-i]);
	}
}
int main()
{
	scanf("%d%d",&n,&m);
	fact[0]=1;
	for(int i=1;i<=n+2;i++)fact[i]=fact[i-1]*i%MOD;
	inv[n+2]=quick_pow(fact[n+2],MOD-2);
	for(int i=n+2;i>=1;i--)inv[i-1]=inv[i]*i%MOD;
	f[0]=1;
	limit=1,l=0;
	while(limit<16384)limit<<=1,l++;
	for(int i=0;i<limit;i++)
	  r[i]=(r[i>>1]>>1)|((i&1)<<(l-1));
	for(int i=3;i<=n+2;i++)B[i]=inv[i];
	NTT(B,1);
	for(int t=1;t<=m;t++)
	{
		for(int i=0;i<n;i++)A[i]=f[i];
		for(int i=n;i<limit;i++)A[i]=0;
		NTT(A,1);
		for(int i=0;i<limit;i++)A[i]=A[i]*B[i]%MOD;
		NTT(A,-1);
		for(int i=0;i<=n;i++)f[i]=(f[i]*(i*(i+1)/2+1)+A[i+2]*(i+1)*(i+2))%MOD;
	}
	ll ans=0;
	for(int i=0;i<=n;i++)
	  ans=(ans+f[i]*fact[n]%MOD*inv[n-i])%MOD;
	if(ans<0)ans+=MOD;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func solve() {
	n := getInt()
	hs := getIntSlice(n)

	ans := 0
	for {
		l, r := -1, 0
		for i, h := range hs {
			if h > 0 {
				l = i
				break
			}
		}
		if l == -1 {
			break
		}

		lowest := hs[l]
		for r = l + 1; ; r++ {
			if r == n || hs[r] == 0 {
				r--
				break
			}
			lowest = min(lowest, hs[r])
		}

		for i := l; i <= r; i++ {
			hs[i] -= lowest
		}
		ans += lowest
	}

	fmt.Fprintln(wr, ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

// -----------------------------------------

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	maxBufSize := int(1e8)
	sc.Buffer(make([]byte, 4096), maxBufSize)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() (ret int) {
	sc.Scan()
	ret, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return
}

func getIntSlice(n int) (ret []int) {
	ret = make([]int, n)
	for i := range ret {
		ret[i] = getInt()
	}
	return
}

func getString() (ret string) {
	sc.Scan()
	ret = sc.Text()
	return
}

func getRunes() (ret []rune) {
	ret = []rune(getString())
	return
}


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

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

    int x = y / 1000;
    int p[3] = {};

    p[0] = y / 10000; y -= 10000 * p[0];
    p[1] = y / 5000; y -= 5000 * p[1];
    p[2] = y / 1000; y -= 1000 * p[2];

    int m = n;
    n -= p[0] + p[1] + p[2];
    if (n < 0 || x < m) {
        cout << "-1 -1 -1" << endl;
        quick_exit(0);
    }
    for (;;) {
        if (n <= 0) break;
        if ((n >= 4 && p[1] > 0) || (p[0] == 0 && p[1] > 0)) {
            p[1]--;
            p[2] += 5;
            n -= 4;
        } else if (p[0]) {
            p[0]--;
            p[1] += 2;
            n -= 1;
        } else break;
    }
    if (n < 0) {
        cout << "-1 -1 -1" << endl;
        quick_exit(0);
    }

    cout << p[0] << ' ' << p[1] << ' ' << p[2] << endl;

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var a = Console.ReadLine();
        int[] line = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int ans = 0;
        for (int i = 1; i < line.Length - 1; i++)
        {
            var intArray = new int[] { line[i], line[i - 1], line[i + 1] };
            Array.Sort(intArray);

            if (line[i] == intArray[1]) ans++;
        }
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;
int main(){
  int x; cin >> x;
  if(x==0) puts("1");
  else puts("0");
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
const int N=200005;
using namespace std;
int n;
set<string>S;
string s;
int main(){
    cin>>n;
    for(int i=0;i<n;i++) {
        cin>>s;
        S.insert(s);
    }
    cout<<S.size();
}

Measured memory_bytes: 19228
S = input()
ans = []
cur = ''


for i in range(len(S)):
    cur += S[i]

    if len(ans) == 0:
        ans.append(cur)
        cur = ''
    else:
        if ans[len(ans)-1] != cur:
            ans.append(cur)
            cur = ''

print(len(ans))


Measured memory_bytes: 53344
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

char c[5] = {'M', 'A', 'R', 'C', 'H'};

void solve() {
	int n;
	cin >> n;
	vector<ll> nums(n);
	rep(i,n) {
		string s;
		cin >> s;
		char d = s[0];
		rep(j,5) {
			if (d == c[j]) nums[j]++;
		}
	}
	ll ans = 0;
	for (int i = 0; i < 5; i++) {
		for (int j = i + 1; j < 5; j++) {
			for (int k = j + 1; k < 5; k++) {
				ans += nums[i] * nums[j] * nums[k];
			}
		}
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 4024
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))

n,c,k = iim()
time = []
for _ in range(n):
    time.append(ii())

time.sort()

bus = 0
fst = time[0]
ans = 0
for item in time:
    if bus <= c-1 and item <= k+fst:
        bus += 1
    elif bus > c-1:
        bus = 1
        ans += 1
        fst = item
    elif item-fst > k:
        bus = 1
        ans += 1
        fst = item
    

print(ans if bus == 0 else ans+1)

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  ll N, x; cin >> N >> x;
  vector<ll> a(N); REP(i, N) cin >> a[i];
  ll ans = 0;
  if(a[0] > x) {
    ll tmp = (a[0] - x);
    a[0] = x;
    ans += tmp;
  }
  for(int i = 0; i < N - 1; ++i) {
    ll tmp = a[i] + a[i + 1];
    if(tmp > x) {
      a[i + 1] -= (tmp - x);
      ans += (tmp - x);
    }
  }
  cout << ans << endl;
}

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

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

using namespace std;

/////////////////////////////////////////////////////
#define MOD 998244353

struct llm{
    ll value=0;
    llm(const ll& val=0){this->value = (MOD + val % MOD) % MOD;}
    llm(const int& val){this->value = (MOD + val % MOD) % MOD;}
    llm(const llm& a) { llm(a.value); }
    llm inv(){ll a = 1;ll b = this->value;for(ll m=MOD-2;m>0;m/=2){if(m&1){a=a*b%MOD;}b=b*b%MOD;}return llm(a);}
    llm &operator+=(const llm &a) {this->value = (this->value + a.value) % MOD;return *this;}
    llm &operator-=(const llm &a) {this->value = (this->value - a.value + MOD) % MOD;return *this;}
    llm &operator*=(const llm &a) {this->value = (this->value * a.value) % MOD; return *this; }
    explicit operator ll() const{return (ll)value;}
    explicit operator int() const{return (int)value;}
};
llm operator+(const llm &a, const llm &b) { return llm(a.value + b.value); }
llm operator-(const llm &a, const llm &b) { return llm(a.value - b.value); }
llm operator*(const llm &a, const llm &b) { return llm(a.value * b.value); }
#define pllm pair<llm,llm>

llm Fa[5050505];
llm C(const ll& a,const ll& b){
    if(a<b||a<0||b<0)
        return 0;
    return Fa[a] * (Fa[b]* Fa[a - b]).inv();
}


ll N,M;
ll i,j,k;
llm ans;
int main(){
    scanf("%lld%lld", &N, &M);
    Fa[0] = 1;
    fornum(i,0,5040302){
        Fa[i + 1] = Fa[i] * (i + 1);
    }
    ans = C(N - 1 + M * 3, N - 1);
    //printf("%lld\n", (ll)ans);
    fornum(i,0,N+1){
        if(i>M*3)
            break;
        if ((M * 3 - i) % 2)
            continue;
        if(i<=M){
            ans -= C(N - 1, i) * N * C(N - 1 + (M - i - 2) / 2, N - 1);
            ans -= C(N - 1, i - 1) * N * C(N - 1 + (M - i) / 2, N - 1);
        }else{
            ans -= C(N, i) * C(N - 1 + (M * 3 - i) / 2, N - 1);
        }
    }
    printf("%lld", (ll)ans);
    return 0;
}

Measured memory_bytes: 39808
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii  pair<int,int>
#define vpii vector<pii>
#define vll  vector<ll>
#define vi  vector<int>
#define pb push_back
#define f  first
#define s  second

int main() {

  int a,b,c;
    cin>>a>>b>>c;

if(2*b==a+c)
  cout<<"YES";
  else
   cout<<"NO";
    

	return 0;
}

Measured memory_bytes: 256
N = int(input())
W = list(map(int,input().split()))
s = sum(W)
total = 0
min_t = s
for w in W:
    total += w
    s -= w
    t = abs(total - s)
    if t < min_t:
        min_t = t
    else:
        break
print(min_t)

Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 998244353
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
ll digitpower(ll a,ll b){//aのb乗を計算
  if(b==1){
    return a;
  }else if(b==0){
    return 1;
  }
  if(b%2==1){
    ll tmp = digitpower(a,(b-1)/2);
    tmp%=d9_7;
    tmp*=tmp;
    tmp%=d9_7;
    tmp*=a;
    return (tmp)%d9_7;
  }else{
    ll tmp = digitpower(a,(b)/2);
    tmp%=d9_7;
    tmp*=tmp;
    tmp%=d9_7;
    return (tmp)%d9_7;
  }
}
int main(void){
  ll n;
  cin>>n;
  vl d(n);
  rep(i,n)cin>>d[i];
  if(d[0]!=0){
    cout<<0;
    return 0;
  }
  rep(i,n){
    if(i!=0&&d[i]==0){
    cout<<0;
    return 0;
 
    }
  }
  sort(d.begin(),d.end());
  vl d2(n,0);
  rep(i,n){
    d2[d[i]]+=1;
  }
  ll ans=1;
  int begin=0;
  rep(i,n-1){
    if(begin==0 && d2[n-i-1]==0)continue;
    begin=1;
    ans*=digitpower(d2[n-i-2],d2[n-i-1]);
    ans%=d9_7;
  }
  cout<<ans%d9_7<<endl;
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
      int N,A[10],B[10],C[10],ans=1,kisu=1;
      cin>>N;
      for(int i=0;i<N;i++){cin>>A[i];}
      for(int i=0;i<N;i++){
        if(A[i]==1){B[i]=3;C[i]=1;}else{
        if(A[i]%2==0){B[i]=3;C[i]=2;}
        if(A[i]%2==1){B[i]=3;C[i]=1;}
        }
        }
        for(int i=0;i<N;i++){
          ans=ans*B[i];
        }
        for(int i=0;i<N;i++){
          kisu=kisu*C[i];
        }
        cout<<ans-kisu<<endl;
        return 0;
      }
      
      


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

int main(int argc, char const *argv[]) {
  ll a, b, k;
  cin >> a >> b >> k;
  if (a >= k) {
    a -= k;
  } else {
    k -= a;
    a = 0;
    if (b > k)
      b -= k;
    else
      b = 0;
  }
  cout << a << " " << b << endl;
  return 0;
}


Measured memory_bytes: 384
fun main(args:Array<String>?): Unit {
    while(true) {
        val (n, w, d) = readLine()!!.trim().split(' ').map(String::toInt)
        if (n == 0 && w == 0 && d == 0) return
        val cakes = arrayListOf(Cake(d, w))
        repeat(n) {
            val (p, s) = readLine()!!.trim().split(' ').map(String::toInt)
            val cake = cakes[p - 1]
            cakes.removeAt(p - 1)
            cakes.addAll(cake.split(s).sortedBy(Cake::area))
        }
        println(
                cakes.sortedBy(Cake::area).joinToString(" ") { it.area.toString() }
        )
    }
}

data class Cake(val height: Int, val width: Int) {
    val area: Int
        get() = height * width
    fun split(pos: Int): List<Cake> {
        val position = pos % (height * 2 + width * 2)
        return when(position){
            in 0 until width -> listOf(Cake(height, position), Cake(height, width - position))
            in width until width + height -> listOf(Cake(position - width, width), Cake(height - position + width, width))
            in width + height until width * 2 + height -> listOf(Cake(height, position - width - height), Cake(height, width * 2 + height - position))
            else -> listOf(Cake(position - 2 * width - height, width), Cake(2 * height + 2 * width - position, width))
        }
    }
}


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
#define mp make_pair
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf=vector<vector<int>>;
#define MAX 1000000007

int main()
{
    ll x;
    cin >> x;
    if(x<=6+5){
        if(x<=6){
            cout << 1 << endl;
        }else if(x<=11){
            cout << 2 << endl;
        }
    }else{
        ll ans=x/11;
        ans*=2;
        if(x%11==0){
            cout << ans << endl;
        }else if(x%11<=6){
            cout << ans+1 << endl;
        }else{
            cout << ans+2 << endl;
        }
    }
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i, a, n) for(int i = (a); i < n; i++)
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;

int N, M, S, T, C;
pair<int, pii> E[10000];
int a[1000];

int find(int i) { return a[i] == i ? i : (a[i] = find(a[i])); }
void unite(int i, int j) { a[find(i)] = find(j); }

int main(void) {
  while(cin >> N >> M, N || M) {
    REP(i, 0, M) {
      cin >> S >> T >> C;
      E[i] = pair<int, pii>(C, pii(S, T));
    }

    sort(E, E + M);

    vector<int> cost;
    REP(i, 0, N) a[i] = i;
    REP(i, 0, M) {
      S = E[i].se.fi;
      T = E[i].se.se;
      C = E[i].fi;
      if(find(S) != find(T)) {
        unite(S, T);
        cost.push_back(C);
      }
    }

    cout << cost[cost.size() / 2] << endl;
  }

  return 0;
}

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

lli x, k, d;

int main(void){
    cin >> x >> k >> d;
    if(x < 0) x=-x;
    lli v = x/d;
    if(v <= k){
        k-=v;
        x = x%d;
    }else{
        cout << x-d*k << endl;
        return 0;
    }
    if(k%2 == 0) cout << x << endl;
    else cout << abs(x-d) << endl;
    return 0;
}


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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, r, Max = -999999999, Min;
  cin >> n >> r;
  Min = r;
  for (int i = 1; i < n; i++) {
    cin >> r;
    Max = max(r - Min, Max);
    Min = min(r, Min);
  }
  cout << Max << '\n';
  return 0;
}



Measured memory_bytes: 3192
#include"bits/stdc++.h"
using namespace std;
using ll = long long;

int main() {
    ll N, M;
    cin >> N >> M;
    vector<vector<ll>> A(N, vector<ll>(M));
    for (ll i = 0; i < N; i++) {
        for (ll j = 0; j < M; j++) {
            cin >> A[i][j];
            A[i][j]--;
        }
    }

    vector<bool> ok(M, true);
    ll ans = INT_MAX;

    for (ll i = 0; i < M; i++) {
        vector<ll> selected_num(M, 0);
        for (ll j = 0; j < N; j++) {
            for (ll k = 0; k < M; k++) {
                if (ok[A[j][k]]) {
                    selected_num[A[j][k]]++;
                    break;
                }
            }
        }

        ll num = 0, max_num = 0, max_index = -1;
        for (ll j = 0; j < M; j++) {
            if (selected_num[j] > 0) {
                num++;
                if (selected_num[j] > max_num) {
                    max_num = selected_num[j];
                    max_index = j;
                }
            }
        }

        ans = min(ans, max_num);

        ok[max_index] = false;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
N=int(input())
S=[input() for _ in range(N)]
AB=sum(s.count("AB") for s in S)
EA=sum(s.endswith("A") for s in S)
SB=sum(s.startswith("B") for s in S)
EASB=sum(s.endswith("A") and s.startswith("B") for s in S)
K=min(EA,SB)-(EA==SB==EASB!=0)
print(AB+K)

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

void solve() {
    int N; cin >> N;
    string S; cin >> S;
    vector<int> left(10), right(10);
    for(int i = 0; i < N; ++i) {
        int n = S[i] - '0';
        right[n]++;
    }
    int n = S[0] - '0';
    right[n]--;
    left[n]++;
    set<string> st;
    for(int i = 1; i < N - 1; ++i) {
        int n = S[i] - '0';
        right[n]--;
        for(int l = 0; l < 10; ++l) {
            for(int r = 0; r < 10; ++r) {
                if(left[l] && right[r]) {
                    string s = to_string(l) + S[i] + to_string(r);
                    st.insert(s);
                }
            }
        }
        left[n]++;
    }
    cout << st.size() << '\n';
    cout << "\n";
}

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


Measured memory_bytes: 384
# include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
typedef long long ll;
int n,k;    
int arr[1005],ans;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>k;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
    }
    sort(arr+1,arr+n+1);
    for(int i=1;i<=k;i++){
        ans+=arr[i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3664
#include<bits/stdc++.h>
using namespace std;
namespace Flandle_Scarlet
{
    #define int long long
    #define N 200100
    class SegmentTree
    {
        public:
            struct node
            {
                int l,r;
                int x;
            }tree[N<<2];
            #define ls index<<1
            #define rs index<<1|1

            #define L tree[index].l
            #define R tree[index].r
            #define X tree[index].x

            #define lL tree[ls].l
            #define lR tree[ls].r
            #define lX tree[ls].x

            #define rL tree[rs].l
            #define rR tree[rs].r
            #define rX tree[rs].x
            void Update(int index)
            {
                X=min(lX,rX);
            }
            void BuildTree(int l,int r,int index)
            {
                L=l,R=r,X=0x3f3f3f3f3f3f3f3fll;
                if (l==r) return;
                int mid=(l+r)>>1;
                BuildTree(l,mid,ls);
                BuildTree(mid+1,r,rs);
                Update(index);
            }
            void Add(int pos,int x,int index)
            {
                if (pos<L or R<pos) return;
                if (L==R)
                {
                    X=x;
                    return;
                }
                Add(pos,x,ls);
                Add(pos,x,rs);
                Update(index);
            }
            int Query(int l,int r,int index)
            {
                if (l>R or L>r) return 0x3f3f3f3f3f3f3f3fll;
                if (l<=L and R<=r) return X;
                return min(Query(l,r,ls),Query(l,r,rs));
            }
    }T[2];int pos=0;

    int n,q;int a,b;
    int Q[N];
    void R1(int &x)
    {
        x=0;char c=getchar();int f=1;
        while(c<'0' or c>'9') f=(c=='-')?-1:1,c=getchar();
        while(c>='0' and c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
        x=(f==1)?x:-x;
    }
    void Input()
    {
        R1(n),R1(q);
        R1(a),R1(b);
        for(int i=1;i<=q;++i) R1(Q[i]);
    }

    int sum[N];//prefix sum of delta(Q)
    int dp[N];
    int calc(int a,int b)
    {
        Q[0]=a;
        for(int i=1;i<=q;++i)
        {
            sum[i]=sum[i-1]+abs(Q[i]-Q[i-1]);
        }
        dp[1]=abs(b-Q[1]);
        T[0].BuildTree(1,n,1);
        T[1].BuildTree(1,n,1);
        T[0].Add(Q[0],dp[1]-sum[1]-Q[0],1);
        T[1].Add(Q[0],dp[1]-sum[1]+Q[0],1);
        for(int i=2;i<=q;++i)
        {
            dp[i]=T[0].Query(1,Q[i],1)+Q[i]+sum[i-1];
            dp[i]=min(dp[i],T[1].Query(Q[i],n,1)-Q[i]+sum[i-1]);
            T[0].Add(Q[i-1],dp[i]-sum[i]-Q[i-1],1);
            T[1].Add(Q[i-1],dp[i]-sum[i]+Q[i-1],1);
        }
        int ans=0x3f3f3f3f3f3f3f3fll;
        for(int i=0;i<=q;++i)
        {
            ans=min(ans,dp[i]+sum[q]-sum[i]);
        }
        return ans;
    }
    void Soviet()
    {
        printf("%lld\n",min(calc(a,b),calc(b,a)));
    }
    void IsMyWife()
    {
        if (0)
        {
            freopen("","r",stdin);
            freopen("","w",stdout);
        }
        Input();
        Soviet();
    }
    #undef int //long long
};
int main()
{
    Flandle_Scarlet::IsMyWife();
    return 0;
}


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

// #define ANS  //for answer
#define CMP  //for compe
#ifdef CMP
using namespace std;
#else
#endif

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define nv(x) #x, (x)
#define ncv(x) #x, ":", (x)
#define ncvc(x) #x, ":", (x), ","
using ll = long long;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
void pPRINT(std::ostream& ost) {}
template <class T, class... U>
void pPRINT(std::ostream& ost, const T t, const U... u) {
  ost << t << " ";
  pPRINT(ost, u...);
}
template <class... T>
void PRINT(const T... t) { pPRINT(std::cout, t...); }
template <class... T>
void PRINTl(const T... t) {
  pPRINT(std::cout, t...);
  std::cout << "\n";
}
template <class T>
void PRINTa(const T* const t, const ll size) {
  REP(i, size)
  PRINT(t[i]);
  PRINTl();
}
template <class T>
void PRINTal(const T* const t, const ll size) {
  REP(i, size)
  PRINTl(i, ":", t[i]);
}
#ifndef DBG
#define DEBUG(...)
void init() {}
#else
#define DEBUG(...)                                                     \
  {                                                                    \
    PRINT("##DEBUG##", "file :", __FILE__, ", line :", __LINE__, "["); \
    PRINT(__VA_ARGS__);                                                \
    PRINTl("]");                                                       \
  }
void init() {
  DEBUG("INIT");
  cin.tie(0);
  ios::sync_with_stdio(false);
}
#endif
#ifdef ANS
#else
#endif

void solve();

int main(int argc, char* argv[]) {
  DEBUG("MAIN");
  init();
  solve();

  return 0;
}

void solve() {
  DEBUG("SOLVE START");

  ll n;
  cin >> n;
  ll a[n], b[n], c[n - 1];
  REP(i, n) {
    cin >> a[i];
    a[i]--;
  }
  REP(i, n) { cin >> b[i]; }
  REP(i, n - 1) { cin >> c[i]; }

  ll ans = 0;
  REP(i, n) {
    ans += b[a[i]];
    if (i < n - 1 && a[i + 1] == a[i] + 1) {
      ans += c[a[i]];
    }
  }
  PRINT(ans);

  return;
}

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

#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/2;
const ll MOD = 1e9+7;

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,K;cin>>N>>K;
  if(K==1){
    cout<<0<<endl;
  }else{
    cout<<N-K<<endl;
  }
  return 0;
}


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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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


ll mod_pow(ll x, ll n){
    if (n == 0) return 1;
    ll res = mod_pow(x * x %MOD, n / 2);
    if(n & 1) return res = res * x %MOD;
    return res %MOD;
}

ll comb(ll n, ll k){
    ll res = 1;
    k = min(n - k, k);
    for(ll i=n-k+1;i<=n;i++) res = (res * i) %MOD;
    for(ll i=1;i<=k;i++) res = (res * mod_pow(i, MOD - 2)) %MOD;
    return res;
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll n, a, b; cin >> n >> a >> b;
    ll ans = mod_pow(2, n);
    ans = (ans + MOD - 1) % MOD;
    ans = (ans + MOD - comb(n, a)) % MOD;
    ans = (ans + MOD - comb(n, b)) % MOD;
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Program {
  static void Main() {
    var arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int n = arr[0];
    int a = arr[1];
    int b = arr[2];
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      var t = i.ToString().Select(x => int.Parse(x.ToString())).Sum();
      if (a <= t && t <= b) {
        ans += i;
      }
    }
    Console.WriteLine(ans);
  }
}

Measured memory_bytes: 13396
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, 
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <stdio.h>
#include <math.h>
#include <iostream>
using namespace std;

int main()
{
    int H, n;
    
    int sum = 0;
    cin >> H >>n;
    for (int i = 0; i<n; i++){
        int x;
        cin >> x;
        //A.push_back(x);
        sum = sum + x;
    }
    
    if (H<=sum) cout <<"Yes"<<endl;
    else cout <<"No" <<endl;

    return 0;
}


Measured memory_bytes: 256
M=10**9+7
n,k=map(int,input().split())
d=[0]*-~k
a=0
for i in range(k,0,-1):
    t=c=0
    for j in range(i,k+1,i):
        c+=1
        t+=d[j]
    d[i]=pow(c,n,M)-t
    a=(a+i*d[i])%M
print(a)

Measured memory_bytes: 11284
#include <stdio.h>
#include<string.h>

int main(){
  int len;
  char s[100];
  int c;
  scanf("%d", &len);
  scanf("%s", s);
  int p;
  char ls[100];
  char rs[100];
  char matchs[100];
  char ts[2];
  
  p = 1;
  int lp, rp;
  int i,j;
  
  
  int maxc = 0;
  lp = 1; // ひだりの長さ
  while(lp < len){
  	c = 0;
    
    for(i = 0; i < 100; i++)
    matchs[i] = '\0';
    
    strcpy(rs, &s[lp]);
    
    for(j = 0; j < lp; j++){
      ts[0] = s[j];
      ts[1] = '\0';
    	if((strstr(rs,ts) != NULL) && (strstr(matchs, ts) == NULL)){ // 左の文字列があるとき
    
      	strcat(matchs, ts);
      	c++;
    
   		}
    
    }
    if(maxc < c)
        maxc = c;
    
  lp++;
}
 
    printf("%d\n", maxc);
  return 0;
}

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

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

  long long n, k;
  cin >> n >> k;
  long long ans = k * pow(k-1, n-1);
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
#include<stack>
#include <cmath>
#include<bits/stdc++.h>
#include<math.h>
#define cinf(n,x) for(int i=0;i<n;i++) cin >> x[i];
#define pi pair<int,int> 
using namespace std;
using ll = long long;
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; }
const int MAX = 3000;
const int MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];
void COMint(){ //前処理
    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;
    }
}
ll 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; // n! * (k!)^-1 * ((n-k)!)^-1
}
int main(){
    int a,b; cin >> a >>b;
    int ans = max(a+b,max(a-b,a*b));
    cout << ans;
}



Measured memory_bytes: 256
#include <iostream>

#define W_MAX 52
#define H_MAX 52

void dfs(int f[H_MAX][W_MAX], int y, int x);

using namespace std;

int main(void)
{
	int w,h;

	int i1,i2;
	int count;

	int f[H_MAX][W_MAX];

	while(1){
		cin >> w >> h;
		if(w==0 && h==0) break;

		for(i1=0;i1<H_MAX;i1++){
			for(i2=0;i2<W_MAX;i2++){
				f[i1][i2] = 0;
			}
		}

		for(i1=1;i1<=h;i1++){
			for(i2=1;i2<=w;i2++){
				cin >> f[i1][i2];
			}
		}

		count=0;
		for(i1=1;i1<=h;i1++){
			for(i2=1;i2<=w;i2++){
				if(f[i1][i2]==1){
					count++;
					dfs(f,i1,i2);
				}
			}
		}

		cout << count << endl;
		
	}

	return 0;
}

void dfs(int f[H_MAX][W_MAX],int y,int x)
{
	int i1,i2;

	f[y][x] = 0;
	for(i1=-1;i1<2;i1++){
		for(i2=-1;i2<2;i2++){

			if(f[y+i1][x+i2]==1) dfs(f,y+i1,x+i2);
		}
	}
	return;
}

Measured memory_bytes: 1352
n=gets.to_i
a=1<<30
x=2*a-1
while a>0
    x-=a if (x-a)*(x-a+1)/2>=n
    a>>=1
end

res=[]
x.downto(1) do |e|
    if n>=e
        res<<e
        n-=e
    end
end
puts res.sort


Measured memory_bytes: 3960
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
vector<ll> fact, ob;

ll ce(ll n, ll k) {
    if (n < k)
        return 0;
    return fact[n] * ob[k] % mod * ob[n - k] % mod;
}
int gcdex (int a, int b, int & x, int & y) {
    if (a == 0) {
        x = 0;
        y = 1;
        return b;
    }
    int x1, y1;
    int d = gcdex(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//    ll n, k;
//    cin >> n >> k;
//    vector<ll> a(n), last(n);
//    map<ll, ll> mp;
//    for (int i = 0; i < n; i++) {
//        cin >> a[i];
//        if (mp.find(a[i]) == mp.end())
//        {
//            last[i] = -1;
//        } else
//            last[i] = mp[a[i]];
//        mp[a[i]] = i;
//    }
//    vector<ll> ans;
//    ll ind = 0;
//    if (k == 1) {
//        for (int i = ind; i < n; i++) {
//            if (last[i] != -1 && ind <= last[i]){
//
//                //ans.push_back(a[i]);
//                ind = i;
//            }
//        }
//        for (int i = ind + 1; i < n; i++)
//            cout << a[i];
//    }
//    else {
//        for (int i = 0; i < n; i++)
//            if (last[i] == ind)
//                ind = i + 1;
//        for (int i = ind; i < n; i++) {
//            if (last[i] != -1 && ind <= last[i]){
//
//                //ans.push_back(a[i]);
//                ind = i;
//            }
//        }
//        for (int i = ind + 1; i < n; i++)
//            cout << a[i];
//    }

    ll s;
    cin >> s;
    if (s <= 1e9) {
        cout << "0 0 1 0 0 " << s;
        return 0;
    }
    else {
        cout << "0 0 1 ";
        cout << (ll)ceil(s / 1e9) << " " << (ll)1e9 << " " << ll(1e9 - s % ll(1e9)) % (ll)1e9;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define oo 666666666
#define ll long long
#define ld long double

int A[25][25];
ll DP[21][1<<21];
ll mod = 1e9+7;
int n;

ll solve(int man, ll mask)
{
    if(mask == (1<<n)-1)return 1;
    if(man >= n)return 0;
    if(DP[man][mask]!=-1)return DP[man][mask];

    bitset<32>M(mask);
    DP[man][mask]=0;

    for(int i=0; i<n; i++)
        if(!M[i] && A[man][i])
            {
                DP[man][mask]+=solve(man+1,mask|(1<<i));
                DP[man][mask]%=mod;
            }

    return DP[man][mask];
}

int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    memset(DP, -1, sizeof DP);
    cin>>n;
    for(int i=0; i<n; i++)
        for(int j=0; j<n; j++)
        cin>>A[i][j];

    cout<<solve(0,0);
}


Measured memory_bytes: 344320
def yoko3(x, w, h):
    s1 = x * w
    h2 = (h-x)//2
    s2 = h2 * w
    s3 = (h - h2 - x) * w

    s = {s1, s2, s3}

    return max(s) - min(s)


def yoko1tate2(x, w, h):
    s1 = x * w
    w2 = w // 2
    s2 = (h-x)*w2
    s3 = (h-x)*(w-w2)

    s = {s1, s2, s3}

    return max(s) - min(s)


def solve():
    [H, W] = [int(x) for x in input().split()]

    ans = float("inf")
    ans = min(ans, min([yoko3(x, W, H) for x in range(H)]))
    ans = min(ans, min([yoko3(x, H, W) for x in range(W)]))
    ans = min(ans, min([yoko1tate2(x, W, H) for x in range(H)]))
    ans = min(ans, min([yoko1tate2(x, H, W) for x in range(W)]))

    return ans


if __name__ == '__main__':
    print(solve())

Measured memory_bytes: 7016
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

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

int n ;
string s , t ;

inline bool ok (int n , string s , string t) {
	if (n < max(_sz(s) , _sz(t))) return 0 ;
	if (n >= _sz(s) + _sz(t)) return 1 ;
	int len = _sz(s) + _sz(t) - n ;
	return s.substr(_sz(s) - len , len) == t.substr(0 , len) ;
}

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

	cin >> n ;
	cin >> s >> t ;

	while (!ok(n , s , t)) n ++ ;

	cout << n << '\n' ;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int, int> mii;
typedef set<int> si;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define arep(i, v) for (auto i : v)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define fi first
#define se second
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline void dump(T& v) {
    irep(i, v) { cout << (*i) << ((i == --v.end()) ? '\n' : ' '); }
}
inline string getline() {
    string s;
    getline(cin, s);
    return s;
}
inline void yn(const bool b) { b ? fin("yes") : fin("no"); }
inline void Yn(const bool b) { b ? fin("Yes") : fin("No"); }
inline void YN(const bool b) { b ? fin("YES") : fin("NO"); }
struct io {
    io() {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-11;

/* --------------------   ここまでテンプレ   -------------------- */

int main() {
    
    string s,t;
    cin>>s>>t;
    int ans=INF;
    for(int i=0;i<s.size()-t.size()+1;i++){
        int c=0;
        for(int j=0;j<t.size();j++){
            if(s[i+j]!=t[j])c++;
        }
        chmin(ans,c);
    }
    fin(ans);
}

Measured memory_bytes: 3620
from collections import Counter
n = int(input())
s = [input() for _ in range(n)]
c = Counter(s)
m = 0
for v in c.values():
	m = max(m, v)
ans = []
for k, v in c.items():
	if v == m:
		ans.append(k)
ans.sort()
print(*ans, sep="\n")

Measured memory_bytes: 35952
#include <bits/stdc++.h>
#define ll long long
#define max(x,y) (x)>(y)?(x):(y)
#define min(x,y) (x)>(y)?(y):(x)
#define cls(name,x) memset(name,x,sizeof(name))
using namespace std;
const int inf=1<<28;
const int maxn=100010;
const int maxm=110;
const int maxk=100010;
const int mod=1e9+7;
const double pi=acos(-1.0);
int n;
int num[maxn*3];
ll maxleft[maxn],minright[maxn];
int main()
{
    int a,b;
    while(~scanf("%d",&n))
    {
        cls(maxleft,0);
        cls(minright,0);
        for(int i=0;i<n*3;i++)
            scanf("%d",&num[i]);
        priority_queue<int, vector<int>, greater<int> > Q1;
        priority_queue<int> Q2;
        for(int i=0;i<n;i++)
        {
            maxleft[0]+=num[i];
            Q1.push(num[i]);
            minright[n+1]+=num[n*3-1-i];
            Q2.push(num[n*3-1-i]);
        }
        for(int i=1;i<=n;i++)
        {
            Q1.push(num[n+i-1]);
            maxleft[i]=maxleft[i-1]+num[n+i-1]-Q1.top();
            Q1.pop();
 
            Q2.push(num[n*2-i]);
            minright[n+1-i]=minright[n+1-i+1]+num[n*2-i]-Q2.top();
            Q2.pop();
        }
        ll ans;
        for(int i=0;i<=n;i++)
        {
            if(i==0)
                ans=maxleft[i]-minright[i+1];
            else
                ans=max(ans,maxleft[i]-minright[i+1]);
        }
        printf("%lld\n",ans);
    }
    return 0;
}

Measured memory_bytes: 3964
import java.io.*;// 从这行开始复制，这是第一行
import java.util.*;


public class Main {

    /**
     * TODO 提交的时候一定要设置为 true
     */
    private boolean submitFlag = true;

    private void solve() {
        int ans = 0;


        System.out.println(ans);
    }


    private void run() throws IOException {
        setReader();

        //TODO 从这里开始读入题目输入
        int x = nextInt();

        for (int i = 1; i < 360; i++) {
            if ((360 * i) % x == 0) {
                System.out.println((360 * i) / x);
                return;
            }
        }


    }


//    main以及输入输出========================================================================

    public static void main(String[] args) throws IOException {
        Main solution = new Main();
        solution.run();
        solution.reader.close();
    }

    /**
     * TODO 存档时，改一下moduleName
     */
    String moduleName = "atcoder-race";

    /**
     * 注意不同题目这里路径要设一下
     *
     * @throws IOException
     */
    private void setReader() throws IOException {
        if (submitFlag) {
            reader = new BufferedReader(new InputStreamReader(System.in));
        } else {
            String projectPath = System.getProperty("user.dir");
            String modulePath = projectPath + "/" + moduleName + "/src/main/java/";
            String className = this.getClass().getPackage().getName().replace(".", "\\");
            reader = new BufferedReader(new FileReader(modulePath + className + "\\input.txt"));
        }
    }

    private BufferedReader reader;
    private StringTokenizer tokenizer;

    private int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    private long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    private double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    private String next() throws IOException {
        return nextToken();
    }

    private String nextToken() throws IOException {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
}


Measured memory_bytes: 32548
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cstdlib>

using namespace std;

int getTime(string s){
  int a=atoi(s.substr(0,2).c_str());
  int b=atoi(s.substr(3,2).c_str());
  return a*60+b;
}
int main(){
  int n;
  while(cin>>n&&n){
    map<string,int> ans;
    map<string,int> info;
    for(int i=0;i<n;i++){
      string s1,s2,s3,s4;
      cin>>s1>>s2>>s3>>s4;
      int time=getTime(s2);
      if(s3=="I")info[s4]=time;
      else{
	int diff=time-info[s4];
	if(s4=="000"){
	  for(map<string,int>::iterator it=info.begin();
	      it!=info.end();it++){
	    if(it->first=="000")continue;
	    int a=time-max(info["000"],(it->second));
	    ans[it->first]+=a;
	  }
	}
	else if(info.count("000")>0)
	  ans[s4]+=(time-max(info["000"],info[s4]));
	info.erase(s4);
      }
    }
    int res=0;
    for(map<string,int>::iterator it=ans.begin();
	it!=ans.end();it++)
      res=max(res,it->second);
    cout<<res<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 972