akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main()
{
	int n,ans=0;
	cin>>n;
	int a[n+1];
	for(int i=1;i<=n;i++) cin>>a[i];
	while(1)
	{
		bool f=false;
		for(int i=1;i<=n;i++)
		{
			if(a[i]%2==1)
			{
				f=true;
				break;
			}
			else
			{
				a[i]=a[i]/2;
			}
		}
		if(f) break;
		ans++;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;
using LL = long long;

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

    int n;
    cin >> n;

    priority_queue< double, vector< double>, greater<double> > pq;

    for (int i = 0; i < n; i ++) {
        double d;
        cin >> d;
        pq.emplace(d * 2);
    }

    for (int i = 0; i < n - 1; i ++) {
        double x = pq.top(); pq.pop();
        double y = pq.top(); pq.pop();
        pq.emplace((x + y) / 2);
    }
    
    cout << pq.top() / 2.0 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<iomanip>
#include<map>
#include<stack>
const int maxn = 1e5+10;
#define INF 1e9+10
using namespace std;
int a[maxn];
int main()
{
    int a,b,c;
    cin >> a >> b >>c;

    cout << (a+b)*c/2<<endl;
    return 0;
}


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

signed main(){
  int x;
  cin >> x;
  int happiness;
  
  happiness += 1000 * (x / 500);
  x -= (happiness / 1000) * 500;
  happiness += 5 * (x / 5);
  cout << happiness << endl;
}

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

#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
//#ifdef LOCAL
//    freopen("input.txt", "r", stdin);
//#endif
    int d, n;
    cin >> d >> n;
    if (n==100) n++;
    n *= (int)pow(100,d);
    cout << n;
}


Measured memory_bytes: 256
x = int(input())

#tmp = []
#for i in range(-100,101):
#    tmp.append(i)


a = 0
b = 0
for k in range(-500,501):
    for h in range(-500,501):
        if k**5 - h**5 == x:
            a = k
            b = h
            break

print(a, b)



Measured memory_bytes: 67824
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;
		
signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int l,r,d;
		cin>>l>>r>>d;
		--l;
		cout<<r/d - l/d;
    }
    return 0;
}


Measured memory_bytes: 3576
N = int(input())

ans = 0
last_a_num = 0
first_b_num = 0
multi_ba_num = 0
for _ in range(N):
    s = input()
    ans += s.count('AB')
    if s[-1] == 'A':
        last_a_num += 1
    if s[0] == 'B':
        first_b_num += 1
    if s[-1] == 'A' and s[0] == 'B':
        multi_ba_num += 1

connect_num = min(last_a_num, first_b_num)
if last_a_num == first_b_num and last_a_num == multi_ba_num:
    if connect_num > 0:
        connect_num -= 1
ans += connect_num

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> num(n);
  for(int i = 1; i < n; i++) {
    int x;
    cin >> x;
    num.at(x-1)++;
  }
  for(int i = 0; i < n; i++) {
    cout << num.at(i) << endl;
  }
}

Measured memory_bytes: 4052
class Room:
  def __init__(self):
    self.__count = 0
  
  @property
  def count(self):
      return self.__count

  @count.setter
  def count(self, count):
      self.__count += count

class Floor:
  def __init__(self):
    self.__rooms = [Room() for i in range(10)]
  
  def room(self, i):
    return self.__rooms[i - 1]
  
  @property
  def get(self):
    return ' ' + ' '.join([str(self.__rooms[i].count) for i in range(10)])

class Building:
  def __init__(self):
    self.__floors = [Floor() for i in range(3)]
  
  def floor(self, i):
    return self.__floors[i - 1]
  
  @property
  def get(self):
    return '\n'.join([self.__floors[i].get for i in range(3)])

class School:
  def __init__(self):
    self.__buildings = [Building() for i in range(4)]
  
  def building(self, i):
    return self.__buildings[i - 1]
  
  @property
  def get(self):
    delimiter = '\n' + '#' * 20 + '\n'
    return delimiter.join([self.__buildings[i].get for i in range(4)])

if __name__ == '__main__':
  school = School()
  for i in range(int(input())):
     b, f, r, v = map(int, input().split())
     school.building(b).floor(f).room(r).count = v
  print(school.get)



Measured memory_bytes: 5664
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    int H,W;cin>>H>>W;
    char c[H][W];
    int sum=0;
    rep(i,H)rep(j,W){
        cin>>c[i][j];
        if(c[i][j]=='#')sum++;
    }
    int h=0,w=0,cnt=0;
    while(true){
        if(h<H-1){
            if(c[h+1][w]=='#')h++,cnt++;
            else if(w<W-1){
                if(c[h][w+1]=='#')w++,cnt++;
                else break;
            }
            else break;
        }
        else if(w<W-1){
            if(c[h][w+1]=='#')w++,cnt++;
            else break;
        }
        else break;
    }
    if(sum==H+W-1 and cnt==sum-1 and h==H-1 and w==W-1)cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    char s[3];
    int count = 0;
    scanf("%s",&s);
    if (s[0] == '1'){count++;}
    if (s[1] == '1'){count++;}
    if (s[2] == '1'){count++;}
    printf("%d",count);
    return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int A, B;
    cin >> A >> B;

    int w = 100;
    vector<string> ans;

    if (B == 1) {
        ans.pb(string(w, '.'));
    } else {
        while(B > 1) {
            ans.pb(string(w, '.'));

            string tmp(w, '.');
            REP(i, w / 2) {
                if (B == 1) break;
                tmp[2*i] = '#';
                B--;
            }

            ans.pb(tmp);
            ans.pb(string(w, '.'));
        }
    }
    A--;

    if (A == 0) {
        ans.pb(string(w, '#'));
    } else {
        while(A > 0) {
            ans.pb(string(w, '#'));

            string tmp(w, '#');
            REP(i, w / 2) {
                if (A == 0) break;
                tmp[2*i] = '.';
                A--;
            }

            ans.pb(tmp);
            ans.pb(string(w, '#'));
        }
    }

    cout << ans.size() << " " << w << endl;
    REP(i, ans.size()) print(ans[i]);


}


