akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	//n := r.nextInt()
	r.Scan(true)
	b := r.nextStringArray().toInts()

	ans := 0
	for i := range b {
		w := b[i]
		if i > 0 {
			if w > b[i-1] {
				w = b[i-1]
			}
		}
		ans += w
	}
	ans += b[len(b)-1]
	fmt.Fprintln(stdout, ans)
}


Measured memory_bytes: 640
/* 
    Author - linpaws07 
*/
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define inf (int)1e9
#define f first
#define s second
#define eps 1e-9
#define PI 3.1415926535897932384626433832795
#define scd(t) scanf("%d",&t)
#define sclld(t) scanf("%lld",&t)
#define scc(t) scanf("%c",&t)
#define scs(t) scanf("%s",t)
#define scf(t) scanf("%f",&t)
#define sclf(t) scanf("%lf",&t)
#define memst(a, b) memset(a, (b), sizeof(a))
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<vi> vvi;
typedef map<int,int> mpii;
typedef set<int> seti;
typedef multiset<int> mseti;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int uint64;
#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define rp(i,n) for(int i=0;i<(n);i++)
#define fr(i,a,b) for(int i=(a);i<(b);i++)
#define fre(i,a,b) for(int i=(a);i<=(b);i++)
#define frd(i,a,b) for(int i=(a);i>=(b);i--)
inline bool eq(double a, double b) { return fabs(a-b) < 1e-9; }
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
auto start = high_resolution_clock::now();
inline void measure();

int64 w[102], v[102];
int64 dp[102][100002];
int main(){
    FAST
    //Do awesome things here
    int n, wt;
    cin >> n >> wt;
    fre(i, 1, n){
        cin >> w[i] >> v[i];
    }
    fre(i, 1, n){
        fre(j, 1, wt){
            if(j >= w[i]){
                dp[i][j] = v[i] + dp[i - 1][j - w[i]];
            }
            dp[i][j] = max(dp[i][j], dp[i - 1][j]);
        }
    }
    cout << dp[n][wt] << endl;
    return 0;
}


inline void measure(){
    auto stop = high_resolution_clock::now(); 
    auto duration = duration_cast<milliseconds>(stop - start);
    cout << duration.count() << endl;
}

Measured memory_bytes: 78336
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <stdarg.h>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int
main() {
  std::ios::sync_with_stdio(false);

  string s;
  cin>>s;

  int n = s.length();
  vector<int> h(n+1, 0);
  for (int i=0; i<=n; i++) 
    if ((i == 0 || s[i-1] == '>')
        && (i == n || s[i] == '<')) {
      h[i] = 0;
      for (int j=i-1; j>=0; j--) {
        if (s[j] != '>') break;
        h[j] = max(h[j], h[j+1]+1);
      }
      for (int j=i+1; j<=n; j++) {
        if (s[j-1] != '<') break;
        h[j] = max(h[j], h[j-1]+1);
      }
    }

  long long ans = 0;
  for (int i=0; i<=n; i++)
    ans += h[i];
  cout<<ans<<endl;

  return 0;
}



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


typedef long long ll;

int main()
{
    long long x, a, b, aux, ans = 1e12;

    cin >> x;


    aux = ceil(sqrt(x));
    for(int i=1; i<=aux; i++) {
        if(x%i != 0) continue;
        a = i;
        b = x/i;

        ans = min(ans, (a-1)+(b-1));
    }
    cout << ans << endl;

}

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

t,a = map(int,input().split())

h = list(map(int,input().split()))

ans = 1000000000000000000000000
memo = 0
for i in range(n):
    if ans > abs(a-(t-h[i]*0.006)):
        ans = abs(a-(t-h[i]*0.006))
        memo = i+1
print(memo)

Measured memory_bytes: 38256
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem B

if __name__ == '__main__':
    n = int(input())
    s = input()
    result = 0

    for i in range(1, len(s)):
        tmp = set(s[:i]) & set(s[i:])
        result = max(len(tmp), result)

    print(result)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.rbegin(), v.rend());//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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

const int V = 100005;
vector<int> to[V*2];
bool visited[V*2];

vector<int> cnt;

void dfs(int v){
    if(visited[v]) return;
    visited[v]=true;
    cnt[v/V]++;
    for(int nv:to[v]) dfs(nv);
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    REP(i,n){
        int x,y;
        cin>>x>>y;
        y+=V;
        to[x].push_back(y);
        to[y].push_back(x);
    }
    ll ans = 0;
    REP(i,V*2){
        if(visited[i]) continue;
        cnt = vector<int>(2);
        dfs(i);
        ans += (ll)cnt[0]*cnt[1];
    }
    ans -= n;
    cout<<ans<<endl;
}

