akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)

struct UnionFind{
    vector<int>d;
   
    UnionFind(int n):d(n,-1){}
  
    int find(int x)
    {
       if(d[x]<0) return x;
       
       return d[x]=find(d[x]);
     }
 
    bool unite(int x,int y)
    {
        x = find(x);
        y = find(y);
        if(x==y)return false;
        if(d[x]>d[y]) swap(x,y);
        
        d[x] += d[y];
        d[y] = x;
    
        return true;
    }

    bool same(int x,int y)
    {
        return find(x)==find(y);
    }

    int size(int x)
    {
        return -d[find(x)];
    }


};

int deg[10000005];
vector<int>to[10000005];

int main()
{
     int n,m,k;
     cin>>n>>m>>k;
  
     UnionFind uf(n);
  
     rep(i,m)
     {
         int a,b;
         cin>>a>>b;
         a--;b--;
       
         deg[a]++;
         deg[b]++;
       
         uf.unite(a,b);
     
     }
  
     rep(i,k)
     {
         int a,b;
         cin>>a>>b;
         a--;b--;
         
         to[a].push_back(b);
         to[b].push_back(a);
     
     }
  
     rep(i,n)
     {
        int ans = uf.size(i)-1-deg[i];
        for(int u:to[i]){
          if(uf.same(i,u))ans--;
         }
    
      cout<<ans<<' ';
     
    }
  
  cout<<endl;
  
  return 0;
  
   

}


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

const long long int INF = 1LL << 50;

struct edge {
    int from,to;
    long long int cost;
};

edge es[2010];

long long int d[1010];
int n,m;

bool shortest_path(int s){
    for(int i=0; i<=n; i++){
        d[i] = INF;
    }
    d[s] = 0;
    for(int loop=0; loop<n-1; loop++){
        for(int i=0; i<m; i++){
            edge ed = es[i];
            if(d[ed.from] == INF){
                continue;
            }
            if(d[ed.to] > d[ed.from] + ed.cost){
                d[ed.to] = d[ed.from] + ed.cost;
            }
        }
    }
    return false;
}

