akhauriyash/Code-Regression huggingface dataset:
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <cstring>
#include <iostream>
#include <algorithm>

#define fi first
#define se second
#define pb push_back
#define MP std::make_pair
#define PII std::pair<int, int>
#define all(x) (x).begin(), (x).end()
#define CL(a, b) memset(a, b, sizeof a)
#define rep(i, l, r) for (int i = (l); i <= (r); ++ i)
#define per(i, r, l) for (int i = (r); i >= (l); -- i)
#define PE(x, a) for (int x = head[a]; x;x = edge[x].next)

typedef long long ll;

const int MAXN = 2e5 + 7;

int a[MAXN], n, f[MAXN], max;

int main() {
	scanf("%d", &n);
	f[0] = 1;
	rep(i, 1, n) scanf("%d", a + i), f[a[i]] = f[a[i] - 1];
	rep(i, 1, n) if (f[i]) max = std::max(max, i);
	printf("%d\n", !max ? -1 : n - max);
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main(){
    int n;
    cin >> n;

    for(int i=0; i<n; i++){
        int a,b,c;
        cin >> a >> b >> c;

        if(a*a == b*b + c*c || b*b == a*a + c*c || c*c == a*a + b*b)
            cout << "YES" << endl;
        else
            cout << "NO" << endl; 
    }


    return 0;
}


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

int main(){
	char S[10];
	int i;
	for(i=0;i<10;i++) cin >> S[i];
	S[0] = '2';
	S[1] = '0';
	S[2] = '1';
	S[3] = '8';
	cout << S << endl;
}

Measured memory_bytes: 256
n = int(input())
a = [int(i) for i in input().split(' ')]
a = sorted(a)
if a[0] == 0:
    print(0)
else:
    x = 1
    for i in a:
        x = x * i
        if x > 10**18:
            print(-1)
            break
    else:
        print(x)


Measured memory_bytes: 21676
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define lli long long int
#define d double
#define mod 1000000007
#define mx 100001
using namespace std;
int main() {
	FIO;
	int n;
	cin>>n;
	vector<int> vec(n);
	for(int i=0;i<n;i++) cin>>vec[i];
	lli sum[n][n];
	memset(sum,0,sizeof(sum));
	for(int i=0;i<n;i++){
		for(int j=i;j<n;j++){
			for(int k=i;k<=j;k++) sum[i][j]+=vec[k];
		}
	}
	lli inf=400000000001;
	lli dp[n][n];
	memset(dp,inf,sizeof(dp));
	for(int i=0;i<n;i++){
		dp[i][i]=0;
		if(i!=n-1) dp[i][i+1]=vec[i]+vec[i+1];
	}
	for(int i=n-1;i>=0;i--){
		for(int j=i+2;j<n;j++){
			for(int k=i;k<j;k++){
				dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+sum[i][j]);
			}
		}
	}
	cout<<dp[0][n-1]<<endl;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

int f[305][305][305];

int main() {

#ifdef LOCAL
  FILEIO("a");
#endif

  int n, k, mod; cin >> n >> k >> mod;
  f[0][1][1] = 1;
  for (RI i = 0; i <= n; ++i)
    for (RI j = 1; j <= k; ++j)
      for (RI l = n + 1; l; --l) {
        if (l == 1) (f[i][j + 1][i + 1] += f[i][j][l]) %= mod;
        else (f[i][j][l - 1] += f[i][j][l]) %= mod;
        (f[i + 1][j][l] += 1ll * f[i][j][l] * l % mod) %= mod;
      }
  cout << f[n][k][1] << endl;

  cerr << (double)(clock()) / CLOCKS_PER_SEC * 1000 << "ms" << endl;

  return 0;
}

// created by Daniel yuan

Measured memory_bytes: 110848
#pragma GCC optimize("Ofast")

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

using namespace std;
using namespace __gnu_pbds;

typedef
tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> orderedSet;

#define pb push_back
#define F first
#define S second
#define all(a) (a).begin(), (a).end()

#define for1(i0, l0, r0) for (int i0 = l0; i0 < r0; ++i0)
#define for2(i0, l0, r0) for (int i0 = l0; i0 <= r0; ++i0)
#define forn(i0, n0) for (int i0 = 0; i0 < n0; ++i0)
#define forn1(i0, n0) for (int i0 = 1; i0 < n0; ++i0)
#define forr(i0, n0) for (int i0 = n0; i0 >= 0; --i0)
#define forr1(i0, r0, l0) for (int i0 = r0; i0 > l0; --i0)
#define forr2(i0, r0, l0) for (int i0 = r0; i0 >= l0; --i0)

#define Sort(a) sort(all(a))
#define Reverse(a) reverse(all(a))
#define relaxMax(a, b) a = max(a, b)
#define relaxMin(a, b) a = min(a, b)

typedef long long ll;
typedef long double ld;
#define ui unsigned int
#define ull unsigned long long

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<string, string> pss;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<bool> vb;
typedef vector<string> vs;

typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<pdd> vpdd;

typedef vector<vi> vvi;
typedef vector<vd> vvd;
typedef vector<vll> vvll;
typedef vector<vb> vvb;

#define vpss vector<pss>
#define vvs vector<vs>
#define vvpii vector<vpii>
#define vvpll vector<vpll>
#define vpt vector<pt>
#define vvvi vector<vvi>
#define vsi vector<set<int>>
#define ss second
#define ff first

#define printvi(arr) for (int x0 : arr) cout << x0 << ' '; cout << '\n';
#define printvll(arr) for (ll x0 : arr) cout << x0 << ' '; cout << '\n';
#define printpair(pair0) cout << pair0.F << ' ' << pair0.S << '\n';
#define printvp(arr) for (auto pair0 : arr) printpair(pair0);
#define initArray(arr, N0, X0) memset(arr, X0, N0 * sizeof(int))
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cout.precision(16);
    //freopen("amusing.in", "r", stdin);
    //freopen("amusing.out", "w", stdout);
}