Measured memory_bytes: 10240
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<deque>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
#include "stdio.h"
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;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const long long mod_const = 1e9+7;
using MIte = multimap<long, long, greater<long> >::iterator;

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

	// long long?
	int N, K;
	cin >> N >> K;

	vector<int> val;
	rep(i, N) {
		int tmp;
		cin >> tmp;
		val.push_back(tmp);
	}
	sort(val.begin(), val.end(), greater<int>());

	int ans = inf;
	for (int i = 0; i != N - K + 1; ++i) {
		ans = min(ans, val[i] - val[i + K - 1]);
	}

	cout << ans << endl;
	return 0;

}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

string str[4] = {"dream", "dreamer", "erase", "eraser"};

int main () {
	string s; cin >> s;
    reverse(all(s));
    rep(i, 4) reverse(all(str[i]));

    while (s.size() != 0) {
        bool flg = false;
        rep(i, 4) {
            string sub = s.substr(0, str[i].size());
            if (sub == str[i]) {
                s = s.substr(str[i].size());
                flg = true;
            }
        }
        if (!flg) {cout << "NO" << endl; return 0;}
    }
    cout << "YES" << endl;
}


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

long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

int main() {
  ll h;
  cin >> h;
  ll cnt = 0;
  while(h != 1) {
    h /= 2;
    cnt++;
  }
  ll ans = 0;
  for(int i = 0; i <= cnt; i++) {
    ans += modpow(2, i);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include "bits/stdc++.h"

using namespace std;

typedef unsigned long long ll;
typedef int                     integer;
#define int                     long long
#define ii                      pair<int,int>
#define vii                     vector<pair<int,int>>
#define vi                      vector<int>
#define vvi                     vector<vector<int>>
#define f(a,b,c)                for(int a=b;a<c;a++)
#define s(x)                    in>>x
#define s2(x,y)                 in>>x>>y
#define s3(x,y,z)               in>>x>>y>>z
#define s4(x,y,z,w)             in>>x>>y>>z>>w
#define p(x)                    out<<x<<endl
#define p2(x,y)                 out<<x<<" "<<y<<endl
#define pl(x)                   out<<x
#define p2l(x,y)                out<<x<<" "<<y
#define p1d(a,n)                for(int ix=0;ix<n;ix++) out<<a[ix]<<" "; out<<endl
#define p2d(a,n,m)              for(int ix=0;ix<n;ix++){ for(int jx=0;jx<m;jx++) out<<a[ix][jx]<<" "; out<<endl;}
#define range(v)                v.begin(),v.end()
#define w(x)                    while(x--)
#define rst(x)                  memset(x, -1, sizeof(x))
#define UNVISITED               -1
#define VISITED                 0
#define EXPLORED                2

class CLowElements {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n;
        s(n);
        vi a(n);
        f(i,0,n) s(a[i]);
        set<int> seen;
        int tot = 0;
        f(i,0,n){
            if(seen.empty() || *seen.begin() > a[i]){
                tot++;
            }
            seen.insert(a[i]);
        }
        out<<tot<<endl;
	}
};


integer main() {
	CLowElements solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define   mt         make_tuple
#define   Y            imag()
#define   X            real()
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define   angle(n)      atan2((n.imag()),(n.real()))
#define   vec(a,b)       ((b)-(a))
//#define   length(a)      hypot( (a.imag()),(a.real()) )
#define   normalize(a)      (a)/(length(a))
#define    dp(a,b)          (((conj(a))*(b)).real())
//#define    cp(a,b)          (((conj(a))*(b)).imag())
#define    lengthsqrt(a)       dp(a,a)
#define    rotate0( a,ang)    ((a)*exp( point(0,ang) ))
#define    rotateA(about,p,ang)   (rotate0(vec(about,p),ang)+about)
#define    reflection0(m,v)         (conj((v)/(m))*(m))
#define     reflectionA(m,v,p0)     (conj( (vec(p0,v))/(vec(p0,m)) ) * (vec(p0,m)) ) + p0
//#define     same(p1,p2)               ( dp(  vec(p1,p2),vec(p1,p2)) < eps )
#define     point                    complex<double>
#define outfile freopen("out.out", "w", stdout);
#define infile  freopen("in.in", "r", stdin);
#define PI acos(-1)
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-9);
using namespace std;
int dcmp(double a,double b){   return fabs(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(int num, int idx) {return ((num >> idx) & 1) == 1;}
ll setBit1(ll num, int idx) {return num | (1ll<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(int num, int idx) {return num ^ (1<<idx);}
void FS(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
const int N=509;
int ans[N][N],n;
void solve(int l,int r,int lv)
{
    if(l==r)
        return ;
    int m=(l+r)/2;
    for(int i=l;i<=m;i++)
    {
        for(int j=m+1;j<=r;j++)
        {
            ans[i][j]=lv;
            ans[j][i]=lv;
        }
    }
    solve(l,m,lv+1);
    solve(m+1,r,lv+1);
}
int main()
{
    cin>>n;
    solve(0,n-1,1);
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            cout<<ans[i-1][j-1]<<" ";
        }
        cout<<endl;
    }
}




















Measured memory_bytes: 1536
#include <stdio.h>          // printf(), scanf(), getchar()
#include <stdbool.h>

const char NUL = '\0';

bool
ope_line()
{
	char train[52];
	int t = 25, s = 25;
	for (int i = 0; i < 52; ++i)
		train[i] = NUL;

	int c = getchar();
	train[t] = c;

	int a = getchar();
	while (a != '\n' && a != EOF)
	{
		int b = getchar();
		c = getchar();
		if (a == '<' && b == '-')
		{
			train[--t] = c;

			if (t < s)
				s = t;
		}

		else if (a == '-' && b == '>')
			train[++t] = c;

		a = getchar();
	}

	printf("%s\n", &train[s]);

	if (a == EOF)
		return false;

	return true;
}

int
main(int argc, char **argv)
{
	int n = 0;
	int c = getchar();
	while (c != '\n')
	{
		n = n * 10 + c - '0';
		c = getchar();
	}

	for (int i = 0; i < n; ++i)
	{
		if (!ope_line())
			break;
	}

	return 0;
}

Measured memory_bytes: 1692
#include<stdio.h>
#define M 100000

int parent(int);
int left(int );
int right(int);

int main(void){
  int n,A[M+1],i;

  scanf("%d",&n);
  for(i=1;i<=n;i++) scanf("%d",&A[i]);

  for(i=1;i<=n;i++){
    printf("node %d: ",i);
    printf("key = %d, ",A[i]);
      if(parent(i)>=1) printf("parent key = %d, ",A[parent(i)]); 
      if(left(i)<=n) printf("left key = %d, ",A[left(i)]);
      if(right(i)<=n) printf("right key = %d, ",A[right(i)]);
      printf("\n");


  }
  return 0;

}

int parent(int i){
  return i/2;
}
int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}



Measured memory_bytes: 2108
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
typedef long long ll;
using namespace std;
typedef pair<int,int> pint;
typedef vector<int> vint;
int INF=2e+9+1;
int main(){
	int c[3][3];
	rep(i,3){
		rep(j,3){
			scan(c[i][j]);
		}
	}
	int flag=1;
	rep(i,3){
		rep(j,3){
			if(c[j][i]-c[(j+1)%3][i]!=c[j][(i+1)%3]-c[(j+1)%3][(i+1)%3]){
				flag=0;
			}
		}
	}
	if(flag) prin("Yes");
	else prin("No");
	return 0;
}


Measured memory_bytes: 256
// not solved by myself

import java.util.*;
import java.util.Map.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        String Ss[] = {"M","A","R","C","H"};
        ArrayList<String> targets = new ArrayList<>(Arrays.asList(Ss));


        HashMap<Character,Integer> initials = new HashMap<>();
        for(int i = 0; i < N; i++){
            Character name = sc.next().toCharArray()[0];
            if(initials.keySet().contains(name))
                initials.put(name,initials.get(name) + 1);
            else
                initials.put(name,1);
        }

        long res = 0;
        HashSet<ArrayList<String>> combs = new HashSet<>();
        combination(targets,3,combs);
        for(ArrayList<String> inis: combs){
            long tmp = 1;
            for(String initial: inis){
                if (initials.containsKey(initial.toCharArray()[0]))
                    tmp *= initials.get(initial.toCharArray()[0]);
                else
                    tmp = 0;
           }
           res += tmp;
        }

        System.out.println(res);
    }

    public static <T> void combination(ArrayList<T> n,Integer r,HashSet<ArrayList<T>> ans){
        if (n.size() == r){
            ans.add(n);
            return;
        }

        for(int i = 0; i < n.size(); i++){
            ArrayList<T> N = new ArrayList<>(n);
            N.remove(i);
            combination(N,r,ans);
        }
    }

    public static List<Entry<Integer,Integer>> SortMapByValue(HashMap<Integer,Integer> maps,boolean is_reverse){
        List<Entry<Integer,Integer>> entries = new ArrayList<>(maps.entrySet());

        Collections.sort(entries, new Comparator<Entry<Integer, Integer>>() {
            @Override
            public int compare(Entry<Integer, Integer> o1, Entry<Integer, Integer> o2) {
                return (is_reverse ? -1 : 1) * o1.getValue().compareTo(o2.getValue());
            }
        });

       return entries;
    }

     public static long max(int[] ar,int size){
        long max = 0;
        for(int i = 0; i< size;i++)
            if(max < ar[i])
                max = ar[i];
        return max;
    }


    public static long max(List<Long> ar){
        long max = 0;
        for(int i = 0; i< ar.size();i++)
            if(max < ar.get(i))
                max = ar.get(i);
        return max;
    }

    public static Integer min(List<Integer> ar){
        int min = 10000;
        int index = 0;
        for(int i = 0; i< ar.size();i++){
            if(min > ar.get(i)){
                min = ar.get(i);
                index = i;
            }
        }
        return min;
    }


    public static long gcd(long m, long n) {
        if(m == 0)
            return n;
        if(n == 0)
            return m;
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }

}





Measured memory_bytes: 44176
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    //nextLineとnextを同時に使ったら死ぬ
    val sc = new Scanner(System.in)
    val m = sc.nextInt()
    val n = sc.next()

    val east = n.toCharArray.reverse
      .scanLeft(0)(
        (acc, c) =>
          c match {
            case 'E' => acc + 1
            case 'W' => acc
        }
      )
      .reverse
    debug(east.mkString(" "))

    val west = n.toCharArray
      .scanLeft(0)(
        (acc, c) =>
          c match {
            case 'E' => acc
            case 'W' => acc + 1
        }
      )

    debug(west.mkString(" "))

    val ans =
      for (i <- 0 until m) yield {
        east(i + 1) + west(i)
      }

    println(ans.min)
  }

  def debug(args: Any*): Unit = {
    Console.err.println(args.mkString(" "))
  }
}


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

