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

const int INF = 1e9 + 10;

struct Edge {
  int to, w;
  Edge(int t, int w) : to(t), w(w) {}
};

struct Graph {
  int N;
  vector<vector<Edge>> edges;

  Graph(int N) : N(N), edges(N) {}

  void addDEdge(int a, int b) { addDEdge(a, b, 1); }
  void addDEdge(int a, int b, int w) { edges[a].emplace_back(b, w); }
  void addEdge(int a, int b) { addEdge(a, b, 1); }
  void addEdge(int a, int b, int w) {
    edges[a].emplace_back(b, w);
    edges[b].emplace_back(a, w);
  }

  int s, t;
  vector<int> level, prog;
  vector<vector<int>> g, cap, flow;
  int dinic(int _s, int _t) {
    s = _s;
    t = _t;
    level = vector<int>(N);
    g = vector<vector<int>>(N);
    cap = vector<vector<int>>(N, vector<int>(N));
    flow = vector<vector<int>>(N, vector<int>(N));
    rep(i, N) for (Edge e : edges[i]) {
      int u = i, v = e.to;
      cap[u][v] += e.w;
      cap[v][u] += e.w;
      flow[v][u] += e.w;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    int maxFlow = 0;
    while (setLevel()) {
      prog = vector<int>(N, 0);
      maxFlow += augment(s, INF);
    }
    return maxFlow;
  }

  inline int res(int u, int v) { return cap[u][v] - flow[u][v]; }
  bool setLevel() {
    level = vector<int>(N, -1);
    level[s] = 0;
    queue<int> q;
    q.push(s);
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (int nv : g[v]) {
        if (level[nv] == -1 && res(v, nv) != 0) {
          level[nv] = level[v] + 1;
          q.push(nv);
        }
      }
    }
    return level[t] != -1;
  }

  int augment(int v, int lim) {
    int maxFlow = 0;
    if (v == t) return lim;
    for (int &i = prog[v]; i < (int)g[v].size(); i++) {
      int nv = g[v][i];
      if (level[nv] <= level[v] || res(v, nv) == 0) continue;
      int aug = augment(nv, min(lim, res(v, nv)));
      flow[v][nv] += aug;
      flow[nv][v] -= aug;
      maxFlow += aug;
      lim -= aug;
      if (lim == 0) break;
    }
    return maxFlow;
  }
};

int main() {
  int N;
  cin >> N;
  Graph G(N * 2 + 2);
  vector<int> a(N), b(N);
  rep(i, N) cin >> a[i] >> b[i];
  int s = N * 2, t = N * 2 + 1;
  rep(i, N) {
    G.addDEdge(s, i);
    G.addDEdge(N + i, t);
    int c, d;
    cin >> c >> d;
    rep(j, N) {
      if (c > a[j] && d > b[j]) G.addDEdge(j, N + i);
    }
  }

  int ans = G.dinic(s, t);

  cout << ans << endl;


}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
#define lint long long int
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
*/


int main() {
	int N;
	cin >> N;
	vector<int>vec(N);
	for (int i = 0; i < N; i++) {
		cin >> vec.at(i);
	}
	int dp[100000];
	dp[0] = 0;
	dp[1] = abs(vec.at(1) - vec.at(0));
	for (int i = 2; i < N; i++) {
		dp[i] = min(dp[i - 1] + abs(vec.at(i) - vec.at(i - 1)), dp[i - 2] + abs(vec.at(i) - vec.at(i - 2)));
	}
	cout << dp[N-1] << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  string S[N];
  for (int i = 0; i < N; i++) cin >> S[i];
  int ac = 0;
  int wa = 0;
  int tle = 0;
  int re = 0;
  for (int i = 0; i < N; i++) {
    if (S[i] == "AC") {
      ac = ac + 1;
    } else if (S[i] == "WA") {
      wa = wa + 1;
    } else if (S[i] == "TLE") {
      tle = tle + 1;
    } else if (S[i] == "RE") {
      re = re + 1;
    }
  }
  cout << "AC x " << ac << endl;
  cout << "WA x " << wa << endl;
  cout << "TLE x " << tle << endl;
  cout << "RE x " << re << endl;
  return 0;
}

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

int main()
{
    std::string str;
    std::cin >> str;

    bool same = true;
    for (int i = 0; i < 2 && same; ++i)
        if (str[i] != str[i + 1])
            same = false;

    std::cout << (same ? "No" : "Yes");
}

Measured memory_bytes: 764
//Main header file
#include <bits/stdc++.h>
using namespace std;

//For PBDS
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define orderfind 		find_by_order
#define orderkey 		order_of_key

//Constants
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX = 1e6;