void solve() {
    string s;
    cin >> s;
    cout << s.substr(0, 3) << '\n';
}

bool multitest = false;

int main() {
    init();
    int t = 1;
    if (multitest) cin >> t;
    forn(i, t) solve();
}

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

int L[15], R[15];
int weight[15];

double W;

int N, w[6];
int TS;

int make_tree(int x, vector<int> A, vector<int> B){
  
  if( (int)B.size() == 1 ) return weight[x] = w[B[0]];
  
  int idx = 0, maxA = -1;
  
  for(int i=0;i<(int)A.size();i++){
    
    if( maxA < A[i] ){
      
      maxA = A[i];
      
      idx = i;
      
    }
    
  }
  
  assert( (int)A.size() + 1 == (int)B.size() );
  
  int sum = 0;
  
  vector<int> xLA, xLB;
  
  for(int i=0;i<idx;i++) xLA.push_back(A[i]);
  
  for(int i=0;i<=idx;i++) xLB.push_back(B[i]);
  
  TS++;
  
  L[x] = TS;
  
  sum += make_tree( TS, xLA, xLB );
  
  vector<int> xRA, xRB;
  
  for(int i=idx+1;i<(int)A.size();i++) xRA.push_back(A[i]);
  
  for(int i=idx+1;i<(int)B.size();i++) xRB.push_back(B[i]);
  
  TS++;
  
  R[x] = TS;
  
  sum += make_tree( TS, xRA, xRB );
  
  return weight[x] = sum;
}

double lmin, rmax;

void dfs(int x, double mid){
  
  lmin = min( lmin, mid );
  rmax = max( rmax, mid );
  
  if( L[x] == -1 && R[x] == -1 ) return;
  
  double l = weight[L[x]], r = weight[R[x]];
  
  double a = r / ( l + r ), b = l / ( l + r );
  
  dfs( L[x], mid - a );
  
  dfs( R[x], mid + b );
  
}

signed main(){
  
  int cnt;
  cin>>cnt;
  
  while(cnt--){
    
    cin>>W>>N;
    
    for(int i=0;i<N;i++) cin>>w[i];
    
    if( N == 1 ){
      cout<<0<<endl;
      continue;
    }
    
    double ans = -1;
    
    vector<int> A;
    
    for(int i=0;i<N-1;i++) A.push_back(i);
    
    do{
      
      vector<int> B;
      
      for(int i=0;i<N;i++) B.push_back(i);
      
      do{
	
	memset( L, -1, sizeof(L) );
	memset( R, -1, sizeof(R) );
	
	TS = 0;
	
	make_tree( TS, A, B );
	
	lmin = 1e9, rmax = -1e9;
	
	dfs( 0, 0.0 );
	
	if( rmax - lmin < W ) ans = max( ans, rmax - lmin );
	
      }
      while( next_permutation( B.begin(), B.end() ) );
      
    }
    while( next_permutation( A.begin(), A.end() ) );
        
    printf("%.8f\n", ans );
    
  }
  
  return 0;
}


Measured memory_bytes: 3288
/*
   THE DARK NIGHT RISES
I LOVE YOU 72 AND WILL FOREVER DO SO
Patience, Persistence, Perseverance, Passion, Purpose
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
const int N = 2e5 + 20 ;
#define F first
#define S second
# define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mk make_pair
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define sz(x)       (int)x.size()
const long long int mod=1e9 + 7;
const long double EPS=1e-12;
#define mem( a, val ) memset(a, val, sizeof( a ) )
#define deci( x ) cout<<fixed<<setprecision( x );
#define bitcount( x ) __builtin_popcountll( x )
 
const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
 

int solve()
{
  ll n ;
  cin >> n ;
  std::vector<ll> v(n+1);
  rep(i,1,n+1) cin >> v[i] ;
  ll ans = 0 ;
  ll st = 1 ;
  for(int i =1 ; i <= n ; i++)
  	if(v[i]==st)st++;
  if(st==1) return cout << -1 , 0 ;
  cout << (n-st+1) ;

}
int main()
{
	fast;
	ll t;
	t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
 
	return 0;
}
// Patience, Persistence, Perseverance, Passion, Purpose
// I LOVE YOU 72 AND WILL FOREVER DO SO.

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

using namespace std;

#define ll  long long
#define ld  double

#define sz(x)   (int)x.size()
#define all(x)  x.begin(),x.end()

#define pb  emplace_back
#define X   first
#define Y   second

const int   N   = 1005;

typedef pair<int,int>   ii;
typedef vector<int>     vi;

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

    int n;  cin >> n;
    ll  ans = -1e9 - 7;
    vi  res;

    vector<ii>  pos[2];

    for(int i = 1 ; i <= n ; ++i)   {
        int x;  cin >> x;

        if (ans < x)    {
            ans = x;
            res = {i};
        }
        if (x > 0)  pos[i & 1].pb(x,i);
    }
    for(int parity = 0 ; parity < 2 ; ++parity) if (pos[parity].size()) {        
        ll  Sum = 0;
        vi  vec;

        for(ii  e : pos[parity])    {
            Sum += e.X;
            vec.pb(e.Y);
        }
        if (ans < Sum)
            ans = Sum,
            res = vec;
    }
    vector<int> Ops;

    for(int i = n ; i > res.back() ; --i)   Ops.pb(i);
    for(int i = sz(res) - 1 ; i > 0 ; --i)  {
        int c = res[i] - res[i - 1];

        for(int j = 2 ; j < c ; j += 2)
            Ops.pb(res[i - 1] + 2);
        
        Ops.pb(res[i - 1] + 1);
    }
    for(int i = 1 ; i < res[0] ; ++i)
        Ops.pb(1);
    
    cout << ans << "\n";
    cout << Ops.size() << "\n";

    for(int x : Ops)
        cout << x << "\n";
}

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


int main(){
    long long N;
    cin >> N;
    long long a = (long long)sqrt(N)+1;
    for(a; a >0; a--){
        if(N%a==0){
            cout << a + N/a-2;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

long long int MOD = 1000000007;

long long int A[300005];

int N;

int C0[70], C1[70];

int main(void) {

	cin >> N;

	for (int i = 1; i <= N; i++) {
		cin >> A[i];
	}

	for (int i = 1; i <= N; i++) {
		long long int tmp = A[i];
		int cnt = 0;
		while (tmp > 0) {
			if (tmp % 2 == 1) { C1[cnt]++; }
			else { C0[cnt]++; }
			tmp /= 2;
			cnt++;
		}
	}

	long long int ans = 0;

	long long int P = 1;
	for (int i = 0; i < 63; i++) {
		long long int prod = (C1[i]*((long long int) N-C1[i])) % MOD;
		ans += (P*prod)%MOD;
		ans %= MOD; 
		P *= 2;
		P %= MOD;
	}

/*	for (int i = 0; i <= 4; i++) {
		cout << "C0[" << i << "]= " << C0[i] << "  C1[" << i << "]= " << C1[i] << endl;
	}*/

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2560
// 解説pdf通りに実装