int main(){

    int s,t;
    long long int dd;

    cin >> n >> m;

    for(int i=0; i<m; i++){
        cin >> es[i].from >> es[i].to >> es[i].cost;
        es[i].cost = -es[i].cost;
    }

    shortest_path(1);

    long long int ans = d[n];

    bool negative[1010];

    for (int i = 0; i <= n; ++i) {
        negative[i] = false;
    }

    for (int loop = 0; loop < n ; loop++) {
        for (int i = 0; i < m; i++) {
            if (d[es[i].from] == INF){
                continue;
            }
            if (d[es[i].to] > d[es[i].from] + es[i].cost) {
                d[es[i].to] = d[es[i].from] + es[i].cost;
                negative[es[i].to] = true;
            }

            if (negative[es[i].from]) {
                negative[es[i].to] = true;
            }
        }
    }

    if(negative[n]){
        cout << "inf" << endl;
    }
    else{
        cout << -ans << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

int main(){
    string S;
    cin >> S;

    string ans = "Yes";
    for(int i=0; i<(int) S.size(); i++){
        if(S[i]=='R' && i%2==1){
            ans="No";
            break;
        }else if(S[i]=='L' && i%2==0){
            ans="No";
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func main() {
	sc.Split(bufio.ScanWords)

	N := nextInt()
	A := nextInt()
	B := nextInt()

	sum := 0
	
	for i := 1; i <= N; i++ {
		num := i
		digit_sum := 0
		for {
			digit_sum += num % 10
			num = num / 10
			
			if num == 0 {
				break
			}
		}
		
		if digit_sum >= A && digit_sum <= B {
			sum += i
		}
	}

	fmt.Println(sum)

}


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

int main(){
	int sx,sy,tx,ty;
	cin>>sx>>sy>>tx>>ty;
	
	for(int i=0;i<tx-sx;i++){
		cout<<"R";
	}
	for(int i=0;i<ty-sy;i++){
		cout<<"U";
	}
	for(int i=0;i<tx-sx;i++){
		cout<<"L";
	}
	for(int i=0;i<ty-sy+1;i++){
		cout<<"D";
	}
	for(int i=0;i<tx-sx+1;i++){
		cout<<"R";
	}
	for(int i=0;i<ty-sy+1;i++){
		cout<<"U";
	}
	cout<<"LU";
	
	for(int i=0;i<tx-sx+1;i++){
		cout<<"L";
	}
	for(int i=0;i<ty-sy+1;i++){
		cout<<"D";
	}
	cout<<"R"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
int main() {
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    bool r = true;
    vector<int> x(n);
    vector<int> y(m);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> y[i];
    }
    if (a >= b) {
        r = false;
    }
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++) {
            if (x[i] >= y[j]) {
                r = false;
            }
            if (a >= y[j] || b <= x[i]) {
                r = false;
            }
        }
    }
    if (r) {
        cout << "No War" << endl;
    }
    else {
        cout << "War" << endl;
    }
}

Measured memory_bytes: 3612
N, M = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(N)]

A.sort(key=lambda x: x[0])

p = M
ans = 0
for c in A:
    if c[1] >= p:
        ans += c[0] * p
        break
    ans += c[0] * c[1]
    p -= c[1]
print(ans)

Measured memory_bytes: 29024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

template< typename T >
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;
int negative[1010] = {};

template< typename T >
vector< T > bellman_ford(Edges< T > &edges, int V, int s) {
  const auto INF = numeric_limits< T >::max();
  vector< T > dist(V, INF);
  dist[s] = 0;
  for(int i = 0; i < V - 1; i++) {
    for(auto &e : edges) {
      if(dist[e.src] == INF) continue;
      dist[e.to] = min(dist[e.to], dist[e.src] + e.cost);
    }
  }
  bool flag = 0;
  for(int i = 0; i < 2*V; i++){
    for(auto &e : edges) {
        if(dist[e.src] == INF) continue;
        if(dist[e.src] + e.cost < dist[e.to])
        {
            dist[e.to] = dist[e.src] + e.cost;
            negative[e.to] = 1;
        }
    }
  }
  return dist;
}

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL N,M; cin >>N>>M;
    Edges<LL> es;
    REP(i,1010) negative[i] = 0;
    REP(i,M)
    {
        LL a,b,c; cin>>a>>b>>c;
        a--; b--; c *= -1;
        es.emplace_back(a,b,c);
    }
    auto dists = bellman_ford(es,N,0);
    if(negative[N-1] == 1)
    {
        cout << "inf" << endl;
        return 0;
    }
    else
    {
        cout << dists[N-1] * -1 << endl;
    }


}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

void solve() {
    using A = array<int, 3>;

    int N, Q;
    cin >> N >> Q;
    vector<A> u(N);
    rep(i, N) {
        cin >> u[i][1] >> u[i][2] >> u[i][0];
    }
    sort(all(u));

    set<pii> ds;
    rep(i, Q) {
        int d;
        cin >> d;
        ds.insert(pii(d, i));
    }

    vi ans(Q, -1);
    rep(i, N) {
        A &v = u[i];
        int x = v[0], s = v[1], t = v[2];
        int L = s - x, R = t - x;
        while (1) {
            auto it = ds.lower_bound(pii(L, 0));
            if (it == ds.end() || it->first >= R) {
                break;
            }
            ans[it->second] = x;
            ds.erase(it);
        }
    }

    each(a, ans)cout << a << endl;
}

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

Measured memory_bytes: 14464
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <math.h>
#include <string>
#include <string.h>
#include <stack>
#include <queue>
#include <vector>
#include <utility>
#include <set>
#include <map>
#include <stdlib.h>
#include <iomanip>

using namespace std;

#define ll long long
#define vi vector<int>
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pi 3.14159265359

char ToUpper(char cX) { return toupper(cX); }


int main() {
	string s1, s2, s3;
	string ans;
	cin >> s1 >> s2 >> s3;
	transform(s1.begin(), s1.end(), s1.begin(), ToUpper);
	transform(s2.begin(), s2.end(), s2.begin(), ToUpper);
	transform(s3.begin(), s3.end(), s3.begin(), ToUpper);
	cout << s1[0] << s2[0] << s3[0];
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
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 T>
void printv(vector<T> v) {for (T t : v) {cout << t << " ";}cout << '\n';}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" <<endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

vi g[200005];
vi ans;

int dfs(int v = 0, int p = -1) {
    for (int c : g[v]) {
        if (p != c) {
            ans[c] += ans[v];
            dfs(c,v);
        }
    }
}

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

    REP(i,N-1) {
        int a, b;
        cin >> a >> b;
        a--;b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }

    ans.resize(N);

    REP(i, Q) {
        int p, x;
        cin >> p >> x;
        p--;
        ans[p] += x;
    }

    dfs();

    REP(i, N) {
        cout << ans[i] << " ";
    }

    return 0;
    
}


Measured memory_bytes: 23424
while True:
    n, x = map(int, raw_input().split())
    if(n == 0 and x == 0):
        break
    count = 0
    for i in range(1, n - 1):
        for j in range(i + 1, n):
            for k in range(j + 1, n + 1):
                if(i + j + k == x):
                    count += 1
    print(count)

Measured memory_bytes: 4212
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;
    int A[N][3];
    REP(i, N) REP(j, 3) cin >> A[i][j];
    ll dp[N + 1][3] = {};

    FOR(day, 1, N + 1) {
        // day-1 に選んだやつ
        REP(dif, 3) {
            // day に選ぶやつ
            REP(i, 3) {
                // day-1 と day に選んだものは違わなければならない
                if (dif == i)
                    continue;
                chmax(dp[day][i], dp[day - 1][dif] + A[day - 1][i]);
            }
        }
    }

    ll ans = 0;
    REP(i, 3) { chmax(ans, dp[N][i]); }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
int W,H,N;
int x,y,a;
int X[110]={};
int Y[110]={};
int Wa=0,Ha=0;
int main(){
  cin >> W >> H >> N;
  for(int i=1;i<=W;i++){
    X[i]++;
  }
  for(int i=1;i<=H;i++){
    Y[i]++;
  }
  /*for(int i=0;i<N;i++){
  if(W==0 || H ==0) break;
  cin >> x >> y >> a;
  //tmpx=max(tmpx,x);
  //tmpy=max(tmpy,y);

  if(a==1){
  W=W-x;
  tmpx=max(tmpx,x);
}
if(a==2){
x=x-tmpx;
if(x<0) x=0;
W=x;
}
if(a==3){
H=H-y;
tmpy=max(tmpy,y);
}
if(a==4){
y=y-tmpy;

if(y<0) y=0;
H=y;
}
}
if(H*W>0) cout << H*W << endl;
else cout << "0" << endl;
*/for(int i=0;i<N;i++){
cin >> x >> y >> a;
if(a==1){
  for(int i=1;i<=x;i++){
    X[i]=0;
  }
}
if(a==2){
  for(int i=x+1;i<=102;i++){
    X[i]=0;
  }
}
if(a==3){
  for(int i=1;i<=y;i++){
    Y[i]=0;
  }
}
if(a==4){
  for(int i=y+1;i<=102;i++){
    Y[i]=0;
  }
}
}
for(int i=0;i<102;i++){
  Wa+=X[i];
}
for(int i=0;i<102;i++){
  Ha+=Y[i];
}
cout << Wa*Ha << endl;

return 0;
}


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

public class Main {

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

	}
	static class Task{
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			char[] sc = in.next().toCharArray();
			int count_x = 0;
			for(char c: sc) if (c == 'x') count_x++;
			out.print(count_x<=7?"YES":"NO");
			
		}//Solve
	}//task
	
	
	static class InputReader{
		public BufferedReader reader;
		public StringTokenizer tokenizer;
		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}
		public String next() {
			while(tokenizer == null || ! tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for(int i = -1; ++i < n;) a[i] = nextInt();
			return a;
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for(int i = -1; ++i < n;) a[i] = nextLong();
			return a;
		}
		public float nextFloat() {
			return Float.parseFloat(next());
		}
	}
}


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