Measured memory_bytes: 3624
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Collections;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author Silviase
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    Scanner in = new Scanner(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    ABC141DPowerfulDiscountTickets solver = new ABC141DPowerfulDiscountTickets();
    solver.solve(1, in, out);
    out.close();
  }

  static class ABC141DPowerfulDiscountTickets {

    public void solve(int testNumber, Scanner in, PrintWriter out) {
      int n = in.nextInt();
      int m = in.nextInt();
      PriorityQueue<Long> pq = new PriorityQueue<>(Collections.reverseOrder());
      for (int i = 0; i < n; i++) {
        pq.add(in.nextLong());
      }

      for (int i = 0; i < m; i++) {
        Long tmp = pq.poll();
        tmp /= 2;
        pq.add(tmp);
      }

      long res = 0;
      for (long l : pq) {
        res += l;
      }
      out.println(res);
    }

  }
}



Measured memory_bytes: 61624
//#define _GLIBCXX_DEBUG
//#include <atcoder/all>
#include <bits/stdc++.h>


using namespace std;
//using namespace atcoder;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
//using mint = modint998244353;
//using mint = modint1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
int dy[9] = {0, 1, 0, -1, 1, -1, -1, 1, 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 main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  string S,T; cin>>S>>T;
  sort(S.begin(),S.end());
  sort(T.rbegin(),T.rend());
  cout<<(S<T?"Yes":"No")<<'\n';
  
  return 0;
}


Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define mer make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;

int main(){
	//my new name is Veex
	//clock_t start1=clock();
	int n;
	cin>>n;
	char ch[n+10];
	int w[n+10],e[n+10];
	memset(w,0,sizeof(w));
	memset(e,0,sizeof(e));
	for(int i=1;i<=n;i++){
		cin>>ch[i];
		w[i]=w[i-1];
		e[i]=e[i-1];
		if(ch[i]=='W')
			w[i]++;
		else
			e[i]++;
	}
	//for(int i=1;i<=n;i++)
	//	cout<<w[i]<<' '<<e[i]<<endl;
	int minn=999999999;
	for(int i=1;i<=n;i++){
		int sum=0;
		sum+=w[i-1]-w[0];
		sum+=e[n]-e[i];
		minn=min(minn,sum);
	}
	cout<<minn;
	//((double)(clock()-start1)/CLOCKS_PER_SEC)*1000;
	return 0;
}


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

int main() {
  int n,d,x,ans=0;
  cin >> n >> d >> x;
  rep(i,n) {
    int a;
    cin >> a;
    ans += (d-1)/a;
    ans++;
  }

  cout << ans + x << endl;
  return 0;

}

Measured memory_bytes: 3556
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define     FAST            ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0);
int main()
{
    
        int n;
        cin>>n;


        cout<<n+n*n+n*n*n<<endl;
















    









    return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#define rep(i,j,n) for(i=j;i<(n);i++)

using namespace std;

int main(){
    int w1,h1,w2=0,h2=0,n,x,y,a,i,s;
    cin>>w1>>h1>>n;
    rep(i,0,n){
        cin>>x>>y>>a;
        switch (a) {
            case 1:if(w2<x){w2=x;}break;
            case 2:if(w1>x){w1=x;}break;
            case 3:if(h2<y){h2=y;}break;
            case 4:if(h1>y){h1=y;}break;
        }
        if(((w1-w2)<=0)||((h1-h2)<=0)){
            s=0;
            break;
        }
        else{
            s=(w1-w2)*(h1-h2);
        }
    }
    cout<<s<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <math.h>
int main(){
    size_t H;
    std::cin >> H;
    int num=0;
    while (H!=1){
        num+=1;
        H=H/2;
    }
    size_t answer = pow(2,num+1)-1;
    std::cout << answer << std::endl;
  return 0;
}


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

LL a,b,c,d;

LL gcd(LL x,LL y)
{
	if(x%y == 0) return y;
	return gcd(y,x%y);
}

LL lcm(LL x,LL y)
{
	return x/gcd(x,y)*y;
}

int QAQ(int x,int y)  {
	return x/y;
}

int fafafa(int x) {
	return x - QAQ(x,c) - QAQ(x,d) + QAQ(x,lcm(c,d));
}

signed main()
{
	cin >> a >> b >> c >> d;
	cout<<fafafa(b) - fafafa(a-1);
	return 0;
 } 

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Queue;
import java.util.LinkedList;
 
public class Main{
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int[][] memo= new int[33][33];
        int[][] mapt = new int[33][33];
        int[][] mapy = new int[33][33];
        int h,w,i,j,nx,ny;
        Queue<Integer> x =new LinkedList<Integer>();
        Queue<Integer> y =new LinkedList<Integer>();
        while(true){
            w = s.nextInt();
            h = s.nextInt();
            if(h+w==0)break;
            for(i=1;i<2*h;i++){
                if(i%2==1)for(j=1;j<w;j++)mapt[i/2+1][j]=1-s.nextInt();
                else for(j=1;j<=w;j++)mapy[i/2][j]=1-s.nextInt();
            }
            x.add(1);
            y.add(1);
            memo[1][1]=1;
            while(x.size()>0&&y.size()>0){
                nx = x.remove();
                ny = y.remove();
                if(mapt[nx][ny-1]==1&&memo[nx][ny-1]==0){
                    x.add(nx);
                    y.add(ny-1);
                    memo[nx][ny-1]=memo[nx][ny]+1;
                }
                if(mapt[nx][ny]==1&&memo[nx][ny+1]==0){
                    x.add(nx);
                    y.add(ny+1);
                    memo[nx][ny+1]=memo[nx][ny]+1;
                }
                if(mapy[nx-1][ny]==1&&memo[nx-1][ny]==0){
                    x.add(nx-1);
                    y.add(ny);
                    memo[nx-1][ny]=memo[nx][ny]+1;
                }
                if(mapy[nx][ny]==1&&memo[nx+1][ny]==0){
                    x.add(nx+1);
                    y.add(ny);
                    memo[nx+1][ny]=memo[nx][ny]+1;
                }
            }
            /*for(i=1;i<=h;i++){
                for(j=1;j<=w;j++){
                    System.out.print(memo[i][j]);
                }
                System.out.println();
            }*/
            System.out.println(memo[h][w]);
            for(i=1;i<2*h;i++){
                if(i%2==1)for(j=1;j<w;j++)mapt[i/2+1][j]=0;
                else for(j=1;j<=w;j++)mapy[i/2][j]=0;
            }
            for(i=0;i<=h;i++)for(j=0;j<=w;j++)memo[i][j]=0;
        }
 
    }
}



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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  while(1){
    c-=b;
    if(c<=0){
      cout << "Yes";
      return 0;
    }
    a-=d;
    if(a<=0){
      cout << "No";
      return 0;
    }
  }
}

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