int main() {
    int n;
    cin >> n;
    vector<int> x(n), y(n), h(n);
    rep(i, n) cin >> x[i] >> y[i] >> h[i];

    rep(posY, 101) {
        rep(posX, 101) {
            int H = 0;
            bool ok = true;
            rep(i, n) {
                if (h[i] == 0) continue;
                int tmpH = abs(x[i] - posX) + abs(y[i] - posY) + h[i];
                if (H == 0) {
                    H = tmpH;
                }else {
                    if (H != tmpH) {
                        ok = false;
                        break;
                    }
                }
            }
            if (!ok) continue;
            rep(i, n) {
                if (h[i] != 0) continue;
                int dist = abs(x[i] - posX) + abs(y[i] - posY);
                if (dist < H) {
                    ok = false;
                    break;
                }
            }
            if (!ok) continue;
            cout << posX << " " << posY << " " << H << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<algorithm>
#include<climits>
using namespace std;
#define CMAX 1000
#define BMAX 100000

class Bar{
    public:
    int pos, depth, t1, t2;
    Bar(int p=0, int d=0):pos(p), depth(d){}
    bool operator < ( const Bar &b) const{
	return depth < b.depth;
    }
};

int T[CMAX];
Bar B[BMAX];
int n, m, h, k;

void compute(){
    int P[CMAX];
    for ( int i = 0; i < n; i++ ) P[i] = i;

    sort( B, B + m);

    for ( int i = 0; i < m; i++ ){
	swap( P[B[i].pos-1], P[B[i].pos] );
	B[i].t1 = P[B[i].pos-1];
	B[i].t2 = P[B[i].pos];
    }

    int minv = 0, total, S[CMAX];

    for ( int i = 0; i < n; i++ ) S[i] = 0;
    for ( int i = 0; i < n; i++ ){
	S[P[i]] = T[i];
	if ( P[i]+1 > k ) continue;
	minv += T[i];
    }
    total = minv;
    for ( int i = 0; i < m; i++ ){
	int source = min(B[i].t1, B[i].t2);
	int target = max(B[i].t1, B[i].t2);
	if ( source < k && k <= target ){
	    int score = total - S[source] + S[target];
	    minv = min(minv, score);
	}
    }

    cout << minv << endl;
}

main(){
    int a, b;
    while( cin >> n >> m >> h >> k && n){
	for ( int i = 0; i < n; i++ ) cin >> T[i];
	for ( int i = 0; i < m; i++ ){
	    cin >> a >> b;
	    B[i] = Bar(a, b);
	}
	compute();
    }
}

Measured memory_bytes: 2440
#include<bits/stdc++.h>
using namespace std;
int x,y;
int main(){
    cin >> x >> y;
    
    for(int i=0;i<=x;i++){
        int tsuru = x - i;
        if(y == 2 * tsuru + 4 * i){
            cout << "Yes" << endl;
            return 0;
        } 
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3596
gets
ps=$<.map{|l|
  x,y,u=l.split
  x=x.to_i
  y=y.to_i
  [u,x,y,x+y,y-x]
}
d_xy={}
l_yx={}
r_as={}
d_as={}
l_sa={}
d_sa={}
ps.sort_by{|r| r[2] }.each{|r|
  next if r[0]!=?D
  (d_xy[r[1]]||=[]).push(r[2])
}
ps.sort_by{|r| r[1] }.each{|r|
  next if r[0]!=?L
  (l_yx[r[2]]||=[]).push(r[1])
}
ps.sort_by{|r| r[4] }.each{|r|
  case r[0]
  when ?R; (r_as[r[3]]||=[]).push(r[4])
  when ?D; (d_as[r[3]]||=[]).push(r[4])
  end
}
ps.sort_by{|r| r[3] }.each{|r|
  case r[0]
  when ?L; (l_sa[r[4]]||=[]).push(r[3])
  when ?D; (d_sa[r[4]]||=[]).push(r[3])
  end
}
m=nil
f=->d,b,k{
  r=d[b] or return
  t=r.bsearch{|e| e>=k } or return
  m=t-k if !m || t-k<m
}
ps.each{|r|
  case r[0]
  when ?U
    f[d_xy,r[1],r[2]]
    f[r_as,r[3],r[4]]
    f[l_sa,r[4],r[3]]
  when ?R
    f[l_yx,r[2],r[1]]
    f[d_sa,r[4],r[3]]
  when ?L
    f[d_as,r[3],r[4]]
  end
}
puts m ? m*5 : 'SAFE'

Measured memory_bytes: 99320
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;

void solve4() {

}

void solve3() {
	string s;
	cin >> s;
	map<char, int> p;
	for (int i = 0; i < s.size(); i++)
	{
		p[s[i]]++;
	}
	int m = min(p['W'], p['B']);
	string W ="W",P="P";
	if (m == 0) {
		cout << 0 << endl;
	}

	string::size_type pos = s.find(W+W);
	while (pos != string::npos) {
		s.replace(pos, s.size(), W);
		pos = s.find(W+W, pos + 1);
	}
	pos = s.find(P + P);
	while (pos != string::npos) {
		s.replace(pos, s.size(), P);
		pos = s.find(P + P, pos + 1);
	}
	/*
	int split = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == M[0]) {
			split++;
		}
	}
	if (s[0] == M[0] || s[s.size()-1] == M[0]) {
		cout << split * 2 - 1 << endl;
	}
	else if(s[0] == M[0] && s[s.size() - 1] == M[0]) {
		cout << split * 2 << endl;
	}
	else {
		cout << split * 2 << endl;
	}
	*/
	cout << s.size() - 1 << endl;
}

void solve2() {
	int H, W,N;
	cin >> W >> H >> N;
	int x[100] , y[100] , a[100] ;
	int min_x = 0, min_y = 0, max_x = W, max_y=H;
	for (int i = 0; i < N; i++)
	{
		cin >> x[i] >> y[i] >> a[i];
		if (a[i] == 1) {
			min_x = max(min_x, x[i]);
		}
		if (a[i] == 2) {
			max_x = min(max_x, x[i]);
		}
		if (a[i] == 3) {
			min_y = max(min_y, y[i]);
		}
		if (a[i] == 4) {
			max_y = min(max_y, y[i]);
		}
	}
	if (max_x - min_x <= 0 || max_y - min_y <= 0)
		cout << 0 << endl;
	else
		cout << max(0,(max_x - min_x)*(max_y - min_y) ) << endl;

	
}

void solve1() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b + c || b == a + c || c == a + b)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

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

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, l int
	fmt.Scan(&n, &l)

	allSum := 0
	min := 10000
	num := 0
	for i := 1 ; i  <= n ;i++ {
		allSum += l + i - 1
		if  min > abs(l + i - 1 ) {
			min =  abs(l + i - 1 )
			num = l + i -1
		}
	}
	fmt.Println(allSum - num)
}
func abs(n int) int {
	y := n >> 63
	return (n ^ y) - y
}


Measured memory_bytes: 1768
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int a,p;
    cin >> a >> p;
    cout << (3 * a + p) / 2 << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include<functional>
#include <tuple>
#include <map>
#include<set>
#include <cmath>
#include <stack>
#include<cstdio>
#include<stdio.h>
using namespace std;

int main() {
	int n, a, b, cnt=0 , b_cnt=0;
	string s;
	cin >> n >> a >> b >> s;
	for (int i = 0;i < n;i++) {
		if (s[i] == 'a' && cnt < a + b) {
			cnt += 1;
			cout << "Yes" << endl;
		}
		else if (s[i] == 'b' && cnt < a + b && b_cnt < b) {
			cnt += 1;
			b_cnt += 1;
			cout << "Yes" << endl;
		}
		else cout << "No" << endl;
	}
}

Measured memory_bytes: 896
package main

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

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	n := io.NextInt()
	x, y := make([]int, n), make([]int, n)
	for i := 0; i < n; i++ {
		xi, yi := io.NextInt(), io.NextInt()
		x[i], y[i] = xi+yi, xi-yi
	}
	sort.Ints(x)
	sort.Ints(y)
	dx, dy := x[n-1]-x[0], y[n-1]-y[0]
	ans := Max(dx, dy)
	io.Println(ans)
}

// Max returns max value of inputs
func Max(a ...int) (max int) {
	for i, ai := range a {
		if i == 0 || ai > max {
			max = ai
		}
	}
	return max
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 8568
//verma_ankit484

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

typedef long long ll;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
const ll mod = (ll) 1e9+7;

using namespace std;
using namespace __gnu_pbds;

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>


int main() {
  IOS
  #ifdef AV
  freopen("int.txt", "r", stdin);
  #endif
  ll n;
  cin >> n;
  string str;
  cin >> str;
  ll ans = 0;
  map<string, ll> mp;
  ll idx = 0;
  vector<ll> suff(n, 0);
  map<ll, ll> mp2;
  ll c = 0;
  for (ll i = n-1; i >= 0; i--) {
    if (mp2[str[i]-'0'] == 0) {
      c++;
      mp2[str[i]-'0'] = 1;
    }
    suff[i] = c;
  }
  while (idx < n) {
    string p;
    p += (str[idx]);
    if (mp[p] == 1) {
      idx++;
      continue;
    }
    for (ll i = idx+1; i < n-1; i++) {
      string p2 = p+str[i];
      if (mp[p2] == 1) {
        continue;
      }
      ans += suff[i+1];
      mp[p2] = 1;
    }
    mp[p] = 1;
    idx++;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

const int MaxN = 1e5 + 15;
const int INF = 1e9;

vector <int> v[MaxN];
int n, m;
int S, T;
int dp[MaxN][3];

struct trpl{
    int a, b, c;
    
    trpl(int a, int b, int c) :
        a(a), b(b), c(c)
        {
            
        }
        
    bool operator < (const trpl & oth) const
    {
        if(a != oth.a)
            return a < oth.a;
        if(b != oth.b)
            return b < oth.b;
        return c < oth.c;
    }
};

void dj()
{
    for(int i = 1; i <= n; ++i)
        for(int j = 0; j < 3; ++j)
            dp[i][j] = INF;
            
    dp[S][0] = 0;
    
    set<trpl> s;
    s.insert(trpl(0, S, 0));
    
    while(!s.empty())
    {
        trpl cur = *s.begin();
        s.erase(s.begin());
        
        int x = cur.b;
        int c = (cur.c + 1) % 3;
        int cost = cur.a + 1;
        
        for(int to : v[x])
        {
            if(dp[to][c] > cost)
            {
                s.erase(trpl(dp[to][c], to, c));
                dp[to][c] = cost;
                s.insert(trpl(dp[to][c], to, c));
            }
        }
    }
    
    if(dp[T][0] == INF)
        cout << -1 << '\n';
    else
        cout << dp[T][0] / 3 << '\n';
}

int main() {
    cin >> n >> m;
    for(int i = 0; i < m; ++i)
    {
        int x, y;
        cin >> x >> y;
        v[x].push_back(y);
    }
    cin >> S >> T;
    
    dj();
}

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

#define ft first
#define sd second
#define sz(x) ((int)x.size())

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 100 * 1000 + 123;






int n, a[MAXN];


int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int x = *max_element(a, a + n);
	double y = 1. * x / 2, z = *min_element(a, a + n);
	for (int i = 0; i < n; i++)
		if (abs(y - z) > abs(y - a[i]))
			z = a[i];
	cout << x << ' ' << (int)z;
	return 0;
}

Measured memory_bytes: 640
#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++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define P pair<int, int>
typedef long long ll;
const ll mod = 1e9+7;

//繰り返し自乗法による累乗計算
//a**n
ll pow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = pow(a, n/2);
    return res * res;
  }
  return a * pow(a, n-1);
}
//繰り返し自乗法によるmod累乗計算
//a**n (mod)
ll modpow(ll a, ll n){
  if(n == 0) return 1;
  if(n%2 == 0){
    ll res = modpow(a, n/2);
    return res * res % mod;
  }
  return a * modpow(a, n-1) % mod;
}
//組み合わせ
//nCa
ll com(ll n, ll a){
  ll x = 1, y = 1;
  rep(i,a){
    x *= n-i;
    y *= i+1;
  }
  ll res = x / y;
  return res;
}
//組み合わせ(mod)
//nCa (mod)
ll modcom(ll n, ll a){
  ll x = 1, y = 1;
  rep(i, a){
    x = x * (n-i) % mod;
    y = y * (i+1) % mod;
  }
  ll ans = x * modpow(y, mod-2) % mod;
  return ans;
}
//gcd 最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x%y);
}
//lcm 最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//ngcd n個の最大公約数
ll ngcd(vector<ll> a){
  ll res;
  res = a[0];
  for(ll i = 1; i < a.size() && res != 1; i++) {
    res = gcd(a[i], res);
  }
  return res;
}
//nlcm n個の最小公倍数
ll nlcm(vector<ll> a) {
  ll res;
  res = a[0];
  for (ll i = 1; i < a.size(); i++) {
    res = lcm(res, a[i]);
  }
  return res;
}
// 素数判定
bool isprime(ll x){
  ll i;
  if(x < 2) return false;
  else if(x == 2) return true;
  if(x % 2 == 0) return false;
  for(i = 3; i*i <= x; i += 2){
    if(x % i == 0) return false;
  }
  return true;
}
// 桁和
ll digsum(ll x){
  ll res = 0;
  while(x > 0){
    res += x % 10;
    x /= 10;
  }
  return res;
}


int main(){
  int n, k;
  cin >> n >> k;
  vector<int> x(n);
  rep(i,n) cin >> x[i];
  int ans = 0;
  rep(i,n){
    ans += min(x[i], k-x[i]);
  }
  ans *= 2;
  cout << ans << endl;
}



Measured memory_bytes: 256
///
// File:  2424.cpp
// Author: ymiyamoto
//
// Created on Thu Nov 16 21:38:19 2017
//

#include <cstdint>
#include <iostream>
#include <string>

using namespace std;

int32_t main()
{
  uint32_t Q;
  cin >> Q;

  for (uint32_t _ = 0; _ < Q; _++) {
    string n;
    cin >> n;

    uint32_t count = 0;
    while (n.size() > 1) {
      count++;
      int32_t maxval = 0;
      for (uint32_t i = 1; i < n.size(); i++) {
        string n1 = n.substr(0, i);
        string n2 = n.substr(i, n.size() - i);
        maxval = max(maxval, stoi(n1) * stoi(n2));
      }
      if (n == to_string(maxval)) {
        count = -1;
        break;
      } else {
        n = to_string(maxval);
      }
    }
    cout << count << endl;
  }
  return 0;
}

Measured memory_bytes: 3264
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def factorization(n):
	arr = []
	temp = n
	for i in range(2, int(-(-n**0.5//1))+1):
		if temp%i == 0:
			cnt = 0
			while temp%i == 0:
				cnt += 1
				temp //= i
			arr.append([i, cnt])
	if temp != 1:
		arr.append([temp, 1])
	if arr == []:
		arr.append([n, 1])
	return arr

A, B = MAP()
N = gcd(A, B)

print(len(factorization(N))+1 if N != 1 else 1)

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

using namespace std;

#define ll long long
#define ini(arr, val) memset(arr, (val), sizeof(arr))
#define loop(i,n)  for(ll i=0; i<n; i++)
#define loop1(i,n)  for(ll i=1; i<=n; i++)

#define all(a)      (a).begin(),(a).end()
#define exist(s,e)  (s.find(e)!=s.end())
#define dbg(x)  cout << #x << " = " << x << endl
#define pt(x) cout<<x<<"\n"
#define pts(x) cout<<x<<" "

#define mp make_pair
#define pb push_back
#define F first
#define S second


#define inf (int)1e9
#define infll 1e18
#define eps 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007


#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test   int t; cin>>t; while(t--)

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<int,int> mii;
typedef set<int> si;

typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<pll> vpll;
typedef vector<vl> vvl;
typedef map<ll,ll> mll;
typedef set<ll> sl;


int dirx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int diry[] = { -1, 0, 1, -1, 1, -1, 0, 1 };



//===========================DEBUG======================//
#define XOX 1
vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

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



//////////////////////////////////////////////////////////////////////////////////////////
//                      main starts
//////////////////////////////////////////////////////////////////////////////////////////
int const lmt=2e5+5;


int main(){
    #ifndef ONLINE_JUDGE
    freopen("../input.txt", "r", stdin);
    freopen("../output.txt", "w", stdout);
	#endif
    fast

    ll n; cin>>n;
    int a[n][3],dp[n][3];
    loop(i,n){
    	cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    loop1(i,n-1){
    	dp[i][0] = a[i][0] + max(dp[i-1][1], dp[i-1][2]);
    	dp[i][1] = a[i][1] + max(dp[i-1][0], dp[i-1][2]);
    	dp[i][2] = a[i][2] + max(dp[i-1][1], dp[i-1][0]);
    }

    int ans = max(dp[n-1][0],dp[n-1][1]);
    ans = max(ans,dp[n-1][2]);
    pt(ans);
}


/*


*/





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

int main() {
    int n;
    while (cin >> n, n) {
        int ans = 0;
        vector<int> v(n);
        for (int i=0; i<n; ++i) cin >> v[i];
        while (1) {
            vector<int> v2(n);
            for (int i=0; i<n; ++i) {
                int cnt = 0;
                for (int j=0; j<n; ++j) cnt += v[i] == v[j];
                v2[i] = cnt;
            }
            if (v == v2) break;
            v = v2;
            ans ++;
        }
        cout << ans << endl;
        for (int i=0; i<n; ++i) {
            cout << (i==0 ? "" : " ") << v[i];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
using namespace std;

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,m,k;
	bool flag = false;
	cin >> n >> m >> k;
	for(int i = 0;i <= n;i++){
		int tmp = i * m;
		for(int j = 0;j <= m;j++){
			if(tmp + (n - i * 2) * j == k) flag = true;
		}
	}
	if(flag) Yes();
	else No();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int n;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	map<long long, int> cnt;
	long long sum = 0;
	for(int i = 1; i <= n; i++){
		int h;
		cin >> h;
		sum += cnt[h - i];
		cnt[-h - i]++;
	}
	cout << sum << "\n";
	return 0;
}

Measured memory_bytes: 26304
import math
#def main(S, b):
if __name__ == '__main__':
    a, b, c, k = map(int, input().split())

    if (a >= k):
        print(k)
    elif (a + b >= k):
        print(a)
    else:
        print(a - (k - a - b))

    # if (s == t[:(len(s))] and len(t) == len(s) + 1):

    #     print("Yes")
    # else:
    #     print("No")
    # s = sum(a)


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

int main (void){
    int n, k;
    cin >> n >> k;
    if(n % k == 0){
        cout << 0 << endl;
    }else{
        cout << 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
struct edge {
	int nxt, to, w;
} e[N << 2];
int n, m, cnt = 1;
int vis[N], h[N], val[N];
bool dfs(int u) {
	vis[u] = 1;
	for(int i = h[u]; i; i = e[i].nxt) {
		if(vis[e[i].to]) {
			if(val[e[i].to] != val[u] + e[i].w) {
				return false;
			}
		} else {
			val[e[i].to] = val[u] + e[i].w;
			if(!dfs(e[i].to)) {
				return false;
			} 
		}
	}
	return true;
}
void link(int u, int v, int w) {
	e[++cnt].nxt = h[u];
	h[u] = cnt;
	e[cnt].to = v;
	e[cnt].w = w; 
}
int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; ++i) {
		int u, v, w;
		scanf("%d%d%d", &u, &v, &w);
		link(u, v, w);
		link(v, u, -w);
	}
	for(int i = 1; i <= n; ++i) {
		if(!vis[i]) {
			if(!dfs(i)) {
				puts("No");
				return 0;
			}
 		}
	}
	puts("Yes");
	return 0;
}

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

  typedef long long int ll;
  typedef pair<int,int> pi;
  typedef pair<ll,ll> pll;
  typedef vector<int> vi;
  typedef vector<ll> vll;
  typedef vector<pi> vpi;
  typedef vector<pll> vpll;

  #define  ff           first
  #define  ss           second
  #define  pb           push_back
  #define  IOS          ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  #define  D(x)         cout << #x << " - " << x << endl;
  #define  D2(x)        cout << "[" << #x << ": "; for(auto it:x) cout << it << " "; cout << "]" << endl;
  #define  all(x)       (x).begin(), (x).end()
  #define  D2p(x)       cout << #x << " ~ [ "; for(auto n: x) cout << n.first << "-" << n.second << " / "; cout << "]" << endl;
  #define  ps(x,y)      fixed<<setprecision(y)<<x
  #define  rep(i,a,b)   for(ll i=a ; i<b ; ++i)

  const ll MOD = 1e9 + 7;
  const ll INF = 1e18;
  const ll maxn = 1e6 + 4;


  void solve(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt = count(all(s),'R');
    int ans=0;
    for(int i=0;i<cnt;i++){
    	ans += (s[i]!='R');
    }
    cout << ans;
  }

  int main(){
    IOS
    solve();
    cerr <<endl <<"[ Time : " << (float)clock() / CLOCKS_PER_SEC << " secs ]" << endl;
  }

// integer overflow
// remember to clear visited array
// take input as vector<string> while using grid
// don't assign after modifying


Measured memory_bytes: 3832
/*
author: Apoorv Singh
*/

#include <bits/stdc++.h>
using namespace std;

typedef vector <long long> vi;
typedef pair <long long, long long> pii;
#define pb push_back   
#define all(c) c.begin(), c.end()
#define FOR(i, a, b) for (long long i = a; i < b; ++i)
#define FORR(i, a, b) for (long long i = a; i > b; --i)
#define um unordered_map
#define F first
#define S second
#define int long long
#define inf LLONG_MAX
#define endl "\n"
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

template <class X>
void printarr(X arr[], int n)
{
    for (int i = 0; i < n; ++i)
        cout << arr[i] << " ";
    cout << endl;
}
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){ for (X a : v) x << a << ' '; return x;} 
template <typename X, typename Y> ostream& operator << (ostream& x, const vector< pair<X, Y> >& v) {for (pair <X, Y> it : v) x << it.first << ' ' << it.second << endl; return x;} 
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (pair <T, S> it : v) os << it.first << " => " << it.second << endl; return os; }

double pi = 3.14159265358979323846264338327950288419716939937510582097494459230;
int modulo = 1e9 + 7;

int fpow(int a, int n)
{
    int ans = 1;
    while (n)
    {
        if (n&1)
            ans = (ans * a)%modulo;
        a = (a*a)%modulo;
        n = n >> 1;
    }
    return ans;
}

/*
const int M = 1e6 + 10;
int composite[M] = {0};

void sieve()
{
    FOR(i,2,M)
    {
        if (!composite[i])
        {
            for (int j = 2*i; j < M; j += i)
                composite[j] = max(composite[j], i);
        }
    }
}
*/

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL); 
    int n; cin >> n;
    ++n;
    int a[n], b[n-1];
    FOR(i,0,n) cin >> a[i];
    FOR(i,0,n-1) cin >> b[i];
    int ans = 0;
    FOR(i,0,n-1)
    {
        int allowed = b[i];
        ans += min(a[i], allowed);
        allowed -= min(a[i], allowed);
        ans += min(a[i+1], allowed);
        a[i+1] -= min(a[i+1], allowed);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1792