#include <iostream>
#include <sstream>
#include <string>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

ll MOD = 1000000007;

ll modPow(ll x, ll y)
{
    ll r=1, a=x;
    while (y > 0) {
        if ( (y&1)==1 ) {
            r = (r * a) % MOD;
        }
        a = (a * a) % MOD;
        y /= 2;
    }
    
    return r;
}
// Modular multiplicative inverse through Fermat's little theorem:
// フェルマーの小定理より, a^-1 ≡ a^(p-2) (mod p) というのを使うらしい
// ただし、pが素数の時しか成り立たない
ll modInverse(ll x)
{
    return modPow(x, MOD-2);
}

// Modular division x / y, find modular multiplicative inverse of y
// and multiply by x.
ll modDivision(ll p, ll q)
{
    return (p * modInverse(q)) % MOD;
}

// Binomial coifficient C(n,k) in O(k) time.
ll n_choose_k(ll n, int k)
{
    if (k > n) {
        return 0;
    }
    ll p = 1, q = 1;
    for (int i=1; i<=k; i++) {
        q = ( q * i) % MOD;
        p = ( p * (n - i + 1) ) % MOD;
    }
    return modDivision( p, q);
}

vector<ll>  make_choose_table(ll N) {
    vector<ll> table(N+1);
    table[0] = 1;
    FOR(k, 1, N+1) {
        auto nxt = (table[k-1] * (N - (k - 1))) % MOD;
        table[k] = modDivision(nxt, k);
    }
    return table;
}


int main(void)
{
    cin.sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> As(N+1);
    vector<int> count(N+1);
    ll target = -1;
    REP(n,N+1) {
        cin >> As[n];
        ++count[As[n]];
        if (count[As[n]] == 2) target = As[n];
    }

    // left, mid, right
    vector<int> splits(3);
    int idx = 0;
    for(auto a: As) {
        if (a == target) ++idx;
        else ++splits[idx];
    }

    // 2つある数字のことをtargetと呼ぶことにする
    auto left = splits[0];  // 左側のtargetより左側にある数字の個数
    auto right = splits[2]; // 右側のtargetより右側にある数字の個数

    vector<ll> ans(N+2);
    vector<ll> cache_Nplus1 = make_choose_table(N+1);
    vector<ll> cache_LR = make_choose_table(left + right);

    // 解説pdf通り
    FOR(k, 1, N+2) { // k: とる数字の個数
        if (k <= left + right + 1) {
            ans[k]
                = cache_Nplus1[k] // N+1個すべての数字から、k個を選ぶ
                - cache_LR[k - 1] // left個の数字とright個の数字のみからk-1個を選ぶ選び方。
                                  // この選び方は、2つある数字のどちらを選んだかを区別できないので、差し引いている
                ;
            if (ans[k] < 0) ans[k] += MOD;
        }
        else {
            // kがこの範囲の場合は、left個の数字とright個の数字のみからk-1個を選ぶ選び方はできない
            ans[k] = cache_Nplus1[k];
        }
    }
    
    FOR(i, 1, N+2) cout << ans[i] << endl;
    

    return 0;
}


Measured memory_bytes: 4736
n = int(input())
xyh = [list(map(int,input().split())) for i in range(n)]
xyh = sorted(xyh,key = lambda x:-x[2])
mx,my,mh = xyh[0]
for cx in range(101):
	for cy in range(101):
		H = mh+abs(mx-cx)+abs(my-cy)
		if all(h == max(0,H-abs(x-cx)-abs(y-cy))for x,y,h in xyh):
			print(cx,cy,H)
			exit()

Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

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

  public void run() {

    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      String[] lns = in.readLine().split(" ");
      long n = Integer.parseInt(lns[0]);
      long m = Integer.parseInt(lns[1]);
      long ans = Math.abs(n * m -(n-1)*2 -(m-1)*2);
      System.out.println(ans);

    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 21460
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
	int A, B, C; cin >> A >> B >> C;
	cout << (A <= C && B >= C?"Yes":"No") << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   String[] a = new String[N];
   for(int i=0;i<N;i++) a[i] = sc.next();
   Arrays.sort(a);
   int tmp = 1;
   int anstmp = 1;
   String tt = a[0];
   List<String> nn = new ArrayList<>();
   nn.add(a[0]);
   for(int i=1;i<N;i++) 
   {
     if(tt.equals(a[i]))
     {
       tmp++;
       if(tmp==anstmp)
       {
         nn.add(a[i]);
       }
       if(tmp>anstmp)
       {
         anstmp = tmp;
         nn.clear();
         nn.add(a[i]);
       }
     }
     else
     {
       tmp = 1;
       tt = a[i];
       if(anstmp==1)
       {
         nn.add(a[i]);
       }
     }
   }
 

   for(int i = 0 ; i < nn.size() ;i++)
   {
     System.out.println(nn.get(i));
   }
 }
}

