akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define fs first
#define sc second
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<tuple<ll,ll>> vtl;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

void solve(){
    //abc120c
    string s;
    cin>>s;
    ll ans,minr=0,mini=0;
    rep(i,s.size()){
      if(s[i]=='0')minr++;
      else mini++;
    }
  ans=min(minr,mini);//0と1の個数のうち少ない方を2倍→01,10erase
    cout<<ans+ans;
}

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

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

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 
#define gre(n) greater<n>()

typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 1000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
const dou pi=3.141592653589793;

int main(){
    std::vector<int> a(3);
    rep(i,3)std::cin >> a[i];
    sort(all(a));
    int k;
    std::cin >> k;
    rep(i,k)a[2]*=2;
    std::cout << sum(a) << std::endl;
}

Measured memory_bytes: 256
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


int main(){
  int X; cin >> X;
  bool gosei[200000] = {};
  for(int i=2; i*i<=200000; i++){
    for(int j=2*i; j<=200000; j+=i){
      gosei[j] = true;
    }
  }
  gosei[0] = true; gosei[1] = true;
  for(int i=X; i<=200000; i++){
    if(!(gosei[i])) {cout << i << endl; break;}
  }
 
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
#define rep(i, j) for (int i = 0; i < j; i++)
using namespace std;
using ll = long long;

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

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

int main() {
    ll ans = 0;
    int n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;

    int current = 0;
    int kaigai = 0;
    for (int i = 0; i < n; i++) {
        string can = "No";
        
        if (s[i] == 'a' && a + b > current) {
            can = "Yes";
            current++;
        }
        else if(s[i] == 'b' && a + b > current && kaigai < b) {
            can = "Yes";
            current++;
            kaigai++;
        }
        cout << can << endl;
    }

	return 0;
}


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

int main(){	
  	string S;
  	cin >> S;
  	if(S == "Sunny"){
    	cout << "Cloudy" << endl;
    }else if(S == "Rainy"){
    	cout << "Sunny" << endl;
    }else if(S == "Cloudy"){
    	cout << "Rainy" << endl;
    }
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<vector>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include<iomanip>
#include<set>
#include<unordered_map>
using namespace std ;

#define MAXN 100007

string a[ 2 ] ;
int pref[ 2 ][ MAXN ] ;

void input ( ) {
    for ( int i = 0 ; i < 2 ; ++ i ) {
        cin >> a[ i ] ;
        int sz = a[ i ].size ( ) ;
        for ( int j = 1 ; j <= sz ; ++ j ) {
            pref[ i ][ j ] = pref[ i ][ j - 1 ] ;
            if ( a[ i ][ j - 1 ] == 'A' ) { ++ pref[ i ][ j ] ; }
            else { pref[ i ][ j ] += 2 ; }
        }
    }
}

void solve ( ) {
    int q ;
    int x , y , z , t ;
    cin >> q ;
    while ( q -- ) {
        cin >> x >> y >> z >> t ;
        int h1 = pref[ 0 ][ y ] - pref[ 0 ][ x - 1 ] ;
        int h2 = pref[ 1 ][ t ] - pref[ 1 ][ z - 1 ] ;
        h1 %= 3 ; h2 %= 3 ;
        if ( h1 == h2 ) { cout << "YES\n" ; }
        else { cout << "NO\n" ; }
        
    }
}


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


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

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;

const int MAXN = 500100, MAXK = 25;
const ll MOD = 1e9+7;

bool exists[30];
vi pos[30];

int main()
{
    FAST_IO;

    string s, t; cin >> s >> t;
    FOR(i, 0, s.size()-1) {
        exists[s[i]-'a'] = true;
        pos[s[i]-'a'].pb(i);
    }


    for (char c : t) {
        if (!exists[c-'a']) {
            cout << -1 << endl;
            return 0;
        }
    }

    ll ans = (ll) pos[t[0]-'a'][0] + 1;
    int last = pos[t[0]-'a'][0];
    FOR(i, 1, t.size()-1) {
        int c = t[i]-'a';
        auto it = upper_bound(pos[c].begin(), pos[c].end(), last);
        if (it != pos[c].end()) {
            ans += (ll)(*it - last);
            last = *it;
        } else {
            ans += (ll)(s.size()-1 - last);
            ans += (ll)(pos[c][0]+1);
            last = pos[c][0];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1228
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int a,b,c,d; cin >> a >> b >> c >> d;
    int start = max(a,c);
    int stop = min(b,d);

    cout << max(0,stop - start) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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; }

int n;
vector<int> G[5050];
int x[5050];
int dp[5050];

void dfs(int v = 0, int p = -1) {
  int sum = 0;
  vector<int> s;
  for (int u: G[v]) {
    if (u == p) continue;
    dfs(u, v);
    sum += max(x[u], dp[u]);
    dp[v] += min(x[u], dp[u]);
    s.push_back(abs(x[u] - dp[u]));
  }
  if (sum <= x[v]) return;
  set<int> res;
  res.insert(0);
  for (int y: s) {
    set<int> nxt = res;
    for (int z: res) nxt.insert(y + z);
    res = nxt;
  }
  if (res.lower_bound(sum - x[v]) == res.end()) {
    cout << "IMPOSSIBLE\n";
    exit(0);
  }
  dp[v] += *res.lower_bound(sum - x[v]);
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(25);

  cin >> n;
  FOR(i, 1, n) {
    int v;
    cin >> v;
    v--;
    G[v].push_back(i);
    G[i].push_back(v);
  }
  rep(i, n) cin >> x[i];

  dfs();
  cout << "POSSIBLE\n";




  




  
  return 0;
}

Measured memory_bytes: 8680
[r,c] = raw_input().split()
r = int(r)
c = int(c)
M = []
V = []
for y in range(0,r):
    s = raw_input().split()
    k = []
    for x in range(0,c):
        v = int(s[x])
        k.append(v)
    M.append(k)
    
for y in range(0,c):
    s = int(raw_input())
    V.append(s)
    

for y in range(0,r):
    ss = 0
    for x in range(0,c):
        ss = ss + M[y][x] * V[x]
    print ss

Measured memory_bytes: 4552
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var w, h, x, y float64
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &w, &h, &x, &y)
	fmt.Printf("%v ", w*h/2)
	if x+x == w && y+y == h {
		fmt.Println(1)
	} else {
		fmt.Println(0)
	}
}


Measured memory_bytes: 1840
N = int(input())
c = list(input())

w = 0
r = 0
for i in range(N):
  if c[i] == "W":
    w += 1
  else:
    r += 1

cnt = 0
for i in range(r):
  if c[i] == "W":
    cnt += 1

print(cnt)

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

int main(){
  long long n;
  cin >> n;
  long long R[200000];
  for (int i=0;i<n;i++){
    cin >> R[i];
  }
  long long maxv = -2 * 1e9;
  long long minv = R[0];
  for (int i=1;i<n;i++){
    maxv = max(maxv,R[i]-minv);
    minv = min(minv,R[i]);
  }
  cout << maxv << endl;
}



Measured memory_bytes: 4648
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe
int digit(int a){
    int count = 0;
    for (int i = 0; i < a; i++)
    {   if (a == 0)
        {
            break;
        }else
        {
            a = a/10;
            count++;
        }     
    }
    return count;
}
//pow(x,n) == x^n

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

int a,b,c,d;
cin >> a  >> b >> c >> d;
if (b < c || d < a)
{
    cout << 0 << endl;
}else
{
    cout << min(b,d)-max(a,c) << endl;
}



//////////////////////////////////////////////////////
return 0;}

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

import static java.lang.Math.*;

public class Main {
    class Reader {
        BufferedReader in;

        Reader() throws IOException {
            in = new BufferedReader(new InputStreamReader(System.in));
        }

        Reader(String name) throws IOException {
            in = new BufferedReader(new FileReader(name));
        }

        StringTokenizer tokin = new StringTokenizer("");

        String next() throws IOException {
            if (!tokin.hasMoreTokens()) {
                tokin = new StringTokenizer(in.readLine());
            }
            return tokin.nextToken();
        }

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

        boolean hasNext() throws IOException {
            if (tokin.hasMoreTokens()) {
                return true;
            } else {
                String s = in.readLine();
                while (s != null && s.length() == 0) {
                    s = in.readLine();
                }
                if (s == null) {
                    return false;
                } else {
                    tokin = new StringTokenizer(s);
                    return true;
                }
            }
        }
    }

    class Writer {
        PrintWriter cout;

        Writer() throws IOException {
            cout = new PrintWriter(System.out);
        }

        Writer(String name) throws IOException {
            cout = new PrintWriter(new FileWriter(name));
        }

        StringBuilder out = new StringBuilder();

        void print(Object a) {
            out.append(a);
        }

        void close() {
            cout.print(out.toString());
            cout.close();
        }
    }

    void run() throws IOException {
        Reader in = new Reader();
        Writer out = new Writer();
        int x = in.nextInt();
        if (x == 1) {
            out.print(0);
        } else {
            out.print(1);
        }
        out.close();
    }

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

Measured memory_bytes: 32704
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include <cmath>

using namespace std;

int i,j;

int main()
{
  cin>>i>>j;
  if(j>=i) cout<<"unsafe";
  else cout <<"safe";
  
}

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

int main() {
    int n, R[200001], min = 2e9, max = -2e9;
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> R[i];

    for (int i = 0; i < n; ++i) {
        if (R[i] - min > max) max = R[i] - min;
        if (R[i] < min) min = R[i];
    }

    cout << max << endl;

    return 0;
}


Measured memory_bytes: 3856
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s, t;
    cin >> s >> t;
    int n = s.length();
    int m = t.length();
    vector<string> v;
    string k = s;
    if(n < m)
    {
        cout << "UNRESTORABLE" << endl;
    }
    else
    {
        int c = 0;
        for(int i = 0; i < n-m+1; i++)
        {
            for(int j = 0; j < m; j++)
            {
                if(s[i+j] != t[j] && s[i+j] != '?')
                {
                    c = 1;
                }
                else
                {
                    k[i+j] = t[j];
                }
            }
            if(c == 0)
            {
                for(int j = 0; j < n; j++)
                {
                    if(k[j] == '?')
                    {
                        k[j] = 'a';
                    }
                }
                v.push_back(k);
            }
            k = s;
            c = 0;
        }
        
        if(v.empty())
        {
            cout << "UNRESTORABLE" << endl;
        }
        else
        {
            string Ans = v[0];
            for(int i = 0; i < v.size(); i++)
            {
                if(Ans > v[i])
                {
                    Ans = v[i];
                }
            }
            cout << Ans << endl;
        }
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 10000

int main(){
  int i, j, n, q, a, A[N], count=0;

  scanf("%d", &n);
  for(i=0; i<n; i++){
    scanf("%d", &A[i]);
  }
  scanf("%d", &q);
  for(i=0; i<q; i++){
    scanf("%d", &a);
    for(j=0; j<n; j++){
      if(a == A[j]){
	count++;
	break;
      }
    }
  }

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

  return 0;
}



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

using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define REP(i, n) for(int i=1;i<=n;i++)
typedef long long ll;

ll n, a, b;
vector<ll> h;

bool check(ll m) {
	vector<ll> temp(n);
	rep(i, n) {
		temp[i] = h[i];
		temp[i] -= b * m;
	}
	ll count = 0;
	rep(i, n) {
		if (temp[i] <= 0) continue;
		count += (temp[i] + (a - b - 1)) / (a - b);
	}
	return count <= m;
}


int main() {
	cin >> n >> a >> b;
	h.resize(n);
	rep(i, n) cin >> h[i];
	ll r = 1e+9;
	ll l = 0;
	while (r - l > 1) {
		ll m = (r + l) / 2;
		if (check(m)) {
			r = m;
		} else {
			l = m;
		}
	}
	cout << r << endl;
	return 0;
}



Measured memory_bytes: 4732
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	n := getNextInt(scanner)
	tt := make([]int64, n)
	aa := make([]int64, n)
	var tm, am int64
	for i := 0; i < n; i++ {
		tt[i] = getNextInt64(scanner)
		aa[i] = getNextInt64(scanner)
		if i == 0 {
			tm = tt[i]
			am = aa[i]
			continue
		}
		tk := int64(1)
		ak := int64(1)
		if tm > tt[i] {
			tk = (tm-tt[i])/tt[i] + 1
			if (tm-tt[i])%tt[i] > 0 {
				tk++
			}
		}
		if am > aa[i] {
			ak = (am-aa[i])/aa[i] + 1
			if (am-aa[i])%aa[i] > 0 {
				ak++
			}
		}
		k := tk
		if tk < ak {
			k = ak
		}
		tm = tt[i] * k
		am = aa[i] * k
	}

	fmt.Fprintln(writer, tm+am)

	writer.Flush()
}

func gcd64(m, n int64) int64 {
	if n == 0 {
		return m
	}
	return gcd64(n, m%n)
}


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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int n;
  cin >> n;
  int T = 1, A = 1;
  rep(i, n) {
    int t, a;
    cin >> t >> a;
    int b = max((T+t-1)/t, (A+a-1)/a);
    T = b*t;
    A = b*a;
  }
  cout << T + A << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<boost/range/irange.hpp>
#include<boost/multiprecision/cpp_int.hpp>
#include<boost/algorithm/string/classification.hpp>
#include<boost/algorithm/string/split.hpp>
#include<boost/algorithm/string/join.hpp>
#include<boost/algorithm/string/replace.hpp>
#include<boost/math/tools/minima.hpp>
#include<boost/pending/disjoint_sets.hpp>
using namespace std;
using boost::irange;
using boost::multiprecision::cpp_int;
using boost::algorithm::split;
using boost::is_any_of;
using boost::algorithm::join;
using boost::algorithm::replace_all;
using boost::math::tools::brent_find_minima;
typedef long long ll;
ll max(ll a, ll b){ 
	if(a >= b) return a;
	else if(a < b) return b;
}
int main(){
	int w, h, n;
	cin >> w >> h >> n;
	int x_head = w, x_tail = 0, y_head = h, y_tail = 0; 
	for(int i = 0; i < n; i++){
		int x, y, a;
		cin >> x >> y >> a;
		if(a==1){
			x_tail = max(x, x_tail);
		}else if(a==2){
			x_head = min(x_head, x);
		}else if(a==3){
			y_tail = max(y, y_tail);
		}else if(a==4){
			y_head = min(y, y_head);
		}
	}
	int ans = 0;
	if((x_head-x_tail) > 0 && (y_head-y_tail) > 0){
		ans = (x_head-x_tail)*(y_head-y_tail);
	}
	cout << ans << endl;
}   



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <ctype.h>
#include <stdlib.h>
using namespace std;

int main()
{
    int r;
    cin >> r;
    int ans = (r * r) / 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
int divr[maxn];
/*ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}*/
void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
 
 
 
 
 












int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    int neg=0,zero=0;
    ll sum=0;
    int mn=INT_MAX;
    for(int i=0;i<n;i++){
         if(a[i]<0)neg++;
         else if(a[i]==0)zero++;
         sum+=abs(a[i]);
         mn=min(mn,abs(a[i]));
    }
    if(neg%2==0)cout<<sum;
    else
    {
         if(zero!=0)cout<<sum;
         else cout<<sum-2*mn;

    }
     
}







 
 

















Measured memory_bytes: 640
#include <iostream>
#include <string>

using namespace std;

typedef long long int lli;

int main(int argc, char const *argv[]) {
  lli n;
  cin >> n;
  string s;
  if (n%2==0) s += to_string(0);
  else {
    s += to_string(1);
    n--;
  }
  n/=-2;
  while (n!=0) {
    if (n%2==0) {
      s.insert(0,to_string(0));
    }
    else {
      s.insert(0,to_string(1));
      --n;
    }
    n /= -2;
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 256
let solve l =
  let sl = List.sort compare l in
  match sl with
    a :: b :: c :: _ -> if a + b = c then "Yes" else "No"
  | _ -> ""

let () =
  Printf.printf "%s\n" @@ Scanf.scanf "%d %d %d\n" (fun x y z -> solve [x;y;z])



Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

int n, k;
int d[9];

bool f(int x){
    while(x > 0){
        int x1 = x % 10;
        x /= 10;
        rep(i, k){
            if(x1 == d[i]) return false;
        }
    }
    return true;
}


int main(){
    cin >> n >> k;
    rep(i, k) cin >> d[i];
    for (int i = n; true; i++){
        if(f(i)){
            cout << i << endl;
            return 0;
        }
    }
    
}


Measured memory_bytes: 256
use proconio::{fastout, input, marker::Chars};
#[allow(unused_mut)]
#[fastout]
fn main() {
    input! {
        s: Chars,
        t: Chars
    }
    let res: usize = s.iter().zip(t.iter()).filter(|a| a.0 == a.1).count();
    println!("{}", res);
}


Measured memory_bytes: 2156
z=int(input())
ind=0
c=0
for i in range(z):
  D=list(map(int, input().split()))
  if D[0]==D[1]:
    ind+=1
    if ind==3:
      c=1
      break
  else:
    ind=0
if c==1:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9184
#include <iostream>

using namespace std;

int n,m,c[20];
int dp[20][50001];

int main() {
	cin >> n >> m;
	for(int i = 0;i < m;i++) cin >> c[i];
	for(int i = 0;i < 20;i++)for(int j = 1;j < 50001;j++) dp[i][j] = 100000;
	for(int i = 0;i < m;i++) {
		for(int j = 0;j <= n;j++) {
			if(i != 0)
				dp[i][j] = min(dp[i-1][j],dp[i][j]);
			if(j >= c[i])
				dp[i][j] = min(dp[i][j-c[i]]+1,dp[i][j]);
		}
	}
	cout << dp[m-1][n] << endl;
}



Measured memory_bytes: 7000
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, int> P;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

int main(void){
	int n;
	cin >> n;
	cout << ((n/10==9 || n%10==9)?"Yes":"No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
using namespace std;
int l[200010], r[200010];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N,M;
    cin>>N>>M;
    rep(i,0,N){
        int L,R;
        cin>>L>>R;
        if(L) l[L-1]++;
        if(R<=M) r[R-1]++;
    }
    rer(i,M-1,0){
        l[i]+=l[i+1];
    }
    rep(i,1,M){
        r[i]+=r[i-1];
    }
    int res=1e8;
    int ans=0;
    rep(i,0,M){
        res=min(res-1,l[i]);
        if(res==0){
            ans=i;
            break;
        }
        if(i==M-1) ans=M;
    }
    res=1e8;
    rep(i,0,M){
        res=min(res-1,r[M-1-i]);
        if(res==0){
            ans+=i;
            break;
        }
        if(i==M-1) ans+=M;
    }
    cout <<max(0,N-min(ans,M))<<"\n";
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) {rep(i,x.size()) cout << x[i] << " "; cout << endl;}
template<class T> bool chmin(T &a, T x) {if(a>x) {a=x;return 1;}return 0;}
template<class T> bool chmax(T &a, T x) {if(a<x) {a=x;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9+7;
const ll inf_l = 1e18;
const int MAX = 1e6;

const int mod = 1e9+7;
struct mint {
    ll x;
    mint (ll x = 0) : x((x%mod+mod)%mod) {}
    mint operator -() const {return mint(-x);}
    mint& operator +=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator -=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator *=(const mint a) {(x *= a.x) %= mod; return *this;}
    mint operator +(const mint a) const {return mint(*this) += a;}
    mint operator -(const mint a) const {return mint(*this) -= a;}
    mint operator *(const mint a) const {return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    mint inv() const {return pow(mod-2);}
    mint operator /=(const mint a) {return *this *= a.inv();}
    mint operator /(const mint a) {return mint(*this) /= a;}
};
istream& operator >>(istream &is, const mint &a) {return is >> a.x;}
ostream& operator <<(ostream &os, const mint &a) {return os << a.x;}

int main() {
    int n, k; cin >> n >> k;
    vint a(n);
    rep(i,n) cin >> a[i];
    mint ans = 0;
    rep(i,n) {
        mint x = 0, y = 0;
        for (int j = 0; j < i; j++) {
            if (a[i] > a[j]) x += 1;
        }
        for (int j = i+1; j < n; j++) {
            if (a[i] > a[j]) y += 1;
        }
        ans += y*k + (y+x)*k*(k-1)/2;
    }
    cout << ans << endl;
}

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

int main() {
  int k;
  vector<int> x(32);
  x = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

  cin >> k;
  cout << x.at(k - 1);
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::num::*;

fn main() {
    let mut a: i32 = read();
    let mut b: i32 = read();
    let mut c: i32 = read();
    let mut d: i32 = read();
    let mut e: i32 = read();
    let mut k: i32 = read();
    let mut x:Vec<i32> = [a,b,c,d,e].to_vec();
    let mut ans:String = "Yay!".to_string();
    for i in 0..5 {
        for j in i+1..5 {
            if (x[i as usize]-x[j as usize]).abs() >k {
                ans=":(".to_string();
                break;
            }
        }
    }
    println!("{}", ans);
}
fn read<T: FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_vec2<T: FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

Measured memory_bytes: 4352
#include <unistd.h>
#include <stdio.h>
 
int	main(void)
{
  char	str[27] = {0};
  int	i = 0;
  int	j = 0;
  
  read(0, str, 26);
  while (str[i])
  {
    j = i + 1;
    while (str[j])
    {
      if (str[i] == str[j])
      {
        printf("no");
        return (0);
      }
      j++;
    }
    i++;
  }
  printf("yes");
  return (0);
}

Measured memory_bytes: 1580
#include <iostream>
#include <string>
using namespace std;
int main(){
	string a, b;
	cin >> a >> b;
	int i,f=0;
	int l1=a.size();
	int l2=b.size();
	if(l1>l2)
		cout << "GREATER\n";
	else if(l1<l2)
		cout << "LESS\n";
	else {
		for(i=0;i<l1;i++){
			if(a[i]>b[i]){
				f=1;
				break;
			}
			if(a[i]<b[i]){
				f=-1;
				break;
			}
		}
		if(f==1)
			cout << "GREATER\n";
		else if(f==-1)
			cout << "LESS\n";
		else
			cout << "EQUAL\n";
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int K;

  cin >> K;

  if(K==4){
  cout << 2 << endl;
  }

  else if(K==6){
  cout << 2 << endl;
  }

  else if(K==8){
  cout << 5 << endl;
  }

  else if(K==9){
  cout << 2 << endl;
  }

  else if(K==10){
  cout << 2 << endl;
  }

  else if(K==12){
  cout << 5 << endl;
  }

  else if(K==14){
  cout << 2 << endl;
  }

  else if(K==16){
  cout << 14 << endl;
  }

  else if(K==18){
  cout << 5 << endl;
  }

  else if(K==20){
  cout << 5 << endl;
  }

  else if(K==21){
  cout << 2 << endl;
  }

  else if(K==22){
  cout << 2 << endl;
  }

  else if(K==24){
  cout << 15 << endl;
  }

  else if(K==25){
  cout << 2 << endl;
  }

  else if(K==26){
  cout << 2 << endl;
  }

  else if(K==27){
  cout << 5 << endl;
  }

  else if(K==28){
  cout << 4 << endl;
  }

  else if(K==30){
  cout << 4 << endl;
  }

  else if(K==32){
  cout << 51 << endl;
  }

  else{
  cout << 1 << endl;
  }
 


  return 0;
}

Measured memory_bytes: 256
/*
     Author: Wasi Ur Rahman
     RMSTU
*/

#include <bits/stdc++.h>
using namespace std;
#define  fast           ios::sync_with_stdio(false);cin.tie(0)
int pos[27] = {0};
int main()
{
    fast;
    int n,m;
    cin >> n >> m;
    int i,j;
    int sum = 0;
    int arr[n];
    for(i = 0;i<n;i++)
    {
        cin >> arr[i];
        sum += arr[i];
    }
    sort(arr,arr+n);
    float item = sum /(4.0*m);
    int fin = 0;
    for(i = 0;i<n;i++)
    {
        if(arr[i] >= item)
           fin++;
    }
    if(fin >= m)
        cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
const int Maxn=1e6+5;
const int inf=0x3f3f3f3f;
class union_find
{
	protected:
		int par[Maxn],rank[Maxn];
	public:
		void init(int n){for (int i=0;i<n;rem(i++));}
		void rem(int i){par[i]=i;rank[i]=0;}
		int find(int x){return x==par[x]?x:par[x]=find(par[x]);}
		void unite(int x,int y)
		{
			x=find(x);
			y=find(y);
			if (x==y) return;
			if (rank[x]<rank[y]) par[x]=y;
			else
			{
				par[y]=x;
				if (rank[x]==rank[y]) rank[x]++;
			}
		}
		bool same(int x,int y) {return find(x)==find(y);}
};
union_find uf;
vector <int> vec[Maxn];
vector <pair <int,int> > query[Maxn];
int id[Maxn],n,m;
bool use[Maxn];
int dist[Maxn];
int main()
{
	cin>>n>>m;
	for (int i=0;i<m;++i)
	{
		int p,q,c;
		cin>>p>>q>>c;p--;q--;
		query[c].push_back({p,q});
	}
	int sz=n;
	for (int i=0;i<Maxn;++i)
	{
		if (query[i].empty()) continue;
		for (auto &p:query[i])
		{
			uf.rem(p.first);
			uf.rem(p.second);
			id[p.first]=id[p.second]=~0;
			use[p.first]=use[p.second]=false;
		}
		for (auto &p:query[i]) uf.unite(p.first,p.second);
		for (auto &p:query[i])
		{
			if (!use[p.first])
			{
				use[p.first]=true;
				int r=uf.find(p.first);
				if (!~id[r]) id[r]=sz++;
				vec[p.first].push_back(id[r]);
				vec[id[r]].push_back(p.first);
			}
			if (!use[p.second])
			{
				use[p.second]=true;
				int r=uf.find(p.second);
				if (!~id[r]) id[r]=sz++;
				vec[p.second].push_back(id[r]);
				vec[id[r]].push_back(p.second);
			}
		}
	}
	queue <int> q;
	q.push(0);
	memset(dist,63,sizeof(dist));
	for (dist[0]=0;!q.empty();)
	{
		int v=q.front();q.pop();
		for (auto &x:vec[v])
		{
			if (dist[x]==inf)
			{
				dist[x]=dist[v]+1;
				q.push(x);
			}
		}
	}
	if (dist[n-1]==inf) cout<<"-1\n";
	else cout<<dist[n-1]/2<<endl;
	return 0;
}

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

int	main(void)
{
	int n;
	cin >> n;
	n = n % 10;
	if (n == 3) cout << "bon" << endl;
	else if (n == 0 || n == 1 || n == 6 || n == 8) cout << "pon" << endl;
	else cout << "hon" << endl;
	return (0);
}


Measured memory_bytes: 3628
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 100000


int main(){
	int a[N];
	int n,m, k;
	int x, y;
	scanf("%d %d", &n,&m);
	for (int i = 0; i < n; i++){
		a[i] = n;
	}
	for (int i = 0; i < m; i++){
		scanf("%d %d", &x, &y);
		x--;
		y--;
		if (y < a[x])a[x] = y;
	}
	k = n;
	for (int i = 0; i < n; i++){
		if (a[n - i - 1] < k)k = a[n - i - 1];
		else a[n - i - 1] = k;
	}
	k = 0;
	x = 0;
	while (a[x] < n){
		k++;
		x = a[x];
	}

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


	return 0;
}

Measured memory_bytes: 512
//
//AtCoder Grand Contest 009
//A
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    vector<ll> a(n);
    vector<ll> b(n);
    REP(i, n) cin >> a[i] >> b[i];

    ll ans=0;
    REPD(i,n){
        ll aa = a[i]+ans;
        if ((aa%b[i])!=0){
            ans+=(b[i]-(aa%b[i]));
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4824
#pragma comment(linker, "/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
//#define dprintf(...) 
#define hash _hash
#define next _next
//#define dprintf(...) fprintf(outFile,__VA_ARGS__)
 
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 200010
 
template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}
 
//FILE* outFile;
inline void add(int &a,int b){a+=b;while(a>=mod)a-=mod;}


int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=ans*(ll)a%mod;
        a=(ll)a*a%mod;b>>=1;
    }
    return ans;
}


pii a[N];
int main(){
	int i,j,k,ca=0,n=0,m;
	scanf("%d%d",&n,&m);
	rep(i,0,n)scanf("%d",&a[i].x),a[i].y=0;
	rep(i,0,m)scanf("%d",&a[i+n].x),a[i+n].y=1;
	sort(a,a+n+m);
	int x=0,y=0;
	ll ans=0;
	rep(i,0,n+m){
		if(a[i].y==0){
			ans+=1LL*a[i].x*(m+1-y);x++;
		}
		else{
			ans+=1LL*a[i].x*(n+1-x);y++;
		}
	}
	printf("%lld\n",ans);
    return 0;
}




Measured memory_bytes: 1920
a = [list(map(int, input().split())) for _ in range(3)]
n = int(input())
b = [int(input()) for _ in range(n)]
mark = [[False, False, False] for _ in range(3)]

for i in range(3):
    for j in range(3):
        if a[i][j] in b:mark[i][j] = True
ans = 'No'
for i in range(3):
    if mark[i][0] and mark[i][1] and mark[i][2]:
        ans = 'Yes'
        break

if ans != 'Yes':
    for j in range(3):
        if mark[0][j] and mark[1][j] and mark[2][j]:
            ans = 'Yes'
            break

if ans != 'Yes':
    if (mark[0][0] and mark[1][1] and mark[2][2]) or (mark[0][2] and mark[1][1] and mark[2][0]): ans = 'Yes'
print(ans)

Measured memory_bytes: 3064
while True:
    W,H=map(int,raw_input().split())
    if W==H==0:break
    C=[raw_input() for i in range(H)]
    table=[[""]*W for i in range(H)]
    ans=0
    for y in range(H):
        for x in range(W):
            if C[y][x].isdigit():
                a,b,c=table[y-1][x],table[y][x-1],C[y][x]
                if a==b=="":
                    table[y][x]=c
                elif a=="":
                    table[y][x]=b+c
                elif b=="":
                    table[y][x]=a+c
                elif int(a)>=int(b):
                    table[y][x]=a+c
                elif int(a)<int(b):
                    table[y][x]=b+c
                ans=ans if ans>int(table[y][x]) else int(table[y][x])
    print ans

Measured memory_bytes: 4356
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<21

using namespace std;

int main()
{
	int n;
	cin >> n;
	
	vector<pair<int,int> > v;
	long long dp[101][101];

	rep(i,n)
	{
		int a,b;
		cin >> a >> b;
		v.push_back(make_pair(a,b));
	}
	
	memset(dp,0x2,sizeof(dp));
	rep(i,n+1) dp[i][i] = 0;
	
	REP(i,1,n)
	{
		rep(j,n-i+1)
		{
			REP(k,j,j+i)
			{
				int cost = v[j].first * v[k].second * v[k+1].first *  v[j+i].second;
				dp[j][j+i] = min(dp[j][j+i],cost+dp[j][k]+dp[k+1][j+i]);
			}
		}
	}

	cout << dp[0][n-1] << endl;

	return 0;
}

Measured memory_bytes: 1276
#include<iostream>

#include<cmath>
#include<string>
#include <algorithm> 

#include <boost/format.hpp>

using namespace std;

# define p(s) cout << s << endl;
# define printStr(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) cout << (j ? "Yes" : "No") << endl;

string lpad(string l,int s,int n){
    string temp = to_string(n);
    string res = "";
    int loop = s - temp.size();
    while(loop--) res+=l;

    return res+temp;
}

int main()
{
    int a,b;
    cin >> a >> b ;

    printStr(a<=8 && b <= 8,"Yay!",":(");
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func nextInt() int {
    sc.Scan()
    i, _ := strconv.Atoi(sc.Text())
    return i
}

func nextIntArr(n int) []int {
    var a []int
    for i := 0; i < n; i++ {
        a = append(a, nextInt())
    }
    return a
}

// 数値を桁区切りのスライスにする
func digit(n int, list []int) []int {
   if n > 0 {
       return digit(n/10, append(list, n%10))
   }
   return list
}


func main() {
    sc.Split(bufio.ScanWords)
    n := nextInt()
    a := nextIntArr(n)
    alice := 0
    bob := 0

    sort.Sort(sort.Reverse(sort.IntSlice(a)))

    for i := 0; i < n; i++ {
        if i % 2 == 0 {
            alice += a[i]
        } else {
            bob += a[i]
        }
    }

    fmt.Println(alice - bob)
}


Measured memory_bytes: 640
import java.math.BigInteger;
import java.util.*;

public class Main {
	double EPS = 10.e-08;
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			long a = sc.nextLong()-1;
			long b = sc.nextLong();
			long c = sc.nextLong();
			long d = sc.nextLong();
			
			long lcm = lcm(c, d);
			
			long a1 = a / c;
			long a2 = a / d;
			long a3 = a / lcm;
			
			long b1 = b / c;
			long b2 = b / d;
			long b3 = b / lcm;
			long res1 = a - a1 - a2 + a3;
			long res2 = b - b1 - b2 + b3;
//			debug(res1, res2, a1, a2, a3, lcm);
//			debug(b, b1, b2, b3, res2, lcm);
			System.out.println(res2 - res1);
		}
	}
	
	private long gcd(long a, long b){
		if(b == 0)  return a;
		else        return gcd(b, a%b);
	}
	
	private long lcm(long a, long b){
		return a / gcd(a, b) * b;
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

	public static void main(String[] args) {
		new Main().doit();
	}

}


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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
#define INF (int)(1e9)
#define EPS (1e-7)
#define MOD ((ll)1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/
/*
int dx[4]={-1,0,1,0};//四方に移動
int dy[4]={0,-1,0,1};
*/
/*--------------------------------------------*/
/*--------------------------------------------*/
/*
ll factorial(ll n){
    if(n==1)return 1;
    return n*factorial(n-1);
}
ll lcm(ll A, ll B) {//最小公倍数
    ll a=A;
    ll b=B;
    if (a==0 || b==0) {return 0;}
    if (a<0) {a=-a;}
    if (b<0) {b=-b;}
    while(b>0) {
        ll c=a%b;
        a=b;
        b=c;
    }
    return A/a*B;
}

ll gcd(ll a,ll b){
    while(b!=0) {
        int t=b;
        b=a%b;
        a=t;
    }
    return a;
}

//入力はすべて正とする
bool is_prime(int n) {//素数判定o(√n)
    for (int i=2;i*i<=n;i++){
        if(n%i==0)return false;
    }
    return n!=1;//1の場合は例外
}

vector<ll> divisor(ll n){//約数の列挙o(√n)
    vector<ll> res;
    for(ll i=1;i*i<=n;i++) {
        if(n%i == 0){
        res.push_back(i);
        if(i!=n/i)res.push_back(n/i);
        }
    }
    return res;
}//vector<ll>k=divisor(n);rep(i,k.size())cout<<k[i]<<endl;//のように使う

map<ll,ll> prime_factor(ll n){//素因数分解o(√n)
    map<ll,ll>res;    
    for(ll i=2;i*i<=n;i++) {
        while (n%i==0) { 
            ++res[i];
            n/=i;
        }
    }
    if (n!=1)res[n]=1;
    return res;
}//map<ll,ll> k=prime_factor(n);for(auto i=k.begin();i!=k.end();i++){cout<<i->first<<" "<<i->second<<endl;}//みたいに使う

vector<ll> prime_list(ll n){//n以下の素数を全て見つける
    vector<ll> is_prime(n);//is_prime[i]が1ならiは素数
    for(ll i=2;i<=n;i++)is_prime[i]=1;//最初はみんな素数かも
    for(ll i=2;i*i<=n;i++){//素数の整数倍を消していく(√nまで)
        if(is_prime[i]){
            for(ll j=2*i;j<=n;j++){
                if(j%i==0){
                    is_prime[j]=0;                
                }
            }
        }
    }return is_prime;
}vector<ll>k=prime_list(n);REP(i,n){if(k[i])cout<<i<<endl;}のように使う
*/
/*--------------------------------------------*/


int main(){
    int n,m,x;cin>>n>>m>>x;
    V A(n);rep(i,m)cin>>A[i];
    int cntr=0;
    int cntl=0;
    rep(i,m){
        
        if(x<A[i]){
            cntr++;
        }
    }
    rep(i,m){
        
        if(x>A[i]){
            cntl++;
        }
    }
    cout<<min(cntr,cntl)<<endl;
}




Measured memory_bytes: 256
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.ST                 as ST
import qualified Data.Array.Unboxed            as AU
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import qualified Data.Foldable                 as DF
import           Data.Int
import qualified Data.IntMap                   as IM
import           Data.List
import qualified Data.Map                      as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Set                      as S
import qualified Data.Sequence                 as SQ
import           Data.Time
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
readInts n = replicateM n readInt
readString = map BS.unpack . BS.words <$> BS.getLine
readStrings n = replicateM n <$> readString
toPair [x, y] = (x, y)

main = do
  [n]<-readInt
  let a = if n `elem` (fmap (*) [1..9] <*> [1..9] ) then "Yes" else "No" in putStrLn a

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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (int i = j; i < (n); i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1e9;


int main(){

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

  for(int i=0;;i++){
    if(i*(a-1)+1>=b){out(i);return 0;}
  }

  return 0;
}


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

using namespace std;
using ll=long long;

int t;

const int mod=1e9+7;

void add_self(int &a, int b){
    a+=b;
    if(a>=mod)a-=mod;
}

void test_case(){
    int h,w;
    cin>>h>>w;
    vector<vector<char>>grid(h,vector<char>(w));
    vector<vector<int>>dp(h,vector<int>(w));
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin>>grid[i][j];
        }
    }
    dp[0][0]=1;
    for(int row=0; row<h; row++){
        for(int col=0; col<w; col++){
            if(col<w-1&&grid[row][col+1]=='.'){
                add_self(dp[row][col+1], dp[row][col]);
            }
            if(row<h-1&&grid[row+1][col]=='.'){
                add_self(dp[row+1][col], dp[row][col]);
            }
        }
    }
    cout<<dp[h-1][w-1]<<endl;
}

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

    t=1;
    while(t--){
        test_case();
    }

    return 0;
}

Measured memory_bytes: 8184