int main(){

 while(1){
  int h,w;
  cin >> h >> w;
  if(h==0 && w==0) break;
 
  for (int i=1;i<=h;++i){
   for (int j=1;j<=w;++j){
    cout << "#";
   }
   cout << endl;
  }
  cout << endl;
 }
  return 0;
}

Measured memory_bytes: 3052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define agewari(a, b) ((ll)a + ((ll)b - 1)) / b
const int MOD = 1000000007;
const long long INF = 1LL << 60;
using Graph = vector<vector<ll>>;

map<string, ll> M;

int dfs(ll n, string s, map<int, int> m1)
{
    if (s.length() >= n)
        return 0;
    auto m2=m1;
    for (int i = 97; i <= 122; i++)
    {
        if (m1[i - 1] == 0)
            break;
        m2[i]++;
        char c = i;
        M[s + c]++;
        dfs(n, s + c, m2);
    }
    return 0;
}

int main()
{
    ll n;
    cin >> n;
    map<int, int> m;
    m[96]++;
    string s = "";
    dfs(n, s, m);

    for (auto m : M)
    {
        if(m.first.length()==n)cout << m.first << endl;
    }
}

Measured memory_bytes: 14696
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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 S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

std::vector<ll> divisors( ll x )
{
  std::vector<ll> ret;

  for( ll i = 1; i*i <= x; ++i ) if( x % i == 0 )
  {
    ret.emplace_back( i );

    if( i != x/i )
      ret.emplace_back( x/i );
  }

  return ret;
}

std::map<ll, ll> prime_factor( ll x )
{
  std::map<ll, ll> ret;

  for( ll i = 2; i*i <= x; ++i )
  {
    while( x%i == 0 )
    {
      ++ret[i];
      x /= i;
    }
  }

  if( x != 1 )
    ++ret[x];

  return ret;
}

ll N;
ll A[200010];
ll mp[2000010];
ll ans;

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

  rep( i, N ) {
    std::cin >> A[i];

    ++mp[A[i]];
  }

  rep( i, N ) {
    auto ds = divisors(A[i]);

    bool fl = true;

    for( auto d : ds ) {
      fl &= d==A[i] ? mp[d] == 1 : !mp[d];

      if( !fl )
        break;
    }

    if( fl )
      ++ans;
  }

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 12984
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N, M := nextInt(), nextInt()
	H := make([]int, N)
	roads := make([][]int, N)
	var ans int
	for i := range H {
		H[i] = nextInt()
	}
	for i := 0; i < M; i++ {
		A, B := nextInt()-1, nextInt()-1
		roads[A] = append(roads[A], B)
		roads[B] = append(roads[B], A)
	}
	for i := 0; i < N; i++ {
		if len(roads[i]) != 0 {
			good := true
			for _, dist := range roads[i] {
				// fmt.Println("check", H[dist], H[i])
				if H[dist] >= H[i] {
					good = false
				}
			}
			if good {
				// fmt.Println("good", i)
				ans++
			}
		} else {
			// fmt.Println("good", i)
			ans++
		}
	}
	fmt.Println(ans)
	// fmt.Println(ans, H, roads)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


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