Measured memory_bytes: 76980
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

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

  cin >> n;
  vector<P> pv;

  REP(i, n) {
    int a, b;
    cin >> a >> b;
    pv.push_back(make_pair(a, b));
  }

  sort(pv.begin(), pv.end());

  int p = -(INF + 10);
  int ans = 0;
  REP(i, n) {
    int l = pv[i].first;
    int r = pv[i].second;
    if(p < l - r) {
      p = l + r - 1;
    } else {
      if((l + r - 1) < p) {
        p = l + r - 1;
      }
      ans++;
    }
  }

  cout << (n - ans) << endl;
}


Measured memory_bytes: 1400
var n:longint;
    i,k:longint;
    a,b,c,d,heap:array[0..201000]of int64;
    m0,m1:int64;
    ans,tot,x,y:int64;
procedure swap(var a,b:int64);
var t:longint;
begin
  t:=a;a:=b;b:=t;
end;
procedure up(x:longint);
begin
  while x>1 do
  begin
    if heap[x]<heap[x div 2] then
    begin
      swap(heap[x],heap[x div 2]);
      x:=x div 2;
    end else break;
  end;
end;
procedure down(x:longint);
var min:longint;
begin
  while x*2<=tot do
  begin
    min:=x*2;
    if (x*2+1<=tot)and(heap[x*2+1]<heap[min]) then inc(min);
    if heap[x]>heap[min] then
    begin
      swap(heap[x],heap[min]);
      x:=min;
    end else break;
  end;
end;

procedure sort;
var i,j:longint;
begin
  for i:=1 to n do
  begin
    c[i]:=heap[1];
    heap[1]:=heap[tot];
    dec(tot);
    down(1);
  end;
  {i:=l;
  j:=r;
  m:=c[(l+r)>>1];
  repeat
    while c[i]<m do inc(i);
    while c[j]>m do dec(j);
    if i<=j then
    begin
      t:=c[i];c[i]:=c[j];c[j]:=t;
      inc(i);
      dec(j);
    end;
  until i>j;
  if l<j then qs(l,j);
  if i<r then qs(i,r);}
end;
function find(x:int64):longint;
var l,r,m:longint;
begin
  l:=1;
  r:=n;
  while l<=r do
  begin
    m:=(l+r)>>1;
    if c[m]<x then l:=m+1 else r:=m-1;
  end;
  exit(l);
end;

begin
  read(n);
  for i:=1 to n do
  read(a[i]);
  for i:=1 to n do
  read(b[i]);
  c[0]:=-1;
  c[n+1]:=1 << 45;
  for k:=1 to 29 do
  begin
    tot:=0;
    x:=1 << k;
    y:=1 << (k-1);
    for i:=1 to n do
    begin
      heap[i]:=a[i] and (x-1);
      inc(tot);
      up(i);
      d[i]:=b[i] and (x-1);
    end;
    //writeln(k);
    sort;
    m0:=0;
    m1:=0;
    for i:=1 to n do
    begin
      m1:=m1+find(x-d[i])-find(y-d[i]);
      m1:=m1+n+1-find(x+y-d[i]);
      //inc(m1);
    end;
    //writeln('0=',m0,' 1=',m1);
    if m1 and 1 =1 then ans:=ans+y;
  end;
  writeln(ans);
end.






Measured memory_bytes: 7936
/*  -*- coding: utf-8 -*-
 *
 * e.cc: E - This Message Will Self-Destruct in 5s
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 200000;

/* typedef */

typedef long long ll;
typedef map<int,int> mii;

/* global variables */

int as[MAX_N];
mii ls, rs;

/* subroutines */

/* main */

int main() {
  // |j-i|=ai+aj
  // i < j -> j-i=ai+aj -> i+ai=j-aj
  // i > j -> i-j=ai+aj -> i-ai=j+aj

  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  for (int i = 0; i < n; i++) rs[i - as[i]]++;

  ll sum = 0;
  for (int i = 0; i < n; i++) {
    rs[i - as[i]]--;
    mii::iterator lit = ls.find(i - as[i]);
    if (lit != ls.end()) sum += lit->second;
    mii::iterator rit = rs.find(i + as[i]);
    if (rit != rs.end()) sum += rit->second;
    ls[i + as[i]]++;
  }

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


Measured memory_bytes: 21324
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
    ll n,sum=10000000000,sumtemp=0,ans;
    cin >> n;//>> b;
    ll a[n];
    for( ll i=0;i<n;i++)
    {
        cin >> a[i];
    }
    sort(a,a+n);
    for(ll i=a[0];i<=a[n-1];i++)
    {
        for(ll j=0;j<n;j++)
        {
            sumtemp = sumtemp + (a[j]-i)*(a[j]-i);
        }
        if(sumtemp<sum)
        {
            sum = sumtemp;
            ans = i;
        }
        sumtemp=0;
    }
    cout << sum << endl;
}

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

answer = [[False, 0] for i in range(n)]

for i in range(m):
  p, s = input().split()
  p = int(p) - 1
  if answer[p][0] == True:
    continue

  if s == 'AC':
    answer[p][0] = True
  else:
    answer[p][1] += 1

cor = sum(map(lambda x: x[0], answer))
pen = sum(map(lambda x: x[1] if x[0] == True else 0, answer))
print(cor, pen)

Measured memory_bytes: 13172
N, M = map(int, input().split())

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

x.sort()
diff_x = [x[i] - x[i-1] for i in range(1, len(x))]
diff_x.sort(reverse=True)
ex_diff = diff_x[:N-1]
ans = sum(diff_x) - sum(ex_diff)
if ans > 0:
    print(ans)
else:
    print(0)

Measured memory_bytes: 13968
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;
 