int main(){
	int n,l,c=0,sum=0;
  	cin >> n >> l;
  
  vector<int> rd(n);
  int m=100000,s;
  
  for(int i=0;i<n;i++){
	rd[i]=l+i;
    sum+=rd[i];
    if(m>fabs(rd[i])){
      m=fabs(rd[i]);
      s=i;
    }
  }
  cout << sum-rd[s] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
using namespace std;
int main() {
    string s,t;
    int a,b;
    string u;
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;
    if(u == s){
        cout << a-1 << " " << b << endl;
    }else{
        cout << a << " " << b-1 << endl;
    }
}

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

 using namespace std;

 int main() {
   int N, T;

   cin >> N >> T;

   vector<int> c(N);
   vector<int> t(N);

   for (int i = 0; i < N; i++) {
     cin >> c.at(i) >> t.at(i);
   }
   int min_cost = 1001;
   for (int i = 0; i < N; i++) {
     if (t.at(i) <= T) min_cost = min(min_cost, c.at(i));
   }

   if (min_cost == 1001) cout << "TLE" << endl;
   else cout << min_cost << endl;
}


Measured memory_bytes: 256
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def solve():
    N = int(input())
    L = list(map(int, input().split()))

    ans = 0
    l = 0
    r = 0
    tmp_sum = 0
    while l < N:
        while r < N and tmp_sum ^ L[r] == tmp_sum+L[r]:
            tmp_sum ^= L[r]
            r += 1
        ans += r-l
        if(l == r):
            r += 1
        else:
            tmp_sum ^= L[l]
            l += 1
    print(ans)


solve()


Measured memory_bytes: 24372
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MAX = 1e5+5;


int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        int n , k;
        cin >> n >> k;
        LL a[n+2] , dp[n+2];
        for(int i = 1 ; i <= n ; i++)
        {
                cin >> a[i];
        }
        dp[1] = 0;
        //dp[2] = abs(a[2] - a[1]);
        for(int i  = 2 ; i <= n ; i++)
        {
                dp[i] = 1e15;
                for(int j = i-1 ; j >= max(1 , i-k) ; j--)
                {
                        dp[i] = min(dp[i] , dp[j] + abs(a[j] - a[i]));
                }
        }
        cout << dp[n] << endl;
        return 0;
}

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