//Vectors
#define vl 			vector<ll>
#define vvl 		vector<vl>
#define vpl 		vector<pl>
#define vb 			vector<bool>
#define vd 			vector<ld>
#define vs 			vector<string>
#define pb 			emplace_back
//Pair
#define pl 			pair<ll, ll>
#define ff 			first
#define ss 			second
#define mp 			make_pair
//Extras
#define ql 			queue<ll>
#define sl 			stack<ll>
#define Set 		set<ll>
#define SetDesc 	set<ll, greater<ll>>
#define PQ(t)		priority_queue<t, vector <t>, greater <t>>
#define PQD(t)		priority_queue<t>
//General
#define fastio 		ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) 		a.begin(), a.end()
#define uniq(a)     (a).resize(distance((a).begin(), unique(all(a))))
#define min(a, b) 	(a<b?a:b)
#define max(a, b) 	(a>b?a:b)
#define ab(a)       (a<0)?(-1*a):a
#define mid(s,e)    (s+(e-s)/2)
#define minel(a)	*min_element(all(a))
#define maxel(a)	*max_element(all(a))
//Grid Movement
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};

//Functions 
ll mod_sum() { return 0LL; }
template<typename T, typename... Args>
T mod_sum(T a, Args... args) { return ((a + mod_sum(args...))%MOD + MOD)%MOD; }

ll mod_prod() { return 1LL; }
template<typename T, typename... Args>
T mod_prod(T a, Args... args) { return (a*mod_prod(args...))%MOD; }

ll power(ll mult, ll pow, ll mod = MOD);
ll gcd(ll a, ll b);
ll lcm(ll a, ll b);
ll inv(ll a, ll m = MOD);
void sieve(ll n);
vl primes;
vb is_prime;


void solve()
{
	ll n;
	cin >> n;

	vl arr(n);

	for(auto &i : arr)
		cin >> i;

	vl dp(n);
	dp[0] = 0;
	dp[1] = abs(arr[1]-arr[0]);

	for(int i = 2; i<n; i++)
		dp[i] = min(dp[i-1]+abs(arr[i]-arr[i-1]), dp[i-2]+abs(arr[i]-arr[i-2]));

	cout << dp[n-1] << "\n";
}


int main()
{
	fastio;

    int t = 1;
    //cin >> t;

    while(t--)
    	solve();

	return 0;
}



// Helper functions
ll power(ll mult, ll pow, ll mod)
{
	ll res = 1;
	while(pow > 0)
	{
		if(pow&1)
		{
			res *= mult;
			res %= mod;
		}
		mult *= mult;
		mult %= mod;
		pow >>=  1;
	}
	return res;
}

ll gcd(ll a, ll b)
{
	if(b == 0)
		return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b)
{
	return (a*b)/gcd(a, b);
}

void sieve(ll n)
{
	is_prime.resize(n+1);
	primes.resize(n+1);

	is_prime[0] = is_prime[1] = false;
	for(int i = 2; i<=n; i++)
	{
	    if(is_prime[i])
	    {
	    	primes.pb(i);
	        for (int j = i*i; j<=n; j+=i)
	            is_prime[j] = false;
	    }
	}
}


ll inv(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {
        int q = a / m;
        int t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }

    if (x < 0)
       x += m0;

    return x;
}

Measured memory_bytes: 1792
#define _USE_NATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <random>
#include <tuple>


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;
#define EPS 1e-9
const int INF = 1050000000;
const long long LINF = 1LL << 60;
const ll MOD = 1e9 + 7;
const int MINF = -1050000000;

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; }


int main() {
	
	ll n, k;
	cin >> n >> k;
	ll keta=0, cnt=0;
	if (n == 0) cout << 1 << endl;
	while (n != 0) {
		n = n / k;
		cnt += 1;
	}
	cout << cnt << endl;
	return 0;
}


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

#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using int32 = int;
using int64 = long long;

const int   mod   = 1e9 + 7;
const int32 inf   = 1001001001;
const int64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

template <typename T = int64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solver() {
  int N = input(), K = input();
  string s;
  cin >> s;

  s[K - 1] -= ('A' - 'a');

  cout << s << endl;
}

signed main(int argc, char *argv[]) {
  solver();
}

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

using namespace std;
using LL = long long;
const int N = 1024;
const int INF = INT32_MAX - 1;
const double EPS = 1E-9;

int a[N];
int n, m;

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

#ifdef CF_DEBUG
    freopen("../cf/input.txt","r",stdin);
#endif
    cin>>m>>n;
    LL res=0;
    if(m==1 || n==1) res=1;
    else res= 1LL*m/2*n + (m%2)*(ceil(1.0*n/2));
    cout<<res;
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		num = nextInt()
		nums = append(nums, num)
	}
	return
}

func main() {
	sc.Split(bufio.ScanWords)
	r := nextInt()
	fmt.Println(r * r * 3)
}


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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define rep(idx, N) for (u64 idx = 0; idx < N; idx++)

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

  vector<u32> a(n);
  rep(i, n) { cin >> a[i]; }

  u64 ans = 1000;
  u64 stock = 0;
  rep(i, n - 1) {
    if (a[i] < a[i + 1]) {
      stock += ans / a[i];
      ans -= (ans / a[i]) * a[i];
    } else if (a[i] > a[i + 1]) {
      ans += stock * a[i];
      stock = 0;
    }
  }

  ans += stock * a[n - 1];
  cout << ans;

  return 0;
}


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

