akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  V<string> s(3);
  rep(i,0,3)cin>>s[i];
  ll ans=siz(s[0])+siz(s[1])+siz(s[2]);
  V<int> v={0,1,2};

  map<Pi,set<int>> can;

  rep(i,0,3){
    rep(j,0,3){
      if(i==j)continue;

      rep(k,0,siz(s[i])+1){
        bool ok=true;
        rep(l,0,siz(s[j])){
          if(k+l>=siz(s[i]))break;

          if(s[i][k+l]!=s[j][l] && s[i][k+l]!='?' && s[j][l]!='?')ok=false;
        }
        if(ok)can[mp(i,j)].insert(k);
      }
    }
  }

  do{
    int i1,i2,i3;
    i1=v[0],i2=v[1],i3=v[2];

    rep(i,0,siz(s[i1])+1){//i2 start
      rep(j,i,max(siz(s[i2])+i+1,siz(s[i1])+1)){//i3 start
        if(can[mp(i1,i2)].count(min(i,siz(s[i1]))) && can[mp(i2,i3)].count(min(j-i,siz(s[i2])))){
          if(j<siz(s[i1]) && !can[mp(i1,i3)].count(min(j,siz(s[i1]))))continue;

          ll len=j+siz(s[i3]);
          chmax(len,i+siz(s[i2]));
          chmax(len,siz(s[i1]));
          chmin(ans,len);
        }
      }
    }
  }while(next_permutation(all(v)));


  cout<<ans<<ENDL;
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 512
# -*- coding: utf-8 -*-
N = int(input())
A = [int(n) for n in input().split()]

tmp = []
result = 1
diff = 0

for i, a in enumerate(A):
    if len(tmp) <= 0:
        tmp.append(a)
    else:
        if tmp[-1] == a:
            pass
        elif (a - tmp[-1]) * diff < 0:
            result += 1
            diff = 0
            tmp = [a]
        else:
            diff = a - tmp[-1]
            tmp.append(a)
print(result)

Measured memory_bytes: 14252
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <numeric>

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<long long> A(M, 0);
    for (int i = 0; i < M; ++i) {
        cin >> A[i];
    }

    long long sum = 0ll;
    for (int i = 0; i < M; ++i) {
        sum += A[i];
    }

    long long ans = N - sum;
    if (ans < 0) {
        ans = -1;
    }
    cout << ans << endl;
    //cout << setprecision(15) << endl;
    return 0;
}


Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000


int main(){
  int n;
  cin >> n;
  vint A(3*n);
  rep(i,n) cin >> A[3*i] >> A[3*i+1] >> A[3*i+2];
  sort(A.begin(),A.end());
  ll ans = 0;
  rep(i,n){
    ans += A[3*n-2-2*i];
  }
  cout << ans << endl;
}




Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int h[100009],K,n,dp[100009];
int f(int i)
{int ans2=INT_MAX;
int ans1;
 int sum1=0;
    if(i==n)
        return 0;
        if(dp[i]!=-1)
            return dp[i];
    for(int j=1;j<=K;j++)
       {

        if(i+j<=n){
    ans1=abs(h[i]-h[i+j])+f(i+j);
    }
  //  if(i<n-1)
    //ans2=abs(h[i]-h[i+2])+f(i+2);
    //else
      //  ans2=INT_MAX;
    ans2=min(ans2,ans1);
       }
    dp[i]=ans2;

    return dp[i];
}
int main()
{
    memset(dp,-1,sizeof(dp));
    //int
    cin>>n>>K;
    for(int i=1;i<=n;i++)
    {

        cin>>h[i];

    }
    cout<<f(1);
}