constexpr const int mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  ll ans = 0, two_factor = 1;
  rep(i, 60) {
    ll even = 0;
    rep(j, n) if ((a[j] >> i) & 1) even++;
    ll add = (even * (n - even)) % mod * two_factor % mod;
    ans = (ans + add) % mod;
    two_factor = (two_factor * 2) % mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5560
//by achhhy
#include<bits/stdc++.h>

using namespace std;

#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,n,a) for(int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;
inline int in()
{
	char ch=getchar();
	int f=1,x=0;
	while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
	return f*x;
}

//need changing
const int inf=(1<<30);
const int N=3010;
const int M=3000;
LL n,mod;
LL S[N][N],f[N],fac[N],inv[N],mi[N*N];
LL ksm(LL a,LL b,LL p)
{
	LL ret=1;
	while(b)
	{
		if(b&1) ret=ret*a%p;
		a=a*a%p;
		b>>=1;
	}
	return ret;
}

LL C(LL a,LL b)
{
	return fac[a]*inv[b]%mod*inv[a-b]%mod;
}


int main()
{
	n=in(),mod=in();
	fac[0]=inv[0]=mi[0]=1;
	rep(i,1,M*M) mi[i]=mi[i-1]*2%mod;
	rep(i,1,M) fac[i]=fac[i-1]*i%mod;
	inv[M]=ksm(fac[M],mod-2,mod);
	per(i,M-1,1) inv[i]=inv[i+1]*(i+1)%mod;
	rep(i,0,M) S[i][0]=1;
	rep(i,1,M) rep(j,1,i) S[i][j]=(S[i-1][j-1]+S[i-1][j]*(j+1))%mod;
	rep(i,0,n)
	{
		rep(j,0,i) (f[i]+=S[i][j]*mi[(n-i)*j])%=mod;
		f[i]=f[i]*ksm(2,ksm(2,n-i,mod-1),mod)%mod;
	}
	LL ans=0;
	rep(i,0,n) (ans+=(i&1?-1ll:1ll)*C(n,i)*f[i]%mod)%=mod;
	printf("%lld\n",(ans+mod)%mod);
	return 0;
}


Measured memory_bytes: 141696
#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
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;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;
//using namespace atcoder;

void solve(){
	ll n,k;
	cin>>n>>k;
	vector<int>a(n);
	rep(i,n)cin>>a[i],a[i]--;
	vector<vector<int>>dp(60,vector<int>(n,-1));
	rep(i,n){
		dp[0][i]=a[i];
	}
	rep(i,60-1){
		rep(j,n){
			if(dp[i][j]==-1){
				dp[i+1][j]=dp[i][j];
			}
			else{
				dp[i+1][j]=dp[i][dp[i][j]];
			}
		}
	}
	int cur=0;
	rep(i,60){
		if(k&(1LL<<i)){
			cur=dp[i][cur];
		}
	}
	cout<<cur+1;
}


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 51784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
ll n = 100005;
vector<vector<ll>> tree(n,vector<ll>());
vector<vector<ll>> dp(n,vector<ll>(2,-1));
vector<bool> flg(n,false);

void dfs(ll i,ll before){
  if(flg.at(i)) return ;
  flg.at(i) = true;
  dp.at(i).at(0) = dp.at(i).at(1) = 1;
  for(auto j:tree.at(i)){
    if(j==before) continue;
    dfs(j,i);
    dp.at(i).at(0) = (dp.at(i).at(0)*dp.at(j).at(1))%MOD;
    dp.at(i).at(1) = (dp.at(i).at(1)*((dp.at(j).at(0)+dp.at(j).at(1))%MOD))%MOD;
  }
  return ;
}

 
int main() {
  cin >> n ;
  rep(i,n-1){
    ll a,b;
    cin >> a >> b;
    --a;--b;
    tree.at(a).push_back(b);
    tree.at(b).push_back(a);
  }
  dfs(0,-1);
  cout << (dp.at(0).at(0)+dp.at(0).at(1))%MOD << endl;
  //rep(i,n) cout << dp.at(i).at(0)  << " " << dp.at(i).at(1) << endl;
  
      
  return 0;
}



Measured memory_bytes: 18176
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  int n;
  std::cin >> n;
  vt<int> t(n), x(n), y(n);
  rep(i,n)  std::cin >> t[i] >> x[i] >> y[i];

  int time = 0, tr = 0;
  rep(i,n) {
    int rtime = t[i] - time;
    int to = x[i] + y[i];
    if(abs(to - tr) <= rtime){
      if((rtime - to + tr)%2 != 0){
        std::cout << "No" << '\n';
        return 0;
      }
    }
    else{
      std::cout << "No" << '\n';
      return 0;
    }
  }

  std::cout << "Yes" << '\n';
}


Measured memory_bytes: 1408
#include<stdio.h>

void BubbleSort(int* data)
{
	int i, j;
	
	for(i = 0; i < 4; ++i)
	{
		for(j = 4; j > i; --j)
		{
			if(data[j - 1] < data[j])
			{
				int temp;
				temp = data[j];
				data[j] = data[j - 1];
				data[j - 1] = temp;
			}
		}
	}
	
	return ;
}