int main(){
    int H, W, D; cin >> H >> W >> D;
    vector<P> mp(H * W);
    rep(i, 0, H) rep(j, 0, W){
        int p; cin >> p; p--;
        mp[p] = {i,j};
    }

    int Q; cin >> Q;
    vector<int> L(Q), R(Q);
    rep(i, 0, Q) cin >> L[i] >> R[i], L[i]--, R[i]--;

    vector<ll> sum(H * W);
    rep(i, 0, H * W){
        if(i < D) sum[i] = 0;
        else{
            int dx = abs(mp[i].first - mp[i-D].first);
            int dy = abs(mp[i].second - mp[i-D].second);
            sum[i] = sum[i - D] + dx + dy;
        }
    }
/*     rep(i, 0, H * W){
        cout << i << " " << sum[i] << endl;
    } */
    rep(i, 0, Q){
        cout << sum[R[i]] - sum[L[i]] << endl;
    }
}


Measured memory_bytes: 3328
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
#define INT_MAX 2147483647
int main() {
	string s; cin >> s;
	int minx = 2, x = 0;
	for (int i = 0; i < s.size(); i++){
		if (s[i] == 'T')x--; else x++;
		minx = min(minx, x);
	}
	cout << -minx*2 << endl;
	char c; cin >> c;
}

Measured memory_bytes: 640
N ,K = map(int,input().split())
P = list(map(int,input().split()))
A = P[:K]
a = sum(A)
max = a
for i in range(N-K):
    a = a-P[i]+P[i+K]
    if max <= a:
        max = a
print((max+K)/2.0)