int main() {
    // C: A のカウンティング配列
    // D[x] := C の中に x 以上が何個あるか
    // S: D の累積和
    int N; cin >> N;
    vector<long long> C(N, 0);
    vector<long long> D(N+1, 0);
    for (int i = 0; i < N; ++i) {
        int a; cin >> a; --a;
        C[a]++;
        D[C[a]]++;
    }
    vector<long long> S(N+1, 0);
    for (int i = 1; i < N+1; ++i) S[i] = S[i-1] + D[i];

    for (long long K = 1; K <= N; ++K) {
        long long low = 0, high = N+1;
        while (high - low > 1) {
            long long x = (low + high) / 2;
            if (S[x] >= K * x) low = x;
            else high = x;
        }
        cout << low << endl;
    }
}


Measured memory_bytes: 7936
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        int result = 0;

        for (int i = 1; i <= N; i++) {
            String imput = String.valueOf(i);
            String[] strings;
            strings = imput.split("");

            int sum = 0;
            for (int j = 0; j <= imput.length() - 1; j++) {
                sum += Integer.valueOf(strings[j]);
            }

            if(A <= sum && sum <= B) {
                result += i;
            }
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 36436
#include <iostream>
#include <set>
using namespace std;
int main()
{
  set<int> s;
  int n; cin>>n;
  int p[n];
  int sum=0;
  for (size_t i = 0; i < n; i++) {
    cin>>p[i];
  }
  for (size_t i = 0; i < n-2; i++) {
    s.insert(p[i]);
    s.insert(p[i+1]);
    s.insert(p[i+2]);
    auto it=s.begin();
    it++;
    int k=*it;
    if(p[i+1]==k) sum++;
    s.clear();
    }

  cout<<sum;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

class Vector{
public:
	double x;
	double y;

	Vector(){}
	Vector( double dx, double dy ){
		x = dx;
		y = dy;
	}

	double operator*( const Vector& hoge ){
		return x * hoge.x + y * hoge.y;
	}

	Vector operator*( const double hoge )
	{
		return Vector( x * hoge, y * hoge );
	}

	Vector operator/( const double hoge )
	{
		return Vector( x / hoge, y / hoge );
	}

	Vector operator-( const Vector& hoge ){
		return Vector( x - hoge.x, y - hoge.y );
	}

	Vector operator-(){
		return Vector( -x, -y );
	}

	Vector operator+( const Vector& hoge ){
		return Vector( x + hoge.x, y + hoge.y );
	}
};

double change( double data )
{
	data *= 1000;
	data = int( data + .5 -( data < 0 ) );
	data /= 1000;
	return data;
}

int main(int argc, char const* argv[])
{
	Vector p1,p2,p3,circ;
	double r;
	int n;

	cin >> n;
	for( int i = 0;i < n;i++ ){
		cin >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y;
		Vector e1,e2,e3;
		e1 = p3 - p2;
		e2 = p1 - p3;
		e3 = p2 - p1;

		double d1 = (-e2) * e3;
		double d2 = (-e3) * e1;
		double d3 = (-e1) * e2;
		double c1 = d2 * d3;
		double c2 = d3 * d1;
		double c3 = d1 * d2;
		double c = c1 + c2 + c3;

		circ = ( (p1 * (c2 + c3)) + (p2 * (c3 + c1)) + (p3 * (c1 + c2)) ) / (2 * c);
		r = sqrt( fabs((d1 + d2) * (d2 + d3) * (d3 + d1) / c) ) / 2;
		circ.x = change( circ.x );
		circ.y = change( circ.y );
		r = change( r );

		printf("%.3f %.3f %.3f\n",circ.x, circ.y, r );
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>
#include <unordered_map>

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;

int MOD = 1000000007;

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

    int n; cin >> n;
    int ans = 0;

    std::vector<std::vector<pii>> v(n);

    rep(i,n){
        int a; cin >> a;
        rep(j,a){
            int x,y; cin >> x >> y; x--;
            v[i].push_back({x,y});
        }
    }


    for(int bit=0; bit < (1<<n); ++bit){
        bool good = true;
        int cnt = 0;

        std::vector<int> og(n,-1);
        std::vector<int> t(n,-1);

        for(int i=0; i<n; ++i){
            if(bit&(1<<i)){

                if(t[i] == 0) good = false;

                rep(j, v[i].size()){
                    int pid = v[i][j].first;
                    int tf = v[i][j].second;
                    if(t[pid]==-1) t[pid]=tf;
                    else if(t[pid]!=-1 && t[pid]!=tf) good = false;
                }

                og[i] = 1;
                cnt++;
            } else {
                og[i] = 0;
            }
        }

        rep(i,n){
            if((t[i] == 1 && og[i]==0) || (t[i] == 0 && og[i]==1)) good = false;
        }


        if(good) ans = std::max(ans, cnt);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Tue May 21 23:08:18 2019

@author: Yamazaki Kenichi
"""

n = int(input())
A = [list(map(int,input().split())) for i in range(n)]
INFTY = 10**6
M = [[INFTY for i in range(n)] for i in range(n)]
for a in A:
    u, k = a[0], a[1]
    for i in range(k):
        M[u][a[i*2+2]] = a[i*2+3]

class Dijkstra(object):
    
    def __init__(self, size, INFTY=10**6):
        self.color = [-1 for i in range(size)]
        self.d = [INFTY for i in range(size)]
        self.p = [-1 for i in range(size)]
        self.d[0] = 0 
        self.p[0] = -1
    
    def add(self, M, INFTY=10**6):
        while True:
            mincost = INFTY
            for i in range(len(M)):
                if self.color[i] != 1 and self.d[i] < mincost:
                    mincost = self.d[i]
                    u = i
            if mincost == INFTY:
                break
            self.color[u] = 1            
            for v in range(len(M)):
                if self.color[v] != 1 and M[u][v] != INFTY:
                    if self.d[v] > self.d[u] + M[u][v]:
                        self.d[v] = self.d[u] + M[u][v]
                        self.p[v] = u
                        self.color[v] = 0
        return self.d

dij = Dijkstra(n)
ans = dij.add(M)
for i in range(n):
    print(i,ans[i])



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

int main() {
	
	int M, D;
	cin >> M >> D;

	int count = 0;

	int d10, d1;
	for (int i = 22; i <= D; i++) {
		// d1が0or1の時スキップ
		if (i % 10 < 2) continue;
		d10 = i / 10;
		d1  = i % 10;
		if (d10 * d1 <= M) count++;
	}

	cout << count;

}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] arg) throws NumberFormatException, IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer strToke;
        String line;
        long gcd; // 最大公約数
        long lcm; // 最小公倍数

        // ab = gcd * lcm
        while ((line = in.readLine()) != null) {
            strToke = new StringTokenizer(line);
            long a = Integer.parseInt(strToke.nextToken());
            long b = Integer.parseInt(strToke.nextToken());
            long aStock = new Long(a).longValue();
            long bStock = new Long(b).longValue();
            int c;
            while (a != b) {
                if (a > b) {
                    a = a - b;
                } else {
                    b = b - a;
                }
            }
            gcd = a;
            lcm = (aStock * bStock) / gcd;

            System.out.println(gcd + " " + lcm);
        }
    }
}

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

int main()
{
    string s;
    string t;
    cin >> s >> t;
    string result = "No";
    for(int i = 0; i <= 'z'-'a'; ++i)
    {
        if(s+(char)('a'+i) == t)
        {
            result = "Yes";
        }
    }
    cout << result << endl;
}

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


int main() 
{
	int n,password=0;cin>>n;
	for(int i=1; i<=n; i++){
		for(int j=1; j<=n; j++){
			for(int k=1; k<=n; k++){
				password++;
			}
		}
	} 
	cout<<password<<endl;
	return 0; 
} 

Measured memory_bytes: 256
N = int(input().strip())
A = list(map(int, input().strip().split()))
X = [0] * N

x = sum(A)
for i in range(1, N, 2):
  x -= 2 * A[i]

X[0] = x

for i in range(N - 1):
  X[i + 1] = 2 * A[i] - X[i]

print(' '.join(map(str, X)))


Measured memory_bytes: 19148
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int A= 1000000000;
int main(){
  int N;
  cin>>N;
  vector<int>X(N);
  rep(i,N){
    cin>>X.at(i);
  }
    int L=X.at(0);
    int R=X.at(0);
  rep(i,N){
    L=min(L,X.at(i));
    R=max(R,X.at(i));}
  int ans=A;
  for(int i=L;i<=R;i++){
   int B=0;
    rep(j,N){ B+=(X.at(j)-i)*(X.at(j)-i);}
      ans=min(ans,B);}
  cout<<ans<<endl;
  return 0;}
      
    
    

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>

#undef DEBUG

int
cmp(const void *a, const void *b)
{
    return *(int *)b - *(int *)a;
}

int
main(int argc, char *argv[])
{
    int N, M;
    int A[100001];
    int tmp, tgt, idx;
    long long sum=0;
    int i, j;
    int k;
 
    scanf("%d%d", &N, &M);
    for (i=1; i<N+1; i++) {
        scanf("%d", A+i);
        sum += A[i];
    }
    qsort(A+1, N, sizeof(int), cmp);

#ifdef DEBUG
    for (k=1; k<N+1; k++)
        printf("%d ", A[k]);
    printf("\n");
#endif

    for (i=0; i<M; i++) {
        sum -= (A[1] - A[1]/2);
        A[1] /= 2;
        tgt = A[1];
        idx = 1;

#ifdef DEBUG
    printf("%d %d %d %d\n", idx, A[idx*2], A[idx*2+1], tgt);
#endif
        while((idx*2<=N && A[idx*2]>tgt) || (idx*2+1<=N && A[idx*2+1]>tgt)) {
#ifdef DEBUG
            printf("### %d %d %d %d\n", idx, A[idx*2], A[idx*2+1], tgt);
#endif
            if (idx*2+1<=N) {
                if (A[idx*2]>A[idx*2+1]) {
                    tmp = A[idx*2];
                    A[idx*2] = tgt;
                    A[idx] = tmp;
                    idx = idx*2;
                }
                else {
                    tmp = A[idx*2+1];
                    A[idx*2+1] = tgt;
                    A[idx] = tmp;
                    idx = idx*2+1;
                }
            }   
            else {
                tmp = A[idx*2];
                A[idx*2] = tgt;
                A[idx] = tmp;
                idx = idx*2;
            }
        }
#ifdef DEBUG
        for (k=1; k<N+1; k++)
            printf("%d: %d ", k, A[k]);
        printf("\n");
#endif
    }

    printf("%lld\n", sum);
 
    return 0;
}

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

using namespace std;

int N, T[210], V[210];

int t;
int f[40010];
bool memo[40010][210];
double dp[40010][210];

double rec(int idx, double v) {
  if (v < 0) return (-1e20);
  if (v > f[idx]) return (-1e20);
  if (idx == t) return (0.0);
  if (memo[idx][(int)(v * 2)]++) return (dp[idx][(int)(v * 2)]);
  double res = -1e20;
  res = max({res, rec(idx + 1, v) + v * 0.5, rec(idx + 1, v + 0.5) + v * 0.5 + 0.5 * 0.5 / 2,
             rec(idx + 1, v - 0.5) + v * 0.5 - 0.5 * 0.5 / 2});
  dp[idx][(int)(v * 2)] = res;

  return res;
}

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) cin >> T[i];
  for (int i = 0; i < N; i++) cin >> V[i];

  t = 1;
  for (int i = 0; i < N; i++) {
    f[t - 1] = min(f[t - 1], V[i]);
    for (int j = 1; j <= 2 * T[i]; j++) f[t++] = V[i];
  }

  f[--t] = 0;
  cout << fixed << setprecision(10) << rec(0, 0) << endl;
}


Measured memory_bytes: 77952
# -*- coding utf-8 -*-
import sys
S = input()
key = 'keyence'

i = 0
state = 0
for j in range(len(S)):
    if state == 0:
        if key[i] == S[j]:
            i += 1
        else:
            state += 1
    elif state == 1:
        if key[i] == S[j]:
            if len(key) - i == len(S) - j:
                i += 1
                state += 1
            elif len(key) - i > len(S) - j:
                print('NO')
                sys.exit()
    elif state == 2:
        if key[i] == S[j]:
            i += 1
        else:
            print('NO')
            sys.exit()
if i == len(key):
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;


int max_dimention(const vvi &tree)
{
    int r = 0;
    for (const vi &n : tree)
        r = max<int>(r, n.size());      
    return r;
}

pair<int,int> edge(int a, int b)
{
    if (a < b)
        return {a, b};
    else
        return {b, a};
}

void dfs(const vvi &tree, map<pair<int,int>,int> &edge_color, int K, int current, int parent)
{
    const vi &node = tree[current];
    for (int i = 0, c = 0; i < (int)node.size(); ++i)
    {
        int next = node[i];
        if (next == parent) continue;
        if (parent >= 0 && c == edge_color[edge(current, parent)]) ++c;

        edge_color[edge(current, next)] = c++;
        dfs(tree, edge_color, K, next, current);
    }
}

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

    vvi tree(N);
    vector<pair<int,int>> edges(N-1);
    map<pair<int,int>,int> edge_color;

    for (int i = 0; i < N - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        --a; --b;

        tree[a].push_back(b);
        tree[b].push_back(a);

        auto e = edge(a,b);
        edges[i] = e;
        edge_color[e] = -1;
    }

    int K = max_dimention(tree);
    dfs(tree, edge_color, K, 0, -1);

    cout << K << endl;
    for (auto e : edges)
        cout << (edge_color[e] + 1) << endl;
}

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

class Node{//树结点的构造
public:
int location,l,r,p;//左右父节点
Node(){}
};

class Point{//记录原来的点的序列
public:
int id,x,y;
Point(){}
Point(int id,int x,int y):id(id),x(x),y(y){}

bool operator < (const Point &p)const{
return id<p.id;
}

void print(){
printf("%d\n", id);
}
};

static const int NIL = -1;
static const int MAX =1000010;
int N;
Point P[MAX];
Node T[MAX];
int np;

bool lessX(const Point &p1,const Point &p2){return p1.x<p2.x;}//结点按照x排序
bool lessY(const Point &p1,const Point &p2){return p1.y<p2.y;}//结点按照y排序

int maketree(int l,int r,int depth){//递归构造二叉树
if(l>=r)return NIL;
int mid = (l+r)/2;
int t = np++;

if(depth%2==0)//按层给x和y交替排序构成二叉树
sort(P+l,P+r,lessX);//按照x排序
else sort(P+l,P+r,lessY);//按照y排序

T[t].location = mid;
T[t].l = maketree(l,mid,depth+1);
T[t].r = maketree(mid+1,r,depth+1);

return t;
}

void find(int v,int sx,int tx,int sy,int ty,int depth,vector<Point> &ans){//寻找范围内的点
int x = P[T[v].location].x;
int y = P[T[v].location].y;

if(sx<=x&&x<=tx&&sy<=y&&y<=ty)
ans.push_back(P[T[v].location]);

if(depth%2==0){//按x和y分层的构造方式,采取对应的分层查找方法
if(T[v].l!=NIL&&x>=sx)
find(T[v].l,sx,tx,sy,ty,depth+1,ans);
if(T[v].r!=NIL&&x<=tx)
find(T[v].r,sx,tx,sy,ty,depth+1,ans);
}
else{
if(T[v].l!=NIL&&y>=sy)
find(T[v].l,sx,tx,sy,ty,depth+1,ans);
if(T[v].r!=NIL&&y<=ty)
find(T[v].r,sx,tx,sy,ty,depth+1,ans);
}
}

int main(){
int x,y;
scanf("%d", &N);
for(int i=0;i<N;i++){
scanf("%d %d", &x, &y);
P[i] = Point(i,x,y);
T[i].l = T[i].r = T[i].p = NIL;
}

np = 0;
int root = maketree(0,N,0);
//printf("%d%d\n",root,P[T[root].location]);
int n;
scanf("%d", &n);
int sx,tx,sy,ty;
vector<Point> result;

for(int j=0;j<n;j++){
scanf("%d %d %d %d",&sx,&tx,&sy,&ty);
result.clear();
find(root,sx,tx,sy,ty,0,result);
sort(result.begin(),result.end());
for(int i=0;i<result.size();i++)
result[i].print();
printf("\n");
}
return 0;
}


Measured memory_bytes: 15856
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)

const int INF = 1e9 + 10;

int N;
vector<P> G[200005];
int height[200005];

void dfs(int v, int p, int h) {
    height[v] = h;
    for (auto uw : G[v]) {
        if (uw.first == p) continue;
        if (uw.second & 1) dfs(uw.first, v, 1 - h);
        else dfs(uw.first, v, h);
    }
}

int main() {
    cin >> N;
    rep(i,N-1) {
        int u, v, w;
        cin >> u >> v >> w;
        --u, --v;
        G[u].emplace_back(v,w);
        G[v].emplace_back(u,w);
    }
    dfs(0, -1, 1);
    rep(i,N) {
        cout << height[i] << endl;
    }
}

Measured memory_bytes: 14564
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    int ans = 0;
    rep(i, n-2) {
        vi b;
        b.pb(a[i]);
        b.pb(a[i+1]);
        b.pb(a[i+2]);
        sort(all(b));
        if(b[1] == a[i+1]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
snk=[0]*n
for i in range(k):
	d=int(input())
	a=list(map(int,input().split()))
	for i in a:
		snk[i-1]+=1
cnt=0
for i in snk:
	if i==0:
		cnt+=1
print(cnt)

Measured memory_bytes: 9192
//url:
//problem name: Brick Break

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N;
    int M; 
    cin >> N >> M;
    vector<int> dist(N,-1);
    vector<vector<int>> G(N);
    REP(i,M) {
        int a,b; cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    queue<int> que;
    dist[0] = 0;
    que.push(0);

    while (!que.empty()) {
        int v = que.front(); 
        que.pop();
        for (int nv : G[v]) {
            if (dist[nv] != -1) continue; 
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }

    if(dist[N-1] != 2) cout << "IMPOSSIBLE" << endl;
    else cout << "POSSIBLE" << endl;
}

Measured memory_bytes: 13168
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

int main() {
	string O, E; cin >> O >> E;
	rep(i, 0, O.size()) {
		cout << O[i];
		if (E[i]) {
			cout << E[i];
		}
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define maxn 3010
using namespace std;
const int md=1e9+7;
const int invt=5e8+4;

int ksm(ll a,ll b){
	ll res=1;
	while(b){
		if (b&1) res=res*a%md;
		a=a*a%md;b>>=1;
	}
	return res;
}

void mul(int &x,int y){
	x=1ll*x*y%md;
}

int n,Q,a[maxn];
int f[maxn][maxn];

void Pre(){
	for (int i=1;i<=n;++i)
	for (int j=1;j<=n;++j)
	f[i][j]=(bool)(a[i]>a[j]);
}

void Solve(int u,int v){
	int fu[maxn],fv[maxn];
	for (int i=1;i<=n;++i)
	fu[i]=f[u][i],fv[i]=f[v][i];
	for (int i=1;i<=n;++i)
	mul(fu[i],invt),mul(fv[i],invt);
	for (int i=1;i<=n;++i)
	if (i!=u) (fu[i]+=(1ll*f[v][i]*invt)%md)%=md;
	(fu[v]+=(1ll*f[v][u]*invt)%md)%=md;
	for (int i=1;i<=n;++i)
	if (i!=v) (fv[i]+=(1ll*f[u][i]*invt)%md)%=md;
	(fv[u]+=(1ll*f[u][v]*invt)%md)%=md;
	int gu[maxn],gv[maxn];
	for (int i=1;i<=n;++i)
	gu[i]=f[i][u],gv[i]=f[i][v];
	for (int i=1;i<=n;++i)
	mul(gu[i],invt),mul(gv[i],invt);
	for (int i=1;i<=n;++i)
	if (i!=u) (gu[i]+=(1ll*f[i][v]*invt)%md)%=md;
	(gu[v]+=(1ll*f[u][v]*invt)%md)%=md;
	for (int i=1;i<=n;++i)
	if (i!=v) (gv[i]+=(1ll*f[i][u]*invt)%md)%=md;
	(gv[u]+=(1ll*f[v][u]*invt)%md)%=md;
	for (int i=1;i<=n;++i)
	f[u][i]=fu[i],f[v][i]=fv[i];
	for (int i=1;i<=n;++i)
	f[i][u]=gu[i],f[i][v]=gv[i];
}

void Calc(){
	int ans=0;
	for (int i=1;i<=n;++i)
	for (int j=i+1;j<=n;++j)
	(ans+=f[i][j])%=md;
	mul(ans,ksm(2,Q));
	printf("%d\n",ans);
}

int main(){
	scanf("%d%d",&n,&Q);
	for (int i=1;i<=n;++i)
	scanf("%d",a+i);
	Pre();
	for (int i=1,u,v;i<=Q;++i)
	scanf("%d%d",&u,&v),
	Solve(u,v);
	Calc();
	return 0;
}

Measured memory_bytes: 35584
M = 10**9 + 7
a = [1] + [0] * 12
p = 1
for c in reversed(input()):
    r = range(0, p * 10, p) if c == '?' else (p * int(c),)
    a = [sum(a[(i - j) % 13] for j in r) % M for i in range(13)]
    p = p * 10 % 13
print(a[5])


Measured memory_bytes: 47196
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll inf=1e18;

//

int main(void){
	ll h,w,ans=inf;
	cin>>h>>w;
	rep(i,h){
		if(((h-i)-(h-i)/2*2)*w>(w-w/2*2)*(h-i)){
			ans=min(ans,max({i*w,w/2*(h-i),(w-w/2)*(h-i)})-min({i*w,w/2*(h-i),(w-w/2)*(h-i)}));
		}else{
			ans=min(ans,max({i*w,(h-i)/2*w,(h-i-(h-i)/2)*w})-min({i*w,(h-i)/2*w,(h-i-(h-i)/2)*w}));
		}
	}
	rep(i,w){
		if(((w-i)-(w-i)/2*2)*h>(h-h/2*2)*(w-i)){
			ans=min(ans,max({i*h,h/2*(w-i),(h-h/2)*(w-i)})-min({i*h,h/2*(w-i),(h-h/2)*(w-i)}));
		}else{
			ans=min(ans,max({i*h,(w-i)/2*h,(w-i-(w-i)/2)*h})-min({i*h,(w-i)/2*h,(w-i-(w-i)/2)*h}));
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const ll mod = 1000000007;
const ll INF = mod * mod;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
typedef vector<string> svec;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
//#define int long long

void solve() {
	int H, W, h, w; cin >> H >> W >> h >> w;
    cout << (H - h) * (W - w) << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::cmp::{max,min};
fn main(){
    input!{
        n:i64,
        m:i64,
        lrm:[(i64,i64);m],
    }
    let mut left_max = 1;
    let mut right_min = n;
    for &(l,r) in &lrm{
        left_max = max(l,left_max);
        right_min = min(r,right_min);
    }
    let ans = if right_min >= left_max {
        right_min - left_max + 1
    } else {
        0
    };
    println!("{}",ans);
}

Measured memory_bytes: 6396
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        int n = in.nextInt();
        int m = in.nextInt();

        List<S> l = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            l.add(new S(in.nextInt(), in.nextInt()));
        }

        Collections.sort(l);

        int c = 0;
        long t = 0;
        for (int i = 0; i < n; i++) {
            S s = l.get(i);
            if (c + s.number >= m) {
                t += (long)s.price * (m - c);
                break;
            }
            t += (long)s.price * s.number;
            c += s.number;
        }

        out.println(t);
    }

    static class S implements Comparable<S> {
        int price;
        int number;

        S(int p, int n) {
            price = p;
            number = n;
        }

        @Override
        public int compareTo(S o) {
            return price - o.price;
        }
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}

Measured memory_bytes: 44084