int main(void)
{
	int i, data[5];
	
	for(i = 0; i < 5; ++i)
	{
		scanf("%d", &data[i]);
	}
	
	BubbleSort(data);
	
	for(i = 0; i < 5; ++i)
	{
		printf("%d", data[i]);
		if(i != 4)
		{
			printf(" ");
		}
		else
		{
			printf("\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int main() {
  int d, g;
  cin >> d >> g;
  vector<int> p(d), c(d);
  for (int i = 0; i < d; i++) {
    cin >> p[i] >> c[i];
  }

  int cscore, scorediff, cnt, cnttmp, pcnt, ans = inf;

  for (int bit = 0; bit < 1 << d; bit++) {
    cscore = 0, scorediff = 0, cnt = 0, cnttmp = 0, pcnt = 0;
    for (int i = 0; i < d; i++) {
      if ((bit >> i & 1) == 1) {
        cscore += p[i] * (i + 1) * 100 + c[i];
        cnt += p[i];
      }
    }
    // cerr << cscore << endl;
    if (cscore >= g) {
      ans = min(ans, cnt);
      continue;
    }
    scorediff = g - cscore;
    for (int i = d - 1; i >= 0; i--) {
      if ((bit >> i & 1) == 1) continue;
      cnttmp = (scorediff - 1) / ((i + 1) * 100) + 1;
      if (cnttmp <= p[i] - 1) {
        ans = min(ans, cnt + pcnt + cnttmp);
        // cerr << bit << " " << ans << " " << cnt << " " << pcnt << " " <<
        // cnttmp
        //      << " " << cscore << endl;
        break;
      } else {
        pcnt += p[i] - 1;
        scorediff -= (p[i] - 1) * (i + 1) * 100;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		int a[]=new int[101];
		int judge=0;
		while(in.hasNext())
		{
			int s=in.nextInt(),t=in.nextInt();
			a[s]++;
			a[t]++;
			if(a[0]==2)
			{
				for(int i=3;i<=100;i++)
				{
					if(a[i]%2==0)
						judge=1;
					else
					{
						judge=0;
						break;
					}
				}
				if(a[1]%2!=0&&a[2]%2!=0&&judge==1)
					System.out.println("OK");
				else
					System.out.println("NG");
				Arrays.fill(a, 0);
			}
		}
	}
}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


int BIT[200001];

void add(int A) {
	while (A > 0) {
		BIT[A]++;
		A -= A & -A;
	}
}

int query(int A) {
	int kotae = 0;
	while (A <= 200000) {
		kotae += BIT[A];
		A += A & -A;
	}
	return kotae;
}


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


	string S;
	cin >> S;
	int N = S.size();
	vector<int> V[26];
	rep(i, N) V[S[i] - 'a'].pb(i);
	int kisuu = 0;
	rep(i, 26) if (V[i].size() & 1) kisuu++;
	if (kisuu > 1) {
		co(-1);
		return 0;
	}
	bool used[200001] = {};
	int kazu = 0;
	ll kotae = 0;
	int atta = 0;
	rep(i, N) {
		if (kazu * 2 >= N - 1) break;
		if (!used[i]) {
			int kari = V[S[i] - 'a'].back();
			if (i == kari) {
				atta = 1;
				continue;
			}
			kotae += N - kari - 1 - query(kari) + atta;
			used[kari] = true;
			add(kari);
			V[S[i] - 'a'].pop_back();
			kazu++;
		}
	}
	co(kotae);

	Would you please return 0;
}


Measured memory_bytes: 2192
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<vector>
#include<deque>
#include<string>
#define dint __int128
using namespace std;
#define kk putchar(32)
#define gc getchar()
#define fup(i,a,b) for(int i=a,i##e=b;i<=i##e;++i)
#define fdn(i,a,b) for(int i=a,i##e=b;i>=i##e;--i)
#define mem(a,b) memset(a,b,sizeof(a))
#define hh putchar(10)
#define ll long long
inline ll rrr(){ll x,f=1;char a;while((a=gc)<48||a>57)if(a==45)f=-1;
for(x=a^48;(a=gc)>47&&a<58;x=(x<<3)+(x<<1)+(a^48));return f*x;}
struct nnn{int x,y,z;};
void Main();

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

inline int huiwen(int x)
{
    int a=x,b=0;
    while(a)b=10*b+a%10,a/=10;
    if(x==b)return 1;
    return 0;
}
void Main()
{
    int a,b;
    cin>>a>>b;
    int ans=0;
    fup(i,a,b)(huiwen(i))&&(++ans);
    cout<<ans;
}


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

int main(){
    int a, b, c, rec=0, rom = 0;
    while(scanf("%d,%d,%d", &a, &b, &c) != EOF) {
        if (a == 0) break;
        if (a*a+b*b == c*c) rec++;
        else if (a == b) rom++;
    }
    printf("%d\n%d\n", rec, rom);
    return 0;
}



Measured memory_bytes: 2712
#include<stdio.h>

int main() {
  int n,i,j;
  int Adj[100][100];
  int u,k,v;
  
  scanf("%d",&n);
  
  for( i=0 ; i<n ; i++ ) {
    for( j=0 ; j<n ; j++ ) {
      Adj[i][j] = 0;
    }
  }
 
  for( i=0 ;  i<n ; i++ ) {
    scanf("%d%d", &u, &k);
    for( j=0 ; j<k ; j++ ) {
      scanf("%d", &v);
      Adj[i][v-1] = 1;
    }
  }

  for( i=0 ; i<n ; i++ ) {
    for( j=0 ; j<n ; j++ ) {
      printf("%d", Adj[i][j]);
      if(j != n-1) printf(" ");
    }
    printf("\n");
  }

  return 0;
}

Measured memory_bytes: 636
def mergeArray(a,b,bLength,c,cLength):
    global count
    apos,bpos,cpos=(0,0,0)
    while bpos<bLength and cpos<cLength:
        if b[bpos]<=c[cpos]:
            a[apos]=b[bpos]
            bpos+=1
        else:
            a[apos]=c[cpos]
            cpos+=1
        apos+=1
        count+=1
    
    while bpos<bLength:
        a[apos]=b[bpos]
        apos+=1
        bpos+=1
        count+=1
    
    while cpos<cLength:
        a[apos]=c[cpos]
        apos+=1
        cpos+=1
        count+=1

def mergeSort(a,aLength):
    b=[]
    c=[]
    if aLength>=2:
        b=a[:aLength//2]
        c=a[aLength//2:]
        mergeSort(b,len(b))
        mergeSort(c,len(c))
    mergeArray(a,b,len(b),c,len(c))

count=0
aLength=int(input())
a=list(map(int,input().split()))
mergeSort(a,aLength)
print(*a)
print(count)


Measured memory_bytes: 63700
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
typedef long long ll;
using namespace std;
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a * b > c) {
		cout << c << endl;
	}
	else if (a * b < c) {
		cout << a * b << endl;
	}
	else if (a * b == c){
		cout << c << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    string s;
    cin>>s;
    bool nn=false;bool ss=false;bool ee=false;bool ww=false;
    for(int i=0;i<=s.size()-1;i++){
      if(s.at(i)=='S'){ss=true;}
      if(s.at(i)=='N'){nn=true;}
      if(s.at(i)=='W'){ww=true;}
      if(s.at(i)=='E'){ee=true;}
    }
    if(ss==true&&nn==true){if(ee==true&&ww==false){cout<<"No"<<endl;}
                           else if(ee==false&&ww==true){cout<<"No"<<endl;}
                           else if(ee==true&&ww==true){cout<<"Yes"<<endl;}
                           else if(ee==false&&ww==false){cout<<"Yes"<<endl;}
                           }
    else if (ss==false&&nn==false){if(ee==true&&ww==false){cout<<"No"<<endl;}
                           else if(ee==false&&ww==true){cout<<"No"<<endl;}
                           else if(ee==true&&ww==true){cout<<"Yes"<<endl;}
                           else if(ee==false&&ww==false){cout<<"Yes"<<endl;}
                           }
    else{cout<<"No"<<endl;}
    return 0;
}

Measured memory_bytes: 256
<>;$x=$==1,s/( \d+)\1*\b/$x*=$&**($a=$&=~y! !!%3);$=*=$&**(-$a%3)/ge,++$h{$x},$t{$x}=$=for`factor`;$\+=$_<2?!!$h{1}:$h{$_},$h{$_}=$h{$t{$_}}=0for sort{$h{$b}-$h{$a}}keys%h;print

Measured memory_bytes: 51912
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define IFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define RPT(i,a,b) for(int i=(a);i<((a)+(b));++i)
#define IRPT(i,a,b) for(int i=((a)+(b)-1);i>=(a);--i)
#define BITBOOL(x,a) (((x)>>(a))&1)
int main(){
  string s; cin >> s; int n = s.size();
  bool flg=true;
  FOR(i,0,n){
    if(i%2==0 && (s[i]=='L')  ) flg=false;
    if(i%2==1 && (s[i]=='R')  ) flg=false;
  }
  if(flg) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 256
a,b,m=map(int,input().split())
ali=list(map(int,input().split()))
bli=list(map(int,input().split()))

an=min(ali)+min(bli)

for i in range(m):
    x,y,c=map(int,input().split())
    if an>((ali[x-1]+bli[y-1])-c):
        an=((ali[x-1]+bli[y-1])-c)

print(an)

Measured memory_bytes: 18612
def resolve():
    w, h, n = map(int, input().split())
    xya = list(list(map(int, input().split())) for _ in range(n))
    min_x, min_y = 0, 0
    max_x, max_y = w, h
    for x, y, a in xya:
        if a == 1 and x > min_x:
            min_x = x
        elif a == 2 and x < max_x:
            max_x = x
        elif a == 3 and y > min_y:
            min_y = y
        elif a == 4 and y < max_y:
            max_y = y
    if min_x >= max_x or min_y >= max_y:
        print(0)
    else:
        print((max_x - min_x) * (max_y - min_y))


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3064
package main

import "fmt"

func main() {
	var N, M, K, L int
	fmt.Scan(&N, &M)
	point := make(map[int]int, M)
	for i := 0; i < N; i++ {
		fmt.Scan(&K)
		for y := 0; y < K; y++ {
			fmt.Scan(&L)
			point[L]++
		}
	}
	c := 0
	for _, p := range point {
		if p == N {
			c++
		}
	}
	fmt.Println(c)
}


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

int main(){
    ll n,m;
    cin >> n >> m;
    ll ans = 0;
    ll a = min(n,m);
    ll b = max(n,m);
    ans = (b-2)*(a-2);
    cout << abs(ans) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MAX_N 100000
#define MAX_M 100000
#define vec vector<int>
#define vecvec vector<vector<int>>
const int INF = 1e9;
#define PI 3.141592653589793
using namespace std;
 
 
 
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, i, j, k, best, x;
	map<int, int> ct1, ct2;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> x;
		if (i % 2 == 0) ct1[x]++;
		else ct2[x]++;
	}
 
	vector<pair<int, int>> c1, c2;
	for (auto p : ct1) c1.push_back({ p.second, p.first });
	for (auto p : ct2) c2.push_back({ p.second, p.first });
	sort(c1.rbegin(), c1.rend());
	sort(c2.rbegin(), c2.rend());
 
	best = n * 10;
	for (i = 0; i < min(2, (int)c1.size()); i++) {
		for (j = 0; j < min(2, (int)c2.size()); j++) 
			if (c1[i].second != c2[j].second) {
				x = n - c1[i].first - c2[j].first;
				best = min(best, x);
			}
	}
 
	if ((c1.size() == 1) && (c2.size() == 1) && (c1[0].second == c2[0].second)) best = n / 2;
	
	cout<<best<<endl;
	return 0;
}

Measured memory_bytes: 6140
/*
  A - Meal Delivery
  <http://abc071.contest.atcoder.jp/tasks/abc071_a>
*/

#include <stdio.h>

int main(int argc, char const *argv[]) {
  int x,a,b;
  scanf("%d %d %d", &x,&a,&b);
  if( x-a < 0 ){
    if( x-b < 0 ){
      if( a-b < 0 ){
        printf("A\n");
      }else{
        printf("B\n");
      }
    }else{
      if( a-x < x-b ){
        printf("A\n");
      }else{
        printf("B\n");
      }
    }
  }else{
    if( x-b < 0 ){
      if( x-a < b-x ){
        printf("A\n");
      }else{
        printf("B\n");
      }
    }else{
      if( b-a < 0 ){
        printf("A\n");
      }else{
        printf("B\n");
      }
    }
  }
  return 0;
}


Measured memory_bytes: 128
N = int(input())
l = [0]*N
for i in range(N):
    a,b = [int(x) for x in input().split()]
    if a == b:
        l[i] = 1
for i in range(1,N):
    if l[i] == 1:
        l[i] = l[i-1] + 1
    else:
        l[i] = 0
if max(l) >= 3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9192
#include <iostream>

using namespace std;


long long gcd(long long x,long long y){
	long long int tmp;
  if(x < y)
		swap(x, y);

  while( y > 0){
  	tmp = x % y;
    x = y;
    y = tmp;
	}
  return x;
}

int main(){
  int n, m;
  cin>> n >> m;
  cout<< gcd( n, m) <<endl;
  return 0;
}

Measured memory_bytes: 1160
MOD = 10**9 + 7
N = int(input())
S = input()

X = {}

for s in S:
    if not(s in X):
        X[s] = 0

    X[s] += 1

ans = 1
for v in X.values():
    ans = ans*(v+1)%MOD

print((ans-1)%MOD)


Measured memory_bytes: 9256
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,M;
    map<int,int> dic;
    
    cin>>N>>M;
    rep(i,M){
        int a,b; cin>>a>>b;
        a--,b--;
        dic[a]++;
        dic[b]++;
    }
    
    for(auto d:dic){
        int num=d.second;
        if(num%2){
            cout1("NO")
            return 0;
        }
    }
    cout1("YES")
}

Measured memory_bytes: 4352
#include <stdio.h>
#include <math.h>

int main(void){
    int i,n,s[1000];
    double h,sum;
    
    while(1){

        scanf("%d",&n);
        if(!n) break;
        
        sum = 0;
        h = 0;
        
        for(i=0;i<n;i++){
            scanf("%d",&s[i]);
            sum += s[i];
        }
    
        sum /= n;
    
   //     printf("%lf ",sum);
        
        for(i=0;i<n;i++){
            h += pow(s[i]-sum, 2.0);
        }
            
        h /= n;

   //     printf("%lf ",h);

        printf("%lf\n",pow(h,1.0/2.0));
    
    }
    
    return 0;
}

Measured memory_bytes: 692
H,W = map(int, input().split())

dif = 10**10

if H%3==0 or W%3==0:
	print(0)
	exit()

for i in range(H):
	a = i*W
	h = (H-i)//2
	abc = [a, h*W, (H-i-h)*W]
	if not(0 in abc):
		dif = min(dif, max(abc)-min(abc))
	
	h = H-i
	w = W//2
	abc = [a, h*w, h*(W-w)]
	if not(0 in abc):
		dif = min(dif, max(abc)-min(abc))

for i in range(W):
	a = H*i
	w = (W-i)//2
	abc = [a, H*w, H*(W-i-w)]
	if not(0 in abc):
		dif = min(dif, max(abc)-min(abc))
	
	w = W-i
	h = H//2
	abc = [a, h*w, (H-h)*w]
	if not(0 in abc):
		dif = min(dif, max(abc)-min(abc))

print(dif)

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()

typedef long long ll;
typedef pair<int, int> P;

ll h,w;

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

	cin>>h>>w;
	if(h%3==0||w%3==0) {
		cout<<'0'<<endl;
		return 0;
	}
	ll mi=LINF;
	REP(i,h) {
		ll a=i*w;
		ll b=(h-i)/2*w;
		ll c=h*w-(a+b);
		mi=min(mi,max(a,max(b,c))-min(a,min(b,c)));

		b=(h-i)*(w/2);
		c=h*w-(a+b);
		mi=min(mi,max(a,max(b,c))-min(a,min(b,c)));
	}
	REP(i,w) {
		ll a=i*h;
		ll b=(w-i)/2*h;
		ll c=h*w-(a+b);
		mi=min(mi,max(a,max(b,c))-min(a,min(b,c)));

		b=(w-i)*(h/2);
		c=h*w-(a+b);
		mi=min(mi,max(a,max(b,c))-min(a,min(b,c)));
	}
	cout<<mi<<endl;

	return 0;
}


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

using namespace std;
using ll = long long;
using P = pair<int,int>;
#define all(c) (c).begin(),(c).end()
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
const ll MOD = 1e9+7;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"[";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"]";return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&p)
{o<<"{"<<p.first<<", "<<p.second<<"}";return o;}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj)
{o<<"{";for(auto itr=obj.begin();itr!=obj.end();++itr)o<<(itr!=obj.begin()?", ":"")<<*itr;o<<"}";return o;}
void print() {}
template <class H, class... T>void print(H&& head, T&&... tail)
{cout << head << (sizeof...(tail)==0 ? "\n" : " "); print(forward<T>(tail)...);}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll ans=0, n;
  cin >> n;
  vector<P> p;
  for(int i=0; i<n; i++){
    int v;
    cin >> v;
    p.push_back(P(v,i));
  }
  sort(all(p));
  reverse(all(p));

  multiset<int> st;
  st.insert(p[0].second);
  st.insert(-1); st.insert(-1);
  st.insert(n); st.insert(n);

  for(int i=1; i<n; i++){
    ll l, r, l2, r2;
    ll v = p[i].first;
    ll idx = p[i].second;
    auto ir = st.upper_bound(idx);
    auto il = ir; il--;
    r = *ir;
    ir++; r2 = *ir;
    l = *il;
    il--; l2 = *il;
    
    ans += ((r2-r) * (idx-l) + (l-l2) * (r-idx)) * v;
    st.insert(idx);
  }
  
  cout << ans << endl;
  return 0;
}


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

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	int x, y, z;
	x = 0;
	y = 0;
	z = 0;
	for (int i = 0; i < N; ++i) {
		int num;
		cin >> num;
		if (num <= A) {
			x++;
		}
		else if (num <= B) {
			y++;
		}
		else {
			z++;
		}
	}
	cout << min(x, min(y, z)) << endl;
	return 0;
}

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