Measured memory_bytes: 25060
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ans;
signed main(){

    string s,t;
    cin>>s;
    rep(i,s.size()/2){
        if(s[i]!=s[s.size()-i-1])ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<=(b);++i)
#define rv(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
typedef long long LL;
const int M = 1200000;
const int inf = 0x3f3f3f3f;
int n,m,k;
int main() {
	cin>>n>>m>>k;
	cout<<min((k+n-1)/n,(k+m-1)/m)<<endl;
	return 0;
}


Measured memory_bytes: 256
def main(N, M, a_list):
    div = 10**9 + 7

    a_set = set(a_list)
    
    dp = {}
    dp[0] = 1
    if 1 in a_set:
        dp[1] = 0
    else:
        dp[1] = 1

    for i in range(N):
        if i+2 in a_set:
            dp[i+2] = 0
        else:
            dp[i+2] = (dp[i+1] + dp[i])
    
    print(dp[N] % div)


if __name__ == "__main__":
    N, M = [int(x) for x in input().split()]
    a_list = []
    for _ in range(M):
        a_list.append(int(input()))

    main(N, M, a_list)


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

int gei[10], jac[10];
bool k[10];
int dfs(int num, int a, int b){
    int sum=0;
    if(num==9){
        if(a>b) return 1;
        else return 0;
    }
    for(int i=0; i<9; i++){
        if(k[i]) continue;
        k[i]=true;
        sum+=dfs(num+1, a+(gei[num]>jac[i]? gei[num]+jac[i] : 0), b+(gei[num]<jac[i]? gei[num]+jac[i] : 0));
        k[i]=false;
    }
    return sum;
}

int main(void){
    int n;
    cin >> n;
    for(int i=0; i<n; i++){
        fill(k, k+10, false);
        for(int j=0; j<9; j++){
            cin >> gei[j];
        }
        for(int j=0; j<9; j++){
            cin >> jac[j];
        }
        double pg = dfs(0, 0, 0)*1.0/(double)(9*8*7*6*5*4*3*2*1);
        cout << pg << " " << (1-pg) << "\n";
    }
    
    return 0;
}


Measured memory_bytes: 3212
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>


 
using namespace std;

 
int main(){
  int A,P;
  int pai=0;

  cin >> A >> P;
  pai= (A*3 + P)/2;

  cout << pai << endl;





    return 0;
}

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

int main(){
    long long n,ans = 0,fav;
    cin >> n;
    for(long long i = 1;i * i <= n;i++){
        if((n - i) % i == 0){
            fav = (n - i) / i;
            if(fav != 0 &&(n / fav) == (n % fav))ans += fav;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int A, B, C, X, Y;
int main() {
	int amount = 0, amount1 = 0, amount2 = 0, amount3 = 0, amount4 = 0;
	cin >> A >> B >> C >> X >> Y;


		amount1 += A*X + B*Y;
	
		amount2 += C*(2*Y);
		if (X > Y) {
			amount2 += A*(X - Y);
		}
		amount = min(amount1, amount2);

		amount3 += C*(2*X);
		if (Y > X) {
			amount3 += B*(Y - X);
		}
		amount = min(amount, amount3);

		if (X < Y) {
			amount4 += C*2*Y;
		}
		else {
			amount4 += C*2*X;
		}
		amount = min(amount, amount4);

	cout << amount << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int a,b,c,x;
    int co=0;
    cin >> a>>b>>c>>x;
    for(int i=0;i<=a;++i){
        for(int j=0;j<=b;++j){
            for(int k=0;k<=c;++k){
               int g=500*i+100*j+50*k;
               if(g==x){
                co++;
               }
            }
        }
    }
    cout << co << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Set;
import java.util.HashSet;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		HashSet<String> set = new HashSet<String>();
		set.add(sc.next());
		set.add(sc.next());
		set.add(sc.next());
		System.out.println(set.size());
	}
}

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

long long n, x;

long long g(long long a, long long b){
	if(b == 0) return -a;
	if(b == 1) return 2*a-1;
	return 2*(a/b*b) + g(b, a%b);
}

long long f(long long a, long long b){
//	if(a % 2 == 1) return 3*(n-1);
	return a + g(a-b, b);
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n >> x;
	cout << f(n, x) << "\n";
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Test
{
    static void Main()
    {
        string ss;
        while ( (ss = Console.ReadLine()) != "0 0")
        {
            int H = int.Parse(ss.Split()[0]);
            int W = int.Parse(ss.Split()[1]);

            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    if ((i + j) % 2 == 0) Console.Write("#");
                    else Console.Write(".");
                }
                Console.Write("\n");
            }
            Console.WriteLine();
        }
    }
}


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

int main() {
	string S;
	cin >> S;
	long long ANS = 0;
	for (int i = 0; i < S.size() - i - 1; i++) {
		if (S[i] != S[S.size() - i - 1]) ANS++;
	}
	cout << ANS << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
bool f[85][85][13000];
int a[85][85];
int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
	int n,m;
	cin>>n>>m;
	FOR(i,1,n){
		FOR(j,1,m){
			cin>>a[i][j];
		}
	}
	int x;
	FOR(i,1,n){
		FOR(j,1,m){
			cin>>x;
			a[i][j]=abs(a[i][j]-x);
		}
	}
	f[0][1][0]=1;int t=80*(m+n-1);
	FOR(i,1,n){
		FOR(j,1,m){
			FOR(k,0,t){
				if(k>=a[i][j]){
					f[i][j][k]=f[i][j][k]|f[i][j-1][k-a[i][j]];
					f[i][j][k]=f[i][j][k]|f[i-1][j][k-a[i][j]];
				}else{
					f[i][j][k]=f[i][j][k]|f[i][j-1][a[i][j]-k];
					f[i][j][k]=f[i][j][k]|f[i-1][j][a[i][j]-k];
				}
				if(a[i][j]+k<=t){
					f[i][j][k]=f[i][j][k]|f[i-1][j][k+a[i][j]];
					f[i][j][k]=f[i][j][k]|f[i][j-1][k+a[i][j]];
				} 
			}
		}
	}
	FOR(i,0,t){
		if(f[n][m][i]){
			cout<<i;RE 0;
		}
	}
}





Measured memory_bytes: 87296
N = int(input())
A = []
for i in range(N):
    a,b,c = [int(_n) for _n in input().split()]
    A.append((a,b,c))
dp = [[0]*3 for _ in range(N)]
dp[0][0] = A[0][0]
dp[0][1] = A[0][1]
dp[0][2] = A[0][2]

for i in range(1,N):
    dp[i][0] = max(dp[i-1][1], dp[i-1][2])+A[i][0]
    dp[i][1] = max(dp[i-1][0], dp[i-1][2])+A[i][1]
    dp[i][2] = max(dp[i-1][0], dp[i-1][1])+A[i][2]
print(max(dp[N-1][0], dp[N-1][1], dp[N-1][2]))

Measured memory_bytes: 76632
X, Y, Z, K = map(int, input().split())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
Cs = list(map(int, input().split()))

As.sort(reverse=True)
Bs.sort(reverse=True)
Cs.sort(reverse=True)

sumABCs = []
for i in range(1, X+1):
    for j in range(1, Y+1):
        if i*j > K: break
        for k in range(1, Z+1):
            if i*j*k > K: break
            sumABCs.append(As[i-1]+Bs[j-1]+Cs[k-1])

sumABCs.sort(reverse=True)

print('\n'.join(map(str, sumABCs[:K])))


Measured memory_bytes: 8708
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] sum = new int[200];
		int i=0;
		while(sc.hasNext()){
			sum[i] = sc.nextInt() + sc.nextInt();
			i++;
		}
		
		for(int j=0;j<i;j++){
			int k=0;
			while(sum[j]!=0){
				k++;
				sum[j] /= 10;
			}
			System.out.println(k);
		}
	}
}

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)   
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

double calc_dist(P pos1, P pos2){
    return sqrt(pow(pos1.fs - pos2.fs, 2) + pow(pos1.sc - pos2.sc,2));
}