typedef long long ll;
const int MOD = (int)1e9 + 7;
int add(int x, int y)
{
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
int sub(int x, int y)
{
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
int mult(int x, int y)
{
	return ((ll)x * y) % MOD;
}
 
const int N = 3030;
int n;
char s[N];
int a[N];
int b[N];
int dp[N][N];
int C[N][N];
 
void read()
{
	int m;
	scanf("%d%d", &n, &m);
	scanf(" %s ", s);
	for (int i = 0; i < n; i++)
		a[i] = (int)(s[i] - '0');
	for (int i = 0; i < n; i++)
		b[i] = i + 1;
	while(m--)
	{
		int l, r;
		scanf("%d%d", &l, &r);
		l--;
		b[l] = max(b[l], r);
	}
	for (int i = 1; i < n; i++)
		b[i] = max(b[i], b[i - 1]);
}
 
int main()
{
	read();
 
	for (int i = 0; i < N; i++)
		C[i][0] = C[i][i] = 1;
	for (int i = 1; i < N; i++)
		for (int j = 1; j < i; j++)
			C[i][j] = add(C[i - 1][j], C[i - 1][j - 1]);
	
	dp[0][0] = 1;
	int cur = 0;
	for (int i = 0; i < n; i++)
	{
		int willAdd = 0;
		while(cur < b[i])
		{
			willAdd += a[cur];
			cur++;
		}
		for (int x = 0; x <= n; x++)
		{
			if (dp[i][x] == 0) continue;
			int y = x + willAdd;
			if (y != 0)
				dp[i + 1][y - 1] = add(dp[i + 1][y - 1], dp[i][x]);
			if (y != cur - i)
				dp[i + 1][y] = add(dp[i + 1][y], dp[i][x]);
		}
	}
	printf("%d\n", dp[n][0]);
 
	return 0;
}

Measured memory_bytes: 44024
let cnt = ref 0

let merge a l m r =
  let ai = Array.make (m - l + 1) max_int in
  for i = 0 to m - l - 1 do
    ai.(i) <- a.(l + i)
  done;
  let aj = Array.make (r - m + 1) max_int in
  for i = 0 to r - m - 1 do
    aj.(i) <- a.(m + i)
  done;
  let i = ref 0 in
  let j = ref 0 in
  for k = l to r - 1 do
    incr cnt;
    if ai.(!i) <= aj.(!j) then begin
      a.(k) <- ai.(!i);
      incr i;
    end else begin
      a.(k) <- aj.(!j);
      incr j;
    end
  done

let rec merge_sort a l r =
  if (l + 1) < r then begin
    let m = (l + r) / 2 in
    merge_sort a l m;
    merge_sort a m r;
    merge a l m r
  end

let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun i -> i)) in
  merge_sort a 0 n;
  print_int a.(0);
  for i = 1 to n - 1 do
    print_string " ";
    print_int a.(i);
  done;
  print_newline ();
  print_int !cnt;
  print_newline ()

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


int main() {
	int n;
	cin >> n;
	vector <int> a(n), b(n);

	for (int i = 0; i < n; i++) {
		cin >> a[i];
		b[i] = a[i];
	}

	sort(a.begin() , a.end());
	int first = a[n - 1];
	int second = a[n - 2];

	for (int i = 0; i < n; i++) {
		if (b[i] == first) {
			cout << second << endl;
		} else {
			cout << first << endl;
		}
	}

	return 0;

}

Measured memory_bytes: 3200
import sys
sys.setrecursionlimit(500000)

def memoize(f):
    table = {}

    def func(*args):
        if not args in table:
            table[args] = f(*args)
        return table[args]
    return func


@memoize
def memo(a, b):
    if a == b:
        return e[a].count(a)
    elif b - a == 1:
        return memo(b, b) + memo(a, a) + e[a].count(b)
    else:
        return memo(a+1, b)+memo(a, b-1) + e[a].count(b) - memo(a+1, b-1)


n, m, q = map(int, input().split())
e = []
for i in range(n+1):
    e.append([])
for i in range(m):
    x, y = map(int, input().split())
    e[x].append(y)
for i in range(q):
    x, y = map(int, input().split())
    print(memo(x, y))


Measured memory_bytes: 32148
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

int main(){
    int a, b, c, d; cin >> a >> b >> c >> d;
    int e, f, g, h; cin >> e >> f >> g >> h;

    ll ans1 = a + b + c + d;
    ll ans2 = e + f + g + h;

    cout << max(ans1, ans2) << endl;
    
}


Measured memory_bytes: 3104
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")
//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair<ll,ll>
#define vpii vector<pair<ll,ll> >
#define F first
#define S second
#define ld long double
#define built __builtin_popcountll
#define mst(a,i) memset(a,i,sizeof(a))
#define all(x) x.begin(),x.end()
#define itit(it,a) for(auto it=(a).begin(); it!=(a).end(); it++)
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define repr(i,a,b) for(ll i=a; i>b; i--)
#define reprr(i,a,b) for(ll i=a; i>=b; i--)
#define pi 3.14159265358979323846264338327950288419716939937510582097494459230
ll max3(ll x,ll y,ll z) {return max(max(x,y),z);}
ll min3(ll x,ll y,ll z) {return min(min(x,y),z);}
const ll M=2e5+10,M2=1e6+10,mod=1e9+7,inf=1e17+10;
void add(int& a, int b) {a+=b;if(a>=mod){a-=mod;}}
#define trace1(x)			 	 cerr<<#x<<": "<<x<<endl
#define trace2(x, y)		 	 cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)		 	 cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)	 	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)	 cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
int X[] = {0, 1, 0, -1};
int Y[] = {-1, 0, 1, 0};
ll power(ll x,ll n){ll result=1;while(n>0){if(n%2==1)result=(result*x)%mod; x=((x%mod)*(x%mod))%mod;n=n/2;}return result;}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	s=" "+s;
	for(ll i=1; i<s.size(); i++){
		if(i%2==0){
			if(s[i]=='L'||s[i]=='U'||s[i]=='D') continue;
			else{
				cout << "No";
				return 0;
			}
		}
		else{
			if(s[i]=='R'||s[i]=='U'||s[i]=='D') continue;
			else{
				cout << "No";
				return 0;
			}
		}
	}
	cout << "Yes";
	return 0;
}
/* The judge is never wrong! Your code is buggy
   Look for:
 * * Read the problem carefully.
 * * Don't forget to sort(), mod, ll!!!!
 * * Initial value = +/- infinity instead of zero!!!
 * * an easier and alternate approach
 * * read the problem statement carefully
 * * if concept is correct and still WA, try with a different implementation
 * * special cases (n=1?)
 * * if you have no idea just guess the appropriate well-known algorithm instead of doing nothing :/
 */


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