Measured memory_bytes: 5760
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  for_each(begin(A), end(A), [](auto& x) { cin >> x; });

  vector<ll> B(N);
  iota(begin(B), end(B), 1LL);

  vector<pair<ll, ll>> C;
  for (ll i = 0; i < N; i++) {
    C.emplace_back(A[i], B[i]);
  }
  sort(begin(C), end(C));

  for (const auto& x: C) {
    cout << x.second << " ";
  }
  return 0;
}


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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)(n-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aut(r,v) __typeof(v) r = (v)
#define each(it,o) for(aut(it,(o).begin()); it!=(o).end(); ++it)
#define reach(it,o) for(aut(it,(o).rbegin()); it!=(o).rend(); ++it)
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T1, typename T2> ostream& operator<<(ostream& o, const pair<T1, T2>& p)
{return o<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>string join(const vector<T>&v, string del=", ")
{stringstream s;rep(i,v.size())s<<del<<v[i];return s.str().substr(del.size());}
template<typename T>ostream& operator<<(ostream& o, const vector<T>&v)
{if(v.size())o<<"["<<join(v)<<"]";return o;}
template<typename T>ostream& operator<<(ostream& o, const vector<vector<T> >&vv)
{int l=vv.size();if(l){o<<endl;rep(i,l){o<<(i==0?"[ ":",\n  ")<<vv[i]<<(i==l-1?" ]":"");}}return o;}
template<typename T>ostream& operator<<(ostream& o, const set<T>& st)
{vector<T> v(st.begin(),st.end());o<<"{ "<<join(v)<<" }";return o;}
template<typename T1, typename T2>ostream& operator<<(ostream& o, const map<T1, T2>& m)
{each(p,m){o<<(p==m.begin()?"{ ":",\n  ")<<*p<<(p==--m.end()?" }":"");}return o;}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const ll INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int dp[110][2][5];

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    string s;
    int K;
    cin >> s >> K;
    int n = s.size();

    dp[0][0][0] = 1;
    rep(i, n) rep(j, 2) rep(k, K+1){
        int D = j ? 9 : s[i] - '0';
        rep(d, D+1){
            dp[i+1][j || d < D][k + (d != 0)] += dp[i][j][k];
        }
        debug(i,j,k)
    }
    cout << dp[n][0][K] + dp[n][1][K] << endl;
    return 0;
}

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


using namespace std;

#define ASIZE 100010

void dfs(const long& i, const long& start, const long& rootW,  const long& n, vector< pair<long,long> > (&ad)[ASIZE], vector<bool>& visited, vector<bool>& ans) {
    if ( visited[i] ) return;
    visited[i] = true;
    ans[i] = rootW%2==0 ? ans[start] : !ans[start];

    for (auto v : ad[i] ) {
        dfs(v.first, start, rootW + v.second, n, ad, visited, ans);
    }
}

int main() {
    long n;
    cin >> n;
    vector < pair<long,long> > ad [ASIZE];
    vector <bool> visited (ASIZE, false);
    vector <bool> ans (ASIZE, false);

    for (long i=1; i<n; i++) {
        long u,v,w;
        cin >> u >> v >> w;
        // ad[u][v] = ad[v][u] = w;
        ad[u].push_back( make_pair(v,w) );
        ad[v].push_back( make_pair(u,w) );
    }
    

    for (long i=1; i<=n; i++) {
        if ( visited[i] ) continue;
        ans[i] = true;
        dfs(i, i, 0, n, ad, visited, ans);
    }

    for (long i=1; i<=n; i++) {
        cout << ans[i] << endl;
    }
    // cout << endl;
  
}

Measured memory_bytes: 12672
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5;

ll mpow(ll a, ll b){
	if(b==0) return 1;
	else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
	else return mpow(a,b-1) * a % MOD;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
	if(kaijo_memo.size() > n) return kaijo_memo[n];
	if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
	while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
	return kaijo_memo[n];
}
ll nCr(ll n, ll r){
	if(n < r || r < 0) return 0;
	ll ret = 1;
	ret *= kaijo(n); ret %= MOD;
	ret *= mpow(kaijo(r), MOD-2); ret %= MOD;
	ret *= mpow(kaijo(n-r), MOD-2); ret %= MOD;
	return ret;
}

int main(void){
	int n;cin>>n;
	vector<vector<int>> A;
	vector<int> idx;
	vector<bool> flag;
	rep(i,n){
		A.push_back(vector<int>());
		idx.push_back(0);
		flag.push_back(true);
		rep(j,n-1){
			int a;
			cin>>a;a--;
			A[i].push_back(a);
		}
	}
	queue<int> q;
	ll ans = 0;
	rep(i,n){
		q.push(i);
	}
	queue<int> q2,q3;
	while(q.size() > 0){
		ans++;
		while(q.size() > 0){
			int next = q.front(); q.pop();
			int enemy = A[next][idx[next]];
			if(A[enemy][idx[enemy]] == next){
				q2.push(next);
				if(idx[next] + 1 < n-1) q3.push(next);
				if(!flag[enemy]){
					flag[enemy] = true;
					q2.push(enemy);
					if(idx[enemy] + 1 < n-1) q3.push(enemy);
				}
			}else{
				flag[next] = false;
			}
		}
		if(q2.size() == 0){
			cout<<-1<<endl;
			return 0;
		}
		while(q2.size() > 0){
			int now = q2.front(); q2.pop();
			idx[now]++;
		}
		while(q3.size() > 0){
			int now = q3.front();q3.pop();
			q.push(now);
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;
int main() {
    int N;
    int tmp;
    int sum;

    cin >> N;
    tmp = N;
    sum = 0;
    while (1) {
        if (tmp == 0)
            break;
        sum += tmp % 10;
        tmp /= 10;
    }

    if (N % sum == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
while True:
    n=input()
    if n=="END OF INPUT":
        break
    
    a=list(n)
    count=0
    for i in range(len(a)):
        if a[i]!=' ':
            count+=1
        else:
            print(count,end="")
            count=0
    print(count)


Measured memory_bytes: 5556
#include<bits/stdc++.h>
using namespace std;
     
int main(){
ios_base :: sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

	int i,j,k,n,l;
	string a,v="";
	cin>>n>>l;
	vector<string> s;
	for(i=0;i<n;i++){
		cin>>a;
		s.push_back(a);
	}
    sort(s.begin(),s.end());
    for(i=0;i<n;i++){
    	v+=s[i];
	}
	cout<<v;
    	
}

Measured memory_bytes: 3636
import math

N = int(input())

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

m1 = math.ceil(sum(X) / N)
m2 = math.floor(sum(X) / N)

res1 = 0
res2 = 0

for i in range(N):
    res1 += (X[i] - m1) ** 2
    res2 += (X[i] - m2) ** 2
    
print(min(res1, res2))

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define llu unsigned long long
#define ld double
#define llu unsigned long long
#define rep(i,x,y)  for(ll i=(ll)(x);i<(ll)(y);++i)
#define For(i,x,y)  for(ll i=(ll)(x);i<=(ll)(y);++i)
#define FOr(i,x,y)  for(ll i=(ll)(x);i>=(ll)(y);--i)
#define pi acos(-1) 
#define mk make_pair
#define pa pair<ll,ll>
#define lf else if
#define IL inline
#define max(x,y)    ((x)<(y)?(y):(x))
#define min(x,y)    ((x)<(y)?(x):(y))
#define sqr(x)      ((x)*(x))
#define Mul(x,y)    ((x)=1LL*(x)*(y)%mod)
#define Add(x,y)    ((x)=((x)+(y))%mod)
#define E(x)        return writeln(x),0
#define LL			(long long)
#define p(x)        printf("~%lld~\n",LL(x))
#define pp(x,y)     printf("~~%lld %lld~~\n",LL(x),LL(y))
#define ppp(x,y,z)  printf("~~~%lld %lld %lld~~~\n",LL(x),LL(y),LL(z))
#define pppp(a,b,c,d)	printf("~~~%lld %lld %lld %lld\n",LL(a),LL(b),LL(c),LL(d))
#define f_in(x)     freopen(x".in","r",stdin)
#define f_out(x)    freopen(x".out","w",stdout)
#define open(x)     f_in(x),f_out(x)
#define fi first
#define se second
#define GuYue		puts("\nGuYueNa________________________________________________________________________________")
#define y1			fafa____
typedef complex<double> E;
namespace SHENZHEBEI{
#ifdef LOCAL
    struct _{_(){freopen("cf.in","r",stdin);}}_; 
#endif 
#define NEG 1
    static const int GYN=2333333;
    char SZB[GYN],*S=SZB,*T=SZB;
    inline char gc(){   if (S==T){  T=(S=SZB)+fread(SZB,1,GYN,stdin); if (S==T) return '\n';  }   return *S++;    }
#if NEG
    inline ll read(){    ll x=0,g=1; char ch=gc();   for (;!isdigit(ch);ch=gc()) if (ch=='-') g=-1;  for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x*g; }
    inline void write(ll x){    if (x<0) putchar('-'),x=-x;  if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#else
    inline ll read(){    ll x=0; char ch=gc();   for (;!isdigit(ch);ch=gc());    for (;isdigit(ch);ch=gc())  x=x*10-48+ch;   return x;   }
    inline void write(ll x){    if (x>=10)   write(x/10);    putchar(x%10+'0');  }
#endif
    inline char readchar(){ char ch=gc();   for(;isspace(ch);ch=gc());  return ch;  }
    inline ll readstr(char *s){ char ch=gc();   int cur=0;  for(;isspace(ch);ch=gc());      for(;!isspace(ch);ch=gc())  s[cur++]=ch;    s[cur]='\0';    return cur; }
	void Print(long long *a,int s,int t){For(i,s,t)printf("%lld ",a[i]);puts("");}
	void Print(int *a,int s,int t){For(i,s,t)printf("%d ",a[i]);puts("");}
	void Print(char *a,int s,int t){For(i,s,t)putchar(a[i]);puts("");}
	void writeln(ll x){write(x);putchar('\n');}
}using namespace SHENZHEBEI;
const ll N=2010,mod=1e9+7;
ll f[N][N],sum[N][N],n,K,answ;
int main(){
	n=read(),K=read();
	f[n+1][0]=1;
	FOr(i,n+1,0)FOr(j,n+1,0){
		if (i==1&&j==n-K)answ=sum[i+1][j];
		Add(f[i][j],sum[i+1][j]+f[i][j+1]);
		sum[i][j]=((j>=1?sum[i+1][j-1]:0ll)+f[i][j])%mod;
	}
	For(i,1,n-K-1)Mul(answ,2);
	writeln(answ);
}
/*
f[4][0]
f[3][0]
f[2][0]=2	f[2][1]=1
32	23		2?
21

一定是1在结尾....

他不一定选2啊。
f[2][1]...
f[1][1]
f[j][k]
小的那个是i,上面还有j剩下。
1.选择上面的
2.枚举下一个。。
选1个,2个,3个。.
*/

Measured memory_bytes: 63744
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		String msg = "Good";

		for (int i = 0; i < 3; i++) {
			if (s.substring(i, i + 1).equals(s.substring(i + 1, i + 2))) {
				msg = "Bad";
			}
		}

		System.out.println(msg);

	}
}


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

int main() {
	int n;
	cin >> n;
	
	vector<int> a(n);
	
	int sum  = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		if (sum == 0){
			sum = a[i];
		}else{
			sum ^= a[i];
		}
	}
	
	for(int i = 0; i < n; i++){
		cout << (sum ^ a[i]) << " ";
	}
	
	return 0;
}

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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    int len = s.length();
    int count = 0;
    for(int i = 0; i <= len; i++){
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')
        {
        count++;
        }
    }
    cout << count << endl;


    return 0;
}


Measured memory_bytes: 256
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;


// 最大公約数（Greatest Common Divisor）
uint64_t gcd(uint64_t m, uint64_t n)
{
	// ユークリッドの互除法
	for (;;)
	{
		if (0 == m) { return n; }
		n %= m;
		if (0 == n) { return m; }
		m %= n;
	}
}
// 最小公倍数（Least Common Multiple）を返す。
uint64_t lcm(uint64_t m, uint64_t n)
{
	if (0 == m) { return n; }
	if (0 == n) { return m; }
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

int32_t Q;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> Q;
	while (Q--)
	{
		int64_t a, b, c, d;
		in >> a >> b >> c >> d;

		if (d < b) {
			out << "No\n";
			continue;
		}
		if (a < b) {
			out << "No\n";
			continue;
		}
		if (c+1 >= b) {
			out << "Yes\n";
			continue;
		}
		a = a - (a / b)*b;
		if (d%b == 0) {
			if (a <= c) {
				out << "Yes\n";
			}
			else {
				out << "No\n";
			}
			continue;
		}

		auto diff = d % b;
		auto diff2 = gcd(b, diff);
		auto err = b-1 - c;//(b,c)
		if (err >= diff2) {
			out << "No\n";
			continue;
		}
		//(c,b)で%diff2 == aが無ければ
		if ((c+ 1) % diff2 <= (b - 1) % diff2) {
			if ((c + 1) % diff2 <= a % diff2 && a%diff2 <= (b - 1) % diff2) {
				out << "No\n";
				continue;
			}
		}
		else {
			if ((b - 1) % diff2 <= a % diff2 || a%diff2 <= (c + 1) % diff2) {
				out << "No\n";
				continue;
			}
		}

		out << "Yes\n";

	}

	return 0;
}
#endif


Measured memory_bytes: 256
/**
 	Template created by Danel Batyrbek
 	All rights are reserved 2017 (lol)
*/
 
#include <bits/stdc++.h>
 
#define speed_up ios_base :: sync_with_stdio(0);cin.tie(0)
#define fr first
#define sc second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define debug(x) cerr << x << '\n';
#define YES "YES"
#define NO "NO"
#define skip continue
#define left(x) x << 1
#define rght(x) x << 1 | 1
#define forn(x, y, z) for(int x = y; x <= z; ++ x)
#define for1(x, y, z) for(int x = y; x >= z; -- x)
#define fname ""
using namespace std;
 
typedef long long ll;
typedef pair <int, int> pii;
typedef double ld;
 
const int N = 1e5 + 10;
const int mod = 1e9 + 7;
const int N3 = 1e3 + 10;
const int INF = 2e9 + 10;
const ll LINF = 2e18;
 
int n, a[N + N], x[N + N];
pii bord[N + N];
ll ans;
 
struct SetTree {
	int mn[N * 8], add[N * 8];
 
	void push(int x, int tl, int tr){
		if(tr <= tl) return;
		mn[x] += add[x];
		if(tl < tr - 1){
			add[left(x)] += add[x];
			add[rght(x)] += add[x];
		}
		add[x] = 0;
		return;
	}
 
	ll get(int x, int tl, int tr, int ql, int qr){
		//if(ql == 6 && qr == 9) cerr << x << ' ' << tl << ' ' << tr << '\n';
		if(tl >= tr) return INF;
		push(x, tl, tr);
		if(qr <= tl || tr <= ql) return INF;
		if(ql <= tl && tr <= qr) return mn[x];
		int md = (tl + tr + 1) >> 1;
		return min(get(left(x), tl, md, ql, qr), get(rght(x), md, tr, ql, qr));	
	}
 
	void upd(int x, int tl, int tr, int ql, int qr, int val){
		//cerr << x << ' ' << tl << ' ' << tr << ' ' << ql << ' ' << qr << '\n';
		if(tl >= tr) return;
		push(x, tl, tr);
		if(qr <= tl || tr <= ql) return;
		if(ql <= tl && tr <= qr){
			add[x] += val;
			push(x, tl, tr);
			return;
		}
		int md = (tl + tr + 1) >> 1;
		upd(left(x), tl, md, ql, qr, val);
		upd(rght(x), md, tr, ql, qr, val);
		mn[x] = min(mn[left(x)], mn[rght(x)]);
		return;
	}
 
} t;
 
int main(){
#ifndef DEBUG
	if(fname != ""){
	freopen(fname".in", "r", stdin);
	freopen(fname".out", "w", stdout);
	}
#endif
	cin >> n;
	forn(i, 1, n){
		cin >> a[i];
		bord[a[i]] = mkp(1, n);
		t.upd(1, 1, n + 1, i, i + 1, a[i]);
		x[a[i]] = i;
	}
	for(long long i = 1; i <= n; ++ i){
		ll len1 = (x[i] - bord[i].fr + 1);
		ll len2 = (bord[i].sc - x[i] + 1);
		ans += (i * len1 * len2);
		//cerr << bord[i].fr << ' ' << x[i] << ' ' << bord[i].sc << ' ' << i << ' ' << len1 << ' ' << len2 << ' ' << i * len1 * len2 << '\n';
		t.upd(1, 1, n + 1, x[i], x[i] + 1, INF);
		//cerr << "OK\n";
		int xl = t.get(1, 1, n + 1, bord[i].fr, x[i]);
		//cerr << '\n';
		int xr = t.get(1, 1, n + 1, x[i] + 1, bord[i].sc + 1);
		//cerr << xl << ' ' << xr << "\n";
		if(xl != INF) {bord[xl].sc = x[i] - 1, bord[xl].fr = bord[i].fr;}
		if(xr != INF) {bord[xr].fr = x[i] + 1, bord[xr].sc = bord[i].sc;}
		if(x[i] - 1 != 0) bord[a[x[i] - 1]].sc = x[i] - 1;
		if(x[i] + 1 <= n) bord[a[x[i] + 1]].fr = x[i] + 1;
		//cerr << "END\n";
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 9600
N,K,Q = map(int,input().split())
points = [0] * (N+1)
for i in range(Q):
    a = int(input())
    points[a] += 1
for i in range(1,N+1):
    if points[i] + K > Q:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 9752
#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include<bits/stdc++.h>
using namespace std;
int main(){
    int k, x;
    cin >> k >> x;
    if(x<=k*500)cout << "Yes";
    else cout << "No";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,d;
    cin>>n>>d;
    int count=0;
    for(int i=0;i<n;i++){
        double a;
        double b;
        cin>>a>>b;
        double c=sqrt(a*a+b*b);
        if(c<=d) count++;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 3816
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int p[] = new int[N];
		int max = 0;
		int ans = 0;
		for (int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
			ans += p[i];
			if (max < p[i]) {
				max = p[i];
			}
		}
		sc.close();
		ans = ans - max / 2;
		System.out.println(ans);
	}
}


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

int main()
{
    int a,b,c,d;
    int area1, area2;
    cin>>a>>b>>c>>d;
    
    area1= a*b;
    area2= c*d;

   if(area1>area2)
   cout<<area1;
else { cout<<area2;}
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

int h[100005];
int n,k;
long long dp[100005];

int main()
{
    cin >> n >> k;
    for (int i = 0;i < n;i++){
        cin >> h[i];
    }
    
    for (int i = 1;i < n;i++){
        dp[i] = 1000000000;
    }
    
    dp[0] = 0;
    for (int i = 0;i < n;i++){
        for (int j = 0;j < k;j++){
            dp[i+j+1] = min(dp[i+j+1],abs(h[i]-h[i+j+1])+dp[i]);
        }
    }
    cout <<  dp[n-1] << endl;
    }


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


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();

		char[] s = sc.next().toCharArray();

		Deque<Character> st = new ArrayDeque<>();

		for (int i = 0; i < n; i++) {
			if (s[i] == '(') {
				st.push(s[i]);
			} else {
				if (st.size() > 0 && st.peek() == '(') {
					st.pop();
				} else {
					st.push(s[i]);
				}
			}
		}

		StringBuilder ret = new StringBuilder();
		ret.append(s);
		for (char c : st) {
			if (c == ')') {
				ret.insert(0, '(');
			} else {
				ret.append(')');
			}
		}

		pr.println(ret);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 21844
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	paramS := scanner.Text()
	scanner.Scan()
	paramT := scanner.Text()
	if strings.HasPrefix(paramT, paramS) && len(paramT) == len(paramS)+1 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1756
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int mod=998244353;
int fac[500005],ifac[500005];
inline int power(int a,int b){
	int c=1;
	while(b){
		if(b&1)c=1ll*c*a%mod;
		a=1ll*a*a%mod;
		b>>=1;
	}
	return c;
}
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	fac[0]=1;
	for(int i=1;i<=k;i++)fac[i]=1ll*fac[i-1]*i%mod;
	ifac[k]=power(fac[k],mod-2);
	for(int i=k;i>0;i--)ifac[i-1]=1ll*ifac[i]*i%mod;
	int ans=0;
	for(int i=n;i<=k;i++)ans=(ans+1ll*fac[k-1]*ifac[i-1]%mod*ifac[k-i])%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4096
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;
using ll = long long;

#define REP(i, a) for (int i = 0; i < (a); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a)-1; i >= (b); --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond, yes, no) \
    { cout << ((cond) ? (yes) : (no)) << endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(), (list).rend())
#define ASSERT(cond, mes) assert(cond&& mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())
    is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a) n = a;
    if (n > b) n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

std::vector<ll> enum_div(ll n) {
    std::vector<ll> ret;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) { ret.push_back(n / i); }
        }
    }
    return ret;
}

template <typename T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

struct ToUpper {
    char operator()(char c) {
        return toupper(c);
    }
};

struct ToLower {
    char operator()(char c) {
        return tolower(c);
    }
};

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

    int N;
    cin >> N;
    vector<int> A(N);
    cin >> A;

    auto solve = [&]() {
        int o = count_if(ALL(A), [](int a) { return a % 2 == 1; });
        if (o > 0) return true;
        return false;
    };

    YESNO(solve(), "first", "second");

    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<queue>
#include<utility>
#include<functional>
#include<algorithm>
using namespace std;

struct edge{
    int v,d;
    edge(int v,int d):v(v),d(d){}
};

struct pqnode{
    int p,v,d;
    pqnode(int p=0,int v=0,int d=0):p(p),v(v),d(d){}
    bool operator<(const pqnode &other) const{
        return d>other.d;
    }
};

vector<edge> E[810];
int n, tmp[810];
bool leaf[810];

pair<int,int> bfs(int s){
    int v;
    pqnode now;

    priority_queue<pqnode> Q;
    Q.push(pqnode(s,s,0));

    while(!Q.empty()){
        now=Q.top();
        v=now.v;
        for(int i=0;i<E[v].size();++i){
            int u=E[v][i].v, d=E[v][i].d;

            if(u==now.p || leaf[u]) continue;
            Q.push(pqnode(v,u,now.d+d));
        }
        Q.pop();
    }
    return make_pair(now.v,now.d);
}

int main(){
    while(true){
        int tot=0;

        cin>>n;
        if(!n) return 0;
        for(int v=1;v<=n;++v){
            E[v].clear();
            leaf[v]=false;
        }
        for(int v=2;v<=n;++v){ cin>>tmp[v]; }
        for(int v=2;v<=n;++v){
            int d;
            cin>>d;
            E[v].push_back(edge(tmp[v],d));
            E[tmp[v]].push_back(edge(v,d));
            tot += 3*d;
        }

        int s=1;
        for(int v=1;v<=n;++v){
            if(E[v].size()==1){ //leaf
                leaf[v]=true;
                if(v==1) s=E[1][0].v;
                tot -= 2*E[v][0].d;
            }
        }

        int f=bfs(s).first;
        int mx=bfs(f).second;
        cout<<(tot-mx)<<endl;
    }
}


Measured memory_bytes: 3208
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define ALL(x) (x).begin(), (x).end()
#define rt return
#define dll(x) scanf("%I64d",&x)
#define xll(x) printf("%I64d\n",x)
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define eps 1e-6
#define gg(x) getInt(&x)
#define db(x) cout<<"== [ "<<x<<" ] =="<<endl;
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll powmod(ll a,ll b,ll MOD){ll ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n;
pair<ll,ll> a[maxn];
bool cmp(pair<ll,ll> p1,pair<ll,ll> p2)
{
	return p1.fi+p1.second>p2.second+p2.first;
}
int main()
{
	gbtb;
	cin>>n;
	repd(i,1,n)
	{
		cin>>a[i].fi>>a[i].se;
	}
	sort(a+1,a+1+n,cmp);
	ll s1=0ll;
	ll s2=0ll;
	repd(i,1,n)
	{
		if(i&1)
			s1+=a[i].fi;
		else
			s2+=a[i].se;
	}
	cout<<s1-s2<<endl;
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define lint long long
#define pii pair<int, int>
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) (v).begin(), (v).end()
#define SZ(v) ((int)v.size())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define MINF(a) memset(a, 0x3f, sizeof(a))
#define POW(n) (1LL << (n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i, a, b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const 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> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double PI = 3.14159265358979323846;
const double EPS = 1e-10;

int N;

void _main() {
    cin >> N;
    vector<int> A(3 * N);
    cin >> A;
    SORT(A);
    int ans = 0;
    for (int i = N; i < 3 * N; i += 2) {
        ans += A[i];
    }
    cout << ans << endl;
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i')) freopen("input.txt", "r", stdin);
        if (strchr(argv[1], 'o')) freopen("output.txt", "w", stdout);
    }
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

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

int main(){
	int N;
	string token, temp;
	cin >> N;
	cout << "0" << endl;
	cin >> token;
	if( token == "Vacant" ){
		return 0;
	}
	int L=0, R=N, mid;
	while(1){
		mid = (L+R)/2;
		cout << mid << endl;
		cin >> temp;
		if( temp == "Vacant" ){
			break;
		} else if ( ( temp == token && mid % 2 == 0 ) || ( temp != token && mid % 2 == 1 ) ){
			L = mid;
		} else {
			R = mid;
		}
	}
	return 0;
}

Measured memory_bytes: 852
#include <iostream>
#include <vector>
#include <map>
#include <functional>

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;

using lint = long long;

constexpr lint MOD = 1000000009, B = 100007;

void solve() {
    int n;
    std::cin >> n;

    Graph<> graph(n);
    for (int i = 0; i < n - 1; ++i) {
        int u, v;
        std::cin >> u >> v;
        --u, --v;

        graph[u].emplace_back(u, v);
        graph[v].emplace_back(v, u);
    }

    std::map<lint, lint> cnt;
    std::function<lint(int, int)>
        dfs = [&](int v, int p) {
            lint ret = 1;
            for (auto e : graph[v]) {
                if (e.dst == p) continue;
                (ret += dfs(e.dst, v) * B % MOD) %= MOD;
            }

            if (!cnt.count(ret)) cnt[ret] = 0;
            ++cnt[ret];

            return ret;
        };
    dfs(0, -1);

    lint ans = 0;
    for (auto p : cnt) {
        lint c = p.second;
        ans += c * (c - 1) / 2;
    }

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

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

    solve();

    return 0;
}



Measured memory_bytes: 23924
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N , M;
    cin >> N >> M;
    vector<pair<int, int>> c(M);
    for(int i = 0; i < M ; i++){
        cin >> c.at(i).first >> c.at(i).second;
    }
    sort(c.begin(), c.end());
    //int check = 0;
    if(M == 0){
        if(N == 1){
            printf("0\n");
            exit(0);
        }
        printf("1");
        for(int i = 0; i < N-1; i++){
            printf("0");
        }
        printf("\n");
        exit(0);
    }
    for(int i = 0; i < M-1; i++){
        if(c.at(i).first == 1 && c.at(i).second == 0 && N != 1){
                printf("-1\n");
                exit(0);
                //check++;
                //break;
        }
        if(c.at(i).first == c.at(i+1).first){
            if(c.at(i).second != c.at(i+1).second){
                printf("-1\n");
                exit(0);
                //check++;
                //break;
            }
        }
    }
    if(c.at(M-1).first == 1 && c.at(M-1).second == 0 && N != 1){
        printf("-1\n");
        exit(0);
    }
    //if(check == 0){
        vector<int> ans(N, 0);
        ans.at(0) = 1;
        for(int i = 0; i < M; i++){
            ans.at(c.at(i).first - 1) = c.at(i).second; 
        }
        for(int i = 0; i < N; i++){
            printf("%d",ans.at(i));
        }
        printf("\n");
    //}
}

Measured memory_bytes: 256
/**
 * Created by hiramekun at 20:44 on 2019-12-08.
 */
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG  
using namespace std;
using ll = long long;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main() {
    ll h, w;
    cin >> h >> w;
    vector<bool> v;
    v[0];
    vector<int> v2;
    v2[0];
    int a[h][w], b[h][w];
    rep(i, h) rep(j, w) cin >> a[i][j];
    rep(i, h) rep(j, w) cin >> b[i][j];

    ll max_diff = 2 * 80 * 160;
    bool dp[h][w][max_diff];
    rep(i, h) rep(j, w) rep(l, max_diff) dp[i][j][l] = false;

    ll mid = max_diff / 2;
    dp[0][0][b[0][0] - a[0][0] + mid] = true;
    dp[0][0][-b[0][0] + a[0][0] + mid] = true;

    rep(i, h) {
        rep(j, w) {
            rep(l, max_diff) {
                if (i + 1 <= h - 1) {
                    dp[i + 1][j][l + b[i + 1][j] - a[i + 1][j]] |= dp[i][j][l];
                    dp[i + 1][j][l - b[i + 1][j] + a[i + 1][j]] |= dp[i][j][l];
                }
                if (j + 1 <= w - 1) {
                    dp[i][j + 1][l + b[i][j + 1] - a[i][j + 1]] |= dp[i][j][l];
                    dp[i][j + 1][l - b[i][j + 1] + a[i][j + 1]] |= dp[i][j][l];
                }
            }
        }
    }
    ll ans = 1e18;
    rep(i, max_diff) {
        if (dp[h - 1][w - 1][i]) ans = min(ans, abs(i - mid));
    }
    cout << ans << '\n';
}


Measured memory_bytes: 160384
import * as fs from "fs";

let input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");

const F = "F";
const T = "T";
const s: Array<"F" | "T"> = input[0].split("") as Array<"F" | "T">;
let [x, y] = input[1].split(" ").map((x: string): number => +x);

while (s.length > 0 && s[0] === F) {
	s.shift();
	x -= 1;
}

let dir = true; // true:x, false:y

type Query = { dir: boolean, dist: number };
const q: Array<Query> = [];
let dist = 0;
let prev: "F" | "T" = T;

let i = 0;
while (i < s.length) {
	while (i < s.length && s[i] === T) {
		dir = !dir;
		i++;
	}
	while (i < s.length && s[i] === F) {
		dist += 1;
		i++;
	}
	q.push({dir, dist});
	dist = 0;
}

const qx = q.filter((q) => q.dir).sort((a, b) => a.dist - b.dist).map((q) => q.dist);
const qy = q.filter((q) => !q.dir).sort((a, b) => a.dist - b.dist).map((q) => q.dist);

const lim_x = qx.reduce((a, b) => a + b, 0);
const lim_y = qy.reduce((a, b) => a + b, 0);

const dpx = new Array<Array<boolean>>();
for (let i = 0; i <= qx.length; i++) {
	dpx.push(new Array<boolean>(lim_x * 2 + 1).fill(false));
}
const dpy = new Array<Array<boolean>>();
for (let i = 0; i <= qy.length; i++) {
	dpy.push(new Array<boolean>(lim_y * 2 + 1).fill(false));
}

dpx[0][lim_x] = true;
dpy[0][lim_y] = true;

for (let i = 0; i < qx.length; i++) {
	for (let ii = 0; ii <= lim_x * 2; ii++) {
		if (dpx[i][ii]) {
			dpx[i + 1][ii - qx[i]] = dpx[i + 1][ii + qx[i]] = true;
		}
	}
}

for (let i = 0; i < qy.length; i++) {
	for (let ii = 0; ii <= lim_y * 2; ii++) {
		if (dpy[i][ii]) {
			dpy[i + 1][ii - qy[i]] = dpy[i + 1][ii + qy[i]] = true;
		}
	}
}

if (dpx[qx.length][x + lim_x] && dpy[qy.length][y + lim_y]) console.log("Yes");
else console.log("No");


Measured memory_bytes: 153364
import sys
sys.setrecursionlimit(500)


def calc(N, K):
    if len(N) < K or K <= 0:
        return 0
    tmp = 9 - int(N[0])
    for i in range(K-1):
        tmp *= 9 * (len(N) - 1 - i)
    for i in range(K-1):
        tmp //= (i+1)
    if N[0] != "0":
        return tmp + calc(N[1:], K-1)
    else:
        return tmp + calc(N[1:], K)


def main():
    N = input()
    K = int(input())
    if len(N) < K:
        print(0)
        return
    ans = 1
    for i in range(K):
        ans *= 9 * (len(N) - i)
    for i in range(K):
        ans //= (i+1)
    ans -= calc(N, K)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 38256
s = input()
s = s[::-1]
wards = ["maerd","remaerd","esare","resare"]
can = True
while can:
    can = False
    for i in wards:
        if s.startswith(i):
            s = s.replace(i,"",1)
            can = True
if s == "":
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define lli long long int
#define tc int t;cin>>t;while(t--)
#define all(x) x.begin(),x.end()
#define f first
#define s second
#define pb push_back
#define vi vector<int>
#define vll vector<lli>
#define maxn 1000005
#define mod 1000000007



int main(){
    fastio;
    int n,m,re,ans=0;
    cin>>n>>m>>re;
    string c[n];
    for(int i=0;i<n;i++)
    {
        cin>>c[i];
    }
    for(int i=0;i<(1<<n);i++)
    {
        for(int j=0;j<(1<<m);j++)
        {
            int cnt=0;
            for(int k=0;k<n;k++){
                for(int l=0;l<m;l++)
                {
                    if(i&(1<<k) or j&(1<<l) or c[k][l]=='.')
                    continue;
                    cnt++;
                }
            }
            if(cnt==re) ans++;
        }
    }
    cout<<ans<<"\n";
    return 0;
}



Measured memory_bytes: 3672
a, b, c = map(int, input().split())
print(min(
    abs(a-b) + abs(b-c),
    abs(a-c) + abs(c-b),
    abs(b-a) + abs(a-c),
    abs(b-c) + abs(c-a),
    abs(c-a) + abs(a-b),
    abs(c-b) + abs(b-a)
))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
typedef pair<pll, pll> P;
const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 1;
//---------------------------------//

pii mindist[212345][2]; // [0]:right, [1]:left
ll ans[212345];

int main() {
	string S; cin >> S;
	int N = S.size();
	
	fill(mindist[0], mindist[N], pii(INF, -1));
	
	for (int i = N - 2; i >= 0; i--) {
		if (S[i] == 'R' && S[i + 1] == 'L') mindist[i][0] = pii(0, i);
		else mindist[i][0] = pii(mindist[i + 1][0].fi + 1, mindist[i + 1][0].se);
	}
	
	FOR(i, 1, N) {
		if (S[i - 1] == 'R' && S[i] == 'L') mindist[i][1] = pii(0, i);
		else mindist[i][1] = pii(mindist[i - 1][1].fi + 1, mindist[i - 1][1].se);
	}
	
	REP(i, N) {
		int pos = mindist[i][S[i] == 'L'].se;
		if (mindist[i][S[i] == 'L'].fi % 2 == 1) pos += S[pos] == 'R' ? 1 : -1;
		ans[pos]++;
	}
	
	REP(i, N) printf("%d%c", ans[i], i == N - 1 ? '\n' : ' ');
	
	return 0;
}


Measured memory_bytes: 3840
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#include<bits/stdc++.h>
using namespace std;

#if defined(DAIJOBU)
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}


int main(){
	FIO
	
	int n;cin >> n;
	long long sum = 0, a[n];
	for(int i = 0; i < n; i++){
		cin >> a[i];sum += a[i];
	}
	sort(a, a + n);
	cout << a[0] << " " << a[n - 1] << " "  << sum << '\n';
	return 0;
}



Measured memory_bytes: 3296
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>
#include <limits>
#include <map>
#include <set>
#include <functional>

using namespace std;

int main()
{
  string S;

  cin >> S;

  int result = 0;
  int continuos_count = 0;

  for (size_t i = 0; i < S.size(); i++) {
    if (S[i] == 'R') {
      continuos_count++;
    }
    else {
      continuos_count = 0;
    }
    result = max(result, continuos_count);
  }

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 3604
use proconio::{input, fastout, marker::Chars};

#[fastout]
fn main() {
    input! {
        h: usize,
        w: usize,
        k: usize,
        c: [Chars; h],
    }
    let mut res = 0;

    for i in 0..((2 as usize).pow(h as u32)) {
        for j in 0..((2 as usize).pow(w as u32)) {
            let mut temp_c = c.clone();
            for ii in 0..h {
                if ((i+1) & (1 << ii)) > 0 {
                    for i_j in 0..w {
                        temp_c[ii][i_j] = 'r';
                    }
                }
            }
            for jj in 0..w {
                if ((j+1) & (1 << jj)) > 0 {
                    for j_i in 0..h {
                        temp_c[j_i][jj] = 'r';
                    }
                }
            }

            // cnt #
            let mut temp_cnt_k = 0;
            for cnt_i in 0..h {
                for cnt_j in 0..w {
                    if temp_c[cnt_i][cnt_j] == '#' {
                        temp_cnt_k += 1;
                    }
                }
            }
            if temp_cnt_k == k {
                res += 1;
            }
        }
    }

    println!("{:?}", res);
}


Measured memory_bytes: 2164