int main(){ 
    ll n;
    cin >> n;
    double ans = 0;
    ll cnt = 0;
    P pos[n];
    ll array[n] = {};

    rep(i,0,n){
        ll a,b;
        cin >> a >> b;
        pos[i].fs = a;
        pos[i].sc = b;
        array[i] = i;
    }

    do{
        rep(i,0,n-1){
            ans += calc_dist(pos[array[i]],pos[array[i+1]]);
        }
        cnt++;

    }while(next_permutation(array,array+n));


    cout << setprecision(10) << ans / (ll)cnt << endl;
    return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int n,m;
ll f[500005],r[500005],ans;
ll modpow(ll x,ll n){
	ll ret = 1;
	while(n){
		if(n%2) ret = ret*x%mod;
		n /= 2;
		x = x*x%mod;
	}
	return ret;
}
ll C(int n,int m){
	if(m < 0 || n < m) return 0;
	return f[n] * r[m] % mod * r[n-m] % mod;
}
int main(){
	cin >> n >> m;
	ll ans = 0;
	f[0] = 1;
	for(int i=1;i<500005;i++) f[i] = f[i-1]*1LL*i%mod;
	r[500004] = modpow(f[500004],mod-2);
	for(int i=500003;i>=0;i--) r[i] = r[i+1]*1LL*(i+1)%mod;
	
	for(int i=0;i<=min(n,m);i++){
		ll way = C(n,i)*C(m,i)%mod*f[i]%mod*modpow(m+1,n-i)%mod*modpow(n+1,m-i)%mod;
		if(i%2 == 0) ans += way;
		else ans -= way;
	}
	cout << (ans%mod+mod)%mod << endl;
}

Measured memory_bytes: 8064
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <functional>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,f,t) for(int i=f;i<t;i++)
#define P(r) do{cout<<#r": ";for(const auto &i:r){cout<<i<<" ";}cout<<endl;}while(0)
int main()
{
    int r, g, b; cin >> r >> g >> b;
    cout << ((r*100 + g*10+b)%4==0?"YES":"NO" )<< endl;
    return 0;
}

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

int main() {
  long long N; cin >> N;
  int sum =0;
  long long n = N;
  while(n>0) {
    sum += n%10;
    n /=10;
  }
  if(N%sum==0) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3508
#![allow(non_snake_case)]
fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let S:Vec<char> = sc.chars();
    let N = S.len();
    let mut ans:usize = 0;
    
    for i in 0..(N/2){
        if S[i] != S[N - 1 - i]{
            ans += 1;
        }
    }
    println!("{}", ans);

}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
        .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}




Measured memory_bytes: 4352
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define x real()
#define y imag()
#define fi first
#define se second
#define pii pair<int, int>

const int N = 3002;
int dp[N][N], arr[N][N];
signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
	string s, t;
	cin >> s >> t;
	int n = sz(s), m = sz(t);
	s = " " + s, t = " " + t;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (s[i] == t[j]) {
				dp[i][j] = 1 + dp[i - 1][j - 1];
				arr[i][j] = 3;
			} else {
				if (dp[i - 1][j] >= dp[i][j - 1]) {
					dp[i][j] = dp[i - 1][j];
					arr[i][j] = 1;
				} else {
					dp[i][j] = dp[i][j - 1];
					arr[i][j] = 2;
				}
			}
		}
	}
	int i = n, j = m;
	string ans = "";
	while (i > 0 && j > 0) {
		if (arr[i][j] == 3) {
			ans += string(1, s[i]);
			i--, j--;
		} else if (arr[i][j] == 2) {
			j--;
		} else {
			i--;
		}
	}
	reverse(ans.begin(), ans.end());
	cout << ans << "\n";
}



Measured memory_bytes: 141056
import sys
n=int(input())
a=list(map(int,input().split()))
cnt4=0
cnt2=0
for i in range(n):
  if a[i]%4==0:
    cnt4+=1
  elif a[i]%2==0:
    cnt2+=1
if n%2==1:
  if (2*cnt4)+1==n:
    print('Yes')
    sys.exit()
if n-(2*cnt4)<=cnt2:
    print('Yes')
    sys.exit()
else:
    print('No')
    sys.exit()


Measured memory_bytes: 14252
using System;
using System.Collections.Generic;
using System.Linq;
 
class Program
{
    static void Main(string [] args)
    {
        var x = int.Parse(Console.ReadLine());

        var m = 1;
        var i = 0;
        for (i = 0; m <= x; i++) m += i+1;

        Console.WriteLine(i);
    }
}

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

const int N = 1e6 + 10, mod = 1e9 + 7;
int ans, psuml[N];
string s;