int n;
unsigned long long f[87];

int main()
{
    cin>>n;
    f[0]=2;
    f[1]=1;
    
    for(int i=2;i<=n;i++) f[i]=f[i-1]+f[i-2];
    
    cout<<f[n];
}

Measured memory_bytes: 256
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <list>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <iterator> 
#include <limits>

#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define ALL(a) (a).begin(),(a).end()
#define RALL(A) (a).rbegin(),(a).rend()
#define PB push_back
#define MP make_pair

#define dump(x) cerr << #x << " = " << (x) << endl;

using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

struct UnionFind {
    vector<int> par;
    int n, cnt;
    UnionFind(const int& x = 0) {init(x);}
    void init(const int& x) {par.assign(cnt=n=x, -1);}
    inline int find(const int& x) {return par[x] < 0 ? x : par[x] = find(par[x]);}
    inline bool same(const int& x, const int& y) { return find(x) == find(y); }
    inline bool unite(int x, int y) {
        if ((x = find(x)) == (y = find(y))) {
            return false;
        }
        --cnt;
        if (par[x] > par[y]) {
            swap(x, y);
        }
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    inline int count() const {return cnt;}
    inline int count(int x) {return -par[find(x)];}
};

int N, M;
const int MAX_N = 100000 + 100;
const int MAX_M = 100000 + 100;
int lang[MAX_M];

int main(int argc, char const* argv[])
{
    cin >> N >> M;
    FOR(i, 1, M + 1) {
        lang[i] = -1;
    }
    UnionFind uf(N);
    REP(i, N) {
        int K;
        cin >> K;
        REP(k, K) {
            int l;
            cin >> l;
            if (lang[l] != -1) {
                uf.unite(i, lang[l]);
            } else {
                lang[l] = i;
            }
        }
    }
    if (uf.count(0) != N) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(){
  int a;
  long long int b;
  scanf("%d %lld",&a,&b);
  long long int c[a];
  for(int i=0; i<a; i++){
    scanf("%lld",&c[i]);
  }
  long long int d=0;
  if(b<c[0]){
    d+=c[0]-b;
    c[0]=b;
  }
  for(int i=1; i<a; i++){
    long long int e=c[i-1]+c[i];
    if(e>b){
      c[i]-=e-b;
      d+=e-b;
    }
  }
  printf("%lld",d);
  return 0;}

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

template <typename T, T F(T, T), T ZERO>
struct SegmentTree {
    T n;
    vector<T> v;

    SegmentTree(T n_){
        n = 1;
        while(n < n_){ n *= 2; }
        v.resize(2 * n - 1);
        fill(v.begin(), v.end(), ZERO);
    }

    // zero-indexed
    void update(ll k, T a){
        k += n - 1;
        v[k] = a;
        while(k > 0){
            k = (k - 1) / 2;
            v[k] = F(v[k * 2 + 1], v[k * 2 + 2]);
        }
    }

    // [a, b), zero-indexed
    T query(ll a, ll b) const {
        return query_internal(a, b, 0, 0, n);
    }

    T get(ll a) const {
        return query(a, a + 1);
    }

    T query_internal(ll a, ll b, ll k, ll l, ll r) const {
        if(r <= a || b <= l){ return ZERO; }
        if(a <= l && r <= b){
            return v[k];
        }else{
            T v1 = query_internal(a, b, k * 2 + 1, l, (l + r) / 2);
            T v2 = query_internal(a, b, k * 2 + 2, (l + r) / 2, r);
            return F(v1, v2);
        }
    }
};

ll op(ll x, ll y){ return min(x, y); }

void solve(long long N, long long M, const string& S){
    SegmentTree<ll, op, numeric_limits<ll>::max()> st(N + 1);
    st.update(N, 0);
    for(ll i = N - 1; i >= 0; --i){
        if(S.at(i) == '1'){ continue; }
        ll d = st.query(i + 1, min(i + M, N) + 1);
        if(d != numeric_limits<ll>::max()){
            st.update(i, d + 1);
        }
    }

    if(st.get(0) == numeric_limits<ll>::max()){
        cout << -1 << endl;
        return;
    }

    vector<ll> d, p;
    REP(i, N + 1){
        if(S.at(i) == '1'){ continue; }
        d.push_back(- st.get(i));
        p.push_back(i);
    }

    vector<ll> ans;
    ll pos = 0;
    while(pos != d.size() - 1){
        ll i = lower_bound(d.begin(), d.end(), d.at(pos) + 1) - d.begin();
        ans.push_back(p.at(i) - p.at(pos));
        pos = i;
    }

    REP(i, ans.size()){
        cout << ans.at(i);
        if(i + 1 < ans.size()){
            cout << ' ';
        }
    }
    cout << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    string S;
    cin >> S;
    solve(N, M, S);
    return 0;
}


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

int main() {

  string S;
  cin >> S;
  int ans=0;
  
  for(int i=0; i<3; i++) {
    if(S.at(i)=='o') ans++;
  }
  
  cout << 700+100*ans << endl;
  
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0; i<n; i++)
#define eb(t) emplace_back(t)
typedef long long ll;
typedef long long unsigned int llu;
ll MOD = 1000000007;
ll INF = 1000000009;

void solve(){

    int n;
    int m;
    cin >> n >> m;
    vector<int> s;
    vector<int> c;
    rep(i,m){
        int x,y;
        cin >> x >> y;
        s.emplace_back(x);
        c.emplace_back(y);
    }

    rep(i,1000){
        auto st = to_string(i);
        if(st.size()!=n) continue;
        bool b=true;
        rep(j,m){
            if(s[j]>st.size()) {
                b=false;
                break;
            }
            if(st[s[j]-1] != (c[j] +'0')) {
                b=false;
                break;
            }
        }
        if(b){
            cout << i << endl;
            return;
        }
    }

    cout << -1 << endl;

}

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


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

	Scanner sc = new Scanner(System.in);

	void run() {

		int n = sc.nextInt();
		int m = sc.nextInt();
		
		int a[] = new int[n];
		for(int i =0 ; i < n ; i++){
			a[i] = sc.nextInt();
		}
		
		int result = 0;
		int x = 0;
		for(;;){
			int min = a[x];
			int max = a[x];
			for(int i =0 ; i< m ; i++){
				min = Math.min(min, a[x]);
				max = Math.max(max, a[x]);
				x++;
				if(x == n) x = 0;
			}
			result += max - min;
			if(x == 0){
				break;
			}
		}
		System.out.println(result);
		
	}
}



Measured memory_bytes: 30656
#include<bits/stdc++.h>
#define XX first
#define YY second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

int N;
int H;
int W;
LL A[114514];
int Y[114514];
int X[114514];
vector<int> ps;

struct UfData {
  int parsz;
  int rem;
  UfData() : parsz(-1), rem(1) {}
  // 自分にdをmerge。頂点自体はuにvをuniteした。
  void Merge(const UfData &d, int u, int v) {
    parsz += d.parsz;
    rem += d.rem;
  }
};

struct UnionFind {
  vector<UfData> dat;