using ll = long long;

#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                     \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define check(s) cerr << s << endl

#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(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

vector<int> dx = {0, 1, 0, -1};
vector<int> dy = {1, 0, -1, 0};

const ll LINF = 2e18;
const int INF = 1e9;

void solve(ll N) {
  int d = N / 1000 + 1;
  cout << (d * 1000 - N) % 1000 << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  ll N;
  scanf("%lld", &N);
  solve(N);
  return 0;
}


Measured memory_bytes: 3720
#include<bits/stdc++.h>
#define ll          long long int
#define lld          long double
#define pb          push_back
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define vec         vector<ll>
#define all(a)     (a).begin(),(a).end()
#define F           first
#define S           second
#define mod         1000000007
#define rep(i,a,b)	for(ll  i=a;i<b;i++)
#define repi(i,a,b)	for(ll  i=a;i<=b;i++)
#define per(i,a,b)  for(ll i=a;i>=b;i--)
#define mp          make_pair
#define mit         map<ll,ll>::iterator
#define sit         set<ll>::iterator
#define pit         pair<ll,ll>::iterator
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;
ll xo(ll x, ll y) 
{ 
   return (x | y) & (~x | ~y); 
}  
ll bin_Expo(ll x,ll n)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return bin_Expo(x*x,n/2);
    else                             //n is odd
        return x*bin_Expo(x*x,(n-1)/2);
}
ll mod_Expo(ll x,ll n,ll M)
{
		if(x==0)
		return 0;
    if(n==0)
        return 1;
    else if(n%2 == 0)        //n is even
        return mod_Expo((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*mod_Expo((x*x)%M,(n-1)/2,M))%M;
 
}
bool prime_check(ll x)
{
    bool prime = (x >= 2);
    for (ll i = 2; i * i <= x; i++) 
    {
        if (x % i == 0) 
        {
            prime = false;
            break;
        }
    }
    return prime;
}
ll logg(ll base,ll x) 
{
    return (ll)(log(x) / log(base));
}
ll n,p; string s;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
    while(TESTS--)
    {
    	ll m,k,l,g,i,ans;
    	cin>>n>>m;
    	cout<<((n*(n-1))+((m*(m-1))))/2;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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 (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n, ma, mb;
    cin >> n >> ma >> mb;
    vector<int> a(n), b(n), c(n);
    rep(i, n) {
        cin >> a[i] >> b[i] >> c[i];
    }

    auto dp = make_vec<int>(50, 500, 500);
    rep(i, 50) rep(j, 500) rep(k, 500) dp[i][j][k] = INF;
    dp[0][0][0] = 0;
    rep(i, n) {
        rep(j, 500) {
            rep(k, 500) {
                if (j - a[i] >= 0 && k - b[i] >= 0) {
                    chmin(dp[i + 1][j][k], dp[i][j - a[i]][k - b[i]] + c[i]);
                }
                chmin(dp[i + 1][j][k], dp[i][j][k]);
            }
        }
    }

    int ans = INF;
    rep(a, 500) rep(b, 500) {
        if (a * b == 0) continue;
        if (a * mb != b * ma) continue;
        chmin(ans, dp[n][a][b]);
    }
    cout << (ans == INF ? -1 : ans) << endl;
}


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

int main()
{
  string s;
  cin >> s;
  if (s.at(0) == s.at(1) && s.at(1) == s.at(2)) {
    cout << "No\n";
  } else {
    cout << "Yes\n";
  }
  return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define rep(i,n) for(int i=0;i<n;++i)
int main(){
  int n,q;
  cin>>n>>q;
  vector <vector<int>> e(n);
  vector<int> p(n,0);
  vector<int> c(n);
  vector<int> vis(n);

  rep(i,n-1){
    int a,b;

    cin>>a>>b;
    a--;b--;
    e[a].emplace_back(b);
    e[b].emplace_back(a);

  }
  rep(i,q){
    int p1,x;
    cin>>p1>>x;
    p1--;
    p[p1]+=x;


  }


//    cout<<e[0].front()<<endl;

  queue<int> que;
   que.push(0);
   c[0]=p[0];
   vis[0]=1;
  // cout<<c[0]<<endl;

  while (!que.empty()) {

       int v = que.front(); // キューから先頭頂点を取り出す
       que.pop();

       // v から辿れる頂点をすべて調べる
       for (int nv : e[v]) {
    //     cout<<c[nv]<<' '<<nv<<endl;
           if (vis[nv]==1)continue;
           c[nv]=p[nv]+c[v];
           vis[nv]=1;
           que.push(nv);
       }
   }
   rep(i,n){
     cout<<c[i]<<' ';
   }


}


Measured memory_bytes: 17344