int pw(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1)
			res = (res * a) % mod;
		a = (a * a) % mod;
		b /= 2;
	}
	return res;
}

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> s;
	
	for (int i = 1; i <= s.size(); i++)
		psuml[i] = psuml[i - 1] + (s[i - 1] == '1');
	
	for (int i = 0; i < s.size(); i++)
		if (s[i] == '1')
			ans = (ans + (pw(2, psuml[i]) * pw(3, (int)s.size() - i - 1) % mod)) % mod;
	cout << (ans + pw(2, psuml[(int)s.size()])) % mod;
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
using P=pair<long long,long long>;
typedef unsigned long long ull;
typedef long long ll;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);  
  
  int n;
  cin >> n;
  vector<P>vec;
  rep(i,n){
    ll a,b;
    cin >> a >> b;
    vec.push_back(make_pair(b,a));
  }
  sort(vec.begin(),vec.end());
  ll now=0;
  rep(i,n){
    if(now+vec[i].second>vec[i].first){
      cout << "No" << endl;
      return 0;
    }
    else{
      now+=vec[i].second;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 6384
#include <iostream>
#include <string>
#include <stack>

using namespace std;

int main() {
    string input;
    while (true) {
        stack<char> parenthesis;
        getline(cin, input);
        if (input == ".") {
            break;
        }
        bool is_valid = true;
        for (int i=0; i<(int)input.length(); i++) {
            if (input[i] == '(' || input[i] == '[') {
                parenthesis.push(input[i]);
            }
            else if (input[i] == ')') {
                if (parenthesis.size() > 0 && parenthesis.top() == '(') {
                    parenthesis.pop();
                }
                else {
                    is_valid = false;
                    break;
                }
            }
            else if (input[i] == ']') {
                if (parenthesis.size() > 0 && parenthesis.top() == '[') {
                    parenthesis.pop();
                }
                else {
                    is_valid = false;
                    break;
                }
            }
        }
        if (parenthesis.size() > 0) {
            is_valid = false;
        }
        if (is_valid) {
            cout << "yes" << endl;
        }
        else {
            cout << "no" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1176
package main

import (
	"fmt"
)

func main() {
	var min, minIdx, ans int

	min = 99
	m := make([]int, 5)
	for i := range m {
		fmt.Scan(&m[i])
		if m[i]%10 != 0 && m[i]%10 < min {
			min = m[i] % 10
			minIdx = i
		}
	}
	for i, v := range m {
		if i != minIdx {
			ans += v
			for ans%10 != 0 {
				ans++
			}
		}
	}
	ans += m[minIdx]
	fmt.Println(ans)
}


Measured memory_bytes: 1768
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll S;
  cin >> S;
  ll c = ceil(SQRT(S));
  ll d = c;
  while (d * c >= S) {
    d--;
  }
  d++;
  cout << "0 0 " << c << " " << 1 << " " << (c * d - S) << " " << d << endl;

  return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())

p = [x for x in range(1, n+1)]

for i in range(k*2):
    nums = list(map(int, input().split()))
    if i%2==0:
        pass
    else:
        for num in nums:
            if p.count(num) > 0:
                p.remove(num)

print(len(p))

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

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

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b; cin>>a>>b;
	int x=a+b;
	if(x>=10) cout << "error" << endl;
	else cout << x << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    string s, t;
    cin >> s >> t;
    int ans = INT_MAX;
    for(int i = 0; i <= s.size()-t.size(); i++) {
        int diff = 0;
        for(int j = 0; j < t.size(); j++) {
            if (t[j] != s[i+j])
                diff += 1;
        }
        ans = min(ans, diff);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n,m,c,a,i,j,k,ans=0;
  cin>>n>>m>>c;
  vector<int> b(m);
  for(j=0;j<m;j++) cin>>b.at(j);
  for(i=0;i<n;i++){
    k=c;
    for(j=0;j<m;j++){
      cin>>a;
      k+=a*b.at(j);
    }
    if(k>0) ans++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include <stdio.h>
char s[16];int n,a,r;
int main(void){
	for(;scanf("%d",&a),a;puts(s+n))
		for(n=15;a;a=(r-a)/10)
			r=a%10,r<0?r+=10:0,s[--n]=r+'0';
	return 0;
}

Measured memory_bytes: 0
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
signed main() {
    ll n, m;
    cin >> n >> m;
    vl data(m);
    for (int i = 0; i < n; i++) {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int a;
            cin >> a;
            data[a - 1]++;
        }
    }
    ll count = 0;
    for (int i = 0; i < m; i++) {
        if (data[i] == n) {
            count++;
        }
    }
    cout << count << endl;
}

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

ans = []
ps = []
if n % 2 == 0:
    ps = [1, n]
    for i in range(2, n // 2 + 1):
        for p in ps:
            ans.append((i, p))
            ans.append((n + 1 - i, p))
        ps.append(i)
        ps.append(n + 1 - i)
else:
    ps = [1, n - 1, n]
    ans.append((1, n))
    ans.append((n - 1, n))
    for i in range(2, n // 2 + 1):
        for p in ps:
            ans.append((i, p))
            ans.append((n - i, p))
        ps.append(i)
        ps.append(n - i)

print(len(ans))
print("\n".join([" ".join(map(str, ai)) for ai in ans]))

Measured memory_bytes: 39920
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,T;
    cin >> N >> T;
    ll mini = INF, dif = 0, ans = 0;
    rep(i,0,N){
        ll a;
        cin >> a;
        mini = min(mini, a);
        if(dif < a - mini){
            dif = a - mini;
            ans = 1;
        }else if(dif == a - mini){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
int n,arr[100001];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string x;
    cin>>x;
    for (auto i:x){
        if (i=='7'){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
    /*
    cin>>n;
    for (int i=0;i<n;i++){
        cin>>arr[i];
    }
    */
}

Measured memory_bytes: 3636
A = int(input())
B = int(input())
C = int(input())
X = int(input())

V = [500, 100, 50]

count = 0
ans = 0
def add(a, b, c):
    global ans
    count = V[0]*a + V[1]*b + V[2]*c
    if count==X:
        ans += 1
    return count

for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            add(a, b, c)

print(ans)


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

int main() {
	int K, N;
	cin >> K >> N;
	int A[N];
	for (int i=0; i<N; i++){
	    cin >> A[i];
	}
	sort(A, A+N);
	int MAX=0;
	for (int i=0; i<N-1; i++){
	    MAX=max(MAX,A[i+1]-A[i]);
	}
	MAX=max(MAX, K-A[N-1]+A[0]);
	cout << K-MAX << endl;
}


Measured memory_bytes: 4428
#include <iostream>
#include <cstring>
#include <cmath>
#include <bitset>
using namespace std;
const int N = 100;
const int M = 6401;
const int Y = 6400;
int H, W, A[N][N], B[N][N];
bitset<M*2> dp[N][N];


int main(){
    cin >> H >> W;
    for (int i = 1; i <= H; i++){
        for (int j = 1; j <= W; j++){
            cin >> A[i][j];
        }
    }
    for (int i = 1; i <= H; i++){
        for (int j = 1; j <= W; j++){
            cin >> B[i][j];
        }
    }
    dp[0][1][Y] = dp[1][0][Y] = 1;
    for (int i = 1; i <= H; i++){
        for (int j = 1; j <= W; j++){
            int cha = abs(A[i][j] - B[i][j]);
            dp[i][j] |= ((dp[i-1][j] << cha)|(dp[i-1][j] >> cha));
            dp[i][j] |= ((dp[i][j-1] << cha)|(dp[i][j-1] >> cha));
        }
    }
    int ans = INT32_MAX;
    for (int i = 0; i < 2*M; i++){
        if (dp[H][W][i]) ans = min(ans, abs(i-Y));
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
  int H1, M1, H2, M2, K;
  cin >> H1 >> M1 >> H2 >> M2 >> K;

  int SS = H1 * 60 + M1;
  int TT = H2 * 60 + M2;
  int BW = TT - SS - K;
  
  if(BW<0) BW = 0;
  cout << BW << endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <set>
#include <vector>
using namespace std;
using lint = long long int;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)


int main()
{
    int N;
    cin >> N;
    vector<int> P(N), Pinv(N + 1);
    REP(i, N) cin >> P[i], Pinv[P[i]] = i;

    multiset<int> m{-1, -1, N, N};
    lint ret = 0;
    IFOR(i, 1, N + 1)
    {
        lint now = Pinv[i];
        lint r = *m.lower_bound(now);
        lint rr = *next(m.lower_bound(now));
        lint l = *prev(m.lower_bound(now));
        lint ll = *prev(m.lower_bound(now), 2);
        ret += ((rr - r) * (now - l) + (l - ll) * (r - now)) * i;
        m.insert(now);
    }
    cout << ret << endl;
}


Measured memory_bytes: 5760
// B - Bingo
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int N;
vvi A(3,vi(3));
vi B;

auto solve(){
	rp(i,0,N)rp(r,0,3)rp(c,0,3) if(A[r][c] == B[i]) A[r][c] = 0;

	rp(r,0,3) if(!A[r][0] && !A[r][1] && !A[r][2]) return "Yes";
	rp(c,0,3) if(!A[0][c] && !A[1][c] && !A[2][c]) return "Yes";
	if(!A[0][0] && !A[1][1] && !A[2][2]) return "Yes";
	if(!A[2][0] && !A[1][1] && !A[0][2]) return "Yes";

	return "No";
}

int main(){
	rp(i,0,3) rp(j,0,3) cin>>A[i][j];
	cin>>N;
	B.resize(N); rp(i,0,N) cin>>B[i];
	cout<< solve() <<endl;
}

Measured memory_bytes: 256
my $N = <>;
my @A = split(/ /, <>);
my @B = split(/ /, <>);

$N--;
my $m = 0;
foreach my $i (0..$N){
        my $s = 0;
        foreach my $j (0..$i) {
                $s += $A[$j];
        }
        foreach my $k ($i..$N) {
                $s += $B[$k];
        }
        if ($s > $m) {
                $m = $s;
        }
}
print $m."\n";

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;
typedef priority_queue<int, vector<int>, greater<int>> PQ;

int main(){
    // lower_boundを行う際、条件を満たす要素がない場合は、配列の末尾の
    // イテレーターを返し、予期せぬ結果を返すことがあるので、最大値を設定
    vector<set<int>> indices(26, set<int>({100000000}));

    int N, Q;
    string S;
    cin >> N >> S >> Q;

    rep(i,N) indices[S[i]-'a'].insert(i);
    
    rep(i,Q){
        int type; cin >> type;
        if (type == 1){
            int index; cin >> index;
            index--;
            char letter; cin >> letter;
            indices[S[index]-'a'].erase(index);
            indices[letter-'a'].insert(index);
            S[index] = letter;
        }
        else{
            int left, right;
            cin >> left >> right;
            left--;
            int ans = 0;
            rep(i,26){
                if (indices[i].empty()) continue;
                int left_index = *indices[i].lower_bound(left);
                int right_index = *indices[i].lower_bound(right);
                if (right_index > left_index) ans++;
            }

            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 27260
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
MOD = 10**9+7

n = int(input())
T = [[] for _ in range(n)]
for _ in range(n-1):
  x, y = map(int, input().split())
  x -= 1
  y -= 1
  T[x].append(y)
  T[y].append(x)
dp = [[-1]*n for _ in range(2)]
def dfs(color, i, par=-1):
  if dp[color][i] != -1:
    return dp[color][i]
  res = 1
  if color == 0:
    for v in T[i]:
      if v == par:
        continue
      res *= dfs(0, v, i) + dfs(1, v, i)
      res %= MOD
  else:
    for v in T[i]:
      if v == par:
        continue
      res *= dfs(0, v, i)
      res %= MOD
  dp[color][i] = res
  return res
ans = dfs(0, 0) + dfs(1, 0)
ans %= MOD
print(ans)

Measured memory_bytes: 118064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;

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

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

ans = 0
minus_cnt = 0
min_num = 10000000000000
for i in a:
  if i < 0:
    minus_cnt += 1
  if abs(i) < min_num:
    min_num = abs(i)

case = minus_cnt % 2

for i in a:
   ans += abs(i)

if case == 1:
  ans -= 2 * min_num

print (ans)

Measured memory_bytes: 14412
// AOJ 1208
#include<cstdio>

int p, n;
int x, y, u, v;

void SternBrocot( int pl = 0, int ql = 1, int pr = 1, int qr = 0 )
{
	int pm = pl+pr, qm = ql+qr;

	if( pm > n || qm > n )
		return;

	if( pm*pm < p*qm*qm )
	{
		u = pm, v = qm;
		SternBrocot( pm, qm, pr, qr );
	}
	else if( pm*pm > p*qm*qm )
	{
		x = pm, y = qm;
		SternBrocot( pl, ql, pm, qm );
	}
	else
		x = u = pm, y = v = qm;

	return;
}

int main()
{
	while( scanf( "%d%d", &p, &n ), p|n )
	{
		SternBrocot();
		printf( "%d/%d %d/%d\n", x, y, u, v );
	}

	return 0;
}

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


int main()
{
	int n;
	cin>>n;
	unordered_set<int> st;

	for (int i = 0; i < n; ++i)
	{
		int tmp;
		cin>> tmp;
		st.insert(tmp);
	}
	printf("%d\n", st.size());



	return 0;
}

Measured memory_bytes: 256
//In the Name of ̲A̲l̲l̲a̲h̲

#define pb push_back
#define F first
#define S second
#define sz size()
#define ll long long

#include <bits/stdc++.h>

using namespace std;
const ll mod = 1e9 + 7;
ll n, dp[2][100011];
vector <ll> adj[100011];
bool mark[100011];
void dfs(int v)
{
    mark[v] = 1;
    for (int u:adj[v])
    {
        if (!mark[u])
        {
            dfs(u);
            dp[1][v] *= (dp[0][u]%mod);
            dp[0][v] *= ((dp[0][u]+dp[1][u])%mod);
            dp[1][v] %= mod;
            dp[0][v] %= mod;
        }
    }
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin >> n;
	for (int i = 0; i < n-1; i++)
    {
        ll x, y;
        cin >> x >> y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    fill (dp[0],dp[0]+n+10,1);
    fill (dp[1],dp[1]+n+10,1);
    dfs(1);
    cout << ((dp[0][1]+dp[1][1]+mod)%mod);

}

/*𝐻𝒶𝒹𝒾*/


Measured memory_bytes: 11520
h, w, k = [int(x) for x in input().rstrip().split(' ')]
counter = 0
mat = [[0 for j in range(w)] for i in range(h)]
for i in range(h):
  line = input().rstrip()
  for j, c in enumerate(line):
    if c == '#':
      mat[i][j] = 1
h_mask = [0 for i in range(h)]
w_mask = [0 for j in range(w)]
for itr in range(2**(h+w)):
  _counter = 0
  for i in range(h):
    h_mask[i] = itr%2
    itr//=2
  for j in range(w):
    w_mask[j] = itr%2
    itr//=2
  for i in range(h):
    for j in range(w):
      if h_mask[i] == 1 and w_mask[j] == 1:
        _counter += mat[i][j]
  if _counter == k:
    counter+=1

print(counter)

Measured memory_bytes: 9236