  UnionFind() {}
  void Init(int n) {
    dat.assign(n, UfData());
  }
  int Root(int v) {
    if (dat[v].parsz < 0) return v;
    return dat[v].parsz = Root(dat[v].parsz);
  }
  bool Unite(int u, int v) {
    int p = Root(u);
    int q = Root(v);
    if (p == q) return false;

    if (dat[p].parsz > dat[q].parsz) {
      swap(p, q);
      swap(u, v);
    }
    dat[p].Merge(dat[q], u, v);
    dat[q].parsz = p;
    return true;
  }
  bool Same(int u, int v) {
    return Root(u) == Root(v);
  }
  int Size(int v) {
    return -dat[Root(v)].parsz;
  }
  UfData& Data(int v) {
    return dat[Root(v)];
  }
};

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);

  cin >> N >> H >> W;
  rep(i, N) {
    cin >> Y[i] >> X[i] >> A[i];
    --Y[i];
    --X[i];
    ps.eb(i);
  }
  sort(all(ps), [](int i, int j){return A[i] > A[j];});
  
  UnionFind uf;
  uf.Init(H+W);
  LL ans = 0;
  int num = 0;
  for (int idx : ps) {
    int u = Y[idx];
    int v = X[idx] + H;
    uf.Unite(u, v);
    auto &dat = uf.Data(v);
    if (dat.rem == 0) continue;
    dat.rem--;
    //cout << Y[idx]+1 << ", " << X[idx]+1 << ", " << A[idx] << endl;
    //cout << "taken\n";
    num++;
    ans += A[idx];
  }
  assert(num <= H+W);
  cout << ans << endl;
}


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

#define sz(x) (int)(x.size())
#define fr(i,a,b) for(int i=a;i<b;++i)
#define fdr(i,a,b) for(int i=b-1;i>=a;--i)
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
/////////////////////

int const N = 2e3 + 41;

int n, m;
int a[N][N];
string s[N];

int same[N][N], diff[N][N];
int l[N][N], r[N][N];

vector<pii> q;

void buildL(int l[N], int same[N], int diff[N], int a[N]){
	q.clear();
	fr(i, 1, m+1){
		int v;
		if(a[i] == a[i-1]) v = same[i];
		else v = diff[i];
		while(sz(q) > 0 && (q.back().first <= v)){
			q.pop_back();
		}
		if(sz(q) == 0) l[i] = 0;
		else l[i] = q.back().second - 1;
		q.pb(mp(v, i));
	}
}

void buildR(int r[N], int same[N], int diff[N], int a[N]){
	q.clear();
	fdr(i, 1, m+1){
		int v;
		if(a[i] == a[i-1]) v = same[i];
		else v = diff[i];
		while(sz(q) > 0 && (q.back().first <= v)){
			q.pop_back();
		}
		if(sz(q) == 0) r[i] = m + 1;
		else r[i] = q.back().second;
		q.pb(mp(v, i));
	}
}

void solve(){
	cin >> n >> m;
	fr(i, 0, n) cin >> s[i];
	fr(i, 0, n) fr(j, 0, m){
		if(s[i][j] == '#') a[i+1][j+1] = 1;
	}
	fr(i, 1, n+1) fr(j, 1, m+1){
		if(j == 1){
			same[i][j] = diff[i][j] = 0;
		}else{
			if(a[i][j] == a[i][j-1]){
				same[i][j] = same[i-1][j];
				diff[i][j] = i;
			}else{
				diff[i][j] = diff[i-1][j];
				same[i][j] = i;
			}
		}
	}


	fr(i, 2, n+1){
		buildL(l[i], same[i-1], diff[i-1], a[i]);
		buildR(r[i], same[i-1], diff[i-1], a[i]);
	}

	int ans = max(n, m);
	fr(i, 2, n+1){
		fr(j, 2, m+1){
			int h = i;
			if(j > 1){
				if(a[i][j] == a[i][j-1]) h -= same[i][j];
				else h -= diff[i][j];
			}
			int w = r[i][j] - l[i][j] - 1;
			ans = max(ans, h * w);
			
		}
	}
	cout << ans << endl;
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();


	return 0;
}

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

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

  long long b,c;
  string a,str1="",str2="";
  cin >> b >> a;
  c=a.length();
  if (c%2!=0){
    cout << "No";}
  else {
    for (int i=0;i<c/2;i++) {
      char c1 = a[i];
      str1+=c1;}
    for (int i=c/2;i<c;i++) {
      char c1 = a[i];
      str2+=c1;}
    if (str2==str1){
      cout << "Yes";}
    else {cout << "No";}}}

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

