akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(void){
    int a,b,c,d,e,f,g,h,S,T;
    cin >> a >> b >> c >> d; 
    cin >> e >> f >> g >> h;
    
    S = a+b+c+d;
    T = e+f+g+h;
    if(S < T){
        cout << T;
    }
    else if(S > T){
        cout << S;
    }
    else if(S == T){
        cout << S;
    }
    cout << endl;
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
#include<math.h>
#include<algorithm> 
#define rep(i,n) for (int i = 0; i < (n) ; ++i)
using namespace std;
using ll = long long ;
using P = pair<int, int> ;
#define PI 3.14159265358979323846264338327950
#define INF 1e18
#define mod 1000000007

int r, p, s; 
int c (char x){
    if(x == 'r') return p ;
    if(x == 's') return r ;
    if(x == 'p') return s ;
}
char f (char x){
    if(x == 'r') return 'p' ;
    if(x == 's') return 'r' ;
    if(x == 'p') return 's' ;
}
char find(char x, char y){
    if((x == 'r' && y == 's') ||(x == 's' && y == 'r')) return 'p' ;
    if((x == 'p' && y == 's') ||(x == 's' && y == 'p')) return 'r' ;
    if((x == 'r' && y == 'p') ||(x == 'p' && y == 'r')) return 's' ;

}
int main() {
    int n, k ; 
    cin >> n >> k ;
    cin >> r >> s >> p ;
    string t ;
    cin >> t ; 
    ll ans = 0 ;
    vector<char> vec(n) ;
    rep(i, n){
        if(i - k >= 0  && f(t[i]) == vec[i - k]){
            if(i + k > n || f(t[i + k]) == vec[i - k]) vec[i] = t[i] ;
            else {
                vec[i] = find(f(t[i + k]), vec[i - k]) ; 
            }
        }
        else{
            vec[i] = f(t[i]) ;
            ans += c(t[i]) ;
        }
    }
    cout << ans << endl ;
}  

Measured memory_bytes: 3860
N, x = map(int, input().split())
bs = list(map(int, input().split()))
dp = bs[:]
ans = sum(bs)
for k in range(1, N):
    dp = [min(dp[i], bs[i-k]) for i in range(N)]
    ans = min(ans, sum(dp)+x*k)
print(ans)

Measured memory_bytes: 3316
import math

N = int(input())
if N == 0:
    print(0)
    exit()

bits = []
for keta in range(5 + int(math.log2(abs(N)))):
    if N % 2 == 1:
        bits.append("1")
        N -= 1
    else:
        bits.append("0")
    N //= -2
    if N == 0:
        break

print("".join(bits[::-1]))

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

int main(){

    int A, B;
    cin >> A >> B;
    
    if(A > 8 || B > 8){
        cout << ":(" << endl;
    }else{
        cout << "Yay!" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
ll f[1<<6][355],ans;
int n,C,L[15];
int main(){
	cin>>n>>C;
	for(int i=0;i<n;++i)cin>>L[i];
	sort(L,L+n);
	int tot=0,t=(1<<n-1)-1;
//	do{
//        ans+=f[(1<<n-1)-1][n*C];
//    }while(next_permutation(L,L+n-1));
	do{
		++tot;memset(f,0,sizeof(f));
//		f[0][n*L[n-1]]=1;
//		for(int i=1;i<=n*C;++i){
//			if(i%n){
//				int id=i%n-1,t=min(i+L[id]*n,n*C);
//				for(int s=0;s<=t;++s){
//					if(!(s>>id&1)){
//						for(int k=i;k<=n*C;++k){
//							f[s|(1<<id)][max(t,k)]+=f[s][k];
//						}
//					}
//				}
//			}
//		}
//        ++tot;
//        memset(f,0,sizeof f);
        f[0][n*L[n-1]]=1; 
        for(int i=1;i<=n*C;++i)if(i%n){
            const int id=i%n-1,t=min(i+L[id]*n,n*C);
            for(int S=0;S<1<<n-1;++S)
            if(!(S>>id&1))
            for(int k=i;k<=n*C;++k)
            f[S|1<<id][max(k,t)]+=f[S][k];
        }
		ans+=f[t][n*C];
	}while(next_permutation(L,L+n-1));
	printf("%.16lf\n",1.0*ans/tot/pow(C,n-1));
	return 0;
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 100000000001
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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


int main()
{
    ull x, h = 0;
    cin >> x;
    h += x / 500 * 1000;
    x -= (x / 500) * 500;
    h += x / 5 * 5;
    cout << h << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace Five_Transportations
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int c = int.Parse(Console.ReadLine());
            int d = int.Parse(Console.ReadLine());
            int e = int.Parse(Console.ReadLine());
            int k = int.Parse(Console.ReadLine());

            var inputs = new List<int> { a, b, c, d, e };
            var flg = false;
            for (int i = 0; i < 5; i++)
            {
                for (int j = i + 1; j < 5; j++)
                {
                    if ((inputs[j] - inputs[i]) > k)
                    {
                        flg = true;
                        break;
                    }
                }
            }
            Console.WriteLine(flg ? ":(" : "Yay!");
        }
    }
}


Measured memory_bytes: 11092
#include<stdio.h>

double a;
double sequence(int);

int main(void){
  double sum;

  while((scanf("%lf",&a))!=EOF){
    sum=0.0;
    for(int i=1;i<=10;i++){
      sum+=sequence(i);
    }
    printf("%.8f\n",sum);  
  }
  return 0;
}

double sequence(int n){
  if(n==1){return a;}
  else{
    if(n%2==0) return sequence(n-1)*2;
    else return sequence(n-1)/3;
  }
}



Measured memory_bytes: 2052
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#include <numeric>
#include <bitset>
#include <cassert>
#include <functional>

using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

int main() {
	string S;
	cin >> S;
	rep(i, S.length() - 1) {
		if (S[i] == 'A' && S[i + 1] == 'C') {
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def print_ans(N, S):
    """Test Case
    >>> print_ans(6, "abcabc")
    Yes
    >>> print_ans(6, "abcadc")
    No
    >>> print_ans(1, "z")
    No
    """
    if N % 2 != 0:
        print("No")
    else:
        if S[:N//2] == S[N//2:]:
            print("Yes")
        else:
            print("No")

if __name__ == '__main__':
    N = int(input().rstrip())
    S = input().rstrip()
    print_ans(N, S)


Measured memory_bytes: 3060
r=lambda x:p[x]>=0and r(p[x])or x
(n,m,k),*t=[map(int,t.split())for t in open(0)]
p=[-1]*-~n
f=[[]for _ in p]
for a,b in t[:m]:
  x,y=r(a),r(b)
  if x!=y:
    if x>y:x,y=y,x
    p[x]+=p[y]
    p[y]=x
  f[a]+=b,
  f[b]+=a,
a=[~len(f[i])-p[r(i)]for i in range(n+1)]
for c,d in t[m:]:
  if r(c)==r(d):
    a[c]-=1
    a[d]-=1
print(*a[1:])

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

typedef long double ld;
const int MAX_N = 1030;    // Change as necessary

ld x[MAX_N],y[MAX_N],r[MAX_N];

ld dist[MAX_N][MAX_N];
ld D[MAX_N];

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  for(int i=0;i<2;i++)
    cin >> x[i] >> y[i];
  
  int n; cin >> n;
  for(int i=0;i<n;i++)
    cin >> x[i+2] >> y[i+2] >> r[i+2];
  
  n += 2;
  
  for(int i=0;i<n;i++)
    for(int j=i;j<n;j++)
      dist[i][j] = dist[j][i] = max((ld)0.0,hypot(x[i]-x[j],y[i]-y[j]) - (r[i]+r[j]));
  
  priority_queue<pair<ld,int> > pq;
  pq.emplace(0,0);
  D[0] = 0;
  for(int i=1;i<n;i++) D[i] = -1;
  
  while(!pq.empty()){
    ld d; int idx;
    tie(d,idx) = pq.top(); pq.pop();
    d *= -1;
    if(D[idx] < d-(1e-9)) continue;
    for(int i=0;i<n;i++)
      if(i != idx && (D[i] < -0.5 || D[i] > d + dist[idx][i])){
	D[i] = d+dist[idx][i];
	pq.emplace(-D[i],i);
      }
  }
  
  cout << fixed << setprecision(10) << D[1] << endl;
  
  return 0;
}


Measured memory_bytes: 24812
//https://atcoder.jp/contests/agc033/tasks/agc033_b
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>

using namespace std;

const int N = 2e5 + 3;
int SR, SC, R, C;
string S, T;

bool check(char l, char r, int X, int lim)
{
  int n = S.size();
  int rpos = X, lpos = X;
  for (int i = 0; i < n; i++)
  {
    if (S[i] == r)
      rpos++;
    if (S[i] == l)
      lpos--;
    if (rpos > lim or lpos < 1)
      return true;
    if (T[i] == l and rpos > 1)
      rpos--;
    if (T[i] == r and lpos < lim)
      lpos++;
  }
  return rpos > lim or lpos < 1;
}

int main()
{
  int i, n, m, j, len;
  ios_base::sync_with_stdio(0);

  cin >> R >> C >> len;

  cin >> SR >> SC;

  cin >> S >> T;

  bool ans = check('L', 'R', SC, C) or check('U', 'D', SR, R);
  cout << (!ans ? "YES" : "NO");
  return 0;
}

Measured memory_bytes: 920
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int32_t main() {
	FAST
	int n;
	cin >> n;
	vector<int> vec(n - 1);
	vector<int> ori(n);
	int sum = 0;
	for(int i = 0; i < n - 1; i++)
	{
		cin >> vec[i];
	}
	ori[0] = vec[0];
	ori[1] = vec[0];

	for(int i = 1; i < n - 1; i++)
	{
		if(vec[i] >= ori[i])
		{
			ori[i + 1] = vec[i];
		}
		else
		{
			ori[i] = vec[i];
			ori[i + 1] = vec[i];
		}
	}
	
	for(int i = 0; i < n; i++) sum += ori[i];
		cout << sum << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e18
bool comp(const pair<int,int>& a,const pair<int,int>& b){
    return a.second<b.second;
}
int main(){
    ll a,b,c;
    cin>>a>>b>>c;
    cout<<min(c,b/a)<<endl;
    
}




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

// ただの辺
struct edge {
    int to;
    long long cost;
    // 引数一つの時は距離1
    edge(int t, long long c = 1) : to(t), cost(c) {}
};

int n;
vector<int> a;
vector<vector<edge>> g;
vector<int> dp;
vector<int> ans;

void dfs(int now, int from) {
    int target = lower_bound(dp.begin(), dp.end(), a[now]) - dp.begin();
    int prev = dp[target];
    dp[target] = a[now];
    ans[now] = lower_bound(dp.begin(), dp.end(), INT_MAX) - dp.begin();
    for (auto e : g[now]) {
        if (e.to == from) {
            continue;
        }
        dfs(e.to, now);
    }
    dp[target] = prev;
}

int main() {
    cin >> n;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    g.resize(n);
    for (int i = 0; i < n - 1; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dp.resize(n, INT_MAX);
    ans.resize(n);
    dfs(0, -1);
    for (auto e : ans) {
        cout << e << endl;
    }
}

Measured memory_bytes: 31072
"use strict"
function main(arg) {
    var data = arg.trim().split("\n")[0].split(" ").map(Number)
    var A = data[0]
    var B = data[1]
    var a = A / 0.08
    var b = B / 0.10
    var c = Math.floor((a + b) / 2)
    var start = (c  - 10) > 0 ? c - 10 : 0 
    var end = c  + 10
    // console.log(c)
    for (var i = start; i < end; i++) {
        var _a = Math.floor(i * 0.08)
        var _b = Math.floor(i * 0.1)
        // console.log([i,_a,_b])
        if (_a === A && _b === B) {
            console.log(i)
            return
        }
    }
    console.log(-1)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

int main() {
    string s;
    cin >> s;
    
    int zero = 0, one = 0;
    for (char c : s) {
        if (c == '0') zero++;
        if (c == '1') one++;
    }
    cout << 2 * min(zero, one) << endl;
    return 0;
}

Measured memory_bytes: 3760
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
using namespace std;
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007

int N,A,x[60];
ll dp[51][51][3010];
int main(int argc, char const *argv[]) {
  std::cin >> N >> A;
  for(int i=0; i<N; i++) std::cin >> x[i];

  dp[0][0][0]=1;

  for(int i=0; i<N; i++){
    for(int j=0; j<N; j++){
      for(int k=0; k<=3000; k++){
        dp[i+1][j][k]+=dp[i][j][k];
        if(k>=x[i]) dp[i+1][j+1][k]+=dp[i][j][k-x[i]];
      }
    }
  }

  ll ans=0;
  for(int i=1; i<=N; i++) ans+=dp[N][i][i*A];

  std::cout << ans << '\n';
  return 0;
}


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

int main(){
  char t[10][10], t_tmp[10][10];

  for(int i = 0; i < 8; i++){
    cin >> t[i];
  }

  for(int loop = 1; loop <= 3; loop++){
    cout << 90 * loop << endl;
    memcpy(t_tmp, t, sizeof(t));

    for(int i = 0; i < 8; i++){
      for(int j = 0; j < 8; j++){
	t[j][7 - i] = t_tmp[i][j];
      }
    }

    for(int i = 0; i < 8; i++){
      for(int j = 0; j < 8; j++){
	cout << t[i][j];
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 1140
import sys
table = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
for _ in range(N):
    cmd = int(input())
    for i in range(3):
        for j in range(3):
            if table[i][j] == cmd:
                table[i][j] = -1
                break
for i in range(3):
    if (table[i][0]==-1 and table[i][1]==-1 and table[i][2]==-1) or \
        (table[0][i]==-1 and table[1][i]==-1 and table[2][i]==-1):
        print("Yes")
        sys.exit()
if (table[0][0]==-1 and table[1][1]==-1 and table[2][2]==-1) or \
    (table[0][2]==-1 and table[1][1]==-1 and table[2][0]==-1):
    print("Yes")
    sys.exit()
print("No")

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;

int main(){
    int sx,sy,tx,ty;
    cin >> sx >> sy >> tx >> ty;
    rep(i,tx-sx)cout <<'R';
    rep(i,ty-sy)cout <<'U';
    rep(i,tx-sx)cout <<'L';
    rep(i,ty-sy)cout <<'D';
    
    cout << 'D';
    rep(i,tx-sx)cout <<'R';
    cout << 'R';
    cout << 'U';
    rep(i,ty-sy)cout <<'U';
    cout << 'L';
    cout << 'U';
    rep(i,tx-sx)cout <<'L';
    cout << 'L';
    cout << 'D';
    rep(i,ty-sy)cout <<'D';
    cout << 'R';
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int N, M;
	cin >> N >> M;
	int k[M];
	vector<vector<int>> s(M);
	for(int i=0;i<M;i++){
		cin >> k[i];
		vector<int> tmp(k[i]);
		for(int j=0;j<k[i];j++){
			cin >> tmp[j];
		}
		s[i] = tmp;
	}
	int p[M];
	for(int i=0;i<M;i++){
		cin >> p[i];
	}
	int cnt = 0;
	for(int t=0;t<pow(2, N);t++){
		int rs = t;
		int ns[N];
		for(int i=0;i<N;i++){
			if(rs % 2)ns[i] = 1;
			else ns[i] = 0;
			rs /= 2;
		}
		int all = 0;
		for(int i=0;i<M;i++){
			int check = 0;
			for(int j=0;j<k[i];j++){
				check += ns[s[i][j]-1];
			}
			if(check % 2 == p[i])all++;
		}
		if(all == M)cnt++;
	}
	cout << cnt << endl;
}

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

int main(){
    string s;
    cin >> s;
    int ans = 1000;
    for (int i = 0; i < s.size() - 2; i++){
        int num = (s[i] - '0')*100 + (s[i+1]-'0')*10 + (s[i+2]-'0');
        ans = min(ans,abs(num-753));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
//全部floatにすればとおるのな
//total/4mで小数点切り捨てられて答えがあわなくなるやつがあるのかな
//a(j)*4*m>=totalでも通るのかーへーとしかいえない
int main() {
	int m,n;
  	cin>>n>>m;
  	vector<int> a(110);
  	int total=0;//なんでここで異常値出てたんだ
  	for(int i=0;i<n;i++){
    	cin>>a[i];
      	total+=a[i];
    }

  
 	 int ok=0;
  
  
  	for(int j=0;j<n;j++){
      //total/4/mかなあ
      if(a[j]*4*m>=total){
        ok++;   	
      }
         	
    }
  
  	if(m>ok){
    	cout<<"No"<<endl;
    }
  
  	else{
    	cout<<"Yes"<<endl;
    }

}

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

int main()
{
  int N, x;
  cin >> N >> x;
  vector<int> a(N);
  for (auto &ai : a)
  {
    cin >> ai;
  }
  long long int cnt = 0;

  if (a[0] > x)
  {
    cnt += a[0] - x;
    a[0] = x;
  }
  for (int i = 0; i < N - 1; i++)
  {
    long long int sum = a[i] + a[i + 1];
    if (sum > x)
    {
      cnt += sum - x;
      a[i + 1] = x - a[i];
    }
  }

  cout << cnt << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#define N 200001

using namespace std;

int Max(int x, int y) {
	int max;
	if (x < y) max = y;
	else max = x;
	return max;
}

int Min(int x, int y) {
	int min;
	if (x > y) min = y;
	else min = x;
	return min;
}

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

	int minv, maxv;
	minv = A[0];
	maxv = -1000000001;
	for (int j = 1; j < n; j++) {
		maxv = Max(maxv, A[j] - minv);
		minv = Min(minv, A[j]);
	}

	int R = maxv;

	cout << R << endl;

	return 0;

}
/*
6
2
3
1
3
4
3

*/


Measured memory_bytes: 3872
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
const int maxn=705;
int G[maxn][maxn];
vi g[maxn];
int col[maxn];
bool ok=1;
int n,m;
pi dfs(int u,int c)
{
    col[u]=c;
    pi ret={0,0};
    if(c) ret.second++;
    else ret.first++;
    for(auto i:g[u])
    {
        if(col[i]!=-1&&col[i]==c)
        {
            ok=0;
            return ret;
        }
        else if(col[i]==-1)
        {
            auto cur=dfs(i,c^1);
            ret.first+=cur.first;
            ret.second+=cur.second;
        }
    }
    return ret;
}
int main()
{
    cin>>n>>m;
    for(int i=0,u,v;i<m;i++)
    {
        cin>>u>>v;
        G[u][v]=G[v][u]=1;
    }
    int cc=0;
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++) 
        {
            if(!G[i][j])
            {
                g[i].push_back(j);
                g[j].push_back(i);
                cc++;
            }
        }
    int ans;
    memset(col,-1,sizeof(col));
    vc<pi> all;
    vc<vi> dp(n+1,vi(n+1,0));
    dp[0][0]=1;
    for(int i=1;i<=n;i++)
    {
        if(col[i]==-1)
        {
            pi cur=dfs(i,0);
            if(!ok) break;
            for(int i=n;i>=0;i--)
            {
                for(int j=n;j>=0;j--)
                {
                    if(i>=cur.second&&j>=cur.first)
                        dp[i][j]|=dp[i-cur.second][j-cur.first];
                    if(i>=cur.first&&j>=cur.second)
                        dp[i][j]|=dp[i-cur.first][j-cur.second];
                }
            }
        }
    }
    if(!ok) ans=-1;
    else
    {
        int tmp=0;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=n;j++)
                if(dp[i][j]) tmp=max(tmp,i*j);
        }
        ans=m-(tmp-cc);
    }
    print(ans);
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n, m;
    ll k;
    cin >> n >> m >> k;
    ll a[n];
    rep(i, n) {
        cin >> a[i];
    }
    ll b[m];
    rep(i, m) {
        cin >> b[i];
    }
    vector<ll> sum(m + 1, 0);
    rep(i, m) {
        sum[i + 1] += sum[i] + b[i];
    }
    sum.emplace_back(LINF);
    ll now = 0;
    int ans = 0;
    rep(i, n) {
        if(k - now >= 0){
            auto itr = upper_bound(ALL(sum), k - now);
            itr--;
            ans = max(ans, (int)(itr - sum.begin()) + i);
        }
        now += a[i];
    }
    if (k - now >= 0) {
        auto itr = upper_bound(ALL(sum), k - now);
        itr--;
        ans = max(ans, (int)(itr - sum.begin()) + n);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9592
#include <bits/stdc++.h>
using namespace std;
 
static const int INF = (1<<30)-1;
 
int main()
{
	string s;
	cin >> s;
	string now;
	int ans = INF;
	for (int i = 0; i < s.size() - 2; ++i)
	{
		now = s.substr(i, 3);
		ans = min(ans, abs(stoi(now)-753));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <cstdlib>
#include <math.h>

using namespace std;

typedef long long ll;
#define rep(i, n) for(long (i) = 0; (i) < (long) (n); (i)++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,a,b) for(long i=(a);i<(b);i++)
#define rrep1(i,a,b) for(long i=(a);i<=(b);i++)
#define rrrep(i,a,b) for(long i=(a);i>=(b);i--)
#define define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define X first
#define Y second
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int> >
#define vpl vector<pair<long, long> >
#define vppl vector<pair<long, pair<long, long> > >

const int INF = 100100100;
const long LONG_INF = 2147483647;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const ll LINF = 1e18;


int pow(int x) {
	if (x == 0) {
		return 1;
	}
	else {
		return pow(x - 1) * 2;
	}
}
bool check2pair(string a, string b, string c, string d) {
    return a==b&&a!=c&&c==d;
}

int main(int argc, char const *argv[])
{
	cin.tie(0);
	ios::sync_with_stdio(false);

    string s;
    cin >> s;
    string a,b,c,d;
    a = s.substr(0,1);
    b = s.substr(1,1);
    c = s.substr(2,1);
    d = s.substr(3,1);
    if (check2pair(a,b,c,d)||check2pair(a,c,b,d)||check2pair(a,d,b,c))
    {
        cout<<"Yes";
    } else
    {
        cout<<"No";
    }
    
    
    
    
    return 0;
}


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long

int main(void)
{
    int k;
    string s;
    cin>>k>>s;
    if(s.size()<=k) cout<<s<<endl;
    else cout<<s.substr(0,k)+"..."<<endl;
    return 0;
} 

Measured memory_bytes: 3628
#include <stdio.h>
int main(void){
    int n,i,j,A[100],mini,bar=0,temp,c,min=100;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&A[i]);
    }
    c=0;
        for(j=0;j<n;j++){
            temp=A[j];
            min=100;
            for(i=j+1;i<n;i++){
                if(min>A[i]){
                    min=A[i];
                    mini=i;
                }
            }
            if(A[j]>min){
            A[j]=A[mini];
            A[mini]=temp;
            c++;
           
            }
        }
    for(i=0;i<n-1;i++){
        printf("%d ",A[i]);
    }
    printf("%d\n%d\n",A[i],c);
    return 0;
}


Measured memory_bytes: 2144
#include <iostream>

typedef long long ll;

const int ms = 100100;

int n;
ll A, B;
ll hp[ms];

bool can(ll x)
{
	ll used = 0;
	for(int i = 0; i < n; i++)
	{
		if(A * x < hp[i])
			return false;
		if(B * x >= hp[i])
			continue;
		// dmg = used * A + (x - used) * B
		// dmg = used * (A - B) + x * B;
		// (dmg - x * B) / (A - B) = used
		used += (hp[i] - (x * B) + (A - B - 1)) / (A - B);
	}
	return used <= x;
}

int main()
{
	std::cin >> n >> A >> B;
	for(int i = 0; i < n; i++)
		std::cin >> hp[i];
	int l = 0, r = 1e9 + 10;
	while(l != r)
	{
		int mid = (l + r) / 2;
		if(can(mid))
			r = mid;
		else
			l = mid + 1;
	}
	std::cout << l << '\n';
}

Measured memory_bytes: 1024
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
MOD = 10**9+7
# 各aが何回最大最小として選ばれるか考える
ans = 0

class Combination:

    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

comb = Combination(N+1)

for i in range(N):
    if i >= K-1:
        ans += (A[i] * comb(i,K-1))%MOD
        ans %= MOD


for i in range(N):
    if i <= N-K:
        ans -= (A[i] * comb(N-1-i,K-1))%MOD
        ans %= MOD
print(ans)

Measured memory_bytes: 20200
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int solve(string S, int p, int q, int t) {
	bool OK = true; for (int i = 0; i < S.size(); i++) { if (S[i] == 'G')OK = false; }
	if (OK == true)return S.size();

	int Y = (p + q) % S.size();
	string T1 = S.substr(0, Y) + S.substr(Y + 1, S.size() - Y - 1);
	int ret = 0; if (T1.size() >= 1) ret = solve(T1, Y%T1.size(), q, t);
	if (t == 0) {
		Y++; Y %= S.size();
		string T1 = S.substr(0, Y) + S.substr(Y + 1, S.size() - Y - 1);
		if (T1.size() >= 1) ret = max(ret, solve(T1, Y%T1.size(), q, 1));
	}
	return ret;
}
int main() {
	int t, n; string S; cin >> t;
	for (int i = 0; i < t; i++) {
		cin >> n >> S; n--;
		cout << solve(S, 0, n, 0) << endl;
	}
	return 0;
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
#define MOD1 1000000007
#define MOD2 1000000009
#define fi first
#define se second
typedef long long int ll;
int main() 
{
	#ifndef ONLINE_JUDGE
	freopen("G:/coding/CPP/input.txt", "r", stdin);
	freopen("G:/coding/CPP/output.txt", "w", stdout);
	#else
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	#endif
	int l,r,d;
	cin>>l>>r>>d;
	int a=0;
	while(l%d!=0) {
		l++;
	}	
	while(l<=r) {
		a++;
		l+=d;
	}
	cout<<a<<endl;

}


Measured memory_bytes: 3644
//#pragma GCC optimize ('O3')
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mp make_pair
#define f first
#define s second
#define pb push_back

const int N = 3e5 + 5;
const int M = 1e6 + 5;
const int OO = 1e9;
const int mod = 1e9 + 7;

int h,w,m,x,y,fr[N],fc[N];
map<pair<int, int>, bool> b;
set<pair<int, int> >r,c;

void init() {}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> h >> w >> m;

    while (m--) {

        cin >> x >> y;
        b[{x,y}] = 1;
        ++fr[x];
        ++fc[y];

    }

    for (int i = 1; i <= h; ++i) {
        if(fr[i]) r.emplace(fr[i],i);
    }

    for (int i = 1; i <= w; ++i) {
        if(fc[i]) c.emplace(fc[i],i);
    }

    int A = (*max_element(r.begin(),r.end())).f;
    int B = (*max_element(c.begin(),c.end())).f;

    for (auto i = r.rbegin(); i != r.rend() && (*i).f == A ; ++i) {
        for (auto j = c.rbegin(); j != c.rend() && (*j).f == B ; ++j) {
            if(!b[{(*i).s,(*j).s}]) return cout << A + B << '\n', 0;
        }
    }

    cout << A + B - 1 << "\n";

    return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

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

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<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;

ll MOD = 1e9+7;


template <typename T>
class Rerooting{
public:
	vector<vector<int>> edge;
	vector<map<int,T>> memo;
	vector<map<int,T>> sumL;
	vector<map<int,T>> sumR;

	struct Solver {
		virtual T init() const = 0;
		virtual T merge(T, T) const = 0;
		virtual T add_me(T) const = 0;
	};
	const Solver *solver;

	const T init_value;

	Rerooting(
			int N,
			const Solver *solver
	) :
		edge(N),
		memo(N),
		sumL(N),
		sumR(N),
		solver(solver),
		init_value(solver->init())
	{ }

	void add_edge(int u, int v){
		edge[u].push_back(v);
		edge[v].push_back(u);
	}

	T dfs(int n, int b = -1) {
		T ret = init_value;
		for(auto t: edge[n]) if(t != b){
			ret = solver->merge(ret, dfs(t, n));
		}
		return memo[n][b] = solver->add_me(ret);
	}

	void dfs2(int n, int b = -1) {
		// 累積を計算しておく
		T sum = init_value;
		rep(i, edge[n].size()){
			int t = edge[n][i];
			sumL[n][t] = sum;
			sum = solver->merge(sum, memo[t][n]);
		}
		sum = init_value;
		rrep(i, edge[n].size()){
			int t = edge[n][i];
			sumR[n][t] = sum;
			sum = solver->merge(sum, memo[t][n]);
		}

		// 累積から逆方向の辺を計算
		for(auto t: edge[n]) if(t != b) {
			auto ret = solver->merge(sumL[n][t], sumR[n][t]);
			memo[n][t] = solver->add_me(ret);
			dfs2(t, n);
		}
		memo[n][-1] = solver->add_me(sum);
	}

	T solve(int n){
		const int b = -1;
		if(memo[n].count(b)) return memo[n][b];

		dfs(n);
		dfs2(n);

		return memo[n][b];
	}
};

struct Solver: Rerooting<ll>::Solver {
	ll init() const override {
		return 1;
	}

	ll merge(ll a, ll b) const override {
		return a * b % MOD;
	}

	ll add_me(ll a) const override {
		return a + 1;
	}
};

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

	int N;
	cin >> N >> MOD;
	Rerooting<ll> rr(N, new Solver());
	rep(i,N-1){
		int a, b;
		cin >> a >> b;
		a--; b--;
		rr.add_edge(a, b);
	}

	rep(i,N) cout << rr.solve(i) - 1 << "\n";

	return 0;
}

Measured memory_bytes: 72576
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Hauptteil

(defun main ()
  (let* ((n (read))
         (k (read)))
    (if (<= k (ceiling n 2))
        (println "YES")
        (println "NO"))))

#-swank(main)


Measured memory_bytes: 15968
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-8
#define REP(i, m) for(long long i=0; i<m; ++i)
#define FOR(i, n, m) for(long long i=n; i<m; ++i)
#define ALL(v) v.begin(), v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef vector<ll> vl;
typedef vector<vector<ll> > vll;

int main() {
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	REP(roop,n) {
		vector<int> num(10);
		REP(i,10) cin>>num[i];
		bool d=false;
		REP(bit,(1<<10)) {
			vector<bool> used(10,false);
			ll buf=bit;
			REP(i,10) {
				if(buf%2==1) used[i]=true;
				buf/=2;
			}
			bool e=true;
			int an=0,bn=0;
			REP(i,10) {
				if(used[i]) {
					if(an>num[i]) e=false;
					an=num[i];
				} else {
					if(bn>num[i]) e=false;
					bn=num[i];
				}
			}
			d=d|e;
		}
		if(d) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}

Measured memory_bytes: 2976
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<cstring>
using namespace std;

int main(){
	int n;
	while(1){
		int i,sum=0,a=0,max=0,min=0,s=0;
		cin>>n;
		if(n==0)break;
		cin>>sum;
		max=sum;min=sum;
		for(i=1;i<n;i++){
			cin>>a;
			sum+=a;
			if(min>a)min=a;
			if(max<a)max=a;
		}
		s=(sum-max-min)/(n-2);
		cout<<s<<endl;
	}
    return 0;
}

Measured memory_bytes: 1160
#include <cstdio>
using namespace std;
#define MOD 1000000007
char s[200007];
int main(){
	register int n, n2, i, ans, cnt, pre, now;
	scanf("%d", &n);
	n2 = n * 2;
	scanf("%s", s + 1);
	if (s[1] == 'W' || s[n2] == 'W') {
		puts("0");
		return 0;
	}
	ans = cnt = 1, pre = 0;
	for (i = 2; i < n2; ++i) {
		if (s[i - 1] != s[i]) now = pre;
		else now = pre ^ 1;
		//now: 0 = [, 1 = ]
		if (now) {
			ans = 1ll * ans * cnt % MOD;
			--cnt;
		}
		else ++cnt;
		pre = now;
	}
	for (i = 2; i <= n; ++i) ans = 1ll * ans * i % MOD;
	printf("%d\n", cnt == 1 ? ans : 0);
	return 0;
}

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


vector<int> seieve_Eras(int n){
    vector<int>a(n,1);vector<int>v;
    for(int i=2;i*i<=n;i++){
        if(a[i]==1){
            for(int j=i*i;j<n;j+=i)
                 a[j]=0;
        }
    }
    for(int i=2;i<n;i++)
    if(a[i]==1)
    v.push_back(i);
    return v;
}
struct listnode{
 int val;
 listnode*  next;};
 vector<int> func( vector<int> a,vector<int>l,int sum){
      vector<int>k,val;
       for(int i=0;i<l.size();i++)
           if(l[i]==0){
            k.push_back(i);
            val.push_back(a[i]);}
   if(sum<0)
   return a;
  else {
      sort(val.rbegin(),val.rend());
      for(int i=0;i<k.size();i++)
         a[k[i]]=val[i];}
         return a;

 }
 


int32_t main(){
 int m=1000000007;
  int n;
  cin>>n;
  int cnt=0;
  vector<int>v;
  while(n--!=0){
     int a,b;
     cin>>a>>b;
     if(a==b)cnt++;
     else
     {
         v.push_back(cnt);
         cnt=0;
     }
     
  }
  v.push_back(cnt);
  sort(v.begin(),v.end());
  cnt=v[v.size()-1];
  if(cnt>=3)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
      
    
return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		int a=input.nextInt();
		
		if(a<= 599 && a>= 400)
		{
			System.out.println(8);
		}
		else if(a<= 799 && a>= 600)
		{
			System.out.println(7);
		}
		else if(a<= 999 && a>= 800)
		{
			System.out.println(6);
		}
		else if(a<= 1199 && a>= 1000)
		{
			System.out.println(5);
		}
		else if(a<= 1399 && a>= 1200)
		{
			System.out.println(4);
		}
		else if(a<= 1599 && a>= 1400)
		{
			System.out.println(3);
		}
		else if(a<= 1799 && a>= 1600)
		{
			System.out.println(2);
		}
		else if(a<= 1999 && a>= 1800)
		{
			System.out.println(1);
		}
		
	}

}

Measured memory_bytes: 35688
from collections import deque
k = int(input())

q = deque([1, 2, 3, 4, 5, 6, 7, 8, 9])
for _ in range(k):
    ans = x = q.popleft()
    x0 = x % 10
    if x0 >= 1:
        q.append(x * 10 + x0 - 1)
    q.append(x * 10 + x0)
    if x0 <= 8:
        q.append(x * 10 + x0 + 1)

print(ans)


Measured memory_bytes: 11968
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define endl '\n'
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t,m,y,z,h,w;
    cin>>h>>w;
    ll ans = LLMAX;
    for(int i=1;i<w;i++){
        x = i*h;
        y = w-i;
        ans = min(ans,max(x, max((y/2)*h, y*h - (y/2)*h)) - min(x, min((y/2)*h, y*h - (y/2)*h)));
        ans = min(ans,max(x, max((y)*(h/2), y*h - (y)*(h/2))) - min(x, min((y)*(h/2), y*h - (y)*(h/2))));
    }
    swap(h,w);
    for(int i=1;i<w;i++){
        x = i*h;
        y = w-i;
        ans = min(ans,max(x, max((y/2)*h, y*h - (y/2)*h)) - min(x, min((y/2)*h, y*h - (y/2)*h)));
        ans = min(ans,max(x, max((y)*(h/2), y*h - (y)*(h/2))) - min(x, min((y)*(h/2), y*h - (y)*(h/2))));
    }
        cout<<ans;
    
    return 0;
}

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

using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, a, b) for (int64_t i = (a); i < (b); ++i)
const int MOD = 1e9 + 7;
typedef long long ll;
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  bool tf = true;
  for (int i = 0; i < n; i++) {
    if (a[i] % 2) tf = false;
  }
  if (tf)
    cout << "second" << endl;
  else
    cout << "first" << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (b == 0) return a;
  return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool is_prime(ll n) {
  for (ll i = 2; i*i <= n; i++) {
    if (n%i == 0) return false;
  }
  return n != 1;
}
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow(x*x%mod, n/2, mod);
  if (n & 1) res = res * x % mod;
  return res;
}

int main() {
  string str;
  cin >> str;
  set <char> s;
  bool flag = 0;
  rep(i, str.size()) {
    if (s.count(str.at(i))) {
      flag = 1;
    } else {
      s.insert(str.at(i));
    }
  }
  if (flag) {
    cout << "no" << endl;
  } else {
    cout << "yes" << endl;
  }
}

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

int main(){
  int N,A[210];
  cin >> N;
  for(int i=0;i<N;i++)
    cin >> A[i];
  int ans=0;
  bool can = true;
  while(can){
    for(int i=0;i<N;i++){
      if(A[i]%2 == 1){
        can = false;
        break;
      }
      A[i] /= 2;
    }
    ans++;
  }
  cout << ans-1 << endl;
}
      
      
      
      
      
      
    

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x) cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s)
{
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}
template <class T>
inline string toString(T x)
{
    ostringstream sout;
    sout << x;
    return sout.str();
}

ll dp[101][101][301];

int main()
{
    std::ios::sync_with_stdio(false);
    int n;
    ll w, w_min;
    cin >> n >> w;
    vector<pair<ll, ll>> items;
    for (int i = 0; i < n; ++i)
    {
        ll tmp_w, tmp_v;
        cin >> tmp_w >> tmp_v;
        items.push_back(MP(tmp_w, tmp_v));
    }
    w_min = items[0].first;
    for(int i=0;i<101;++i)
    {
        for(int j=0;j<101;++j)
        {
            for(int k=0;k<301;++k)
            {
                dp[i][j][k] = -1;
            }
        }
    }
    dp[0][0][0] = 0;
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j <= i; ++j)
        {
            for (int k = 0; k <= i * 3; ++k)
            {
                if((w_min * j + k) > w) continue;
                if ((w_min * j + k + items[i].first) <= w && dp[i][j][k] != -1)
                {
                    dp[i+1][j+1][k + items[i].first - w_min] = max(
                        dp[i][j+1][k + items[i].first - w_min],
                        dp[i][j][k] + items[i].second);
                }
                dp[i+1][j][k] = max(dp[i+1][j][k], dp[i][j][k]);
                //cerr << i << " " << j+1 << " " << k + items[i].first - w_min << " = " << dp[i][j+1][k + items[i].first - w_min] << endl;
            }
        }
    }

    ll ret = -1;
    for (int j = 0; j <= n; ++j)
    {
        for(int k=0;k<=300;++k)
        {
            ret = max(ret, dp[n][j][k]);
        }
    }

    cout << ret << endl;
}

Measured memory_bytes: 24320
#include<iostream>
#include<cstdio>
#include<stack>
#include<queue>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<math.h>
using namespace std; 
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define pp(...) "\033[94m [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define dg1(x) debug() << pp(x)
#define dg2(x,y) debug() << pp(x) pp(y)
#define dg3(x,y,z) debug() << pp(x) pp(y) pp(z)
#define dg4(w,x,y,z) debug() << pp(w) pp(x) pp(y) pp(z)
#define msg(x) debug() << x
#define int long long
const int xx = 2e5;
const int MOD = 1e9 + 7;
int cnt(int l , int r , int x){
  return (r/x) - (l-1)/x;
}
int lcm(int a, int b){
  return a * (b/__gcd(a,b));
}
signed main(){
  ios::sync_with_stdio(false);cin.tie(0);

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

  int tot = b - a + 1;
  int sub = cnt(a,b,c) + cnt(a,b,d) - cnt(a,b,lcm(c,d));
  int ans = tot - sub;
  cout << ans << '\n';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=3000050;
const int mod=998244353;
int mul(int x, int y){ return (ll)x*y%mod;}
int add(int x, int y){ x+=y;return x>=mod?x-mod:x;}
int pow(int x, int k){ int ans=1;for(;k;k>>=1,x=mul(x,x)) if(k&1) ans=mul(ans,x);return ans;}
int F[N],I[N];
void Calc()
{
	F[0]=1;
	for(int i=1;i<N;i++) F[i]=mul(F[i-1],i);
	I[N-1]=pow(F[N-1],mod-2);
	for(int i=N-2;~i;i--) I[i]=mul(I[i+1],i+1);
}
int Binom(int n, int k){ return mul(F[n],mul(I[k],I[n-k]));}
int Count(int n, int z){ return Binom(n+z-1,z);}
int main()
{
	Calc();
	int n,m;
	scanf("%i %i",&n,&m);
	int sum=0;
	for(int odd=0;odd<=min(m,n);odd++) if((odd%2)==(m%2))
	{
		int ways=Binom(n,odd);
		int ans=mul(ways,Count(n,(3*m-odd)/2)),tmp;
		//printf("%i ",ans);
		tmp=mul(ways,mul(n,Count(n,(m-odd)/2)));
		ans-=tmp;
		if(ans<0) ans+=mod;
		//printf("%i ",tmp);
		tmp=mul(mul(n,Binom(n-1,odd)),Count(n-1,(m-odd)/2));
		ans=add(ans,tmp);
		//printf("%i ",tmp);
		//printf("odd:%i ans:%i\n",odd,ans);
		sum=add(sum,ans);
	}
	printf("%i\n",sum);
	return 0;
}

Measured memory_bytes: 23680
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
  int N;
  int sum=0;
  cin >> N;
  
  vector<int> l(N);
  vector<int> r(N);

  for(int i = 0; i < N; i++)
  {
    cin >> l.at(i) >> r.at(i);
    //cout << l.at(i) << endl;
    //cout << r.at(i) << endl;
    sum += (r.at(i) - l.at(i)+1);
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#define loop(i, a, b) for(i=a; i<=b; i++)
#define MOD 1000000007
#define ll long long
using namespace std;
int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int a, b;
	cin >> a >> b;
	//cout << re << endl;
	if(a>0 && b>0) cout << "Positive\n";
	else if(a<=0 && b>=0) cout << "Zero\n";
	else{
		if((b-a)%2) cout << "Positive\n";
		else cout << "Negative\n";
	}
	return 0;
}


Measured memory_bytes: 3624
void main() {
	auto ip = readAs!(int[]), N = ip[0], M = ip[1];
	auto X = readAs!(int[]);
	X.sort();
	auto arr = new int[](M-1);
	foreach(i; 0..M-1) arr[i] = abs(X[i+1] - X[i]);
	//X.writeln;
	//arr.writeln;
	arr.sort!"a > b"();
	long tmp;
	if(N >= M) {
		writeln(0);
		return;
	}
	foreach(i; arr[0..N-1]) {
		tmp += i;
	}
	//tmp.writeln;
	writeln(abs(X.reduce!max - X.reduce!min) - tmp);
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 3720
#include<stdio.h>

int main(void){

	int d,inte;

	while(scanf("%d",&d)!=EOF){
		inte=0;
		for(int i=d;i<=600-d;i+=d){
			inte=inte+(d*i*i);
		}
		printf("%d\n",inte);
	}
	


	return 0;
}

Measured memory_bytes: 1024