int main(int argc, char *argv[]) {
  std::string s;
  std::cin >> s;
  int count = 0;
  for (size_t i = 0; i < s.size() / 2; ++i)
    if (s.at(i) != s.at(s.size() - i - 1))
      ++count;
  std::cout << count << std::endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
int popcount(int x) { return __builtin_popcount(x); }
int popcountll(ll x) { return __builtin_popcountll(x); }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

template <typename T>
vector<T> slide_min(const vector<T> &a, int len) {
  int n = a.size();
  vector<T> res(n - len + 1);
  deque<T> deq;
  REP(i, n) {
    while (!deq.empty() && a[deq.back()] >= a[i]) deq.pop_back();
    deq.emplace_back(i);
    if (i + 1 >= len) {
      int left = i + 1 - len;
      res[left] = a[deq.front()];
      if (deq.front() == left) deq.pop_front();
    }
  }
  return res;
}

template <typename T>
vector<T> slide_max(const vector<T> &a, int len) {
  int n = a.size();
  vector<T> res(n - len + 1);
  deque<T> deq;
  REP(i, n) {
    while (!deq.empty() && a[deq.back()] <= a[i]) deq.pop_back();
    deq.emplace_back(i);
    if (i + 1 >= len) {
      int left = i + 1 - len;
      res[left] = a[deq.front()];
      if (deq.front() == left) deq.pop_front();
    }
  }
  return res;
}

int main() {
  int n, k; cin >> n >> k;
  vector<int> p(n); REP(i, n) cin >> p[i];
  if (n == k) {
    cout << "1\n";
    return 0;
  }
  vector<int> inc(n, 0);
  REP(i, n - 1) {
    inc[i] += p[i] < p[i + 1];
    inc[i + 1] = inc[i];
  }
  vector<int> same(n - k + 1, -1), mn = slide_min(p, k + 1), mx = slide_max(p, k + 1);
  REP(i, n - k + 1) {
    if (inc[i + k - 2] - (i == 0 ? 0 : inc[i - 1]) == k - 1) continue;
    same[i] = !(i < n - k && mn[i] == p[i] && mx[i] == p[i + k]);
  }
  int ans = 0;
  bool fixed = false;
  REP(i, n - k + 1) {
    if (same[i] == -1) {
      fixed = true;
    } else if (same[i] == 1) {
      ++ans;
    }
  }
  cout << ans + fixed << '\n';
  return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 100000000;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int N; cin >> N;
  string str; cin >> str;
  int numW[N+1], numE[N+1];
  numW[0] = 0;
  numE[0] = 0;
  for(int i=1;i<=N;i++){
    if(str[i-1] == 'E'){
      numE[i] = numE[i-1] + 1;
      numW[i] = numW[i-1];
    }else{
      numW[i] = numW[i-1] + 1;
      numE[i] = numE[i-1];
    }
  }
  int minans = INF;
  for(int i=1;i<=N;i++){
    int left = numW[i-1] - numW[0];
    int right = numE[N] - numE[i];
    // cout << left << " " << right << endl;
    int ans = left + right;
    minans = min(ans, minans);
  }
  cout << minans << endl;
}

Measured memory_bytes: 2964
#include <iostream>
#include <algorithm>
#include <vector>

uint64_t A, B, C, X, Y;

int main() {

  std::cin >> A >> B >> C >> X >> Y;

  std::vector<uint64_t> ps{};

  ps.push_back(2 * C * std::max(X, Y));

  if (X < Y)
    ps.push_back(2 * C * X + B * (Y - X));
  else
    ps.push_back(2 * C * Y + A * (X - Y));

  ps.push_back(A * X + B * Y);

  std::sort(ps.begin(), ps.end());

  std::cout << ps.front() << std::endl;

  return 0;
}


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

int main(void){
    ll n;
    cin>>n;
    ll z=26,tmp=26,c=1;
    while(tmp<n){
        n-=tmp;
        tmp*=z;
        ++c;
    }
    --n;
    string line="abcdefghijklmnopqrstuvwxyz",ans="";
    rep(0,i,c){
        ans+=line[n%z];
        n/=z;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
}

Measured memory_bytes: 3584
import java.util.Scanner;


public class Main 
{
	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		
		String ans ="No";
		if(n.charAt(0)==n.charAt(2))
		{
			ans ="Yes";
		}
		
		System.out.println(ans);

	}

}


Measured memory_bytes: 21844
#include <cstdio>
void reader(int *x) {
	char k = getchar_unlocked(); *x = k - '0';
	while (1) {
		k = getchar_unlocked();
		if (k < '0' || k > '9') break;
		*x = ((*x) << 1) + ((*x) << 3) + k - '0';
	}
}
void reader(long long *x) {
	char k = getchar_unlocked(); *x = k - '0';
	while (1) {
		k = getchar_unlocked();
		if (k < '0' || k > '9') break;
		*x = ((*x) << 1) + ((*x) << 3) + k - '0';
	}
}
int n, b[100009]; long long a[100009];
int main() {
	reader(&n);
	for (int i = 0; i < n; i++) {
		reader(&a[i]);
		reader(&b[i]);
	}
	long long ret = 0;
	for (int i = n - 1; i >= 0; i--) {
		long long d = (a[i] + ret) % b[i];
		if (d) ret += b[i] - d;
	}
	printf("%lld\n", ret);
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const int INF = 1001001001;
const int MOD = 1000000007;
typedef long long ll;

int main(){
    int N;
    cin >> N;
    ll cnt = 0;
    for(int i = 0; i < N; i++){
        cnt += i;
    }
    cout << cnt << endl;
    return 0;

}


Measured memory_bytes: 256
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let n: i64 = read();
    let m: i64 = read();
    println!(
        "{}",
        if m == 1 && n == 1 {
            1
        } else if n == 1 {
            m - 2
        } else if m == 1 {
            n - 2
        } else {
            (n - 2) * (m - 2)
        }
    );
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352